Add compile-time checks for various tables being in alphabetical order.
authorJeremy Harris <jgh146exb@wizmail.org>
Sun, 12 May 2013 21:31:36 +0000 (22:31 +0100)
committerJeremy Harris <jgh146exb@wizmail.org>
Sun, 12 May 2013 21:34:48 +0000 (22:34 +0100)
This is gross hackery and somewhat fragile.  A better method would
actuallyt compile the 'C' involved and check programmatically.

src/Makefile
src/scripts/source_checks [new file with mode: 0644]
src/src/acl.c

index a18c3d7289356646b574913fd454df540e3b4482..ec573b5d64a48255ac274e0e85b9e7436543199b 100644 (file)
@@ -45,12 +45,15 @@ build-directory:
        $(SHELL) -c "test -d $$builddir -a -r $$builddir/version.c || \
          (mkdir $$builddir; cd $$builddir; $(SHELL) ../scripts/MakeLinks)";
 
+checks:
+       $(SHELL) scripts/source_checks
+
 # The "configure" target ensures that the build directory exists, then arranges
 # to build the main makefile from inside the build directory, by calling the
 # Configure-Makefile script. This does its own dependency checking because of
 # the optional files.
 
-configure: build-directory
+configure: checks build-directory
        @cd build-$(buildname); \
          build=$(build) $(SHELL) ../scripts/Configure-Makefile
 
diff --git a/src/scripts/source_checks b/src/scripts/source_checks
new file mode 100644 (file)
index 0000000..79f9c35
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+cd src;
+
+# Tables with struct items
+while read file table
+do
+  : $file $table
+  < $file \
+  perl -e '$/= undef; while (<>) { print $1 if /(?<='$table'\[\])\s*=\s*{\n(([^}].*\n)+)/m }' \
+  | awk '/{ (US)?"/ {print $2}' \
+  | awk -F\" '{print $2}' \
+  | LANG=C sort -c \
+  || exit 1
+done <<-END
+       readconf.c      optionlist_config
+       globals.c       optionlist_auths
+       globals.c       debug_options
+       globals.c       header_names
+       globals.c       log_options
+       expand.c        item_table
+       transport.c     optionlist_transports
+       route.c         optionlist_routers
+       transports/appendfile.c appendfile_transport_options
+       transports/autoreply.c  autoreply_transport_options
+       transports/lmtp.c       lmtp_transport_options
+       transports/pipe.c       pipe_transport_options
+       transports/smtp.c       smtp_transport_options
+       expand.c        var_table
+END
+
+# Tables with just string items
+while read file table
+do
+  : $file $table
+  < $file \
+  perl -e '$/= undef; while (<>) { print $1 if /(?<='$table'\[\])\s*=\s*{\s?(([^}]*)+)}/m }' \
+  | awk -F\" '/"/ {print $2}' \
+  | LANG=C sort -c \
+  || exit 1
+
+done <<-END
+       expand.c        item_table
+       expand.c        op_table_underscore
+       expand.c        op_table_main
+       expand.c        cond_table
+       acl.c           verbs
+       acl.c           conditions
+END
+
index 1d5e0590dfbe012fca997c55047294255671c3e5..4f64e0a53e5f2e8140027b28c10dba33a6622615 100644 (file)
@@ -21,8 +21,13 @@ enum { ACL_ACCEPT, ACL_DEFER, ACL_DENY, ACL_DISCARD, ACL_DROP, ACL_REQUIRE,
 
 /* ACL verbs */
 
-static uschar *verbs[] =
-  { US"accept", US"defer", US"deny", US"discard", US"drop", US"require",
+static uschar *verbs[] = {
+    US"accept",
+    US"defer",
+    US"deny",
+    US"discard",
+    US"drop",
+    US"require",
     US"warn" };
 
 /* For each verb, the conditions for which "message" or "log_message" are used