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

  1. Newsgroups: comp.sources.misc
  2. From: Warren Tucker <wht@n4hgf.Mt-Park.GA.US>
  3. Subject:  v21i063:  ecu - ECU async comm package rev 3.10, Part11/37
  4. Message-ID: <1991Aug4.015736.8778@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 964f9b34e7a52c35a7161ac0afaa8729
  6. Date: Sun, 4 Aug 1991 01:57:36 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 63
  11. Archive-name: ecu/part11
  12. Environment: SCO, XENIX, ISC
  13. Supersedes: ecu3: Volume 16, Issue 25-59
  14.  
  15. ---- Cut Here and feed the following to sh ----
  16. #!/bin/sh
  17. # this is ecu310.11 (part 11 of ecu310)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file ecuutil.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" != 11; 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 ecuutil.c'
  39. else
  40. echo 'x - continuing file ecuutil.c'
  41. sed 's/^X//' << 'SHAR_EOF' >> 'ecuutil.c' &&
  42. X    arg_token(parsestr,termchars)
  43. X    ascii_name_to_hex(str3char)
  44. X    ascii_to_hex(ascii)
  45. X    build_arg_array(cmd,arg,arg_max_quan,narg_rtn)
  46. X    build_str_array(str,arg,str_max_quan,nstr_rtn)
  47. X    disp_line_termio(fd,text)
  48. X    disp_stat(st)
  49. X    disp_termio(ttt,text)
  50. X    errno_text(errno)
  51. X    find_shell_chars(command)
  52. X    get_curr_dir(cdir,cdir_max)
  53. X    get_home_dir(home_dir)
  54. X    hex_to_ascii_name(char_val)
  55. X    make_char_graphic(ch,incl_3char)
  56. X    make_dirs(pathname)
  57. X    make_ecu_subdir()
  58. X    mem_cpy(dest,src,len);
  59. X    mkdir(dpath,dmode)
  60. X    mode_map(mode,mode_str)
  61. X    pad_zstr_to_len(zstr,len)
  62. X    perror_errmsg(str)
  63. X    print_cwd(curdir,buf_size)
  64. X    skip_ld_break(zstr)
  65. X    str_token(parsestr,termchars)
  66. X    yes_or_no(strarg)
  67. X
  68. X------------------------------------------------------------------------*/
  69. X/*+:EDITS:*/
  70. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  71. X/*:04-16-1991-15:45-wht@n4hgf-gcc cannot use memmove */
  72. X/*:03-18-1991-22:31-wht@n4hgf-ISC 2.2 has mkdir() */
  73. X/*:02-03-1991-14:23-wht@n4hgf-hack workaround for get_home_dir under x286 */
  74. X/*:01-25-1991-16:23-wht@n4hgf-source name wrong in headers */
  75. X/*:12-26-1990-14:32-wht@n4hgf-use memmove or Duff's Device in mem_cpy() */
  76. X/*:12-04-1990-00:58-wht@n4hgf-allow alternating between str/arg_token */
  77. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  78. X
  79. X#include "ecu.h"
  80. X#include "termecu.h"
  81. X#include "ecufork.h"
  82. X#include "ecukey.h"
  83. X#include <pwd.h>
  84. X
  85. Xchar *getenv();
  86. X
  87. Xextern int errno;
  88. Xextern int rcvr_pid;        /* ==0 if rcvr process, else pid of rcvr */
  89. Xextern char curr_dir[CURR_DIRSIZ];
  90. X
  91. Xchar *str_token_static = (char *)0;
  92. X
  93. Xchar *ascii_ctlstr =
  94. X"NULSOHSTXETXEOTENQACKBELBS HT NL VT FF CR SO SI DLEDC1DC2DC3DC4NAKSYNETBCANEM SUBESCFS GS RS US SP ";
  95. X
  96. X/*+-------------------------------------------------------------------------
  97. X    mem_cpy(dest,src,len) - memcpy() with non-destructive overlapping copy
  98. X
  99. X  use Duff's device for speed if memmove not available
  100. X--------------------------------------------------------------------------*/
  101. Xvoid
  102. Xmem_cpy(dest,src,len)
  103. Xregister char *dest;
  104. Xregister char *src;
  105. Xregister len;
  106. X{
  107. X#if defined(M_UNIX) && !defined(DUFF) /*  && !defined(__GNUC__) */
  108. X    /*
  109. X     * memmove() clobbers regs that GCC wants to keep
  110. X     * unless you use at least some of -fcall-save-{ax,bx,cx,dx}
  111. X     */
  112. X    memmove(dest,src,len);
  113. X#else
  114. X    /*
  115. X     * for systems without memmove or with compiler that cannot use it
  116. X     */
  117. X
  118. X    register itmp = (len + 7) / 8;
  119. X    if(dest > src)
  120. X    {
  121. X        dest += len;
  122. X        src += len;
  123. X        switch(len % 8)
  124. X        {
  125. X        case 0:    do{    *--dest = *--src;
  126. X        case 7:        *--dest = *--src;
  127. X        case 6:        *--dest = *--src;
  128. X        case 5:        *--dest = *--src;
  129. X        case 4:        *--dest = *--src;
  130. X        case 3:        *--dest = *--src;
  131. X        case 2:        *--dest = *--src;
  132. X        case 1:        *--dest = *--src;
  133. X                 }while(--itmp > 0);
  134. X        }
  135. X    }
  136. X    else
  137. X    {
  138. X        switch(len % 8)
  139. X        {
  140. X        case 0:    do{    *dest++ = *src++;
  141. X        case 7:        *dest++ = *src++;
  142. X        case 6:        *dest++ = *src++;
  143. X        case 5:        *dest++ = *src++;
  144. X        case 4:        *dest++ = *src++;
  145. X        case 3:        *dest++ = *src++;
  146. X        case 2:        *dest++ = *src++;
  147. X        case 1:        *dest++ = *src++;
  148. X                 }while(--itmp > 0);
  149. X        }
  150. X    }
  151. X#endif
  152. X}    /* end of mem_cpy */
  153. X
  154. X/*+-------------------------------------------------------------------------
  155. X    errno_text(err_no)
  156. X--------------------------------------------------------------------------*/
  157. Xchar *
  158. Xerrno_text(err_no)
  159. Xint err_no;
  160. X{
  161. Xstatic char errant[16];
  162. X
  163. X    switch(err_no)
  164. X    {
  165. X        case 0: return("0");
  166. X        case EPERM: return("EPERM");
  167. X        case ENOENT: return("ENOENT");
  168. X        case ESRCH: return("ESRCH");
  169. X        case EINTR: return("EINTR");
  170. X        case EIO: return("EIO");
  171. X        case ENXIO: return("ENXIO");
  172. X        case E2BIG: return("E2BIG");
  173. X        case ENOEXEC: return("ENOEXEC");
  174. X        case EBADF: return("EBADF");
  175. X        case ECHILD: return("ECHILD");
  176. X        case EAGAIN: return("EAGAIN");
  177. X        case ENOMEM: return("ENOMEM");
  178. X        case EACCES: return("EACCES");
  179. X        case EFAULT: return("EFAULT");
  180. X        case ENOTBLK: return("ENOTBLK");
  181. X        case EBUSY: return("EBUSY");
  182. X        case EEXIST: return("EEXIST");
  183. X        case EXDEV: return("EXDEV");
  184. X        case ENODEV: return("ENODEV");
  185. X        case ENOTDIR: return("ENOTDIR");
  186. X        case EISDIR: return("EISDIR");
  187. X        case EINVAL: return("EINVAL");
  188. X        case ENFILE: return("ENFILE");
  189. X        case EMFILE: return("EMFILE");
  190. X        case ENOTTY: return("ENOTTY");
  191. X        case ETXTBSY: return("ETXTBSY");
  192. X        case EFBIG: return("EFBIG");
  193. X        case ENOSPC: return("ENOSPC");
  194. X        case ESPIPE: return("ESPIPE");
  195. X        case EROFS: return("EROFS");
  196. X        case EMLINK: return("EMLINK");
  197. X        case EPIPE: return("EPIPE");
  198. X        case EDOM: return("EDOM");
  199. X        case ERANGE: return("ERANGE");
  200. X        default:
  201. X            sprintf(errant,"E%04u",errno);
  202. X            return(errant);
  203. X    }
  204. X
  205. X}    /* end of errno_text */
  206. X
  207. X/*+-------------------------------------------------------------------------
  208. X    skip_ld_break(zstr) - skip leading spaces and tabs
  209. X--------------------------------------------------------------------------*/
  210. Xchar *
  211. Xskip_ld_break(zstr)
  212. Xregister char *zstr;
  213. X{
  214. X    while(isspace(*zstr))
  215. X        zstr++;
  216. X    return(zstr);
  217. X}    /* end of skip_ld_break */
  218. X
  219. X/*+-------------------------------------------------------------------------
  220. X    strip_trail_break(zstr) - strip leading spaces and tabs
  221. X--------------------------------------------------------------------------*/
  222. Xvoid
  223. Xstrip_trail_break(zstr)
  224. Xchar *zstr;
  225. X{
  226. Xregister int itmp = strlen(zstr);
  227. Xregister char *zptr = zstr + itmp - 1;
  228. X
  229. X    while(itmp && isspace(*zptr))
  230. X    {
  231. X        *zptr-- = 0;
  232. X        itmp--;
  233. X    }
  234. X}    /* end of strip_trail_break */
  235. X
  236. X/*+-----------------------------------------------------------------------
  237. X    pad_zstr_to_len(zstr,len)
  238. X
  239. X  pads with spaces to specified length, unless already longer than
  240. X  len in which case the string is truncated to 'len' characters.
  241. X------------------------------------------------------------------------*/
  242. Xvoid
  243. Xpad_zstr_to_len(zstr,len)
  244. Xchar *zstr;
  245. Xint len;
  246. X{
  247. Xregister izstr;
  248. X
  249. X    izstr = strlen(zstr);
  250. X    if(izstr >= len)
  251. X        zstr[len] = 0;
  252. X    else
  253. X    {
  254. X        while(izstr < len)
  255. X            zstr[izstr++] = 0x20;
  256. X        zstr[izstr] = 0;
  257. X    }
  258. X}    /* end of pad_zstr_to_len */
  259. X
  260. X/*+-----------------------------------------------------------------------
  261. X    arg_token(parsestr,termchars)
  262. X
  263. XGet next token from string parsestr ((char *)0 on 2nd, 3rd, etc.
  264. Xcalls), where tokens are nonempty strings separated by runs of chars
  265. Xfrom termchars.  Writes nulls into parsestr to end tokens.
  266. Xtermchars need not remain constant from call to call.
  267. X
  268. XTreats multiple occurrences of a termchar as one delimiter (does not
  269. Xallow null fields).
  270. X------------------------------------------------------------------------*/
  271. Xchar *
  272. Xarg_token(parsestr,termchars)
  273. Xchar *parsestr;
  274. Xchar *termchars;
  275. X{
  276. Xregister char *parseptr;
  277. Xchar *token;
  278. X
  279. X    if(!parsestr && !str_token_static)
  280. X        return((char *)0);
  281. X
  282. X    if(parsestr)
  283. X        parseptr = parsestr;
  284. X    else
  285. X       parseptr = str_token_static;
  286. X
  287. X    while(*parseptr)
  288. X    {
  289. X        if(!strchr(termchars,*parseptr))
  290. X            break;
  291. X        parseptr++;
  292. X    }
  293. X
  294. X    if(!*parseptr)
  295. X    {
  296. X        str_token_static = (char *)0;
  297. X        return((char *)0);
  298. X    }
  299. X
  300. X    token = parseptr;
  301. X    if(*token == '\'')
  302. X    {
  303. X        token++;
  304. X        parseptr++;
  305. X        while(*parseptr)
  306. X        {
  307. X            if(*parseptr == '\'')
  308. X            {
  309. X                str_token_static = parseptr + 1;
  310. X                *parseptr = 0;
  311. X                return(token);
  312. X            }
  313. X            parseptr++;
  314. X        }
  315. X        str_token_static = (char *)0;
  316. X        return(token);
  317. X    }
  318. X    while(*parseptr)
  319. X    {
  320. X        if(strchr(termchars,*parseptr))
  321. X        {
  322. X            *parseptr = 0;
  323. X            str_token_static = parseptr + 1;
  324. X            while(*str_token_static)
  325. X            {
  326. X                if(!strchr(termchars,*str_token_static))
  327. X                    break;
  328. X                str_token_static++;
  329. X            }
  330. X            return(token);
  331. X        }
  332. X        parseptr++;
  333. X    }
  334. X    str_token_static = (char *)0;
  335. X    return(token);
  336. X}    /* end of arg_token */
  337. X
  338. X/*+-------------------------------------------------------------------------
  339. X    build_arg_array(cmd,arg,arg_max_quan,&narg)
  340. X--------------------------------------------------------------------------*/
  341. Xvoid
  342. Xbuild_arg_array(cmd,arg,arg_max_quan,narg_rtn)
  343. Xchar *cmd;
  344. Xchar **arg;
  345. Xint arg_max_quan;
  346. Xint *narg_rtn;
  347. X{
  348. Xregister itmp;
  349. Xregister narg;
  350. X
  351. X    str_token_static = (char *)0;
  352. X    for(itmp = 0; itmp < arg_max_quan; itmp++)
  353. X        arg[itmp] = (char *)0;
  354. X    arg[0] = arg_token(cmd," \t\r\n");
  355. X
  356. X    for(narg = 1; narg < arg_max_quan; ++narg)
  357. X    {
  358. X        if(!(arg[narg] = arg_token((char *)0," \t\r\n"))) 
  359. X            break;
  360. X    }
  361. X
  362. X    *narg_rtn = narg;
  363. X
  364. X}    /* end of build_arg_array */
  365. X
  366. X/*+-----------------------------------------------------------------------
  367. X    str_token(parsestr,termchars)
  368. X
  369. XGet next token from string parsestr ((char *)0 on 2nd, 3rd, etc.
  370. Xcalls), where tokens are nonempty strings separated by runs of chars
  371. Xfrom termchars.  Writes nulls into parsestr to end tokens.
  372. Xtermchars need not remain constant from call to call.
  373. X
  374. XTreats each occurrence of a termchar as delimiter (allows null
  375. Xfields).
  376. X------------------------------------------------------------------------*/
  377. Xchar *
  378. Xstr_token(parsestr,termchars)
  379. Xchar *parsestr;
  380. Xchar *termchars;
  381. X{
  382. Xregister char *termptr;
  383. Xregister char *parseptr;
  384. Xchar *token;
  385. X
  386. X    if(!parsestr && !str_token_static)
  387. X        return((char *)0);
  388. X
  389. X    if(parsestr)
  390. X        parseptr = parsestr;
  391. X    else
  392. X       parseptr = str_token_static;
  393. X
  394. X    while(*parseptr)
  395. X    {
  396. X        for(termptr = termchars; *termptr != 0; termptr++)
  397. X        {
  398. X            if(*parseptr == *termptr)
  399. X                goto FOUND_TERM;
  400. X        }
  401. X        if(!*termptr)
  402. X            break;
  403. X        parseptr++;
  404. X    }
  405. X
  406. X    if(!*parseptr)
  407. X    {
  408. X        str_token_static = (char *)0;
  409. X        return((char *)0);
  410. X    }
  411. X
  412. XFOUND_TERM:
  413. X    token = parseptr;
  414. X    while(*parseptr)
  415. X    {
  416. X        for(termptr = termchars; *termptr;)
  417. X        {
  418. X            if(*parseptr == *termptr++)
  419. X            {
  420. X                str_token_static = parseptr + 1;
  421. X                *parseptr = 0;
  422. X                return(token);
  423. X            }
  424. X        }
  425. X        parseptr++;
  426. X    }
  427. X    str_token_static = (char *)0;
  428. X    return(token);
  429. X}    /* end of str_token */
  430. X
  431. X/*+-------------------------------------------------------------------------
  432. X    build_str_array(str,arg,str_max_quan,&narg)
  433. X--------------------------------------------------------------------------*/
  434. Xvoid
  435. Xbuild_str_array(str,arg,str_max_quan,nstr_rtn)
  436. Xchar *str;
  437. Xchar **arg;
  438. Xint str_max_quan;
  439. Xint *nstr_rtn;
  440. X{
  441. Xregister itmp;
  442. Xregister narg;
  443. X
  444. X
  445. X    str_token_static = (char *)0;
  446. X    for(itmp = 0; itmp < str_max_quan; itmp++)
  447. X        arg[itmp] = (char *)0;
  448. X    arg[0] = str_token(str," \t\r\n");
  449. X
  450. X    for(narg = 1; narg < str_max_quan; ++narg)
  451. X    {
  452. X        if(!(arg[narg] = str_token((char *)0," \t\r\n"))) 
  453. X            break;
  454. X    }
  455. X
  456. X    *nstr_rtn = narg;
  457. X
  458. X}    /* end of build_str_array */
  459. X
  460. X/*+-----------------------------------------------------------------------
  461. X    make_char_graphic(character,incl_3char) - Make all chars "printable"
  462. X
  463. X  returns pointer to a static string containing printable version
  464. X  of a character.  If control char, printed as "^A", etc.
  465. X  if incl_3char set true, then space + ASCII assignment (e.g. "NUL") is
  466. X  appended to the string for non-printable graphics
  467. X------------------------------------------------------------------------*/
  468. Xchar *make_char_graphic(ch,incl_3char)
  469. Xregister char ch;
  470. Xint incl_3char;
  471. X{
  472. Xstatic char gg[16];
  473. X
  474. X    ch &= 0x7F;
  475. X    if((ch >= 0x20) && (ch < 0x7F))
  476. X    {
  477. X        gg[0] = ch; gg[1] = 0;
  478. X    }
  479. X    else
  480. X    {
  481. X        gg[0] = '^'; 
  482. X        if(ch == 0x7F)
  483. X        {
  484. X            gg[1] = '?';
  485. X            if(incl_3char)
  486. X                strcpy(&gg[2]," DEL");
  487. X            else
  488. X                gg[2] = 0;
  489. X        }
  490. X        else
  491. X        {
  492. X            gg[1] = ch + 0x40;
  493. X            if(incl_3char)
  494. X            {
  495. X                gg[2] = 0x20;
  496. X                strncpy(&gg[3],ascii_ctlstr + (ch * 3),3);
  497. X                gg[7] = 0;
  498. X            }
  499. X            else
  500. X                gg[2] = 0;
  501. X        }
  502. X    }
  503. X    return(gg);
  504. X}    /* end of make_char_graphic */
  505. X
  506. X/*+-----------------------------------------------------------------------
  507. X    mode_map(mode,mode_str)    build drwxrwxrwx string
  508. X------------------------------------------------------------------------*/
  509. Xchar *
  510. Xmode_map(mode,mode_str)
  511. Xunsigned short mode;
  512. Xchar *mode_str;
  513. X{
  514. Xregister unsigned ftype = mode & S_IFMT;
  515. Xregister char *rtn;
  516. Xstatic char result[12];
  517. X
  518. X    rtn = (mode_str) ? mode_str : result;
  519. X
  520. X    /*          drwxrwxrwx */
  521. X    /*          0123456789 */
  522. X    strcpy(rtn,"----------");
  523. X
  524. X    switch(ftype)
  525. X    {
  526. X        case S_IFIFO:    *rtn = 'p'; break; /* FIFO (named pipe) */
  527. X        case S_IFDIR:    *rtn = 'd'; break; /* directory */
  528. X        case S_IFCHR:    *rtn = 'c'; break; /* character special */
  529. X        case S_IFBLK:    *rtn = 'b'; break; /* block special */
  530. X        case S_IFREG:    *rtn = '-'; break; /* regular */
  531. X
  532. X#if defined(BSD)
  533. X        case S_IFLNK:    *rtn = 'l'; break; /* symbolic link */
  534. X        case S_IFSOCK:    *rtn = 's'; break; /* socket */
  535. X#endif
  536. X
  537. X#if defined (M_XENIX) || defined(M_UNIX)
  538. X        case S_IFNAM:                        /* name space entry */
  539. X            if(mode & S_INSEM)                /* semaphore */
  540. X            {
  541. X                *rtn = 's';
  542. X                break;
  543. X            }
  544. X            if(mode & S_INSHD)                /* shared memory */
  545. X            {
  546. X                *rtn = 'm';
  547. X                break;
  548. X            }
  549. X#endif
  550. X
  551. X        default:        *rtn = '?'; break;    /* ??? */
  552. X    }
  553. X
  554. X    if(mode & 000400) *(rtn + 1) = 'r';
  555. X    if(mode & 000200) *(rtn + 2) = 'w';
  556. X    if(mode & 000100) *(rtn + 3) = 'x';
  557. X    if(mode & 004000) *(rtn + 3) = 's';
  558. X    if(mode & 000040) *(rtn + 4) = 'r';
  559. X    if(mode & 000020) *(rtn + 5) = 'w';
  560. X    if(mode & 000010) *(rtn + 6) = 'x';
  561. X    if(mode & 002000) *(rtn + 6) = 's';
  562. X    if(mode & 000004) *(rtn + 7) = 'r';
  563. X    if(mode & 000002) *(rtn + 8) = 'w';
  564. X    if(mode & 000001) *(rtn + 9) = 'x';
  565. X    if(mode & 001000) *(rtn + 9) = 't';
  566. X
  567. X    return(rtn);
  568. X
  569. X}    /* end of mode_map */
  570. X
  571. X/*+-----------------------------------------------------------------------
  572. X    disp_termio(ttt)
  573. X  display termio 'ttt' on stderr
  574. X------------------------------------------------------------------------*/
  575. Xvoid disp_termio(ttt,text)
  576. Xstruct termio *ttt;
  577. Xchar *text;
  578. X{
  579. Xregister flag;
  580. Xregister i_cc;
  581. Xregister char *cptr;
  582. Xint dbits;
  583. Xchar parity;
  584. X
  585. X    pprintf("---------> %s\n",text);
  586. X
  587. X    flag = ttt->c_iflag;
  588. X    pprintf("iflag: %07o IGNBRK:%d  BRKINT:%d  IGNPAR:%d  PARMRK:%d  INPCK:%d  ISTRIP:%d\n",
  589. X                flag,
  590. X                (flag & IGNBRK) ? 1 : 0,
  591. X                (flag & BRKINT) ? 1 : 0,
  592. X                (flag & IGNPAR) ? 1 : 0,
  593. X                (flag & PARMRK) ? 1 : 0,
  594. X                (flag & INPCK ) ? 1 : 0,
  595. X                (flag & ISTRIP) ? 1 : 0);
  596. X    pprintf(
  597. X"               INLCR:%d  IGNCR:%d  ICRNL:%d  IUCLC:%d  IXON:%d  IXANY:%d  IXOFF:%d\n",
  598. X                (flag & INLCR ) ? 1 : 0,
  599. X                (flag & IGNCR ) ? 1 : 0,
  600. X                (flag & ICRNL ) ? 1 : 0,
  601. X                (flag & IUCLC ) ? 1 : 0,
  602. X                (flag & IXON  ) ? 1 : 0,
  603. X                (flag & IXANY ) ? 1 : 0,
  604. X                (flag & IXOFF ) ? 1 : 0);
  605. X
  606. X    flag = ttt->c_oflag;
  607. X    pprintf("oflag: %07o OPOST:%d  OLCUC:%d  ONLCR:%d  OCRNL:%d  ONOCR:%d  ONLRET:%d  OFDEL:%d\n",
  608. X                flag,
  609. X                (flag & OPOST ) ? 1 : 0,
  610. X                (flag & OLCUC ) ? 1 : 0,
  611. X                (flag & ONLCR ) ? 1 : 0,
  612. X                (flag & OCRNL ) ? 1 : 0,
  613. X                (flag & ONOCR ) ? 1 : 0,
  614. X                (flag & ONLRET) ? 1 : 0,
  615. X                (flag & OFDEL ) ? 1 : 0);
  616. X
  617. X    flag = ttt->c_cflag;
  618. X    pprintf("cflag: %07o ",ttt->c_cflag);
  619. X    switch(flag & CBAUD)
  620. X    {
  621. X        case B0:    cptr = "HUP"; break;
  622. X        case B50:    cptr = "50"; break;
  623. X        case B75:    cptr = "75"; break;
  624. X        case B110:    cptr = "110"; break;
  625. X        case B134:    cptr = "134.5"; break;
  626. X        case B150:    cptr = "150"; break;
  627. X        case B200:    cptr = "200"; break;
  628. X        case B300:    cptr = "300"; break;
  629. X        case B600:    cptr = "600"; break;
  630. X        case B1200:    cptr = "1200"; break;
  631. X        case B1800:    cptr = "1800"; break;
  632. X        case B2400:    cptr = "2400"; break;
  633. X        case B4800:    cptr = "4800"; break;
  634. X        case B9600:    cptr = "9600"; break;
  635. X#if defined(B19200)
  636. X        case B19200:cptr = "19200"; break;
  637. X#endif
  638. X#if defined(B38400)
  639. X        case B38400:cptr = "38400"; break;
  640. X#endif
  641. X        default:    
  642. X            switch(flag & CBAUD)
  643. X            {
  644. X                case EXTA:    cptr = "EXTA"; break;
  645. X                case EXTB:    cptr = "EXTB"; break;
  646. X                default:    cptr = "????"; break;
  647. X            }
  648. X    }
  649. X    dbits = 5 + ((flag & CSIZE) >> 4);
  650. X    parity = (flag & PARENB) ? ((flag & PARODD) ? 'O' : 'E') : 'N';
  651. X    pprintf("%s-%d-%c-%d ",cptr,dbits,parity,(flag & CSTOPB) ? 2 : 1);
  652. X    switch(flag & CS8)
  653. X    {
  654. X        case CS8: pputs("CS8 "); break;
  655. X        case CS7: pputs("CS7 "); break;
  656. X        case CS6: pputs("CS6 "); break;
  657. X        case CS5: pputs("CS5 "); break;
  658. X    }
  659. X    pprintf("CREAD:%d  HUPCL:%d  CLOCAL:%d",
  660. X                (flag & CREAD ) ? 1 : 0,
  661. X                (flag & HUPCL ) ? 1 : 0,
  662. X                (flag & CLOCAL) ? 1 : 0);
  663. X#if defined(RTSFLOW)    /* only SCO */
  664. X    pprintf(" RTSFLOW:%d  CTSFLOW:%d",
  665. X                (flag & RTSFLOW ) ? 1 : 0,
  666. X                (flag & CTSFLOW ) ? 1 : 0);
  667. X#endif
  668. X    pprintf("\n");
  669. X
  670. X    flag = ttt->c_lflag;
  671. X    pprintf("lflag: %07o ISIG:%d  ICANON:%d  XCASE:%d  ECHO:%d  ECHOE:%d\n",
  672. X                flag,
  673. X                (flag & ISIG  ) ? 1 : 0,
  674. X                (flag & ICANON) ? 1 : 0,
  675. X                (flag & XCASE ) ? 1 : 0,
  676. X                (flag & ECHO  ) ? 1 : 0,
  677. X                (flag & ECHOE ) ? 1 : 0);
  678. X    pprintf("            ECHOK:%d  ECHONL:%d  NOFLSH:%d",
  679. X                (flag & ECHOK ) ? 1 : 0,
  680. X                (flag & ECHONL) ? 1 : 0,
  681. X                (flag & NOFLSH) ? 1 : 0);
  682. X
  683. X#if defined(XCLUDE)
  684. X    pprintf("  XCLUDE:%d",(flag & XCLUDE) ? 1 : 0);
  685. X#endif
  686. X    pputs("\n");
  687. X
  688. X    pprintf("ctl chars: ");
  689. X    for(i_cc = 0; i_cc < NCC; i_cc++)
  690. X        pprintf("%02x   ",ttt->c_cc[i_cc]);
  691. X    pprintf("  (hex)\n");
  692. X    pprintf("           INTR QUIT ERAS KILL EOF  EOL  EOL2 SWTCH  VMIN-EOF VTIME-EOL\n");
  693. X
  694. X}    /* end of disp_termio */
  695. X
  696. X/*+-------------------------------------------------------------------------
  697. X    disp_stat(st)
  698. X--------------------------------------------------------------------------*/
  699. Xvoid
  700. Xdisp_stat(st)
  701. Xstruct stat *st;
  702. X{
  703. Xchar mdmap[32];
  704. X    mode_map(st->st_mode,mdmap);
  705. X    pprintf("mode: %s ",mdmap);
  706. X    pprintf("inode: %5u  dev: %3u rdev: %u,%u (0x%04x)\n",
  707. X        (uint)st->st_ino,(uint)st->st_dev,
  708. X        (ushort)st->st_rdev >> 8,(ushort)st->st_rdev & 0xFF,
  709. X        (ushort)st->st_rdev);
  710. X
  711. X}    /* end of disp_stat */
  712. X
  713. X/*+-----------------------------------------------------------------------
  714. X    disp_line_termio(fd)
  715. X
  716. XGet current termio structure for file descriptor fd
  717. Xand display on stderr
  718. X------------------------------------------------------------------------*/
  719. Xvoid
  720. Xdisp_line_termio(fd,text)
  721. Xint fd;        /* file descriptor */
  722. Xchar *text;
  723. X{
  724. Xstruct termio fd_termio;
  725. Xstruct stat fd_stat;
  726. Xchar text2[128];
  727. X
  728. X    ioctl(fd,TCGETA,&fd_termio);
  729. X    sprintf(text2,"fd: %d  %s",fd,text);
  730. X    disp_termio(&fd_termio,text2);
  731. X    fstat(fd,&fd_stat);
  732. X    disp_stat(&fd_stat);
  733. X
  734. X}    /* end of disp_line_termio */
  735. X
  736. X/*+-----------------------------------------------------------------------
  737. X    print_cwd(curdir) print and return current working directory
  738. X------------------------------------------------------------------------*/
  739. Xvoid print_cwd(curdir,buf_size)
  740. Xchar *curdir;
  741. Xint buf_size;
  742. X{
  743. X    ff(se,"%s\r\n",curr_dir);
  744. X    strncpy(curdir,curr_dir,buf_size);
  745. X}    /* end of print_cwd */
  746. X
  747. X/*+-----------------------------------------------------------------------
  748. X    dummy_call() bypass optimizer (call from another module for noop)
  749. X------------------------------------------------------------------------*/
  750. Xvoid dummy_call() { ; }
  751. X
  752. X/*+-----------------------------------------------------------------------
  753. X    ascii_name_to_hex(str3char)
  754. X
  755. X  return value of ascii ctl char name (e.g., "NUL") 0 - 0x1F
  756. X  returns -1 if input not valid
  757. X------------------------------------------------------------------------*/
  758. Xascii_name_to_hex(str3char)
  759. Xchar *str3char;
  760. X{
  761. Xregister char *cptr = ascii_ctlstr;
  762. Xregister intval;
  763. X
  764. X    if(ulcmpb(str3char,"del") < 0)
  765. X        return(127);
  766. X
  767. X    for(intval = 0; intval <= SPACE; intval++)
  768. X    {
  769. X        if(    (to_lower(*str3char) == to_lower(*cptr))                &&
  770. X            (to_lower(*(str3char + 1)) == to_lower(*(cptr + 1)))    &&
  771. X            ((to_lower(*(str3char + 2)) == to_lower(*(cptr + 2)))    ||
  772. X            (*(cptr + 2) == ' ')))
  773. X        {
  774. X            return(intval);
  775. X        }
  776. X        cptr += 3;
  777. X    }
  778. X
  779. X    return(-1);
  780. X
  781. X}    /* end of ascii_name_to_hex */
  782. X
  783. X/*+-------------------------------------------------------------------------
  784. X    ascii_to_hex(ascii)
  785. X--------------------------------------------------------------------------*/
  786. Xascii_to_hex(ascii)
  787. Xchar *ascii;
  788. X{
  789. Xint hexval;
  790. X    if(strlen(ascii) == 1)
  791. X        return(*ascii);
  792. X    else if(!strncmp(ascii,"0x",2))
  793. X    {
  794. X        sscanf(ascii + 2,"%x",&hexval);
  795. X        return(hexval & 0xFF);
  796. X    }
  797. X    else if(*ascii == '^')
  798. X        return(*(ascii + 1) & 0x1F);
  799. X    else
  800. X        return(ascii_name_to_hex(ascii));
  801. X}    /* end of ascii_to_hex */
  802. X
  803. X/*+-------------------------------------------------------------------------
  804. X    hex_to_ascii_name(char_val)
  805. X
  806. X  Returns pointer to static string containing three character ASCII
  807. X  name for control character followed by a null.
  808. X--------------------------------------------------------------------------*/
  809. Xchar *
  810. Xhex_to_ascii_name(char_val)
  811. Xchar char_val;
  812. X{
  813. Xstatic char ascii_name[4];
  814. X
  815. X    char_val &= 0x7F;
  816. X
  817. X    if(char_val == 0x7F)
  818. X        strcpy(ascii_name,"DEL");
  819. X    else if(char_val > SPACE)
  820. X    {
  821. X        ascii_name[0] = char_val;
  822. X        ascii_name[1] = 0;
  823. X    }
  824. X    else
  825. X    {
  826. X        strncpy(ascii_name,ascii_ctlstr + (char_val * 3),3);
  827. X        ascii_name[3] = 0;
  828. X    }
  829. X
  830. X    return(ascii_name);
  831. X
  832. X}    /* end of hex_to_ascii_name */
  833. X
  834. X/*+-------------------------------------------------------------------------
  835. X    get_curr_dir(cdir,cdir_max) - get current directory into 'cdir'
  836. X--------------------------------------------------------------------------*/
  837. Xint
  838. Xget_curr_dir(cdir,cdir_max)
  839. Xchar *cdir;
  840. Xint cdir_max;
  841. X{
  842. X#if defined(BSD)
  843. Xchar *getwd();
  844. X    strcpy(cdir,".");
  845. X    return((!getwd(cdir)) ? -1 : 0);
  846. X#endif
  847. X
  848. X#if defined(M_XENIX) || defined(M_UNIX)
  849. XFILE *popen();
  850. XFILE *pipefp = popen("/bin/pwd","r");
  851. Xint itmp;
  852. X    strcpy(cdir,".");
  853. X    if(!pipefp)
  854. X        return(-1);
  855. X    fgets(cdir,cdir_max,pipefp);
  856. X    if((itmp = strlen(cdir)) && (*(cdir + itmp - 1) == 0x0A))
  857. X        *(cdir + itmp - 1) = 0;
  858. X    fclose(pipefp);
  859. X    return(0);
  860. X#endif
  861. X
  862. X}    /* end of get_curr_dir */
  863. X
  864. X/*+-----------------------------------------------------------------------
  865. X    get_home_dir(home_dir):  leave plenty of room for result!
  866. X------------------------------------------------------------------------*/
  867. Xget_home_dir(home_dir)
  868. Xchar *home_dir;
  869. X{
  870. Xstatic char home_directory[256] = "";
  871. Xstruct passwd *pwent;
  872. Xchar *cptr;
  873. X
  874. X    if(home_directory[0])
  875. X    {
  876. X        strcpy(home_dir,home_directory);
  877. X        return(0);
  878. X    }
  879. X
  880. X    if(cptr = getenv("HOME"))            /* x286 seems to blow up ... */
  881. X    {                                    /* ... in pwent code ... hmmm */
  882. X        strcpy(home_directory,cptr);
  883. X        strcpy(home_dir,cptr);
  884. X        return(0);
  885. X    }
  886. X
  887. X    if(!(pwent = getpwuid(getuid())))
  888. X    {
  889. X        pperror("cannot get pwent for you!!");
  890. X        termecu(TERMECU_PWENT_ERROR);
  891. X    }
  892. X    strcpy(home_directory,pwent->pw_dir);
  893. X    strcpy(home_dir,pwent->pw_dir);
  894. X    endpwent();
  895. X    return(0);
  896. X
  897. X}    /* end of get_home_dir */
  898. X
  899. X/*+-------------------------------------------------------------------------
  900. X    make_ecu_subdir()
  901. Xmust be called early in execution before wierd tty states set, etc.
  902. X--------------------------------------------------------------------------*/
  903. Xvoid
  904. Xmake_ecu_subdir()
  905. X{
  906. Xint itmp;
  907. Xstruct stat fst;
  908. Xchar s256[256];
  909. X
  910. X    get_home_dir(s256);
  911. X    strcat(s256,"/.ecu");
  912. X    if((!(itmp = stat(s256,&fst))) && ((fst.st_mode & S_IFMT) != S_IFDIR))
  913. X    {
  914. X        ff(se,"~/.ecu is not a directory. Rename the file and try again.\n\n");
  915. X        exit(1);
  916. X    }
  917. X    if(itmp)        /* if stat failed, try to make the directory */
  918. X    {
  919. X        strcat(s256,"/.");
  920. X        if(make_dirs(s256))
  921. X        {
  922. X            if(stat(s256,&fst))
  923. X            {
  924. X                ff(se,"cannot make ~/.ecu subdirectory.\n");
  925. X                perror(s256);
  926. X                exit(1);
  927. X            }
  928. X        }
  929. X    }
  930. X    chmod(s256,0700);
  931. X}    /* end of make_ecu_subdir */
  932. X
  933. X/*+-------------------------------------------------------------------------
  934. X    yes_or_no(strarg)
  935. X  Returns 1 if first char is 'Y' or 'y'
  936. X    or if strarg is numeric returns the numeric value
  937. X    or if strarg is alpha == "on" returns 1
  938. X  Returns 0 otherwise
  939. X--------------------------------------------------------------------------*/
  940. Xint
  941. Xyes_or_no(strarg)
  942. Xchar *strarg;
  943. X{
  944. X    if((strcmp(strarg,"on") == 0) || (to_lower(*strarg) == 'y'))
  945. X        return(1);
  946. X    else
  947. X        return(atoi(strarg));
  948. X}    /* end of yes_or_no */
  949. X
  950. X/*+-------------------------------------------------------------------------
  951. X    find_shell_chars(command)
  952. X--------------------------------------------------------------------------*/
  953. Xint
  954. Xfind_shell_chars(command)
  955. Xchar *command;
  956. X{
  957. Xregister schar;
  958. Xregister cchar;
  959. Xregister char *scptr;
  960. Xstatic char shell_chars[] = "\"~;*?'`{}[]$";
  961. X
  962. X    while(cchar = *command++)
  963. X    {
  964. X        scptr = shell_chars;
  965. X        while(schar = *scptr++)
  966. X            if(schar == cchar)
  967. X                return(1);
  968. X    }
  969. X    return(0);
  970. X}    /* end of find_shell_chars */
  971. X
  972. X/*+-------------------------------------------------------------------------
  973. X    perror_errmsg(str)
  974. X--------------------------------------------------------------------------*/
  975. Xvoid
  976. Xperror_errmsg(str)
  977. Xchar *str;
  978. X{
  979. Xextern char errmsg[];
  980. Xextern char *sys_errlist[];
  981. Xextern int sys_nerr;
  982. Xextern int errno;
  983. X
  984. X    if(errno > sys_nerr)
  985. X        sprintf(errmsg,"%s: error %d",str,errno);
  986. X    else
  987. X        sprintf(errmsg,"%s: %s",str,sys_errlist[errno]);
  988. X}    /* end of perror_errmsg */
  989. X
  990. X/*+-------------------------------------------------------------------------
  991. X    cfree(p,num,size) - fix bug in XENIX -lmalloc
  992. X--------------------------------------------------------------------------*/
  993. X#if defined(M_XENIX) && defined(XENIX_MALLOC_LIB_BUG)
  994. Xcfree(p,num,size)
  995. Xchar *p;
  996. Xint num;
  997. Xint size;
  998. X{
  999. X    free(p);
  1000. X}    /* end of cfree */
  1001. X#endif
  1002. X
  1003. X#if defined(__GNUC__) && !defined(GCC140)
  1004. X/*+-------------------------------------------------------------------------
  1005. X    defeat_optimize_to_work_around_bug(would_be_optimized)
  1006. X
  1007. Xwork around for GCC 1.39 optimization bug (see ecufkey.c)
  1008. XThis bug was fixed in gcc 1.40
  1009. X--------------------------------------------------------------------------*/
  1010. Xvoid
  1011. Xdefeat_optimize_to_work_around_bug(would_be_optimized)
  1012. Xint *would_be_optimized;
  1013. X{
  1014. X    ;    /* do absolutely nothing */
  1015. X}    /* end of defeat_optimize_to_work_around_bug */
  1016. X
  1017. X#endif /* __GNUC__ */
  1018. X/* end of ecuutil.c */
  1019. X/* vi: set tabstop=4 shiftwidth=4: */
  1020. SHAR_EOF
  1021. echo 'File ecuutil.c is complete' &&
  1022. $TOUCH -am 0725125791 'ecuutil.c' &&
  1023. chmod 0644 ecuutil.c ||
  1024. echo 'restore of ecuutil.c failed'
  1025. Wc_c="`wc -c < 'ecuutil.c'`"
  1026. test 24595 -eq "$Wc_c" ||
  1027.     echo 'ecuutil.c: original size 24595, current size' "$Wc_c"
  1028. rm -f _shar_wnt_.tmp
  1029. fi
  1030. # ============= ecuvmin.h ==============
  1031. if test -f 'ecuvmin.h' -a X"$1" != X"-c"; then
  1032.     echo 'x - skipping ecuvmin.h (File already exists)'
  1033.     rm -f _shar_wnt_.tmp
  1034. else
  1035. > _shar_wnt_.tmp
  1036. echo 'x - extracting ecuvmin.h (Text)'
  1037. sed 's/^X//' << 'SHAR_EOF' > 'ecuvmin.h' &&
  1038. X/*+-------------------------------------------------------------------------
  1039. X    xenixvmin.h  --  set line default VMIN
  1040. X    wht@n4hgf.Mt-Park.GA.US
  1041. X--------------------------------------------------------------------------*/
  1042. X/*+:EDITS:*/
  1043. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  1044. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1045. X
  1046. X#if defined(BUILDING_PROTOTYPES)    /* if building lint_args.h ... */
  1047. X#define XENIX_VMIN        2    /* ... include vmin handling routines */
  1048. X#else
  1049. X#define XENIX_VMIN        1    /* this is the real value for vmin */
  1050. X#endif
  1051. X/* vi: set tabstop=4 shiftwidth=4: */
  1052. SHAR_EOF
  1053. $TOUCH -am 0725125791 'ecuvmin.h' &&
  1054. chmod 0644 ecuvmin.h ||
  1055. echo 'restore of ecuvmin.h failed'
  1056. Wc_c="`wc -c < 'ecuvmin.h'`"
  1057. test 588 -eq "$Wc_c" ||
  1058.     echo 'ecuvmin.h: original size 588, current size' "$Wc_c"
  1059. rm -f _shar_wnt_.tmp
  1060. fi
  1061. # ============= ecuwinutil.c ==============
  1062. if test -f 'ecuwinutil.c' -a X"$1" != X"-c"; then
  1063.     echo 'x - skipping ecuwinutil.c (File already exists)'
  1064.     rm -f _shar_wnt_.tmp
  1065. else
  1066. > _shar_wnt_.tmp
  1067. echo 'x - extracting ecuwinutil.c (Text)'
  1068. sed 's/^X//' << 'SHAR_EOF' > 'ecuwinutil.c' &&
  1069. X/*+-------------------------------------------------------------------------
  1070. X    ecuwinutil.c - curses window utilities
  1071. X    wht@n4hgf.Mt-Park.GA.US
  1072. X
  1073. X  Defined functions:
  1074. X    clear_area(win,y,x,len)
  1075. X    clear_area_char(win,y,x,len,fillchar)
  1076. X    winbox(win)
  1077. X    window_create(title,title_x,tly,tlx,lines,cols)
  1078. X    window_setup(win,title,title_x)
  1079. X    windows_end(last_win)
  1080. X    windows_end_signal()
  1081. X    windows_start()
  1082. X    winget_single(win,nondelim_list,delim_list)
  1083. X    wingets(win,y,x,buf,bufsize,delim,edit)
  1084. X
  1085. X--------------------------------------------------------------------------*/
  1086. X/*+:EDITS:*/
  1087. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  1088. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1089. X
  1090. X#include "ecucurses.h"
  1091. X#include <errno.h>
  1092. X#include "ecukey.h"
  1093. X#include "ecuxkey.h"
  1094. X#include "termecu.h"
  1095. X#include "pc_scr.h"
  1096. X
  1097. X#if !defined(ushort)
  1098. X#define ushort unsigned short
  1099. X#endif
  1100. X#if !defined(uchar)
  1101. X#define uchar unsigned char
  1102. X#endif
  1103. X#if !defined(uint)
  1104. X#define uint unsigned int
  1105. X#endif
  1106. X#if !defined(ulong)
  1107. X#define ulong unsigned long
  1108. X#endif
  1109. X
  1110. X#ifdef WHT /* for testing */
  1111. Xextern int tty_is_ansi;
  1112. X#endif
  1113. Xextern int tty_is_multiscreen;
  1114. X
  1115. Xunsigned char sTL = at_TL;
  1116. Xunsigned char sTR = at_TR;
  1117. Xunsigned char sBL = at_BL;
  1118. Xunsigned char sBR = at_BR;
  1119. Xunsigned char sLT = at_LT;
  1120. Xunsigned char sRT = at_RT;
  1121. Xunsigned char sVR = at_VR;
  1122. Xunsigned char sHR = at_HR;
  1123. X
  1124. Xint windows_active = 0;
  1125. Xint ttymode_before_window_start;
  1126. X
  1127. X/*+-------------------------------------------------------------------------
  1128. X    clear_area_char(win,y,x,len,fillchar)
  1129. X--------------------------------------------------------------------------*/
  1130. Xvoid
  1131. Xclear_area_char(win,y,x,len,fillchar)
  1132. XWINDOW *win;
  1133. Xint y;
  1134. Xint x;
  1135. Xint len;
  1136. Xchar fillchar;
  1137. X{
  1138. X    wmove(win,y,x);
  1139. X    while(len-- > 0)
  1140. X        waddch(win,fillchar & 0xFF);
  1141. X    wmove(win,y,x);
  1142. X
  1143. X}    /* end of clear_area_char */
  1144. X
  1145. X/*+-------------------------------------------------------------------------
  1146. X    clear_area(win,y,x,len)
  1147. X--------------------------------------------------------------------------*/
  1148. Xvoid
  1149. Xclear_area(win,y,x,len)
  1150. XWINDOW *win;
  1151. Xint y;
  1152. Xint x;
  1153. Xint len;
  1154. X{
  1155. X    clear_area_char(win,y,x,len,' ');
  1156. X}    /* end of clear_area_char */
  1157. X
  1158. X/*+-------------------------------------------------------------------------
  1159. X    windows_start()
  1160. X--------------------------------------------------------------------------*/
  1161. Xvoid
  1162. Xwindows_start()
  1163. X{
  1164. Xextern int tty_not_char_special;
  1165. X
  1166. X    if(tty_not_char_special)
  1167. X    {
  1168. X        errno = ENOTTY;
  1169. X        fprintf(stderr,"curses features unavailable when stdin not tty\r\n");
  1170. X        termecu(TERMECU_CURSES_ERROR);
  1171. X    }
  1172. X
  1173. X    ttymode_before_window_start = get_ttymode();
  1174. X    ttymode(0);
  1175. X    if(!initscr())
  1176. X    {
  1177. X        fprintf(stderr,"curses init failure ... check terminal type\r\n");
  1178. X        termecu(TERMECU_CURSES_ERROR);
  1179. X    }
  1180. X    savetty(); raw(); noecho(); nonl(); clear();
  1181. X#if defined(M_TERMINFO)
  1182. X    typeahead(-1);
  1183. X#endif
  1184. X    windows_active = 1;
  1185. X
  1186. X    if(!tty_is_multiscreen)
  1187. X    {
  1188. X        sTL = vanilla_TL;
  1189. X        sTR = vanilla_TR;
  1190. X        sBL = vanilla_BL;
  1191. X        sBR = vanilla_BR;
  1192. X        sLT = vanilla_LT;
  1193. X        sRT = vanilla_RT;
  1194. X        sVR = vanilla_VR;
  1195. X        sHR = vanilla_HR;
  1196. X    }
  1197. X
  1198. X}    /* end of windows_start */
  1199. X
  1200. X/*+-------------------------------------------------------------------------
  1201. X    windows_end(last_win)
  1202. X--------------------------------------------------------------------------*/
  1203. Xvoid
  1204. Xwindows_end(last_win)
  1205. XWINDOW *last_win;
  1206. X{
  1207. X    if(last_win)
  1208. X        wrefresh(last_win);
  1209. X/*
  1210. X    resetty();
  1211. X*/
  1212. X    endwin();
  1213. X    tcap_cursor(LINES - 1,0);
  1214. X    ttymode(ttymode_before_window_start);
  1215. X    windows_active = 0;
  1216. X}    /* end of windows_end */
  1217. X
  1218. X/*+-------------------------------------------------------------------------
  1219. X    windows_end2()
  1220. X--------------------------------------------------------------------------*/
  1221. Xvoid
  1222. Xwindows_end2()
  1223. X{
  1224. X    endwin();
  1225. X    ttymode(ttymode_before_window_start);
  1226. X    windows_active = 0;
  1227. X}    /* end of windows_end2 */
  1228. X
  1229. X/*+-------------------------------------------------------------------------
  1230. X    windows_end_signal() -- called by termecu()
  1231. X--------------------------------------------------------------------------*/
  1232. Xvoid
  1233. Xwindows_end_signal()
  1234. X{
  1235. X    windows_end2();
  1236. X}    /* end of windows_end_signal */
  1237. X
  1238. X/*+-------------------------------------------------------------------------
  1239. X    winbox(win)
  1240. X--------------------------------------------------------------------------*/
  1241. Xvoid
  1242. Xwinbox(win)
  1243. XWINDOW *win;
  1244. X{
  1245. X
  1246. X    box(win,sVR,sHR);
  1247. X    wmove(win,0,0); waddch(win,(unsigned)sTL);
  1248. X    wmove(win,win->_maxy - 1,0); waddch(win,(unsigned)sBL);
  1249. X    wmove(win,win->_maxy - 1,win->_maxx - 1); waddch(win,(unsigned)sBR);
  1250. X    wmove(win,0,win->_maxx - 1); waddch(win,(unsigned)sTR);
  1251. X
  1252. X}    /* end of winbox */
  1253. X
  1254. X/*+-------------------------------------------------------------------------
  1255. X    window_setup(win,title,title_x)
  1256. X--------------------------------------------------------------------------*/
  1257. Xvoid
  1258. Xwindow_setup(win,title,title_x)
  1259. XWINDOW *win;
  1260. Xchar *title;
  1261. Xint title_x;
  1262. X{
  1263. Xregister stand = (title_x < 0);
  1264. X
  1265. X    if(stand)
  1266. X        title_x = -title_x;
  1267. X
  1268. X    touchwin(win);
  1269. X    scrollok(win,0);        /* do not scroll */
  1270. X    winbox(win);
  1271. X    wmove(win,0,title_x);
  1272. X    if(stand)
  1273. X        wstandout(win);
  1274. X    waddch(win,'[');
  1275. X    wprintw(win," %s ",title);
  1276. X    waddch(win,']');
  1277. X    if(stand)
  1278. X        wstandend(win);
  1279. X}    /* end of window_setup */
  1280. X
  1281. X/*+-------------------------------------------------------------------------
  1282. X    window_create(title,title_x,tly,tlx,lines,cols)
  1283. Xif title_x negative, make title "stand" out
  1284. X--------------------------------------------------------------------------*/
  1285. XWINDOW *
  1286. Xwindow_create(title,title_x,tly,tlx,lines,cols)
  1287. Xchar *title;
  1288. Xint title_x;
  1289. Xint tly;
  1290. Xint tlx;
  1291. Xint lines;
  1292. Xint cols;
  1293. X{
  1294. Xregister WINDOW *nwin = newwin(lines,cols,tly,tlx);
  1295. X    
  1296. X    if(nwin)
  1297. X        window_setup(nwin,title,title_x);
  1298. X    else
  1299. X    {
  1300. X        fprintf(stderr,"\r\ncurses error: cannot create new window\r\n");
  1301. X        termecu(TERMECU_CURSES_ERROR);
  1302. X    }
  1303. X    return(nwin);
  1304. X}    /* end of window_create */
  1305. X
  1306. X/*+-------------------------------------------------------------------------
  1307. X    wingets
  1308. X numchars = wingets(win,y,x,buf,bufsize,&delim,edit)
  1309. X
  1310. XThis procedure reads a string from win and returns the number
  1311. Xof characters read.
  1312. X
  1313. XIf edit is non-zero and pstrpos is not null, the inital string
  1314. Xposition is set by dereferencing the pointer.
  1315. X
  1316. XThe terminating delim is returned in 'delim'.
  1317. X
  1318. XIf pstrpos is not null, the ending string position is returned in
  1319. Xthe integer pointed to.
  1320. X
  1321. X-1 is returned if an ESCape is typed by the keyboard user,
  1322. Xotherwise the count of characters in the string.
  1323. X
  1324. XThe entired line must be contained on one line (no line wrap supported).
  1325. X--------------------------------------------------------------------------*/
  1326. Xint
  1327. Xwingets(win,y,x,buf,bufsize,delim,edit,pstrpos)
  1328. XWINDOW *win;
  1329. Xint y;
  1330. Xregister x;
  1331. Xregister char *buf;
  1332. Xint bufsize;    /* includes room for null..field is 1 less */
  1333. Xregister uchar *delim;
  1334. Xint edit;
  1335. Xint *pstrpos;
  1336. X{
  1337. Xregister count = 0;
  1338. Xregister pos = 0;
  1339. Xint insert_mode = 0;
  1340. Xint rtn_val = 0;
  1341. X
  1342. X    bufsize--;
  1343. X    clear_area_char(win,y,x,bufsize,'_');
  1344. X    if(edit)
  1345. X    {
  1346. X        waddstr(win,buf);
  1347. X        count = pos = strlen(buf);
  1348. X        if(pstrpos)
  1349. X        {
  1350. X            pos = *pstrpos;
  1351. X            if((pos < 0) || (pos > count))
  1352. X                pos = count;
  1353. X        }
  1354. X    }
  1355. X    else
  1356. X        *buf = 0;
  1357. X    wmove(win,y,x + pos);
  1358. X
  1359. X    while(1)
  1360. X    {
  1361. X        wrefresh(win);
  1362. X        *delim = ttygetc(1);
  1363. X        if((*delim < 0x20) || (*delim >= 0x7F))
  1364. X        {
  1365. X            switch(*delim)
  1366. X            {
  1367. X                case CRET:
  1368. X                    *delim = NL;
  1369. X                case NL:
  1370. X                    wrefresh(win);
  1371. X                    rtn_val = count;
  1372. X                    goto RETURN;
  1373. X
  1374. X                case BS:
  1375. X                    if(count)
  1376. X                    {
  1377. X                        if(count == pos)
  1378. X                        {
  1379. X                            *(buf + --count) = 0;
  1380. X                            wmove(win,y,x + count);
  1381. X                            waddch(win,'_');
  1382. X                            wmove(win,y,x + count);
  1383. X                            pos--;
  1384. X                        }
  1385. X                        else
  1386. X                        {
  1387. X                            if(!pos)
  1388. X                                continue;
  1389. X                            mem_cpy(buf + pos - 1,buf + pos,count - pos);
  1390. X                            *(buf + --count) = 0;
  1391. X                            wmove(win,y,x + --pos);
  1392. X                            waddstr(win,buf + pos);
  1393. X                            waddch(win,'_');
  1394. X                            wmove(win,y,x + pos);
  1395. X                        }
  1396. X                    }
  1397. X                    continue;
  1398. X
  1399. X                case XFcurlf:
  1400. X                    if(pos)
  1401. X                        wmove(win,y,x + --pos);
  1402. X                    continue;
  1403. X
  1404. X                case XFcurrt:
  1405. X                    if(pos < count)
  1406. X                        wmove(win,y,x + ++pos);
  1407. X                    continue;
  1408. X
  1409. X                case XFins:
  1410. X                    insert_mode = !insert_mode;
  1411. X                    continue;
  1412. X
  1413. X                case ESC:
  1414. X                    rtn_val = -1;
  1415. X                    goto RETURN;
  1416. X
  1417. X                case CTL_U:
  1418. X                    clear_area_char(win,y,x,bufsize,'_');
  1419. X                    count = 0;
  1420. X                    pos = 0;
  1421. X                    *buf = 0;
  1422. X                    continue;
  1423. X
  1424. X                default:
  1425. X                    *(buf + count) = 0;
  1426. X                    rtn_val = count;
  1427. X                    goto RETURN;
  1428. X
  1429. X            }    /* end of switch(*delim) */
  1430. X            /*NOTREACHED*/
  1431. X        }        /* end of if read delimiter */
  1432. X
  1433. X        if(count == bufsize)
  1434. X        {
  1435. X            ring_bell();
  1436. X            continue;
  1437. X        }
  1438. X
  1439. X        if(insert_mode && (pos != count))
  1440. X        {
  1441. X            waddch(win,*delim);
  1442. X            waddstr(win,buf + pos);
  1443. X            mem_cpy(buf + pos + 1,buf + pos,count - pos);
  1444. X            *(buf + pos++) = *delim;
  1445. X            *(buf + ++count) = 0;
  1446. X            wmove(win,y,x + pos);
  1447. X        }
  1448. X        else
  1449. X        {
  1450. X            waddch(win,*delim);
  1451. X            *(buf + pos) = *delim;
  1452. X            if(pos == count)
  1453. X                *(buf + ++count) = 0;
  1454. X            pos++;
  1455. X        }
  1456. X    }    /* end of while can get character */
  1457. X
  1458. XRETURN:
  1459. X    if(pstrpos)
  1460. X        *pstrpos = pos;
  1461. X    return(rtn_val);
  1462. X
  1463. X}    /* end of wingets */
  1464. X
  1465. X/*+-------------------------------------------------------------------------
  1466. X    winget_single(win,nondelim_list,delim_list)
  1467. X
  1468. XThis procedure assumes cursor is positioned, repeats reading a non-echoing
  1469. Xcharacter from the keyboard until it matches a character in nondelim_list
  1470. Xor delim_list.  delim_list is expected to contain printable characters
  1471. Xand no upper-case characters.
  1472. X
  1473. XIf no match occurs, the bell is rung and the keyboard is read again.
  1474. X
  1475. XIf the input character matches a character in delim_list, the index (0-n)
  1476. Xof the character in delim_list is returned.  If a match occurs, an
  1477. Xupper-case version of the matching character is placed in the window.
  1478. X
  1479. XIf the input character matches a character in nondelim_list, the character
  1480. Xis returned or'ed with 0x1000
  1481. X
  1482. X--------------------------------------------------------------------------*/
  1483. Xint
  1484. Xwinget_single(win,nondelim_list,delim_list)
  1485. XWINDOW *win;
  1486. Xregister char *nondelim_list;
  1487. Xregister char *delim_list;
  1488. X{
  1489. Xregister itmp;
  1490. Xregister nlen = strlen(nondelim_list);
  1491. Xregister dlen = strlen(delim_list);
  1492. Xregister ichar;
  1493. X
  1494. X    wrefresh(win);
  1495. X
  1496. X    while(1)
  1497. X    {
  1498. X        ichar = to_lower(ttygetc(1));
  1499. X        for(itmp = 0; itmp < nlen; itmp++)
  1500. X        {
  1501. X            if(ichar == nondelim_list[itmp])
  1502. X            {
  1503. X                waddch(win,to_upper(ichar));
  1504. X                wrefresh(win);
  1505. X                return(itmp);
  1506. X            }
  1507. X        }
  1508. X        for(itmp = 0; itmp < dlen; itmp++)
  1509. X        {
  1510. X            if(ichar == delim_list[itmp])
  1511. X                return(ichar | 0x1000);
  1512. X        }
  1513. X        ring_bell();
  1514. X    }
  1515. X
  1516. X}    /* end of winget_single */
  1517. X
  1518. X/* end of ecuwinutil.c */
  1519. X/* vi: set tabstop=4 shiftwidth=4: */
  1520. SHAR_EOF
  1521. $TOUCH -am 0725125791 'ecuwinutil.c' &&
  1522. chmod 0644 ecuwinutil.c ||
  1523. echo 'restore of ecuwinutil.c failed'
  1524. Wc_c="`wc -c < 'ecuwinutil.c'`"
  1525. test 10243 -eq "$Wc_c" ||
  1526.     echo 'ecuwinutil.c: original size 10243, current size' "$Wc_c"
  1527. rm -f _shar_wnt_.tmp
  1528. fi
  1529. # ============= ecuxenix.c ==============
  1530. if test -f 'ecuxenix.c' -a X"$1" != X"-c"; then
  1531.     echo 'x - skipping ecuxenix.c (File already exists)'
  1532.     rm -f _shar_wnt_.tmp
  1533. else
  1534. > _shar_wnt_.tmp
  1535. echo 'x - extracting ecuxenix.c (Text)'
  1536. sed 's/^X//' << 'SHAR_EOF' > 'ecuxenix.c' &&
  1537. X/*+-----------------------------------------------------------------
  1538. X    ecuxenix.c -- very machine/OS dependent functions
  1539. X    wht@n4hgf.Mt-Park.GA.US
  1540. X
  1541. X  Defined functions:
  1542. X    bell_alarm(xbell_type)
  1543. X    bell_notify(xbell_type)
  1544. X    kbd_escape(xkey)
  1545. X    morse_bell(xbell_type,count)
  1546. X    rename(from,to)
  1547. X    send_bell_fd(fd,count,nap_msec)
  1548. X    send_get_response(token,narg,arg)
  1549. X    set_bell_fd(fd,pitch,duration)
  1550. X    set_default_escape_prompt()
  1551. X    show_escape_prompt()
  1552. X    signal_name_text(sig)
  1553. X    xbell(type,count)
  1554. X    xbell_fd(fd,type,count)
  1555. X
  1556. X  This module is a grab bag for historical reasons.  Needs reorg.
  1557. X------------------------------------------------------------------*/
  1558. X/*+:EDITS:*/
  1559. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  1560. X/*:07-17-1991-07:04-wht@n4hgf-avoid SCO UNIX nap bug */
  1561. X/*:07-14-1991-18:18-wht@n4hgf-new ttygets functions */
  1562. X/*:06-29-1991-15:42-wht@n4hgf-if WHT and xterm, play with title bar */
  1563. X/*:06-04-1991-13:19-wht@n4hgf-WHT version always gets morse for bells */
  1564. X/*:05-07-1991-06:10-wht@n4hgf-subtle changes in send_and_get_response */
  1565. X/*:03-18-1991-22:31-wht@n4hgf-ISC 2.2 has rename() */
  1566. X/*:01-16-1991-23:54-wht@n4hgf-if WHT, bell_notify always available */
  1567. X/*:01-09-1991-22:31-wht@n4hgf-ISC port */
  1568. X/*:12-04-1990-03:55-wht@n4hgf-bell_notify only if on multiscreen */
  1569. X/*:09-19-1990-19:36-wht@n4hgf-ecu_log_event now gets pid for log from caller */
  1570. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1571. X
  1572. X#include "ecu.h"
  1573. X#include "ecukey.h"
  1574. X#include "ecufkey.h"
  1575. X#include "ecuxkey.h"
  1576. X#include "ecutty.h"
  1577. X#include "ecufork.h"
  1578. X#include "esd.h"
  1579. X
  1580. X#if defined(MORSE)
  1581. X/* the space between # and include prevents make depend from seeing this */
  1582. X# include <local/morse_dvr.h>
  1583. X#endif
  1584. X
  1585. Xchar *get_ttyname();
  1586. X
  1587. Xextern char curr_dir[]; /* current working key defns */
  1588. Xextern KDE keyset_table[];
  1589. Xextern char keyset_name[];
  1590. Xextern int want_bell_notify;    /* want bell notify */
  1591. Xextern int rcvr_pid;
  1592. Xextern int sigint;
  1593. Xextern int tty_is_multiscreen;
  1594. X
  1595. XESD *icmd_prompt;        /* interactive command prompt */
  1596. Xint icmd_prompt_len;
  1597. X
  1598. X/*+-------------------------------------------------------------------------
  1599. X    show_escape_prompt()
  1600. Xreturns number of character positions written to screen
  1601. X--------------------------------------------------------------------------*/
  1602. Xshow_escape_prompt()
  1603. X{
  1604. Xchar prompt_last;
  1605. X
  1606. X    prompt_last = 'd';    /* dummy */
  1607. X    if(icmd_prompt->cb)
  1608. X        prompt_last = *(icmd_prompt->pb + icmd_prompt->cb - 1);
  1609. X
  1610. X    icmd_prompt_len = 0;
  1611. X    shmx_make_rcvr_sleep(1);
  1612. X    if(!(colors_current & 0xFFFF0000L) || !(colors_current & 0xFFFFL))
  1613. X        setcolor(colors_normal);
  1614. X    else
  1615. X        setcolor(colors_current);
  1616. X    tcap_stand_out();
  1617. X    if(icmd_prompt->cb)
  1618. X    {
  1619. X        ff(se," %s",icmd_prompt->pb);
  1620. X        icmd_prompt_len += icmd_prompt->cb + 1;
  1621. X    }
  1622. X    if(isalnum(prompt_last))
  1623. X    {
  1624. X        fputs(" %",se);
  1625. X        icmd_prompt_len += 2;
  1626. X    }
  1627. X    tcap_stand_end();
  1628. X    fputc(' ',se);
  1629. X    icmd_prompt_len++;
  1630. X    fflush(so);
  1631. X    return(icmd_prompt_len);
  1632. X
  1633. X}    /* end of show_escape_prompt */
  1634. X
  1635. X/*+-------------------------------------------------------------------------
  1636. X    set_default_escape_prompt()
  1637. X--------------------------------------------------------------------------*/
  1638. Xvoid
  1639. Xset_default_escape_prompt()
  1640. X{
  1641. Xregister char *cptr;
  1642. Xchar *getenv();
  1643. X
  1644. X    if((cptr = getenv("ECUPROMPT")) != (char *)0)
  1645. X    {
  1646. X        strncpy(icmd_prompt->pb,cptr,icmd_prompt->maxcb);
  1647. X        *(icmd_prompt->pb + icmd_prompt->maxcb - 1) = 0;
  1648. X        icmd_prompt->cb = strlen(icmd_prompt->pb);
  1649. X        esd_null_terminate(icmd_prompt);
  1650. X    }
  1651. X
  1652. X}    /* end of set_default_escape_prompt */
  1653. X
  1654. X/*+-------------------------------------------------------------------------
  1655. X    kbd_escape() -- xmtr got extended key -- process it
  1656. Xreturns(1)
  1657. X--------------------------------------------------------------------------*/
  1658. Xkbd_escape(xkey)
  1659. Xuchar xkey;
  1660. X{
  1661. Xregister itmp;
  1662. Xint ttygets_flags = TG_XDELIM;
  1663. Xuchar delim;
  1664. Xint strpos;
  1665. Xregister backspace_count;
  1666. Xregister KDE *tkde;
  1667. Xuchar icmd_buf[128];
  1668. X
  1669. X    if((xkey >= XF_ALTA) && (xkey <= XF_ALTZ))
  1670. X    {
  1671. X    char alt_key_proc_name[8];
  1672. X    char *arg = alt_key_proc_name;
  1673. X    int narg = 1;
  1674. X    int rcvr_alive = (rcvr_pid > 0);
  1675. X        sprintf(alt_key_proc_name,"alt_%c",xkey - XF_ALTA + 'a');
  1676. X        if(rcvr_alive)
  1677. X            kill_rcvr_process(SIGUSR1);
  1678. X        ttymode(2);
  1679. X        ttyflush(0);
  1680. X        if(do_proc(narg,&arg))
  1681. X            ring_bell();
  1682. X        sigint = 0;
  1683. X        proc_file_reset();
  1684. X        ttymode(1);
  1685. X        if(rcvr_alive)
  1686. X            start_rcvr_process(0);
  1687. X        return(1);
  1688. X    }
  1689. X
  1690. X    switch(xkey)
  1691. X    {
  1692. X        case XFhome:     /* home key pressed ? */
  1693. X            icmd_buf[0] = 0;
  1694. X            backspace_count = show_escape_prompt();
  1695. X            strpos = 0;
  1696. X            icmd_buf[0] = 0;
  1697. XGET_ICMD:
  1698. X            ttygets(icmd_buf,sizeof(icmd_buf),ttygets_flags,&delim,&strpos);
  1699. X            switch(delim)
  1700. X            {
  1701. X                case XFhome:
  1702. X                case XFend:
  1703. X                case XFpgup:
  1704. X                case XFpgdn:
  1705. X                case XFcurup:
  1706. X                case XFcurdn:
  1707. X                    if(icmd_history_manager(delim,icmd_buf,sizeof(icmd_buf)))
  1708. X                    {
  1709. X                        ring_bell();
  1710. X                        ttygets_flags |= 4;
  1711. X                        goto GET_ICMD;
  1712. X                    }
  1713. X                case ESC:
  1714. X                case NL:
  1715. X                    break;
  1716. X                default:
  1717. X                    ring_bell();
  1718. X                    ttygets_flags |= 4;
  1719. X                    goto GET_ICMD;
  1720. X            }
  1721. X            if((delim == ESC) || !icmd_buf[0])
  1722. X            {
  1723. X                while(backspace_count--)
  1724. X                    ff(se,"\b \b");
  1725. X                break;
  1726. X            }
  1727. X            if(icmd(icmd_buf))
  1728. X                termecu(TERMECU_OK);
  1729. X            break;
  1730. X
  1731. X        default:
  1732. X            if((itmp = xf_to_KDEt(xkey)) < 0)
  1733. X            {
  1734. X                ring_bell();
  1735. X                break;
  1736. X            }
  1737. X            tkde = &keyset_table[itmp];
  1738. X            if((itmp = tkde->count) > 0)
  1739. X            {
  1740. X            register char *cptr = tkde->str;
  1741. X                while(itmp--)
  1742. X                    lputc(*cptr++);
  1743. X            }
  1744. X            else if(tkde->count < 0)
  1745. X            {
  1746. X                switch(tkde->count)
  1747. X                {
  1748. X                    case KACT_LOCAL_SHELL:
  1749. X                        fputs("\r\n",se);
  1750. X                        tcap_stand_out();
  1751. X                        ff(se," local shell in %s ",curr_dir);
  1752. X                        tcap_stand_end();
  1753. X                        ff(se,"\r\n");
  1754. X                        shell("!");
  1755. X                        break;
  1756. X                    case KACT_REDISPLAY:
  1757. X                        redisplay_rcvr_screen();
  1758. X                }
  1759. X            }
  1760. X            else
  1761. X                ring_bell();
  1762. X            break;
  1763. X    }
  1764. X    return(1);
  1765. X}    /* end of kbd_escape */
  1766. X
  1767. X/*+-------------------------------------------------------------------------
  1768. X    set_bell_fd(fd,pitch,duration)
  1769. XExample: 1B 5B 3D 34 30 30 30 3B 31 42 | .[=4000;1B
  1770. X--------------------------------------------------------------------------*/
  1771. Xvoid
  1772. Xset_bell_fd(fd,pitch,duration)
  1773. Xint fd;
  1774. Xint pitch;
  1775. Xint duration;
  1776. X{
  1777. X#if defined(M_SYSV)
  1778. Xchar bell_cmd[32];
  1779. X
  1780. X    if(!tty_is_multiscreen)
  1781. X        return;
  1782. X
  1783. X    sprintf(bell_cmd,"\033[=%d;%dB",pitch,duration);
  1784. X    write(fd,bell_cmd,strlen(bell_cmd));
  1785. X#endif
  1786. X}    /* end of set_bell_fd */
  1787. X
  1788. X/*+-------------------------------------------------------------------------
  1789. X    send_bell_fd(fd,count,nap_msec)
  1790. X--------------------------------------------------------------------------*/
  1791. Xvoid
  1792. Xsend_bell_fd(fd,count,nap_msec)
  1793. Xregister fd;
  1794. Xregister count;
  1795. Xregister nap_msec;
  1796. X{
  1797. Xstatic char bellch = 0x07;
  1798. X
  1799. X    if(count)
  1800. X    {
  1801. X        while(count--)
  1802. X        {
  1803. X            write(fd,&bellch,1);    
  1804. X            nap((long)nap_msec);
  1805. X        }
  1806. X    }
  1807. X}    /* end of send_bell_fd */
  1808. X
  1809. X/*+-------------------------------------------------------------------------
  1810. X    xbell_fd(fd,type,count)
  1811. X--------------------------------------------------------------------------*/
  1812. Xvoid
  1813. Xxbell_fd(fd,type,count)
  1814. Xregister fd;
  1815. Xregister type;
  1816. Xregister count;
  1817. X{
  1818. X#if defined(M_SYSV)
  1819. Xregister itmp;
  1820. X
  1821. X    if(!tty_is_multiscreen)
  1822. X    {
  1823. X        ring_bell();
  1824. X        return;
  1825. X    }
  1826. X
  1827. X    if(count)
  1828. X    {
  1829. X        while(count--)
  1830. X        {
  1831. X            switch(type)
  1832. X            {
  1833. X                case XBELL_DONE:        /* octaves */
  1834. X                    set_bell_fd(fd,1000,1);
  1835. X                    send_bell_fd(fd,1,100);
  1836. X                    set_bell_fd(fd,2000,1);
  1837. X                    send_bell_fd(fd,1,100);
  1838. X                    set_bell_fd(fd,4000,1);
  1839. X                    send_bell_fd(fd,1,100);
  1840. X                    break;
  1841. X                case XBELL_ATTENTION:        /* morse .-.-.- ATTENTION */
  1842. X                    for(itmp = 0; itmp < 3; itmp++)
  1843. X                    {
  1844. X                        set_bell_fd(fd,2000,1);
  1845. X                        send_bell_fd(fd,1,140);
  1846. X                        set_bell_fd(fd,2000,3);
  1847. X                        send_bell_fd(fd,1,340);
  1848. X                    }
  1849. X                    break;
  1850. X                case XBELL_C:        /* morse -.-. C */
  1851. X                    for(itmp = 0; itmp < 2; itmp++)
  1852. X                    {
  1853. X                        set_bell_fd(fd,2000,3);
  1854. X                        send_bell_fd(fd,1,320);
  1855. X                        set_bell_fd(fd,2000,1);
  1856. X                        send_bell_fd(fd,1,120);
  1857. X                    }
  1858. X                    break;
  1859. X                case XBELL_3T:        /* 3 morse T's */
  1860. X                    set_bell_fd(fd,2000,3);
  1861. X                    send_bell_fd(fd,3,460);
  1862. X                    break;
  1863. X                default:
  1864. X                    set_bell_fd(fd,2000,4);
  1865. X                    send_bell_fd(fd,1,100);
  1866. X                    break;
  1867. X            }
  1868. X        }
  1869. X    }
  1870. X                
  1871. X    set_bell_fd(fd,4000,1);
  1872. X#endif    
  1873. X}    /* end of xbell_fd */
  1874. X
  1875. X/*+-------------------------------------------------------------------------
  1876. X    morse_bell(xbell_type,count)
  1877. X--------------------------------------------------------------------------*/
  1878. X#if defined(MORSE)
  1879. Xmorse_bell(xbell_type,count)
  1880. Xint xbell_type;
  1881. Xint count;
  1882. X{
  1883. Xregister morse_fd;
  1884. Xint morse_frequency = 800;
  1885. Xchar morse_char;
  1886. Xstatic int morse_ticks = 0;
  1887. X
  1888. X#if !defined(WHT)
  1889. X    if(!tty_is_multiscreen)
  1890. X    {
  1891. X        ring_bell();
  1892. X        return(0);
  1893. X    }
  1894. X#endif
  1895. X
  1896. X    if(!morse_ticks)
  1897. X        morse_ticks = hz / 25;
  1898. X
  1899. X    if((morse_fd = open("/dev/morse",O_WRONLY,0)) < 0)
  1900. X        return(-1);
  1901. X
  1902. X    ioctl(morse_fd,MORSE_SET_SPEED,&morse_ticks);
  1903. X    ioctl(morse_fd,MORSE_SET_FREQUENCY,&morse_frequency);
  1904. X    switch(xbell_type)
  1905. X    {
  1906. X        case XBELL_DONE:
  1907. X            morse_char = 'd';
  1908. X/*
  1909. X            morse_frequency = 400;
  1910. X            ioctl(morse_fd,MORSE_SET_FREQUENCY,&morse_frequency);
  1911. X*/
  1912. X            break;
  1913. X        case XBELL_ATTENTION:
  1914. X            morse_char = '.';
  1915. X            break;
  1916. X        case XBELL_C:
  1917. X            morse_char = 'c';
  1918. X            break;
  1919. X        case XBELL_3T:
  1920. X            morse_char = 'o';
  1921. X            break;
  1922. X        default:
  1923. X            morse_char = BT;
  1924. X            break;
  1925. X    }
  1926. X    while(count--)
  1927. X        write(morse_fd,&morse_char,1);
  1928. X    close(morse_fd);
  1929. X    return(0);
  1930. X}    /* end of morse_bell */
  1931. X#endif
  1932. X
  1933. X/*+-------------------------------------------------------------------------
  1934. X    xbell(type,count)
  1935. X--------------------------------------------------------------------------*/
  1936. Xvoid
  1937. Xxbell(type,count)
  1938. Xint type;
  1939. Xint count;
  1940. X{
  1941. X#if defined(WHT) && defined(MORSE)
  1942. X    if(morse_bell(type,count))
  1943. X        ring_bell();
  1944. X#else
  1945. X    if(!tty_is_multiscreen)
  1946. X    {
  1947. X        ring_bell();
  1948. X        return;
  1949. X    }
  1950. X
  1951. X#if defined(MORSE)
  1952. X    if(morse_bell(type,count))
  1953. X#endif
  1954. X        xbell_fd(1,type,count);
  1955. X#endif /* WHT && MORSE */
  1956. X
  1957. X}    /* end of xbell */
  1958. X
  1959. X/*+-------------------------------------------------------------------------
  1960. X    bell_alarm(xbell_type)
  1961. X  ring bell on multiscreens; if morse driver included, use it instead
  1962. X--------------------------------------------------------------------------*/
  1963. Xint
  1964. Xbell_alarm(xbell_type)
  1965. Xint xbell_type;
  1966. X{
  1967. Xregister notify_fd;
  1968. Xregister fork_pid;
  1969. Xstatic long notify_time = 0L;
  1970. Xchar *get_ttyname();
  1971. Xchar devname[64];
  1972. Xint devnum;
  1973. Xint ttnum;
  1974. Xlong time();
  1975. X
  1976. X#if defined(M_SYSV)
  1977. X#if !(defined(WHT) && defined(MORSE))
  1978. X    if(!tty_is_multiscreen)
  1979. X    {
  1980. X        ring_bell();
  1981. X        return(1);
  1982. X    }
  1983. X#endif
  1984. X
  1985. X    ttnum = atoi(get_ttyname() + 8);
  1986. X
  1987. X/* if happened less than 15 secs ago, forget it */
  1988. X    if((time((long *)0) - notify_time) < 15L)
  1989. X        return(0);
  1990. X
  1991. X    notify_time = time((long *)0);
  1992. X
  1993. X#if defined(MORSE)
  1994. X    if(morse_bell(xbell_type,1))
  1995. X    {
  1996. X#endif
  1997. X        if((fork_pid = smart_fork()) != 0)
  1998. X        {
  1999. X#if defined(FORK_DEBUG)
  2000. X            sprintf(devname,"DEBUG bell notify pid %d",fork_pid);
  2001. X            ecu_log_event(getpid(),devname);    /* bell notify */
  2002. X#endif
  2003. X            return(fork_pid > 0);
  2004. X        }
  2005. X
  2006. X        for(devnum = 1; devnum < 13; devnum++)
  2007. X        {
  2008. X            if(devnum == ttnum)        /* don't bell notify ecu's tty */
  2009. X                continue;
  2010. X            sprintf(devname,"/dev/tty%02d",devnum);
  2011. X            if((notify_fd = open(devname,O_WRONLY,0)) >= 0)
  2012. X            {
  2013. X                xbell_fd(notify_fd,xbell_type,1);
  2014. X                close(notify_fd);
  2015. X            }
  2016. X        }
  2017. X
  2018. X        _exit(0);        /* end of child tine (of the fork, naturally) */
  2019. X#if defined(MORSE)
  2020. X    }
  2021. X    /*NOTREACHED*/
  2022. X#endif
  2023. X#else /* not SCO (M_SYSV) */
  2024. X    ring_bell();
  2025. X#endif
  2026. X    return(1);
  2027. X}    /* end of bell_alarm */
  2028. X
  2029. X/*+-------------------------------------------------------------------------
  2030. X    bell_notify(xbell_type)
  2031. X--------------------------------------------------------------------------*/
  2032. Xvoid
  2033. Xbell_notify(xbell_type)
  2034. Xint xbell_type;
  2035. X{
  2036. X#if defined(M_SYSV)
  2037. X    if(
  2038. X#ifndef WHT
  2039. X        tty_is_multiscreen &&
  2040. X#endif
  2041. X             want_bell_notify)
  2042. X    {
  2043. X        bell_alarm(xbell_type);
  2044. X    }
  2045. X#endif
  2046. X}    /* end of bell_notify */
  2047. X
  2048. X/*+-------------------------------------------------------------------------
  2049. X    signal_name_text(sig)
  2050. X--------------------------------------------------------------------------*/
  2051. Xchar *
  2052. Xsignal_name_text(sig)
  2053. Xint sig;
  2054. X{
  2055. Xregister char *cptr;
  2056. Xstatic char sigunknown[20];
  2057. X
  2058. X    sig &= 0x7F;
  2059. X    switch(sig)
  2060. X    {
  2061. X        case SIGHUP:    cptr = "SIGHUP"; break;
  2062. X        case SIGINT:    cptr = "SIGINT"; break;
  2063. X        case SIGQUIT:    cptr = "SIGQUIT"; break;
  2064. X        case SIGILL:    cptr = "SIGILL"; break;
  2065. X        case SIGTRAP:    cptr = "SIGTRAP"; break;
  2066. X#ifdef SIGABRT
  2067. X        case SIGABRT:    cptr = "SIGABRT"; break;
  2068. X#else
  2069. X        case SIGIOT:    cptr = "SIGIOT"; break;
  2070. X#endif
  2071. X        case SIGEMT:    cptr = "SIGEMT"; break;
  2072. X        case SIGFPE:    cptr = "SIGFPE"; break;
  2073. X        case SIGKILL:    cptr = "SIGKILL"; break;
  2074. X        case SIGBUS:    cptr = "SIGBUS"; break;
  2075. X        case SIGSEGV:    cptr = "SIGSEGV"; break;
  2076. X        case SIGSYS:    cptr = "SIGSYS"; break;
  2077. X        case SIGPIPE:    cptr = "SIGPIPE"; break;
  2078. X        case SIGALRM:    cptr = "SIGALRM"; break;
  2079. X        case SIGTERM:    cptr = "SIGTERM"; break;
  2080. X        case SIGUSR1:    cptr = "SIGUSR1"; break;
  2081. X        case SIGUSR2:    cptr = "SIGUSR2"; break;
  2082. X        case SIGCLD:    cptr = "SIGCLD"; break;
  2083. X        case SIGPWR:    cptr = "SIGPWR"; break;
  2084. X#if    defined(SIGSTOP)
  2085. X        case SIGSTOP:   cptr = "SIGSTOP"; break;
  2086. X#endif
  2087. X#if    defined(SIGTSOP)
  2088. X        case SIGTSTP:   cptr = "SIGTSTP"; break;
  2089. X#endif
  2090. X#if    defined(SIGCONT)
  2091. X        case SIGCONT:   cptr = "SIGCONT"; break;
  2092. X#endif
  2093. X#if    defined(SIGTTIN)
  2094. X        case SIGTTIN:   cptr = "SIGTTIN"; break;
  2095. X#endif
  2096. X#if    defined(SIGTTOU)
  2097. X        case SIGTTOU:   cptr = "SIGTTOU"; break;
  2098. X#endif
  2099. X        default:
  2100. X            sprintf(sigunknown,"SIGNAL %u",sig);
  2101. X            return(sigunknown);
  2102. X    }
  2103. X    return(cptr);
  2104. X
  2105. X}    /* end of signal_name_text */
  2106. X
  2107. X/*+-------------------------------------------------------------------------
  2108. X    rename(from,to)
  2109. X--------------------------------------------------------------------------*/
  2110. X#if !defined(M_UNIX) && !defined(BUILDING_LINT_ARGS)
  2111. Xrename(from,to)
  2112. Xchar *from;
  2113. Xchar *to;
  2114. X{
  2115. Xstruct stat ss;
  2116. Xint save_errno;
  2117. Xextern int errno;
  2118. X
  2119. X    if(!stat(to,&ss))    /* if to exists, flunk */
  2120. X    {
  2121. X        errno = EEXIST;    /* fake "file exists" error */
  2122. X        return(-1);
  2123. X    }
  2124. X
  2125. X    if(link(from,to))    /* if cannot link, flunk */
  2126. X        return(-1);
  2127. X
  2128. X    if(unlink(from))    /* if cannot unlink, flunk */
  2129. X    {
  2130. X        save_errno = errno;
  2131. X        unlink(to);
  2132. X        errno = save_errno;
  2133. X        return(-1);
  2134. X    }
  2135. X
  2136. X    return(0);
  2137. X
  2138. X}    /* end of rename */
  2139. X#endif
  2140. X
  2141. X/*+-------------------------------------------------------------------------
  2142. X    send_get_response(token,narg,arg) - send a string, get and log response
  2143. X--------------------------------------------------------------------------*/
  2144. SHAR_EOF
  2145. true || echo 'restore of ecuxenix.c failed'
  2146. fi
  2147. echo 'End of ecu310 part 11'
  2148. echo 'File ecuxenix.c is continued in part 12'
  2149. echo 12 > _shar_seq_.tmp
  2150. exit 0
  2151. --------------------------------------------------------------------
  2152. Warren Tucker, TuckerWare emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
  2153. Hacker Extraordinaire  d' async PADs,  pods,  proteins and protocols
  2154.  
  2155. exit 0 # Just in case...
  2156. -- 
  2157. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2158. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2159. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2160. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2161.