diff options
author | biouman <biouman> | 2001-05-02 01:14:42 +0000 |
---|---|---|
committer | biouman <biouman> | 2001-05-02 01:14:42 +0000 |
commit | 4115cde1a2045658f66cf1ba09e42556ec3cb7a5 (patch) | |
tree | 2f93f4f1b3ab57729e778541c6caae100b387698 /lib | |
parent | 5cc0d45db39afff3bceae05977c89709cf9dd30a (diff) |
*** empty log message ***
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fonctions.c | 138 | ||||
-rw-r--r-- | lib/pile.c | 23 | ||||
-rw-r--r-- | lib/scalaires.c | 2 |
3 files changed, 158 insertions, 5 deletions
diff --git a/lib/fonctions.c b/lib/fonctions.c index 499c159..2600f98 100644 --- a/lib/fonctions.c +++ b/lib/fonctions.c @@ -6,14 +6,144 @@ #include "fonctions.h" #include "pile.h" +#include "hash.h" +#include "main.h" +#include "scalaires.h" +#include "terminal.h" + + +typedef (void)(*func_name)(polynome arg1, polynome arg2, polynome arg3); typedef struct func_t { func_name func; char *nom; int arite; - type_elem arg1, arg2, arg3; } func_t; -static func_table[] = { - { DERIV, "deriv", 1, T_POLY, -1, -1}, - { DERIVN, "derivn"
\ No newline at end of file + +static func_t func_table[] = { + { deriv, "deriv", 1, }, + { derivn, "derivn", 2 }, + { integ, "int", 1 }, + { printvars, "printvars", 0 }, + { ans, "ans", 0 }, + { help, "help", 0 }, + { setdisplay, "setdisplay", 1 }, + { reinit, "reinit", 0 }, + { exit_call, "exit", 0 }, + { NULL, NULL, -1 } +} + +void appel_fonction(char *nom, int arite, polynome p1, polynome p2, polynome p3) +{ + int i; + int trouve = 0; + polynome temp; + + while (func_table[i].nom) { + if( strcmp(func_table[i].nom, nom)) + trouve = 1; + i++; + } + if (trouve) + if (func_table[i].arite==arite) { + (*func_table[i].func)(p1, p2, p3); + } else { + exception(1,_("appel_fonction: incorrect arg number")); + } + } else { + exception(1,_("appel_fonction: non-existent function")); + } + + +} + + + + +void deriv(polynome p1, polynome p2, polynome p3) +{ + +} + +void derivn(polynome p1, polynome p2, polynome p3) +{ + +} + +void integ(polynome p1, polynome p2, polynome p3) +{ + +} + +void printvars(polynome p1, polynome p2, polynome p3) +{ + AfficheTableau(variables); +} + +void ans(polynome p1, polynome p2, polynome p3) +{ polynome poly; + int valid; + + polynome = return_last(&valid); + if (valid) + push_pile_poly(poly); + + +} + +void help(polynome p1, polynome p2, polynome p3) +{ + printf(_("Available functions:\n + deriv(p); first derivative of p\n + derivn(p, n); nth derivative of p\n + integ(p); primitive of p\n + printvars(); print all variables\n + ans(); last result\n + help(); this help message\n + setdisplay(n); set integer display format\n + \tn=1: DECIMAL, n=2: HEXA\n + \tn=3: OCTAL, n=4: FLOAT\n + reinit(); clear all variables\n + exit(); end program\n")); +} + +void setdisplay(polynome p1, polynome p2, polynome p3) +{ + if (p1) + if ((!p1->degre)) + switch (p1->coef) { + case 1: + display=DEC; + break; + case 2: + display=HEX; + break; + case 3: + display=OCT; + break; + case 4: + display=FLT; + break; + default: + exception(1, _("setdisplay: invalid arg")); + } + } else { + exception(1, _("setdisplay: invalid arg")); + } + } else { + exception(1, _("setdisplay: invalid arg")); + } +} + +void reinit(polynome p1, polynome p2, polynome p3) +{ + DetruitTab(&variables); + Initialise(&variables); +} + +void exit_call(polynome p1, polynome p2, polynome p3) +{ + clearterm(); + exception(2, _("Exiting, bye!")); +}
\ No newline at end of file @@ -18,6 +18,8 @@ pile_elem result_pile[PILE_MAX]; unsigned int pile_ptr = 0; unsigned int result_pile_ptr = 0; +/* fonctions basiques sur la pile d operandes */ + void push_pile(char *st) { int valid1, valid2, valid3; @@ -140,6 +142,11 @@ void flush_pile(void) pile_ptr=0; } + + +/* fonctions basiques sur la pile de resultats */ + + void move_to_resultat_pile(void) { pile_elem temp; @@ -174,10 +181,26 @@ char * pop_resultat(void) return result; } + +polynome return_last(int *valid) +{ + if (!result_pile_ptr) { + *valid=0; + return NULL; + } else { + *valid=1; + return result_pile[result_pile_ptr--].poly; + } + +} + + int has_resultat(void) { return (result_pile_ptr ? 1 : 0); } +/* fonctions avancees sur la pile d operandes */ + char *affichage_level_1(void) { char *result = NULL; diff --git a/lib/scalaires.c b/lib/scalaires.c index e805b7c..d55c4b2 100644 --- a/lib/scalaires.c +++ b/lib/scalaires.c @@ -14,7 +14,7 @@ #endif #define PRECISION 1E6 -typedisplay display=DEC; +typedisplay display; static int pgcd(int a, int b) { |