home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / lora299s.zip / LOG.CPP < prev    next >
C/C++ Source or Header  |  1998-05-12  |  2KB  |  103 lines

  1.  
  2. // LoraBBS Version 2.99 Free Edition
  3. // Copyright (C) 1987-98 Marco Maccaferri
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include "_ldefs.h"
  20. #include "lora_api.h"
  21.  
  22. TLog::TLog (void)
  23. {
  24.    fp = NULL;
  25.  
  26.    Months[0] = "Jan";
  27.    Months[1] = "Feb";
  28.    Months[2] = "Mar";
  29.    Months[3] = "Apr";
  30.    Months[4] = "May";
  31.    Months[5] = "Jun";
  32.    Months[6] = "Jul";
  33.    Months[7] = "Aug";
  34.    Months[8] = "Sep";
  35.    Months[9] = "Oct";
  36.    Months[10] = "Nov";
  37.    Months[11] = "Dec";
  38. }
  39.  
  40. TLog::~TLog (void)
  41. {
  42.    if (fp != NULL)
  43.       fclose (fp);
  44. }
  45.  
  46. USHORT TLog::Open (PSZ pszName)
  47. {
  48.    USHORT RetVal = FALSE;
  49.  
  50.    if (fp != NULL)
  51.       fclose (fp);
  52.  
  53.    strcpy (FileName, pszName);
  54.    if ((fp = fopen (FileName, "a+t")) != NULL)
  55.       RetVal = TRUE;
  56.  
  57.    return (RetVal);
  58. }
  59.  
  60. VOID TLog::Suspend (VOID)
  61. {
  62.    if (fp != NULL) {
  63.       fclose (fp);
  64.       fp = NULL;
  65.    }
  66. }
  67.  
  68. VOID TLog::Resume (VOID)
  69. {
  70.    if (fp == NULL)
  71.       fp = fopen (FileName, "a+t");
  72. }
  73.  
  74. VOID TLog::Write (PSZ pszFormat, ...)
  75. {
  76.    va_list arglist;
  77.    time_t t;
  78.    struct tm *timep;
  79.  
  80.    va_start (arglist, pszFormat);
  81.    vsprintf (Buffer, pszFormat, arglist);
  82.    va_end (arglist);
  83.  
  84.    t = time (NULL);
  85.    timep = localtime (&t);
  86.    sprintf (Temp, "%c %02d %3s %02d:%02d:%02d %s %s", Buffer[0], timep->tm_mday, Months[timep->tm_mon], timep->tm_hour, timep->tm_min, timep->tm_sec, "LORA", &Buffer[1]);
  87.  
  88.    if (fp != NULL) {
  89.       fprintf (fp, "%s\n", Temp);
  90.       fflush (fp);
  91.    }
  92. }
  93.  
  94. VOID TLog::WriteBlank (VOID)
  95. {
  96.    if (fp != NULL) {
  97.       fprintf (fp, "\n");
  98.       fflush (fp);
  99.    }
  100. }
  101.  
  102.  
  103.