naspro

view permafrost/src/main.c @ 178:7169a8909d53

Added Permafrost + small changes
author Stefano D'Angelo <zanga.mail@gmail.com>
date Sun May 02 14:19:58 2010 +0300 (2010-05-02)
parents
children
line source
1 /*
2 * Permafrost - Physical modelling framework
3 *
4 * Copyright (C) 2009, 2010 Stefano D'Angelo <zanga.mail@gmail.com>
5 *
6 * See the COPYING file for license conditions.
7 */
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <string.h>
13 #include "src/util.h"
14 #include "src/types.h"
15 #include "src/list.h"
16 #include "src/parser.h"
17 #include "src/macro.h"
18 #include "src/schedule.h"
19 #include "src/compile.h"
21 static const char **filenames = NULL;
22 static size_t filenames_count = 0;
23 static list_t block_systems;
24 static list_t scheduled_systems;
25 static char dry_run = 0;
27 static void
28 parse_cmd(int argc, char *argv[])
29 {
30 int i;
32 for (i = 1; i < argc; i++)
33 {
34 if (!strcmp(argv[i], "--help"))
35 {
36 printf("Usage: %s [options] file...\n", argv[0]);
37 printf("Options:\n");
38 printf(" --help Display this "
39 "information\n");
40 printf(" --version Display the "
41 "compiler version information\n");
42 printf(" --output-dir=<directory> Directory where to "
43 "put generated files\n");
44 printf(" --dry-run Do not generate "
45 "output files (implies all\n"
46 " --no-<option> "
47 "options)\n");
48 printf(" --no-code Do not generate "
49 "source files (implies\n"
50 " --no-descriptor "
51 "and --no-makefile)\n");
52 printf(" --no-descriptor Do not generate "
53 "lv2_descriptor.c (implies\n"
54 " --no-makefile)"
55 "\n");
56 printf(" --no-makefile Do not generate "
57 "the Makefile\n");
58 printf(" --no-ttl Do not generate "
59 ".ttl files (implies --no-manifest,\n"
60 " --no-plugins-ttl "
61 "and --no-extra-ttl)\n");
62 printf(" --no-manifest Do not generate "
63 "manifest.ttl\n");
64 printf(" --no-plugin-ttl Do not generate "
65 "plugin-specific .ttl files\n");
66 printf(" --no-extra-ttl Do not generate "
67 "plugin-specific -extra.ttl files\n");
68 printf(" --uri-prefix=<prefix> Use <prefix> as "
69 "the initial part of URIs\n");
70 printf(" --license-uri=<uri> Use <uri> as the "
71 "DOAP license URI\n");
72 exit(EXIT_SUCCESS);
73 }
74 }
76 for (i = 1; i < argc; i++)
77 {
78 if (!strcmp(argv[i], "--version"))
79 {
80 printf("permafrost (Permafrost) 0.2.0\n");
81 printf("Copyright (C) 2009, 2010 Stefano D'Angelo "
82 "<zanga.mail@gmail.com>\n");
83 exit(EXIT_SUCCESS);
84 }
85 }
87 for (i = 1; i < argc; i++)
88 {
89 if (argv[i][0] == '-')
90 {
91 if (!strncmp(argv[i], "--output-dir=",
92 sizeof("--output-dir=") - 1))
93 {
94 compile_output_dir = argv[i] - 1
95 + sizeof("--output-dir=");
96 continue;
97 }
98 if (!strcmp(argv[i], "--dry-run"))
99 {
100 dry_run = 1;
101 continue;
102 }
103 if (!strcmp(argv[i], "--no-code"))
104 {
105 compile_gen_code = 0;
106 compile_gen_descriptor = 0;
107 compile_gen_makefile = 0;
108 continue;
109 }
110 if (!strcmp(argv[i], "--no-descriptor"))
111 {
112 compile_gen_descriptor = 0;
113 compile_gen_makefile = 0;
114 continue;
115 }
116 if (!strcmp(argv[i], "--no-makefile"))
117 {
118 compile_gen_makefile = 0;
119 continue;
120 }
121 if (!strcmp(argv[i], "--no-ttl"))
122 {
123 compile_gen_manifest = 0;
124 compile_gen_plugin_ttl = 0;
125 compile_gen_extra_ttl = 0;
126 continue;
127 }
128 if (!strcmp(argv[i], "--no-manifest"))
129 {
130 compile_gen_manifest = 0;
131 continue;
132 }
133 if (!strcmp(argv[i], "--no-plugin-ttl"))
134 {
135 compile_gen_plugin_ttl = 0;
136 continue;
137 }
138 if (!strcmp(argv[i], "--no-extra-ttl"))
139 {
140 compile_gen_extra_ttl = 0;
141 continue;
142 }
143 if (!strncmp(argv[i], "--uri-prefix=",
144 sizeof("--uri-prefix=") - 1))
145 {
146 compile_uri_prefix = argv[i] - 1
147 + sizeof("--uri-prefix=");
148 continue;
149 }
150 if (!strncmp(argv[i], "--license-uri=",
151 sizeof("--license-uri=") - 1))
152 {
153 compile_license_uri = argv[i] - 1
154 + sizeof("--license-uri=");
155 continue;
156 }
158 fprintf(stderr, "%s: unrecognized option `%s'\n",
159 argv[0], argv[i]);
160 exit(EXIT_FAILURE);
161 }
163 filenames_count++;
164 filenames = xrealloc(filenames,
165 filenames_count * sizeof(const char *));
166 filenames[filenames_count - 1] = argv[i];
167 }
169 if (filenames == NULL)
170 {
171 fprintf(stderr, "%s: no input files\n", argv[0]);
172 exit(EXIT_FAILURE);
173 }
174 }
176 static void
177 do_macro_to_blocks(void *data, void *context)
178 {
179 struct system *s, *ns;
181 s = (struct system *)data;
183 ns = macro_to_blocks(s);
185 list_append(block_systems, ns);
186 }
188 static void
189 do_schedule(void *data, void *context)
190 {
191 struct system *s;
192 struct scheduled_system *ss;
194 s = (struct system *)data;
196 ss = schedule(s);
198 list_append(scheduled_systems, ss);
199 }
201 static void
202 free_scheduled_system(void *data, void *context)
203 {
204 struct scheduled_system *ss;
206 ss = (struct scheduled_system *)data;
208 scheduled_system_free(ss);
209 }
211 int
212 main(int argc, char *argv[])
213 {
214 size_t i;
216 parse_cmd(argc, argv);
218 for (i = 0; i < filenames_count; i++)
219 parser_parse(filenames[i]);
221 block_systems = list_new();
222 list_for_each(parser_systems, do_macro_to_blocks, NULL);
224 scheduled_systems = list_new();
225 list_for_each(block_systems, do_schedule, NULL);
227 if (!dry_run)
228 compile(scheduled_systems);
230 list_for_each(scheduled_systems, free_scheduled_system, NULL);
231 list_free(scheduled_systems);
233 list_for_each(block_systems, free_system, NULL);
234 list_free(block_systems);
236 parser_free();
238 free(filenames);
240 return EXIT_SUCCESS;
241 }