1 /* $NetBSD: srt1.c,v 1.4 2005/12/11 12:16:05 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/libsa/stand.h>
32 #include <lib/libkern/libkern.h>
33 #include <riscoscalls.h>
38 if ((c
== '\0') || (c
== ' ') || (c
== '\t')
39 || (c
== '\r') || (c
== '\n'))
44 enum state
{skipping
, doing_arg
, doing_long_arg
};
46 /* build argv/argc, start real main() */
48 int splitargs(char *, int, char**);
49 extern int main(int, char**);
51 extern char edata
[], end
[];
60 memset(edata
, 0, end
- edata
);
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
));
70 panic("alloc of argv failed");
71 argc
= splitargs(args
, 1, argv
);
73 /* start real main() */
74 os_exit(NULL
, main(argc
, argv
));
78 splitargs(char *args
, int really
, char **argv
)
86 for (i
= 0; args
[i
]; i
++){
88 if (whitespace(args
[i
])) {
90 /* end of argument word */
99 /* start or end long arg
100 * (end only if next char is whitespace)
101 * XXX but '" ' cannot be in argument
105 /* next char begins new argument word */
107 argv
[argc
] = &args
[i
+ 1];
112 if (whitespace(args
[i
+ 1])) {
119 /* ignore in the middle of arguments */
126 /* all other characters */
128 /* begin new argument word */
130 argv
[argc
] = &args
[i
];
135 if (s
!= skipping
&& really
)
136 args
[i
] = '\0'; /* to be sure */