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

1.5     ! noro        1: /* $OpenXM: OpenXM_contrib2/asir2000/builtin/miscf.c,v 1.4 2000/03/01 02:29:17 noro Exp $ */
1.1       noro        2: #include "ca.h"
                      3: #include "parse.h"
                      4: #if INET && !defined(VISUAL)
                      5: #include <X11/Xlib.h>
                      6: #include <X11/cursorfont.h>
                      7: #endif
                      8:
                      9: void Pquit(), Pdebug(), Pnmono(), Pnez(), Popt(), Pshell(), Pheap();
                     10: void Perror(), Perror3(), Pversion(), Pflist(), Pdelete_history(), Ppause(), Pxpause();
                     11: void Pr2g(), Pread_cmo(), Pwrite_cmo();
                     12: void Pgc(),Pbatch(),Psend_progress();
                     13: void Pnull_command();
                     14: void Pgetenv();
1.2       noro       15: void Plib_ox_push_cmo(),Plib_ox_pop_cmo(),Plib_ox_push_cmd();
                     16: void Plib_ox_execute_string();
1.1       noro       17:
                     18: void delete_history(int,int);
                     19:
                     20: struct ftab misc_tab[] = {
                     21:        {"null_command",Pnull_command,-99999},
                     22:        {"getenv",Pgetenv,1},
                     23:        {"end",Pquit,0},
                     24:        {"quit",Pquit,0},
                     25:        {"debug",Pdebug,0},
                     26:        {"shell",Pshell,-2},
                     27:        {"heap",Pheap,-1},
                     28:        {"version",Pversion,0},
                     29:        {"nmono",Pnmono,1},
                     30:        {"error",Perror,1},
                     31:        {"error3",Perror3,3},
                     32:        {"nez",Pnez,1},
                     33:        {"flist",Pflist,0},
                     34:        {"delete_history",Pdelete_history,-2},
                     35:        {"pause",Ppause,0},
                     36:        {"gc",Pgc,0},
                     37:        {"batch",Pbatch,2},
                     38:        {"send_progress",Psend_progress,-2},
1.3       noro       39: #if INET && !defined(VISUAL) && DO_PLOT
1.1       noro       40:        {"xpause",Pxpause,0},
                     41: #endif
                     42: #if 0
                     43:        {"opt",Popt,1},
                     44: #endif
1.4       noro       45: #if !defined(VISUAL)
1.2       noro       46: /* test functions for library mode ox operations */
                     47:        {"lib_ox_push_cmo",Plib_ox_push_cmo,1},
                     48:        {"lib_ox_pop_cmo",Plib_ox_pop_cmo,0},
                     49:        {"lib_ox_push_cmd",Plib_ox_push_cmd,1},
                     50:        {"lib_ox_execute_string",Plib_ox_execute_string,1},
1.4       noro       51: #endif
1.1       noro       52:        {0,0,0},
                     53: };
1.2       noro       54:
                     55: extern int little_endian;
                     56:
                     57: int lib_ox_initialized;
                     58:
1.4       noro       59: #if !defined(VISUAL)
1.2       noro       60: void Plib_ox_push_cmo(arg,rp)
                     61: NODE arg;
                     62: Q *rp;
                     63: {
                     64:        void *cmo;
                     65:
                     66:        if ( !lib_ox_initialized ) asir_ox_io_init(little_endian);
                     67:        risa_to_cmo(ARG0(arg),&cmo);
                     68:        asir_ox_push_cmo(cmo);
                     69:        *rp = ONE;
                     70: }
                     71:
                     72: void Plib_ox_pop_cmo(rp)
                     73: Obj *rp;
                     74: {
                     75:        void *buf;
                     76:        int ret,len;
                     77:
                     78:        if ( !lib_ox_initialized ) asir_ox_io_init(little_endian);
                     79:        len = asir_ox_peek_cmo_size();
                     80:        buf = (void *)MALLOC_ATOMIC(len);
                     81:        ret = asir_ox_pop_cmo(buf,len);
                     82:        if ( ret < 0 )
                     83:                error("lib_ox_pop_cmo : buffer too small (cannot happen!)");
                     84:        cmo_to_risa(buf,rp);
                     85: }
                     86:
                     87: void Plib_ox_push_cmd(arg,rp)
                     88: NODE arg;
                     89: Q *rp;
                     90: {
                     91:        if ( !lib_ox_initialized ) asir_ox_io_init(little_endian);
                     92:        asir_ox_push_cmd((unsigned int)QTOS((Q)ARG0(arg)));
                     93:        *rp = ONE;
                     94: }
                     95:
                     96: void Plib_ox_execute_string(arg,rp)
                     97: NODE arg;
                     98: Q *rp;
                     99: {
                    100:        if ( !lib_ox_initialized ) asir_ox_io_init(little_endian);
                    101:        asir_ox_execute_string(BDY((STRING)ARG0(arg)));
                    102:        *rp = ONE;
                    103: }
1.4       noro      104: #endif
1.1       noro      105:
                    106: void Pgetenv(arg,rp)
                    107: NODE arg;
                    108: STRING *rp;
                    109: {
                    110:        char *e,*f;
                    111:        int len;
                    112:
                    113:        e = (char *)getenv(BDY((STRING)ARG0(arg)));
                    114:        if ( e ) {
                    115:                len = strlen(e);
                    116:                f = (char *)MALLOC_ATOMIC(len+1);
                    117:                strcpy(f,e);
                    118:                MKSTR(*rp,f);
                    119:        } else
                    120:                *rp = 0;
                    121: }
                    122:
                    123: void Pnull_command(arg,rp)
                    124: NODE arg;
                    125: Q *rp;
                    126: {
                    127:        *rp = 0;
                    128: }
                    129:
                    130: void Pquit(rp)
                    131: pointer *rp;
                    132: {
                    133:        if ( !NEXT(asir_infile) )
                    134:                asir_terminate(2);
                    135:        else {
                    136:                closecurrentinput();
1.5     ! noro      137:                if ( !asir_infile->fp && strcmp(asir_infile->name,"string") )
1.1       noro      138:                        asir_terminate(2);
                    139:        }
                    140:        *rp = 0;
                    141: }
                    142:
                    143: void Pdebug(rp)
                    144: pointer *rp;
                    145: {
                    146:        debug(0); *rp = 0;
                    147: }
                    148:
                    149: void Pshell(arg,rp)
                    150: NODE arg;
                    151: Q *rp;
                    152: {
                    153:        char *com = 0;
                    154:        char *pstr = 0;
                    155:        int status;
                    156:
                    157:        if ( arg ) {
                    158:                asir_assert(ARG0(arg),O_STR,"shell");
                    159:                com = BDY((STRING)ARG0(arg));
                    160:                if ( NEXT(arg) )
                    161:                        pstr = BDY((STRING)ARG1(arg));
                    162:        }
                    163:        status = system(com);
                    164:        STOQ(status,*rp);
                    165: }
                    166:
                    167: void Pnmono(arg,rp)
                    168: NODE arg;
                    169: Q *rp;
                    170: {
                    171:        Obj obj;
                    172:        int n;
                    173:
                    174:        obj = (Obj)ARG0(arg);
                    175:        if ( !obj || OID(obj) > O_R )
                    176:                *rp = 0;
                    177:        else
                    178:                switch (OID(obj)) {
                    179:                        case O_N: case O_P:
                    180:                                n = nmonop((P)obj); STOQ(n,*rp); break;
                    181:                        case O_R:
                    182:                                n = nmonop(NM((R)obj)) + nmonop(DN((R)obj));
                    183:                                STOQ(n,*rp); break;
                    184:                }
                    185: }
                    186:
                    187: void Pheap(arg,rp)
                    188: NODE arg;
                    189: Q *rp;
                    190: {
                    191:        int h0,h;
                    192:        void GC_expand_hp(int);
                    193:
                    194:        h0 = get_heapsize();
                    195:        if ( arg ) {
                    196:                h = QTOS((Q)ARG0(arg));
                    197:                if ( h > h0 )
                    198:                        GC_expand_hp(h-h0);
                    199:        }
                    200:        h = get_heapsize();
                    201:        STOQ(h,*rp);
                    202: }
                    203:
                    204: unsigned int get_asir_version();
                    205:
                    206: void Pversion(rp)
                    207: Q *rp;
                    208: {
                    209:        unsigned int version;
                    210:
                    211:        version = get_asir_version();
                    212:        STOQ(version,*rp);
                    213: }
                    214:
                    215: extern int nez;
                    216:
                    217: void Pnez(arg,rp)
                    218: NODE arg;
                    219: pointer *rp;
                    220: {
                    221:        nez = ARG0(arg) ? 1 : 0; *rp = 0;
                    222: }
                    223:
                    224: void Perror(arg,rp)
                    225: NODE arg;
                    226: Q *rp;
                    227: {
                    228:        char *s;
                    229:
                    230:        if ( !arg || !ARG0(arg) || (OID((Obj)ARG0(arg)) != O_STR) )
                    231:                s = "";
                    232:        else
                    233:                s = BDY((STRING)ARG0(arg));
                    234:        error(s);
                    235:        *rp = 0;
                    236: }
                    237:
                    238: void Perror3(arg,rp)
                    239: NODE arg;
                    240: Q *rp;
                    241: {
                    242:        char s[BUFSIZ];
                    243:        int code;
                    244:        char *reason,*action;
                    245:
                    246:        asir_assert(ARG0(arg),O_N,"error3");
                    247:        asir_assert(ARG1(arg),O_STR,"error3");
                    248:        asir_assert(ARG2(arg),O_STR,"error3");
                    249:        code = QTOS((Q)ARG0(arg));
                    250:        reason = BDY((STRING)ARG1(arg));
                    251:        action = BDY((STRING)ARG2(arg));
1.3       noro      252: #if defined(VISUAL)
1.1       noro      253:        set_error(code,reason,action);
1.3       noro      254: #endif
1.1       noro      255:        error("");
                    256:        *rp = 0;
                    257: }
                    258:
                    259: void Pflist(rp)
                    260: LIST *rp;
                    261: {
                    262:        char *n;
                    263:        STRING name;
                    264:        NODE t,r,r0;
                    265:        LIST l;
                    266:
                    267:        for ( t = usrf, r0 = 0; t; t = NEXT(t) )
                    268:                if ( ((FUNC)BDY(t))->id != A_UNDEF ) {
                    269:                        n = NAME((FUNC)BDY(t)); MKSTR(name,n);
                    270:                        MKNODE(r,name,r0); r0 = r;
                    271:                }
                    272:        for ( t = ubinf; t; t = NEXT(t) )
                    273:                if ( ((FUNC)BDY(t))->id != A_UNDEF ) {
                    274:                        n = NAME((FUNC)BDY(t)); MKSTR(name,n);
                    275:                        MKNODE(r,name,r0); r0 = r;
                    276:                }
                    277:        for ( t = sysf; t; t = NEXT(t) )
                    278:                if ( ((FUNC)BDY(t))->id != A_UNDEF ) {
                    279:                        n = NAME((FUNC)BDY(t)); MKSTR(name,n);
                    280:                        MKNODE(r,name,r0); r0 = r;
                    281:                }
                    282:        MKLIST(l,r0); *rp = l;
                    283: }
                    284:
                    285: void Pdelete_history(arg,rp)
                    286: NODE arg;
                    287: Q *rp;
                    288: {
                    289:        switch ( argc(arg) ) {
                    290:                case 0: default:
                    291:                        delete_history(0,(int)APVS->n);
                    292:                        break;
                    293:                case 1:
                    294:                        delete_history(QTOS((Q)ARG0(arg)),1);
                    295:                        break;
                    296:        }
                    297:        *rp = 0;
                    298: }
                    299:
                    300: void delete_history(start,n)
                    301: int start,n;
                    302: {
                    303:        int i,max;
                    304:
                    305:        max = APVS->n;
                    306:        if ( start < 0 || start >= max )
                    307:                return;
                    308:        if ( start + n > max )
                    309:                n = max - start;
                    310:        for ( i = 0; i < n; i++ )
                    311:                APVS->va[start+i].priv = 0;
                    312: }
                    313:
                    314: void Ppause(rp)
                    315: LIST *rp;
                    316: {
                    317:        char buf[BUFSIZ];
                    318:
                    319:        fgets(buf,BUFSIZ,stdin);
                    320:        *rp = 0;
                    321: }
                    322:
                    323: void Pgc(rp)
                    324: LIST *rp;
                    325: {
                    326:        GC_gcollect();
                    327:        *rp = 0;
                    328: }
                    329:
                    330: int exec_file(char *,char *);
                    331:
                    332: void Pbatch(arg,rp)
                    333: NODE arg;
                    334: Q *rp;
                    335: {
                    336:        int ret;
                    337:
                    338:        ret = exec_file(BDY((STRING)ARG0(arg)),BDY((STRING)ARG1(arg)));
                    339:        STOQ(ret,*rp);
                    340: }
                    341:
1.3       noro      342: #if INET && !defined(VISUAL) && DO_PLOT
1.1       noro      343: void Pxpause(rp)
                    344: Q *rp;
                    345: {
                    346:        if ( !init_display() )
                    347:                *rp = 0;
                    348:        else {
                    349:                grab_pointer(); *rp = ONE;
                    350:        }
                    351: }
                    352:
                    353: static Display *display;
                    354: static Window rootwin;
                    355:
                    356: init_display()
                    357: {
                    358:        char *dname;
                    359:        unsigned int tmp;
                    360:        static int initialized;
                    361:        int argc;
                    362:        char *argv[1];
                    363:
                    364:        if ( initialized )
                    365:                return 1;
                    366:        else
                    367:                initialized = 1;
                    368:        dname = (char *)getenv("DISPLAY");
                    369:
                    370:        display = XOpenDisplay(dname);
                    371:        if ( !display ) {
                    372:                fprintf(stderr,"Can't open display\n");
                    373:                return 0;
                    374:        }
                    375:        rootwin = RootWindow(display,DefaultScreen(display));
                    376: }
                    377:
                    378: grab_pointer()
                    379: {
                    380:        XEvent ev;
                    381:        static Cursor cursor;
                    382:
                    383:        if ( !cursor )
                    384:                cursor = XCreateFontCursor(display,XC_leftbutton);
                    385:        XGrabPointer(display,rootwin,True,ButtonPressMask,GrabModeAsync,GrabModeAsync,None,cursor,CurrentTime);
                    386:        while ( 1 ) {
                    387:                XNextEvent(display,&ev);
                    388:                if ( ev.xany.type == ButtonPress )
                    389:                        break;
                    390:        }
                    391:        XUngrabPointer(display,CurrentTime);
                    392:        XSync(display,False);
                    393:        return;
                    394: }
                    395: #endif
                    396:
                    397: void Psend_progress(NODE arg,Q *rp)
                    398: {
                    399: #if defined(VISUAL)
                    400:        short per;
                    401:        char *msg;
                    402:
                    403:        per = (short)QTOS((Q)BDY(arg)); arg = NEXT(arg);
                    404:        if ( arg )
                    405:                msg = BDY((STRING)BDY(arg));
                    406:        else
                    407:                msg = "";
                    408:        send_progress(per,msg);
                    409: #endif
                    410:        *rp = 0;
                    411: }
                    412:
                    413: #if 0
                    414: static int optimize;
                    415: static struct oN oPSN[1000];
                    416: static struct oQ oPSZ[1000],oMSZ[1000];
                    417: static szinit = 0;
                    418:
                    419: void Popt(arg,rp)
                    420: NODE arg;
                    421: pointer *rp;
                    422: {
                    423:        optimize = ARG0(arg) ? 1 : 0; *rp = 0;
                    424: }
                    425:
                    426:
                    427: void sz_init() {
                    428:        int i;
                    429:        Q t;
                    430:
                    431:        for ( i = 1; i < 1000; i++ ) {
                    432:                oPSN[i].p = 1; oPSN[i].b[0] = i;
                    433:                t = &oPSZ[i];
                    434:                OID(t) = O_N; NID(t) = N_Q; SGN(t) = 1; NM(t) = &oPSN[i]; DN(t) = 0;
                    435:                t = &oMSZ[i];
                    436:                OID(t) = O_N; NID(t) = N_Q; SGN(t) = -1; NM(t) = &oPSN[i]; DN(t) = 0;
                    437:        }
                    438:        szinit = 1;
                    439: }
                    440:
                    441: optobj(p)
                    442: Obj *p;
                    443: {
                    444:        Obj t;
                    445:        int n;
                    446:        DCP dc;
                    447:
                    448:        if ( t = *p )
                    449:                switch ( OID(t) ) {
                    450:                        case O_N:
                    451:                                if ( (NID(t)==N_Q) && INT(t) && (PL(NM((Q)t))==1) ) {
                    452:                                        n = QTOS((Q)t);
                    453:                                        if ( !szinit )
                    454:                                                sz_init();
                    455:                                        if ( n < 1000 )
                    456:                                                *p = (Obj)(SGN((Q)t)>0?&oPSZ[n]:&oMSZ[n]);
                    457:                                }
                    458:                                break;
                    459:                        case O_P:
                    460:                                for ( dc = DC((P)t); dc; dc = NEXT(dc) ) {
                    461:                                        optobj(&DEG(dc)); optobj(&COEF(dc));
                    462:                                }
                    463:                                break;
                    464:                        case O_R:
                    465:                                optobj(&NM((R)t)); optobj(&DN((R)t)); break;
                    466:                        default:
                    467:                                break;
                    468:                }
                    469: }
                    470: #endif

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