home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / MISC / XSRC_117.ZIP / XLOWLVL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  27.3 KB  |  1,094 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*   XBBS SOURCE CODE copyright (c) 1990 by M. Kimes                        */
  4. /*   All Rights Reserved                                                    */
  5. /*                                                                          */
  6. /*    For complete details of the licensing restrictions, please refer      */
  7. /*    to the License agreement, which is published in its entirety in       */
  8. /*    the in the file LICENSE.XBS.                                          */
  9. /*                                                                          */
  10. /*    USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE      */
  11. /*    XBBS LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF            */
  12. /*    THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO       */
  13. /*    NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT M. KIMES         */
  14. /*    AT THE ADDRESS LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO USE   */
  15. /*    THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE XBBS LICENSING     */
  16. /*    AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE ABLE TO REACH WITH      */
  17. /*    M. KIMES                                                              */
  18. /*                                                                          */
  19. /*                                                                          */
  20. /* You can contact M. Kimes at the following address:                       */
  21. /*                                                                          */
  22. /* M. Kimes                         1:380/16.0@FidoNet                      */
  23. /* 542 Merrick                      (318)222-3455 data                      */
  24. /* Shreveport, LA  71104                                                    */
  25. /*                                                                          */
  26. /*                                                                          */
  27. /* Please feel free to contact me at any time to share your comments about  */
  28. /* my software and/or licensing policies.                                   */
  29. /*                                                                          */
  30. /*--------------------------------------------------------------------------*/
  31. /*======================================================================*/
  32. /*  XBBS Bulletin Board System.....Misc low-level routines              */
  33. /*======================================================================*/
  34.  
  35. #include "msg.h"
  36. #include "xext.h"
  37.  
  38. extern word lastlevel[10];
  39.  
  40.  
  41. extern void pascal CLEAROVERLAY (void);
  42. extern void pascal _REINITOVERLAYS (void);
  43.  
  44.  
  45.  
  46. void pascal readconfig (void) {
  47.  
  48.   int fp;
  49.   char s[14];
  50.   word temp;
  51.  
  52.  if (nodenumber!=1) sprintf(s,"config%hu.bbs",nodenumber);
  53.  else strcpy(s,"config.bbs");
  54.  if ((fp=oopen(s,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
  55. Fatal:
  56.    printm(addtolog("\nFatal Configuration Error...sorry.\n"));
  57.    gprintf(LOCALONLY,"\04Error #%d\n",errno);
  58.    fossil(FLUSHOUT,0);
  59.    fossil(DTR,DOWN);
  60.    exit(253);
  61.  }
  62.   if ((temp=(_read(fp,&conf,sizeof(struct _config))))<1) goto Fatal;
  63.   if(temp<sizeof(struct _config)) {
  64.     lprint("\n\04Suspicious config file.\n");
  65.     fputs("\07",stdout);
  66.     sleep(1);
  67.   }
  68.   if(conf.version<VERSION) {
  69.     lprint("\n\04Not current config version.\n");
  70.     fputs("\07",stdout);
  71.     sleep(1);
  72.   }
  73.   cclose(fp);
  74. }
  75.  
  76.  
  77. void pascal prepare (void) {
  78.  
  79.   int fp;
  80.   char s[90];
  81.   char numnode[4]="";
  82.  
  83.  if (nodenumber!=1) sprintf(numnode,"%hu",nodenumber);
  84.  sprintf(s,"%sonline%s.xbs",conf.homepath,numnode);
  85.  if ((fp=oopen(s,O_RDWR | O_BINARY | O_DENYNONE))==-1) {
  86.     if ((fp=ccreat(s,S_IWRITE))==-1) {
  87.         gprintf(LOCALONLY | LOGONLY,"\n\04Can't create ONLINE.XBS--%d\n",errno);
  88.     }
  89.  }
  90.  else {
  91.   _write(fp,&user,sizeof(struct _user));
  92.   _write(fp,&userno,sizeof(userno));
  93.   _write(fp,&timelimit,sizeof(timelimit));
  94.   _write(fp,&timeon,sizeof(timeon));
  95.   _write(fp,&starter,sizeof(starter));
  96.   _write(fp,&baud,sizeof(baud));
  97.   _write(fp,&pages,sizeof(pages));
  98.   _write(fp,&age,sizeof(age));
  99.   _write(fp,&timer_off,sizeof(timer_off));
  100.   _write(fp,&hold_time,sizeof(hold_time));
  101.   _write(fp,variable,(sizeof(variable[0])*10));
  102.   _write(fp,&mboard,sizeof(struct _mboard));
  103.   _write(fp,&fboard,sizeof(struct _fboard));
  104.   _write(fp,event,(sizeof(struct _events)*10));
  105.   cclose(fp);
  106.  }
  107.  save_lastread();
  108. }
  109.  
  110.  
  111.  
  112. char pascal spawnit (char *a,char type,char errorlevel) {
  113.  
  114.  int fp;
  115.  int register x;
  116.  char noelevelflag=0;
  117.  char *e[26];
  118.  char str[81];
  119.  char c[134];
  120.  int  drive;
  121.  char dir[MAXDIR];
  122.  ulong temptimer;
  123.  
  124.   if(type!=10 && type!=5) fossil(FLUSHOUT,0);
  125.   temptimer=getxbbstime();
  126.   switch (type) {
  127.     case 5:    break;
  128.     case 1:
  129.     case 2:
  130.     case 8:
  131.     case 9:
  132.     case 4:  prepare();
  133.              saveconfig();
  134.     default: textattr(WHITE | BLACK * 16);
  135.   }
  136.  
  137.   if (type==4) {
  138.     update();
  139.     blank_stat();
  140.     gprintf(LOGONLY,"ERRORLEVEL Exit %hu",errorlevel);
  141.     fossil(DEINIT,0);
  142.     exit(errorlevel);
  143.   }
  144.  
  145.   for (x=0;x<26;x++) e[x]=NULL;
  146.   a=convertstring(a);
  147.   strncpy(c,a,133);
  148.   c[132]=0;
  149.   for (x=0;x<26;x++) e[x]=NULL;
  150.   e[0]=strtok(c," ");
  151.   for (x=1;(e[x]=strtok(0," "));x++) if (x==25) break;
  152.  
  153.    if (type==5) {
  154.      a=strtok(a," ");
  155.      if ((fp=oopen(e[0],O_RDWR | O_APPEND | O_BINARY | O_DENYNONE))==-1)
  156.         if ((fp=ccreat(e[0],S_IWRITE))==-1) {
  157.            gprintf(LOCALONLY," Error in write to %s\n",e[0]);
  158.            return(level=255);
  159.      }
  160.      a=strtok(0,"\n");
  161.      lseek(fp,0L,SEEK_END);
  162.      if(!*a || a==NULL) ffprintf(fp,"\r\n");
  163.      else if (a[strlen(a)-1]!=';') {
  164.        ffprintf(fp,"%s\r\n",a);
  165.      }
  166.      else {
  167.         a[strlen(a)-1]=0;
  168.         _write(fp,a,strlen(a));
  169.      }
  170.      cclose (fp);
  171.      return(level=0);
  172.    }
  173.  
  174.  r.x.ax=0x4400;            /* Set console in (std) cooked mode */
  175.  r.x.bx=1;
  176.  int86(33,&r,&r);
  177.  r.h.dh=0;
  178.  r.h.dl=r.h.dl&(~0x20);
  179.  r.x.ax=0x4401;
  180.  int86(33,&r,&r);
  181.  
  182.    fputs("\x1b[25;1H\n",stderr);
  183.    if (conf.debug) addtolog(a);
  184.    if (type!=6) fossil(DEINIT,0);
  185.  
  186.    if (type==2) {
  187.       gprintf(LOGONLY,"BATch ERRORLEVEL %hu",errorlevel);
  188.       if (nodenumber!=1) sprintf(str,"xbbs%hu.bat",nodenumber);
  189.       else strcpy(str,"xbbs.bat");
  190.       if ((fp=ccreat(str,S_IWRITE))==-1) {
  191.              printm("Error creating BAT file");
  192.              return(level=255);
  193.       }
  194.       ffprintf(fp,"%s\r\n",a);
  195.       cclose(fp);
  196.       exit(errorlevel);
  197.    }
  198.  
  199.  CLEAROVERLAY();
  200.  
  201.    if (type==3 || type==9) {
  202.      ffprintf(LOGONLY,"DOS exit-> %s",a);
  203.      timer_off++;
  204.      noelevelflag++;
  205.      system (a);
  206.    }
  207.  
  208.    strtok(a," ");
  209.  
  210.    if (!type || type==7 || type==6 || type==8) {
  211.        drive=getdisk();
  212.        getcurdir(++drive,dir);
  213.        if (!strnicmp(a,"COMMAND.COM",11)) noelevelflag++;
  214.        gprintf(LOGONLY,"Spawning: %s",a);
  215.        timer_off++;
  216.        if ((type==7 && !conf.swap) || ((!type || type==6 || type==8) && conf.swap)) {
  217.  
  218.             int templevel;
  219.             char *p;
  220.             char *pp;
  221.  
  222.             if (conf.debug) addtolog("Swapping...");
  223.             if (!strchr(a,':') && !strchr(a,'\\')) {
  224.                 p=searchpath(a);
  225.                 if(!p) {
  226.                     gprintf(LOCALONLY | LOGONLY,"Can't find `%s'",a);
  227.                     goto SkipSpawn;
  228.                 }
  229.             }
  230.             else p=a;
  231.             pp=strtok(0,"\n");
  232.             if (!pp) pp="";
  233.             templevel=doswap(p,pp);
  234.             if (templevel!=(-1)) {
  235.                 level=(word)templevel;
  236.                 goto SkipSpawn;
  237.             }
  238.        }
  239. SpawnAnyway:
  240.        level=(word)spawnvp(P_WAIT,a,e);
  241. SkipSpawn:
  242.        setdisk (--drive);
  243.        strcpy(str,"\\");
  244.        strcat(str,dir);
  245.        chdir(str);
  246.        goto getelevel;
  247.    }
  248.    if (type==1 || type==6) {
  249.        gprintf(LOGONLY,"Executing: %s",a);
  250.        execvp(a,e);
  251.    }
  252.    level=256;
  253.  
  254. getelevel:
  255.  
  256.   _REINITOVERLAYS();
  257.   fossil(INIT,0);
  258.   fputs("\x1b[2J",stderr);
  259.   redraw_stat(NULL);
  260.   fossil(WATCHDOG,0);
  261.   if (!level) {
  262.       r.h.ah=77;
  263.       int86(33,&r,&r);
  264.       level=(word)r.h.al;
  265.   }
  266. Skiplevel:
  267.  
  268.   if (type==8 || type==9) {
  269.         getonline();
  270.         readconfig();
  271.   }
  272.   r.x.ax=0x4400;            /* Set console in raw mode */
  273.   r.x.bx=1;
  274.   int86(33,&r,&r);
  275.   r.h.dh=0;
  276.   r.h.dl=r.h.dl|0x20;
  277.   r.x.ax=0x4401;
  278.   int86(33,&r,&r);
  279.  
  280.   lastexittime=(getxbbstime()-temptimer)/60L;
  281.   timer_off=0;
  282.   if(noelevelflag) level=0;    /* Nulify erroneous elevels */
  283.   if (conf.debug){
  284.       gprintf(LOCALONLY,"\n\x4 Watchdog off--Exit status: %u\n",level);
  285.       gprintf(LOGONLY,"Returned %u",level);
  286.   }
  287.   return((char)level);
  288. }
  289.  
  290.  
  291.  
  292. void pascal assignvar (char *a,char x) {
  293.  
  294.   strncpy(variable[x],a,80);
  295.   variable[x][81]=0;
  296. }
  297.  
  298.  
  299.  
  300. int cdecl break_handler (void) {
  301.  
  302.   return 1;
  303. }
  304.  
  305.  
  306. char * pascal stripcr (char *a) {
  307.  
  308.   register int x;
  309.  
  310.   x=strlen(a);
  311.   while (x && (a[x-1]=='\n' || a[x-1]=='\r')) a[--x]=0;
  312.   return a;
  313.  
  314. }
  315.  
  316.  
  317. char * pascal addtolog (char *text) { /* WRITE LOGFILE ENTRIES */
  318.  
  319.  int handle;
  320.  char p[127];
  321.  char nn[5];
  322.  
  323.  if ((handle=_open(conf.logfile,O_RDWR | O_APPEND | O_BINARY | O_DENYWRITE))==-1)
  324.      if ((handle=creat(conf.logfile,S_IWRITE))==-1) return text;
  325.  lseek(handle,0L,SEEK_END);
  326.  if (*text!='*') {
  327.        strcpy(p,fidodate());
  328.        p[16]=0;
  329.        if (nodenumber!=1) {
  330.             sprintf(nn," %-2hu",nodenumber);
  331.             strcat(p,nn);
  332.        }
  333.        else strcat(p,"   ");
  334.        strncat(p,text,126-strlen(p));
  335.        p[126]=0;
  336.  }
  337.  else {
  338.         strncpy(p,&text[1],79);
  339.         p[79]=0;
  340.  }
  341.  _write(handle,p,strlen(p));
  342.  _write(handle,"\r\n",2);
  343.  _close(handle);
  344.  return text;
  345. }
  346.  
  347.  
  348.  
  349. char pascal carrchk (void) { /* Checks for carrier */
  350.  
  351.    if (baud) {
  352.      r.x.dx=conf.commport;
  353.      r.h.ah=GETSTAT;
  354.      int86(20,&r,&r);
  355.      if (!(r.h.al & 128)) {
  356.        if (!userno) goto NoUser;
  357.        sleep(1);
  358.        r.x.dx=conf.commport;
  359.        r.h.ah=GETSTAT;
  360.        int86(20,&r,&r);
  361.        if (!(r.h.al & 128)) {
  362. NoUser:
  363.          baud=0;
  364.          if (leaving) exit(254);
  365.          user.violations++;
  366.          say_prompt(193);
  367.          logoff();
  368.          userno=0;
  369.          leaving++;
  370.          exit(254);
  371.        }
  372.      }
  373.      return r.h.ah;
  374.    }
  375.    return 0;
  376. }
  377.  
  378.  
  379. word pascal find_msgarea (char *filename,char *areaname,int which) {
  380.  
  381.     int handle,x;
  382.     char s[256],descr[83];
  383.     char *p;
  384.     char *pp;
  385.     struct _mboard temp;
  386.     word areano;
  387.     char tempause;
  388.     char eeof=0;
  389.     word zone,net,node;
  390.     char temp_domain[37];
  391.  
  392.     if ((handle=oopen(filename,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
  393.         say_prompt(393);
  394.         return 0;
  395.     }
  396.     if(which==1)areano=atoi(areaname);
  397.     else if (which==2) {
  398.         tempause=pauser;
  399.         pauser=1;
  400.     }
  401.     memcpy(&temp,&mboard,sizeof(struct _mboard));
  402.     zone=conf.alt_zone;
  403.     net=conf.alt_net;
  404.     node=conf.alt_node;
  405.     strcpy(temp_domain,conf.alt_domain);
  406.     while (!eof(handle)) {
  407. BreakIn:
  408.         if (!fgetsx(s,256,handle)) {
  409.             eeof=1;
  410.             break;
  411.         }
  412.         if (*s=='\r' || *s=='\n' || *s==';') continue;
  413.         stripcr(s);
  414.         strtok(s,",");
  415.         strncpy(mboard.name,s,48);
  416.         mboard.name[47]=0;
  417.         if (!which) if (stricmp(s,areaname)) continue;
  418.         mboard.attr=(word)atol(strtok(0," ,"));
  419.         mboard.max=(word)atol(strtok(0," ,"));
  420.         mboard.number=(word)atol(strtok(0," ,"));
  421.         if (which==1) {
  422.              if(mboard.number!=areano) continue;
  423.         }
  424.         mboard.substat1=(word)atol(strtok(0," ,"));
  425.         mboard.substat2=(word)atol(strtok(0," ,"));
  426.         if(mboard.substat1>user.stat[0]) continue;
  427.         p=NULL;
  428.         pp=strtok(0,"\n");
  429.         if(pp && *pp) {
  430.             if(*pp!=',') {
  431.                 p=strtok(pp,",");
  432.                 pp=strtok(0,"\n");
  433.             }
  434.             else pp++;
  435.         }
  436.         if (p!=NULL) strncpy(mboard.forceto,p,36);
  437.         else *mboard.forceto=0;
  438.         mboard.forceto[35]=0;
  439.         p=NULL;
  440.         if(pp && *pp) {
  441.             if(*pp!=',') {
  442.                 p=strtok(pp,",");
  443.                 pp=strtok(0,"\n");
  444.             }
  445.             else pp++;
  446.         }
  447.  
  448.         if(which==2) {
  449.             if(!p)*descr=0;
  450.             else {
  451.                 strcpy(descr,"...");
  452.                 strncat(descr,p,79);
  453.                 descr[82]=0;
  454.             }
  455.         }
  456.  
  457.         p=NULL;
  458.         if(pp && *pp) {
  459.             if(*pp!=',') {
  460.                 p=strtok(pp,",");
  461.                 pp=strtok(0,"\n");
  462.             }
  463.             else pp++;
  464.         }
  465.             if(p!=NULL) {
  466.                 mboard.age=(signed char)atoi(p);
  467.             }
  468.             else mboard.age=0;
  469.             if(mboard.age) {
  470.                 if(mboard.age>0) {
  471.                     if(age<(char)mboard.age) {
  472.                         mboard.substat1=mboard.substat2=65535;
  473.                         continue;
  474.                     }
  475.                 }
  476.                 else {
  477.                     if(age>(char)abs(mboard.age)) {
  478.                         mboard.substat1=mboard.substat2=65535;
  479.                         continue;
  480.                     }
  481.                 }
  482.             }
  483.             p=NULL;
  484.             if(pp && *pp) {
  485.                 if(*pp!=',') {
  486.                     p=strtok(pp,",");
  487.                     pp=strtok(0,"\n");
  488.                 }
  489.                 else pp++;
  490.             }
  491.             if(p!=NULL) {
  492.                 mboard.flags=(word)atol(p);
  493.             }
  494.             else mboard.flags=0;
  495.             if(mboard.flags) {
  496.                 for(x=0;x<16;x++) {
  497.                     if(mboard.flags & (1<<x)) {
  498.                         if(!(user.attr2 & (1<<x))) {
  499.                             mboard.substat1=mboard.substat2=65535;
  500.                             goto BreakIn;
  501.                         }
  502.                     }
  503.                 }
  504.             }
  505.             p=NULL;
  506.             if(pp && *pp) {
  507.                 if(*pp!=',') {
  508.                     p=strtok(pp,",");
  509.                     pp=strtok(0,"\n");
  510.                 }
  511.                 else pp++;
  512.             }
  513.  
  514.  
  515.         if(which!=2) {
  516.             if(p!=NULL) {
  517.                 conf.alt_zone=(word)atol(p);
  518.                 while(*p && *p!=':')p++;
  519.                 if(*p)p++;
  520.                 conf.alt_net=(word)atol(p);
  521.                 while(*p && *p!='/')p++;
  522.                 if(*p)p++;
  523.                 conf.alt_node=(word)atol(p);
  524.                 while(*p && *p!='@')p++;
  525.                 if(*p)p++;
  526.                 if(p) {
  527.                     strncpy(conf.alt_domain,p,37);
  528.                     conf.alt_domain[36]=0;
  529.                 }
  530.             }
  531.             p=NULL;
  532.             if(pp && *pp) {
  533.                 if(*pp!=',') {
  534.                     p=strtok(pp,",");
  535.                     pp=strtok(0,"\n");
  536.                 }
  537.                 else pp++;
  538.             }
  539.             p=NULL;
  540.             if(pp && *pp) {
  541.                 if(*pp!=',') {
  542.                     p=strtok(pp,",");
  543.                     pp=strtok(0,"\n");
  544.                 }
  545.                 else pp++;
  546.             }
  547.             if(p)mboard.minwrite=(word)atol(p);
  548.             else mboard.minwrite=0;
  549.         }
  550.         else {
  551.             if(gprintf(0,"%-4u  %s%s\n",mboard.number,mboard.name,descr)) break;
  552.             continue;
  553.         }
  554.         break;
  555.     }
  556.     if (eeof || eof(handle) || mboard.substat1>user.stat[0] || which==2 || !*mboard.name) {
  557.         memcpy(&mboard,&temp,sizeof(struct _mboard));
  558.         conf.alt_zone=zone;
  559.         conf.alt_net=net;
  560.         conf.alt_node=node;
  561.         strcpy(conf.alt_domain,temp_domain);
  562.         cclose(handle);
  563.         if(which==2)pauser=tempause;
  564.         return 0;
  565.     }
  566.     cclose(handle);
  567.     return (mboard.number);
  568. }
  569.  
  570.  
  571. word pascal find_filearea (char *filename,char *areaname,word seclvl) {
  572.  
  573.     int handle;
  574.     char s[256];
  575.     char *p,*adescr;
  576.     struct _fboard temp;
  577.     word security=0;
  578.     char tempause;
  579.     word which=0;
  580.     word x=0;
  581.     char eeof=0;
  582.  
  583.     if ((handle=oopen(filename,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
  584.         say_prompt(392);
  585.         return 0;
  586.     }
  587.     if(!strcmp(areaname,"___")) {
  588.         tempause=pauser;
  589.         pauser=tempause;
  590.     }
  591.     if(*areaname=='#') which=(word)atol(&areaname[1]);
  592.     memcpy(&temp,&fboard,sizeof(struct _fboard));
  593.     while (!eof(handle)) {
  594. BreakIn:
  595.         if (!fgetsx(s,256,handle)) break;
  596.         if (*s=='\n' || *s=='\r' || *s==';') continue;
  597.         stripcr(s);
  598.         strncpy(fboard.dpath,strtok(s," "),79);
  599.         fboard.dpath[78]=0;
  600.         if (fboard.dpath[strlen(fboard.dpath)-1]!='\\') strcat(fboard.dpath,"\\");
  601.         security=(word)atol(strtok(0," "));
  602.         if(seclvl<security) continue;
  603.         x++;
  604.         strncpy(fboard.name,strtok(0," "),47);
  605.         fboard.name[46]=0;
  606.         while((p=strchr(fboard.name,'_'))!=NULL) *p=' ';
  607.         fboard.flags=(char)atoi(strtok(0," "));
  608.         p=strtok(0," ");
  609.         if (p) {
  610.             strncpy(fboard.upath,p,79);
  611.             fboard.upath[78]=0;
  612.             if (fboard.upath[strlen(fboard.upath)-1]!='\\') strcat(fboard.upath,"\\");
  613.         }
  614.         else strcpy(fboard.upath,"NUL");
  615.         adescr=strtok(0,",");
  616.         p=strtok(0,",");
  617.         if(p) fboard.age=(signed char)atoi(p);
  618.         else fboard.age=0;
  619.         if(fboard.age) {
  620.                 if(fboard.age>0) {
  621.                     if(age<(char)fboard.age) {
  622.                         security=65535;
  623.                         continue;
  624.                     }
  625.                 }
  626.                 else {
  627.                     if(age>(char)abs(fboard.age)) {
  628.                         security=65535;
  629.                         continue;
  630.                     }
  631.                 }
  632.         }
  633.         p=strtok(0,",");
  634.         if(p) fboard.userflags=(word)atol(p);
  635.         else fboard.userflags=0;
  636.         if(fboard.userflags) {
  637.             for(x=0;x<16;x++) {
  638.                 if(fboard.userflags & (1<<x)) {
  639.                     if(!(user.attr2 & (1<<x))) {
  640.                         security=65535;
  641.                         goto BreakIn;
  642.                     }
  643.                 }
  644.             }
  645.         }
  646.         p=strtok(0,",");
  647.         if(p) fboard.leechpercent=(char)atol(p);
  648.         else fboard.leechpercent=0;
  649.         if(!strcmp(areaname,"___")) {
  650.             if(!adescr) adescr="";
  651.             else {
  652.                 strcpy(s,"...");
  653.                 strncat(s,adescr,79);
  654.                 s[81]=0;
  655.                 adescr=s;
  656.             }
  657.             if(gprintf(0,"%-5u  %s%s\n",x,fboard.name,adescr)) break;
  658.             continue;
  659.         }
  660.         if (!stricmp(fboard.name,areaname)) break;
  661.         if(which) {
  662.             if(which==x) break;
  663.         }
  664.     }
  665.     if (eeof || eof(handle) || seclvl<security || !strcmp(areaname,"___")) {
  666.         memcpy(&fboard,&temp,sizeof(struct _fboard));
  667.         if(!strcmp(areaname,"___")) pauser=tempause;
  668.         cclose(handle);
  669.         return 0;
  670.     }
  671.     cclose(handle);
  672.     return 1;
  673. }
  674.  
  675.  
  676.  
  677. void * pascal mmalloc (unsigned int size) {
  678.  
  679.     register int x;
  680.  
  681.     for(x=0;x<MAXALLOCHANDLES;x++) {
  682.         if(allochandles[x]==NULL) {
  683.             allochandles[x]=(void *)malloc(size);
  684.             if(conf.whichstat==2) redraw_stat(NULL);
  685.             return allochandles[x];
  686.         }
  687.     }
  688.     addtolog("\nOut of memory handles!\n");
  689.     strcpy(startfile,"MAIN.XBS");
  690.     longjmp(envbuf,99);
  691. }
  692.  
  693.  
  694. void pascal ffree (void *ptr) {
  695.  
  696.     register int x;
  697.  
  698.     if (ptr==NULL) return;
  699.     for(x=0;x<MAXALLOCHANDLES;x++) {
  700.         if(ptr==allochandles[x]) {
  701.             free(ptr);
  702.             ptr=NULL;
  703.             allochandles[x]=NULL;
  704.             if(conf.whichstat==2) redraw_stat(NULL);
  705.             break;
  706.         }
  707.     }
  708. }
  709.  
  710.  
  711. int pascal oopen (char *filename,int access) {
  712.  
  713.     register int x;
  714.  
  715.     for(x=0;x<MAXFPHANDLES;x++) {
  716.         if(fphandles[x] == -1) {
  717.             fphandles[x] = _open(filename,access);
  718.  
  719.         /* This lets you allow a user to enter a filename to open without
  720.            having to worry about things like "CON.TXT" being entered and
  721.            effectively crashing the system */
  722.  
  723.             if (fphandles[x] != -1) {             /* it aint there */
  724.                     r.h.ah=0x44;
  725.                     r.h.al=0x00;
  726.                     r.x.bx=fphandles[x];
  727.                     int86(33,&r,&r);                /* see if device */
  728.                     cclose(x);                      /* close handle  */
  729.                     if ((int)r.h.al == -1) {        /* some error    */
  730.                         _close(fphandles[x]);
  731.                         fphandles[x] = -1;
  732.                         return -1;
  733.                     }
  734.                     if(r.h.al & 0x80) {      /* 0x80 is the device bit */
  735.                         _close(fphandles[x]);
  736.                         fphandles[x]=-1;
  737.                         say_prompt(198);
  738.                         return -1;
  739.                     }
  740.             }
  741.  
  742.             if(conf.whichstat==2 && fphandles[x] != -1) redraw_stat(NULL);
  743. /*
  744. gprintf(LOCALONLY,"\nOpened handle %d (%d)\n",fphandles[x],x);
  745. */
  746.             return fphandles[x];
  747.         }
  748.     }
  749.     gprintf(LOCALONLY | LOGONLY,"\nOut of file handles!\n");
  750.     strcpy(startfile,"MAIN.XBS");
  751.     if(envbuf)longjmp(envbuf,99);
  752.     return -1;
  753. }
  754.  
  755.  
  756. void pascal cclose (int handle) {
  757.  
  758.     register int x;
  759.  
  760.     if(handle==-1) return;
  761.     for(x=0;x<MAXFPHANDLES;x++) {
  762.         if(fphandles[x]==handle) {
  763. /*
  764. gprintf(LOCALONLY,"\nClosing %d (%d)\n",fphandles[x],x);
  765. */
  766.             _close(handle);
  767.             fphandles[x]=(-1);
  768.             if(conf.whichstat==2) redraw_stat(NULL);
  769.             break;
  770.         }
  771.     }
  772. }
  773.  
  774.  
  775. int pascal ccreat (char *filename,int mode) {
  776.  
  777.     register int x;
  778.  
  779.     for(x=0;x<MAXFPHANDLES;x++) {
  780.         if(fphandles[x]==-1) {
  781.             fphandles[x]=creat(filename,mode);
  782.             if(conf.whichstat==2) redraw_stat(NULL);
  783.             return fphandles[x];
  784.         }
  785.     }
  786.     gprintf(LOCALONLY | LOGONLY,"\nOut of file handles!\n");
  787.     strcpy(startfile,"MAIN.XBS");
  788.     if(envbuf)longjmp(envbuf,99);
  789.     return -1;
  790. }
  791.  
  792.  
  793. void pascal ccloseall (void) {
  794.  
  795.     register int x;
  796.  
  797.     for(x=0;x<MAXFPHANDLES;x++) {
  798.         if(fphandles[x]!=-1) {
  799.             _close(fphandles[x]);
  800.             fphandles[x]=(-1);
  801.         }
  802.     }
  803.     if(conf.whichstat==2) redraw_stat(NULL);
  804. }
  805.  
  806.  
  807.  
  808. void pascal ffreeall (void) {
  809.  
  810.     register int x;
  811.  
  812.     for(x=0;x<MAXALLOCHANDLES;x++) {
  813.         if(allochandles[x]!=NULL) {
  814.             free(allochandles[x]);
  815.             allochandles[x]=NULL;
  816.         }
  817.     }
  818.     if(conf.whichstat==2) redraw_stat(NULL);
  819. }
  820.  
  821.  
  822. word pascal next_filearea (char *filename,word seclvl) {
  823.  
  824.     word register x;
  825.     static long next_pos=0L;
  826.     char s[256];
  827.     char *p;
  828.     word security=0;
  829.     int handle;
  830.     char name[48];
  831.     word flags;
  832.     signed char fage;
  833.  
  834.     if(filename==NULL) {
  835.         next_pos=0L;
  836.         return 0;
  837.     }
  838.     if ((handle=oopen(filename,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
  839.         say_prompt(392);
  840.         return 0;
  841.     }
  842.     lseek(handle,next_pos,SEEK_SET);
  843.     level=0;
  844. Loop:
  845.     if (!fgetsx(s,256,handle)) {
  846.          next_pos=0L;
  847.          level=1;
  848.          cclose(handle);
  849.          return 0;
  850.     }
  851.     next_pos=tell(handle);
  852.     if (*s=='\n' || *s=='\r' || *s==';') goto Loop;
  853.     stripcr(s);
  854.     strtok(s," ");
  855.     security=(word)atol(strtok(0," "));
  856.     if (eof(handle)) {
  857.         level=1;
  858.         next_pos=0L;
  859.     }
  860.     if(seclvl>=security) {
  861.         p=strtok(0," ");
  862.         if(p) {
  863.             strncpy(name,p,46);
  864.             name[46]=0;
  865.             while((p=strchr(name,'_'))!=NULL) *p=' ';
  866.             strtok(0," ");
  867.             strtok(0," ");
  868.             strtok(0,",");
  869.             p=strtok(0,",");
  870.             if(p) fage=(signed char)atoi(p);
  871.             else fage=0;
  872.             if(fage) {
  873.                     if(fage>0) {
  874.                         if(age<(char)fage) {
  875.                             goto Loop;
  876.                         }
  877.                     }
  878.                     else {
  879.                         if(age>(char)abs(fage)) {
  880.                             goto Loop;
  881.                         }
  882.                     }
  883.             }
  884.             p=strtok(0,",");
  885.             if(p) flags=(word)atol(p);
  886.             else flags=0;
  887.             if(flags) {
  888.                 for(x=0;x<16;x++) {
  889.                     if(flags & (1<<x)) {
  890.                         if(!(user.attr2 & (1<<x))) {
  891.                             goto Loop;
  892.                         }
  893.                     }
  894.                 }
  895.             }
  896.         }
  897.         find_filearea(filename,name,seclvl);
  898.     }
  899.     else if (next_pos) goto Loop;
  900.     else {
  901.         cclose(handle);
  902.         level=1;
  903.         return 0;
  904.     }
  905.     cclose(handle);
  906.     return 1;
  907. }
  908.  
  909.  
  910. word pascal next_msgarea (char *filename) {
  911.  
  912.     word register x;
  913.     static long next_pos=0L;
  914.     char s[256];
  915.     char *p,*pp;
  916.     int handle;
  917.     word number;
  918.     word substat1;
  919.     word flags;
  920.     signed char mage;
  921.  
  922.     if(filename==NULL) {
  923.         next_pos=0L;
  924.         return 0;
  925.     }
  926.     if ((handle=oopen(filename,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
  927.         say_prompt(392);
  928.         return 0;
  929.     }
  930.     lseek(handle,next_pos,SEEK_SET);
  931.     level=0;
  932. Loop:
  933.     if (!fgetsx(s,256,handle)) {
  934.          next_pos=0L;
  935.          level=1;
  936.          cclose(handle);
  937.          return 0;
  938.     }
  939.     next_pos=tell(handle);
  940.     if (*s=='\n' || *s=='\r' || *s==';') goto Loop;
  941.     stripcr(s);
  942.     if(!strtok(s,",")) goto Loop;
  943.     strtok(0," ,");
  944.     strtok(0," ,");
  945.     number=(word)atol(strtok(0," ,"));
  946.     substat1=(word)atol(strtok(0," ,"));
  947.     if(substat1>user.stat[0]) goto Loop;
  948.     p=NULL;
  949.     pp=strtok(0,"\n");
  950.     if(pp && *pp) {
  951.         if(*pp!=',') {
  952.             p=strtok(pp,",");
  953.             pp=strtok(0,"\n");
  954.         }
  955.         else pp++;
  956.     }
  957.     p=NULL;
  958.     if(pp && *pp) {
  959.         if(*pp!=',') {
  960.             p=strtok(pp,",");
  961.             pp=strtok(0,"\n");
  962.         }
  963.         else pp++;
  964.     }
  965.     p=NULL;
  966.     if(pp && *pp) {
  967.         if(*pp!=',') {
  968.             p=strtok(pp,",");
  969.             pp=strtok(0,"\n");
  970.         }
  971.         else pp++;
  972.     }
  973.     if(pp && *pp) {
  974.         if(*pp!=',') {
  975.             p=strtok(pp,",");
  976.             pp=strtok(0,"\n");
  977.         }
  978.         else pp++;
  979.     }
  980.     if(p!=NULL) {
  981.         mage=(signed char)atoi(p);
  982.     }
  983.     else mage=0;
  984.     if(mage) {
  985.         if(mage>0) {
  986.             if(age<(char)mage) {
  987.                 goto Loop;
  988.             }
  989.         }
  990.         else {
  991.             if(age>(char)abs(mage)) {
  992.                 goto Loop;
  993.             }
  994.         }
  995.     }
  996.     p=NULL;
  997.     if(pp && *pp) {
  998.         if(*pp!=',') {
  999.             p=strtok(pp,",");
  1000.             pp=strtok(0,"\n");
  1001.         }
  1002.         else pp++;
  1003.     }
  1004.     if(p!=NULL) {
  1005.         flags=(word)atol(p);
  1006.     }
  1007.     else flags=0;
  1008.     if(flags) {
  1009.         for(x=0;x<16;x++) {
  1010.             if(flags & (1<<x)) {
  1011.                 if(!(user.attr2 & (1<<x))) {
  1012.                     goto Loop;
  1013.                 }
  1014.             }
  1015.         }
  1016.     }
  1017.     cclose(handle);
  1018.     if(find_msgarea(filename,s,0)) return number;
  1019.     return 0;
  1020. }
  1021.  
  1022.  
  1023. char pascal printg (char *text) {
  1024.  
  1025.     char temppause;
  1026.     char returnval;
  1027.  
  1028.     if (user.graphics) {
  1029.         temppause=pauser;
  1030.         pauser=2;
  1031.         returnval=(printm(text));
  1032.         pauser=temppause;
  1033.         return returnval;
  1034.     }
  1035.     return 0;
  1036.  
  1037. }
  1038.  
  1039.  
  1040. void pascal backup (char *p) {
  1041.  
  1042.   while(*p++) printm(BACKSPACE);
  1043. }
  1044.  
  1045.  
  1046. void pascal backupnum (int p) {
  1047.  
  1048.   while(p--) printm(BACKSPACE);
  1049. }
  1050.  
  1051.  
  1052. char * pascal mystrdup (char *str) {    /* Replaces strdup() */
  1053.  
  1054.     char *s;
  1055.  
  1056.     s=(char *)mmalloc(strlen(str));
  1057.     if(!s) return NULL;
  1058.     strcpy(s,str);
  1059.     return s;
  1060. }
  1061.  
  1062.  
  1063. char * pascal var_trans (char *str) {
  1064.  
  1065.     static char s[34];
  1066.  
  1067.     if(str==NULL) return "";
  1068.     if(*str=='@') {
  1069.         if(isdigit(str[1])) {
  1070.             return variable[str[1]-'0'];
  1071.         }
  1072.     }
  1073.     if(*str=='e') {
  1074.         if(isdigit(str[1])) {
  1075.             sprintf(s,"%u",lastlevel[str[1]]);
  1076.             return s;
  1077.         }
  1078.     }
  1079.     return str;
  1080. }
  1081.  
  1082.  
  1083. int pascal isleech (char percent) {
  1084.  
  1085.     if(!user.ignorerat && (user.downno>(word)conf.startat) && percent) {
  1086.         if(((long)fboard.leechpercent<(long)(user.downk/user.upk))) {
  1087.             if(((long)fboard.leechpercent<(long)(user.downno/user.upno))) {
  1088.                 return 1;
  1089.             }
  1090.         }
  1091.     }
  1092.     return 0;
  1093. }
  1094.