00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <data_struct/string_table.h>
00021 #include <opsystem/application_shell.h>
00022 #include <loggers/console_logger.h>
00023 #include <opsystem/filename.h>
00024 #include <opsystem/ini_config.h>
00025 #include <data_struct/static_memory_gremlin.h>
00026 #include <textual/list_parsing.h>
00027
00028 #include <stdlib.h>
00029
00030 #undef LOG
00031 #define LOG(to_print) program_wide_logger().log(to_print)
00032
00033 class ini_editor : public application_shell
00034 {
00035 public:
00036 ini_editor()
00037 : application_shell(static_class_name()),
00038 _app_name(filename(__argv[0]).basename()) {}
00039 IMPLEMENT_CLASS_NAME("ini_editor");
00040 virtual int execute();
00041 int print_instructions();
00042
00043 private:
00044 istring _app_name;
00045 };
00046
00047 int ini_editor::print_instructions()
00048 {
00049 LOG(isprintf("\
00050 %s: This program needs five parameters to process an ini file.\n\
00051 There are two major operations, read and write. The type of operation\n\
00052 should be the first parameter. The other parameters are similar for both\n\
00053 operations, except for the last parameter. These are as follows:\n\
00054 Reading:\n\
00055 \tread inifile section entry defaultvalue\n\
00056 This reads the \"inifile\" specified and looks for the \"section\" and\n\
00057 \"entry\" name in the file. It will either return (via standard output)\n\
00058 the value found there or it will return the \"defaultvalue\". No error\n\
00059 will be raised if the entry is missing, but the default signals that no\n\
00060 value was defined.\n\
00061 Additionally, if the entry name is the special value \"whole_section\",\n\
00062 then the entire section will be read and returned as a CSV list. If the\n\
00063 section is empty, then the default string is returned instead.\n\
00064 Writing:\n\
00065 \twrite inifile section entry newvalue\n\
00066 This writes a new item with contents \"newvalue\" into the \"inifile\"\n\
00067 in the \"section\" at the \"entry\" specified. This should always succeed\n\
00068 unless the ini file is not writable (in which case an error should be\n\
00069 returned). Nothing is send to standard output for a write operation.\n\
00070 ", _app_name.s()));
00071 return 23;
00072 }
00073
00074 int ini_editor::execute()
00075 {
00076 SET_DEFAULT_CONSOLE_LOGGER;
00077
00078 if (__argc < 6) return print_instructions();
00079
00080 istring operation = __argv[1];
00081 bool read_op = true;
00082 if ( (operation[0] == 'w') || (operation[0] == 'W') ) read_op = false;
00083 istring ini_file = __argv[2];
00084 istring section = __argv[3];
00085 istring entry = __argv[4];
00086 istring value = __argv[5];
00087 ini_configurator ini(ini_file, ini_configurator::RETURN_ONLY);
00088 if (read_op) {
00089
00090 istring found;
00091 if (entry == "whole_section") {
00092
00093 string_table found;
00094 bool worked = ini.get_section(section, found);
00095 if (!worked) program_wide_logger().log(value);
00096 else {
00097
00098 istring temp;
00099 list_parsing::create_csv_line(found, temp);
00100 program_wide_logger().log(temp);
00101 }
00102 } else {
00103 bool worked = ini.get(section, entry, found);
00104 program_wide_logger().eol(log_base::NO_ENDING);
00105 if (!worked) program_wide_logger().log(value);
00106 else program_wide_logger().log(found);
00107 }
00108 } else {
00109
00110 bool worked = ini.put(section, entry, value);
00111 if (!worked) exit(28);
00112 }
00113
00114 return 0;
00115 }
00116
00117 HOOPLE_MAIN(ini_editor, )
00118
00119 #ifdef __BUILD_STATIC_APPLICATION__
00120
00121 #include <basis/array.cpp>
00122 #include <basis/byte_array.cpp>
00123 #include <basis/callstack_tracker.cpp>
00124 #include <basis/chaos.cpp>
00125 #include <basis/convert_utf.cpp>
00126 #include <basis/definitions.cpp>
00127 #include <basis/earth_time.cpp>
00128 #include <basis/guards.cpp>
00129 #include <basis/istring.cpp>
00130 #include <basis/log_base.cpp>
00131 #include <basis/memory_checker.cpp>
00132 #include <basis/mutex.cpp>
00133 #include <basis/object_base.cpp>
00134 #include <basis/outcome.cpp>
00135 #include <basis/packable.cpp>
00136 #include <basis/portable.cpp>
00137 #include <basis/sequence.cpp>
00138 #include <basis/set.cpp>
00139 #include <basis/utility.cpp>
00140 #include <basis/version_record.cpp>
00141 #include <data_struct/amorph.cpp>
00142 #include <data_struct/bit_vector.cpp>
00143 #include <data_struct/byte_hasher.cpp>
00144 #include <data_struct/configurator.cpp>
00145 #include <data_struct/hash_table.cpp>
00146 #include <data_struct/pointer_hash.cpp>
00147 #include <data_struct/stack.cpp>
00148 #include <data_struct/static_memory_gremlin.cpp>
00149 #include <data_struct/string_hash.cpp>
00150 #include <data_struct/string_hasher.cpp>
00151 #include <data_struct/string_table.cpp>
00152 #include <data_struct/symbol_table.cpp>
00153 #include <data_struct/table_configurator.cpp>
00154 #include <loggers/console_logger.cpp>
00155 #include <loggers/file_logger.cpp>
00156 #include <loggers/locked_logger.cpp>
00157 #include <loggers/null_logger.cpp>
00158 #include <loggers/program_wide_logger.cpp>
00159 #include <opsystem/application_base.cpp>
00160 #include <opsystem/application_shell.cpp>
00161 #include <opsystem/byte_filer.cpp>
00162 #include <opsystem/command_line.cpp>
00163 #include <opsystem/critical_events.cpp>
00164 #include <opsystem/directory.cpp>
00165 #include <opsystem/filename.cpp>
00166 #include <opsystem/ini_config.cpp>
00167 #include <opsystem/ini_parser.cpp>
00168 #include <opsystem/path_configuration.cpp>
00169 #include <opsystem/rendezvous.cpp>
00170 #include <textual/byte_format.cpp>
00171 #include <textual/list_parsing.cpp>
00172 #include <textual/parser_bits.cpp>
00173 #include <textual/string_manipulation.cpp>
00174 #include <textual/tokenizer.cpp>
00175 #endif // __BUILD_STATIC_APPLICATION__
00176