home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 110_01 / yam3.c < prev    next >
Text File  |  1984-03-03  |  8KB  |  410 lines

  1. /*
  2. >>:yam3.c 9-6-81
  3.  *
  4.  * two-way conversation with remote -whatever.
  5.  * Printer is buffered such that it needn't be as fast as the baudrate
  6.  * as long as it eventually gets a chance to catch up.
  7.  * This buffering also allows one to write the received data out to disk
  8.  * after the conservation has started.
  9.  */
  10. #include "yam.h"
  11.  
  12. term()
  13. {
  14. #ifndef BDSC
  15.     register char cfast;
  16. #endif
  17.     register c, cc;
  18.     unsigned register charsent;
  19.  
  20. sayterm:
  21. #ifdef TERMRESET
  22.     lprintf(TERMRESET);
  23. #endif
  24.     charsent=0;
  25.     Waitecho=Txwait=FALSE;
  26.     if(Tfile)
  27.         lpstat("Sending '%s' %s", Tname, Txgo?"":"Stopped");
  28.     if(Rfile)
  29.         pstat("Term Receiving '%s'", Rname);
  30.     else
  31.         pstat("Term Function");
  32.     for(;;) {
  33.         if(MIREADY) {
  34.              *bufcq++ = MICHAR;
  35.             Timeout=0;
  36.             if(bufcq >= bufend) {
  37.                 Wrapped=TRUE;
  38.                 bufcq=bufst;
  39.             }
  40.             if(--Free == Low)
  41.                 outp(MODATA, Xoffflg=XOFF);
  42.             continue;
  43.         }
  44.         if(COREADY && bufcdq != bufcq) {
  45.             switch(cfast= (*bufcdq & 0177) ) {
  46.             case '\b':
  47.                 if(Ttycol)
  48.                     --Ttycol;
  49.                 break;
  50.             case '\t':
  51.                 if(++Ttycol & 07)
  52. #ifdef CDATA
  53.                     outp(CDATA, ' ');
  54. #else
  55.                     bios(4,' ');
  56. #endif
  57.                 else if(++bufcdq >= bufend)
  58.                     bufcdq=bufst;
  59.                 continue;
  60.             case '\r':
  61.                 Ttycol=0; break;
  62.             case '\n':
  63.                 if(Txeoln==EOL_CRWAIT)
  64.                     Waitecho=FALSE;
  65.                 break;
  66. cxoff:
  67.             case XOFF:
  68. #ifdef STATLINE
  69.                 if(Tfile)
  70.                     pstat("Sending stopped by XOFF");
  71. #endif
  72.                 Txgo=FALSE; break;
  73. cxon:
  74.             case XON:
  75.                 Txgo=TRUE;
  76. #ifdef STATLINE
  77.                 if(Tfile)
  78.                     goto sayterm;
  79. #endif
  80.                 break;
  81. #ifdef XMODEM
  82.             case CPMEOF:
  83.                 return;
  84. #endif
  85.             default:
  86.                 if(
  87. #ifndef XMODEM
  88.                   Ctlview &&
  89. #endif
  90.                   cfast<040) {
  91.                     putchar('^'); putchar(cfast|0100);
  92.                     Ttycol += 2;
  93.                     if(++bufcdq >= bufend)
  94.                         bufcdq=bufst;
  95.                     continue;
  96.                 }
  97.                 else
  98.                     ++Ttycol; break;
  99.             }
  100. #ifdef CDATA
  101.             outp(CDATA, cfast);
  102. #else
  103.             bios(4, cfast);
  104. #endif
  105.             if(Echo)
  106.                 sendline(cfast);
  107.             if(++bufcdq >= bufend)
  108.                 bufcdq=bufst;
  109.             continue;
  110.         }
  111.         if(Pflag && bufpcdq!=bufcq && POREADY) {
  112. #ifdef CPM
  113.             bios(5, *bufpcdq++);
  114. #endif
  115.             if(bufpcdq >= bufend)
  116.                 bufpcdq=bufst;
  117.         }
  118.         if(CIREADY) {
  119.             switch(cfast= CICHAR&0177){
  120.             case ENQ:
  121.                 if(moment())    /* ^E ^E quick sends one */
  122.                     break;
  123.                 return;
  124.             case XON:
  125.                 if(Tfile && !Txgo)
  126.                     goto cxon;
  127.                 break;
  128.             case XOFF:
  129.                 if(Tfile && Txgo)
  130.                     goto cxoff;
  131.                 break;
  132.             case 'v'&037:
  133.                 if(moment())
  134.                     break;
  135.                 replot(TLENGTH<<1); goto sayterm;
  136.             default:
  137.                 break;
  138.             }
  139.             outp(MODATA, cfast);
  140.             if(Hdx) {
  141. #ifdef CDATA
  142.                 while(!COREADY)
  143.                     ;
  144.                 outp(CDATA, cfast);
  145. #else
  146.                 bios(4, cfast);
  147. #endif
  148.             }
  149.             continue;
  150.         }
  151.         if(MOREADY) {
  152.             if(Tfile && !Txwait && !Waitecho && Txgo) {
  153.                 c= getc(fin);
  154. #ifdef CPM
  155.                 if(c==EOF || (c==CPMEOF && Txeoln != TX_BINARY))
  156. #else
  157.                 if(c==EOF)
  158.     /* Compiler please notice the following....*/
  159.     /* Compiler please notice the following....*/
  160.     /* Compiler please notice the following....*/
  161. #endif
  162.                 {
  163.                     closetx();
  164. #ifdef XMODEM
  165.                     return;
  166. #else
  167.                     if(Exoneof)
  168.                         return;
  169.                     else
  170.                         goto sayterm;
  171. #endif
  172.                 }
  173.                 if(Waitbunch && ++charsent==Waitnum) {
  174.                     charsent=0;
  175.                     if(Waitnum>1) {
  176.                         Waitecho=TRUE; Timeout=0;
  177.                     } else {
  178.                         Txwait=TRUE; Txtimeout=Throttle;
  179.                     }
  180.                 }
  181.  
  182.                 if(c=='\r') {    /* end of line processing */
  183.                     switch(Txeoln) {
  184.                     case EOL_NL: continue;
  185.                     case EOL_CRPROMPT:
  186.                     case EOL_CRWAIT:
  187.                         Waitecho=TRUE; Timeout=0;
  188.                     case EOL_CR:
  189.                         if((cc=getc(fin))!='\n')
  190.                             ungetc(cc, fin);
  191.                         break;
  192.                     }
  193.                 }
  194.                 outp(MODATA, c);
  195.                 continue;
  196.             }
  197.         }
  198.         if(++Timeout == Tpause) {
  199.             Waitecho=FALSE;
  200.             if(Xoffflg) {
  201.                 dumprxbuff();
  202.                 if(bufcdq != bufcq)
  203.                     continue;
  204.                 if(Pflag && bufpcdq != bufcq)
  205.                     continue;
  206.                 Free=Bufsize;
  207.                 Xoffflg=FALSE;
  208.                 outp(MODATA, XON);
  209.             }
  210. #ifdef CDO
  211. /* this seems to be the magic cookie */
  212.  
  213.             if(CDO) {
  214.                 lprintf("Carrier Lost\n");
  215.                 return;
  216.             }
  217.  
  218. /* Compiler, Please notice the following!!! */
  219. /* Compiler, Please notice the following!!! */
  220. /* Compiler, Please notice the following!!! */
  221. /* Compiler, Please notice the following!!! */
  222. /* Compiler, Please notice the following!!! */
  223. /* Compiler, Please notice the following!!! */
  224. /* Compiler, Please notice the following!!! */
  225. /* Compiler, Please notice the following!!! */
  226. /* Compiler, Please notice the following!!! */
  227.  
  228. #endif
  229.  
  230. /* should be compiling again here! */
  231.         }
  232.         if(--Txtimeout==0)
  233.             Txwait=FALSE;
  234.     }
  235. }
  236. /* open a capture file and set the removal pointer to get max goods */
  237. opencapt(name)
  238. char *name;
  239. {
  240.     dumprxbuff(); closerx(TRUE);
  241.     if(openrx(name)==ERROR)
  242.         return ERROR;
  243.     if(buffcdq<bufst)
  244.         buffcdq=bufst;
  245.     if(Wrapped)
  246.         buffcdq=bufcq+1;
  247.     if(buffcdq >= bufend)
  248.         buffcdq=bufst;
  249. /*    dumprxbuff(); */
  250. }
  251.  
  252.  
  253. dumprxbuff()
  254. {
  255.     register c;
  256.  
  257.     if(!Rfile || buffcdq==NULL)
  258.         return OK;
  259.     while(buffcdq != bufcq) {
  260.         c= *buffcdq++;
  261.         if(buffcdq >= bufend)
  262.             buffcdq=bufst;
  263.         if(!Image) {
  264.             switch(c &= 0177) {
  265.              case 0:
  266.                  continue;
  267.             case 032:        /* ^Z or CPMEOF */
  268.                 if(Zeof) {
  269.                     closerx(TRUE);
  270.                     return;
  271.                 }
  272.                 else
  273. #ifdef CPM
  274.                     continue;
  275. #else
  276.                     break;
  277. #endif
  278.             case 022:
  279.                 if(Squelch) {
  280.                     Dumping=TRUE;
  281.                     continue;
  282.                 }
  283.                 break;
  284.             case 024:
  285.                 if(Squelch) {
  286.                     Dumping=FALSE;
  287.                     continue;
  288.                 }
  289.                 break;
  290.             default:
  291.                 break;
  292.             }
  293.         }
  294.         if(Dumping || Image)
  295.             if(putc(c, fout)==ERROR) {
  296.                 printf("\nDisk Full\n");
  297.                 closerx(FALSE);
  298.                 return ERROR;
  299.             }
  300.     }
  301.     Free=Bufsize;
  302.     return OK;
  303. }
  304.  
  305. rewindcb()
  306. {
  307.     bufcdq=buffcdq=bufpcdq=Wrapped?bufcq+1:bufst;
  308. }
  309.  
  310. /*
  311.  * replot redisplays the buffer contents thru putcty allowing XOFF
  312.  * number will represent how many lines to go back first 
  313.  */
  314. replot(number)
  315. {
  316.     char *s, c;
  317.     int count;
  318.  
  319. #ifdef Z19
  320.     /* set it to truncate long lines so count is right */
  321.     printf("\033w");
  322. #endif
  323.     bufmark=Wrapped?bufcq+1:bufst;
  324.  
  325.     if(number) {
  326.         s=bufcq;
  327. backsome:
  328. #ifdef CLEARS
  329.         /* backing up is confusing unless screen is cleard first */
  330.         printf(CLEARS);
  331. #endif
  332.         for(;;) {
  333.             --s;
  334.             if(s<bufst) {
  335.                 if(Wrapped)
  336.                     s= bufend-1;
  337.                 else {
  338.                     s=bufst;
  339.                     break;
  340.                 }
  341.             }
  342.             if(s==bufcq)
  343.                 break;
  344.             if((*s&0177)=='\n' && --number<=0)
  345.                 break;
  346.         }
  347.         bufmark=s;
  348.     }
  349.     s=bufmark;
  350. nextscreen:
  351. #ifdef T4014
  352.     /* Do the big flash on the 4014 or 4012 */
  353.     printf("\033\014");
  354.     sleep(CLKMHZ * 5);
  355. #endif
  356.     count=TLENGTH-2;
  357. nextline:
  358.     while(s != bufcq) {
  359.         cfast= *s++ & 0177;
  360.         if(s >= bufend)
  361.             s=bufst;
  362.         if(c=putcty(cfast))
  363.             goto choose;
  364.         if(cfast=='\r' && --count<=0)
  365.             break;
  366.     }
  367.  
  368.     pstat("Replot cmd?");
  369.     c=getcty();
  370. #ifdef STATLINE
  371.     pstat("");
  372. #endif
  373. choose:
  374. /* Treat Control chars and letters the same */
  375.     switch((c|0140)&0177) {
  376.     case 'v':    /* control-v or v */
  377.     case 'h':    /* backspace */
  378.         number=TLENGTH-2; s=bufmark; goto backsome;
  379.     case 0140:        /* space bar */
  380.         bufmark=s; goto nextscreen;
  381.     case 'p':
  382.         number=1; s=bufmark; goto backsome;
  383.     case 'n':
  384.     case 'j':    /* linefeed */
  385.         bufmark=s; count=1; goto nextline;
  386.     default:
  387.         return;
  388.     }
  389. }
  390.  
  391. /*
  392.  * moment waits a moment and returns FALSE, unless a character is hit,
  393.  * in which case that character is returned
  394.  */
  395. moment()
  396. {
  397.     int c;
  398.     for(c=300*CLKMHZ; --c>0;)
  399.         if(kbhit())
  400.             return(getchar());
  401.     return FALSE;
  402. }
  403. chat()
  404. {
  405.     printf("Ring My Chimes, Maybe I'll Come\n");
  406.     printf("Exit chat with ^Z\n");
  407.     Ctlview=Hdx=Echo=TRUE;
  408.     term();
  409. }
  410. li