1 /* parse_cmdline.h */ 2 #ifndef PARSE_CMD_LINE_H 3 #define PARSE_CMD_LINE_H 4 5 #include <stddef.h> 6 #include <stdint.h> 7 8 #ifdef __cplusplus 9 extern "C" { 10 #endif 11 12 /* The official name of the program */ 13 #define PROGRAM_NAME "RHash" 14 #define CMD_FILENAME "rhash" 15 16 #ifdef _WIN32 17 typedef wchar_t opt_tchar; 18 #else 19 typedef char opt_tchar; 20 #endif 21 22 /** 23 * Options bit flags and constants. 24 */ 25 enum { 26 /* program modes */ 27 MODE_CHECK = 0x1, 28 MODE_CHECK_EMBEDDED = 0x2, 29 MODE_UPDATE = 0x4, 30 MODE_BENCHMARK = 0x8, 31 MODE_TORRENT = 0x10, 32 33 /* misc options */ 34 OPT_EMBED_CRC = 0x20, 35 OPT_RECURSIVE = 0x40, 36 OPT_FOLLOW = 0x80, 37 OPT_SKIP_OK = 0x100, 38 OPT_IGNORE_CASE = 0x200, 39 OPT_VERBOSE = 0x400, 40 OPT_PERCENTS = 0x800, 41 OPT_SPEED = 0x1000, 42 OPT_BT_PRIVATE = 0x2000, 43 OPT_UPPERCASE = 0x4000, 44 OPT_LOWERCASE = 0x8000, 45 OPT_GOST_REVERSE = 0x10000, 46 OPT_BENCH_RAW = 0x20000, 47 OPT_NO_DETECT_BY_EXT = 0x40000, 48 OPT_HEX = 0x040000, 49 OPT_BASE32 = 0x080000, 50 OPT_BASE64 = 0x100000, 51 OPT_FMT_MODIFIERS = OPT_HEX | OPT_BASE32 | OPT_BASE64, 52 53 #ifdef _WIN32 54 OPT_UTF8 = 0x10000000, 55 OPT_ENC_WIN = 0x20000000, 56 OPT_ENC_DOS = 0x40000000, 57 OPT_ENCODING = OPT_UTF8 | OPT_ENC_WIN | OPT_ENC_DOS, 58 #endif 59 60 FMT_BSD = 1, 61 FMT_SFV = 2, 62 FMT_SIMPLE = 4, 63 FMT_MAGNET = 8, 64 }; 65 66 #define OPT_ED2K_LINK 0x80000000 67 68 struct vector_t; 69 70 /** 71 * Parsed program options. 72 */ 73 struct options_t 74 { 75 unsigned flags; /* program options */ 76 unsigned sum_flags; /* flags to specify what sums will be calculated */ 77 unsigned fmt; /* flags to specify output format to use */ 78 unsigned mode; /* flags to specify program mode */ 79 unsigned openssl_mask; /* bit-mask for enabled OpenSSL hash functions */ 80 char* printf_str; /* printf-like format */ 81 opt_tchar* template_file; /* printf-like template file path */ 82 opt_tchar* output; /* file to output calculation or checking results to */ 83 opt_tchar* log; /* file to log percents and other info to */ 84 opt_tchar* update_file; /* hash file to update */ 85 char* embed_crc_delimiter; 86 char path_separator; 87 int find_max_depth; 88 struct vector_t* files_accept; /* suffixes of files to process */ 89 struct vector_t* files_exclude; /* suffixes of files to exclude from processing */ 90 struct vector_t* crc_accept; /* suffixes of hash files to verify or update */ 91 struct vector_t* bt_announce; /* BitTorrent announce URL */ 92 size_t bt_piece_length; /* BitTorrent piece length */ 93 opt_tchar* bt_batch_file; /* path to save a batch torrent to */ 94 95 char** argv; 96 int has_files; /* flag: command line contain files */ 97 struct file_search_data* search_data; /* files obtained from the command line */ 98 struct vector_t* mem; /* allocated memory blocks that must be freed on exit */ 99 }; 100 extern struct options_t opt; 101 102 void read_options(int argc, char* argv[]); 103 void options_destroy(struct options_t*); 104 105 #ifdef _WIN32 106 int detect_encoding(wchar_t** wargv, int nArg); 107 #endif 108 109 #ifdef __cplusplus 110 } /* extern "C" */ 111 #endif /* __cplusplus */ 112 113 #endif /* PARSE_CMD_LINE_H */ 114