new action construction with seperate brief and help parsers
[mala.git] / tests / test-mala_stdmodule.c
blob333dc81b55f8b08d26b424fc071b54d06792ca1f
1 /*
2 test-mala_stdmodule.c - MaLa stdandard module test suite
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 "mala.h"
25 /*TODO move to the proper module headers*/
26 #define MALA_SUBSTITUTE_PARSER(name,subst) \
27 {name, (MalaParserFunc)mala_substitute_parser, (MalaDataFactory)mala_string_factory, \
28 subst, NULL}
29 #define MALA_SUBSTITUTE_PARSER_P(name,subst,parent) \
30 {name, (MalaParserFunc)mala_substitute_parser, (MalaDataFactory)mala_string_factory, \
31 subst, parent}
33 /*todo expand_parser*/
34 #define MALA_EXPAND_PARSER(name, expand) \
35 {name, (MalaParserFunc)mala_substitute_parser, (MalaDataFactory)mala_stringlist_factory, \
36 MALA_STATIC_STRINGLIST_INIT expand, NULL}
37 #define MALA_EXPAND_PARSER_P(name, expand, parent) \
38 {name, (MalaParserFunc)mala_substitute_parser, (MalaDataFactory)mala_stringlist_factory, \
39 MALA_STATIC_STRINGLIST_INIT expand, parent}
41 #define MALA_PARSER_BRIEF(name, brief) \
42 MALA_EXPAND_PARSER_P("--BRIEF." name, ("--BRIEF-ACTION", brief), name)
44 #define MALA_PARSER_HELP(name, args) \
45 MALA_EXPAND_PARSER_P("--HELP." name, args, name)
47 #define MALA_TRUE_PARSER(name) \
48 MALA_SUBSTITUTE_PARSER(name,"--TRUE")
49 #define MALA_FALSE_PARSER(name) \
50 MALA_SUBSTITUTE_PARSER(name,"--FALSE")
52 mala_actioninit my_actions[] =
54 MALA_TRUE_PARSER("--FLAG-NUMSPLIT-EXPANSION"),
55 MALA_TRUE_PARSER("--FLAG-LITERAL-EXPANSION"),
56 MALA_TRUE_PARSER("--FLAG-EXCLAM-EXPANSION"),
57 MALA_TRUE_PARSER("--FLAG-NO-EXPANSION"),
58 MALA_TRUE_PARSER("--FLAG-ASSIGN-EXPANSION"),
59 MALA_TRUE_PARSER("--FLAG-ENVVAR-EXPANSION"),
60 MALA_TRUE_PARSER("--FLAG-CHAR-EXPANSION"),
61 MALA_TRUE_PARSER("--FLAG-UNDERSCORE-EXPANSION"),
62 MALA_TRUE_PARSER("--FLAG-SETENV-EXPANSION"),
63 MALA_TRUE_PARSER("--FLAG-BRACKET-EXPANSION"),
64 MALA_TRUE_PARSER("--FLAG-ASSIGN-CONTRACTION"),
66 MALA_SUBSTITUTE_PARSER("--BRIEF-ACTION","--PRINTL"),
68 MALA_SUBSTITUTE_PARSER("--test","HEY_TEST_SUCCEEDED"),
69 MALA_PARSER_BRIEF("--test","brief explanation of test"),
70 MALA_PARSER_HELP("--test",("--PRINTL","long help for test")),
72 MALA_EXPAND_PARSER("--testtwo",("HEY", "TEST","SUCCEEDED")),
73 MALA_PARSER_BRIEF("--testtwo","brief explanation if testtwo"),
74 MALA_PARSER_HELP("--testtwo",("--PRINTL","long help for testtwo")),
76 MALA_ACTIONS_END
79 int
80 main(int argc, char * argv[])
82 MalaEngine my_engine;
83 my_engine = mala_engine_new_main (0, argc, argv, my_actions);
84 if (!my_engine)
86 printf ("error creating engine\n");
87 exit(5);
90 #if 0 /*TODO*/
91 my_engine = mala_engine_new_main (mala_stdmodule_init, argc, argv, 0);
92 #endif
94 mala_engine_run (my_engine);
96 mala_engine_dumpargs (my_engine, "arg: ", "\n");
97 mala_engine_dumpprogram (my_engine, "prg: ", "\n");
99 printf ("variable: %s\n", getenv ("variable"));
100 printf ("negated: %d\n", mala_engine_negated (my_engine));
101 printf ("state: %d\n", mala_engine_state_get (my_engine));
103 MALA_DEBUG("freeing engine");
104 mala_engine_free (my_engine);
105 return 0;
111 // Local Variables:
112 // mode: C
113 // c-file-style: "gnu"
114 // End:
115 // arch-tag: 56bcc0c2-d247-4a47-95dc-a460f26a444b
116 // end_of_file