No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / acorn26 / stand / lib / srt1.c
blob53cc2235c79cf59ff4a6f946fabcb8da782d958a
1 /* $NetBSD: srt1.c,v 1.4 2005/12/11 12:16:05 christos Exp $ */
3 /*
4 * Copyright (c) 2001 Ben Harris.
5 * Copyright (c) 1996
6 * Matthias Drochner. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /* Command-line parsing from i386 doscommain.c */
31 #include <lib/libsa/stand.h>
32 #include <lib/libkern/libkern.h>
33 #include <riscoscalls.h>
35 static int
36 whitespace(char c)
38 if ((c == '\0') || (c == ' ') || (c == '\t')
39 || (c == '\r') || (c == '\n'))
40 return (1);
41 return (0);
44 enum state {skipping, doing_arg, doing_long_arg};
46 /* build argv/argc, start real main() */
47 void __start(void);
48 int splitargs(char *, int, char**);
49 extern int main(int, char**);
51 extern char edata[], end[];
53 void
54 __start(void)
56 int argc;
57 char *args, **argv;
59 /* Clear BSS */
60 memset(edata, 0, end - edata);
62 /* Define heap. */
63 setheap(end, (void *)(HIMEM - 0x1000));
65 args = os_get_env(NULL, NULL);
67 argc = splitargs(args, 0, NULL);
68 argv = alloc(argc * sizeof(*argv));
69 if (argv == NULL)
70 panic("alloc of argv failed");
71 argc = splitargs(args, 1, argv);
73 /* start real main() */
74 os_exit(NULL, main(argc, argv));
77 int
78 splitargs(char *args, int really, char **argv)
80 int argc, i;
81 enum state s;
83 argc = 0;
84 s = skipping;
86 for (i = 0; args[i]; i++){
88 if (whitespace(args[i])) {
89 if (s == doing_arg) {
90 /* end of argument word */
91 if (really)
92 args[i] = '\0';
93 s = skipping;
95 continue;
98 if (args[i] == '"') {
99 /* start or end long arg
100 * (end only if next char is whitespace)
101 * XXX but '" ' cannot be in argument
103 switch (s) {
104 case skipping:
105 /* next char begins new argument word */
106 if (really)
107 argv[argc] = &args[i + 1];
108 argc++;
109 s = doing_long_arg;
110 break;
111 case doing_long_arg:
112 if (whitespace(args[i + 1])) {
113 if (really)
114 args[i] = '\0';
115 s = skipping;
117 break;
118 case doing_arg:
119 /* ignore in the middle of arguments */
120 default:
121 break;
123 continue;
126 /* all other characters */
127 if (s == skipping) {
128 /* begin new argument word */
129 if (really)
130 argv[argc] = &args[i];
131 argc++;
132 s = doing_arg;
135 if (s != skipping && really)
136 args[i] = '\0'; /* to be sure */
137 return argc;
140 void _rtt(void)
143 os_exit(NULL, 0);