From 6efece51f99980b824b199bbeb6452f03e6736c6 Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Tue, 27 Sep 2016 00:23:14 +0700 Subject: add x-verbs support (bzr r15136.1.1) --- src/CMakeLists.txt | 2 + src/main-cmdlineact.cpp | 35 ++++ src/main-cmdlineact.h | 9 +- src/main-cmdlinexact.cpp | 526 +++++++++++++++++++++++++++++++++++++++++++++++ src/main-cmdlinexact.h | 52 +++++ src/main.cpp | 22 ++ 6 files changed, 644 insertions(+), 2 deletions(-) create mode 100644 src/main-cmdlinexact.cpp create mode 100644 src/main-cmdlinexact.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9928f9694..6875eaa38 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -221,6 +221,7 @@ set(inkscape_SRC line-geometry.cpp line-snapper.cpp main-cmdlineact.cpp + main-cmdlinexact.cpp media.cpp message-context.cpp message-stack.cpp @@ -337,6 +338,7 @@ set(inkscape_SRC line-snapper.h macros.h main-cmdlineact.h + main-cmdlinexact.h media.h menus-skeleton.h message-context.h diff --git a/src/main-cmdlineact.cpp b/src/main-cmdlineact.cpp index c1b756ad5..2d0a5cfd6 100644 --- a/src/main-cmdlineact.cpp +++ b/src/main-cmdlineact.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include @@ -22,6 +23,7 @@ namespace Inkscape { std::list CmdLineAction::_list; +bool CmdLineAction::_requestQuit = false; CmdLineAction::CmdLineAction (bool isVerb, gchar const * arg) : _isVerb(isVerb), _arg(NULL) { if (arg != NULL) { @@ -39,10 +41,34 @@ CmdLineAction::~CmdLineAction () { } } +bool +CmdLineAction::isExtended() { + return false; +} + +void +CmdLineAction::doItX (ActionContext const & context) +{ + (void)context; + printf("CmdLineAction::doItX() %s\n", _arg); +} + void CmdLineAction::doIt (ActionContext const & context) { //printf("Doing: %s\n", _arg); if (_isVerb) { + if (isExtended()) { + //printf("Is extended\n"); + + doItX(context); + return; + } + + static std::string quit_verb_name = "FileQuit"; + if (quit_verb_name == _arg) { + _requestQuit = true; + return; + } Inkscape::Verb * verb = Inkscape::Verb::getbyid(_arg); if (verb == NULL) { printf(_("Unable to find verb ID '%s' specified on the command line.\n"), _arg); @@ -69,10 +95,19 @@ CmdLineAction::doIt (ActionContext const & context) { bool CmdLineAction::doList (ActionContext const & context) { bool hasActions = !_list.empty(); + if (!hasActions && _requestQuit) { + sp_file_exit(); + return true; + } + for (std::list::iterator i = _list.begin(); i != _list.end(); ++i) { CmdLineAction * entry = *i; entry->doIt(context); + if (_requestQuit) { + sp_file_exit(); + return true; + } } return hasActions; } diff --git a/src/main-cmdlineact.h b/src/main-cmdlineact.h index b8ec4403b..f50e70e5a 100644 --- a/src/main-cmdlineact.h +++ b/src/main-cmdlineact.h @@ -21,15 +21,20 @@ class ActionContext; class CmdLineAction { bool _isVerb; - char * _arg; - static std::list _list; + static bool _requestQuit; + +protected: + char * _arg; public: CmdLineAction (bool isVerb, char const * arg); virtual ~CmdLineAction (); + virtual bool isExtended(); + virtual void doItX (ActionContext const & context); void doIt (ActionContext const & context); + /** Return true if any actions were performed */ static bool doList (ActionContext const & context); static bool idle (void); diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp new file mode 100644 index 000000000..9efbfe8cd --- /dev/null +++ b/src/main-cmdlinexact.cpp @@ -0,0 +1,526 @@ +/* + * Authors: + * Dmitry Zhulanov + * + * Copyright (C) 2016 Authors + * + * Released under GNU GPL v2, read the file 'COPYING' for more information + * + * Format of xverbs.yaml + * + * verbose: yes # only "verbose: yes" enable logging + * run: + * # open document to process + * - xverb-id: XFileOpen, gfx_sources/loading_screen/sandclock_atlas.svg + * - xverb-id: XUndoLabel, fresh_document # set label for UndoToLabel xverb works + * # note: if something wrong with undo labels use verb EditUndo instead of XUndoLabel and UndoToLabel at all + * + * # select element to handle + * - xverb-id: XSelectElement, top_sand + * + * # verbs + * - verb-id: EditInvertInAllLayers + * - verb-id: EditDelete + * - verb-id: FitCanvasToDrawing + * + * # save element to separated svg document + * - xverb-id: XFileSaveAs, output/thegame/linux/data/gfx/loading_screen/top_sand.svg + * + * # also save png preview + * - xverb-id: XFileExportPNG, output/thegame/linux/data/gfx_preview/loading_screen/top_sand.png + * + * # return to the fresh_state of document + * - xverb-id: UndoToLabel, fresh_document + * + * # do any other handling + * + * # inkscape have a lot of useful verbs + * - verb-id: FileQuit + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include "main-cmdlinexact.h" +#include "yaml.h" +#include "extension/system.h" +#include "file.h" +#include +#include "sp-root.h" +#include "document-undo.h" +#include "util/units.h" +#include "sp-namedview.h" +#include "resource-manager.h" +#include "ui/dialog/font-substitution.h" +#include "extension/db.h" +#include "preferences.h" +#include "helper/png-write.h" +#include +#include +#include + +#define DPI_BASE Inkscape::Util::Quantity::convert(1, "in", "px") + +namespace +{ +bool s_verbose = false; + +bool createDirForFilename( const std::string &filename ) +{ + size_t found = filename.find_last_of("/\\"); + std::string output_directory = filename.substr(0,found); + + if( output_directory == filename ) + return true; + + if (g_mkdir_with_parents(output_directory.c_str(), 0755)) + { + printf("Can't create directory %s\n", output_directory.c_str()); + fflush(stdout); + + return false; + } + + return true; +} + +void xFileOpen( const Glib::ustring &uri ) +{ + if (s_verbose) { + printf("open %s\n", uri.c_str()); + fflush(stdout); + } + + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if (desktop) { + SPDocument *old_document = desktop->getDocument(); + desktop->setWaitingCursor(); + Inkscape::DocumentUndo::clearRedo(old_document); + } + + SPDocument *doc = NULL; + Inkscape::Extension::Extension *key = NULL; + try { + doc = Inkscape::Extension::open(key, uri.c_str()); + } catch (std::exception &e) { + doc = NULL; + std::string exeption_mgs = e.what(); + printf("Error: open %s:%s\n",uri.c_str(), exeption_mgs.c_str() ); + fflush(stdout); + } + + // Set viewBox if it doesn't exist + if (!doc->getRoot()->viewBox_set + && (doc->getRoot()->width.unit != SVGLength::PERCENT) + && (doc->getRoot()->height.unit != SVGLength::PERCENT)) { + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit()))); + } + + desktop->change_document(doc); + doc->emitResizedSignal(doc->getWidth().value("px"), doc->getHeight().value("px")); + if(desktop) + desktop->clearWaitingCursor(); + + doc->virgin = FALSE; + + // everyone who cares now has a reference, get rid of our`s + doc->doUnref(); + + // resize the window to match the document properties + sp_namedview_window_from_document(desktop); + sp_namedview_update_layers_from_document(desktop); + + if ( INKSCAPE.use_gui() ) { + // Perform a fixup pass for hrefs. + if ( Inkscape::ResourceManager::getManager().fixupBrokenLinks(doc) ) { + Glib::ustring msg = _("Broken links have been changed to point to existing files."); + desktop->showInfoDialog(msg); + } + + // Check for font substitutions + Inkscape::UI::Dialog::FontSubstitution::getInstance().checkFontSubstitutions(doc); + } +} + +void xFileSaveAs( Inkscape::ActionContext const & context, const Glib::ustring &uri ) +{ + SPDocument *doc = context.getDocument(); + if (s_verbose) { + printf("save as %s\n", uri.c_str()); + fflush(stdout); + } + + if( createDirForFilename( uri )) { + Inkscape::Extension::save( + Inkscape::Extension::db.get("org.inkscape.output.svg.inkscape"), + doc, uri.c_str(), false, false, true, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); + if (s_verbose) { + printf("save done: %s\n", uri.c_str() ); + fflush(stdout); + } + } + else + { + printf("can't create dirs for filename %s\n", uri.c_str() ); + fflush(stdout); + } +} + +void xFileExportPNG( Inkscape::ActionContext const & context, const Glib::ustring &uri ) +{ + if (s_verbose) { + printf("export png %s\n", uri.c_str()); + fflush(stdout); + } + + SPDocument *doc = context.getDocument(); + + gdouble dpi = 200.0; + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + dpi = prefs->getDouble("/dialogs/export/defaultxdpi/value", DPI_BASE); + + gdouble width = doc->getWidth().value(doc->getDisplayUnit()); + gdouble height = doc->getHeight().value(doc->getDisplayUnit()); + + gdouble bmwidth = (width) * dpi / DPI_BASE; + gdouble bmheight = (height) * dpi / DPI_BASE; + + int png_width = (int)(0.5 + bmwidth); + int png_height = (int)(0.5 + bmheight); + + SPNamedView *nv = desktop->getNamedView(); + + ExportResult status = sp_export_png_file(doc, uri.c_str(), + Geom::Rect(Geom::Point(0,0), Geom::Point(width, height)), png_width, png_height, dpi, dpi, + nv->pagecolor, 0, 0, TRUE); +} + +void xSelectElement( Inkscape::ActionContext const & context, const Glib::ustring &uri ) +{ + if (context.getDocument() == NULL || context.getSelection() == NULL) { return; } + + if (s_verbose) { + printf("select element: %s\n", uri.c_str()); + fflush(stdout); + } + + SPDocument * doc = context.getDocument(); + SPObject * obj = doc->getObjectById(uri); + + if (obj == NULL) { + printf(_("Unable to find node ID: '%s'\n"), uri.c_str()); + fflush(stdout); + return; + } + + Inkscape::Selection * selection = context.getSelection(); + selection->add(obj); + + if (s_verbose) { + printf("select done %s\n", uri.c_str()); + fflush(stdout); + } +} + +} // end of unnamed namespace + +namespace Inkscape { + +CmdLineXAction::CmdLineXAction (gchar const * arg, xaction_args_values_map_t &values_map): + CmdLineAction(true, arg), _values_map(values_map) { + this->arg = (char *)arg; + return; +} + +bool +CmdLineXAction::isExtended() { + return true; +} + +void +CmdLineXAction::doItX (ActionContext const & context) { + (void)(context); + + if( arg == "XFileSaveAs") + xFileSaveAs( context, _values_map["filename"] ); + else if (arg == "XFileOpen") + xFileOpen( _values_map["filename"] ); + else if (arg == "XFileExportPNG") + xFileExportPNG( context, _values_map["png_filename"] ); + else if (arg == "XSelectElement") + xSelectElement( context, _values_map["element-id"] ); + else + { + printf("unknown xverb: %s", arg.c_str()); + fflush(stdout); + } + + return; +} + +enum parser_state_t{ HANDLING_ROOT, + HANDLING_VERBOSE, // options + HANDLING_RUN, HANDLING_RUN_LIST, HANDLING_RUN_LIST_ENTRY }; // run entries + +struct verb_info_t +{ + bool xverb; + std::vector args; +}; + +typedef std::list verbs_list_t; + +static void tokenize(const std::string& str, std::vector& tokens, const std::string& delimiters = ",") +{ + // Skip delimiters at beginning. + std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); + + // Find first non-delimiter. + std::string::size_type pos = str.find_first_of(delimiters, lastPos); + + while (std::string::npos != pos || std::string::npos != lastPos) { + // Found a token, add it to the vector. + tokens.push_back(str.substr(lastPos, pos - lastPos)); + + // Skip delimiters. + lastPos = str.find_first_not_of(delimiters, pos); + + // Find next non-delimiter. + pos = str.find_first_of(delimiters, lastPos); + } +} + +void +CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { + FILE *fh = fopen(yaml_filename, "r"); + if(fh == NULL) { + printf("Failed to open file!\n"); + fflush(stdout); + return; + } + + yaml_parser_t parser; + if(!yaml_parser_initialize(&parser)) { + printf("Failed to initialize parser!\n"); + fflush(stdout); + return; + } + + /* Set input file */ + yaml_parser_set_input_file(&parser, fh); + + parser_state_t state = HANDLING_ROOT; + + + bool handling_key = false; + bool handling_value = false; + + std::string key; + verbs_list_t verbs_list; + + // parse + yaml_token_t token; + do { + yaml_parser_scan(&parser, &token); + switch(token.type) + { + // avoid "warning: enumeration value", "-Wswitch" + case YAML_NO_TOKEN: break; + case YAML_STREAM_START_TOKEN: break; + case YAML_STREAM_END_TOKEN: break; + case YAML_VERSION_DIRECTIVE_TOKEN: break; + case YAML_TAG_DIRECTIVE_TOKEN: break; + case YAML_DOCUMENT_START_TOKEN: break; + case YAML_DOCUMENT_END_TOKEN: break; + case YAML_FLOW_SEQUENCE_START_TOKEN: break; + case YAML_FLOW_SEQUENCE_END_TOKEN: break; + case YAML_FLOW_MAPPING_START_TOKEN: break; + case YAML_FLOW_MAPPING_END_TOKEN: break; + case YAML_FLOW_ENTRY_TOKEN: break; + case YAML_ALIAS_TOKEN: break; + case YAML_ANCHOR_TOKEN: break; + case YAML_TAG_TOKEN: break; + + /* Token types (read before actual token) */ + case YAML_KEY_TOKEN: + handling_key = true; + handling_value = false; + break; + case YAML_VALUE_TOKEN: + handling_key = false; + handling_value = true; + break; + + /* Block delimeters */ + case YAML_BLOCK_SEQUENCE_START_TOKEN: + if( state == HANDLING_ROOT ) + { + if( key == "run" ) + state = HANDLING_RUN; + } + break; + case YAML_BLOCK_ENTRY_TOKEN: + if( state == HANDLING_RUN ) + state = HANDLING_RUN_LIST; + else if( state == HANDLING_RUN_LIST ) + state = HANDLING_RUN_LIST_ENTRY; + else if( state == HANDLING_VERBOSE ) + state = HANDLING_ROOT; + break; + case YAML_BLOCK_END_TOKEN: + if( state == HANDLING_RUN_LIST_ENTRY ) + state = HANDLING_RUN_LIST; + else if( state == HANDLING_RUN_LIST ) + state = HANDLING_RUN; + else if( state == HANDLING_VERBOSE ) + state = HANDLING_ROOT; + else if( state == HANDLING_RUN ) + state = HANDLING_ROOT; + break; + + /* Data */ + case YAML_BLOCK_MAPPING_START_TOKEN: + break; + case YAML_SCALAR_TOKEN: + if( handling_key ) + key = (char *)token.data.scalar.value; + else if ( handling_value ) + { + if(state == HANDLING_RUN_LIST) + { + if(key == "xverb-id") + { + verb_info_t verb; + verb.xverb = true; + + std::string values = (char *)token.data.scalar.value; + tokenize(values, verb.args); + for( size_t i = 0; i < verb.args.size(); ++i ) + { + verb.args[i].erase(0, verb.args[i].find_first_not_of(' ')); //prefixing spaces + verb.args[i].erase(verb.args[i].find_last_not_of(' ')+1); //surfixing spaces + } + verbs_list.push_back(verb); + } + else if(key == "verb-id") + { + verb_info_t verb; + verb.xverb = false; + verb.args.push_back((char *)token.data.scalar.value); + verbs_list.push_back(verb); + } + else + { + printf("unknown verb type [%s]\n", key.c_str()); + fflush(stdout); + } + } + else if(state == HANDLING_ROOT) + { + std::string value = (char *)token.data.scalar.value; + if( (key == "verbose") && (value == "yes") ) + s_verbose = true; + } + } + break; + } + } while(token.type != YAML_STREAM_END_TOKEN); + + /* Cleanup */ + yaml_token_delete(&token); + yaml_parser_delete(&parser); + fclose(fh); + + typedef std::map undo_labels_map_t; + undo_labels_map_t undo_labels_map; + int undo_counter = 0; + + verbs_list_t::iterator iter = verbs_list.begin(); + for( ; iter != verbs_list.end(); ++iter ) + { + verb_info_t &verb = *iter; + std::string &verb_word = verb.args[0]; + if( s_verbose ) + printf("handle %s and args count is %d\n", verb_word.c_str(), (int)verb.args.size()); + + if( verb.args.size() == 2 ) + { + xaction_args_values_map_t values_map; + if (verb_word == "XFileSaveAs" || verb_word == "XFileOpen") + { + std::string &filename = verb.args[1]; + values_map["filename"] = filename; + new CmdLineXAction(verb_word.c_str(), values_map); + } + else if (verb_word == "XUndoLabel") + undo_labels_map[verb.args[1]] = undo_counter; + else if (verb_word == "UndoToLabel") + { + undo_labels_map_t::iterator iter = undo_labels_map.find(verb.args[1]); + if(iter != undo_labels_map.end()) + { + int counter = undo_counter - iter->second; + if( counter > 0 ) + { + for(int i = 0; i < counter; ++i) + new CmdLineAction(true, "EditUndo"); + undo_counter -= counter; + } + } + } + else if (verb_word == "XSelectElement") + { + ++undo_counter; + values_map["element-id"] = verb.args[1]; + new CmdLineXAction(verb_word.c_str(), values_map); + } + else if (verb_word == "XFileExportPNG") + { + std::string &png_filename = verb.args[1]; + values_map["png_filename"] = png_filename; + if(createDirForFilename( png_filename )) { + new CmdLineXAction(verb_word.c_str(), values_map); + } + } + } + else if(!verb.xverb) + { + ++undo_counter; + new CmdLineAction(true, verb.args[0].c_str()); + } + + else + { + printf("Unhadled verb %s\n", verb.args[0].c_str()); + fflush(stdout); + } + } + + fflush(stdout); + return; +} + + +} // Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/main-cmdlinexact.h b/src/main-cmdlinexact.h new file mode 100644 index 000000000..1ac630e55 --- /dev/null +++ b/src/main-cmdlinexact.h @@ -0,0 +1,52 @@ + +#ifndef __INK_MAIN_CMD_LINE_XACTIONS_H__ +#define __INK_MAIN_CMD_LINE_XACTIONS_H__ + +/** \file + * Extended actions that can be queued at the yaml file + */ + +/* + * Authors: + * Dmitry Zhulanov + * + * Copyright (C) 2016 Authors + * + * Released under GNU GPL v2.x, read the file 'COPYING' for more information + */ + +#include "main-cmdlineact.h" +#include + +namespace Inkscape { + +typedef std::map xaction_args_values_map_t; + +class CmdLineXAction : public CmdLineAction { + std::string arg; + xaction_args_values_map_t _values_map; +public: + CmdLineXAction (gchar const * arg, xaction_args_values_map_t &values_map); + + virtual void doItX (ActionContext const & context); + virtual bool isExtended(); + + static void createActionsFromYAML( gchar const *filename ); +}; + +} // Inkscape + + + +#endif /* __INK_MAIN_CMD_LINE_XACTIONS_H__ */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/main.cpp b/src/main.cpp index 004d96191..d9f11ed8b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -112,6 +112,7 @@ #endif #include "main-cmdlineact.h" +#include "main-cmdlinexact.h" #include "widgets/icon.h" #include @@ -127,6 +128,7 @@ enum { SP_ARG_NOGUI, SP_ARG_GUI, SP_ARG_FILE, + SP_ARG_XVERBS, SP_ARG_PRINT, SP_ARG_EXPORT_PNG, SP_ARG_EXPORT_DPI, @@ -227,6 +229,9 @@ static gchar *sp_export_png_utf8 = NULL; static gchar *sp_export_svg_utf8 = NULL; static gchar *sp_global_printer_utf8 = NULL; +static gchar *sp_xverbs_yaml_utf8 = NULL; +static gchar *sp_xverbs_yaml = NULL; + /** * Reset variables to default values. @@ -301,6 +306,11 @@ struct poptOption options[] = { N_("Open specified document(s) (option string may be excluded)"), N_("FILENAME")}, + {"xverbs", 'B', + POPT_ARG_STRING, &sp_xverbs_yaml, SP_ARG_XVERBS, + N_("xverbs command"), + N_("XVERBS_FILENAME")}, + {"print", 'p', POPT_ARG_STRING, &sp_global_printer, SP_ARG_PRINT, N_("Print document(s) to specified output file (use '| program' for pipe)"), @@ -881,6 +891,7 @@ static int sp_common_main( int argc, char const **argv, GSList **flDest ) fixupSingleFilename( &sp_export_png, &sp_export_png_utf8 ); fixupSingleFilename( &sp_export_svg, &sp_export_svg_utf8 ); fixupSingleFilename( &sp_global_printer, &sp_global_printer_utf8 ); + fixupSingleFilename( &sp_xverbs_yaml, &sp_xverbs_yaml_utf8 ); } else { @@ -890,6 +901,9 @@ static int sp_common_main( int argc, char const **argv, GSList **flDest ) sp_export_svg_utf8 = g_strdup( sp_export_svg ); if ( sp_global_printer ) sp_global_printer_utf8 = g_strdup( sp_global_printer ); + if ( sp_xverbs_yaml ) + sp_xverbs_yaml_utf8 = g_strdup( sp_xverbs_yaml ); + } #ifdef WITH_DBUS @@ -2131,6 +2145,14 @@ sp_process_args(poptContext ctx) } break; } + case SP_ARG_XVERBS: { + gchar const *fn = poptGetOptArg(ctx); + if (fn != NULL) { + sp_xverbs_yaml = g_strdup(fn); + Inkscape::CmdLineXAction::createActionsFromYAML((const char *)sp_xverbs_yaml); + } + break; + } case SP_ARG_VERSION: { printf("Inkscape %s (%s)\n", Inkscape::version_string, __DATE__); exit(0); -- cgit v1.2.3 From 38cd1793fb8ac7983c001834193d41b5b5b4e660 Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Tue, 27 Sep 2016 21:17:03 +0700 Subject: update intends and brackets (bzr r15136.1.3) --- src/main-cmdlinexact.cpp | 661 +++++++++++++++++++++++------------------------ 1 file changed, 320 insertions(+), 341 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index 9efbfe8cd..940abfca4 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -7,6 +7,7 @@ * Released under GNU GPL v2, read the file 'COPYING' for more information * * Format of xverbs.yaml + * using: $ inkscape -B xverbs.yaml * * verbose: yes # only "verbose: yes" enable logging * run: @@ -80,29 +81,28 @@ bool createDirForFilename( const std::string &filename ) std::string output_directory = filename.substr(0,found); if( output_directory == filename ) - return true; + return true; - if (g_mkdir_with_parents(output_directory.c_str(), 0755)) - { - printf("Can't create directory %s\n", output_directory.c_str()); - fflush(stdout); + if (g_mkdir_with_parents(output_directory.c_str(), 0755)) { + printf("Can't create directory %s\n", output_directory.c_str()); + fflush(stdout); - return false; - } + return false; + } return true; } void xFileOpen( const Glib::ustring &uri ) { - if (s_verbose) { - printf("open %s\n", uri.c_str()); - fflush(stdout); - } + if (s_verbose) { + printf("open %s\n", uri.c_str()); + fflush(stdout); + } SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (desktop) { - SPDocument *old_document = desktop->getDocument(); + SPDocument *old_document = desktop->getDocument(); desktop->setWaitingCursor(); Inkscape::DocumentUndo::clearRedo(old_document); } @@ -114,123 +114,122 @@ void xFileOpen( const Glib::ustring &uri ) } catch (std::exception &e) { doc = NULL; std::string exeption_mgs = e.what(); - printf("Error: open %s:%s\n",uri.c_str(), exeption_mgs.c_str() ); - fflush(stdout); + printf("Error: open %s:%s\n",uri.c_str(), exeption_mgs.c_str() ); + fflush(stdout); } - // Set viewBox if it doesn't exist - if (!doc->getRoot()->viewBox_set - && (doc->getRoot()->width.unit != SVGLength::PERCENT) - && (doc->getRoot()->height.unit != SVGLength::PERCENT)) { - doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit()))); - } - - desktop->change_document(doc); - doc->emitResizedSignal(doc->getWidth().value("px"), doc->getHeight().value("px")); - if(desktop) - desktop->clearWaitingCursor(); - - doc->virgin = FALSE; - - // everyone who cares now has a reference, get rid of our`s - doc->doUnref(); - - // resize the window to match the document properties - sp_namedview_window_from_document(desktop); - sp_namedview_update_layers_from_document(desktop); - - if ( INKSCAPE.use_gui() ) { - // Perform a fixup pass for hrefs. - if ( Inkscape::ResourceManager::getManager().fixupBrokenLinks(doc) ) { - Glib::ustring msg = _("Broken links have been changed to point to existing files."); - desktop->showInfoDialog(msg); - } - - // Check for font substitutions - Inkscape::UI::Dialog::FontSubstitution::getInstance().checkFontSubstitutions(doc); - } + // Set viewBox if it doesn't exist + if (!doc->getRoot()->viewBox_set + && (doc->getRoot()->width.unit != SVGLength::PERCENT) + && (doc->getRoot()->height.unit != SVGLength::PERCENT)) { + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit()))); + } + + desktop->change_document(doc); + doc->emitResizedSignal(doc->getWidth().value("px"), doc->getHeight().value("px")); + if(desktop) + desktop->clearWaitingCursor(); + + doc->virgin = FALSE; + + // everyone who cares now has a reference, get rid of our`s + doc->doUnref(); + + // resize the window to match the document properties + sp_namedview_window_from_document(desktop); + sp_namedview_update_layers_from_document(desktop); + + if ( INKSCAPE.use_gui() ) { + // Perform a fixup pass for hrefs. + if ( Inkscape::ResourceManager::getManager().fixupBrokenLinks(doc) ) { + Glib::ustring msg = _("Broken links have been changed to point to existing files."); + desktop->showInfoDialog(msg); + } + + // Check for font substitutions + Inkscape::UI::Dialog::FontSubstitution::getInstance().checkFontSubstitutions(doc); + } } void xFileSaveAs( Inkscape::ActionContext const & context, const Glib::ustring &uri ) { - SPDocument *doc = context.getDocument(); - if (s_verbose) { - printf("save as %s\n", uri.c_str()); - fflush(stdout); - } - - if( createDirForFilename( uri )) { - Inkscape::Extension::save( - Inkscape::Extension::db.get("org.inkscape.output.svg.inkscape"), - doc, uri.c_str(), false, false, true, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); - if (s_verbose) { - printf("save done: %s\n", uri.c_str() ); - fflush(stdout); - } - } - else - { - printf("can't create dirs for filename %s\n", uri.c_str() ); - fflush(stdout); - } + SPDocument *doc = context.getDocument(); + if (s_verbose) { + printf("save as %s\n", uri.c_str()); + fflush(stdout); + } + + if( createDirForFilename( uri )) { + Inkscape::Extension::save( + Inkscape::Extension::db.get("org.inkscape.output.svg.inkscape"), + doc, uri.c_str(), false, false, true, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); + if (s_verbose) { + printf("save done: %s\n", uri.c_str() ); + fflush(stdout); + } + } + else { + printf("can't create dirs for filename %s\n", uri.c_str() ); + fflush(stdout); + } } void xFileExportPNG( Inkscape::ActionContext const & context, const Glib::ustring &uri ) { - if (s_verbose) { - printf("export png %s\n", uri.c_str()); - fflush(stdout); - } - - SPDocument *doc = context.getDocument(); - - gdouble dpi = 200.0; - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - dpi = prefs->getDouble("/dialogs/export/defaultxdpi/value", DPI_BASE); - - gdouble width = doc->getWidth().value(doc->getDisplayUnit()); - gdouble height = doc->getHeight().value(doc->getDisplayUnit()); - - gdouble bmwidth = (width) * dpi / DPI_BASE; - gdouble bmheight = (height) * dpi / DPI_BASE; - - int png_width = (int)(0.5 + bmwidth); - int png_height = (int)(0.5 + bmheight); - - SPNamedView *nv = desktop->getNamedView(); - - ExportResult status = sp_export_png_file(doc, uri.c_str(), - Geom::Rect(Geom::Point(0,0), Geom::Point(width, height)), png_width, png_height, dpi, dpi, - nv->pagecolor, 0, 0, TRUE); + if (s_verbose) { + printf("export png %s\n", uri.c_str()); + fflush(stdout); + } + + SPDocument *doc = context.getDocument(); + + gdouble dpi = 200.0; + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + dpi = prefs->getDouble("/dialogs/export/defaultxdpi/value", DPI_BASE); + + gdouble width = doc->getWidth().value(doc->getDisplayUnit()); + gdouble height = doc->getHeight().value(doc->getDisplayUnit()); + + gdouble bmwidth = (width) * dpi / DPI_BASE; + gdouble bmheight = (height) * dpi / DPI_BASE; + + int png_width = (int)(0.5 + bmwidth); + int png_height = (int)(0.5 + bmheight); + + SPNamedView *nv = desktop->getNamedView(); + + ExportResult status = sp_export_png_file(doc, uri.c_str(), + Geom::Rect(Geom::Point(0,0), Geom::Point(width, height)), png_width, png_height, dpi, dpi, + nv->pagecolor, 0, 0, TRUE); } void xSelectElement( Inkscape::ActionContext const & context, const Glib::ustring &uri ) { - if (context.getDocument() == NULL || context.getSelection() == NULL) { return; } + if (context.getDocument() == NULL || context.getSelection() == NULL) { return; } - if (s_verbose) { - printf("select element: %s\n", uri.c_str()); - fflush(stdout); - } + if (s_verbose) { + printf("select element: %s\n", uri.c_str()); + fflush(stdout); + } - SPDocument * doc = context.getDocument(); - SPObject * obj = doc->getObjectById(uri); + SPDocument * doc = context.getDocument(); + SPObject * obj = doc->getObjectById(uri); - if (obj == NULL) { - printf(_("Unable to find node ID: '%s'\n"), uri.c_str()); - fflush(stdout); - return; - } + if (obj == NULL) { + printf(_("Unable to find node ID: '%s'\n"), uri.c_str()); + fflush(stdout); + return; + } - Inkscape::Selection * selection = context.getSelection(); - selection->add(obj); + Inkscape::Selection * selection = context.getSelection(); + selection->add(obj); - if (s_verbose) { - printf("select done %s\n", uri.c_str()); - fflush(stdout); - } + if (s_verbose) { + printf("select done %s\n", uri.c_str()); + fflush(stdout); + } } } // end of unnamed namespace @@ -238,45 +237,44 @@ void xSelectElement( Inkscape::ActionContext const & context, const Glib::ustrin namespace Inkscape { CmdLineXAction::CmdLineXAction (gchar const * arg, xaction_args_values_map_t &values_map): - CmdLineAction(true, arg), _values_map(values_map) { - this->arg = (char *)arg; - return; + CmdLineAction(true, arg), _values_map(values_map) { + this->arg = (char *)arg; + return; } bool CmdLineXAction::isExtended() { - return true; + return true; } void CmdLineXAction::doItX (ActionContext const & context) { - (void)(context); - - if( arg == "XFileSaveAs") - xFileSaveAs( context, _values_map["filename"] ); - else if (arg == "XFileOpen") - xFileOpen( _values_map["filename"] ); - else if (arg == "XFileExportPNG") - xFileExportPNG( context, _values_map["png_filename"] ); - else if (arg == "XSelectElement") - xSelectElement( context, _values_map["element-id"] ); - else - { - printf("unknown xverb: %s", arg.c_str()); - fflush(stdout); - } - - return; + (void)(context); + + if( arg == "XFileSaveAs") + xFileSaveAs( context, _values_map["filename"] ); + else if (arg == "XFileOpen") + xFileOpen( _values_map["filename"] ); + else if (arg == "XFileExportPNG") + xFileExportPNG( context, _values_map["png_filename"] ); + else if (arg == "XSelectElement") + xSelectElement( context, _values_map["element-id"] ); + else { + printf("unknown xverb: %s", arg.c_str()); + fflush(stdout); + } + + return; } enum parser_state_t{ HANDLING_ROOT, - HANDLING_VERBOSE, // options - HANDLING_RUN, HANDLING_RUN_LIST, HANDLING_RUN_LIST_ENTRY }; // run entries + HANDLING_VERBOSE, // options + HANDLING_RUN, HANDLING_RUN_LIST, HANDLING_RUN_LIST_ENTRY }; // run entries struct verb_info_t { - bool xverb; - std::vector args; + bool xverb; + std::vector args; }; typedef std::list verbs_list_t; @@ -303,212 +301,193 @@ static void tokenize(const std::string& str, std::vector& tokens, c void CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { - FILE *fh = fopen(yaml_filename, "r"); - if(fh == NULL) { - printf("Failed to open file!\n"); - fflush(stdout); - return; - } - - yaml_parser_t parser; - if(!yaml_parser_initialize(&parser)) { - printf("Failed to initialize parser!\n"); - fflush(stdout); - return; - } - - /* Set input file */ - yaml_parser_set_input_file(&parser, fh); - - parser_state_t state = HANDLING_ROOT; - - - bool handling_key = false; - bool handling_value = false; - - std::string key; - verbs_list_t verbs_list; - - // parse - yaml_token_t token; - do { - yaml_parser_scan(&parser, &token); - switch(token.type) - { - // avoid "warning: enumeration value", "-Wswitch" - case YAML_NO_TOKEN: break; - case YAML_STREAM_START_TOKEN: break; - case YAML_STREAM_END_TOKEN: break; - case YAML_VERSION_DIRECTIVE_TOKEN: break; - case YAML_TAG_DIRECTIVE_TOKEN: break; - case YAML_DOCUMENT_START_TOKEN: break; - case YAML_DOCUMENT_END_TOKEN: break; - case YAML_FLOW_SEQUENCE_START_TOKEN: break; - case YAML_FLOW_SEQUENCE_END_TOKEN: break; - case YAML_FLOW_MAPPING_START_TOKEN: break; - case YAML_FLOW_MAPPING_END_TOKEN: break; - case YAML_FLOW_ENTRY_TOKEN: break; - case YAML_ALIAS_TOKEN: break; - case YAML_ANCHOR_TOKEN: break; - case YAML_TAG_TOKEN: break; - - /* Token types (read before actual token) */ - case YAML_KEY_TOKEN: - handling_key = true; - handling_value = false; - break; - case YAML_VALUE_TOKEN: - handling_key = false; - handling_value = true; - break; - - /* Block delimeters */ - case YAML_BLOCK_SEQUENCE_START_TOKEN: - if( state == HANDLING_ROOT ) - { - if( key == "run" ) - state = HANDLING_RUN; - } - break; - case YAML_BLOCK_ENTRY_TOKEN: - if( state == HANDLING_RUN ) - state = HANDLING_RUN_LIST; - else if( state == HANDLING_RUN_LIST ) - state = HANDLING_RUN_LIST_ENTRY; - else if( state == HANDLING_VERBOSE ) - state = HANDLING_ROOT; - break; - case YAML_BLOCK_END_TOKEN: - if( state == HANDLING_RUN_LIST_ENTRY ) - state = HANDLING_RUN_LIST; - else if( state == HANDLING_RUN_LIST ) - state = HANDLING_RUN; - else if( state == HANDLING_VERBOSE ) - state = HANDLING_ROOT; - else if( state == HANDLING_RUN ) - state = HANDLING_ROOT; - break; - - /* Data */ - case YAML_BLOCK_MAPPING_START_TOKEN: - break; - case YAML_SCALAR_TOKEN: - if( handling_key ) - key = (char *)token.data.scalar.value; - else if ( handling_value ) - { - if(state == HANDLING_RUN_LIST) - { - if(key == "xverb-id") - { - verb_info_t verb; - verb.xverb = true; - - std::string values = (char *)token.data.scalar.value; - tokenize(values, verb.args); - for( size_t i = 0; i < verb.args.size(); ++i ) - { - verb.args[i].erase(0, verb.args[i].find_first_not_of(' ')); //prefixing spaces - verb.args[i].erase(verb.args[i].find_last_not_of(' ')+1); //surfixing spaces - } - verbs_list.push_back(verb); - } - else if(key == "verb-id") - { - verb_info_t verb; - verb.xverb = false; - verb.args.push_back((char *)token.data.scalar.value); - verbs_list.push_back(verb); - } - else - { - printf("unknown verb type [%s]\n", key.c_str()); - fflush(stdout); - } - } - else if(state == HANDLING_ROOT) - { - std::string value = (char *)token.data.scalar.value; - if( (key == "verbose") && (value == "yes") ) - s_verbose = true; - } - } - break; - } - } while(token.type != YAML_STREAM_END_TOKEN); - - /* Cleanup */ - yaml_token_delete(&token); - yaml_parser_delete(&parser); - fclose(fh); - - typedef std::map undo_labels_map_t; - undo_labels_map_t undo_labels_map; - int undo_counter = 0; - - verbs_list_t::iterator iter = verbs_list.begin(); - for( ; iter != verbs_list.end(); ++iter ) - { - verb_info_t &verb = *iter; - std::string &verb_word = verb.args[0]; - if( s_verbose ) - printf("handle %s and args count is %d\n", verb_word.c_str(), (int)verb.args.size()); - - if( verb.args.size() == 2 ) - { - xaction_args_values_map_t values_map; - if (verb_word == "XFileSaveAs" || verb_word == "XFileOpen") - { - std::string &filename = verb.args[1]; - values_map["filename"] = filename; - new CmdLineXAction(verb_word.c_str(), values_map); - } - else if (verb_word == "XUndoLabel") - undo_labels_map[verb.args[1]] = undo_counter; - else if (verb_word == "UndoToLabel") - { - undo_labels_map_t::iterator iter = undo_labels_map.find(verb.args[1]); - if(iter != undo_labels_map.end()) - { - int counter = undo_counter - iter->second; - if( counter > 0 ) - { - for(int i = 0; i < counter; ++i) - new CmdLineAction(true, "EditUndo"); - undo_counter -= counter; - } - } - } - else if (verb_word == "XSelectElement") - { - ++undo_counter; - values_map["element-id"] = verb.args[1]; - new CmdLineXAction(verb_word.c_str(), values_map); - } - else if (verb_word == "XFileExportPNG") - { - std::string &png_filename = verb.args[1]; - values_map["png_filename"] = png_filename; - if(createDirForFilename( png_filename )) { - new CmdLineXAction(verb_word.c_str(), values_map); - } - } - } - else if(!verb.xverb) - { - ++undo_counter; - new CmdLineAction(true, verb.args[0].c_str()); - } - - else - { - printf("Unhadled verb %s\n", verb.args[0].c_str()); - fflush(stdout); - } - } - - fflush(stdout); - return; + FILE *fh = fopen(yaml_filename, "r"); + if(fh == NULL) { + printf("Failed to open file!\n"); + fflush(stdout); + return; + } + + yaml_parser_t parser; + if(!yaml_parser_initialize(&parser)) { + printf("Failed to initialize parser!\n"); + fflush(stdout); + return; + } + + /* Set input file */ + yaml_parser_set_input_file(&parser, fh); + + parser_state_t state = HANDLING_ROOT; + + + bool handling_key = false; + bool handling_value = false; + + std::string key; + verbs_list_t verbs_list; + + // parse + yaml_token_t token; + do { + yaml_parser_scan(&parser, &token); + switch(token.type) + { + // avoid "warning: enumeration value", "-Wswitch" + case YAML_NO_TOKEN: break; + case YAML_STREAM_START_TOKEN: break; + case YAML_STREAM_END_TOKEN: break; + case YAML_VERSION_DIRECTIVE_TOKEN: break; + case YAML_TAG_DIRECTIVE_TOKEN: break; + case YAML_DOCUMENT_START_TOKEN: break; + case YAML_DOCUMENT_END_TOKEN: break; + case YAML_FLOW_SEQUENCE_START_TOKEN: break; + case YAML_FLOW_SEQUENCE_END_TOKEN: break; + case YAML_FLOW_MAPPING_START_TOKEN: break; + case YAML_FLOW_MAPPING_END_TOKEN: break; + case YAML_FLOW_ENTRY_TOKEN: break; + case YAML_ALIAS_TOKEN: break; + case YAML_ANCHOR_TOKEN: break; + case YAML_TAG_TOKEN: break; + + /* Token types (read before actual token) */ + case YAML_KEY_TOKEN: + handling_key = true; + handling_value = false; + break; + case YAML_VALUE_TOKEN: + handling_key = false; + handling_value = true; + break; + + /* Block delimeters */ + case YAML_BLOCK_SEQUENCE_START_TOKEN: + if( state == HANDLING_ROOT ) { + if( key == "run" ) + state = HANDLING_RUN; + } + break; + case YAML_BLOCK_ENTRY_TOKEN: + if( state == HANDLING_RUN ) + state = HANDLING_RUN_LIST; + else if( state == HANDLING_RUN_LIST ) + state = HANDLING_RUN_LIST_ENTRY; + else if( state == HANDLING_VERBOSE ) + state = HANDLING_ROOT; + break; + case YAML_BLOCK_END_TOKEN: + if( state == HANDLING_RUN_LIST_ENTRY ) + state = HANDLING_RUN_LIST; + else if( state == HANDLING_RUN_LIST ) + state = HANDLING_RUN; + else if( state == HANDLING_VERBOSE ) + state = HANDLING_ROOT; + else if( state == HANDLING_RUN ) + state = HANDLING_ROOT; + break; + + /* Data */ + case YAML_BLOCK_MAPPING_START_TOKEN: + break; + case YAML_SCALAR_TOKEN: + if( handling_key ) + key = (char *)token.data.scalar.value; + else if ( handling_value ) { + if(state == HANDLING_RUN_LIST) { + if(key == "xverb-id") { + verb_info_t verb; + verb.xverb = true; + + std::string values = (char *)token.data.scalar.value; + tokenize(values, verb.args); + for( size_t i = 0; i < verb.args.size(); ++i ) { + verb.args[i].erase(0, verb.args[i].find_first_not_of(' ')); //prefixing spaces + verb.args[i].erase(verb.args[i].find_last_not_of(' ')+1); //surfixing spaces + } + verbs_list.push_back(verb); + } + else if(key == "verb-id") { + verb_info_t verb; + verb.xverb = false; + verb.args.push_back((char *)token.data.scalar.value); + verbs_list.push_back(verb); + } + else { + printf("unknown verb type [%s]\n", key.c_str()); + fflush(stdout); + } + } + else if(state == HANDLING_ROOT) { + std::string value = (char *)token.data.scalar.value; + if( (key == "verbose") && (value == "yes") ) + s_verbose = true; + } + } + break; + } + } while(token.type != YAML_STREAM_END_TOKEN); + + /* Cleanup */ + yaml_token_delete(&token); + yaml_parser_delete(&parser); + fclose(fh); + + typedef std::map undo_labels_map_t; + undo_labels_map_t undo_labels_map; + int undo_counter = 0; + + verbs_list_t::iterator iter = verbs_list.begin(); + for( ; iter != verbs_list.end(); ++iter ) { + verb_info_t &verb = *iter; + std::string &verb_word = verb.args[0]; + if( s_verbose ) + printf("handle %s and args count is %d\n", verb_word.c_str(), (int)verb.args.size()); + + if( verb.args.size() == 2 ) { + xaction_args_values_map_t values_map; + if (verb_word == "XFileSaveAs" || verb_word == "XFileOpen") { + std::string &filename = verb.args[1]; + values_map["filename"] = filename; + new CmdLineXAction(verb_word.c_str(), values_map); + } + else if (verb_word == "XUndoLabel") + undo_labels_map[verb.args[1]] = undo_counter; + else if (verb_word == "UndoToLabel") { + undo_labels_map_t::iterator iter = undo_labels_map.find(verb.args[1]); + if(iter != undo_labels_map.end()) { + int counter = undo_counter - iter->second; + if( counter > 0 ) { + for(int i = 0; i < counter; ++i) + new CmdLineAction(true, "EditUndo"); + undo_counter -= counter; + } + } + } + else if (verb_word == "XSelectElement") { + ++undo_counter; + values_map["element-id"] = verb.args[1]; + new CmdLineXAction(verb_word.c_str(), values_map); + } + else if (verb_word == "XFileExportPNG") { + std::string &png_filename = verb.args[1]; + values_map["png_filename"] = png_filename; + if(createDirForFilename( png_filename )) { + new CmdLineXAction(verb_word.c_str(), values_map); + } + } + } + else if(!verb.xverb) { + ++undo_counter; + new CmdLineAction(true, verb.args[0].c_str()); + } + else { + printf("Unhadled verb %s\n", verb.args[0].c_str()); + fflush(stdout); + } + } + + fflush(stdout); + return; } -- cgit v1.2.3 From 10476bfa9f215afe2d5ea368269c44eebe5d0628 Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Tue, 27 Sep 2016 21:25:42 +0700 Subject: fix indention (bzr r15136.1.4) --- src/main-cmdlineact.cpp | 144 ++++++++++++++++++++++++------------------------ 1 file changed, 72 insertions(+), 72 deletions(-) (limited to 'src') diff --git a/src/main-cmdlineact.cpp b/src/main-cmdlineact.cpp index 2d0a5cfd6..cea1291c7 100644 --- a/src/main-cmdlineact.cpp +++ b/src/main-cmdlineact.cpp @@ -26,106 +26,106 @@ std::list CmdLineAction::_list; bool CmdLineAction::_requestQuit = false; CmdLineAction::CmdLineAction (bool isVerb, gchar const * arg) : _isVerb(isVerb), _arg(NULL) { - if (arg != NULL) { - _arg = g_strdup(arg); - } + if (arg != NULL) { + _arg = g_strdup(arg); + } - _list.insert(_list.end(), this); + _list.insert(_list.end(), this); - return; + return; } CmdLineAction::~CmdLineAction () { - if (_arg != NULL) { - g_free(_arg); - } + if (_arg != NULL) { + g_free(_arg); + } } bool CmdLineAction::isExtended() { - return false; + return false; } void CmdLineAction::doItX (ActionContext const & context) { - (void)context; - printf("CmdLineAction::doItX() %s\n", _arg); + (void)context; + printf("CmdLineAction::doItX() %s\n", _arg); } void CmdLineAction::doIt (ActionContext const & context) { - //printf("Doing: %s\n", _arg); - if (_isVerb) { - if (isExtended()) { - //printf("Is extended\n"); - - doItX(context); - return; - } - - static std::string quit_verb_name = "FileQuit"; - if (quit_verb_name == _arg) { - _requestQuit = true; - return; - } - Inkscape::Verb * verb = Inkscape::Verb::getbyid(_arg); - if (verb == NULL) { - printf(_("Unable to find verb ID '%s' specified on the command line.\n"), _arg); - return; - } - SPAction * action = verb->get_action(context); - sp_action_perform(action, NULL); - } else { - if (context.getDocument() == NULL || context.getSelection() == NULL) { return; } - - SPDocument * doc = context.getDocument(); - SPObject * obj = doc->getObjectById(_arg); - if (obj == NULL) { - printf(_("Unable to find node ID: '%s'\n"), _arg); - return; - } - - Inkscape::Selection * selection = context.getSelection(); - selection->add(obj); - } - return; + //printf("Doing: %s\n", _arg); + if (_isVerb) { + if (isExtended()) { + //printf("Is extended\n"); + + doItX(context); + return; + } + + static std::string quit_verb_name = "FileQuit"; + if (quit_verb_name == _arg) { + _requestQuit = true; + return; + } + Inkscape::Verb * verb = Inkscape::Verb::getbyid(_arg); + if (verb == NULL) { + printf(_("Unable to find verb ID '%s' specified on the command line.\n"), _arg); + return; + } + SPAction * action = verb->get_action(context); + sp_action_perform(action, NULL); + } else { + if (context.getDocument() == NULL || context.getSelection() == NULL) { return; } + + SPDocument * doc = context.getDocument(); + SPObject * obj = doc->getObjectById(_arg); + if (obj == NULL) { + printf(_("Unable to find node ID: '%s'\n"), _arg); + return; + } + + Inkscape::Selection * selection = context.getSelection(); + selection->add(obj); + } + return; } bool CmdLineAction::doList (ActionContext const & context) { bool hasActions = !_list.empty(); - if (!hasActions && _requestQuit) { - sp_file_exit(); - return true; - } - - for (std::list::iterator i = _list.begin(); - i != _list.end(); ++i) { - CmdLineAction * entry = *i; - entry->doIt(context); - if (_requestQuit) { - sp_file_exit(); - return true; - } - } + if (!hasActions && _requestQuit) { + sp_file_exit(); + return true; + } + + for (std::list::iterator i = _list.begin(); + i != _list.end(); ++i) { + CmdLineAction * entry = *i; + entry->doIt(context); + if (_requestQuit) { + sp_file_exit(); + return true; + } + } return hasActions; } bool CmdLineAction::idle (void) { - std::list desktops; - INKSCAPE.get_all_desktops(desktops); - - // We're going to assume one desktop per document, because no one - // should have had time to make more at this point. - for (std::list::iterator i = desktops.begin(); - i != desktops.end(); ++i) { - SPDesktop * desktop = *i; - //Inkscape::UI::View::View * view = dynamic_cast(desktop); - doList(ActionContext(desktop)); - } - return false; + std::list desktops; + INKSCAPE.get_all_desktops(desktops); + + // We're going to assume one desktop per document, because no one + // should have had time to make more at this point. + for (std::list::iterator i = desktops.begin(); + i != desktops.end(); ++i) { + SPDesktop * desktop = *i; + //Inkscape::UI::View::View * view = dynamic_cast(desktop); + doList(ActionContext(desktop)); + } + return false; } } // Inkscape -- cgit v1.2.3 From ef6e004b46469da3419554758bd0c0ed47df286f Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Tue, 27 Sep 2016 21:38:32 +0700 Subject: no need to FileQuit verb checking (bzr r15136.1.5) --- src/main-cmdlineact.cpp | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'src') diff --git a/src/main-cmdlineact.cpp b/src/main-cmdlineact.cpp index cea1291c7..fc0f50cd4 100644 --- a/src/main-cmdlineact.cpp +++ b/src/main-cmdlineact.cpp @@ -23,7 +23,6 @@ namespace Inkscape { std::list CmdLineAction::_list; -bool CmdLineAction::_requestQuit = false; CmdLineAction::CmdLineAction (bool isVerb, gchar const * arg) : _isVerb(isVerb), _arg(NULL) { if (arg != NULL) { @@ -64,11 +63,6 @@ CmdLineAction::doIt (ActionContext const & context) { return; } - static std::string quit_verb_name = "FileQuit"; - if (quit_verb_name == _arg) { - _requestQuit = true; - return; - } Inkscape::Verb * verb = Inkscape::Verb::getbyid(_arg); if (verb == NULL) { printf(_("Unable to find verb ID '%s' specified on the command line.\n"), _arg); @@ -95,19 +89,10 @@ CmdLineAction::doIt (ActionContext const & context) { bool CmdLineAction::doList (ActionContext const & context) { bool hasActions = !_list.empty(); - if (!hasActions && _requestQuit) { - sp_file_exit(); - return true; - } - for (std::list::iterator i = _list.begin(); i != _list.end(); ++i) { CmdLineAction * entry = *i; entry->doIt(context); - if (_requestQuit) { - sp_file_exit(); - return true; - } } return hasActions; } -- cgit v1.2.3 From 2de5e2452a8cd319e195eb77099e5a3a8898c94f Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Tue, 27 Sep 2016 23:25:28 +0700 Subject: ignore additional arguments of x-verbs (bzr r15136.1.6) --- src/main-cmdlinexact.cpp | 98 +++++++++++++++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index 940abfca4..a498f8425 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -437,44 +437,74 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { int undo_counter = 0; verbs_list_t::iterator iter = verbs_list.begin(); - for( ; iter != verbs_list.end(); ++iter ) { + for (;iter != verbs_list.end(); ++iter) { verb_info_t &verb = *iter; std::string &verb_word = verb.args[0]; - if( s_verbose ) + if (s_verbose) printf("handle %s and args count is %d\n", verb_word.c_str(), (int)verb.args.size()); - if( verb.args.size() == 2 ) { - xaction_args_values_map_t values_map; - if (verb_word == "XFileSaveAs" || verb_word == "XFileOpen") { - std::string &filename = verb.args[1]; - values_map["filename"] = filename; - new CmdLineXAction(verb_word.c_str(), values_map); - } - else if (verb_word == "XUndoLabel") - undo_labels_map[verb.args[1]] = undo_counter; - else if (verb_word == "UndoToLabel") { - undo_labels_map_t::iterator iter = undo_labels_map.find(verb.args[1]); - if(iter != undo_labels_map.end()) { - int counter = undo_counter - iter->second; - if( counter > 0 ) { - for(int i = 0; i < counter; ++i) - new CmdLineAction(true, "EditUndo"); - undo_counter -= counter; - } - } - } - else if (verb_word == "XSelectElement") { - ++undo_counter; - values_map["element-id"] = verb.args[1]; - new CmdLineXAction(verb_word.c_str(), values_map); - } - else if (verb_word == "XFileExportPNG") { - std::string &png_filename = verb.args[1]; - values_map["png_filename"] = png_filename; - if(createDirForFilename( png_filename )) { - new CmdLineXAction(verb_word.c_str(), values_map); - } - } + if (verb_word == "XFileOpen") { + if( verb.args.size() < 2 ) + { + printf("bad arguments for XFileOpen\n"); + continue; + } + + xaction_args_values_map_t values_map; + values_map["filename"] = verb.args[1]; + new CmdLineXAction(verb_word.c_str(), values_map); + } else if (verb_word == "XFileSaveAs") + { + if (verb.args.size() < 2) { + printf("bad arguments for XFileSaveAs\n"); + continue; + } + + xaction_args_values_map_t values_map; + values_map["filename"] = verb.args[1]; + new CmdLineXAction(verb_word.c_str(), values_map); + } else if (verb_word == "XUndoLabel") { + if (verb.args.size() < 2) { + printf("bad arguments for XUndoLabel\n"); + continue; + } + undo_labels_map[verb.args[1]] = undo_counter; + } else if (verb_word == "UndoToLabel") { + if (verb.args.size() < 2) { + printf("bad arguments for UndoToLabel\n"); + continue; + } + + undo_labels_map_t::iterator iter = undo_labels_map.find(verb.args[1]); + if(iter != undo_labels_map.end()) { + int counter = undo_counter - iter->second; + if( counter > 0 ) { + for(int i = 0; i < counter; ++i) + new CmdLineAction(true, "EditUndo"); + undo_counter -= counter; + } + } + } else if (verb_word == "XSelectElement") { + if (verb.args.size() < 2) { + printf("bad arguments for XSelectElement\n"); + continue; + } + ++undo_counter; + + xaction_args_values_map_t values_map; + values_map["element-id"] = verb.args[1]; + new CmdLineXAction(verb_word.c_str(), values_map); + } else if (verb_word == "XFileExportPNG") { + if (verb.args.size() < 2) { + printf("bad arguments for XFileExportPNG\n"); + continue; + } + + xaction_args_values_map_t values_map; + std::string &png_filename = verb.args[1]; + values_map["png_filename"] = png_filename; + if(createDirForFilename( png_filename )) + new CmdLineXAction(verb_word.c_str(), values_map); } else if(!verb.xverb) { ++undo_counter; -- cgit v1.2.3 From d9c220b750654b229096a9f62f24480e100c8aa8 Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Thu, 29 Sep 2016 21:47:23 +0700 Subject: allow optional args for xverbs (bzr r15136.1.7) --- src/main-cmdlinexact.cpp | 185 ++++++++++++++++++++++++----------------------- src/verbs.cpp | 8 +- src/verbs.h | 2 +- 3 files changed, 102 insertions(+), 93 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index a498f8425..ddf8a73eb 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -68,6 +68,7 @@ #include #include #include +#include #define DPI_BASE Inkscape::Util::Quantity::convert(1, "in", "px") @@ -93,6 +94,35 @@ bool createDirForFilename( const std::string &filename ) return true; } +std::vector vectorFromString(const std::string &csv) +{ + std::vector result; + + std::string delimiters = ","; + + // Skip delimiters at beginning. + std::string::size_type lastPos = csv.find_first_not_of(delimiters, 0); + + // Find first non-delimiter. + std::string::size_type pos = csv.find_first_of(delimiters, lastPos); + + while (std::string::npos != pos || std::string::npos != lastPos) { + // Found a token, add it to the vector. + std::string token = csv.substr(lastPos, pos - lastPos); + token.erase(0, token.find_first_not_of(' ')); //prefixing spaces + token.erase(token.find_last_not_of(' ')+1); //surfixing spaces + result.push_back(token); + + // Skip delimiters. + lastPos = csv.find_first_not_of(delimiters, pos); + + // Find next non-delimiter. + pos = csv.find_first_of(delimiters, lastPos); + } + + return result; +} + void xFileOpen( const Glib::ustring &uri ) { if (s_verbose) { @@ -279,25 +309,6 @@ struct verb_info_t typedef std::list verbs_list_t; -static void tokenize(const std::string& str, std::vector& tokens, const std::string& delimiters = ",") -{ - // Skip delimiters at beginning. - std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); - - // Find first non-delimiter. - std::string::size_type pos = str.find_first_of(delimiters, lastPos); - - while (std::string::npos != pos || std::string::npos != lastPos) { - // Found a token, add it to the vector. - tokens.push_back(str.substr(lastPos, pos - lastPos)); - - // Skip delimiters. - lastPos = str.find_first_not_of(delimiters, pos); - - // Find next non-delimiter. - pos = str.find_first_of(delimiters, lastPos); - } -} void CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { @@ -397,19 +408,15 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { if(key == "xverb-id") { verb_info_t verb; verb.xverb = true; - - std::string values = (char *)token.data.scalar.value; - tokenize(values, verb.args); - for( size_t i = 0; i < verb.args.size(); ++i ) { - verb.args[i].erase(0, verb.args[i].find_first_not_of(' ')); //prefixing spaces - verb.args[i].erase(verb.args[i].find_last_not_of(' ')+1); //surfixing spaces - } + verb.args = vectorFromString((char *)token.data.scalar.value); + if ((verb.args.size() > 1) && Verb::getbyid((char *)token.data.scalar.value)) + verb.xverb = false; verbs_list.push_back(verb); } else if(key == "verb-id") { verb_info_t verb; verb.xverb = false; - verb.args.push_back((char *)token.data.scalar.value); + verb.args = vectorFromString((char *)token.data.scalar.value); verbs_list.push_back(verb); } else { @@ -443,68 +450,68 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { if (s_verbose) printf("handle %s and args count is %d\n", verb_word.c_str(), (int)verb.args.size()); - if (verb_word == "XFileOpen") { - if( verb.args.size() < 2 ) - { - printf("bad arguments for XFileOpen\n"); - continue; - } - - xaction_args_values_map_t values_map; - values_map["filename"] = verb.args[1]; - new CmdLineXAction(verb_word.c_str(), values_map); - } else if (verb_word == "XFileSaveAs") - { - if (verb.args.size() < 2) { - printf("bad arguments for XFileSaveAs\n"); - continue; - } - - xaction_args_values_map_t values_map; - values_map["filename"] = verb.args[1]; - new CmdLineXAction(verb_word.c_str(), values_map); - } else if (verb_word == "XUndoLabel") { - if (verb.args.size() < 2) { - printf("bad arguments for XUndoLabel\n"); - continue; - } - undo_labels_map[verb.args[1]] = undo_counter; - } else if (verb_word == "UndoToLabel") { - if (verb.args.size() < 2) { - printf("bad arguments for UndoToLabel\n"); - continue; - } - - undo_labels_map_t::iterator iter = undo_labels_map.find(verb.args[1]); - if(iter != undo_labels_map.end()) { - int counter = undo_counter - iter->second; - if( counter > 0 ) { - for(int i = 0; i < counter; ++i) - new CmdLineAction(true, "EditUndo"); - undo_counter -= counter; - } - } - } else if (verb_word == "XSelectElement") { - if (verb.args.size() < 2) { - printf("bad arguments for XSelectElement\n"); - continue; - } - ++undo_counter; - - xaction_args_values_map_t values_map; - values_map["element-id"] = verb.args[1]; - new CmdLineXAction(verb_word.c_str(), values_map); - } else if (verb_word == "XFileExportPNG") { - if (verb.args.size() < 2) { - printf("bad arguments for XFileExportPNG\n"); - continue; - } - - xaction_args_values_map_t values_map; - std::string &png_filename = verb.args[1]; - values_map["png_filename"] = png_filename; - if(createDirForFilename( png_filename )) - new CmdLineXAction(verb_word.c_str(), values_map); + if (verb_word == "XFileOpen") { + if( verb.args.size() < 2 ) + { + printf("bad arguments for XFileOpen\n"); + continue; + } + + xaction_args_values_map_t values_map; + values_map["filename"] = verb.args[1]; + new CmdLineXAction(verb_word.c_str(), values_map); + } else if (verb_word == "XFileSaveAs") + { + if (verb.args.size() < 2) { + printf("bad arguments for XFileSaveAs\n"); + continue; + } + + xaction_args_values_map_t values_map; + values_map["filename"] = verb.args[1]; + new CmdLineXAction(verb_word.c_str(), values_map); + } else if (verb_word == "XUndoLabel") { + if (verb.args.size() < 2) { + printf("bad arguments for XUndoLabel\n"); + continue; + } + undo_labels_map[verb.args[1]] = undo_counter; + } else if (verb_word == "UndoToLabel") { + if (verb.args.size() < 2) { + printf("bad arguments for UndoToLabel\n"); + continue; + } + + undo_labels_map_t::iterator iter = undo_labels_map.find(verb.args[1]); + if(iter != undo_labels_map.end()) { + int counter = undo_counter - iter->second; + if( counter > 0 ) { + for(int i = 0; i < counter; ++i) + new CmdLineAction(true, "EditUndo"); + undo_counter -= counter; + } + } + } else if (verb_word == "XSelectElement") { + if (verb.args.size() < 2) { + printf("bad arguments for XSelectElement\n"); + continue; + } + ++undo_counter; + + xaction_args_values_map_t values_map; + values_map["element-id"] = verb.args[1]; + new CmdLineXAction(verb_word.c_str(), values_map); + } else if (verb_word == "XFileExportPNG") { + if (verb.args.size() < 2) { + printf("bad arguments for XFileExportPNG\n"); + continue; + } + + xaction_args_values_map_t values_map; + std::string &png_filename = verb.args[1]; + values_map["png_filename"] = png_filename; + if(createDirForFilename( png_filename )) + new CmdLineXAction(verb_word.c_str(), values_map); } else if(!verb.xverb) { ++undo_counter; diff --git a/src/verbs.cpp b/src/verbs.cpp index 5130f1701..72708a7c0 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -817,7 +817,7 @@ Verb *Verb::get_search(unsigned int code) * * @param id Which id to search for. */ -Verb *Verb::getbyid(gchar const *id) +Verb *Verb::getbyid(gchar const *id, bool verbose) { Verb *verb = NULL; VerbIDTable::iterator verb_found = _verb_ids.find(id); @@ -833,8 +833,10 @@ Verb *Verb::getbyid(gchar const *id) && strcmp(id, "SelectionTrace") != 0 && strcmp(id, "PaintBucketPrefs") != 0 #endif - ) - printf("Unable to find: %s\n", id); + ) { + if (verbose) + printf("Unable to find: %s\n", id); + } return verb; } diff --git a/src/verbs.h b/src/verbs.h index 16f88c408..e9ae10ba5 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -553,7 +553,7 @@ public: SPAction * get_action(Inkscape::ActionContext const & context); private: - static Verb * get_search (unsigned int code); + static Verb * get_search (unsigned int code, bool verbose = true); public: /** -- cgit v1.2.3 From 06f90c27b6e17397b03f20fe92fd0fb31d55332c Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Thu, 29 Sep 2016 23:08:29 +0700 Subject: allow to use verbs as xverbs (bzr r15136.1.8) --- src/main-cmdlinexact.cpp | 7 ++++++- src/verbs.h | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index ddf8a73eb..a3c9436bd 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -517,8 +517,13 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { ++undo_counter; new CmdLineAction(true, verb.args[0].c_str()); } + else if( Verb::getbyid(verb.args[0].c_str()) != NULL ) + { + ++undo_counter; + new CmdLineAction(true, verb.args[0].c_str()); + } else { - printf("Unhadled verb %s\n", verb.args[0].c_str()); + printf("Unhadled xverb %s\n", verb.args[0].c_str()); fflush(stdout); } } diff --git a/src/verbs.h b/src/verbs.h index e9ae10ba5..a273fe76e 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -553,7 +553,7 @@ public: SPAction * get_action(Inkscape::ActionContext const & context); private: - static Verb * get_search (unsigned int code, bool verbose = true); + static Verb * get_search (unsigned int code); public: /** @@ -575,7 +575,7 @@ public: return get_search(code); } } - static Verb * getbyid (gchar const * id); + static Verb * getbyid (gchar const * id, bool verbose = true); /** * Print a message to stderr indicating that this verb needs a GUI to run -- cgit v1.2.3 From 81364db0bc98b01319dc5ecb835a4e37b906bad2 Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Sat, 1 Oct 2016 13:05:10 +0700 Subject: disable xverb feature if WITH_YAML defined (bzr r15136.1.9) --- src/main-cmdlinexact.cpp | 10 ++++++++-- src/main.cpp | 15 +++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index a3c9436bd..3dc83bc8f 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -52,7 +52,10 @@ #include #include "main-cmdlinexact.h" +#ifdef WITH_YAML #include "yaml.h" +#endif // WITH_YAML + #include "extension/system.h" #include "file.h" #include @@ -312,6 +315,9 @@ typedef std::list verbs_list_t; void CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { +#ifndef WITH_YAML + return; +#else // WITH_YAML FILE *fh = fopen(yaml_filename, "r"); if(fh == NULL) { printf("Failed to open file!\n"); @@ -409,7 +415,7 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { verb_info_t verb; verb.xverb = true; verb.args = vectorFromString((char *)token.data.scalar.value); - if ((verb.args.size() > 1) && Verb::getbyid((char *)token.data.scalar.value)) + if ((verb.args.size() > 1) && Verb::getbyid((char *)token.data.scalar.value, false)) verb.xverb = false; verbs_list.push_back(verb); } @@ -529,7 +535,7 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { } fflush(stdout); - return; +#endif // WITH_YAML } diff --git a/src/main.cpp b/src/main.cpp index d9f11ed8b..5b7dcc5ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -229,8 +229,10 @@ static gchar *sp_export_png_utf8 = NULL; static gchar *sp_export_svg_utf8 = NULL; static gchar *sp_global_printer_utf8 = NULL; +#ifdef WITH_YAML static gchar *sp_xverbs_yaml_utf8 = NULL; static gchar *sp_xverbs_yaml = NULL; +#endif // WITH_YAML /** @@ -305,12 +307,12 @@ struct poptOption options[] = { POPT_ARG_STRING, NULL, SP_ARG_FILE, N_("Open specified document(s) (option string may be excluded)"), N_("FILENAME")}, - - {"xverbs", 'B', +#ifdef WITH_YAML + {"xverbs", 0, POPT_ARG_STRING, &sp_xverbs_yaml, SP_ARG_XVERBS, N_("xverbs command"), N_("XVERBS_FILENAME")}, - +#endif // WITH_YAML {"print", 'p', POPT_ARG_STRING, &sp_global_printer, SP_ARG_PRINT, N_("Print document(s) to specified output file (use '| program' for pipe)"), @@ -891,7 +893,9 @@ static int sp_common_main( int argc, char const **argv, GSList **flDest ) fixupSingleFilename( &sp_export_png, &sp_export_png_utf8 ); fixupSingleFilename( &sp_export_svg, &sp_export_svg_utf8 ); fixupSingleFilename( &sp_global_printer, &sp_global_printer_utf8 ); +#ifdef WITH_YAML fixupSingleFilename( &sp_xverbs_yaml, &sp_xverbs_yaml_utf8 ); +#endif // WITH_YAML } else { @@ -901,9 +905,10 @@ static int sp_common_main( int argc, char const **argv, GSList **flDest ) sp_export_svg_utf8 = g_strdup( sp_export_svg ); if ( sp_global_printer ) sp_global_printer_utf8 = g_strdup( sp_global_printer ); +#ifdef WITH_YAML if ( sp_xverbs_yaml ) sp_xverbs_yaml_utf8 = g_strdup( sp_xverbs_yaml ); - +#endif // WITH_YAML } #ifdef WITH_DBUS @@ -2145,6 +2150,7 @@ sp_process_args(poptContext ctx) } break; } +#ifdef WITH_YAML case SP_ARG_XVERBS: { gchar const *fn = poptGetOptArg(ctx); if (fn != NULL) { @@ -2153,6 +2159,7 @@ sp_process_args(poptContext ctx) } break; } +#endif // WITH_YAML case SP_ARG_VERSION: { printf("Inkscape %s (%s)\n", Inkscape::version_string, __DATE__); exit(0); -- cgit v1.2.3 From ea38e86ebfbcc53d86433fddbffffbfb5403c9fc Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Sat, 1 Oct 2016 16:01:18 +0700 Subject: fix indent (bzr r15136.1.10) --- src/main-cmdlinexact.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index 3dc83bc8f..f29d22377 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -316,8 +316,8 @@ typedef std::list verbs_list_t; void CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { #ifndef WITH_YAML - return; -#else // WITH_YAML + return; +#else // WITH_YAML FILE *fh = fopen(yaml_filename, "r"); if(fh == NULL) { printf("Failed to open file!\n"); @@ -527,7 +527,7 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { { ++undo_counter; new CmdLineAction(true, verb.args[0].c_str()); - } + } else { printf("Unhadled xverb %s\n", verb.args[0].c_str()); fflush(stdout); -- cgit v1.2.3 From 017616c4fc99883323c2a0d6e44b88f7cd16ce2d Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Sat, 1 Oct 2016 17:08:49 +0700 Subject: fix cmake warning and remove whole xverbs code from compilation without yaml (bzr r15136.1.11) --- src/main-cmdlinexact.cpp | 11 ++++------- src/main-cmdlinexact.h | 4 +++- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index f29d22377..f5db522ae 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -38,7 +38,7 @@ * # inkscape have a lot of useful verbs * - verb-id: FileQuit */ - +#ifdef WITH_YAML #include #include #include @@ -52,9 +52,8 @@ #include #include "main-cmdlinexact.h" -#ifdef WITH_YAML + #include "yaml.h" -#endif // WITH_YAML #include "extension/system.h" #include "file.h" @@ -315,9 +314,6 @@ typedef std::list verbs_list_t; void CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { -#ifndef WITH_YAML - return; -#else // WITH_YAML FILE *fh = fopen(yaml_filename, "r"); if(fh == NULL) { printf("Failed to open file!\n"); @@ -535,12 +531,13 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { } fflush(stdout); -#endif // WITH_YAML } } // Inkscape +#endif // WITH_YAML + /* Local Variables: mode:c++ diff --git a/src/main-cmdlinexact.h b/src/main-cmdlinexact.h index 1ac630e55..8634f3875 100644 --- a/src/main-cmdlinexact.h +++ b/src/main-cmdlinexact.h @@ -2,6 +2,8 @@ #ifndef __INK_MAIN_CMD_LINE_XACTIONS_H__ #define __INK_MAIN_CMD_LINE_XACTIONS_H__ +#ifdef WITH_YAML + /** \file * Extended actions that can be queued at the yaml file */ @@ -37,7 +39,7 @@ public: } // Inkscape - +#endif // WITH_YAML #endif /* __INK_MAIN_CMD_LINE_XACTIONS_H__ */ /* -- cgit v1.2.3 From 745dd3ffab16bdadc91beb6d3b0da81594f539fa Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Sun, 2 Oct 2016 11:02:44 +0700 Subject: split big function (bzr r15136.1.12) --- src/main-cmdlinexact.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index f5db522ae..2f7afe9fa 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -311,21 +311,23 @@ struct verb_info_t typedef std::list verbs_list_t; +static verbs_list_t +parseVerbsYAMLFile(gchar const *yaml_filename) +{ + verbs_list_t verbs_list; -void -CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { FILE *fh = fopen(yaml_filename, "r"); if(fh == NULL) { printf("Failed to open file!\n"); fflush(stdout); - return; + return verbs_list; } yaml_parser_t parser; if(!yaml_parser_initialize(&parser)) { printf("Failed to initialize parser!\n"); fflush(stdout); - return; + return verbs_list; } /* Set input file */ @@ -333,12 +335,10 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { parser_state_t state = HANDLING_ROOT; - bool handling_key = false; bool handling_value = false; std::string key; - verbs_list_t verbs_list; // parse yaml_token_t token; @@ -441,6 +441,14 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { yaml_parser_delete(&parser); fclose(fh); + return verbs_list; +} + +void +CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) +{ + verbs_list_t verbs_list = parseVerbsYAMLFile(yaml_filename); + typedef std::map undo_labels_map_t; undo_labels_map_t undo_labels_map; int undo_counter = 0; -- cgit v1.2.3 From 62fc42f0bceab46b06f0d535a235d8bfe4c851a2 Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Mon, 3 Oct 2016 21:38:19 +0700 Subject: butify idents (bzr r15136.1.13) --- src/main-cmdlinexact.cpp | 108 +++++++++++++++++++++++++++-------------------- 1 file changed, 63 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index 2f7afe9fa..99f0c699b 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -8,11 +8,11 @@ * * Format of xverbs.yaml * using: $ inkscape -B xverbs.yaml - * + * * verbose: yes # only "verbose: yes" enable logging * run: * # open document to process - * - xverb-id: XFileOpen, gfx_sources/loading_screen/sandclock_atlas.svg + * - xverb-id: XFileOpen, gfx_sources/loading_screen/sandclock_atlas.svg * - xverb-id: XUndoLabel, fresh_document # set label for UndoToLabel xverb works * # note: if something wrong with undo labels use verb EditUndo instead of XUndoLabel and UndoToLabel at all * @@ -31,7 +31,7 @@ * - xverb-id: XFileExportPNG, output/thegame/linux/data/gfx_preview/loading_screen/top_sand.png * * # return to the fresh_state of document - * - xverb-id: UndoToLabel, fresh_document + * - xverb-id: UndoToLabel, fresh_document * * # do any other handling * @@ -82,10 +82,10 @@ bool createDirForFilename( const std::string &filename ) { size_t found = filename.find_last_of("/\\"); std::string output_directory = filename.substr(0,found); - + if( output_directory == filename ) return true; - + if (g_mkdir_with_parents(output_directory.c_str(), 0755)) { printf("Can't create directory %s\n", output_directory.c_str()); fflush(stdout); @@ -138,7 +138,7 @@ void xFileOpen( const Glib::ustring &uri ) desktop->setWaitingCursor(); Inkscape::DocumentUndo::clearRedo(old_document); } - + SPDocument *doc = NULL; Inkscape::Extension::Extension *key = NULL; try { @@ -152,8 +152,8 @@ void xFileOpen( const Glib::ustring &uri ) // Set viewBox if it doesn't exist if (!doc->getRoot()->viewBox_set - && (doc->getRoot()->width.unit != SVGLength::PERCENT) - && (doc->getRoot()->height.unit != SVGLength::PERCENT)) { + && (doc->getRoot()->width.unit != SVGLength::PERCENT) + && (doc->getRoot()->height.unit != SVGLength::PERCENT)) { doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit()))); } @@ -193,7 +193,7 @@ void xFileSaveAs( Inkscape::ActionContext const & context, const Glib::ustring & if( createDirForFilename( uri )) { Inkscape::Extension::save( - Inkscape::Extension::db.get("org.inkscape.output.svg.inkscape"), + Inkscape::Extension::db.get("org.inkscape.output.svg.inkscape"), doc, uri.c_str(), false, false, true, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); if (s_verbose) { printf("save done: %s\n", uri.c_str() ); @@ -220,26 +220,28 @@ void xFileExportPNG( Inkscape::ActionContext const & context, const Glib::ustrin Inkscape::Preferences *prefs = Inkscape::Preferences::get(); dpi = prefs->getDouble("/dialogs/export/defaultxdpi/value", DPI_BASE); - + gdouble width = doc->getWidth().value(doc->getDisplayUnit()); gdouble height = doc->getHeight().value(doc->getDisplayUnit()); - + gdouble bmwidth = (width) * dpi / DPI_BASE; gdouble bmheight = (height) * dpi / DPI_BASE; - + int png_width = (int)(0.5 + bmwidth); int png_height = (int)(0.5 + bmheight); - + SPNamedView *nv = desktop->getNamedView(); ExportResult status = sp_export_png_file(doc, uri.c_str(), - Geom::Rect(Geom::Point(0,0), Geom::Point(width, height)), png_width, png_height, dpi, dpi, - nv->pagecolor, 0, 0, TRUE); + Geom::Rect(Geom::Point(0,0), Geom::Point(width, height)), png_width, png_height, dpi, dpi, + nv->pagecolor, 0, 0, TRUE); } void xSelectElement( Inkscape::ActionContext const & context, const Glib::ustring &uri ) { - if (context.getDocument() == NULL || context.getSelection() == NULL) { return; } + if (context.getDocument() == NULL || context.getSelection() == NULL) { + return; + } if (s_verbose) { printf("select element: %s\n", uri.c_str()); @@ -281,7 +283,7 @@ CmdLineXAction::isExtended() { void CmdLineXAction::doItX (ActionContext const & context) { - (void)(context); + (void)(context); if( arg == "XFileSaveAs") xFileSaveAs( context, _values_map["filename"] ); @@ -299,9 +301,10 @@ CmdLineXAction::doItX (ActionContext const & context) { return; } -enum parser_state_t{ HANDLING_ROOT, - HANDLING_VERBOSE, // options - HANDLING_RUN, HANDLING_RUN_LIST, HANDLING_RUN_LIST_ENTRY }; // run entries +enum parser_state_t { HANDLING_ROOT, + HANDLING_VERBOSE, // options + HANDLING_RUN, HANDLING_RUN_LIST, HANDLING_RUN_LIST_ENTRY + }; // run entries struct verb_info_t { @@ -314,7 +317,7 @@ typedef std::list verbs_list_t; static verbs_list_t parseVerbsYAMLFile(gchar const *yaml_filename) { - verbs_list_t verbs_list; + verbs_list_t verbs_list; FILE *fh = fopen(yaml_filename, "r"); if(fh == NULL) { @@ -346,24 +349,39 @@ parseVerbsYAMLFile(gchar const *yaml_filename) yaml_parser_scan(&parser, &token); switch(token.type) { - // avoid "warning: enumeration value", "-Wswitch" - case YAML_NO_TOKEN: break; - case YAML_STREAM_START_TOKEN: break; - case YAML_STREAM_END_TOKEN: break; - case YAML_VERSION_DIRECTIVE_TOKEN: break; - case YAML_TAG_DIRECTIVE_TOKEN: break; - case YAML_DOCUMENT_START_TOKEN: break; - case YAML_DOCUMENT_END_TOKEN: break; - case YAML_FLOW_SEQUENCE_START_TOKEN: break; - case YAML_FLOW_SEQUENCE_END_TOKEN: break; - case YAML_FLOW_MAPPING_START_TOKEN: break; - case YAML_FLOW_MAPPING_END_TOKEN: break; - case YAML_FLOW_ENTRY_TOKEN: break; - case YAML_ALIAS_TOKEN: break; - case YAML_ANCHOR_TOKEN: break; - case YAML_TAG_TOKEN: break; - - /* Token types (read before actual token) */ + // avoid "warning: enumeration value", "-Wswitch" + case YAML_NO_TOKEN: + break; + case YAML_STREAM_START_TOKEN: + break; + case YAML_STREAM_END_TOKEN: + break; + case YAML_VERSION_DIRECTIVE_TOKEN: + break; + case YAML_TAG_DIRECTIVE_TOKEN: + break; + case YAML_DOCUMENT_START_TOKEN: + break; + case YAML_DOCUMENT_END_TOKEN: + break; + case YAML_FLOW_SEQUENCE_START_TOKEN: + break; + case YAML_FLOW_SEQUENCE_END_TOKEN: + break; + case YAML_FLOW_MAPPING_START_TOKEN: + break; + case YAML_FLOW_MAPPING_END_TOKEN: + break; + case YAML_FLOW_ENTRY_TOKEN: + break; + case YAML_ALIAS_TOKEN: + break; + case YAML_ANCHOR_TOKEN: + break; + case YAML_TAG_TOKEN: + break; + + /* Token types (read before actual token) */ case YAML_KEY_TOKEN: handling_key = true; handling_value = false; @@ -373,12 +391,12 @@ parseVerbsYAMLFile(gchar const *yaml_filename) handling_value = true; break; - /* Block delimeters */ + /* Block delimeters */ case YAML_BLOCK_SEQUENCE_START_TOKEN: if( state == HANDLING_ROOT ) { if( key == "run" ) state = HANDLING_RUN; - } + } break; case YAML_BLOCK_ENTRY_TOKEN: if( state == HANDLING_RUN ) @@ -399,7 +417,7 @@ parseVerbsYAMLFile(gchar const *yaml_filename) state = HANDLING_ROOT; break; - /* Data */ + /* Data */ case YAML_BLOCK_MAPPING_START_TOKEN: break; case YAML_SCALAR_TOKEN: @@ -441,7 +459,7 @@ parseVerbsYAMLFile(gchar const *yaml_filename) yaml_parser_delete(&parser); fclose(fh); - return verbs_list; + return verbs_list; } void @@ -454,7 +472,7 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) int undo_counter = 0; verbs_list_t::iterator iter = verbs_list.begin(); - for (;iter != verbs_list.end(); ++iter) { + for (; iter != verbs_list.end(); ++iter) { verb_info_t &verb = *iter; std::string &verb_word = verb.args[0]; if (s_verbose) @@ -516,7 +534,7 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) printf("bad arguments for XFileExportPNG\n"); continue; } - + xaction_args_values_map_t values_map; std::string &png_filename = verb.args[1]; values_map["png_filename"] = png_filename; -- cgit v1.2.3 From f9a55c6269f20bfe98e1eeb0dd07f5bb3036b7ab Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Mon, 3 Oct 2016 22:19:23 +0700 Subject: beautify idents (bzr r15136.1.14) --- src/main-cmdlineact.cpp | 2 -- src/main.cpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/main-cmdlineact.cpp b/src/main-cmdlineact.cpp index fc0f50cd4..f5c6e52eb 100644 --- a/src/main-cmdlineact.cpp +++ b/src/main-cmdlineact.cpp @@ -57,8 +57,6 @@ CmdLineAction::doIt (ActionContext const & context) { //printf("Doing: %s\n", _arg); if (_isVerb) { if (isExtended()) { - //printf("Is extended\n"); - doItX(context); return; } diff --git a/src/main.cpp b/src/main.cpp index 5b7dcc5ef..0d5f35797 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -308,7 +308,7 @@ struct poptOption options[] = { N_("Open specified document(s) (option string may be excluded)"), N_("FILENAME")}, #ifdef WITH_YAML - {"xverbs", 0, + {"xverbs", 0, POPT_ARG_STRING, &sp_xverbs_yaml, SP_ARG_XVERBS, N_("xverbs command"), N_("XVERBS_FILENAME")}, -- cgit v1.2.3 From d43d0384c8f95baa781beaaca79b938e680b727a Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Mon, 3 Oct 2016 22:25:41 +0700 Subject: beautify idents (bzr r15136.1.15) --- src/main-cmdlineact.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main-cmdlineact.cpp b/src/main-cmdlineact.cpp index f5c6e52eb..03bf4083c 100644 --- a/src/main-cmdlineact.cpp +++ b/src/main-cmdlineact.cpp @@ -86,13 +86,12 @@ CmdLineAction::doIt (ActionContext const & context) { bool CmdLineAction::doList (ActionContext const & context) { - bool hasActions = !_list.empty(); - for (std::list::iterator i = _list.begin(); - i != _list.end(); ++i) { + bool hasActions = !_list.empty(); + for (std::list::iterator i = _list.begin(); i != _list.end(); ++i) { CmdLineAction * entry = *i; entry->doIt(context); } - return hasActions; + return hasActions; } bool -- cgit v1.2.3