From ef62b340e0a6b7b18931000dcbb19c4703bfe0e8 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 24 May 2000 10:54:49 -0300 Subject: code cleaner for 16 bits. --- lstrlib.c | 67 +++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 35 insertions(+), 32 deletions(-) (limited to 'lstrlib.c') diff --git a/lstrlib.c b/lstrlib.c index 6a38fd01..da75bbd7 100644 --- a/lstrlib.c +++ b/lstrlib.c @@ -1,11 +1,12 @@ /* -** $Id: lstrlib.c,v 1.41 2000/03/03 14:58:26 roberto Exp roberto $ +** $Id: lstrlib.c,v 1.42 2000/05/02 18:32:22 roberto Exp roberto $ ** Standard library for string operations and pattern-matching ** See Copyright Notice in lua.h */ #include +#include #include #include #include @@ -18,7 +19,7 @@ -static void addnchar (lua_State *L, const char *s, int n) { +static void addnchar (lua_State *L, const char *s, size_t n) { char *b = luaL_openspace(L, n); memcpy(b, s, n); luaL_addsize(L, n); @@ -26,7 +27,7 @@ static void addnchar (lua_State *L, const char *s, int n) { static void str_len (lua_State *L) { - long l; + size_t l; luaL_check_lstr(L, 1, &l); lua_pushnumber(L, l); } @@ -37,19 +38,19 @@ static void closeandpush (lua_State *L) { } -static long posrelat (long pos, long len) { +static long posrelat (long pos, size_t len) { /* relative string position: negative means back from end */ - return (pos>=0) ? pos : len+pos+1; + return (pos>=0) ? pos : (long)len+pos+1; } static void str_sub (lua_State *L) { - long l; + size_t l; const char *s = luaL_check_lstr(L, 1, &l); long start = posrelat(luaL_check_long(L, 2), l); long end = posrelat(luaL_opt_long(L, 3, -1), l); if (start < 1) start = 1; - if (end > l) end = l; + if (end > (long)l) end = l; if (start <= end) lua_pushlstring(L, s+start-1, end-start+1); else lua_pushstring(L, ""); @@ -57,8 +58,8 @@ static void str_sub (lua_State *L) { static void str_lower (lua_State *L) { - long l; - int i; + size_t l; + size_t i; const char *s = luaL_check_lstr(L, 1, &l); luaL_resetbuffer(L); for (i=0; isrc_end && luaI_singlematch((unsigned char)*(s+i), p, ep)) i++; /* keeps trying to match mith the maximum repetitions */ @@ -276,8 +278,8 @@ static const char *max_expand (lua_State *L, const char *s, const char *p, const } -static const char *min_expand (lua_State *L, const char *s, const char *p, const char *ep, - struct Capture *cap) { +static const char *min_expand (lua_State *L, const char *s, const char *p, + const char *ep, struct Capture *cap) { for (;;) { const char *res = match(L, s, ep+1, cap); if (res != NULL) @@ -317,15 +319,16 @@ static const char *end_capture (lua_State *L, const char *s, const char *p, static const char *match_capture (lua_State *L, const char *s, int level, struct Capture *cap) { int l = check_capture(L, level, cap); - int len = cap->capture[l].len; - if (cap->src_end-s >= len && + size_t len = cap->capture[l].len; + if ((size_t)(cap->src_end-s) >= len && memcmp(cap->capture[l].init, s, len) == 0) return s+len; else return NULL; } -static const char *match (lua_State *L, const char *s, const char *p, struct Capture *cap) { +static const char *match (lua_State *L, const char *s, const char *p, + struct Capture *cap) { init: /* using goto's to optimize tail recursion */ switch (*p) { case '(': /* start capture */ @@ -397,12 +400,12 @@ static const char *memfind (const char *s1, long l1, const char *s2, long l2) { static void str_find (lua_State *L) { - long l1, l2; + size_t l1, l2; const char *s = luaL_check_lstr(L, 1, &l1); const char *p = luaL_check_lstr(L, 2, &l2); long init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1; struct Capture cap; - luaL_arg_check(L, 0 <= init && init <= l1, 3, "out of range"); + luaL_arg_check(L, 0 <= init && (size_t)init <= l1, 3, "out of range"); if (lua_getparam(L, 4) != LUA_NOOBJECT || strpbrk(p, SPECIALS) == NULL) { /* no special characters? */ const char *s2 = memfind(s+init, l1-init, p, l2); @@ -434,8 +437,8 @@ static void str_find (lua_State *L) { static void add_s (lua_State *L, lua_Object newp, struct Capture *cap) { if (lua_isstring(L, newp)) { const char *news = lua_getstring(L, newp); - int l = lua_strlen(L, newp); - int i; + size_t l = lua_strlen(L, newp); + size_t i; for (i=0; i= 100) { /* no precision and string is too long to be formatted; -- cgit v1.2.3-55-g6feb