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;
96 noconvertcase = 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;
110 /* ------------------------------------------------------------------------ */
111 /* NOTES : Text File Format */
112 /* GENERATOR NewLine */
113 /* [generic] 0D 0A */
115 /* [OS9][MacOS] 0D */
117 /* ------------------------------------------------------------------------ */
122 usage: lha [-]<commands>[<options>] [-<options> ...] archive_file [file...]\n\
123 commands: [axelvudmcpt]\n\
124 options: [q[012]vnfto[567]dizg012e[w=<dir>|x=<pattern>]]\n\
125 long options: --system-kanji-code={euc,sjis,utf8,cap}\n\
126 --archive-kanji-code={euc,sjis,utf8,cap}\n\
127 --extract-broken-archive\n\
136 LHarc for UNIX V 1.02 Copyright(C) 1989 Y.Tagawa\n\
137 LHx for MSDOS V C2.01 Copyright(C) 1990 H.Yoshizaki\n\
138 LHx(arc) for OSK V 2.01 Modified 1990 Momozou\n\
139 LHa for UNIX V 1.00 Copyright(C) 1992 Masaru Oki\n\
140 LHa for UNIX V 1.14 Modified 1995 Nobutaka Watazaki\n\
141 LHa for UNIX V 1.14i Modified 2000 Tsugio Okamoto\n\
142 Autoconfiscated 2001-2005 Koji Arai\n\
148 commands: options:\n\
149 a Add(or replace) to archive q{num} quiet (num:quiet mode)\n\
150 x,e EXtract from archive v verbose\n\
151 l,v List / Verbose List n not execute\n\
152 u Update newer files to archive f force (over write at extract)\n\
153 d Delete from archive t FILES are TEXT file\n");
156 m Move to archive (means 'ad') o[567] compression method (a/u/c)\n\
161 m Move to archive (means 'ad') o use LHarc compatible method (a/u/c)\n\
165 c re-Construct new archive d delete FILES after (a/u/c)\n\
166 p Print to STDOUT from archive i ignore directory path (x/e)\n\
167 t Test file CRC in archive z files not compress (a/u/c)\n\
168 g Generic format (for compatibility)\n\
169 or not convert case when extracting\n\
170 0/1/2 header level (a/u/c)\n\
174 e TEXT code convert from/to EUC\n\
178 w=<dir> specify extract directory (x/e)\n\
179 x=<pattern> eXclude files (a/u/c)\n\
181 #if IGNORE_DOT_FILES /* experimental feature */
183 X ignore dot files (a/u/c)\n\
188 #include "getopt_long.h"
194 parse_suboption(int argc, char **argv)
197 char *short_options = "q[012]vnfto[567]dizg012ew:x:X";
199 char *short_options = "q[012]vnfto[567]dizg012ew:x:";
201 /* "[...]" means optional 1 byte argument (original extention) */
205 SYSTEM_KANJI_CODE_OPTION,
206 ARCHIVE_KANJI_CODE_OPTION,
209 struct option long_options[] = {
210 /* These options set a flag. */
211 {"help", no_argument, 0, HELP_OPTION},
212 {"version", no_argument, 0, VERSION_OPTION},
214 {"system-kanji-code", required_argument, 0, SYSTEM_KANJI_CODE_OPTION},
215 {"archive-kanji-code", required_argument, 0, ARCHIVE_KANJI_CODE_OPTION},
216 {"extract-broken-archive", no_argument, &extract_broken_archive, 1},
223 int option_index = 0;
224 int c = getopt_long(argc, argv,
225 short_options, long_options,
228 if (c == -1) break; /* end of options */
232 /* Already set a flag variable by the definition of the
247 /* In quiet mode, no confirm to overwrite */
254 case '0': /* no quiet */
255 case '1': /* no use the incremental indicator */
256 quiet_mode = *optarg - '0';
258 case '2': /* no output */
285 generic_format = TRUE;
286 noconvertcase = TRUE;
290 delete_after_append = TRUE;
294 compress_method = LZHUFF1_METHOD_NUM;
300 compress_method = LZHUFF5_METHOD_NUM;
304 compress_method = LZHUFF6_METHOD_NUM;
307 compress_method = LZHUFF7_METHOD_NUM;
311 error("invalid compression method 'o%c'", *optarg);
316 compress_method = LZHUFF0_METHOD_NUM; /* Changed N.Watazaki */
319 ignore_directory = TRUE;
323 error("exclude files does not specified for `-x'");
327 for (i = 0; exclude_files && exclude_files[i]; i++)
329 exclude_files = (char**)xrealloc(exclude_files,
330 sizeof(char*) * (i+2));
334 exclude_files[i] = optarg;
335 exclude_files[i+1] = 0;
338 #if IGNORE_DOT_FILES /* experimental feature */
340 for (i = 0; exclude_files && exclude_files[i]; i++)
342 exclude_files = (char**)xrealloc(exclude_files,
343 sizeof(char*) * (i+2));
345 exclude_files[i] = xstrdup(".*");
346 exclude_files[i+1] = 0;
351 error("working directory does not specified for `-w'");
357 extract_directory = optarg;
368 case SYSTEM_KANJI_CODE_OPTION:
370 error("kanji code not specified for --%s",
371 long_options[option_index].name);
374 if (strcmp(optarg, "euc") == 0) {
375 optional_system_kanji_code = CODE_EUC;
377 else if (strcmp(optarg, "sjis") == 0) {
378 optional_system_kanji_code = CODE_SJIS;
380 else if (strcmp(optarg, "utf8") == 0) {
381 optional_system_kanji_code = CODE_UTF8;
383 else if (strcmp(optarg, "cap") == 0) {
384 optional_system_kanji_code = CODE_CAP;
387 error("unknown kanji code \"%s\"", optarg);
392 case ARCHIVE_KANJI_CODE_OPTION:
394 error("kanji code not specified for --%s",
395 long_options[option_index].name);
398 if (strcmp(optarg, "euc") == 0) {
399 optional_archive_kanji_code = CODE_EUC;
401 else if (strcmp(optarg, "sjis") == 0) {
402 optional_archive_kanji_code = CODE_SJIS;
404 else if (strcmp(optarg, "utf8") == 0) {
405 optional_archive_kanji_code = CODE_UTF8;
407 else if (strcmp(optarg, "cap") == 0) {
408 optional_archive_kanji_code = CODE_CAP;
411 error("unknown kanji code \"%s\"", optarg);
417 error("unknown option `-%c'.", c);
426 archive_name = *argv++;
437 Parse LHA command and options.
440 parse_option(int argc, char **argv)
444 if (argv[1] == NULL || strcmp(argv[1], "--help") == 0) {
449 if (strcmp(argv[1], "--version") == 0) {
454 if (argc == 2 && *argv[1] != '-') {
455 archive_name = argv[1];
464 if (cmd_char[0] == '-')
475 output_to_stdout = TRUE;
493 update_if_newer = TRUE;
498 delete_after_append = TRUE;
503 verbose_listing = TRUE;
517 error("unknown command `-%c'", *cmd_char);
521 if (cmd_char[1] == '\0') {
522 /* argv[1] is command name */
528 /* Eliminate command character
529 e.g.) lha cv foo.lzh -> lha -v foo.lzh
530 lha -cv foo.lzh -> lha -v foo.lzh
536 return parse_suboption(argc, argv);
539 /* ------------------------------------------------------------------------ */
549 init_variable(); /* Added N.Watazaki */
551 if (parse_option(argc, argv) == -1) {
558 error("archive file does not specified");
564 if (!strcmp(archive_name, "-")) {
565 if (!isatty(1) && cmd == CMD_ADD)
568 #if 0 /* Comment out; IMHO, this feature is useless. by Koji Arai */
570 if (argc == 3 && !isatty(0)) { /* 1999.7.18 */
571 /* Bug(?) on MinGW, isatty() return 0 on Cygwin console.
572 mingw-runtime-1.3-2 and Cygwin 1.3.10(0.51/3/2) on Win2000 */
573 get_filename_from_stdin = TRUE;
578 /* target file name */
579 if (get_filename_from_stdin) {
585 xfilev = (char **)xmalloc(sizeof(char *) * xfilec);
586 while (fgets(inpbuf, sizeof(inpbuf), stdin)) {
587 /* delete \n if it exist */
589 while (i < sizeof(inpbuf) && p != 0) {
597 if (cmd_filec >= xfilec) {
599 xfilev = (char **) xrealloc(xfilev,
600 sizeof(char *) * xfilec);
602 if (strlen(inpbuf) < 1)
604 xfilev[cmd_filec++] = xstrdup(inpbuf);
606 xfilev[cmd_filec] = NULL;
636 /* ------------------------------------------------------------------------ */
640 /* macro PACKAGE_NAME, PACKAGE_VERSION and PLATFORM are
641 defined in config.h by configure script */
642 fprintf(stderr, "%s version %s (%s)\n",
643 PACKAGE_NAME, PACKAGE_VERSION, PLATFORM);
648 message(char *fmt, ...)
650 message(fmt, va_alist)
655 int errno_sv = errno;
658 fprintf(stderr, "LHa: ");
661 vfprintf(stderr, fmt, v);
669 /* ------------------------------------------------------------------------ */
672 warning(char *fmt, ...)
674 warning(fmt, va_alist)
679 int errno_sv = errno;
682 fprintf(stderr, "LHa: Warning: ");
685 vfprintf(stderr, fmt, v);
693 /* ------------------------------------------------------------------------ */
696 error(char *fmt, ...)
703 int errno_sv = errno;
706 fprintf(stderr, "LHa: Error: ");
709 vfprintf(stderr, fmt, v);
721 fatal_error(char *fmt, ...)
723 fatal_error(fmt, va_alist)
728 int errno_sv = errno;
731 fprintf(stderr, "LHa: Fatal error: ");
734 vfprintf(stderr, fmt, v);
738 fprintf(stderr, ": %s\n", strerror(errno_sv));
748 if (temporary_fd != -1) {
751 unlink(temporary_name);
754 if (recover_archive_when_interrupt) {
755 rename(backup_archive_name, archive_name);
756 recover_archive_when_interrupt = FALSE;
758 if (remove_extracting_file_when_interrupt) {
759 message("Removing: %s", writing_filename);
760 unlink(writing_filename);
761 remove_extracting_file_when_interrupt = FALSE;
769 message("Interrupted");
773 signal(SIGINT, SIG_DFL);
775 signal(SIGHUP, SIG_DFL);
777 kill(getpid(), signo);
780 /* ------------------------------------------------------------------------ */
782 /* ------------------------------------------------------------------------ */
787 register char *p, *q;
791 if (generic_format) {
793 c1 = *(unsigned char *) p++;
794 c2 = *(unsigned char *) q++;
806 while (*p == *q && *p != '\0')
808 return *(unsigned char *) p - *(unsigned char *) q;
812 /* ------------------------------------------------------------------------ */
817 qsort(cmd_filev, cmd_filec, sizeof(char *), sort_by_ascii);
820 /* ------------------------------------------------------------------------ */
825 void *p = malloc(size);
827 fatal_error("Not enough memory");
831 /* ------------------------------------------------------------------------ */
837 void *p = (char *) realloc(old, size);
839 fatal_error("Not enough memory");
847 int len = strlen(str);
848 char *p = (char *)xmalloc(len + 1);
849 strcpy(p, str); /* ok */
853 /* ------------------------------------------------------------------------ */
855 /* ------------------------------------------------------------------------ */
858 +-------------+-------------+------+-------------+----------+
859 | N A M E 1 \0| N A M E 2 \0| .... | N A M E n \0| |
860 +-------------+-------------+------+-------------+----------+
861 ^ ^ ^ buffer+0 buffer+used buffer+size
864 +---------------+---------------+------------- -----------------+
865 | pointer to | pointer to | pointer to ... pointer to |
866 | stringpool | N A M E 1 | N A M E 2 ... N A M E n |
867 +---------------+---------------+------------- -------------+
868 ^ malloc base returned
871 /* ------------------------------------------------------------------------ */
874 struct string_pool *sp;
876 sp->size = 1024 - 8; /* any ( >=0 ) */
879 sp->buffer = (char *) xmalloc(sp->size * sizeof(char));
882 /* ------------------------------------------------------------------------ */
884 add_sp(sp, name, len)
885 struct string_pool *sp;
886 char *name; /* stored '\0' at tail */
887 int len; /* include '\0' */
889 while (sp->used + len > sp->size) {
891 sp->buffer = (char *) xrealloc(sp->buffer, sp->size * sizeof(char));
893 memmove(sp->buffer + sp->used, name, len);
898 /* ------------------------------------------------------------------------ */
900 finish_sp(sp, v_count, v_vector)
901 register struct string_pool *sp;
909 v = (char **) xmalloc((sp->n + 1) * sizeof(char *));
914 for (i = sp->n; i; i--) {
921 /* ------------------------------------------------------------------------ */
927 free(*vector); /* free string pool */
932 /* ------------------------------------------------------------------------ */
933 /* READ DIRECTORY FILES */
934 /* ------------------------------------------------------------------------ */
936 include_path_p(path, name)
942 return (path[-1] == '/' && *n == '\0');
943 return (*n == '/' || (n != name && path[-1] == '/' && n[-1] == '/'));
946 /* ------------------------------------------------------------------------ */
948 cleaning_files(v_filec, v_filev)
955 register char **filev = *v_filev;
956 register int filec = *v_filec;
963 flags = xmalloc(filec * sizeof(char));
965 /* flags & 0x01 : 1: ignore */
966 /* flags & 0x02 : 1: directory, 0 : regular file */
967 /* flags & 0x04 : 1: need delete */
969 for (i = 0; i < filec; i++)
970 if (GETSTAT(filev[i], &stbuf) < 0) {
972 warning("Cannot access \"%s\" : %s; ignored.", filev[i],
976 if (is_regularfile(&stbuf))
978 else if (is_directory(&stbuf))
981 else if (is_symlink(&stbuf)) /* t.okamoto */
986 warning("Cannot archive \"%s\", ignored.", filev[i]);
990 for (i = 0; i < filec; i++) {
992 if ((flags[i] & 0x07) == 0x00) { /* regular file, not
994 for (j = i + 1; j < filec; j++) {
995 if ((flags[j] & 0x07) == 0x00) { /* regular file, not
997 if (STREQU(p, filev[j]))
998 flags[j] = 0x04; /* delete */
1002 else if ((flags[i] & 0x07) == 0x02) { /* directory, not
1003 * deleted/ignored */
1004 for (j = i + 1; j < filec; j++) {
1005 if ((flags[j] & 0x07) == 0x00) { /* regular file, not
1006 * deleted/ignored */
1007 if (include_path_p(p, filev[j]))
1008 flags[j] = 0x04; /* delete */
1010 else if ((flags[j] & 0x07) == 0x02) { /* directory, not
1011 * deleted/ignored */
1012 if (include_path_p(p, filev[j]))
1013 flags[j] = 0x04; /* delete */
1019 for (i = j = 0; i < filec; i++) {
1020 if ((flags[i] & 0x04) == 0) {
1022 filev[j] = filev[i];
1031 /* ------------------------------------------------------------------------ */
1033 find_files(name, v_filec, v_filev)
1038 struct string_pool sp;
1039 char newname[FILENAME_LENGTH];
1043 struct stat tmp_stbuf, arc_stbuf, fil_stbuf;
1044 int exist_tmp = 1, exist_arc = 1;
1046 len = str_safe_copy(newname, name, sizeof(newname));
1047 if (len > 0 && newname[len - 1] != '/') {
1048 if (len < sizeof(newname)-1)
1049 strcpy(&newname[len++], "/"); /* ok */
1051 warning("the length of pathname \"%s\" is too long.", name);
1054 dirp = opendir(name);
1060 if (GETSTAT(temporary_name, &tmp_stbuf) == -1)
1062 if (GETSTAT(archive_name, &arc_stbuf) == -1)
1065 while ((dp = readdir(dirp)) != NULL) {
1068 /* exclude '.' and '..' */
1069 if (strncmp(dp->d_name, ".", n) == 0
1070 || strncmp(dp->d_name, "..", n) == 0)
1073 /* exclude exclude_files supplied by user */
1074 for (i = 0; exclude_files && exclude_files[i]; i++) {
1075 if (fnmatch(exclude_files[i], dp->d_name,
1076 FNM_PATHNAME|FNM_NOESCAPE|FNM_PERIOD) == 0)
1080 if (len + n >= sizeof(newname)) {
1081 warning("filename is too long");
1085 strncpy(newname + len, dp->d_name, n);
1086 newname[len + n] = '\0';
1087 if (GETSTAT(newname, &fil_stbuf) < 0)
1090 #if defined(HAVE_STRUCT_STAT_ST_INO) && !__MINGW32__
1091 /* MinGW has meaningless st_ino */
1093 /* exclude temporary file, archive file and these links */
1095 tmp_stbuf.st_dev == fil_stbuf.st_dev &&
1096 tmp_stbuf.st_ino == fil_stbuf.st_ino)
1100 arc_stbuf.st_dev == fil_stbuf.st_dev &&
1101 arc_stbuf.st_ino == fil_stbuf.st_ino)
1104 add_sp(&sp, newname, len+n+1);
1109 finish_sp(&sp, v_filec, v_filev);
1111 qsort(*v_filev, *v_filec, sizeof(char *), sort_by_ascii);
1112 cleaning_files(v_filec, v_filev);
1117 /* ------------------------------------------------------------------------ */
1119 free_files(filec, filev)
1126 /* ------------------------------------------------------------------------ */
1128 /* ------------------------------------------------------------------------ */
1129 /* Build temporary file name and store to TEMPORARY_NAME */
1131 build_temporary_name()
1133 #ifdef TMP_FILENAME_TEMPLATE
1134 /* "/tmp/lhXXXXXX" etc. */
1135 if (extract_directory == NULL) {
1136 str_safe_copy(temporary_name, TMP_FILENAME_TEMPLATE,
1137 sizeof(temporary_name));
1140 xsnprintf(temporary_name, sizeof(temporary_name),
1141 "%s/lhXXXXXX", extract_directory);
1146 str_safe_copy(temporary_name, archive_name, sizeof(temporary_name));
1147 s = strrchr(temporary_name, '/');
1150 len = s - temporary_name;
1151 if (len + strlen("lhXXXXXX") < sizeof(temporary_name))
1152 /* use directory at archive file */
1153 strcpy(s, "lhXXXXXX"); /* ok */
1155 /* use current directory */
1156 str_safe_copy(temporary_name, "lhXXXXXX", sizeof(temporary_name));
1159 /* use current directory */
1160 str_safe_copy(temporary_name, "lhXXXXXX", sizeof(temporary_name));
1166 old_umask = umask(077);
1167 fd = mkstemp(temporary_name);
1175 mktemp(temporary_name);
1176 flags = O_CREAT|O_EXCL|O_RDWR;
1180 return open(temporary_name, flags, 0600);
1185 /* ------------------------------------------------------------------------ */
1187 modify_filename_extention(buffer, ext, size)
1192 register char *p, *dot;
1194 for (p = buffer, dot = (char *) 0; *p; p++) {
1204 str_safe_copy(p, ext, size - (p - buffer));
1207 /* ------------------------------------------------------------------------ */
1208 /* build backup file name */
1210 build_backup_name(buffer, original, size)
1215 str_safe_copy(buffer, original, size);
1216 modify_filename_extention(buffer, BACKUPNAME_EXTENTION, size); /* ".bak" */
1219 /* ------------------------------------------------------------------------ */
1221 build_standard_archive_name(buffer, original, size)
1226 str_safe_copy(buffer, original, size);
1227 modify_filename_extention(buffer, ARCHIVENAME_EXTENTION, size); /* ".lzh" */
1230 /* ------------------------------------------------------------------------ */
1232 /* ------------------------------------------------------------------------ */
1242 for (i = 0; i < cmd_filec; i++) {
1243 if (patmatch(cmd_filev[i], name, 0))
1256 if ((fp = fopen(name, mode)) == NULL)
1257 fatal_error("Cannot open file \"%s\"", name);
1262 /* ------------------------------------------------------------------------ */
1264 /* ------------------------------------------------------------------------ */
1266 open_old_archive_1(name, v_fp)
1273 if (stat(name, &stbuf) >= 0 &&
1274 is_regularfile(&stbuf) &&
1275 (fp = fopen(name, READ_BINARY)) != NULL) {
1277 archive_file_gid = stbuf.st_gid;
1278 archive_file_mode = stbuf.st_mode;
1283 archive_file_gid = -1;
1287 /* ------------------------------------------------------------------------ */
1293 static char expanded_archive_name[FILENAME_LENGTH];
1295 if (!strcmp(archive_name, "-")) {
1296 if (cmd == CMD_EXTRACT || cmd == CMD_LIST) {
1298 setmode(fileno(stdin), O_BINARY);
1305 p = strrchr(archive_name, '.');
1307 if (strcasecmp(".LZH", p) == 0
1308 || strcasecmp(".LZS", p) == 0
1309 || strcasecmp(".COM", p) == 0 /* DOS SFX */
1310 || strcasecmp(".EXE", p) == 0
1311 || strcasecmp(".X", p) == 0 /* HUMAN SFX */
1312 || strcasecmp(".BAK", p) == 0) { /* for BackUp */
1313 open_old_archive_1(archive_name, &fp);
1318 if (open_old_archive_1(archive_name, &fp))
1320 xsnprintf(expanded_archive_name, sizeof(expanded_archive_name),
1321 "%s.lzh", archive_name);
1322 if (open_old_archive_1(expanded_archive_name, &fp)) {
1323 archive_name = expanded_archive_name;
1327 * if ( (errno&0xffff)!=E_PNNF ) { archive_name =
1328 * expanded_archive_name; return NULL; }
1330 xsnprintf(expanded_archive_name, sizeof(expanded_archive_name),
1331 "%s.lzs", archive_name);
1332 if (open_old_archive_1(expanded_archive_name, &fp)) {
1333 archive_name = expanded_archive_name;
1337 * if ( (errno&0xffff)!=E_PNNF ) { archive_name =
1338 * expanded_archive_name; return NULL; }
1341 * sprintf( expanded_archive_name , "%s.lzh",archive_name);
1342 * archive_name = expanded_archive_name;
1347 /* ------------------------------------------------------------------------ */
1349 inquire(msg, name, selective)
1350 char *msg, *name, *selective;
1356 fprintf(stderr, "%s %s ", name, msg);
1359 fgets(buffer, 1024, stdin);
1361 for (p = selective; *p; p++)
1362 if (buffer[0] == *p)
1363 return p - selective;
1368 /* ------------------------------------------------------------------------ */
1370 write_archive_tail(nafp)
1376 /* ------------------------------------------------------------------------ */
1378 copy_old_one(oafp, nafp, hdr)
1383 fseeko(oafp, hdr->header_size + hdr->packed_size, SEEK_CUR);
1386 reading_filename = archive_name;
1387 writing_filename = temporary_name;
1388 copyfile(oafp, nafp, hdr->header_size + hdr->packed_size, 0, 0);