OSDN Git Service

* src/lharc.c (print_tiny_usage, parse_suboption): added a long
[lha/lha.git] / src / lharc.c
index 9011411..b809dbb 100644 (file)
@@ -93,7 +93,7 @@ init_variable()     /* Added N.Watazaki */
     exclude_files                           = NULL;
     verify_mode                             = FALSE;
 
-    noconvertcase                           = FALSE;
+    convertcase                             = FALSE;
 
     extract_directory = NULL;
     temporary_fd = -1;
@@ -105,6 +105,7 @@ init_variable()     /* Added N.Watazaki */
 #endif
 
     extract_broken_archive = FALSE;
+    decode_macbinary_contents = FALSE;
 }
 
 /* ------------------------------------------------------------------------ */
@@ -118,28 +119,48 @@ init_variable()     /* Added N.Watazaki */
 static void
 print_tiny_usage()
 {
-    fprintf(stderr, "\
+#if HAVE_LIBAPPLEFILE
+    fprintf(stdout, "\
 usage: lha [-]<commands>[<options>] [-<options> ...] archive_file [file...]\n\
   commands:  [axelvudmcpt]\n\
-  options:   [q[012]vnfto[567]dizg012e[w=<dir>|x=<pattern>]]\n");
+  options:   [q[012]vnfto[567]dizg012eb[w=<dir>|x=<pattern>]]\n\
+  long options: --system-kanji-code={euc,sjis,utf8,cap}\n\
+                --archive-kanji-code={euc,sjis,utf8,cap}\n\
+                --extract-broken-archive\n\
+                --convert-filename-case\n\
+                --help\n\
+                --version\n");
+#else
+    fprintf(stdout, "\
+usage: lha [-]<commands>[<options>] [-<options> ...] archive_file [file...]\n\
+  commands:  [axelvudmcpt]\n\
+  options:   [q[012]vnfto[567]dizg012e[w=<dir>|x=<pattern>]]\n\
+  long options: --system-kanji-code={euc,sjis,utf8,cap}\n\
+                --archive-kanji-code={euc,sjis,utf8,cap}\n\
+                --extract-broken-archive\n\
+                --convert-filename-case\n\
+                --traditional\n\
+                --help\n\
+                --version\n");
+#endif
 }
 
 static void
 print_usage()
 {
-    fprintf(stderr, "\
+    fprintf(stdout, "\
 LHarc    for UNIX  V 1.02  Copyright(C) 1989  Y.Tagawa\n\
 LHx      for MSDOS V C2.01 Copyright(C) 1990  H.Yoshizaki\n\
 LHx(arc) for OSK   V 2.01  Modified     1990  Momozou\n\
 LHa      for UNIX  V 1.00  Copyright(C) 1992  Masaru Oki\n\
 LHa      for UNIX  V 1.14  Modified     1995  Nobutaka Watazaki\n\
 LHa      for UNIX  V 1.14i Modified     2000  Tsugio Okamoto\n\
-                   Autoconfiscated 2001-2004  Koji Arai\n\
+                   Autoconfiscated 2001-2007  Koji Arai\n\
 ");
 
     print_tiny_usage();
 
-    fprintf(stderr, "\
+    fprintf(stdout, "\
 commands:                           options:\n\
  a   Add(or replace) to archive      q{num} quiet (num:quiet mode)\n\
  x,e EXtract from archive            v  verbose\n\
@@ -147,34 +168,38 @@ commands:                           options:\n\
  u   Update newer files to archive   f  force (over write at extract)\n\
  d   Delete from archive             t  FILES are TEXT file\n");
 #ifdef SUPPORT_LH7
-    fprintf(stderr, "\
+    fprintf(stdout, "\
  m   Move to archive (means 'ad')    o[567] compression method (a/u/c)\n\
 ");
 #endif
 #ifndef SUPPORT_LH7
-    fprintf(stderr, "\
+    fprintf(stdout, "\
  m   Move to archive (means 'ad')    o  use LHarc compatible method (a/u/c)\n\
 ");
 #endif
-    fprintf(stderr, "\
+    fprintf(stdout, "\
  c   re-Construct new archive        d  delete FILES after (a/u/c)\n\
  p   Print to STDOUT from archive    i  ignore directory path (x/e)\n\
  t   Test file CRC in archive        z  files not compress (a/u/c)\n\
                                      g  Generic format (for compatibility)\n\
-                                        or not convert case when extracting\n\
                                      0/1/2 header level (a/u/c)\n\
 ");
 #ifdef EUC
-    fprintf(stderr, "\
+    fprintf(stdout, "\
                                      e  TEXT code convert from/to EUC\n\
 ");
 #endif
-    fprintf(stderr, "\
+#if HAVE_LIBAPPLEFILE
+    fprintf(stdout, "\
+                                     b  decode MacBinary (x/e)\n\
+");
+#endif
+    fprintf(stdout, "\
                                      w=<dir> specify extract directory (x/e)\n\
                                      x=<pattern>  eXclude files (a/u/c)\n\
 ");
 #if IGNORE_DOT_FILES            /* experimental feature */
-    fprintf(stderr, "\
+    fprintf(stdout, "\
                                      X ignore dot files (a/u/c)\n\
 ");
 #endif
@@ -188,13 +213,12 @@ commands:                           options:\n\
 static int
 parse_suboption(int argc, char **argv)
 {
-    char *short_options = "q[012]vnfto[567]dizg012ew:x:";
-    /* "[...]" means optional 1 byte argument (original extention) */
     enum {
         HELP_OPTION = 256,
         VERSION_OPTION,
         SYSTEM_KANJI_CODE_OPTION,
         ARCHIVE_KANJI_CODE_OPTION,
+        TRADITIONAL_BEHAVIOR,
     };
 
     struct option long_options[] = {
@@ -205,10 +229,22 @@ parse_suboption(int argc, char **argv)
         {"system-kanji-code", required_argument, 0, SYSTEM_KANJI_CODE_OPTION},
         {"archive-kanji-code", required_argument, 0, ARCHIVE_KANJI_CODE_OPTION},
         {"extract-broken-archive", no_argument, &extract_broken_archive, 1},
+        {"convert-filename-case", no_argument, &convertcase, TRUE},
+        {"traditional", no_argument, 0, TRADITIONAL_BEHAVIOR},
         {0, 0, 0, 0}
     };
     int i;
 
+    char short_options[256] = "q[012]vnfto[567]dizg012ew:x:";
+    /* "[...]" means optional 1 byte argument (original extention) */
+
+#if IGNORE_DOT_FILES
+    strncat(short_options, "X", sizeof(short_options)-strlen(short_options)-1);
+#endif
+#if HAVE_LIBAPPLEFILE
+    strncat(short_options, "b", sizeof(short_options)-strlen(short_options)-1);
+#endif
+
     /* parse option */
     while (1) {
         int option_index = 0;
@@ -269,12 +305,16 @@ parse_suboption(int argc, char **argv)
             euc_mode = TRUE;
             break;
 #endif
+#if HAVE_LIBAPPLEFILE
+        case 'b':
+            decode_macbinary_contents = TRUE;
+            break;
+#endif
         case 'n':
             noexec = TRUE;
             break;
         case 'g':
             generic_format = TRUE;
-            noconvertcase = TRUE;
             header_level = 0;
             break;
         case 'd':
@@ -378,6 +418,8 @@ parse_suboption(int argc, char **argv)
                 error("unknown kanji code \"%s\"", optarg);
                 return -1;
             }
+            break;
+
         case ARCHIVE_KANJI_CODE_OPTION:
             if (!optarg) {
                 error("kanji code not specified for --%s",
@@ -402,20 +444,26 @@ parse_suboption(int argc, char **argv)
             }
             break;
 
+        case TRADITIONAL_BEHAVIOR:
+            convertcase = TRUE;
+            break;
+
         default:
             error("unknown option `-%c'.", c);
             return -1;
         }
     }
 
+    argc -= optind;
+    argv += optind;
+
     if (!archive_name) {
-        archive_name = argv[optind];
-        argv++;
+        archive_name = *argv++;
         argc--;
     }
 
-    cmd_filec = argc - optind;
-    cmd_filev = argv + optind;
+    cmd_filec = argc;
+    cmd_filev = argv;
 
     return 0;
 }
@@ -1281,7 +1329,7 @@ open_old_archive()
 
     if (!strcmp(archive_name, "-")) {
         if (cmd == CMD_EXTRACT || cmd == CMD_LIST) {
-#if __MINGW32__
+#if defined(__MINGW32__) || defined(__DJGPP__)
             setmode(fileno(stdin), O_BINARY);
 #endif
             return stdin;