aboutsummaryrefslogtreecommitdiff
path: root/src/survive_driverman.c
blob: b4684c80eb2c80ebb030d77438d950c46b6b6262 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#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] );
	}

}