OSDN Git Service

* src/lha_macro.h: deprecate the macro name `DELIM2' which is path
authorarai <arai@6a8cc165-1e22-0410-a132-eb4e3f353aba>
Sat, 6 Jul 2002 07:25:49 +0000 (07:25 +0000)
committerarai <arai@6a8cc165-1e22-0410-a132-eb4e3f353aba>
Sat, 6 Jul 2002 07:25:49 +0000 (07:25 +0000)
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
src/lha_macro.h
src/util.c

index c327601..a7f687a 100644 (file)
@@ -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;
index b68505b..f3b8597 100644 (file)
@@ -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
index 53aef00..1dfd30d 100644 (file)
@@ -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 */