本文整理汇总了C++中parseCommand函数的典型用法代码示例。如果您正苦于以下问题:C++ parseCommand函数的具体用法?C++ parseCommand怎么用?C++ parseCommand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parseCommand函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pipe
//Pipe function to allow piping between two programs.
void pipe(const std::string command, std::chrono::duration<double>& totalTime){
char** argv1;
char** argv2;
//Getting two char** argv's from the one already made,
//splitting it by the '|' character/argument in argv.
std::string command1 = "";
std::string command2 = "";
std::stringstream ss;
ss.str(command);
getline(ss, command1, '|');
getline(ss, command2);
parseCommand(command1, argv1);
parseCommand(command2, argv2);
//Constants setup
const int PIPE_COUNT = 2;
const int PIPE_READ_END = 0;
const int PIPE_WRITE_END = 1;
const int STDIN = 0;
const int STDOUT = 1;
//Pipe creation
int pids[PIPE_COUNT];
pipe(pids);
//Duplicate stdout and stdin to use to connect the
//ends back together later
int savedStdout = dup(STDOUT);
int savedStdin = dup(STDIN);
//First process: put the pipe's write end in place of stdout.
pid_t pid1 = fork();
if (pid1 == 0){
dup2(pids[PIPE_WRITE_END], STDOUT);
runAndTimeChildProcess(argv1[0], argv1, totalTime);
exit(111);
}
//Second process: put the pipe's read end in place of stdin,
//and close the pipe's write end to tell 2nd process no more
//data is coming for it to read.
pid_t pid2 = fork();
if (pid2 == 0){
dup2(pids[PIPE_READ_END], STDIN);
close(pids[PIPE_WRITE_END]);
runAndTimeChildProcess(argv2[0], argv2, totalTime);
exit(111);
}
int status;
waitpid(pid1, &status, 0);
close(pids[PIPE_WRITE_END]);
close(pids[PIPE_READ_END]);
waitpid(pid2, &status, 0);
dup2(savedStdout, STDOUT);
dup2(savedStdin, STDIN);
}
示例2: main
int main(int argc, char*argv[]){
string test = "PUT:fileName:DATA";
int t = parseCommand(test);
string data = listen(PORT);
int command = parseCommand(data);
if(command == PUT){
string fileName = getFileName(data);
string dataToWrite = getData(data);
writeFile(fileName, dataToWrite);
}
return 0;
}
示例3: connectionReceiveCommand
int connectionReceiveCommand(connection *con) {
int socketFD = con->tArgs->socketFD;
command *cmd = con->cmd;
error *err = con->err;
// if (cmd->args != NULL) {
// free(cmd->args);
// cmd->args = NULL;
// }
destroyCommandArgs(cmd);
printf("\n>====== Waiting to receive command from client...\n");
char buf[BUFSIZE];
memset(buf, 0, BUFSIZE);
int term;
if (messageReceive(socketFD, buf, &(con->dataBytes), &(con->data), &term)) {
if (term) {
ERROR(err, E_EXIT);
} else {
ERROR(err, E_MSG);
}
return 1;
}
return parseCommand(buf, cmd, err);
}
示例4: qWarning
void ClientThread::run()
{
QTcpSocket tcpSocket;
if (!tcpSocket.setSocketDescriptor(m_socketDescriptor)) {
qWarning() << ":(((";
emit error(tcpSocket.error());
return;
}
m_running = true;
QString command, response;
// Send greetings
tcpSocket.write("OK MPD 0.12.2\n");
while (m_running && (tcpSocket.state() == QAbstractSocket::ConnectedState)) {
m_running = tcpSocket.waitForReadyRead(); // Wait for command,
// if none is received until timeout
// (default 30 seconds, stop running).
command = QString(tcpSocket.readLine()).trimmed();
qDebug() << command;
tcpSocket.write(parseCommand(command).toLocal8Bit());
}
tcpSocket.disconnectFromHost();
}
示例5: wxT
void browsers::CellBrowser::OnWXOpenCell(wxCommandEvent& event)
{
_activeStructure = top_structure = RBcellID;
wxString cmd;
cmd << wxT("opencell(\"") << GetItemText(RBcellID) <<wxT("\");");
parseCommand(cmd);
}
示例6: parseAndOr
CMD *parseCommand(token **lstHead)
{
CMD *cmd = parseAndOr(lstHead);
if(cmd->type == ERROR)
{
//propagate an error
return cmd;
}
//check to make sure that end of linked list not reached
if(cmd && *lstHead && ((*lstHead)->type == SEP_END ||
(*lstHead)->type == SEP_BG))
{
CMD *andorCMD = cmd;
cmd = mallocCMD();
cmd->type = (*lstHead)->type;
cmd->left = andorCMD;
*lstHead = (*lstHead)->next;
if(*lstHead)
{
cmd->right = parseCommand(lstHead);
if(cmd->right->type == ERROR)
{
//propagate along an error
return cmd->right;
}
}
}
return cmd;
}
示例7: handleCommand
static void handleCommand(char *command) {
commandinfo *cinfo = parseCommand(command, MSG_OUTGOING);
switch (cinfo->command) {
case C_QUIT:
cleanup(0);
break;
case C_SYNACK:
sendMessage(sock, "ACK");
break;
case C_GET:
if (cinfo->param == P_POSTS) {
sendMessage(sock, command);
} else if (cinfo->param == P_POST) {
sendMessage(sock, command);
}
break;
default:
sendMessage(sock, command);
break;
}
freeCommandInfo(cinfo);
}
示例8: parseCommand
//Ingresa un string que puede ser tanto un comando, una variable o un literal
//por lo que se procesa y devuelve resuelto, si corresponde, en formato de lista
std::vector<std::string> InterpreteLISP::procesarComandoLISP(
const std::string &input) const {
std::vector<std::string> comando;
std::string palabra;
if (input.empty()) return comando;
if (input.at(0) =='(') {
//el string ingresado es comando LISP
comando = parseCommand(input);
std::string nombreFuncion;
nombreFuncion = comando.front();
comando.erase(comando.begin());
FuncionLISP* funcion = (*funcionesAmbiente)[nombreFuncion];
comando = funcion->resolver(comando, *this);
} else {
//el string ingresado es un simbolo
if ((*variablesAmbiente)[input] != NULL) {
//el simbolo es una variable definida anteriormente
return *((*variablesAmbiente)[input])->getVariable();
} else {
//el simbolo ingresado es un literal
comando.push_back(input);
}
}
return comando;
}
示例9: printNetDevSentBytes
void printNetDevSentBytes(const char *cmd)
{
int i;
char **retval;
retval = parseCommand(cmd);
if (retval == NULL)
return;
for (i = 0; i < NetDevCnt; i++) {
if (!strcmp(NetDevs[i].name, retval[0])) {
if (!strncmp(retval[1], "data", 4))
fprintf(CurrentClient, "%lu", (u_long)((NetDevs[i].sentBytes - NetDevsOld[i].sentBytes) / (1024 * elapsed)));
if (!strncmp(retval[1], "packets", 7))
fprintf(CurrentClient, "%lu", (u_long)((NetDevs[i].sentPacks - NetDevsOld[i].sentPacks) / elapsed));
if (!strncmp(retval[1], "errors", 6))
fprintf(CurrentClient, "%lu", (u_long)((NetDevs[i].sentErrs - NetDevsOld[i].sentErrs) / elapsed));
if (!strncmp(retval[1], "multicast", 9))
fprintf(CurrentClient, "%lu", (u_long)((NetDevs[i].sentMulticast - NetDevsOld[i].sentMulticast) / elapsed));
if (!strncmp(retval[1], "collisions", 10))
fprintf(CurrentClient, "%lu", (u_long)((NetDevs[i].sentColls - NetDevsOld[i].sentColls) / elapsed));
}
}
free(retval[0]);
free(retval[1]);
free(retval);
fprintf(CurrentClient, "\n");
}
示例10: while
void Client::listen() {
string line;
string response = "";
string request = "";
cout << "% ";
// loop to handle user interface
while (getline(cin,line)) {
request = parseCommand(line);
if(request.size() == 0){
cout << "% ";
continue;
}
bool success = sendRequest(request);
// break if an error occurred
if (not success)
break;
// get a response
success = getResponse();
// break if an error occurred
if (not success)
break;
cout << "% ";
}
close(server_);
}
示例11: parseByte
void parseByte (int newByte) // parse an incoming commandbyte from serial interface, perform command if valid
{
static uint8_t cmdlen=0;
if (CimParserActive)
parse_CIM_protocol(newByte); // handle AsTeRICS CIM protocol messages !
else
{
switch (readstate) {
case 0:
if ((newByte=='A') || (newByte=='a')) readstate++;
if (newByte=='@') { readstate++; CimParserActive=1; } // switch to AsTeRICS CIM protocol parser
break;
case 1:
if ((newByte=='T') || (newByte=='t')) readstate++; else readstate=0;
break;
case 2:
if ((newByte=='\r') || (newByte=='\n')) // AT reply: "OK"
{ Serial.println("OK"); readstate=0; }
else if (newByte==' ') { cmdlen=0; readstate++; }
else goto err;
break;
case 3:
if ((newByte=='\r') || (newByte=='\n') || (cmdlen>=MAX_CMDLEN-1))
{ tmpstring[cmdlen]=0; parseCommand(tmpstring);
readstate=0; }
else tmpstring[cmdlen++]=newByte;
break;
default: err: Serial.println("?");readstate=0;
}
}
}
示例12: m_idObj
// Checked: 2009-12-27 (RLVa-1.1.0k) | Modified: RLVa-1.1.0k
RlvCommand::RlvCommand(const LLUUID& idObj, const std::string& strCommand)
: m_idObj(idObj), m_eBehaviour(RLV_BHVR_UNKNOWN), m_fStrict(false), m_eParamType(RLV_TYPE_UNKNOWN)
{
if ((m_fValid = parseCommand(strCommand, m_strBehaviour, m_strOption, m_strParam)))
{
S32 nTemp = 0;
if ( ("n" == m_strParam) || ("add" == m_strParam) )
m_eParamType = RLV_TYPE_ADD;
else if ( ("y" == m_strParam) || ("rem" == m_strParam) )
m_eParamType = RLV_TYPE_REMOVE;
else if (m_strBehaviour == "clear") // clear is the odd one out so just make it its own type
m_eParamType = RLV_TYPE_CLEAR;
else if ("force" == m_strParam)
m_eParamType = RLV_TYPE_FORCE;
else if (LLStringUtil::convertToS32(m_strParam, nTemp)) // Assume it's a reply command if we can convert <param> to an S32
m_eParamType = RLV_TYPE_REPLY;
else
{
m_eParamType = RLV_TYPE_UNKNOWN;
m_fValid = false;
}
}
if (!m_fValid)
{
m_strBehaviour = m_strOption = m_strParam = "";
return;
}
// HACK: all those @addoutfit* synonyms are rather tedious (and error-prone) to deal with so replace them their @attach* equivalent
if ( (RLV_TYPE_FORCE == m_eParamType) && (0 == m_strBehaviour.find("addoutfit")) )
m_strBehaviour.replace(0, 9, "attach");
m_eBehaviour = getBehaviourFromString(m_strBehaviour, &m_fStrict);
}
示例13: readClient
void Client::readClient() {
//qDebug()<<"Client::readClient";
QTcpSocket* socket = (QTcpSocket*)sender();
QByteArray buffer=socket->readLine();
QString response=parseCommand(QString(buffer));
socket->write(response.toLatin1());
}
示例14: processCommand
int Programmanalisator::processCommand(QString* Kadr, int LNum)
{
int Typ=parseCommand(Kadr, LNum); // анализируем кадр
if (Typ<0) {
return -1;
}
switch (Typ) { // выдача сигнала по результатам команды
case BULK_FORM1 : break;
case BULK_FORM2 : emit Kommand(BULK_FORM2, Q1, Q2, Q3, Q4, Q5, Q6, 0);
break;
case FRES_X : emit Kommand(FRES_X,Q1,0,0,0,0,0,0);
break;
case FRES_Y : emit Kommand(FRES_Y,Q1,0,0,0,0,0,0);
break;
case FRES_Z : emit Kommand(FRES_Z,Q1,0,0,0,0,0,0);
break;
case FRES_IX : emit Kommand(FRES_IX,Q1,0,0,0,0,0,0);
break;
case FRES_IY : emit Kommand(FRES_IY,Q1,0,0,0,0,0,0);
break;
case FRES_IZ : emit Kommand(FRES_IZ,Q1,0,0,0,0,0,0);
break;
case TOOL_CALL : emit Kommand(TOOL_CALL,0,0,0,0,0,0,I1);
break;
case LBL_CALL : return I1;
break;
default : break;
}
return 0;
}
示例15: prvCommsTask
void prvCommsTask(void *pvParameters)
{
pvParameters = pvParameters;
static uint8_t line[80];
static uint8_t characterPosition = 0;
initGlobals();
/* Timer to cause outgoing communications to cease if nothing received for 10
seconds */
lapseCommsTimer = xTimerCreate("Lapse Comms",10000,pdFALSE,0,lapseCommsCallback);
while(1)
{
/* Build a command line string before actioning. The task will block
indefinitely waiting for input. */
char character;
xQueueReceive(commsReceiveQueue,&character,portMAX_DELAY);
if ((character == 0x0D) || (character == 0x0A) || (characterPosition > 78))
{
if (lapseCommsTimer != NULL) xTimerReset(lapseCommsTimer,0);
line[characterPosition] = 0;
characterPosition = 0;
parseCommand(line);
}
else line[characterPosition++] = character;
}
}