home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / UTILITY / ES102.ARJ / GFE.C < prev    next >
Text File  |  1990-07-16  |  12KB  |  507 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <io.h>
  4. #include <fcntl.h>
  5. #include <dos.h>
  6. #include <stdlib.h>
  7. #include <sys\stat.h>
  8. #include <dir.h>
  9. #include "vardec.h"
  10. #define DO_PW_CHECK
  11. /* delete or comment out above line if sysop password check is not desired */
  12.  
  13. int    usernum,             /* user number for the user */
  14.        age,                 /* age of the user */
  15.        screenchars,         /* chars/line user has specified */
  16.        screenlines,         /* lines/screen user has specified */
  17.        sl,                  /* sec lev for user (0-255) */
  18.        so,                  /* non-zero if user is sysop (sl=255) */
  19.        cs,                  /* non-zero if user is co-sysop */
  20.        okansi,              /* non-zero if user can support ANSI */
  21.        incom,               /* non-zero if user is calling remotely */
  22.        comport;             /* com port user is on */
  23. char   name[81],            /* name/alias of user */
  24.        realname[81],        /* real name of user */
  25.        callsign[10],        /* amateur radio callsign of user */
  26.        sex,                 /* sex of user, M or F */
  27.        laston[81],          /* date user was last on */
  28.        gfiles[81],          /* directory for text files, ends in \ */
  29.        data[81],            /* directory for non-text files, ends in \ */
  30.        sysoplog[81],        /* full path & filename for sysop log */
  31.        curspeed[81];        /* speed user is on at, "KB" if local */
  32. double gold,                /* gold user has */
  33.        timeallowed,         /* number of seconds before user logged off */
  34.        version;             /* version of WWIV running under */
  35.  
  36. configrec syscfg;
  37. int num_sec;
  38. gfiledirrec gfilesec[32];
  39. char cdir[81];
  40.  
  41. void far interrupt (*inli)(char *, char *, int, int);
  42. void far interrupt (*checka)(int *, int *);
  43. void far interrupt (*pla)(char *, int *);
  44. void far interrupt (*outchr)(char);
  45. void far interrupt (*outstr)(char *);
  46. void far interrupt (*nl)();
  47. void far interrupt (*pl)(char *);
  48. int  far interrupt (*empty)();
  49. char far interrupt (*inkey)();
  50. unsigned char far interrupt (*getkey)();
  51. void far interrupt (*input)(char *, int);
  52. void far interrupt (*inputl)(char *, int);
  53. int  far interrupt (*yn)();
  54. int  far interrupt (*ny)();
  55. void far interrupt (*ansic)(int);
  56. char far interrupt (*onek)(char *);
  57. void far interrupt (*prt)(int, char *);
  58. void far interrupt (*mpl)(int);
  59. void far **funcs;
  60.  
  61. int read_in_data(char *fn)
  62. {
  63.   char buf[1024];
  64.   char *ptr[30],*ss,s[81];
  65.   int i,f,len,i1;
  66.   float fl;
  67.  
  68.   f=open(fn,O_RDONLY | O_BINARY);
  69.   if (f<0) {
  70.     return(-1);
  71.   }
  72.   i1=1;
  73.   ptr[0]=buf;
  74.   len=read(f,(void *)buf,1024);
  75.   close(f);
  76.   for (i=0; i<len; i++)
  77.     if (buf[i]==13) {
  78.       buf[i]=0;
  79.       ptr[i1++]=&buf[i+2];
  80.     }
  81.   while (*ptr[6]==32)
  82.     ++(ptr[6]);
  83.   while (*ptr[15]==32)
  84.     ++(ptr[15]);
  85.   usernum=atoi(ptr[0]);
  86.   strcpy(name,ptr[1]);
  87.   strcpy(realname,ptr[2]);
  88.   strcpy(callsign,ptr[3]);
  89.   age=atoi(ptr[4]);
  90.   sex=*ptr[5];
  91.   sscanf(ptr[6],"%f",&fl);
  92.   gold=(double)fl;
  93.   strcpy(laston,ptr[7]);
  94.   screenchars=atoi(ptr[8]);
  95.   screenlines=atoi(ptr[9]);
  96.   sl=atoi(ptr[10]);
  97.   so=atoi(ptr[11]);
  98.   cs=atoi(ptr[12]);
  99.   okansi=atoi(ptr[13]);
  100.   incom=atoi(ptr[14]);
  101.   sscanf(ptr[15],"%f",&fl);
  102.   timeallowed=(double)fl;
  103.   strcpy(gfiles,ptr[16]);
  104.   strcpy(data,ptr[17]);
  105.   strcpy(sysoplog,gfiles);
  106.   strcat(sysoplog,ptr[18]);
  107.   strcpy(curspeed,ptr[19]);
  108.   comport=atoi(ptr[20]);
  109.  
  110.   version=-1.0;
  111.   ss=getenv("BBS");
  112.   if (strncmp(ss,"WWIV",4)) {
  113.     printf("\nThis program MUST be run under WWIV v4.07 or later.\n");
  114.     exit(0);
  115.   }
  116.   strcpy(s,&(ss[6]));
  117.   i=(s[0]-'0')*100+(s[2]-'0')*10+(s[3]-'0');
  118.   version=((double)i)/100.0;
  119.   if (i<407) {
  120.     printf("\nThis program requires WWIV v4.07 or later.\n");
  121.     exit(0);
  122.   }
  123.   funcs=(void far *)getvect(0x6a);
  124.   inli=funcs[0];
  125.   checka=funcs[1];
  126.   pla=funcs[2];
  127.   outchr=funcs[3];
  128.   outstr=funcs[4];
  129.   nl=funcs[5];
  130.   pl=funcs[8];
  131.   empty=funcs[9];
  132.   inkey=funcs[10];
  133.   getkey=funcs[11];
  134.   input=funcs[12];
  135.   inputl=funcs[13];
  136.   yn=funcs[14];
  137.   ny=funcs[15];
  138.   ansic=funcs[16];
  139.   onek=funcs[17];
  140.   prt=funcs[18];
  141.   mpl=funcs[19];
  142.   return(0);
  143. }
  144.  
  145. int checkpw()
  146. {
  147. #ifdef DO_PW_CHECK
  148.   char s[81];
  149.  
  150.   nl();
  151.   prt(2,"SY: ");
  152.   input(s,20);
  153.   if (strcmp(s,(syscfg.systempw))==0)
  154. #endif
  155.     return(1);
  156. #ifdef DO_PW_CHECK
  157.   else
  158.     return(0);
  159. #endif
  160. }
  161.  
  162. void cd_to(char *s)
  163. {
  164.   char s1[81];
  165.   int i,db;
  166.  
  167.   strcpy(s1,s);
  168.   i=strlen(s1)-1;
  169.   db=(s1[i]=='\\');
  170.   if (i==0)
  171.     db=0;
  172.   if ((i==2) && (s1[1]==':'))
  173.     db=0;
  174.   if (db)
  175.     s1[i]=0;
  176.   chdir(s1);
  177.   if (s[1]==':')
  178.     setdisk(s[0]-'A');
  179. }
  180.  
  181. void pausescr()
  182. {
  183.   int i;
  184.  
  185.   outstr("[PAUSE]");
  186.   getkey();
  187.   for (i = 0; i < 7; i++)
  188.     outstr("\b \b");
  189. }
  190.  
  191. void gfiledata(int n, char *s)
  192. {
  193.   char x,y,k,i;
  194.   gfiledirrec r;
  195.  
  196.   r=gfilesec[n];
  197.   if (r.ar==0)
  198.     x=32;
  199.   else {
  200.     for (i=0; i<16; i++)
  201.       if ((1 << i) & r.ar)
  202.         x='A'+i;
  203.   }
  204.   sprintf(s,"%2d %1c  %-40s  %-8s %-3d %-3d %-3d",
  205.             n,x,r.name,r.filename,r.sl,r.age,r.maxfiles);
  206. }
  207.  
  208. void showsec()
  209. {
  210.   int abort,i;
  211.   char s[180];
  212.  
  213.   outchr(12);
  214.   abort=0;
  215.   pla("NN AR Name                                      FN       SL  AGE MAX",
  216.       &abort);
  217.   pla("-- == ----------------------------------------  ======== --- === ---",
  218.       &abort);
  219.   for (i=0; (i<num_sec) && (!abort); i++) {
  220.     gfiledata(i,s);
  221.     pla(s,&abort);
  222.   }
  223. }
  224.  
  225. int exist_dir(char *s)
  226. {
  227.   int ok;
  228.  
  229.   cd_to(syscfg.gfilesdir);
  230.   if (chdir(s))
  231.     ok=0;
  232.   else
  233.     ok=1;
  234.   cd_to(cdir);
  235.   return(ok);
  236. }
  237.  
  238. void modify_sec(int n)
  239. {
  240.   gfiledirrec r;
  241.   char s[81],s1[81],s2[81],ch,ch2;
  242.   int i,i1,done;
  243.  
  244.   r=gfilesec[n];
  245.   done=0;
  246.   do {
  247.     outchr(12);
  248.     sprintf(s2, "A. Name       : %s",r.name); pl(s2);
  249.     sprintf(s2, "B. Filename   : %s",r.filename); pl(s2);
  250.     itoa(r.sl,s,10);
  251.     sprintf(s2, "C. SL         : %s",s); pl(s2);
  252.     itoa(r.age,s,10);
  253.     sprintf(s2, "D. Min. Age   : %s",s); pl(s2);
  254.     itoa(r.maxfiles,s,10);
  255.     sprintf(s2, "E. Max Files  : %s",s); pl(s2);
  256.     strcpy(s,"None.");
  257.     if (r.ar!=0) {
  258.       for (i=0; i<16; i++)
  259.         if ((1 << i) & r.ar)
  260.           s[0]='A'+i;
  261.       s[1]=0;
  262.     }
  263.     sprintf(s2, "F. AR         : %s",s); pl(s2);
  264.     nl();
  265.     prt(2,"Which (A-F,Q) ? ");
  266.     ch=onek("QABCDEF");
  267.     switch(ch) {
  268.       case 'Q':done=1; break;
  269.       case 'A':
  270.         nl();
  271.         prt(2,"New Name? ");
  272.         inputl(s,40);
  273.         if (s[0])
  274.           strcpy(r.name,s);
  275.         break;
  276.       case 'B':
  277.         nl();
  278.         if (exist_dir(r.filename)) {
  279.           nl();
  280.           pl("There is currently a directory for this g-file section.");
  281.           pl("If you change the filename, the directory will still be there.");
  282.           nl();
  283.         }
  284.         nl();
  285.         prt(2,"New Filename? ");
  286.         input(s,8);
  287.         if ((s[0]!=0) && (strchr(s,'.')==0)) {
  288.           strcpy(r.filename,s);
  289.           if (!exist_dir(r.filename)) {
  290.             nl();
  291.             prt(5,"Create directory for this section? ");
  292.             if (yn()) {
  293.               cd_to(syscfg.gfilesdir);
  294.               i = mkdir(r.filename);
  295.               if (i == -1) {
  296.                 nl();
  297.                 pl("Could not create directory.");
  298.                 nl();
  299.               }
  300.               cd_to(cdir);
  301.             } else {
  302.               nl();
  303.               pl("You will have to create the directory manually, then.");
  304.               nl();
  305.             }
  306.           } else {
  307.             nl();
  308.             pl("A directory already exists under this filename.");
  309.             nl();
  310.           }
  311.           pausescr();
  312.         }
  313.         break;
  314.       case 'C':
  315.         nl();
  316.         prt(2,"New SL? ");
  317.         input(s,3);
  318.         i=atoi(s);
  319.         if ((i>=0) && (i<256) && (s[0]))
  320.           r.sl=i;
  321.         break;
  322.       case 'D':
  323.         nl();
  324.         prt(2,"New Min Age? ");
  325.         input(s,3);
  326.         i=atoi(s);
  327.         if ((i>=0) && (i<128) && (s[0]))
  328.           r.age=i;
  329.         break;
  330.       case 'E':
  331.         nl();
  332.         pl("Max 99 files/section.");
  333.         prt(2,"New Max Files? ");
  334.         input(s,3);
  335.         i=atoi(s);
  336.         if ((i>=0) && (i<99) && (s[0]))
  337.           r.maxfiles=i;
  338.         break;
  339.       case 'F':
  340.         nl();
  341.         prt(2,"New AR (<SPC>=None) ? ");
  342.         ch2=onek("ABCDEFGHIJKLMNOP ");
  343.         if (ch2==32)
  344.           r.ar=0;
  345.         else
  346.           r.ar=1 << (ch2-'A');
  347.         break;
  348.     }
  349.   } while (!done);
  350.   gfilesec[n]=r;
  351. }
  352.  
  353.  
  354. void insert_sec(int n)
  355. {
  356.   gfiledirrec r;
  357.   int i,i1,nu;
  358.  
  359.   for (i=num_sec-1; i>=n; i--)
  360.     gfilesec[i+1]=gfilesec[i];
  361.   strcpy(r.name,"** NEW SECTION **");
  362.   strcpy(r.filename,"NONAME");
  363.   r.sl=10;
  364.   r.age=0;
  365.   r.maxfiles=99;
  366.   r.ar=0;
  367.   gfilesec[n]=r;
  368.   ++num_sec;
  369.   modify_sec(n);
  370. }
  371.  
  372. void delete_sec(int n)
  373. {
  374.   int i,i1,nu;
  375.   char s[81],s1[81];
  376.   int f1;
  377.   struct ffblk ff;
  378.  
  379.   prt(5, "Delete data files? ");
  380.   if (yn()) {
  381.     sprintf(s, "%s%s.GFL", syscfg.datadir, gfilesec[n].filename);
  382.     unlink(s);
  383.   }
  384.   prt(5, "Delete all text files in that section's directory? ");
  385.   if (yn()) {
  386.     sprintf(s, "%s%s\\*.*", syscfg.gfilesdir, gfilesec[n].filename);
  387.     f1=findfirst(s,&ff,0);
  388.     while (f1==0) {
  389.       sprintf(s, "%s%s\\%s", syscfg.gfilesdir, gfilesec[n].filename,
  390.                             ff.ff_name);
  391.       unlink(s);
  392.       sprintf(s1, "Deleting %s...", ff.ff_name);
  393.       pl(s1);
  394.       f1=findnext(&ff);
  395.     }
  396.     prt(5, "Delete G-File section directory? ");
  397.     if (yn()) {
  398.       sprintf(s, "%s%s", syscfg.gfilesdir, gfilesec[n].filename);
  399.       f1=rmdir(s);
  400.     }
  401.   }
  402.  
  403.   for (i=n; i<num_sec; i++)
  404.     gfilesec[i]=gfilesec[i+1];
  405.   --num_sec;
  406. }
  407.  
  408. void gfileedit()
  409. {
  410.   int i,i1,i2,done,f;
  411.   char s[81],s1[81],s2[81],ch;
  412.  
  413.   if (!checkpw())
  414.     return;
  415.   showsec();
  416.   done=0;
  417.   do {
  418.     nl();
  419.     prt(2,"G-files: D:elete, I:nsert, M:odify, Q:uit, ? : ");
  420.     ch=onek("QDIM?");
  421.     switch(ch) {
  422.       case '?':
  423.         showsec();
  424.         break;
  425.       case 'Q':
  426.         done=1;
  427.         break;
  428.       case 'M':
  429.         nl();
  430.         prt(2,"Section number? ");
  431.         input(s,2);
  432.         i=atoi(s);
  433.         if ((s[0]!=0) && (i>=0) && (i<num_sec))
  434.           modify_sec(i);
  435.         break;
  436.       case 'I':
  437.         if (num_sec<32) {
  438.           nl();
  439.           prt(2,"Insert before which section? ");
  440.           input(s,2);
  441.           i=atoi(s);
  442.           if ((s[0]!=0) && (i>=0) && (i<=num_sec))
  443.             insert_sec(i);
  444.         }
  445.         break;
  446.       case 'D':
  447.         nl();
  448.         prt(2,"Delete which section? ");
  449.         input(s,2);
  450.         i=atoi(s);
  451.         if ((s[0]!=0) && (i>=0) && (i<num_sec)) {
  452.           nl();
  453.           strcpy(s1,"Delete ");
  454.           strcat(s1,gfilesec[i].name);
  455.           strcat(s1,"? ");
  456.           prt(5,s1);
  457.           if (yn())
  458.             delete_sec(i);
  459.         }
  460.         break;
  461.     }
  462.   } while (!done);
  463.   strcpy(s,syscfg.datadir);
  464.   strcat(s,"GFILE.DAT");
  465.   f=open(s,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  466.   write(f,(void *)(&gfilesec[0]), num_sec * sizeof(gfiledirrec));
  467.   close(f);
  468. }
  469.  
  470. void main(int argc, char *argv[])
  471. {
  472.   char s[81];
  473.   int i;
  474.  
  475.   if (argc<2)
  476.     strcpy(s,"chain.txt");
  477.   else
  478.     strcpy(s,argv[1]);
  479.   if (read_in_data(s)==-1) {
  480.     printf("\nData file not found: %s\n\n", s);
  481.     abort();
  482.   }
  483.  
  484.   strcpy(s,"CONFIG.DAT");
  485.   i=open(s,O_RDWR | O_BINARY);
  486.   if (i<0) {
  487.     printf("%s NOT FOUND.\n",s);
  488.     exit(1);
  489.   }
  490.   read(i, (void *)(&syscfg), sizeof(configrec));
  491.   close(i);
  492.  
  493.   strcpy(cdir,"X:\\");
  494.   cdir[0]='A'+getdisk();
  495.   getcurdir(0,&(cdir[3]));
  496.  
  497.   sprintf(s, "%sGFILE.DAT", syscfg.datadir);
  498.   i=open(s, O_RDWR | O_BINARY);
  499.   if (i<0)
  500.     num_sec=0;
  501.   else
  502.     num_sec=read(i,(void *)gfilesec,32*sizeof(gfiledirrec))/sizeof(gfiledirrec);
  503.   close(i);
  504.  
  505.   gfileedit();
  506. }
  507.