1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
/* pe2pl.c - presentation element to presentation list */
/*
* isode/psap/pe2pl.c
*/
/*
* NOTICE
*
* Acquisition, use, and distribution of this module and related
* materials are subject to the restrictions of a license agreement.
* Consult the Preface in the User's Manual for the full terms of
* this agreement.
*
*/
/* Presentation lists are a human-readable, unambiguous way of describing
a presentation element.
SYNTAX: list :: "(" class code arguments ")"
class :: "UNIV" / "APPL" / "CONT" / "PRIV"
code :: name / number
name :: letter (letter / digit / dash)*
number :: "0x" [0-f] [0-f]* /
"0" [0-7] [0-7]* /
[1-9] [0-9]* /
"\"" (IA5 subset)* "\""
arguments:: primitive / constructor
primitive:: number number*
constructor:: list*
NOTE WELL: A single "number" must be representable in no more than
(sizeof (int)) bytes.
*/
/* LINTLIBRARY */
#include <ctype.h>
#include <stdio.h>
#include "psap.h"
static int pe2pl_aux ();
#define bf_write() \
if (ps_write (ps, (PElementData) buffer, (PElementLen) strlen (buffer)) == NOTOK) \
return NOTOK
/* */
int pe2pl (ps, pe)
register PS ps;
register PE pe;
{
int result;
if ((result = pe2pl_aux (ps, pe, 0)) != NOTOK)
result = ps_flush (ps);
return result;
}
/* */
static int pe2pl_aux (ps, pe, level)
register PS ps;
register PE pe;
int level;
{
register int i,
ia5,
ia5ok;
register char *bp;
char buffer[BUFSIZ];
register PE p;
register PElementID id;
register PElementData dp,
ep,
fp,
gp;
(void) sprintf (buffer, "%*s( %s ",
level * 4, "", pe_classlist[pe -> pe_class]);
bf_write ();
switch (pe -> pe_class) {
case PE_CLASS_UNIV:
if ((int)(id = pe -> pe_id) < pe_maxuniv && (bp = pe_univlist[id])) {
if (ps_write (ps, (PElementData) bp, (PElementLen) strlen (bp))
== NOTOK)
return NOTOK;
}
else
goto no_code;
break;
case PE_CLASS_APPL:
if ((int)(id = pe -> pe_id) < pe_maxappl && (bp = pe_applist[id])) {
if (ps_write (ps, (PElementData) bp, (PElementLen) strlen (bp))
== NOTOK)
return NOTOK;
}
else
goto no_code;
case PE_CLASS_PRIV:
if ((int)(id = pe -> pe_id) < pe_maxpriv && (bp = pe_privlist[id])) {
if (ps_write (ps, (PElementData) bp, (PElementLen) strlen (bp))
== NOTOK)
return NOTOK;
} /* else fall */
case PE_CLASS_CONT:
no_code: ;
(void) sprintf (buffer, "0x%x", pe -> pe_id);
bf_write ();
break;
}
level++;
switch (pe -> pe_form) {
case PE_FORM_PRIM:
case PE_FORM_ICONS:
(void) sprintf (buffer, " 0x%x%c",
pe -> pe_len, pe -> pe_len ? '\n' : ' ');
bf_write ();
if (pe -> pe_len) {
ia5ok = 0;
if (pe -> pe_form == PE_FORM_PRIM
&& pe -> pe_class == PE_CLASS_UNIV)
switch (pe -> pe_id) {
case PE_PRIM_OCTS:
case PE_DEFN_IA5S:
case PE_DEFN_NUMS:
case PE_DEFN_PRTS:
case PE_DEFN_T61S:
case PE_DEFN_VTXS:
case PE_DEFN_VISS:
case PE_DEFN_GENT:
case PE_DEFN_UTCT:
case PE_DEFN_GFXS:
case PE_PRIM_ODE:
case PE_DEFN_GENS:
ia5ok = 1;
break;
default:
break;
}
for (ep = (dp = pe -> pe_prim) + pe -> pe_len; dp < ep;) {
i = min (ep - dp, sizeof (int));
if (ia5 = ia5ok) {
for (gp = (fp = dp) + i; fp < gp; fp++) {
switch (*fp) {
case ' ':
continue;
case '"':
break;
default:
if (iscntrl ((u_char) *fp)
|| isspace ((u_char) *fp)
|| (*fp & 0x80))
break;
continue;
}
ia5 = 0;
break;
}
}
(void) sprintf (buffer, ia5 ? "%*s\"" : "%*s0x",
level * 4, "");
bp = buffer + strlen (buffer);
while (i-- > 0) {
(void) sprintf (bp, ia5 ? (i ? "%c" : "%c\"\n")
: (i ? "%02x" : "%02x\n"), *dp++);
bp += strlen (bp);
}
bf_write ();
}
}
else
level = 1;
break;
case PE_FORM_CONS:
if (p = pe -> pe_cons) {
if (ps_write (ps, (PElementData) "\n", (PElementLen) 1)
== NOTOK)
return NOTOK;
for (p = pe -> pe_cons; p; p = p -> pe_next)
if (pe2pl_aux (ps, p, level) == NOTOK)
return NOTOK;
}
else {
if (ps_write (ps, (PElementData) " ", (PElementLen) 1)
== NOTOK)
return NOTOK;
level = 1;
}
break;
}
level--;
(void) sprintf (buffer, "%*s)\n", level * 4, "");
bf_write ();
return OK;
}
|