home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: DFÜ und Kommunikation / SOS-DFUE.ISO / programm / dos / utility / pccp076 / term.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-10  |  17.7 KB  |  868 lines

  1. /*    Copyright (C) 1992 Peter Edward Cann, all rights reserved.
  2.  */
  3.  
  4. #include<stdio.h>
  5. #include<bios.h>
  6. #include<dos.h>
  7. #include<fcntl.h>
  8. #include<graph.h>
  9. #include"emu.h"
  10. #include"color.h"
  11. #include"port.h"
  12.  
  13.  
  14. unsigned long tick;
  15.  
  16. void (interrupt far *oldtick)();
  17.  
  18. void interrupt far tickhndl()
  19.     {
  20.     tick++;
  21.     }
  22.  
  23. int locechop;
  24.  
  25. sendraw(str)
  26.     char *str;
  27.     {
  28.     int i;
  29.     i=0;
  30.     while(str[i])
  31.         {
  32.         while(!(inp(basereg+STATREG)&TXMTMASK));
  33.         outp(basereg, str[i++]);
  34.         }
  35.     }
  36.  
  37. dispkbd(code)
  38.     unsigned short code;
  39.     {
  40.     int i;
  41.     unsigned char ccode, scode;
  42.     ccode=code&0xff;
  43.     scode=(code>>8)&0xff;
  44.     if(ccode)
  45.         {
  46.         while(!(inp(basereg+STATREG)&TXMTMASK));
  47.         if(locechop)
  48.             dispport(ccode);
  49.         outp(basereg, code);
  50.         }
  51.     else
  52.         if(!emu.keys[scode].len)
  53.             putch(0x07);
  54.         else
  55.             for(i=0;i<emu.keys[scode].len;i++)
  56.                 {
  57.                 while(!(inp(basereg+STATREG)&TXMTMASK));
  58.                 if(emu.keys[scode].nullpause_p&&!emu.keys[scode].chars[i])
  59.                     {
  60.                     tick=0L;
  61.                     while(1)
  62.                         {
  63.                         if(tick>22)
  64.                             break;
  65.                         }
  66.                     }
  67.                 else if(emu.keys[scode].nullpause_p&&(emu.keys[scode].chars[i]==0xff))
  68.                     {
  69.                     tick=0L;
  70.                     outp(basereg+LCTLREG, lctl|0x40);
  71.                     while(1)
  72.                         {
  73.                         if(tick>10)
  74.                             break;
  75.                         }
  76.                     outp(basereg+LCTLREG, lctl);
  77.                     }
  78.                 else
  79.                     {
  80.                     if(locechop)
  81.                         dispport(emu.keys[scode].chars[i]);
  82.                     outp(basereg, emu.keys[scode].chars[i]);
  83.                     }
  84.                 }
  85.     }
  86.  
  87. #define LISTSIZ 16
  88.  
  89. struct
  90.     {
  91.     short index;
  92.     short row;
  93.     char rowset;
  94.     short column;
  95.     char colset;
  96.     short list[LISTSIZ];
  97.     short listindex;
  98.     }
  99.     funcstor[NFUNCS];
  100.  
  101. clrfuncstor(seqn)
  102.     short seqn;
  103.     {
  104.     int i;
  105.     if(funcstor[seqn].listindex==LISTSIZ)
  106.         funcstor[seqn].listindex--;
  107.     for(i=funcstor[seqn].listindex;i>=0;i--)
  108.         funcstor[seqn].list[i]=0;
  109.     funcstor[seqn].row=funcstor[seqn].column=funcstor[seqn].listindex=funcstor[seqn].index=funcstor[seqn].rowset=funcstor[seqn].colset=0;
  110.     }
  111.  
  112. int bold, faint, blink, inverse, bkcolor, fgcolor;
  113. struct videoconfig far *vconf;
  114.  
  115. atthndl()
  116.     {
  117.     int adds, workingbk, workingfg;
  118.     adds=0;
  119.     if((vconf->adapter!=_MDPA)&&(vconf->adapter!=_HGC))
  120.         {
  121.         /* Color Adapter */
  122.         workingbk=bkcolor;
  123.         workingfg=fgcolor;
  124.         if(faint&&(fgcolor==WHITE))
  125.             workingfg=GRAY;
  126.         if(bold)
  127.             adds+=BOLDADD;
  128.         if(blink)
  129.             adds+=BLINKADD;
  130.         if(inverse)
  131.             {
  132.             _settextcolor(workingbk+adds);
  133.             _setbkcolor((long)(workingfg&0x07));
  134.             }
  135.         else
  136.             {
  137.             _settextcolor(workingfg+adds);
  138.             _setbkcolor((long)(workingbk&0x07));
  139.             }
  140.         }
  141.     else
  142.         {
  143.         workingbk=BLACK;
  144.         if(bold&&!inverse)
  145.             workingfg=M_UNDER;
  146.         else
  147.             if(inverse)
  148.                 workingfg=WHITE;
  149.             else
  150.                 workingfg=M_NORMAL;
  151.         if(faint)
  152.             if(inverse)
  153.                 if(bkcolor!=BLACK)
  154.                     adds+=FAINTADD;
  155.                 else;
  156.             else
  157.                 if(fgcolor!=BLACK)
  158.                     adds+=FAINTADD;
  159.         if(blink)
  160.             adds+=BLINKADD;
  161.         if(inverse)
  162.             {
  163.             _settextcolor(workingbk+adds);
  164.             _setbkcolor((long)(workingfg&0x07));
  165.             }
  166.         else
  167.             {
  168.             _settextcolor(workingfg+adds);
  169.             _setbkcolor((long)(workingbk&0x07));
  170.             }
  171.         }
  172.     }
  173.  
  174.  
  175. ansiatthndl(seqn)
  176.     short seqn;
  177.     {
  178.     int i, adds, workingbk, workingfg;
  179.     if(emu.funcs[seqn].func==ANSIATTRIB)
  180.         for(i=0;i<funcstor[seqn].listindex;i++)
  181.             switch(funcstor[seqn].list[i])
  182.                 {
  183.                 /*at the moment this is strictly ANSI subset*/
  184.                 case 0:
  185.                     bkcolor=BLACK;
  186.                     fgcolor=WHITE;
  187.                     bold=faint=blink=inverse=0;
  188.                     break;
  189.                 case 1:
  190.                     bold=1;
  191.                     break;
  192.                 case 2:
  193.                     faint=1;
  194.                     break;
  195.                 case 5:
  196.                 case 6:
  197.                     blink=1;
  198.                     break;
  199.                 case 7:
  200.                     inverse=1;
  201.                     break;
  202.                 case 30:
  203.                     fgcolor=BLACK;
  204.                     break;
  205.                 case 31:
  206.                     fgcolor=RED;
  207.                     break;
  208.                 case 32:
  209.                     fgcolor=GREEN;
  210.                     break;    
  211.                 case 33:
  212.                     fgcolor=YELLOW;
  213.                     break;
  214.                 case 34:
  215.                     fgcolor=BLUE;
  216.                     break;
  217.                 case 35:
  218.                     fgcolor=MAGENTA;
  219.                     break;
  220.                 case 36:
  221.                     fgcolor=CYAN;
  222.                     break;
  223.                 case 37:
  224.                     fgcolor=WHITE;
  225.                     break;
  226.                 case 40:
  227.                     bkcolor=BLACK;
  228.                     break;
  229.                 case 41:
  230.                     bkcolor=RED;
  231.                     break;
  232.                 case 42:
  233.                     bkcolor=GREEN;
  234.                     break;    
  235.                 case 43:
  236.                     bkcolor=YELLOW;
  237.                     break;
  238.                 case 44:
  239.                     bkcolor=BLUE;
  240.                     break;
  241.                 case 45:
  242.                     bkcolor=MAGENTA;
  243.                     break;
  244.                 case 46:
  245.                     bkcolor=CYAN;
  246.                     break;
  247.                 case 47:
  248.                     bkcolor=WHITE;
  249.                     break;
  250.                 default:
  251.                     break;
  252.                 }
  253.     atthndl();
  254.     }
  255.  
  256. int wrap_p;
  257.  
  258. wrapctl()
  259.     {
  260.     if(wrap_p)
  261.         _wrapon(_GWRAPON);
  262.     else
  263.         _wrapon(_GWRAPOFF);
  264.     }
  265.  
  266. char emupname[256], emubname[13], dribpname[256];
  267.  
  268. updstatus()
  269.     {
  270.     struct rccoord posptr;
  271.     short tc;
  272.     long bc;
  273.     char str[81];
  274.     posptr=_gettextposition();
  275.     tc=_gettextcolor();
  276.     bc=_getbkcolor();
  277.     _settextwindow(1,1,1,80);
  278.     _settextcolor(BLACK);
  279.     _setbkcolor((long)WHITE);
  280.     _clearscreen(_GWINDOW);
  281.     _wrapon(_GWRAPOFF);
  282.     sprintf(str, " Ctrl-Alt-Shift to Exit  COM%u %5u %c%c%c %8s %30s",
  283.         comnum+1, speed, databits, parity, stopbits, emubname, dribpname);
  284.     _outtext(str);
  285.     _settextwindow(2,1,25,80);
  286.     wrapctl();
  287.     _settextcolor(tc);
  288.     _setbkcolor(bc);
  289.     _settextposition(posptr.row, posptr.col);
  290.     }
  291.  
  292. int graphics;
  293.  
  294. showchar(c)
  295.     unsigned char c;
  296.     {
  297.     unsigned char str[2];
  298.     if(graphics)
  299.         if(emu.gchars[c])
  300.             c=emu.gchars[c];
  301.     str[0]=c;
  302.     str[1]='\0';
  303.     _outtext(str);
  304.     }
  305.  
  306. int savedrow, savedcol;
  307.  
  308. perffunc(seqn)
  309.     short seqn;
  310.     {
  311.     char str[64];
  312.     struct rccoord posptr;
  313.     int i;
  314.     switch(emu.funcs[seqn].func)
  315.         {
  316.         case CLEAR:
  317.             _clearscreen(_GWINDOW);
  318.             _settextposition(1,1);
  319.             break;
  320.         case HOME:
  321.             _settextposition(1,1);
  322.             break;
  323.         case CLREOL:
  324.             posptr=_gettextposition();
  325.             _wrapon(_GWRAPOFF);
  326.             for(i=posptr.col;i<=80;i++)
  327.                 _outtext(" ");
  328.             _settextposition(posptr.row, posptr.col);
  329.             wrapctl();
  330.             break;
  331.         case UP:
  332.             posptr=_gettextposition();
  333.             if(posptr.row>1)
  334.                 _settextposition(posptr.row-1, posptr.col);
  335.             break;
  336.         case DOWN:
  337.             posptr=_gettextposition();
  338.             if(posptr.row<24)
  339.                 _settextposition(posptr.row+1, posptr.col);
  340.             else
  341.                 {
  342.                 showchar('\n');
  343.                 _settextposition(posptr.row, posptr.col);
  344.                 }
  345.             break;
  346.         case LEFT:
  347.             posptr=_gettextposition();
  348.             if(posptr.col>1)
  349.                 _settextposition(posptr.row, posptr.col-1);
  350.             break;
  351.         case RIGHT:
  352.             posptr=_gettextposition();
  353.             if(posptr.col<80)
  354.                 _settextposition(posptr.row, posptr.col+1);
  355.             break;
  356.         case GOTO:
  357.             funcstor[seqn].row-=(emu.firstrowaddr-1);
  358.             funcstor[seqn].column-=(emu.firstcoladdr-1);
  359.             if(funcstor[seqn].row<1)
  360.                 funcstor[seqn].row=1;
  361.             if(funcstor[seqn].row>24)
  362.                 funcstor[seqn].row=24;
  363.             if(funcstor[seqn].column<1)
  364.                 funcstor[seqn].column=1;
  365.             if(funcstor[seqn].column>80)
  366.                 funcstor[seqn].row=80;
  367.             _settextposition((emu.tophi_p?25-funcstor[seqn].row:funcstor[seqn].row), funcstor[seqn].column);
  368.             break;
  369.         case NORMAL:
  370.             fgcolor=WHITE;
  371.             bkcolor=BLACK;
  372.             blink=faint=bold=inverse=0;
  373.             atthndl();
  374.             break;
  375.         case BLINK:
  376.             blink=1;
  377.             atthndl();
  378.             break;
  379.         case NOBLINK:
  380.             blink=0;
  381.             atthndl();
  382.             break;
  383.         case BOLD:
  384.             bold=1;
  385.             atthndl();
  386.             break;
  387.         case NOBOLD:
  388.             bold=0;
  389.             atthndl();
  390.             break;
  391.         case FAINT:
  392.             faint=1;
  393.             atthndl();
  394.             break;
  395.         case NOFAINT:
  396.             faint=0;
  397.             atthndl();
  398.             break;
  399.         case INVERSE:
  400.             inverse=1;
  401.             atthndl();
  402.             break;
  403.         case NOINVERSE:
  404.             inverse=0;
  405.             atthndl();
  406.             break;
  407.         case UPN:
  408.             posptr=_gettextposition();
  409.             if(posptr.row-funcstor[seqn].row<1)
  410.                 _settextposition(1, posptr.col);
  411.             else
  412.                 _settextposition(posptr.row-funcstor[seqn].row, posptr.col);
  413.             break;
  414.         case DOWNN:
  415.             posptr=_gettextposition();
  416.             if(posptr.row+funcstor[seqn].row>24)
  417.                 {
  418.                 _settextposition(24,1);
  419.                 for(i=25-(posptr.row+funcstor[seqn].row);i<0;++i)
  420.                     showchar('\n');
  421.                 _settextposition(24, posptr.col);
  422.                 }
  423.             else
  424.                 _settextposition(posptr.row+funcstor[seqn].row, posptr.col);
  425.             break;
  426.         case LEFTN:
  427.             posptr=_gettextposition();
  428.             if(posptr.col-funcstor[seqn].column<1)
  429.                 _settextposition(posptr.row, 1);
  430.             else
  431.                 _settextposition(posptr.row, posptr.col-funcstor[seqn].column);
  432.             break;
  433.         case RIGHTN:
  434.             posptr=_gettextposition();
  435.             if(posptr.col+funcstor[seqn].column>80)
  436.                 _settextposition(posptr.row, 80);
  437.             else
  438.                 _settextposition(posptr.row, posptr.col+funcstor[seqn].column);
  439.             break;
  440.         case ANSIATTRIB:
  441.             ansiatthndl(seqn);
  442.             break;
  443.         case WRAP:
  444.             wrap_p=1;
  445.             wrapctl();
  446.             break;
  447.         case NOWRAP:
  448.             wrap_p=0;
  449.             wrapctl();
  450.             break;
  451.         case GOTOLINE:
  452.             funcstor[seqn].row-=(emu.firstrowaddr-1);
  453.             posptr=_gettextposition();
  454.             if(funcstor[seqn].row<1)
  455.                 funcstor[seqn].row=1;
  456.             if(funcstor[seqn].row>24)
  457.                 funcstor[seqn].row=24;
  458.             _settextposition(emu.tophi_p?25-funcstor[seqn].row:funcstor[seqn].row, 1);
  459.             break;
  460.         case GOTOCOL:
  461.             funcstor[seqn].column-=(emu.firstcoladdr-1);
  462.             posptr=_gettextposition();
  463.             if(funcstor[seqn].column<1)
  464.                 funcstor[seqn].column=1;
  465.             if(funcstor[seqn].column>80)
  466.                 funcstor[seqn].row=80;
  467.             _settextposition(posptr.row, funcstor[seqn].column);
  468.             break;
  469.         case BINATTR:
  470.             if((funcstor[seqn].row-emu.attroffset)&emu.blinkmask)
  471.                 blink=1;
  472.             else
  473.                 blink=0;
  474.             if((funcstor[seqn].row-emu.attroffset)&emu.inversemask)
  475.                 inverse=1;
  476.             else
  477.                 inverse=0;
  478.             if((funcstor[seqn].row-emu.attroffset)&emu.boldmask)
  479.                 bold=1;
  480.             else
  481.                 bold=0;
  482.             if((funcstor[seqn].row-emu.attroffset)&emu.faintmask)
  483.                 faint=1;
  484.             else
  485.                 faint=0;
  486.             atthndl();
  487.             break;
  488.         case GRAPHCHAR:
  489.             showchar(emu.gchars[funcstor[seqn].row]);
  490.             break;
  491.         case BEGGRAPH:
  492.             graphics=1;
  493.             break;
  494.         case ENDGRAPH:
  495.             graphics=0;
  496.             break;
  497.         case TAB:
  498.             posptr=_gettextposition();
  499.             _settextposition(posptr.row, posptr.col+(8-((posptr.col-1)%8)));
  500.             break;
  501.         case BELL:
  502.             putch(7);
  503.             break;
  504.         case DTAB:
  505.             posptr=_gettextposition();
  506.             for(i=0;i<(8-((posptr.col-1)%8));++i)
  507.                 _outtext(" ");
  508.  
  509.         case CRLF:
  510.             showchar('\n');
  511.             break;
  512.         case SAVEPOS:
  513.             posptr=_gettextposition();
  514.             savedrow=posptr.row;
  515.             savedcol=posptr.col;
  516.             break;
  517.         case RESTOREPOS:
  518.             _settextposition(savedrow, savedcol);
  519.             break;
  520.         case RESPOND:
  521.             dispkbd(0x0000); /* Macro for scancode 0 */
  522.             break;
  523.         case ANSICPR:
  524.             posptr=_gettextposition();
  525.             sprintf(str, "\033[%d;%dR", posptr.row, posptr.col);
  526.             sendraw(str);
  527.             break;
  528.         default:
  529.             break;
  530.         }
  531.     }
  532.  
  533. int foundfuncs;
  534.  
  535. dispport(c)
  536.     unsigned char c;
  537.     {
  538.     int seqn, done, ok;
  539.     done=0;
  540.     ok=0;
  541.     for(seqn=0;seqn<foundfuncs;seqn++)
  542.         {
  543.         if(emu.funcs[seqn].codes[funcstor[seqn].index]&0xff00)
  544.             switch(emu.funcs[seqn].codes[funcstor[seqn].index])
  545.                 {
  546.                 case END:
  547.                     if(funcstor[seqn].index)
  548.                         {
  549.                         done=1;
  550.                         perffunc(seqn);
  551.                         }
  552.                     break;
  553.                 case BINCOL:
  554.                     funcstor[seqn].column=c-emu.bincoloff;
  555.                     ok=1;
  556.                     if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  557.                         {
  558.                         done=1;
  559.                         perffunc(seqn);
  560.                         }
  561.                     break;
  562.                 case BINROW:
  563.                     funcstor[seqn].row=c-emu.binrowoff;
  564.                     ok=1;
  565.                     if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  566.                         {
  567.                         done=1;
  568.                         perffunc(seqn);
  569.                         }
  570.                     break;
  571.                 case ASCDECCOL:
  572.                     if((c>='0')&&(c<='9'))
  573.                         {
  574.                         ok=1;
  575.                         funcstor[seqn].column*=10;
  576.                         funcstor[seqn].column+=(c-'0');
  577.                         funcstor[seqn].colset=1;
  578.                         }
  579.                     else
  580.                         if(funcstor[seqn].colset&&(c==emu.funcs[seqn].codes[++funcstor[seqn].index]))
  581.                             {
  582.                             ok=1;
  583.                             if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  584.                                 {
  585.                                 done=1;
  586.                                 perffunc(seqn);
  587.                                 }
  588.                             }
  589.                         else
  590.                             clrfuncstor(seqn);
  591.                     break;
  592.                 case ASCDECROW:
  593.                     if((c>='0')&&(c<='9'))
  594.                         {
  595.                         ok=1;
  596.                         funcstor[seqn].row*=10;
  597.                         funcstor[seqn].row+=(c-'0');
  598.                         funcstor[seqn].rowset=1;
  599.                         }
  600.                     else
  601.                         if(funcstor[seqn].rowset&&(c==emu.funcs[seqn].codes[++funcstor[seqn].index]))
  602.                             {
  603.                             ok=1;
  604.                             if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  605.                                 {
  606.                                 done=1;
  607.                                 perffunc(seqn);
  608.                                 }
  609.                             }
  610.                         else
  611.                             clrfuncstor(seqn);
  612.                     break;
  613.                 case ASCDECSEMILIST:
  614.                     if((c>='0')&&(c<='9')&&(funcstor[seqn].listindex<LISTSIZ))
  615.                         {
  616.                         ok=1;
  617.                         funcstor[seqn].list[funcstor[seqn].listindex]*=10;
  618.                         funcstor[seqn].list[funcstor[seqn].listindex]+=(c-'0');
  619.                         }
  620.                     else
  621.                         {
  622.                         if(funcstor[seqn].listindex<LISTSIZ)
  623.                             funcstor[seqn].listindex++;
  624.                         
  625.                         if(c==';')
  626.                             ok=1;
  627.                         else
  628.                             if(c==emu.funcs[seqn].codes[++funcstor[seqn].index])
  629.                                 {
  630.                                 ok=1;
  631.                                 if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  632.                                     {
  633.                                     done=1;
  634.                                     perffunc(seqn);
  635.                                     }
  636.                                 }
  637.                             else
  638.                                 clrfuncstor(seqn);
  639.                         }
  640.                     break;
  641.                 case GRABCHAR:
  642.                     ok=1;
  643.                     funcstor[seqn].row=c;
  644.                     if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  645.                         {
  646.                         done=1;
  647.                         perffunc(seqn);
  648.                         }
  649.                     break;
  650.                 case GRAPHCHAR_T:
  651.                     if(emu.gchars[c])
  652.                         {
  653.                         ok=1;
  654.                         funcstor[seqn].row=c;
  655.                         if(emu.funcs[seqn].codes[funcstor[seqn].index]==END)
  656.                             {
  657.                             done=1;
  658.                             perffunc(seqn);
  659.                             }
  660.                         }
  661.                     else
  662.                         clrfuncstor(seqn);
  663.                     break;
  664.                 }
  665.         else
  666.             if(c==emu.funcs[seqn].codes[funcstor[seqn].index])
  667.                 {
  668.                 ok=1;
  669.                 if(emu.funcs[seqn].codes[++funcstor[seqn].index]==END)
  670.                     {
  671.                     done=1;
  672.                     perffunc(seqn);
  673.                     }
  674.                 }
  675.             else
  676.                 clrfuncstor(seqn);
  677.         if(done)
  678.             {
  679.             ok=1;
  680.             for(seqn=0;seqn<foundfuncs;seqn++)
  681.                 clrfuncstor(seqn);
  682.             break;
  683.             }
  684.         }
  685.     if(!ok)
  686.         showchar(c);
  687.     }
  688.  
  689. initdisp()
  690.     {
  691.     int i;
  692.     for(i=0;i<foundfuncs;i++)
  693.         {
  694.         funcstor[i].listindex=LISTSIZ;
  695.         clrfuncstor(i);
  696.         }
  697.     bold=faint=blink=inverse=0;
  698.     fgcolor=WHITE;
  699.     bkcolor=BLACK;
  700.     graphics=0;
  701.     wrap_p=emu.default_wrap_p;
  702.     }
  703.  
  704. main(argc, argv)
  705.     int argc;
  706.     char **argv;
  707.     {
  708.     FILE *dribble;
  709.     int follow, emufd, i, j, orun;
  710.     if(!strcmp(getenv("REMOTE"), "YES"))
  711.         {
  712.         printf("You appear to be logged in remotely, judging by the environment\n");
  713.         printf("variable REMOTE, so this is probably a very bad idea.\n");
  714.         printf("Are you sure you want to run TERM? (y or n) --> ");
  715.         if(getchar()!='y') /* Note getchar() and not getch()! */
  716.             {
  717.             printf("I didn't think so!\n");
  718.             exit(99);
  719.             }
  720.         else
  721.             printf("OK, you're the boss!\n");
  722.         }
  723.     _getvideoconfig(vconf);
  724.     _setvideomode(_DEFAULTMODE);
  725.     index=follow=0;
  726.     if((argc<4)||(argc>6))
  727.         {
  728.         printf("Copyright (C) 1992 Peter Edward Cann, all rights reserved.\n");
  729.         printf("USAGE: term <comnum> <bps> <data><parity><stop> [<emu or - >] [<dribble>]\n");
  730.         printf("<emu> is an emulation file base pathname.\n");
  731.         printf("<dribble> is a dribble (text capture) file.\n");
  732.         printf("The environment variable PCCPPATH is used for the emulation file if set.\n");
  733.         exit(1);
  734.         }
  735.     emupname[0]='\0';
  736.     dribpname[0]='\0';
  737.     if((argc>=5)&&(argv[4][0]=='+'))
  738.         {
  739.         locechop=1;
  740.         argv[4]++;
  741.         }
  742.     else
  743.         locechop=0;
  744.     if((argc>=5)&&(argv[4][0]!='-'))
  745.         {
  746.         if((getenv("PCCPPATH")==NULL)||(argv[4][0]=='\\')||(argv[4][0]&&(argv[4][1]==':'))||(argv[4][0]=='.'))
  747.             sprintf(emupname, "%s.emu", argv[4]);
  748.         else
  749.             sprintf(emupname, "%s\\%s.emu", getenv("PCCPPATH"), argv[4]);
  750.         if((emufd=open(emupname, O_RDONLY|O_BINARY))==-1)
  751.             {
  752.             printf("Error opening emulation file %s.\n", emupname);
  753.             exit(2);
  754.             }
  755.         else
  756.             if(read(emufd, &emu, sizeof(emu))!=sizeof(emu))
  757.                 {
  758.                 printf("Error reading emulation file %s.\n", emupname);
  759.                 exit(3);
  760.                 }
  761.             else;
  762.         for(i=strlen(argv[4]);(i>=0)&&(argv[4][i]!='\\')&&(argv[4][i]!=':');i--);
  763.         i++;
  764.         for(j=0;argv[4][i];i++,j++)
  765.             emubname[j]=argv[4][i];
  766.         emubname[j]='\0';
  767.         }
  768.     else
  769.         {
  770.         strcpy(emubname, "-");
  771.         nullemu();
  772.         emu.funcs[0].func=LEFT;
  773.         emu.funcs[0].codes[0]='\b';
  774.         emu.funcs[0].codes[1]=END;
  775.         emu.funcs[1].func=DTAB;
  776.         emu.funcs[1].codes[0]='\t';
  777.         emu.funcs[1].codes[1]=END;
  778.         emu.funcs[2].func=BELL;
  779.         emu.funcs[2].codes[0]='\007';
  780.         emu.funcs[2].codes[1]=END;
  781.         }
  782.     for(foundfuncs=NFUNCS;foundfuncs>=0;foundfuncs--)
  783.         if(emu.funcs[foundfuncs].func!=NOOP)
  784.             break;
  785.     foundfuncs++;
  786.     if(argc==6)
  787.         {
  788.         strcpy(dribpname, argv[5]);
  789.         if((dribble=fopen(argv[5], "a"))==NULL)
  790.             {
  791.             printf("Couldn't open dribble file %s.\n");
  792.             exit(10);
  793.             }
  794.         else
  795.             {
  796.             setmode(fileno(dribble), O_BINARY);
  797.             fprintf(dribble, "\r\nBeginning of dribble segment.\r\n\n");
  798.             }
  799.         }
  800.     else
  801.         {
  802.         strcpy(dribpname, "-");
  803.         dribble=NULL;
  804.         }
  805.     oldtick=_dos_getvect(0x1c);
  806.     _dos_setvect(0x1c, tickhndl);
  807.     comnum=atoi(argv[1])-1;
  808.     speed=atoi(argv[2]);
  809.     parity=argv[3][1];
  810.     databits=argv[3][0];
  811.     stopbits=argv[3][2];
  812.     setport();
  813.     readset();
  814.     setup();
  815.     _clearscreen(_GCLEARSCREEN);
  816.     initdisp();
  817.     updstatus();
  818.     atthndl();
  819.     _settextposition(1,1);
  820.     orun=0;
  821.     if(vconf->adapter==_VGA)
  822.         _remappalette(GRAY, (long)0x001a1a1a); /* Lighten up gray */
  823.     while(1)
  824.         {
  825.         if((_bios_keybrd(_KEYBRD_SHIFTSTATUS) & 0x0f)>12)
  826.             {
  827.             cleanup(0);
  828.             _settextcolor(WHITE);
  829.             _setbkcolor((long)BLACK);
  830.             _settextposition(24,1);
  831.             if(dribble!=NULL)
  832.                 {
  833.                 fprintf(dribble, "\r\nEnd of dribble segment.\r\n");
  834.                 fclose(dribble);
  835.                 }
  836.             if(vconf->adapter==_VGA)
  837.                 _remappalette(GRAY, _GRAY); /* Restore gray */
  838.             _dos_setvect(0x1c, oldtick);
  839.             _outtext("\nOrderly exit from TERM.\n");
  840.             exit(0);
  841.             }
  842.         if(_bios_keybrd(_KEYBRD_READY))
  843.             dispkbd(_bios_keybrd(_KEYBRD_READ));
  844.         if(follow!=index)
  845.             {
  846.             if(dribble!=NULL)
  847.                 fputc(buf[follow], dribble);
  848.             /* We only display if we're not too far behind; */
  849.             /* this makes dribble more reliable. */
  850.             if(((index-follow)>4096)||(((index-follow)<0)&&((follow-index)<4096)))
  851.                 if(!orun)
  852.                     {
  853.                     orun=1;
  854.                     initdisp();
  855.                     }
  856.                 else;
  857.             else
  858.                 {
  859.                 orun=0;
  860.                 dispport(buf[follow]);
  861.                 }
  862.             follow++;
  863.             if(follow>=TBUFSIZ)
  864.                 follow=0;
  865.             }
  866.         }
  867.     }
  868.