ecuicmaux.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. /*+------------------------------------------------------------------------
  2. ecuicmaux.c
  3. wht@wht.net
  4. Defined functions:
  5. display_ascii_names()
  6. icmd_conversion(token, narg, arg)
  7. icmd_log(token, narg, arg)
  8. nlin_nlout_control(token, narg, arg)
  9. pcmd_rlog(param)
  10. rcvr_log_control(token, narg, arg)
  11. --------------------------------------------------------------------------*/
  12. /*+:EDITS:*/
  13. /*:04-26-2000-11:15-wht@bob-RELEASE 4.42 */
  14. /*:01-24-1997-02:37-wht@yuriatin-SOURCE RELEASE 4.00 */
  15. /*:09-11-1996-20:00-wht@yuriatin-3.48-major telnet,curses,structural overhaul */
  16. /*:09-06-1996-02:23-wht@kepler-cleanup */
  17. /*:02-13-1996-15:22-wht@kepler-fix stupid semantics in log status */
  18. /*:12-03-1995-20:34-wht@gyro-cosmetics and neatness */
  19. /*:12-03-1995-20:25-wht@gyro-allow shell wild card chars in log filename */
  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. /*:03-12-1995-01:03-wht@kepler-use ECU_MAXPN */
  23. /*:05-04-1994-04:38-wht@n4hgf-ECU release 3.30 */
  24. /*:09-10-1992-13:58-wht@n4hgf-ECU release 3.20 */
  25. /*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  26. /*:02-07-1992-19:19-root@n4hgf-fix incorrect log append/write notification */
  27. /*:07-25-1991-12:56-wht@n4hgf-ECU release 3.10 */
  28. /*:07-04-1991-20:03-wht@n4hgf-make pcmd_log */
  29. /*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  30. #include "ecu.h"
  31. #include "ecuerror.h"
  32. #include "ecucmd.h"
  33. #include "esd.h"
  34. int rcvr_log = 0; /* if non-zero, logging rcvd data */
  35. char rcvr_log_file[ECU_MAXPN]; /* log filename */
  36. int rcvr_log_gen_title = 0; /* gen log header on next open (rcvr process) */
  37. FILE *rcvr_log_fp = (FILE *) 0; /* rcvr log file */
  38. int rcvr_log_append = 1;
  39. int rcvr_log_raw = 0;
  40. int rcvr_log_flusheach = 0;
  41. /*+-----------------------------------------------------------------------
  42. display_ascii_names()
  43. ------------------------------------------------------------------------*/
  44. void
  45. display_ascii_names()
  46. {
  47. int intval;
  48. char *hex_to_ascii_name();
  49. for (intval = 0; intval < 32; intval++)
  50. {
  51. ff(se, "%s %3d %03o %02x ^%c | ", hex_to_ascii_name((intval)),
  52. (intval), (intval), (intval), (intval) | 0x40);
  53. ff(se, " %3d %03o %02x %c | ",
  54. intval + 32, intval + 32, intval + 32, intval + 32);
  55. ff(se, " %3d %03o %02x %c | ",
  56. intval + 64, intval + 64, intval + 64, intval + 64);
  57. if (intval != 31)
  58. {
  59. ff(se, " %3d %03o %02x %c\r\n",
  60. intval + 96, intval + 96, intval + 96, intval + 96);
  61. }
  62. else
  63. {
  64. ff(se, " %3d %03o %02x ^?\r\n",
  65. intval + 96, intval + 96, intval + 96);
  66. }
  67. }
  68. } /* end of display_ascii_names */
  69. /*+-------------------------------------------------------------------------
  70. icmd_conversion(token,narg,arg)
  71. --------------------------------------------------------------------------*/
  72. void
  73. icmd_conversion(token, narg, arg)
  74. int token;
  75. int narg;
  76. char **arg;
  77. {
  78. int itmp;
  79. switch (token)
  80. {
  81. case CTxa:
  82. case CToa:
  83. case CTda:
  84. if (narg > 1)
  85. {
  86. int result;
  87. char format[4];
  88. sprintf(format, "%%%c", to_lower(*arg[0]));
  89. if (sscanf(arg[1], format, &result) == 0)
  90. {
  91. ff(se, " invalid argument\r\n");
  92. return;
  93. }
  94. result &= 0xFF;
  95. if (result == ' ')
  96. ff(se, " == ' ' 0x20\r\n");
  97. else
  98. ff(se, " == %s\r\n", graphic_char_text(result, 1));
  99. }
  100. else
  101. {
  102. ff(se, "\r\n");
  103. display_ascii_names();
  104. }
  105. break;
  106. case CTax:
  107. if (arg[1] == (char *)0)
  108. {
  109. ff(se, "\r\n");
  110. display_ascii_names();
  111. break;
  112. }
  113. switch (strlen(arg[1]))
  114. {
  115. case 1:
  116. ff(se, " == 0x%02x\r\n", *arg[1]);
  117. break;
  118. case 2:
  119. if (*arg[1] == '^')
  120. {
  121. itmp = to_upper(*(arg[1] + 1));
  122. if ((itmp < '@') || (itmp > '_'))
  123. {
  124. ff(se, " not a valid control character\r\n");
  125. return;
  126. }
  127. itmp &= 0x1F;
  128. ff(se, " == 0x%02x %s\r\n", itmp,
  129. graphic_char_text(itmp, 1));
  130. break;
  131. } /* else fall thru */
  132. case 3:
  133. if ((itmp = ascii_name_to_hex(arg[1])) > -1)
  134. {
  135. ff(se, " == 0x%02x %s\r\n", itmp,
  136. graphic_char_text(itmp, 1));
  137. break;
  138. } /* else fall thru */
  139. default:
  140. ff(se, " invalid ... examples of valid parameters:\r\n");
  141. ff(se, " ^A ETX or printable character\r\n");
  142. break;
  143. }
  144. break;
  145. default:
  146. ff(se, " invalid command\r\n");
  147. }
  148. } /* end of icmd_conversion */
  149. /*+-------------------------------------------------------------------------
  150. rcvr_log_control(token,narg,arg)
  151. --------------------------------------------------------------------------*/
  152. int
  153. rcvr_log_control(token, narg, arg)
  154. int token;
  155. int narg;
  156. char **arg;
  157. {
  158. int itmp;
  159. int itmp2;
  160. #if defined(M_XENIX) || defined(M_UNIX)
  161. char *lparg = "/dev/lp1";
  162. #endif
  163. switch (token)
  164. {
  165. case CTloff:
  166. goto LOG_OFF;
  167. #if defined(M_XENIX) || defined(M_UNIX)
  168. case CTllp:
  169. narg = 1;
  170. arg = &lparg;
  171. /* fall thru */
  172. #endif
  173. case CTlog:
  174. if (narg > 1)
  175. {
  176. if (minunique("off", arg[1], 3))
  177. {
  178. LOG_OFF:
  179. shmx_set_rcvr_log("", 0, 0, 0);
  180. rcvr_log = 0;
  181. rcvr_log_file[0] = 0;
  182. return (0);
  183. }
  184. /*
  185. * turning logging on
  186. */
  187. itmp2 = -1;
  188. rcvr_log_append = 1;
  189. rcvr_log_raw = 0;
  190. for (itmp = 1; itmp < narg; itmp++)
  191. {
  192. if (*arg[itmp] == '-')
  193. {
  194. switch (arg[itmp][1])
  195. {
  196. case 's':
  197. rcvr_log_append = 0;
  198. break;
  199. case 'r':
  200. rcvr_log_raw = 1;
  201. break;
  202. case 'f':
  203. rcvr_log_flusheach = 1;
  204. break;
  205. default:
  206. pprintf("unrecognized switch -%c\n",
  207. arg[itmp][1]);
  208. log_cmd_usage();
  209. return (eFATAL_ALREADY);
  210. }
  211. }
  212. else
  213. {
  214. if (itmp2 > 0)
  215. {
  216. pputs("too many arguments\n");
  217. log_cmd_usage();
  218. return (eFATAL_ALREADY);
  219. }
  220. itmp2 = itmp;
  221. }
  222. }
  223. if (itmp2 < 0)
  224. {
  225. pputs("no log file name specified\n");
  226. log_cmd_usage();
  227. return (eFATAL_ALREADY);
  228. }
  229. if (arg[itmp2][0] != '/') /* if log file not full path,
  230. * ... */
  231. { /* ... supply current directory */
  232. get_curr_dir(rcvr_log_file,
  233. sizeof(rcvr_log_file) - strlen(arg[itmp2]) - 2);
  234. strcat(rcvr_log_file, "/");
  235. strcat(rcvr_log_file, arg[itmp2]);
  236. }
  237. else
  238. strcpy(rcvr_log_file, arg[itmp2]);
  239. /* try to open the file if we can */
  240. rcvr_log_fp = fopen(rcvr_log_file, "a");
  241. if (rcvr_log_fp) /* if success */
  242. {
  243. fclose(rcvr_log_fp);
  244. rcvr_log_fp = (FILE *) 0;
  245. rcvr_log = 1;
  246. shmx_set_rcvr_log(rcvr_log_file, rcvr_log_append,
  247. rcvr_log_raw, rcvr_log_flusheach);
  248. }
  249. else
  250. /* xmtr() could not open file */
  251. {
  252. pputs("could not open ");
  253. pperror(rcvr_log_file);
  254. return (eFATAL_ALREADY);
  255. }
  256. rcvr_log_append = 1;
  257. } /* end of if argument to command */
  258. if (rcvr_log && (!proc_level || proc_trace))
  259. {
  260. pprintf("\n%sing %s received text to\n%s\n",
  261. (rcvr_log_append) ? "append" : "writ",
  262. (rcvr_log_raw) ? "raw" : "filtered",
  263. rcvr_log_file);
  264. }
  265. else if (!proc_level || proc_trace)
  266. pputs("not logging\n");
  267. break;
  268. default:
  269. pputs("invalid command\n");
  270. return (eFATAL_ALREADY);
  271. }
  272. return (0);
  273. } /* end of rcvr_log_control */
  274. /*+-------------------------------------------------------------------------
  275. pcmd_rlog(param) - control receiver logging (script)
  276. rlog [-srf] ['filename'] # see ecuidmc.d
  277. rlog 'off'
  278. This is a hack to use icmd stuff from proc language
  279. --------------------------------------------------------------------------*/
  280. int
  281. pcmd_rlog(param)
  282. ESD *param;
  283. {
  284. int erc;
  285. int lnarg = 0;
  286. char *larg[3];
  287. ESD *tesd = esdalloc(ESD_NOMSZ);
  288. char switches[8];
  289. if (!tesd)
  290. return (eNoMemory);
  291. larg[lnarg++] = "log";
  292. if (!get_switches(param, switches, sizeof(switches)))
  293. larg[lnarg++] = switches;
  294. if (!gstr(param, tesd, 1))
  295. larg[lnarg++] = tesd->pb;
  296. erc = rcvr_log_control(CTlog, lnarg, larg);
  297. esdfree(tesd);
  298. return (erc);
  299. } /* end of pcmd_rlog */
  300. /*+-------------------------------------------------------------------------
  301. icmd_log(token,narg,arg)
  302. --------------------------------------------------------------------------*/
  303. int
  304. icmd_log(token, narg, arg)
  305. int token;
  306. int narg;
  307. char **arg;
  308. {
  309. int itmp;
  310. int itmp2;
  311. char proto_fname[ECU_MAXPN];
  312. switch (token)
  313. {
  314. case CTloff:
  315. goto LOG_OFF;
  316. #if defined(M_XENIX) || defined(M_UNIX)
  317. case CTllp:
  318. icmd("log /dev/lp1");
  319. break;
  320. #endif
  321. case CTlog:
  322. if (narg > 1)
  323. {
  324. if (minunique("off", arg[1], 3))
  325. {
  326. LOG_OFF:
  327. if (rcvr_log == 0) /* "off", but not logging */
  328. goto RECORD_REPORT;
  329. ff(se, "\r\nlogging concluded (file %s)\r\n",
  330. rcvr_log_file);
  331. shmx_set_rcvr_log("", 0, 0, 0);
  332. rcvr_log = 0;
  333. rcvr_log_file[0] = 0;
  334. return (0);
  335. }
  336. /*
  337. * turning logging on
  338. */
  339. itmp2 = -1;
  340. rcvr_log_append = 1;
  341. rcvr_log_raw = 0;
  342. for (itmp = 1; itmp < narg; itmp++)
  343. {
  344. if (*arg[itmp] == '-')
  345. {
  346. switch (arg[itmp][1])
  347. {
  348. case 's':
  349. rcvr_log_append = 0;
  350. break;
  351. case 'r':
  352. rcvr_log_raw = 1;
  353. break;
  354. case 'f':
  355. rcvr_log_flusheach = 1;
  356. break;
  357. default:
  358. ff(se, " unrecognized switch -%c\r\n",
  359. arg[itmp][1]);
  360. log_cmd_usage();
  361. return (eFATAL_ALREADY);
  362. }
  363. }
  364. else
  365. {
  366. if (itmp2 > 0)
  367. {
  368. ff(se, " too many positional arguments\r\n");
  369. log_cmd_usage();
  370. return (eFATAL_ALREADY);
  371. }
  372. itmp2 = itmp;
  373. }
  374. }
  375. if (itmp2 < 0)
  376. {
  377. ff(se, " no log file name specified\r\n");
  378. log_cmd_usage();
  379. return (eFATAL_ALREADY);
  380. }
  381. /*
  382. * expand wild card chars
  383. */
  384. strncpy(proto_fname, arg[itmp2], sizeof(proto_fname));
  385. proto_fname[sizeof(proto_fname) - 1] = 0;
  386. if (expand_filename(proto_fname, sizeof(proto_fname)))
  387. goto RECORD_REPORT;
  388. /*
  389. * if log file not full path, supply current directory
  390. */
  391. if (proto_fname[0] != '/')
  392. {
  393. get_curr_dir(rcvr_log_file,
  394. sizeof(rcvr_log_file) - strlen(proto_fname) - 2);
  395. strcat(rcvr_log_file, "/");
  396. strcat(rcvr_log_file, proto_fname);
  397. }
  398. else
  399. strcpy(rcvr_log_file, proto_fname);
  400. /*
  401. * try to open the file if we can
  402. */
  403. rcvr_log_fp = fopen(rcvr_log_file, "a");
  404. if (rcvr_log_fp) /* if success */
  405. {
  406. fclose(rcvr_log_fp);
  407. rcvr_log_fp = (FILE *) 0;
  408. rcvr_log = 1;
  409. shmx_set_rcvr_log(rcvr_log_file, rcvr_log_append,
  410. rcvr_log_raw, rcvr_log_flusheach);
  411. }
  412. else
  413. {
  414. /*
  415. * xmtr() could not open file
  416. */
  417. ff(se, " could not open ");
  418. perror(rcvr_log_file);
  419. ff(se, "\r\n");
  420. return (eFATAL_ALREADY);
  421. }
  422. } /* end of if argument to command */
  423. RECORD_REPORT:
  424. if (rcvr_log)
  425. {
  426. ff(se, "\r\n%sing %s received text to\r\n%s\r\n",
  427. (rcvr_log_append) ? "append" : "writ",
  428. (rcvr_log_raw) ? "raw" : "filtered",
  429. rcvr_log_file);
  430. ff(se, "use \"HOME log off\" to stop logging\r\n");
  431. }
  432. else
  433. {
  434. ff(se, " not logging.\r\n");
  435. ff(se, "use \"HOME slog <filename>\" to start logging\r\n");
  436. }
  437. break;
  438. default:
  439. ff(se, " invalid command\r\n");
  440. return (eFATAL_ALREADY);
  441. }
  442. rcvr_log_append = 1;
  443. return (0);
  444. } /* end of icmd_log */
  445. /*+-------------------------------------------------------------------------
  446. nlin_nlout_control(token,narg,arg)
  447. --------------------------------------------------------------------------*/
  448. void
  449. nlin_nlout_control(token, narg, arg)
  450. int token;
  451. int narg;
  452. char **arg;
  453. {
  454. switch (token)
  455. {
  456. case CTnlin:
  457. if (narg != 1)
  458. shm->Ladd_nl_incoming = yes_or_no(arg[1]);
  459. ff(se, " %sappending NL to incoming CR\r\n",
  460. (shm->Ladd_nl_incoming) ? "" : "not ");
  461. break;
  462. case CTnlout:
  463. if (narg != 1)
  464. shm->Ladd_nl_outgoing = yes_or_no(arg[1]);
  465. ff(se, " %sappending NL to outgoing CR\r\n",
  466. (shm->Ladd_nl_outgoing) ? "" : "not ");
  467. break;
  468. default:
  469. case CTnl:
  470. ff(se, " incoming: %s outgoing: %s\r\n",
  471. (shm->Ladd_nl_incoming) ? "CR/LF" : "CR",
  472. (shm->Ladd_nl_outgoing) ? "CR/LF" : "CR");
  473. break;
  474. }
  475. } /* end of nlin_nlout_control */
  476. /* end of ecuicmaux.c */
  477. /* vi: set tabstop=4 shiftwidth=4: */