diff options
-rw-r--r-- | include/Makefile.am | 2 | ||||
-rw-r--r-- | include/interface.h | 4 | ||||
-rw-r--r-- | include/scalaires.h | 2 | ||||
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/interface.c | 6 | ||||
-rw-r--r-- | lib/polynom.c | 25 | ||||
-rw-r--r-- | lib/scalaires.c | 12 |
7 files changed, 45 insertions, 8 deletions
diff --git a/include/Makefile.am b/include/Makefile.am index 77cdc01..1747117 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1 +1 @@ -include_HEADERS = exceptions.h hash.h main.h numbers.h parser.h pile.h polynom.h scalaires.h +include_HEADERS = exceptions.h hash.h main.h numbers.h parser.h pile.h polynom.h scalaires.h terminal.h interface.h diff --git a/include/interface.h b/include/interface.h new file mode 100644 index 0000000..e0bad75 --- /dev/null +++ b/include/interface.h @@ -0,0 +1,4 @@ +#ifndef __INTERFACE_H__ +#define __INTERFACE_H__ + +#endif diff --git a/include/scalaires.h b/include/scalaires.h index 30e7f82..4596fa1 100644 --- a/include/scalaires.h +++ b/include/scalaires.h @@ -25,6 +25,6 @@ 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 */ -char *rat_to_string(rationnel rat); +char *rat_to_string(rationnel rat, int first); #endif diff --git a/lib/Makefile.am b/lib/Makefile.am index a893ab5..1353da6 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -4,7 +4,7 @@ AM_CFLAGS = -O3 -DDEBUG -Wall -Wstrict-prototypes $(CFLAGS) INCLUDES = -I. -I.. -I$(includedir) -I../include lib_LTLIBRARIES = libPolynom.la -libPolynom_la_SOURCES = exceptions.c hash.c numbers.c parser.c pile.c polynom.c scalaires.c +libPolynom_la_SOURCES = exceptions.c hash.c numbers.c parser.c pile.c polynom.c scalaires.c terminal.c interface.c libPolynom_la_LDFLAGS = -version-info $(Polynom_VERSION_INFO) diff --git a/lib/interface.c b/lib/interface.c new file mode 100644 index 0000000..8a89c8e --- /dev/null +++ b/lib/interface.c @@ -0,0 +1,6 @@ +#include <stdio.h> +#include <string.h> +#include "config.h" +#include "interface.h" +#include "exceptions.h" + diff --git a/lib/polynom.c b/lib/polynom.c index ab0ac07..dbb4334 100644 --- a/lib/polynom.c +++ b/lib/polynom.c @@ -17,6 +17,8 @@ #define _(x) x #endif +int smartprint = 1; + /* FIXME: manque div et mod */ polynome ply_constr(rationnel coef, int degre) @@ -272,6 +274,7 @@ char *ply_affichage(polynome poly) static char buf[BUFSIZ]; char temp[BUFSIZ]; int count = 0; + int first = 1; buf[0] = '\0'; if (!poly) { @@ -279,9 +282,26 @@ char *ply_affichage(polynome poly) } else { while (poly) { if (poly->degre != 0) { - sprintf(temp, "%s*%s^%u ", rat_to_string(poly->coef), mute, poly->degre); + if (smartprint) { + switch(poly->degre) { + case 1: + sprintf(temp, "%s%s ", rat_to_string(poly->coef, first), mute); + break; + case 2: + sprintf(temp, "%s%s² ", rat_to_string(poly->coef, first), mute); + break; + case 3: + sprintf(temp, "%s%s³ ", rat_to_string(poly->coef, first), mute); + break; + default: + sprintf(temp, "%s%s^%u ", rat_to_string(poly->coef, first), mute, poly->degre); + break; + } + } else { + sprintf(temp, "%s*%s^%u ", rat_to_string(poly->coef, first), mute, poly->degre); + } } else { - sprintf(temp, "%s ", rat_to_string(poly->coef)); + sprintf(temp, "%s ", rat_to_string(poly->coef, first)); } count += strlen(temp); if (count < BUFSIZ) @@ -289,6 +309,7 @@ char *ply_affichage(polynome poly) else exception(2, _("ply_affichage: strcat error, not enough space in buffer")); poly = poly->suiv; + first = 0; } } return buf; diff --git a/lib/scalaires.c b/lib/scalaires.c index 49c243f..e805b7c 100644 --- a/lib/scalaires.c +++ b/lib/scalaires.c @@ -117,7 +117,7 @@ rationnel rat_division(rationnel rat1, rationnel rat2) } -char *rat_to_string(rationnel rat) +char *rat_to_string(rationnel rat, int first) { static char resultat[128]; char temp[64]; @@ -126,9 +126,15 @@ char *rat_to_string(rationnel rat) if (rat.num<0) { rat.num=-rat.num; - strcat(resultat,"-"); + if (first) { + strcat(resultat,"-"); + } else { + strcat(resultat,"- "); + } } else { - strcat(resultat,"+"); + if (!first) { + strcat(resultat,"+ "); + } } switch(display) { |