comparison lwbasic/main.c @ 22:7c35fa8dbc91

Added initial framework for lwbasic
author lost@l-w.ca
date Sat, 22 Jan 2011 21:01:03 -0700
parents
children 87590f43e76d
comparison
equal deleted inserted replaced
21:ac311e7ffed6 22:7c35fa8dbc91
1 /*
2 main.c
3
4 Copyright © 2011 William Astle
5
6 This file is part of LWTOOLS.
7
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
9 terms of the GNU General Public License as published by the Free Software
10 Foundation, either version 3 of the License, or (at your option) any later
11 version.
12
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 more details.
17
18 You should have received a copy of the GNU General Public License along with
19 this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 /*
23 main program startup handling for lwbasic
24 */
25
26 #include <stdlib.h>
27 #include <stdio.h>
28
29 #include <lw_cmdline.h>
30 #include <lw_string.h>
31 #include <lw_alloc.h>
32
33 #include "lwbasic.h"
34
35 #define PROGVER "lwbasic from " PACKAGE_STRING
36
37 static struct lw_cmdline_options options[] =
38 {
39 { "output", 'o', "FILE", 0, "Output to FILE"},
40 { "debug", 'd', "LEVEL", lw_cmdline_opt_optional, "Set debug mode"},
41 { 0 }
42 };
43
44 static int parse_opts(int key, char *arg, void *data)
45 {
46 cstate *state = data;
47
48 switch (key)
49 {
50 case 'o':
51 if (state -> output_file)
52 lw_free(state -> output_file);
53 state -> output_file = lw_strdup(arg);
54 break;
55
56 case 'd':
57 if (!arg)
58 state -> debug_level = 50;
59 else
60 state -> debug_level = atoi(arg);
61 break;
62
63 case lw_cmdline_key_end:
64 return 0;
65
66 case lw_cmdline_key_arg:
67 if (state -> input_file)
68 {
69 fprintf(stderr, "Already have an input file; ignoring %s\n", arg);
70 }
71 else
72 {
73 state -> input_file = lw_strdup(arg);
74 }
75 break;
76
77 default:
78 return lw_cmdline_err_unknown;
79 }
80
81 return 0;
82 }
83
84 static struct lw_cmdline_parser cmdline_parser =
85 {
86 options,
87 parse_opts,
88 "INPUTFILE",
89 "lwbasic, a compiler for a dialect of Basic\vPlease report bugs to lost@l-w.ca.",
90 PROGVER
91 };
92
93 int main(int argc, char **argv)
94 {
95 cstate state = { 0 };
96
97 lw_cmdline_parse(&cmdline_parser, argc, argv, 0, 0, &state);
98
99 exit(0);
100 }