File:  [Repository ATC2] / ADD_ver_10 / Attic / Notificaciones.c
Revision 1.2: download - view: text, annotated - select for diffs
Wed Feb 15 13:00:30 2006 UTC (18 years, 7 months ago) by rico
Branches: MAIN
CVS tags: Version_10, HEAD
*** empty log message ***

/******************************************************************************/
/* 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>