summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1999-08-10 10:50:18 +0000
committerJim Meyering <jim@meyering.net>1999-08-10 10:50:18 +0000
commit66bec62b1852c1389265e9d05ec95101cfcf504b (patch)
tree3965b7375f11f95169ec63cfb285b70cd1d76f10
parent9142a5a2a4bfd9b07388e159fc104bb75c25efe8 (diff)
downloadgnulib-66bec62b1852c1389265e9d05ec95101cfcf504b.tar.gz
Include <libintl.h> if ENABLE_NLS.
(_): New macro. (quoting_style_args, quoting_style_v, quotearg_buffer): Add support for locale_quoting_style, using _("`") and _("'") for open and close quote symbols. Do not quote spaces in escape_quoting_style. (quotearg_n_style, quotearg_style): New functions.
-rw-r--r--lib/quotearg.c78
1 files changed, 55 insertions, 23 deletions
diff --git a/lib/quotearg.c b/lib/quotearg.c
index 124f74274e..06f5fea843 100644
--- a/lib/quotearg.c
+++ b/lib/quotearg.c
@@ -17,6 +17,8 @@
/* Written by Paul Eggert <eggert@twinsun.com> */
+/* FIXME: Multibyte characters are not supported yet. */
+
#if HAVE_CONFIG_H
# include <config.h>
#endif
@@ -37,6 +39,13 @@
# define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c))
#endif
+#if ENABLE_NLS
+# include <libintl.h>
+# define _(text) gettext (text)
+#else
+# define _(text) text
+#endif
+
#if HAVE_LIMITS_H
# include <limits.h>
#endif
@@ -76,6 +85,7 @@ char const *const quoting_style_args[] =
"shell-always",
"c",
"escape",
+ "locale",
0
};
@@ -86,7 +96,8 @@ enum quoting_style const quoting_style_vals[] =
shell_quoting_style,
shell_always_quoting_style,
c_quoting_style,
- escape_quoting_style
+ escape_quoting_style,
+ locale_quoting_style
};
/* The default quoting options. */
@@ -150,8 +161,9 @@ quotearg_buffer (char *buffer, size_t buffersize,
{
unsigned char c;
size_t i;
- size_t len;
- int quote_mark;
+ size_t len = 0;
+ char const *quote_string;
+ size_t quote_string_len;
struct quoting_options const *p = o ? o : &default_quoting_options;
enum quoting_style quoting_style = p->style;
#define STORE(c) \
@@ -174,7 +186,6 @@ quotearg_buffer (char *buffer, size_t buffersize,
break;
default:
- len = 0;
for (i = 0; ; i++)
{
if (argsize == (size_t) -1 ? arg[i] == '\0' : i == argsize)
@@ -199,31 +210,39 @@ quotearg_buffer (char *buffer, size_t buffersize,
STORE (c);
}
-
needs_quoting:;
+
+ len = 0;
break;
}
}
/* Fall through. */
case shell_always_quoting_style:
- quote_mark = '\'';
+ STORE ('\'');
+ quote_string = "'";
+ quote_string_len = 1;
break;
case c_quoting_style:
- quote_mark = '"';
+ STORE ('"');
+ quote_string = "\"";
+ quote_string_len = 1;
+ break;
+
+ case locale_quoting_style:
+ for (quote_string = _("`"); *quote_string; quote_string++)
+ STORE (*quote_string);
+ quote_string = _("'");
+ quote_string_len = strlen (quote_string);
break;
default:
- quote_mark = 0;
+ quote_string = 0;
+ quote_string_len = 0;
break;
}
- len = 0;
-
- if (quote_mark)
- STORE (quote_mark);
-
for (i = 0; ! (argsize == (size_t) -1 ? arg[i] == '\0' : i == argsize); i++)
{
c = arg[i];
@@ -245,6 +264,7 @@ quotearg_buffer (char *buffer, size_t buffersize,
case c_quoting_style:
case escape_quoting_style:
+ case locale_quoting_style:
switch (c)
{
case '?': /* Do not generate trigraphs. */
@@ -258,16 +278,12 @@ quotearg_buffer (char *buffer, size_t buffersize,
case '\t': c = 't'; goto store_escape;
case '\v': c = 'v'; goto store_escape;
- case '"':
- if (quoting_style == c_quoting_style)
- goto store_escape;
- break;
+ case ' ': break;
- case ' ':
- if (quoting_style == c_quoting_style)
- goto store_c;
- /* Fall through. */
default:
+ if (quote_string_len
+ && strncmp (arg + i, quote_string, quote_string_len) == 0)
+ goto store_escape;
if (!ISGRAPH (c))
{
STORE ('\\');
@@ -290,8 +306,9 @@ quotearg_buffer (char *buffer, size_t buffersize,
STORE (c);
}
- if (quote_mark)
- STORE (quote_mark);
+ if (quote_string)
+ for (; *quote_string; quote_string++)
+ STORE (*quote_string);
done:
if (len < buffersize)
@@ -356,6 +373,21 @@ quotearg (char const *arg)
}
char *
+quotearg_n_style (unsigned int n, enum quoting_style s, char const *arg)
+{
+ struct quoting_options o;
+ o.style = s;
+ memset (o.quote_these_too, 0, sizeof o.quote_these_too);
+ return quotearg_n_options (n, arg, &o);
+}
+
+char *
+quotearg_style (enum quoting_style s, char const *arg)
+{
+ return quotearg_n_style (0, s, arg);
+}
+
+char *
quotearg_char (char const *arg, char ch)
{
struct quoting_options options;