summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPixel <>2001-04-02 01:00:37 +0000
committerPixel <>2001-04-02 01:00:37 +0000
commitce176d3637caebac401e634b40abe8bc48505327 (patch)
tree6176a1d949974cb887773177727c2894945b56e8 /lib
parent8212d25ba09a7fdf1938a1992022a0143d29e05b (diff)
Exceptions.
Diffstat (limited to 'lib')
-rw-r--r--lib/exceptions.c31
-rw-r--r--lib/meta.c45
2 files changed, 73 insertions, 3 deletions
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;
}