-
Notifications
You must be signed in to change notification settings - Fork 1
/
ptgenmap.c
69 lines (54 loc) · 1.97 KB
/
ptgenmap.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
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include "pretrace.h"
#include "trie.h"
/* this program will read the libpretrace configuration file, and parse it into a format that can be machine read
* and searched very quickly.
*
* This will reduce the impact on initialisation time of using pretrace.
*/
int main(int argc, char **argv)
{
FILE *config;
trie_t trie;
char line[LINE_MAX], app[PATH_MAX], debugger[ARG_MAX], *c;
unsigned short perc;
unsigned short fields;
if (trieinit__pt(&trie) != 0) {
fprintf(stderr, "error: there was a problem with memory allocation.\n");
return 1;
}
if ((config = fopen(PRETRACECONF, "r"))) {
while (fgets(line, sizeof(line), config) != NULL) {
if (*line == '#' || *line == '\n')
continue; /* skip comments */
if ((c = strchr(line, ':')))
*c = ' ';
if ((fields = sscanf(line, "%" xstr(PATH_MAX) "s %[^\n]" xstr(ARG_MAX) "s", app, debugger)) < 1)
continue;
/* check for percentage */
if ((c = strchr(app, '%')))
*(c++) = '\0', perc = atoi(c);
else
perc = 100;
eprintf("debug: adding %s, debugger: %s, percentage: %u\n", app, debugger, perc);
if (trieadd__pt(app, perc, fields == 2 ? debugger : DEFAULT_DEBUGGER, &trie) != 0) {
fprintf(stderr, "error: there was a problem constructing the map structure.\n");
return 1;
}
}
fclose(config);
} else {
fprintf(stderr, "error: could not open configuration file %s.\n", PRETRACECONF);
return 1;
}
if (triewrite__pt(PRETRACEMAP, &trie) != 0) {
fprintf(stderr, "error: failed to create map file %s.\n", PRETRACEMAP);
return 1;
}
fprintf(stdout, "info: %s created successfully.\n", PRETRACEMAP);
triedestroy__pt(&trie);
return 0;
}