📄 arj.c
字号:
else flist_add_files(&flist_exclusion, NULL, names, 0, 0, 0, NULL);}/* Parses the command line, taking filename argument. Returns the command code. */static int parse_cmdline(char *token, int cmd){ int name_len; char *endptr; char end_sym; if(debug_enabled&&strchr(debug_opt, 'v')!=NULL) msg_cprintf(H_HL|H_NFMT, M_TOKEN, token); if(is_switch(token)) analyze_arg(token); else { if(cmd==0) { cmd=toupper(token[0]); /* Use fake 1-byte commands for 2-byte commands */ if(!stricmp(token, cmd_ac)) return(cmd=ARJ_CMD_ADDC); if(!stricmp(token, cmd_cc)) return(cmd=ARJ_CMD_CNVC); if(!stricmp(token, cmd_dc)) return(cmd=ARJ_CMD_DELC); if(msg_strchr(M_CMD_TABLE, (char)cmd)==NULL||strlen(token)!=1) { msg_cprintf(H_HL|H_NFMT, M_INVALID_COMMAND, token); exit(ARJ_ERL_USER_ERROR); } } else { if(file_args<0) { far_strcpyn((char FAR *)archive_name, (char FAR *)token, FILENAME_MAX); unix_path_to_dos(archive_name); alltrim(archive_name); if(archive_name[0]=='\0') { if(!append_curtime) error(M_NO_FILE_GIVEN); finish_archive_name(archive_name); } file_args++; } else { unix_path_to_dos(token); name_len=strlen(token); endptr=&token[name_len-1]; end_sym=*endptr; while(*endptr==' ') endptr--; if(file_args<0||strcmp_os(token, nonexist_name)) { if(file_args==0&&!set_target_directory&&target_dir[0]=='\0'&& strchr(path_separators, *endptr)!=NULL) { target_dir=token; if(end_sym!=' ') return(cmd); } if(file_args==0&&!set_target_directory&&target_dir[0]=='\0'&& msg_strchr(M_DIR_COMMANDS, (char)cmd)!=NULL&&strpbrk(token, wildcard_pattern)==NULL&& is_directory(token)) { target_dir=malloc_msg(name_len+2); strcpy(target_dir, token); target_dir[name_len]=PATHSEP_DEFAULT; target_dir[name_len+1]='\0'; } else { if(file_args>=params_max) error(M_ARGTABLE_OVERFLOW); f_arg_array[file_args++]=token; } } else f_arg_array[file_args++]=token; } } } return(cmd);}/* Ctrl+C handler */static void ctrlc_handler(SIGHDLPARAMS){ ctrlc_processing=1; /* Check if we are able to honor the request. If we aren't, raise the signal again and make a speedy getaway. */ if(!ctrlc_not_busy) raise(SIGINT); else { error_occured=1; /* ARJ needs termination */ signal(SIGINT, NULL); /* Restore default Ctrl+C handler */ msg_cprintf(H_SIG, M_BREAK_SIGNALED); exit(ARJ_ERL_BREAK); }}/* Termination handler */#ifndef NO_TERM_HDLstatic void term_handler(SIGHDLPARAMS){ error_occured=1; /* ARJ needs termination */ signal(SIGTERM, NULL); msg_cprintf(H_SIG, M_SIGTERM); exit(ARJ_ERL_BREAK);}#endif/* Executes an OS command with checking for break */void exec_cmd(char *cmd){ flush_kbd(); ctrlc_not_busy=0; /* Say that we are busy */ system_cmd(cmd); ctrlc_not_busy=1; if(ctrlc_processing) /* If processing was delayed... */ #if COMPILER==BCC ctrlc_handler(); #else ctrlc_handler(0); #endif}/* atexit routine - closes all files and frees memory */static void final_cleanup(void){ short pad; static int double_shutdown=0; file_close(idxstream); file_close(aistream); file_close(atstream); idxstream=NULL; aistream=NULL; atstream=NULL; if(aostream!=NULL) { if(last_hdr_offset>0L) { fseek(aostream, last_hdr_offset+2L, SEEK_SET); pad=0; fwrite(&pad, 1, 2, aostream); } file_close(aostream); aostream=NULL; } #if TARGET!=UNIX||defined(HAVE_FCLOSEALL) fcloseall(); #endif if(tmp_archive_name!=NULL) { if(tmp_archive_removed) { rename_with_check(tmp_archive_name, archive_name); tmp_archive_name[0]='\0'; } if(!keep_tmp_archive&&tmp_archive_name[0]!='\0'&&(!tmp_archive_used||!tmp_archive_exists)) file_unlink(tmp_archive_name); if(tmp_archive_used==1) file_unlink(archive_name); free(tmp_archive_name); tmp_archive_name=NULL; } if(tmp_tmp_filename!=NULL) { if(!keep_tmp_file&&tmp_tmp_filename[0]!='\0') file_unlink(tmp_tmp_filename); free(tmp_tmp_filename); tmp_tmp_filename=NULL; } if(debug_enabled&&strchr(debug_opt, 'v')!=NULL) { msg_cprintf(0, M_EXITING_PROGRAM); if(double_shutdown) msg_cprintf(0, M_HERE_TWICE); if(verify_heap()) msg_cprintf(H_ERR, M_BAD_HEAP); } if(double_shutdown) return; double_shutdown=1; flist_cleanup(&flist_main); flist_cleanup(&flist_order); flist_cleanup(&flist_exclusion); flist_cleanup(&flist_archive); #if defined(HAVE_EAS) flist_cleanup(&flist_ea); flist_cleanup(&flist_xea); #endif #if TARGET==UNIX if(l_entries.list!=NULL) farfree(l_entries.list); #endif if(quiet_mode) freopen(dev_con, m_w, stdout); if(ferror(stdout)) msg_fprintf(stderr, M_DISK_FULL); if(debug_enabled&&strchr(debug_opt, 't')!=NULL) { ticks=get_ticks()-ticks; msg_cprintf(H_HL|H_NFMT, M_FINAL_TIMING, ticks); } if(!store_by_suffix) free(archive_suffixes); cfa_shutdown(); if(arj_env_str!=NULL) free_env_str(arj_env_str); if(eh!=NULL) { eh_release(eh); eh=NULL; } if(ntext!=NULL) /* ASR fix for 2.76.05 */ free(ntext); free_fmsg(arj_env_name); free(header); free(archive_name); free(misc_buf); free(strcpy_buf); free(exe_name); farfree(order); free(f_arg_array);#ifdef COLOR_OUTPUT scrn_reset();#endif}/* Waits and then prints an error message */static void wait_error(FMSG *errmsg){ arj_delay(5); error(errmsg);}/* Checks if the ARJ beta has expired */static void arj_exec_validation(){ #if !defined(COMMERCIAL)&&EXPIRABLE==1 struct timestamp cur_time, expiry_time; #endif limit=0; #if !defined(COMMERCIAL)&&EXPIRABLE==1 /* See top of this module for definitions */ cur_time_stamp(&cur_time); make_timestamp(&expiry_time, EXPIRY_YR, EXPIRY_MO, EXPIRY_DY, EXPIRY_H, EXPIRY_M, EXPIRY_S); if(ts_cmp(&cur_time, &expiry_time)>=0) limit=100; #endif /* The EXE validation must occur here. Skipped for speed-up */}/* This is not an optimization -- ASR fix for High C -- 05/04/2001 */#if COMPILER==HIGHC&&!defined(DEBUG) #pragma on(Optimize_for_space)#endif/* Main routine */int main(int argc, char *argv[]){ int cmd; int is_add_cmd; unsigned long start_time, proc_time; FILE_COUNT i; int j; int cur_arg; FILE *stream; char *tmp_ptr, *tptr, *endptr; int got_str=0; char *name; int flist_type; FILE_COUNT numfiles; int expand_wildcards; int entry; int sort_f; FILE_COUNT count; FILE_COUNT cur_file; int ansi_cpf; FILE *tmp_stdout; FILE_COUNT default_capacity=EXT_FILELIST_CAPACITY;#if TARGET==WIN32 win32_platform=1;#else win32_platform=0;#endif#ifdef COLOR_OUTPUT no_colors=redirected=!is_tty(stdout);#endif errorlevel=0; ignore_errors=0; ansi_cpf=0; in_key=1; params_max=argc+PARAMS_MAX; order=NULL; f_arg_array=NULL; #ifdef TZ_VAR tzset(); #endif ticks=get_ticks(); detect_lfns(); detect_eas(); ticks=get_ticks(); cmd=preprocess_cmdline(argc, argv); set_file_apis(use_ansi_cp); /* ARJ32 only (from v 2.72) */ #ifndef NO_FATAL_ERROR_HDL install_smart_handler(); #endif /* Perform STDOUT setup -- ASR fix for IBM C Set++, VisualAge C++ and GLIBC builds */ #ifdef STDOUT_SETBUF_FIX setbuf(stdout, NULL); setbuf(stderr, NULL); #endif new_stderr=NULL; if(quiet_mode) new_stderr=fopen(dev_null, m_w); if(quiet_mode==ARJ_QUIET||quiet_mode==ARJ_SILENT) new_stdout=new_stderr; /* Test for low-memory DOS situtations */ #if TARGET==DOS free(malloc_msg(10000)); farfree(farmalloc_msg(9000)); #endif /* Locate the executables. On UNIX systems, before assuming /usr/bin/arj, we try to guess if ARGV contains a somewhat qualified filename. This is a special hack for PACKAGER. */ exe_name=(char *)malloc_msg(CCHMAXPATH); #ifndef SKIP_GET_EXE_NAME get_exe_name(exe_name); #else get_exe_name(exe_name, argv[0]); #endif case_path(arj_env_name); init_crc(); start_time=get_ticks(); ctrlc_processing=0; tmp_archive_removed=0; tmp_archive_exists=0; is_registered=1; #ifdef COMMERCIAL is_commercial=1; #else is_commercial=0; #endif archive_suffixes=NULL; header=(char *)malloc_msg(HEADERSIZE_MAX); archive_name=(char *)malloc_msg(FILENAME_MAX); archive_name[0]='\0'; /* ASR fix for ARJ -i in ARJ 2.73 */ misc_buf=(char *)malloc_msg(FILENAME_MAX+INPUT_LENGTH); tmp_tmp_filename=(char *)malloc_msg(FILENAME_MAX); strcpy_buf=(char *)malloc_msg(200); order=(FILE_COUNT FAR *)farmalloc_msg(params_max*sizeof(FILE_COUNT)); f_arg_array=(char **)malloc_msg(params_max*sizeof(char *)); limit=20; parse_reg_key(); arj_exec_validation(); set_file_apis(use_ansi_cp); init(); flist_init(&flist_main, 0, FL_STANDARD); flist_init(&flist_exclusion, 0, FL_STANDARD); flist_init(&flist_order, 0, FL_STANDARD); flist_init(&flist_archive, 0, FL_STANDARD); #if defined(HAVE_EAS) flist_init(&flist_ea, 0, FL_STANDARD); flist_init(&flist_xea, 0, FL_STANDARD); #endif if(signal(SIGINT, ctrlc_handler)==SIG_ERR) error(M_SIGNAL_FAILED); #ifndef NO_TERM_HDL if(signal(SIGTERM, term_handler)==SIG_ERR) error(M_SIGNAL_FAILED); #endif #ifdef HAVE_BREAK_HANDLER if(signal(SIGBREAK, term_handler)==SIG_ERR) error(M_SIGNAL_FAILED); #endif atexit(final_cleanup); for(i=0; i<10; i++) is_registered=reg_validation(regdata+REG_KEY1_SHIFT, regdata+REG_KEY2_SHIFT, regdata+REG_NAME_SHIFT, regdata+REG_HDR_SHIFT); check_fmsg(CHKMSG_SKIP); if((tmp_stdout=new_stdout)==new_stderr&&!is_registered) new_stdout=stderr; msg_strcpy(strcpy_buf, M_VERSION); msg_cprintf(0, M_ARJ_BANNER, M_ARJ_BINDING, strcpy_buf, build_date); if(!is_registered&&!msg_strcmp((FMSG *)(regdata+REG_KEY2_SHIFT), M_REG_TYPE)) msg_cprintf(0, M_REGISTERED_TO, regdata+REG_NAME_SHIFT); else msg_cprintf(0, (FMSG *)lf); new_stdout=tmp_stdout; proc_time=get_ticks(); flist_init(&flist_exclusion, FCLIM_EXCLUSION, FL_STANDARD); #if defined(HAVE_EAS) flist_init(&flist_ea, FCLIM_EA, FL_STANDARD); flist_init(&flist_xea, FCLIM_EA, FL_STANDARD); #endif switch_char='\0'; if(!disable_arj_sw) { if((arj_env_str=malloc_env_str(arj_env_name))!=NULL) parse_arj_sw(cmd, arj_env_str, header); else { #ifndef SKIP_GET_EXE_NAME split_name(exe_name, archive_name, NULL); msg_strcat(archive_name, M_ARJ_CFG); if(file_exists(archive_name)) parse_arj_sw(cmd, archive_name, header); #else msg_strcpy(misc_buf, M_ARJ_CFG);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -