From 1f69c1f1a64f5e68f00a53ba325dcbcb897df4d6 Mon Sep 17 00:00:00 2001
From: Akim Demaille <demaille@gostai.com>
Date: Sat, 28 Jan 2012 13:56:08 +0100
Subject: [PATCH] use a more consistent quoting style.

See http://lists.gnu.org/archive/html/bug-bison/2012-01/msg00120.html.
Use quotearg as often as possible instead of leaving the choice of
the quotes to the translators.  Provide a means to disable locale-
dependent quotes.

	* bootstrap.conf (gnulib_modules): Remove quote.
	* lib/quote.h, lib/quote.c: New, based on gnulib's.
	(quote_init): New.
	* src/main.c: Call it.
	* tests/atlocal.in: Disable translated quotes.
	* src/files.c: Use quote() on printf arguments instead of quotes
	in the format string.
---
 bootstrap.conf   |    2 +-
 lib/.gitignore   |    4 ----
 lib/quote.c      |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/quote.h      |   21 +++++++++++++++++++++
 m4/.gitignore    |    1 +
 src/files.c      |    2 +-
 src/main.c       |    3 ++-
 tests/atlocal.in |    4 ++++
 8 files changed, 81 insertions(+), 7 deletions(-)
 create mode 100644 lib/quote.c
 create mode 100644 lib/quote.h

diff --git a/bootstrap.conf b/bootstrap.conf
index 599b778..6f422c1 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -22,7 +22,7 @@ gnulib_modules='
   gettext git-version-gen gitlog-to-changelog
   gpl-3.0 hash inttypes isnan javacomp-script
   javaexec-script ldexpl maintainer-makefile malloc-gnu mbschr mbsrchr
-  mbswidth obstack perror pipe-posix quote quotearg realloc-posix
+  mbswidth obstack perror pipe-posix quotearg realloc-posix
   spawn-pipe stdbool stpcpy strdup-posix strerror strtoul strverscmp
   unistd unistd-safer unlocked-io update-copyright unsetenv verify
   warnings xalloc xalloc-die xstrndup
diff --git a/lib/.gitignore b/lib/.gitignore
index 54edced..737dbba 100644
--- a/lib/.gitignore
+++ b/lib/.gitignore
@@ -1,4 +1,3 @@
-
 /*.a
 /*.bak
 /*.o
@@ -125,8 +124,6 @@
 /printf-parse.c
 /printf-parse.h
 /printf.c
-/quote.c
-/quote.h
 /quotearg.c
 /quotearg.h
 /rawmemchr.c
@@ -242,7 +239,6 @@
 /xsize.h
 /xstrndup.c
 /xstrndup.h
-
 /c-strcaseeq.h
 /fd-hook.c
 /fd-hook.h
diff --git a/lib/quote.c b/lib/quote.c
new file mode 100644
index 0000000..c086c1c
--- /dev/null
+++ b/lib/quote.c
@@ -0,0 +1,51 @@
+/* quote.c - quote arguments for output
+
+   Copyright (C) 1998-2001, 2003, 2005-2006, 2009-2012 Free Software
+   Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paul Eggert <eggert@twinsun.com> */
+
+#include <config.h>
+#include <stdlib.h>
+
+#include "quotearg.h"
+#include "quote.h"
+
+enum quoting_style bison_quoting_style = locale_quoting_style;
+
+void
+quote_init (void)
+{
+  if (getenv ("BISON_C_QUOTING_STYLE"))
+    bison_quoting_style = shell_quoting_style;
+  set_quoting_style (0, QA_ELIDE_OUTER_QUOTES);
+}
+
+/* Return an unambiguous printable representation of NAME,
+   allocated in slot N, suitable for diagnostics.  */
+char const *
+quote_n (int n, char const *name)
+{
+  return quotearg_n_style (n, bison_quoting_style, name);
+}
+
+/* Return an unambiguous printable representation of NAME,
+   suitable for diagnostics.  */
+char const *
+quote (char const *name)
+{
+  return quote_n (0, name);
+}
diff --git a/lib/quote.h b/lib/quote.h
new file mode 100644
index 0000000..b4d742f
--- /dev/null
+++ b/lib/quote.h
@@ -0,0 +1,21 @@
+/* quote.h - prototypes for quote.c
+
+   Copyright (C) 1998-2001, 2003, 2009-2012 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+
+void quote_init (void);
+char const *quote_n (int n, char const *name);
+char const *quote (char const *name);
diff --git a/m4/.gitignore b/m4/.gitignore
index c50ed39..f46e164 100644
--- a/m4/.gitignore
+++ b/m4/.gitignore
@@ -166,3 +166,4 @@
 /raise.m4
 /ssize_t.m4
 /strerror_r.m4
+/gnulib-comp.m4
diff --git a/src/files.c b/src/files.c
index 66d9218..b66b513 100644
--- a/src/files.c
+++ b/src/files.c
@@ -109,7 +109,7 @@ xfopen (const char *name, const char *mode)
 
   ptr = fopen_safer (name, mode);
   if (!ptr)
-    error (EXIT_FAILURE, get_errno (), _("cannot open file '%s'"), name);
+    error (EXIT_FAILURE, get_errno (), _("cannot open file %s"), quote (name));
 
   return ptr;
 }
diff --git a/src/main.c b/src/main.c
index e777ca0..2fafce1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -39,6 +39,7 @@
 #include "muscle-tab.h"
 #include "nullable.h"
 #include "output.h"
+#include "quote.h"
 #include "print.h"
 #include "print_graph.h"
 #include "print-xml.h"
@@ -52,7 +53,6 @@
 #include "uniqstr.h"
 
 
-
 int
 main (int argc, char *argv[])
 {
@@ -62,6 +62,7 @@ main (int argc, char *argv[])
   (void) bindtextdomain ("bison-runtime", LOCALEDIR);
   (void) textdomain (PACKAGE);
 
+  quote_init ();
   uniqstrs_new ();
   muscle_init ();
 
diff --git a/tests/atlocal.in b/tests/atlocal.in
index 764540c..cc016ea 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -45,3 +45,7 @@ CONF_JAVA='@CONF_JAVA@'
 
 # We need egrep.
 : ${EGREP='@EGREP@'}
+
+# Use simple quotes.
+BISON_C_QUOTING_STYLE=1
+export BISON_C_QUOTING_STYLE
-- 
1.7.7.4

