OSDN Git Service

Fix nesting of MULTIBYTE_FILENAME compiler switch
[lha/lha.git] / src / header.c
index fc7c1fa..17f4b6d 100644 (file)
@@ -61,8 +61,9 @@ calc_sum(p, len)
     int len;
 {
     int sum = 0;
+    unsigned char *pc = (unsigned char*)p;
 
-    while (len--) sum += *(unsigned char*)p++;
+    while (len--) sum += *pc++;
 
     return sum & 0xff;
 }
@@ -277,7 +278,24 @@ convert_filename(name, len, size,
         to_code_save = CODE_CAP;
         to_code = CODE_SJIS;
     }
+#endif
 
+    /* special case: if `name' has small lettter, not convert case. */
+    if (from_code == CODE_SJIS && case_to == TO_LOWER) {
+        for (i = 0; i < len; i++) {
+#ifdef MULTIBYTE_FILENAME
+            if (SJIS_FIRST_P(name[i]) && SJIS_SECOND_P(name[i+1]))
+                i++;
+            else
+#endif
+            if (islower(name[i])) {
+                case_to = NONE;
+                break;
+            }
+        }
+    }
+
+#ifdef MULTIBYTE_FILENAME
     if (from_code == CODE_SJIS && to_code == CODE_UTF8) {
         for (i = 0; i < len; i++) {
             if (SJIS_FIRST_P(name[i]) && SJIS_SECOND_P(name[i+1]))
@@ -310,21 +328,6 @@ convert_filename(name, len, size,
     }
 #endif
 
-    /* special case: if `name' has small lettter, not convert case. */
-    if (from_code == CODE_SJIS && case_to == TO_LOWER) {
-        for (i = 0; i < len; i++) {
-#ifdef MULTIBYTE_FILENAME
-            if (SJIS_FIRST_P(name[i]) && SJIS_SECOND_P(name[i+1]))
-                i++;
-            else
-#endif
-            if (islower(name[i])) {
-                case_to = NONE;
-                break;
-            }
-        }
-    }
-
     for (i = 0; i < len; i ++) {
 #ifdef MULTIBYTE_FILENAME
         if (from_code == CODE_EUC &&
@@ -611,12 +614,9 @@ get_extended_header(fp, hdr, header_size, hcrc)
             /* set last modified time */
             if (hdr->header_level >= 2)
                 skip_bytes(8);  /* time_t has been already set */
-            else {
+            else
                 hdr->unix_last_modified_stamp = wintime_to_unix_stamp();
-                if (file_time_stamp < hdr->unix_last_modified_stamp) {
-                    file_time_stamp = hdr->unix_last_modified_stamp;
-                }
-            }
+
             skip_bytes(8); /* last access time is ignored */
 
             break;
@@ -671,9 +671,6 @@ get_extended_header(fp, hdr, header_size, hcrc)
 #endif
             /* UNIX last modified time */
             hdr->unix_last_modified_stamp = (time_t) get_longword();
-            if (file_time_stamp < hdr->unix_last_modified_stamp) {
-                file_time_stamp = hdr->unix_last_modified_stamp;
-            }
             break;
         default:
             /* other headers */
@@ -815,9 +812,6 @@ get_header_level0(fp, hdr, data)
     hdr->packed_size = (unsigned long)get_longword();
     hdr->original_size = (unsigned long)get_longword();
     hdr->unix_last_modified_stamp = generic_to_unix_stamp(get_longword());
-    if (file_time_stamp < hdr->unix_last_modified_stamp) {
-        file_time_stamp = hdr->unix_last_modified_stamp;
-    }
     hdr->attribute = get_byte(); /* MS-DOS attribute */
     hdr->header_level = get_byte();
     name_length = get_byte();
@@ -857,9 +851,6 @@ get_header_level0(fp, hdr, data)
         if (extend_size >= 11) {
             hdr->minor_version = get_byte();
             hdr->unix_last_modified_stamp = (time_t) get_longword();
-            if (file_time_stamp < hdr->unix_last_modified_stamp) {
-                file_time_stamp = hdr->unix_last_modified_stamp;
-            }
             hdr->unix_mode = get_word();
             hdr->unix_uid = get_word();
             hdr->unix_gid = get_word();
@@ -937,9 +928,6 @@ get_header_level1(fp, hdr, data)
     hdr->packed_size = (unsigned long)get_longword(); /* skip size */
     hdr->original_size = (unsigned long)get_longword();
     hdr->unix_last_modified_stamp = generic_to_unix_stamp(get_longword());
-    if (file_time_stamp < hdr->unix_last_modified_stamp) {
-        file_time_stamp = hdr->unix_last_modified_stamp;
-    }
     hdr->attribute = get_byte(); /* 0x20 fixed */
     hdr->header_level = get_byte();
 
@@ -1027,9 +1015,6 @@ get_header_level2(fp, hdr, data)
     hdr->packed_size = (unsigned long)get_longword();
     hdr->original_size = (unsigned long)get_longword();
     hdr->unix_last_modified_stamp = get_longword();
-    if (file_time_stamp < hdr->unix_last_modified_stamp) {
-        file_time_stamp = hdr->unix_last_modified_stamp;
-    }
     hdr->attribute = get_byte(); /* reserved */
     hdr->header_level = get_byte();
 
@@ -1110,9 +1095,6 @@ get_header_level3(fp, hdr, data)
     hdr->packed_size = (unsigned long)get_longword();
     hdr->original_size = (unsigned long)get_longword();
     hdr->unix_last_modified_stamp = get_longword();
-    if (file_time_stamp < hdr->unix_last_modified_stamp) {
-        file_time_stamp = hdr->unix_last_modified_stamp;
-    }
     hdr->attribute = get_byte(); /* reserved */
     hdr->header_level = get_byte();
 
@@ -1266,9 +1248,11 @@ seek_lha_header(fp)
     n = fread(buffer, 1, sizeof(buffer), fp);
 
     for (p = buffer; p < buffer + n; p++) {
-        if (! (p[I_METHOD]=='-' && p[I_METHOD+1]=='l' && p[I_METHOD+4]=='-'))
+        if (! (p[I_METHOD]=='-' &&
+               (p[I_METHOD+1]=='l' || p[I_METHOD+1]=='p') &&
+               p[I_METHOD+4]=='-'))
             continue;
-        /* found "-l??-" keyword (as METHOD type string) */
+        /* found "-[lp]??-" keyword (as METHOD type string) */
 
         /* level 0 or 1 header */
         if ((p[I_HEADER_LEVEL] == 0 || p[I_HEADER_LEVEL] == 1)
@@ -1419,7 +1403,6 @@ init_header(name, v_stat, hdr)
     hdr->crc = 0x0000;
     hdr->extend_type = EXTEND_UNIX;
     hdr->unix_last_modified_stamp = v_stat->st_mtime;
-    if (file_time_stamp < v_stat->st_mtime) { file_time_stamp = v_stat->st_mtime; }
     /* since 00:00:00 JAN.1.1970 */
 #ifdef NOT_COMPATIBLE_MODE
     /* Please need your modification in this space. */