aboutsummaryrefslogtreecommitdiff
path: root/pkg/system/delete.x
blob: 0c15a2c4c91cb72a02da57dd9a1a8126856eb3aa (plain) (blame)
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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<error.h>

# DELETE -- Delete a list of files.  If file cannot be deleted, warn but do
# not abort.  Verify before deleting each file if user wishes.

procedure t_delete()

bool	verify			# verify before deleting
bool	allversions		# delete all versions of each file
bool	subfiles		# delete any subfiles of a file
char	fname[SZ_FNAME]
int	list
pointer	tty

bool	clgetb()
int	clpopns(), clgfil(), access(), btoi(), strncmp()
pointer	ttyodes()

begin
	list = clpopns ("files")
	verify = clgetb ("verify")
	allversions = clgetb ("allversions")
	subfiles = clgetb ("subfiles")
	if (verify)
	    tty = ttyodes ("terminal")

	while (clgfil (list, fname, SZ_FNAME) != EOF) {
	    if (verify) {
		# If file does not exist, warn user (since verify mode is
		# in effect).
		if (access (fname, 0, 0) == NO) {
		    call eprintf ("Warning: Nonexistent file '%s'\n")
			call pargstr (fname)
		    next
		}

		# Set default action of verify prompt (override learning of
		# most recent response).

		call flush (STDOUT)
		call clputb ("go_ahead", clgetb ("default_action"))
		call eprintf ("Delete file ")
		call ttyso (STDERR, tty, YES)
		call eprintf ("'%s'")
		    call pargstr (fname)
		call ttyso (STDERR, tty, NO)
		call flush (STDERR)

		if (!clgetb ("go_ahead"))
		    next
	    }

	    if (strncmp ("http:", fname, 5) == 0) {
		call eprintf ("Cannot delete URL `%s'\n")
		    call pargstr (fname)
		next
	    }

	    iferr (call deletefg (fname, btoi(allversions), btoi(subfiles)))
		call erract (EA_WARN)
	}

	# Reset the go_ahead parameter, overiding learn mode, in case delete
	# is subsequently called from the background.  Close tty descriptor.

	if (verify) {
	    call clputb ("go_ahead", true)
	    call ttycdes (tty)
	}

	call clpcls (list)
end