| Ilya Zakharevich on Tue, 29 Feb 2000 13:08:02 -0500 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| [PATCH 2.0.18] pretty printing results |
I beafed up my tex2mail converter. See
ftp://ftp.math.ohio-state.edu/pub/users/ilya/tex/tex2mail
With the enclosed patch one can do this and a lot of other stuff:
? default(prettyprinter,"tex2mail -TeX -noindent -ragged -by_par")
prettyprinter = "tex2mail -TeX -noindent -ragged -by_par"
? sin(x+x*tan(x))
2 1 3 1 4 59 5 19 6 1261 7 421 8 6955 9
%2 = x + x - -x - -x - ---x - ---x - ----x - ----x - -----x -
6 6 120 120 5040 5040 72576
13607 10 119743 11 538121 12 36391213 13 4067263 14
------x - -------x - --------x + ----------x - ----------x +
362880 5702400 39916800 6227020800 1245404160
14328323099 15 24080089 16 1
-------------x + ------------x +O(x 7)
1307674368000 118879488000
Enjoy,
Ilya
--- ./src/gp/gp.c.orig Mon Dec 20 13:40:00 1999
+++ ./src/gp/gp.c Tue Feb 29 12:59:39 2000
@@ -16,6 +16,7 @@
#endif
#include "../language/anal.h"
#include "gp.h"
+#include "errno.h"
#ifdef READLINE
void init_readline();
@@ -57,6 +58,8 @@ static GEN *hist;
static char *help_prg,*path;
static char prompt[MAX_PROMPT_LEN];
static char thestring[256];
+static char *prettyprinter;
+static FILE *prettyprinter_file;
static long prettyp, test_mode, quiet_mode, gpsilent, simplifyflag;
static long chrono, pariecho, primelimit, parisize, strictmatch;
static long tglobal, histsize, paribufsize, lim_lines;
@@ -133,6 +136,8 @@ gp_preinit(int force)
tglobal = 0;
bufstack = NULL;
secure = test_mode = under_emacs = chrono = pariecho = 0;
+ prettyprinter = 0;
+ prettyprinter_file = 0;
fmt.format = 'g'; fmt.field = 0;
#ifdef LONG_IS_64BIT
fmt.nb = 38;
@@ -754,6 +759,27 @@ sd_path(char *v, int flag)
}
static GEN
+sd_prettyprinter(char *v, int flag)
+{
+ if (*v || flag == d_ACKNOWLEDGE || flag == d_SILENT)
+ {
+ char *old = prettyprinter;
+
+ if (old && strcmp(old,v) != 0 && prettyprinter_file) {
+ if (fclose(prettyprinter_file) != 0)
+ fprintferr("Could not close pipe to '%s': %s\n", old, strerror(errno));
+ prettyprinter_file = 0;
+ }
+ prettyprinter = pari_strdup(v); free(old);
+ if (flag == d_INITRC) return gnil;
+ }
+ if (flag == d_RETURN) return strtoGEN(prettyprinter ? prettyprinter : "");
+ if (flag == d_ACKNOWLEDGE)
+ pariputsf(" prettyprinter = \"%s\"\n",prettyprinter ? prettyprinter : "");
+ return gnil;
+}
+
+static GEN
sd_prompt(char *v, int flag)
{
if (*v)
@@ -788,6 +814,7 @@ default_type gp_default_list[] =
{"parisize",(void*)sd_parisize},
{"path",(void*)sd_path},
{"primelimit",(void*)sd_primelimit},
+ {"prettyprinter",(void*)sd_prettyprinter},
{"prompt",(void*)sd_prompt},
{"psfile",(void*)sd_psfile},
{"realprecision",(void*)sd_realprecision},
@@ -2112,16 +2139,53 @@ gp_main_loop(int ismain)
else
{
PariOUT *old = pariOut;
+ FILE *o_out = pari_outfile;
+ int o_prettyp = prettyp;
+
if (DEBUGLEVEL > 4) fprintferr("prec = [%ld, %ld]\n", prec,precdl);
- term_color(c_HIST);
+ if (prettyprinter && prettyprinter[0]) {
+ if (!prettyprinter_file)
+ prettyprinter_file = popen(prettyprinter, "w");
+ if (!prettyprinter_file) {
+ fprintferr("Could not open pipe to '%s': %s\n", prettyprinter, strerror(errno));
+ prettyprinter = 0;
+ } else {
+ pariflush();
+ pari_outfile = prettyprinter_file;
+ prettyp = f_TEX;
+ pariputs("\\"); /* Protect %12= */
+ }
+ }
+ if (!prettyprinter || prettyprinter[0] == 0)
+ term_color(c_HIST);
sprintf(thestring, "%%%ld = ",tglobal);
pariputs_opt(thestring);
- term_color(c_OUTPUT);
- init_lim_lines(thestring,lim_lines);
- gp_output(z); pariOut=old;
+ if (!prettyprinter || prettyprinter[0] == 0) {
+ term_color(c_OUTPUT);
+ init_lim_lines(thestring,lim_lines);
+ }
+ gp_output(z);
+ if (prettyprinter && prettyprinter[0]) {
+ pariputs("\n\n"); pariflush();
+ { /* Wait until the program finish. Otherwise prompt can overwrite
+ the output. Fill the output buffer, wait until it is read. */
+ char *s = " \n";
+ int i = 400;
+
+ while (--i)
+ pariputs(s);
+ pariputs("\n");
+ pariflush();
+ } /* better than sleep(2); Give possibility to print */
+ }
+ pariOut=old;
+ pari_outfile = o_out;
+ prettyp = o_prettyp;
term_color(c_NONE);
}
- pariputc('\n'); pariflush();
+ if (!prettyprinter || prettyprinter[0] == 0)
+ pariputc('\n');
+ pariflush();
}
pop_buffer();
}