home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / W / WWIVSOR.ZIP / EXTRN1.C < prev    next >
C/C++ Source or Header  |  1995-05-06  |  25KB  |  1,004 lines

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1995 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 <process.h>
  22.  
  23. #ifndef __OS2__
  24. extern void far interrupt newintr1();
  25. extern int shrink_out_1(char *cmdline, unsigned short flags);
  26. #endif
  27.  
  28. #define READ(x) sh_read(f,&(x),sizeof(x))
  29. #define WRITE(x) sh_write(f,&(x),sizeof(x))
  30.  
  31. #ifndef __OS2__
  32. #ifdef RIPDRIVE
  33.   extern char *kbptr, keybuffer[768];
  34. #endif
  35. #define SCROLL_UP(t,b,l) \
  36.   _CH=t;\
  37.   _DH=b;\
  38.   _BH=curatr;\
  39.   _AL=l;\
  40.   _CL=0;\
  41.   _DL=79;\
  42.   _AH=6;\
  43.   my_video_int();
  44. #endif
  45.  
  46. /****************************************************************************/
  47.  
  48. static void initporte(int port_num)
  49. /* This function initializes the com buffer, setting up the interrupt,
  50.  * and com parameters
  51.  */
  52. {
  53. #ifdef __OS2__
  54.   (void) port_num;
  55. #else
  56.   int temp;
  57.  
  58.   if (!ok_modem_stuff)
  59.     return;
  60.   disable();
  61.   temp=port_num;
  62.   setvect(ISR_VECT(async_irq),async_isr);
  63.   head=tail=0;
  64.   outportb(base+3,0x03);
  65.   temp=inportb(base+5);
  66.   temp=inportb(base);
  67.   temp=inportb(ISR_CTRLR(async_irq));
  68.   temp=temp & ((1 << (async_irq%8)) ^ 0x00ff);
  69.   outportb(ISR_CTRLR(async_irq),temp);
  70.   outportb(base+1,0x01);
  71.   temp=inportb(base+4);
  72.   outportb(base+4,temp | 0x0A);
  73.   enable();
  74.   dtr(1);
  75.   reset_colors();
  76.   ansic(0);
  77. #endif
  78. }
  79.  
  80. /****************************************************************************/
  81.  
  82. static int do_it(char *cl)
  83. {
  84.   int i,i1,l;
  85.   char s[256];
  86.   char *ss[30];
  87.  
  88.   strcpy(s,cl);
  89.   ss[0]=s;
  90.   i=1;
  91.   l=strlen(s);
  92.   for (i1=1; i1<l; i1++)
  93.     if (s[i1]==32) {
  94.       s[i1]=0;
  95.       ss[i++]=&(s[i1+1]);
  96.     }
  97.   ss[i]=NULL;
  98.   funcs[20]=NULL;
  99.   i=spawnvpe(P_WAIT,ss[0],ss,xenviron);
  100.   funcs[20]=NULL;
  101.   return(i);
  102. }
  103.  
  104. /****************************************************************************/
  105.  
  106. int extern_prog(char *cmdline, unsigned short flags)
  107. {
  108.   char cmdline1[255], cmdline2[255], save_net[255], *ss;
  109.   int rc=-1, sb, ookskey, ogh, cx, cy, xxx, dotop=0, i,i1;
  110.   unsigned long osysstatus;
  111.   unsigned short osysconfig;
  112.   char restorefn[81], statfn[81];
  113.   void interrupt far (*saveint)();
  114. #define SHRINK_ENVIRON
  115. #ifdef SHRINK_ENVIRON
  116.   unsigned short envseg;
  117.   char *env, *env1;
  118.   unsigned short far *envptr;
  119.   int count;
  120. #endif
  121. #define SAVE_ENV
  122. #ifdef SAVE_ENV
  123.   unsigned short es_seg;
  124.   long es_len;
  125.   char *es_ptr;
  126.   char far *es_rptr;
  127. #endif
  128.  
  129.   rip_popup=0;
  130.  
  131.   /* store flags */
  132.   eflags = flags;
  133.  
  134.   /* forget it if the user has hung up */
  135.   if (!(eflags & EFLAG_NOHUP)) {
  136.     checkhangup();
  137.     if (hangup)
  138.       return(-1);
  139.   }
  140.  
  141.   /* get local copy of commandline */
  142.   strcpy(cmdline1, cmdline);
  143.  
  144.   if (eflags & EFLAG_NETPROG) {
  145.     strcpy(save_net, cmdline1);
  146.     sprintf(cmdline1, "%s%s", net_data, save_net);
  147.   } else {
  148.     save_net[0]=0;
  149.   }
  150.  
  151. net_retry:
  152.  
  153.   /* make it into absolute pathname, if not already done so */
  154.   make_abs_cmd(cmdline1);
  155.  
  156.   /* use command.com if a .BAT file */
  157.   strcpy(cmdline2, cmdline1);
  158.   strtok(cmdline2, " \t");
  159.   if (strlen(cmdline2)>4) {
  160.     ss=cmdline2+strlen(cmdline2)-4;
  161.     if (stricmp(ss,".exe") && stricmp(ss,".com")) {
  162.       if (stricmp(ss,".bat")) {
  163.         if (save_net[0]) {
  164.           strcpy(cmdline1, save_net);
  165.           save_net[0]=0;
  166.           goto net_retry;
  167.         }
  168.         return(-1);
  169.       } else {
  170.         sprintf(cmdline2, "%s /C %s", getenv("COMSPEC"), cmdline1);
  171.         strcpy(cmdline1, cmdline2);
  172.       }
  173.     }
  174.   } else {
  175.     if (save_net[0]) {
  176.       strcpy(cmdline1, save_net);
  177.       save_net[0]=0;
  178.       goto net_retry;
  179.     }
  180.     return(-1);
  181.   }
  182.  
  183.   /* get ready to run it */
  184.   sb=base;
  185.   sl1(1,"");
  186.   if (useron) {
  187.     write_user(usernum,&thisuser);
  188.     write_qscn(usernum,qsc,0);
  189.   }
  190.   close_strfiles();
  191.   ookskey=okskey;
  192.   okskey=0;
  193.   in_extern=1;
  194.   hanguptime1=-1L;
  195.   abortext=0;
  196.   ogh=global_handle;
  197.   set_global_handle(0);
  198.  
  199.  
  200.   /* ensure return.exe is there for shrinking with COMIO */
  201.   if ((eflags & EFLAG_SHRINK) && (eflags & EFLAG_COMIO)) {
  202.     sprintf(cmdline2, "%s\\RETURN.EXE", cdir);
  203.     if (!exist(cmdline2)) {
  204.       nl();
  205.       pl(get_string(885));
  206.       nl();
  207.       eflags &= ~EFLAG_SHRINK;
  208.     }
  209.   }
  210.  
  211.   /* need files for return.exe */
  212.   if ((eflags & EFLAG_SHRINK) && (eflags & EFLAG_COMIO)) {
  213.     eflags |= EFLAG_FILES;
  214.   }
  215.  
  216.   /* make shrink files, if needed */
  217.   if (eflags & EFLAG_FILES) {
  218.     save_state(0, eflags&EFLAG_ABORT, restorefn, statfn);
  219.   }
  220.  
  221.   /* extra processing for net programs */
  222.   if (eflags & EFLAG_NETPROG) {
  223.     write_inst(INST_LOC_NET, net_num+1, INST_FLAGS_NONE);
  224.  
  225.     /* create WWIV_NET.DAT, if needed */
  226.     if ((eflags & EFLAG_SHRINK) && (status.net_version<33)) {
  227.       sprintf(cmdline2,"%d\r\n",net_num);
  228.       i=sh_open("WWIV_NET.DAT",O_RDWR|O_BINARY|O_TRUNC|O_CREAT, S_IREAD|S_IWRITE);
  229.       if (i>0) {
  230.         sh_write(i,cmdline2,strlen(cmdline2));
  231.         sh_close(i);
  232.       }
  233.     }
  234.   }
  235.  
  236. #ifdef SAVE_ENV
  237.   es_seg = *((unsigned short far *) MK_FP(_psp, 0x2c));
  238.   es_rptr=MK_FP(es_seg, 0);
  239.   es_len = ((long) (*((unsigned short far *) MK_FP(es_seg-1, 3)))) * 16L;
  240.   es_ptr=bbsmalloc(es_len);
  241.   if (es_ptr) {
  242.     memcpy(es_ptr, es_rptr, es_len);
  243.   }
  244. #endif
  245.  
  246.   /* run it */
  247.   if (eflags & EFLAG_SHRINK) {
  248.     /* shrink */
  249.     if (!(eflags & EFLAG_TOPSCREEN)) {
  250.       set_protect(0);
  251.       dotop=1;
  252.     }
  253.  
  254.     if (eflags & EFLAG_COMIO) {
  255.       sprintf(cmdline2, "%s\\RETURN.EXE 1 0 %s", cdir, cmdline1);
  256.       strcpy(cmdline1, cmdline2);
  257.     }
  258.  
  259.     if (ok_modem_stuff)
  260.       closeport();
  261.  
  262.     saveint=getvect(save_dos);
  263.     setvect(save_dos,NULL);
  264. #ifdef SHRINK_ENVIRON
  265.     envptr=MK_FP(_psp, 0x2c);
  266.     envseg=*envptr;
  267.     count=20;
  268.     for (i=0; xenviron[i]; i++)
  269.       count += strlen(xenviron[i])+1;
  270.     env=(char *)malloca(count);
  271.     if (env) {
  272.       count=(((long)env)%16);
  273.       if (count)
  274.         env1= (env+16-count);
  275.       else
  276.         env1= env;
  277.       count=0;
  278.       for (i=0; xenviron[i]; i++) {
  279.         if (strncmp(xenviron[i],"WWIV_FP=",8)) {
  280.           strcpy((char *) (env1+count), xenviron[i]);
  281.           count += strlen(xenviron[i])+1;
  282.         }
  283.       }
  284.       env1[count]=0;
  285.       *envptr=FP_SEG(env1) + (FP_OFF(env1)/16);
  286.     }
  287. #endif
  288.     rc=shrink_out_1(cmdline1, 0);
  289. #ifdef SHRINK_ENVIRON
  290.     if (env) {
  291.       *envptr=envseg;
  292.       bbsfree(env);
  293.     }
  294. #endif
  295.     setvect(save_dos,saveint);
  296.  
  297.   } else {
  298.     /* don't shrink */
  299.  
  300.     /* set up for comio redirect, if needed */
  301.     if (eflags & EFLAG_COMIO) {
  302.       if (!(eflags & EFLAG_INTERNAL) && !(eflags & EFLAG_TOPSCREEN)) {
  303.         if (screenlinest>defscreenbottom-topline) {
  304.           set_protect(0);
  305.           dotop=1;
  306.         }
  307.  
  308.         if ((screenlinest<=defscreenbottom) && (screenlinest>20)) {
  309.           screenbottom=screenlinest-1+topline;
  310.           cy=WhereY();
  311.           cx=WhereX();
  312.           xxx=cy-screenbottom+topline;
  313.           if (xxx>0) {
  314.             SCROLL_UP(topline,defscreenbottom,xxx);
  315.             movecsr(cx,screenbottom);
  316.           }
  317.         }
  318.  
  319.       }
  320.  
  321.       setvect(save_dos, getvect(INT_REAL_DOS));
  322.       setvect(INT_REAL_DOS, newintr1);
  323.       osysconfig=syscfg.sysconfig;
  324.       syscfg.sysconfig |= sysconfig_no_local;
  325.     } else {
  326.       if (!(eflags & EFLAG_TOPSCREEN)) {
  327.         set_protect(0);
  328.         dotop=1;
  329.       }
  330.     }
  331.  
  332.     /* disable pause, if needed */
  333.     if (eflags & EFLAG_NOPAUSE) {
  334.       osysstatus=thisuser.sysstatus;
  335.       thisuser.sysstatus &= ~sysstatus_pause_on_page;
  336.     }
  337.  
  338.     /* do it */
  339.     rc=do_it(cmdline1);
  340.  
  341.     /* re-enable pause, if needed */
  342.     if (eflags & EFLAG_NOPAUSE) {
  343.       thisuser.sysstatus=osysstatus;
  344.     }
  345.  
  346.     /* undo comio redirect, if needed */
  347.     if (eflags & EFLAG_COMIO) {
  348.       setvect(INT_REAL_DOS, getvect(save_dos));
  349.       if (abortext) {
  350.         nln(2);
  351.         if (!rc)
  352.           rc=1;
  353.       }
  354.       syscfg.sysconfig=osysconfig;
  355.       if (!(eflags & EFLAG_INTERNAL)) {
  356.         screenbottom=defscreenbottom;
  357.       }
  358.     }
  359.   }
  360.  
  361. #ifdef SAVE_ENV
  362.   if (es_ptr) {
  363.     memcpy(es_rptr, es_ptr, es_len);
  364.     bbsfree(es_ptr);
  365.     es_ptr=NULL;
  366.   }
  367. #endif
  368.  
  369.   /* remove shrink files, if needed */
  370.   if (eflags & EFLAG_FILES) {
  371.     _chmod(restorefn, 1, 0);
  372.     _chmod(statfn, 1, 0);
  373.     unlink(restorefn);
  374.     unlink(statfn);
  375.   }
  376.  
  377.   /* kill no-longer-required WWIV_NET.DAT file, if needed */
  378.   if ((eflags & EFLAG_NETPROG) && (eflags & EFLAG_SHRINK)) {
  379.     unlink("WWIV_NET.DAT");
  380.   }
  381.  
  382.   /* clean up */
  383.   cd_to(cdir);
  384.   base=sb;
  385.   initporte(syscfgovr.primaryport);
  386.   if (useron) {
  387.     i=useron;
  388.     i1=wfc;
  389.     useron=0;
  390.     wfc=0;
  391.     read_user(usernum,&thisuser);
  392.     read_qscn(usernum,qsc,0);
  393.     useron=i;
  394.     wfc=i1;
  395.   }
  396.   okskey=ookskey;
  397.   if (in_extern==2)
  398.     getkey();
  399.   in_extern=0;
  400.   if (dotop && useron)
  401.     topscreen();
  402.   if (ogh)
  403.     set_global_handle(1);
  404.  
  405.   rip_popup = -1;
  406. #ifdef RIPDRIVE
  407.   if (rd_on()) {
  408.     delaykey(1);
  409.   }
  410.   kbptr = NULL;
  411.   *keybuffer = 0;
  412. #endif
  413.  
  414.   /* return to caller */
  415.   return(rc);
  416. }
  417.  
  418. /****************************************************************************/
  419. /****************************************************************************/
  420. /****************************************************************************/
  421.  
  422. void create_filename(int which, char *name)
  423. {
  424.   switch(which) {
  425.     case CHAINFILE_CHAIN:
  426.       if (instance>1)
  427.         sprintf(name,"%s\\CHAIN.%3.3d", cdir, instance);
  428.       else
  429.         sprintf(name,"%s\\CHAIN.TXT", cdir);
  430.       break;
  431.     case CHAINFILE_DORINFO:
  432.       if (instance < 10)
  433.         sprintf(name,"%s\\DORINFO%d.DEF",cdir, instance);
  434.       else if (instance==10)
  435.         sprintf(name,"%s\\DORINFO0.DEF", cdir);
  436.       else if (instance < 37)
  437.         sprintf(name,"%s\\DORINFO%c.DEF",cdir, instance-10+'@');
  438.       else
  439.         sprintf(name,"%s\\DORINFO.%3.3d",cdir, instance);
  440.       break;
  441.     case CHAINFILE_PCBOARD:
  442.       if (instance>1)
  443.         sprintf(name,"%s\\PCBOARD.%3.3d", cdir, instance);
  444.       else
  445.         sprintf(name,"%s\\PCBOARD.SYS", cdir);
  446.       break;
  447.     case CHAINFILE_CALLINFO:
  448.       if (instance>1)
  449.         sprintf(name,"%s\\CALLINFO.%3.3d", cdir, instance);
  450.       else
  451.         sprintf(name,"%s\\CALLINFO.BBS", cdir);
  452.       break;
  453.     case CHAINFILE_DOOR:
  454.       if (instance>1)
  455.         sprintf(name,"%s\\DOOR.%3.3d", cdir, instance);
  456.       else
  457.         sprintf(name,"%s\\DOOR.SYS", cdir);
  458.       break;
  459.  
  460.     default:
  461.       /* hmm? */
  462.       strcpy(name,"NUL:");
  463.       break;
  464.   }
  465. }
  466.  
  467. /****************************************************************************/
  468.  
  469. static void getname(int wn, unsigned char *s)
  470. {
  471.   unsigned char *ss;
  472.  
  473.   if (!wn) {
  474.     ss=strchr(s,' ');
  475.     if (ss)
  476.       s[strlen(s)-strlen(ss)]=0;
  477.   } else {
  478.     ss=strrchr(s,' ');
  479.     sprintf(s,"%s",(ss)?++ss:"");
  480.   }
  481. }
  482.  
  483. /****************************************************************************/
  484.  
  485. static void create_drop_files(char *cspeed)
  486. {
  487.   char s[150],s1[81],s2[81],*ss;
  488.   int fl=-1,h1,h2,m1,m2;
  489.   double d;
  490.   pcboard_sys_rec pcb;
  491.   FILE *f;
  492.   long l;
  493.  
  494.   /* minutes left */
  495.   l=(long) (nsl()/60);
  496.   l-=1L;
  497.   if (l<0L)
  498.     l=0L;
  499.  
  500.   /* make DORINFO1.DEF (RBBS and many others) */
  501.   create_filename(CHAINFILE_DORINFO, s);
  502.   unlink(s);
  503.   f=fsh_open(s,"wt");
  504.   if (f) {
  505.     fprintf(f,"%s\n%s\n\nCOM%d\n",syscfg.systemname,syscfg.sysopname,
  506.       incom?syscfgovr.primaryport:0);
  507.     if (using_modem)
  508.       fprintf(f,"%u ",com_speed);
  509.     else
  510.       /* local speed */
  511.       fprintf(f,"0 ");
  512.     fprintf(f,"BAUD,%s\n%c\n",(andwith==0x7f)?"E,7,1":"N,8,1",
  513.             (multitasker&01?'4':'0'));
  514.     if (syscfg.sysconfig & sysconfig_no_alias) {
  515.       strcpy(s,thisuser.realname);
  516.       getname(0,s);
  517.       fprintf(f,"%s\n",s);
  518.       strcpy(s,thisuser.realname);
  519.       getname(1,s);
  520.       fprintf(f,"%s\n",s);
  521.     } else
  522.       fprintf(f,"%s\n\n",thisuser.name);
  523.     if (syscfg.sysconfig & sysconfig_extended_info)
  524.       fprintf(f,"%s, %s\n",thisuser.city,thisuser.state);
  525.     else
  526.       fprintf(f,"\n");
  527.     fprintf(f,"%c\n%d\n%ld\n",(thisuser.sysstatus & sysstatus_ansi)?'1':'0',
  528.       thisuser.sl,(long)(l));
  529.     fsh_close(f);
  530.   }
  531.  
  532.   /* make PCBOARD.SYS (PC Board) */
  533.   create_filename(CHAINFILE_PCBOARD, s);
  534.   unlink(s);
  535.   fl=sh_open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD|S_IWRITE);
  536.   if (fl) {
  537.     memset(&pcb,0,sizeof(pcb));
  538.     strcpy(pcb.display,  "-1");
  539.     strcpy(pcb.printer, (syscfg.sysconfig & sysconfig_printer)?"-1":" 0");
  540.     strcpy(pcb.page_bell," 0");
  541.     strcpy(pcb.alarm, (sysop_alert)?"-1":" 0");
  542.     strcpy(pcb.errcheck, (modem_flag & flag_ec)?"-1":" 0");
  543.     if (okansi()) {
  544.       pcb.graphics = 'Y';
  545.       pcb.ansi = '1';
  546.     } else {
  547.       pcb.graphics = 'N';
  548.       pcb.ansi = '0';
  549.     }
  550.     pcb.nodechat=32;
  551.     sprintf(pcb.openbps, "%-5.5s",cspeed);
  552.     if (!incom)
  553.       strcpy(pcb.connectbps,"Local");
  554.     else
  555.       sprintf(pcb.connectbps,"%-5.5u",modem_speed);
  556.     pcb.usernum=usernum;
  557.     sprintf(s,"%-25.25s",thisuser.name);
  558.     ss=strtok(s," \t");
  559.     sprintf(pcb.firstname,"%-15.15s",ss);
  560.     strcpy(pcb.password,"XXX"); /* Don't write password - security */
  561.     pcb.time_on=thisuser.timeon/60;
  562.     pcb.prev_used = 0;
  563.     d  = thisuser.timeon/60;
  564.     h1 = (d/60)/10;
  565.     h2 = (d/60)-(h1*10);
  566.     m1 = (d-((h1*10+h2)*60))/10;
  567.     m2 = (d-((h1*10+h2)*60))-(m1*10);
  568.     pcb.time_logged[0] = h1+'0';
  569.     pcb.time_logged[1] = h2+'0';
  570.     pcb.time_logged[2] = ':';
  571.     pcb.time_logged[3] = m1+'0';
  572.     pcb.time_logged[4] = m2+'0';
  573.     pcb.time_limit = nsl();
  574.     pcb.down_limit = 1024;
  575.     pcb.curconf = curconfsub;
  576.     strcpy(pcb.slanguage,cur_lang_name);
  577.     strcpy(pcb.name,thisuser.name);
  578.     pcb.sminsleft = pcb.time_limit;
  579.     if (num_instances()>1)
  580.       pcb.snodenum = instance;
  581.     else
  582.       pcb.snodenum = 0;
  583.     strcpy(pcb.seventtime, "01:00");
  584.     strcpy(pcb.seventactive, (syscfg.executetime && syscfg.executestr[0])?
  585.       "-1":" 0");
  586.     strcpy(pcb.sslide," 0");
  587.     pcb.scomport=syscfgovr.primaryport+'0';
  588.     pcb.packflag = 27;
  589.     pcb.bpsflag = 32;
  590.     /* Added for PCB 14.5 Revision */
  591.     strcpy(pcb.lastevent, status.date1);
  592.     pcb.exittodos = '0';
  593.     pcb.eventupcoming = '0';
  594.     pcb.lastconfarea = curconfsub;
  595.     /* End Additions */
  596.  
  597.     sh_write(fl, &pcb, sizeof(pcb));
  598.     fl=sh_close(fl);
  599.   }
  600.  
  601.   /* make CALLINFO.BBS (WildCat!) */
  602.   create_filename(CHAINFILE_CALLINFO, s);
  603.   unlink(s);
  604.   f=fsh_open(s,"wt");
  605.   if (f) {
  606.     fprintf(f,"%s\n",thisuser.realname);
  607.     switch (modem_speed) {
  608.       case 300    : fprintf(f,"1\n");
  609.       case 1200   : fprintf(f,"2\n");
  610.       case 2400   : fprintf(f,"0\n");
  611.       case 19200  : fprintf(f,"4\n");
  612.       default: fprintf(f,"3\n");
  613.     }
  614.     fprintf(f," \n%d\n%ld\n%s\n%s\n%d\n%ld\n%.5s\n0\nABCD\n0\n0\n0\n0\n",
  615.       thisuser.sl, l,
  616.       (thisuser.sysstatus & sysstatus_ansi)?"COLOR":"MONO",
  617.       "X" /* thisuser.pw */, usernum, ((long)(timeon/60)), times());
  618.     fprintf(f,"%s\n%s 00:01\nEXPERT\nN\n%s\n%d\n%d\n1\n%d\n%d\n%s\n%s\n%d\n",
  619.       thisuser.phone, thisuser.laston, thisuser.laston, thisuser.logons,
  620.       thisuser.screenlines, thisuser.uploaded, thisuser.downloaded,
  621.       (andwith==0x7f)?"7E1":"8N1",
  622.       (incom)?"REMOTE":"LOCAL",
  623.       (incom)?0:syscfgovr.primaryport);
  624.     strcpy(s1,"00/00/00");
  625.     sprintf(s2,"%d",thisuser.month);
  626.     memmove(&(s1[2-strlen(s2)]),&(s2[0]),strlen(s2));
  627.     sprintf(s2,"%d",thisuser.day);
  628.     memmove(&(s1[5-strlen(s2)]),&(s2[0]),strlen(s2));
  629.     sprintf(s2,"%d",thisuser.year);
  630.     memmove(&(s1[8-strlen(s2)]),&(s2[0]),strlen(s2));
  631.     fprintf(f,"%s\n",s1);
  632.     fprintf(f,"%s\n",(incom)?cspeed:"14400");
  633.     fsh_close(f);
  634.   }
  635.  
  636.   /* make DOOR.SYS (Generic) */
  637.   create_filename(CHAINFILE_DOOR, s);
  638.   unlink(s);
  639.   f=fsh_open(s,"wt");
  640.   if (f) {
  641.     fprintf(f,"COM%d\n%s\n%c\n%u\n%u\n%c\n%c\n%c\n%c\n%s\n%s, %s\n",
  642.       (using_modem)?syscfgovr.primaryport:0,
  643.       cspeed,
  644.       (andwith==0x7f)?'7':'8',
  645.       instance,  /* node */
  646.       (using_modem)?modem_speed:14400,
  647.       'Y', /* screen display */
  648.       (syscfg.sysconfig & sysconfig_printer)?'Y':'N',
  649.       'N',  /* page bell */
  650.       'N',  /* caller alarm */
  651.       thisuser.realname,
  652.       thisuser.city,
  653.       thisuser.state);
  654.     fprintf(f,"%s\n%s\n%s\n%d\n%u\n%s\n%ld\n%ld\n",
  655.       thisuser.phone,
  656.       thisuser.dataphone,
  657.       "X", /* thisuser.pw */
  658.       thisuser.sl,
  659.       thisuser.logons,
  660.       thisuser.laston,
  661.       (unsigned long)(60L*l),
  662.       l);
  663.     sprintf(s1,"%s",okansi()?"GR":"NG");
  664.     if (andwith==0x7f)
  665.       strcpy(s1,"7E");
  666.     fprintf(f,"%s\n%u\n%c\n%s\n%u\n%s\n%u\n%c\n%u\n%u\n%u\n%u\n",
  667.       s1,
  668.       thisuser.screenlines,
  669.       (thisuser.sysstatus & sysstatus_expert)?'Y':'N',
  670.       "1,2,3", /* conferences */
  671.       cursub,  /* current 'conference' */
  672.       "12/31/99", /* expiration date */
  673.       usernum,
  674.       'Y', /* default protocol */
  675.       thisuser.uploaded,
  676.       thisuser.downloaded,
  677.       0,  /* kb dl today */
  678.       0); /* kb dl/day max */
  679.     strcpy(s1,"00/00/00");
  680.     sprintf(s2,"%d",thisuser.month);
  681.     memmove(&(s1[2-strlen(s2)]),&(s2[0]),strlen(s2));
  682.     sprintf(s2,"%d",thisuser.day);
  683.     memmove(&(s1[5-strlen(s2)]),&(s2[0]),strlen(s2));
  684.     sprintf(s2,"%d",thisuser.year);
  685.     memmove(&(s1[8-strlen(s2)]),&(s2[0]),strlen(s2));
  686.     fprintf(f,"%s\n%s\n%s\n%s\n%s\n%s\n%c\n%c\n%c\n%u\n%u\n%s\n%-.5s\n%s\n",
  687.       s1,
  688.       syscfg.datadir,
  689.       syscfg.gfilesdir,
  690.       syscfg.sysopname,
  691.       thisuser.name,
  692.       "00:01", /* event time */
  693.       (modem_flag & flag_ec)?'Y':'N',
  694.       (okansi())?'N':'Y',  /* ansi ok but graphics turned off? */
  695.       'N', /* record-locking */
  696.       thisuser.colors[0],
  697.       thisuser.banktime,
  698.       thisuser.laston, /* last n-scan date */
  699.       times(),
  700.       "00:01"); /* time last call */
  701.     fprintf(f,"%u\n%u\n%ld\n%ld\n%s\n%u\n%ld\n",
  702.       99, /* max files dl/day */
  703.       0,  /* files dl today so far */
  704.       thisuser.uk,
  705.       thisuser.dk,
  706.       thisuser.note,
  707.       thisuser.chainsrun,
  708.       thisuser.msgpost);
  709.     fsh_close(f);
  710.   }
  711. }
  712.  
  713. /****************************************************************************/
  714.  
  715. char *create_chain_file(void)
  716. {
  717.   char s[81],gd[81],dd[81], cspeed[15];
  718.   static char fpn[81];
  719.   long l,l1;
  720.   FILE *f;
  721.  
  722.   ultoa(com_speed,cspeed,10);
  723.   if ((com_speed==1) || (com_speed==49664))
  724.     strcpy(cspeed,"115200");
  725.  
  726.   create_drop_files(cspeed);
  727.   cd_to(syscfg.gfilesdir);
  728.   get_dir(gd,1);
  729.   cd_to(cdir);
  730.   cd_to(syscfg.datadir);
  731.   get_dir(dd,1);
  732.   cd_to(cdir);
  733.   islname(s);
  734.   l=(long) (timeon);
  735.   if (l<0)
  736.     l += 3600*24;
  737.   l1=(long) (timer()-timeon);
  738.   if (l1<0)
  739.     l1 += 3600*24;
  740.  
  741.   create_filename(CHAINFILE_CHAIN, fpn);
  742.  
  743.   unlink(fpn);
  744.   f=fsh_open(fpn,"wt");
  745.   if (f) {
  746.     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",
  747.             usernum, thisuser.name, thisuser.realname, thisuser.callsign,
  748.             thisuser.age, thisuser.sex, thisuser.gold, thisuser.laston,
  749.             thisuser.screenchars, thisuser.screenlines, thisuser.sl);
  750.     fprintf(f,"%d\n%d\n%d\n%d\n%10.2f\n%s\n%s\n%s\n",
  751.             cs(),so(),okansi(), incom, nsl(), gd, dd, s);
  752.     if (using_modem)
  753.       fprintf(f,"%u\n",modem_speed);
  754.     else
  755.       fprintf(f,"KB\n");
  756.     fprintf(f,"%d\n%s\n%s\n%ld\n%ld\n%lu\n%u\n%lu\n%u\n%s\n%s\n%u\n",
  757.             syscfgovr.primaryport, syscfg.systemname, syscfg.sysopname, l, l1,
  758.             thisuser.uk, thisuser.uploaded, thisuser.dk, thisuser.downloaded,
  759.             (andwith==0x7f)?"7E1":"8N1", cspeed, net_sysnum);
  760.     fprintf(f,"%c\n%c\n%c\n",(rip)?'Y':'N',(menu_on())?'Y':'N',
  761. #ifdef RIPDRIVE
  762.      (rd_on())?'Y':'N'
  763. #else
  764.      'N'
  765. #endif
  766.      );
  767.     fsh_close(f);
  768.   }
  769.   return(fpn);
  770. }
  771.  
  772.  
  773.  
  774. /****************************************************************************/
  775.  
  776. void save_state(int state,int ctc, char *restorefn, char *statfn)
  777. {
  778.   int f,i;
  779.   char ldir[81];
  780.  
  781.   get_dir(ldir, 1);
  782.   if (instance>1) {
  783.     sprintf(restorefn, "%sRESTORE.%3.3d", ldir, instance);
  784.     sprintf(statfn, "%sSTAT.%3.3d", ldir, instance);
  785.   } else {
  786.     sprintf(restorefn, "%sRESTORE.WWV", ldir);
  787.     sprintf(statfn, "%sSTAT.WWV", ldir);
  788.   }
  789.   _chmod(restorefn, 1, 0);
  790.   _chmod(statfn, 1, 0);
  791.   unlink(restorefn);
  792.   unlink(statfn);
  793.  
  794.   /* if (1) */ {
  795.     f=sh_open(restorefn,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  796.     if (f<0)
  797.       return;
  798.  
  799.     WRITE(state);
  800.     WRITE(oklevel);
  801.     WRITE(noklevel);
  802.     WRITE(ooneuser);
  803.     WRITE(no_hangup);
  804.     WRITE(ok_modem_stuff);
  805.     WRITE(topdata);
  806.     WRITE(last_time_c);
  807.     WRITE(sysop_alert);
  808.     WRITE(do_event);
  809.  
  810.     WRITE(andwith);
  811.     WRITE(usernum);
  812.     WRITE(chatcall);
  813.     WRITE(chatreason);
  814.     WRITE(timeon);
  815.     WRITE(extratimecall);
  816.     WRITE(curspeed);
  817.     WRITE(modem_speed);
  818.     WRITE(com_speed);
  819.     WRITE(modem_flag);
  820.     WRITE(cursub);
  821.     WRITE(curdir);
  822.     WRITE(curdloads);
  823.     WRITE(msgreadlogon);
  824.     WRITE(nscandate);
  825.     WRITE(mailcheck);
  826.     WRITE(smwcheck);
  827.     WRITE(use_workspace);
  828.     WRITE(using_modem);
  829.     WRITE(last_time);
  830.     WRITE(fsenttoday);
  831.     WRITE(global_xx);
  832.     WRITE(xtime);
  833.     WRITE(xdate);
  834.     WRITE(incom);
  835.     WRITE(outcom);
  836.     WRITE(global_handle);
  837.     WRITE(actsl);
  838.     WRITE(numbatch);
  839.     WRITE(numbatchdl);
  840.  
  841.     sh_write(f,batch, numbatch*sizeof(batchrec));
  842.     WRITE(batchtime);
  843.  
  844.  
  845.     WRITE(last_time);
  846.     WRITE(time_event);
  847.     WRITE(syscfg.executetime);
  848.     WRITE(syscfg.executestr);
  849.     i=uconfsub[curconfsub].confnum;
  850.     WRITE(i);
  851.     i=uconfdir[curconfdir].confnum;
  852.     WRITE(i);
  853.     i=usub[cursub].subnum;
  854.     WRITE(i);
  855.     i=udir[curdir].subnum;
  856.     WRITE(i);
  857.  
  858.     set_global_handle(0);
  859.  
  860.     sh_close(f);
  861.  
  862.     _chmod(restorefn, 1, FA_HIDDEN);
  863.   }
  864.  
  865.   f=sh_open(statfn,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  866.   if (f<0)
  867.     return;
  868.  
  869.   WRITE(incom);
  870.   WRITE(outcom);
  871.   WRITE(thisuser);
  872.   WRITE(flow_control);
  873.   WRITE(async_irq);
  874.   WRITE(com_speed);
  875.   WRITE(base);
  876.   WRITE(andwith);
  877.   WRITE(ctc);
  878.   WRITE(defscreenbottom);
  879.   WRITE(ok_modem_stuff);
  880.   WRITE(save_dos);
  881.  
  882.   sh_close(f);
  883.  
  884.   _chmod(statfn, 1, FA_HIDDEN);
  885.  
  886. }
  887.  
  888.  
  889. /****************************************************************************/
  890. /****************************************************************************/
  891. /****************************************************************************/
  892.  
  893. #ifdef OLD_STUFF
  894.  
  895. int restore_data(char *s) /**/
  896. {
  897.   int f,stat,i;
  898.   char s1[81];
  899.  
  900.   f=sh_open1(s,O_RDONLY | O_BINARY);
  901.   if (f<0)
  902.     return(-1);
  903.  
  904.   READ(stat);
  905.   READ(oklevel);
  906.   READ(noklevel);
  907.   READ(ooneuser);
  908.   READ(no_hangup);
  909.   READ(ok_modem_stuff);
  910.   READ(topdata);
  911.   READ(last_time_c);
  912.   READ(sysop_alert);
  913.   READ(do_event);
  914.  
  915.   if (stat) {
  916.     READ(andwith);
  917.     READ(usernum);
  918.     READ(chatcall);
  919.     READ(chatreason);
  920.     READ(timeon);
  921.     READ(extratimecall);
  922.     READ(curspeed);
  923.     READ(modem_speed);
  924.     READ(com_speed);
  925.     READ(modem_flag);
  926.     READ(cursub);
  927.     READ(curdir);
  928.     READ(curdloads);
  929.     READ(msgreadlogon);
  930.     READ(nscandate);
  931.     READ(mailcheck);
  932.     READ(smwcheck);
  933.     READ(use_workspace);
  934.     READ(using_modem);
  935.     READ(last_time);
  936.     READ(fsenttoday);
  937.     READ(global_xx);
  938.     READ(xtime);
  939.     READ(xdate);
  940.     READ(incom);
  941.     READ(outcom);
  942.     READ(global_handle);
  943.     READ(actsl);
  944.     READ(numbatch);
  945.     READ(numbatchdl);
  946.  
  947.     sh_read(f,batch, numbatch*sizeof(batchrec));
  948.     READ(batchtime);
  949.  
  950.     READ(last_time);
  951.     READ(time_event);
  952.     READ(syscfg.executetime);
  953.     READ(syscfg.executestr);
  954.     READ(i);
  955.     uconfsub[0].confnum=i;
  956.     READ(i);
  957.     uconfdir[0].confnum=i;
  958.     curconfsub=curconfdir=0;
  959.     READ(i);
  960.     usub[0].subnum=i;
  961.     READ(i);
  962.     udir[0].subnum=i;
  963.     cursub=curdir=0;
  964.  
  965.     if (global_handle) {
  966.       global_handle=0;
  967.       set_global_handle(1);
  968.     }
  969.  
  970.     read_user(usernum,&thisuser);
  971.     read_qscn(usernum,qsc,0);
  972.     if (set_language(thisuser.language)) {
  973.       thisuser.language=0;
  974.       set_language(thisuser.language);
  975.     }
  976.  
  977.     useron=1;
  978.     changedsl();
  979.     topscreen();
  980.   }
  981.   if (ok_modem_stuff) {
  982.     initport(syscfgovr.primaryport);
  983.     if (stat) {
  984.       set_baud(com_speed);
  985.       if (modem_flag & flag_fc)
  986.         flow_control = 1;
  987.     } else {
  988.       do_result(&(modem_i->defl));
  989.     }
  990.   }
  991.  
  992.   sh_close(f);
  993.   unlink(s);
  994.   if(instance > 1)
  995.     sprintf(s1,"STAT.%3.3d",instance);
  996.   else
  997.     sprintf(s1,"STAT.WWV");
  998.   unlink(s1);
  999.   return(stat);
  1000. }
  1001.  
  1002. #endif
  1003.  
  1004.