home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / ARC521-2.ZIP / ARCDEL.C < prev    next >
C/C++ Source or Header  |  1989-12-29  |  2KB  |  77 lines

  1. /*
  2.  * $Header: arcdel.c,v 1.3 88/04/19 01:39:32 hyc Exp $
  3.  */
  4.  
  5. /*
  6.  * ARC - Archive utility - ARCDEL
  7.  *
  8.  * Version 2.09, created on 02/03/86 at 22:53:27
  9.  *
  10.  * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  11.  *
  12.  * By:  Thom Henderson
  13.  *
  14.  * Description: This file contains the routines used to delete entries in an
  15.  * archive.
  16.  *
  17.  * Language: Computer Innovations Optimizing C86
  18.  */
  19. #include <stdio.h>
  20. #include "arc.h"
  21.  
  22. void    abort(), rempath(), openarc(), closearc(), writehdr(), filecopy();
  23. int    match(), readhdr();
  24.  
  25. void
  26. delarc(num, arg)        /* remove files from archive */
  27.     int             num;    /* number of arguments */
  28.     char           *arg[];    /* pointers to arguments */
  29. {
  30.     struct heads    hdr;    /* header data */
  31.     int             del;    /* true to delete a file */
  32.     int             did[MAXARG];/* true when argument used */
  33.     int             n;    /* index */
  34.  
  35.     if (!num)        /* she must specify which */
  36.         abort("You must tell me which files to delete!");
  37.  
  38.     for (n = 0; n < num; n++)    /* for each argument */
  39.         did[n] = 0;    /* reset usage flag */
  40.     rempath(num, arg);    /* strip off paths */
  41.  
  42.     openarc(1);        /* open archive for changes */
  43.  
  44.     while (readhdr(&hdr, arc)) {    /* while more entries in archive */
  45.         del = 0;    /* reset delete flag */
  46.         for (n = 0; n < num; n++) {    /* for each template given */
  47.             if (match(hdr.name, arg[n])) {
  48.                 del = 1;    /* turn on delete flag */
  49.                 did[n] = 1;    /* turn on usage flag */
  50.                 break;    /* stop looking */
  51.             }
  52.         }
  53.  
  54.         if (del) {    /* skip over unwanted files */
  55.             fseek(arc, hdr.size, 1);
  56.             if (note)
  57.                 printf("Deleting file: %s\n", hdr.name);
  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.