Annotation of OpenXM_contrib2/asir2000/builtin/strobj.c, Revision 1.3
1.3 ! noro 1: /* $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.2 2000/02/03 05:45:44 noro Exp $ */
1.1 noro 2: #include "ca.h"
3: #include "parse.h"
4: #include "ctype.h"
5: #if PARI
6: #include "genpari.h"
7: extern jmp_buf environnement;
8: #endif
9: extern char *parse_strp;
10:
11: void Prtostr(), Pstrtov(), Peval_str();
1.3 ! noro 12: void Pstrtoascii(), Pasciitostr();
1.1 noro 13:
14: struct ftab str_tab[] = {
15: {"rtostr",Prtostr,1},
16: {"strtov",Pstrtov,1},
17: {"eval_str",Peval_str,1},
1.3 ! noro 18: {"strtoascii",Pstrtoascii,1},
! 19: {"asciitostr",Pasciitostr,1},
1.1 noro 20: {0,0,0},
21: };
1.3 ! noro 22:
! 23: void Pstrtoascii(arg,rp)
! 24: NODE arg;
! 25: LIST *rp;
! 26: {
! 27: STRING str;
! 28: unsigned char *p;
! 29: int len,i;
! 30: NODE n,n1;
! 31: Q q;
! 32:
! 33: str = (STRING)ARG0(arg);
! 34: asir_assert(str,O_STR,"strtoascii");
! 35: p = BDY(str);
! 36: len = strlen(p);
! 37: for ( i = len-1, n = 0; i >= 0; i-- ) {
! 38: UTOQ((unsigned int)p[i],q);
! 39: MKNODE(n1,q,n);
! 40: n = n1;
! 41: }
! 42: MKLIST(*rp,n);
! 43: }
! 44:
! 45: void Pasciitostr(arg,rp)
! 46: NODE arg;
! 47: STRING *rp;
! 48: {
! 49: LIST list;
! 50: unsigned char *p;
! 51: int len,i,j;
! 52: NODE n;
! 53: Q q;
! 54:
! 55: list = (LIST)ARG0(arg);
! 56: asir_assert(list,O_LIST,"asciitostr");
! 57: n = BDY(list);
! 58: len = length(n);
! 59: p = MALLOC_ATOMIC(len+1);
! 60: for ( i = 0; i < len; i++, n = NEXT(n) ) {
! 61: q = (Q)BDY(n);
! 62: asir_assert(q,O_N,"asciitostr");
! 63: j = QTOS(q);
! 64: if ( j >= 256 || j < 0 )
! 65: error("asciitostr : argument out of range");
! 66: p[i] = j;
! 67: }
! 68: p[i] = 0;
! 69: MKSTR(*rp,(char *)p);
! 70: }
1.1 noro 71:
72: void Peval_str(arg,rp)
73: NODE arg;
74: Obj *rp;
75: {
76: FNODE fnode;
77: char *cmd;
78: #if PARI
79: recover(0);
80: if ( setjmp(environnement) ) {
81: avma = top; recover(1);
82: resetenv("");
83: }
84: #endif
85: cmd = BDY((STRING)ARG0(arg));
86: exprparse(0,cmd,&fnode);
87: *rp = eval(fnode);
88: }
89:
90: void Prtostr(arg,rp)
91: NODE arg;
92: STRING *rp;
93: {
94: char *b;
95: int len;
96:
1.2 noro 97: len = estimate_length(CO,ARG0(arg));
1.1 noro 98: b = (char *)MALLOC(len+1);
99: soutput_init(b);
100: sprintexpr(CO,ARG0(arg));
101: MKSTR(*rp,b);
102: }
103:
104: void Pstrtov(arg,rp)
105: NODE arg;
106: P *rp;
107: {
108: char *p,*t;
109:
110: p = BDY((STRING)ARG0(arg));
111: #if 0
112: if ( !islower(*p) )
113: *rp = 0;
114: else {
115: for ( t = p+1; t && (isalnum(*t) || *t == '_'); t++ );
116: if ( *t )
117: *rp = 0;
118: else
119: makevar(p,rp);
120: }
121: #else
122: makevar(p,rp);
123: #endif
124: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>