home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff214.lzh / ArcPrep / arcprep.c < prev    next >
C/C++ Source or Header  |  1989-05-30  |  8KB  |  234 lines

  1.                /*****************************************a*\
  2.                 *                                        *
  3.                 *  ArcPrepare V2.1  © 1988 G.Glendown    *
  4.                 *                                        *
  5.                 *  This program is placed in the public  *
  6.                 *  domain, no fee may be charged except  *
  7.                 *  for media and copying. Distribution   *
  8.                 *  is only permitted via electronic mail *
  9.                 *  and similar and by Fred Fish's PD     *
  10.                 *  Disks. No other PD series may include *
  11.                 *  ArcPrep on one of their disks.        *
  12.                 *                                        *
  13.                 * If you really like it, just send me $5 *
  14.                 * $10, $50, cars or whatever you think   *
  15.                 * it is worth to this address:           *
  16.                 *                                        *
  17.                 * Garry Glendown                         *
  18.                 * Gueldene Kammer 35                     *
  19.                 * 6430 Bad Hersfeld                      *
  20.                 * West Germany                           *
  21.                 *                                        *
  22.                 * Too, I'm happy about any new ideas or  *
  23.                 * most anything you write. Try to reach  *
  24.                 * me under:                              *
  25.                 *                                        *
  26.                 * Garry@DGIHRZ01.BITNET                  *
  27.                 *                                        *
  28.                \******************************************/
  29.  
  30. /* ...and a voice from the chaos said:
  31.          "Smile and be happy, it could come worse!"
  32.      I smiled and was happy, and it came worse... */
  33. /* (That's where I was a few days ago, trying to get this #@#@$% program
  34.     to do RENAMEing and DELETEing itself. Good that my HD-Backup was only
  35.     two days old! Can you imagine the program getting out of the start-path
  36.     into the main directory and starting to rename *ALL* files ...? [without
  37.     creating the EXECUTE_ME-file because I pressed CTRL-C])      */
  38.  
  39.  
  40. #define FIBLEN   (long)sizeof(struct FileInfoBlock)
  41. VOID   *AllocMem();         /* I don't like warnings...*/
  42. struct   FileLock   *Lock();
  43. char   startpath[256];         /* the path I started at */
  44. struct   FileHandle   *fh,*Open(),*fh1;
  45.                         /* Filehandles for the two Output-Files */
  46. struct   FileHandle   *fhi;      /* and this for the inventory */
  47.  
  48. long   cnt=0;               /* File-Counter. 'Word' would have been  */
  49.                         /* enough, but... */
  50. int      inv=0;               /* inventory-flag */
  51.  
  52. /* This routine scans directories recursively and writes the data
  53.    to the 2 files.                                       */
  54.  
  55. ScanDir(name)
  56. char   *name;
  57. {
  58. char path[1000],p2[1000],p3[1000];
  59.                /* Probably don't need 'em all */
  60.  
  61. struct FileLock         *lock;   /* local file/dir lock */
  62. struct FileInfoBlock   *fib;
  63.  
  64.    strcpy(p3,startpath);
  65.    strcat(p3,name);         /* Tadah! That's where we are! */
  66.  
  67.    if (lock=Lock(p3,SHARED_LOCK)) {   /* Can we lock in? */
  68.  
  69.       if (fib=AllocMem(FIBLEN,MEMF_PUBLIC)) {   /* Some memory, please */
  70.  
  71.          if (Examine(lock,fib)) {   /* Let's have a look ... */
  72.  
  73.             while (ExNext(lock,fib)) {   /* Anybody there ? */
  74.  
  75.                if (fib->fib_DirEntryType>0) {   /* wow, another room */
  76.                         strcpy(path,name);
  77.                         strcat(path,fib->fib_FileName); /* room-number... */
  78.                   sprintf(p2,"makedir \"%s\"\n",path);
  79.                      /* build Dir */
  80.                   Write(fh,p2,(long)strlen(p2));   /* write it down */
  81.                   if (path[0]!='\0')
  82.                      strcat(path,"/");
  83.                   ScanDir(path);            /* enter the room */
  84.                   sprintf(p2,"delete \"%s%s\"\n",name,fib->fib_FileName);
  85.                       /* get rid of it */
  86.                   Write(fh1,p2,(long)strlen(p2));
  87.                }
  88.                else {   /* hey, a file! */
  89.                   if ((strcmp(fib->fib_FileName,"EXECUTE_ME"))&&
  90.                      (strcmp(fib->fib_FileName,"INVENTORY"))&&
  91.                      (strcmp(fib->fib_FileName,"PREP_FILES"))) {
  92.                      /* (phew, that was long.) Is the file from us?*/
  93.  
  94.                      sprintf(p2,"Rename \"%s%s\" Arc-%05ld\n",name,fib->fib_FileName,cnt);
  95.                      /* What's in a name? Gimme a new one! */
  96.  
  97.                      Write(fh1,p2,(long)strlen(p2));
  98.                      sprintf(p2,"Rename Arc-%05ld \"%s%s\"\n",cnt,name,fib->fib_FileName);
  99.                      /* If you don't like it, bring it back... */
  100.                      /* But, while you use it, */
  101.                      /*        DON'T GIVE IT A BAD NAME! */
  102.                      /* (Hey, d'you know Rodney Dangerfield ?) */
  103.                      Write(fh,p2,(long)strlen(p2));
  104.                      if (inv) {
  105.                         sprintf(p2,"Arc-%05ld   %s%s\n",cnt,name,fib->fib_FileName);
  106.                         Write(fhi,p2,(long)strlen(p2));
  107.                      }
  108.                      cnt++;   /* Prepare for files to come... */
  109.                   }
  110.                }
  111.             }
  112.          }
  113.          else printf("Examine...\n");
  114.          FreeMem(fib,FIBLEN);
  115.       }
  116.       else printf("Memory!\n");
  117.       UnLock(lock);
  118.    }
  119.    else printf("Lock!\n");
  120. }
  121.  
  122.  
  123. main(argc,argv)
  124. int      argc;
  125. char   *argv[];
  126. /* Hey, you wanna argue with me? Oh, just an argument, o.k. */
  127. {
  128. char   path[256];
  129.  
  130.    if (argc<2)
  131.       puts("What do you want to prepare?"),
  132.       puts("ArcPrep <Path> <-i>"),
  133.       Exit();
  134.    if (argc==3)
  135.       if ((argv[2][0]=='-')&&(argv[2][1]=='i')) inv=1;
  136.    strcpy(path,argv[1]);
  137.    if (path[strlen(path)-1]!=':')
  138.       strcat(path,"/");
  139.    strcpy(startpath,path);
  140.    strcat(path,"EXECUTE_ME");   /* Here's what to do after 'arc x' */
  141.    fh=Open(path,MODE_NEWFILE);
  142.    if (fh) {
  143.       strcpy(path,startpath);
  144.       strcat(path,"PREP_FILES"); /* And do this to make good names for
  145.                              your files */
  146.       fh1=Open(path,MODE_NEWFILE);
  147.       if (fh1) {
  148.          if (inv) {
  149.             strcpy(path,startpath);
  150.             strcat(path,"INVENTORY");   /* Here's what we got in here */
  151.             if (!(fhi=Open(path,MODE_NEWFILE))) inv=0;
  152.             else {
  153.                Write(fhi,"»»» Inventory created with 'ArcPrep' by G.Glendown «««\n",55L);
  154.                Write(fhi,"    ==============================================\n",51L);
  155.                Write(fhi,"The following files are included in this archive:\n\n",51L);
  156.             }
  157.          }
  158.          path[0]='\0';
  159.          Write(fh,"; Script created with 'ArcPrep' by G.Glendown\n",46L);
  160.          Write(fh,"failat 21\n",10L);
  161.          Write(fh1,"failat 21\n",10L);
  162.          ScanDir(path);
  163.          Write(fh1,"echo \"Please delete 'PREP_FILES' now!\"\n",39L);
  164.          Write(fh,"echo \"Please delete 'EXECUTE_ME' now!\"\n",39L);
  165.          if (inv) Close(fhi);
  166.          Close(fh1);
  167.       }
  168.       Close(fh);
  169.    }
  170. }
  171. /* That's all, friends. No more. Nothing. NIL. Or, as Harpo would say:
  172.  
  173.                    "             "
  174.  
  175.    Capice ? */
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212. /*
  213.  
  214. But, if you really want some more, here are the greetings:
  215.  
  216.    'normal' greetings go to all Amiga-Users on the whole world
  217.    special greetings to all the programmers and my friends
  218.    very special greetings and many thanks to:
  219.       Commo      for their Amiga
  220.       Leo Schwab   for the fine hacks and his 'Iconify'-routine
  221.                (you should receive my 'ViroTrack'-program soon)
  222.       Fred Fish   (did anybody tell you that you have started a fine
  223.                 collection?) Thanks for it!
  224.       My mother   I wouldn't make it through all them hours on my Amy
  225.                without the food, sandwiches, drinks ...
  226.       Thorsten Budesheim   for always stopping my best ideas from coming
  227.                      by calling me...
  228.  
  229. O.K., but this is really it. Even *YOU* should notice that...
  230.  
  231. */
  232.  
  233.  
  234.