This repository was archived by the owner on Oct 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathproperties.c
More file actions
361 lines (318 loc) · 8.5 KB
/
properties.c
File metadata and controls
361 lines (318 loc) · 8.5 KB
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/*
* Copyright (C) 2013 Skrilax_CZ
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <limits.h>
#include <linux/input.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/reboot.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <termios.h>
#include <unistd.h>
#include "common.h"
#include "ui.h"
#include "console.h"
// UI properties
#define UI_INDETERMINATE_FRAMES_PROP_NAME "ui.intederminate.frames"
#define UI_INSTALL_FRAMES_PROP_NAME "ui.install.frames"
#define UI_INSTALL_LOC_X_PROP_NAME "ui.install.x"
#define UI_INSTALL_LOC_Y_PROP_NAME "ui.install.y"
// Colors
#define COLOR_LED_PROP_NAME "color.LED"
#define COLOR_BKGROUND_PROP_NAME "color.background"
#define COLOR_TITLE_PROP_NAME "color.title"
#define COLOR_MENU_PROP_NAME "color.menu"
#define COLOR_MENU_SEL_PROP_NAME "color.selection"
#define COLOR_SCRIPT_PROP_NAME "color.script"
// Console colors
#define COLOR_CONSOLE_HEADER_PROP_NAME "color.console.header"
#define COLOR_CONSOLE_BACKGROUND_PROP_NAME "color.console.background"
#define COLOR_CONSOLE_FRONT_PROP_NAME "color.console.front"
#define COLOR_CONSOLE_TERMCLR_PROP_NAME_BASE "color.console.termclr"
/* reads a file with properties, making sure it is terminated with \n \0 */
static void*
read_file(const char *fn, unsigned *_sz)
{
char *data;
int sz;
int fd;
data = 0;
fd = open(fn, O_RDONLY);
if(fd < 0)
return 0;
sz = lseek(fd, 0, SEEK_END);
if(sz < 0)
goto oops;
if(lseek(fd, 0, SEEK_SET) != 0)
goto oops;
data = (char*) malloc(sz + 2);
if(data == 0)
goto oops;
if(read(fd, data, sz) != sz)
goto oops;
close(fd);
data[sz] = '\n';
data[sz+1] = 0;
if(_sz)
*_sz = sz;
return data;
oops:
close(fd);
if(data != 0) free(data);
return 0;
}
static int
read_byte_hex(const char* text)
{
unsigned int value = 0;
unsigned char c;
if (text[0] > '9')
{
c = text[0] - 'A' + 0x0A;
if (c > 0x0F)
return -1;
}
else
{
c = text[0] - '0';
if (c > 0x09)
return -1;
}
value = c * 0x10;
if (text[1] > '9')
{
c = text[1] - 'A' + 0x0A;
if (c > 0x0F)
return -1;
}
else
{
c = text[1] - '0';
if (c > 0x09)
return -1;
}
return value + c;
}
static int
htoc_internal(const char* text, unsigned char* clr_struct, unsigned int clr_bytes)
{
int c;
unsigned int i;
for (i = 0; i < clr_bytes; i++)
{
c = read_byte_hex(text);
if (c == -1)
return 1;
(*clr_struct) = c;
clr_struct++;
text += 2;
}
return 0;
}
static int
htoc(const char* text, color* color)
{
if (strlen(text) < 9)
return 1;
if (text[0] != '#')
return 1;
text++;
return htoc_internal(text, (unsigned char*)color, 4);
}
static void
evaluate_property(const char* data, const char* value)
{
if (!strcmp(data, COLOR_LED_PROP_NAME))
{
color c;
if (!htoc(value, &c))
{
led_color = c;
fprintf(stderr, "%s: Led color set to:\n"
"r = %d, g = %d, b = %d, a = %d\n", __func__, c.r, c.g, c.b, c.a);
}
}
else if (!strcmp(data, COLOR_BKGROUND_PROP_NAME))
{
color c;
if (!htoc(value, &c))
{
background_color = c;
fprintf(stderr, "%s: Background color set to:\n"
"r = %d, g = %d, b = %d, a = %d\n", __func__, c.r, c.g, c.b, c.a);
}
}
else if (!strcmp(data, COLOR_TITLE_PROP_NAME))
{
color c;
if (!htoc(value, &c))
{
title_color = c;
fprintf(stderr, "%s: Title color set to:\n"
"r = %d, g = %d, b = %d, a = %d\n", __func__, c.r, c.g, c.b, c.a);
}
}
else if (!strcmp(data, COLOR_MENU_PROP_NAME))
{
color c;
if (!htoc(value, &c))
{
menu_color = c;
fprintf(stderr, "%s: Menu color set to:\n"
"r = %d, g = %d, b = %d, a = %d\n", __func__, c.r, c.g, c.b, c.a);
}
}
else if (!strcmp(data, COLOR_MENU_SEL_PROP_NAME))
{
color c;
if (!htoc(value, &c))
{
menu_sel_color = c;
fprintf(stderr, "%s: Selection color set to:\n"
"r = %d, g = %d, b = %d, a = %d\n", __func__, c.r, c.g, c.b, c.a);
}
}
else if (!strcmp(data, COLOR_SCRIPT_PROP_NAME))
{
color c;
if (!htoc(value, &c))
{
script_color = c;
fprintf(stderr, "%s: Script color set to:\n"
"r = %d, g = %d, b = %d, a = %d\n", __func__, c.r, c.g, c.b, c.a);
}
}
else if (!strcmp(data, COLOR_CONSOLE_HEADER_PROP_NAME))
{
color c;
if (!htoc(value, &c))
{
console_header_color = c;
fprintf(stderr, "%s: Console header color set to:\n"
"r = %d, g = %d, b = %d\n", __func__, c.r, c.g, c.b);
}
}
else if (!strcmp(data, COLOR_CONSOLE_BACKGROUND_PROP_NAME))
{
color c;
if (!htoc(value, &c))
{
console_background_color = c;
fprintf(stderr, "%s: Console background color set to:\n"
"r = %d, g = %d, b = %d\n", __func__, c.r, c.g, c.b);
}
}
else if (!strcmp(data, COLOR_CONSOLE_FRONT_PROP_NAME))
{
color c;
if (!htoc(value, &c))
{
console_front_color = c;
fprintf(stderr, "%s: Console front color set to:\n"
"r = %d, g = %d, b = %d\n", __func__, c.r, c.g, c.b);
}
}
else if (!strncmp(data, COLOR_CONSOLE_TERMCLR_PROP_NAME_BASE, strlen(COLOR_CONSOLE_TERMCLR_PROP_NAME_BASE)))
{
color c;
if (!htoc(value, &c))
{
const char* termclr_ascii = data + strlen(COLOR_CONSOLE_TERMCLR_PROP_NAME_BASE);
int val = atoi(termclr_ascii);
if (val >= 30 && val <= 37)
{
console_term_colors[val - 30] = c;
fprintf(stderr, "%s: Console terminal front color no. %d set to:\n"
"r = %d, g = %d, b = %d\n", __func__, val, c.r, c.g, c.b);
}
else if (val >= 90 && val <= 97)
{
console_term_colors[val - 90 + 8] = c;
fprintf(stderr, "%s: Console terminal bright front color no. %d set to:\n"
"r = %d, g = %d, b = %d\n", __func__, val, c.r, c.g, c.b);
}
}
}
else if (!strncmp(data, UI_INDETERMINATE_FRAMES_PROP_NAME, strlen(UI_INDETERMINATE_FRAMES_PROP_NAME)))
{
const char* val_str = data + strlen(UI_INDETERMINATE_FRAMES_PROP_NAME) + 1;
ui_parameters.indeterminate_frames = atoi(val_str);
fprintf(stderr, "%s: ui_parameters.indeterminate_frames = %d\n", __func__, ui_parameters.indeterminate_frames);
}
else if (!strncmp(data, UI_INSTALL_FRAMES_PROP_NAME, strlen(UI_INSTALL_FRAMES_PROP_NAME)))
{
const char* val_str = data + strlen(UI_INSTALL_FRAMES_PROP_NAME) + 1;
ui_parameters.installing_frames = atoi(val_str);
fprintf(stderr, "%s: ui_parameters.installing_frames = %d\n", __func__, ui_parameters.installing_frames);
}
else if (!strncmp(data, UI_INSTALL_LOC_X_PROP_NAME, strlen(UI_INSTALL_LOC_X_PROP_NAME)))
{
const char* val_str = data + strlen(UI_INSTALL_LOC_X_PROP_NAME) + 1;
ui_parameters.install_overlay_offset_x = atoi(val_str);
fprintf(stderr, "%s: ui_parameters.install_overlay_offset_x = %d\n", __func__, ui_parameters.install_overlay_offset_x);
}
else if (!strncmp(data, UI_INSTALL_LOC_Y_PROP_NAME, strlen(UI_INSTALL_LOC_Y_PROP_NAME)))
{
const char* val_str = data + strlen(UI_INSTALL_LOC_Y_PROP_NAME) + 1;
ui_parameters.install_overlay_offset_y = atoi(val_str);
fprintf(stderr, "%s: ui_parameters.install_overlay_offset_y = %d\n", __func__, ui_parameters.install_overlay_offset_y);
}
}
//copied from init
void
load_properties()
{
unsigned int sz;
char *key, *value, *eol, *sol, *tmp;
char* data = read_file(PROPERTY_FILE, &sz);
if(data == NULL)
return;
sol = data;
while((eol = strchr(sol, '\n')))
{
key = sol;
*eol++ = 0;
sol = eol;
value = strchr(key, '=');
if(value == 0)
continue;
*value++ = 0;
while(isspace(*key))
key++;
if(*key == '#')
continue;
tmp = value - 2;
while((tmp > key) && isspace(*tmp))
*tmp-- = 0;
while(isspace(*value))
value++;
tmp = eol - 2;
while((tmp > value) && isspace(*tmp))
*tmp-- = 0;
evaluate_property(key, value);
}
free(data);
}