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

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1991 by Wayne Bell
  5.  
  6. *****************************************************************************/
  7.  
  8. #include "vars.h"
  9. #pragma hdrstop
  10. #include <dir.h>
  11. #define utoa(s,v,r) ultoa((unsigned long)(s),v,r)
  12.  
  13. void gfiledata(int n, char *s)
  14. {
  15.   char x,y,k,i;
  16.   gfiledirrec r;
  17.  
  18.   r=gfilesec[n];
  19.   if (r.ar==0)
  20.     x=32;
  21.   else {
  22.     for (i=0; i<16; i++)
  23.       if ((1 << i) & r.ar)
  24.         x='A'+i;
  25.   }
  26.   sprintf(s,"%2d %1c  %-40s  %-8s %-3d %-3d %-3d",
  27.             n,x,r.name,r.filename,r.sl,r.age,r.maxfiles);
  28. }
  29.  
  30. void showsec()
  31. {
  32.   int abort,i;
  33.   char s[180];
  34.  
  35.   outchr(12);
  36.   abort=0;
  37.   pla("NN AR Name                                      FN       SL  AGE MAX",
  38.       &abort);
  39.   pla("-- == ----------------------------------------  ======== --- === ---",
  40.       &abort);
  41.   for (i=0; (i<num_sec) && (!abort); i++) {
  42.     gfiledata(i,s);
  43.     pla(s,&abort);
  44.   }
  45. }
  46.  
  47. int exist_dir(char *s)
  48. {
  49.   int ok;
  50.  
  51.   cd_to(syscfg.gfilesdir);
  52.   if (chdir(s))
  53.     ok=0;
  54.   else
  55.     ok=1;
  56.   cd_to(cdir);
  57.   return(ok);
  58. }
  59.  
  60. void modify_sec(int n)
  61. {
  62.   gfiledirrec r;
  63.   char s[81],s1[81],ch,ch2;
  64.   int i,i1,done;
  65.  
  66.   r=gfilesec[n];
  67.   done=0;
  68.   do {
  69.     outchr(12);
  70.     npr("A. Name       : %s\r\n",r.name);
  71.     npr("B. Filename   : %s\r\n",r.filename);
  72.     npr("C. SL         : %d\r\n",r.sl);
  73.     npr("D. Min. Age   : %d\r\n",r.age);
  74.     npr("E. Max Files  : %d\r\n",r.maxfiles);
  75.     strcpy(s,"None.");
  76.     if (r.ar!=0) {
  77.       for (i=0; i<16; i++)
  78.         if ((1 << i) & r.ar)
  79.           s[0]='A'+i;
  80.       s[1]=0;
  81.     }
  82.     npr("F. AR         : %s\r\n",s);
  83.     nl();
  84.     prt(2,"Which (A-F,Q) ? ");
  85.     ch=onek("QABCDEF");
  86.     switch(ch) {
  87.       case 'Q':done=1; break;
  88.       case 'A':
  89.         nl();
  90.         prt(2,"New name? ");
  91.         inputl(s,40);
  92.         if (s[0])
  93.           strcpy(r.name,s);
  94.         break;
  95.       case 'B':
  96.     nl();
  97.     if (exist_dir(r.filename)) {
  98.           nl();
  99.       pl("There is currently a directory for this g-file section.");
  100.       pl("If you change the filename, the directory will still be there.");
  101.       nl();
  102.     }
  103.         nl();
  104.         prt(2,"New filename? ");
  105.         input(s,8);
  106.         if ((s[0]!=0) && (strchr(s,'.')==0)) {
  107.           strcpy(r.filename,s);
  108.       if (!exist_dir(r.filename)) {
  109.             nl();
  110.         prt(5,"Create directory for this section? ");
  111.         if (yn()) {
  112.           cd_to(syscfg.gfilesdir);
  113.           mkdir(r.filename);
  114.           cd_to(cdir);
  115.         } else {
  116.           nl();
  117.           pl("You will have to create the directory manually, then.");
  118.           nl();
  119.         }
  120.       } else {
  121.         nl();
  122.         pl("A directory already exists under this filename.");
  123.         nl();
  124.       }
  125.       pausescr();
  126.     }
  127.         break;
  128.       case 'C':
  129.         nl();
  130.         prt(2,"New SL? ");
  131.         input(s,3);
  132.         i=atoi(s);
  133.         if ((i>=0) && (i<256) && (s[0]))
  134.           r.sl=i;
  135.         break;
  136.       case 'D':
  137.         nl();
  138.         prt(2,"New Min Age? ");
  139.         input(s,3);
  140.         i=atoi(s);
  141.         if ((i>=0) && (i<128) && (s[0]))
  142.           r.age=i;
  143.         break;
  144.       case 'E':
  145.         nl();
  146.         pl("Max 99 files/section.");
  147.         prt(2,"New max files? ");
  148.         input(s,3);
  149.         i=atoi(s);
  150.         if ((i>=0) && (i<99) && (s[0]))
  151.           r.maxfiles=i;
  152.         break;
  153.       case 'F':
  154.         nl();
  155.         prt(2,"New AR (<SPC>=None) ? ");
  156.         ch2=onek("ABCDEFGHIJKLMNOP ");
  157.         if (ch2==32)
  158.           r.ar=0;
  159.         else
  160.           r.ar=1 << (ch2-'A');
  161.         break;
  162.     }
  163.   } while ((!done) && (!hangup));
  164.   gfilesec[n]=r;
  165. }
  166.  
  167. void insert_sec(int n)
  168. {
  169.   gfiledirrec r;
  170.   int i,i1,nu;
  171.  
  172.   for (i=num_sec-1; i>=n; i--)
  173.     gfilesec[i+1]=gfilesec[i];
  174.   strcpy(r.name,"** NEW SECTION **");
  175.   strcpy(r.filename,"NONAME");
  176.   r.sl=10;
  177.   r.age=0;
  178.   r.maxfiles=99;
  179.   r.ar=0;
  180.   gfilesec[n]=r;
  181.   ++num_sec;
  182.   modify_sec(n);
  183. }
  184.  
  185. void delete_sec(int n)
  186. {
  187.   int i,i1,nu;
  188.  
  189.   for (i=n; i<num_sec; i++)
  190.     gfilesec[i]=gfilesec[i+1];
  191.   --num_sec;
  192. }
  193.  
  194. void gfileedit()
  195. {
  196.   int i,i1,i2,done,f;
  197.   char s[81],s1[81],s2[81],ch;
  198.  
  199.   showsec();
  200.   done=0;
  201.   do {
  202.     nl();
  203.     prt(2,"G-files: D:elete, I:nsert, M:odify, Q:uit, ? : ");
  204.     ch=onek("QDIM?");
  205.     switch(ch) {
  206.       case '?':
  207.         showsec();
  208.         break;
  209.       case 'Q':
  210.         done=1;
  211.         break;
  212.       case 'M':
  213.         nl();
  214.         prt(2,"Section number? ");
  215.         input(s,2);
  216.         i=atoi(s);
  217.         if ((s[0]!=0) && (i>=0) && (i<num_sec))
  218.           modify_sec(i);
  219.         break;
  220.       case 'I':
  221.         if (num_sec<32) {
  222.           nl();
  223.           prt(2,"Insert before which section? ");
  224.           input(s,2);
  225.           i=atoi(s);
  226.           if ((s[0]!=0) && (i>=0) && (i<=num_sec))
  227.             insert_sec(i);
  228.         }
  229.         break;
  230.       case 'D':
  231.         nl();
  232.         prt(2,"Delete which section? ");
  233.         input(s,2);
  234.         i=atoi(s);
  235.         if ((s[0]!=0) && (i>=0) && (i<num_sec)) {
  236.           nl();
  237.           ansic(5);
  238.           npr("Delete %s? ",gfilesec[i].name);
  239.           if (yn())
  240.             delete_sec(i);
  241.         }
  242.         break;
  243.     }
  244.   } while ((!done) && (!hangup));
  245.   sprintf(s,"%sGFILE.DAT",syscfg.datadir);
  246.   f=open(s,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  247.   write(f,(void *)(&gfilesec[0]), num_sec * sizeof(gfiledirrec));
  248.   close(f);
  249. }
  250.  
  251. int fill_sec(int sn)
  252. {
  253.   gfilerec *g,g1;
  254.   int f1,nf,ok,i,i1,i2,chd;
  255.   char s[81],s1[81];
  256.   struct ffblk ff;
  257.  
  258.   g=read_sec(sn,&nf);
  259.   sprintf(s1,"%s%s\\*.*",syscfg.gfilesdir,gfilesec[sn].filename);
  260.   f1=findfirst(s1,&ff,0);
  261.   ok=1;
  262.   chd=0;
  263.   while ((f1==0) && (!hangup) && (nf<gfilesec[sn].maxfiles) && (ok)) {
  264.     strcpy(s,(ff.ff_name));
  265.     align(s);
  266.     i=1;
  267.     for (i1=0; i1<nf; i1++)
  268.       if (compare(s,g[i1].filename))
  269.     i=0;
  270.     if (i) {
  271.       ansic(2);
  272.       npr("%s : ",s);
  273.       inputl(s1,60);
  274.       if (s1[0]) {
  275.     chd=1;
  276.     i=0;
  277.     while ((strcmp(s1,g[i].description)>0) && (i<nf))
  278.       ++i;
  279.     for (i1=nf; i1>i; i1--)
  280.       g[i1]=g[i1-1];
  281.     ++nf;
  282.     strcpy(g1.filename,s);
  283.     strcpy(g1.description,s1);
  284.     time(&(g1.daten));
  285.     g[i]=g1;
  286.       } else
  287.     ok=0;
  288.     }
  289.     f1=findnext(&ff);
  290.   }
  291.   if (!ok)
  292.     pl("Aborted.");
  293.   if (nf>=gfilesec[sn].maxfiles)
  294.     pl("Section full.");
  295.   if (chd) {
  296.     sprintf(s,"%s%s.GFL",syscfg.datadir,gfilesec[sn].filename);
  297.     i=open(s,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  298.     write(i,(void *)g,nf*sizeof(gfilerec));
  299.     close(i);
  300.   }
  301.   farfree(g);
  302.   return(!ok);
  303. }
  304.