Annotation of 43BSDReno/contrib/isode-beta/dsap/common/telex.c, revision 1.1.1.1

1.1       root        1: /* telex.c - Telex attribute */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/dsap/common/RCS/telex.c,v 7.0 89/11/23 21:44:37 mrose Rel $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/dsap/common/RCS/telex.c,v 7.0 89/11/23 21:44:37 mrose Rel $
                      9:  *
                     10:  *
                     11:  * $Log:       telex.c,v $
                     12:  * Revision 7.0  89/11/23  21:44:37  mrose
                     13:  * Release 6.0
                     14:  * 
                     15:  */
                     16: 
                     17: /*
                     18:  *                               NOTICE
                     19:  *
                     20:  *    Acquisition, use, and distribution of this module and related
                     21:  *    materials are subject to the restrictions of a license agreement.
                     22:  *    Consult the Preface in the User's Manual for the full terms of
                     23:  *    this agreement.
                     24:  *
                     25:  */
                     26: 
                     27: 
                     28: /*
                     29:        SYNTAX
                     30:        telex ::= <printablestring> '$' <printablestring> '$' <printablestring>
                     31:        
                     32:        REPRESENTING
                     33:                number $ country $ answerback
                     34: */
                     35: 
                     36: /* LINTLIBRARY */
                     37: 
                     38: #include "quipu/util.h"
                     39: #include "quipu/entry.h"
                     40: 
                     41: static telex_free (ptr)
                     42: struct telex * ptr;
                     43: {
                     44:        free (ptr->telexnumber);
                     45:        free (ptr->countrycode);
                     46:        free (ptr->answerback);
                     47: 
                     48:        free ((char *) ptr);
                     49: }
                     50: 
                     51: 
                     52: static struct telex * telex_cpy (a)
                     53: struct telex * a;
                     54: {
                     55: struct telex * result;
                     56: 
                     57:        result = (struct telex *) smalloc (sizeof (struct telex));
                     58:        result->telexnumber = strdup (a->telexnumber);
                     59:        result->countrycode = strdup (a->countrycode);
                     60:        result->answerback  = strdup (a->answerback);
                     61:        return (result);
                     62: }
                     63: 
                     64: static telex_cmp (a,b)
                     65: struct telex * a;
                     66: struct telex * b;
                     67: {
                     68: int res;
                     69: 
                     70:        if (a == (struct telex *) NULL)
                     71:                if (b == (struct telex *) NULL)
                     72:                        return (0);
                     73:                else 
                     74:                        return (-1);
                     75: 
                     76:        if ( (res = lexequ(a->telexnumber,b->telexnumber)) != 0) 
                     77:                return (res);
                     78:        if ( (res = lexequ(a->countrycode,b->countrycode)) != 0)
                     79:                return (res);
                     80:        if ( (res = lexequ(a->answerback,b->answerback)) != 0)
                     81:                return (res);
                     82:        return (0);
                     83: }
                     84: 
                     85: 
                     86: static telex_print (ps,telex,format)
                     87: register PS ps;
                     88: struct   telex* telex;
                     89: int format;
                     90: {
                     91:        if (format == READOUT)
                     92:                ps_printf (ps,"number: %s, country: %s, answerback: %s",telex->telexnumber, telex->countrycode, telex->answerback);
                     93:        else
                     94:                ps_printf (ps,"%s $ %s $ %s",telex->telexnumber, telex->countrycode, telex->answerback);
                     95: }
                     96: 
                     97: 
                     98: static struct telex* str2telex (str)
                     99: char * str;
                    100: {
                    101: struct telex * result;
                    102: char * ptr;
                    103: char * mark = NULLCP;
                    104: char * prtparse ();
                    105: 
                    106:        if ( (ptr=index (str,'$')) == NULLCP) {
                    107:                parse_error ("seperator missing in telex '%s'",str);
                    108:                return ((struct telex *) NULL);
                    109:        }
                    110: 
                    111:        result = (struct telex *) smalloc (sizeof (struct telex));
                    112:        *ptr--= 0;
                    113:        if (isspace (*ptr)) {
                    114:                *ptr = 0;
                    115:                mark = ptr;
                    116:        }
                    117:        ptr++;
                    118:        if ((result->telexnumber = prtparse(str)) == NULLCP)
                    119:                 return ((struct telex *) NULL);
                    120:        if (strlen (result->telexnumber) > UB_TELEX_NUMBER) {
                    121:                parse_error ("telexnumber too big",NULLCP);
                    122:                return ((struct telex *) NULL);
                    123:        }
                    124:                
                    125:        *ptr++ = '$';
                    126: 
                    127:        if (mark != NULLCP)
                    128:                *mark = ' ';
                    129: 
                    130:        str = SkipSpace(ptr);   
                    131: 
                    132:        if ( (ptr=index (str,'$')) == NULLCP) {
                    133:                parse_error ("2nd seperator missing in telex '%s'",str);
                    134:                return ((struct telex *) NULL);
                    135:        }
                    136: 
                    137:        *ptr--= 0;
                    138:        if (isspace (*ptr)) {
                    139:                *ptr = 0;
                    140:                mark = ptr;
                    141:        } else
                    142:                mark = NULLCP;
                    143: 
                    144:        ptr++;
                    145: 
                    146:        if ((result->countrycode = prtparse(str)) == NULLCP)
                    147:                 return ((struct telex *) NULL);
                    148:        if (strlen (result->countrycode) > UB_COUNTRY_CODE) {
                    149:                parse_error ("countrycode too big",NULLCP);
                    150:                return ((struct telex *) NULL);
                    151:        }
                    152: 
                    153:        *ptr++ = '$';
                    154: 
                    155:        if (mark != NULLCP)
                    156:                *mark = ' ';
                    157: 
                    158:        if ((result->answerback = prtparse(SkipSpace(ptr))) == NULLCP)
                    159:                 return ((struct telex *) NULL);
                    160:        if (strlen (result->answerback) > UB_ANSWERBACK) {
                    161:                parse_error ("answerback too big",NULLCP);
                    162:                return ((struct telex *) NULL);
                    163:        }
                    164: 
                    165:        return (result);
                    166: }
                    167: 
                    168: static PE telex_enc (m)
                    169: struct telex * m;
                    170: {
                    171: PE ret_pe;
                    172: 
                    173:         (void) encode_SA_TelexNumber (&ret_pe,0,0,NULLCP,m);
                    174: 
                    175:        return (ret_pe);
                    176: }
                    177: 
                    178: static struct telex * telex_dec (pe)
                    179: PE pe;
                    180: {
                    181: struct telex * m;
                    182: 
                    183:        m = (struct telex *) smalloc (sizeof (struct telex));
                    184: 
                    185:        if (decode_SA_TelexNumber (pe,1,NULLIP,NULLVP,m) == NOTOK) {
                    186:                free ((char *)m);
                    187:                return ((struct telex *) NULL);
                    188:        }
                    189:        return (m);
                    190: }
                    191: 
                    192: telex_syntax ()
                    193: {
                    194:        (void) add_attribute_syntax ("TelexNumber",
                    195:                (IFP) telex_enc,        (IFP) telex_dec,
                    196:                (IFP) str2telex,        telex_print,
                    197:                (IFP) telex_cpy,        telex_cmp,
                    198:                telex_free,             NULLCP,
                    199:                NULLIFP,                TRUE);
                    200: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.