home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume32 / ecu / part05 < prev    next >
Encoding:
Text File  |  1992-09-10  |  56.9 KB  |  2,219 lines

  1. Newsgroups: comp.sources.misc
  2. From: wht@n4hgf.mt-park.ga.us (Warren Tucker)
  3. Subject:  v32i040:  ecu - ECU Asynchronous Communications v3.20, Part05/40
  4. Message-ID: <1992Sep11.192340.6499@sparky.imd.sterling.com>
  5. X-Md4-Signature: 8b2eef7d3735c51f6e44bcafdf491d0d
  6. Date: Fri, 11 Sep 1992 19:23:40 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: wht@n4hgf.mt-park.ga.us (Warren Tucker)
  10. Posting-number: Volume 32, Issue 40
  11. Archive-name: ecu/part05
  12. Environment: SCO,XENIX,ISC,SUNOS,SYSVR4,HDB,Curses
  13. Supersedes: ecu: Volume 21, Issue 53-89
  14.  
  15. ---- Cut Here and feed the following to sh ----
  16. #!/bin/sh
  17. # this is ecu320.05 (part 5 of ecu320)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file config.c continued
  20. #
  21. if test ! -r _shar_seq_.tmp; then
  22.     echo 'Please unpack part 1 first!'
  23.     exit 1
  24. fi
  25. (read Scheck
  26.  if test "$Scheck" != 5; then
  27.     echo Please unpack part "$Scheck" next!
  28.     exit 1
  29.  else
  30.     exit 0
  31.  fi
  32. ) < _shar_seq_.tmp || exit 1
  33. if test ! -f _shar_wnt_.tmp; then
  34.     echo 'x - still skipping config.c'
  35. else
  36. echo 'x - continuing file config.c'
  37. sed 's/^X//' << 'SHAR_EOF' >> 'config.c' &&
  38. X        compiler = C_CC;
  39. X    }
  40. X    else
  41. X    {
  42. X        if(compiler < 0)
  43. X        {
  44. X            switch(tgetopt("Do you wish to use cc or gcc","cg",'c'))
  45. X            {
  46. X                case 'c':
  47. X                    compiler = C_CC;
  48. X                    if(sco_type == X_32v4)
  49. X                    {
  50. X                        if(have_lng353)
  51. X                            tputstrs(strs_lng353);
  52. X                        else
  53. X                            tputstrs(strs_nolng353);
  54. X                    }
  55. X                    break;
  56. X
  57. X                case 'g':
  58. X                    compiler = C_GCC;
  59. X#ifdef PEDANTIC
  60. X                    printf("I see we are being brave, er pedantic.\n");
  61. X#endif
  62. X                    switch(tgetopt("Answer no if you are not sure.\n\
  63. XWARNING: The default answer for this question is now YES\n\
  64. XDo you have gcc 1.40 or later","yn",'y'))
  65. X                    {
  66. X                        case 'y': have_gcc_140 = 1; break;
  67. X                    }
  68. X                    switch(sys)
  69. X                    {
  70. X                        case S_SUN:
  71. X                        case S_ISCSVR4:
  72. X                        case S_ESIXSVR4:
  73. X                            can_pipe = 1; /* native as reads from stdin ok */
  74. X                            break;
  75. X                        default:
  76. X                            switch(tgetopt("Answer no if you are not sure.\n\
  77. XCan I use -pipe (do you have gas?)","yn",'n'))
  78. X                            {
  79. X                                case 'y': can_pipe = 1; break;
  80. X                            }
  81. X                            break;
  82. X                    }
  83. X                    break;
  84. X            }
  85. X        }
  86. X    }
  87. X
  88. X    if(!debug)
  89. X    {
  90. X        if(!getopt_tty)
  91. X        {
  92. X            printf("\nWhat do you want for a default tty? [%s]\n:",tty);
  93. X            tgets(s128);
  94. X            if(s128[0])
  95. X                tty = strdup(s128);
  96. X        }
  97. X
  98. X        if(!getopt_baud)
  99. X        {
  100. X            printf("\nWhat do you want for a default baud rate? [%s]\n:",baud);
  101. X            tgets(s128);
  102. X            if(s128[0])
  103. X                baud = strdup(s128);
  104. X        }
  105. X
  106. X        if(!getopt_parity)
  107. X        {
  108. X            parity = tgetopt( "What do you want for default parity","neo",'n');
  109. X        }
  110. X
  111. X        if(!getopt_bindir)
  112. X        {
  113. X            printf(
  114. X            "\nWhere do you want the public executables placed? [%s]\n: ",
  115. X                bindir);
  116. X            tgets(s128);
  117. X            if(s128[0])
  118. X                bindir = strdup(s128);
  119. X        }
  120. X
  121. X        if(!getopt_libdir)
  122. X        {
  123. X            printf(
  124. X            "\nWhere do you want the ECU library placed? [%s]\n: ",libdir);
  125. X            tgets(s128);
  126. X            if(s128[0])
  127. X                libdir = strdup(s128);
  128. X        }
  129. X    }
  130. X
  131. X    printf("\nThank you.\n\n");
  132. X
  133. X    makedir = makedirs;
  134. X    while(*makedir)
  135. X    {
  136. X        if(!strcmp(*makedir,"./ecuungetty") && (*use_ecuungetty == 'n'))
  137. X        {
  138. X            makedir++;
  139. X            continue;
  140. X        }
  141. X        generate_config(*makedir++);
  142. X    }
  143. X
  144. X    if(!debug)
  145. X        tputstrs(strs_mkdep);
  146. X
  147. X#ifdef WHT
  148. X    printf("\7Doing it anyway for WHT\n");
  149. X    sleep(2);
  150. X    system("make depend");
  151. X#endif
  152. X
  153. X    goodbye(0);
  154. X}
  155. X
  156. X/* vi: set tabstop=4 shiftwidth=4: */
  157. X/* end of config.c */
  158. SHAR_EOF
  159. echo 'File config.c is complete' &&
  160. chmod 0644 config.c ||
  161. echo 'restore of config.c failed'
  162. Wc_c="`wc -c < 'config.c'`"
  163. test 25615 -eq "$Wc_c" ||
  164.     echo 'config.c: original size 25615, current size' "$Wc_c"
  165. rm -f _shar_wnt_.tmp
  166. fi
  167. # ============= dialprog.h ==============
  168. if test -f 'dialprog.h' -a X"$1" != X"-c"; then
  169.     echo 'x - skipping dialprog.h (File already exists)'
  170.     rm -f _shar_wnt_.tmp
  171. else
  172. > _shar_wnt_.tmp
  173. echo 'x - extracting dialprog.h (Text)'
  174. sed 's/^X//' << 'SHAR_EOF' > 'dialprog.h' &&
  175. X/*+-------------------------------------------------------------------------
  176. X    dialprog.h - HDB UUCP dialer program return code error codes
  177. X    wht@n4hgf.Mt-Park.GA.US
  178. X--------------------------------------------------------------------------*/
  179. X/*+:EDITS:*/
  180. X/*:09-10-1992-13:58-wht@n4hgf-ECU release 3.20 */
  181. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  182. X/*:03-27-1992-16:21-wht@n4hgf-re-include protection for all .h files */
  183. X/*:07-25-1991-12:55-wht@n4hgf-ECU release 3.10 */
  184. X/*:08-14-1990-20:39-wht@n4hgf-ecu3.00-flush old edit history */
  185. X
  186. X#ifndef _dialprog_h
  187. X#define _dialprog_h
  188. X
  189. X/*  Return code masks:
  190. X *            0x80    bit = 1 if connection failed
  191. X *            0x10    bit = 1 if line is also used for dialin #ifndef HDUU
  192. X *            0x0f    if msb=1: error code
  193. X *                    if msb=0: connected baud rate (0=same as dialed baud)
  194. X */
  195. X/* return codes: these are set up so that an abort signal at any time can */
  196. X/* set the fail bit and return to the caller with the correct status */
  197. X#define       RC_BAUD         0x0f    /* CBAUD connected at (0=same as dialed speed)*/
  198. X#define       RC_ENABLED      0x10    /* enabled flag: 1 = ungetty -r required to */
  199. X                  /* restore the line */
  200. X#define    RC_FAIL        0x80    /* 1 = failed to connect */
  201. X#define    RCE_NULL    0        /* general purpose or unknown error code */
  202. X#define    RCE_INUSE    1        /* line in use */
  203. X#define    RCE_SIG        2        /* signal aborted dialer */
  204. X#define    RCE_ARGS    3        /* invalid arguments */
  205. X#define    RCE_PHNO    4        /* invalid phone number */
  206. X#define    RCE_SPEED    5        /* invalid baud rate -or- bad connect baud */
  207. X#define    RCE_OPEN    6        /* can't open line */
  208. X#define    RCE_IOCTL    7        /* ioctl error */
  209. X#define    RCE_TIMOUT    8        /* timeout */
  210. X#define    RCE_NOTONE    9        /* no dial tone */
  211. X#define    RCE_BUSY    13        /* phone is busy */
  212. X#define    RCE_NOCARR    14        /* no carrier */
  213. X#define    RCE_ANSWER    15        /* no answer */
  214. X
  215. X/* code writing aid */
  216. X#ifdef NEVER
  217. X        case RCE_NULL:        /* general purpose or unknown error code */
  218. X        case RCE_INUSE:        /* line in use */
  219. X        case RCE_SIG:        /* signal aborted dialer */
  220. X        case RCE_ARGS:        /* invalid arguments */
  221. X        case RCE_PHNO:        /* invalid phone number */
  222. X        case RCE_SPEED:        /* invalid baud rate -or- bad connect baud */
  223. X        case RCE_OPEN:        /* can't open line */
  224. X        case RCE_IOCTL:        /* ioctl error */
  225. X        case RCE_TIMOUT:    /* timeout */
  226. X        case RCE_NOTONE:    /* no dial tone */
  227. X        case RCE_BUSY:        /* phone is busy */
  228. X        case RCE_NOCARR:    /* no carrier */
  229. X        case RCE_ANSWER:    /* no answer */
  230. X#endif
  231. X
  232. X#endif /* _dialprog_h */
  233. X
  234. X/* vi: set tabstop=4 shiftwidth=4: */
  235. X/* end of dialprog.h */
  236. SHAR_EOF
  237. chmod 0644 dialprog.h ||
  238. echo 'restore of dialprog.h failed'
  239. Wc_c="`wc -c < 'dialprog.h'`"
  240. test 2535 -eq "$Wc_c" ||
  241.     echo 'dialprog.h: original size 2535, current size' "$Wc_c"
  242. rm -f _shar_wnt_.tmp
  243. fi
  244. # ============= dlent.h ==============
  245. if test -f 'dlent.h' -a X"$1" != X"-c"; then
  246.     echo 'x - skipping dlent.h (File already exists)'
  247.     rm -f _shar_wnt_.tmp
  248. else
  249. > _shar_wnt_.tmp
  250. echo 'x - extracting dlent.h (Text)'
  251. sed 's/^X//' << 'SHAR_EOF' > 'dlent.h' &&
  252. X/*+-------------------------------------------------------------------------
  253. X    dlent.h - HDB UUCP Dialers file entry (a la pwent.h)
  254. X    wht@n4hgf.Mt-Park.GA.US
  255. X--------------------------------------------------------------------------*/
  256. X/*+:EDITS:*/
  257. X/*:09-10-1992-13:58-wht@n4hgf-ECU release 3.20 */
  258. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  259. X/*:07-19-1992-08:41-wht@n4hgf-add typedef DLE */
  260. X/*:03-27-1992-16:21-wht@n4hgf-re-include protection for all .h files */
  261. X/*:07-25-1991-12:55-wht@n4hgf-ECU release 3.10 */
  262. X/*:08-14-1990-20:39-wht@n4hgf-ecu3.00-flush old edit history */
  263. X
  264. X#ifndef _dlent_h
  265. X#define _dlent_h
  266. X
  267. Xtypedef struct dlent
  268. X{
  269. X    char *name;        /* Dialer name */
  270. X    char *tlate;    /* translate string */
  271. X    char *script;    /* expect-respond script */
  272. X} DLE;
  273. X
  274. XDLE *getdlent();
  275. Xvoid enddlent();
  276. X
  277. X#endif /* _dlent_h */
  278. X
  279. X/* vi: set tabstop=4 shiftwidth=4: */
  280. X/* end of dlent.h */
  281. SHAR_EOF
  282. chmod 0644 dlent.h ||
  283. echo 'restore of dlent.h failed'
  284. Wc_c="`wc -c < 'dlent.h'`"
  285. test 882 -eq "$Wc_c" ||
  286.     echo 'dlent.h: original size 882, current size' "$Wc_c"
  287. rm -f _shar_wnt_.tmp
  288. fi
  289. # ============= dutmp.c ==============
  290. if test -f 'dutmp.c' -a X"$1" != X"-c"; then
  291.     echo 'x - skipping dutmp.c (File already exists)'
  292.     rm -f _shar_wnt_.tmp
  293. else
  294. > _shar_wnt_.tmp
  295. echo 'x - extracting dutmp.c (Text)'
  296. sed 's/^X//' << 'SHAR_EOF' > 'dutmp.c' &&
  297. X/* CHK=0xD757 */
  298. Xchar *revision = "1.2";
  299. X/*+-----------------------------------------------------------------------
  300. X    dutmp.c -- dump /etc/utmp
  301. X    wht@n4hgf.Mt-Park.GA.US
  302. X------------------------------------------------------------------------*/
  303. X/*+:EDITS:*/
  304. X/*:09-10-1992-13:58-wht@n4hgf-ECU release 3.20 */
  305. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  306. X/*:04-28-1992-13:05-wht@n4hgf-clean up for inclusion in ecu */
  307. X/*:11-19-1989-16:34-wht-creation */
  308. X
  309. X#include <stdio.h>
  310. X#include <fcntl.h>
  311. X#include <ctype.h>
  312. X#include <sys/types.h>
  313. X#include <utmp.h>
  314. X
  315. Xchar *utmp_file = "/etc/utmp";
  316. X
  317. Xextern char    *ctime();
  318. X
  319. X/*+-------------------------------------------------------------------------
  320. X    main(argc,argv)
  321. X--------------------------------------------------------------------------*/
  322. Xmain(argc,argv)
  323. Xint argc;
  324. Xchar **argv;
  325. X{
  326. X    struct utmp ut;
  327. X    register int ufd;
  328. X
  329. X    printf("dutmp %s\n",revision);
  330. X
  331. X    if((ufd = open(utmp_file,O_RDONLY,755)) < 0)
  332. X    {
  333. X        perror(utmp_file);
  334. X        exit(1);
  335. X    }
  336. X
  337. X    while(read(ufd,&ut,sizeof(ut)) > 0)
  338. X    {
  339. X#if defined(sun)
  340. X        if(!*ut.ut_name || (ut.ut_time < 0))
  341. X            continue;
  342. X        printf("%-10.10s %-14.14s %-15.15s %s",
  343. X            ut.ut_name,
  344. X            ut.ut_line,
  345. X            ut.ut_host,
  346. X            ctime(&ut.ut_time));
  347. X#else
  348. X        printf("%-10.10s %-7.7s %-14.14s %6u %s",
  349. X            ut.ut_user,
  350. X            ut.ut_id,
  351. X            ut.ut_line,
  352. X            ut.ut_pid,
  353. X            ctime(&ut.ut_time));
  354. X#endif
  355. X    }
  356. X    close(ufd);
  357. X    exit(0);
  358. X}    /* end of main */
  359. X
  360. X
  361. X/* vi: set tabstop=4 shiftwidth=4: */
  362. X/* end of dutmp.c */
  363. SHAR_EOF
  364. chmod 0644 dutmp.c ||
  365. echo 'restore of dutmp.c failed'
  366. Wc_c="`wc -c < 'dutmp.c'`"
  367. test 1474 -eq "$Wc_c" ||
  368.     echo 'dutmp.c: original size 1474, current size' "$Wc_c"
  369. rm -f _shar_wnt_.tmp
  370. fi
  371. # ============= dvent.h ==============
  372. if test -f 'dvent.h' -a X"$1" != X"-c"; then
  373.     echo 'x - skipping dvent.h (File already exists)'
  374.     rm -f _shar_wnt_.tmp
  375. else
  376. > _shar_wnt_.tmp
  377. echo 'x - extracting dvent.h (Text)'
  378. sed 's/^X//' << 'SHAR_EOF' > 'dvent.h' &&
  379. X/*+-------------------------------------------------------------------------
  380. X    dvent.h - HDB UUCP Devices file entry (a la pwent.h)
  381. X    wht@n4hgf.Mt-Park.GA.US
  382. X--------------------------------------------------------------------------*/
  383. X/*+:EDITS:*/
  384. X/*:09-10-1992-13:58-wht@n4hgf-ECU release 3.20 */
  385. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  386. X/*:03-27-1992-16:21-wht@n4hgf-re-include protection for all .h files */
  387. X/*:12-01-1991-12:38-wht@n4hgf-new typedef for striuct dvent */
  388. X/*:07-25-1991-12:55-wht@n4hgf-ECU release 3.10 */
  389. X/*:08-14-1990-20:39-wht@n4hgf-ecu3.00-flush old edit history */
  390. X
  391. X#ifndef _dvent_h
  392. X#define _dvent_h
  393. X
  394. Xtypedef struct dvent
  395. X{
  396. X    char *type;        /* ACU or Direct */
  397. X    char *line;        /* tty  name "ttyxx"-style */
  398. X    char *dialer;    /* "801" dialer line */
  399. X    uint low_baud;    /* lowest baud rate */
  400. X    uint high_baud;    /* highest baud rate */
  401. X    char *dialprog;    /* dialer program */
  402. X    char *token;    /* token to be passed to the dialer */
  403. X} DVE;
  404. X
  405. XDVE *getdvent();
  406. XDVE *getdvbaud();
  407. XDVE *getdvline();
  408. Xvoid enddvent();
  409. X
  410. X#endif /* _dvent_h */
  411. X
  412. X/* vi: set tabstop=4 shiftwidth=4: */
  413. X/* end of dvent.h */
  414. SHAR_EOF
  415. chmod 0644 dvent.h ||
  416. echo 'restore of dvent.h failed'
  417. Wc_c="`wc -c < 'dvent.h'`"
  418. test 1114 -eq "$Wc_c" ||
  419.     echo 'dvent.h: original size 1114, current size' "$Wc_c"
  420. rm -f _shar_wnt_.tmp
  421. fi
  422. # ============= ecu.c ==============
  423. if test -f 'ecu.c' -a X"$1" != X"-c"; then
  424.     echo 'x - skipping ecu.c (File already exists)'
  425.     rm -f _shar_wnt_.tmp
  426. else
  427. > _shar_wnt_.tmp
  428. echo 'x - extracting ecu.c (Text)'
  429. sed 's/^X//' << 'SHAR_EOF' > 'ecu.c' &&
  430. X/*+-----------------------------------------------------------------------
  431. X    ecu.c - Extended Calling Unit/Call Utility/Call UNIX/whatever
  432. X    wht@n4hgf.Mt-Park.GA.US
  433. X
  434. X  Defined functions:
  435. X    main(argc,argv,envp)
  436. X    xmtr()
  437. X
  438. X   "Now tell me, old man, what's your name?"
  439. X   "Holloway, sir. Charles William Holloway."
  440. X   "Oh yes, the town's librarian."
  441. X   "I have the honor, sir, and have had for many years."
  442. X   "I believe all that time spent living through other men's lives,
  443. Xother men's dreams, what a waste."
  444. X   "Sometimes, a man can learn more from other men's dreams than he
  445. Xcan from his own.  Come visit me sir, if you wish to improve your
  446. Xeducation and I may improve yours."  -- Something Wicked This Way Comes
  447. X
  448. X------------------------------------------------------------------------*/
  449. X/*+:EDITS:*/
  450. X/*:09-10-1992-13:58-wht@n4hgf-ECU release 3.20 */
  451. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  452. X/*:08-16-1992-03:43-wht@n4hgf-add -F funckeytype */
  453. X/*:08-16-1992-03:08-wht@n4hgf-head off another POSIX plot */
  454. X/*:04-30-1992-00:49-wht@n4hgf-remove obsolete -c */
  455. X/*:04-24-1992-21:59-wht@n4hgf-more SCO tty name normalizing */
  456. X/*:04-17-1992-18:19-wht@n4hgf-"default" keyset read if present */
  457. X/*:02-16-1992-02:39-wht@n4hgf-add -P phonedir switch for rll@sco */
  458. X/*:02-16-1992-01:41-wht@n4hgf-turn off xterm_title */
  459. X/*:08-11-1991-19:56-wht@n4hgf-soup up -l for ISC vs. SCO */
  460. X/*:08-06-1991-13:02-wht@n4hgf-jpm@logixwi fix: HZ getenv test wrong sense */
  461. X/*:07-29-1991-17:57-wht@n4hgf-add memstat */
  462. X/*:07-25-1991-12:55-wht@n4hgf-ECU release 3.10 */
  463. X/*:07-17-1991-07:04-wht@n4hgf-avoid SCO UNIX nap bug */
  464. X/*:04-27-1991-01:52-wht@n4hgf-overhaul revision numbers */
  465. X/*:03-17-1991-13:44-wht@n4hgf-nice and uid revision */
  466. X/*:01-09-1991-22:31-wht@n4hgf-ISC port */
  467. X/*:11-30-1990-19:04-wht@n4hgf-new ttyinit parameter - see TTYINIT_... */
  468. X/*:11-28-1990-15:58-wht@n4hgf-add non-ansi terminal support */
  469. X/*:08-14-1990-20:39-wht@n4hgf-ecu3.00-flush old edit history */
  470. X
  471. X#if !defined(XECU)
  472. X#include "ecu.h"
  473. X#include "dvent.h"
  474. X#include "esd.h"
  475. X#include "proc.h"
  476. X#include "ecukey.h"
  477. X#include "ecuxkey.h"
  478. X#include "termecu.h"
  479. X
  480. Xchar *getenv();
  481. Xvoid xmtr_SIGINT_handler();
  482. XDVE *hdb_choose_Any();
  483. X
  484. Xextern char *makedate;            /* temporary make date */
  485. Xextern char *revstr;    /* ecunumrev.c */
  486. Xextern char *revision_modifier; /* ecunumrev.c */
  487. Xextern ESD *icmd_prompt;
  488. Xextern char kbdeof;            /* current input EOF */
  489. Xextern char kbdeol2;        /* current secondary input EOL */
  490. Xextern char kbdeol;            /* current input EOL */
  491. Xextern char kbderase;        /* current input ERASE */
  492. Xextern char kbdintr;        /* current input INTR */
  493. Xextern char kbdkill;        /* current input KILL */
  494. Xextern char kbdquit;        /* current input QUIT */
  495. Xextern char kbd_is_7bit;    /* keyboard has parity */
  496. Xextern uint tcap_LINES;
  497. Xextern uint tcap_COLS;
  498. Xextern ulong colors_current;
  499. Xextern int there_is_hdb_on_this_machine;
  500. Xextern char lopen_err_str[];
  501. Xextern char phonedir_name[PHONEDIR_NAME_SIZE];
  502. X
  503. Xchar *eculibdir = ECULIBDIR;
  504. Xchar *dash_f_funckeytype;
  505. Xchar curr_dir[CURR_DIRSIZ];        /* current working directory of process */
  506. Xchar hello_str[128];        /* msg printed upon BOJ */
  507. Xchar errmsg[128];
  508. Xchar initial_procedure[128] = "";
  509. Xchar *default_tty = DEFAULT_TTY;    /* configurable default tty name */
  510. Xint init_proc_argc = 0;
  511. Xchar *init_proc_argv[MAX_PARGV];
  512. XPID_T rcvr_pid = -1;        /* pid for rcvr process (-1 == no proc active) */
  513. X    /* ... -2 == special flag for modem control/timed-read procedures */
  514. XPID_T xmtr_pid = 0;
  515. Xint quit_on_init_proc_fail = 0;
  516. Xint quit_on_init_proc_done = 0;
  517. Xint rc_ep_has_run = 0;
  518. Xstruct timeb starting_timeb;
  519. X
  520. Xint hz;                    /* HZ from environ or sys/param.h */
  521. Xulong hzmsec;            /* clock period in msec rounded up */
  522. X
  523. X
  524. X#ifdef MALLOC_3X
  525. Xchar *sbrk();
  526. Xchar *startbrk;
  527. Xchar *startsp;
  528. X#endif
  529. X
  530. Xchar *_rc = "_rc";    /* _rc.ep */
  531. X
  532. Xushort geteuid();
  533. Xushort getuid();
  534. Xushort euid;
  535. Xushort uid;
  536. X
  537. X/*+-----------------------------------------------------------------------
  538. X    xmtr() --  copy stdin to comm line
  539. X
  540. X  THE INITIAL PROCESS EXECUTES THIS PROCESS UNTIL PROGRAM TERMINATION
  541. X
  542. X  TTY input lines beginning with % have special significance
  543. X  (see ecuicmd.c)
  544. X------------------------------------------------------------------------*/
  545. Xvoid
  546. Xxmtr()
  547. X{
  548. Xuchar xmtr_char;
  549. Xuchar nlchar = NL;
  550. X
  551. X    ttymode(1);
  552. X    xmtr_signals();
  553. X    while(1)
  554. X    {
  555. X
  556. X#if 0
  557. X/* bug somewhere ... may be SIGINT too rapidly causing SIG_IGN ????? */
  558. X        signal(SIGINT,xmtr_SIGINT_handler);    /* so make sure */
  559. X#endif
  560. X
  561. X        xmtr_char = ttygetc(1);
  562. X
  563. X        if(xmtr_char & 0x80)
  564. X        {
  565. X            kbd_escape(xmtr_char);
  566. X            continue;
  567. X        }
  568. X
  569. X        lputc(xmtr_char);
  570. X        if(shm->Lfull_duplex == 0)        /* echo character if asked */
  571. X            write(TTYERR,(char *)&xmtr_char,1);
  572. X
  573. X        if(xmtr_char == CRET)
  574. X        {
  575. X            if(shm->Ladd_nl_outgoing)
  576. X                lputc('\n');
  577. X            if(shm->Lfull_duplex == 0)
  578. X                write(TTYERR,(char *)&nlchar,1);
  579. X        }
  580. X    }
  581. X    /*NOTREACHED*/
  582. X
  583. X}    /* end of xmtr */
  584. X
  585. X/*+-------------------------------------------------------------------------
  586. X    main(argc,argv,envp)
  587. X
  588. X  main() program forks to create rcvr process; then main()
  589. X  becomes the xmtr process
  590. X------------------------------------------------------------------------*/
  591. Xint
  592. Xmain(argc,argv,envp)
  593. Xint argc;
  594. Xchar **argv;
  595. Xchar **envp;
  596. X{
  597. Xint swchar;
  598. Xint itmp;
  599. Xulong colors_save;
  600. Xchar *get_ttyname();
  601. Xextern char *optarg;
  602. Xextern int optind;
  603. X
  604. X#ifdef MALLOC_3X
  605. X    startbrk = sbrk(0);            /* initial break */
  606. X    startsp = (char *)&swchar;    /* initial sp */
  607. X    (void)mallopt(M_MXFAST,256+4);
  608. X    (void)mallopt(M_NLBLKS,64);
  609. X    (void)mallopt(M_GRAIN,sizeof(ESD) + 8);
  610. X#endif
  611. X
  612. X    setbuf(stderr,NULL);
  613. X    xmtr_signals();            /* catch xmtr signals */
  614. X
  615. X    ftime(&starting_timeb);    /* get startup time */
  616. X    xmtr_pid = (PID_T)getpid();
  617. X
  618. X    /*
  619. X     * get this off quick, cause we'll be busy for a little while on 286
  620. X     */
  621. X    build_revision_string();
  622. X    sprintf(hello_str,"ecu %s",revstr);
  623. X    ff(se,"%s\n",hello_str);
  624. X
  625. X    /*
  626. X     * initialize 'hz'/'hzmsec' and  Nap() implimentation
  627. X     */
  628. X    init_Nap();
  629. X
  630. X    /*
  631. X     * if we are root (or setuid to root as we should be on 286 versions),
  632. X     * nice to very bad
  633. X     */
  634. X    uid = getuid();
  635. X    euid = geteuid();
  636. X    if((euid == 0) || (uid == 0))    /* if root running or prog text ... */
  637. X    {                                /* ... sets to root, then grab gusto */
  638. X    int nice_value = 3;                /* go for hi priority */
  639. X    int old_nice = nice(0) + 20;
  640. X        nice(-old_nice + nice_value);
  641. X    }
  642. X
  643. X    /*
  644. X     * set uid to real uid
  645. X     */
  646. X    if(uid != euid)                /* if user not really who he say he is ... */
  647. X    {
  648. X        if(setuid(uid))            /* ... make him so */
  649. X        {
  650. X            ff(se,"\r\n");
  651. X            perror("setuid failed");
  652. X            ff(se,"\r\n");
  653. X            exit(-1);
  654. X        }
  655. X    }
  656. X
  657. X    /*
  658. X     * Initialize shared memory segment.
  659. X     * This must be done before any uses are made of the Lermio variable
  660. X     * see ecushm.c and ecu.h.
  661. X     */
  662. X    shm_init();                /* open shared segment */
  663. X
  664. X    keyset_init();            /* intialize keyset */
  665. X    keyset_read("default");
  666. X
  667. X    make_ecu_subdir();        /* needs to be very early before lots of init */
  668. X
  669. X    get_curr_dir(curr_dir,sizeof(curr_dir));
  670. X    cd_array_init();        /* read %cd directory list */
  671. X
  672. X    hdb_init();
  673. X
  674. X    var_init();                /* initialize procedure variables */
  675. X    poutput_init();            /* initialize procedure output */
  676. X
  677. X    icmd_prompt = esdalloc(64);
  678. X    set_default_escape_prompt();
  679. X
  680. X    /*
  681. X     * init line variables
  682. X     */
  683. X    memset(shm->Lline,0,sizeof(shm->Lline));
  684. X    shm->Liofd = -1;                /* no line open now */
  685. X    shm->Lbaud = DEFAULT_BAUD_RATE;    /* from config.c run */
  686. X    shm->Lparity = DEFAULT_PARITY;    /* from config.c run */
  687. X    if(shm->Lparity == 'n')
  688. X        shm->Lparity = 0;
  689. X    shm->Ltelno[0] = 0;                /* no telephone number for remote yet */
  690. X    shm->Llogical[0] = 0;            /* no logical name for remote yet */
  691. X    shm->Lrname[0] = 0;                /* no logical name for remote yet */
  692. X    shm->Ldescr[0] = 0;                /* no description for remote yet */
  693. X    shm->Lconnected = 0;            /* not connected */
  694. X    shm->Ladd_nl_incoming = 0;        /* dont add nl to incoming cr */
  695. X    shm->Ladd_nl_outgoing = 0;        /* dont add nl to outgoing cr */
  696. X    shm->Lfull_duplex = 1;            /* assume full duplex */
  697. X    shm->Lmodem_already_init = 0;    /* modem has not been initialized */
  698. X    shm->Lxonxoff = IXON | IXOFF;    /* default to xon/xoff protocol */
  699. X    shm->xmtr_pid = (PID_T)getpid();
  700. X    shm->xmtr_ppid = (PID_T)getppid();
  701. X    shm->xmtr_pgrp = (PID_T)getpgrp(0);
  702. X    strcpy(shm->tty_name,get_ttyname());
  703. X    shm->shm_revision = SHM_REV;
  704. X    shm->ttyuse = TTYUSE_NORMAL;
  705. X    shm->terminating = 0;
  706. X
  707. X    while((swchar = getopt(argc,argv,"DF:HNP:T:b:defhl:o:p:t")) != -1)
  708. X    {
  709. X        switch(swchar)
  710. X        {
  711. X            case 'b':
  712. X                if(valid_baud_rate(shm->Lbaud = atoi(optarg)) < 0)
  713. X                {
  714. X                    ff(se,"invalid baud rate %u\n",shm->Lbaud);
  715. X                    usage();
  716. X                }
  717. X                break;
  718. X            case 'l':
  719. X                strcpy(shm->Lline,"/dev/");
  720. X#if defined(M_SYSV)
  721. X                if(strncmp(optarg,"tty",4))
  722. X                    strcat(shm->Lline,"tty");
  723. X                strcat(shm->Lline,optarg);
  724. X#else
  725. X                strncat(shm->Lline,optarg,sizeof(shm->Lline) - 5);
  726. X                shm->Lline[sizeof(shm->Lline) - 1] = 0;
  727. X#endif /* M_SYSV */
  728. X                break;
  729. X            case 'p':
  730. X                strcpy(initial_procedure,optarg);
  731. X                break;
  732. X            case 'h': shm->Lfull_duplex = 0; break;
  733. X            case 'f': shm->Lfull_duplex = 1; break;
  734. X            case 'd': quit_on_init_proc_fail = 1; break;
  735. X            case 'D': quit_on_init_proc_done = 1; break;
  736. X            case 't': shm->Ladd_nl_incoming = 1;
  737. X                      shm->Ladd_nl_outgoing = 1; break;
  738. X            case 'e': shm->Lparity = 'e'; break;
  739. X            case 'o': shm->Lparity = 'o'; break;
  740. X            case 'N': shm->ttyuse = TTYUSE_FORCE_SIMPLE; break;
  741. X            case 'T': proctrace = atoi(optarg); break;
  742. X            case 'P':
  743. X                strncpy(phonedir_name,optarg,PHONEDIR_NAME_SIZE);
  744. X                phonedir_name[PHONEDIR_NAME_SIZE - 1] = 0;
  745. X                break;
  746. X            case 'F':
  747. X                dash_f_funckeytype = optarg;
  748. X                break;
  749. X            case '?': usage();
  750. X        }
  751. X    }
  752. X
  753. X    /*
  754. X     * check a few options for validity
  755. X     */
  756. X    if(!initial_procedure[0] &&
  757. X        (quit_on_init_proc_done || quit_on_init_proc_fail))
  758. X    {
  759. X        ff(se,"no -D/-d without -p\n");
  760. X        usage();
  761. X    }
  762. X
  763. X    ttyinit(shm->ttyuse);    /* init console tty mode handler */
  764. X    ttymode(3);        /* put user console in `raw' mode but SIGINT terms prog */
  765. X    tcap_clear_screen();
  766. X#if defined(WHT2) || defined(XTERM_FRIEND)
  767. X    /*
  768. X     * if xterm, put notice in title bar
  769. X     * but this really should be done in _rc.ep
  770. X     */
  771. X    xterm_title("ECU",0);
  772. X#endif
  773. X    ff(se,"%s\r\n",hello_str);
  774. X
  775. X    /*
  776. X     * do the _rc.ep execution
  777. X     */
  778. X    if(find_procedure(_rc))
  779. X    {
  780. X        if(do_proc(1,&_rc))
  781. X        {
  782. X            if(quit_on_init_proc_fail || quit_on_init_proc_done)
  783. X                termecu(TERMECU_INIT_PROC_ERROR);
  784. X        }
  785. X    }
  786. X    rc_ep_has_run = 1;
  787. X
  788. X    /*
  789. X     * check out line
  790. X     */
  791. X    if(!shm->Lline[0])
  792. X    {
  793. X        if(!there_is_hdb_on_this_machine)
  794. X            strcpy(shm->Lline,default_tty);
  795. X        else
  796. X        {
  797. X            DVE *tdve;
  798. X            if(tdve = hdb_choose_Any(shm->Lbaud))
  799. X                sprintf(shm->Lline,"/dev/%s",tdve->line);
  800. X            else
  801. X            {
  802. X#if 0
  803. X                ff(se,"\r\n\n");
  804. X                tcap_stand_out();
  805. X                ff(se,"[no available Devices line at %u baud]",shm->Lbaud);
  806. X                tcap_stand_end();
  807. X                ff(se,"\r\n");
  808. X                Nap(1000L);
  809. X#endif
  810. X                strcpy(shm->Lline,default_tty);
  811. X            }
  812. X        }
  813. X    }
  814. X
  815. X    /*
  816. X     * either present startup screen or run initial procedure or both
  817. X     */
  818. X    if(initial_procedure[0])
  819. X    {
  820. X        init_proc_argv[0] = initial_procedure;
  821. X        init_proc_argc = 1;
  822. X        for(itmp = optind; itmp < argc; itmp++)
  823. X        {
  824. X            if(*argv[itmp] != '-')
  825. X            {
  826. X                if(init_proc_argc == MAX_PARGV)
  827. X                {
  828. X                    ff(se,"too many arguments to initial procedure\r\n");
  829. X                    termecu(TERMECU_USAGE);
  830. X                }
  831. X                init_proc_argv[init_proc_argc++] = argv[itmp];
  832. X            }
  833. X        }
  834. X
  835. X        if(tty_not_char_special)
  836. X            quit_on_init_proc_done = 1;
  837. X        else    /* rattle curses once - fixes quirk/bug I can't find */
  838. X        {
  839. X            windows_start();
  840. X            windows_end(0);
  841. X            fflush(so);
  842. X        }
  843. X
  844. X        if(do_proc(init_proc_argc,init_proc_argv))
  845. X        {
  846. X            if(quit_on_init_proc_fail || quit_on_init_proc_done)
  847. X                termecu(TERMECU_INIT_PROC_ERROR);
  848. X        }
  849. X        proc_file_reset();
  850. X        colors_save = colors_current;
  851. X        setcolor(colors_notify);
  852. X        fputs("[procedure finished]",se);
  853. X        setcolor(colors_save);
  854. X        ff(se,"\r\n");
  855. X        if(quit_on_init_proc_done)
  856. X            termecu(0);
  857. X        if(shm->Liofd < 0)
  858. X        {
  859. X            ff(se,"\r\n\n");
  860. X            tcap_stand_out();
  861. X            ff(se,"[no line attached by initial procedure]");
  862. X            tcap_stand_end();
  863. X            ff(se,"\r\n");
  864. X            if(quit_on_init_proc_fail)
  865. X                termecu(TERMECU_INIT_PROC_ERROR);
  866. X            tcap_stand_out();
  867. X            ff(se,"[press ESC to exit or SPACE for setup menu]");
  868. X            tcap_stand_end();
  869. X            itmp = ttygetc(0);
  870. X            ff(se,"\r\n");
  871. X            if(itmp == ESC)
  872. X                termecu(1);
  873. X            shm->Llogical[0] = 0;
  874. X            shm->Ltelno[0] = 0;
  875. X            shm->Ldescr[0] = 0;
  876. X            setup_screen((char *)0);
  877. X        }
  878. X        else
  879. X            start_rcvr_process(0);
  880. X    }
  881. X    else        /* no initial procedure */
  882. X        setup_screen((optind < argc) ? argv[optind] : (char *)0);
  883. X
  884. X    /* enter xmtr operation */
  885. X    xmtr();
  886. X    termecu(0);
  887. X    return(0); /* never get here, but keep gcc optim from complaining */
  888. X    /*NOTREACHED*/
  889. X}    /* end of main */
  890. X
  891. X#endif /* XECU */
  892. X/* end of ecu.c */
  893. X/* vi: set tabstop=4 shiftwidth=4: */
  894. SHAR_EOF
  895. chmod 0644 ecu.c ||
  896. echo 'restore of ecu.c failed'
  897. Wc_c="`wc -c < 'ecu.c'`"
  898. test 12474 -eq "$Wc_c" ||
  899.     echo 'ecu.c: original size 12474, current size' "$Wc_c"
  900. rm -f _shar_wnt_.tmp
  901. fi
  902. # ============= ecu.h ==============
  903. if test -f 'ecu.h' -a X"$1" != X"-c"; then
  904.     echo 'x - skipping ecu.h (File already exists)'
  905.     rm -f _shar_wnt_.tmp
  906. else
  907. > _shar_wnt_.tmp
  908. echo 'x - extracting ecu.h (Text)'
  909. sed 's/^X//' << 'SHAR_EOF' > 'ecu.h' &&
  910. X/*+-----------------------------------------------------------------------
  911. X    ecu.h -- TuckerWare Extended Calling Unit
  912. X    wht@n4hgf.Mt-Park.GA.US
  913. X------------------------------------------------------------------------*/
  914. X/*+:EDITS:*/
  915. X/*:09-10-1992-13:58-wht@n4hgf-ECU release 3.20 */
  916. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  917. X/*:08-21-1992-13:39-wht@n4hgf-rewire direct/modem device use */
  918. X/*:07-21-1992-12:09-wht@n4hgf-3.2v4 only has sys/time.h if TCPRT installed */
  919. X/*:04-17-1992-20:10-wht@gyro-default tty, baud and parity moved to config.c */
  920. X/*:03-27-1992-16:21-wht@n4hgf-re-include protection for all .h files */
  921. X/*:02-13-1992-06:35-wht@n4hgf-when port to many time() can be int/long/time_t */
  922. X/*:11-30-1991-13:46-wht@n4hgf-smap conditional compilation reorg */
  923. X/*:11-26-1991-20:17-wht@n4hgf-add shm->Ldcdwatch values */
  924. X/*:11-26-1991-19:37-wht@n4hgf-add STR_CLASSIFY */
  925. X/*:11-13-1991-16:29-wht@n4hgf-use if __STDC__ instead of defined(__STDC__) */
  926. X/*:11-11-1991-22:45-wht@n4hgf-redefinition of Ltermio's place in life */
  927. X/*:08-25-1991-14:39-wht@n4hgf-SVR4 port thanks to aega84!lh */
  928. X/*:08-13-1991-13:53-wht@n4hgf-UNIX and ISC nap() broken; XENIX still wins */
  929. X/*:08-09-1991-11:07-wht@n4hgf-configurable lock directory */
  930. X/*:07-25-1991-12:55-wht@n4hgf-ECU release 3.10 */
  931. X/*:01-25-1991-06:08-wht@n4hgf-mulltiple #define of ECULIBDIR */
  932. X/*:01-22-1991-14:33-wht@n4hgf-XENIX calloc/memmove fix */
  933. X/*:01-01-1991-21:36-wht@n4hgf-add GCC implies STDC */
  934. X/*:08-14-1990-20:39-wht@n4hgf-ecu3.00-flush old edit history */
  935. X
  936. X#ifndef _ecu_h
  937. X#define _ecu_h
  938. X
  939. X/*
  940. X * damn ANSI dweebs
  941. X */
  942. X#if defined(__sun__) && !defined(sun)
  943. X#define sun 1
  944. X#endif
  945. X#if defined(__i386__) && !defined(i386)
  946. X#define i386 1
  947. X#endif
  948. X#if defined(__SVR4__) && !defined(SVR4)
  949. X#define SVR4 1
  950. X#endif
  951. X
  952. X/*
  953. X * some gcc's don't know about i386
  954. X */
  955. X#if (defined(M_I386) || defined(ISC) /* || defined(MYSYS) */)  && !defined(i386)
  956. X#define i386 /* needed by setjmp.h on 386 unix r3 */
  957. X#endif
  958. X
  959. X#if !defined(STDIO_H_INCLUDED)
  960. X#include <stdio.h>
  961. X#endif
  962. X
  963. X#include <signal.h>
  964. X#include <ctype.h>
  965. X#include <errno.h>
  966. X#include <string.h>
  967. X#include <memory.h>
  968. X#include <fcntl.h>
  969. X#include "ecu_types.h"
  970. X#include "ecu_stat.h"
  971. X#include <sys/timeb.h>
  972. X
  973. X#if defined(WORKING_SELECT)
  974. X/* SCO pre 3.2v4 */
  975. X#if defined(M_XENIX) || defined(M_UNIX)
  976. X# include <sys/select.h>
  977. X#else
  978. X# include <sys/time.h>
  979. X#endif
  980. X#endif
  981. X
  982. X/*
  983. X * if building prototypes with SCO cc sometimes buggy -Zg * or using lint
  984. X */
  985. X#if defined(BUILDING_PROTOTYPES) || defined(lint)
  986. X#define ECULIBDIR "dummy"
  987. X#define HDBLIBDIR "dummy"
  988. X#define LOCK_DIR_NAME "dummy"
  989. X#define DEFAULT_TTY "/dev/tty1"
  990. X#define DEFAULT_BAUD_RATE 2400
  991. X#define DEFAULT_PARITY 'n'
  992. X#endif
  993. X
  994. X/*
  995. X * streams tty stuff is so similar to traditional that
  996. X * this hack worked for porting to the sun and left the tty code
  997. X * clean .... this hack will most certainly break down one day
  998. X */
  999. X#if !defined(OMIT_TERMIO_REFERENCES)
  1000. X#if defined(sun) || defined(USE_TERMIOS)
  1001. X#include <termio.h>        /* may need to be termios.h on other than sun */
  1002. X#define termio termios
  1003. X#undef TCGETA
  1004. X#undef TCSETA
  1005. X#undef TCSETAW
  1006. X#define TCGETA    TCGETS
  1007. X#define TCSETA    TCSETS
  1008. X#define TCSETAW    TCSETSW
  1009. X#else
  1010. X#include <termio.h>
  1011. X#endif /* sun */
  1012. X#endif /* OMIT_TERMIO_REFERENCES */
  1013. X
  1014. X/*
  1015. X * The various flavors of hardware flow control, most of them 
  1016. X * flakey or incomplete
  1017. X */
  1018. X#if defined(RTSFLOW) && !defined(HW_FLOW_CONTROL)
  1019. X#define HW_FLOW_CONTROL
  1020. X#endif
  1021. X#if defined(CRTSFL) && !defined(HW_FLOW_CONTROL)  /* 3.2v4 */
  1022. X#define HW_FLOW_CONTROL
  1023. X#endif
  1024. X#if defined(RTSXOFF) && !defined(HW_FLOW_CONTROL) /* SVR4 */
  1025. X#define HW_FLOW_CONTROL
  1026. X#endif
  1027. X#if defined(CRTSCTS) && !defined(HW_FLOW_CONTROL) /* sun */
  1028. X#define HW_FLOW_CONTROL
  1029. X#endif
  1030. X
  1031. X#if defined(M_UNIX) && !defined(GNUC) && !defined(__GNUC__)
  1032. X/* some MSC intrinsics produce bad inline code with certain usages */
  1033. X#pragma intrinsic(memcpy)    /* trust these intrinsics ... */
  1034. X#pragma intrinsic(memset)    /* ... because we know how we use them */
  1035. X#endif
  1036. X
  1037. X/*
  1038. X * Some ANSI pacifiers typedef time_t to int, some to long.
  1039. X * int is 'wrong', but on a 32-bit machine who cares?  On the 286
  1040. X * it matters.  The following compromise should allow time() to work
  1041. X * everywhere since only 286 we support is SCO XENIX/286.  Folks
  1042. X * on 386 with small model with 16-bit ints (like Coherent) will
  1043. X * get caught here, but I believe there will be larger snags as well.
  1044. X */
  1045. X#ifdef M_I286
  1046. Xlong time();
  1047. X#endif
  1048. X
  1049. Xlong Nap();
  1050. X
  1051. Xtypedef int  (*PFV)();    /* pointer to function returning void */
  1052. Xtypedef char (*PFC)();    /* pointer to function returning char */
  1053. Xtypedef int  (*PFI)();    /* pointer to function returning integer */
  1054. Xtypedef long (*PFL)();    /* pointer to function returning long */
  1055. X
  1056. X
  1057. X/* already in ecushm.h */
  1058. X/* #if !defined(ushort) */
  1059. X/* #define ushort unsigned short */
  1060. X/* #endif */
  1061. X/* #if !defined(uchar) */
  1062. X/* #define uchar unsigned char */
  1063. X/* #endif */
  1064. X/* #if !defined(uint) */
  1065. X/* #define uint unsigned int */
  1066. X/* #endif */
  1067. X/* #if !defined(ulong) */
  1068. X/* #define ulong unsigned long */
  1069. X/* #endif */
  1070. X
  1071. X#if __STDC__    /* sigh ... malloc and such types; SIGTYPE just a guess*/
  1072. X#define VTYPE void
  1073. X#define VOLATILE volatile
  1074. X#ifndef SIGTYPE
  1075. X#define SIGTYPE void
  1076. X#endif
  1077. X#else
  1078. X#define VTYPE char
  1079. X#define VOLATILE
  1080. X#ifndef SIGTYPE
  1081. X#define SIGTYPE int
  1082. X#endif
  1083. X#endif
  1084. X
  1085. X#include "smap.h"
  1086. X#if defined(MALLOC_3X)
  1087. X#include <malloc.h>
  1088. X#else
  1089. XVTYPE *malloc();
  1090. XVTYPE *calloc();
  1091. XVTYPE *realloc();
  1092. X#endif
  1093. X
  1094. X/*
  1095. X * this must come after any system header inclusion
  1096. X */
  1097. X#if defined(M_UNIX)
  1098. X#undef M_XENIX        /* now can truly distinquish between SCO XENIX and UNIX */
  1099. X#endif /* M_UNIX */
  1100. X
  1101. X#include "ecushm.h"
  1102. X#include "termecu.h"
  1103. X#include "ttynaming.h"
  1104. X
  1105. X/*
  1106. X * for better source line utilization, frequent use of
  1107. X * fprintf and stderr warrants the following
  1108. X */
  1109. X#define pf    printf
  1110. X#define ff    fprintf
  1111. X#define se    stderr
  1112. X#define so    stdout
  1113. X
  1114. X/*
  1115. X * console tty information
  1116. X */
  1117. Xextern int tty_is_multiscreen;        /* SCO multiscreen */
  1118. Xextern int tty_is_pty;                /* bursty network connection? */
  1119. Xextern int tty_not_char_special;    /* /dev/null not considered char special */
  1120. X
  1121. X/*
  1122. X * useful macros
  1123. X */
  1124. X#define max(a,b) ((a > b) ? a : b)
  1125. X#define min(a,b) ((a < b) ? a : b)
  1126. X
  1127. X/*
  1128. X * decide how to write to logfile
  1129. X */
  1130. X#define LOGPUTC fputc    /* fputc() or putc() */
  1131. X
  1132. X#define TTYIN    0
  1133. X#define TTYOUT  1                /* ditto tty output */
  1134. X#define TTYERR  2                /* ditty tty output error channel */
  1135. X
  1136. X/*
  1137. X * xbell codes (see ecuxenix.c)
  1138. X */
  1139. Xenum xbell
  1140. X{
  1141. X    XBELL_DONE = 1,        /* octaves or morse 'd' */
  1142. X    XBELL_ATTENTION,    /* morse .-.-.- ATTENTION */
  1143. X    XBELL_C,            /* morse -.-. C */
  1144. X    XBELL_3T                /* 3 Ts --- really 'o' */
  1145. X};
  1146. X
  1147. X/*
  1148. X * lopen() and related routines error codes
  1149. X */
  1150. Xenum linst
  1151. X{
  1152. X    LINST_INVALID = -50,    /* for invalid tty name */
  1153. X    LINST_UNKPID,            /* unknown pid using line */
  1154. X    LINST_LCKERR,            /* lock file open error */
  1155. X    LINST_NODEV,            /* device does not exist */
  1156. X    LINST_OPNFAIL,            /* could not access line */
  1157. X    LINST_ALREADY,            /* line already open */
  1158. X    LINST_ENABLED,            /* line enabled for login */
  1159. X    LINST_ENABLED_IN_USE,    /* line in use by incoming login */
  1160. X    LINST_DIALOUT_IN_USE,    /* line in use by another dial out */
  1161. X    LINST_NOPTY,            /* pty not supported */
  1162. X    LINST_WEGOTIT,            /* not really an error: we already
  1163. X                             * own the line (used by check_utmp())
  1164. X                             */
  1165. X    LINST_ECUUNGETTY,        /* ecuungetty unexpected response */
  1166. X    LINST_ECUUNGETTY2,        /* ecuungetty execution error */
  1167. X    LINST_NOTCHR            /* not a character special */
  1168. X};
  1169. X
  1170. X/*
  1171. X * filename sizes
  1172. X */
  1173. X#define CURR_DIRSIZ 256            /* current directory array size */
  1174. X#define PHONEDIR_NAME_SIZE 256    /* phone directory */
  1175. X
  1176. X/*
  1177. X * in case errno.h doesn't pick this up
  1178. X */
  1179. Xextern int errno;
  1180. Xextern char *sys_errlist[];
  1181. Xextern int sys_nerr;
  1182. Xchar *errno_text();        /* see ecuutil.c */
  1183. X
  1184. Xchar *getenv();
  1185. X
  1186. X/*
  1187. X * process IDs
  1188. X */
  1189. Xextern PID_T rcvr_pid;
  1190. Xextern PID_T xmtr_pid;
  1191. X
  1192. X/*
  1193. X * both of the following are set by xmtr_SIGINT_handler()
  1194. X * 'sigint' reset by 1st detector/processor
  1195. X * 'proc_interrupt' reset/handled by procedure monitor
  1196. X *                  (execute_esd and execute_proc)
  1197. X */
  1198. Xextern int sigint;
  1199. X/* extern int proc_interrupt; <------ force using modules to declare it */
  1200. X
  1201. X/*
  1202. X * procedure nesting level
  1203. X * non-zero if procedure executing (see proc.c)
  1204. X */
  1205. Xextern int proc_level;
  1206. Xextern int proctrace;
  1207. X
  1208. X/*
  1209. X * need_rcvr_restart() - check rcvr status
  1210. X *
  1211. X * If rcvr_pid == -2, queued restart has been requested by some function
  1212. X * but we don't want to do it if a procedure is executing
  1213. X */
  1214. X#define need_rcvr_restart() \
  1215. X    ((rcvr_pid > 0) || ((rcvr_pid == -2) && !proc_level))
  1216. X
  1217. X/*
  1218. X * 'hz' is getenv("HZ"); that not found, the value from sys/param.h
  1219. X * 'hzmsec' is ceiling(clock period) in milliseconds
  1220. X */
  1221. Xextern int hz;                /* HZ from environ or sys/param.h */
  1222. Xextern ulong hzmsec;        /* clock period in msec rounded up */
  1223. X
  1224. X/*
  1225. X * Communication line variables that are not in shared memory
  1226. X *
  1227. X * One special note: Ltermio points to a buffer in shared memory
  1228. X * used to hold the line's current termio structure.  The shared
  1229. X * memory buffer is defined as a simple array of longs so that
  1230. X * friend code need not include termio.h if it does not need it.
  1231. X * What's more, due to sgtty-based curses code, XENIX versions
  1232. X * cannot include termio.h in some modules.  ecushm.c has runtime
  1233. X * code to initialize Ltermio to point to shm->Ltiobuf and to
  1234. X * make sure shm->Ltiobuf is long enough. This is a hack of
  1235. X */
  1236. X#if defined(DECLARE_LINEVARS_PUBLIC)
  1237. X#if !defined(OMIT_TERMIO_REFERENCES)
  1238. Xstruct termio *Ltermio;        /* attributes for the line to remote */
  1239. X#endif
  1240. Xuchar Ldial_debug_level;
  1241. X#else
  1242. X#if !defined(OMIT_TERMIO_REFERENCES)
  1243. Xextern struct termio *Ltermio;
  1244. X#endif
  1245. Xextern uchar Ldial_debug_level;
  1246. X#endif
  1247. X
  1248. Xextern int zero_length_read_detected;    /* see lgetc_xmtr in eculine.c */
  1249. X
  1250. X/*
  1251. X * lock file directory
  1252. X */
  1253. Xextern char *lock_dir_name;    /* defined in ecuLCK.c */
  1254. X
  1255. X/*
  1256. X * setcolor variables - see setcolor()
  1257. X */
  1258. Xextern ulong colors_current;
  1259. Xextern ulong colors_normal;
  1260. Xextern ulong colors_success;
  1261. Xextern ulong colors_alert;
  1262. Xextern ulong colors_error;
  1263. Xextern ulong colors_notify;
  1264. X
  1265. X/*
  1266. X * miscellaneuous
  1267. X */
  1268. Xextern char *eculibdir;        /* lib dir, i.e., "/usr/local/lib/ecu" */
  1269. Xextern char *ttype;            /* getenv("TERM") */
  1270. X
  1271. X/*
  1272. X * param to lgets_timeout in eculine.c
  1273. X */
  1274. Xtypedef struct lrwt
  1275. X{
  1276. X    ulong to1;        /* timeout for 1st character (granularity 20) */
  1277. X    ulong to2;        /* timeout for each next char (granularity 20) */
  1278. X    int raw_flag;    /* !=0, rtn full buffer, ==0, rtn filtered hayes result */
  1279. X    char *buffer;    /* buffer to fill */
  1280. X    int bufsize;    /* size of buffer */
  1281. X    int count;        /* from proc, count rcvd */
  1282. X    char *delim;    /* ending string for lgets_timeout_or_delim */
  1283. X    int echo_flag;    /* echo incoming chars to screen */
  1284. X}    LRWT;
  1285. X
  1286. X/*
  1287. X * parameter structure for str_classify()
  1288. X */
  1289. Xtypedef struct str_classify
  1290. X{
  1291. X    char *str;        /* string to match */
  1292. X    int min_ch;        /* minimum characters required */
  1293. X    int token;        /* token for match */
  1294. X} STR_CLASSIFY;
  1295. X
  1296. X/*
  1297. X * shm->Ldcdwatch values
  1298. X */
  1299. X#define DCDW_OFF        0
  1300. X#define DCDW_ON            1
  1301. X#define DCDW_TERMINATE    2
  1302. X
  1303. X#ifdef DEBUG_SRP
  1304. X#define start_rcvr_process(flag) _start_rcvr_process(flag,__FILE__,__LINE__)
  1305. X#else
  1306. X#define start_rcvr_process(flag) _start_rcvr_process(flag)
  1307. X#endif
  1308. X
  1309. X/*
  1310. X * prototyes or external declarations
  1311. X *
  1312. X * "I took a silver needle [ANSI] and I put it into my arm.
  1313. X * It did some good. It did some harm.  But the nights were
  1314. X * cold and lonely and it almost kept me warm."
  1315. X * -- Leonard Cohen, _Songs from a Room_
  1316. X *
  1317. X */
  1318. X#ifdef USE_PROTOS
  1319. X# include "protos.h"
  1320. X#endif
  1321. X
  1322. X#ifdef XECU
  1323. X# include "xecu.h"
  1324. X#endif
  1325. X
  1326. X#endif /* _ecu_h */
  1327. X
  1328. X/* vi: set tabstop=4 shiftwidth=4: */
  1329. X/* end of ecu.h */
  1330. SHAR_EOF
  1331. chmod 0644 ecu.h ||
  1332. echo 'restore of ecu.h failed'
  1333. Wc_c="`wc -c < 'ecu.h'`"
  1334. test 11447 -eq "$Wc_c" ||
  1335.     echo 'ecu.h: original size 11447, current size' "$Wc_c"
  1336. rm -f _shar_wnt_.tmp
  1337. fi
  1338. # ============= ecuDCE.c ==============
  1339. if test -f 'ecuDCE.c' -a X"$1" != X"-c"; then
  1340.     echo 'x - skipping ecuDCE.c (File already exists)'
  1341.     rm -f _shar_wnt_.tmp
  1342. else
  1343. > _shar_wnt_.tmp
  1344. echo 'x - extracting ecuDCE.c (Text)'
  1345. sed 's/^X//' << 'SHAR_EOF' > 'ecuDCE.c' &&
  1346. X/* #define USE_S7 */
  1347. X/*+-------------------------------------------------------------------------
  1348. X    ecuDCE.c - ECU DCE dialing and management
  1349. X    wht@n4hgf.Mt-Park.GA.US
  1350. X
  1351. X  Defined functions:
  1352. X    DCE_autoanswer()
  1353. X    DCE_dial()
  1354. X    DCE_get_result(msec_to_wait)
  1355. X    DCE_get_sreg_value(regnum)
  1356. X    DCE_hangup()
  1357. X    DCE_modem_init()
  1358. X    DCE_now_on_hook()
  1359. X    DCE_read_modem_init()
  1360. X    DCE_redial(arg,argc)
  1361. X    DCE_report_iv_set(varnum)
  1362. X    DCE_send_cmd(cmd)
  1363. X    DCE_set_sreg(regnum,value)
  1364. X    check_queued_sigint()
  1365. X    process_modem_init(str)
  1366. X    show_modem_init_error(erc,iesd)
  1367. X
  1368. XLothar Hirschbiegel <emory!tmcsys.uucp!lothar> added the ability to
  1369. Xspecify a modem acknowledgement string other than "OK".
  1370. XExample use:
  1371. X#+-----------------------------------------------------------------
  1372. X#  tty1a.mi - Microcom QX/V.32c
  1373. X#------------------------------------------------------------------
  1374. Xinit_default:sceon
  1375. Xdial_default:dp
  1376. Xok_string:!
  1377. X
  1378. X--------------------------------------------------------------------------*/
  1379. X/*+:EDITS:*/
  1380. X/*:09-10-1992-13:58-wht@n4hgf-ECU release 3.20 */
  1381. X/*:09-05-1992-14:17-wht@n4hgf-was starting rcvr process too early on connect */
  1382. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  1383. X/*:04-19-1992-03:21-jhpb@sarto.budd-lake.nj.us-3.18.37 has ESIX SVR4 */
  1384. X/*:02-16-1992-01:41-wht@n4hgf-turn off xterm_title */
  1385. X/*:02-04-1992-04:49-wht@n4hgf-fix bug in kill_rcvr_process logic */
  1386. X/*:01-17-1992-15:32-wht@n4hgf-.credit open to public */
  1387. X/*:11-07-1991-16:54-tmcsys!lothar-alternate OK string for built-in dialer */
  1388. X/*:08-28-1991-14:07-wht@n4hgf2-SVR4 cleanup by aega84!lh */
  1389. X/*:07-25-1991-12:55-wht@n4hgf-ECU release 3.10 */
  1390. X/*:07-17-1991-07:04-wht@n4hgf-avoid SCO UNIX nap bug */
  1391. X/*:06-29-1991-15:42-wht@n4hgf-if WHT and xterm, play with title bar */
  1392. X/*:06-16-1991-23:24-wht@n4hgf-ensure hangup since proc could fail connected */
  1393. X/*:06-07-1991-04:09-wht@n4hgf-remove unnecessary naps after kill_rcvr_process */
  1394. X/*:05-20-1991-00:56-wht@n4hgf-fix/upgrade auto fkey load */
  1395. X/*:01-09-1991-22:31-wht@n4hgf-ISC port */
  1396. X/*:01-09-1991-21:23-wht@n4hgf-fix statement not reached */
  1397. X/*:09-19-1990-19:36-wht@n4hgf-ecu_log_event now gets pid for log from caller */
  1398. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1399. X
  1400. X#include "ecu.h"
  1401. X#include "ecukey.h"
  1402. X#include "esd.h"
  1403. X#include "var.h"
  1404. X#include "ecupde.h"
  1405. X#include "ecuerror.h"
  1406. X#include "relop.h"
  1407. X
  1408. X
  1409. Xchar *get_elapsed_time();
  1410. Xchar *make_char_graphic();
  1411. Xvoid DCE_hangup();
  1412. X
  1413. Xextern int proctrace;
  1414. Xextern ulong colors_current;
  1415. Xextern char kbdintr;
  1416. X
  1417. Xint mi_line;
  1418. Xchar mi_name[64];
  1419. Xchar last_dial_result[64];
  1420. X
  1421. X#define MI_MAX_LEN 65
  1422. Xchar Lmodem_init[MI_MAX_LEN] = "";        /* modem init string w/o trailing CR */
  1423. Xchar Lmodem_dial[MI_MAX_LEN] = "";        /* modem dialing prefix */
  1424. Xchar Lmodem_autoans[MI_MAX_LEN] = "";    /* modem autoanswer */
  1425. Xchar Lmodem_okstring[MI_MAX_LEN] = "";    /* modem ok_answer */
  1426. X
  1427. Xchar *interrupted_string = "!Interrupted";
  1428. X
  1429. X/*+-------------------------------------------------------------------------
  1430. X    check_queued_sigint()
  1431. X--------------------------------------------------------------------------*/
  1432. Xint
  1433. Xcheck_queued_sigint()
  1434. X{
  1435. X    while(ttyrdchk())
  1436. X    {
  1437. X        if((uchar)ttygetc(1) == (uchar)kbdintr)
  1438. X        {
  1439. X            sigint = 1;
  1440. X            return(1);
  1441. X        }
  1442. X    }
  1443. X    return(0);
  1444. X}    /* end of check_queued_sigint */
  1445. X
  1446. X/*+-------------------------------------------------------------------------
  1447. X    show_modem_init_error(erc,iesd)
  1448. X--------------------------------------------------------------------------*/
  1449. Xvoid
  1450. Xshow_modem_init_error(erc,iesd)
  1451. Xint erc;
  1452. XESD *iesd;
  1453. X{
  1454. X    register itmp;
  1455. X
  1456. X    pputs(mi_name);
  1457. X    pprintf(" line %d: ",mi_line);
  1458. X    proc_error(erc);
  1459. X    pputs(iesd->pb);
  1460. X    pputc(NL);
  1461. X    itmp = iesd->old_index;
  1462. X    while(itmp--)
  1463. X        pputc(' ');
  1464. X    pputs("^\n\n");
  1465. X
  1466. X}    /* end of show_modem_init_error */
  1467. X
  1468. X/*+-----------------------------------------------------------------------
  1469. X    process_modem_init(str)
  1470. X
  1471. Xsample /usr/lib/ecu/tty??.mi lines:
  1472. Xinit_9600:ATS11=47X4S0=0S7=30\Q0\X0\N0
  1473. Xinit_>2400:ATS11=47X4S0=0S7=30\Q0\X0\N0
  1474. Xinit_<=2400:ATS11=47X4S0=0S7=30\Q1\X1\N3
  1475. XATDT
  1476. X
  1477. Xreturn 0 if entire list read, else 1 if error (error msg in errmsg)
  1478. X------------------------------------------------------------------------*/
  1479. Xvoid
  1480. Xprocess_modem_init(str)
  1481. Xchar *str;
  1482. X{
  1483. X#define MI_INIT        1
  1484. X#define MI_DIAL        2
  1485. X#define MI_AUTOANS    3
  1486. X#define MI_OKSTRING    4
  1487. X    int erc;
  1488. X    ESD sesd;
  1489. X    char typestr[32];
  1490. X    int relop;
  1491. X    int truth = 0;
  1492. X    int type;
  1493. X    long test_baud;
  1494. X
  1495. X    sesd.pb = str;
  1496. X    sesd.cb = strlen(str);
  1497. X    sesd.maxcb = strlen(str);
  1498. X    sesd.index = 0;
  1499. X    sesd.old_index = 0;
  1500. X
  1501. X    if(get_alpha_zstr(&sesd,typestr,sizeof(typestr)))
  1502. X    {
  1503. X        erc = eSyntaxError;
  1504. X        goto SHOW_ERROR;
  1505. X    }
  1506. X    if(ulindex(typestr,"init_") == 0)
  1507. X        type = MI_INIT;
  1508. X    else if(ulindex(typestr,"dial_") == 0)
  1509. X        type = MI_DIAL;
  1510. X    else if(!strcmpi(typestr,"autoanswer"))
  1511. X        type = MI_AUTOANS;
  1512. X    else if(!strcmpi(typestr,"ok_string"))
  1513. X        type = MI_OKSTRING;
  1514. X    else
  1515. X    {
  1516. X        erc = eSyntaxError;
  1517. X        goto SHOW_ERROR;
  1518. X    }
  1519. X
  1520. X/* test for default ... if none, check baud rate */
  1521. X    if((type == MI_AUTOANS) || (type == MI_OKSTRING)) 
  1522. X        truth = 1;
  1523. X    else if(ulindex(typestr,"_default") > 0)
  1524. X    {
  1525. X        truth = !( ((type == MI_INIT) && Lmodem_init[0]) ||
  1526. X            ((type == MI_DIAL) && Lmodem_dial[0]));
  1527. X    }
  1528. X    else
  1529. X    {
  1530. X        /* get optional operator */
  1531. X        if(get_relop(&sesd,&relop))
  1532. X            relop = OP_EQ;
  1533. X        if(erc = gint_constant(&sesd,&test_baud))
  1534. X            goto SHOW_ERROR;
  1535. X        truth = test_truth_int((long)shm->Lbaud,relop,test_baud);
  1536. X    }
  1537. X
  1538. X/* if no match, skip this one */
  1539. X    if(!truth)
  1540. X        return;
  1541. X
  1542. X/* skip over colon */
  1543. X    if(erc = skip_colon(&sesd))
  1544. X        goto SHOW_ERROR;
  1545. X
  1546. X/* make sure init or dial string not empty or too long */
  1547. X    if((erc = skip_cmd_break(&sesd)) && (type != MI_AUTOANS))
  1548. X        goto SHOW_ERROR;
  1549. X
  1550. X    if((sesd.cb - sesd.index) > (MI_MAX_LEN - 1))
  1551. X    {
  1552. X        erc = eBufferTooSmall;
  1553. X        goto SHOW_ERROR;
  1554. X    }
  1555. X
  1556. X    erc = eDuplicateMatch;        /* in case of show error in switch */
  1557. X    switch(type)
  1558. X    {
  1559. X        case MI_INIT:
  1560. X            if(Lmodem_init[0])
  1561. X                goto SHOW_ERROR;
  1562. X            strcpy(Lmodem_init,sesd.pb + sesd.index);
  1563. X            break;
  1564. X
  1565. X        case MI_DIAL:
  1566. X            if(Lmodem_dial[0])
  1567. X                goto SHOW_ERROR;
  1568. X            strcpy(Lmodem_dial,sesd.pb + sesd.index);
  1569. X            break;
  1570. X
  1571. X        case MI_AUTOANS:
  1572. X            if(Lmodem_autoans[0])
  1573. X                goto SHOW_ERROR;
  1574. X            if(!sesd.cb)
  1575. X                strcpy(Lmodem_autoans,"!null!");
  1576. X            else
  1577. X                strcpy(Lmodem_autoans,sesd.pb + sesd.index);
  1578. X            break;
  1579. X
  1580. X        case MI_OKSTRING:
  1581. X            if(Lmodem_okstring[0])
  1582. X                goto SHOW_ERROR;
  1583. X            strcpy(Lmodem_okstring,sesd.pb + sesd.index);
  1584. X            break;
  1585. X            
  1586. X    }
  1587. X    return;        /* <<<<====== done */
  1588. X
  1589. XSHOW_ERROR:
  1590. X    show_modem_init_error(erc,&sesd);
  1591. X
  1592. X}    /* end of process_modem_init */
  1593. X
  1594. X/*+-----------------------------------------------------------------------
  1595. X    DCE_read_modem_init()
  1596. X0123456789
  1597. X/dev/ttyxx
  1598. X------------------------------------------------------------------------*/
  1599. Xvoid
  1600. XDCE_read_modem_init()
  1601. X{
  1602. X    char *cptr;
  1603. X    register FILE *fp_modem;
  1604. X    char *skip_ld_break();
  1605. X    char buffer[128];
  1606. X
  1607. X/* zap init information */
  1608. X    Lmodem_init[0] = 0;
  1609. X    Lmodem_dial[0] = 0;
  1610. X
  1611. X/* build filename */
  1612. X    sprintf(mi_name,"%s/%s.mi",ECULIBDIR,shm->Lline + 5);
  1613. X
  1614. X/* read modem initialization */
  1615. X    if(!(fp_modem = fopen(mi_name,"r")))
  1616. X        pperror(mi_name);
  1617. X    else
  1618. X    {
  1619. X        mi_line = 0;
  1620. X        while((!Lmodem_init[0] || !Lmodem_dial[0] || !Lmodem_okstring[0]) &&
  1621. X            fgets(buffer,sizeof(buffer),fp_modem))
  1622. X        {
  1623. X            mi_line++;
  1624. X            buffer[strlen(buffer) - 1] = 0;
  1625. X            cptr = skip_ld_break(buffer);
  1626. X            /* skip comments and null lines */
  1627. X            if(!strlen(cptr) || (*cptr == '#'))
  1628. X                continue;
  1629. X            process_modem_init(cptr);
  1630. X        }
  1631. X        fclose(fp_modem);
  1632. X    }
  1633. X
  1634. X/* default */
  1635. X    if(!Lmodem_init[0])
  1636. X    {
  1637. X        strcpy(Lmodem_init,"ATE1Q0V1");
  1638. X        pputs("modem init string not found (using default '");
  1639. X        pputs(Lmodem_init);
  1640. X        pputs("')\n");
  1641. X    }
  1642. X    if(!Lmodem_dial[0])
  1643. X    {
  1644. X        strcpy(Lmodem_dial,"ATDT");
  1645. X        pputs("modem dial string not found (using default '");
  1646. X        pputs(Lmodem_dial);
  1647. X        pputs("')\n");
  1648. X    }
  1649. X
  1650. X    if(!Lmodem_autoans[0])
  1651. X    {
  1652. X        strcpy(Lmodem_autoans,"ATQ1S0=1");
  1653. X#ifdef INUSE
  1654. X        pputs("modem autoanswer string not found (using default '");
  1655. X        pputs(Lmodem_autoans);
  1656. X        pputs("')\n");
  1657. X#endif
  1658. X    }
  1659. X    if(!Lmodem_okstring[0])
  1660. X    {
  1661. X        strcpy(Lmodem_okstring,"OK");
  1662. X#ifdef notdef
  1663. X        pputs("modem ok_string not found (using default '");
  1664. X        pputs(Lmodem_okstring);
  1665. X        pputs("')\n");
  1666. X#endif
  1667. X    }
  1668. X    else if(!strcmp(Lmodem_autoans,"!null!"))
  1669. X        Lmodem_autoans[0] = 0;
  1670. X
  1671. X     if(proctrace > 1)  
  1672. X    {
  1673. X        pprintf("init:       '%s'\n",Lmodem_init);
  1674. X        pprintf("dial:       '%s'\n",Lmodem_dial);
  1675. X        pprintf("autoanswer: '%s'\n",Lmodem_autoans);
  1676. X        pprintf("okstring:   '%s'\n",Lmodem_okstring);
  1677. X    }
  1678. X}    /* end of DCE_read_modem_init */
  1679. X
  1680. X/*+-------------------------------------------------------------------------
  1681. X    DCE_get_result(msec_to_wait)
  1682. Xreturn pointer to static buf containing result code
  1683. X--------------------------------------------------------------------------*/
  1684. Xchar *
  1685. XDCE_get_result(msec_to_wait)
  1686. Xlong msec_to_wait;
  1687. X{
  1688. X    static char s32[32];
  1689. X    LRWT lr;
  1690. X
  1691. X    if(sigint)
  1692. X        return("!Interrupted");
  1693. X    s32[0] = 0;
  1694. X    lr.to1 = msec_to_wait;
  1695. X    lr.to2 = 200L;
  1696. X    lr.raw_flag = 0x80; /* allow interrupts */
  1697. X    lr.buffer = s32;
  1698. X    lr.bufsize = sizeof(s32);
  1699. X    lr.delim = (char *)0;
  1700. X    lr.echo_flag = 0;
  1701. X    lgets_timeout(&lr);
  1702. X
  1703. X    if(sigint)
  1704. X        return("!Interrupted");
  1705. X
  1706. X    return(lr.buffer);
  1707. X}    /* end of DCE_get_result */
  1708. X
  1709. X/*+-------------------------------------------------------------------------
  1710. X    DCE_modem_init()
  1711. X--------------------------------------------------------------------------*/
  1712. XDCE_modem_init()
  1713. X{
  1714. X    register itmp;
  1715. X    int retries = 0;
  1716. X    char *cmd;
  1717. X    char *cptr;
  1718. X    int old_ttymode = get_ttymode();
  1719. X
  1720. X    if(shm->Lmodem_already_init)
  1721. X        return(0);
  1722. X
  1723. X    DCE_read_modem_init();
  1724. X
  1725. X    ttymode(2);
  1726. X    lputs_paced(0,"\b\b\b\b\b\b\b\b\b");
  1727. X    (void)Nap(200L);
  1728. X    lflush(0);
  1729. X
  1730. X    while(!shm->Lmodem_already_init)
  1731. X    {
  1732. XINIT_LOOP:
  1733. X        if(retries > 3)
  1734. X            goto ERROR_RETURN;
  1735. X
  1736. X        if(sigint)
  1737. X            goto ERROR_RETURN;
  1738. X
  1739. X        if(retries)
  1740. X        {
  1741. X            lflash_dtr();
  1742. X            lputs_paced(0,"AT\r");
  1743. X            (void)Nap(400L);
  1744. X            lputs_paced(0,"ATQ0V1E1\r");
  1745. X            (void)Nap(400L);
  1746. X        }
  1747. X
  1748. X        lflush(0);
  1749. X        cmd = Lmodem_init;
  1750. X        itmp = 0;
  1751. X#ifdef NEUROTIC
  1752. X        while(*cmd)
  1753. X        {
  1754. X            lputc_paced(0,*cmd++);
  1755. X            if(++itmp < 2)
  1756. X                (void)Nap(40L);
  1757. X            if((itmp = lgetc_timeout(500L)) < 0)
  1758. X            {
  1759. X                if(sigint)
  1760. X                    goto ERROR_RETURN;
  1761. X                retries++;
  1762. X                goto INIT_LOOP;
  1763. X            }
  1764. X            pputc(itmp);
  1765. X        }
  1766. X#else
  1767. X        lputs(cmd);
  1768. X        pputs(cmd);
  1769. X#endif
  1770. X
  1771. X        pputc(NL);
  1772. X        lputc_paced(0,CRET);
  1773. X
  1774. X        itmp = 0;
  1775. X        while(itmp != CRET)
  1776. X        {
  1777. X            if((itmp = lgetc_timeout(500L)) < 0)
  1778. X            {
  1779. X                if(sigint)
  1780. X                    goto ERROR_RETURN;
  1781. X                pputs("missed expected carriage return\n");
  1782. X                pprintf("got: %x\n",itmp);
  1783. X                retries++;
  1784. X                goto INIT_LOOP;
  1785. X            }
  1786. X        }
  1787. X
  1788. X        if(strcmp(cptr = DCE_get_result(1200L),Lmodem_okstring))
  1789. X        {
  1790. X            if(!strcmp(cptr,interrupted_string))
  1791. X            {
  1792. X                sigint = 1;
  1793. X                goto ERROR_RETURN;
  1794. X            }
  1795. X            pprintf("unexpected result: '%s'\n",cptr);
  1796. X            retries++;
  1797. X            continue;
  1798. X        }
  1799. X        shm->Lmodem_already_init = 1;
  1800. X    }
  1801. X
  1802. X    ttymode(old_ttymode);
  1803. X    return(0);
  1804. X
  1805. XERROR_RETURN:
  1806. X    ttymode(old_ttymode);
  1807. X    return(-1);
  1808. X
  1809. X}    /* end of DCE_modem_init */
  1810. X
  1811. X/*+-------------------------------------------------------------------------
  1812. X    DCE_send_cmd(cmd)
  1813. X--------------------------------------------------------------------------*/
  1814. Xint
  1815. XDCE_send_cmd(cmd)
  1816. Xregister char *cmd;
  1817. X{
  1818. X    register itmp;
  1819. X
  1820. X    DCE_modem_init();
  1821. X    (void)Nap(600L);
  1822. X
  1823. X    lflush(0);
  1824. X#ifdef NEUROTIC
  1825. X    while(*cmd)
  1826. X    {
  1827. X        lputc_paced(20,*cmd++);
  1828. X        if(++char_count < 2)
  1829. X            (void)Nap(40L);
  1830. X        if((itmp = lgetc_timeout(500L)) < 0)
  1831. X            return(-1);
  1832. X        pputc(itmp);
  1833. X    }
  1834. X#else
  1835. X    lputs(cmd);
  1836. X    pputs(cmd);
  1837. X#endif
  1838. X    pputc(NL);
  1839. X    lputc_paced(20,CRET);
  1840. X    itmp = 0;
  1841. X    if(sigint || check_queued_sigint())
  1842. X        return(-1);
  1843. X    while(itmp != CRET)
  1844. X    {
  1845. X        if((itmp = lgetc_timeout(1000L)) < 0)
  1846. X        {
  1847. X            pputs("missed expected carriage return\n");
  1848. X            return(-1);
  1849. X        }
  1850. X        if(sigint || check_queued_sigint())
  1851. X            return(-1);
  1852. X    }
  1853. X    return(0);
  1854. X
  1855. X}    /* end of DCE_send_cmd */
  1856. X
  1857. X/*+-------------------------------------------------------------------------
  1858. X    DCE_report_iv_set(varnum)
  1859. X--------------------------------------------------------------------------*/
  1860. Xvoid
  1861. XDCE_report_iv_set(varnum)
  1862. Xint varnum;
  1863. X{
  1864. X    if(proctrace)
  1865. X        pprintf("modem handler set $i%02d = %ld\n",varnum,iv[varnum]);
  1866. X}    /* end of DCE_report_iv_set */
  1867. X
  1868. X/*+-----------------------------------------------------------------------
  1869. X    DCE_dial() - dial a remote or connect
  1870. X
  1871. X  All shm->L... variables have been set up and are used to
  1872. X  drive the dialing sequence
  1873. X
  1874. X  returns 0 on success (CONNECT),
  1875. X          eConnectFailed if failure
  1876. X          eCONINT on interrupt
  1877. X
  1878. X  sets #I0 to 0==connect,
  1879. X              1==failed to connect,
  1880. X              2==interrupted
  1881. X              3==modem error
  1882. X  sets #S0 to modem result code or uucp status code string
  1883. X
  1884. X  This function has gotten quite NASTY and needs rewriting!
  1885. X------------------------------------------------------------------------*/
  1886. Xint
  1887. XDCE_dial()
  1888. X{
  1889. X    char s128[128];
  1890. X    int itmp;
  1891. X    int erc = -1;        /* assume error unless chg'd */
  1892. X    int s7;
  1893. X    char *result = "";
  1894. X    int restart_rcvr = need_rcvr_restart();
  1895. X    ulong colors_at_entry = colors_current;
  1896. X    char s64[64];
  1897. X    char *_doproc_args[3];
  1898. X    FILE *fp;
  1899. X    char *cptr;
  1900. X    char credit_file[128];
  1901. X    extern char kbdintr;        /* current input INTR */
  1902. X
  1903. X    kill_rcvr_process(SIGUSR1);
  1904. X
  1905. X    lclear_xmtr_xoff();
  1906. X    if(shm->Ldescr[0])
  1907. X    {
  1908. X        setcolor(colors_success);
  1909. X        get_tod(1,s64);
  1910. X        pprintf("%s %s\n",
  1911. X            (shm->Ltelno[0]) ? "Dialing" : "Connecting to",shm->Ldescr);
  1912. X        pprintf("on %s at %u baud (%s)\n",shm->Lline,shm->Lbaud,s64);
  1913. X    }
  1914. X
  1915. X    DCE_hangup();
  1916. X    last_dial_result[0] = 0;
  1917. X    setcolor(colors_alert);
  1918. X    if(!shm->Ltelno[0])    /* if no phone number, direct connect */
  1919. X    {
  1920. X        sprintf(s64,"CONNECT %u",shm->Lbaud);
  1921. X        result = s64;
  1922. X        iv[0] = 0;
  1923. X        erc = 0;
  1924. X        shm->Lconnected = 1;
  1925. X        Ldial_debug_level = 0;
  1926. X        goto CONNECTED;
  1927. X    }
  1928. X     else
  1929. X    {
  1930. X        itmp = hdb_dial(&result);
  1931. X        lreset_ksr();    /* dialer may have changed termio */
  1932. X        switch(itmp)
  1933. X        {
  1934. X            case 0:        /* success */
  1935. X                goto CONNECTED;
  1936. X            case 1:        /* failure -- iv[0] set by hdb_dial */
  1937. X                DCE_report_iv_set(0);
  1938. X                erc = eConnectFailed;
  1939. X                goto START_RCVR_PROCESS;
  1940. X            case 2:        /* interrupted -- iv[0] set by hdb_dial */
  1941. X                DCE_report_iv_set(0);
  1942. X                erc = eCONINT;
  1943. X                goto START_RCVR_PROCESS;
  1944. X            case 3:        /* modem error */
  1945. X                setcolor(colors_error);
  1946. X                pprintf("%s\n",result);
  1947. X                goto CANNOT_TALK_TO_MODEM;
  1948. X            case 4:        /* try local */
  1949. X                pputs("\ntrying ecu dialer\n");
  1950. X                break;
  1951. X        }
  1952. X
  1953. X        /*
  1954. X         * brain-damaged "built-in dialer"
  1955. X         */
  1956. X
  1957. X        DCE_modem_init();
  1958. X
  1959. X#if defined(USE_S7)
  1960. X        if((s7 = DCE_get_sreg_value(7)) < 0)
  1961. X            s7 = 30;
  1962. X#else
  1963. X        s7 = 30;
  1964. X#endif
  1965. X
  1966. X        /*
  1967. X         * build dial command
  1968. X         */
  1969. X        strcpy(s128,Lmodem_dial);
  1970. X        strcat(s128,shm->Ltelno);
  1971. X
  1972. X        /*
  1973. X         * if trailing '$', read and append ~/.ecu/.credit
  1974. X         */
  1975. X        if(*(cptr = s128 + strlen(s128) - 1) == '$')
  1976. X        {
  1977. X            *cptr = 0;
  1978. X            get_home_dir(credit_file);
  1979. X            strcat(credit_file,"/.ecu/.credit");
  1980. X            if(fp = fopen(credit_file,"r"))
  1981. X            {
  1982. X                fgets(cptr,30,fp);
  1983. X                fclose(fp);
  1984. X            }
  1985. X            if(!fp || !(*cptr))
  1986. X            {
  1987. X                result = "!CREDIT CARD ERROR";
  1988. X                goto CONNECT_FAILED;
  1989. X            }
  1990. X            if(*(cptr + strlen(cptr) - 1) == 0x0A)
  1991. X                *(cptr + strlen(cptr) - 1) = 0; /* kill NL */
  1992. X        }
  1993. X
  1994. X        if(sigint || check_queued_sigint())
  1995. X            goto SEND_CMD_ERROR;
  1996. X
  1997. X        if(DCE_send_cmd(s128))
  1998. X            goto SEND_CMD_ERROR;
  1999. X
  2000. X        /* some modems (ahem, the Hayes 2400) do not accurately honor S7
  2001. X        so our timer is twice sreg 7 */
  2002. X         pprintf("Type %s to abort ... ",make_char_graphic(kbdintr,1));
  2003. X        setcolor(colors_normal);
  2004. X        lflush(0);
  2005. X        strcpy(s64,DCE_get_result(s7 * 2 * 1000L));
  2006. X        result = s64;
  2007. X
  2008. X        if(sigint || !strcmp(result,interrupted_string))
  2009. X        {
  2010. X            setcolor(colors_error);
  2011. X            pprintf("%s\n",result);
  2012. X            sigint = 0;
  2013. X            lputc(0);            /* send char in case DTR ignored */
  2014. X            lflash_dtr();                    /* force on hook */
  2015. X            (void)DCE_get_result(2000L);    /* wait for any result code */
  2016. X            erc = eCONINT;
  2017. X            iv[0] = 2;
  2018. X            DCE_report_iv_set(0);
  2019. X            goto START_RCVR_PROCESS;
  2020. X        }
  2021. X        if(!strncmp(result,"CONNECT",7))
  2022. X        {
  2023. X            if(strlen(result) > (unsigned)7)
  2024. X            {
  2025. X                if(shm->Lbaud != (unsigned)atoi(result + 7))
  2026. X                {
  2027. X                    setcolor(colors_error);
  2028. X                    pprintf("%s (incorrect rate)\n",result);
  2029. X                    iv[0] = 2;
  2030. X                    DCE_report_iv_set(0);
  2031. X                    goto START_RCVR_PROCESS;
  2032. X                }
  2033. X            }
  2034. XCONNECTED:
  2035. X#if defined(WHT2) && defined(XTERM_FRIEND)
  2036. X            /*
  2037. X             * if xterm, put connection in title bar
  2038. X             * but this really should be done in _connect.ep
  2039. X             */
  2040. X            sprintf(s128,"connected to %s",shm->Llogical);
  2041. X            xterm_title(s128,1);
  2042. X#endif
  2043. X            setcolor(colors_success);
  2044. X            pprintf("%s\n",result);
  2045. X            sprintf(s128,"CONNECT %s (%s) %u baud",
  2046. X                shm->Llogical,shm->Ltelno,shm->Lbaud);
  2047. X            strcpy(shm->Lrname,shm->Llogical);
  2048. X            ecu_log_event(getpid(),s128);
  2049. X            if(isalpha(shm->Llogical[0]))
  2050. X            {
  2051. X                if(!keyset_read(shm->Llogical))
  2052. X                    pprintf("[autoloaded fkeys for %s]\n",shm->Llogical);
  2053. X            }
  2054. X            shmx_connect();
  2055. X            shm->xmit_chars_this_connect = 0L;
  2056. X            shm->Loff_hook_time = time((long *)0);
  2057. X            iv[0] = 0;
  2058. X            DCE_report_iv_set(0);
  2059. X            erc = 0;
  2060. X            shm->Lconnected = 1;
  2061. X            lCLOCAL(!shm->Ldcdwatch); /* set CLOCAL per DCD watcher */
  2062. X            goto START_RCVR_PROCESS;
  2063. X        }
  2064. X
  2065. XCONNECT_FAILED: ;
  2066. X        setcolor(colors_error);
  2067. X        pprintf("%s\n",result);
  2068. X        iv[0] = 1;
  2069. X        DCE_report_iv_set(0);
  2070. X        erc = eConnectFailed;
  2071. X        goto START_RCVR_PROCESS;
  2072. X    }
  2073. X
  2074. XSEND_CMD_ERROR: ;
  2075. X    if(sigint)
  2076. X    {
  2077. X        sigint = 0;
  2078. X        result = interrupted_string;
  2079. X        iv[0] = 2;
  2080. X        DCE_report_iv_set(0);
  2081. X        erc = eCONINT;
  2082. X    }
  2083. X    else
  2084. X    {
  2085. XCANNOT_TALK_TO_MODEM: ;
  2086. X        setcolor(colors_error);
  2087. X        pprintf("Cannot talk to modem\n");
  2088. X        result = "!Modem Error";
  2089. X        iv[0] = 3;
  2090. X        DCE_report_iv_set(0);
  2091. X        erc = eConnectFailed;
  2092. X    }
  2093. X
  2094. XSTART_RCVR_PROCESS:    ;
  2095. X    setcolor(colors_at_entry);
  2096. X    strcpy(sv[0]->pb,result);
  2097. X    sv[0]->cb = strlen(result);
  2098. X    strcpy(last_dial_result,result);
  2099. X    /*
  2100. X     * do the _connect.ep or _connfail.ep execution
  2101. X     */
  2102. X    if(!iv[0])
  2103. X    {
  2104. X        if(find_procedure("_connect"))
  2105. X        {
  2106. X        int erc2;
  2107. X            _doproc_args[0] = "_connect";    /* _connect.ep */
  2108. X            _doproc_args[1] = result;        /* "CONNECT XXXX" */
  2109. X            if(erc2 = do_proc(2,_doproc_args))
  2110. X            {
  2111. X                DCE_hangup();
  2112. X                if(erc2 < 256)
  2113. X                {
  2114. X                    sprintf(s64,"!CONNECT PROCEDURE RETURNED %d",erc2);
  2115. X                    result = s64;
  2116. X                }
  2117. X                else
  2118. X                    result = "!CONNECT PROCEDURE ABNORMAL TERMINATION";
  2119. X                strcpy(sv[0]->pb,result);
  2120. X                sv[0]->cb = strlen(result);
  2121. X                setcolor(colors_error);
  2122. X                pprintf("%s\n",result);
  2123. X                iv[0] = 1;
  2124. X                DCE_report_iv_set(0);
  2125. X                erc = eConnectFailed;
  2126. X            }
  2127. X        }
  2128. X    }
  2129. X    else if(find_procedure("_connfail"))
  2130. X    {
  2131. X        _doproc_args[0] = "_connfail";    /* _connfail.ep */
  2132. X        _doproc_args[1] = shm->Llogical;
  2133. X        _doproc_args[2] = result;
  2134. X        (void)do_proc(3,_doproc_args);
  2135. X    }
  2136. X    if(restart_rcvr)
  2137. X        start_rcvr_process(1);
  2138. X    return(erc);
  2139. X}    /* end of DCE_dial */
  2140. X
  2141. X/*+-------------------------------------------------------------------------
  2142. X    DCE_redial(arg,argc)
  2143. X--------------------------------------------------------------------------*/
  2144. XDCE_redial(arg,argc)
  2145. Xchar **arg;
  2146. Xint argc;
  2147. X{
  2148. X    int erc = 0;
  2149. X    int delay = 60;
  2150. X    int retries = 10;
  2151. X    long nap_msec;
  2152. X    int ans;
  2153. X
  2154. X    if(shm->Ltelno[0] == 0)
  2155. X    {
  2156. X        pprintf("   no previous number\n");
  2157. X        return(-1);
  2158. X    }
  2159. X
  2160. X    if((argc > 1) && ((retries = atoi(arg[1])) == 0))
  2161. X    {
  2162. X        pprintf("  invalid retry count\n");
  2163. X        return(-1);
  2164. X    }
  2165. X
  2166. X    if((argc > 2) && ((delay = atoi(arg[2])) == 0))
  2167. X    {
  2168. X        pprintf("  invalid delay\n");
  2169. X        return(-1);
  2170. X    }
  2171. X
  2172. X    if(delay < 0)        /* try to be nice to telcos */
  2173. X        delay = 0;        /* (they are our friends :-) */
  2174. X
  2175. X    pprintf("  for %d retries, pause between: %d secs\n",
  2176. X                retries,delay);
  2177. X
  2178. X    kill_rcvr_process(SIGUSR1);        /* kill rcvr process */
  2179. X
  2180. X    DCE_hangup();
  2181. X    while(retries--)
  2182. X    {
  2183. X        if(!isdigit(shm->Llogical[0]) && find_procedure(shm->Llogical))
  2184. X        {
  2185. X        char *pargv[2];
  2186. X        ulong colors_at_entry = colors_current;
  2187. X            pargv[0] = shm->Llogical;
  2188. X            pargv[1] = "!REDIAL;";
  2189. X            sigint = 0;
  2190. X            ttymode(2);
  2191. X            erc = do_proc(2,pargv);
  2192. X            proc_file_reset();
  2193. X            ttymode(1);
  2194. X            setcolor(colors_notify);
  2195. X            ff(se,"[procedure finished]");
  2196. X            setcolor(colors_at_entry);
  2197. X            ff(se,"\r\n");
  2198. X            if(!erc)
  2199. X            {
  2200. X                start_rcvr_process(0);
  2201. X                return(0);
  2202. X            }
  2203. X            lflash_dtr();
  2204. X            sigint = 0;
  2205. X        }
  2206. X        else if(!(erc = DCE_dial()))
  2207. X        {
  2208. X            start_rcvr_process(1);
  2209. X            return(0);
  2210. SHAR_EOF
  2211. true || echo 'restore of ecuDCE.c failed'
  2212. fi
  2213. echo 'End of ecu320 part 5'
  2214. echo 'File ecuDCE.c is continued in part 6'
  2215. echo 6 > _shar_seq_.tmp
  2216. exit 0
  2217.  
  2218. exit 0 # Just in case...
  2219.