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

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