new test program, part 1
[mala.git] / tests / test-mala.c
blob05d3d3254690814074657337458e1626d4d6b479
1 /*
2 test-mala.c - MaLa test driver
4 Copyright (C) 2004, Christian Thaeter <chth@gmx.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, contact me.
19 #include <assert.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <nobug.h>
23 #include <acogc.h>
25 #include "mala.h"
26 #include "std.h"
28 mala_actioninit my_actions[] =
30 MALA_PARSER_SUBSTITUTE("--SUBST-TEST","SUBST_SUCCEEDED"),
31 MALA_PARSER_EXPAND("--FOOBAR",("foo","bar")),
32 MALA_ACTIONS_END
35 int
36 main(int argc, char * argv[])
38 MalaEngine engine;
40 engine = mala_engine_new ();
42 TRACE (NOBUG_ON);
44 ACOGC_STACK_ENTER (&engine->gcroot);
45 ACOGC_STACK_PTR (MalaStringList, args);
46 ACOGC_STACK_PTR (MalaStringList, result);
48 mala_module_std_init (engine);
50 // TODO mala_engine_new_main
51 mala_engine_actions_register (engine, my_actions);
53 args.ptr = mala_stringlist_new (engine);
54 mala_stringlist_append_cstrs (args.ptr, argc - 1, argv + 1, engine);
56 mala_engine_action_new_cstr (engine, "--ARGV0",
57 mala_substitute_parser,
58 argv[0], ACOGC_STATIC,
59 mala_engine_action_get_cstr (engine, "--WORLD"));
61 mala_engine_action_new_cstr (engine, "--COMMANDLINE",
62 mala_expand_parser,
63 args.ptr, ACOGC_GC,
64 mala_engine_action_get_cstr (engine, "--WORLD"));
66 printf ("stdout: ");
67 mala_engine_run_cstr (engine, "--COMMANDLINE", &result.ptr);
69 mala_stringlist_dump (result.ptr, stdout, ".\n", "literal: ","%s.\n", "", "");
72 printf ("variable: %s\n", getenv ("variable"));
73 printf ("state: %s\n", mala_engine_state_str (engine));
74 ACOGC_STACK_LEAVE;
75 mala_engine_free (engine);
76 return 0;
82 // Local Variables:
83 // mode: C
84 // c-file-style: "gnu"
85 // End:
86 // arch-tag: 610917e5-3918-4cba-be05-bf83efb45223
87 // end_of_file