Skip to content

Commit

Permalink
fcoemon: Add string array support
Browse files Browse the repository at this point in the history
Add generalized string array support for new code.

Signed-off-by: Mark Rustad <mark.d.rustad@intel.com>
Tested-by: Ross Brattain <ross.b.brattain@intel.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
  • Loading branch information
mdrustad authored and Robert Love committed Jun 24, 2011
1 parent aef23b9 commit 6611cc0
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions include/strarr.h
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2011 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
*
* Maintained at www.Open-FCoE.org
*/

#ifndef _STRARR_H_
#define _STRARR_H_

typedef const char * const _strarr[];

struct _str_arr_desc {
const unsigned limit;
const _strarr * const str_arr;
const char * const unknown_str;
const char * const out_of_range_str;
};

#define GEN_STR_ARR(sc, sz, nm, unk, oor, ...) \
static const char * const _##nm##_strs[sz] = { __VA_ARGS__ }; \
sc const struct _str_arr_desc nm = { \
.limit = sizeof(_##nm##_strs) / sizeof(_##nm##_strs[0]),\
.str_arr = &_##nm##_strs, \
.unknown_str = unk, \
.out_of_range_str = oor, \
}

#define EXT_STR_ARR(nm, unk, oor, ...) \
GEN_STR_ARR(, , nm, unk, oor, __VA_ARGS__)
#define EXT_STR_ARR_SZ(nm, sz, unk, oor, ...) \
GEN_STR_ARR(, sz, nm, unk, oor, __VA_ARGS__)
#define STR_ARR(nm, unk, oor, ...) \
GEN_STR_ARR(static, , nm, unk, oor, __VA_ARGS__)
#define STR_ARR_SZ(nm, sz, unk, oor, ...) \
GEN_STR_ARR(static, sz, nm, unk, oor, __VA_ARGS__)

static inline const char *
getstr(const struct _str_arr_desc *desc, unsigned ix)
{
const char *str;

if (ix >= desc->limit)
return desc->out_of_range_str;
str = (*desc->str_arr)[ix];
if (!str)
return desc->unknown_str;

return str;
}

#endif /* _STRARR_H_ */

0 comments on commit 6611cc0

Please sign in to comment.