PPrototypeAST Parser::parse_prototype() { Type return_type = get_type(current_tok); get_next_token(); // eat type token std::string name; //We should read identifier or entry point token if (current_tok == Token::Identifier) { name = lex.get_last_token_value<std::string>(); get_next_token(); // eat identifier } else if (current_tok == Token::EntryPoint) { name = "Coq"; get_next_token(); // eat identifier } else throw ParserException(ParserExceptionType::ExpectedIdentifier); if (current_tok != Token::StartArg) throw ParserException(ParserExceptionType::ExpectedStartArg); get_next_token(); // eat '<' //Read types of arguments ArgList args; if (current_tok != Token::EndArg) while (true) { if (!is_type(current_tok)) throw ParserException(ParserExceptionType::ExpectedType); Type arg_type = get_type(current_tok); get_next_token(); // eat type // Users are allowed to do not specify a name std::string arg_name; if (current_tok == Token::Identifier) { name = lex.get_last_token_value<std::string>(); get_next_token(); } args.push_back(ArgPair(arg_type, arg_name)); if (current_tok == Token::EndArg) break; if (current_tok != Token::ArgSep) throw ParserException(ParserExceptionType::ExpectedEndOfArg); get_next_token(); //eat separator ',' } get_next_token(); // eat '>' return PPrototypeAST(new PrototypeAST(return_type, name, args)); }
QString PluginLiveConnectExtension::evalJavaScript(const QString &script) { kdDebug(1432) << "PLUGIN:LiveConnect::evalJavaScript " << script << endl; ArgList args; QString jscode; jscode.sprintf("this.__nsplugin=eval(\"%s\")", QString(script).replace('\\', "\\\\").replace('"', "\\\"").latin1()); // kdDebug(1432) << "String is [" << jscode << "]" << endl; args.push_back(qMakePair(KParts::LiveConnectExtension::TypeString, jscode)); QString nsplugin("Undefined"); _retval = &nsplugin; emit partEvent(0, "eval", args); _retval = 0L; return nsplugin; }
int run(int argc, char **argv){ if(argc % 2 != 0) { return 1; } std::string module_name = argv[1]; ArgList args; for(int i=2; i<argc; i+=2) { std::string arg_name = argv[i]; std::string arg_value = argv[i+1]; Arg arg(arg_name, arg_value); args.push_back(arg); } Module::run(module_name, args); return 0; }
void ArchDaemonWindows::serviceMain(DWORD argc, LPTSTR* argvIn) { typedef std::vector<LPCTSTR> ArgList; typedef std::vector<std::string> Arguments; const char** argv = const_cast<const char**>(argvIn); // create synchronization objects m_serviceMutex = ARCH->newMutex(); m_serviceCondVar = ARCH->newCondVar(); // register our service handler function m_statusHandle = RegisterServiceCtrlHandler(argv[0], &ArchDaemonWindows::serviceHandlerEntry); if (m_statusHandle == 0) { // cannot start as service m_daemonResult = -1; ARCH->closeCondVar(m_serviceCondVar); ARCH->closeMutex(m_serviceMutex); return; } // tell service control manager that we're starting m_serviceState = SERVICE_START_PENDING; setStatus(m_serviceState, 0, 10000); std::string commandLine; // if no arguments supplied then try getting them from the registry. // the first argument doesn't count because it's the service name. Arguments args; ArgList myArgv; if (argc <= 1) { // read command line HKEY key = openNTServicesKey(); key = ArchMiscWindows::openKey(key, argvIn[0]); key = ArchMiscWindows::openKey(key, _T("Parameters")); if (key != NULL) { commandLine = ArchMiscWindows::readValueString(key, _T("CommandLine")); } // if the command line isn't empty then parse and use it if (!commandLine.empty()) { // parse, honoring double quoted substrings std::string::size_type i = commandLine.find_first_not_of(" \t"); while (i != std::string::npos && i != commandLine.size()) { // find end of string std::string::size_type e; if (commandLine[i] == '\"') { // quoted. find closing quote. ++i; e = commandLine.find("\"", i); // whitespace must follow closing quote if (e == std::string::npos || (e + 1 != commandLine.size() && commandLine[e + 1] != ' ' && commandLine[e + 1] != '\t')) { args.clear(); break; } // extract args.push_back(commandLine.substr(i, e - i)); i = e + 1; } else { // unquoted. find next whitespace. e = commandLine.find_first_of(" \t", i); if (e == std::string::npos) { e = commandLine.size(); } // extract args.push_back(commandLine.substr(i, e - i)); i = e + 1; } // next argument i = commandLine.find_first_not_of(" \t", i); } // service name goes first myArgv.push_back(argv[0]); // get pointers for (size_t j = 0; j < args.size(); ++j) { myArgv.push_back(args[j].c_str()); } // adjust argc/argv argc = (DWORD)myArgv.size(); argv = &myArgv[0]; } } m_commandLine = commandLine; try { // invoke daemon function m_daemonResult = m_daemonFunc(static_cast<int>(argc), argv); } catch (XArchDaemonRunFailed& e) { setStatusError(e.m_result); m_daemonResult = -1; } catch (...) { setStatusError(1); m_daemonResult = -1; } // clean up ARCH->closeCondVar(m_serviceCondVar); ARCH->closeMutex(m_serviceMutex); // we're going to exit now, so set status to stopped m_serviceState = SERVICE_STOPPED; setStatus(m_serviceState, 0, 10000); }