changeset 14379:2330aac2ae54

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.
author Jim Meyering <meyering@redhat.com>
date Sun, 20 Feb 2011 23:02:43 +0100
parents 479b128e79a2
children 5cee7a3cd6ca
files ChangeLog Makefile lib/dup3.c lib/fchownat.c lib/flock.c lib/fsync.c lib/fts.c lib/getpass.c lib/gettimeofday.c lib/linkat.c lib/nanosleep.c lib/openat-die.c lib/openat.c lib/userspec.c
diffstat 14 files changed, 124 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2011-02-22  Jim Meyering  <meyering@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  <bruno@clisp.org>
 
 	New module 'wctomb'.
--- a/Makefile
+++ b/Makefile
@@ -45,6 +45,15 @@
 		 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
 
--- a/lib/dup3.c
+++ b/lib/dup3.c
@@ -56,10 +56,10 @@
         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;
--- 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
 
--- 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 @@
 }
 
 /* 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 @@
 
 #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 @@
   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 */
--- 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 @@
 
 #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 */
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -628,7 +628,7 @@
 #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
--- a/lib/getpass.c
+++ b/lib/getpass.c
@@ -26,53 +26,53 @@
 
 #if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__)
 
-#include <stdbool.h>
+# include <stdbool.h>
 
-#if HAVE_DECL___FSETLOCKING && HAVE___FSETLOCKING
-# if HAVE_STDIO_EXT_H
-#  include <stdio_ext.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 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 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
-# 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
 
 /* 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 @@
   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 @@
       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 @@
     }
 
   /* 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 @@
    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)
--- 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 @@
 
 #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
--- a/lib/linkat.c
+++ b/lib/linkat.c
@@ -298,7 +298,7 @@
       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 @@
           }
       }
   }
-#endif
+# endif
 
   if (!flag)
     return linkat (fd1, file1, fd2, file2, flag);
--- a/lib/nanosleep.c
+++ b/lib/nanosleep.c
@@ -45,7 +45,7 @@
 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
--- 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"
--- a/lib/openat.c
+++ b/lib/openat.c
@@ -53,7 +53,7 @@
       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 @@
           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 @@
             }
         }
     }
-#endif
+# endif
 
   return fd;
 }
--- 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.  */