tizen 2.3 release
[framework/uifw/embryo.git] / src / bin / embryo_cc_sc5.c
1 /*  Small compiler - Error message system
2  *  In fact a very simple system, using only 'panic mode'.
3  *
4  *  Copyright (c) ITB CompuPhase, 1997-2003
5  *
6  *  This software is provided "as-is", without any express or implied warranty.
7  *  In no event will the authors be held liable for any damages arising from
8  *  the use of this software.
9  *
10  *  Permission is granted to anyone to use this software for any purpose,
11  *  including commercial applications, and to alter it and redistribute it
12  *  freely, subject to the following restrictions:
13  *
14  *  1.  The origin of this software must not be misrepresented; you must not
15  *      claim that you wrote the original software. If you use this software in
16  *      a product, an acknowledgment in the product documentation would be
17  *      appreciated but is not required.
18  *  2.  Altered source versions must be plainly marked as such, and must not be
19  *      misrepresented as being the original software.
20  *  3.  This notice may not be removed or altered from any source distribution.
21  *
22  *  Version: $Id$
23  */
24
25
26 #ifdef HAVE_CONFIG_H
27 # include <config.h>
28 #endif
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <stdarg.h>
33 #include <string.h>
34
35 #ifdef HAVE_UNISTD_H
36 # include <unistd.h>
37 #endif
38
39 #include "embryo_cc_sc.h"
40 #include "embryo_cc_sc5.scp"
41
42 static int errflag;
43 static int errstart;    /* line number at which the instruction started */
44
45 /*  error
46  *
47  *  Outputs an error message (note: msg is passed optionally).
48  *  If an error is found, the variable "errflag" is set and subsequent
49  *  errors are ignored until lex() finds a semicolumn or a keyword
50  *  (lex() resets "errflag" in that case).
51  *
52  *  Global references: inpfname   (referred to only)
53  *                     fline      (referred to only)
54  *                     fcurrent   (referred to only)
55  *                     errflag    (altered)
56  */
57 int
58 error(int number, ...)
59 {
60    static int          lastline, lastfile, errorcount;
61    char               *msg;
62    va_list             argptr;
63    char                string[1024];
64    int start;
65
66    /* errflag is reset on each semicolon.
67     * In a two-pass compiler, an error should not be reported twice. Therefore
68     * the error reporting is enabled only in the second pass (and only when
69     * actually producing output). Fatal errors may never be ignored.
70     */
71    if (((errflag) || (sc_status != statWRITE)) &&
72        ((number < 100) || (number >= 200)))
73      return 0;
74
75    if (number < 100)
76      {
77             if (number > 74) number = 74;
78             msg = errmsg[number - 1];
79             errflag = TRUE;     /* set errflag (skip rest of erroneous expression) */
80             errnum++;
81      }
82    else if (number < 200)
83      {
84             if (number > 107) number = 107;
85             msg = fatalmsg[number - 100];
86             errnum++; /* a fatal error also counts as an error */
87      }
88    else
89      {
90         msg = warnmsg[number - 200];
91         warnnum++;
92      }
93
94    strexpand(string, (unsigned char *)msg, sizeof string, SCPACK_TABLE);
95
96    va_start(argptr, number);
97
98    start = (errstart == fline) ? -1 : errstart;
99
100    if (sc_error(number, string, inpfname, start, fline, argptr))
101    {
102       sc_closeasm(outf);
103       outf = NULL;
104       longjmp(errbuf, 3);
105    }
106
107    va_end(argptr);
108
109    if (((number >= 100) && (number < 200)) || (errnum > 250))
110      {
111         va_start(argptr, number);
112         sc_error(0, "\nCompilation aborted.", NULL, 0, 0, argptr);
113         va_end(argptr);
114
115         if (outf)
116           {
117              sc_closeasm(outf);
118              outf = NULL;
119           }                     /* if */
120         longjmp(errbuf, 2);     /* fatal error, quit */
121      }                          /* if */
122
123    /* check whether we are seeing many errors on the same line */
124    if (((errstart < 0) && (lastline != fline)) ||
125        (lastline < errstart) || (lastline > fline) || (fcurrent != lastfile))
126       errorcount = 0;
127    lastline = fline;
128    lastfile = fcurrent;
129    if (number < 200)
130       errorcount++;
131    if (errorcount >= 3)
132       error(107); /* too many error/warning messages on one line */
133    return 0;
134 }
135
136 void
137 errorset(int code)
138 {
139    switch (code)
140      {
141       case sRESET:
142         errflag = FALSE;        /* start reporting errors */
143         break;
144       case sFORCESET:
145         errflag = TRUE;         /* stop reporting errors */
146         break;
147       case sEXPRMARK:
148         errstart = fline;       /* save start line number */
149         break;
150       case sEXPRRELEASE:
151         errstart = -1;          /* forget start line number */
152         break;
153       default:
154         break;
155      }
156 }