Deleted Added
full compact
read.c (80284) read.c (91592)
1/* $NetBSD: read.c,v 1.2 1995/07/03 21:24:59 cgd Exp $ */
1/* $NetBSD: read.c,v 1.12 2002/01/21 19:49:52 tv Exp $ */
2
3/*
2
3/*
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.

--- 14 unchanged lines hidden (view full) ---

26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
5 * Copyright (c) 1994, 1995 Jochen Pohl
6 * All Rights Reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.

--- 14 unchanged lines hidden (view full) ---

27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
34#ifndef lint
35static const char rcsid[] =
36 "$FreeBSD: head/usr.bin/xlint/lint2/read.c 80284 2001-07-24 14:02:07Z obrien $";
35#include <sys/cdefs.h>
36#if defined(__RCSID) && !defined(lint)
37__RCSID("$NetBSD: read.c,v 1.12 2002/01/21 19:49:52 tv Exp $");
37#endif
38#endif
39__FBSDID("$FreeBSD: head/usr.bin/xlint/lint2/read.c 91592 2002-03-03 15:12:50Z markm $");
38
40
41#include <ctype.h>
42#include <limits.h>
39#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
43#include <stdio.h>
44#include <stdlib.h>
45#include <string.h>
42#include <ctype.h>
43#include <limits.h>
44#include <err.h>
45
46#include "lint2.h"
47
48
49/* index of current (included) source file */
50static int srcfile;
51
52/*

--- 21 unchanged lines hidden (view full) ---

74 const char *th_name;
75 u_short th_idx;
76 struct thtab *th_nxt;
77} thtab_t;
78static thtab_t **thtab; /* hash table */
79type_t **tlst; /* array for indexed access */
80static size_t tlstlen; /* length of tlst */
81
46
47#include "lint2.h"
48
49
50/* index of current (included) source file */
51static int srcfile;
52
53/*

--- 21 unchanged lines hidden (view full) ---

75 const char *th_name;
76 u_short th_idx;
77 struct thtab *th_nxt;
78} thtab_t;
79static thtab_t **thtab; /* hash table */
80type_t **tlst; /* array for indexed access */
81static size_t tlstlen; /* length of tlst */
82
83static hte_t **renametab;
84
82/* index of current C source file (as spezified at the command line) */
83static int csrcfile;
84
85
85/* index of current C source file (as spezified at the command line) */
86static int csrcfile;
87
88
86static void inperr __P((void));
87static void setsrc __P((const char *));
88static void setfnid __P((int, const char *));
89static void funccall __P((pos_t *, const char *));
90static void decldef __P((pos_t *, const char *));
91static void usedsym __P((pos_t *, const char *));
92static u_short inptype __P((const char *, const char **));
93static int gettlen __P((const char *, const char **));
94static u_short findtype __P((const char *, size_t, int));
95static u_short storetyp __P((type_t *, const char *, size_t, int));
96static int thash __P((const char *, size_t));
97static char *inpqstrg __P((const char *, const char **));
98static const char *inpname __P((const char *, const char **));
99static int getfnidx __P((const char *));
89static void inperr(void);
90static void setsrc(const char *);
91static void setfnid(int, const char *);
92static void funccall(pos_t *, const char *);
93static void decldef(pos_t *, const char *);
94static void usedsym(pos_t *, const char *);
95static u_short inptype(const char *, const char **);
96static int gettlen(const char *, const char **);
97static u_short findtype(const char *, size_t, int);
98static u_short storetyp(type_t *, const char *, size_t, int);
99static int thash(const char *, size_t);
100static char *inpqstrg(const char *, const char **);
101static const char *inpname(const char *, const char **);
102static int getfnidx(const char *);
100
101void
103
104void
102readfile(name)
103 const char *name;
105readfile(const char *name)
104{
105 FILE *inp;
106 size_t len;
107 const char *cp;
106{
107 FILE *inp;
108 size_t len;
109 const char *cp;
108 char *line, *eptr, rt;
110 char *line, *eptr, rt = '\0';
109 int cline, isrc, iline;
110 pos_t pos;
111
112 if (inpfns == NULL)
113 if ((inpfns = calloc(ninpfns = 128, sizeof (short))) == NULL)
114 nomem();
115 if (fnames == NULL)
116 if ((fnames = calloc(nfnames = 256, sizeof (char *))) == NULL)
117 nomem();
118 if (tlstlen == 0)
119 if ((tlst = calloc(tlstlen = 256, sizeof (type_t *))) == NULL)
120 nomem();
121 if (thtab == NULL)
122 if ((thtab = calloc(THSHSIZ2, sizeof (thtab_t))) == NULL)
123 nomem();
124
111 int cline, isrc, iline;
112 pos_t pos;
113
114 if (inpfns == NULL)
115 if ((inpfns = calloc(ninpfns = 128, sizeof (short))) == NULL)
116 nomem();
117 if (fnames == NULL)
118 if ((fnames = calloc(nfnames = 256, sizeof (char *))) == NULL)
119 nomem();
120 if (tlstlen == 0)
121 if ((tlst = calloc(tlstlen = 256, sizeof (type_t *))) == NULL)
122 nomem();
123 if (thtab == NULL)
124 if ((thtab = calloc(THSHSIZ2, sizeof (thtab_t))) == NULL)
125 nomem();
126
127 _inithash(&renametab);
128
125 srcfile = getfnidx(name);
126
127 if ((inp = fopen(name, "r")) == NULL)
128 err(1, "cannot open %s", name);
129
130 while ((line = fgetln(inp, &len)) != NULL) {
131
132 if (len == 0 || line[len - 1] != '\n')

--- 60 unchanged lines hidden (view full) ---

193 usedsym(&pos, cp);
194 break;
195 default:
196 inperr();
197 }
198
199 }
200
129 srcfile = getfnidx(name);
130
131 if ((inp = fopen(name, "r")) == NULL)
132 err(1, "cannot open %s", name);
133
134 while ((line = fgetln(inp, &len)) != NULL) {
135
136 if (len == 0 || line[len - 1] != '\n')

--- 60 unchanged lines hidden (view full) ---

197 usedsym(&pos, cp);
198 break;
199 default:
200 inperr();
201 }
202
203 }
204
205 _destroyhash(renametab);
206
201 if (ferror(inp))
202 err(1, "read error on %s", name);
203
204 (void)fclose(inp);
205}
206
207
208static void
207 if (ferror(inp))
208 err(1, "read error on %s", name);
209
210 (void)fclose(inp);
211}
212
213
214static void
209inperr()
215inperr(void)
210{
216{
217
211 errx(1, "input file error: %s", fnames[srcfile]);
212}
213
214/*
215 * Set the name of the C source file of the .ln file which is
216 * currently read.
217 */
218static void
218 errx(1, "input file error: %s", fnames[srcfile]);
219}
220
221/*
222 * Set the name of the C source file of the .ln file which is
223 * currently read.
224 */
225static void
219setsrc(cp)
220 const char *cp;
226setsrc(const char *cp)
221{
227{
228
222 csrcfile = getfnidx(cp);
223}
224
225/*
226 * setfnid() gets as input an index as used in an input file and the
229 csrcfile = getfnidx(cp);
230}
231
232/*
233 * setfnid() gets as input an index as used in an input file and the
227 * associated file name. If neccessary, it creates a new lint2 file
234 * associated file name. If necessary, it creates a new lint2 file
228 * name index for this file name and creates the mapping of the index
229 * as used in the input file to the index used in lint2.
230 */
231static void
235 * name index for this file name and creates the mapping of the index
236 * as used in the input file to the index used in lint2.
237 */
238static void
232setfnid(fid, cp)
233 int fid;
234 const char *cp;
239setfnid(int fid, const char *cp)
235{
240{
241
236 if (fid == -1)
237 inperr();
238
239 if (fid >= ninpfns) {
240 if ((inpfns = realloc(inpfns, (ninpfns * 2) * sizeof (short)))
241 == NULL)
242 nomem();
243 (void)memset(inpfns + ninpfns, 0, ninpfns * sizeof (short));

--- 7 unchanged lines hidden (view full) ---

251 errx(1, "internal error: setfnid()");
252 inpfns[fid] = (u_short)getfnidx(cp);
253}
254
255/*
256 * Process a function call record (c-record).
257 */
258static void
242 if (fid == -1)
243 inperr();
244
245 if (fid >= ninpfns) {
246 if ((inpfns = realloc(inpfns, (ninpfns * 2) * sizeof (short)))
247 == NULL)
248 nomem();
249 (void)memset(inpfns + ninpfns, 0, ninpfns * sizeof (short));

--- 7 unchanged lines hidden (view full) ---

257 errx(1, "internal error: setfnid()");
258 inpfns[fid] = (u_short)getfnidx(cp);
259}
260
261/*
262 * Process a function call record (c-record).
263 */
264static void
259funccall(posp, cp)
260 pos_t *posp;
261 const char *cp;
265funccall(pos_t *posp, const char *cp)
262{
263 arginf_t *ai, **lai;
264 char c, *eptr;
265 int rused, rdisc;
266 hte_t *hte;
267 fcall_t *fcall;
266{
267 arginf_t *ai, **lai;
268 char c, *eptr;
269 int rused, rdisc;
270 hte_t *hte;
271 fcall_t *fcall;
272 const char *name;
268
269 fcall = xalloc(sizeof (fcall_t));
270 STRUCT_ASSIGN(fcall->f_pos, *posp);
271
272 /* read flags */
273 rused = rdisc = 0;
274 lai = &fcall->f_args;
275 while ((c = *cp) == 'u' || c == 'i' || c == 'd' ||

--- 37 unchanged lines hidden (view full) ---

313 lai = &ai->a_nxt;
314 break;
315 }
316 }
317 fcall->f_rused = rused;
318 fcall->f_rdisc = rdisc;
319
320 /* read name of function */
273
274 fcall = xalloc(sizeof (fcall_t));
275 STRUCT_ASSIGN(fcall->f_pos, *posp);
276
277 /* read flags */
278 rused = rdisc = 0;
279 lai = &fcall->f_args;
280 while ((c = *cp) == 'u' || c == 'i' || c == 'd' ||

--- 37 unchanged lines hidden (view full) ---

318 lai = &ai->a_nxt;
319 break;
320 }
321 }
322 fcall->f_rused = rused;
323 fcall->f_rdisc = rdisc;
324
325 /* read name of function */
321 hte = hsearch(inpname(cp, &cp), 1);
326 name = inpname(cp, &cp);
327
328 /* first look it up in the renaming table, then in the normal table */
329 hte = _hsearch(renametab, name, 0);
330 if (hte != NULL)
331 hte = hte->h_hte;
332 else
333 hte = hsearch(name, 1);
322 hte->h_used = 1;
323
324 fcall->f_type = inptype(cp, &cp);
325
326 *hte->h_lcall = fcall;
327 hte->h_lcall = &fcall->f_nxt;
328
329 if (*cp != '\0')
330 inperr();
331}
332
333/*
334 * Process a declaration or definition (d-record).
335 */
336static void
334 hte->h_used = 1;
335
336 fcall->f_type = inptype(cp, &cp);
337
338 *hte->h_lcall = fcall;
339 hte->h_lcall = &fcall->f_nxt;
340
341 if (*cp != '\0')
342 inperr();
343}
344
345/*
346 * Process a declaration or definition (d-record).
347 */
348static void
337decldef(posp, cp)
338 pos_t *posp;
339 const char *cp;
349decldef(pos_t *posp, const char *cp)
340{
341 sym_t *symp, sym;
350{
351 sym_t *symp, sym;
342 char c, *ep;
343 int used;
344 hte_t *hte;
352 char c, *ep, *pos1;
353 int used, renamed;
354 hte_t *hte, *renamehte = NULL;
355 const char *name, *rename;
345
346 (void)memset(&sym, 0, sizeof (sym));
347 STRUCT_ASSIGN(sym.s_pos, *posp);
348 sym.s_def = NODECL;
349
350 used = 0;
351
352 while ((c = *cp) == 't' || c == 'd' || c == 'e' || c == 'u' ||

--- 61 unchanged lines hidden (view full) ---

414 sym.s_nscfl = (short)strtol(cp, &ep, 10);
415 if (cp == ep)
416 inperr();
417 cp = ep;
418 break;
419 }
420 }
421
356
357 (void)memset(&sym, 0, sizeof (sym));
358 STRUCT_ASSIGN(sym.s_pos, *posp);
359 sym.s_def = NODECL;
360
361 used = 0;
362
363 while ((c = *cp) == 't' || c == 'd' || c == 'e' || c == 'u' ||

--- 61 unchanged lines hidden (view full) ---

425 sym.s_nscfl = (short)strtol(cp, &ep, 10);
426 if (cp == ep)
427 inperr();
428 cp = ep;
429 break;
430 }
431 }
432
422 /* read symbol name */
423 hte = hsearch(inpname(cp, &cp), 1);
433 /* read symbol name, doing renaming if necessary */
434 name = inpname(cp, &cp);
435 renamed = 0;
436 if (*cp == 'r') {
437 cp++;
438 name = xstrdup(name);
439 rename = inpname(cp, &cp);
440
441 /* enter it and see if it's already been renamed */
442 renamehte = _hsearch(renametab, name, 1);
443 if (renamehte->h_hte == NULL) {
444 hte = hsearch(rename, 1);
445 renamehte->h_hte = hte;
446 renamed = 1;
447 } else if (strcmp((hte = renamehte->h_hte)->h_name, rename)) {
448 pos1 = xstrdup(mkpos(&renamehte->h_syms->s_pos));
449 /* %s renamed multiple times\t%s :: %s */
450 msg(18, name, pos1, mkpos(&sym.s_pos));
451 free(pos1);
452 }
453 free((char *)name);
454 } else {
455 /* it might be a previously-done rename */
456 hte = _hsearch(renametab, name, 0);
457 if (hte != NULL)
458 hte = hte->h_hte;
459 else
460 hte = hsearch(name, 1);
461 }
424 hte->h_used |= used;
425 if (sym.s_def == DEF || sym.s_def == TDEF)
426 hte->h_def = 1;
427
428 sym.s_type = inptype(cp, &cp);
429
430 /*
431 * Allocate memory for this symbol only if it was not already

--- 19 unchanged lines hidden (view full) ---

451 symp = xalloc(sizeof (sym_t));
452 STRUCT_ASSIGN(*symp, sym);
453 } else {
454 symp = xalloc(sizeof (symp->s_s));
455 STRUCT_ASSIGN(symp->s_s, sym.s_s);
456 }
457 *hte->h_lsym = symp;
458 hte->h_lsym = &symp->s_nxt;
462 hte->h_used |= used;
463 if (sym.s_def == DEF || sym.s_def == TDEF)
464 hte->h_def = 1;
465
466 sym.s_type = inptype(cp, &cp);
467
468 /*
469 * Allocate memory for this symbol only if it was not already

--- 19 unchanged lines hidden (view full) ---

489 symp = xalloc(sizeof (sym_t));
490 STRUCT_ASSIGN(*symp, sym);
491 } else {
492 symp = xalloc(sizeof (symp->s_s));
493 STRUCT_ASSIGN(symp->s_s, sym.s_s);
494 }
495 *hte->h_lsym = symp;
496 hte->h_lsym = &symp->s_nxt;
497
498 /* XXX hack so we can remember where a symbol was renamed */
499 if (renamed)
500 renamehte->h_syms = symp;
459 }
460
461 if (*cp != '\0')
462 inperr();
463}
464
465/*
466 * Read an u-record (emited by lint1 if a symbol was used).
467 */
468static void
501 }
502
503 if (*cp != '\0')
504 inperr();
505}
506
507/*
508 * Read an u-record (emited by lint1 if a symbol was used).
509 */
510static void
469usedsym(posp, cp)
470 pos_t *posp;
471 const char *cp;
511usedsym(pos_t *posp, const char *cp)
472{
473 usym_t *usym;
474 hte_t *hte;
512{
513 usym_t *usym;
514 hte_t *hte;
515 const char *name;
475
476 usym = xalloc(sizeof (usym_t));
477 STRUCT_ASSIGN(usym->u_pos, *posp);
478
479 /* needed as delimiter between two numbers */
480 if (*cp++ != 'x')
481 inperr();
482
516
517 usym = xalloc(sizeof (usym_t));
518 STRUCT_ASSIGN(usym->u_pos, *posp);
519
520 /* needed as delimiter between two numbers */
521 if (*cp++ != 'x')
522 inperr();
523
483 hte = hsearch(inpname(cp, &cp), 1);
524 name = inpname(cp, &cp);
525 hte = _hsearch(renametab, name, 0);
526 if (hte != NULL)
527 hte = hte->h_hte;
528 else
529 hte = hsearch(name, 1);
484 hte->h_used = 1;
485
486 *hte->h_lusym = usym;
487 hte->h_lusym = &usym->u_nxt;
488}
489
490/*
491 * Read a type and return the index of this type.
492 */
493static u_short
530 hte->h_used = 1;
531
532 *hte->h_lusym = usym;
533 hte->h_lusym = &usym->u_nxt;
534}
535
536/*
537 * Read a type and return the index of this type.
538 */
539static u_short
494inptype(cp, epp)
495 const char *cp, **epp;
540inptype(const char *cp, const char **epp)
496{
497 char c, s, *eptr;
498 const char *ep;
499 type_t *tp;
541{
542 char c, s, *eptr;
543 const char *ep;
544 type_t *tp;
500 int narg, i, osdef;
545 int narg, i, osdef = 0;
501 size_t tlen;
502 u_short tidx;
503 int h;
504
505 /* If we have this type already, return it's index. */
506 tlen = gettlen(cp, &ep);
507 h = thash(cp, tlen);
508 if ((tidx = findtype(cp, tlen, h)) != 0) {

--- 94 unchanged lines hidden (view full) ---

603 break;
604 case ENUM:
605 tp->t_tspec = INT;
606 tp->t_isenum = 1;
607 /* FALLTHROUGH */
608 case STRUCT:
609 case UNION:
610 switch (*cp++) {
546 size_t tlen;
547 u_short tidx;
548 int h;
549
550 /* If we have this type already, return it's index. */
551 tlen = gettlen(cp, &ep);
552 h = thash(cp, tlen);
553 if ((tidx = findtype(cp, tlen, h)) != 0) {

--- 94 unchanged lines hidden (view full) ---

648 break;
649 case ENUM:
650 tp->t_tspec = INT;
651 tp->t_isenum = 1;
652 /* FALLTHROUGH */
653 case STRUCT:
654 case UNION:
655 switch (*cp++) {
611 case '0':
612 break;
613 case '1':
614 tp->t_istag = 1;
615 tp->t_tag = hsearch(inpname(cp, &cp), 1);
616 break;
617 case '2':
618 tp->t_istynam = 1;
619 tp->t_tynam = hsearch(inpname(cp, &cp), 1);
620 break;
656 case '1':
657 tp->t_istag = 1;
658 tp->t_tag = hsearch(inpname(cp, &cp), 1);
659 break;
660 case '2':
661 tp->t_istynam = 1;
662 tp->t_tynam = hsearch(inpname(cp, &cp), 1);
663 break;
664 case '3':
665 tp->t_isuniqpos = 1;
666 tp->t_uniqpos.p_line = strtol(cp, &eptr, 10);
667 cp = eptr;
668 cp++;
669 /* xlate to 'global' file name. */
670 tp->t_uniqpos.p_file =
671 addoutfile(inpfns[strtol(cp, &eptr, 10)]);
672 cp = eptr;
673 cp++;
674 tp->t_uniqpos.p_uniq = strtol(cp, &eptr, 10);
675 cp = eptr;
676 break;
621 }
622 break;
677 }
678 break;
623 /* LINTED (enumeration value(s) not handled in switch) */
624 default:
679 case LONG:
680 case VOID:
681 case LDOUBLE:
682 case DOUBLE:
683 case FLOAT:
684 case UQUAD:
685 case QUAD:
686 case ULONG:
687 case UINT:
688 case INT:
689 case USHORT:
690 case SHORT:
691 case UCHAR:
692 case SCHAR:
693 case CHAR:
694 case UNSIGN:
695 case SIGNED:
696 case NOTSPEC:
697 break;
698 case NTSPEC:
699 abort();
625 }
626
627 *epp = cp;
628 return (tidx);
629}
630
631/*
632 * Get the length of a type string.
633 */
634static int
700 }
701
702 *epp = cp;
703 return (tidx);
704}
705
706/*
707 * Get the length of a type string.
708 */
709static int
635gettlen(cp, epp)
636 const char *cp, **epp;
710gettlen(const char *cp, const char **epp)
637{
638 const char *cp1;
639 char c, s, *eptr;
640 tspec_t t;
641 int narg, i, cm, vm;
642
643 cp1 = cp;
644

--- 128 unchanged lines hidden (view full) ---

773 }
774 }
775 (void)gettlen(cp, &cp);
776 break;
777 case ENUM:
778 case STRUCT:
779 case UNION:
780 switch (*cp++) {
711{
712 const char *cp1;
713 char c, s, *eptr;
714 tspec_t t;
715 int narg, i, cm, vm;
716
717 cp1 = cp;
718

--- 128 unchanged lines hidden (view full) ---

847 }
848 }
849 (void)gettlen(cp, &cp);
850 break;
851 case ENUM:
852 case STRUCT:
853 case UNION:
854 switch (*cp++) {
781 case '0':
782 break;
783 case '1':
784 (void)inpname(cp, &cp);
785 break;
786 case '2':
787 (void)inpname(cp, &cp);
788 break;
855 case '1':
856 (void)inpname(cp, &cp);
857 break;
858 case '2':
859 (void)inpname(cp, &cp);
860 break;
861 case '3':
862 /* unique position: line.file.uniquifier */
863 (void)strtol(cp, &eptr, 10);
864 if (cp == eptr)
865 inperr();
866 cp = eptr;
867 if (*cp++ != '.')
868 inperr();
869 (void)strtol(cp, &eptr, 10);
870 if (cp == eptr)
871 inperr();
872 cp = eptr;
873 if (*cp++ != '.')
874 inperr();
875 (void)strtol(cp, &eptr, 10);
876 if (cp == eptr)
877 inperr();
878 cp = eptr;
879 break;
789 default:
790 inperr();
791 }
792 break;
880 default:
881 inperr();
882 }
883 break;
793 /* LINTED (enumeration value(s) not handled in switch) */
794 default:
884 case FLOAT:
885 case USHORT:
886 case SHORT:
887 case UCHAR:
888 case SCHAR:
889 case CHAR:
890 case UNSIGN:
891 case SIGNED:
892 case NOTSPEC:
893 case INT:
894 case UINT:
895 case DOUBLE:
896 case LDOUBLE:
897 case VOID:
898 case ULONG:
899 case QUAD:
900 case UQUAD:
901 case LONG:
902 break;
903 case NTSPEC:
904 abort();
795 }
796
797 *epp = cp;
798 return (cp - cp1);
799}
800
801/*
802 * Search a type by it's type string.
803 */
804static u_short
905 }
906
907 *epp = cp;
908 return (cp - cp1);
909}
910
911/*
912 * Search a type by it's type string.
913 */
914static u_short
805findtype(cp, len, h)
806 const char *cp;
807 size_t len;
808 int h;
915findtype(const char *cp, size_t len, int h)
809{
810 thtab_t *thte;
811
812 for (thte = thtab[h]; thte != NULL; thte = thte->th_nxt) {
813 if (strncmp(thte->th_name, cp, len) != 0)
814 continue;
815 if (thte->th_name[len] == '\0')
816 return (thte->th_idx);
817 }
818
819 return (0);
820}
821
822/*
823 * Store a type and it's type string so we can later share this type
824 * if we read the same type string from the input file.
825 */
826static u_short
916{
917 thtab_t *thte;
918
919 for (thte = thtab[h]; thte != NULL; thte = thte->th_nxt) {
920 if (strncmp(thte->th_name, cp, len) != 0)
921 continue;
922 if (thte->th_name[len] == '\0')
923 return (thte->th_idx);
924 }
925
926 return (0);
927}
928
929/*
930 * Store a type and it's type string so we can later share this type
931 * if we read the same type string from the input file.
932 */
933static u_short
827storetyp(tp, cp, len, h)
828 type_t *tp;
829 const char *cp;
830 size_t len;
831 int h;
934storetyp(type_t *tp, const char *cp, size_t len, int h)
832{
935{
833 /* 0 ist reserved */
834 static u_int tidx = 1;
936 static u_int tidx = 1; /* 0 is reserved */
835 thtab_t *thte;
836 char *name;
837
838 if (tidx >= USHRT_MAX)
839 errx(1, "sorry, too many types");
840
841 if (tidx == tlstlen - 1) {
842 if ((tlst = realloc(tlst, (tlstlen * 2) * sizeof (type_t *)))

--- 18 unchanged lines hidden (view full) ---

861
862 return ((u_short)tidx++);
863}
864
865/*
866 * Hash function for types
867 */
868static int
937 thtab_t *thte;
938 char *name;
939
940 if (tidx >= USHRT_MAX)
941 errx(1, "sorry, too many types");
942
943 if (tidx == tlstlen - 1) {
944 if ((tlst = realloc(tlst, (tlstlen * 2) * sizeof (type_t *)))

--- 18 unchanged lines hidden (view full) ---

963
964 return ((u_short)tidx++);
965}
966
967/*
968 * Hash function for types
969 */
970static int
869thash(s, len)
870 const char *s;
871 size_t len;
971thash(const char *s, size_t len)
872{
873 u_int v;
874
875 v = 0;
876 while (len-- != 0) {
877 v = (v << sizeof (v)) + (u_char)*s++;
878 v ^= v >> (sizeof (v) * CHAR_BIT - sizeof (v));
879 }
880 return (v % THSHSIZ2);
881}
882
883/*
884 * Read a string enclosed by "". This string may contain quoted chars.
885 */
886static char *
972{
973 u_int v;
974
975 v = 0;
976 while (len-- != 0) {
977 v = (v << sizeof (v)) + (u_char)*s++;
978 v ^= v >> (sizeof (v) * CHAR_BIT - sizeof (v));
979 }
980 return (v % THSHSIZ2);
981}
982
983/*
984 * Read a string enclosed by "". This string may contain quoted chars.
985 */
986static char *
887inpqstrg(src, epp)
888 const char *src, **epp;
987inpqstrg(const char *src, const char **epp)
889{
890 char *strg, *dst;
891 size_t slen;
892 int c;
893 int v;
894
895 if ((dst = strg = malloc(slen = 32)) == NULL)
896 nomem();

--- 10 unchanged lines hidden (view full) ---

907 switch (c) {
908 case 'n':
909 c = '\n';
910 break;
911 case 't':
912 c = '\t';
913 break;
914 case 'v':
988{
989 char *strg, *dst;
990 size_t slen;
991 int c;
992 int v;
993
994 if ((dst = strg = malloc(slen = 32)) == NULL)
995 nomem();

--- 10 unchanged lines hidden (view full) ---

1006 switch (c) {
1007 case 'n':
1008 c = '\n';
1009 break;
1010 case 't':
1011 c = '\t';
1012 break;
1013 case 'v':
915#ifdef __STDC__
916 c = '\v';
1014 c = '\v';
917#else
918 c = '\013';
919#endif
920 break;
921 case 'b':
922 c = '\b';
923 break;
924 case 'r':
925 c = '\r';
926 break;
927 case 'f':
928 c = '\f';
929 break;
930 case 'a':
1015 break;
1016 case 'b':
1017 c = '\b';
1018 break;
1019 case 'r':
1020 c = '\r';
1021 break;
1022 case 'f':
1023 c = '\f';
1024 break;
1025 case 'a':
931#ifdef __STDC__
932 c = '\a';
1026 c = '\a';
933#else
934 c = '\007';
935#endif
936 break;
937 case '\\':
938 c = '\\';
939 break;
940 case '"':
941 c = '"';
942 break;
943 case '\'':

--- 29 unchanged lines hidden (view full) ---

973 *epp = src;
974 return (strg);
975}
976
977/*
978 * Read the name of a symbol in static memory.
979 */
980static const char *
1027 break;
1028 case '\\':
1029 c = '\\';
1030 break;
1031 case '"':
1032 c = '"';
1033 break;
1034 case '\'':

--- 29 unchanged lines hidden (view full) ---

1064 *epp = src;
1065 return (strg);
1066}
1067
1068/*
1069 * Read the name of a symbol in static memory.
1070 */
1071static const char *
981inpname(cp, epp)
982 const char *cp, **epp;
1072inpname(const char *cp, const char **epp)
983{
984 static char *buf;
985 static size_t blen = 0;
986 size_t len, i;
987 char *eptr, c;
988
989 len = (int)strtol(cp, &eptr, 10);
990 if (cp == eptr)
991 inperr();
992 cp = eptr;
993 if (len + 1 > blen)
994 if ((buf = realloc(buf, blen = len + 1)) == NULL)
995 nomem();
996 for (i = 0; i < len; i++) {
997 c = *cp++;
1073{
1074 static char *buf;
1075 static size_t blen = 0;
1076 size_t len, i;
1077 char *eptr, c;
1078
1079 len = (int)strtol(cp, &eptr, 10);
1080 if (cp == eptr)
1081 inperr();
1082 cp = eptr;
1083 if (len + 1 > blen)
1084 if ((buf = realloc(buf, blen = len + 1)) == NULL)
1085 nomem();
1086 for (i = 0; i < len; i++) {
1087 c = *cp++;
998 if (!isalnum(c) && c != '_')
1088 if (!isalnum((unsigned char)c) && c != '_')
999 inperr();
1000 buf[i] = c;
1001 }
1002 buf[i] = '\0';
1003
1004 *epp = cp;
1005 return (buf);
1006}
1007
1008/*
1009 * Return the index of a file name. If the name cannot be found, create
1010 * a new entry and return the index of the newly created entry.
1011 */
1012static int
1089 inperr();
1090 buf[i] = c;
1091 }
1092 buf[i] = '\0';
1093
1094 *epp = cp;
1095 return (buf);
1096}
1097
1098/*
1099 * Return the index of a file name. If the name cannot be found, create
1100 * a new entry and return the index of the newly created entry.
1101 */
1102static int
1013getfnidx(fn)
1014 const char *fn;
1103getfnidx(const char *fn)
1015{
1016 int i;
1017
1018 /* 0 ist reserved */
1019 for (i = 1; fnames[i] != NULL; i++) {
1020 if (strcmp(fnames[i], fn) == 0)
1021 break;
1022 }

--- 12 unchanged lines hidden (view full) ---

1035 nomem();
1036 return (i);
1037}
1038
1039/*
1040 * Separate symbols with static and external linkage.
1041 */
1042void
1104{
1105 int i;
1106
1107 /* 0 ist reserved */
1108 for (i = 1; fnames[i] != NULL; i++) {
1109 if (strcmp(fnames[i], fn) == 0)
1110 break;
1111 }

--- 12 unchanged lines hidden (view full) ---

1124 nomem();
1125 return (i);
1126}
1127
1128/*
1129 * Separate symbols with static and external linkage.
1130 */
1131void
1043mkstatic(hte)
1044 hte_t *hte;
1132mkstatic(hte_t *hte)
1045{
1046 sym_t *sym1, **symp, *sym;
1047 fcall_t **callp, *call;
1048 usym_t **usymp, *usym;
1049 hte_t *nhte;
1050 int ofnd;
1051
1052 /* Look for first static definition */

--- 27 unchanged lines hidden (view full) ---

1080 }
1081
1082 /*
1083 * Create a new hash table entry
1084 *
1085 * XXX this entry should be put at the beginning of the list to
1086 * avoid to process the same symbol twice.
1087 */
1133{
1134 sym_t *sym1, **symp, *sym;
1135 fcall_t **callp, *call;
1136 usym_t **usymp, *usym;
1137 hte_t *nhte;
1138 int ofnd;
1139
1140 /* Look for first static definition */

--- 27 unchanged lines hidden (view full) ---

1168 }
1169
1170 /*
1171 * Create a new hash table entry
1172 *
1173 * XXX this entry should be put at the beginning of the list to
1174 * avoid to process the same symbol twice.
1175 */
1088 for (nhte = hte; nhte->h_link != NULL; nhte = nhte->h_link) ;
1089 nhte->h_link = xalloc(sizeof (hte_t));
1176 for (nhte = hte; nhte->h_link != NULL; nhte = nhte->h_link)
1177 continue;
1178 nhte->h_link = xmalloc(sizeof (hte_t));
1090 nhte = nhte->h_link;
1091 nhte->h_name = hte->h_name;
1179 nhte = nhte->h_link;
1180 nhte->h_name = hte->h_name;
1092 nhte->h_static = 1;
1093 nhte->h_used = 1;
1094 nhte->h_def = 1; /* error in lint1 */
1181 nhte->h_used = 1;
1182 nhte->h_def = 1; /* error in lint1 */
1183 nhte->h_static = 1;
1184 nhte->h_syms = NULL;
1095 nhte->h_lsym = &nhte->h_syms;
1185 nhte->h_lsym = &nhte->h_syms;
1186 nhte->h_calls = NULL;
1096 nhte->h_lcall = &nhte->h_calls;
1187 nhte->h_lcall = &nhte->h_calls;
1188 nhte->h_usyms = NULL;
1097 nhte->h_lusym = &nhte->h_usyms;
1189 nhte->h_lusym = &nhte->h_usyms;
1190 nhte->h_link = NULL;
1191 nhte->h_hte = NULL;
1098
1099 /*
1100 * move all symbols used in this translation unit into the new
1101 * hash table entry.
1102 */
1103 for (symp = &hte->h_syms; (sym = *symp) != NULL; ) {
1104 if (sym->s_pos.p_src == sym1->s_pos.p_src) {
1105 sym->s_static = 1;

--- 46 unchanged lines hidden ---
1192
1193 /*
1194 * move all symbols used in this translation unit into the new
1195 * hash table entry.
1196 */
1197 for (symp = &hte->h_syms; (sym = *symp) != NULL; ) {
1198 if (sym->s_pos.p_src == sym1->s_pos.p_src) {
1199 sym->s_static = 1;

--- 46 unchanged lines hidden ---