[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
(mgp-users 00120) stupid locale/gs interaction...
- To: mgp-users@mew.org
- Subject: (mgp-users 00120) stupid locale/gs interaction...
- From: Fabien COELHO <coelho@cri.ensmp.fr>
- Date: Wed, 10 Mar 1999 18:11:21 +0900
- Posted: Wed, 10 Mar 1999 10:10:55 +0100
- Reply-to: coelho@cri.ensmp.fr
Hi,
I could not display postscript files with mgp, so I investigated the bug.
After a few hours of investigation, I finally found a pretty !"£$%^&*
problem, which is due to the locale feature. Indeed, I compiled with
--enable-locale, and I have LANG=fr in my environment, so that French word
boundaries are understood properly by mgp. When it comes to translating a
postscript file, mgp forks/execs a gs and pipes commands to it, including
a scale, which is output as:
3,040000 2,000000 scale
instead of
3.040000 2.000000 scale
because in French a comma is used for separating the fractional part of
floating point numbers. However, it happends that the gs parser is not
aware of French conventions;-)
I appended a patch to fix this problem, but it is not really beautiful.
I have not found how to specify the separator in a format.
Thanks for considering it or a similar fix to this problem...
Have a nice day,
Fabien.
--- draw.c.orig Mon Mar 8 16:42:06 1999
+++ draw.c Wed Mar 10 10:02:18 1999
@@ -120,6 +120,8 @@
return 1;
if (3 < p - p0 && strcasecmp(p - 3, ".ps") == 0)
return 1;
+ if (6 < p - p0 && strcasecmp(p - 6, ".idraw") == 0)
+ return 1;
return 0;
}
@@ -3244,6 +3246,18 @@
x_registerseed(state, NULL, NULL);
}
+/* print double d to fd with a *dot*
+ * so as to avoid interaction with the locale setting.
+ */
+static void fprint_fdot(FILE * fd, double d)
+{
+ char buffer[32], * comma;
+ sprintf(buffer, "%f", d);
+ comma = strchr(buffer, ',');
+ if (comma) *comma = '.';
+ fprintf(fd, "%s", buffer);
+}
+
static char *
epstoimage(state, epsfile, x, y, width, height, xzoom, yzoom)
struct render_state *state;
@@ -3422,8 +3436,10 @@
}
sigpipe_handler = signal(SIGPIPE, SIG_IGN); /* XXX: avoid SIGPIPE */
pfd[0][1] = -1;
- fprintf(fp, "%f %f scale\n", (double)xzoom/100., (double)yzoom/100.);
- fprintf(fp, "%d %d translate\n", -1 * x, -1 * y);
+ fprint_fdot(fp, (double)xzoom/100.);
+ fprintf(fp, " ");
+ fprint_fdot(fp, (double)yzoom/100.);
+ fprintf(fp, " scale\n%d %d translate\n", -1 * x, -1 * y);
fprintf(fp, "(%s) run\n", epsfile);
fprintf(fp, "showpage\n");
fprintf(fp, "quit\n");