1 /* $NetBSD: srt1.c,v 1.5 2005/12/11 12:16:08 christos Exp $ */
4 * Copyright (c) 2001 Ben Harris.
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
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>
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'))
52 enum state
{skipping
, doing_arg
, doing_long_arg
};
55 /* build argv/argc, start real main() */
57 int splitargs(char *, int, char**);
58 extern int main(int, char**);
60 extern char edata
[], end
[];
67 char *ro_args
, *args
, **argv
;
70 memset(edata
, 0, end
- edata
);
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
));
83 panic("alloc of argv failed");
84 argc
= splitargs(args
, 1, argv
);
86 /* start real main() */
87 os_exit(NULL
, main(argc
, argv
));
91 splitargs(char *args
, int really
, char **argv
)
99 for (i
= 0; args
[i
]; i
++){
101 if (whitespace(args
[i
])) {
102 if (s
== doing_arg
) {
103 /* end of argument word */
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
118 /* next char begins new argument word */
120 argv
[argc
] = &args
[i
+ 1];
125 if (whitespace(args
[i
+ 1])) {
132 /* ignore in the middle of arguments */
139 /* all other characters */
141 /* begin new argument word */
143 argv
[argc
] = &args
[i
];