aboutsummaryrefslogtreecommitdiff
path: root/loslib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2016-02-09 10:16:11 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2016-02-09 10:16:11 -0200
commit5f3ad5731ebf6d80a4282462d7ce19d6906b8a2d (patch)
treea4e94d45547a900c296d7eabbb2c49f6dc0c45ae /loslib.c
parent494e9ba0f477b19603092cb01423003bdc1dd740 (diff)
downloadlua-5f3ad5731ebf6d80a4282462d7ce19d6906b8a2d.tar.gz
lua-5f3ad5731ebf6d80a4282462d7ce19d6906b8a2d.tar.bz2
lua-5f3ad5731ebf6d80a4282462d7ce19d6906b8a2d.zip
simpler yet definition for 'checkoption'
Diffstat (limited to 'loslib.c')
-rw-r--r--loslib.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/loslib.c b/loslib.c
index 7e5b60b7..1f893cc0 100644
--- a/loslib.c
+++ b/loslib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: loslib.c,v 1.60 2015/11/19 19:16:22 roberto Exp $ 2** $Id: loslib.c,v 1.62 2016/02/08 14:42:46 roberto Exp roberto $
3** Standard Operating System library 3** Standard Operating System library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -25,24 +25,21 @@
25/* 25/*
26** {================================================================== 26** {==================================================================
27** List of valid conversion specifiers for the 'strftime' function; 27** List of valid conversion specifiers for the 'strftime' function;
28** each option ends with a '|'. 28** options are grouped by length; group of length 2 start with '||'.
29** =================================================================== 29** ===================================================================
30*/ 30*/
31#if !defined(LUA_STRFTIMEOPTIONS) /* { */ 31#if !defined(LUA_STRFTIMEOPTIONS) /* { */
32 32
33/* options for ANSI C 89 */ 33/* options for ANSI C 89 */
34#define L_STRFTIMEC89 \ 34#define L_STRFTIMEC89 "aAbBcdHIjmMpSUwWxXyYZ%"
35 "a|A|b|B|c|d|H|I|j|m|M|p|S|U|w|W|x|X|y|Y|Z|%|"
36 35
37/* options for ISO C 99 and POSIX */ 36/* options for ISO C 99 and POSIX */
38#define L_STRFTIMEC99 \ 37#define L_STRFTIMEC99 "aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%" \
39 L_STRFTIMEC89 "C|D|e|F|g|G|h|n|r|R|t|T|u|V|z|" \ 38 "||" "EcECExEXEyEY" "OdOeOHOIOmOMOSOuOUOVOwOWOy"
40 "Ec|EC|Ex|EX|Ey|EY|" \
41 "Od|Oe|OH|OI|Om|OM|OS|Ou|OU|OV|Ow|OW|Oy|"
42 39
43/* options for Windows */ 40/* options for Windows */
44#define L_STRFTIMEWIN \ 41#define L_STRFTIMEWIN "aAbBcdHIjmMpSUwWxXyYzZ%" \
45 L_STRFTIMEC89 "z|#c|#x|#d|#H|#I|#j|#m|#M|#S|#U|#w|#W|#y|#Y|" 42 "||" "#c#x#d#H#I#j#m#M#S#U#w#W#y#Y"
46 43
47#if defined(LUA_USE_WINDOWS) 44#if defined(LUA_USE_WINDOWS)
48#define LUA_STRFTIMEOPTIONS L_STRFTIMEWIN 45#define LUA_STRFTIMEOPTIONS L_STRFTIMEWIN
@@ -244,17 +241,16 @@ static int getfield (lua_State *L, const char *key, int d, int delta) {
244 241
245 242
246static const char *checkoption (lua_State *L, const char *conv, char *buff) { 243static const char *checkoption (lua_State *L, const char *conv, char *buff) {
247 const char *option = LUA_STRFTIMEOPTIONS; 244 const char *option;
248 const char *opend; 245 int oplen = 1;
249 while ((opend = strchr(option, '|')) != NULL) { /* for each option */ 246 for (option = LUA_STRFTIMEOPTIONS; *option != '\0'; option += oplen) {
250 ptrdiff_t oplen = opend - option; /* get its length */ 247 if (*option == '|') /* next block? */
251 if (memcmp(conv, option, oplen) == 0) { /* match? */ 248 oplen++; /* next length */
252 memcpy(buff, conv, oplen); /* copy option to buffer */ 249 else if (memcmp(conv, option, oplen) == 0) { /* match? */
250 memcpy(buff, conv, oplen); /* copy valid option to buffer */
253 buff[oplen] = '\0'; 251 buff[oplen] = '\0';
254 return conv + oplen; /* return next item */ 252 return conv + oplen; /* return next item */
255 } 253 }
256 else
257 option += oplen + 1; /* step to next option */
258 } 254 }
259 luaL_argerror(L, 1, 255 luaL_argerror(L, 1,
260 lua_pushfstring(L, "invalid conversion specifier '%%%s'", conv)); 256 lua_pushfstring(L, "invalid conversion specifier '%%%s'", conv));