blob: e73b903077d43d352e44433b6dcf96172d4c5770 (
plain)
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
|
#include <stdlib.h>
#include <stdio.h>
#include "utilities.h"
void _finish(bool ok)
{
puts(ok ? "\nOk. " : "\nBlad. ");
exit(ok ? 0 : -1);
}
void *dirtyalloc(size_t size)
{
void *memory = malloc(size);
if (memory == NULL)
FAIL(MSG_MALLOC_FAIL);
return memory;
}
/* Used to suppress stderr output of iniparser library */
int dummy_errback(const char *fmt, ...)
{
return 1;
}
/*
* I had to deal with UTF-16 config files. Since mostly the ASCII characters
* are used anyway, I decided to just pick every second byte of the file and
* got this semi-working... This IS provisional.
*/
int provisional_wide_char_fgetc(FILE *stream)
{
int c = 128;
while (c > 127) {
c = getc(stream);
getc(stream);
if (c == EOF)
return EOF;
}
return c;
}
bool is_valid_port_number(int port)
{
return port >= 0 && port <= 65535;
}
/*
* Different implementations if validate_config() and perform_work()
* are supplied in pop and push programs.
*/
int main(int argc, const char **argv)
{
struct config config;
get_config(argc, argv, &config);
validate_config(&config);
perform_work(&config);
/* actually, this won't be reached, because perform_work exit()s... */
free_config(&config);
return 0;
}
|