File: arcdel.c

package info (click to toggle)
arc 5.21m-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 364 kB
  • ctags: 306
  • sloc: ansic: 4,078; makefile: 123
file content (76 lines) | stat: -rw-r--r-- 2,084 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * $Header: /cvsroot/arc/arc/arcdel.c,v 1.2 2003/10/31 02:22:36 highlandsun Exp $
 */

/*
 * ARC - Archive utility - ARCDEL
 * 
 * Version 2.09, created on 02/03/86 at 22:53:27
 * 
 * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
 * 
 * By:  Thom Henderson
 * 
 * Description: This file contains the routines used to delete entries in an
 * archive.
 * 
 * Language: Computer Innovations Optimizing C86
 */
#include <stdio.h>
#include "arc.h"

VOID	arcdie(), rempath(), openarc(), closearc(), writehdr(), filecopy();
int	match(), readhdr();

VOID
delarc(num, arg)		/* remove files from archive */
	int             num;	/* number of arguments */
	char           *arg[];	/* pointers to arguments */
{
	struct heads    hdr;	/* header data */
	int             del;	/* true to delete a file */
	int             did[MAXARG];/* true when argument used */
	int             n;	/* index */

	if (!num)		/* she must specify which */
		arcdie("You must tell me which files to delete!");

	for (n = 0; n < num; n++)	/* for each argument */
		did[n] = 0;	/* reset usage flag */
	rempath(num, arg);	/* strip off paths */

	openarc(1);		/* open archive for changes */

	while (readhdr(&hdr, arc)) {	/* while more entries in archive */
		del = 0;	/* reset delete flag */
		for (n = 0; n < num; n++) {	/* for each template given */
			if (match(hdr.name, arg[n])) {
				del = 1;	/* turn on delete flag */
				did[n] = 1;	/* turn on usage flag */
				break;	/* stop looking */
			}
		}

		if (del) {	/* skip over unwanted files */
			fseek(arc, hdr.size, 1);
			if (note)
				printf("Deleting file: %s\n", hdr.name);
		} else {	/* else copy over file data */
			writehdr(&hdr, new);	/* write out header and file */
			filecopy(arc, new, hdr.size);
		}
	}

	hdrver = 0;		/* special end of archive type */
	writehdr(&hdr, new);	/* write out archive end marker */
	closearc(1);		/* close archive after changes */

	if (note) {
		for (n = 0; n < num; n++) {	/* report unused arguments */
			if (!did[n]) {
				printf("File not found: %s\n", arg[n]);
				nerrs++;
			}
		}
	}
}