Annotation of OpenXM_contrib2/asir2000/builtin/strobj.c, Revision 1.15
1.6 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.7 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.6 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.15 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.14 2004/03/03 09:25:30 noro Exp $
1.6 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "parse.h"
52: #include "ctype.h"
1.10 ohara 53: #if defined(PARI)
1.1 noro 54: #include "genpari.h"
1.11 saito 55: # if !(PARI_VERSION_CODE > 131588)
1.1 noro 56: extern jmp_buf environnement;
1.11 saito 57: # endif
1.1 noro 58: #endif
1.5 noro 59: #include <string.h>
60:
1.1 noro 61: extern char *parse_strp;
62:
63: void Prtostr(), Pstrtov(), Peval_str();
1.3 noro 64: void Pstrtoascii(), Pasciitostr();
1.5 noro 65: void Pstr_len(), Pstr_chr(), Psub_str();
1.14 noro 66: void Pwrite_to_tb();
67: void Ptb_to_string();
68: void Pclear_tb();
69: void Pstring_to_tb();
70: void Pquotetotex_tb();
71: void Pquotetotex();
72: void fnodetotex_tb(FNODE f,TB tb);
73: char *symbol_name(char *name);
74: void tb_to_string(TB tb,STRING *rp);
75: void fnodenodetotex_tb(NODE n,TB tb);
76: void fargstotex_tb(char *opname,FNODE f,TB tb);
1.1 noro 77:
78: struct ftab str_tab[] = {
79: {"rtostr",Prtostr,1},
80: {"strtov",Pstrtov,1},
81: {"eval_str",Peval_str,1},
1.3 noro 82: {"strtoascii",Pstrtoascii,1},
83: {"asciitostr",Pasciitostr,1},
1.5 noro 84: {"str_len",Pstr_len,1},
85: {"str_chr",Pstr_chr,3},
86: {"sub_str",Psub_str,3},
1.14 noro 87: {"write_to_tb",Pwrite_to_tb,2},
88: {"clear_tb",Pclear_tb,1},
89: {"tb_to_string",Ptb_to_string,1},
90: {"string_to_tb",Pstring_to_tb,1},
91: {"quotetotex_tb",Pquotetotex_tb,2},
92: {"quotetotex",Pquotetotex,1},
1.1 noro 93: {0,0,0},
94: };
1.13 noro 95:
1.14 noro 96: void write_tb(char *s,TB tb)
97: {
98: if ( tb->next == tb->size ) {
99: tb->size *= 2;
100: tb->body = (char **)REALLOC(tb->body,tb->size*sizeof(char *));
101: }
102: tb->body[tb->next] = s;
103: tb->next++;
104: }
1.13 noro 105:
1.14 noro 106: void Pwrite_to_tb(NODE arg,Q *rp)
1.13 noro 107: {
108: int i;
109:
1.14 noro 110: asir_assert(ARG1(arg),O_TB,"write_to_tb");
111: write_tb(BDY((STRING)ARG0(arg)),ARG1(arg));
112: *rp = 0;
1.13 noro 113: }
114:
1.14 noro 115: void Pquotetotex(NODE arg,STRING *rp)
1.13 noro 116: {
1.14 noro 117: TB tb;
1.13 noro 118:
1.14 noro 119: NEWTB(tb);
120: fnodetotex_tb(BDY((QUOTE)ARG0(arg)),tb);
121: tb_to_string(tb,rp);
1.13 noro 122: }
123:
1.14 noro 124: void Pquotetotex_tb(NODE arg,Q *rp)
1.13 noro 125: {
126: int i;
1.14 noro 127: TB tb;
1.13 noro 128:
1.14 noro 129: asir_assert(ARG1(arg),O_TB,"quotetotex_tb");
130: fnodetotex_tb(BDY((QUOTE)ARG0(arg)),ARG1(arg));
1.13 noro 131: *rp = 0;
132: }
133:
1.14 noro 134: void Pstring_to_tb(NODE arg,TB *rp)
135: {
136: TB tb;
137:
138: asir_assert(ARG0(arg),O_STR,"string_to_tb");
139: NEWTB(tb);
140: tb->body[0] = BDY((STRING)ARG0(arg));
141: tb->next++;
142: *rp = tb;
143: }
144:
145: void Ptb_to_string(NODE arg,STRING *rp)
146: {
147: TB tb;
148:
149: asir_assert(ARG0(arg),O_TB,"tb_to_string");
150: tb = (TB)ARG0(arg);
151: tb_to_string(tb,rp);
152: }
153:
154: void tb_to_string(TB tb,STRING *rp)
1.13 noro 155: {
1.14 noro 156: int j,len;
1.13 noro 157: char *all,*p,*q;
158:
1.14 noro 159: for ( j = 0, len = 0; j < tb->next; j++ )
160: len += strlen(tb->body[j]);
161: all = (char *)MALLOC_ATOMIC((len+1)*sizeof(char));
162: for ( j = 0, p = all; j < tb->next; j++ )
163: for ( q = tb->body[j]; *q; *p++ = *q++ );
164: *p = 0;
165: MKSTR(*rp,all);
166: }
167:
168: void Pclear_tb(NODE arg,Q *rp)
169: {
170: TB tb;
171: int j;
172:
173: asir_assert(ARG0(arg),O_TB,"clear_tb");
174: tb = (TB)ARG0(arg);
175: for ( j = 0; j < tb->next; j++ )
176: tb->body[j] = 0;
177: tb->next = 0;
178: *rp = 0;
1.13 noro 179: }
1.5 noro 180:
181: void Pstr_len(arg,rp)
182: NODE arg;
183: Q *rp;
184: {
185: STRING str;
186: int r;
187:
188: str = (STRING)ARG0(arg);
189: asir_assert(str,O_STR,"str_chr");
190: r = strlen(BDY(str));
191: STOQ(r,*rp);
192: }
193:
194: void Pstr_chr(arg,rp)
195: NODE arg;
196: Q *rp;
197: {
198: STRING str,terminator;
199: Q start;
200: char *p,*ind;
201: int chr,spos,r;
202:
203: str = (STRING)ARG0(arg);
204: start = (Q)ARG1(arg);
205: terminator = (STRING)ARG2(arg);
206: asir_assert(str,O_STR,"str_chr");
207: asir_assert(start,O_N,"str_chr");
208: asir_assert(terminator,O_STR,"str_chr");
209: p = BDY(str);
210: spos = QTOS(start);
211: chr = BDY(terminator)[0];
1.8 noro 212: if ( spos > (int)strlen(p) )
1.5 noro 213: r = -1;
214: else {
215: ind = strchr(p+spos,chr);
216: if ( ind )
217: r = ind-p;
218: else
219: r = -1;
220: }
221: STOQ(r,*rp);
222: }
223:
224: void Psub_str(arg,rp)
225: NODE arg;
226: STRING *rp;
227: {
228: STRING str;
229: Q head,tail;
230: char *p,*r;
231: int spos,epos,len;
232:
233: str = (STRING)ARG0(arg);
234: head = (Q)ARG1(arg);
235: tail = (Q)ARG2(arg);
236: asir_assert(str,O_STR,"sub_str");
237: asir_assert(head,O_N,"sub_str");
238: asir_assert(tail,O_N,"sub_str");
239: p = BDY(str);
240: spos = QTOS(head);
241: epos = QTOS(tail);
242: len = strlen(p);
243: if ( (spos >= len) || (epos < spos) ) {
244: *rp = 0; return;
245: }
246: if ( epos >= len )
247: epos = len-1;
248: len = epos-spos+1;
249: r = (char *)MALLOC(len+1);
250: strncpy(r,p+spos,len);
251: r[len] = 0;
252: MKSTR(*rp,r);
253: }
1.3 noro 254:
255: void Pstrtoascii(arg,rp)
256: NODE arg;
257: LIST *rp;
258: {
259: STRING str;
260: unsigned char *p;
261: int len,i;
262: NODE n,n1;
263: Q q;
264:
265: str = (STRING)ARG0(arg);
266: asir_assert(str,O_STR,"strtoascii");
267: p = BDY(str);
268: len = strlen(p);
269: for ( i = len-1, n = 0; i >= 0; i-- ) {
270: UTOQ((unsigned int)p[i],q);
271: MKNODE(n1,q,n);
272: n = n1;
273: }
274: MKLIST(*rp,n);
275: }
276:
277: void Pasciitostr(arg,rp)
278: NODE arg;
279: STRING *rp;
280: {
281: LIST list;
282: unsigned char *p;
283: int len,i,j;
284: NODE n;
285: Q q;
286:
287: list = (LIST)ARG0(arg);
288: asir_assert(list,O_LIST,"asciitostr");
289: n = BDY(list);
290: len = length(n);
291: p = MALLOC_ATOMIC(len+1);
292: for ( i = 0; i < len; i++, n = NEXT(n) ) {
293: q = (Q)BDY(n);
294: asir_assert(q,O_N,"asciitostr");
295: j = QTOS(q);
1.4 noro 296: if ( j >= 256 || j <= 0 )
1.3 noro 297: error("asciitostr : argument out of range");
298: p[i] = j;
299: }
300: p[i] = 0;
301: MKSTR(*rp,(char *)p);
302: }
1.1 noro 303:
304: void Peval_str(arg,rp)
305: NODE arg;
306: Obj *rp;
307: {
308: FNODE fnode;
309: char *cmd;
1.10 ohara 310: #if defined(PARI)
1.8 noro 311: void recover(int);
312:
1.1 noro 313: recover(0);
1.11 saito 314: # if !(PARI_VERSION_CODE > 131588)
1.1 noro 315: if ( setjmp(environnement) ) {
316: avma = top; recover(1);
317: resetenv("");
318: }
1.11 saito 319: # endif
1.1 noro 320: #endif
321: cmd = BDY((STRING)ARG0(arg));
1.9 noro 322: exprparse_create_var(0,cmd,&fnode);
1.1 noro 323: *rp = eval(fnode);
324: }
325:
326: void Prtostr(arg,rp)
327: NODE arg;
328: STRING *rp;
329: {
330: char *b;
331: int len;
332:
1.2 noro 333: len = estimate_length(CO,ARG0(arg));
1.12 noro 334: b = (char *)MALLOC_ATOMIC(len+1);
1.1 noro 335: soutput_init(b);
336: sprintexpr(CO,ARG0(arg));
337: MKSTR(*rp,b);
338: }
339:
340: void Pstrtov(arg,rp)
341: NODE arg;
342: P *rp;
343: {
1.8 noro 344: char *p;
1.1 noro 345:
346: p = BDY((STRING)ARG0(arg));
347: #if 0
348: if ( !islower(*p) )
349: *rp = 0;
350: else {
351: for ( t = p+1; t && (isalnum(*t) || *t == '_'); t++ );
352: if ( *t )
353: *rp = 0;
354: else
355: makevar(p,rp);
356: }
357: #else
358: makevar(p,rp);
359: #endif
1.14 noro 360: }
361:
1.15 ! noro 362: struct TeXSymbol {
! 363: char *text;
! 364: char *symbol;
! 365: };
! 366:
! 367: static struct TeXSymbol texsymbol[] = {
! 368: {"sin","\\sin"},
! 369: {"cos","\\cos"},
! 370: {"tan","\\tan"},
! 371: {"sinh","\\sinh"},
! 372: {"cosh","\\cosh"},
! 373: {"tanh","\\tanh"},
! 374: {"exp","\\exp"},
! 375: {"log","\\log"},
! 376:
! 377: /* Greek Letters (lower case) */
! 378: {"alpha","\\alpha"},
! 379: {"beta","\\beta"},
! 380: {"gamma","\\gamma"},
! 381: {"delta","\\delta"},
! 382: {"epsilon","\\epsilon"},
! 383: {"varepsilon","\\varepsilon"},
! 384: {"zeta","\\zeta"},
! 385: {"eta","\\eta"},
! 386: {"theta","\\theta"},
! 387: {"vartheta","\\vartheta"},
! 388: {"iota","\\iota"},
! 389: {"kappa","\\kappa"},
! 390: {"lambda","\\lambda"},
! 391: {"mu","\\mu"},
! 392: {"nu","\\nu"},
! 393: {"xi","\\xi"},
! 394: {"pi","\\pi"},
! 395: {"varpi","\\varpi"},
! 396: {"rho","\\rho"},
! 397: {"sigma","\\sigma"},
! 398: {"varsigma","\\varsigma"},
! 399: {"tau","\\tau"},
! 400: {"upsilon","\\upsilon"},
! 401: {"phi","\\phi"},
! 402: {"varphi","\\varphi"},
! 403: {"chi","\\chi"},
! 404: {"omega","\\omega"},
! 405:
! 406: /* Greek Letters, (upper case) */
! 407: {"ggamma","\\Gamma"},
! 408: {"ddelta","\\Delta"},
! 409: {"ttheta","\\Theta"},
! 410: {"llambda","\\Lambda"},
! 411: {"xxi","\\Xi"},
! 412: {"ppi","\\Pi"},
! 413: {"ssigma","\\Sigma"},
! 414: {"uupsilon","\\Upsilon"},
! 415: {"pphi","\\Phi"},
! 416: {"ppsi","\\Psi"},
! 417: {"oomega","\\Omega"},
! 418:
! 419: /* Our own mathematical functions */
! 420: {"algebra_tensor","\\otimes"},
! 421: {"base_where","{\\rm \\ where \\ }"},
! 422: /* Mathematical constants */
! 423: {"c_pi","\\pi"},
! 424: {"c_i","\\sqrt{-1}"},
! 425:
! 426: /* Temporary */
! 427: {"dx","\\partial"},
! 428: {0,0}
! 429: };
! 430:
1.14 noro 431: char *symbol_name(char *name)
432: {
1.15 ! noro 433: int i;
! 434:
! 435: for ( i = 0; texsymbol[i].text; i++ )
! 436: if ( !strcmp(texsymbol[i].text,name) )
! 437: return texsymbol[i].symbol;
1.14 noro 438: return name;
439: }
440:
441: void fnodetotex_tb(FNODE f,TB tb)
442: {
443: NODE n,t,t0;
444: char vname[BUFSIZ];
445: char *opname;
446: Obj obj;
1.15 ! noro 447: int i,len,allzero;
! 448: FNODE fi;
1.14 noro 449:
450: write_tb(" ",tb);
451: if ( !f ) {
452: write_tb("0",tb);
453: return;
454: }
455: switch ( f->id ) {
456: /* unary operators */
457: case I_NOT: case I_PAREN: case I_MINUS:
458: switch ( f->id ) {
459: case I_NOT:
460: write_tb("\\neg (",tb);
461: fnodetotex_tb((FNODE)FA0(f),tb);
462: write_tb(")",tb);
463: break;
464: case I_PAREN:
465: write_tb("(",tb);
466: fnodetotex_tb((FNODE)FA0(f),tb);
467: write_tb(")",tb);
468: break;
469: case I_MINUS:
470: write_tb("-",tb);
471: fnodetotex_tb((FNODE)FA0(f),tb);
472: break;
473: }
474: break;
475:
476: /* binary operators */
477: case I_BOP: case I_COP: case I_LOP: case I_AND: case I_OR:
478: /* arg list */
479: /* I_AND, I_OR => FA0(f), FA1(f) */
480: /* otherwise => FA1(f), FA2(f) */
481:
482: /* op */
483: switch ( f->id ) {
484: case I_BOP:
485: opname = ((ARF)FA0(f))->name;
486: if ( !strcmp(opname,"+") ) {
487: fnodetotex_tb((FNODE)FA1(f),tb);
488: write_tb(opname,tb);
489: fnodetotex_tb((FNODE)FA2(f),tb);
490: } else if ( !strcmp(opname,"-") ) {
491: if ( FA1(f) ) fnodetotex_tb((FNODE)FA1(f),tb);
492: write_tb(opname,tb);
493: fnodetotex_tb((FNODE)FA2(f),tb);
494: } else if ( !strcmp(opname,"*") ) {
495: fnodetotex_tb((FNODE)FA1(f),tb);
496: write_tb(" ",tb);
497: fnodetotex_tb((FNODE)FA2(f),tb);
498: } else if ( !strcmp(opname,"/") ) {
499: write_tb("\\frac{",tb);
500: fnodetotex_tb((FNODE)FA1(f),tb);
501: write_tb("} {",tb);
502: fnodetotex_tb((FNODE)FA2(f),tb);
503: write_tb("}",tb);
504: } else if ( !strcmp(opname,"^") ) {
505: fnodetotex_tb((FNODE)FA1(f),tb);
506: write_tb("^{",tb);
507: fnodetotex_tb((FNODE)FA2(f),tb);
508: write_tb("} ",tb);
509: } else if ( !strcmp(opname,"%") ) {
510: fnodetotex_tb((FNODE)FA1(f),tb);
511: write_tb(" {\\rm mod}\\, ",tb);
512: fnodetotex_tb((FNODE)FA2(f),tb);
513: } else
514: error("invalid binary operator");
515:
516: case I_COP:
517: switch( (cid)FA0(f) ) {
518: case C_EQ:
519: fnodetotex_tb((FNODE)FA1(f),tb);
520: write_tb(" = ",tb);
521: fnodetotex_tb((FNODE)FA2(f),tb);
522: break;
523: case C_NE:
524: fnodetotex_tb((FNODE)FA1(f),tb);
525: write_tb(" \\neq ",tb);
526: fnodetotex_tb((FNODE)FA2(f),tb);
527: break;
528: case C_GT:
529: fnodetotex_tb((FNODE)FA1(f),tb);
530: write_tb(" \\gt ",tb);
531: fnodetotex_tb((FNODE)FA2(f),tb);
532: break;
533: case C_LT:
534: fnodetotex_tb((FNODE)FA1(f),tb);
535: write_tb(" \\lt ",tb);
536: fnodetotex_tb((FNODE)FA2(f),tb);
537: break;
538: case C_GE:
539: fnodetotex_tb((FNODE)FA1(f),tb);
540: write_tb(" \\geq ",tb);
541: fnodetotex_tb((FNODE)FA2(f),tb);
542: break;
543: case C_LE:
544: fnodetotex_tb((FNODE)FA1(f),tb);
545: write_tb(" \\leq ",tb);
546: fnodetotex_tb((FNODE)FA2(f),tb);
547: break;
548: }
549: break;
550:
551: case I_LOP:
552: switch( (lid)FA0(f) ) {
553: case L_EQ:
554: fnodetotex_tb((FNODE)FA1(f),tb);
555: write_tb(" = ",tb);
556: fnodetotex_tb((FNODE)FA2(f),tb);
557: break;
558: case L_NE:
559: fnodetotex_tb((FNODE)FA1(f),tb);
560: write_tb(" \\neq ",tb);
561: fnodetotex_tb((FNODE)FA2(f),tb);
562: break;
563: case L_GT:
564: fnodetotex_tb((FNODE)FA1(f),tb);
565: write_tb(" \\gt ",tb);
566: fnodetotex_tb((FNODE)FA2(f),tb);
567: break;
568: case L_LT:
569: fnodetotex_tb((FNODE)FA1(f),tb);
570: write_tb(" \\lt ",tb);
571: fnodetotex_tb((FNODE)FA2(f),tb);
572: break;
573: case L_GE:
574: fnodetotex_tb((FNODE)FA1(f),tb);
575: write_tb(" \\geq ",tb);
576: fnodetotex_tb((FNODE)FA2(f),tb);
577: break;
578: case L_LE:
579: fnodetotex_tb((FNODE)FA1(f),tb);
580: write_tb(" \\leq ",tb);
581: fnodetotex_tb((FNODE)FA2(f),tb);
582: break;
583: case L_AND:
584: fnodetotex_tb((FNODE)FA1(f),tb);
585: write_tb(" {\\rm \\ and\\ } ",tb);
586: fnodetotex_tb((FNODE)FA2(f),tb);
587: break;
588: case L_OR:
589: fnodetotex_tb((FNODE)FA1(f),tb);
590: write_tb(" {\\rm \\ or\\ } ",tb);
591: fnodetotex_tb((FNODE)FA2(f),tb);
592: break;
593: case L_NOT:
594: /* XXX : L_NOT is a unary operator */
595: write_tb("\\neg (",tb);
596: fnodetotex_tb((FNODE)FA1(f),tb);
597: write_tb(")",tb);
598: return;
599: }
600: break;
601:
602: case I_AND:
603: fnodetotex_tb((FNODE)FA0(f),tb);
604: write_tb(" {\\rm \\ and\\ } ",tb);
605: fnodetotex_tb((FNODE)FA1(f),tb);
606: break;
607:
608: case I_OR:
609: fnodetotex_tb((FNODE)FA0(f),tb);
610: write_tb(" {\\rm \\ or\\ } ",tb);
611: fnodetotex_tb((FNODE)FA1(f),tb);
612: break;
613: }
614: break;
615:
616: /* ternary operators */
617: case I_CE:
618: error("fnodetotex_tb : not implemented yet");
619: break;
620:
621: /* lists */
622: case I_LIST:
623: write_tb(" [ ",tb);
624: n = (NODE)FA0(f);
625: fnodenodetotex_tb(n,tb);
626: write_tb("]",tb);
627: break;
628:
629: /* function */
630: case I_FUNC: case I_CAR: case I_CDR: case I_EV:
631: switch ( f->id ) {
632: case I_FUNC:
633: opname = symbol_name(((FUNC)FA0(f))->name);
634: write_tb(opname,tb);
635: write_tb("(",tb);
636: fargstotex_tb(opname,FA1(f),tb);
637: write_tb(")",tb);
638: break;
639: case I_CAR:
640: opname = symbol_name("car");
641: write_tb(opname,tb);
642: write_tb("(",tb);
643: fargstotex_tb(opname,FA0(f),tb);
644: write_tb(")",tb);
645: break;
646: case I_CDR:
647: opname = symbol_name("cdr");
648: write_tb(opname,tb);
649: write_tb("(",tb);
650: fargstotex_tb(opname,FA0(f),tb);
651: write_tb(")",tb);
652: break;
653: case I_EV:
654: n = (NODE)FA0(f);
1.15 ! noro 655: allzero = 1;
1.14 noro 656: for ( t0 = 0, i = 0; n; n = NEXT(n), i++ ) {
1.15 ! noro 657: fi = (FNODE)BDY(n);
! 658: if ( fi->id == I_FORMULA && !FA0(fi) ) continue;
! 659: allzero = 0;
! 660: if ( fi->id == I_FORMULA && UNIQ(FA0(fi)) ) {
! 661: sprintf(vname,"x_{%d}",i);
! 662: len = strlen(vname);
! 663: opname = MALLOC_ATOMIC(len+1);
! 664: strcpy(opname,vname);
! 665: write_tb(opname,tb);
! 666: } else {
! 667: sprintf(vname,"x_{%d}^{",i);
! 668: len = strlen(vname);
! 669: opname = MALLOC_ATOMIC(len+1);
! 670: strcpy(opname,vname);
! 671: write_tb(opname,tb);
! 672: fnodetotex_tb((FNODE)BDY(n),tb);
! 673: write_tb("} ",tb);
! 674: }
1.14 noro 675: }
1.15 ! noro 676: /* XXX */
! 677: if ( allzero )
! 678: write_tb(" 1 ",tb);
1.14 noro 679: break;
680: }
681: break;
682:
683: case I_STR:
684: write_tb((char *)FA0(f),tb);
685: break;
686:
687: case I_FORMULA:
688: obj = (Obj)FA0(f);
689: if ( obj && OID(obj) == O_P ) {
690: opname = symbol_name(VR((P)obj)->name);
691: } else {
692: len = estimate_length(CO,obj);
693: opname = (char *)MALLOC_ATOMIC(len+1);
694: soutput_init(opname);
695: sprintexpr(CO,obj);
696: }
697: write_tb(opname,tb);
698: break;
699:
700: case I_PVAR:
701: if ( FA1(f) )
702: error("fnodetotex_tb : not implemented yet");
703: GETPVNAME(FA0(f),opname);
704: write_tb(opname,tb);
705: break;
706:
707: default:
708: error("fnodetotex_tb : not implemented yet");
709: }
710: }
711:
712: void fnodenodetotex_tb(NODE n,TB tb)
713: {
714: for ( ; n; n = NEXT(n) ) {
715: fnodetotex_tb((FNODE)BDY(n),tb);
716: if ( NEXT(n) ) write_tb(", ",tb);
717: }
718: }
719:
720: void fargstotex_tb(char *name,FNODE f,TB tb)
721: {
722: NODE n;
723:
724: if ( !strcmp(name,"matrix") ) {
725: error("fargstotex_tb : not implemented yet");
726: } else if ( !strcmp(name,"vector") ) {
727: error("fargstotex_tb : not implemented yet");
728: } else {
729: if ( f->id == I_LIST ) {
730: n = (NODE)FA0(f);
731: fnodenodetotex_tb(n,tb);
732: } else
733: fnodetotex_tb(f,tb);
734: }
1.1 noro 735: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>