mirror of https://github.com/rusefi/lua.git
simpler yet definition for 'checkoption'
This commit is contained in:
parent
494e9ba0f4
commit
5f3ad5731e
32
loslib.c
32
loslib.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: loslib.c,v 1.60 2015/11/19 19:16:22 roberto Exp $
|
** $Id: loslib.c,v 1.62 2016/02/08 14:42:46 roberto Exp roberto $
|
||||||
** Standard Operating System library
|
** Standard Operating System library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -25,24 +25,21 @@
|
||||||
/*
|
/*
|
||||||
** {==================================================================
|
** {==================================================================
|
||||||
** List of valid conversion specifiers for the 'strftime' function;
|
** List of valid conversion specifiers for the 'strftime' function;
|
||||||
** each option ends with a '|'.
|
** options are grouped by length; group of length 2 start with '||'.
|
||||||
** ===================================================================
|
** ===================================================================
|
||||||
*/
|
*/
|
||||||
#if !defined(LUA_STRFTIMEOPTIONS) /* { */
|
#if !defined(LUA_STRFTIMEOPTIONS) /* { */
|
||||||
|
|
||||||
/* options for ANSI C 89 */
|
/* options for ANSI C 89 */
|
||||||
#define L_STRFTIMEC89 \
|
#define L_STRFTIMEC89 "aAbBcdHIjmMpSUwWxXyYZ%"
|
||||||
"a|A|b|B|c|d|H|I|j|m|M|p|S|U|w|W|x|X|y|Y|Z|%|"
|
|
||||||
|
|
||||||
/* options for ISO C 99 and POSIX */
|
/* options for ISO C 99 and POSIX */
|
||||||
#define L_STRFTIMEC99 \
|
#define L_STRFTIMEC99 "aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%" \
|
||||||
L_STRFTIMEC89 "C|D|e|F|g|G|h|n|r|R|t|T|u|V|z|" \
|
"||" "EcECExEXEyEY" "OdOeOHOIOmOMOSOuOUOVOwOWOy"
|
||||||
"Ec|EC|Ex|EX|Ey|EY|" \
|
|
||||||
"Od|Oe|OH|OI|Om|OM|OS|Ou|OU|OV|Ow|OW|Oy|"
|
|
||||||
|
|
||||||
/* options for Windows */
|
/* options for Windows */
|
||||||
#define L_STRFTIMEWIN \
|
#define L_STRFTIMEWIN "aAbBcdHIjmMpSUwWxXyYzZ%" \
|
||||||
L_STRFTIMEC89 "z|#c|#x|#d|#H|#I|#j|#m|#M|#S|#U|#w|#W|#y|#Y|"
|
"||" "#c#x#d#H#I#j#m#M#S#U#w#W#y#Y"
|
||||||
|
|
||||||
#if defined(LUA_USE_WINDOWS)
|
#if defined(LUA_USE_WINDOWS)
|
||||||
#define LUA_STRFTIMEOPTIONS L_STRFTIMEWIN
|
#define LUA_STRFTIMEOPTIONS L_STRFTIMEWIN
|
||||||
|
@ -244,17 +241,16 @@ static int getfield (lua_State *L, const char *key, int d, int delta) {
|
||||||
|
|
||||||
|
|
||||||
static const char *checkoption (lua_State *L, const char *conv, char *buff) {
|
static const char *checkoption (lua_State *L, const char *conv, char *buff) {
|
||||||
const char *option = LUA_STRFTIMEOPTIONS;
|
const char *option;
|
||||||
const char *opend;
|
int oplen = 1;
|
||||||
while ((opend = strchr(option, '|')) != NULL) { /* for each option */
|
for (option = LUA_STRFTIMEOPTIONS; *option != '\0'; option += oplen) {
|
||||||
ptrdiff_t oplen = opend - option; /* get its length */
|
if (*option == '|') /* next block? */
|
||||||
if (memcmp(conv, option, oplen) == 0) { /* match? */
|
oplen++; /* next length */
|
||||||
memcpy(buff, conv, oplen); /* copy option to buffer */
|
else if (memcmp(conv, option, oplen) == 0) { /* match? */
|
||||||
|
memcpy(buff, conv, oplen); /* copy valid option to buffer */
|
||||||
buff[oplen] = '\0';
|
buff[oplen] = '\0';
|
||||||
return conv + oplen; /* return next item */
|
return conv + oplen; /* return next item */
|
||||||
}
|
}
|
||||||
else
|
|
||||||
option += oplen + 1; /* step to next option */
|
|
||||||
}
|
}
|
||||||
luaL_argerror(L, 1,
|
luaL_argerror(L, 1,
|
||||||
lua_pushfstring(L, "invalid conversion specifier '%%%s'", conv));
|
lua_pushfstring(L, "invalid conversion specifier '%%%s'", conv));
|
||||||
|
|
Loading…
Reference in New Issue