This repository has been archived by the owner on Jan 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bspc.c
135 lines (100 loc) · 2.39 KB
/
bspc.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
127
128
129
130
131
132
133
134
135
/*
* bspc.c
*
* compilador bsp.
*
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <err.h>
#define _GNU_SOURCE 1
#include <getopt.h>
#undef _GNU_SOURCE
#include "common/boolean.h"
#include "rogimodel/rogimodel.h"
#include "bsp/bsp.h"
#include "bsp/bsp_model.h"
#define _(s) ((s))
char* program_name = NULL;
const char* version_message =
"%s version development\n";
#define print_version() printf((_(version_message)), program_name)
const char* usage_message =
"Usage: %s [option]...\n";
#define print_usage() printf((_(usage_message)), program_name)
const char* help_message =
"Usage: %s [option]... <infile> <outfile>\n"
"rogi engine bsp compiler\n"
"\n"
"Mandatory arguments to long options are mandatory for short options too.\n"
"\n"
" -V, --version\tPrint version string and exit.\n"
" -h, --help\tPrint this help message and exit.\n"
" -v, --verbose\tExplain what is being done.\n"
"\n"
"Returns 0 on success and -1 on error\n"
"\n"
"rogi <[email protected]>.\n";
#define print_help() printf(_(help_message), program_name)
bool verbose = false;
int bspc(const model_t* model, bsp_tree_t* tree)
{
return 0;
}
int bsp_write_tree(const char* outfile, const bsp_tree_t* tree)
{
return 0;
}
int main(int argc, char** argv)
{
struct option longopts[] =
{
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
{"verbose", no_argument, NULL, 'v'},
{NULL, no_argument, NULL, '\0'}
};
char shortopts[] = "Vh:v";
int opt;
program_name = argv[0];
optind = 0;
opterr = true;
opt = getopt_long(argc, argv, shortopts, longopts, &optind);
while(opt != -1)
{
switch(opt)
{
/* -V, --version*/
case 'V':
print_version();
return 0;
/* -h, --help */
case 'h':
print_help();
return 0;
/* -v, --verbose */
case 'v':
verbose = true;
break;
/* opção inválida */
case '?':
return -1;
}
opt = getopt_long(argc, argv, shortopts, longopts, &optind);
}
if(argc - optind < 2)
errx(-1, _("Too few arguments. See --help for usage information."));
if(argc - optind > 2)
errx(-1, _("Too many arguments. See --help for usage information."));
int ret;
model_t model;
ret = rogimodel_read(&model, argv[optind]);
if(ret == -1)
err(-1, "%s", argv[optind]);
bsp_tree_t tree;
bsp_make_tree_from_model(&tree, &model);
bsp_tree_write(&tree, argv[optind + 1]);
return 0;
}
/* EOF */