home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Issue 2 / Freelog_HS_3_Setp_Oct_Nov_2000_CD2.mdx / Arcade / Orbit / src / log.c < prev    next >
C/C++ Source or Header  |  1999-08-19  |  2KB  |  87 lines

  1. /*
  2.  
  3. ORBIT, a freeware space combat simulator
  4. Copyright (C) 1999  Steve Belczyk <steve1@genesis.nred.ma.us>
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20. */
  21.  
  22. #include "orbit.h"
  23. #include <stdarg.h>
  24.  
  25. /*
  26.  *  Stuff to maintain the log file
  27.  */
  28.  
  29. FILE *logfd;
  30.  
  31. InitLog()
  32. /*
  33.  *  Open the log file
  34.  */
  35. {
  36.     if (NULL == (logfd = fopen ("orbit.log", "wt"))) return;
  37.  
  38.     Log ("InitLog()");
  39.  
  40.     /* That's all! */
  41.     return;
  42. }
  43.  
  44. CloseLog()
  45. /*
  46.  *  Close up the log file
  47.  */
  48. {
  49.     Log ("CloseLog()");
  50.     fclose (logfd);
  51.     return;
  52. }
  53.  
  54. void Log (char *fmt, ...)
  55. /*
  56.  *  Write a log message
  57.  */
  58. {
  59.     va_list ap;
  60.     int tm;
  61.     char buf[64];
  62.  
  63.     tm = time (NULL);
  64.  
  65.     va_start (ap, fmt);
  66.     strcpy (buf, ctime((const time_t *)&tm));
  67.     buf[strlen(buf)-1] = 0;
  68.     fprintf (logfd, "%s: ", buf);
  69.     vfprintf (logfd, fmt, ap);
  70.     fprintf (logfd, "\n");
  71.     fflush (logfd);
  72.     va_end (ap);
  73. }
  74.  
  75. LogWrite (buf, n)
  76. char *buf;
  77. int n;
  78. /*
  79.  *  Write raw data to logfile
  80.  */
  81. {
  82.     fwrite (buf, 1, n, logfd);
  83.     fprintf (logfd, "\n");
  84. }
  85.  
  86.  
  87.