-
Notifications
You must be signed in to change notification settings - Fork 25
/
inifile_prop.c
59 lines (53 loc) · 1.48 KB
/
inifile_prop.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
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include "inifile_prop.h"
uint32_t get_property_value(struct section *sections, char *sectname, char *propname, char *def)
{
uint32_t val=0;
uint32_t defval=0;
char *pStr=0;
// get default value string (if exists)
if(def != NULL) {
defval=strtoul(def, NULL, 16);
}
// lookup property
pStr = get_property(sections, sectname, propname, NULL);
// success?
if(pStr != NULL) {
// scan property value
val=strtoul(pStr, NULL, 16);
free(pStr);
} else {
val = defval;
}
return val;
}
int process_properties_list(struct section *osconfig, PropertyListItem *ci)
{
int i=0,type,errCount=0;
uint32_t *pAdr;
while(1) {
type = ci[i].attr_type;
if(type == END_LIST) break; // exit list...
if(type == GET_VALUE) { // process list entry for GET_VALUE type
pAdr = ci[i].attr_adr;
if(pAdr != 0) {
*pAdr = get_property_value(osconfig, ci[i].attr_path, ci[i].attr_name, ci[i].attr_default);
// printf("get_property_value( %s, %s)\n",ci[i].attr_path,ci[i].attr_name);
if(*pAdr == 0) {
errCount++;
// printf("Warning: Failed to get value for %s %s\n",ci[i].attr_path, ci[i].attr_name);
}
} else {
printf("Error: Invalid storage for property, check property list definition, item %d\n",i);
}
} else {
printf("Unsupported property accessor type, check propertylist, item %d\n", i);
}
i++;
}
printf("Processed %d elements with %d issues\n",i,errCount);
return errCount;
}
// vim:ts=4:sw=4