logevent.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*+-------------------------------------------------------------------------
  2. logevent.c - log ecu event
  3. wht@wht.net
  4. Defined functions:
  5. logevent(pid, event_note)
  6. vlogevent(pid, format, va_alist)
  7. --------------------------------------------------------------------------*/
  8. /*+:EDITS:*/
  9. /*:04-26-2000-11:16-wht@bob-RELEASE 4.42 */
  10. /*:01-24-1997-02:37-wht@yuriatin-SOURCE RELEASE 4.00 */
  11. /*:09-11-1996-20:00-wht@yuriatin-3.48-major telnet,curses,structural overhaul */
  12. /*:08-11-1996-02:14-wht@kepler-add vlogevent */
  13. /*:08-11-1996-02:10-wht@kepler-rename ecu_log_event to logevent */
  14. /*:11-23-1995-11:20-wht@kepler-source control 3.37 for tsx-11 */
  15. /*:11-14-1995-10:23-wht@kepler-3.37.80-source control point: SOCKETS */
  16. /*:05-04-1994-04:39-wht@n4hgf-ECU release 3.30 */
  17. /*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  18. /*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
  19. /*:08-21-1991-02:00-wht@n4hgf-sun does not have xenix locking - fix later */
  20. /*:08-07-1991-14:23-wht@n4hgf-use static logname */
  21. /*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 */
  22. /*:09-19-1990-19:36-wht@n4hgf-logevent now gets pid for log from caller */
  23. /*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  24. #include <stdio.h>
  25. #if defined(USE_LOCKING)
  26. #include <sys/locking.h>
  27. #endif
  28. #include <string.h>
  29. #include <stdarg.h>
  30. /* This must be a typedef not a #define! */
  31. typedef char *pointer;
  32. typedef int *intp;
  33. /*+-------------------------------------------------------------------------
  34. logevent(pid,event_note)
  35. --------------------------------------------------------------------------*/
  36. void
  37. logevent(pid, event_note)
  38. int pid;
  39. char *event_note;
  40. {
  41. char s32[32];
  42. FILE *ecu_log_fp;
  43. static char logname[256] = "";
  44. if (!logname[0])
  45. {
  46. get_home_dir(logname);
  47. strcat(logname, "/.ecu/log");
  48. }
  49. if (ecu_log_fp = fopen(logname, "a"))
  50. {
  51. #if defined(USE_LOCKING)
  52. locking(fileno(ecu_log_fp), LK_LOCK, 0L);
  53. #endif
  54. timeofday_text(4, s32);
  55. s32[10] = '-';
  56. fputs(s32, ecu_log_fp);
  57. fprintf(ecu_log_fp, "-%05d-", pid);
  58. fputs(event_note, ecu_log_fp);
  59. fputs("\n", ecu_log_fp);
  60. #if defined(USE_LOCKING)
  61. fflush(ecu_log_fp);
  62. locking(fileno(ecu_log_fp), LK_UNLCK, 0L);
  63. #endif
  64. fclose(ecu_log_fp);
  65. }
  66. } /* end of logevent */
  67. void vlogevent(pid, format, va_alist) { }
  68. /*+-------------------------------------------------------------------------
  69. vlogevent(pid,format,va_alist)
  70. --------------------------------------------------------------------------*/
  71. /*void
  72. vlogevent(pid, format, va_alist)
  73. int pid;
  74. char *format;
  75. va_dcl
  76. {
  77. va_list args;
  78. char c;
  79. char *tp;
  80. char tempfmt[64];
  81. char accum_string[256];
  82. char *dp = accum_string;
  83. va_start(args);
  84. tempfmt[0] = '%';
  85. while (c = *format++)
  86. {
  87. if (c == '%')
  88. {
  89. tp = &tempfmt[1];
  90. continue_format:
  91. switch (c = *format++)
  92. {
  93. case 's':
  94. *tp++ = c;
  95. *tp = '\0';
  96. sprintf(dp, tempfmt, va_arg(args, char *));
  97. dp += strlen(dp);
  98. break;
  99. case 'u':
  100. case 'x':
  101. case 'o':
  102. case 'X':
  103. #if defined(UNSIGNEDSPECIAL)
  104. *tp++ = c;
  105. *tp = '\0';
  106. sprintf(dp, tempfmt, va_arg(args, unsigned));
  107. dp += strlen(dp);
  108. break;
  109. #endif
  110. case 'd':
  111. case 'c':
  112. case 'i':
  113. *tp++ = c;
  114. *tp = '\0';
  115. sprintf(dp, tempfmt, va_arg(args, int));
  116. dp += strlen(dp);
  117. break;
  118. case 'f':
  119. case 'e':
  120. case 'E':
  121. case 'g':
  122. case 'G':
  123. *tp++ = c;
  124. *tp = '\0';
  125. sprintf(dp, tempfmt, va_arg(args, double));
  126. dp += strlen(dp);
  127. break;
  128. case '-':
  129. case '+':
  130. case '0':
  131. case '1':
  132. case '2':
  133. case '3':
  134. case '4':
  135. case '5':
  136. case '6':
  137. case '7':
  138. case '8':
  139. case '9':
  140. case '.':
  141. case ' ':
  142. case '#':
  143. case 'h':
  144. *tp++ = c;
  145. goto continue_format;
  146. case 'l':
  147. goto continue_format;
  148. case '*':
  149. sprintf(tp, "%d", va_arg(args, int));
  150. tp += strlen(tp);
  151. goto continue_format;
  152. case '%':
  153. default:
  154. *dp++ = c;
  155. break;
  156. }
  157. }
  158. else
  159. *dp++ = c;
  160. }
  161. *dp = '\0';
  162. va_end(args);
  163. logevent(pid, accum_string);
  164. }*/ /* end of vlogevent */
  165. /* vi: set tabstop=4 shiftwidth=4: */
  166. /* end of logevent.c */