]> xenbits.xensource.com Git - people/liuw/rumprun.git/commitdiff
Push xen/parseargs() to librumprun_base as rumprun_parseargs().
authorAntti Kantee <pooka@iki.fi>
Tue, 28 Apr 2015 07:38:08 +0000 (07:38 +0000)
committerAntti Kantee <pooka@iki.fi>
Tue, 28 Apr 2015 07:38:08 +0000 (07:38 +0000)
include/rumprun-base/parseargs.h [new file with mode: 0644]
lib/librumprun_base/Makefile
lib/librumprun_base/parseargs.c [new file with mode: 0644]
platform/xen/callmain.c

diff --git a/include/rumprun-base/parseargs.h b/include/rumprun-base/parseargs.h
new file mode 100644 (file)
index 0000000..95a5742
--- /dev/null
@@ -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_ */
index d4cde20160b972879c65fbace6195f9d5b3dd2c5..a737b8419df94b6dff441084aec99a18bd99c920 100644 (file)
@@ -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 (file)
index 0000000..4965781
--- /dev/null
@@ -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 <rumprun-base/parseargs.h>
+
+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;
+       }
+}
index 2aa9044ea14565f570de88bef3394fbb0b650b22..22b57c6e00ef5b03e9a35f910c220054afdf2d86 100644 (file)
 #include <bmk-core/memalloc.h>
 
 #include <rumprun-base/rumprun.h>
+#include <rumprun-base/parseargs.h>
 
 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;