home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / W / DEVBBS.ZIP / RETURN.C < prev    next >
C/C++ Source or Header  |  1992-07-20  |  44KB  |  1,924 lines

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