aboutsummaryrefslogtreecommitdiff
path: root/unix/boot/rmbin
diff options
context:
space:
mode:
authorJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
committerJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
commit40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch)
tree4464880c571602d54f6ae114729bf62a89518057 /unix/boot/rmbin
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'unix/boot/rmbin')
-rw-r--r--unix/boot/rmbin/README1
-rw-r--r--unix/boot/rmbin/mkpkg.sh6
-rw-r--r--unix/boot/rmbin/rmbin.c264
-rw-r--r--unix/boot/rmbin/rmbin.hlp70
4 files changed, 341 insertions, 0 deletions
diff --git a/unix/boot/rmbin/README b/unix/boot/rmbin/README
new file mode 100644
index 00000000..7eb6a6c4
--- /dev/null
+++ b/unix/boot/rmbin/README
@@ -0,0 +1 @@
+RMBIN -- Descend a directory tree, removing all binary files therein.
diff --git a/unix/boot/rmbin/mkpkg.sh b/unix/boot/rmbin/mkpkg.sh
new file mode 100644
index 00000000..aa2aa4ad
--- /dev/null
+++ b/unix/boot/rmbin/mkpkg.sh
@@ -0,0 +1,6 @@
+# Make and install the RMBIN utility.
+
+$CC -c $HSI_CF rmbin.c
+$CC $HSI_LF rmbin.o $HSI_LIBS -o rmbin.e
+mv -f rmbin.e ../../hlib
+rm *.o
diff --git a/unix/boot/rmbin/rmbin.c b/unix/boot/rmbin/rmbin.c
new file mode 100644
index 00000000..760a1fb3
--- /dev/null
+++ b/unix/boot/rmbin/rmbin.c
@@ -0,0 +1,264 @@
+/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#define import_spp
+#define import_knames
+#include <iraf.h>
+
+#include "../bootProto.h"
+
+
+#define MAXEXTN 128
+
+char *only[MAXEXTN]; /* delete files with these extensions */
+char *excl[MAXEXTN]; /* exclude these files */
+int interactive; /* verify if file does not have extn */
+int recurse; /* recursively descend directories */
+int verbose; /* print names of deleted files */
+int execute; /* permission to delete files */
+
+
+extern int ZZSTRT(void);
+extern int ZZSTOP(void);
+
+static void rmbin (char *dir, int recurse, char *path);
+static int verify_delete (char *fname, char *path);
+static int exclude_file (char *fname);
+
+
+/*
+ * RMBIN -- Delete all binary files in a directory tree or trees.
+ *
+ * rmbin [-dinrv] [-o extns] [-e extns] dir1 dir2 ... dirN
+ *
+ * -d disable recursive descent
+ * -e exclude files with the following extensions
+ * -i verify before deleting files without extensions
+ * -n no execute; do not delete files
+ * -o delete only files with the following extensions
+ * -r enable recursive descent
+ * -v print names of files as they are deleted
+ *
+ * Note that flags may be inserted between directory name arguments to change
+ * switches for different directories.
+ *
+ */
+int
+main (int argc, char *argv[])
+{
+ char path[SZ_PATHNAME+1];
+ char *argp;
+ int argno, i;
+
+ ZZSTRT();
+
+ if (argc < 2)
+ goto help_;
+
+ only[0] = NULL;
+ excl[0] = NULL;
+ path[0] = EOS;
+
+ interactive = 0;
+ recurse = 0;
+ verbose = 0;
+ execute = 1;
+
+ for (argno=1; (argp = argv[argno]) != NULL; argno++)
+ if (*argp == '-') {
+ for (argp++; *argp; argp++)
+ switch (*argp) {
+ case 'd': /* disable recursion */
+ recurse = 0;
+ break;
+ case 'i': /* verify deletions */
+ interactive = 1;
+ break;
+ case 'r': /* enable recursion */
+ recurse = 1;
+ break;
+ case 'n': /* no execute */
+ execute = 0;
+ /* fall through */
+ case 'v': /* set verbose mode */
+ verbose = 1;
+ break;
+
+ case 'e': /* exclude listed files */
+ i = 0;
+ argno++;
+ while (argv[argno] != NULL && *(argv[argno]) == '.' &&
+ *(argv[argno]+1) != EOS)
+ excl[i++] = argv[argno++];
+ --argno;
+ break;
+
+ case 'o': /* only the listed files */
+ i = 0;
+ argno++;
+ while (argv[argno] != NULL && *(argv[argno]) == '.' &&
+ *(argv[argno]+1) != EOS)
+ only[i++] = argv[argno++];
+ --argno;
+ break;
+
+ default:
+ goto help_;
+ }
+ } else
+ rmbin (argp, recurse, path);
+
+ ZZSTOP();
+ exit (OSOK);
+help_:
+ fprintf (stderr, "rmbin [-dinrv] [-o extns] [-e extns] dir dir ...\n");
+ ZZSTOP();
+ exit (OSOK+1);
+}
+
+
+/* RMBIN -- Remove all binaries in a directory or in a directory tree.
+ * We chdir to each directory to minimize path searches.
+ */
+static void
+rmbin (
+ char *dir,
+ int recurse,
+ char *path /* pathname of current directory */
+)
+{
+ char newpath[SZ_PATHNAME+1];
+ char fname[SZ_PATHNAME+1];
+ int dp, ftype;
+
+ if ((dp = os_diropen (dir)) == ERR) {
+ fprintf (stderr, "cannot open directory `%s'\n", dir);
+ fflush (stderr);
+ return;
+ }
+
+ sprintf (newpath, "%s%s/", path, dir);
+
+ /* Descend into the subdirectory.
+ */
+ if (strcmp (dir, ".") != 0)
+ if (os_chdir (dir) == ERR) {
+ os_dirclose (dp);
+ fprintf (stderr, "cannot change directory to `%s'\n", newpath);
+ fflush (stderr);
+ return;
+ }
+
+ /* Scan through the directory.
+ */
+ while (os_gfdir (dp, fname, SZ_PATHNAME) > 0) {
+ if (os_symlink (fname, 0, 0))
+ continue;
+
+ if ((ftype = os_filetype (fname)) == DIRECTORY_FILE)
+ rmbin (fname, recurse, newpath);
+ else {
+ if (only[0] != NULL) {
+ if (exclude_file (fname))
+ continue;
+ } else if (ftype != BINARY_FILE || exclude_file (fname))
+ continue;
+
+ /* We have a binary file which is not excluded from deletion
+ * by its extension, so delete it.
+ */
+ if (interactive && (verify_delete (fname, newpath) == NO))
+ continue;
+
+ if (verbose) {
+ printf ("%s%s\n", newpath, fname);
+ fflush (stdout);
+ }
+
+ if (execute)
+ if (os_delete (fname) == ERR) {
+ fprintf (stderr, "cannot delete `%s'\n", fname);
+ fflush (stderr);
+ }
+ }
+ }
+
+ /* Return from the subdirectory.
+ */
+ if (strcmp (dir, ".") != 0)
+ if (os_chdir ("..") == ERR) {
+ fprintf (stderr, "cannot return from subdirectory `%s'\n",
+ newpath);
+ fflush (stderr);
+ }
+
+ os_dirclose (dp);
+}
+
+
+/* EXCLUDE_FILE -- Check the "only" and "exclude" file lists to see if the
+ * file should be excluded from deletion.
+ */
+static int
+exclude_file (char *fname)
+{
+ register char *ip, *ep;
+ register int ch, i;
+ char *extn;
+
+ extn = NULL;
+ for (ip=fname; (ch = *ip); ip++)
+ if (ch == '.')
+ extn = ip;
+
+ /* If the file has no extension all we have to do is check if there is
+ * an "only" file list.
+ */
+ if (extn == NULL)
+ return (only[0] != NULL ? YES : NO);
+
+ /* Check the only and exclude file lists.
+ */
+ ch = *(extn + 1);
+ if (only[0] != NULL) {
+ for (i=0; (ep = only[i]); i++)
+ if (*(ep+1) == ch)
+ if (strcmp (ep, extn) == 0)
+ return (NO);
+ return (YES);
+ } else if (excl[0] != NULL) {
+ for (i=0; (ep = excl[i]); i++)
+ if (*(ep+1) == ch)
+ if (strcmp (ep, extn) == 0)
+ return (YES);
+ return (NO);
+ } else
+ return (NO);
+}
+
+
+/* VERIFY_DELETE -- Ask the user if they want to delete the named file.
+ */
+static int
+verify_delete (
+ char *fname, /* name of file to be deleted */
+ char *path /* current directory pathname */
+)
+{
+ char lbuf[SZ_LINE+1];
+ char *ip;
+
+ fprintf (stderr, "delete file %s%s? ", path, fname);
+ fflush (stderr);
+ fgets (lbuf, SZ_LINE, stdin);
+
+ for (ip=lbuf; *ip == ' ' || *ip == '\t'; ip++)
+ ;
+ if (*ip == 'y' || *ip == 'Y')
+ return (YES);
+ else
+ return (NO);
+}
diff --git a/unix/boot/rmbin/rmbin.hlp b/unix/boot/rmbin/rmbin.hlp
new file mode 100644
index 00000000..30f54c9e
--- /dev/null
+++ b/unix/boot/rmbin/rmbin.hlp
@@ -0,0 +1,70 @@
+.help rmbin Feb86 "softools"
+.ih
+NAME
+rmbin -- find/remove binary files in subdirectories
+.ih
+USAGE
+rmbin [-dinrv] [-o extns] [-e extns] dir1 dir2 ... dirN
+.ih
+PARAMETERS
+.ls 4 -d
+Disable recursive descent into subdirectories.
+.le
+.ls 4 -e extns
+Exclude files with the listed extensions (whitespace delimited).
+.le
+.ls 4 -i
+Verify before deleting files without extensions. Files with well known
+extensions like ".[aoe]" are deleted without a query. A heuristic (ZFACSS)
+is used to determine the filetype of files with unknown extensions, and
+it can fail, though in practice it works quite well.
+.le
+.ls 4 -n
+No execute; do not delete files. This option may be used to generate
+a list of binary files for some purpose other than deletion. For example,
+on a UNIX host, the following command will compute the disk space used
+by the binary files in a directory tree:
+
+ % du `rmbin -n .`
+
+The -n option, of course, is also useful for verifying the delete operation
+before destroying the files.
+.le
+.ls 4 -o extns
+Delete only files with the listed extensions (whitespace delimited).
+.le
+.ls 4 -r
+Reenable recursive descent. Recursive descent is the default, however
+it may be turned off at one point in the command line, and later reenabled
+with this switch.
+.le
+.ls 4 -v
+Print names of files as they are deleted.
+.le
+
+Note that flags may be inserted between directory name arguments to change
+switches for different directories.
+.ih
+DESCRIPTION
+The \fIrmbin\fR task is used to descend a directory tree, deleting (or listing)
+all the binary files therein. The task may also be used to delete or list
+nonbinary files by explicitly listing their extensions.
+
+\fIRmbin\fR is used the strip the IRAF system down to the sources, prior to
+a full system rebuild. After changing to the IRAF root directory, one runs
+\fIrmbin\fR to delete all the binaries in lib, sys, pkg, etc. (but \fInot\fR
+in hlib, else a bootstrap will be necessary too). \fIMkpkg\fR is then run
+to recompile the system; this currently takes about 20 hours on our UNIX
+11/750 development system, provided nothing else is running on the system.
+.ih
+EXAMPLES
+1. Delete all binaries in the pkg and sys directories of IRAF. The example
+is for a UNIX host, but this works for all other IRAF hosts as well.
+
+.nf
+ % cd $iraf
+ % rmbin -v pkg sys
+.fi
+.ih
+SEE ALSO
+rtar, wtar, mkpkg