2
* $Id: arj_user.c,v 1.11 2004/06/18 16:19:37 andrew_belov Exp $
3
* ---------------------------------------------------------------------------
4
* High-level routines that perform ARJ command processing are located in this
5
* module. It may be partially inherited by ARJSFXV and ARJSFX.
11
DEBUGHDR(__FILE__) /* Debug information block */
13
/* Operating system names used in short listings. For their numerical
14
equivalents see ARJ_USER.H. */
16
static char *host_os_names[]={"MS-DOS", "PRIMOS", "UNIX", "AMIGA", "MAC-OS",
17
"OS/2", "APPLE GS", "ATARI ST", "NEXT",
18
"VAX VMS", "WIN95", "WIN32", NULL};
20
/* Binary/Text/... - type signature */
22
#if SFX_LEVEL>=ARJSFXV
23
static char type_sig[]={'B', 'T', '?', 'D', 'V', 'C', 'U'};
25
static char type_sig[]={'B', 'T', '?', 'D'};
28
/* Combined volume/extfile flags for UNIX-mode lists */
30
#if TARGET==UNIX&&SFX_LEVEL>=ARJSFXV
31
static char vfext_flags[]={' ', '>', '<', '*'};
36
#if SFX_LEVEL>=ARJSFXV
38
#define LFLAGS is_chapter?'*':' ', is_in_subdir?'+':' ', method, enc_type, vfext_flags[(is_volume?1:0)+(is_extfile?2:0)]
40
#define LFLAGS is_chapter?'*':' ', type_sig[uf_type], is_in_subdir?'+':' ', method, enc_type, is_volume?'V':' ', is_extfile?'X':' '
44
#define LFLAGS is_in_subdir?'+':' ', method, enc_type
46
#define LFLAGS type_sig[uf_type], is_in_subdir?'+':' ', method, enc_type
50
#define LMODESTR file_crc, mode_str
52
#define LMODESTR mode_str
57
#if SFX_LEVEL>=ARJSFXV
58
static char century_sig[]={' ', ' ', '1'}; /* 20th/21st/22nd centuries */
63
static char volfmt_2digit[]="%s%02d";
64
static char volfmt_3digit[]="%s%03d";
65
static char volfmt_4digit[]="%s%4d";
66
static char stub_fmt[]="%s%03d%s";
67
static char bell[]="\a";
71
static FILE_COUNT total_processed; /* Number of already processed files */
72
static unsigned long FAR *order_list; /* List of files to order */
74
static FILE_COUNT cf_num; /* Current file # */
76
static FILE_COUNT order_fcap; /* Size of order array */
77
static FILE_COUNT order_fcount; /* # of files in order array */
78
static FILE_COUNT vol_file_num;
79
static unsigned long saved_timestamp;
81
static char *arjsec_signature;
83
static char arjsec_signature[ARJSEC_SIG_MAXLEN];
85
static unsigned long first_file_offset; /* Offset of first file within arch. */
87
#if SFX_LEVEL>=ARJSFXV
89
static int is_removable; /* 1 if the current archive is on a
93
/* Since ARJSFX has totally static allocation, the cache buffers are statically
96
#if SFX_LEVEL<=ARJSFX&&!defined(NO_CACHING)
97
static char cache_buf[VBUF_SFX];
100
/* Return 1 if the given system is similar to ARJ host OS */
102
int test_host_os(int os)
106
for(i=0; friendly_systems[i]>=0; i++)
108
if(friendly_systems[i]==os)
116
/* Allocates RAM for and composes the protection filename */
118
char *form_prot_name()
121
char *result; /* Address of newly-formed buffer */
124
name_len=strlen(archive_name)+far_strlen(M_PROT_SUFFIX)+2;
125
strcpy(result=malloc_msg(name_len), archive_name);
126
name_len=split_name(result, NULL, NULL);
127
if((tmp_ptr=strchr(&result[name_len], '.'))==NULL)
128
msg_strcat(result, M_PROT_SUFFIX);
129
else if(tmp_ptr[1]=='\0')
130
msg_strcat(result, M_PROT_SUFFIX);
132
tmp_ptr[1]=M_PROT_SUFFIX[1]; /* Substitute first letter of extension
133
with the one from prot_name suffix */
139
#if SFX_LEVEL>=ARJSFXV
141
/* Checks for the occurence of the destination file, returns 1 if the file can
142
be extracted, 0 if it already exists and must be skipped */
144
int destfile_extr_validation()
146
char tmp_name[FILENAME_MAX];
150
strcpy(tmp_name, filename);
151
add_base_dir(tmp_name);
152
return(!file_exists(tmp_name));
159
/* Writes an index file entry */
161
void write_index_entry(char *prefix)
168
bytes_written=msg_fprintf(idxstream, M_IDXFMT_NP, filename);
170
bytes_written=msg_fprintf(idxstream, (strlen(prefix)>3)?M_IDXFMT_LONG:M_IDXFMT_SHORT, prefix, filename);
178
/* Outputs the listing header */
180
static void show_list_header()
185
if(verbose_display==VERBOSE_STD)
187
if(verbose_display==VERBOSE_ENH)
188
msg_cprintf(0, M_VLIST_P1);
191
msg_cprintf(0, M_VLIST_HDR);
192
msg_cprintf(0, M_VLIST_P1);
196
msg_cprintf(0, M_LIST_P1);
197
msg_cprintf(0, verbose_display?M_LIST_P2_CHAP:M_LIST_P2);
201
msg_cprintf(0, M_VLIST_HDR);
202
msg_cprintf(0, M_VLIST_P1);
205
msg_cprintf(0, M_LIST_P1);
206
msg_cprintf(0, M_LIST_P2);
208
msg_cprintf(0, M_LIST_SEPARATOR);
211
/* Picks the most favorable century character */
213
#if SFX_LEVEL>=ARJSFXV
214
static char pick_century(char *timetext)
222
if(timetext[0]=='2'&&timetext[1]=='0')
224
else if(timetext[0]=='2'&&timetext[1]=='1')
228
return(century_sig[n_centuries]);
232
if(timetext[0]=='1'||(timetext[0]=='2'&&timetext[1]=='0'&&timetext[2]<'7'))
238
#elif SFX_LEVEL>=ARJSFXV
239
if(timetext[0]=='2'&&timetext[1]=='0')
241
else if(timetext[0]=='2'&&timetext[1]=='1')
245
return(century_sig[n_centuries]);
250
/* List command itself */
252
#if SFX_LEVEL>=ARJSFXV
253
static int list_cmd(FILE_COUNT lnum, FILE_COUNT fnum)
255
static void list_cmd()
259
#if SFX_LEVEL>=ARJSFXV
260
int is_volume, is_extfile;
261
int is_chapter; /* Chapter or backup */
263
unsigned int raw_ea_size;
264
struct ext_hdr FAR *p_eh;
267
char tmp_name[FILENAME_MAX];
273
char mode_str[16]; /* ASR fix for 2.77 */
274
char *tmp_ptr; /* Either from the host_os_names list or
278
#if SFX_LEVEL>=ARJSFXV
279
if(!destfile_extr_validation())
282
#if SFX_LEVEL>=ARJSFXV
290
for(total_os=0; host_os_names[total_os]!=NULL; total_os++);
292
enc_type=(arj_flags&GARBLED_FLAG)?ext_hdr_flags+'0':' ';
293
#if SFX_LEVEL>=ARJSFXV
294
is_volume=(arj_flags&VOLUME_FLAG)?1:0;
295
is_extfile=(arj_flags&EXTFILE_FLAG)?1:0;
298
is_chapter=(total_chapters!=0&&((int)chapter_number<total_chapters||(int)ext_flags>total_chapters))?1:0;
299
#elif SFX_LEVEL==ARJSFXV
300
is_chapter=(arj_flags&BACKUP_FLAG)?1:0;
302
is_in_subdir=entry_pos>0;
303
ratio=calc_percentage(compsize, origsize);
304
total_uncompressed+=origsize;
305
total_compressed+=compsize;
306
#if SFX_LEVEL>=ARJSFXV
308
disk_space_used+=((origsize+(unsigned long)alloc_unit_size-1L)/(unsigned long)alloc_unit_size)*(unsigned long)alloc_unit_size;
310
timestamp_to_str(timetext, &ftime_stamp);
312
uf_type=(file_type==ARJT_BINARY||file_type==ARJT_TEXT||file_type==ARJT_DIR||file_type==ARJT_UXSPECIAL||file_type==ARJT_LABEL||file_type==ARJT_CHAPTER)?file_type:ARJT_COMMENT;
313
#elif SFX_LEVEL==ARJSFXV
314
uf_type=(file_type==ARJT_BINARY||file_type==ARJT_TEXT||file_type==ARJT_DIR||file_type==ARJT_UXSPECIAL||file_type==ARJT_LABEL)?file_type:ARJT_DIR;
316
uf_type=(file_type==ARJT_BINARY||file_type==ARJT_TEXT||file_type==ARJT_DIR)?file_type:ARJT_DIR;
318
/* In ARJSFX, there are no non-host OSes */
319
#if SFX_LEVEL<=ARJSFX
322
msg_strcpy(mode_str, M_EMPTY_ATTR);
324
if(test_host_os(host_os))
326
get_mode_str(mode_str, file_mode.native);
328
if(file_type==ARJT_BINARY||file_type==ARJT_TEXT)
331
mode_str[0]=tolower(type_sig[uf_type]);
335
strcpy(tmp_name, filename);
336
if((uf_type==ARJT_BINARY||uf_type==ARJT_TEXT||uf_type==ARJT_DIR||file_type==ARJT_UXSPECIAL)&&(host_os==OS_WIN95||host_os==OS_WINNT))
345
#if SFX_LEVEL>=ARJSFXV
347
if(verbose_display!=VERBOSE_ENH)
349
if(verbose_display==VERBOSE_NONE)
352
msg_cprintf(H_HL, M_LIST_NUM_FMT, fnum);
357
entry=(exclude_paths==EP_PATH)?(unsigned int)entry_pos:0;
358
msg_cprintf(H_HL, M_FILENAME_FORM, tmp_name+entry);
361
msg_cprintf(H_HL, M_FILENAME_FORM, filename);
364
if(verbose_display==VERBOSE_STD)
369
display_comment(comment);
371
msg_cprintf(0, (FMSG *)lf);
376
msg_cprintf(H_HL|H_NFMT, M_CHAPTER_LIST_FMT, (int)ext_flags, (int)chapter_number);
381
tmp_ptr=((int)host_os>=total_os)?nullstr:host_os_names[host_os];
382
msg_cprintf(H_HL|H_NFMT, M_REV_OS_FMT, (int)arj_nbr, tmp_ptr);
384
msg_cprintf(H_HL, M_VERBOSE_NAME_FMT, filename);
387
if(show_ansi_comments)
388
printf(strform, comment);
390
display_comment(comment);
392
msg_cprintf(H_HL|H_NFMT, M_REV_OS_FMT, (int)arj_nbr, host_os_names[host_os]);
397
msg_cprintf(0, (strlen(tmp_name+entry_pos)>12)?M_LONG_NAME_FMT:M_SHORT_NAME_FMT, tmp_name+entry_pos);
398
#elif SFX_LEVEL>=ARJSFXV
399
msg_cprintf(0, (strlen(filename+entry_pos)>12)?M_LONG_NAME_FMT:M_SHORT_NAME_FMT, filename+entry_pos);
401
msg_cprintf(0, (strlen(list_adapted_name)>12)?M_LONG_NAME_FMT:M_SHORT_NAME_FMT, list_adapted_name);
405
msg_cprintf(H_HL|H_NFMT, M_VERBOSE_LIST_LINE, origsize, compsize, ratio/1000, ratio%1000, pick_century(timetext), timetext+2, (int)ext_flags, (int)chapter_number, mode_str, LFLAGS);
408
#if SFX_LEVEL>=ARJSFXV
409
msg_cprintf(H_HL|H_NFMT, M_STD_LIST_LINE, origsize, compsize, ratio/1000, ratio%1000, pick_century(timetext), timetext+2, LMODESTR, LFLAGS);
411
msg_cprintf(H_HL|H_NFMT, M_STD_LIST_LINE, origsize, compsize, ratio/1000, ratio%1000, timetext+2, LMODESTR, LFLAGS);
414
if(std_list_cmd&&verbose_display==VERBOSE_ENH)
416
if((tmp_ptr=strrchr(tmp_name, '.'))==NULL)
418
msg_cprintf(H_HL|H_NFMT, M_PATH_LIST_FMT, tmp_ptr, tmp_name+entry_pos, filename);
420
msg_cprintf(0, (FMSG *)lf);
421
if(std_list_cmd&&ts_valid(atime_stamp)&&verbose_display!=VERBOSE_ENH)
423
timestamp_to_str(timetext, &atime_stamp);
424
msg_cprintf(H_HL|H_NFMT, M_ATIME_FMT, pick_century(timetext), timetext+2);
425
timestamp_to_str(timetext, &ctime_stamp);
426
msg_cprintf(H_HL|H_NFMT, M_CTIME_FMT, pick_century(timetext), timetext+2);
428
/* Report the extended headers */
429
if(std_list_cmd&&valid_ext_hdr&&!(arj_flags&VOLUME_FLAG)&&verbose_display!=VERBOSE_ENH)
431
/* UNIX special files */
432
if((p_eh=eh_lookup(eh, UXSPECIAL_ID))!=NULL)
433
uxspecial_stats(p_eh->raw, UXSTATS_LONG);
434
/* Owner (character) */
435
if((p_eh=eh_lookup(eh, OWNER_ID))!=NULL)
436
owner_stats(p_eh->raw, 1);
437
/* Owner (UID/GID). The archiving won't allow simultaneous storage of both
438
numeric and character IDs */
439
if((p_eh=eh_lookup(eh, OWNER_ID_NUM))!=NULL)
440
owner_stats(p_eh->raw, 0);
442
if((p_eh=eh_lookup(eh, EA_ID))!=NULL&&(!file_garbled||garble_enabled))
444
raw_ea=unpack_ea(p_eh);
445
raw_ea_size=get_eablk_size(raw_ea);
446
ratio=calc_percentage((unsigned long)p_eh->size, (unsigned long)raw_ea_size);
447
msg_cprintf(H_HL|H_NFMT, M_EA_LIST, raw_ea_size, p_eh->size, ratio/1000, ratio%1000, get_num_eas(raw_ea));
451
write_index_entry(nullstr);
453
#if SFX_LEVEL>=ARJSFXV
454
msg_cprintf(0, (FMSG *)lf);
457
#if SFX_LEVEL>=ARJSFXV
462
/* A simplified set of filelist routines */
464
#if SFX_LEVEL<=ARJSFX
466
/* Looks for the given fully-qualified filename in the file argument array */
468
static int f_arg_lookup(char *name)
472
for(i=0; i<sflist_args; i++)
473
if(!strcmp_os(name, sflist[i]))
478
/* Adds a new filename to the arg table if it's not present there */
480
static void add_f_arg(char *name)
484
if(f_arg_lookup(name)==0)
486
if((nptr=(char *)malloc(strlen(name)+1))==NULL)
487
error(M_OUT_OF_MEMORY);
489
sflist[sflist_args++]=nptr;
497
/* Checks if an archived file can be processed, returns 1 if yes. */
499
static int processing_validation()
507
if(file_attr_mask&TAG_WINLFN&&(host_os==OS_WIN95||host_os==OS_WINNT)&&
508
(file_type==ARJT_DIR||file_type==ARJT_UXSPECIAL||file_type==ARJT_BINARY||file_type==ARJT_TEXT))
510
if(file_attr_mask&TAG_LABEL&&file_type==ARJT_LABEL)
512
if(file_attr_mask&TAG_CHAPTER&&file_type==ARJT_CHAPTER)
514
if(file_attr_mask&TAG_DIREC&&file_type==ARJT_DIR)
516
if(file_attr_mask&TAG_UXSPECIAL&&file_type==ARJT_UXSPECIAL)
518
if(file_attr_mask&TAG_NORMAL&&(file_type==ARJT_BINARY||file_type==ARJT_TEXT))
520
if((file_mode.dos&FATTR_DIREC)!=FATTR_DIREC&&
521
(file_mode.dos&FATTR_RDONLY)!=FATTR_RDONLY&&
522
(file_mode.dos&FATTR_SYSTEM)!=FATTR_SYSTEM&&
523
(file_mode.dos&FATTR_HIDDEN)!=FATTR_HIDDEN&&
524
file_type!=ARJT_UXSPECIAL)
527
if(file_attr_mask&TAG_RDONLY&&file_mode.dos&FATTR_RDONLY)
529
if(file_attr_mask&TAG_HIDDEN&&file_mode.dos&FATTR_HIDDEN)
531
if(file_attr_mask&TAG_SYSTEM&&file_mode.dos&FATTR_SYSTEM)
533
if(file_attr_mask&TAG_ARCH&&(file_mode.dos&FATTR_ARCH)!=FATTR_ARCH)
535
if(file_attr_mask&TAG_NOT_ARCH&&file_mode.dos&FATTR_ARCH)
540
if(ts_valid(tested_ftime_newer)&&(filter_same_or_newer==TCHECK_FTIME||filter_same_or_newer==TCHECK_NDAYS))
542
if(ts_cmp(&ftime_stamp, &tested_ftime_newer)<0)
545
if(ts_valid(tested_ftime_older)&&(filter_older==TCHECK_FTIME||filter_older==TCHECK_NDAYS))
547
if(ts_cmp(&ftime_stamp, &tested_ftime_older)>=0)
551
if(ts_valid(tested_ftime_newer)&&filter_same_or_newer==TCHECK_CTIME)
553
if(ts_cmp(&ctime_stamp, &tested_ftime_newer)<0)
556
if(ts_valid(tested_ftime_older)&&filter_older==TCHECK_CTIME)
558
if(ts_cmp(&ctime_stamp, &tested_ftime_older)>=0)
562
if(ts_valid(tested_ftime_newer)&&filter_same_or_newer==TCHECK_ATIME)
564
if(ts_cmp(&atime_stamp, &tested_ftime_newer)<0)
567
if(ts_valid(tested_ftime_older)&&filter_older==TCHECK_ATIME)
569
if(ts_cmp(&atime_stamp, &tested_ftime_older)>=0)
572
entry=(add_command&&exclude_paths==EP_BASEDIR)?strlen(target_dir):0;
573
return(!flist_find(&flist_exclusion, filename+entry));
576
/* Retrieves total statistics for the archive */
578
static void get_totals()
587
for(cur_file=0; cur_file<flist_main.files; cur_file++)
589
flist_retrieve(filename, &properties, &flist_main, cur_file);
590
if(match_attrib(&properties))
591
total_size+=properties.fsize;
596
/* Basic archive processing routine */
598
static void process_archive(int cmd, int no_in_arch)
603
int update_perm; /* Update permission */
607
ts_store(&ftime_stamp, OS_SPECIAL, 0L);
610
ext_hdr_capacity=LONG_MAX; /* ASR fix 15/05/2003 */
611
while(!no_in_arch&&read_header(0, aistream, archive_name))
613
if(!modify_command&&exit_after_count&&total_processed+comment_entries+total_files-split_files>=exit_count)
615
pf_num=flist_lookup(++cf_num);
616
val_result=processing_validation();
620
if(pf_num!=0&&file_type!=ARJT_LABEL)
622
flist_retrieve(filename, &properties, &flist_main, pf_num-1);
626
msg_sprintf(misc_buf, M_QUERY_UPDATE, filename);
627
update_perm=query_action(REPLY_YES, QUERY_UPDATE, (FMSG *)misc_buf);
633
pack_rc=pack_file_stub(0, 1);
643
cfa_store(pf_num-1, FLFLAG_PROCESSED);
648
cfa_store(pf_num-1, FLFLAG_SKIPPED);
650
special_processing(CFA_NONE, aistream);
652
case ARJ_CMD_COMMENT:
653
if(pf_num&&val_result&&(!use_comment||supply_comment_file)&&!(arj_flags&EXTFILE_FLAG))
656
if(query_for_each_file)
658
msg_sprintf(misc_buf, M_QUERY_COMMENT, filename);
659
update_perm=query_action(REPLY_YES, QUERY_ARCH_OP, (FMSG *)misc_buf);
663
if(supply_comment(comment_file, filename))
667
special_processing(CFA_NONE, aistream);
670
if(pf_num&&val_result)
672
if(arcv_delete(cf_num))
675
special_processing(CFA_NONE, aistream);
677
case ARJ_CMD_FRESHEN:
679
if(pf_num&&file_type!=ARJT_LABEL)
681
flist_retrieve(filename, &properties, &flist_main, pf_num-1);
682
pack_rc=pack_file_stub(1, 1);
685
if(vol_file_num==pf_num)
690
cfa_store(vol_file_num-1, FLFLAG_PROCESSED);
697
cfa_store(pf_num-1, FLFLAG_PROCESSED);
700
special_processing(CFA_NONE, aistream);
701
cfa_store(pf_num-1, FLFLAG_SKIPPED);
704
special_processing(CFA_NONE, aistream);
708
if(pf_num!=0&&val_result)
711
if(query_for_each_file)
713
msg_sprintf(misc_buf, M_QUERY_GARBLE, filename);
714
update_perm=query_action(REPLY_YES, QUERY_ARCH_OP, (FMSG *)misc_buf);
717
sp_action=CFA_GARBLE;
719
special_processing(sp_action, aistream);
722
if(pf_num!=0&&val_result)
727
special_processing(CFA_NONE, aistream);
730
if(arj_flags&VOLUME_FLAG||arj_flags&EXTFILE_FLAG)
731
error(M_CANT_ORDER_MV);
732
if(order_fcount>=order_fcap)
735
order_fcap=flist_main.files;
736
order_fcap+=FILELIST_INCREMENT;
737
if((order_list=(unsigned long FAR *)farrealloc(order_list, order_fcap*sizeof(unsigned long)))==NULL)
738
error(M_OUT_OF_MEMORY);
742
arch_hdr_index[pf_num-1]=cur_header_pos;
743
cfa_store(pf_num-1, FLFLAG_PROCESSED);
744
order_list[order_fcount++]=0L;
747
order_list[order_fcount++]=cur_header_pos;
751
case ARJ_CMD_REMPATH:
753
if(pf_num!=0&&val_result)
756
if(query_for_each_file)
758
msg_sprintf(misc_buf, M_QUERY_GARBLE, filename);
759
update_perm=query_action(REPLY_YES, QUERY_ARCH_OP, (FMSG *)misc_buf);
762
sp_action=CFA_REMPATH;
764
special_processing(sp_action, aistream);
768
special_processing(CFA_NONE, aistream);
773
if(pf_num!=0&&val_result)
775
if(chapter_mode==CHAP_USE)
776
sp_action=CFA_MARK_EXT;
777
else if(chapter_mode==CHAP_REMOVE)
778
sp_action=CFA_UNMARK_EXT;
779
else if(garble_enabled)
780
sp_action=CFA_UNGARBLE;
782
special_processing(sp_action, aistream);
784
case ARJ_CMD_EXTR_NP:
786
if(pf_num!=0&&val_result)
789
if(query_for_each_file)
791
if(!first_vol_passed||!continued_prevvolume)
793
msg_sprintf(misc_buf, M_QUERY_EXTRACT, filename);
794
update_perm=query_action(REPLY_YES, QUERY_ARCH_OP, (FMSG *)misc_buf);
804
if(unpack_file_proc(cmd==ARJ_CMD_PRINT, cf_num))
810
tmp_tmp_filename[0]='\0';
819
if(pf_num!=0&&val_result)
821
if(list_cmd(total_files, cf_num))
827
if(pf_num!=0&&val_result)
829
if(test_archive_crc==TC_CRC_AND_CONTENTS)
830
add_base_dir(filename);
831
if(unpack_validation(cmd))
838
if(pf_num!=0&&val_result)
840
if(unpack_validation(cmd))
848
if((cmd==ARJ_CMD_ADD||cmd==ARJ_CMD_UPDATE)&&multivolume_option&&continued_nextvolume&&!no_inarch)
850
if(multivolume_option&&add_command)
851
continued_nextvolume=1;
853
/* ASR fix for v 2.76.04 - prevent phantom EAs at archive joints */
854
if(!continued_nextvolume)
862
if(cmd==ARJ_CMD_ADD||cmd==ARJ_CMD_UPDATE)
867
continued_prevvolume=0;
869
if(multivolume_option&&check_multivolume(MULTIVOLUME_INCREMENT)<MULTIVOLUME_INCREMENT)
871
if(!volume_flag_set&&vol_file_num!=0)
873
flist_retrieve(filename, &properties, &flist_main, vol_file_num-1);
874
if(pack_file_stub(0, 0)&&!volume_flag_set)
876
cfa_store(vol_file_num-1, FLFLAG_PROCESSED);
880
for(cur_file=0; !volume_flag_set&&cur_file<flist_main.files; cur_file++)
882
if(cfa_get(cur_file)==FLFLAG_TO_PROCESS)
884
flist_retrieve(filename, &properties, &flist_main, cur_file);
885
if(pack_file_stub(0, 0))
888
vol_file_num=cur_file+1;
890
cfa_store(cur_file, FLFLAG_PROCESSED);
893
cfa_store(cur_file, FLFLAG_SKIPPED);
894
if(multivolume_option&&check_multivolume(MULTIVOLUME_INCREMENT)<MULTIVOLUME_INCREMENT&&(cur_file+1)<flist_main.files)
898
if(multivolume_option&&check_multivolume(MULTIVOLUME_INCREMENT)<MULTIVOLUME_INCREMENT&&cur_file<flist_main.files)
900
#ifdef HAVE_VOL_LABELS
901
if(handle_labels&&!volume_flag_set)
904
if(multivolume_option&&check_multivolume(MULTIVOLUME_INCREMENT)<MULTIVOLUME_INCREMENT&&cur_file<flist_main.files)
906
if(total_chapters!=0&&!volume_flag_set&¤t_chapter<=CHAPTERS_MAX&&total_chapters>recent_chapter)
907
create_chapter_mark();
909
else if(cmd==ARJ_CMD_JOIN)
910
total_files+=copy_archive();
911
else if(cmd==ARJ_CMD_ORDER)
914
for(cur_file=0; cur_file<flist_main.files; cur_file++)
916
/* has been previously selected? Otherwise its "default" value is FLFLAG_TO_PROCESS :-o */
917
if(cfa_get(cur_file)==FLFLAG_PROCESSED)
919
fseek(aistream, arch_hdr_index[cur_file], SEEK_SET);
920
read_header(0, aistream, archive_name);
921
special_processing(CFA_NONE, aistream);
925
for(cur_file=0; cur_file<order_fcount; cur_file++)
927
if(order_list[cur_file]>0L)
929
fseek(aistream, order_list[cur_file], SEEK_SET);
930
read_header(0, aistream, archive_name);
931
special_processing(CFA_NONE, aistream);
935
if(total_files!=pf_num)
936
error(M_ORDER_CNT_MISMATCH);
937
msg_cprintf(0, M_FILES_REORDERED);
939
if(cmd==ARJ_CMD_COPY&&total_chapters!=0&&!volume_flag_set&&total_files!=0&&total_chapters>recent_chapter)
940
create_chapter_mark();
943
/* Some post-processing actions */
945
static void finish_processing(int cmd)
948
unsigned long cur_pos, eof_pos;
956
unsigned long free_space;
962
if(cmd==ARJ_CMD_DELETE&&total_files!=0&&file_args==1&&!strcmp_os(f_arg_array[0], all_wildcard))
964
skip_query=yes_on_all_queries||query_delete;
967
msg_sprintf(misc_buf, M_QUERY_DELETE_N_FILES, total_files);
968
if(!query_action(REPLY_YES, QUERY_DELETE_N_FILES, (FMSG *)misc_buf))
971
tmp_archive_cleanup();
972
longjmp(main_proc, 1);
976
if(cmd==ARJ_CMD_DELETE&&total_chapters!=0&¤t_chapter!=RESERVED_CHAPTER&&total_chapters>max_chapter)
977
final_header(FP_CHAPTER);
978
if(cmd==ARJ_CMD_DELETE&&!first_vol_passed&&!continued_nextvolume&&ftell(aostream)==first_file_offset)
980
msg_cprintf(H_HL|H_NFMT, M_DELETING_EMPTY_ARCH, archive_name);
981
file_close(aistream);
983
if(!no_file_activity)
985
if(file_unlink(archive_name))
986
error(M_CANT_DELETE, archive_name);
987
tmp_archive_cleanup();
990
/* ASR fix: the original didn't check for ARJ_CMD_COMMENT */
991
else if(total_files!=0||(cmd==ARJ_CMD_COMMENT&&comment_entries!=0)||create_sfx!=0)
993
fput_word(HEADER_ID, aostream);
994
fput_word(0, aostream);
996
if(!no_file_activity)
998
eof_pos=ftell(aostream);
999
if(continued_nextvolume&&add_command&&!volume_flag_set&&!force_volume_flag)
1001
final_header(FP_VOLUME);
1002
continued_nextvolume=0;
1004
if(!encryption_applied&&encryption_id!=ENCID_NONE)
1005
final_header(FP_GARBLE);
1006
if(sign_with_arjsec)
1008
msg_cprintf(0, M_WORKING);
1009
cur_pos=ftell(aostream);
1010
secured_size=cur_pos-main_hdr_offset;
1011
arjsec_offset=(unsigned long)is_registered*cur_pos;
1012
final_header(FP_SECURITY);
1013
if(create_envelope(aostream, arjsec_offset, ARJSEC_ITER))
1016
error(M_NO_ARJSEC_KEY);
1019
if(test_archive_crc)
1028
prot_blocks=arjprot_tail;
1029
fseek(aostream, 0L, SEEK_END);
1030
arjsec_offset=ftell(aostream);
1031
if(!sign_with_arjsec)
1032
final_header(FP_PROT);
1034
create_protfile(aostream, prot_blocks, 0);
1036
if(multivolume_option)
1038
fseek(aostream, 0L, SEEK_END);
1039
if(debug_enabled&&strchr(debug_opt, 'a')!=NULL&&create_index)
1041
if(msg_fprintf(idxstream, M_ARCH_SIZE, ftell(aostream), archive_name)<0)
1044
if(ftell(aostream)>volume_limit&&create_index)
1046
if(msg_fprintf(idxstream, M_VOLUME_BUG, archive_name)<0)
1050
if(ferror(aostream)||fclose(aostream)==EOF)
1053
if(test_archive_crc&&protected)
1056
if(debug_enabled&&strchr(debug_opt, 'a')!=NULL)
1058
msg_strcpy(tmp_tmp_filename, M_ARJFIXED_NAME);
1059
if(recover_file(tmp_archive_name, nullstr, tmp_tmp_filename, protected, eof_pos))
1061
msg_cprintf(H_HL, M_CANT_FIND_DAMAGE, archive_name);
1068
if(msg_fprintf(idxstream, M_AUTOPROT_DAMAGE, archive_name)<0)
1072
tmp_tmp_filename[0]='\0';
1076
if(create_sfx&&!first_vol_passed)
1078
entry=split_name(archive_name, NULL, NULL);
1079
if((ext_ptr=strchr(archive_name+entry, '.'))==NULL)
1080
msg_strcat(archive_name, M_EXE_EXT);
1081
#ifndef NULL_EXE_EXTENSION
1083
msg_strcpy(ext_ptr, M_EXE_EXT);
1088
file_close(aistream);
1090
if(!no_file_activity)
1092
if(keep_bak&&file_exists(archive_name))
1094
bak_name=(char *)malloc_msg(far_strlen(M_BAK_EXT)+strlen(archive_name)+1);
1095
strcpy(bak_name, archive_name);
1096
entry=split_name(bak_name, NULL, NULL);
1097
if((ext_ptr=strchr(bak_name+entry, '.'))==NULL)
1098
msg_strcat(bak_name, M_BAK_EXT);
1100
msg_strcpy(ext_ptr, M_BAK_EXT);
1101
file_unlink(bak_name);
1102
rename_with_check(archive_name, bak_name);
1109
if(file_exists(archive_name))
1110
if(file_unlink(archive_name))
1111
error(M_CANT_DELETE, archive_name);
1115
if(file_unlink(archive_name))
1116
error(M_CANT_DELETE, archive_name);
1121
if(!no_file_activity)
1123
if(assign_work_directory)
1125
msg_cprintf(H_HL|H_NFMT, M_COPYING_TEMP, tmp_archive_name, archive_name);
1127
if(file_copy(archive_name, tmp_archive_name, test_archive_crc))
1128
error(M_CANT_COPY_TEMP, tmp_archive_name, archive_name);
1130
if(file_unlink(tmp_archive_name))
1131
error(M_CANT_DELETE, archive_name);
1134
rename_with_check(tmp_archive_name, archive_name);
1135
if(create_sfx&&!first_vol_passed)
1136
msg_cprintf(0, M_SFX_CREATED);
1138
tmp_archive_name[0]='\0';
1142
fput_word(HEADER_ID, aostream);
1143
fput_word(0, aostream);
1145
if(!no_file_activity&&delete_processed&&add_command&&test_archive_crc)
1147
for(cur_file=0; cur_file<flist_main.files; cur_file++)
1148
if(cfa_get(cur_file)==FLFLAG_PROCESSED)
1150
if(cur_file<flist_main.files)
1156
file_close(aistream);
1158
tmp_archive_cleanup();
1159
if(continued_nextvolume&&!volume_flag_set&&no_inarch)
1160
continued_nextvolume=0;
1163
if(create_index&&(cmd==ARJ_CMD_ADD||cmd==ARJ_CMD_UPDATE))
1167
if(continued_nextvolume&&volume_flag_set)
1169
vol_code=continued_prevvolume;
1170
far_strcpy((char FAR *)filename, tmp_filename);
1172
if(msg_fprintf(idxstream, M_NEXT_VOLUME_STATS, volume_number, vol_code, resume_position, filename)<0)
1175
if(cmd==ARJ_CMD_ADD||cmd==ARJ_CMD_FRESHEN||cmd==ARJ_CMD_UPDATE||cmd==ARJ_CMD_JOIN)
1177
if(filter_fa_arch==FAA_BACKUP_CLEAR||filter_fa_arch==FAA_CLEAR)
1178
group_clear_arch(&flist_main);
1179
if(delete_processed)
1180
delete_processed_files(&flist_main);
1182
total_processed+=total_files+comment_entries;
1183
av_compressed+=total_compressed;
1184
av_uncompressed+=total_uncompressed;
1185
av_total_files+=total_files;
1186
av_total_longnames+=total_longnames;
1187
if(quiet_mode==ARJ_QUIET2)
1189
/* Now produce statistics for each command individually */
1190
if(cmd==ARJ_CMD_LIST)
1192
if(!std_list_cmd||verbose_display!=VERBOSE_ENH)
1194
if(total_files==0||(std_list_cmd&&verbose_display==VERBOSE_STD))
1196
if(total_longnames==0)
1197
msg_cprintf(H_HL|H_NFMT, M_N_FILES, total_files);
1199
msg_cprintf(H_HL|H_NFMT, M_N_FILES_LFN, total_files, total_longnames);
1200
if(total_chapters!=0)
1202
msg_cprintf(0, M_CHAPTERS_ON);
1203
msg_cprintf(0, (FMSG *)lf);
1208
msg_cprintf(0, M_BRIEF_LIST_SEPARATOR);
1209
if(total_chapters!=0)
1211
msg_strcpy(strcpy_buf, M_CHAPTERS_ON);
1216
ratio=calc_percentage(total_compressed, total_uncompressed);
1217
if(total_longnames==0)
1218
msg_cprintf(H_HL|H_NFMT, M_TOTAL_STATS, total_files, total_uncompressed, total_compressed, ratio/1000, ratio%1000, msg_ptr);
1220
msg_cprintf(H_HL|H_NFMT, M_TOTAL_STATS_LFN, total_files, total_uncompressed, total_compressed, ratio/1000, ratio%1000, msg_ptr, total_longnames);
1221
if(av_total_files>total_files)
1223
ratio=calc_percentage(av_compressed, av_uncompressed);
1224
if(total_longnames==0)
1225
msg_cprintf(H_HL|H_NFMT, M_TOTAL_STATS, av_total_files, av_uncompressed, av_compressed, ratio/1000, ratio%1000, nullstr);
1227
msg_cprintf(H_HL|H_NFMT, M_TOTAL_STATS_LFN, av_total_files, av_uncompressed, av_compressed, ratio/1000, ratio%1000, nullstr, av_total_longnames);
1233
free_space=file_getfree(target_dir);
1234
if(disk_space_used+minfree>free_space)
1236
msg_cprintf(H_ALERT, M_NOT_ENOUGH_SPACE_X, disk_space_used+minfree-free_space);
1241
else if(cmd==ARJ_CMD_PRINT)
1244
msg_cprintf(H_HL|H_NFMT, M_N_FILES, total_files);
1246
else if(cmd==ARJ_CMD_COMMENT)
1247
msg_cprintf(H_HL|H_NFMT, M_N_COMMENTS, comment_entries);
1248
else if(cmd==ARJ_CMD_ADD||cmd==ARJ_CMD_FRESHEN||cmd==ARJ_CMD_UPDATE)
1252
if(total_longnames==0)
1253
msg_cprintf(H_HL|H_NFMT, M_N_FILES, total_files);
1255
msg_cprintf(H_HL|H_NFMT, M_N_FILES_LFN, total_files, total_longnames);
1259
if(verbose_display==VERBOSE_STD)
1261
msg_cprintf(0, M_FINAL_FOOTER);
1262
ratio=calc_percentage(total_compressed, total_uncompressed);
1263
msg_cprintf(H_HL|H_NFMT, M_VERBOSE_FOOTER, total_files, total_uncompressed, total_compressed, ratio/10, ratio%10);
1264
if(total_files<av_total_files)
1266
ratio=calc_percentage(av_compressed, av_uncompressed);
1267
msg_cprintf(H_HL|H_NFMT, M_VERBOSE_FOOTER, av_total_files, av_uncompressed, av_compressed, ratio/10, ratio%10);
1272
if(total_longnames==0)
1273
msg_cprintf(H_HL|H_NFMT, M_N_FILES, total_files);
1275
msg_cprintf(H_HL|H_NFMT, M_N_FILES_LFN, total_files, total_longnames);
1278
if(comment_entries!=0)
1279
msg_cprintf(H_HL|H_NFMT, M_N_COMMENTS, comment_entries);
1281
else if(cmd==ARJ_CMD_TEST&&total_files!=0&&errors==0&&(protfile_option||arjprot_tail||security_state==ARJSEC_SIGNED))
1283
eof_pos=ftell(aistream);
1284
fseek(aistream, 0L, SEEK_END);
1285
arjsec_offset=ftell(aistream);
1286
is_prot=(security_state==ARJSEC_SIGNED&&chk_prot_sig(aistream, eof_pos))?1:0;
1287
file_close(aistream);
1289
if(arjprot_tail||is_prot)
1292
if(debug_enabled&&strchr(debug_opt, 'a')!=NULL)
1294
if(recover_file(archive_name, nullstr, nullstr, protected, eof_pos))
1296
msg_cprintf(H_HL, M_CANT_FIND_DAMAGE, archive_name);
1303
if(msg_fprintf(idxstream, M_AUTOPROT_DAMAGE, archive_name)<0)
1308
if(protfile_option&&protected)
1310
arjprot_tail=protfile_option;
1312
prot_blocks=protfile_option;
1313
if((aostream=file_open(archive_name, m_rbp))==NULL)
1314
error(M_CANTOPEN, archive_name);
1315
if(security_state==ARJSEC_NONE)
1316
final_header(FP_PROT);
1317
create_protfile(aostream, prot_blocks, 0);
1318
file_close(aostream);
1324
if(cmd==ARJ_CMD_COPY&&chapter_mode)
1326
if(chapter_mode==CHAP_USE)
1327
msg_cprintf(0, M_CHAPTERS_ON);
1328
else if(chapter_mode==CHAP_REMOVE)
1329
msg_cprintf(0, M_CHAPTERS_OFF);
1330
msg_cprintf(0, strform, lf);
1332
if(cmd==ARJ_CMD_COPY&&protfile_option&&!arjprot_tail)
1333
msg_cprintf(0, M_ARJPROT_DISABLED);
1334
msg_cprintf(H_HL|H_NFMT, M_N_FILES, total_files);
1335
if(comment_entries>0)
1336
msg_cprintf(H_HL|H_NFMT, M_N_COMMENTS, comment_entries);
1338
if(security_state==ARJSEC_SIGNED&&arjsec_opt!=ARJSECP_SKIP)
1340
msg_cprintf(H_HL|H_NFMT, M_VALID_ARJSEC, arjsec_signature);
1341
msg_strcpy(strcpy_buf, M_SDN_1);
1342
if(strstr(arjsec_signature, strcpy_buf)!=NULL)
1344
msg_cprintf(0, M_SDN_ADD_DESC);
1345
msg_cprintf(0, M_SDN_SECURITY_TEST);
1347
msg_strcpy(strcpy_buf, M_SDN_2);
1348
if(strstr(arjsec_signature, strcpy_buf)!=NULL)
1350
msg_cprintf(0, M_SDN_DIST_DESC);
1351
msg_cprintf(0, M_SDN_SECURITY_TEST);
1354
file_close(aistream);
1357
msg_cprintf(0, M_ARJPROT_ENABLED, prot_blocks);
1358
if(arjsec_signature!=NULL)
1360
free(arjsec_signature);
1361
arjsec_signature=NULL;
1363
if(((modify_command&×tamp_override==ATO_SAVE_ARCHIVE)||
1364
timestamp_override==ATO_NEWEST)&&ts_valid(ftime_max))
1365
file_setftime(archive_name, ts_native(&ftime_max, OS));
1366
else if((timestamp_override==ATO_SAVE_ORIGINAL||timestamp_override==ATO_SAVE_BOTH)&&saved_timestamp!=0L)
1367
file_setftime(archive_name, saved_timestamp);
1368
if(modify_command&&file_is_removable(archive_name))
1369
reset_drive(archive_name);
1370
if(!modify_command&&total_processed==0&&!continued_nextvolume)
1372
if(errorlevel==ARJ_ERL_SUCCESS)
1373
errorlevel=ARJ_ERL_WARNING;
1376
total_processed-=split_files;
1377
av_total_files-=split_files;
1378
av_total_longnames-=split_longnames;
1383
/* Changes SFX executable name (for -ve) */
1385
#if SFX_LEVEL>=ARJSFXV
1386
static char *iterate_sfxname()
1392
for(l=strlen(archive_name); l>0; l--)
1394
if(archive_name[l]=='.')
1399
p=(l>0)?(archive_name+l):nullstr;
1411
tmp_str=malloc_str(archive_name);
1413
sprintf(archive_name, stub_fmt, tmp_str, volume_number, p);
1420
/* Mangles the filename so it can be transformed to an aesthetic SFX name.
1421
ASR fix 26/08/2001 for UNIX. */
1423
#if SFX_LEVEL>=ARJSFXV
1424
static void fix_sfx_name()
1426
#ifdef NULL_EXE_EXTENSION
1428
static char exe_append[]=".exe";
1430
if(!first_vol_passed)
1432
digit_pos=strrchr(archive_name, PATHSEP_DEFAULT);
1434
digit_pos=archive_name;
1435
digit_pos=strchr(digit_pos, '.');
1436
if(digit_pos==NULL) /* "test" -> "test.exe" */
1437
strcat(archive_name, exe_append);
1438
else if(strlen(digit_pos)<3) /* ".xx" -> ".01" */
1439
strcpy(digit_pos, exe_append);
1444
/* Extended archive processing routine. A non-zero return value indicates
1445
that processing of further volumes must be omitted. */
1448
static int process_archive_proc(int cmd)
1450
struct timestamp tmp_time;
1451
static unsigned int t_buf, v_buf;
1454
int encryption_version;
1456
int filename_length;
1457
unsigned long avail_space;
1466
unsigned long arch_size;
1467
unsigned int desc_word, reg_id; /* SFX */
1472
arjsec_signature=NULL;
1474
main_hdr_offset=last_hdr_offset=0L;
1477
total_files=total_longnames=0;
1479
security_state=ARJSEC_NONE;
1481
total_uncompressed=0L;
1482
total_compressed=0L;
1484
ts_store(&ftime_max, OS_SPECIAL, 0L);
1487
encryption_applied=0;
1491
if(!setjmp(main_proc))
1493
set_file_apis(use_ansi_cp);
1494
v_buf=add_command?VBUF_ADD:VBUF_EXTRACT;
1496
if(coreleft()<TBUF_MINFREE)
1498
if(coreleft()<VBUF_MINFREE)
1500
if((tmp_ptr=strchr(debug_opt, 'b'))!=NULL)
1503
v_buf=(int)strtol(tmp_ptr, &tmp_ptr, 10);
1505
if((tmp_ptr=strchr(debug_opt, 'p'))!=NULL)
1508
t_buf=(int)strtol(tmp_ptr, &tmp_ptr, 10);
1510
if((tmp_ptr=strchr(debug_opt, 'v'))!=NULL)
1511
msg_cprintf(H_HL|H_NFMT, M_BRIEF_MEMSTATS, coreleft(), t_buf, v_buf);
1513
alloc_unit_size=get_bytes_per_cluster(target_dir);
1514
ts_store(&ftime_stamp, OS_SPECIAL, 0L);
1515
first_hdr_size=FIRST_HDR_SIZE;
1516
if(multivolume_option)
1519
digit_pos=iterate_sfxname();
1523
tmp_ptr=volfmt_2digit;
1525
filename_length=strlen(archive_name)-vol_num_digits;
1526
if(volume_number>99||isdigit(archive_name[filename_length-1]))
1529
tmp_ptr=volfmt_3digit;
1531
if(volume_number>999&&lfn_supported)
1533
if(volume_number>1000)
1535
tmp_ptr=volfmt_4digit;
1537
else if(volume_number>999)
1542
vol_name_fmt=malloc_str(archive_name);
1543
vol_name_fmt[filename_length]='\0';
1544
sprintf(archive_name, tmp_ptr, vol_name_fmt, volume_number);
1547
digit_pos=archive_name+filename_length;
1549
continued_nextvolume=1;
1554
avail_space=file_getfree(archive_name);
1556
if(assign_work_directory&&file_exists(archive_name))
1558
arch_size=file_getfsize(archive_name);
1559
if(file_getfree(work_directory)<(avail_space+arch_size)*2)
1561
avail_space+=arch_size;
1563
if(multivolume_option==MV_AVAIL)
1564
volume_limit=avail_space;
1565
if(debug_enabled&&strchr(debug_opt, 'v')!=NULL)
1566
msg_cprintf(H_HL|H_NFMT, M_AVAIL_SPACE, avail_space);
1567
if(avail_space<MIN_VOLUME_SIZE)
1569
msg_cprintf(H_HL|H_NFMT, M_FILENAME_FORM, archive_name);
1570
if(!yes_on_all_queries&&!skip_space_query)
1572
msg_cprintf(H_ALERT, M_NOT_ENOUGH_SPACE_V);
1576
error(M_NOT_ENOUGH_SPACE_V);
1578
if(volume_limit>avail_space)
1580
if(!yes_on_all_queries&&!skip_space_query)
1582
msg_cprintf(H_HL|H_NFMT, M_FILENAME_FORM, archive_name);
1583
msg_sprintf(misc_buf, M_LOW_SPACE_WARNING, avail_space);
1584
if(!query_action(REPLY_YES, QUERY_LOW_SPACE, (FMSG *)misc_buf))
1588
} while((arch_size+avail_space)!=file_getfree(archive_name));
1593
if(file_exists(archive_name))
1597
saved_timestamp=file_getftime(archive_name);
1598
aistream=file_open_noarch(archive_name, m_rbp);
1601
aistream=file_open(archive_name, m_rb);
1602
fseek(aistream, arcv_ext_pos, SEEK_SET);
1606
if(aistream==NULL&&msg_strchr(M_UPDATE_COMMANDS, (char)cmd)==NULL)
1608
if(multivolume_option&&!yes_on_all_queries&&!skip_next_vol_query)
1611
msg_cprintf(H_ERR, M_CANTOPEN, archive_name);
1616
error(M_CANTOPEN, archive_name);
1620
cur_time_stamp(&tmp_time);
1621
timestamp_to_str(timetext, &tmp_time);
1622
if(msg_fprintf(idxstream, M_IDX_VOLUME_HEADER, timetext, resume_position, archive_name)<0)
1629
setvbuf(aistream, NULL, _IOFBF, v_buf);
1634
msg_cprintf(H_HL|H_NFMT, M_PROCESSING_ARCHIVE, archive_name);
1637
if(!tmp_archive_name)
1639
tmp_archive_used=-1;
1640
tmp_archive_name=(char *)malloc_msg(FILENAME_MAX);
1641
tmp_archive_name[0]='\0';
1646
if(!first_vol_passed)
1648
sfx_name=malloc_msg(filename_length=strlen(archive_name)+far_strlen(M_EXE_EXT)+1);
1649
strcpy(sfx_name, archive_name);
1650
entry=split_name(sfx_name, NULL, NULL);
1651
if((tmp_ptr=strchr(sfx_name+entry, '.'))==NULL)
1652
msg_strcat(sfx_name, M_EXE_EXT);
1653
#ifndef NULL_EXE_EXTENSION
1655
msg_strcpy(tmp_ptr, M_EXE_EXT);
1657
if(file_exists(sfx_name))
1659
query_result=yes_on_all_queries||overwrite_existing;
1662
msg_cprintf(H_HL|H_NFMT, M_EXISTS, sfx_name);
1663
msg_sprintf(misc_buf, M_QUERY_UPDATE, sfx_name);
1664
query_result=query_action(REPLY_YES, QUERY_OVERWRITE, (FMSG *)misc_buf);
1666
if(!query_result||(stricmp(archive_name, sfx_name)&&file_unlink(sfx_name)))
1667
error(M_CANT_DELETE, sfx_name);
1669
msg_cprintf(H_HL|H_NFMT, M_CREATING_SFX, sfx_name);
1674
msg_cprintf(H_HL|H_NFMT, (aistream==NULL)?M_CREATING_ARCHIVE:M_UPDATING_ARCHIVE, archive_name);
1675
if(!no_file_activity)
1679
aostream=file_open_noarch(archive_name, m_wb);
1680
file_close(aostream);
1682
file_unlink(archive_name);
1684
tmp_archive_used=-1;
1685
if(assign_work_directory)
1687
strcpy(tmp_archive_name, work_directory);
1688
add_pathsep(tmp_archive_name);
1691
split_name(archive_name, tmp_archive_name, NULL);
1692
strcat(tmp_archive_name, arjtemp_spec);
1693
find_tmp_filename(tmp_archive_name);
1694
aostream=file_open_noarch(tmp_archive_name, m_wbp);
1697
setvbuf(aostream, NULL, _IOFBF, t_buf);
1699
avail_space=file_getfree(tmp_archive_name);
1700
if(volume_limit>avail_space)
1702
if(!yes_on_all_queries&&!skip_space_query)
1704
msg_cprintf(H_HL|H_NFMT, M_FILENAME_FORM, tmp_archive_name);
1705
msg_sprintf(misc_buf, M_LOW_SPACE_WARNING, avail_space);
1706
if(!query_action(REPLY_YES, QUERY_LOW_SPACE, (FMSG *)misc_buf))
1708
tmp_archive_cleanup();
1713
if(create_sfx==SFXCRT_SFX&&multivolume_option)
1715
if(!first_vol_passed)
1721
else if(create_sfx==SFXCRT_SFX)
1723
else if(create_sfx==SFXCRT_SFXJR)
1725
/* Adjust the privileges on UNIX platforms */
1729
if(create_sfx==SFXCRT_SFX&&multivolume_option&&first_vol_passed&&!use_sfxstub)
1730
make_nonexecutable(aostream);
1732
make_executable(aostream);
1735
make_nonexecutable(aostream);
1743
fill_archive_header();
1744
if(win32_platform&&use_ansi_cp)
1745
msg_cprintf(0, M_ANSI_CP_ARCHIVE);
1749
if((main_hdr_offset=find_header(0, aistream))<0L)
1751
msg_cprintf(H_ALERT, M_NOT_ARJ_ARCHIVE, archive_name);
1752
msg_cprintf(0, (FMSG *)lf);
1753
file_close(aistream);
1755
if(errorlevel==ARJ_ERL_SUCCESS)
1756
errorlevel=ARJ_ERL_NOT_ARJ_ARCHIVE;
1758
tmp_archive_cleanup();
1759
return(ARJ_ERL_NOT_ARJ_ARCHIVE);
1761
if(main_hdr_offset==0L&&modify_command&&create_sfx)
1762
copy_bytes(main_hdr_offset);
1763
if(main_hdr_offset>EXESIZE_MINSFX)
1765
fseek(aistream, main_hdr_offset, SEEK_SET);
1766
fseek(aistream, -8L, SEEK_CUR);
1767
desc_word=fget_word(aistream);
1768
reg_id=fget_word(aistream);
1769
sfx_desc_word=desc_word;
1770
/* Perform a simple integrity check */
1771
if(reg_id!=REG_ID&®_id!=UNREG_ID)
1772
sfx_desc_word=SFXDESC_NONSFX;
1773
if(sfx_desc_word<SFXDESC_MIN||sfx_desc_word>SFXDESC_MAX)
1774
sfx_desc_word=SFXDESC_NONSFX;
1776
fseek(aistream, main_hdr_offset, SEEK_SET);
1777
if(!read_header(1, aistream, archive_name))
1778
error(M_INVALID_COMMENT_HDR);
1780
digit_pos=iterate_sfxname();
1781
if(modify_command&&continued_nextvolume&&!multivolume_option)
1783
msg_cprintf(0, M_MV_UPDATE_REQ_SW);
1784
file_close(aistream);
1787
tmp_archive_cleanup();
1790
if(modify_command&&(cmd==ARJ_CMD_GARBLE||garble_enabled))
1792
if(arj_nbr>=ARJ_NEWCRYPT_VERSION&&ext_hdr_flags==0&&!encryption_applied)
1794
ext_hdr_flags=ENCRYPT_STD;
1795
if(gost_cipher==GOST256)
1796
ext_hdr_flags=ENCRYPT_UNK;
1797
else if(gost_cipher==GOST40)
1798
ext_hdr_flags=ENCRYPT_GOST40;
1802
if((gost_cipher!=GOST256||(ext_hdr_flags!=ENCRYPT_GOST256&&ext_hdr_flags!=ENCRYPT_GOST256L))&&
1803
(gost_cipher!=GOST40||ext_hdr_flags!=ENCRYPT_GOST40)&&
1804
gost_cipher!=GOST_NONE)
1805
error(M_WRONG_ENC_VERSION, 0);
1808
if(!win32_platform&&create_sfx&&!multivolume_option&&ext_hdr_flags>=ENCRYPT_STD)
1809
error(M_BAD_SYNTAX);
1810
if(cmd!=ARJ_CMD_COPY&&chapter_mode&&total_chapters==0)
1811
error(M_NOT_A_CHAPTER_ARCH);
1812
if(cmd==ARJ_CMD_DELETE&&delete_processed==DP_EXTRACT&&total_chapters!=0)
1813
error(M_BAD_SYNTAX);
1814
if(cmd==ARJ_CMD_DELETE&¤t_chapter==RESERVED_CHAPTER&&total_chapters==0)
1815
error(M_NOT_A_CHAPTER_ARCH);
1816
if(arjsec_opt==ARJSECP_SET_ERROR&&arj_flags&SECURED_FLAG)
1817
error(M_SKIPPING_SEC);
1818
if(protfile_option&&(multivolume_option||continued_nextvolume)&&
1819
!arjprot_tail&&is_removable)
1820
error(M_ARJPROT_REJECTED);
1821
timestamp_to_str(timetext, &ftime_stamp);
1822
msg_cprintf(H_HL|H_NFMT, M_ARCHIVE_CREATED, timetext);
1823
if(arj_nbr>=ARJ_M_VERSION)
1825
ts_store(&tmp_time, host_os, compsize);
1826
timestamp_to_str(timetext, &tmp_time);
1827
msg_cprintf(H_HL|H_NFMT, M_MODIFIED, timetext);
1828
if(total_chapters!=0)
1829
msg_cprintf(H_HL, M_CHAPTER_NUMBER, total_chapters);
1831
msg_cprintf(0, (FMSG *)lf);
1832
if((!modify_command||!use_comment)&&(cmd!=ARJ_CMD_COMMENT||supply_comment_file))
1834
if((cmd!=ARJ_CMD_LIST||!std_list_cmd||verbose_display!=VERBOSE_ENH)&&comment_display!=CMTD_NONE)
1835
display_comment(comment);
1837
set_file_apis(ansi_codepage);
1840
msg_cprintf(0, M_ANSI_CP_ARCHIVE);
1842
if(cmd==ARJ_CMD_EXTR_NP&&!use_ansi_cp)
1843
error(M_REQUIRES_ARJ32);
1846
if(cmd==ARJ_CMD_LIST&&debug_enabled&&strchr(debug_opt, 'l')!=NULL)
1847
msg_cprintf(H_HL|H_NFMT, M_ENCRYPT_VALUE, ext_hdr_flags);
1849
if(multivolume_option)
1850
volume_number=strtol(digit_pos, &digit_pos, 10)+1;
1853
main_hdr_offset=ftell(aostream);
1856
msg_cprintf(0, M_CANT_UPDATE_SEC);
1857
msg_cprintf(0, (FMSG *)lf);
1858
file_close(aistream);
1861
errorlevel=ARJ_ERL_ARJSEC_ERROR;
1862
tmp_archive_cleanup();
1865
if(timestamp_override!=ATO_SAVE_BOTH)
1867
cur_time_stamp(&tmp_time);
1868
compsize=ts_native(&tmp_time, host_os);
1870
if(ts_valid(secondary_ftime))
1871
compsize=ts_native(&secondary_ftime, host_os); /* Archive modification time */
1874
encryption_version=garble_init(0);
1875
if(ext_hdr_flags==ENCRYPT_UNK)
1876
ext_hdr_flags=encryption_version;
1877
if(ext_hdr_flags!=0&&encryption_version!=ext_hdr_flags)
1878
error(M_WRONG_ENC_VERSION, ext_hdr_flags);
1880
ext_flags=ext_hdr_flags;
1883
arjprot_tail=protfile_option;
1885
prot_blocks=arjprot_tail%256; /* v 2.75+ - %'ing is pointless! */
1887
if(sfx_desc_word!=SFXDESC_NONSFX)
1890
error(M_CHAPTER_SFX_CREATION);
1891
if(custom_method==5||method_specifier==4)
1892
error(M_INVALID_METHOD_SFX);
1893
if(sfx_desc_word<=SFXDESC_SFX&&multivolume_option)
1894
error(M_BAD_SYNTAX);
1895
/* Skip check for EAs - an existing archive may contain them but
1896
they are harmless! */
1897
if(sfx_desc_word==SFXDESC_SFXJR&&(type_override||lfn_supported!=LFN_NOT_SUPPORTED))
1898
error(M_TEXTMODE_LFN_SFXJR);
1899
if(sfx_desc_word==SFXDESC_SFXJR&&garble_enabled)
1900
error(M_NO_GARBLE_IN_SFXJR);
1901
if(sfx_desc_word==SFXDESC_SFX&&ext_hdr_flags>ENCRYPT_STD)
1902
error(M_WRONG_ENC_VERSION, ext_hdr_flags);
1904
if(cmd==ARJ_CMD_COPY)
1906
if(chapter_mode==CHAP_USE&&total_chapters!=0&&!multivolume_option)
1907
error(M_ALREADY_CHAPTER_ARCH);
1908
if(chapter_mode==CHAP_REMOVE&&total_chapters==0)
1909
error(M_NOT_A_CHAPTER_ARCH);
1910
if(chapter_mode==CHAP_USE&&total_chapters==0)
1914
current_chapter=HIGHEST_CHAPTER;
1917
else if(chapter_mode==CHAP_REMOVE&&total_chapters!=0)
1921
current_chapter=HIGHEST_CHAPTER;
1927
arj_flags&=~GARBLED_FLAG;
1928
if(!test_archive_crc)
1929
test_archive_crc=TC_ARCHIVE;
1931
if(use_ansi_cp==ANSICP_SKIP)
1933
if(arj_nbr==ARJ_ANSI_VERSION||arj_flags&ANSICP_FLAG)
1935
msg_cprintf(H_ALERT, M_NOT_OEM_CP_ARCHIVE);
1936
file_close(aistream);
1939
errorlevel=ARJ_ERL_WARNING;
1940
tmp_archive_cleanup();
1943
arj_flags|=ANSICP_FLAG;
1950
arj_flags&=~PROT_FLAG;
1954
if(add_command&&multivolume_option)
1955
arj_flags|=VOLUME_FLAG;
1956
if(arj_flags&DUAL_NAME_FLAG)
1958
if(add_command&&!dual_name&&(lfn_mode==LFN_DUAL||lfn_mode==LFN_DUAL_EXT))
1959
error(M_CANT_CNV_TO_DUAL_N);
1960
if(arj_flags&ANSICP_FLAG)
1962
if(add_command&&!ansi_codepage&&use_ansi_cp==ANSICP_CONVERT)
1963
error(M_ARCHIVE_CP_MISMATCH);
1964
if(!win32_platform&&ansi_codepage)
1965
error(M_ARCHIVE_CP_MISMATCH);
1967
if((cmd==ARJ_CMD_COMMENT&&!supply_comment_file)||use_comment)
1969
if(supply_comment(archive_cmt_name, archive_name))
1973
first_file_offset=ftell(aostream);
1977
first_file_offset=ftell(aistream);
1978
if(security_state&&arjsec_opt!=ARJSECP_SKIP)
1980
if(method>ARJSEC_VERSION)
1982
msg_cprintf(H_HL|H_NFMT, M_CANT_HANDLE_ARJSEC_V, method);
1983
msg_cprintf(0, (FMSG *)misc_buf);
1987
msg_cprintf(0, M_VERIFYING_ARJSEC);
1988
if(arjsec_signature==NULL)
1989
arjsec_signature=(char *)malloc_msg(ARJSEC_SIG_MAXLEN+1);
1990
if(get_arjsec_signature(aistream, arjsec_offset, arjsec_signature, ARJSEC_ITER))
1993
msg_cprintf(0, M_DAMAGED_SEC_ARCHIVE);
1999
msg_cprintf(0, M_VALID_ENVELOPE);
2000
fseek(aistream, first_file_offset, SEEK_SET);
2001
security_state=ARJSEC_SIGNED;
2006
encryption_version=garble_init(0);
2007
if((encryption_version!=ENCRYPT_GOST256&&encryption_version!=ENCRYPT_GOST256L)||
2008
(ext_hdr_flags!=ENCRYPT_GOST256&&ext_hdr_flags!=ENCRYPT_GOST256L))
2010
if(ext_hdr_flags!=0&&encryption_version!=ext_hdr_flags)
2011
error(M_WRONG_ENC_VERSION, encryption_version);
2014
if(test_archive_crc==TC_ARCHIVE)
2016
cmd_verb=ARJ_CMD_TEST;
2017
while(read_header(0, aistream, archive_name))
2018
unpack_validation(ARJ_CMD_TEST);
2021
error(M_FOUND_N_ERRORS, errors);
2022
fseek(aistream, first_file_offset, SEEK_SET);
2024
if(cmd==ARJ_CMD_EXTR_NP&&use_comment&&archive_cmt_name[0]!='\0')
2026
msg_cprintf(H_HL|H_NFMT, M_EXTRACTING_CMT_TO_F, archive_cmt_name);
2027
cmtstream=file_create(archive_cmt_name, m_w);
2028
if(hdr_comment[0]=='\0')
2030
msg_strcpy(strcpy_buf, M_EMPTY_COMMENT);
2031
if(fputs(strcpy_buf, cmtstream)==EOF)
2036
cmt_len=strlen(hdr_comment);
2037
if(fwrite(hdr_comment, 1, cmt_len, cmtstream)!=cmt_len)
2044
if((tmp_ptr=strchr(debug_opt, 'v'))!=NULL)
2045
msg_cprintf(H_HL|H_NFMT, M_BRIEF_MEMSTATS, coreleft(), t_buf, v_buf);
2046
/* The main part of the whole routine */
2047
process_archive(cmd, no_input);
2048
finish_processing(cmd);
2050
if(order_list!=NULL)
2052
farfree(order_list);
2055
file_close(aistream);
2060
#elif SFX_LEVEL<=ARJSFXV /* Simplified routine for ARJSFXV */
2062
#if SFX_LEVEL>=ARJSFXV
2065
void process_archive()
2072
#if SFX_LEVEL>=ARJSFXV
2073
struct timestamp tmp_time;
2074
static unsigned int t_buf, v_buf;
2075
char *tmp_ptr, *msg_ptr;
2079
int filename_length;
2083
unsigned long free_space;
2084
unsigned int cf_num;
2088
char tmp_name[FILENAME_MAX];
2091
#if SFX_LEVEL>=ARJSFXV
2094
main_hdr_offset=last_hdr_offset=0L;
2097
security_state=ARJSEC_NONE;
2101
total_uncompressed=0L;
2102
total_compressed=0L;
2104
ts_store(&ftime_max, OS, 0L);
2105
ts_store(&ftime_stamp, OS_SPECIAL, 0L);
2110
first_hdr_size=STD_HDR_SIZE;
2111
for(total_os=0; host_os_names[total_os]!=NULL; total_os++);
2113
if((tmp_ptr=strchr(debug_opt, 'b'))!=NULL)
2116
v_buf=(int)strtol(tmp_ptr, &tmp_ptr, 10);
2119
if((tmp_ptr=strchr(debug_opt, 'p'))!=NULL)
2122
t_buf=(int)strtol(tmp_ptr, &tmp_ptr, 10);
2124
if(multivolume_option)
2127
digit_pos=iterate_sfxname();
2131
tmp_ptr=volfmt_2digit;
2132
if(volume_number>99)
2135
tmp_ptr=volfmt_3digit;
2137
if(volume_number>1000) /* ASR fix 20/10/2000 */
2140
tmp_ptr=volfmt_4digit;
2143
filename_length=strlen(archive_name)-vol_num_digits;
2146
vol_name_fmt=malloc_str(archive_name);
2147
vol_name_fmt[filename_length]='\0';
2148
sprintf(archive_name, tmp_ptr, vol_name_fmt, volume_number);
2151
digit_pos=archive_name+filename_length;
2153
continued_nextvolume=1;
2156
aistream=file_open(archive_name, m_rb);
2160
if(multivolume_option&&!yes_on_all_queries&&!skip_next_vol_query)
2163
msg_cprintf(H_ERR, M_CANTOPEN, archive_name);
2164
msg_cprintf(0, (FMSG *)lf);
2168
error(M_CANTOPEN, archive_name);
2171
/* ARJSFX initialization... quite short */
2172
#if SFX_LEVEL<=ARJSFX
2173
/* Set up ARJ$DISP screen if needed */
2176
cmd_verb=ARJDISP_CMD_START;
2179
uncompsize=compsize=0L;
2180
display_indicator(0L);
2182
if((aistream=file_open(archive_name, m_rb))==NULL)
2183
error(M_CANTOPEN, archive_name);
2185
/* Initialize caching */
2187
#if SFX_LEVEL>=ARJSFXV
2189
setvbuf(aistream, NULL, _IOFBF, v_buf);
2191
setvbuf(aistream, cache_buf, _IOFBF, VBUF_SFX);
2194
/* Skip EXE header */
2195
#if SFX_LEVEL>=ARJSFXV
2196
if(!first_vol_passed)
2199
main_hdr_offset=find_header(0, aistream);
2203
/* Header verification */
2204
#if SFX_LEVEL>=ARJSFXV
2205
if(main_hdr_offset<0L)
2207
msg_cprintf(H_ALERT, M_NOT_ARJ_ARCHIVE, archive_name);
2208
msg_cprintf(0, (FMSG *)lf);
2209
file_close(aistream);
2211
if(errorlevel==ARJ_ERL_SUCCESS)
2212
errorlevel=ARJ_ERL_NOT_ARJ_ARCHIVE;
2216
fseek(aistream, main_hdr_offset, SEEK_SET);
2218
/* Read the main archive header */
2219
#if SFX_LEVEL>=ARJSFXV
2220
if(!read_header(1, aistream, archive_name))
2221
error(M_INVALID_COMMENT_HDR);
2224
error(M_BAD_HEADER);
2226
/* ARJSFXV: increment SFXNAME */
2227
#if SFX_LEVEL>=ARJSFXV
2229
digit_pos=iterate_sfxname();
2230
if(multivolume_option)
2231
volume_number=strtol(digit_pos, &digit_pos, 10)+1;
2233
/* Analyze preset options */
2235
#if SFX_LEVEL>=ARJSFXV
2236
if(!first_vol_passed)
2238
if(!skip_preset_options)
2239
cmt_ptr=preprocess_comment(cmt_ptr);
2242
msg_cprintf(H_HL|H_NFMT, M_PROCESSING_ARCHIVE, archive_name);
2243
timestamp_to_str(timetext, &ftime_stamp);
2244
msg_cprintf(H_HL|H_NFMT, M_ARCHIVE_CREATED, timetext);
2245
if(arj_nbr>=ARJ_M_VERSION)
2247
ts_store(&tmp_time, host_os, compsize);
2248
timestamp_to_str(timetext, &tmp_time);
2249
msg_cprintf(H_HL|H_NFMT, M_MODIFIED, timetext);
2251
msg_cprintf(0, (FMSG *)lf);
2253
msg_cprintf(0, M_ANSI_CP_ARCHIVE);
2255
alloc_unit_size=get_bytes_per_cluster(target_dir);
2256
if(process_lfn_archive==1)
2257
lfn_supported=LFN_NOT_SUPPORTED;
2258
display_comment(cmt_ptr);
2259
if(!first_vol_passed&&cmd_verb==ARJ_CMD_EXTRACT&&!yes_on_all_queries&&!skip_extract_query)
2260
if(!query_action(REPLY_YES, QUERY_CRITICAL, M_CONTINUE_EXTRACTION))
2261
exit(ARJ_ERL_WARNING);
2264
/* */ /* Nag screen removed */ /* */
2265
#if SFX_LEVEL>=ARJSFXV
2266
if(!first_vol_passed)
2268
if((garble_enabled&&!strcmp(garble_password, "?"))||
2269
(file_garbled&&!garble_enabled&&(cmd_verb==ARJ_CMD_EXTRACT||cmd_verb==ARJ_CMD_TEST)))
2272
tmp_ptr=(char *)malloc_msg(INPUT_LENGTH+1);
2273
msg_cprintf(0, M_ENTER_PWD);
2274
read_line_noecho(tmp_ptr, INPUT_LENGTH);
2275
garble_password=malloc_str(tmp_ptr);
2279
alloc_unit_size=get_bytes_per_cluster(target_dir);
2280
if(process_lfn_archive==1)
2281
lfn_supported=LFN_NOT_SUPPORTED;
2285
enc_version=garble_init(0);
2286
if(ext_hdr_flags!=0&&enc_version!=ext_hdr_flags)
2287
error(M_WRONG_ENC_VERSION, ext_hdr_flags);
2292
if(!skip_preset_options)
2293
cmt_ptr=preprocess_comment(cmt_ptr);
2294
if(quiet_mode&&!yes_on_all_queries)
2297
freopen(dev_null, m_w, stdout);
2298
if(!process_lfn_archive)
2299
lfn_supported=LFN_NOT_SUPPORTED;
2300
msg_cprintf(H_HL|H_NFMT, M_ARJSFX_BANNER, exe_name);
2301
msg_cprintf(H_HL|H_NFMT, M_PROCESSING_ARCHIVE, archive_name);
2303
timestamp_to_str(timetext, &ftime_stamp);
2304
msg_cprintf(H_HL|H_NFMT, M_ARCHIVE_CREATED, timetext);
2305
if(show_ansi_comments)
2308
display_comment(cmt_ptr);
2309
/* The sfx_setup() occurs here */
2311
cmd_verb=ARJ_CMD_LIST;
2312
else if(verbose_list)
2314
cmd_verb=ARJ_CMD_LIST;
2317
else if(test_sfx_cmd)
2318
cmd_verb=ARJ_CMD_TEST;
2321
cmd_verb=ARJ_CMD_EXTR_NP;
2324
if(garble_enabled&&garble_password[0]=='\0')
2325
error(M_NO_PWD_OPTION);
2327
f_arg_array[file_args++]=all_wildcard;
2328
case_path(target_dir);
2329
for(i=0; i<file_args; i++)
2331
strcpy(tmp_name, f_arg_array[i]);
2332
case_path(tmp_name);
2333
add_f_arg(tmp_name);
2335
if(cmd_verb==ARJ_CMD_EXTR_NP&&!yes_on_all_queries&&!skip_extract_query)
2337
msg_cprintf(0, M_CONTINUE_EXTRACTION);
2339
exit(ARJSFX_ERL_ERROR);
2342
#if SFX_LEVEL>=ARJSFXV
2343
if(!first_vol_passed&&prompt_for_directory)
2345
if(prompt_for_directory)
2349
if(target_dir[0]!='\0')
2351
#if SFX_LEVEL>=ARJSFXV
2352
msg_sprintf(misc_buf, M_QUERY_DEST_DIR, target_dir);
2353
query_result=query_action(REPLY_YES, QUERY_CRITICAL, (FMSG *)misc_buf);
2355
msg_cprintf(H_HL|H_NFMT, M_QUERY_DEST_DIR, target_dir);
2356
query_result=query_action();
2361
msg_cprintf(0, M_ENTER_INSTALL_DIR);
2362
read_line(target_dir, FILENAME_MAX-2);
2363
alltrim(target_dir);
2364
if(target_dir[0]!='\0')
2366
if(target_dir[lt=strlen(target_dir)-1]!=PATHSEP_DEFAULT)
2368
target_dir[lt+1]=PATHSEP_DEFAULT;
2369
target_dir[lt+2]='\0';
2371
case_path(target_dir);
2375
if(security_state&&!skip_integrity_test)
2377
if(get_arjsec_signature(aistream, arjsec_offset, arjsec_signature, ARJSEC_ITER))
2380
error(M_DAMAGED_SEC_ARCHIVE);
2384
if(test_sfx_cmd&&cmd_verb==ARJ_CMD_EXTRACT)
2386
last_hdr_offset=ftell(aistream);
2387
#if SFX_LEVEL>=ARJSFXV
2388
while(read_header(0, aistream, archive_name))
2390
while(read_header(0))
2392
unpack_validation();
2394
error(M_FOUND_N_ERRORS, errors);
2395
fseek(aistream, last_hdr_offset, SEEK_SET);
2397
#if SFX_LEVEL>=ARJSFXV
2398
ts_store(&ftime_stamp, OS, 0L);
2399
if(first_volume_number!=0)
2401
volume_number=first_volume_number;
2402
first_volume_number=0;
2409
#if SFX_LEVEL>=ARJSFXV
2410
while(!no_in_arch&&read_header(0, aistream, archive_name))
2412
while(read_header(0))
2415
pf_num=flist_lookup();
2416
#if SFX_LEVEL>=ARJSFXV
2421
case ARJ_CMD_EXTR_NP:
2422
case ARJ_CMD_EXTRACT:
2425
if(unpack_file_proc())
2427
tmp_tmp_filename[0]='\0';
2435
#if SFX_LEVEL>=ARJSFXV
2436
if(list_cmd(total_files, cf_num))
2448
if(unpack_validation())
2450
#if SFX_LEVEL>ARJSFXV /* Avoid to skip data twice! Is this "minimal" fix safe????? */
2460
#if SFX_LEVEL>=ARJSFXV
2461
total_processed+=total_files+comment_entries;
2462
av_compressed+=total_compressed;
2463
av_uncompressed+=total_uncompressed;
2464
av_total_files+=total_files;
2466
#if SFX_LEVEL>=ARJSFXV
2467
if(cmd_verb==ARJ_CMD_LIST)
2469
if(cmd_verb==ARJ_CMD_LIST&&total_files>0)
2472
msg_cprintf(0, M_BRIEF_LIST_SEPARATOR);
2473
#if SFX_LEVEL>=ARJSFXV
2476
ratio=calc_percentage(total_compressed, total_uncompressed);
2477
#if SFX_LEVEL>=ARJSFXV
2478
msg_cprintf(H_HL|H_NFMT, M_TOTAL_STATS, total_files, total_uncompressed, total_compressed, ratio/1000, ratio%1000, msg_ptr, nullstr);
2479
if(av_total_files>total_files)
2480
msg_cprintf(H_HL|H_NFMT, M_TOTAL_STATS, av_total_files, av_uncompressed, av_compressed, ratio/1000, ratio%1000, nullstr, nullstr);
2482
msg_cprintf(H_HL|H_NFMT, M_TOTAL_STATS, total_files, total_uncompressed, total_compressed, ratio/1000, ratio%1000);
2484
#if SFX_LEVEL>=ARJSFXV
2487
free_space=file_getfree(target_dir);
2488
if(disk_space_used+minfree>free_space)
2490
msg_cprintf(H_ALERT, M_NOT_ENOUGH_SPACE_X, disk_space_used+minfree-free_space);
2498
#if SFX_LEVEL>=ARJSFXV
2499
msg_cprintf(H_HL|H_NFMT, M_N_FILES, total_files);
2500
if(comment_entries!=0)
2501
msg_cprintf(H_HL|H_NFMT, M_N_COMMENTS, comment_entries);
2503
msg_cprintf(H_HL|H_NFMT, M_N_FILES, total_files);
2506
#if SFX_LEVEL>=ARJSFXV
2507
file_close(aistream);
2511
#if SFX_LEVEL>=ARJSFXV
2513
if(total_processed==0&&!continued_nextvolume)
2515
if(errorlevel==ARJ_ERL_SUCCESS)
2516
errorlevel=ARJ_ERL_WARNING;
2521
msg_cprintf(H_HL|H_NFMT, M_VALID_ARJSEC, arjsec_signature);
2522
#if SFX_LEVEL<=ARJSFX
2523
/* ARJDISP cleanup */
2526
cmd_verb=ARJDISP_CMD_END;
2527
display_indicator(0L);
2534
#if SFX_LEVEL>=ARJSFXV
2536
/* Performs all archive processing actions including setup and so on... */
2539
void perform_cmd(int cmd)
2547
unsigned long arch_time;
2555
/* Set up ARJ$DISP screen if needed */
2558
cmd_verb=ARJDISP_CMD_START;
2561
uncompsize=compsize=0L;
2562
display_indicator(0L);
2568
continued_nextvolume=0;
2595
modify_command=msg_strchr(M_MODIFY_COMMANDS, (char)cmd)!=NULL;
2596
add_command=msg_strchr(M_ADD_COMMANDS, (char)cmd)!=NULL;
2597
order_command=cmd==ARJ_CMD_ORDER;
2599
if((tmp_ptr=strchr(debug_opt, 'o'))!=NULL)
2600
convert_strtime(&secondary_ftime, ++tmp_ptr);
2602
ts_store(&secondary_ftime, OS_SPECIAL, 0L);
2603
if(resume_volume_num!=0)
2605
volume_number=resume_volume_num;
2606
resume_volume_num=0;
2609
if(start_at_ext_pos)
2611
resume_position=ext_pos;
2612
continued_prevvolume=1;
2615
t_volume_offset=mv_reserve_space;
2617
comment=farmalloc_msg(COMMENT_MAX);
2619
tmp_filename=farmalloc_msg(FILENAME_MAX);
2620
tmp_filename[0]='\0';
2621
is_removable=file_is_removable(archive_name);
2623
if(mv_cmd_state!=MVC_NONE)
2627
if(mv_cmd_state==MVC_DELETION)
2628
delete_files(mv_cmd);
2629
else if(mv_cmd_state==MVC_RUN_CMD)
2631
msg_cprintf(H_PROMPT, M_COMMAND);
2632
msg_cprintf(H_HL|H_NFMT, M_FILENAME_FORM, mv_cmd);
2641
syscmd=(char *)malloc_msg(CMDLINE_LENGTH+1);
2644
msg_cprintf(0, M_ENTER_CMD_EXIT);
2645
msg_cprintf(H_PROMPT, M_COMMAND);
2646
read_line(syscmd, CMDLINE_LENGTH);
2648
msg_strcpy(strcpy_buf, M_EXIT_CMD);
2649
if(!stricmp(strcpy_buf, syscmd))
2658
/* The archive processing itself occurs now */
2660
proc_rc=process_archive_proc(cmd);
2665
if(multivolume_option&&!proc_rc)
2667
if(multivolume_option)
2670
is_removable=file_is_removable(archive_name);
2677
vol_num=volume_number;
2679
while(continued_nextvolume)
2682
arch_time=file_getftime(archive_name);
2685
if(vol_num!=volume_number)
2688
vol_num=volume_number;
2690
if(++tries>MAX_VOLUME_TRIES)
2692
if(errorlevel==ARJ_ERL_SUCCESS)
2693
errorlevel=ARJ_ERL_FATAL_ERROR;
2695
goto all_volumes_done;
2697
if(beep_between_volumes)
2698
msg_cprintf(0, (FMSG *)bell);
2699
if((!is_removable||skip_next_vol_query)&&(yes_on_all_queries||skip_next_vol_query))
2703
msg_sprintf(misc_buf, M_INSERT_DISKETTE, volume_number, reply);
2705
msg_sprintf(misc_buf, M_QUERY_NEXT_VOLUME, volume_number);
2706
if(!query_action(REPLY_YES, QUERY_NEXT_VOLUME, (FMSG *)misc_buf))
2708
if(errorlevel==ARJ_ERL_SUCCESS)
2709
errorlevel=ARJ_ERL_WARNING;
2711
goto all_volumes_done;
2713
if(inhibit_change_test||tries>MAX_VOLUME_FT_CHECKS||!is_removable)
2715
if(!file_exists(archive_name))
2717
} while(file_getftime(archive_name)==arch_time);
2718
if(mv_cmd_state!=MVC_NONE)
2722
if(mv_cmd_state==MVC_DELETION)
2723
delete_files(mv_cmd);
2724
else if(mv_cmd_state==MVC_RUN_CMD)
2726
msg_cprintf(H_PROMPT, M_COMMAND);
2727
printf(strform, mv_cmd);
2733
syscmd=(char *)malloc_msg(CMDLINE_LENGTH+1);
2736
msg_cprintf(0, M_ENTER_CMD_EXIT);
2737
msg_cprintf(H_PROMPT, M_COMMAND);
2738
read_line(syscmd, CMDLINE_LENGTH);
2740
msg_strcpy(strcpy_buf, M_EXIT_CMD);
2741
if(!stricmp(strcpy_buf, syscmd))
2749
if(pause_between_volumes)
2750
arj_delay(change_vol_delay);
2752
if(!yes_on_all_queries&&!skip_next_vol_query)
2753
msg_cprintf(0, (FMSG *)bell);
2754
if((is_removable&&!skip_next_vol_query)||(!yes_on_all_queries&&!skip_next_vol_query))
2758
msg_sprintf(misc_buf, M_INSERT_DISKETTE, volume_number, reply);
2760
msg_sprintf(misc_buf, M_QUERY_NEXT_VOLUME, volume_number);
2761
if(!query_action(REPLY_YES, QUERY_CRITICAL, (FMSG *)misc_buf))
2763
if(errorlevel==ARJ_ERL_SUCCESS)
2764
errorlevel=ARJ_ERL_WARNING;
2770
/* Process next volume... */
2772
process_archive_proc(cmd);
2779
if(beep_between_volumes)
2780
msg_cprintf(0, (FMSG *)bell);
2783
msg_cprintf(0, (FMSG *)bell);
2788
file_close(ofstream);
2790
far_strcpy((char FAR *)filename, tmp_filename);
2791
file_setftime(filename, ts_native(&volume_ftime, OS));
2794
if(tmp_filename!=NULL)
2795
farfree(tmp_filename);
2799
farfree(tmp_filename);
2803
/* ARJDISP cleanup */
2806
cmd_verb=ARJDISP_CMD_END;
2807
display_indicator(0L);