Module Name:    src
Committed By:   rillig
Date:           Mon Jul 10 12:40:22 UTC 2023

Modified Files:
        src/usr.bin/xlint/lint2: chk.c externs2.h hash.c lint2.h main2.c msg.c
            read.c

Log Message:
lint: clean up lint2


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/xlint/lint2/chk.c
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/xlint/lint2/externs2.h
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/xlint/lint2/hash.c
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint2/lint2.h
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/xlint/lint2/main2.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint2/msg.c
cvs rdiff -u -r1.84 -r1.85 src/usr.bin/xlint/lint2/read.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint2/chk.c
diff -u src/usr.bin/xlint/lint2/chk.c:1.57 src/usr.bin/xlint/lint2/chk.c:1.58
--- src/usr.bin/xlint/lint2/chk.c:1.57	Mon Jul  3 10:23:12 2023
+++ src/usr.bin/xlint/lint2/chk.c	Mon Jul 10 12:40:22 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: chk.c,v 1.57 2023/07/03 10:23:12 rillig Exp $ */
+/* $NetBSD: chk.c,v 1.58 2023/07/10 12:40:22 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: chk.c,v 1.57 2023/07/03 10:23:12 rillig Exp $");
+__RCSID("$NetBSD: chk.c,v 1.58 2023/07/10 12:40:22 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -78,7 +78,7 @@ mark_main_as_used(void)
 {
 	hte_t *hte;
 
-	if ((hte = hsearch("main", false)) != NULL)
+	if ((hte = htab_search("main", false)) != NULL)
 		hte->h_used = true;
 }
 

Index: src/usr.bin/xlint/lint2/externs2.h
diff -u src/usr.bin/xlint/lint2/externs2.h:1.19 src/usr.bin/xlint/lint2/externs2.h:1.20
--- src/usr.bin/xlint/lint2/externs2.h:1.19	Sat Jan 14 08:48:18 2023
+++ src/usr.bin/xlint/lint2/externs2.h	Mon Jul 10 12:40:22 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: externs2.h,v 1.19 2023/01/14 08:48:18 rillig Exp $ */
+/* $NetBSD: externs2.h,v 1.20 2023/07/10 12:40:22 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,27 +35,27 @@
 /*
  * main2.c
  */
-extern	bool	xflag;
-extern	bool	uflag;
 extern	bool	Cflag;
-extern	const char *libname;
-extern	bool	sflag;
-extern	bool	tflag;
+extern	bool	Fflag;
 extern	bool	Hflag;
 extern	bool	hflag;
-extern	bool	Fflag;
+extern	bool	sflag;
+extern	bool	tflag;
+extern	bool	uflag;
+extern	bool	xflag;
+extern	const char *libname;
 
 /*
  * hash.c
  */
-extern	hte_t**	htab_new(void);
-extern	hte_t	*_hsearch(hte_t **, const char *, bool);
-extern	void	symtab_init(void);
-extern	void	symtab_forall(void (*)(hte_t *));
-extern	void	symtab_forall_sorted(void (*)(hte_t *));
-extern	void	_destroyhash(hte_t **);
+hte_t**	htab_new(void);
+hte_t	*hash_search(hte_t **, const char *, bool);
+void	symtab_init(void);
+void	symtab_forall(void (*)(hte_t *));
+void	symtab_forall_sorted(void (*)(hte_t *));
+void	hash_free(hte_t **);
 
-#define	hsearch(a, b)	_hsearch(NULL, (a), (b))
+#define	htab_search(a, b)	hash_search(NULL, (a), (b))
 
 /*
  * read.c
@@ -63,23 +63,23 @@ extern	void	_destroyhash(hte_t **);
 extern	const	char **fnames;
 extern	type_t	**tlst;
 
-extern	void	readfile(const char *);
-extern	void	mkstatic(hte_t *);
+void	readfile(const char *);
+void	mkstatic(hte_t *);
 
 /*
  * chk.c
  */
-extern	void	mark_main_as_used(void);
-extern	void	check_name(const hte_t *);
+void	mark_main_as_used(void);
+void	check_name(const hte_t *);
 
 /*
  * msg.c
  */
-extern	void	msg(int, ...);
-extern	const	char *mkpos(pos_t *);
+void	msg(int, ...);
+const	char *mkpos(const pos_t *);
 
 /*
  * emit2.c
  */
-extern	void	outlib(const char *);
-extern	int	addoutfile(short);
+void	outlib(const char *);
+int	addoutfile(short);

Index: src/usr.bin/xlint/lint2/hash.c
diff -u src/usr.bin/xlint/lint2/hash.c:1.26 src/usr.bin/xlint/lint2/hash.c:1.27
--- src/usr.bin/xlint/lint2/hash.c:1.26	Mon Jul 10 09:51:30 2023
+++ src/usr.bin/xlint/lint2/hash.c	Mon Jul 10 12:40:22 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: hash.c,v 1.26 2023/07/10 09:51:30 rillig Exp $	*/
+/*	$NetBSD: hash.c,v 1.27 2023/07/10 12:40:22 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: hash.c,v 1.26 2023/07/10 09:51:30 rillig Exp $");
+__RCSID("$NetBSD: hash.c,v 1.27 2023/07/10 12:40:22 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -76,7 +76,7 @@ hash(const char *s)
  * given name exists and mknew is set, create a new one.
  */
 hte_t *
-_hsearch(hte_t **table, const char *s, bool mknew)
+hash_search(hte_t **table, const char *s, bool mknew)
 {
 	unsigned int h;
 	hte_t *hte;
@@ -185,14 +185,11 @@ symtab_forall_sorted(void (*action)(hte_
  * Free all contents of the hash table that this module allocated.
  */
 void
-_destroyhash(hte_t **table)
+hash_free(hte_t **table)
 {
 	int i;
 	hte_t *hte, *nexthte;
 
-	if (table == NULL)
-		err(1, "_destroyhash called on main hash table");
-
 	for (i = 0; i < HTAB_BUCKETS; i++) {
 		for (hte = table[i]; hte != NULL; hte = nexthte) {
 			free(__UNCONST(hte->h_name));

Index: src/usr.bin/xlint/lint2/lint2.h
diff -u src/usr.bin/xlint/lint2/lint2.h:1.22 src/usr.bin/xlint/lint2/lint2.h:1.23
--- src/usr.bin/xlint/lint2/lint2.h:1.22	Mon Feb  7 21:57:47 2022
+++ src/usr.bin/xlint/lint2/lint2.h	Mon Jul 10 12:40:22 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lint2.h,v 1.22 2022/02/07 21:57:47 rillig Exp $ */
+/* $NetBSD: lint2.h,v 1.23 2023/07/10 12:40:22 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -120,7 +120,6 @@ typedef	struct sym {
 		bool	s_printflike:1;
 		bool	s_scanflike:1;
 		unsigned short s_type;
-		/* XXX: gap of 4 bytes on LP64 platforms */
 		struct	sym *s_next;	/* next symbol with same name */
 	} s_s;
 	/*

Index: src/usr.bin/xlint/lint2/main2.c
diff -u src/usr.bin/xlint/lint2/main2.c:1.31 src/usr.bin/xlint/lint2/main2.c:1.32
--- src/usr.bin/xlint/lint2/main2.c:1.31	Mon Jul  3 11:16:32 2023
+++ src/usr.bin/xlint/lint2/main2.c	Mon Jul 10 12:40:22 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: main2.c,v 1.31 2023/07/03 11:16:32 rillig Exp $	*/
+/*	$NetBSD: main2.c,v 1.32 2023/07/10 12:40:22 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: main2.c,v 1.31 2023/07/03 11:16:32 rillig Exp $");
+__RCSID("$NetBSD: main2.c,v 1.32 2023/07/10 12:40:22 rillig Exp $");
 #endif
 
 #include <stdio.h>
@@ -47,33 +47,15 @@ __RCSID("$NetBSD: main2.c,v 1.31 2023/07
 
 #include "lint2.h"
 
-/* warnings for symbols which are declared but not defined or used */
-bool	xflag;
-
-bool	uflag;
-
-/* Create a lint library in the current directory with name libname. */
 bool	Cflag;
-const char *libname;
-
-/*
- * warnings for (tentative) definitions of the same name in more than
- * one translation unit
- */
-bool	sflag;
-
-bool	tflag;
-
-/*
- * If a complaint stems from a included file, print the name of the included
- * file instead of the name specified at the command line followed by '?'
- */
+bool	Fflag;
 bool	Hflag;
-
 bool	hflag;
-
-/* Print full path names, not only the last component */
-bool	Fflag;
+bool	sflag;
+bool	tflag;
+bool	uflag;
+bool	xflag;
+const char *libname;
 
 /*
  * List of libraries (from -l flag). These libraries are read after all

Index: src/usr.bin/xlint/lint2/msg.c
diff -u src/usr.bin/xlint/lint2/msg.c:1.20 src/usr.bin/xlint/lint2/msg.c:1.21
--- src/usr.bin/xlint/lint2/msg.c:1.20	Fri Jun  9 13:03:49 2023
+++ src/usr.bin/xlint/lint2/msg.c	Mon Jul 10 12:40:22 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg.c,v 1.20 2023/06/09 13:03:49 rillig Exp $	*/
+/*	$NetBSD: msg.c,v 1.21 2023/07/10 12:40:22 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: msg.c,v 1.20 2023/06/09 13:03:49 rillig Exp $");
+__RCSID("$NetBSD: msg.c,v 1.21 2023/07/10 12:40:22 rillig Exp $");
 #endif
 
 #include <stdarg.h>
@@ -102,7 +102,7 @@ lbasename(const char *path)
  * Create a string which describes a position in a source file.
  */
 const char *
-mkpos(pos_t *posp)
+mkpos(const pos_t *posp)
 {
 	size_t len;
 	const char *fn;
@@ -125,12 +125,10 @@ mkpos(pos_t *posp)
 
 	if (len > blen)
 		buf = xrealloc(buf, blen = len);
-	if (line != 0) {
-		(void)sprintf(buf, "%s%s(%d)",
-			      fn, qm ? "?" : "", line);
-	} else {
+	if (line != 0)
+		(void)sprintf(buf, "%s%s(%d)", fn, qm ? "?" : "", line);
+	else
 		(void)sprintf(buf, "%s", fn);
-	}
 
 	return buf;
 }

Index: src/usr.bin/xlint/lint2/read.c
diff -u src/usr.bin/xlint/lint2/read.c:1.84 src/usr.bin/xlint/lint2/read.c:1.85
--- src/usr.bin/xlint/lint2/read.c:1.84	Mon Jul 10 09:51:30 2023
+++ src/usr.bin/xlint/lint2/read.c	Mon Jul 10 12:40:22 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: read.c,v 1.84 2023/07/10 09:51:30 rillig Exp $ */
+/* $NetBSD: read.c,v 1.85 2023/07/10 12:40:22 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: read.c,v 1.84 2023/07/10 09:51:30 rillig Exp $");
+__RCSID("$NetBSD: read.c,v 1.85 2023/07/10 12:40:22 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -246,7 +246,7 @@ readfile(const char *name)
 		readfile_line = NULL;
 	}
 
-	_destroyhash(renametab);
+	hash_free(renametab);
 
 	if (ferror(inp) != 0)
 		err(1, "read error on %s", name);
@@ -374,11 +374,11 @@ again:
 	name = inpname(cp, &cp);
 
 	/* first look it up in the renaming table, then in the normal table */
-	hte = _hsearch(renametab, name, false);
+	hte = hash_search(renametab, name, false);
 	if (hte != NULL)
 		hte = hte->h_hte;
 	else
-		hte = hsearch(name, true);
+		hte = htab_search(name, true);
 	hte->h_used = true;
 
 	fcall->f_type = inptype(cp, &cp);
@@ -490,9 +490,9 @@ decldef(pos_t pos, const char *cp)
 		newname = inpname(cp, &cp);
 
 		/* enter it and see if it's already been renamed */
-		renamehte = _hsearch(renametab, tname, true);
+		renamehte = hash_search(renametab, tname, true);
 		if (renamehte->h_hte == NULL) {
-			hte = hsearch(newname, true);
+			hte = htab_search(newname, true);
 			renamehte->h_hte = hte;
 			renamed = true;
 		} else if (hte = renamehte->h_hte,
@@ -505,11 +505,11 @@ decldef(pos_t pos, const char *cp)
 		free(tname);
 	} else {
 		/* it might be a previously-done rename */
-		hte = _hsearch(renametab, name, false);
+		hte = hash_search(renametab, name, false);
 		if (hte != NULL)
 			hte = hte->h_hte;
 		else
-			hte = hsearch(name, true);
+			hte = htab_search(name, true);
 	}
 	hte->h_used |= used;
 	if (sym.s_def == DEF || sym.s_def == TDEF)
@@ -574,11 +574,11 @@ usedsym(pos_t pos, const char *cp)
 		inperr("bad delim %c", cp[-1]);
 
 	name = inpname(cp, &cp);
-	hte = _hsearch(renametab, name, false);
+	hte = hash_search(renametab, name, false);
 	if (hte != NULL)
 		hte = hte->h_hte;
 	else
-		hte = hsearch(name, true);
+		hte = htab_search(name, true);
 	hte->h_used = true;
 
 	*hte->h_lusym = usym;
@@ -719,11 +719,11 @@ inptype(const char *cp, const char **epp
 		switch (*cp++) {
 		case '1':
 			tp->t_istag = true;
-			tp->t_tag = hsearch(inpname(cp, &cp), true);
+			tp->t_tag = htab_search(inpname(cp, &cp), true);
 			break;
 		case '2':
 			tp->t_istynam = true;
-			tp->t_tynam = hsearch(inpname(cp, &cp), true);
+			tp->t_tynam = htab_search(inpname(cp, &cp), true);
 			break;
 		case '3':
 			tp->t_isuniqpos = true;

Reply via email to