librfn
An ad-hoc utility library
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
librfn
enum.c
Go to the documentation of this file.
1
/*
2
* enum.c
3
*
4
* Part of librfn (a general utility library from redfelineninja.org.uk)
5
*
6
* Copyright (C) 2012 Daniel Thompson <daniel@redfelineninja.org.uk>
7
*
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU Lesser General Public License as published
10
* by the Free Software Foundation; either version 3 of the License, or
11
* (at your option) any later version.
12
*/
13
14
#include <
string.h
>
15
16
#include "
librfn.h
"
17
18
const
char
*
rf_enum2string
(
rf_enumtable_t
*t,
int
e)
19
{
20
for
(; t->
s
; t++) {
21
if
(t->
e
== e)
22
return
t->
s
;
23
}
24
25
return
NULL;
26
}
27
28
int
rf_string2enum
(
rf_enumtable_t
*t,
const
char
*s)
29
{
30
for
(; t->
s
; t++) {
31
if
(0 == strcmp(t->
s
, s))
32
return
t->
e
;
33
}
34
35
return
RF_ENUM_OUT_OF_RANGE
;
36
}
string.h
rf_enum2string
const char * rf_enum2string(rf_enumtable_t *t, int e)
Definition:
enum.c:18
rf_string2enum
int rf_string2enum(rf_enumtable_t *t, const char *s)
Definition:
enum.c:28
rf_enumtable_t
Lookup table used for the conversions.
Definition:
enum.h:43
rf_enumtable_t::e
int e
Definition:
enum.h:45
librfn.h
rf_enumtable_t::s
const char * s
Definition:
enum.h:44
RF_ENUM_OUT_OF_RANGE
#define RF_ENUM_OUT_OF_RANGE
Definition:
enum.h:56
Generated on Sat Feb 6 2016 21:25:32 for librfn by
1.8.10