[Pkg-privacy-commits] [irssi-plugin-otr] 128/267: Add new explode string arguments function
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 12:26:25 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch debian
in repository irssi-plugin-otr.
commit 3151b579d5010fce137c70d6d308994ddc901abc
Author: David Goulet <dgoulet at ev0ke.net>
Date: Mon Nov 12 22:06:20 2012 -0500
Add new explode string arguments function
Will be used with the refactoring of the command subsystem. Been tested
out of tree and working.
Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
src/utils.c | 41 +++++++++++++++++++++++++++++++++++++++++
src/utils.h | 1 +
2 files changed, 42 insertions(+)
diff --git a/src/utils.c b/src/utils.c
index 4a301dc..cfbac5e 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -104,6 +104,47 @@ error:
return -1;
}
+void utils_explode_args(const char *_data, char ***_argv, int *_argc)
+{
+ int argc = 1, i = 0;
+ char **argv = NULL, *c, *data = NULL;
+
+ assert(_data);
+
+ data = strndup(_data, strlen(_data));
+ if (!data) {
+ goto error;
+ }
+
+ c = data;
+ while ((c = strchr(c + 1, ' '))) {
+ /* Skip consecutive spaces. */
+ if (*(c + 1) == ' ') {
+ continue;
+ }
+ argc++;
+ }
+
+ argv = malloc(argc * sizeof(char *));
+ if (!argv) {
+ goto error;
+ }
+
+ c = strtok(data, " ");
+ while (c != NULL) {
+ argv[i] = strdup(c);
+ c = strtok(NULL, " ");
+ i++;
+ }
+
+error:
+ *_argv = argv;
+ *_argc = argc;
+
+ free(data);
+ return;
+}
+
void utils_io_explode_args(const char *args, char ***argvp, char ***argv_eolp,
int *argcp)
{
diff --git a/src/utils.h b/src/utils.h
index fe2fc0d..5386dd3 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -34,6 +34,7 @@
void otr_log(SERVER_REC *server, const char *to, int lvl, const char *fmt, ...);
+void utils_explode_args(const char *_data, char ***_argv, int *_argc);
void utils_io_explode_args(const char *args, char ***argvp, char ***argv_eolp,
int *argcp);
int utils_io_extract_smp(const char *data, char **question, char **secret);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/irssi-plugin-otr.git
More information about the Pkg-privacy-commits
mailing list