|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: static char sccsid[] = "@(#)errorsubr.c 5.4 (Berkeley) 6/1/90"; ! 22: #endif /* not lint */ ! 23: ! 24: #include <stdio.h> ! 25: #include <ctype.h> ! 26: #include "error.h" ! 27: /* ! 28: * Arrayify a list of rules ! 29: */ ! 30: arrayify(e_length, e_array, header) ! 31: int *e_length; ! 32: Eptr **e_array; ! 33: Eptr header; ! 34: { ! 35: reg Eptr errorp; ! 36: reg Eptr *array; ! 37: reg int listlength; ! 38: reg int listindex; ! 39: ! 40: for (errorp = header, listlength = 0; ! 41: errorp; errorp = errorp->error_next, listlength++) ! 42: continue; ! 43: array = (Eptr*)Calloc(listlength+1, sizeof (Eptr)); ! 44: for(listindex = 0, errorp = header; ! 45: listindex < listlength; ! 46: listindex++, errorp = errorp->error_next){ ! 47: array[listindex] = errorp; ! 48: errorp->error_position = listindex; ! 49: } ! 50: array[listindex] = (Eptr)0; ! 51: *e_length = listlength; ! 52: *e_array = array; ! 53: } ! 54: ! 55: /*VARARGS1*/ ! 56: error(msg, a1, a2, a3) ! 57: char *msg; ! 58: { ! 59: fprintf(stderr, "Error: "); ! 60: fprintf(stderr, msg, a1, a2, a3); ! 61: fprintf(stderr, "\n"); ! 62: fflush(stdout); ! 63: fflush(stderr); ! 64: exit(6); ! 65: } ! 66: /*ARGSUSED*/ ! 67: char *Calloc(nelements, size) ! 68: int nelements; ! 69: int size; ! 70: { ! 71: char *back; ! 72: if ( (back = (char *)calloc(nelements, size)) == (char *)NULL){ ! 73: error("Ran out of memory.\n"); ! 74: exit(1); ! 75: } ! 76: return(back); ! 77: } ! 78: ! 79: char *strsave(instring) ! 80: char *instring; ! 81: { ! 82: char *outstring; ! 83: (void)strcpy(outstring = (char *)Calloc(1, strlen(instring) + 1), ! 84: instring); ! 85: return(outstring); ! 86: } ! 87: /* ! 88: * find the position of a given character in a string ! 89: * (one based) ! 90: */ ! 91: int position(string, ch) ! 92: reg char *string; ! 93: reg char ch; ! 94: { ! 95: reg int i; ! 96: if (string) ! 97: for (i=1; *string; string++, i++){ ! 98: if (*string == ch) ! 99: return(i); ! 100: } ! 101: return(-1); ! 102: } ! 103: /* ! 104: * clobber the first occurance of ch in string by the new character ! 105: */ ! 106: char *substitute(string, chold, chnew) ! 107: char *string; ! 108: char chold, chnew; ! 109: { ! 110: reg char *cp = string; ! 111: ! 112: if (cp) ! 113: while (*cp){ ! 114: if (*cp == chold){ ! 115: *cp = chnew; ! 116: break; ! 117: } ! 118: cp++; ! 119: } ! 120: return(string); ! 121: } ! 122: ! 123: char lastchar(string) ! 124: char *string; ! 125: { ! 126: int length; ! 127: if (string == 0) return('\0'); ! 128: length = strlen(string); ! 129: if (length >= 1) ! 130: return(string[length-1]); ! 131: else ! 132: return('\0'); ! 133: } ! 134: ! 135: char firstchar(string) ! 136: char *string; ! 137: { ! 138: if (string) ! 139: return(string[0]); ! 140: else ! 141: return('\0'); ! 142: } ! 143: ! 144: char next_lastchar(string) ! 145: char *string; ! 146: { ! 147: int length; ! 148: if (string == 0) return('\0'); ! 149: length = strlen(string); ! 150: if (length >= 2) ! 151: return(string[length - 2]); ! 152: else ! 153: return('\0'); ! 154: } ! 155: ! 156: clob_last(string, newstuff) ! 157: char *string, newstuff; ! 158: { ! 159: int length = 0; ! 160: if (string) ! 161: length = strlen(string); ! 162: if (length >= 1) ! 163: string[length - 1] = newstuff; ! 164: } ! 165: ! 166: /* ! 167: * parse a string that is the result of a format %s(%d) ! 168: * return TRUE if this is of the proper format ! 169: */ ! 170: boolean persperdexplode(string, r_perd, r_pers) ! 171: char *string; ! 172: char **r_perd, **r_pers; ! 173: { ! 174: reg char *cp; ! 175: int length = 0; ! 176: ! 177: if (string) ! 178: length = strlen(string); ! 179: if ( (length >= 4) ! 180: && (string[length - 1] == ')' ) ){ ! 181: for (cp = &string[length - 2]; ! 182: (isdigit(*cp)) && (*cp != '('); ! 183: --cp) ! 184: continue; ! 185: if (*cp == '('){ ! 186: string[length - 1] = '\0'; /* clobber the ) */ ! 187: *r_perd = strsave(cp+1); ! 188: string[length - 1] = ')'; ! 189: *cp = '\0'; /* clobber the ( */ ! 190: *r_pers = strsave(string); ! 191: *cp = '('; ! 192: return(TRUE); ! 193: } ! 194: } ! 195: return(FALSE); ! 196: } ! 197: /* ! 198: * parse a quoted string that is the result of a format \"%s\"(%d) ! 199: * return TRUE if this is of the proper format ! 200: */ ! 201: boolean qpersperdexplode(string, r_perd, r_pers) ! 202: char *string; ! 203: char **r_perd, **r_pers; ! 204: { ! 205: reg char *cp; ! 206: int length = 0; ! 207: ! 208: if (string) ! 209: length = strlen(string); ! 210: if ( (length >= 4) ! 211: && (string[length - 1] == ')' ) ){ ! 212: for (cp = &string[length - 2]; ! 213: (isdigit(*cp)) && (*cp != '('); ! 214: --cp) ! 215: continue; ! 216: if (*cp == '(' && *(cp - 1) == '"'){ ! 217: string[length - 1] = '\0'; ! 218: *r_perd = strsave(cp+1); ! 219: string[length - 1] = ')'; ! 220: *(cp - 1) = '\0'; /* clobber the " */ ! 221: *r_pers = strsave(string + 1); ! 222: *(cp - 1) = '"'; ! 223: return(TRUE); ! 224: } ! 225: } ! 226: return(FALSE); ! 227: } ! 228: ! 229: static char cincomment[] = CINCOMMENT; ! 230: static char coutcomment[] = COUTCOMMENT; ! 231: static char fincomment[] = FINCOMMENT; ! 232: static char foutcomment[] = FOUTCOMMENT; ! 233: static char newline[] = NEWLINE; ! 234: static char piincomment[] = PIINCOMMENT; ! 235: static char pioutcomment[] = PIOUTCOMMENT; ! 236: static char lispincomment[] = LISPINCOMMENT; ! 237: static char riincomment[] = RIINCOMMENT; ! 238: static char rioutcomment[] = RIOUTCOMMENT; ! 239: static char troffincomment[] = TROFFINCOMMENT; ! 240: static char troffoutcomment[] = TROFFOUTCOMMENT; ! 241: static char mod2incomment[] = MOD2INCOMMENT; ! 242: static char mod2outcomment[] = MOD2OUTCOMMENT; ! 243: ! 244: struct lang_desc lang_table[] = { ! 245: /*INUNKNOWN 0*/ "unknown", cincomment, coutcomment, ! 246: /*INCPP 1*/ "cpp", cincomment, coutcomment, ! 247: /*INCC 2*/ "cc", cincomment, coutcomment, ! 248: /*INAS 3*/ "as", ASINCOMMENT, newline, ! 249: /*INLD 4*/ "ld", cincomment, coutcomment, ! 250: /*INLINT 5*/ "lint", cincomment, coutcomment, ! 251: /*INF77 6*/ "f77", fincomment, foutcomment, ! 252: /*INPI 7*/ "pi", piincomment, pioutcomment, ! 253: /*INPC 8*/ "pc", piincomment, pioutcomment, ! 254: /*INFRANZ 9*/ "franz",lispincomment, newline, ! 255: /*INLISP 10*/ "lisp", lispincomment, newline, ! 256: /*INVAXIMA 11*/ "vaxima",lispincomment,newline, ! 257: /*INRATFOR 12*/ "ratfor",fincomment, foutcomment, ! 258: /*INLEX 13*/ "lex", cincomment, coutcomment, ! 259: /*INYACC 14*/ "yacc", cincomment, coutcomment, ! 260: /*INAPL 15*/ "apl", ".lm", newline, ! 261: /*INMAKE 16*/ "make", ASINCOMMENT, newline, ! 262: /*INRI 17*/ "ri", riincomment, rioutcomment, ! 263: /*INTROFF 18*/ "troff",troffincomment,troffoutcomment, ! 264: /*INMOD2 19*/ "mod2", mod2incomment, mod2outcomment, ! 265: 0, 0, 0 ! 266: }; ! 267: ! 268: printerrors(look_at_subclass, errorc, errorv) ! 269: boolean look_at_subclass; ! 270: int errorc; ! 271: Eptr errorv[]; ! 272: { ! 273: reg int i; ! 274: reg Eptr errorp; ! 275: ! 276: for (errorp = errorv[i = 0]; i < errorc; errorp = errorv[++i]){ ! 277: if (errorp->error_e_class == C_IGNORE) ! 278: continue; ! 279: if (look_at_subclass && errorp->error_s_class == C_DUPL) ! 280: continue; ! 281: printf("Error %d, (%s error) [%s], text = \"", ! 282: i, ! 283: class_table[errorp->error_e_class], ! 284: lang_table[errorp->error_language].lang_name); ! 285: wordvprint(stdout,errorp->error_lgtext,errorp->error_text); ! 286: printf("\"\n"); ! 287: } ! 288: } ! 289: ! 290: wordvprint(fyle, wordc, wordv) ! 291: FILE *fyle; ! 292: int wordc; ! 293: char *wordv[]; ! 294: { ! 295: int i; ! 296: char *sep = ""; ! 297: ! 298: for(i = 0; i < wordc; i++) ! 299: if (wordv[i]) { ! 300: fprintf(fyle, "%s%s",sep,wordv[i]); ! 301: sep = " "; ! 302: } ! 303: } ! 304: ! 305: /* ! 306: * Given a string, parse it into a number of words, and build ! 307: * a wordc wordv combination pointing into it. ! 308: */ ! 309: wordvbuild(string, r_wordc, r_wordv) ! 310: char *string; ! 311: int *r_wordc; ! 312: char ***r_wordv; ! 313: { ! 314: reg char *cp; ! 315: char *saltedbuffer; ! 316: char **wordv; ! 317: int wordcount; ! 318: int wordindex; ! 319: ! 320: saltedbuffer = strsave(string); ! 321: for (wordcount = 0, cp = saltedbuffer; *cp; wordcount++){ ! 322: while (*cp && isspace(*cp)) ! 323: cp++; ! 324: if (*cp == 0) ! 325: break; ! 326: while (!isspace(*cp)) ! 327: cp++; ! 328: } ! 329: wordv = (char **)Calloc(wordcount + 1, sizeof (char *)); ! 330: for (cp=saltedbuffer,wordindex=0; wordcount; wordindex++,--wordcount){ ! 331: while (*cp && isspace(*cp)) ! 332: cp++; ! 333: if (*cp == 0) ! 334: break; ! 335: wordv[wordindex] = cp; ! 336: while(!isspace(*cp)) ! 337: cp++; ! 338: *cp++ = '\0'; ! 339: } ! 340: if (wordcount != 0) ! 341: error("Initial miscount of the number of words in a line\n"); ! 342: wordv[wordindex] = (char *)0; ! 343: #ifdef FULLDEBUG ! 344: for (wordcount = 0; wordcount < wordindex; wordcount++) ! 345: printf("Word %d = \"%s\"\n", wordcount, wordv[wordcount]); ! 346: printf("\n"); ! 347: #endif ! 348: *r_wordc = wordindex; ! 349: *r_wordv = wordv; ! 350: } ! 351: /* ! 352: * Compare two 0 based wordvectors ! 353: */ ! 354: int wordvcmp(wordv1, wordc, wordv2) ! 355: char **wordv1; ! 356: int wordc; ! 357: char **wordv2; ! 358: { ! 359: reg int i; ! 360: int back; ! 361: for (i = 0; i < wordc; i++){ ! 362: if (wordv1[i] == 0 || wordv2[i] == 0) ! 363: return(-1); ! 364: if (back = strcmp(wordv1[i], wordv2[i])){ ! 365: return(back); ! 366: } ! 367: } ! 368: return(0); /* they are equal */ ! 369: } ! 370: ! 371: /* ! 372: * splice a 0 basedword vector onto the tail of a ! 373: * new wordv, allowing the first emptyhead slots to be empty ! 374: */ ! 375: char **wordvsplice(emptyhead, wordc, wordv) ! 376: int emptyhead; ! 377: int wordc; ! 378: char **wordv; ! 379: { ! 380: reg char **nwordv; ! 381: int nwordc = emptyhead + wordc; ! 382: reg int i; ! 383: ! 384: nwordv = (char **)Calloc(nwordc, sizeof (char *)); ! 385: for (i = 0; i < emptyhead; i++) ! 386: nwordv[i] = 0; ! 387: for(i = emptyhead; i < nwordc; i++){ ! 388: nwordv[i] = wordv[i-emptyhead]; ! 389: } ! 390: return(nwordv); ! 391: } ! 392: /* ! 393: * plural'ize and verb forms ! 394: */ ! 395: static char *S = "s"; ! 396: static char *N = ""; ! 397: char *plural(n) ! 398: int n; ! 399: { ! 400: return( n > 1 ? S : N); ! 401: } ! 402: char *verbform(n) ! 403: int n; ! 404: { ! 405: return( n > 1 ? N : S); ! 406: } ! 407:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.