summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--volk/include/volk/volk_prefs.h19
-rw-r--r--volk/lib/volk_prefs.c49
2 files changed, 68 insertions, 0 deletions
diff --git a/volk/include/volk/volk_prefs.h b/volk/include/volk/volk_prefs.h
new file mode 100644
index 000000000..77bcb709b
--- /dev/null
+++ b/volk/include/volk/volk_prefs.h
@@ -0,0 +1,19 @@
+#ifndef INCLUDED_VOLK_PREFS_H
+#define INCLUDED_VOLK_PREFS_H
+
+struct volk_arch_pref {
+ char name[128];
+ char arch[32];
+};
+
+////////////////////////////////////////////////////////////////////////
+// get path to volk_config profiling info
+////////////////////////////////////////////////////////////////////////
+void get_config_path(char *);
+
+////////////////////////////////////////////////////////////////////////
+// load prefs into global prefs struct
+////////////////////////////////////////////////////////////////////////
+int load_preferences(struct volk_arch_pref **);
+
+#endif //INCLUDED_VOLK_PREFS_H
diff --git a/volk/lib/volk_prefs.c b/volk/lib/volk_prefs.c
new file mode 100644
index 000000000..bd15c130e
--- /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 = "/.gnuradio/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;
+}