home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume16 / ecu3 / part08 < prev    next >
Encoding:
Internet Message Format  |  1991-01-06  |  38.8 KB

  1. From: wht@n4hgf.uucp (Warren Tucker)
  2. Newsgroups: comp.sources.misc
  3. Subject: v16i032:  ECU async comm package rev 3.0, Part08/35
  4. Message-ID: <1991Jan6.051946.27628@sparky.IMD.Sterling.COM>
  5. Date: 6 Jan 91 05:19:46 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: 234c2d4f 130d17e8 627683b6 fd09c597
  8.  
  9. Submitted-by: wht@n4hgf.uucp (Warren Tucker)
  10. Posting-number: Volume 16, Issue 32
  11. Archive-name: ecu3/part08
  12.  
  13. ---- Cut Here and feed the following to sh ----
  14. #!/bin/sh
  15. # This is part 08 of ecu3
  16. if touch 2>&1 | fgrep 'amc' > /dev/null
  17.  then TOUCH=touch
  18.  else TOUCH=true
  19. fi
  20. # ============= ecutime.c ==============
  21. echo 'x - extracting ecutime.c (Text)'
  22. sed 's/^X//' << 'SHAR_EOF' > 'ecutime.c' &&
  23. X/*+-------------------------------------------------------------------------
  24. X    ecutime.c -- ecu time-related functions
  25. X    wht@n4hgf.Mt-Park.GA.US
  26. X
  27. X  Defined functions:
  28. X    epoch_secs_to_str(epoch_secs,type,buf)
  29. X    get_elapsed_time(elapsed_seconds)
  30. X    get_tod(type,buf)
  31. X
  32. X--------------------------------------------------------------------------*/
  33. X/*+:EDITS:*/
  34. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  35. X
  36. X#include <sys/types.h>
  37. X#include <time.h>
  38. X#include <sys/timeb.h>
  39. X
  40. Xstruct tm *gmtime();
  41. Xstruct tm *localtime();
  42. X
  43. X/*+-------------------------------------------------------------------------
  44. X    get_month(zflag) - month 1-12 - zflag true for UTC (Z)), else local time
  45. X--------------------------------------------------------------------------*/
  46. Xint
  47. Xget_month(zflag)
  48. Xint zflag;
  49. X{
  50. Xlong time();
  51. Xlong epoch_secs = time((long *)0);
  52. Xstruct tm *tod = (zflag) ? gmtime(&epoch_secs) : localtime(&epoch_secs);
  53. X    return(tod->tm_mon + 1);
  54. X}    /* end of get_month */
  55. X
  56. X/*+-------------------------------------------------------------------------
  57. X    get_day(zflag) - day 0-6 - zflag true for UTC (Z)), else local time
  58. X--------------------------------------------------------------------------*/
  59. Xint
  60. Xget_day(zflag)
  61. Xint zflag;
  62. X{
  63. Xlong time();
  64. Xlong epoch_secs = time((long *)0);
  65. Xstruct tm *tod = (zflag) ? gmtime(&epoch_secs) : localtime(&epoch_secs);
  66. X    return(tod->tm_wday);
  67. X}    /* end of get_day */
  68. X
  69. X/*+-----------------------------------------------------------------------
  70. X    char *epoch_secs_to_str(epoch_secs,type,buf)
  71. X
  72. X  time of day types:
  73. X    0        hh:mm
  74. X    1        hh:mm:ss
  75. X    2        mm-dd-yyyy hh:mm
  76. X    3        mm-dd-yyyy hh:mm:ss
  77. X    4        mm-dd-yyyy hh:mm:ss (UTC hh:mm)
  78. X    5        mm-dd-yyyy
  79. X    6        hh:mmZ
  80. X    7        hh:mm:ssZ
  81. X    8        mm-dd-yyyy (UTC date)
  82. X
  83. X    returns 'buf' address
  84. X
  85. X------------------------------------------------------------------------*/
  86. Xchar *
  87. Xepoch_secs_to_str(epoch_secs,type,buf)
  88. Xlong epoch_secs;
  89. Xint type;
  90. Xchar *buf;
  91. X{
  92. Xstruct tm *tod;
  93. X
  94. X
  95. X    if(type < 6)
  96. X        tod = localtime(&epoch_secs);
  97. X    else
  98. X        tod = gmtime(&epoch_secs);
  99. X
  100. X    switch(type)
  101. X    {
  102. X        default:
  103. X        case 6:
  104. X        case 0:
  105. X            sprintf(buf,"%02d:%02d",tod->tm_hour,tod->tm_min);
  106. X            if(type == 6)
  107. X                strcat(buf,"Z");
  108. X            break;
  109. X
  110. X        case 7:
  111. X        case 1:
  112. X            sprintf(buf,"%02d:%02d:%02d",tod->tm_hour,tod->tm_min,tod->tm_sec);
  113. X            if(type == 7)
  114. X                strcat(buf,"Z");
  115. X            break;
  116. X
  117. X        case 2:
  118. X            sprintf(buf,"%02d-%02d-%04d %02d:%02d",
  119. X                tod->tm_mon + 1,tod->tm_mday,tod->tm_year + 1900,
  120. X                tod->tm_hour,tod->tm_min);
  121. X            break;
  122. X
  123. X        case 3:
  124. X            sprintf(buf,"%02d-%02d-%04d %02d:%02d:%02d",
  125. X                tod->tm_mon + 1,tod->tm_mday,tod->tm_year + 1900,
  126. X                tod->tm_hour,tod->tm_min,tod->tm_sec);
  127. X            break;
  128. X
  129. X        case 4:
  130. X            sprintf(buf,"%02d-%02d-%04d %02d:%02d:%02d",
  131. X                tod->tm_mon + 1,tod->tm_mday,tod->tm_year + 1900,
  132. X                tod->tm_hour,tod->tm_min,tod->tm_sec);
  133. X            tod = gmtime(&epoch_secs);
  134. X            sprintf(&buf[strlen(buf) ]," (UTC %02d:%02d)",
  135. X                tod->tm_hour,tod->tm_min);
  136. X            break;
  137. X
  138. X        case 8:
  139. X        case 5:
  140. X            sprintf(buf,"%02d-%02d-%04d",
  141. X                tod->tm_mon + 1,tod->tm_mday,tod->tm_year + 1900);
  142. X            break;
  143. X
  144. X    }
  145. X
  146. X    return(buf);
  147. X}    /* end of epoch_secs_to_str */
  148. X
  149. X/*+-----------------------------------------------------------------------
  150. X    char *get_tod(type,buf)
  151. X
  152. X  time of day types:
  153. X    0        hh:mm
  154. X    1        hh:mm:ss
  155. X    2        mm-dd-yyyy hh:mm
  156. X    3        mm-dd-yyyy hh:mm:ss
  157. X    4        mm-dd-yyyy hh:mm:ss (UTC hh:mm)
  158. X    5        mm-dd-yyyy
  159. X    6        hh:mmZ
  160. X    7        hh:mm:ssZ
  161. X    8        mm-dd-yyyy (UTC date)
  162. X
  163. X    returns 'buf' address
  164. X
  165. X------------------------------------------------------------------------*/
  166. Xchar *
  167. Xget_tod(type,buf)
  168. Xint type;
  169. Xchar *buf;
  170. X{
  171. Xlong time();
  172. X    return(epoch_secs_to_str(time((long *)0),type,buf));
  173. X}    /* end of get_tod */
  174. X
  175. X/*+-----------------------------------------------------------------------
  176. X    char *get_elapsed_time(elapsed_seconds)
  177. X    "hh:mm:ss" returned
  178. X  static string address is returned
  179. X------------------------------------------------------------------------*/
  180. Xchar *
  181. Xget_elapsed_time(elapsed_seconds)
  182. Xlong elapsed_seconds;
  183. X{
  184. Xstatic char elapsed_time_str[40];
  185. Xlong hh,mm,ss;
  186. X
  187. X    hh = elapsed_seconds / 3600;
  188. X    elapsed_seconds -= hh * 3600;
  189. X    mm = elapsed_seconds / 60L;
  190. X    elapsed_seconds -= mm * 60L;
  191. X    ss = elapsed_seconds;
  192. X
  193. X    sprintf(elapsed_time_str,"%02ld:%02ld:%02ld",hh,mm,ss);
  194. X    return(elapsed_time_str);
  195. X}    /* end of get_elapsed_time */
  196. X
  197. X/* end of ecutime.c */
  198. X/* vi: set tabstop=4 shiftwidth=4: */
  199. SHAR_EOF
  200. $TOUCH -am 1224223490 'ecutime.c' &&
  201. chmod 0644 ecutime.c ||
  202. echo 'restore of ecutime.c failed'
  203. Wc_c="`wc -c < 'ecutime.c'`"
  204. test 4253 -eq "$Wc_c" ||
  205.     echo 'ecutime.c: original size 4253, current size' "$Wc_c"
  206. # ============= ecutty.c ==============
  207. echo 'x - extracting ecutty.c (Text)'
  208. sed 's/^X//' << 'SHAR_EOF' > 'ecutty.c' &&
  209. X/*+-------------------------------------------------------------------------
  210. X    ecutty.c - local tty (console) functions
  211. X    wht@n4hgf.Mt-Park.GA.US
  212. X
  213. X  Defined functions:
  214. X    _setcolor(clrs)
  215. X    B_to_timeout_msec(c_cflag,st_rdev)
  216. X    color_name_to_num(cname)
  217. X    get_ttymode()
  218. X    get_ttyname()
  219. X    ring_bell()
  220. X    setcolor(new_colors)
  221. X    setcolor_internal(ntokens,tokens)
  222. X    ttyflush(flush_type)
  223. X    ttygetc(xkey_ok)
  224. X    ttygets(str,maxsize,flags)
  225. X    ttygets_esd(tesd,flags,append_flag)
  226. X    ttyinit(param)
  227. X    ttymode(arg)
  228. X
  229. X--------------------------------------------------------------------------*/
  230. X/*+:EDITS:*/
  231. X/*:12-01-1990-14:33-wht@n4hgf-more non-ansi - fkey mapping with nonansi.c */
  232. X/*:11-28-1990-15:56-wht@n4hgf-add non-ansi terminal support */
  233. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  234. X
  235. X#include "ecu.h"
  236. X#include "esd.h"
  237. X#include "ecufkey.h"
  238. X#include "ecukey.h"
  239. X#include "ecuxkey.h"
  240. X#include "ecuerror.h"
  241. X#include "ecuhangup.h"
  242. X#include <sys/machdep.h>
  243. X
  244. X#define DEFINE_TTY_DATA
  245. X#include "ecutty.h"
  246. X
  247. X/*
  248. X * mapping table index to internal function code map
  249. X *
  250. X * the order of this table depends upon the pseudo-magic
  251. X * KDEk_.. codes defined in ecufkey.h
  252. X */
  253. Xuchar KDEk_to_XF[] =
  254. X{
  255. X    XF1,        /* KDEk_F1 */
  256. X    XF2,        /* KDEk_F2 */
  257. X    XF3,        /* KDEk_F3 */
  258. X    XF4,        /* KDEk_F4 */
  259. X    XF5,        /* KDEk_F5 */
  260. X    XF6,        /* KDEk_F6 */
  261. X    XF7,        /* KDEk_F7 */
  262. X    XF8,        /* KDEk_F8 */
  263. X    XF9,        /* KDEk_F9 */
  264. X    XF10,        /* KDEk_F10 */
  265. X    XF11,        /* KDEk_F11 */
  266. X    XF12,        /* KDEk_F12 */
  267. X    XFcurup,    /* KDEk_CUU */
  268. X    XFcurdn,    /* KDEk_CUD */
  269. X    XFcurlf,    /* KDEk_CUL */
  270. X    XFcurrt,    /* KDEk_CUR */
  271. X    XFcur5,        /* KDEk_CU5 */
  272. X    XFpgup,        /* KDEk_PGUP */
  273. X    XFpgdn,        /* KDEk_PGDN */
  274. X    XFend,        /* KDEk_END */
  275. X    XFins,        /* KDEk_INS */
  276. X    XFbktab,    /* KDEk_BKTAB */
  277. X    XFhome        /* KDEk_HOME */
  278. X};
  279. X
  280. Xstatic char *dole_out_rd_char = (char *)0;
  281. X
  282. Xextern int interrupt;
  283. Xextern uint tcap_LINES;
  284. Xextern uint tcap_COLS;
  285. Xextern int LINES;
  286. Xextern int COLS;
  287. X
  288. Xuint LINESxCOLS;
  289. Xint current_ttymode = 0;
  290. Xint tty_is_ansi;
  291. Xint tty_is_multiscreen;
  292. X
  293. Xstruct termio tty_termio_at_entry;
  294. Xstruct termio tty_termio_current;
  295. Xstruct stat tty_stat;
  296. Xstruct stat dn;
  297. Xstruct stat tty01;
  298. Xstruct stat ttyp0;
  299. Xstruct stat console;
  300. X
  301. Xuchar kbdeof;            /* current input EOF */
  302. Xuchar kbdeol2;            /* current secondary input EOL */
  303. Xuchar kbdeol;            /* current input EOL */
  304. Xuchar kbderase;            /* current input ERASE */
  305. Xuchar kbdintr;            /* current input INTR */
  306. Xuchar kbdkill;            /* current input KILL */
  307. Xuchar kbdquit;            /* current input QUIT */
  308. Xint echo_erase_char;    /* save users ECHOE bit */
  309. Xint echo_kill_char;        /* save users ECHOK bit */
  310. Xchar kbd_is_7bit;        /* keyboard has parity */
  311. Xlong TOmsec = 20L;        /* timeout on waiting for char after ESC */
  312. X
  313. Xulong colors_current = 0x04070A00L;
  314. Xulong colors_normal = 0x04070A00L;    /* lt_green/black red/white */
  315. Xulong colors_success = 0x07000A00L;    /* lt_green/black red/white */
  316. Xulong colors_alert = 0x0E000E00L;    /* yellow */
  317. Xulong colors_error = 0x04000400L;    /* red */
  318. Xulong colors_notify = 0x08000800L;    /* gray */
  319. X
  320. Xint use_colors = 0;        /* set by ttyinit, but default no */
  321. Xint tty_not_char_special;
  322. X
  323. Xextern char screen_dump_file_name[];
  324. X
  325. X/*+-------------------------------------------------------------------------
  326. X    B_to_timeout_msec(c_cflag,st_rdev) - CBAUD code to ESC timeout msec
  327. X--------------------------------------------------------------------------*/
  328. Xlong
  329. XB_to_timeout_msec(c_cflag,st_rdev)
  330. Xushort c_cflag;
  331. Xushort st_rdev;
  332. X{
  333. Xlong ms = 0L;
  334. X
  335. X    /* if multiscreen, 20 msec is pu-lenty */
  336. X
  337. X    if(((st_rdev & 0xFF00) == (tty01.st_rdev & 0xFF00)) ||
  338. X       ((st_rdev & 0xFF00) == (console.st_rdev & 0xFF00)) )
  339. X    {
  340. X        return(20L);
  341. X    }
  342. X
  343. X    /* baud rate fiddling */
  344. X
  345. X    switch(c_cflag & CBAUD)
  346. X    {
  347. X        /*      char times * time/char */
  348. X        case B110:    ms = 3 * 100;
  349. X        case B300:    ms = 3 * 33;
  350. X        case B600:    ms = 3 * 16;
  351. X        case B1200:    ms = 3 * 8;
  352. X        case B2400:    ms = 3 * 4;
  353. X        case B4800:    ms = 8 * 2;
  354. X        case B9600:    ms = 8 * 1;
  355. X        case EXTA:    ms = 8 * 1;
  356. X        case EXTB:    ms = 8 * 1;
  357. X    }
  358. X
  359. X
  360. X    /* make network/xterm/pty sweat, but don't make as many mistakes */
  361. X
  362. X    if(((st_rdev & 0xFF00) == (ttyp0.st_rdev & 0xFF00)) && (ms < 80L))
  363. X        ms = 80L;
  364. X    else if(ms < 20L)    /* enforce minimum time for obvious reasons + */
  365. X        ms = 20L;        /* make sure we don't incur the UNIX nap() bug */
  366. X
  367. X    return(ms);
  368. X
  369. X}    /* end of B_to_timeout_msec */
  370. X
  371. X/*+-------------------------------------------------------------------------
  372. X    color_name_to_num(cname)
  373. X--------------------------------------------------------------------------*/
  374. Xint
  375. Xcolor_name_to_num(cname)
  376. Xchar *cname;
  377. X{
  378. Xregister COLOR *color = colors;
  379. Xregister itmp;
  380. X
  381. X    while(color->name)
  382. X    {
  383. X        if((itmp = strcmp(color->name,cname)) > 0)
  384. X            return(-1);
  385. X        if(!itmp)
  386. X            return(color->num);
  387. X        color++;
  388. X    }
  389. X    return(-1);
  390. X
  391. X}    /* end of color_name_to_num */
  392. X
  393. X/*+-------------------------------------------------------------------------
  394. X    _setcolor(clrs)
  395. X--------------------------------------------------------------------------*/
  396. Xvoid
  397. X_setcolor(clrs)
  398. Xulong clrs;
  399. X{
  400. X    if(!use_colors || tty_not_char_special)
  401. X        return;
  402. X
  403. X    /* normal */
  404. X    ff(se,"\033[=%ldF\033[=%ldG",(clrs >> 8) & 0xFF,clrs & 0xFF);
  405. X
  406. X    /* reverse */
  407. X    ff(se,"\033[=%ldH\033[=%ldI",(clrs >> 24) & 0xFF,(clrs >> 16) & 0xFF);
  408. X
  409. X    colors_current = clrs;
  410. X
  411. X}    /* end of _setcolor */
  412. X
  413. X/*+-------------------------------------------------------------------------
  414. X    setcolor(new_colors)
  415. X
  416. Xrequires termcap init to have been done
  417. X--------------------------------------------------------------------------*/
  418. Xvoid
  419. Xsetcolor(new_colors)
  420. Xulong new_colors;
  421. X{
  422. X    if(tty_not_char_special)
  423. X        return;
  424. X
  425. X    if(!use_colors)
  426. X    {
  427. X        if((new_colors == colors_notify) || (new_colors == colors_alert) ||
  428. X           (new_colors == colors_error))
  429. X        {
  430. X            tcap_stand_out();
  431. X        }
  432. X        else
  433. X            tcap_stand_end();
  434. X        return;
  435. X    }
  436. X    _setcolor(new_colors);
  437. X    tcap_stand_end();
  438. X
  439. X}    /* end of setcolor */
  440. X
  441. X/*+-------------------------------------------------------------------------
  442. X    setcolor_internal(ntokens,tokens)
  443. X
  444. Xreturns 0 on success, else token number in error + 1
  445. X--------------------------------------------------------------------------*/
  446. Xint
  447. Xsetcolor_internal(ntokens,tokens)
  448. Xint ntokens;
  449. Xchar **tokens;
  450. X{
  451. Xulong fgnd;
  452. Xulong bgnd;
  453. X
  454. X    if(tty_not_char_special || !use_colors)
  455. X        return(0);
  456. X
  457. X    if(ntokens == 2)
  458. X        tokens[2] = "black";
  459. X
  460. X    if((fgnd = (ulong)color_name_to_num(tokens[1])) > 15)
  461. X        return(2);
  462. X    if((bgnd = (ulong)color_name_to_num(tokens[2])) > 15) 
  463. X        return(3);
  464. X
  465. X    if(!strcmp(tokens[0],"normal"))
  466. X    {
  467. X        colors_normal &= 0xFFFF0000L;
  468. X        colors_normal |= (fgnd << 8) | bgnd;
  469. X        setcolor(colors_normal);
  470. X    }
  471. X    else if(!strcmp(tokens[0],"reverse"))
  472. X    {
  473. X        colors_normal &= 0x0000FFFFL;
  474. X        colors_normal |= (fgnd << 24) | (bgnd << 16);
  475. X        setcolor(colors_normal);
  476. X    }
  477. X    else if(!strcmp(tokens[0],"notify"))
  478. X        colors_notify = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;
  479. X    else if(!strcmp(tokens[0],"success"))
  480. X        colors_success = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;
  481. X    else if(!strcmp(tokens[0],"alert"))
  482. X        colors_alert = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;
  483. X    else if(!strcmp(tokens[0],"error"))
  484. X        colors_error = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;
  485. X    else
  486. X        return(1);
  487. X
  488. X    return(0);
  489. X
  490. X}    /* end of setcolor_internal */
  491. X
  492. X/*+-------------------------------------------------------------------------
  493. X    read_colors_file()
  494. X--------------------------------------------------------------------------*/
  495. Xvoid
  496. Xread_colors_file()
  497. X{
  498. XFILE *fp;
  499. Xchar s128[128];
  500. X#define MAX_COLOR_TOKENS 6
  501. Xchar *tokens[MAX_COLOR_TOKENS];
  502. Xint ntokens;
  503. Xchar *cptr;
  504. Xint itmp;
  505. X
  506. X    if(tty_not_char_special)
  507. X        return;
  508. X
  509. X    get_home_dir(s128);
  510. X    strcat(s128,"/.ecu/colors");
  511. X    if(access(s128,4))
  512. X        return;
  513. X
  514. X    fp = fopen(s128,"r");
  515. X
  516. X    while(fgets(s128,sizeof(s128),fp))
  517. X    {
  518. X        if(s128[0] == '#')            /* comment? */
  519. X            continue;
  520. X        if(itmp = strlen(s128))        /* itmp = len; if > 0 ... */
  521. X        {
  522. X            itmp--;
  523. X            s128[itmp] = 0;            /* ... strip trailing NL */
  524. X        }
  525. X        cptr = s128;                /* first call to str_token, -> buff */
  526. X        while((*cptr == 0x20) || (*cptr == TAB))
  527. X            cptr++;                /* strip leading spaces */
  528. X        if(*cptr == 0)                /* if line all blank, skip it */
  529. X            continue;
  530. X
  531. X        build_str_array(s128,tokens,MAX_COLOR_TOKENS,&ntokens);
  532. X        if(ntokens < 2)
  533. X            continue;
  534. X
  535. X        setcolor_internal(ntokens,tokens);
  536. X
  537. X    }            /* while records left to ready */
  538. X    fclose(fp);
  539. X}    /* end of read_colors_file */
  540. X
  541. X/*+-------------------------------------------------------------------------
  542. X    ring_bell()
  543. X--------------------------------------------------------------------------*/
  544. Xvoid
  545. Xring_bell()
  546. X{
  547. X    if(tty_not_char_special)
  548. X        return;
  549. X
  550. X    fputc(7,se);
  551. X}    /* end of ring_bell */
  552. X
  553. X/*+-------------------------------------------------------------------------
  554. X    ttyinit(param)
  555. X--------------------------------------------------------------------------*/
  556. Xvoid
  557. Xttyinit(param)
  558. Xuchar param;
  559. X{
  560. Xint itmp;
  561. Xint monitor_type;
  562. Xchar *cptr;
  563. X
  564. X    interrupt = 0;            /* see xmtr signal handlers */
  565. X
  566. X    memset((char *)&ttyp0,0xFF,sizeof(struct stat));
  567. X    memset((char *)&console,0xFF,sizeof(struct stat));
  568. X    stat("/dev/null",&dn);
  569. X    stat("/dev/tty01",&tty01);
  570. X    stat("/dev/ttyp0",&ttyp0);
  571. X    stat("/dev/console",&console);
  572. X
  573. X    if(fstat(TTYIN,&tty_stat) || ((tty_stat.st_mode & S_IFMT) != S_IFCHR) ||
  574. X        ((dn.st_ino == tty_stat.st_ino) && (dn.st_rdev == tty_stat.st_rdev)))
  575. X    {
  576. X        tcap_LINES = LINES = 25;    /* fake necessary termcap/curses vars */
  577. X        tcap_COLS = COLS = 80;
  578. X        LINESxCOLS = tcap_LINES * tcap_COLS;
  579. X
  580. X        tty_not_char_special = 1;
  581. X        tty_is_ansi = (param == TTYINIT_FORCE_ANSI);
  582. X        tty_is_multiscreen = 0;
  583. X        return;
  584. X    }
  585. X
  586. X    /* save initial tty state */
  587. X    ioctl(TTYIN,TCGETA,(char *)&tty_termio_at_entry);
  588. X    TOmsec = B_to_timeout_msec(tty_termio_at_entry.c_cflag,tty_stat.st_rdev);
  589. X
  590. X    kbdintr =  (tty_termio_at_entry.c_cc[VINTR])
  591. X        ? (tty_termio_at_entry.c_cc[VINTR]  & 0x7F) : '\377';
  592. X    kbdquit =  (tty_termio_at_entry.c_cc[VQUIT])
  593. X        ? (tty_termio_at_entry.c_cc[VQUIT]  & 0x7F) : '\377';
  594. X    kbderase = (tty_termio_at_entry.c_cc[VERASE])
  595. X        ? (tty_termio_at_entry.c_cc[VERASE] & 0x7F) : '\377';
  596. X    kbdkill =  (tty_termio_at_entry.c_cc[VKILL])
  597. X        ? (tty_termio_at_entry.c_cc[VKILL]  & 0x7F) : '\377';
  598. X    kbdeof =   (tty_termio_at_entry.c_cc[VEOF])
  599. X        ? (tty_termio_at_entry.c_cc[VEOF]   & 0x7F) : '\04';
  600. X    kbdeol2 =  (tty_termio_at_entry.c_cc[VEOL])
  601. X        ? (tty_termio_at_entry.c_cc[VEOL]   & 0x7F) : '\377';
  602. X    kbdeol =   (tty_termio_at_entry.c_iflag & ICRNL)
  603. X        ? '\r' : '\n';
  604. X
  605. X    kbd_is_7bit = ((tty_termio_at_entry.c_cflag & PARENB) != 0);
  606. X    echo_erase_char = tty_termio_at_entry.c_lflag & ECHOE;
  607. X    echo_kill_char = tty_termio_at_entry.c_lflag & ECHOK;
  608. X    tty_termio_current = tty_termio_at_entry;
  609. X    current_ttymode = 0;
  610. X
  611. X    get_home_dir(screen_dump_file_name);
  612. X    strcat(screen_dump_file_name,"/.ecu/screen.dump");
  613. X
  614. X    cptr = (char *)0;
  615. X    if(param)
  616. X        tty_is_ansi = (param == TTYINIT_FORCE_ANSI);
  617. X    else
  618. X        tty_is_ansi = ((cptr = getenv("TERM")) && (ulindex(cptr,"ansi") != -1));
  619. X
  620. X    if(!tty_is_ansi && cptr)
  621. X        nonansi_key_read(cptr);
  622. X
  623. X/* initialize termcap */
  624. X    tcap_init();            /* read termcap strings */
  625. X
  626. X/* yetch - magic number gretching for lines and columns */
  627. X    if((tcap_LINES < 16) || (tcap_LINES > 43))
  628. X    {
  629. X        ff(se,"terminal height must be >= 16 and <= 43 lines.\r\n");
  630. X        hangup(HANGUP_USAGE);
  631. X    }
  632. X    if(tcap_COLS != 80)
  633. X    {
  634. X        ff(se,"terminal width must be 80 columns.\r\n");
  635. X        hangup(HANGUP_USAGE);
  636. X    }
  637. X    if(!tcap_LINES || !tcap_COLS)
  638. X    {
  639. X        tcap_LINES = 25;
  640. X        tcap_COLS = 80;
  641. X    }
  642. X    if(tcap_LINES > 43)
  643. X        tcap_LINES = 43;
  644. X    if(tcap_COLS > 80)
  645. X        tcap_COLS = 80;
  646. X    LINESxCOLS = tcap_LINES * tcap_COLS;
  647. X
  648. X    /*
  649. X     * use color if we are on a multiscreen and video supports it
  650. X     * also, remember whether or not we are on a multiscreen
  651. X     * (I ain't proud of this beyond being a valiant attempt)
  652. X     */
  653. X    tty_is_multiscreen = 
  654. X        ((tty_stat.st_rdev & 0xFF00) == (tty01.st_rdev & 0xFF00)) ||
  655. X        ((tty_stat.st_rdev & 0xFF00) == (console.st_rdev & 0xFF00));
  656. X    use_colors = 0;
  657. X    itmp = 0;
  658. X    if(tty_is_multiscreen &&
  659. X        ((itmp = ioctl(TTYIN,CONS_GET,&monitor_type)) >= 0) &&
  660. X        (use_colors = (monitor_type != MONO)))
  661. X    {
  662. X        read_colors_file();
  663. X        setcolor(colors_normal);
  664. X    }
  665. X    if(itmp < 0)
  666. X        tty_is_multiscreen = 0;
  667. X
  668. X}    /* end of ttyinit */
  669. X
  670. X/*+-----------------------------------------------------------------------
  671. X    ttymode(arg) -- control user console (kbd/screen)
  672. X
  673. X  Where arg ==
  674. X    0 restore attributes saved at start of execution
  675. X    1 raw mode (send xon/xoff, but do not respond to it, no ISIG/SIGINT)
  676. X    2 raw mode (same as 1 but allow keyboard interrupts)
  677. X    3 attributes at start of execution, but with echo disabled and no parity
  678. X
  679. X------------------------------------------------------------------------*/
  680. Xvoid
  681. Xttymode(arg)
  682. X{
  683. X    if(tty_not_char_special)
  684. X        return;
  685. X
  686. X    if(arg == 0)
  687. X    {
  688. X        ioctl(TTYIN,TCSETAW,(char *)&tty_termio_at_entry);
  689. X        tty_termio_current = tty_termio_at_entry;
  690. X        current_ttymode = 0;
  691. X    }
  692. X    else if((arg == 1) || (arg == 2))
  693. X    {
  694. X        tty_termio_current = tty_termio_at_entry;
  695. X
  696. X        tty_termio_current.c_cflag &= ~(PARENB | PARODD);
  697. X        tty_termio_current.c_cflag |= CS8;
  698. X
  699. X        /* don't want to honor tty xon/xoff, but pass to other end */
  700. X        tty_termio_current.c_iflag &=
  701. X            ~(INLCR | ICRNL | IGNCR | IXON | IUCLC | ISTRIP);
  702. X        tty_termio_current.c_iflag |= IXOFF;    /* this end will xon/xoff */
  703. X
  704. X        tty_termio_current.c_oflag |= OPOST;
  705. X        tty_termio_current.c_oflag &= ~(OLCUC | ONLCR | OCRNL | ONOCR | ONLRET);
  706. X
  707. X        tty_termio_current.c_lflag &= ~(ICANON | ISIG | ECHO);
  708. X        if(arg == 2)
  709. X            tty_termio_current.c_lflag |= ISIG;
  710. X
  711. X        tty_termio_current.c_cc[VMIN] = 1;
  712. X        tty_termio_current.c_cc[VTIME] = 0;
  713. X
  714. X        ioctl(TTYIN,TCSETAW,(char *)&tty_termio_current);
  715. X        current_ttymode = arg;
  716. X    }
  717. X    else if(arg == 3)
  718. X    {
  719. X        tty_termio_current = tty_termio_at_entry;
  720. X        tty_termio_current.c_cflag &= ~(PARENB | PARODD);
  721. X        tty_termio_current.c_cflag |= CS8;
  722. X        tty_termio_current.c_iflag &= ~(ISTRIP);
  723. X        tty_termio_current.c_lflag &= ~(ICANON | ISIG | ECHO);
  724. X        ioctl(TTYIN,TCSETAW,(char *)&tty_termio_current);
  725. X        current_ttymode = 3;
  726. X    }
  727. X}    /* end of ttymode */
  728. X
  729. X/*+-------------------------------------------------------------------------
  730. X    int    get_ttymode()
  731. X--------------------------------------------------------------------------*/
  732. Xint
  733. Xget_ttymode()
  734. X{
  735. X    return(current_ttymode);
  736. X}    /* end of get_ttymode */
  737. X
  738. X/*+-----------------------------------------------------------------------
  739. X    ttyflush(flush_type) -- flush tty driver input &/or output buffers
  740. X
  741. X0 == input buffer
  742. X1 == output buffer
  743. X2 == both buffers
  744. X------------------------------------------------------------------------*/
  745. Xvoid
  746. Xttyflush(flush_type)
  747. Xint flush_type;
  748. X{
  749. X    if(tty_not_char_special)
  750. X        return;
  751. X
  752. X    ioctl(TTYIN,TCXONC,(char *)0); /* stop tty output */
  753. X
  754. X#if !defined(M_I286)
  755. X    ioctl(TTYIN,TCFLSH,(char *)flush_type);
  756. X#else
  757. X    /* avoid 286 compiler warning of cast int to far ptr */
  758. X    switch(flush_type)
  759. X    {
  760. X        case 0:
  761. X            ioctl(TTYIN,TCFLSH,(char *)0); break;
  762. X        case 1:
  763. X            ioctl(TTYIN,TCFLSH,(char *)1); break;
  764. X        case 2:
  765. X            ioctl(TTYIN,TCFLSH,(char *)2); break;
  766. X    }
  767. X#endif
  768. X
  769. X    ioctl(TTYIN,TCXONC,(char *)1);    /* restart tty output */
  770. X
  771. X#if defined(M_XENIX) || defined(M_UNIX)
  772. X    dole_out_rd_char = (char *)0;    /* see ttygetc() */
  773. X#endif
  774. X
  775. X}    /* end of ttyflush */
  776. X
  777. X/*+-------------------------------------------------------------------------
  778. X    ttygetc(xkey_ok) -- get a key from the keyboard
  779. Xif UNIX or XENIX, map extended keys to sign-bit-set special value
  780. Xif xkey_ok is 0, disallow extended keys
  781. X--------------------------------------------------------------------------*/
  782. Xuint
  783. Xttygetc(xkey_ok)
  784. Xint xkey_ok;
  785. X{
  786. Xuchar ctmp;
  787. Xextern int errno;
  788. Xregister uint itmp = 0;
  789. Xstatic uchar rd_char[16];
  790. Xuchar map_nonansi_key();
  791. X
  792. X    if(tty_not_char_special)
  793. X    {
  794. X        rd_char[0] = 0;
  795. X        read(0,rd_char,1);
  796. X        return((uint)rd_char[0]);
  797. X    }
  798. X
  799. X    if(dole_out_rd_char)        /* handle (very unlikely) FAST typist */
  800. X    {
  801. X        if(itmp = *dole_out_rd_char++)
  802. X            return(itmp);
  803. X        else
  804. X            dole_out_rd_char = (char *)0;
  805. X    }
  806. X
  807. XGET_KEY:
  808. X    errno = 0;
  809. X    if(read(TTYIN,&ctmp,1) < 0)
  810. X    {
  811. X        if(errno == EINTR)
  812. X            goto GET_KEY;
  813. X        perror_errmsg("keyboard");
  814. X        hangup(HANGUP_TTYIN_READ_ERROR);
  815. X    }
  816. X
  817. X    if(kbd_is_7bit)
  818. X        ctmp &= 0x7F;
  819. X
  820. X    if(tty_is_ansi && (ctmp == ESC))    /* if escape from ansi terminal */
  821. X    {
  822. X        itmp = 0;
  823. X        nap(TOmsec);
  824. X        while((!isalpha(ctmp)) && (itmp < sizeof(rd_char) - 1))
  825. X        {
  826. X            if(rdchk(0) <= 0)
  827. X                break;
  828. X            read(TTYIN,&ctmp,1);
  829. X            if(kbd_is_7bit)
  830. X                ctmp &= 0x7F;
  831. X            if(itmp == (sizeof(rd_char) - 1))    /* do not allow overflow */
  832. X                break;
  833. X            rd_char[itmp++] = ctmp;
  834. X            nap(TOmsec);
  835. X        }
  836. X        rd_char[itmp] = 0;
  837. X        if(!itmp)                /* no subsequent chars, so ... */
  838. X            return(ESC);        /* return the escape */
  839. X        else if((itmp == 2) && (rd_char[0] == '['))
  840. X        {
  841. X            switch(rd_char[1] | 0x80)
  842. X            {
  843. X                case XFcur5:
  844. X                    screen_dump(screen_dump_file_name);
  845. X                    goto GET_KEY;
  846. X                case XFcurup: case XFcurdn: case XFcurrt: case XFcurlf:
  847. X                case XFend: case XFpgdn: case XFhome: case XFpgup: case XFins:
  848. X                case XF1: case XF2: case XF3: case XF4: case XF5: case XF6:
  849. X                case XF7: case XF8: case XF9: case XF10: case XF11: case XF12:
  850. X                case XFbktab:
  851. X                    if(xkey_ok)
  852. X                        return(rd_char[1] | 0x80);
  853. X                    /* fall thru -- xkey not allowed */
  854. X                default:
  855. X                    ring_bell();
  856. X                    goto GET_KEY;
  857. X            }
  858. X            /*NOTREACHED*/
  859. X        }
  860. X        /* not func key -- we have a FAST typist */
  861. X        dole_out_rd_char = rd_char;
  862. X        return(ESC);
  863. X    }
  864. X    else if(!tty_is_ansi && (ctmp >= 0x01) && (ctmp <= 0x1F) &&
  865. X            (ctmp != kbderase) && (ctmp != kbdkill) &&
  866. X            (ctmp != kbdeol) && (ctmp != kbdeol2) &&
  867. X            (ctmp != kbdintr) && (ctmp != kbdeof) )
  868. X    {
  869. X        rd_char[0] = ctmp;
  870. X        rd_char[itmp = 1] = 0;
  871. X        nap(TOmsec);
  872. X        while((ctmp = map_nonansi_key(rd_char,itmp)) == 255)
  873. X        {
  874. X
  875. X            if(rdchk(0) <= 0)
  876. X                break;
  877. X            read(TTYIN,&ctmp,1);
  878. X            if(kbd_is_7bit)
  879. X                ctmp &= 0x7F;
  880. X            if(itmp == (sizeof(rd_char) - 1))    /* do not allow overflow */
  881. X                break;
  882. X            rd_char[itmp++] = ctmp;
  883. X            nap(TOmsec);
  884. X        }
  885. X        rd_char[itmp] = 0;
  886. X        if((ctmp == 255) && (itmp == 1))
  887. X            return(rd_char[0]);
  888. X        else if(ctmp != 255)    /* if we got a map */
  889. X        {
  890. X            if(!xkey_ok)
  891. X            {
  892. X                ring_bell();
  893. X                goto GET_KEY;
  894. X            }
  895. X            switch(ctmp)
  896. X            {
  897. X                case KDEk_CU5:
  898. X                    screen_dump(screen_dump_file_name);
  899. X                    goto GET_KEY;
  900. X                default:
  901. X                    return(KDEk_to_XF[ctmp]);
  902. X            }
  903. X            /*NOTREACHED*/
  904. X        }
  905. X        /* not func key -- we have a FAST typist */
  906. X        dole_out_rd_char = rd_char;
  907. X        return(ctmp);
  908. X    }
  909. X    return(ctmp);
  910. X}    /* end if ttygetc */
  911. X
  912. X/*+-----------------------------------------------------------------------
  913. X    ttygets(str,maxsize,flags)
  914. X
  915. Xflags & 1 - echo cr/lf terminator
  916. Xflags & 2 - extended delimiter set (Home, End, PgUp, PgDn, CurUp, CurDn)
  917. Xflags & 4 - redisplay/edit current string
  918. X------------------------------------------------------------------------*/
  919. Xvoid
  920. Xttygets(str,maxsize,flags)
  921. Xregister char *str;
  922. Xint maxsize;
  923. Xint flags;
  924. X{
  925. Xregister inch;
  926. Xregister strcount = 0;
  927. Xregister strpos = 0;
  928. Xint insert_mode = 0;
  929. X
  930. X    --maxsize;        /* decrement for safety */
  931. X
  932. X    if(flags & 4)
  933. X    {
  934. X        strpos = strcount = strlen(str);
  935. X        fputs(str,se);
  936. X    }
  937. X
  938. X    while(1)
  939. X    {
  940. X        inch = ttygetc(1);
  941. X        if((inch == kbdintr) || (inch == ESC))
  942. X        {
  943. X            tcap_curright(strcount - strpos);
  944. X            while(strcount)
  945. X            {
  946. X                fputc(BS,se);
  947. X                fputc(SPACE,se);
  948. X                fputc(BS,se);
  949. X                strcount--;
  950. X            }
  951. X            *str       = ESC;
  952. X            *(str + 1) = 0;
  953. X            return;
  954. X        }
  955. X        else if(inch == kbdkill)
  956. X        {
  957. X            tcap_curright(strcount - strpos);
  958. X            while(strcount)
  959. X            {
  960. X                fputc(BS,se);
  961. X                fputc(SPACE,se);
  962. X                fputc(BS,se);
  963. X                strcount--;
  964. X            }
  965. X            strpos = 0;
  966. X            *str = 0;
  967. X            continue;
  968. X        }
  969. X        else if(inch == kbderase)
  970. X        {
  971. X            if(strcount)
  972. X            {
  973. X                if(strcount == strpos)
  974. X                {
  975. X                    fputc(BS,se);
  976. X                    fputc(SPACE,se);
  977. X                    fputc(BS,se);
  978. X                    strcount--,strpos--;
  979. X                }
  980. X                else
  981. X                {
  982. X                    if(!strpos)
  983. X                        continue;
  984. X                    mem_cpy(str + strpos - 1,str + strpos,strcount - strpos);
  985. X                    fputc(BS,se);
  986. X                    str[--strcount] = 0;
  987. X                    strpos--;
  988. X                    fputs(str + strpos,se);
  989. X                    fputc(' ',se);
  990. X                    tcap_curleft(strcount - strpos + 1);
  991. X                }
  992. X            }
  993. X            str[strcount] = 0;
  994. X            continue;
  995. X        }
  996. X        else if(inch == XFins)
  997. X        {
  998. X            insert_mode = !insert_mode;
  999. X            continue;
  1000. X        }
  1001. X        else if(inch == XFcurlf)
  1002. X        {
  1003. X            if(strpos)
  1004. X            {
  1005. X                strpos--;
  1006. X                tcap_curleft(1);
  1007. X            }
  1008. X            continue;
  1009. X        }
  1010. X        else if(inch == XFcurrt)
  1011. X        {
  1012. X            if(strpos < strcount)
  1013. X            {
  1014. X                strpos++;
  1015. X                tcap_curright(1);
  1016. X            }
  1017. X            continue;
  1018. X        }
  1019. X
  1020. X        if(flags & 2)    /* extended delimiter */
  1021. X        {
  1022. X            switch(inch)
  1023. X            {
  1024. X                case XFhome:
  1025. X                case XFend:
  1026. X                case XFpgup:
  1027. X                case XFpgdn:
  1028. X                case XFcurup:
  1029. X                case XFcurdn:
  1030. X                    tcap_curright(strcount - strpos);
  1031. X                    while(strcount)
  1032. X                    {
  1033. X                        fputc(BS,se);
  1034. X                        fputc(SPACE,se);
  1035. X                        fputc(BS,se);
  1036. X                        strcount--;
  1037. X                    }
  1038. X                    *str       = inch;
  1039. X                    *(str + 1) = 0;
  1040. X                    return;
  1041. X            }
  1042. X        }
  1043. X
  1044. X        switch(inch)
  1045. X        {
  1046. X            case CR:
  1047. X            case NL:
  1048. X                str[strcount] = 0;
  1049. X                tcap_curright(strcount - strpos);
  1050. X                if((flags & 1))
  1051. X                    ff(se,"\r\n");
  1052. X                return;
  1053. X
  1054. X            case CTL_L:
  1055. X            case CTL_R:
  1056. X                tcap_curright(strcount - strpos);
  1057. X                ff(se,"%s (insert mode %s)\r\n",make_char_graphic(inch,0),
  1058. X                    (insert_mode) ? "ON" : "OFF");
  1059. X                tcap_eeol();
  1060. X                fputs(str,se);
  1061. X                tcap_curleft(strcount - strpos);
  1062. X                break;
  1063. X
  1064. X            default:
  1065. X                if((inch < SPACE) || (inch >= 0x7F))
  1066. X                {
  1067. X                    ring_bell();
  1068. X                    break;
  1069. X                }
  1070. X                if(strpos == strcount)
  1071. X                {
  1072. X                    if(strcount == maxsize)
  1073. X                    {
  1074. X                        ring_bell();
  1075. X                        break;
  1076. X                    }
  1077. X                    str[strcount++] = inch & 0x7F;
  1078. X                    strpos++;
  1079. X                    fputc(inch,se);
  1080. X                }
  1081. X                else
  1082. X                {
  1083. X                    if(insert_mode)
  1084. X                    {
  1085. X                        if(strcount == maxsize)
  1086. X                        {
  1087. X                            ring_bell();
  1088. X                            break;
  1089. X                        }
  1090. X                        mem_cpy(str+strpos+1,str+strpos,strcount-strpos);
  1091. X                        str[strpos] = inch;
  1092. X                        strcount++;
  1093. X                        str[strcount] = 0;
  1094. X                        fputs(str + strpos++,se);
  1095. X                        tcap_curleft(strcount - strpos);
  1096. X                    }
  1097. X                    else
  1098. X                    {
  1099. X                        str[strpos++] = inch;
  1100. X                        fputc(inch,se);
  1101. X                    }
  1102. X                }
  1103. X                str[strcount] = 0;
  1104. X                break;
  1105. X        }
  1106. X    }            /* end of while we have room left in string */
  1107. X
  1108. X}    /* end of ttygets() */
  1109. X
  1110. X/*+-------------------------------------------------------------------------
  1111. X    ttygets_esd(tesd,flags,append_flag)
  1112. X--------------------------------------------------------------------------*/
  1113. Xttygets_esd(tesd,flags,append_flag)
  1114. XESD *tesd;
  1115. Xint flags;
  1116. Xint append_flag;
  1117. X{
  1118. Xchar *pb = tesd->pb;
  1119. Xint maxcb = tesd->maxcb;
  1120. X
  1121. X    if(append_flag)
  1122. X    {
  1123. X        pb += tesd->cb;
  1124. X        maxcb -= tesd->cb;
  1125. X    }
  1126. X    else
  1127. X    {
  1128. X        pb = tesd->pb;
  1129. X        maxcb = tesd->maxcb;
  1130. X        tesd->cb = 0;
  1131. X    }
  1132. X
  1133. X    ttygets(pb,maxcb,flags);
  1134. X
  1135. X    if(*pb == ESC)
  1136. X    {
  1137. X        if(!append_flag)
  1138. X            zero_esd(tesd);
  1139. X        return(eProcAttn_ESCAPE);
  1140. X    }
  1141. X
  1142. X    tesd->cb = strlen(tesd->pb);
  1143. X    plogs(pb);
  1144. X    if(flags & 1)
  1145. X        plogc(NL);
  1146. X    return(0);
  1147. X
  1148. X}    /* end of ttygets_esd */
  1149. X
  1150. X/*+-------------------------------------------------------------------------
  1151. X    char *get_ttyname() - return pointer to static string
  1152. X
  1153. XThis routine is largely a crock and is likely to explode at any rev or twist
  1154. X--------------------------------------------------------------------------*/
  1155. Xchar *
  1156. Xget_ttyname()
  1157. X{
  1158. X#ifndef OLD_WAY
  1159. Xchar *ttyname();
  1160. X    return(ttyname(TTYIN));
  1161. X#else
  1162. Xstatic char ttname[64];
  1163. Xregister unsigned int rdev;
  1164. Xregister char *cptr;
  1165. X
  1166. X    if(tty_not_char_special)
  1167. X        return("stdin");
  1168. X    else if(!tty_is_multiscreen)
  1169. X        return("non-multiscreen");
  1170. X
  1171. X    rdev = (unsigned)tty_stat.st_rdev;
  1172. X    if(rdev == 0x0301)
  1173. X        strcpy(ttname,"/dev/console");
  1174. X#if defined(M_UNIX)
  1175. X    else if(rdev == 0x0000)
  1176. X        strcpy(ttname,"/dev/syscon");
  1177. X#endif
  1178. X    else
  1179. X    {
  1180. X        strcpy(ttname,"/dev/tty");
  1181. X        cptr = ttname + 8;
  1182. X
  1183. X        if(rdev < 0x000C)
  1184. X        {
  1185. X            *cptr++ = '0' + ((rdev + 1) / 10);
  1186. X            *cptr++ = '0' + ((rdev + 1) % 10);
  1187. X        }
  1188. X        else if(!(rdev & ~0x58F))
  1189. X        {
  1190. X            *cptr++ = (rdev & 0x0008) ? '2' : '1';
  1191. X            *cptr++ = ((rdev & 0x0080) ? 'A' : 'a') + (rdev & 0x0007);
  1192. X        }
  1193. X        else
  1194. X        {
  1195. X            *cptr++ = '?';
  1196. X            *cptr++ = '?';
  1197. X        }
  1198. X        *cptr = 0;
  1199. X    }
  1200. X
  1201. X    return(ttname);
  1202. X#endif
  1203. X}    /* end of get_ttyname */
  1204. X
  1205. X/* end of ecutty.c */
  1206. X/* vi: set tabstop=4 shiftwidth=4: */
  1207. SHAR_EOF
  1208. $TOUCH -am 1224223490 'ecutty.c' &&
  1209. chmod 0644 ecutty.c ||
  1210. echo 'restore of ecutty.c failed'
  1211. Wc_c="`wc -c < 'ecutty.c'`"
  1212. test 23288 -eq "$Wc_c" ||
  1213.     echo 'ecutty.c: original size 23288, current size' "$Wc_c"
  1214. # ============= ecuuclc.c ==============
  1215. echo 'x - extracting ecuuclc.c (Text)'
  1216. sed 's/^X//' << 'SHAR_EOF' > 'ecuuclc.c' &&
  1217. X/*+-----------------------------------------------------------------------
  1218. X    ecuuclc.c - uuper/lower-case string functions
  1219. X    wht@n4hgf.Mt-Park.GA.US
  1220. X
  1221. X  Defined functions:
  1222. X    minunique(str1,str2,minquan)
  1223. X    to_lower(ch)
  1224. X    to_upper(ch)
  1225. X    ulcmpb(str1,str2)
  1226. X    ulindex(str1,str2)
  1227. X    ulrindex(str1,str2)
  1228. X
  1229. X------------------------------------------------------------------------*/
  1230. X/*+:EDITS:*/
  1231. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1232. X
  1233. X/*+-------------------------------------------------------------------------
  1234. X    to_upper() / to_lower()
  1235. X  one would think that these were relatively standard
  1236. X  types of thing, but MSC/Xenix specifies toupper() to convert to upper
  1237. X  case if not already and Unix says to adjust without testing,
  1238. X  so, two stupid little routines here
  1239. X  ASCII only -- no EBCDIC gradoo here please
  1240. X--------------------------------------------------------------------------*/
  1241. Xchar to_upper(ch)
  1242. Xregister char ch;
  1243. X{ return( ((ch >= 'a') && (ch <= 'z')) ? ch - 0x20 : ch);
  1244. X}   /* end of to_upper() */
  1245. X
  1246. Xchar to_lower(ch)
  1247. Xregister char ch;
  1248. X{ return( ((ch >= 'A') && (ch <= 'Z')) ? ch + 0x20 : ch);
  1249. X}   /* end of to_lower() */
  1250. X
  1251. X/*+----------------------------------------------------------------------------
  1252. X    ulcmpb(str1,str) -- Upper/Lower [case insensitive] Compare Bytes
  1253. X
  1254. X Returns -1 if strings are equal, else failing character position
  1255. X If the second strings terminates with a null and both strings have matched
  1256. X character for character until that point, then -1 is returned.
  1257. X NOTE:  this is not a test for complete equality of two strings, but allows
  1258. X discovery of a string as a substring in a larger containing string.
  1259. X-----------------------------------------------------------------------------*/
  1260. Xint
  1261. Xulcmpb(str1,str2)
  1262. Xregister unsigned char    *str1;
  1263. Xregister unsigned char    *str2;
  1264. X{
  1265. Xregister istr;
  1266. X
  1267. X    for( istr=0 ; ;  ++istr )
  1268. X    {
  1269. X        if(str2[istr] == '\0')          /* if second string exhausts, match! */
  1270. X            return(-1);
  1271. X        if((str1[istr] == '\0' ) ||
  1272. X            ( to_upper(str1[istr]) != to_upper(str2[istr]) ))
  1273. X            return(istr);
  1274. X    }
  1275. X    /*NOTREACHED*/
  1276. X} /* end of ulcmpb */
  1277. X
  1278. X/*+-------------------------------------------------------------------------
  1279. X    ulindex:  Upper/Lower [case insensitive] Index function
  1280. X
  1281. X  Returns position of 'str2' in 'str1' if found
  1282. X  If 'str2' is null, then 0 is returned (null matches anything)
  1283. X  Returns -1 if not found
  1284. X
  1285. X  uses 'ulcmpb'
  1286. X--------------------------------------------------------------------------*/
  1287. Xint
  1288. Xulindex(str1,str2)
  1289. Xregister char *str1;    /* the (target) string to search */
  1290. Xregister char *str2;    /* the (comparand) string to search for */
  1291. X{
  1292. Xregister istr1 = 0;        /* moving index into str1 */
  1293. Xregister char *mstr = str1;    /* moving string pointer */
  1294. X
  1295. X    if(str2[0] == '\0')             /* null string matches anything */
  1296. X        return(0);
  1297. X    if(strlen(str2) > strlen(str1))
  1298. X        return(-1);
  1299. X    while(1)
  1300. X    {
  1301. X        if(*mstr == '\0')           /* if we exhaust target string, flunk */
  1302. X            return(-1);
  1303. X        /* Can we find either case of first comparand char in target? */
  1304. X        if( to_upper(*mstr) == to_upper(str2[0]) )
  1305. X        {
  1306. X            /* we have a first char match... does rest of string match? */
  1307. X            if(ulcmpb(mstr,str2) == -1)         /* if the rest matches, ... */
  1308. X                return(istr1);                  /* ... return match position */
  1309. X        }
  1310. X        /* we did not match this time... increment istr1, mstr and try again */
  1311. X        ++istr1;
  1312. X        ++mstr;
  1313. X    }
  1314. X}    /* end of ulindex */
  1315. X
  1316. X/*+-------------------------------------------------------------------------
  1317. X    ulrindex:  Upper/Lower [case insensitive] Right Index function
  1318. X
  1319. X  Returns position of 'str2' in 'str1' if found
  1320. X  Returns -1 if not found
  1321. X  If 'str2' is null, then -1 is returned
  1322. X
  1323. X  uses 'ulcmpb'
  1324. X--------------------------------------------------------------------------*/
  1325. Xint
  1326. Xulrindex(str1,str2)
  1327. Xregister char *str1;    /* the (target) string to search */
  1328. Xregister char *str2;    /* the (comparand) string to search for */
  1329. X{
  1330. Xregister char *mstr;
  1331. Xregister istr1;
  1332. X
  1333. X    if(!str2[0])             /* null string matches anything */
  1334. X        return(-1);
  1335. X    if(strlen(str2) > strlen(str1))
  1336. X        return(-1);
  1337. X
  1338. X    mstr = str1 + strlen(str1) - strlen(str2);    /* moving string pointer */
  1339. X    istr1 = mstr - str1;        /* moving index into str1 */
  1340. X
  1341. X    while(mstr >= str1)
  1342. X    {
  1343. X        /* Can we find either case of first comparand char in target? */
  1344. X        if( to_upper(*mstr) == to_upper(str2[0]) )
  1345. X        {
  1346. X            /* we have a first char match... does rest of string match? */
  1347. X            if(ulcmpb(mstr,str2) == -1)         /* if the rest matches, ... */
  1348. X                return(istr1);                  /* ... return match position */
  1349. X        }
  1350. X        /* we did not match this time... increment istr1, mstr and try again */
  1351. X        --istr1;
  1352. X        --mstr;
  1353. X    }
  1354. X    return(-1);
  1355. X}    /* end of ulrindex */
  1356. X
  1357. X/*+----------------------------------------------------------------
  1358. X    minunique(str1,str2,minquan)
  1359. X
  1360. X  Returns 1 if at least 'minquan' chars of str2 match
  1361. X  str1 and there are no chars after the minimum unique
  1362. X  chars which do not match str1.  Returns 0 on failure.
  1363. X-----------------------------------------------------------------*/
  1364. Xint
  1365. Xminunique(str1,str2,minquan)
  1366. Xregister char *str1;
  1367. Xregister char *str2;
  1368. Xregister minquan;
  1369. X{
  1370. Xregister index;
  1371. X
  1372. X    if(strlen(str2) < minquan)
  1373. X        return(0);
  1374. X
  1375. X    index = ulcmpb(str1,str2);
  1376. X    if(index < 0)
  1377. X        return(1);
  1378. X
  1379. X    if(index < minquan)
  1380. X        return(0);
  1381. X    if(index < strlen(str2))
  1382. X        return(0);
  1383. X    
  1384. X    return(1);
  1385. X    
  1386. X}   /* end of minunique */
  1387. X/* vi: set tabstop=4 shiftwidth=4: */
  1388. SHAR_EOF
  1389. $TOUCH -am 1224223590 'ecuuclc.c' &&
  1390. chmod 0644 ecuuclc.c ||
  1391. echo 'restore of ecuuclc.c failed'
  1392. Wc_c="`wc -c < 'ecuuclc.c'`"
  1393. test 5623 -eq "$Wc_c" ||
  1394.     echo 'ecuuclc.c: original size 5623, current size' "$Wc_c"
  1395. # ============= ecuusage.c ==============
  1396. echo 'x - extracting ecuusage.c (Text)'
  1397. sed 's/^X//' << 'SHAR_EOF' > 'ecuusage.c' &&
  1398. X/*+-----------------------------------------------------------------------
  1399. X    ecuusage.c - user admonishment
  1400. X    wht@n4hgf.Mt-Park.GA.US
  1401. X
  1402. X  Defined functions:
  1403. X    general_usage(uptr)
  1404. X    log_cmd_usage()
  1405. X    usage()
  1406. X
  1407. X------------------------------------------------------------------------*/
  1408. X/*+:EDITS:*/
  1409. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1410. X
  1411. X#include <stdio.h>
  1412. X#include "ecuhangup.h"
  1413. X#define ff fprintf
  1414. X#define se stderr
  1415. X
  1416. Xextern char *makedate;            /* temporary make date */
  1417. Xextern char *numeric_revision;    /* ecunumrev.c */
  1418. Xextern char *revision_modifier; /* ecunumrev.c */
  1419. X
  1420. Xchar *usage_text[] = 
  1421. X{
  1422. X"usage: ecu [-l /dev/tty<ttynum>] [-b <baud_rate>] [-e] [-o] [-d]\r\n",
  1423. X"           [-c <filename>] [-h] [-k] [-t] [-v[vv...]]\r\n",
  1424. X"           [-p <initial_proc> | <phone_number>]\r\n",
  1425. X"Default: 2400,N,8 (use -e for even parity, -o for odd 7 data bits)\r\n",
  1426. X"-c <filename> use this file rather than ~/.ecumodem\r\n",
  1427. X"-h half duplex ... default is full duplex\r\n",
  1428. X"-v verbosity ... the more 'v's the more verbosity.\r\n",
  1429. X"-d stop execution if -p initial procedure fails\r\n",
  1430. X"-D unconditionally stop execution when -p initial procedure is done\r\n",
  1431. X"\r\n",
  1432. X"For a list of built in commands, type HOME?<ENTER> once program started\r\n",
  1433. X"\r\n",
  1434. X"For access to line with no dialing try: ecu - [-eosv]\r\n",
  1435. X"However, program default line may be busy or not exist\r\n",
  1436. X    (char *)0        /* terminated with null pointer */
  1437. X};
  1438. X
  1439. Xchar *log_cmd_usage_text[] = 
  1440. X{
  1441. X"Usage: log [-s] [-r] <filename>\r\n",
  1442. X"       log off   turn logging off\r\n",
  1443. X" -s scratch any previous contents of <filename>, else append\r\n",
  1444. X" -r raw log, else drop 0x00-0x08,0x11-0x1F,0x7F-0xFF\r\n",
  1445. X    (char *)0        /* terminated with null pointer */
  1446. X};
  1447. X
  1448. X/*+-----------------------------------------------------------------------
  1449. X    general_usage(uptr)
  1450. X------------------------------------------------------------------------*/
  1451. Xvoid
  1452. Xgeneral_usage(uptr)
  1453. Xregister char **uptr;
  1454. X{
  1455. X    while(*uptr != (char *)0)
  1456. X        fputs(*(uptr++),se);
  1457. X}    /* end of usage */
  1458. X
  1459. X/*+-----------------------------------------------------------------------
  1460. X    usage()
  1461. X------------------------------------------------------------------------*/
  1462. Xvoid
  1463. Xusage()
  1464. X{
  1465. X    ff(se,"ecu %s%s made: %s\r\n",
  1466. X        numeric_revision,revision_modifier,makedate);
  1467. X    general_usage(usage_text);
  1468. X    hangup(HANGUP_USAGE);
  1469. X    /*NOTREACHED*/
  1470. X}
  1471. X
  1472. X/*+-------------------------------------------------------------------------
  1473. X    log_cmd_usage()
  1474. X--------------------------------------------------------------------------*/
  1475. Xvoid
  1476. Xlog_cmd_usage()
  1477. X{
  1478. X    general_usage(log_cmd_usage_text);
  1479. X}    /* end of log_cmd_usage */
  1480. X
  1481. X/* vi: set tabstop=4 shiftwidth=4: */
  1482. SHAR_EOF
  1483. $TOUCH -am 1224223590 'ecuusage.c' &&
  1484. chmod 0644 ecuusage.c ||
  1485. echo 'restore of ecuusage.c failed'
  1486. Wc_c="`wc -c < 'ecuusage.c'`"
  1487. test 2642 -eq "$Wc_c" ||
  1488.     echo 'ecuusage.c: original size 2642, current size' "$Wc_c"
  1489. true || echo 'restore of ecuutil.c failed'
  1490. echo End of part 8, continue with part 9
  1491. exit 0
  1492. --------------------------------------------------------------------
  1493. Warren Tucker, TuckerWare emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
  1494. Hacker Extraordinaire  d' async PADs,  pods,  proteins and protocols
  1495.  
  1496. exit 0 # Just in case...
  1497. -- 
  1498. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1499. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1500. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1501. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1502.