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

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