#include #include #include "stdlib/kumirstdlib.hpp" #include "vm/variant.hpp" #include "vm/vm_bytecode.hpp" #include "vm/vm.hpp" #if !defined(WIN32) && !defined(_WIN32) #define LOCALE Kumir::UTF8 #else #define LOCALE Kumir::CP866 #endif int usage(const char * programName) { std::cerr << "Usage: " << std::endl; std::cerr << "\t" << programName << " FILENAME.kod | FILENAME.ks [ARG1 [ARG2 ... [ARGn]]]" << std::endl << std::endl; std::cerr << "\tFILENAME.kod\tKumir runtime code file name" << std::endl; std::cerr << "\tFILENAME.ks\tKumir assembler input file name" << std::endl; std::cerr << "\tARG1...ARGn\tKumir program main algorithm arguments" << std::endl; return 127; } class InteractionHandler : public VM::AbstractInteractionHandler { public: explicit InteractionHandler(int argc, char *argv[]); bool makeInputArgument(VM::Variable & reference); bool makeOutputArgument(const VM::Variable & reference); private: void output(const Kumir::String & s); inline void output(const std::string & s) { output(Kumir::Core::fromAscii(s)); } bool readScalarArgument(const Kumir::String & message, const Kumir::String & name, VM::ValueType type, VM::AnyValue & val); std::deque< Kumir::String > m_arguments; size_t i_currentArgument; }; InteractionHandler::InteractionHandler(int argc, char *argv[]) { i_currentArgument = 0; bool argumentsScope = false; for (int i=1; i it is a program, // so next arg is a program argument argumentsScope = true; } } else { m_arguments.push_back(Kumir::Coder::decode(LOCALE, arg)); } } } #define IS_HEX(x) ( (x>='0' && x<='9') || (x>='A' && x<='F') || (x>='a' && x<='f') ) Kumir::String decodeHttpStringValue(const std::string & s) { Kumir::String result; size_t cpos = 0; std::string utf8string; utf8string.reserve(s.length()); while (cposAn error occured on server\n"; std::cout << "\n"; std::cout << localMessage << std::endl; std::cout << "\n"; return 0; } } bool InteractionHandler::readScalarArgument(const Kumir::String &message, const Kumir::String &name, VM::ValueType type, VM::AnyValue &val) { Kumir::IO::InputStream stream; bool foundValue = false; #if !defined(WIN32) && !defined(_WIN32) char * REQUEST_METHOD = getenv("REQUEST_METHOD"); char * QUERY_STRING = getenv("QUERY_STRING"); if (REQUEST_METHOD && std::string(REQUEST_METHOD)==std::string("GET") && QUERY_STRING) { Kumir::String query_string = decodeHttpStringValue(std::string(QUERY_STRING)); Kumir::StringList pairs = Kumir::Core::splitString(query_string, Kumir::Char('&'), true); for (size_t i=0; i args; bool forceTextForm = false; for (int i=1; i0) { static const Kumir::String RUNTIME_ERROR = Kumir::Core::fromUtf8("ОШИБКА ВЫПОЛНЕНИЯ: "); static const Kumir::String RUNTIME_ERROR_AT = Kumir::Core::fromUtf8("ОШИБКА ВЫПОЛНЕНИЯ В СТРОКЕ "); static const Kumir::String COLON = Kumir::Core::fromAscii(": "); Kumir::String message; if (vm.effectiveLineNo()!=-1) { message = RUNTIME_ERROR_AT+ Kumir::Converter::sprintfInt(vm.effectiveLineNo()+1,10,0,0)+ COLON+ vm.error(); } else { message = RUNTIME_ERROR + vm.error(); } return showErrorMessage(message, 10); return 10; } } return 0; }