Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / acorn32 / stand / lib / srt1.c
blobe07aa05196a5665d146a58057fdd5dd8019ced66
1 /* $NetBSD: srt1.c,v 1.5 2005/12/11 12:16:08 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/libkern/libkern.h>
32 #include <lib/libsa/stand.h>
33 #include <riscoscalls.h>
34 #include <srt0.h>
37 /* limit of the memory given to us by RISC OS's WIMPslot; inited by srt0.S */
38 /* init it also to a reasonable value also so it doesnt get into the BSS ! */
39 void *HIMEM = (void *) 0x12000;
42 static int whitespace(char);
44 static int whitespace(char c) {
45 if ((c == '\0') || (c == ' ') || (c == '\t')
46 || (c == '\r') || (c == '\n'))
47 return (1);
48 return (0);
52 enum state {skipping, doing_arg, doing_long_arg};
55 /* build argv/argc, start real main() */
56 void __start(void);
57 int splitargs(char *, int, char**);
58 extern int main(int, char**);
60 extern char edata[], end[];
63 void
64 __start(void)
66 int argc;
67 char *ro_args, *args, **argv;
69 /* Clear BSS */
70 memset(edata, 0, end - edata);
72 /* Define heap. */
73 setheap(end, (void *)(HIMEM - 0x1000));
75 ro_args = os_get_env(NULL, NULL);
77 args = alloc(strlen(ro_args)+10); /* some spare extra */
78 strcpy(args, ro_args);
80 argc = splitargs(args, 0, NULL);
81 argv = alloc(argc * sizeof(*argv));
82 if (argv == NULL)
83 panic("alloc of argv failed");
84 argc = splitargs(args, 1, argv);
86 /* start real main() */
87 os_exit(NULL, main(argc, argv));
90 int
91 splitargs(char *args, int really, char **argv)
93 int argc, i;
94 enum state s;
96 argc = 0;
97 s = skipping;
99 for (i = 0; args[i]; i++){
101 if (whitespace(args[i])) {
102 if (s == doing_arg) {
103 /* end of argument word */
104 if (really)
105 args[i] = '\0';
106 s = skipping;
108 continue;
111 if (args[i] == '"') {
112 /* start or end long arg
113 * (end only if next char is whitespace)
114 * XXX but '" ' cannot be in argument
116 switch (s) {
117 case skipping:
118 /* next char begins new argument word */
119 if (really)
120 argv[argc] = &args[i + 1];
121 argc++;
122 s = doing_long_arg;
123 break;
124 case doing_long_arg:
125 if (whitespace(args[i + 1])) {
126 if (really)
127 args[i] = '\0';
128 s = skipping;
130 break;
131 case doing_arg:
132 /* ignore in the middle of arguments */
133 default:
134 break;
136 continue;
139 /* all other characters */
140 if (s == skipping) {
141 /* begin new argument word */
142 if (really)
143 argv[argc] = &args[i];
144 argc++;
145 s = doing_arg;
148 return argc;
151 void _rtt(void)
154 os_exit(NULL, 0);