⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arj_arcv.c

📁 open arj source
💻 C
📖 第 1 页 / 共 5 页
字号:
  arj_flags|=PROT_FLAG;  prot_blocks=tmp_prot_blocks;  /* ASR fix - the original (v 3.02) checks for ==0 only */  if(file_crc==0L||file_crc>arjsec_offset||(arjsec_offset-file_crc)>=CACHE_SIZE)   file_crc=arjsec_offset; } else if(operation==FP_VOLUME)  arj_flags&=~VOLUME_FLAG; else if(operation==FP_CHAPTER)  chapter_number=max_chapter; else if(operation==FP_GARBLE) {  arj_flags|=GARBLED_FLAG;  ext_flags=(ext_flags&0xF0)|(cur_ext_hdr_flags&0x0F); } create_header(1); write_header(); fseek(aostream, cur_pos, SEEK_SET); prot_blocks=tmp_prot_blocks; resume_position=tmp_resume_position; continued_prevvolume=tmp_cont_prev; mvfile_type=tmp_multivolume; comment[0]='\0';                       /* ASR fix - the original is somewhere                                           else */}#endif/* Skips over the compressed data in the input file */void skip_compdata(){ #if SFX_LEVEL>=ARJSFXV  if(compsize!=0L)   file_seek(aistream, compsize, SEEK_CUR); #else  fseek(aistream, compsize, SEEK_CUR); #endif}/* Skips over the compressed data, prompting the user */void skip_file(){ #if SFX_LEVEL>=ARJSFXV  msg_cprintf(H_HL|H_NFMT, M_SKIPPED, filename); #else  msg_cprintf(H_HL|H_NFMT, M_SKIPPED, filename); #endif skip_compdata();}/* Displays ARJ$DISP screen */void arjdisp_scrn(unsigned long bytes){ char *arjdisp_name; #if SFX_LEVEL<=ARJSFX  char cmd_buf[CCHMAXPATH]; #endif #if SFX_LEVEL>=ARJSFXV ctrlc_not_busy=0; arjdisp_name=arjdisp_ptr; if(arjdisp_name[0]=='\0')  arjdisp_name=arjdisp_default; #else  arjdisp_name=arjdisp_default; #endif if(strcmp_os(filename, arjdisp_name)) {  #if SFX_LEVEL>=ARJSFXV   msg_sprintf(misc_buf, M_ARJDISP_INVOCATION, arjdisp_name, archive_name, filename, uncompsize, bytes, compsize, cmd_verb);   system_cmd(misc_buf);  #else   msg_sprintf(cmd_buf, M_ARJDISP_INVOCATION, arjdisp_name, archive_name, filename, uncompsize, bytes, compsize, cmd_verb);   system_cmd(cmd_buf);  #endif } #if SFX_LEVEL>=ARJSFXV ctrlc_not_busy=1; #endif}#if SFX_LEVEL>=ARJ/* Returns CRC-32 ofthe given file */static unsigned long crc32_for_file(char *name){ FILE *stream; char *buffer; int block_size; crc32term=CRC_MASK; if((stream=file_open(name, m_rb))!=NULL) {  buffer=malloc_msg(CACHE_SIZE);  while((block_size=fread(buffer, 1, CACHE_SIZE, stream))!=0)   crc32_for_block(buffer, block_size);  free(buffer);  fclose(stream); } return(crc32term^CRC_MASK);}/* Issues various actions on currently processed file in archive */void special_processing(int action, FILE *stream){ int garble_task; struct timestamp gtime; char *pbuf; unsigned long cur_pos; int count; char *tmp_name; garble_task=0;                         /* Initally, no garble post-processing                                           is considered. */ switch(action) {  case CFA_UNMARK:   msg_cprintf(H_HL|H_NFMT, M_UNMARKING, filename);   if((int)chapter_number!=total_chapters)    error(M_CHAPTER_ERROR, 1);   chapter_number--;   create_header(0);   break;  case CFA_MARK:   msg_cprintf(H_HL|H_NFMT, M_MARKING, filename);   if((int)chapter_number!=total_chapters)    error(M_CHAPTER_ERROR, 1);   ext_flags=(unsigned char)total_chapters;   create_header(0);   break;  case CFA_MARK_INCREMENT:   msg_cprintf(H_HL|H_NFMT, M_MARKING, filename);   if((int)chapter_number+1!=total_chapters)    error(M_CHAPTER_ERROR, 1);   chapter_number=(unsigned char)total_chapters;   create_header(0);   total_files++;   if(host_os==OS_WIN95||host_os==OS_WINNT)   {    total_longnames++;    if(volume_flag_set)     split_longnames++;   }   break;  case CFA_REMPATH:   msg_cprintf(H_HL|H_NFMT, M_REMOVING_PATH, filename);   far_strcpyn(comment, (char FAR *)hdr_comment, COMMENT_MAX);   tmp_name=malloc_str(hdr_filename);   split_name(tmp_name, NULL, hdr_filename);   free(tmp_name);   entry_pos=0;   arj_flags&=~PATHSYM_FLAG;   calc_comment_offset();   far_strcpyn((char FAR *)hdr_comment, comment, COMMENT_MAX);   if(dual_name)   {    tmp_name=malloc_str(hdr_comment);    split_name(tmp_name, NULL, hdr_comment);    free(tmp_name);   }   create_header(0);   calc_basic_hdr_size();   total_files++;   break;  case CFA_MARK_EXT:   msg_cprintf(H_HL|H_NFMT, M_MARKING, filename);   if(ext_flags==0)    ext_flags=(unsigned char)total_chapters;   if(chapter_number==0)    chapter_number=(unsigned char)total_chapters;   create_header(0);   total_files++;   break;  case CFA_UNMARK_EXT:   msg_cprintf(H_HL|H_NFMT, M_UNMARKING, filename);   ext_flags=0;   chapter_number=0;   create_header(0);   total_files++;   break;  case CFA_GARBLE:   if(!(arj_flags&GARBLED_FLAG))   {    msg_cprintf(H_HL|H_NFMT, M_GARBLING, filename);    arj_flags|=GARBLED_FLAG;    cur_time_stamp(&gtime);    password_modifier=ts_native(&gtime, OS);    garble_task=1;    create_header(0);    total_files++;   }   break;  case CFA_UNGARBLE:   if(arj_flags&GARBLED_FLAG)   {    msg_cprintf(H_HL|H_NFMT, M_UNGARBLING, filename);    arj_flags&=~GARBLED_FLAG;    garble_task=2;    create_header(0);    total_files++;   }   break; } if(arj_flags&GARBLED_FLAG)  encryption_id=ENCID_GARBLE; write_header(); if(garble_task)  garble_init(password_modifier); pbuf=(char *)malloc_msg(PROC_BLOCK_SIZE); cur_pos=ftell(stream); count=min(CACHE_SIZE-(cur_pos%CACHE_SIZE), compsize); while(compsize>0L) {  if(fread(pbuf, 1, count, stream)!=count)   error(M_CANTREAD);  if(garble_task==1)   garble_encode_stub(pbuf, count);  else if(garble_task==2)   garble_decode_stub(pbuf, count);  if(!no_file_activity)   file_write(pbuf, 1, count, aostream);  compsize-=(unsigned long)count;  count=min(PROC_BLOCK_SIZE, compsize); } free(pbuf);}/* Prints an "Adding..." message */static void addition_msg(int is_update, int is_replace, char *filespec){ /* -hdx will turn off these messages */ if(!debug_enabled||strchr(debug_opt, 'x')==NULL) {  if(is_update)   msg_cprintf(H_HL, M_UPDATING);  else if(is_replace)   msg_cprintf(H_HL, M_REPLACING);  else   msg_cprintf(H_HL, M_ADDING);  if(verbose_display==VERBOSE_STD)  {   if(file_type==ARJT_BINARY)    msg_cprintf(0, M_BINARY_FILE);   else if(file_type==ARJT_TEXT)    msg_cprintf(0, M_TEXT_FILE);   else if(file_type==ARJT_DIR)    msg_cprintf(0, M_DIRECTORY);   else if(file_type==ARJT_UXSPECIAL)    msg_cprintf(0, M_UXSPECIAL_FILE);  }  if(continued_prevvolume&&eh_find_pending(eh)==NULL)   msg_cprintf(H_HL|H_NFMT, M_AT_POSITION, format_filename(filespec), resume_position);  else   msg_cprintf(0, (FMSG *)strform, format_filename(filespec));  if(!verbose_display)   msg_cprintf(0, (FMSG *)vd_space);  else  {   nputlf();   if(method==0)    msg_cprintf(0, M_STORING);   else    msg_cprintf(H_HL|H_NFMT, M_COMPRESSING, method);   msg_cprintf(H_HL|H_NFMT, M_N_BYTES, uncompsize);  } }}/* Initializes global variables and performs general set-up before packing a   file. */void init_packing(unsigned long offset, int is_mv){ unpackable=0; volume_flag_set=0; ext_voldata=0; compsize=origsize=0L; if(garble_enabled)  garble_init(password_modifier); crc32term=CRC_MASK; if(file_type==ARJT_BINARY||file_type==ARJT_TEXT) {  if(!is_mv||resume_position>0)   smart_seek(resume_position, encstream); } if(!is_mv&!no_file_activity)  fseek(aostream, offset, SEEK_SET);}/* Stores or compresses a single file */static void pack_file_proc(unsigned long offset){ if(method==1||method==2||method==3)  encode_stub(method); else if(method==4)  encode_f_stub(); else if(method==9)  hollow_encode(); if(unpackable)                         /* Fall back to method #0 */ {  if(verbose_display==VERBOSE_STD)  {   msg_cprintf(0, (FMSG *)"       \r");   msg_cprintf(0, M_STORING);   msg_cprintf(H_HL|H_NFMT, M_N_BYTES, uncompsize);  }  method=0;  init_packing(offset, 0); } if(method==0)  store(); display_indicator(uncompsize);}/* Opens the file for encoding */static int open_input_file(){ int e;                                 /* Error indicator */ if((encstream=file_open(filename, read_perms[file_type%2]))!=NULL)  return(0); error_report(); msg_cprintf(H_ERR, M_CANTOPEN, filename); nputlf(); e=1; if(no_inarch) {  if(ignore_open_errors==IAE_ACCESS&&errno==EACCES||     ignore_open_errors==IAE_NOTFOUND&&errno==ENOENT||     ignore_open_errors==IAE_ALL&&(errno==EACCES||errno==ENOENT))  e=0; } if(e)  errors++; write_index_entry(idxid_fault); return(1);}/* Packs a single file, involving all neccessary checks. Returns 1 if it got   packed, 0 if not, -1 in case of an error. */int pack_file(int is_update, int is_replace){ struct timestamp ftime, atime, ctime, cur_time; unsigned long fsize; int volume_file;                       /* 1 if file spans across volumes */ int needs_skip;                        /* 1 if the file needs to be skipped */ int err_id; ATTRIB attrib; int fb; unsigned int total_chars, nd_chars; int textf=0;                           /* 1 if the file seems to be text */ int fetch_size; unsigned long cur_pos=0;               /* Current position in output file */ int lfn; unsigned long data_pos=0; unsigned long st_ticks=0;              /* Start time (used for profiling) */ unsigned int bck_method; int ratio; char timetext[20]; char FAR *raw_eh; struct mempack mempack; int lfn_xlated; char ea_res[FILENAME_MAX]; int res_len=0; char FAR *ea_blk; struct ext_hdr FAR *p_eh; if(is_replace&&new_files_only)  return(0); if(!match_attrib(&properties)) {  error(M_SELECTION_ERROR);  return(-1); } ts_store(&ftime, OS, properties.ftime); ts_store(&atime, OS, properties.atime); ts_store(&ctime, OS, properties.ctime); if(is_update&&!skip_ts_check) {  fsize=properties.fsize;  volume_file=arj_flags&VOLUME_FLAG||arj_flags&EXTFILE_FLAG;  needs_skip=0;  if(update_criteria==UC_NEW_OR_CRC||freshen_criteria==FC_CRC)  {   if(!volume_file&&fsize==origsize)   {    if(crc32_for_file(filename)==file_crc)     needs_skip=1;   }  }  else if(update_criteria==UC_NEW_OR_DIFFERENT||freshen_criteria==FC_DIFFERENT)  {   if(!volume_file&&!ts_cmp(&ftime_stamp, &ftime)&&fsize==origsize)    needs_skip=1;  }  else if(update_criteria==UC_NEW_OR_OLDER||freshen_criteria==FC_OLDER)  {   if(ts_cmp(&ftime, &ftime_stamp)>=0)    needs_skip=1;  }  else if(update_criteria==UC_NEW_OR_NEWER||freshen_criteria==FC_EXISTING)  {   if(ts_cmp(&ftime, &ftime_stamp)<=0)    needs_skip=1;  }  if(needs_skip)  {   if(verbose_display)   {    msg_cprintf(H_HL|H_NFMT, M_NO_CHANGE, format_filename(filename));   }   special_processing((total_chapters!=0)?CFA_MARK_INCREMENT:CFA_NONE, aistream);   return(1);  } } if(query_for_each_file) {  msg_sprintf(misc_buf, is_update?M_QUERY_UPDATE:M_QUERY_ADD, filename);  if(!query_action(REPLY_YES, QUERY_ARCH_OP, (char FAR *)misc_buf))   return(0); } if(is_replace) {  if(total_chapters>0)   special_processing(CFA_NONE, aistream);  else   skip_compdata();  if(multivolume_option)  {   total_files++;   return(2);  } } else {  file_type=ARJT_BINARY;  first_hdr_size=continued_prevvolume?FIRST_HDR_SIZE_V:STD_HDR_SIZE;  if(lfn_supported!=LFN_NOT_SUPPORTED&&!skip_time_attrs)   first_hdr_size=R9_HDR_SIZE;  hdr_filename=&header[first_hdr_size];  hdr_filename[0]='\0';  calc_comment_offset();  hdr_comment[0]='\0'; } method=custom_method?method_specifier:1; uncompsize=properties.fsize; attrib=properties.attrib; if(clear_archive_bit)  attrib&=~FATTR_RDONLY; garble_ftime=ts_native(&ftime, OS); if(type_override) {  file_type=primary_file_type;  if(*swptr_t!='\0')   if(search_for_extension(filename, swptr_t))    file_type=secondary_file_type; } if(continued_prevvolume&&mvfile_type>=0)  file_type=mvfile_type; if(!is_filename_valid(filename))  error(M_CANTOPEN, filename); if(properties.type==ARJT_DIR)  file_type=ARJT_DIR; else if(properties.type==ARJT_UXSPECIAL)  file_type=ARJT_UXSPECIAL; volume_flag_set=0; user_wants_fail=0; err_id=0; if(hollow_mode!=HM_NO_CRC) {  if(file_type==ARJT_DIR||file_type==ARJT_UXSPECIAL)   method=0;  else if(file_type==ARJT_BINARY||file_type==ARJT_TEXT)  {   if(open_input_file())    return(0);   current_bufsiz=jh_enabled?user_bufsiz:BUFSIZ_DEFAULT;   if(file_type==ARJT_TEXT)   {    nd_chars=0;    textf=1;    fetch_size=CACHE_SIZE;    total_chars=0;    while((fb=fgetc(encstream))!=EOF)    {     if(fb<TEXT_LCHAR||fb>TEXT_UCHAR)      nd_chars++;     total_chars++;     if(total_chars>=fetch_size)      break;    }    if(total_chars>0)     rewind(encstream);    /* Select files that meet size requirements... */    if(type_override<FT_TEXT_FORCED&&uncompsize>=(unsigned long)MIN_TEXT_SIZE&&       total_chars<fetch_size&&(unsigned long)total_chars*5L<uncompsize*4L)     textf=0;    /* ...or meet character composition requirements */    if(type_override<FT_TEXT_FORCED&&total_chars/5<=nd_chars)     textf=0;    if((type_override==FT_BINARY||type_override==FT_TEXT_FORCED)&&nd_chars!=0)     textf=0;   }   if(file_type==ARJT_TEXT&&type_override!=FT_NO_OVERRIDE&&resume_position==0L)   {    if(!textf)     file_type=ARJT_BINARY;    if(file_type==ARJT_BINARY)    {     file_close(encstream);     encstream=NULL;     if(open_input_file())      return(0);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -