diff options
author | Pixel <Pixel> | 2001-05-02 00:18:08 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2001-05-02 00:18:08 +0000 |
commit | 064a422245f2ef4e881f50350dbbf686283ae310 (patch) | |
tree | d6043c3fd05a3f0842ac67cf6f72fa82ddb3e347 | |
parent | 7dd4d0c7b11f8341fc4f7c357273c4d14f6bb237 (diff) |
Pouet
-rw-r--r-- | acconfig.h | 2 | ||||
-rw-r--r-- | config.h.in | 2 | ||||
-rw-r--r-- | configure.in | 9 | ||||
-rw-r--r-- | include/pile.h | 2 | ||||
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/exceptions.c | 6 | ||||
-rw-r--r-- | lib/interface.c | 10 | ||||
-rw-r--r-- | lib/parser.c | 9 | ||||
-rw-r--r-- | lib/pile.c | 44 | ||||
-rw-r--r-- | po/cat-id-tbl.c | 64 | ||||
-rw-r--r-- | src/Polynom.c | 2 |
11 files changed, 92 insertions, 60 deletions
@@ -1,3 +1,5 @@ +#undef DEBUG + #undef HAVE_LIBINTL_H /* Define to 1 if NLS is requested. */ diff --git a/config.h.in b/config.h.in index cdf91e8..460af93 100644 --- a/config.h.in +++ b/config.h.in @@ -47,6 +47,8 @@ byte first (like Motorola and SPARC, unlike Intel and VAX). */ #undef WORDS_BIGENDIAN +#undef DEBUG + /* Define to 1 if NLS is requested. */ #undef ENABLE_NLS diff --git a/configure.in b/configure.in index e2f10e6..c11916c 100644 --- a/configure.in +++ b/configure.in @@ -24,6 +24,15 @@ AM_CONFIG_HEADER(config.h) AM_MAINTAINER_MODE +AC_ARG_WITH(debug, +[ --with-debug enable debug info], +[ with_debug=$withval; ], +[ with_debug=no; ]) + +if test x$with_debug = xyes; then + AC_DEFINE(DEBUG) +fi + dnl Checks for programs. AC_PROG_CXX AC_PROG_AWK diff --git a/include/pile.h b/include/pile.h index 031424f..e06d11f 100644 --- a/include/pile.h +++ b/include/pile.h @@ -41,6 +41,6 @@ void move_to_resultat_pile(void); char * pop_resultat(void); - +int has_resultat(void); #endif 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(); } @@ -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")); diff --git a/po/cat-id-tbl.c b/po/cat-id-tbl.c index d2dffc7..33f4c45 100644 --- a/po/cat-id-tbl.c +++ b/po/cat-id-tbl.c @@ -30,42 +30,44 @@ const struct _msg_ent _msg_tbl[] = { {"push_pile_int: Stack Overflow", 21}, {"push_pile_string: Stack Overflow", 22}, {"pop_pile: Can't pop %u elements", 23}, - {"move_to_resultat_pile: invalid argument type", 24}, - {"move_to_resultat_pile: Stack Overflow", 25}, - {"move_to_resultat_pile: empty stack", 26}, - {"Calling act_pile(%i)", 27}, - {"act_pile: OP_PLUS invalid arguments", 28}, - {"act_pile: OP_MOINS invalid arguments", 29}, - {"act_pile: OP_MUL invalid arguments", 30}, - {"act_pile: OP_DIV invalid arguments", 31}, - {"act_pile: OP_MOD invalid arguments", 32}, - {"act_pile: OP_EXP invalid power", 33}, - {"act_pile: OP_EXP empty polynom", 34}, - {"act_pile: OP_EXP invalid arguments", 35}, - {"act_pile: OP_ASSIGN empty string", 36}, - {"act_pile: OP_ASSIGN invalid arguments", 37}, - {"act_pile: OP_MOINS_UNARY invalid argument", 38}, - {"act_pile: OP_FUNC_CALL incorrect value for 2nd arg", 39}, - {"act_pile: OP_FUNC_CALL arg2 is an empty polynom", 40}, - {"act_pile: OP_FUNC_CALL invalid arguments", 41}, - {"act_pile: OP_FUNC_CALL incorrect argument number", 42}, - {"act_pile: Unknown operator", 43}, - {"\t-- Printing Stack\n", 44}, - {"\t-- End Printing Stack\n", 45}, - {"ply_affichage: strcat error, not enough space in buffer", 46}, - {"rat_constr: division by zero", 47}, - {"division by zero", 48}, - {"Signal received: segfault", 49}, - {"Signal received: break", 50}, + {"move_to_resultat_pile()", 24}, + {"move_to_resultat_pile: invalid argument type", 25}, + {"move_to_resultat_pile: Stack Overflow", 26}, + {"pop_resultat()", 27}, + {"move_to_resultat_pile: empty stack", 28}, + {"Calling act_pile(%i)", 29}, + {"act_pile: OP_PLUS invalid arguments", 30}, + {"act_pile: OP_MOINS invalid arguments", 31}, + {"act_pile: OP_MUL invalid arguments", 32}, + {"act_pile: OP_DIV invalid arguments", 33}, + {"act_pile: OP_MOD invalid arguments", 34}, + {"act_pile: OP_EXP invalid power", 35}, + {"act_pile: OP_EXP empty polynom", 36}, + {"act_pile: OP_EXP invalid arguments", 37}, + {"act_pile: OP_ASSIGN empty string", 38}, + {"act_pile: OP_ASSIGN invalid arguments", 39}, + {"act_pile: OP_MOINS_UNARY invalid argument", 40}, + {"act_pile: OP_FUNC_CALL incorrect value for 2nd arg", 41}, + {"act_pile: OP_FUNC_CALL arg2 is an empty polynom", 42}, + {"act_pile: OP_FUNC_CALL invalid arguments", 43}, + {"act_pile: OP_FUNC_CALL incorrect argument number", 44}, + {"act_pile: Unknown operator", 45}, + {"\t-- Printing Stack\n", 46}, + {"\t-- End Printing Stack\n", 47}, + {"ply_affichage: strcat error, not enough space in buffer", 48}, + {"rat_constr: division by zero", 49}, + {"division by zero", 50}, + {"Signal received: segfault", 51}, + {"Signal received: break", 52}, {"\ \n\ Performing initialisation...\n\ -\n", 51}, +\n", 53}, {"\ \n\ Performing shutdown...\n\ -\n", 52}, - {"Exitting, bye!\n", 53}, +\n", 54}, + {"Exitting, bye!\n", 55}, }; -int _msg_tbl_length = 53; +int _msg_tbl_length = 55; diff --git a/src/Polynom.c b/src/Polynom.c index 6863e4b..98b083d 100644 --- a/src/Polynom.c +++ b/src/Polynom.c @@ -23,13 +23,11 @@ char valid; void segfaulthand(int i) { - clearterm(); exception(2, _("Signal received: segfault")); } void ctrlbreakhand(int i) { - clearterm(); exception(1, _("Signal received: break")); } |