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

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

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