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) |
37__RCSID("$NetBSD: read.c,v 1.19 2007/09/28 21:53:50 uwe Exp $"); |
38#endif |
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 |
90#define inperr() inperror(__FILE__, __LINE__) 91static void inperror(const char *, size_t); |
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 |
217inperror(const char *file, size_t line) |
218{ 219 |
220 errx(1, "%s,%zd: input file error: %s", file, line, fnames[srcfile]); |
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 |
365 while (strchr("tdeurosvPS", (c = *cp)) != NULL) { |
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; |
547 u_short tidx, sidx; |
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; |
623 sidx = inptype(cp, &cp); /* force seq. point! (ditto below) */ 624 tp->t_subt = TP(sidx); |
625 break; 626 case PTR: |
627 sidx = inptype(cp, &cp); 628 tp->t_subt = TP(sidx); |
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 { |
645 sidx = inptype(cp, &cp); 646 tp->t_args[i] = TP(sidx); |
647 } 648 } 649 } |
650 sidx = inptype(cp, &cp); 651 tp->t_subt = TP(sidx); |
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 --- |