home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / WWIV2.ZIP / EXTRN.C < prev    next >
C/C++ Source or Header  |  1992-12-30  |  14KB  |  675 lines

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1993 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 "vars.h"
  18.  
  19. #pragma hdrstop
  20.  
  21. #include <dir.h>
  22. #include <process.h>
  23. #include <math.h>
  24.  
  25.  
  26. static int checking_event;
  27.  
  28. #define SCROLL_UP(t,b,l) \
  29.   _CH=t;\
  30.   _DH=b;\
  31.   _BH=curatr;\
  32.   _AL=l;\
  33.   _CL=0;\
  34.   _DL=79;\
  35.   _AH=6;\
  36.   my_video_int();
  37.  
  38.  
  39. unsigned char getkeyext(void)
  40. {
  41.   unsigned char ch;
  42.   static int holding=0;
  43.   static char held=0;
  44.  
  45.   if (holding) {
  46.     holding=0;
  47.     return(held);
  48.   }
  49.   ch=getkey();
  50.   if (charbufferpointer==0) {
  51.     if (ch==16) {
  52.       ch=getkey();
  53.       if ((ch==1) && (charbufferpointer==0)) {
  54.         strcpy(charbuffer,&(thisuser.macros[2][0]));
  55.         ch=charbuffer[0];
  56.         if (ch) {
  57.           charbufferpointer=1;
  58.       return(ch);
  59.         } else
  60.       return(getkeyext());
  61.       } else
  62.         if ((ch==4) && (charbufferpointer==0)) {
  63.           strcpy(charbuffer,&(thisuser.macros[0][0]));
  64.           ch=charbuffer[0];
  65.           if (ch) {
  66.             charbufferpointer=1;
  67.         return(ch);
  68.           } else
  69.         return(getkeyext());
  70.         } else
  71.           if ((ch==6) && (charbufferpointer==0)) {
  72.             strcpy(charbuffer,&(thisuser.macros[1][0]));
  73.             ch=charbuffer[0];
  74.             if (ch) {
  75.               charbufferpointer=1;
  76.           return(ch);
  77.             } else
  78.           return(getkeyext());
  79.           } else {
  80.             holding=1;
  81.         held=ch;
  82.             return(16);
  83.           }
  84.     }
  85.   }
  86.   return(ch);
  87. }
  88.  
  89.  
  90. void cd_to(char *s)
  91. {
  92.   char s1[81];
  93.   int i,db;
  94.  
  95.   strcpy(s1,s);
  96.   i=strlen(s1)-1;
  97.   db=(s1[i]=='\\');
  98.   if (i==0)
  99.     db=0;
  100.   if ((i==2) && (s1[1]==':'))
  101.     db=0;
  102.   if (db)
  103.     s1[i]=0;
  104.   chdir(s1);
  105.   if (s[1]==':')
  106.     setdisk(s[0]-'A');
  107. }
  108.  
  109. void get_dir(char *s, int be)
  110. {
  111.   strcpy(s,"X:\\");
  112.   s[0]='A'+getdisk();
  113.   getcurdir(0,&(s[3]));
  114.   if (be) {
  115.     if (s[strlen(s)-1]!='\\')
  116.       strcat(s,"\\");
  117.   }
  118. }
  119.  
  120.  
  121. void initporte(int port_num)
  122. /* This function initializes the com buffer, setting up the interrupt,
  123.  * and com parameters
  124.  */
  125. {
  126.   int temp;
  127.  
  128.   if (!ok_modem_stuff)
  129.     return;
  130.   temp=port_num;
  131.   setvect(8+async_irq,async_isr);
  132.   head=tail=0;
  133.   outportb(base+3,0x03);
  134.   disable();
  135.   temp=inportb(base+5);
  136.   temp=inportb(base);
  137.   temp=inportb(0x21);
  138.   temp=temp & ((1 << async_irq) ^ 0x00ff);
  139.   outportb(0x21,temp);
  140.   outportb(base+1,0x01);
  141.   temp=inportb(base+4);
  142.   outportb(base+4,temp | 0x0A);
  143.   enable();
  144.   dtr(1);
  145.   reset_colors();
  146.   ansic(0);
  147. }
  148.  
  149.  
  150.  
  151. int do_it(char *cl)
  152. {
  153.   int i,i1,l;
  154.   char s[160];
  155.   char *ss[30];
  156.  
  157.   sl1(1,"");
  158.   strcpy(s,cl);
  159.   ss[0]=s;
  160.   i=1;
  161.   l=strlen(s);
  162.   for (i1=1; i1<l; i1++)
  163.     if (s[i1]==32) {
  164.       s[i1]=0;
  165.       ss[i++]=&(s[i1+1]);
  166.     }
  167.   ss[i]=NULL;
  168.   funcs[20]=NULL;
  169.   i=spawnvpe(P_WAIT,ss[0],ss,xenviron);
  170.   funcs[20]=NULL;
  171.   return(i);
  172. }
  173.  
  174.  
  175.  
  176. int do_remote(char *s, int ccc)
  177. {
  178.   int rc,xx;
  179.   char x[161];
  180.  
  181.   sl1(1,"");
  182.   close_user();
  183.   close_strfiles();
  184.   if (!checking_event) {
  185.     checkhangup();
  186.     if (hangup)
  187.       return(32767);
  188.   }
  189.   sprintf(x,"%s /C %s", getenv("COMSPEC"), s);
  190.   if (ccc)
  191.     rc=do_it(x);
  192.   else
  193.     rc=do_it(s);
  194.   initporte(syscfg.primaryport);
  195.   chdir(cdir);
  196.   setdisk(cdir[0]-'A');
  197.   return(rc);
  198. }
  199.  
  200. void checka1(void)
  201. {
  202.   char ch;
  203.   long d1;
  204.  
  205.   while ((!empty()) && (!(abortext)) && (!hangup)) {
  206.     ch=inkey();
  207.     switch(ch) {
  208.       case 3:
  209.       case 32:
  210.       case 24:
  211.         abortext=1;
  212.         break;
  213.       case 'P':
  214.       case 'p':
  215.       case 19:
  216.         d1=timer1();
  217.         while ((inkey()==0) && (labs(timer1()-d1)<3276L) && (!hangup))
  218.           checkhangup();
  219.         lines_listed=0;
  220.         break;
  221.     }
  222.   }
  223. }
  224.  
  225.  
  226. union REGS ca_r;
  227. int ca_pause,ca_ctrl_c;
  228. long ca_d1;
  229.  
  230.  
  231. void checka2(void)
  232. {
  233.   ca_pause=0;
  234.   ca_ctrl_c=0;
  235.   ca_r.h.ah=1;
  236.   int86(0x16,&ca_r,&ca_r);
  237.   if ((ca_r.x.flags & 64)==0) {
  238.     if (ca_r.x.ax==11779)
  239.       ca_ctrl_c=1;
  240.     if (ca_r.x.ax==7955)
  241.       ca_pause=1;
  242.   }
  243.   if (head!=tail) {
  244.     if (buffer[tail]==3)
  245.       ca_ctrl_c=1;
  246.     if (buffer[tail]==19)
  247.       ca_pause=1;
  248.   }
  249.   if (ca_pause) {
  250.     while (inkey()!=0)
  251.       ;
  252.     ca_d1=timer1();
  253.     while ((inkey()==0) && (labs(timer1()-ca_d1)<3276L) && (!hangup))
  254.       checkhangup();
  255.     lines_listed=0;
  256.   }
  257.   if ((ca_ctrl_c) && (nextext)) {
  258.     while (inkey()!=0)
  259.       ;
  260.     pl("^C");
  261.     ca_r.x.ax=0x4c00;
  262.     int86(save_dos,&ca_r,&ca_r);
  263.   }
  264. }
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271. int run_external(char *s)
  272. {
  273.   return(do_remote(s,1));
  274. }
  275.  
  276.  
  277. int run_external_ul(char *s)
  278. {
  279.   int i;
  280.  
  281.   checking_event=1;
  282.   i=do_remote(s,1);
  283.   checking_event=0;
  284.   return(i);
  285. }
  286.  
  287.  
  288.  
  289. int run_external1(char *s)
  290. {
  291.   return(do_remote(s,0));
  292. }
  293.  
  294.  
  295.  
  296. void outdosstr(char *s)
  297. /* This function outputs a string of characters to the screen (and remotely
  298.  * if applicable).  The com port is also checked first to see if a remote
  299.  * user has hung up
  300.  */
  301. {
  302.   int i;
  303.  
  304.   checkhangup();
  305.   if (hangup==0) {
  306.     i=0;
  307.     while ((s[i] !='$') && (i<1024)) {
  308.       checka2();
  309.       outchr(s[i++]);
  310.     }
  311.   }
  312. }
  313.  
  314.  
  315. union REGS ni_r;
  316. struct SREGS ni_s;
  317. unsigned ni_n;
  318. char ni_ch,ni_ch1,ni_ss[10],ni_ch2;
  319. unsigned char *ni_st;
  320.  
  321. #define ST_SIZE 500
  322. static unsigned short ni_stack[ST_SIZE];
  323.  
  324.  
  325. #pragma warn -par
  326.  
  327. void far interrupt newintr1(unsigned bp, unsigned di, unsigned si,
  328.                            unsigned ds, unsigned es, unsigned dx,
  329.                            unsigned cx, unsigned bx, unsigned ax,
  330.                            unsigned ip, unsigned cs, unsigned flags)
  331. {
  332.  
  333.   unsigned short ni_SS, ni_SP;
  334. #define NEW_STK() { _BX=FP_OFF(&ni_stack[ST_SIZE-2]); _SS=_DS; _SP=_BX; }
  335. #define OLD_STK() { _AX=ni_SS; _BX=ni_SP; _SS=_AX; _SP=_BX; }
  336.  
  337.  
  338.  
  339.   ni_r.x.ax=ax;
  340.   ni_r.x.bx=bx;
  341.   ni_r.x.cx=cx;
  342.   ni_r.x.dx=dx;
  343.   ni_r.x.si=si;
  344.   ni_r.x.di=di;
  345.   ni_r.x.flags=flags;
  346.   ni_s.ds=ds;
  347.   ni_s.es=es;
  348.  
  349.   ni_SS=_SS;
  350.   ni_SP=_SP;
  351.  
  352.   ni_ch=ni_r.h.ah;
  353.   ni_ch1=0;
  354.  
  355.   switch(ni_ch) {
  356.     case 0x01:
  357.       NEW_STK();
  358.       ni_ch=getkeyext();
  359.       outchr(ni_ch);
  360.       if (hangup)
  361.         ni_ch=3;
  362.       ni_r.h.al=ni_ch;
  363.       ni_ch1=1;
  364.       OLD_STK();
  365.       break;
  366.     case 0x02:
  367.       NEW_STK();
  368.       outchr(ni_r.h.dl);
  369.       ni_ch1=1;
  370.       checka2();
  371.       OLD_STK();
  372.       break;
  373.     case 0x06:
  374.       NEW_STK();
  375.       if (ni_r.h.dl!=0xff) {
  376.         outchr(ni_r.h.dl);
  377.         ni_ch1=1;
  378.       } else {
  379.         if (empty()) {
  380.           ni_r.x.flags |= 64;
  381.         } else {
  382.           ni_r.x.flags &= (0xffff ^ 64);
  383.           ni_r.h.al=getkeyext();
  384.         }
  385.       }
  386.       OLD_STK();
  387.       break;
  388.     case 0x07:
  389.       NEW_STK();
  390.       ni_ch1=1;
  391.       ni_r.h.al=getkeyext();
  392.       OLD_STK();
  393.       break;
  394.     case 0x08:
  395.       NEW_STK();
  396.       ni_ch1=1;
  397.       ni_r.h.al=getkeyext();
  398.       OLD_STK();
  399.       break;
  400.     case 0x09:
  401.       NEW_STK();
  402.       outdosstr((char *) MK_FP(ni_s.ds, ni_r.x.dx));
  403.       ni_ch1=1;
  404.       OLD_STK();
  405.       break;
  406.     case 0x0a:
  407.       NEW_STK();
  408.       ni_st=(char *) MK_FP(ni_s.ds,ni_r.x.dx);
  409.       ni_n=(unsigned int)(ni_st[0]);
  410.       if (in_extern==2)
  411.         getkeyext();
  412.       in_extern=0;
  413.       input_extern=1;
  414.       input1(&(ni_st[2]),ni_n-3,1,0);
  415.       input_extern=0;
  416.       in_extern=1;
  417.       ni_st[1]=strlen(&(ni_st[2]));
  418.       strcat(&(ni_st[2]),"\r");
  419.       if ((hangup)) {
  420.         strcpy(&(ni_st[2]),"EXIT\r");
  421.         ni_st[1]=4;
  422.         outs("Exiting...");
  423.       }
  424.       ni_ch1=1;
  425.       OLD_STK();
  426.       break;
  427.     case 0x0b:
  428.       NEW_STK();
  429.       if (empty())
  430.         ni_r.h.al=0x00;
  431.       else
  432.         ni_r.h.al=0xff;
  433.       ni_ch1=1;
  434.       OLD_STK();
  435.       break;
  436.     case 0x0c:
  437.       ni_r.h.ah=ni_r.h.al;
  438.       int86x(INT_REAL_DOS,&ni_r,&ni_r,&ni_s);
  439.       ni_ch1=1;
  440.       break;
  441.     case 0x3f:
  442.       if (ni_r.x.bx==0x0000) {
  443.         NEW_STK();
  444.         ni_st=(char *)MK_FP(ni_s.ds,ni_r.x.dx);
  445.         inputl(ni_st,ni_r.x.cx);
  446.         strcat(ni_st,"\r\n");
  447.         ni_r.x.ax=strlen(ni_st);
  448.         if (hangup)
  449.           ni_r.x.ax=0;
  450.         ni_r.x.flags &=(0xffff ^ 1);
  451.         ni_ch1=1;
  452.         OLD_STK();
  453.       } else
  454.         int86x(save_dos,&ni_r,&ni_r,&ni_s);
  455.       break;
  456.     case 0x40:
  457.       if ((ni_r.x.bx==0x0001) || (ni_r.x.bx==0x0002)) {
  458.         NEW_STK();
  459.         ni_st=(char *)MK_FP(ni_s.ds,ni_r.x.dx);
  460.         for (ni_n=0; ni_n<ni_r.x.cx; ni_n++) {
  461.           outchr(ni_st[ni_n]);
  462.           checka2();
  463.         }
  464.         ni_r.x.ax=ni_r.x.cx;
  465.         ni_r.x.flags &=(0xffff ^ 1);
  466.         ni_ch1=1;
  467.         OLD_STK();
  468.       } else
  469.         int86x(save_dos,&ni_r,&ni_r,&ni_s);
  470.       break;
  471.     default:
  472.       int86x(save_dos,&ni_r,&ni_r,&ni_s);
  473.       break;
  474.   }
  475.  
  476.   if (ni_ch1) {
  477.     if (arcling) {
  478.       if ((nextext) && (!abortext)) {
  479.         checka1();
  480.         if (abortext) {
  481.           ni_r.x.ax=0x4c00;
  482.           int86x(save_dos,&ni_r,&ni_r,&ni_s);
  483.         }
  484.       }
  485.     }
  486.     checkhangup();
  487.     if (hangup) {
  488.       if (hanguptime1<0L) {
  489.         hanguptime1=timer1();
  490.         if (funcs[20]) {
  491.           outs("Terminating...\r\n");
  492.           ip=FP_OFF(funcs[20]);
  493.           cs=FP_SEG(funcs[20]);
  494.           funcs[20]=(void far *)36;
  495.         } else {
  496.           funcs[20]=(void far *)36;
  497.           outs("Aborting...\r\n");
  498.           ni_r.x.ax=0x4c00;
  499.           int86x(save_dos,&ni_r,&ni_r,&ni_s);
  500.         }
  501.       } else {
  502.         if (((unsigned long) funcs[20])>500)
  503.           funcs[20]=(void far *)36;
  504.         if (labs(timer1()-hanguptime1)>(long)funcs[20]) {
  505.           hanguptime1=timer1();
  506.           outs("Aborting...\r\n");
  507.           ni_r.x.ax=0x4c00;
  508.           int86x(save_dos,&ni_r,&ni_r,&ni_s);
  509.         }
  510.       }
  511.     }
  512.   }
  513.  
  514.   ax=ni_r.x.ax;
  515.   bx=ni_r.x.bx;
  516.   cx=ni_r.x.cx;
  517.   dx=ni_r.x.dx;
  518.   si=ni_r.x.si;
  519.   di=ni_r.x.di;
  520.   flags=ni_r.x.flags;
  521.   ds=ni_s.ds;
  522.   es=ni_s.es;
  523. }
  524.  
  525.  
  526. #pragma warn +par
  527.  
  528. int do_external(char *s, int enab)
  529. {
  530.   unsigned short sav;
  531.   int ookskey;
  532.  
  533.   checkhangup();
  534.   if (hangup)
  535.     return(0);
  536.   in_extern=1;
  537.   hanguptime1=-1L;
  538.   abortext=0;
  539.   nextext=enab;
  540.   arcling=1;
  541.   ookskey=okskey;
  542.   okskey=0;
  543.   sav=syscfg.sysconfig;
  544.   if ((syscfg.sysconfig & sysconfig_no_local)==0)
  545.     syscfg.sysconfig |= sysconfig_no_local;
  546.   setvect(save_dos,getvect(INT_REAL_DOS));
  547.  
  548.   set_global_handle(0);
  549.  
  550.   setvect(INT_REAL_DOS,newintr1);
  551.  
  552.   do_remote(s,1);
  553.  
  554.   setvect(INT_REAL_DOS,getvect(save_dos));
  555.  
  556.   if (abortext) {
  557.     nl();
  558.     nl();
  559.   }
  560.  
  561.   syscfg.sysconfig=sav;
  562.   if (in_extern==2)
  563.     getkey();
  564.   in_extern=0;
  565.   okskey=ookskey;
  566.   return(abortext);
  567. }
  568.  
  569.  
  570. int full_external(char *s, int ctc, int ccc)
  571. {
  572.   unsigned short sav;
  573.   int ookskey,xx,cy,cx,xxx;
  574.  
  575.   sl1(1,"");
  576.   checkhangup();
  577.   if (hangup)
  578.     return(0);
  579.   in_extern=1;
  580.   ookskey=okskey;
  581.   okskey=0;
  582.   hanguptime1=-1L;
  583.   arcling=0;
  584.   if (screenlinest>defscreenbottom-topline)
  585.     set_protect(0);
  586.   abortext=0;
  587.   nextext=ctc;
  588.   sav=syscfg.sysconfig;
  589.   if ((syscfg.sysconfig & sysconfig_no_local)==0)
  590.     syscfg.sysconfig |= sysconfig_no_local;
  591.  
  592.   setvect(save_dos,getvect(INT_REAL_DOS));
  593.  
  594.   set_global_handle(0);
  595.  
  596.   setvect(INT_REAL_DOS,newintr1);
  597.  
  598.   if ((screenlinest<=defscreenbottom) && (screenlinest>20)) {
  599.     screenbottom=screenlinest-1+topline;
  600.     cy=wherey();
  601.     cx=wherex();
  602.     xxx=cy-screenbottom+topline;
  603.     if (xxx>0) {
  604.       SCROLL_UP(topline,defscreenbottom,xxx);
  605.       movecsr(cx,screenbottom);
  606.     }
  607.   }
  608.  
  609.   do_remote(s,ccc);
  610.  
  611.   screenbottom=defscreenbottom;
  612.  
  613.   setvect(INT_REAL_DOS,getvect(save_dos));
  614.  
  615.   if (abortext) {
  616.     nl();
  617.     nl();
  618.   }
  619.  
  620.   syscfg.sysconfig=sav;
  621.   okskey=ookskey;
  622.   if (in_extern==2)
  623.     getkey();
  624.   in_extern=0;
  625.   if (!wfc)
  626.     topscreen();
  627.   return(abortext);
  628. }
  629.  
  630. char *create_chain_file(char *fn)
  631. {
  632.   int i,i1;
  633.   char s[81],s1[81],gd[81],dd[81];
  634.   static char fpn[81];
  635.   long l,l1;
  636.   FILE *f;
  637.  
  638.   cd_to(syscfg.gfilesdir);
  639.   get_dir(gd,1);
  640.   cd_to(cdir);
  641.   cd_to(syscfg.datadir);
  642.   get_dir(dd,1);
  643.   cd_to(cdir);
  644.   sl1(3,s);
  645.   l=(long) (timeon);
  646.   if (l<0)
  647.     l += 3600*24;
  648.   l1=(long) (timer()-timeon);
  649.   if (l1<0)
  650.     l1 += 3600*24;
  651.  
  652.   unlink(fn);
  653.   f=fopen(fn,"wt");
  654.   if (f) {
  655.     fprintf(f,"%d\n%s\n%s\n%s\n%d\n%c\n%10.2f\n%s\n%d\n%d\n%u\n",
  656.             usernum, thisuser.name, thisuser.realname, thisuser.callsign,
  657.             thisuser.age, thisuser.sex, thisuser.gold, thisuser.laston,
  658.             thisuser.screenchars, thisuser.screenlines, thisuser.sl);
  659.     fprintf(f,"%d\n%d\n%d\n%d\n%10.2f\n%s\n%s\n%s\n",
  660.             cs(),so(),okansi(), incom, nsl(), gd, dd, s);
  661.     if (using_modem)
  662.       fprintf(f,"%u\n",modem_speed);
  663.     else
  664.       fprintf(f,"KB\n");
  665.     fprintf(f,"%d\n%s\n%s\n%ld\n%ld\n%lu\n%u\n%lu\n%u\n%s\n%u\n%u\n",
  666.             syscfg.primaryport, syscfg.systemname, syscfg.sysopname, l, l1,
  667.             thisuser.uk, thisuser.uploaded, thisuser.dk, thisuser.downloaded,
  668.             (andwith==0x7f)?"7E1":"8N1", com_speed, net_sysnum);
  669.     fclose(f);
  670.   }
  671.   get_dir(fpn,1);
  672.   strcat(fpn,fn);
  673.   return(fpn);
  674. }
  675.