merge_inis.cpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002 *                                                                             *
00003 *  Name   : merge_inis                                                        *
00004 *  Author : Chris Koeritz                                                     *
00005 *                                                                             *
00006 *  Purpose:                                                                   *
00007 *                                                                             *
00008 *    Takes an ini file with new content and merges it into an existing file.  *
00009 *                                                                             *
00010 *******************************************************************************
00011 * Copyright (c) 2007-$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/function.h>
00020 #include <basis/string_array.h>
00021 #include <data_struct/static_memory_gremlin.h>
00022 #include <data_struct/string_table.h>
00023 #include <loggers/console_logger.h>
00024 #include <opsystem/ini_config.h>
00025 
00026 HOOPLE_STARTUP_CODE;
00027 
00028 #define LOG(to_print) program_wide_logger().log(to_print)
00029 
00030 int main(int argc, char *argv[])
00031 {
00032   SET_DEFAULT_CONSOLE_LOGGER;
00033   if (argc < 4) {
00034     LOG(
00035 "The first parameter must be the name of an existing ini file with important\n"
00036 "contents.  The second parameter must be the name of a new ini file with\n"
00037 "updates to the original file.  The third parameter (and others if present)\n"
00038 "is the section name to be merged.  The contents of the sections specified\n"
00039 "will be copied from the second ini file into the existing ini file.");
00040     return 37;  // error.
00041   }
00042 
00043   istring main_ini_file = argv[1];
00044   istring second_ini = argv[2];
00045   string_array sections;
00046   for (int i = 3; i < argc; i++)
00047     sections += argv[i];
00048 
00049   ini_configurator ini(main_ini_file, ini_configurator::RETURN_ONLY);
00050   ini_configurator new_ini(second_ini, ini_configurator::RETURN_ONLY);
00051 
00052   for (int s = 0; s < sections.length(); s++) {
00053     istring section = sections[s];
00054     string_table found;
00055     new_ini.get_section(section, found);
00056 LOG(istring("working on section: ") + section);
00057     if (!found.symbols())
00058       LOG(istring("No symbols were found in the section named ") + section);
00059 
00060     for (int i = 0; i < found.symbols(); i++) {
00061       istring name = found.name(i);
00062       istring value = found.get(i);
00063       ini.store(section, name, value);
00064 LOG(istring("writing name=") + name + " value=" + value);
00065     }
00066   }
00067   return 0;
00068 }
00069 
00070 #ifdef __BUILD_STATIC_APPLICATION__
00071   // static dependencies found by buildor_gen_deps.sh:
00072   #include <basis/array.cpp>
00073   #include <basis/byte_array.cpp>
00074   #include <basis/callstack_tracker.cpp>
00075   #include <basis/chaos.cpp>
00076   #include <basis/convert_utf.cpp>
00077   #include <basis/definitions.cpp>
00078   #include <basis/earth_time.cpp>
00079   #include <basis/guards.cpp>
00080   #include <basis/istring.cpp>
00081   #include <basis/log_base.cpp>
00082   #include <basis/memory_checker.cpp>
00083   #include <basis/mutex.cpp>
00084   #include <basis/object_base.cpp>
00085   #include <basis/outcome.cpp>
00086   #include <basis/packable.cpp>
00087   #include <basis/portable.cpp>
00088   #include <basis/sequence.cpp>
00089   #include <basis/set.cpp>
00090   #include <basis/utility.cpp>
00091   #include <basis/version_record.cpp>
00092   #include <data_struct/amorph.cpp>
00093   #include <data_struct/bit_vector.cpp>
00094   #include <data_struct/byte_hasher.cpp>
00095   #include <data_struct/configurator.cpp>
00096   #include <data_struct/hash_table.cpp>
00097   #include <data_struct/pointer_hash.cpp>
00098   #include <data_struct/stack.cpp>
00099   #include <data_struct/static_memory_gremlin.cpp>
00100   #include <data_struct/string_hash.cpp>
00101   #include <data_struct/string_hasher.cpp>
00102   #include <data_struct/string_table.cpp>
00103   #include <data_struct/symbol_table.cpp>
00104   #include <data_struct/table_configurator.cpp>
00105   #include <loggers/console_logger.cpp>
00106   #include <loggers/file_logger.cpp>
00107   #include <loggers/locked_logger.cpp>
00108   #include <loggers/null_logger.cpp>
00109   #include <loggers/program_wide_logger.cpp>
00110   #include <opsystem/byte_filer.cpp>
00111   #include <opsystem/command_line.cpp>
00112   #include <opsystem/critical_events.cpp>
00113   #include <opsystem/directory.cpp>
00114   #include <opsystem/filename.cpp>
00115   #include <opsystem/ini_config.cpp>
00116   #include <opsystem/ini_parser.cpp>
00117   #include <opsystem/path_configuration.cpp>
00118   #include <opsystem/rendezvous.cpp>
00119   #include <textual/byte_format.cpp>
00120   #include <textual/parser_bits.cpp>
00121   #include <textual/string_manipulation.cpp>
00122   #include <textual/tokenizer.cpp>
00123 #endif // __BUILD_STATIC_APPLICATION__
00124 

Generated on Fri Nov 28 04:28:51 2008 for HOOPLE Libraries by  doxygen 1.5.1