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

  1. Newsgroups: comp.sources.misc
  2. Path: sparky!kent
  3. From: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
  4. Subject:  v32i049:  ecu - ECU Asynchronous Communications v3.20, Part14/40
  5. Message-ID: <1992Sep13.153528.5428@sparky.imd.sterling.com>
  6. Followup-To: comp.sources.d
  7. X-Md4-Signature: 2bdb7392c1efd7960ac7f6377a2d5073
  8. Sender: kent@sparky.imd.sterling.com (Kent Landfield)
  9. Organization: Sterling Software
  10. References: <csm-v32i036=ecu.141245@sparky.IMD.Sterling.COM>
  11. Date: Sun, 13 Sep 1992 15:35:28 GMT
  12. Approved: kent@sparky.imd.sterling.com
  13. Lines: 2175
  14.  
  15. Submitted-by: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
  16. Posting-number: Volume 32, Issue 49
  17. Archive-name: ecu/part14
  18. Environment: SCO,XENIX,ISC,SUNOS,SYSVR4,HDB,Curses
  19. Supersedes: ecu: Volume 21, Issue 53-89
  20.  
  21. ---- Cut Here and feed the following to sh ----
  22. #!/bin/sh
  23. # this is ecu320.14 (part 14 of ecu320)
  24. # do not concatenate these parts, unpack them in order with /bin/sh
  25. # file ecuusage.c continued
  26. #
  27. if test ! -r _shar_seq_.tmp; then
  28.     echo 'Please unpack part 1 first!'
  29.     exit 1
  30. fi
  31. (read Scheck
  32.  if test "$Scheck" != 14; then
  33.     echo Please unpack part "$Scheck" next!
  34.     exit 1
  35.  else
  36.     exit 0
  37.  fi
  38. ) < _shar_seq_.tmp || exit 1
  39. if test ! -f _shar_wnt_.tmp; then
  40.     echo 'x - still skipping ecuusage.c'
  41. else
  42. echo 'x - continuing file ecuusage.c'
  43. sed 's/^X//' << 'SHAR_EOF' >> 'ecuusage.c' &&
  44. X
  45. Xchar *usage_text[] = 
  46. X{
  47. X"usage: ecu [-l <ttyname>] [-b <baud_rate>] [-eon]\n",
  48. X"           [-h] [-t] [-P <phonedir>] [-F name] [-T <trace-level>]\n",
  49. X"           [-p <initial_proc> [-d] [-D] | <phone_number>]\n",
  50. X"-D unconditionally stop execution when -p initial procedure is done\n",
  51. X"-F sets an alternate funckeymap name for the *keyboard*\n",
  52. X"-P choose alternate phone directory (<phonedir> must be a full pathname)\n",
  53. X"-T set procedure tracing to level: 0=none, 1=standard, 2=ECU-debugging\n",
  54. X"-b choose baud rate (any UNIX rate 110-38400)\n",
  55. X"-d stop execution if -p initial procedure fails\n",
  56. X"-e even parity   -o odd parity   -n no parity\n",
  57. X"-h half duplex ... default is full duplex\n",
  58. X"-l choose line (/dev/<ttyname>)\n",
  59. X"-p execute an initial procedure\n",
  60. X"-t append NL to incoming and outgoing CR characters\n",
  61. X"<phone_number> is either an actual number or a directory entry name\n",
  62. X"\n",
  63. X"For interactive option selection, try executing ecu with no arguments\n",
  64. X"\n",
  65. X"For a list of built in commands, type HOME?<ENTER> once program started\n",
  66. X    (char *)0        /* terminated with null pointer */
  67. X};
  68. X
  69. Xchar *log_cmd_usage_text[] = 
  70. X{
  71. X"Usage: log [-s] [-r] <filename>\n",
  72. X"       log off   turn logging off\n",
  73. X" -s scratch any previous contents of <filename>, else append\n",
  74. X" -r raw log, else drop 0x00-0x08,0x11-0x1F,0x7F-0xFF\n",
  75. X    (char *)0        /* terminated with null pointer */
  76. X};
  77. X
  78. X/*+-----------------------------------------------------------------------
  79. X    general_usage(uptr)
  80. X------------------------------------------------------------------------*/
  81. Xvoid
  82. Xgeneral_usage(uptr)
  83. Xregister char **uptr;
  84. X{
  85. X    while(*uptr != (char *)0)
  86. X        pputs(*(uptr++));
  87. X}    /* end of usage */
  88. X
  89. X/*+-----------------------------------------------------------------------
  90. X    usage()
  91. X------------------------------------------------------------------------*/
  92. Xvoid
  93. Xusage()
  94. X{
  95. X    fprintf(stderr,"ecu %s made: %s\n",revstr,makedate);
  96. X    general_usage(usage_text);
  97. X    pprintf("\nDefaults: tty=%s baud=%d parity=%c\n",
  98. X        DEFAULT_TTY, DEFAULT_BAUD_RATE, DEFAULT_PARITY);
  99. X    termecu(TERMECU_USAGE);
  100. X    /*NOTREACHED*/
  101. X}
  102. X
  103. X/*+-------------------------------------------------------------------------
  104. X    log_cmd_usage()
  105. X--------------------------------------------------------------------------*/
  106. Xvoid
  107. Xlog_cmd_usage()
  108. X{
  109. X    general_usage(log_cmd_usage_text);
  110. X}    /* end of log_cmd_usage */
  111. X
  112. X/* vi: set tabstop=4 shiftwidth=4: */
  113. SHAR_EOF
  114. echo 'File ecuusage.c is complete' &&
  115. chmod 0644 ecuusage.c ||
  116. echo 'restore of ecuusage.c failed'
  117. Wc_c="`wc -c < 'ecuusage.c'`"
  118. test 3383 -eq "$Wc_c" ||
  119.     echo 'ecuusage.c: original size 3383, current size' "$Wc_c"
  120. rm -f _shar_wnt_.tmp
  121. fi
  122. # ============= ecuutil.c ==============
  123. if test -f 'ecuutil.c' -a X"$1" != X"-c"; then
  124.     echo 'x - skipping ecuutil.c (File already exists)'
  125.     rm -f _shar_wnt_.tmp
  126. else
  127. > _shar_wnt_.tmp
  128. echo 'x - extracting ecuutil.c (Text)'
  129. sed 's/^X//' << 'SHAR_EOF' > 'ecuutil.c' &&
  130. X/*+-----------------------------------------------------------------------
  131. X    ecuutil.c -- utility routines for extended calling unit
  132. X    wht@n4hgf.Mt-Park.GA.US
  133. X
  134. X
  135. X  Defined functions:
  136. X    arg_token(parsestr,termchars)
  137. X    ascii_name_to_hex(str3char)
  138. X    ascii_to_hex(ascii)
  139. X    build_arg_array(cmd,arg,arg_max_quan,narg_rtn)
  140. X    build_str_array(str,arg,str_max_quan,nstr_rtn)
  141. X    cfree(p,num,size)
  142. X    defeat_optimize_to_work_around_bug(would_be_optimized)
  143. X    disp_line_termio(fd,text)
  144. X    disp_stat(st)
  145. X    disp_termio(ttt,text)
  146. X    errno_text(err)
  147. X    find_shell_chars(command)
  148. X    get_curr_dir(cdir,cdir_max)
  149. X    get_home_dir(home_dir)
  150. X    hex_to_ascii_name(char_val)
  151. X    make_char_graphic(ch,incl_3char)
  152. X    make_ecu_subdir()
  153. X    mem_cpy(dest,src,len)
  154. X    mode_map(mode,mode_str)
  155. X    pad_zstr_to_len(zstr,len)
  156. X    perror_errmsg(str)
  157. X    rdchk(fd)
  158. X    skip_ld_break(zstr)
  159. X    str_classify(sc,str)
  160. X    str_token(parsestr,termchars)
  161. X    strip_trail_break(zstr)
  162. X    yes_or_no(strarg)
  163. X
  164. XThis module assumes the neo-standard 'mode_t' type is an unsigned
  165. Xshort and 'dev_t' is a short in accordance with tradition.  This
  166. Xis, in fact, true with all the supported systems which have it as
  167. Xof this writing.  This is just a test of the Brown Shirt Warning
  168. XSystem.  If this had been an actual Brown Shirt Alert, you would
  169. Xhave heard the noise of sickening thuds and breaking things nearby.
  170. X
  171. X------------------------------------------------------------------------*/
  172. X/*+:EDITS:*/
  173. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  174. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  175. X/*:05-11-1992-16:42-wht@gyro-fix WORKING_SELECT nap once and for all */
  176. X/*:05-08-1992-02:42-wht@n4hgf-select-based Nap was buggy on EINTR */
  177. X/*:04-05-1992-15:31-wht@n4hgf-no more use of memmove in any environment */
  178. X/*:02-22-1992-16:19-wht@n4hgf-build arg/str array now handles zero tokens */
  179. X/*:11-26-1991-19:36-wht@n4hgf-add str_classify and yes_or_no uses it */
  180. X/*:09-01-1991-12:46-wht@n4hgf2-show sun flow control bit */
  181. X/*:08-30-1991-20:09-wht@n4hgf2-sun Nap was not returning a value */
  182. X/*:08-25-1991-14:39-wht@n4hgf-SVR4 port thanks to aega84!lh */
  183. X/*:08-17-1991-14:11-root@n4hgf-ascii_to_hex supports "csi" */
  184. X/*:08-13-1991-13:53-wht@n4hgf-UNIX and ISC nap() broken; XENIX still wins */
  185. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  186. X/*:04-16-1991-15:45-wht@n4hgf-gcc cannot use memmove */
  187. X/*:03-18-1991-22:31-wht@n4hgf-ISC 2.2 has mkdir() */
  188. X/*:02-03-1991-14:23-wht@n4hgf-hack workaround for get_home_dir under x286 */
  189. X/*:01-25-1991-16:23-wht@n4hgf-source name wrong in headers */
  190. X/*:12-26-1990-14:32-wht@n4hgf-use memmove or Duff's Device in mem_cpy() */
  191. X/*:12-04-1990-00:58-wht@n4hgf-allow alternating between str/arg_token */
  192. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  193. X
  194. X#include "ecu.h"
  195. X#include "termecu.h"
  196. X#include "ecufork.h"
  197. X#include "ecukey.h"
  198. X#include "ecu_pwd.h"
  199. X
  200. X#if defined(sun)
  201. X#undef ECHO
  202. X#undef NL0
  203. X#undef NL1
  204. X#undef TAB0
  205. X#undef TAB1
  206. X#undef TAB2
  207. X#undef XTABS
  208. X#undef CR0
  209. X#undef CR1
  210. X#undef CR2
  211. X#undef CR3
  212. X#undef FF0
  213. X#undef FF1
  214. X#undef BS0
  215. X#undef BS1
  216. X#undef TOSTOP
  217. X#undef FLUSHO
  218. X#undef PENDIN
  219. X#undef NOFLSH
  220. X#include <sys/ioctl.h>
  221. X#endif
  222. X
  223. X#if defined(SVR4)
  224. X# include <sys/termiox.h>
  225. Xextern int hx_flag;
  226. X#endif
  227. X
  228. Xchar *getenv();
  229. X
  230. Xextern int errno;
  231. Xextern char curr_dir[CURR_DIRSIZ];
  232. X
  233. Xchar *str_token_static = (char *)0;
  234. X
  235. Xchar *ascii_ctlstr =
  236. X"NULSOHSTXETXEOTENQACKBELBS HT NL VT FF CR SO SI DLEDC1DC2DC3DC4NAKSYNETBCANEM SUBESCFS GS RS US SP ";
  237. X
  238. X/*+-------------------------------------------------------------------------
  239. X    mem_cpy(dest,src,len) - memcpy() with non-destructive overlapping copy
  240. X
  241. X  use Duff's device for speed if memmove not available
  242. X--------------------------------------------------------------------------*/
  243. Xvoid
  244. Xmem_cpy(dest,src,len)
  245. Xregister char *dest;
  246. Xregister char *src;
  247. Xregister len;
  248. X{
  249. X#if 0 /* defined(M_UNIX) && !defined(DUFF)*/ /*  && !defined(__GNUC__) */
  250. X    /*
  251. X     * memmove() clobbers regs that GCC wants to keep
  252. X     * unless you use -fcall-save-bx
  253. X     */
  254. X    memmove(dest,src,len);
  255. X#else
  256. X    /*
  257. X     * for systems without memmove or with compiler that cannot use it
  258. X     */
  259. X
  260. X    register itmp = (len + 7) / 8;
  261. X    if(dest > src)
  262. X    {
  263. X        dest += len;
  264. X        src += len;
  265. X        switch(len % 8)
  266. X        {
  267. X        case 0:    do{    *--dest = *--src;
  268. X        case 7:        *--dest = *--src;
  269. X        case 6:        *--dest = *--src;
  270. X        case 5:        *--dest = *--src;
  271. X        case 4:        *--dest = *--src;
  272. X        case 3:        *--dest = *--src;
  273. X        case 2:        *--dest = *--src;
  274. X        case 1:        *--dest = *--src;
  275. X                 }while(--itmp > 0);
  276. X        }
  277. X    }
  278. X    else
  279. X    {
  280. X        switch(len % 8)
  281. X        {
  282. X        case 0:    do{    *dest++ = *src++;
  283. X        case 7:        *dest++ = *src++;
  284. X        case 6:        *dest++ = *src++;
  285. X        case 5:        *dest++ = *src++;
  286. X        case 4:        *dest++ = *src++;
  287. X        case 3:        *dest++ = *src++;
  288. X        case 2:        *dest++ = *src++;
  289. X        case 1:        *dest++ = *src++;
  290. X                 }while(--itmp > 0);
  291. X        }
  292. X    }
  293. X#endif
  294. X}    /* end of mem_cpy */
  295. X
  296. X/*+-------------------------------------------------------------------------
  297. X    skip_ld_break(zstr) - skip leading spaces and tabs
  298. X--------------------------------------------------------------------------*/
  299. Xchar *
  300. Xskip_ld_break(zstr)
  301. Xregister char *zstr;
  302. X{
  303. X    while(isspace(*zstr))
  304. X        zstr++;
  305. X    return(zstr);
  306. X}    /* end of skip_ld_break */
  307. X
  308. X/*+-------------------------------------------------------------------------
  309. X    strip_trail_break(zstr) - strip leading spaces and tabs
  310. X--------------------------------------------------------------------------*/
  311. Xvoid
  312. Xstrip_trail_break(zstr)
  313. Xchar *zstr;
  314. X{
  315. X    register int itmp = strlen(zstr);
  316. X    register char *zptr = zstr + itmp - 1;
  317. X
  318. X    while(itmp && isspace(*zptr))
  319. X    {
  320. X        *zptr-- = 0;
  321. X        itmp--;
  322. X    }
  323. X}    /* end of strip_trail_break */
  324. X
  325. X/*+-----------------------------------------------------------------------
  326. X    pad_zstr_to_len(zstr,len)
  327. X
  328. X  pads with spaces to specified length, unless already longer than
  329. X  len in which case the string is truncated to 'len' characters.
  330. X------------------------------------------------------------------------*/
  331. Xvoid
  332. Xpad_zstr_to_len(zstr,len)
  333. Xchar *zstr;
  334. Xint len;
  335. X{
  336. X    register izstr;
  337. X
  338. X    izstr = strlen(zstr);
  339. X    if(izstr >= len)
  340. X        zstr[len] = 0;
  341. X    else
  342. X    {
  343. X        while(izstr < len)
  344. X            zstr[izstr++] = 0x20;
  345. X        zstr[izstr] = 0;
  346. X    }
  347. X}    /* end of pad_zstr_to_len */
  348. X
  349. X/*+-----------------------------------------------------------------------
  350. X    arg_token(parsestr,termchars)
  351. X
  352. XGet next token from string parsestr ((char *)0 on 2nd, 3rd, etc.
  353. Xcalls), where tokens are nonempty strings separated by runs of chars
  354. Xfrom termchars.  Writes nulls into parsestr to end tokens.
  355. Xtermchars need not remain constant from call to call.
  356. X
  357. XTreats multiple occurrences of a termchar as one delimiter (does not
  358. Xallow null fields).
  359. X------------------------------------------------------------------------*/
  360. Xchar *
  361. Xarg_token(parsestr,termchars)
  362. Xchar *parsestr;
  363. Xchar *termchars;
  364. X{
  365. X    register char *parseptr;
  366. X    char *token;
  367. X
  368. X    if(!parsestr && !str_token_static)
  369. X        return((char *)0);
  370. X
  371. X    if(parsestr)
  372. X    {
  373. X        str_token_static = (char *)0;
  374. X        parseptr = parsestr;
  375. X    }
  376. X    else
  377. X       parseptr = str_token_static;
  378. X
  379. X    while(*parseptr)
  380. X    {
  381. X        if(!strchr(termchars,*parseptr))
  382. X            break;
  383. X        parseptr++;
  384. X    }
  385. X
  386. X    if(!*parseptr)
  387. X    {
  388. X        str_token_static = (char *)0;
  389. X        return((char *)0);
  390. X    }
  391. X
  392. X    token = parseptr;
  393. X    if(*token == '\'')
  394. X    {
  395. X        token++;
  396. X        parseptr++;
  397. X        while(*parseptr)
  398. X        {
  399. X            if(*parseptr == '\'')
  400. X            {
  401. X                str_token_static = parseptr + 1;
  402. X                *parseptr = 0;
  403. X                return(token);
  404. X            }
  405. X            parseptr++;
  406. X        }
  407. X        str_token_static = (char *)0;
  408. X        return(token);
  409. X    }
  410. X    while(*parseptr)
  411. X    {
  412. X        if(strchr(termchars,*parseptr))
  413. X        {
  414. X            *parseptr = 0;
  415. X            str_token_static = parseptr + 1;
  416. X            while(*str_token_static)
  417. X            {
  418. X                if(!strchr(termchars,*str_token_static))
  419. X                    break;
  420. X                str_token_static++;
  421. X            }
  422. X            return(token);
  423. X        }
  424. X        parseptr++;
  425. X    }
  426. X    str_token_static = (char *)0;
  427. X    return(token);
  428. X}    /* end of arg_token */
  429. X
  430. X/*+-------------------------------------------------------------------------
  431. X    build_arg_array(cmd,arg,arg_max_quan,&narg)
  432. X--------------------------------------------------------------------------*/
  433. Xvoid
  434. Xbuild_arg_array(cmd,arg,arg_max_quan,narg_rtn)
  435. Xchar *cmd;
  436. Xchar **arg;
  437. Xint arg_max_quan;
  438. Xint *narg_rtn;
  439. X{
  440. X    register narg;
  441. X
  442. X    str_token_static = (char *)0;
  443. X    memset((char *)arg,0,sizeof(char *) * arg_max_quan);
  444. X    if(!(arg[0] = arg_token(cmd," \t\r\n")))
  445. X    {
  446. X        *narg_rtn = 0;
  447. X        return;
  448. X    }
  449. X
  450. X    for(narg = 1; narg < arg_max_quan; ++narg)
  451. X    {
  452. X        if(!(arg[narg] = arg_token((char *)0," \t\r\n"))) 
  453. X            break;
  454. X    }
  455. X
  456. X    *narg_rtn = narg;
  457. X
  458. X}    /* end of build_arg_array */
  459. X
  460. X/*+-----------------------------------------------------------------------
  461. X    str_token(parsestr,termchars)
  462. X
  463. XGet next token from string parsestr ((char *)0 on 2nd, 3rd, etc.
  464. Xcalls), where tokens are nonempty strings separated by runs of chars
  465. Xfrom termchars.  Writes nulls into parsestr to end tokens.
  466. Xtermchars need not remain constant from call to call.
  467. X
  468. XTreats each occurrence of a termchar as delimiter (allows null
  469. Xfields).
  470. X------------------------------------------------------------------------*/
  471. Xchar *
  472. Xstr_token(parsestr,termchars)
  473. Xchar *parsestr;
  474. Xchar *termchars;
  475. X{
  476. X    register char *termptr;
  477. X    register char *parseptr;
  478. X    char *token;
  479. X
  480. X    if(!parsestr && !str_token_static)
  481. X        return((char *)0);
  482. X
  483. X    if(parsestr)
  484. X    {
  485. X        str_token_static = (char *)0;
  486. X        parseptr = parsestr;
  487. X    }
  488. X    else
  489. X       parseptr = str_token_static;
  490. X
  491. X    while(*parseptr)
  492. X    {
  493. X        for(termptr = termchars; *termptr != 0; termptr++)
  494. X        {
  495. X            if(*parseptr == *termptr)
  496. X                goto FOUND_TERM;
  497. X        }
  498. X        if(!*termptr)
  499. X            break;
  500. X        parseptr++;
  501. X    }
  502. X
  503. X    if(!*parseptr)
  504. X    {
  505. X        str_token_static = (char *)0;
  506. X        return((char *)0);
  507. X    }
  508. X
  509. XFOUND_TERM:
  510. X    token = parseptr;
  511. X    while(*parseptr)
  512. X    {
  513. X        for(termptr = termchars; *termptr;)
  514. X        {
  515. X            if(*parseptr == *termptr++)
  516. X            {
  517. X                str_token_static = parseptr + 1;
  518. X                *parseptr = 0;
  519. X                return(token);
  520. X            }
  521. X        }
  522. X        parseptr++;
  523. X    }
  524. X    str_token_static = (char *)0;
  525. X    return(token);
  526. X}    /* end of str_token */
  527. X
  528. X/*+-------------------------------------------------------------------------
  529. X    build_str_array(str,arg,arg_max_quan,&narg)
  530. X--------------------------------------------------------------------------*/
  531. Xvoid
  532. Xbuild_str_array(str,arg,arg_max_quan,narg_rtn)
  533. Xchar *str;
  534. Xchar **arg;
  535. Xint arg_max_quan;
  536. Xint *narg_rtn;
  537. X{
  538. X    register narg;
  539. X
  540. X    str_token_static = (char *)0;
  541. X    memset((char *)arg,0,sizeof(char *) * arg_max_quan);
  542. X    if(!(arg[0] = str_token(str," \t\r\n")))
  543. X    {
  544. X        *narg_rtn = 0;
  545. X        return;
  546. X    }
  547. X
  548. X    for(narg = 1; narg < arg_max_quan; ++narg)
  549. X    {
  550. X        if(!(arg[narg] = str_token((char *)0," \t\r\n"))) 
  551. X            break;
  552. X    }
  553. X
  554. X    *narg_rtn = narg;
  555. X
  556. X}    /* end of build_str_array */
  557. X
  558. X/*+-----------------------------------------------------------------------
  559. X    make_char_graphic(character,incl_3char) - Make all chars "printable"
  560. X
  561. X  returns pointer to a static string containing printable version
  562. X  of a character.  If control char, printed as "^A", etc.
  563. X  if incl_3char set true, then space + ASCII assignment (e.g. "NUL") is
  564. X  appended to the string for non-printable graphics
  565. X------------------------------------------------------------------------*/
  566. Xchar *
  567. Xmake_char_graphic(ch,incl_3char)
  568. Xregister char ch;
  569. Xint incl_3char;
  570. X{
  571. X    static char gg[16];
  572. X
  573. X    ch &= 0x7F;
  574. X    if((ch >= 0x20) && (ch < 0x7F))
  575. X    {
  576. X        gg[0] = ch; gg[1] = 0;
  577. X    }
  578. X    else
  579. X    {
  580. X        gg[0] = '^'; 
  581. X        if(ch == 0x7F)
  582. X        {
  583. X            gg[1] = '?';
  584. X            if(incl_3char)
  585. X                strcpy(&gg[2]," DEL");
  586. X            else
  587. X                gg[2] = 0;
  588. X        }
  589. X        else
  590. X        {
  591. X            gg[1] = ch + 0x40;
  592. X            if(incl_3char)
  593. X            {
  594. X                gg[2] = 0x20;
  595. X                strncpy(&gg[3],ascii_ctlstr + (ch * 3),3);
  596. X                gg[7] = 0;
  597. X            }
  598. X            else
  599. X                gg[2] = 0;
  600. X        }
  601. X    }
  602. X    return(gg);
  603. X}    /* end of make_char_graphic */
  604. X
  605. X/*+-----------------------------------------------------------------------
  606. X    mode_map(mode,mode_str)    build drwxrwxrwx string
  607. X------------------------------------------------------------------------*/
  608. Xchar *
  609. Xmode_map(mode,mode_str)
  610. Xunsigned short mode;
  611. Xchar *mode_str;
  612. X{
  613. X    register unsigned ftype = mode & S_IFMT;
  614. X    register char *rtn;
  615. X    static char result[12];
  616. X
  617. X    rtn = (mode_str == (char *)0) ? result : mode_str;
  618. X
  619. X    /*               drwxrwxrwx */
  620. X    /*               0123456789 */
  621. X    strcpy(rtn,"----------");
  622. X
  623. X    switch(ftype)
  624. X    {
  625. X        case S_IFIFO:    *rtn = 'p'; break; /* FIFO (named pipe) */
  626. X        case S_IFDIR:    *rtn = 'd'; break; /* directory */
  627. X        case S_IFCHR:    *rtn = 'c'; break; /* character special */
  628. X        case S_IFBLK:    *rtn = 'b'; break; /* block special */
  629. X        case S_IFREG:    *rtn = '-'; break; /* regular */
  630. X
  631. X#if defined(S_IFLNK)
  632. X        case S_IFLNK:    *rtn = 'l'; break; /* symbolic link */
  633. X#endif
  634. X#if defined(S_IFSOCK)
  635. X        case S_IFSOCK:    *rtn = 's'; break; /* socket */
  636. X#endif
  637. X
  638. X#if defined(S_IFNAM)
  639. X        case S_IFNAM:                        /* name space entry */
  640. X#if defined(S_IFNAM)
  641. X            if(mode & S_INSEM)                /* semaphore */
  642. X            {
  643. X                *rtn = 's';
  644. X                break;
  645. X            }
  646. X#endif
  647. X#if defined(S_INSHD)
  648. X            if(mode & S_INSHD)                /* shared memory */
  649. X            {
  650. X                *rtn = 'm';
  651. X                break;
  652. X            }
  653. X            break;
  654. X#endif
  655. X#endif
  656. X
  657. X        default:        *rtn = '?'; break;    /* ??? */
  658. X    }
  659. X
  660. X    if(mode & 000400) *(rtn + 1) = 'r';
  661. X    if(mode & 000200) *(rtn + 2) = 'w';
  662. X    if(mode & 000100) *(rtn + 3) = 'x';
  663. X    if(mode & 004000) *(rtn + 3) = 's';
  664. X    if(mode & 000040) *(rtn + 4) = 'r';
  665. X    if(mode & 000020) *(rtn + 5) = 'w';
  666. X    if(mode & 000010) *(rtn + 6) = 'x';
  667. X    if(mode & 002000) *(rtn + 6) = 's';
  668. X    if(mode & 000004) *(rtn + 7) = 'r';
  669. X    if(mode & 000002) *(rtn + 8) = 'w';
  670. X    if(mode & 000001) *(rtn + 9) = 'x';
  671. X    if(mode & 001000) *(rtn + 9) = 't';
  672. X
  673. X    return(rtn);
  674. X
  675. X}    /* end of mode_map */
  676. X
  677. X/*+-----------------------------------------------------------------------
  678. X    disp_termio(ttt)
  679. X  display termio 'ttt' on stderr
  680. X------------------------------------------------------------------------*/
  681. Xvoid disp_termio(ttt,text)
  682. Xstruct termio *ttt;
  683. Xchar *text;
  684. X{
  685. X    register flag;
  686. X    register i_cc;
  687. X    register char *cptr;
  688. X    int dbits;
  689. X    char parity;
  690. X
  691. X    pprintf("---------> %s\n",text);
  692. X
  693. X    flag = ttt->c_iflag;
  694. X    pprintf(
  695. X"iflag: %07o IGNBRK:%d  BRKINT:%d  IGNPAR:%d  PARMRK:%d  INPCK:%d  ISTRIP:%d\n",
  696. X                flag,
  697. X                (flag & IGNBRK) ? 1 : 0,
  698. X                (flag & BRKINT) ? 1 : 0,
  699. X                (flag & IGNPAR) ? 1 : 0,
  700. X                (flag & PARMRK) ? 1 : 0,
  701. X                (flag & INPCK ) ? 1 : 0,
  702. X                (flag & ISTRIP) ? 1 : 0);
  703. X    pprintf("               INLCR:%d  IGNCR:%d  ICRNL:%d  IUCLC:%d  ",
  704. X                (flag & INLCR ) ? 1 : 0,
  705. X                (flag & IGNCR ) ? 1 : 0,
  706. X                (flag & ICRNL ) ? 1 : 0,
  707. X                (flag & IUCLC ) ? 1 : 0);
  708. X    pprintf("IXON:%d  IXANY:%d  IXOFF:%d\n",
  709. X                (flag & IXON  ) ? 1 : 0,
  710. X                (flag & IXANY ) ? 1 : 0,
  711. X                (flag & IXOFF ) ? 1 : 0);
  712. X
  713. X    flag = ttt->c_oflag;
  714. X    pprintf("oflag: %07o OPOST:%d  OLCUC:%d  ONLCR:%d  OCRNL:%d  ",
  715. X                flag,
  716. X                (flag & OPOST ) ? 1 : 0,
  717. X                (flag & OLCUC ) ? 1 : 0,
  718. X                (flag & ONLCR ) ? 1 : 0,
  719. X                (flag & OCRNL ) ? 1 : 0);
  720. X    pprintf("ONOCR:%d  ONLRET:%d  OFDEL:%d\n",
  721. X                (flag & ONOCR ) ? 1 : 0,
  722. X                (flag & ONLRET) ? 1 : 0,
  723. X                (flag & OFDEL ) ? 1 : 0);
  724. X
  725. X    flag = ttt->c_cflag;
  726. X    pprintf("cflag: %07o ",ttt->c_cflag);
  727. X    switch(flag & CBAUD)
  728. X    {
  729. X        case B0:    cptr = "HUP"; break;
  730. X        case B50:    cptr = "50"; break;
  731. X        case B75:    cptr = "75"; break;
  732. X        case B110:    cptr = "110"; break;
  733. X        case B134:    cptr = "134.5"; break;
  734. X        case B150:    cptr = "150"; break;
  735. X        case B200:    cptr = "200"; break;
  736. X        case B300:    cptr = "300"; break;
  737. X        case B600:    cptr = "600"; break;
  738. X        case B1200:    cptr = "1200"; break;
  739. X        case B1800:    cptr = "1800"; break;
  740. X        case B2400:    cptr = "2400"; break;
  741. X        case B4800:    cptr = "4800"; break;
  742. X        case B9600:    cptr = "9600"; break;
  743. X#if defined(B19200)
  744. X        case B19200:cptr = "19200"; break;
  745. X#endif
  746. X#if defined(B38400)
  747. X        case B38400:cptr = "38400"; break;
  748. X#endif
  749. X        default:    
  750. X            switch(flag & CBAUD)
  751. X            {
  752. X                case EXTA:    cptr = "EXTA"; break;
  753. X                case EXTB:    cptr = "EXTB"; break;
  754. X                default:    cptr = "????"; break;
  755. X            }
  756. X    }
  757. X    dbits = 5 + ((flag & CSIZE) >> 4);
  758. X    parity = (flag & PARENB) ? ((flag & PARODD) ? 'O' : 'E') : 'N';
  759. X    pprintf("%s-%d-%c-%d ",cptr,dbits,parity,(flag & CSTOPB) ? 2 : 1);
  760. X    switch(flag & CS8)
  761. X    {
  762. X        case CS8: pputs("CS8 "); break;
  763. X        case CS7: pputs("CS7 "); break;
  764. X        case CS6: pputs("CS6 "); break;
  765. X        case CS5: pputs("CS5 "); break;
  766. X    }
  767. X    pprintf("CREAD:%d  HUPCL:%d  CLOCAL:%d",
  768. X                (flag & CREAD ) ? 1 : 0,
  769. X                (flag & HUPCL ) ? 1 : 0,
  770. X                (flag & CLOCAL) ? 1 : 0);
  771. X#if defined(RTSFLOW) /* SCO */
  772. X    pprintf(" RTSFLOW:%d  CTSFLOW:%d",
  773. X                (flag & RTSFLOW ) ? 1 : 0,
  774. X                (flag & CTSFLOW ) ? 1 : 0);
  775. X#endif
  776. X#if defined(CRTSFL) /* SCO 3.2v4 */
  777. X    pprintf("\n               CRTSFL:%d",
  778. X                (flag & CRTSFL ) ? 1 : 0);
  779. X#endif
  780. X#if defined(RTSXOFF) /* SVR4 */
  781. X    pprintf(" RTSXOFF:%d  CTSXON:%d",
  782. X                (hx_flag & RTSXOFF ) ? 1 : 0,
  783. X                (hx_flag & CTSXON ) ? 1 : 0);
  784. X#endif
  785. X#ifdef CRTSCTS /* sun */
  786. X    pprintf(" CRTSCTS:%d",(flag & CRTSCTS) ? 1 : 0);
  787. X#endif
  788. X    pprintf("\n");
  789. X
  790. X    flag = ttt->c_lflag;
  791. X    pprintf("lflag: %07o ISIG:%d  ICANON:%d  XCASE:%d  ECHO:%d  ECHOE:%d\n",
  792. X                flag,
  793. X                (flag & ISIG  ) ? 1 : 0,
  794. X                (flag & ICANON) ? 1 : 0,
  795. X                (flag & XCASE ) ? 1 : 0,
  796. X                (flag & ECHO  ) ? 1 : 0,
  797. X                (flag & ECHOE ) ? 1 : 0);
  798. X    pprintf("               ECHOK:%d  ECHONL:%d  NOFLSH:%d",
  799. X                (flag & ECHOK ) ? 1 : 0,
  800. X                (flag & ECHONL) ? 1 : 0,
  801. X                (flag & NOFLSH) ? 1 : 0);
  802. X
  803. X#if defined(XCLUDE)
  804. X    pprintf("  XCLUDE:%d",(flag & XCLUDE) ? 1 : 0);
  805. X#endif
  806. X    pputs("\n");
  807. X
  808. X    pprintf("ctl chars: ");
  809. X    for(i_cc = 0; i_cc < NCC; i_cc++)
  810. X        pprintf("%02x   ",ttt->c_cc[i_cc]);
  811. X    pputs("  (hex)\n");
  812. X    pputs("           INTR QUIT ERAS KILL EOF  EOL  ");
  813. X    pputs("EOL2 SWTCH  VMIN-EOF VTIME-EOL\n");
  814. X
  815. X}    /* end of disp_termio */
  816. X
  817. X/*+-------------------------------------------------------------------------
  818. X    disp_stat(st)
  819. X--------------------------------------------------------------------------*/
  820. Xvoid
  821. Xdisp_stat(st)
  822. Xstruct stat *st;
  823. X{
  824. X    char mdmap[32];
  825. X    mode_map(st->st_mode,mdmap);
  826. X    pprintf("mode: %s ",mdmap);
  827. X    pprintf("inode: %5u  dev: %3u rdev: %u,%u (0x%04x)\n",
  828. X        (uint)st->st_ino,(uint)st->st_dev,
  829. X        (ushort)st->st_rdev >> 8,(ushort)st->st_rdev & 0xFF,
  830. X        (ushort)st->st_rdev);
  831. X
  832. X}    /* end of disp_stat */
  833. X
  834. X/*+-----------------------------------------------------------------------
  835. X    disp_line_termio(fd)
  836. X
  837. XGet current termio structure for file descriptor fd
  838. Xand display on stderr
  839. X------------------------------------------------------------------------*/
  840. Xvoid
  841. Xdisp_line_termio(fd,text)
  842. Xint fd;        /* file descriptor */
  843. Xchar *text;
  844. X{
  845. X    struct termio fd_termio;
  846. X    struct stat fd_stat;
  847. X    char text2[128];
  848. X
  849. X    ioctl(fd,TCGETA,&fd_termio);
  850. X    sprintf(text2,"fd: %d  %s",fd,text);
  851. X    disp_termio(&fd_termio,text2);
  852. X    fstat(fd,&fd_stat);
  853. X    disp_stat(&fd_stat);
  854. X
  855. X}    /* end of disp_line_termio */
  856. X
  857. X/*+-----------------------------------------------------------------------
  858. X    ascii_name_to_hex(str3char)
  859. X
  860. X  return value of ascii ctl char name (e.g., "NUL") 0 - 0x1F
  861. X  support CSI "ascii" 0x9B (for ESC + '[' ANSI)
  862. X  returns -1 if input not valid
  863. X------------------------------------------------------------------------*/
  864. Xascii_name_to_hex(str3char)
  865. Xchar *str3char;
  866. X{
  867. X    register char *cptr = ascii_ctlstr;
  868. X    register intval;
  869. X
  870. X    if((strlen(str3char) == 3) && (ulcmpb(str3char,"del") < 0))
  871. X        return(0x7F);
  872. X    if((strlen(str3char) == 3) && (ulcmpb(str3char,"csi") < 0))
  873. X        return(0x9B);
  874. X
  875. X    for(intval = 0; intval <= SPACE; intval++)
  876. X    {
  877. X        if(    (to_lower(*str3char) == to_lower(*cptr))                &&
  878. X            (to_lower(*(str3char + 1)) == to_lower(*(cptr + 1)))    &&
  879. X            ((to_lower(*(str3char + 2)) == to_lower(*(cptr + 2)))    ||
  880. X            (*(cptr + 2) == ' ')))
  881. X        {
  882. X            return(intval);
  883. X        }
  884. X        cptr += 3;
  885. X    }
  886. X
  887. X    return(-1);
  888. X
  889. X}    /* end of ascii_name_to_hex */
  890. X
  891. X/*+-------------------------------------------------------------------------
  892. X    ascii_to_hex(ascii)
  893. X--------------------------------------------------------------------------*/
  894. Xint
  895. Xascii_to_hex(ascii)
  896. Xchar *ascii;
  897. X{
  898. X    int hexval;
  899. X    if(strlen(ascii) == 1)
  900. X        return(*ascii);
  901. X    else if(!strncmp(ascii,"0x",2))
  902. X    {
  903. X        sscanf(ascii + 2,"%x",&hexval);
  904. X        return(hexval & 0xFF);
  905. X    }
  906. X    else if(*ascii == '^')
  907. X        return(*(ascii + 1) & 0x1F);
  908. X    else
  909. X        return(ascii_name_to_hex(ascii));
  910. X}    /* end of ascii_to_hex */
  911. X
  912. X/*+-------------------------------------------------------------------------
  913. X    hex_to_ascii_name(char_val)
  914. X
  915. X  Returns pointer to static string containing three character ASCII
  916. X  name for control character followed by a null.
  917. X--------------------------------------------------------------------------*/
  918. Xchar *
  919. Xhex_to_ascii_name(char_val)
  920. Xchar char_val;
  921. X{
  922. X    static char ascii_name[4];
  923. X
  924. X    char_val &= 0x7F;
  925. X
  926. X    if(char_val == 0x7F)
  927. X        strcpy(ascii_name,"DEL");
  928. X    else if(char_val > SPACE)
  929. X    {
  930. X        ascii_name[0] = char_val;
  931. X        ascii_name[1] = 0;
  932. X    }
  933. X    else
  934. X    {
  935. X        strncpy(ascii_name,ascii_ctlstr + (char_val * 3),3);
  936. X        ascii_name[3] = 0;
  937. X    }
  938. X
  939. X    return(ascii_name);
  940. X
  941. X}    /* end of hex_to_ascii_name */
  942. X
  943. X/*+-------------------------------------------------------------------------
  944. X    get_curr_dir(cdir,cdir_max) - get current directory into 'cdir'
  945. X--------------------------------------------------------------------------*/
  946. Xint
  947. Xget_curr_dir(cdir,cdir_max)
  948. Xchar *cdir;
  949. Xint cdir_max;
  950. X{
  951. X    FILE *popen();
  952. X    FILE *pipefp = popen("/bin/pwd","r");
  953. X    int itmp;
  954. X
  955. X    strcpy(cdir,".");
  956. X    if(!pipefp)
  957. X        return(-1);
  958. X    fgets(cdir,cdir_max,pipefp);
  959. X    if((itmp = strlen(cdir)) && (*(cdir + itmp - 1) == 0x0A))
  960. X        *(cdir + itmp - 1) = 0;
  961. X    fclose(pipefp);
  962. X    return(0);
  963. X}    /* end of get_curr_dir */
  964. X
  965. X/*+-----------------------------------------------------------------------
  966. X    get_home_dir(home_dir) - get user home directory
  967. X------------------------------------------------------------------------*/
  968. Xget_home_dir(home_dir)
  969. Xchar *home_dir;
  970. X{
  971. X    static char home_directory[256] = "";
  972. X    struct passwd *pwent;
  973. X    char *cptr;
  974. X
  975. X    if(home_directory[0])
  976. X    {
  977. X        strcpy(home_dir,home_directory);
  978. X        return(0);
  979. X    }
  980. X
  981. X    if(cptr = getenv("HOME"))            /* x286 seems to blow up ... */
  982. X    {                                    /* ... in pwent code ... hmmm */
  983. X        strcpy(home_directory,cptr);
  984. X        strcpy(home_dir,cptr);
  985. X        return(0);
  986. X    }
  987. X
  988. X    if(!(pwent = getpwuid(getuid())))
  989. X    {
  990. X        pperror("cannot get pwent for you!!");
  991. X        termecu(TERMECU_PWENT_ERROR);
  992. X    }
  993. X    strcpy(home_directory,pwent->pw_dir);
  994. X    strcpy(home_dir,pwent->pw_dir);
  995. X    endpwent();
  996. X    return(0);
  997. X
  998. X}    /* end of get_home_dir */
  999. X
  1000. X/*+-------------------------------------------------------------------------
  1001. X    make_ecu_subdir()
  1002. Xmust be called early in execution before wierd tty states set, etc.
  1003. X--------------------------------------------------------------------------*/
  1004. Xvoid
  1005. Xmake_ecu_subdir()
  1006. X{
  1007. X    int itmp;
  1008. X    struct stat fst;
  1009. X    char s256[256];
  1010. X    char s258[258];
  1011. X
  1012. X    get_home_dir(s256);
  1013. X    strcat(s256,"/.ecu");
  1014. X    if((!(itmp = stat(s256,&fst))) && ((fst.st_mode & S_IFMT) != S_IFDIR))
  1015. X    {
  1016. X        ff(se,"~/.ecu is not a directory. Rename the file and try again.\n\n");
  1017. X        exit(1);
  1018. X    }
  1019. X    if(itmp)        /* if stat failed, try to make the directory */
  1020. X    {
  1021. X        strcpy(s258,s256);
  1022. X        strcat(s258,"/x");
  1023. X        errno = ENOENT;
  1024. X        if(make_dirs(s258))
  1025. X        {
  1026. X            if(stat(s256,&fst))
  1027. X            {
  1028. X                ff(se,"cannot make ~/.ecu subdirectory.\n");
  1029. X                perror(s256);
  1030. X                exit(1);
  1031. X            }
  1032. X        }
  1033. X    }
  1034. X    chmod(s256,0700);
  1035. X}    /* end of make_ecu_subdir */
  1036. X
  1037. X/*+-------------------------------------------------------------------------
  1038. X    str_classify(sc,str) - classify a string and return value
  1039. X
  1040. XUse the STR_CLASSIFY structure to classify a string (convert str to
  1041. Xlexical token or error code) and return the value;  use last token
  1042. Xin table if no string matches
  1043. X--------------------------------------------------------------------------*/
  1044. Xstr_classify(sc,str)
  1045. XSTR_CLASSIFY *sc;
  1046. Xchar *str;
  1047. X{
  1048. X    while(sc->str)
  1049. X    {
  1050. X        if(minunique(sc->str,str,sc->min_ch))
  1051. X            return(sc->token);
  1052. X        sc++;
  1053. X    }
  1054. X    return(sc->token);
  1055. X}    /* end of str_classify */
  1056. X
  1057. X/*+-------------------------------------------------------------------------
  1058. X    yes_or_no(strarg) - lenient yes/no, on/off
  1059. X
  1060. X  Returns 1 if first char is 'Y' or 'y'
  1061. X    or if strarg is numeric returns the numeric value
  1062. X    or if strarg is alpha == "on" returns 1
  1063. X  Returns 0 otherwise
  1064. X--------------------------------------------------------------------------*/
  1065. Xint
  1066. Xyes_or_no(strarg)
  1067. Xchar *strarg;
  1068. X{
  1069. X    static STR_CLASSIFY sc[] = {
  1070. X        { "yes",    1,1 },
  1071. X        { "on",        2,1 },
  1072. X        { "no",        1,0 },
  1073. X        { "off",    3,0 },
  1074. X        { (char *)0,0,0 },
  1075. X    };
  1076. X
  1077. X    if(isdigit(*strarg))
  1078. X        return(atoi(strarg));
  1079. X    else
  1080. X        return(str_classify(sc,strarg));
  1081. X
  1082. X}    /* end of yes_or_no */
  1083. X
  1084. X/*+-------------------------------------------------------------------------
  1085. X    find_shell_chars(command) - search for shell metacharacters
  1086. X
  1087. Xreturns 1 if found
  1088. X--------------------------------------------------------------------------*/
  1089. Xint
  1090. Xfind_shell_chars(command)
  1091. Xchar *command;
  1092. X{
  1093. X    register schar;
  1094. X    register cchar;
  1095. X    register char *scptr;
  1096. X    static char shell_chars[] = "\\\"~;*?'`{}[]$";
  1097. X
  1098. X    while(cchar = *command++)
  1099. X    {
  1100. X        scptr = shell_chars;
  1101. X        while(schar = *scptr++)
  1102. X            if(schar == cchar)
  1103. X                return(1);
  1104. X    }
  1105. X    return(0);
  1106. X}    /* end of find_shell_chars */
  1107. X
  1108. X/*+-------------------------------------------------------------------------
  1109. X    errno_text(err) - safe sys_errlist lookup
  1110. X--------------------------------------------------------------------------*/
  1111. Xchar *
  1112. Xerrno_text(err)
  1113. Xint err;
  1114. X{
  1115. X    static char errant[32];
  1116. X
  1117. X    if((unsigned)err <= (unsigned)sys_nerr)
  1118. X        return(sys_errlist[errno]);
  1119. X    sprintf(errant,"errno %d",errno);
  1120. X    return(errant);
  1121. X
  1122. X}    /* end of errno_text */
  1123. X
  1124. X/*+-------------------------------------------------------------------------
  1125. X    perror_errmsg(str)
  1126. X--------------------------------------------------------------------------*/
  1127. Xvoid
  1128. Xperror_errmsg(str)
  1129. Xchar *str;
  1130. X{
  1131. X    extern char errmsg[];
  1132. X
  1133. X    sprintf(errmsg,"%s: %s",str,errno_text(errno));
  1134. X}    /* end of perror_errmsg */
  1135. X
  1136. X/*+-------------------------------------------------------------------------
  1137. X    cfree(p,num,size) - fix bug in XENIX -lmalloc
  1138. X--------------------------------------------------------------------------*/
  1139. X#if defined(M_XENIX) && defined(XENIX_MALLOC_LIB_BUG)
  1140. Xcfree(p,num,size)
  1141. Xchar *p;
  1142. Xint num;
  1143. Xint size;
  1144. X{
  1145. X    free(p);
  1146. X}    /* end of cfree */
  1147. X#endif
  1148. X
  1149. X/*+-------------------------------------------------------------------------
  1150. X    defeat_optimize_to_work_around_bug(would_be_optimized)
  1151. X
  1152. Xwork around for GCC 1.39 optimization bug (see ecufkey.c)
  1153. XThis bug was fixed in gcc 1.40
  1154. X--------------------------------------------------------------------------*/
  1155. X#if defined(__GNUC__) && !defined(GCC140)
  1156. Xvoid
  1157. Xdefeat_optimize_to_work_around_bug(would_be_optimized)
  1158. Xint *would_be_optimized;
  1159. X{
  1160. X    ;    /* do absolutely nothing */
  1161. X}    /* end of defeat_optimize_to_work_around_bug */
  1162. X
  1163. X#endif /* __GNUC__ */
  1164. X
  1165. X/*+-------------------------------------------------------------------------
  1166. X    rdchk(fd) - for systems without it but with FIONREAD
  1167. X--------------------------------------------------------------------------*/
  1168. X#if defined(sun) || defined(NO_RDCHK)
  1169. Xint
  1170. Xrdchk(fd)
  1171. Xint fd;
  1172. X{
  1173. X    int chars_waiting;
  1174. X
  1175. X    if(ioctl(fd,FIONREAD,&chars_waiting))
  1176. X        return(0);
  1177. X    else
  1178. X        return(!!chars_waiting);
  1179. X}    /* end of rdchk */
  1180. X#endif
  1181. X
  1182. X/* end of ecuutil.c */
  1183. X/* vi: set tabstop=4 shiftwidth=4: */
  1184. SHAR_EOF
  1185. chmod 0644 ecuutil.c ||
  1186. echo 'restore of ecuutil.c failed'
  1187. Wc_c="`wc -c < 'ecuutil.c'`"
  1188. test 26150 -eq "$Wc_c" ||
  1189.     echo 'ecuutil.c: original size 26150, current size' "$Wc_c"
  1190. rm -f _shar_wnt_.tmp
  1191. fi
  1192. # ============= ecuvmin.h ==============
  1193. if test -f 'ecuvmin.h' -a X"$1" != X"-c"; then
  1194.     echo 'x - skipping ecuvmin.h (File already exists)'
  1195.     rm -f _shar_wnt_.tmp
  1196. else
  1197. > _shar_wnt_.tmp
  1198. echo 'x - extracting ecuvmin.h (Text)'
  1199. sed 's/^X//' << 'SHAR_EOF' > 'ecuvmin.h' &&
  1200. X/*+-------------------------------------------------------------------------
  1201. X    ecuvmin.h  --  set line default VMIN
  1202. X    wht@n4hgf.Mt-Park.GA.US
  1203. X--------------------------------------------------------------------------*/
  1204. X/*+:EDITS:*/
  1205. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  1206. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  1207. X/*:03-27-1992-16:21-wht@n4hgf-re-include protection for all .h files */
  1208. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  1209. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1210. X
  1211. X#ifndef _ecuvmin_h
  1212. X#define _ecuvmin_h
  1213. X
  1214. X#if defined(BUILDING_PROTOTYPES)    /* if building protos.h ... */
  1215. X                                    /* ... pick up extra functions */
  1216. X#define XENIX_VMIN        2    /* ... include vmin handling routines */
  1217. X#else
  1218. X#define XENIX_VMIN        1    /* this is the real value for vmin */
  1219. X#endif
  1220. X
  1221. X#endif /* _ecuvmin_h */
  1222. X
  1223. X/* vi: set tabstop=4 shiftwidth=4: */
  1224. X/* end of ecuvmin.h */
  1225. SHAR_EOF
  1226. chmod 0644 ecuvmin.h ||
  1227. echo 'restore of ecuvmin.h failed'
  1228. Wc_c="`wc -c < 'ecuvmin.h'`"
  1229. test 891 -eq "$Wc_c" ||
  1230.     echo 'ecuvmin.h: original size 891, current size' "$Wc_c"
  1231. rm -f _shar_wnt_.tmp
  1232. fi
  1233. # ============= ecuwinutil.c ==============
  1234. if test -f 'ecuwinutil.c' -a X"$1" != X"-c"; then
  1235.     echo 'x - skipping ecuwinutil.c (File already exists)'
  1236.     rm -f _shar_wnt_.tmp
  1237. else
  1238. > _shar_wnt_.tmp
  1239. echo 'x - extracting ecuwinutil.c (Text)'
  1240. sed 's/^X//' << 'SHAR_EOF' > 'ecuwinutil.c' &&
  1241. X/*+-------------------------------------------------------------------------
  1242. X    ecuwinutil.c - curses window utilities
  1243. X    wht@n4hgf.Mt-Park.GA.US
  1244. X
  1245. X  Defined functions:
  1246. X    clear_area(win,y,x,len)
  1247. X    clear_area_char(win,y,x,len,fillchar)
  1248. X    winbox(win)
  1249. X    window_create(title,title_x,tly,tlx,lines,cols)
  1250. X    window_setup(win,title,title_x)
  1251. X    windows_end(botleft_flag)
  1252. X    windows_end_signal()
  1253. X    windows_start()
  1254. X    winget_single(win,nondelim_list,delim_list)
  1255. X    wingets(win,y,x,buf,bufsize,delim,edit,pwgpos)
  1256. X
  1257. X--------------------------------------------------------------------------*/
  1258. X/*+:EDITS:*/
  1259. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  1260. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  1261. X/*:02-09-1992-16:08-root@n4hgf-ruling characters only on  SCO (tcap curses) */
  1262. X/*:08-25-1991-14:39-wht@n4hgf-SVR4 port thanks to aega84!lh */
  1263. X/*:08-01-1991-03:52-wht@n4hgf-when editing string, set cursor to end */
  1264. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  1265. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1266. X
  1267. X#include "ecucurses.h"
  1268. X#include <errno.h>
  1269. X#include "ecukey.h"
  1270. X#include "ecuxkey.h"
  1271. X#include "termecu.h"
  1272. X#include "pc_scr.h"
  1273. X#ifdef USE_PROTOS
  1274. X# include "protos.h"
  1275. X#endif
  1276. X
  1277. X#if !defined(ushort)
  1278. X#define ushort unsigned short
  1279. X#endif
  1280. X#if !defined(uchar)
  1281. X#define uchar unsigned char
  1282. X#endif
  1283. X#if !defined(uint)
  1284. X#define uint unsigned int
  1285. X#endif
  1286. X#if !defined(ulong)
  1287. X#define ulong unsigned long
  1288. X#endif
  1289. X
  1290. Xextern int tty_is_multiscreen;
  1291. X
  1292. X#ifdef M_SYSV
  1293. Xunsigned char sTL = at_TL;
  1294. Xunsigned char sTR = at_TR;
  1295. Xunsigned char sBL = at_BL;
  1296. Xunsigned char sBR = at_BR;
  1297. Xunsigned char sLT = at_LT;
  1298. Xunsigned char sRT = at_RT;
  1299. Xunsigned char sVR = at_VR;
  1300. Xunsigned char sHR = at_HR;
  1301. X#else
  1302. Xunsigned char sTL = vanilla_TL;
  1303. Xunsigned char sTR = vanilla_TR;
  1304. Xunsigned char sBL = vanilla_BL;
  1305. Xunsigned char sBR = vanilla_BR;
  1306. Xunsigned char sLT = vanilla_LT;
  1307. Xunsigned char sRT = vanilla_RT;
  1308. Xunsigned char sVR = vanilla_VR;
  1309. Xunsigned char sHR = vanilla_HR;
  1310. X#endif
  1311. X
  1312. Xint windows_active = 0;
  1313. X
  1314. Xint ttymode_before_window_start;
  1315. X
  1316. X/*+-------------------------------------------------------------------------
  1317. X    clear_area_char(win,y,x,len,fillchar)
  1318. X--------------------------------------------------------------------------*/
  1319. Xvoid
  1320. Xclear_area_char(win,y,x,len,fillchar)
  1321. XWINDOW *win;
  1322. Xint y;
  1323. Xint x;
  1324. Xint len;
  1325. Xchar fillchar;
  1326. X{
  1327. X    wmove(win,y,x);
  1328. X    while(len-- > 0)
  1329. X        waddch(win,fillchar & 0xFF);
  1330. X    wmove(win,y,x);
  1331. X
  1332. X}    /* end of clear_area_char */
  1333. X
  1334. X/*+-------------------------------------------------------------------------
  1335. X    clear_area(win,y,x,len)
  1336. X--------------------------------------------------------------------------*/
  1337. Xvoid
  1338. Xclear_area(win,y,x,len)
  1339. XWINDOW *win;
  1340. Xint y;
  1341. Xint x;
  1342. Xint len;
  1343. X{
  1344. X    clear_area_char(win,y,x,len,' ');
  1345. X}    /* end of clear_area_char */
  1346. X
  1347. X/*+-------------------------------------------------------------------------
  1348. X    windows_start()
  1349. X--------------------------------------------------------------------------*/
  1350. Xvoid
  1351. Xwindows_start()
  1352. X{
  1353. X    extern int tty_not_char_special;
  1354. X    static int initscr_already_performed = 0;
  1355. X
  1356. X    if(tty_not_char_special)
  1357. X    {
  1358. X        errno = ENOTTY;
  1359. X        fprintf(stderr,"curses features unavailable when stdin not tty\r\n");
  1360. X        termecu(TERMECU_CURSES_ERROR);
  1361. X    }
  1362. X
  1363. X    ttymode_before_window_start = get_ttymode();
  1364. X    ttymode(0);
  1365. X    if(!initscr_already_performed && !initscr())
  1366. X    {
  1367. X        fprintf(stderr,"curses init failure ... check terminal type\r\n");
  1368. X        termecu(TERMECU_CURSES_ERROR);
  1369. X    }
  1370. X    initscr_already_performed = 1;
  1371. X    scrollok(stdscr,0);
  1372. X    savetty(); 
  1373. X    raw(); 
  1374. X    noecho(); 
  1375. X    nonl(); 
  1376. X    clear();
  1377. X#if defined(M_TERMINFO)
  1378. X    typeahead(-1);
  1379. X#endif
  1380. X    windows_active = 1;
  1381. X
  1382. X#if defined(M_SYSV)
  1383. X    if(!tty_is_multiscreen)
  1384. X    {
  1385. X        sTL = vanilla_TL;
  1386. X        sTR = vanilla_TR;
  1387. X        sBL = vanilla_BL;
  1388. X        sBR = vanilla_BR;
  1389. X        sLT = vanilla_LT;
  1390. X        sRT = vanilla_RT;
  1391. X        sVR = vanilla_VR;
  1392. X        sHR = vanilla_HR;
  1393. X    }
  1394. X#endif
  1395. X
  1396. X    wclear(stdscr);
  1397. X    touchwin(stdscr);
  1398. X    wrefresh(stdscr);
  1399. X
  1400. X}    /* end of windows_start */
  1401. X
  1402. X/*+-------------------------------------------------------------------------
  1403. X    windows_end(botleft_flag)
  1404. X--------------------------------------------------------------------------*/
  1405. Xvoid
  1406. Xwindows_end(botleft_flag)
  1407. Xint botleft_flag;
  1408. X{
  1409. X    if(!windows_active)
  1410. X        return;
  1411. X/*
  1412. X    endwin();
  1413. X*/
  1414. X    if(botleft_flag)
  1415. X        tcap_cursor(LINES - 1,0);
  1416. X    ttymode(ttymode_before_window_start);
  1417. X    windows_active = 0;
  1418. X}    /* end of windows_end */
  1419. X
  1420. X/*+-------------------------------------------------------------------------
  1421. X    windows_end_signal() -- called by termecu()
  1422. X--------------------------------------------------------------------------*/
  1423. Xvoid
  1424. Xwindows_end_signal()
  1425. X{
  1426. X    windows_end(0);
  1427. X}    /* end of windows_end_signal */
  1428. X
  1429. X/*+-------------------------------------------------------------------------
  1430. X    winbox(win)
  1431. X--------------------------------------------------------------------------*/
  1432. Xvoid
  1433. Xwinbox(win)
  1434. XWINDOW *win;
  1435. X{
  1436. X
  1437. X#if defined(SVR4)
  1438. X    box(win,(unsigned long)sVR,(unsigned long)sHR);
  1439. X#else
  1440. X    box(win,sVR,sHR);
  1441. X    wmove(win,0,0); waddch(win,(unsigned)sTL);
  1442. X    wmove(win,win->_maxy - 1,0); waddch(win,(unsigned)sBL);
  1443. X    wmove(win,win->_maxy - 1,win->_maxx - 1); waddch(win,(unsigned)sBR);
  1444. X    wmove(win,0,win->_maxx - 1); waddch(win,(unsigned)sTR);
  1445. X#endif
  1446. X
  1447. X}    /* end of winbox */
  1448. X
  1449. X/*+-------------------------------------------------------------------------
  1450. X    window_setup(win,title,title_x)
  1451. X--------------------------------------------------------------------------*/
  1452. Xvoid
  1453. Xwindow_setup(win,title,title_x)
  1454. XWINDOW *win;
  1455. Xchar *title;
  1456. Xint title_x;
  1457. X{
  1458. X    register stand = (title_x < 0);
  1459. X
  1460. X    if(stand)
  1461. X        title_x = -title_x;
  1462. X
  1463. X    touchwin(win);
  1464. X    scrollok(win,0);        /* do not scroll */
  1465. X    winbox(win);
  1466. X    wmove(win,0,title_x);
  1467. X    if(stand)
  1468. X        wstandout(win);
  1469. X    waddch(win,'[');
  1470. X    wprintw(win," %s ",title);
  1471. X    waddch(win,']');
  1472. X    if(stand)
  1473. X        wstandend(win);
  1474. X}    /* end of window_setup */
  1475. X
  1476. X/*+-------------------------------------------------------------------------
  1477. X    window_create(title,title_x,tly,tlx,lines,cols)
  1478. Xif title_x negative, make title "stand" out
  1479. X--------------------------------------------------------------------------*/
  1480. XWINDOW *
  1481. Xwindow_create(title,title_x,tly,tlx,lines,cols)
  1482. Xchar *title;
  1483. Xint title_x;
  1484. Xint tly;
  1485. Xint tlx;
  1486. Xint lines;
  1487. Xint cols;
  1488. X{
  1489. X    register WINDOW *nwin = newwin(lines,cols,tly,tlx);
  1490. X    
  1491. X    if(nwin)
  1492. X        window_setup(nwin,title,title_x);
  1493. X    else
  1494. X    {
  1495. X        fprintf(stderr,"\r\ncurses error: cannot create new window\r\n");
  1496. X        termecu(TERMECU_CURSES_ERROR);
  1497. X    }
  1498. X    return(nwin);
  1499. X}    /* end of window_create */
  1500. X
  1501. X/*+-------------------------------------------------------------------------
  1502. X    wingets(win,y,x,buf,bufsize,delim,edit,pwgpos)
  1503. X
  1504. XThis procedure reads a string from win and returns the number
  1505. Xof characters read.
  1506. X
  1507. XIf edit is non-zero and pwgpos is not null, the inital string
  1508. Xposition is set by dereferencing the pointer.
  1509. X
  1510. XThe terminating delim is returned in 'delim'.
  1511. X
  1512. XIf pwgpos is not null, the ending string position is returned in
  1513. Xthe integer pointed to.
  1514. X
  1515. X-1 is returned if an ESCape is typed by the keyboard user,
  1516. Xotherwise the count of characters in the string.
  1517. X
  1518. XThe entire line must be contained on one line (no line wrap supported).
  1519. X--------------------------------------------------------------------------*/
  1520. Xint
  1521. Xwingets(win,y,x,buf,bufsize,delim,edit,pwgpos)
  1522. XWINDOW *win;
  1523. Xint y;
  1524. Xregister x;
  1525. Xregister char *buf;
  1526. Xint bufsize;    /* includes room for null..field is 1 less */
  1527. Xregister uchar *delim;
  1528. Xint edit;
  1529. Xint *pwgpos;
  1530. X{
  1531. X    register count = 0;
  1532. X    register pos = 0;
  1533. X    int insert_mode = 0;
  1534. X    int rtn_val = 0;
  1535. X
  1536. X    bufsize--;
  1537. X    clear_area_char(win,y,x,bufsize,'_');
  1538. X    if(edit)
  1539. X    {
  1540. X        waddstr(win,buf);
  1541. X        count = pos = strlen(buf);
  1542. X        if(pwgpos)
  1543. X        {
  1544. X            pos = *pwgpos;
  1545. X            if((pos < 0) || (pos > count))
  1546. X                pos = count;
  1547. X        }
  1548. X    }
  1549. X    else
  1550. X        *buf = 0;
  1551. X    wmove(win,y,x + pos);
  1552. X
  1553. X    while(1)
  1554. X    {
  1555. X        wrefresh(win);
  1556. X        *delim = ttygetc(1);
  1557. X        if((*delim < 0x20) || (*delim >= 0x7F))
  1558. X        {
  1559. X            switch(*delim)
  1560. X            {
  1561. X                case CRET:
  1562. X                    *delim = NL;
  1563. X                case NL:
  1564. X                    wrefresh(win);
  1565. X                    rtn_val = count;
  1566. X                    goto RETURN;
  1567. X
  1568. X                case BS:
  1569. X                    if(count)
  1570. X                    {
  1571. X                        if(count == pos)
  1572. X                        {
  1573. X                            *(buf + --count) = 0;
  1574. X                            wmove(win,y,x + count);
  1575. X                            waddch(win,'_');
  1576. X                            wmove(win,y,x + count);
  1577. X                            pos--;
  1578. X                        }
  1579. X                        else
  1580. X                        {
  1581. X                            if(!pos)
  1582. X                                continue;
  1583. X                            mem_cpy(buf + pos - 1,buf + pos,count - pos);
  1584. X                            *(buf + --count) = 0;
  1585. X                            wmove(win,y,x + --pos);
  1586. X                            waddstr(win,buf + pos);
  1587. X                            waddch(win,'_');
  1588. X                            wmove(win,y,x + pos);
  1589. X                        }
  1590. X                    }
  1591. X                    continue;
  1592. X
  1593. X                case XFcurlf:
  1594. X                    if(pos)
  1595. X                        wmove(win,y,x + --pos);
  1596. X                    continue;
  1597. X
  1598. X                case XFcurrt:
  1599. X                    if(pos < count)
  1600. X                        wmove(win,y,x + ++pos);
  1601. X                    continue;
  1602. X
  1603. X                case XFins:
  1604. X                    insert_mode = !insert_mode;
  1605. X                    continue;
  1606. X
  1607. X                case ESC:
  1608. X                    rtn_val = -1;
  1609. X                    goto RETURN;
  1610. X
  1611. X                case CTL_U:
  1612. X                    clear_area_char(win,y,x,bufsize,'_');
  1613. X                    count = 0;
  1614. X                    pos = 0;
  1615. X                    *buf = 0;
  1616. X                    continue;
  1617. X
  1618. X                default:
  1619. X                    *(buf + count) = 0;
  1620. X                    rtn_val = count;
  1621. X                    goto RETURN;
  1622. X
  1623. X            }    /* end of switch(*delim) */
  1624. X            /*NOTREACHED*/
  1625. X        }        /* end of if read delimiter */
  1626. X
  1627. X        if(count == bufsize)
  1628. X        {
  1629. X            ring_bell();
  1630. X            continue;
  1631. X        }
  1632. X
  1633. X        if(insert_mode && (pos != count))
  1634. X        {
  1635. X            waddch(win,*delim);
  1636. X            waddstr(win,buf + pos);
  1637. X            mem_cpy(buf + pos + 1,buf + pos,count - pos);
  1638. X            *(buf + pos++) = *delim;
  1639. X            *(buf + ++count) = 0;
  1640. X            wmove(win,y,x + pos);
  1641. X        }
  1642. X        else
  1643. X        {
  1644. X            waddch(win,*delim);
  1645. X            *(buf + pos) = *delim;
  1646. X            if(pos == count)
  1647. X                *(buf + ++count) = 0;
  1648. X            pos++;
  1649. X        }
  1650. X    }    /* end of while can get character */
  1651. X
  1652. XRETURN:
  1653. X    if(pwgpos)
  1654. X        *pwgpos = pos;
  1655. X    return(rtn_val);
  1656. X
  1657. X}    /* end of wingets */
  1658. X
  1659. X/*+-------------------------------------------------------------------------
  1660. X    winget_single(win,nondelim_list,delim_list)
  1661. X
  1662. XThis procedure assumes cursor is positioned, repeats reading a non-echoing
  1663. Xcharacter from the keyboard until it matches a character in nondelim_list
  1664. Xor delim_list.  delim_list is expected to contain printable characters
  1665. Xand no upper-case characters.
  1666. X
  1667. XIf no match occurs, the bell is rung and the keyboard is read again.
  1668. X
  1669. XIf the input character matches a character in delim_list, the index (0-n)
  1670. Xof the character in delim_list is returned.  If a match occurs, an
  1671. Xupper-case version of the matching character is placed in the window.
  1672. X
  1673. XIf the input character matches a character in nondelim_list, the character
  1674. Xis returned or'ed with 0x1000
  1675. X
  1676. X--------------------------------------------------------------------------*/
  1677. Xint
  1678. Xwinget_single(win,nondelim_list,delim_list)
  1679. XWINDOW *win;
  1680. Xregister char *nondelim_list;
  1681. Xregister char *delim_list;
  1682. X{
  1683. X    register itmp;
  1684. X    register nlen = strlen(nondelim_list);
  1685. X    register dlen = strlen(delim_list);
  1686. X    register ichar;
  1687. X
  1688. X    wrefresh(win);
  1689. X
  1690. X    while(1)
  1691. X    {
  1692. X        ichar = to_lower(ttygetc(1));
  1693. X        for(itmp = 0; itmp < nlen; itmp++)
  1694. X        {
  1695. X            if(ichar == nondelim_list[itmp])
  1696. X            {
  1697. X                waddch(win,to_upper(ichar));
  1698. X                wrefresh(win);
  1699. X                return(itmp);
  1700. X            }
  1701. X        }
  1702. X        for(itmp = 0; itmp < dlen; itmp++)
  1703. X        {
  1704. X            if(ichar == delim_list[itmp])
  1705. X                return(ichar | 0x1000);
  1706. X        }
  1707. X        ring_bell();
  1708. X    }
  1709. X
  1710. X}    /* end of winget_single */
  1711. X
  1712. X/* end of ecuwinutil.c */
  1713. X/* vi: set tabstop=4 shiftwidth=4: */
  1714. SHAR_EOF
  1715. chmod 0644 ecuwinutil.c ||
  1716. echo 'restore of ecuwinutil.c failed'
  1717. Wc_c="`wc -c < 'ecuwinutil.c'`"
  1718. test 10846 -eq "$Wc_c" ||
  1719.     echo 'ecuwinutil.c: original size 10846, current size' "$Wc_c"
  1720. rm -f _shar_wnt_.tmp
  1721. fi
  1722. # ============= ecuxfer.c ==============
  1723. if test -f 'ecuxfer.c' -a X"$1" != X"-c"; then
  1724.     echo 'x - skipping ecuxfer.c (File already exists)'
  1725.     rm -f _shar_wnt_.tmp
  1726. else
  1727. > _shar_wnt_.tmp
  1728. echo 'x - extracting ecuxfer.c (Text)'
  1729. sed 's/^X//' << 'SHAR_EOF' > 'ecuxfer.c' &&
  1730. X/*+-------------------------------------------------------------------------
  1731. X    ecuxfer.c - file transfer
  1732. X    wht@n4hgf.Mt-Park.GA.US
  1733. X
  1734. X   000000000011111111112222222222333333333344444444445555555555666666666actually
  1735. X   012345678901234567890123456789012345678901234567890123456789012345678wider
  1736. X00:.--[ Send ZMODEM/CRC32 ]--------------------------------------------.
  1737. X01:|                                                                   |
  1738. X02:|  File? to send:                                                   |
  1739. X03:|  ................................................................ |
  1740. X04:|                                                                   |
  1741. X05:|  Binary: Y (no CR/LF translation)                                 |
  1742. X06:|  Overwrite destination files: Y                                   |
  1743. X07:|  Send full pathnames: N                                           |
  1744. X08:|  Transfer only newer files:   N (if receiver supports)            |
  1745. X09:|  Resume interrupted transfer: N (if receiver supports)            |
  1746. X10:|  ZMODEM window: ______                                            |
  1747. X11:|                                                                   |
  1748. X-1:| TAB:next  ^B:prev  END:perform transfer  ESC:abort                |
  1749. X-0:`-------------------------------------------------------------------'
  1750. X
  1751. X  Defined functions:
  1752. X    file_xfer_done_bell()
  1753. X    file_xfer_start()
  1754. X    receive_files_from_remote(argc,argv)
  1755. X    report_send_status()
  1756. X    send_files_to_remote(argc,argv)
  1757. X    xfer_title_fragment()
  1758. X    xfrw_bot_msg(msg)
  1759. X    xfrw_display_cmd_line()
  1760. X    xfrw_get_single(nondelim_list)
  1761. X    xfrws_display_allvars()
  1762. X    xfrws_display_binary()
  1763. X    xfrws_display_literals()
  1764. X    xfrws_display_name()
  1765. X    xfrws_display_resume()
  1766. X    xfrws_display_xfernew()
  1767. X
  1768. X--------------------------------------------------------------------------*/
  1769. X/*+:EDITS:*/
  1770. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  1771. X/*:09-05-1992-15:31-wht@n4hgf-add resume choice  */
  1772. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  1773. X/*:08-21-1992-15:21-wht@n4hgf-look for ecu xfer programs in ECULIBDIR */
  1774. X/*:09-25-1991-16:26-wht@n4hgf2-flexible C-Kermit filename */
  1775. X/*:09-17-1991-19:41-wht@n4hgf-restore console termio after xfer prog runs */
  1776. X/*:08-28-1991-14:07-wht@n4hgf2-SVR4 cleanup by aega84!lh */
  1777. X/*:08-25-1991-14:39-wht@n4hgf-SVR4 port thanks to aega84!lh */
  1778. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  1779. X/*:07-17-1991-07:04-wht@n4hgf-avoid SCO UNIX nap bug */
  1780. X/*:07-14-1991-18:18-wht@n4hgf-new ttygets functions */
  1781. X/*:06-04-1991-14:18-wht@n4hgf-sometimes I forget 286: zwindw_size now uint */
  1782. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1783. X
  1784. X#include "ecucurses.h"
  1785. X
  1786. X#define STDIO_H_INCLUDED
  1787. X#define OMIT_TERMIO_REFERENCES
  1788. X#include "ecu.h"
  1789. X#include "ecuerror.h"
  1790. X#include "ecukey.h"
  1791. X#include "ecuxkey.h"
  1792. X#include "ecutty.h"
  1793. X#include "pc_scr.h"
  1794. X
  1795. Xlong atol();
  1796. Xchar *find_executable();
  1797. X
  1798. X#ifdef M_I286
  1799. X#define ZWINDW_LIMIT 65472
  1800. X#else
  1801. X#define ZWINDW_LIMIT 65536
  1802. X#endif
  1803. X
  1804. X/* -- protocol xfer types -- */
  1805. X#define ECUSZ_X            1
  1806. X#define ECUSZ_Y            2
  1807. X#define ECUSZ_Z            3
  1808. X#define ECUSEA            4
  1809. X#define CKERMIT            5
  1810. X#define ECURZ_X            7
  1811. X#define ECURZ_Y            8
  1812. X#define ECURZ_Z            9
  1813. X
  1814. X/* --------------------- send window ----------------------------------- */
  1815. X/*      SNDW_LINES            calculated (xfrw_lines) */
  1816. X#define SNDW_COLS            79
  1817. X#define SNDW_TLY            2
  1818. X/*      SNDW_TLX            calculated (xfrw_tlx) */
  1819. X
  1820. X#define SNDW_FILE_LY        2
  1821. X#define SNDW_FILE_LX        3
  1822. X#define SNDW_FILE_Y            3
  1823. X#define SNDW_FILE_X            3
  1824. X#define SNDW_FILE_LEN        (SNDW_COLS - SNDW_FILE_X - 2)
  1825. X
  1826. X#define SNDW_BIN_Y            5
  1827. X#define SNDW_BIN_LX            3
  1828. X#define SNDW_BIN_X            11
  1829. X#define SNDW_BIN_LX2        13
  1830. X
  1831. X#define SNDW_OVERW_Y        6
  1832. X#define SNDW_OVERW_LX        3
  1833. X#define SNDW_OVERW_X        32
  1834. X
  1835. X#define SNDW_SENDFULL_Y        7
  1836. X#define SNDW_SENDFULL_LX    3
  1837. X#define SNDW_SENDFULL_X        24
  1838. X
  1839. X#define SNDW_XFERNEW_Y        8
  1840. X#define SNDW_XFERNEW_LX        3
  1841. X#define SNDW_XFERNEW_X        32
  1842. X
  1843. X#define SNDW_RESUME_Y        9
  1844. X#define SNDW_RESUME_LX        3
  1845. X#define SNDW_RESUME_X        32
  1846. X
  1847. X#define SNDW_ZWINDW_Y        10
  1848. X#define SNDW_ZWINDW_LX        3
  1849. X#define SNDW_ZWINDW_X        16
  1850. X#define SNDW_ZWINDW_LEN        6
  1851. X
  1852. Xextern char curr_dir[CURR_DIRSIZ];        /* current working directory */
  1853. Xextern int protocol_log_packets;
  1854. Xextern int last_child_wait_status;
  1855. X
  1856. Xlong file_xfer_start_time;    /* time() value at beginning of file xfer */
  1857. Xchar xfertype = -1;        /* file xfer type */
  1858. XWINDOW *xfrw;
  1859. Xchar xfrw_cols;
  1860. Xchar xfrw_lines;
  1861. Xchar xfrw_tlx;
  1862. X
  1863. Xchar p_binary;        /* xfer options -- not all apply to all protocols */
  1864. Xchar p_sendfull;
  1865. Xchar p_overwrite;
  1866. Xchar p_xfernew;
  1867. Xchar p_resume;
  1868. Xchar p_filelist[80];
  1869. Xuint zwindw_size;
  1870. X
  1871. X/*+-------------------------------------------------------------------------
  1872. X    file_xfer_start()
  1873. X--------------------------------------------------------------------------*/
  1874. Xvoid
  1875. Xfile_xfer_start()
  1876. X{
  1877. X    time(&file_xfer_start_time);
  1878. X}    /* end of file_xfer_start */
  1879. X
  1880. X/*+-------------------------------------------------------------------------
  1881. X    file_xfer_done_bell()
  1882. X--------------------------------------------------------------------------*/
  1883. Xvoid
  1884. Xfile_xfer_done_bell()
  1885. X{
  1886. X    long xfer_time;
  1887. X    int xbell_count = 0;
  1888. X
  1889. X    time(&xfer_time);
  1890. X    xfer_time -= file_xfer_start_time;
  1891. X    sleep(1);
  1892. X    xbell_count = 1;
  1893. X    if(xfer_time >= 3600L)            /* >= one hour */
  1894. X        xbell_count = 3;
  1895. X    else if(xfer_time >= 1800L)        /* >= 1/2 hour */
  1896. X        xbell_count = 2;
  1897. X
  1898. X    if(shm->bell_notify_state)
  1899. X        bell_notify(XBELL_ATTENTION);
  1900. X    xbell(XBELL_DONE,xbell_count);
  1901. X
  1902. X}    /* end of file_xfer_done_bell */
  1903. X
  1904. X/*+-------------------------------------------------------------------------
  1905. X    xfrw_bot_msg(msg)
  1906. X--------------------------------------------------------------------------*/
  1907. Xvoid
  1908. Xxfrw_bot_msg(msg)
  1909. Xchar *msg;
  1910. X{
  1911. X    register itmp;
  1912. X    register itmp2;
  1913. X    static last_msglen = 0;
  1914. X    char msg2[80];
  1915. X
  1916. X    wmove(xfrw,xfrw_lines - 1,3);
  1917. X
  1918. X    if((itmp = strlen(msg)) == 0)
  1919. X    {
  1920. X        itmp2 = last_msglen + 2;
  1921. X#if defined(SVR4)
  1922. X        whline(xfrw, (unsigned long)(sHR & 0x00ff), itmp2);
  1923. X#else
  1924. X        for(itmp = 0; itmp < itmp2; itmp++)
  1925. X            waddch(xfrw,(unsigned)sHR);
  1926. X#endif
  1927. X        last_msglen = 0;
  1928. X    }
  1929. X    else
  1930. X    {
  1931. X        waddch(xfrw,' ');
  1932. X        if(itmp > xfrw_cols - 3 - 2)
  1933. X        {
  1934. X            strncpy(msg2,msg,xfrw_cols - 3 - 2);
  1935. X            msg2[xfrw_cols - 3 - 2 + 1] = 0;
  1936. X            waddstr(xfrw,msg2);
  1937. X            itmp = strlen(msg2);
  1938. X        }
  1939. X        else
  1940. X        {
  1941. X            waddstr(xfrw,msg);
  1942. X            itmp = strlen(msg);
  1943. X        }
  1944. X        waddch(xfrw,' ');
  1945. X        if((itmp2 = last_msglen - itmp) > 0)
  1946. X        {
  1947. X#if defined(SVR4)
  1948. X            whline(xfrw, (unsigned long)(sHR & 0x00ff), itmp2);
  1949. X#else
  1950. X            while(itmp2--)
  1951. X                waddch(xfrw,(unsigned)sHR);
  1952. X#endif
  1953. X        }
  1954. X        last_msglen = itmp;        /* remember last message length */
  1955. X    }
  1956. X    wrefresh(xfrw);
  1957. X}    /* end of xfrw_bot_msg */
  1958. X
  1959. X/*+-------------------------------------------------------------------------
  1960. X    xfrw_get_single(nondelim_list)
  1961. Xassumes cursor is already positioned
  1962. X--------------------------------------------------------------------------*/
  1963. Xint
  1964. Xxfrw_get_single(nondelim_list)
  1965. Xregister char *nondelim_list;
  1966. X{
  1967. X    register uint itmp;
  1968. X    static uchar xfrw_nondelim_list[] =
  1969. X    {
  1970. X        CRET,NL,XFcurup,XFcurdn,CTL_B,TAB,ESC,CTL_L,CTL_R,XFend,(uchar)0
  1971. X    };
  1972. X
  1973. X    itmp = winget_single(xfrw,nondelim_list,xfrw_nondelim_list);
  1974. X    if( (itmp & 0xFF) == CRET)
  1975. X        itmp = NL | 0x1000;
  1976. X    return(itmp);
  1977. X}    /* end of xfrw_get_single */
  1978. X
  1979. X/*+-------------------------------------------------------------------------
  1980. X    xfer_title_fragment()
  1981. X--------------------------------------------------------------------------*/
  1982. Xchar *
  1983. Xxfer_title_fragment()
  1984. X{
  1985. X    register char *cptr = "UNKNOWN";
  1986. X
  1987. X    switch(xfertype)
  1988. X    {
  1989. X        case ECURZ_X:
  1990. X        case ECUSZ_X: cptr = "XMODEM/CRC"; break;
  1991. X        case ECURZ_Y:
  1992. X        case ECUSZ_Y: cptr = "YMODEM/CRC"; break;
  1993. X        case ECURZ_Z:
  1994. X        case ECUSZ_Z: cptr = "ZMODEM/CRC32"; break;
  1995. X        case ECUSEA:  cptr = "SEAlink"; break;
  1996. X        case CKERMIT: cptr = "KERMIT/CRC" ;break;
  1997. X    }
  1998. X    return(cptr);
  1999. X}    /* end of xfer_title_fragment */
  2000. X
  2001. X/*+-------------------------------------------------------------------------
  2002. X    xfrw_display_cmd_line()
  2003. X--------------------------------------------------------------------------*/
  2004. Xvoid
  2005. Xxfrw_display_cmd_line()
  2006. X{
  2007. X    register itmp;
  2008. X    char *cmd_string = "TAB:next  ^B:prev  END:perform transfer  ESC:abort"; 
  2009. X    register left_spaces = ((xfrw_cols - 2) - strlen(cmd_string)) / (unsigned)2;
  2010. X    int x;
  2011. X    int y;
  2012. X
  2013. X    wmove(xfrw,xfrw_lines - 2,1);
  2014. X    wstandout(xfrw);
  2015. X    for(itmp = 0; itmp < left_spaces; itmp++)
  2016. X        waddch(xfrw,' ');
  2017. X    waddstr(xfrw,cmd_string);
  2018. X    getyx(xfrw,y,x);
  2019. X    while(++x < xfrw_cols)
  2020. X        waddch(xfrw,' '); 
  2021. X    wstandend(xfrw);
  2022. X
  2023. X}    /* end of xfrw_display_cmd_line */
  2024. X
  2025. X/*+-------------------------------------------------------------------------
  2026. X    xfrws_display_literals()
  2027. X--------------------------------------------------------------------------*/
  2028. Xvoid
  2029. Xxfrws_display_literals()
  2030. X{
  2031. X    wmove(xfrw,SNDW_FILE_LY,SNDW_FILE_LX);
  2032. X    if(xfertype == ECUSZ_X)
  2033. X        waddstr(xfrw,"File");
  2034. X    else
  2035. X        waddstr(xfrw,"File(s)");
  2036. X    waddstr(xfrw," to send:");
  2037. X
  2038. X    switch(xfertype)
  2039. X    {
  2040. X        case ECUSZ_Z:
  2041. X            wmove(xfrw,SNDW_XFERNEW_Y,SNDW_XFERNEW_LX);
  2042. X            waddstr(xfrw,"Transfer only newer files:");
  2043. X            wmove(xfrw,SNDW_SENDFULL_Y,SNDW_SENDFULL_LX);
  2044. X            waddstr(xfrw,"Send full pathames:");
  2045. X            wmove(xfrw,SNDW_RESUME_Y,SNDW_RESUME_LX);
  2046. X            waddstr(xfrw,"Resume interrupted transfer:");
  2047. X            wmove(xfrw,SNDW_ZWINDW_Y,SNDW_ZWINDW_LX);
  2048. X            waddstr(xfrw,"Window size:");
  2049. X        case CKERMIT:
  2050. X            wmove(xfrw,SNDW_OVERW_Y,SNDW_OVERW_LX);
  2051. X            waddstr(xfrw,"Overwrite destination files:");
  2052. X        case ECUSZ_Y:
  2053. X        case ECUSZ_X:
  2054. X            wmove(xfrw,SNDW_BIN_Y,SNDW_BIN_LX);
  2055. X            waddstr(xfrw,"Binary:");
  2056. X    }
  2057. X}    /* end of xfrws_display_literals */
  2058. X
  2059. X/*+-------------------------------------------------------------------------
  2060. X    xfrws_display_name()
  2061. X--------------------------------------------------------------------------*/
  2062. Xvoid
  2063. Xxfrws_display_name()
  2064. X{
  2065. X    clear_area(xfrw,SNDW_FILE_Y,SNDW_FILE_X,SNDW_FILE_LEN);
  2066. X    waddstr(xfrw,p_filelist);
  2067. X
  2068. X}    /* end of xfrws_display_name */
  2069. X
  2070. X/*+-------------------------------------------------------------------------
  2071. X    xfrws_display_binary()
  2072. X--------------------------------------------------------------------------*/
  2073. Xvoid
  2074. Xxfrws_display_binary()
  2075. X{
  2076. X    wmove(xfrw,SNDW_BIN_Y,SNDW_BIN_X);
  2077. X    waddch(xfrw,(p_binary) ? 'Y' : 'N');
  2078. X    if(p_binary)
  2079. X        waddstr(xfrw," (no NL-CR/LF translation)     ");
  2080. X    else
  2081. X        waddstr(xfrw," (NL-CR/LF translation enabled)");
  2082. X
  2083. X}    /* end of xfrws_display_binary */
  2084. X
  2085. X/*+-------------------------------------------------------------------------
  2086. X    xfrws_display_xfernew()
  2087. X--------------------------------------------------------------------------*/
  2088. Xvoid
  2089. Xxfrws_display_xfernew()
  2090. X{
  2091. X    wmove(xfrw,SNDW_XFERNEW_Y,SNDW_XFERNEW_X);
  2092. X    waddch(xfrw,(p_xfernew) ? 'Y' : 'N');
  2093. X    if(p_xfernew)
  2094. X        waddstr(xfrw," (if receiver supports)");
  2095. X    else
  2096. X        waddstr(xfrw,"                       ");
  2097. X}    /* end of xfrws_display_xfernew */
  2098. X
  2099. X/*+-------------------------------------------------------------------------
  2100. X    xfrws_display_resume()
  2101. X--------------------------------------------------------------------------*/
  2102. Xvoid
  2103. Xxfrws_display_resume()
  2104. X{
  2105. X    wmove(xfrw,SNDW_RESUME_Y,SNDW_RESUME_X);
  2106. X    waddch(xfrw,(p_resume) ? 'Y' : 'N');
  2107. X    if(p_resume)
  2108. X        waddstr(xfrw," (if receiver supports)");
  2109. X    else
  2110. X        waddstr(xfrw,"                       ");
  2111. X}    /* end of xfrws_display_resume */
  2112. X
  2113. X/*+-------------------------------------------------------------------------
  2114. X    xfrws_display_allvars()
  2115. X--------------------------------------------------------------------------*/
  2116. Xvoid
  2117. Xxfrws_display_allvars()
  2118. X{
  2119. X    char s32[32];
  2120. X
  2121. X    xfrws_display_name();
  2122. X    switch(xfertype)
  2123. X    {
  2124. X        case ECUSZ_Z:
  2125. X            xfrws_display_xfernew();
  2126. X            xfrws_display_resume();
  2127. X            wmove(xfrw,SNDW_SENDFULL_Y,SNDW_SENDFULL_X);
  2128. X            waddch(xfrw,(p_sendfull) ? 'Y' : 'N');
  2129. X            wmove(xfrw,SNDW_ZWINDW_Y,SNDW_ZWINDW_X);
  2130. X            sprintf(s32,"%u",zwindw_size);
  2131. X            waddstr(xfrw,s32);
  2132. X        case CKERMIT:
  2133. X            wmove(xfrw,SNDW_OVERW_Y,SNDW_OVERW_X);
  2134. X            waddch(xfrw,(p_overwrite) ? 'Y' : 'N');
  2135. X        case ECUSZ_Y:
  2136. X        case ECUSZ_X:
  2137. X            xfrws_display_binary();
  2138. X    }
  2139. X}    /* end of xfrws_display_allvars */
  2140. X
  2141. X/*+-------------------------------------------------------------------------
  2142. X    report_send_status() - report file transmission result
  2143. Xreturns proc-type erc
  2144. Xfor "ecu knowledgeable" protocols only
  2145. X--------------------------------------------------------------------------*/
  2146. Xreport_send_status()
  2147. X{
  2148. X    int erc = 0;
  2149. X    ushort int ustmp;
  2150. X    ulong colors_at_entry = colors_current;
  2151. X    char *signal_name_text();
  2152. X
  2153. X    ustmp = last_child_wait_status;
  2154. X    if((ustmp & 0xFF) == 0)    /* exit() called */
  2155. X    {
  2156. X        ustmp >>= 8;
  2157. X        if(ustmp == 0)
  2158. X        {
  2159. X            setcolor(colors_notify);
  2160. X            pputs("[transfer successful]");
  2161. X            erc = 0;
  2162. X        }
  2163. X        else if(ustmp == 255)
  2164. X        {
  2165. X            setcolor(colors_error);
  2166. X            pputs("[ecu error: transfer program usage error]");
  2167. X            erc = eFATAL_ALREADY;
  2168. X        }
  2169. X        else if(ustmp == 254)
  2170. X        {
  2171. X            setcolor(colors_error);
  2172. X            pputs(
  2173. X            "[protocol failure: bad line conditions or remote not ready]");
  2174. X            erc = eFATAL_ALREADY;
  2175. X        }
  2176. X        else if(ustmp == 253)
  2177. X        {
  2178. X            setcolor(colors_alert);
  2179. X            pputs("[no requested files exist]");
  2180. X            erc = eFATAL_ALREADY;
  2181. SHAR_EOF
  2182. true || echo 'restore of ecuxfer.c failed'
  2183. fi
  2184. echo 'End of ecu320 part 14'
  2185. echo 'File ecuxfer.c is continued in part 15'
  2186. echo 15 > _shar_seq_.tmp
  2187. exit 0
  2188.  
  2189. exit 0 # Just in case...
  2190.