aboutsummaryrefslogtreecommitdiff
path: root/src/survive_driverman.c
diff options
context:
space:
mode:
authorJosh Allen <axlecrusher@gmail.com>2017-02-27 21:30:44 -0500
committerJosh Allen <axlecrusher@gmail.com>2017-02-27 21:30:44 -0500
commit711a55ec79fefbefdc3527c89742acf622aaec3c (patch)
treef087cb3e592aa5cabc5c7b3d281260f4657ad671 /src/survive_driverman.c
parente8d696e03128242be33eb0734addee645e894635 (diff)
parent51751d4a9f407f526de2b626d44e14690fbef004 (diff)
downloadlibsurvive-711a55ec79fefbefdc3527c89742acf622aaec3c.tar.gz
libsurvive-711a55ec79fefbefdc3527c89742acf622aaec3c.tar.bz2
Merge branch 'master' of 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] );
+ }
+}
+