home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume21 / ecu / part08 < prev    next >
Text File  |  1991-08-05  |  55KB  |  2,152 lines

  1. Newsgroups: comp.sources.misc
  2. From: Warren Tucker <wht@n4hgf.Mt-Park.GA.US>
  3. Subject:  v21i060:  ecu - ECU async comm package rev 3.10, Part08/37
  4. Message-ID: <1991Aug3.033806.28412@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 6557e4b0a5675290240c8313ff7925ce
  6. Date: Sat, 3 Aug 1991 03:38:06 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Warren Tucker <wht@n4hgf.Mt-Park.GA.US>
  10. Posting-number: Volume 21, Issue 60
  11. Archive-name: ecu/part08
  12. Supersedes: ecu3: Volume 16, Issue 25-59
  13. Environment: SCO, XENIX, ISC
  14.  
  15. ---- Cut Here and feed the following to sh ----
  16. #!/bin/sh
  17. # this is ecu310.08 (part 8 of ecu310)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file ecuphone.c continued
  20. #
  21. if touch 2>&1 | fgrep 'amc' > /dev/null
  22.  then TOUCH=touch
  23.  else TOUCH=true
  24. fi
  25. if test ! -r _shar_seq_.tmp; then
  26.     echo 'Please unpack part 1 first!'
  27.     exit 1
  28. fi
  29. (read Scheck
  30.  if test "$Scheck" != 8; then
  31.     echo Please unpack part "$Scheck" next!
  32.     exit 1
  33.  else
  34.     exit 0
  35.  fi
  36. ) < _shar_seq_.tmp || exit 1
  37. if test ! -f _shar_wnt_.tmp; then
  38.     echo 'x - still skipping ecuphone.c'
  39. else
  40. echo 'x - continuing file ecuphone.c'
  41. sed 's/^X//' << 'SHAR_EOF' >> 'ecuphone.c' &&
  42. X            case 'c': pde_cmd_change_dir(); break;
  43. X
  44. X            case 'w': pde_cmd_set_wait(); break;
  45. X
  46. X            case CRET:
  47. X            case NL:
  48. X                cmd = NL;
  49. X                if(!check_curr_pde())
  50. X                    break;
  51. X                pde_list_save_if_dirty();
  52. X                windows_end(dirw);
  53. X                dirw = (WINDOW *)0;
  54. X                scrw = (WINDOW *)0;
  55. X                pde_dial_cycle();
  56. X                done = 1;
  57. X                if(rcvr_was_active)
  58. X                    start_rcvr_process(1);
  59. X                break;
  60. X
  61. X            case ESC:
  62. X            case CTL_C:
  63. X                cmd = 'q';
  64. X            case 'q':
  65. X                done = 1;
  66. X                continue;
  67. X
  68. X            case '/':
  69. X            case 'f': pde_cmd_find(); break;
  70. X
  71. X            case 'r': pde_cmd_remove(); break;
  72. X            case 'o': pde_cmd_remove_oops(); break;
  73. X
  74. X            case 'a': pde_cmd_add((PDE *)0); break;
  75. X
  76. X            case 'e': pde_add_or_edit(curr_pde,1); break;
  77. X
  78. X            case CTL_L:
  79. X            case CTL_R:
  80. X                touchwin(stdscr);
  81. X                wrefresh(stdscr);
  82. X                touchwin(dirw);
  83. X                wrefresh(dirw);
  84. X                touchwin(scrw);
  85. X                wrefresh(scrw);
  86. X                break;
  87. X
  88. X            default:
  89. X                sprintf(s80,"invalid command: %s",
  90. X                    (cmd < 0x80) ? make_char_graphic(cmd,0) : "?");
  91. X                ring_bell();
  92. X                dirw_bot_msg(s80);
  93. X                break;
  94. X        }
  95. X    }
  96. X    sigint = 0;
  97. X    if(cmd == NL)
  98. X        return;
  99. X
  100. X    pde_list_save_if_dirty();
  101. X    windows_end(dirw);
  102. X    dirw = (WINDOW *)0;
  103. X    scrw = (WINDOW *)0;
  104. X    redisplay_rcvr_screen();
  105. X    if(rcvr_was_active)
  106. X        start_rcvr_process(0);
  107. X}    /* end of pde_list_manager */
  108. X
  109. X/*+-------------------------------------------------------------------------
  110. X    copy_pde_to_lvar(tpde)
  111. X
  112. Xif changing line, close old line and open new one
  113. Xif cannot change line, return 1, else 0
  114. X--------------------------------------------------------------------------*/
  115. Xint
  116. Xcopy_pde_to_lvar(tpde)
  117. Xregister PDE *tpde;
  118. X{
  119. Xint reopen = 0;
  120. Xint lerr;
  121. X
  122. X    if((tpde->tty[0] == '=') || (tpde->tty[0] == '/')) /* Devices device type */
  123. X    {
  124. X        if(choose_device(tpde->tty,tpde->baud))
  125. X        {
  126. X            sprintf(errmsg,"no idle line matches type '%s'",tpde->tty);
  127. X            return(1);
  128. X        }
  129. X    }
  130. X    else if(tpde->tty[0])
  131. X    {
  132. X        if(shm->Lline[0] && shm->Lline[8] && strcmp(tpde->tty,shm->Lline + 8))
  133. X        {
  134. X            reopen = 1;
  135. X            shm->Lmodem_already_init = 0;
  136. X            lclose();
  137. X        }
  138. X        strcpy(shm->Lline,"/dev/tty");
  139. X        strcat(shm->Lline,tpde->tty);
  140. X    }
  141. X    else    /* "Any" */
  142. X        choose_line(tpde->baud);
  143. X
  144. X    if(shm->Liofd < 0)
  145. X        reopen = 1;
  146. X    strcpy(shm->Llogical,tpde->logical);
  147. X    strcpy(shm->Ldescr,tpde->descr);
  148. X    strcpy(shm->Ltelno,tpde->telno);
  149. X    Ldial_debug_level = tpde->debug_level;
  150. X    if(!shm->Ldescr[0])
  151. X        strcpy(shm->Ldescr,shm->Llogical);
  152. X    shm->Lparity = tpde->parity;
  153. X    if(shm->Lbaud != tpde->baud)
  154. X        shm->Lmodem_already_init = 0;
  155. X    shm->Lbaud =tpde->baud;    
  156. X    if(reopen)
  157. X    {
  158. X        if(lerr = lopen())
  159. X        {
  160. X            tcap_curbotleft();
  161. X            pprintf("%s: %s\n",shm->Lline,lopen_err_text(lerr));
  162. X            termecu(TERMECU_LINE_OPEN_ERROR);
  163. X        }
  164. X    }
  165. X    else
  166. X    {
  167. X        lset_baud_rate(1);
  168. X        lset_parity(1);
  169. X    }
  170. X    return(0);
  171. X
  172. X}    /* end of copy_pde_to_lvar */
  173. X
  174. X/*+-----------------------------------------------------------------------
  175. X    lookup_logical_telno()
  176. X
  177. XA logical telephone number is either a symbolic identifer
  178. Xor an actual telephone number.  A symbolic identifer is a string
  179. Xwhose initial character is a letter.
  180. XAn actual telephone number begins with a numeral.
  181. X
  182. XThis function converts a logical telephone number 
  183. Xto a telephone number (suitable for dialing by a Hayes or
  184. Xcompatible modem).  It is called by command line processing
  185. Xwhen 'ecu logical-name' is specified or in response to
  186. Xa %dial logical-name.  It is not used by the curses directory
  187. Xmanager.
  188. X
  189. XIf the first character of 'shm->Llogical' is a digit, the entire
  190. Xinput string is copied to 'shm->Ltelno'.  If 'shm->Llogical' has a 
  191. Xnon-numeric first character, then the user's home directory is
  192. Xsearched for the file .ecu/phone (~/.ecu/phone). The file is a series
  193. Xof records terminated with a newline.  Each record has two or three
  194. Xfields separated by colons.  The first field is the logical telephone
  195. Xnumber and the second field is the telephone number.  The third
  196. X(optional) field contains a string to further identify the telephone
  197. Xnumber being called.
  198. X
  199. XCASE IS INSIGNIFICANT in logical entry names for this procedure
  200. X
  201. XThe function returns one of the following:
  202. X
  203. X  1        if no error occurs
  204. X  0        if not numeric phone number and logical string not found in file.
  205. X
  206. X------------------------------------------------------------------------*/
  207. Xlookup_logical_telno()
  208. X{
  209. Xregister PDE *tpde;
  210. X
  211. X/* if literal phone number, return it immediately */
  212. X    Ldial_debug_level = 0;
  213. X    if(isdigit(shm->Llogical[0]))
  214. X    {
  215. X        strcpy(shm->Ltelno,shm->Llogical);
  216. X        strcpy(shm->Ldescr,"<telephone number>");
  217. X        return(1);
  218. X    }
  219. X
  220. X/* if logical phone number */
  221. X    if(!pde_list_quan)
  222. X    {
  223. X        if(pde_list_read())
  224. X        {
  225. XNO_DIR:
  226. X            strcpy(errmsg,"phone directory empty");
  227. X            return(0);
  228. X        
  229. X        }
  230. X        if(!pde_list_quan)
  231. X            goto NO_DIR;
  232. X    }
  233. X
  234. X    if(tpde = pde_list_search(shm->Llogical,0))    /* inexact search */
  235. X        return(!copy_pde_to_lvar(tpde));
  236. X
  237. X    shm->Lrname[0] = 0;
  238. X    shm->Ltelno[0] = 0;
  239. X    shm->Ldescr[0] = 0;
  240. X    strcpy(errmsg,"entry not found in directory");
  241. X    return(0);
  242. X
  243. X}    /* end of lookup_logical_telno */
  244. X
  245. X/* end of ecuphone.c */
  246. X/* vi: set tabstop=4 shiftwidth=4: */
  247. SHAR_EOF
  248. echo 'File ecuphone.c is complete' &&
  249. $TOUCH -am 0725125691 'ecuphone.c' &&
  250. chmod 0644 ecuphone.c ||
  251. echo 'restore of ecuphone.c failed'
  252. Wc_c="`wc -c < 'ecuphone.c'`"
  253. test 51343 -eq "$Wc_c" ||
  254.     echo 'ecuphone.c: original size 51343, current size' "$Wc_c"
  255. rm -f _shar_wnt_.tmp
  256. fi
  257. # ============= ecuphrase.c ==============
  258. if test -f 'ecuphrase.c' -a X"$1" != X"-c"; then
  259.     echo 'x - skipping ecuphrase.c (File already exists)'
  260.     rm -f _shar_wnt_.tmp
  261. else
  262. > _shar_wnt_.tmp
  263. echo 'x - extracting ecuphrase.c (Text)'
  264. sed 's/^X//' << 'SHAR_EOF' > 'ecuphrase.c' &&
  265. X/*+-----------------------------------------------------------------
  266. X    ecuphrases.c - %# phrase management
  267. X    wht@n4hgf.Mt-Park.GA.US
  268. X
  269. X  Defined functions:
  270. X    phrase_help()
  271. X    phrases(nargc,nargv)
  272. X    read_phrases()
  273. X
  274. X------------------------------------------------------------------------*/
  275. X/*+:EDITS:*/
  276. X/*:07-25-1991-12:56-wht@n4hgf-ECU release 3.10 */
  277. X/*:07-17-1991-07:04-wht@n4hgf-avoid SCO UNIX nap bug */
  278. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  279. X
  280. X#include "ecu.h"
  281. X
  282. X#define P_N_QUAN    23
  283. Xchar *phrases_string[P_N_QUAN];
  284. Xchar *phrases_label[P_N_QUAN];
  285. Xint phrases_count = 0;
  286. Xint phrases_resident = 0;
  287. X
  288. X/*+-----------------------------------------------------------------------
  289. X    read_phrases()
  290. X------------------------------------------------------------------------*/
  291. Xvoid
  292. Xread_phrases()
  293. X{
  294. Xregister char *phrases_str;
  295. Xchar phrases_buf[256];
  296. Xchar phrases_buf_copy[256];
  297. Xchar *phrases_lbl;
  298. XFILE *fd_phrase;
  299. X
  300. X    if(phrases_resident)
  301. X    {
  302. X        while(phrases_count)
  303. X            free(phrases_string[--phrases_count]);
  304. X        phrases_resident = 0;
  305. X    }
  306. X
  307. X    get_home_dir(phrases_buf);
  308. X    strcat(phrases_buf,"/.ecu/phrases");
  309. X
  310. X    if( (fd_phrase = fopen(phrases_buf,"r")) == NULL)
  311. X    {
  312. X        ff(se,"\r\n");
  313. X        perror(phrases_buf);
  314. X        ff(se,"\r\n");
  315. X        ff(se,"... no phrases resident\r\n");
  316. X        return;
  317. X    }
  318. X
  319. X/* we have an open .ecu/phrase file */
  320. X    phrases_count = 0;
  321. X    while(fgets(phrases_buf,sizeof(phrases_buf),fd_phrase) != NULL)
  322. X    {
  323. X        phrases_buf[strlen(phrases_buf) - 1] = 0;
  324. X        if(strlen(phrases_buf) == 0)
  325. X            continue;
  326. X
  327. X        if(phrases_count == P_N_QUAN)
  328. X        {
  329. X            ff(se,"\r\nMaximum number of phrases %d exceeded\r\n",P_N_QUAN);
  330. X            ff(se,"rest of file ignored, starting with the following:\r\n");
  331. X            ff(se,"--> %s\r\n\r\n",phrases_buf);
  332. X            phrases_resident = 1;
  333. X            fclose(fd_phrase);
  334. X            return;
  335. X        }
  336. X        strcpy(phrases_buf_copy,phrases_buf);
  337. X        phrases_lbl = phrases_buf_copy;
  338. X        for(phrases_str = phrases_buf_copy; *phrases_str; phrases_str++)
  339. X        {
  340. X            if(*phrases_str == ':')
  341. X            {
  342. X                *phrases_str++ = 0;
  343. X                break;
  344. X            }
  345. X            if(*phrases_str == 0)
  346. X            {
  347. X                ff(se,"invalid entry `%s'\n",phrases_buf);
  348. X                continue;
  349. X            }
  350. X        }
  351. X
  352. X        if(!(phrases_string[phrases_count] = malloc(strlen(phrases_str)+2)) ||
  353. X           !(phrases_label[phrases_count] = malloc(strlen(phrases_lbl)+2)))
  354. X        {
  355. X            ff(se,"\r\nNo more memory for phrases\r\n");
  356. X            ff(se,"rest of file ignored, starting with the following:\r\n");
  357. X            ff(se,"--> %s\r\n\r\n",phrases_buf);
  358. X            phrases_resident = 1;
  359. X            fclose(fd_phrase);
  360. X            if(phrases_string[phrases_count])
  361. X                free(phrases_string[phrases_count]);
  362. X            return;
  363. X        }
  364. X        strcpy(phrases_string[phrases_count],phrases_str);
  365. X        strcpy(phrases_label[phrases_count],phrases_lbl);
  366. X        phrases_count++;
  367. X    }            /* while records left to read */
  368. X
  369. X    fclose(fd_phrase);
  370. X    phrases_resident = 1;
  371. X}    /* end of read_phrases */
  372. X
  373. X/*+-------------------------------------------------------------------------
  374. X    phrases(nargc,nargv)
  375. X--------------------------------------------------------------------------*/
  376. Xphrases(nargc,nargv)
  377. Xint nargc;
  378. Xchar **nargv;
  379. X{
  380. Xregister itmp;
  381. Xregister ichar;
  382. Xregister char *cptr;
  383. Xint old_ttymode = get_ttymode();
  384. Xextern char *phrases_string[]; 
  385. Xextern int phrases_count;
  386. Xextern int phrases_resident;
  387. Xextern int sigint;
  388. Xextern int icmd_prompt_len;
  389. X
  390. X    for(itmp = icmd_prompt_len + strlen(nargv[0]); itmp; itmp--)
  391. X        fputs("\b \b",se);
  392. X
  393. X    itmp = atoi(nargv[0]);
  394. X
  395. X    if(itmp == 0)
  396. X    {
  397. X        ff(se,"\r\n");
  398. X        read_phrases();
  399. X        if(!phrases_count)
  400. X            return(0);
  401. X        tcap_stand_out();
  402. X        ff(se,
  403. X" # |  mnemonic    |     phrase                                              ");
  404. X        tcap_stand_end();
  405. X        ff(se,"\r\n");
  406. X        for(itmp = 0; itmp < phrases_count; itmp++)
  407. X            ff(se,"%2d | %12s |  %s\r\n",itmp + 1,phrases_label[itmp],
  408. X                        phrases_string[itmp]);
  409. X        return(0);
  410. X    }
  411. X    else
  412. X        if(phrases_resident == 0)
  413. X            read_phrases();
  414. X
  415. X    if(itmp > phrases_count)
  416. X    {
  417. X        ff(se,"  unknown: %d\r\n",itmp);
  418. X        return(-1);
  419. X    }
  420. X    else
  421. X    {
  422. X        cptr = phrases_string[itmp - 1];
  423. X        ttymode(2);
  424. X        while(*cptr)
  425. X        {
  426. X            if(sigint)
  427. X                break;
  428. X
  429. X            switch(ichar = *cptr++)
  430. X            {
  431. X                case '^':
  432. X                    ichar = *cptr++;
  433. X                    if((ichar >= '@') && (ichar <= '_'))
  434. X                        lputc_paced(0,ichar & 0x1F);
  435. X                    else if(ichar == '?')
  436. X                        lputc_paced(0,0x7F);
  437. X                    else
  438. X                    {
  439. X                        switch(ichar)
  440. X                        {
  441. X                            case 0:
  442. X                                goto NULL_FOUND;
  443. X                            case 'r':
  444. X                                lputc_paced(0,'\r');
  445. X                                break;
  446. X                            case 'n':
  447. X                                lputc_paced(0,'\n');
  448. X                                break;
  449. X                            case 't':
  450. X                                lputc_paced(0,'\t');
  451. X                                break;
  452. X                            case '^':
  453. X                                lputc_paced(0,'^'); 
  454. X                                break;
  455. X                            case 'p': 
  456. X                                itmp = atoi(cptr);
  457. X                                while((*cptr >= '0') && (*cptr <= '9'))
  458. X                                    cptr++;
  459. X                                if(*cptr == '.')
  460. X                                    cptr++;
  461. X                                if(!itmp)
  462. X                                    itmp = 1;
  463. X                                nap((long)itmp * 100L);
  464. X                                break;
  465. X                            case 'a':
  466. X                                itmp = atoi(cptr);
  467. X                                while((*cptr >= '0') && (*cptr <= '9'))
  468. X                                    cptr++;
  469. X                                if(*cptr == '.')
  470. X                                    cptr++;
  471. X                                if(itmp < nargc)
  472. X                                {
  473. X                                    lputs_paced(0,nargv[itmp]);
  474. X                                    itmp = strlen(nargv[itmp]);
  475. X                                }
  476. X                                break;
  477. X                        }
  478. X                    }
  479. X                    break;
  480. X                default:
  481. X                    lputc_paced(0,ichar);
  482. X            }
  483. X        }
  484. X
  485. XNULL_FOUND:
  486. X        if(sigint)
  487. X        {
  488. X            sigint = 0;
  489. X            ff(se,"\r\n--> interrupted\r\n");
  490. X        }
  491. X
  492. X    }
  493. X
  494. X    ttymode(old_ttymode);
  495. X    return(0);
  496. X
  497. X}    /* end of phrases */
  498. X
  499. X
  500. X/*+-------------------------------------------------------------------------
  501. X    phrase_help()
  502. X--------------------------------------------------------------------------*/
  503. Xvoid
  504. Xphrase_help()
  505. X{
  506. X    ff(se,"^r == \\r    ^n == \\n   ^t == \\t  ^^ == '^'\r\n");
  507. X    ff(se,"^p#.  pause # secs\r\n");
  508. X    ff(se,"^a#.  arg number # of %%# invocation\r\n");
  509. X}    /* end of phrase_help */
  510. X/* vi: set tabstop=4 shiftwidth=4: */
  511. SHAR_EOF
  512. $TOUCH -am 0725125691 'ecuphrase.c' &&
  513. chmod 0644 ecuphrase.c ||
  514. echo 'restore of ecuphrase.c failed'
  515. Wc_c="`wc -c < 'ecuphrase.c'`"
  516. test 5615 -eq "$Wc_c" ||
  517.     echo 'ecuphrase.c: original size 5615, current size' "$Wc_c"
  518. rm -f _shar_wnt_.tmp
  519. fi
  520. # ============= ecurcvr.c ==============
  521. if test -f 'ecurcvr.c' -a X"$1" != X"-c"; then
  522.     echo 'x - skipping ecurcvr.c (File already exists)'
  523.     rm -f _shar_wnt_.tmp
  524. else
  525. > _shar_wnt_.tmp
  526. echo 'x - extracting ecurcvr.c (Text)'
  527. sed 's/^X//' << 'SHAR_EOF' > 'ecurcvr.c' &&
  528. X#define DEFENSIVE        /* lots of changes this rev: defining this
  529. X                         * will make for screwed up screen image
  530. X                         * but no core dump if nassssty bugs show up
  531. X                         */
  532. X/* #define ANSI_DEBUG */        /* debug ansi */
  533. X/* #define ANSI_DEBUG_2 */        /* debug ansi intensive output */
  534. X/* #define ANSI_DEBUG_3 */        /* debug ansi selected output */
  535. X/* #define ANSI_DEBUG_NOBUF */    /* unbufferred logging */
  536. X/* #define ANSI_DEBUG_LOGFILE    "/dev/tty2h" */
  537. X/* #define DEBUG_CURSOR */
  538. X/*+-------------------------------------------------------------------------
  539. X    ecurcvr.c - rcvr process + ANSI filter + non-ANSI<->ANSI hoop jumping
  540. X    wht@n4hgf.Mt-Park.GA.US
  541. X
  542. X  Defined functions:
  543. X    accumulate_ansi_sequence(rchar)
  544. X    ansi_CNL()
  545. X    ansi_CPL()
  546. X    ansi_CUB()
  547. X    ansi_CUD()
  548. X    ansi_CUF()
  549. X    ansi_CUP()
  550. X    ansi_CUU()
  551. X    ansi_DCH()
  552. X    ansi_DL()
  553. X    ansi_DSR()
  554. X    ansi_ECH()
  555. X    ansi_ED()
  556. X    ansi_EL()
  557. X    ansi_HPA()
  558. X    ansi_ICH()
  559. X    ansi_IL()
  560. X    ansi_SD()
  561. X    ansi_SGR()
  562. X    ansi_SU()
  563. X    ansi_VPA()
  564. X    is_ansi_terminator(rchar)
  565. X    lgetc_rcvr()
  566. X    process_ansi_sequence()
  567. X    process_rcvd_char(rchar)
  568. X    rcvd_ESC()
  569. X    rcvr()
  570. X    rcvr_log_open()
  571. X    redisplay_rcvr_screen()
  572. X    saved_cursor_restore_cursor()
  573. X    saved_cursor_save_cursor()
  574. X    spaces(buf,buflen)
  575. X    spaces_trap(code,buf,buflen)
  576. X
  577. X--------------------------------------------------------------------------*/
  578. X/*+:EDITS:*/
  579. X/*:07-25-1991-12:56-wht@n4hgf-ECU release 3.10 */
  580. X/*:07-05-1991-06:13-wht@n4hgf-SD was in baaaaadd shape */
  581. X/*:01-09-1991-22:31-wht@n4hgf-ISC port */
  582. X/*:12-26-1990-14:32-wht@n4hgf-use memset in spaces() */
  583. X/*:12-21-1990-21:06-wht@n4hgf-CUF and CUB set non-ansi cursor incorrectly */
  584. X/*:12-20-1990-16:27-wht@n4hgf-had SU and SD swapped */
  585. X/*:11-30-1990-18:39-wht@n4hgf-non-ansi console rcvr appears to be working */
  586. X/*:11-28-1990-14:13-wht@n4hgf-start non-ansi console support */
  587. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  588. X
  589. X#include "ecu.h"
  590. X#include "ecukey.h"
  591. X
  592. Xextern int errno;
  593. Xextern char rcvr_log_file[];    /* if rcvr_log!= 0,log filename */
  594. Xextern int rcvr_log;            /* rcvr log active if != 0 */
  595. Xextern FILE *rcvr_log_fp;        /* rcvr log file */
  596. Xextern int rcvr_log_raw;        /* if true, log all, else filter ctl chrs */
  597. Xextern int rcvr_log_append;        /* if true, append, else scratch */
  598. Xextern int rcvr_log_flusheach;    /* if true, flush log on each char */
  599. Xextern int rcvr_log_gen_title;
  600. X
  601. Xextern int want_bell_notify;
  602. Xextern uint tcap_LINES;    /* terminal line quantity - see ecutcap.c */
  603. Xextern uint tcap_COLS;    /* terminal column quantity - see ecutcap.c */
  604. Xextern uint LINESxCOLS;
  605. Xextern int tty_is_ansi;        /* true if TERM contains "ansi" */
  606. X
  607. Xstatic char esc = ESC;
  608. X#define MAX_ANSI_LEN    30    /* generous */
  609. Xchar ansibuf[MAX_ANSI_LEN];
  610. Xchar *ansi;
  611. Xint ansilen = 0;
  612. Xint in_ansi_accumulation = 0;
  613. X
  614. Xint saved_cursor_y;
  615. Xint saved_cursor_x;
  616. X
  617. X#define RCVR_RDQUAN        250
  618. Xchar lgetc_buf[RCVR_RDQUAN];
  619. Xchar *lgetc_ptr;
  620. Xextern int lgetc_count;
  621. Xint vmin;                /* quick copy of current vmin value */
  622. X
  623. X#ifdef ANSI_DEBUG
  624. XFILE *wfp = (FILE *)0;
  625. X#endif
  626. X
  627. Xextern int tty_is_multiscreen;
  628. Xuchar non_multiscreen_hi_map[128] =
  629. X{
  630. X/*80*/    'c','u','e','a','a','a','a','c', /* the main purpose of this ... */
  631. X/*88*/    'e','e','e','i','i','i','a','a', /* ... is to map ruling ... */
  632. X/*90*/    'e','e','a','a','a','o','u','u', /* ... characters, but as ...*/
  633. X/*98*/    'y','o','u','X','#','Y','P','f', /* ... a side effect, also map ... */
  634. X/*A0*/    'a','i','o','u','n','n','a','o', /* ... others to reasonable, ... */
  635. X/*A8*/    '?','-','-','%','%','|','<','>', /* ... near, amusing, or random ... */
  636. X/*B0*/    '#','#','#','|','+','+','+','.', /* ... printing characters as well */
  637. X/*B8*/    '.','+','|','.','\'','\'','\'','.',
  638. X/*C0*/    '`','+','+','+','-','+','+','+',
  639. X/*C8*/    '`','.','+','+','+','=','+','+',
  640. X/*D0*/    '+','+','+','`','`','.','.','+',
  641. X/*D8*/    '+','\'','.','#','_','|','|','-',
  642. X/*E0*/    'a','b','F','T','E','o','u','t',
  643. X/*E8*/    'I','0','O','o','o','o','e','n',
  644. X/*F0*/    '=','+','>','<','f','j','%','=',
  645. X/*F8*/    'o','.','.','V','n','2','*',' '
  646. X};
  647. X
  648. X/*+-------------------------------------------------------------------------
  649. X    redisplay_rcvr_screen() - redisplay logical receiver screen
  650. XAs of writing, this function is called only by the XMTR process
  651. X--------------------------------------------------------------------------*/
  652. Xvoid
  653. Xredisplay_rcvr_screen()
  654. X{
  655. Xregister uint y;
  656. Xextern int tty_not_char_special;
  657. X
  658. X
  659. X    if(tty_not_char_special)
  660. X        return;
  661. X
  662. X    setcolor(colors_current);
  663. X    tcap_stand_end();
  664. X    for(y = 0; y < tcap_LINES; y++)
  665. X    {
  666. X        tcap_cursor(y,0);
  667. X        fwrite(&shm->screen[y][0],
  668. X            ((y != tcap_LINES - 1) ? tcap_COLS : tcap_COLS - 1),1,se);
  669. X    }
  670. X    tcap_eeol();
  671. X    tcap_cursor(shm->cursor_y,shm->cursor_x);
  672. X
  673. X}    /* end of redisplay_rcvr_screen */
  674. X
  675. X#ifdef DEBUG_CURSOR
  676. Xvoid
  677. Xspaces_trap(code,buf,buflen)
  678. Xint code;
  679. Xregister uchar *buf;
  680. Xregister uint buflen;
  681. X{
  682. Xchar *xyz = (char *)0x90000000;
  683. X    ff(se,"rcvr 'spaces trap' code %d: cursor x,y=%d,%d\r\n",
  684. X        code,
  685. X        shm->cursor_y,shm->cursor_x);
  686. X    ff(se,"buf=%08lx len=%08lx offs=%08lx\r\n",buf,buflen,
  687. X        (ulong)buf - (ulong)shm->screen);
  688. X    *xyz = 0;
  689. X    abort();
  690. X}
  691. X#endif
  692. X
  693. X/*+-------------------------------------------------------------------------
  694. X    spaces(buf,buflen) - fill with spaces
  695. X--------------------------------------------------------------------------*/
  696. Xvoid
  697. Xspaces(buf,buflen)
  698. Xregister uchar *buf;
  699. Xuint buflen;
  700. X{
  701. X#ifdef DEBUG_CURSOR
  702. X    if((ulong)buf > (((ulong)shm->screen) + LINESxCOLS))
  703. X        spaces_trap(1,buf,buflen);
  704. X    if((ulong)buf < (ulong)shm->screen)
  705. X        spaces_trap(2,buf,buflen);
  706. X    if((ulong)(buf + buflen) > (((ulong)shm->screen) + LINESxCOLS))
  707. X        spaces_trap(3,buf,buflen);
  708. X    if((ulong)(buf + buflen) < (ulong)shm->screen)
  709. X        spaces_trap(4,buf,buflen);
  710. X#endif
  711. X
  712. X    if(!buflen)
  713. X        return;
  714. X
  715. X#ifdef DEFENSIVE
  716. X    if((ulong)buf < (ulong)shm->screen)
  717. X        return;
  718. X    if((ulong)(buf + buflen) > (((ulong)shm->screen) + LINESxCOLS))
  719. X        return;
  720. X#endif
  721. X
  722. X    memset(buf,SPACE,buflen);
  723. X
  724. X}    /* end of spaces */
  725. X
  726. X/*+-------------------------------------------------------------------------
  727. X    lgetc_rcvr() - rcvr version of get char from line
  728. X--------------------------------------------------------------------------*/
  729. Xint
  730. Xlgetc_rcvr()
  731. X{
  732. Xextern int errno;
  733. Xchar char_rtnd;
  734. X
  735. X    if(!lgetc_count)
  736. X    {
  737. X        if(vmin == 1)
  738. X        {
  739. X            char_rtnd = lgetc_xmtr();
  740. X            return(char_rtnd);
  741. X        }
  742. X        lgetc_ptr = lgetc_buf;
  743. XREAD_AGAIN:
  744. X        errno = 0;
  745. X        if((lgetc_count =
  746. X            read(shm->Liofd,lgetc_buf,RCVR_RDQUAN)) < 0)
  747. X        {
  748. X            if(errno == EINTR)            /* if signal interrupted, ... */
  749. X                goto READ_AGAIN;
  750. X            termecu(TERMECU_LINE_READ_ERROR);
  751. X        }
  752. X        shm->rcvd_chars += lgetc_count;
  753. X        shm->rcvd_chars_this_connect += lgetc_count;
  754. X
  755. X    }
  756. X    if(!lgetc_count)
  757. X        goto READ_AGAIN;
  758. X
  759. X    lgetc_count--;
  760. X    return(*lgetc_ptr++);
  761. X}    /* end of lgetc_rcvr */
  762. X
  763. X/*+-------------------------------------------------------------------------
  764. X    ansi_SGR() - Set Graphics Rendition
  765. X
  766. XThe DOS ANSI world expects to be able to be able to chain 0,1 and
  767. X3x,4x params together with semicolons.
  768. X
  769. X  Supported modifiers for non-ansi terminals
  770. X  0       normal
  771. X  1       bold
  772. X  4       underscore
  773. X  5       blink
  774. X  7       reverse video
  775. X--------------------------------------------------------------------------*/
  776. Xvoid
  777. Xansi_SGR()
  778. X{
  779. Xregister itmp;
  780. Xregister char *cptr;
  781. Xchar SGRstr[MAX_ANSI_LEN];
  782. Xchar *token;
  783. Xchar *str_token();
  784. X
  785. X    if(!tty_is_ansi)
  786. X    {
  787. X        ansibuf[ansilen - 1] = 0;    /* get rid of 'm' */
  788. X        cptr = ansibuf + 1;            /* get rid of '[' */
  789. X        if(!strlen(cptr))
  790. X            goto SGR_0;
  791. X        while(token = str_token(cptr,";"))
  792. X        {
  793. X            cptr = (char *)0;    /* further calls to str_token need NULL */
  794. X            switch(atoi(token))
  795. X            {
  796. X                case 0:        /* normal */
  797. XSGR_0:
  798. X                    tcap_stand_end();
  799. X                    tcap_blink_off();
  800. X                    tcap_underscore_off();
  801. X                    tcap_bold_off();
  802. X                    break;
  803. X                case 1:        /* bold */
  804. X                    tcap_bold_on();
  805. X                    break;
  806. X                case 4:        /* underscore */
  807. X                    tcap_underscore_on();
  808. X                    break;
  809. X                case 5:        /* blink */
  810. X                    tcap_blink_on();
  811. X                    break;
  812. X                case 7:        /* reverse video */
  813. X                    tcap_stand_out();
  814. X                    break;
  815. X                default:
  816. X                    break;
  817. X            }
  818. X        }
  819. X        return;
  820. X    }
  821. X
  822. X    if(ansilen <= 3)    /* 'ESC[<0-9>m' and 'ESC[m' - quickly handled */
  823. X    {
  824. X        write(TTYERR,&esc,1);
  825. X        write(TTYERR,ansibuf,ansilen);
  826. X        return;
  827. X    }
  828. X
  829. X/* check XENIX 'ESC[<2,3,7>m' extensions */
  830. X    switch(itmp = atoi(ansibuf + 1))
  831. X    {
  832. X        case 7: /* XENIX 'ESC[7;<0-15>;<0-15>m' set fore/background color */
  833. X            itmp = atoi(ansibuf + 3);    /* second parameter */
  834. X            if(itmp > 15)                /* not XENIX extension */
  835. X                break;
  836. X            /* fall through */
  837. X        case 2:    /* XENIX 'ESC[2;<0-15>;<0-15>m' set fore/background color */
  838. X        case 3:    /* XENIX 'ESC[3;<0-1>m' color only set/clear blink */
  839. X            write(TTYERR,&esc,1);
  840. X            write(TTYERR,ansibuf,ansilen);
  841. X            return;
  842. X        default:
  843. X            break;
  844. X    }
  845. X
  846. X/* not XENIX extension */
  847. X    ansibuf[ansilen - 1] = 0;    /* get rid of 'm' */
  848. X    cptr = ansibuf + 1;            /* get rid of '[' */
  849. X
  850. X    while(token = str_token(cptr,";"))
  851. X    {
  852. X        cptr = (char *)0;    /* further calls to str_token need NULL */
  853. X        sprintf(SGRstr,"\033[%sm",token);
  854. X        write(TTYERR,SGRstr,strlen(SGRstr));
  855. X    }
  856. X
  857. X}    /* end of ansi_SGR */
  858. X
  859. X/*+-------------------------------------------------------------------------
  860. X    ansi_CUP() - cursor position (also HVP horiz/vertical position)
  861. X--------------------------------------------------------------------------*/
  862. Xvoid
  863. Xansi_CUP()
  864. X{
  865. Xregister uint param_count = 0;
  866. Xchar ansicopy[MAX_ANSI_LEN];
  867. Xregister char *cptr = ansicopy;
  868. Xregister char *token;
  869. Xchar *str_token();
  870. X
  871. X    strcpy(cptr,ansibuf + 1);
  872. X    *(cptr + ansilen - 2) = 0;
  873. X
  874. X    while(token = str_token(cptr,";"))
  875. X    {
  876. X        cptr = (char *)0;    /* further calls to str_token need NULL */
  877. X        switch(++param_count)
  878. X        {
  879. X            case 1:    shm->cursor_y = atoi(token) - 1; break;
  880. X            case 2:    shm->cursor_x = atoi(token) - 1; break;
  881. X        }
  882. X    }
  883. X    switch(param_count)
  884. X    {
  885. X        case 0:
  886. X            shm->cursor_y = 0;
  887. X        case 1:
  888. X            shm->cursor_x = 0;
  889. X    }
  890. X    if(shm->cursor_x >= tcap_COLS)
  891. X        shm->cursor_x = 0;
  892. X    if(shm->cursor_y >= tcap_LINES)
  893. X        shm->cursor_y = 0;
  894. X
  895. X    if(!tty_is_ansi)
  896. X        tcap_cursor(shm->cursor_y,shm->cursor_x);
  897. X
  898. X}    /* end of ansi_CUP */
  899. X
  900. X/*+-------------------------------------------------------------------------
  901. X    ansi_CUU() - cursor up
  902. X--------------------------------------------------------------------------*/
  903. Xvoid
  904. Xansi_CUU()
  905. X{
  906. Xregister uint count;
  907. Xregister uint y;
  908. X
  909. X    if(ansilen == 2)        /* no param */
  910. X        count = 1;
  911. X    else
  912. X        count = atoi(ansibuf + 1);
  913. X
  914. X    y = shm->cursor_y - count;
  915. X    if(y >= tcap_LINES)    /* unsigned comparison */
  916. X        y = 0;
  917. X
  918. X    if(y != shm->cursor_y)
  919. X    {
  920. X        shm->cursor_y = y;
  921. X        if(!tty_is_ansi)
  922. X            tcap_cursor(shm->cursor_y,shm->cursor_x);
  923. X    }
  924. X
  925. X}    /* end of ansi_CUU */
  926. X
  927. X/*+-------------------------------------------------------------------------
  928. X    ansi_CUD() - cursor down (also VPR vertical position relative)
  929. X--------------------------------------------------------------------------*/
  930. Xvoid
  931. Xansi_CUD()
  932. X{
  933. Xregister uint count;
  934. Xregister uint y;
  935. X
  936. X    if(ansilen == 2)        /* no param */
  937. X        count = 1;
  938. X    else
  939. X        count = atoi(ansibuf + 1);
  940. X
  941. X    y = shm->cursor_y + count;
  942. X    if(y >= tcap_LINES)
  943. X        y = tcap_LINES - 1;
  944. X
  945. X    if(y != shm->cursor_y)
  946. X    {
  947. X        shm->cursor_y = y;
  948. X        if(!tty_is_ansi)
  949. X            tcap_cursor(shm->cursor_y,shm->cursor_x);
  950. X    }
  951. X
  952. X}    /* end of ansi_CUD */
  953. X
  954. X/*+-------------------------------------------------------------------------
  955. X    ansi_CUF() - cursor forward (also HPR horizontal position relative)
  956. X--------------------------------------------------------------------------*/
  957. Xvoid
  958. Xansi_CUF()
  959. X{
  960. Xregister uint count;
  961. Xregister uint x;
  962. X
  963. X    if(ansilen == 2)        /* no param */
  964. X        count = 1;
  965. X    else
  966. X        count = atoi(ansibuf + 1);
  967. X
  968. X    x = shm->cursor_x + count;
  969. X    if(x >= tcap_COLS)
  970. X        x = tcap_COLS - 1;
  971. X
  972. X    if(x != shm->cursor_x)
  973. X    {
  974. X        shm->cursor_x = x;
  975. X        if(!tty_is_ansi)
  976. X            tcap_cursor(shm->cursor_y,shm->cursor_x);
  977. X    }
  978. X
  979. X}    /* end of ansi_CUF */
  980. X
  981. X/*+-------------------------------------------------------------------------
  982. X    ansi_CUB() - cursor forward
  983. X--------------------------------------------------------------------------*/
  984. Xvoid
  985. Xansi_CUB()
  986. X{
  987. Xregister uint count;
  988. Xregister uint x;
  989. X
  990. X    if(ansilen == 2)        /* no param */
  991. X        count = 1;
  992. X    else
  993. X        count = atoi(ansibuf + 1);
  994. X
  995. X    x = shm->cursor_x - count;
  996. X    if(x >= tcap_COLS)    /* unsigned comparison */
  997. X        x = 0;
  998. X
  999. X    if(x != shm->cursor_x)
  1000. X    {
  1001. X        shm->cursor_x = x;
  1002. X        if(!tty_is_ansi)
  1003. X            tcap_cursor(shm->cursor_y,shm->cursor_x);
  1004. X    }
  1005. X
  1006. X}    /* end of ansi_CUB */
  1007. X
  1008. X/*+-------------------------------------------------------------------------
  1009. X    ansi_DSR() - device status report
  1010. X--------------------------------------------------------------------------*/
  1011. Xvoid
  1012. Xansi_DSR()
  1013. X{
  1014. Xchar response[MAX_ANSI_LEN];
  1015. X
  1016. X    sprintf(response,"\033[%d;%dR",shm->cursor_y + 1,shm->cursor_x + 1);
  1017. X    write(shm->Liofd,response,strlen(response));
  1018. X
  1019. X}    /* end of ansi_DSR */
  1020. X
  1021. X/*+-------------------------------------------------------------------------
  1022. X    ansi_ED() - erase in display
  1023. X--------------------------------------------------------------------------*/
  1024. Xvoid
  1025. Xansi_ED()
  1026. X{
  1027. Xregister uint param;
  1028. Xint y;
  1029. X
  1030. X    if(ansilen == 2)        /* no param */
  1031. X        param = 0;
  1032. X    else
  1033. X        param = atoi(ansibuf + 1);
  1034. X
  1035. X    switch(param)
  1036. X    {
  1037. X        case 0:    /* erase to end of display */
  1038. X            spaces(&shm->screen[shm->cursor_y][shm->cursor_x],
  1039. X                LINESxCOLS - ((shm->cursor_y * tcap_COLS) + shm->cursor_x));
  1040. X            if(!tty_is_ansi)
  1041. X                tcap_eeod();
  1042. X            break;
  1043. X        case 1:    /* erase from beginning of display */
  1044. X            spaces((char *)shm->screen,(shm->cursor_y * tcap_COLS) +
  1045. X                shm->cursor_x);
  1046. X            if(!tty_is_ansi)
  1047. X            {
  1048. X                for(y = 0; y < shm->cursor_y - 1; y++)
  1049. X                {
  1050. X                    tcap_cursor(y,0);
  1051. X                    tcap_eeol();
  1052. X                }
  1053. X                if(shm->cursor_x)
  1054. X                {
  1055. X                    tcap_cursor(shm->cursor_y,0);
  1056. X                    tcap_clear_area_char(shm->cursor_x,' ');
  1057. X                }
  1058. X                else
  1059. X                    tcap_cursor(shm->cursor_y,shm->cursor_x);
  1060. X            }
  1061. X            break;
  1062. X        case 2:    /* clear display */
  1063. X            shm->cursor_y = 0;
  1064. X            shm->cursor_x = 0;
  1065. X            spaces((char *)shm->screen,LINESxCOLS);
  1066. X            if(!tty_is_ansi)
  1067. X            {
  1068. X                tcap_clear_screen();
  1069. X                tcap_cursor(shm->cursor_y,shm->cursor_x);
  1070. X            }
  1071. X            break;
  1072. X    }
  1073. X
  1074. X}    /* end of ansi_ED */
  1075. X
  1076. X/*+-------------------------------------------------------------------------
  1077. X    ansi_EL() - erase in line
  1078. X--------------------------------------------------------------------------*/
  1079. Xvoid
  1080. Xansi_EL()
  1081. X{
  1082. Xregister uint param;
  1083. Xchar cr = CRET;
  1084. X
  1085. X    if(ansilen == 2)        /* no param */
  1086. X        param = 0;
  1087. X    else
  1088. X        param = atoi(ansibuf + 1);
  1089. X
  1090. X    switch(param)
  1091. X    {
  1092. X        case 2:    /* clear line */
  1093. X            shm->cursor_x = 0;
  1094. X            if(!tty_is_ansi)
  1095. X                write(TTYERR,&cr,1);
  1096. X            /* fall thru */
  1097. X        case 0:    /* erase to end of line */
  1098. X            spaces(&shm->screen[shm->cursor_y][shm->cursor_x],
  1099. X                tcap_COLS - shm->cursor_x);
  1100. X            if(!tty_is_ansi)
  1101. X                tcap_eeol();
  1102. X            break;
  1103. X        case 1:    /* erase from beginning of line */
  1104. X            spaces(&shm->screen[shm->cursor_y][0],shm->cursor_x);
  1105. X            if(!tty_is_ansi && shm->cursor_x)
  1106. X            {
  1107. X                write(TTYERR,&cr,1);
  1108. X                tcap_clear_area_char(shm->cursor_x,' ');
  1109. X            }
  1110. X            break;
  1111. X    }
  1112. X
  1113. X}    /* end of ansi_EL */
  1114. X
  1115. X/*+-------------------------------------------------------------------------
  1116. X    ansi_ECH() - erase characters
  1117. X--------------------------------------------------------------------------*/
  1118. Xvoid
  1119. Xansi_ECH()
  1120. X{
  1121. Xregister uint param;
  1122. Xregister uint screen_pos;
  1123. X
  1124. X    if(ansilen == 2)        /* no param */
  1125. X        param = 1;
  1126. X    else
  1127. X        param = atoi(ansibuf + 1);
  1128. X
  1129. X    if((shm->cursor_x + param) >= tcap_COLS)
  1130. X        return;
  1131. X
  1132. X    screen_pos = (shm->cursor_y * tcap_COLS) + shm->cursor_x;
  1133. X    mem_cpy((char *)shm->screen + screen_pos,
  1134. X           (char *)shm->screen + screen_pos + param,param);
  1135. X    spaces((char *)shm->screen + ((shm->cursor_y + 1) * tcap_COLS) -
  1136. X                param,param);
  1137. X
  1138. X    if(!tty_is_ansi)
  1139. X        tcap_delete_chars(param);
  1140. X
  1141. X}    /* end of ansi_ECH */
  1142. X
  1143. X/*+-------------------------------------------------------------------------
  1144. X    ansi_SU() - scroll up (new blank lines at the bottom)
  1145. X--------------------------------------------------------------------------*/
  1146. Xvoid
  1147. Xansi_SU()
  1148. X{
  1149. Xregister uint param;
  1150. Xregister uint count;
  1151. X
  1152. X    if(ansilen == 2)        /* no param */
  1153. X        param = 1;
  1154. X    else
  1155. X        param = atoi(ansibuf + 1);
  1156. X
  1157. X    if(param > tcap_LINES)
  1158. X        param = tcap_LINES;
  1159. X    if(!param)
  1160. X        return;
  1161. X
  1162. X#ifdef ANSI_DEBUG_3
  1163. X    if(wfp)
  1164. X        fprintf(wfp,"SU: param=%u y,x=%d,%d\n",param,
  1165. X            shm->cursor_y,shm->cursor_x);
  1166. X#endif
  1167. X
  1168. X    count = tcap_COLS * param;
  1169. X    mem_cpy((char *)shm->screen,(char *)shm->screen + count,
  1170. X        LINESxCOLS - count);
  1171. X    spaces((char *)shm->screen + LINESxCOLS - count,count);
  1172. X
  1173. X    if(!tty_is_ansi)
  1174. X    {
  1175. X        tcap_cursor(tcap_LINES - 1,0);
  1176. X        while(param--)
  1177. X            ff(se,"\r\n");
  1178. X        tcap_cursor(shm->cursor_y,shm->cursor_x);
  1179. X    }
  1180. X
  1181. X}    /* end of ansi_SU */
  1182. X
  1183. X/*+-------------------------------------------------------------------------
  1184. X    ansi_SD() - scroll down (new blank lines at the top)
  1185. X--------------------------------------------------------------------------*/
  1186. Xvoid
  1187. Xansi_SD()
  1188. X{
  1189. Xregister uint param;
  1190. Xregister uint count;
  1191. X
  1192. X    if(ansilen == 2)        /* no param */
  1193. X        param = 1;
  1194. X    else
  1195. X        param = atoi(ansibuf + 1);
  1196. X
  1197. X    if(param > tcap_LINES)
  1198. X        param = tcap_LINES;
  1199. X    if(!param)
  1200. X        return;
  1201. X
  1202. X#ifdef ANSI_DEBUG_3
  1203. X    if(wfp)
  1204. X        fprintf(wfp,"SD: param=%u y,x=%d,%d\n",param,
  1205. X            shm->cursor_y,shm->cursor_x);
  1206. X#endif
  1207. X
  1208. X    count = tcap_COLS * param;
  1209. X    mem_cpy((char *)shm->screen,(char *)shm->screen + count,
  1210. X        LINESxCOLS - count);
  1211. X    spaces((char *)shm->screen + LINESxCOLS - count,count);
  1212. X
  1213. X    if(!tty_is_ansi)
  1214. X    {
  1215. X        tcap_cursor(0,0);
  1216. X        tcap_insert_lines(count);
  1217. X        tcap_cursor(shm->cursor_y,shm->cursor_x);
  1218. X    }
  1219. X
  1220. X}    /* end of ansi_SD */
  1221. X
  1222. X/*+-------------------------------------------------------------------------
  1223. X    ansi_HPA() - horizontal position absolute
  1224. X--------------------------------------------------------------------------*/
  1225. Xvoid
  1226. Xansi_HPA()
  1227. X{
  1228. Xregister uint param;
  1229. X
  1230. X    if(ansilen == 2)        /* no param */
  1231. X        param = 1;
  1232. X    else
  1233. X        param = atoi(ansibuf + 1);
  1234. X
  1235. X    if(param >= tcap_LINES)
  1236. X        return;
  1237. X
  1238. X    if((unsigned)(shm->cursor_x = param) >= (unsigned)tcap_COLS)
  1239. X        shm->cursor_x = tcap_COLS - 1;
  1240. X
  1241. X    if(!tty_is_ansi)
  1242. X        tcap_cursor(shm->cursor_y,shm->cursor_x);
  1243. X
  1244. X}    /* end of ansi_HPA */
  1245. X
  1246. X/*+-------------------------------------------------------------------------
  1247. X    ansi_VPA() - vertical position absolute
  1248. X--------------------------------------------------------------------------*/
  1249. Xvoid
  1250. Xansi_VPA()
  1251. X{
  1252. Xregister uint param;
  1253. X
  1254. X    if(ansilen == 2)        /* no param */
  1255. X        param = 1;
  1256. X    else
  1257. X        param = atoi(ansibuf + 1);
  1258. X
  1259. X    if(param >= tcap_COLS)
  1260. X        return;
  1261. X
  1262. X    if((unsigned)(shm->cursor_y = param) >= (unsigned)tcap_LINES)
  1263. X        shm->cursor_y = tcap_LINES - 1;
  1264. X
  1265. X    if(!tty_is_ansi)
  1266. X        tcap_cursor(shm->cursor_y,shm->cursor_x);
  1267. X
  1268. X}    /* end of ansi_VPA */
  1269. X
  1270. X/*+-------------------------------------------------------------------------
  1271. X    ansi_IL() - insert lines
  1272. X--------------------------------------------------------------------------*/
  1273. Xvoid
  1274. Xansi_IL()
  1275. X{
  1276. Xregister uint param;
  1277. Xregister uint count;
  1278. Xregister uint screen_pos;
  1279. X
  1280. X    if(ansilen == 2)        /* no param */
  1281. X        param = 1;
  1282. X    else
  1283. X        param = atoi(ansibuf + 1);
  1284. X
  1285. X    if((shm->cursor_y + param) >= tcap_LINES)
  1286. X        return;
  1287. X
  1288. X    count = tcap_COLS * param;
  1289. X    screen_pos = shm->cursor_y * tcap_COLS;
  1290. X    mem_cpy((char *)shm->screen + screen_pos + count,
  1291. X           (char *)shm->screen + screen_pos,
  1292. X           LINESxCOLS - screen_pos - count);
  1293. X    spaces((char *)shm->screen + screen_pos,count);
  1294. X
  1295. X    if(!tty_is_ansi)
  1296. X        tcap_insert_lines(param);
  1297. X
  1298. X}    /* end of ansi_IL */
  1299. X
  1300. X/*+-------------------------------------------------------------------------
  1301. X    ansi_ICH() - insert characters
  1302. X--------------------------------------------------------------------------*/
  1303. Xvoid
  1304. Xansi_ICH()
  1305. X{
  1306. Xregister uint param;
  1307. Xregister uint count;
  1308. Xregister uint screen_pos;
  1309. X
  1310. X    if(ansilen == 2)        /* no param */
  1311. X        param = 1;
  1312. X    else
  1313. X        param = atoi(ansibuf + 1);
  1314. X
  1315. X    if(param > tcap_COLS - shm->cursor_x)
  1316. X        param = tcap_COLS - shm->cursor_x;
  1317. X
  1318. X    if(!param)
  1319. X        return;
  1320. X
  1321. X    screen_pos = (shm->cursor_y * tcap_COLS) + shm->cursor_x;
  1322. X    count = tcap_COLS - shm->cursor_x - param;
  1323. X    mem_cpy((char *)shm->screen + screen_pos + param,
  1324. X           (char *)shm->screen + screen_pos,count);
  1325. X    spaces((char *)shm->screen + screen_pos,param);
  1326. X
  1327. X    if(!tty_is_ansi)
  1328. X        tcap_insert_chars(param);
  1329. X
  1330. X}    /* end of ansi_ICH */
  1331. X
  1332. X/*+-------------------------------------------------------------------------
  1333. X    ansi_DL() - delete lines
  1334. X--------------------------------------------------------------------------*/
  1335. Xvoid
  1336. Xansi_DL()
  1337. X{
  1338. Xregister uint param;
  1339. Xregister uint count;
  1340. Xregister uint screen_pos;
  1341. X
  1342. X    if(ansilen == 2)        /* no param */
  1343. X        param = 1;
  1344. X    else
  1345. X        param = atoi(ansibuf + 1);
  1346. X
  1347. X    if(param > (tcap_LINES - shm->cursor_y))
  1348. X        param = tcap_LINES - shm->cursor_y;
  1349. X
  1350. X    if(!param)
  1351. X        return;
  1352. X
  1353. X    count = tcap_COLS * param;
  1354. X    screen_pos = shm->cursor_y * tcap_COLS;
  1355. X    mem_cpy((char *)shm->screen + screen_pos,
  1356. X           (char *)shm->screen + screen_pos + count,
  1357. X            LINESxCOLS - screen_pos - count);
  1358. X    spaces((char *)shm->screen + LINESxCOLS - count,count);
  1359. X
  1360. X    if(!tty_is_ansi)
  1361. X        tcap_delete_lines(param);
  1362. X
  1363. X}    /* end of ansi_DL */
  1364. X
  1365. X/*+-------------------------------------------------------------------------
  1366. X    ansi_DCH() - delete characters
  1367. X--------------------------------------------------------------------------*/
  1368. Xvoid
  1369. Xansi_DCH()
  1370. X{
  1371. Xregister uint param;
  1372. Xregister uint count;
  1373. Xregister uint screen_pos;
  1374. X
  1375. X    if(ansilen == 2)        /* no param */
  1376. X        param = 1;
  1377. X    else
  1378. X        param = atoi(ansibuf + 1);
  1379. X
  1380. X    if(ansilen == 2)        /* no param */
  1381. X        param = 1;
  1382. X    else
  1383. X        param = atoi(ansibuf + 1);
  1384. X
  1385. X    if(param > tcap_COLS - shm->cursor_x)
  1386. X        param = tcap_COLS - shm->cursor_x;
  1387. X
  1388. X    if(!param)
  1389. X        return;
  1390. X
  1391. X    screen_pos = (shm->cursor_y * tcap_COLS) + shm->cursor_x;
  1392. X    count = tcap_COLS - shm->cursor_x - param;
  1393. X    mem_cpy((char *)shm->screen + screen_pos,
  1394. X            (char *)shm->screen + screen_pos + param,count);
  1395. X    screen_pos = ((shm->cursor_y + 1) * tcap_COLS) - param;
  1396. X    spaces((char *)shm->screen + screen_pos,param);
  1397. X
  1398. X    if(!tty_is_ansi)
  1399. X        tcap_delete_chars(param);
  1400. X
  1401. X}    /* end of ansi_DCH */
  1402. X
  1403. X/*+-------------------------------------------------------------------------
  1404. X    ansi_CPL() - cursor to previous line
  1405. X--------------------------------------------------------------------------*/
  1406. Xvoid
  1407. Xansi_CPL()
  1408. X{
  1409. Xregister uint param;
  1410. X
  1411. X    if(ansilen == 2)        /* no param */
  1412. X        param = 1;
  1413. X    else
  1414. X        param = atoi(ansibuf + 1);
  1415. X
  1416. X    if((shm->cursor_y -= param) >= tcap_LINES)    /* unsigned comparison */
  1417. X        shm->cursor_y = 0;
  1418. X    shm->cursor_x = 0;
  1419. X
  1420. X    if(!tty_is_ansi)
  1421. X        tcap_cursor(shm->cursor_y,shm->cursor_x);
  1422. X
  1423. X}    /* end of ansi_CPL */
  1424. X
  1425. X/*+-------------------------------------------------------------------------
  1426. X    ansi_CNL() - cursor to next line
  1427. X--------------------------------------------------------------------------*/
  1428. Xvoid
  1429. Xansi_CNL()
  1430. X{
  1431. Xregister uint param;
  1432. X
  1433. X    if(ansilen == 2)        /* no param */
  1434. X        param = 1;
  1435. X    else
  1436. X        param = atoi(ansibuf + 1);
  1437. X
  1438. X    if((shm->cursor_y += param) >= tcap_LINES)
  1439. X        shm->cursor_y = tcap_LINES - 1;
  1440. X    shm->cursor_x = 0;
  1441. X
  1442. X    if(!tty_is_ansi)
  1443. X        tcap_cursor(shm->cursor_y,shm->cursor_x);
  1444. X
  1445. X}    /* end of ansi_CNL */
  1446. X
  1447. X/*+-------------------------------------------------------------------------
  1448. X    saved_cursor_save_cursor() - nice but unfortunate IBM extension
  1449. X
  1450. XI can't find this used anywhere but in the DOS world.  Supporting this
  1451. Xpair of sequences is what started this whole complex mess.
  1452. X--------------------------------------------------------------------------*/
  1453. Xvoid
  1454. Xsaved_cursor_save_cursor()
  1455. X{
  1456. X    saved_cursor_y = shm->cursor_y;
  1457. X    saved_cursor_x = shm->cursor_x;
  1458. X}    /* end of saved_cursor_save_cursor */
  1459. X
  1460. X/*+-------------------------------------------------------------------------
  1461. X    saved_cursor_restore_cursor() - nice but unfortunate IBM extension
  1462. X
  1463. XI can't find this used anywhere but in the DOS world.  Supporting this
  1464. Xpair of sequences is what started this whole complex mess.
  1465. X--------------------------------------------------------------------------*/
  1466. Xvoid
  1467. Xsaved_cursor_restore_cursor()
  1468. X{
  1469. X    shm->cursor_y = saved_cursor_y;
  1470. X    shm->cursor_x = saved_cursor_x;
  1471. X    tcap_cursor(shm->cursor_y,shm->cursor_x);
  1472. X}    /* end of saved_cursor_restore_cursor */
  1473. X
  1474. X/*+-------------------------------------------------------------------------
  1475. X    rcvd_ESC() - ESC seen-prepare to accumulate ansi sequence
  1476. X--------------------------------------------------------------------------*/
  1477. Xvoid
  1478. Xrcvd_ESC()
  1479. X{
  1480. X#ifdef ANSI_DEBUG
  1481. X    if(wfp)
  1482. X        fprintf(wfp,"ESC ");
  1483. X#endif
  1484. X
  1485. X    ansi = ansibuf;
  1486. X    ansilen = 0;
  1487. X    in_ansi_accumulation = 1;
  1488. X
  1489. X}    /* end of rcvd_ESC */
  1490. X
  1491. X/*+-------------------------------------------------------------------------
  1492. X    is_ansi_terminator(rchar) - is character terminator for ansi sequence?
  1493. X--------------------------------------------------------------------------*/
  1494. Xint
  1495. Xis_ansi_terminator(rchar)
  1496. Xregister uint rchar;
  1497. X{
  1498. X    return(isalpha(rchar) || (rchar == '@'));
  1499. X}    /* end of is_ansi_terminator */
  1500. X
  1501. X/*+-------------------------------------------------------------------------
  1502. X    accumulate_ansi_sequence(rchar)
  1503. X--------------------------------------------------------------------------*/
  1504. Xvoid
  1505. Xaccumulate_ansi_sequence(rchar)
  1506. Xuint rchar;
  1507. X{
  1508. X    if(ansilen == (MAX_ANSI_LEN - 2))
  1509. X    {
  1510. X        in_ansi_accumulation = 0;
  1511. X        return;
  1512. X    }
  1513. X
  1514. X#ifdef ANSI_DEBUG_2
  1515. X    if(wfp)
  1516. X    {
  1517. X        fprintf(wfp,"\naas: %02x %c ansilen=%d",
  1518. X            rchar,(rchar & 0x7F < SPACE) ? '.' : (rchar & 0x7F),ansilen);
  1519. X    }
  1520. X#endif
  1521. X
  1522. X    *ansi++ = (uchar)rchar;
  1523. X    *ansi   = 0;
  1524. X    ansilen++;
  1525. X
  1526. X}    /* end of accumulate_ansi_sequence */
  1527. X
  1528. X/*+-------------------------------------------------------------------------
  1529. X    process_ansi_sequence() - a full ansi sequence is to be decoded
  1530. X--------------------------------------------------------------------------*/
  1531. Xvoid
  1532. Xprocess_ansi_sequence()
  1533. X{
  1534. Xregister itmp;
  1535. X
  1536. X#ifdef ANSI_DEBUG
  1537. X    if(wfp)
  1538. X        fprintf(wfp,"\npas: len=%d '%s' y,x=%d,%d\n",ansilen,ansibuf,
  1539. X            shm->cursor_y,shm->cursor_x);
  1540. X#endif
  1541. X
  1542. X    if(!in_ansi_accumulation)
  1543. X        return;
  1544. X    in_ansi_accumulation = 0;
  1545. X
  1546. X    itmp = 1;        /* assume write needed */
  1547. X    if((ansilen > 1) && (ansibuf[1] == '='))
  1548. X        ;
  1549. X    else switch(ansibuf[ansilen - 1])
  1550. X    {
  1551. X        case '@': ansi_ICH(); break;
  1552. X        case 'A': ansi_CUU(); break;
  1553. X        case 'B': ansi_CUD(); break;
  1554. X        case 'C': ansi_CUF(); break;
  1555. X        case 'D': ansi_CUB(); break;
  1556. X        case 'E': ansi_CNL(); break;
  1557. X        case 'F': ansi_CPL(); break;
  1558. X        case 'H': ansi_CUP(); break;
  1559. X        case 'J': ansi_ED(); break;
  1560. X        case 'K': ansi_EL(); break;
  1561. X        case 'L': ansi_IL(); break;
  1562. X        case 'M': ansi_DL(); break;
  1563. X        case 'P': ansi_DCH(); break;
  1564. X        case 'S': ansi_SU(); break;
  1565. X        case 'T': ansi_SD(); break;
  1566. X        case 'X': ansi_ECH(); break;
  1567. X        case '`': ansi_HPA(); break;
  1568. X        case 'a': ansi_CUF(); break; /* HPR */
  1569. X        case 'd': ansi_VPA(); break;
  1570. X        case 'e': ansi_CUD(); break; /* VPR */
  1571. X        case 'f': ansi_CUP(); break; /* HVP */
  1572. X        case 'm': ansi_SGR(); itmp = 0; break;
  1573. X        case 'n': ansi_DSR(); itmp = 0; break;
  1574. X        case 's': saved_cursor_save_cursor(); itmp = 0; break;
  1575. X        case 'u': saved_cursor_restore_cursor(); itmp = 0; break;
  1576. X#ifdef FUTURES
  1577. X        case 'h': ansi_SM(); break;    /* Set Mode: SCO: lock keyboard
  1578. X                                     *           MSDOS: host of shit */
  1579. X        case 'i': ansi_MC(); break;    /* Media Copy: send screen to line */
  1580. X        case 'l': ansi_RM(); break;    /* Reset Mode: SCO: unlock keyboard
  1581. X                                     *             MSDOS: host of shit */
  1582. X#endif /* FUTURES */
  1583. X        default:
  1584. X            break;
  1585. X    }
  1586. X
  1587. X/* if proper ansi console and indicated, write the buffer to the screen */
  1588. X    if(tty_is_ansi && itmp)
  1589. X    {
  1590. X        write(TTYERR,&esc,1);
  1591. X        write(TTYERR,ansibuf,ansilen);
  1592. X    }
  1593. X
  1594. X#ifdef ANSI_DEBUG
  1595. X    if(wfp)
  1596. X        fprintf(wfp,"pas: new cursor y,x=%d,%d\n",shm->cursor_y,shm->cursor_x);
  1597. X#endif
  1598. X}    /* end of process_ansi_sequence */
  1599. X
  1600. X/*+-------------------------------------------------------------------------
  1601. X    rcvr_log_open()
  1602. X--------------------------------------------------------------------------*/
  1603. Xvoid
  1604. Xrcvr_log_open()
  1605. X{
  1606. X
  1607. X    if(rcvr_log)        /* if xmtr set us up for logging */
  1608. X    {
  1609. X        rcvr_log_fp = fopen(rcvr_log_file,rcvr_log_append ? "a" : "w");
  1610. X        rcvr_log_append = 1;    /* until next %log -s */
  1611. X        if(!rcvr_log_fp)
  1612. X        {
  1613. X            ff(se,"ecu RCVR: Could not open log file: %s\r\n",rcvr_log_file);
  1614. X            ff(se,"recording aborted.\r\n");
  1615. X            rcvr_log = 0;
  1616. X        }
  1617. X        else if(!rcvr_log_raw && rcvr_log_gen_title)
  1618. X        {
  1619. X        char tstr[80];
  1620. X            get_tod(2,tstr);
  1621. X            fprintf(rcvr_log_fp,"\n====> %s (%s, %s, %s) %s\n\n",
  1622. X                shm->Lrname,shm->Llogical,
  1623. X                shm->Ldescr,(shm->Ltelno[0]) ? shm->Ltelno : "NONE",tstr);
  1624. X        }
  1625. X        rcvr_log_gen_title = 0;
  1626. X    }
  1627. X}    /* end of rcvr_log_open */
  1628. X
  1629. X/*+-------------------------------------------------------------------------
  1630. X    process_rcvd_char(rchar)
  1631. X--------------------------------------------------------------------------*/
  1632. Xint
  1633. Xprocess_rcvd_char(rchar)
  1634. Xregister uint rchar;
  1635. X{
  1636. Xregister itmp;
  1637. X
  1638. X    if(shm->Lparity)
  1639. X        rchar &= 0x7F;
  1640. X
  1641. X    if(want_bell_notify == 2)
  1642. X    {
  1643. X        shmr_set_xmtr_bn_1();
  1644. X        want_bell_notify = 1;
  1645. X        bell_notify(XBELL_3T);
  1646. X    }
  1647. X    else if(rchar == 7)
  1648. X    {
  1649. X        bell_notify(XBELL_ATTENTION);
  1650. X        return(0);
  1651. X    }
  1652. X
  1653. X    if(rchar == ESC)
  1654. X    {
  1655. X        rcvd_ESC();
  1656. X        return(1);
  1657. X    }
  1658. X    else if(in_ansi_accumulation)
  1659. X    {
  1660. X        accumulate_ansi_sequence(rchar);
  1661. X        if(is_ansi_terminator(rchar))
  1662. X            process_ansi_sequence();
  1663. X        return(1);
  1664. X    }
  1665. X
  1666. X#ifdef TANDEM_ENQ_ACK    /* for my friend John Dashner at Tandem */
  1667. X    if(rchar == ENQ)
  1668. X    {
  1669. X        lputc(ACK);
  1670. X        return(0);
  1671. X    }
  1672. X#endif
  1673. X
  1674. X    if(rchar < SPACE)
  1675. X    {
  1676. X        switch(rchar)
  1677. X        {
  1678. X            case CTL_L:
  1679. X                spaces((char *)shm->screen,LINESxCOLS);
  1680. X                shm->cursor_y = 0;
  1681. X                shm->cursor_x = 0;
  1682. X                break;
  1683. X
  1684. X            case BS:
  1685. X                if(shm->cursor_x)
  1686. X                    shm->cursor_x--;
  1687. X                break;
  1688. X
  1689. X            case NL:
  1690. X                if(shm->cursor_y != tcap_LINES - 1)
  1691. X                    shm->cursor_y++;
  1692. X                else
  1693. X                {
  1694. X                    mem_cpy((char *)shm->screen,(char *)shm->screen + tcap_COLS,
  1695. X                        LINESxCOLS - tcap_COLS);
  1696. X                    spaces(&shm->screen[shm->cursor_y][0],tcap_COLS);
  1697. X                }
  1698. X                break;
  1699. X
  1700. X            case CRET:
  1701. X                shm->cursor_x = 0;
  1702. X                break;
  1703. X
  1704. X            case TAB:
  1705. X                itmp = 8 - (shm->cursor_x % 8);
  1706. X                shm->cursor_x += itmp;
  1707. X                if(shm->cursor_x >= tcap_COLS)
  1708. X                {
  1709. X                    shm->cursor_x = 0;
  1710. X                    if(++shm->cursor_y >= tcap_LINES)
  1711. X                        shm->cursor_y = tcap_LINES - 1;
  1712. X                }
  1713. X#ifdef old
  1714. X                else
  1715. X#endif
  1716. X                    spaces(&shm->screen[shm->cursor_y][shm->cursor_x],itmp);
  1717. X                break;
  1718. X        }
  1719. X    }
  1720. X    else
  1721. X    {
  1722. X        shm->screen[shm->cursor_y][shm->cursor_x++] = (uchar)rchar;
  1723. X        if(shm->cursor_x >= tcap_COLS)
  1724. X        {
  1725. X            shm->cursor_x = 0;
  1726. X            if(shm->cursor_y != tcap_LINES - 1)
  1727. X                shm->cursor_y++;
  1728. X            else
  1729. X            {
  1730. X                mem_cpy((char *)shm->screen,(char *)shm->screen + tcap_COLS,
  1731. X                    LINESxCOLS - tcap_COLS);
  1732. X                spaces(&shm->screen[shm->cursor_y][shm->cursor_x],tcap_COLS);
  1733. X            }
  1734. X        }
  1735. X    }
  1736. X
  1737. X#ifdef ANSI_DEBUG_2
  1738. X    if(wfp)
  1739. X    {
  1740. X        if((rchar & 0x7F) == NL)
  1741. X            fputs("\n",wfp);
  1742. X        else
  1743. X            fputc(((rchar & 0x7F) < SPACE) ? '.' : (rchar & 0x7F),wfp);
  1744. X    }
  1745. X#endif
  1746. X
  1747. X    if(rcvr_log && rcvr_log_fp)
  1748. X    {
  1749. X        /* if raw mode or character not excluded from "cooked" logging */
  1750. X        if(rcvr_log_raw || ((rchar >= SPACE) && (rchar <= '~')) ||
  1751. X             (rchar == NL) || (rchar == TAB))
  1752. X        {
  1753. X            LOGPUTC(rchar,rcvr_log_fp);
  1754. X        }
  1755. X        /* back if log file if not raw and char is backspace */
  1756. X        else if(!rcvr_log_raw && (rchar == BS))
  1757. X        {
  1758. X        long logpos = 0;
  1759. X            if(logpos = ftell(rcvr_log_fp))
  1760. X                fseek(rcvr_log_fp,logpos - 1,0);
  1761. X        }
  1762. X
  1763. X        if(rcvr_log_flusheach)
  1764. X            fflush(rcvr_log_fp);
  1765. X    }
  1766. X    return(0);
  1767. X
  1768. X}    /* end of process_rcvd_char */
  1769. X
  1770. X/*+-----------------------------------------------------------------------
  1771. X    rcvr() - copy characters from remote line to so (fd == 1)
  1772. X------------------------------------------------------------------------*/
  1773. Xvoid
  1774. Xrcvr()
  1775. X{
  1776. Xuchar rchar;
  1777. Xuchar nlchar = NL;
  1778. X
  1779. X#ifdef ANSI_DEBUG
  1780. Xchar s80[80];
  1781. X    wfp = fopen(ANSI_DEBUG_LOGFILE,"a");
  1782. X    if(ulindex(ANSI_DEBUG_LOGFILE,"/dev/tty") != -1)
  1783. X    {
  1784. X        sprintf(s80,"stty opost ocrnl < %s",ANSI_DEBUG_LOGFILE);
  1785. X        system(s80);
  1786. X    }
  1787. X    fprintf(wfp,"***************\n");
  1788. X#ifdef ANSI_DEBUG_NOBUF
  1789. X    setbuf(wfp,NULL);
  1790. X#endif /* ANSI_DEBUG_NOBUF */
  1791. X#endif /* ANSI_DEBUG */
  1792. X
  1793. X    lgetc_count = 0;
  1794. X    in_ansi_accumulation = 0;
  1795. X    ansi = ansibuf;
  1796. X    ansilen = 0;
  1797. X
  1798. X/* yetch - magic number gretching for lines and columns */
  1799. X    if(!tcap_LINES || !tcap_COLS)
  1800. X    {
  1801. X        tcap_LINES = 25;
  1802. X        tcap_COLS = 80;
  1803. X    }
  1804. X    if(tcap_LINES > 43)
  1805. X        tcap_LINES = 43;
  1806. X    if(tcap_COLS > 80)
  1807. X        tcap_COLS = 80;
  1808. X    LINESxCOLS = tcap_LINES * tcap_COLS;
  1809. X
  1810. X    rcvr_signals();
  1811. X    rcvr_log_open();
  1812. X
  1813. X    saved_cursor_y = shm->cursor_y;
  1814. X    saved_cursor_x = shm->cursor_x;
  1815. X
  1816. X/* receive loop - keep tight as possible! */
  1817. X    if(tty_is_multiscreen)
  1818. X    {
  1819. X        while(1)
  1820. X        {
  1821. X            rchar = lgetc_rcvr();
  1822. X
  1823. X            if(process_rcvd_char(rchar))
  1824. X                continue;
  1825. X
  1826. X            write(TTYERR,(char *)&rchar,1);
  1827. X
  1828. X            if(shm->Ladd_nl_incoming && (rchar == CRET))
  1829. X                write(TTYERR,(char *)&nlchar,1);
  1830. X        }
  1831. X    }
  1832. X    else
  1833. X    {
  1834. X        while(1)
  1835. X        {
  1836. X            rchar = lgetc_rcvr();
  1837. X
  1838. X            if(rchar >= 0x80)
  1839. X                rchar = non_multiscreen_hi_map[rchar - 0x80];
  1840. X
  1841. X            if(process_rcvd_char(rchar))
  1842. X                continue;
  1843. X
  1844. X            write(TTYERR,(char *)&rchar,1);
  1845. X
  1846. X            if(shm->Ladd_nl_incoming && (rchar == CRET))
  1847. X                write(TTYERR,(char *)&nlchar,1);
  1848. X        }
  1849. X    }
  1850. X}    /* end of rcvr */
  1851. X
  1852. X/* end of ecurcvr.c */
  1853. X/* vi: set tabstop=4 shiftwidth=4: */
  1854. SHAR_EOF
  1855. $TOUCH -am 0725125691 'ecurcvr.c' &&
  1856. chmod 0644 ecurcvr.c ||
  1857. echo 'restore of ecurcvr.c failed'
  1858. Wc_c="`wc -c < 'ecurcvr.c'`"
  1859. test 31860 -eq "$Wc_c" ||
  1860.     echo 'ecurcvr.c: original size 31860, current size' "$Wc_c"
  1861. rm -f _shar_wnt_.tmp
  1862. fi
  1863. # ============= ecuscrdump.c ==============
  1864. if test -f 'ecuscrdump.c' -a X"$1" != X"-c"; then
  1865.     echo 'x - skipping ecuscrdump.c (File already exists)'
  1866.     rm -f _shar_wnt_.tmp
  1867. else
  1868. > _shar_wnt_.tmp
  1869. echo 'x - extracting ecuscrdump.c (Text)'
  1870. sed 's/^X//' << 'SHAR_EOF' > 'ecuscrdump.c' &&
  1871. X#define MULTISCREEN_DUMP_BUG
  1872. X/*+-------------------------------------------------------------------------
  1873. X    ecuscrdump.c - screen dump
  1874. X    wht@n4hgf.Mt-Park.GA.US
  1875. X
  1876. X  Defined functions:
  1877. X    screen_dump(scrfile)
  1878. X
  1879. X--------------------------------------------------------------------------*/
  1880. X/*+:EDITS:*/
  1881. X/*:07-25-1991-12:56-wht@n4hgf-ECU release 3.10 */
  1882. X/*:07-17-1991-07:04-wht@n4hgf-avoid SCO UNIX nap bug */
  1883. X/*:12-21-1990-17:27-wht@n4hgf-non-ansi considerations */
  1884. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1885. X
  1886. X#include "ecu.h"
  1887. X#include "ecukey.h"
  1888. X#include "pc_scr.h"
  1889. X
  1890. Xextern char curr_dir[CURR_DIRSIZ];        /* current working directory */
  1891. Xextern int rcvr_pid;
  1892. Xextern uint tcap_LINES;
  1893. Xextern uint tcap_COLS;
  1894. Xextern struct termio tty_termio_at_entry;
  1895. Xextern int tty_not_char_special;
  1896. Xextern int tty_is_multiscreen;
  1897. X
  1898. Xchar screen_dump_file_name[256];
  1899. X
  1900. X/*+-------------------------------------------------------------------------
  1901. X    screen_dump(scrfile) - dump physical display contents
  1902. Xunless stdin is non-multiscreen and/or /dev/null, in which case,
  1903. Xdump rcvr virtual screen
  1904. Xif scrfile == NULL, default to ~/.ecu/screen.dump
  1905. X--------------------------------------------------------------------------*/
  1906. Xvoid
  1907. Xscreen_dump(scrfile)
  1908. Xchar *scrfile;
  1909. X{
  1910. Xuchar s133[133];
  1911. Xuchar schar;
  1912. Xregister uchar *cptr = s133;
  1913. Xuchar *sptr = (uchar *)shm->screen;
  1914. Xint srow = 0;
  1915. Xint scol = 0;
  1916. XFILE *fp;
  1917. Xstruct termio dump_tty_termio_at_entry;
  1918. Xstruct termio dump_tty_termio_current;
  1919. Xint rcvr_alive = (rcvr_pid > 0);
  1920. Xint use_ansi_MC = !(!tty_is_multiscreen || tty_not_char_special);
  1921. Xuint lines_left = tcap_LINES;
  1922. X
  1923. X    if(rcvr_alive)
  1924. X        kill_rcvr_process(SIGUSR1);
  1925. X
  1926. X    if(use_ansi_MC)
  1927. X    {
  1928. X        /* save keyboard termio at entry */
  1929. X        ioctl(TTYIN,TCGETA,(char *)&dump_tty_termio_at_entry);
  1930. X
  1931. X        /* set keyboard to termio status at staart of execution of program 
  1932. X         * plus a few mods
  1933. X         */
  1934. X
  1935. X        dump_tty_termio_current = tty_termio_at_entry;
  1936. X        dump_tty_termio_current.c_cflag &= ~(PARENB | PARODD);
  1937. X        dump_tty_termio_current.c_cflag |= CS8;
  1938. X        dump_tty_termio_current.c_iflag &= ~(ISTRIP);
  1939. X        dump_tty_termio_current.c_lflag &= ~(ICANON | ISIG | ECHO);
  1940. X        ioctl(TTYIN,TCSETAW,(char *) &dump_tty_termio_current);
  1941. X        ttyflush(2);
  1942. X    }
  1943. X
  1944. X    if(scrfile)
  1945. X        fp = fopen(scrfile,"a");
  1946. X    else
  1947. X    {
  1948. X        get_home_dir(s133);
  1949. X        strcat((char *)s133,"/.ecu/screen.dump");
  1950. X        fp = fopen((char *)s133,"a");
  1951. X    }
  1952. X    if(!fp)
  1953. X    {
  1954. X#if defined(MORSE)
  1955. X        xbell(XBELL_DONE,1);
  1956. X#else
  1957. X        ring_bell();
  1958. X        nap(50L);
  1959. X        ring_bell();
  1960. X#endif
  1961. X        return;
  1962. X    }
  1963. X
  1964. X    get_tod(2,s133);
  1965. X    fprintf(fp,"==> %s: %s (phone %s)\n",
  1966. X        s133,shm->Ldescr,(shm->Ltelno[0]) ? shm->Ltelno : "NONE");
  1967. X
  1968. X    if(use_ansi_MC)
  1969. X        write(1,"\033[2i",4);    /* spill your guts, screen */
  1970. X
  1971. X    while(1)
  1972. X    {
  1973. X        if(use_ansi_MC)
  1974. X        {
  1975. X            if(!rdchk(0))
  1976. X            {
  1977. X                nap(hzmsec * 3);
  1978. X                if(!rdchk(0))
  1979. X                    break;
  1980. X            }
  1981. X            read(0,(char *)&schar,1);
  1982. X            if(!lines_left)
  1983. X                continue;
  1984. X        }
  1985. X        else
  1986. X        {
  1987. X            if(srow == tcap_LINES)
  1988. X                break;
  1989. X            if(scol == tcap_COLS)
  1990. X            {
  1991. X                scol = 0;
  1992. X                srow++;
  1993. X                schar = NL;
  1994. X            }
  1995. X            else
  1996. X            {
  1997. X                schar = *sptr++;
  1998. X                scol++;
  1999. X            }
  2000. X        }
  2001. X
  2002. X        if((schar > 0x7E) || (schar < 0x20))
  2003. X        {
  2004. X            switch(schar)
  2005. X            {
  2006. X            case NL:
  2007. X                while((cptr > s133) && (*(cptr - 1) == ' '))
  2008. X                    cptr--;
  2009. X                *cptr++ = 0x0A;
  2010. X                *cptr = 0;
  2011. X                fputs((char *)s133,fp);
  2012. X                cptr = s133;
  2013. X                *cptr = 0;
  2014. X                --lines_left;
  2015. X                continue;
  2016. X
  2017. X            case at_TL:        
  2018. X                schar = vanilla_TL;
  2019. X                break;
  2020. X            case at_TR:
  2021. X                schar = vanilla_TR;
  2022. X                break;
  2023. X            case at_BL:        
  2024. X                schar = vanilla_BL;
  2025. X                break;
  2026. X            case at_BR:        
  2027. X                schar = vanilla_BR;
  2028. X                break;
  2029. X            case at_LT:            /* left hand T */
  2030. X                schar = vanilla_LT;
  2031. X                break;
  2032. X            case at_RT:            /* right hand T */
  2033. X                schar = vanilla_RT;
  2034. X                break;
  2035. X            case at_VR:            /* vertical rule */
  2036. X                schar = vanilla_VR;
  2037. X                break;
  2038. X            case at_HR:            /* horizontal rule */
  2039. X                schar = vanilla_HR;
  2040. X                break;
  2041. X            default:
  2042. X                schar = ' ';
  2043. X            }
  2044. X        }
  2045. X        *cptr++ = schar;
  2046. X    }
  2047. X
  2048. X    if(use_ansi_MC)
  2049. X    {
  2050. X        /* restore keyboard termio at entry */
  2051. X        ioctl(TTYIN,TCSETAW,(char *)&dump_tty_termio_at_entry);
  2052. X        ttyflush(2);
  2053. X#if defined(MULTISCREEN_DUMP_BUG)
  2054. X        /*
  2055. X         * bug in 2.3.1 sco video driver leaves "ESC[2" active;
  2056. X         * use "l" (unlock tty) a noop
  2057. X         */
  2058. X        fputs("l",stdout);
  2059. X#endif /* MULTISCREEN_DUMP_BUG */
  2060. X    }
  2061. X
  2062. X    fclose(fp);
  2063. X
  2064. X#if defined(MORSE)
  2065. X    xbell(XBELL_DONE,1);
  2066. X#else
  2067. X    ring_bell();
  2068. X#endif
  2069. X
  2070. X    if(rcvr_alive)
  2071. X        start_rcvr_process(0);
  2072. X
  2073. X}    /* end of screen_dump */
  2074. SHAR_EOF
  2075. $TOUCH -am 0725125691 'ecuscrdump.c' &&
  2076. chmod 0644 ecuscrdump.c ||
  2077. echo 'restore of ecuscrdump.c failed'
  2078. Wc_c="`wc -c < 'ecuscrdump.c'`"
  2079. test 4313 -eq "$Wc_c" ||
  2080.     echo 'ecuscrdump.c: original size 4313, current size' "$Wc_c"
  2081. rm -f _shar_wnt_.tmp
  2082. fi
  2083. # ============= ecusetup.c ==============
  2084. if test -f 'ecusetup.c' -a X"$1" != X"-c"; then
  2085.     echo 'x - skipping ecusetup.c (File already exists)'
  2086.     rm -f _shar_wnt_.tmp
  2087. else
  2088. > _shar_wnt_.tmp
  2089. echo 'x - extracting ecusetup.c (Text)'
  2090. sed 's/^X//' << 'SHAR_EOF' > 'ecusetup.c' &&
  2091. X/*+-------------------------------------------------------------------------
  2092. X    ecusetup.c -- ecu visual "argv"
  2093. X    wht@n4hgf.Mt-Park.GA.US
  2094. X
  2095. X  0000000000111111111122222222223333333333444444444455555555556666
  2096. X  0123456789012345678901234567890123456789012345678901234567890123
  2097. X00.--[ ecu rev ]-------------------------------------------------.
  2098. X01|                                                              |
  2099. X02|  Name/phone number to call: .....................            |
  2100. X03|  Telephone     ....................                          |
  2101. X04|  Description   ........................................      |
  2102. X05|                                                              |
  2103. X06|  tty: /dev/tty.....   (opened)                               | 
  2104. X07|                                                              |
  2105. X08|  duplex: .  baud: .....  parity: . (data bits .)             |
  2106. X09|  add NL to transmitted CR: .                                 |
  2107. X10|  add NL to received CR:    .                                 |
  2108. X11|                                                              |
  2109. X12|                                                              |
  2110. X13|   TAB:next ^B:prev END:proceed ^D:phone dir  ESC:quit ecu    |
  2111. X14`--------------------------------------------------------------'
  2112. X
  2113. X  Defined functions:
  2114. X    setup_display_baud()
  2115. X    setup_display_name()
  2116. X    setup_display_screen(write_lits)
  2117. X    setup_display_single_char()
  2118. X    setup_display_tty()
  2119. X    setup_line_open()
  2120. X    setup_open_status()
  2121. X    setup_screen(argv_logical)
  2122. X    setw_bot_msg(msg)
  2123. X    setw_get_single(nondelim_list)
  2124. X
  2125. X--------------------------------------------------------------------------*/
  2126. X/*+:EDITS:*/
  2127. X/*:07-25-1991-12:56-wht@n4hgf-ECU release 3.10 */
  2128. X/*:07-17-1991-07:04-wht@n4hgf-avoid SCO UNIX nap bug */
  2129. X/*:06-05-1991-18:07-wht@n4hgf-rework */
  2130. X/*:04-27-1991-01:52-wht@n4hgf-overhaul revision numbers */
  2131. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  2132. X
  2133. X#include "ecucurses.h"
  2134. X#include "patchlevel.h"
  2135. SHAR_EOF
  2136. true || echo 'restore of ecusetup.c failed'
  2137. fi
  2138. echo 'End of ecu310 part 8'
  2139. echo 'File ecusetup.c is continued in part 9'
  2140. echo 9 > _shar_seq_.tmp
  2141. exit 0
  2142. --------------------------------------------------------------------
  2143. Warren Tucker, TuckerWare emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
  2144. Hacker Extraordinaire  d' async PADs,  pods,  proteins and protocols
  2145.  
  2146. exit 0 # Just in case...
  2147. -- 
  2148. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2149. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2150. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2151. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2152.