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