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

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

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