2018-05-13 20:49:11 +00:00
|
|
|
/* Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors)
|
2014-11-07 17:02:52 +00:00
|
|
|
*
|
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
|
|
|
* GNSS-SDR is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GNSS-SDR is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-05-13 20:49:11 +00:00
|
|
|
* along with GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
|
2014-11-07 17:02:52 +00:00
|
|
|
*/
|
|
|
|
|
2014-09-07 23:56:09 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <volk_gnsssdr/volk_gnsssdr_prefs.h>
|
|
|
|
|
|
|
|
|
|
|
|
void volk_gnsssdr_get_config_path(char *path)
|
|
|
|
{
|
2015-04-26 22:36:45 +00:00
|
|
|
if (!path) return;
|
2014-09-07 23:56:09 +00:00
|
|
|
const char *suffix = "/.volk_gnsssdr/volk_gnsssdr_config";
|
2018-03-03 11:09:45 +00:00
|
|
|
const char *suffix2 = "/volk_gnsssdr/volk_gnsssdr_config"; // non-hidden
|
2014-09-07 23:56:09 +00:00
|
|
|
char *home = NULL;
|
2016-07-02 11:34:00 +00:00
|
|
|
|
|
|
|
//allows config redirection via env variable
|
|
|
|
home = getenv("VOLK_CONFIGPATH");
|
2018-03-03 11:09:45 +00:00
|
|
|
if (home != NULL)
|
|
|
|
{
|
|
|
|
strncpy(path, home, 512);
|
|
|
|
strcat(path, suffix2);
|
|
|
|
return;
|
|
|
|
}
|
2016-07-02 11:34:00 +00:00
|
|
|
|
2014-09-07 23:56:09 +00:00
|
|
|
if (home == NULL) home = getenv("HOME");
|
|
|
|
if (home == NULL) home = getenv("APPDATA");
|
2014-11-22 09:19:06 +00:00
|
|
|
if (home == NULL)
|
|
|
|
{
|
2015-04-26 22:36:45 +00:00
|
|
|
path[0] = 0;
|
2014-11-22 09:19:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-05-14 09:20:02 +00:00
|
|
|
strncpy(path, home, 512);
|
2014-09-07 23:56:09 +00:00
|
|
|
strcat(path, suffix);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t volk_gnsssdr_load_preferences(volk_gnsssdr_arch_pref_t **prefs_res)
|
|
|
|
{
|
|
|
|
FILE *config_file;
|
|
|
|
char path[512], line[512];
|
|
|
|
size_t n_arch_prefs = 0;
|
|
|
|
volk_gnsssdr_arch_pref_t *prefs = NULL;
|
|
|
|
|
|
|
|
//get the config path
|
|
|
|
volk_gnsssdr_get_config_path(path);
|
2018-03-03 11:09:45 +00:00
|
|
|
if (!path[0]) return n_arch_prefs; //no prefs found
|
2014-09-07 23:56:09 +00:00
|
|
|
config_file = fopen(path, "r");
|
2018-03-03 11:09:45 +00:00
|
|
|
if (!config_file) return n_arch_prefs; //no prefs found
|
2014-09-07 23:56:09 +00:00
|
|
|
|
|
|
|
//reset the file pointer and write the prefs into volk_gnsssdr_arch_prefs
|
2018-03-03 11:09:45 +00:00
|
|
|
while (fgets(line, sizeof(line), config_file) != NULL)
|
2014-09-07 23:56:09 +00:00
|
|
|
{
|
2018-03-03 11:09:45 +00:00
|
|
|
prefs = (volk_gnsssdr_arch_pref_t *)realloc(prefs, (n_arch_prefs + 1) * sizeof(*prefs));
|
2014-11-22 09:19:06 +00:00
|
|
|
volk_gnsssdr_arch_pref_t *p = prefs + n_arch_prefs;
|
2018-03-03 11:09:45 +00:00
|
|
|
if (sscanf(line, "%s %s %s", p->name, p->impl_a, p->impl_u) == 3 && !strncmp(p->name, "volk_gnsssdr_", 5))
|
2014-11-22 09:19:06 +00:00
|
|
|
{
|
|
|
|
n_arch_prefs++;
|
|
|
|
}
|
2014-09-07 23:56:09 +00:00
|
|
|
}
|
|
|
|
fclose(config_file);
|
|
|
|
*prefs_res = prefs;
|
|
|
|
return n_arch_prefs;
|
|
|
|
}
|