OSDN Git Service

make it possible to add archive suffixes.
authorarai <arai@6a8cc165-1e22-0410-a132-eb4e3f353aba>
Tue, 5 Feb 2008 21:30:09 +0000 (21:30 +0000)
committerarai <arai@6a8cc165-1e22-0410-a132-eb4e3f353aba>
Tue, 5 Feb 2008 21:30:09 +0000 (21:30 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/lha/lha/trunk@879 6a8cc165-1e22-0410-a132-eb4e3f353aba

config.h.in
configure.ac
src/lharc.c

index bd501f6..f66a06c 100644 (file)
@@ -1,5 +1,9 @@
 /* config.h.in.  Generated from configure.ac by autoheader.  */
 
+/* Define to comma separated suffixes list if you wish to regard it as
+   implicit archive suffixes. */
+#undef ADDITIONAL_SUFFIXES
+
 /* Define to 1 if you want to leave an old archive */
 #undef BACKUP_OLD_ARCHIVE
 
 /* Define to 1 if you want to use the user/group name extened header */
 #undef INCLUDE_OWNER_NAME_IN_HEADER
 
+/* specified options for the configure script. */
+#undef LHA_CONFIGURE_OPTIONS
+
 /* Define to CODE_EUC or CODE_SJIS if you want to use multibyte filename */
 #undef MULTIBYTE_FILENAME
 
index 5828693..b4f4d44 100644 (file)
@@ -1,5 +1,7 @@
 # Process this file with autoconf to produce a configure script.
-AC_INIT([LHa for UNIX], 1.14i-ac20070909, arai@users.sourceforge.jp, lha)
+AC_INIT([LHa for UNIX], 1.14i-ac20080117, arai@users.sourceforge.jp, lha)
+AC_DEFINE_UNQUOTED(LHA_CONFIGURE_OPTIONS, "$ac_configure_args",
+           [specified options for the configure script.])
 AC_CANONICAL_HOST
 AC_CANONICAL_TARGET
 AM_INIT_AUTOMAKE
@@ -165,11 +167,11 @@ SUPPORT_LZHUFF_METHOD=-DSUPPORT_LH7
 # whether use the -lh567- method
 AC_MSG_CHECKING(default archive method)
 AC_ARG_WITH(default-method,
-  AC_HELP_STRING([--with-default-method=[[567]]],
-                [create the -lh[[567]]- archive default [[default=5]]]),
+  [AC_HELP_STRING([[[[--with-default-method=[567]]]]],
+                [create the -lh[567]- archive default [default=5]])],
   [case $withval in
-   [567]) ;;
-   *) AC_MSG_ERROR(you should have specified 5, 6 or 7);;
+   [[567]]) ;;
+   *) AC_MSG_ERROR([you should have specified 5, 6 or 7]);;
    esac],
   with_default_method=5)
 AC_MSG_RESULT(-lh$with_default_method-)
@@ -276,7 +278,19 @@ if test "x$enable_backup_archive" = xyes; then
            [Define to 1 if you want to leave an old archive])
 fi
 
-case $host_os in 
+# additional suffixes of archive filename.
+AC_MSG_CHECKING(additional suffixes of archive filename)
+AC_ARG_WITH(additional-suffixes,
+  [AC_HELP_STRING([[[--with-additional-suffixes=foo,bar]]],
+                [additional suffixes of archive filename, default is empty string])],
+  ,
+  with_additional_suffixes="")
+
+AC_MSG_RESULT($with_additional_suffixes)
+AC_DEFINE_UNQUOTED(ADDITIONAL_SUFFIXES, "$with_additional_suffixes",
+           [Define to comma separated suffixes list if you wish to regard it as implicit archive suffixes.])
+
+case $host_os in
 *msdosdjgpp*)
 CFLAGS="$CFLAGS -DNOT_COMPATIBLE_MODE"
 ;;
index 0e577a7..1124026 100644 (file)
@@ -154,7 +154,7 @@ 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-2007  Koji Arai\n\
+                   Autoconfiscated 2001-2008  Koji Arai\n\
 ");
 
     print_tiny_usage();
@@ -672,6 +672,7 @@ print_version()
        defined in config.h by configure script */
     fprintf(stderr, "%s version %s (%s)\n",
             PACKAGE_NAME, PACKAGE_VERSION, PLATFORM);
+    fprintf(stderr, "  configure options: %s\n", LHA_CONFIGURE_OPTIONS);
 }
 
 void
@@ -1319,8 +1320,8 @@ open_old_archive_1(name, v_fp)
 FILE           *
 open_old_archive()
 {
-    FILE           *fp;
-    char           *p;
+    FILE           *fp = NULL;
+    char           *p = NULL, *ext, *ext2;
     static char expanded_archive_name[FILENAME_LENGTH];
 
     if (!strcmp(archive_name, "-")) {
@@ -1333,46 +1334,60 @@ open_old_archive()
         else
             return NULL;
     }
-    p = strrchr(archive_name, '.');
-    if (p) {
-        if (strcasecmp(".LZH", p) == 0
-            || strcasecmp(".LZS", p) == 0
-            || strcasecmp(".COM", p) == 0  /* DOS SFX */
-            || strcasecmp(".EXE", p) == 0
-            || strcasecmp(".X", p) == 0    /* HUMAN SFX */
-            || strcasecmp(".BAK", p) == 0) {   /* for BackUp */
-            open_old_archive_1(archive_name, &fp);
-            return fp;
+
+    ext2 = strrchr(archive_name, '.');
+    if (ext2) {
+        ext2++;
+
+        /* .com: DOS SFX
+           .exe: DOS SFX
+           .x:   HUMAN SFX
+           .bak: Backup file
+           .lha: Amiga(?) */
+        p = xstrdup("lzh," ADDITIONAL_SUFFIXES);
+        for (ext = strtok(p, ",");
+             ext;
+             ext = strtok(NULL, ",")) {
+
+            if (*ext == 0) continue;
+
+            if (strcasecmp(ext, ext2)) {
+                /* Try to open file just specified filename
+                   with usual suffixes.
+                   Return NULL if the file is not exist. */
+
+                open_old_archive_1(archive_name, &fp);
+                goto ret;       /* found or not */
+            }
         }
+        free(p);
+        p = NULL;
     }
 
+    /* Try to open file just specified filename */
     if (open_old_archive_1(archive_name, &fp))
-        return fp;
-    xsnprintf(expanded_archive_name, sizeof(expanded_archive_name),
-              "%s.lzh", archive_name);
-    if (open_old_archive_1(expanded_archive_name, &fp)) {
-        archive_name = expanded_archive_name;
-        return fp;
-    }
-    /*
-     * if ( (errno&0xffff)!=E_PNNF ) { archive_name =
-     * expanded_archive_name; return NULL; }
-     */
-    xsnprintf(expanded_archive_name, sizeof(expanded_archive_name),
-              "%s.lzs", archive_name);
-    if (open_old_archive_1(expanded_archive_name, &fp)) {
-        archive_name = expanded_archive_name;
-        return fp;
+        goto ret;               /* found */
+
+    /* Try to open file with implicit suffixes */
+    p = xstrdup("lzh," ADDITIONAL_SUFFIXES);
+    for (ext = strtok(p, ",");
+         ext;
+         ext = strtok(NULL, ",")) {
+
+        if (*ext == 0) continue;
+
+        xsnprintf(expanded_archive_name, sizeof(expanded_archive_name),
+                  "%s.%s", archive_name, ext);
+
+        if (open_old_archive_1(expanded_archive_name, &fp)) {
+            archive_name = expanded_archive_name;
+            goto ret;           /* found */
+        }
     }
-    /*
-     * if ( (errno&0xffff)!=E_PNNF ) { archive_name =
-     * expanded_archive_name; return NULL; }
-     */
-    /*
-     * sprintf( expanded_archive_name , "%s.lzh",archive_name);
-     * archive_name = expanded_archive_name;
-     */
-    return NULL;
+
+ret:
+    if (p) free(p);
+    return fp;
 }
 
 /* ------------------------------------------------------------------------ */