|
|
1.1 root 1: /******************************************************************************
2: * Copyright (c) 2004, 2008 IBM Corporation
3: * All rights reserved.
4: * This program and the accompanying materials
5: * are made available under the terms of the BSD License
6: * which accompanies this distribution, and is available at
7: * http://www.opensource.org/licenses/bsd-license.php
8: *
9: * Contributors:
10: * IBM Corporation - initial implementation
11: *****************************************************************************/
12:
13: #include <stdlib.h>
14: #include <string.h>
1.1.1.2 ! root 15:
1.1 root 16: extern int main (int, char**);
17: extern int callback (int, char **);
18:
1.1.1.2 ! root 19: int _start(char *arg_string, long len);
! 20: unsigned long callback_entry(void *base, unsigned long len);
! 21:
! 22:
1.1 root 23: #define MAX_ARGV 10
1.1.1.2 ! root 24: static int
1.1 root 25: gen_argv(const char *arg_string, int len, char* argv[])
26: {
27: const char *str, *str_end, *arg_string_end = arg_string + len;
28: int i;
29:
30: str = arg_string;
31: for (i = 0; i < MAX_ARGV; i++)
32: {
33: str_end = str;
34:
35: while((*str_end++ != ' ') && (str_end <= arg_string_end));
36:
37: argv[i] = malloc(str_end-str);
38:
39: memcpy (argv[i], str, str_end-str-1);
40: argv[i][str_end-str-1] = '\0';
41: str = str_end-1;
42: while(*(++str) == ' ');
43: if (str >= arg_string_end)
44: break;
45: }
46: return i+1;
47: }
48:
49:
50:
51: int
52: _start(char * arg_string, long len)
53: {
54: int rc;
55: int argc;
56: char* argv[MAX_ARGV];
57:
58: argc = gen_argv(arg_string, len, argv);
59:
60: rc = main(argc, argv);
61:
62: return rc;
63: }
64:
65: /*
66: * Takes a Forth representation of a string and generates an argument array,
67: * then calls callback().
68: */
69: unsigned long
70: callback_entry(void *base, unsigned long len) {
71: char *argv[MAX_ARGV];
72: int argc;
73:
74: argc = gen_argv(base, len, argv);
75:
76: return (callback(argc, argv));
77: }
78:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.