>From daadd70793142da47410583432bd9ac8a45341c8 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Thu, 13 Dec 2012 17:19:47 -0800
Subject: [PATCH 2/2] Check that the distributed files use a safe ASCII
 subset.

* Makefile (TAB_CHAR, INVALID_CHAR1, INVALID_CHAR2, INVALID_CHAR3)
(INVALID_CHAR): New macros.
(check_character_set): New rule.
(check): Use it.
---
 Makefile | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index a579ab8..feec727 100644
--- a/Makefile
+++ b/Makefile
@@ -264,6 +264,17 @@ VALIDATE_ENV = \
   SP_CHARSET_FIXED=YES \
   SP_ENCODING=UTF-8
 
+# INVALID_CHAR is a regular expression that matches invalid characters in
+# distributed files.  For now, stick to a safe subset of ASCII.
+# The caller must set the shell variable 'sharp' to the character '#',
+# since Makefile macros cannot contain '#'.
+# TAB_CHAR is a single tab character, in single quotes.
+TAB_CHAR=	'	'
+INVALID_CHAR1=	$(TAB_CHAR)' !\"'$$sharp'$$%&'\''()*+,./0123456789:;<=>?@'
+INVALID_CHAR2=	'ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\^_`'
+INVALID_CHAR3=	'abcdefghijklmnopqrstuvwxyz{|}~'
+INVALID_CHAR=	'[^]'$(INVALID_CHAR1)$(INVALID_CHAR2)$(INVALID_CHAR3)'-]'
+
 # Flags to give 'tar' when making a distribution.
 # Try to use flags appropriate for GNU tar.
 GNUTARFLAGS=	--numeric-owner --owner=0 --group=0 --mode=go+u,go-w
@@ -406,7 +417,10 @@ tzselect:	tzselect.ksh
 			<$? >$@
 		chmod +x $@
 
-check:		check_tables check_web
+check:		check_character_set check_tables check_web
+
+check_character_set: $(ENCHILADA)
+		sharp='#'; ! grep -n $(INVALID_CHAR) $(ENCHILADA)
 
 check_tables:	checktab.awk $(PRIMARY_YDATA)
 		$(AWK) -f checktab.awk $(PRIMARY_YDATA)
-- 
1.7.11.7

