poutput.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*+-------------------------------------------------------------------------
  2. poutput.c - ecu procedure output routines
  3. wht@wht.net
  4. Defined functions:
  5. pcmd_plog(param)
  6. pflush()
  7. plog_control(fname)
  8. plogc(ch)
  9. plogs(str)
  10. poutput_init()
  11. pperror(str)
  12. pputc(ch)
  13. pputs(str)
  14. --------------------------------------------------------------------------*/
  15. /*+:EDITS:*/
  16. /*:04-26-2000-11:16-wht@bob-RELEASE 4.42 */
  17. /*:01-24-1997-02:38-wht@yuriatin-SOURCE RELEASE 4.00 */
  18. /*:09-11-1996-20:01-wht@yuriatin-3.48-major telnet,curses,structural overhaul */
  19. /*:12-06-1995-13:30-wht@n4hgf-termecu w/errno -1 consideration */
  20. /*:11-23-1995-11:20-wht@kepler-source control 3.37 for tsx-11 */
  21. /*:11-14-1995-10:23-wht@kepler-3.37.80-source control point: SOCKETS */
  22. /*:05-04-1994-04:39-wht@n4hgf-ECU release 3.30 */
  23. /*:09-10-1992-14:00-wht@n4hgf-ECU release 3.20 */
  24. /*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
  25. /*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  26. /*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  27. #include "ecu.h"
  28. #include "ecukey.h"
  29. #include "ecuerror.h"
  30. #include "esd.h"
  31. extern FILE *rcvr_log_fp;
  32. FILE *plog_fp = (FILE *) 0;
  33. ESD *plog_name = (ESD *) 0;
  34. /*+-------------------------------------------------------------------------
  35. plogs(str)
  36. --------------------------------------------------------------------------*/
  37. void
  38. plogs(str)
  39. char *str;
  40. {
  41. if (plog_fp)
  42. fputs(str, plog_fp);
  43. } /* end of plogs */
  44. /*+-------------------------------------------------------------------------
  45. plogc(ch)
  46. --------------------------------------------------------------------------*/
  47. void
  48. plogc(ch)
  49. char ch;
  50. {
  51. if (plog_fp)
  52. fputc(ch, plog_fp);
  53. } /* end of plogc */
  54. /*+-------------------------------------------------------------------------
  55. pputc(ch) - put procedure output character to stderr and log
  56. --------------------------------------------------------------------------*/
  57. void
  58. pputc(ch)
  59. char ch;
  60. {
  61. if (ch == NL)
  62. fputc(CRET, se);
  63. fputc(ch, se);
  64. if (plog_fp && (ch != CRET))
  65. fputc(ch, plog_fp);
  66. if (rcvr_log_fp && (ch != CRET))
  67. fputc(ch, rcvr_log_fp);
  68. } /* end of pputc */
  69. /*+-------------------------------------------------------------------------
  70. pputs(str) - put procedure output string to stderr and log
  71. --------------------------------------------------------------------------*/
  72. void
  73. pputs(str)
  74. char *str;
  75. {
  76. while (*str)
  77. {
  78. if (*str == NL)
  79. fputc(CRET, se);
  80. fputc(*str, se);
  81. if (plog_fp && (*str != CRET))
  82. fputc(*str, plog_fp);
  83. if (rcvr_log_fp && (*str != CRET))
  84. fputc(*str, rcvr_log_fp);
  85. str++;
  86. }
  87. } /* end of pputs */
  88. /*+-------------------------------------------------------------------------
  89. pflush()
  90. --------------------------------------------------------------------------*/
  91. void
  92. pflush()
  93. {
  94. if (plog_fp)
  95. fflush(plog_fp);
  96. } /* end of pflush */
  97. /*+-------------------------------------------------------------------------
  98. pperror(str)
  99. --------------------------------------------------------------------------*/
  100. void
  101. pperror(str)
  102. char *str;
  103. {
  104. int save_errno = errno;
  105. if (str && *str)
  106. {
  107. pputs(str);
  108. pputs(": ");
  109. }
  110. pputs(strerror(save_errno));
  111. pputs("\n");
  112. } /* end of pperror */
  113. /*+-------------------------------------------------------------------------
  114. plog_control(fname)
  115. fname == 0, close
  116. fname == 1, plog_name already plugged
  117. --------------------------------------------------------------------------*/
  118. int
  119. plog_control(fname)
  120. char *fname;
  121. {
  122. if (!fname) /* close */
  123. {
  124. if (plog_fp)
  125. fclose(plog_fp);
  126. plog_fp = (FILE *) 0;
  127. return (0);
  128. }
  129. if (plog_fp)
  130. plog_control((char *)0);
  131. if (fname != (char *)1)
  132. {
  133. strcpy(plog_name->pb, fname);
  134. plog_name->cb = strlen(fname);
  135. }
  136. if ((plog_fp = fopen(plog_name->pb, "a")) == NULL)
  137. {
  138. pperror(plog_name->pb);
  139. return (eFATAL_ALREADY);
  140. }
  141. return (0);
  142. } /* end of plog_control */
  143. /*+-------------------------------------------------------------------------
  144. pcmd_plog(param)
  145. plog $s0 log to file
  146. plog off stop logging
  147. plog show status
  148. --------------------------------------------------------------------------*/
  149. int
  150. pcmd_plog(param)
  151. ESD *param;
  152. {
  153. int erc = eSyntaxError;
  154. char off_str[8];
  155. if (!skip_cmd_break(param)) /* if arguments */
  156. {
  157. if (!get_alpha_zstr(param, off_str, sizeof(off_str)))
  158. {
  159. if (strcmp(off_str, "off"))
  160. return (eBadParameter);
  161. erc = plog_control((char *)0);
  162. }
  163. else
  164. {
  165. if (erc = gstr(param, plog_name, 1))
  166. return (erc);
  167. erc = plog_control((char *)1);
  168. }
  169. }
  170. return (erc);
  171. } /* end of pcmd_plog */
  172. /*+-------------------------------------------------------------------------
  173. poutput_init()
  174. --------------------------------------------------------------------------*/
  175. void
  176. poutput_init()
  177. {
  178. if (!(plog_name = esdalloc(ESD_NOMSZ)))
  179. {
  180. ff(se, "poutput_init: Out of memory\r\n");
  181. errno = -1;
  182. termecu(TERMECU_MALLOC);
  183. }
  184. } /* end of poutput_init */
  185. /* vi: set tabstop=4 shiftwidth=4: */
  186. /* end of poutput.c */