Annotation of OpenXM_contrib/pari-2.2/src/gp/highlvl.c, Revision 1.1.1.1
1.1 noro 1: /* $Id: highlvl.c,v 1.9 2001/09/05 17:33:32 karim Exp $
2:
3: Copyright (C) 2000 The PARI group.
4:
5: This file is part of the PARI/GP package.
6:
7: PARI/GP is free software; you can redistribute it and/or modify it under the
8: terms of the GNU General Public License as published by the Free Software
9: Foundation. It is distributed in the hope that it will be useful, but WITHOUT
10: ANY WARRANTY WHATSOEVER.
11:
12: Check the License for details. You should have received a copy of it, along
13: with the package; see the file 'COPYING'. If not, write to the Free Software
14: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
15:
16: /*******************************************************************/
17: /* */
18: /* SOME GP FUNCTION THAT MAY BE USEFUL OUTSIDE OF IT */
19: /* */
20: /*******************************************************************/
21: #include "pari.h"
22: #ifdef macintosh
23: # include "rect.h"
24: # include "anal.h"
25: #else
26: # include "../graph/rect.h"
27: # include "../language/anal.h"
28: #endif
29:
30: void kill0(entree *ep);
31: long secure;
32:
33: #ifdef HAS_DLOPEN
34: #include <dlfcn.h>
35: char *expand_tilde(char *s);
36:
37: void
38: install0(char *name, char *code, char *gpname, char *lib)
39: {
40: void *f, *handle;
41:
42: /* dlopen(NULL) returns a handle to the running process.
43: * Bug report Y. Uchikawa: does not work for gp-dyn on FreeBSD 2.2.5
44: */
45: #ifdef __FreeBSD__
46: if (! *lib) lib = DL_DFLT_NAME;
47: #else
48: if (! *lib) lib = NULL;
49: #endif
50: if (! *gpname) gpname=name;
51: if (lib) lib = expand_tilde(lib);
52:
53: handle = dlopen(lib,RTLD_LAZY);
54: if (!handle)
55: {
56: const char *s = dlerror(); if (s) fprintferr("%s\n\n",s);
57: if (lib) err(talker,"couldn't open dynamic library '%s'",lib);
58: err(talker,"couldn't open dynamic symbol table of process");
59: }
60: f = dlsym(handle,name);
61: if (!f)
62: {
63: if (lib) err(talker,"can't find symbol '%s' in library '%s'",name,lib);
64: err(talker,"can't find symbol '%s' in dynamic symbol table of process",name);
65: }
66: if (lib) free(lib);
67: install(f,gpname,code);
68: }
69: #else
70: # ifdef _WIN32
71: # include <windows.h>
72: void
73: install0(char *name, char *code, char *gpname, char *lib)
74: {
75: FARPROC f;
76: HMODULE handle;
77: #ifdef WINCE
78: short wlib[256], wname[256];
79:
80: MultiByteToWideChar(CP_ACP, 0, lib, strlen(lib)+1, wlib, 256);
81: MultiByteToWideChar(CP_ACP, 0, name, strlen(name)+1, wname, 256);
82: lib = wlib;
83: name = wname;
84: #endif
85:
86: #ifdef DL_DFLT_NAME
87: if (! *lib) lib = DL_DFLT_NAME;
88: #endif
89: if (! *gpname) gpname=name;
90: if (lib) lib = expand_tilde(lib);
91:
92: handle = LoadLibrary(lib);
93: if (!handle)
94: {
95: if (lib) err(talker,"couldn't open dynamic library '%s'",lib);
96: err(talker,"couldn't open dynamic symbol table of process");
97: }
98: f = GetProcAddress(handle,name);
99: if (!f)
100: {
101: if (lib) err(talker,"can't find symbol '%s' in library '%s'",name,lib);
102: err(talker,"can't find symbol '%s' in dynamic symbol table of process",name);
103: }
104: if (lib) free(lib);
105: install((void*)f,gpname,code);
106: }
107: # else
108: void
109: install0(char *name, char *code, char *gpname, char *lib) { err(archer); }
110: #endif
111: #endif
112:
113: void
114: gpinstall(char *s, char *code, char *gpname, char *lib)
115: {
116: if (secure)
117: {
118: fprintferr("[secure mode]: about to install '%s'. OK ? (^C if not)\n",s);
119: hit_return();
120: }
121: install0(s, code, gpname, lib);
122: }
123:
124: void
125: addhelp(entree *ep, char *s)
126: {
127: if (ep->help && ! EpSTATIC(ep)) free(ep->help);
128: ep->help = pari_strdup(s);
129: }
130:
131: static long
132: get_type_num(char *st)
133: {
134: if (isdigit((int)*st))
135: {
136: char *s = st;
137: while (*s && isdigit((int)*s)) s++;
138: if (*s) err(talker,"Unknown type: %s",s);
139: return atol(st);
140: }
141: if (!strncmp(st,"t_",2)) st += 2; /* skip initial part */
142:
143: switch(strlen(st))
144: {
145: case 3:
146: if (!strcmp(st,"INT")) return t_INT;
147: if (!strcmp(st,"POL")) return t_POL;
148: if (!strcmp(st,"SER")) return t_SER;
149: if (!strcmp(st,"QFR")) return t_QFR;
150: if (!strcmp(st,"QFI")) return t_QFI;
151: if (!strcmp(st,"VEC")) return t_VEC;
152: if (!strcmp(st,"COL")) return t_COL;
153: if (!strcmp(st,"MAT")) return t_MAT;
154: if (!strcmp(st,"STR")) return t_STR;
155: break;
156:
157: case 4:
158: if (!strcmp(st,"REAL")) return t_REAL;
159: if (!strcmp(st,"FRAC")) return t_FRAC;
160: if (!strcmp(st,"QUAD")) return t_QUAD;
161: if (!strcmp(st,"LIST")) return t_LIST;
162: break;
163:
164: case 5:
165: if (!strcmp(st,"FRACN")) return t_FRACN;
166: if (!strcmp(st,"PADIC")) return t_PADIC;
167: if (!strcmp(st,"RFRAC")) return t_RFRAC;
168: if (!strcmp(st,"SMALL")) return t_SMALL;
169: break;
170:
171: case 6:
172: if (!strcmp(st,"INTMOD")) return t_INTMOD;
173: if (!strcmp(st,"POLMOD")) return t_POLMOD;
174: if (!strcmp(st,"RFRACN")) return t_RFRACN;
175: break;
176:
177: case 7:
178: if (!strcmp(st,"COMPLEX")) return t_COMPLEX;
179: break;
180:
181: case 8:
182: if (!strcmp(st,"VECSMALL")) return t_VECSMALL;
183: break;
184: }
185: err(talker,"Unknown type: t_%s",st);
186: return 0; /* not reached */
187: }
188:
189: GEN
190: type0(GEN x, char *st)
191: {
192: long t, tx;
193: if (! *st)
194: {
195: char *s = type_name(typ(x));
196: return strtoGENstr(s, 0);
197: }
198: tx = typ(x);
199: t = get_type_num(st);
200:
201: if (is_frac_t(tx))
202: {
203: if (!is_frac_t(t) && !is_rfrac_t(t))
204: err(typeer, "type");
205: x = gcopy(x);
206: }
207: else if (is_rfrac_t(tx))
208: {
209: if (is_frac_t(t))
210: {
211: x = simplify(gred(x)); tx = typ(x);
212: if (!is_frac_t(tx)) err(typeer, "type");
213: }
214: else
215: {
216: if (!is_rfrac_t(t)) err(typeer, "type");
217: x = gcopy(x);
218: }
219: }
220: else if (is_vec_t(tx))
221: {
222: if (!is_vec_t(t)) err(typeer, "type");
223: x = gcopy(x);
224: }
225: else if (tx != t) err(typeer, "type");
226: settyp(x, t); return x;
227: }
228:
229: entree functions_highlevel[]={
230: {"addhelp",99,(void*)addhelp,11,"vSs"},
231: {"install",99,(void*)gpinstall,11,"vrrD\"\",r,D\"\",s,"},
232: {"kill",85,(void*)kill0,11,"vS"},
233: {"plot",99,(void*)plot,10,"vV=GGIDGDGp"},
234: {"plotbox",35,(void*)rectbox,10,"vLGG"},
235: {"plotclip",99,(void*)rectclip,10,"vL"},
236: {"plotcolor",19,(void*)rectcolor,10,"vLL"},
237: {"plotcopy",99,(void*)rectcopy_gen,10,"vLLGGD0,L,"},
238: {"plotcursor",11,(void*)rectcursor,10,"L"},
239: {"plotdraw",99,(void*)rectdraw_flag,10,"vGD0,L,"},
240: {"plotfile",16,(void*)plot_outfile_set,10,"ls"},
241: {"ploth",99,(void*)ploth,10,"V=GGIpD0,L,D0,L,"},
242: {"plothraw",25,(void*)plothraw,10,"GGD0,L,"},
243: {"plothsizes",0,(void*)plothsizes_flag,10,"D0,L,"},
244: {"plotinit",99,(void*)initrect_gen,10,"vLD0,G,D0,G,D0,L,"},
245: {"plotkill",99,(void*)killrect,10,"vL"},
246: {"plotlines",99,(void*)rectlines,10,"vLGGD0,L,"},
247: {"plotlinetype",19,(void*)rectlinetype,10,"vLL"},
248: {"plotmove",35,(void*)rectmove,10,"vLGG"},
249: {"plotpoints",35,(void*)rectpoints,10,"vLGG"},
250: {"plotpointsize",99,(void*)rectpointsize,10,"vLG"},
251: {"plotpointtype",19,(void*)rectpointtype,10,"vLL"},
252: {"plotrbox",35,(void*)rectrbox,10,"vLGG"},
253: {"plotrecth",73,(void*)rectploth,10,"LV=GGIpD0,L,D0,L,"},
254: {"plotrecthraw",45,(void*)rectplothraw,10,"LGD0,L,"},
255: {"plotrline",35,(void*)rectrline,10,"vLGG"},
256: {"plotrmove",35,(void*)rectrmove,10,"vLGG"},
257: {"plotrpoint",35,(void*)rectrpoint,10,"vLGG"},
258: {"plotscale",59,(void*)rectscale,10,"vLGGGG"},
259: {"plotstring",57,(void*)rectstring3,10,"vLsD0,L,"},
260: {"plotterm",16,(void*)term_set,10,"ls"},
261: {"psdraw",99,(void*)postdraw_flag,10,"vGD0,L,"},
262: {"psploth",99,(void*)postploth,10,"V=GGIpD0,L,D0,L,"},
263: {"psplothraw",25,(void*)postplothraw,10,"GGD0,L,"},
264: {"type",99,(void*)type0,11,"GD\"\",r,"},
265:
266: {NULL,0,NULL,0,NULL} /* sentinel */
267: };
268:
269: char *helpmessages_highlevel[]={
270: "addhelp(symbol,\"message\"): add/change help message for a symbol",
271: "install(name,code,{gpname},{lib}): load from dynamic library 'lib' the function 'name'. Assign to it the name 'gpname' in this GP session, with argument code 'code'. If 'lib' is omitted use 'libpari.so'. If 'gpname' is omitted, use 'name'",
272: "kill(x): kills the present value of the variable or function x. Returns new value or 0",
273: "plot(X=a,b,expr,{ymin},{ymax}): crude plot of expression expr, X goes from a to b, with Y ranging from ymin to ymax. If ymin (resp. ymax) is not given, the minima (resp. the maxima) of the expression is used instead",
274: "plotbox(w,x2,y2): if the cursor is at position (x1,y1), draw a box with diagonal (x1,y1) and (x2,y2) in rectwindow w (cursor does not move)",
275: "plotclip(w): clip the contents of the rectwindow to the bounding box (except strings)",
276: "plotcolor(w,c): in rectwindow w, set default color to c. Possible values for c are 1=black, 2=blue, 3=sienna, 4=red, 5=cornsilk, 6=grey, 7=gainsborough",
277: "plotcopy(sourcew,destw,dx,dy,{flag=0}): copy the contents of rectwindow sourcew to rectwindow destw with offset (dx,dy). If flag's bit 1 is set, dx and dy express fractions of the size of the current output device, otherwise dx and dy are in pixels. dx and dy are relative positions of northwest corners if other bits of flag vanish, otherwise of: 2: southwest, 4: southeast, 6: northeast corners",
278: "plotcursor(w): current position of cursor in rectwindow w",
279: "plotdraw(list, {flag=0}): draw vector of rectwindows list at indicated x,y positions; list is a vector w1,x1,y1,w2,x2,y2,etc. . If flag!=0, x1, y1 etc. express fractions of the size of the current output device",
280: "plotfile(filename): set the output file for plotting output. \"-\" redirects to the same place as PARI output",
281: "ploth(X=a,b,expr,{flags=0},{n=0}): plot of expression expr, X goes from a to b in high resolution. Both flags and n are optional. Binary digits of flags mean : 1 parametric plot, 2 recursive plot, 8 omit x-axis, 16 omit y-axis, 32 omit frame, 64 do not join points, 128 plot both lines and points, 256 use cubic splines, 512/1024 no x/y ticks, 2048 plot all ticks with the same length. n specifies number of reference points on the graph (0=use default value). Returns a vector for the bounding box",
282: "plothraw(listx,listy,{flag=0}): plot in high resolution points whose x (resp. y) coordinates are in listx (resp. listy). If flag is 1, join points, other non-0 flags should be combinations of bits 8,16,32,64,128,256 meaning the same as for ploth()",
283: "plothsizes({flag=0}): returns array of 6 elements: terminal width and height, sizes for ticks in horizontal and vertical directions, width and height of characters. If flag=0, sizes of ticks and characters are in pixels, otherwise are fractions of the screen size",
284: "plotinit(w,{x=0},{y=0},{flag=0}): initialize rectwindow w to size x,y. If flag!=0, x and y express fractions of the size of the current output device. x=0 or y=0 means use the full size of the device",
285: "plotkill(w): erase the rectwindow w",
286: "plotlines(w,listx,listy,{flag=0}): draws an open polygon in rectwindow w where listx and listy contain the x (resp. y) coordinates of the vertices. If listx and listy are both single values (i.e not vectors), draw the corresponding line (and move cursor). If (optional) flag is non-zero, close the polygon",
287: "plotlinetype(w,type): change the type of following lines in rectwindow w. type -2 corresponds to frames, -1 to axes, larger values may correspond to something else. w=-1 changes highlevel plotting",
288: "plotmove(w,x,y): move cursor to position x,y in rectwindow w",
289: "plotpoints(w,listx,listy): draws in rectwindow w the points whose x (resp y) coordinates are in listx (resp listy). If listx and listy are both single values (i.e not vectors), draw the corresponding point (and move cursor)",
290: "plotpointsize(w,size): change the \"size\" of following points in rectwindow w. w=-1 changes global value",
291: "plotpointtype(w,type): change the type of following points in rectwindow w. type -1 corresponds to a dot, larger values may correspond to something else. w=-1 changes highlevel plotting",
292: "plotrbox(w,dx,dy): if the cursor is at (x1,y1), draw a box with diagonal (x1,y1)-(x1+dx,y1+dy) in rectwindow w (cursor does not move)",
293: "plotrecth(w,X=xmin,xmax,expr,{flags=0},{n=0}): plot graph(s) for expr in rectwindow w, where expr is scalar for a single non-parametric plot, and a vector otherwise. If plotting is parametric, its length should be even and pairs of entries give points coordinates. If not, all entries but the first are y-coordinates. Both flags and n are optional. Binary digits of flags mean: 1 parametric plot, 2 recursive plot, 4 do not rescale w, 8 omit x-axis, 16 omit y-axis, 32 omit frame, 64 do not join points, 128 plot both lines and points. n specifies the number of reference points on the graph (0=use default value). Returns a vector for the bounding box",
294: "plotrecthraw(w,data,{flags=0}): plot graph(s) for data in rectwindow w, where data is a vector of vectors. If plot is parametric, length of data should be even, and pairs of entries give curves to plot. If not, first entry gives x-coordinate, and the other ones y-coordinates. Admits the same optional flags as plotrecth, save that recursive plot is meaningless",
295: "plotrline(w,dx,dy): if the cursor is at (x1,y1), draw a line from (x1,y1) to (x1+dx,y1+dy) (and move the cursor) in the rectwindow w",
296: "plotrmove(w,dx,dy): move cursor to position (dx,dy) relative to the present position in the rectwindow w",
297: "plotrpoint(w,dx,dy): draw a point (and move cursor) at position dx,dy relative to present position of the cursor in rectwindow w",
298: "plotscale(w,x1,x2,y1,y2): scale the coordinates in rectwindow w so that x goes from x1 to x2 and y from y1 to y2 (y2<y1 is allowed)",
299: "plotstring(w,x,{flags=0}): draw in rectwindow w the string corresponding to x. Bits 1 and 2 of flag regulate horizontal alignment: left if 0, right if 2, center if 1. Bits 4 and 8 regulate vertical alignment: bottom if 0, top if 8, v-center if 4. Can insert additional gap between point and string: horizontal if bit 16 is set, vertical if bit 32 is set",
300: "plotterm(\"termname\"): set terminal to plot in high resolution to. Ignored by some drivers. In gnuplot driver possible terminals are the same as in gnuplot, terminal options can be put after the terminal name and space; terminal size can be put immediately after the name, as in \"gif=300,200\". If term is \"?\", lists possible values. Positive return value means success",
301: "psdraw(list, {flag=0}): same as plotdraw, except that the output is a postscript program in psfile (pari.ps by default), and flag!=0 scales the plot from size of the current output device to the standard postscript plotting size",
302: "psploth(X=a,b,expr,{flags=0},{n=0}): same as ploth, except that the output is a postscript program in psfile (pari.ps by default)",
303: "psplothraw(listx,listy,{flag=0}): same as plothraw, except that the output is a postscript program in psfile (pari.ps by default)",
304: "type(x,{t}): if t is not present, output the type of the GEN x. Else make a copy of x with type t. Use with extreme care, usually with t = t_FRACN or t = t_RFRACN). Try \\t for a list of types",
305: };
306:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>