Esempio n. 1
0
static void run(int argc, const char* argv[])
{
    PO po;
    PO::Option& inputOpt = po.add("input").requiresValue("<filename>");
    PO::Option& widgetId = po.add("widgetid").requiresValue("<filename>");
    PO::Option& prefH = po.add("pref-h");
    PO::Option& prefCpp = po.add("pref-cpp");
    PO::Option& skin = po.add("skin");
    po.parse(argc, argv);

    // Try to load the XML file
    TiXmlDocument* doc = NULL;

    std::string inputFilename = po.value_of(inputOpt);
    if (!inputFilename.empty()) {
        base::FileHandle inputFile(base::open_file(inputFilename, "rb"));
        doc = new TiXmlDocument();
        doc->SetValue(inputFilename.c_str());
        if (!doc->LoadFile(inputFile.get()))
            throw std::runtime_error("invalid input file");
    }

    if (doc) {
        if (po.enabled(widgetId))
            gen_ui_class(doc, inputFilename, po.value_of(widgetId));
        else if (po.enabled(prefH))
            gen_pref_header(doc, inputFilename);
        else if (po.enabled(prefCpp))
            gen_pref_impl(doc, inputFilename);
        else if (po.enabled(skin))
            gen_skin_class(doc, inputFilename);
    }
}
Esempio n. 2
0
static void run(int argc, const char* argv[])
{
  PO po;
  PO::Option& inputOpt = po.add("input").requiresValue("<filename>");
  PO::Option& widgetId = po.add("widgetid").requiresValue("<id>");
  PO::Option& prefH = po.add("pref-h");
  PO::Option& prefCpp = po.add("pref-cpp");
  PO::Option& theme = po.add("theme");
  PO::Option& strings = po.add("strings");
  PO::Option& commandIds = po.add("command-ids");
  PO::Option& widgetsDir = po.add("widgets-dir").requiresValue("<dir>");
  PO::Option& stringsDir = po.add("strings-dir").requiresValue("<dir>");
  PO::Option& guiFile = po.add("gui-file").requiresValue("<filename>");
  po.parse(argc, argv);

  // Try to load the XML file
  TiXmlDocument* doc = nullptr;

  std::string inputFilename = po.value_of(inputOpt);
  if (!inputFilename.empty() &&
      base::get_file_extension(inputFilename) == "xml") {
    base::FileHandle inputFile(base::open_file(inputFilename, "rb"));
    doc = new TiXmlDocument();
    doc->SetValue(inputFilename.c_str());
    if (!doc->LoadFile(inputFile.get())) {
      std::cerr << doc->Value() << ":"
                << doc->ErrorRow() << ":"
                << doc->ErrorCol() << ": "
                << "error " << doc->ErrorId() << ": "
                << doc->ErrorDesc() << "\n";

      throw std::runtime_error("invalid input file");
    }
  }

  if (doc) {
    // Generate widget class
    if (po.enabled(widgetId))
      gen_ui_class(doc, inputFilename, po.value_of(widgetId));
    // Generate preference header file
    else if (po.enabled(prefH))
      gen_pref_header(doc, inputFilename);
    // Generate preference c++ file
    else if (po.enabled(prefCpp))
      gen_pref_impl(doc, inputFilename);
    // Generate theme class
    else if (po.enabled(theme))
      gen_theme_class(doc, inputFilename);
  }
  // Generate strings.ini.h file
  else if (po.enabled(strings)) {
    gen_strings_class(inputFilename);
  }
  // Generate command_ids.ini.h file
  else if (po.enabled(commandIds)) {
    gen_command_ids(inputFilename);
  }
  // Check all translation files (en.ini, es.ini, etc.)
  else if (po.enabled(widgetsDir) &&
           po.enabled(stringsDir)) {
    check_strings(po.value_of(widgetsDir),
                  po.value_of(stringsDir),
                  po.value_of(guiFile));
  }
}