From aaacd3696e258dfeffc81177b27898535775819f Mon Sep 17 00:00:00 2001 From: arai Date: Sat, 6 Jul 2002 07:25:49 +0000 Subject: [PATCH] * src/lha_macro.h: deprecate the macro name `DELIM2' which is path separattor for the filename in lha header. use `LHA_PATHSEP' instead. * src/util.c (convdelim): ditto. * src/header.c (convert_filename): ditto. (write_header): ditto. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/lha/lha/trunk@281 6a8cc165-1e22-0410-a132-eb4e3f353aba --- src/header.c | 16 +++++++++------- src/lha_macro.h | 8 +++++--- src/util.c | 31 ++++++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/header.c b/src/header.c index c327601..a7f687a 100644 --- a/src/header.c +++ b/src/header.c @@ -213,23 +213,25 @@ convert_filename(name, len, size, if (from_code == CODE_SJIS && to_code == CODE_UTF8) { for (i = 0; i < len; i++) - if (name[i] == '\xff') name[i] = '/'; + if ((unsigned char)name[i] == LHA_PATHSEP) name[i] = '/'; sjis_to_utf8(tmp, name, sizeof(tmp)); strncpy(name, tmp, size); name[size-1] = 0; len = strlen(name); for (i = 0; i < len; i++) - if (name[i] == '/') name[i] = '\xff'; + if (name[i] == '/') name[i] = LHA_PATHSEP; + from_code = CODE_UTF8; } else if (from_code == CODE_UTF8 && to_code == CODE_SJIS) { for (i = 0; i < len; i++) - if (name[i] == '\xff') name[i] = '/'; + if ((unsigned char)name[i] == LHA_PATHSEP) name[i] = '/'; utf8_to_sjis(tmp, name, sizeof(tmp)); strncpy(name, tmp, size); name[size-1] = 0; len = strlen(name); for (i = 0; i < len; i++) - if (name[i] == '/') name[i] = '\xff'; + if (name[i] == '/') name[i] = LHA_PATHSEP; + from_code = CODE_SJIS; } #endif @@ -990,7 +992,7 @@ write_header(nafp, hdr) "\xff\\/", "\xff\xff\xff", NONE); if (hdr->header_level != HEADER_LEVEL2) { - if (p = (char *) strrchr(lzname, DELIM2)) + if (p = (char *) strrchr(lzname, LHA_PATHSEP)) name_length = strlen(++p); else name_length = strlen(lzname); @@ -1062,7 +1064,7 @@ write_header(nafp, hdr) put_byte(hdr->user[i]); } - if (p = (char *) strrchr(lzname, DELIM2)) { + if (p = (char *) strrchr(lzname, LHA_PATHSEP)) { int i; name_length = p - lzname + 1; @@ -1088,7 +1090,7 @@ write_header(nafp, hdr) data[I_HEADER_CHECKSUM] = calc_sum(data + I_METHOD, header_size); } else { /* header level 2 */ int i; - if (p = (char *) strrchr(lzname, DELIM2)) + if (p = (char *) strrchr(lzname, LHA_PATHSEP)) name_length = strlen(++p); else { p = lzname; diff --git a/src/lha_macro.h b/src/lha_macro.h index b68505b..f3b8597 100644 --- a/src/lha_macro.h +++ b/src/lha_macro.h @@ -222,9 +222,11 @@ typedef int boolean; #define CURRENT_UNIX_MINOR_VERSION 0x00 -#define DELIM ('/') -#define DELIM2 (0xff) -#define DELIMSTR "/" +#define LHA_PATHSEP 0xff /* path separator of the + filename in lha header. + it should compare with + `unsigned char' or `int', + that is not '\xff', but 0xff. */ #define OSK_RW_RW_RW 0000033 #define OSK_FILE_REGULAR 0000000 diff --git a/src/util.c b/src/util.c index 53aef00..1dfd30d 100644 --- a/src/util.c +++ b/src/util.c @@ -120,7 +120,7 @@ convdelim(path, delim) } else #endif - if (c == '\\' || c == DELIM || c == DELIM2) { + if (c == '\\' || c == '/' || c == LHA_PATHSEP) { *p = delim; path = p + 1; } @@ -389,6 +389,35 @@ xsnprintf(char *dest, size_t size, char *fmt, ...) return 0; } +#if !STRCHR_8BIT_CLEAN +/* 8 bit clean strchr()/strrchr() */ +char * +xstrchr(const char *s, int c) +{ + while (*s) { + if ((unsigned char)*s == (unsigned char)c) + return s; + s++; + } + + return 0; +} + +char * +xstrrchr(const char *s, int c) +{ + char *p = 0; + + while (*s) { + if ((unsigned char)*s == (unsigned char)c) + p = s; + s++; + } + + return p; +} +#endif + /* Local Variables: */ /* mode:c */ /* tab-width:4 */ -- 2.11.0