From 6e5f6775d16e9730ccf1edbecf14da52d0ef134a Mon Sep 17 00:00:00 2001 From: Pixel Date: Thu, 3 May 2001 00:20:43 +0000 Subject: Indentation --- lib/fonctions.c | 289 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 152 insertions(+), 137 deletions(-) (limited to 'lib/fonctions.c') diff --git a/lib/fonctions.c b/lib/fonctions.c index 2d25eea..674b2e8 100644 --- a/lib/fonctions.c +++ b/lib/fonctions.c @@ -3,7 +3,7 @@ * fonctions avancees sur les polynomes * */ - + #include "fonctions.h" #include "pile.h" #include "hash.h" @@ -19,196 +19,211 @@ #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); +/* + * 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 { - func_name func; - char *nom; - int arite; + func_name func; + char *nom; + int arite; } func_t; -/* ... et la structure elle-même */ - +/* + * ... et la structure elle-meme + */ + static func_t func_table[] = { - { deriv, "deriv", 1, }, - { derivn, "derivn", 2 }, - { integ, "int", 1 }, - { printvars, "printvars", 0 }, - { help, "help", 0 }, - { setdisplay, "setdisplay", 1 }, - { reinit, "reinit", 0 }, - { exit_call, "exit", 0 }, - { setsmartprint, "setsmartprint", 1 }, - { NULL, NULL, -1 } + {deriv, "deriv", 1,}, + {derivn, "derivn", 2}, + {integ, "int", 1}, + {printvars, "printvars", 0}, + {help, "help", 0}, + {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 */ +/* + * 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; - int trouve = 0; - - while ((func_table[i].nom)&&(!trouve)) { - if(!strcmp(func_table[i].nom, nom)) - trouve = 1; + int i = 0; + int trouve = 0; + + while ((func_table[i].nom) && (!trouve)) { + if (!strcmp(func_table[i].nom, nom)) + trouve = 1; i++; - } - if (trouve) { - if (func_table[i-1].arite==arite) { - (*func_table[i-1].func)(p1, p2, p3); - } else { - exception(1,_("appel_fonction: incorrect arg number")); - } + } + if (trouve) { + if (func_table[i - 1].arite == arite) { + (*func_table[i - 1].func) (p1, p2, p3); } else { - exception(1,_("appel_fonction: non-existent function")); + exception(1, _("appel_fonction: incorrect arg number")); } + } else { + exception(1, _("appel_fonction: non-existent function")); + } } - -/* Fonction de dérivation - rajoute le résultat sur la pile. */ +/* + * Fonction de derivation - rajoute le resultat sur la pile. + */ void deriv(polynome p1, polynome p2, polynome p3) { - polynome resultat = NULL, temp = NULL, t; - - 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; - } - } + polynome resultat = NULL, temp = NULL, t; + + 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; } - p1=p1->suiv; + } } - push_pile_poly(resultat); + p1 = p1->suiv; + } + push_pile_poly(resultat); } - -/* Fonction paresseuse */ +/* + * 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(NULL); - for(i=0; icoef.num; i++) { - temp = pop_pile(1); - ply_destruct(temp.poly); - deriv(temp.poly, NULL, NULL); - } - } else { - exception(1,_("derivn: invalid 2nd arg")); - } +{ + pile_elem temp; + int i; + + if (p1) { + if ((p1->degre == 0) && (p1->coef.num > 0) && (p1->coef.denom == 1)) { + push_pile_poly(NULL); + for (i = 0; i < p1->coef.num; i++) { + temp = pop_pile(1); + ply_destruct(temp.poly); + deriv(temp.poly, NULL, NULL); + } } else { - exception(1,_("derivn: invalid 2nd arg")); - } + exception(1, _("derivn: invalid 2nd arg")); + } + } else { + exception(1, _("derivn: invalid 2nd arg")); + } } - -/* Intégration d'un polynome */ +/* + * Integration d'un polynome + */ void integ(polynome p1, polynome p2, polynome p3) { - polynome resultat = NULL, temp = NULL, t; - - - while (p1) { - t=ply_constr(rat_constr((p1->coef.num), (p1->coef.denom)*(p1->degre+1)), (p1->degre+1)); - if (t) { - if (resultat) { - temp->suiv = t; - temp = t; - } else { - resultat = t; - temp = t; - } - } - p1=p1->suiv; + polynome resultat = NULL, temp = NULL, t; + + while (p1) { + t = + ply_constr(rat_constr((p1->coef.num), (p1->coef.denom) * (p1->degre + 1)), + (p1->degre + 1)); + if (t) { + if (resultat) { + temp->suiv = t; + temp = t; + } else { + resultat = t; + temp = t; + } } - push_pile_poly(resultat); + p1 = p1->suiv; + } + push_pile_poly(resultat); } -/* Quelques fonctions explicites... */ +/* + * Quelques fonctions explicites... + */ void printvars(polynome p1, polynome p2, polynome p3) { - AfficheTableau(variables); + AfficheTableau(variables); } 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" - ". 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" - ". smartprint(bool); toggle smart print of polynoms\n" - ". reinit(); clear all variables\n" - ". exit(); end program\n")); + 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" + ". 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" + ". smartprint(bool); toggle smart print of polynoms\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.num) { - 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 { + if (p1) { + if ((!p1->degre)) { + switch (p1->coef.num) { + 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); + DetruitTab(&variables); + Initialise(&variables); } void exit_call(polynome p1, polynome p2, polynome p3) { - quit = 1; + 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")); - } +void setsmartprint(polynome p1, polynome p2, polynome p3) +{ + if (p1) { + if ((!p1->degre)) { + smartprint = p1->coef.num; } else { - smartprint = 0; - } + exception(1, _("setsmartprint: invalid arg")); + } + } else { + smartprint = 0; + } } -- cgit v1.2.3