home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / WWIV2.ZIP / XINIT.C < prev   
C/C++ Source or Header  |  1993-10-18  |  14KB  |  508 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 <math.h>
  23.  
  24.  
  25. void far interrupt inlii();
  26. void far interrupt checkai();
  27. void far interrupt plai();
  28. void far interrupt outchri();
  29. void far interrupt outstri();
  30. void far interrupt nli();
  31. void far interrupt pli();
  32. void far interrupt emptyi();
  33. void far interrupt inkeyi();
  34. void far interrupt getkeyi();
  35. void far interrupt inputi();
  36. void far interrupt inputli();
  37. void far interrupt yni();
  38. void far interrupt nyi();
  39. void far interrupt ansici();
  40. void far interrupt oneki();
  41. void far interrupt prti();
  42. void far interrupt mpli();
  43.  
  44.  
  45. void far *mallocx(unsigned long l, char *where)
  46. {
  47.   void *x;
  48.  
  49.   x=farmalloc(l);
  50.   if (!x) {
  51.     printf("Insufficient memory (%ld bytes) for %s.\n",l,where);
  52.     end_bbs(noklevel);
  53.   }
  54.   memset(x, 0, l);
  55.   return(x);
  56. }
  57.  
  58. #define OFFOF(x) (FP_OFF(&(thisuser.x))-FP_OFF(&thisuser))
  59.  
  60. void init(void)
  61. {
  62.   char s[161],*buf,ch,*ss;
  63.   int i,i1,i2,sm,cp,n,f;
  64.   int f1,f2,f3,f4,f5,f6,f7;
  65.   long l;
  66.   union REGS r;
  67.   struct date today;
  68.   votingrec v;
  69.  
  70.  
  71.   save_dos=find_interrupt();
  72.   if (!save_dos) {
  73.     printf("\nNo spare interrupt vector found to use.\n\n");
  74.     end_bbs(noklevel);
  75.   }
  76.   crttype=peekb(0x0040,0x0049);
  77.   if (crttype==7)
  78.     scrn=MK_FP(0xb000,0x0000);
  79.   else
  80.     scrn=MK_FP(0xb800,0x0000);
  81.   r.h.ah=15;
  82.   int86(0x10,&r,&r);
  83.   sm=r.h.al;
  84.   if (r.h.ah!=80) {
  85.     printf("\n\nYou must be in 80 column mode to run WWIV.\n\n");
  86.     end_bbs(noklevel);
  87.   }
  88.   if ((sm==4) || (sm==5) || (sm==6)) {
  89.     printf("\n\nYou must be in text mode to run WWIV.\n\n");
  90.     end_bbs(noklevel);
  91.   }
  92.   defscreenbottom=(int) peekb(0x0000,0x0484);
  93.   if (defscreenbottom<24)
  94.     defscreenbottom=24;
  95.   if (defscreenbottom>63)
  96.     defscreenbottom=24;
  97.   if ((defscreenbottom!=42) && (defscreenbottom!=49))
  98.     defscreenbottom=24;
  99.   screenbottom=defscreenbottom;
  100.   screenlen=160*(screenbottom+1);
  101.   if (!exist("restore.wwv")) {
  102.     for (i=0; i<screenbottom; i++)
  103.       printf("\n");
  104.     strcpy(s,wwiv_version);
  105.     strcat(s,", Copyright (c) 1988-1993 by Wayne Bell.\n\n");
  106.     printf(s);
  107.   }
  108.   strcpy(cdir,"X:\\");
  109.   cdir[0]='A'+getdisk();
  110.   getcurdir(0,&(cdir[3]));
  111.  
  112. #ifdef EMS_XMS
  113.   if (_OvrInitEms(0,0,16)!=0)
  114.     _OvrInitExt(0L,0);
  115. #endif
  116.  
  117.   userfile=-1;
  118.   configfile=-1;
  119.   statusfile=-1;
  120.   dlf=-1;
  121.   curlsub=-1;
  122.   curldir=-1;
  123.   setvect(save_dos, getvect(INT_REAL_DOS));
  124.   oldx=0;
  125.   oldy=0;
  126.   itimer();
  127.   r.h.ah=0x33;
  128.   r.h.al=0x01;
  129.   r.h.dl=0x00;
  130.   int86(INT_REAL_DOS,&r,&r);
  131.   use_workspace=0;
  132.   input_extern=0;
  133.   chat_file=0;
  134.   sysop_alert=0;
  135.   global_handle=0;
  136.  
  137.   for (i=0; i<25; i++)
  138.     funcs[i]=NULL;
  139.   funcs[0]=(void far *)inlii;
  140.   funcs[1]=(void far *)checkai;
  141.   funcs[2]=(void far *)plai;
  142.   funcs[3]=(void far *)outchri;
  143.   funcs[4]=(void far *)outstri;
  144.   funcs[5]=(void far *)nli;
  145.   funcs[8]=(void far *)pli;
  146.   funcs[9]=(void far *)emptyi;
  147.   funcs[10]=(void far *)inkeyi;
  148.   funcs[11]=(void far *)getkeyi;
  149.   funcs[12]=(void far *)inputi;
  150.   funcs[13]=(void far *)inputli;
  151.   funcs[14]=(void far *)yni;
  152.   funcs[15]=(void far *)nyi;
  153.   funcs[16]=(void far *)ansici;
  154.   funcs[17]=(void far *)oneki;
  155.   funcs[18]=(void far *)prti;
  156.   funcs[19]=(void far *)mpli;
  157.   sprintf(ver_no2,"WWIV_FP=%04.4X:%04.4X",FP_SEG(funcs), FP_OFF(funcs));
  158.  
  159.   strcpy(ver_no1,"BBS=");
  160.   strcat(ver_no1,wwiv_version);
  161.  
  162.   getdate(&today);
  163.   if (today.da_year<1988) {
  164.     printf("You need to set the date & time before running the BBS.\n");
  165.     end_bbs(noklevel);
  166.   }
  167.   configfile=open("CONFIG.DAT",O_RDWR | O_BINARY);
  168.   if (configfile<0) {
  169.     printf("CONFIG.DAT NOT FOUND.\n");
  170.     end_bbs(noklevel);
  171.   }
  172.   read(configfile,(void *) (&syscfg), sizeof(configrec));
  173.   close(configfile);
  174.  
  175.   cur_lang=-1;
  176.   if (set_language(0)) {
  177.     printf("You need the default language fully installed to run the BBS.\n");
  178.     end_bbs(noklevel);
  179.   }
  180.  
  181.   /* make sure it is the new userrec structure */
  182.   sprintf(s,"%sUSER.QSC",syscfg.datadir);
  183.   if (!exist(s)) {
  184.     printf("You must go into INIT and convert your userlist before running the BBS.\n");
  185.     end_bbs(noklevel);
  186.   }
  187.  
  188.   /* update user info data */
  189.   f1=sizeof(userrec);
  190.   f2=OFFOF(waiting);
  191.   f3=OFFOF(inact);
  192.   f4=OFFOF(sysstatus);
  193.   f5=OFFOF(forwardusr);
  194.   f6=OFFOF(forwardsys);
  195.   f7=OFFOF(net_num);
  196.  
  197.   if ((f1!=syscfg.userreclen) ||
  198.       (f2!=syscfg.waitingoffset) ||
  199.       (f3!=syscfg.inactoffset) ||
  200.       (f4!=syscfg.sysstatusoffset) ||
  201.       (f5!=syscfg.fuoffset) ||
  202.       (f6!=syscfg.fsoffset) ||
  203.       (f7!=syscfg.fnoffset)) {
  204.  
  205.     syscfg.userreclen=f1;
  206.     syscfg.waitingoffset=f2;
  207.     syscfg.inactoffset=f3;
  208.     syscfg.sysstatusoffset=f4;
  209.     syscfg.fuoffset=f5;
  210.     syscfg.fsoffset=f6;
  211.     syscfg.fnoffset=f7;
  212.  
  213.     /* store the new config.dat file */
  214.     configfile=open("CONFIG.DAT",O_RDWR | O_BINARY);
  215.     write(configfile,(void *) (&syscfg), sizeof(configrec));
  216.     close(configfile);
  217.   }
  218.  
  219.   if (!syscfg.primaryport)
  220.     ok_modem_stuff=0;
  221.  
  222.   net_networks=NULL;
  223.   net_num=0;
  224.   sprintf(s,"%sNETWORKS.DAT", syscfg.datadir);
  225.   f=open(s,O_RDONLY|O_BINARY);
  226.   if (f>0) {
  227.     net_num_max=filelength(f)/sizeof(net_networks_rec);
  228.     if (net_num_max) {
  229.       net_networks=mallocx(net_num_max*sizeof(net_networks_rec),"networks.dat");
  230.       read(f, net_networks, net_num_max*sizeof(net_networks_rec));
  231.     }
  232.     close(f);
  233.     for (i=0; i<net_num_max; i++) {
  234.       ss=strchr(net_networks[i].name, ' ');
  235.       if (ss)
  236.         *ss=0;
  237.     }
  238.   }
  239.   if (!net_networks) {
  240.     net_networks=mallocx(sizeof(net_networks_rec), "networks.dat");
  241.     net_num_max=1;
  242.     strcpy(net_networks->name,"WWIVnet");
  243.     strcpy(net_networks->dir, syscfg.datadir);
  244.     net_networks->sysnum=syscfg.systemnumber;
  245.   }
  246.  
  247.   set_net_num(0);
  248.  
  249.   strcpy(s,syscfg.tempdir);
  250.   i=strlen(s);
  251.   if (s[0]==0)
  252.     i1=1;
  253.   else {
  254.     if ((s[i-1]=='\\') && (s[i-2]!=':'))
  255.       s[i-1]=0;
  256.     i1=chdir(s);
  257.   }
  258.   if (i1) {
  259.     printf("\nYour temporary directory isn't valid.\n");
  260.     printf("It is now set to: '%s'\n\n",syscfg.tempdir);
  261.     end_bbs(noklevel);
  262.   } else
  263.     cd_to(cdir);
  264.  
  265.   strcpy(s,syscfg.batchdir);
  266.   i=strlen(s);
  267.   if (s[0]==0)
  268.     i1=1;
  269.   else {
  270.     if ((s[i-1]=='\\') && (s[i-2]!=':'))
  271.       s[i-1]=0;
  272.     i1=chdir(s);
  273.   }
  274.   if (i1) {
  275.     printf("\nYour batchdirectory isn't valid.\n");
  276.     printf("It is now set to: '%s'\n\n",syscfg.batchdir);
  277.     end_bbs(noklevel);
  278.   } else
  279.     cd_to(cdir);
  280.  
  281.   sprintf(s,"%sSTATUS.DAT",syscfg.datadir);
  282.   statusfile=open(s,O_RDWR | O_BINARY);
  283.   if (statusfile<0) {
  284.     printf("%s NOT FOUND.\n",s);
  285.     end_bbs(noklevel);
  286.   }
  287.   read(statusfile,(void *)(&status), sizeof(statusrec));
  288.   close(statusfile);
  289.   status.wwiv_version=wwiv_num_version;
  290.   gat=(unsigned short *) mallocx(2048 * sizeof(short), "gat");
  291.   smallist=(smalrec *) mallocx((long)syscfg.maxusers * (long)sizeof(smalrec),
  292.                                "names.lst - try decreasing max users in INIT");
  293.   gfilesec=(gfiledirrec *) mallocx((long) (32 * sizeof(gfiledirrec)), "gfiles");
  294.  
  295.   sprintf(s,"%sGFILE.DAT",syscfg.datadir);
  296.   i=open(s,O_RDWR | O_BINARY);
  297.   if (i<0)
  298.     num_sec=0;
  299.   else
  300.     num_sec=read(i,(void *)gfilesec,32*sizeof(gfiledirrec))/sizeof(gfiledirrec);
  301.   close(i);
  302.  
  303.   sprintf(s,"%sNAMES.LST",syscfg.datadir);
  304.   i=open(s,O_RDWR | O_BINARY);
  305.   if (i<0) {
  306.     printf("%s NOT FOUND.\n",s);
  307.     end_bbs(noklevel);
  308.   }
  309.   read(i,(void *) (smallist), (sizeof(smalrec) * status.users));
  310.   close(i);
  311.  
  312.   max_subs=syscfg.max_subs;
  313.   max_dirs=syscfg.max_dirs;
  314.  
  315.   subboards=(subboardrec *) mallocx(max_subs*sizeof(subboardrec), "subboards");
  316.   directories=(directoryrec *)mallocx(max_dirs*sizeof(directoryrec), "directories");
  317.  
  318.   sprintf(s,"%sSUBS.DAT",syscfg.datadir);
  319.   i=open(s,O_RDWR | O_BINARY);
  320.   if (i<0) {
  321.     printf("%s NOT FOUND.\n",s);
  322.     end_bbs(noklevel);
  323.   }
  324.   num_subs=(read(i,subboards, (max_subs*sizeof(subboardrec))))/
  325.            sizeof(subboardrec);
  326.   close(i);
  327.  
  328.   if (read_subs_xtr(max_subs, num_subs, subboards))
  329.     end_bbs(noklevel);
  330.  
  331.   sprintf(s,"%sDIRS.DAT",syscfg.datadir);
  332.   i=open(s,O_RDWR | O_BINARY);
  333.   if (i<0) {
  334.     printf("%s NOT FOUND.\n",s);
  335.     end_bbs(noklevel);
  336.   }
  337.   num_dirs=(read(i,directories, (max_dirs*sizeof(directoryrec))))/
  338.            sizeof(directoryrec);
  339.   close(i);
  340.  
  341.   chains=(chainfilerec *) mallocx(50 * sizeof(chainfilerec), "chains");
  342.   numextrn=0;
  343.   numchain=0;
  344.   numed=0;
  345.   sprintf(s,"%sCHAINS.DAT",syscfg.datadir);
  346.   i=open(s,O_RDWR | O_BINARY);
  347.   if (i>0) {
  348.     numchain=(read(i,(void *)chains, 50*sizeof(chainfilerec)))/sizeof(chainfilerec);
  349.     numchain=numchain;
  350.     close(i);
  351.   }
  352.   sprintf(s,"%sMODEM.DAT",syscfg.datadir);
  353.   i=open(s,O_RDWR | O_BINARY);
  354.   if (i>0) {
  355.     l=filelength(i);
  356.     modem_i = mallocx(l, "modem.dat");
  357.     read(i,modem_i, (unsigned) l);
  358.     close(i);
  359.   } else {
  360.     printf("\nRun INIT.EXE to convert modem data.\n\n");
  361.     end_bbs(noklevel);
  362.   }
  363.  
  364.   sprintf(s,"%sNEXTERN.DAT",syscfg.datadir);
  365.   i=open(s,O_RDWR | O_BINARY);
  366.   if (i>0) {
  367.     l=filelength(i);
  368.     if (l>15*sizeof(newexternalrec))
  369.       l=15*sizeof(newexternalrec);
  370.     externs=mallocx(l+10, "external protocols");
  371.     numextrn=(read(i,(void *)externs, (unsigned) l))/sizeof(newexternalrec);
  372.     close(i);
  373.   } else
  374.     numextrn=0;
  375.  
  376.   sprintf(s,"%sNINTERN.DAT",syscfg.datadir);
  377.   i=open(s,O_RDWR|O_BINARY);
  378.   if (i>0) {
  379.     over_intern=mallocx(3*sizeof(newexternalrec),"interal protocol overrides");
  380.     read(i,over_intern, 3*sizeof(newexternalrec));
  381.     close(i);
  382.   }
  383.  
  384.  
  385.   sprintf(s,"%sEDITORS.DAT",syscfg.datadir);
  386.   i=open(s,O_RDWR | O_BINARY);
  387.   if (i>0) {
  388.     l=filelength(i);
  389.     if (l>10*sizeof(editorrec))
  390.       l=10*sizeof(editorrec);
  391.     editors=mallocx(l+10, "external editors");
  392.     numed=(read(i,(void *)editors, (unsigned) l))/sizeof(editorrec);
  393.     numed=numed;
  394.     close(i);
  395.   }
  396.   batch=mallocx(MAX_BATCH * sizeof(batchrec), "batch list");
  397.  
  398.   read_user(1,&thisuser);
  399.   if (thisuser.inact & inact_deleted)
  400.     fwaiting=0;
  401.   else
  402.     fwaiting=thisuser.waiting;
  403.   sl1(2,status.date1);
  404.   if (ok_modem_stuff) {
  405.     initport(syscfg.primaryport);
  406.     do_result(&(modem_i->defl));
  407.   }
  408.   if (syscfg.sysconfig & sysconfig_no_local)
  409.     topdata=0;
  410.   else
  411.     topdata=2;
  412.   ss=getenv("PROMPT");
  413.   strcpy(newprompt,"PROMPT=WWIV: ");
  414.   if (ss)
  415.     strcat(newprompt,ss);
  416.   else
  417.     strcat(newprompt,"$P$G");
  418.   sprintf(dszlog,"%s\\WWIVDSZ.LOG",cdir);
  419.   sprintf(s,"DSZLOG=%s",dszlog);
  420.   i=i1=0;
  421.   while (environ[i]!=NULL) {
  422.     if (strncmp(environ[i],"PROMPT=",7)==0)
  423.       xenviron[i1++]=newprompt;
  424.     else
  425.       if (strncmp(environ[i],"DSZLOG=",7)==0)
  426.         xenviron[i1++]=strdup(s);
  427.       else {
  428.         if ((strncmp(environ[i],"BBS=",4)) &&
  429.             (strncmp(environ[i],"WWIV_FP=",8)) &&
  430.             (strncmp(environ[i],"WWIV_NET=",8)))
  431.           xenviron[i1++]=environ[i];
  432.       }
  433.     ++i;
  434.   }
  435.   if (!getenv("DSZLOG"))
  436.     xenviron[i1++]=strdup(s);
  437.   if (!ss)
  438.     xenviron[i1++]=newprompt;
  439.   xenviron[i1++]=ver_no1;
  440.   xenviron[i1++]=ver_no2;
  441.   xenviron[i1++]=wwiv_net_no;
  442.   xenviron[i1]=NULL;
  443.   for (i=0; i<20; i++)
  444.     questused[i]=0;
  445.   sprintf(s,"%sVOTING.DAT",syscfg.datadir);
  446.   f=open(s,O_RDWR | O_BINARY);
  447.   if (f>0) {
  448.     n=(int) (filelength(f) / sizeof(votingrec)) -1;
  449.     for (i=0; i<n; i++) {
  450.       lseek(f,(long) i * sizeof(votingrec),SEEK_SET);
  451.       read(f,(void *)&v,sizeof(votingrec));
  452.       if (v.numanswers)
  453.         questused[i]=1;
  454.     }
  455.     close(f);
  456.   }
  457.   if (syscfg.sysconfig & sysconfig_high_speed)
  458.     high_speed=1;
  459.   else
  460.     high_speed=0;
  461.   time_event=((double)syscfg.executetime)*60.0;
  462.   last_time=time_event-timer();
  463.   if (last_time<0.0)
  464.     last_time+=24.0*3600.0;
  465.   do_event=0;
  466.   if (status.callernum!=65535) {
  467.     status.callernum1=(long)status.callernum;
  468.     status.callernum=65535;
  469.     save_status();
  470.   }
  471.   msgs=(postrec *) mallocx((long)(255 * sizeof(postrec)), "posts");
  472.  
  473.   usub=(usersubrec *)mallocx(max_subs*sizeof(usersubrec), "usub");
  474.   sub_dates=(long *) mallocx(max_subs*sizeof(long),"sub_dates");
  475.  
  476.   udir=(usersubrec *)mallocx(max_dirs*sizeof(usersubrec), "udir");
  477.   dir_dates=(long *) mallocx(max_dirs*sizeof(long),"dir_dates");
  478.  
  479.   qsc=(unsigned long *)mallocx(syscfg.qscn_len, "quickscan");
  480.   qsc_n=qsc+1;
  481.   qsc_q=qsc_n+(max_dirs+31)/32;
  482.   qsc_p=qsc_q+(max_subs+31)/32;
  483.  
  484.   read_bbs_list_index();
  485.   frequent_init();
  486.   if (!restoring_shrink && !already_on) {
  487.     remove_from_temp("*.*", syscfg.tempdir, 1);
  488.     remove_from_temp("*.*", syscfg.batchdir, 1);
  489.     imodem(1);
  490.     cleanup_net();
  491.   }
  492.  
  493.   lecho=ok_local();
  494.   daylight=0;
  495.   find_devices();
  496.  
  497.   if (!restoring_shrink) {
  498. /*   sprintf(s,"%s brought up at %s on %s.",wwiv_version, times(), date());*/
  499.     sprintf(s,"");
  500.     sl1(0,"");
  501.     sl1(0,s);
  502.     sl1(0,"");
  503.   }
  504.   unlink("WWIV_NET.DAT");
  505.  
  506.   detect_multitask();
  507. }
  508.