[BACK]Return to ctrl.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / builtin

Annotation of OpenXM_contrib2/asir2000/builtin/ctrl.c, Revision 1.56

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.56    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/builtin/ctrl.c,v 1.55 2017/09/04 02:10:33 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.56    ! noro      124:        {"error_in_timer",&error_in_timer,"If set to 1, the usual error handler is executed when the timer is expired."},
        !           125:        {"cputime",&prtime,"If set to 1, the CPU time at the toplevel is shown." },
        !           126:        {"nez",&nez,"If set to 1, a new version of EZGCD implementation is used."  },
        !           127:        {"echo",&echoback,"If set to 1, characters read by the input function are printed."  },
        !           128:        {"bigfloat",&bigfloat,"If set to 1, MPFR bigfloat functions are used for floating point evaluation." },
        !           129:        {"evalef",&evalef,"If set to 1, elementary functions are evaluated immediately."},
        !           130:        {"verbose",&Verbose,"If set to 1, a warning is printed if a function is redefined."},
        !           131:        {"quiet_mode",&do_quiet,"If set to 1, the copyright notices are not printed at the beginning of the session."},
        !           132:        {"hideargs",&hideargs,"If set to 1, the arguments of a function call are not printed."},
        !           133:        {"hex",&hex_output,"If set to 1, integers are printed by the hexadecimal notation."},
        !           134:        {"debug_window",&do_server_in_X11,"If set to 1, an input window for debugging remote server are shown."},
        !           135:        {"message",&do_message,"If set to 1, an opening message is printed in ox_asir and ox_plot."},
        !           136:        {"terse",&do_terse,"If set to 1, messages are not printed when user-defined callbacks are executed."},
        !           137:        {"debug_up",&debug_up,"If set to 1, some debug messages are printed in special functions for univariate polynomials."},
        !           138:        {"no_prompt",&do_quiet,"If set to 1, prompts are not shown."},
        !           139:        {"asir_setenv",&asir_setenv,"Not used."},
        !           140:        {"ox_batch",&ox_batch,"If set to 1, the OX stream are not flushed at each sending of an OX data."},
        !           141:        {"ox_check",&ox_check,"If set to 1, mathcap check is done for OpenXM date communication."},
        !           142:        {"ox_exchange_mathcap",&ox_exchange_mathcap,"If set to 1, mathcaps are exchanged."},
        !           143:        {"f4_nocheck",&f4_nocheck,"If set to 1, correctness check of the result of modular computation are omitted in nd_f4()."},
        !           144:        {"StrassenSize",&StrassenSize,"Determines the parameter in Strassen-Winograd matrix multiplication algorithm."},
        !           145:        {"outputstyle",&outputstyle,"If set to 1, structured data such as matrices and vectors are printed in the style mat(...), vect(...)."},
        !           146:        {"double_output",&double_output,"If set to 1, floating point numbers are printed in the style ddd.ddd."},
        !           147:        {"real_digit",&real_digit,"Determines the number of digits to appear after the decimal point."},
        !           148:        {"real_binary",&real_binary,"If set to 1, a floating point number is printed by the binary notation."},
        !           149:        {"fortran_output",&fortran_output,"If set to 1, ** is used instead of ^ for representing the power."},
        !           150:        {"new_hensel",&use_new_hensel,"If set to 1, a function hensel2() is used in the univariate factorizer over Q."},
        !           151:        {"print_quote",&print_quote,"Determines the behavior of the printed form of a quote."},
        !           152:        {"show_crossref",&show_crossref,"If set to 1, cross-references are shown when a program file is loaded."},
        !           153:        {"allow_laurent",&allow_laurent,"If set to 1, negative exponents are allowed in monomials."},
        !           154:        {"show_orderspec",&show_orderspec,"If set to 1, the specification of a composite term order is printed upon its creation."},
        !           155:        {"no_debug_on_error",&no_debug_on_error,"If set to 1, the debug mode is not used."},
        !           156:        {"diag_period",&diag_period,"Determines the frequency of the intermediate inter-reduction in nd_gr()."},
        !           157:        {"weight_check",&weight_check,"If set to 1, an overflow check for the given weight vector is done before starting the Groebner basis computation."},
        !           158:        {"no_ox_reset",&No_ox_reset,"Determines the treatment of OX reset request for a server which does not implement the reset protocol."},
        !           159:        {"fake_ox_reset",&No_ox_reset,"Determines the treatment of OX reset request for a server which does not implement the reset protocol."},
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.56    ! noro      171: LIST create_control_values()
        !           172: {
        !           173:   int n,i;
        !           174:   NODE top,top1,nd;
        !           175:   LIST list;
        !           176:   STRING key,desc;
        !           177:   Q val;
        !           178:
        !           179:   n = sizeof(ctrls)/sizeof(struct keyval)-1;
        !           180:   top = 0;
        !           181:   for ( i = n-1; i >= 0; i-- ) {
        !           182:     MKSTR(key,ctrls[i].key);
        !           183:     MKSTR(desc,ctrls[i].desc);
        !           184:     STOQ(*(ctrls[i].val),val);
        !           185:     nd = mknode(3,key,val,desc);
        !           186:     MKLIST(list,nd);
        !           187:     MKNODE(top1,list,top);
        !           188:    top = top1;
        !           189:   }
        !           190:   MKLIST(list,top);
        !           191:   return list;
        !           192: }
        !           193:
1.53      noro      194: void Pctrl(NODE arg,Q *rp)
1.1       noro      195: {
1.24      noro      196:        int t,i,n;
1.39      ohara     197:        int nm,dv;
1.1       noro      198:        N num,den;
                    199:        Q c;
                    200:        char *key;
                    201:        char buf[BUFSIZ];
1.24      noro      202:        char *str;
1.41      ohara     203:        STRING s;
                    204:        NODE node,p;
                    205:        LIST list;
1.50      ohara     206:        P f;
1.49      ohara     207:        extern Q ox_pari_stream;
                    208:        extern int ox_pari_stream_initialized;
1.50      ohara     209:        extern P ox_pari_starting_function;
1.1       noro      210:
                    211:        if ( !arg ) {
1.56    ! noro      212:                *rp = create_control_values();
1.1       noro      213:                return;
                    214:        }
                    215:        key = BDY((STRING)ARG0(arg));
                    216:        if ( !strcmp(key,"adj") ) {
                    217:                /* special treatment is necessary for "adj" */
                    218:                if ( argc(arg) == 1 ) {
1.39      ohara     219:                        Risa_GC_get_adj(&nm,&dv);
                    220:                        UTON(dv,num);
                    221:                        UTON(nm,den);
1.1       noro      222:                } else {
                    223:                        c = (Q)ARG1(arg);
                    224:                        if ( !c )
                    225:                                error("ctrl : adj : invalid argument");
                    226:                        num = NM(c);
                    227:                        den = !DN(c)?ONEN:DN(c);
1.39      ohara     228:                        dv = BD(num)[0];
                    229:                        nm = BD(den)[0];
                    230:                        Risa_GC_set_adj(nm,dv);
1.1       noro      231:                }
                    232:                NDTOQ(num,den,1,*rp);
1.24      noro      233:                return;
                    234:        } else if ( !strcmp(key,"prompt") ) {
                    235:                /* special treatment is necessary for "prompt" */
                    236:                if ( argc(arg) == 1 ) {
1.26      takayama  237:                  if ((!do_quiet) && (user_defined_prompt == (Obj)0)) *rp=ONE;
                    238:           else *rp = (Q)user_defined_prompt;
1.24      noro      239:                } else {
                    240:                        c = (Q)ARG1(arg);
1.25      noro      241:                        if ( !c ) {
                    242:                                do_quiet = 1;
                    243:                                user_defined_prompt = 0;
                    244:                                *rp = 0;
                    245:                        } else if ( OID(c) == O_STR ) {
                    246:                                str = BDY((STRING)c);
                    247:                                for ( i = 0, n = 0; str[i]; i++ )
                    248:                                        if ( str[i] == '%' )
                    249:                                                n++;
                    250:                                if ( n >= 2 )
                    251:                                        error("ctrl : prompt : invalid prompt specification");
1.24      noro      252:                                do_quiet = 1;
                    253:                                user_defined_prompt = (Obj)c;
                    254:                                *rp = c;
                    255:                        } else if ( NUM(c) && RATN(c) && UNIQ(c) ) {
                    256:                                user_defined_prompt = 0;
                    257:                                do_quiet = 0;
                    258:                        } else {
                    259:                                error("ctrl : prompt : invalid argument");
                    260:                        }
                    261:                }
1.1       noro      262:                return;
1.41      ohara     263:        } else if ( !strcmp(key,"loadpath") ) {
                    264:                *rp = 0;
                    265:                if ( argc(arg) == 1 ) {
                    266:                        if( ASIRLOADPATH[0] ) {
                    267:                                for(i=0; ASIRLOADPATH[i]; i++) {
                    268:                                }
                    269:                                for(i--,p=NULL; i>=0; i--,p=node) {
                    270:                                        MKSTR(s,ASIRLOADPATH[i]);
                    271:                                        MKNODE(node,s,p);
                    272:                                }
                    273:                                MKLIST(list,node);
1.53      noro      274:                                *rp = (Q)list;
1.41      ohara     275:                        }
                    276:                } else {
                    277:                        list = (LIST)ARG1(arg);
                    278:                        if ( OID(list) == O_LIST ) {
                    279:                                for(i=0,p=BDY(list); p; i++,p=NEXT(p)) {
                    280:                                        s=(STRING)BDY(p);
                    281:                                        if(!s || OID(s)!=O_STR) {
                    282:                                                error("ctrl : loadpath : invalid argument");
                    283:                                        }
                    284:                                }
                    285:                                if(i >= ASIRLOADPATH_LEN) {
                    286:                                        ASIRLOADPATH_LEN = i+1;
                    287:                                        ASIRLOADPATH = (char **)MALLOC(sizeof(char *)*ASIRLOADPATH_LEN);
                    288:                                }
                    289:                                for(i=0,p=BDY(list); p; i++,p=NEXT(p)) {
                    290:                                        ASIRLOADPATH[i] = (char *)BDY((STRING)BDY(p));
                    291:                                }
                    292:                                ASIRLOADPATH[i] = NULL;
                    293:                        }else {
                    294:                                error("ctrl : loadpath : invalid argument");
                    295:                        }
                    296:                }
                    297:                return;
1.49      ohara     298:        } else if ( !strcmp(key,"oxpari_id") ) {
                    299:         if ( argc(arg) == 1 ) {
                    300:             if(!ox_pari_stream_initialized) {
                    301:                 t=-1;
                    302:                 STOQ(t,*rp);
                    303:             }else {
                    304:                 *rp = ox_pari_stream;
                    305:             }
                    306:         }else {
                    307:                        c = (Q)ARG1(arg);
                    308:                        if ( !c || ( NUM(c) && INT(c) && SGN(c)>0 ) ) {
                    309:                                ox_pari_stream_initialized = 1;
                    310:                                ox_pari_stream = c;
                    311:                                *rp = c;
                    312:                        }else {
                    313:                 t=-1;
                    314:                 STOQ(t,*rp);
                    315:                        }
                    316:                }
                    317:                return;
1.50      ohara     318:        } else if ( !strcmp(key,"oxpari_start") ) {
                    319:         if ( argc(arg) == 1 ) {
1.53      noro      320:                        *rp = (Q)ox_pari_starting_function;
1.50      ohara     321:                } else {
1.53      noro      322:                        f = (P)ARG1(arg);
1.50      ohara     323:                        if ( !f || OID(f) == O_P) {
                    324:                                ox_pari_starting_function = f;
1.53      noro      325:                                *rp = (Q)f;
1.50      ohara     326:                        }else {
                    327:                                *rp = 0;
                    328:                        }
                    329:                }
                    330:                return;
1.1       noro      331:        }
                    332:        for ( i = 0; ctrls[i].key; i++ )
                    333:                if ( !strcmp(key,ctrls[i].key) )
                    334:                        break;
                    335:        if ( ctrls[i].key ) {
                    336:                if ( argc(arg) == 1 )
                    337:                        t = *ctrls[i].val;
                    338:                else
                    339:                        *ctrls[i].val = t = QTOS((Q)ARG1(arg));
                    340:                STOQ(t,*rp);
                    341:        } else {
                    342:                sprintf(buf,"ctrl : %s : no such key",key);
                    343:                error(buf);
                    344:        }
                    345: }
1.42      ohara     346:
                    347: void Psysinfo(LIST *rp)
                    348: {
                    349:     int i;
                    350:     NODE n,p;
1.44      ohara     351:     STRING s[7];
1.42      ohara     352:
                    353:     get_sysinfo();
                    354:     MKSTR(s[0],sysinfo.type);  MKSTR(s[1],sysinfo.kernel);   MKSTR(s[2],sysinfo.name);
                    355:     MKSTR(s[3],sysinfo.arch);  MKSTR(s[4],sysinfo.release);  MKSTR(s[5],sysinfo.full);
1.44      ohara     356:     MKSTR(s[6],sysinfo.lang);
                    357:     for(i=6,p=NULL; i>=0; i--,p=n) {
1.42      ohara     358:         MKNODE(n,s[i],p);
                    359:     }
                    360:     MKLIST(*rp,n);
                    361: }
                    362:
1.48      fujimoto  363: #if !defined(VISUAL) && !defined(__MINGW32__)
1.44      ohara     364:
                    365: static char *get_lang()
                    366: {
                    367:     char *c, *p, *q;
                    368:     c = setlocale(LC_ALL, NULL); /* saving current locale */
                    369:     p = setlocale(LC_ALL, "");
                    370:     q = (char *)MALLOC(strlen(p)+1);
                    371:     strcpy(q,p);
                    372:     setlocale(LC_ALL, c);        /* restoring current locale */
                    373:     return q;
                    374: }
                    375:
1.43      ohara     376: static char *myuname(char *option)
1.42      ohara     377: {
                    378:     char buf[BUFSIZ];
                    379:     char *s;
1.43      ohara     380:     int fd[2], status, pid;
1.42      ohara     381:     *buf = 0;
                    382:     if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) {
1.43      ohara     383:         *buf = 0; return NULL;
1.42      ohara     384:     }
1.43      ohara     385:     pid = fork();
                    386:     if (pid < 0) {
                    387:         return NULL;
                    388:     }else if (pid == 0) {
1.42      ohara     389:         dup2(fd[1], 1);
1.43      ohara     390:         close(2);
1.42      ohara     391:         execlp("uname", "uname", option, NULL);
                    392:     }
1.43      ohara     393:     waitpid(pid, &status, 0);
                    394:     if (status) { /* error */
                    395:         return NULL;
                    396:     }
1.42      ohara     397:     s = buf;
                    398:     if( !read(fd[0], s, BUFSIZ-1) || (s = strchr(s, '\n')) ) {
                    399:         *s = 0;
                    400:     }
                    401:     close(fd[0]);
                    402:     close(fd[1]);
                    403:     s = (char *)MALLOC(strlen(buf)+1);
                    404:     strcpy(s, buf);
                    405:     return s;
                    406: }
                    407:
                    408: static void get_sysinfo()
                    409: {
1.43      ohara     410:     static struct utsname u;
1.42      ohara     411:     static int initialized = 0;
                    412:     if (initialized) {
                    413:         return;
                    414:     }
                    415:     initialized = 1;
1.43      ohara     416:     uname(&u);
                    417:     sysinfo.kernel = u.sysname;
1.42      ohara     418: #if defined(__DARWIN__)
                    419:     sysinfo.type   = "macosx";
                    420:     sysinfo.name   = sysinfo.kernel;
                    421: #else
                    422:     sysinfo.type   = "unix";
1.43      ohara     423:     sysinfo.name   = myuname("-o"); // not work on Darwin
                    424:     if (!sysinfo.name) {
                    425:         sysinfo.name = sysinfo.kernel;
                    426:     }
1.42      ohara     427: #endif
1.43      ohara     428:     sysinfo.arch   = u.machine;
                    429:     sysinfo.release= u.release;
                    430:     sysinfo.full   = myuname("-a");
1.44      ohara     431:     sysinfo.lang   = get_lang();
1.42      ohara     432: }
                    433:
                    434: #else
                    435:
                    436: /* http://msdn.microsoft.com/ja-jp/library/windows/desktop/ms724834%28v=vs.85%29.aspx */
                    437: static char *osnameNT(int major, int minor)
                    438: {
                    439:     if ((major == 3 && minor == 51) || (major == 4 && minor == 0)) {
                    440:         return "WindowsNT";
                    441:     }else if (major == 5 && minor == 0) {
                    442:         return "Windows2000";
                    443:     }else if (major == 5 && minor == 1) {
                    444:         return "WindowsXP";
                    445:     }else if (major == 5 && minor == 2) {
                    446:         return "Windows2003 Server";
                    447:     }else if (major == 6 && minor == 0) {
                    448:         return "WindowsVista";
                    449:     }else if (major == 6 && minor == 1) {
                    450:         return "Windows7";
                    451:     }else if (major == 6 && minor == 2) {
                    452:         return "Windows8";
                    453:     }else if (major == 6 && minor == 3) {
                    454:         return "Windows8.1";
                    455:     }
                    456:     return "unknown";
                    457: }
                    458:
                    459: static char *osname95(int major, int minor)
                    460: {
                    461:     if (major == 4 && minor == 0) {
                    462:         return "Windows95";
                    463:     }else if (major == 4 && minor == 10) {
                    464:         return "Windows98";
                    465:     }else if (major == 4 && minor == 90) {
                    466:         return "WindowsMe";
                    467:     }
                    468:     return "unknown";
                    469: }
                    470:
1.44      ohara     471: static char *get_lang()
                    472: {
                    473:     char lang[BUFSIZ];
                    474:     char *s;
                    475:     if(GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SISO639LANGNAME, lang, BUFSIZ)) {
                    476:         s = (char *)MALLOC(strlen(lang)+1);
                    477:         strcpy(s,lang);
                    478:         return s;
                    479:     }
                    480:     return "en"; // English
                    481: }
                    482:
1.42      ohara     483: static void get_sysinfo()
                    484: {
                    485:     int arch64 = 0;
                    486:     char buf[BUFSIZ];
                    487:     OSVERSIONINFO v;
                    488:     char *s;
                    489:     static int initialized = 0;
                    490:
                    491:     if (initialized) {
                    492:         return;
                    493:     }
                    494:     initialized = 1;
                    495:
                    496:     v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
                    497:     GetVersionEx(&v);
                    498:
                    499:     sysinfo.type = "windows";
                    500:     sysinfo.arch = "x86";
                    501:     sprintf(buf, "%d.%d.%d", v.dwMajorVersion, v.dwMinorVersion, v.dwBuildNumber);
                    502:     s = (char *)MALLOC(strlen(buf)+1);
                    503:     strcpy(s, buf);
                    504:     sysinfo.release = s;
                    505:
                    506:     if (v.dwPlatformId == VER_PLATFORM_WIN32_NT) {
                    507:         sysinfo.kernel = "WindowsNT";
                    508:         sysinfo.name = osnameNT(v.dwMajorVersion, v.dwMinorVersion);
                    509:
                    510: #if defined(_WIN64)
                    511:         sysinfo.arch = "x86_64";
                    512: #else
                    513:         // IsWow64Process exists on WindowsXP SP2 or later
                    514:         if(GetProcAddress(GetModuleHandle("kernel32.dll"), "IsWow64Process")) {
                    515:             IsWow64Process(GetCurrentProcess(),&arch64);
                    516:             if(arch64) {
                    517:                 sysinfo.arch = "x86_64";
                    518:             }
                    519:         }
                    520: #endif
                    521:     }else { /* v.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS */
                    522:         sysinfo.kernel = "Windows95";
                    523:         sysinfo.name = osname95(v.dwMajorVersion, v.dwMinorVersion);
                    524:     }
                    525:     sprintf(buf, "%s %s %s %s %s", sysinfo.kernel, sysinfo.release, sysinfo.name, v.szCSDVersion, sysinfo.arch);
                    526:     s = (char *)MALLOC(strlen(buf)+1);
                    527:     strcpy(s, buf);
                    528:     sysinfo.full = s;
1.44      ohara     529:     sysinfo.lang = get_lang();
1.42      ohara     530: }
                    531:
                    532: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>