ecugrabbag.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984
  1. /*+-----------------------------------------------------------------
  2. ecugrabbag.c -- very machine/OS dependent functions
  3. wht@wht.net
  4. Defined functions:
  5. bell_alarm(xbell_type)
  6. bell_notify(xbell_type)
  7. bell_notify_text(bn)
  8. kbd_escape(xkey)
  9. morse_bell(xbell_type, count)
  10. parse_bell_notify_argument(strarg)
  11. rename(from, to)
  12. send_bell_fd(fd, count, nap_msec)
  13. send_get_response(narg, arg)
  14. set_bell_fd(fd, pitch, duration)
  15. set_default_escape_prompt()
  16. show_escape_prompt()
  17. signal_name_text(sig)
  18. xbell(type, count)
  19. xbell_fd(fd, type, count)
  20. xterm_title(text, code)
  21. This module is a grab bag for historical reasons. Needs reorg.
  22. Like so many Americans, she was trying to construct a life that
  23. made sense from things she found in gift shops. -- Kurt
  24. Vonnegut, Jr.
  25. ------------------------------------------------------------------*/
  26. /*+:EDITS:*/
  27. /*:04-26-2000-11:15-wht@bob-RELEASE 4.42 */
  28. /*:01-24-1997-02:37-wht@yuriatin-SOURCE RELEASE 4.00 */
  29. /*:09-11-1996-20:00-wht@yuriatin-3.48-major telnet,curses,structural overhaul */
  30. /*:08-20-1996-12:39-wht@kepler-locale/ctype fixes from ache@nagual.ru */
  31. /*:08-11-1996-02:10-wht@kepler-rename ecu_log_event to logevent */
  32. /*:11-23-1995-11:20-wht@kepler-source control 3.37 for tsx-11 */
  33. /*:11-14-1995-10:23-wht@kepler-3.37.80-source control point: SOCKETS */
  34. /*:05-11-1995-15:55-wht@n4hgf-ck_sigint fools optimizing compilers */
  35. /*:04-02-1995-04:06-wht@n4hgf-sgr command bug on console display */
  36. /*:01-12-1995-15:19-wht@n4hgf-apply Andrew Chernov 8-bit clean+FreeBSD patch */
  37. /*:12-27-1994-15:12-wht@n4hgf-turn on rename if CFG_FakeRename */
  38. /*:05-04-1994-04:38-wht@n4hgf-ECU release 3.30 */
  39. /*:11-12-1993-11:00-wht@n4hgf-Linux changes by bob@vancouver.zadall.com */
  40. /*:08-07-1993-21:16-wht@n4hgf-entering history mgr from col > 1 caused glitch */
  41. /*:01-01-1993-12:52-wht@n4hgf-add procedure binding for function keys */
  42. /*:12-20-1992-12:37-wht@n4hgf-WHT experiment with attributes */
  43. /*:09-10-1992-13:58-wht@n4hgf-ECU release 3.20 */
  44. /*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  45. /*:04-09-1992-05:47-wht@n4hgf-cleanup new "bn" argument parsing */
  46. /*:02-16-1992-01:41-wht@n4hgf-turn off xterm_title */
  47. /*:12-13-1991-17:14-wht@n4hgf-add bell_notify_text */
  48. /*:12-13-1991-17:14-wht@n4hgf-add parse_bell_notify_argument */
  49. /*:09-03-1991-18:23-wht@n4hgf-sigint rearrangement in send_get_response */
  50. /*:08-28-1991-14:07-wht@n4hgf2-SVR4 cleanup by aega84!lh */
  51. /*:08-13-1991-15:28-wht@n4hgf-more problems with history manager */
  52. /*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  53. /*:07-17-1991-07:04-wht@n4hgf-avoid SCO UNIX nap bug */
  54. /*:07-14-1991-18:18-wht@n4hgf-new ttygets functions */
  55. /*:06-29-1991-15:42-wht@n4hgf-if WHT and xterm, play with title bar */
  56. /*:06-04-1991-13:19-wht@n4hgf-WHT version always gets morse for bells */
  57. /*:05-07-1991-06:10-wht@n4hgf-subtle changes in send_and_get_response */
  58. /*:03-18-1991-22:31-wht@n4hgf-ISC 2.2 has rename() */
  59. /*:01-16-1991-23:54-wht@n4hgf-if WHT, bell_notify always available */
  60. /*:01-09-1991-22:31-wht@n4hgf-ISC port */
  61. /*:12-04-1990-03:55-wht@n4hgf-bell_notify only if on multiscreen */
  62. /*:09-19-1990-19:36-wht@n4hgf-logevent now gets pid for log from caller */
  63. /*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  64. #include "ecu.h"
  65. #include "ecukey.h"
  66. #include "ecufkey.h"
  67. #include "ecuxkey.h"
  68. #include "ecutty.h"
  69. #include "ecufork.h"
  70. #include "esd.h"
  71. #if defined(MORSE)
  72. /* the space between # and include prevents make depend from seeing this */
  73. #include <local/morse_dvr.h>
  74. #endif
  75. char *get_ttyname();
  76. extern char curr_dir[]; /* current working key defns */
  77. extern KDE keyset_table[];
  78. extern char keyset_name[];
  79. ESD *icmd_prompt; /* interactive command prompt */
  80. int icmd_prompt_len;
  81. /*+-------------------------------------------------------------------------
  82. show_escape_prompt()
  83. returns number of character positions written to screen
  84. --------------------------------------------------------------------------*/
  85. int
  86. show_escape_prompt()
  87. {
  88. char prompt_last;
  89. prompt_last = 'd'; /* dummy */
  90. if (icmd_prompt->cb)
  91. prompt_last = *(icmd_prompt->pb + icmd_prompt->cb - 1);
  92. icmd_prompt_len = 0;
  93. shmx_make_rcvr_sleep(1);
  94. if (!(colors_current & 0xFFFF0000L) || !(colors_current & 0xFFFFL))
  95. setcolor(colors_normal);
  96. else
  97. setcolor(colors_current);
  98. #ifdef WHT
  99. tcap_bold_on();
  100. tcap_underscore_on();
  101. #else
  102. tcap_stand_out();
  103. #endif
  104. if (icmd_prompt->cb)
  105. {
  106. ff(se, " %s", icmd_prompt->pb);
  107. icmd_prompt_len += icmd_prompt->cb + 1;
  108. }
  109. if (isalnum((uchar) prompt_last))
  110. {
  111. fputs(" %", se);
  112. icmd_prompt_len += 2;
  113. }
  114. #ifdef WHT
  115. tcap_bold_off();
  116. tcap_underscore_off();
  117. #else
  118. tcap_stand_end();
  119. #endif
  120. fputc(' ', se);
  121. icmd_prompt_len++;
  122. return (icmd_prompt_len);
  123. } /* end of show_escape_prompt */
  124. /*+-------------------------------------------------------------------------
  125. set_default_escape_prompt()
  126. --------------------------------------------------------------------------*/
  127. void
  128. set_default_escape_prompt()
  129. {
  130. char *cp;
  131. char *getenv();
  132. if ((cp = getenv("ECUPROMPT")) != (char *)0)
  133. {
  134. strncpy(icmd_prompt->pb, cp, icmd_prompt->maxcb);
  135. *(icmd_prompt->pb + icmd_prompt->maxcb - 1) = 0;
  136. icmd_prompt->cb = strlen(icmd_prompt->pb);
  137. esd_null_terminate(icmd_prompt);
  138. }
  139. } /* end of set_default_escape_prompt */
  140. /*+-------------------------------------------------------------------------
  141. kbd_escape() -- xmtr got extended key -- process it
  142. returns(1)
  143. --------------------------------------------------------------------------*/
  144. kbd_escape(xkey)
  145. UINT xkey;
  146. {
  147. int itmp;
  148. int ttygets_flags = TG_XDELIM;
  149. UINT delim;
  150. int strpos;
  151. int old_ttymode = get_ttymode();
  152. int backspace_count;
  153. KDE *tkde;
  154. uchar icmd_buf[128];
  155. if ((xkey >= XF_ALTA) && (xkey <= XF_ALTZ))
  156. {
  157. char alt_key_proc_name[8];
  158. char *arg = alt_key_proc_name;
  159. int narg = 1;
  160. int restart_rcvr = need_rcvr_restart();
  161. kill_rcvr_process(SIGUSR1);
  162. sprintf(alt_key_proc_name, "alt_%c", xkey - XF_ALTA + 'a');
  163. ttymode(2);
  164. ttyflush(0);
  165. if (do_proc(narg, &arg))
  166. ring_bell();
  167. sigint = 0;
  168. proc_file_reset();
  169. ttymode(old_ttymode);
  170. if (restart_rcvr)
  171. start_rcvr_process(0);
  172. return (1);
  173. }
  174. switch (xkey)
  175. {
  176. case XFhome: /* home key pressed ? */
  177. icmd_buf[0] = 0;
  178. backspace_count = show_escape_prompt();
  179. strpos = 0;
  180. icmd_buf[0] = 0;
  181. GET_ICMD:
  182. ttygets(icmd_buf, sizeof(icmd_buf), ttygets_flags, &delim, &strpos);
  183. switch (delim)
  184. {
  185. case XFhome:
  186. case XFpgup:
  187. case XFcurup:
  188. itmp = strlen((char *)icmd_buf);
  189. while (itmp--)
  190. ff(se, "\b \b");
  191. if (icmd_history_manager(delim, icmd_buf, sizeof(icmd_buf)))
  192. {
  193. ring_bell();
  194. ttygets_flags |= 4;
  195. goto GET_ICMD;
  196. }
  197. break;
  198. case ESC:
  199. case NL:
  200. break;
  201. default:
  202. ring_bell();
  203. itmp = strlen((char *)icmd_buf);
  204. while (itmp--)
  205. ff(se, "\b \b");
  206. ttygets_flags |= 4;
  207. goto GET_ICMD;
  208. }
  209. if ((delim == ESC) || !icmd_buf[0])
  210. {
  211. while (backspace_count--)
  212. ff(se, "\b \b");
  213. break;
  214. }
  215. if (icmd(icmd_buf))
  216. termecu(TERMECU_OK);
  217. break;
  218. default:
  219. if ((itmp = xf_to_ikde(xkey)) < 0)
  220. {
  221. ring_bell();
  222. break;
  223. }
  224. tkde = &keyset_table[itmp];
  225. if ((itmp = tkde->count) > 0)
  226. {
  227. char *cp = tkde->str;
  228. while (itmp--)
  229. lputc(*cp++);
  230. }
  231. else if (tkde->count < 0)
  232. {
  233. switch (tkde->count)
  234. {
  235. case KACT_LOCAL_SHELL:
  236. fputs("\r\n", se);
  237. tcap_stand_out();
  238. ff(se, " local shell in %s ", curr_dir);
  239. tcap_stand_end();
  240. ff(se, "\r\n");
  241. shell("!");
  242. break;
  243. case KACT_REDISPLAY:
  244. redisplay_rcvr_screen();
  245. break;
  246. case KACT_PROC:
  247. {
  248. #define ARG_MAX_QUAN 32
  249. char *arg[ARG_MAX_QUAN];
  250. int narg;
  251. build_arg_array(tkde->str, arg, ARG_MAX_QUAN, &narg);
  252. kill_rcvr_process(SIGUSR1);
  253. ttymode(2);
  254. do_proc(narg, arg);
  255. proc_file_reset();
  256. ttymode(1);
  257. sigint = 0;
  258. }
  259. break;
  260. }
  261. }
  262. else
  263. ring_bell();
  264. break;
  265. }
  266. return (1);
  267. } /* end of kbd_escape */
  268. /*+-------------------------------------------------------------------------
  269. set_bell_fd(fd,pitch,duration)
  270. Example: 1B 5B 3D 34 30 30 30 3B 31 42 | .[=4000;1B
  271. --------------------------------------------------------------------------*/
  272. void
  273. set_bell_fd(fd, pitch, duration)
  274. int fd;
  275. int pitch;
  276. int duration;
  277. {
  278. #if defined(M_SYSV) || defined(SCO32v5)
  279. char bell_cmd[32];
  280. if (!tty_is_multiscreen)
  281. return;
  282. sprintf(bell_cmd, "\033[=%d;%dB", pitch, duration);
  283. write(fd, bell_cmd, strlen(bell_cmd));
  284. #else
  285. /*
  286. * shut up gcc warnings
  287. */
  288. fd = pitch = duration = 0;
  289. #endif
  290. } /* end of set_bell_fd */
  291. /*+-------------------------------------------------------------------------
  292. send_bell_fd(fd,count,nap_msec)
  293. --------------------------------------------------------------------------*/
  294. void
  295. send_bell_fd(fd, count, nap_msec)
  296. int fd;
  297. int count;
  298. int nap_msec;
  299. {
  300. static char bellch = 0x07;
  301. if (count)
  302. {
  303. while (count--)
  304. {
  305. write(fd, &bellch, 1);
  306. Nap((long)nap_msec);
  307. }
  308. }
  309. } /* end of send_bell_fd */
  310. /*+-------------------------------------------------------------------------
  311. xbell_fd(fd,type,count)
  312. --------------------------------------------------------------------------*/
  313. void
  314. xbell_fd(fd, type, count)
  315. int fd;
  316. int type;
  317. int count;
  318. {
  319. #if defined(M_SYSV) || defined(SCO32v5)
  320. int itmp;
  321. if (!tty_is_multiscreen)
  322. {
  323. ring_bell();
  324. return;
  325. }
  326. if (count)
  327. {
  328. while (count--)
  329. {
  330. switch (type)
  331. {
  332. case XBELL_DONE: /* octaves */
  333. set_bell_fd(fd, 1000, 1);
  334. send_bell_fd(fd, 1, 100);
  335. set_bell_fd(fd, 2000, 1);
  336. send_bell_fd(fd, 1, 100);
  337. set_bell_fd(fd, 4000, 1);
  338. send_bell_fd(fd, 1, 100);
  339. break;
  340. case XBELL_ATTENTION: /* morse .-.-.- ATTENTION */
  341. for (itmp = 0; itmp < 3; itmp++)
  342. {
  343. set_bell_fd(fd, 2000, 1);
  344. send_bell_fd(fd, 1, 140);
  345. set_bell_fd(fd, 2000, 3);
  346. send_bell_fd(fd, 1, 340);
  347. }
  348. break;
  349. case XBELL_C: /* morse -.-. C */
  350. for (itmp = 0; itmp < 2; itmp++)
  351. {
  352. set_bell_fd(fd, 2000, 3);
  353. send_bell_fd(fd, 1, 320);
  354. set_bell_fd(fd, 2000, 1);
  355. send_bell_fd(fd, 1, 120);
  356. }
  357. break;
  358. case XBELL_3T: /* 3 morse T's */
  359. set_bell_fd(fd, 2000, 3);
  360. send_bell_fd(fd, 3, 460);
  361. break;
  362. default:
  363. set_bell_fd(fd, 2000, 4);
  364. send_bell_fd(fd, 1, 100);
  365. break;
  366. }
  367. }
  368. }
  369. set_bell_fd(fd, 4000, 1);
  370. #else
  371. /*
  372. * shut up gcc warnings
  373. */
  374. fd = type = count = 0;
  375. #endif
  376. } /* end of xbell_fd */
  377. /*+-------------------------------------------------------------------------
  378. morse_bell(xbell_type,count)
  379. --------------------------------------------------------------------------*/
  380. #if defined(MORSE)
  381. morse_bell(xbell_type, count)
  382. int xbell_type;
  383. int count;
  384. {
  385. int morse_fd;
  386. int morse_frequency = 800;
  387. char morse_char;
  388. static int morse_ticks = 0;
  389. #if !defined(WHT)
  390. if (!tty_is_multiscreen)
  391. {
  392. ring_bell();
  393. return (0);
  394. }
  395. #endif
  396. if (!morse_ticks)
  397. morse_ticks = hertz / 25;
  398. if ((morse_fd = open("/dev/morse", O_WRONLY, 0)) < 0)
  399. return (-1);
  400. ioctl(morse_fd, MORSE_SET_SPEED, &morse_ticks);
  401. ioctl(morse_fd, MORSE_SET_FREQUENCY, &morse_frequency);
  402. switch (xbell_type)
  403. {
  404. case XBELL_DONE:
  405. morse_char = 'd';
  406. /*
  407. morse_frequency = 400;
  408. ioctl(morse_fd,MORSE_SET_FREQUENCY,&morse_frequency);
  409. */
  410. break;
  411. case XBELL_ATTENTION:
  412. morse_char = '.';
  413. break;
  414. case XBELL_C:
  415. morse_char = 'c';
  416. break;
  417. case XBELL_3T:
  418. morse_char = 'o';
  419. break;
  420. default:
  421. morse_char = BT;
  422. break;
  423. }
  424. while (count--)
  425. write(morse_fd, &morse_char, 1);
  426. close(morse_fd);
  427. return (0);
  428. } /* end of morse_bell */
  429. #endif
  430. /*+-------------------------------------------------------------------------
  431. xbell(type,count)
  432. --------------------------------------------------------------------------*/
  433. void
  434. xbell(type, count)
  435. int type;
  436. int count;
  437. {
  438. #if defined(WHT) && defined(MORSE)
  439. if (morse_bell(type, count))
  440. ring_bell();
  441. #else
  442. #if defined(WHT) && defined(AUDIO)
  443. void audio_notify();
  444. audio_notify(type);
  445. #else
  446. if (!tty_is_multiscreen)
  447. {
  448. ring_bell();
  449. return;
  450. }
  451. #if defined(MORSE)
  452. if (morse_bell(type, count))
  453. #endif
  454. xbell_fd(1, type, count);
  455. #endif /* WHT && AUDIO */
  456. #endif /* WHT && MORSE */
  457. } /* end of xbell */
  458. /*+-------------------------------------------------------------------------
  459. bell_alarm(xbell_type)
  460. ring bell on multiscreens; if morse driver included, use it instead
  461. --------------------------------------------------------------------------*/
  462. int
  463. bell_alarm(xbell_type)
  464. int xbell_type;
  465. {
  466. #if defined(M_SYSV) || defined(SCO32v5)
  467. int notify_fd;
  468. int fork_pid;
  469. static long notify_time = 0L;
  470. char *get_ttyname();
  471. char devname[64];
  472. int devnum;
  473. int ttnum;
  474. #if !(defined(WHT) && defined(MORSE))
  475. if (!tty_is_multiscreen)
  476. {
  477. ring_bell(xbell_type);
  478. return (1);
  479. }
  480. #endif
  481. ttnum = atoi(get_ttyname() + 8);
  482. /* if happened less than 15 secs ago, forget it */
  483. if ((time((long *)0) - notify_time) < 15L)
  484. return (0);
  485. notify_time = time((long *)0);
  486. #if defined(MORSE)
  487. if (morse_bell(xbell_type, 1))
  488. {
  489. #endif
  490. if ((fork_pid = smart_fork()) != 0)
  491. {
  492. #if defined(FORK_DEBUG)
  493. sprintf(devname, "DEBUG bell notify pid %d", fork_pid);
  494. logevent(getpid(), devname); /* bell notify */
  495. #endif
  496. return (fork_pid > 0);
  497. }
  498. for (devnum = 1; devnum < 13; devnum++)
  499. {
  500. if (devnum == ttnum) /* don't bell notify ecu's tty */
  501. continue;
  502. sprintf(devname, "/dev/tty%02d", devnum);
  503. if ((notify_fd = open(devname, O_WRONLY, 0)) >= 0)
  504. {
  505. xbell_fd(notify_fd, xbell_type, 1);
  506. close(notify_fd);
  507. }
  508. }
  509. _exit(0); /* end of child tine (of the fork, naturally) */
  510. #if defined(MORSE)
  511. }
  512. /* NOTREACHED */
  513. #endif
  514. #else /* not SCO (M_SYSV) */
  515. ring_bell(xbell_type);
  516. #endif
  517. return (1);
  518. } /* end of bell_alarm */
  519. /*+-------------------------------------------------------------------------
  520. bell_notify(xbell_type)
  521. --------------------------------------------------------------------------*/
  522. void
  523. bell_notify(xbell_type)
  524. int xbell_type;
  525. {
  526. #if defined(M_SYSV) || defined(SCO32v5)
  527. if (
  528. #if !defined(WHT) && !defined(PTY_BELL_NOTIFY)
  529. tty_is_multiscreen &&
  530. #endif
  531. shm->bell_notify_state)
  532. {
  533. bell_alarm(xbell_type);
  534. }
  535. #else
  536. ring_bell(xbell_type);
  537. #endif
  538. } /* end of bell_notify */
  539. /*+-------------------------------------------------------------------------
  540. parse_bell_notify_argument(strarg) - parse "bell notify" argument
  541. Returns 0,1,2 according to parsing rules
  542. -1 on error
  543. --------------------------------------------------------------------------*/
  544. int
  545. parse_bell_notify_argument(strarg)
  546. char *strarg;
  547. {
  548. static STR_CLASSIFY sc[] =
  549. {
  550. {"off", 3, 0},
  551. {"on", 2, 1},
  552. {"alert", 1, 2},
  553. {(char *)0, 0, -1},
  554. };
  555. int itmp;
  556. if (isdigit((uchar) * strarg))
  557. {
  558. if (((itmp = atoi(strarg)) >= 0) && (itmp < 3))
  559. return (itmp);
  560. return (-1);
  561. }
  562. return (str_classify(sc, strarg));
  563. } /* end of parse_bell_notify_argument */
  564. /*+-------------------------------------------------------------------------
  565. bell_notify_text(bn) - text for bell notify status
  566. --------------------------------------------------------------------------*/
  567. char *
  568. bell_notify_text(bn)
  569. int bn;
  570. {
  571. char *cp = "?";
  572. switch (bn)
  573. {
  574. case 0:
  575. cp = "OFF";
  576. break;
  577. case 1:
  578. cp = "ON";
  579. break;
  580. case 2:
  581. cp = "ON+ALERT";
  582. break;
  583. default:
  584. cp = "???";
  585. break;
  586. }
  587. return (cp);
  588. } /* end of bell_notify_text */
  589. /*+-------------------------------------------------------------------------
  590. signal_name_text(sig)
  591. --------------------------------------------------------------------------*/
  592. char *
  593. signal_name_text(sig)
  594. int sig;
  595. {
  596. char *cp;
  597. static char sigunknown[20];
  598. sig &= 0x7F;
  599. switch (sig)
  600. {
  601. case SIGHUP:
  602. cp = "SIGHUP";
  603. break;
  604. case SIGINT:
  605. cp = "SIGINT";
  606. break;
  607. case SIGQUIT:
  608. cp = "SIGQUIT";
  609. break;
  610. case SIGILL:
  611. cp = "SIGILL";
  612. break;
  613. case SIGTRAP:
  614. cp = "SIGTRAP";
  615. break;
  616. #ifdef SIGIOT
  617. case SIGIOT:
  618. cp = "SIGIOT";
  619. break;
  620. #endif
  621. #ifdef SIGEMT
  622. case SIGEMT:
  623. cp = "SIGEMT";
  624. break;
  625. #endif
  626. case SIGFPE:
  627. cp = "SIGFPE";
  628. break;
  629. case SIGKILL:
  630. cp = "SIGKILL";
  631. break;
  632. #if defined(SIGBUS)
  633. case SIGBUS:
  634. cp = "SIGBUS";
  635. break;
  636. #endif
  637. case SIGSEGV:
  638. cp = "SIGSEGV";
  639. break;
  640. #if defined(SIGSYS)
  641. case SIGSYS:
  642. cp = "SIGSYS";
  643. break;
  644. #endif
  645. case SIGPIPE:
  646. cp = "SIGPIPE";
  647. break;
  648. case SIGALRM:
  649. cp = "SIGALRM";
  650. break;
  651. case SIGTERM:
  652. cp = "SIGTERM";
  653. break;
  654. case SIGUSR1:
  655. cp = "SIGUSR1";
  656. break;
  657. case SIGUSR2:
  658. cp = "SIGUSR2";
  659. break;
  660. case SIGCLD:
  661. cp = "SIGCLD";
  662. break;
  663. #if defined(SIGPWR)
  664. case SIGPWR:
  665. cp = "SIGPWR";
  666. break;
  667. #endif
  668. #if defined(SIGSTOP)
  669. case SIGSTOP:
  670. cp = "SIGSTOP";
  671. break;
  672. #endif
  673. #if defined(SIGTSOP)
  674. case SIGTSTP:
  675. cp = "SIGTSTP";
  676. break;
  677. #endif
  678. #if defined(SIGCONT)
  679. case SIGCONT:
  680. cp = "SIGCONT";
  681. break;
  682. #endif
  683. #if defined(SIGTTIN)
  684. case SIGTTIN:
  685. cp = "SIGTTIN";
  686. break;
  687. #endif
  688. #if defined(SIGTTOU)
  689. case SIGTTOU:
  690. cp = "SIGTTOU";
  691. break;
  692. #endif
  693. default:
  694. sprintf(sigunknown, "SIGNAL %u", sig);
  695. return (sigunknown);
  696. }
  697. return (cp);
  698. } /* end of signal_name_text */
  699. /*+-------------------------------------------------------------------------
  700. rename(from,to)
  701. --------------------------------------------------------------------------*/
  702. #if defined(M_XENIX) || defined(CFG_FakeRename)
  703. int
  704. rename(from, to)
  705. char *from;
  706. char *to;
  707. {
  708. struct stat ss;
  709. int save_errno;
  710. extern int errno;
  711. if (!stat(to, &ss)) /* if to exists, flunk */
  712. {
  713. errno = EEXIST; /* fake "file exists" error */
  714. return (-1);
  715. }
  716. if (link(from, to)) /* if cannot link, flunk */
  717. return (-1);
  718. if (unlink(from)) /* if cannot unlink, flunk */
  719. {
  720. save_errno = errno;
  721. unlink(to);
  722. errno = save_errno;
  723. return (-1);
  724. }
  725. return (0);
  726. } /* end of rename */
  727. #endif
  728. /*+-------------------------------------------------------------------------
  729. send_get_response(narg,arg) - send a string, get and log response
  730. --------------------------------------------------------------------------*/
  731. /*ARGSUSED*/
  732. void
  733. send_get_response(narg, arg)
  734. int narg;
  735. char **arg;
  736. {
  737. int itmp;
  738. int cmd;
  739. int mode;
  740. LRWT lr;
  741. char buf[1024];
  742. FILE *fplog;
  743. char *fname = "./ecu.sgr.log";
  744. static long sgrto1 = 10 * 1000L;
  745. static long sgrto2 = 2 * 1000L;
  746. long to;
  747. int restart_rcvr;
  748. #define SGR_EXEC 0
  749. #define SGR_SET_TO1 1
  750. #define SGR_SET_TO2 2
  751. /*
  752. * combination usage/parse hack detect unsupported commands and give
  753. * usage
  754. */
  755. if (!strcmp(arg[0], "sgr"))
  756. cmd = SGR_EXEC;
  757. else if (!strcmp(arg[0], "sgrto1"))
  758. cmd = SGR_SET_TO1;
  759. else if (!strcmp(arg[0], "sgrto2"))
  760. cmd = SGR_SET_TO2;
  761. else
  762. {
  763. ff(se, " sgr logic error\r\n");
  764. return;
  765. }
  766. if ((cmd == SGR_EXEC) && (narg < 3))
  767. {
  768. ff(se, "\r\nusage: sgr <mode> <cmd>\r\n");
  769. ff(se, " mode = 0 for sanitized response, 1 == raw\r\n");
  770. ff(se, " cmd = 'Send' string (see 'expresp' proc cmd in manual)\r\n");
  771. ff(se, " current sgrto1=%ld, sgrto2=%ld msec\r\n", sgrto1, sgrto2);
  772. return;
  773. }
  774. else if ((cmd != SGR_EXEC) && (narg != 2))
  775. {
  776. ff(se, "\r\nusage: sgrto1 <msec> or sgrto2 <msec>\r\n");
  777. ff(se, " sets `sgr' to1=time for 1st character, to2 for later\r\n");
  778. ff(se, " current sgrto1=%ld, sgrto2=%ld msec\r\n", sgrto1, sgrto2);
  779. return;
  780. }
  781. switch (cmd)
  782. {
  783. case SGR_EXEC:
  784. break;
  785. case SGR_SET_TO1:
  786. case SGR_SET_TO2:
  787. to = atol(arg[1]);
  788. if (to <= 0)
  789. {
  790. ff(se, " cannot set timeout <= 0\r\n");
  791. return;
  792. }
  793. if (cmd == SGR_SET_TO1)
  794. sgrto1 = to;
  795. else
  796. sgrto2 = to;
  797. ff(se, " sgrto1=%ld, sgrto2=%ld msec\r\n", sgrto1, sgrto2);
  798. return;
  799. }
  800. /*
  801. * we are going to execute an `sgr'; don't want receiver stealing our
  802. * response
  803. */
  804. if (restart_rcvr = need_rcvr_restart())
  805. kill_rcvr_process(SIGUSR1);
  806. /*
  807. * set up for capturing response
  808. */
  809. mode = atoi(arg[1]) & 0x0F;;
  810. lr.to1 = sgrto1;
  811. lr.to2 = sgrto2;
  812. lr.raw_flag = 0x80 + mode; /* allow interrupts */
  813. lr.buffer = buf;
  814. lr.bufsize = sizeof(buf);
  815. lr.delim = (char *)0;
  816. lr.echo_flag = 0;
  817. /*
  818. * stimulus/response
  819. */
  820. ff(se, "\r\nsend ... ");
  821. respond(arg[2]);
  822. ff(se, "wait (to1=%ld,to2=%ld) ... ", sgrto1, sgrto2);
  823. if (!ck_sigint())
  824. {
  825. lgets_timeout(&lr);
  826. if (ck_sigint())
  827. goto INTERRUPTED;
  828. ff(se, "done\r\n");
  829. /*
  830. * log response if possible and display on screen
  831. */
  832. if (fplog = fopen(fname, "a"))
  833. {
  834. itmp = strlen(arg[2]);
  835. hex_dump_fp(fplog, arg[2], itmp, "Stimulus", (itmp <= 16));
  836. hex_dump_fp(fplog, buf, lr.count, "Response", (lr.count <= 16));
  837. fputs("\n", fplog);
  838. fclose(fplog);
  839. ff(se, "\r\nDialog dump appended to '%s'\r\n", fname);
  840. }
  841. itmp = strlen(arg[2]);
  842. hex_dump(arg[2], itmp, "Stimulus", (itmp <= 16));
  843. hex_dump(buf, lr.count, "Response", (lr.count <= 16));
  844. if (!lr.count)
  845. ff(se, "\r\n");
  846. }
  847. else
  848. {
  849. INTERRUPTED:
  850. sigint = 0;
  851. ff(se, "interrupted\r\n");
  852. }
  853. if (restart_rcvr)
  854. start_rcvr_process(0);
  855. } /* end of send_get_response */
  856. /*+-------------------------------------------------------------------------
  857. xterm_title(text,code) - experimental - watch this space
  858. --------------------------------------------------------------------------*/
  859. #if defined(WHT2) || defined(XTERM_FRIEND)
  860. void
  861. xterm_title(text, code)
  862. char *text;
  863. int code;
  864. {
  865. static char *term = (char *)0;
  866. static char usrname[L_cuserid] = "";
  867. char *getenv();
  868. char *cuserid();
  869. static char xtstr1[82] = "";
  870. if (!term)
  871. term = getenv("TERM");
  872. if (!term)
  873. {
  874. term = "";
  875. return;
  876. }
  877. if (ulcmpb(term, "xterm") >= 0)
  878. return;
  879. if (!usrname[0])
  880. (void)cuserid(usrname);
  881. switch (code)
  882. {
  883. case 0:
  884. case 1:
  885. xtstr1[0] = 0;
  886. if (code == 1)
  887. strcpy(xtstr1, "ECU: ");
  888. strcat(xtstr1, text);
  889. if (usrname[0])
  890. sprintf(xtstr1 + strlen(xtstr1), " (%s)", usrname);
  891. case 2:
  892. fputs("\033]0;", se);
  893. fputs(xtstr1, se);
  894. fputc(7, se);
  895. break;
  896. }
  897. } /* end of xterm_title */
  898. #endif
  899. /* end of ecugrabbag.c */
  900. /* vi: set tabstop=4 shiftwidth=4: */