--- ed-1.4/io.c.orig 2009-06-12 20:13:06.000000000 +0900 +++ ed-1.4/io.c 2009-07-23 10:33:06.000000000 +0900 @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include "ed.h" @@ -236,8 +238,13 @@ int read_file( const char *filename, con { FILE *fp; long size; + mbstate_t mbs; + int is_bang = 0; - if( *filename == '!' ) fp = popen( filename + 1, "r" ); + memset (&mbs, 0, sizeof (mbs)); + is_bang = ((mbrlen (filename, MB_CUR_MAX, &mbs) == 1) && + (*filename == '!')) ? 1 : 0; + if( is_bang ) fp = popen( filename + 1, "r" ); else fp = fopen( strip_escapes( filename ), "r" ); if( !fp ) { @@ -246,7 +253,7 @@ int read_file( const char *filename, con return -1; } if( ( size = read_stream( fp, addr ) ) < 0 ) return -1; - if( ( (*filename == '!' ) ? pclose( fp ) : fclose( fp ) ) < 0 ) + if( ( ( is_bang ) ? pclose( fp ) : fclose( fp ) ) < 0 ) { show_strerror( filename, errno ); set_error_msg( "Cannot close input file" ); @@ -291,8 +298,13 @@ int write_file( const char * const filen { FILE *fp; long size; + mbstate_t mbs; + int is_bang = 0; - if( *filename == '!' ) fp = popen( filename + 1, "w" ); + memset (&mbs, 0, sizeof (mbs)); + is_bang = ((mbrlen (filename, MB_CUR_MAX, &mbs) == 1) && + (*filename == '!')) ? 1 : 0; + if( is_bang ) fp = popen( filename + 1, "w" ); else fp = fopen( strip_escapes( filename ), mode ); if( !fp ) { @@ -301,7 +313,7 @@ int write_file( const char * const filen return -1; } if( ( size = write_stream( fp, from, to ) ) < 0 ) return -1; - if( ( (*filename == '!' ) ? pclose( fp ) : fclose( fp ) ) < 0 ) + if( ( ( is_bang ) ? pclose( fp ) : fclose( fp ) ) < 0 ) { show_strerror( filename, errno ); set_error_msg( "Cannot close output file" ); --- ed-1.4/regex.c.orig 2009-06-12 20:15:28.000000000 +0900 +++ ed-1.4/regex.c 2009-07-23 10:33:06.000000000 +0900 @@ -24,6 +24,7 @@ #include #include #include +#include #include "ed.h" @@ -87,9 +88,18 @@ static char *extract_pattern( const char static int bufsz = 0; const char *nd = *ibufpp; int len; + mbstate_t mbs; while( *nd != delimiter && *nd != '\n' ) { + memset (&mbs, 0, sizeof (mbs)); + len = mbrlen (nd, MB_CUR_MAX, &mbs); + if (len > 1) + { + nd += len; + continue; + } + if( *nd == '[' ) { nd = parse_char_class( ++nd ); --- ed-1.4/signal.c.orig 2009-06-12 21:25:39.000000000 +0900 +++ ed-1.4/signal.c 2009-07-23 10:38:14.000000000 +0900 @@ -25,6 +25,7 @@ #include #include #include +#include #include "ed.h" @@ -248,12 +249,28 @@ const char *strip_escapes( const char *s static char *buf = 0; static int bufsz = 0; const int len = strlen( s ); + int char_len; + mbstate_t mbs; int i = 0; if( !resize_buffer( &buf, &bufsz, len + 1 ) ) return 0; /* assert: no trailing escape */ - while( ( buf[i++] = ( (*s == '\\' ) ? *++s : *s ) ) ) - s++; + while( *s ) + { + memset (&mbs, 0, sizeof (mbs)); + char_len = mbrlen (s, MB_CUR_MAX, &mbs); + if (char_len > 1) + { + while (char_len > 0) + { + buf[i++] = *s++; + char_len--; + } + continue; + } + buf[i++] = ( (*s == '\\' ) ? *++s : *s ); + s++; + } return buf; }