summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <>2001-04-02 01:00:37 +0000
committerPixel <>2001-04-02 01:00:37 +0000
commitce176d3637caebac401e634b40abe8bc48505327 (patch)
tree6176a1d949974cb887773177727c2894945b56e8
parent8212d25ba09a7fdf1938a1992022a0143d29e05b (diff)
Exceptions.
-rw-r--r--include/Makefile.am2
-rw-r--r--include/exceptions.h4
-rw-r--r--lib/exceptions.c31
-rw-r--r--lib/meta.c45
-rw-r--r--po/ProjetArchi.pot54
-rw-r--r--src/compilo.c24
6 files changed, 105 insertions, 55 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index f451c35..44298ee 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1 +1 @@
-include_HEADERS = hash.h assembler.h meta.h parser.h numbers.h global.h
+include_HEADERS = hash.h assembler.h meta.h parser.h numbers.h exceptions.h
diff --git a/include/exceptions.h b/include/exceptions.h
index efc02f7..5ce9f60 100644
--- a/include/exceptions.h
+++ b/include/exceptions.h
@@ -7,4 +7,8 @@ char * Estrdup(char *);
void * Emalloc(size_t);
void exception(int, char *);
+void pushcontext(char *);
+void popcontext(void);
+void flushcontext(void);
+
#endif
diff --git a/lib/exceptions.c b/lib/exceptions.c
index 349e8a9..231ca63 100644
--- a/lib/exceptions.c
+++ b/lib/exceptions.c
@@ -4,6 +4,9 @@
#include "config.h"
#include "exceptions.h"
+char * contexts[128];
+int clevel = 0;
+
char * Estrdup(char * o) {
char * r;
@@ -22,8 +25,34 @@ void * Emalloc(size_t s) {
return r;
}
+void pushcontext(char * c) {
+ if (clevel == 128) {
+ exception(1, _("Too much error contexts during pushcontext()."));
+ }
+ contexts[clevel++] = Estrdup(c);
+}
+
+void popcontext(void) {
+ if (clevel == 0) {
+ exception(1, _("Error context empty, but popcontext() called."));
+ }
+ free(contexts[--clevel]);
+}
+
+void flushcontext(void) {
+ while (clevel) {
+ popcontext();
+ }
+}
+
void exception(int level, char *msg)
{
- fprintf(stderr, "%s\n", msg);
+ int i;
+
+ fprintf(stderr, "Error detected. Showing context.\n");
+ for (i = 0; i < clevel; i++) {
+ fprintf(stderr, " (%i) - %s\n", i, contexts[i]);
+ }
+ fprintf(stderr, " Error description: %s\n", msg);
exit(level);
}
diff --git a/lib/meta.c b/lib/meta.c
index c40f116..275d60b 100644
--- a/lib/meta.c
+++ b/lib/meta.c
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <limits.h>
#include <string.h>
+#include <errno.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
@@ -45,25 +46,32 @@ static char *getword(char *line, char *p)
line++;
} while ((*line) && (!strchr(meta_ops, o)) && (!strchr(meta_ops, *line)));
*p = '\0';
+
return line;
}
void meta_parse_line(char *line)
{
char buffer[BUFSIZ], *first = NULL, m = 0, *p1 = NULL, *p2 = NULL, *Fnames[MAXF], *Fimplicits[MAXF],
- *Snames[MAXF], *Sinames[MAXF], gotname = 0, goteoi = 0;
+ *Snames[MAXF], *Sinames[MAXF], gotname = 0, goteoi = 0, errbuff[BUFSIZ];
phon_t *phon = NULL;
field_t *field = NULL;
pattern_t *pattern = NULL;
instruct_t *instruct = NULL;
metaexpr_t *metaexpr = NULL, *tmetaexpr, *tabmetaexpr[MAXM];
int Fsizes[MAXF], Fvalues[MAXF], Itypes[MAXF], Etypes[MAXF], nbfields = 0, valid, i, nbimplicit = 0;
-
+
if (*line == '#') {
return;
}
+
+ sprintf(errbuff, _("Read line '%s'"), line);
+ pushcontext(errbuff);
+
while (*line) {
line = getword(line, buffer);
+ sprintf(errbuff, _("Analysing word '%s'"), buffer);
+ pushcontext(errbuff);
if (!m) {
if (*line != ':') {
exception(1, _("Missing operator ':'"));
@@ -137,7 +145,10 @@ void meta_parse_line(char *line)
tmetaexpr->type = 0;
if (*buffer == '.') {
tmetaexpr->type = 1;
+ popcontext();
line = getword(line, buffer);
+ sprintf(errbuff, _("Analysing word '%s'"), buffer);
+ pushcontext(errbuff);
}
if (!isident(buffer)) {
exception(1, _("Identifier incorrect."));
@@ -147,7 +158,10 @@ void meta_parse_line(char *line)
if (*(++line) != '.') {
exception(1, _("Error: Expecting a . after a ="));
}
+ popcontext();
line = getword(++line, buffer);
+ sprintf(errbuff, _("Analysing word '%s'"), buffer);
+ pushcontext(errbuff);
if (!isident(buffer)) {
exception(1, _("Identifier incorrect."));
}
@@ -217,14 +231,20 @@ void meta_parse_line(char *line)
Etypes[nbfields] = 0;
if (*buffer == '.') {
Etypes[nbfields] = 1;
+ popcontext();
line = getword(line, buffer);
+ sprintf(errbuff, _("Analysing word '%s'"), buffer);
+ pushcontext(errbuff);
}
Fnames[nbfields] = Estrdup(buffer);
if (*line == '=') {
if (*(++line) != '.') {
exception(1, _("Error: character . expected."));
}
+ popcontext();
line = getword(++line, buffer);
+ sprintf(errbuff, _("Analysing word '%s'"), buffer);
+ pushcontext(errbuff);
if (!isident(buffer)) {
exception(1, _("Identifier incorrect."));
}
@@ -246,11 +266,17 @@ void meta_parse_line(char *line)
if (*line != '=') {
exception(1, _("= expected after an implicit name"));
}
+ popcontext();
line = getword(++line, buffer);
+ sprintf(errbuff, _("Analysing word '%s'"), buffer);
+ pushcontext(errbuff);
if (*buffer == '.') {
Itypes[nbimplicit] = 1;
+ popcontext();
line = getword(line, buffer);
+ sprintf(errbuff, _("Analysing word '%s'"), buffer);
+ pushcontext(errbuff);
if (!isident(buffer)) {
exception(1, _("Identifier incorrect"));
}
@@ -304,7 +330,10 @@ void meta_parse_line(char *line)
break;
}
}
+ popcontext();
}
+
+ popcontext();
}
int meta_init(void)
@@ -452,9 +481,16 @@ int meta_load(char * n) {
FILE * f;
char buf[BUFSIZ], *p;
+ pushcontext("Loading meta file");
+ sprintf(buf, "Opening file '%s'", n);
+ pushcontext(buf);
+
if (!(f = fopen(n, "r"))) {
+ pushcontext(strerror(errno));
return 1;
}
+ popcontext();
+ pushcontext("Reading file");
while (fgets(buf, BUFSIZ, f)) {
if ((p = strchr(buf, '\r'))) {
*p = '\0';
@@ -464,6 +500,11 @@ int meta_load(char * n) {
}
meta_parse_line(buf);
}
+ popcontext();
+ popcontext();
+
+
+ fclose(f);
return 0;
}
diff --git a/po/ProjetArchi.pot b/po/ProjetArchi.pot
index 915184b..9f909a4 100644
--- a/po/ProjetArchi.pot
+++ b/po/ProjetArchi.pot
@@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
-"POT-Creation-Date: 2001-04-01 14:30+0200\n"
+"POT-Creation-Date: 2001-04-02 02:48+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -14,64 +14,64 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: ENCODING\n"
-#: lib/meta.c:69
+#: lib/meta.c:77
msgid "Missing operator ':'"
msgstr ""
-#: lib/meta.c:97
+#: lib/meta.c:105
msgid "Invalid number."
msgstr ""
-#: lib/meta.c:101
+#: lib/meta.c:109
msgid "Expecting ';' for field separator."
msgstr ""
-#: lib/meta.c:120
+#: lib/meta.c:128
msgid "Expecting ',' for field separator."
msgstr ""
-#: lib/meta.c:143 lib/meta.c:152 lib/meta.c:190 lib/meta.c:210 lib/meta.c:229
-#: lib/meta.c:243
+#: lib/meta.c:154 lib/meta.c:166 lib/meta.c:204 lib/meta.c:224 lib/meta.c:249
+#: lib/meta.c:263
msgid "Identifier incorrect."
msgstr ""
-#: lib/meta.c:148
+#: lib/meta.c:159
msgid "Error: Expecting a . after a ="
msgstr ""
-#: lib/meta.c:185
+#: lib/meta.c:199
msgid "Extra parameters for field 'p'."
msgstr ""
-#: lib/meta.c:193
+#: lib/meta.c:207
msgid "Unexpected char at end of line."
msgstr ""
-#: lib/meta.c:206
+#: lib/meta.c:220
msgid "Expecting operator '=' for field 'p'."
msgstr ""
-#: lib/meta.c:225
+#: lib/meta.c:242
msgid "Error: character . expected."
msgstr ""
-#: lib/meta.c:247
+#: lib/meta.c:267
msgid "= expected after an implicit name"
msgstr ""
-#: lib/meta.c:255 lib/meta.c:264
+#: lib/meta.c:281 lib/meta.c:290
msgid "Identifier incorrect"
msgstr ""
-#: lib/meta.c:274
+#: lib/meta.c:300
msgid "expecting ; as field separator"
msgstr ""
-#: lib/meta.c:475 lib/meta.c:484 src/compilo.c:15 src/compilo.c:24
+#: lib/meta.c:516 lib/meta.c:525
msgid "Out of memory."
msgstr ""
-#: lib/meta.c:504 src/compilo.c:43
+#: lib/meta.c:545 src/compilo.c:19
msgid "Meta parser init failed."
msgstr ""
@@ -107,54 +107,54 @@ msgstr ""
msgid "Invalid character"
msgstr ""
-#: src/compilo.c:36
+#: src/compilo.c:12
msgid ""
"Assembler\n"
"\n"
msgstr ""
-#: src/compilo.c:40
+#: src/compilo.c:16
msgid " o Initialising the meta engine... "
msgstr ""
-#: src/compilo.c:46
+#: src/compilo.c:22
msgid ""
" Done!\n"
" o Meta language loading... "
msgstr ""
-#: src/compilo.c:49
+#: src/compilo.c:25
msgid "Meta language loading failed."
msgstr ""
-#: src/compilo.c:52
+#: src/compilo.c:28
msgid ""
" Done!\n"
" o Initialising the assembler core..."
msgstr ""
-#: src/compilo.c:55
+#: src/compilo.c:31
msgid "Assembler core init failed."
msgstr ""
-#: src/compilo.c:58
+#: src/compilo.c:34
msgid " Done!\n"
msgstr ""
-#: src/compilo.c:69
+#: src/compilo.c:45
msgid ""
"\n"
"Performing initialisation...\n"
"\n"
msgstr ""
-#: src/compilo.c:72
+#: src/compilo.c:48
msgid ""
"\n"
"Performing shutdown...\n"
"\n"
msgstr ""
-#: src/compilo.c:75
+#: src/compilo.c:51
msgid "Exitting, bye!\n"
msgstr ""
diff --git a/src/compilo.c b/src/compilo.c
index 6c9e36b..161c70f 100644
--- a/src/compilo.c
+++ b/src/compilo.c
@@ -8,30 +8,6 @@
#include "hash.h"
#include "assembler.h"
-char * Estrdup(char * o) {
- char * r;
-
- if (!(r = strdup(o))) {
- exception(1, _("Out of memory."));
- }
- return r;
-}
-
-void * Emalloc(size_t s) {
- void * r;
-
- if (!(r = malloc(s))) {
- exception(1, _("Out of memory."));
- }
- return r;
-}
-
-void exception(int level, char *msg)
-{
- fprintf(stderr, "%s\n", msg);
- exit(level);
-}
-
void invite(void) {
fprintf(stderr, _("Assembler\n\n"));
}