static void parseBlock (tokenInfo *const token, const boolean local) { int depth = 1; while (depth > 0) { readToken (token); switch (token->keyword) { default: if (isType (token, TOKEN_IDENTIFIER)) { if (local) makeSqlTag (token, SQLTAG_LOCAL_VARIABLE); else makeSqlTag (token, SQLTAG_VARIABLE); } break; case KEYWORD_cursor: parseSimple (token, SQLTAG_CURSOR); break; case KEYWORD_function: parseSubProgram (token); break; case KEYWORD_procedure: parseSubProgram (token); break; case KEYWORD_subtype: parseSimple (token, SQLTAG_SUBTYPE); break; case KEYWORD_trigger: parseSimple (token, SQLTAG_TRIGGER); break; case KEYWORD_type: parseType (token); break; case KEYWORD_end: --depth; break; case KEYWORD_begin: { while (depth > 0) { switch (token->keyword) { case KEYWORD_if: case KEYWORD_loop: ++depth; readToken (token); break; case KEYWORD_end: --depth; findToken (token, TOKEN_SEMICOLON); break; default: readToken (token); break; } } break; } } findToken (token, TOKEN_SEMICOLON); } }
static boost::optional<Oid> read(std::string::const_iterator begin, std::string::const_iterator end) { Oid ret; bool first = true; size_t bits = 0; size_t n = 0; for (auto i = begin; i != end; ++i) { uint8_t v = *i; n = (n<<bits) + (v & 0x7f); if (v & 0x80) { bits = 7; } else { if (first) { parseSimple(ret.oid, v); first = false; } else { ret.oid.push_back(n); } bits = 0; n = 0; } } if (bits) { return boost::none; } return ret; }
ctkLDAPExpr ctkLDAPExpr::parseExpr( ParseState &ps ) throw (ctkInvalidSyntaxException) { ps.skipWhite(); if (!ps.prefix("(")) ps.error(MALFORMED); int op; ps.skipWhite(); QChar c = ps.peek(); if ( c == '&') { op = AND; }else if ( c == '|' ){ op = OR; } else if ( c == '!' ) { op = NOT; } else { return parseSimple(ps); } ps.skip(1); // Ignore the d->m_operator QList<ctkLDAPExpr> v; do { v.append(parseExpr(ps)); ps.skipWhite(); } while (ps.peek() == '('); int n = v.size(); if (!ps.prefix(")") || n == 0 || (op == NOT && n > 1)) ps.error(MALFORMED); return ctkLDAPExpr(op, v); }
static void parseSqlFile (tokenInfo *const token) { do { readToken (token); switch (token->keyword) { case KEYWORD_cursor: parseSimple (token, SQLTAG_CURSOR); break; case KEYWORD_declare: parseBlock (token, FALSE); break; case KEYWORD_function: parseSubProgram (token); break; case KEYWORD_package: parsePackage (token); break; case KEYWORD_procedure: parseSubProgram (token); break; case KEYWORD_subtype: parseSimple (token, SQLTAG_SUBTYPE); break; case KEYWORD_table: parseTable (token); break; case KEYWORD_trigger: parseSimple (token, SQLTAG_TRIGGER); break; case KEYWORD_type: parseType (token); break; default: break; } } while (! isKeyword (token, KEYWORD_end)); }
void CtcpParser::parse(IrcEventRawMessage *e, Message::Type messagetype) { //lowlevel message dequote QByteArray dequotedMessage = lowLevelDequote(e->rawMessage()); CtcpEvent::CtcpType ctcptype = e->type() == EventManager::IrcEventRawNotice ? CtcpEvent::Reply : CtcpEvent::Query; Message::Flags flags = (ctcptype == CtcpEvent::Reply && !e->network()->isChannelName(e->target())) ? Message::Redirected : Message::None; if (coreSession()->networkConfig()->standardCtcp()) parseStandard(e, messagetype, dequotedMessage, ctcptype, flags); else parseSimple(e, messagetype, dequotedMessage, ctcptype, flags); }
/** parse response from slave. There are two connections between proxy and slave, one to transfer slave to master data, the other for proxy to query slave and get responses. This function deals with the latter situation. **/ void parseReadData(aeEventLoop *el, int fd, int mask, struct WData *wdata){ int index = 0; int flag = 0; struct WData *processData = wdata; if(buf_slave_answer.len > 0){ if(buf_slave_answer.len + wdata->len < MAX_READ * 2){ struct WData merge_buf_cmd; flag = 1; merge_buf_cmd.len=buf_slave_answer.len + wdata->len ; merge_buf_cmd.data=(char*) calloc(merge_buf_cmd.len, sizeof(char)); strncpy(merge_buf_cmd.data, buf_slave_answer.data, buf_slave_answer.len); strncpy(merge_buf_cmd.data + buf_slave_answer.len, wdata->data , wdata->len ); processData = &merge_buf_cmd; } buf_slave_answer.len=0; } while(index >= 0 && index < processData->len){ if(processData->data[index] == '*'){ index = parseArray(processData, index); } else if(processData->data[index] == '$'){ index = parseBulkString(processData, index); } else if(processData->data[index] == '-' || processData->data[index] == '+' || processData->data[index] == ':'){ index = parseSimple(processData, index); } else{ log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "query data unexpected index %d, total %d at line %d in file %s, data %s", index, processData->len, __LINE__, __FILE__, processData->data); printf("query data unexpected index %d, total %d\n", index, processData->len); int i; for(i = 0; i < index; i++) printf("%c", processData->data[i]); printf("\n index %d\n", processData->data[index]); for(i = index + 1; i < processData->len; i++){ printf("%c", processData->data[i]); } printf(" end\n"); break; } } if(flag){ free(processData->data); } }
void CtcpParser::parse(IrcEventRawMessage *e, Message::Type messagetype) { //lowlevel message dequote QByteArray dequotedMessage = lowLevelDequote(e->rawMessage()); CtcpEvent::CtcpType ctcptype = e->type() == EventManager::IrcEventRawNotice ? CtcpEvent::Reply : CtcpEvent::Query; Message::Flags flags = (ctcptype == CtcpEvent::Reply && !e->network()->isChannelName(e->target())) ? Message::Redirected : Message::None; bool isStatusMsg = false; // First remove all statusmsg prefix characters that are not also channel prefix characters. while (e->network()->isStatusMsg(e->target()) && !e->network()->isChannelName(e->target())) { isStatusMsg = true; e->setTarget(e->target().remove(0, 1)); } // Then continue removing statusmsg characters as long as removing the character will still result in a // valid channel name. This prevents removing the channel prefix character if said character is in the // overlap between the statusmsg characters and the channel prefix characters. while (e->network()->isStatusMsg(e->target()) && e->network()->isChannelName(e->target().remove(0, 1))) { isStatusMsg = true; e->setTarget(e->target().remove(0, 1)); } // If any statusmsg characters were removed, Flag the message as a StatusMsg. if (isStatusMsg) { flags |= Message::StatusMsg; } if (coreSession()->networkConfig()->standardCtcp()) parseStandard(e, messagetype, dequotedMessage, ctcptype, flags); else parseSimple(e, messagetype, dequotedMessage, ctcptype, flags); }
CMD *parseStage(token **lstHead) { CMD *cmd = parseSimple(lstHead); if(cmd && cmd->type == ERROR) { //propagate along an error return cmd; } /*if(*lstHead && (*lstHead)->type == PAR_RIGHT) { //right parenthesis before left...error! fprintf(stderr,"%s\n","Error: Right parenthesis before left"); return errorCMD(cmd); }*/ if(*lstHead && (*lstHead)->type == PAR_LEFT) { if(cmd) { //error..subcommand after command fprintf(stderr,"%s\n","Error: Subcommand after command"); return errorCMD(cmd); } *lstHead = (*lstHead)->next; cmd = mallocCMD(); if(*lstHead == NULL) { //error..invalid subcommand fprintf(stderr,"%s\n","Error: Invalid subcommand"); return errorCMD(cmd); } cmd->type = SUBCMD; cmd->left = parseCommand(lstHead); if(cmd->left->type == ERROR) { //propagate error return cmd->left; } if(*lstHead == NULL || ((*lstHead)->type != PAR_RIGHT && !IS_RED((*lstHead)->type))) { //error...parens incorrectly nested fprintf(stderr,"%s\n","Error: Incorrect parenthesis nesting"); return errorCMD(cmd); } *lstHead = (*lstHead)->next; if(*lstHead && IS_RED((*lstHead)->type)) { //redirection found cmd = parseRedirect(lstHead,cmd); if(cmd->type == ERROR) { //if error occurred in parseRedirect return cmd; } } } return cmd; }