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

Annotation of OpenXM_contrib2/asir2000/builtin/miscf.c, Revision 1.31

1.7       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.8       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.7       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.31    ! ohara      48:  * $OpenXM: OpenXM_contrib2/asir2000/builtin/miscf.c,v 1.30 2013/06/13 08:11:55 ohara Exp $
1.7       noro       49: */
1.1       noro       50: #include "ca.h"
                     51: #include "parse.h"
1.27      ohara      52: #include <string.h>
1.17      noro       53: #if !defined(VISUAL) && defined(DO_PLOT)
1.1       noro       54: #include <X11/Xlib.h>
                     55: #include <X11/cursorfont.h>
                     56: #endif
                     57:
1.12      noro       58: #if defined(VISUAL)
1.28      ohara      59: #include <direct.h>
1.12      noro       60: #include <stdlib.h>
                     61: #include <windows.h>
1.27      ohara      62: #else
                     63: #include <unistd.h>
                     64: #include <sys/param.h>
1.12      noro       65: #endif
                     66:
1.27      ohara      67: void Pgetcwd(), Pchdir();
1.24      noro       68: void Pset_secure_mode();
                     69: void Pset_secure_flag();
1.1       noro       70: void Pquit(), Pdebug(), Pnmono(), Pnez(), Popt(), Pshell(), Pheap();
1.20      noro       71: void Ptoplevel();
1.21      ohara      72: void Perror(), Perror3(), Pversion(), Pcopyright(), Pflist(), Pdelete_history(), Ppause(), Pxpause();
1.1       noro       73: void Pr2g(), Pread_cmo(), Pwrite_cmo();
                     74: void Pgc(),Pbatch(),Psend_progress();
                     75: void Pnull_command();
                     76: void Pgetenv();
1.9       noro       77: void Pget_addr(),Phex_dump();
                     78: void Ppeek(),Ppoke();
1.12      noro       79: void Psleep();
1.18      noro       80: void Premove_module();
                     81: void Pmodule_list();
1.19      takayama   82: void Pmodule_definedp();
1.22      noro       83: void Ptest();
1.1       noro       84:
                     85: void delete_history(int,int);
                     86:
                     87: struct ftab misc_tab[] = {
1.27      ohara      88:        {"pwd",Pgetcwd,0},
                     89:        {"chdir",Pchdir,1},
1.24      noro       90:        {"set_secure_mode",Pset_secure_mode,-1},
                     91:        {"set_secure_flag",Pset_secure_flag,-2},
1.18      noro       92:        {"module_list",Pmodule_list,0},
                     93:        {"remove_module",Premove_module,1},
1.19      takayama   94:        {"module_definedp",Pmodule_definedp,1},
1.12      noro       95:        {"sleep",Psleep,1},
1.1       noro       96:        {"null_command",Pnull_command,-99999},
                     97:        {"getenv",Pgetenv,1},
                     98:        {"end",Pquit,0},
                     99:        {"quit",Pquit,0},
                    100:        {"debug",Pdebug,0},
                    101:        {"shell",Pshell,-2},
                    102:        {"heap",Pheap,-1},
1.11      noro      103:        {"version",Pversion,-99999},
1.21      ohara     104:        {"copyright",Pcopyright,0},
1.1       noro      105:        {"nmono",Pnmono,1},
1.20      noro      106:        {"toplevel",Ptoplevel,-1},
1.1       noro      107:        {"error",Perror,1},
                    108:        {"error3",Perror3,3},
                    109:        {"nez",Pnez,1},
1.18      noro      110:        {"flist",Pflist,-1},
1.1       noro      111:        {"delete_history",Pdelete_history,-2},
                    112:        {"pause",Ppause,0},
                    113:        {"gc",Pgc,0},
                    114:        {"batch",Pbatch,2},
                    115:        {"send_progress",Psend_progress,-2},
1.9       noro      116:        {"get_addr",Pget_addr,1},
                    117:        {"hex_dump",Phex_dump,2},
                    118:        {"peek",Ppeek,1},
                    119:        {"poke",Ppoke,2},
1.16      noro      120: #if !defined(VISUAL) && defined(DO_PLOT)
1.1       noro      121:        {"xpause",Pxpause,0},
                    122: #endif
                    123: #if 0
                    124:        {"opt",Popt,1},
                    125: #endif
                    126:        {0,0,0},
                    127: };
1.24      noro      128:
1.27      ohara     129: void Pgetcwd(STRING *rp)
                    130: {
                    131:        char *r;
1.28      ohara     132: #if defined(VISUAL)
                    133:        char buf[_MAX_PATH];
                    134:        _getcwd(buf, _MAX_PATH);
                    135: #else
1.27      ohara     136:        char buf[MAXPATHLEN];
                    137:        getcwd(buf, MAXPATHLEN);
1.28      ohara     138: #endif
1.27      ohara     139:        r = (char *)MALLOC_ATOMIC(strlen(buf)+1);
                    140:        strcpy(r,buf);
                    141:        MKSTR(*rp,r);
                    142: }
                    143:
                    144: void Pchdir(NODE arg, Q *rp)
                    145: {
                    146:        char *dir = BDY((STRING)ARG0(arg));
1.28      ohara     147: #if defined(VISUAL)
                    148:        int status = _chdir(dir);
                    149: #else
1.27      ohara     150:        int status = chdir(dir);
1.28      ohara     151: #endif
1.27      ohara     152:        STOQ(status,*rp);
                    153: }
                    154:
1.24      noro      155: void Pset_secure_mode(NODE arg,Q *rp)
                    156: {
                    157:        int s;
                    158:        if ( argc(arg) )
                    159:                setsecuremode(QTOS((Q)ARG0(arg)));
                    160:        s = getsecuremode();
                    161:        STOQ(s,*rp);
                    162: }
                    163:
                    164: void Pset_secure_flag(NODE arg,Q *rp)
                    165: {
1.25      noro      166:        int ac,s,status;
                    167:        Obj f;
                    168:        char *fname;
1.24      noro      169:
                    170:        ac = argc(arg);
                    171:        if ( !ac )
                    172:                error("set_secure_flag : a function name must be specified");
                    173:        if ( ac == 2 )
                    174:                s = QTOS((Q)ARG1(arg));
                    175:        else
                    176:                s = 1;
1.25      noro      177:        f = ARG0(arg);
                    178:        if ( !f )
                    179:                error("set_secure_flag : invalid argument");
                    180:        switch ( OID(f) ) {
                    181:                case O_STR:
                    182:                        fname = BDY((STRING)f); break;
                    183:                case O_P:
                    184:                        fname = NAME(VR((P)f)); break;
                    185:                default:
                    186:                        error("set_secure_flag : invalid argument"); break;
                    187:        }
                    188:        status = setsecureflag(fname,s);
                    189:        if ( status < 0 )
                    190:                error("set_secure_flag : function not found");
1.24      noro      191:        STOQ(s,*rp);
                    192: }
1.22      noro      193:
                    194: void Ptest(arg,rp)
                    195: NODE arg;
                    196: Q *rp;
                    197: {
                    198:        int r;
                    199:
                    200:        r = equalr(CO,ARG0(arg),ARG1(arg));
                    201:        STOQ(r,*rp);
                    202: }
1.12      noro      203:
                    204: void Psleep(arg,rp)
                    205: NODE arg;
                    206: Q *rp;
                    207: {
                    208:        int ms;
                    209:
                    210:        ms = QTOS((Q)ARG0(arg));
                    211: #if defined(VISUAL)
                    212:        Sleep(ms);
                    213: #else
                    214:        usleep(ms*1000);
                    215: #endif
                    216:        *rp = ONE;
                    217: }
1.1       noro      218:
1.18      noro      219: void Pmodule_list(rp)
                    220: LIST *rp;
                    221: {
                    222:        char *name;
                    223:        NODE r,r1,m;
                    224:        STRING s;
                    225:
                    226:        r = 0;
                    227:        for ( m = MODULE_LIST; m; m = NEXT(m) ) {
                    228:                MKSTR(s,((MODULE)BDY(m))->name);
                    229:                MKNODE(r1,s,r); r = r1;
                    230:        }
                    231:        MKLIST(*rp,r);
                    232: }
                    233:
                    234: void Premove_module(arg,rp)
                    235: NODE arg;
                    236: Q *rp;
                    237: {
                    238:        NODE pm,m;
                    239:        char *name;
                    240:
                    241:        asir_assert(ARG0(arg),O_STR,"remove_module");
                    242:        name = BDY((STRING)ARG0(arg));
                    243:        for ( pm = 0, m = MODULE_LIST; m; pm = m, m = NEXT(m) )
                    244:                if ( !strcmp(name,((MODULE)BDY(m))->name) ) {
                    245:                        if ( !pm )
                    246:                                MODULE_LIST = NEXT(MODULE_LIST);
                    247:                        else
                    248:                                NEXT(pm) = NEXT(m);
                    249:                        *rp = ONE;
                    250:                        return;
1.19      takayama  251:                }
                    252:        *rp = 0;
                    253: }
                    254:
                    255: void Pmodule_definedp(arg,rp)
                    256: NODE arg;
                    257: Q *rp;
                    258: {
                    259:        NODE m;
                    260:        char *name;
                    261:
                    262:        asir_assert(ARG0(arg),O_STR,"module_definedp");
                    263:        name = BDY((STRING)ARG0(arg));
                    264:     /* bug: the linear search is used here. The list of module shoud be sorted
                    265:        and cashed, and binary search should be used. */
                    266:        for (m = MODULE_LIST; m; m = NEXT(m) )
                    267:                if ( !strcmp(name,((MODULE)BDY(m))->name) ) {
                    268:                        *rp = ONE;
                    269:                        return ;
1.18      noro      270:                }
                    271:        *rp = 0;
                    272: }
                    273:
1.1       noro      274: void Pgetenv(arg,rp)
                    275: NODE arg;
                    276: STRING *rp;
                    277: {
                    278:        char *e,*f;
1.31    ! ohara     279:        size_t len;
1.1       noro      280:
                    281:        e = (char *)getenv(BDY((STRING)ARG0(arg)));
                    282:        if ( e ) {
                    283:                len = strlen(e);
                    284:                f = (char *)MALLOC_ATOMIC(len+1);
                    285:                strcpy(f,e);
                    286:                MKSTR(*rp,f);
                    287:        } else
                    288:                *rp = 0;
                    289: }
                    290:
                    291: void Pnull_command(arg,rp)
                    292: NODE arg;
                    293: Q *rp;
                    294: {
                    295:        *rp = 0;
                    296: }
                    297:
                    298: void Pquit(rp)
                    299: pointer *rp;
                    300: {
1.26      noro      301:        if ( asir_infile && NEXT(asir_infile) && asir_infile->ready_for_longjmp )
                    302:                LONGJMP(asir_infile->jmpbuf,1);
1.1       noro      303:        else {
                    304:                closecurrentinput();
1.26      noro      305:                asir_terminate(2);
1.1       noro      306:        }
                    307:        *rp = 0;
                    308: }
                    309:
                    310: void Pdebug(rp)
                    311: pointer *rp;
                    312: {
                    313:        debug(0); *rp = 0;
                    314: }
                    315:
                    316: void Pshell(arg,rp)
                    317: NODE arg;
                    318: Q *rp;
                    319: {
                    320:        char *com = 0;
                    321:        char *pstr = 0;
                    322:        int status;
                    323:
                    324:        if ( arg ) {
                    325:                asir_assert(ARG0(arg),O_STR,"shell");
                    326:                com = BDY((STRING)ARG0(arg));
                    327:                if ( NEXT(arg) )
                    328:                        pstr = BDY((STRING)ARG1(arg));
                    329:        }
                    330:        status = system(com);
                    331:        STOQ(status,*rp);
                    332: }
                    333:
                    334: void Pnmono(arg,rp)
                    335: NODE arg;
                    336: Q *rp;
                    337: {
                    338:        Obj obj;
                    339:        int n;
                    340:
                    341:        obj = (Obj)ARG0(arg);
                    342:        if ( !obj || OID(obj) > O_R )
                    343:                *rp = 0;
                    344:        else
                    345:                switch (OID(obj)) {
                    346:                        case O_N: case O_P:
                    347:                                n = nmonop((P)obj); STOQ(n,*rp); break;
                    348:                        case O_R:
                    349:                                n = nmonop(NM((R)obj)) + nmonop(DN((R)obj));
                    350:                                STOQ(n,*rp); break;
                    351:                }
                    352: }
                    353:
                    354: void Pheap(arg,rp)
                    355: NODE arg;
                    356: Q *rp;
                    357: {
1.29      ohara     358:        size_t h0,h;
                    359:        unsigned int u,l;
                    360:        N n;
1.1       noro      361:        void GC_expand_hp(int);
                    362:
                    363:        h0 = get_heapsize();
                    364:        if ( arg ) {
                    365:                h = QTOS((Q)ARG0(arg));
                    366:                if ( h > h0 )
                    367:                        GC_expand_hp(h-h0);
                    368:        }
                    369:        h = get_heapsize();
1.29      ohara     370:        if(sizeof(size_t)>sizeof(int)) {
                    371:                u = h>>(sizeof(int)*CHAR_BIT); l = h&(~0);
1.30      ohara     372:                if ( !u ) UTOQ(l,*rp);
1.29      ohara     373:                else {
                    374:                        n = NALLOC(2); PL(n)=2; BD(n)[0] = l; BD(n)[1] = u;
                    375:                        NTOQ(n,1,*rp);
                    376:                }
                    377:        }else {
1.30      ohara     378:                UTOQ(h,*rp);
1.29      ohara     379:        }
1.1       noro      380: }
                    381:
                    382: unsigned int get_asir_version();
1.11      noro      383: char *get_asir_distribution();
1.1       noro      384:
1.11      noro      385: void Pversion(arg,rp)
                    386: NODE arg;
                    387: Obj *rp;
1.1       noro      388: {
                    389:        unsigned int version;
1.11      noro      390:        char *distribution;
                    391:        Q q;
                    392:        STRING str;
                    393:        NODE n;
                    394:        LIST l;
1.1       noro      395:
                    396:        version = get_asir_version();
1.11      noro      397:        distribution = get_asir_distribution();
1.13      noro      398:        UTOQ(version,q);
1.11      noro      399:        if ( !argc(arg) )
                    400:                *rp = (Obj)q;
                    401:        else {
                    402:                MKSTR(str,distribution);
                    403:                n = mknode(2,q,str);
                    404:                MKLIST(l,n);
                    405:                *rp = (Obj)l;
                    406:        }
1.21      ohara     407: }
                    408:
                    409: char *scopyright();
                    410:
                    411: void Pcopyright(rp)
                    412: STRING *rp;
                    413: {
                    414:        MKSTR(*rp,scopyright());
1.1       noro      415: }
                    416:
                    417: extern int nez;
                    418:
                    419: void Pnez(arg,rp)
                    420: NODE arg;
                    421: pointer *rp;
                    422: {
                    423:        nez = ARG0(arg) ? 1 : 0; *rp = 0;
                    424: }
                    425:
                    426: void Perror(arg,rp)
                    427: NODE arg;
                    428: Q *rp;
                    429: {
                    430:        char *s;
                    431:
                    432:        if ( !arg || !ARG0(arg) || (OID((Obj)ARG0(arg)) != O_STR) )
                    433:                s = "";
                    434:        else
                    435:                s = BDY((STRING)ARG0(arg));
                    436:        error(s);
1.20      noro      437:        *rp = 0;
                    438: }
                    439:
                    440: void Ptoplevel(arg,rp)
                    441: NODE arg;
                    442: Q *rp;
                    443: {
                    444:        char *s;
                    445:
                    446:        if ( !arg || !ARG0(arg) || (OID((Obj)ARG0(arg)) != O_STR) )
                    447:                s = "";
                    448:        else
                    449:                s = BDY((STRING)ARG0(arg));
                    450:        toplevel(s);
1.1       noro      451:        *rp = 0;
                    452: }
                    453:
                    454: void Perror3(arg,rp)
                    455: NODE arg;
                    456: Q *rp;
                    457: {
                    458:        int code;
                    459:        char *reason,*action;
                    460:
                    461:        asir_assert(ARG0(arg),O_N,"error3");
                    462:        asir_assert(ARG1(arg),O_STR,"error3");
                    463:        asir_assert(ARG2(arg),O_STR,"error3");
                    464:        code = QTOS((Q)ARG0(arg));
                    465:        reason = BDY((STRING)ARG1(arg));
                    466:        action = BDY((STRING)ARG2(arg));
1.3       noro      467: #if defined(VISUAL)
1.1       noro      468:        set_error(code,reason,action);
1.3       noro      469: #endif
1.1       noro      470:        error("");
                    471:        *rp = 0;
                    472: }
                    473:
1.18      noro      474: void Pflist(arg,rp)
                    475: NODE arg;
1.1       noro      476: LIST *rp;
                    477: {
                    478:        char *n;
                    479:        STRING name;
1.18      noro      480:        char *mname;
                    481:        NODE t,r,r0,m;
1.1       noro      482:        LIST l;
                    483:
1.18      noro      484:        if ( argc(arg) ) {
                    485:                /* module name is specified */
                    486:                asir_assert(ARG0(arg),O_STR,"flist");
                    487:                mname = BDY((STRING)ARG0(arg));
                    488:                r0 = 0;
                    489:                for ( m = MODULE_LIST; m; m = NEXT(m) ) {
                    490:                        if ( !strcmp(mname,((MODULE)BDY(m))->name) ) {
                    491:                                t = ((MODULE)BDY(m))->usrf_list;
                    492:                                for ( r0 = 0; t; t = NEXT(t) )
                    493:                                        if ( ((FUNC)BDY(t))->id != A_UNDEF ) {
                    494:                                                n = NAME((FUNC)BDY(t)); MKSTR(name,n);
                    495:                                                MKNODE(r,name,r0); r0 = r;
                    496:                                }
                    497:                        }
1.1       noro      498:                }
1.18      noro      499:        } else {
                    500:                for ( t = usrf, r0 = 0; t; t = NEXT(t) )
                    501:                        if ( ((FUNC)BDY(t))->id != A_UNDEF ) {
                    502:                                n = NAME((FUNC)BDY(t)); MKSTR(name,n);
                    503:                                MKNODE(r,name,r0); r0 = r;
                    504:                        }
                    505:                for ( t = ubinf; t; t = NEXT(t) )
                    506:                        if ( ((FUNC)BDY(t))->id != A_UNDEF ) {
                    507:                                n = NAME((FUNC)BDY(t)); MKSTR(name,n);
                    508:                                MKNODE(r,name,r0); r0 = r;
                    509:                        }
                    510:                for ( t = sysf; t; t = NEXT(t) )
                    511:                        if ( ((FUNC)BDY(t))->id != A_UNDEF ) {
                    512:                                n = NAME((FUNC)BDY(t)); MKSTR(name,n);
                    513:                                MKNODE(r,name,r0); r0 = r;
                    514:                        }
                    515:        }
1.1       noro      516:        MKLIST(l,r0); *rp = l;
                    517: }
                    518:
                    519: void Pdelete_history(arg,rp)
                    520: NODE arg;
                    521: Q *rp;
                    522: {
                    523:        switch ( argc(arg) ) {
                    524:                case 0: default:
                    525:                        delete_history(0,(int)APVS->n);
                    526:                        break;
                    527:                case 1:
                    528:                        delete_history(QTOS((Q)ARG0(arg)),1);
                    529:                        break;
                    530:        }
                    531:        *rp = 0;
                    532: }
                    533:
                    534: void delete_history(start,n)
                    535: int start,n;
                    536: {
                    537:        int i,max;
                    538:
                    539:        max = APVS->n;
                    540:        if ( start < 0 || start >= max )
                    541:                return;
                    542:        if ( start + n > max )
                    543:                n = max - start;
                    544:        for ( i = 0; i < n; i++ )
                    545:                APVS->va[start+i].priv = 0;
                    546: }
                    547:
                    548: void Ppause(rp)
                    549: LIST *rp;
                    550: {
                    551:        char buf[BUFSIZ];
                    552:
                    553:        fgets(buf,BUFSIZ,stdin);
                    554:        *rp = 0;
                    555: }
                    556:
                    557: void Pgc(rp)
                    558: LIST *rp;
                    559: {
                    560:        GC_gcollect();
                    561:        *rp = 0;
                    562: }
                    563:
                    564: int exec_file(char *,char *);
                    565:
                    566: void Pbatch(arg,rp)
                    567: NODE arg;
                    568: Q *rp;
                    569: {
                    570:        int ret;
                    571:
                    572:        ret = exec_file(BDY((STRING)ARG0(arg)),BDY((STRING)ARG1(arg)));
                    573:        STOQ(ret,*rp);
                    574: }
                    575:
1.16      noro      576: #if !defined(VISUAL) && defined(DO_PLOT)
1.1       noro      577: void Pxpause(rp)
                    578: Q *rp;
                    579: {
                    580:        if ( !init_display() )
                    581:                *rp = 0;
                    582:        else {
                    583:                grab_pointer(); *rp = ONE;
                    584:        }
                    585: }
                    586:
                    587: static Display *display;
                    588: static Window rootwin;
                    589:
                    590: init_display()
                    591: {
                    592:        char *dname;
                    593:        unsigned int tmp;
                    594:        static int initialized;
                    595:        int argc;
                    596:        char *argv[1];
                    597:
                    598:        if ( initialized )
                    599:                return 1;
                    600:        else
                    601:                initialized = 1;
                    602:        dname = (char *)getenv("DISPLAY");
                    603:
                    604:        display = XOpenDisplay(dname);
                    605:        if ( !display ) {
                    606:                fprintf(stderr,"Can't open display\n");
                    607:                return 0;
                    608:        }
                    609:        rootwin = RootWindow(display,DefaultScreen(display));
                    610: }
                    611:
                    612: grab_pointer()
                    613: {
                    614:        XEvent ev;
                    615:        static Cursor cursor;
                    616:
                    617:        if ( !cursor )
                    618:                cursor = XCreateFontCursor(display,XC_leftbutton);
                    619:        XGrabPointer(display,rootwin,True,ButtonPressMask,GrabModeAsync,GrabModeAsync,None,cursor,CurrentTime);
                    620:        while ( 1 ) {
                    621:                XNextEvent(display,&ev);
                    622:                if ( ev.xany.type == ButtonPress )
                    623:                        break;
                    624:        }
                    625:        XUngrabPointer(display,CurrentTime);
                    626:        XSync(display,False);
                    627:        return;
                    628: }
                    629: #endif
                    630:
                    631: void Psend_progress(NODE arg,Q *rp)
                    632: {
                    633: #if defined(VISUAL)
                    634:        short per;
                    635:        char *msg;
                    636:
                    637:        per = (short)QTOS((Q)BDY(arg)); arg = NEXT(arg);
                    638:        if ( arg )
                    639:                msg = BDY((STRING)BDY(arg));
                    640:        else
                    641:                msg = "";
                    642:        send_progress(per,msg);
                    643: #endif
1.9       noro      644:        *rp = 0;
                    645: }
                    646:
                    647: void Pget_addr(arg,rp)
                    648: NODE arg;
                    649: Q *rp;
                    650: {
                    651:        pointer obj;
                    652:        unsigned int u,l;
                    653:        N n;
                    654:
                    655:        obj = ARG0(arg);
                    656:        if ( sizeof(pointer) == sizeof(unsigned int) ) {
                    657:                UTOQ((unsigned int)obj,*rp);
                    658:        } else {
                    659:                /* a pointer must fit in long */
                    660:                u = ((unsigned long)obj)>>32;
                    661:                l = ((unsigned long)obj)&(unsigned long)0xffffffff;
                    662:                if ( u ) {
                    663:                        n = NALLOC(2); PL(n) = 2; BD(n)[0] = l; BD(n)[1] = u;
                    664:                        NTOQ(n,1,*rp);
                    665:                } else {
                    666:                        UTOQ(l,*rp);
                    667:                }
                    668:        }
                    669: }
                    670:
                    671: unsigned char *qtoaddr(q)
                    672: Q q;
                    673: {
                    674:        unsigned char *addr;
                    675:        N n;
                    676:
                    677:        if ( !q )
                    678:                return 0;
                    679:        n = NM(q);
                    680:        if ( (sizeof(pointer) == sizeof(unsigned int)) || (PL(n) == 1) )
                    681:                addr = (char *)BD(n)[0];
                    682:        else {
                    683:                /* a pointer must fit in long */
                    684:                addr = (char *)((((unsigned long)BD(n)[1])<<32)
                    685:                        | ((unsigned long)BD(n)[0]));
                    686:        }
                    687:        return addr;
                    688: }
                    689:
                    690: void Phex_dump(arg,rp)
                    691: NODE arg;
                    692: Q *rp;
                    693: {
                    694:        unsigned char *start;
                    695:        int len,i;
                    696:
                    697:        *rp = 0;
                    698:        start = qtoaddr((Q)ARG0(arg));
                    699:        len = QTOS((Q)ARG1(arg));
                    700:        for ( i = 0; i < len; i++ ) {
                    701:                if ( !(i%16) )
                    702:                        fprintf(asir_out,"%08x: ",start+i);
                    703:                fprintf(asir_out,"%02x",start[i]);
                    704:                if ( !((i+1)%16) )
                    705:                        fprintf(asir_out,"\n");
                    706:                else if ( !((i+1)%4) )
                    707:                        fprintf(asir_out," ");
                    708:        }
                    709:        if ( i%16 )
                    710:                fprintf(asir_out,"\n");
                    711: }
                    712:
                    713: void Ppeek(arg,rp)
                    714: NODE arg;
                    715: Q *rp;
                    716: {
                    717:        unsigned int b;
                    718:        unsigned char *a;
                    719:
                    720:        a = qtoaddr((Q)ARG0(arg));
                    721:        b = (unsigned int) (*a);
                    722:        UTOQ(b,*rp);
                    723: }
                    724:
                    725: void Ppoke(arg,rp)
                    726: NODE arg;
                    727: Q *rp;
                    728: {
                    729:        unsigned char *addr;
                    730:
                    731:        addr = qtoaddr((Q)ARG0(arg));
                    732:        *addr = (unsigned char)QTOS((Q)ARG1(arg));
1.1       noro      733:        *rp = 0;
                    734: }
                    735:
                    736: #if 0
                    737: static int optimize;
                    738: static struct oN oPSN[1000];
                    739: static struct oQ oPSZ[1000],oMSZ[1000];
                    740: static szinit = 0;
                    741:
                    742: void Popt(arg,rp)
                    743: NODE arg;
                    744: pointer *rp;
                    745: {
                    746:        optimize = ARG0(arg) ? 1 : 0; *rp = 0;
                    747: }
                    748:
                    749:
                    750: void sz_init() {
                    751:        int i;
                    752:        Q t;
                    753:
                    754:        for ( i = 1; i < 1000; i++ ) {
                    755:                oPSN[i].p = 1; oPSN[i].b[0] = i;
                    756:                t = &oPSZ[i];
                    757:                OID(t) = O_N; NID(t) = N_Q; SGN(t) = 1; NM(t) = &oPSN[i]; DN(t) = 0;
                    758:                t = &oMSZ[i];
                    759:                OID(t) = O_N; NID(t) = N_Q; SGN(t) = -1; NM(t) = &oPSN[i]; DN(t) = 0;
                    760:        }
                    761:        szinit = 1;
                    762: }
                    763:
                    764: optobj(p)
                    765: Obj *p;
                    766: {
                    767:        Obj t;
                    768:        int n;
                    769:        DCP dc;
                    770:
                    771:        if ( t = *p )
                    772:                switch ( OID(t) ) {
                    773:                        case O_N:
                    774:                                if ( (NID(t)==N_Q) && INT(t) && (PL(NM((Q)t))==1) ) {
                    775:                                        n = QTOS((Q)t);
                    776:                                        if ( !szinit )
                    777:                                                sz_init();
                    778:                                        if ( n < 1000 )
                    779:                                                *p = (Obj)(SGN((Q)t)>0?&oPSZ[n]:&oMSZ[n]);
                    780:                                }
                    781:                                break;
                    782:                        case O_P:
                    783:                                for ( dc = DC((P)t); dc; dc = NEXT(dc) ) {
                    784:                                        optobj(&DEG(dc)); optobj(&COEF(dc));
                    785:                                }
                    786:                                break;
                    787:                        case O_R:
                    788:                                optobj(&NM((R)t)); optobj(&DN((R)t)); break;
                    789:                        default:
                    790:                                break;
                    791:                }
                    792: }
                    793: #endif

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