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

  1. Newsgroups: comp.sources.misc
  2. Path: sparky!kent
  3. From: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
  4. Subject:  v32i050:  ecu - ECU Asynchronous Communications v3.20, Part15/40
  5. Message-ID: <1992Sep13.153555.5502@sparky.imd.sterling.com>
  6. Followup-To: comp.sources.d
  7. X-Md4-Signature: cde5726cfd9f6ced031f319e8c1353f5
  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: Sun, 13 Sep 1992 15:35:55 GMT
  12. Approved: kent@sparky.imd.sterling.com
  13. Lines: 2326
  14.  
  15. Submitted-by: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
  16. Posting-number: Volume 32, Issue 50
  17. Archive-name: ecu/part15
  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.15 (part 15 of ecu320)
  24. # do not concatenate these parts, unpack them in order with /bin/sh
  25. # file ecuxfer.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" != 15; 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 ecuxfer.c'
  41. else
  42. echo 'x - continuing file ecuxfer.c'
  43. sed 's/^X//' << 'SHAR_EOF' >> 'ecuxfer.c' &&
  44. X        }
  45. X        else if(ustmp < 128)
  46. X        {
  47. X            setcolor(colors_alert);
  48. X            if(ustmp == 127)
  49. X                pputs("[127 or more files skipped]");
  50. X            else
  51. X                pprintf("[%u files rejected]",ustmp);
  52. X            erc = 0;
  53. X        }
  54. X        else
  55. X        {
  56. X            setcolor(colors_alert);
  57. X            pprintf("[transfer aborted by %s]",
  58. X                signal_name_text(ustmp & 0x7F));
  59. X            erc = eProcAttn_Interrupt;
  60. X        }
  61. X    }
  62. X    else
  63. X    {
  64. X        tcap_curbotleft();
  65. X        setcolor(colors_error);
  66. X        pprintf("[transfer killed by %s]",
  67. X            signal_name_text(ustmp & 0x7F));
  68. X        erc = eProcAttn_Interrupt;
  69. X    }
  70. X
  71. X    setcolor(colors_at_entry);
  72. X    pputs("\n");
  73. X    return(erc);
  74. X
  75. X}    /* end of report_send_status */
  76. X
  77. X/*+-----------------------------------------------------------------------
  78. X    send_files_to_remote(argc,argv)
  79. X------------------------------------------------------------------------*/
  80. Xvoid
  81. Xsend_files_to_remote(argc,argv)
  82. Xint argc;
  83. Xchar **argv;
  84. X{
  85. X    register itmp;
  86. X    register input_state = 0;
  87. X    register input_state_mod;
  88. X    long ltmp;
  89. X    int input_done;
  90. X    int used_argv = 0;
  91. X    char *ckufnm;
  92. X    char execcmd[256];
  93. X    char s80[80];
  94. X    char flst[80];
  95. X    uchar delim;    /* important to be unsigned to avoid sign extension */
  96. X    WINDOW *window_create();
  97. X    char bottom_label[64];
  98. X    int old_ttymode = get_ttymode();
  99. X
  100. X    p_binary = 1;        /* assume p_binary xfer */
  101. X    p_sendfull = 0;        /* assume no full pathnames */
  102. X    p_overwrite = 1;    /* assume overwrite */
  103. X    p_xfernew = 0;        /* assume send only newer */
  104. X    p_filelist[0] = 0;    /* no filenames yet */
  105. X#if defined(WHT)
  106. X    zwindw_size = 65536;                    /* my preference */
  107. X#else
  108. X#if defined(DEFAULT_SZ_WINDOW)
  109. X    zwindw_size = DEFAULT_SZ_WINDOW_SIZE;    /* your preference */
  110. X#else
  111. X    zwindw_size = 0;                        /* default to full streaming sz */
  112. X#endif /* DEFAULT_SZ_WINDOW */
  113. X#endif /* WHT */
  114. X
  115. X    switch(to_lower(*(argv[0] + 1)))
  116. X    {
  117. X        case 'x': xfertype = ECUSZ_X; break;
  118. X        case 'y': xfertype = ECUSZ_Y; break;
  119. X        case 'z': xfertype = ECUSZ_Z; break;
  120. X        case 'k': xfertype = CKERMIT; break;
  121. X        case 's': xfertype = ECUSEA; break;
  122. X        default: ff(se,"send command invalid\n");
  123. X            return;
  124. X    }
  125. X
  126. X    kill_rcvr_process(SIGUSR1);    /* SIGUSR1 gives chance to close log file */
  127. X
  128. X/* define and open window */
  129. X    input_state_mod = 0;
  130. X    xfrw_tlx = (COLS - SNDW_COLS) / 2;
  131. X    xfrw_cols = SNDW_COLS;
  132. X    switch(xfertype)
  133. X    {
  134. X        case ECUSEA:
  135. X            input_state_mod = 1;
  136. X            xfrw_lines = 7;
  137. X            break;
  138. X        case ECUSZ_X:
  139. X            input_state_mod = 2;
  140. X            xfrw_lines = 9;
  141. X            break;
  142. X        case ECUSZ_Z:
  143. X            input_state_mod = 7;
  144. X            xfrw_lines = input_state_mod + 7;
  145. X            break;
  146. X        case CKERMIT:
  147. X            input_state_mod = 3;
  148. X            xfrw_lines = input_state_mod + 7;
  149. X            break;
  150. X        case ECUSZ_Y:
  151. X            input_state_mod = 2;
  152. X            xfrw_lines = input_state_mod + 7;
  153. X            break;
  154. X        default:
  155. X            termecu(9999);
  156. X    }
  157. X
  158. X    windows_start();
  159. X    sprintf(execcmd,"Send %s",xfer_title_fragment());
  160. X    xfrw = window_create(execcmd,-3,SNDW_TLY,(int)xfrw_tlx,
  161. X            (int)xfrw_lines,(int)xfrw_cols);
  162. X    xfrw_display_cmd_line();
  163. X    xfrws_display_literals();
  164. X    xfrws_display_allvars();
  165. X    wmove(xfrw,0,27);
  166. X    waddstr(xfrw," dir: ");
  167. X    if(strlen(curr_dir) > (unsigned)(xfrw_cols - 32))
  168. X    {
  169. X        strncpy(s80,curr_dir,xfrw_cols - 32);
  170. X        s80[xfrw_cols - 32] = 0;
  171. X        waddstr(xfrw,s80);
  172. X    }
  173. X    else
  174. X        waddstr(xfrw,curr_dir);
  175. X    waddch(xfrw,' ');
  176. X    flst[0] = 0;
  177. X
  178. XREENTER_INPUT_LOOP:
  179. X    input_done = 0;
  180. X    while(!input_done)
  181. X    {
  182. X        switch(input_state)
  183. X        {
  184. X            case 0:        /* filename(s) */
  185. X                xfrw_bot_msg("enter file(s) to send");
  186. XCASE_0_AGAIN:
  187. X                if(used_argv || (argc == 1))
  188. X                {
  189. X                    itmp = wingets(xfrw,SNDW_FILE_Y,SNDW_FILE_X,flst,
  190. X                        SNDW_FILE_LEN + 1,&delim,
  191. X                        (p_filelist[0] != 0),(int *)0);
  192. X                }
  193. X                else
  194. X                {
  195. X                    used_argv = 1;
  196. X                    flst[0] = 0;
  197. X                    for(itmp = 1; itmp < argc; itmp++)
  198. X                    {
  199. X                        if((strlen(flst) + strlen(argv[itmp]) + 1) >
  200. X                            sizeof(flst))
  201. X                        {
  202. X                            xfrw_bot_msg("arguments too long ... reenter list");
  203. X                            ring_bell();
  204. X                            goto CASE_0_AGAIN;
  205. X                        }
  206. X                        strcat(flst,argv[itmp]);
  207. X                        if(itmp != (argc - 1))
  208. X                            strcat(flst," ");
  209. X                    }
  210. X                    delim = NL;
  211. X                }
  212. X                if(delim == ESC)
  213. X                    break;
  214. X                if(strlen(flst))
  215. X                {
  216. X                    strcpy(p_filelist,flst);
  217. X                    xfrws_display_name();
  218. X                    if(find_shell_chars(p_filelist))
  219. X                    {
  220. X                    char *expcmd;
  221. X
  222. X                        if(expand_wildcard_list(p_filelist,&expcmd))
  223. X                        {
  224. X                            xfrw_bot_msg(expcmd);
  225. X                            ring_bell();
  226. X                            goto CASE_0_AGAIN;
  227. X                        }
  228. X                        expcmd[SNDW_FILE_LEN - 1] = 0;
  229. X                        clear_area(xfrw,SNDW_FILE_Y,SNDW_FILE_X,SNDW_FILE_LEN);
  230. X                        waddstr(xfrw,expcmd);
  231. X                        free(expcmd);
  232. X                    }
  233. X                }
  234. X                break;
  235. X
  236. X            case 1:        /* binary */
  237. X                xfrw_bot_msg("Y: no conversion, N: NLs converted to CR/LF");
  238. X                wmove(xfrw,SNDW_BIN_Y,SNDW_BIN_X);
  239. X                wrefresh(xfrw);
  240. X                delim = NL;
  241. X                switch(itmp = xfrw_get_single("ny"))
  242. X                {
  243. X                    case 0:
  244. X                    case 1:
  245. X                        p_binary = itmp;
  246. X                        xfrws_display_binary();
  247. X                        break;
  248. X                    default:
  249. X                        delim = itmp & 0xFF;
  250. X                        break;
  251. X                }
  252. X                break;
  253. X
  254. X            case 2:        /* overwrite */
  255. X                xfrw_bot_msg("Y: overwrite, N: protect destination files");
  256. X                wmove(xfrw,SNDW_OVERW_Y,SNDW_OVERW_X);
  257. X                wrefresh(xfrw);
  258. X                delim = NL;
  259. X                switch(itmp = xfrw_get_single("ny"))
  260. X                {
  261. X                    case 0:
  262. X                    case 1:
  263. X                        p_overwrite = itmp;
  264. X                        break;
  265. X                    default:
  266. X                        delim = itmp & 0xFF;
  267. X                        break;
  268. X                }
  269. X                break;
  270. X
  271. X            case 3:        /* send full pathnames */
  272. X                xfrw_bot_msg(
  273. X                    "Y: full pathnames, N: strip directory portion from names");
  274. X                wmove(xfrw,SNDW_SENDFULL_Y,SNDW_SENDFULL_X);
  275. X                wrefresh(xfrw);
  276. X                delim = NL;
  277. X                switch(itmp = xfrw_get_single("ny"))
  278. X                {
  279. X                    case 0:
  280. X                    case 1:
  281. X                        p_sendfull = itmp;
  282. X                        break;
  283. X                    default:
  284. X                        delim = itmp & 0xFF;
  285. X                        break;
  286. X                }
  287. X                break;
  288. X
  289. X            case 4:        /* src newer than dest */
  290. X
  291. X                xfrw_bot_msg(
  292. X                "Y: send only if source newer than destination, N send all");
  293. X                wmove(xfrw,SNDW_XFERNEW_Y,SNDW_XFERNEW_X);
  294. X                wrefresh(xfrw);
  295. X                delim = NL;
  296. X                switch(itmp = xfrw_get_single("ny"))
  297. X                {
  298. X                    case 0:
  299. X                    case 1:
  300. X                        p_xfernew = itmp;
  301. X                        xfrws_display_xfernew();
  302. X                        break;
  303. X                    default:
  304. X                        delim = itmp & 0xFF;
  305. X                        break;
  306. X                }
  307. X                break;
  308. X
  309. X            case 5:        /* resume interrupted transfer */
  310. X
  311. X                xfrw_bot_msg(
  312. X                "Y: resume transfer at remote file EOF, N send all");
  313. X                wmove(xfrw,SNDW_RESUME_Y,SNDW_RESUME_X);
  314. X                wrefresh(xfrw);
  315. X                delim = NL;
  316. X                switch(itmp = xfrw_get_single("ny"))
  317. X                {
  318. X                    case 0:
  319. X                    case 1:
  320. X                        p_resume = itmp;
  321. X                        xfrws_display_resume();
  322. X                        break;
  323. X                    default:
  324. X                        delim = itmp & 0xFF;
  325. X                        break;
  326. X                }
  327. X                break;
  328. X
  329. X            case 6:        /* window size */
  330. X
  331. X                xfrw_bot_msg(
  332. X                "window size (max bytes sent before ACK required) 0 = stream");
  333. XCASE_5_AGAIN:
  334. X                sprintf(s80,"%u",zwindw_size);
  335. X                clear_area(xfrw,SNDW_ZWINDW_Y,SNDW_ZWINDW_X,
  336. X                    SNDW_ZWINDW_LEN + 10);
  337. X                itmp = wingets(xfrw,SNDW_ZWINDW_Y,SNDW_ZWINDW_X,s80,
  338. X                    SNDW_ZWINDW_LEN + 1,&delim,1,(int *)0);
  339. X                if((delim == ESC))
  340. X                    break;
  341. X                if( ((ltmp = atol(s80)) != 0) &&
  342. X                    ((ltmp < 256) || (ltmp > ZWINDW_LIMIT)))
  343. X                {
  344. X                char xbmsg[80];
  345. X                    ring_bell();
  346. X                    sprintf(xbmsg,"window size must be 0 or 256 <= w <= %u",
  347. X                        ZWINDW_LIMIT);
  348. X                    xfrw_bot_msg(xbmsg);
  349. X                    goto CASE_5_AGAIN;
  350. X                }
  351. X                zwindw_size = (uint)(ltmp / 64L) * 64L;
  352. X                sprintf(s80,"%u%s",zwindw_size,
  353. X                    (zwindw_size != (uint)ltmp) ? " adjusted" : "" );
  354. X                clear_area(xfrw,SNDW_ZWINDW_Y,SNDW_ZWINDW_X,
  355. X                    SNDW_ZWINDW_LEN + 10);
  356. X                waddstr(xfrw,s80);
  357. X                break;
  358. X        }
  359. X
  360. X        switch(delim)
  361. X        {
  362. X            case XFcurup:
  363. X            case CTL_B:
  364. X                input_state = (input_state) ? input_state - 1 
  365. X                                            : input_state_mod - 1;
  366. X                break;
  367. X
  368. X            case XFcurdn:
  369. X            case TAB:
  370. X            case NL:
  371. X                input_state++;
  372. X                input_state %= input_state_mod;
  373. X                break;
  374. X
  375. X            case CTL_L:
  376. X            case CTL_R:
  377. X                tcap_clear_screen();
  378. X                touchwin(stdscr);
  379. X                wrefresh(stdscr);
  380. X                touchwin(xfrw);
  381. X                wrefresh(xfrw);
  382. X                break;
  383. X
  384. X            case ESC:
  385. X                xfrw_bot_msg("transfer abandoned");
  386. X                input_done = 1;
  387. X                break;
  388. X
  389. X            case XFend:
  390. X                input_done = 1;
  391. X                break;
  392. X        }
  393. X    }
  394. X
  395. X    if(delim == XFend)
  396. X    {
  397. X        if(!p_filelist[0])
  398. X        {
  399. X            ring_bell();
  400. X            xfrw_bot_msg("No filenames entered!  Press <ENTER>");
  401. X            (void)ttygetc(1);
  402. X            input_state = 0;
  403. X            goto REENTER_INPUT_LOOP;
  404. X        }
  405. X        xfrw_bot_msg("starting file transfer");
  406. X    }
  407. X
  408. X    wrefresh(xfrw);
  409. X    delwin(xfrw);
  410. X    windows_end(0);
  411. X    tcap_cursor(SNDW_TLY + xfrw_lines + 1,0);
  412. X
  413. X    if(delim == ESC)
  414. X    {
  415. X        start_rcvr_process(1);
  416. X        return;
  417. X    }
  418. X
  419. X    bottom_label[0] = 0;
  420. X    if(shm->Llogical[0])
  421. X        sprintf(bottom_label,"-C \"'Connected to %s'\" ",shm->Llogical);
  422. X
  423. X/* we are going to do a transfer! */
  424. X    switch(xfertype)
  425. X    {
  426. X        case ECUSZ_X:
  427. X            sprintf(execcmd,"%s/ecusz -X -. %d ",eculibdir,shm->Liofd);
  428. X            strcat(execcmd,bottom_label);
  429. X            if(protocol_log_packets)
  430. X                strcat(execcmd,"-, ");
  431. X            if(p_binary)
  432. X                strcat(execcmd,"-b ");
  433. X            else
  434. X                strcat(execcmd,"-a ");
  435. X            strcat(execcmd,p_filelist);
  436. X            break;
  437. X        case ECUSZ_Y:
  438. X            sprintf(execcmd,"%s/ecusz -Y -. %d -k ",eculibdir,shm->Liofd);
  439. X            strcat(execcmd,bottom_label);
  440. X            if(protocol_log_packets)
  441. X                strcat(execcmd,"-, ");
  442. X            if(p_binary)
  443. X                strcat(execcmd,"-b ");
  444. X            else
  445. X                strcat(execcmd,"-a ");
  446. X            strcat(execcmd,p_filelist);
  447. X            break;
  448. X
  449. X        case ECUSZ_Z:
  450. X            sprintf(execcmd,"%s/ecusz -Z -. %d ",eculibdir,shm->Liofd);
  451. X            strcat(execcmd,bottom_label);
  452. X            if(zwindw_size)
  453. X                sprintf(&execcmd[strlen(execcmd)]," -w %u ",zwindw_size);
  454. X            if(protocol_log_packets)
  455. X                strcat(execcmd,"-, ");
  456. X            if(p_overwrite)
  457. X                strcat(execcmd,"-y ");
  458. X            else
  459. X                strcat(execcmd,"-p ");
  460. X            if(p_binary)
  461. X                strcat(execcmd,"-b ");
  462. X            else
  463. X                strcat(execcmd,"-a ");
  464. X            if(p_xfernew)
  465. X                strcat(execcmd,"-n ");    /* overrides -y/-p choice earlier */
  466. X            if(p_resume)
  467. X                strcat(execcmd,"-r ");
  468. X            if(p_sendfull)
  469. X                strcat(execcmd,"-f ");
  470. X            strcat(execcmd,p_filelist);
  471. X            break;
  472. X
  473. X        case ECUSEA:
  474. X            sprintf(execcmd,"%s/ecusea -. %d -/ %s -s ",
  475. X                eculibdir,shm->Liofd,curr_dir);
  476. X            if(protocol_log_packets)
  477. X                strcat(execcmd,"-, ");
  478. X            strcat(execcmd,p_filelist);
  479. X            break;
  480. X
  481. X        case CKERMIT:    /* flexible kermit filename */
  482. X#ifdef WHT
  483. X        if(ckufnm = find_executable("ck5a")) /* private alpha version */
  484. X            ;
  485. X#else
  486. X        if(ckufnm = (char *)0)
  487. X            ;
  488. X#endif
  489. X        else if(ckufnm = find_executable("kermit"))
  490. X            ;
  491. X        else if(ckufnm = find_executable("ckermit"))
  492. X            ; /* our old 286 4E hack (and alternate name used by many) */
  493. X        else
  494. X        {
  495. X            ff(se,"Cannot find C-Kermit ('kermit' or 'ckermit')\r\n");
  496. X            last_child_wait_status = -1;
  497. X            goto EXIT;
  498. X        }
  499. X
  500. X        sprintf(execcmd,"%s -l %d -b %u -p %c%s%s -s %s",
  501. X                ckufnm,    /* kermit flexible name */
  502. X                shm->Liofd,
  503. X                shm->Lbaud,
  504. X                (shm->Lparity) ? shm->Lparity : 'n',
  505. X                (p_binary) ? " -i" : "",
  506. X                (p_overwrite) ? "" : " -w",
  507. X                p_filelist);
  508. X        break;
  509. X
  510. X    default:
  511. X        pprintf("logic error in send_files_to_remote xfertype=%d\n",
  512. X            xfertype);
  513. X        termecu(TERMECU_LOGIC_ERROR);
  514. X        /*NOTREACHED*/
  515. X}
  516. X
  517. Xfile_xfer_start();
  518. X
  519. Xif(!find_shell_chars(execcmd))
  520. X    exec_cmd(execcmd);
  521. Xelse
  522. X{
  523. Xchar *expcmd;
  524. X
  525. X    if(expand_wildcard_list(execcmd,&expcmd))
  526. X    {
  527. X        ff(se,"No files match\r\n");
  528. X        return;
  529. X    }
  530. X    exec_cmd(expcmd);
  531. X    free(expcmd);
  532. X}
  533. X
  534. XEXIT:
  535. Xlreset_ksr();                /* ensure line termio back to our config */
  536. Xttymode(old_ttymode);        /* xfer prog may screw up tty too */
  537. X
  538. Xswitch(xfertype)
  539. X{
  540. X    case ECUSEA:
  541. X    case ECUSZ_X:
  542. X    case ECUSZ_Y:
  543. X    case ECUSZ_Z:
  544. X        xfertype = 1;        /* was ecusz */
  545. X        break;
  546. X    default:
  547. X        xfertype = 0;
  548. X        break;
  549. X}
  550. X
  551. Xif(xfertype)    /* ecu knowledgable */
  552. X    report_send_status();
  553. Xelse
  554. X{
  555. X    tcap_stand_out();
  556. X    ff(se," transfer status %04x ",last_child_wait_status);
  557. X    tcap_stand_end();
  558. X    ff(se,"\r\n");
  559. X}
  560. X
  561. Xff(se,"\r\n");
  562. X
  563. Xfile_xfer_done_bell();
  564. Xstart_rcvr_process(1);
  565. X}    /* end of send_files_to_remote */
  566. X
  567. X/*+-------------------------------------------------------------------------
  568. Xreceive_files_from_remote(argc,argv)
  569. X
  570. Xalso used by "automatic rz"
  571. X
  572. Xarg[0] = "rk", "rs", "rx", "ry", or "rz"
  573. X--------------------------------------------------------------------------*/
  574. Xvoid
  575. Xreceive_files_from_remote(argc,argv)
  576. Xint argc;
  577. Xchar **argv;
  578. X{
  579. X    register itmp;
  580. X    uchar delim;
  581. X    char execcmd[256];
  582. X    char bottom_label[64];
  583. X    char *ckufnm;
  584. X    int old_ttymode = get_ttymode();
  585. X    int restart_rcvr = need_rcvr_restart();
  586. X
  587. X    if(!argc)    /* this should never happen, but ... */
  588. X        return;
  589. X
  590. X    sprintf(bottom_label,"-C 'Connected to %s' ",
  591. X        (shm->Llogical[0]) ? shm->Llogical : "?");
  592. X
  593. X    switch(to_lower(*(argv[0] + 1)))
  594. X    {
  595. X        case 'k': xfertype = CKERMIT; break;
  596. X        case 's': xfertype = ECUSEA; break;
  597. X        case 'x': xfertype = ECURZ_X; break;
  598. X        case 'y': xfertype = ECURZ_Y; break;
  599. X        case 'z': xfertype = ECURZ_Z; break;
  600. X        default: 
  601. X            ff(se,"receive command invalid\n");
  602. X            return;
  603. X    }
  604. X
  605. X
  606. X    if(xfertype == ECURZ_X)
  607. X    {
  608. X        char xfilenam[128];
  609. X        if(restart_rcvr)
  610. X            kill_rcvr_process(SIGUSR1);
  611. X        sprintf(execcmd,"%s/ecurz -X -. %d -c ",eculibdir,shm->Liofd);
  612. X        strcat(execcmd,bottom_label);
  613. X        if(protocol_log_packets)
  614. X            strcat(execcmd,"-, ");
  615. X
  616. X        if(argc > 1)
  617. X        {
  618. X            strncpy(xfilenam,argv[1],sizeof(xfilenam) - 1);
  619. X            xfilenam[sizeof(xfilenam) - 1] = 0;
  620. X        }
  621. X        else
  622. X        {
  623. X            ff(se,"    File name to receive via XMODEM/CRC:  ");
  624. X            ttygets(xfilenam,sizeof(xfilenam),TG_CRLF,&delim,(int *)0);
  625. X            if(!xfilenam[0] || (delim == ESC))
  626. X            {
  627. X                ff(se,"transfer abandoned\r\n");
  628. X                if(restart_rcvr)
  629. X                    start_rcvr_process(1);
  630. X                return;
  631. X            }
  632. X        }
  633. X        /* get xmodem ascii or binary */
  634. X        ff(se,"Translate CR/LF to NL (y,n)? ");
  635. X        switch(itmp = to_lower(ttygetc(0)))
  636. X        {
  637. X        case 'y': 
  638. X            strcat(execcmd,"-a "); 
  639. X            break;
  640. X        case 'n': 
  641. X            strcat(execcmd,"-b "); 
  642. X            break;
  643. X        default:
  644. X            ff(se,"transfer abandoned\r\n");
  645. X            if(restart_rcvr)
  646. X                start_rcvr_process(1);
  647. X            return;
  648. X        }
  649. X        ff(se,"%s\r\n",(itmp == 'y') ? "yes" : "no");
  650. X        strcat(execcmd,xfilenam);
  651. X        file_xfer_start();
  652. X        exec_cmd(execcmd);
  653. X    }
  654. X    else if(xfertype == ECURZ_Y)
  655. X    {
  656. X        ff(se,"\r\n");
  657. X        if(restart_rcvr)
  658. X            kill_rcvr_process(SIGUSR1);
  659. X        sprintf(execcmd,"%s/ecurz -Y -. %d -y ",eculibdir,shm->Liofd);
  660. X        strcat(execcmd,bottom_label);
  661. X        if(protocol_log_packets)
  662. X            strcat(execcmd,"-, ");
  663. X        file_xfer_start();
  664. X        exec_cmd(execcmd);
  665. X    }
  666. X    else if(xfertype == ECURZ_Z)
  667. X    {
  668. X        ff(se,"\r\n");
  669. X        if(restart_rcvr)
  670. X            kill_rcvr_process(SIGUSR1);
  671. X        sprintf(execcmd,"%s/ecurz -Z -. %d ",eculibdir,shm->Liofd);
  672. X        if(protocol_log_packets)
  673. X            strcat(execcmd,"-, ");
  674. X        strcat(execcmd,bottom_label);
  675. X        file_xfer_start();
  676. X        exec_cmd(execcmd);
  677. X    }
  678. X    else if(xfertype == CKERMIT)
  679. X    {
  680. X        ckufnm = 0;
  681. X#ifdef WHT
  682. X        if(ckufnm = find_executable("ck5a")) /* private alpha version */
  683. X            ;
  684. X#endif /* WHT */
  685. X
  686. X        if(!ckufnm && (ckufnm = find_executable("kermit")))
  687. X            ;
  688. X        else if(ckufnm = find_executable("ckermit"))
  689. X            ; /* our old 286 4E hack (and alternate name used by many) */
  690. X        else
  691. X        {
  692. X            ff(se,"Cannot find C-Kermit ('kermit' or 'ckermit')\r\n");
  693. X            last_child_wait_status = 255 << 8;
  694. X            return;    /* <<=================================== */
  695. X        }
  696. X        if(restart_rcvr)
  697. X            kill_rcvr_process(SIGUSR1);
  698. X        sprintf(execcmd,"%s -r -e 512 -l %d -b %d -p %c",
  699. X            ckufnm,
  700. X            shm->Liofd,shm->Lbaud,(shm->Lparity) ? shm->Lparity : 'n');
  701. X        ff(se,"    Translate CR/LF to NL (y,n)? ");
  702. X        switch(itmp = to_lower(ttygetc(0)))
  703. X        {
  704. X            case 'y': 
  705. X                strcat(execcmd," -i"); 
  706. X                break;
  707. X            case 'n': 
  708. X                break;
  709. X            default:
  710. X                ff(se,"transfer abandoned\r\n");
  711. X                if(restart_rcvr)
  712. X                    start_rcvr_process(1);
  713. X                return;
  714. X        }
  715. X        ff(se,"%s\r\n",(itmp == 'a') ? "yes" : "no");
  716. X        file_xfer_start();
  717. X        exec_cmd(execcmd);
  718. X    }
  719. X    else if(xfertype == ECUSEA)
  720. X    {
  721. X        if(restart_rcvr)
  722. X            kill_rcvr_process(SIGUSR1);
  723. X        sprintf(execcmd,"%s/ecusea -r -. %d -/ %s",
  724. X            eculibdir,shm->Liofd,curr_dir);
  725. X        if(protocol_log_packets)
  726. X            strcat(execcmd," -,");
  727. X        file_xfer_start();
  728. X        exec_cmd(execcmd);
  729. X    }
  730. X    lreset_ksr();                /* ensure line termio back to our config */
  731. X    ttymode(old_ttymode);        /* xfer prog may screw up tty too */
  732. X    file_xfer_done_bell();
  733. X    Nap(20L);
  734. X    if(restart_rcvr)
  735. X        start_rcvr_process(1);
  736. X
  737. X}    /* end of receive_files_from_remote */
  738. X
  739. X/* end of ecuxfer.c */
  740. X/* vi: set tabstop=4 shiftwidth=4: */
  741. SHAR_EOF
  742. echo 'File ecuxfer.c is complete' &&
  743. chmod 0644 ecuxfer.c ||
  744. echo 'restore of ecuxfer.c failed'
  745. Wc_c="`wc -c < 'ecuxfer.c'`"
  746. test 28250 -eq "$Wc_c" ||
  747.     echo 'ecuxfer.c: original size 28250, current size' "$Wc_c"
  748. rm -f _shar_wnt_.tmp
  749. fi
  750. # ============= ecuxkey.h ==============
  751. if test -f 'ecuxkey.h' -a X"$1" != X"-c"; then
  752.     echo 'x - skipping ecuxkey.h (File already exists)'
  753.     rm -f _shar_wnt_.tmp
  754. else
  755. > _shar_wnt_.tmp
  756. echo 'x - extracting ecuxkey.h (Text)'
  757. sed 's/^X//' << 'SHAR_EOF' > 'ecuxkey.h' &&
  758. X/*+-------------------------------------------------------------------------
  759. X    ecuxkey.h -- function key single char value mapping
  760. X    wht@n4hgf.Mt-Park.GA.US
  761. X
  762. XNOTE: all of these codes must be in the range 0x80 <= c <= 0xFD
  763. XInternational considerations make changing the ALT+[a-z] codes
  764. Xunadvisable.
  765. X--------------------------------------------------------------------------*/
  766. X/*+:EDITS:*/
  767. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  768. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  769. X/*:03-27-1992-16:21-wht@n4hgf-re-include protection for all .h files */
  770. X/*:09-03-1991-23:16-wht@n4hgf2-alt-[a-z] starts w/0xE1: crisp compatibility */
  771. X/*:08-28-1991-14:07-wht@n4hgf2-SVR4 cleanup by aega84!lh */
  772. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  773. X/*:05-02-1991-01:57-r@n4hgf-alt-[a-z] range moved from 0x80-0x99 to 0xE0-0xF9 */
  774. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  775. X
  776. X#ifndef _ecuxkey_h
  777. X#define _ecuxkey_h
  778. X
  779. X/*
  780. X * these are not changeable: they map to the last character in
  781. X * an AT/"ANSI" function key sequence
  782. X */
  783. X
  784. X#define XFcurup        (0x80 | 'A')    /* 0xC1 */
  785. X#define XFcurdn        (0x80 | 'B')    /* 0xC2 */
  786. X#define XFcurrt        (0x80 | 'C')    /* 0xC3 */
  787. X#define XFcurlf        (0x80 | 'D')    /* 0xC4 */
  788. X#define XFcur5        (0x80 | 'E')    /* 0xC5 */
  789. X#define XFend        (0x80 | 'F')    /* 0xC6 */
  790. X#define XFpgdn        (0x80 | 'G')    /* 0xC7 */
  791. X#define XFhome        (0x80 | 'H')    /* 0xC8 */
  792. X#define XFpgup        (0x80 | 'I')    /* 0xC9 */
  793. X#define XFins        (0x80 | 'L')    /* 0xCA */
  794. X#define XF1            (0x80 | 'M')    /* 0xCB */
  795. X#define XF2            (0x80 | 'N')    /* 0xCC */
  796. X#define XF3            (0x80 | 'O')    /* 0xCD */
  797. X#define XF4            (0x80 | 'P')    /* 0xCE */
  798. X#define XF5            (0x80 | 'Q')    /* 0xCF */
  799. X#define XF6            (0x80 | 'R')    /* 0xD0 */
  800. X#define XF7            (0x80 | 'S')    /* 0xD1 */
  801. X#define XF8            (0x80 | 'T')    /* 0xD2 */
  802. X#define XF9            (0x80 | 'U')    /* 0xD3 */
  803. X#define XF10        (0x80 | 'V')    /* 0xD4 */
  804. X#define XF11        (0x80 | 'W')    /* 0xD5 */
  805. X#define XF12        (0x80 | 'X')    /* 0xD6 */
  806. X#define XFbktab        (0x80 | 'Z')    /* 0xD7 */
  807. X
  808. X/*
  809. X * special codes for non-ANSI keyboard support
  810. X * These are really cleverly disguised magic numbers:
  811. X * they HAVE to have the values used below.
  812. X */
  813. X#define XF_no_way    0xFE
  814. X#define XF_not_yet    0xFF
  815. X
  816. X/*
  817. X * extended ALT+[a-z] codes
  818. X */
  819. X#define XF_ALTA    0xE1            /* depends on /usr/lib/keyboard keys ... */
  820. X#define XF_ALTZ    ((unsigned)(0xE0+'z'-'a'))    /* ... mapping ALT-a to 0xE0, etc */
  821. X
  822. X#endif /* _ecuxkey_h */
  823. X
  824. X/* vi: set tabstop=4 shiftwidth=4: */
  825. X/* end of ecuxkey.h */
  826. SHAR_EOF
  827. chmod 0644 ecuxkey.h ||
  828. echo 'restore of ecuxkey.h failed'
  829. Wc_c="`wc -c < 'ecuxkey.h'`"
  830. test 2415 -eq "$Wc_c" ||
  831.     echo 'ecuxkey.h: original size 2415, current size' "$Wc_c"
  832. rm -f _shar_wnt_.tmp
  833. fi
  834. # ============= esd.h ==============
  835. if test -f 'esd.h' -a X"$1" != X"-c"; then
  836.     echo 'x - skipping esd.h (File already exists)'
  837.     rm -f _shar_wnt_.tmp
  838. else
  839. > _shar_wnt_.tmp
  840. echo 'x - extracting esd.h (Text)'
  841. sed 's/^X//' << 'SHAR_EOF' > 'esd.h' &&
  842. X/*+-----------------------------------------------------------------------
  843. X    esd.h -- support header for users of esdutil.c
  844. X    wht@n4hgf.Mt-Park.GA.US
  845. X------------------------------------------------------------------------*/
  846. X/*+:EDITS:*/
  847. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  848. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  849. X/*:03-27-1992-16:21-wht@n4hgf-re-include protection for all .h files */
  850. X/*:03-20-1992-06:28-wht@n4hgf-max size of esd now 16384 */
  851. X/*:08-29-1991-02:02-wht@n4hgf2-larger max string size for sun and SVR4 */
  852. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  853. X/*:04-24-1991-18:49-wht@n4hgf-add ESD_MAXSIZE */
  854. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  855. X
  856. X#ifndef _esd_h
  857. X#define _esd_h
  858. X
  859. X#define ESD_MAXSIZE 16384
  860. X
  861. Xtypedef struct esd
  862. X{
  863. X    char *pb;            /* pointer to string buffer */
  864. X    short cb;            /* count of bytes */
  865. X    short maxcb;        /* maximum bytes allowed */
  866. X    short index;        /* next character of significance */
  867. X    short old_index;    /* last token (backup or error reporting) */
  868. X}    ESD;
  869. X
  870. Xtypedef struct keyword_table_type /* table terminated with null key_word */
  871. X{
  872. X    char *key_word;        /* 12 char max key word */
  873. X    int key_token;        /* token returned on match */
  874. X} KEYTAB;
  875. X
  876. XESD *esdalloc();
  877. X
  878. X#endif /* _esd_h */
  879. X
  880. X/* vi: set tabstop=4 shiftwidth=4: */
  881. X/* end of esd.h */
  882. SHAR_EOF
  883. chmod 0644 esd.h ||
  884. echo 'restore of esd.h failed'
  885. Wc_c="`wc -c < 'esd.h'`"
  886. test 1310 -eq "$Wc_c" ||
  887.     echo 'esd.h: original size 1310, current size' "$Wc_c"
  888. rm -f _shar_wnt_.tmp
  889. fi
  890. # ============= esdutil.c ==============
  891. if test -f 'esdutil.c' -a X"$1" != X"-c"; then
  892.     echo 'x - skipping esdutil.c (File already exists)'
  893.     rm -f _shar_wnt_.tmp
  894. else
  895. > _shar_wnt_.tmp
  896. echo 'x - extracting esdutil.c (Text)'
  897. sed 's/^X//' << 'SHAR_EOF' > 'esdutil.c' &&
  898. X/*+----------------------------------------------------------------
  899. X    esdutil.c - ecu extended string descriptor manipulation
  900. X    wht@n4hgf.Mt-Park.GA.US
  901. X
  902. X  Defined functions:
  903. X    end_of_cmd(tesd)
  904. X    esd_null_terminate(tesd)
  905. X    esd_strip_trail_break(ztext)
  906. X    esdalloc(maxcb)
  907. X    esdcat(dest,suffix,realloc_ok)
  908. X    esdfgets(tesd,fileptr)
  909. X    esdfputs(tesd,fileptr,index_flag,nl_flag)
  910. X    esdfree(tesd)
  911. X    esdinit(tesd,cptr,maxcb)
  912. X    esdrealloc(tesd,maxcb)
  913. X    esdshow(tesd,title)
  914. X    esdstrcat(tesd,zstr)
  915. X    esdstrindex(esd1,esd2,index1_flag,index2_flag)
  916. X    esdzero(tesd)
  917. X    get_alpha_zstr(tesd,strbuf,strbuf_maxcb)
  918. X    get_alphanum_zstr(tesd,strbuf,strbuf_maxcb)
  919. X    get_cmd_char(tesd,pchar)
  920. X    get_numeric_value(tesd,value)
  921. X    get_numeric_zstr(tesd,strbuf,strbuf_maxcb)
  922. X    get_switches(tesd,switches,switches_max)
  923. X    get_word_zstr(tesd,strbuf,strbuf_maxcb)
  924. X    keyword_lookup(ktable,tesd)
  925. X    skip_cmd_break(tesd)
  926. X    skip_cmd_char(tesd,skipchar)
  927. X    skip_colon(tesd)
  928. X    skip_comma(tesd)
  929. X    skip_paren(tesd,fLeft)
  930. X    strindex(str1,str2)
  931. X
  932. XThis is old code; give me a break
  933. X-----------------------------------------------------------------*/
  934. X/*+:EDITS:*/
  935. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  936. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  937. X/*:03-20-1992-06:26-wht@n4hgf-esdstrcat will grow an esd */
  938. X/*:08-25-1991-23:20-root@n4hgf2-get_switches could overflow result string */
  939. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  940. X/*:05-02-1991-04:12-wht@n4hgf-how did esdrealloc ever work? */
  941. X/*:04-23-1991-04:33-wht@n4hgf-function name reorganization */
  942. X/*:04-23-1991-04:33-wht@n4hgf-add esdcat */
  943. X/*:01-31-1991-14:49-wht@n4hgf-rework esdrealloc for speed */
  944. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  945. X
  946. X#include "ecu.h"
  947. X#include "ecuerror.h"
  948. X#include "esd.h"
  949. X
  950. Xextern int errno;
  951. X
  952. X/*+-------------------------------------------------------------------------
  953. X    esd_null_terminate(&esd)
  954. X    puts null at 'cb' position of string (standard esd always
  955. X    has one more byte in buffer than maxcb says)
  956. X--------------------------------------------------------------------------*/
  957. Xvoid
  958. Xesd_null_terminate(tesd)
  959. Xregister ESD *tesd;
  960. X{
  961. X    tesd->pb[tesd->cb] = 0;
  962. X}   /* end of esd_null_terminate */
  963. X
  964. X/*+-----------------------------------------------------------------------
  965. X    esdzero(tesd)  zero an esd 
  966. X------------------------------------------------------------------------*/
  967. Xvoid
  968. Xesdzero(tesd)
  969. Xregister ESD *tesd;
  970. X{
  971. X    tesd->cb = 0;                /* current count == 0 */
  972. X    tesd->index = 0;            /* parse index to first position */
  973. X    tesd->old_index = 0;        /* parse index to first position */
  974. X    *tesd->pb = 0;                /* start with null terminated string */
  975. X
  976. X}    /* end of esdzero */
  977. X
  978. X/*+-----------------------------------------------------------------------
  979. X    esdinit(tesd,cptr,maxcb)  init an esd 
  980. X------------------------------------------------------------------------*/
  981. Xvoid
  982. Xesdinit(tesd,cptr,maxcb)
  983. Xregister ESD *tesd;
  984. Xchar *cptr;
  985. Xregister maxcb;
  986. X{
  987. X    tesd->pb = cptr;            /* pointer to string */
  988. X    tesd->maxcb = maxcb;        /* max characters in buffer */
  989. X    esdzero(tesd);
  990. X
  991. X}    /* end of esdinit */
  992. X
  993. X/*+-----------------------------------------------------------------------
  994. X    esdptr = esdalloc(maxcb)    allocate an esd and buffer
  995. X------------------------------------------------------------------------*/
  996. XESD *
  997. Xesdalloc(maxcb)
  998. Xregister maxcb;        /* desired maxcb */
  999. X{
  1000. Xregister ESD *tesd;
  1001. Xregister actual_cb;
  1002. X
  1003. X    /* we get an extra character to ensure room for null past maxcb */
  1004. X    actual_cb = maxcb + 1;
  1005. X    if(actual_cb & 1)        /* even allocation */
  1006. X        ++actual_cb;
  1007. X
  1008. X    if(!(tesd = (ESD *)malloc(sizeof(ESD))))
  1009. X        return((ESD *)0);     /* return NULL if failure */
  1010. X
  1011. X    if(!(tesd->pb = malloc(actual_cb)))
  1012. X    {
  1013. X        free((char *)tesd);
  1014. X        return((ESD *)0);     /* return NULL if failure */
  1015. X    }
  1016. X
  1017. X    esdinit(tesd,tesd->pb,maxcb);
  1018. X    return(tesd);
  1019. X
  1020. X}    /* end of esdalloc */
  1021. X
  1022. X/*+-----------------------------------------------------------------------
  1023. X    esdptr = esdrealloc(maxcb)    - realloc an esd buffer
  1024. X
  1025. Xmay only be used to enlarge an esd buffer
  1026. Xthis used to use realloc(), which did a lot of unnecessary copying
  1027. Xalso no more abnormal program termination on memory failure
  1028. X------------------------------------------------------------------------*/
  1029. Xint
  1030. Xesdrealloc(tesd,maxcb)
  1031. XESD *tesd;
  1032. Xregister maxcb;        /* desired maxcb */
  1033. X{
  1034. Xregister actual_cb;
  1035. Xchar *newpb;
  1036. X
  1037. X    if(!tesd || (tesd->maxcb > maxcb))
  1038. X        return(eInternalLogicError);
  1039. X
  1040. X    /* enforce our limit */
  1041. X    if(maxcb > ESD_MAXSIZE)
  1042. X        return(eBufferTooSmall);
  1043. X
  1044. X    /* we get an extra character to ensure room for null past maxcb */
  1045. X    actual_cb = maxcb + 1;
  1046. X    if(actual_cb & 1)        /* even allocation */
  1047. X        ++actual_cb;
  1048. X
  1049. X    if(!(newpb = malloc(actual_cb)))
  1050. X        return(eNoMemory);
  1051. X
  1052. X    if(tesd->cb)
  1053. X        memcpy(newpb,tesd->pb,tesd->cb);
  1054. X
  1055. X    free(tesd->pb);
  1056. X    tesd->pb = newpb;
  1057. X    tesd->maxcb = actual_cb;
  1058. X    esd_null_terminate(tesd);
  1059. X    return(0);
  1060. X
  1061. X}    /* end of esdrealloc */
  1062. X
  1063. X/*+-----------------------------------------------------------------------
  1064. X    esdfree(esdptr)
  1065. X------------------------------------------------------------------------*/
  1066. Xvoid
  1067. Xesdfree(tesd)
  1068. Xregister ESD *tesd;
  1069. X{
  1070. X    if(tesd && tesd->pb)
  1071. X    {
  1072. X        free(tesd->pb);
  1073. X        free((char *)tesd);
  1074. X    }
  1075. X    else
  1076. X    {
  1077. X        errno = ENOMEM;
  1078. X        ff(se,"\r\n\r\nFREE_ESD FAILED. FATAL ERROR. SORRY.\r\n");
  1079. X        termecu(TERMECU_XMTR_FATAL_ERROR);
  1080. X    }
  1081. X}
  1082. X
  1083. X/*+-------------------------------------------------------------------------
  1084. X    esdcat(dest,suffix,realloc_ok) - "strcat" for ESDs
  1085. X
  1086. X  Append 'suffix' contents to 'dest'
  1087. X  if realloc_ok true, expand 'dest' as necessary
  1088. X
  1089. X  Returns: 0 - success
  1090. X           eNoMemory
  1091. X           eBufferTooSmall
  1092. X--------------------------------------------------------------------------*/
  1093. Xint
  1094. Xesdcat(dest,suffix,realloc_ok)
  1095. XESD *dest;
  1096. XESD *suffix;
  1097. Xint realloc_ok;
  1098. X{
  1099. X    int erc = 0;
  1100. X    int new_maxcb = dest->cb + suffix->cb;
  1101. X
  1102. X    if(dest->maxcb < new_maxcb)
  1103. X    {
  1104. X        if(!realloc_ok)
  1105. X            return(eBufferTooSmall);
  1106. X        if(erc = esdrealloc(dest,new_maxcb))
  1107. X            return(erc);
  1108. X    }
  1109. X
  1110. X    memcpy(dest->pb + dest->cb,suffix->pb,suffix->cb + 1);  /* catch null too */
  1111. X    dest->cb += suffix->cb;
  1112. X
  1113. X    return(0);
  1114. X
  1115. X}   /* end of esdcat */
  1116. X
  1117. X/*+-------------------------------------------------------------------------
  1118. X    esdstrcat(tesd,zstr) - "strcat" for ESDs
  1119. X
  1120. Xsimilar to esdcat(), but with automatic esd growth
  1121. X--------------------------------------------------------------------------*/
  1122. Xint
  1123. Xesdstrcat(tesd,zstr)
  1124. XESD *tesd;
  1125. Xchar *zstr;
  1126. X{
  1127. X    register zstrlen = strlen(zstr);
  1128. X    register erc = 0;
  1129. X
  1130. X    if(zstrlen > (tesd->maxcb - tesd->cb))
  1131. X    {
  1132. X        if(erc = esdrealloc(tesd,tesd->cb + zstrlen))
  1133. X            return(erc);
  1134. X    }
  1135. X
  1136. X    if(zstrlen)
  1137. X    {
  1138. X        strncpy(tesd->pb + tesd->cb,zstr,zstrlen);
  1139. X        tesd->cb += zstrlen;
  1140. X        esd_null_terminate(tesd);
  1141. X    }
  1142. X
  1143. X    return(erc);
  1144. X
  1145. X}    /* end of esdstrcat */
  1146. X
  1147. X
  1148. X/*+-------------------------------------------------------------------------
  1149. X    esdshow(tesd,title)
  1150. X--------------------------------------------------------------------------*/
  1151. Xvoid
  1152. Xesdshow(tesd,title)
  1153. XESD *tesd;
  1154. Xchar *title;
  1155. X{
  1156. Xregister itmp;
  1157. X
  1158. X    if(title && *title)
  1159. X    {
  1160. X        pputs(title);
  1161. X        pputs("\n");
  1162. X    }
  1163. X    esd_null_terminate(tesd);
  1164. X    pputs(tesd->pb);
  1165. X    pputs("\n");
  1166. X    for(itmp = 0; itmp <= tesd->cb; itmp++)
  1167. X    {
  1168. X        if(itmp == tesd->old_index)
  1169. X            pputc('^');
  1170. X        else if(itmp == tesd->index)
  1171. X            pputc('^');
  1172. X        else
  1173. X            pputc(' ');
  1174. X        if((itmp > tesd->old_index) && (itmp > tesd->index))
  1175. X            break;
  1176. X    }
  1177. X#if 0
  1178. X    pprintf(" o%d i%d c%d\n",tesd->old_index,tesd->index,tesd->cb);
  1179. X#else
  1180. X    pputs("\n");
  1181. X#endif
  1182. X
  1183. X}    /* end of esdshow */
  1184. X
  1185. X/*+----------------------------------------------------------------
  1186. X    strindex:  string index function
  1187. X
  1188. X  Returns position of 'str2' in 'str1' if found
  1189. X  If 'str2' is null, then 0 is returned (null matches anything)
  1190. X  Returns -1 if not found
  1191. X-----------------------------------------------------------------*/
  1192. Xint
  1193. Xstrindex(str1,str2)
  1194. Xchar *str1;    /* the (target) string to search */
  1195. Xchar *str2;    /* the (comparand) string to search for */
  1196. X{
  1197. Xregister istr1 = 0;
  1198. Xregister lstr2 = strlen(str2);
  1199. Xregister char *mstr = str1;    /* the (target) string to search */
  1200. X
  1201. X    if(*str2 == 0)            /* null string matches anything */
  1202. X        return(0);
  1203. X
  1204. X    while(*mstr)
  1205. X    {
  1206. X        if(*mstr == *str2)
  1207. X        { /* we have a first char match... does rest of string match? */
  1208. X            if(!strncmp(mstr,str2,lstr2))
  1209. X                return(istr1);        /* if so, return match position */
  1210. X        }
  1211. X        mstr++;
  1212. X        istr1++;
  1213. X    }
  1214. X
  1215. X    return(-1);        /* if we exhaust target string, flunk */
  1216. X
  1217. X}   /* end of strindex */
  1218. X
  1219. X/*+-------------------------------------------------------------------------
  1220. X    esdstrindex(esd1,esd2,index1_flag,index2_flag)
  1221. X
  1222. X  Call strindex with esd1->pb and esd2->pb.
  1223. X  If index1_flag != 0, esd1->pb + esd1->index passed
  1224. X  If index2_flag != 0, esd2->pb + esd2->index passed
  1225. X--------------------------------------------------------------------------*/
  1226. Xesdstrindex(esd1,esd2,index1_flag,index2_flag)
  1227. Xregister ESD *esd1;
  1228. Xregister ESD *esd2;
  1229. Xregister index1_flag;
  1230. Xregister index2_flag;
  1231. X{
  1232. X    return(strindex((index1_flag) ? esd1->pb : esd1->pb + esd1->index,
  1233. X        (index2_flag) ? esd2->pb : esd2->pb + esd2->index));
  1234. X
  1235. X}    /* end of esdstrindex */
  1236. X
  1237. X/*+----------------------------------------------------------------
  1238. X    keyword_lookup(ktable,tesd)
  1239. X
  1240. X  Lookup string in keyword_table struct array
  1241. X  Returns table->key_token if 'tesd' found in
  1242. X  'table', else -1
  1243. X
  1244. X  Beware substrings.  "type","typedef" will both match "type"
  1245. X-----------------------------------------------------------------*/
  1246. Xkeyword_lookup(ktable,tesd)
  1247. Xregister KEYTAB *ktable;
  1248. Xregister char *tesd;
  1249. X{
  1250. X/* register plen = strlen(tesd); */
  1251. X
  1252. X    while(ktable->key_word)
  1253. X    {
  1254. X/*        if(!strncmp(ktable->key_word,tesd,plen)) */
  1255. X        if(!strcmp(ktable->key_word,tesd))
  1256. X            return(ktable->key_token);
  1257. X        ++ktable;
  1258. X    }   /* end of while */
  1259. X
  1260. X    return(-1);     /* search failed */
  1261. X
  1262. X}   /* end of keyword_lookup */
  1263. X
  1264. X/*+----------------------------------------------------------------
  1265. X    skip_cmd_break(tesd)
  1266. X
  1267. X  Finds next non-break
  1268. X
  1269. X  'tesd' is an esd with valid 'index' field
  1270. X  Returns  0             index field points to non-break character
  1271. X           eNoParameter  end of command found
  1272. X-----------------------------------------------------------------*/
  1273. Xint
  1274. Xskip_cmd_break(tesd)
  1275. Xregister ESD *tesd;
  1276. X{
  1277. Xregister cb = tesd->cb;
  1278. Xregister index = tesd->index;
  1279. Xregister char *pb = tesd->pb;
  1280. X
  1281. X    while(index < cb)
  1282. X    {
  1283. X        if(!isspace(*(pb + index)))
  1284. X            break;
  1285. X        index++;
  1286. X    }
  1287. X    tesd->old_index = tesd->index = index;
  1288. X    if(index >= cb)
  1289. X        return(eNoParameter);
  1290. X    return(0);
  1291. X
  1292. X}   /* end of skip_cmd_break */
  1293. X
  1294. X/*+-------------------------------------------------------------------------
  1295. X    end_of_cmd(tesd) - return 1 if at end of command
  1296. X--------------------------------------------------------------------------*/
  1297. Xint
  1298. Xend_of_cmd(tesd)
  1299. Xregister ESD *tesd;
  1300. X{
  1301. X    if(skip_cmd_break(tesd) || (*(tesd->pb + tesd->index) == ';') ||
  1302. X            (*(tesd->pb + tesd->index) == '#'))
  1303. X        return(1);
  1304. X    return(0);
  1305. X}    /* end of end_of_cmd */
  1306. X
  1307. X/*+-------------------------------------------------------------------------
  1308. X    erc = skip_cmd_char(tesd,skipchar)
  1309. X--------------------------------------------------------------------------*/
  1310. Xint
  1311. Xskip_cmd_char(tesd,skipchar)
  1312. Xregister ESD *tesd;
  1313. Xregister char skipchar;
  1314. X{
  1315. Xint erc;
  1316. X
  1317. X    if(erc = skip_cmd_break(tesd))
  1318. X        return(erc);
  1319. X
  1320. X    if(tesd->pb[tesd->index] == skipchar)
  1321. X    {
  1322. X        ++tesd->index;
  1323. X        return(0);
  1324. X    }
  1325. X
  1326. X    return(eSyntaxError);
  1327. X
  1328. X}   /* end of skip_cmd_char */
  1329. X
  1330. X/*+-------------------------------------------------------------------------
  1331. X    erc = skip_colon(tesd)
  1332. X--------------------------------------------------------------------------*/
  1333. Xint
  1334. Xskip_colon(tesd)
  1335. Xregister ESD *tesd;
  1336. X{
  1337. X    register erc;
  1338. X
  1339. X    if(erc = skip_cmd_break(tesd))
  1340. X        return(erc);
  1341. X
  1342. X    if(tesd->pb[tesd->index] == ':')
  1343. X    {
  1344. X        ++tesd->index;
  1345. X        return(0);
  1346. X    }
  1347. X
  1348. X    return(eCommaExpected);
  1349. X
  1350. X}   /* end of skip_colon */
  1351. X
  1352. X/*+-------------------------------------------------------------------------
  1353. X    erc = skip_comma(tesd)
  1354. X--------------------------------------------------------------------------*/
  1355. Xint
  1356. Xskip_comma(tesd)
  1357. Xregister ESD *tesd;
  1358. X{
  1359. X    register erc;
  1360. X
  1361. X    if(erc = skip_cmd_break(tesd))
  1362. X        return(erc);
  1363. X
  1364. X    if(tesd->pb[tesd->index] == ',')
  1365. X    {
  1366. X        ++tesd->index;
  1367. X        return(0);
  1368. X    }
  1369. X
  1370. X    return(eCommaExpected);
  1371. X
  1372. X}   /* end of skip_comma */
  1373. X
  1374. X/*+-------------------------------------------------------------------------
  1375. X    erc = skip_paren(fparam,LEFT or RIGHT)
  1376. X--------------------------------------------------------------------------*/
  1377. Xint
  1378. Xskip_paren(tesd,fLeft)
  1379. Xregister ESD *tesd;
  1380. Xint fLeft;
  1381. X{
  1382. Xregister erc;
  1383. Xregister char search = (fLeft) ? '(' : ')';
  1384. X
  1385. X    if(erc = skip_cmd_break(tesd))
  1386. X        return(erc);
  1387. X
  1388. X    if(tesd->pb[tesd->index] == search)
  1389. X    {
  1390. X        tesd->index++;
  1391. X        return(0);
  1392. X    }
  1393. X    return((fLeft) ? eMissingLeftParen : eMissingRightParen);
  1394. X
  1395. X}   /* end of skip_paren */
  1396. X
  1397. X/*+-------------------------------------------------------------------------
  1398. X    get_cmd_char(tesd,pchar)
  1399. X--------------------------------------------------------------------------*/
  1400. Xint
  1401. Xget_cmd_char(tesd,pchar)
  1402. Xregister ESD *tesd;
  1403. Xchar *pchar;
  1404. X{
  1405. Xint erc;
  1406. X
  1407. X    if(erc = skip_cmd_break(tesd))
  1408. X        return(erc);
  1409. X    *pchar = tesd->pb[tesd->index++];
  1410. X    return(0);
  1411. X
  1412. X}    /* end of get_cmd_char */
  1413. X
  1414. X/*+----------------------------------------------------------------
  1415. X    get_alpha_zstr(&esd,&strbuf,strbuf_maxcb)
  1416. X
  1417. X  places next alphabetic string token [A-Za-z_] into
  1418. X  the null-terminated 'strbuf' string.  returns 0 or -1
  1419. X  or skip_cmd_break error codes
  1420. X-----------------------------------------------------------------*/
  1421. Xint
  1422. Xget_alpha_zstr(tesd,strbuf,strbuf_maxcb)
  1423. XESD *tesd;
  1424. Xregister char *strbuf;
  1425. Xint strbuf_maxcb;
  1426. X{
  1427. Xregister izstr;
  1428. Xregister schar;
  1429. Xregister char *pb = tesd->pb;
  1430. X
  1431. X    if(izstr = skip_cmd_break(tesd))
  1432. X        return(izstr);
  1433. X    izstr = 0;
  1434. X    while( (izstr < strbuf_maxcb-1) && (tesd->index < tesd->cb) )
  1435. X    {
  1436. X        schar = pb[tesd->index];
  1437. X        if((!isalpha(schar)) && (schar != '_'))
  1438. X            break;
  1439. X        strbuf[izstr++] = schar;
  1440. X        tesd->index++;
  1441. X    }
  1442. X
  1443. X    strbuf[izstr] = 0;
  1444. X    return(izstr ? 0 : eBadParameter);
  1445. X
  1446. X}   /* end of get_alpha_zstr */
  1447. X
  1448. X/*+----------------------------------------------------------------
  1449. X    get_alphanum_zstr(&esd,&strbuf,strbuf_maxcb)
  1450. X
  1451. X  places next alphanumeric string token [A-Za-z0-9_]
  1452. X  into the null-terminated 'strbuf' string.  returns 0
  1453. X  or -1 or skip_cmd_break error codes
  1454. X-----------------------------------------------------------------*/
  1455. Xint
  1456. Xget_alphanum_zstr(tesd,strbuf,strbuf_maxcb)
  1457. Xregister ESD *tesd;
  1458. Xregister char *strbuf;
  1459. Xint strbuf_maxcb;
  1460. X{
  1461. Xint izstr = 0;
  1462. Xint schar;
  1463. Xregister cb = tesd->cb;
  1464. Xregister index;
  1465. X
  1466. X    if(izstr = skip_cmd_break(tesd))
  1467. X        return(izstr);
  1468. X
  1469. X    index = tesd->index;
  1470. X    while( (izstr < strbuf_maxcb-1) && (index < cb))
  1471. X    {
  1472. X        schar = tesd->pb[index++];
  1473. X        if(isalnum(schar) || (schar == '_'))
  1474. X            strbuf[izstr++] = schar;
  1475. X        else
  1476. X        {
  1477. X            --index;
  1478. X            break;
  1479. X        }
  1480. X    }
  1481. X
  1482. X    tesd->index = index;
  1483. X    strbuf[izstr]=0;
  1484. X    return(izstr ? 0 : eBadParameter);
  1485. X
  1486. X}   /* end of get_alphanum_zstr */
  1487. X
  1488. X/*+----------------------------------------------------------------
  1489. X    get_numeric_zstr(&esd,&strbuf,strbuf_maxcb)
  1490. X    gets next numeric string token places it
  1491. X    into the null-terminated 'strbuf' string.  returns 0 or -1 
  1492. X    or skip_cmd_break error codes
  1493. X-----------------------------------------------------------------*/
  1494. Xint
  1495. Xget_numeric_zstr(tesd,strbuf,strbuf_maxcb)
  1496. Xregister ESD *tesd;
  1497. Xregister char *strbuf;
  1498. Xregister strbuf_maxcb;
  1499. X{
  1500. X    register izstr;
  1501. X    register schar;
  1502. X
  1503. X    if(izstr = skip_cmd_break(tesd))
  1504. X        return(izstr);
  1505. X
  1506. X    while( (izstr < strbuf_maxcb-1) && (tesd->index < tesd->cb) )
  1507. X    {
  1508. X        schar = tesd->pb[tesd->index++];
  1509. X        if( isdigit(schar) )
  1510. X            strbuf[izstr++]=schar;
  1511. X        else
  1512. X        {
  1513. X            --tesd->index;
  1514. X            break;
  1515. X        }
  1516. X    }
  1517. X
  1518. X    strbuf[izstr]=0;
  1519. X    return(izstr ? 0 : eBadParameter);
  1520. X
  1521. X}   /* end of get_numeric_zstr */
  1522. X
  1523. X/*+-----------------------------------------------------------------------
  1524. X    get_numeric_value(tesd,&long_var)
  1525. X------------------------------------------------------------------------*/
  1526. Xget_numeric_value(tesd,value)
  1527. Xregister ESD *tesd;
  1528. Xregister long *value;
  1529. X{
  1530. Xregister erc;
  1531. Xchar buf[32];
  1532. X
  1533. X    if(erc = get_numeric_zstr(tesd,buf,sizeof(buf)))
  1534. X        return(erc);
  1535. X    sscanf(buf,"%ld",value);
  1536. X    return(0);
  1537. X
  1538. X}    /* end of get_numeric_value */
  1539. X
  1540. X/*+----------------------------------------------------------------
  1541. X    get_word_zstr(&esd,&strbuf,strbuf_maxcb)
  1542. X
  1543. X  gets next word (continuous string of characters without spaces
  1544. X  or tabs) returns 0 or -1 or skip_cmd_break error codes
  1545. X-----------------------------------------------------------------*/
  1546. Xint
  1547. Xget_word_zstr(tesd,strbuf,strbuf_maxcb)
  1548. Xregister ESD *tesd;
  1549. Xregister char *strbuf;
  1550. Xregister strbuf_maxcb;
  1551. X{
  1552. X    register izstr;
  1553. X    register schar;
  1554. X
  1555. X    if(izstr = skip_cmd_break(tesd))
  1556. X        return(izstr);
  1557. X
  1558. X    strbuf_maxcb--;
  1559. X    while((izstr < strbuf_maxcb) && (tesd->index < tesd->cb))
  1560. X    {
  1561. X        schar = tesd->pb[tesd->index++];
  1562. X        if( (schar > 0x20) && (schar <= 0x7e))
  1563. X            strbuf[izstr++]=schar;
  1564. X        else
  1565. X        {
  1566. X            --tesd->index;
  1567. X            break;
  1568. X        }
  1569. X    }
  1570. X
  1571. X    strbuf[izstr]=0;
  1572. X    return(izstr ? 0 : eBadParameter);
  1573. X
  1574. X}   /* end of get_word_zstr */
  1575. X
  1576. X/*+-------------------------------------------------------------------------
  1577. X    esd_strip_trail_break(tesd)
  1578. X--------------------------------------------------------------------------*/
  1579. Xvoid
  1580. Xesd_strip_trail_break(ztext)
  1581. Xregister ESD *ztext;
  1582. X{
  1583. X    while(ztext->cb &&
  1584. X        ((ztext->pb[ztext->cb-1] == 0x20) || (ztext->pb[ztext->cb-1] == 0x20)))
  1585. X    {
  1586. X        ztext->cb--;
  1587. X    }
  1588. X}   /* end of esd_strip_trail_break */
  1589. X
  1590. X/*+-------------------------------------------------------------------------
  1591. X    esdfgets(&esd,fileptr)
  1592. X
  1593. X  stdio read from FILE *fileptr into esd
  1594. X  returns tesd->cb set up not including trailing nl, tesd->index == 0
  1595. X--------------------------------------------------------------------------*/
  1596. Xint
  1597. Xesdfgets(tesd,fileptr)
  1598. Xregister ESD *tesd;
  1599. Xregister FILE *fileptr;
  1600. X{
  1601. Xregister char *cptr;
  1602. X
  1603. X    tesd->cb = 0;
  1604. X    if(!fgets(tesd->pb,tesd->maxcb+1,fileptr))
  1605. X        return(eEOF);
  1606. X    if(!(cptr = strchr(tesd->pb,0x0A)))
  1607. X        return(eBufferTooSmall);
  1608. X    tesd->cb = (int)(cptr - tesd->pb);
  1609. X    esd_null_terminate(tesd);
  1610. X    tesd->index = 0;
  1611. X    tesd->old_index = 0;
  1612. X    return(0);
  1613. X
  1614. X}    /* end of esdfgets */
  1615. X
  1616. X/*+-------------------------------------------------------------------------
  1617. X    esdfputs(&esd,fileptr,index_flag,nl_flag)
  1618. X
  1619. X  write esd contents to stdio FILE *fileptr
  1620. X  if index_flag is true, write from tesd->index thru end of esd
  1621. X  otherwise, from start of esd
  1622. X  if nl_flag is true, append nl to write, else just esd contents
  1623. X--------------------------------------------------------------------------*/
  1624. Xint
  1625. Xesdfputs(tesd,fileptr,index_flag,nl_flag)
  1626. Xregister ESD *tesd;
  1627. XFILE *fileptr;
  1628. Xint index_flag;
  1629. Xint nl_flag;
  1630. X{
  1631. Xregister char *cptr;
  1632. Xregister write_length;
  1633. X
  1634. X    if(index_flag)
  1635. X    {
  1636. X        cptr = &tesd->pb[tesd->index];
  1637. X        write_length = tesd->cb - tesd->index;
  1638. X    }
  1639. X    else
  1640. X    {
  1641. X        cptr = tesd->pb;
  1642. X        write_length = tesd->cb;
  1643. X    }
  1644. X
  1645. X    if(write_length)
  1646. X        fwrite(cptr,write_length,1,fileptr);
  1647. X
  1648. X    if(nl_flag)
  1649. X        fputc(0x0A,fileptr);
  1650. X
  1651. X    return(0);
  1652. X}    /* end of esdfputs */
  1653. X
  1654. X/*+-------------------------------------------------------------------------
  1655. X    get_switches(tesd,switches,switches_max)
  1656. X--------------------------------------------------------------------------*/
  1657. Xint
  1658. Xget_switches(tesd,switches,switches_max)
  1659. XESD *tesd;
  1660. Xchar *switches;
  1661. Xint switches_max;
  1662. X{
  1663. Xregister erc;
  1664. Xregister index;
  1665. Xregister char *pb = tesd->pb;
  1666. Xint cb = tesd->cb;
  1667. Xchar schar;
  1668. X
  1669. X    *switches = 0;
  1670. X
  1671. X    if(erc = skip_cmd_break(tesd))
  1672. X        return(erc);
  1673. X
  1674. X    index = tesd->index;
  1675. X    if(*(pb + index) != '-')
  1676. X        return(eNoSwitches);
  1677. X
  1678. X    if(switches_max < 3)
  1679. X        return(eSwitchesTooLong);
  1680. X
  1681. X    switches_max--;            /* for trailing null */
  1682. X    *switches++ = '-';
  1683. X    switches_max--;
  1684. X    index++;
  1685. X    while(index < cb)
  1686. X    {
  1687. X        schar = *(pb + index++);
  1688. X        if(switches_max > 0)
  1689. X            *switches++ = schar;
  1690. X        switches_max--;
  1691. X        if(isspace(schar))
  1692. X            break;
  1693. X    }
  1694. X
  1695. X    tesd->index = index;
  1696. X    *switches = 0;
  1697. X    return((switches_max < 0) ? eSwitchesTooLong : 0);
  1698. X
  1699. X}   /* end of get_switches() */
  1700. X
  1701. X/* vi: set tabstop=4 shiftwidth=4: */
  1702. X/* end of esdutil.c */
  1703. SHAR_EOF
  1704. chmod 0644 esdutil.c ||
  1705. echo 'restore of esdutil.c failed'
  1706. Wc_c="`wc -c < 'esdutil.c'`"
  1707. test 19527 -eq "$Wc_c" ||
  1708.     echo 'esdutil.c: original size 19527, current size' "$Wc_c"
  1709. rm -f _shar_wnt_.tmp
  1710. fi
  1711. # ============= expresp.c ==============
  1712. if test -f 'expresp.c' -a X"$1" != X"-c"; then
  1713.     echo 'x - skipping expresp.c (File already exists)'
  1714.     rm -f _shar_wnt_.tmp
  1715. else
  1716. > _shar_wnt_.tmp
  1717. echo 'x - extracting expresp.c (Text)'
  1718. sed 's/^X//' << 'SHAR_EOF' > 'expresp.c' &&
  1719. X/*+-------------------------------------------------------------------------
  1720. X    expresp.c - HDB expect/respond per SCO Devices file
  1721. X    wht@n4hgf.Mt-Park.GA.US
  1722. X
  1723. X Meaning of some of the escape characters:
  1724. X \p - pause (approximately 1/4-1/2 second delay)
  1725. X \d - delay (2 seconds)
  1726. X \D - phone number/token
  1727. X \T - phone number with Dialcodes and character translation
  1728. X \N - null byte
  1729. X \K - insert a BREAK
  1730. X \E - turn on echo checking (for slow devices)
  1731. X \e - turn off echo checking
  1732. X \r - carriage return
  1733. X \c - no new-line
  1734. X \n - send new-line
  1735. X \nnn - send octal number
  1736. X \\ - send backslash
  1737. X \m### - sleep ### (decimal) milliseconds (non-standard)
  1738. X Speed - Hayes-specific "CONNECT"  handler
  1739. X
  1740. X  Defined functions:
  1741. X    execute_expresp(expresp_script)
  1742. X    expect(str)
  1743. X    pcmd_expresp(param)
  1744. X    respond(str)
  1745. X
  1746. X--------------------------------------------------------------------------*/
  1747. X/*+:EDITS:*/
  1748. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  1749. X/*:09-04-1992-19:07-wht@n4hgf-new msec delay syntax + harden */
  1750. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  1751. X/*:12-16-1991-15:25-wht@n4hgf-allow for backslash in expect and respond */
  1752. X/*:10-09-1991-20:21-wht@n4hgf-bad llookfor echo argument */
  1753. X/*:08-01-1991-05:00-wht@n4hgf-\n sent CR not NL */
  1754. X/*:08-01-1991-04:31-wht@n4hgf-nap min of hzmsec if \m */
  1755. X/*:08-01-1991-04:22-wht@n4hgf-detect NULL expect string */
  1756. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  1757. X/*:07-17-1991-07:04-wht@n4hgf-avoid SCO UNIX nap bug */
  1758. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1759. X
  1760. X#include "ecu.h"
  1761. X#include "ecuerror.h"
  1762. X#include "esd.h"
  1763. X#include "var.h"
  1764. X#include "proc.h"
  1765. X
  1766. X
  1767. X#define MAX_FIELDS    50    /* max fields in a chat script */
  1768. X#define MAX_EXPRESP    511    /* max length of a chat script */
  1769. X#define MAX_EXPECT    63    /* max length of expect string */
  1770. X#define DEFAULT_TIMEOUT_MSECS (10*1000L)
  1771. X
  1772. X#define ERDEBUG(verb,str,arg) if(expresp_verbosity >= verb) \
  1773. X    pprintf(str,arg)
  1774. X
  1775. Xlong atol();
  1776. Xchar *strip_phone_num();
  1777. Xchar *dialcodes_translate();
  1778. X
  1779. Xextern int proctrace;
  1780. X
  1781. Xint expresp_verbosity = 0;
  1782. Xulong expect_timeout_msecs = DEFAULT_TIMEOUT_MSECS;
  1783. Xint expresp_echo_check = 0;
  1784. X
  1785. Xchar last_Speed_result[32];
  1786. X
  1787. X/*+-------------------------------------------------------------------------
  1788. X    expect(str) - expect (read) string from remote
  1789. Xreturn code on failure, 0 on success
  1790. X--------------------------------------------------------------------------*/
  1791. Xint
  1792. Xexpect(str)
  1793. Xchar *str;
  1794. X{
  1795. X    int erc;
  1796. X    int itmp;
  1797. X    char op;
  1798. X    char s4[4];
  1799. X    char parsebuf[MAX_EXPECT + 1];
  1800. X    int remaining = MAX_EXPECT;
  1801. X    long atol();
  1802. X    register char *cptr;
  1803. X    register char *parsed = parsebuf;
  1804. X    int old_ttymode = get_ttymode();
  1805. X
  1806. X    if(!str)
  1807. X    {
  1808. X        ERDEBUG(2,"expect string NULL\n",0);
  1809. X        return(eExpectRespondFail);
  1810. X    }
  1811. X
  1812. X    if(old_ttymode != 2)
  1813. X        ttymode(2);
  1814. X
  1815. X    /*
  1816. X     * ~?[]
  1817. X     */
  1818. X    if((*str == '~') && *(str + 1) && (*(str + 2) == '['))
  1819. X    {
  1820. X        op = *(str + 1);
  1821. X        str += 3;
  1822. X        switch(op)
  1823. X        {
  1824. X            case 'm':    /* msec expect timeout */
  1825. X            case 't':    /*  sec expect timeout */
  1826. X                expect_timeout_msecs = atol(str);
  1827. X                if(op == 't')
  1828. X                    expect_timeout_msecs *= 1000L;
  1829. X                ERDEBUG(2,"expect timeout = %lu msec\n",expect_timeout_msecs);
  1830. X                break;
  1831. X
  1832. X            default:
  1833. X                ERDEBUG(0,"\nexpect: invalid subop: ~%c[]\n",op);
  1834. X                break;
  1835. X        }
  1836. X        if(cptr = strchr(str,']'))
  1837. X            str = cptr + 1;
  1838. X        else
  1839. X        {
  1840. X            ERDEBUG(0,"\nexpect: missing ] after ~[%c\n",op);
  1841. X            erc = eExpectRespondFail;
  1842. X            goto DID_NOT_GET_EXPECTED;
  1843. X        }
  1844. X    }
  1845. X
  1846. X    ERDEBUG(2,"expect: <<%s>>\n",str);
  1847. X    if(!strlen(str) || !strcmp(str,"\"\""))
  1848. X        goto GOT_EXPECTED;
  1849. X
  1850. X    if(!strcmp(str,"Speed"))
  1851. X    {
  1852. X        LRWT lr;
  1853. X        long ms_start;
  1854. X        long ms_now;
  1855. X        struct timeb now_timeb;
  1856. X        ftime(&now_timeb);
  1857. X        ms_start = (now_timeb.time * 1000) + now_timeb.millitm;
  1858. X        do {
  1859. X            last_Speed_result[0] = 0;
  1860. X            lr.to1 = 90 * 100L;
  1861. X            lr.to2 = 120L;
  1862. X            /* allow interrupts + cooked read */
  1863. X            lr.raw_flag = 0x80;
  1864. X            lr.buffer = last_Speed_result;
  1865. X            lr.bufsize = sizeof(last_Speed_result);
  1866. X            lr.delim = "\n";
  1867. X            lr.echo_flag = !!expresp_verbosity;
  1868. X            lgets_timeout(&lr);
  1869. X            ftime(&now_timeb);
  1870. X            ms_now = (now_timeb.time * 1000) + now_timeb.millitm;
  1871. X        } while(!sigint && !lr.count && ((ms_now - ms_start) < 90*1000L));
  1872. X
  1873. X        if(sigint || strncmp(lr.buffer,"CONNECT",7))
  1874. X            goto DID_NOT_GET_EXPECTED;
  1875. X        else
  1876. X            goto GOT_EXPECTED;
  1877. X    }
  1878. X
  1879. X    cptr = str;
  1880. X    while(remaining && *cptr)
  1881. X    {
  1882. X        if(*cptr == '\\')
  1883. X        {
  1884. X            if(!*(++cptr))    /* if no character after escape, ... */
  1885. X            {
  1886. X                ERDEBUG(2," error: str ended with '\\'\n",0);
  1887. X                goto DID_NOT_GET_EXPECTED;
  1888. X            }
  1889. X
  1890. X            if(isdigit(*cptr))    /* handle \ooo */
  1891. X            {
  1892. X                strncpy(s4,cptr,3);
  1893. X                s4[3] = 0;
  1894. X                sscanf(s4,"%o",&itmp);
  1895. X                cptr += strspn(s4,"01234567");
  1896. X                *parsed++ = (char)itmp;
  1897. X                remaining--;
  1898. X                continue;
  1899. X            }
  1900. X
  1901. X            switch(*cptr)
  1902. X            {
  1903. X                case 'n':
  1904. X                    *parsed++ = 0x0A;
  1905. X                    remaining--;
  1906. X                    break;
  1907. X                case 'r':
  1908. X                    *parsed++ = 0x0D;
  1909. X                    remaining--;
  1910. X                    break;
  1911. X                case '\\':
  1912. X                    *parsed++ = '\\';
  1913. X                    remaining--;
  1914. X                    break;
  1915. X                case '~':
  1916. X                    *parsed++ = '~';
  1917. X                    remaining--;
  1918. X                    break;
  1919. X                default:
  1920. X                    ERDEBUG(2," meaningless here: \\%c\n",*cptr);
  1921. X                    break;
  1922. X            }
  1923. X            cptr++;
  1924. X        }
  1925. X        else
  1926. X        {
  1927. X            *parsed++ = *cptr++;
  1928. X            remaining--;
  1929. X        }
  1930. X    }
  1931. X    *parsed = 0;
  1932. X
  1933. X    if(!remaining)
  1934. X        ERDEBUG(1," expect string too long\n",0);
  1935. X
  1936. X    if(expresp_verbosity >= 3)
  1937. X        hex_dump(parsebuf,strlen(parsebuf),"expecting",1);
  1938. X
  1939. X    if(llookfor(parsebuf,expect_timeout_msecs,!!expresp_verbosity))
  1940. X    {
  1941. XGOT_EXPECTED:
  1942. X        ERDEBUG(2,"[EXPECT SUCCEEDED]\n",0);
  1943. X        erc = 0;
  1944. X        goto RESTORE_TTYMODE_AND_RETURN_ERC;
  1945. X
  1946. X    }
  1947. X
  1948. XDID_NOT_GET_EXPECTED:
  1949. X    ERDEBUG(2,"[EXPECT FAILED%s]\n",(sigint) ? " (interrupted)" : "");
  1950. X    if(sigint)
  1951. X    {
  1952. X        sigint = 0;
  1953. X        erc = eCONINT;
  1954. X    }
  1955. X    else
  1956. X        erc = eExpectRespondFail;
  1957. X    goto RESTORE_TTYMODE_AND_RETURN_ERC;
  1958. X
  1959. XRESTORE_TTYMODE_AND_RETURN_ERC:
  1960. X    if(old_ttymode != 2)
  1961. X        ttymode(old_ttymode);
  1962. X    return(erc);
  1963. X
  1964. X}    /* end of expect */
  1965. X
  1966. X/*+-------------------------------------------------------------------------
  1967. X    respond(str) - send to remote
  1968. X
  1969. Xwe enable SIGINT processing in here and return if 'sigint'
  1970. Xdetected, but here, unlike many other places, we do *not* reset
  1971. Xsigint (since we do not really "handle" it)
  1972. X--------------------------------------------------------------------------*/
  1973. Xvoid
  1974. Xrespond(str)
  1975. Xregister char *str;
  1976. X{
  1977. X    int itmp;
  1978. X    long nap_msec;
  1979. X    char s4[4];
  1980. X    char *cptr;
  1981. X    char *phnum;
  1982. X    char op;
  1983. X    int send_no_cr = 0;
  1984. X    int old_ttymode = get_ttymode();
  1985. X
  1986. X    if(sigint)
  1987. X        return;
  1988. X
  1989. X    ttymode(2);    /* enable SIGINT/sigint */
  1990. X
  1991. X    ERDEBUG(2,"respond: <<%s>>\n",str);
  1992. X    while(*str)
  1993. X    {
  1994. X        if(*str == '\\')
  1995. X        {
  1996. X            if(isdigit(*++str))    /* handle \ooo */
  1997. X            {
  1998. X                strncpy(s4,str,3);
  1999. X                s4[3] = 0;
  2000. X                sscanf(s4,"%o",&itmp);
  2001. X                str += strspn(s4,"01234567") - 1; /* -1 because str++ later */
  2002. X                lputc((char)itmp);
  2003. X            }
  2004. X            else switch(*str)
  2005. X            {
  2006. X                case 'p':  /* pause (approximately 1/4-1/2 second delay) */
  2007. X                    ldraino(0);    /* wait for output to drain */
  2008. X                    if(Nap(400L) < 0)
  2009. X                        goto RETURN;
  2010. X                    break;
  2011. X                case 'M': /* CLOCAL on */
  2012. X                case 'm': /* CLOCAL off */
  2013. X                    itmp = (*str == 'M');
  2014. X                    lCLOCAL(itmp);
  2015. X                    ERDEBUG(2,"CLOCAL set %s\n",(itmp) ? "ON" : "OFF");
  2016. X                    break;
  2017. X                case 'd':  /* delay (2 seconds) */
  2018. X                    ldraino(0);    /* wait for output to drain */
  2019. X                    if(Nap(2000L) < 0)
  2020. X                        goto RETURN;
  2021. X                    break;
  2022. X                case 'D':  /* phone number/token */
  2023. X                    cptr = strip_phone_num(shm->Ltelno);
  2024. X                    if(expresp_echo_check)
  2025. X                        lputs_paced(40,cptr);
  2026. X                    else
  2027. X                        lputs(cptr);
  2028. X                    break;
  2029. X                case 'T':  /* phnum with Dialcodes and char translation */
  2030. X                    phnum = strip_phone_num(shm->Ltelno);
  2031. X                    cptr = dialcodes_translate(&phnum);
  2032. X                    if(expresp_echo_check)
  2033. X                    {
  2034. X                        lputs_paced(40,cptr);
  2035. X                        lputs_paced(40,phnum);
  2036. X                    }
  2037. X                    else
  2038. X                    {
  2039. X                        lputs(cptr);
  2040. X                        lputs(phnum);
  2041. X                    }
  2042. X                    break;
  2043. X                case 'N':  /* null byte */
  2044. X                    lputc(0);
  2045. X                    break;
  2046. X                case 'K':  /* insert a BREAK */
  2047. X                    lbreak();
  2048. X                    break;
  2049. X                case 'E':  /* turn on echo checking (for slow devices) */
  2050. X                    expresp_echo_check = 1;
  2051. X                    break;
  2052. X                case 'e':  /* turn off echo checking */
  2053. X                    expresp_echo_check = 0;
  2054. X                    break;
  2055. X                case 'r':  /* carriage return */
  2056. X                    lputc(0x0D);
  2057. X                    break;
  2058. X                case 'c':  /* no new-line */
  2059. X                    send_no_cr = 1;
  2060. X                    break;
  2061. X                case 'n':  /* send new-line */
  2062. X                    lputc(0x0A);
  2063. X                    break;
  2064. X                case '\\':  /* send backslash */
  2065. X                    lputc('\\');
  2066. X                    break;
  2067. X                case '~':  /* send tilde */
  2068. X                    lputc('~');
  2069. X                    break;
  2070. X            }
  2071. X
  2072. X        }
  2073. X        else if((*str == '~') && *(str + 1) && (*(str + 2) == '['))
  2074. X        {
  2075. X            op = *(str + 1);
  2076. X            str += 3;
  2077. X            switch(op)
  2078. X            {
  2079. X
  2080. X                case 'n':    /* nap for milliseconds */
  2081. X                    nap_msec = atol(str);
  2082. X                    if(nap_msec < 0L)
  2083. X                        nap_msec = 0;
  2084. X                    if(nap_msec >= 500)
  2085. X                        ERDEBUG(2,"nap for %lu msec\n",nap_msec);
  2086. X                    Nap(nap_msec);
  2087. X                    break;
  2088. X
  2089. X                default:
  2090. X                    ERDEBUG(0,"\nrespond: invalid subop: ~%c[]\n",op);
  2091. X                    break;
  2092. X
  2093. X            }
  2094. X            if(cptr = strchr(str,']'))
  2095. X                str = cptr + 1;
  2096. X            else
  2097. X            {
  2098. X                ERDEBUG(0,"\nrespond: missing ] after ~[%c\n",op);
  2099. X                goto RETURN;
  2100. X            }
  2101. X        }
  2102. X        else
  2103. X            lputc(*str);
  2104. X
  2105. X
  2106. X        if(expresp_echo_check)
  2107. X        {
  2108. X            ldraino(1);        /* wait for output to drain, then flush input */
  2109. X            Nap(40L);        /* fake it */
  2110. X        }
  2111. X        str++;
  2112. X    }
  2113. X
  2114. X    if(!send_no_cr)
  2115. X        lputc(0x0D);
  2116. X
  2117. XRETURN:
  2118. X    ttymode(old_ttymode);
  2119. X
  2120. X}    /* end of respond */
  2121. X
  2122. X/*+-------------------------------------------------------------------------
  2123. X    execute_expresp(expresp_script)
  2124. X
  2125. Xreturn 0 on success, else error code
  2126. X--------------------------------------------------------------------------*/
  2127. Xint
  2128. Xexecute_expresp(expresp_script)
  2129. Xchar *expresp_script;
  2130. X{
  2131. X    char *fields[MAX_FIELDS + 1];
  2132. X    int ifields;
  2133. X    int nfields;
  2134. X    int erc;
  2135. X    char expresp_copy[MAX_EXPRESP + 1];
  2136. X    char *expect_this;
  2137. X    char *send_on_fail;
  2138. X
  2139. X#define EXPECT_STATE (!(ifields & 1))    /* even numbered fields are expect */
  2140. X    expresp_echo_check = 0;
  2141. X    last_Speed_result[0] = 0;
  2142. X
  2143. X    ERDEBUG(2,"[EXPECT/RESPOND INITIAL TIMEOUT %ld MSEC]\n",
  2144. X        expect_timeout_msecs);
  2145. X
  2146. X    strncpy(expresp_copy,expresp_script,sizeof(expresp_copy));
  2147. X    build_arg_array(expresp_copy,fields,MAX_FIELDS,&nfields);
  2148. X    if(!nfields)    /* if no script, assume success */
  2149. X    {
  2150. X        ERDEBUG(2,"[EMPTY SCRIPT - EXPECT/RESPOND SUCCEEDED]\n",0);
  2151. X        return(0);
  2152. X    }
  2153. X
  2154. X    for(ifields = 0; ifields < nfields; ifields++)
  2155. X    {
  2156. X        if(sigint)
  2157. X            break;
  2158. X        if(EXPECT_STATE)
  2159. X        {
  2160. X            expect_this = fields[ifields];
  2161. X            while(1)    /* until break or return(error) */
  2162. X            {
  2163. X                if(send_on_fail = strchr(expect_this,'-'))
  2164. X                    *send_on_fail++ = 0;
  2165. X                if(!(erc = expect(expect_this)))
  2166. X                    break;
  2167. X                if((erc != eExpectRespondFail) || !send_on_fail)
  2168. X                {
  2169. X                    ERDEBUG(2,"[EXPECT/RESPOND FAILED]\n",0);
  2170. X                    return(eExpectRespondFail);
  2171. X                }
  2172. X                if(expect_this = strchr(send_on_fail,'-'))
  2173. X                    *expect_this++ = 0;
  2174. X                if(sigint)
  2175. X                    break;
  2176. X                respond(send_on_fail);
  2177. X            }
  2178. X        }
  2179. X        else
  2180. X            respond(fields[ifields]);
  2181. X    }
  2182. X    if(sigint)
  2183. X    {
  2184. X        sigint = 0;
  2185. X        ERDEBUG(2,"[CONSOLE INTERRUPT]\n",0);
  2186. X        return(eCONINT);
  2187. X    }
  2188. X    ERDEBUG(2,"[EXPECT/RESPOND SUCCEEDED]\n",0);
  2189. X    return(0);
  2190. X
  2191. X}    /* end of execute_expresp */
  2192. X
  2193. X/*+-------------------------------------------------------------------------
  2194. X    pcmd_expresp(param)
  2195. Xexpresp [-v[v...]] <exp-resp-str> [<timeout_msecs>]
  2196. X--------------------------------------------------------------------------*/
  2197. Xint
  2198. Xpcmd_expresp(param)
  2199. XESD *param;
  2200. X{
  2201. X    int erc;
  2202. X    int itmp;
  2203. X    char *cptr;
  2204. X    ESD *tesd;
  2205. X    char switches[8];
  2206. X
  2207. X    if((tesd = esdalloc(MAX_EXPRESP + 1)) == (ESD *)0)
  2208. X        return(eNoMemory);
  2209. X
  2210. X    get_switches(param,switches,sizeof(switches));
  2211. X
  2212. X    if(erc = gstr(param,tesd,0))
  2213. X    {
  2214. X        esdfree(tesd);
  2215. X        return(erc);
  2216. X    }
  2217. X
  2218. X    expect_timeout_msecs = DEFAULT_TIMEOUT_MSECS;
  2219. X    expresp_verbosity = (!!strchr(switches,'v')) || proctrace;
  2220. X    if(expresp_verbosity)
  2221. X    {
  2222. X        cptr = switches;
  2223. X        itmp = 0;
  2224. X        while(*cptr)
  2225. X            itmp += (*cptr++ == 'v');
  2226. X        if(itmp > 1)
  2227. X            expresp_verbosity = itmp;
  2228. X    }
  2229. X
  2230. X    if(erc = gint(param,&expect_timeout_msecs))
  2231. X    {
  2232. X        /* if something there non-integer */
  2233. X        if(!end_of_cmd(param))
  2234. X        {
  2235. X            erc = eSyntaxError;
  2236. X            goto RETURN;
  2237. X        }
  2238. X    }
  2239. X
  2240. X    erc = execute_expresp(tesd->pb);
  2241. X
  2242. XRETURN:
  2243. X    esdfree(tesd);
  2244. X    iv[0] = !!erc;
  2245. X    if(proctrace)
  2246. X        pprintf("$i00 = %7ld (0x%08lx,0%lo)\n",iv[0],iv[0],iv[0]);
  2247. X    if(erc == eExpectRespondFail)
  2248. X        erc = 0;
  2249. X    return(erc);
  2250. X
  2251. X}    /* end of pcmd_expresp */
  2252. X
  2253. X/* vi: set tabstop=4 shiftwidth=4: */
  2254. X/* end of expresp.c */
  2255. SHAR_EOF
  2256. chmod 0644 expresp.c ||
  2257. echo 'restore of expresp.c failed'
  2258. Wc_c="`wc -c < 'expresp.c'`"
  2259. test 12024 -eq "$Wc_c" ||
  2260.     echo 'expresp.c: original size 12024, current size' "$Wc_c"
  2261. rm -f _shar_wnt_.tmp
  2262. fi
  2263. # ============= fasiintf.c ==============
  2264. if test -f 'fasiintf.c' -a X"$1" != X"-c"; then
  2265.     echo 'x - skipping fasiintf.c (File already exists)'
  2266.     rm -f _shar_wnt_.tmp
  2267. else
  2268. > _shar_wnt_.tmp
  2269. echo 'x - extracting fasiintf.c (Text)'
  2270. sed 's/^X//' << 'SHAR_EOF' > 'fasiintf.c' &&
  2271. X/*+-------------------------------------------------------------------------
  2272. X    fasiintf.c - FAS/i interface
  2273. X    wht@n4hgf.Mt-Park.GA.US
  2274. X
  2275. X  Defined functions:
  2276. X    display_fasi(fip)
  2277. X    fasi_breaks_detected()
  2278. X    fasi_line_errors()
  2279. X    fasi_msr()
  2280. X    fasi_rings_detected()
  2281. X    icmd_fasi(narg,arg)
  2282. X    ier_text(ier)
  2283. X    lcr_text(lcr)
  2284. X    mcr_text(mcr)
  2285. X    msr_text(msr)
  2286. X    pcmd_fasi(param)
  2287. X
  2288. X--------------------------------------------------------------------------*/
  2289. X/*+:EDITS:*/
  2290. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  2291. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  2292. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  2293. X/*:04-29-1991-18:52-wht@n4hgf-FAS/i 2.08.0 official release */
  2294. X/*:12-24-1990-00:51-wht-creation */
  2295. X
  2296. X#include "ecu.h"
  2297. X
  2298. X#if    defined(FASI)
  2299. X#include "ecuerror.h"
  2300. X#include "esd.h"
  2301. X#if defined(NULL)
  2302. X#undef NULL
  2303. X#endif
  2304. X# include <local/fas.h>
  2305. X
  2306. Xextern int proctrace;
  2307. X
  2308. X/*+-------------------------------------------------------------------------
  2309. X    msr_text(msr)
  2310. X--------------------------------------------------------------------------*/
  2311. Xchar *
  2312. Xmsr_text(msr)
  2313. Xuchar msr;
  2314. X{
  2315. X    static char txt[50];
  2316. X
  2317. X    txt[0] = '*';
  2318. X    txt[1] = 0;
  2319. X    if(!msr)
  2320. X    {
  2321. X        strcat(txt,"NULL*");
  2322. X        return(txt);
  2323. X    }
  2324. X    if(msr & MS_CTS_DELTA) strcat(txt,"dCTS*");
  2325. X    if(msr & MS_DSR_DELTA) strcat(txt,"dDSR*");
  2326. X    if(msr & MS_RING_TEDGE) strcat(txt,"dRI*");
  2327. X    if(msr & MS_DCD_DELTA) strcat(txt,"dDCD*");
  2328. X    if(msr & MS_CTS_PRESENT) strcat(txt,"CTS*");
  2329. X    if(msr & MS_DSR_PRESENT) strcat(txt,"DSR*");
  2330. X    if(msr & MS_RING_PRESENT) strcat(txt,"RING*");
  2331. X    if(msr & MS_DCD_PRESENT) strcat(txt,"DCD*");
  2332. SHAR_EOF
  2333. true || echo 'restore of fasiintf.c failed'
  2334. fi
  2335. echo 'End of ecu320 part 15'
  2336. echo 'File fasiintf.c is continued in part 16'
  2337. echo 16 > _shar_seq_.tmp
  2338. exit 0
  2339.  
  2340. exit 0 # Just in case...
  2341.