|
|
1.1 ! root 1: /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */ ! 2: /* $Header: b2err.c,v 1.1 84/06/28 00:49:07 timo Exp $ */ ! 3: ! 4: /* B error message handling */ ! 5: #include "b.h" ! 6: #include "b0con.h" ! 7: #include "b1obj.h" ! 8: #include "b2err.h" ! 9: #include "b2scr.h" ! 10: #include "b2env.h" ! 11: #include "b2sem.h" /* for xeq */ ! 12: #include "b2syn.h" ! 13: #include "b2sig.h" ! 14: #include "b2fil.h" ! 15: ! 16: jmp_buf main_loop; ! 17: bool skipping; ! 18: ! 19: ! 20: #define Interactive ((cntxt == In_read || active_reads > 0) \ ! 21: ? read_interactive : interactive) ! 22: #define Errout (Interactive ? stderr : stdout) ! 23: #define Skip() {if (skipping) proceed();} ! 24: ! 25: Hidden Procedure Line() { ! 26: if (interactive || Errout == stdout) line(); ! 27: } ! 28: ! 29: Hidden Procedure errmess(m) string m; { ! 30: fprintf(Errout, m); ! 31: } ! 32: ! 33: Hidden Procedure core_dump() { ! 34: errmess("*** Core-dump for inspection purposes: "); ! 35: fflush(stdout); ! 36: dump(); ! 37: } ! 38: ! 39: Visible Procedure bye(ex) int ex; { ! 40: at_nwl= Yes; ! 41: putprmnv(); ! 42: exit(ex); ! 43: } ! 44: ! 45: Hidden Procedure prname(name) value name; { ! 46: value ch; int k, len; ! 47: if (Is_text(name)) { ! 48: len= length(name); ! 49: k_Over_len { ! 50: ch= thof(k+1, name); ! 51: putc(charval(ch), Errout); ! 52: release(ch); ! 53: } ! 54: } else errmess("???"); ! 55: } ! 56: ! 57: value erruname= Vnil; literal errutype; intlet errlino= 0; ! 58: ! 59: Hidden intlet display_line(ax) txptr ax; { ! 60: /*displays the line that tx is in, and returns the column number that ! 61: ax is at. ! 62: */ ! 63: txptr lx= fcol(); intlet ap= -1, p= 0; char c; ! 64: while (!Eol(lx) && Char(lx) != Eotc) { ! 65: if (lx == ax) ap= p; ! 66: c= *lx++; ! 67: if (c == '\t') { ! 68: do { putc(' ', Errout); } while (((++p)%4)!=0); ! 69: } else { putc(c, Errout); p++; } ! 70: } ! 71: putc('\n', Errout); ! 72: if (ap < 0) return p; ! 73: return ap; ! 74: } ! 75: ! 76: Hidden Procedure prline(at) bool at; { ! 77: txptr ax= tx; intlet p, ap; ! 78: if (cntxt == In_read || cntxt == In_value) errmess(" in your "); ! 79: else if (cntxt != In_formal) ! 80: fprintf(Errout, " in line %d of your ", lino); ! 81: switch (cntxt) { ! 82: case In_command: errmess("command"); break; ! 83: case In_read: errmess("expression to be read"); break; ! 84: case In_value: errmess("edited value"); break; ! 85: case In_unit:errmess("unit "); prname(uname); ! 86: erruname= uname; errutype= utype; errlino= lino; ! 87: break; ! 88: case In_formal: break; ! 89: case In_prmnv: errmess("permanent environment"); break; ! 90: default: errmess("???\n"); return; ! 91: } ! 92: errmess("\n "); ! 93: if (!at) do ax--; while (Space(Char(ax))); ! 94: ap= display_line(ax)+4; ! 95: for (p= 0; p < ap; p++) putc(' ', Errout); ! 96: putc('^', Errout); ! 97: putc('\n', Errout); ! 98: } ! 99: ! 100: Hidden Procedure show_where(at, wia) bool at, wia; { ! 101: context cc; ! 102: if (cntxt == In_formal) { ! 103: sv_context(&cc); ! 104: set_context(&how_context); ! 105: prline(No); ! 106: set_context(&cc); ! 107: errmess("originating from your command"); ! 108: } ! 109: prline(at); ! 110: if (!Interactive || !wia) { ! 111: fprintf(Errout, ! 112: "(detected after reading %d input line%s of your input file ", ! 113: alino, alino == 1 ? "" : "s"); ! 114: if (iname == Vnil) errmess("standard input)"); ! 115: else { ! 116: prname(iname); ! 117: errmess(")"); ! 118: } ! 119: putc('\n', Errout); ! 120: } ! 121: } ! 122: ! 123: Visible Procedure syserr(m) string m; { ! 124: Line(); ! 125: errmess("*** Sorry, B system malfunction"); ! 126: show_where(Yes, Yes); ! 127: fprintf(Errout, "*** The problem is: %s\n", m); ! 128: errmess("*** Please save pertinent data for inspection by B guru\n"); ! 129: core_dump(); ! 130: } ! 131: ! 132: Visible Procedure memexh() { ! 133: Line(); ! 134: errmess("*** Sorry, memory exhausted"); ! 135: show_where(Yes, Yes); ! 136: errmess("*** Get your boss to buy a larger computer\n"); ! 137: core_dump(); ! 138: } ! 139: ! 140: Hidden Procedure fix_files() { ! 141: if (ifile != stdin) fclose(ifile); ! 142: if (f_interactive(stdin) || filtered) { ! 143: interactive= Yes; ! 144: release(iname); ! 145: iname = Vnil; ! 146: ifile = stdin; ! 147: Eof= Eof0= No; ! 148: } ! 149: } ! 150: ! 151: Hidden Procedure proceed() { ! 152: if (cntxt == In_prmnv) exit(-1); ! 153: else if (cntxt == In_read && read_interactive) { ! 154: errmess("*** please enter a valid expression instead\n"); ! 155: longjmp(reading[active_reads-1], 1); ! 156: } else if (active_reads > 0 && read_interactive) { ! 157: errmess("*** please enter a suitable expression instead\n"); ! 158: longjmp(reading[active_reads-1], 1); ! 159: } else { ! 160: if (cntxt == In_value) fix_files(); ! 161: longjmp(main_loop, 1); ! 162: } ! 163: } ! 164: ! 165: Hidden Procedure message(m1, m2, m3, at) string m1, m2, m3; bool at; { ! 166: Skip(); Line(); ! 167: errmess(m1); ! 168: show_where(at, Yes); ! 169: fprintf(Errout, "*** The problem is: %s%s\n", m2, m3); ! 170: proceed(); ! 171: } ! 172: ! 173: Visible Procedure error(m) string m; { ! 174: message("*** Cannot cope with problem", m, "", No); ! 175: } ! 176: ! 177: Visible Procedure parerr(m, ss) string m, ss; { ! 178: message("*** There's something I don't understand", m, ss, Yes); ! 179: } ! 180: ! 181: Visible Procedure pprerr(m, ss) string m, ss; { ! 182: message("*** There's something I don't understand", m, ss, No); ! 183: } ! 184: ! 185: Visible Procedure checkerr() { ! 186: Line(); ! 187: errmess("*** Your check failed"); ! 188: show_where(No, Yes); ! 189: longjmp(main_loop, 1); ! 190: } ! 191: ! 192: Visible Procedure int_signal(in_read) bool in_read; { ! 193: if (cntxt == In_prmnv) exit(-1); ! 194: else if (interactive) { ! 195: interrupt(in_read); ! 196: if (!in_read) accept_int(); ! 197: longjmp(main_loop, 1); ! 198: } else { ! 199: fix_files(); ! 200: if (interactive) { ! 201: interrupt(in_read); ! 202: if (!in_read) accept_int(); ! 203: process(); ! 204: } else bye(1); ! 205: } ! 206: } ! 207: ! 208: Hidden Procedure interrupt(in_read) bool in_read; { ! 209: if (!in_read) at_nwl= No; ! 210: Line(); ! 211: errmess(in_read ? "*** READ aborted\n" : "*** interrupted\n"); ! 212: if (filtered) errmess("\177"); ! 213: if (cntxt == In_read || active_reads > 0) set_context(&read_context); ! 214: /* show_where(No, was_interactive); */ ! 215: } ! 216: ! 217: bool bugs= No; ! 218: bool tracing= No; ! 219: ! 220: Visible Procedure debug(m) string m; { ! 221: if (bugs) { ! 222: Line(); ! 223: fprintf(Errout, "*** Debugging (xeq = %s, cur_ilev = %d)", ! 224: xeq ? "Yes" : "No", cur_ilev); ! 225: show_where(Yes, Yes); ! 226: fprintf(Errout, "*** %s\n", m); ! 227: } ! 228: } ! 229: ! 230: Visible Procedure trace() { ! 231: VOID display_line(tx); ! 232: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.