From 86fd2114ac3940e03a02e99658c8df88aed8a235 Mon Sep 17 00:00:00 2001 From: Jim Meyering 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 +# include 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 a9d060b38..26ce08f3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2011-02-22 Jim Meyering + + 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 + +# include + 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 New module 'wctomb'. diff --git a/Makefile b/Makefile index c3bf4a979..398b14a10 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 60d3f76ef..2f87da616 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 8884b97ae..303d0fdf4 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 bdec6d48e..8f018e50c 100644 --- a/lib/flock.c +++ b/lib/flock.c @@ -27,13 +27,13 @@ #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ /* _get_osfhandle */ -#include +# include /* LockFileEx */ -#define WIN32_LEAN_AND_MEAN -#include +# define WIN32_LEAN_AND_MEAN +# include -#include +# include /* 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 +# include -#ifdef HAVE_UNISTD_H -#include -#endif +# ifdef HAVE_UNISTD_H +# include +# endif -#include -#include +# include +# include 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 8dea41ab8..f0fc8e5d3 100644 --- a/lib/fsync.c +++ b/lib/fsync.c @@ -28,13 +28,13 @@ #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ /* _get_osfhandle */ -#include +# include /* FlushFileBuffers */ -#define WIN32_LEAN_AND_MEAN -#include +# define WIN32_LEAN_AND_MEAN +# include -#include +# include 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 c44f628a5..ad762dd77 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 +# include /* Linux-specific constants from coreutils' src/fs.h */ # define S_MAGIC_TMPFS 0x1021994 diff --git a/lib/getpass.c b/lib/getpass.c index 226be155b..c747f35c2 100644 --- a/lib/getpass.c +++ b/lib/getpass.c @@ -26,53 +26,53 @@ #if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) -#include - -#if HAVE_DECL___FSETLOCKING && HAVE___FSETLOCKING -# if HAVE_STDIO_EXT_H -# include +# include + +# if HAVE_DECL___FSETLOCKING && HAVE___FSETLOCKING +# if HAVE_STDIO_EXT_H +# include +# endif +# else +# define __fsetlocking(stream, type) /* empty */ # endif -#else -# define __fsetlocking(stream, type) /* empty */ -#endif -#if HAVE_TERMIOS_H -# include -#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 # 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 +# include /* For _getch(). */ -#include +# include /* For strdup(). */ -#include +# include -#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 bbad88e98..ae2a6f148 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 ec89050db..77b634599 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 d58497524..ab5cc8986 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 b10e627c6..ea36dda89 100644 --- a/lib/openat-die.c +++ b/lib/openat-die.c @@ -22,7 +22,7 @@ #include #ifndef GNULIB_LIBPOSIX -#include "error.h" +# include "error.h" #endif #include "exitfail.h" diff --git a/lib/openat.c b/lib/openat.c index 55e12e211..939e3c70d 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 @@ -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 @@ -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 9d910de9a..bf3b792a7 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. */ -- 2.11.0