-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.c
126 lines (111 loc) · 3.12 KB
/
app.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "isogen_config.h"
#include "utils.h"
#include "voxelgrid.h"
#include "generator.h"
#include "settings.h"
#include "renderer.h"
#include "cli.h"
#include "gui.h"
#include "app.h"
void suggest_help(void)
{
fprintf(stderr, "Use -h for help\n");
}
static void show_help(void)
{
puts(
"usage: isogen [OPTIONS] [voxel-file]\n"
"\n"
"Arguments:\n"
" -o write image file\n"
" -n draw face numbers\n"
" -s radius generate sphere\n"
" -r size,[seed] generate random voxels\n"
" -m filename generate voxels from 3d mesh\n"
" -v,-vv verbosity level"
);
}
int main(int argc, char **argv) {
int opt;
int error = 0;
int result;
int i;
int argnum;
// get user settings
Settings *settings = settings_create();
// Parse arguments
while ( (opt = getopt(argc, argv, "hgnm:r:s:i:o:v")) != -1) {
switch (opt) {
case 'h':
settings->help_option = 1;
break;
case 'g':
settings->gui_option = 1;
break;
case 'n':
settings->numbered_faces = 1;
break;
case 'o':
strcpy (settings->out_filename, optarg);
break;
case 's':
settings->generator = generator_create(GENERATOR_SPHERE,optarg);
break;
case 'r':
settings->generator = generator_create(GENERATOR_RANDOM,optarg);
break;
case 'm':
settings->generator = generator_create(GENERATOR_MESH,optarg);
break;
case 'v':
// increment verbosity level for each 'v'
verbosity_level++;
break;
case '?':
// invalid argument
error = 1;
break;
}
}
// unless the user specified a generator
if(settings->generator == NULL){
// parse remaining arguments
for (i=optind, argnum=0; i<argc; i++, argnum++) {
switch (argnum) {
case 0: // == input file
strcpy (settings->in_filename, argv[i]);
break;
default: // invalid number of arguments
fprintf (stderr, "Too many arguments\n");
error = 1;
break;
}
}
}
if (error != 0) {
suggest_help();
settings_free(settings);
return 1;
}
if (settings->help_option) {
show_help();
settings_free(settings);
return 0;
}
if (settings->gui_option) {
result = gui_main (argc, argv, settings);
} else {
result = cli_main (argc, argv, settings);
}
// free generator
if(settings->generator != NULL)
{
generator_free(settings->generator);
}
// free settings
settings_free(settings);
return result;
}