BSD 4_4_Lite1 development
authorCSRG <csrg@ucbvax.Berkeley.EDU>
Thu, 14 Feb 1991 11:45:20 +0000 (03:45 -0800)
committerCSRG <csrg@ucbvax.Berkeley.EDU>
Thu, 14 Feb 1991 11:45:20 +0000 (03:45 -0800)
Work on file usr/src/kerberosIV/compile_et/compile_et.c
Work on file usr/src/kerberosIV/compile_et/error_table.y

Synthesized-from: CSRG/cd2/4.4BSD-Lite1

usr/src/kerberosIV/compile_et/compile_et.c [new file with mode: 0644]
usr/src/kerberosIV/compile_et/error_table.y [new file with mode: 0644]

diff --git a/usr/src/kerberosIV/compile_et/compile_et.c b/usr/src/kerberosIV/compile_et/compile_et.c
new file mode 100644 (file)
index 0000000..4bdcaf0
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+ *
+ * Copyright 1986, 1987 by MIT Student Information Processing Board
+ *
+ * For copyright info, see "mit-sipb-copyright.h".
+ *
+ */
+
+#include <stdio.h>
+#include <sys/file.h>
+#include <strings.h>
+#include <sys/param.h>
+#include "mit-sipb-copyright.h"
+
+static char copyright[] = "Copyright 1987 by MIT Student Information Processing Board";
+
+extern char *gensym();
+extern char *current_token;
+extern int table_number, current;
+char buffer[BUFSIZ];
+char *table_name = (char *)NULL;
+FILE *hfile, *cfile;
+     
+/* C library */
+extern int errno;
+     
+/* lex stuff */
+extern FILE *yyin;
+extern int yylineno;
+     
+/* pathnames */
+char c_file[MAXPATHLEN];       /* temporary file */
+char h_file[MAXPATHLEN];       /* output */
+char o_file[MAXPATHLEN];       /* output */
+char et_file[MAXPATHLEN];      /* input */
+
+main(argc, argv)
+     int argc;
+     char **argv;
+{
+     register char *p;
+     int n_flag = 0, debug = 0;
+     
+     while (argc > 2) {
+         register char *arg, ch;
+         arg = argv[--argc];
+         if (strlen(arg) != 2 || arg[0] != '-')
+              goto usage;
+         ch = arg[1];
+         if (ch == 'n')
+              n_flag++;
+         else if (ch == 'd')
+              debug++;
+         else
+              goto usage;
+     }
+
+     if (argc != 2) {
+     usage:
+         fprintf(stderr, "Usage:  %s et_file [-n]\n", argv[0]);
+         exit(1);
+     }
+     
+     strcpy(et_file, argv[1]);
+     p = rindex(et_file, '/');
+     if (p == (char *)NULL)
+         p = et_file;
+     else
+         p++;
+     p = rindex(p, '.');
+     if (!strcmp(p, ".et"))
+         *++p = '\0';
+     else {
+         if (!p)
+              p = et_file;
+         while (*p)
+              p++;
+         *p++ = '.';
+         *p = '\0';
+     }
+     /* p points at null where suffix should be */
+     strcpy(p, "et.c");
+     strcpy(c_file, et_file);
+     p[0] = 'h';
+     p[1] = '\0';
+     strcpy(h_file, et_file);
+     p[0] = 'o';
+     strcpy(o_file, et_file);
+     p[0] = 'e';
+     p[1] = 't';
+     p[2] = '\0';
+
+     yyin = fopen(et_file, "r");
+     if (!yyin) {
+         perror(et_file);
+         exit(1);
+     }
+     
+     hfile = fopen(h_file, "w");
+     if (hfile == (FILE *)NULL) {
+         perror(h_file);
+         exit(1);
+     }
+     
+     cfile = fopen(c_file, "w");
+     if (cfile == (FILE *)NULL) {
+         perror("Can't open temp file");
+         exit(1);
+     }
+     
+     /* parse it */
+     fputs("#define NULL 0\n", cfile);
+     fputs("static char *_et[] = {\n", cfile);
+     
+     yyparse();
+     fclose(yyin);             /* bye bye input file */
+     
+     fputs("\t(char *)0\n};\n", cfile);
+     fputs("extern int init_error_table();\n\n", cfile);
+     fprintf(cfile, "int %s_err_base = %d;\n\n", table_name, table_number);
+     fprintf(cfile, "int\ninit_%s_err_tbl()\n", table_name);
+     fprintf(cfile, "{\n\treturn(init_error_table(_et, %d, %d));\n}\n",
+            table_number, current);
+     fclose(cfile);
+     
+     fputs("extern int init_", hfile);
+     fputs(table_name, hfile);
+     fputs("_err_tbl();\nextern int ", hfile);
+     fputs(table_name, hfile);
+     fputs("_err_base;\n", hfile);
+     fclose(hfile);            /* bye bye hfile */
+     
+     if (n_flag)
+         exit(0);
+
+     if (!fork()) {
+         p = rindex(c_file, '/');
+         if (p) {
+              *p++ = '\0';
+              chdir(c_file);
+         }
+         else
+              p = c_file;
+         execlp("cc", "cc", "-c", "-R", "-O", p, 0);
+         perror("cc");
+         exit(1);
+     }
+     else wait(0);
+
+     if (!debug)
+         (void) unlink(c_file);
+     /* make it .o file name */
+     c_file[strlen(c_file)-1] = 'o';
+     if (!fork()) {
+         execlp("cp", "cp", c_file, o_file, 0);
+         perror("cp");
+         exit(1);
+     }
+     else wait(0);
+     if (!debug)
+         (void) unlink(c_file);
+
+     exit(0);
+}
+
+yyerror(s)
+     char *s;
+{
+     fputs(s, stderr);
+     fprintf(stderr, "\nLine number %d; last token was '%s'\n",
+            yylineno, current_token);
+}
diff --git a/usr/src/kerberosIV/compile_et/error_table.y b/usr/src/kerberosIV/compile_et/error_table.y
new file mode 100644 (file)
index 0000000..bdaa133
--- /dev/null
@@ -0,0 +1,208 @@
+%{
+#include <stdio.h>
+#include <stdlib.h>
+char *str_concat(), *ds(), *quote();
+char *current_token = (char *)NULL;
+extern char *table_name;
+%}
+%union {
+       char *dynstr;
+}
+
+%token ERROR_TABLE ERROR_CODE_ENTRY END
+%token <dynstr> STRING QUOTED_STRING
+%type <dynstr> ec_name description table_id
+%{
+%}
+%start error_table
+%%
+
+error_table    :       ERROR_TABLE table_id error_codes END
+                       { table_name = ds($2);
+                         current_token = table_name;
+                         put_ecs(); }
+               ;
+
+table_id       :       STRING
+                       { current_token = $1;
+                         set_table_num($1);
+                         $$ = $1; }
+               ;
+
+error_codes    :       error_codes ec_entry
+               |       ec_entry
+               ;
+
+ec_entry       :       ERROR_CODE_ENTRY ec_name ',' description
+                       { add_ec($2, $4);
+                         free($2);
+                         free($4); }
+               |       ERROR_CODE_ENTRY ec_name '=' STRING ',' description
+                       { add_ec_val($2, $4, $6);
+                         free($2);
+                         free($4);
+                         free($6);
+                       }
+               ;
+
+ec_name                :       STRING
+                       { $$ = ds($1);
+                         current_token = $$; }
+               ;
+
+description    :       QUOTED_STRING
+                       { $$ = ds($1);
+                         current_token = $$; }
+               ;
+
+%%
+/*
+ *
+ * Copyright 1986, 1987 by the MIT Student Information Processing Board
+ *
+ * For copyright info, see mit-sipb-copyright.h.
+ */
+
+#include <strings.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include "error_table.h"
+#include "mit-sipb-copyright.h"
+
+extern FILE *hfile, *cfile;
+
+static long gensym_n = 0;
+char *
+gensym(x)
+       char *x;
+{
+       char *symbol;
+       if (!gensym_n) {
+               struct timeval tv;
+               struct timezone tzp;
+               gettimeofday(&tv, &tzp);
+               gensym_n = (tv.tv_sec%10000)*100 + tv.tv_usec/10000;
+       }
+       symbol = malloc(32 * sizeof(char));
+       gensym_n++;
+       sprintf(symbol, "et%ld", gensym_n);
+       return(symbol);
+}
+
+char *
+ds(string)
+       char *string;
+{
+       char *rv;
+       rv = malloc(strlen(string)+1);
+       strcpy(rv, string);
+       return(rv);
+}
+
+char *
+quote(string)
+       char *string;
+{
+       char *rv;
+       rv = malloc(strlen(string)+3);
+       strcpy(rv, "\"");
+       strcat(rv, string);
+       strcat(rv, "\"");
+       return(rv);
+}
+
+int table_number;
+int current = 0;
+char **error_codes = (char **)NULL;
+
+add_ec(name, description)
+       char *name, *description;
+{
+       fprintf(cfile, "\t\"%s\",\n", description);
+       if (error_codes == (char **)NULL) {
+               error_codes = (char **)malloc(sizeof(char *));
+               *error_codes = (char *)NULL;
+       }
+       error_codes = (char **)realloc((char *)error_codes,
+                                      (current + 2)*sizeof(char *));
+       error_codes[current++] = ds(name);
+       error_codes[current] = (char *)NULL;
+}
+
+add_ec_val(name, val, description)
+       char *name, *val, *description;
+{
+       int ncurrent = atoi(val);
+       if (ncurrent < current) {
+               printf("Error code %s (%d) out of order", name,
+                      current);
+               return;
+       }
+      
+       while (ncurrent > current)
+            fputs("\t(char *)NULL,\n", cfile), current++;
+       
+       fprintf(cfile, "\t\"%s\",\n", description);
+       if (error_codes == (char **)NULL) {
+               error_codes = (char **)malloc(sizeof(char *));
+               *error_codes = (char *)NULL;
+       }
+       error_codes = (char **)realloc((char *)error_codes,
+                                      (current + 2)*sizeof(char *));
+       error_codes[current++] = ds(name);
+       error_codes[current] = (char *)NULL;
+} 
+
+put_ecs()
+{
+       int i;
+       for (i = 0; i < current; i++) {
+            if (error_codes[i] != (char *)NULL)
+                 fprintf(hfile, "#define %-40s ((%s)%d)\n",
+                         error_codes[i], ERROR_CODE, table_number + i);
+       }
+}
+
+/*
+ * char_to_num -- maps letters and numbers into a small numbering space
+ *     uppercase ->  1-26
+ *     lowercase -> 27-52
+ *     digits    -> 53-62
+ *     underscore-> 63
+ */
+int
+char_to_num(c)
+       char c;
+{
+       if (isupper(c))
+               return(c-'A'+1);
+       else if (islower(c))
+               return(c-'a'+27);
+       else if (isdigit(c))
+               return(c-'0'+53);
+       else {
+               fprintf(stderr, "Illegal character in name: %c\n", c);
+               exit(1);
+               /*NOTREACHED*/
+       }
+}
+
+set_table_num(string)
+       char *string;
+{
+       if (strlen(string) > 4) {
+               fprintf(stderr, "Table name %s too long, truncated ",
+                       string);
+               string[4] = '\0';
+               fprintf(stderr, "to %s\n", string);
+       }
+       while (*string != '\0') {
+               table_number = (table_number << BITS_PER_CHAR)
+                       + char_to_num(*string);
+               string++;
+       }
+       table_number = table_number << ERRCODE_RANGE;
+}
+
+#include "et_lex.lex.c"