File:  [Repository ATC2] / ADD_ver_10 / Attic / Notificaciones.c
Revision 1.1: download - view: text, annotated - select for diffs
Thu Jan 19 17:16:29 2006 UTC (18 years, 8 months ago) by rico
Branches: MAIN
CVS tags: HEAD
*** empty log message ***

/********************************************************************/
/*  Notificaciones.c                                                */
/*                                                                  */
/*  Copyright (c) 1997-2006 Rafael Rico      (rafael.rico@uah.es)   */
/*                                                                  */
/*  This file is part of ADD version 5.10.                          */
/*                                                                  */
/*  ADD is free software; you can redistribute it and/or modify     */
/*  it under the terms of the GNU General Public License as         */
/*  published by the Free Software Foundation; either version 2 of  */
/*  the License, or (at your option) any later version.             */
/*                                                                  */
/*  ADD is distributed in the hope that it will be useful,          */
/*  but WITHOUT ANY WARRANTY; without even the implied warranty of  */
/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   */
/*  GNU General Public License for more details.                    */
/*                                                                  */
/*  You should have received a copy of the GNU General Public       */
/*  License along with ADD; if not, write to the Free Software      */
/*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA        */
/*  02111-1307  USA                                                 */
/*                                                                  */
/*  --------------------------- History --------------------------- */
/*                                                                  */
/*  Revision 1.2. 01/2006                                           */
/*  Added GPL License and JavaDoc style documentation               */
/*                                                                  */
/*  Revision 1.1. 09/2005                                           */
/*  Initial Revision                                                */
/*                                                                  */
/********************************************************************/


/******************************************************************************/
/* MÓDULO: Notificaciones.c                                                   */
/*                                                                            */
/* Este módulo contiene las funciones que anotan notificación de sucesos      */
/* o errores en un fichero especial (notificaciones.log).                     */
/******************************************************************************/
/* Fecha: 16 de septiembre de 2005                                            */
/******************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>

#include "defines.h"
#include "tipos.h"
#include "notificaciones.h"

/* configuración */
extern struct argumentos configuracion;



/* NOTIFICACIONES Y GESTIÓN DE ERRORES */

void IniciarNotificaciones()
{
	time_t tiempo;
	struct tm *ptr_tm;
	FILE *handle;
	char fichero[MAX_LINE];
	char buffer[9];

	/* nombre del fichero de notificaciones */
	strcpy(fichero, "notificaciones.log");

	/* abro el fichero de notificaciones y escribo una cabecera */
	if((handle  = fopen(fichero, "w")) != NULL)
	{
		fprintf(handle, "FICHERO DE NOTIFICACIONES\n");
		/* OJO: el formato de fecha está en inglés */
		/* esto no es ANSI
		_strdate(buffer);
		fprintf(handle, "Fecha %s \n", buffer);
		_strtime(buffer);
		fprintf(handle, "Hora %s \n\n", buffer);
		*/

		/* fecha y hora */
		tiempo = time(NULL);
		ptr_tm = localtime(&tiempo);
		strftime(buffer, MAX_LINE, "%d/%m/%y", ptr_tm);
		fprintf(handle, "Fecha %s \n", buffer);
		strftime(buffer, MAX_LINE, "%H:%M:%S", ptr_tm);
		fprintf(handle, "Hora %s \n\n", buffer);

		
		if(fclose(handle))
		{
			fprintf(handle, "El fichero '%s' no se ha podido cerrar\n", fichero);
			printf("El fichero '%s' no se ha podido cerrar\n", fichero);
		}
	}
	else
	{
		printf("El fichero '%s' no se ha podido abrir\n", fichero);
		printf("Pulse cualquier tecla para salir\n");
		getchar();
		exit(1);
	}
}


void Notificar(char *mensaje, unsigned char accion, unsigned char eco)
{
	FILE *handle;
	char fichero[MAX_LINE];

	/* nombre del fichero de notificaciones */
	strcpy(fichero, "notificaciones.log");

	/* escribo la notificación en el fichero y si no es posible aborto el programa */
	if((handle  = fopen(fichero, "a")) != NULL)
	{
		if(accion != NO_ERROR || configuracion.nivelnotificaciones != ERRORS)
			fprintf(handle, "%s%s\n", accion!= NO_ERROR ? "ERROR: ": "", mensaje);

		if(fclose(handle))
		{
			fprintf(handle, "El fichero '%s' no se ha podido cerrar\n", fichero);
			printf("El fichero '%s' no se ha podido cerrar\n", fichero);
		}
	}
	else
	{
		printf("El fichero '%s' no se ha podido abrir\n", fichero);
		printf("Pulse cualquier tecla para salir\n");
		getchar();
		exit(1);
	}

	/* escribo el error en la pantalla */
	if(eco == ECO_SI) printf("%s\n", mensaje);

	/* acción en función del parámetro */
	switch(accion)
	{
		case ERROR_SALIR:
		printf("\n\nERROR GRAVE\nPulse cualquier tecla para salir\n");
		getchar();
		exit(1);
		break;

		case ERROR_SEGUIR:
		printf("\n\nERROR LEVE\nPulse cualquier tecla para continuar\n");
		getchar();
		break;

		case NO_ERROR:
		break;
	}
}


void NotificarConfiguracion()
{
	FILE *handle;
	char fichero[MAX_LINE];

	/* nombre del fichero de notificaciones */
	strcpy(fichero, "notificaciones.log");

	/* escribo la notificación en el fichero y si no es posible aborto el programa */
	if((handle  = fopen(fichero, "a")) != NULL)
	{
		/* sin cabecera, fecha NO, completo SI, comentarios NO, separador " "); */
		SalvarConfiguracionFichero(handle, "", NO, SI, NO, ' ');	
		
		/* SalvarConfiguracion(handle); */

		if(fclose(handle))
		{
			fprintf(handle, "El fichero '%s' no se ha podido cerrar\n", fichero);
			printf("El fichero '%s' no se ha podido cerrar\n", fichero);
		}
	}
	else
	{
		printf("El fichero '%s' no se ha podido abrir\n", fichero);
		printf("Pulse cualquier tecla para salir\n");
		getchar();
		exit(1);
	}
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>