summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Youngman <jay@gnu.org>2013-03-31 20:25:49 +0100
committerJames Youngman <jay@gnu.org>2013-03-31 20:25:49 +0100
commit16e147b9909745dab72bfb7f839fb07af849ee3e (patch)
tree7b60eb84b169c8248c3a375829f77dc214eeb7dc
parentfdaa57adba0f7016781aeab078c144e4ae1f7681 (diff)
downloadfindutils-16e147b9909745dab72bfb7f839fb07af849ee3e.tar.gz
Don't use reserved identifiers in macro names; fix other code smells.
* build-aux/src-sniff.py (checkers): Check for #define directives which use a macro name which is reserved. (MakefileRegexChecker): New class which performs regex checks on makefiles; this ensures that we don't check Makefile.in if we're going to check Makefile.am anyway. * lib/unused-result.h: Don't use a reserved identifier in the macro name defined as the #include guard. * locate/locatedb.h: Likewise. * Makefile.am (findutils-check-smells): Don't check gnulib code. * import-gnulib.sh (hack_gnulib_tool_output): Move the 'do' of a for loop onto the line following the 'for' (instead of the same line).
-rw-r--r--ChangeLog16
-rw-r--r--Makefile.am2
-rw-r--r--build-aux/src-sniff.py47
-rwxr-xr-ximport-gnulib.sh3
-rw-r--r--lib/unused-result.h4
-rw-r--r--locate/locatedb.h6
6 files changed, 68 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index dd881817..c99d77d0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2013-03-31 James Youngman <jay@gnu.org>
+
+ Don't use reserved identifiers in macro names; fix other code smells.
+ * build-aux/src-sniff.py (checkers): Check for #define directives
+ which use a macro name which is reserved.
+ (MakefileRegexChecker): New class which performs regex checks on
+ makefiles; this ensures that we don't check Makefile.in if we're
+ going to check Makefile.am anyway.
+ * lib/unused-result.h: Don't use a reserved identifier in the
+ macro name defined as the #include guard.
+ * locate/locatedb.h: Likewise.
+ * Makefile.am (findutils-check-smells): Don't check gnulib code.
+ * import-gnulib.sh (hack_gnulib_tool_output): Move the 'do' of a
+ for loop onto the line following the 'for' (instead of the same
+ line).
+
2013-03-29 James Youngman <jay@gnu.org>
Document that -0/-d turns off logical end-of-file processing.
diff --git a/Makefile.am b/Makefile.am
index 4f178c30..fa54bac4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -48,6 +48,8 @@ findutils-check-testfiles:
findutils-check-smells:
find $(srcdir) \( -path $(srcdir)/autom4te.cache -o \
-path $(srcdir)/gnulib -o \
+ -path $(srcdir)/gl -o \
+ -path $(srcdir)/tests -o \
-name .git -o \
\( -type d -name CVS \) \
\) -prune -o \
diff --git a/build-aux/src-sniff.py b/build-aux/src-sniff.py
index e2be5979..a0145e66 100644
--- a/build-aux/src-sniff.py
+++ b/build-aux/src-sniff.py
@@ -21,6 +21,7 @@
# gnulib provides a way of disabling checks for particular files, and
# has a wider range of checks. Indeed, many of these checks do in fact
# check the same thing as "make syntax-check".
+import os.path
import re
import sys
@@ -68,11 +69,13 @@ class RegexSniffer(object):
class RegexChecker(object):
+
def __init__(self, regex, line_smells, file_smells):
super(RegexChecker, self).__init__()
self._regex = re.compile(regex)
self._line_sniffers = [RegexSniffer(s[0],s[1]) for s in line_smells]
self._file_sniffers = [RegexSniffer(s[0],s[1],re.S|re.M) for s in file_smells]
+
def Check(self, filename, lines, fulltext):
if self._regex.search(filename):
# We recognise this type of file.
@@ -86,11 +89,49 @@ class RegexChecker(object):
pass
+class MakefileRegexChecker(object):
+
+ MAKEFILE_PRIORITY_LIST = ['Makefile.am', 'Makefile.in', 'Makefile']
+ MAKEFILE_REGEX = ''.join(
+ '|'.join(['(%s)' % pattern for pattern in MAKEFILE_PRIORITY_LIST]))
+
+ def __init__(self, line_smells, file_smells):
+ self._file_regex = re.compile(self.MAKEFILE_REGEX)
+ self._rxc = RegexChecker(self.MAKEFILE_REGEX, line_smells, file_smells)
+
+ def WantToCheck(self, filename):
+ if not self._file_regex.search(filename):
+ return False
+ makefile_base = os.path.basename(filename)
+ makefile_dir = os.path.dirname(filename)
+
+ for base in self.MAKEFILE_PRIORITY_LIST:
+ path = os.path.join(makefile_dir, base)
+ if os.path.exists(path):
+ if path == filename:
+ # The first existing name in MAKEFILE_PRIORITY_LIST
+ # is actually this file, so we want to check it.
+ return True
+ else:
+ # These is another (source) Makefile we want to check
+ # instead.
+ return False
+ # If we get to here we were asked about a file which either
+ # doesn't exist or which doesn't look like anything in
+ # MAKEFILE_PRIORITY_LIST. So give the go-ahead to check it.
+ return True
+
+ def Check(self, filename, lines, fulltext):
+ if self.WantToCheck(filename):
+ self._rxc.Check(filename, lines, fulltext)
+
+
checkers = [
# Check C-like languages for C code smells.
RegexChecker(C_ISH_FILENAME_RE,
# line smells
[
+ [r'^\s*#\s*define\s+(_[A-Z_]+)', "Don't use reserved macro names"],
[r'(?<!\w)free \(\(', "don't cast the argument to free()"],
[r'\*\) *x(m|c|re)alloc(?!\w)',"don't cast the result of x*alloc"],
[r'\*\) *alloca(?!\w)',"don't cast the result of alloca"],
@@ -104,7 +145,6 @@ checkers = [
[r'the\s*the', "'the"+" the' is probably not deliberate"],
[r'(?<!\w)error \([^_"]*[^_]"[^"]*[a-z]{3}', "untranslated error message"],
[r'^# *if\s+defined *\(', "useless parentheses in '#if defined'"],
-
],
[
[r'# *include <assert.h>(?!.*assert \()',
@@ -115,9 +155,8 @@ checkers = [
"If you include \"quote.h\", use one of its functions."],
]),
# Check Makefiles for Makefile code smells.
- RegexChecker('(^|/)[Mm]akefile(.am|.in)?',
- [ [r'^ ', "Spaces at start of line"], ],
- []),
+ MakefileRegexChecker([ [r'^ ', "Spaces at start of makefile line"], ],
+ []),
# Check everything for whitespace problems.
RegexChecker('', [], [[r'[ ]$',
"trailing whitespace '%(matchtext)s'"],]),
diff --git a/import-gnulib.sh b/import-gnulib.sh
index 073ddb0f..ff9c3301 100755
--- a/import-gnulib.sh
+++ b/import-gnulib.sh
@@ -175,7 +175,8 @@ update_licenses() {
hack_gnulib_tool_output() {
local gnulibdir="${1}"
- for file in $extra_files; do
+ for file in $extra_files
+ do
case $file in
*/mdate-sh | */texinfo.tex) dest=doc;;
*) dest=build-aux;;
diff --git a/lib/unused-result.h b/lib/unused-result.h
index 050440c9..a49b2792 100644
--- a/lib/unused-result.h
+++ b/lib/unused-result.h
@@ -16,8 +16,8 @@
*/
/* Taken from coreutils' fts_.h */
-#ifndef _UNUSED_RESULT_H
-# define _UNUSED_RESULT_H 1
+#ifndef INC_UNUSED_RESULT_H
+# define INC_UNUSED_RESULT_H 1
# ifndef __GNUC_PREREQ
# if defined __GNUC__ && defined __GNUC_MINOR__
diff --git a/locate/locatedb.h b/locate/locatedb.h
index ff79b311..048a2eab 100644
--- a/locate/locatedb.h
+++ b/locate/locatedb.h
@@ -15,8 +15,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _LOCATEDB_H
-#define _LOCATEDB_H 1
+#ifndef INC_LOCATEDB_H
+#define INC_LOCATEDB_H 1
/* The magic string at the start of a locate database, to make sure
it's in the right format. The 02 is the database format version number.
@@ -69,4 +69,4 @@ bool putword (FILE *fp, int word,
#define SLOCATE_DB_MAGIC_LEN 2
-#endif /* !_LOCATEDB_H */
+#endif /* !INC_LOCATEDB_H */