1 /* ------------------------------------------------------------------------ */
3 /* lharc.c -- append to archive */
5 /* Copyright (C) MCMLXXXIX Yooichi.Tagawa */
6 /* Modified Nobutaka Watazaki */
7 /* Thanks to H.Yoshizaki. (MS-DOS LHarc) */
9 /* Ver. 0.00 Original 1988.05.23 Y.Tagawa */
10 /* Ver. 0.01 Alpha Version (for 4.2BSD) 1989.05.28 Y.Tagawa */
11 /* Ver. 0.02 Alpha Version Rel.2 1989.05.29 Y.Tagawa */
12 /* Ver. 0.03 Release #3 Beta Version 1989.07.02 Y.Tagawa */
13 /* Ver. 0.03a Debug 1989.07.03 Y.Tagawa */
14 /* Ver. 0.03b Modified 1989.07.13 Y.Tagawa */
15 /* Ver. 0.03c Debug (Thanks to void@rena.dit.junet) */
16 /* 1989.08.09 Y.Tagawa */
17 /* Ver. 0.03d Modified (quiet and verbose) 1989.09.14 Y.Tagawa */
18 /* V1.00 Fixed 1989.09.22 Y.Tagawa */
19 /* V1.01 Bug Fixed 1989.12.25 Y.Tagawa */
21 /* DOS-Version Original LHx V C2.01 (C) H.Yohizaki */
23 /* V2.00 UNIX Lharc + DOS LHx -> OSK LHx 1990.11.01 Momozou */
24 /* V2.01 Minor Modified 1990.11.24 Momozou */
26 /* Ver. 0.02 LHx for UNIX 1991.11.18 M.Oki */
27 /* Ver. 0.03 LHa for UNIX 1991.12.17 M.Oki */
28 /* Ver. 0.04 LHa for UNIX beta version 1992.01.20 M.Oki */
29 /* Ver. 1.00 LHa for UNIX Fixed 1992.03.19 M.Oki */
31 /* Ver. 1.10 for Symbolic Link 1993.06.25 N.Watazaki */
32 /* Ver. 1.11 for Symbolic Link Bug Fixed 1993.08.18 N.Watazaki */
33 /* Ver. 1.12 for File Date Check 1993.10.28 N.Watazaki */
34 /* Ver. 1.13 Bug Fixed (Idicator calcurate) 1994.02.21 N.Watazaki */
35 /* Ver. 1.13a Bug Fixed (Sym. Link delete) 1994.03.11 N.Watazaki */
36 /* Ver. 1.13b Bug Fixed (Sym. Link delete) 1994.07.29 N.Watazaki */
37 /* Ver. 1.14 Source All chagned 1995.01.14 N.Watazaki */
38 /* Ver. 1.14b,c Bug Fixed 1996.03.07 t.okamoto */
39 /* Ver. 1.14d Version up 1997.01.12 t.okamoto */
40 /* Ver. 1.14g Bug Fixed 2000.05.06 t.okamoto */
41 /* Ver. 1.14i Modified 2000.10.06 t.okamoto */
42 /* ------------------------------------------------------------------------ */
47 static int cmd = CMD_UNKNOWN;
48 static int error_occurred;
50 /* static functions */
51 static void sort_files();
52 static void print_version();
54 extern int optional_archive_kanji_code;
55 extern int optional_system_kanji_code;
57 /* ------------------------------------------------------------------------ */
59 init_variable() /* Added N.Watazaki */
65 noexec = FALSE; /* debugging option */
68 compress_method = DEFAULT_LZHUFF_METHOD; /* defined in config.h */
70 header_level = 2; /* level 2 */
77 /* view command flags */
78 verbose_listing = FALSE;
80 /* extract command flags */
81 output_to_stdout = FALSE;
83 /* append command flags */
85 update_if_newer = FALSE;
86 delete_after_append = FALSE;
87 generic_format = FALSE;
89 recover_archive_when_interrupt = FALSE;
90 remove_extracting_file_when_interrupt = FALSE;
91 get_filename_from_stdin = FALSE;
92 ignore_directory = FALSE;
98 extract_directory = NULL;
101 #if BACKUP_OLD_ARCHIVE
102 backup_old_archive = TRUE;
104 backup_old_archive = FALSE;
107 extract_broken_archive = FALSE;
108 decode_macbinary_contents = FALSE;
111 /* ------------------------------------------------------------------------ */
112 /* NOTES : Text File Format */
113 /* GENERATOR NewLine */
114 /* [generic] 0D 0A */
116 /* [OS9][MacOS] 0D */
118 /* ------------------------------------------------------------------------ */
122 #if HAVE_LIBAPPLEFILE
124 usage: lha [-]<commands>[<options>] [-<options> ...] archive_file [file...]\n\
125 commands: [axelvudmcpt]\n\
126 options: [q[012]vnfto[567]dizg012eb[w=<dir>|x=<pattern>]]\n\
127 long options: --system-kanji-code={euc,sjis,utf8,cap}\n\
128 --archive-kanji-code={euc,sjis,utf8,cap}\n\
129 --extract-broken-archive\n\
130 --convert-filename-case\n\
135 usage: lha [-]<commands>[<options>] [-<options> ...] archive_file [file...]\n\
136 commands: [axelvudmcpt]\n\
137 options: [q[012]vnfto[567]dizg012e[w=<dir>|x=<pattern>]]\n\
138 long options: --system-kanji-code={euc,sjis,utf8,cap}\n\
139 --archive-kanji-code={euc,sjis,utf8,cap}\n\
140 --extract-broken-archive\n\
141 --convert-filename-case\n\
151 LHarc for UNIX V 1.02 Copyright(C) 1989 Y.Tagawa\n\
152 LHx for MSDOS V C2.01 Copyright(C) 1990 H.Yoshizaki\n\
153 LHx(arc) for OSK V 2.01 Modified 1990 Momozou\n\
154 LHa for UNIX V 1.00 Copyright(C) 1992 Masaru Oki\n\
155 LHa for UNIX V 1.14 Modified 1995 Nobutaka Watazaki\n\
156 LHa for UNIX V 1.14i Modified 2000 Tsugio Okamoto\n\
157 Autoconfiscated 2001-2007 Koji Arai\n\
163 commands: options:\n\
164 a Add(or replace) to archive q{num} quiet (num:quiet mode)\n\
165 x,e EXtract from archive v verbose\n\
166 l,v List / Verbose List n not execute\n\
167 u Update newer files to archive f force (over write at extract)\n\
168 d Delete from archive t FILES are TEXT file\n");
171 m Move to archive (means 'ad') o[567] compression method (a/u/c)\n\
176 m Move to archive (means 'ad') o use LHarc compatible method (a/u/c)\n\
180 c re-Construct new archive d delete FILES after (a/u/c)\n\
181 p Print to STDOUT from archive i ignore directory path (x/e)\n\
182 t Test file CRC in archive z files not compress (a/u/c)\n\
183 g Generic format (for compatibility)\n\
184 0/1/2 header level (a/u/c)\n\
188 e TEXT code convert from/to EUC\n\
191 #if HAVE_LIBAPPLEFILE
193 b decode MacBinary (x/e)\n\
197 w=<dir> specify extract directory (x/e)\n\
198 x=<pattern> eXclude files (a/u/c)\n\
200 #if IGNORE_DOT_FILES /* experimental feature */
202 X ignore dot files (a/u/c)\n\
207 #include "getopt_long.h"
213 parse_suboption(int argc, char **argv)
218 SYSTEM_KANJI_CODE_OPTION,
219 ARCHIVE_KANJI_CODE_OPTION,
222 struct option long_options[] = {
223 /* These options set a flag. */
224 {"help", no_argument, 0, HELP_OPTION},
225 {"version", no_argument, 0, VERSION_OPTION},
227 {"system-kanji-code", required_argument, 0, SYSTEM_KANJI_CODE_OPTION},
228 {"archive-kanji-code", required_argument, 0, ARCHIVE_KANJI_CODE_OPTION},
229 {"extract-broken-archive", no_argument, &extract_broken_archive, 1},
230 {"convert-filename-case", no_argument, &convertcase, TRUE},
235 char short_options[256] = "q[012]vnfto[567]dizg012ew:x:";
236 /* "[...]" means optional 1 byte argument (original extention) */
239 strncat(short_options, "X", sizeof(short_options)-strlen(short_options)-1);
241 #if HAVE_LIBAPPLEFILE
242 strncat(short_options, "b", sizeof(short_options)-strlen(short_options)-1);
247 int option_index = 0;
248 int c = getopt_long(argc, argv,
249 short_options, long_options,
252 if (c == -1) break; /* end of options */
256 /* Already set a flag variable by the definition of the
271 /* In quiet mode, no confirm to overwrite */
278 case '0': /* no quiet */
279 case '1': /* no use the incremental indicator */
280 quiet_mode = *optarg - '0';
282 case '2': /* no output */
305 #if HAVE_LIBAPPLEFILE
307 decode_macbinary_contents = TRUE;
314 generic_format = TRUE;
318 delete_after_append = TRUE;
322 compress_method = LZHUFF1_METHOD_NUM;
328 compress_method = LZHUFF5_METHOD_NUM;
332 compress_method = LZHUFF6_METHOD_NUM;
335 compress_method = LZHUFF7_METHOD_NUM;
339 error("invalid compression method 'o%c'", *optarg);
344 compress_method = LZHUFF0_METHOD_NUM; /* Changed N.Watazaki */
347 ignore_directory = TRUE;
351 error("exclude files does not specified for `-x'");
355 for (i = 0; exclude_files && exclude_files[i]; i++)
357 exclude_files = (char**)xrealloc(exclude_files,
358 sizeof(char*) * (i+2));
362 exclude_files[i] = optarg;
363 exclude_files[i+1] = 0;
366 #if IGNORE_DOT_FILES /* experimental feature */
368 for (i = 0; exclude_files && exclude_files[i]; i++)
370 exclude_files = (char**)xrealloc(exclude_files,
371 sizeof(char*) * (i+2));
373 exclude_files[i] = xstrdup(".*");
374 exclude_files[i+1] = 0;
379 error("working directory does not specified for `-w'");
385 extract_directory = optarg;
396 case SYSTEM_KANJI_CODE_OPTION:
398 error("kanji code not specified for --%s",
399 long_options[option_index].name);
402 if (strcmp(optarg, "euc") == 0) {
403 optional_system_kanji_code = CODE_EUC;
405 else if (strcmp(optarg, "sjis") == 0) {
406 optional_system_kanji_code = CODE_SJIS;
408 else if (strcmp(optarg, "utf8") == 0) {
409 optional_system_kanji_code = CODE_UTF8;
411 else if (strcmp(optarg, "cap") == 0) {
412 optional_system_kanji_code = CODE_CAP;
415 error("unknown kanji code \"%s\"", optarg);
420 case ARCHIVE_KANJI_CODE_OPTION:
422 error("kanji code not specified for --%s",
423 long_options[option_index].name);
426 if (strcmp(optarg, "euc") == 0) {
427 optional_archive_kanji_code = CODE_EUC;
429 else if (strcmp(optarg, "sjis") == 0) {
430 optional_archive_kanji_code = CODE_SJIS;
432 else if (strcmp(optarg, "utf8") == 0) {
433 optional_archive_kanji_code = CODE_UTF8;
435 else if (strcmp(optarg, "cap") == 0) {
436 optional_archive_kanji_code = CODE_CAP;
439 error("unknown kanji code \"%s\"", optarg);
445 error("unknown option `-%c'.", c);
454 archive_name = *argv++;
465 Parse LHA command and options.
468 parse_option(int argc, char **argv)
472 if (argv[1] == NULL || strcmp(argv[1], "--help") == 0) {
477 if (strcmp(argv[1], "--version") == 0) {
482 if (argc == 2 && *argv[1] != '-') {
483 archive_name = argv[1];
492 if (cmd_char[0] == '-')
503 output_to_stdout = TRUE;
521 update_if_newer = TRUE;
526 delete_after_append = TRUE;
531 verbose_listing = TRUE;
545 error("unknown command `-%c'", *cmd_char);
549 if (cmd_char[1] == '\0') {
550 /* argv[1] is command name */
556 /* Eliminate command character
557 e.g.) lha cv foo.lzh -> lha -v foo.lzh
558 lha -cv foo.lzh -> lha -v foo.lzh
564 return parse_suboption(argc, argv);
567 /* ------------------------------------------------------------------------ */
577 init_variable(); /* Added N.Watazaki */
579 if (parse_option(argc, argv) == -1) {
586 error("archive file does not specified");
592 if (!strcmp(archive_name, "-")) {
593 if (!isatty(1) && cmd == CMD_ADD)
596 #if 0 /* Comment out; IMHO, this feature is useless. by Koji Arai */
598 if (argc == 3 && !isatty(0)) { /* 1999.7.18 */
599 /* Bug(?) on MinGW, isatty() return 0 on Cygwin console.
600 mingw-runtime-1.3-2 and Cygwin 1.3.10(0.51/3/2) on Win2000 */
601 get_filename_from_stdin = TRUE;
606 /* target file name */
607 if (get_filename_from_stdin) {
613 xfilev = (char **)xmalloc(sizeof(char *) * xfilec);
614 while (fgets(inpbuf, sizeof(inpbuf), stdin)) {
615 /* delete \n if it exist */
617 while (i < sizeof(inpbuf) && p != 0) {
625 if (cmd_filec >= xfilec) {
627 xfilev = (char **) xrealloc(xfilev,
628 sizeof(char *) * xfilec);
630 if (strlen(inpbuf) < 1)
632 xfilev[cmd_filec++] = xstrdup(inpbuf);
634 xfilev[cmd_filec] = NULL;
664 /* ------------------------------------------------------------------------ */
668 /* macro PACKAGE_NAME, PACKAGE_VERSION and PLATFORM are
669 defined in config.h by configure script */
670 fprintf(stderr, "%s version %s (%s)\n",
671 PACKAGE_NAME, PACKAGE_VERSION, PLATFORM);
676 message(char *fmt, ...)
678 message(fmt, va_alist)
683 int errno_sv = errno;
686 fprintf(stderr, "LHa: ");
689 vfprintf(stderr, fmt, v);
697 /* ------------------------------------------------------------------------ */
700 warning(char *fmt, ...)
702 warning(fmt, va_alist)
707 int errno_sv = errno;
710 fprintf(stderr, "LHa: Warning: ");
713 vfprintf(stderr, fmt, v);
721 /* ------------------------------------------------------------------------ */
724 error(char *fmt, ...)
731 int errno_sv = errno;
734 fprintf(stderr, "LHa: Error: ");
737 vfprintf(stderr, fmt, v);
749 fatal_error(char *fmt, ...)
751 fatal_error(fmt, va_alist)
756 int errno_sv = errno;
759 fprintf(stderr, "LHa: Fatal error: ");
762 vfprintf(stderr, fmt, v);
766 fprintf(stderr, ": %s\n", strerror(errno_sv));
776 if (temporary_fd != -1) {
779 unlink(temporary_name);
782 if (recover_archive_when_interrupt) {
783 rename(backup_archive_name, archive_name);
784 recover_archive_when_interrupt = FALSE;
786 if (remove_extracting_file_when_interrupt) {
787 message("Removing: %s", writing_filename);
788 unlink(writing_filename);
789 remove_extracting_file_when_interrupt = FALSE;
797 message("Interrupted");
801 signal(SIGINT, SIG_DFL);
803 signal(SIGHUP, SIG_DFL);
805 kill(getpid(), signo);
808 /* ------------------------------------------------------------------------ */
810 /* ------------------------------------------------------------------------ */
815 register char *p, *q;
819 if (generic_format) {
821 c1 = *(unsigned char *) p++;
822 c2 = *(unsigned char *) q++;
834 while (*p == *q && *p != '\0')
836 return *(unsigned char *) p - *(unsigned char *) q;
840 /* ------------------------------------------------------------------------ */
845 qsort(cmd_filev, cmd_filec, sizeof(char *), sort_by_ascii);
848 /* ------------------------------------------------------------------------ */
853 void *p = malloc(size);
855 fatal_error("Not enough memory");
859 /* ------------------------------------------------------------------------ */
865 void *p = (char *) realloc(old, size);
867 fatal_error("Not enough memory");
875 int len = strlen(str);
876 char *p = (char *)xmalloc(len + 1);
877 strcpy(p, str); /* ok */
881 /* ------------------------------------------------------------------------ */
883 /* ------------------------------------------------------------------------ */
886 +-------------+-------------+------+-------------+----------+
887 | N A M E 1 \0| N A M E 2 \0| .... | N A M E n \0| |
888 +-------------+-------------+------+-------------+----------+
889 ^ ^ ^ buffer+0 buffer+used buffer+size
892 +---------------+---------------+------------- -----------------+
893 | pointer to | pointer to | pointer to ... pointer to |
894 | stringpool | N A M E 1 | N A M E 2 ... N A M E n |
895 +---------------+---------------+------------- -------------+
896 ^ malloc base returned
899 /* ------------------------------------------------------------------------ */
902 struct string_pool *sp;
904 sp->size = 1024 - 8; /* any ( >=0 ) */
907 sp->buffer = (char *) xmalloc(sp->size * sizeof(char));
910 /* ------------------------------------------------------------------------ */
912 add_sp(sp, name, len)
913 struct string_pool *sp;
914 char *name; /* stored '\0' at tail */
915 int len; /* include '\0' */
917 while (sp->used + len > sp->size) {
919 sp->buffer = (char *) xrealloc(sp->buffer, sp->size * sizeof(char));
921 memmove(sp->buffer + sp->used, name, len);
926 /* ------------------------------------------------------------------------ */
928 finish_sp(sp, v_count, v_vector)
929 register struct string_pool *sp;
937 v = (char **) xmalloc((sp->n + 1) * sizeof(char *));
942 for (i = sp->n; i; i--) {
949 /* ------------------------------------------------------------------------ */
955 free(*vector); /* free string pool */
960 /* ------------------------------------------------------------------------ */
961 /* READ DIRECTORY FILES */
962 /* ------------------------------------------------------------------------ */
964 include_path_p(path, name)
970 return (path[-1] == '/' && *n == '\0');
971 return (*n == '/' || (n != name && path[-1] == '/' && n[-1] == '/'));
974 /* ------------------------------------------------------------------------ */
976 cleaning_files(v_filec, v_filev)
983 register char **filev = *v_filev;
984 register int filec = *v_filec;
991 flags = xmalloc(filec * sizeof(char));
993 /* flags & 0x01 : 1: ignore */
994 /* flags & 0x02 : 1: directory, 0 : regular file */
995 /* flags & 0x04 : 1: need delete */
997 for (i = 0; i < filec; i++)
998 if (GETSTAT(filev[i], &stbuf) < 0) {
1000 warning("Cannot access \"%s\" : %s; ignored.", filev[i],
1004 if (is_regularfile(&stbuf))
1006 else if (is_directory(&stbuf))
1009 else if (is_symlink(&stbuf)) /* t.okamoto */
1014 warning("Cannot archive \"%s\", ignored.", filev[i]);
1018 for (i = 0; i < filec; i++) {
1020 if ((flags[i] & 0x07) == 0x00) { /* regular file, not
1021 * deleted/ignored */
1022 for (j = i + 1; j < filec; j++) {
1023 if ((flags[j] & 0x07) == 0x00) { /* regular file, not
1024 * deleted/ignored */
1025 if (STREQU(p, filev[j]))
1026 flags[j] = 0x04; /* delete */
1030 else if ((flags[i] & 0x07) == 0x02) { /* directory, not
1031 * deleted/ignored */
1032 for (j = i + 1; j < filec; j++) {
1033 if ((flags[j] & 0x07) == 0x00) { /* regular file, not
1034 * deleted/ignored */
1035 if (include_path_p(p, filev[j]))
1036 flags[j] = 0x04; /* delete */
1038 else if ((flags[j] & 0x07) == 0x02) { /* directory, not
1039 * deleted/ignored */
1040 if (include_path_p(p, filev[j]))
1041 flags[j] = 0x04; /* delete */
1047 for (i = j = 0; i < filec; i++) {
1048 if ((flags[i] & 0x04) == 0) {
1050 filev[j] = filev[i];
1059 /* ------------------------------------------------------------------------ */
1061 find_files(name, v_filec, v_filev)
1066 struct string_pool sp;
1067 char newname[FILENAME_LENGTH];
1071 struct stat tmp_stbuf, arc_stbuf, fil_stbuf;
1072 int exist_tmp = 1, exist_arc = 1;
1074 len = str_safe_copy(newname, name, sizeof(newname));
1075 if (len > 0 && newname[len - 1] != '/') {
1076 if (len < sizeof(newname)-1)
1077 strcpy(&newname[len++], "/"); /* ok */
1079 warning("the length of pathname \"%s\" is too long.", name);
1082 dirp = opendir(name);
1088 if (GETSTAT(temporary_name, &tmp_stbuf) == -1)
1090 if (GETSTAT(archive_name, &arc_stbuf) == -1)
1093 while ((dp = readdir(dirp)) != NULL) {
1096 /* exclude '.' and '..' */
1097 if (strncmp(dp->d_name, ".", n) == 0
1098 || strncmp(dp->d_name, "..", n) == 0)
1101 /* exclude exclude_files supplied by user */
1102 for (i = 0; exclude_files && exclude_files[i]; i++) {
1103 if (fnmatch(exclude_files[i], dp->d_name,
1104 FNM_PATHNAME|FNM_NOESCAPE|FNM_PERIOD) == 0)
1108 if (len + n >= sizeof(newname)) {
1109 warning("filename is too long");
1113 strncpy(newname + len, dp->d_name, n);
1114 newname[len + n] = '\0';
1115 if (GETSTAT(newname, &fil_stbuf) < 0)
1118 #if defined(HAVE_STRUCT_STAT_ST_INO) && !__MINGW32__
1119 /* MinGW has meaningless st_ino */
1121 /* exclude temporary file, archive file and these links */
1123 tmp_stbuf.st_dev == fil_stbuf.st_dev &&
1124 tmp_stbuf.st_ino == fil_stbuf.st_ino)
1128 arc_stbuf.st_dev == fil_stbuf.st_dev &&
1129 arc_stbuf.st_ino == fil_stbuf.st_ino)
1132 add_sp(&sp, newname, len+n+1);
1137 finish_sp(&sp, v_filec, v_filev);
1139 qsort(*v_filev, *v_filec, sizeof(char *), sort_by_ascii);
1140 cleaning_files(v_filec, v_filev);
1145 /* ------------------------------------------------------------------------ */
1147 free_files(filec, filev)
1154 /* ------------------------------------------------------------------------ */
1156 /* ------------------------------------------------------------------------ */
1157 /* Build temporary file name and store to TEMPORARY_NAME */
1159 build_temporary_name()
1161 #ifdef TMP_FILENAME_TEMPLATE
1162 /* "/tmp/lhXXXXXX" etc. */
1163 if (extract_directory == NULL) {
1164 str_safe_copy(temporary_name, TMP_FILENAME_TEMPLATE,
1165 sizeof(temporary_name));
1168 xsnprintf(temporary_name, sizeof(temporary_name),
1169 "%s/lhXXXXXX", extract_directory);
1174 str_safe_copy(temporary_name, archive_name, sizeof(temporary_name));
1175 s = strrchr(temporary_name, '/');
1178 len = s - temporary_name;
1179 if (len + strlen("lhXXXXXX") < sizeof(temporary_name))
1180 /* use directory at archive file */
1181 strcpy(s, "lhXXXXXX"); /* ok */
1183 /* use current directory */
1184 str_safe_copy(temporary_name, "lhXXXXXX", sizeof(temporary_name));
1187 /* use current directory */
1188 str_safe_copy(temporary_name, "lhXXXXXX", sizeof(temporary_name));
1194 old_umask = umask(077);
1195 fd = mkstemp(temporary_name);
1203 mktemp(temporary_name);
1204 flags = O_CREAT|O_EXCL|O_RDWR;
1208 return open(temporary_name, flags, 0600);
1213 /* ------------------------------------------------------------------------ */
1215 modify_filename_extention(buffer, ext, size)
1220 register char *p, *dot;
1222 for (p = buffer, dot = (char *) 0; *p; p++) {
1232 str_safe_copy(p, ext, size - (p - buffer));
1235 /* ------------------------------------------------------------------------ */
1236 /* build backup file name */
1238 build_backup_name(buffer, original, size)
1243 str_safe_copy(buffer, original, size);
1244 modify_filename_extention(buffer, BACKUPNAME_EXTENTION, size); /* ".bak" */
1247 /* ------------------------------------------------------------------------ */
1249 build_standard_archive_name(buffer, original, size)
1254 str_safe_copy(buffer, original, size);
1255 modify_filename_extention(buffer, ARCHIVENAME_EXTENTION, size); /* ".lzh" */
1258 /* ------------------------------------------------------------------------ */
1260 /* ------------------------------------------------------------------------ */
1270 for (i = 0; i < cmd_filec; i++) {
1271 if (patmatch(cmd_filev[i], name, 0))
1284 if ((fp = fopen(name, mode)) == NULL)
1285 fatal_error("Cannot open file \"%s\"", name);
1290 /* ------------------------------------------------------------------------ */
1292 /* ------------------------------------------------------------------------ */
1294 open_old_archive_1(name, v_fp)
1301 if (stat(name, &stbuf) >= 0 &&
1302 is_regularfile(&stbuf) &&
1303 (fp = fopen(name, READ_BINARY)) != NULL) {
1305 archive_file_gid = stbuf.st_gid;
1306 archive_file_mode = stbuf.st_mode;
1311 archive_file_gid = -1;
1315 /* ------------------------------------------------------------------------ */
1321 static char expanded_archive_name[FILENAME_LENGTH];
1323 if (!strcmp(archive_name, "-")) {
1324 if (cmd == CMD_EXTRACT || cmd == CMD_LIST) {
1325 #if defined(__MINGW32__) || defined(__DJGPP__)
1326 setmode(fileno(stdin), O_BINARY);
1333 p = strrchr(archive_name, '.');
1335 if (strcasecmp(".LZH", p) == 0
1336 || strcasecmp(".LZS", p) == 0
1337 || strcasecmp(".COM", p) == 0 /* DOS SFX */
1338 || strcasecmp(".EXE", p) == 0
1339 || strcasecmp(".X", p) == 0 /* HUMAN SFX */
1340 || strcasecmp(".BAK", p) == 0) { /* for BackUp */
1341 open_old_archive_1(archive_name, &fp);
1346 if (open_old_archive_1(archive_name, &fp))
1348 xsnprintf(expanded_archive_name, sizeof(expanded_archive_name),
1349 "%s.lzh", archive_name);
1350 if (open_old_archive_1(expanded_archive_name, &fp)) {
1351 archive_name = expanded_archive_name;
1355 * if ( (errno&0xffff)!=E_PNNF ) { archive_name =
1356 * expanded_archive_name; return NULL; }
1358 xsnprintf(expanded_archive_name, sizeof(expanded_archive_name),
1359 "%s.lzs", archive_name);
1360 if (open_old_archive_1(expanded_archive_name, &fp)) {
1361 archive_name = expanded_archive_name;
1365 * if ( (errno&0xffff)!=E_PNNF ) { archive_name =
1366 * expanded_archive_name; return NULL; }
1369 * sprintf( expanded_archive_name , "%s.lzh",archive_name);
1370 * archive_name = expanded_archive_name;
1375 /* ------------------------------------------------------------------------ */
1377 inquire(msg, name, selective)
1378 char *msg, *name, *selective;
1384 fprintf(stderr, "%s %s ", name, msg);
1387 fgets(buffer, 1024, stdin);
1389 for (p = selective; *p; p++)
1390 if (buffer[0] == *p)
1391 return p - selective;
1396 /* ------------------------------------------------------------------------ */
1398 write_archive_tail(nafp)
1404 /* ------------------------------------------------------------------------ */
1406 copy_old_one(oafp, nafp, hdr)
1411 fseeko(oafp, hdr->header_size + hdr->packed_size, SEEK_CUR);
1414 reading_filename = archive_name;
1415 writing_filename = temporary_name;
1416 copyfile(oafp, nafp, hdr->header_size + hdr->packed_size, 0, 0);