home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / network / eqtree / logfile.c < prev    next >
C/C++ Source or Header  |  1994-01-18  |  1KB  |  93 lines

  1. /*
  2.  * LOGFILE.c
  3.  *
  4.  * Logdatei und Funktionen darauf
  5.  *
  6.  * Autor: SG
  7.  * Stand: 22.6.93
  8.  *
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include <stdarg.h>
  13. #include <stdlib.h>
  14.  
  15. FILE *LOFile;
  16.  
  17. void LOClose(void)
  18. {
  19.     if (LOFile)
  20.     fclose(LOFile);
  21. }
  22.  
  23. static int LOOpen(const char *Logfilename,const char *mode)
  24. {
  25.     if (Logfilename == NULL)
  26.     return 0;
  27.  
  28.     LOFile = fopen(Logfilename,mode);
  29.     if (LOFile == NULL)
  30.     return 0;
  31.  
  32.     atexit(LOClose);
  33.     return 1;
  34. }
  35.  
  36. int LOInit(const char *Logfilename)
  37. {
  38.     return LOOpen(Logfilename,"w");
  39. }
  40.  
  41. int LOAppend(const char *Logfilename)
  42. {
  43.     return LOOpen(Logfilename,"a");
  44. }
  45.  
  46. static int LOWrite(const char *Format,va_list vl)
  47. {
  48.     vfprintf(stdout,Format,vl);
  49.     fputs("\n",stdout);
  50.     if (LOFile)
  51.     {
  52.     vfprintf(LOFile,Format,vl);
  53.     fputs("\n",LOFile);
  54.     }
  55.     return 1;
  56. }
  57.  
  58. int LOItem(const char *Format,...)
  59. {
  60.     va_list vl;
  61.  
  62.     va_start(vl,Format);
  63.     LOWrite(Format,vl);
  64.     va_end(vl);
  65.     return 1;
  66. }
  67.  
  68. void ERFatal(const char *Format,...)
  69. {
  70.     va_list vl;
  71.  
  72.     va_start(vl,Format);
  73.     fprintf(stdout,"Fatal: ");
  74.     if (LOFile)
  75.     fprintf(LOFile,"Fatal: ");
  76.     LOWrite(Format,vl);
  77.     va_end(vl);
  78.     exit(1);
  79. }
  80.  
  81. int ERMessage(const char *Format,...)
  82. {
  83.     va_list vl;
  84.  
  85.     va_start(vl,Format);
  86.     fprintf(stdout,"Message: ");
  87.     if (LOFile)
  88.     fprintf(LOFile,"Message: ");
  89.     LOWrite(Format,vl);
  90.     va_end(vl);
  91.     return 1;
  92. }
  93.