forked from nimblemachines/muforth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
69 lines (57 loc) · 1.55 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* This file is part of muFORTH: http://muforth.nimblemachines.com/
*
* Copyright (c) 2002-2012 David Frech. All rights reserved, and all wrongs
* reversed. (See the file COPYRIGHT for details.)
*/
#include "muforth.h"
#include <stdlib.h> /* exit(3) */
static struct counted_string *pcmd_line;
/*
* Unlike memcpy, which STOOPIDLY returns dest, rather than something
* USEFUL, this routine returns dest + length. It also calculates the
* length of the string for you - but doesn't copy the trailing null,
* unlike strcpy.
*/
static char *str_copy(char *dest, char *src)
{
size_t length = strlen(src);
return memcpy(dest, src, length) + length;
}
static void convert_command_line(int argc, char *argv[])
{
char *pline;
/* skip arg[0] */
argc--;
argv++;
pcmd_line = (struct counted_string *)ph;
pline = pcmd_line->data;
while (argc--)
{
pline = str_copy(pline, *argv++);
*pline++ = ' ';
}
pcmd_line->length = pline - pcmd_line->data;
/*
* No need to null-terminate! This string is evaluated by the Forth
* parser, not C code. Any pieces - like filenames - that get passed to
* C are copied out of this string into the dictionary and
* null-terminated first - just like input from _any other_ source.
*/
ph = (cell *)ALIGNED(pline);
}
void mu_push_command_line()
{
PUSH_ADDR(&pcmd_line->data);
}
void mu_bye()
{
exit(0);
}
int main(int argc, char *argv[])
{
muforth_init();
convert_command_line(argc, argv);
muforth_start();
return 0;
}