/** * Gets values associated to a given option for the GenPrepare function. * * @param varName NULL-terminated string containing the option name * @param varValue NULL-terminated string containing the option value * @param PB a pointer to a structure containing benchmark parameters for this session */ static void GetValuesGP (const char *varName, const char *varValue, UflipParams *PB) { const char *fmt_str [3] = { "None", "Seq", "Rnd" }; const int fmt_enum [3] = { NONE, SEQ, RND }; if (get_common_values (varName, varValue, PB)) return; /* still some specific options to parse */ if (get_common_gen_values (varName, varValue, PB)) return; /* still not fatal */ if (strcasecmp (varName, "OutName") == 0) { strcpy (PB->outName, varValue); } else if (parse_number ("IOC", varName, varValue, "%d", &PB->IOCount)); else if (parse_number ("IOC2", varName, varValue, "%d", &PB->IOCount2)); else if (parse_number ("Pause", varName, varValue, "%d", &PB->pauseExp)) { PB->pauseExp *= 1000; } else if (parse_enum ("FormatType", varName, varValue, fmt_str, fmt_enum, 3, &PB->fmtType, sizeof (PB->fmtType))); else { /* ok, now this is fatal */ PrintHelp (varName); } }
/* XXX EXTRA_PARAM and PARAM_NUM are a kludge to get in * backward-compatible support for "format" parameter type. The * latter is only valid if the former is non-NULL, which is only in * top-level context. */ static int parse_alias(struct protolib *plib, struct locus *loc, char **str, struct arg_type_info **retp, int *ownp, struct param **extra_param, size_t param_num) { /* For backward compatibility, we need to support things like * stringN (which is like string[argN], string[N], and also * bare string. We might, in theory, replace this by * preprocessing configure file sources with M4, but for now, * "string" is syntax. */ if (strncmp(*str, "string", 6) == 0) { (*str) += 6; return parse_string(plib, loc, str, retp, ownp); } else if (try_parse_kwd(str, "format") >= 0 && extra_param != NULL) { /* For backward compatibility, format is parsed as * "string", but it smuggles to the parameter list of * a function a "printf" argument pack with this * parameter as argument. */ if (parse_string(plib, loc, str, retp, ownp) < 0) return -1; return build_printf_pack(loc, extra_param, param_num); } else if (try_parse_kwd(str, "enum") >=0) { return parse_enum(plib, loc, str, retp, ownp); } else { *retp = NULL; return 0; } }
bool fw3_parse_limit(void *ptr, const char *val, bool is_list) { struct fw3_limit *limit = ptr; enum fw3_limit_unit u = FW3_LIMIT_UNIT_SECOND; char *e; int n; if (*val == '!') { limit->invert = true; while (isspace(*++val)); } n = strtol(val, &e, 10); if (errno == ERANGE || errno == EINVAL) return false; if (*e && *e++ != '/') return false; if (!strlen(e)) return false; if (!parse_enum(&u, e, limit_units, 0, FW3_LIMIT_UNIT_DAY)) return false; limit->rate = n; limit->unit = u; return true; }
/* * Parse the value based on the field table * * @param context The main context pointer * @param rest String to parse * @param field Field item to parse * @param value Returns the value that was parsed * @return the remainder of the string after the value was parsed */ static char *parse_field_value(build_image_context *context, char *rest, field_item *field, u_int32_t *value) { assert(rest != NULL); assert(field != NULL); assert((field->type != field_type_enum) || (field->enum_table != NULL)); switch (field->type) { case field_type_enum: rest = parse_enum(context, rest, field->enum_table, value); break; case field_type_u32: rest = parse_u32(rest, value); break; case field_type_u8: rest = parse_u8(rest, value); break; default: printf("Unexpected field type %d at line %d\n", field->type, __LINE__); rest = NULL; break; } return rest; }
file_contents parse(parse_source source) { file_contents contents; contents.imports = ll_new(); contents.enums = ll_new(); contents.unions = ll_new(); contents.structs = ll_new(); contents.functions = ll_new(); optional op = get_token(&source); while(op_has(op)) { parse_token current = *((parse_token*)op_get(op)); if(equals(current.data, new_slice("struct"))) { struct_declaration *dec = analyze_struct(&source); ll_add_last(contents.structs, dec); } else if(equals(current.data, new_slice("union"))) { struct_declaration *dec = analyze_struct(&source); ll_add_last(contents.unions, dec); } else if(equals(current.data, new_slice("func"))) { func_declaration *func = analyze_func(&source); ll_add_last(contents.functions, func); } else if(equals(current.data, new_slice("import"))) { import_declaration *imp = parse_import(&source); ll_add_last(contents.imports, imp); } else if(equals(current.data, new_slice("enum"))) { enum_declaration *enm = parse_enum(&source); ll_add_last(contents.enums, enm); }//TODO: Throw an error for an unexpected token op = get_token(&source); } return contents; }
/** * Parses the following options/values: Dev, Size, Fake. They are common to all functions. * * @param varName option name * @param varValue option value * @param PB pointer to a struct where to store the parsed options * @return false if given @a varName isn't a known option or if given @a varValue * isn't a valid value for the option, otherwise true. */ static bool get_common_values (const char *varName, const char *varValue, UflipParams *PB) { const char *fake_str [2] = { "True", "False" }; const bool fake_enum [2] = { true, false }; if (strcasecmp (varName, "Dev") == 0) { PB->device = uflip_device_new (varValue); } else if (parse_number ("Size", varName, varValue, "%d", &PB->deviceSize)) { PB->deviceSize /= BLOCK; PB->deviceSize *= BLOCK; } else if (parse_enum ("Fake", varName, varValue, fake_str, fake_enum, 2, &PB->fake, sizeof (PB->fake))); else { return false; /* warning, unknown option! */ } return true; /* option found and parsed. */ }
/** Parse module. * * Parse a program module. * * The input is read using the lexer associated with @a parse. The resulting * declarations are added to existing declarations in the program associated * with @a parse. * * If any parse error occurs, parse->error will @c b_true when this function * returns. parse->error_bailout will be @c b_true if the error has not * been recovered yet. Similar holds for other parsing functions in this * module. * * @param parse Parser object. */ void parse_module(parse_t *parse) { stree_csi_t *csi; stree_enum_t *enum_d; stree_modm_t *modm; while (lcur_lc(parse) != lc_eof && !parse_is_error(parse)) { switch (lcur_lc(parse)) { case lc_class: case lc_struct: case lc_interface: csi = parse_csi(parse, lcur_lc(parse), NULL); modm = stree_modm_new(mc_csi); modm->u.csi = csi; list_append(&parse->cur_mod->members, modm); break; case lc_enum: enum_d = parse_enum(parse, NULL); modm = stree_modm_new(mc_enum); modm->u.enum_d = enum_d; list_append(&parse->cur_mod->members, modm); break; default: lunexpected_error(parse); lex_next(parse->lex); break; } } }
static int32_t parse_type(struct snmp_toolinfo *snmptoolctx, enum tok *tok, enum snmp_tc *tc, struct enum_pairs **snmp_enum) { int32_t syntax, mem; syntax = val; *tc = 0; if (*tok == TOK_ENUM || *tok == TOK_BITS) { if (*snmp_enum == NULL) { if ((*snmp_enum = enum_pairs_init()) == NULL) return (-1); mem = 1; *tc = SNMP_TC_OWN; } else mem = 0; if (gettoken(snmptoolctx) != '(') { warnx("'(' expected after ENUM/BITS"); return (-1); } if ((*tok = gettoken(snmptoolctx)) != TOK_NUM) { warnx("need value for ENUM//BITS"); if (mem == 1) { free(*snmp_enum); *snmp_enum = NULL; } return (-1); } if (parse_enum(snmptoolctx, tok, *snmp_enum) < 0) { enum_pairs_free(*snmp_enum); *snmp_enum = NULL; return (-1); } *tok = gettoken(snmptoolctx); } else if (*tok == TOK_DEFTYPE) { struct enum_type *t; *tc = 0; t = snmp_enumtc_lookup(snmptoolctx, nexttok); if (t != NULL) *snmp_enum = t->snmp_enum; *tok = gettoken(snmptoolctx); } else { if ((*tok = gettoken(snmptoolctx)) == '|') { if (parse_subtype(snmptoolctx, tok, tc) < 0) return (-1); } } return (syntax); }
void parse_decl(context& ctx) throw (coord) { parse_enum(ctx); if (ctx.tag == IDENT) parse_vars(ctx); if (ctx.tag != SEMICOLON) throw ctx.start; next_token(ctx); }
__owur static int parse_session_id(SSL_TEST_CTX *test_ctx, const char *value) { int ret_value; if (!parse_enum(ssl_session_id, OSSL_NELEM(ssl_session_id), &ret_value, value)) { return 0; } test_ctx->session_id_expected = ret_value; return 1; }
__owur static int parse_key_update_type(SSL_TEST_CTX *test_ctx, const char *value) { int ret_value; if (!parse_enum(ssl_key_update_types, OSSL_NELEM(ssl_key_update_types), &ret_value, value)) { return 0; } test_ctx->key_update_type = ret_value; return 1; }
__owur static int parse_handshake_mode(SSL_TEST_CTX *test_ctx, const char *value) { int ret_value; if (!parse_enum(ssl_handshake_modes, OSSL_NELEM(ssl_handshake_modes), &ret_value, value)) { return 0; } test_ctx->handshake_mode = ret_value; return 1; }
__owur static int parse_test_method(SSL_TEST_CTX *test_ctx, const char *value) { int ret_value; if (!parse_enum(ssl_test_methods, OSSL_NELEM(ssl_test_methods), &ret_value, value)) { return 0; } test_ctx->method = ret_value; return 1; }
__owur static int parse_expected_result(SSL_TEST_CTX *test_ctx, const char *value) { int ret_value; if (!parse_enum(ssl_test_results, OSSL_NELEM(ssl_test_results), &ret_value, value)) { return 0; } test_ctx->expected_result = ret_value; return 1; }
__owur static int parse_servername_callback(SSL_TEST_SERVER_CONF *server_conf, const char *value) { int ret_value; if (!parse_enum(ssl_servername_callbacks, OSSL_NELEM(ssl_servername_callbacks), &ret_value, value)) { return 0; } server_conf->servername_callback = ret_value; return 1; }
__owur static int parse_expected_servername(SSL_TEST_CTX *test_ctx, const char *value) { int ret_value; if (!parse_enum(ssl_servername, OSSL_NELEM(ssl_servername), &ret_value, value)) { return 0; } test_ctx->expected_servername = ret_value; return 1; }
__owur static int parse_servername(SSL_TEST_CLIENT_CONF *client_conf, const char *value) { int ret_value; if (!parse_enum(ssl_servername, OSSL_NELEM(ssl_servername), &ret_value, value)) { return 0; } client_conf->servername = ret_value; return 1; }
__owur static int parse_client_verify_callback(SSL_TEST_CLIENT_CONF *client_conf, const char *value) { int ret_value; if (!parse_enum(ssl_verify_callbacks, OSSL_NELEM(ssl_verify_callbacks), &ret_value, value)) { return 0; } client_conf->verify_callback = ret_value; return 1; }
__owur static int parse_certstatus(SSL_TEST_SERVER_CONF *server_conf, const char *value) { int ret_value; if (!parse_enum(ssl_certstatus, OSSL_NELEM(ssl_certstatus), &ret_value, value)) { return 0; } server_conf->cert_status = ret_value; return 1; }
__owur static int parse_ct_validation(SSL_TEST_CLIENT_CONF *client_conf, const char *value) { int ret_value; if (!parse_enum(ssl_ct_validation_modes, OSSL_NELEM(ssl_ct_validation_modes), &ret_value, value)) { return 0; } client_conf->ct_validation = ret_value; return 1; }
__owur static int parse_servername_callback(SSL_TEST_CTX *test_ctx, const char *value) { int ret_value; if (!parse_enum(ssl_servername_callbacks, OSSL_NELEM(ssl_servername_callbacks), &ret_value, value)) { return 0; } test_ctx->servername_callback = ret_value; return 1; }
__owur static int parse_max_fragment_len_mode(SSL_TEST_CLIENT_CONF *client_conf, const char *value) { int ret_value; if (!parse_enum(ssl_max_fragment_len_mode, OSSL_NELEM(ssl_max_fragment_len_mode), &ret_value, value)) { return 0; } client_conf->max_fragment_len_mode = ret_value; return 1; }
/* * Parse the given string and find the array items in config file. * * @param context The main context pointer * @param token The parse token value * @param rest String to parse * @return 0 and 1 for success and failure */ static int parse_array(build_image_context *context, parse_token token, char *rest) { u_int32_t index; u_int32_t value; assert(context != NULL); assert(rest != NULL); /* Parse the index. */ rest = parse_u32(rest, &index); if (rest == NULL) return 1; /* Parse the closing bracket. */ if (*rest != ']') return 1; rest++; /* Parse the equals sign.*/ if (*rest != '=') return 1; rest++; /* Parse the value based on the field table. */ switch (token) { case token_attribute: rest = parse_u32(rest, &value); break; case token_dev_type: rest = parse_enum(context, rest, s_devtype_table_t20, &value); break; default: /* Unknown token */ return 1; } if (rest == NULL) return 1; /* Store the result. */ return set_array(context, index, token, value); }
/** * Gets values associated to a given option for the GenBench function. * * @param varName NULL-terminated string containing the option name * @param varValue NULL-terminated string containing the option value * @param PB a pointer to a structure containing benchmark parameters for this session */ static void GetValuesGB (const char *varName, const char *varValue, UflipParams *PB) { const char *buf_str [4] = { "N", "H", "S", "A" }; const int buf_enum [4] = { NO_BUFFERING, HW_BUFFERING, FS_BUFFERING, HW_BUFFERING | FS_BUFFERING }; if (get_common_values (varName, varValue, PB)) return; /* still some specific options to parse */ if (get_common_gen_values (varName, varValue, PB)) return; /* still not fatal */ if (strcasecmp (varName, "ExpPlan") == 0) { strcpy (PB->expPlan, varValue); } else if (strcasecmp (varName, "ExpSel") == 0) { strcpy (PB->expSelect, varValue); } else if (strcasecmp (varName, "OutName") == 0) { strcpy (PB->outName, varValue); } else if (parse_number ("IOCSR", varName, varValue, "%d", &PB->IOCountSR)); else if (parse_number ("IOCRR", varName, varValue, "%d", &PB->IOCountRR)); else if (parse_number ("IOCSW", varName, varValue, "%d", &PB->IOCountSW)); else if (parse_number ("IOCRW", varName, varValue, "%d", &PB->IOCountRW)); else if (parse_number ("IgnIOSR", varName, varValue, "%d", &PB->ignoreIOSR)); else if (parse_number ("IgnIORR", varName, varValue, "%d", &PB->ignoreIORR)); else if (parse_number ("IgnIOSW", varName, varValue, "%d", &PB->ignoreIOSW)); else if (parse_number ("IgnIORW", varName, varValue, "%d", &PB->ignoreIORW)); else if (parse_number ("Pause", varName, varValue, "%d", &PB->pauseExp)); else if (parse_enum ("BufferType", varName, varValue, buf_str, buf_enum, 4, &PB->bufferType, sizeof (PB->bufferType))); else { /* ok, now this is fatal */ PrintHelp (varName); } }
MMAL_STATUS_T mmal_parse_video_codec(uint32_t *dest, const char *str) { static string_pair_t video_codec_enums[] = { { "h264", MMAL_ENCODING_H264 }, { "h263", MMAL_ENCODING_H263 }, { "mpeg4", MMAL_ENCODING_MP4V }, { "mpeg2", MMAL_ENCODING_MP2V }, { "vp8", MMAL_ENCODING_VP8 }, { "vp7", MMAL_ENCODING_VP7 }, { "vp6", MMAL_ENCODING_VP6 }, }; int i = 0; MMAL_STATUS_T ret; ret = parse_enum(&i, video_codec_enums, vcos_countof(video_codec_enums), str); *dest = i; return ret; }
void Parser::parse_body(ptr<Token> token) { switch (token->type()) { case TOKEN_DEFINE: do { object<DefineTree> tree; tree->parse(this); if (tree != _symbols.probe(tree->name()->text(), tree, _input.is_root())) { log_error(tree->name()->loc(), "dup enum name '%s'", tree->name()->text()); } return; } while (0); case TOKEN_ENUM: parse_enum(); return; case TOKEN_EXTERN: parse_extern(); return; case TOKEN_STRUCT: do { object<StructTree> tree; tree->parse(this); if (tree != _symbols.probe(tree->name()->text(), tree, _input.is_root())) { log_error(tree->name()->loc(), "dup struct name '%s'", tree->name()->text()); } return; } while (0); case TOKEN_MESSAGE: do { object<MessageTree> tree; tree->parse(this); if (tree != _symbols.probe(tree->name()->text(), tree, _input.is_root())) { log_error(tree->name()->loc(), "dup message name '%s'", tree->name()->text()); } return; } while (0); break; default: log_expect(token->loc(), "%define or enum or or struct or message"); } }
Value *Parser::parse_value(void) { int c; Value *value; c = read_byte(); switch (c) { case trace::TYPE_NULL: value = new Null; break; case trace::TYPE_FALSE: value = new Bool(false); break; case trace::TYPE_TRUE: value = new Bool(true); break; case trace::TYPE_SINT: value = parse_sint(); break; case trace::TYPE_UINT: value = parse_uint(); break; case trace::TYPE_FLOAT: value = parse_float(); break; case trace::TYPE_DOUBLE: value = parse_double(); break; case trace::TYPE_STRING: value = parse_string(); break; case trace::TYPE_ENUM: value = parse_enum(); break; case trace::TYPE_BITMASK: value = parse_bitmask(); break; case trace::TYPE_ARRAY: value = parse_array(); break; case trace::TYPE_STRUCT: value = parse_struct(); break; case trace::TYPE_BLOB: value = parse_blob(); break; case trace::TYPE_OPAQUE: value = parse_opaque(); break; default: std::cerr << "error: unknown type " << c << "\n"; exit(1); case -1: value = NULL; break; } #if TRACE_VERBOSE if (value) { std::cerr << "\tVALUE " << value << "\n"; } #endif return value; }
__owur static int parse_alert(int *alert, const char *value) { return parse_enum(ssl_alerts, OSSL_NELEM(ssl_alerts), alert, value); }
/* Wants: name = value */ static enum status_code option_set_command(int argc, const char *argv[]) { if (argc < 3) return ERROR_WRONG_NUMBER_OF_ARGUMENTS; if (strcmp(argv[1], "=")) return ERROR_NO_VALUE_ASSIGNED; if (!strcmp(argv[0], "blame-options")) return parse_args(&opt_blame_options, argv + 2); if (!strcmp(argv[0], "diff-options")) return parse_args(&opt_diff_options, argv + 2); if (argc != 3) return ERROR_WRONG_NUMBER_OF_ARGUMENTS; if (!strcmp(argv[0], "show-author")) return parse_enum(&opt_show_author, argv[2], author_map); if (!strcmp(argv[0], "show-date")) return parse_enum(&opt_show_date, argv[2], date_map); if (!strcmp(argv[0], "show-rev-graph")) return parse_bool(&opt_show_rev_graph, argv[2]); if (!strcmp(argv[0], "show-refs")) return parse_bool(&opt_show_refs, argv[2]); if (!strcmp(argv[0], "show-changes")) return parse_bool(&opt_show_changes, argv[2]); if (!strcmp(argv[0], "show-notes")) { bool matched = FALSE; enum status_code res = parse_bool_matched(&opt_show_notes, argv[2], &matched); if (res == SUCCESS && matched) { update_notes_arg(); return res; } opt_show_notes = TRUE; strcpy(opt_notes_arg, "--show-notes="); res = parse_string(opt_notes_arg + 8, argv[2], sizeof(opt_notes_arg) - 8); if (res == SUCCESS && opt_notes_arg[8] == '\0') opt_notes_arg[7] = '\0'; return res; } if (!strcmp(argv[0], "show-line-numbers")) return parse_bool(&opt_show_line_numbers, argv[2]); if (!strcmp(argv[0], "line-graphics")) return parse_enum(&opt_line_graphics, argv[2], graphic_map); if (!strcmp(argv[0], "line-number-interval")) return parse_int(&opt_line_number_interval, argv[2], 1, 1024); if (!strcmp(argv[0], "author-width")) return parse_int(&opt_author_width, argv[2], 0, 1024); if (!strcmp(argv[0], "filename-width")) return parse_int(&opt_show_filename_width, argv[2], 0, 1024); if (!strcmp(argv[0], "show-filename")) return parse_enum(&opt_show_filename, argv[2], filename_map); if (!strcmp(argv[0], "show-file-size")) return parse_enum(&opt_show_file_size, argv[2], file_size_map); if (!strcmp(argv[0], "horizontal-scroll")) return parse_step(&opt_horizontal_scroll, argv[2]); if (!strcmp(argv[0], "split-view-height")) return parse_step(&opt_split_view_height, argv[2]); if (!strcmp(argv[0], "vertical-split")) return parse_enum(&opt_vertical_split, argv[2], vertical_split_map); if (!strcmp(argv[0], "tab-size")) return parse_int(&opt_tab_size, argv[2], 1, 1024); if (!strcmp(argv[0], "diff-context") && !*opt_diff_context_arg) { enum status_code code = parse_int(&opt_diff_context, argv[2], 0, 999999); if (code == SUCCESS) update_diff_context_arg(opt_diff_context); return code; } if (!strcmp(argv[0], "ignore-space") && !*opt_ignore_space_arg) { enum status_code code = parse_enum(&opt_ignore_space, argv[2], ignore_space_map); if (code == SUCCESS) update_ignore_space_arg(); return code; } if (!strcmp(argv[0], "commit-order") && !*opt_commit_order_arg) { enum status_code code = parse_enum(&opt_commit_order, argv[2], commit_order_map); if (code == SUCCESS) update_commit_order_arg(); return code; } if (!strcmp(argv[0], "status-untracked-dirs")) return parse_bool(&opt_status_untracked_dirs, argv[2]); if (!strcmp(argv[0], "read-git-colors")) return parse_bool(&opt_read_git_colors, argv[2]); if (!strcmp(argv[0], "ignore-case")) return parse_bool(&opt_ignore_case, argv[2]); if (!strcmp(argv[0], "focus-child")) return parse_bool(&opt_focus_child, argv[2]); if (!strcmp(argv[0], "wrap-lines")) return parse_bool(&opt_wrap_lines, argv[2]); if (!strcmp(argv[0], "show-id")) return parse_bool(&opt_show_id, argv[2]); if (!strcmp(argv[0], "id-width")) return parse_id(&opt_id_width, argv[2]); if (!strcmp(argv[0], "title-overflow")) { bool enabled = FALSE; bool matched; enum status_code code; /* * "title-overflow" is considered a boolint. * We try to parse it as a boolean (and set the value to 50 if true), * otherwise we parse it as an integer and use the given value. */ code = parse_bool_matched(&enabled, argv[2], &matched); if (code == SUCCESS && matched) { if (enabled) opt_title_overflow = 50; } else { code = parse_int(&opt_title_overflow, argv[2], 2, 1024); if (code != SUCCESS) opt_title_overflow = 50; } return code; } if (!strcmp(argv[0], "editor-line-number")) return parse_bool(&opt_editor_line_number, argv[2]); if (!strcmp(argv[0], "mouse")) return parse_bool(&opt_mouse, argv[2]); if (!strcmp(argv[0], "mouse-scroll")) return parse_int(&opt_mouse_scroll, argv[2], 0, 1024); return ERROR_UNKNOWN_VARIABLE_NAME; }
__owur static int parse_protocol(SSL_TEST_CTX *test_ctx, const char *value) { return parse_enum(ssl_protocols, OSSL_NELEM(ssl_protocols), &test_ctx->expected_protocol, value); }