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

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1991 by Wayne Bell
  5.  
  6. *****************************************************************************/
  7. #include "vars.h"
  8. #pragma hdrstop
  9. #include <dir.h>
  10. #include <math.h>
  11.  
  12. /* functions for external programs to call */
  13.  
  14. #pragma warn -par
  15.  
  16. void far interrupt inlii(unsigned bp, unsigned di, unsigned si,
  17.                            unsigned ds, unsigned es, unsigned dx,
  18.                            unsigned cx, unsigned bx, unsigned ax,
  19.                            unsigned ip, unsigned cs, unsigned flags,
  20.                            char *s1, char *s2, int i1, int i2)
  21. {
  22.   inli(s1,s2,i1,i2);
  23. }
  24.  
  25. void far interrupt checkai(unsigned bp, unsigned di, unsigned si,
  26.                            unsigned ds, unsigned es, unsigned dx,
  27.                            unsigned cx, unsigned bx, unsigned ax,
  28.                            unsigned ip, unsigned cs, unsigned flags,
  29.                            int *i1, int *i2)
  30. {
  31.   checka(i1,i2);
  32. }
  33.  
  34. void far interrupt plai(unsigned bp, unsigned di, unsigned si,
  35.                            unsigned ds, unsigned es, unsigned dx,
  36.                            unsigned cx, unsigned bx, unsigned ax,
  37.                            unsigned ip, unsigned cs, unsigned flags,
  38.                            char *s1, int *i1)
  39. {
  40.   pla(s1,i1);
  41. }
  42.  
  43. void far interrupt outchri(unsigned bp, unsigned di, unsigned si,
  44.                            unsigned ds, unsigned es, unsigned dx,
  45.                            unsigned cx, unsigned bx, unsigned ax,
  46.                            unsigned ip, unsigned cs, unsigned flags,
  47.                            char ch)
  48. {
  49.   outchr(ch);
  50. }
  51.  
  52. void far interrupt outstri(unsigned bp, unsigned di, unsigned si,
  53.                            unsigned ds, unsigned es, unsigned dx,
  54.                            unsigned cx, unsigned bx, unsigned ax,
  55.                            unsigned ip, unsigned cs, unsigned flags,
  56.                            char *s1)
  57. {
  58.   outstr(s1);
  59. }
  60.  
  61. void far interrupt nli(unsigned bp, unsigned di, unsigned si,
  62.                            unsigned ds, unsigned es, unsigned dx,
  63.                            unsigned cx, unsigned bx, unsigned ax,
  64.                            unsigned ip, unsigned cs, unsigned flags)
  65. {
  66.   nl();
  67. }
  68.  
  69. void far interrupt pli(unsigned bp, unsigned di, unsigned si,
  70.                            unsigned ds, unsigned es, unsigned dx,
  71.                            unsigned cx, unsigned bx, unsigned ax,
  72.                            unsigned ip, unsigned cs, unsigned flags,
  73.                            char *s1)
  74. {
  75.   pl(s1);
  76. }
  77.  
  78. void far interrupt emptyi(unsigned bp, unsigned di, unsigned si,
  79.                            unsigned ds, unsigned es, unsigned dx,
  80.                            unsigned cx, unsigned bx, unsigned ax,
  81.                            unsigned ip, unsigned cs, unsigned flags)
  82. {
  83.   ax=empty();
  84. }
  85.  
  86. void far interrupt inkeyi(unsigned bp, unsigned di, unsigned si,
  87.                            unsigned ds, unsigned es, unsigned dx,
  88.                            unsigned cx, unsigned bx, unsigned ax,
  89.                            unsigned ip, unsigned cs, unsigned flags)
  90. {
  91.   ax=(unsigned) empty();
  92. }
  93.  
  94. void far interrupt getkeyi(unsigned bp, unsigned di, unsigned si,
  95.                            unsigned ds, unsigned es, unsigned dx,
  96.                            unsigned cx, unsigned bx, unsigned ax,
  97.                            unsigned ip, unsigned cs, unsigned flags)
  98. {
  99.   ax=(unsigned) getkey();
  100. }
  101.  
  102. void far interrupt inputi(unsigned bp, unsigned di, unsigned si,
  103.                            unsigned ds, unsigned es, unsigned dx,
  104.                            unsigned cx, unsigned bx, unsigned ax,
  105.                            unsigned ip, unsigned cs, unsigned flags,
  106.                            char *s1, int i)
  107. {
  108.   input(s1,i);
  109. }
  110.  
  111. void far interrupt inputli(unsigned bp, unsigned di, unsigned si,
  112.                            unsigned ds, unsigned es, unsigned dx,
  113.                            unsigned cx, unsigned bx, unsigned ax,
  114.                            unsigned ip, unsigned cs, unsigned flags,
  115.                            char *s1, int i)
  116. {
  117.   inputl(s1,i);
  118. }
  119.  
  120. void far interrupt yni(unsigned bp, unsigned di, unsigned si,
  121.                            unsigned ds, unsigned es, unsigned dx,
  122.                            unsigned cx, unsigned bx, unsigned ax,
  123.                            unsigned ip, unsigned cs, unsigned flags)
  124. {
  125.   ax=yn();
  126. }
  127.  
  128. void far interrupt nyi(unsigned bp, unsigned di, unsigned si,
  129.                            unsigned ds, unsigned es, unsigned dx,
  130.                            unsigned cx, unsigned bx, unsigned ax,
  131.                            unsigned ip, unsigned cs, unsigned flags)
  132. {
  133.   ax=ny();
  134. }
  135.  
  136. void far interrupt ansici(unsigned bp, unsigned di, unsigned si,
  137.                            unsigned ds, unsigned es, unsigned dx,
  138.                            unsigned cx, unsigned bx, unsigned ax,
  139.                            unsigned ip, unsigned cs, unsigned flags,
  140.                            int i1)
  141. {
  142.   ansic(i1);
  143. }
  144.  
  145. void far interrupt oneki(unsigned bp, unsigned di, unsigned si,
  146.                            unsigned ds, unsigned es, unsigned dx,
  147.                            unsigned cx, unsigned bx, unsigned ax,
  148.                            unsigned ip, unsigned cs, unsigned flags,
  149.                            char *s1)
  150. {
  151.   ax=(unsigned) onek(s1);
  152. }
  153.  
  154. void far interrupt prti(unsigned bp, unsigned di, unsigned si,
  155.                            unsigned ds, unsigned es, unsigned dx,
  156.                            unsigned cx, unsigned bx, unsigned ax,
  157.                            unsigned ip, unsigned cs, unsigned flags,
  158.                            int i1, char *s1)
  159. {
  160.   prt(i1,s1);
  161. }
  162.  
  163. void far interrupt mpli(unsigned bp, unsigned di, unsigned si,
  164.                            unsigned ds, unsigned es, unsigned dx,
  165.                            unsigned cx, unsigned bx, unsigned ax,
  166.                            unsigned ip, unsigned cs, unsigned flags,
  167.                            int i1)
  168. {
  169.   mpl(i1);
  170. }
  171.  
  172. #pragma warn +par
  173.  
  174. /* end of functions for external programs to call */
  175.  
  176. void reset_act_sl()
  177. {
  178.   actsl = thisuser.sl;
  179. }
  180.  
  181. void remove_from_temp(char *fn, char *dir, int po)
  182. {
  183.   int i,i1,f1,ok;
  184.   char s[81],s1[81];
  185.   struct ffblk ff;
  186.   uploadsrec u;
  187.  
  188.   sprintf(s1,"%s%s",dir,stripfn(fn));
  189.   f1=findfirst(s1,&ff,0);
  190.   ok=1;
  191.   nl();
  192.   while ((f1==0) && (ok)) {
  193.     sprintf(s,"%s%s",dir,ff.ff_name);
  194.     if (po)
  195.       npr("Deleting %s\r\n",ff.ff_name);
  196.     _chmod(s,1,0);
  197.     unlink(s);
  198.     f1=findnext(&ff);
  199.   }
  200. }
  201.  
  202. void check_event()
  203. {
  204.   double tl;
  205.  
  206.   if (syscfg.executetime) {
  207.     tl=time_event-timer();
  208.     if (tl<0.0)
  209.       tl += 24.0*3600.0;
  210.     if ((tl-last_time)>2.0)
  211.       do_event=1;
  212.     last_time=tl;
  213.   }
  214. }
  215.  
  216. void run_event()
  217. {
  218.   if ((do_event) && (syscfg.executetime)) {
  219.     do_event=0;
  220.     nl();
  221.     pl("Now running external event.");
  222.     nl();
  223.     if (syscfg.executestr[0]) {
  224.       holdphone(1);
  225.       shrink_out(syscfg.executestr,0,0,0,1);
  226.       /* run_external(syscfg.executestr); */
  227.       holdphone(0);
  228.     } else
  229.       end_bbs(oklevel);
  230.   }
  231.   clrscrb();
  232. }
  233.  
  234. double freek(int dr)
  235. {
  236.   float d;
  237.   struct dfree df;
  238.  
  239.   getdfree(dr,&df);
  240.   d=(float) df.df_avail;
  241.   d*=((float) df.df_bsec);
  242.   d*=((float) df.df_sclus);
  243.   d/=1024.0;
  244.   if (df.df_sclus<0)
  245.   d=-1.0;
  246.   return(d);
  247. }
  248.  
  249. unsigned char years_old(unsigned char m, unsigned char d, unsigned char y)
  250. {
  251.   struct date today;
  252.   int a;
  253.  
  254.   getdate(&today);
  255.   a=(int) (today.da_year-1900-y);
  256.   if (today.da_mon<m)
  257.     --a;
  258.   else
  259.     if ((today.da_mon==m) && (today.da_day<d))
  260.       --a;
  261.   return((unsigned char)a);
  262. }
  263.  
  264. void itimer()
  265. /* This function initializes the high-resolution timer */
  266. {
  267.   outportb(0x43,0x34);
  268.   outportb(0x40,0x00);
  269.   outportb(0x40,0x00);
  270.  
  271. }
  272.  
  273. double timer()
  274. /* This function returns the time, in seconds since midnight. */
  275. {
  276.   double cputim;
  277.   unsigned short int h,m,l1,l2;
  278.  
  279.   disable();
  280.   outportb(0x43,0x00);
  281.   m=peek(0x0040,0x006c);
  282.   h=peek(0x0040,0x006e);
  283.   l1=inportb(0x40);
  284.   l2=inportb(0x40);
  285.   enable();
  286.   l1=((l2*256)+l1) ^ 65535;
  287.   cputim=((h*65536. + m)*65536. + l1)*8.380955e-7;
  288.   return (cputim);
  289. }
  290.  
  291. long timer1()
  292. /* This function returns the time, in ticks since midnight. */
  293. {
  294.   unsigned short h,m;
  295.   long l;
  296.  
  297.   m=peek(0x0040,0x006c);
  298.   h=peek(0x0040,0x006e);
  299.   l=((long)h)*65536 + ((long)m);
  300.   return(l);
  301. }
  302.  
  303. int sysop1()
  304. /* This function returns the status of scoll lock.  If scroll lock is active
  305.  * (ie, the user has hit scroll lock + the light is lit if there is a
  306.  * scoll lock LED), the sysop is assumed to be available.
  307.  */
  308. {
  309.   if ((peekb(0,1047) & 0x10)==0)
  310.     return(0);
  311.   else
  312.     return(1);
  313. }
  314.  
  315. int okansi()
  316. /* This function checks the status of the current user's record to see if
  317.  * the user has specified that he wants ANSI graphics displayed.
  318.  */
  319. {
  320.   if (thisuser.sysstatus & sysstatus_ansi)
  321.     return(1);
  322.   else
  323.     return(0);
  324. }
  325.  
  326. void frequent_init()
  327. /* This should be called after a user is logged off, and will initialize
  328.  * screen-access variables.
  329.  */
  330. {
  331.   curlsub=-1;
  332.   ansiptr=0;
  333.   curatr=0x07;
  334.   outcom=0;
  335.   incom=0;
  336.   charbufferpointer=0;
  337.   andwith=0xff;
  338.   checkit=0;
  339.   topline=0;
  340.   screenlinest=defscreenbottom+1;
  341.   if (!restoring_shrink)
  342.     clrscrb();
  343.   endofline[0]=0;
  344.   hangup=0;
  345.   hungup=0;
  346.   chatcall=0;
  347.   chatreason[0]=0;
  348.   useron=0;
  349.   change_color=0;
  350.   chatting=0;
  351.   echo=1;
  352.   irt[0]=0;
  353.   irt_name[0]=0;
  354.   okskey=0;
  355.   lines_listed=0;
  356.   read_user(1,&thisuser);
  357.   if (thisuser.inact & inact_deleted)
  358.     fwaiting=0;
  359.   else
  360.     fwaiting=thisuser.waiting;
  361.   okmacro=1;
  362.   okskey=1;
  363.   helpl=0;
  364.   ihelp=0;
  365.   mailcheck=0;
  366.   smwcheck=0;
  367.   in_extern=0;
  368.   gatfn[0]=0;
  369.   use_workspace=0;
  370.   extratimecall=0.0;
  371.   two_color=0;
  372.   using_modem=0;
  373.   set_global_handle(0);
  374.   live_user=1;
  375.   _chmod(dszlog,1,0);
  376.   unlink(dszlog);
  377. }
  378.  
  379. void read_in_file(char *fn, messagerec *m, int maxary)
  380. {
  381.   int i,i1,i2;
  382.   char *buf,s[81];
  383.   long l,l1;
  384.  
  385.   for (i=0; i<maxary; i++) {
  386.     m[i].stored_as=0L;
  387.     m[i].storage_type=255;
  388.   }
  389.   sprintf(s,"%s%s",syscfg.gfilesdir,fn);
  390.   i=open(s,O_RDWR | O_BINARY);
  391.   if (i<0) {
  392.     printf("%s NOT FOUND.\n",s);
  393.     end_bbs(noklevel);
  394.   }
  395.   l=filelength(i);
  396.   buf=(char *) farmalloc(l);
  397.   lseek(i,0L,SEEK_SET);
  398.   if (buf==NULL) {
  399.     printf("NOT ENOUGH MEMORY.\n");
  400.     end_bbs(noklevel);
  401.   }
  402.   read(i,(void *) buf,l);
  403.   close(i);
  404.   i1=0;
  405.   for (l1=0; l1<l; l1++) {
  406.     if (buf[l1]=='`') {
  407.       i1=1;
  408.       i2=0;
  409.     } else
  410.       if (i1) {
  411.         if ((buf[l1]>='0') && (buf[l1]<='9')) {
  412.           i2*=10;
  413.           i2+=(buf[l1])-'0';
  414.         } else {
  415.           while ((l1<l) && (buf[l1]!=10))
  416.             ++l1;
  417.           ++l1;
  418.           if ((i2>=0) && (i2<maxary))
  419.             m[i2].stored_as=l1;
  420.           i1=0;
  421.         }
  422.       }
  423.   }
  424.   farfree((void *) buf);
  425. }
  426.  
  427. void far *mallocx(unsigned long l)
  428. {
  429.   void *x;
  430.  
  431.   x=farmalloc(l);
  432.   if (!x) {
  433.     printf("NOT ENOUGH MEMORY.\n");
  434.     end_bbs(noklevel);
  435.   }
  436.   return(x);
  437. }
  438.  
  439. void fix_user_rec(userrec *u)
  440. {
  441.   u->name[30]=0;
  442.   u->realname[20]=0;
  443.   u->zipcode[6]=0;
  444.   u->phone[12]=0;
  445.   u->pw[8]=0;
  446.   u->laston[8]=0;
  447.   u->note[40]=0;
  448.   u->macros[0][80]=0;
  449.   u->macros[1][80]=0;
  450.   u->macros[2][80]=0;
  451. }
  452.  
  453. void close_user()
  454. {
  455.   if (userfile!=-1) {
  456.     close(userfile);
  457.     userfile=-1;
  458.   }
  459. }
  460.  
  461. void open_user()
  462. {
  463.   char s[81];
  464.  
  465.   if (userfile==-1) {
  466.     sprintf(s,"%sUSER.LST",syscfg.datadir);
  467.     userfile=open(s,O_RDWR | O_BINARY);
  468.     if (userfile<0) {
  469.       userfile=-1;
  470.     }
  471.   }
  472. }
  473.  
  474. int number_userrecs()
  475. {
  476.   open_user();
  477.   return((int) (filelength(userfile)/syscfg.userreclen)-1);
  478. }
  479.  
  480. void read_user(unsigned int un, userrec *u)
  481. {
  482.   long pos;
  483.   char s[80];
  484.   int i;
  485.  
  486.   open_user();
  487.   if ((userfile<0) || (un>number_userrecs())) {
  488.     u->inact=inact_deleted;
  489.     fix_user_rec(u);
  490.     return;
  491.   }
  492.  
  493.   if (((useron) && (un==usernum)) || ((wfc) && (un==1))) {
  494.     *u=thisuser;
  495.     fix_user_rec(u);
  496.     return;
  497.   }
  498.   pos=((long) syscfg.userreclen) * ((long) un);
  499.   lseek(userfile,pos,SEEK_SET);
  500.   i=read(userfile, (void *)u, syscfg.userreclen);
  501.   if (i==-1) {
  502.     open_user();
  503.     if ((userfile<0) || (un>number_userrecs())) {
  504.       u->inact=inact_deleted;
  505.       fix_user_rec(u);
  506.       return;
  507.     }
  508.     pos=((long) syscfg.userreclen) * ((long) un);
  509.     lseek(userfile,pos,SEEK_SET);
  510.     i=read(userfile, (void *)u, syscfg.userreclen);
  511.     if (i==-1) {
  512.       pl("COULDN'T READ USER.");
  513.     }
  514.     close_user();
  515.   }
  516.   fix_user_rec(u);
  517. }
  518.  
  519. void write_user(unsigned int un, userrec *u)
  520. {
  521.   long pos;
  522.   char s[80];
  523.   unsigned char oldsl;
  524.   int i;
  525.  
  526.   if (userfile==-1) {
  527.     sprintf(s,"%sUSER.LST",syscfg.datadir);
  528.     userfile=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  529.   }
  530.   if (((useron) && (un==usernum)) || ((wfc) && (un==1))) {
  531.     thisuser=*u;
  532.   }
  533.   pos=((long) syscfg.userreclen) * ((long) un);
  534.   lseek(userfile,pos,SEEK_SET);
  535.   i=write(userfile, (void *)u, syscfg.userreclen);
  536.   if (i==-1) {
  537.     sprintf(s,"%sUSER.LST",syscfg.datadir);
  538.     userfile=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  539.     pos=((long) syscfg.userreclen) * ((long) un);
  540.     lseek(userfile,pos,SEEK_SET);
  541.     i=write(userfile, (void *)u, syscfg.userreclen);
  542.     if (i==-1) {
  543.       pl("COULDN'T WRITE USER.");
  544.     }
  545.     close_user();
  546.   }
  547. }
  548.  
  549. void save_status()
  550. {
  551.   char s[80];
  552.  
  553.   sprintf(s,"%sSTATUS.DAT",syscfg.datadir);
  554.   statusfile=open(s,O_RDWR | O_BINARY);
  555.   write(statusfile, (void *)(&status), sizeof(statusrec));
  556.   close(statusfile);
  557.   statusfile=-1;
  558. }
  559.  
  560. double ratio()
  561. {
  562.   double r;
  563.  
  564.   if (thisuser.dk==0)
  565.     return(99.999);
  566.   r=((float) thisuser.uk) / ((float) thisuser.dk);
  567.   if (r>99.998)
  568.     r=99.998;
  569.   return(r);
  570. }
  571.  
  572. double post_ratio()
  573. {
  574.   double r;
  575.  
  576.   if (thisuser.logons==0)
  577.     return(99.999);
  578.   r=((float) thisuser.msgpost) / ((float) thisuser.logons);
  579.   if (r>99.998)
  580.     r=99.998;
  581.   return(r);
  582. }
  583.  
  584. char *nam(userrec *u1, unsigned int un)
  585. {
  586.   static char o[81];
  587.   int i,f,p;
  588.   userrec u;
  589.  
  590.   u=*u1;
  591.   f=1;
  592.   for (p=0; p<strlen(u.name); p++) {
  593.     if (f) {
  594.       if ((u.name[p]>='A') && (u.name[p]<='Z'))
  595.     f=0;
  596.       o[p]=u.name[p];
  597.     } else {
  598.       if ((u.name[p]>='A') && (u.name[p]<='Z'))
  599.         o[p]=u.name[p]-'A'+'a';
  600.       else {
  601.         if ((u.name[p]>=' ') && (u.name[p]<='/'))
  602.           f=1;
  603.         o[p]=u.name[p];
  604.       }
  605.     }
  606.   }
  607.   o[p++]=32;
  608.   o[p++]='#';
  609.   itoa(un,&o[p],10);
  610.   return(o);
  611. }
  612.  
  613. char *nam1(userrec *u1, unsigned int un, unsigned int sy)
  614. {
  615.   static char o[81];
  616.   char s[10];
  617.  
  618.   strcpy(o,nam(u1,un));
  619.   if (sy) {
  620.     sprintf(s," @%u",sy);
  621.     strcat(o,s);
  622.   }
  623.   return(o);
  624. }
  625.  
  626. double nsl()
  627. {
  628.   double tlt,tlc,tot,tpl,tpd,dd,rtn;
  629.   slrec xx;
  630.  
  631.   dd=timer();
  632.   if (useron) {
  633.     if (timeon>(dd+60.0))
  634.       timeon -= 24.0*3600.0;
  635.     tot=(dd-timeon);
  636.     xx=syscfg.sl[actsl];
  637.     tpl=((double) xx.time_per_logon) * 60.0;
  638.     tpd=((double) xx.time_per_day) * 60.0;
  639.     tlc = tpl - tot + (thisuser.extratime) + extratimecall;
  640.     tlt = tpd - tot - ((double) thisuser.timeontoday) + (thisuser.extratime);
  641.  
  642.     tlt=(((tlc)<(tlt)) ? (tlc) : (tlt));
  643.     if (tlt<0.0)
  644.       tlt=0.0;
  645.     if (tlt>32767.0)
  646.       tlt=32767.0;
  647.     rtn=tlt;
  648.   } else {
  649.     rtn=1.00;
  650.   }
  651.   if (syscfg.executetime) {
  652.     tlt=time_event-dd;
  653.     if (tlt<0.0)
  654.       tlt += 24.0*3600.0;
  655.     if (rtn>tlt)
  656.       rtn=tlt;
  657.     check_event();
  658.     if (do_event)
  659.       rtn=0.0;
  660.   }
  661.   if (rtn<0.0)
  662.     rtn=0.0;
  663.   if (rtn>32767.0)
  664.     rtn=32767.0;
  665.   return(rtn);
  666. }
  667.  
  668. char *date()
  669. {
  670.   static char ds[9];
  671.   struct date today;
  672.  
  673.   getdate(&today);
  674.   sprintf(ds,"%02d/%02d/%02d",today.da_mon,today.da_day,today.da_year-1900);
  675.   return(ds);
  676. }
  677.  
  678. char *times()
  679. {
  680.   static char ti[9];
  681.   int h,m,s;
  682.   double t;
  683.  
  684.   t=timer();
  685.   h=(int) (t/3600.0);
  686.   t-=((double) (h)) * 3600.0;
  687.   m=(int) (t/60.0);
  688.   t-=((double) (m)) * 60.0;
  689.   s=(int) (t);
  690.   sprintf(ti,"%02d:%02d:%02d",h,m,s);
  691.   return(ti);
  692. }
  693.  
  694.  
  695. unsigned int finduser(char *s)
  696. {
  697.   int un;
  698.   smalrec *sr;
  699.   userrec u;
  700.   char *ss;
  701.  
  702.   if (strcmp(s,"NEW")==0)
  703.     return(-1);
  704.   if (strcmp(s,"!-@NETWORK@-!")==0)
  705.     return(-2);
  706.   if (strcmp(s,"!-@REMOTE@-!")==0)
  707.     return(-3);
  708.   if (strncmp(s,"!=@",3)==0) {
  709.     ss=s+strlen(s)-3;
  710.     if (strcmp(ss,"@=!")==0) {
  711.       strcpy(s,s+3);
  712.       s[strlen(s)-3]=0;
  713.       return(-4);
  714.     }
  715.   }
  716.   if ((un=atoi(s))>0) {
  717.     if (un>number_userrecs())
  718.       return(0);
  719.     read_user(un,&u);
  720.     if (u.inact & inact_deleted)
  721.       return(0);
  722.     return(un);
  723.   }
  724.   sr=(smalrec *) bsearch((void *)s,
  725.              (void *)smallist,
  726.              (size_t)status.users,
  727.              (size_t)sizeof(smalrec),
  728.              (int _Cdecl (*) (const void *, const void *))strcmp);
  729.   if (sr==0L)
  730.     return(0);
  731.   else {
  732.     read_user(sr->number,&u);
  733.     if (u.inact & inact_deleted)
  734.       return(0);
  735.     else
  736.       return(sr -> number);
  737.   }
  738. }
  739.  
  740. void changedsl()
  741. {
  742.   int i,i1,i2,i3,i4,ok,dp,ddp;
  743.   subboardrec s;
  744.   directoryrec d;
  745.   usersubrec s1;
  746.  
  747.   topscreen();
  748.   dp=0;
  749.   dc[dp++]='/';
  750.   ddp=0;
  751.   dcd[ddp++]='/';
  752.   for (i=0; i<3; i++) {
  753.     s1.keys[i]=0;
  754.   }
  755.   s1.subnum=-1;
  756.   for (i=0; i<MAX_SUBS; i++)
  757.     usub[i]=s1;
  758.   for (i=0; i<MAX_DIRS; i++)
  759.     udir[i]=s1;
  760.   i1=1;
  761.   i2=0;
  762.   i3=0;
  763.   for (i=0; i<num_subs; i++) {
  764.     ok=1;
  765.     s=subboards[i];
  766.     if (actsl<s.readsl)
  767.       ok=0;
  768.     if (thisuser.age<s.age)
  769.       ok=0;
  770.     if ((s.ar!=0) && (((thisuser.ar) & (s.ar))==0))
  771.       ok=0;
  772.     if ((s.anony & anony_ansi_only) && (!okansi()))
  773.       ok=0;
  774.     if (ok) {
  775.       s1.subnum=i;
  776.       if (s.key!=0) {
  777.         s1.keys[0]=s.key;
  778.         s1.keys[1]=0;
  779.         s1.subnum=i;
  780.         usub[i3++]=s1;
  781.       } else {
  782.         if ((i1 % 10)==0)
  783.           dc[dp++]=('0'+(i1/10));
  784.         itoa(i1++,s1.keys,10);
  785.         s1.subnum=i;
  786.         for (i4=i3; i4>i2; i4--)
  787.           usub[i4]=usub[i4-1];
  788.         i3++;
  789.         usub[i2++]=s1;
  790.       }
  791.     }
  792.   }
  793.   i1=1;
  794.   i2=0;
  795.   for (i=0; i<num_dirs; i++) {
  796.     ok=1;
  797.     d=directories[i];
  798.     if (thisuser.dsl<d.dsl)
  799.       ok=0;
  800.     if (thisuser.age<d.age)
  801.       ok=0;
  802.     if (d.dar)
  803.       if ((d.dar & thisuser.dar)==0)
  804.         ok=0;
  805.     if (ok) {
  806.       s1.subnum=i;
  807.       if (i==0)
  808.         strcpy(s1.keys,"0");
  809.       else {
  810.         if ((i1 % 10)==0)
  811.           dcd[ddp++]=('0'+(i1/10));
  812.         itoa(i1++,s1.keys,10);
  813.       }
  814.       udir[i2++]=s1;
  815.     }
  816.   }
  817.   dcd[ddp]=0;
  818.   dc[dp]=0;
  819. }
  820.  
  821. void isr(int un, char *name)
  822. {
  823.   int cp,i;
  824.   char s[81];
  825.   smalrec sr;
  826.  
  827.   cp=0;
  828.   while ((cp<status.users) && (strcmp(name,(smallist[cp].name))>0))
  829.     ++cp;
  830.   memmove(&(smallist[cp+1]),&(smallist[cp]),sizeof(smalrec)*(status.users-cp));
  831.   strcpy(sr.name,name);
  832.   sr.number=un;
  833.   smallist[cp]=sr;
  834.   sprintf(s,"%sNAMES.LST",syscfg.datadir);
  835.   i=open(s,O_RDWR | O_BINARY | O_TRUNC);
  836.   if (i<0) {
  837.     printf("%s NOT FOUND.\n",s);
  838.     end_bbs(noklevel);
  839.   }
  840.   ++status.users;
  841.   save_status();
  842.   write(i,(void *) (smallist), (sizeof(smalrec) * status.users));
  843.   close(i);
  844. }
  845.  
  846. void dsr(char *name)
  847. {
  848.   int cp,i;
  849.   char s[81];
  850.   smalrec sr;
  851.  
  852.   cp=0;
  853.   while ((cp<status.users) && (strcmp(name,(smallist[cp].name))!=0))
  854.     ++cp;
  855.   if (strcmp(name,(smallist[cp].name))) {
  856.     sprintf(s,"%s NOT ABLE TO BE DELETED#*#*#*#*#*#*#*#",name);
  857.     sl1(0,s);
  858.     sl1(0,"#*#*#*# Run //resetf to fix it");
  859.     return;
  860.   }
  861.   memmove(&(smallist[cp]),&(smallist[cp+1]),sizeof(smalrec)*(status.users-cp));
  862.   sprintf(s,"%sNAMES.LST",syscfg.datadir);
  863.   i=open(s,O_RDWR | O_BINARY | O_TRUNC | O_CREAT, S_IREAD | S_IWRITE);
  864.   if (i<0) {
  865.     printf("%s COULDN'T BE CREATED.\n",s);
  866.     end_bbs(noklevel);
  867.   }
  868.   --status.users;
  869.   save_status();
  870.   write(i,(void *) (smallist), (sizeof(smalrec) * status.users));
  871.   close(i);
  872. }
  873.  
  874. void wait(double d)
  875. {
  876.   long l1;
  877.  
  878.   l1=((long) (18.2*d));
  879.   l1 += timer1();
  880.  
  881.   enable();
  882.   while (timer1()<l1)
  883.     ;
  884. }
  885.  
  886. void wait1(long l)
  887. {
  888.   long l1;
  889.  
  890.   l1 = timer1()+l;
  891.  
  892.   enable();
  893.   while (timer1()<l1)
  894.     ;
  895. }
  896.  
  897. double freek1(char *s)
  898. {
  899.   int d;
  900.  
  901.   d=cdir[0];
  902.   if (s[1]==':')
  903.     d=s[0];
  904.   d=d-'A'+1;
  905.   return(freek(d));
  906. }
  907.  
  908. int exist(char *s)
  909. {
  910.   int f;
  911.  
  912.   f=open(s,O_RDONLY | O_BINARY);
  913.   close(f);
  914.   if (f>0)
  915.     return(1);
  916.   else
  917.     return(0);
  918. }
  919.  
  920. void add_ass(int i, char *ss)
  921. {
  922.   char s[81],s1[10];
  923.  
  924.   strcpy(s,"*** ");
  925.   sysoplog(s);
  926.   strcat(s,ss);
  927.   sysoplog(s);
  928.   itoa(i,s1,10);
  929.   strcpy(s,"*** ASS-PTS: ");
  930.   strcat(s,s1);
  931.   sysoplog(s);
  932.   thisuser.ass_pts += i;
  933. }
  934.