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

Annotation of OpenXM_contrib2/asir2000/builtin/strobj.c, Revision 1.12

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.12    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.11 2004/02/13 05:48:35 saito 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.1       noro       66:
                     67: struct ftab str_tab[] = {
                     68:        {"rtostr",Prtostr,1},
                     69:        {"strtov",Pstrtov,1},
                     70:        {"eval_str",Peval_str,1},
1.3       noro       71:        {"strtoascii",Pstrtoascii,1},
                     72:        {"asciitostr",Pasciitostr,1},
1.5       noro       73:        {"str_len",Pstr_len,1},
                     74:        {"str_chr",Pstr_chr,3},
                     75:        {"sub_str",Psub_str,3},
1.1       noro       76:        {0,0,0},
                     77: };
1.5       noro       78:
                     79: void Pstr_len(arg,rp)
                     80: NODE arg;
                     81: Q *rp;
                     82: {
                     83:        STRING str;
                     84:        int r;
                     85:
                     86:        str = (STRING)ARG0(arg);
                     87:        asir_assert(str,O_STR,"str_chr");
                     88:        r = strlen(BDY(str));
                     89:        STOQ(r,*rp);
                     90: }
                     91:
                     92: void Pstr_chr(arg,rp)
                     93: NODE arg;
                     94: Q *rp;
                     95: {
                     96:        STRING str,terminator;
                     97:        Q start;
                     98:        char *p,*ind;
                     99:        int chr,spos,r;
                    100:
                    101:        str = (STRING)ARG0(arg);
                    102:        start = (Q)ARG1(arg);
                    103:        terminator = (STRING)ARG2(arg);
                    104:        asir_assert(str,O_STR,"str_chr");
                    105:        asir_assert(start,O_N,"str_chr");
                    106:        asir_assert(terminator,O_STR,"str_chr");
                    107:        p = BDY(str);
                    108:        spos = QTOS(start);
                    109:        chr = BDY(terminator)[0];
1.8       noro      110:        if ( spos > (int)strlen(p) )
1.5       noro      111:                r = -1;
                    112:        else {
                    113:                ind = strchr(p+spos,chr);
                    114:                if ( ind )
                    115:                        r = ind-p;
                    116:                else
                    117:                        r = -1;
                    118:        }
                    119:        STOQ(r,*rp);
                    120: }
                    121:
                    122: void Psub_str(arg,rp)
                    123: NODE arg;
                    124: STRING *rp;
                    125: {
                    126:        STRING str;
                    127:        Q head,tail;
                    128:        char *p,*r;
                    129:        int spos,epos,len;
                    130:
                    131:        str = (STRING)ARG0(arg);
                    132:        head = (Q)ARG1(arg);
                    133:        tail = (Q)ARG2(arg);
                    134:        asir_assert(str,O_STR,"sub_str");
                    135:        asir_assert(head,O_N,"sub_str");
                    136:        asir_assert(tail,O_N,"sub_str");
                    137:        p = BDY(str);
                    138:        spos = QTOS(head);
                    139:        epos = QTOS(tail);
                    140:        len = strlen(p);
                    141:        if ( (spos >= len) || (epos < spos) ) {
                    142:                *rp = 0; return;
                    143:        }
                    144:        if ( epos >= len )
                    145:                epos = len-1;
                    146:        len = epos-spos+1;
                    147:        r = (char *)MALLOC(len+1);
                    148:        strncpy(r,p+spos,len);
                    149:        r[len] = 0;
                    150:        MKSTR(*rp,r);
                    151: }
1.3       noro      152:
                    153: void Pstrtoascii(arg,rp)
                    154: NODE arg;
                    155: LIST *rp;
                    156: {
                    157:        STRING str;
                    158:        unsigned char *p;
                    159:        int len,i;
                    160:        NODE n,n1;
                    161:        Q q;
                    162:
                    163:        str = (STRING)ARG0(arg);
                    164:        asir_assert(str,O_STR,"strtoascii");
                    165:        p = BDY(str);
                    166:        len = strlen(p);
                    167:        for ( i = len-1, n = 0; i >= 0; i-- ) {
                    168:                UTOQ((unsigned int)p[i],q);
                    169:                MKNODE(n1,q,n);
                    170:                n = n1;
                    171:        }
                    172:        MKLIST(*rp,n);
                    173: }
                    174:
                    175: void Pasciitostr(arg,rp)
                    176: NODE arg;
                    177: STRING *rp;
                    178: {
                    179:        LIST list;
                    180:        unsigned char *p;
                    181:        int len,i,j;
                    182:        NODE n;
                    183:        Q q;
                    184:
                    185:        list = (LIST)ARG0(arg);
                    186:        asir_assert(list,O_LIST,"asciitostr");
                    187:        n = BDY(list);
                    188:        len = length(n);
                    189:        p = MALLOC_ATOMIC(len+1);
                    190:        for ( i = 0; i < len; i++, n = NEXT(n) ) {
                    191:                q = (Q)BDY(n);
                    192:                asir_assert(q,O_N,"asciitostr");
                    193:                j = QTOS(q);
1.4       noro      194:                if ( j >= 256 || j <= 0 )
1.3       noro      195:                        error("asciitostr : argument out of range");
                    196:                p[i] = j;
                    197:        }
                    198:        p[i] = 0;
                    199:        MKSTR(*rp,(char *)p);
                    200: }
1.1       noro      201:
                    202: void Peval_str(arg,rp)
                    203: NODE arg;
                    204: Obj *rp;
                    205: {
                    206:        FNODE fnode;
                    207:        char *cmd;
1.10      ohara     208: #if defined(PARI)
1.8       noro      209:        void recover(int);
                    210:
1.1       noro      211:        recover(0);
1.11      saito     212: #  if !(PARI_VERSION_CODE > 131588)
1.1       noro      213:        if ( setjmp(environnement) ) {
                    214:                avma = top; recover(1);
                    215:                resetenv("");
                    216:        }
1.11      saito     217: #  endif
1.1       noro      218: #endif
                    219:        cmd = BDY((STRING)ARG0(arg));
1.9       noro      220:        exprparse_create_var(0,cmd,&fnode);
1.1       noro      221:        *rp = eval(fnode);
                    222: }
                    223:
                    224: void Prtostr(arg,rp)
                    225: NODE arg;
                    226: STRING *rp;
                    227: {
                    228:        char *b;
                    229:        int len;
                    230:
1.2       noro      231:        len = estimate_length(CO,ARG0(arg));
1.12    ! noro      232:        b = (char *)MALLOC_ATOMIC(len+1);
1.1       noro      233:        soutput_init(b);
                    234:        sprintexpr(CO,ARG0(arg));
                    235:        MKSTR(*rp,b);
                    236: }
                    237:
                    238: void Pstrtov(arg,rp)
                    239: NODE arg;
                    240: P *rp;
                    241: {
1.8       noro      242:        char *p;
1.1       noro      243:
                    244:        p = BDY((STRING)ARG0(arg));
                    245: #if 0
                    246:        if ( !islower(*p) )
                    247:                *rp = 0;
                    248:        else {
                    249:                for ( t = p+1; t && (isalnum(*t) || *t == '_'); t++ );
                    250:                if ( *t )
                    251:                        *rp = 0;
                    252:                else
                    253:                        makevar(p,rp);
                    254:        }
                    255: #else
                    256:        makevar(p,rp);
                    257: #endif
                    258: }

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