diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 3b15ddb7..332b712d 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c,v 1.132 2006-07-01 16:24:36 bacon Exp $ + * $Id: parse.c,v 1.133 2006-07-02 12:16:24 bacon Exp $ */ #include @@ -3465,25 +3465,96 @@ static int __get_string (xp_awk_t* awk) { xp_cint_t c; int escaped = 0; + int digit_count = 0; + xp_cint_t c_acc; - GET_CHAR_TO (awk, c); while (1) { + GET_CHAR_TO (awk, c); + if (c == XP_CHAR_EOF) { awk->errnum = XP_AWK_EENDSTR; return -1; } + if (escaped == 3) + { + if (c >= XP_T('0') && c <= XP_T('7')) + { + c_acc = c_acc * 8 + c - XP_T('0'); + digit_count++; + if (digit_count >= escaped) + { + ADD_TOKEN_CHAR (awk, c_acc); + escaped = 0; + } + continue; + } + else + { + ADD_TOKEN_CHAR (awk, c_acc); + escaped = 0; + } + } + else if (escaped == 2 || escaped == 4 || escaped == 8) + { + if (c >= XP_T('0') && c <= XP_T('9')) + { + c_acc = c_acc * 16 + c - XP_T('0'); + digit_count++; + if (digit_count >= escaped) + { + ADD_TOKEN_CHAR (awk, c_acc); + escaped = 0; + } + continue; + } + else if (c >= XP_T('A') && c <= XP_T('F')) + { + c_acc = c_acc * 16 + c - XP_T('A') + 10; + digit_count++; + if (digit_count >= escaped) + { + ADD_TOKEN_CHAR (awk, c_acc); + escaped = 0; + } + continue; + } + else if (c >= XP_T('a') && c <= XP_T('f')) + { + c_acc = c_acc * 16 + c - XP_T('a') + 10; + digit_count++; + if (digit_count >= escaped) + { + ADD_TOKEN_CHAR (awk, c_acc); + escaped = 0; + } + continue; + } + else + { + xp_char_t rc; + + rc = (escaped == 2)? XP_T('x'): + (escaped == 4)? XP_T('u'): XP_T('U'); + + if (digit_count == 0) ADD_TOKEN_CHAR (awk, rc); + else ADD_TOKEN_CHAR (awk, c_acc); + + escaped = 0; + } + } + if (escaped == 0 && c == XP_T('\"')) { + /* terminating quote */ GET_CHAR_TO (awk, c); break; } if (escaped == 0 && c == XP_T('\\')) { - GET_CHAR_TO (awk, c); escaped = 1; continue; } @@ -3497,40 +3568,41 @@ static int __get_string (xp_awk_t* awk) else if (c == XP_T('b')) c = XP_T('\b'); else if (c == XP_T('v')) c = XP_T('\v'); else if (c == XP_T('a')) c = XP_T('\a'); - else if (c == XP_T('0')) escaped = 2; - else if (c == XP_T('x')) escaped = 3; + else if (c >= XP_T('0') && c <= XP_T('7')) + { + escaped = 3; + digit_count = 1; + c_acc = c - XP_T('0'); + continue; + } + else if (c == XP_T('x')) + { + escaped = 2; + digit_count = 0; + c_acc = 0; + continue; + } #ifdef XP_CHAR_IS_WCHAR - else if (c == XP_T('u')) escaped = 4; - else if (c == XP_T('U')) escaped = 5; + else if (c == XP_T('u') && xp_sizeof(xp_char_t) >= 2) + { + escaped = 4; + digit_count = 0; + c_acc = 0; + continue; + } + else if (c == XP_T('U') && xp_sizeof(xp_char_t) >= 4) + { + escaped = 8; + digit_count = 0; + c_acc = 0; + continue; + } #endif - if (escaped == 1) escaped = 0; + escaped = 0; } - else if (escaped == 2) - { - /* 3-digit octal code */ - /* TODO */ - } - else if (escaped == 3) - { - /* 2-digit hex code */ - /* TODO */ - } - #ifdef XP_CHAR_IS_WCHAR - else if (escaped == 4) - { - /* 4-digit hex unicode */ - /* TODO */ - } - else if (escaped == 5) - { - /* 8-digit hex unicode */ - /* TODO */ - } - #endif ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); } return 0; diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c index 647169eb..f061020d 100644 --- a/ase/test/awk/awk.c +++ b/ase/test/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.50 2006-06-30 06:16:57 bacon Exp $ + * $Id: awk.c,v 1.51 2006-07-02 12:16:24 bacon Exp $ */ #include @@ -24,6 +24,7 @@ #endif #ifdef _WIN32 +#include #include #pragma warning (disable: 4996) #endif @@ -391,6 +392,7 @@ xp_printf (XP_TEXT("closing [%s] of type %d (console)\n"), epa->name, epa->type /* TODO: how to return error or 0 */ fputs_t (data, /*size,*/ (FILE*)epa->handle); /*fputs_t (data, stdout);*/ + MessageBox (NULL, data, data, MB_OK); return size; } diff --git a/ase/test/awk/makefile.cl b/ase/test/awk/makefile.cl index 85f339ce..ebe8cd34 100644 --- a/ase/test/awk/makefile.cl +++ b/ase/test/awk/makefile.cl @@ -2,7 +2,7 @@ CC = cl #CFLAGS = /nologo /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I..\..\.. CFLAGS = /nologo /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I..\..\.. -D__STAND_ALONE LDFLAGS = /libpath:..\..\bas /libpath:..\..\awk -LIBS = xpawk.lib +LIBS = xpawk.lib user32.lib all: awk diff --git a/ase/test/awk/t15.awk b/ase/test/awk/t15.awk new file mode 100644 index 00000000..86c473dd --- /dev/null +++ b/ase/test/awk/t15.awk @@ -0,0 +1,10 @@ +BEGIN +{ + print ("\x5C"); + print ("\x5C6_ABCDEGH"); + print ("\xZZ5C6_ABCDEGH"); + print ("\xZZ5C6_AB\u7658&&"); + print "\uC720\uB2C8\uCF54\uB4DC \uD14C\uC2A4\uD2B8"; + print "\UC720\UB2C8\UCF54\UB4DC \UD14C\UC2A4\UD2B8"; +} +