home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d0xx / d050 / unixarc.lha / UnixArc / arcdel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-01-17  |  2.4 KB  |  69 lines

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