emit1.c revision 1.16 1 1.16 perry /* $NetBSD: emit1.c,v 1.16 2005/09/24 15:30:35 perry Exp $ */
2 1.2 cgd
3 1.1 cgd /*
4 1.5 cgd * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
5 1.1 cgd * Copyright (c) 1994, 1995 Jochen Pohl
6 1.1 cgd * All Rights Reserved.
7 1.1 cgd *
8 1.1 cgd * Redistribution and use in source and binary forms, with or without
9 1.1 cgd * modification, are permitted provided that the following conditions
10 1.1 cgd * are met:
11 1.1 cgd * 1. Redistributions of source code must retain the above copyright
12 1.1 cgd * notice, this list of conditions and the following disclaimer.
13 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 cgd * notice, this list of conditions and the following disclaimer in the
15 1.1 cgd * documentation and/or other materials provided with the distribution.
16 1.1 cgd * 3. All advertising materials mentioning features or use of this software
17 1.1 cgd * must display the following acknowledgement:
18 1.1 cgd * This product includes software developed by Jochen Pohl for
19 1.1 cgd * The NetBSD Project.
20 1.1 cgd * 4. The name of the author may not be used to endorse or promote products
21 1.1 cgd * derived from this software without specific prior written permission.
22 1.1 cgd *
23 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.1 cgd * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.1 cgd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.1 cgd * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.1 cgd * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.1 cgd * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.1 cgd * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.1 cgd * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.1 cgd * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.1 cgd * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.1 cgd */
34 1.1 cgd
35 1.14 jmc #if HAVE_NBTOOL_CONFIG_H
36 1.14 jmc #include "nbtool_config.h"
37 1.14 jmc #endif
38 1.14 jmc
39 1.7 christos #include <sys/cdefs.h>
40 1.11 tv #if defined(__RCSID) && !defined(lint)
41 1.16 perry __RCSID("$NetBSD: emit1.c,v 1.16 2005/09/24 15:30:35 perry Exp $");
42 1.1 cgd #endif
43 1.1 cgd
44 1.1 cgd #include <ctype.h>
45 1.1 cgd
46 1.1 cgd #include "lint1.h"
47 1.1 cgd
48 1.10 lukem static void outtt(sym_t *, sym_t *);
49 1.10 lukem static void outfstrg(strg_t *);
50 1.1 cgd
51 1.1 cgd /*
52 1.1 cgd * Write type into the output buffer.
53 1.1 cgd * The type is written as a sequence of substrings, each of which describes a
54 1.1 cgd * node of type type_t
55 1.1 cgd * a node is coded as follows:
56 1.15 yamt * _Bool B
57 1.1 cgd * char C
58 1.1 cgd * signed char s C
59 1.1 cgd * unsigned char u C
60 1.1 cgd * short S
61 1.1 cgd * unsigned short u S
62 1.1 cgd * int I
63 1.1 cgd * unsigned int u I
64 1.1 cgd * long L
65 1.1 cgd * unsigned long u L
66 1.1 cgd * long long Q
67 1.1 cgd * unsigned long long u Q
68 1.1 cgd * float s D
69 1.1 cgd * double D
70 1.1 cgd * long double l D
71 1.1 cgd * void V
72 1.1 cgd * * P
73 1.1 cgd * [n] A n
74 1.1 cgd * () F
75 1.1 cgd * (void) F 0
76 1.1 cgd * (n arguments) F n arg1 arg2 ... argn
77 1.1 cgd * (n arguments, ...) F n arg1 arg2 ... argn-1 E
78 1.1 cgd * (a, b, c, ...) f n arg1 arg2 ...
79 1.1 cgd * enum tag e T tag_or_typename
80 1.1 cgd * struct tag s T tag_or_typename
81 1.1 cgd * union tag u T tag_or_typename
82 1.1 cgd *
83 1.1 cgd * tag_or_typename 0 no tag or type name
84 1.1 cgd * 1 n tag Tag
85 1.1 cgd * 2 n typename only type name
86 1.1 cgd *
87 1.1 cgd * spaces are only for better readability
88 1.1 cgd * additionaly it is possible to prepend the characters 'c' (for const)
89 1.1 cgd * and 'v' (for volatile)
90 1.1 cgd */
91 1.1 cgd void
92 1.10 lukem outtype(type_t *tp)
93 1.1 cgd {
94 1.1 cgd int t, s, na;
95 1.1 cgd sym_t *arg;
96 1.1 cgd tspec_t ts;
97 1.1 cgd
98 1.1 cgd while (tp != NULL) {
99 1.1 cgd if ((ts = tp->t_tspec) == INT && tp->t_isenum)
100 1.1 cgd ts = ENUM;
101 1.1 cgd switch (ts) {
102 1.15 yamt case BOOL: t = 'B'; s = '\0'; break;
103 1.1 cgd case CHAR: t = 'C'; s = '\0'; break;
104 1.1 cgd case SCHAR: t = 'C'; s = 's'; break;
105 1.1 cgd case UCHAR: t = 'C'; s = 'u'; break;
106 1.1 cgd case SHORT: t = 'S'; s = '\0'; break;
107 1.1 cgd case USHORT: t = 'S'; s = 'u'; break;
108 1.1 cgd case INT: t = 'I'; s = '\0'; break;
109 1.1 cgd case UINT: t = 'I'; s = 'u'; break;
110 1.1 cgd case LONG: t = 'L'; s = '\0'; break;
111 1.1 cgd case ULONG: t = 'L'; s = 'u'; break;
112 1.1 cgd case QUAD: t = 'Q'; s = '\0'; break;
113 1.1 cgd case UQUAD: t = 'Q'; s = 'u'; break;
114 1.1 cgd case FLOAT: t = 'D'; s = 's'; break;
115 1.1 cgd case DOUBLE: t = 'D'; s = '\0'; break;
116 1.1 cgd case LDOUBLE: t = 'D'; s = 'l'; break;
117 1.1 cgd case VOID: t = 'V'; s = '\0'; break;
118 1.1 cgd case PTR: t = 'P'; s = '\0'; break;
119 1.1 cgd case ARRAY: t = 'A'; s = '\0'; break;
120 1.1 cgd case FUNC: t = 'F'; s = '\0'; break;
121 1.1 cgd case ENUM: t = 'T'; s = 'e'; break;
122 1.1 cgd case STRUCT: t = 'T'; s = 's'; break;
123 1.1 cgd case UNION: t = 'T'; s = 'u'; break;
124 1.1 cgd default:
125 1.13 christos LERROR("outtyp()");
126 1.1 cgd }
127 1.1 cgd if (tp->t_const)
128 1.1 cgd outchar('c');
129 1.1 cgd if (tp->t_volatile)
130 1.1 cgd outchar('v');
131 1.1 cgd if (s != '\0')
132 1.1 cgd outchar(s);
133 1.1 cgd outchar(t);
134 1.1 cgd if (ts == ARRAY) {
135 1.1 cgd outint(tp->t_dim);
136 1.1 cgd } else if (ts == ENUM) {
137 1.1 cgd outtt(tp->t_enum->etag, tp->t_enum->etdef);
138 1.1 cgd } else if (ts == STRUCT || ts == UNION) {
139 1.1 cgd outtt(tp->t_str->stag, tp->t_str->stdef);
140 1.1 cgd } else if (ts == FUNC && tp->t_proto) {
141 1.1 cgd na = 0;
142 1.1 cgd for (arg = tp->t_args; arg != NULL; arg = arg->s_nxt)
143 1.1 cgd na++;
144 1.1 cgd if (tp->t_vararg)
145 1.1 cgd na++;
146 1.1 cgd outint(na);
147 1.1 cgd for (arg = tp->t_args; arg != NULL; arg = arg->s_nxt)
148 1.1 cgd outtype(arg->s_type);
149 1.1 cgd if (tp->t_vararg)
150 1.1 cgd outchar('E');
151 1.1 cgd }
152 1.1 cgd tp = tp->t_subt;
153 1.1 cgd }
154 1.1 cgd }
155 1.1 cgd
156 1.1 cgd /*
157 1.1 cgd * type to string
158 1.1 cgd * used for debugging output
159 1.1 cgd *
160 1.1 cgd * it uses its own output buffer for conversion
161 1.1 cgd */
162 1.1 cgd const char *
163 1.10 lukem ttos(type_t *tp)
164 1.1 cgd {
165 1.1 cgd static ob_t tob;
166 1.1 cgd ob_t tmp;
167 1.1 cgd
168 1.1 cgd if (tob.o_buf == NULL) {
169 1.1 cgd tob.o_len = 64;
170 1.1 cgd tob.o_buf = tob.o_nxt = xmalloc(tob.o_len);
171 1.1 cgd tob.o_end = tob.o_buf + tob.o_len;
172 1.1 cgd }
173 1.1 cgd
174 1.1 cgd tmp = ob;
175 1.1 cgd ob = tob;
176 1.1 cgd ob.o_nxt = ob.o_buf;
177 1.1 cgd outtype(tp);
178 1.1 cgd outchar('\0');
179 1.1 cgd tob = ob;
180 1.1 cgd ob = tmp;
181 1.1 cgd
182 1.1 cgd return (tob.o_buf);
183 1.1 cgd }
184 1.1 cgd
185 1.1 cgd /*
186 1.1 cgd * write the name of a tag or typename
187 1.1 cgd *
188 1.1 cgd * if the tag is named, the name of the
189 1.1 cgd * tag is written, otherwise, if a typename exists which
190 1.1 cgd * refers to this tag, this typename is written
191 1.1 cgd */
192 1.1 cgd static void
193 1.10 lukem outtt(sym_t *tag, sym_t *tdef)
194 1.1 cgd {
195 1.5 cgd
196 1.5 cgd /*
197 1.5 cgd * 0 is no longer used.
198 1.5 cgd */
199 1.1 cgd if (tag->s_name != unnamed) {
200 1.1 cgd outint(1);
201 1.1 cgd outname(tag->s_name);
202 1.1 cgd } else if (tdef != NULL) {
203 1.1 cgd outint(2);
204 1.1 cgd outname(tdef->s_name);
205 1.1 cgd } else {
206 1.5 cgd outint(3);
207 1.5 cgd outint(tag->s_dpos.p_line);
208 1.5 cgd outchar('.');
209 1.5 cgd outint(getfnid(tag->s_dpos.p_file));
210 1.5 cgd outchar('.');
211 1.5 cgd outint(tag->s_dpos.p_uniq);
212 1.1 cgd }
213 1.1 cgd }
214 1.1 cgd
215 1.1 cgd /*
216 1.3 jpo * write information about an global declared/defined symbol
217 1.3 jpo * with storage class extern
218 1.1 cgd *
219 1.1 cgd * informations about function definitions are written in outfdef(),
220 1.1 cgd * not here
221 1.1 cgd */
222 1.1 cgd void
223 1.10 lukem outsym(sym_t *sym, scl_t sc, def_t def)
224 1.1 cgd {
225 1.10 lukem
226 1.1 cgd /*
227 1.1 cgd * Static function declarations must also be written to the output
228 1.1 cgd * file. Compatibility of function declarations (for both static
229 1.1 cgd * and extern functions) must be checked in lint2. Lint1 can't do
230 1.1 cgd * this, especially not, if functions are declared at block level
231 1.1 cgd * before their first declaration at level 0.
232 1.1 cgd */
233 1.1 cgd if (sc != EXTERN && !(sc == STATIC && sym->s_type->t_tspec == FUNC))
234 1.1 cgd return;
235 1.1 cgd
236 1.1 cgd /* reset buffer */
237 1.1 cgd outclr();
238 1.1 cgd
239 1.1 cgd /*
240 1.1 cgd * line number of .c source, 'd' for declaration, Id of current
241 1.1 cgd * source (.c or .h), and line in current source.
242 1.1 cgd */
243 1.1 cgd outint(csrc_pos.p_line);
244 1.1 cgd outchar('d');
245 1.1 cgd outint(getfnid(sym->s_dpos.p_file));
246 1.1 cgd outchar('.');
247 1.1 cgd outint(sym->s_dpos.p_line);
248 1.1 cgd
249 1.1 cgd /* flags */
250 1.1 cgd
251 1.3 jpo switch (def) {
252 1.1 cgd case DEF:
253 1.1 cgd /* defined */
254 1.1 cgd outchar('d');
255 1.1 cgd break;
256 1.1 cgd case TDEF:
257 1.1 cgd /* tentative defined */
258 1.1 cgd outchar('t');
259 1.1 cgd break;
260 1.1 cgd case DECL:
261 1.1 cgd /* declared */
262 1.1 cgd outchar('e');
263 1.1 cgd break;
264 1.1 cgd default:
265 1.13 christos LERROR("outsym()");
266 1.1 cgd }
267 1.3 jpo if (llibflg && def != DECL) {
268 1.1 cgd /*
269 1.1 cgd * mark it as used so we get no warnings from lint2 about
270 1.1 cgd * unused symbols in libraries.
271 1.1 cgd */
272 1.1 cgd outchar('u');
273 1.1 cgd }
274 1.1 cgd
275 1.1 cgd if (sc == STATIC)
276 1.1 cgd outchar('s');
277 1.1 cgd
278 1.1 cgd /* name of the symbol */
279 1.1 cgd outname(sym->s_name);
280 1.1 cgd
281 1.6 cgd /* renamed name of symbol, if necessary */
282 1.6 cgd if (sym->s_rename) {
283 1.6 cgd outchar('r');
284 1.6 cgd outname(sym->s_rename);
285 1.6 cgd }
286 1.6 cgd
287 1.1 cgd /* type of the symbol */
288 1.1 cgd outtype(sym->s_type);
289 1.1 cgd }
290 1.1 cgd
291 1.1 cgd /*
292 1.1 cgd * write information about function definition
293 1.1 cgd *
294 1.1 cgd * this is also done for static functions so we are able to check if
295 1.1 cgd * they are called with proper argument types
296 1.1 cgd */
297 1.1 cgd void
298 1.10 lukem outfdef(sym_t *fsym, pos_t *posp, int rval, int osdef, sym_t *args)
299 1.1 cgd {
300 1.1 cgd int narg;
301 1.1 cgd sym_t *arg;
302 1.1 cgd
303 1.1 cgd /* reset the buffer */
304 1.1 cgd outclr();
305 1.1 cgd
306 1.1 cgd /*
307 1.1 cgd * line number of .c source, 'd' for declaration, Id of current
308 1.1 cgd * source (.c or .h), and line in current source
309 1.1 cgd *
310 1.1 cgd * we are already at the end of the function. If we are in the
311 1.1 cgd * .c source, posp->p_line is correct, otherwise csrc_pos.p_line
312 1.1 cgd * (for functions defined in header files).
313 1.1 cgd */
314 1.1 cgd if (posp->p_file == csrc_pos.p_file) {
315 1.1 cgd outint(posp->p_line);
316 1.1 cgd } else {
317 1.1 cgd outint(csrc_pos.p_line);
318 1.1 cgd }
319 1.1 cgd outchar('d');
320 1.1 cgd outint(getfnid(posp->p_file));
321 1.1 cgd outchar('.');
322 1.1 cgd outint(posp->p_line);
323 1.1 cgd
324 1.1 cgd /* flags */
325 1.1 cgd
326 1.1 cgd /* both SCANFLIKE and PRINTFLIKE imply VARARGS */
327 1.1 cgd if (prflstrg != -1) {
328 1.1 cgd nvararg = prflstrg;
329 1.1 cgd } else if (scflstrg != -1) {
330 1.1 cgd nvararg = scflstrg;
331 1.1 cgd }
332 1.1 cgd
333 1.1 cgd if (nvararg != -1) {
334 1.1 cgd outchar('v');
335 1.1 cgd outint(nvararg);
336 1.1 cgd }
337 1.1 cgd if (scflstrg != -1) {
338 1.1 cgd outchar('S');
339 1.1 cgd outint(scflstrg);
340 1.1 cgd }
341 1.1 cgd if (prflstrg != -1) {
342 1.1 cgd outchar('P');
343 1.1 cgd outint(prflstrg);
344 1.1 cgd }
345 1.1 cgd nvararg = prflstrg = scflstrg = -1;
346 1.1 cgd
347 1.1 cgd outchar('d');
348 1.1 cgd
349 1.1 cgd if (rval)
350 1.1 cgd /* has return value */
351 1.1 cgd outchar('r');
352 1.1 cgd
353 1.1 cgd if (llibflg)
354 1.1 cgd /*
355 1.1 cgd * mark it as used so lint2 does not complain about
356 1.1 cgd * unused symbols in libraries
357 1.1 cgd */
358 1.1 cgd outchar('u');
359 1.1 cgd
360 1.1 cgd if (osdef)
361 1.1 cgd /* old style function definition */
362 1.1 cgd outchar('o');
363 1.1 cgd
364 1.1 cgd if (fsym->s_scl == STATIC)
365 1.1 cgd outchar('s');
366 1.1 cgd
367 1.1 cgd /* name of function */
368 1.1 cgd outname(fsym->s_name);
369 1.6 cgd
370 1.6 cgd /* renamed name of function, if necessary */
371 1.6 cgd if (fsym->s_rename) {
372 1.6 cgd outchar('r');
373 1.6 cgd outname(fsym->s_rename);
374 1.6 cgd }
375 1.1 cgd
376 1.1 cgd /* argument types and return value */
377 1.1 cgd if (osdef) {
378 1.1 cgd narg = 0;
379 1.1 cgd for (arg = args; arg != NULL; arg = arg->s_nxt)
380 1.1 cgd narg++;
381 1.1 cgd outchar('f');
382 1.1 cgd outint(narg);
383 1.1 cgd for (arg = args; arg != NULL; arg = arg->s_nxt)
384 1.1 cgd outtype(arg->s_type);
385 1.4 jpo outtype(fsym->s_type->t_subt);
386 1.1 cgd } else {
387 1.4 jpo outtype(fsym->s_type);
388 1.1 cgd }
389 1.1 cgd }
390 1.1 cgd
391 1.1 cgd /*
392 1.1 cgd * write out all information necessary for lint2 to check function
393 1.1 cgd * calls
394 1.1 cgd *
395 1.1 cgd * rvused is set if the return value is used (asigned to a variable)
396 1.1 cgd * rvdisc is set if the return value is not used and not ignored
397 1.1 cgd * (casted to void)
398 1.1 cgd */
399 1.1 cgd void
400 1.10 lukem outcall(tnode_t *tn, int rvused, int rvdisc)
401 1.1 cgd {
402 1.1 cgd tnode_t *args, *arg;
403 1.1 cgd int narg, n, i;
404 1.12 thorpej int64_t q;
405 1.1 cgd tspec_t t;
406 1.1 cgd
407 1.1 cgd /* reset buffer */
408 1.1 cgd outclr();
409 1.1 cgd
410 1.1 cgd /*
411 1.1 cgd * line number of .c source, 'c' for function call, Id of current
412 1.1 cgd * source (.c or .h), and line in current source
413 1.1 cgd */
414 1.1 cgd outint(csrc_pos.p_line);
415 1.1 cgd outchar('c');
416 1.1 cgd outint(getfnid(curr_pos.p_file));
417 1.1 cgd outchar('.');
418 1.1 cgd outint(curr_pos.p_line);
419 1.1 cgd
420 1.1 cgd /*
421 1.1 cgd * flags; 'u' and 'i' must be last to make sure a letter
422 1.1 cgd * is between the numeric argument of a flag and the name of
423 1.1 cgd * the function
424 1.1 cgd */
425 1.1 cgd narg = 0;
426 1.1 cgd args = tn->tn_right;
427 1.1 cgd for (arg = args; arg != NULL; arg = arg->tn_right)
428 1.1 cgd narg++;
429 1.1 cgd /* informations about arguments */
430 1.1 cgd for (n = 1; n <= narg; n++) {
431 1.1 cgd /* the last argument is the top one in the tree */
432 1.10 lukem for (i = narg, arg = args; i > n; i--, arg = arg->tn_right)
433 1.10 lukem continue;
434 1.1 cgd arg = arg->tn_left;
435 1.1 cgd if (arg->tn_op == CON) {
436 1.1 cgd if (isityp(t = arg->tn_type->t_tspec)) {
437 1.1 cgd /*
438 1.1 cgd * XXX it would probably be better to
439 1.16 perry * explicitly test the sign
440 1.1 cgd */
441 1.1 cgd if ((q = arg->tn_val->v_quad) == 0) {
442 1.1 cgd /* zero constant */
443 1.1 cgd outchar('z');
444 1.1 cgd } else if (msb(q, t, 0) == 0) {
445 1.1 cgd /* positive if casted to signed */
446 1.1 cgd outchar('p');
447 1.1 cgd } else {
448 1.1 cgd /* negative if casted to signed */
449 1.1 cgd outchar('n');
450 1.1 cgd }
451 1.1 cgd outint(n);
452 1.1 cgd }
453 1.1 cgd } else if (arg->tn_op == AMPER &&
454 1.1 cgd arg->tn_left->tn_op == STRING &&
455 1.1 cgd arg->tn_left->tn_strg->st_tspec == CHAR) {
456 1.1 cgd /* constant string, write all format specifiers */
457 1.1 cgd outchar('s');
458 1.1 cgd outint(n);
459 1.1 cgd outfstrg(arg->tn_left->tn_strg);
460 1.1 cgd }
461 1.1 cgd
462 1.1 cgd }
463 1.1 cgd /* return value discarded/used/ignored */
464 1.1 cgd outchar(rvdisc ? 'd' : (rvused ? 'u' : 'i'));
465 1.1 cgd
466 1.1 cgd /* name of the called function */
467 1.1 cgd outname(tn->tn_left->tn_left->tn_sym->s_name);
468 1.1 cgd
469 1.1 cgd /* types of arguments */
470 1.1 cgd outchar('f');
471 1.1 cgd outint(narg);
472 1.1 cgd for (n = 1; n <= narg; n++) {
473 1.1 cgd /* the last argument is the top one in the tree */
474 1.10 lukem for (i = narg, arg = args; i > n; i--, arg = arg->tn_right)
475 1.10 lukem continue;
476 1.1 cgd outtype(arg->tn_left->tn_type);
477 1.1 cgd }
478 1.1 cgd /* expected type of return value */
479 1.1 cgd outtype(tn->tn_type);
480 1.1 cgd }
481 1.1 cgd
482 1.1 cgd /*
483 1.1 cgd * extracts potential format specifiers for printf() and scanf() and
484 1.1 cgd * writes them, enclosed in "" and qouted if necessary, to the output buffer
485 1.1 cgd */
486 1.1 cgd static void
487 1.10 lukem outfstrg(strg_t *strg)
488 1.1 cgd {
489 1.1 cgd int c, oc, first;
490 1.1 cgd u_char *cp;
491 1.1 cgd
492 1.1 cgd if (strg->st_tspec != CHAR)
493 1.13 christos LERROR("outfstrg()");
494 1.1 cgd
495 1.1 cgd cp = strg->st_cp;
496 1.1 cgd
497 1.1 cgd outchar('"');
498 1.1 cgd
499 1.1 cgd c = *cp++;
500 1.1 cgd
501 1.1 cgd while (c != '\0') {
502 1.1 cgd
503 1.1 cgd if (c != '%') {
504 1.1 cgd c = *cp++;
505 1.1 cgd continue;
506 1.1 cgd }
507 1.1 cgd
508 1.1 cgd outqchar('%');
509 1.1 cgd c = *cp++;
510 1.1 cgd
511 1.1 cgd /* flags for printf and scanf and *-fieldwidth for printf */
512 1.1 cgd while (c != '\0' && (c == '-' || c == '+' || c == ' ' ||
513 1.1 cgd c == '#' || c == '0' || c == '*')) {
514 1.1 cgd outqchar(c);
515 1.1 cgd c = *cp++;
516 1.1 cgd }
517 1.1 cgd
518 1.1 cgd /* numeric field width */
519 1.1 cgd while (c != '\0' && isdigit(c)) {
520 1.1 cgd outqchar(c);
521 1.1 cgd c = *cp++;
522 1.1 cgd }
523 1.1 cgd
524 1.1 cgd /* precision for printf */
525 1.1 cgd if (c == '.') {
526 1.1 cgd outqchar(c);
527 1.1 cgd if ((c = *cp++) == '*') {
528 1.1 cgd outqchar(c);
529 1.1 cgd c = *cp++;
530 1.1 cgd } else {
531 1.1 cgd while (c != '\0' && isdigit(c)) {
532 1.1 cgd outqchar(c);
533 1.1 cgd c = *cp++;
534 1.1 cgd }
535 1.1 cgd }
536 1.1 cgd }
537 1.1 cgd
538 1.1 cgd /* h, l, L and q flags fpr printf and scanf */
539 1.1 cgd if (c == 'h' || c == 'l' || c == 'L' || c == 'q') {
540 1.1 cgd outqchar(c);
541 1.1 cgd c = *cp++;
542 1.1 cgd }
543 1.1 cgd
544 1.1 cgd /*
545 1.1 cgd * The last character. It is always written so we can detect
546 1.1 cgd * invalid format specifiers.
547 1.1 cgd */
548 1.1 cgd if (c != '\0') {
549 1.1 cgd outqchar(c);
550 1.1 cgd oc = c;
551 1.1 cgd c = *cp++;
552 1.1 cgd /*
553 1.1 cgd * handle [ for scanf. [-] means that a minus sign
554 1.1 cgd * was found at an undefined position.
555 1.1 cgd */
556 1.1 cgd if (oc == '[') {
557 1.1 cgd if (c == '^')
558 1.1 cgd c = *cp++;
559 1.1 cgd if (c == ']')
560 1.1 cgd c = *cp++;
561 1.1 cgd first = 1;
562 1.1 cgd while (c != '\0' && c != ']') {
563 1.1 cgd if (c == '-') {
564 1.1 cgd if (!first && *cp != ']')
565 1.1 cgd outqchar(c);
566 1.1 cgd }
567 1.1 cgd first = 0;
568 1.1 cgd c = *cp++;
569 1.1 cgd }
570 1.1 cgd if (c == ']') {
571 1.1 cgd outqchar(c);
572 1.1 cgd c = *cp++;
573 1.1 cgd }
574 1.1 cgd }
575 1.1 cgd }
576 1.1 cgd
577 1.1 cgd }
578 1.1 cgd
579 1.1 cgd outchar('"');
580 1.1 cgd }
581 1.1 cgd
582 1.1 cgd /*
583 1.1 cgd * writes a record if sym was used
584 1.1 cgd */
585 1.1 cgd void
586 1.10 lukem outusg(sym_t *sym)
587 1.1 cgd {
588 1.1 cgd /* reset buffer */
589 1.1 cgd outclr();
590 1.1 cgd
591 1.1 cgd /*
592 1.1 cgd * line number of .c source, 'u' for used, Id of current
593 1.1 cgd * source (.c or .h), and line in current source
594 1.1 cgd */
595 1.1 cgd outint(csrc_pos.p_line);
596 1.1 cgd outchar('u');
597 1.1 cgd outint(getfnid(curr_pos.p_file));
598 1.1 cgd outchar('.');
599 1.1 cgd outint(curr_pos.p_line);
600 1.1 cgd
601 1.1 cgd /* necessary to delimit both numbers */
602 1.1 cgd outchar('x');
603 1.1 cgd
604 1.1 cgd /* Den Namen des Symbols ausgeben */
605 1.1 cgd outname(sym->s_name);
606 1.1 cgd }
607