|
|
ffd6ed |
From b361a8a13b4cea045315a018a79374e0203ad1fc Mon Sep 17 00:00:00 2001
|
|
|
ffd6ed |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
ffd6ed |
Date: Wed, 17 Dec 2014 12:34:53 +0000
|
|
|
ffd6ed |
Subject: [PATCH] fish: Move 'is_true' function to library utilities.
|
|
|
ffd6ed |
|
|
|
ffd6ed |
The 'is_true' function can be useful elsewhere, not just for parsing
|
|
|
ffd6ed |
guestfish command parameters.
|
|
|
ffd6ed |
|
|
|
ffd6ed |
This is just code motion.
|
|
|
ffd6ed |
|
|
|
ffd6ed |
(cherry picked from commit bdcd2fabe9a5ba6f61e662986fcd92e352f203c0)
|
|
|
ffd6ed |
---
|
|
|
ffd6ed |
fish/fish.c | 26 --------------------------
|
|
|
ffd6ed |
generator/fish.ml | 21 ++++++++++++++++-----
|
|
|
ffd6ed |
src/guestfs-internal-frontend.h | 1 +
|
|
|
ffd6ed |
src/utils.c | 23 +++++++++++++++++++++++
|
|
|
ffd6ed |
4 files changed, 40 insertions(+), 31 deletions(-)
|
|
|
ffd6ed |
|
|
|
ffd6ed |
diff --git a/fish/fish.c b/fish/fish.c
|
|
|
ffd6ed |
index 981a7d4..6d07f36 100644
|
|
|
ffd6ed |
--- a/fish/fish.c
|
|
|
ffd6ed |
+++ b/fish/fish.c
|
|
|
ffd6ed |
@@ -1293,32 +1293,6 @@ print_table (char *const *argv)
|
|
|
ffd6ed |
printf ("%s: %s\n", argv[i], argv[i+1]);
|
|
|
ffd6ed |
}
|
|
|
ffd6ed |
|
|
|
ffd6ed |
-int
|
|
|
ffd6ed |
-is_true (const char *str)
|
|
|
ffd6ed |
-{
|
|
|
ffd6ed |
- /* Similar to Tcl_GetBoolean. */
|
|
|
ffd6ed |
-
|
|
|
ffd6ed |
- if (STREQ (str, "1") ||
|
|
|
ffd6ed |
- STRCASEEQ (str, "true") ||
|
|
|
ffd6ed |
- STRCASEEQ (str, "t") ||
|
|
|
ffd6ed |
- STRCASEEQ (str, "yes") ||
|
|
|
ffd6ed |
- STRCASEEQ (str, "y") ||
|
|
|
ffd6ed |
- STRCASEEQ (str, "on"))
|
|
|
ffd6ed |
- return 1;
|
|
|
ffd6ed |
-
|
|
|
ffd6ed |
- if (STREQ (str, "0") ||
|
|
|
ffd6ed |
- STRCASEEQ (str, "false") ||
|
|
|
ffd6ed |
- STRCASEEQ (str, "f") ||
|
|
|
ffd6ed |
- STRCASEEQ (str, "no") ||
|
|
|
ffd6ed |
- STRCASEEQ (str, "n") ||
|
|
|
ffd6ed |
- STRCASEEQ (str, "off"))
|
|
|
ffd6ed |
- return 0;
|
|
|
ffd6ed |
-
|
|
|
ffd6ed |
- fprintf (stderr, _("%s: '%s': invalid boolean value, use 'true' or 'false'\n"),
|
|
|
ffd6ed |
- program_name, str);
|
|
|
ffd6ed |
- return -1;
|
|
|
ffd6ed |
-}
|
|
|
ffd6ed |
-
|
|
|
ffd6ed |
/* Free strings from a non-NULL terminated char** */
|
|
|
ffd6ed |
static void
|
|
|
ffd6ed |
free_n_strings (char **str, size_t len)
|
|
|
ffd6ed |
diff --git a/generator/fish.ml b/generator/fish.ml
|
|
|
ffd6ed |
index 3f53ffa..6d6802a 100644
|
|
|
ffd6ed |
--- a/generator/fish.ml
|
|
|
ffd6ed |
+++ b/generator/fish.ml
|
|
|
ffd6ed |
@@ -84,12 +84,15 @@ let generate_fish_cmds () =
|
|
|
ffd6ed |
pr "#include <string.h>\n";
|
|
|
ffd6ed |
pr "#include <inttypes.h>\n";
|
|
|
ffd6ed |
pr "#include <libintl.h>\n";
|
|
|
ffd6ed |
+ pr "#include <errno.h>\n";
|
|
|
ffd6ed |
pr "\n";
|
|
|
ffd6ed |
pr "#include \"c-ctype.h\"\n";
|
|
|
ffd6ed |
pr "#include \"full-write.h\"\n";
|
|
|
ffd6ed |
pr "#include \"xstrtol.h\"\n";
|
|
|
ffd6ed |
pr "\n";
|
|
|
ffd6ed |
- pr "#include <guestfs.h>\n";
|
|
|
ffd6ed |
+ pr "#include \"guestfs.h\"\n";
|
|
|
ffd6ed |
+ pr "#include \"guestfs-internal-frontend.h\"\n";
|
|
|
ffd6ed |
+ pr "\n";
|
|
|
ffd6ed |
pr "#include \"fish.h\"\n";
|
|
|
ffd6ed |
pr "#include \"fish-cmds.h\"\n";
|
|
|
ffd6ed |
pr "#include \"options.h\"\n";
|
|
|
ffd6ed |
@@ -479,8 +482,12 @@ Guestfish will prompt for these separately."
|
|
|
ffd6ed |
pr " input_lineno++;\n";
|
|
|
ffd6ed |
pr " if (%s == NULL) goto out_%s;\n" name name
|
|
|
ffd6ed |
| Bool name ->
|
|
|
ffd6ed |
- pr " switch (is_true (argv[i++])) {\n";
|
|
|
ffd6ed |
- pr " case -1: goto out_%s;\n" name;
|
|
|
ffd6ed |
+ pr " switch (guestfs___is_true (argv[i++])) {\n";
|
|
|
ffd6ed |
+ pr " case -1:\n";
|
|
|
ffd6ed |
+ pr " fprintf (stderr,\n";
|
|
|
ffd6ed |
+ pr " _(\"%%s: '%%s': invalid boolean value, use 'true' or 'false'\\n\"),\n";
|
|
|
ffd6ed |
+ pr " program_name, argv[i-1]);\n";
|
|
|
ffd6ed |
+ pr " goto out_%s;\n" name;
|
|
|
ffd6ed |
pr " case 0: %s = 0; break;\n" name;
|
|
|
ffd6ed |
pr " default: %s = 1;\n" name;
|
|
|
ffd6ed |
pr " }\n"
|
|
|
ffd6ed |
@@ -518,8 +525,12 @@ Guestfish will prompt for these separately."
|
|
|
ffd6ed |
pr "if (STRPREFIX (argv[i], \"%s:\")) {\n" n;
|
|
|
ffd6ed |
(match argt with
|
|
|
ffd6ed |
| OBool n ->
|
|
|
ffd6ed |
- pr " switch (is_true (&argv[i][%d])) {\n" (len+1);
|
|
|
ffd6ed |
- pr " case -1: goto out;\n";
|
|
|
ffd6ed |
+ pr " switch (guestfs___is_true (&argv[i][%d])) {\n" (len+1);
|
|
|
ffd6ed |
+ pr " case -1:\n";
|
|
|
ffd6ed |
+ pr " fprintf (stderr,\n";
|
|
|
ffd6ed |
+ pr " _(\"%%s: '%%s': invalid boolean value, use 'true' or 'false'\\n\"),\n";
|
|
|
ffd6ed |
+ pr " program_name, &argv[i][%d]);\n" (len+1);
|
|
|
ffd6ed |
+ pr " goto out;\n";
|
|
|
ffd6ed |
pr " case 0: optargs_s.%s = 0; break;\n" n;
|
|
|
ffd6ed |
pr " default: optargs_s.%s = 1;\n" n;
|
|
|
ffd6ed |
pr " }\n"
|
|
|
ffd6ed |
diff --git a/src/guestfs-internal-frontend.h b/src/guestfs-internal-frontend.h
|
|
|
ffd6ed |
index 5c5d957..ba3ddde 100644
|
|
|
ffd6ed |
--- a/src/guestfs-internal-frontend.h
|
|
|
ffd6ed |
+++ b/src/guestfs-internal-frontend.h
|
|
|
ffd6ed |
@@ -105,6 +105,7 @@ extern char **guestfs___split_string (char sep, const char *);
|
|
|
ffd6ed |
extern char *guestfs___exit_status_to_string (int status, const char *cmd_name, char *buffer, size_t buflen);
|
|
|
ffd6ed |
extern int guestfs___random_string (char *ret, size_t len);
|
|
|
ffd6ed |
extern char *guestfs___drive_name (size_t index, char *ret);
|
|
|
ffd6ed |
+extern int guestfs___is_true (const char *str);
|
|
|
ffd6ed |
|
|
|
ffd6ed |
/* These functions are used internally by the CLEANUP_* macros.
|
|
|
ffd6ed |
* Don't call them directly.
|
|
|
ffd6ed |
diff --git a/src/utils.c b/src/utils.c
|
|
|
ffd6ed |
index be7f643..11c6953 100644
|
|
|
ffd6ed |
--- a/src/utils.c
|
|
|
ffd6ed |
+++ b/src/utils.c
|
|
|
ffd6ed |
@@ -270,3 +270,26 @@ guestfs___drive_name (size_t index, char *ret)
|
|
|
ffd6ed |
*ret = '\0';
|
|
|
ffd6ed |
return ret;
|
|
|
ffd6ed |
}
|
|
|
ffd6ed |
+
|
|
|
ffd6ed |
+/* Similar to Tcl_GetBoolean. */
|
|
|
ffd6ed |
+int
|
|
|
ffd6ed |
+guestfs___is_true (const char *str)
|
|
|
ffd6ed |
+{
|
|
|
ffd6ed |
+ if (STREQ (str, "1") ||
|
|
|
ffd6ed |
+ STRCASEEQ (str, "true") ||
|
|
|
ffd6ed |
+ STRCASEEQ (str, "t") ||
|
|
|
ffd6ed |
+ STRCASEEQ (str, "yes") ||
|
|
|
ffd6ed |
+ STRCASEEQ (str, "y") ||
|
|
|
ffd6ed |
+ STRCASEEQ (str, "on"))
|
|
|
ffd6ed |
+ return 1;
|
|
|
ffd6ed |
+
|
|
|
ffd6ed |
+ if (STREQ (str, "0") ||
|
|
|
ffd6ed |
+ STRCASEEQ (str, "false") ||
|
|
|
ffd6ed |
+ STRCASEEQ (str, "f") ||
|
|
|
ffd6ed |
+ STRCASEEQ (str, "no") ||
|
|
|
ffd6ed |
+ STRCASEEQ (str, "n") ||
|
|
|
ffd6ed |
+ STRCASEEQ (str, "off"))
|
|
|
ffd6ed |
+ return 0;
|
|
|
ffd6ed |
+
|
|
|
ffd6ed |
+ return -1;
|
|
|
ffd6ed |
+}
|
|
|
ffd6ed |
--
|
|
|
ffd6ed |
1.8.3.1
|
|
|
ffd6ed |
|