[INTERPRETER]

* BUG: Shell$() does not try to convert into current locale anymore.


git-svn-id: svn://localhost/gambas/trunk@7542 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2016-01-02 11:11:52 +00:00
parent a6f458e05c
commit 66f5c498d2

View file

@ -47,10 +47,10 @@ static PCRE_INTERFACE PCRE;
static void init_pcre() static void init_pcre()
{ {
static bool init = FALSE; static bool init = FALSE;
if (init) if (init)
return; return;
COMPONENT_load(COMPONENT_create("gb.pcre")); COMPONENT_load(COMPONENT_create("gb.pcre"));
LIBRARY_get_interface_by_name("gb.pcre", PCRE_INTERFACE_VERSION, &PCRE); LIBRARY_get_interface_by_name("gb.pcre", PCRE_INTERFACE_VERSION, &PCRE);
init = TRUE; init = TRUE;
@ -66,19 +66,19 @@ void SUBR_cat(ushort code)
{ {
int len, len2; int len, len2;
char *str; char *str;
VALUE_conv_string(&PARAM[0]); VALUE_conv_string(&PARAM[0]);
len = PARAM[0]._string.len ; len = PARAM[0]._string.len ;
VALUE_conv_string(&PARAM[1]); VALUE_conv_string(&PARAM[1]);
len2 = PARAM[1]._string.len; len2 = PARAM[1]._string.len;
#if 0 #if 0
if (EXEC_string_add) if (EXEC_string_add)
{ {
EXEC_string_add = FALSE; EXEC_string_add = FALSE;
str = PARAM[0]._string.addr; str = PARAM[0]._string.addr;
if (0 && PARAM[0].type == T_STRING && PARAM[0]._string.start == 0 && STRING_length(str) == len) if (0 && PARAM[0].type == T_STRING && PARAM[0]._string.start == 0 && STRING_length(str) == len)
{ {
if (str && !STRING_extend_will_realloc(str, len + len2)) if (str && !STRING_extend_will_realloc(str, len + len2))
@ -113,14 +113,14 @@ void SUBR_cat(ushort code)
}*/ }*/
} }
#endif #endif
str = STRING_new(NULL, len + len2); str = STRING_new(NULL, len + len2);
//fprintf(stderr, "normal: str = %p p0 = %p p1 = %p\n", str, PARAM[0]._string.addr + PARAM[0]._string.start, PARAM[1]._string.addr + PARAM[1]._string.start); //fprintf(stderr, "normal: str = %p p0 = %p p1 = %p\n", str, PARAM[0]._string.addr + PARAM[0]._string.start, PARAM[1]._string.addr + PARAM[1]._string.start);
memcpy(str, PARAM[0]._string.addr + PARAM[0]._string.start, len); memcpy(str, PARAM[0]._string.addr + PARAM[0]._string.start, len);
memcpy(&str[len], PARAM[1]._string.addr + PARAM[1]._string.start, len2); memcpy(&str[len], PARAM[1]._string.addr + PARAM[1]._string.start, len2);
RELEASE_STRING(&PARAM[0]); RELEASE_STRING(&PARAM[0]);
RELEASE_STRING(&PARAM[1]); RELEASE_STRING(&PARAM[1]);
@ -152,13 +152,13 @@ void SUBR_cat(ushort code)
while (i--) while (i--)
{ {
len = PARAM->_string.len; len = PARAM->_string.len;
if (len) if (len)
{ {
memcpy(ptr, PARAM->_string.addr + PARAM->_string.start, len); memcpy(ptr, PARAM->_string.addr + PARAM->_string.start, len);
ptr += len; ptr += len;
} }
RELEASE_STRING(PARAM); RELEASE_STRING(PARAM);
PARAM++; PARAM++;
} }
@ -219,7 +219,7 @@ void SUBR_file(ushort code)
if (PARAM->type != T_NULL) if (PARAM->type != T_NULL)
{ {
VALUE_get_string(PARAM, &addr, &len); VALUE_get_string(PARAM, &addr, &len);
if (len > 0) if (len > 0)
{ {
if (ptr > str) if (ptr > str)
@ -229,16 +229,16 @@ void SUBR_file(ushort code)
else if (slash && *addr == '/') else if (slash && *addr == '/')
ptr--; ptr--;
} }
slash = addr[len - 1] == '/'; slash = addr[len - 1] == '/';
memcpy(ptr, addr, len); memcpy(ptr, addr, len);
ptr += len; ptr += len;
} }
RELEASE_STRING(PARAM); RELEASE_STRING(PARAM);
} }
PARAM++; PARAM++;
} }
@ -368,9 +368,9 @@ void SUBR_upper(ushort code)
{ {
char *str; char *str;
int len, i; int len, i;
SUBR_ENTER_PARAM(1); SUBR_ENTER_PARAM(1);
if (SUBR_check_string(PARAM)) if (SUBR_check_string(PARAM))
{ {
VOID_STRING(&SP[-1]); VOID_STRING(&SP[-1]);
@ -381,7 +381,7 @@ void SUBR_upper(ushort code)
if (len > 0) if (len > 0)
{ {
str = STRING_new(&PARAM->_string.addr[PARAM->_string.start], PARAM->_string.len); str = STRING_new(&PARAM->_string.addr[PARAM->_string.start], PARAM->_string.len);
if (code & 0x3F) if (code & 0x3F)
{ {
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
@ -392,7 +392,7 @@ void SUBR_upper(ushort code)
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
str[i] = toupper(str[i]); str[i] = toupper(str[i]);
} }
SP--; SP--;
RELEASE_STRING(SP); RELEASE_STRING(SP);
SP->type = T_STRING; SP->type = T_STRING;
@ -481,7 +481,7 @@ void SUBR_instr(ushort code)
if (NPARAM >= 3) if (NPARAM >= 3)
is = SUBR_get_integer(&PARAM[2]); is = SUBR_get_integer(&PARAM[2]);
if (NPARAM == 4) if (NPARAM == 4)
nocase = SUBR_get_integer(&PARAM[3]) == GB_COMP_NOCASE; nocase = SUBR_get_integer(&PARAM[3]) == GB_COMP_NOCASE;
@ -515,14 +515,14 @@ void SUBR_like(ushort code)
SUBR_get_string_len(&PARAM[1], &pattern, &len_pattern); SUBR_get_string_len(&PARAM[1], &pattern, &len_pattern);
goto *jump[code & 0x3]; goto *jump[code & 0x3];
__LIKE: __LIKE:
ret = REGEXP_match(pattern, len_pattern, string, len_string); ret = REGEXP_match(pattern, len_pattern, string, len_string);
goto __RETURN; goto __RETURN;
__BEGINS: __BEGINS:
if (len_pattern == 0) if (len_pattern == 0)
ret = TRUE; ret = TRUE;
else if (len_pattern <= len_string) else if (len_pattern <= len_string)
@ -530,13 +530,13 @@ __BEGINS:
goto __RETURN; goto __RETURN;
__ENDS: __ENDS:
if (len_pattern == 0) if (len_pattern == 0)
ret = TRUE; ret = TRUE;
else if (len_pattern <= len_string) else if (len_pattern <= len_string)
ret = STRING_equal_same(string + len_string - len_pattern, pattern, len_pattern); ret = STRING_equal_same(string + len_string - len_pattern, pattern, len_pattern);
goto __RETURN; goto __RETURN;
__MATCH: __MATCH:
init_pcre(); init_pcre();
@ -544,7 +544,7 @@ __MATCH:
goto __RETURN; goto __RETURN;
__RETURN: __RETURN:
RETURN->type = T_BOOLEAN; RETURN->type = T_BOOLEAN;
RETURN->_boolean.value = -(ret ^ !!(code & 0x4)); RETURN->_boolean.value = -(ret ^ !!(code & 0x4));
@ -624,22 +624,22 @@ void SUBR_replace(ushort code)
{ {
char cp = *pp; char cp = *pp;
char cr = *pr; char cr = *pr;
ps = STRING_new_temp(ps, ls); ps = STRING_new_temp(ps, ls);
for (pos = 0; pos < ls; pos++) for (pos = 0; pos < ls; pos++)
{ {
if (ps[pos] == cp) if (ps[pos] == cp)
ps[pos] = cr; ps[pos] = cr;
} }
RETURN->_string.addr = ps; RETURN->_string.addr = ps;
RETURN->_string.len = ls; RETURN->_string.len = ls;
} }
else else
{ {
STRING_start_len(ls); STRING_start_len(ls);
for(;;) for(;;)
{ {
pos = STRING_search(ps, ls, pp, lp, 1, FALSE, nocase); pos = STRING_search(ps, ls, pp, lp, 1, FALSE, nocase);
@ -661,7 +661,7 @@ void SUBR_replace(ushort code)
if (ls <= 0) if (ls <= 0)
break; break;
} }
STRING_make(ps, ls); STRING_make(ps, ls);
RETURN->_string.addr = STRING_end_temp(); RETURN->_string.addr = STRING_end_temp();
RETURN->_string.len = STRING_length(RETURN->_string.addr); RETURN->_string.len = STRING_length(RETURN->_string.addr);
@ -686,7 +686,7 @@ void SUBR_split(ushort code)
bool keep_esc = FALSE; bool keep_esc = FALSE;
SUBR_ENTER(); SUBR_ENTER();
VALUE_conv_string(PARAM); VALUE_conv_string(PARAM);
VALUE_get_string(PARAM, &str, &lstr); VALUE_get_string(PARAM, &str, &lstr);
@ -899,23 +899,23 @@ void SUBR_is_chr(ushort code)
void SUBR_tr(void) void SUBR_tr(void)
{ {
char *str; char *str;
SUBR_ENTER_PARAM(1); SUBR_ENTER_PARAM(1);
VALUE_conv_string(&PARAM[0]); VALUE_conv_string(&PARAM[0]);
if (SUBR_check_string(PARAM)) if (SUBR_check_string(PARAM))
STRING_void_value(RETURN); STRING_void_value(RETURN);
else else
{ {
str = STRING_new_temp(&PARAM->_string.addr[PARAM->_string.start], PARAM->_string.len); str = STRING_new_temp(&PARAM->_string.addr[PARAM->_string.start], PARAM->_string.len);
RETURN->type = T_CSTRING; RETURN->type = T_CSTRING;
RETURN->_string.addr = (char *)LOCAL_gettext(str); RETURN->_string.addr = (char *)LOCAL_gettext(str);
RETURN->_string.start = 0; RETURN->_string.start = 0;
RETURN->_string.len = strlen(RETURN->_string.addr); RETURN->_string.len = strlen(RETURN->_string.addr);
} }
SUBR_LEAVE(); SUBR_LEAVE();
} }
@ -935,22 +935,22 @@ void SUBR_quote(ushort code)
int i; int i;
unsigned char c; unsigned char c;
char buf[8]; char buf[8];
SUBR_ENTER_PARAM(1); SUBR_ENTER_PARAM(1);
VALUE_conv_string(&PARAM[0]); VALUE_conv_string(&PARAM[0]);
str = PARAM->_string.addr + PARAM->_string.start; str = PARAM->_string.addr + PARAM->_string.start;
lstr = PARAM->_string.len; lstr = PARAM->_string.len;
STRING_start_len(lstr); STRING_start_len(lstr);
goto *jump[code & 0x7]; goto *jump[code & 0x7];
__QUOTE: __QUOTE:
STRING_make_char('"'); STRING_make_char('"');
for (i = 0; i < lstr; i++) for (i = 0; i < lstr; i++)
{ {
c = str[i]; c = str[i];
@ -975,22 +975,22 @@ __QUOTE:
STRING_make_char(c); STRING_make_char(c);
} }
} }
STRING_make_char('"'); STRING_make_char('"');
goto __END; goto __END;
__SHELL: __SHELL:
if (!LOCAL_is_UTF8) /*if (!LOCAL_is_UTF8)
{ {
char *conv; char *conv;
STRING_conv(&conv, str, lstr, SC_UTF8, LOCAL_encoding, FALSE); STRING_conv(&conv, str, lstr, SC_UTF8, LOCAL_encoding, FALSE);
str = conv; str = conv;
lstr = str ? strlen(str) : 0; lstr = str ? strlen(str) : 0;
} }*/
// TODO: The following works with bash, but not with dash! // TODO: The following works with bash, but not with dash!
STRING_make_char('\''); STRING_make_char('\'');
for (i = 0; i < lstr; i++) for (i = 0; i < lstr; i++)
@ -1022,7 +1022,7 @@ __SHELL:
} }
*/ */
} }
STRING_make_char('\''); STRING_make_char('\'');
goto __END; goto __END;
@ -1050,15 +1050,15 @@ __HTML:
else else
STRING_make_char(c); STRING_make_char(c);
} }
goto __END; goto __END;
__BASE64: __BASE64:
{ {
static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
uchar *in; uchar *in;
char *out = buf; char *out = buf;
for (i = 0; i < (lstr - 2); i += 3) for (i = 0; i < (lstr - 2); i += 3)
{ {
in = (uchar *)&str[i]; in = (uchar *)&str[i];
@ -1134,7 +1134,7 @@ __JAVASCRIPT:
STRING_make_char('\''); STRING_make_char('\'');
} }
goto __END; goto __END;
#endif #endif
@ -1168,25 +1168,25 @@ static int read_hex_digit(unsigned char c)
void SUBR_unquote(ushort code) void SUBR_unquote(ushort code)
{ {
static void *jump[4] = { &&__UNQUOTE, &&__FROM_BASE64, &&__FROM_URL, &&__ILLEGAL }; static void *jump[4] = { &&__UNQUOTE, &&__FROM_BASE64, &&__FROM_URL, &&__ILLEGAL };
char *str; char *str;
int lstr; int lstr;
int i; int i;
unsigned char c; unsigned char c;
SUBR_ENTER_PARAM(1); SUBR_ENTER_PARAM(1);
VALUE_conv_string(&PARAM[0]); VALUE_conv_string(&PARAM[0]);
str = PARAM->_string.addr + PARAM->_string.start; str = PARAM->_string.addr + PARAM->_string.start;
lstr = PARAM->_string.len; lstr = PARAM->_string.len;
STRING_start_len(lstr); STRING_start_len(lstr);
goto *jump[code & 0x3]; goto *jump[code & 0x3];
__UNQUOTE: __UNQUOTE:
if (lstr >= 2 && str[0] == '"' && str[lstr - 1] == '"') if (lstr >= 2 && str[0] == '"' && str[lstr - 1] == '"')
{ {
str++; str++;
@ -1202,7 +1202,7 @@ __UNQUOTE:
if (i >= lstr) if (i >= lstr)
break; break;
c = str[i]; c = str[i];
if (c == 'n') if (c == 'n')
c = '\n'; c = '\n';
else if (c == 't') else if (c == 't')
@ -1213,23 +1213,23 @@ __UNQUOTE:
{ {
if (i >= (lstr - 2)) if (i >= (lstr - 2))
break; break;
c = (read_hex_digit(str[i + 1]) << 4) + read_hex_digit(str[i + 2]); c = (read_hex_digit(str[i + 1]) << 4) + read_hex_digit(str[i + 2]);
i += 2; i += 2;
} }
} }
STRING_make_char(c); STRING_make_char(c);
} }
goto __END; goto __END;
__FROM_BASE64: __FROM_BASE64:
{ {
char buf[4]; char buf[4];
unsigned char n = 0; unsigned char n = 0;
for (i = 0; i < lstr; i++) for (i = 0; i < lstr; i++)
{ {
c = str[i]; c = str[i];
@ -1247,7 +1247,7 @@ __FROM_BASE64:
break; break;
else else
continue; continue;
switch (n & 3) switch (n & 3)
{ {
case 0: buf[0] = c << 2; break; case 0: buf[0] = c << 2; break;
@ -1261,7 +1261,7 @@ __FROM_BASE64:
if ((n & 3) > 1) if ((n & 3) > 1)
STRING_make(buf, (n & 3) - 1); STRING_make(buf, (n & 3) - 1);
} }
goto __END; goto __END;
__FROM_URL: __FROM_URL:
@ -1288,14 +1288,14 @@ __FROM_URL:
__ILLEGAL: __ILLEGAL:
THROW_ILLEGAL(); THROW_ILLEGAL();
__END: __END:
RETURN->type = T_STRING; RETURN->type = T_STRING;
RETURN->_string.addr = STRING_end_temp(); RETURN->_string.addr = STRING_end_temp();
RETURN->_string.start = 0; RETURN->_string.start = 0;
RETURN->_string.len = STRING_length(RETURN->_string.addr); RETURN->_string.len = STRING_length(RETURN->_string.addr);
SUBR_LEAVE(); SUBR_LEAVE();
} }
@ -1309,9 +1309,9 @@ void SUBR_swap(ushort code)
SUBR_move(1); SUBR_move(1);
return; return;
} }
SUBR_ENTER(); SUBR_ENTER();
if (NPARAM == 2 && (SUBR_get_integer(&PARAM[1]) == GB_BIG_ENDIAN) == EXEC_big_endian) if (NPARAM == 2 && (SUBR_get_integer(&PARAM[1]) == GB_BIG_ENDIAN) == EXEC_big_endian)
{ {
SP--; SP--;
@ -1337,7 +1337,7 @@ void SUBR_swap(ushort code)
RETURN->_string.len = len; RETURN->_string.len = len;
} }
} }
SUBR_LEAVE(); SUBR_LEAVE();
} }