diff options
-rw-r--r-- | ChangeLog | 25 | ||||
-rwxr-xr-x | configure | 2 | ||||
-rw-r--r-- | match.c | 42 | ||||
-rw-r--r-- | parser.l | 6 | ||||
-rw-r--r-- | stream.c | 1 | ||||
-rw-r--r-- | txr.c | 3 |
6 files changed, 55 insertions, 24 deletions
@@ -1,5 +1,30 @@ 2009-11-17 Kaz Kylheku <kkylheku@gmail.com> + More removal of C99 wide character I/O, and tightening up + of standard conformance. + + * configure (lang_flags): Specify -D_POSIX_C_SOURCE=2 to obtain + POSIX 1003.1 and POSIX 1003.2 functions from the headers, + without GNU extensions. Specify -std=c89 to get C89 conformance + from gcc. + + * match.c (dump_byte_string): New function. + (dump_shell_string): Retargetted to object streams. + (dump_var, dump_bindings): Retargetted to object streams. + Changed back to using a byte string for the array index prefixes, + to avoid using the wide-character swprintf. + + * parser.l (grammar): Eliminate wcsdup uses in favor of chk_strdup. + Not only is wcsdup a GNU extension, it doesn't have the OOM check. + + * stream.c: Added <sys/wait.h> header to define WIFEXITED and others. + + * txr.c: Added include of <stdarg.h>. Removed <locale.h>, + (main): Removed setlocale call. Not needed any more, since wide + stream and string I/O is no longer used from the C library. + +2009-11-17 Kaz Kylheku <kkylheku@gmail.com> + Removing use of C99 wide character I/O. * stream.c (BROKEN_POPEN_GETWC): Macro removed. Work around no @@ -109,7 +109,7 @@ lex=${lex-'$(cross)$(tool_prefix)flex'} lexlib=${lexlib--lfl} yacc=${yacc-'$(cross)$(tool_prefix)yacc'} opt_flags=${opt_flags--O2} -lang_flags=${lang_flags--ansi -D_GNU_SOURCE} +lang_flags=${lang_flags--ansi -std=c89 -D_POSIX_C_SOURCE=2} diag_flags=${diag_flags--Wall} debug_flags=${debug_flags--g} lex_dbg_flags=${lex_dbg_flags-} @@ -105,30 +105,37 @@ void dump_shell_string(const wchar_t *str) { int ch; - putwchar('"'); + put_char(std_output, chr('"')); while ((ch = *str++) != 0) { switch (ch) { case '"': case '`': case '$': case '\\': case '\n': - putwchar('\\'); + put_char(std_output, chr('\\')); /* fallthrough */ default: - putwchar(ch); + put_char(std_output, chr(ch)); } } - putwchar('"'); + put_char(std_output, chr('"')); } -void dump_var(const wchar_t *name, wchar_t *pfx1, size_t len1, - wchar_t *pfx2, size_t len2, obj_t *value, int level) +void dump_byte_string(const char *str) +{ + while (*str) + put_char(std_output, chr(*str++)); +} + + +void dump_var(obj_t *var, char *pfx1, size_t len1, + char *pfx2, size_t len2, obj_t *value, int level) { if (len1 >= 112 || len2 >= 112) internal_error("too much depth in bindings"); if (stringp(value) || chrp(value)) { - fputws(name, stdout); - fputws(pfx1, stdout); - fputws(pfx2, stdout); - putwchar('='); + put_string(std_output, var); + dump_byte_string(pfx1); + dump_byte_string(pfx2); + put_char(std_output, chr('=')); if (stringp(value)) { dump_shell_string(c_str(value)); } else { @@ -137,7 +144,7 @@ void dump_var(const wchar_t *name, wchar_t *pfx1, size_t len1, mini[1] = 0; dump_shell_string(mini); } - putwchar('\n'); + put_char(std_output, chr('\n')); } else { obj_t *iter; int i; @@ -145,14 +152,14 @@ void dump_var(const wchar_t *name, wchar_t *pfx1, size_t len1, for (i = 0, iter = value; iter; iter = cdr(iter), i++) { if (level < opt_arraydims) { - add2 = swprintf(pfx2 + len2, 12, L"[%d]", i); + add2 = sprintf(pfx2 + len2, "[%d]", i); add1 = 0; } else { - add1 = swprintf(pfx1 + len1, 12, L"_%d", i); + add1 = sprintf(pfx1 + len1, "_%d", i); add2 = 0; } - dump_var(name, pfx1, len1 + add1, pfx2, len2 + add2, car(iter), level + 1); + dump_var(var, pfx1, len1 + add1, pfx2, len2 + add2, car(iter), level + 1); } } } @@ -160,17 +167,16 @@ void dump_var(const wchar_t *name, wchar_t *pfx1, size_t len1, void dump_bindings(obj_t *bindings) { if (opt_loglevel >= 2) { - fputws(L"raw_bindings:\n", stderr); + put_line(std_error, lit("raw_bindings:")); dump(bindings, std_error); } while (bindings) { - wchar_t pfx1[128], pfx2[128]; + char pfx1[128], pfx2[128]; obj_t *var = car(car(bindings)); obj_t *value = cdr(car(bindings)); - const wchar_t *name = c_str(symbol_name(var)); *pfx1 = 0; *pfx2 = 0; - dump_var(name, pfx1, 0, pfx2, 0, value, 0); + dump_var(var, pfx1, 0, pfx2, 0, value, 0); bindings = cdr(bindings); } } @@ -359,7 +359,7 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} <SPECIAL>@ { yy_pop_state(); - yylval.lexeme = wcsdup(L"@"); + yylval.lexeme = chk_strdup(L"@"); return TEXT; } @@ -381,7 +381,7 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} wchar_t lexeme[2]; lexeme[0] = char_esc(yytext[1]); lexeme[1] = 0; - yylval.lexeme = wcsdup(lexeme); + yylval.lexeme = chk_strdup(lexeme); yy_pop_state(); return TEXT; } @@ -390,7 +390,7 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} wchar_t lexeme[2]; lexeme[0] = num_esc(yytext + 1); lexeme[1] = 0; - yylval.lexeme = wcsdup(lexeme); + yylval.lexeme = chk_strdup(lexeme); yy_pop_state(); return TEXT; } @@ -34,6 +34,7 @@ #include <errno.h> #include <wchar.h> #include <unistd.h> +#include <sys/wait.h> #include "lib.h" #include "gc.h" #include "unwind.h" @@ -31,8 +31,8 @@ #include <limits.h> #include <dirent.h> #include <setjmp.h> +#include <stdarg.h> #include <wchar.h> -#include <locale.h> #include "lib.h" #include "stream.h" #include "gc.h" @@ -144,7 +144,6 @@ int main(int argc, char **argv) obj_t *stack_bottom = nil; progname = argv[0] ? utf8_dup_from(argv[0]) : progname; init(progname, oom_realloc_handler, &stack_bottom); - setlocale(LC_CTYPE, "en_US.UTF-8"); return txr_main(argc, argv); } |