-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproperties_gen.c
208 lines (188 loc) · 4.8 KB
/
properties_gen.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <deadbeef/deadbeef.h>
#include "cmd_tools.h"
extern const char * configdialog;
// default argv size, will be reallocated if needed
#define ARGV_MAX 16
// default property size, will be reallocated if needed
#define PROPERTIES_MAX 8
DB_functions_t *deadbeef = 0;
DB_conf_item_t * dummy_conf_find (const char *tab, DB_conf_item_t *prev) {
return NULL;
}
void deadbeef_omit () {
deadbeef = malloc (sizeof(DB_functions_t));
deadbeef->conf_find = dummy_conf_find;
}
int printf_esc (const char *str, const char * str2) {
char buffer[strlen(str2)+1+12];
int i;
int j = 0;
for (i = 0; str2[i]; i++) {
if (str2[i] == '\"') {
buffer[j++] = '\\';
}
buffer[j++] = str2[i];
}
buffer[j] = 0;
return printf (str,buffer);
}
int main () {
deadbeef_omit ();
time_t timer;
struct tm* tm_info;
time(&timer);
tm_info = localtime(&timer);
property_t ** props[32];
char * prop_tabs[32];
char * props_s[32];
char buffer[strlen(configdialog)+1];
strcpy (buffer, configdialog);
int i;
int to_break = 0;
char * ptrb = buffer;
char * ptre = buffer;
char * ptrg = buffer;
for (i = 0; !to_break; i++) {
// get first tab
ptrg = strstr (ptrg, "tab");
if (!ptrg) {
printf ("error i=%d\n", i);
break;
}
// get first property
ptrb = strchr (ptrg, '\n');
// but first save tabname
if (!ptrb) {
printf ("did not found any property in tab?!\n");
}
*ptrb = 0;
if (*(ptrb-1) == ';')
*(ptrb-1) = 0;
prop_tabs[i] = strdup (ptrg+4);
ptrb++;
// terminate before next tab
ptrg = strstr (ptrb, "tab");
if (!ptrg) {
to_break = 1;
}
else {
ptre = ptrg - 1;
*ptre = 0;
}
// add to table
props_s[i] = ptrb;
}
props_s[i] = NULL;
prop_tabs[i] = NULL;
int props_count = i;
for (i = 0; props_s[i]; i++) {
props[i] = properties_alloc (props_s[i]);
}
props[i] = NULL;
printf ("properties_gen: got %d tabs\n", props_count);
strftime(buffer, strlen(configdialog)+1, "%Y-%m-%d %H:%M:%S", tm_info);
// print props
freopen("props.c", "w", stdout);
printf ("// File generated by properties_gen (%s)\n", buffer);
printf ("#include <deadbeef/deadbeef.h>\n#include \"cmd_tools.h\"\n#include \"common.h\"\n\n");
property_t *p;
int h = 0;
for (h = 0; props[h]; h++) {
for (i = 0; props[h][i]; i++) {
p = (property_t *) props[h][i];
printf ("struct property %s_%02d = {\n", prop_tabs[h], i);
printf_esc ("\t.name = \"%s\",\n",p->name);
printf ("\t.type = %d,\n",p->type);
printf ("\t.type_string = \"%s\",\n",p->type_string);
printf ("\t.type_min = %d,\n",p->type_min);
printf ("\t.type_max = %d,\n",p->type_max);
printf ("\t.type_step = %d,\n",p->type_step);
printf ("\t.type_count = %d,\n",p->type_count);
printf ("\t.key = \"%s\",\n",p->key);
printf ("\t.val = 0,\n");
printf ("\t.val_possible = ");
if (p->val_possible) {
int j;
printf ("(char *[]) {\n");
for (j = 0; p->val_possible[j]; j++) {
printf ("\t\t\"%s\"",p->val_possible[j]);
if (p->val_possible[j+1]) {
printf (",\n");
}
}
printf ("\n\t\t},\n");
}
else {
printf ("0,\n");
}
printf ("\t.def = \"%s\"",p->def);
printf (",\n");
// v2
printf ("\t.group = { ");
if (p->group) {
int j;
for (j = 0; p->group[j]; j++) {
printf ("\"%s\"",p->group[j]);
printf (", ");
}
printf ("NULL },\n");
}
else {
printf ("NULL },\n");
}
// todo
printf ("\t.requires = ");
if (p->requires) {
int a;
int found = 0;
for (a = 0; props[h][a]; a++) {
if ((struct property *) props[h][a] == (struct property *) p->requires) {
printf ("&%s_%02d\n", prop_tabs[h], a);
found = 1;
break;
}
}
if (!found) {
fprintf (stderr, "did not found property %s for requires!\n", p->requires->name);
printf ("NULL\n");
}
}
else {
printf ("NULL\n");
}
printf ("};\n\n");
}
printf ("struct property * p_%s[%d] = {\n\t", prop_tabs[h], properties_count(props[h])+1);
int elements = i;
for (i = 0; i < elements; i++) {
printf ("&%s_%02d", prop_tabs[h], i);
if (i+1 < elements) {
printf (", ");
if (i != 0 && !(i%5))
printf ("\n\t");
}
else {
printf (", NULL");
}
}
printf ("\n};\n\n");
//printf ("{\n", prop_tabs[h]);
//printf ("}\n");
}
fclose (stdout);
freopen("props.h", "w", stdout);
printf ("// File generated by properties_gen (%s)\n", buffer);
for (h = 0; props[h]; h++) {
printf ("extern struct property * p_%s[%d];\n", prop_tabs[h],properties_count(props[h])+1);
}
fclose (stdout);
for (i = 0; props[i]; i++) {
properties_free (props[i]);
free (prop_tabs[i]);
}
free (deadbeef);
return 0;
}