Annotation of OpenXM_contrib2/asir2018/builtin/ctrl.c, Revision 1.1
1.1 ! 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
! 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
! 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: *
! 48: * $OpenXM$
! 49: */
! 50: #include "ca.h"
! 51: #include "parse.h"
! 52: #include <string.h>
! 53: #if defined(VISUAL) || defined(__MINGW32__)
! 54: #include <windows.h>
! 55: #include <winnls.h>
! 56: #else
! 57: #include <locale.h>
! 58: #include <unistd.h>
! 59: #include <sys/types.h>
! 60: #include <sys/socket.h>
! 61: #include <sys/wait.h>
! 62: #include <sys/utsname.h>
! 63: #endif
! 64:
! 65: static struct {
! 66: char *type;
! 67: char *kernel;
! 68: char *name;
! 69: char *arch;
! 70: char *release;
! 71: char *full;
! 72: char *lang;
! 73: } sysinfo;
! 74:
! 75: void Pctrl();
! 76: void Psysinfo(LIST *rp);
! 77: static void get_sysinfo();
! 78:
! 79: struct ftab ctrl_tab[] = {
! 80: {"ctrl",Pctrl,-2},
! 81: {"asir_env",Pctrl,-2},
! 82: {"sysinfo", Psysinfo, 0},
! 83: {0,0,0},
! 84: };
! 85:
! 86: extern int error_in_timer;
! 87: extern int prtime,nez,echoback,bigfloat,evalef;
! 88: extern int debug_up;
! 89: extern int GC_max_heap_size,Verbose,hideargs,hex_output,do_server_in_X11;
! 90: extern int do_message,do_terse;
! 91: extern int ox_batch,ox_check,ox_exchange_mathcap;
! 92: extern int f4_nocheck;
! 93: extern int StrassenSize;
! 94: extern int outputstyle;
! 95: extern int fortran_output;
! 96: extern int real_digit;
! 97: extern int real_binary;
! 98: extern int allow_laurent;
! 99: #if defined(INTERVAL)
! 100: extern int zerorewrite;
! 101: extern int Itvplot;
! 102: #endif
! 103: extern int double_output;
! 104: extern int use_new_hensel;
! 105: extern int print_quote;
! 106: extern int show_crossref;
! 107: extern Obj user_defined_prompt;
! 108: extern int asir_setenv;
! 109: extern int show_orderspec;
! 110: extern int no_debug_on_error;
! 111: extern int diag_period;
! 112: extern int weight_check;
! 113: extern char **ASIRLOADPATH;
! 114: extern int ASIRLOADPATH_LEN;
! 115: extern int No_ox_reset;
! 116: extern int plot_by_bigfloat;
! 117: extern int debug_plot;
! 118:
! 119: static struct keyval {
! 120: char *key;
! 121: int *val;
! 122: char *desc;
! 123: } ctrls[] = {
! 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." },
! 128: {"cputime",&prtime,"If set to 1, the CPU time at the toplevel is shown." },
! 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."},
! 133: {"echo",&echoback,"If set to 1, characters read by the input function are printed." },
! 134: {"error_in_timer",&error_in_timer,"If set to 1, the usual error handler is executed when the timer is expired."},
! 135: {"evalef",&evalef,"If set to 1, elementary functions are evaluated immediately."},
! 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."},
! 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."},
! 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."},
! 146: {"no_prompt",&do_quiet,"If set to 1, prompts are not shown."},
! 147: {"outputstyle",&outputstyle,"If set to 1, structured data such as matrices and vectors are printed in the style mat(...), vect(...)."},
! 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."},
! 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."},
! 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."},
! 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."},
! 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."},
! 160: #if defined(DO_PLOT)
! 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."},
! 163: #endif
! 164: #if defined(INTERVAL)
! 165: {"zerorewrite",&zerorewrite,""},
! 166: {"itvplotsize",&Itvplot,""},
! 167: #endif
! 168: {0,0},
! 169: };
! 170:
! 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 Z ox_pari_stream;
! 187: extern int ox_pari_stream_initialized;
! 188: extern P ox_pari_starting_function;
! 189:
! 190: LIST create_control_values(int withdesc)
! 191: {
! 192: int n,i;
! 193: NODE top,top1,nd,node,p;
! 194: LIST list,l;
! 195: STRING s;
! 196: char *descstr;
! 197: Z val;
! 198: Q adj;
! 199: int nm,dv;
! 200: Z num,den;
! 201:
! 202: n = sizeof(ctrls)/sizeof(struct keyval)-1;
! 203: top = 0;
! 204: for ( i = n-1; i >= 0; i-- ) {
! 205: STOQ(*(ctrls[i].val),val);
! 206: list = create_control_value(ctrls[i].key,(Obj)val,ctrls[i].desc,withdesc);
! 207: MKNODE(top1,list,top); top = top1;
! 208: }
! 209: /* adj */
! 210: Risa_GC_get_adj(&nm,&dv); UTOQ(nm,num); UTOQ(dv,den); divq((Q)num,(Q)den,&adj);
! 211: descstr = "Determines the parameter for Boehm's GC.";
! 212: list = create_control_value("adj",(Obj)adj,descstr,withdesc);
! 213: MKNODE(top1,list,top); top = top1;
! 214:
! 215: /* prompt */
! 216: descstr = "Determines the user-defined prompt.";
! 217: list = create_control_value("prompt",(Obj)user_defined_prompt,descstr,withdesc);
! 218: MKNODE(top1,list,top); top = top1;
! 219:
! 220: /* loadpath */
! 221: node = 0;
! 222: if( ASIRLOADPATH[0] ) {
! 223: for(i=0; ASIRLOADPATH[i]; i++);
! 224: for(i--,p=NULL; i>=0; i--,p=node) {
! 225: MKSTR(s,ASIRLOADPATH[i]);
! 226: MKNODE(node,s,p);
! 227: }
! 228: }
! 229: MKLIST(l,node);
! 230: descstr = "List of paths in ASIRLOADPATHt.";
! 231: list = create_control_value("loadpath",(Obj)l,descstr,withdesc);
! 232: MKNODE(top1,list,top); top = top1;
! 233:
! 234: /* oxpari_id */
! 235: if(!ox_pari_stream_initialized) {
! 236: STOQ(-1,val);
! 237: } else val = ox_pari_stream;
! 238: descstr = "Id of ox_pari.";
! 239: list = create_control_value("oxpari_id",(Obj)val,descstr,withdesc);
! 240: MKNODE(top1,list,top); top = top1;
! 241:
! 242: /* oxpari_start */
! 243: val = (Z)ox_pari_starting_function;
! 244: descstr = "oxpari starting function.";
! 245: list = create_control_value("oxpari_start",(Obj)val,descstr,withdesc);
! 246: MKNODE(top1,list,top); top = top1;
! 247:
! 248: MKLIST(list,top);
! 249: return list;
! 250: }
! 251:
! 252: void Pctrl(NODE arg,Obj *rp)
! 253: {
! 254: int t,i,n,desc=0;
! 255: int nm,dv;
! 256: Z num,den,z;
! 257: Q c;
! 258: char *key;
! 259: char buf[BUFSIZ];
! 260: char *str;
! 261: STRING s;
! 262: NODE node,p,opt;
! 263: LIST list;
! 264: P f;
! 265: Obj value;
! 266:
! 267: if ( !arg ) {
! 268: if ( current_option ) {
! 269: for ( opt = current_option; opt; opt = NEXT(opt) ) {
! 270: p = BDY((LIST)BDY(opt));
! 271: key = BDY((STRING)BDY(p));
! 272: value = (Obj)BDY(NEXT(p));
! 273: if ( !strcmp(key,"desc") && value ) {
! 274: desc = value ? 1 : 0;
! 275: break;
! 276: }
! 277: }
! 278: }
! 279: *rp = (Obj)create_control_values(desc);
! 280: return;
! 281: }
! 282: key = BDY((STRING)ARG0(arg));
! 283: if ( !strcmp(key,"adj") ) {
! 284: /* special treatment is necessary for "adj" */
! 285: if ( argc(arg) == 1 ) {
! 286: Risa_GC_get_adj(&nm,&dv);
! 287: UTOQ(dv,num);
! 288: UTOQ(nm,den);
! 289: divq((Q)num,(Q)den,(Q *)rp);
! 290: } else {
! 291: absq((Q)ARG1(arg),&c);
! 292: if ( !c )
! 293: error("ctrl : adj : invalid argument");
! 294: nmq(c,&num);
! 295: dnq(c,&den);
! 296: Risa_GC_set_adj(QTOS(den),QTOS(num));
! 297: *rp = (Obj)c;
! 298: }
! 299: return;
! 300: } else if ( !strcmp(key,"prompt") ) {
! 301: /* special treatment is necessary for "prompt" */
! 302: if ( argc(arg) == 1 ) {
! 303: if ((!do_quiet) && (user_defined_prompt == (Obj)0)) *rp=(Obj)ONE;
! 304: else *rp = (Obj)user_defined_prompt;
! 305: } else {
! 306: c = (Q)ARG1(arg);
! 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");
! 318: do_quiet = 1;
! 319: user_defined_prompt = (Obj)c;
! 320: *rp = (Obj)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: }
! 328: return;
! 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);
! 340: *rp = (Obj)list;
! 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;
! 364: } else if ( !strcmp(key,"oxpari_id") ) {
! 365: if ( argc(arg) == 1 ) {
! 366: if(!ox_pari_stream_initialized) {
! 367: STOQ(-1,z);
! 368: *rp = (Obj)z;
! 369: }else {
! 370: *rp = (Obj)ox_pari_stream;
! 371: }
! 372: }else {
! 373: c = (Q)ARG1(arg);
! 374: if ( !c || ( NUM(c) && INT(c) && sgnq(c)>0 ) ) {
! 375: ox_pari_stream_initialized = 1;
! 376: ox_pari_stream = (Z)c;
! 377: *rp = (Obj)c;
! 378: }else {
! 379: STOQ(-1,z);
! 380: *rp = (Obj)z;
! 381: }
! 382: }
! 383: return;
! 384: } else if ( !strcmp(key,"oxpari_start") ) {
! 385: if ( argc(arg) == 1 ) {
! 386: *rp = (Obj)ox_pari_starting_function;
! 387: } else {
! 388: f = (P)ARG1(arg);
! 389: if ( !f || OID(f) == O_P) {
! 390: ox_pari_starting_function = f;
! 391: *rp = (Obj)f;
! 392: }else {
! 393: *rp = 0;
! 394: }
! 395: }
! 396: return;
! 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,z);
! 407: *rp = (Obj)z;
! 408: } else {
! 409: sprintf(buf,"ctrl : %s : no such key",key);
! 410: error(buf);
! 411: }
! 412: }
! 413:
! 414: void Psysinfo(LIST *rp)
! 415: {
! 416: int i;
! 417: NODE n,p;
! 418: STRING s[7];
! 419:
! 420: get_sysinfo();
! 421: MKSTR(s[0],sysinfo.type); MKSTR(s[1],sysinfo.kernel); MKSTR(s[2],sysinfo.name);
! 422: MKSTR(s[3],sysinfo.arch); MKSTR(s[4],sysinfo.release); MKSTR(s[5],sysinfo.full);
! 423: MKSTR(s[6],sysinfo.lang);
! 424: for(i=6,p=NULL; i>=0; i--,p=n) {
! 425: MKNODE(n,s[i],p);
! 426: }
! 427: MKLIST(*rp,n);
! 428: }
! 429:
! 430: #if !defined(VISUAL) && !defined(__MINGW32__)
! 431:
! 432: static char *get_lang()
! 433: {
! 434: char *c, *p, *q;
! 435: c = setlocale(LC_ALL, NULL); /* saving current locale */
! 436: p = setlocale(LC_ALL, "");
! 437: q = (char *)MALLOC(strlen(p)+1);
! 438: strcpy(q,p);
! 439: setlocale(LC_ALL, c); /* restoring current locale */
! 440: return q;
! 441: }
! 442:
! 443: static char *myuname(char *option)
! 444: {
! 445: char buf[BUFSIZ];
! 446: char *s;
! 447: int fd[2], status, pid;
! 448: *buf = 0;
! 449: if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) {
! 450: *buf = 0; return NULL;
! 451: }
! 452: pid = fork();
! 453: if (pid < 0) {
! 454: return NULL;
! 455: }else if (pid == 0) {
! 456: dup2(fd[1], 1);
! 457: close(2);
! 458: execlp("uname", "uname", option, NULL);
! 459: }
! 460: waitpid(pid, &status, 0);
! 461: if (status) { /* error */
! 462: return NULL;
! 463: }
! 464: s = buf;
! 465: if( !read(fd[0], s, BUFSIZ-1) || (s = strchr(s, '\n')) ) {
! 466: *s = 0;
! 467: }
! 468: close(fd[0]);
! 469: close(fd[1]);
! 470: s = (char *)MALLOC(strlen(buf)+1);
! 471: strcpy(s, buf);
! 472: return s;
! 473: }
! 474:
! 475: static void get_sysinfo()
! 476: {
! 477: static struct utsname u;
! 478: static int initialized = 0;
! 479: if (initialized) {
! 480: return;
! 481: }
! 482: initialized = 1;
! 483: uname(&u);
! 484: sysinfo.kernel = u.sysname;
! 485: #if defined(__DARWIN__)
! 486: sysinfo.type = "macosx";
! 487: sysinfo.name = sysinfo.kernel;
! 488: #else
! 489: sysinfo.type = "unix";
! 490: sysinfo.name = myuname("-o"); // not work on Darwin
! 491: if (!sysinfo.name) {
! 492: sysinfo.name = sysinfo.kernel;
! 493: }
! 494: #endif
! 495: sysinfo.arch = u.machine;
! 496: sysinfo.release= u.release;
! 497: sysinfo.full = myuname("-a");
! 498: sysinfo.lang = get_lang();
! 499: }
! 500:
! 501: #else
! 502:
! 503: /* http://msdn.microsoft.com/ja-jp/library/windows/desktop/ms724834%28v=vs.85%29.aspx */
! 504: static char *osnameNT(int major, int minor)
! 505: {
! 506: if ((major == 3 && minor == 51) || (major == 4 && minor == 0)) {
! 507: return "WindowsNT";
! 508: }else if (major == 5 && minor == 0) {
! 509: return "Windows2000";
! 510: }else if (major == 5 && minor == 1) {
! 511: return "WindowsXP";
! 512: }else if (major == 5 && minor == 2) {
! 513: return "Windows2003 Server";
! 514: }else if (major == 6 && minor == 0) {
! 515: return "WindowsVista";
! 516: }else if (major == 6 && minor == 1) {
! 517: return "Windows7";
! 518: }else if (major == 6 && minor == 2) {
! 519: return "Windows8";
! 520: }else if (major == 6 && minor == 3) {
! 521: return "Windows8.1";
! 522: }
! 523: return "unknown";
! 524: }
! 525:
! 526: static char *osname95(int major, int minor)
! 527: {
! 528: if (major == 4 && minor == 0) {
! 529: return "Windows95";
! 530: }else if (major == 4 && minor == 10) {
! 531: return "Windows98";
! 532: }else if (major == 4 && minor == 90) {
! 533: return "WindowsMe";
! 534: }
! 535: return "unknown";
! 536: }
! 537:
! 538: static char *get_lang()
! 539: {
! 540: char lang[BUFSIZ];
! 541: char *s;
! 542: if(GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SISO639LANGNAME, lang, BUFSIZ)) {
! 543: s = (char *)MALLOC(strlen(lang)+1);
! 544: strcpy(s,lang);
! 545: return s;
! 546: }
! 547: return "en"; // English
! 548: }
! 549:
! 550: static void get_sysinfo()
! 551: {
! 552: int arch64 = 0;
! 553: char buf[BUFSIZ];
! 554: OSVERSIONINFO v;
! 555: char *s;
! 556: static int initialized = 0;
! 557:
! 558: if (initialized) {
! 559: return;
! 560: }
! 561: initialized = 1;
! 562:
! 563: v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
! 564: GetVersionEx(&v);
! 565:
! 566: sysinfo.type = "windows";
! 567: sysinfo.arch = "x86";
! 568: sprintf(buf, "%d.%d.%d", v.dwMajorVersion, v.dwMinorVersion, v.dwBuildNumber);
! 569: s = (char *)MALLOC(strlen(buf)+1);
! 570: strcpy(s, buf);
! 571: sysinfo.release = s;
! 572:
! 573: if (v.dwPlatformId == VER_PLATFORM_WIN32_NT) {
! 574: sysinfo.kernel = "WindowsNT";
! 575: sysinfo.name = osnameNT(v.dwMajorVersion, v.dwMinorVersion);
! 576:
! 577: #if defined(_WIN64)
! 578: sysinfo.arch = "x86_64";
! 579: #else
! 580: // IsWow64Process exists on WindowsXP SP2 or later
! 581: if(GetProcAddress(GetModuleHandle("kernel32.dll"), "IsWow64Process")) {
! 582: IsWow64Process(GetCurrentProcess(),&arch64);
! 583: if(arch64) {
! 584: sysinfo.arch = "x86_64";
! 585: }
! 586: }
! 587: #endif
! 588: }else { /* v.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS */
! 589: sysinfo.kernel = "Windows95";
! 590: sysinfo.name = osname95(v.dwMajorVersion, v.dwMinorVersion);
! 591: }
! 592: sprintf(buf, "%s %s %s %s %s", sysinfo.kernel, sysinfo.release, sysinfo.name, v.szCSDVersion, sysinfo.arch);
! 593: s = (char *)MALLOC(strlen(buf)+1);
! 594: strcpy(s, buf);
! 595: sysinfo.full = s;
! 596: sysinfo.lang = get_lang();
! 597: }
! 598:
! 599: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>