Deleted Added
full compact
read.c (256281) read.c (281168)
1/* $NetBSD: read.c,v 1.12 2002/01/21 19:49:52 tv Exp $ */
1/* $NetBSD: read.c,v 1.19 2007/09/28 21:53:50 uwe Exp $ */
2
3/*
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
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

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

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
35#include <sys/cdefs.h>
36#if defined(__RCSID) && !defined(lint)
2
3/*
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
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

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

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
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__RCSID("$NetBSD: read.c,v 1.19 2007/09/28 21:53:50 uwe Exp $");
38#endif
38#endif
39__FBSDID("$FreeBSD: stable/10/usr.bin/xlint/lint2/read.c 228992 2011-12-30 11:02:40Z uqs $");
39__FBSDID("$FreeBSD: stable/10/usr.bin/xlint/lint2/read.c 281168 2015-04-06 19:56:27Z pfg $");
40
41#include <ctype.h>
42#include <err.h>
43#include <limits.h>
44#include <stdio.h>
45#include <stdlib.h>
46#include <string.h>
47

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

82static size_t tlstlen; /* length of tlst */
83
84static hte_t **renametab;
85
86/* index of current C source file (as spezified at the command line) */
87static int csrcfile;
88
89
40
41#include <ctype.h>
42#include <err.h>
43#include <limits.h>
44#include <stdio.h>
45#include <stdlib.h>
46#include <string.h>
47

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

82static size_t tlstlen; /* length of tlst */
83
84static hte_t **renametab;
85
86/* index of current C source file (as spezified at the command line) */
87static int csrcfile;
88
89
90static void inperr(void);
90#define inperr() inperror(__FILE__, __LINE__)
91static void inperror(const char *, size_t);
91static void setsrc(const char *);
92static void setfnid(int, const char *);
93static void funccall(pos_t *, const char *);
94static void decldef(pos_t *, const char *);
95static void usedsym(pos_t *, const char *);
96static u_short inptype(const char *, const char **);
97static int gettlen(const char *, const char **);
98static u_short findtype(const char *, size_t, int);

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

208 if (ferror(inp))
209 err(1, "read error on %s", name);
210
211 (void)fclose(inp);
212}
213
214
215static void
92static void setsrc(const char *);
93static void setfnid(int, const char *);
94static void funccall(pos_t *, const char *);
95static void decldef(pos_t *, const char *);
96static void usedsym(pos_t *, const char *);
97static u_short inptype(const char *, const char **);
98static int gettlen(const char *, const char **);
99static u_short findtype(const char *, size_t, int);

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

209 if (ferror(inp))
210 err(1, "read error on %s", name);
211
212 (void)fclose(inp);
213}
214
215
216static void
216inperr(void)
217inperror(const char *file, size_t line)
217{
218
218{
219
219 errx(1, "input file error: %s", fnames[srcfile]);
220 errx(1, "%s,%zd: input file error: %s", file, line, fnames[srcfile]);
220}
221
222/*
223 * Set the name of the C source file of the .ln file which is
224 * currently read.
225 */
226static void
227setsrc(const char *cp)

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

356 const char *name, *rename;
357
358 (void)memset(&sym, 0, sizeof (sym));
359 STRUCT_ASSIGN(sym.s_pos, *posp);
360 sym.s_def = NODECL;
361
362 used = 0;
363
221}
222
223/*
224 * Set the name of the C source file of the .ln file which is
225 * currently read.
226 */
227static void
228setsrc(const char *cp)

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

357 const char *name, *rename;
358
359 (void)memset(&sym, 0, sizeof (sym));
360 STRUCT_ASSIGN(sym.s_pos, *posp);
361 sym.s_def = NODECL;
362
363 used = 0;
364
364 while ((c = *cp) == 't' || c == 'd' || c == 'e' || c == 'u' ||
365 c == 'r' || c == 'o' || c == 's' || c == 'v' ||
366 c == 'P' || c == 'S') {
365 while (strchr("tdeurosvPS", (c = *cp)) != NULL) {
367 cp++;
368 switch (c) {
369 case 't':
370 if (sym.s_def != NODECL)
371 inperr();
372 sym.s_def = TDEF;
373 break;
374 case 'd':

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

540static u_short
541inptype(const char *cp, const char **epp)
542{
543 char c, s, *eptr;
544 const char *ep;
545 type_t *tp;
546 int narg, i, osdef = 0;
547 size_t tlen;
366 cp++;
367 switch (c) {
368 case 't':
369 if (sym.s_def != NODECL)
370 inperr();
371 sym.s_def = TDEF;
372 break;
373 case 'd':

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

539static u_short
540inptype(const char *cp, const char **epp)
541{
542 char c, s, *eptr;
543 const char *ep;
544 type_t *tp;
545 int narg, i, osdef = 0;
546 size_t tlen;
548 u_short tidx;
547 u_short tidx, sidx;
549 int h;
550
551 /* If we have this type already, return it's index. */
552 tlen = gettlen(cp, &ep);
553 h = thash(cp, tlen);
554 if ((tidx = findtype(cp, tlen, h)) != 0) {
555 *epp = ep;
556 return (tidx);

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

616 tp->t_tspec = s == 'e' ? ENUM : (s == 's' ? STRUCT : UNION);
617 break;
618 }
619
620 switch (tp->t_tspec) {
621 case ARRAY:
622 tp->t_dim = (int)strtol(cp, &eptr, 10);
623 cp = eptr;
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) {
554 *epp = ep;
555 return (tidx);

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

615 tp->t_tspec = s == 'e' ? ENUM : (s == 's' ? STRUCT : UNION);
616 break;
617 }
618
619 switch (tp->t_tspec) {
620 case ARRAY:
621 tp->t_dim = (int)strtol(cp, &eptr, 10);
622 cp = eptr;
624 tp->t_subt = TP(inptype(cp, &cp));
623 sidx = inptype(cp, &cp); /* force seq. point! (ditto below) */
624 tp->t_subt = TP(sidx);
625 break;
626 case PTR:
625 break;
626 case PTR:
627 tp->t_subt = TP(inptype(cp, &cp));
627 sidx = inptype(cp, &cp);
628 tp->t_subt = TP(sidx);
628 break;
629 case FUNC:
630 c = *cp;
631 if (isdigit((u_char)c)) {
632 if (!osdef)
633 tp->t_proto = 1;
634 narg = (int)strtol(cp, &eptr, 10);
635 cp = eptr;
636 if ((tp->t_args = calloc((size_t)(narg + 1),
637 sizeof (type_t *))) == NULL)
638 nomem();
639 for (i = 0; i < narg; i++) {
640 if (i == narg - 1 && *cp == 'E') {
641 tp->t_vararg = 1;
642 cp++;
643 } else {
629 break;
630 case FUNC:
631 c = *cp;
632 if (isdigit((u_char)c)) {
633 if (!osdef)
634 tp->t_proto = 1;
635 narg = (int)strtol(cp, &eptr, 10);
636 cp = eptr;
637 if ((tp->t_args = calloc((size_t)(narg + 1),
638 sizeof (type_t *))) == NULL)
639 nomem();
640 for (i = 0; i < narg; i++) {
641 if (i == narg - 1 && *cp == 'E') {
642 tp->t_vararg = 1;
643 cp++;
644 } else {
644 tp->t_args[i] = TP(inptype(cp, &cp));
645 sidx = inptype(cp, &cp);
646 tp->t_args[i] = TP(sidx);
645 }
646 }
647 }
647 }
648 }
649 }
648 tp->t_subt = TP(inptype(cp, &cp));
650 sidx = inptype(cp, &cp);
651 tp->t_subt = TP(sidx);
649 break;
650 case ENUM:
651 tp->t_tspec = INT;
652 tp->t_isenum = 1;
653 /* FALLTHROUGH */
654 case STRUCT:
655 case UNION:
656 switch (*cp++) {

--- 586 unchanged lines hidden ---
652 break;
653 case ENUM:
654 tp->t_tspec = INT;
655 tp->t_isenum = 1;
656 /* FALLTHROUGH */
657 case STRUCT:
658 case UNION:
659 switch (*cp++) {

--- 586 unchanged lines hidden ---