home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 157.lha / Arc_Src / arcdel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-27  |  2.4 KB  |  68 lines

  1. /*  ARC - Archive utility - ARCDEL
  2.  
  3. System V Version 1.0 based upon:
  4.     Version 2.09, created on 02/03/86 at 22:53:27
  5.  
  6. (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  7.  
  8.     By:  Thom Henderson
  9.  
  10.     Description:
  11.          This file contains the routines used to delete entries
  12.          in an archive.
  13. */
  14. #include "arc.h"
  15.  
  16. INT delarc(num,arg)                    /* remove files from archive */
  17. INT num;                               /* number of arguments */
  18. char *arg[];                           /* pointers to arguments */
  19. {
  20.     struct heads hdr;                  /* header data */
  21.     INT del;                           /* true to delete a file */
  22.     INT did[MAXARG];                   /* true when argument used */
  23.     INT n;                             /* index */
  24.  
  25.     if(!num)                           /* she must specify which */
  26.          abort("You must tell me which files to delete!");
  27.  
  28.     for(n=0; n<num; n++)               /* for each argument */
  29.          did[n] = 0;                   /* reset usage flag */
  30.     rempath(num,arg);                  /* strip off paths */
  31.  
  32.     openarc(1);                        /* open archive for changes */
  33.  
  34.     while(readhdr(&hdr,arc))           /* while more entries in archive */
  35.     {    del = 0;                      /* reset delete flag */
  36.          for(n=0; n<num; n++)          /* for each template given */
  37.          {    if(match(hdr.name,arg[n]))
  38.               {    del = 1;            /* turn on delete flag */
  39.                    did[n] = 1;         /* turn on usage flag */
  40.                    break;              /* stop looking */
  41.               }
  42.          }
  43.  
  44.          if(del)                       /* skip over unwanted files */
  45.          {    fseek(arc,hdr.size,1);
  46.               if(note)
  47.                    printf("Deleting file: %s\n",hdr.name);
  48.          }
  49.          else                          /* else copy over file data */
  50.          {    writehdr(&hdr,new);      /* write out header and file */
  51.               filecopy(arc,new,hdr.size);
  52.          }
  53.     }
  54.  
  55.     hdrver = 0;                        /* special end of archive type */
  56.     writehdr(&hdr,new);                /* write out archive end marker */
  57.     closearc(1);                       /* close archive after changes */
  58.  
  59.     if(note)
  60.     {    for(n=0; n<num; n++)          /* report unused arguments */
  61.          {    if(!did[n])
  62.               {    printf("File not found: %s\n",arg[n]);
  63.                    nerrs++;
  64.               }
  65.          }
  66.     }
  67. }
  68.