Annotation of freem/src/merr.c, revision 1.3
1.1 snw 1: /*
1.3 ! snw 2: * $Id$
1.1 snw 3: * stuff for handling program bogosity
4: *
5: *
1.2 snw 6: * Author: Serena Willis <snw@coherent-logic.com>
1.1 snw 7: * Copyright (C) 1998 MUG Deutschland
1.3 ! snw 8: * Copyright (C) 2020, 2025 Coherent Logic Development LLC
1.1 snw 9: *
10: *
11: * This file is part of FreeM.
12: *
13: * FreeM is free software: you can redistribute it and/or modify
14: * it under the terms of the GNU Affero Public License as published by
15: * the Free Software Foundation, either version 3 of the License, or
16: * (at your option) any later version.
17: *
18: * FreeM is distributed in the hope that it will be useful,
19: * but WITHOUT ANY WARRANTY; without even the implied warranty of
20: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21: * GNU Affero Public License for more details.
22: *
23: * You should have received a copy of the GNU Affero Public License
24: * along with FreeM. If not, see <https://www.gnu.org/licenses/>.
25: *
1.3 ! snw 26: * $Log$
! 27: *
! 28: * SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC
! 29: * SPDX-License-Identifier: AGPL-3.0-or-later
1.1 snw 30: **/
31:
32: #include <string.h>
33: #include <stdlib.h>
34:
35: #include "mpsdef.h"
36: #include "merr.h"
37: #include "jobtab.h"
38:
39: merr_stackent merr_stack[NESTLEVLS + 1];
40: char etrap[256];
41: char ecode[256];
42: char user_ecode[256];
43: int estack;
44: int etrap_lvl = 0;
45: int merr_topstk = 0;
46:
47: typedef struct err_lut {
48: int ecode;
49: const char *canonical_name;
50: } err_lut;
51:
52: err_lut errtab[] = {
53: {0, "ZOK"},
54: {1, "ZINRPT"},
55: {2, "ZBKERR"},
56: {3, "ZNOSTAND"},
57: {4, "ZUNDEF"},
58: {5, "ZLBLUNDEF"},
59: {6, "ZMISSOPD"},
60: {7, "ZMISSOP"},
61: {8, "ZILLOP"},
62: {9, "ZQUOTER"},
63: {10, "ZCOMMAER"},
64: {11, "ZASSIGNER"},
65: {12, "ZARGER"},
66: {13, "ZSPACER"},
67: {14, "ZBRAER"},
68: {15, "ZLVLERR"},
69: {16, "ZDIVER"},
70: {17, "ZILLFUN"},
71: {18, "ZFUNARG"},
72: {19, "ZZTERR"},
73: {20, "ZNEXTER"},
74: {21, "ZSELER"},
75: {22, "ZCMMND"},
76: {23, "ZARGLIST"},
77: {24, "ZINVEXPR"},
78: {25, "ZINVREF"},
79: {26, "ZMXSTR"},
80: {27, "ZTOOPARA"},
81: {28, "ZNOPEN"},
82: {29, "ZNODEVICE"},
83: {30, "ZPROTECT"},
84: {31, "ZGLOBER"},
85: {32, "ZFILERR"},
86: {33, "ZPGMOV"},
87: {34, "ZSTKOV"},
88: {35, "ZSTORE"},
89: {36, "ZNOREAD"},
90: {37, "ZNOWRITE"},
91: {38, "ZNOPGM"},
92: {39, "ZNAKED"},
93: {40, "ZSBSCR"},
94: {41, "ZISYNTX"},
95: {42, "ZDBDGD"},
96: {43, "ZKILLER"},
97: {44, "ZHUPER"},
98: {45, "ZMXNUM"},
99: {46, "ZNOVAL"},
100: {47, "ZTYPEMISMATCH"},
101: {48, "ZMEMOV"},
102: {49, "ZNAMERES"},
103: {50, "ZSCKCREAT"},
104: {51, "ZSCKIFAM"},
105: {52, "ZSCKITYP"},
106: {53, "ZSCKIPRT"},
107: {54, "ZSCKCERR"},
108: {55, "ZSCKAERR"},
109: {56, "ZSCKACON"},
110: {57, "ZSCKNCON"},
111: {58, "ZSCKEOPT"},
112: {59, "ZSCKERCV"},
113: {60, "ZSCKESND"},
114: {61, "ZNORPI"},
115: {62, "ZCREDEF"},
116: {63, "ZCMODIFY"},
117: {64, "ZFILEXWR"},
118: {65, "ZINEWMUL"},
119: {66, "ZINVHORO"},
120: {67, "ZTYPMISMATCH"},
121: {68, "ZINVTYPE"},
122: {69, "ZINVLIBOPT"},
123: {80, "ZECODEINV"},
124: {81, "ZASSERT"},
125: {82, "ZUSERERR"},
126: {83, "ZOBJFLDACCV"},
127: {84, "ZOBJCONFLICT"},
128: {85, "ZOBJPRIVOVFL"},
129: {86, "ZOBJACINVALID"},
130: {128, "ZSYNTERR"},
131: {140, "M1"},
132: {141, "M2"},
133: {142, "M3"},
134: {143, "M4"},
135: {144, "M5"},
136: {145, "M6"},
137: {146, "M7"},
138: {147, "M8"},
139: {148, "M9"},
140: {149, "M10"},
141: {150, "M11"},
142: {151, "M12"},
143: {152, "M13"},
144: {153, "M14"},
145: {154, "M15"},
146: {155, "M16"},
147: {156, "M17"},
148: {157, "M18"},
149: {158, "M19"},
150: {159, "M20"},
151: {160, "M21"},
152: {161, "M22"},
153: {162, "M23"},
154: {163, "M24"},
155: {164, "M25"},
156: {165, "M26"},
157: {166, "M27"},
158: {167, "M28"},
159: {168, "M29"},
160: {169, "M30"},
161: {170, "M31"},
162: {171, "M32"},
163: {172, "M33"},
164: {173, "M34"},
165: {174, "M35"},
166: {175, "M36"},
167: {176, "M37"},
168: {177, "M38"},
169: {178, "M39"},
170: {179, "M40"},
171: {180, "M41"},
172: {181, "M42"},
173: {182, "M43"},
174: {183, "M44"},
175: {184, "M45"},
176: {185, "M46"},
177: {186, "M47"},
178: {187, "M48"},
179: {188, "M49"},
180: {189, "M50"},
181: {190, "M51"},
182: {191, "M52"},
183: {192, "M53"},
184: {193, "M54"},
185: {194, "M55"},
186: {195, "M56"},
187: {196, "M57"},
188: {197, "M58"},
189: {198, "M59"},
190: {199, "M60"},
191: {214, "M75"},
192: {240, "M101"},
193: {241, "M102"},
194: {242, "M103"},
195: {243, "M104"},
196: {254, "ZASYNC"},
197: {255, "ZCTRLB"},
198: {-1, NULL}
199: };
200:
201: inline int merr_raise(int num)
202: {
203: char place[256];
204: char cod[256];
205:
206: if (merr_in_break ()) {
207: ierr = num - CTRLB;
208: }
209: else {
210: ierr = num;
211: }
212:
213: if (num != OK) {
214: merr_set_ecode_ierr ();
215:
216: stcpy (merr_stack[nstx].MCODE, code);
217: stcpy (merr_stack[nstx].ECODE, ecode);
218:
219: if (direct_mode == 1 && nstx == 0) {
220: stcpy (merr_stack[nstx].PLACE, "@\201\0");
221: }
222: else {
223: if (!rtn_get_offset (merr_stack[nstx].PLACE)) {
224: stcpy (merr_stack[nstx].PLACE, "???\201");
225: }
226: }
227:
228: if (nstx > merr_topstk) merr_topstk = nstx;
229: }
230:
231: return ierr;
232: }
233:
234: inline int merr(void)
235: {
236: return ierr < OK ? ierr + CTRLB : ierr;
237: }
238:
239: short merr_in_break(void)
240: {
241: if (ierr < OK) {
242: return TRUE;
243: }
244: else {
245: return FALSE;
246: }
247: }
248:
249: void merr_set_break(void)
250: {
251: if (!merr_in_break ()) {
252: ierr = ierr - CTRLB;
253: }
254: }
255:
256: void merr_clear_break(void)
257: {
258: if (merr_in_break ()) {
259: ierr = ierr + CTRLB;
260: }
261: }
262:
263: int merr_num_to_code (int num, char *code)
264: {
265:
266: err_lut *p;
267:
268: for (p = errtab; p->canonical_name != NULL; ++p) {
269:
270: if (p->ecode == num) {
271: strcpy (code, p->canonical_name);
272: return 1;
273: }
274:
275: }
276:
277: return -1;
278:
279: }
280:
281: int merr_code_to_num (char *code)
282: {
283:
284: err_lut *p;
285:
286: for (p = errtab; p->canonical_name != NULL; ++p) {
287:
288: if (strcmp (p->canonical_name, code) == 0) {
289: return p->ecode;
290: }
291:
292: }
293:
294: return -1;
295:
296: }
297:
298: void merr_set_ecode_ierr (void)
299: {
300: char *cod;
301: char *t;
302:
303: cod = (char *) malloc (256 * sizeof (char));
304: NULLPTRCHK(cod,"merr_set_ecode_ierr");
305:
306: t = (char *) malloc (256 * sizeof (char));
307: NULLPTRCHK(t,"merr_set_ecode_ierr");
308:
309: if ((merr_num_to_code (merr (), cod)) == -1) goto done;
310:
311: snprintf (t, 255, ",%s,\201", cod);
312: merr_set_ecode (t);
313:
314: job_set_ecode (pid, cod);
315:
316: done:
317:
318: free (cod);
319: free (t);
320: return;
321:
322: }
323:
324: int merr_set_ecode (char *t_code)
325: {
326: int ec;
327: char *tmp;
328:
329: if (t_code[0] == '\201') {
330: stcpy (ecode, "\201");
331: return 0;
332: }
333:
334: if (t_code[1] != 'M' && t_code[1] != 'Z' && t_code[1] != 'U') {
335: return M101;
336: }
337:
338: stcpy (ecode, t_code);
339:
340: if (stcmp (t_code, "") == 0) {
341: merr_clear ();
342: stcpy (t_code, ",ZOK,");
343: stcpy (user_ecode, t_code);
344: }
345:
346: tmp = strtok (t_code, ",");
347:
348: /* caller may set ierr with return value */
349: if (ecode[1] == 'U') {
350: stcpy (user_ecode, ecode);
351: return USERERR;
352: }
353: else {
354: ec = merr_code_to_num (tmp);
355: return (ec);
356: }
357: }
358:
359: void merr_dump (int num, char *rtn, char *nsn, char *tcod, int tpos)
360: {
361: char *tbuf;
362: char *dbuf;
363: char *nem;
364: char *nrt;
365: char *real_ecode;
366: err_lut *p;
367:
368: tbuf = (char *) malloc (STRLEN * sizeof (char));
369: NULLPTRCHK(tbuf,"merr_dump");
370:
371: dbuf = (char *) malloc (STRLEN * sizeof (char));
372: NULLPTRCHK(dbuf,"merr_dump");
373:
374: nem = (char *) malloc (STRLEN * sizeof (char));
375: NULLPTRCHK(nem,"merr_dump");
376:
377: nrt = (char *) malloc (STRLEN * sizeof (char));
378: NULLPTRCHK(nrt,"merr_dump");
379:
380: real_ecode = (char *) malloc (STRLEN * sizeof (char));
381: NULLPTRCHK(real_ecode,"merr_dump");
382:
383: stcpy (nrt, rtn);
384: stcnv_m2c (nrt);
385:
386: stcpy (nem, errmes[num]);
387: stcnv_m2c (nem);
388:
389: for (p = errtab; p->canonical_name != NULL; ++p) {
390:
391: if (p->ecode == num) {
392:
393: if (strcmp (p->canonical_name, "ZUSERERR") == 0) {
394: stcpy (real_ecode, &user_ecode[1]);
395: stcnv_m2c (real_ecode);
396: real_ecode [strlen (real_ecode) - 1] = NUL;
397:
398: snprintf (tbuf, STRLEN - 1, "^$JOB\202%d\202USER_ERRORS\202%s\201", pid, &user_ecode[1]);
399: tbuf [stlen (tbuf) - 1] = '\201';
400:
401: global (get_sym, tbuf, dbuf);
402:
403: if (merr () == OK) {
404: stcpy (nem, dbuf);
405: stcnv_m2c (nem);
406: }
407: else {
408: merr_clear ();
409: }
410:
411: }
412: else {
413: strcpy (real_ecode, p->canonical_name);
414: }
415:
416: if (!stlen (err_suppl)) {
417: sprintf (tbuf, "\r\n>> Error %s: %s in %s.%s::%s [$STACK = %d]\r\n\201", real_ecode, nem, shm_env, nsn, nrt, nstx);
418: }
419: else {
420: stcnv_m2c (err_suppl);
421: sprintf (tbuf, "\r\n>> Error %s: %s (%s) in %s::%s [$STACK = %d]\r\n\201", real_ecode, nem, err_suppl, nsn, nrt, nstx);
422: err_suppl[0] = EOL;
423: }
424: write_m (tbuf);
425: write_m (">> \201");
426: write_m (tcod);
427: write_m ("\r\n\201");
428: write_t (tpos);
429: write_m ("^\201");
430:
431: goto done;
432: }
433:
434: }
435:
436:
437: done:
438:
439: free (tbuf);
440: free (dbuf);
441: free (nem);
442: free (nrt);
443: free (real_ecode);
444:
445: return;
446: }
447:
448:
449: void merr_set_iochan_err(int channel, short frm_err, char *err_text)
450: {
451: if (channel > MAXDEV || channel < 0) {
452: merr_raise (ARGLIST);
453: return;
454: }
455:
456: devstat[channel].mdc_err = 1;
457: devstat[channel].frm_err = frm_err;
458:
459: strncpy (devstat[channel].err_txt, err_text, 79);
460:
461: return;
462: }
463:
464: void merr_clear_iochan_err(int channel)
465: {
466: if (channel > MAXDEV || channel < 0) {
467: merr_raise (ARGLIST);
468: return;
469: }
470:
471: devstat[channel].mdc_err = 1;
472: devstat[channel].frm_err = OK;
473: devstat[channel].err_txt[0] = '\0';
474:
475: return;
476:
477: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>