00001 /*****************************************************************************\ 00002 * * 00003 * Name : dump_bytes * 00004 * Author : Chris Koeritz * 00005 * * 00006 * Purpose: * 00007 * * 00008 * Prints the files specified out in terms of their hex bytes. * 00009 * * 00010 ******************************************************************************* 00011 * Copyright (c) 1991-$now By Author. This program is free software; you can * 00012 * redistribute it and/or modify it under the terms of the GNU General Public * 00013 * License as published by the Free Software Foundation; either version 2 of * 00014 * the License or (at your option) any later version. This is online at: * 00015 * http://www.fsf.org/copyleft/gpl.html * 00016 * Please send any updates to: fred@gruntose.com * 00017 \*****************************************************************************/ 00018 00019 #include <basis/istring.h> 00020 #include <opsystem/byte_filer.h> 00021 #include <loggers/console_logger.h> 00022 #include <data_struct/static_memory_gremlin.h> 00023 #include <textual/byte_format.h> 00024 00025 HOOPLE_STARTUP_CODE; 00026 00027 const int MAXIMUM_BYTEDUMP_BUFFER_SIZE = 32768; 00028 // this is the size of the chunk we read from the files at a time. it is 00029 // important to make this a multiple of 16, since that's the size of the line 00030 // we use in the byte dumping. 00031 00032 #define console program_wide_logger() 00033 00034 int print_instructions_and_exit(char *program_name) 00035 { 00036 console.log(istring(istring::SPRINTF, "\n\ 00037 Usage:\n\t%s filename [filename]\n\n\ 00038 Prints out (on standard output) a byte dump of the files specified.\n\n", 00039 program_name).s()); 00040 return 12; 00041 } 00042 00043 int main(int argc, char *argv[]) 00044 { 00045 SET_DEFAULT_CONSOLE_LOGGER; 00046 00047 if (argc <= 1) return print_instructions_and_exit(argv[0]); 00048 else { 00049 int current_parameter = 0; 00050 /* 00051 if (argv[1][0] == '-') { 00052 if (argv[1][1] == 't') { 00053 current_parameter++; 00054 open_file_as_text = true; 00055 } else if (argv[1][1] == 'b') { 00056 current_parameter++; 00057 open_file_as_text = false; 00058 } else print_instructions_and_exit(argv[0]); 00059 } 00060 */ 00061 bool past_first_file = false; 00062 while (++current_parameter < argc) { 00063 if (past_first_file) { 00064 // we're into the second file so start using some white space. 00065 console.log(""); 00066 console.log(""); 00067 } 00068 past_first_file = true; // set condition for next time. 00069 istring name = argv[current_parameter]; 00070 byte_filer current(name, "rb"); 00071 if (!current.good()) { 00072 console.log(istring("Cannot find the file named \"") + name 00073 + istring("\".")); 00074 continue; 00075 } 00076 byte buff[MAXIMUM_BYTEDUMP_BUFFER_SIZE + 10]; 00077 // buffer plus some extra room. 00078 bool printed_header = false; 00079 int current_label = 0; 00080 while (true) { 00081 int bytes_read = current.read(buff, MAXIMUM_BYTEDUMP_BUFFER_SIZE); 00082 if (bytes_read <= 0) break; // no contents. 00083 //console.log(istring(istring::SPRINTF, "read %d bytes", bytes_read)); 00084 if (!printed_header) { 00085 console.log(name + ":"); 00086 console.log(""); // blank line. 00087 printed_header = true; 00088 } 00089 istring to_log = byte_format::text_dump(buff, bytes_read, 00090 current_label); 00091 if (to_log[to_log.end()] == '\n') 00092 to_log.zap(to_log.end(), to_log.end()); 00093 console.log(to_log); 00094 current_label += bytes_read; 00095 } 00096 } 00097 } 00098 return 0; 00099 } 00100 00101 #ifdef __BUILD_STATIC_APPLICATION__ 00102 // static dependencies found by buildor_gen_deps.sh: 00103 #include <basis/array.cpp> 00104 #include <basis/byte_array.cpp> 00105 #include <basis/callstack_tracker.cpp> 00106 #include <basis/chaos.cpp> 00107 #include <basis/convert_utf.cpp> 00108 #include <basis/definitions.cpp> 00109 #include <basis/earth_time.cpp> 00110 #include <basis/guards.cpp> 00111 #include <basis/istring.cpp> 00112 #include <basis/log_base.cpp> 00113 #include <basis/memory_checker.cpp> 00114 #include <basis/mutex.cpp> 00115 #include <basis/object_base.cpp> 00116 #include <basis/outcome.cpp> 00117 #include <basis/packable.cpp> 00118 #include <basis/portable.cpp> 00119 #include <basis/sequence.cpp> 00120 #include <basis/set.cpp> 00121 #include <basis/utility.cpp> 00122 #include <basis/version_record.cpp> 00123 #include <data_struct/amorph.cpp> 00124 #include <data_struct/bit_vector.cpp> 00125 #include <data_struct/byte_hasher.cpp> 00126 #include <data_struct/configurator.cpp> 00127 #include <data_struct/hash_table.cpp> 00128 #include <data_struct/pointer_hash.cpp> 00129 #include <data_struct/stack.cpp> 00130 #include <data_struct/static_memory_gremlin.cpp> 00131 #include <data_struct/string_hash.cpp> 00132 #include <data_struct/string_hasher.cpp> 00133 #include <data_struct/string_table.cpp> 00134 #include <data_struct/symbol_table.cpp> 00135 #include <data_struct/table_configurator.cpp> 00136 #include <loggers/console_logger.cpp> 00137 #include <loggers/file_logger.cpp> 00138 #include <loggers/locked_logger.cpp> 00139 #include <loggers/null_logger.cpp> 00140 #include <loggers/program_wide_logger.cpp> 00141 #include <opsystem/byte_filer.cpp> 00142 #include <opsystem/command_line.cpp> 00143 #include <opsystem/critical_events.cpp> 00144 #include <opsystem/directory.cpp> 00145 #include <opsystem/filename.cpp> 00146 #include <opsystem/ini_config.cpp> 00147 #include <opsystem/ini_parser.cpp> 00148 #include <opsystem/path_configuration.cpp> 00149 #include <opsystem/rendezvous.cpp> 00150 #include <textual/byte_format.cpp> 00151 #include <textual/parser_bits.cpp> 00152 #include <textual/string_manipulation.cpp> 00153 #include <textual/tokenizer.cpp> 00154 #endif // __BUILD_STATIC_APPLICATION__ 00155
1.5.1