From 064a422245f2ef4e881f50350dbbf686283ae310 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 2 May 2001 00:18:08 +0000 Subject: Pouet --- lib/Makefile.am | 2 +- lib/exceptions.c | 6 ++++++ lib/interface.c | 10 +++++++++- lib/parser.c | 9 +++------ lib/pile.c | 44 ++++++++++++++++++++++++++------------------ 5 files changed, 45 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/Makefile.am b/lib/Makefile.am index 1353da6..c6651e2 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,6 +1,6 @@ localedir = $(datadir)/locale DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ -AM_CFLAGS = -O3 -DDEBUG -Wall -Wstrict-prototypes $(CFLAGS) +AM_CFLAGS = -O3 -Wall -Wstrict-prototypes $(CFLAGS) INCLUDES = -I. -I.. -I$(includedir) -I../include lib_LTLIBRARIES = libPolynom.la diff --git a/lib/exceptions.c b/lib/exceptions.c index 72842a4..89d15c4 100644 --- a/lib/exceptions.c +++ b/lib/exceptions.c @@ -14,6 +14,7 @@ #endif #include "exceptions.h" #include "pile.h" +#include "terminal.h" char *contexts[128]; int clevel = 0; @@ -81,6 +82,10 @@ void exception(int level, char *msg) int i; switch (level) { case 1: + 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); flush_pile(); global_error = 1; @@ -91,6 +96,7 @@ void exception(int level, char *msg) fprintf(stderr, " (%i) - %s\n", i, contexts[i]); } fprintf(stderr, " Error description: %s\n", msg); + clearterm(); exit(1); break; } diff --git a/lib/interface.c b/lib/interface.c index c23d175..001c01d 100644 --- a/lib/interface.c +++ b/lib/interface.c @@ -4,6 +4,8 @@ #include "interface.h" #include "terminal.h" #include "exceptions.h" +#include "parser.h" +#include "pile.h" void supprime(char * ch) { for (; *ch; ch++) { @@ -76,6 +78,7 @@ void ifloop(void) { } switch(cread) { case 3: /* CTRL-C */ + printf(_("*CTRL-C*\n")); quit = 1; break; case 8: /* backspace */ @@ -92,7 +95,12 @@ void ifloop(void) { parse_line(buffer); position = 0; buffer[0] = 0; - printf("> "); + printf("\n"); + while (has_resultat()) { + printf(" . %s\n", pop_resultat()); + } + printf("\n> "); + global_error = 0; break; case 27: /* ESC */ gotesc = 1; diff --git a/lib/parser.c b/lib/parser.c index 1e7347e..ef3f0e9 100644 --- a/lib/parser.c +++ b/lib/parser.c @@ -175,8 +175,7 @@ static char *getword(char *line, char *p) } line++; } - while (((*line) && (*line != ')') - && (*line != ';') && (get_func(*line) == -1) + while (((*line) && (*line != ')') && (*line != ';') && (get_func(*line) == -1) && (get_func(o) == -1)) || (instring)); *p = '\0'; return line; @@ -233,9 +232,8 @@ void parse_line(char *line) exception(1, _("Parse error: too much left parenthesis")); act_pile(get_func(op)); } - popcontext(); - popcontext(); - return; + move_to_resultat_pile(); + break; case ')': /* Fin de parenthese (Appel de fonction ou expression mathématique) */ while (1) { @@ -273,5 +271,4 @@ void parse_line(char *line) popcontext(); } popcontext(); - move_to_resultat_pile(); } diff --git a/lib/pile.c b/lib/pile.c index 48bce46..5073127 100644 --- a/lib/pile.c +++ b/lib/pile.c @@ -10,17 +10,14 @@ #include "main.h" #include "parser.h" #include "scalaires.h" -#ifdef HAVE_CONFIG_H #include "config.h" -#else -#define _(x) x -#endif pile_elem pile[PILE_MAX]; pile_elem result_pile[PILE_MAX]; unsigned int pile_ptr = 0; unsigned int result_pile_ptr = 0; + void push_pile(char *st) { int valid1, valid2, valid3; @@ -54,6 +51,10 @@ void push_pile(char *st) popcontext(); } else { /* il s agit d un nom */ pushcontext(_("it's a name")); + if (*st == '\'') { + st++; + st[strlen(st) + 1] = 0; + } push_pile_string(Estrdup(st)); popcontext(); } @@ -142,34 +143,40 @@ void flush_pile(void) void move_to_resultat_pile(void) { pile_elem temp; - temp=pop_pile(1); - if (result_pile_ptr!=PILE_MAX) { - if (temp.type==T_POLY) { - result_pile[result_pile_ptr]=temp; - result_pile_ptr++; - } else { - exception(2, _("move_to_resultat_pile: invalid argument type")); - } - } else { - exception(2, _("move_to_resultat_pile: Stack Overflow")); + pushcontext(_("move_to_resultat_pile()")); + if (pile_ptr) { + temp=pop_pile(1); + if (result_pile_ptr!=PILE_MAX) { + if (temp.type==T_POLY) { + result_pile[result_pile_ptr]=temp; + result_pile_ptr++; + } else { + exception(1, _("move_to_resultat_pile: invalid argument type")); + } + } else { + exception(2, _("move_to_resultat_pile: Stack Overflow")); + } } + popcontext(); } char * pop_resultat(void) { static char result[BUFSIZ]; + pushcontext(_("pop_resultat()")); if (result_pile_ptr) { result_pile_ptr--; - sprintf(result,"%s",ply_affichage(result_pile[result_pile_ptr].poly)); + sprintf(result,"%s", ply_affichage(result_pile[result_pile_ptr].poly)); } else { exception(2, _("move_to_resultat_pile: empty stack")); } + popcontext(); return result; } - - - +int has_resultat(void) { + return (result_pile_ptr ? 1 : 0); +} char *affichage_level_1(void) { @@ -328,6 +335,7 @@ void act_pile(int func) if (valid) SupprimerDansTab(&variables,operande2.label); InsererVarDansTab(&variables, CreerElement(operande2.label, (void *) operande1.poly)); + push_pile(operande2.label); free(operande2.label); } else { exception(1, _("act_pile: OP_ASSIGN empty string")); -- cgit v1.2.3