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