int cct_run(suite_fn *suites, int verbose_output) { suite_fn *suite; int tty = is_tty(1); verbose = verbose_output; for (suite = suites; *suite; suite++) { unsigned test_index = 0; while (true) { test_index = (*suite)(test_index + 1); if (test_index == 0) { /* We have reached the end of the suite. */ break; } } } if (failed_tests == 0) { printf("%sPASSED%s: %u assertion%s, %u test%s, %u suite%s\n", COLOR(tty, GREEN), COLOR(tty, END), total_asserts, plural_s(total_asserts), total_tests, plural_s(total_tests), total_suites, plural_s(total_suites)); } else { printf("%sFAILED%s: %u test%s\n", COLOR(tty, RED), COLOR(tty, END), failed_tests, plural_s(failed_tests)); } return failed_tests > 0 ? 1 : 0; }
// Either 1. Print directory structure of zip file given as filename or piped through stdin // or 2. Print contents of file contained in aforementioned zip file int main(int argc, char *argv[]) { zip_file file; std::vector<std::string> args; for(int i = 1; i < argc; i++) { args.push_back(argv[i]); } if(is_tty()) // Expect first argument to be zip file path { if(args.size() < 1) { std::cout << "usage: " << argv[0] << " zip_file [file_to_print]" << std::endl; std::cout << " (zip_file can be replaced by data piped from standard input)" << std::endl; return 1; } file.load(args.front()); args.erase(args.begin()); } else { #ifdef _WIN32 // Ensure that we are reading the raw binary data when using a pipe in Windows. _setmode(_fileno(stdin), O_BINARY); #endif file.load(std::cin); } if(args.empty()) { file.printdir(); } else { std::cout << file.read(args.front()) << std::endl; } return 0; }
std::ostream& operator<<(std::ostream& out, term x) { if (is_tty(out)) set_term_color(out, tty_codes[static_cast<size_t>(x)]); return out; }
void display_comment(char *cmt) #endif { unsigned char c; #if SFX_LEVEL>=ARJSFXV int is_ansi=0; #endif #if TARGET==OS2 USHORT af; #endif #if SFX_LEVEL>=ARJ if(new_stderr==new_stdout) return; #endif #if TARGET==OS2 fflush(stdout); VioGetAnsi(&af, 0); VioSetAnsi(ANSI_ON, 0); #endif while((c=*(cmt++))!='\0') { #if SFX_LEVEL>=ARJSFXV if(c==ANSI_ESC) is_ansi=1; #endif #if SFX_LEVEL>=ARJSFXV&&!defined(DIRECT_TO_ANSI) if(is_ansi) { display_ansi(c); if(c==LF) display_ansi(CR); } else { #endif /* Substitute non-printable control characters with "?"'s */ #ifndef DIRECT_TO_ANSI if(c<' '&&c!=TAB&&c!=LF&&c!=CR) c=UNDISP_CHAR; #endif #if SFX_LEVEL>=ARJSFXV nputc((int)c); #else fputc((int)c, stdout); #endif #if SFX_LEVEL>=ARJ if(c==LF) { lines_scrolled++; if(lines_scrolled>=lines_per_page-1) { lines_scrolled=0; if(!yes_on_all_queries&&prompt_for_more&&is_tty(stdout)) { if(!pause()) return; } } } #endif #if SFX_LEVEL>=ARJSFXV&&!defined(DIRECT_TO_ANSI) } #endif } #if SFX_LEVEL>=ARJSFXV if(is_ansi) { #ifdef DIRECT_TO_ANSI printf("\x1B[0m\n"); #else display_ansi(LF); #endif } #endif #if TARGET==OS2 VioSetAnsi(af, 0); #endif }
int extraction_stub(char *block, int block_len, int action) { char c; char *block_ptr; int cn; #if SFX_LEVEL>=ARJ if(!debug_enabled||strchr(debug_opt, 'c')==NULL) crc_for_block(block, block_len); #else crc32_for_block(block, block_len); #endif if(!file_packing) /* Not applicable for memory data */ { if(encmem_limit<block_len) /* Check for overrun */ error(M_BAD_HEADER); encmem_limit-=block_len; far_memmove(encblock_ptr, (char FAR *)block, block_len); encblock_ptr+=block_len; encmem_remain+=block_len; return(0); } /* Postprocessing */ #if SFX_LEVEL>=ARJ if(action==BOP_LIST||action==BOP_SEARCH||action==BOP_COMPARE||action==BOP_DISPLAY) return(block_op(action, block, block_len)); #endif if(atstream==NULL) return(0); /* Strip high bit from files created by different OS */ if(file_type==ARJT_TEXT&&host_os!=OS #if SFX_LEVEL>=ARJ &&type_override!=FT_BINARY #endif ) { block_ptr=block; while(block_len-->0) { c=*(block_ptr++); c&=0x7F; if(fputc((int)c, atstream)==EOF) error(M_DISK_FULL); } } else { /* HACK for IBM LIBC implementations under 32-bit OS/2 */ #if SFX_LEVEL>=ARJSFXV&&TARGET==OS2&&(COMPILER==ICC||defined(LIBC)) int fn=fileno(atstream); if(fn<6) { _setmode(fn, file_type?0x4000:0x8000); /* O_TEXT:O_BINARY */ cn=write(fn, block, block_len); } else cn=fwrite(block, 1, block_len, atstream); #else cn=fwrite(block, 1, block_len, atstream); #endif #if SFX_LEVEL>=ARJSFXV if(is_tty(atstream)) cn=block_len; #endif if(cn!=block_len) error(M_DISK_FULL); } return(0); }
int main(int argc, char *argv[]) { int cur_arg; #if SFX_LEVEL>=ARJSFXV int cmd; int is_add_cmd; unsigned long start_time, proc_time; FILE_COUNT i; FILE *stream; char *tmp_ptr, *tptr; int got_str; char *name; int flist_type; FILE_COUNT numfiles; int expand_wildcards; int entry; int sort_f; FILE_COUNT count; FILE_COUNT cur_file; int tmp_reg; #else char *tmp_ptr; #endif #ifdef COLOR_OUTPUT no_colors=redirected=!is_tty(stdout); #endif #if SFX_LEVEL>=ARJSFXV errorlevel=0; ignore_errors=0; new_stdout=stdout; lfn_supported=LFN_NOT_SUPPORTED; ticks=get_ticks(); detect_lfns(); detect_eas(); #ifndef NO_FATAL_ERROR_HDL install_smart_handler(); #endif build_crc32_table(); #else build_crc32_table(); detect_lfns(); file_packing=1; #endif #ifdef TZ_VAR tzset(); #endif #ifdef STDOUT_SETBUF_FIX /* ASR fix for IBM C Set / GLIBC */ setbuf(stdout, NULL); setbuf(stderr, NULL); #endif #if SFX_LEVEL>=ARJSFXV start_time=get_ticks(); flist_init(&flist_main, FCLIM_ARCHIVE, FL_STANDARD); ctrlc_processing=0; header=(char *)malloc_msg(HEADERSIZE_MAX); archive_name=(char *)malloc_msg(FILENAME_MAX); /* Original ARJSFX reserves 200 bytes for misc_buf but, taking into account that LFNs can be large enough, more space is to be reserved. */ misc_buf=(char *)malloc_msg(FILENAME_MAX+INPUT_LENGTH); tmp_tmp_filename=(char *)malloc_msg(FILENAME_MAX); limit=20; init(); 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 atexit(final_cleanup); #else tmp_tmp_filename[0]='\0'; target_dir=nullstr; garble_password=nullstr; extr_cmd_text=nullstr; #endif #ifndef SKIP_GET_EXE_NAME get_exe_name(archive_name); #else strcpy(archive_name, argv[0]); #endif exe_name=archive_name; #if SFX_LEVEL<=ARJSFX for(tmp_ptr=exe_name; *tmp_ptr!='\0'; tmp_ptr++) if(*tmp_ptr==PATHSEP_DEFAULT) exe_name=tmp_ptr+1; atexit(final_cleanup); signal(SIGINT, ctrlc_handler); #ifndef NO_TERM_HDL signal(SIGTERM, term_handler); #endif #endif check_fmsg(CHKMSG_SKIP); #if SFX_LEVEL>=ARJSFXV skip_switch_processing=0; #else switch_char=0; #endif for(cur_arg=1; cur_arg<argc; cur_arg++) parse_cmdline(argv[cur_arg]); #if SFX_LEVEL>=ARJSFXV if(install_errhdl) ignore_errors=1; if(quiet_mode) freopen(dev_null, m_w, stdout); #endif if(argc>1) skip_preset_options=1; arj_exec_validation(); if(help_issued) { #if SFX_LEVEL>=ARJSFXV show_sfx_logo(); #else msg_cprintf(0, M_ARJSFX_BANNER, exe_name); #endif check_fmsg(CHKMSG_SFX_HELP); #if SFX_LEVEL>=ARJSFXV exit(ARJ_ERL_SUCCESS); #else exit(ARJSFX_ERL_SUCCESS); #endif } #if SFX_LEVEL>=ARJSFXV if(limit!=0) wait_error(M_CRC_ERROR); limit=20; arj_exec_validation(); proc_time=get_ticks(); check_fmsg(CHKMSG_SKIP); perform_cmd(); #else process_archive(); #endif /* Cleanup for ARJSFXV */ #if SFX_LEVEL>=ARJSFXV file_arg_cleanup(); #endif if(errors>0) error(M_FOUND_N_ERRORS, errors); #if SFX_LEVEL>=ARJSFXV if(errorlevel!=ARJ_ERL_SUCCESS) exit(errorlevel); #endif #if SFX_LEVEL>=ARJSFXV if(extr_cmd_text[0]!='\0') #else if(execute_extr_cmd&&extr_cmd_text[0]!='\0') #endif { if(licensed_sfx) { msg_cprintf(0, M_EXECUTING_CMD, extr_cmd_text); arj_delay(2); exec_command(extr_cmd_text); } else { #if SFX_LEVEL>=ARJSFXV msg_sprintf(misc_buf, M_EXTR_CMD_QUERY, extr_cmd_text); if(query_action(REPLY_YES, QUERY_CRITICAL, (FMSG *)misc_buf)) exec_command(extr_cmd_text); #else msg_cprintf(0, M_EXTR_CMD_QUERY, extr_cmd_text); if(query_action()) exec_command(extr_cmd_text); #endif } } #if SFX_LEVEL>=ARJSFXV return(ARJ_ERL_SUCCESS); #else return(ARJSFX_ERL_SUCCESS); #endif }