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

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

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