Hi Bruno, I understand your not wanting to modify many of your files to make them consistent in this manner. However, since all but a dozen of mine already conform, I've adjusted those outliers with the following patch and added a Makefile rule so that it's easy to see if/when a new inconsistency arises. The new rule checks only .c files under lib/ that are in modules owned by me.
Jim >From 86fd2114ac3940e03a02e99658c8df88aed8a235 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyer...@redhat.com> Date: Sun, 20 Feb 2011 23:02:43 +0100 Subject: [PATCH] maint: adjust cpp indentation to reflect nesting depth I.e., in a block of code that begins with an unnested "#if", put one space between the "#" in column 1 and following token. For example, -#include <sys/vfs.h> +# include <sys/vfs.h> Do this only in .c files that are part of a module I maintain. * lib/linkat.c: Filter through cppi. * lib/nanosleep.c: Likewise. * lib/openat.c: Likewise. * lib/openat-die.c: Likewise. * lib/dup3.c: Likewise. * lib/fchownat.c: Likewise. * lib/flock.c: Likewise. * lib/fsync.c: Likewise. * lib/fts.c: Likewise. * lib/getpass.c: Likewise. * lib/gettimeofday.c: Likewise. * lib/userspec.c: Likewise. * Makefile (sc_cpp_indent_check): New rule, to check this. --- ChangeLog | 23 +++++++++++++ Makefile | 9 +++++ lib/dup3.c | 4 +- lib/fchownat.c | 18 +++++----- lib/flock.c | 34 +++++++++--------- lib/fsync.c | 10 +++--- lib/fts.c | 2 +- lib/getpass.c | 94 ++++++++++++++++++++++++++-------------------------- lib/gettimeofday.c | 6 ++-- lib/linkat.c | 4 +- lib/nanosleep.c | 2 +- lib/openat-die.c | 2 +- lib/openat.c | 8 ++-- lib/userspec.c | 2 +- 14 files changed, 125 insertions(+), 93 deletions(-) diff --git a/ChangeLog b/ChangeLog index a9d060b..26ce08f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2011-02-22 Jim Meyering <meyer...@redhat.com> + + maint: adjust cpp indentation to reflect nesting depth + I.e., in a block of code that begins with an unnested "#if", + put one space between the "#" in column 1 and following token. + For example, + -#include <sys/vfs.h> + +# include <sys/vfs.h> + Do this only in .c files that are part of a module I maintain. + * lib/linkat.c: Filter through cppi. + * lib/nanosleep.c: Likewise. + * lib/openat.c: Likewise. + * lib/openat-die.c: Likewise. + * lib/dup3.c: Likewise. + * lib/fchownat.c: Likewise. + * lib/flock.c: Likewise. + * lib/fsync.c: Likewise. + * lib/fts.c: Likewise. + * lib/getpass.c: Likewise. + * lib/gettimeofday.c: Likewise. + * lib/userspec.c: Likewise. + * Makefile (sc_cpp_indent_check): New rule, to check this. + 2011-02-22 Bruno Haible <br...@clisp.org> New module 'wctomb'. diff --git a/Makefile b/Makefile index c3bf4a9..398b14a 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,15 @@ sc_pragma_columns: exit 1; } || :; \ else :; fi +# Verify that certain (for now, only Jim Meyering's) lib/**.c files +# are consistently cpp indented. +sc_cpp_indent_check: + ./gnulib-tool --extract-filelist $$(cd modules; grep -ilr meyering .) \ + | sort -u \ + | grep 'lib/.*\.c$$' \ + | grep -v '/getloadavg\.c$$' \ + | xargs cppi -c + # Regenerate some files that are stored in the repository. regen: MODULES.html diff --git a/lib/dup3.c b/lib/dup3.c index 60d3f76..2f87da6 100644 --- a/lib/dup3.c +++ b/lib/dup3.c @@ -56,10 +56,10 @@ dup3 (int oldfd, int newfd, int flags) if (!(result < 0 && errno == ENOSYS)) { have_dup3_really = 1; -#if REPLACE_FCHDIR +# if REPLACE_FCHDIR if (0 <= result) result = _gl_register_dup (oldfd, newfd); -#endif +# endif return result; } have_dup3_really = -1; diff --git a/lib/fchownat.c b/lib/fchownat.c index 8884b97..303d0fd 100644 --- a/lib/fchownat.c +++ b/lib/fchownat.c @@ -66,15 +66,15 @@ static int local_lchownat (int fd, char const *file, uid_t owner, gid_t group); -# define AT_FUNC_NAME local_lchownat -# define AT_FUNC_F1 lchown -# define AT_FUNC_POST_FILE_PARAM_DECLS , uid_t owner, gid_t group -# define AT_FUNC_POST_FILE_ARGS , owner, group -# include "at-func.c" -# undef AT_FUNC_NAME -# undef AT_FUNC_F1 -# undef AT_FUNC_POST_FILE_PARAM_DECLS -# undef AT_FUNC_POST_FILE_ARGS +# define AT_FUNC_NAME local_lchownat +# define AT_FUNC_F1 lchown +# define AT_FUNC_POST_FILE_PARAM_DECLS , uid_t owner, gid_t group +# define AT_FUNC_POST_FILE_ARGS , owner, group +# include "at-func.c" +# undef AT_FUNC_NAME +# undef AT_FUNC_F1 +# undef AT_FUNC_POST_FILE_PARAM_DECLS +# undef AT_FUNC_POST_FILE_ARGS # endif diff --git a/lib/flock.c b/lib/flock.c index bdec6d4..8f018e5 100644 --- a/lib/flock.c +++ b/lib/flock.c @@ -27,13 +27,13 @@ #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ /* _get_osfhandle */ -#include <io.h> +# include <io.h> /* LockFileEx */ -#define WIN32_LEAN_AND_MEAN -#include <windows.h> +# define WIN32_LEAN_AND_MEAN +# include <windows.h> -#include <errno.h> +# include <errno.h> /* Determine the current size of a file. Because the other braindead * APIs we'll call need lower/upper 32 bit pairs, keep the file size @@ -47,9 +47,9 @@ file_size (HANDLE h, DWORD * lower, DWORD * upper) } /* LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems. */ -#ifndef LOCKFILE_FAIL_IMMEDIATELY -# define LOCKFILE_FAIL_IMMEDIATELY 1 -#endif +# ifndef LOCKFILE_FAIL_IMMEDIATELY +# define LOCKFILE_FAIL_IMMEDIATELY 1 +# endif /* Acquire a lock. */ static BOOL @@ -160,17 +160,17 @@ flock (int fd, int operation) #else /* !Windows */ -#ifdef HAVE_STRUCT_FLOCK_L_TYPE +# ifdef HAVE_STRUCT_FLOCK_L_TYPE /* We know how to implement flock in terms of fcntl. */ -#include <fcntl.h> +# include <fcntl.h> -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif +# ifdef HAVE_UNISTD_H +# include <unistd.h> +# endif -#include <errno.h> -#include <string.h> +# include <errno.h> +# include <string.h> int flock (int fd, int operation) @@ -211,10 +211,10 @@ flock (int fd, int operation) return r; } -#else /* !HAVE_STRUCT_FLOCK_L_TYPE */ +# else /* !HAVE_STRUCT_FLOCK_L_TYPE */ -#error "This platform lacks flock function, and Gnulib doesn't provide a replacement. This is a bug in Gnulib." +# error "This platform lacks flock function, and Gnulib doesn't provide a replacement. This is a bug in Gnulib." -#endif /* !HAVE_STRUCT_FLOCK_L_TYPE */ +# endif /* !HAVE_STRUCT_FLOCK_L_TYPE */ #endif /* !Windows */ diff --git a/lib/fsync.c b/lib/fsync.c index 8dea41a..f0fc8e5 100644 --- a/lib/fsync.c +++ b/lib/fsync.c @@ -28,13 +28,13 @@ #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ /* _get_osfhandle */ -#include <io.h> +# include <io.h> /* FlushFileBuffers */ -#define WIN32_LEAN_AND_MEAN -#include <windows.h> +# define WIN32_LEAN_AND_MEAN +# include <windows.h> -#include <errno.h> +# include <errno.h> int fsync (int fd) @@ -73,6 +73,6 @@ fsync (int fd) #else /* !Windows */ -#error "This platform lacks fsync function, and Gnulib doesn't provide a replacement. This is a bug in Gnulib." +# error "This platform lacks fsync function, and Gnulib doesn't provide a replacement. This is a bug in Gnulib." #endif /* !Windows */ diff --git a/lib/fts.c b/lib/fts.c index c44f628..ad762dd 100644 --- a/lib/fts.c +++ b/lib/fts.c @@ -628,7 +628,7 @@ fts_close (FTS *sp) #if defined __linux__ \ && HAVE_SYS_VFS_H && HAVE_FSTATFS && HAVE_STRUCT_STATFS_F_TYPE -#include <sys/vfs.h> +# include <sys/vfs.h> /* Linux-specific constants from coreutils' src/fs.h */ # define S_MAGIC_TMPFS 0x1021994 diff --git a/lib/getpass.c b/lib/getpass.c index 226be15..c747f35 100644 --- a/lib/getpass.c +++ b/lib/getpass.c @@ -26,53 +26,53 @@ #if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) -#include <stdbool.h> - -#if HAVE_DECL___FSETLOCKING && HAVE___FSETLOCKING -# if HAVE_STDIO_EXT_H -# include <stdio_ext.h> +# include <stdbool.h> + +# if HAVE_DECL___FSETLOCKING && HAVE___FSETLOCKING +# if HAVE_STDIO_EXT_H +# include <stdio_ext.h> +# endif +# else +# define __fsetlocking(stream, type) /* empty */ # endif -#else -# define __fsetlocking(stream, type) /* empty */ -#endif -#if HAVE_TERMIOS_H -# include <termios.h> -#endif - -#if USE_UNLOCKED_IO -# include "unlocked-io.h" -#else -# if !HAVE_DECL_FFLUSH_UNLOCKED -# undef fflush_unlocked -# define fflush_unlocked(x) fflush (x) -# endif -# if !HAVE_DECL_FLOCKFILE -# undef flockfile -# define flockfile(x) ((void) 0) +# if HAVE_TERMIOS_H +# include <termios.h> # endif -# if !HAVE_DECL_FUNLOCKFILE -# undef funlockfile -# define funlockfile(x) ((void) 0) -# endif -# if !HAVE_DECL_FPUTS_UNLOCKED -# undef fputs_unlocked -# define fputs_unlocked(str,stream) fputs (str, stream) -# endif -# if !HAVE_DECL_PUTC_UNLOCKED -# undef putc_unlocked -# define putc_unlocked(c,stream) putc (c, stream) + +# if USE_UNLOCKED_IO +# include "unlocked-io.h" +# else +# if !HAVE_DECL_FFLUSH_UNLOCKED +# undef fflush_unlocked +# define fflush_unlocked(x) fflush (x) +# endif +# if !HAVE_DECL_FLOCKFILE +# undef flockfile +# define flockfile(x) ((void) 0) +# endif +# if !HAVE_DECL_FUNLOCKFILE +# undef funlockfile +# define funlockfile(x) ((void) 0) +# endif +# if !HAVE_DECL_FPUTS_UNLOCKED +# undef fputs_unlocked +# define fputs_unlocked(str,stream) fputs (str, stream) +# endif +# if !HAVE_DECL_PUTC_UNLOCKED +# undef putc_unlocked +# define putc_unlocked(c,stream) putc (c, stream) +# endif # endif -#endif /* It is desirable to use this bit on systems that have it. The only bit of terminal state we want to twiddle is echoing, which is done in software; there is no need to change the state of the terminal hardware. */ -#ifndef TCSASOFT -# define TCSASOFT 0 -#endif +# ifndef TCSASOFT +# define TCSASOFT 0 +# endif static void call_fclose (void *arg) @@ -112,7 +112,7 @@ getpass (const char *prompt) flockfile (out); /* Turn echoing off if it is on now. */ -#if HAVE_TCGETATTR +# if HAVE_TCGETATTR if (tcgetattr (fileno (in), &t) == 0) { /* Save the old one. */ @@ -121,7 +121,7 @@ getpass (const char *prompt) t.c_lflag &= ~(ECHO | ISIG); tty_changed = (tcsetattr (fileno (in), TCSAFLUSH | TCSASOFT, &t) == 0); } -#endif +# endif /* Write the prompt. */ fputs_unlocked (prompt, out); @@ -158,10 +158,10 @@ getpass (const char *prompt) } /* Restore the original setting. */ -#if HAVE_TCSETATTR +# if HAVE_TCSETATTR if (tty_changed) tcsetattr (fileno (in), TCSAFLUSH | TCSASOFT, &s); -#endif +# endif funlockfile (out); @@ -176,15 +176,15 @@ getpass (const char *prompt) improved by Simon Josefsson. */ /* For PASS_MAX. */ -#include <limits.h> +# include <limits.h> /* For _getch(). */ -#include <conio.h> +# include <conio.h> /* For strdup(). */ -#include <string.h> +# include <string.h> -#ifndef PASS_MAX -# define PASS_MAX 512 -#endif +# ifndef PASS_MAX +# define PASS_MAX 512 +# endif char * getpass (const char *prompt) diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c index bbad88e..ae2a6f1 100644 --- a/lib/gettimeofday.c +++ b/lib/gettimeofday.c @@ -40,10 +40,10 @@ static struct tm tm_zero_buffer; static struct tm *localtime_buffer_addr = &tm_zero_buffer; -#undef localtime +# undef localtime extern struct tm *localtime (time_t const *); -#undef gmtime +# undef gmtime extern struct tm *gmtime (time_t const *); /* This is a wrapper for localtime. It is used only on systems for which @@ -79,7 +79,7 @@ rpl_gmtime (time_t const *timep) #if TZSET_CLOBBERS_LOCALTIME -#undef tzset +# undef tzset extern void tzset (void); /* This is a wrapper for tzset, for systems on which tzset may clobber diff --git a/lib/linkat.c b/lib/linkat.c index ec89050..77b6345 100644 --- a/lib/linkat.c +++ b/lib/linkat.c @@ -298,7 +298,7 @@ rpl_linkat (int fd1, char const *file1, int fd2, char const *file2, int flag) return -1; } -#if LINKAT_TRAILING_SLASH_BUG +# if LINKAT_TRAILING_SLASH_BUG /* Reject trailing slashes on non-directories. */ { size_t len1 = strlen (file1); @@ -319,7 +319,7 @@ rpl_linkat (int fd1, char const *file1, int fd2, char const *file2, int flag) } } } -#endif +# endif if (!flag) return linkat (fd1, file1, fd2, file2, flag); diff --git a/lib/nanosleep.c b/lib/nanosleep.c index d584975..ab5cc89 100644 --- a/lib/nanosleep.c +++ b/lib/nanosleep.c @@ -45,7 +45,7 @@ enum { BILLION = 1000 * 1000 * 1000 }; int nanosleep (const struct timespec *requested_delay, struct timespec *remaining_delay) -#undef nanosleep +# undef nanosleep { /* nanosleep mishandles large sleeps due to internal overflow problems. The worst known case of this is Linux 2.6.9 with glibc 2.3.4, which diff --git a/lib/openat-die.c b/lib/openat-die.c index b10e627..ea36dda 100644 --- a/lib/openat-die.c +++ b/lib/openat-die.c @@ -22,7 +22,7 @@ #include <stdlib.h> #ifndef GNULIB_LIBPOSIX -#include "error.h" +# include "error.h" #endif #include "exitfail.h" diff --git a/lib/openat.c b/lib/openat.c index 55e12e2..939e3c7 100644 --- a/lib/openat.c +++ b/lib/openat.c @@ -53,7 +53,7 @@ rpl_openat (int dfd, char const *filename, int flags, ...) va_end (arg); } -#if OPEN_TRAILING_SLASH_BUG +# if OPEN_TRAILING_SLASH_BUG /* If the filename ends in a slash and one of O_CREAT, O_WRONLY, O_RDWR is specified, then fail. Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html> @@ -84,11 +84,11 @@ rpl_openat (int dfd, char const *filename, int flags, ...) return -1; } } -#endif +# endif fd = openat (dfd, filename, flags, mode); -#if OPEN_TRAILING_SLASH_BUG +# if OPEN_TRAILING_SLASH_BUG /* If the filename ends in a slash and fd does not refer to a directory, then fail. Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html> @@ -117,7 +117,7 @@ rpl_openat (int dfd, char const *filename, int flags, ...) } } } -#endif +# endif return fd; } diff --git a/lib/userspec.c b/lib/userspec.c index 9d910de..bf3b792 100644 --- a/lib/userspec.c +++ b/lib/userspec.c @@ -80,7 +80,7 @@ POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to isdigit unless it's important to use the locale's definition of `digit' even when the host does not conform to POSIX. */ -#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9) +# define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9) /* Return true if STR represents an unsigned decimal integer. */ -- 1.7.4.1.16.g759e8