[BACK]Return to miscf.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2018 / builtin

Annotation of OpenXM_contrib2/asir2018/builtin/miscf.c, Revision 1.4

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

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