int main() { char cmd[MAXLINE]; for(; ;) { printf("mysh$ "); fgets(cmd, MAXLINE, stdin); if(strcmp(cmd, "exit\n") == 0) { printf("Now exiting ... good-bye.\n"); return 0; } else { pid_t myprocess = fork(); if(myprocess == 0) { printf("Processing your so desired command...\n"); parse_function(cmd); kill(myprocess); } wait(); } fflush(stdin); } }
static void parse_function(rapidxml::xml_node<>* node, configuration const& config, std::string const& parent, function& f) { if (node != NULL) { std::string name = node->name(); std::string full = parent + "." + name; if (full == ".name") f.name = node->value(); else if (full == ".argsstring") f.argsstring = node->value(); else if (full == ".definition") { f.definition = node->value(); if (! config.skip_namespace.empty()) { boost::replace_all(f.definition, config.skip_namespace, ""); } } else if (full == ".param") { parameter p; parse_parameter(node->first_node(), p); add_or_set(f.parameters, p); } else if (full == ".type") { get_contents(node->first_node(), f.return_type); } else if (full == ".detaileddescription.para.simplesect") { std::string kind = get_attribute(node, "kind"); if (kind == "return") { get_contents(node->first_node(), f.return_description); } /*else if (kind == "param") { get_contents(node->first_node(), f.paragraphs); }*/ } else if (full == ".detaileddescription.para.image") { } parse_function(node->first_node(), config, full, f); parse_function(node->next_sibling(), config, parent, f); } }
struct algo *parse_algo(void) { eat(ALGORITHM); if (lookahead[0]->type == PROCEDURE) return parse_procedure(); else return parse_function(); }
void commandLibraryCall::execute(const std::vector<std::string>& cmd) { if (svmMemory->get_start()) { index_t rDest = parse_register(cmd[1]); index_t rSrc = parse_register(cmd[2]); std::string func = parse_function(cmd[3]); execute(rDest, rSrc, func); } svmMemory->inc_program_counter(); }
void commandLibraryCall::execute(const std::vector<bytecode_t>& cmd) { counter_t pointer = svmMemory->get_program_counter(); if (svmMemory->get_start()) { index_t rDest = cmd[pointer+1] & 0x0F; index_t rSrc = (cmd[pointer+1] & 0xF0) >> 4; std::string func; pointer = pointer + 2; while (cmd[pointer] != 0) func += cmd[pointer++]; execute(rDest, rSrc, parse_function(func)); }
static void makeTags (xmlNode *node, const gchar *parent) { g_assert (node != NULL); g_assert (node->name != NULL); if (strcmp ((const gchar*)node->name, "text") == 0 || strcmp ((const gchar*)node->name, "implements") == 0) return; if (strcmp ((const gchar*)node->name, "enumeration") == 0 || strcmp ((const gchar*)node->name, "union") == 0 || strcmp ((const gchar*)node->name, "namespace") == 0 || strcmp ((const gchar*)node->name, "class") == 0 || strcmp ((const gchar*)node->name, "record") == 0 || strcmp ((const gchar*)node->name, "bitfield") == 0 || strcmp ((const gchar*)node->name, "interface") == 0) { parse_class (node); return; } if (strcmp ((const gchar*)node->name, "function") == 0 || strcmp ((const gchar*)node->name, "method") == 0 || strcmp ((const gchar*)node->name, "callback") == 0 || strcmp ((const gchar*)node->name, "constructor") == 0) { parse_function (node, parent); return; } if (strcmp ((const gchar*)node->name, "alias") == 0 || strcmp ((const gchar*)node->name, "constant") == 0 || strcmp ((const gchar*)node->name, "signal") == 0 || strcmp ((const gchar*)node->name, "field") == 0 || strcmp ((const gchar*)node->name, "property") == 0 || strcmp ((const gchar*)node->name, "member") == 0) { gchar *name = (gchar*)xmlGetProp (node, (const xmlChar*)"name"); if (!name) return; tagEntryInfo *tag = (tagEntryInfo*)malloc (sizeof (tagEntryInfo)); initTagEntry (tag, name); tag->isFileScope = 1; tag->kindName = "variable"; tag->kind = 'v'; get_file_pos (node->line, &tag->filePosition, File.fp); tag->lineNumber = node->line; if (parent) { tag->kindName = "member"; tag->kind = 'm'; tag->extensionFields.scope[0] = "class"; tag->extensionFields.scope[1] = parent; } makeTagEntry (tag); return; } }
static int calcitem_parse_expression(DC_ITEM *dc_item, expression_t *exp, char *error, int max_error_len) { const char *__function_name = "calcitem_parse_expression"; char *e, *f, *func = NULL, *params = NULL; int functionid, exp_alloc = 128, exp_offset = 0, ret; zabbix_log(LOG_LEVEL_DEBUG, "In %s() expression:'%s'", __function_name, dc_item->params_orig); assert(dc_item); assert(exp); exp->exp = zbx_malloc(exp->exp, exp_alloc); for (e = dc_item->params_orig; '\0' != *e; e++) { if (NULL != strchr(" \t\r\n", *e)) continue; f = e; if (FAIL == parse_function(&e, &func, ¶ms)) { e = f; calcitem_exp_addchr(&exp->exp, &exp_alloc, &exp_offset, 128, *f); continue; } else e--; functionid = calcitem_add_function(exp, func, params); zabbix_log(LOG_LEVEL_DEBUG, "%s() functionid:%d function:'%s(%s)'", __function_name, functionid, func, params); func = NULL; params = NULL; zbx_snprintf_alloc(&exp->exp, &exp_alloc, &exp_offset, 16, "{%d}", functionid); } calcitem_exp_addchr(&exp->exp, &exp_alloc, &exp_offset, 1, '\0'); zabbix_log(LOG_LEVEL_DEBUG, "%s() expression:'%s'", __function_name, exp->exp); if (FAIL == (ret = substitute_simple_macros(NULL, NULL, NULL, dc_item, NULL, &exp->exp, MACRO_TYPE_ITEM_EXPRESSION, error, max_error_len))) ret = NOTSUPPORTED; zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
// Parses a set of function arguments struct list *parse_function_args(struct lexer_state *lexer) { struct function *arg = NULL; struct list *args = list_new(); while(lexer->error == OK) { // First parse a function and add it to the list arg = parse_function(lexer); if(!arg) { clear_function_list(args); return NULL; } list_push_back(args, arg); // Then look for either a separator or a close lex(lexer); if(lexer->error == UNRECOGNIZED_TOKEN) { print_error(lexer, LEX_ERROR); clear_function_list(args); return NULL; } if(lexer->error == END_OF_INPUT) { print_error(lexer, UNEXPECTED_END); clear_function_list(args); return NULL; } if(lexer->type == CLOSE_FORM) break; // If there hasn't been a close, then it better be a separator if(lexer->type != SEPARATOR) { print_error(lexer, INVALID_ELEMENT); clear_function_list(args); return NULL; } } return args; }
void handle_guest_message(const char *message) { fprintf(guestlog, "%s\n", message); switch (message[0]) { case 'P': parse_process(message); break; case 'M': parse_module(message); break; case 'F': parse_function(message); break; } }
int parse_desc_file(FILE* f, DESC* desc) { int c = 0; char* value; char line[256], buffer[256]; while (fgets(line, sizeof(line), f) != 0 && c < 4) { if (sscanf(line, "%s", buffer) != 1) return PARSE_ERROR; value = strchr(buffer, '='); if (!(value && strlen(value) > 1)) return PARSE_ERROR; value++; switch (c) { case 0: if (!parse_name(value, desc->name)) return PARSE_ERROR; break; case 1: if (!parse_type(value, &(desc->type))) return PARSE_ERROR; break; case 2: if (!parse_opcode(value, &(desc->opcode))) return PARSE_ERROR; break; case 3: if (desc->type == 'R') { if (!parse_function(value, &(desc->function))) return PARSE_ERROR; } else { desc->function = -1; } break; } c++; } return PARSE_SUCCESS; }
static void compile(str_iter iter) { #define advance (cur_tok = get_token(&iter)) ast ast; token cur_tok; while (1) { switch (advance.kind) { case Tok_keyword_fn: { parse_function(&ast, &iter); } break; case Tok_eof: { } return; default: { } token_error(str_from_lit("item"), &cur_tok); } } #undef advance }
exparser::return_type exparser::loop(const std::string& s) { if (s.empty()) return return_false; if (debug) std::cout << "PARSING : " << s << std::endl; if (debug) std::cerr << "Try parenthesis" << std::endl; return_type parenthesis = parse_parenthesis(s); if (parenthesis) return parenthesis; if (debug) std::cerr << "Try constant" << std::endl; return_type constant = parse_constant(s); if (constant) return constant; if (debug) std::cerr << "Try variable" << std::endl; return_type variable = parse_variable(s); if (variable) return variable; if (debug) std::cerr << "Try plus" << std::endl; return_type plus = parse_plus(s); if (plus) return plus; if (debug) std::cerr << "Try minus" << std::endl; return_type minus = parse_minus(s); if (minus) return minus; if (debug) std::cerr << "Try multiply" << std::endl; return_type multiply = parse_multiply(s); if (multiply) return multiply; if (debug) std::cerr << "Try divide" << std::endl; return_type divide = parse_divide(s); if (divide) return divide; if (debug) std::cerr << "Try poewr" << std::endl; return_type power = parse_power(s); if (power) return power; if (debug) std::cerr << "Try function" << std::endl; return_type function = parse_function(s); if (function) return function; return return_false; }
int main(int argc, char **argv) { if (argc < 4) { LOGF("you must provide 3 arguments to function: F, X, LEN"); return 0; } jit_context = jit_context_create(); jit_context_build_start(jit_context); jit_function_t func = parse_function(); jit_context_build_end(jit_context); jit_float64 result, f = atof(argv[1]); jit_nuint x = atoi(argv[2]), len = atoi(argv[3]); void *args[3] = {&f, &x, &len}; jit_function_apply(func, args, &result); LOGF("f(%f, %i, %i) = %f", f, x, len, result); jit_context_destroy(jit_context); return 0; }
PExprAST Parser::get_next_expression() { if (first_read) { //Read the first token get_next_token(); first_read = false; } while (true) { //TODO Handle global variable //Top level prototype if (is_type(current_tok)) return parse_prototype(); switch(current_tok) { case Token::EndOfFile: return PExprAST(nullptr); case Token::EndInstr: //Ignore top level end of instr //And top level comments get_next_token(); break; case Token::Define: return parse_function(); case Token::Extern: return parse_extern(); default: throw ParserException(ParserExceptionType::ExpectedTopLevel); } } }
/** * ts_parse_packet - Parse a transport stream packet. Called by the backend's process() function. */ int ts_parse_packet(const struct ts_header *header, const char *payload, struct demuxfs_data *priv) { int ret = 0; uint8_t pointer_field = 0; uint16_t section_length = 0; const char *payload_end; const char *payload_start = payload; parse_function_t parse_function; if (header->sync_byte != TS_SYNC_BYTE) { TS_WARNING("sync_byte != %#x (%#x)", TS_SYNC_BYTE, header->sync_byte); return -EBADMSG; } if (header->adaptation_field == 0x00) { /* ITU-T Rec. H.222.0 decoders shall discard this packet */ return 0; } else if (header->adaptation_field == 0x01) { /* No adaptation field, payload only */ } else if (header->adaptation_field == 0x02) { /* Adaptation field only, no payload */ return 0; } else if (header->adaptation_field == 0x03) { /* Adaptation field followed by payload */ uint8_t adaptation_field_length = payload[0]; payload_start += 1 + adaptation_field_length; if ((payload_start - payload) > priv->options.packet_size) { TS_WARNING("adaptation_field length is bigger than a TS packet: %d", adaptation_field_length); return -ENOBUFS; } /* TODO: parse adaptation field */ } struct user_options *opt = &priv->options; payload_end = payload + opt->packet_size - 4 - 1 - opt->packet_error_correction_bytes; //ts_dump_header(header); //ts_dump_payload(payload, payload_end-payload_start); struct buffer *buffer = NULL; if (ts_is_psi_packet(header->pid, priv)) { const char *start = payload_start; const char *end = payload_end; bool is_new_packet = false; bool pusi = header->payload_unit_start_indicator; uint8_t table_id; if (pusi) { /* The first byte of the payload carries the pointer_field */ pointer_field = payload_start[0]; start = payload_start + 1; if ((payload_start + pointer_field) > payload_end) { TS_WARNING("pointer_field > TS packet size (%d)", pointer_field); return -ENOBUFS; } section_length = CONVERT_TO_16(start[1], start[2]) & 0x0fff; if ((int) pointer_field > 0) { end = payload_start + pointer_field; } else { is_new_packet = true; end = ((payload_start + 3 + section_length) <= payload_end) ? payload_start + 3 + section_length : payload_end; } } while (start <= payload_end) { buffer = hashtable_get(priv->packet_buffer, header->pid); if (! buffer && is_new_packet) { buffer = buffer_create(header->pid, section_length + 3, false); if (! buffer) return 0; buffer->continuity_counter = header->continuity_counter; hashtable_add(priv->packet_buffer, header->pid, buffer, NULL); } else if (buffer && ! continuity_counter_is_ok(header, buffer, true, priv)) { return 0; } else if (buffer && buffer->current_size == 0 && ! is_new_packet) { /* * Cannot start appending data if we don't have PUSI set and there are * no contents in the buffer yet. */ if (! pusi) return 0; /* * The second half of the packet can very well have valid data. * Just invalidate the buffer to return to the beginning of the loop. */ buffer = NULL; } if (is_new_packet && IS_STUFFING_PACKET(start)) buffer = NULL; if (buffer) { int ret = buffer_append(buffer, start, end - start + 1); if (ret >= 0 && buffer_contains_full_psi_section(buffer)) { table_id = buffer->data[0]; if (! crc32_check(buffer->data, buffer->current_size) && priv->options.verbose_mask & CRC_ERROR) TS_WARNING("CRC error on PID %d(%#x), table_id %d(%#x)", header->pid, header->pid, table_id, table_id); else if ((parse_function = ts_get_psi_parser(header, table_id, priv))) /* Invoke the PSI parser for this packet */ ret = parse_function(header, buffer->data, buffer->current_size, priv); buffer_reset_size(buffer); } } if (! pusi || pointer_field == 0) break; if (buffer) buffer_reset_size(buffer); start = end + 1; if (start >= (payload_end-1)) /* No more data to parse */ break; section_length = CONVERT_TO_16(start[1], start[2]) & 0x0fff; if (IS_STUFFING_PACKET(start) || section_length == 0) /* Nothing to parse */ break; end = ((start + section_length + 2) <= payload_end) ? start + section_length + 2 : payload_end; pusi = false; is_new_packet = true; } } else if (ts_is_pes_packet(header->pid, priv)) { uint16_t size; bool pusi = header->payload_unit_start_indicator; buffer = hashtable_get(priv->packet_buffer, header->pid); if (! buffer) { if (! pusi || (payload_end - payload_start <= 6)) return 0; size = CONVERT_TO_16(payload_start[4], payload_start[5]); buffer = buffer_create(header->pid, size, true); if (! buffer) return 0; buffer->continuity_counter = header->continuity_counter; hashtable_add(priv->packet_buffer, header->pid, buffer, NULL); } else if (!continuity_counter_is_ok(header, buffer, false, priv) || (buffer_get_current_size(buffer) == 0 && !buffer_is_unbounded(buffer) && (!pusi || (payload_end - payload_start <= 6)))) { return 0; } buffer_append(buffer, payload_start, payload_end - payload_start + 1); if (buffer_contains_full_pes_section(buffer)) { /* Invoke the PES parser for this packet */ if ((parse_function = (parse_function_t) hashtable_get(priv->pes_parsers, header->pid))) ret = parse_function(header, buffer->data, buffer->current_size, priv); buffer_reset_size(buffer); } } if (buffer) buffer->continuity_counter = header->continuity_counter; return ret; }
// Parses the output of a lexer, builds a symtable and returns it struct symtable *parse(struct lexer_state *lexer) { int error = 0; char *ident = NULL; struct function *definition = NULL; struct symtable *table = symtable_new(); // At the top level, we expect // <ident> "=" <function-expression> while(lexer->error == OK) { // First lex the function name lex(lexer); // Check for end of file if(lexer->error == END_OF_INPUT) break; // Check for lex error if(lexer->error == UNRECOGNIZED_TOKEN) { print_error(lexer, LEX_ERROR); error = 1; break; } if(lexer->type != IDENT) { print_error(lexer, EXPECTED_IDENT); error = 1; break; } // Otherwise, grab the name ident = strdup(lexer->value.sval); // Require the assign operator if(!require_token(lexer, ASSIGN)) { print_error(lexer, EXPECTED_ASSIGN); error = 1; break; } // Parse the function definition definition = parse_function(lexer); if(!definition) { error = 1; break; } // ...and finally add both to symtable symtable_add(table, ident, definition); free(ident); } // If any errors occurred, delete the symtable and return NULL if(error) { symtable_delete(table); return NULL; } // Otherwise, return the symtable return table; }
static int calcitem_parse_expression(DC_ITEM *dc_item, expression_t *exp, char *error, int max_error_len) { const char *__function_name = "calcitem_parse_expression"; char *e, *f, *func = NULL, *params = NULL; size_t exp_alloc = 128, exp_offset = 0, len; int functionid, ret; zabbix_log(LOG_LEVEL_DEBUG, "In %s() expression:'%s'", __function_name, dc_item->params); assert(dc_item); assert(exp); exp->exp = zbx_malloc(exp->exp, exp_alloc); for (e = dc_item->params; '\0' != *e; e++) { if (SUCCEED != is_function_char(*e)) { zbx_chrcpy_alloc(&exp->exp, &exp_alloc, &exp_offset, *e); continue; } if ((0 == strncmp("and", e, len = 3) || 0 == strncmp("not", e, 3) || 0 == strncmp("or", e, len = 2)) && NULL != strchr("()" ZBX_WHITESPACE, e[len])) { zbx_strncpy_alloc(&exp->exp, &exp_alloc, &exp_offset, e, len); e += len - 1; continue; } f = e; if (SUCCEED != parse_function(&e, &func, ¶ms)) { e = f; zbx_chrcpy_alloc(&exp->exp, &exp_alloc, &exp_offset, *f); continue; } else e--; functionid = calcitem_add_function(exp, func, params); zabbix_log(LOG_LEVEL_DEBUG, "%s() functionid:%d function:'%s(%s)'", __function_name, functionid, func, params); func = NULL; params = NULL; zbx_snprintf_alloc(&exp->exp, &exp_alloc, &exp_offset, "{%d}", functionid); } zabbix_log(LOG_LEVEL_DEBUG, "%s() expression:'%s'", __function_name, exp->exp); if (FAIL == (ret = substitute_simple_macros(NULL, NULL, NULL, NULL, NULL, &dc_item->host, NULL, NULL, &exp->exp, MACRO_TYPE_ITEM_EXPRESSION, error, max_error_len))) ret = NOTSUPPORTED; zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
/* * Parse expression and output appropriate tokens. * Return token at end of expression. */ int parse_expression(TOKEN *token) { int token_class; int i, last_class, temp_class; DECL_MEMBER *id_type; DECL_ID *id_id; char *new_id; char string_const[MAX_TOKEN_LENGTH], octal_const[5]; last_class = OPERATOR; token_class = get_token(token); while (1) { switch (token_class) { case LEFT_PAREN : if (last_class != OPERATOR) { parse_error("Missing operator"); return ERROR; } /* Sub-expression */ out_token(token); /* Parse to closing right paren */ token_class = parse_expression(token); if (token_class != RIGHT_PAREN) { parse_error("Missing ')'"); return ERROR; } out_token(token); break; case RIGHT_PAREN : return token_class; case OPERATOR : out_white_space(token); if (token->token_type == EQUAL) /* Make it a '==' */ out_str("=="); else /* Check for address operator '@' or '.' */ if ((token->token_type == AT_OP) || (token->token_type == PERIOD)) { token_class = get_token(token); if (token_class == IDENTIFIER) { /* Make it a '&' */ out_char('&'); /* See if it's a function reference */ if (find_symbol(token, &id_type, &id_id) && (id_type->type->token_type != PROCEDURE)) { /* Variable - parse it */ temp_class = parse_member(token, id_type, id_id); } else { /* Function call - Check for */ /* a function conversion */ if (check_cvt_id(token, &cvt_functions[0], &new_id)) /* Convert to desired function */ out_str(new_id); else /* Function call - output name */ out_token_name(token); temp_class = get_token(token); } } else if (token_class == LEFT_PAREN) { /* Constant list - convert to string */ out_char('"'); string_const[0] = '\0'; do { token_class = get_token(token); if (token_class == STRING) (void) strcat(string_const, token->token_name); else if (token_class == NUMERIC) { cvt_octal(token, octal_const); (void) strcat(string_const, octal_const); } else { parse_error("Illegal constant"); return ERROR; } token_class = get_token(token); } while (token_class == COMMA); if (token_class != RIGHT_PAREN) { parse_error("')' expected"); return ERROR; } i = strlen(string_const); if ((i >= 4) && (!strcmp(string_const + i - 4, "\\000"))) /* Discard trailing null */ string_const[i - 4] = '\0'; out_str(string_const); out_char('"'); } else { parse_error("Illegal operator"); return ERROR; } } else out_token_name(token); break; case IDENTIFIER : /* Check for identifier conversion */ if (check_cvt_id(token, &cvt_identifiers[0], &new_id)) { out_white_space(token); out_str(new_id); temp_class = get_token(token); } else /* See if variable in context */ if (find_symbol(token, &id_type, &id_id) && (id_type->type->token_type != PROCEDURE)) { /* Variable - parse it */ temp_class = parse_member(token, id_type, id_id); } else /* Function call - parse it */ temp_class = parse_function(token); break; case NUMERIC : out_token(token); break; case STRING : out_white_space(token); /* Convert to a numeric constant */ if (token->token_length > 4) { parse_error("Illegal string constant"); return ERROR; } if (token->token_length > 1) out_char('('); out_str_const(token->token_name, token->token_length); if (token->token_length > 1) out_char(')'); break; default : /* Must not be part of an expression! */ return token_class; } last_class = token_class; token_class = (last_class == IDENTIFIER) ? temp_class : get_token(token); } }
static int DBpatch_2030095(void) { DB_RESULT result; DB_ROW row; int ret = SUCCEED; char *p, *q, *params = NULL, *params_esc; size_t params_alloc = 0, params_offset; result = DBselect("select itemid,params from items where type=%d", 15 /* ITEM_TYPE_CALCULATED */); while (SUCCEED == ret && NULL != (row = DBfetch(result))) { params_offset = 0; for (p = row[1]; '\0' != *p; p++) { if (NULL != strchr(ZBX_WHITESPACE, *p)) { if (' ' != *p || (0 != params_offset && NULL == strchr(ZBX_WHITESPACE, params[params_offset - 1]))) { zbx_chrcpy_alloc(¶ms, ¶ms_alloc, ¶ms_offset, *p); } continue; } if (NULL != strchr("#&|", *p)) { if ('#' == *p && 0 != params_offset && '{' == params[params_offset - 1]) { zbx_chrcpy_alloc(¶ms, ¶ms_alloc, ¶ms_offset, *p); continue; } if (('&' == *p || '|' == *p) && 0 != params_offset && NULL == strchr(ZBX_WHITESPACE, params[params_offset - 1])) { zbx_chrcpy_alloc(¶ms, ¶ms_alloc, ¶ms_offset, ' '); } switch (*p) { case '#': zbx_strcpy_alloc(¶ms, ¶ms_alloc, ¶ms_offset, "<>"); break; case '&': zbx_strcpy_alloc(¶ms, ¶ms_alloc, ¶ms_offset, "and"); break; case '|': zbx_strcpy_alloc(¶ms, ¶ms_alloc, ¶ms_offset, "or"); break; } if (('&' == *p || '|' == *p) && NULL == strchr(ZBX_WHITESPACE, *(p + 1))) zbx_chrcpy_alloc(¶ms, ¶ms_alloc, ¶ms_offset, ' '); continue; } q = p; if (SUCCEED == parse_function(&q, NULL, NULL)) { zbx_strncpy_alloc(¶ms, ¶ms_alloc, ¶ms_offset, p, q - p); p = q - 1; continue; } zbx_chrcpy_alloc(¶ms, ¶ms_alloc, ¶ms_offset, *p); } #if defined(HAVE_IBM_DB2) || defined(HAVE_ORACLE) if (2048 < params_offset && 2048 /* ITEM_PARAM_LEN */ < zbx_strlen_utf8(params)) #else if (65535 < params_offset && 65535 /* ITEM_PARAM_LEN */ < zbx_strlen_utf8(params)) #endif { zabbix_log(LOG_LEVEL_WARNING, "cannot convert calculated item expression \"%s\":" " resulting expression is too long", row[1]); } else if (0 != strcmp(row[1], params)) { params_esc = DBdyn_escape_string(params); if (ZBX_DB_OK > DBexecute("update items set params='%s' where itemid=%s", params_esc, row[0])) ret = FAIL; zbx_free(params_esc); } } DBfree_result(result); zbx_free(params); return ret; }
/** * Assumed that the right image is bound to IL */ int perform_operation(const char * operation, int verbose) { /* Where to store the first parsing results? */ char function[long_strlen], params[long_strlen], solid_params[long_strlen]; /* Get the function name string and parameters string */ parse_function(operation, function, params); /* Get rid of any whitespaces from the parameters string */ remove_whitespaces(params, solid_params); if (verbose) printf("Calling %s(%s)\n", function, solid_params); /* What function was wanted? -1 means that we don't know */ int function_index = -1; int i; for (i = 0; i < ILU_FUN_COUNT; i++) if (strncmp(function, ilu_functions[i].Name, short_strlen) == 0) {/* Yeah, this function was wanted. Let's have its index from the ilu_functions array */ function_index = i; break; /* nothing to do here any more */ } if (function_index == -1) {/* Seems we haven't found anything... */ fprintf(stderr, "Error: You have specified an invalid function name '%s' (have you called %s).\nRun '%s --help' command to get some help\n", function, operation, program_name); return 1; } /* We are going to try something and we want to know how it ended */ ILboolean return_value; switch (ilu_functions[function_index].Parameter_type) {/* First semi-automatic processing according to type of parameters */ case PARAM_VOID: { ILboolean (* function)() = ilu_functions[function_index].Callback; return_value = function(); break; }/* endcase PARAM_VOID */ case PARAM_ILUINT: { /* first assign and determine the type of the Callback */ ILboolean (* function)(ILuint) = ilu_functions[function_index].Callback; /* then declare the parameter variables */ ILuint param_value; /* fill them */ int success = sscanf(solid_params, "%u", & param_value); if (success != 1) {/* see how it ended */ fprintf(stderr, "Error interpreting '%s' as unsigned integer (when calling %s)\n", solid_params, operation); break; } /* execute the command and store the result */ return_value = function(param_value); break; }/* endcase PARAM_ILUINT */ case PARAM_ILFLOAT: { ILboolean (* function)(ILfloat) = ilu_functions[function_index].Callback; double param_value; int success = sscanf(solid_params, "%lf", & param_value); if (success != 1) { fprintf(stderr, "Error interpreting '%s' as float (when calling %s)\n", solid_params, operation); break; } return_value = function((ILfloat)param_value); break; }/* endcase PARAM_ILFLOAT */ case PARAM_OTHERS: switch (function_index) {/* next, the manual processing according to names */ case ILU_SHARPEN: { ILboolean (* function)(ILfloat, ILuint) = ilu_functions[function_index].Callback; double factor; ILuint iter; int success = sscanf(solid_params, "%lf,%u", & factor, & iter); if (success != 2) { fprintf(stderr, "Error interpreting '%s' as floating-point number and unsigned integer separated by comma (when calling %s)\n", solid_params, operation); break; } return_value = function((ILfloat)factor, iter); break; }/* endcase ILU_SHARPEN */ case ILU_CROP: { ILboolean (* function)(ILuint, ILuint, ILuint, ILuint, ILuint, ILuint ) = ilu_functions[function_index].Callback; ILuint xoff, yoff, zoff, width, height, depth; int success = sscanf(solid_params, "%u,%u,%u,%u,%u,%u", & xoff, & yoff, & zoff, & width, & height, & depth); if (success != 6) { fprintf(stderr, "Error interpreting '%s' as 6 unsigned integers separated by comma (when calling %s)\n", solid_params, operation); break; } return_value = function(xoff, yoff, zoff, width, height, depth); break; }/* endcase ILU_CROP */ case ILU_ENLARGECANVAS: case ILU_SCALE: { ILboolean (* function)(ILuint, ILuint, ILuint) = ilu_functions[function_index].Callback; ILuint width, height, depth; int success = sscanf(solid_params, "%u,%u,%u", & width, & height, & depth); if (success != 3) { fprintf(stderr, "Error interpreting '%s' as 3 unsigned integers separated by comma (when calling %s)\n", solid_params, operation); break; } return_value = function(width, height, depth); break; }/* endcase ILU_ENLARGECANVAS + ILU_SCALE */ case ILU_ENLARGEIMAGE: case ILU_SCALECOLOURS: { ILboolean (* function)(ILfloat, ILfloat, ILfloat) = ilu_functions[function_index].Callback; double first, second, third; int success = sscanf(solid_params, "%lf,%lf,%lf", & first, & second, & third); if (success != 3) { fprintf(stderr, "Error interpreting '%s' as 3 floating-point numbers separated by comma (when calling %s)\n", solid_params, operation); break; } return_value = function((ILfloat)first, (ILfloat)second, (ILfloat)third); break; }/* endcase ILU_ENLARGEIMAGE + ILU_SCALECOLOURS */ case ILU_ROTATE3D: case ILU_SATURATE4F: { ILboolean (* function)(ILfloat, ILfloat, ILfloat, ILfloat) = ilu_functions[function_index].Callback; double first, second, third, fourth; int success = sscanf(solid_params, "%lf,%lf,%lf,%lf", & first, & second, & third, & fourth); if (success != 4) { fprintf(stderr, "Error interpreting '%s' as 4 floating-point numbers separated by comma (when calling %s)\n", solid_params, operation); break; } return_value = function((ILfloat)first, (ILfloat)second, (ILfloat)third, (ILfloat)fourth); break; }/* endcase ILU_ROTATE3D + ILU_SATURATE4F */ case ILU_REPLACECOLOUR: { ILboolean (* function)(ILubyte, ILubyte, ILubyte, ILfloat ) = ilu_functions[function_index].Callback; ILuint red, green, blue; double tolerance; int success = sscanf(solid_params, "%u,%u,%u,%lf", & red, & green, & blue, & tolerance); if (success != 4) { fprintf(stderr, "Error interpreting '%s' as 3 8-bit unsigned integers and one floating-point number separated by comma (when calling %s)\n", solid_params, operation); break; } return_value = function((ILubyte)red, (ILubyte)green, (ILubyte)blue, (ILfloat)tolerance); break; }/* endcase ILU_ROTATE3D + ILU_SATURATE4F * */ /* iluConvolution(ILint *matrix, ILint scale, ILint bias); Any idea about this? */ }/* endswitch(function_index) */ break; }/* endswitch (ilu_functions[function_index].Parameter_type) */ /* It didn't end good for some reason... */ if (return_value == IL_FALSE) { int error= ilGetError(); fprintf(stderr, "Something got wrong when calling %s(%s): %s\n", function, solid_params, iluErrorString(error) ); return error; } return 0; }
static void parse(rapidxml::xml_node<>* node, configuration const& config, documentation& doc, bool member = false) { if (node != NULL) { bool recurse = false; bool is_member = member; std::string nodename = node->name(); if (nodename == "doxygen") { recurse = true; } else if (nodename == "sectiondef") { std::string kind = get_attribute(node, "kind"); if (kind == "func" || kind == "define" || kind == "enum" ) { recurse = true; } else if (boost::starts_with(kind, "public")) { recurse = true; is_member = true; } } else if (nodename == "compounddef") { std::string kind = get_attribute(node, "kind"); if (kind == "group") { recurse = true; } else if (kind == "struct") { recurse = true; doc.cos.is_class = false; parse_element(node->first_node(), config, "", doc.cos); } else if (kind == "class") { recurse = true; doc.cos.is_class = true; parse_element(node->first_node(), config, "", doc.cos); } } else if (nodename == "memberdef") { std::string kind = get_attribute(node, "kind"); if (kind == "function") { function f; parse_element(node->first_node(), config, "", f); parse_function(node->first_node(), config, "", f); if (member) { f.type = boost::equals(f.name, doc.cos.name) ? function_constructor : function_member; doc.cos.functions.push_back(f); } else { f.type = function_free; doc.functions.push_back(f); } } else if (kind == "define") { function f; f.type = function_define; parse_element(node->first_node(), config, "", f); parse_function(node->first_node(), config, "", f); doc.functions.push_back(f); } else if (kind == "enum") { enumeration e; parse_element(node->first_node(), config, "", e); parse_enumeration(node->first_node(), config, "", e); doc.enumerations.push_back(e); } else if (kind == "typedef") { if (boost::equals(get_attribute(node, "prot"), "public")) { std::string name = parse_named_node(node->first_node(), "name"); doc.cos.typedefs.push_back(base_element(name)); } } else if (kind == "variable") { if (boost::equals(get_attribute(node, "static"), "yes") && boost::equals(get_attribute(node, "mutable"), "no") && boost::equals(get_attribute(node, "prot"), "public")) { std::string name = parse_named_node(node->first_node(), "name"); doc.cos.variables.push_back(base_element(name)); } } } else if (nodename == "compoundname") { std::string name = node->value(); if (name.find("::") != std::string::npos) { doc.cos.fullname = name; // For a class, it should have "boost::something::" before // set its name without namespace doc.cos.name = keep_after(name, "::"); } } else if (nodename == "basecompoundref") { base_class bc; bc.name = node->value(); bc.derivation = get_attribute(node, "prot"); bc.virtuality = get_attribute(node, "virt"); doc.cos.base_classes.push_back(bc); } else { //std::cout << nodename << " ignored." << std::endl; } if (recurse) { // First recurse into childnodes, then handle next siblings parse(node->first_node(), config, doc, is_member); } parse(node->next_sibling(), config, doc, is_member); } }
void parse_command (char *command, int linenum) { char *temp; char writeme[1024]; //int val = 0; temp = malloc(strlen(command)*sizeof(char) + 1); strcpy(temp, command); if (temp) { /* trim whitespace */ temp = str_trim(temp); for (i=0; i < functionnum; i++) { if (!strcmp(functions[i].name, command)) { parse_function(i, linenum); free(temp); return; } } if(strcmp(temp, "end") == 0) { quit(); } else if (strcmp(temp, "pop") == 0) { stack_pop(&stack); } else if (!strcmp(temp, "dup")) { stackElementT tempElement = stack_pop(&stack); stack_push(&stack, tempElement); stack_push(&stack, tempElement); } else if (strcmp(temp, "add") == 0) { stack_push(&stack, stack_pop(&stack) + stack_pop(&stack)); } else if (!strcmp(temp, "push")) { /* push is basically a noop now since the argument handling does it instead */ } else if (!strcmp(temp, "print")) { putchar(stack_peek(&stack)); } else if (!strcmp(temp, "iprint")) { printf("%d", stack_peek(&stack)); } else if (!strcmp(temp, "line")) { printf("\n"); } else if (!strcmp(temp, "swap")) { stack_swap(&stack); } else if (!strcmp(temp, "zsk")) { if (stack_peek(&stack) == 0) { fgets(writeme, 1024, fp); } } else if (!strcmp(temp, "nzsk")) { if (stack_peek(&stack) != 0) { fgets(writeme, 1024, fp); } } else if (!strcmp(temp, "esk")) { if (stack_empty(&stack)) { fgets(writeme, 1024, fp); } } else if (!strcmp(temp, "nesk")) { if (!stack_empty(&stack)) { fgets(writeme, 1024, fp); } } else if (!strcmp(temp, "return")) { fseek(fp, stack_pop(&callstack), SEEK_SET); } else if (!strcmp(temp, "give")) { stack_push(&auxstack, stack_pop(&stack)); } else if (!strcmp(temp, "take")) { stack_push(&stack, stack_pop(&auxstack)); } else if (!strcmp(temp, "argc")) { stack_push(&stack, argcount); } else if (!strcmp(temp, "neg")) { stack_push(&stack, -1*stack_pop(&stack)); } else if (!strcmp(temp, "input")) { fgets(writeme, 1024, stdin); inpcount = strlen(writeme)-1; for (i = inpcount; i >= 0; i--) { if (writeme[i] != '\n') { stack_push(&stack, writeme[i]); } } } else if (!strcmp(temp, "inpc")) { stack_push(&stack, inpcount); } else if (!strcmp(temp, "rand")) { stack_push(&stack, rand() % stack_pop(&stack)); } else if (!strcmp(temp, "")) { // DON'T DO ANYTHING, because it's an empty command } else if (!strcmp(temp, "stack")) { printf("<- "); stackNodeT *node = stack.top; while (node) { printf("%d ", node->value); node = node->next; } printf("]\n"); } else { fprintf(stderr, "\nunrecognized command: `%s` at line %d.", temp, linenum); } /*if (strcmp(temp, "stack")) { printf("STACK : "); parse_command("stack"); }*/ } free(temp); }