home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / SNIPTREE.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  3KB  |  111 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /* SNIPTREE
  4.  
  5.    Written by Tom Torfs (2:292/516@fidonet.org)
  6.    I hereby donate this code to the public domain
  7.  
  8.    Builds custom directory structure for SNIPPETS by reading SNIPPETS.NDX
  9.  
  10.    Requires POSIX-function mkdir(), rest should be ANSI C.
  11. */
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16.  
  17. #if defined(MSDOS) || defined(__MSDOS__)
  18.  #include "unistd.h"
  19. #else
  20.  #include <unistd.h>
  21. #endif
  22.  
  23. int main(void)
  24. {
  25.       FILE *fp;
  26.       char buf[100];
  27.       char curpath[80];
  28.       char oldfile[80],newfile[80];
  29.       int i;
  30.       int skiparea;
  31.  
  32.       puts("SNIPTREE by Tom Torfs");
  33.  
  34.       if ((fp=fopen("SNIPPETS.NDX","r"))==NULL)
  35.       {
  36.             puts("ERROR: can't open SNIPPETS.NDX for reading");
  37.             return 1;
  38.       }
  39.  
  40.       while (1)
  41.       {
  42.             do
  43.             {
  44.                   fgets(buf,100,fp);
  45.                   if (feof(fp)) goto finished;
  46.             }
  47.             while (memcmp(buf,"|=========",10))
  48.                   ;
  49.             fgets(buf,100,fp);
  50.             if (feof(fp)) goto finished;
  51.             if (!memcmp(buf,"|=========",10))
  52.             {
  53.                   fgets(buf,100,fp); /* empty */
  54.                   fgets(buf,100,fp); /* section name */
  55.                   fgets(buf,100,fp); /* empty */
  56.                   fgets(buf,100,fp); /* |======================= */
  57.                   fgets(buf,100,fp); /* |======================= */
  58.                   continue;
  59.             }
  60.             strtok(buf,"\n");
  61.             printf("\nFile area: %s\n",buf+2);
  62.             if (!memicmp(buf+2,"Files deleted",13))
  63.             {
  64.                   skiparea = 1;
  65.                   puts("--> SKIPPING");
  66.             }
  67.             else
  68.             {
  69.                   skiparea = 0;
  70.                   printf("Subdirectory (empty=don't move): ");
  71.                   fgets(curpath,80,stdin);
  72.                   i = strlen(curpath);
  73.                   while (i>0 && (curpath[i-1]=='\n' || curpath[i-1]=='\\'
  74.                                  || curpath[i-1]=='/'))
  75.                         i--;
  76.                   curpath[i] = '\0';
  77.                   if (i>0)
  78.                         mkdir(curpath);
  79.             }
  80.             fgets(buf,100,fp); /* |======================= */
  81.             fgets(buf,100,fp); /* | File  O/S  Description */
  82.             fgets(buf,100,fp); /* | ----  ---  ----------- */
  83.             while (1)
  84.             {
  85.                   fgets(buf,100,fp);
  86.                   if (feof(fp)) goto finished;
  87.                   if (buf[0]=='\n')
  88.                         break;
  89.                   if (skiparea)
  90.                         continue;
  91.                   strtok(buf+2," ");
  92.                   strcpy(oldfile,buf+2);
  93.                   if (curpath[0]=='\0' || !stricmp(oldfile,"SNIPPETS.NDX"))
  94.                         printf("%s (not moved)\n",oldfile);
  95.                   else
  96.                   {
  97.                         sprintf(newfile,"%s\\%s",curpath,oldfile);
  98.                         printf("%s -> %s\n",oldfile,newfile);
  99.                         rename(oldfile,newfile);
  100.                   }
  101.             }
  102.       }
  103. finished:
  104.  
  105.       puts("\nFinished.");
  106.  
  107.       fclose(fp);
  108.  
  109.       return 0;
  110. }
  111.