diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2008-11-11 16:40:48 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2008-11-11 16:40:48 +0000 |
commit | 27d368b005bdf092442321735c0d426f518d9199 (patch) | |
tree | 67067758c115c8836dc23be85fb5ddbf1e2d7045 /module/wrapper.c | |
parent | 0d244e11569291f8eec9c4268510f72ae3cbfc2a (diff) | |
download | iconv-27d368b005bdf092442321735c0d426f518d9199.tar.gz iconv-27d368b005bdf092442321735c0d426f518d9199.tar.bz2 |
Some kind of half-arsed attempt at parsing command line parameters for *Iconv.
Actually invoke this command through the wrapper code.
svn path=/trunk/iconv/; revision=5684
Diffstat (limited to 'module/wrapper.c')
-rw-r--r-- | module/wrapper.c | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/module/wrapper.c b/module/wrapper.c index 506a5ae..6b15a25 100644 --- a/module/wrapper.c +++ b/module/wrapper.c @@ -1,6 +1,8 @@ /* Wrapper around module API so we can run/test it on non-RO machines */ #include <stdio.h> +#include <stdlib.h> +#include <string.h> #include "header.h" @@ -9,24 +11,60 @@ int main(int argc, char **argv) { _kernel_oserror *error; + char *buf = NULL; + int buf_alloc = 0, buf_len = 0; - if (argc != 1) { - printf("Usage: %s\n", argv[0]); - return 1; + for (int i = 1; i < argc; i++) { + /* Need a leading space for all but the first argument */ + int req = buf_len + (buf_len > 0 ? 1 : 0) + strlen(argv[i]) + 1; + + while (req > buf_alloc) { + char *temp = realloc(buf, buf_alloc + 4096); + if (temp == NULL) { + printf("Insufficient memory for parameters"); + return 1; + } + + buf = temp; + buf_alloc += 4096; + } + + if (buf_len > 0) { + memcpy(buf + buf_len, " ", 1); + buf_len++; + } + + memcpy(buf + buf_len, argv[i], strlen(argv[i])); + + buf_len += strlen(argv[i]); + + buf[buf_len] = '\0'; } error = mod_init(NULL, 0, NULL); if (error != NULL) { + free(buf); printf("mod_init: %s (%d)\n", error->errmess, error->errnum); return 1; } + error = command_handler(buf, argc - 1, CMD_Iconv, NULL); + if (error != NULL) { + free(buf); + printf("command_handler: %s (%d)\n", error->errmess, + error->errnum); + return 1; + } + error = mod_fini(0, 0, NULL); if (error != NULL) { + free(buf); printf("mod_fini: %s (%d)\n", error->errmess, error->errnum); return 1; } + free(buf); + return 0; } |