|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. The Berkeley software License Agreement ! 4: * specifies the terms and conditions for redistribution. ! 5: */ ! 6: ! 7: #ifndef lint ! 8: char copyright[] = ! 9: "@(#) Copyright (c) 1980 Regents of the University of California.\n\ ! 10: All rights reserved.\n"; ! 11: #endif not lint ! 12: ! 13: #ifndef lint ! 14: static char sccsid[] = "@(#)csfix.c 6.2 (Berkeley) 5/7/86"; ! 15: #endif not lint ! 16: ! 17: #include <stdio.h> ! 18: /* ! 19: * csfix - fix constant spacing for error message flags in troff ! 20: * ! 21: * Bill Joy UCB September 11, 1977 ! 22: * ! 23: * This would be better written in snobol! ! 24: * ! 25: * Normally fixes error flags in a pi listing ! 26: * Optional - causes fixing of '---' and initial blank widthin a pxp profile. ! 27: */ ! 28: ! 29: char flag, dflag; ! 30: ! 31: main(argc, argv) ! 32: int argc; ! 33: char *argv[]; ! 34: { ! 35: ! 36: argc--, argv++; ! 37: if (argc > 0 && argv[0][0] == '-' && argv[0][1] == 'd') ! 38: dflag++, argc--, argv++; ! 39: if (argc > 0 && argv[0][0] == '-') ! 40: flag++, argc--, argv++; ! 41: if (argc != 0) { ! 42: write(2, "Usage: csfix\n", 13); ! 43: exit(1); ! 44: } ! 45: while (getline()) { ! 46: if (errline()) { ! 47: flag ? fixpxp() : reformat(); ! 48: continue; ! 49: } ! 50: if (flag) { ! 51: fixdigits(); ! 52: continue; ! 53: } ! 54: if (spwarn()) ! 55: continue; ! 56: if (nontriv()) ! 57: save(); ! 58: if (dflag) ! 59: fixdigits(); ! 60: else ! 61: putline(); ! 62: } ! 63: exit(0); ! 64: } ! 65: ! 66: char line[160], flagee[160], *digitty(); ! 67: ! 68: getline() ! 69: { ! 70: register char *cp, c; ! 71: ! 72: for (cp = line, c = getchar(); c != '\n' && c != EOF; c = getchar()) ! 73: *cp++ = c; ! 74: if (c == EOF) ! 75: return (0); ! 76: *cp = 0; ! 77: return (1); ! 78: } ! 79: ! 80: errline() ! 81: { ! 82: register int i; ! 83: register char *cp; ! 84: ! 85: for (cp = line; cp[0] && cp[1] && cp[2]; cp++) ! 86: if (cp[0] == '-' && cp[1] == '-' && cp[2] == '-') ! 87: return (1); ! 88: return (0); ! 89: } ! 90: ! 91: reformat() ! 92: { ! 93: register char *cp, c, *tail; ! 94: ! 95: printf("%2.2s", line); ! 96: if (line[0] != 'w') ! 97: printf("\\l'\\w`w `u-\\w`%2.2s`u '", line); ! 98: for (cp = line; *cp != 0 && *cp != '^'; cp++) ! 99: continue; ! 100: tail = cp + 1; ! 101: if (cp[-1] == '\b' && cp[-2] == '|') ! 102: cp -= 2; ! 103: c = flagee[cp - line]; ! 104: flagee[cp - line] = 0; ! 105: printf("\\l'\\w`%s`u-\\w`w `u\\&\\(rh'", flagee); ! 106: flagee[cp - line] = c; ! 107: if (c == '\0') ! 108: c = flagee[cp - line - 1]; ! 109: printf("\\l'(\\w`%c`u-\\w`^`u)/2 '", c); ! 110: printf("\\(ua"); ! 111: printf("\\l'(\\w`%c`u-\\w`^`u)/2 '", c); ! 112: printf("\\l'\\w`---`u\\&\\(rh'%s\n", tail+3); ! 113: } ! 114: ! 115: nontriv() ! 116: { ! 117: ! 118: switch (line[0]) { ! 119: case 'E': ! 120: case 'e': ! 121: case 'w': ! 122: case 's': ! 123: case 0: ! 124: return (0); ! 125: } ! 126: return (1); ! 127: } ! 128: ! 129: save() ! 130: { ! 131: ! 132: strcpy(flagee, line); ! 133: } ! 134: ! 135: putline() ! 136: { ! 137: ! 138: printf("%s\n", flag ? digitty(0) : line); ! 139: } ! 140: ! 141: spwarn() ! 142: { ! 143: ! 144: if (line[0] != ' ' || line[1] != ' ' || line[2] != 'w') ! 145: return (0); ! 146: printf(" \\l'(\\w`E`u-\\w`w`u)/2 'w\\l'(\\w`E`u-\\w`w`u)/2 '"); ! 147: printf(&line[3]); ! 148: printf("\n"); ! 149: return (1); ! 150: } ! 151: ! 152: fixpxp() ! 153: { ! 154: register char *cp; ! 155: ! 156: for (cp = line; *cp != '-'; cp++) ! 157: continue; ! 158: *cp = 0; ! 159: printf("%s\\l'\\w`\\0\\0\\0\\0`u-\\w`.`u\\&\\(rh'%s\n", digitty(1), cp + 3); ! 160: } ! 161: ! 162: char * ! 163: digitty(yup) ! 164: char yup; ! 165: { ! 166: register char *cp, *dp, *lp; ! 167: ! 168: for (lp = line; *lp && *lp != '|'; lp++) ! 169: continue; ! 170: if (yup == 0 && !*lp) ! 171: return (line); ! 172: for (cp = line, dp = flagee; cp < lp; cp++) ! 173: if (*cp == ' ') ! 174: *dp++ = '\\', *dp++ = '0'; ! 175: else ! 176: *dp++ = *cp; ! 177: strcpy(dp, cp); ! 178: return (flagee); ! 179: } ! 180: ! 181: fixdigits() ! 182: { ! 183: register char *cp, c; ! 184: ! 185: for (cp = line; *cp == ' ' || *cp >= '0' && *cp <= '9'; cp++) ! 186: continue; ! 187: c = *cp, *cp = 0; ! 188: digitty(1); ! 189: *cp = c; ! 190: printf("%s%s\n", flagee, cp); ! 191: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.