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

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

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