home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sources / misc / 3932 < prev    next >
Encoding:
Text File  |  1992-09-11  |  57.1 KB  |  2,225 lines

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