home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Entertainment / MacMud / syslog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-05  |  1.3 KB  |  75 lines  |  [TEXT/MPS ]

  1. /*
  2.  * syslog, openlog, closelog - hacked from Unix - use dprintf
  3.  * perror - hacked from Unix - uses dprintf
  4.  */
  5. extern int errno;
  6.  
  7. #ifdef DPRINTF
  8. /*
  9.  * normally supplied by caller - there's too many places to do I/O on a mac
  10.  */
  11. dprintf(fmt,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12)
  12.     char *fmt;
  13.     char *a1,*a2,*a3,*a4,*a5,*a6,*a7,*a8,*a9,*a10,*a11,*a12;
  14. {
  15.     (void) fprintf(stderr,fmt,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12);
  16. }
  17. #endif DPRINTF
  18.  
  19. #define MAXLINE 1000
  20.  
  21. static int LogMask = LOG_DEBUG;
  22. static char LogTag[100] = "";
  23.  
  24. openlog(ident, logstat) char *ident; int logstat;
  25. {
  26.     if (logstat >= LOG_ALERT && logstat <= LOG_DEBUG)
  27.         LogMask = logstat;
  28.         
  29.     if (ident)
  30.         strcpy(LogTag,ident);
  31. }
  32.  
  33. closelog()
  34. {
  35. }
  36.  
  37. syslog(pri, fmt, p0,p1,p2,p3,p4,p5,p6,p7,p8,p9) int pri; char *fmt;
  38. {
  39.     register char *b, *f = fmt, c;
  40.     char buf[MAXLINE+50];
  41.     char oline[MAXLINE];
  42.     
  43.     if (pri > LogMask)
  44.         return;
  45.  
  46.     b = buf;
  47.     while ((c = *f++) != '\0' && b < buf + MAXLINE) 
  48.     {
  49.         if (c != '%') 
  50.         {
  51.             *b++ = c;
  52.             continue;
  53.         }
  54.         c = *f++;
  55.         if (c != 'm') 
  56.         {
  57.             *b++ = '%', *b++ = c;
  58.             continue;
  59.         }
  60.         if ((unsigned)errno > sys_nerr)
  61.             sprintf(b, "error %d", errno);
  62.         else
  63.             sprintf(b, "%s", sys_errlist[errno]);
  64.         b += strlen(b);
  65.     }
  66.     if (b[-1] != '\n')
  67.         *b++ = '\n';
  68.     *b = '\0';
  69.         
  70.     sprintf(oline, buf, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
  71.  
  72.     dprintf("%s: %s\n", LogTag,oline);
  73. }
  74.  
  75.