aboutsummaryrefslogtreecommitdiff
path: root/src/survive_driverman.c
blob: 2afaf65c94125e40ba60153f6e83b294d5d77c14 (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
51
52
53
54
// (C) 2017 <>< C. N. Lohr, Under MIT/x11 License.
//
// See notice in survive_driverman.h
//

#include "survive_internal.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 = (int)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] );
	}
}