home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / WWIV2.ZIP / GFLEDIT.C < prev    next >
C/C++ Source or Header  |  1992-12-03  |  7KB  |  331 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.  
  23.  
  24.  
  25. #define utoa(s,v,r) ultoa((unsigned long)(s),v,r)
  26.  
  27.  
  28. void gfiledata(int n, char *s)
  29. {
  30.   char x,y,k,i;
  31.   gfiledirrec r;
  32.  
  33.   r=gfilesec[n];
  34.   if (r.ar==0)
  35.     x=32;
  36.   else {
  37.     for (i=0; i<16; i++)
  38.       if ((1 << i) & r.ar)
  39.         x='A'+i;
  40.   }
  41.   sprintf(s,"%2d %1c  %-40s  %-8s %-3d %-3d %-3d",
  42.             n,x,r.name,r.filename,r.sl,r.age,r.maxfiles);
  43. }
  44.  
  45. void showsec(void)
  46. {
  47.   int abort,i;
  48.   char s[180];
  49.  
  50.   outchr(12);
  51.   abort=0;
  52.   pla(get_string(60),
  53.       &abort);
  54.   pla(get_string(61),
  55.       &abort);
  56.   for (i=0; (i<num_sec) && (!abort); i++) {
  57.     gfiledata(i,s);
  58.     pla(s,&abort);
  59.   }
  60. }
  61.  
  62.  
  63. int exist_dir(char *s)
  64. {
  65.   int ok;
  66.  
  67.   cd_to(syscfg.gfilesdir);
  68.   if (chdir(s))
  69.     ok=0;
  70.   else
  71.     ok=1;
  72.   cd_to(cdir);
  73.   return(ok);
  74. }
  75.  
  76.  
  77. void modify_sec(int n)
  78. {
  79.   gfiledirrec r;
  80.   char s[81],s1[81],ch,ch2;
  81.   int i,i1,done;
  82.  
  83.   r=gfilesec[n];
  84.   done=0;
  85.   do {
  86.     outchr(12);
  87.     outstr(get_string(62)); pl(r.name);
  88.     outstr(get_string(63)); pl(r.filename);
  89.     outstr(get_string(64)); pln(r.sl);
  90.     outstr(get_string(65)); pln(r.age);
  91.     outstr(get_string(66)); pln(r.maxfiles);
  92.     strcpy(s,get_string(5));
  93.     if (r.ar!=0) {
  94.       for (i=0; i<16; i++)
  95.         if ((1 << i) & r.ar)
  96.           s[0]='A'+i;
  97.       s[1]=0;
  98.     }
  99.     outstr(get_string(67)); pl(s);
  100.     nl();
  101.     prt(2,get_string(68));
  102.     ch=onek("QABCDEF");
  103.     switch(ch) {
  104.       case 'Q':done=1; break;
  105.       case 'A':
  106.         nl();
  107.         prt(2,get_string(69));
  108.         inputl(s,40);
  109.         if (s[0])
  110.           strcpy(r.name,s);
  111.         break;
  112.       case 'B':
  113.     nl();
  114.     if (exist_dir(r.filename)) {
  115.           nl();
  116.       pl(get_string(70));
  117.       pl(get_string(71));
  118.       nl();
  119.     }
  120.         nl();
  121.         prt(2,get_string(72));
  122.         input(s,8);
  123.         if ((s[0]!=0) && (strchr(s,'.')==0)) {
  124.           strcpy(r.filename,s);
  125.       if (!exist_dir(r.filename)) {
  126.             nl();
  127.         prt(5,get_string(73));
  128.         if (yn()) {
  129.           cd_to(syscfg.gfilesdir);
  130.           mkdir(r.filename);
  131.           cd_to(cdir);
  132.         } else {
  133.           nl();
  134.           pl(get_string(74));
  135.           nl();
  136.         }
  137.       } else {
  138.         nl();
  139.         pl(get_string(75));
  140.         nl();
  141.       }
  142.       pausescr();
  143.     }
  144.         break;
  145.       case 'C':
  146.         nl();
  147.         prt(2,get_string(76));
  148.         input(s,3);
  149.         i=atoi(s);
  150.         if ((i>=0) && (i<256) && (s[0]))
  151.           r.sl=i;
  152.         break;
  153.       case 'D':
  154.         nl();
  155.         prt(2,get_string(77));
  156.         input(s,3);
  157.         i=atoi(s);
  158.         if ((i>=0) && (i<128) && (s[0]))
  159.           r.age=i;
  160.         break;
  161.       case 'E':
  162.         nl();
  163.         pl(get_string(78));
  164.         prt(2,get_string(79));
  165.         input(s,3);
  166.         i=atoi(s);
  167.         if ((i>=0) && (i<99) && (s[0]))
  168.           r.maxfiles=i;
  169.         break;
  170.       case 'F':
  171.         nl();
  172.         prt(2,get_string(80));
  173.         ch2=onek("ABCDEFGHIJKLMNOP ");
  174.         if (ch2==32)
  175.           r.ar=0;
  176.         else
  177.           r.ar=1 << (ch2-'A');
  178.         break;
  179.     }
  180.   } while ((!done) && (!hangup));
  181.   gfilesec[n]=r;
  182. }
  183.  
  184.  
  185. void insert_sec(int n)
  186. {
  187.   gfiledirrec r;
  188.   int i,i1,nu;
  189.  
  190.   for (i=num_sec-1; i>=n; i--)
  191.     gfilesec[i+1]=gfilesec[i];
  192.   strcpy(r.name,get_string(81));
  193.   strcpy(r.filename,get_string(82));
  194.   r.sl=10;
  195.   r.age=0;
  196.   r.maxfiles=99;
  197.   r.ar=0;
  198.   gfilesec[n]=r;
  199.   ++num_sec;
  200.   modify_sec(n);
  201. }
  202.  
  203.  
  204. void delete_sec(int n)
  205. {
  206.   int i,i1,nu;
  207.  
  208.   for (i=n; i<num_sec; i++)
  209.     gfilesec[i]=gfilesec[i+1];
  210.   --num_sec;
  211. }
  212.  
  213.  
  214. void gfileedit(void)
  215. {
  216.   int i,i1,i2,done,f;
  217.   char s[81],s1[81],s2[81],ch;
  218.  
  219.   if (!checkpw())
  220.     return;
  221.   showsec();
  222.   done=0;
  223.   do {
  224.     nl();
  225.     prt(2,get_string(83));
  226.     ch=onek("QDIM?");
  227.     switch(ch) {
  228.       case '?':
  229.         showsec();
  230.         break;
  231.       case 'Q':
  232.         done=1;
  233.         break;
  234.       case 'M':
  235.         nl();
  236.         prt(2,get_string(84));
  237.         input(s,2);
  238.         i=atoi(s);
  239.         if ((s[0]!=0) && (i>=0) && (i<num_sec))
  240.           modify_sec(i);
  241.         break;
  242.       case 'I':
  243.         if (num_sec<32) {
  244.           nl();
  245.           prt(2,get_string(85));
  246.           input(s,2);
  247.           i=atoi(s);
  248.           if ((s[0]!=0) && (i>=0) && (i<=num_sec))
  249.             insert_sec(i);
  250.         }
  251.         break;
  252.       case 'D':
  253.         nl();
  254.         prt(2,get_string(86));
  255.         input(s,2);
  256.         i=atoi(s);
  257.         if ((s[0]!=0) && (i>=0) && (i<num_sec)) {
  258.           nl();
  259.           ansic(5);
  260.           outstr(get_string(87));
  261.           outstr(gfilesec[i].name);
  262.           outstr("? ");
  263.           if (yn())
  264.             delete_sec(i);
  265.         }
  266.         break;
  267.     }
  268.   } while ((!done) && (!hangup));
  269.   sprintf(s,"%sGFILE.DAT",syscfg.datadir);
  270.   f=open(s,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  271.   write(f,(void *)(&gfilesec[0]), num_sec * sizeof(gfiledirrec));
  272.   close(f);
  273. }
  274.  
  275.  
  276. int fill_sec(int sn)
  277. {
  278.   gfilerec *g,g1;
  279.   int f1,nf,ok,i,i1,i2,chd;
  280.   char s[81],s1[81];
  281.   struct ffblk ff;
  282.  
  283.   g=read_sec(sn,&nf);
  284.   sprintf(s1,"%s%s\\*.*",syscfg.gfilesdir,gfilesec[sn].filename);
  285.   f1=findfirst(s1,&ff,0);
  286.   ok=1;
  287.   chd=0;
  288.   while ((f1==0) && (!hangup) && (nf<gfilesec[sn].maxfiles) && (ok)) {
  289.     strcpy(s,(ff.ff_name));
  290.     align(s);
  291.     i=1;
  292.     for (i1=0; i1<nf; i1++)
  293.       if (compare(s,g[i1].filename))
  294.     i=0;
  295.     if (i) {
  296.       ansic(2);
  297.       npr("%s : ",s);
  298.       inputl(s1,60);
  299.       if (s1[0]) {
  300.     chd=1;
  301.     i=0;
  302.     while ((strcmp(s1,g[i].description)>0) && (i<nf))
  303.       ++i;
  304.     for (i1=nf; i1>i; i1--)
  305.       g[i1]=g[i1-1];
  306.     ++nf;
  307.     strcpy(g1.filename,s);
  308.     strcpy(g1.description,s1);
  309.     time(&(g1.daten));
  310.     g[i]=g1;
  311.       } else
  312.     ok=0;
  313.     }
  314.     f1=findnext(&ff);
  315.   }
  316.   if (!ok)
  317.     pl(get_string(14));
  318.   if (nf>=gfilesec[sn].maxfiles)
  319.     pl(get_string(88));
  320.   if (chd) {
  321.     sprintf(s,"%s%s.GFL",syscfg.datadir,gfilesec[sn].filename);
  322.     i=open(s,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  323.     write(i,(void *)g,nf*sizeof(gfilerec));
  324.     close(i);
  325.   }
  326.   farfree(g);
  327.   return(!ok);
  328. }
  329.  
  330.  
  331.