diff options
author | Josh Blum | 2011-05-12 15:57:42 -0700 |
---|---|---|
committer | Josh Blum | 2011-05-12 15:57:42 -0700 |
commit | 52662c938d42c6dab110c015719ba3d98f491f96 (patch) | |
tree | 3e73dabbf9fff73cf22c3fa8c2e386d448a4dec8 /volk/lib/volk_prefs.c | |
parent | a56dad2b5caf5167f4c93a15b86c304c0077a0a6 (diff) | |
parent | b0e781a55387e02ef8126219ccfe8b3c48a838f5 (diff) | |
download | gnuradio-52662c938d42c6dab110c015719ba3d98f491f96.tar.gz gnuradio-52662c938d42c6dab110c015719ba3d98f491f96.tar.bz2 gnuradio-52662c938d42c6dab110c015719ba3d98f491f96.zip |
Merge branch 'volk_cmake' of github.com:bistromath/gnuradio into new_volk_cmake
Conflicts:
volk/lib/CMakeLists.txt
Diffstat (limited to 'volk/lib/volk_prefs.c')
-rw-r--r-- | volk/lib/volk_prefs.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/volk/lib/volk_prefs.c b/volk/lib/volk_prefs.c new file mode 100644 index 000000000..ebfe3bc40 --- /dev/null +++ b/volk/lib/volk_prefs.c @@ -0,0 +1,49 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <volk/volk_prefs.h> + +//#if defined(_WIN32) +//#include <Windows.h> +//#endif + +void get_config_path(char *path) { + const char *suffix = "/.volk/volk_config"; + strcpy(path, getenv("HOME")); + strcat(path, suffix); +} + +//passing by reference in C can suck my balls +int load_preferences(struct volk_arch_pref **prefs) { + FILE *config_file; + char path[512], line[512], function[128], arch[32]; + int n_arch_prefs = 0; + struct volk_arch_pref *t_pref; + + //get the config path + get_config_path(path); + config_file = fopen(path, "r"); + if(!config_file) return; //no prefs found + + while(fgets(line, 512, config_file) != NULL) { + if(sscanf(line, "%s %s", function, arch) == 2 && !strncmp(function, "volk_", 5)) { + n_arch_prefs++; + } + } + + //now allocate the memory required for volk_arch_prefs + (*prefs) = (struct volk_arch_pref *) malloc(n_arch_prefs * sizeof(struct volk_arch_pref)); + t_pref = (*prefs); + + //reset the file pointer and write the prefs into volk_arch_prefs + rewind(config_file); + while(fgets(line, 512, config_file) != NULL) { + if(sscanf(line, "%s %s", function, arch) == 2 && !strncmp(function, "volk_", 5)) { + strncpy(t_pref->name, function, 128); + strncpy(t_pref->arch, arch, 32); + t_pref++; + } + } + fclose(config_file); + return n_arch_prefs; +} |