File:  [Repository ATC2] / ADD_ver_10 / Source Code / Source Files / Notificaciones.c
Revision 1.2: download - view: text, annotated - select for diffs
Tue Feb 28 14:54:21 2006 UTC (18 years, 6 months ago) by rico
Branches: MAIN
CVS tags: HEAD
*** empty log message ***

/********************************************************************/
/*  Notificaciones.c                                                */
/*                                                                  */
/*                                                                  */
/*  Copyright (c) 1997-2006 Rafael Rico      (rafael.rico@uah.es)   */
/*                                                                  */
/*  Este fichero forma parte de ADD                                 */
/*  (Analizador de Dependencias de Datos)                           */
/*  Version 5.10.                                                   */
/*                                                                  */
/*                                                                  */
/*  ADD es software libre. Puede redistribuirlo y/o modificarlo     */
/*  bajo los términos de la Licencia Pública General de GNU         */
/*  según es publicada por la Free Software Foundation, bien bajo   */
/*  la versión 2 de dicha Licencia o bien (según su elección)       */
/*  bajo cualquier versión posterior.                               */
/*                                                                  */
/*  ADD se distribuye con la esperanza de que sea útil,             */
/*  pero SIN NINGUNA GARANTÍA, incluso sin la garantía MERCANTIL    */
/*  implícita y sin garantizar la CONVENIENCIA PARA UN PROPÓSITO    */
/*  PARTICULAR. Véase la Licencia Pública General de GNU para       */
/*  más detalles.                                                   */
/*                                                                  */
/*  Debería haber recibido una copia de la Licencia Pública General */
/*  junto con ADD. Si no ha sido así, escriba a la Free Software    */
/*  Foundation, Inc., 51 Franklin St, Fifth Floor,                  */
/*  Boston, MA  02110-1301  EEUU.                                   */
/*                                                                  */
/*  -------------------------- Historia --------------------------- */
/*                                                                  */
/*  $Id: Notificaciones.c,v 1.2 2006/02/28 14:54:21 rico Exp $                                                            */
/*                                                                  */
/*  Revisión 1.2. 01/2006                                           */
/*  Se añade la licencia GPL y documentación en estilo Javadoc      */
/*                                                                  */
/*  Revisión 1.1. 09/2005                                           */
/*  Versión inicial                                                 */
/*                                                                  */
/********************************************************************/

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