Added new files device.c and device.h

This commit is contained in:
Pali Rohár committed 2012-08-07 16:57:55 +02:00
1 parent b596e97926
commit 03eeca994d
2 files changed
+57

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "device.h"
static const char * devices[] = {
[DEVICE_SU_18] = "SU-18",
[DEVICE_RX_34] = "RX-34",
[DEVICE_RX_44] = "RX-44",
[DEVICE_RX_48] = "RX-48",
[DEVICE_RX_51] = "RX-51",
};
enum device device_from_string(const char * device) {
size_t i;
if ( ! device )
return DEVICE_ANY;
for ( i = 0; i < sizeof(devices)/sizeof(devices[0]); ++i )
if ( devices[i] && strcmp(devices[i], device) == 0 )
return i;
return DEVICE_UNKNOWN;
}
const char * device_to_string(enum device device) {
if ( device > sizeof(devices) )
return NULL;
return devices[device];
}
+18
View File
@@ -0,0 +1,18 @@
#ifndef DEVICE_H
#define DEVICE_H
enum device {
DEVICE_UNKNOWN = 0,
DEVICE_ANY, /* Unspecified / Any device */
DEVICE_SU_18, /* Nokia 770 */
DEVICE_RX_34, /* Nokia N800 */
DEVICE_RX_44, /* Nokia N810 */
DEVICE_RX_48, /* Nokia N810 WiMax */
DEVICE_RX_51, /* Nokia N900 */
};
enum device device_from_string(const char * device);
const char * device_to_string(enum device device);
#endif