aboutsummaryrefslogtreecommitdiff
path: root/noao/imred/ccdred/src/ccddelete.x
blob: 9093113512b900b460b7de01f79d41a97092fd85 (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
# CCDDELETE -- Delete an image by renaming it to a backup image.
#
#   1.	Get the backup prefix which may be a path name.
#   2.  If no prefix is specified then delete the image without a backup.
#   3.  If there is a prefix then make a backup image name.
#       Rename the image to the backup image name.
#
#   The backup image name is formed by prepending the backup prefix to the
#   image name.  If a previous backup exist append integers to the backup
#   prefix until a nonexistant image name is created.

procedure ccddelete (image)

char	image[ARB]		# Image to delete (backup)

int	i, imaccess()
pointer	sp, prefix, backup
errchk	imdelete, imrename

begin
	call smark (sp)
	call salloc (prefix, SZ_FNAME, TY_CHAR)
	call salloc (backup, SZ_FNAME, TY_CHAR)

	# Get the backup prefix.
	call clgstr ("backup", Memc[prefix], SZ_FNAME)
	call xt_stripwhite (Memc[prefix])

	# If there is no prefix then simply delete the image.
	if (Memc[prefix] == EOS)
	    call imdelete (image)

	# Otherwise create a backup image name which does not exist and
	# rename the image to the backup image.

	else {
	    i = 0
	    repeat {
		if (i == 0) {
	    	    call sprintf (Memc[backup], SZ_FNAME, "%s%s")
		        call pargstr (Memc[prefix])
		        call pargstr (image)
		} else {
	            call sprintf (Memc[backup], SZ_FNAME, "%s%d%s")
			call pargstr (Memc[prefix])
			call pargi (i)
			call pargstr (image)
		}
	        i = i + 1
	    } until (imaccess (Memc[backup], READ_ONLY) == NO)
	    call imrename (image, Memc[backup])
	}

	call sfree (sp)
end