forked from GPSBabel/gpsbabel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
explorist_ini.cc
74 lines (65 loc) · 1.51 KB
/
explorist_ini.cc
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
#include "defs.h"
#include "inifile.h"
#include "explorist_ini.h"
static inifile_t* inifile;
static const char myname[] = "explorist";
const char*
explorist_read_value(const char* section, const char* key)
{
return inifile_readstr(inifile, section, key);
}
static mag_info*
explorist_ini_try(const char* path)
{
mag_info* info = NULL;
char* inipath;
char* s;
xasprintf(&inipath, "%s/%s", path, "APP/Atlas.ini");
inifile = inifile_init(inipath, myname);
if (!inifile) {
xfree(inipath);
return NULL;
}
info = (mag_info*) xmalloc(sizeof(mag_info));
info->geo_path = NULL;
info->track_path = NULL;
info->waypoint_path = NULL;
s = xstrdup(inifile_readstr(inifile, "UGDS", "WpFolder"));
if (s) {
s = gstrsub(s, "\\", "/");
xasprintf(&info->waypoint_path, "%s/%s", path, s);
}
s = xstrdup(inifile_readstr(inifile, "UGDS", "GcFolder"));
if (s) {
s = gstrsub(s, "\\", "/");
xasprintf(&info->geo_path, "%s/%s", path, s);
}
s = xstrdup(inifile_readstr(inifile, "UGDS", "TrkFolder"));
if (s) {
s = gstrsub(s, "\\", "/");
xasprintf(&info->track_path, "%s/%s", path, s);
}
inifile_done(inifile);
xfree(inipath);
return info;
}
mag_info*
explorist_ini_get(const char** dirlist)
{
mag_info* r = NULL;
while (dirlist && *dirlist) {
r = explorist_ini_try(*dirlist);
if (r) {
return r;
}
}
return r;
}
void
explorist_ini_done(mag_info* info)
{
xfree(info->geo_path);
xfree(info->track_path);
xfree(info->waypoint_path);
xfree(info);
}