[9] | 1 | /* ELLE - Copyright 1982, 1987 by Ken Harrenstien, SRI International
|
---|
| 2 | * This software is quasi-public; it may be used freely with
|
---|
| 3 | * like software, but may NOT be sold or made part of licensed
|
---|
| 4 | * products without permission of the author.
|
---|
| 5 | */
|
---|
| 6 | /* EEERR - Error handling & testing routines
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 | #include "elle.h"
|
---|
| 10 |
|
---|
| 11 | #if V6
|
---|
| 12 | #include "eesigs.h"
|
---|
| 13 | #else
|
---|
| 14 | #include <signal.h>
|
---|
| 15 | #endif
|
---|
| 16 |
|
---|
| 17 | /* EFUN: "Hit Breakpoint" */
|
---|
| 18 | f_bkpt()
|
---|
| 19 | { clean_exit();
|
---|
| 20 | bpt();
|
---|
| 21 | set_tty();
|
---|
| 22 | }
|
---|
| 23 | bpt() {} /* Put a DDT/ADB breakpoint here */
|
---|
| 24 | |
---|
| 25 |
|
---|
| 26 | #if !(STRERROR) /* If strerror() not supported, we provide it. */
|
---|
| 27 | extern int sys_nerr; /* Max index into sys_errlist */
|
---|
| 28 | extern char *sys_errlist[];
|
---|
| 29 |
|
---|
| 30 | char *
|
---|
| 31 | strerror(num)
|
---|
| 32 | int num;
|
---|
| 33 | {
|
---|
| 34 | static char badbuf[30];
|
---|
| 35 | if (num > 0 && num <= sys_nerr)
|
---|
| 36 | return (sys_errlist[num]);
|
---|
| 37 | sprintf(badbuf, "unknown error %d", num);
|
---|
| 38 | return badbuf;
|
---|
| 39 | }
|
---|
| 40 | #endif /* -STRERROR */
|
---|
| 41 | |
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | errsbm(type,adr,str,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12)
|
---|
| 45 | register int type; /* Type, flags */
|
---|
| 46 | int (*adr)(); /* Addr called from */
|
---|
| 47 | char *str; /* Printf string */
|
---|
| 48 | { register struct buffer *b;
|
---|
| 49 | int oldttystate;
|
---|
| 50 |
|
---|
| 51 | oldttystate = clean_exit(); /* Ensure not in editing mode */
|
---|
| 52 | if(type == SBFERR) /* File overwrite error? A0 is FD */
|
---|
| 53 | { printf("WARNING - FILE CORRUPTED!\nBuffers affected:\n");
|
---|
| 54 | for(b = buf_head; b; b = b->b_next)
|
---|
| 55 | { if(sb_fdinp((SBBUF *)b, a0))
|
---|
| 56 | printf((b->b_fn ? " %s: %s\n" : " %s\n"),
|
---|
| 57 | b->b_name, b->b_fn);
|
---|
| 58 | }
|
---|
| 59 | if (oldttystate > 0) set_tty();
|
---|
| 60 | return(1); /* Try to continue normally */
|
---|
| 61 | }
|
---|
| 62 | printf("%sERR: %o ", (type ? "SBX" : "SBM"), adr);
|
---|
| 63 | printf(str,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12);
|
---|
| 64 | askerr();
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | /*
|
---|
| 68 | * Bite_bag -- Try to save our rear ends after a catastrophe.
|
---|
| 69 | * This routine is mainly called from "interrupt"
|
---|
| 70 | * level when a memory fault or bus error occurs.
|
---|
| 71 | * We try to save the buffer to the file "ELLE.crash"
|
---|
| 72 | * in the current working directory. If it loses, well
|
---|
| 73 | * then you have really lost. Note: this routine does
|
---|
| 74 | * not reset the appropriate signal handler, so it is
|
---|
| 75 | * never re-entered. If a fault repeats once in this
|
---|
| 76 | * code, then the world dies.
|
---|
| 77 | */
|
---|
| 78 |
|
---|
| 79 | bite_bag(fault) /* We come here on any memory error */
|
---|
| 80 | int fault;
|
---|
| 81 | {
|
---|
| 82 | int ostate;
|
---|
| 83 | /* Some systems, such as BSD4.x and SUN, do not reset caught signals
|
---|
| 84 | * to SIG_DFL.
|
---|
| 85 | * This is a win, but isn't what vanilla UNIX code expects.
|
---|
| 86 | * Since it doesn't hurt to do it explicitly, we always turn it off
|
---|
| 87 | * explicitly...
|
---|
| 88 | */
|
---|
| 89 | signal(fault, SIG_DFL); /* Reinstate default handling */
|
---|
| 90 |
|
---|
| 91 | ostate = clean_exit(); /* Fix up the terminal modes first! */
|
---|
| 92 | printf("ELLE stopped by fatal interrupt (%d)!\n\
|
---|
| 93 | Type S or W to try saving your work.\n",fault);
|
---|
| 94 | askerr();
|
---|
| 95 | if(ostate > 0) set_tty();
|
---|
| 96 | signal(fault, bite_bag); /* If continued, re-enable signal */
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | /* HUP_EXIT - Called by a SIGHUP hangup signal.
|
---|
| 100 | * Tries to save all modified buffers before exiting.
|
---|
| 101 | * Note that the TTY is not touched at all, although the terminal mode
|
---|
| 102 | * flag is set just in case further error handling routines are invoked.
|
---|
| 103 | */
|
---|
| 104 | hup_exit()
|
---|
| 105 | { extern int trm_mode; /* See e_disp.c */
|
---|
| 106 |
|
---|
| 107 | trm_mode = -1; /* Say TTY is now detached */
|
---|
| 108 | saveworld((struct buffer *)0, 0); /* Save world, w/o feedback */
|
---|
| 109 | exit(1);
|
---|
| 110 | }
|
---|
| 111 | |
---|
| 112 |
|
---|
| 113 | errint() /* Routine provided for ADB jumps */
|
---|
| 114 | { askerr();
|
---|
| 115 | }
|
---|
| 116 | char askh1[] = "\
|
---|
| 117 | A - Abort process\n\
|
---|
| 118 | B - Breakpoint (must have \"bpt:b\" set in ADB)\n\
|
---|
| 119 | C - Continue\n\
|
---|
| 120 | D - Diagnostic command mode\n";
|
---|
| 121 | char askh2[] = "\
|
---|
| 122 | S - Try to save current buffer\n\
|
---|
| 123 | W - Try to save world (all modified buffers)\n";
|
---|
| 124 |
|
---|
| 125 | int bsaving = 0; /* Set while in middle of saving buffer(s) */
|
---|
| 126 |
|
---|
| 127 | askerr()
|
---|
| 128 | { register struct buffer *b;
|
---|
| 129 | char linbuf[100];
|
---|
| 130 | char *asklin();
|
---|
| 131 | extern int (*funtab[])(); /* In E_CMDS.C */
|
---|
| 132 | int ostate;
|
---|
| 133 |
|
---|
| 134 | ostate = clean_exit(); /* Clean up TTY if not already done */
|
---|
| 135 | reask:
|
---|
| 136 | printf("(A,B,C,D,S,W,?)");
|
---|
| 137 | switch(upcase(*asklin(linbuf)))
|
---|
| 138 | {
|
---|
| 139 | case '?':
|
---|
| 140 | writez(1,askh1); /* Too long for &$@! printf */
|
---|
| 141 | writez(1,askh2); /* Too long for &$@! V6 C */
|
---|
| 142 | break; /* optimizer (/lib/c2) */
|
---|
| 143 | case 'A':
|
---|
| 144 | abort();
|
---|
| 145 | break;
|
---|
| 146 | case 'B':
|
---|
| 147 | bpt();
|
---|
| 148 | break;
|
---|
| 149 | case 'Q':
|
---|
| 150 | case 'C':
|
---|
| 151 | goto done;
|
---|
| 152 | case 'D':
|
---|
| 153 | if(funtab[FN_DEBUG])
|
---|
| 154 | (*funtab[FN_DEBUG])(-1);
|
---|
| 155 | else printf("Sorry, no diagnostics\n");
|
---|
| 156 | break;
|
---|
| 157 | case 'S': /* Try to save current buffer only */
|
---|
| 158 | b = cur_buf;
|
---|
| 159 | goto savb;
|
---|
| 160 | case 'W': /* Try to save all modified buffers */
|
---|
| 161 | b = 0;
|
---|
| 162 | savb: if(bsaving++)
|
---|
| 163 | { printf("Already saving -- continued");
|
---|
| 164 | goto done;
|
---|
| 165 | }
|
---|
| 166 | saveworld(b, 1); /* Save, with feedback */
|
---|
| 167 | bsaving = 0;
|
---|
| 168 | break;
|
---|
| 169 | }
|
---|
| 170 | goto reask;
|
---|
| 171 | done:
|
---|
| 172 | if(ostate > 0)
|
---|
| 173 | set_tty();
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | char *
|
---|
| 177 | asklin(acp)
|
---|
| 178 | char *acp;
|
---|
| 179 | { register char *cp;
|
---|
| 180 | register int c;
|
---|
| 181 | cp = acp;
|
---|
| 182 | while((c = tgetc()) != LF)
|
---|
| 183 | *cp++ = c;
|
---|
| 184 | *cp++ = 0;
|
---|
| 185 | return(acp);
|
---|
| 186 | }
|
---|