aboutsummaryrefslogtreecommitdiff
path: root/unix/boot/generic
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
commitfa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch)
treebdda434976bc09c864f2e4fa6f16ba1952b1e555 /unix/boot/generic
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'unix/boot/generic')
-rw-r--r--unix/boot/generic/README3
-rw-r--r--unix/boot/generic/chario.c188
-rw-r--r--unix/boot/generic/generic.c892
-rw-r--r--unix/boot/generic/generic.hlp245
-rw-r--r--unix/boot/generic/lex.sed7
-rw-r--r--unix/boot/generic/lexyy.c679
-rw-r--r--unix/boot/generic/mkpkg.sh18
-rw-r--r--unix/boot/generic/tok.l91
-rw-r--r--unix/boot/generic/yywrap.c10
-rw-r--r--unix/boot/generic/z20
10 files changed, 2153 insertions, 0 deletions
diff --git a/unix/boot/generic/README b/unix/boot/generic/README
new file mode 100644
index 00000000..98a1d23a
--- /dev/null
+++ b/unix/boot/generic/README
@@ -0,0 +1,3 @@
+GENERIC -- The generic preprocessor is a simple task used to process generic
+ code into type specific code. A different copy of the code is output
+ for each datatype.
diff --git a/unix/boot/generic/chario.c b/unix/boot/generic/chario.c
new file mode 100644
index 00000000..09b46e40
--- /dev/null
+++ b/unix/boot/generic/chario.c
@@ -0,0 +1,188 @@
+/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+/*
+ * OS Character I/O. This set of routines are provided as a workaround in
+ * the event that the host system cannot execute FTELL/FSEEK reliably (VMS/C
+ * could not). The idea here is to keep track of the character offset from
+ * the beginning of the file. K_FTELL returns the character offset. K_FSEEK
+ * rewinds the file and reads characters forward to the indicated offset.
+ * K_GETC keeps a count of the file position. (the k_ stands for kludge).
+ */
+
+extern int debug;
+
+struct context {
+ FILE *fp; /* file descriptor */
+ long fpos; /* saved file pointer */
+ char fname[512]; /* file being scanned */
+};
+
+FILE *
+k_fopen (fname, mode)
+char *fname;
+char *mode;
+{
+ register struct context *cx;
+ register FILE *fp;
+
+ if ((fp = fopen (fname, mode)) == NULL)
+ return (NULL);
+
+ cx = (struct context *) malloc (sizeof(struct context));
+ strcpy (cx->fname, fname);
+ cx->fpos = 0;
+ cx->fp = fp;
+
+ return ((FILE *)cx);
+}
+
+
+int
+k_fclose (cx_i)
+FILE *cx_i;
+{
+ register struct context *cx = (struct context *)cx_i;
+ int status;
+
+ status = fclose (cx->fp);
+ free (cx);
+
+ return (status);
+}
+
+#ifdef vms
+
+int
+k_getc (cx_i)
+FILE *cx_i;
+{
+ register struct context *cx = (struct context *)cx_i;
+ register int ch;
+
+ cx->fpos++;
+ if (debug > 3) {
+ if ((ch = getc (cx->fp)) > 0)
+ printf ("%5d %03o %c\n", cx->fpos, ch, ch > 040 ? ch : 040);
+ return (ch);
+ } else
+ return (getc (cx->fp));
+}
+
+char *
+k_fgets (obuf, maxch, cx_i)
+char *obuf;
+int maxch;
+FILE *cx_i;
+{
+ register struct context *cx = (struct context *)cx_i;
+ register int ch, n;
+ register char *op;
+
+ for (op=obuf, n=maxch; --n >= 0; )
+ if ((ch = k_getc(cx)) < 0)
+ return (NULL);
+ else {
+ *op++ = ch;
+ if (ch == '\n')
+ break;
+ }
+
+ return (obuf);
+}
+
+seek
+k_fseek (cx_i, offset, type)
+FILE *cx_i;
+long offset;
+int type;
+{
+ register struct context *cx = (struct context *)cx_i;
+ register FILE *fp = cx->fp;
+ register int ch;
+
+ if (debug > 1)
+ printf ("seek (%s, %ld, %d)\n", cx->fname, offset, type);
+
+ if (type == 0) {
+ fseek (fp, 0L, 0);
+ cx->fpos = 0;
+
+ while (cx->fpos < offset && (ch = getc(fp)) != EOF) {
+ if (debug > 1)
+ fputc (ch, stdout);
+ cx->fpos++;
+ }
+
+ if (debug > 1)
+ printf ("[]\n");
+
+ return (0);
+ }
+
+ if (fseek (fp, offset, type) == -1)
+ return (-1);
+ else {
+ cx->fpos = ftell (fp);
+ return (0);
+ }
+}
+
+long
+k_ftell (cx_i)
+FILE *cx_i;
+{
+ register struct context *cx = (struct context *)cx_i;
+
+ if (debug > 1) {
+ printf ("ftell returns %d\n", cx->fpos);
+ fflush (stdout);
+ }
+
+ return (cx->fpos);
+}
+
+#else
+
+int
+k_getc (cx_i)
+FILE *cx_i;
+{
+ register struct context *cx = (struct context *)cx_i;
+ return (getc (cx->fp));
+}
+
+char *
+k_fgets (op, maxch, cx_i)
+char *op;
+int maxch;
+FILE *cx_i;
+{
+ register struct context *cx = (struct context *)cx_i;
+ return (fgets (op, maxch, cx->fp));
+}
+
+int
+k_fseek (cx_i, offset, type)
+FILE *cx_i;
+long offset;
+int type;
+{
+ register struct context *cx = (struct context *)cx_i;
+ return (fseek (cx->fp, offset, type));
+}
+
+int
+k_ftell (cx_i)
+FILE *cx_i;
+{
+ register struct context *cx = (struct context *)cx_i;
+ return (ftell (cx->fp));
+}
+
+#endif
diff --git a/unix/boot/generic/generic.c b/unix/boot/generic/generic.c
new file mode 100644
index 00000000..07d19885
--- /dev/null
+++ b/unix/boot/generic/generic.c
@@ -0,0 +1,892 @@
+/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+ */
+
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#define import_spp
+#include <iraf.h>
+
+/*
+ * GENERIC -- This filter takes a file containing a generic operator as input
+ * and generates as output either a set of files, one for each of the data
+ * types in the generic family, or a single file wherein the generic section
+ * has been duplicated for each case.
+ */
+
+#define input lex_input
+#define unput lex_unput
+extern char yytext[];
+extern int yyleng;
+extern FILE *yyin;
+extern FILE *yyout;
+
+#define MAXFILES 512
+#define MAXNEST 50
+#define OK 0
+#define SZ_FORSTK 20
+
+/* $FOR contstruct descriptor.
+ */
+struct _for {
+ char f_prevtype; /* type before $for */
+ char f_types[20]; /* "csilrdx" */
+ char *f_curtype; /* pointer into f_types */
+ long f_fpos; /* seek offset of $FOR */
+};
+
+struct _for forstk[SZ_FORSTK];
+int forlev;
+char *type_string;
+char xtype_string[SZ_FNAME+1];
+char type_char;
+int pass_output = 1;
+int clobber = NO;
+
+extern long k_ftell (FILE *cx_i);
+extern FILE *k_fopen (char *fname, char *mode);
+extern int k_fseek (FILE *cx_i, long offset, int type);
+extern int k_fclose (FILE *cx_i);
+
+extern int yylex (void);
+extern int lex_input (void);
+extern void lex_unput (int ch);
+
+
+char *make_typed_filename (char *template, char type_char);
+void set_type_string (char ch);
+void copy_line (void);
+void copy_string (void);
+void copy_comment (void);
+void make_float (char type_ch);
+void output_indef (char ch);
+void output_upper (char *s);
+void pass_through (void);
+void do_for (void);
+void do_endfor (void);
+void do_if (void);
+void do_else (void);
+void do_endif (void);
+
+int evaluate_expr (void);
+int parse_relational (int *size1, int *size2, int *op);
+
+int relop (void);
+int gsize (char ch);
+char nextch (void);
+char gch (void);
+void uch (char ch);
+
+void output (char ch);
+void outstr (char *s);
+
+
+
+
+/**
+ * GENERIC: e.g., generic [-k] [-t csilrdx] file
+ */
+int main (int argc, char *argv[])
+{
+ char *files[MAXFILES], *s, **p, *ip;
+ char fname[SZ_FNAME], *extension;
+ char *types = "i", *t;
+ char *prefix = "";
+ char genfname[SZ_FNAME+1];
+ char template[SZ_FNAME+1];
+ char input_file[SZ_FNAME+1];
+ char *index(), *rindex();
+ int n, nfiles;
+ FILE *fp;
+
+ genfname[0] = EOS;
+ nfiles = 0;
+
+ for (p = &argv[1]; *p != NULL; p++) {
+ s = *p;
+ if (s[0] == '-') {
+ switch (s[1]) {
+ case 'k':
+ clobber = YES;
+ break;
+ case 't':
+ if (*(p+1) != NULL)
+ types = *++p;
+ break;
+ case 'o':
+ if (*(p+1) != NULL)
+ strcpy (genfname, *++p);
+ break;
+ case 'p':
+ if (*(p+1) != NULL)
+ prefix = *++p;
+ break;
+ }
+ } else {
+ files[nfiles++] = s;
+ if (genfname[0] != EOS && nfiles > 1) {
+ fprintf (stderr,
+ "Cannot process multiple files with '-o' flag\n");
+ exit (OSOK+1);
+ }
+ }
+ }
+
+ for (n=0; n < nfiles; n++) {
+ strcpy (input_file, files[n]);
+ yyin = k_fopen (input_file, "r");
+ if (yyin == NULL) {
+ fprintf (stderr, "Cannot open input file '%s'\n", input_file);
+ continue;
+ }
+
+ /* Set pointer to the filename extension string. If the file name
+ * has an extension, lop it off by overwriting the '.' with EOS.
+ * The first character of the extension of a generic file is
+ * normally a 'g', e.g., ".gx" or ".gc", but we want to generate
+ * a ".x" or ".c" file, so lop off any leading g in the extension.
+ */
+ if ((extension = rindex (input_file, '.')) != NULL) {
+ *extension++ = EOS;
+ if (*extension == 'g')
+ extension++;
+ } else
+ extension = "";
+
+ for (t=types; *t != EOS; t++) {
+ /* Make output file name */
+ strcpy (fname, prefix);
+
+ /* Expand a template of the form "chars$tchars" into the root
+ * name of the new file, replacing the $t by the type char.
+ * If using input filename as the root, add "$t"; otherwise,
+ * check whether or not the generic filename string has a
+ * "$t" in it, and add one at end if it does not.
+ */
+ if (genfname[0] == EOS) {
+ strcpy (template, input_file);
+ strcat (template, "$t");
+
+ } else {
+ strcpy (template, genfname);
+
+ for (ip=index(genfname,'$'); ip != NULL;
+ ip = index(ip,'$')) {
+
+ if (*(ip+1) == '$')
+ ip += 2;
+ else if (*(ip+1) == 't')
+ break;
+ }
+
+ if (ip == NULL && strlen(types) > 1)
+ strcat (ip, "$t");
+ }
+
+ if (genfname[0] == EOS || strlen (types) > 1)
+ strcat (fname, make_typed_filename (template, *t));
+ else
+ strcat (fname, template);
+
+ /* If the user supplied the output filename template, we
+ * assume that it already contains an extension.
+ */
+ if (genfname[0] == EOS) {
+ strcat (fname, ".");
+ strcat (fname, extension);
+ }
+
+ if (access(fname,0) == 0) {
+ if (clobber == NO) {
+ fprintf (stderr, "File `%s' already exists\n", fname);
+ continue;
+ } else
+ unlink (fname);
+ }
+ if ((fp = fopen (fname, "w")) == NULL) {
+ fprintf (stderr, "Cannot open file `%s'\n", fname);
+ continue;
+ }
+
+ yyout = fp;
+ set_type_string (*t);
+ type_char = *t;
+ forlev = -1;
+
+ yylex(); /* do it */
+
+ fclose (fp);
+ k_fseek (yyin,0L,0);
+ }
+
+ k_fclose (yyin);
+ }
+
+ exit (OSOK);
+}
+
+
+/* MAKE_TYPED_FILENAME -- Make a copy of a filename string, substituting
+ * the given type suffix character for the every sequence "$t" found in the
+ * input string. The output string is retained in an internal static buffer.
+ * Any sequence "$$" is converted into a single "$".
+ */
+char *
+make_typed_filename (char *template, char type_char)
+{
+ register char *ip, *op;
+ char ch;
+ static char fname[SZ_FNAME+1];
+
+ if (isupper (type_char))
+ ch = tolower (type_char);
+ else
+ ch = type_char;
+
+ for (ip=template, op=fname; *ip != EOS; )
+ if (*ip == '$' && *(ip+1) == '$') {
+ *op++ = '$';
+ ip += 2;
+ } else if (*ip == '$' && *(ip+1) == 't') {
+ *op++ = ch;
+ ip += 2;
+ } else
+ *op++ = *ip++;
+
+ return (fname);
+}
+
+
+/* SET_TYPE_STRING -- Given the type suffix character, set the external
+ * array "type_string" to the name of the corresponding SPP datatype.
+ */
+void
+set_type_string (char ch)
+{
+ char *ip, *op;
+
+ switch (ch) {
+ case 'B':
+ type_string = "ubyte"; /* unsigned byte */
+ break;
+ case 'U':
+ type_string = "ushort";
+ break;
+ case 'b':
+ type_string = "bool";
+ break;
+ case 'c':
+ type_string = "char";
+ break;
+ case 's':
+ type_string = "short";
+ break;
+ case 'i':
+ type_string = "int";
+ break;
+ case 'l':
+ type_string = "long";
+ break;
+ case 'r':
+ type_string = "real";
+ break;
+ case 'd':
+ type_string = "double";
+ break;
+ case 'x':
+ type_string = "complex";
+ break;
+ case 'p':
+ type_string = "pointer";
+ break;
+ default:
+ fprintf (stderr, "Unknown type suffix char `%c'\n", ch);
+ }
+
+ op = xtype_string;
+ *op++ = 'X';
+ for (ip=type_string; *ip != EOS; ip++)
+ *op++ = toupper (*ip);
+ *op++ = EOS;
+}
+
+
+/* COPY_LINE -- Output whatever is in the yylex token buffer, followed by the
+ * remainder of the line from which the token was extracted.
+ */
+void
+copy_line (void)
+{
+ char ch;
+
+ outstr(yytext);
+ while ((ch = input()) != '\n')
+ output(ch);
+ unput(ch);
+}
+
+
+/* COPY_STRING -- Called when the opening quote of a string is seen in the
+ * input. Copy the opening quote followed by all input characters until the
+ * end of string is seen.
+ */
+void
+copy_string (void)
+{
+ char ch;
+
+ outstr(yytext);
+ for (;;) {
+ switch (ch = input()) {
+ case '"':
+ output(ch);
+ return;
+ case '\\':
+ output(ch);
+ if ((ch = input()) != '\n')
+ output(ch);
+ else
+ unput(ch);
+ break;
+ case '\n':
+ unput(ch);
+ return;
+ default:
+ output(ch);
+ }
+ }
+}
+
+
+/* COPY_COMMENT -- Copy a C style comment to the output file.
+ */
+void
+copy_comment (void)
+{
+ char ch;
+ int flag = 0;
+
+ outstr (yytext);
+
+ while ((ch = input()) != EOF) {
+ output (ch);
+ switch (ch) {
+ case '*':
+ flag = 1;
+ break;
+ case '/':
+ if (flag == 1)
+ return;
+ else
+ flag = 0;
+ break;
+ default:
+ flag = 0;
+ break;
+ }
+ }
+}
+
+
+/* MAKE_FLOAT -- Called when a n$f is seen in the input to convert a numeric
+ * constant to the form appropriate for the indicated datatype, e.g., "0",
+ * "0.", "0.0D0", etc.
+ */
+void
+make_float (char type_ch)
+{
+ char *p;
+
+ for (p=yytext; *p != '$'; p++)
+ ;
+ *p = EOS;
+
+ if (type_ch == 'x') {
+ output ('(');
+ outstr (yytext);
+ outstr (".0,");
+ outstr (yytext);
+ outstr (".0)");
+ } else {
+ outstr (yytext);
+ switch (type_ch) {
+ case 'r':
+ outstr (".0");
+ break;
+ case 'd':
+ outstr (".0D0");
+ break;
+ }
+ }
+}
+
+
+/* OUTPUT_INDEF -- Output the INDEF string for the indicated datatype.
+ */
+void
+output_indef (char ch) /* output INDEF, INDEFS, INDEFL, etc. */
+{
+ outstr(yytext);
+
+ switch (ch) {
+ case 's':
+ output ('S');
+ break;
+ case 'i':
+ output ('I');
+ break;
+ case 'l':
+ output ('L');
+ break;
+ case 'r':
+ output ('R');
+ break;
+ case 'd':
+ output ('D');
+ break;
+ case 'x':
+ output ('X');
+ break;
+ }
+}
+
+
+/* OUTPUT_UPPER -- Output the name of the current datatype (INT, REAL, etc.)
+ * in upper case.
+ */
+void
+output_upper (char *s)
+{
+ char ch, *p;
+
+ outstr(s);
+ for (p=type_string; (ch = *p) != EOS; p++)
+ output(toupper(ch));
+}
+
+
+/* PASS_THROUGH -- Used to pass text on to the output without modification.
+ * The text is delimited as "$/ (text) /" in the input file. The delimited
+ * section may enclose newlines.
+ */
+void
+pass_through (void)
+{
+ char ch;
+
+ while ((ch = input()) != '/')
+ output(ch);
+}
+
+
+/* DO_FOR -- Process a "$FOR (types)" statement. The sequence of statements
+ * bracketed by $for ... $endfor will be processed and output (to a single
+ * output stream) for each datatype named in the for predicate.
+ */
+void
+do_for (void)
+{
+ register char *op;
+ register int ch;
+ register struct _for *fp;
+ char types[20];
+
+ if (++forlev + 1 >= SZ_FORSTK) {
+ fprintf (stderr, "$for statements nested too deeply\n");
+ exit (OSOK+1);
+ }
+
+ /* Extract list of types.
+ */
+ while ((ch = input()) != '(')
+ if (ch == EOF || ch == '\n') {
+ fprintf (stderr, "$for must have () delimited list of types\n");
+ strcpy (types, "i");
+ goto init_;
+ }
+
+ for (op=types; (ch = input()) != ')'; op++)
+ if (ch == EOF || ch == '\n') {
+ fprintf (stderr, "missing right paren in $for statement\n");
+ break;
+ } else
+ *op = ch;
+
+ *op = EOS;
+ if (op == types) {
+ fprintf (stderr, "null typelist in $for statement\n");
+ strcpy (types, "i");
+ }
+
+init_:
+ fp = &forstk[forlev];
+ fp->f_prevtype = type_char;
+ strcpy (fp->f_types, types);
+ fp->f_curtype = fp->f_types;
+ fp->f_fpos = k_ftell (yyin);
+
+ type_char = *(fp->f_curtype)++;
+ set_type_string (type_char);
+}
+
+
+/* DO_ENDFOR -- Called to process a $ENDFOR. Set the next datatype and seek
+ * back to the line following the matching $FOR statement. When the type list
+ * is exhausted pop the $for stack and continue normal processing.
+ */
+void
+do_endfor (void)
+{
+ register struct _for *fp;
+
+ if (forlev < 0) {
+ fprintf (stderr, "$endfor with no matching $for\n");
+ return;
+ }
+
+ fp = &forstk[forlev];
+ if ((type_char = *(fp->f_curtype)++) != EOS) {
+ set_type_string (type_char);
+ k_fseek (yyin, fp->f_fpos, 0);
+ } else {
+ type_char = fp->f_prevtype;
+ set_type_string (type_char);
+ --forlev;
+ }
+}
+
+
+/*
+ * Conditional Compilation
+ * -------------------------
+ */
+
+#define TRUE 1
+#define FALSE 0
+#define EQ 0
+#define NE 1
+#define LE 2
+#define LT 3
+#define GE 4
+#define GT 5
+
+char expr_buf[80], *expr;
+int level = 0;
+
+struct if_stack {
+ int oldstate;
+ int active;
+} stk[MAXNEST];
+
+
+/* DO_IF -- Process a $IF statement. Evaluate the predicate and push a
+ * pass or stop output flag on the if stack.
+ */
+void
+do_if (void)
+{
+ char ch;
+ int expr_value;
+ struct if_stack *p;
+
+ level += 1;
+ p = &stk[level];
+ p->oldstate = pass_output;
+ p->active = (pass_output == TRUE);
+
+ if ((expr_value = evaluate_expr()) == ERR)
+ expr_value = FALSE;
+
+ if ((ch = input()) != '\n')
+ unput(ch);
+
+ if (p->active == FALSE)
+ return;
+ else if (expr_value == FALSE)
+ pass_output = FALSE;
+}
+
+
+/* DO_ELSE -- Process a $ELSE statement. Toggle the pass/stop output flag
+ * on top of the if stack.
+ */
+void
+do_else (void)
+{
+ char ch;
+
+ if (level == 0)
+ fprintf (stderr, "Unmatched $else statement\n");
+ else if (stk[level].active) /* toggle pass_output */
+ pass_output = (pass_output == FALSE);
+
+ if ((ch = input()) != '\n')
+ unput(ch);
+}
+
+
+/* DO_ENDIF -- Process a $ENDIF statement. Pop the if stack.
+ */
+void
+do_endif (void) /* $endif statement */
+{
+ char ch;
+
+ if (level == 0)
+ fprintf (stderr, "Too many $endif statements\n");
+ else
+ pass_output = stk[level--].oldstate;
+
+ if ((ch = input()) != '\n')
+ unput(ch);
+}
+
+
+/* EVALUATE_EXPR -- Kludge to evaluate boolean expressions in $if statements.
+ * Two kinds of expressions are permitted: (datatype relop chars), or
+ * (sizeof(char) relop sizeof(char)), where relop = (==, !=, <= etc.).
+ *
+ * Examples: $if (datatype != dx)
+ * (code to be compiled if type not d or x)
+ *
+ * $if (sizeof(i) <= sizeof(r))
+ * (code to be compiled if size int <= real)
+ */
+int
+evaluate_expr (void)
+{
+ char ch=0, *p, *index();
+ int lpar, size1, size2, op;
+
+
+ /* Advance to start of expression (discard '(') */
+ if (nextch() != '(')
+ goto err;
+ else
+ input();
+
+ /* Extract expression string into buffer */
+ expr = expr_buf;
+ nextch();
+
+ for (p=expr_buf, lpar=1; lpar > 0 && (*p = input()) != EOF; p++)
+ switch (ch = *p) {
+ case '(':
+ lpar++;
+ break;
+ case ')':
+ if (--lpar == 0)
+ *p = EOS;
+ break;
+ case '\n':
+ goto err;
+ }
+
+ /* Is current type in set or not in set */
+ if (strncmp (expr,"datatype",8) == 0) {
+ expr += 8;
+ switch (relop()) {
+ case EQ:
+ return (index(expr,type_char) != NULL);
+ case NE:
+ return (index(expr,type_char) == NULL);
+ default:
+ goto err;
+ }
+
+ /* Compare sizes of two data types */
+ } else if (strncmp(expr,"sizeof",6) == 0) {
+ if (parse_relational (&size1, &size2, &op) == ERR) {
+ ch = 0;
+ goto err;
+ }
+ switch (op) {
+ case EQ:
+ return (size1 == size2);
+ case NE:
+ return (size1 != size2);
+ case LE:
+ return (size1 <= size2);
+ case LT:
+ return (size1 < size2);
+ case GE:
+ return (size1 >= size2);
+ case GT:
+ return (size1 > size2);
+ }
+
+ /* only "type" and "sizeof" are implemented */
+ } else {
+err: fprintf (stderr, "Syntax error in $if statement\n");
+ if (ch != '\n') {
+ /* skip rest of line */
+ while ((ch = input()) != '\n')
+ ;
+ unput(ch);
+ }
+ }
+
+ return (ERR);
+}
+
+
+/* PARSE_RELATIONAL -- Parse "sizeof(t1) relop sizeof(t2)" (via brute force...) */
+int
+parse_relational (int *size1, int *size2, int *op)
+{
+ expr += 6; /* ... (t1) */
+
+ if (gch() != '(')
+ return (ERR);
+ if ((*size1 = gsize(gch())) == ERR)
+ return (ERR);
+ if (gch() != ')')
+ return (ERR); /* relop */
+ if ((*op = relop()) == ERR)
+ return (ERR);
+
+ uch (gch()); /* skip whitespace */
+
+ if (strncmp(expr,"sizeof",6) != 0) /* sizeof(t2) */
+ return (ERR);
+
+ expr += 6;
+
+ if (gch() != '(')
+ return (ERR);
+ if ((*size2 = gsize(gch())) == ERR)
+ return (ERR);
+ if (gch() != ')')
+ return (ERR);
+
+ return (OK);
+}
+
+
+/* RELOP -- Return a code for the next relational operator token in the input
+ * stream.
+ */
+int
+relop (void)
+{
+ char ch;
+
+
+ switch (gch()) {
+ case '!':
+ if (gch() == '=')
+ return (NE);
+ return (ERR);
+ case '=':
+ if (gch() == '=')
+ return (EQ);
+ return (ERR);
+ case '<':
+ if ((ch = gch()) == '=')
+ return (LE);
+ uch(ch);
+ return (LT);
+ case '>':
+ if ((ch = gch()) == '=')
+ return (GE);
+ uch(ch);
+ return (GT);
+ default:
+ return (ERR);
+ }
+}
+
+
+/* GSIZE -- Return the size of a datatype given its character code.
+ */
+int
+gsize (char ch)
+{
+ switch (ch) {
+ case 'B':
+ return (sizeof(XUBYTE));
+ case 'U':
+ return (sizeof(XUSHORT));
+ case 't':
+ return (gsize(type_char));
+ case 'c':
+ return (sizeof(XCHAR));
+ case 's':
+ return (sizeof(XSHORT));
+ case 'i':
+ return (sizeof(XINT));
+ case 'l':
+ return (sizeof(XLONG));
+ case 'r':
+ return (sizeof(XREAL));
+ case 'd':
+ return (sizeof(XDOUBLE));
+ case 'x':
+ return (sizeof(XCOMPLEX));
+ case 'p':
+ return (sizeof(XPOINTER));
+ default:
+ return (ERR);
+ }
+}
+
+
+/* NEXTCH -- Advance to next non-whitespace character.
+ */
+char
+nextch (void)
+{
+ char ch;
+
+ for (ch=input(); ch == ' ' || ch == '\t'; ch=input())
+ ;
+ unput (ch);
+ return (ch);
+}
+
+
+/* GCH -- Get next nonwhite char from expression buffer.
+ */
+char
+gch (void)
+{
+ while (*expr == ' ' || *expr == '\t')
+ expr++;
+
+ if (*expr != EOS)
+ return (*expr++);
+ else
+ return (EOS);
+}
+
+
+/* UCH -- Put char back into expression buffer.
+ */
+void
+uch (char ch)
+{
+ *--expr = ch;
+}
+
+
+/* OUTPUT -- Write a single character to the output file, if output is
+ * currently enabled (else throw it away).
+ */
+void
+output (char ch)
+{
+ if (pass_output)
+ putc (ch, yyout);
+}
+
+
+/* OUTSTR -- Output a string.
+ */
+void
+outstr (char *s)
+{
+ if (pass_output)
+ fputs (s, yyout);
+}
diff --git a/unix/boot/generic/generic.hlp b/unix/boot/generic/generic.hlp
new file mode 100644
index 00000000..eda8ceb2
--- /dev/null
+++ b/unix/boot/generic/generic.hlp
@@ -0,0 +1,245 @@
+.help generic Feb86 softools
+.ih
+NAME
+generic -- generic preprocessor
+.ih
+USAGE
+generic [-k] [-o ofile] [-p prefix] [-t types] files
+.ih
+PARAMETERS
+.ls 4 -k
+Allow the output files generated by \fIgeneric\fR to clobber any existing
+files.
+.le
+.ls 4 -o ofile
+The name of the output file. If this option is selected, only a single
+file can be processed.
+.le
+.ls 4 -p prefix
+A prefix to be prepended to the output filenames. This is useful when
+the output files are to be placed in a different directory.
+.le
+.ls 4 -t types
+The datatypes for which output is desired. One output file will be generated
+for each type specified, with \fIgeneric\fR automatically generating the
+output filename by appending the type character to the root filename of
+the input file. The \fItype\fR string is some subset of [ubscilrdx],
+where the type characters are as follows.
+.ls
+.nf
+u - C unsigned short
+b - C byte (char)
+c - SPP character
+s - SPP short
+i - SPP int
+l - SPP long
+r - SPP real
+d - SPP double
+x - SPP complex
+.fi
+.le
+
+This option cannot be used in combination with the -o option, and should
+not be used when generic code is expanded inline, rather than written into
+multiple output files.
+.le
+.ls 4 files
+The input file or files to be processed. Generic input files should have
+the extension ".gx" or ".gc", although this is not required. Only a single
+input file can be given if the -o option is specified.
+.le
+.ih
+DESCRIPTION
+The generic preprocessor is used to translate generic source code (code
+written to work for any datatype) into type dependent source code,
+suitable for compilation and insertion into a library. The generic source
+is translated for each datatype, producing a type dependent copy of the
+source code for each datatype. There are two primary modes of operation:
+
+.ls
+.ls [1]
+The generic source is embedded in a normal file, bracketed by \fI$for\fR and
+\fI$endfor\fR directives. There is one input file and one somewhat larger
+output file, with the generic code in the input file being replaced in the
+output file by several copies of the enclosed source, one for each datatype.
+This mode is most commonly used for modules to be linked in their entirety
+into an applications package. The "-o" parameter is used to specify
+the output filename.
+.le
+.ls [2]
+The entire input file is generic. There may be multiple input files, and
+for each input file N output files are generated, one for each datatype
+specified with the "-t" parameter. The output filenames are automatically
+generated by appending the type character to the root filename of the
+input file. This mode is most commonly used for object libraries.
+.le
+.le
+
+
+The generic preprocessor operates by token replacement (currently using a
+UNIX \fILex\fR lexical analyzer). The input stream is broken up into a
+stream of tokens. Each token is examined to see if it is in the following
+list, and the indicated action is taken if the token is matched. The generic
+preprocessor directives have the form "$NAME", where $ marks a \fIgeneric\fR
+directive, and where NAME is the name of the directive.
+.ls 10 PIXEL
+Replaced by the current type name, e.g., "int", "real", etc.
+.le
+.ls 10 XPIXEL
+Replaced by the current type name in upper case, preceded by an X,
+e.g., "XINT", "XREAL", etc. This is used for generic C procedures meant
+to be called from SPP or Fortran.
+.le
+.ls 10 INDEF
+Replaced by the numeric constant denoting indefinite for the current
+datatype.
+.le
+.ls 10 INDEF[SILRDX]
+These strings are \fInot\fR replaced, since the "INDEF" in this case is
+not generic.
+.le
+.ls 10 SZ_PIXEL
+Replaced by "SZ_INT", "SZ_REAL", etc.
+.le
+.ls 10 TY_PIXEL
+Replaced by "TY_INT", "TY_REAL", etc.
+.le
+.ls 10 $PIXEL
+Replaced by the string "PIXEL". This is used in doubly generic sources,
+where the first pass translates $PIXEL to PIXEL, and the second to the
+actual type string.
+.le
+.ls 10 $INDEF
+Replaced by the string "INDEF".
+.le
+.ls 10 $t
+Replaced by one of the characters [ubcsilrdx].
+.le
+.ls 10 $T
+Replaced by one of the characters [UBCSILRDX].
+.le
+.ls 10 $/.../
+Replaced by the string "...", i.e., whatever is within the // delimiters.
+Used to disable generic preprocessing of arbitrary text.
+.le
+.ls 10 [0-9]+("$f"|"$F")
+Replaced by the corresponding real or double constant. For example,
+"1$f" translates as "1.0" for type real, but as "1.0D0" for type double.
+.le
+
+.ls 10 $if (expression)
+The conditional preprocessing facility. If the $IF tests false the code
+which follows is skipped over, and is not copied to the output file.
+Control transfers to the matching $ELSE or $ENDIF. The following may be
+used in the boolean expression:
+
+.nf
+"datatype" denotes the current type
+ubcsilrdx any subset of these characters denotes
+ the corresponding datatype
+sizeof() the size of the specified type,
+ e.g., for comparisons
+
+!= == the relational operators
+ > < >= <=
+
+
+Examples:
+
+ $if (datatype != dx)
+ (code to be compiled if type not d or x)
+
+ $if (sizeof(i) <= sizeof(r))
+ (code to be compiled if size int <= real)
+.fi
+
+$IF constructs may be nested. The directive may appear anywhere on
+a line.
+.le
+
+.ls 10 $else
+Marks the else clause of a $IF.
+.le
+.ls 10 $endif
+Marks the end of a $IF. One is required for every $IF.
+.le
+.ls 10 $for (types)
+For each of the listed types, output a translated copy of the code between
+the $FOR and the matching $ENDFOR. Nesting is permitted.
+
+.nf
+Example:
+ $for (silrd)
+ (any amount of generic code)
+ $endfor
+.fi
+.le
+.ls 10 $endfor
+Marks the end of a $FOR statement.
+.le
+.ls 10 $$
+Replaced by a single $.
+.le
+.ls 10 /*...*/
+C comments are not preprocessed.
+.le
+.ls 10 "..."
+Quoted strings are not preprocessed.
+.le
+.ls 10 #...(EOL)
+SPP comments are not preprocessed.
+.le
+.ls 10 %...(EOL)
+SPP Fortran escapes are not preprocessed.
+.le
+.ih
+EXAMPLES
+1. Translate the generic source "aadd.gx" to produce the six output files
+"aadds.x", "aaddi.x", etc., in the subdirectory "ak", clobbering any
+existing files therein. The \fIgeneric\fR task is a bootstrap utility
+written in C and is implemented as a CL foreign task, hence the UNIX
+command syntax.
+
+ cl> generic -k -p ak/ -t silrdx aadd.gx
+
+2. Perform an inline transformation ($FOR directive) of the source file
+"imsum.gx", producing the single file "imsum.x" as output.
+
+ cl> generic -k -o imsum.x imsum.gx
+
+3. The following is a simple example of a typical generic source file.
+For additional examples, see the ".gx" sources in the VOPS, IMIO, IMAGES
+and other directories.
+
+.nf
+# ALIM -- Compute the limits (minimum and maximum values) of a vector.
+# (this is a copy of the file vops$alim.gx).
+
+procedure alim$t (a, npix, minval, maxval)
+
+PIXEL a[ARB], minval, maxval, value
+int npix, i
+
+begin
+ minval = a[1]
+ maxval = a[1]
+
+ do i = 1, npix {
+ value = a[i]
+ $if (datatype == x)
+ if (abs(value) < abs(minval))
+ minval = value
+ else if (abs(value) > abs(maxval))
+ maxval = value
+ $else
+ if (value < minval)
+ minval = value
+ else if (value > maxval)
+ maxval = value
+ $endif
+ }
+end
+.fi
+.ih
+SEE ALSO
+xc, xyacc
diff --git a/unix/boot/generic/lex.sed b/unix/boot/generic/lex.sed
new file mode 100644
index 00000000..56df4751
--- /dev/null
+++ b/unix/boot/generic/lex.sed
@@ -0,0 +1,7 @@
+/int nstr; extern int yyprevious;/a\
+if (yyin==NULL) yyin = stdin;\
+if (yyout==NULL) yyout = stdout;
+/{stdin}/c\
+FILE *yyin, *yyout;
+s/"stdio.h"/<stdio.h>/
+s/getc/k_getc/
diff --git a/unix/boot/generic/lexyy.c b/unix/boot/generic/lexyy.c
new file mode 100644
index 00000000..6cda8553
--- /dev/null
+++ b/unix/boot/generic/lexyy.c
@@ -0,0 +1,679 @@
+# include <stdio.h>
+# define U(x) x
+# define NLSTATE yyprevious=YYNEWLINE
+# define BEGIN yybgin = yysvec + 1 +
+# define INITIAL 0
+# define YYLERR yysvec
+# define YYSTATE (yyestate-yysvec-1)
+# define YYOPTIM 1
+# define YYLMAX BUFSIZ
+# define output(c) putc(c,yyout)
+# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):k_getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
+# define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
+# define yymore() (yymorfg=1)
+# define ECHO fprintf(yyout, "%s",yytext)
+# define REJECT { nstr = yyreject(); goto yyfussy;}
+int yyleng; extern char yytext[];
+int yymorfg;
+extern char *yysptr, yysbuf[];
+int yytchar;
+FILE *yyin, *yyout;
+extern int yylineno;
+struct yysvf {
+ struct yywork *yystoff;
+ struct yysvf *yyother;
+ int *yystops;};
+struct yysvf *yyestate;
+extern struct yysvf yysvec[], *yybgin;
+
+#include <ctype.h>
+
+/*
+ * GENERIC -- This filter takes a file containing a generic operator as input
+ * and generates as output either a set of files, one for each of the data
+ * types in the generic family, or a single file wherein the generic section
+ * has been duplicated for each case.
+ */
+
+#undef output
+extern char *type_string;
+extern char xtype_string[];
+extern char type_char;
+
+# define YYNEWLINE 10
+yylex(){
+int nstr; extern int yyprevious;
+if (yyin==NULL) yyin = stdin;
+if (yyout==NULL) yyout = stdout;
+while((nstr = yylook()) >= 0)
+yyfussy: switch(nstr){
+case 0:
+if(yywrap()) return(0); break;
+case 1:
+ outstr (type_string);
+break;
+case 2:
+ outstr (xtype_string);
+break;
+case 3:
+ output_indef (type_char);
+break;
+case 4:
+ ECHO;
+break;
+case 5:
+ output_upper ("SZ_");
+break;
+case 6:
+ output_upper ("TY_");
+break;
+case 7:
+ outstr ("PIXEL");
+break;
+case 8:
+ outstr ("INDEF");
+break;
+case 9:
+ {
+ yytext[strlen(yytext)-5] = '\0';
+ output_upper (yytext);
+ }
+break;
+case 10:
+ { if (isupper (type_char))
+ output (tolower (type_char));
+ else
+ output (type_char);
+ }
+break;
+case 11:
+ { if (islower (type_char))
+ output (toupper (type_char));
+ else
+ output (type_char);
+ }
+break;
+case 12:
+ pass_through();
+break;
+case 13:
+ make_float (type_char);
+break;
+case 14:
+ do_if();
+break;
+case 15:
+ do_else();
+break;
+case 16:
+ do_endif();
+break;
+case 17:
+ do_for();
+break;
+case 18:
+ do_endfor();
+break;
+case 19:
+ do_if();
+break;
+case 20:
+ do_else();
+break;
+case 21:
+ do_endif();
+break;
+case 22:
+ do_for();
+break;
+case 23:
+ do_endfor();
+break;
+case 24:
+ output ('$');
+break;
+case 25:
+ copy_comment();
+break;
+case 26:
+ copy_string();
+break;
+case 27:
+ ECHO;
+break;
+case 28:
+ ECHO;
+break;
+case 29:
+ ECHO;
+break;
+case 30:
+ ECHO;
+break;
+case 31:
+ copy_line();
+break;
+case 32:
+ copy_line();
+break;
+case -1:
+break;
+default:
+fprintf(yyout,"bad switch yylook %d",nstr);
+} return(0); }
+/* end of yylex */
+
+
+/* LEX_INPUT -- Make input() callable as a function from the .c code.
+ */
+lex_input()
+{
+ return (input());
+}
+
+
+/* LEX_UNPUT -- Make unput() callable as a function from the .c code.
+ */
+lex_unput (ch)
+int ch;
+{
+ unput (ch);
+}
+int yyvstop[] = {
+0,
+
+26,
+0,
+
+31,
+0,
+
+31,
+0,
+
+32,
+0,
+
+24,
+0,
+
+12,
+0,
+
+11,
+0,
+
+10,
+0,
+
+25,
+0,
+
+19,
+0,
+
+14,
+0,
+
+13,
+0,
+
+27,
+0,
+
+22,
+0,
+
+17,
+0,
+
+20,
+0,
+
+15,
+0,
+
+3,
+0,
+
+1,
+0,
+
+28,
+0,
+
+21,
+0,
+
+8,
+0,
+
+7,
+0,
+
+16,
+0,
+
+9,
+0,
+
+4,
+0,
+
+2,
+9,
+0,
+
+29,
+0,
+
+23,
+0,
+
+18,
+0,
+
+5,
+9,
+0,
+
+6,
+9,
+0,
+
+30,
+0,
+0};
+# define YYTYPE char
+struct yywork { YYTYPE verify, advance; } yycrank[] = {
+0,0, 0,0, 0,0, 0,0,
+0,0, 0,0, 0,0, 0,0,
+0,0, 0,0, 1,3, 0,0,
+0,0, 0,0, 0,0, 0,0,
+3,3, 0,0, 0,0, 0,0,
+0,0, 0,0, 0,0, 0,0,
+0,0, 0,0, 0,0, 0,0,
+0,0, 0,0, 0,0, 0,0,
+0,0, 1,3, 0,0, 1,4,
+1,5, 1,6, 2,15, 3,3,
+2,16, 0,0, 0,0, 3,17,
+7,29, 0,0, 0,0, 0,0,
+1,7, 1,8, 1,8, 1,8,
+1,8, 1,8, 1,8, 1,8,
+1,8, 1,8, 1,8, 0,0,
+0,0, 0,0, 0,0, 0,0,
+0,0, 0,0, 1,9, 1,9,
+1,9, 1,9, 1,9, 1,9,
+1,9, 1,9, 1,10, 1,9,
+1,9, 1,9, 1,9, 1,9,
+1,9, 1,11, 1,9, 1,9,
+1,12, 1,13, 1,9, 1,9,
+1,9, 1,14, 1,9, 1,9,
+6,18, 8,30, 10,32, 11,33,
+12,34, 13,35, 14,36, 20,40,
+21,42, 20,41, 23,45, 6,19,
+27,49, 8,8, 8,8, 8,8,
+8,8, 8,8, 8,8, 8,8,
+8,8, 8,8, 8,8, 15,37,
+17,20, 17,21, 26,48, 15,38,
+17,39, 25,46, 22,43, 25,47,
+30,50, 6,20, 6,21, 31,51,
+32,52, 6,22, 22,44, 33,53,
+34,54, 35,55, 36,56, 37,57,
+6,23, 37,58, 38,59, 39,43,
+6,24, 40,61, 41,62, 42,63,
+44,64, 45,65, 38,60, 46,66,
+17,25, 17,26, 47,67, 48,68,
+17,27, 51,69, 52,70, 53,71,
+30,50, 6,25, 6,26, 54,72,
+55,73, 6,27, 56,74, 57,75,
+58,76, 60,77, 61,78, 62,79,
+64,81, 65,82, 62,80, 66,83,
+6,28, 9,9, 9,9, 9,9,
+9,9, 9,9, 9,9, 9,9,
+9,9, 9,9, 9,9, 9,9,
+9,9, 9,9, 9,9, 9,9,
+9,31, 9,9, 9,9, 9,9,
+9,9, 9,9, 9,9, 9,9,
+9,9, 9,9, 9,9, 67,84,
+69,86, 70,87, 67,85, 9,9,
+71,88, 72,89, 73,90, 74,91,
+75,92, 76,93, 77,94, 79,95,
+80,96, 81,97, 82,98, 84,99,
+85,100, 86,101, 87,102, 89,103,
+90,104, 91,105, 93,106, 87,102,
+94,107, 95,108, 87,102, 99,109,
+103,110, 104,111, 107,112, 110,113,
+87,102, 87,102, 111,114, 112,115,
+0,0, 0,0, 87,102, 0,0,
+0,0};
+struct yysvf yysvec[] = {
+0, 0, 0,
+yycrank+1, 0, 0,
+yycrank+3, yysvec+1, 0,
+yycrank+7, 0, 0,
+yycrank+0, 0, yyvstop+1,
+yycrank+0, 0, yyvstop+3,
+yycrank+56, 0, 0,
+yycrank+2, 0, 0,
+yycrank+57, 0, 0,
+yycrank+108, 0, 0,
+yycrank+16, yysvec+9, 0,
+yycrank+22, yysvec+9, 0,
+yycrank+6, yysvec+9, 0,
+yycrank+8, yysvec+9, 0,
+yycrank+18, yysvec+9, 0,
+yycrank+14, 0, yyvstop+5,
+yycrank+0, 0, yyvstop+7,
+yycrank+47, 0, 0,
+yycrank+0, 0, yyvstop+9,
+yycrank+0, 0, yyvstop+11,
+yycrank+23, 0, 0,
+yycrank+21, 0, 0,
+yycrank+52, 0, 0,
+yycrank+29, 0, 0,
+yycrank+0, 0, yyvstop+13,
+yycrank+13, 0, 0,
+yycrank+7, 0, 0,
+yycrank+2, 0, 0,
+yycrank+0, 0, yyvstop+15,
+yycrank+0, 0, yyvstop+17,
+yycrank+54, 0, 0,
+yycrank+54, yysvec+9, 0,
+yycrank+60, yysvec+9, 0,
+yycrank+43, yysvec+9, 0,
+yycrank+37, yysvec+9, 0,
+yycrank+38, yysvec+9, 0,
+yycrank+61, yysvec+9, 0,
+yycrank+27, 0, 0,
+yycrank+36, 0, 0,
+yycrank+69, 0, 0,
+yycrank+58, 0, 0,
+yycrank+74, 0, 0,
+yycrank+61, 0, 0,
+yycrank+0, 0, yyvstop+19,
+yycrank+76, 0, 0,
+yycrank+57, 0, 0,
+yycrank+32, 0, 0,
+yycrank+50, 0, 0,
+yycrank+37, 0, 0,
+yycrank+0, 0, yyvstop+21,
+yycrank+0, 0, yyvstop+23,
+yycrank+65, yysvec+9, 0,
+yycrank+85, yysvec+9, 0,
+yycrank+86, yysvec+9, 0,
+yycrank+79, yysvec+9, 0,
+yycrank+80, yysvec+9, 0,
+yycrank+74, yysvec+9, 0,
+yycrank+48, 0, 0,
+yycrank+64, 0, 0,
+yycrank+0, 0, yyvstop+25,
+yycrank+66, 0, 0,
+yycrank+97, 0, 0,
+yycrank+97, 0, 0,
+yycrank+0, 0, yyvstop+27,
+yycrank+99, 0, 0,
+yycrank+100, 0, 0,
+yycrank+70, 0, 0,
+yycrank+97, 0, 0,
+yycrank+0, 0, yyvstop+29,
+yycrank+131, yysvec+9, 0,
+yycrank+131, yysvec+9, 0,
+yycrank+128, yysvec+9, 0,
+yycrank+132, yysvec+9, 0,
+yycrank+133, yysvec+9, 0,
+yycrank+138, yysvec+9, 0,
+yycrank+107, 0, 0,
+yycrank+104, 0, 0,
+yycrank+102, 0, 0,
+yycrank+0, 0, yyvstop+31,
+yycrank+132, 0, 0,
+yycrank+142, 0, 0,
+yycrank+143, 0, 0,
+yycrank+138, 0, 0,
+yycrank+0, 0, yyvstop+33,
+yycrank+104, 0, 0,
+yycrank+114, 0, 0,
+yycrank+141, yysvec+9, 0,
+yycrank+150, yysvec+9, yyvstop+35,
+yycrank+0, yysvec+9, yyvstop+37,
+yycrank+131, yysvec+9, 0,
+yycrank+132, yysvec+9, 0,
+yycrank+145, yysvec+9, 0,
+yycrank+0, 0, yyvstop+39,
+yycrank+120, 0, 0,
+yycrank+107, 0, 0,
+yycrank+143, 0, 0,
+yycrank+0, 0, yyvstop+41,
+yycrank+0, 0, yyvstop+43,
+yycrank+0, 0, yyvstop+45,
+yycrank+113, 0, 0,
+yycrank+0, 0, yyvstop+47,
+yycrank+0, yysvec+9, yyvstop+49,
+yycrank+0, yysvec+9, yyvstop+51,
+yycrank+159, yysvec+9, 0,
+yycrank+160, yysvec+9, 0,
+yycrank+0, yysvec+9, yyvstop+53,
+yycrank+0, 0, yyvstop+56,
+yycrank+130, 0, 0,
+yycrank+0, 0, yyvstop+58,
+yycrank+0, 0, yyvstop+60,
+yycrank+155, yysvec+9, 0,
+yycrank+158, yysvec+9, 0,
+yycrank+134, 0, 0,
+yycrank+0, yysvec+9, yyvstop+62,
+yycrank+0, yysvec+9, yyvstop+65,
+yycrank+0, 0, yyvstop+68,
+0, 0, 0};
+struct yywork *yytop = yycrank+238;
+struct yysvf *yybgin = yysvec+1;
+char yymatch[] = {
+00 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
+01 ,011 ,01 ,01 ,01 ,01 ,01 ,01 ,
+01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
+01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
+011 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
+01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
+'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,
+'0' ,'0' ,01 ,01 ,01 ,01 ,01 ,01 ,
+01 ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
+'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
+'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
+'A' ,'A' ,'A' ,01 ,01 ,01 ,01 ,'_' ,
+01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
+01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
+01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
+01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
+0};
+char yyextra[] = {
+0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,
+0};
+#ifndef lint
+static char ncform_sccsid[] = "@(#)ncform 1.6 88/02/08 SMI"; /* from S5R2 1.2 */
+#endif
+
+int yylineno =1;
+# define YYU(x) x
+# define NLSTATE yyprevious=YYNEWLINE
+char yytext[YYLMAX];
+struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
+char yysbuf[YYLMAX];
+char *yysptr = yysbuf;
+int *yyfnd;
+extern struct yysvf *yyestate;
+int yyprevious = YYNEWLINE;
+yylook(){
+ register struct yysvf *yystate, **lsp;
+ register struct yywork *yyt;
+ struct yysvf *yyz;
+ int yych, yyfirst;
+ struct yywork *yyr;
+# ifdef LEXDEBUG
+ int debug;
+# endif
+ char *yylastch;
+ /* start off machines */
+# ifdef LEXDEBUG
+ debug = 0;
+# endif
+ yyfirst=1;
+ if (!yymorfg)
+ yylastch = yytext;
+ else {
+ yymorfg=0;
+ yylastch = yytext+yyleng;
+ }
+ for(;;){
+ lsp = yylstate;
+ yyestate = yystate = yybgin;
+ if (yyprevious==YYNEWLINE) yystate++;
+ for (;;){
+# ifdef LEXDEBUG
+ if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
+# endif
+ yyt = yystate->yystoff;
+ if(yyt == yycrank && !yyfirst){ /* may not be any transitions */
+ yyz = yystate->yyother;
+ if(yyz == 0)break;
+ if(yyz->yystoff == yycrank)break;
+ }
+ *yylastch++ = yych = input();
+ yyfirst=0;
+ tryagain:
+# ifdef LEXDEBUG
+ if(debug){
+ fprintf(yyout,"char ");
+ allprint(yych);
+ putchar('\n');
+ }
+# endif
+ yyr = yyt;
+ if ( (int)yyt > (int)yycrank){
+ yyt = yyr + yych;
+ if (yyt <= yytop && yyt->verify+yysvec == yystate){
+ if(yyt->advance+yysvec == YYLERR) /* error transitions */
+ {unput(*--yylastch);break;}
+ *lsp++ = yystate = yyt->advance+yysvec;
+ goto contin;
+ }
+ }
+# ifdef YYOPTIM
+ else if((int)yyt < (int)yycrank) { /* r < yycrank */
+ yyt = yyr = yycrank+(yycrank-yyt);
+# ifdef LEXDEBUG
+ if(debug)fprintf(yyout,"compressed state\n");
+# endif
+ yyt = yyt + yych;
+ if(yyt <= yytop && yyt->verify+yysvec == yystate){
+ if(yyt->advance+yysvec == YYLERR) /* error transitions */
+ {unput(*--yylastch);break;}
+ *lsp++ = yystate = yyt->advance+yysvec;
+ goto contin;
+ }
+ yyt = yyr + YYU(yymatch[yych]);
+# ifdef LEXDEBUG
+ if(debug){
+ fprintf(yyout,"try fall back character ");
+ allprint(YYU(yymatch[yych]));
+ putchar('\n');
+ }
+# endif
+ if(yyt <= yytop && yyt->verify+yysvec == yystate){
+ if(yyt->advance+yysvec == YYLERR) /* error transition */
+ {unput(*--yylastch);break;}
+ *lsp++ = yystate = yyt->advance+yysvec;
+ goto contin;
+ }
+ }
+ if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
+# ifdef LEXDEBUG
+ if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
+# endif
+ goto tryagain;
+ }
+# endif
+ else
+ {unput(*--yylastch);break;}
+ contin:
+# ifdef LEXDEBUG
+ if(debug){
+ fprintf(yyout,"state %d char ",yystate-yysvec-1);
+ allprint(yych);
+ putchar('\n');
+ }
+# endif
+ ;
+ }
+# ifdef LEXDEBUG
+ if(debug){
+ fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
+ allprint(yych);
+ putchar('\n');
+ }
+# endif
+ while (lsp-- > yylstate){
+ *yylastch-- = 0;
+ if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
+ yyolsp = lsp;
+ if(yyextra[*yyfnd]){ /* must backup */
+ while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
+ lsp--;
+ unput(*yylastch--);
+ }
+ }
+ yyprevious = YYU(*yylastch);
+ yylsp = lsp;
+ yyleng = yylastch-yytext+1;
+ yytext[yyleng] = 0;
+# ifdef LEXDEBUG
+ if(debug){
+ fprintf(yyout,"\nmatch ");
+ sprint(yytext);
+ fprintf(yyout," action %d\n",*yyfnd);
+ }
+# endif
+ return(*yyfnd++);
+ }
+ unput(*yylastch);
+ }
+ if (yytext[0] == 0 /* && feof(yyin) */)
+ {
+ yysptr=yysbuf;
+ return(0);
+ }
+ yyprevious = yytext[0] = input();
+ if (yyprevious>0)
+ output(yyprevious);
+ yylastch=yytext;
+# ifdef LEXDEBUG
+ if(debug)putchar('\n');
+# endif
+ }
+ }
+yyback(p, m)
+ int *p;
+{
+if (p==0) return(0);
+while (*p)
+ {
+ if (*p++ == m)
+ return(1);
+ }
+return(0);
+}
+ /* the following are only used in the lex library */
+yyinput(){
+ return(input());
+ }
+yyoutput(c)
+ int c; {
+ output(c);
+ }
+yyunput(c)
+ int c; {
+ unput(c);
+ }
diff --git a/unix/boot/generic/mkpkg.sh b/unix/boot/generic/mkpkg.sh
new file mode 100644
index 00000000..5ab35c4d
--- /dev/null
+++ b/unix/boot/generic/mkpkg.sh
@@ -0,0 +1,18 @@
+# Bootstrap the generic preprocessor. The -lln library is not used to avoid
+# the enternal dependency. The sed script is used to edit certain nonportable
+# constructs in the LEX code, and the filename lex.yy.c is changed to lexyy.c
+# for portability reasons.
+
+find tok.l -newer lexyy.c -exec rm lexyy.c \;
+if test -f lexyy.c; then\
+ $CC -c $HSI_CF -w lexyy.c;\
+else\
+ lex tok.l;\
+ sed -f lex.sed lex.yy.c > lexyy.c; rm lex.yy.c;\
+ $CC -c $HSI_CF -w lexyy.c;\
+fi
+
+$CC -c $HSI_CF generic.c chario.c yywrap.c
+$CC $HSI_LF generic.o lexyy.o chario.o yywrap.o $HSI_LIBS -o generic.e
+mv -f generic.e ../../hlib
+rm *.o
diff --git a/unix/boot/generic/tok.l b/unix/boot/generic/tok.l
new file mode 100644
index 00000000..f72c1bb8
--- /dev/null
+++ b/unix/boot/generic/tok.l
@@ -0,0 +1,91 @@
+%{
+
+#include <ctype.h>
+
+/*
+ * GENERIC -- This filter takes a file containing a generic operator as input
+ * and generates as output either a set of files, one for each of the data
+ * types in the generic family, or a single file wherein the generic section
+ * has been duplicated for each case.
+ */
+
+#undef output
+extern char *type_string;
+extern char xtype_string[];
+extern char type_char;
+
+%}
+
+W [ \t]
+
+%%
+
+PIXEL outstr (type_string);
+XPIXEL outstr (xtype_string);
+INDEF output_indef (type_char);
+INDEF(S|I|L|R|D|X) ECHO;
+SZ_PIXEL output_upper ("SZ_");
+TY_PIXEL output_upper ("TY_");
+$PIXEL outstr ("PIXEL");
+$INDEF outstr ("INDEF");
+
+[A-Z][A-Z_]*PIXEL {
+ yytext[strlen(yytext)-5] = '\0';
+ output_upper (yytext);
+ }
+
+"$t" { if (isupper (type_char))
+ output (tolower (type_char));
+ else
+ output (type_char);
+ }
+"$T" { if (islower (type_char))
+ output (toupper (type_char));
+ else
+ output (type_char);
+ }
+
+"$/" pass_through();
+[0-9]+("$f"|"$F") make_float (type_char);
+
+{W}*"$if" do_if();
+{W}*"$else" do_else();
+{W}*"$endif" do_endif();
+{W}*"$for" do_for();
+{W}*"$endfor" do_endfor();
+{W}*"$IF" do_if();
+{W}*"$ELSE" do_else();
+{W}*"$ENDIF" do_endif();
+{W}*"$FOR" do_for();
+{W}*"$ENDFOR" do_endfor();
+
+"$$" output ('$');
+"/*" copy_comment();
+\" copy_string();
+
+^\#if ECHO;
+^\#else ECHO;
+^\#endif ECHO;
+^\#include ECHO;
+
+\# copy_line();
+^\% copy_line();
+
+%%
+
+
+/* LEX_INPUT -- Make input() callable as a function from the .c code.
+ */
+lex_input()
+{
+ return (input());
+}
+
+
+/* LEX_UNPUT -- Make unput() callable as a function from the .c code.
+ */
+lex_unput (ch)
+int ch;
+{
+ unput (ch);
+}
diff --git a/unix/boot/generic/yywrap.c b/unix/boot/generic/yywrap.c
new file mode 100644
index 00000000..627dff08
--- /dev/null
+++ b/unix/boot/generic/yywrap.c
@@ -0,0 +1,10 @@
+/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+ */
+
+/* YYWRAP -- Called by lex when end of file is seen.
+ */
+int
+yywrap()
+{
+ return (1);
+}
diff --git a/unix/boot/generic/z b/unix/boot/generic/z
new file mode 100644
index 00000000..91a515fe
--- /dev/null
+++ b/unix/boot/generic/z
@@ -0,0 +1,20 @@
+# Bootstrap the generic preprocessor. The -lln library is not used to avoid
+# the enternal dependency. The sed script is used to edit certain nonportable
+# constructs in the LEX code, and the filename lex.yy.c is changed to lexyy.c
+# for portability reasons.
+
+find tok.l -newer lexyy.c -exec rm lexyy.c \;
+if test -f lexyy.c; then\
+ $CC -c $HSI_CF -w lexyy.c;\
+else\
+ lex tok.l;\
+ sed -f lex.sed lex.yy.c > lexyy.c; rm lex.yy.c;\
+ $CC -c $HSI_CF -w lexyy.c;\
+fi
+
+$CC -c -g $HSI_CF generic.c chario.c yywrap.c
+$CC $HSI_LF generic.o lexyy.o chario.o yywrap.o $HSI_LIBS -o generic.e
+
+
+echo "Running .... "
+./generic.e -k -t csilrdx /tmp/acht.gx