home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / COMPRESS / ARC520S.ZIP / ARCDEL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-10-23  |  2.5 KB  |  71 lines

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