summaryrefslogtreecommitdiff
path: root/wsutil/str_util.c
diff options
context:
space:
mode:
authorJeff Morriss <jeff.morriss@ulticom.com>2012-06-25 20:38:45 +0000
committerJeff Morriss <jeff.morriss@ulticom.com>2012-06-25 20:38:45 +0000
commit8eeebf73e0743192e9c395ea240f41dd08ab0670 (patch)
tree88804283396eea97527dc6e8a89129cbfe238403 /wsutil/str_util.c
parentaeceb172a4dce008b0eeae7ff93158b56be6efdf (diff)
downloadwireshark-8eeebf73e0743192e9c395ea240f41dd08ab0670.tar.gz
Move get_args_as_string from ui/util.c into wsutil (maybe not to the best
module, but...). This makes dftest no longer dependent on libui, so stop linking against it. svn path=/trunk/; revision=43481
Diffstat (limited to 'wsutil/str_util.c')
-rw-r--r--wsutil/str_util.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/wsutil/str_util.c b/wsutil/str_util.c
index 717fcb516d..3bbe09a883 100644
--- a/wsutil/str_util.c
+++ b/wsutil/str_util.c
@@ -27,6 +27,7 @@
#endif
#include <glib.h>
+#include <string.h>
#include "str_util.h"
#include <ctype.h>
@@ -90,3 +91,44 @@ isdigit_string(guchar *str)
/* The string contains only digits */
return TRUE;
}
+
+/*
+ * Collect command-line arguments as a string consisting of the arguments,
+ * separated by spaces.
+ */
+char *
+get_args_as_string(int argc, char **argv, int optindex)
+{
+ int len;
+ int i;
+ char *argstring;
+
+ /*
+ * Find out how long the string will be.
+ */
+ len = 0;
+ for (i = optindex; i < argc; i++) {
+ len += (int) strlen(argv[i]);
+ len++; /* space, or '\0' if this is the last argument */
+ }
+
+ /*
+ * Allocate the buffer for the string.
+ */
+ argstring = (char *)g_malloc(len);
+
+ /*
+ * Now construct the string.
+ */
+ argstring[0] = '\0';
+ i = optindex;
+ for (;;) {
+ g_strlcat(argstring, argv[i], len);
+ i++;
+ if (i == argc)
+ break;
+ g_strlcat(argstring, " ", len);
+ }
+ return argstring;
+}
+