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

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

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