summaryrefslogtreecommitdiff
path: root/lib/fonctions.c
blob: 2600f98eadaa14b1bb770469ea89d29a7f60d980 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 *
 * fonctions avancees sur les polynomes
 *
 */
 
#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;
} func_t;

		      
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!"));
}