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

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.10    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/builtin/miscf.c,v 1.9 2000/11/14 08:38:38 noro Exp $
1.7       noro       49: */
1.1       noro       50: #include "ca.h"
                     51: #include "parse.h"
1.10    ! noro       52: #if !defined(VISUAL)
1.1       noro       53: #include <X11/Xlib.h>
                     54: #include <X11/cursorfont.h>
                     55: #endif
                     56:
                     57: void Pquit(), Pdebug(), Pnmono(), Pnez(), Popt(), Pshell(), Pheap();
                     58: void Perror(), Perror3(), Pversion(), Pflist(), Pdelete_history(), Ppause(), Pxpause();
                     59: void Pr2g(), Pread_cmo(), Pwrite_cmo();
                     60: void Pgc(),Pbatch(),Psend_progress();
                     61: void Pnull_command();
                     62: void Pgetenv();
1.9       noro       63: void Pget_addr(),Phex_dump();
                     64: void Ppeek(),Ppoke();
1.1       noro       65:
                     66: void delete_history(int,int);
                     67:
                     68: struct ftab misc_tab[] = {
                     69:        {"null_command",Pnull_command,-99999},
                     70:        {"getenv",Pgetenv,1},
                     71:        {"end",Pquit,0},
                     72:        {"quit",Pquit,0},
                     73:        {"debug",Pdebug,0},
                     74:        {"shell",Pshell,-2},
                     75:        {"heap",Pheap,-1},
                     76:        {"version",Pversion,0},
                     77:        {"nmono",Pnmono,1},
                     78:        {"error",Perror,1},
                     79:        {"error3",Perror3,3},
                     80:        {"nez",Pnez,1},
                     81:        {"flist",Pflist,0},
                     82:        {"delete_history",Pdelete_history,-2},
                     83:        {"pause",Ppause,0},
                     84:        {"gc",Pgc,0},
                     85:        {"batch",Pbatch,2},
                     86:        {"send_progress",Psend_progress,-2},
1.9       noro       87:        {"get_addr",Pget_addr,1},
                     88:        {"hex_dump",Phex_dump,2},
                     89:        {"peek",Ppeek,1},
                     90:        {"poke",Ppoke,2},
1.10    ! noro       91: #if !defined(VISUAL) && DO_PLOT
1.1       noro       92:        {"xpause",Pxpause,0},
                     93: #endif
                     94: #if 0
                     95:        {"opt",Popt,1},
                     96: #endif
                     97:        {0,0,0},
                     98: };
                     99:
                    100: void Pgetenv(arg,rp)
                    101: NODE arg;
                    102: STRING *rp;
                    103: {
                    104:        char *e,*f;
                    105:        int len;
                    106:
                    107:        e = (char *)getenv(BDY((STRING)ARG0(arg)));
                    108:        if ( e ) {
                    109:                len = strlen(e);
                    110:                f = (char *)MALLOC_ATOMIC(len+1);
                    111:                strcpy(f,e);
                    112:                MKSTR(*rp,f);
                    113:        } else
                    114:                *rp = 0;
                    115: }
                    116:
                    117: void Pnull_command(arg,rp)
                    118: NODE arg;
                    119: Q *rp;
                    120: {
                    121:        *rp = 0;
                    122: }
                    123:
                    124: void Pquit(rp)
                    125: pointer *rp;
                    126: {
                    127:        if ( !NEXT(asir_infile) )
                    128:                asir_terminate(2);
                    129:        else {
                    130:                closecurrentinput();
1.5       noro      131:                if ( !asir_infile->fp && strcmp(asir_infile->name,"string") )
1.1       noro      132:                        asir_terminate(2);
                    133:        }
                    134:        *rp = 0;
                    135: }
                    136:
                    137: void Pdebug(rp)
                    138: pointer *rp;
                    139: {
                    140:        debug(0); *rp = 0;
                    141: }
                    142:
                    143: void Pshell(arg,rp)
                    144: NODE arg;
                    145: Q *rp;
                    146: {
                    147:        char *com = 0;
                    148:        char *pstr = 0;
                    149:        int status;
                    150:
                    151:        if ( arg ) {
                    152:                asir_assert(ARG0(arg),O_STR,"shell");
                    153:                com = BDY((STRING)ARG0(arg));
                    154:                if ( NEXT(arg) )
                    155:                        pstr = BDY((STRING)ARG1(arg));
                    156:        }
                    157:        status = system(com);
                    158:        STOQ(status,*rp);
                    159: }
                    160:
                    161: void Pnmono(arg,rp)
                    162: NODE arg;
                    163: Q *rp;
                    164: {
                    165:        Obj obj;
                    166:        int n;
                    167:
                    168:        obj = (Obj)ARG0(arg);
                    169:        if ( !obj || OID(obj) > O_R )
                    170:                *rp = 0;
                    171:        else
                    172:                switch (OID(obj)) {
                    173:                        case O_N: case O_P:
                    174:                                n = nmonop((P)obj); STOQ(n,*rp); break;
                    175:                        case O_R:
                    176:                                n = nmonop(NM((R)obj)) + nmonop(DN((R)obj));
                    177:                                STOQ(n,*rp); break;
                    178:                }
                    179: }
                    180:
                    181: void Pheap(arg,rp)
                    182: NODE arg;
                    183: Q *rp;
                    184: {
                    185:        int h0,h;
                    186:        void GC_expand_hp(int);
                    187:
                    188:        h0 = get_heapsize();
                    189:        if ( arg ) {
                    190:                h = QTOS((Q)ARG0(arg));
                    191:                if ( h > h0 )
                    192:                        GC_expand_hp(h-h0);
                    193:        }
                    194:        h = get_heapsize();
                    195:        STOQ(h,*rp);
                    196: }
                    197:
                    198: unsigned int get_asir_version();
                    199:
                    200: void Pversion(rp)
                    201: Q *rp;
                    202: {
                    203:        unsigned int version;
                    204:
                    205:        version = get_asir_version();
                    206:        STOQ(version,*rp);
                    207: }
                    208:
                    209: extern int nez;
                    210:
                    211: void Pnez(arg,rp)
                    212: NODE arg;
                    213: pointer *rp;
                    214: {
                    215:        nez = ARG0(arg) ? 1 : 0; *rp = 0;
                    216: }
                    217:
                    218: void Perror(arg,rp)
                    219: NODE arg;
                    220: Q *rp;
                    221: {
                    222:        char *s;
                    223:
                    224:        if ( !arg || !ARG0(arg) || (OID((Obj)ARG0(arg)) != O_STR) )
                    225:                s = "";
                    226:        else
                    227:                s = BDY((STRING)ARG0(arg));
                    228:        error(s);
                    229:        *rp = 0;
                    230: }
                    231:
                    232: void Perror3(arg,rp)
                    233: NODE arg;
                    234: Q *rp;
                    235: {
                    236:        char s[BUFSIZ];
                    237:        int code;
                    238:        char *reason,*action;
                    239:
                    240:        asir_assert(ARG0(arg),O_N,"error3");
                    241:        asir_assert(ARG1(arg),O_STR,"error3");
                    242:        asir_assert(ARG2(arg),O_STR,"error3");
                    243:        code = QTOS((Q)ARG0(arg));
                    244:        reason = BDY((STRING)ARG1(arg));
                    245:        action = BDY((STRING)ARG2(arg));
1.3       noro      246: #if defined(VISUAL)
1.1       noro      247:        set_error(code,reason,action);
1.3       noro      248: #endif
1.1       noro      249:        error("");
                    250:        *rp = 0;
                    251: }
                    252:
                    253: void Pflist(rp)
                    254: LIST *rp;
                    255: {
                    256:        char *n;
                    257:        STRING name;
                    258:        NODE t,r,r0;
                    259:        LIST l;
                    260:
                    261:        for ( t = usrf, r0 = 0; t; t = NEXT(t) )
                    262:                if ( ((FUNC)BDY(t))->id != A_UNDEF ) {
                    263:                        n = NAME((FUNC)BDY(t)); MKSTR(name,n);
                    264:                        MKNODE(r,name,r0); r0 = r;
                    265:                }
                    266:        for ( t = ubinf; t; t = NEXT(t) )
                    267:                if ( ((FUNC)BDY(t))->id != A_UNDEF ) {
                    268:                        n = NAME((FUNC)BDY(t)); MKSTR(name,n);
                    269:                        MKNODE(r,name,r0); r0 = r;
                    270:                }
                    271:        for ( t = sysf; t; t = NEXT(t) )
                    272:                if ( ((FUNC)BDY(t))->id != A_UNDEF ) {
                    273:                        n = NAME((FUNC)BDY(t)); MKSTR(name,n);
                    274:                        MKNODE(r,name,r0); r0 = r;
                    275:                }
                    276:        MKLIST(l,r0); *rp = l;
                    277: }
                    278:
                    279: void Pdelete_history(arg,rp)
                    280: NODE arg;
                    281: Q *rp;
                    282: {
                    283:        switch ( argc(arg) ) {
                    284:                case 0: default:
                    285:                        delete_history(0,(int)APVS->n);
                    286:                        break;
                    287:                case 1:
                    288:                        delete_history(QTOS((Q)ARG0(arg)),1);
                    289:                        break;
                    290:        }
                    291:        *rp = 0;
                    292: }
                    293:
                    294: void delete_history(start,n)
                    295: int start,n;
                    296: {
                    297:        int i,max;
                    298:
                    299:        max = APVS->n;
                    300:        if ( start < 0 || start >= max )
                    301:                return;
                    302:        if ( start + n > max )
                    303:                n = max - start;
                    304:        for ( i = 0; i < n; i++ )
                    305:                APVS->va[start+i].priv = 0;
                    306: }
                    307:
                    308: void Ppause(rp)
                    309: LIST *rp;
                    310: {
                    311:        char buf[BUFSIZ];
                    312:
                    313:        fgets(buf,BUFSIZ,stdin);
                    314:        *rp = 0;
                    315: }
                    316:
                    317: void Pgc(rp)
                    318: LIST *rp;
                    319: {
                    320:        GC_gcollect();
                    321:        *rp = 0;
                    322: }
                    323:
                    324: int exec_file(char *,char *);
                    325:
                    326: void Pbatch(arg,rp)
                    327: NODE arg;
                    328: Q *rp;
                    329: {
                    330:        int ret;
                    331:
                    332:        ret = exec_file(BDY((STRING)ARG0(arg)),BDY((STRING)ARG1(arg)));
                    333:        STOQ(ret,*rp);
                    334: }
                    335:
1.10    ! noro      336: #if !defined(VISUAL) && DO_PLOT
1.1       noro      337: void Pxpause(rp)
                    338: Q *rp;
                    339: {
                    340:        if ( !init_display() )
                    341:                *rp = 0;
                    342:        else {
                    343:                grab_pointer(); *rp = ONE;
                    344:        }
                    345: }
                    346:
                    347: static Display *display;
                    348: static Window rootwin;
                    349:
                    350: init_display()
                    351: {
                    352:        char *dname;
                    353:        unsigned int tmp;
                    354:        static int initialized;
                    355:        int argc;
                    356:        char *argv[1];
                    357:
                    358:        if ( initialized )
                    359:                return 1;
                    360:        else
                    361:                initialized = 1;
                    362:        dname = (char *)getenv("DISPLAY");
                    363:
                    364:        display = XOpenDisplay(dname);
                    365:        if ( !display ) {
                    366:                fprintf(stderr,"Can't open display\n");
                    367:                return 0;
                    368:        }
                    369:        rootwin = RootWindow(display,DefaultScreen(display));
                    370: }
                    371:
                    372: grab_pointer()
                    373: {
                    374:        XEvent ev;
                    375:        static Cursor cursor;
                    376:
                    377:        if ( !cursor )
                    378:                cursor = XCreateFontCursor(display,XC_leftbutton);
                    379:        XGrabPointer(display,rootwin,True,ButtonPressMask,GrabModeAsync,GrabModeAsync,None,cursor,CurrentTime);
                    380:        while ( 1 ) {
                    381:                XNextEvent(display,&ev);
                    382:                if ( ev.xany.type == ButtonPress )
                    383:                        break;
                    384:        }
                    385:        XUngrabPointer(display,CurrentTime);
                    386:        XSync(display,False);
                    387:        return;
                    388: }
                    389: #endif
                    390:
                    391: void Psend_progress(NODE arg,Q *rp)
                    392: {
                    393: #if defined(VISUAL)
                    394:        short per;
                    395:        char *msg;
                    396:
                    397:        per = (short)QTOS((Q)BDY(arg)); arg = NEXT(arg);
                    398:        if ( arg )
                    399:                msg = BDY((STRING)BDY(arg));
                    400:        else
                    401:                msg = "";
                    402:        send_progress(per,msg);
                    403: #endif
1.9       noro      404:        *rp = 0;
                    405: }
                    406:
                    407: void Pget_addr(arg,rp)
                    408: NODE arg;
                    409: Q *rp;
                    410: {
                    411:        pointer obj;
                    412:        unsigned int u,l;
                    413:        N n;
                    414:
                    415:        obj = ARG0(arg);
                    416:        if ( sizeof(pointer) == sizeof(unsigned int) ) {
                    417:                UTOQ((unsigned int)obj,*rp);
                    418:        } else {
                    419:                /* a pointer must fit in long */
                    420:                u = ((unsigned long)obj)>>32;
                    421:                l = ((unsigned long)obj)&(unsigned long)0xffffffff;
                    422:                if ( u ) {
                    423:                        n = NALLOC(2); PL(n) = 2; BD(n)[0] = l; BD(n)[1] = u;
                    424:                        NTOQ(n,1,*rp);
                    425:                } else {
                    426:                        UTOQ(l,*rp);
                    427:                }
                    428:        }
                    429: }
                    430:
                    431: unsigned char *qtoaddr(q)
                    432: Q q;
                    433: {
                    434:        unsigned char *addr;
                    435:        N n;
                    436:
                    437:        if ( !q )
                    438:                return 0;
                    439:        n = NM(q);
                    440:        if ( (sizeof(pointer) == sizeof(unsigned int)) || (PL(n) == 1) )
                    441:                addr = (char *)BD(n)[0];
                    442:        else {
                    443:                /* a pointer must fit in long */
                    444:                addr = (char *)((((unsigned long)BD(n)[1])<<32)
                    445:                        | ((unsigned long)BD(n)[0]));
                    446:        }
                    447:        return addr;
                    448: }
                    449:
                    450: void Phex_dump(arg,rp)
                    451: NODE arg;
                    452: Q *rp;
                    453: {
                    454:        unsigned char *start;
                    455:        int len,i;
                    456:
                    457:        *rp = 0;
                    458:        start = qtoaddr((Q)ARG0(arg));
                    459:        len = QTOS((Q)ARG1(arg));
                    460:        for ( i = 0; i < len; i++ ) {
                    461:                if ( !(i%16) )
                    462:                        fprintf(asir_out,"%08x: ",start+i);
                    463:                fprintf(asir_out,"%02x",start[i]);
                    464:                if ( !((i+1)%16) )
                    465:                        fprintf(asir_out,"\n");
                    466:                else if ( !((i+1)%4) )
                    467:                        fprintf(asir_out," ");
                    468:        }
                    469:        if ( i%16 )
                    470:                fprintf(asir_out,"\n");
                    471: }
                    472:
                    473: void Ppeek(arg,rp)
                    474: NODE arg;
                    475: Q *rp;
                    476: {
                    477:        unsigned int b;
                    478:        unsigned char *a;
                    479:
                    480:        a = qtoaddr((Q)ARG0(arg));
                    481:        b = (unsigned int) (*a);
                    482:        UTOQ(b,*rp);
                    483: }
                    484:
                    485: void Ppoke(arg,rp)
                    486: NODE arg;
                    487: Q *rp;
                    488: {
                    489:        unsigned char *addr;
                    490:
                    491:        addr = qtoaddr((Q)ARG0(arg));
                    492:        *addr = (unsigned char)QTOS((Q)ARG1(arg));
1.1       noro      493:        *rp = 0;
                    494: }
                    495:
                    496: #if 0
                    497: static int optimize;
                    498: static struct oN oPSN[1000];
                    499: static struct oQ oPSZ[1000],oMSZ[1000];
                    500: static szinit = 0;
                    501:
                    502: void Popt(arg,rp)
                    503: NODE arg;
                    504: pointer *rp;
                    505: {
                    506:        optimize = ARG0(arg) ? 1 : 0; *rp = 0;
                    507: }
                    508:
                    509:
                    510: void sz_init() {
                    511:        int i;
                    512:        Q t;
                    513:
                    514:        for ( i = 1; i < 1000; i++ ) {
                    515:                oPSN[i].p = 1; oPSN[i].b[0] = i;
                    516:                t = &oPSZ[i];
                    517:                OID(t) = O_N; NID(t) = N_Q; SGN(t) = 1; NM(t) = &oPSN[i]; DN(t) = 0;
                    518:                t = &oMSZ[i];
                    519:                OID(t) = O_N; NID(t) = N_Q; SGN(t) = -1; NM(t) = &oPSN[i]; DN(t) = 0;
                    520:        }
                    521:        szinit = 1;
                    522: }
                    523:
                    524: optobj(p)
                    525: Obj *p;
                    526: {
                    527:        Obj t;
                    528:        int n;
                    529:        DCP dc;
                    530:
                    531:        if ( t = *p )
                    532:                switch ( OID(t) ) {
                    533:                        case O_N:
                    534:                                if ( (NID(t)==N_Q) && INT(t) && (PL(NM((Q)t))==1) ) {
                    535:                                        n = QTOS((Q)t);
                    536:                                        if ( !szinit )
                    537:                                                sz_init();
                    538:                                        if ( n < 1000 )
                    539:                                                *p = (Obj)(SGN((Q)t)>0?&oPSZ[n]:&oMSZ[n]);
                    540:                                }
                    541:                                break;
                    542:                        case O_P:
                    543:                                for ( dc = DC((P)t); dc; dc = NEXT(dc) ) {
                    544:                                        optobj(&DEG(dc)); optobj(&COEF(dc));
                    545:                                }
                    546:                                break;
                    547:                        case O_R:
                    548:                                optobj(&NM((R)t)); optobj(&DN((R)t)); break;
                    549:                        default:
                    550:                                break;
                    551:                }
                    552: }
                    553: #endif

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