kernel tracing
[unix-history] / usr / src / usr.bin / error / subr.c
index 30a95e7..a964ce9 100644 (file)
@@ -1,4 +1,24 @@
-static char *sccsid = "@(#)subr.c      1.2 (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"
@@ -71,6 +91,7 @@ int position(string, ch)
        reg     char    ch;
 {
        reg     int     i;
        reg     char    ch;
 {
        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);
@@ -86,6 +107,7 @@ char *substitute(string, chold, chnew)
 {
        reg     char    *cp = string;
 
 {
        reg     char    *cp = string;
 
+       if (cp)
        while (*cp){
                if (*cp == chold){
                        *cp = chnew;
        while (*cp){
                if (*cp == chold){
                        *cp = chnew;
@@ -100,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]);
@@ -110,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]);
@@ -127,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;
 }
@@ -142,9 +170,10 @@ boolean persperdexplode(string, r_perd, r_pers)
        char    **r_perd, **r_pers;
 {
        reg     char    *cp;
        char    **r_perd, **r_pers;
 {
        reg     char    *cp;
-               int     length;
+               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];
@@ -172,9 +201,10 @@ boolean qpersperdexplode(string, r_perd, r_pers)
        char    **r_perd, **r_pers;
 {
        reg     char    *cp;
        char    **r_perd, **r_pers;
 {
        reg     char    *cp;
-               int     length;
+               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];
@@ -204,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,
@@ -224,6 +258,8 @@ 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
 };
 
                                0,      0,           0
 };
 
@@ -255,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 = " ";
+               }
 }
 
 /*
 }
 
 /*
@@ -319,6 +357,8 @@ int wordvcmp(wordv1, wordc, wordv2)
        reg     int i;
                int     back;
        for (i = 0; i < wordc; i++){
        reg     int i;
                int     back;
        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);
                }