From 40e202532723bac8317e296bb3b44aba89d3da05 Mon Sep 17 00:00:00 2001 From: axel Date: Mon, 4 Sep 2006 09:00:06 +1000 Subject: [PATCH] Minor polish darcs-hash:20060903230006-ac50b-c55a9272bb1cdb10312b8580c4c2a85654329e30.gz --- common.c | 187 ++++++++++++++++++++++++++++++--------------------- configure.ac | 6 +- halloc.c | 2 +- parse_util.c | 2 +- 4 files changed, 117 insertions(+), 80 deletions(-) diff --git a/common.c b/common.c index e5138f28b..c80aa1ca1 100644 --- a/common.c +++ b/common.c @@ -813,87 +813,22 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special ) { switch( in[++in_pos] ) { + + /* + A null character after a backslash is an + error, return null + */ case L'\0': { free(in); return 0; } - case L'n': - { - in[out_pos]=L'\n'; - break; - } + /* + Numeric escape sequences. No prefix means + octal escape, otherwise hexadecimal. + */ - case L'r': - { - in[out_pos]=L'\r'; - break; - } - - case L't': - { - in[out_pos]=L'\t'; - break; - } - - case L'b': - { - in[out_pos]=L'\b'; - break; - } - - case L'a': - { - in[out_pos]=L'\a'; - break; - } - - case L'f': - { - in[out_pos]=L'\f'; - break; - } - - case L'v': - { - in[out_pos]=L'\v'; - break; - } - - case L'e': - { - in[out_pos]=L'\x1b'; - break; - } - - case L'c': - { - in_pos++; - if( in[in_pos] >= L'a' && - in[in_pos] <= (L'a'+32) ) - { - in[out_pos]=in[in_pos]-L'a'+1; - } - else if( in[in_pos] >= L'A' && - in[in_pos] <= (L'A'+32) ) - { - in[out_pos]=in[in_pos]-L'A'+1; - } - else - { - free(in); - return 0; - } - break; - - } - - - case L'u': - case L'U': - case L'x': - case L'X': case L'0': case L'1': case L'2': @@ -902,6 +837,10 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special ) case L'5': case L'6': case L'7': + case L'u': + case L'U': + case L'x': + case L'X': { int i; long long res=0; @@ -974,6 +913,103 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special ) break; } + /* + \a means bell (alert) + */ + case L'a': + { + in[out_pos]=L'\a'; + break; + } + + /* + \b means backspace + */ + case L'b': + { + in[out_pos]=L'\b'; + break; + } + + /* + \cX means control sequence X + */ + case L'c': + { + in_pos++; + if( in[in_pos] >= L'a' && + in[in_pos] <= (L'a'+32) ) + { + in[out_pos]=in[in_pos]-L'a'+1; + } + else if( in[in_pos] >= L'A' && + in[in_pos] <= (L'A'+32) ) + { + in[out_pos]=in[in_pos]-L'A'+1; + } + else + { + free(in); + return 0; + } + break; + + } + + /* + \e means escape + */ + case L'e': + { + in[out_pos]=L'\x1b'; + break; + } + + /* + \f means form feed + */ + case L'f': + { + in[out_pos]=L'\f'; + break; + } + + /* + \n means newline + */ + case L'n': + { + in[out_pos]=L'\n'; + break; + } + + /* + \r means carriage return + */ + case L'r': + { + in[out_pos]=L'\r'; + break; + } + + /* + \t means tab + */ + case L't': + { + in[out_pos]=L'\t'; + break; + } + + /* + \v means vetrical tab + */ + case L'v': + { + in[out_pos]=L'\v'; + break; + } + default: { in[out_pos++] = INTERNAL_SEPARATOR; @@ -984,7 +1020,8 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special ) } else { - switch( in[in_pos]){ + switch( in[in_pos]) + { case L'~': { if( unescape_special && (in_pos == 0) ) diff --git a/configure.ac b/configure.ac index 1e4417a40..fe350c04c 100644 --- a/configure.ac +++ b/configure.ac @@ -586,8 +586,8 @@ else AC_MSG_RESULT(no) fi -# Check if getopt_long actually works -AC_MSG_CHECKING([if getopt_long works]) +# Check if getopt_long exists and works +AC_MSG_CHECKING([if getopt_long exists and works]) AC_TRY_LINK( [ #if HAVE_GETOPT_H @@ -616,7 +616,7 @@ if test "$have_working_getopt_long" = yes; then AC_DEFINE( [HAVE_WORKING_GETOPT_LONG], [1], - [Define to 1 if getopt_long actually works.] + [Define to 1 if getopt_long exists and works.] ) else AC_MSG_RESULT(no) diff --git a/halloc.c b/halloc.c index 78bd3919b..c87371261 100644 --- a/halloc.c +++ b/halloc.c @@ -74,7 +74,7 @@ typedef struct halloc size_t scratch_free; #if __STDC_VERSION__ < 199901L /** - The actual data. MAde to be of type long long to make sure memory alignment is in order. + The actual data. Made to be of type long long to make sure memory alignment is in order. */ long long data[1]; // Waste one byte on non-C99 compilers... :-( #else diff --git a/parse_util.c b/parse_util.c index fff0570e6..d4b821464 100644 --- a/parse_util.c +++ b/parse_util.c @@ -778,6 +778,7 @@ static int path_util_load_internal( const wchar_t *cmd, { wchar_t *esc = escape( (wchar_t *)path->buff, 1 ); wchar_t *src_cmd = wcsdupcat( L". ", esc ); + free( esc ); if( !tm ) { @@ -792,7 +793,6 @@ static int path_util_load_internal( const wchar_t *cmd, intern( cmd ), tm ); - free( esc ); if( on_load ) on_load(cmd );