Annotation of OpenXM_contrib2/asir2000/builtin/ctrl.c, Revision 1.58
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.58 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/builtin/ctrl.c,v 1.57 2018/03/28 07:58:17 noro Exp $
1.8 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "parse.h"
1.42 ohara 52: #include <string.h>
1.48 fujimoto 53: #if defined(VISUAL) || defined(__MINGW32__)
1.42 ohara 54: #include <windows.h>
1.44 ohara 55: #include <winnls.h>
1.42 ohara 56: #else
1.44 ohara 57: #include <locale.h>
1.42 ohara 58: #include <unistd.h>
59: #include <sys/types.h>
60: #include <sys/socket.h>
61: #include <sys/wait.h>
1.43 ohara 62: #include <sys/utsname.h>
1.42 ohara 63: #endif
64:
65: static struct {
66: char *type;
67: char *kernel;
68: char *name;
69: char *arch;
70: char *release;
71: char *full;
1.44 ohara 72: char *lang;
1.42 ohara 73: } sysinfo;
1.1 noro 74:
75: void Pctrl();
1.42 ohara 76: void Psysinfo(LIST *rp);
77: static void get_sysinfo();
1.1 noro 78:
79: struct ftab ctrl_tab[] = {
80: {"ctrl",Pctrl,-2},
1.30 noro 81: {"asir_env",Pctrl,-2},
1.42 ohara 82: {"sysinfo", Psysinfo, 0},
1.1 noro 83: {0,0,0},
84: };
85:
1.33 noro 86: extern int error_in_timer;
1.45 noro 87: extern int prtime,nez,echoback,bigfloat,evalef;
1.39 ohara 88: extern int debug_up;
1.1 noro 89: extern int GC_max_heap_size,Verbose,hideargs,hex_output,do_server_in_X11;
1.36 noro 90: extern int do_message,do_terse;
1.4 noro 91: extern int ox_batch,ox_check,ox_exchange_mathcap;
1.1 noro 92: extern int f4_nocheck;
1.16 saito 93: extern int StrassenSize;
1.22 saito 94: extern int outputstyle;
1.3 noro 95: extern int fortran_output;
1.13 noro 96: extern int real_digit;
1.27 noro 97: extern int real_binary;
1.31 noro 98: extern int allow_laurent;
1.12 saito 99: #if defined(INTERVAL)
100: extern int zerorewrite;
1.38 saito 101: extern int Itvplot;
1.12 saito 102: #endif
1.11 noro 103: extern int double_output;
1.14 noro 104: extern int use_new_hensel;
1.15 noro 105: extern int print_quote;
1.20 noro 106: extern int show_crossref;
1.24 noro 107: extern Obj user_defined_prompt;
1.28 ohara 108: extern int asir_setenv;
1.32 noro 109: extern int show_orderspec;
1.34 noro 110: extern int no_debug_on_error;
1.37 noro 111: extern int diag_period;
1.40 noro 112: extern int weight_check;
1.41 ohara 113: extern char **ASIRLOADPATH;
114: extern int ASIRLOADPATH_LEN;
1.51 noro 115: extern int No_ox_reset;
1.54 noro 116: extern int plot_by_bigfloat;
117: extern int debug_plot;
1.1 noro 118:
1.56 noro 119: static struct keyval {
1.1 noro 120: char *key;
121: int *val;
1.56 noro 122: char *desc;
1.1 noro 123: } ctrls[] = {
1.57 noro 124: {"StrassenSize",&StrassenSize,"Determines the parameter in Strassen-Winograd matrix multiplication algorithm."},
125: {"allow_laurent",&allow_laurent,"If set to 1, negative exponents are allowed in monomials."},
126: {"asir_setenv",&asir_setenv,"Not used."},
127: {"bigfloat",&bigfloat,"If set to 1, MPFR bigfloat functions are used for floating point evaluation." },
1.56 noro 128: {"cputime",&prtime,"If set to 1, the CPU time at the toplevel is shown." },
1.57 noro 129: {"debug_up",&debug_up,"If set to 1, some debug messages are printed in special functions for univariate polynomials."},
130: {"debug_window",&do_server_in_X11,"If set to 1, an input window for debugging remote server are shown."},
131: {"diag_period",&diag_period,"Determines the frequency of the intermediate inter-reduction in nd_gr()."},
132: {"double_output",&double_output,"If set to 1, floating point numbers are printed in the style ddd.ddd."},
1.56 noro 133: {"echo",&echoback,"If set to 1, characters read by the input function are printed." },
1.57 noro 134: {"error_in_timer",&error_in_timer,"If set to 1, the usual error handler is executed when the timer is expired."},
1.56 noro 135: {"evalef",&evalef,"If set to 1, elementary functions are evaluated immediately."},
1.57 noro 136: {"f4_nocheck",&f4_nocheck,"If set to 1, correctness check of the result of modular computation are omitted in nd_f4()."},
137: {"fake_ox_reset",&No_ox_reset,"Determines the treatment of OX reset request for a server which does not implement the reset protocol."},
138: {"fortran_output",&fortran_output,"If set to 1, ** is used instead of ^ for representing the power."},
139: {"hex",&hex_output,"If set to 1, integers are printed by the hexadecimal notation."},
1.56 noro 140: {"hideargs",&hideargs,"If set to 1, the arguments of a function call are not printed."},
141: {"message",&do_message,"If set to 1, an opening message is printed in ox_asir and ox_plot."},
1.57 noro 142: {"new_hensel",&use_new_hensel,"If set to 1, a function hensel2() is used in the univariate factorizer over Q."},
143: {"nez",&nez,"If set to 1, a new version of EZGCD implementation is used." },
144: {"no_debug_on_error",&no_debug_on_error,"If set to 1, the debug mode is not used."},
145: {"no_ox_reset",&No_ox_reset,"Determines the treatment of OX reset request for a server which does not implement the reset protocol."},
1.56 noro 146: {"no_prompt",&do_quiet,"If set to 1, prompts are not shown."},
1.57 noro 147: {"outputstyle",&outputstyle,"If set to 1, structured data such as matrices and vectors are printed in the style mat(...), vect(...)."},
1.56 noro 148: {"ox_batch",&ox_batch,"If set to 1, the OX stream are not flushed at each sending of an OX data."},
149: {"ox_check",&ox_check,"If set to 1, mathcap check is done for OpenXM date communication."},
150: {"ox_exchange_mathcap",&ox_exchange_mathcap,"If set to 1, mathcaps are exchanged."},
1.57 noro 151: {"print_quote",&print_quote,"Determines the behavior of the printed form of a quote."},
152: {"quiet_mode",&do_quiet,"If set to 1, the copyright notices are not printed at the beginning of the session."},
153: {"real_binary",&real_binary,"If set to 1, a floating point number is printed by the binary notation."},
1.56 noro 154: {"real_digit",&real_digit,"Determines the number of digits to appear after the decimal point."},
155: {"show_crossref",&show_crossref,"If set to 1, cross-references are shown when a program file is loaded."},
156: {"show_orderspec",&show_orderspec,"If set to 1, the specification of a composite term order is printed upon its creation."},
1.57 noro 157: {"terse",&do_terse,"If set to 1, messages are not printed when user-defined callbacks are executed."},
158: {"verbose",&Verbose,"If set to 1, a warning is printed if a function is redefined."},
1.56 noro 159: {"weight_check",&weight_check,"If set to 1, an overflow check for the given weight vector is done before starting the Groebner basis computation."},
1.55 noro 160: #if defined(DO_PLOT)
1.56 noro 161: {"plot_by_bigfloat",&plot_by_bigfloat,"If set to 1, computation is done by using MPFR bigfloat functions in ox_plot."},
162: {"debug_plot",&debug_plot,"If set to 1, ox_plot is executed with the message window."},
1.55 noro 163: #endif
1.12 saito 164: #if defined(INTERVAL)
1.56 noro 165: {"zerorewrite",&zerorewrite,""},
166: {"itvplotsize",&Itvplot,""},
1.12 saito 167: #endif
1.1 noro 168: {0,0},
169: };
170:
1.58 ! noro 171: LIST create_control_value(char *keystr,Obj value,char *descstr,int withdesc)
! 172: {
! 173: STRING key,desc;
! 174: NODE nd;
! 175: LIST list;
! 176:
! 177: MKSTR(key,keystr);
! 178: if ( withdesc ) {
! 179: MKSTR(desc,descstr);
! 180: nd = mknode(3,key,value,desc);
! 181: } else nd = mknode(2,key,value);
! 182: MKLIST(list,nd);
! 183: return list;
! 184: }
! 185:
! 186: extern Q ox_pari_stream;
! 187: extern int ox_pari_stream_initialized;
! 188: extern P ox_pari_starting_function;
! 189:
1.57 noro 190: LIST create_control_values(int withdesc)
1.56 noro 191: {
192: int n,i;
1.58 ! noro 193: NODE top,top1,nd,node,p;
! 194: LIST list,l;
! 195: STRING s;
! 196: char *descstr;
! 197: Q val,adj;
! 198: int nm,dv;
! 199: N num,den;
1.56 noro 200:
201: n = sizeof(ctrls)/sizeof(struct keyval)-1;
202: top = 0;
203: for ( i = n-1; i >= 0; i-- ) {
204: STOQ(*(ctrls[i].val),val);
1.58 ! noro 205: list = create_control_value(ctrls[i].key,val,ctrls[i].desc,withdesc);
! 206: MKNODE(top1,list,top); top = top1;
1.56 noro 207: }
1.58 ! noro 208: /* adj */
! 209: Risa_GC_get_adj(&nm,&dv); UTON(nm,num); UTON(dv,den); NDTOQ(num,den,1,adj);
! 210: descstr = "Determines the parameter for Boehm's GC.";
! 211: list = create_control_value("adj",adj,descstr,withdesc);
! 212: MKNODE(top1,list,top); top = top1;
! 213:
! 214: /* prompt */
! 215: descstr = "Determines the user-defined prompt.";
! 216: list = create_control_value("prompt",user_defined_prompt,descstr,withdesc);
! 217: MKNODE(top1,list,top); top = top1;
! 218:
! 219: /* loadpath */
! 220: node = 0;
! 221: if( ASIRLOADPATH[0] ) {
! 222: for(i=0; ASIRLOADPATH[i]; i++);
! 223: for(i--,p=NULL; i>=0; i--,p=node) {
! 224: MKSTR(s,ASIRLOADPATH[i]);
! 225: MKNODE(node,s,p);
! 226: }
! 227: }
! 228: MKLIST(l,node);
! 229: descstr = "List of paths in ASIRLOADPATHt.";
! 230: list = create_control_value("loadpath",l,descstr,withdesc);
! 231: MKNODE(top1,list,top); top = top1;
! 232:
! 233: /* oxpari_id */
! 234: if(!ox_pari_stream_initialized) {
! 235: STOQ(-1,val);
! 236: } else val = ox_pari_stream;
! 237: descstr = "Id of ox_pari.";
! 238: list = create_control_value("oxpari_id",val,descstr,withdesc);
! 239: MKNODE(top1,list,top); top = top1;
! 240:
! 241: /* oxpari_start */
! 242: val = (Q)ox_pari_starting_function;
! 243: descstr = "oxpari starting function.";
! 244: list = create_control_value("oxpari_start",val,descstr,withdesc);
! 245: MKNODE(top1,list,top); top = top1;
! 246:
1.56 noro 247: MKLIST(list,top);
248: return list;
249: }
250:
1.53 noro 251: void Pctrl(NODE arg,Q *rp)
1.1 noro 252: {
1.57 noro 253: int t,i,n,desc=0;
1.39 ohara 254: int nm,dv;
1.1 noro 255: N num,den;
256: Q c;
257: char *key;
258: char buf[BUFSIZ];
1.24 noro 259: char *str;
1.41 ohara 260: STRING s;
1.57 noro 261: NODE node,p,opt;
1.41 ohara 262: LIST list;
1.50 ohara 263: P f;
1.57 noro 264: Obj value;
1.1 noro 265:
266: if ( !arg ) {
1.57 noro 267: if ( current_option ) {
268: for ( opt = current_option; opt; opt = NEXT(opt) ) {
269: p = BDY((LIST)BDY(opt));
270: key = BDY((STRING)BDY(p));
271: value = (Obj)BDY(NEXT(p));
272: if ( !strcmp(key,"desc") && value ) {
273: desc = value ? 1 : 0;
274: break;
275: }
276: }
277: }
278: *rp = create_control_values(desc);
1.1 noro 279: return;
280: }
281: key = BDY((STRING)ARG0(arg));
282: if ( !strcmp(key,"adj") ) {
283: /* special treatment is necessary for "adj" */
284: if ( argc(arg) == 1 ) {
1.39 ohara 285: Risa_GC_get_adj(&nm,&dv);
286: UTON(dv,num);
287: UTON(nm,den);
1.1 noro 288: } else {
289: c = (Q)ARG1(arg);
290: if ( !c )
291: error("ctrl : adj : invalid argument");
292: num = NM(c);
293: den = !DN(c)?ONEN:DN(c);
1.39 ohara 294: dv = BD(num)[0];
295: nm = BD(den)[0];
296: Risa_GC_set_adj(nm,dv);
1.1 noro 297: }
298: NDTOQ(num,den,1,*rp);
1.24 noro 299: return;
300: } else if ( !strcmp(key,"prompt") ) {
301: /* special treatment is necessary for "prompt" */
302: if ( argc(arg) == 1 ) {
1.26 takayama 303: if ((!do_quiet) && (user_defined_prompt == (Obj)0)) *rp=ONE;
304: else *rp = (Q)user_defined_prompt;
1.24 noro 305: } else {
306: c = (Q)ARG1(arg);
1.25 noro 307: if ( !c ) {
308: do_quiet = 1;
309: user_defined_prompt = 0;
310: *rp = 0;
311: } else if ( OID(c) == O_STR ) {
312: str = BDY((STRING)c);
313: for ( i = 0, n = 0; str[i]; i++ )
314: if ( str[i] == '%' )
315: n++;
316: if ( n >= 2 )
317: error("ctrl : prompt : invalid prompt specification");
1.24 noro 318: do_quiet = 1;
319: user_defined_prompt = (Obj)c;
320: *rp = c;
321: } else if ( NUM(c) && RATN(c) && UNIQ(c) ) {
322: user_defined_prompt = 0;
323: do_quiet = 0;
324: } else {
325: error("ctrl : prompt : invalid argument");
326: }
327: }
1.1 noro 328: return;
1.41 ohara 329: } else if ( !strcmp(key,"loadpath") ) {
330: *rp = 0;
331: if ( argc(arg) == 1 ) {
332: if( ASIRLOADPATH[0] ) {
333: for(i=0; ASIRLOADPATH[i]; i++) {
334: }
335: for(i--,p=NULL; i>=0; i--,p=node) {
336: MKSTR(s,ASIRLOADPATH[i]);
337: MKNODE(node,s,p);
338: }
339: MKLIST(list,node);
1.53 noro 340: *rp = (Q)list;
1.41 ohara 341: }
342: } else {
343: list = (LIST)ARG1(arg);
344: if ( OID(list) == O_LIST ) {
345: for(i=0,p=BDY(list); p; i++,p=NEXT(p)) {
346: s=(STRING)BDY(p);
347: if(!s || OID(s)!=O_STR) {
348: error("ctrl : loadpath : invalid argument");
349: }
350: }
351: if(i >= ASIRLOADPATH_LEN) {
352: ASIRLOADPATH_LEN = i+1;
353: ASIRLOADPATH = (char **)MALLOC(sizeof(char *)*ASIRLOADPATH_LEN);
354: }
355: for(i=0,p=BDY(list); p; i++,p=NEXT(p)) {
356: ASIRLOADPATH[i] = (char *)BDY((STRING)BDY(p));
357: }
358: ASIRLOADPATH[i] = NULL;
359: }else {
360: error("ctrl : loadpath : invalid argument");
361: }
362: }
363: return;
1.49 ohara 364: } else if ( !strcmp(key,"oxpari_id") ) {
365: if ( argc(arg) == 1 ) {
366: if(!ox_pari_stream_initialized) {
367: t=-1;
368: STOQ(t,*rp);
369: }else {
370: *rp = ox_pari_stream;
371: }
372: }else {
373: c = (Q)ARG1(arg);
374: if ( !c || ( NUM(c) && INT(c) && SGN(c)>0 ) ) {
375: ox_pari_stream_initialized = 1;
376: ox_pari_stream = c;
377: *rp = c;
378: }else {
379: t=-1;
380: STOQ(t,*rp);
381: }
382: }
383: return;
1.50 ohara 384: } else if ( !strcmp(key,"oxpari_start") ) {
385: if ( argc(arg) == 1 ) {
1.53 noro 386: *rp = (Q)ox_pari_starting_function;
1.50 ohara 387: } else {
1.53 noro 388: f = (P)ARG1(arg);
1.50 ohara 389: if ( !f || OID(f) == O_P) {
390: ox_pari_starting_function = f;
1.53 noro 391: *rp = (Q)f;
1.50 ohara 392: }else {
393: *rp = 0;
394: }
395: }
396: return;
1.1 noro 397: }
398: for ( i = 0; ctrls[i].key; i++ )
399: if ( !strcmp(key,ctrls[i].key) )
400: break;
401: if ( ctrls[i].key ) {
402: if ( argc(arg) == 1 )
403: t = *ctrls[i].val;
404: else
405: *ctrls[i].val = t = QTOS((Q)ARG1(arg));
406: STOQ(t,*rp);
407: } else {
408: sprintf(buf,"ctrl : %s : no such key",key);
409: error(buf);
410: }
411: }
1.42 ohara 412:
413: void Psysinfo(LIST *rp)
414: {
415: int i;
416: NODE n,p;
1.44 ohara 417: STRING s[7];
1.42 ohara 418:
419: get_sysinfo();
420: MKSTR(s[0],sysinfo.type); MKSTR(s[1],sysinfo.kernel); MKSTR(s[2],sysinfo.name);
421: MKSTR(s[3],sysinfo.arch); MKSTR(s[4],sysinfo.release); MKSTR(s[5],sysinfo.full);
1.44 ohara 422: MKSTR(s[6],sysinfo.lang);
423: for(i=6,p=NULL; i>=0; i--,p=n) {
1.42 ohara 424: MKNODE(n,s[i],p);
425: }
426: MKLIST(*rp,n);
427: }
428:
1.48 fujimoto 429: #if !defined(VISUAL) && !defined(__MINGW32__)
1.44 ohara 430:
431: static char *get_lang()
432: {
433: char *c, *p, *q;
434: c = setlocale(LC_ALL, NULL); /* saving current locale */
435: p = setlocale(LC_ALL, "");
436: q = (char *)MALLOC(strlen(p)+1);
437: strcpy(q,p);
438: setlocale(LC_ALL, c); /* restoring current locale */
439: return q;
440: }
441:
1.43 ohara 442: static char *myuname(char *option)
1.42 ohara 443: {
444: char buf[BUFSIZ];
445: char *s;
1.43 ohara 446: int fd[2], status, pid;
1.42 ohara 447: *buf = 0;
448: if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) {
1.43 ohara 449: *buf = 0; return NULL;
1.42 ohara 450: }
1.43 ohara 451: pid = fork();
452: if (pid < 0) {
453: return NULL;
454: }else if (pid == 0) {
1.42 ohara 455: dup2(fd[1], 1);
1.43 ohara 456: close(2);
1.42 ohara 457: execlp("uname", "uname", option, NULL);
458: }
1.43 ohara 459: waitpid(pid, &status, 0);
460: if (status) { /* error */
461: return NULL;
462: }
1.42 ohara 463: s = buf;
464: if( !read(fd[0], s, BUFSIZ-1) || (s = strchr(s, '\n')) ) {
465: *s = 0;
466: }
467: close(fd[0]);
468: close(fd[1]);
469: s = (char *)MALLOC(strlen(buf)+1);
470: strcpy(s, buf);
471: return s;
472: }
473:
474: static void get_sysinfo()
475: {
1.43 ohara 476: static struct utsname u;
1.42 ohara 477: static int initialized = 0;
478: if (initialized) {
479: return;
480: }
481: initialized = 1;
1.43 ohara 482: uname(&u);
483: sysinfo.kernel = u.sysname;
1.42 ohara 484: #if defined(__DARWIN__)
485: sysinfo.type = "macosx";
486: sysinfo.name = sysinfo.kernel;
487: #else
488: sysinfo.type = "unix";
1.43 ohara 489: sysinfo.name = myuname("-o"); // not work on Darwin
490: if (!sysinfo.name) {
491: sysinfo.name = sysinfo.kernel;
492: }
1.42 ohara 493: #endif
1.43 ohara 494: sysinfo.arch = u.machine;
495: sysinfo.release= u.release;
496: sysinfo.full = myuname("-a");
1.44 ohara 497: sysinfo.lang = get_lang();
1.42 ohara 498: }
499:
500: #else
501:
502: /* http://msdn.microsoft.com/ja-jp/library/windows/desktop/ms724834%28v=vs.85%29.aspx */
503: static char *osnameNT(int major, int minor)
504: {
505: if ((major == 3 && minor == 51) || (major == 4 && minor == 0)) {
506: return "WindowsNT";
507: }else if (major == 5 && minor == 0) {
508: return "Windows2000";
509: }else if (major == 5 && minor == 1) {
510: return "WindowsXP";
511: }else if (major == 5 && minor == 2) {
512: return "Windows2003 Server";
513: }else if (major == 6 && minor == 0) {
514: return "WindowsVista";
515: }else if (major == 6 && minor == 1) {
516: return "Windows7";
517: }else if (major == 6 && minor == 2) {
518: return "Windows8";
519: }else if (major == 6 && minor == 3) {
520: return "Windows8.1";
521: }
522: return "unknown";
523: }
524:
525: static char *osname95(int major, int minor)
526: {
527: if (major == 4 && minor == 0) {
528: return "Windows95";
529: }else if (major == 4 && minor == 10) {
530: return "Windows98";
531: }else if (major == 4 && minor == 90) {
532: return "WindowsMe";
533: }
534: return "unknown";
535: }
536:
1.44 ohara 537: static char *get_lang()
538: {
539: char lang[BUFSIZ];
540: char *s;
541: if(GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SISO639LANGNAME, lang, BUFSIZ)) {
542: s = (char *)MALLOC(strlen(lang)+1);
543: strcpy(s,lang);
544: return s;
545: }
546: return "en"; // English
547: }
548:
1.42 ohara 549: static void get_sysinfo()
550: {
551: int arch64 = 0;
552: char buf[BUFSIZ];
553: OSVERSIONINFO v;
554: char *s;
555: static int initialized = 0;
556:
557: if (initialized) {
558: return;
559: }
560: initialized = 1;
561:
562: v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
563: GetVersionEx(&v);
564:
565: sysinfo.type = "windows";
566: sysinfo.arch = "x86";
567: sprintf(buf, "%d.%d.%d", v.dwMajorVersion, v.dwMinorVersion, v.dwBuildNumber);
568: s = (char *)MALLOC(strlen(buf)+1);
569: strcpy(s, buf);
570: sysinfo.release = s;
571:
572: if (v.dwPlatformId == VER_PLATFORM_WIN32_NT) {
573: sysinfo.kernel = "WindowsNT";
574: sysinfo.name = osnameNT(v.dwMajorVersion, v.dwMinorVersion);
575:
576: #if defined(_WIN64)
577: sysinfo.arch = "x86_64";
578: #else
579: // IsWow64Process exists on WindowsXP SP2 or later
580: if(GetProcAddress(GetModuleHandle("kernel32.dll"), "IsWow64Process")) {
581: IsWow64Process(GetCurrentProcess(),&arch64);
582: if(arch64) {
583: sysinfo.arch = "x86_64";
584: }
585: }
586: #endif
587: }else { /* v.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS */
588: sysinfo.kernel = "Windows95";
589: sysinfo.name = osname95(v.dwMajorVersion, v.dwMinorVersion);
590: }
591: sprintf(buf, "%s %s %s %s %s", sysinfo.kernel, sysinfo.release, sysinfo.name, v.szCSDVersion, sysinfo.arch);
592: s = (char *)MALLOC(strlen(buf)+1);
593: strcpy(s, buf);
594: sysinfo.full = s;
1.44 ohara 595: sysinfo.lang = get_lang();
1.42 ohara 596: }
597:
598: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>