summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPixel <Pixel>2001-05-01 17:24:59 +0000
committerPixel <Pixel>2001-05-01 17:24:59 +0000
commitb44d595ac1be31d01c568b0bd0386a1c60715ac6 (patch)
treed83d43d8f580c1b0f08155e3341f5e6378dfe2c9 /lib
parent759be422fcf0fcca5a91b01e5ed7f752d95f0f8d (diff)
Plop
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am2
-rw-r--r--lib/interface.c6
-rw-r--r--lib/polynom.c25
-rw-r--r--lib/scalaires.c12
4 files changed, 39 insertions, 6 deletions
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) {