[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.32

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

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