*** empty log message ***

This commit is contained in:
hyung-hwan 2005-03-23 14:57:35 +00:00
parent 3f31c91d2f
commit 628d53c667

View File

@ -1,6 +1,7 @@
#include <xp/lisp/lisp.h>
#include <xp/c/stdio.h>
#include <xp/c/ctype.h>
#include <xp/c/stdcli.h>
#ifdef LINUX
#include <mcheck.h>
@ -35,10 +36,65 @@ int to_int (const xp_char_t* str)
#include <locale.h>
int handle_cli_error (
const xp_cli_t* cli, int code,
const xp_char_t* name, const xp_char_t* value)
{
xp_printf (XP_TEXT("usage: %s /memory=nnn /increment=nnn\n"), cli->verb);
if (code == XP_CLI_ERROR_INVALID_OPTNAME) {
xp_printf (XP_TEXT("unknown option - %s\n"), name);
}
else if (code == XP_CLI_ERROR_MISSING_OPTNAME) {
xp_printf (XP_TEXT("missing option - %s\n"), name);
}
else if (code == XP_CLI_ERROR_REDUNDANT_OPTVAL) {
xp_printf (XP_TEXT("redundant value %s for %s\n"), value, name);
}
else if (code == XP_CLI_ERROR_MISSING_OPTVAL) {
xp_printf (XP_TEXT("missing value for %s\n"), name);
}
else if (code == XP_CLI_ERROR_MEMORY) {
xp_printf (XP_TEXT("memory error in processing %s\n"), name);
}
else {
xp_printf (XP_TEXT("error code: %d\n"), code);
}
return -1;
}
xp_cli_t* parse_cli (int argc, xp_char_t* argv[])
{
static const xp_char_t* optsta[] =
{
XP_TEXT("/"), XP_TEXT("--"), XP_NULL
};
static xp_cliopt_t opts[] =
{
{ XP_TEXT("memory"), XP_CLI_OPTNAME | XP_CLI_OPTVAL },
{ XP_TEXT("increment"), XP_CLI_OPTNAME | XP_CLI_OPTVAL },
{ XP_NULL, 0 }
};
static xp_cli_t cli =
{
handle_cli_error,
optsta,
XP_TEXT("="),
opts
};
if (xp_parsecli (argc, argv, &cli) == -1) return XP_NULL;
return &cli;
}
int xp_main (int argc, xp_char_t* argv[])
{
xp_lisp_t* lisp;
xp_lisp_obj_t* obj;
xp_cli_t* cli;
int mem, inc;
#ifdef LINUX
mtrace ();
@ -46,14 +102,21 @@ int xp_main (int argc, xp_char_t* argv[])
setlocale (LC_ALL, "");
if (argc != 3) {
xp_fprintf (xp_stderr, XP_TEXT("usage: %s mem_ubound mem_ubound_inc\n"), argv[0]);
if ((cli = parse_cli (argc, argv)) == XP_NULL) return -1;
mem = to_int(xp_getclioptval(cli, XP_TEXT("memory")));
inc = to_int(xp_getclioptval(cli, XP_TEXT("increment")));
xp_clearcli (cli);
if (mem <= 0) {
xp_fprintf (xp_stderr,
XP_TEXT("error: invalid memory size given\n"));
return -1;
}
lisp = xp_lisp_new (to_int(argv[1]), to_int(argv[2]));
lisp = xp_lisp_new (mem, inc);
if (lisp == NULL) {
xp_fprintf (xp_stderr, XP_TEXT("can't create a lisp instance\n"));
xp_fprintf (xp_stderr,
XP_TEXT("error: cannot create a lisp instance\n"));
return -1;
}