home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / UTIL / WWIVE / RETURN.C < prev    next >
Text File  |  1991-12-24  |  45KB  |  2,086 lines

  1. /*****************************************************************************
  2.  
  3.                                 WWIV Version 4
  4.                     Copyright (C) 1988-1991 by Wayne Bell
  5.  
  6. Distribution of the source code for WWIV, in any form, modified or unmodified,
  7. without PRIOR, WRITTEN APPROVAL by the author, is expressly prohibited.
  8. Distribution of compiled versions of WWIV is limited to copies compiled BY
  9. THE AUTHOR.  Distribution of any copies of WWIV not compiled by the author
  10. is expressly prohibited.
  11.  
  12.  
  13. *****************************************************************************/
  14.  
  15.  
  16.  
  17. #include <process.h>
  18. #include <math.h>
  19. #include <dir.h>
  20. #include <stdio.h>
  21. #include <io.h>
  22. #include <fcntl.h>
  23. #include <string.h>
  24. #include <stdlib.h>
  25. #include <sys\stat.h>
  26. #include <dos.h>
  27. #include <alloc.h>
  28. #include <time.h>
  29.  
  30.  
  31. #include "vardec.h"
  32.  
  33.  
  34. void far *funcs[25];
  35. /****************************************************************************/
  36.  
  37. void ansic(int n);
  38. unsigned char getkey();
  39. char inkey();
  40. void pausescr();
  41. void backspace();
  42. void nl();
  43. void outstr(char *s);
  44. void outchr(char c);
  45. void checkhangup();
  46. void outcomch(char ch);
  47. long timer1();
  48. void checka(int *abort, int *next);
  49. /****************************************************************************/
  50. char *xenviron[50],newprompt[161];
  51. char ver_no1[51];
  52.  
  53.  
  54. int topline=0,screenbottom=24,tempio,curatr=0x07,lines_listed=0,outcom=0;
  55. int hangup=0,hungup=0,echo=1,lecho=1,input_extern=0,ctc=0,ccc=0;
  56. int defscreenbottom=24;
  57.  
  58. char charbuffer[161]="",endofline[81]="";
  59. int charbufferpointer=0;
  60. int ansiptr=0;
  61.  
  62. int oldx,oldy,flow_control;
  63. char ansistr[81];
  64. int change_color;
  65. userrec thisuser;
  66.  
  67. unsigned int baud_rate;
  68.  
  69. long timelastchar1,hanguptime1;
  70.  
  71. unsigned char andwith=255;
  72.  
  73. char cdir[81];
  74.  
  75.  
  76. volatile int head,tail;
  77. volatile char buffer[max_buf];
  78. int base,async_irq,useron,in_extern,ok_modem_stuff;
  79. int outcom,incom,using_modem,chatting,screenlinest;
  80.  
  81. /****************************************************************************/
  82.  
  83.  
  84. void my_video_int()
  85. {
  86.   static unsigned short sav_bp;
  87.  
  88.   __emit__(0x56, 0x57); /* push si, push di */
  89.   sav_bp = _BP;
  90.   geninterrupt(0x10);
  91.   _BP = sav_bp;
  92.   __emit__(0x5f, 0x5e); /* pop di, pop si */
  93. }
  94.  
  95.  
  96. /****************************************************************************/
  97.  
  98. int okansi()
  99. /* This function checks the status of the current user's record to see if
  100.  * the user has specified that he wants ANSI graphics displayed.
  101.  */
  102. {
  103.   if (thisuser.sysstatus & sysstatus_ansi)
  104.     return(1);
  105.   else
  106.     return(0);
  107. }
  108.  
  109.  
  110. void wait1(long l)
  111. {
  112.   long l1;
  113.  
  114.   l1 = timer1()+l;
  115.  
  116.   enable();
  117.   while (timer1()<l1)
  118.     ;
  119. }
  120.  
  121.  
  122.  
  123.  
  124. #define frequency 500
  125.  
  126. void setbeep(int i)
  127. {
  128.   int i1,i2;
  129.  
  130.   if (i) {
  131.     i1 = 0x34DD / frequency;
  132.     i2 = inportb(0x61);
  133.     if (!(i2 & 0x03)) {
  134.       outportb(0x61, i2 | 0x03);
  135.       outportb(0x43, 0xB6);
  136.     }
  137.     outportb(0x42, i1 & 0x0F);
  138.     outportb(0x42, i1 >> 4);
  139.   } else
  140.     outportb(0x61, inportb(0x61) & 0xFC);
  141. }
  142.  
  143. void pla(char *s, int *abort)
  144. {
  145.   int i,next;
  146.  
  147.   i=0;
  148.   checkhangup();
  149.   if (hangup)
  150.     *abort=1;
  151.   checka(abort,&next);
  152.   while ((s[i]) && (!(*abort))) {
  153.     outchr(s[i++]);
  154.     checka(abort,&next);
  155.   }
  156.   if (!(*abort))
  157.     nl();
  158. }
  159.  
  160.  
  161. void checka(int *abort, int *next)
  162. {
  163.   char ch;
  164.  
  165.   while ((!empty()) && (!(*abort)) && (!hangup)) {
  166.     checkhangup();
  167.     ch=inkey();
  168.     switch(ch) {
  169.       case 14:
  170.         *next=1;
  171.       case 3:
  172.       case 32:
  173.       case 24:
  174.         *abort=1;
  175.         break;
  176.       case 'P':
  177.       case 'p':
  178.       case 19:
  179.         ch=getkey();
  180.         break;
  181.     }
  182.   }
  183. }
  184.  
  185.  
  186.  
  187. void inli(char *s, char *rollover, int maxlen, int crend)
  188. {
  189.   int cp,i,i1,done,cm,begx;
  190.   char s1[255];
  191.   unsigned char ch;
  192.  
  193.   cm=chatting;
  194.  
  195.   begx=wherex();
  196.   if (rollover[0]!=0) {
  197.     if (charbufferpointer) {
  198.       strcpy(s1,rollover);
  199.       strcat(s1,&charbuffer[charbufferpointer]);
  200.       strcpy(&charbuffer[1],s1);
  201.       charbufferpointer=1;
  202.     } else {
  203.       strcpy(&charbuffer[1],rollover);
  204.       charbufferpointer=1;
  205.     }
  206.     rollover[0]=0;
  207.   }
  208.   cp=0;
  209.   done=0;
  210.   do {
  211.     ch=getkey();
  212.     if (cm)
  213.       if (chatting==0)
  214.         ch=13;
  215.     if ((ch>=32)) {
  216.       if ((wherex()<(thisuser.screenchars-1)) && (cp<maxlen)) {
  217.         s[cp++]=ch;
  218.         outchr(ch);
  219.         if (wherex()==(thisuser.screenchars-1))
  220.           done=1;
  221.       } else {
  222.         if (wherex()>=(thisuser.screenchars-1))
  223.           done=1;
  224.       }
  225.     } else
  226.         switch(ch) {
  227.           case 7:
  228.             if ((chatting) && (outcom))
  229.               outcomch(7);
  230.             break;
  231.           case 13: /* C/R */
  232.             s[cp]=0;
  233.             done=1;
  234.             break;
  235.           case 8:  /* Backspace */
  236.             if (cp) {
  237.               if (s[cp-2]==3) {
  238.                 cp-=2;
  239.                 ansic(0);
  240.               } else
  241.                 if (s[cp-1]==8) {
  242.                   cp--;
  243.                   outchr(32);
  244.                 } else {
  245.                   cp--;
  246.                   backspace();
  247.                 }
  248.             }
  249.             break;
  250.           case 24: /* Ctrl-X */
  251.             while (wherex()>begx) {
  252.               backspace();
  253.               cp=0;
  254.             }
  255.             ansic(0);
  256.             break;
  257.           case 23: /* Ctrl-W */
  258.             if (cp) {
  259.               do {
  260.                 if (s[cp-2]==3) {
  261.                   cp-=2;
  262.                   ansic(0);
  263.                 } else
  264.                   if (s[cp-1]==8) {
  265.                     cp--;
  266.                     outchr(32);
  267.                   } else {
  268.                     cp--;
  269.                     backspace();
  270.                   }
  271.               } while ((cp) && (s[cp-1]!=32) && (s[cp-1]!=8) && (s[cp-2]!=3));
  272.             }
  273.             break;
  274.           case 14: /* Ctrl-N */
  275.             if ((wherex()) && (cp<maxlen)) {
  276.               outchr(8);
  277.               s[cp++]=8;
  278.             }
  279.             break;
  280.           case 16: /* Ctrl-P */
  281.             if (cp<maxlen-1) {
  282.               ch=getkey();
  283.               if ((ch>='0') && (ch<='7')) {
  284.                 s[cp++]=3;
  285.                 s[cp++]=ch;
  286.                 ansic(ch-'0');
  287.               }
  288.             }
  289.             break;
  290.           case 9:  /* Tab */
  291.             i=5-(cp % 5);
  292.             if (((cp+i)<maxlen) && ((wherex()+i)<thisuser.screenchars)) {
  293.               i=5-((wherex()+1) % 5);
  294.               for (i1=0; i1<i; i1++) {
  295.                 s[cp++]=32;
  296.                 outchr(32);
  297.               }
  298.             }
  299.             break;
  300.         }
  301.   } while ((done==0) && (hangup==0));
  302.   if (ch!=13) {
  303.     i=cp-1;
  304.     while ((i>0) && (s[i]!=32) && (s[i]!=8) || (s[i-1]==3))
  305.       i--;
  306.     if ((i>(wherex()/2)) && (i!=(cp-1))) {
  307.       i1=cp-i-1;
  308.       for (i=0; i<i1; i++)
  309.         outchr(8);
  310.       for (i=0; i<i1; i++)
  311.         outchr(32);
  312.       for (i=0; i<i1; i++)
  313.         rollover[i]=s[cp-i1+i];
  314.       rollover[i1]=0;
  315.       cp -= i1;
  316.     }
  317.     s[cp++]=1;
  318.     s[cp]=0;
  319.   }
  320.   if (crend)
  321.     nl();
  322.  
  323. }
  324.  
  325.  
  326.  
  327.  
  328. long timer1()
  329. /* This function returns the time, in seconds since midnight. */
  330. {
  331.   unsigned short h,m;
  332.   long l;
  333.  
  334.   m=peek(0x0040,0x006c);
  335.   h=peek(0x0040,0x006e);
  336.   l=((long)h)*65536 + ((long)m);
  337.   return(l);
  338. }
  339.  
  340. #define SCROLL_UP(t,b,l) \
  341.   _CH=t;\
  342.   _DH=b;\
  343.   _BH=curatr;\
  344.   _AL=l;\
  345.   _CL=0;\
  346.   _DL=79;\
  347.   _AH=6;\
  348.   my_video_int();
  349.  
  350. void movecsr(int x,int y)
  351. /* This, obviously, moves the cursor to the location specified, offset from
  352.  * the protected dispaly at the top of the screen
  353.  */
  354. {
  355.   if (x<0)
  356.     x=0;
  357.   if (x>79)
  358.     x=79;
  359.   if (y<0)
  360.     y=0;
  361.   y+=topline;
  362.   if (y>screenbottom)
  363.     y=screenbottom;
  364.  
  365.   _BH=0x00;
  366.   _DH=y;
  367.   _DL=x;
  368.   _AH=0x02;
  369.   my_video_int();
  370. }
  371.  
  372.  
  373.  
  374. int wherex()
  375. /* This function returns the current X cursor position, as the number of
  376.  * characters from the left hand side of the screen.  An X position of zero
  377.  * means the cursor is at the left-most position
  378.  */
  379. {
  380.   _BH=0x00;
  381.   _AH=0x03;
  382.   my_video_int();
  383.   tempio=_DL;
  384.   return(tempio);
  385. }
  386.  
  387.  
  388.  
  389. int wherey()
  390. /* This function returns the Y cursor position, as the line number from
  391.  * the top of the logical window.  The offset due to the protected top
  392.  * of the screen display is taken into account.  A wherey() of zero means
  393.  * the cursor is at the top-most position it can be at.
  394.  */
  395. {
  396.   _BH=0x00;
  397.   _AH=0x03;
  398.   my_video_int();
  399.   tempio=_DH;
  400.   return(tempio-topline);
  401. }
  402.  
  403.  
  404.  
  405. void lf()
  406. /* This function performs a linefeed to the screen (but not remotely) by
  407.  * either moving the cursor down one line, or scrolling the logical screen
  408.  * up one line.
  409.  */
  410. {
  411.   _BH=0x00;
  412.   _AH=0x03;
  413.   my_video_int();
  414.   tempio=_DL;
  415.   if (_DH==screenbottom) {
  416.     SCROLL_UP(topline,screenbottom,1);
  417.     _DL=tempio;
  418.     _DH=screenbottom;
  419.     _BH=0;
  420.     _AH=0x02;
  421.     my_video_int();
  422.   } else {
  423.     tempio=_DH+1;
  424.     _DH=tempio;
  425.     _AH=0x02;
  426.     my_video_int();
  427.   }
  428. }
  429.  
  430.  
  431.  
  432. void cr()
  433. /* This short function returns the local cursor to the left-most position
  434.  * on the screen.
  435.  */
  436. {
  437.   _BH=0x00;
  438.   _AH=0x03;
  439.   my_video_int();
  440.   _DL=0x00;
  441.   _AH=2;
  442.   my_video_int();
  443. }
  444.  
  445. void clrscrb()
  446. /* This clears the local logical screen */
  447. {
  448.   SCROLL_UP(topline,screenbottom,0);
  449.   movecsr(0,0);
  450.   lines_listed=0;
  451. }
  452.  
  453.  
  454.  
  455. void bs()
  456. /* This function moves the cursor one position to the left, or if the cursor
  457.  * is currently at its left-most position, the cursor is moved to the end of
  458.  * the previous line, except if it is on the top line, in which case nothing
  459.  * happens.
  460.  */
  461. {
  462.   _BH=0;
  463.   _AH=3;
  464.   my_video_int();
  465.   if (_DL==0) {
  466.     if (_DH != topline) {
  467.       _DL=79;
  468.       tempio=_DH-1;
  469.       _DH=tempio;
  470.       _AH=2;
  471.       my_video_int();
  472.     }
  473.   } else {
  474.     _DL--;
  475.     _AH=2;
  476.     my_video_int();
  477.   }
  478. }
  479.  
  480.  
  481.  
  482. void out1chx(unsigned char ch)
  483. /* This function outputs one character to the screen, then updates the
  484.  * cursor position accordingly, scolling the screen if necessary.  Not that
  485.  * this function performs no commands such as a C/R or L/F.  If a value of
  486.  * 8, 7, 13, 10, 12 (backspace, beep, C/R, L/F, TOF), or any other command-
  487.  * type characters are passed, the appropriate corresponding "graphics"
  488.  * symbol will be output to the screen as a normal character.
  489.  */
  490. {
  491.   _BL=curatr;
  492.   _BH=0x00;
  493.   _CX=0x01;
  494.   _AL=ch;
  495.   _AH=0x09;
  496.   my_video_int();
  497.   _BH=0x00;
  498.   _AH=0x03;
  499.   my_video_int();
  500.   ++_DL;
  501.   if (_DL==80) {
  502.     _DL=0;
  503.     if (_DH==screenbottom) {
  504.       SCROLL_UP(topline,screenbottom,1);
  505.       _DH=screenbottom;
  506.       _DL=0;
  507.       _BH=0;
  508.       _AH=0x02;
  509.       my_video_int();
  510.     } else {
  511.       tempio=_DH+1;
  512.       _DH=tempio;
  513.       _AH=0x02;
  514.       my_video_int();
  515.     }
  516.   } else {
  517.     _AH=0x02;
  518.     my_video_int();
  519.   }
  520. }
  521.  
  522.  
  523.  
  524.  
  525. void out1ch(unsigned char ch)
  526. /* This function outputs one character to the local screen.  C/R, L/F, TOF,
  527.  * BS, and BELL are interpreted as commands instead of characters.
  528.  */
  529. {
  530.   if (ch>31)
  531.     out1chx(ch);
  532.   else
  533.     if (ch==13)
  534.       cr();
  535.     else
  536.       if (ch==10)
  537.         lf();
  538.       else
  539.         if (ch==12)
  540.           clrscrb();
  541.         else
  542.           if (ch==8)
  543.             bs();
  544.           else
  545.             if (ch==7)
  546.               if (outcom==0) {
  547.                 setbeep(1);
  548.                 wait1(4);
  549.                 setbeep(0);
  550.               }
  551. }
  552.  
  553.  
  554.  
  555. /****************************************************************************/
  556. void far interrupt async_isr ()
  557. /* This function is called every time a char is received on the com port.
  558.  * The character is stored in the buffer[] array, and the head pointer is
  559.  * updated.
  560.  */
  561. {
  562.   buffer[head++] = inportb(base);
  563.   if (head == max_buf)
  564.     head = 0;
  565.   outportb(0x20, 0x20);
  566. }
  567.  
  568.  
  569.  
  570. void outcomch(char ch)
  571. /* This function outputs one character to the com port */
  572. {
  573.   while (!(inportb(base + 5) & 0x20))
  574.     ;
  575.   if (flow_control)
  576.     while (!(inportb(base + 6) & 0x10))
  577.       ;
  578.   outportb(base, ch);
  579. }
  580.  
  581.  
  582.  
  583.  
  584. char get1c()
  585. /* This function returns one character from the com port, or a zero if
  586.  * no character is waiting
  587.  */
  588. {
  589.   char c1;
  590.  
  591.   if (head != tail) {
  592.     disable();
  593.     c1 = buffer[tail++];
  594.     if (tail == max_buf)
  595.       tail = 0;
  596.     enable();
  597.     return(c1);
  598.   } else
  599.     return(0);
  600. }
  601.  
  602.  
  603.  
  604. int comhit()
  605. /* This returns a value telling if there is a character waiting in the com
  606.  * buffer.
  607.  */
  608. {
  609.   return(head != tail);
  610. }
  611.  
  612.  
  613.  
  614. void dump()
  615. /* This function clears the com buffer */
  616. {
  617.   disable();
  618.   head = tail = 0;
  619.   enable();
  620. }
  621.  
  622.  
  623.  
  624. void set_baud(unsigned int rate)
  625. /* This function sets the com speed to that passed */
  626. {
  627.   float rl;
  628.  
  629.   if ((rate > 49) && (rate < 57601)) {
  630.     rl   = 115200.0 / ((float) rate);
  631.     rate = (int) rl;
  632.     outportb(base + 3, inportb(base + 3) | 0x80);
  633.     outportb(base,     (rate & 0x00FF));
  634.     outportb(base + 1, ((rate >> 8) & 0x00FF));
  635.     outportb(base + 3, inportb(base + 3) & 0x7F);
  636.   }
  637. }
  638.  
  639.  
  640. void initport(int portnum)
  641. /* This function initializes the com buffer, setting up the interrupt,
  642.  * and com parameters
  643.  */
  644. {
  645.   int temp;
  646.  
  647.   temp=portnum;
  648.  
  649.   setvect(8 + async_irq, async_isr);
  650.   head = tail = 0;
  651.   outportb(base + 3, 0x03);
  652.   disable();
  653.   temp = inportb(base + 5);
  654.   temp = inportb(base);
  655.   temp = inportb(0x21);
  656.   temp = temp & ((1 << async_irq) ^ 0x00FF);
  657.   outportb(0x21, temp);
  658.   outportb(base + 1, 0x01);
  659.   temp=inportb(base + 4);
  660.   outportb(base + 4, temp | 0x0B);
  661.   enable();
  662.   set_baud(baud_rate);
  663. }
  664.  
  665.  
  666.  
  667. void closeport()
  668. /* This function closes out the com port, removing the interrupt routine,
  669.  * etc.
  670.  */
  671. {
  672.   int temp;
  673.  
  674.   disable();
  675.   temp = inportb(0x21);
  676.   temp = temp | ((1 << async_irq));
  677.   outportb(0x21, temp | 0x10);
  678.   outportb(base + 2, 0);
  679.   outportb(base + 4, 3);
  680.   enable();
  681. }
  682.  
  683.  
  684. int cdet()
  685. /* This returns the status of the carrier detect lead from the modem */
  686. {
  687.   return((inportb(base + 6) & 0x80) ? 1 : 0);
  688. }
  689.  
  690.  
  691.  
  692. void checkhangup()
  693. /* This function checks to see if the user logged on to the com port has
  694.  * hung up.  Obviously, if no user is logged on remotely, this does nothing.
  695.  * If carrier detect is detected to be low, it is checked 100 times
  696.  * sequentially to make sure it stays down, and is not just a quirk.
  697.  */
  698. {
  699.   int i, ok;
  700.  
  701.   if (!hangup && using_modem && !cdet()) {
  702.     ok = 0;
  703.     for (i = 0; (i < 500) && !ok; i++)
  704.       if (cdet())
  705.         ok = 1;
  706.     if (!ok) {
  707.       hangup = hungup = 1;
  708.     }
  709.   }
  710. }
  711.  
  712.  
  713.  
  714.  
  715. void addto(char *s, int i)
  716. {
  717.   char temp[20];
  718.  
  719.   if (s[0])
  720.     strcat(s, ";");
  721.   else
  722.     strcpy(s, "\x1B[");
  723.   itoa(i, temp, 10);
  724.   strcat(s, temp);
  725. }
  726.  
  727.  
  728.  
  729. void makeansi(unsigned char attr, char *s, int forceit)
  730. /* Passed to this function is a one-byte attribute as defined for IBM type
  731.  * screens.  Returned is a string which, when printed, will change the
  732.  * display to the color desired, from the current function.
  733.  */
  734. {
  735.   unsigned char catr;
  736.   char *temp = "04261537";
  737.  
  738.   catr = curatr;
  739.   s[0] = 0;
  740.   if (attr != catr) {
  741.     if ((catr & 0x88) ^ (attr & 0x88)) {
  742.       addto(s, 0);
  743.       addto(s, 30 + temp[attr & 0x07] - '0');
  744.       addto(s, 40 + temp[(attr & 0x70) >> 4] - '0');
  745.       catr = attr & 0x77;
  746.     }
  747.     if ((catr & 0x07) != (attr & 0x07))
  748.       addto(s, 30 + temp[attr & 0x07] - '0');
  749.     if ((catr & 0x70) != (attr & 0x70))
  750.       addto(s, 40 + temp[(attr & 0x70) >> 4] - '0');
  751.     if ((catr & 0x08) ^ (attr & 0x08))
  752.       addto(s, 1);
  753.     if ((catr & 0x80) ^ (attr & 0x80))
  754.       addto(s, 5);
  755.   }
  756.   if (s[0])
  757.     strcat(s, "m");
  758.   if (!okansi() && !forceit)
  759.     s[0]=0;
  760. }
  761.  
  762.  
  763.  
  764. void setfgc(int i)
  765. /* This sets the foreground color to that passed.  It is called only from
  766.  * execute_ansi
  767.  */
  768. {
  769.   curatr = (curatr & 0xf8) | i;
  770. }
  771.  
  772.  
  773.  
  774. void setbgc(int i)
  775. /* This sets the background color to that passed.  It is called only from
  776.  * execute_ansi
  777.  */
  778. {
  779.   curatr = (curatr & 0x8f) | (i << 4);
  780. }
  781.  
  782.  
  783. void execute_ansi()
  784. /* This function executes an ANSI string to change color, position the
  785.  * cursor, etc.
  786.  */
  787. {
  788.   int args[10], argptr, count, ptr, tempptr, ox, oy;
  789.   char cmd, temp[10], teol[81], *clrlst = "04261537";
  790.  
  791.   if (ansistr[1] != '[') {
  792.  
  793.     /* do nothing if invalid ANSI string. */
  794.  
  795.   } else {
  796.     argptr = tempptr = 0;
  797.     ptr = 2;
  798.     for (count = 0; count < 10; count++)
  799.       args[count] = temp[count] = 0;
  800.     cmd = ansistr[ansiptr - 1];
  801.     ansistr[ansiptr - 1] = 0;
  802.     while (ansistr[ptr]) {
  803.       if (ansistr[ptr] == ';') {
  804.         temp[tempptr] = 0;
  805.         tempptr = 0;
  806.         args[argptr++] = atoi(temp);
  807.       } else
  808.         temp[tempptr++] = ansistr[ptr];
  809.       ++ptr;
  810.     }
  811.     if (tempptr) {
  812.       temp[tempptr]  = 0;
  813.       args[argptr++] = atoi(temp);
  814.     }
  815.     if ((cmd >= 'A') && (cmd <= 'D') && !args[0])
  816.       args[0] = 1;
  817.     switch (cmd) {
  818.         case 'f':
  819.         case 'H':
  820.           movecsr(args[1] - 1, args[0] - 1);
  821.           break;
  822.         case 'A':
  823.           movecsr(wherex(), wherey() - args[0]);
  824.           break;
  825.         case 'B':
  826.           movecsr(wherex(), wherey() + args[0]);
  827.           break;
  828.         case 'C':
  829.           movecsr(wherex() + args[0], wherey());
  830.           break;
  831.         case 'D':
  832.           movecsr(wherex() - args[0], wherey());
  833.           break;
  834.         case 's':
  835.           oldx = wherex();
  836.           oldy = wherey();
  837.           break;
  838.         case 'u':
  839.           movecsr(oldx, oldy);
  840.           break;
  841.         case 'J':
  842.           if (args[0] == 2)
  843.             clrscrb();
  844.           break;
  845.         case 'k':
  846.         case 'K':
  847.           ox = wherex();
  848.           oy = wherey();
  849.           _CX = 80 - ox;
  850.           _AH = 0x09;
  851.           _BH = 0x00;
  852.           _AL = 32;
  853.           _BL = curatr;
  854.           my_video_int();
  855.           movecsr(ox, oy);
  856.           break;
  857.         case 'm':
  858.           if (!argptr) {
  859.             argptr = 1;
  860.             args[0] = 0;
  861.           }
  862.           for (count = 0; count < argptr; count++)
  863.             switch (args[count]) {
  864.               case 0: curatr = 0x07; break;
  865.               case 1: curatr = curatr | 0x08; break;
  866.               case 4: break;
  867.               case 5: curatr = curatr | 0x80; break;
  868.               case 7:
  869.                 ptr = curatr & 0x77;
  870.                 curatr = (curatr & 0x88) | (ptr << 4) | (ptr >> 4);
  871.                 break;
  872.               case 8: curatr = 0; break;
  873.               default:
  874.                 if ((args[count] >= 30) && (args[count] <= 37))
  875.                   setfgc(clrlst[args[count] - 30] - '0');
  876.                 else if ((args[count] >= 40) && (args[count] <= 47))
  877.                   setbgc(clrlst[args[count] - 40] - '0');
  878.             }
  879.           break;
  880.       }
  881.     }
  882.   ansiptr = 0;
  883. }
  884.  
  885.  
  886.  
  887. void outchr(char c)
  888. /* This function outputs one character to the screen, and if output to the
  889.  * com port is enabled, the character is output there too.  ANSI graphics
  890.  * are also trapped here, and the ansi function is called to execute the
  891.  * ANSI codes
  892.  */
  893. {
  894.   int i, i1;
  895.  
  896.   if (change_color) {
  897.     change_color = 0;
  898.     if ((c >= '0') && (c <= '7'))
  899.       ansic(c - '0');
  900.     return;
  901.   }
  902.   if (c == 3) {
  903.     change_color = 1;
  904.     return;
  905.   }
  906.   if ((c == 10) && endofline[0]) {
  907.     if (!in_extern)
  908.       outstr(endofline);
  909.     endofline[0] = 0;
  910.   }
  911.   if (outcom && (c != 9))
  912.     outcomch(echo ? c : 'X');
  913.   if (ansiptr) {
  914.     ansistr[ansiptr++] = c;
  915.     ansistr[ansiptr]   = 0;
  916.     if (((c > '@') && (c != '[')) || (ansistr[1] != '['))
  917.       execute_ansi();
  918.   } else if (c == 27) {
  919.     ansistr[0] = 27;
  920.     ansiptr = 1;
  921.   } else if (c == 9) {
  922.     i1 = wherex();
  923.     for (i = i1; i< (((i1 / 8) + 1) * 8); i++)
  924.       outchr(32);
  925.   } else if (echo || lecho) {
  926.     out1ch(c);
  927.     if (c == 10) {
  928.       ++lines_listed;
  929.       if ((sysstatus_pause_on_page & thisuser.sysstatus) &&
  930.           (lines_listed >= screenlinest - 1)) {
  931.         pausescr();
  932.         lines_listed = 0;
  933.       }
  934.     }
  935.   } else
  936.     out1ch('X');
  937. }
  938.  
  939.  
  940.  
  941. void outstr(char *s)
  942. /* This function outputs a string of characters to the screen (and remotely
  943.  * if applicable).  The com port is also checked first to see if a remote
  944.  * user has hung up
  945.  */
  946. {
  947.   int i=0;
  948.  
  949.   checkhangup();
  950.   if (!hangup)
  951.     while (s[i])
  952.       outchr(s[i++]);
  953. }
  954.  
  955.  
  956.  
  957. void nl()
  958. /* This function performs a CR/LF sequence to move the cursor to the next
  959.  * line.  If any end-of-line ANSI codes are set (such as changing back to
  960.  * the default color) are specified, those are executed first.
  961.  */
  962. {
  963.   if (endofline[0]) {
  964.     outstr(endofline);
  965.     endofline[0] = 0;
  966.   }
  967.   outstr("\r\n");
  968. }
  969.  
  970.  
  971.  
  972. void backspace()
  973. /* This function executes a backspace, space, backspace sequence. */
  974. {
  975.   int i;
  976.  
  977.   i = echo;
  978.   echo = 1;
  979.   outstr("\b \b");
  980.   echo = i;
  981. }
  982.  
  983.  
  984.  
  985. void setc(unsigned char ch)
  986. /* This sets the current color (both locally and remotely) to that
  987.  * specified (in IBM format).
  988.  */
  989. {
  990.   char s[30];
  991.  
  992.   makeansi(ch, s, 0);
  993.   outstr(s);
  994. }
  995.  
  996.  
  997.  
  998. void pausescr()
  999. /* This will pause output, displaying the [PAUSE] message, and wait for
  1000.  * a key to be hit.
  1001.  */
  1002. {
  1003.   int i;
  1004.  
  1005.   if (okansi()) {
  1006.     i = curatr;
  1007.     setc((thisuser.sysstatus & sysstatus_color) ? thisuser.colors[3] :
  1008.           thisuser.bwcolors[3]);
  1009.     outstr("[PaUsE]\x1b[7D");
  1010.     setc(i);
  1011.     getkey();
  1012.     outstr("       \x1b[7D");
  1013.   } else {
  1014.     outstr("[PaUsE]");
  1015.     getkey();
  1016.     for (i = 0; i < 7; i++)
  1017.       backspace();
  1018.   }
  1019. }
  1020.  
  1021.  
  1022.  
  1023. void pl(char *s)
  1024. {
  1025.   outstr(s);
  1026.   nl();
  1027. }
  1028.  
  1029.  
  1030. int kbhitb()
  1031. {
  1032.   union REGS r;
  1033.  
  1034.   r.h.ah = 1;
  1035.   int86(0x16, &r, &r);
  1036.   return((r.x.flags & 64) == 0);
  1037. }
  1038.  
  1039.  
  1040. int empty()
  1041. {
  1042.   if (kbhitb() || (incom && (head != tail)) ||
  1043.       (charbufferpointer && charbuffer[charbufferpointer]) ||
  1044.       (in_extern == 2))
  1045.     return(0);
  1046.   return(1);
  1047. }
  1048.  
  1049.  
  1050.  
  1051. void skey1(char *ch)
  1052. {
  1053.   char c;
  1054.  
  1055.   c = *ch;
  1056.   if (c == 127)
  1057.     c = 8;
  1058.     switch(c) {
  1059.       case 1:
  1060.       case 4:
  1061.       case 6:
  1062.         if (!charbufferpointer) {
  1063.           if (c == 1)
  1064.             c = 2;
  1065.           else if (c == 4)
  1066.             c = 0;
  1067.           else if (c == 6)
  1068.             c = 1;
  1069.           strcpy(charbuffer, &(thisuser.macros[c][0]));
  1070.           c = charbuffer[0];
  1071.           if (c)
  1072.             charbufferpointer = 1;
  1073.         }
  1074.         break;
  1075.     }
  1076.   *ch = c;
  1077. }
  1078.  
  1079. char getchd()
  1080. {
  1081.   union REGS r;
  1082.  
  1083.   r.h.ah = 0x07;
  1084.   int86(INT_SAVE_21, &r, &r);
  1085.   return(r.h.al);
  1086. }
  1087.  
  1088.  
  1089. char getchd1()
  1090. {
  1091.   union REGS r;
  1092.  
  1093.   r.h.ah = 0x06;
  1094.   r.h.dl = 0xFF;
  1095.   int86(INT_SAVE_21, &r, &r);
  1096.   return((r.x.flags & 0x40) ? 255 : r.h.al);
  1097. }
  1098.  
  1099.  
  1100. char inkey()
  1101. /* This function checks both the local keyboard, and the remote terminal
  1102.  * (if any) for input.  If there is input, the key is returned.  If there
  1103.  * is no input, a zero is returned.  Function keys hit are interpreted as
  1104.  * such within the routine and not returned.
  1105.  */
  1106. {
  1107.   char ch=0;
  1108.  
  1109.   if (charbufferpointer) {
  1110.     if (!charbuffer[charbufferpointer])
  1111.       charbufferpointer = charbuffer[0] = 0;
  1112.     else
  1113.       return(charbuffer[charbufferpointer++]);
  1114.   }
  1115.   if (kbhitb() || (in_extern == 2)) {
  1116.     ch = getchd1();
  1117.     if (!ch) {
  1118.       if (in_extern)
  1119.         in_extern = 2;
  1120.       else {
  1121.         ch = getchd1();
  1122.         ch=0;
  1123.       }
  1124.     } else if (in_extern)
  1125.       in_extern = 1;
  1126.     timelastchar1=timer1();
  1127.   } else if (incom && comhit()) {
  1128.     ch = (get1c() & andwith);
  1129.   }
  1130.   skey1(&ch);
  1131.   return(ch);
  1132. }
  1133.  
  1134.  
  1135.  
  1136. void mpl(int i)
  1137. /* This will make a reverse-video prompt line i characters long, repositioning
  1138.  * the cursor at the beginning of the input prompt area.  Of course, if the
  1139.  * user does not want ansi, this routine does nothing.
  1140.  */
  1141. {
  1142.   int i1;
  1143.   char s[81];
  1144.  
  1145.   if (okansi()) {
  1146.     ansic(4);
  1147.     for (i1 = 0; i1 < i; i1++)
  1148.       outchr(' ');
  1149.     outstr("\x1b[");
  1150.     itoa(i,s,10);
  1151.     outstr(s);
  1152.     outstr("D");
  1153.   }
  1154. }
  1155.  
  1156.  
  1157.  
  1158. char upcase(char ch)
  1159. /* This converts a character to uppercase */
  1160. {
  1161.   if ((ch > '`') && (ch < '{'))
  1162.     ch = ch - 32;
  1163.   return(ch);
  1164. }
  1165.  
  1166.  
  1167. unsigned char getkey()
  1168. /* This function returns one character from either the local keyboard or
  1169.  * remote com port (if applicable).  After 1.5 minutes of inactivity, a
  1170.  * beep is sounded.  After 3 minutes of inactivity, the user is hung up.
  1171.  */
  1172. {
  1173.   unsigned char ch;
  1174.   int beepyet;
  1175.   long dd;
  1176.  
  1177.   beepyet = 0;
  1178.   timelastchar1=timer1();
  1179.  
  1180.   lines_listed = 0;
  1181.   do {
  1182.     while (empty() && !hangup) {
  1183.       dd = timer1();
  1184.       if (labs(dd - timelastchar1) > 65536L)
  1185.         timelastchar1 -= 1572480L;
  1186.       if (((dd - timelastchar1) > 1638L) && (!beepyet)) {
  1187.         beepyet = 1;
  1188.         outchr(7);
  1189.       }
  1190.       if (labs(dd - timelastchar1) > 3276L) {
  1191.         nl();
  1192.     outstr("3Oops! Looks like you waited too long!");
  1193.     nl();
  1194.     hangup = 1;
  1195.       }
  1196.       checkhangup();
  1197.     }
  1198.     ch = inkey();
  1199.   } while (!ch && !in_extern && !hangup);
  1200.   return(ch);
  1201. }
  1202.  
  1203.  
  1204.  
  1205. void input1(char *s, int maxlen, int lc, int crend)
  1206. /* This will input a line of data, maximum maxlen characters long, terminated
  1207.  * by a C/R.  if (lc) is non-zero, lowercase is allowed, otherwise all
  1208.  * characters are converted to uppercase.
  1209.  */
  1210. {
  1211.   int curpos=0, done=0;
  1212.   unsigned char ch;
  1213.  
  1214.   while (!done && !hangup) {
  1215.     ch = getkey();
  1216.     if (ch > 31) {
  1217.       if (curpos < maxlen) {
  1218.         if (!lc)
  1219.           ch = upcase(ch);
  1220.         s[curpos++] = ch;
  1221.         outchr(ch);
  1222.       }
  1223.     } else
  1224.       switch(ch) {
  1225.         case 14:
  1226.         case 13:
  1227.           s[curpos] = 0;
  1228.           done = echo = 1;
  1229.           if (crend)
  1230.             nl();
  1231.           break;
  1232.         case 26:
  1233.           if (input_extern) {
  1234.             s[curpos++] = 26;
  1235.             outstr("^Z");
  1236.           }
  1237.           break;
  1238.         case 8:
  1239.           if (curpos) {
  1240.             curpos--;
  1241.             backspace();
  1242.             if (s[curpos] == 26)
  1243.               backspace();
  1244.           }
  1245.           break;
  1246.         case 24:
  1247.           while (curpos) {
  1248.             curpos--;
  1249.             backspace();
  1250.             if (s[curpos] == 26)
  1251.               backspace();
  1252.           }
  1253.           break;
  1254.       }
  1255.   }
  1256.   if (hangup)
  1257.     s[0] = 0;
  1258. }
  1259.  
  1260.  
  1261.  
  1262. void input(char *s, int len)
  1263. /* This will input an upper-case string */
  1264. {
  1265.   input1(s, len, 0, 1);
  1266. }
  1267.  
  1268.  
  1269.  
  1270. void inputl(char *s, int len)
  1271. /* This will input an upper or lowercase string of characters */
  1272. {
  1273.   input1(s, len, 1, 1);
  1274. }
  1275.  
  1276.  
  1277.  
  1278. int yn()
  1279. /* The keyboard is checked for either a Y, N, or C/R to be hit.  C/R is
  1280.  * assumed to be the same as a N.  Yes or No is output, and yn is set to
  1281.  * zero if No was returned, and yn() is non-zero if Y was hit.
  1282.  */
  1283. {
  1284.   char ch=0;
  1285.  
  1286.   ansic(1);
  1287.   while (!hangup && ((ch = upcase(getkey())) != 'Y') && (ch != 'N') && (ch != 13))
  1288.     ;
  1289.   outstr((ch == 'Y') ? "Yes" : "No");
  1290.   nl();
  1291.   return(ch == 'Y');
  1292. }
  1293.  
  1294.  
  1295.  
  1296. int ny()
  1297. /* This is the same as yn(), except C/R is assumed to be "Y" */
  1298. {
  1299.   char ch=0;
  1300.  
  1301.   ansic(1);
  1302.   while (!hangup && ((ch = upcase(getkey())) != 'Y') && (ch != 'N') && (ch != 13))
  1303.     ;
  1304.   outstr((ch == 'N') ? "No" : "Yes");
  1305.   nl();
  1306.   return((ch == 'Y') || (ch==13));
  1307. }
  1308.  
  1309.  
  1310. void ansic(int n)
  1311. {
  1312.   char s[81], c;
  1313.  
  1314.   c = ((thisuser.sysstatus & sysstatus_color) ? thisuser.colors[n] :
  1315.         thisuser.bwcolors[n]);
  1316.   if (c == curatr)
  1317.     return;
  1318.   setc(c);
  1319.   makeansi((thisuser.sysstatus & sysstatus_color) ? thisuser.colors[0] :
  1320.         thisuser.bwcolors[0],endofline, 0);
  1321. }
  1322.  
  1323.  
  1324. char onek(char *s)
  1325. {
  1326.   char ch;
  1327.  
  1328.   while (!strchr(s, ch = upcase(getkey())) && !hangup)
  1329.     ;
  1330.   if (hangup)
  1331.     ch = s[0];
  1332.   outchr(ch);
  1333.   nl();
  1334.   return(ch);
  1335. }
  1336.  
  1337.  
  1338. void prt(int i, char *s)
  1339. {
  1340.   ansic(i);
  1341.   outstr(s);
  1342.   ansic(0);
  1343. }
  1344.  
  1345. /****************************************************************************/
  1346. #pragma warn -par
  1347.  
  1348. void far interrupt inlii(unsigned bp, unsigned di, unsigned si,
  1349.                            unsigned ds, unsigned es, unsigned dx,
  1350.                            unsigned cx, unsigned bx, unsigned ax,
  1351.                            unsigned ip, unsigned cs, unsigned flags,
  1352.                            char *s1, char *s2, int i1, int i2)
  1353. {
  1354.   inli(s1,s2,i1,i2);
  1355. }
  1356.  
  1357. void far interrupt checkai(unsigned bp, unsigned di, unsigned si,
  1358.                            unsigned ds, unsigned es, unsigned dx,
  1359.                            unsigned cx, unsigned bx, unsigned ax,
  1360.                            unsigned ip, unsigned cs, unsigned flags,
  1361.                            int *i1, int *i2)
  1362. {
  1363.   checka(i1,i2);
  1364. }
  1365.  
  1366.  
  1367. void far interrupt plai(unsigned bp, unsigned di, unsigned si,
  1368.                            unsigned ds, unsigned es, unsigned dx,
  1369.                            unsigned cx, unsigned bx, unsigned ax,
  1370.                            unsigned ip, unsigned cs, unsigned flags,
  1371.                            char *s1, int *i1)
  1372. {
  1373.   pla(s1,i1);
  1374. }
  1375.  
  1376.  
  1377. void far interrupt outchri(unsigned bp, unsigned di, unsigned si,
  1378.                            unsigned ds, unsigned es, unsigned dx,
  1379.                            unsigned cx, unsigned bx, unsigned ax,
  1380.                            unsigned ip, unsigned cs, unsigned flags,
  1381.                            char ch)
  1382. {
  1383.   outchr(ch);
  1384. }
  1385.  
  1386.  
  1387. void far interrupt outstri(unsigned bp, unsigned di, unsigned si,
  1388.                            unsigned ds, unsigned es, unsigned dx,
  1389.                            unsigned cx, unsigned bx, unsigned ax,
  1390.                            unsigned ip, unsigned cs, unsigned flags,
  1391.                            char *s1)
  1392. {
  1393.   outstr(s1);
  1394. }
  1395.  
  1396.  
  1397. void far interrupt nli(unsigned bp, unsigned di, unsigned si,
  1398.                            unsigned ds, unsigned es, unsigned dx,
  1399.                            unsigned cx, unsigned bx, unsigned ax,
  1400.                            unsigned ip, unsigned cs, unsigned flags)
  1401. {
  1402.   nl();
  1403. }
  1404.  
  1405.  
  1406. void far interrupt pli(unsigned bp, unsigned di, unsigned si,
  1407.                            unsigned ds, unsigned es, unsigned dx,
  1408.                            unsigned cx, unsigned bx, unsigned ax,
  1409.                            unsigned ip, unsigned cs, unsigned flags,
  1410.                            char *s1)
  1411. {
  1412.   pl(s1);
  1413. }
  1414.  
  1415.  
  1416. void far interrupt emptyi(unsigned bp, unsigned di, unsigned si,
  1417.                            unsigned ds, unsigned es, unsigned dx,
  1418.                            unsigned cx, unsigned bx, unsigned ax,
  1419.                            unsigned ip, unsigned cs, unsigned flags)
  1420. {
  1421.   ax=empty();
  1422. }
  1423.  
  1424.  
  1425. void far interrupt inkeyi(unsigned bp, unsigned di, unsigned si,
  1426.                            unsigned ds, unsigned es, unsigned dx,
  1427.                            unsigned cx, unsigned bx, unsigned ax,
  1428.                            unsigned ip, unsigned cs, unsigned flags)
  1429. {
  1430.   ax=(unsigned) empty();
  1431. }
  1432.  
  1433.  
  1434. void far interrupt getkeyi(unsigned bp, unsigned di, unsigned si,
  1435.                            unsigned ds, unsigned es, unsigned dx,
  1436.                            unsigned cx, unsigned bx, unsigned ax,
  1437.                            unsigned ip, unsigned cs, unsigned flags)
  1438. {
  1439.   ax=(unsigned) getkey();
  1440. }
  1441.  
  1442.  
  1443. void far interrupt inputi(unsigned bp, unsigned di, unsigned si,
  1444.                            unsigned ds, unsigned es, unsigned dx,
  1445.                            unsigned cx, unsigned bx, unsigned ax,
  1446.                            unsigned ip, unsigned cs, unsigned flags,
  1447.                            char *s1, int i)
  1448. {
  1449.   input(s1,i);
  1450. }
  1451.  
  1452.  
  1453. void far interrupt inputli(unsigned bp, unsigned di, unsigned si,
  1454.                            unsigned ds, unsigned es, unsigned dx,
  1455.                            unsigned cx, unsigned bx, unsigned ax,
  1456.                            unsigned ip, unsigned cs, unsigned flags,
  1457.                            char *s1, int i)
  1458. {
  1459.   inputl(s1,i);
  1460. }
  1461.  
  1462.  
  1463. void far interrupt yni(unsigned bp, unsigned di, unsigned si,
  1464.                            unsigned ds, unsigned es, unsigned dx,
  1465.                            unsigned cx, unsigned bx, unsigned ax,
  1466.                            unsigned ip, unsigned cs, unsigned flags)
  1467. {
  1468.   ax=yn();
  1469. }
  1470.  
  1471.  
  1472.  
  1473. void far interrupt nyi(unsigned bp, unsigned di, unsigned si,
  1474.                            unsigned ds, unsigned es, unsigned dx,
  1475.                            unsigned cx, unsigned bx, unsigned ax,
  1476.                            unsigned ip, unsigned cs, unsigned flags)
  1477. {
  1478.   ax=ny();
  1479. }
  1480.  
  1481.  
  1482. void far interrupt ansici(unsigned bp, unsigned di, unsigned si,
  1483.                            unsigned ds, unsigned es, unsigned dx,
  1484.                            unsigned cx, unsigned bx, unsigned ax,
  1485.                            unsigned ip, unsigned cs, unsigned flags,
  1486.                            int i1)
  1487. {
  1488.   ansic(i1);
  1489. }
  1490.  
  1491.  
  1492. void far interrupt oneki(unsigned bp, unsigned di, unsigned si,
  1493.                            unsigned ds, unsigned es, unsigned dx,
  1494.                            unsigned cx, unsigned bx, unsigned ax,
  1495.                            unsigned ip, unsigned cs, unsigned flags,
  1496.                            char *s1)
  1497. {
  1498.   ax=(unsigned) onek(s1);
  1499. }
  1500.  
  1501.  
  1502. void far interrupt prti(unsigned bp, unsigned di, unsigned si,
  1503.                            unsigned ds, unsigned es, unsigned dx,
  1504.                            unsigned cx, unsigned bx, unsigned ax,
  1505.                            unsigned ip, unsigned cs, unsigned flags,
  1506.                            int i1, char *s1)
  1507. {
  1508.   prt(i1,s1);
  1509. }
  1510.  
  1511.  
  1512.  
  1513. void far interrupt mpli(unsigned bp, unsigned di, unsigned si,
  1514.                            unsigned ds, unsigned es, unsigned dx,
  1515.                            unsigned cx, unsigned bx, unsigned ax,
  1516.                            unsigned ip, unsigned cs, unsigned flags,
  1517.                            int i1)
  1518. {
  1519.   mpl(i1);
  1520. }
  1521.  
  1522.  
  1523. #pragma warn +par
  1524.  
  1525. /****************************************************************************/
  1526.  
  1527. unsigned char getkeyext()
  1528. {
  1529.   unsigned char ch;
  1530.   static int holding=0;
  1531.   static char held=0;
  1532.  
  1533.   if (holding) {
  1534.     holding=0;
  1535.     return(held);
  1536.   }
  1537.   ch=getkey();
  1538.   if (charbufferpointer==0) {
  1539.     if (ch==16) {
  1540.       ch=getkey();
  1541.       if ((ch==1) && (charbufferpointer==0)) {
  1542.         strcpy(charbuffer,&(thisuser.macros[2][0]));
  1543.         ch=charbuffer[0];
  1544.         if (ch) {
  1545.           charbufferpointer=1;
  1546.           return(ch);
  1547.         } else
  1548.           return(getkeyext());
  1549.       } else
  1550.         if ((ch==4) && (charbufferpointer==0)) {
  1551.           strcpy(charbuffer,&(thisuser.macros[0][0]));
  1552.           ch=charbuffer[0];
  1553.           if (ch) {
  1554.             charbufferpointer=1;
  1555.             return(ch);
  1556.           } else
  1557.             return(getkeyext());
  1558.         } else
  1559.           if ((ch==6) && (charbufferpointer==0)) {
  1560.             strcpy(charbuffer,&(thisuser.macros[1][0]));
  1561.             ch=charbuffer[0];
  1562.             if (ch) {
  1563.               charbufferpointer=1;
  1564.               return(ch);
  1565.             } else
  1566.               return(getkeyext());
  1567.           } else {
  1568.             holding=1;
  1569.             held=ch;
  1570.             return(16);
  1571.           }
  1572.     }
  1573.   }
  1574.   return(ch);
  1575. }
  1576.  
  1577.  
  1578. int do_it(char *cl)
  1579. {
  1580.   int i,i1,l;
  1581.   char s[160];
  1582.   char *ss[30];
  1583.  
  1584.   strcpy(s,cl);
  1585.   ss[0]=s;
  1586.   i=1;
  1587.   l=strlen(s);
  1588.   for (i1=1; i1<l; i1++)
  1589.     if (s[i1]==32) {
  1590.       s[i1]=0;
  1591.       ss[i++]=&(s[i1+1]);
  1592.     }
  1593.   ss[i]=NULL;
  1594.   i=(spawnvpe(P_WAIT,ss[0],ss,xenviron) & 0x00ff);
  1595. /*   spawnvp(P_WAIT,ss[0],ss); */
  1596.   return(i);
  1597. }
  1598.  
  1599.  
  1600.  
  1601. int do_remote(char *s, int ccc)
  1602. {
  1603.   int rc,xx;
  1604.   char x[161];
  1605.  
  1606.   checkhangup();
  1607.   if (hangup)
  1608.     return(32767);
  1609.   strcpy(x,getenv("COMSPEC"));
  1610.   strcat(x," /C ");
  1611.   strcat(x,s);
  1612.   if (ccc)
  1613.     rc=do_it(x);
  1614.   else
  1615.     rc=do_it(s);
  1616.   chdir(cdir);
  1617.   setdisk(cdir[0]-'A');
  1618.   return(rc);
  1619. }
  1620.  
  1621.  
  1622. union REGS ca_r;
  1623. int ca_pause,ca_ctrl_c;
  1624. long ca_d1;
  1625.  
  1626.  
  1627. void checka2()
  1628. {
  1629.   ca_pause=0;
  1630.   ca_ctrl_c=0;
  1631.   ca_r.h.ah=1;
  1632.   int86(0x16,&ca_r,&ca_r);
  1633.   if ((ca_r.x.flags & 64)==0) {
  1634.     if (ca_r.x.ax==11779)
  1635.       ca_ctrl_c=1;
  1636.     if (ca_r.x.ax==7955)
  1637.       ca_pause=1;
  1638.   }
  1639.   if (head!=tail) {
  1640.     if (buffer[tail]==3)
  1641.       ca_ctrl_c=1;
  1642.     if (buffer[tail]==19)
  1643.       ca_pause=1;
  1644.   }
  1645.   if (ca_pause) {
  1646.     while (inkey()!=0)
  1647.       ;
  1648.     ca_d1=timer1();
  1649.     while ((inkey()==0) && (labs(timer1()-ca_d1)<3276L) && (!hangup))
  1650.       checkhangup();
  1651.     lines_listed=0;
  1652.   }
  1653.   if ((ca_ctrl_c) && (ctc)) {
  1654.     while (inkey()!=0)
  1655.       ;
  1656.     pl("^C");
  1657.     ca_r.x.ax=0x4c00;
  1658.     int86(INT_SAVE_21,&ca_r,&ca_r);
  1659.   }
  1660. }
  1661.  
  1662.  
  1663.  
  1664.  
  1665. void outdosstr(char *s)
  1666. /* This function outputs a string of characters to the screen (and remotely
  1667.  * if applicable).  The com port is also checked first to see if a remote
  1668.  * user has hung up
  1669.  */
  1670. {
  1671.   int i;
  1672.  
  1673.   checkhangup();
  1674.   if (hangup==0) {
  1675.     i=0;
  1676.     while ((s[i] !='$') && (i<1024)) {
  1677.       checka2();
  1678.       outchr(s[i++]);
  1679.     }
  1680.   }
  1681. }
  1682.  
  1683.  
  1684.  
  1685. union REGS ni_r;
  1686. struct SREGS ni_s;
  1687. unsigned ni_n;
  1688. char ni_ch,ni_ch1,ni_ss[10],ni_ch2;
  1689. unsigned char *ni_st;
  1690.  
  1691. static unsigned short ni_stack[150];
  1692.  
  1693.  
  1694. #pragma warn -par
  1695.  
  1696. void far interrupt newintr1(unsigned bp, unsigned di, unsigned si,
  1697.                            unsigned ds, unsigned es, unsigned dx,
  1698.                            unsigned cx, unsigned bx, unsigned ax,
  1699.                            unsigned ip, unsigned cs, unsigned flags)
  1700. {
  1701.  
  1702.   unsigned short ni_SS, ni_SP;
  1703. #define NEW_STK() { _BX=FP_OFF(&ni_stack[98]); _SS=_DS; _SP=_BX; }
  1704. #define OLD_STK() { _AX=ni_SS; _BX=ni_SP; _SS=_AX; _SP=_BX; }
  1705.  
  1706.  
  1707.  
  1708.   ni_r.x.ax=ax;
  1709.   ni_r.x.bx=bx;
  1710.   ni_r.x.cx=cx;
  1711.   ni_r.x.dx=dx;
  1712.   ni_r.x.si=si;
  1713.   ni_r.x.di=di;
  1714.   ni_r.x.flags=flags;
  1715.   ni_s.ds=ds;
  1716.   ni_s.es=es;
  1717.  
  1718.   ni_SS=_SS;
  1719.   ni_SP=_SP;
  1720.  
  1721.   ni_ch=ni_r.h.ah;
  1722.   ni_ch1=0;
  1723.  
  1724.   switch(ni_ch) {
  1725.     case 0x01:
  1726.       NEW_STK();
  1727.       ni_ch=getkeyext();
  1728.       outchr(ni_ch);
  1729.       if (hangup)
  1730.         ni_ch=3;
  1731.       ni_r.h.al=ni_ch;
  1732.       ni_ch1=1;
  1733.       OLD_STK();
  1734.       break;
  1735.     case 0x02:
  1736.       NEW_STK();
  1737.       outchr(ni_r.h.dl);
  1738.       ni_ch1=1;
  1739.       checka2();
  1740.       OLD_STK();
  1741.       break;
  1742.     case 0x06:
  1743.       NEW_STK();
  1744.       if (ni_r.h.dl!=0xff) {
  1745.         outchr(ni_r.h.dl);
  1746.         ni_ch1=1;
  1747.       } else {
  1748.         if (empty()) {
  1749.           ni_r.x.flags |= 64;
  1750.         } else {
  1751.           ni_r.x.flags &= (0xffff ^ 64);
  1752.           ni_r.h.al=getkeyext();
  1753.         }
  1754.       }
  1755.       OLD_STK();
  1756.       break;
  1757.     case 0x07:
  1758.       NEW_STK();
  1759.       ni_ch1=1;
  1760.       ni_r.h.al=getkeyext();
  1761.       OLD_STK();
  1762.       break;
  1763.     case 0x08:
  1764.       NEW_STK();
  1765.       ni_ch1=1;
  1766.       ni_r.h.al=getkeyext();
  1767.       OLD_STK();
  1768.       break;
  1769.     case 0x09:
  1770.       NEW_STK();
  1771.       outdosstr((char *) MK_FP(ni_s.ds, ni_r.x.dx));
  1772.       ni_ch1=1;
  1773.       OLD_STK();
  1774.       break;
  1775.     case 0x0a:
  1776.       NEW_STK();
  1777.       ni_st=(char *) MK_FP(ni_s.ds,ni_r.x.dx);
  1778.       ni_n=(unsigned int)(ni_st[0]);
  1779.       if (in_extern==2)
  1780.         getkeyext();
  1781.       in_extern=0;
  1782.       input_extern=1;
  1783.       input1(&(ni_st[2]),ni_n-3,1,0);
  1784.       input_extern=0;
  1785.       in_extern=1;
  1786.       ni_st[1]=strlen(&(ni_st[2]));
  1787.       strcat(&(ni_st[2]),"\r");
  1788.       if ((hangup)) {
  1789.         strcpy(&(ni_st[2]),"EXIT\r");
  1790.         ni_st[1]=4;
  1791.         outstr("Exiting...");
  1792.       }
  1793.       ni_ch1=1;
  1794.       OLD_STK();
  1795.       break;
  1796.     case 0x0b:
  1797.       NEW_STK();
  1798.       if (empty())
  1799.         ni_r.h.al=0x00;
  1800.       else
  1801.         ni_r.h.al=0xff;
  1802.       ni_ch1=1;
  1803.       OLD_STK();
  1804.       break;
  1805.     case 0x0c:
  1806.       ni_r.h.ah=ni_r.h.al;
  1807.       int86x(0x21,&ni_r,&ni_r,&ni_s);
  1808.       ni_ch1=1;
  1809.       break;
  1810.     case 0x3f:
  1811.       if (ni_r.x.bx==0x0000) {
  1812.         NEW_STK();
  1813.         ni_st=(char *)MK_FP(ni_s.ds,ni_r.x.dx);
  1814.         inputl(ni_st,ni_r.x.cx);
  1815.         strcat(ni_st,"\r\n");
  1816.         ni_r.x.ax=strlen(ni_st);
  1817.         if (hangup)
  1818.           ni_r.x.ax=0;
  1819.         ni_r.x.flags &=(0xffff ^ 1);
  1820.         ni_ch1=1;
  1821.         OLD_STK();
  1822.       } else
  1823.         int86x(INT_SAVE_21,&ni_r,&ni_r,&ni_s);
  1824.       break;
  1825.     case 0x40:
  1826.       if ((ni_r.x.bx==0x0001) || (ni_r.x.bx==0x0002)) {
  1827.         NEW_STK();
  1828.         ni_st=(char *)MK_FP(ni_s.ds,ni_r.x.dx);
  1829.         for (ni_n=0; ni_n<ni_r.x.cx; ni_n++) {
  1830.           outchr(ni_st[ni_n]);
  1831.           checka2();
  1832.         }
  1833.         ni_r.x.ax=ni_r.x.cx;
  1834.         ni_r.x.flags &=(0xffff ^ 1);
  1835.         ni_ch1=1;
  1836.         OLD_STK();
  1837.       } else
  1838.         int86x(INT_SAVE_21,&ni_r,&ni_r,&ni_s);
  1839.       break;
  1840.     default:
  1841.       int86x(INT_SAVE_21,&ni_r,&ni_r,&ni_s);
  1842.       break;
  1843.   }
  1844.  
  1845.   if (ni_ch1) {
  1846.     checkhangup();
  1847.     if (hangup) {
  1848.       if (hanguptime1<0L) {
  1849.         hanguptime1=timer1();
  1850.         outstr("Aborting...\r\n");
  1851.         ni_r.x.ax=0x4c00;
  1852.         int86x(INT_SAVE_21,&ni_r,&ni_r,&ni_s);
  1853.       } else {
  1854.         if (labs(timer1()-hanguptime1)>36L) {
  1855.           hanguptime1=timer1();
  1856.           outstr("Aborting...\r\n");
  1857.           ni_r.x.ax=0x4c00;
  1858.           int86x(INT_SAVE_21,&ni_r,&ni_r,&ni_s);
  1859.         }
  1860.       }
  1861.     }
  1862.   }
  1863.  
  1864.   ax=ni_r.x.ax;
  1865.   bx=ni_r.x.bx;
  1866.   cx=ni_r.x.cx;
  1867.   dx=ni_r.x.dx;
  1868.   si=ni_r.x.si;
  1869.   di=ni_r.x.di;
  1870.   flags=ni_r.x.flags;
  1871.   ds=ni_s.ds;
  1872.   es=ni_s.es;
  1873. }
  1874.  
  1875.  
  1876.  
  1877. int full_external(char *s, int ccc)
  1878. {
  1879.   unsigned short sav;
  1880.   int xx,cy,cx,xxx;
  1881.  
  1882.   checkhangup();
  1883.   if (hangup)
  1884.     return(0);
  1885.   in_extern=1;
  1886.   hanguptime1=-1L;
  1887.   setvect(INT_SAVE_21,getvect(0x21));
  1888.  
  1889.   setvect(0x21,newintr1);
  1890.  
  1891.   if ((screenlinest<=defscreenbottom) && (screenlinest>20)) {
  1892.     screenbottom=screenlinest-1;
  1893.     cy=wherey();
  1894.     cx=wherex();
  1895.     xxx=cy-screenbottom+topline;
  1896.     if (xxx>0) {
  1897.       SCROLL_UP(topline,defscreenbottom,xxx);
  1898.       movecsr(cx,screenbottom);
  1899.     }
  1900.   }
  1901.  
  1902.   do_remote(s,ccc);
  1903.  
  1904.   setvect(0x21,getvect(INT_SAVE_21));
  1905.  
  1906.   if (in_extern==2)
  1907.     getkey();
  1908.   in_extern=0;
  1909.   return(0);
  1910. }
  1911.  
  1912.  
  1913. /****************************************************************************/
  1914.  
  1915. #define READ(x) read(i,&(x),sizeof(x))
  1916.  
  1917. int init_r()
  1918. {
  1919.   int i;
  1920.  
  1921.   for (i=0; i<25; i++)
  1922.     funcs[i]=NULL;
  1923.   funcs[0]=(void far *)inlii;
  1924.   funcs[1]=(void far *)checkai;
  1925.   funcs[2]=(void far *)plai;
  1926.   funcs[3]=(void far *)outchri;
  1927.   funcs[4]=(void far *)outstri;
  1928.   funcs[5]=(void far *)nli;
  1929.   funcs[8]=(void far *)pli;
  1930.   funcs[9]=(void far *)emptyi;
  1931.   funcs[10]=(void far *)inkeyi;
  1932.   funcs[11]=(void far *)getkeyi;
  1933.   funcs[12]=(void far *)inputi;
  1934.   funcs[13]=(void far *)inputli;
  1935.   funcs[14]=(void far *)yni;
  1936.   funcs[15]=(void far *)nyi;
  1937.   funcs[16]=(void far *)ansici;
  1938.   funcs[17]=(void far *)oneki;
  1939.   funcs[18]=(void far *)prti;
  1940.   funcs[19]=(void far *)mpli;
  1941.   setvect(INT_POINT_FUNCS,(void far interrupt (*) (void))funcs);
  1942.  
  1943.   i=open("stat.wwv",O_RDONLY | O_BINARY);
  1944.   if (i<0)
  1945.     return(1);
  1946.  
  1947.   READ(incom);
  1948.   READ(outcom);
  1949.   using_modem=incom || outcom;
  1950.   READ(thisuser);
  1951.   READ(flow_control);
  1952.   READ(async_irq);
  1953.   READ(baud_rate);
  1954.   READ(base);
  1955.   READ(andwith);
  1956.   READ(ctc);
  1957.   READ(defscreenbottom);
  1958.   READ(ok_modem_stuff);
  1959.  
  1960.   close(i);
  1961.  
  1962.   if (ok_modem_stuff)
  1963.     initport(0);
  1964.   return(0);
  1965. }
  1966.  
  1967. void get_dir(char *s, int be)
  1968. {
  1969.   strcpy(s,"X:\\");
  1970.   s[0]='A'+getdisk();
  1971.   getcurdir(0,&(s[3]));
  1972.   if (be) {
  1973.     if (s[strlen(s)-1]!='\\')
  1974.       strcat(s,"\\");
  1975.   }
  1976. }
  1977.  
  1978.  
  1979. void cd_to(char *s)
  1980. {
  1981.   char s1[81];
  1982.   int i,db;
  1983.  
  1984.   strcpy(s1,s);
  1985.   i=strlen(s1)-1;
  1986.   db=(s1[i]=='\\');
  1987.   if (i==0)
  1988.     db=0;
  1989.   if ((i==2) && (s1[1]==':'))
  1990.     db=0;
  1991.   if (db)
  1992.     s1[i]=0;
  1993.   chdir(s1);
  1994.   if (s[1]==':')
  1995.     setdisk(s[0]-'A');
  1996. }
  1997.  
  1998. void setup_stuff()
  1999. {
  2000.   char s[161];
  2001.   int i;
  2002.  
  2003.     strcpy(ver_no1,"BBS=");
  2004.     strcat(ver_no1,VERSION_NUMBER);
  2005.  
  2006.  
  2007.     strcpy(s,getenv("PROMPT"));
  2008.     strcpy(newprompt,"PROMPT=WWIV: ");
  2009.     if (s[0])
  2010.       strcat(newprompt,s);
  2011.     else
  2012.       strcat(newprompt,"$P$G");
  2013.     i=0;
  2014.     while (environ[i]!=NULL) {
  2015.       if (strncmp(environ[i],"PROMPT=",7)==0)
  2016.         xenviron[i]=newprompt;
  2017.       else
  2018.         xenviron[i]=environ[i];
  2019.       ++i;
  2020.     }
  2021.     if (s[0]==0)
  2022.       xenviron[i++]=newprompt;
  2023.     xenviron[i++]=ver_no1;
  2024.     xenviron[i]=NULL;
  2025. }
  2026.  
  2027. /****************************************************************************/
  2028. void do_it_1(char *cl)
  2029. {
  2030.   char *ss1;
  2031.  
  2032.   ss1=(char far *)getvect(INT_SHRINK);
  2033.   *ss1=1;
  2034.   ss1++;
  2035.   strcpy(ss1,searchpath(cl));
  2036.   ss1=MK_FP(FP_SEG(ss1),0x0080);
  2037.   *ss1=0;
  2038.   ++ss1;
  2039.   *ss1=0x0d;
  2040.   exit(0);
  2041. }
  2042.  
  2043. /****************************************************************************/
  2044.  
  2045.  
  2046. void main(int argc, char *argv[])
  2047. {
  2048.   int i,i1;
  2049.   char s[130];
  2050.  
  2051.  
  2052.   i=atoi(argv[1]);
  2053.   ccc=atoi(argv[2]);
  2054.  
  2055.  
  2056.   get_dir(cdir,0);
  2057.  
  2058.   setup_stuff();
  2059.   if (argc>=3) {
  2060.     s[0]=0;
  2061.     for (i1=3; i1<argc; i1++) {
  2062.       strcat(s,argv[i1]);
  2063.       strcat(s," ");
  2064.     }
  2065.     if (i) {
  2066.       if (!init_r()) {
  2067.         if (incom || outcom)
  2068.           screenbottom=thisuser.screenlines-1;
  2069.         else
  2070.           screenbottom=defscreenbottom;
  2071.         screenlinest=screenbottom+1;
  2072.         full_external(s,ccc);
  2073.         pl("Returning...");
  2074.         if (ok_modem_stuff)
  2075.           closeport();
  2076.         setvect(INT_POINT_FUNCS,NULL);
  2077.       } else
  2078.         pl("Couldn't find data");
  2079.     } else
  2080.       do_remote(s,ccc);
  2081.   }
  2082.   cd_to(cdir);
  2083.   do_it_1("BBS.EXE");
  2084. }
  2085.  
  2086.