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

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.37    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/builtin/miscf.c,v 1.36 2015/08/14 13:51:54 fujimoto 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);
        !           404:     n = mknode(2,q,str);
        !           405:     MKLIST(l,n);
        !           406:     *rp = (Obj)l;
        !           407:   }
1.21      ohara     408: }
                    409:
                    410: char *scopyright();
                    411:
                    412: void Pcopyright(rp)
                    413: STRING *rp;
                    414: {
1.37    ! noro      415:   MKSTR(*rp,scopyright());
1.1       noro      416: }
                    417:
                    418: extern int nez;
                    419:
                    420: void Pnez(arg,rp)
                    421: NODE arg;
                    422: pointer *rp;
                    423: {
1.37    ! noro      424:   nez = ARG0(arg) ? 1 : 0; *rp = 0;
1.1       noro      425: }
                    426:
                    427: void Perror(arg,rp)
                    428: NODE arg;
                    429: Q *rp;
                    430: {
1.37    ! noro      431:   char *s;
1.1       noro      432:
1.37    ! noro      433:   if ( !arg || !ARG0(arg) || (OID((Obj)ARG0(arg)) != O_STR) )
        !           434:     s = "";
        !           435:   else
        !           436:     s = BDY((STRING)ARG0(arg));
        !           437:   error(s);
        !           438:   *rp = 0;
1.20      noro      439: }
                    440:
                    441: void Ptoplevel(arg,rp)
                    442: NODE arg;
                    443: Q *rp;
                    444: {
1.37    ! noro      445:   char *s;
1.20      noro      446:
1.37    ! noro      447:   if ( !arg || !ARG0(arg) || (OID((Obj)ARG0(arg)) != O_STR) )
        !           448:     s = "";
        !           449:   else
        !           450:     s = BDY((STRING)ARG0(arg));
        !           451:   goto_toplevel(s);
        !           452:   *rp = 0;
1.1       noro      453: }
                    454:
                    455: void Perror3(arg,rp)
                    456: NODE arg;
                    457: Q *rp;
                    458: {
1.37    ! noro      459:   int code;
        !           460:   char *reason,*action;
1.1       noro      461:
1.37    ! noro      462:   asir_assert(ARG0(arg),O_N,"error3");
        !           463:   asir_assert(ARG1(arg),O_STR,"error3");
        !           464:   asir_assert(ARG2(arg),O_STR,"error3");
        !           465:   code = QTOS((Q)ARG0(arg));
        !           466:   reason = BDY((STRING)ARG1(arg));
        !           467:   action = BDY((STRING)ARG2(arg));
1.36      fujimoto  468: #if defined(VISUAL) || defined(__MINGW32__)
1.37    ! noro      469:   set_error(code,reason,action);
1.3       noro      470: #endif
1.37    ! noro      471:   error("");
        !           472:   *rp = 0;
1.1       noro      473: }
                    474:
1.18      noro      475: void Pflist(arg,rp)
                    476: NODE arg;
1.1       noro      477: LIST *rp;
                    478: {
1.37    ! noro      479:   char *n;
        !           480:   STRING name;
        !           481:   char *mname;
        !           482:   NODE t,r,r0,m;
        !           483:   LIST l;
        !           484:
        !           485:   if ( argc(arg) ) {
        !           486:     /* module name is specified */
        !           487:     asir_assert(ARG0(arg),O_STR,"flist");
        !           488:     mname = BDY((STRING)ARG0(arg));
        !           489:     r0 = 0;
        !           490:     for ( m = MODULE_LIST; m; m = NEXT(m) ) {
        !           491:       if ( !strcmp(mname,((MODULE)BDY(m))->name) ) {
        !           492:         t = ((MODULE)BDY(m))->usrf_list;
        !           493:         for ( r0 = 0; t; t = NEXT(t) )
        !           494:           if ( ((FUNC)BDY(t))->id != A_UNDEF ) {
        !           495:             n = NAME((FUNC)BDY(t)); MKSTR(name,n);
        !           496:             MKNODE(r,name,r0); r0 = r;
        !           497:         }
        !           498:       }
        !           499:     }
        !           500:   } else {
        !           501:     for ( t = usrf, r0 = 0; t; t = NEXT(t) )
        !           502:       if ( ((FUNC)BDY(t))->id != A_UNDEF ) {
        !           503:         n = NAME((FUNC)BDY(t)); MKSTR(name,n);
        !           504:         MKNODE(r,name,r0); r0 = r;
        !           505:       }
        !           506:     for ( t = ubinf; t; t = NEXT(t) )
        !           507:       if ( ((FUNC)BDY(t))->id != A_UNDEF ) {
        !           508:         n = NAME((FUNC)BDY(t)); MKSTR(name,n);
        !           509:         MKNODE(r,name,r0); r0 = r;
        !           510:       }
        !           511:     for ( t = sysf; t; t = NEXT(t) )
        !           512:       if ( ((FUNC)BDY(t))->id != A_UNDEF ) {
        !           513:         n = NAME((FUNC)BDY(t)); MKSTR(name,n);
        !           514:         MKNODE(r,name,r0); r0 = r;
        !           515:       }
        !           516:   }
        !           517:   MKLIST(l,r0); *rp = l;
1.1       noro      518: }
                    519:
                    520: void Pdelete_history(arg,rp)
                    521: NODE arg;
                    522: Q *rp;
                    523: {
1.37    ! noro      524:   switch ( argc(arg) ) {
        !           525:     case 0: default:
        !           526:       delete_history(0,(int)APVS->n);
        !           527:       break;
        !           528:     case 1:
        !           529:       delete_history(QTOS((Q)ARG0(arg)),1);
        !           530:       break;
        !           531:   }
        !           532:   *rp = 0;
1.1       noro      533: }
                    534:
                    535: void delete_history(start,n)
                    536: int start,n;
                    537: {
1.37    ! noro      538:   int i,max;
1.1       noro      539:
1.37    ! noro      540:   max = APVS->n;
        !           541:   if ( start < 0 || start >= max )
        !           542:     return;
        !           543:   if ( start + n > max )
        !           544:     n = max - start;
        !           545:   for ( i = 0; i < n; i++ )
        !           546:     APVS->va[start+i].priv = 0;
1.1       noro      547: }
                    548:
                    549: void Ppause(rp)
                    550: LIST *rp;
                    551: {
1.37    ! noro      552:   char buf[BUFSIZ];
1.1       noro      553:
1.37    ! noro      554:   fgets(buf,BUFSIZ,stdin);
        !           555:   *rp = 0;
1.1       noro      556: }
                    557:
                    558: void Pgc(rp)
                    559: LIST *rp;
                    560: {
1.37    ! noro      561:   GC_gcollect();
        !           562:   *rp = 0;
1.1       noro      563: }
                    564:
                    565: int exec_file(char *,char *);
                    566:
                    567: void Pbatch(arg,rp)
                    568: NODE arg;
                    569: Q *rp;
                    570: {
1.37    ! noro      571:   int ret;
1.1       noro      572:
1.37    ! noro      573:   ret = exec_file(BDY((STRING)ARG0(arg)),BDY((STRING)ARG1(arg)));
        !           574:   STOQ(ret,*rp);
1.1       noro      575: }
                    576:
1.35      fujimoto  577: #if !defined(VISUAL) && defined(DO_PLOT)
1.1       noro      578: void Pxpause(rp)
                    579: Q *rp;
                    580: {
1.37    ! noro      581:   if ( !init_display() )
        !           582:     *rp = 0;
        !           583:   else {
        !           584:     grab_pointer(); *rp = ONE;
        !           585:   }
1.1       noro      586: }
                    587:
                    588: static Display *display;
                    589: static Window rootwin;
                    590:
                    591: init_display()
                    592: {
1.37    ! noro      593:   char *dname;
        !           594:   unsigned int tmp;
        !           595:   static int initialized;
        !           596:   int argc;
        !           597:   char *argv[1];
        !           598:
        !           599:   if ( initialized )
        !           600:     return 1;
        !           601:   else
        !           602:     initialized = 1;
        !           603:   dname = (char *)getenv("DISPLAY");
        !           604:
        !           605:   display = XOpenDisplay(dname);
        !           606:   if ( !display ) {
        !           607:     fprintf(stderr,"Can't open display\n");
        !           608:     return 0;
        !           609:   }
        !           610:   rootwin = RootWindow(display,DefaultScreen(display));
1.1       noro      611: }
                    612:
1.32      noro      613: void grab_pointer()
1.1       noro      614: {
1.37    ! noro      615:   XEvent ev;
        !           616:   static Cursor cursor;
1.1       noro      617:
1.37    ! noro      618:   if ( !cursor )
        !           619:     cursor = XCreateFontCursor(display,XC_leftbutton);
        !           620:   XGrabPointer(display,rootwin,True,ButtonPressMask,GrabModeAsync,GrabModeAsync,None,cursor,CurrentTime);
        !           621:   while ( 1 ) {
        !           622:     XNextEvent(display,&ev);
        !           623:     if ( ev.xany.type == ButtonPress )
        !           624:       break;
        !           625:   }
        !           626:   XUngrabPointer(display,CurrentTime);
        !           627:   XSync(display,False);
        !           628:   return;
1.1       noro      629: }
                    630: #endif
                    631:
                    632: void Psend_progress(NODE arg,Q *rp)
                    633: {
1.35      fujimoto  634: #if defined(VISUAL)
1.37    ! noro      635:   short per;
        !           636:   char *msg;
1.1       noro      637:
1.37    ! noro      638:   per = (short)QTOS((Q)BDY(arg)); arg = NEXT(arg);
        !           639:   if ( arg )
        !           640:     msg = BDY((STRING)BDY(arg));
        !           641:   else
        !           642:     msg = "";
        !           643:   send_progress(per,msg);
1.1       noro      644: #endif
1.37    ! noro      645:   *rp = 0;
1.9       noro      646: }
                    647:
                    648: void Pget_addr(arg,rp)
                    649: NODE arg;
                    650: Q *rp;
                    651: {
1.37    ! noro      652:   pointer obj;
        !           653:   unsigned int u,l;
        !           654:   N n;
        !           655:
        !           656:   obj = ARG0(arg);
        !           657:   if ( sizeof(pointer) == sizeof(unsigned int) ) {
        !           658:     UTOQ((unsigned int)obj,*rp);
        !           659:   } else {
        !           660:     /* a pointer must fit in long */
        !           661:     u = ((unsigned long)obj)>>32;
        !           662:     l = ((unsigned long)obj)&(unsigned long)0xffffffff;
        !           663:     if ( u ) {
        !           664:       n = NALLOC(2); PL(n) = 2; BD(n)[0] = l; BD(n)[1] = u;
        !           665:       NTOQ(n,1,*rp);
        !           666:     } else {
        !           667:       UTOQ(l,*rp);
        !           668:     }
        !           669:   }
1.9       noro      670: }
                    671:
                    672: unsigned char *qtoaddr(q)
                    673: Q q;
                    674: {
1.37    ! noro      675:   unsigned char *addr;
        !           676:   N n;
1.9       noro      677:
1.37    ! noro      678:   if ( !q )
        !           679:     return 0;
        !           680:   n = NM(q);
        !           681:   if ( (sizeof(pointer) == sizeof(unsigned int)) || (PL(n) == 1) )
        !           682:     addr = (char *)BD(n)[0];
        !           683:   else {
        !           684:     /* a pointer must fit in long */
        !           685:     addr = (char *)((((unsigned long)BD(n)[1])<<32)
        !           686:       | ((unsigned long)BD(n)[0]));
        !           687:   }
        !           688:   return addr;
1.9       noro      689: }
                    690:
                    691: void Phex_dump(arg,rp)
                    692: NODE arg;
                    693: Q *rp;
                    694: {
1.37    ! noro      695:   unsigned char *start;
        !           696:   int len,i;
1.9       noro      697:
1.37    ! noro      698:   *rp = 0;
        !           699:   start = qtoaddr((Q)ARG0(arg));
        !           700:   len = QTOS((Q)ARG1(arg));
        !           701:   for ( i = 0; i < len; i++ ) {
        !           702:     if ( !(i%16) )
        !           703:       fprintf(asir_out,"%08x: ",start+i);
        !           704:     fprintf(asir_out,"%02x",start[i]);
        !           705:     if ( !((i+1)%16) )
        !           706:       fprintf(asir_out,"\n");
        !           707:     else if ( !((i+1)%4) )
        !           708:       fprintf(asir_out," ");
        !           709:   }
        !           710:   if ( i%16 )
        !           711:     fprintf(asir_out,"\n");
1.9       noro      712: }
                    713:
                    714: void Ppeek(arg,rp)
                    715: NODE arg;
                    716: Q *rp;
                    717: {
1.37    ! noro      718:   unsigned int b;
        !           719:   unsigned char *a;
1.9       noro      720:
1.37    ! noro      721:   a = qtoaddr((Q)ARG0(arg));
        !           722:   b = (unsigned int) (*a);
        !           723:   UTOQ(b,*rp);
1.9       noro      724: }
                    725:
                    726: void Ppoke(arg,rp)
                    727: NODE arg;
                    728: Q *rp;
                    729: {
1.37    ! noro      730:   unsigned char *addr;
1.9       noro      731:
1.37    ! noro      732:   addr = qtoaddr((Q)ARG0(arg));
        !           733:   *addr = (unsigned char)QTOS((Q)ARG1(arg));
        !           734:   *rp = 0;
1.1       noro      735: }
                    736:
                    737: #if 0
                    738: static int optimize;
                    739: static struct oN oPSN[1000];
                    740: static struct oQ oPSZ[1000],oMSZ[1000];
                    741: static szinit = 0;
                    742:
                    743: void Popt(arg,rp)
                    744: NODE arg;
                    745: pointer *rp;
                    746: {
1.37    ! noro      747:   optimize = ARG0(arg) ? 1 : 0; *rp = 0;
1.1       noro      748: }
                    749:
                    750:
                    751: void sz_init() {
1.37    ! noro      752:   int i;
        !           753:   Q t;
1.1       noro      754:
1.37    ! noro      755:   for ( i = 1; i < 1000; i++ ) {
        !           756:     oPSN[i].p = 1; oPSN[i].b[0] = i;
        !           757:     t = &oPSZ[i];
        !           758:     OID(t) = O_N; NID(t) = N_Q; SGN(t) = 1; NM(t) = &oPSN[i]; DN(t) = 0;
        !           759:     t = &oMSZ[i];
        !           760:     OID(t) = O_N; NID(t) = N_Q; SGN(t) = -1; NM(t) = &oPSN[i]; DN(t) = 0;
        !           761:   }
        !           762:   szinit = 1;
1.1       noro      763: }
                    764:
                    765: optobj(p)
                    766: Obj *p;
                    767: {
1.37    ! noro      768:   Obj t;
        !           769:   int n;
        !           770:   DCP dc;
        !           771:
        !           772:   if ( t = *p )
        !           773:     switch ( OID(t) ) {
        !           774:       case O_N:
        !           775:         if ( (NID(t)==N_Q) && INT(t) && (PL(NM((Q)t))==1) ) {
        !           776:           n = QTOS((Q)t);
        !           777:           if ( !szinit )
        !           778:             sz_init();
        !           779:           if ( n < 1000 )
        !           780:             *p = (Obj)(SGN((Q)t)>0?&oPSZ[n]:&oMSZ[n]);
        !           781:         }
        !           782:         break;
        !           783:       case O_P:
        !           784:         for ( dc = DC((P)t); dc; dc = NEXT(dc) ) {
        !           785:           optobj(&DEG(dc)); optobj(&COEF(dc));
        !           786:         }
        !           787:         break;
        !           788:       case O_R:
        !           789:         optobj(&NM((R)t)); optobj(&DN((R)t)); break;
        !           790:       default:
        !           791:         break;
        !           792:     }
1.1       noro      793: }
                    794: #endif

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