summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Jennings <mej@kainx.org>2006-02-24 21:46:12 +0000
committerMichael Jennings <mej@kainx.org>2006-02-24 21:46:12 +0000
commit8b56abf863d4bc8c5c542df80a7eaf236ca8dc9a (patch)
tree9268217353894cf5730bfb27a24e2465b42a63f2
parent5d208fe25b4ae86c10a4ea0af31c5980c33b2afd (diff)
downloadlibast-8b56abf863d4bc8c5c542df80a7eaf236ca8dc9a.tar.gz
Fri Feb 24 16:45:38 2006 Michael Jennings (mej)
Make removal of options from argv[] optional and off by default. Fixes Eterm problem with WM_COMMAND entries being empty. ---------------------------------------------------------------------- SVN revision: 20765
-rw-r--r--ChangeLog5
-rw-r--r--include/libast.h15
-rw-r--r--src/options.c10
-rw-r--r--test/test.c1
4 files changed, 24 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 696d05a..f28eaf2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -768,3 +768,8 @@ Sun Feb 5 00:58:03 2006 Michael Jennings (mej)
Fixed off-by-1 error in spiftool_join().
----------------------------------------------------------------------
+Fri Feb 24 16:45:38 2006 Michael Jennings (mej)
+
+Make removal of options from argv[] optional and off by default.
+Fixes Eterm problem with WM_COMMAND entries being empty.
+----------------------------------------------------------------------
diff --git a/include/libast.h b/include/libast.h
index 5c767c5..956d818 100644
--- a/include/libast.h
+++ b/include/libast.h
@@ -1743,9 +1743,7 @@ extern const char *true_vals[], *false_vals[];
*
* The option parser settings structure (spifopt_settings_t_struct)
* has an 8-bit flag field which contains toggles affecting the
- * parser's internal behavior. As a general rule, these will not be
- * flags that client programs will want to manipulate. In the event
- * that you do wish to manipulate these flags, use the
+ * parser's internal behavior. Manipulate these flags using the
* SPIFOPT_FLAGS_*() macros.
*
* @ingroup DOXGRP_OPT
@@ -1760,6 +1758,17 @@ extern const char *true_vals[], *false_vals[];
* this flag is not required.
*/
#define SPIFOPT_SETTING_PREPARSE (1UL << 0)
+
+/**
+ * Remove arguments flag. This flag controls whether spifopt_parse()
+ * will return argv[] unmodified or remove all option parameters. For
+ * example: if this flag were set and argv[] contained "tar", "-zcvf",
+ * "foo.tar.gz", "foo/" prior to calling spifopt_parse(), after option
+ * parsing was complete, argv[] would contain only "tar", "foo/".
+ * Everything else would be consumed by the options "-z", "-c", "-v",
+ * and "-f foo.tar.gz". Use of this flag is not required.
+ */
+#define SPIFOPT_SETTING_REMOVE_ARGS (1UL << 1)
/*@}*/
/*@{*/
diff --git a/src/options.c b/src/options.c
index 05173f6..0a8b4b9 100644
--- a/src/options.c
+++ b/src/options.c
@@ -498,7 +498,9 @@ handle_arglist(spif_int32_t n, spif_charptr_t val_ptr, unsigned char hasequal,
for (k = 0; k < len; k++) {
tmp[k] = SPIF_CAST(charptr) STRDUP(argv[k + i]);
D_OPTIONS(("tmp[%d] == %s\n", k, tmp[k]));
- argv[k + i] = NULL;
+ if (SPIFOPT_FLAGS_IS_SET(SPIFOPT_SETTING_REMOVE_ARGS)) {
+ argv[k + i] = NULL;
+ }
}
tmp[k] = SPIF_NULL_TYPE(charptr);
*(SPIF_CAST_C(spif_charptr_t **) SPIFOPT_OPT_VALUE(n)) = tmp;
@@ -560,7 +562,7 @@ spifopt_parse(int argc, char *argv[])
NEXT_LETTER();
}
}
- if (!SPIFOPT_FLAGS_IS_SET(SPIFOPT_SETTING_PREPARSE)) {
+ if (!SPIFOPT_FLAGS_IS_SET(SPIFOPT_SETTING_PREPARSE) && SPIFOPT_FLAGS_IS_SET(SPIFOPT_SETTING_REMOVE_ARGS)) {
argv[i] = NULL;
}
@@ -663,7 +665,7 @@ spifopt_parse(int argc, char *argv[])
((spifopt_abstract_handler_t) SPIFOPT_OPT_VALUE(j))(val_ptr);
}
}
- if (!SPIFOPT_FLAGS_IS_SET(SPIFOPT_SETTING_PREPARSE)) {
+ if (!SPIFOPT_FLAGS_IS_SET(SPIFOPT_SETTING_PREPARSE) && SPIFOPT_FLAGS_IS_SET(SPIFOPT_SETTING_REMOVE_ARGS)) {
argv[i] = NULL;
}
NEXT_LOOP();
@@ -671,7 +673,7 @@ spifopt_parse(int argc, char *argv[])
if (SPIFOPT_FLAGS_IS_SET(SPIFOPT_SETTING_PREPARSE)) {
SPIFOPT_FLAGS_CLEAR(SPIFOPT_SETTING_PREPARSE);
- } else {
+ } else if (SPIFOPT_FLAGS_IS_SET(SPIFOPT_SETTING_REMOVE_ARGS)) {
for (i = 1, j = 1; i < argc; i++) {
if (argv[i]) {
argv[j] = argv[i];
diff --git a/test/test.c b/test/test.c
index ddd0bfc..c720cbf 100644
--- a/test/test.c
+++ b/test/test.c
@@ -563,6 +563,7 @@ test_options(void)
SPIFOPT_NUMOPTS_SET(sizeof(opts2) / sizeof(spifopt_t));
SPIFOPT_ALLOWBAD_SET(0);
SPIFOPT_FLAGS_SET(SPIFOPT_SETTING_PREPARSE);
+ SPIFOPT_FLAGS_SET(SPIFOPT_SETTING_REMOVE_ARGS);
spifopt_parse(argc2, argv2);
TEST_FAIL_IF(strcmp(SPIF_CHARPTR_C(display), "foo:0"));
TEST_FAIL_IF(name != NULL);