summaryrefslogtreecommitdiff
path: root/lib/fonctions.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fonctions.c')
-rw-r--r--lib/fonctions.c138
1 files changed, 134 insertions, 4 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