kernel tracing
[unix-history] / usr / src / usr.bin / error / subr.c
index f8ab91a..a964ce9 100644 (file)
@@ -1,31 +1,51 @@
-static char *sccsid = "@(#)subr.c      1.1 (Berkeley) %G%";
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)subr.c     5.3 (Berkeley) %G%";
+#endif /* not lint */
+
 #include <stdio.h>
 #include <ctype.h>
 #include "error.h"
 /*
 #include <stdio.h>
 #include <ctype.h>
 #include "error.h"
 /*
- *     go through and arrayify a list of rules
+ *     Arrayify a list of rules
  */
 arrayify(e_length, e_array, header)
  */
 arrayify(e_length, e_array, header)
-       int                     *e_length;
-       struct  error_desc      ***e_array;
-       struct  error_desc      *header;
+       int     *e_length;
+       Eptr    **e_array;
+       Eptr    header;
 {
 {
-       register        struct  error_desc      *errorp;
-       register        struct  error_desc      **array;
-       register        int     listlength;
-       register        int     listindex;
+       reg     Eptr    errorp;
+       reg     Eptr    *array;
+       reg     int     listlength;
+       reg     int     listindex;
 
        for (errorp = header, listlength = 0;
             errorp; errorp = errorp->error_next, listlength++)
                continue;
 
        for (errorp = header, listlength = 0;
             errorp; errorp = errorp->error_next, listlength++)
                continue;
-       array = (struct error_desc **)Calloc(listlength+1,sizeof (struct error_desc*));
+       array = (Eptr*)Calloc(listlength+1, sizeof (Eptr));
        for(listindex = 0, errorp = header;
            listindex < listlength;
            listindex++, errorp = errorp->error_next){
                array[listindex] = errorp;
                errorp->error_position = listindex;
        }
        for(listindex = 0, errorp = header;
            listindex < listlength;
            listindex++, errorp = errorp->error_next){
                array[listindex] = errorp;
                errorp->error_position = listindex;
        }
-       array[listindex] = (struct error_desc *)0;
+       array[listindex] = (Eptr)0;
        *e_length = listlength;
        *e_array = array;
 }
        *e_length = listlength;
        *e_array = array;
 }
@@ -58,7 +78,8 @@ char *strsave(instring)
        char    *instring;
 {
        char    *outstring;
        char    *instring;
 {
        char    *outstring;
-       strcpy(outstring = (char *)Calloc(1, strlen(instring) + 1), instring);
+       (void)strcpy(outstring = (char *)Calloc(1, strlen(instring) + 1),
+               instring);
        return(outstring);
 }
 /*
        return(outstring);
 }
 /*
@@ -66,10 +87,11 @@ char *strsave(instring)
  *             (one based)
  */
 int position(string, ch)
  *             (one based)
  */
 int position(string, ch)
-       register        char    *string;
-       register        char    ch;
+       reg     char    *string;
+       reg     char    ch;
 {
 {
-       register        int     i;
+       reg     int     i;
+       if (string)
        for (i=1; *string; string++, i++){
                if (*string == ch)
                        return(i);
        for (i=1; *string; string++, i++){
                if (*string == ch)
                        return(i);
@@ -83,8 +105,9 @@ char *substitute(string, chold, chnew)
        char    *string;
        char    chold, chnew;
 {
        char    *string;
        char    chold, chnew;
 {
-       register        char    *cp = string;
+       reg     char    *cp = string;
 
 
+       if (cp)
        while (*cp){
                if (*cp == chold){
                        *cp = chnew;
        while (*cp){
                if (*cp == chold){
                        *cp = chnew;
@@ -99,6 +122,7 @@ char lastchar(string)
        char    *string;
 {
        int     length;
        char    *string;
 {
        int     length;
+       if (string == 0) return('\0');
        length = strlen(string);
        if (length >= 1)
                return(string[length-1]);
        length = strlen(string);
        if (length >= 1)
                return(string[length-1]);
@@ -109,13 +133,17 @@ char lastchar(string)
 char firstchar(string)
        char    *string;
 {
 char firstchar(string)
        char    *string;
 {
-       return(string[0]);
+       if (string)
+               return(string[0]);
+       else
+               return('\0');
 }
 
 char   next_lastchar(string)
        char    *string;
 {
        int     length;
 }
 
 char   next_lastchar(string)
        char    *string;
 {
        int     length;
+       if (string == 0) return('\0');
        length = strlen(string);
        if (length >= 2)
                return(string[length - 2]);
        length = strlen(string);
        if (length >= 2)
                return(string[length - 2]);
@@ -126,8 +154,9 @@ char        next_lastchar(string)
 clob_last(string, newstuff)
        char    *string, newstuff;
 {
 clob_last(string, newstuff)
        char    *string, newstuff;
 {
-       int     length;
-       length = strlen(string);
+       int     length = 0;
+       if (string)
+               length = strlen(string);
        if (length >= 1)
                string[length - 1] = newstuff;
 }
        if (length >= 1)
                string[length - 1] = newstuff;
 }
@@ -140,10 +169,11 @@ boolean persperdexplode(string, r_perd, r_pers)
        char    *string;
        char    **r_perd, **r_pers;
 {
        char    *string;
        char    **r_perd, **r_pers;
 {
-       register        char    *cp;
-       int             length;
+       reg     char    *cp;
+               int     length = 0;
 
 
-       length = strlen(string);
+       if (string)
+               length = strlen(string);
        if (   (length >= 4)
            && (string[length - 1] == ')' ) ){
                for (cp = &string[length - 2];
        if (   (length >= 4)
            && (string[length - 1] == ')' ) ){
                for (cp = &string[length - 2];
@@ -170,10 +200,11 @@ boolean qpersperdexplode(string, r_perd, r_pers)
        char    *string;
        char    **r_perd, **r_pers;
 {
        char    *string;
        char    **r_perd, **r_pers;
 {
-       register        char    *cp;
-       int             length;
+       reg     char    *cp;
+               int     length = 0;
 
 
-       length = strlen(string);
+       if (string)
+               length = strlen(string);
        if (   (length >= 4)
            && (string[length - 1] == ')' ) ){
                for (cp = &string[length - 2];
        if (   (length >= 4)
            && (string[length - 1] == ')' ) ){
                for (cp = &string[length - 2];
@@ -203,6 +234,10 @@ static     char    pioutcomment[] = PIOUTCOMMENT;
 static char    lispincomment[] = LISPINCOMMENT;
 static char    riincomment[] = RIINCOMMENT;
 static char    rioutcomment[] = RIOUTCOMMENT;
 static char    lispincomment[] = LISPINCOMMENT;
 static char    riincomment[] = RIINCOMMENT;
 static char    rioutcomment[] = RIOUTCOMMENT;
+static char    troffincomment[] = TROFFINCOMMENT;
+static char    troffoutcomment[] = TROFFOUTCOMMENT;
+static char    mod2incomment[] = MOD2INCOMMENT;
+static char    mod2outcomment[] = MOD2OUTCOMMENT;
 
 struct lang_desc lang_table[] = {
        /*INUNKNOWN     0*/     "unknown", cincomment,  coutcomment,
 
 struct lang_desc lang_table[] = {
        /*INUNKNOWN     0*/     "unknown", cincomment,  coutcomment,
@@ -223,16 +258,19 @@ struct    lang_desc lang_table[] = {
        /*INAPL         15*/    "apl",  ".lm",         newline,
        /*INMAKE        16*/    "make", ASINCOMMENT,   newline,
        /*INRI          17*/    "ri",   riincomment,   rioutcomment,
        /*INAPL         15*/    "apl",  ".lm",         newline,
        /*INMAKE        16*/    "make", ASINCOMMENT,   newline,
        /*INRI          17*/    "ri",   riincomment,   rioutcomment,
+       /*INTROFF       18*/    "troff",troffincomment,troffoutcomment,
+       /*INMOD2        19*/    "mod2", mod2incomment, mod2outcomment,
                                0,      0,           0
 };
 
 printerrors(look_at_subclass, errorc, errorv)
        boolean look_at_subclass;
        int     errorc;
                                0,      0,           0
 };
 
 printerrors(look_at_subclass, errorc, errorv)
        boolean look_at_subclass;
        int     errorc;
-       struct  error_desc      *errorv[];
+       Eptr    errorv[];
 {
 {
-       register        int     i;
-       register        struct  error_desc      *errorp;
+       reg     int     i;
+       reg     Eptr    errorp;
+
        for (errorp = errorv[i = 0]; i < errorc; errorp = errorv[++i]){
                if (errorp->error_e_class == C_IGNORE)
                        continue;
        for (errorp = errorv[i = 0]; i < errorc; errorp = errorv[++i]){
                if (errorp->error_e_class == C_IGNORE)
                        continue;
@@ -253,11 +291,13 @@ wordvprint(fyle, wordc, wordv)
        char    *wordv[];
 {
        int     i;
        char    *wordv[];
 {
        int     i;
-       for(i = 0; i < wordc; i++){
-               fprintf(fyle, "%s",wordv[i]);
-               if (i != wordc - 1)
-                       fprintf(fyle, " ");
-       }
+       char *sep = "";
+
+       for(i = 0; i < wordc; i++)
+               if (wordv[i]) {
+                       fprintf(fyle, "%s%s",sep,wordv[i]);
+                       sep = " ";
+               }
 }
 
 /*
 }
 
 /*
@@ -269,11 +309,11 @@ wordvbuild(string, r_wordc, r_wordv)
        int     *r_wordc;
        char    ***r_wordv;
 {
        int     *r_wordc;
        char    ***r_wordv;
 {
-       register        char    *cp;
-                       char    *saltedbuffer;
-                       char    **wordv;
-                       int     wordcount;
-                       int     wordindex;
+       reg     char    *cp;
+               char    *saltedbuffer;
+               char    **wordv;
+               int     wordcount;
+               int     wordindex;
 
        saltedbuffer = strsave(string);
        for (wordcount = 0, cp = saltedbuffer; *cp; wordcount++){
 
        saltedbuffer = strsave(string);
        for (wordcount = 0, cp = saltedbuffer; *cp; wordcount++){
@@ -314,9 +354,11 @@ int wordvcmp(wordv1, wordc, wordv2)
        int     wordc;
        char    **wordv2;
 {
        int     wordc;
        char    **wordv2;
 {
-       register        int i;
-                       int     back;
+       reg     int i;
+               int     back;
        for (i = 0; i < wordc; i++){
        for (i = 0; i < wordc; i++){
+               if (wordv1[i] == 0 || wordv2[i] == 0)
+                               return(-1);
                if (back = strcmp(wordv1[i], wordv2[i])){
                        return(back);
                }
                if (back = strcmp(wordv1[i], wordv2[i])){
                        return(back);
                }
@@ -333,9 +375,9 @@ char        **wordvsplice(emptyhead, wordc, wordv)
        int     wordc;
        char    **wordv;
 {
        int     wordc;
        char    **wordv;
 {
-       register        char    **nwordv;
-       int     nwordc = emptyhead + wordc;
-       register        int     i;
+       reg     char    **nwordv;
+               int     nwordc = emptyhead + wordc;
+       reg     int     i;
 
        nwordv = (char **)Calloc(nwordc, sizeof (char *));
        for (i = 0; i < emptyhead; i++)
 
        nwordv = (char **)Calloc(nwordc, sizeof (char *));
        for (i = 0; i < emptyhead; i++)
@@ -345,3 +387,19 @@ char       **wordvsplice(emptyhead, wordc, wordv)
        }
        return(nwordv);
 }
        }
        return(nwordv);
 }
+/*
+ *     plural'ize and verb forms
+ */
+static char    *S = "s";
+static char    *N = "";
+char *plural(n)
+       int     n;
+{
+       return( n > 1 ? S : N);
+}
+char *verbform(n)
+       int     n;
+{
+       return( n > 1 ? N : S);
+}
+