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

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

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