Annotation of OpenXM_contrib2/asir2000/builtin/ctrl.c, Revision 1.42
1.8 noro 1: /*
2: * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
3: * All rights reserved.
4: *
5: * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
6: * non-exclusive and royalty-free license to use, copy, modify and
7: * redistribute, solely for non-commercial and non-profit purposes, the
8: * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
9: * conditions of this Agreement. For the avoidance of doubt, you acquire
10: * only a limited right to use the SOFTWARE hereunder, and FLL or any
11: * third party developer retains all rights, including but not limited to
12: * copyrights, in and to the SOFTWARE.
13: *
14: * (1) FLL does not grant you a license in any way for commercial
15: * purposes. You may use the SOFTWARE only for non-commercial and
16: * non-profit purposes only, such as academic, research and internal
17: * business use.
18: * (2) The SOFTWARE is protected by the Copyright Law of Japan and
19: * international copyright treaties. If you make copies of the SOFTWARE,
20: * with or without modification, as permitted hereunder, you shall affix
21: * to all such copies of the SOFTWARE the above copyright notice.
22: * (3) An explicit reference to this SOFTWARE and its copyright owner
23: * shall be made on your publication or presentation in any form of the
24: * results obtained by use of the SOFTWARE.
25: * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.9 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.8 noro 27: * for such modification or the source code of the modified part of the
28: * SOFTWARE.
29: *
30: * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
31: * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
32: * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
33: * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
34: * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
35: * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
36: * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
37: * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
38: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
39: * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
40: * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
41: * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
42: * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
43: * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
44: * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
45: * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
46: * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
47: *
1.42 ! ohara 48: * $OpenXM: OpenXM_contrib2/asir2000/builtin/ctrl.c,v 1.41 2014/05/12 02:35:35 ohara Exp $
1.8 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "parse.h"
1.42 ! ohara 52: #include <string.h>
! 53: #if defined(VISUAL)
! 54: #include <windows.h>
! 55: #else
! 56: #include <unistd.h>
! 57: #include <sys/types.h>
! 58: #include <sys/socket.h>
! 59: #include <sys/wait.h>
! 60: #endif
! 61:
! 62: static struct {
! 63: char *type;
! 64: char *kernel;
! 65: char *name;
! 66: char *arch;
! 67: char *release;
! 68: char *full;
! 69: } sysinfo;
1.1 noro 70:
71: void Pctrl();
1.42 ! ohara 72: void Psysinfo(LIST *rp);
! 73: static void get_sysinfo();
1.1 noro 74:
75: struct ftab ctrl_tab[] = {
76: {"ctrl",Pctrl,-2},
1.30 noro 77: {"asir_env",Pctrl,-2},
1.42 ! ohara 78: {"sysinfo", Psysinfo, 0},
1.1 noro 79: {0,0,0},
80: };
81:
1.33 noro 82: extern int error_in_timer;
1.1 noro 83: extern int prtime,nez,echoback,bigfloat;
1.39 ohara 84: extern int debug_up;
1.1 noro 85: extern int GC_max_heap_size,Verbose,hideargs,hex_output,do_server_in_X11;
1.36 noro 86: extern int do_message,do_terse;
1.4 noro 87: extern int ox_batch,ox_check,ox_exchange_mathcap;
1.1 noro 88: extern int f4_nocheck;
1.16 saito 89: extern int StrassenSize;
1.22 saito 90: extern int outputstyle;
1.3 noro 91: extern int fortran_output;
1.13 noro 92: extern int real_digit;
1.27 noro 93: extern int real_binary;
1.31 noro 94: extern int allow_laurent;
1.12 saito 95: #if defined(INTERVAL)
96: extern int zerorewrite;
1.38 saito 97: extern int Itvplot;
1.12 saito 98: #endif
1.11 noro 99: extern int double_output;
1.14 noro 100: extern int use_new_hensel;
1.15 noro 101: extern int print_quote;
1.20 noro 102: extern int show_crossref;
1.24 noro 103: extern Obj user_defined_prompt;
1.28 ohara 104: extern int asir_setenv;
1.32 noro 105: extern int show_orderspec;
1.34 noro 106: extern int no_debug_on_error;
1.37 noro 107: extern int diag_period;
1.40 noro 108: extern int weight_check;
1.41 ohara 109: extern char **ASIRLOADPATH;
110: extern int ASIRLOADPATH_LEN;
1.1 noro 111:
112: static struct {
113: char *key;
114: int *val;
115: } ctrls[] = {
1.33 noro 116: {"error_in_timer",&error_in_timer},
1.1 noro 117: {"cputime",&prtime},
118: {"nez",&nez},
119: {"echo",&echoback},
1.35 noro 120: #if defined(PARI)
1.1 noro 121: {"bigfloat",&bigfloat},
1.6 noro 122: #endif
1.1 noro 123: {"verbose",&Verbose},
1.23 ohara 124: {"quiet_mode",&do_quiet},
1.1 noro 125: {"hideargs",&hideargs},
126: {"hex",&hex_output},
127: {"debug_window",&do_server_in_X11},
128: {"message",&do_message},
1.36 noro 129: {"terse",&do_terse},
1.1 noro 130: {"debug_up",&debug_up},
1.24 noro 131: {"no_prompt",&do_quiet},
1.28 ohara 132: {"asir_setenv",&asir_setenv},
1.1 noro 133: {"ox_batch",&ox_batch},
134: {"ox_check",&ox_check},
1.5 noro 135: {"ox_exchange_mathcap",&ox_exchange_mathcap},
1.1 noro 136: {"f4_nocheck",&f4_nocheck},
1.16 saito 137: {"StrassenSize",&StrassenSize},
1.22 saito 138: {"outputstyle",&outputstyle},
1.11 noro 139: {"double_output",&double_output},
1.13 noro 140: {"real_digit",&real_digit},
1.27 noro 141: {"real_binary",&real_binary},
1.3 noro 142: {"fortran_output",&fortran_output},
1.14 noro 143: {"new_hensel",&use_new_hensel},
1.15 noro 144: {"print_quote",&print_quote},
1.20 noro 145: {"show_crossref",&show_crossref},
1.31 noro 146: {"allow_laurent",&allow_laurent},
1.32 noro 147: {"show_orderspec",&show_orderspec},
1.34 noro 148: {"no_debug_on_error",&no_debug_on_error},
1.37 noro 149: {"diag_period",&diag_period},
1.40 noro 150: {"weight_check",&weight_check},
1.12 saito 151: #if defined(INTERVAL)
152: {"zerorewrite",&zerorewrite},
1.38 saito 153: {"itvplotsize",&Itvplot},
1.12 saito 154: #endif
1.1 noro 155: {0,0},
156: };
157:
158: void Pctrl(arg,rp)
159: NODE arg;
160: Q *rp;
161: {
1.24 noro 162: int t,i,n;
1.39 ohara 163: int nm,dv;
1.1 noro 164: N num,den;
165: Q c;
166: char *key;
167: char buf[BUFSIZ];
1.24 noro 168: char *str;
1.41 ohara 169: STRING s;
170: NODE node,p;
171: LIST list;
1.1 noro 172:
173: if ( !arg ) {
174: *rp = 0;
175: return;
176: }
177: key = BDY((STRING)ARG0(arg));
178: if ( !strcmp(key,"adj") ) {
179: /* special treatment is necessary for "adj" */
180: if ( argc(arg) == 1 ) {
1.39 ohara 181: Risa_GC_get_adj(&nm,&dv);
182: UTON(dv,num);
183: UTON(nm,den);
1.1 noro 184: } else {
185: c = (Q)ARG1(arg);
186: if ( !c )
187: error("ctrl : adj : invalid argument");
188: num = NM(c);
189: den = !DN(c)?ONEN:DN(c);
1.39 ohara 190: dv = BD(num)[0];
191: nm = BD(den)[0];
192: Risa_GC_set_adj(nm,dv);
1.1 noro 193: }
194: NDTOQ(num,den,1,*rp);
1.24 noro 195: return;
196: } else if ( !strcmp(key,"prompt") ) {
197: /* special treatment is necessary for "prompt" */
198: if ( argc(arg) == 1 ) {
1.26 takayama 199: if ((!do_quiet) && (user_defined_prompt == (Obj)0)) *rp=ONE;
200: else *rp = (Q)user_defined_prompt;
1.24 noro 201: } else {
202: c = (Q)ARG1(arg);
1.25 noro 203: if ( !c ) {
204: do_quiet = 1;
205: user_defined_prompt = 0;
206: *rp = 0;
207: } else if ( OID(c) == O_STR ) {
208: str = BDY((STRING)c);
209: for ( i = 0, n = 0; str[i]; i++ )
210: if ( str[i] == '%' )
211: n++;
212: if ( n >= 2 )
213: error("ctrl : prompt : invalid prompt specification");
1.24 noro 214: do_quiet = 1;
215: user_defined_prompt = (Obj)c;
216: *rp = c;
217: } else if ( NUM(c) && RATN(c) && UNIQ(c) ) {
218: user_defined_prompt = 0;
219: do_quiet = 0;
220: } else {
221: error("ctrl : prompt : invalid argument");
222: }
223: }
1.1 noro 224: return;
1.41 ohara 225: } else if ( !strcmp(key,"loadpath") ) {
226: *rp = 0;
227: if ( argc(arg) == 1 ) {
228: if( ASIRLOADPATH[0] ) {
229: for(i=0; ASIRLOADPATH[i]; i++) {
230: }
231: for(i--,p=NULL; i>=0; i--,p=node) {
232: MKSTR(s,ASIRLOADPATH[i]);
233: MKNODE(node,s,p);
234: }
235: MKLIST(list,node);
236: *rp = list;
237: }
238: } else {
239: list = (LIST)ARG1(arg);
240: if ( OID(list) == O_LIST ) {
241: for(i=0,p=BDY(list); p; i++,p=NEXT(p)) {
242: s=(STRING)BDY(p);
243: if(!s || OID(s)!=O_STR) {
244: error("ctrl : loadpath : invalid argument");
245: }
246: }
247: if(i >= ASIRLOADPATH_LEN) {
248: ASIRLOADPATH_LEN = i+1;
249: ASIRLOADPATH = (char **)MALLOC(sizeof(char *)*ASIRLOADPATH_LEN);
250: }
251: for(i=0,p=BDY(list); p; i++,p=NEXT(p)) {
252: ASIRLOADPATH[i] = (char *)BDY((STRING)BDY(p));
253: }
254: ASIRLOADPATH[i] = NULL;
255: }else {
256: error("ctrl : loadpath : invalid argument");
257: }
258: }
259: return;
1.1 noro 260: }
261: for ( i = 0; ctrls[i].key; i++ )
262: if ( !strcmp(key,ctrls[i].key) )
263: break;
264: if ( ctrls[i].key ) {
265: if ( argc(arg) == 1 )
266: t = *ctrls[i].val;
267: else
268: *ctrls[i].val = t = QTOS((Q)ARG1(arg));
269: STOQ(t,*rp);
270: } else {
271: sprintf(buf,"ctrl : %s : no such key",key);
272: error(buf);
273: }
274: }
1.42 ! ohara 275:
! 276: void Psysinfo(LIST *rp)
! 277: {
! 278: int i;
! 279: NODE n,p;
! 280: STRING s[6];
! 281:
! 282: get_sysinfo();
! 283: MKSTR(s[0],sysinfo.type); MKSTR(s[1],sysinfo.kernel); MKSTR(s[2],sysinfo.name);
! 284: MKSTR(s[3],sysinfo.arch); MKSTR(s[4],sysinfo.release); MKSTR(s[5],sysinfo.full);
! 285: for(i=5,p=NULL; i>=0; i--,p=n) {
! 286: MKNODE(n,s[i],p);
! 287: }
! 288: MKLIST(*rp,n);
! 289: }
! 290:
! 291: #if !defined(VISUAL)
! 292: static char *uname(char *option)
! 293: {
! 294: char buf[BUFSIZ];
! 295: char *s;
! 296: int fd[2], status;
! 297: *buf = 0;
! 298: if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) {
! 299: *buf = 0; return "";
! 300: }
! 301: if (fork() == 0) {
! 302: dup2(fd[1], 1);
! 303: execlp("uname", "uname", option, NULL);
! 304: }
! 305: s = buf;
! 306: if( !read(fd[0], s, BUFSIZ-1) || (s = strchr(s, '\n')) ) {
! 307: *s = 0;
! 308: }
! 309: wait(&status);
! 310: close(fd[0]);
! 311: close(fd[1]);
! 312: s = (char *)MALLOC(strlen(buf)+1);
! 313: strcpy(s, buf);
! 314: return s;
! 315: }
! 316:
! 317: static void get_sysinfo()
! 318: {
! 319: static int initialized = 0;
! 320: if (initialized) {
! 321: return;
! 322: }
! 323: initialized = 1;
! 324: sysinfo.kernel = uname(NULL);
! 325: #if defined(__DARWIN__)
! 326: sysinfo.type = "macosx";
! 327: sysinfo.name = sysinfo.kernel;
! 328: #else
! 329: sysinfo.type = "unix";
! 330: sysinfo.name = uname("-o"); // not work on Darwin
! 331: #endif
! 332: sysinfo.arch = uname("-m");
! 333: sysinfo.release= uname("-r");
! 334: sysinfo.full = uname("-a");
! 335: }
! 336:
! 337: #else
! 338:
! 339: /* http://msdn.microsoft.com/ja-jp/library/windows/desktop/ms724834%28v=vs.85%29.aspx */
! 340: static char *osnameNT(int major, int minor)
! 341: {
! 342: if ((major == 3 && minor == 51) || (major == 4 && minor == 0)) {
! 343: return "WindowsNT";
! 344: }else if (major == 5 && minor == 0) {
! 345: return "Windows2000";
! 346: }else if (major == 5 && minor == 1) {
! 347: return "WindowsXP";
! 348: }else if (major == 5 && minor == 2) {
! 349: return "Windows2003 Server";
! 350: }else if (major == 6 && minor == 0) {
! 351: return "WindowsVista";
! 352: }else if (major == 6 && minor == 1) {
! 353: return "Windows7";
! 354: }else if (major == 6 && minor == 2) {
! 355: return "Windows8";
! 356: }else if (major == 6 && minor == 3) {
! 357: return "Windows8.1";
! 358: }
! 359: return "unknown";
! 360: }
! 361:
! 362: static char *osname95(int major, int minor)
! 363: {
! 364: if (major == 4 && minor == 0) {
! 365: return "Windows95";
! 366: }else if (major == 4 && minor == 10) {
! 367: return "Windows98";
! 368: }else if (major == 4 && minor == 90) {
! 369: return "WindowsMe";
! 370: }
! 371: return "unknown";
! 372: }
! 373:
! 374: static void get_sysinfo()
! 375: {
! 376: int arch64 = 0;
! 377: char buf[BUFSIZ];
! 378: OSVERSIONINFO v;
! 379: char *s;
! 380: static int initialized = 0;
! 381:
! 382: if (initialized) {
! 383: return;
! 384: }
! 385: initialized = 1;
! 386:
! 387: v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
! 388: GetVersionEx(&v);
! 389:
! 390: sysinfo.type = "windows";
! 391: sysinfo.arch = "x86";
! 392: sprintf(buf, "%d.%d.%d", v.dwMajorVersion, v.dwMinorVersion, v.dwBuildNumber);
! 393: s = (char *)MALLOC(strlen(buf)+1);
! 394: strcpy(s, buf);
! 395: sysinfo.release = s;
! 396:
! 397: if (v.dwPlatformId == VER_PLATFORM_WIN32_NT) {
! 398: sysinfo.kernel = "WindowsNT";
! 399: sysinfo.name = osnameNT(v.dwMajorVersion, v.dwMinorVersion);
! 400:
! 401: #if defined(_WIN64)
! 402: sysinfo.arch = "x86_64";
! 403: #else
! 404: // IsWow64Process exists on WindowsXP SP2 or later
! 405: if(GetProcAddress(GetModuleHandle("kernel32.dll"), "IsWow64Process")) {
! 406: IsWow64Process(GetCurrentProcess(),&arch64);
! 407: if(arch64) {
! 408: sysinfo.arch = "x86_64";
! 409: }
! 410: }
! 411: #endif
! 412: }else { /* v.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS */
! 413: sysinfo.kernel = "Windows95";
! 414: sysinfo.name = osname95(v.dwMajorVersion, v.dwMinorVersion);
! 415: }
! 416: sprintf(buf, "%s %s %s %s %s", sysinfo.kernel, sysinfo.release, sysinfo.name, v.szCSDVersion, sysinfo.arch);
! 417: s = (char *)MALLOC(strlen(buf)+1);
! 418: strcpy(s, buf);
! 419: sysinfo.full = s;
! 420: }
! 421:
! 422: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>