From 31fc6e64f9d9db08e6fe4c0065c5fd2299091a50 Mon Sep 17 00:00:00 2001 From: Antti Kantee Date: Tue, 28 Apr 2015 07:38:08 +0000 Subject: [PATCH] Push xen/parseargs() to librumprun_base as rumprun_parseargs(). --- include/rumprun-base/parseargs.h | 31 +++++++++++++ lib/librumprun_base/Makefile | 1 + lib/librumprun_base/parseargs.c | 74 ++++++++++++++++++++++++++++++++ platform/xen/callmain.c | 53 ++--------------------- 4 files changed, 109 insertions(+), 50 deletions(-) create mode 100644 include/rumprun-base/parseargs.h create mode 100644 lib/librumprun_base/parseargs.c diff --git a/include/rumprun-base/parseargs.h b/include/rumprun-base/parseargs.h new file mode 100644 index 0000000..95a5742 --- /dev/null +++ b/include/rumprun-base/parseargs.h @@ -0,0 +1,31 @@ +/*- + * Copyright (c) 2014 Citrix. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _RUMPRUN_BASE_PARSEARGS_H_ +#define _RUMPRUN_BASE_PARSEARGS_H_ + +void rumprun_parseargs(char *, int *, char **); + +#endif /* _RUMPRUN_BASE_PARSEARGS_H_ */ diff --git a/lib/librumprun_base/Makefile b/lib/librumprun_base/Makefile index d4cde20..a737b84 100644 --- a/lib/librumprun_base/Makefile +++ b/lib/librumprun_base/Makefile @@ -6,6 +6,7 @@ LIB= rumprun_base LIBISPRIVATE= # defined SRCS= rumprun.c +SRCS+= parseargs.c SRCS+= malloc.c netbsd_initfini.c signals.c syscall_misc.c SRCS+= __errno.c _lwp.c libc_stubs.c diff --git a/lib/librumprun_base/parseargs.c b/lib/librumprun_base/parseargs.c new file mode 100644 index 0000000..4965781 --- /dev/null +++ b/lib/librumprun_base/parseargs.c @@ -0,0 +1,74 @@ +/*- + * Copyright (c) 2014 Citrix. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +void +rumprun_parseargs(char *p, int *nargs, char **outarray) +{ + char *out = 0; + int quote = -1; /* -1 means outside arg, 0 or '"' or '\'' inside */ + + *nargs = 0; + + for (;;) { + int ac = *p++; + int rc = ac; + if (ac == '\\') + rc = *p++; + if (!rc || ac==' ' || ac=='\n' || ac=='\t') { + /* any kind of delimiter */ + if (!rc || quote==0) { + /* ending an argument */ + if (out) + *out++ = 0; + quote = -1; + } + if (!rc) + /* definitely quit then */ + break; + if (quote<0) + /* not in an argument now */ + continue; + } + if (quote<0) { + /* starting an argument */ + if (outarray) + outarray[*nargs] = out = p-1; + (*nargs)++; + quote = 0; + } + if (quote > 0 && ac == quote) { + quote = 0; + continue; + } + if (ac == '\'' || ac == '"') { + quote = ac; + continue; + } + if (out) + *out++ = rc; + } +} diff --git a/platform/xen/callmain.c b/platform/xen/callmain.c index 2aa9044..22b57c6 100644 --- a/platform/xen/callmain.c +++ b/platform/xen/callmain.c @@ -29,57 +29,10 @@ #include #include +#include extern int main(int argc, char **argv); -static void -parseargs(char *p, int *nargs, char **outarray) -{ - char *out = 0; - int quote = -1; /* -1 means outside arg, 0 or '"' or '\'' inside */ - - *nargs = 0; - - for (;;) { - int ac = *p++; - int rc = ac; - if (ac == '\\') - rc = *p++; - if (!rc || ac==' ' || ac=='\n' || ac=='\t') { - /* any kind of delimiter */ - if (!rc || quote==0) { - /* ending an argument */ - if (out) - *out++ = 0; - quote = -1; - } - if (!rc) - /* definitely quit then */ - break; - if (quote<0) - /* not in an argument now */ - continue; - } - if (quote<0) { - /* starting an argument */ - if (outarray) - outarray[*nargs] = out = p-1; - (*nargs)++; - quote = 0; - } - if (quote > 0 && ac == quote) { - quote = 0; - continue; - } - if (ac == '\'' || ac == '"') { - quote = ac; - continue; - } - if (out) - *out++ = rc; - } -} - void __default_app_main(start_info_t *); void __default_app_main(start_info_t *si) @@ -90,10 +43,10 @@ __default_app_main(start_info_t *si) char **argv; void *cookie; - parseargs(rawcmdline, &nargs, 0); + rumprun_parseargs(rawcmdline, &nargs, 0); argv = bmk_xmalloc(sizeof(*argv) * (nargs+3)); argv[0] = argv0; - parseargs(rawcmdline, &nargs, argv+1); + rumprun_parseargs(rawcmdline, &nargs, argv+1); argv[nargs+1] = 0; argv[nargs+2] = 0; -- 2.39.5