home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume13 / tipx / part04 < prev    next >
Text File  |  1990-05-29  |  58KB  |  2,388 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v13i016: tipx (extended tip) part 04/04
  3. From: wht@gatech.edu@tridom.UUCP (Warren H. Tucker)
  4. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5.  
  6. Posting-number: Volume 13, Issue 16
  7. Submitted-by: wht@gatech.edu@tridom.UUCP (Warren H. Tucker)
  8. Archive-name: tipx/part04
  9.  
  10. #!/bin/sh
  11. # This is part 04 of tipx
  12. if touch 2>&1 | fgrep 'mmdd' > /dev/null
  13.  then TOUCH=touch
  14.  else TOUCH=true
  15. fi
  16. # ============= xfer/zcurses.c ==============
  17. echo "x - extracting xfer/zcurses.c (Text)"
  18. sed 's/^X//' << 'SHAR_EOF' > xfer/zcurses.c &&
  19. X/*+-------------------------------------------------------------------------
  20. X    zcurses.c -- tip file transfer program curses interface
  21. X    wht%n4hgf@emory.mathcs.emory.edu
  22. X
  23. X  000000000011111111112222222222333333333344444444445555555550
  24. X  012345678901234567890123456789012345678901234567890123456789
  25. X00.-[ prog+rev ]-- <dir> ------------------------------------.
  26. X01|  ZMODEM_6____  _40_____________________________________  |
  27. X02|  File ### of ###: _38__________________________________  |
  28. X03|  File position:  _8______ length: _8______  -rwxrwxrwx   |
  29. X04|  _55____________________________________________________ | transaction
  30. X05|  _55____________________________________________________ | last rx/tx hdr
  31. X06|  Comm I/O: rx _8______  tx _8______ bytes                |
  32. X07|  Baud rate: _5___ BINARY blklen: _____ comm mode: RAW-g  |
  33. X08|  Time:    started: __:__:__ this file: __:__:__ window:  |
  34. X09|  __:__:__ elapsed: __:__:__            __:__:__ ________ |
  35. X10|  Errors: this file: _3_ total: _4__ files skipped: _3_   |
  36. X11|  _55____________________________________________________ |  err str
  37. X12|  _55____________________________________________________ |  comment str
  38. X13|  _55____________________________________________________ |  remote info
  39. X14`----------------------------------------------------------'
  40. X
  41. X  Defined functions:
  42. X    clear_area(win,row,col,len)
  43. X    clear_area_char(win,row,col,len,fillchar)
  44. X    get_elapsed_time(elapsed_seconds)
  45. X    get_tod(type,tod)
  46. X    mode_map(mode,mode_str)
  47. X    report_comm_baud_rate(baud_rate)
  48. X    report_error_count()
  49. X    report_file_byte_io(count)
  50. X    report_file_close()
  51. X    report_file_open_length(length)
  52. X    report_file_open_mode(file_mode)
  53. X    report_file_open_tod()
  54. X    report_file_rcv_started(filename,length,last_mod_time,file_mode)
  55. X    report_file_send_open(filename,filestat)
  56. X    report_init(title)
  57. X    report_last_rxhdr(rptstr,error_flag)
  58. X    report_last_txhdr(rptstr,error_flag)
  59. X    report_mode(mode)
  60. X    report_protocol_crc_type(str)
  61. X    report_protocol_type(str)
  62. X    report_rx_ind(status)
  63. X    report_rx_tx_count()
  64. X    report_rxblklen(blklen)
  65. X    report_rxpos(rxpos)
  66. X    report_str(rptstr,error_flag)
  67. X    report_top_line(topstr)
  68. X    report_transaction(str)
  69. X    report_tx_ind(status)
  70. X    report_txblklen(blklen)
  71. X    report_txpos(txpos)
  72. X    report_uninit(sig)
  73. X    report_window()
  74. X    report_xfer_mode(str)
  75. X
  76. X------------------------------------------------------------------------*/
  77. X/*+:EDITS:*/
  78. X/*:05-21-1990-16:00-wht@tridom-adapt ecu xfer protocols for tipwht */
  79. X
  80. X#include <curses.h>
  81. X#include <sys/types.h>
  82. X#include <sys/stat.h>
  83. X#include <ctype.h>
  84. X#include <signal.h>
  85. X#include <time.h>
  86. X#include <sys/timeb.h>
  87. X
  88. X#include "zlint.h"
  89. X
  90. Xlong time();
  91. Xextern char *tzname[];
  92. Xstruct tm *localtime();
  93. X
  94. X#ifdef IBMPC
  95. X#define sTL        0xDA
  96. X#define sTR        0xBF
  97. X#define sBL        0xC0
  98. X#define sBR        0xD9
  99. X#define sLT        0xC3    /* left hand T */
  100. X#define sRT        0xB4    /* right hand T */
  101. X#define sVR        0xB3    /* vertical rule */
  102. X#define sHR        0xC4    /* horizontal rule */
  103. X#else
  104. X#define sTL        '.'
  105. X#define sTR        '.'
  106. X#define sBL        '`'
  107. X#define sBR        '\''
  108. X#define sLT        '+'
  109. X#define sRT        '+'
  110. X#define sVR        '|'
  111. X#define sHR        '-'
  112. X#endif
  113. X
  114. X#define WIN_LINES    15
  115. X#define WIN_COLS    60
  116. X#define WIN_TOPY    2
  117. X#define WIN_LEFTX    8
  118. X
  119. Xextern char curr_dir[];
  120. Xextern char s128[];
  121. Xextern char *bottom_label;
  122. Xextern int Filcnt;
  123. Xextern int tipsz_flag;    /* tipsz == 1, tiprz == 0 */
  124. Xextern int skip_count;
  125. Xextern int npats;
  126. Xextern long rxpos;
  127. Xextern int log_packets;
  128. Xextern long Txpos;
  129. Xextern long Rxpos;
  130. X
  131. XWINDOW    *win;
  132. Xint (*original_sigint_handler)();
  133. Xint (*original_sigquit_handler)();
  134. Xint (*original_sigterm_handler)();
  135. Xint curses_installed = 0;        /* curses not yet active */
  136. Xint this_file_errors;
  137. Xint total_errors;
  138. Xint show_window = 0;
  139. Xlong current_seconds = 0;
  140. Xlong start_seconds = 0;
  141. Xlong this_file_start_seconds = 0;
  142. Xlong elapsed_seconds = 0;
  143. Xunsigned long total_data_chars_xfered = 0L;
  144. Xunsigned int zcurses_baud_rate = 0;
  145. Xchar s256[256];
  146. X
  147. Xchar *win_template[] =
  148. X{
  149. X/*00000000001111111111222222222233333333334444444444555555555 */
  150. X/*01234567890123456789012345678901234567890123456789012345678 */
  151. X/*.----------------------------------------------------------. */
  152. X  "                                                          ",    /* 1 */
  153. X  "  File ### of ###: _____________________________________  ",    /* 2 */
  154. X  "  File position:  ________ length: ________               ",    /* 3 */
  155. X  "                                                          ",    /* 4 */
  156. X  "  tx: ______________________  rx: ______________________  ",    /* 5 */
  157. X  "  Comm I/O: rx ________  tx ________ bytes                ",    /* 6 */
  158. X  "  Baud rate: _____ ______ blklen: _____ comm mode: ______ ",    /* 7 */
  159. X  "  Time:    started: __:__:__ this file: __:__:__          ", /* 8 */
  160. X  "  __:__:__ elapsed: __:__:__            __:__:__          ", /* 9 */
  161. X  "  Errors: this file: ___ total: ____ files skipped: ___   ", /* 10 */
  162. X  "                                                          ",    /* 11 */
  163. X  "                                                          ",    /* 12 */
  164. X  "                                                          ",    /* 13 */
  165. X/*`----------------------------------------------------------' */
  166. X(char *)0
  167. X};
  168. X
  169. X/*+-----------------------------------------------------------------------
  170. X    char *get_elapsed_time(elapsed_seconds)
  171. X    hh:mm:ss returned
  172. X  static string address is returned
  173. X------------------------------------------------------------------------*/
  174. Xchar *get_elapsed_time(elapsed_seconds)
  175. Xlong elapsed_seconds;
  176. X{
  177. X    static char elapsed_time_str[10];
  178. X    long hh,mm,ss;
  179. X
  180. X    hh = elapsed_seconds / 3600;
  181. X    elapsed_seconds -= hh * 3600;
  182. X    mm = elapsed_seconds / 60L;
  183. X    elapsed_seconds -= mm * 60L;
  184. X    ss = elapsed_seconds;
  185. X
  186. X    sprintf(elapsed_time_str,"%02ld:%02ld:%02ld",hh,mm,ss);
  187. X    return(elapsed_time_str);
  188. X}    /* end of get_elapsed_time */
  189. X
  190. X/*+-----------------------------------------------------------------------
  191. X    char *get_tod(type,tod)
  192. X
  193. X  time of day types:
  194. X    0        hh:mm
  195. X    1        hh:mm:ss
  196. X    2        mm-dd-yyyy hh:mm
  197. X
  198. X  static string address is returned
  199. X  if tod != (char *)0, time is returned there too
  200. X------------------------------------------------------------------------*/
  201. Xchar *
  202. Xget_tod(type,tod)
  203. Xint type;
  204. Xchar *tod;
  205. X{
  206. X    long cur_time = 0;
  207. X    struct tm *lt;            /* local time */
  208. X    static char tod_str[32];
  209. X#if defined(M_SYS5)
  210. X    struct timeb tp;
  211. X#endif
  212. X
  213. X    cur_time = time((long *)0);
  214. X    lt = localtime(&cur_time);
  215. X
  216. X    switch(type)
  217. X    {
  218. X    case 0:
  219. X        sprintf(tod_str,"%02d:%02d",lt->tm_hour,lt->tm_min);
  220. X        break;
  221. X
  222. X    default:
  223. X    case 1:
  224. X        sprintf(tod_str,"%02d:%02d:%02d",lt->tm_hour,lt->tm_min,lt->tm_sec);
  225. X        break;
  226. X
  227. X    case 2:
  228. X        sprintf(tod_str,"%02d-%02d-%04d %02d:%02d",
  229. X            lt->tm_mon + 1,lt->tm_mday,lt->tm_year + 1900,
  230. X            lt->tm_hour,lt->tm_min);
  231. X        break;
  232. X    }
  233. X
  234. X    if(tod != (char *)0)
  235. X        strcpy(tod,tod_str);
  236. X
  237. X    return(tod_str);
  238. X}    /* end of get_tod */
  239. X
  240. X/*+-----------------------------------------------------------------------
  241. X    mode_map(mode,mode_str)    build drwxrwxrwx string
  242. X------------------------------------------------------------------------*/
  243. Xchar *
  244. Xmode_map(mode,mode_str)
  245. Xunsigned short mode;
  246. Xchar *mode_str;
  247. X{
  248. Xregister unsigned ftype = mode & S_IFMT;
  249. Xregister char *rtn;
  250. Xstatic char result[12];
  251. X
  252. X    rtn = (mode_str == (char *)0) ? result : mode_str;
  253. X
  254. X    /*               drwxrwxrwx */
  255. X    /*               0123456789 */
  256. X    strcpy(rtn,"----------");
  257. X
  258. X    switch(ftype)
  259. X    {
  260. X        case S_IFIFO:    *rtn = 'p'; break; /* FIFO (named pipe) */
  261. X        case S_IFDIR:    *rtn = 'd'; break; /* directory */
  262. X        case S_IFCHR:    *rtn = 'c'; break; /* character special */
  263. X        case S_IFBLK:    *rtn = 'b'; break; /* block special */
  264. X        case S_IFREG:    *rtn = '-'; break; /* regular */
  265. X
  266. X#if defined(pyr) | defined(BSD4)
  267. X        case S_IFLNK:    *rtn = 'l'; break; /* symbolic link */
  268. X        case S_IFSOCK:    *rtn = 's'; break; /* socket */
  269. X#endif
  270. X
  271. X#if defined(M_SYS5)
  272. X        case S_IFNAM:                        /* name space entry */
  273. X            if(mode & S_INSEM)                /* semaphore */
  274. X            {
  275. X                *rtn = 's';
  276. X                break;
  277. X            }
  278. X            if(mode & S_INSHD)                /* shared memory */
  279. X            {
  280. X                *rtn = 'm';
  281. X                break;
  282. X            }
  283. X#endif
  284. X
  285. X        default:        *rtn = '?'; break;    /* ??? */
  286. X    }
  287. X
  288. X    if(mode & 000400) *(rtn + 1) = 'r';
  289. X    if(mode & 000200) *(rtn + 2) = 'w';
  290. X    if(mode & 000100) *(rtn + 3) = 'x';
  291. X    if(mode & 004000) *(rtn + 3) = 's';
  292. X    if(mode & 000040) *(rtn + 4) = 'r';
  293. X    if(mode & 000020) *(rtn + 5) = 'w';
  294. X    if(mode & 000010) *(rtn + 6) = 'x';
  295. X    if(mode & 002000) *(rtn + 6) = 's';
  296. X    if(mode & 000004) *(rtn + 7) = 'r';
  297. X    if(mode & 000002) *(rtn + 8) = 'w';
  298. X    if(mode & 000001) *(rtn + 9) = 'x';
  299. X    if(mode & 001000) *(rtn + 9) = 't';
  300. X
  301. X    return(rtn);
  302. X
  303. X}    /* end of mode_map */
  304. X
  305. X/*+-------------------------------------------------------------------------
  306. X    clear_area(win,row,col,len)
  307. X--------------------------------------------------------------------------*/
  308. Xclear_area(win,row,col,len)
  309. XWINDOW    *win;
  310. Xint row;
  311. Xint col;
  312. Xint len;
  313. X{
  314. X    wmove(win,row,col);
  315. X    while(len-- > 0)
  316. X        waddch(win,' ');
  317. X    wmove(win,row,col);
  318. X
  319. X}    /* end of clear_area */
  320. X
  321. X/*+-------------------------------------------------------------------------
  322. X    clear_area_char(win,row,col,len,fillchar)
  323. X--------------------------------------------------------------------------*/
  324. Xclear_area_char(win,row,col,len,fillchar)
  325. XWINDOW    *win;
  326. Xint row;
  327. Xint col;
  328. Xint len;
  329. Xchar fillchar;
  330. X{
  331. X    wmove(win,row,col);
  332. X    while(len-- > 0)
  333. X        waddch(win,fillchar);
  334. X    wmove(win,row,col);
  335. X
  336. X}    /* end of clear_area_char */
  337. X
  338. X/*+-------------------------------------------------------------------------
  339. X    report_top_line(topstr)
  340. X   top line: row 1 col 17 length 42
  341. X--------------------------------------------------------------------------*/
  342. Xvoid
  343. Xreport_top_line(topstr)
  344. Xchar *topstr;
  345. X{
  346. Xchar s42[42];
  347. X    clear_area(win,1,17,42);
  348. X    if(strlen(topstr) < 40)
  349. X        waddstr(win,topstr);
  350. X    else
  351. X    {
  352. X        strncpy(s42,topstr,40);
  353. X        s42[40] = 0;
  354. X        waddstr(win,s42);
  355. X    }
  356. X}    /* end of report_top_line */
  357. X
  358. X/*+-------------------------------------------------------------------------
  359. X    report_xfer_mode(modestr)  BINARY/ASCII
  360. X   protocol xfer type: row 7 col 20 length 6
  361. X--------------------------------------------------------------------------*/
  362. Xreport_xfer_mode(str)
  363. Xchar *str;
  364. X{
  365. Xchar s10[10];
  366. X
  367. X    if(strlen(str) > 6)
  368. X    {
  369. X        strncpy(s10,str,6);
  370. X        s10[7] = 0;
  371. X        str = s10;
  372. X    }
  373. X    clear_area(win,7,20,6);
  374. X    waddstr(win,str);
  375. X    wrefresh(win);
  376. X
  377. X}    /* end of report_xfer_mode */
  378. X
  379. X/*+-------------------------------------------------------------------------
  380. X    report_protocol_type(str)
  381. X
  382. X  protocol type:  row 1 col 3 length 6 string
  383. X--------------------------------------------------------------------------*/
  384. Xreport_protocol_type(str)
  385. Xregister char *str;
  386. X{
  387. Xchar s10[10];
  388. X
  389. X    if(strlen(str) > 6)
  390. X    {
  391. X        strncpy(s10,str,6);
  392. X        s10[7] = 0;
  393. X        str = s10;
  394. X    }
  395. X    clear_area(win,1,3,6);
  396. X    waddstr(win,str);
  397. X    wrefresh(win);
  398. X
  399. X}    /* end of report_protocol_type */
  400. X
  401. X/*+-------------------------------------------------------------------------
  402. X    report_protocol_crc_type(str)
  403. X
  404. X  protocol crc type:  row 1 col 9 length 6
  405. X--------------------------------------------------------------------------*/
  406. Xreport_protocol_crc_type(str)
  407. Xregister char *str;
  408. X{
  409. Xchar s8[8];
  410. X
  411. X    if(strlen(str) > 6)
  412. X    {
  413. X        strncpy(s8,str,6);
  414. X        s8[7] = 0;
  415. X        str = s8;
  416. X    }
  417. X    clear_area(win,1,9,6);
  418. X    waddstr(win,str);
  419. X    wrefresh(win);
  420. X
  421. X}    /* end of report_protocol_crc_type */
  422. X
  423. X/*+-------------------------------------------------------------------------
  424. X    report_uninit(sig)
  425. X--------------------------------------------------------------------------*/
  426. Xvoid
  427. Xreport_uninit(sig)
  428. Xint sig;        /* if -1, called by normal code, else kill() value */
  429. X{
  430. X    float rate = 0.0;
  431. X    float eff = 0.0;
  432. X
  433. X    if(curses_installed)
  434. X    {
  435. X        elapsed_seconds = current_seconds - start_seconds;
  436. X        if(elapsed_seconds)
  437. X        {
  438. X            rate = (float)total_data_chars_xfered / (float)elapsed_seconds;
  439. X            if(zcurses_baud_rate)
  440. X                eff  = 100 * (rate / ((float)zcurses_baud_rate / 10.0));
  441. X        }
  442. X        if(rate > 0.01)
  443. X        {
  444. X            sprintf(s128,"Transfer rate ~= %.0f ch/sec (%.0f%%)",
  445. X                rate,(eff > 0.5) ? eff : 0.0);
  446. X            if(log_packets)
  447. X            {
  448. X                write(log_packets,"info: ",6);
  449. X                write(log_packets,s128,strlen(s128));
  450. X                write(log_packets,"\n",1);
  451. X            }
  452. X            report_top_line(s128);
  453. X        }
  454. X        report_file_byte_io(0L);
  455. X        report_rx_tx_count();
  456. X        wmove(win,WIN_LINES - 1,WIN_COLS - 1);
  457. X        wrefresh(win);
  458. X        endwin();
  459. X        fprintf(stderr,"\r\n\r\n\r\n");
  460. X        fflush(stderr);
  461. X        curses_installed = 0;
  462. X    }
  463. X
  464. X}    /* end of report_uninit */
  465. X
  466. X/*+-------------------------------------------------------------------------
  467. X    report_init(title)
  468. X  "top line": row 1 col 11 len 21
  469. X  file quan:  row 2 col 15 len  3
  470. X              row 2 col 12 len  7 clear "of ###"
  471. X  start time: row 8 col 21 len  8
  472. X  "window:"   row 8 col 50 len  7
  473. X--------------------------------------------------------------------------*/
  474. Xvoid
  475. Xreport_init(title)
  476. Xchar *title;
  477. X{
  478. X    register int itmp;
  479. X    register char *cptr;
  480. X    char buf[80];
  481. X
  482. X    if(curses_installed)
  483. X        return;
  484. X
  485. X    initscr();
  486. X    crmode();
  487. X    noecho();
  488. X    nonl();
  489. X    clear();
  490. X    curses_installed = 1;
  491. X    win = newwin(WIN_LINES,WIN_COLS,WIN_TOPY,WIN_LEFTX);
  492. X    box(win,sVR,sHR);
  493. X    wmove(win,0,0); waddch(win,sTL);
  494. X    wmove(win,win->_maxy - 1,0); waddch(win,sBL);
  495. X    wmove(win,win->_maxy - 1,win->_maxx - 1); waddch(win,sBR);
  496. X    wmove(win,0,win->_maxx - 1); waddch(win,sTR);
  497. X    wmove(win,0,2);
  498. X    wstandout(win);
  499. X    waddch(win,'[');
  500. X    waddch(win,' ');
  501. X    waddstr(win,title);
  502. X    waddch(win,' ');
  503. X    waddch(win,']');
  504. X    wstandend(win);
  505. X    waddch(win,sHR);
  506. X    waddch(win,sHR);
  507. X    waddch(win,' ');
  508. X    itmp = WIN_COLS - 2 - 7 - strlen(title);
  509. X    curr_dir[itmp] = 0;
  510. X    waddstr(win,curr_dir);
  511. X    waddch(win,' ');
  512. X    if(bottom_label)
  513. X    {
  514. X        strncpy(buf,bottom_label,WIN_COLS - 6);
  515. X        buf[WIN_COLS - 6] = 0;
  516. X        wmove(win,WIN_LINES - 1,2);
  517. X        waddch(win,' ');
  518. X        waddstr(win,buf);
  519. X        waddch(win,' ');
  520. X    }
  521. X
  522. X    itmp = 0;
  523. X    while(1)
  524. X    {
  525. X        if(win_template[itmp] == (char *)0)
  526. X            break;
  527. X        wmove(win,itmp + 1,1);
  528. X        waddstr(win,win_template[itmp++]);
  529. X    }
  530. X    if(tipsz_flag)
  531. X    {
  532. X        clear_area(win,2,15,3);
  533. X        sprintf(s128,"%3d",npats);
  534. X        waddstr(win,s128);
  535. X    }
  536. X    else    /* tiprz */
  537. X    {
  538. X        clear_area(win,2,11,8);    /* clear "of ###" */
  539. X        waddstr(win,":");
  540. X    }
  541. X
  542. X    clear_area(win,1,11,21);
  543. X    report_error_count();
  544. X    clear_area(win,8,21,8);        /* starting time */
  545. X    waddstr(win,get_tod(1,(char *)0));
  546. X    start_seconds = time((long *)0);
  547. X    current_seconds = start_seconds;
  548. X
  549. X    if(show_window)
  550. X    {
  551. X        wmove(win,8,50);
  552. X        waddstr(win,"window:");
  553. X        wmove(win,9,50);
  554. X        waddstr(win,"+0");
  555. X    }
  556. X
  557. X    wrefresh(win);
  558. X
  559. X}    /* end of report_init */
  560. X
  561. X/*+-------------------------------------------------------------------------
  562. X    report_rx_ind(status)
  563. X--------------------------------------------------------------------------*/
  564. Xvoid
  565. Xreport_rx_ind(status)
  566. Xint status;
  567. X{
  568. X#if defined(M_SYS5)
  569. X    wmove(win,1,54);
  570. X    waddch(win,(status) ? 'R' : ' ');
  571. X    wmove(win,1,54);
  572. X    wrefresh(win);
  573. X#endif
  574. X}    /* end of report_rx_ind */
  575. X
  576. X/*+-------------------------------------------------------------------------
  577. X    report_tx_ind(status)
  578. X--------------------------------------------------------------------------*/
  579. Xvoid
  580. Xreport_tx_ind(status)
  581. Xint status;
  582. X{
  583. X#if defined(M_SYS5)
  584. X    wmove(win,1,56);
  585. X    waddch(win,(status) ? 'T' : ' ');
  586. X    wmove(win,1,56);
  587. X    wrefresh(win);
  588. X#endif
  589. X}    /* end of report_tx_ind */
  590. X
  591. X/*+-------------------------------------------------------------------------
  592. X    report_window() - if enable, show open widow size
  593. X--------------------------------------------------------------------------*/
  594. Xvoid
  595. Xreport_window()
  596. X{
  597. X    if(show_window)
  598. X    {
  599. X    long ltmp;
  600. X        wmove(win,9,50);
  601. X        if((ltmp = (Txpos - Rxpos)) > 999999L)
  602. X            waddstr(win,">+999999");
  603. X        else if(ltmp < -999999L)
  604. X            ;
  605. X        else
  606. X        {
  607. X            sprintf(s128,"%+-8ld",ltmp);
  608. X            waddstr(win,s128);
  609. X            if(log_packets)
  610. X            {
  611. X                write(log_packets,"window: ",8);
  612. X                write(log_packets,s128,strlen(s128));
  613. X                write(log_packets,"\n",1);
  614. X            }
  615. X        }
  616. X    }
  617. X}    /* end of report_window */
  618. X
  619. X/*+-------------------------------------------------------------------------
  620. X    report_rx_tx_count()
  621. X
  622. X  This procedure may be counted upon to perform wrefresh(win)
  623. X
  624. X  rx char count:          row 6 col 16 len 8 unsigned long
  625. X  tx char count:          row 6 col 29 len 8 unsigned long
  626. X  session elapsed time:   row 9 col 21 len 8
  627. X  this file elapsed time: row 9 col 41 len 8
  628. X  current tod:            row 9 col  3 len 8
  629. X  window:                 row 9 col 50 len 8
  630. X--------------------------------------------------------------------------*/
  631. Xreport_rx_tx_count()
  632. X{
  633. X    extern unsigned long rx_char_count;
  634. X    extern unsigned long tx_char_count;
  635. X
  636. X    register char *cptr;
  637. X
  638. X    sprintf(s128,"%8ld",rx_char_count);
  639. X    wmove(win,6,16);
  640. X    waddstr(win,s128);
  641. X    sprintf(s128,"%8ld",tx_char_count);
  642. X    wmove(win,6,29);
  643. X    waddstr(win,s128);
  644. X
  645. X    /* now time of day */
  646. X    wmove(win,9,3);
  647. X    cptr = get_tod(1,(char *)0);
  648. X    waddstr(win,cptr);
  649. X    current_seconds = time((long *)0);
  650. X    elapsed_seconds = current_seconds - start_seconds;
  651. X    cptr = get_elapsed_time(elapsed_seconds);
  652. X    wmove(win,9,21);
  653. X    waddstr(win,cptr);
  654. X    if(this_file_start_seconds)
  655. X        elapsed_seconds = current_seconds - this_file_start_seconds;
  656. X    else
  657. X        elapsed_seconds = 0;
  658. X    cptr = get_elapsed_time(elapsed_seconds);
  659. X    wmove(win,9,41);
  660. X    waddstr(win,cptr);
  661. X
  662. X    report_window();
  663. X
  664. X    wrefresh(win);        /* calling procs expect this to occur always */
  665. X
  666. X}    /* end of report_rx_tx_count */
  667. X
  668. X/*+-------------------------------------------------------------------------
  669. X    report_mode(mode)
  670. X
  671. X comm mode row 7 col 52 length 6
  672. X   3: save old tty stat, set raw mode with flow control
  673. X   2: set XON/XOFF for sb/sz with ZMODEM or YMODEM-g
  674. X   1: save old tty stat, set raw mode 
  675. X   0: restore original tty mode
  676. X--------------------------------------------------------------------------*/
  677. Xvoid
  678. Xreport_mode(mode)
  679. Xint mode;
  680. X{
  681. Xchar *cptr;
  682. Xchar tmp[8];
  683. X
  684. X    clear_area(win,7,52,6);
  685. X    switch(mode)
  686. X    {
  687. X    case 0:
  688. X        cptr = "NORMAL";
  689. X        break;
  690. X    case 1:
  691. X        cptr = "RAW";
  692. X        break;
  693. X    case 2:
  694. X        cptr = "RAW-g";
  695. X        break;
  696. X    case 3:
  697. X        cptr = "RAW-f";
  698. X        break;
  699. X    default:
  700. X        sprintf(tmp,"%5u",mode);
  701. X        cptr = tmp;
  702. X    }
  703. X    waddstr(win,cptr);
  704. X    wrefresh(win);
  705. X    if(log_packets)
  706. X    {
  707. X        write(log_packets,"mode: ",6);
  708. X        write(log_packets,cptr,strlen(cptr));
  709. X        write(log_packets,"\n",1);
  710. X    }
  711. X
  712. X}    /* end of report_mode */
  713. X
  714. X/*+-------------------------------------------------------------------------
  715. X    report_rxblklen(blklen) 
  716. Xrow 7 col 35 5 chars
  717. X--------------------------------------------------------------------------*/
  718. Xvoid
  719. Xreport_rxblklen(blklen)
  720. Xint blklen;
  721. X{
  722. X    char tmp[10];
  723. X
  724. X    sprintf(tmp,"%5u",blklen);
  725. X    clear_area(win,7,35,5);
  726. X    waddstr(win,tmp);
  727. X    wrefresh(win);
  728. X}    /* end of report_rxblklen */
  729. X
  730. X/*+-------------------------------------------------------------------------
  731. X    report_txblklen(blklen) 
  732. Xrow 7 col 35 5 chars
  733. X--------------------------------------------------------------------------*/
  734. Xvoid
  735. Xreport_txblklen(blklen)
  736. Xint blklen;
  737. X{
  738. X    report_rxblklen(blklen);
  739. X}    /* end of report_txblklen */
  740. X
  741. X/*+-------------------------------------------------------------------------
  742. X    report_rxpos(rxpos) row 3 col 19 len 8
  743. X--------------------------------------------------------------------------*/
  744. Xvoid
  745. Xreport_rxpos(rxpos)
  746. Xlong rxpos;
  747. X{
  748. Xint i;
  749. Xchar tmp[16];
  750. Xchar rdchar;
  751. X    if(
  752. X#if defined(M_SYS5)
  753. X        rdchk(0)
  754. X#else
  755. X        !ioctl(0,FIONREAD,&i) && i
  756. X#endif
  757. X            )
  758. X    {
  759. X        read(0,&rdchar,1);
  760. X        rdchar &= 0x7f;
  761. X        if(rdchar == 0x0C || rdchar == 0x012)    /* ^L or ^R */
  762. X        {
  763. X            touchwin(stdscr);
  764. X            wrefresh(stdscr);
  765. X            touchwin(win);
  766. X            wrefresh(win);
  767. X        }
  768. X    }
  769. X
  770. X    if((rxpos > 99999999L) || (rxpos < 0L))
  771. X        return;
  772. X
  773. X    sprintf(tmp,"%8lu",rxpos);
  774. X    wmove(win,3,19);
  775. X    waddstr(win,tmp);
  776. X    wrefresh(win);
  777. X    report_rx_tx_count();    /* which will do a refresh */
  778. X}    /* end of report_rxpos */
  779. X
  780. X/*+-------------------------------------------------------------------------
  781. X    report_txpos(txpos)
  782. X--------------------------------------------------------------------------*/
  783. Xvoid
  784. Xreport_txpos(txpos)
  785. Xlong txpos;
  786. X{
  787. X    report_rxpos(txpos);
  788. X}    /* end of report_txpos */
  789. X
  790. X/*+-------------------------------------------------------------------------
  791. X    report_error_count()
  792. X    DOES NOT PERFORM A REFRESH CYCLE
  793. X
  794. X  this file: row 10 col 22 len 3
  795. X  total:     row 10 col 33 len 4
  796. X  skipped:   row 10 col 53 len 3
  797. X--------------------------------------------------------------------------*/
  798. Xreport_error_count()
  799. X{
  800. X    char tmp[16];
  801. X
  802. X    wmove(win,10,22);
  803. X    sprintf(tmp,"%3d",this_file_errors);
  804. X    if(this_file_errors)
  805. X        wstandout(win);
  806. X    waddstr(win,tmp);
  807. X    if(this_file_errors)
  808. X        wstandend(win);
  809. X
  810. X    wmove(win,10,33);
  811. X    sprintf(tmp,"%4d",total_errors);
  812. X    if(total_errors)
  813. X        wstandout(win);
  814. X    waddstr(win,tmp);
  815. X    if(total_errors)
  816. X        wstandend(win);
  817. X
  818. X    wmove(win,10,53);
  819. X    sprintf(tmp,"%3d",skip_count);
  820. X    waddstr(win,tmp);
  821. X    wrefresh(win);
  822. X
  823. X}    /* end of report_error_count */
  824. X
  825. X/*+-------------------------------------------------------------------------
  826. X    report_last_txhdr(rptstr,error_flag)
  827. X    5,7,22
  828. X--------------------------------------------------------------------------*/
  829. Xvoid
  830. Xreport_last_txhdr(rptstr,error_flag)
  831. Xregister char *rptstr;
  832. Xint error_flag;
  833. X{
  834. Xchar s24[24];
  835. X
  836. X    if(log_packets)
  837. X    {
  838. X        write(log_packets,"tx:   ",6);
  839. X        write(log_packets,rptstr,strlen(rptstr));
  840. X        write(log_packets,"\n",1);
  841. X    }
  842. X
  843. X    if(strlen(rptstr) > 22)
  844. X    {
  845. X        strncpy(s24,rptstr,22);
  846. X        s24[23] = 0;
  847. X        rptstr = s24;
  848. X    }
  849. X    clear_area(win,5,7,22);
  850. X    waddstr(win,rptstr);
  851. X
  852. X    if(error_flag)
  853. X    {
  854. X        ++this_file_errors;
  855. X        ++total_errors;
  856. X        report_error_count();
  857. X    }
  858. X
  859. X}    /* end of report_last_txhdr */
  860. X
  861. X/*+-------------------------------------------------------------------------
  862. X    report_last_rxhdr(rptstr,error_flag)
  863. X    5,35,22
  864. X--------------------------------------------------------------------------*/
  865. Xvoid
  866. Xreport_last_rxhdr(rptstr,error_flag)
  867. Xregister char *rptstr;
  868. Xint error_flag;
  869. X{
  870. Xchar s24[24];
  871. Xextern int log_packets;
  872. X
  873. X    if(log_packets)
  874. X    {
  875. X        write(log_packets,"rx:   ",6);
  876. X        write(log_packets,rptstr,strlen(rptstr));
  877. X        write(log_packets,"\n",1);
  878. X    }
  879. X
  880. X    if(strlen(rptstr) > 22)
  881. X    {
  882. X        strncpy(s24,rptstr,22);
  883. X        s24[23] = 0;
  884. X        rptstr = s24;
  885. X    }
  886. X    clear_area(win,5,35,22);
  887. X    waddstr(win,rptstr);
  888. X
  889. X    if(error_flag)
  890. X    {
  891. X        ++this_file_errors;
  892. X        ++total_errors;
  893. X        report_error_count();
  894. X    }
  895. X    report_window();
  896. X
  897. X}    /* end of report_last_rxhdr */
  898. X
  899. X/*+-------------------------------------------------------------------------
  900. X    report_str(rptstr,error_flag) row 11/12 col 3 len 55
  901. X
  902. X  error_flag == 0 for status/progress message
  903. X             == 1 for bump error count, unless rptstr is null
  904. X                  in which case, merely clear error string area
  905. X             == 2 write string on bottom line (not an error)
  906. X             == 3 write string on transaction line (not an error)
  907. X             == -1 use error line but do not bump error count
  908. X--------------------------------------------------------------------------*/
  909. Xvoid
  910. Xreport_str(rptstr,error_flag)
  911. Xregister char *rptstr;
  912. Xint error_flag;
  913. X{
  914. Xchar s60[60];
  915. Xextern int log_packets;
  916. X
  917. X    if(strlen(rptstr) > 55)
  918. X    {
  919. X        strncpy(s60,rptstr,55);
  920. X        s60[55] = 0;
  921. X        rptstr = s60;
  922. X    }
  923. X
  924. X    switch(error_flag)
  925. X    {
  926. X        case 0:
  927. X            clear_area(win,12,3,55);
  928. X            break;
  929. X        case 1:
  930. X            ++this_file_errors;
  931. X            ++total_errors;
  932. X            report_error_count();
  933. X        case -1:
  934. X            clear_area(win,11,3,55);
  935. X            break;
  936. X        case 2:
  937. X            clear_area(win,13,3,55);
  938. X            break;
  939. X        case 3:
  940. X            clear_area(win,4,3,55);
  941. X            break;
  942. X    }
  943. X
  944. X    waddstr(win,rptstr);
  945. X    wrefresh(win);
  946. X
  947. X    if(log_packets)
  948. X    {
  949. X        write(log_packets,"info: ",6);
  950. X        write(log_packets,rptstr,strlen(rptstr));
  951. X        write(log_packets,"\n",1);
  952. X    }
  953. X
  954. X}    /* end of report_str */
  955. X
  956. X/*+-------------------------------------------------------------------------
  957. X    report_transaction()
  958. X--------------------------------------------------------------------------*/
  959. Xvoid
  960. Xreport_transaction(str)
  961. Xchar *str;
  962. X{
  963. X    report_str(str,3);
  964. X}    /* end of report_transaction */
  965. X
  966. X/*+-------------------------------------------------------------------------
  967. X    report_file_open_tod() -- time of start of this file
  968. X
  969. X  this file open time: row 8 col 41 length 8
  970. X--------------------------------------------------------------------------*/
  971. Xvoid
  972. Xreport_file_open_tod()
  973. X{
  974. X    clear_area(win,8,41,8);
  975. X    this_file_start_seconds = time((long *)0);
  976. X    waddstr(win,get_tod(1,(char *)0));
  977. X    wrefresh(win);
  978. X}    /* end of report_file_open_tod */
  979. X
  980. X/*+-------------------------------------------------------------------------
  981. X    report_file_open_mode(file_mode)
  982. X  mode map: row 4 col 46 len 10
  983. X--------------------------------------------------------------------------*/
  984. Xreport_file_open_mode(file_mode)
  985. Xunsigned short file_mode;
  986. X{
  987. X    clear_area(win,3,46,10);
  988. X    waddstr(win,mode_map(file_mode,(char *)0));
  989. X    wrefresh(win);
  990. X}    /* end of report_file_open_mode */
  991. X
  992. X/*+-------------------------------------------------------------------------
  993. X    report_file_open_length(long_length)
  994. X  length:   row 3 col 36 len  8
  995. X--------------------------------------------------------------------------*/
  996. Xreport_file_open_length(length)
  997. Xlong length;
  998. X{
  999. X    clear_area(win,3,36,8);
  1000. X    if(length <= 0)
  1001. X        waddstr(win,"unknown");
  1002. X    else
  1003. X    {
  1004. X        sprintf(s128,"%8lu",length);
  1005. X        waddstr(win,s128);
  1006. X    }
  1007. X    wrefresh(win);
  1008. X}    /* end of report_file_open_length */
  1009. X
  1010. X/*+-------------------------------------------------------------------------
  1011. X    report_file_send_open(filename,filestat)
  1012. X
  1013. X  filename: row 2 col 20 len 38
  1014. X  number:   row 2 col 8 len 3
  1015. X  length:   row 3 col 36 len  8
  1016. X  mode:     row 3 col 46 len 10
  1017. X  time of start of this file: row 4 col 47 length 8 hh:mm:ss
  1018. X--------------------------------------------------------------------------*/
  1019. Xvoid
  1020. Xreport_file_send_open(filename,filestat)
  1021. Xchar *filename;
  1022. Xstruct stat *filestat;
  1023. X{
  1024. Xchar s50[50];
  1025. Xregister char *cptr = filename;
  1026. X
  1027. X    if(log_packets)
  1028. X    {
  1029. X        write(log_packets,"file: ",6);
  1030. X        write(log_packets,filename,strlen(filename));
  1031. X        write(log_packets,"\n",1);
  1032. X    }
  1033. X
  1034. X    /* number */
  1035. X    clear_area(win,2,8,3);
  1036. X    sprintf(s50,"%3d",Filcnt);
  1037. X    waddstr(win,s50);
  1038. X
  1039. X    /* filename */
  1040. X    if(strlen(filename) > 38)
  1041. X    {
  1042. X        strncpy(s50,filename,38);
  1043. X        s50[39] = 0;
  1044. X        cptr = s50;
  1045. X    }
  1046. X    clear_area(win,2,20,38);
  1047. X    waddstr(win,cptr);
  1048. X
  1049. X    /* length */
  1050. X    report_file_open_length(filestat->st_size);
  1051. X
  1052. X    /* mode */
  1053. X    report_file_open_mode(filestat->st_mode);
  1054. X
  1055. X    /* time of start of this file */
  1056. X    report_file_open_tod();
  1057. X
  1058. X    this_file_errors = 0;
  1059. X    report_error_count();
  1060. X}    /* end of report_file_send_open */
  1061. X
  1062. X/*+-------------------------------------------------------------------------
  1063. X    report_file_rcv_started(filename,length,last_mod_time,file_mode)
  1064. X
  1065. X  filenumber: row 2 col  8 len  3
  1066. X              row 2 col 12 len  7 clear "of ###"
  1067. X  filename:   row 2 col 20 len 38
  1068. X--------------------------------------------------------------------------*/
  1069. Xreport_file_rcv_started(filename,length,last_mod_time,file_mode)
  1070. Xchar *filename;
  1071. Xlong length;                    /* if < 0, "UNKNOWN" */
  1072. Xlong last_mod_time;            /* not currently displayed */
  1073. Xunsigned short file_mode;        /* UNIX file modifier or zero */
  1074. X{
  1075. Xregister char *cptr;
  1076. Xchar s50[50];
  1077. X
  1078. X    if(log_packets)
  1079. X    {
  1080. X        write(log_packets,"file: ",6);
  1081. X        write(log_packets,filename,strlen(filename));
  1082. X        write(log_packets,"\n",1);
  1083. X    }
  1084. X
  1085. X    /* filename */
  1086. X    if(strlen(filename) > 38)
  1087. X    {
  1088. X        strncpy(s50,filename,38);
  1089. X        s50[39] = 0;
  1090. X        cptr = s50;
  1091. X    }
  1092. X    else
  1093. X        cptr = filename;
  1094. X
  1095. X    clear_area(win,2,20,38);
  1096. X    waddstr(win,cptr);
  1097. X
  1098. X    /* file number */
  1099. X    clear_area(win,2,8,3);
  1100. X    sprintf(s50,"%3d",Filcnt);    /* rz uses as file number 1-n */
  1101. X    waddstr(win,s50);
  1102. X
  1103. X/* if remote sender provides a file count, display it */
  1104. X    if(npats)
  1105. X    {
  1106. X        clear_area(win,2,12,7);    /* clear "of ###" */
  1107. X        sprintf(s50,"of %3d:",npats);
  1108. X        waddstr(win,s50);
  1109. X    }
  1110. X
  1111. X    /* length */
  1112. X    report_file_open_length(length);
  1113. X
  1114. X    /* mode */
  1115. X    report_file_open_mode(file_mode);
  1116. X
  1117. X    /* time of start of this file */
  1118. X    report_file_open_tod();
  1119. X
  1120. X    this_file_errors = 0;
  1121. X    report_error_count();
  1122. X}    /* end of report_file_rcv_started */
  1123. X
  1124. X/*+-------------------------------------------------------------------------
  1125. X    report_file_close()
  1126. X--------------------------------------------------------------------------*/
  1127. Xvoid report_file_close()
  1128. X{
  1129. X    if(show_window)
  1130. X    {
  1131. X        clear_area(win,9,50,8);
  1132. X        waddstr(win,"+0");
  1133. X        Txpos = 0;
  1134. X        Rxpos = 0;
  1135. X    }
  1136. X
  1137. X    report_str("End of file",0);
  1138. X    wrefresh(win);
  1139. X    this_file_start_seconds = 0;
  1140. X
  1141. X}    /* end of report_file_close */
  1142. X
  1143. X/*+-------------------------------------------------------------------------
  1144. X    report_comm_baud_rate(baud_rate)
  1145. X
  1146. X baud rate: row 7 col 14 length 5
  1147. X--------------------------------------------------------------------------*/
  1148. Xreport_comm_baud_rate(baud_rate)
  1149. Xunsigned int baud_rate;
  1150. X{
  1151. X    char tstr8[8];
  1152. X
  1153. X    zcurses_baud_rate = baud_rate;
  1154. X    clear_area(win,7,14,5);
  1155. X    if(baud_rate == 0)
  1156. X        waddstr(win,"?");
  1157. X    else
  1158. X
  1159. X    {
  1160. X        sprintf(tstr8,"%5u",baud_rate);
  1161. X        waddstr(win,tstr8);
  1162. X    }
  1163. X    wrefresh(win);
  1164. X
  1165. X}    /* end of report_comm_baud_rate */
  1166. X
  1167. X/*+-------------------------------------------------------------------------
  1168. X    report_file_byte_io(count)
  1169. X--------------------------------------------------------------------------*/
  1170. Xreport_file_byte_io(count)
  1171. Xlong count;
  1172. X{
  1173. X
  1174. X    total_data_chars_xfered += (long)count;
  1175. X    if(total_data_chars_xfered)
  1176. X    {
  1177. X        sprintf(s128,"Total file bytes transferred: %lu",
  1178. X            total_data_chars_xfered);
  1179. X        report_str(s128,-1);
  1180. X    }
  1181. X
  1182. X}    /* end of report_file_byte_io */
  1183. X
  1184. X/* end of zcurses.c */
  1185. X/* vi: set tabstop=4 shiftwidth=4: */
  1186. SHAR_EOF
  1187. $TOUCH -am 0521190890 xfer/zcurses.c &&
  1188. chmod 0644 xfer/zcurses.c ||
  1189. echo "restore of xfer/zcurses.c failed"
  1190. set `wc -c xfer/zcurses.c`;Wc_c=$1
  1191. if test "$Wc_c" != "28447"; then
  1192.     echo original size 28447, current size $Wc_c
  1193. fi
  1194. # ============= xfer/zdebug.c ==============
  1195. echo "x - extracting xfer/zdebug.c (Text)"
  1196. sed 's/^X//' << 'SHAR_EOF' > xfer/zdebug.c &&
  1197. X/* see zcurses.c report_lasthdr() */
  1198. X/*+:EDITS:*/
  1199. X/*:05-21-1990-16:00-wht@tridom-adapt ecu xfer protocols for tipwht */
  1200. Xint header_debug = 0;
  1201. X/* vi: set tabstop=4 shiftwidth=4: */
  1202. SHAR_EOF
  1203. $TOUCH -am 0521180090 xfer/zdebug.c &&
  1204. chmod 0644 xfer/zdebug.c ||
  1205. echo "restore of xfer/zdebug.c failed"
  1206. set `wc -c xfer/zdebug.c`;Wc_c=$1
  1207. if test "$Wc_c" != "180"; then
  1208.     echo original size 180, current size $Wc_c
  1209. fi
  1210. # ============= xfer/zlint.h ==============
  1211. echo "x - extracting xfer/zlint.h (Text)"
  1212. sed 's/^X//' << 'SHAR_EOF' > xfer/zlint.h &&
  1213. X/*+-----------------------------------------------------------------------
  1214. X    zlint.h
  1215. X------------------------------------------------------------------------*/
  1216. X/*+:EDITS:*/
  1217. X/*:05-21-1990-16:00-wht@tridom-adapt ecu xfer protocols for tipwht */
  1218. X
  1219. X/* zcommon.c */
  1220. Xstatic  unsigned int getspeed();
  1221. Xvoid get_curr_dir();
  1222. X/* zcurses.c */
  1223. Xchar *get_elapsed_time();
  1224. Xchar *get_tod();
  1225. Xchar *mode_map();
  1226. Xvoid report_file_close();
  1227. Xvoid report_file_open_tod();
  1228. Xvoid report_file_send_open();
  1229. Xvoid report_init();
  1230. Xvoid report_last_rxhdr();
  1231. Xvoid report_last_txhdr();
  1232. Xvoid report_mode();
  1233. Xvoid report_rx_ind();
  1234. Xvoid report_rxblklen();
  1235. Xvoid report_rxpos();
  1236. Xvoid report_str();
  1237. Xvoid report_top_line();
  1238. Xvoid report_transaction();
  1239. Xvoid report_tx_ind();
  1240. Xvoid report_txblklen();
  1241. Xvoid report_txpos();
  1242. Xvoid report_uninit();
  1243. Xvoid report_window();
  1244. X/* zdebug.c */
  1245. X/* zmodem.c */
  1246. Xlong rclhdr();
  1247. X
  1248. X/* vi: set ts=4 sw=4: */
  1249. X/* end of zlint.h */
  1250. SHAR_EOF
  1251. $TOUCH -am 0521180190 xfer/zlint.h &&
  1252. chmod 0644 xfer/zlint.h ||
  1253. echo "restore of xfer/zlint.h failed"
  1254. set `wc -c xfer/zlint.h`;Wc_c=$1
  1255. if test "$Wc_c" != "907"; then
  1256.     echo original size 907, current size $Wc_c
  1257. fi
  1258. # ============= xfer/zmodem.c ==============
  1259. echo "x - extracting xfer/zmodem.c (Text)"
  1260. sed 's/^X//' << 'SHAR_EOF' > xfer/zmodem.c &&
  1261. X/*+-------------------------------------------------------------------------
  1262. X    zmodem.c - ZMODEM protocol primitives
  1263. X    based on code by Chuck Forsberg
  1264. X    tip adaptation by wht%n4hgf@emory.mathcs.emory.edu
  1265. X
  1266. X  Entry point Functions:
  1267. X    zsbhdr(type,hdr) send binary header
  1268. X    zshhdr(type,hdr) send hex header
  1269. X    zgethdr(hdr,eflag) receive header - binary or hex
  1270. X    zsdata(buf,len,frameend) send data
  1271. X    zrdata(buf,len) receive data
  1272. X    stohdr(pos) store position data in Txhdr
  1273. X    long rclhdr(hdr) recover position offset from header
  1274. X
  1275. X  Defined functions:
  1276. X    noxrd7()
  1277. X    rclhdr(hdr)
  1278. X    stohdr(pos)
  1279. X    zdlread()
  1280. X    zgeth1()
  1281. X    zgethdr(hdr,eflag)
  1282. X    zgethex()
  1283. X    zputhex(c)
  1284. X    zrbhdr(hdr)
  1285. X    zrbhdr32(hdr)
  1286. X    zrdat32(buf,length)
  1287. X    zrdata(buf,length)
  1288. X    zrhhdr(hdr)
  1289. X    zsbh32(hdr,type)
  1290. X    zsbhdr(type,hdr)
  1291. X    zsda32(buf,length,frameend)
  1292. X    zsdata(buf,length,frameend)
  1293. X    zsendline(c)
  1294. X    zshhdr(type,hdr)
  1295. X
  1296. X--------------------------------------------------------------------------*/
  1297. X/*+:EDITS:*/
  1298. X/*:05-21-1990-16:00-wht@tridom-adapt ecu xfer protocols for tipwht */
  1299. X
  1300. X#include "zmodem.h"            /* wht */
  1301. X#include "zlint.h"
  1302. X
  1303. Xextern char s128[];                /* wht */
  1304. Xextern int Zctlesc;                /* wht */
  1305. Xextern int Zmodem;                /* wht */
  1306. Xextern long cr3tab[];            /* wht */
  1307. Xextern unsigned Baudrate;        /* wht */
  1308. Xextern unsigned short crctab[];    /* wht */
  1309. X
  1310. Xint Rxtimeout = 100;        /* Tenths of seconds to wait for something */
  1311. X
  1312. X#if !defined(UNSL)
  1313. X#define UNSL
  1314. X#endif
  1315. X
  1316. X
  1317. X
  1318. Xstatic lastsent;    /* Last char we sent */
  1319. Xstatic evenp;        /* Even parity seen on header */
  1320. X
  1321. X/* Globals used by ZMODEM functions */
  1322. Xchar Attn[ZATTNLEN+1];    /* Attention string rx sends to tx on err */
  1323. Xchar Rxhdr[4];        /* Received header */
  1324. Xchar Txhdr[4];        /* Transmitted header */
  1325. Xint Crc32;        /* Display flag indicating 32 bit CRC being received */
  1326. Xint Crc32t;        /* Display flag indicating 32 bit CRC being sent */
  1327. Xint Rxcount;        /* Count of data bytes received */
  1328. Xint Rxframeind;        /* ZBIN ZBIN32,or ZHEX type of frame received */
  1329. Xint Rxtimeout;    /* Tenths of seconds to wait for something */
  1330. Xint Rxtype;        /* Type of header received */
  1331. Xint Txfcs32;        /* TURE means send binary frames with 32 bit FCS */
  1332. Xint Zrwindow;    /* RX window size (controls garbage count) */
  1333. Xlong Rxpos;    /* Received file position */
  1334. Xlong Txpos;    /* Transmitted file position */
  1335. X
  1336. Xchar *frametypes[] = 
  1337. X{
  1338. X    "Carrier Lost",        /* -3 */
  1339. X    "TIMEOUT",            /* -2 */
  1340. X    "ERROR",            /* -1 */
  1341. X/* #define FTOFFSET 3 moved to zmodem.h */
  1342. X    "ZRQINIT",
  1343. X    "ZRINIT",
  1344. X    "ZSINIT",
  1345. X    "ZACK ",
  1346. X    "ZFILE",
  1347. X    "ZSKIP",
  1348. X    "ZNAK ",
  1349. X    "ZABORT",
  1350. X    "ZFIN ",
  1351. X    "ZRPOS",
  1352. X    "ZDATA",
  1353. X    "ZEOF ",
  1354. X    "ZFERR",
  1355. X    "ZCRC ",
  1356. X    "ZCHALLENGE",
  1357. X    "ZCOMPL",
  1358. X    "ZCAN ",
  1359. X    "ZFREECNT",
  1360. X    "ZCOMMAND",
  1361. X    "ZSTDERR",
  1362. X    "xxxxx"
  1363. X#define FRTYPES 22    /* Total number of frame types in this array */
  1364. X    /*  not including psuedo negative entries */
  1365. X};
  1366. X
  1367. Xstatic char masked[] = "8 bit transparent path required";
  1368. Xstatic char badcrc[] = "Bad CRC";
  1369. X
  1370. X/* Send ZMODEM binary header hdr of type type */
  1371. Xzsbhdr(type,hdr)
  1372. Xregister unsigned char *hdr;
  1373. X{
  1374. X    register int n;
  1375. X    register unsigned crc;
  1376. X
  1377. X    report_tx_ind(1);
  1378. X    sprintf(s128,"hdr %s %ld",frametypes[type+FTOFFSET],rclhdr(hdr));
  1379. X    report_last_txhdr(s128,0);
  1380. X
  1381. X    xsendline(ZPAD); 
  1382. X    xsendline(ZDLE);
  1383. X
  1384. X    if(Crc32t=Txfcs32)
  1385. X        zsbh32(hdr,type);
  1386. X    else 
  1387. X    {
  1388. X        xsendline(ZBIN); 
  1389. X        zsendline(type); 
  1390. X        crc = updcrc(type,0);
  1391. X
  1392. X        for(n=4; --n >= 0; ++hdr)
  1393. X        {
  1394. X            zsendline(*hdr);
  1395. X            crc = updcrc(*hdr,crc);
  1396. X        }
  1397. X        crc = updcrc(0,updcrc(0,crc));
  1398. X        zsendline(crc>>8);
  1399. X        zsendline(crc);
  1400. X    }
  1401. X    if(type != ZDATA)
  1402. X        flushline();
  1403. X    report_tx_ind(0);
  1404. X}
  1405. X
  1406. X
  1407. X/* Send ZMODEM binary header hdr of type type */
  1408. Xzsbh32(hdr,type)
  1409. Xregister char *hdr;
  1410. X{
  1411. X    register int n;
  1412. X    register UNSL long crc;
  1413. X
  1414. X    report_tx_ind(1);
  1415. X    xsendline(ZBIN32);  
  1416. X    zsendline(type);
  1417. X    crc = 0xFFFFFFFFL; 
  1418. X    crc = UPDC32(type,crc);
  1419. X
  1420. X    for(n=4; --n >= 0; ++hdr)
  1421. X    {
  1422. X        crc = UPDC32((0377 & *hdr),crc);
  1423. X        zsendline(*hdr);
  1424. X    }
  1425. X    crc = ~crc;
  1426. X    for(n=4; --n >= 0;)
  1427. X    {
  1428. X        zsendline((int)crc);
  1429. X        crc >>= 8;
  1430. X    }
  1431. X    report_tx_ind(0);
  1432. X}
  1433. X
  1434. X/* Send ZMODEM HEX header hdr of type type */
  1435. Xzshhdr(type,hdr)
  1436. Xregister unsigned char *hdr;
  1437. X{
  1438. X    register int n;
  1439. X    register unsigned short crc;
  1440. X
  1441. X    report_tx_ind(1);
  1442. X
  1443. X    sprintf(s128,"hdr %s %ld",frametypes[type+FTOFFSET],rclhdr(hdr));
  1444. X    report_last_txhdr(s128,0);
  1445. X    sendline(ZPAD); 
  1446. X    sendline(ZPAD); 
  1447. X    sendline(ZDLE); 
  1448. X    sendline(ZHEX);
  1449. X    zputhex(type);
  1450. X    Crc32t = 0;
  1451. X
  1452. X    crc = updcrc(type,0);
  1453. X    for(n=4; --n >= 0; ++hdr)
  1454. X    {
  1455. X        zputhex(*hdr); 
  1456. X        crc = updcrc(*hdr,crc);
  1457. X/*        crc = updcrc((0377 & *hdr),crc);  original - wht */
  1458. X    }
  1459. X    crc = updcrc(0,updcrc(0,crc));
  1460. X    zputhex(crc>>8); 
  1461. X    zputhex(crc);
  1462. X
  1463. X    /* Make it printable on remote machine */
  1464. X    sendline(015); 
  1465. X    sendline(012);
  1466. X    /*
  1467. X     * Uncork the remote in case a fake XOFF has stopped data flow
  1468. X     */
  1469. X    if(type != ZFIN && type != ZACK)
  1470. X        sendline(021);
  1471. X    flushline();
  1472. X    report_tx_ind(0);
  1473. X}
  1474. X
  1475. X/*
  1476. X * Send binary array buf of length length,with ending ZDLE sequence frameend
  1477. X */
  1478. Xstatic char *Zendnames[] = { "ZCRCE","ZCRCG","ZCRCQ","ZCRCW"};
  1479. X
  1480. Xzsdata(buf,length,frameend)
  1481. Xregister unsigned char *buf;
  1482. X{
  1483. X    register unsigned short crc;
  1484. X
  1485. X    report_tx_ind(1);
  1486. X
  1487. X    sprintf(s128,"data %s %d bytes",Zendnames[frameend-ZCRCE&3],length);
  1488. X    report_last_txhdr(s128,0);
  1489. X    if(Crc32t)
  1490. X        zsda32(buf,length,frameend);
  1491. X    else 
  1492. X    {
  1493. X        crc = 0;
  1494. X        for(;--length >= 0; ++buf)
  1495. X        {
  1496. X            zsendline(*buf); 
  1497. X            crc = updcrc(*buf,crc);
  1498. X        }
  1499. X        xsendline(ZDLE); 
  1500. X        xsendline(frameend);
  1501. X        crc = updcrc(frameend,crc);
  1502. X
  1503. X        crc = updcrc(0,updcrc(0,crc));
  1504. X        zsendline(crc>>8); 
  1505. X        zsendline(crc);
  1506. X    }
  1507. X    if(frameend == ZCRCW)
  1508. X    {
  1509. X        xsendline(XON);  
  1510. X        flushline();
  1511. X    }
  1512. X    report_tx_ind(0);
  1513. X
  1514. X}
  1515. X
  1516. Xzsda32(buf,length,frameend)
  1517. Xregister char *buf;
  1518. X{
  1519. X    register int c;
  1520. X    register UNSL long crc;
  1521. X
  1522. X    report_tx_ind(1);
  1523. X
  1524. X    crc = 0xFFFFFFFFL;
  1525. X    for(;--length >= 0; ++buf)
  1526. X    {
  1527. X        c = *buf & 0377;
  1528. X        if(c & 0140)
  1529. X            xsendline(lastsent = c);
  1530. X        else
  1531. X            zsendline(c);
  1532. X        crc = UPDC32(c,crc);
  1533. X    }
  1534. X    xsendline(ZDLE); 
  1535. X    xsendline(frameend);
  1536. X    crc = UPDC32(frameend,crc);
  1537. X
  1538. X    crc = ~crc;
  1539. X    for(length=4; --length >= 0;)
  1540. X    {
  1541. X        zsendline((int)crc);  
  1542. X        crc >>= 8;
  1543. X    }
  1544. X    report_tx_ind(0);
  1545. X}
  1546. X
  1547. X/*
  1548. X * Receive array buf of max length with ending ZDLE sequence
  1549. X *  and CRC.  Returns the ending character or error code.
  1550. X *  NB: On errors may store length+1 bytes!
  1551. X */
  1552. Xzrdata(buf,length)
  1553. Xregister char *buf;
  1554. X{
  1555. X    register int c;
  1556. X    register unsigned short crc;
  1557. X    register char *end;
  1558. X    register int d;
  1559. X
  1560. X    report_rx_ind(1);
  1561. X
  1562. X    if(Rxframeind == ZBIN32)
  1563. X    {
  1564. X        report_rx_ind(0);
  1565. X        return(zrdat32(buf,length));
  1566. X    }
  1567. X
  1568. X    crc = Rxcount = 0;  
  1569. X    end = buf + length;
  1570. X    while(buf <= end)
  1571. X    {
  1572. X        if((c = zdlread()) & ~0377)
  1573. X        {
  1574. Xcrcfoo:
  1575. X            switch(c)
  1576. X            {
  1577. X            case GOTCRCE:
  1578. X            case GOTCRCG:
  1579. X            case GOTCRCQ:
  1580. X            case GOTCRCW:
  1581. X                crc = updcrc(((d=c)&0377),crc);
  1582. X                if((c = zdlread()) & ~0377)
  1583. X                    goto crcfoo;
  1584. X                crc = updcrc(c,crc);
  1585. X                if((c = zdlread()) & ~0377)
  1586. X                    goto crcfoo;
  1587. X                crc = updcrc(c,crc);
  1588. X                if(crc & 0xFFFF)
  1589. X                {
  1590. X                    report_str(badcrc,0);
  1591. X                    report_rx_ind(0);
  1592. X                    return(ERROR);
  1593. X                }
  1594. X                Rxcount = length - (end - buf);
  1595. X                report_rxblklen(Rxcount);
  1596. X                sprintf(s128,"data %s %d bytes",
  1597. X                    Zendnames[d-GOTCRCE&3],Rxcount);
  1598. X                report_last_rxhdr(s128,0);
  1599. X                report_rx_ind(0);
  1600. X                return(d);
  1601. X            case GOTCAN:
  1602. X                report_str("Sender Cancelled",1);
  1603. X                report_rx_ind(0);
  1604. X                return(ZCAN);
  1605. X            case TIMEOUT:
  1606. X                report_str("TIMEOUT",1);
  1607. X                report_rx_ind(0);
  1608. X                return(c);
  1609. X            default:
  1610. X                report_str("Bad data subpacket",1);
  1611. X                report_rx_ind(0);
  1612. X                return(c);
  1613. X            }
  1614. X        }
  1615. X        *buf++ = c;
  1616. X        crc = updcrc(c,crc);
  1617. X    }
  1618. X    report_str("Data subpacket too long",1);
  1619. X    report_rx_ind(0);
  1620. X    return(ERROR);
  1621. X}
  1622. X
  1623. Xzrdat32(buf,length)
  1624. Xregister char *buf;
  1625. X{
  1626. X    register int c;
  1627. X    register UNSL long crc;
  1628. X    register char *end;
  1629. X    register int d;
  1630. X
  1631. X    report_rx_ind(1);
  1632. X    crc = 0xFFFFFFFFL;  
  1633. X    Rxcount = 0;  
  1634. X    end = buf + length;
  1635. X    while(buf <= end)
  1636. X    {
  1637. X        if((c = zdlread()) & ~0377)
  1638. X        {
  1639. Xcrcfoo:
  1640. X            switch(c)
  1641. X            {
  1642. X            case GOTCRCE:
  1643. X            case GOTCRCG:
  1644. X            case GOTCRCQ:
  1645. X            case GOTCRCW:
  1646. X                d = c;  
  1647. X                c &= 0377;
  1648. X                crc = UPDC32(c,crc);
  1649. X                if((c = zdlread()) & ~0377)
  1650. X                    goto crcfoo;
  1651. X                crc = UPDC32(c,crc);
  1652. X                if((c = zdlread()) & ~0377)
  1653. X                    goto crcfoo;
  1654. X                crc = UPDC32(c,crc);
  1655. X                if((c = zdlread()) & ~0377)
  1656. X                    goto crcfoo;
  1657. X                crc = UPDC32(c,crc);
  1658. X                if((c = zdlread()) & ~0377)
  1659. X                    goto crcfoo;
  1660. X                crc = UPDC32(c,crc);
  1661. X                if(crc != 0xDEBB20E3)
  1662. X                {
  1663. X                    report_str(badcrc,0);
  1664. X                    report_rx_ind(0);
  1665. X                    return(ERROR);
  1666. X                }
  1667. X                Rxcount = length - (end - buf);
  1668. X                report_rxblklen(Rxcount);
  1669. X                sprintf(s128,"data %s %d bytes",
  1670. X                    Zendnames[d-GOTCRCE&3],Rxcount);
  1671. X                report_last_rxhdr(s128,0);
  1672. X                report_rx_ind(0);
  1673. X                return(d);
  1674. X            case GOTCAN:
  1675. X                report_str("Sender Canceled",1);
  1676. X                report_rx_ind(0);
  1677. X                return(ZCAN);
  1678. X            case TIMEOUT:
  1679. X                report_str("TIMEOUT",1);
  1680. X                report_rx_ind(0);
  1681. X                return(c);
  1682. X            default:
  1683. X                report_str("Bad data subpacket",1);
  1684. X                report_rx_ind(0);
  1685. X                return(c);
  1686. X            }
  1687. X        }
  1688. X        *buf++ = c;
  1689. X        crc = UPDC32(c,crc);
  1690. X    }
  1691. X    report_str("Data subpacket too long",1);
  1692. X    report_rx_ind(0);
  1693. X    return(ERROR);
  1694. X}
  1695. X
  1696. X
  1697. X/*
  1698. X * Read a ZMODEM header to hdr,either binary or hex.
  1699. X *  eflag controls local display of non zmodem characters:
  1700. X *    0:  no display
  1701. X *    1:  display printing characters only
  1702. X *    2:  display all non ZMODEM characters
  1703. X *  On success,set Zmodem to 1,set Rxpos and return type of header.
  1704. X *   Otherwise return negative on error.
  1705. X *   Return ERROR instantly if ZCRCW sequence,for fast error recovery.
  1706. X */
  1707. Xzgethdr(hdr,eflag)
  1708. Xchar *hdr;
  1709. X{
  1710. Xregister int c,n,cancount;
  1711. X
  1712. X    report_rx_ind(1);
  1713. X    n = Zrwindow + Baudrate;    /* Max bytes before start of frame */
  1714. X    Rxframeind = Rxtype = 0;
  1715. X
  1716. Xstartover:
  1717. X    cancount = 5;
  1718. Xagain:
  1719. X    /* Return immediate ERROR if ZCRCW sequence seen */
  1720. X    switch(c = readline(Rxtimeout))
  1721. X    {
  1722. X    case RCDO:
  1723. X    case TIMEOUT:
  1724. X        goto fifi;
  1725. X    case CAN:
  1726. Xgotcan:
  1727. X        if(--cancount <= 0)
  1728. X        {
  1729. X            c = ZCAN; 
  1730. X            goto fifi;
  1731. X        }
  1732. X        switch(c = readline(1))
  1733. X        {
  1734. X        case TIMEOUT:
  1735. X            goto again;
  1736. X        case ZCRCW:
  1737. X            c = ERROR;
  1738. X            /* **** FALL THRU TO **** */
  1739. X        case RCDO:
  1740. X            goto fifi;
  1741. X        default:
  1742. X            break;
  1743. X        case CAN:
  1744. X            if(--cancount <= 0)
  1745. X            {
  1746. X                c = ZCAN; 
  1747. X                goto fifi;
  1748. X            }
  1749. X            goto again;
  1750. X        }
  1751. X        /* **** FALL THRU TO **** */
  1752. X    default:
  1753. Xagn2:
  1754. X        if( --n == 0)
  1755. X        {
  1756. X            report_str("Garbage count exceeded",1);
  1757. X            report_last_rxhdr("Noise",0);
  1758. X            report_rx_ind(0);
  1759. X            return(ERROR);
  1760. X        }
  1761. X        goto startover;
  1762. X    case ZPAD|0200:        /* This is what we want. */
  1763. X    case ZPAD:        /* This is what we want. */
  1764. X        evenp = c & 0200;
  1765. X        break;
  1766. X    }
  1767. X    cancount = 5;
  1768. Xsplat:
  1769. X    switch(c = noxrd7())
  1770. X    {
  1771. X    case ZPAD:
  1772. X        goto splat;
  1773. X    case RCDO:
  1774. X    case TIMEOUT:
  1775. X        goto fifi;
  1776. X    default:
  1777. X        goto agn2;
  1778. X    case ZDLE:        /* This is what we want. */
  1779. X        break;
  1780. X    }
  1781. X
  1782. X    switch(c = noxrd7())
  1783. X    {
  1784. X    case RCDO:
  1785. X    case TIMEOUT:
  1786. X        goto fifi;
  1787. X    case ZBIN:
  1788. X        Rxframeind = ZBIN;  
  1789. X        Crc32 = FALSE;
  1790. X        c =  zrbhdr(hdr);
  1791. X        break;
  1792. X    case ZBIN32:
  1793. X        Crc32 = Rxframeind = ZBIN32;
  1794. X        c =  zrbhdr32(hdr);
  1795. X        break;
  1796. X    case ZHEX:
  1797. X        Rxframeind = ZHEX;  
  1798. X        Crc32 = FALSE;
  1799. X        c =  zrhhdr(hdr);
  1800. X        break;
  1801. X    case CAN:
  1802. X        goto gotcan;
  1803. X    default:
  1804. X        goto agn2;
  1805. X    }
  1806. X    Rxpos = hdr[ZP3] & 0377;
  1807. X    Rxpos = (Rxpos<<8) + (hdr[ZP2] & 0377);
  1808. X    Rxpos = (Rxpos<<8) + (hdr[ZP1] & 0377);
  1809. X    Rxpos = (Rxpos<<8) + (hdr[ZP0] & 0377);
  1810. Xfifi:
  1811. X    switch(c)
  1812. X    {
  1813. X    case GOTCAN:
  1814. X        c = ZCAN;
  1815. X        /* **** FALL THRU TO **** */
  1816. X    case ZNAK:
  1817. X    case ZCAN:
  1818. X    case ERROR:
  1819. X    case TIMEOUT:
  1820. X    case RCDO:
  1821. X        sprintf(s128,"Got %s",frametypes[c+FTOFFSET]);
  1822. X        report_str(s128,1);
  1823. X        /* **** FALL THRU TO **** */
  1824. X    default:
  1825. X        if(c >= -3 && c <= FRTYPES)
  1826. X            sprintf(s128,"hdr %s %ld",frametypes[c+FTOFFSET],Rxpos);
  1827. X        else
  1828. X            sprintf(s128,"hdr 0x%02x? %ld",c,Rxpos);
  1829. X        report_last_rxhdr(s128,0);
  1830. X    }
  1831. X    report_rx_ind(0);
  1832. X    return(c);
  1833. X}
  1834. X
  1835. X/* Receive a binary style header (type and position) */
  1836. Xzrbhdr(hdr)
  1837. Xregister char *hdr;
  1838. X{
  1839. X    register int c,n;
  1840. X    register unsigned short crc;
  1841. X
  1842. X    if((c = zdlread()) & ~0377)
  1843. X        return(c);
  1844. X    Rxtype = c;
  1845. X    crc = updcrc(c,0);
  1846. X
  1847. X    for(n=4; --n >= 0; ++hdr)
  1848. X    {
  1849. X        if((c = zdlread()) & ~0377)
  1850. X            return(c);
  1851. X        crc = updcrc(c,crc);
  1852. X        *hdr = c;
  1853. X    }
  1854. X    if((c = zdlread()) & ~0377)
  1855. X        return(c);
  1856. X    crc = updcrc(c,crc);
  1857. X    if((c = zdlread()) & ~0377)
  1858. X        return(c);
  1859. X    crc = updcrc(c,crc);
  1860. X    if(crc & 0xFFFF)
  1861. X    {
  1862. X        if(evenp)
  1863. X            report_str(masked,1);
  1864. X        report_str(badcrc,0);
  1865. X        return(ERROR);
  1866. X    }
  1867. X#if defined(ZMODEM)
  1868. X    Protocol = ZMODEM;
  1869. X#endif
  1870. X    Zmodem = 1;
  1871. X    return(Rxtype);
  1872. X}
  1873. X
  1874. X/* Receive a binary style header (type and position) with 32 bit FCS */
  1875. Xzrbhdr32(hdr)
  1876. Xregister char *hdr;
  1877. X{
  1878. X    register int c,n;
  1879. X    register UNSL long crc;
  1880. X
  1881. X    if((c = zdlread()) & ~0377)
  1882. X        return(c);
  1883. X    Rxtype = c;
  1884. X    crc = 0xFFFFFFFFL; 
  1885. X    crc = UPDC32(c,crc);
  1886. X
  1887. X    for(n=4; --n >= 0; ++hdr)
  1888. X    {
  1889. X        if((c = zdlread()) & ~0377)
  1890. X            return(c);
  1891. X        crc = UPDC32(c,crc);
  1892. X        *hdr = c;
  1893. X    }
  1894. X    for(n=4; --n >= 0;)
  1895. X    {
  1896. X        if((c = zdlread()) & ~0377)
  1897. X            return(c);
  1898. X        crc = UPDC32(c,crc);
  1899. X    }
  1900. X    if(crc != 0xDEBB20E3)
  1901. X    {
  1902. X        if(evenp)
  1903. X            report_str(masked,1);
  1904. X        report_str(badcrc,0);
  1905. X        return(ERROR);
  1906. X    }
  1907. X#if defined(ZMODEM)
  1908. X    Protocol = ZMODEM;
  1909. X#endif
  1910. X    Zmodem = 1;
  1911. X    return(Rxtype);
  1912. X}
  1913. X
  1914. X
  1915. X/* Receive a hex style header (type and position) */
  1916. Xzrhhdr(hdr)
  1917. Xchar *hdr;
  1918. X{
  1919. X    register int c;
  1920. X    register unsigned short crc;
  1921. X    register int n;
  1922. X
  1923. X    if((c = zgethex()) < 0)
  1924. X        return(c);
  1925. X    Rxtype = c;
  1926. X    crc = updcrc(c,0);
  1927. X
  1928. X    for(n=4; --n >= 0; ++hdr)
  1929. X    {
  1930. X        if((c = zgethex()) < 0)
  1931. X            return(c);
  1932. X        crc = updcrc(c,crc);
  1933. X        *hdr = c;
  1934. X    }
  1935. X    if((c = zgethex()) < 0)
  1936. X        return(c);
  1937. X    crc = updcrc(c,crc);
  1938. X    if((c = zgethex()) < 0)
  1939. X        return(c);
  1940. X    crc = updcrc(c,crc);
  1941. X    if(crc & 0xFFFF)
  1942. X    {
  1943. X        report_str(badcrc,0); 
  1944. X        return(ERROR);
  1945. X    }
  1946. X    if(readline(1) == '\r')    /* Throw away possible cr/lf */
  1947. X        readline(1);
  1948. X#if defined(ZMODEM)
  1949. X    Protocol = ZMODEM;
  1950. X#endif
  1951. X    Zmodem = 1; 
  1952. X    return(Rxtype);
  1953. X}
  1954. X
  1955. X/* Send a byte as two hex digits */
  1956. Xzputhex(c)
  1957. Xregister int c;
  1958. X{
  1959. X    static char digits[]    = "0123456789abcdef";
  1960. X
  1961. X    sendline(digits[(c&0xF0)>>4]);
  1962. X    sendline(digits[(c)&0xF]);
  1963. X}
  1964. X
  1965. X/*
  1966. X * Send character c with ZMODEM escape sequence encoding.
  1967. X *  Escape XON,XOFF. Escape CR following @ (Telenet net escape)
  1968. X */
  1969. Xzsendline(c)
  1970. X{
  1971. X
  1972. X    /* Quick check for non control characters */
  1973. X    if(c & 0140)
  1974. X        xsendline(lastsent = c);
  1975. X    else 
  1976. X    {
  1977. X        switch(c &= 0377)
  1978. X        {
  1979. X        case ZDLE:
  1980. X            xsendline(ZDLE);
  1981. X            xsendline(lastsent = (c ^= 0100));
  1982. X            break;
  1983. X        case 015:
  1984. X        case 0215:
  1985. X            if(!Zctlesc && (lastsent & 0177) != '@')
  1986. X                goto sendit;
  1987. X            /* **** FALL THRU TO **** */
  1988. X        case 020:
  1989. X        case 021:
  1990. X        case 023:
  1991. X        case 0220:
  1992. X        case 0221:
  1993. X        case 0223:
  1994. X            xsendline(ZDLE);
  1995. X            c ^= 0100;
  1996. Xsendit:
  1997. X            xsendline(lastsent = c);
  1998. X            break;
  1999. X        default:
  2000. X            if(Zctlesc && ! (c & 0140))
  2001. X            {
  2002. X                xsendline(ZDLE);
  2003. X                c ^= 0100;
  2004. X            }
  2005. X            xsendline(lastsent = c);
  2006. X        }
  2007. X    }
  2008. X}
  2009. X
  2010. X/* Decode two lower case hex digits into an 8 bit byte value */
  2011. Xzgethex()
  2012. X{
  2013. X    register int c;
  2014. X
  2015. X    c = zgeth1();
  2016. X    return(c);
  2017. X}
  2018. Xzgeth1()
  2019. X{
  2020. X    register int c,n;
  2021. X
  2022. X    if((c = noxrd7()) < 0)
  2023. X        return(c);
  2024. X    n = c - '0';
  2025. X    if(n > 9)
  2026. X        n -= ('a' - ':');
  2027. X    if(n & ~0xF)
  2028. X        return(ERROR);
  2029. X    if((c = noxrd7()) < 0)
  2030. X        return(c);
  2031. X    c -= '0';
  2032. X    if(c > 9)
  2033. X        c -= ('a' - ':');
  2034. X    if(c & ~0xF)
  2035. X        return(ERROR);
  2036. X    c += (n<<4);
  2037. X    return(c);
  2038. X}
  2039. X
  2040. X/*
  2041. X * Read a byte,checking for ZMODEM escape encoding
  2042. X *  including CAN*5 which represents a quick abort
  2043. X */
  2044. Xzdlread()
  2045. X{
  2046. X    register int c;
  2047. X
  2048. Xagain:
  2049. X    /* Quick check for non control characters */
  2050. X    if((c = readline(Rxtimeout)) & 0140)
  2051. X        return(c);
  2052. X    switch(c)
  2053. X    {
  2054. X    case ZDLE:
  2055. X        break;
  2056. X    case 023:
  2057. X    case 0223:
  2058. X    case 021:
  2059. X    case 0221:
  2060. X        goto again;
  2061. X    default:
  2062. X        if(Zctlesc && !(c & 0140))
  2063. X        {
  2064. X            goto again;
  2065. X        }
  2066. X        return(c);
  2067. X    }
  2068. Xagain2:
  2069. X    if((c = readline(Rxtimeout)) < 0)
  2070. X        return(c);
  2071. X    if(c == CAN && (c = readline(Rxtimeout)) < 0)
  2072. X        return(c);
  2073. X    if(c == CAN && (c = readline(Rxtimeout)) < 0)
  2074. X        return(c);
  2075. X    if(c == CAN && (c = readline(Rxtimeout)) < 0)
  2076. X        return(c);
  2077. X    switch(c)
  2078. X    {
  2079. X    case CAN:
  2080. X        return(GOTCAN);
  2081. X    case ZCRCE:
  2082. X    case ZCRCG:
  2083. X    case ZCRCQ:
  2084. X    case ZCRCW:
  2085. X        return(c | GOTOR);
  2086. X    case ZRUB0:
  2087. X        return(0177);
  2088. X    case ZRUB1:
  2089. X        return(0377);
  2090. X    case 023:
  2091. X    case 0223:
  2092. X    case 021:
  2093. X    case 0221:
  2094. X        goto again2;
  2095. X    default:
  2096. X        if(Zctlesc && ! (c & 0140))
  2097. X        {
  2098. X            goto again2;
  2099. X        }
  2100. X        if((c & 0140) ==  0100)
  2101. X            return(c ^ 0100);
  2102. X        break;
  2103. X    }
  2104. X    sprintf(s128,"Bad escape sequence %x",c);
  2105. X    report_str(s128,1);
  2106. X    return(ERROR);
  2107. X}
  2108. X
  2109. X/*
  2110. X * Read a character from the modem line with timeout.
  2111. X *  Eat parity,XON and XOFF characters.
  2112. X */
  2113. Xnoxrd7()
  2114. X{
  2115. X    register int c;
  2116. X
  2117. X    for(;;)
  2118. X    {
  2119. X        if((c = readline(Rxtimeout)) < 0)
  2120. X            return(c);
  2121. X        switch(c &= 0177)
  2122. X        {
  2123. X        case XON:
  2124. X        case XOFF:
  2125. X            continue;
  2126. X        default:
  2127. X            if(Zctlesc && !(c & 0140))
  2128. X                continue;
  2129. X        case '\r':
  2130. X        case '\n':
  2131. X        case ZDLE:
  2132. X            return(c);
  2133. X        }
  2134. X    }
  2135. X}
  2136. X
  2137. X/* Store long integer pos in Txhdr */
  2138. Xstohdr(pos)
  2139. Xlong pos;
  2140. X{
  2141. X    Txhdr[ZP0] = pos;
  2142. X    Txhdr[ZP1] = pos>>8;
  2143. X    Txhdr[ZP2] = pos>>16;
  2144. X    Txhdr[ZP3] = pos>>24;
  2145. X}
  2146. X
  2147. X/* Recover a long integer from a header */
  2148. Xlong
  2149. Xrclhdr(hdr)
  2150. Xregister char *hdr;
  2151. X{
  2152. X    register long l;
  2153. X
  2154. X    l = (hdr[ZP3] & 0377);
  2155. X    l = (l << 8) | (hdr[ZP2] & 0377);
  2156. X    l = (l << 8) | (hdr[ZP1] & 0377);
  2157. X    l = (l << 8) | (hdr[ZP0] & 0377);
  2158. X    return(l);
  2159. X}
  2160. X
  2161. X/* end of zmodem.c */
  2162. X/* vi: set tabstop=4 shiftwidth=4: */
  2163. SHAR_EOF
  2164. $TOUCH -am 0521180190 xfer/zmodem.c &&
  2165. chmod 0644 xfer/zmodem.c ||
  2166. echo "restore of xfer/zmodem.c failed"
  2167. set `wc -c xfer/zmodem.c`;Wc_c=$1
  2168. if test "$Wc_c" != "16500"; then
  2169.     echo original size 16500, current size $Wc_c
  2170. fi
  2171. # ============= xfer/zmodem.h ==============
  2172. echo "x - extracting xfer/zmodem.h (Text)"
  2173. sed 's/^X//' << 'SHAR_EOF' > xfer/zmodem.h &&
  2174. X/*+-------------------------------------------------------------------------
  2175. X    zmodem.h -- common include filefor tiprz/tipsz
  2176. X--------------------------------------------------------------------------*/
  2177. X/*+:EDITS:*/
  2178. X/*:05-21-1990-16:00-wht@tridom-adapt ecu xfer protocols for tipwht */
  2179. X
  2180. X#if defined(pyr)
  2181. X#include <sys/types.h>
  2182. X#include <sys/stat.h>
  2183. X#include <sgtty.h>
  2184. X#define OS "BSD4.x"
  2185. X#if defined(LLITOUT)
  2186. X#include <strings.h>
  2187. X#endif
  2188. X#endif
  2189. X
  2190. X#if defined(M_UNIX)
  2191. X#define OS "UNIX"
  2192. X#undef M_XENIX
  2193. X#endif
  2194. X
  2195. X#if !defined(OS)
  2196. X#if !defined(M_XENIX)
  2197. X#define XENIX
  2198. X#endif
  2199. X#endif
  2200. X
  2201. X#if defined(M_XENIX) || defined(M_UNIX)
  2202. X#include <sys/types.h>
  2203. X#include <sys/stat.h>
  2204. X#include <termio.h>
  2205. X#include <sys/ioctl.h>
  2206. X#include <string.h>
  2207. X#define MODE2OK
  2208. X#endif
  2209. X
  2210. X#if defined(pyr)
  2211. X#if defined(TIOCSBRK)
  2212. X#define CANBREAK
  2213. X#endif
  2214. X#endif
  2215. X#if defined(M_XENIX) || defined(M_UNIX)
  2216. X#define CANBREAK
  2217. X#endif
  2218. X
  2219. X#if !defined(READCHECK)
  2220. X#if defined(FIONREAD)
  2221. X#define READCHECK
  2222. X#endif
  2223. X#if defined(SV)
  2224. X#define READCHECK
  2225. X#endif
  2226. X#endif
  2227. X
  2228. X#define ACK 6
  2229. X#define CAN ('X'&037)
  2230. X#define CPMEOF 032
  2231. X#define ENQ 005
  2232. X#define EOT 4
  2233. X#define ERROR (-1)
  2234. X#define ERRORMAX 5
  2235. X#define FALSE 0
  2236. X#define NAK 025
  2237. X#define OK 0
  2238. X#define PATHLEN 257    /* ready for 4.2 bsd ? */
  2239. X#define RCDO (-3)
  2240. X#define SOH 1
  2241. X#define STX 2
  2242. X#define TIMEOUT (-2)
  2243. X#define TRUE 1
  2244. X#define UNIXFILE 0xF000    /* The S_IFMT file mask bit for stat */
  2245. X#define WANTCRC 0103    /* send C not NAK to get crc not checksum */
  2246. X
  2247. X#define WANTG 0107    /* Send G not NAK to get nonstop batch xmsn */
  2248. X#define WCEOT (-10)
  2249. X#define XOFF ('s'&037)
  2250. X#define XON ('q'&037)
  2251. X
  2252. X/*
  2253. X * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell. 
  2254. X *  NOTE: First argument must be in range 0 to 255.
  2255. X *        Second argument is referenced twice.
  2256. X * 
  2257. X * Programmers may incorporate any or all code into their programs, 
  2258. X * giving proper credit within the source. Publication of the 
  2259. X * source routines is permitted so long as proper credit is given 
  2260. X * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg, 
  2261. X * Omen Technology.
  2262. X */
  2263. X
  2264. X#define updcrc(cp, crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ (cp))
  2265. X#define UPDC32(b, c) (cr3tab[((int)c ^ b) & 0xff] ^ ((c >> 8) & 0x00FFFFFF))
  2266. X
  2267. X
  2268. X#define ZPAD '*'    /* 052 Padding character begins frames */
  2269. X#define ZDLE 030    /* Ctrl-X Zmodem escape - `ala BISYNC DLE */
  2270. X#define ZDLEE (ZDLE^0100)    /* Escaped ZDLE as transmitted */
  2271. X#define ZBIN 'A'    /* Binary frame indicator */
  2272. X#define ZHEX 'B'    /* HEX frame indicator */
  2273. X#define ZBIN32 'C'    /* Binary frame with 32 bit FCS */
  2274. X
  2275. X/* Frame types (see array "frametypes" in zm.c) */
  2276. X#define ZRQINIT    0    /* Request receive init */
  2277. X#define ZRINIT    1    /* Receive init */
  2278. X#define ZSINIT 2    /* Send init sequence (optional) */
  2279. X#define ZACK 3        /* ACK to above */
  2280. X#define ZFILE 4        /* File name from sender */
  2281. X#define ZSKIP 5        /* To sender: skip this file */
  2282. X#define ZNAK 6        /* Last packet was garbled */
  2283. X#define ZABORT 7    /* Abort batch transfers */
  2284. X#define ZFIN 8        /* Finish session */
  2285. X#define ZRPOS 9        /* Resume data trans at this position */
  2286. X#define ZDATA 10    /* Data packet(s) follow */
  2287. X#define ZEOF 11        /* End of file */
  2288. X#define ZFERR 12    /* Fatal Read or Write error Detected */
  2289. X#define ZCRC 13        /* Request for file CRC and response */
  2290. X#define ZCHALLENGE 14    /* Receiver's Challenge */
  2291. X#define ZCOMPL 15    /* Request is complete */
  2292. X#define ZCAN 16        /* Other end canned session with CAN*5 */
  2293. X#define ZFREECNT 17    /* Request for free bytes on filesystem */
  2294. X#define ZCOMMAND 18    /* Command from sending program */
  2295. X#define ZSTDERR 19    /* Output to standard error, data follows */
  2296. X
  2297. X/* ZDLE sequences */
  2298. X#define ZCRCE 'h'    /* CRC next, frame ends, header packet follows */
  2299. X#define ZCRCG 'i'    /* CRC next, frame continues nonstop */
  2300. X#define ZCRCQ 'j'    /* CRC next, frame continues, ZACK expected */
  2301. X#define ZCRCW 'k'    /* CRC next, ZACK expected, end of frame */
  2302. X#define ZRUB0 'l'    /* Translate to rubout 0177 */
  2303. X#define ZRUB1 'm'    /* Translate to rubout 0377 */
  2304. X
  2305. X/* zdlread return values (internal) */
  2306. X/* -1 is general error, -2 is timeout */
  2307. X#define GOTOR 0400
  2308. X#define GOTCRCE (ZCRCE|GOTOR)    /* ZDLE-ZCRCE received */
  2309. X#define GOTCRCG (ZCRCG|GOTOR)    /* ZDLE-ZCRCG received */
  2310. X#define GOTCRCQ (ZCRCQ|GOTOR)    /* ZDLE-ZCRCQ received */
  2311. X#define GOTCRCW (ZCRCW|GOTOR)    /* ZDLE-ZCRCW received */
  2312. X#define GOTCAN    (GOTOR|030)    /* CAN*5 seen */
  2313. X
  2314. X/* Byte positions within header array */
  2315. X#define ZF0    3    /* First flags byte */
  2316. X#define ZF1    2
  2317. X#define ZF2    1
  2318. X#define ZF3    0
  2319. X#define ZP0    0    /* Low order 8 bits of position */
  2320. X#define ZP1    1
  2321. X#define ZP2    2
  2322. X#define ZP3    3    /* High order 8 bits of file position */
  2323. X
  2324. X/* Bit Masks for ZRINIT flags byte ZF0 */
  2325. X#define CANFDX    01    /* Rx can send and receive true FDX */
  2326. X#define CANOVIO    02    /* Rx can receive data during disk I/O */
  2327. X#define CANBRK    04    /* Rx can send a break signal */
  2328. X#define CANCRY    010    /* Receiver can decrypt */
  2329. X#define CANLZW    020    /* Receiver can uncompress */
  2330. X#define CANFC32    040    /* Receiver can use 32 bit Frame Check */
  2331. X#define ESCCTL 0100    /* Receiver expects ctl chars to be escaped */
  2332. X#define ESC8   0200    /* Receiver expects 8th bit to be escaped */
  2333. X
  2334. X/* Parameters for ZSINIT frame */
  2335. X#define ZATTNLEN 32    /* Max length of attention string */
  2336. X/* Bit Masks for ZSINIT flags byte ZF0 */
  2337. X#define TESCCTL 0100    /* Transmitter expects ctl chars to be escaped */
  2338. X#define TESC8   0200    /* Transmitter expects 8th bit to be escaped */
  2339. X
  2340. X/* Parameters for ZFILE frame */
  2341. X/* Conversion options one of these in ZF0 */
  2342. X#define ZCBIN    1    /* Binary transfer - inhibit conversion */
  2343. X#define ZCNL    2    /* Convert NL to local end of line convention */
  2344. X#define ZCRESUM    3    /* Resume interrupted file transfer */
  2345. X/* Management include options, one of these ored in ZF1 */
  2346. X#define ZMSKNOLOC    0200    /* Skip file if not present at rx */
  2347. X/* Management options, one of these ored in ZF1 */
  2348. X#define ZMMASK    037    /* Mask for the choices below */
  2349. X#define ZMNEWL    1    /* Transfer if source newer or longer */
  2350. X#define ZMCRC    2    /* Transfer if different file CRC or length */
  2351. X#define ZMAPND    3    /* Append contents to existing file (if any) */
  2352. X#define ZMCLOB    4    /* Replace existing file */
  2353. X#define ZMNEW    5    /* Transfer if source newer */
  2354. X    /* Number 5 is alive ... */
  2355. X#define ZMDIFF    6    /* Transfer if dates or lengths different */
  2356. X#define ZMPROT    7    /* Protect destination file */
  2357. X/* Transport options, one of these in ZF2 */
  2358. X#define ZTLZW    1    /* Lempel-Ziv compression */
  2359. X#define ZTCRYPT    2    /* Encryption */
  2360. X#define ZTRLE    3    /* Run Length encoding */
  2361. X/* Extended options for ZF3, bit encoded */
  2362. X#define ZXSPARS    64    /* Encoding for sparse file operations */
  2363. X
  2364. X/* Parameters for ZCOMMAND frame ZF0 (otherwise 0) */
  2365. X#define ZCACK1    1    /* Acknowledge, then do command */
  2366. X
  2367. X/* FTOFFSET is offset for frametypes array in tipzm.c */
  2368. X#define FTOFFSET 3
  2369. X
  2370. Xlong rclhdr();
  2371. X
  2372. X#include "zlint.h"
  2373. X/* vi: set tabstop=4 shiftwidth=4: */
  2374. SHAR_EOF
  2375. $TOUCH -am 0521180190 xfer/zmodem.h &&
  2376. chmod 0644 xfer/zmodem.h ||
  2377. echo "restore of xfer/zmodem.h failed"
  2378. set `wc -c xfer/zmodem.h`;Wc_c=$1
  2379. if test "$Wc_c" != "6734"; then
  2380.     echo original size 6734, current size $Wc_c
  2381. fi
  2382. exit 0
  2383.  
  2384. ------------------------------------------------------------------
  2385. Warren Tucker, Tridom Corporation      ...!gatech!emory!tridom!wht
  2386. home address:                                 ...!gatech!n4hgf!wht
  2387.  
  2388.