Annotation of OpenXM_contrib/pari-2.2/src/gp/highlvl.c, Revision 1.2
1.2 ! noro 1: /* $Id: highlvl.c,v 1.15 2002/08/15 10:13:25 karim Exp $
1.1 noro 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:
1.2 ! noro 30: extern void kill0(entree *ep);
1.1 noro 31:
32: #ifdef HAS_DLOPEN
33: #include <dlfcn.h>
1.2 ! noro 34: extern char *expand_tilde(char *s);
1.1 noro 35:
36: void
37: install0(char *name, char *code, char *gpname, char *lib)
38: {
39: void *f, *handle;
40:
41: /* dlopen(NULL) returns a handle to the running process.
42: * Bug report Y. Uchikawa: does not work for gp-dyn on FreeBSD 2.2.5
43: */
44: #ifdef __FreeBSD__
45: if (! *lib) lib = DL_DFLT_NAME;
46: #else
47: if (! *lib) lib = NULL;
48: #endif
49: if (! *gpname) gpname=name;
50: if (lib) lib = expand_tilde(lib);
1.2 ! noro 51:
! 52: /* OSF1 has dlopen but not RTLD_GLOBAL*/
! 53: #ifndef RTLD_GLOBAL
! 54: #define RTLD_GLOBAL 0
! 55: #endif
! 56:
! 57: handle = dlopen(lib,RTLD_LAZY|RTLD_GLOBAL);
! 58:
1.1 noro 59: if (!handle)
60: {
61: const char *s = dlerror(); if (s) fprintferr("%s\n\n",s);
62: if (lib) err(talker,"couldn't open dynamic library '%s'",lib);
63: err(talker,"couldn't open dynamic symbol table of process");
64: }
65: f = dlsym(handle,name);
66: if (!f)
67: {
68: if (lib) err(talker,"can't find symbol '%s' in library '%s'",name,lib);
69: err(talker,"can't find symbol '%s' in dynamic symbol table of process",name);
70: }
71: if (lib) free(lib);
72: install(f,gpname,code);
73: }
74: #else
75: # ifdef _WIN32
76: # include <windows.h>
77: void
78: install0(char *name, char *code, char *gpname, char *lib)
79: {
80: FARPROC f;
81: HMODULE handle;
82: #ifdef WINCE
83: short wlib[256], wname[256];
84:
85: MultiByteToWideChar(CP_ACP, 0, lib, strlen(lib)+1, wlib, 256);
86: MultiByteToWideChar(CP_ACP, 0, name, strlen(name)+1, wname, 256);
87: lib = wlib;
88: name = wname;
89: #endif
90:
91: #ifdef DL_DFLT_NAME
92: if (! *lib) lib = DL_DFLT_NAME;
93: #endif
94: if (! *gpname) gpname=name;
95: if (lib) lib = expand_tilde(lib);
96:
97: handle = LoadLibrary(lib);
98: if (!handle)
99: {
100: if (lib) err(talker,"couldn't open dynamic library '%s'",lib);
101: err(talker,"couldn't open dynamic symbol table of process");
102: }
103: f = GetProcAddress(handle,name);
104: if (!f)
105: {
106: if (lib) err(talker,"can't find symbol '%s' in library '%s'",name,lib);
107: err(talker,"can't find symbol '%s' in dynamic symbol table of process",name);
108: }
109: if (lib) free(lib);
110: install((void*)f,gpname,code);
111: }
112: # else
113: void
114: install0(char *name, char *code, char *gpname, char *lib) { err(archer); }
115: #endif
116: #endif
117:
118: void
119: gpinstall(char *s, char *code, char *gpname, char *lib)
120: {
1.2 ! noro 121: if (GP_DATA->flags & SECURE)
1.1 noro 122: {
123: fprintferr("[secure mode]: about to install '%s'. OK ? (^C if not)\n",s);
124: hit_return();
125: }
126: install0(s, code, gpname, lib);
127: }
128:
129: void
130: addhelp(entree *ep, char *s)
131: {
132: if (ep->help && ! EpSTATIC(ep)) free(ep->help);
133: ep->help = pari_strdup(s);
134: }
135:
136: static long
137: get_type_num(char *st)
138: {
139: if (isdigit((int)*st))
140: {
141: char *s = st;
142: while (*s && isdigit((int)*s)) s++;
143: if (*s) err(talker,"Unknown type: %s",s);
144: return atol(st);
145: }
146: if (!strncmp(st,"t_",2)) st += 2; /* skip initial part */
147:
148: switch(strlen(st))
149: {
150: case 3:
151: if (!strcmp(st,"INT")) return t_INT;
152: if (!strcmp(st,"POL")) return t_POL;
153: if (!strcmp(st,"SER")) return t_SER;
154: if (!strcmp(st,"QFR")) return t_QFR;
155: if (!strcmp(st,"QFI")) return t_QFI;
156: if (!strcmp(st,"VEC")) return t_VEC;
157: if (!strcmp(st,"COL")) return t_COL;
158: if (!strcmp(st,"MAT")) return t_MAT;
159: if (!strcmp(st,"STR")) return t_STR;
160: break;
161:
162: case 4:
163: if (!strcmp(st,"REAL")) return t_REAL;
164: if (!strcmp(st,"FRAC")) return t_FRAC;
165: if (!strcmp(st,"QUAD")) return t_QUAD;
166: if (!strcmp(st,"LIST")) return t_LIST;
167: break;
168:
169: case 5:
170: if (!strcmp(st,"FRACN")) return t_FRACN;
171: if (!strcmp(st,"PADIC")) return t_PADIC;
172: if (!strcmp(st,"RFRAC")) return t_RFRAC;
173: if (!strcmp(st,"SMALL")) return t_SMALL;
174: break;
175:
176: case 6:
177: if (!strcmp(st,"INTMOD")) return t_INTMOD;
178: if (!strcmp(st,"POLMOD")) return t_POLMOD;
179: if (!strcmp(st,"RFRACN")) return t_RFRACN;
180: break;
181:
182: case 7:
183: if (!strcmp(st,"COMPLEX")) return t_COMPLEX;
184: break;
185:
186: case 8:
187: if (!strcmp(st,"VECSMALL")) return t_VECSMALL;
188: break;
189: }
190: err(talker,"Unknown type: t_%s",st);
191: return 0; /* not reached */
192: }
193:
194: GEN
195: type0(GEN x, char *st)
196: {
197: long t, tx;
198: if (! *st)
199: {
200: char *s = type_name(typ(x));
201: return strtoGENstr(s, 0);
202: }
203: tx = typ(x);
204: t = get_type_num(st);
205:
206: if (is_frac_t(tx))
207: {
208: if (!is_frac_t(t) && !is_rfrac_t(t))
209: err(typeer, "type");
210: x = gcopy(x);
211: }
212: else if (is_rfrac_t(tx))
213: {
214: if (is_frac_t(t))
215: {
216: x = simplify(gred(x)); tx = typ(x);
217: if (!is_frac_t(tx)) err(typeer, "type");
218: }
219: else
220: {
221: if (!is_rfrac_t(t)) err(typeer, "type");
222: x = gcopy(x);
223: }
224: }
225: else if (is_vec_t(tx))
226: {
227: if (!is_vec_t(t)) err(typeer, "type");
228: x = gcopy(x);
229: }
230: else if (tx != t) err(typeer, "type");
231: settyp(x, t); return x;
232: }
233:
234: entree functions_highlevel[]={
235: {"addhelp",99,(void*)addhelp,11,"vSs"},
236: {"install",99,(void*)gpinstall,11,"vrrD\"\",r,D\"\",s,"},
237: {"kill",85,(void*)kill0,11,"vS"},
238: {"plot",99,(void*)plot,10,"vV=GGIDGDGp"},
239: {"plotbox",35,(void*)rectbox,10,"vLGG"},
240: {"plotclip",99,(void*)rectclip,10,"vL"},
241: {"plotcolor",19,(void*)rectcolor,10,"vLL"},
242: {"plotcopy",99,(void*)rectcopy_gen,10,"vLLGGD0,L,"},
243: {"plotcursor",11,(void*)rectcursor,10,"L"},
244: {"plotdraw",99,(void*)rectdraw_flag,10,"vGD0,L,"},
245: {"plotfile",16,(void*)plot_outfile_set,10,"ls"},
1.2 ! noro 246: {"ploth",99,(void*)ploth,10,"V=GGIpD0,M,D0,L,\nParametric|1; Recursive|2; no_Rescale|4; no_X_axis|8; no_Y_axis|16; no_Frame|32; no_Lines|64; Points_too|128; Splines|256; no_X_ticks|512; no_Y_ticks|1024; Same_ticks|2048"},
1.1 noro 247: {"plothraw",25,(void*)plothraw,10,"GGD0,L,"},
248: {"plothsizes",0,(void*)plothsizes_flag,10,"D0,L,"},
249: {"plotinit",99,(void*)initrect_gen,10,"vLD0,G,D0,G,D0,L,"},
250: {"plotkill",99,(void*)killrect,10,"vL"},
251: {"plotlines",99,(void*)rectlines,10,"vLGGD0,L,"},
252: {"plotlinetype",19,(void*)rectlinetype,10,"vLL"},
253: {"plotmove",35,(void*)rectmove,10,"vLGG"},
254: {"plotpoints",35,(void*)rectpoints,10,"vLGG"},
255: {"plotpointsize",99,(void*)rectpointsize,10,"vLG"},
256: {"plotpointtype",19,(void*)rectpointtype,10,"vLL"},
257: {"plotrbox",35,(void*)rectrbox,10,"vLGG"},
258: {"plotrecth",73,(void*)rectploth,10,"LV=GGIpD0,L,D0,L,"},
259: {"plotrecthraw",45,(void*)rectplothraw,10,"LGD0,L,"},
260: {"plotrline",35,(void*)rectrline,10,"vLGG"},
261: {"plotrmove",35,(void*)rectrmove,10,"vLGG"},
262: {"plotrpoint",35,(void*)rectrpoint,10,"vLGG"},
263: {"plotscale",59,(void*)rectscale,10,"vLGGGG"},
264: {"plotstring",57,(void*)rectstring3,10,"vLsD0,L,"},
265: {"plotterm",16,(void*)term_set,10,"ls"},
266: {"psdraw",99,(void*)postdraw_flag,10,"vGD0,L,"},
267: {"psploth",99,(void*)postploth,10,"V=GGIpD0,L,D0,L,"},
268: {"psplothraw",25,(void*)postplothraw,10,"GGD0,L,"},
269: {"type",99,(void*)type0,11,"GD\"\",r,"},
270:
271: {NULL,0,NULL,0,NULL} /* sentinel */
272: };
273:
274: char *helpmessages_highlevel[]={
275: "addhelp(symbol,\"message\"): add/change help message for a symbol",
276: "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'",
277: "kill(x): kills the present value of the variable or function x. Returns new value or 0",
278: "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",
279: "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)",
280: "plotclip(w): clip the contents of the rectwindow to the bounding box (except strings)",
281: "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",
282: "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",
283: "plotcursor(w): current position of cursor in rectwindow w",
284: "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",
285: "plotfile(filename): set the output file for plotting output. \"-\" redirects to the same place as PARI output",
1.2 ! noro 286: "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, 2=Recursive, 4=no_Rescale, 8=no_X_axis, 16=no_Y_axis, 32=no_Frame, 64=no_Lines (do not join points), 128=Points_too (plot both lines and points), 256=Splines (use cubic splines), 512=no_X_ticks, 1024= no_Y_ticks, 2048=Same_ticks (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",
1.1 noro 287: "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()",
288: "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",
289: "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",
290: "plotkill(w): erase the rectwindow w",
291: "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",
292: "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",
293: "plotmove(w,x,y): move cursor to position x,y in rectwindow w",
294: "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)",
295: "plotpointsize(w,size): change the \"size\" of following points in rectwindow w. w=-1 changes global value",
296: "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",
297: "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)",
298: "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",
299: "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",
300: "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",
301: "plotrmove(w,dx,dy): move cursor to position (dx,dy) relative to the present position in the rectwindow w",
302: "plotrpoint(w,dx,dy): draw a point (and move cursor) at position dx,dy relative to present position of the cursor in rectwindow w",
303: "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)",
304: "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",
305: "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",
306: "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",
307: "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)",
308: "psplothraw(listx,listy,{flag=0}): same as plothraw, except that the output is a postscript program in psfile (pari.ps by default)",
309: "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",
310: };
311:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>