void TranslatorAction::readFlags() { flags.propValues = getBoolArg("propValues", true); #if defined(_IPF_) flags.optArrayInit = getBoolArg("optArrayInit", false); #else flags.optArrayInit = getBoolArg("optArrayInit", true); #endif flags.onlyBalancedSync = getBoolArg("balancedSync", false); flags.ignoreSync = getBoolArg("ignoreSync",false); flags.syncAsEnterFence = getBoolArg("syncAsEnterFence",false); flags.genMinMaxAbs = getBoolArg("genMinMaxAbs", false); flags.genFMinMaxAbs = getBoolArg("genFMinMaxAbs", false); #ifndef _IPF_ bool defaultIsLazy = true; #else bool defaultIsLazy = false; #endif flags.lazyResolution = getBoolArg("lazyResolution", defaultIsLazy); flags.assertOnRecursion = getBoolArg("assertOnRecursion", flags.lazyResolution); }
// Cgi to change choice of pin assignments int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) { if (connData->conn==NULL) { return HTTPD_CGI_DONE; // Connection aborted } int8_t ok = 0; int8_t reset, isp, conn, ser; bool swap, rxpup; ok |= getInt8Arg(connData, "reset", &reset); ok |= getInt8Arg(connData, "isp", &isp); ok |= getInt8Arg(connData, "conn", &conn); ok |= getInt8Arg(connData, "ser", &ser); ok |= getBoolArg(connData, "swap", &swap); ok |= getBoolArg(connData, "rxpup", &rxpup); if (ok < 0) return HTTPD_CGI_DONE; char *coll; if (ok > 0) { // check whether two pins collide uint16_t pins = 0; if (reset >= 0) pins = 1 << reset; if (isp >= 0) { if (pins & (1<<isp)) { coll = "ISP/Flash"; goto collision; } pins |= 1 << isp; } if (conn >= 0) { if (pins & (1<<conn)) { coll = "Conn LED"; goto collision; } pins |= 1 << conn; } if (ser >= 0) { if (pins & (1<<ser)) { coll = "Serial LED"; goto collision; } pins |= 1 << ser; } if (swap) { if (pins & (1<<15)) { coll = "Uart TX"; goto collision; } if (pins & (1<<13)) { coll = "Uart RX"; goto collision; } } else { if (pins & (1<<1)) { coll = "Uart TX"; goto collision; } if (pins & (1<<3)) { coll = "Uart RX"; goto collision; } } // we're good, set flashconfig flashConfig.reset_pin = reset; flashConfig.isp_pin = isp; flashConfig.conn_led_pin = conn; flashConfig.ser_led_pin = ser; flashConfig.swap_uart = swap; flashConfig.rx_pullup = rxpup; os_printf("Pins changed: reset=%d isp=%d conn=%d ser=%d swap=%d rx-pup=%d\n", reset, isp, conn, ser, swap, rxpup); // apply the changes serbridgeInitPins(); serledInit(); statusInit(); // save to flash if (configSave()) { httpdStartResponse(connData, 204); httpdEndHeaders(connData); } else { httpdStartResponse(connData, 500); httpdEndHeaders(connData); httpdSend(connData, "Failed to save config", -1); } } return HTTPD_CGI_DONE; collision: { char buff[128]; os_sprintf(buff, "Pin assignment for %s collides with another assignment", coll); errorResponse(connData, 400, buff); return HTTPD_CGI_DONE; } }
int execute(int argc, char* argv[]) { if (argc <= 1) { showHelp(); return RESULT_EC_SUCCESS; } std::string fileInput = argv[1]; int errorlevel = 0; int limit = -1; bool info = false; bool help = false; for (int i = 1; i < argc; i++) { getStringArg(fileInput, argv[i], "file"); getIntArg(errorlevel, argv[i], "errorlevel"); getIntArg(limit, argv[i], "limit"); getBoolArg(info, argv[i], "info"); getBoolArg(help, argv[i], "help"); } if (help) { showHelp(); return RESULT_EC_SUCCESS; } if (errorlevel < 0 || errorlevel > 3) { std::cerr << "Invalid value for errorlevel: " << errorlevel << std::endl; return RESULT_EC_INVALIDERRORLEVEL; } int width = 0; int height = 0; std::vector<std::string> lines; try { std::ifstream file(fileInput); if (!file.is_open()) { std::cerr << "Cannot open file: " << fileInput << std::endl; return RESULT_EC_FILEREADEXCEPTION; } std::string str; bool first = true; while (std::getline(file, str)) { // UTF-8 BOM if (first && str.length() >= 3 && (uint8_t)str.at(0) == 0xEF && (uint8_t)str.at(1) == 0xBB && (uint8_t)str.at(2) == 0xBF) { str = str.substr(3); } lines.push_back(str); width = std::max(width, (int)str.length()); height++; first = false; } } catch (const std::exception& ex) { std::cerr << "Cannot open/read file " << fileInput << std::endl; std::cerr << ex.what() << std::endl; return RESULT_EC_FILEREADEXCEPTION; } catch (...) { std::cerr << "Unknown internal exception in file " << __FILE__ << " at line " << __LINE__ << std::endl; return RESULT_EC_UNKNOWNEXCEPTION; } if (width <= 0 || height <= 0) { std::cerr << "The program has an size of zero" << std::endl; return RESULT_EC_INVALIDSIZE; } IBefungeRunner *runner; if (info) { runner = new BefungeRunnerInfo(width, height); } else if (errorlevel == 0) { runner = new BefungeRunner0(width, height); } else if (errorlevel == 1) { runner = new BefungeRunner1(width, height); } else if (errorlevel == 2) { runner = new BefungeRunner2(width, height); } else if (errorlevel == 3) { runner = new BefungeRunner3(width, height); } else { std::cerr << "Cannot create a befunge runner for the supplied parameters" << std::endl; return RESULT_EC_INVALIDRUNNER; } runner->Init(lines); runner->SetLimit(limit); try { runner->Run(); } catch (const BFRunException& ex) { std::cerr << ex.what() << std::endl; return ex.exitCode; } catch (const std::exception& ex) { std::cerr << "Internal exception while running program:" << std::endl; std::cerr << ex.what() << std::endl; return RESULT_EC_UNKNOWNEXCEPTION; } catch (...) { std::cerr << "Unknown internal exception in file " << __FILE__ << " at line " << __LINE__ << std::endl; return RESULT_EC_UNKNOWNEXCEPTION; } delete runner; return RESULT_EC_SUCCESS; }
bool KateCommands::CoreCommands::exec(Kate::View *view, const QString &_cmd, QString &errorMsg) { #define KCC_ERR(s) { errorMsg=s; return false; } // cast it hardcore, we know that it is really a kateview :) KateView *v = (KateView*) view; if ( ! v ) KCC_ERR( i18n("Could not access view") ); //create a list of args QStringList args( QStringList::split( QRegExp("\\s+"), _cmd ) ); QString cmd ( args.first() ); args.remove( args.first() ); // ALL commands that takes no arguments. if ( cmd == "indent" ) { v->indent(); return true; } else if ( cmd == "run-myself" ) { #ifndef Q_WS_WIN //todo return KateFactory::self()->jscript()->execute(v, v->doc()->text(), errorMsg); #else return 0; #endif } else if ( cmd == "unindent" ) { v->unIndent(); return true; } else if ( cmd == "cleanindent" ) { v->cleanIndent(); return true; } else if ( cmd == "comment" ) { v->comment(); return true; } else if ( cmd == "uncomment" ) { v->uncomment(); return true; } else if ( cmd == "kill-line" ) { v->killLine(); return true; } else if ( cmd == "set-indent-mode" ) { bool ok(false); int val ( args.first().toInt( &ok ) ); if ( ok ) { if ( val < 0 ) KCC_ERR( i18n("Mode must be at least 0.") ); v->doc()->config()->setIndentationMode( val ); } else v->doc()->config()->setIndentationMode( KateAutoIndent::modeNumber( args.first() ) ); return true; } else if ( cmd == "set-highlight" ) { QString val = _cmd.section( ' ', 1 ).lower(); for ( uint i=0; i < v->doc()->hlModeCount(); i++ ) { if ( v->doc()->hlModeName( i ).lower() == val ) { v->doc()->setHlMode( i ); return true; } } KCC_ERR( i18n("No such highlight '%1'").arg( args.first() ) ); } // ALL commands that takes exactly one integer argument. else if ( cmd == "set-tab-width" || cmd == "set-indent-width" || cmd == "set-word-wrap-column" || cmd == "goto" ) { // find a integer value > 0 if ( ! args.count() ) KCC_ERR( i18n("Missing argument. Usage: %1 <value>").arg( cmd ) ); bool ok; int val ( args.first().toInt( &ok ) ); if ( !ok ) KCC_ERR( i18n("Failed to convert argument '%1' to integer.") .arg( args.first() ) ); if ( cmd == "set-tab-width" ) { if ( val < 1 ) KCC_ERR( i18n("Width must be at least 1.") ); v->setTabWidth( val ); } else if ( cmd == "set-indent-width" ) { if ( val < 1 ) KCC_ERR( i18n("Width must be at least 1.") ); v->doc()->config()->setIndentationWidth( val ); } else if ( cmd == "set-word-wrap-column" ) { if ( val < 2 ) KCC_ERR( i18n("Column must be at least 1.") ); v->doc()->setWordWrapAt( val ); } else if ( cmd == "goto" ) { if ( val < 1 ) KCC_ERR( i18n("Line must be at least 1") ); if ( (uint)val > v->doc()->numLines() ) KCC_ERR( i18n("There is not that many lines in this document") ); v->gotoLineNumber( val - 1 ); } return true; } // ALL commands that takes 1 boolean argument. else if ( cmd == "set-icon-border" || cmd == "set-folding-markers" || cmd == "set-line-numbers" || cmd == "set-replace-tabs" || cmd == "set-remove-trailing-space" || cmd == "set-show-tabs" || cmd == "set-indent-spaces" || cmd == "set-mixed-indent" || cmd == "set-word-wrap" || cmd == "set-wrap-cursor" || cmd == "set-replace-tabs-save" || cmd == "set-remove-trailing-space-save" || cmd == "set-show-indent" ) { if ( ! args.count() ) KCC_ERR( i18n("Usage: %1 on|off|1|0|true|false").arg( cmd ) ); bool enable; if ( getBoolArg( args.first(), &enable ) ) { if ( cmd == "set-icon-border" ) v->setIconBorder( enable ); else if (cmd == "set-folding-markers") v->setFoldingMarkersOn( enable ); else if ( cmd == "set-line-numbers" ) v->setLineNumbersOn( enable ); else if ( cmd == "set-show-indent" ) v->renderer()->setShowIndentLines( enable ); else if ( cmd == "set-replace-tabs" ) setDocFlag( KateDocumentConfig::cfReplaceTabsDyn, enable, v->doc() ); else if ( cmd == "set-remove-trailing-space" ) setDocFlag( KateDocumentConfig::cfRemoveTrailingDyn, enable, v->doc() ); else if ( cmd == "set-show-tabs" ) setDocFlag( KateDocumentConfig::cfShowTabs, enable, v->doc() ); else if ( cmd == "set-indent-spaces" ) setDocFlag( KateDocumentConfig::cfSpaceIndent, enable, v->doc() ); else if ( cmd == "set-mixed-indent" ) { // this is special, in that everything is set up -- space-indent is enabled, // and a indent-width is set if it is 0 (to tabwidth/2) setDocFlag( KateDocumentConfig::cfMixedIndent, enable, v->doc() ); if ( enable ) { setDocFlag( KateDocumentConfig::cfSpaceIndent, enable, v->doc() ); if ( ! v->doc()->config()->indentationWidth() ) v->doc()->config()->setIndentationWidth( v->tabWidth()/2 ); } } else if ( cmd == "set-word-wrap" ) v->doc()->setWordWrap( enable ); else if ( cmd == "set-remove-trailing-space-save" ) setDocFlag( KateDocumentConfig::cfRemoveSpaces, enable, v->doc() ); else if ( cmd == "set-wrap-cursor" ) setDocFlag( KateDocumentConfig::cfWrapCursor, enable, v->doc() ); return true; } else KCC_ERR( i18n("Bad argument '%1'. Usage: %2 on|off|1|0|true|false") .arg( args.first() ).arg( cmd ) ); } // unlikely.. KCC_ERR( i18n("Unknown command '%1'").arg(cmd) ); }
bool KateCommands::CoreCommands::exec(KTextEditor::View *view, const QString &_cmd, QString &errorMsg, const KTextEditor::Range& range) { #define KCC_ERR(s) { errorMsg=s; return false; } // cast it hardcore, we know that it is really a kateview :) KateView *v = static_cast<KateView*>(view); if ( ! v ) KCC_ERR( i18n("Could not access view") ); //create a list of args QStringList args(_cmd.split( QRegExp("\\s+"), QString::SkipEmptyParts)) ; QString cmd ( args.takeFirst() ); // ALL commands that takes no arguments. if ( cmd == "indent" ) { if ( range.isValid() ) { v->doc()->editStart(); for ( int line = range.start().line(); line <= range.end().line(); line++ ) { v->doc()->indent( KTextEditor::Range(line, 0, line, 0), 1 ); } v->doc()->editEnd(); } else { v->indent(); } return true; } else if ( cmd == "unindent" ) { if ( range.isValid() ) { v->doc()->editStart(); for ( int line = range.start().line(); line <= range.end().line(); line++ ) { v->doc()->indent( KTextEditor::Range(line, 0, line, 0), -1 ); } v->doc()->editEnd(); } else { v->unIndent(); } return true; } else if ( cmd == "cleanindent" ) { if ( range.isValid() ) { v->doc()->editStart(); for ( int line = range.start().line(); line <= range.end().line(); line++ ) { v->doc()->indent( KTextEditor::Range(line, 0, line, 0), 0 ); } v->doc()->editEnd(); } else { v->cleanIndent(); } return true; } else if ( cmd == "comment" ) { if ( range.isValid() ) { v->doc()->editStart(); for ( int line = range.start().line(); line <= range.end().line(); line++ ) { v->doc()->comment( v, line, 0, 1 ); } v->doc()->editEnd(); } else { v->comment(); } return true; } else if ( cmd == "uncomment" ) { if ( range.isValid() ) { v->doc()->editStart(); for ( int line = range.start().line(); line <= range.end().line(); line++ ) { v->doc()->comment( v, line, 0, -1 ); } v->doc()->editEnd(); } else { v->uncomment(); } return true; } else if ( cmd == "kill-line" ) { if ( range.isValid() ) { v->doc()->editStart(); for ( int line = range.start().line(); line <= range.end().line(); line++ ) { v->doc()->removeLine( range.start().line() ); } v->doc()->editEnd(); } else { v->killLine(); } return true; } else if ( cmd == "print" ) { v->doc()->printDialog(); return true; } // ALL commands that take a string argument else if ( cmd == "set-indent-mode" || cmd == "set-highlight" || cmd == "set-mode" ) { // need at least one item, otherwise args.first() crashes if ( ! args.count() ) KCC_ERR( i18n("Missing argument. Usage: %1 <value>", cmd ) ); if ( cmd == "set-indent-mode" ) { v->doc()->config()->setIndentationMode( args.join(" ") ); v->doc()->rememberUserDidSetIndentationMode (); return true; } else if ( cmd == "set-highlight" ) { if ( v->doc()->setHighlightingMode( args.first()) ) { static_cast<KateDocument*>(v->doc())->setDontChangeHlOnSave (); return true; } KCC_ERR( i18n("No such highlighting '%1'", args.first() ) ); } else if ( cmd == "set-mode" ) { if ( v->doc()->setMode( args.first()) ) return true; KCC_ERR( i18n("No such mode '%1'", args.first() ) ); } } // ALL commands that takes exactly one integer argument. else if ( cmd == "set-tab-width" || cmd == "set-indent-width" || cmd == "set-word-wrap-column" || cmd == "goto" ) { // find a integer value > 0 if ( ! args.count() ) KCC_ERR( i18n("Missing argument. Usage: %1 <value>", cmd ) ); bool ok; int val ( args.first().toInt( &ok, 10 ) ); // use base 10 even if the string starts with '0' if ( !ok ) KCC_ERR( i18n("Failed to convert argument '%1' to integer.", args.first() ) ); if ( cmd == "set-tab-width" ) { if ( val < 1 ) KCC_ERR( i18n("Width must be at least 1.") ); v->doc()->config()->setTabWidth( val ); } else if ( cmd == "set-indent-width" ) { if ( val < 1 ) KCC_ERR( i18n("Width must be at least 1.") ); v->doc()->config()->setIndentationWidth( val ); } else if ( cmd == "set-word-wrap-column" ) { if ( val < 2 ) KCC_ERR( i18n("Column must be at least 1.") ); v->doc()->setWordWrapAt( val ); } else if ( cmd == "goto" ) { if ( args.first().at(0) == '-' || args.first().at(0) == '+' ) { // if the number starts with a minus or plus sign, add/subract the number val = v->cursorPosition().line() + val; } else { val--; // convert given line number to the internal representation of line numbers } // constrain cursor to the range [0, number of lines] if ( val < 0 ) { val = 0; } else if ( val > v->doc()->lines()-1 ) { val = v->doc()->lines()-1; } v->setCursorPosition( KTextEditor::Cursor( val, 0 ) ); return true; } return true; } // ALL commands that takes 1 boolean argument. else if ( cmd == "set-icon-border" || cmd == "set-folding-markers" || cmd == "set-line-numbers" || cmd == "set-replace-tabs" || cmd == "set-show-tabs" || cmd == "set-word-wrap" || cmd == "set-wrap-cursor" || cmd == "set-replace-tabs-save" || cmd == "set-show-indent" ) { if ( ! args.count() ) KCC_ERR( i18n("Usage: %1 on|off|1|0|true|false", cmd ) ); bool enable = false; KateDocumentConfig * const config = v->doc()->config(); if ( getBoolArg( args.first(), &enable ) ) { if ( cmd == "set-icon-border" ) v->setIconBorder( enable ); else if (cmd == "set-folding-markers") v->setFoldingMarkersOn( enable ); else if ( cmd == "set-line-numbers" ) v->setLineNumbersOn( enable ); else if ( cmd == "set-show-indent" ) v->renderer()->setShowIndentLines( enable ); else if ( cmd == "set-replace-tabs" ) config->setReplaceTabsDyn( enable ); else if ( cmd == "set-show-tabs" ) config->setShowTabs( enable ); else if ( cmd == "set-show-trailing-spaces" ) config->setShowSpaces( enable ); else if ( cmd == "set-word-wrap" ) v->doc()->setWordWrap( enable ); return true; } else KCC_ERR( i18n("Bad argument '%1'. Usage: %2 on|off|1|0|true|false", args.first() , cmd ) ); } else if ( cmd == "set-remove-trailing-spaces" ) { // need at least one item, otherwise args.first() crashes if ( args.count() != 1 ) KCC_ERR( i18n("Usage: set-remove-trailing-spaces 0|-|none or 1|+|mod|modified or 2|*|all") ); QString tmp = args.first().toLower().trimmed(); if (tmp == "1" || tmp == "modified" || tmp == "mod" || tmp == "+") { v->doc()->config()->setRemoveSpaces(1); } else if (tmp == "2" || tmp == "all" || tmp == "*") { v->doc()->config()->setRemoveSpaces(2); } else { v->doc()->config()->setRemoveSpaces(0); } } // unlikely.. KCC_ERR( i18n("Unknown command '%1'", cmd) ); }