home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / OS2ARC_S.ZIP / ARCDEL.C < prev    next >
C/C++ Source or Header  |  1987-10-14  |  3KB  |  77 lines

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