home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / BEEHIVE / COMMS / YAM.ARC / YAM3.C < prev    next >
Text File  |  1990-09-20  |  8KB  |  456 lines

  1. /*
  2. >>:yam3.c 28-Sep-82 (dif 10-17-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.     sayterm();
  20.     charsent=0;
  21.     Waitecho=Txwait=FALSE;
  22.     for(;;) {
  23.         MODEMON
  24.         if(MIREADY) {
  25.             *bufcq++ = MICHAR;
  26.             Timeout=0;
  27.             if(bufcq >= bufend) {
  28.                 Wrapped=TRUE;
  29.                 bufcq=bufst;
  30.             }
  31.             if(--Free == Low)
  32.                 sendline(Xoffflg=XOFF);
  33.             else if(Free==0)
  34.                 goto belch;
  35.             continue;
  36.         }
  37.         CONSOLON
  38.         if(COREADY && bufcdq != bufcq) {
  39.             switch(cfast= (*bufcdq & 0177) ) {
  40.             case '\b':
  41.                  if(Ttycol)
  42.                     --Ttycol;
  43.                 break;
  44.             case '\t':
  45.                 sendcon(' ');
  46.                 if(++Ttycol & 07)
  47.                     continue;
  48.                 else
  49.                     goto chuckit;
  50.             case '\r':
  51.                 Ttycol=0;
  52.             case '\n':
  53.                 break;
  54.             case XOFF:
  55. #ifdef STATLINE
  56.                 sayterm();
  57. #endif
  58.                 Txgo=FALSE; break;
  59.             case XON:
  60.                 Txgo=TRUE;
  61. #ifdef STATLINE
  62.                 sayterm();
  63. #endif
  64.                 break;
  65. #ifdef XMODEM
  66.             case CPMEOF:
  67. /*                pstat(""); */
  68.                 return;
  69.             case 007:
  70.                 break;
  71. #endif
  72.             default:
  73.                 if(Ctlview)
  74.                 {
  75.                     if(cfast & 0200) {
  76.                         cfast &= 0177;
  77.                         if(Ctlview>1) {
  78.                             putchar('~'); ++Ttycol;
  79.                         }
  80.                     }
  81.                     if(cfast<040) {
  82.                         putchar('^');
  83.                         putchar(cfast|0100);
  84.                         Ttycol += 2;
  85.                         goto chuckit;
  86.                     }
  87.                     else
  88.                         ++Ttycol; break;
  89.                 }
  90.             }
  91.             if(cfast==GOchar && Txeoln==EOL_CRWAIT)
  92.                 Waitecho=FALSE;
  93.  
  94. #ifdef RXNONO
  95.             if( !index(cfast, RXNONO))
  96. #endif /* RXNONO */
  97.                 sendcon(cfast);
  98.             if(Echo) {
  99.                 sendline(cfast);
  100.                 if(Chat && cfast== '\r') {
  101.                     sendcon('\n');
  102. #ifndef XMODEM
  103.                     sendline('\n');
  104. #endif
  105.                 }
  106.             }
  107. chuckit:
  108.             if(++bufcdq >= bufend)
  109.                 bufcdq=bufst;
  110.             continue;
  111.         }
  112.         if(Pflag && bufpcdq!=bufcq && POREADY) {
  113. #ifdef CPM
  114.             bios(5, (*bufpcdq++ & 0177));
  115. #else
  116.             foobar...
  117. #endif
  118.             if(bufpcdq >= bufend)
  119.                 bufpcdq=bufst;
  120.         }
  121.         CONSOLON
  122.         if(CIREADY) {
  123.             switch(cfast= CICHAR & KBMASK){
  124.              case ENQ:
  125.                 if(moment(KTIME2))   /* ^E ^E quick sends one */
  126.                     break;
  127. /*                pstat(""); */
  128.                 putchar('\n');
  129.                 return;
  130.             case XON:
  131.                 if(Tfile && !Txgo) {
  132.                     Txgo=TRUE;
  133.                     sayterm();
  134.                 }
  135.                 break;
  136.             case XOFF:
  137.                 if(Tfile && Txgo) {
  138.                     Txgo=FALSE;
  139.                     sayterm();
  140.                 }
  141.                 break;
  142.             case 'v'&037:
  143.                 if(moment(KTIME2))
  144.                     break;
  145.                 replot(TLENGTH<<1);
  146.                 sayterm();
  147.                 continue;
  148.             case '\r':
  149.                 if(Hdx)
  150.                     printf("\n");
  151.                 if(Chat)
  152.                     sendline('\n');
  153.                 break;
  154.             default:
  155.                 break;
  156.             }
  157.             sendline(cfast);
  158.             if(Hdx) {
  159.                 sendcon(cfast);
  160.             }
  161.             continue;
  162.         }
  163.         MODEMON
  164.         if(MOREADY) {
  165.             if(Tfile && !Txwait && !Waitecho && Txgo) {
  166.                 c= getc(fin);
  167. #ifdef CPM
  168.                 if(c==EOF || (c==CPMEOF && Txeoln != TX_BINARY))
  169. #else
  170.                 if(c==EOF)
  171. #endif
  172.                 {
  173.                     closetx(FALSE);
  174. #ifdef XMODEM
  175. /*                    pstat(""); */
  176.                     return;
  177. #else
  178.                     if(Exoneof)
  179.                         return;
  180.                     sayterm();
  181. #endif
  182.                 }
  183. offwithit:
  184.                 if(Waitbunch && ++charsent==Waitnum) {
  185.                     charsent=0;
  186.                     if(Waitnum>1) {
  187.                         Waitecho=TRUE;
  188.                         Timeout=0;
  189.                     } else {
  190.                         Txwait=TRUE;
  191.                         Txtimeout=Throttle;
  192.                     }
  193.                 }
  194.  
  195.                 if(c=='\r') {    /* end of line processing */
  196.                     switch(Txeoln) {
  197.                     case EOL_NL:
  198.                         continue;
  199.                     case EOL_CRPROMPT:
  200.                     case EOL_CRWAIT:
  201.                         Waitecho=TRUE;
  202.                         Timeout=0;
  203.                     case EOL_CR:
  204.                         if(Tfile) {
  205.                             if((cc=getc(fin))!='\n')
  206.                                 ungetc(cc, fin);
  207.                         }
  208.                         else if(*++abptr != '\n')
  209.                             --abptr;
  210.                         break;
  211.                     }
  212.                 }
  213.                 sendline(c);
  214.                 continue;
  215.             }
  216.             if(abptr && !Txwait && !Waitecho && Txgo) {
  217.                 if(abptr>=abend) {
  218.                     abptr=NULL;
  219.                     if(Exoneof)
  220.                         return;
  221.                 }
  222.                 else {
  223.                     c= *abptr++;
  224. #ifdef LOOPBACKNONO
  225.                     if(index(c, LOOPBACKNONO))
  226.                         continue;
  227. #endif
  228.                     goto offwithit;
  229.                 }
  230.             }
  231.         }
  232.         if(++Timeout == Tpause) {
  233.             Waitecho=FALSE;
  234. belch:
  235.             if(Xoffflg) {
  236.                 dumprxbuff();
  237.                 MODEMON
  238.                 if(MIREADY) {
  239.                     lpstat("\007OVERRUN: DATA LOST");
  240.                     if(Low<1000)
  241.                         return;
  242.                 }
  243.                 if(bufcdq != bufcq)
  244.                     continue;
  245.                 if(Pflag && bufpcdq != bufcq)
  246.                     continue;
  247.                 Free=Bufsize-1;
  248.                 Xoffflg=FALSE;
  249.                 sendline(XON);
  250.             }
  251. #ifdef CDO
  252.             MODEMON
  253.             if(CDO) {
  254.                 pstat("Carrier Lost");
  255.                 return;
  256.             }
  257. #endif
  258.         }
  259.         if(--Txtimeout==0)
  260.             Txwait=FALSE;
  261.     }
  262. }
  263.  
  264. /* display the appropriate status information */
  265. sayterm()
  266. {
  267. #ifdef TERMRESET
  268.     lprintf(TERMRESET);
  269. #endif
  270.     if(Tfile)
  271.         lpstat("Sending '%s' %s", Tname, Txgo?"":"Stopped by XOFF");
  272.     if(Rfile)
  273.         pstat("Term Receiving '%s'", Rname);
  274.     else
  275.         pstat("Term Function");
  276. }
  277.  
  278. /* open a capture file and set the removal pointer to get max goods */
  279. opencapt(name)
  280. char *name;
  281. {
  282.     dumprxbuff();
  283.     closerx(TRUE);
  284.     if(openrx(name)==ERROR)
  285.         return ERROR;
  286.     if(buffcdq<bufst)
  287.         buffcdq=bufst;
  288.     if(Wrapped)
  289.         buffcdq=bufcq+1;
  290.     if(buffcdq >= bufend)
  291.         buffcdq=bufst;
  292. /*    dumprxbuff(); */
  293. }
  294.  
  295. dumprxbuff()
  296. {
  297.     register c;
  298.  
  299.     if(!Rfile || buffcdq==NULL)
  300.         return OK;
  301.     while(buffcdq != bufcq) {
  302.         c= *buffcdq++;
  303.         if(buffcdq >= bufend)
  304.             buffcdq=bufst;
  305.         if(!Image) {
  306.             switch(c &= 0177) {
  307.              case 0:
  308.                  continue;
  309.             case 032:        /* ^Z or CPMEOF */
  310.                 if(Zeof) {
  311.                     closerx(TRUE);
  312.                     return;
  313.                 }
  314.                 else
  315. #ifdef CPM
  316.                     continue;
  317. #else
  318.                     break;
  319. #endif
  320.             case 022:
  321.                 if(Squelch) {
  322.                     Dumping=TRUE;
  323.                     continue;
  324.                 }
  325.                 break;
  326.             case 024:
  327.                 if(Squelch) {
  328.                     Dumping=FALSE;
  329.                     continue;
  330.                 }
  331.                 break;
  332.             default:
  333.                 break;
  334.             }
  335.         }
  336.         if(Dumping || Image)
  337.             if(putc(c, fout)==ERROR) {
  338.                 printf("\nDisk Full\n");
  339.                 closerx(FALSE);
  340.                 return ERROR;
  341.             }
  342.     }
  343.     Free=Bufsize-1;
  344.     return OK;
  345. }
  346.  
  347. rewindcb()
  348. {
  349.     bufcdq=buffcdq=bufpcdq=Wrapped?bufcq+1:bufst;
  350. }
  351.  
  352. /*
  353.  * replot redisplays the buffer contents thru putcty allowing XOFF
  354.  * number will represent how many lines to go back first 
  355.  */
  356. replot(number)
  357. {
  358.     char *s, c;
  359.     int count, shorts;
  360.  
  361. fromtop:
  362.     shorts=0;
  363.     bufmark=Wrapped?bufcq+1:bufst;
  364.  
  365.     if(number) {
  366.         s=bufcq;
  367. backsome:
  368. #ifdef TERMINIT
  369.         /* backing up is confusing unless screen is cleard first */
  370.         lprintf(TERMINIT);
  371. #endif
  372.         for(;;) {
  373.             --s;
  374.             if(s<bufst) {
  375.                 if(Wrapped)
  376.                     s= bufend-1;
  377.                 else {
  378.                     s=bufst;
  379.                     break;
  380.                 }
  381.             }
  382.             if(s==bufcq)
  383.                 break;
  384.             if((*s&0177)=='\n' && --number<=0)
  385.                 break;
  386.         }
  387.         bufmark=s;
  388.     }
  389.     s=bufmark;
  390. nextscreen:
  391. #ifdef T4014
  392.     /* Do the big flash on the 4014 or 4012 */
  393.     printf("\033\014");
  394.     sleep(CLKMHZ * 5);
  395. #endif
  396.     count=TLENGTH - shorts;
  397.     shorts =0;
  398. nextline:
  399.     while(s != bufcq) {
  400.         cfast= *s++ & 0177;
  401.         if(s >= bufend)
  402.             s=bufst;
  403.         if(c=putcty(cfast))
  404.             goto choose;
  405.         if(cfast=='\r' && --count<=0)
  406.             break;
  407.     }
  408.  
  409. #ifdef STATLINE
  410.     pstat("Replot cmd?");
  411. #endif
  412.     c=getcty();
  413. #ifdef STATLINE
  414. /*    pstat(""); */
  415. #endif
  416. choose:
  417. /* Treat Control chars and letters the same */
  418.     switch((c|0140)&0177) {
  419.     case 'b':
  420.         number=0;
  421.         goto fromtop;
  422.     case 'v':    /* control-v or v */
  423.     case 'h':    /* backspace */
  424.         number=TLENGTH-2;
  425.         s=bufmark;
  426.         goto backsome;
  427.     case 0140:        /* space bar */
  428.         shorts=2;
  429.         bufmark=s;
  430.         goto nextscreen;
  431.     case 'p':
  432.         number=1;
  433.         s=bufmark;
  434.         goto backsome;
  435.     case 'n':
  436.     case 'j':    /* linefeed */
  437.         bufmark=s;
  438.         count=1;
  439.         goto nextline;
  440.     default:
  441.         return;
  442.     }
  443. }
  444.  
  445. chat()
  446. {
  447. #ifdef XMODEM
  448.     printf("Ring My Chimes, Maybe I'll Come\n");
  449.     printf("Exit chat with ^Z\n");
  450. #endif
  451.     Chat=Ctlview=Hdx=Echo=TRUE;
  452.     term();
  453. }
  454.  
  455. /* end of YAM3.C */
  456.