コード例 #1
0
ファイル: quickbook.cpp プロジェクト: cpascal/af-cpp
    static int
    parse_document(
        fs::path const& filein_
      , fs::path const& fileout_
      , fs::path const& deps_out_
      , fs::path const& locations_out_
      , fs::path const& xinclude_base_
      , int indent
      , int linewidth
      , bool pretty_print)
    {
        string_stream buffer;
        id_manager ids;

        int result = 0;

        try {
            quickbook::state state(filein_, xinclude_base_, buffer, ids);
            set_macros(state);

            if (state.error_count == 0) {
                state.add_dependency(filein_);
                state.current_file = load(filein_); // Throws load_error

                parse_file(state);

                if(state.error_count) {
                    detail::outerr()
                        << "Error count: " << state.error_count << ".\n";
                }
            }

            result = state.error_count ? 1 : 0;

            if (!deps_out_.empty())
            {
                fs::ofstream out(deps_out_);
                BOOST_FOREACH(quickbook::state::dependency_list::value_type
                        const& d, state.dependencies)
                {
                    if (d.second) {
                        out << detail::path_to_generic(d.first) << std::endl;
                    }
                }
            }

            if (!locations_out_.empty())
            {
                fs::ofstream out(locations_out_);
                BOOST_FOREACH(quickbook::state::dependency_list::value_type
                        const& d, state.dependencies)
                {
                    out << (d.second ? "+ " : "- ")
                        << detail::path_to_generic(d.first) << std::endl;
                }
            }
コード例 #2
0
ファイル: quickbook.cpp プロジェクト: CASL/vera_tpls
    static int
    parse_document(
        fs::path const& filein_
      , fs::path const& fileout_
      , fs::path const& xinclude_base_
      , int indent
      , int linewidth
      , bool pretty_print)
    {
        string_stream buffer;
        id_manager ids;

        int result = 0;

        try {
            actions actor(filein_, xinclude_base_, buffer, ids);
            set_macros(actor);

            if (actor.error_count == 0) {
                actor.current_file = load(filein_); // Throws load_error

                parse_file(actor);

                if(actor.error_count) {
                    detail::outerr()
                        << "Error count: " << actor.error_count << ".\n";
                }
            }

            result = actor.error_count ? 1 : 0;
        }
        catch (load_error& e) {
            detail::outerr(filein_) << detail::utf8(e.what()) << std::endl;
            result = 1;
        }

        if (result == 0)
        {
            std::string stage2 = ids.replace_placeholders(buffer.str());

            fs::ofstream fileout(fileout_);

            if (fileout.fail()) {
                ::quickbook::detail::outerr()
                    << "Error opening output file "
                    << fileout_
                    << std::endl;

                return 1;
            }

            if (pretty_print)
            {
                try
                {
                    fileout << post_process(stage2, indent, linewidth);
                }
                catch (quickbook::post_process_failure&)
                {
                    // fallback!
                    ::quickbook::detail::outerr()
                        << "Post Processing Failed."
                        << std::endl;
                    fileout << stage2;
                    return 1;
                }
            }
            else
            {
                fileout << stage2;
            }

            if (fileout.fail()) {
                ::quickbook::detail::outerr()
                    << "Error writing to output file "
                    << fileout_
                    << std::endl;

                return 1;
            }
        }

        return result;
    }