Build it.
[AROS-Contrib.git] / rexx / src / error.c
blob8b9a6e6b3866e08917e2966c2f9f4baf0ce34f40
1 /*
2 * $Header$
3 * $Log$
4 * Revision 1.1 2001/04/04 05:43:39 wang
5 * First commit: compiles on Linux, Amiga, Windows, Windows CE, generic gcc
7 * Revision 1.2 1999/11/26 13:13:47 bnv
8 * Changed: To use the new macros
10 * Revision 1.1 1998/07/02 17:34:50 bnv
11 * Initial revision
15 #include <stdarg.h>
16 #include <lstring.h>
18 #include <rexx.h>
19 #include <trace.h>
20 #include <compile.h>
21 #include <interpre.h>
22 #include <variable.h>
23 #include <nextsymb.h>
25 /* --- Global variable --- */
26 Lstr errmsg; /* initialise string from beggining */
28 /* ---------------- RxHaltTrap ----------------- */
29 void
30 RxHaltTrap( int cnd )
32 if (_Proc[_rx_proc].condition & SC_HALT)
33 RxSignalCondition(SC_HALT);
34 else
35 Lerror(ERR_PROG_INTERRUPT,0);
36 } /* RxHaltTrap */
38 /* ---------------- RxSignalCondition -------------- */
39 void
40 RxSignalCondition( int cnd )
42 PBinLeaf leaf;
43 RxFunc *func;
44 PLstr cndstr=NULL;
46 /*///////// first we need to terminate all the interpret strings */
47 switch (cnd) {
48 case SC_ERROR:
49 cndstr = _Proc[_rx_proc].lbl_error;
50 break;
51 case SC_HALT:
52 cndstr = _Proc[_rx_proc].lbl_halt;
53 break;
54 case SC_NOVALUE:
55 cndstr = _Proc[_rx_proc].lbl_novalue;
56 break;
57 case SC_NOTREADY:
58 cndstr = _Proc[_rx_proc].lbl_notready;
59 break;
60 case SC_SYNTAX:
61 cndstr = _Proc[_rx_proc].lbl_syntax;
62 break;
64 leaf = BinFind(&_labels,cndstr);
65 if (leaf==NULL || ((RxFunc*)(leaf->value))->label==UNKNOWN_LABEL) {
66 if (cnd==SC_SYNTAX) /* disable the error handling */
67 _Proc[_rx_proc].condition &= ~SC_SYNTAX;
68 Lerror(ERR_UNEXISTENT_LABEL,1,cndstr);
70 func = (RxFunc*)(leaf->value);
71 RxSetSpecialVar(SIGLVAR,TraceCurline(NULL,FALSE));
72 Rxcip = (CIPTYPE*)((byte huge *)Rxcodestart + (size_t)(func->label));
73 longjmp(_error_trap,JMP_CONTINUE);
74 } /* RxSignalCondition */
76 /* ------------------ Rerror ------------------- */
77 void
78 Rerror( int errno, int subno, ... )
80 int line;
81 RxFile *rxf;
82 va_list ap;
84 if (_Proc[_rx_proc].condition & SC_SYNTAX) {
85 RxSetSpecialVar(RCVAR,errno);
86 if (symbolptr==NULL) /* we are in intepret */
87 RxSignalCondition(SC_SYNTAX);
88 else { /* we are in compile */
89 RxReturnCode = errno;
90 longjmp(_error_trap,JMP_ERROR);
92 } else {
93 line = TraceCurline(&rxf,TRUE);
94 if (symbolptr==NULL) /* we are in intepret */
95 RxSetSpecialVar(SIGLVAR,line);
97 #ifndef WIN
98 va_start(ap,subno);
99 Lerrortext(&errmsg,errno,subno,&ap);
100 va_end(ap);
102 if (LLEN(errmsg)==0)
103 fprintf(STDERR," +++ Ooops unknown error %d.%d +++\n",errno,subno);
104 else {
105 LASCIIZ(errmsg);
106 if (subno==0)
107 fprintf(STDERR,
108 "Error %d running %s, line %d: %s\n",
109 errno,
110 LSTR(rxf->filename),
111 line,
112 LSTR(errmsg));
113 else
114 fprintf(STDERR,
115 "Error %d.%d running %s, line %d: %s\n",
116 errno,
117 subno,
118 LSTR(rxf->filename),
119 line,
120 LSTR(errmsg));
122 #else
124 PUTS("Error ");
125 PUTINT(errno,0,10);
126 PUTS(" running ");
127 PUTS(LSTR(rxf->filename));
128 PUTS(" line ");
129 PUTINT(line,0,10);
130 PUTS(": ");
131 Lerrortext(&errmsg,errno,subno,NULL);
132 Lprint(NULL,&errmsg);
133 PUTCHAR('\n');
135 #endif
136 RxReturnCode = errno;
137 longjmp(_exit_trap,JMP_EXIT);
139 } /* Rerror */