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

  1. Newsgroups: comp.sources.misc
  2. From: Warren Tucker <wht@n4hgf.Mt-Park.GA.US>
  3. Subject:  v21i074:  ecu - ECU async comm package rev 3.10, Part22/37
  4. Message-ID: <1991Aug4.163026.18598@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: fd2995b3260fbb6c80574e020f96075e
  6. Date: Sun, 4 Aug 1991 16:30:26 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 74
  11. Archive-name: ecu/part22
  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.22 (part 22 of ecu310)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file z/ecusz.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" != 22; 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 z/ecusz.c'
  39. else
  40. echo 'x - continuing file z/ecusz.c'
  41. sed 's/^X//' << 'SHAR_EOF' >> 'z/ecusz.c' &&
  42. X         *  sent by the receiver,in place of setjmp/longjmp
  43. X         *  rdchk(fdes) returns non 0 if a character is available
  44. X         */
  45. X        while(rdchk(iofd))
  46. X        {
  47. X            switch(readline(1))
  48. X            {
  49. X            case CAN:
  50. X            case ZPAD:
  51. X                c = getinsync(1);
  52. X                if(c == ZACK)
  53. X                    break;
  54. X#if defined(TCFLSH)
  55. X                ioctl(iofd,TCFLSH,1);
  56. X#endif
  57. X                /* zcrce - dinna wanna starta ping-pong game */
  58. X                zsdata(txbuf,0,ZCRCE);
  59. X                goto gotack;
  60. X
  61. X            case XOFF:        /* Wait a while for an XON */
  62. X            case XOFF|0200:
  63. X                readline(100);
  64. X
  65. X            default:
  66. X                ++junkcount;
  67. X            }
  68. X        }
  69. X#endif    /* READCHECK */
  70. X        if(Txwindow)
  71. X        {
  72. X            while((tcount = Txpos - Lrxpos) >= Txwindow)
  73. X            {
  74. X                if(e != ZCRCQ)
  75. X                    zsdata(txbuf,0,e = ZCRCQ);
  76. X                c = getinsync(1);
  77. X                if(c != ZACK)
  78. X                {
  79. X#if defined(TCFLSH)
  80. X                    ioctl(iofd,TCFLSH,1);
  81. X#endif
  82. X                    zsdata(txbuf,0,ZCRCE);
  83. X                    goto gotack;
  84. X                }
  85. X            }
  86. X        }
  87. X    } while(n == blklen);
  88. X
  89. X    for(;;)
  90. X    {
  91. X        stohdr(Txpos);
  92. X        zsbhdr(ZEOF,Txhdr);
  93. X        switch(err = getinsync(0))
  94. X        {
  95. X        case ZACK:
  96. X            continue;
  97. X        case ZRPOS:
  98. X            goto somemore;
  99. X        case ZRINIT:
  100. X            return(OK);
  101. X        case ZSKIP:
  102. X            report_file_close(6);
  103. X            fclose(in);
  104. X            return(c);
  105. X        default:
  106. X            sprintf(s128,"SEND protocol sync error 0x%04x: %s",err,Pathname);
  107. X            ecu_log_event(getppid(),s128);    /* always log this */
  108. X            report_str(s128 + 5,1);
  109. X            skip_count++;
  110. X            report_error_count();
  111. X            report_file_byte_io(this_file_length);
  112. X            report_file_close(7);
  113. X            fclose(in);
  114. X            return(ERROR);
  115. X        }
  116. X    }
  117. X}    /* end of zsendfdata */
  118. X
  119. X/*+-------------------------------------------------------------------------
  120. X    getinsync(flag) - get back in sync with receiver
  121. X--------------------------------------------------------------------------*/
  122. Xgetinsync(flag)
  123. Xint flag;
  124. X{
  125. X    register c;
  126. X
  127. X    for(;;)
  128. X    {
  129. X        switch(c = zgethdr(Rxhdr,0))
  130. X        {
  131. X        case ZCAN:
  132. X        case ZABORT:
  133. X        case ZFIN:
  134. X        case TIMEOUT:
  135. X            sprintf(s128,"Receiver %s",frametypes[c+FTOFFSET]);
  136. X            report_str(s128,1);
  137. X            return(ERROR);
  138. X        case ZRPOS:
  139. X            report_str("Receiver ZRPOS",1);
  140. X            /* ************************************* */
  141. X            /*  If sending to a modem buffer,you     */
  142. X            /*   might send a break at this point to */
  143. X            /*   dump the modem's buffer.            */
  144. X            /* ************************************* */
  145. X            if(Lastn >= 0 && Lastread == Rxpos)
  146. X            {
  147. X                Dontread = TRUE;
  148. X            } else
  149. X            {
  150. X                clearerr(in);    /* In case file EOF seen */
  151. X                fseek(in,Rxpos,0);
  152. X            }
  153. X            bytcnt = Lrxpos = Txpos = Rxpos;
  154. X            if(Lastsync == Rxpos)                    /* wht - original code */
  155. X            {                                        /* wht - original code */
  156. X                /* save frame count at time of each occurrence (wht) */
  157. X                bad_condx_frame_count = this_file_frame_count;    /* wht */
  158. X                /* save block length at time of error (wht) */
  159. X                if(++SameZrposAgain > 4)            /* wht - original code */
  160. X                {                                    /* wht */
  161. X                    if(bad_condx_blklen == 0)        /* wht */
  162. X                        bad_condx_blklen = blklen;    /* wht */
  163. X                    if(blklen > 256)                /* wht - 32->256 */
  164. X                    {
  165. X                        blklen /= 2;                /* wht - original code */
  166. X                        report_txblklen(blklen);
  167. X                    }
  168. X                }                                    /* wht */
  169. X            }                                        /* wht - original code */
  170. X            Lastsync = Rxpos;
  171. X            report_send_stats(Txpos);
  172. X            return(c);
  173. X        case ZACK:
  174. X            report_str("",-1);
  175. X            Lrxpos = Rxpos;
  176. X            if(flag || Txpos == Rxpos)
  177. X                return(ZACK);
  178. X            continue;
  179. X
  180. X        case ZRINIT:
  181. X            report_str("",-1);
  182. X#if defined(LOG_XFER)
  183. X            sprintf(s128,"SEND success: %s",Pathname);
  184. X            ecu_log_event(getppid(),s128);
  185. X#endif
  186. X        case ZSKIP:
  187. X            report_file_byte_io(this_file_length);
  188. X            report_file_close(0);
  189. X            fclose(in);
  190. X            return(c);
  191. X        case ERROR:
  192. X        default:
  193. X            report_str("Sending ZNAK",0);
  194. X            zsbhdr(ZNAK,Txhdr);
  195. X            continue;
  196. X        }
  197. X    }
  198. X}    /* end of getinsync */
  199. X
  200. X/*+-------------------------------------------------------------------------
  201. X    saybibi() - Say "bibi" to the receiver, try to do it cleanly
  202. X--------------------------------------------------------------------------*/
  203. Xsaybibi()
  204. X{
  205. X    for(;;)
  206. X    {
  207. X        stohdr(0L);        /* CAF Was zsbhdr - minor change */
  208. X        zshhdr(ZFIN,Txhdr);    /*  to make debugging easier */
  209. X        switch(zgethdr(Rxhdr,0))
  210. X        {
  211. X        case ZFIN:
  212. X            sendline('O');
  213. X            sendline('O');
  214. X            flushline();
  215. X        case ZCAN:
  216. X        case TIMEOUT:
  217. X            return;
  218. X        }
  219. X    }
  220. X}    /* end of saybibi */
  221. X
  222. X/*+-------------------------------------------------------------------------
  223. X    determine_transaction_time()
  224. X--------------------------------------------------------------------------*/
  225. Xdetermine_transaction_time()
  226. X{
  227. Xregister c;
  228. Xstruct stat f;
  229. Xchar *name;
  230. X
  231. X    rewind_file_list();
  232. X    TotalLeft = 0;
  233. X    Filesleft = 0;
  234. X    while(get_file_list_name(&name))
  235. X    {
  236. X        f.st_size = -1;
  237. X        if((access(name,04) >= 0) && (stat(name,&f) >= 0))
  238. X        {
  239. X            c = f.st_mode & S_IFMT;
  240. X            if(c != S_IFDIR && c != S_IFBLK)
  241. X            {
  242. X                ++Filesleft;
  243. X                TotalLeft += f.st_size;
  244. X            }
  245. X        }
  246. X    }
  247. X    FilesTotal = Filesleft;
  248. X    rewind_file_list();
  249. X}    /* end of determine_transaction_time */
  250. X
  251. X/* vi: set tabstop=4 shiftwidth=4: */
  252. X/* end of ecusz.c */
  253. SHAR_EOF
  254. echo 'File z/ecusz.c is complete' &&
  255. $TOUCH -am 0725125991 'z/ecusz.c' &&
  256. chmod 0644 z/ecusz.c ||
  257. echo 'restore of z/ecusz.c failed'
  258. Wc_c="`wc -c < 'z/ecusz.c'`"
  259. test 42014 -eq "$Wc_c" ||
  260.     echo 'z/ecusz.c: original size 42014, current size' "$Wc_c"
  261. rm -f _shar_wnt_.tmp
  262. fi
  263. # ============= z/lint_args.h ==============
  264. if test -f 'z/lint_args.h' -a X"$1" != X"-c"; then
  265.     echo 'x - skipping z/lint_args.h (File already exists)'
  266.     rm -f _shar_wnt_.tmp
  267. else
  268. > _shar_wnt_.tmp
  269. echo 'x - extracting z/lint_args.h (Text)'
  270. sed 's/^X//' << 'SHAR_EOF' > 'z/lint_args.h' &&
  271. X/*+-----------------------------------------------------------------------
  272. X    lint_args.h
  273. X------------------------------------------------------------------------*/
  274. X/*+:EDITS:*/
  275. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  276. X/*:04-29-1991-00:01-afterlint-creation */
  277. X
  278. X#ifndef BUILDING_LINT_ARGS
  279. X#ifdef LINT_ARGS
  280. X
  281. X/* baudtest.c */
  282. Xvoid test_tty_and_line_baud(void );
  283. X/* zcommon.c */
  284. Xint get_home_dir(char *);
  285. Xint mode(int );
  286. Xint sendbrk(void );
  287. Xint zmputs(char *);
  288. Xunsigned int getspeed(int );
  289. Xvoid get_curr_dir(char *,int );
  290. X/* zcurses.c */
  291. Xchar *get_elapsed_time(long );
  292. Xchar *get_tod(int,char *);
  293. Xchar *mode_map(unsigned short ,char *);
  294. Xint clear_area(struct _win_st *,int ,int ,int );
  295. Xint clear_area_char(struct _win_st *,int ,int ,int ,char );
  296. Xint determine_output_mode(void );
  297. Xint report_comm_baud_rate(unsigned int );
  298. Xint report_error_count(void );
  299. Xint report_file_byte_io(long );
  300. Xint report_file_open_length(long );
  301. Xint report_file_open_mode(unsigned short );
  302. Xint report_file_rcv_started(char *,long ,long ,unsigned short );
  303. Xvoid report_file_xfer_rate(char *, long, int);
  304. Xint report_protocol_crc_type(char *);
  305. Xint report_protocol_type(char *);
  306. Xint report_rx_tx_count(void );
  307. Xint report_xfer_mode(char *);
  308. Xvoid no_curses_newline(void );
  309. Xvoid report_file_close(int );
  310. Xvoid report_file_open_tod(void );
  311. Xvoid report_file_send_open(char *,struct stat *);
  312. Xvoid report_init(char *);
  313. Xvoid report_last_rxhdr(char *,int );
  314. Xvoid report_last_txhdr(char *,int );
  315. Xvoid report_mode(int );
  316. Xvoid report_rx_ind(int );
  317. Xvoid report_rxblklen(int );
  318. Xvoid report_rxpos(long );
  319. Xvoid report_str(char *,int );
  320. Xvoid report_top_line(char *);
  321. Xvoid report_transaction(char *);
  322. Xvoid report_tx_ind(int );
  323. Xvoid report_txblklen(int );
  324. Xvoid report_txpos(long );
  325. Xvoid report_uninit(int );
  326. Xvoid report_window(void );
  327. X/* zdebug.c */
  328. X/* zmodem.c */
  329. Xint noxrd7(void );
  330. Xint stohdr(long );
  331. Xint zdlread(void );
  332. Xint zgeth1(void );
  333. Xint zgethdr(char *,int );
  334. Xint zgethex(void );
  335. Xint zputhex(int );
  336. Xint zrbhdr(char *);
  337. Xint zrbhdr32(char *);
  338. Xint zrdat32(char *,int );
  339. Xint zrdata(char *,int );
  340. Xint zrhhdr(char *);
  341. Xint zsbh32(int,char *);
  342. Xint zsbhdr(int ,unsigned char *);
  343. Xint zsda32(char *,int ,int );
  344. Xint zsdata(unsigned char *,int ,int );
  345. Xint zsendline(int );
  346. Xint zshhdr(int ,unsigned char *);
  347. Xlong rclhdr(char *);
  348. X
  349. X#else        /* compiler doesn't know about prototyping */
  350. X
  351. X/* baudtest.c */
  352. Xvoid test_tty_and_line_baud();
  353. X/* zcommon.c */
  354. Xunsigned int getspeed();
  355. Xvoid get_curr_dir();
  356. X/* zcurses.c */
  357. Xchar *get_elapsed_time();
  358. Xchar *hhmmss();
  359. Xchar *mode_map();
  360. Xvoid no_curses_newline();
  361. Xvoid report_file_close();
  362. Xvoid report_file_open_tod();
  363. Xvoid report_file_send_open();
  364. Xvoid report_file_xfer_rate();
  365. Xvoid report_init();
  366. Xvoid report_last_rxhdr();
  367. Xvoid report_last_txhdr();
  368. Xvoid report_mode();
  369. Xvoid report_rx_ind();
  370. Xvoid report_rxblklen();
  371. Xvoid report_rxpos();
  372. Xvoid report_str();
  373. Xvoid report_top_line();
  374. Xvoid report_transaction();
  375. Xvoid report_tx_ind();
  376. Xvoid report_txblklen();
  377. Xvoid report_txpos();
  378. Xvoid report_uninit();
  379. Xvoid report_window();
  380. X/* zdebug.c */
  381. X/* zmodem.c */
  382. Xlong rclhdr();
  383. X
  384. X#endif /* LINT_ARGS */
  385. X#endif /* BUILDING_LINT_ARGS */
  386. X
  387. X/* end of lint_args.h */
  388. SHAR_EOF
  389. $TOUCH -am 0725125991 'z/lint_args.h' &&
  390. chmod 0644 z/lint_args.h ||
  391. echo 'restore of z/lint_args.h failed'
  392. Wc_c="`wc -c < 'z/lint_args.h'`"
  393. test 3125 -eq "$Wc_c" ||
  394.     echo 'z/lint_args.h: original size 3125, current size' "$Wc_c"
  395. rm -f _shar_wnt_.tmp
  396. fi
  397. # ============= z/zcommon.c ==============
  398. if test -f 'z/zcommon.c' -a X"$1" != X"-c"; then
  399.     echo 'x - skipping z/zcommon.c (File already exists)'
  400.     rm -f _shar_wnt_.tmp
  401. else
  402. > _shar_wnt_.tmp
  403. echo 'x - extracting z/zcommon.c (Text)'
  404. sed 's/^X//' << 'SHAR_EOF' > 'z/zcommon.c' &&
  405. X/*+-------------------------------------------------------------------------
  406. X    zcommon.c -  ecurz/ecusz common code
  407. X    derived from public domain code by Chuck Forsberg
  408. X    ecu adaptation wht@n4hgf.Mt-Park.GA.US
  409. X
  410. X  Defined functions:
  411. X    cancel_transaction(0)
  412. X    get_curr_dir(currdir,currdir_max)
  413. X    get_home_dir(home_dir)
  414. X    getspeed(code)
  415. X    mode(new_mode)
  416. X    rdchk(f)
  417. X    rdchk(f)
  418. X    sendbrk()
  419. X    zmputs(str)
  420. X
  421. X--------------------------------------------------------------------------*/
  422. X/*+:EDITS:*/
  423. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  424. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  425. X
  426. X#include <stdio.h>
  427. X#include <signal.h>
  428. X#include <setjmp.h>
  429. X#include <ctype.h>
  430. X#include <pwd.h>
  431. X#include "zmodem.h"
  432. X
  433. Xextern unsigned char vmin_count;
  434. Xextern int Zmodem;
  435. Xextern unsigned Baudrate;
  436. Xextern int Twostop;        /* Use two stop bits */
  437. X
  438. X#if defined(LLITOUT)
  439. Xlong Locmode;        /* Saved "local mode" for 4.x BSD "new driver" */
  440. Xlong Locbit = LLITOUT;    /* Bit SUPPOSED to disable output translations */
  441. X#endif
  442. X
  443. Xstruct 
  444. X{
  445. X    unsigned baudr;
  446. X    int speedcode;
  447. X} speeds[] = 
  448. X{
  449. X    110,    B110,
  450. X    300,    B300,
  451. X    600,    B600,
  452. X    1200,    B1200,
  453. X    2400,    B2400,
  454. X    4800,    B4800,
  455. X    9600,    B9600,
  456. X    19200,    EXTA,
  457. X    38400,    EXTB,
  458. X    0,
  459. X};
  460. X
  461. X/* crctab calculated by Mark G. Mendel,Network Systems Corporation */
  462. Xunsigned short crctab[256] = 
  463. X{
  464. X    0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,
  465. X    0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,
  466. X    0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,0x72f7,0x62d6,
  467. X    0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3de,
  468. X    0x2462,0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485,
  469. X    0xa56a,0xb54b,0x8528,0x9509,0xe5ee,0xf5cf,0xc5ac,0xd58d,
  470. X    0x3653,0x2672,0x1611,0x0630,0x76d7,0x66f6,0x5695,0x46b4,
  471. X    0xb75b,0xa77a,0x9719,0x8738,0xf7df,0xe7fe,0xd79d,0xc7bc,
  472. X    0x48c4,0x58e5,0x6886,0x78a7,0x0840,0x1861,0x2802,0x3823,
  473. X    0xc9cc,0xd9ed,0xe98e,0xf9af,0x8948,0x9969,0xa90a,0xb92b,
  474. X    0x5af5,0x4ad4,0x7ab7,0x6a96,0x1a71,0x0a50,0x3a33,0x2a12,
  475. X    0xdbfd,0xcbdc,0xfbbf,0xeb9e,0x9b79,0x8b58,0xbb3b,0xab1a,
  476. X    0x6ca6,0x7c87,0x4ce4,0x5cc5,0x2c22,0x3c03,0x0c60,0x1c41,
  477. X    0xedae,0xfd8f,0xcdec,0xddcd,0xad2a,0xbd0b,0x8d68,0x9d49,
  478. X    0x7e97,0x6eb6,0x5ed5,0x4ef4,0x3e13,0x2e32,0x1e51,0x0e70,
  479. X    0xff9f,0xefbe,0xdfdd,0xcffc,0xbf1b,0xaf3a,0x9f59,0x8f78,
  480. X    0x9188,0x81a9,0xb1ca,0xa1eb,0xd10c,0xc12d,0xf14e,0xe16f,
  481. X    0x1080,0x00a1,0x30c2,0x20e3,0x5004,0x4025,0x7046,0x6067,
  482. X    0x83b9,0x9398,0xa3fb,0xb3da,0xc33d,0xd31c,0xe37f,0xf35e,
  483. X    0x02b1,0x1290,0x22f3,0x32d2,0x4235,0x5214,0x6277,0x7256,
  484. X    0xb5ea,0xa5cb,0x95a8,0x8589,0xf56e,0xe54f,0xd52c,0xc50d,
  485. X    0x34e2,0x24c3,0x14a0,0x0481,0x7466,0x6447,0x5424,0x4405,
  486. X    0xa7db,0xb7fa,0x8799,0x97b8,0xe75f,0xf77e,0xc71d,0xd73c,
  487. X    0x26d3,0x36f2,0x0691,0x16b0,0x6657,0x7676,0x4615,0x5634,
  488. X    0xd94c,0xc96d,0xf90e,0xe92f,0x99c8,0x89e9,0xb98a,0xa9ab,
  489. X    0x5844,0x4865,0x7806,0x6827,0x18c0,0x08e1,0x3882,0x28a3,
  490. X    0xcb7d,0xdb5c,0xeb3f,0xfb1e,0x8bf9,0x9bd8,0xabbb,0xbb9a,
  491. X    0x4a75,0x5a54,0x6a37,0x7a16,0x0af1,0x1ad0,0x2ab3,0x3a92,
  492. X    0xfd2e,0xed0f,0xdd6c,0xcd4d,0xbdaa,0xad8b,0x9de8,0x8dc9,
  493. X    0x7c26,0x6c07,0x5c64,0x4c45,0x3ca2,0x2c83,0x1ce0,0x0cc1,
  494. X    0xef1f,0xff3e,0xcf5d,0xdf7c,0xaf9b,0xbfba,0x8fd9,0x9ff8,
  495. X    0x6e17,0x7e36,0x4e55,0x5e74,0x2e93,0x3eb2,0x0ed1,0x1ef0
  496. X};
  497. X
  498. X#if defined(WANT_UPDCRC_HERE)    /* wht -- moved to zmodem.h */
  499. X/*
  500. X * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell. 
  501. X *  NOTE: First srgument must be in range 0 to 255.
  502. X *        Second argument is referenced twice.
  503. X * 
  504. X * Programmers may incorporate any or all code into their programs,
  505. X * giving proper credit within the source. Publication of the 
  506. X * source routines is permitted so long as proper credit is given 
  507. X * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg,
  508. X * Omen Technology.
  509. X */
  510. X
  511. X#define updcrc(cp,crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp)
  512. X#endif
  513. X
  514. X/*
  515. X  First,the polynomial itself and its table of feedback terms.  The
  516. X  polynomial is:
  517. X
  518. X  X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0
  519. X
  520. X  Note that we take it "backwards" and put the highest-order term in the
  521. X  lowest-order bit.  The X^32 term is "implied"; the LSB is the X^31
  522. X  term,etc.  The X^0 term (usually shown as "+1") results in the MSB being
  523. X  1.  Note that the usual hardware shift register implementation,which is
  524. X  what we're using (we're merely optimizing it by doing eight-bit chunks at
  525. X  a time) shifts bits into the lowest-order term.  In our
  526. X  implementation,that means shifting towards the right.  Why do we do it
  527. X  this way?  Because the calculated CRC must be transmitted in order from
  528. X  highest-order term to lowest-order term.  UARTs transmit characters in
  529. X  order from LSB to MSB.  By storing the CRC this way, we hand it to the
  530. X  UART in the order low-byte to high-byte; the UART sends each low-bit to
  531. X  hight-bit; and the result is transmission bit by bit from highest- to
  532. X  lowest-order term without requiring any bit shuffling on our part.
  533. X  Reception works similarly.
  534. X
  535. X  The feedback terms table consists of 256 32-bit entries.  Notes:   
  536. X
  537. X     The macro for using the table is UPDC32 is located in zmodem.h
  538. X                                                                     
  539. X     It might not be obvious,but the feedback terms simply represent the
  540. X     results of eight shift/xor opera- tions for all combinations of data
  541. X     and CRC register values.
  542. X                                                                     
  543. X     The values must be right-shifted by eight bits by the "UPDC32" logic;
  544. X     the shift must be unsigned (bring in zeroes).  On some hardware you
  545. X     could probably optimize the shift in assembler by using byte-swap
  546. X     instructions.
  547. X*/
  548. X
  549. Xlong cr3tab[] =        /* CRC polynomial 0xedb88320 */
  550. X{
  551. X    0x00000000,0x77073096,0xee0e612c,0x990951ba,0x076dc419,0x706af48f,0xe963a535,0x9e6495a3,
  552. X    0x0edb8832,0x79dcb8a4,0xe0d5e91e,0x97d2d988,0x09b64c2b,0x7eb17cbd,0xe7b82d07,0x90bf1d91,
  553. X    0x1db71064,0x6ab020f2,0xf3b97148,0x84be41de,0x1adad47d,0x6ddde4eb,0xf4d4b551,0x83d385c7,
  554. X    0x136c9856,0x646ba8c0,0xfd62f97a,0x8a65c9ec,0x14015c4f,0x63066cd9,0xfa0f3d63,0x8d080df5,
  555. X    0x3b6e20c8,0x4c69105e,0xd56041e4,0xa2677172,0x3c03e4d1,0x4b04d447,0xd20d85fd,0xa50ab56b,
  556. X    0x35b5a8fa,0x42b2986c,0xdbbbc9d6,0xacbcf940,0x32d86ce3,0x45df5c75,0xdcd60dcf,0xabd13d59,
  557. X    0x26d930ac,0x51de003a,0xc8d75180,0xbfd06116,0x21b4f4b5,0x56b3c423,0xcfba9599,0xb8bda50f,
  558. X    0x2802b89e,0x5f058808,0xc60cd9b2,0xb10be924,0x2f6f7c87,0x58684c11,0xc1611dab,0xb6662d3d,
  559. X    0x76dc4190,0x01db7106,0x98d220bc,0xefd5102a,0x71b18589,0x06b6b51f,0x9fbfe4a5,0xe8b8d433,
  560. X    0x7807c9a2,0x0f00f934,0x9609a88e,0xe10e9818,0x7f6a0dbb,0x086d3d2d,0x91646c97,0xe6635c01,
  561. X    0x6b6b51f4,0x1c6c6162,0x856530d8,0xf262004e,0x6c0695ed,0x1b01a57b,0x8208f4c1,0xf50fc457,
  562. X    0x65b0d9c6,0x12b7e950,0x8bbeb8ea,0xfcb9887c,0x62dd1ddf,0x15da2d49,0x8cd37cf3,0xfbd44c65,
  563. X    0x4db26158,0x3ab551ce,0xa3bc0074,0xd4bb30e2,0x4adfa541,0x3dd895d7,0xa4d1c46d,0xd3d6f4fb,
  564. X    0x4369e96a,0x346ed9fc,0xad678846,0xda60b8d0,0x44042d73,0x33031de5,0xaa0a4c5f,0xdd0d7cc9,
  565. X    0x5005713c,0x270241aa,0xbe0b1010,0xc90c2086,0x5768b525,0x206f85b3,0xb966d409,0xce61e49f,
  566. X    0x5edef90e,0x29d9c998,0xb0d09822,0xc7d7a8b4,0x59b33d17,0x2eb40d81,0xb7bd5c3b,0xc0ba6cad,
  567. X    0xedb88320,0x9abfb3b6,0x03b6e20c,0x74b1d29a,0xead54739,0x9dd277af,0x04db2615,0x73dc1683,
  568. X    0xe3630b12,0x94643b84,0x0d6d6a3e,0x7a6a5aa8,0xe40ecf0b,0x9309ff9d,0x0a00ae27,0x7d079eb1,
  569. X    0xf00f9344,0x8708a3d2,0x1e01f268,0x6906c2fe,0xf762575d,0x806567cb,0x196c3671,0x6e6b06e7,
  570. X    0xfed41b76,0x89d32be0,0x10da7a5a,0x67dd4acc,0xf9b9df6f,0x8ebeeff9,0x17b7be43,0x60b08ed5,
  571. X    0xd6d6a3e8,0xa1d1937e,0x38d8c2c4,0x4fdff252,0xd1bb67f1,0xa6bc5767,0x3fb506dd,0x48b2364b,
  572. X    0xd80d2bda,0xaf0a1b4c,0x36034af6,0x41047a60,0xdf60efc3,0xa867df55,0x316e8eef,0x4669be79,
  573. X    0xcb61b38c,0xbc66831a,0x256fd2a0,0x5268e236,0xcc0c7795,0xbb0b4703,0x220216b9,0x5505262f,
  574. X    0xc5ba3bbe,0xb2bd0b28,0x2bb45a92,0x5cb36a04,0xc2d7ffa7,0xb5d0cf31,0x2cd99e8b,0x5bdeae1d,
  575. X    0x9b64c2b0,0xec63f226,0x756aa39c,0x026d930a,0x9c0906a9,0xeb0e363f,0x72076785,0x05005713,
  576. X    0x95bf4a82,0xe2b87a14,0x7bb12bae,0x0cb61b38,0x92d28e9b,0xe5d5be0d,0x7cdcefb7,0x0bdbdf21,
  577. X    0x86d3d2d4,0xf1d4e242,0x68ddb3f8,0x1fda836e,0x81be16cd,0xf6b9265b,0x6fb077e1,0x18b74777,
  578. X    0x88085ae6,0xff0f6a70,0x66063bca,0x11010b5c,0x8f659eff,0xf862ae69,0x616bffd3,0x166ccf45,
  579. X    0xa00ae278,0xd70dd2ee,0x4e048354,0x3903b3c2,0xa7672661,0xd06016f7,0x4969474d,0x3e6e77db,
  580. X    0xaed16a4a,0xd9d65adc,0x40df0b66,0x37d83bf0,0xa9bcae53,0xdebb9ec5,0x47b2cf7f,0x30b5ffe9,
  581. X    0xbdbdf21c,0xcabac28a,0x53b39330,0x24b4a3a6,0xbad03605,0xcdd70693,0x54de5729,0x23d967bf,
  582. X    0xb3667a2e,0xc4614ab8,0x5d681b02,0x2a6f2b94,0xb40bbe37,0xc30c8ea1,0x5a05df1b,0x2d02ef8d
  583. X};
  584. X
  585. X#if defined(FIONREAD)
  586. X/*
  587. X *  Return non 0 iff something to read from io descriptor f
  588. X */
  589. Xrdchk(f)
  590. X{
  591. X    static long lf;
  592. X
  593. X    ioctl(f,FIONREAD,&lf);
  594. X    return((int) lf);
  595. X}
  596. X#endif
  597. X
  598. X#if defined(SV)
  599. X#include <fcntl.h>
  600. X
  601. Xchar checked = '\0' ;
  602. X/*
  603. X * Nonblocking I/O is a bit different in System V,Release 2
  604. X */
  605. Xrdchk(f)
  606. X{
  607. X    int lf,savestat;
  608. X
  609. X    savestat = fcntl(f,F_GETFL) ;
  610. X    fcntl(f,F_SETFL,savestat | O_NDELAY) ;
  611. X    lf = read(f,&checked,1) ;
  612. X    fcntl(f,F_SETFL,savestat) ;
  613. X    return(lf) ;
  614. X}
  615. X#endif
  616. X
  617. X
  618. Xstatic unsigned
  619. Xgetspeed(code)
  620. Xint code;
  621. X{
  622. X    register n;
  623. X
  624. X    for(n=0; speeds[n].baudr; ++n)
  625. X        if(speeds[n].speedcode == code)
  626. X            return(speeds[n].baudr);
  627. X    return(38400);    /* Assume fifo if ioctl failed */
  628. X}
  629. X
  630. X
  631. X
  632. X#if defined(ICANON)
  633. Xstruct termio oldtty,tty;
  634. X#else
  635. Xstruct sgttyb oldtty,tty;
  636. Xstruct tchars oldtch,tch;
  637. X#endif
  638. X
  639. Xextern int iofd;        /* File descriptor for ioctls & reads */
  640. X
  641. X/*
  642. X * mode(n)
  643. X *  3: save old tty stat, set raw mode with flow control
  644. X *  2: set XON/XOFF for sb/sz with ZMODEM or YMODEM-g
  645. X *  1: save old tty stat, set raw mode 
  646. X *  0: restore original tty mode
  647. X */
  648. Xmode(new_mode)
  649. Xint new_mode;
  650. X{
  651. X    static did0 = FALSE;
  652. X    report_mode(new_mode);
  653. X    switch(new_mode)
  654. X    {
  655. X#if defined(M_SYSV)
  656. X    case 2:        /* Un-raw mode used by sz,sb when -g detected */
  657. X        if(!did0)
  658. X            (void) ioctl(iofd,TCGETA,&oldtty);
  659. X        tty = oldtty;
  660. X        tty.c_iflag &= ~(IXON | IXOFF | IXANY);
  661. X
  662. X#if defined(RTSFLOW)
  663. X        if(tty.c_cflag & (RTSFLOW | CTSFLOW))
  664. X            tty.c_iflag = BRKINT;
  665. X        else
  666. X            tty.c_iflag = BRKINT|IXON;
  667. X#else
  668. X        tty.c_iflag = BRKINT|IXON;
  669. X#endif
  670. X
  671. X        tty.c_oflag = 0;    /* Transparent output */
  672. X
  673. X        tty.c_cflag &= ~PARENB;    /* Disable parity */
  674. X        tty.c_cflag |= CS8;    /* Set character size = 8 */
  675. X        if(Twostop)
  676. X            tty.c_cflag |= CSTOPB;    /* Set two stop bits */
  677. X
  678. X
  679. X#if defined(READCHECK)
  680. X        tty.c_lflag = Zmodem ? 0 : ISIG;
  681. X        tty.c_cc[VINTR] = Zmodem ? -1:030;    /* Interrupt char */
  682. X#else
  683. X        tty.c_lflag = ISIG;
  684. X        tty.c_cc[VINTR] = Zmodem ? 03:030;    /* Interrupt char */
  685. X#endif
  686. X        tty.c_cc[VQUIT] = -1;            /* Quit char */
  687. X#if defined(NFGVMIN)
  688. X        tty.c_cc[VMIN] = 1;
  689. X#else
  690. X        tty.c_cc[VMIN] = 3;     /* This many chars satisfies reads */
  691. X#endif
  692. X        tty.c_cc[VTIME] = 1;    /* or in this many tenths of seconds */
  693. X
  694. X        (void) ioctl(iofd,TCSETAW,&tty);
  695. X        did0 = TRUE;
  696. X        return(OK);
  697. X    case 1:
  698. X    case 3:
  699. X        if(!did0)
  700. X            (void) ioctl(iofd,TCGETA,&oldtty);
  701. X        tty = oldtty;
  702. X        tty.c_iflag &= ~(IXON | IXOFF | IXANY);
  703. X
  704. X#if defined(RTSFLOW)
  705. X        tty.c_iflag = new_mode == 3 ? (IGNBRK | RTSFLOW) : IGNBRK;
  706. X#else
  707. X        tty.c_iflag = new_mode == 3 ? (IGNBRK | IXOFF) : IGNBRK;
  708. X#endif
  709. X
  710. X        /* No echo,crlf mapping,INTR,QUIT,delays,no erase/kill */
  711. X        tty.c_lflag &= ~(ECHO | ICANON | ISIG);
  712. X
  713. X        tty.c_oflag = 0;    /* Transparent output */
  714. X
  715. X        tty.c_cflag &= ~PARENB;    /* Same baud rate,disable parity */
  716. X        tty.c_cflag |= CS8;    /* Set character size = 8 */
  717. X        if(Twostop)
  718. X            tty.c_cflag |= CSTOPB;    /* Set two stop bits */
  719. X#if defined(NFGVMIN)
  720. X        tty.c_cc[VMIN] = 1; /* This many chars satisfies reads */
  721. X#else
  722. X        tty.c_cc[VMIN] = vmin_count; /* This many chars satisfies reads */
  723. X#endif
  724. X        tty.c_cc[VTIME] = 1;    /* or in this many tenths of seconds */
  725. X        (void) ioctl(iofd,TCSETAW,&tty);
  726. X        did0 = TRUE;
  727. X        Baudrate = getspeed(tty.c_cflag & CBAUD);
  728. X        report_comm_baud_rate(Baudrate);
  729. X        return(OK);
  730. X#endif
  731. X#if defined(pyr)
  732. X        /*
  733. X     *  NOTE: this should transmit all 8 bits and at the same time
  734. X     *   respond to XOFF/XON flow control.  If no FIONREAD or other
  735. X     *   READCHECK alternative,also must respond to INTRRUPT char
  736. X     *   This doesn't work with BSD4.  It should work with LLITOUT,
  737. X     *   but LLITOUT was broken on the machine I tried it on.
  738. X     */
  739. X    case 2:        /* Un-raw mode used by sz,sb when -g detected */
  740. X        if(!did0)
  741. X        {
  742. X            ioctl(iofd,TIOCEXCL,0);
  743. X            ioctl(iofd,TIOCGETP,&oldtty);
  744. X            ioctl(iofd,TIOCGETC,&oldtch);
  745. X#if defined(LLITOUT)
  746. X            ioctl(TIOCLGET,&Locmode);    /* Get "local mode" */
  747. X#endif
  748. X        }
  749. X        tty = oldtty;
  750. X        tch = oldtch;
  751. X#if defined(READCHECK)
  752. X        tch.t_intrc = Zmodem ? -1:030;    /* Interrupt char */
  753. X#else
  754. X        tch.t_intrc = Zmodem ? 03:030;    /* Interrupt char */
  755. X#endif
  756. X        tty.sg_flags |= (ODDP|EVENP|CBREAK);
  757. X        tty.sg_flags &= ~(ALLDELAY|CRMOD|ECHO|LCASE);
  758. X        ioctl(iofd,TIOCSETP,&tty);
  759. X        ioctl(iofd,TIOCSETC,&tch);
  760. X#if defined(LLITOUT)
  761. X        ioctl(TIOCLBIS,&Locbit);
  762. X#endif
  763. X/* un-raw doesn't work w/o lit out *//*wht code was 99 */
  764. X        cancel_transaction(0);
  765. X        did0 = TRUE;
  766. X        return(OK);
  767. X    case 1:
  768. X    case 3:
  769. X        if(!did0)
  770. X        {
  771. X            ioctl(iofd,TIOCEXCL,0);
  772. X            ioctl(iofd,TIOCGETP,&oldtty);
  773. X            ioctl(iofd,TIOCGETC,&oldtch);
  774. X#if defined(LLITOUT)
  775. X            ioctl(TIOCLGET,&Locmode);    /* Get "local mode" */
  776. X#endif
  777. X        }
  778. X        tty = oldtty;
  779. X        tty.sg_flags |= RAW;
  780. X        tty.sg_flags &= ~ECHO;
  781. X        ioctl(iofd,TIOCSETP,&tty);
  782. X        did0 = TRUE;
  783. X        Baudrate = getspeed(tty.sg_ospeed);
  784. X        report_comm_baud_rate(Baudrate);
  785. X        return(OK);
  786. X#endif
  787. X    case 0:
  788. X        if(!did0)
  789. X            return(ERROR);
  790. X#if defined(M_SYS5)
  791. X        (void) ioctl(iofd,TCSBRK,1);    /* Wait for output to drain */
  792. X        (void) ioctl(iofd,TCFLSH,1);    /* Flush input queue */
  793. X        (void) ioctl(iofd,TCSETAW,&oldtty);    /* Restore modes */
  794. X        (void) ioctl(iofd,TCXONC,1);    /* Restart output */
  795. X#endif
  796. X#if defined(pyr)
  797. X        ioctl(iofd,TIOCSETP,&oldtty);
  798. X        ioctl(iofd,TIOCSETC,&oldtch);
  799. X        ioctl(iofd,TIOCNXCL,0);
  800. X#if defined(LLITOUT)
  801. X        ioctl(TIOCLSET,&Locmode);    /* Restore "local mode" */
  802. X#endif
  803. X#endif
  804. X
  805. X        return(OK);
  806. X    default:
  807. X        return(ERROR);
  808. X    }
  809. X}
  810. X
  811. X/*+-------------------------------------------------------------------------
  812. X    sendbrk()
  813. X--------------------------------------------------------------------------*/
  814. Xsendbrk()
  815. X{
  816. X#if defined(pyr)
  817. X    sleep(1);
  818. X    ioctl(iofd,TIOCSBRK,0);
  819. X    sleep(1);
  820. X    ioctl(iofd,TIOCCBRK,0);
  821. X#endif
  822. X#if defined(M_SYS5)
  823. X    ioctl(iofd,TCSBRK,0);
  824. X#endif
  825. X}    /* end of sendbrk */
  826. X
  827. X/*+-------------------------------------------------------------------------
  828. X    get_curr_dir(currdir,currdir_max)
  829. X--------------------------------------------------------------------------*/
  830. Xvoid
  831. Xget_curr_dir(currdir,currdir_max)
  832. Xchar *currdir;
  833. Xint currdir_max;
  834. X{
  835. X#if defined(pyr)
  836. X    getwd(currdir);
  837. X#endif
  838. X
  839. X#if defined(M_SYS5)
  840. X    getcwd(currdir,currdir_max);
  841. X#endif
  842. X
  843. X}    /* end of get_curr_dir */
  844. X
  845. X/*+-------------------------------------------------------------------------
  846. X    zmputs(str) - send a string to the modem
  847. X
  848. Xprocessing for \336 (sleep 1 sec) and \335 (break signal)
  849. X--------------------------------------------------------------------------*/
  850. Xzmputs(str)
  851. Xregister char *str;
  852. X{
  853. Xregister char strch;
  854. X
  855. X    while(strch = *str++)
  856. X    {
  857. X        switch(strch)
  858. X        {
  859. X        case '\336':
  860. X            sleep(1);
  861. X            continue;
  862. X        case '\335':
  863. X            sendbrk();
  864. X            continue;
  865. X        default:
  866. X            sendline(strch);
  867. X        }
  868. X    }
  869. X}    /* end of zmputs */
  870. X
  871. X/*+-----------------------------------------------------------------------
  872. X    get_home_dir(home_dir):  leave plenty of room for result!
  873. X------------------------------------------------------------------------*/
  874. Xget_home_dir(home_dir)
  875. Xchar *home_dir;
  876. X{
  877. Xstatic char home_directory[256] = "";
  878. Xstruct passwd *pwent;
  879. Xstruct passwd *getpwuid();
  880. X
  881. X    if(home_directory[0])
  882. X    {
  883. X        strcpy(home_dir,home_directory);
  884. X        return(0);
  885. X    }
  886. X
  887. X    if(!(pwent = getpwuid(getuid())))
  888. X    {
  889. X        perror("cannot get pwent for you!!");
  890. X        exit(1);
  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/* end of zcommon.c */
  900. X/* vi: set tabstop=4 shiftwidth=4: */
  901. SHAR_EOF
  902. $TOUCH -am 0725125991 'z/zcommon.c' &&
  903. chmod 0644 z/zcommon.c ||
  904. echo 'restore of z/zcommon.c failed'
  905. Wc_c="`wc -c < 'z/zcommon.c'`"
  906. test 15678 -eq "$Wc_c" ||
  907.     echo 'z/zcommon.c: original size 15678, current size' "$Wc_c"
  908. rm -f _shar_wnt_.tmp
  909. fi
  910. # ============= z/zcurses.c ==============
  911. if test -f 'z/zcurses.c' -a X"$1" != X"-c"; then
  912.     echo 'x - skipping z/zcurses.c (File already exists)'
  913.     rm -f _shar_wnt_.tmp
  914. else
  915. > _shar_wnt_.tmp
  916. echo 'x - extracting z/zcurses.c (Text)'
  917. sed 's/^X//' << 'SHAR_EOF' > 'z/zcurses.c' &&
  918. X/*+-------------------------------------------------------------------------
  919. X    zcurses.c -- ecu file transfer program curses interface
  920. X
  921. X  000000000011111111112222222222333333333344444444445555555550
  922. X  012345678901234567890123456789012345678901234567890123456789
  923. X00.-[ prog+rev ]-- <dir> ------------------------------------.
  924. X01|  ZMODEM_6____  _40_____________________________________  |
  925. X02|  File ### of ###: _38__________________________________  |
  926. X03|  File position:  _8______ length: _8______  -rwxrwxrwx   |
  927. X04|  _55____________________________________________________ | transaction
  928. X05|  _55____________________________________________________ | last rx/tx hdr
  929. X06|  Comm I/O: rx _8______  tx _8______ bytes                |
  930. X07|  Baud rate: _5___ BINARY blklen: _____ comm mode: RAW-g  |
  931. X08|  Time:    started: __:__:__ this file: __:__:__ window:  |
  932. X09|  __:__:__ elapsed: __:__:__            __:__:__ ________ |
  933. X10|  Errors: this file: _3_ total: _4__ files skipped: _3_   |
  934. X11|  _55____________________________________________________ |  err str
  935. X12|  _55____________________________________________________ |  comment str
  936. X13|  _55____________________________________________________ |  remote info
  937. X14`----------------------------------------------------------'
  938. X14|  FE ___ OE ___ rcvd ________ xmtd ________ RTS _ CTS _
  939. X15|  flow xmtr CTS ____ XOFF ____ rcvr RTS ____ XOFF ____
  940. X
  941. X  Defined functions:
  942. X    clear_area(win,row,col,len)
  943. X    clear_area_char(win,row,col,len,fillchar)
  944. X    determine_output_mode()
  945. X    get_elapsed_time(elapsed_seconds)
  946. X    get_tod(type,tod)
  947. X    mode_map(mode,mode_str)
  948. X    report_comm_baud_rate(baud_rate)
  949. X    report_error_count()
  950. X    report_file_byte_io(count)
  951. X    report_file_close(skipped)
  952. X    report_file_open_length(length)
  953. X    report_file_open_mode(file_mode)
  954. X    report_file_open_tod()
  955. X    report_file_rcv_started(filename,length,last_mod_time,file_mode)
  956. X    report_file_send_open(filename,filestat)
  957. X    report_file_xfer_rate(text,count,final)
  958. X    report_init(title)
  959. X    report_last_rxhdr(rptstr,error_flag)
  960. X    report_last_txhdr(rptstr,error_flag)
  961. X    report_mode(mode)
  962. X    report_protocol_crc_type(str)
  963. X    report_protocol_type(str)
  964. X    report_rx_ind(status)
  965. X    report_rx_tx_count()
  966. X    report_rxblklen(blklen)
  967. X    report_rxpos(rxpos)
  968. X    report_str(rptstr,error_flag)
  969. X    report_top_line(topstr)
  970. X    report_transaction(str)
  971. X    report_tx_ind(status)
  972. X    report_txblklen(blklen)
  973. X    report_txpos(txpos)
  974. X    report_uninit(sig)
  975. X    report_window()
  976. X    report_xfer_mode(str)
  977. X
  978. X------------------------------------------------------------------------*/
  979. X/*+:EDITS:*/
  980. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  981. X/*:06-15-1991-05:47-root@n4hgf-report per-file xfer rate */
  982. X/*:05-25-1991-14:51-wht@n4hgf-FAS/i display */
  983. X/*:04-24-1991-01:22-wht@n4hgf-handle no_curses and single file xfer >= 1 hour */
  984. X/*:02-03-1991-17:27-wht@n4hgf-show elapsed time during no curses xfer */
  985. X/*:01-04-1991-15:54-wht@n4hgf-no_curses per-file xfer rate was wrong */
  986. X/*:12-18-1990-21:26-wht@n4hgf-better output control */
  987. X/*:12-04-1990-04:07-wht@n4hgf-handle slow terminal using faster line */
  988. X/*:12-04-1990-03:04-wht@n4hgf-choose ruling chars based on multiscreen or not */
  989. X/*:09-19-1990-19:36-wht@n4hgf-ecu_log_event now gets pid for log from caller */
  990. X/*:08-14-1990-20:41-wht@n4hgf-ecu3.00-flush old edit history */
  991. X
  992. X#include "../ecucurses.h"
  993. X#include <sys/types.h>
  994. X#include <sys/stat.h>
  995. X#include <ctype.h>
  996. X#include <signal.h>
  997. X#include <time.h>
  998. X#include <sys/timeb.h>
  999. X#if defined(M_SYSV)
  1000. X#   include <sys/machdep.h>
  1001. X#else
  1002. X#  include <sys/at_ansi.h>
  1003. X#  include <sys/kd.h>
  1004. X#endif
  1005. X#if defined(FASI)
  1006. X#  include <local/fas.h>
  1007. X#endif    /* FASI */
  1008. X
  1009. X#include "../pc_scr.h"
  1010. X#include "lint_args.h"
  1011. X
  1012. Xlong time();
  1013. Xextern char *tzname[];
  1014. Xstruct tm *localtime();
  1015. X
  1016. Xunsigned char sTL = at_TL;
  1017. Xunsigned char sTR = at_TR;
  1018. Xunsigned char sBL = at_BL;
  1019. Xunsigned char sBR = at_BR;
  1020. Xunsigned char sLT = at_LT;
  1021. Xunsigned char sRT = at_RT;
  1022. Xunsigned char sVR = at_VR;
  1023. Xunsigned char sHR = at_HR;
  1024. X
  1025. X#if defined(FASI)
  1026. X#define WIN_LINES    17
  1027. X#else
  1028. X#define WIN_LINES    15
  1029. X#endif    /* FASI */
  1030. X#define WIN_COLS    60
  1031. X#define WIN_TOPY    2
  1032. X#define WIN_LEFTX    8
  1033. X
  1034. Xextern char curr_dir[];
  1035. Xextern char *bottom_label;
  1036. Xextern int Filcnt;
  1037. Xextern int ecusz_flag;    /* ecusz == 1, ecurz == 0 */
  1038. Xextern int force_no_curses;
  1039. Xextern int skip_count;
  1040. Xextern int npats;
  1041. Xextern long rxpos;
  1042. Xextern int log_packets;
  1043. Xextern long Txpos;
  1044. Xextern long Rxpos;
  1045. X
  1046. XWINDOW    *win;
  1047. Xint (*original_sigint_handler)();
  1048. Xint (*original_sigquit_handler)();
  1049. Xint (*original_sigterm_handler)();
  1050. Xint report_init_complete = 0;
  1051. Xint report_verbosity;
  1052. Xint no_curses = 0;
  1053. Xint no_curses_pos = 0;
  1054. Xint this_file_errors;
  1055. Xlong this_file_xfer_count = 0;
  1056. Xint total_errors;
  1057. Xint show_window = 0;
  1058. Xlong current_seconds = 0;
  1059. Xlong start_seconds = 0;
  1060. Xlong this_file_start_seconds = 0;
  1061. Xlong elapsed_seconds = 0;
  1062. Xunsigned long total_data_chars_xfered = 0L;
  1063. Xunsigned int zcurses_baud_rate = 0;
  1064. Xchar s128[128];
  1065. X
  1066. X#if defined(FASI)
  1067. Xstruct fas_info fip_start;
  1068. X#endif /* FASI */
  1069. X
  1070. X
  1071. Xchar *win_template[] =
  1072. X{
  1073. X/*00000000001111111111222222222233333333334444444444555555555 */
  1074. X/*01234567890123456789012345678901234567890123456789012345678 */
  1075. X/*.----------------------------------------------------------. */
  1076. X  "                                                          ",    /* 1 */
  1077. X  "  File ### of ###: _____________________________________  ",    /* 2 */
  1078. X  "  File position:  ________ length: ________               ",    /* 3 */
  1079. X  "                                                          ",    /* 4 */
  1080. X  "  tx: ______________________  rx: ______________________  ",    /* 5 */
  1081. X  "  Comm I/O: rx ________  tx ________ bytes                ",    /* 6 */
  1082. X  "  Baud rate: _____ ______ blklen: _____ comm mode: ______ ",    /* 7 */
  1083. X  "  Time:    started: __:__:__ this file: __:__:__          ", /* 8 */
  1084. X  "  __:__:__ elapsed: __:__:__            __:__:__          ", /* 9 */
  1085. X  "  Errors: this file: ___ total: ____ files skipped: ___   ", /* 10 */
  1086. X  "                                                          ",    /* 11 */
  1087. X  "                                                          ",    /* 12 */
  1088. X  "                                                          ",    /* 13 */
  1089. X#if defined(FASI)
  1090. X  "  FE ___ OE ___ rcvd ________ xmtd ________ RTS _ CTS _   ",
  1091. X  "  flow xmtr CTS ____ XOFF ____ rcvr RTS ____ XOFF ____    ",
  1092. X#endif    /* FASI */
  1093. X/*`----------------------------------------------------------' */
  1094. X(char *)0
  1095. X};
  1096. X
  1097. X/*+-----------------------------------------------------------------------
  1098. X    char *get_elapsed_time(elapsed_seconds)
  1099. X    hh:mm:ss returned
  1100. X  static string address is returned
  1101. X------------------------------------------------------------------------*/
  1102. Xchar *
  1103. Xget_elapsed_time(elapsed_seconds)
  1104. Xlong elapsed_seconds;
  1105. X{
  1106. X    static char elapsed_time_str[10];
  1107. X    long hh,mm,ss;
  1108. X
  1109. X    hh = elapsed_seconds / 3600;
  1110. X    elapsed_seconds -= hh * 3600;
  1111. X    mm = elapsed_seconds / 60L;
  1112. X    elapsed_seconds -= mm * 60L;
  1113. X    ss = elapsed_seconds;
  1114. X
  1115. X    sprintf(elapsed_time_str,"%02ld:%02ld:%02ld",hh,mm,ss);
  1116. X    return(elapsed_time_str);
  1117. X}    /* end of get_elapsed_time */
  1118. X
  1119. X/*+-----------------------------------------------------------------------
  1120. X    char *get_tod(type,tod)
  1121. X
  1122. X  time of day types:
  1123. X    0        hh:mm
  1124. X    1        hh:mm:ss
  1125. X    2        mm-dd-yyyy hh:mm
  1126. X
  1127. X  static string address is returned
  1128. X  if tod != (char *)0, time is returned there too
  1129. X------------------------------------------------------------------------*/
  1130. Xchar *
  1131. Xget_tod(type,tod)
  1132. Xint type;
  1133. Xchar *tod;
  1134. X{
  1135. X    static char tod_str[32];
  1136. X    long cur_time = time((long *)0);
  1137. X    struct tm *lt = localtime(&cur_time);
  1138. X
  1139. X    switch(type)
  1140. X    {
  1141. X        case 0:
  1142. X            sprintf(tod_str,"%02d:%02d",lt->tm_hour,lt->tm_min);
  1143. X            break;
  1144. X
  1145. X        default:
  1146. X        case 1:
  1147. X            sprintf(tod_str,"%02d:%02d:%02d",
  1148. X                lt->tm_hour,lt->tm_min,lt->tm_sec);
  1149. X            break;
  1150. X
  1151. X        case 2:
  1152. X            sprintf(tod_str,"%02d-%02d-%04d %02d:%02d",
  1153. X                lt->tm_mon + 1,lt->tm_mday,lt->tm_year + 1900,
  1154. X                lt->tm_hour,lt->tm_min);
  1155. X            break;
  1156. X    }
  1157. X
  1158. X    if(tod != (char *)0)
  1159. X        strcpy(tod,tod_str);
  1160. X
  1161. X    return(tod_str);
  1162. X}    /* end of get_tod */
  1163. X
  1164. X/*+-----------------------------------------------------------------------
  1165. X    mode_map(mode,mode_str)    build drwxrwxrwx string
  1166. X------------------------------------------------------------------------*/
  1167. Xchar *
  1168. Xmode_map(mode,mode_str)
  1169. Xunsigned short mode;
  1170. Xchar *mode_str;
  1171. X{
  1172. Xregister unsigned ftype = mode & S_IFMT;
  1173. Xregister char *rtn;
  1174. Xstatic char result[12];
  1175. X
  1176. X    rtn = (mode_str == (char *)0) ? result : mode_str;
  1177. X
  1178. X    /*               drwxrwxrwx */
  1179. X    /*               0123456789 */
  1180. X    strcpy(rtn,"----------");
  1181. X
  1182. X    switch(ftype)
  1183. X    {
  1184. X        case S_IFIFO:    *rtn = 'p'; break; /* FIFO (named pipe) */
  1185. X        case S_IFDIR:    *rtn = 'd'; break; /* directory */
  1186. X        case S_IFCHR:    *rtn = 'c'; break; /* character special */
  1187. X        case S_IFBLK:    *rtn = 'b'; break; /* block special */
  1188. X        case S_IFREG:    *rtn = '-'; break; /* regular */
  1189. X
  1190. X#if defined(pyr) | defined(BSD4)
  1191. X        case S_IFLNK:    *rtn = 'l'; break; /* symbolic link */
  1192. X        case S_IFSOCK:    *rtn = 's'; break; /* socket */
  1193. X#endif
  1194. X
  1195. X#if defined(M_SYS5)
  1196. X        case S_IFNAM:                        /* name space entry */
  1197. X            if(mode & S_INSEM)                /* semaphore */
  1198. X            {
  1199. X                *rtn = 's';
  1200. X                break;
  1201. X            }
  1202. X            if(mode & S_INSHD)                /* shared memory */
  1203. X            {
  1204. X                *rtn = 'm';
  1205. X                break;
  1206. X            }
  1207. X#endif
  1208. X
  1209. X        default:        *rtn = '?'; break;    /* ??? */
  1210. X    }
  1211. X
  1212. X    if(mode & 000400) *(rtn + 1) = 'r';
  1213. X    if(mode & 000200) *(rtn + 2) = 'w';
  1214. X    if(mode & 000100) *(rtn + 3) = 'x';
  1215. X    if(mode & 004000) *(rtn + 3) = 's';
  1216. X    if(mode & 000040) *(rtn + 4) = 'r';
  1217. X    if(mode & 000020) *(rtn + 5) = 'w';
  1218. X    if(mode & 000010) *(rtn + 6) = 'x';
  1219. X    if(mode & 002000) *(rtn + 6) = 's';
  1220. X    if(mode & 000004) *(rtn + 7) = 'r';
  1221. X    if(mode & 000002) *(rtn + 8) = 'w';
  1222. X    if(mode & 000001) *(rtn + 9) = 'x';
  1223. X    if(mode & 001000) *(rtn + 9) = 't';
  1224. X
  1225. X    return(rtn);
  1226. X
  1227. X}    /* end of mode_map */
  1228. X
  1229. X/*+-------------------------------------------------------------------------
  1230. X    no_curses_newline()
  1231. X--------------------------------------------------------------------------*/
  1232. Xvoid
  1233. Xno_curses_newline()
  1234. X{
  1235. X    if(no_curses_pos)
  1236. X        printf("\r\n");
  1237. X    no_curses_pos = 0;
  1238. X
  1239. X}    /* end of no_curses_newline */
  1240. X
  1241. X/*+-------------------------------------------------------------------------
  1242. X    clear_area(win,row,col,len)
  1243. X--------------------------------------------------------------------------*/
  1244. Xclear_area(win,row,col,len)
  1245. XWINDOW    *win;
  1246. Xint row;
  1247. Xint col;
  1248. Xint len;
  1249. X{
  1250. X    if(no_curses)
  1251. X        return;
  1252. X    wmove(win,row,col);
  1253. X    while(len-- > 0)
  1254. X        waddch(win,' ');
  1255. X    wmove(win,row,col);
  1256. X
  1257. X}    /* end of clear_area */
  1258. X
  1259. X/*+-------------------------------------------------------------------------
  1260. X    clear_area_char(win,row,col,len,fillchar)
  1261. X--------------------------------------------------------------------------*/
  1262. Xclear_area_char(win,row,col,len,fillchar)
  1263. XWINDOW    *win;
  1264. Xint row;
  1265. Xint col;
  1266. Xint len;
  1267. Xchar fillchar;
  1268. X{
  1269. X    if(no_curses)
  1270. X        return;
  1271. X    wmove(win,row,col);
  1272. X    while(len-- > 0)
  1273. X        waddch(win,fillchar);
  1274. X    wmove(win,row,col);
  1275. X
  1276. X}    /* end of clear_area_char */
  1277. X
  1278. X/*+-------------------------------------------------------------------------
  1279. X    report_top_line(topstr)
  1280. X   top line: row 1 col 17 length 42
  1281. X--------------------------------------------------------------------------*/
  1282. Xvoid
  1283. Xreport_top_line(topstr)
  1284. Xchar *topstr;
  1285. X{
  1286. Xchar s42[42];
  1287. X
  1288. X    if(no_curses)
  1289. X    {
  1290. X        no_curses_newline();
  1291. X        no_curses_pos = printf("%s",topstr);
  1292. X        fflush(stdout);
  1293. X        return;
  1294. X    }
  1295. X
  1296. X    clear_area(win,1,17,42);
  1297. X    if(strlen(topstr) < 40)
  1298. X        waddstr(win,topstr);
  1299. X    else
  1300. X    {
  1301. X        strncpy(s42,topstr,40);
  1302. X        s42[40] = 0;
  1303. X        waddstr(win,s42);
  1304. X    }
  1305. X}    /* end of report_top_line */
  1306. X
  1307. X/*+-------------------------------------------------------------------------
  1308. X    report_xfer_mode(modestr)  BINARY/ASCII
  1309. X   protocol xfer type: row 7 col 20 length 6
  1310. X--------------------------------------------------------------------------*/
  1311. Xreport_xfer_mode(str)
  1312. Xchar *str;
  1313. X{
  1314. Xchar s10[10];
  1315. X
  1316. X    if(no_curses)
  1317. X        return;
  1318. X    if(strlen(str) > 6)
  1319. X    {
  1320. X        strncpy(s10,str,6);
  1321. X        s10[7] = 0;
  1322. X        str = s10;
  1323. X    }
  1324. X    clear_area(win,7,20,6);
  1325. X    waddstr(win,str);
  1326. X    wrefresh(win);
  1327. X
  1328. X}    /* end of report_xfer_mode */
  1329. X
  1330. X/*+-------------------------------------------------------------------------
  1331. X    report_protocol_type(str)
  1332. X
  1333. X  protocol type:  row 1 col 3 length 6 string
  1334. X--------------------------------------------------------------------------*/
  1335. Xreport_protocol_type(str)
  1336. Xregister char *str;
  1337. X{
  1338. Xchar s10[10];
  1339. X
  1340. X    if(no_curses)
  1341. X    {
  1342. X        return;
  1343. X    }
  1344. X
  1345. X    if(strlen(str) > 6)
  1346. X    {
  1347. X        strncpy(s10,str,6);
  1348. X        s10[7] = 0;
  1349. X        str = s10;
  1350. X    }
  1351. X    clear_area(win,1,3,6);
  1352. X    waddstr(win,str);
  1353. X    wrefresh(win);
  1354. X
  1355. X}    /* end of report_protocol_type */
  1356. X
  1357. X/*+-------------------------------------------------------------------------
  1358. X    report_protocol_crc_type(str)
  1359. X
  1360. X  protocol crc type:  row 1 col 9 length 6
  1361. X--------------------------------------------------------------------------*/
  1362. Xreport_protocol_crc_type(str)
  1363. Xregister char *str;
  1364. X{
  1365. Xchar s8[8];
  1366. X
  1367. X    if(no_curses)
  1368. X    {
  1369. X        return;
  1370. X    }
  1371. X
  1372. X    if(strlen(str) > 6)
  1373. X    {
  1374. X        strncpy(s8,str,6);
  1375. X        s8[7] = 0;
  1376. X        str = s8;
  1377. X    }
  1378. X    clear_area(win,1,9,6);
  1379. X    waddstr(win,str);
  1380. X    wrefresh(win);
  1381. X
  1382. X}    /* end of report_protocol_crc_type */
  1383. X
  1384. X/*+-------------------------------------------------------------------------
  1385. X    report_uninit(sig)
  1386. X--------------------------------------------------------------------------*/
  1387. Xvoid
  1388. Xreport_uninit(sig)
  1389. Xint sig;        /* if -1, called by normal code, else kill() value */
  1390. X{
  1391. X    float rate = 0.0;
  1392. X    float eff = 0.0;
  1393. X
  1394. X    if(report_init_complete)
  1395. X    {
  1396. X        current_seconds = time((long *)0);
  1397. X        elapsed_seconds = current_seconds - start_seconds;
  1398. X        if(elapsed_seconds && (zcurses_baud_rate > 50))
  1399. X        {
  1400. X            rate = (float)total_data_chars_xfered / (float)elapsed_seconds;
  1401. X            if(zcurses_baud_rate)
  1402. X                eff  = 100.0 * (rate / ((float)zcurses_baud_rate / 10.0));
  1403. X        }
  1404. X        if(rate > 0.01)
  1405. X        {
  1406. X            sprintf(s128,"XFERINFO transaction rate ~= %.0f ch/sec (%.0f%%)",
  1407. X                rate,(eff > 0.5) ? eff : 0.0);
  1408. X            if(log_packets)
  1409. X            {
  1410. X                write(log_packets,"info: ",6);
  1411. X                write(log_packets,s128,strlen(s128));
  1412. X                write(log_packets,"\n",1);
  1413. X            }
  1414. X            report_top_line(s128 + 9);
  1415. X#if defined(WHT)
  1416. X            ecu_log_event(getppid(),s128);
  1417. X#endif
  1418. X        }
  1419. X        if(no_curses)
  1420. X            no_curses_newline();
  1421. X        else
  1422. X        {
  1423. X            report_file_byte_io(0L);
  1424. X            report_rx_tx_count();
  1425. X            wmove(win,WIN_LINES - 1,WIN_COLS - 1);
  1426. X            wrefresh(win);
  1427. X            endwin();
  1428. X            fprintf(stderr,"\r\n\r\n\r\n");
  1429. X            fflush(stderr);
  1430. X        }
  1431. X        report_init_complete = 0;
  1432. X    }
  1433. X
  1434. X}    /* end of report_uninit */
  1435. X
  1436. X/*+-------------------------------------------------------------------------
  1437. X    determine_output_mode()
  1438. X--------------------------------------------------------------------------*/
  1439. Xint
  1440. Xdetermine_output_mode()
  1441. X{
  1442. X    int monitor_type;
  1443. X    struct stat dn;
  1444. X    struct stat tty_stat;
  1445. X#ifdef NO_PTY_CURSES
  1446. X    struct stat pty_stat;
  1447. X#endif
  1448. X
  1449. X    if(force_no_curses)
  1450. X    {
  1451. X        no_curses = 1;
  1452. X        report_verbosity = 1;
  1453. X        report_init_complete = 1;
  1454. X        return(1);
  1455. X    }
  1456. X
  1457. X    if(ioctl(0,CONS_GET,&monitor_type) < 0)    /* not multiscreen */
  1458. X    {
  1459. X        sTL = vanilla_TL;
  1460. X        sTR = vanilla_TR;
  1461. X        sBL = vanilla_BL;
  1462. X        sBR = vanilla_BR;
  1463. X        sLT = vanilla_LT;
  1464. X        sRT = vanilla_RT;
  1465. X        sVR = vanilla_VR;
  1466. X        sHR = vanilla_HR;
  1467. X
  1468. X        /*
  1469. X         * if tty (console) is not character special, only report
  1470. X         * basic progress
  1471. X         */
  1472. X        memset((char *)&dn,0,sizeof(dn));
  1473. X        stat("/dev/null",&dn);
  1474. X        if(fstat(0,&tty_stat) ||
  1475. X            ((tty_stat.st_mode & S_IFMT) != S_IFCHR) ||
  1476. X            (dn.st_rdev == tty_stat.st_rdev))
  1477. X        {
  1478. X            no_curses = 1;
  1479. X            report_verbosity = 0;
  1480. X            report_init_complete = 1;
  1481. X            return(1);
  1482. X        }
  1483. X
  1484. X#ifdef NO_PTY_CURSES
  1485. X        /*
  1486. X         * if pty (must be xterm), send clear screen and no curses
  1487. X         */
  1488. X        if(!stat("/dev/ttyp0",&pty_stat) &&
  1489. X            (pty_stat.st_rdev & 0xFF00) == (tty_stat.st_rdev & 0xFF00))
  1490. X        {
  1491. X        static char ff[] = "\033[H\0332J\r\n";
  1492. X            write(2,ff,strlen(ff));
  1493. X            no_curses = 1;
  1494. X            report_verbosity = 1;
  1495. X            report_init_complete = 1;
  1496. X            return(1);
  1497. X        }
  1498. X#endif
  1499. X
  1500. X        /*
  1501. X         * if non-multiscreen tty baud rate not at least that
  1502. X         * of the attached line, use no curses, but do be a bit
  1503. X         * more verbose than if tty not char special
  1504. X         */
  1505. X        test_tty_and_line_baud();
  1506. X    }
  1507. X
  1508. X    return(no_curses);
  1509. X
  1510. X}    /* end of determine_output_mode */
  1511. X
  1512. X/*+-------------------------------------------------------------------------
  1513. X    report_init(title)
  1514. X  "top line": row 1 col 11 len 21
  1515. X  file quan:  row 2 col 15 len  3
  1516. X              row 2 col 12 len  7 clear "of ###"
  1517. X  start time: row 8 col 21 len  8
  1518. X  "window:"   row 8 col 50 len  7
  1519. X--------------------------------------------------------------------------*/
  1520. Xvoid
  1521. Xreport_init(title)
  1522. Xchar *title;
  1523. X{
  1524. X    register int itmp;
  1525. X
  1526. X    if(report_init_complete)
  1527. X        return;
  1528. X
  1529. X    start_seconds = time((long *)0);
  1530. X    current_seconds = start_seconds;
  1531. X
  1532. X    if(no_curses)
  1533. X        return;
  1534. X
  1535. X#if defined(FASI)
  1536. X    { extern int iofd;
  1537. X        (void)ioctl(iofd,FASIC_SIP,&fip_start);
  1538. X    }
  1539. X#endif /* FASI */
  1540. X
  1541. X    if(!initscr())
  1542. X        exit(254);
  1543. X    if(!stdscr)
  1544. X        exit(254);
  1545. X    crmode();
  1546. X    noecho();
  1547. X    nonl();
  1548. X    clear();
  1549. X    report_init_complete = 1;
  1550. X    win = newwin(WIN_LINES,WIN_COLS,WIN_TOPY,WIN_LEFTX);
  1551. X    box(win,sVR,sHR);
  1552. X    wmove(win,0,0); waddch(win,sTL);
  1553. X    wmove(win,win->_maxy - 1,0); waddch(win,sBL);
  1554. X    wmove(win,win->_maxy - 1,win->_maxx - 1); waddch(win,sBR);
  1555. X    wmove(win,0,win->_maxx - 1); waddch(win,sTR);
  1556. X    wmove(win,0,2);
  1557. X    wstandout(win);
  1558. X    waddch(win,'[');
  1559. X    waddch(win,' ');
  1560. X    strcpy(s128,title);
  1561. X    waddstr(win,s128);
  1562. X    waddch(win,' ');
  1563. X    waddch(win,']');
  1564. X    wstandend(win);
  1565. X    waddch(win,sHR);
  1566. X    waddch(win,sHR);
  1567. X    waddch(win,' ');
  1568. X    itmp = WIN_COLS - 2 - 7 - strlen(title);
  1569. X    curr_dir[itmp] = 0;
  1570. X    waddstr(win,curr_dir);
  1571. X    waddch(win,' ');
  1572. X    if(bottom_label)
  1573. X    {
  1574. X        strncpy(s128,bottom_label,WIN_COLS - 6);
  1575. X        s128[WIN_COLS - 6] = 0;
  1576. X        wmove(win,WIN_LINES - 1,2);
  1577. X        waddch(win,' ');
  1578. X        waddstr(win,s128);
  1579. X        waddch(win,' ');
  1580. X    }
  1581. X
  1582. X    itmp = 0;
  1583. X    while(1)
  1584. X    {
  1585. X        if(win_template[itmp] == (char *)0)
  1586. X            break;
  1587. X        wmove(win,itmp + 1,1);
  1588. X        waddstr(win,win_template[itmp++]);
  1589. X    }
  1590. X    if(ecusz_flag)
  1591. X    {
  1592. X        clear_area(win,2,15,3);
  1593. X        sprintf(s128,"%-3d",npats);
  1594. X        waddstr(win,s128);
  1595. X#if defined(FORK_DEBUG)
  1596. X        sprintf(s128,"DEBUG ecusz pid %d",getpid());
  1597. X#endif
  1598. X    }
  1599. X    else    /* ecurz */
  1600. X    {
  1601. X        clear_area(win,2,11,8);    /* clear "of ###" */
  1602. X        waddstr(win,":");
  1603. X#if defined(FORK_DEBUG)
  1604. X        sprintf(s128,"DEBUG ecurz pid %d",getpid());
  1605. X#endif
  1606. X    }
  1607. X
  1608. X#if defined(FORK_DEBUG)
  1609. X    ecu_log_event(getppid(),s128);
  1610. X#endif
  1611. X
  1612. X    clear_area(win,1,11,21);
  1613. X    report_error_count();
  1614. X    clear_area(win,8,21,8);        /* starting time */
  1615. X    waddstr(win,get_tod(1,(char *)0));
  1616. X
  1617. X    if(show_window)
  1618. X    {
  1619. X        wmove(win,8,50);
  1620. X        waddstr(win,"window:");
  1621. X        wmove(win,9,50);
  1622. X        waddstr(win,"+0");
  1623. X    }
  1624. X
  1625. X    wrefresh(win);
  1626. X
  1627. X}    /* end of report_init */
  1628. X
  1629. X/*+-------------------------------------------------------------------------
  1630. X    report_rx_ind(status)
  1631. X--------------------------------------------------------------------------*/
  1632. Xvoid
  1633. Xreport_rx_ind(status)
  1634. Xint status;
  1635. X{
  1636. Xchar *cptr;
  1637. X
  1638. X    if(no_curses)
  1639. X    {
  1640. X        if(report_verbosity && status)
  1641. X        {
  1642. X            printf("R");
  1643. X            if(++no_curses_pos > 75)
  1644. X            {
  1645. X                no_curses_newline();
  1646. X                current_seconds = time((long *)0);
  1647. X                elapsed_seconds = current_seconds - this_file_start_seconds;
  1648. X                cptr = get_elapsed_time(elapsed_seconds);
  1649. X                no_curses_pos = printf("%s elapsed ",cptr +
  1650. X                    ((elapsed_seconds < 3600L) ? 3 : 0));
  1651. X            }
  1652. X            fflush(stdout);
  1653. X        }
  1654. X        return;
  1655. X    }
  1656. X    wmove(win,1,54);
  1657. X    waddch(win,(status) ? 'R' : ' ');
  1658. X    wmove(win,1,54);
  1659. X    wrefresh(win);
  1660. X}    /* end of report_rx_ind */
  1661. X
  1662. X/*+-------------------------------------------------------------------------
  1663. X    report_tx_ind(status)
  1664. X--------------------------------------------------------------------------*/
  1665. Xvoid
  1666. Xreport_tx_ind(status)
  1667. Xint status;
  1668. X{
  1669. Xchar *cptr;
  1670. X    if(no_curses)
  1671. X    {
  1672. X        if(report_verbosity && status)
  1673. X        {
  1674. X            printf("T");
  1675. X            if(++no_curses_pos > 75)
  1676. X            {
  1677. X                no_curses_newline();
  1678. X                no_curses_newline();
  1679. X                current_seconds = time((long *)0);
  1680. X                elapsed_seconds = current_seconds - this_file_start_seconds;
  1681. X                cptr = get_elapsed_time(elapsed_seconds);
  1682. X                no_curses_pos = printf("%s elapsed ",cptr +
  1683. X                    ((elapsed_seconds < 3600L) ? 3 : 0));
  1684. X            }
  1685. X            fflush(stdout);
  1686. X        }
  1687. X        return;
  1688. X    }
  1689. X    wmove(win,1,56);
  1690. X    waddch(win,(status) ? 'T' : ' ');
  1691. X    wmove(win,1,56);
  1692. X    wrefresh(win);
  1693. X}    /* end of report_tx_ind */
  1694. X
  1695. X/*+-------------------------------------------------------------------------
  1696. X    report_window() - if enable, show open widow size
  1697. X--------------------------------------------------------------------------*/
  1698. Xvoid
  1699. Xreport_window()
  1700. X{
  1701. X    if(show_window && !no_curses)
  1702. X    {
  1703. X    long ltmp;
  1704. X        wmove(win,9,50);
  1705. X        if((ltmp = (Txpos - Rxpos)) > 999999L)
  1706. X            waddstr(win,">+999999");
  1707. X        else if(ltmp < -999999L)
  1708. X            ;
  1709. X        else
  1710. X        {
  1711. X            sprintf(s128,"%+-8ld",ltmp);
  1712. X            waddstr(win,s128);
  1713. X            if(log_packets)
  1714. X            {
  1715. X                write(log_packets,"window: ",8);
  1716. X                write(log_packets,s128,strlen(s128));
  1717. X                write(log_packets,"\n",1);
  1718. X            }
  1719. X        }
  1720. X    }
  1721. X}    /* end of report_window */
  1722. X
  1723. X/*+-------------------------------------------------------------------------
  1724. X    report_rx_tx_count()
  1725. X
  1726. X  This function may be counted upon to perform wrefresh(win)
  1727. X
  1728. X  rx char count:          row  6 col 16 len 8 unsigned long
  1729. X  tx char count:          row  6 col 29 len 8 unsigned long
  1730. X  session elapsed time:   row  9 col 21 len 8
  1731. X  this file elapsed time: row  9 col 41 len 8
  1732. X  current tod:            row  9 col  3 len 8
  1733. X  window:                 row  9 col 50 len 8
  1734. X
  1735. XIf FASI,
  1736. X  FE:                     row 14 col  6 len 4
  1737. X  OE:                     row 14 col 13 len 4
  1738. X  rcvd count:             row 14 col 22 len 8 unsigned long
  1739. X  xmtd count:             row 14 col 36 len 8 unsigned long
  1740. X  RTS status:             row 14 col 48 len 1
  1741. X  CTS status:             row 14 col 55 len 1
  1742. X  xmtr CTS count:         row 15 col 18 len 4
  1743. X  xmtr XOFF count:        row 15 col 28 len 4
  1744. X  rcvr CTS count:         row 15 col 42 len 4
  1745. X  rcvr XOFF count:        row 15 col 52 len 4
  1746. X--------------------------------------------------------------------------*/
  1747. Xreport_rx_tx_count()
  1748. X{
  1749. X    extern unsigned long rx_char_count;
  1750. X    extern unsigned long tx_char_count;
  1751. X#if defined(FASI)
  1752. X    unsigned long ltmp;
  1753. X    struct fas_info now;
  1754. X    extern int iofd;
  1755. X#endif    /* FASI */
  1756. X
  1757. X    register char *cptr;
  1758. X
  1759. X    if(no_curses)
  1760. X    {
  1761. X        return;
  1762. X    }
  1763. X
  1764. X    sprintf(s128,"%-8ld",rx_char_count);
  1765. X    wmove(win,6,16);
  1766. X    waddstr(win,s128);
  1767. X    sprintf(s128,"%-8ld",tx_char_count);
  1768. X    wmove(win,6,29);
  1769. X    waddstr(win,s128);
  1770. X
  1771. X    /* now time of day */
  1772. X    wmove(win,9,3);
  1773. X    cptr = get_tod(1,(char *)0);
  1774. X    waddstr(win,cptr);
  1775. X    current_seconds = time((long *)0);
  1776. X    elapsed_seconds = current_seconds - start_seconds;
  1777. X    cptr = get_elapsed_time(elapsed_seconds);
  1778. X    wmove(win,9,21);
  1779. X    waddstr(win,cptr);
  1780. X    if(this_file_start_seconds)
  1781. X        elapsed_seconds = current_seconds - this_file_start_seconds;
  1782. X    else
  1783. X        elapsed_seconds = 0;
  1784. X    cptr = get_elapsed_time(elapsed_seconds);
  1785. X    wmove(win,9,41);
  1786. X    waddstr(win,cptr);
  1787. X
  1788. X#if defined(FASI)
  1789. X    if(!ioctl(iofd,FASIC_SIP,&now))
  1790. X    {
  1791. X        if((ltmp = now.framing_errors - fip_start.framing_errors) > 999L)
  1792. X            ltmp = 999L;
  1793. X        sprintf(s128,"%-3lu",ltmp);
  1794. X        wmove(win,14,6);
  1795. X        waddstr(win,s128);
  1796. X
  1797. X        if((ltmp = now.overrun_errors - fip_start.overrun_errors) > 999L)
  1798. X            ltmp = 999L;
  1799. X        sprintf(s128,"%-3lu",ltmp);
  1800. X        wmove(win,14,13);
  1801. X        waddstr(win,s128);
  1802. X
  1803. X        ltmp = now.characters_received - fip_start.characters_received;
  1804. X        sprintf(s128,"%-8lu",ltmp);
  1805. X        wmove(win,14,22);
  1806. X        waddstr(win,s128);
  1807. X
  1808. X        ltmp = now.characters_transmitted - fip_start.characters_transmitted;
  1809. X        sprintf(s128,"%-8lu",ltmp);
  1810. X        wmove(win,14,36);
  1811. X        waddstr(win,s128);
  1812. X
  1813. X        wmove(win,14,49);
  1814. X        waddch(win,(now.mcr & MC_SET_RTS) ? 'T' : 'F');
  1815. X
  1816. X        wmove(win,14,55);
  1817. X        waddch(win,(now.msr & MS_CTS_PRESENT) ? 'T' : 'F');
  1818. X
  1819. X        ltmp = now.xmtr_hw_flow_count - fip_start.xmtr_hw_flow_count;
  1820. X        if(ltmp > 9999L)
  1821. X            ltmp = 9999L;
  1822. X        sprintf(s128,"%-4lu",ltmp);
  1823. X        wmove(win,15,17);
  1824. X        waddstr(win,s128);
  1825. X
  1826. X        ltmp = now.xmtr_sw_flow_count - fip_start.xmtr_sw_flow_count;
  1827. X        if(ltmp > 9999L)
  1828. X            ltmp = 9999L;
  1829. X        sprintf(s128,"%-4lu",ltmp);
  1830. X        wmove(win,15,27);
  1831. X        waddstr(win,s128);
  1832. X
  1833. X        ltmp = now.rcvr_hw_flow_count - fip_start.rcvr_hw_flow_count;
  1834. X        if(ltmp > 9999L)
  1835. X            ltmp = 9999L;
  1836. X        sprintf(s128,"%-4lu",ltmp);
  1837. X        wmove(win,15,41);
  1838. X        waddstr(win,s128);
  1839. X
  1840. X        ltmp = now.rcvr_sw_flow_count - fip_start.rcvr_sw_flow_count;
  1841. X        if(ltmp > 9999L)
  1842. X            ltmp = 9999L;
  1843. X        sprintf(s128,"%-4lu",ltmp);
  1844. X        wmove(win,15,51);
  1845. X        waddstr(win,s128);
  1846. X    }
  1847. X#endif    /* FASI */
  1848. X
  1849. X    report_window();
  1850. X
  1851. X    wrefresh(win);        /* calling procs expect this to occur always */
  1852. X
  1853. X}    /* end of report_rx_tx_count */
  1854. X
  1855. X/*+-------------------------------------------------------------------------
  1856. X    report_mode(mode)
  1857. X
  1858. X comm mode row 7 col 52 length 6
  1859. X   3: save old tty stat, set raw mode with flow control
  1860. X   2: set XON/XOFF for sb/sz with ZMODEM or YMODEM-g
  1861. X   1: save old tty stat, set raw mode 
  1862. X   0: restore original tty mode
  1863. X--------------------------------------------------------------------------*/
  1864. Xvoid
  1865. Xreport_mode(mode)
  1866. Xint mode;
  1867. X{
  1868. Xchar *cptr;
  1869. Xchar tmp[8];
  1870. X
  1871. X    if(no_curses)
  1872. X    {
  1873. X        return;
  1874. X    }
  1875. X
  1876. X    clear_area(win,7,52,6);
  1877. X    switch(mode)
  1878. X    {
  1879. X    case 0:
  1880. X        cptr = "NORMAL";
  1881. X        break;
  1882. X    case 1:
  1883. X        cptr = "RAW";
  1884. X        break;
  1885. X    case 2:
  1886. X        cptr = "RAW-g";
  1887. X        break;
  1888. X    case 3:
  1889. X        cptr = "RAW-f";
  1890. X        break;
  1891. X    default:
  1892. X        sprintf(tmp,"%5u",mode);
  1893. X        cptr = tmp;
  1894. X    }
  1895. X    waddstr(win,cptr);
  1896. X    wrefresh(win);
  1897. X    if(log_packets)
  1898. X    {
  1899. X        write(log_packets,"mode: ",6);
  1900. X        write(log_packets,cptr,strlen(cptr));
  1901. X        write(log_packets,"\n",1);
  1902. X    }
  1903. X
  1904. X}    /* end of report_mode */
  1905. X
  1906. X/*+-------------------------------------------------------------------------
  1907. X    report_rxblklen(blklen) 
  1908. Xrow 7 col 35 5 chars
  1909. X--------------------------------------------------------------------------*/
  1910. Xvoid
  1911. Xreport_rxblklen(blklen)
  1912. Xint blklen;
  1913. X{
  1914. X    char tmp[10];
  1915. X
  1916. X    if(no_curses)
  1917. X    {
  1918. X        return;
  1919. X    }
  1920. X
  1921. X    sprintf(tmp,"%-5u",blklen);
  1922. X    clear_area(win,7,35,5);
  1923. X    waddstr(win,tmp);
  1924. X    wrefresh(win);
  1925. X}    /* end of report_rxblklen */
  1926. X
  1927. X/*+-------------------------------------------------------------------------
  1928. X    report_txblklen(blklen) 
  1929. Xrow 7 col 35 5 chars
  1930. X--------------------------------------------------------------------------*/
  1931. Xvoid
  1932. Xreport_txblklen(blklen)
  1933. Xint blklen;
  1934. X{
  1935. X    if(no_curses)
  1936. X    {
  1937. X        return;
  1938. X    }
  1939. X
  1940. X    report_rxblklen(blklen);
  1941. X}    /* end of report_txblklen */
  1942. X
  1943. X/*+-------------------------------------------------------------------------
  1944. X    report_file_xfer_rate(text,count,final)
  1945. X--------------------------------------------------------------------------*/
  1946. Xvoid
  1947. Xreport_file_xfer_rate(text,count,final)
  1948. Xchar *text;
  1949. Xlong count;
  1950. Xint final;
  1951. X{
  1952. X    float rate = 0.0;
  1953. X    float eff = 0.0;
  1954. X    static long last_report = 0L;
  1955. X
  1956. X    s128[0] = 0;
  1957. X
  1958. X    current_seconds = time((long *)0);
  1959. SHAR_EOF
  1960. true || echo 'restore of z/zcurses.c failed'
  1961. fi
  1962. echo 'End of ecu310 part 22'
  1963. echo 'File z/zcurses.c is continued in part 23'
  1964. echo 23 > _shar_seq_.tmp
  1965. exit 0
  1966. --------------------------------------------------------------------
  1967. Warren Tucker, TuckerWare emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
  1968. Hacker Extraordinaire  d' async PADs,  pods,  proteins and protocols
  1969.  
  1970. exit 0 # Just in case...
  1971. -- 
  1972. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1973. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1974. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1975. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1976.