home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / WWIV2.ZIP / GFILES.C < prev    next >
C/C++ Source or Header  |  1992-12-03  |  5KB  |  253 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.  
  22.  
  23. char *get_file(char *fn, long *len)
  24. {
  25.   int i;
  26.   char *s;
  27.  
  28.   i=open(fn,O_RDWR | O_BINARY);
  29.   if (i<0) {
  30.     *len=0L;
  31.     return(NULL);
  32.   }
  33.   if ((s=malloca(filelength(i)+50))==NULL) {
  34.     *len=0L;
  35.     close(i);
  36.     return(NULL);
  37.   }
  38.   *len=(long) read(i,(void *)s, filelength(i));
  39.   close(i);
  40.   return(s);
  41. }
  42.  
  43.  
  44. gfilerec *read_sec(int sn, int *nf)
  45. {
  46.   gfilerec *g;
  47.   int f,i;
  48.   char s[81];
  49.  
  50.   i=sizeof(gfilerec)*(gfilesec[sn].maxfiles);
  51.   if ((g=malloca((long) i))==NULL) {
  52.     *nf=0;
  53.     return(NULL);
  54.   }
  55.   sprintf(s,"%s%s.GFL",syscfg.datadir,gfilesec[sn].filename);
  56.   f=open(s,O_RDWR | O_BINARY);
  57.   if (f<0)
  58.     *nf=0;
  59.   else
  60.     *nf=read(f,(void *)g,i)/sizeof(gfilerec);
  61.   close(f);
  62.   return(g);
  63. }
  64.  
  65.  
  66. void list_sec(int *map, int nmap)
  67. {
  68.   int i,abort;
  69.   char s[81];
  70.  
  71.   abort=0;
  72.   pla("",&abort);
  73.   pla("",&abort);
  74.   pla(get_string(48),&abort);
  75.   pla("",&abort);
  76.   for (i=0; (i<nmap) && (!abort) && (!hangup); i++) {
  77.     sprintf(s,"%2d. %s",i+1, gfilesec[map[i]].name);
  78.     pla(s,&abort);
  79.   }
  80.   nl();
  81. }
  82.  
  83.  
  84. void list_gfiles(gfilerec *g, int nf)
  85. {
  86.   int i,abort;
  87.   char s[81];
  88.  
  89.   abort=0;
  90.   pla("",&abort);
  91.   pla("",&abort);
  92.   pla(get_string(49),&abort);
  93.   pla("",&abort);
  94.   if ((nf==0) && (abort==0)) {
  95.     nl();
  96.     pl(get_string(5));
  97.     nl();
  98.   }
  99.   for (i=0; (i<nf) && (!abort) && (!hangup); i++) {
  100.     sprintf(s,"%2d. %s",i+1, g[i].description);
  101.     pla(s,&abort);
  102.   }
  103.   nl();
  104.   if ((!abort) && (cs())) {
  105.     pl(get_string(50));
  106.     pl(get_string(51));
  107.     nl();
  108.   }
  109. }
  110.  
  111.  
  112. void gfile_sec(int sn)
  113. {
  114.   gfilerec *g;
  115.   int i,done,nf,i1;
  116.   char xdc[81],*ss,*ss1,s[81];
  117.  
  118.   g=read_sec(sn,&nf);
  119.   if (g==NULL)
  120.     return;
  121.   strcpy(xdc,odc);
  122.   for (i=0; i<20; i++)
  123.     odc[i]=0;
  124.   for (i=1; i<=nf/10; i++)
  125.     odc[i-1]=i+'0';
  126.   list_gfiles(g,nf);
  127.   done=0;
  128.   while ((!done) && (!hangup)) {
  129.     nl();
  130.     tleft(1);
  131.     prt(2,get_string(52));
  132.     ss=mmkey(2);
  133.     i=atoi(ss);
  134.     if (strcmp(ss,"Q")==0)
  135.       done=1;
  136.     else
  137.       if ((strcmp(ss,"A")==0) && (cs())) {
  138.     farfree(g);
  139.     fill_sec(sn);
  140.         g=read_sec(sn,&nf);
  141.         if (g==NULL)
  142.           return;
  143.         for (i=0; i<20; i++)
  144.           odc[i]=0;
  145.         for (i=1; i<=nf/10; i++)
  146.           odc[i-1]=i+'0';
  147.       } else
  148.     if ((strcmp(ss,"D")==0) && (cs())) {
  149.       nl();
  150.       prt(2,get_string(53));
  151.           ss1=mmkey(2);
  152.       i=atoi(ss1);
  153.       if ((i>0) && (i<=nf)) {
  154.             sprintf(s,"%s %s? ",get_string(54), g[i-1].description);
  155.         prt(5,s);
  156.         if (yn()) {
  157.           prt(5,get_string(55));
  158.           if (yn()) {
  159.                 sprintf(s,"%s%s\\%s",syscfg.gfilesdir,
  160.                       gfilesec[sn].filename,g[i-1].filename);
  161.         unlink(s);
  162.           }
  163.               for (i1=i; i1<nf; i1++)
  164.         g[i1-1]=g[i1];
  165.           --nf;
  166.               sprintf(s,"%s%s.GFL",syscfg.datadir,gfilesec[sn].filename);
  167.               i=open(s,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  168.               write(i,(void *)g,nf*sizeof(gfilerec));
  169.               close(i);
  170.               nl();
  171.           pl(get_string(56));
  172.           nl();
  173.         }
  174.       }
  175.     } else
  176.           if (strcmp(ss,"?")==0)
  177.         list_gfiles(g,nf);
  178.       else
  179.             if ((i>0) && (i<=nf)) {
  180.               sprintf(s,"%s\\%s",gfilesec[sn].filename,g[i-1].filename);
  181.           i1=printfile(s);
  182.           if (i1==0) {
  183.                 sprintf(s,get_stringx(1,15),g[i-1].filename);
  184.             sysoplog(s);
  185.           }
  186.             }
  187.   }
  188.   farfree(g);
  189.   strcpy(odc,xdc);
  190. }
  191.  
  192.  
  193. void gfiles(void)
  194. {
  195.   int i,i1,i2,done,abort,map[32],nmap,ok;
  196.   char s[81],s1[81],s2[81],*ss;
  197.  
  198.   done=0;
  199.   nmap=0;
  200.   for (i=0; i<20; i++)
  201.     odc[i]=0;
  202.   for (i=0; i<num_sec; i++) {
  203.     ok=1;
  204.     if (thisuser.age<gfilesec[i].age)
  205.       ok=0;
  206.     if (actsl<gfilesec[i].sl)
  207.       ok=0;
  208.     if (((thisuser.ar & gfilesec[i].ar)==0) && (gfilesec[i].ar))
  209.       ok=0;
  210.     if (ok) {
  211.       map[nmap++]=i;
  212.       if ((nmap % 10)==0)
  213.     odc[nmap/10-1]='0'+(nmap/10);
  214.     }
  215.   }
  216.   if (nmap==0) {
  217.     nl();
  218.     pl(get_string(57));
  219.     nl();
  220.     return;
  221.   }
  222.   list_sec(map,nmap);
  223.   while ((!done) && (!hangup)) {
  224.     nl();
  225.     tleft(1);
  226.     prt(2,get_string(58));
  227.     ss=mmkey(2);
  228.     if (strcmp(ss,"Q")==0)
  229.       done=1;
  230.     else
  231.       if (strcmp(ss,"?")==0)
  232.     list_sec(map,nmap);
  233.       else
  234.     if ((strcmp(ss,"A")==0) && (cs())) {
  235.       i1=0;
  236.       for (i=0; (i<nmap) && (!i1); i++) {
  237.         nl();
  238.             outstr(get_string(59));
  239.             pl(gfilesec[map[i]].name);
  240.         nl();
  241.         i1=fill_sec(map[i]);
  242.       }
  243.     } else {
  244.           i=atoi(ss);
  245.           if ((i>0) && (i<=nmap)) {
  246.         gfile_sec(map[i-1]);
  247.           }
  248.         }
  249.   }
  250. }
  251.  
  252.  
  253.