summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <Pixel>2001-05-02 22:14:21 +0000
committerPixel <Pixel>2001-05-02 22:14:21 +0000
commitecd16166cde1ffa3edfbaa897b049d532e234ab6 (patch)
tree192b47251b141e0dd0f53530e3a4a2a5f961ea0f
parent8626b278cdccd95e628f14c027ae8a1c47133c48 (diff)
Pouet
-rw-r--r--include/fonctions.h2
-rw-r--r--include/polynom.h4
-rw-r--r--include/scalaires.h1
-rw-r--r--lib/exceptions.c12
-rw-r--r--lib/fonctions.c52
-rw-r--r--lib/hash.c3
-rw-r--r--lib/interface.c33
-rw-r--r--lib/numbers.c2
-rw-r--r--lib/parser.c6
-rw-r--r--lib/pile.c42
-rw-r--r--lib/polynom.c21
-rw-r--r--lib/scalaires.c16
-rw-r--r--po/cat-id-tbl.c112
-rw-r--r--src/Polynom.c37
14 files changed, 206 insertions, 137 deletions
diff --git a/include/fonctions.h b/include/fonctions.h
index c4a1b18..ee3e11d 100644
--- a/include/fonctions.h
+++ b/include/fonctions.h
@@ -21,5 +21,7 @@ void setdisplay(polynome p1, polynome p2, polynome p3);
void reinit(polynome p1, polynome p2, polynome p3);
void exit_call(polynome p1, polynome p2, polynome p3);
+
+void setsmartprint(polynome p1, polynome p2, polynome p3);
#endif \ No newline at end of file
diff --git a/include/polynom.h b/include/polynom.h
index 64a9273..2078d0b 100644
--- a/include/polynom.h
+++ b/include/polynom.h
@@ -2,6 +2,8 @@
#define __POLYNOM_H__
#include "scalaires.h"
+extern int smartprint;
+
typedef struct monome {
rationnel coef;
unsigned int degre;
@@ -30,7 +32,7 @@ polynome ply_modulo(polynome poly1, polynome poly2); /* reste de la division de
polynome ply_exposant(polynome poly, unsigned int exp); /* exponentiation d'un polynome */
-double ply_valuation(polynome poly, double point); /* valuation d'un polynome en un point */
+rationnel ply_valuation(polynome poly, rationnel point); /* valuation d'un polynome en un point */
char *ply_affichage(polynome poly); /* routine d'affichage d'un polynome */
diff --git a/include/scalaires.h b/include/scalaires.h
index 06b798b..5fc7dd2 100644
--- a/include/scalaires.h
+++ b/include/scalaires.h
@@ -25,6 +25,7 @@ rationnel rat_soustraction(rationnel rat1, rationnel rat2); /* soustraction */
rationnel rat_moinsunaire(rationnel rat1); /* moins unaire */
rationnel rat_multiplication(rationnel rat1, rationnel rat2); /* multiplication */
rationnel rat_division(rationnel rat, rationnel rat2); /* division */
+rationnel rat_pow(rationnel rat, unsigned int p); /* puissance */
char *rat_to_string(rationnel rat, int first);
#endif
diff --git a/lib/exceptions.c b/lib/exceptions.c
index 89d15c4..b19df9b 100644
--- a/lib/exceptions.c
+++ b/lib/exceptions.c
@@ -20,6 +20,8 @@ char *contexts[128];
int clevel = 0;
int global_error = 0;
+/* Les fonctions strdup et malloc sont réécrites ici afin de simplifier la vie en cas d'erreur. */
+
char *Estrdup(char *o)
{
char *r;
@@ -48,6 +50,8 @@ void *Emalloc(size_t s)
return r;
}
+/* Les routines de manipulation de la pile de contexte d'erreurs */
+
void pushcontext(char *c)
{
if (clevel == 128) {
@@ -82,20 +86,20 @@ void exception(int level, char *msg)
int i;
switch (level) {
case 1:
- fprintf(stderr, "Error detected. Showing context.\n");
+ fprintf(stderr, _("Non-fatal 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);
+ fprintf(stderr, _(" Error description: %s\n"), msg);
flush_pile();
global_error = 1;
break;
default:
- fprintf(stderr, "Error detected. Showing context.\n");
+ fprintf(stderr, _("Fatal 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);
+ fprintf(stderr, _(" Error description: %s\n"), msg);
clearterm();
exit(1);
break;
diff --git a/lib/fonctions.c b/lib/fonctions.c
index eca44cb..2d25eea 100644
--- a/lib/fonctions.c
+++ b/lib/fonctions.c
@@ -19,7 +19,7 @@
#define _(x) x
#endif
-
+/* Nous allons utiliser des pointeurs sur des fonctions. Voici donc les typedefs pour notre structure... */
typedef void (*func_name)(polynome arg1, polynome arg2, polynome arg3);
typedef struct func_t {
@@ -28,6 +28,7 @@ typedef struct func_t {
int arite;
} func_t;
+/* ... et la structure elle-même */
static func_t func_table[] = {
{ deriv, "deriv", 1, },
@@ -38,9 +39,13 @@ static func_t func_table[] = {
{ setdisplay, "setdisplay", 1 },
{ reinit, "reinit", 0 },
{ exit_call, "exit", 0 },
+ { setsmartprint, "setsmartprint", 1 },
{ NULL, NULL, -1 }
};
+
+/* On cherche simplement la routine a appeler parmi la table des fonctions */
+
void appel_fonction(char *nom, int arite, polynome p1, polynome p2, polynome p3)
{
int i=0;
@@ -60,9 +65,10 @@ void appel_fonction(char *nom, int arite, polynome p1, polynome p2, polynome p3)
} else {
exception(1,_("appel_fonction: non-existent function"));
}
+}
-}
+/* Fonction de dérivation - rajoute le résultat sur la pile. */
void deriv(polynome p1, polynome p2, polynome p3)
{
@@ -71,14 +77,14 @@ void deriv(polynome p1, polynome p2, polynome p3)
while (p1) {
if (p1->degre) {
t=ply_constr(rat_constr((p1->coef.num)*(p1->degre), p1->coef.denom), (p1->degre-1));
- if (t) {
- if (resultat) {
- temp->suiv = t;
- temp = t;
- } else {
- resultat = t;
- temp = t;
- }
+ if (t) {
+ if (resultat) {
+ temp->suiv = t;
+ temp = t;
+ } else {
+ resultat = t;
+ temp = t;
+ }
}
}
p1=p1->suiv;
@@ -86,15 +92,19 @@ void deriv(polynome p1, polynome p2, polynome p3)
push_pile_poly(resultat);
}
+
+/* Fonction paresseuse */
+
void derivn(polynome p1, polynome p2, polynome p3)
{ pile_elem temp;
int i;
if (p1) {
if ((p1->degre==0) && (p1->coef.num>0) && (p1->coef.denom==1)) {
- push_pile_poly(p2);
+ push_pile_poly(NULL);
for(i=0; i<p1->coef.num; i++) {
- temp=pop_pile(1);
+ temp = pop_pile(1);
+ ply_destruct(temp.poly);
deriv(temp.poly, NULL, NULL);
}
} else {
@@ -105,6 +115,9 @@ void derivn(polynome p1, polynome p2, polynome p3)
}
}
+
+/* Intégration d'un polynome */
+
void integ(polynome p1, polynome p2, polynome p3)
{
polynome resultat = NULL, temp = NULL, t;
@@ -126,6 +139,8 @@ void integ(polynome p1, polynome p2, polynome p3)
push_pile_poly(resultat);
}
+/* Quelques fonctions explicites... */
+
void printvars(polynome p1, polynome p2, polynome p3)
{
AfficheTableau(variables);
@@ -142,6 +157,7 @@ void help(polynome p1, polynome p2, polynome p3)
". setdisplay(n); set integer display format\n"
"\tn=1: DECIMAL, n=2: HEXA\n"
"\tn=3: OCTAL, n=4: FLOAT\n"
+ ". smartprint(bool); toggle smart print of polynoms\n"
". reinit(); clear all variables\n"
". exit(); end program\n"));
}
@@ -184,3 +200,15 @@ void exit_call(polynome p1, polynome p2, polynome p3)
{
quit = 1;
}
+
+void setsmartprint(polynome p1, polynome p2, polynome p3) {
+ if (p1) {
+ if ((!p1->degre)) {
+ smartprint = p1->coef.num;
+ } else {
+ exception(1, _("setsmartprint: invalid arg"));
+ }
+ } else {
+ smartprint = 0;
+ }
+}
diff --git a/lib/hash.c b/lib/hash.c
index f1cc597..5009611 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -16,6 +16,9 @@
#define _(x) x
#endif
+/* L'ensemble de ce code source nous sert à implémenter une table de hachage qui nous sera utile
+ pour le stockage des variables du programme. C'est juste histoire d'aller un peu plus vite qu'une
+ simple liste chaînée. */
static char *CHAINEHACHAGE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
diff --git a/lib/interface.c b/lib/interface.c
index f698318..3a3c6fc 100644
--- a/lib/interface.c
+++ b/lib/interface.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
#include "config.h"
#include "interface.h"
#include "terminal.h"
@@ -9,6 +10,11 @@
int quit;
+char * ancien = NULL;
+
+/* Ces deux fonctions nous servent à insérer ou supprimer un caractère dans une chaîne. Utile pour l'utilisation des
+touches backspace, suppr et insert */
+
void supprime(char * ch) {
for (; *ch; ch++) {
*ch = *(ch + 1);
@@ -26,6 +32,9 @@ void inserer(char * ch, char c) {
*ch = c;
}
+/* La boucle de l'interface. Même si elle a l'air longue, elle ne fait que tester les différents cas
+en fonction des touches enfoncées. */
+
void ifloop(void) {
int cread, i, insert = 0;
int gotesc = 0;
@@ -44,9 +53,6 @@ void ifloop(void) {
cread = fgetc(input);
switch (cread) {
case 49: /* Home */
- for (i = 0; i < position; i++) {
- printf("\010");
- }
position = 0;
break;
case 50: /* Insert */
@@ -72,6 +78,23 @@ void ifloop(void) {
break;
}
break;
+ case 79:
+ cread = fgetc(input);
+ switch (cread) {
+ case 82: /* F3 */
+ for (i = 0; i < position; i++) {
+ printf("\010");
+ }
+ strcpy(buffer, ancien);
+ position = strlen(buffer);
+ printf("%s", buffer);
+ break;
+ default:
+ gotesc = 0;
+ break;
+
+ }
+ break;
default:
gotesc = 0;
break;
@@ -98,6 +121,8 @@ void ifloop(void) {
case 10: /* Entrée */
printf("\n");
clearterm();
+ if (ancien) free(ancien);
+ ancien = Estrdup(buffer);
parse_line(buffer);
if (quit) break;
initterm();
@@ -124,7 +149,7 @@ void ifloop(void) {
printf("\010");
}
break;
- default:
+ default: /* Tout caractère autre, on le rajoute à la position en cours */
if (insert) {
inserer(&(buffer[position]), cread);
printf("%s", &(buffer[position]));
diff --git a/lib/numbers.c b/lib/numbers.c
index 7d0c64a..100cabd 100644
--- a/lib/numbers.c
+++ b/lib/numbers.c
@@ -73,7 +73,7 @@ int char_to_number(char *st, int *valid)
rationnel char_to_rat(char *st, int *valid)
-{ /* cette fonction tente de traduire une chaine en flottant */
+{ /* cette fonction tente de traduire une chaine en rationnel */
int dotnum = 0, deci = 1, temp = 0;
while (*st) {
diff --git a/lib/parser.c b/lib/parser.c
index 529516b..74a7b71 100644
--- a/lib/parser.c
+++ b/lib/parser.c
@@ -3,6 +3,7 @@
* Interpreteur de ligne de commande
*
*/
+
#include <stdio.h>
#include <limits.h>
#ifdef HAVE_CONFIG_H
@@ -45,9 +46,6 @@ static operator_t operators[] = {
{255, -1, -1}
};
-
-
-
/* Fonction interne: convertit un operateur en sa structure */
static operator_t get_op(op_t op)
@@ -243,8 +241,6 @@ void parse_line(char *line)
op = pop_op();
if (((op & 127) == '('))
break;
- if (((op & 127) == '['))
- exception(1, _("Parse error: enclosure mismatch"));
act_pile(get_func(op));
}
if (global_error) break;
diff --git a/lib/pile.c b/lib/pile.c
index dd43a6e..11f1327 100644
--- a/lib/pile.c
+++ b/lib/pile.c
@@ -18,8 +18,10 @@ pile_elem result_pile[PILE_MAX];
unsigned int pile_ptr = 0;
unsigned int result_pile_ptr = 0;
-/* fonctions basiques sur la pile d operandes */
+/* Fonctions basiques sur la pile d'opérandes. Elle seront appelées par le parser. */
+/* La fonction push_pile est générique. Le parser lui transmet une chaîne de caractères, et cette
+fonction va tenter de la convertir en ce qui lui semble le mieux pour empiler */
void push_pile(char *st)
{
int valid1, valid2, valid3;
@@ -35,23 +37,23 @@ void push_pile(char *st)
r_number = char_to_rat(st, &valid2);
valid3 = is_mute(st);
poly = (polynome) NomVarToVar(st, variables, &valid4);
- if (valid1) { /* il s agit d un entier */
+ if (valid1) { /* il s'agit d'un entier */
pushcontext(_("it's an integer"));
push_pile_poly(ply_constr(rat_constr(i_number, 1), 0));
popcontext();
- } else if (valid2) { /* il s agit d un flottant */
+ } else if (valid2) { /* il s'agit d'un flottant */
pushcontext(_("it's a float"));
push_pile_poly(ply_constr(r_number, 0));
popcontext();
- } else if (valid3) { /* il s agit de x */
+ } else if (valid3) { /* il s'agit de x */
pushcontext(_("it's X"));
push_pile_poly(ply_constr(rat_constr(1, 1), 1));
popcontext();
- } else if (valid4) { /* il s agit d une variable */
+ } else if (valid4) { /* il s'agit d'une variable */
pushcontext(_("it's a variable"));
push_pile_poly(ply_copy(poly));
popcontext();
- } else { /* il s agit d un nom */
+ } else { /* il s'agit d'un nom */
pushcontext(_("it's a name"));
if (*st == '\'') {
st++;
@@ -61,14 +63,12 @@ void push_pile(char *st)
popcontext();
}
popcontext();
-
-
#ifdef DEBUG
-
fprintf(stderr, "exiting push_pile\n");
#endif
}
+/* Fonctions "atomiques" appelées par push_pile() */
void push_pile_poly(polynome poly)
{
@@ -108,6 +108,8 @@ void push_pile_string(char *st)
}
+/* Dépilement */
+
pile_elem pop_pile(unsigned int count)
{
char buf[50];
@@ -121,6 +123,8 @@ pile_elem pop_pile(unsigned int count)
return pile[pile_ptr];
}
+/* Vidage (appelée en cas d'erreur) */
+
void flush_pile(void)
{
int i;
@@ -144,8 +148,8 @@ void flush_pile(void)
-/* fonctions basiques sur la pile de resultats */
-
+/* Fonctions basiques sur la pile de resultats. Grâce à cette pile résultat, nous pouvons passer un résultat
+à l'interface, dès que le parser aura terminé son travail. */
void move_to_resultat_pile(void)
{ pile_elem temp;
@@ -189,7 +193,6 @@ char * pop_resultat(void)
return result;
}
-
polynome return_last(int *valid)
{
if (!result_pile_ptr) {
@@ -202,12 +205,12 @@ polynome return_last(int *valid)
}
-
int has_resultat(void) {
return (result_pile_ptr ? 1 : 0);
}
-/* fonctions avancees sur la pile d operandes */
+/* Fonctions avancées sur la pile d'opérandes. Nous allons surtout manipuler les opérandes de la pile, à l'aide
+des opérateurs que le parser nous enverra. */
char *affichage_level_1(void)
{
@@ -223,7 +226,6 @@ char *affichage_level_1(void)
break;
case T_INT:
result = (char *) Emalloc(11 * sizeof(char));
-
sprintf(result, "%10d", pile[pile_ptr - 1].val);
break;
}
@@ -237,7 +239,7 @@ int is_mute(char *st)
return !(strcmp(st, mute));
}
-
+/* Cette fonction est appelée par le parser, et est donc un énorme switch qui va tester l'opérateur passé en paramètre */
void act_pile(int func)
{
pile_elem operande1, operande2;
@@ -423,11 +425,7 @@ void act_pile(int func)
exception(1, _("act_pile: OP_FUNC_CALL need only one argument for a polynom evaluation"));
}
if (operande[0].poly->degre == 0) {
- push_pile_poly(ply_constr
- (rat_constr_from_double
- (ply_valuation
- (operande2.poly, rat_to_double(operande[0].poly->coef))),
- 0));
+ push_pile_poly(ply_constr(ply_valuation(operande2.poly, operande[0].poly->coef), 0));
if (operande[0].poly)
ply_destruct(operande[0].poly);
ply_destruct(operande2.poly);
@@ -453,7 +451,7 @@ void act_pile(int func)
popcontext();
}
-
+/* Fonction de déboguage uniquement */
void affichage_pile(void)
{
int i;
diff --git a/lib/polynom.c b/lib/polynom.c
index b502849..e2e88d3 100644
--- a/lib/polynom.c
+++ b/lib/polynom.c
@@ -19,6 +19,7 @@
int smartprint = 1;
+/* Les fonctions de base pour la construction et la destruction de polynomes */
polynome ply_constr(rationnel coef, int degre)
{ /* constructeur monome */
polynome temp;
@@ -69,7 +70,9 @@ polynome ply_copy(polynome poly)
}
-
+/* Voici toutes les fonctions de manipulation de polynôme. La fonction d'addition est la plus importante
+puisqu'elle nous sert à construire un polynome entier à partir de monomes. Sa structure est comparable à celle
+de l'opération 'fusion' dans le cas du tri fusion */
polynome ply_addition(polynome poly1, polynome poly2)
{ /* addition de deux polynomes */
@@ -129,6 +132,7 @@ polynome ply_addition(polynome poly1, polynome poly2)
return resultat;
}
+/* Nous avons choisi de réécrire cette fonction entièrement, plutôt que de bricoler à partir de la fonction addition */
polynome ply_soustraction(polynome poly1, polynome poly2)
{ /* soustraction de deux polynomes */
@@ -188,7 +192,7 @@ polynome ply_soustraction(polynome poly1, polynome poly2)
return resultat;
}
-
+/* La fonction multiplication se base sur la fonction addition, suivant les mathématiques classiques */
polynome ply_multiplication(polynome poly1, polynome poly2)
{ /* multiplication de deux polynomes */
polynome temp = NULL, t, resultat = NULL, r, tempresult = NULL, poly2init;
@@ -220,6 +224,11 @@ polynome ply_multiplication(polynome poly1, polynome poly2)
return resultat;
}
+
+/* L'algorithme pour la division et le modulo est le même. Seul le return change. En effet, pour faire le calcul, nous
+utilisons la méthode simple vue en cours de mathématiques, qui consiste à poser la division sur une feuille et à effectuer
+une série de multiplications élémentaires et de soustractions. Nous obtenons donc le quotient ET le reste. */
+
polynome ply_division(polynome dividende, polynome diviseur)
{ /* division de deux polynomes */
polynome interdividende = ply_copy(dividende), interdiviseur = NULL, inter = NULL, reste = dividende, resultat = NULL, r = NULL;
@@ -323,12 +332,12 @@ polynome ply_exposant(polynome poly, unsigned int exp)
}
-double ply_valuation(polynome poly, double point)
-{ /* valuation d'un polynome en un point */
- double result = 0;
+rationnel ply_valuation(polynome poly, rationnel point)
+{ /* évaluation d'un polynome en un point */
+ rationnel result = rat_constr_zero();
while (poly) {
- result += rat_to_double(poly->coef) * pow(point, (poly->degre));
+ result = rat_addition(result, rat_multiplication(poly->coef, rat_pow(point, poly->degre)));
poly = poly->suiv;
}
return result;
diff --git a/lib/scalaires.c b/lib/scalaires.c
index 5dd6bb1..eb7b7c6 100644
--- a/lib/scalaires.c
+++ b/lib/scalaires.c
@@ -13,9 +13,12 @@
#define _(x) x
#endif
+/* Cette précision est utilisée dans le cas où nous devons convertir un double en rationnel */
#define PRECISION 1E6
typedisplay display;
+/* Fonction interne uniquement */
+
static unsigned long long pgcd(unsigned long long a, unsigned long long b)
{
if (a < b)
@@ -113,6 +116,19 @@ rationnel rat_division(rationnel rat1, rationnel rat2)
}
+/* On choisit délibérément de faire une puissance 'lente' pour éviter de faire des overflow
+trop facilement */
+
+rationnel rat_pow(rationnel rat, unsigned int p)
+{ /* puissance */
+ for (; p; p--) {
+ rat = rat_multiplication(rat, rat);
+ }
+ return rat;
+}
+
+/* On convertit un rationnel en une chaîne. Le booléen first indique si on le rationnel devra être placé en début de chaîne (pour
+les signes) */
char *rat_to_string(rationnel rat, int first)
{
diff --git a/po/cat-id-tbl.c b/po/cat-id-tbl.c
index 56a192f..7cfa119 100644
--- a/po/cat-id-tbl.c
+++ b/po/cat-id-tbl.c
@@ -11,69 +11,71 @@ const struct _msg_ent _msg_tbl[] = {
{"Out of memory.", 2},
{"Too much error contexts during pushcontext().", 3},
{"Error context empty, but popcontext() called.", 4},
- {"Internal error into hashing", 5},
- {"Too many nested operators in expression.\n", 6},
- {"Too many nested functions calls in expression.\n", 7},
- {"Invalid unary operator", 8},
- {"Invalid binary operator", 9},
- {"Parse error: too much left parenthesis", 10},
- {"Parse error: too much right parenthesis", 11},
- {"Parse error: enclosure mismatch", 12},
- {"Invalid character", 13},
- {"Calling push_pile(%s)", 14},
- {"it's an integer", 15},
- {"it's a float", 16},
- {"it's X", 17},
- {"it's a variable", 18},
- {"it's a name", 19},
- {"push_pile_poly: Stack Overflow", 20},
- {"push_pile_int: Stack Overflow", 21},
- {"push_pile_string: Stack Overflow", 22},
- {"pop_pile: Can't pop %u elements", 23},
- {"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 argument type", 41},
- {"act_pile: OP_FUNC_CALL invalid operand type", 42},
- {"act_pile: OP_FUNC_CALL need only one argument for a polynom evaluation", 43},
- {"act_pile: OP_FUNC_CALL incorrect value for 2nd arg", 44},
- {"act_pile: OP_FUNC_CALL arg2 is an empty polynom", 45},
- {"act_pile: OP_FUNC_CALL incorrect argument number", 46},
- {"act_pile: Unknown operator", 47},
- {"\t-- Printing Stack\n", 48},
- {"\t-- End Printing Stack\n", 49},
- {"ply_affichage: strcat error, not enough space in buffer", 50},
- {"rat_constr: division by zero", 51},
- {"division by zero", 52},
- {"Signal received: segfault", 53},
- {"Signal received: break", 54},
+ {"Non-fatal error detected. Showing context.\n", 5},
+ {" Error description: %s\n", 6},
+ {"Fatal error detected. Showing context.\n", 7},
+ {"Internal error into hashing", 8},
+ {"Too many nested operators in expression.\n", 9},
+ {"Too many nested functions calls in expression.\n", 10},
+ {"Invalid unary operator", 11},
+ {"Invalid binary operator", 12},
+ {"Parse error: too much left parenthesis", 13},
+ {"Parse error: too much right parenthesis", 14},
+ {"Invalid character", 15},
+ {"Calling push_pile(%s)", 16},
+ {"it's an integer", 17},
+ {"it's a float", 18},
+ {"it's X", 19},
+ {"it's a variable", 20},
+ {"it's a name", 21},
+ {"push_pile_poly: Stack Overflow", 22},
+ {"push_pile_int: Stack Overflow", 23},
+ {"push_pile_string: Stack Overflow", 24},
+ {"pop_pile: Can't pop %u elements", 25},
+ {"move_to_resultat_pile()", 26},
+ {"move_to_resultat_pile: invalid argument type", 27},
+ {"move_to_resultat_pile: Stack Overflow", 28},
+ {"pop_resultat()", 29},
+ {"move_to_resultat_pile: empty stack", 30},
+ {"Calling act_pile(%i)", 31},
+ {"act_pile: OP_PLUS invalid arguments", 32},
+ {"act_pile: OP_MOINS invalid arguments", 33},
+ {"act_pile: OP_MUL invalid arguments", 34},
+ {"act_pile: OP_DIV invalid arguments", 35},
+ {"act_pile: OP_MOD invalid arguments", 36},
+ {"act_pile: OP_EXP invalid power", 37},
+ {"act_pile: OP_EXP empty polynom", 38},
+ {"act_pile: OP_EXP invalid arguments", 39},
+ {"act_pile: OP_ASSIGN empty string", 40},
+ {"act_pile: OP_ASSIGN invalid arguments", 41},
+ {"act_pile: OP_MOINS_UNARY invalid argument", 42},
+ {"act_pile: OP_FUNC_CALL incorrect argument type", 43},
+ {"act_pile: OP_FUNC_CALL invalid operand type", 44},
+ {"act_pile: OP_FUNC_CALL need only one argument for a polynom evaluation", 45},
+ {"act_pile: OP_FUNC_CALL incorrect value for 2nd arg", 46},
+ {"act_pile: OP_FUNC_CALL arg2 is an empty polynom", 47},
+ {"act_pile: OP_FUNC_CALL incorrect argument number", 48},
+ {"act_pile: Unknown operator", 49},
+ {"\t-- Printing Stack\n", 50},
+ {"\t-- End Printing Stack\n", 51},
+ {"ply_affichage: strcat error, not enough space in buffer", 52},
+ {"rat_constr: division by zero", 53},
+ {"division by zero", 54},
+ {"Signal received: segfault", 55},
+ {"Signal received: break", 56},
{"\
\n\
Performing initialisation...\n\
-\n", 55},
+\n", 57},
{"\
\n\
Starting interface...\n\
-\n", 56},
+\n", 58},
{"\
\n\
Performing shutdown...\n\
-\n", 57},
- {"Exiting, bye!\n", 58},
+\n", 59},
+ {"Exiting, bye!\n", 60},
};
-int _msg_tbl_length = 58;
+int _msg_tbl_length = 60;
diff --git a/src/Polynom.c b/src/Polynom.c
index dea8eb8..805c0fa 100644
--- a/src/Polynom.c
+++ b/src/Polynom.c
@@ -21,6 +21,8 @@ _TableauVariable variables;
char *mute;
char valid;
+/* Les deux gestionnaires de signaux */
+
void segfaulthand(int i)
{
exception(2, _("Signal received: segfault"));
@@ -31,8 +33,12 @@ void ctrlbreakhand(int i)
exception(1, _("Signal received: break"));
}
+/* Les routines générales */
+
void init_all(void) {
Initialise(&variables);
+ /* nom de la variable utilisee pour la saisie des polynomes, a recuperer en argv eventuellt
+ ATTENTION: elle est case sensitive */
mute = "x";
display=DEC;
}
@@ -44,42 +50,19 @@ void invite(void) {
fprintf(stderr, "Polynomia v1.0\n\n");
}
+/* Et notre main. On ne fait que lancer la boucle principale de l'interface */
+
int main(void)
{
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- /* nom de la variable utilisee pour la saisie des polynomes, a recuperer en argv eventuellt
- ATTENTION: elle est case sensitive */
-
-/*
- parse_line("P=-4.5+2*x+3*x^2;");
- //parse_line("P(2);");
- //AfficheTableau(variables);
- //printf("%p\n",(polynome)NomVarToVar("P",variables,&valid));
- //printf("-- affichage:%s\n",ply_affichage((polynome)NomVarToVar("P",variables,&valid)));
-
- parse_line("P(2);");
- pop_pile(1);
- parse_line("Q=6*x^3+4*x^2+x;");
- parse_line("soja=P-Q+2;");
- parse_line("soja;");
- parse_line("soja^3;");
- //parse_line("quake4@%*)+vo;i");
- printf("Resultat: %s\n", affichage_level_1());
- flush_pile();
- parse_line("0x52;");
- parse_line("x+0;");
- affichage_pile();
- AfficheTableau(variables);
-
-*/
invite();
-/* signal(SIGSEGV, segfaulthand);
- signal(SIGINT, ctrlbreakhand);*/
+ signal(SIGSEGV, segfaulthand);
+ signal(SIGINT, ctrlbreakhand);
fprintf(stderr, _("\nPerforming initialisation...\n\n"));
init_all();