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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
/*@z04.c:Token Service:NewToken(), CopyTokenList()@***************************/
/* */
/* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.27) */
/* COPYRIGHT (C) 1991, 2002 Jeffrey H. Kingston */
/* */
/* Jeffrey H. Kingston (jeff@it.usyd.edu.au) */
/* Basser Department of Computer Science */
/* The University of Sydney 2006 */
/* AUSTRALIA */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either Version 2, or (at your option) */
/* any later version. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program; if not, write to the Free Software */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
/* */
/* FILE: z04.c */
/* MODULE: Token Service */
/* EXTERNS: NewToken(), CopyTokenList(), EchoCatOp(), EchoToken() */
/* */
/*****************************************************************************/
#include "externs.h"
/*****************************************************************************/
/* */
/* OBJECT NewToken(xtype, xfpos, xvspace, xhspace, xprec, xactual) */
/* */
/* Returns a new non-WORD token initialised as the parameters indicate. */
/* */
/*****************************************************************************/
OBJECT NewToken(unsigned char xtype, FILE_POS *xfpos, unsigned char xvspace,
unsigned char xhspace, unsigned char xprec, OBJECT xactual)
{ OBJECT res;
debug1(DTS, DDD, "NewToken(%s, ...)", Image(xtype));
New(res, xtype); FposCopy(fpos(res), *xfpos);
vspace(res) = xvspace; hspace(res) = xhspace;
precedence(res) = xprec; actual(res) = xactual;
debug1(DTS, DDD, "NewToken returning %s", EchoToken(res));
return res;
} /* end NewToken */
/*****************************************************************************/
/* */
/* OBJECT CopyTokenList(x, pos) */
/* */
/* Returns a copy of the list of tokens pointed to by x. */
/* All file positions in the copy are set to *pos. */
/* */
/*****************************************************************************/
OBJECT CopyTokenList(OBJECT x, FILE_POS *pos)
{ OBJECT y, z, res;
res = nilobj; y = x;
if( x != nilobj ) do
{ if( is_word(type(y)) )
{ z = MakeWord(type(y), string(y), pos);
vspace(z) = vspace(y); hspace(z) = hspace(y);
}
else z = NewToken(type(y), pos,vspace(y),hspace(y),precedence(y),actual(y));
res = Append(res, z, PARENT);
y = succ(y, PARENT);
} while( y != x );
return res;
} /* end CopyTokenList */
/*@::EchoCatOp(), EchoToken()@************************************************/
/* */
/* FULL_CHAR *EchoCatOp(xtype, xmark, xjoin) */
/* */
/* Return the catenation operator with this type, mark and join. */
/* */
/*****************************************************************************/
FULL_CHAR *EchoCatOp(unsigned xtype, BOOLEAN xmark, BOOLEAN xjoin)
{ switch( xtype )
{
case VCAT: return (xmark ? xjoin ? KW_VCAT_MJ : KW_VCAT_MN
: xjoin ? KW_VCAT_NJ : KW_VCAT_NN);
case HCAT: return (xmark ? xjoin ? KW_HCAT_MJ : KW_HCAT_MN
: xjoin ? KW_HCAT_NJ : KW_HCAT_NN);
case ACAT: return (xmark ? xjoin ? KW_ACAT_MJ : AsciiToFull("??")
: xjoin ? KW_ACAT_NJ : AsciiToFull("??") );
default: assert(FALSE, "EchoCatOp");
return STR_EMPTY;
} /* end switch */
} /* end EchoCatOp */
#if DEBUG_ON
/*****************************************************************************/
/* */
/* FULL_CHAR *EchoToken(x) */
/* */
/* Return an image of token x. Do not worry about preceding space. */
/* */
/*****************************************************************************/
FULL_CHAR *EchoToken(OBJECT x)
{ switch( type(x) )
{
case WORD:
return string(x);
case QWORD:
return StringQuotedWord(x);
case TSPACE:
case TJUXTA:
case USE:
case NOT_REVEALED:
case GSTUB_EXT:
case GSTUB_INT:
case GSTUB_NONE:
return Image(type(x));
case UNEXPECTED_EOF:
case BEGIN:
case END:
case ENV:
case ENVA:
case ENVB:
case ENVC:
case ENVD:
case CENV:
case CLOS:
case LBR:
case RBR:
case NULL_CLOS:
case PAGE_LABEL:
case CROSS:
case FORCE_CROSS:
case BEGIN_HEADER:
case END_HEADER:
case SET_HEADER:
case CLEAR_HEADER:
case ONE_COL:
case ONE_ROW:
case WIDE:
case HIGH:
case HSHIFT:
case VSHIFT:
case HSCALE:
case VSCALE:
case HCOVER:
case VCOVER:
case SCALE:
case KERN_SHRINK:
case HCONTRACT:
case VCONTRACT:
case HLIMITED:
case VLIMITED:
case HEXPAND:
case VEXPAND:
case START_HVSPAN:
case START_HSPAN:
case START_VSPAN:
case HSPAN:
case VSPAN:
case PADJUST:
case HADJUST:
case VADJUST:
case ROTATE:
case BACKGROUND:
case VERBATIM:
case RAW_VERBATIM:
case CASE:
case YIELD:
case BACKEND:
case XCHAR:
case FONT:
case SPACE:
case YUNIT:
case ZUNIT:
case BREAK:
case UNDERLINE:
case COLOUR:
case TEXTURE:
case OUTLINE:
case LANGUAGE:
case CURR_LANG:
case CURR_FAMILY:
case CURR_FACE:
case CURR_YUNIT:
case CURR_ZUNIT:
case COMMON:
case RUMP:
case MELD:
case INSERT:
case ONE_OF:
case NEXT:
case PLUS:
case MINUS:
case OPEN:
case TAGGED:
case INCGRAPHIC:
case SINCGRAPHIC:
case PLAIN_GRAPHIC:
case GRAPHIC:
case LINK_SOURCE:
case LINK_DEST:
case LINK_DEST_NULL:
case LINK_URL:
case ACAT:
case HCAT:
case VCAT:
case CLOSURE:
case PREPEND:
case SYS_PREPEND:
case INCG_REPEATED:
case SINCG_REPEATED:
case DATABASE:
case SYS_DATABASE:
case LUSE:
case LEO:
case LVIS:
return actual(x) != nilobj ? SymName(actual(x)) : Image(type(x));
default:
assert1(FALSE, "EchoToken:", Image(type(x)));
return STR_EMPTY;
}
} /* end EchoToken */
#endif
|