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 /* ------------------------------------------------------------------------ */
123 usage: lha [-]<commands>[<options>] [-<options> ...] archive_file [file...]\n\
124 commands: [axelvudmcpt]\n\
125 options: [q[012]vnfto[567]dizg012%s%s[w=<dir>|x=<pattern>]]\n\
126 long options: --system-kanji-code={euc,sjis,utf8,cap}\n\
127 --archive-kanji-code={euc,sjis,utf8,cap}\n\
128 --extract-broken-archive\n\
129 --convert-filename-case\n\
130 --ignore-mac-files\n\
139 #if HAVE_LIBAPPLEFILE
140 ,"b" /* decode_macbinary_contents */
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\
202 #include "getopt_long.h"
208 parse_suboption(int argc, char **argv)
213 SYSTEM_KANJI_CODE_OPTION,
214 ARCHIVE_KANJI_CODE_OPTION,
215 TRADITIONAL_BEHAVIOR,
219 struct option long_options[] = {
220 /* These options set a flag. */
221 {"help", no_argument, 0, HELP_OPTION},
222 {"version", no_argument, 0, VERSION_OPTION},
224 {"system-kanji-code", required_argument, 0, SYSTEM_KANJI_CODE_OPTION},
225 {"archive-kanji-code", required_argument, 0, ARCHIVE_KANJI_CODE_OPTION},
226 {"extract-broken-archive", no_argument, &extract_broken_archive, 1},
227 {"convert-filename-case", no_argument, &convertcase, TRUE},
228 {"traditional", no_argument, 0, TRADITIONAL_BEHAVIOR},
229 {"ignore-mac-files", no_argument, 0, IGNORE_MAC_FILES},
234 char short_options[256] = "q[012]vnfto[567]dizg012ew:x:";
235 /* "[...]" means optional 1 byte argument (original extention) */
237 #if HAVE_LIBAPPLEFILE
238 strncat(short_options, "b", sizeof(short_options)-strlen(short_options)-1);
243 int option_index = 0;
244 int c = getopt_long(argc, argv,
245 short_options, long_options,
248 if (c == -1) break; /* end of options */
252 /* Already set a flag variable by the definition of the
267 /* In quiet mode, no confirm to overwrite */
274 case '0': /* no quiet */
275 case '1': /* no use the incremental indicator */
276 quiet_mode = *optarg - '0';
278 case '2': /* no output */
301 #if HAVE_LIBAPPLEFILE
303 decode_macbinary_contents = TRUE;
310 generic_format = TRUE;
314 delete_after_append = TRUE;
318 compress_method = LZHUFF1_METHOD_NUM;
324 compress_method = LZHUFF5_METHOD_NUM;
328 compress_method = LZHUFF6_METHOD_NUM;
331 compress_method = LZHUFF7_METHOD_NUM;
335 error("invalid compression method 'o%c'", *optarg);
340 compress_method = LZHUFF0_METHOD_NUM; /* Changed N.Watazaki */
343 ignore_directory = TRUE;
347 error("exclude files does not specified for `-x'");
351 for (i = 0; exclude_files && exclude_files[i]; i++)
353 exclude_files = (char**)xrealloc(exclude_files,
354 sizeof(char*) * (i+2));
358 exclude_files[i] = optarg;
359 exclude_files[i+1] = 0;
364 error("working directory does not specified for `-w'");
370 extract_directory = optarg;
381 case SYSTEM_KANJI_CODE_OPTION:
383 error("kanji code not specified for --%s",
384 long_options[option_index].name);
387 if (strcmp(optarg, "euc") == 0) {
388 optional_system_kanji_code = CODE_EUC;
390 else if (strcmp(optarg, "sjis") == 0) {
391 optional_system_kanji_code = CODE_SJIS;
393 else if (strcmp(optarg, "utf8") == 0) {
394 optional_system_kanji_code = CODE_UTF8;
396 else if (strcmp(optarg, "cap") == 0) {
397 optional_system_kanji_code = CODE_CAP;
400 error("unknown kanji code \"%s\"", optarg);
405 case ARCHIVE_KANJI_CODE_OPTION:
407 error("kanji code not specified for --%s",
408 long_options[option_index].name);
411 if (strcmp(optarg, "euc") == 0) {
412 optional_archive_kanji_code = CODE_EUC;
414 else if (strcmp(optarg, "sjis") == 0) {
415 optional_archive_kanji_code = CODE_SJIS;
417 else if (strcmp(optarg, "utf8") == 0) {
418 optional_archive_kanji_code = CODE_UTF8;
420 else if (strcmp(optarg, "cap") == 0) {
421 optional_archive_kanji_code = CODE_CAP;
424 error("unknown kanji code \"%s\"", optarg);
429 case TRADITIONAL_BEHAVIOR:
433 case IGNORE_MAC_FILES:
434 /* ignore Mac specific files (._*, .DS_Store and Icon\r)
436 for (i = 0; exclude_files && exclude_files[i]; i++)
438 exclude_files = (char**)xrealloc(exclude_files,
439 sizeof(char*) * (i+4));
441 exclude_files[i] = xstrdup("._*");
442 exclude_files[i+1] = xstrdup(".DS_Store");
443 exclude_files[i+2] = xstrdup("Icon\r");
444 exclude_files[i+3] = 0;
448 error("unknown option `-%c'.", c);
457 archive_name = *argv++;
468 Parse LHA command and options.
471 parse_option(int argc, char **argv)
475 if (argv[1] == NULL || strcmp(argv[1], "--help") == 0) {
480 if (strcmp(argv[1], "--version") == 0) {
485 if (argc == 2 && *argv[1] != '-') {
486 archive_name = argv[1];
495 if (cmd_char[0] == '-')
506 output_to_stdout = TRUE;
524 update_if_newer = TRUE;
529 delete_after_append = TRUE;
534 verbose_listing = TRUE;
548 error("unknown command `-%c'", *cmd_char);
552 if (cmd_char[1] == '\0') {
553 /* argv[1] is command name */
559 /* Eliminate command character
560 e.g.) lha cv foo.lzh -> lha -v foo.lzh
561 lha -cv foo.lzh -> lha -v foo.lzh
567 return parse_suboption(argc, argv);
570 /* ------------------------------------------------------------------------ */
580 init_variable(); /* Added N.Watazaki */
582 if (parse_option(argc, argv) == -1) {
589 error("archive file does not specified");
595 if (!strcmp(archive_name, "-")) {
596 if (!isatty(1) && cmd == CMD_ADD)
599 #if 0 /* Comment out; IMHO, this feature is useless. by Koji Arai */
601 if (argc == 3 && !isatty(0)) { /* 1999.7.18 */
602 /* Bug(?) on MinGW, isatty() return 0 on Cygwin console.
603 mingw-runtime-1.3-2 and Cygwin 1.3.10(0.51/3/2) on Win2000 */
604 get_filename_from_stdin = TRUE;
609 /* target file name */
610 if (get_filename_from_stdin) {
616 xfilev = (char **)xmalloc(sizeof(char *) * xfilec);
617 while (fgets(inpbuf, sizeof(inpbuf), stdin)) {
618 /* delete \n if it exist */
620 while (i < sizeof(inpbuf) && p != 0) {
628 if (cmd_filec >= xfilec) {
630 xfilev = (char **) xrealloc(xfilev,
631 sizeof(char *) * xfilec);
633 if (strlen(inpbuf) < 1)
635 xfilev[cmd_filec++] = xstrdup(inpbuf);
637 xfilev[cmd_filec] = NULL;
667 /* ------------------------------------------------------------------------ */
671 /* macro PACKAGE_NAME, PACKAGE_VERSION and PLATFORM are
672 defined in config.h by configure script */
673 fprintf(stderr, "%s version %s (%s)\n",
674 PACKAGE_NAME, PACKAGE_VERSION, PLATFORM);
679 message(char *fmt, ...)
681 message(fmt, va_alist)
686 int errno_sv = errno;
689 fprintf(stderr, "LHa: ");
692 vfprintf(stderr, fmt, v);
700 /* ------------------------------------------------------------------------ */
703 warning(char *fmt, ...)
705 warning(fmt, va_alist)
710 int errno_sv = errno;
713 fprintf(stderr, "LHa: Warning: ");
716 vfprintf(stderr, fmt, v);
724 /* ------------------------------------------------------------------------ */
727 error(char *fmt, ...)
734 int errno_sv = errno;
737 fprintf(stderr, "LHa: Error: ");
740 vfprintf(stderr, fmt, v);
752 fatal_error(char *fmt, ...)
754 fatal_error(fmt, va_alist)
759 int errno_sv = errno;
762 fprintf(stderr, "LHa: Fatal error: ");
765 vfprintf(stderr, fmt, v);
769 fprintf(stderr, ": %s\n", strerror(errno_sv));
779 if (temporary_fd != -1) {
782 unlink(temporary_name);
785 if (recover_archive_when_interrupt) {
786 rename(backup_archive_name, archive_name);
787 recover_archive_when_interrupt = FALSE;
789 if (remove_extracting_file_when_interrupt) {
790 message("Removing: %s", writing_filename);
791 unlink(writing_filename);
792 remove_extracting_file_when_interrupt = FALSE;
800 message("Interrupted");
804 signal(SIGINT, SIG_DFL);
806 signal(SIGHUP, SIG_DFL);
808 kill(getpid(), signo);
811 /* ------------------------------------------------------------------------ */
813 /* ------------------------------------------------------------------------ */
818 register char *p, *q;
822 if (generic_format) {
824 c1 = *(unsigned char *) p++;
825 c2 = *(unsigned char *) q++;
837 while (*p == *q && *p != '\0')
839 return *(unsigned char *) p - *(unsigned char *) q;
843 /* ------------------------------------------------------------------------ */
848 qsort(cmd_filev, cmd_filec, sizeof(char *), sort_by_ascii);
851 /* ------------------------------------------------------------------------ */
856 void *p = malloc(size);
858 fatal_error("Not enough memory");
862 /* ------------------------------------------------------------------------ */
868 void *p = (char *) realloc(old, size);
870 fatal_error("Not enough memory");
878 int len = strlen(str);
879 char *p = (char *)xmalloc(len + 1);
880 strcpy(p, str); /* ok */
884 /* ------------------------------------------------------------------------ */
886 /* ------------------------------------------------------------------------ */
889 +-------------+-------------+------+-------------+----------+
890 | N A M E 1 \0| N A M E 2 \0| .... | N A M E n \0| |
891 +-------------+-------------+------+-------------+----------+
892 ^ ^ ^ buffer+0 buffer+used buffer+size
895 +---------------+---------------+------------- -----------------+
896 | pointer to | pointer to | pointer to ... pointer to |
897 | stringpool | N A M E 1 | N A M E 2 ... N A M E n |
898 +---------------+---------------+------------- -------------+
899 ^ malloc base returned
902 /* ------------------------------------------------------------------------ */
905 struct string_pool *sp;
907 sp->size = 1024 - 8; /* any ( >=0 ) */
910 sp->buffer = (char *) xmalloc(sp->size * sizeof(char));
913 /* ------------------------------------------------------------------------ */
915 add_sp(sp, name, len)
916 struct string_pool *sp;
917 char *name; /* stored '\0' at tail */
918 int len; /* include '\0' */
920 while (sp->used + len > sp->size) {
922 sp->buffer = (char *) xrealloc(sp->buffer, sp->size * sizeof(char));
924 memmove(sp->buffer + sp->used, name, len);
929 /* ------------------------------------------------------------------------ */
931 finish_sp(sp, v_count, v_vector)
932 register struct string_pool *sp;
940 v = (char **) xmalloc((sp->n + 1) * sizeof(char *));
945 for (i = sp->n; i; i--) {
952 /* ------------------------------------------------------------------------ */
958 free(*vector); /* free string pool */
963 /* ------------------------------------------------------------------------ */
964 /* READ DIRECTORY FILES */
965 /* ------------------------------------------------------------------------ */
967 include_path_p(path, name)
973 return (path[-1] == '/' && *n == '\0');
974 return (*n == '/' || (n != name && path[-1] == '/' && n[-1] == '/'));
977 /* ------------------------------------------------------------------------ */
979 cleaning_files(v_filec, v_filev)
986 register char **filev = *v_filev;
987 register int filec = *v_filec;
994 flags = xmalloc(filec * sizeof(char));
996 /* flags & 0x01 : 1: ignore */
997 /* flags & 0x02 : 1: directory, 0 : regular file */
998 /* flags & 0x04 : 1: need delete */
1000 for (i = 0; i < filec; i++)
1001 if (GETSTAT(filev[i], &stbuf) < 0) {
1003 warning("Cannot access \"%s\" : %s; ignored.", filev[i],
1007 if (is_regularfile(&stbuf))
1009 else if (is_directory(&stbuf))
1012 else if (is_symlink(&stbuf)) /* t.okamoto */
1017 warning("Cannot archive \"%s\", ignored.", filev[i]);
1021 for (i = 0; i < filec; i++) {
1023 if ((flags[i] & 0x07) == 0x00) { /* regular file, not
1024 * deleted/ignored */
1025 for (j = i + 1; j < filec; j++) {
1026 if ((flags[j] & 0x07) == 0x00) { /* regular file, not
1027 * deleted/ignored */
1028 if (STREQU(p, filev[j]))
1029 flags[j] = 0x04; /* delete */
1033 else if ((flags[i] & 0x07) == 0x02) { /* directory, not
1034 * deleted/ignored */
1035 for (j = i + 1; j < filec; j++) {
1036 if ((flags[j] & 0x07) == 0x00) { /* regular file, not
1037 * deleted/ignored */
1038 if (include_path_p(p, filev[j]))
1039 flags[j] = 0x04; /* delete */
1041 else if ((flags[j] & 0x07) == 0x02) { /* directory, not
1042 * deleted/ignored */
1043 if (include_path_p(p, filev[j]))
1044 flags[j] = 0x04; /* delete */
1050 for (i = j = 0; i < filec; i++) {
1051 if ((flags[i] & 0x04) == 0) {
1053 filev[j] = filev[i];
1062 /* ------------------------------------------------------------------------ */
1064 find_files(name, v_filec, v_filev)
1069 struct string_pool sp;
1070 char newname[FILENAME_LENGTH];
1074 struct stat tmp_stbuf, arc_stbuf, fil_stbuf;
1075 int exist_tmp = 1, exist_arc = 1;
1077 len = str_safe_copy(newname, name, sizeof(newname));
1078 if (len > 0 && newname[len - 1] != '/') {
1079 if (len < sizeof(newname)-1)
1080 strcpy(&newname[len++], "/"); /* ok */
1082 warning("the length of pathname \"%s\" is too long.", name);
1085 dirp = opendir(name);
1091 if (GETSTAT(temporary_name, &tmp_stbuf) == -1)
1093 if (GETSTAT(archive_name, &arc_stbuf) == -1)
1096 while ((dp = readdir(dirp)) != NULL) {
1099 /* exclude '.' and '..' */
1100 if (strncmp(dp->d_name, ".", n) == 0
1101 || strncmp(dp->d_name, "..", n) == 0)
1104 /* exclude exclude_files supplied by user */
1105 for (i = 0; exclude_files && exclude_files[i]; i++) {
1106 if (fnmatch(exclude_files[i], dp->d_name,
1107 FNM_PATHNAME|FNM_NOESCAPE|FNM_PERIOD) == 0)
1111 if (len + n >= sizeof(newname)) {
1112 warning("filename is too long");
1116 strncpy(newname + len, dp->d_name, n);
1117 newname[len + n] = '\0';
1118 if (GETSTAT(newname, &fil_stbuf) < 0)
1121 #if defined(HAVE_STRUCT_STAT_ST_INO) && !__MINGW32__
1122 /* MinGW has meaningless st_ino */
1124 /* exclude temporary file, archive file and these links */
1126 tmp_stbuf.st_dev == fil_stbuf.st_dev &&
1127 tmp_stbuf.st_ino == fil_stbuf.st_ino)
1131 arc_stbuf.st_dev == fil_stbuf.st_dev &&
1132 arc_stbuf.st_ino == fil_stbuf.st_ino)
1135 add_sp(&sp, newname, len+n+1);
1140 finish_sp(&sp, v_filec, v_filev);
1142 qsort(*v_filev, *v_filec, sizeof(char *), sort_by_ascii);
1143 cleaning_files(v_filec, v_filev);
1148 /* ------------------------------------------------------------------------ */
1150 free_files(filec, filev)
1157 /* ------------------------------------------------------------------------ */
1159 /* ------------------------------------------------------------------------ */
1160 /* Build temporary file name and store to TEMPORARY_NAME */
1162 build_temporary_name()
1164 #ifdef TMP_FILENAME_TEMPLATE
1165 /* "/tmp/lhXXXXXX" etc. */
1166 if (extract_directory == NULL) {
1167 str_safe_copy(temporary_name, TMP_FILENAME_TEMPLATE,
1168 sizeof(temporary_name));
1171 xsnprintf(temporary_name, sizeof(temporary_name),
1172 "%s/lhXXXXXX", extract_directory);
1177 str_safe_copy(temporary_name, archive_name, sizeof(temporary_name));
1178 s = strrchr(temporary_name, '/');
1181 len = s - temporary_name;
1182 if (len + strlen("lhXXXXXX") < sizeof(temporary_name))
1183 /* use directory at archive file */
1184 strcpy(s, "lhXXXXXX"); /* ok */
1186 /* use current directory */
1187 str_safe_copy(temporary_name, "lhXXXXXX", sizeof(temporary_name));
1190 /* use current directory */
1191 str_safe_copy(temporary_name, "lhXXXXXX", sizeof(temporary_name));
1197 old_umask = umask(077);
1198 fd = mkstemp(temporary_name);
1206 mktemp(temporary_name);
1207 flags = O_CREAT|O_EXCL|O_RDWR;
1211 return open(temporary_name, flags, 0600);
1216 /* ------------------------------------------------------------------------ */
1218 modify_filename_extention(buffer, ext, size)
1223 register char *p, *dot;
1225 for (p = buffer, dot = (char *) 0; *p; p++) {
1235 str_safe_copy(p, ext, size - (p - buffer));
1238 /* ------------------------------------------------------------------------ */
1239 /* build backup file name */
1241 build_backup_name(buffer, original, size)
1246 str_safe_copy(buffer, original, size);
1247 modify_filename_extention(buffer, BACKUPNAME_EXTENTION, size); /* ".bak" */
1250 /* ------------------------------------------------------------------------ */
1252 build_standard_archive_name(buffer, original, size)
1257 str_safe_copy(buffer, original, size);
1258 modify_filename_extention(buffer, ARCHIVENAME_EXTENTION, size); /* ".lzh" */
1261 /* ------------------------------------------------------------------------ */
1263 /* ------------------------------------------------------------------------ */
1273 for (i = 0; i < cmd_filec; i++) {
1274 if (patmatch(cmd_filev[i], name, 0))
1287 if ((fp = fopen(name, mode)) == NULL)
1288 fatal_error("Cannot open file \"%s\"", name);
1293 /* ------------------------------------------------------------------------ */
1295 /* ------------------------------------------------------------------------ */
1297 open_old_archive_1(name, v_fp)
1304 if (stat(name, &stbuf) >= 0 &&
1305 is_regularfile(&stbuf) &&
1306 (fp = fopen(name, READ_BINARY)) != NULL) {
1308 archive_file_gid = stbuf.st_gid;
1309 archive_file_mode = stbuf.st_mode;
1314 archive_file_gid = -1;
1318 /* ------------------------------------------------------------------------ */
1324 static char expanded_archive_name[FILENAME_LENGTH];
1326 if (!strcmp(archive_name, "-")) {
1327 if (cmd == CMD_EXTRACT || cmd == CMD_LIST) {
1328 #if defined(__MINGW32__) || defined(__DJGPP__)
1329 setmode(fileno(stdin), O_BINARY);
1336 p = strrchr(archive_name, '.');
1338 if (strcasecmp(".LZH", p) == 0
1339 || strcasecmp(".LZS", p) == 0
1340 || strcasecmp(".COM", p) == 0 /* DOS SFX */
1341 || strcasecmp(".EXE", p) == 0
1342 || strcasecmp(".X", p) == 0 /* HUMAN SFX */
1343 || strcasecmp(".BAK", p) == 0) { /* for BackUp */
1344 open_old_archive_1(archive_name, &fp);
1349 if (open_old_archive_1(archive_name, &fp))
1351 xsnprintf(expanded_archive_name, sizeof(expanded_archive_name),
1352 "%s.lzh", archive_name);
1353 if (open_old_archive_1(expanded_archive_name, &fp)) {
1354 archive_name = expanded_archive_name;
1358 * if ( (errno&0xffff)!=E_PNNF ) { archive_name =
1359 * expanded_archive_name; return NULL; }
1361 xsnprintf(expanded_archive_name, sizeof(expanded_archive_name),
1362 "%s.lzs", archive_name);
1363 if (open_old_archive_1(expanded_archive_name, &fp)) {
1364 archive_name = expanded_archive_name;
1368 * if ( (errno&0xffff)!=E_PNNF ) { archive_name =
1369 * expanded_archive_name; return NULL; }
1372 * sprintf( expanded_archive_name , "%s.lzh",archive_name);
1373 * archive_name = expanded_archive_name;
1378 /* ------------------------------------------------------------------------ */
1380 inquire(msg, name, selective)
1381 char *msg, *name, *selective;
1387 fprintf(stderr, "%s %s ", name, msg);
1390 fgets(buffer, 1024, stdin);
1392 for (p = selective; *p; p++)
1393 if (buffer[0] == *p)
1394 return p - selective;
1399 /* ------------------------------------------------------------------------ */
1401 write_archive_tail(nafp)
1407 /* ------------------------------------------------------------------------ */
1409 copy_old_one(oafp, nafp, hdr)
1414 fseeko(oafp, hdr->header_size + hdr->packed_size, SEEK_CUR);
1417 reading_filename = archive_name;
1418 writing_filename = temporary_name;
1419 copyfile(oafp, nafp, hdr->header_size + hdr->packed_size, 0, 0);