00001 /*****************************************************************************\ 00002 * * 00003 * Name : find_non_ascii * 00004 * Author : Chris Koeritz * 00005 * * 00006 * Purpose: * 00007 * * 00008 * Reads through a file looking for bytes with value greater than 127. * 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 00024 HOOPLE_STARTUP_CODE; 00025 00026 const int BUFFER_SIZE = 32768; 00027 // this is the size of the chunk we read from the files at a time. it is 00028 // important to make this a multiple of 16, since that's the size of the line 00029 // we use in the byte dumping. 00030 00031 #define fnc_console program_wide_logger() 00032 00033 int print_instructions_and_exit(char *program_name) 00034 { 00035 fnc_console.log(istring(istring::SPRINTF, "\n\ 00036 Usage:\n\t%s filename [filename]\n\n\ 00037 Reads the files specified and reports characters whose value is greater\n\ 00038 than 127. The reported line number and character positions start at one\n\ 00039 rather than the programmer's zero.\n\n", 00040 program_name).s()); 00041 return 23; 00042 } 00043 00044 int main(int argc, char *argv[]) 00045 { 00046 SET_DEFAULT_CONSOLE_LOGGER; 00047 00048 if (argc <= 1) return print_instructions_and_exit(argv[0]); 00049 else { 00050 int current_parameter = 0; 00051 bool past_first_file = false; 00052 while (++current_parameter < argc) { 00053 if (past_first_file) { 00054 // we're into the second file so start using some white space. 00055 fnc_console.log(""); 00056 fnc_console.log(""); 00057 } 00058 past_first_file = true; // set condition for next time. 00059 istring name = argv[current_parameter]; 00060 byte_filer current(name, "rb"); 00061 if (!current.good()) { 00062 fnc_console.log(istring("Cannot find the file named \"") + name 00063 + istring("\".")); 00064 continue; 00065 } 00066 byte buff[BUFFER_SIZE + 10]; // buffer plus some extra room. 00067 int line = 0; 00068 while (true) { 00069 line++; 00070 int bytes_read = current.getline(buff, BUFFER_SIZE); 00071 if (bytes_read <= 0) break; // no contents. 00072 //fnc_console.log(istring(istring::SPRINTF, "read %d bytes", bytes_read)); 00073 00074 for (int i = 0; i < bytes_read; i++) { 00075 if (buff[i] > 127) { 00076 fnc_console.log(isprintf("non-ascii char %d at line %d " 00077 "posn %d in file %s", int(buff[i]), line, i + 1, name.s())); 00078 } 00079 } 00080 00081 } 00082 } 00083 } 00084 return 0; 00085 } 00086 00087 #ifdef __BUILD_STATIC_APPLICATION__ 00088 // static dependencies found by buildor_gen_deps.sh: 00089 #include <basis/array.cpp> 00090 #include <basis/byte_array.cpp> 00091 #include <basis/callstack_tracker.cpp> 00092 #include <basis/chaos.cpp> 00093 #include <basis/convert_utf.cpp> 00094 #include <basis/definitions.cpp> 00095 #include <basis/earth_time.cpp> 00096 #include <basis/guards.cpp> 00097 #include <basis/istring.cpp> 00098 #include <basis/log_base.cpp> 00099 #include <basis/memory_checker.cpp> 00100 #include <basis/mutex.cpp> 00101 #include <basis/object_base.cpp> 00102 #include <basis/outcome.cpp> 00103 #include <basis/packable.cpp> 00104 #include <basis/portable.cpp> 00105 #include <basis/sequence.cpp> 00106 #include <basis/set.cpp> 00107 #include <basis/utility.cpp> 00108 #include <basis/version_record.cpp> 00109 #include <data_struct/amorph.cpp> 00110 #include <data_struct/bit_vector.cpp> 00111 #include <data_struct/byte_hasher.cpp> 00112 #include <data_struct/configurator.cpp> 00113 #include <data_struct/hash_table.cpp> 00114 #include <data_struct/pointer_hash.cpp> 00115 #include <data_struct/stack.cpp> 00116 #include <data_struct/static_memory_gremlin.cpp> 00117 #include <data_struct/string_hash.cpp> 00118 #include <data_struct/string_hasher.cpp> 00119 #include <data_struct/string_table.cpp> 00120 #include <data_struct/symbol_table.cpp> 00121 #include <data_struct/table_configurator.cpp> 00122 #include <loggers/console_logger.cpp> 00123 #include <loggers/file_logger.cpp> 00124 #include <loggers/locked_logger.cpp> 00125 #include <loggers/null_logger.cpp> 00126 #include <loggers/program_wide_logger.cpp> 00127 #include <opsystem/byte_filer.cpp> 00128 #include <opsystem/command_line.cpp> 00129 #include <opsystem/critical_events.cpp> 00130 #include <opsystem/directory.cpp> 00131 #include <opsystem/filename.cpp> 00132 #include <opsystem/ini_config.cpp> 00133 #include <opsystem/ini_parser.cpp> 00134 #include <opsystem/path_configuration.cpp> 00135 #include <opsystem/rendezvous.cpp> 00136 #include <textual/byte_format.cpp> 00137 #include <textual/parser_bits.cpp> 00138 #include <textual/string_manipulation.cpp> 00139 #include <textual/tokenizer.cpp> 00140 #endif // __BUILD_STATIC_APPLICATION__ 00141
1.5.1