From fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Jul 2015 20:46:52 -0400 Subject: Initial commit --- sys/imio/imdelete.x | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 sys/imio/imdelete.x (limited to 'sys/imio/imdelete.x') diff --git a/sys/imio/imdelete.x b/sys/imio/imdelete.x new file mode 100644 index 00000000..785d5c60 --- /dev/null +++ b/sys/imio/imdelete.x @@ -0,0 +1,57 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +# IMDELETE -- Delete an image. + +procedure imdelete (image) + +char image[ARB] + +char cache[SZ_FNAME], fname[SZ_FNAME], extn[SZ_FNAME] +char root[SZ_FNAME], src[SZ_FNAME] +int status, len, ip + +int envgets(), strlen(), iki_access(), imaccess() +bool streq() + +begin + # Delete a cached version of the file. + if (envgets ("cache", cache, SZ_PATHNAME) > 0) { + status = iki_access (image, root, extn, READ_ONLY) + len = strlen (root) + for (ip = len; ip > 0; ip=ip-1) { + if (root[ip] == '/') { + call strcpy (root[ip+1], root, SZ_FNAME) + break + } + } + + # Make sure the name has the image extension. + len = strlen (image) + if (! streq (extn, image[len-strlen(extn)+1])) { + call strcat (".", root, SZ_FNAME) + call strcat (extn, root, SZ_FNAME) + } + + # Note that if the file in the cache was added using + # a full path and/or image type extension, it will not + # be found in the cache and deleted. + if (status > 0) { + call fclookup (cache, image, fname, extn, SZ_FNAME) + if (fname[1] != EOS) { + call fcdelete (cache, fname) + + call fcsrc (cache, image, src, SZ_FNAME) + if (src[1] != EOS) { + call fclookup (cache, src, fname, extn, SZ_FNAME) + call fcdelete (cache, fname) + call fcdelete (cache, src) + } + } + } + } + + if (imaccess (image, READ_ONLY) == YES) { + call iki_init() + call iki_delete (image) + } +end -- cgit