-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
74 lines (65 loc) · 1.84 KB
/
main.cc
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
#include <iostream>
#include <cstring>
#include <cstdio>
#include "templateProj.h"
#include "ctemplate.h"
void Usage(char *str) {
printf("genproj is used to generate a code template!\n");
printf("Usages:\n\t%s -t language -p projectName [-m comment]\n", str);
}
void getOps(Typeinfo &t, int argc, char *argv[]);
int main(int argc, char *argv[]) {
Typeinfo t;
if (argc < 3) {
Usage(argv[0]);
return -1;
} else {
getOps(t, argc, argv);
if ((t.mode & 0x03) != 0x03) {
Usage(argv[0]);
return -1;
}
}
ITemplate *generator;
if (0 == strcmp(t.type, "c")) {
if (t.mode & 1 << 2)
generator = new cTemplate(t.name, t.comment);
else
generator = new cTemplate(t.name);
} else {
if (t.mode & 1 << 2)
generator = new cppTemplate(t.name, t.comment);
else
generator = new cppTemplate(t.name);
}
(*generator)();
delete generator;
return 0;
}
void getOps(Typeinfo &t, int argc, char *argv[]) {
int opt = 0;
t.mode = 0;
while ((opt = getopt(argc, argv, "t:p:m:h")) != -1) {
switch (opt) {
case 't':
t.mode |= 1;
strcpy(t.type, optarg);
//printf("mode=%d\tI get the type %s\n",t.mode,t.type);
break;
case 'p':
t.mode |= 1 << 1;
strcpy(t.name, optarg);
//printf("mode=%d\tI got the name %s\n",t.mode,t.name);
break;
case 'm':
t.mode |= 1 << 2;
strcpy(t.comment, optarg);
//printf("mode = %d\tI got the comment %s\n",t.mode,t.name);
break;
case 'h':
case '?':
Usage(argv[0]);
break;
}
}
}