Annotation of OpenXM_contrib/pari/src/gp/highlvl.c, Revision 1.1
1.1 ! maekawa 1: /*******************************************************************/
! 2: /* */
! 3: /* SOME GP FUNCTION THAT MAY BE USEFUL OUTSIDE OF IT */
! 4: /* */
! 5: /*******************************************************************/
! 6: /* $Id: highlvl.c,v 1.1.1.1 1999/09/16 13:47:42 karim Exp $ */
! 7: #include "pari.h"
! 8: #ifdef macintosh
! 9: # include "rect.h"
! 10: # include "anal.h"
! 11: #else
! 12: # include "../graph/rect.h"
! 13: # include "../language/anal.h"
! 14: #endif
! 15:
! 16: void kill0(entree *ep);
! 17:
! 18: void
! 19: addhelp(entree *ep, char *s)
! 20: {
! 21: if (ep->help && ! EpSTATIC(ep)) free(ep->help);
! 22: ep->help = pari_strdup(s);
! 23: }
! 24:
! 25: #ifdef HAS_DLOPEN
! 26: #include <dlfcn.h>
! 27: void
! 28: install0(char *name, char *code, char *gpname, char *lib)
! 29: {
! 30: void *f, *handle;
! 31:
! 32: /* dlopen(NULL) returns a handle to the running process.
! 33: * bug report Y. Uchikawa: does not work for gp-dyn on FreeBSD 2.2.5
! 34: */
! 35: #ifdef __FreeBSD__
! 36: if (! *lib) lib = DL_DFLT_NAME;
! 37: #else
! 38: if (! *lib) lib = NULL;
! 39: #endif
! 40: if (! *gpname) gpname=name;
! 41:
! 42: handle = dlopen(lib,RTLD_LAZY);
! 43: if (!handle)
! 44: {
! 45: const char *s = dlerror(); if (s) fprintferr("%s\n\n",s);
! 46: if (lib) err(talker,"couldn't open dynamic library '%s'",lib);
! 47: err(talker,"couldn't open dynamic symbol table of process");
! 48: }
! 49: f = dlsym(handle,name);
! 50: if (!f)
! 51: {
! 52: if (lib) err(talker,"can't find symbol '%s' in library '%s'",name,lib);
! 53: err(talker,"can't find symbol '%s' in dynamic symbol table of process",name);
! 54: }
! 55: install(f,gpname,code);
! 56: }
! 57: #else
! 58: # ifdef _WIN32
! 59: # include <windows.h>
! 60: void
! 61: install0(char *name, char *code, char *gpname, char *lib)
! 62: {
! 63: FARPROC f;
! 64: HMODULE handle;
! 65: #ifdef WINCE
! 66: short wlib[256];
! 67: short wname[256];
! 68: #endif
! 69:
! 70: #ifdef DL_DFLT_NAME
! 71: if (! *lib) lib = DL_DFLT_NAME;
! 72: #endif
! 73: if (! *gpname) gpname=name;
! 74:
! 75: #ifdef WINCE
! 76: MultiByteToWideChar(CP_ACP, 0, lib, strlen(lib)+1, wlib, 256);
! 77: handle = LoadLibrary(wlib);
! 78: #else
! 79: handle = LoadLibrary(lib);
! 80: #endif
! 81: if (!handle)
! 82: {
! 83: if (lib) err(talker,"couldn't open dynamic library '%s'",lib);
! 84: err(talker,"couldn't open dynamic symbol table of process");
! 85: }
! 86: #ifdef WINCE
! 87: MultiByteToWideChar(CP_ACP, 0, name, strlen(name)+1, wname, 256);
! 88: f = GetProcAddress(handle,wname);
! 89: #else
! 90: f = GetProcAddress(handle,name);
! 91: #endif
! 92: if (!f)
! 93: {
! 94: if (lib) err(talker,"can't find symbol '%s' in library '%s'",name,lib);
! 95: err(talker,"can't find symbol '%s' in dynamic symbol table of process",name);
! 96: }
! 97: install((void*)f,gpname,code);
! 98: }
! 99: # else
! 100: void
! 101: install0(char *name, char *code, char *gpname, char *lib) { err(archer); }
! 102: #endif
! 103: #endif
! 104:
! 105: static long
! 106: get_type_num(char *st)
! 107: {
! 108: if (isdigit((int)*st))
! 109: {
! 110: char *s = st;
! 111: while (*s && isdigit((int)*s)) s++;
! 112: if (*s) err(talker,"Unknown type: %s",s);
! 113: return atol(st);
! 114: }
! 115: if (!strncmp(st,"t_",2)) st += 2; /* skip initial part */
! 116:
! 117: switch(strlen(st))
! 118: {
! 119: case 3:
! 120: if (!strcmp(st,"INT")) return t_INT;
! 121: if (!strcmp(st,"POL")) return t_POL;
! 122: if (!strcmp(st,"SER")) return t_SER;
! 123: if (!strcmp(st,"QFR")) return t_QFR;
! 124: if (!strcmp(st,"QFI")) return t_QFI;
! 125: if (!strcmp(st,"VEC")) return t_VEC;
! 126: if (!strcmp(st,"COL")) return t_COL;
! 127: if (!strcmp(st,"MAT")) return t_MAT;
! 128: if (!strcmp(st,"STR")) return t_STR;
! 129: break;
! 130:
! 131: case 4:
! 132: if (!strcmp(st,"REAL")) return t_REAL;
! 133: if (!strcmp(st,"FRAC")) return t_FRAC;
! 134: if (!strcmp(st,"QUAD")) return t_QUAD;
! 135: if (!strcmp(st,"LIST")) return t_LIST;
! 136: break;
! 137:
! 138: case 5:
! 139: if (!strcmp(st,"FRACN")) return t_FRACN;
! 140: if (!strcmp(st,"PADIC")) return t_PADIC;
! 141: if (!strcmp(st,"RFRAC")) return t_RFRAC;
! 142: if (!strcmp(st,"SMALL")) return t_SMALL;
! 143: break;
! 144:
! 145: case 6:
! 146: if (!strcmp(st,"INTMOD")) return t_INTMOD;
! 147: if (!strcmp(st,"POLMOD")) return t_POLMOD;
! 148: if (!strcmp(st,"RFRACN")) return t_RFRACN;
! 149: break;
! 150:
! 151: case 7:
! 152: if (!strcmp(st,"COMPLEX")) return t_COMPLEX;
! 153: break;
! 154:
! 155: case 8:
! 156: if (!strcmp(st,"VECSMALL")) return t_VECSMALL;
! 157: break;
! 158: }
! 159: err(talker,"Unknown type: t_%s",st);
! 160: return 0; /* not reached */
! 161: }
! 162:
! 163: GEN
! 164: type0(GEN x, char *st)
! 165: {
! 166: if (! *st)
! 167: {
! 168: char *s = type_name(typ(x));
! 169: return strtoGENstr(s, 0);
! 170: }
! 171: x = gcopy(x); settyp(x,get_type_num(st));
! 172: return x;
! 173: }
! 174:
! 175: entree functions_highlevel[]={
! 176: {"addhelp",99,(void*)addhelp,11,"vSs"},
! 177: {"install",99,(void*)install0,11,"vrrD\"\",r,D\"\",s,"},
! 178: {"kill",85,(void*)kill0,11,"vS"},
! 179: {"plot",99,(void*)plot,10,"vV=GGIp"},
! 180: {"plotbox",35,(void*)rectbox,10,"vLGG"},
! 181: {"plotclip",99,(void*)rectclip,10,"vL"},
! 182: {"plotcolor",19,(void*)rectcolor,10,"vLL"},
! 183: {"plotcopy",99,(void*)rectcopy,10,"vLLLL"},
! 184: {"plotcursor",11,(void*)rectcursor,10,"L"},
! 185: {"plotdraw",99,(void*)rectdraw,10,"vG"},
! 186: {"plotfile",16,(void*)plot_outfile_set,10,"ls"},
! 187: {"ploth",99,(void*)ploth,10,"V=GGIpD0,L,D0,L,"},
! 188: {"plothraw",25,(void*)plothraw,10,"GGD0,L,"},
! 189: {"plothsizes",0,(void*)plothsizes,10,""},
! 190: {"plotinit",34,(void*)initrect,10,"vLLL"},
! 191: {"plotkill",99,(void*)killrect,10,"vL"},
! 192: {"plotlines",99,(void*)rectlines,10,"vLGGD0,L,"},
! 193: {"plotlinetype",19,(void*)rectlinetype,10,"vLL"},
! 194: {"plotmove",35,(void*)rectmove,10,"vLGG"},
! 195: {"plotpoints",35,(void*)rectpoints,10,"vLGG"},
! 196: {"plotpointsize",99,(void*)rectpointsize,10,"vLG"},
! 197: {"plotpointtype",19,(void*)rectpointtype,10,"vLL"},
! 198: {"plotrbox",35,(void*)rectrbox,10,"vLGG"},
! 199: {"plotrecth",73,(void*)rectploth,10,"LV=GGIpD0,L,D0,L,"},
! 200: {"plotrecthraw",45,(void*)rectplothraw,10,"LGD0,L,"},
! 201: {"plotrline",35,(void*)rectrline,10,"vLGG"},
! 202: {"plotrmove",35,(void*)rectrmove,10,"vLGG"},
! 203: {"plotrpoint",35,(void*)rectrpoint,10,"vLGG"},
! 204: {"plotscale",59,(void*)rectscale,10,"vLGGGG"},
! 205: {"plotstring",57,(void*)rectstring,10,"vLs"},
! 206: {"plotterm",16,(void*)term_set,10,"ls"},
! 207: {"psdraw",99,(void*)postdraw,10,"vG"},
! 208: {"psploth",99,(void*)postploth,10,"V=GGIpD0,L,D0,L,"},
! 209: {"psplothraw",25,(void*)postplothraw,10,"GGD0,L,"},
! 210: {"type",99,(void*)type0,11,"GD\"\",r,"},
! 211:
! 212: {NULL,0,NULL,0,NULL} /* sentinel */
! 213: };
! 214:
! 215: char *helpmessages_highlevel[]={
! 216: "addhelp(symbol,\"message\"): add/change help message for a symbol",
! 217: "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'",
! 218: "kill(x): kills the present value of the variable or function x. Returns new value or 0",
! 219: "plot(X=a,b,expr): crude plot of expression expr, X goes from a to b",
! 220: "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)",
! 221: "plotclip(w): clip the contents of the rectwindow to the bounding box (except strings)",
! 222: "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",
! 223: "plotcopy(sourcew,destw,dx,dy): copy the contents of rectwindow sourcew to rectwindow destw with offset (dx,dy)",
! 224: "plotcursor(w): current position of cursor in rectwindow w",
! 225: "plotdraw(list): draw vector of rectwindows list at indicated x,y positions; list is a vector w1,x1,y1,w2,x2,y2,etc. . ",
! 226: "plotfile(filename): set the output file for plotting output. \"-\" redirects to the same place as PARI output",
! 227: "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. n specifies number of reference points on the graph (0=use default value). Returns a vector for the bounding box",
! 228: "plothraw(listx,listy,{flag=0}): plot in high resolution points whose x (resp. y) coordinates are in listx (resp. listy). If flag is non zero, join points",
! 229: "plothsizes(): returns array of 6 elements: terminal width and height, sizes for ticks in horizontal and vertical directions (in pixels), width and height of characters",
! 230: "plotinit(w,x,y): initialize rectwindow w to size x,y",
! 231: "plotkill(w): erase the rectwindow w",
! 232: "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",
! 233: "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",
! 234: "plotmove(w,x,y): move cursor to position x,y in rectwindow w",
! 235: "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)",
! 236: "plotpointsize(w,size): change the \"size\" of following points in rectwindow w. w=-1 changes global value",
! 237: "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",
! 238: "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)",
! 239: "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",
! 240: "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",
! 241: "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",
! 242: "plotrmove(w,dx,dy): move cursor to position (dx,dy) relative to the present position in the rectwindow w",
! 243: "plotrpoint(w,dx,dy): draw a point (and move cursor) at position dx,dy relative to present position of the cursor in rectwindow w",
! 244: "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)",
! 245: "plotstring(w,x): draw in rectwindow w the string corresponding to x",
! 246: "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. Positive value means success",
! 247: "psdraw(list): same as plotdraw, except that the output is a postscript program in psfile (pari.ps by default)",
! 248: "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)",
! 249: "psplothraw(listx,listy,{flag=0}): same as plothraw, except that the output is a postscript program in psfile (pari.ps by default)",
! 250: "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",
! 251: };
! 252:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>