From b44d595ac1be31d01c568b0bd0386a1c60715ac6 Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 1 May 2001 17:24:59 +0000 Subject: Plop --- lib/Makefile.am | 2 +- lib/interface.c | 6 ++++++ lib/polynom.c | 25 +++++++++++++++++++++++-- lib/scalaires.c | 12 +++++++++--- 4 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 lib/interface.c (limited to 'lib') 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 +#include +#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) { -- cgit v1.2.3