|
|
| version 1.1, 2006/01/19 17:16:29 | version 1.2, 2006/02/15 13:00:30 |
|---|---|
| Line 1 | Line 1 |
| /********************************************************************/ | |
| /* 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 */ | /* MÓDULO: Notificaciones.c */ |
| /* */ | /* */ |
| Line 59 extern struct argumentos configuracion; | Line 26 extern struct argumentos configuracion; |
| void IniciarNotificaciones() | void IniciarNotificaciones() |
| { | { |
| time_t tiempo; | time_t tiempo; |
| struct tm *ptr_tm; | struct tm *ptr_tm; |
| FILE *handle; | FILE *handle; |
| char fichero[MAX_LINE]; | char fichero[MAX_LINE]; |
| char buffer[9]; | char buffer[9]; |
| /* nombre del fichero de notificaciones */ | /* nombre del fichero de notificaciones */ |
| strcpy(fichero, "notificaciones.log"); | strcpy(fichero, "notificaciones.log"); |
| /* abro el fichero de notificaciones y escribo una cabecera */ | /* abro el fichero de notificaciones y escribo una cabecera */ |
| if((handle = fopen(fichero, "w")) != NULL) | if((handle = fopen(fichero, "w")) != NULL) |
| { | { |
| fprintf(handle, "FICHERO DE NOTIFICACIONES\n"); | fprintf(handle, "FICHERO DE NOTIFICACIONES\n"); |
| /* OJO: el formato de fecha está en inglés */ | /* OJO: el formato de fecha está en inglés */ |
| /* esto no es ANSI | /* esto no es ANSI |
| _strdate(buffer); | _strdate(buffer); |
| fprintf(handle, "Fecha %s \n", buffer); | fprintf(handle, "Fecha %s \n", buffer); |
| _strtime(buffer); | _strtime(buffer); |
| fprintf(handle, "Hora %s \n\n", buffer); | fprintf(handle, "Hora %s \n\n", buffer); |
| */ | */ |
| /* fecha y hora */ | /* fecha y hora */ |
| tiempo = time(NULL); | tiempo = time(NULL); |
| ptr_tm = localtime(&tiempo); | ptr_tm = localtime(&tiempo); |
| strftime(buffer, MAX_LINE, "%d/%m/%y", ptr_tm); | strftime(buffer, MAX_LINE, "%d/%m/%y", ptr_tm); |
| fprintf(handle, "Fecha %s \n", buffer); | fprintf(handle, "Fecha %s \n", buffer); |
| strftime(buffer, MAX_LINE, "%H:%M:%S", ptr_tm); | strftime(buffer, MAX_LINE, "%H:%M:%S", ptr_tm); |
| fprintf(handle, "Hora %s \n\n", buffer); | fprintf(handle, "Hora %s \n\n", buffer); |
| if(fclose(handle)) | if(fclose(handle)) |
| { | { |
| fprintf(handle, "El fichero '%s' no se ha podido cerrar\n", fichero); | fprintf(handle, "El fichero '%s' no se ha podido cerrar\n", fichero); |
| printf("El fichero '%s' no se ha podido cerrar\n", fichero); | printf("El fichero '%s' no se ha podido cerrar\n", fichero); |
| } | } |
| } | } |
| else | else |
| { | { |
| printf("El fichero '%s' no se ha podido abrir\n", fichero); | printf("El fichero '%s' no se ha podido abrir\n", fichero); |
| printf("Pulse cualquier tecla para salir\n"); | printf("Pulse cualquier tecla para salir\n"); |
| getchar(); | getchar(); |
| exit(1); | exit(1); |
| } | } |
| } | } |
| void Notificar(char *mensaje, unsigned char accion, unsigned char eco) | void Notificar(char *mensaje, unsigned char accion, unsigned char eco) |
| { | { |
| FILE *handle; | FILE *handle; |
| char fichero[MAX_LINE]; | char fichero[MAX_LINE]; |
| /* nombre del fichero de notificaciones */ | /* nombre del fichero de notificaciones */ |
| strcpy(fichero, "notificaciones.log"); | strcpy(fichero, "notificaciones.log"); |
| /* escribo la notificación en el fichero y si no es posible aborto el programa */ | /* escribo la notificación en el fichero y si no es posible aborto el programa */ |
| if((handle = fopen(fichero, "a")) != NULL) | if((handle = fopen(fichero, "a")) != NULL) |
| { | { |
| if(accion != NO_ERROR || configuracion.nivelnotificaciones != ERRORS) | if(accion != NO_ERROR || configuracion.nivelnotificaciones != ERRORS) |
| fprintf(handle, "%s%s\n", accion!= NO_ERROR ? "ERROR: ": "", mensaje); | fprintf(handle, "%s%s\n", accion!= NO_ERROR ? "ERROR: ": "", mensaje); |
| if(fclose(handle)) | if(fclose(handle)) |
| { | { |
| fprintf(handle, "El fichero '%s' no se ha podido cerrar\n", fichero); | fprintf(handle, "El fichero '%s' no se ha podido cerrar\n", fichero); |
| printf("El fichero '%s' no se ha podido cerrar\n", fichero); | printf("El fichero '%s' no se ha podido cerrar\n", fichero); |
| } | } |
| } | } |
| else | else |
| { | { |
| printf("El fichero '%s' no se ha podido abrir\n", fichero); | printf("El fichero '%s' no se ha podido abrir\n", fichero); |
| printf("Pulse cualquier tecla para salir\n"); | printf("Pulse cualquier tecla para salir\n"); |
| getchar(); | getchar(); |
| exit(1); | exit(1); |
| } | } |
| /* escribo el error en la pantalla */ | /* escribo el error en la pantalla */ |
| if(eco == ECO_SI) printf("%s\n", mensaje); | if(eco == ECO_SI) printf("%s\n", mensaje); |
| /* acción en función del parámetro */ | /* acción en función del parámetro */ |
| switch(accion) | switch(accion) |
| { | { |
| case ERROR_SALIR: | case ERROR_SALIR: |
| printf("\n\nERROR GRAVE\nPulse cualquier tecla para salir\n"); | printf("\n\nERROR GRAVE\nPulse cualquier tecla para salir\n"); |
| getchar(); | getchar(); |
| exit(1); | exit(1); |
| break; | break; |
| case ERROR_SEGUIR: | case ERROR_SEGUIR: |
| printf("\n\nERROR LEVE\nPulse cualquier tecla para continuar\n"); | printf("\n\nERROR LEVE\nPulse cualquier tecla para continuar\n"); |
| getchar(); | getchar(); |
| break; | break; |
| case NO_ERROR: | case NO_ERROR: |
| break; | break; |
| } | } |
| } | } |
| void NotificarConfiguracion() | void NotificarConfiguracion() |
| { | { |
| FILE *handle; | FILE *handle; |
| char fichero[MAX_LINE]; | char fichero[MAX_LINE]; |
| /* nombre del fichero de notificaciones */ | /* nombre del fichero de notificaciones */ |
| strcpy(fichero, "notificaciones.log"); | 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); | |
| } | |
| } | |
| /* 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); | |
| } | |
| } |