aboutsummaryrefslogtreecommitdiff
path: root/src/survive_driverman.c
diff options
context:
space:
mode:
authorultramn <dchapm2@umbc.edu>2017-03-02 19:55:54 -0800
committerultramn <dchapm2@umbc.edu>2017-03-02 19:55:54 -0800
commita59f42935a7472da7b9f162a68b3c55aff128f7e (patch)
treee4bf6314161bbabbde6064d8b7fdb9335a764ca6 /src/survive_driverman.c
parent1c131c03fe8c5d5ab17193c9f6e7e79d81110d52 (diff)
parent9d1b1d09ed51344c8ca7b4f0a94f5841ee2c509e (diff)
downloadlibsurvive-a59f42935a7472da7b9f162a68b3c55aff128f7e.tar.gz
libsurvive-a59f42935a7472da7b9f162a68b3c55aff128f7e.tar.bz2
Merge branch 'master' of https://github.com/cnlohr/libsurvive
Diffstat (limited to 'src/survive_driverman.c')
-rw-r--r--src/survive_driverman.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/survive_driverman.c b/src/survive_driverman.c
new file mode 100644
index 0000000..8cdfb71
--- /dev/null
+++ b/src/survive_driverman.c
@@ -0,0 +1,54 @@
+// (C) 2017 <>< C. N. Lohr, Under MIT/x11 License.
+//
+// See notice in survive_driverman.h
+//
+
+#include "survive_driverman.h"
+#include <string.h>
+#include <stdio.h>
+
+static void * Drivers[MAX_DRIVERS];
+static const char * DriverNames[MAX_DRIVERS];
+static int NrDrivers;
+
+void RegisterDriver( const char * element, void * data )
+{
+ Drivers[NrDrivers] = data;
+ DriverNames[NrDrivers] = element;
+ NrDrivers++;
+}
+
+void * GetDriver( const char * element )
+{
+ int i;
+ for( i = 0; i < NrDrivers; i++ )
+ {
+ if( strcmp( element, DriverNames[i] ) == 0 ) return Drivers[i];
+ }
+ return 0;
+}
+
+const char * GetDriverNameMatching( const char * prefix, int place )
+{
+ int i;
+ int prefixlen = strlen( prefix );
+
+ for( i = 0; i < NrDrivers; i++ )
+ {
+ if( memcmp( prefix, DriverNames[i], prefixlen ) == 0 )
+ if( 0 == (place--) )
+ return DriverNames[i];
+ }
+ return 0;
+}
+
+void ListDrivers()
+{
+ int i;
+ printf( "Drivers (%d/%d):\n", NrDrivers, MAX_DRIVERS );
+ for( i = 0; i < NrDrivers; i++ )
+ {
+ printf( " %s\n", DriverNames[i] );
+ }
+}
+