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

📄 arj.c

📁 arj source code
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * $Id: arj.c,v 1.8 2003/06/22 11:12:28 andrew_belov Exp $ * --------------------------------------------------------------------------- * This is  the main file of the  ARJ project. The  routines in this file have * a wide variety of purposes, however, all archive-related procedures are NOT * put into ARJ.C. * */#include <stdio.h>#include <signal.h>#include "arj.h"DEBUGHDR(__FILE__)                      /* Debug information block *//* Expiry date/time */#define EXPIRABLE                  0    /* 1 -> allow expiry as such */#define EXPIRY_YR               1980#define EXPIRY_MO                  1#define EXPIRY_DY                  1#define EXPIRY_H                   0#define EXPIRY_M                   0#define EXPIRY_S                   0/* Local variables */static char fixed_arjtemp[]="ARJTEMP.$$$";static char arjtemp_wildcard[]="ARJTEMP.$??";static char wildcard_pattern[]="?*[]^";static int tmp_archive_exists;static int tmp_archive_removed;static unsigned long ticks;static unsigned int limit;static char brief_help[]="arjs.txt";static char full_help[]="arjl.txt";static char sort_filename[]="arjsort.$$$";static char *arj_env_str=NULL;static char single_spc[]=" ";/* Forward references */static void finish_archive_name(char *name);static void final_cleanup(void);/* Checks if all the files given to ARJ were successfully processed. */static void file_arg_cleanup(struct flist_root *flist){ int cur_arg; FILE_COUNT cur_file; char *tmp_name; for(cur_arg=0; cur_arg<file_args; cur_arg++) {  if(order[cur_arg]==0&&strcmp_os(f_arg_array[cur_arg], nonexist_name))  {   msg_cprintf(H_ERR, M_CANT_FIND, f_arg_array[cur_arg]);   if(errorlevel==ARJ_ERL_SUCCESS)    errorlevel=ARJ_ERL_WARNING;   errors++;  } } if(flist->files>0) {  tmp_name=malloc_msg(FILENAME_MAX);  for(cur_file=0; cur_file<flist->files; cur_file++)  {   flist_retrieve(tmp_name, NULL, flist, cur_file);   msg_cprintf(H_ERR, M_CANT_FIND, tmp_name);   if(listfile_err_opt)   {    if(errorlevel==ARJ_ERL_SUCCESS)     errorlevel=ARJ_ERL_WARNING;    errors++;   }  }  free(tmp_name); }}/* Depending on the command given, issues some special setup */static void cmd_setup(int *cmd, int *is_add_cmd){ int cnv_cmd; int add_cmd; char *tmp_swptr; char *vptr; unsigned long vol_size; cnv_cmd=*cmd; switch(*cmd) {  case ARJ_CMD_MOVE:   cnv_cmd=ARJ_CMD_ADD;   delete_processed=DP_ADD;  case ARJ_CMD_ADD:   if(freshen_criteria)    cnv_cmd=ARJ_CMD_FRESHEN;   if(update_criteria)    cnv_cmd=ARJ_CMD_UPDATE;   break;  case ARJ_CMD_REM_BAK:   current_chapter=RESERVED_CHAPTER;   break;  case ARJ_CMD_FRESHEN:   if(freshen_criteria==FC_NONE)    freshen_criteria=FC_EXISTING;   break;  case ARJ_CMD_UPDATE:   if(update_criteria==FC_NONE)    update_criteria=FC_EXISTING;   break;  case ARJ_CMD_SECURE:   sign_with_arjsec=1;   break;  case ARJ_CMD_ADDC:   cnv_cmd=ARJ_CMD_UPDATE;   update_criteria=UC_NEW_OR_DIFFERENT;   chapter_mode=CHAP_USE;   break;  case ARJ_CMD_CNVC:   cnv_cmd=ARJ_CMD_COPY;   chapter_mode=CHAP_USE;   break;  case ARJ_CMD_DELC:   cnv_cmd=ARJ_CMD_DELETE;   chapter_mode=CHAP_USE;   break;  case ARJ_CMD_EXEC:   cnv_cmd=ARJ_CMD_EXTR_NP;   execute_cmd=1;   if(extraction_filename[0]=='\0')   {    extraction_filename=fixed_arjtemp;    extract_to_file=1;   }   break;  case ARJ_CMD_SAMPLE:   cnv_cmd=ARJ_CMD_PRINT;   print_with_more=1;   break;  case ARJ_CMD_PRINT:   if(!prompt_for_more)    break;   print_with_more=1;   break;  case ARJ_CMD_V_LIST:   cnv_cmd=ARJ_CMD_LIST;   std_list_cmd=1;   break;  case ARJ_CMD_EXTRACT:   cnv_cmd=ARJ_CMD_EXTR_NP;   subdir_extraction=1;   break; } if(cnv_cmd==ARJ_CMD_EXTR_NP&&delete_processed&&!execute_cmd) {  cnv_cmd=ARJ_CMD_DELETE;  delete_processed=DP_EXTRACT; } add_cmd=msg_strchr(M_ADD_COMMANDS, (char)cnv_cmd)!=NULL; if(file_args<0) {  if(!append_curtime)   error(M_NO_FILE_GIVEN);  else  {   archive_name[0]='\0';   file_args++;   finish_archive_name(archive_name);  } } if(cnv_cmd==ARJ_CMD_DELETE&&file_args==0&&delete_processed!=DP_EXTRACT)  error(M_NO_DELETE_ARG); if(cnv_cmd!=ARJ_CMD_COMMENT&&msg_strchr(M_MODIFY_COMMANDS, (char)cnv_cmd)!=NULL&&current_chapter!=0&&current_chapter<=CHAPTERS_MAX)  error(M_BAD_SYNTAX); if(add_cmd&&multivolume_option) {  if(volume_limit<MIN_VOLUME_SIZE)   error(M_INVALID_VOL_SIZE);  /* ASR fix. This was dropped in original ARJ but stays here, with a fix to     treat -va adequately. */  if(protfile_option)  {   vol_size=(unsigned long)calc_protdata_size(volume_limit, protfile_option)+MIN_VOLUME_SIZE;   if(volume_limit<vol_size&&multivolume_option!=MV_AVAIL)    error(M_PROTFILE_EXCEEDS, vol_size);  } } if(add_command&&strpbrk(archive_name, wildcard_pattern)!=NULL)  error(M_CANTOPEN, archive_name); if(cnv_cmd==ARJ_CMD_COPY&&file_args>0)  error(M_BAD_SYNTAX); if(win32_platform&&lfn_mode==LFN_DUAL)  error(M_BAD_SYNTAX); if(chapter_mode==CHAP_REMOVE&&cnv_cmd!=ARJ_CMD_COPY)  error(M_BAD_SYNTAX); if(test_archive_crc>=TC_CRC_AND_CONTENTS&&exclude_paths)  error(M_JT_UNUSABLE, "-e/-e1"); if(test_archive_crc>=TC_CRC_AND_CONTENTS&&fix_longnames)  error(M_JT_UNUSABLE, "-2l"); if(arcmail_sw&&serialize_exts)  error(M_JO_UNUSABLE, "-2a"); #if TARGET==DOS  if(priority.class!=0)   error(M_OS_DEPENDENT, "-2p"); #endif if(ea_supported&&restart_at_filename)  error(M_CANT_RESTART_W_EAS); if(assign_work_directory&&work_directory[0]=='\0')  error(M_MISSING_FILENAME_ARG, "-w"); if(extract_to_file&&extraction_filename[0]=='\0')  error(M_MISSING_FILENAME_ARG, "-jw"); if(create_list_file&&list_file[0]=='\0')  error(M_MISSING_FILENAME_ARG, "-l"); if(create_index&&index_name[0]=='\0')  error(M_MISSING_FILENAME_ARG, "-ji"); if(restart_at_filename&&filename_to_restart[0]=='\0'&&index_name[0]=='\0')  error(M_MISSING_FILENAME_ARG, "-jn"); if((cnv_cmd==ARJ_CMD_EXTR_NP||cnv_cmd==ARJ_CMD_EXTRACT)&&use_comment&&archive_cmt_name[0]=='\0')  error(M_MISSING_FILENAME_ARG, "-z"); if(chk_arj_version) {  tmp_swptr=swptr_hv;  if(tmp_swptr[0]=='\0'||tmp_swptr[0]=='R'||tmp_swptr[0]=='r')   if(!is_registered)    exit(ARJ_ERL_WARNING);   else if(tmp_swptr[0]!='\0')    tmp_swptr++;  if(tmp_swptr[0]!='\0')  {   msg_strcpy(strcpy_buf, M_VERSION);   vptr=strcpy_buf;   if(vptr[0]<tmp_swptr[0])    exit(ARJ_ERL_WARNING);   if(vptr[0]==tmp_swptr[0])   {    vptr+=2;    tmp_swptr+=2;                       /* Skip over "." */    if(vptr[0]<tmp_swptr[0])     exit(ARJ_ERL_WARNING);    if(vptr[0]==tmp_swptr[0])    {     vptr++;     tmp_swptr++;     if(vptr[0]<tmp_swptr[0])      exit(ARJ_ERL_WARNING);     if(vptr[0]==tmp_swptr[0])     {      vptr++;      tmp_swptr++;      if(vptr[0]<tmp_swptr[0])       exit(ARJ_ERL_WARNING);     }    }   }  } } if(file_args==0)  f_arg_array[file_args++]=all_wildcard; method_specifier=(custom_method==0)?1:custom_method-1; if(create_sfx) {  if(method_specifier==4)   error(M_INVALID_METHOD_SFX);  if(chapter_mode)   error(M_CHAPTER_SFX_CREATION);  if(create_sfx==SFXCRT_SFXJR&&type_override&&primary_file_type==ARJT_TEXT)   error(M_TEXTMODE_LFN_SFXJR);  #if TARGET==DOS   if(create_sfx==SFXCRT_SFXJR&&lfn_supported!=LFN_NOT_SUPPORTED)    error(M_TEXTMODE_LFN_SFXJR);  #endif  #if defined(HAVE_EAS)   if(create_sfx==SFXCRT_SFXJR&&ea_supported)    error(M_TEXTMODE_LFN_SFXJR);  #endif  #if TARGET==UNIX   if(create_sfx==SFXCRT_SFXJR&&dos_host)    error(M_DOS_MODE_SFXJR);  #endif  if(create_sfx==SFXCRT_SFXJR&&garble_enabled)   error(M_NO_GARBLE_IN_SFXJR);  if(msg_strchr(M_MODIFY_COMMANDS, (char)cnv_cmd)==NULL)   error(M_INVALID_SFX_SW_USE);  if(create_sfx==SFXCRT_SFXJR&&multivolume_option)   error(M_MULTIVOLUME_SFXJR); } if(debug_enabled&&strchr(debug_opt, 'n')!=NULL)  no_file_activity=1; if(ignore_crc_errors)  keep_tmp_file=1; if(exit_after_count&&exit_count==0)  exit_count=file_args; if(handle_labels&&label_drive=='\0'&&target_dir[0]!='\0'&&target_dir[1]==':')  label_drive=target_dir[0]; if(filelist_storage==BST_NONE&&!win32_platform) {  filelist_storage=BST_DISK;  max_filenames=3000; } *cmd=cnv_cmd; *is_add_cmd=add_cmd;}/* Gets the command for execution */static void get_exec_cmd(){ if(set_string_parameter&&string_parameter[0]!='\0')  cmd_to_exec=string_parameter; else {  while(header[0]=='\0')  {   msg_cprintf(0, M_ENTER_CMD);   read_line(header, HEADERSIZE_MAX);  }  cmd_to_exec=malloc_str(header); }}/* Picks an extension from the -hx extension list */static int fetch_extension(int offset, char *dest){ int c_offset; if(strlen(archive_ext_list)<offset)  return(0); while(archive_ext_list[offset]!='\0'&&archive_ext_list[offset]!='.') offset++; if(archive_ext_list[offset]=='\0')  return(0); c_offset=offset; do  offset++; while(c_offset+6>offset&&archive_ext_list[offset]!='\0'&&archive_ext_list[offset]!='.'); while(c_offset<offset)  *(dest++)=archive_ext_list[c_offset++]; *dest='\0'; return(offset);}/* Adds ARJ extension to the archive name */static void finish_archive_name(char *name){ int n_len; char last_char; int offset; char ext_pad[EXTENSION_MAX+2];         /* +2 means space for '.' and '\0' */ int entry; if(name[0]=='\0')  msg_strcpy(name, M_EXT_ARJ); n_len=strlen(name); entry=split_name(name, NULL, NULL); last_char=name[n_len-1]; if(last_char=='.')  name[n_len-1]='\0'; else if(strchr(name+entry, '.')==NULL) {  /* create_sfx is an ASR fix for 2.77 (empty extension on UNIX) */  if(!override_archive_exts)  {   #ifdef NULL_EXE_EXTENSION    if(!create_sfx)     msg_strcpy(name+n_len, M_EXT_ARJ);    else     name[n_len]='\0';   #else    msg_strcpy(name+n_len, M_EXT_ARJ);   #endif   if(lfn_supported==LFN_NOT_SUPPORTED)    strupper(name+n_len);  }  else  {   offset=0;   while((offset=fetch_extension(offset, ext_pad))!=0)   {    strcpy(name+n_len, ext_pad);    if(file_exists(name))     break;   }   if(offset==0)   {    fetch_extension(0, ext_pad);    strcpy(name+n_len, ext_pad);   }  } }}/* Converts a filename entered from command-line to standard form */static void cnv_cmdline_fnm(char *name){ strip_lf(name); alltrim(name); if(translate_unix_paths)  unix_path_to_dos(name);}/* Creates an exclusion list */void create_excl_list(char *names){ char tmp_name[FILENAME_MAX]; FILE *stream; if(listchars_allowed&&names[0]==listchar) {  if(*++names=='\0')   error(M_MISSING_FILENAME_ARG, "-x");  unix_path_to_dos(names);  stream=file_open_noarch(names, m_r);  while(fgets(tmp_name, sizeof(tmp_name), stream)!=NULL)  {   cnv_cmdline_fnm(tmp_name);   if(tmp_name[0]!='\0')    flist_add_files(&flist_exclusion, NULL, tmp_name, 0, 0, 0, NULL);  }  fclose(stream);

⌨️ 快捷键说明

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