home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Kernel / Utils / errMsg.c next >
Encoding:
C/C++ Source or Header  |  1990-08-17  |  3.3 KB  |  155 lines

  1. #include <stdio.h>
  2. #include <sys/types.h>
  3.  
  4. #undef integer        /* Silly stdtypes */
  5. #include "Kernel/h/system.h"
  6. #include "Kernel/h/mmTypes.h"
  7. #include "Kernel/h/mmCodes.h"
  8. #include "Kernel/h/unixCodes.h"
  9. #include "Kernel/h/mmBufTypes.h"
  10. #include "Kernel/h/mmFifoTypes.h"
  11. #include "Kernel/h/mmMsgDefs.h"
  12. #include "Kernel/h/mmMsgTypes.h"
  13.  
  14. #include "Kernel/h/kmdDefs.h"
  15. #include "Kernel/h/kmdTypes.h"
  16. /* Special in this file: Undefine the macro for DebugMsg! */
  17. #undef DebugMsg
  18.  
  19. #ifndef NODISK
  20. extern char nodisk;
  21. #endif
  22.  
  23. int DebugLevel=0;    /* Level of debugging output wanted */
  24. FILE *logout = (FILE *) 0; /* fp for log file */
  25. char *ctime ();
  26. int IamPOD;
  27.  
  28. /*
  29.  * DebugMsg(level, <printf arguments> ... )
  30.  *
  31.  * Prints out a message to help with debugging.  This is an old Unix
  32.  * hack to allow a variable number of arguments to doprnt.  It is a
  33.  * terrible hack but I don't know how else to do it.  This should
  34.  * eventually be changed to put messages in a file or out an IPC
  35.  * port or something.
  36.  */
  37.  
  38. #ifdef USEREALDEBUGMSG
  39. /*VARARGS1*/
  40. DebugMsg(level, fmt, args)
  41. int level;
  42. char *fmt;
  43. int args;
  44. {
  45.     struct _iobuf _strbuf;
  46.     char str[500];
  47.     char fullfmt[132];
  48.     
  49.     if (DebugLevel >= level) {
  50.         _strbuf._flag = _IOWRT+_IOSTRG;
  51.         _strbuf._ptr = str;
  52.         _strbuf._cnt = 32767;
  53.         sprintf(fullfmt, "%s: ", MMTraceHost);
  54.         (void) strcat(fullfmt,fmt);
  55.         _doprnt(fullfmt, &args, &_strbuf);
  56.         putc('\0',&_strbuf);
  57.         printf("%s",str);
  58.                 if (level == 0)
  59.                     LogMsg (fmt, (char *) &args);
  60.         };        
  61.         KMDTracex("DebugMsg", level, fmt, &args);
  62. }
  63. #endif  USEREALDEBUGMSG
  64.  
  65. /*VARARGS2*/
  66. void DebugMsg1(level, fmt, args)
  67. int level;
  68. char *fmt;
  69. int *args;
  70. {
  71.     struct _iobuf _strbuf;
  72.     char str[500];
  73.     char fullfmt[132];
  74.     
  75.     if (DebugLevel >= level) {
  76.         _strbuf._flag = _IOWRT+_IOSTRG;
  77. #ifdef vax
  78.         _strbuf._ptr = str;
  79. #else
  80.         _strbuf._ptr = (unsigned char *)str;
  81. #endif
  82.         _strbuf._cnt = 32767;
  83.         sprintf(fullfmt, "%s: ", MMTraceHost);
  84.         (void) strcat(fullfmt, fmt);
  85.         _doprnt(fullfmt, &args, &_strbuf);
  86.         putc('\0',&_strbuf);
  87.         printf("%s",str);
  88.                 if (level == 0)
  89.                     LogMsg (fmt, (char *) &args);
  90.         };
  91.         KMDTracex("DebugMsg", level, fmt, &args);
  92. }
  93.  
  94. /*
  95.  * ErrMsg
  96.  *
  97.  * A lot like DebugMsg, but for more fatal errors.
  98.  */
  99.  
  100. /*VARARGS1*/
  101. void ErrMsg(fmt, args)
  102. char *fmt;
  103. int  args;
  104. {
  105.   struct _iobuf _strbuf;
  106.   char fullfmt[2000];
  107.  
  108.   printf("%s: ", MMTraceHost);
  109. #ifdef BSD
  110.   _doprnt(fmt, &args, stdout);
  111. #else
  112.   _strbuf._flag = _IOWRT+_IOSTRG;
  113. #ifdef vax
  114.   _strbuf._ptr = fullfmt;
  115. #else
  116.   _strbuf._ptr = (unsigned char *)fullfmt;
  117. #endif
  118.   _strbuf._cnt = 32767;
  119.   _doprnt(fmt, &args, &_strbuf);
  120.   putc('\0',&_strbuf);
  121.   printf("%s",fullfmt);
  122. #endif
  123.   LogMsg (fmt, (char *) &args);
  124. }
  125.  
  126. /*
  127.  * LogMsg
  128.  * 
  129.  * Prints out a message to a log file, along with the current time.
  130.  * Log file only exists for Process B and POD.
  131.  * Because of the way fargs is passed, this should not be called directly, but
  132.  * through DebugMsg or ErrMsg.
  133.  */
  134. static
  135. /*VARARGS*/
  136. LogMsg (fmt, fargs)
  137. char *fmt, *fargs;
  138. {
  139.   time_t      t;
  140.   char       *p;
  141.  
  142. #ifndef NODISK
  143.   if(!nodisk) {
  144.     if (logout) {
  145.       t = time ( (time_t *) 0);
  146.       p = ctime (&t);
  147.       *(p + strlen (p) - 1) = '\0';
  148.       fprintf (logout, "%s: ", p);
  149.       _doprnt(fmt, fargs, logout);
  150.       (void) fflush (logout);
  151.     }
  152.   }
  153. #endif
  154. }
  155.