int lex_json(const char *input, struct lexer *lexer, struct lexer_result *result) { int res = LEX_OK; static void* dispatch_table[] = { &&state_base, &&state_string, &&state_number, &&state_true, &&state_false, &&state_null }; #define DISPATCH() { \ if (!(lexer->position < lexer->length && lexer->result_num < lexer->result_limit && res == 0)) \ return res; \ goto *dispatch_table[lexer->current_state];\ } DISPATCH(); state_base: res = handle_base(input, lexer, result); DISPATCH(); state_string: res = handle_string(input, lexer, result); DISPATCH(); state_number: res = handle_number(input, lexer, result); DISPATCH(); state_true: res = handle_ident(input, lexer, "true", RES_TRUE, result); DISPATCH(); state_false: res = handle_ident(input, lexer, "false", RES_FALSE, result); DISPATCH(); state_null: res = handle_ident(input, lexer, "null", RES_NULL, result); DISPATCH(); return res; }
/* * Handle a preprocessor line. Extract and return filename if it is a linemarker line. */ static int handle_preprocessor_line(FILE *fp, char **filename) { int c, line; if (fscanf(fp, "%d", &line) == 1) { /* Seems to be a line marker. Try to find a filename. */ while ((c = fgetc(fp)) != EOF && c != '"' && c != '\n'); if (c == '"') { Buffer buffer = { 0 }; handle_string(fp, &buffer, '"'); free(*filename); *filename = bufDetach(&buffer); bufReset(&buffer); } } /* Consume the rest of the line. */ while (c != EOF && c != '\n') c = fgetc(fp); return 0; }
/* * Read a declaration up to a semicolon or an open curly brace and add it to <declaration>. */ static int handle_declaration(FILE *fp, Buffer *declaration) { int c; while ((c = fgetc(fp)) != EOF) { if (c == ';') { bufAddC(declaration, c); break; } else if (c == '{') { Buffer body = { 0 }; handle_compound(fp, &body); bufReset(&body); break; } else if (c == '/') { bufAddC(declaration, c); handle_comment(fp, declaration); } else if (c == '"' || c == '\'') { handle_string(fp, declaration, c); } else { bufAddC(declaration, c); } } return 0; }
int linux_sysctl(struct thread *td, struct linux_sysctl_args *args) { struct l___sysctl_args la; struct sbuf *sb; l_int *mib; int error, i; error = copyin(args->args, &la, sizeof(la)); if (error) return (error); if (la.nlen <= 0 || la.nlen > LINUX_CTL_MAXNAME) return (ENOTDIR); mib = malloc(la.nlen * sizeof(l_int), M_TEMP, M_WAITOK); error = copyin(PTRIN(la.name), mib, la.nlen * sizeof(l_int)); if (error) { free(mib, M_TEMP); return (error); } switch (mib[0]) { case LINUX_CTL_KERN: if (la.nlen < 2) break; switch (mib[1]) { case LINUX_KERN_VERSION: error = handle_string(&la, version); free(mib, M_TEMP); return (error); default: break; } break; default: break; } sb = sbuf_new(NULL, NULL, 20 + la.nlen * 5, SBUF_AUTOEXTEND); if (sb == NULL) { linux_msg(td, "sysctl is not implemented"); } else { sbuf_printf(sb, "sysctl "); for (i = 0; i < la.nlen; i++) sbuf_printf(sb, "%c%d", (i) ? ',' : '{', mib[i]); sbuf_printf(sb, "} is not implemented"); sbuf_finish(sb); linux_msg(td, "%s", sbuf_data(sb)); sbuf_delete(sb); } free(mib, M_TEMP); return (ENOTDIR); }
/* * MPALMOSTSAFE */ int sys_linux_sysctl(struct linux_sysctl_args *args) { struct l___sysctl_args la; l_int *mib; int error, i; error = copyin((caddr_t)args->args, &la, sizeof(la)); if (error) return (error); if (la.nlen <= 0 || la.nlen > LINUX_CTL_MAXNAME) return (ENOTDIR); mib = kmalloc(la.nlen * sizeof(l_int), M_TEMP, M_WAITOK); error = copyin(la.name, mib, la.nlen * sizeof(l_int)); if (error) { kfree(mib, M_TEMP); return (error); } get_mplock(); switch (mib[0]) { case LINUX_CTL_KERN: if (la.nlen < 2) { error = ENOTDIR; break; } switch (mib[1]) { case LINUX_KERN_VERSION: error = handle_string(&la, version); break; default: error = ENOTDIR; break; } break; default: error = ENOTDIR; break; } rel_mplock(); if (error == ENOTDIR && mib) { kprintf("linux: sysctl: unhandled name="); for (i = 0; i < la.nlen; i++) kprintf("%c%d", (i) ? ',' : '{', mib[i]); kprintf("}\n"); } if (mib) kfree(mib, M_TEMP); return (error); }
static void notify_win(PidginWindow *purplewin, PurpleConversation *conv) { if (count_messages(purplewin) <= 0) return; if (purple_prefs_get_bool("/plugins/gtk/X11/notify/method_count")) handle_count_title(purplewin); if (purple_prefs_get_bool("/plugins/gtk/X11/notify/method_count_xprop")) handle_count_xprop(purplewin); if (purple_prefs_get_bool("/plugins/gtk/X11/notify/method_string")) handle_string(purplewin); if (purple_prefs_get_bool("/plugins/gtk/X11/notify/method_urgent")) handle_urgent(purplewin, TRUE); if (purple_prefs_get_bool("/plugins/gtk/X11/notify/method_raise")) handle_raise(purplewin); if (purple_prefs_get_bool("/plugins/gtk/X11/notify/method_present")) handle_present(conv); }
/* * Read a compound statement and add it to <buffer>. */ static int handle_compound(FILE *fp, Buffer *buffer) { int c; while ((c = fgetc(fp)) != EOF) { bufAddC(buffer, c); if (c == '}') break; else if (c == '"' || c == '\'') handle_string(fp, buffer, c); else if (c == '{') handle_compound(fp, buffer); else if (c == '/') { bufAddC(buffer, c); handle_comment(fp, buffer); } } return 0; }
/** * Parse the command line arguments for options. * * This function iterates through the command line arguments looking * for options which have been defined. Each option encountered is * handled according to its type. * * @param argc The number of arguments. * @param argv The array of argument strings. * * @see @link DOXGRP_OPT Command Line Option Parser @endlink * @ingroup DOXGRP_OPT */ void spifopt_parse(int argc, char *argv[]) { spif_int32_t i, j; spif_charptr_t opt; REQUIRE(argc > 1); REQUIRE(argv != NULL); /* Process each command line arg one-by-one. */ for (i = 1, opt = SPIF_CHARPTR(argv[1]); i < argc; ) { spif_charptr_t val_ptr = NULL; spif_char_t islong = 0, hasequal = 0; D_OPTIONS(("argv[%d] == \"%s\", opt == \"%s\"\n", i, argv[i], opt)); if (SPIF_PTR_ISNULL(opt)) { /* NEXT_ARG(); */ break; } else if (opt == SPIF_CHARPTR(argv[i])) { /* If it's not an option, skip it. */ if (*opt != '-') { NEXT_ARG(); } else { opt++; } } /* If the second character is also a hyphen, it's a long option. */ if (*opt == '-') { islong = 1; /* Skip the leading "--" */ opt++; D_OPTIONS(("Long option detected\n")); if ((j = find_long_option(opt)) == -1) { NEXT_ARG(); } } else { if ((j = find_short_option(*opt)) == -1) { NEXT_LETTER(); } } if (!SPIFOPT_FLAGS_IS_SET(SPIFOPT_SETTING_PREPARSE) && SPIFOPT_FLAGS_IS_SET(SPIFOPT_SETTING_REMOVE_ARGS)) { argv[i] = NULL; } /* If a value was passed to this option, set val_ptr to point to it. */ if (islong) { val_ptr = find_value_long(SPIF_CHARPTR(opt), SPIF_CHARPTR(argv[i + 1]), &hasequal); } else { val_ptr = find_value_short(opt, SPIF_CHARPTR(argv[i + 1])); } /* Boolean options may or may not have a value... */ if (val_ptr) { if (SPIFOPT_OPT_IS_BOOLEAN(j) && !is_boolean_value(val_ptr)) { val_ptr = NULL; } else if (SPIFOPT_OPT_IS_ABSTRACT(j) && is_valid_option(val_ptr)) { val_ptr = NULL; } } if (val_ptr) { if (val_ptr == SPIF_CHARPTR(argv[i + 1])) { i++; opt += strlen((char *) opt); } } /* If this option is deprecated, print a warning before continuing. */ if (SPIFOPT_OPT_IS_DEPRECATED(j)) { spif_str_t warn; warn = spif_str_new_from_buff(SPIF_CHARPTR("The "), 128); if (SPIFOPT_OPT_SHORT(j)) { spif_str_append_char(warn, '-'); spif_str_append_char(warn, SPIFOPT_OPT_SHORT(j)); spif_str_append_from_ptr(warn, SPIF_CHARPTR(" / --")); } else { spif_str_append_from_ptr(warn, SPIF_CHARPTR("--")); } spif_str_append_from_ptr(warn, SPIFOPT_OPT_LONG(j)); spif_str_append_from_ptr(warn, SPIF_CHARPTR(" option is deprecated and should not be used.\n")); libast_print_warning((char *) SPIF_STR_STR(warn)); spif_str_del(warn); } /* Make sure that options which require a parameter have them. */ if (SPIFOPT_OPT_NEEDS_VALUE(j)) { if (!val_ptr) { if (islong) { libast_print_error("long option --%s requires a%s value\n", SPIFOPT_OPT_LONG(j), (SPIFOPT_OPT_IS_INTEGER(j) ? ("n integer") : (SPIFOPT_OPT_IS_STRING(j) ? " string" : (SPIFOPT_OPT_IS_ARGLIST(j) ? "n argument list" : "")))); } else { libast_print_error("option -%c requires a%s value\n", SPIFOPT_OPT_SHORT(j), (SPIFOPT_OPT_IS_INTEGER(j) ? ("n integer") : (SPIFOPT_OPT_IS_STRING(j) ? " string" : (SPIFOPT_OPT_IS_ARGLIST(j) ? "n argument list" : "")))); } CHECK_BAD(); continue; } /* Also make sure we know what to do with the value. */ if (!SPIFOPT_OPT_VALUE(j)) { NEXT_LOOP(); } } else if (SPIFOPT_OPT_IS_ABSTRACT(j) && !SPIFOPT_OPT_VALUE(j)) { /* Also make sure that abstract options have a function pointer. */ NEXT_LOOP(); } if (SPIFOPT_OPT_IS_BOOLEAN(j)) { if (!handle_boolean(j, val_ptr, islong)) { i--; } } else if (SPIFOPT_OPT_IS_STRING(j)) { if (SHOULD_PARSE(j)) { handle_string(j, val_ptr); } } else if (SPIFOPT_OPT_IS_INTEGER(j)) { if (SHOULD_PARSE(j)) { handle_integer(j, val_ptr); } } else if (SPIFOPT_OPT_IS_ARGLIST(j)) { if (SHOULD_PARSE(j)) { handle_arglist(j, val_ptr, hasequal, i, argc, argv); } if (!hasequal) { break; } } else if (SPIFOPT_OPT_IS_ABSTRACT(j)) { if (SHOULD_PARSE(j)) { D_OPTIONS(("Abstract option detected\n")); ((spifopt_abstract_handler_t) SPIFOPT_OPT_VALUE(j))(val_ptr); } } if (!SPIFOPT_FLAGS_IS_SET(SPIFOPT_SETTING_PREPARSE) && SPIFOPT_FLAGS_IS_SET(SPIFOPT_SETTING_REMOVE_ARGS)) { argv[i] = NULL; } NEXT_LOOP(); } if (SPIFOPT_FLAGS_IS_SET(SPIFOPT_SETTING_PREPARSE)) { SPIFOPT_FLAGS_CLEAR(SPIFOPT_SETTING_PREPARSE); } else if (SPIFOPT_FLAGS_IS_SET(SPIFOPT_SETTING_REMOVE_ARGS)) { for (i = 1, j = 1; i < argc; i++) { if (argv[i]) { argv[j] = argv[i]; j++; } } if (j > 1) { argv[j] = NULL; } } }
void config_load (const char *cfg_name) { FILE *cfg = fopen (cfg_name, "rt"); char buffer [4096], var [4096], *val; cfg_var *cv; if (!cfg) { perror (cfg_name); return; } while (fgets (buffer, 4096, cfg)) { // Kill comments char *split = strrchr (buffer, '#'); char *cp1 = var, *cp2 = buffer; if (split) *split = '\0'; // remove trailing newline split = strrchr (buffer, '\n'); if (split) *split = '\0'; // Skip leading white space ... cp2 = skip_ws (cp2); // Silently ignore empty lines. if (!*cp2) continue; // search for '=' val = strchr (cp2, '='); if (!val) { fprintf (stderr, "%s: ignoring bad config line starting \"%s\" (missing '='!)\n", cfg_name, buffer); continue; } *val++ = '\0'; // front part basically must be a variable name. // To keep it simple we ignore *all* white space here - even if inside the variable name. while (*cp2) { if (!isspace (*cp2)) *cp1++ = toupper (*cp2); *cp2++; } *cp1 = '\0'; // remove leading and trailing white space off val val = skip_ws (val); if (!*val) { fprintf (stderr, "%s: ignoring bad config line starting \"%s\" (missing value!)\n", cfg_name, buffer); continue; } cp2 = strchr (val, '\0') - 1; while (cp2 > val && isspace (*cp2)) cp2--; cp2 [1] = '\0'; // search the variable for (cv = config; cv->name; cv++) if (strcmp (cv->name, var) == 0) break; if (!cv->name) fprintf (stderr, "%s: ignoring bad config line starting \"%s\" (variable '%s' unknown!)\n", cfg_name, buffer, var); else switch (cv->type) { case NUM: handle_num (var, cv->v_ptr, val); break; case BOOL: handle_bool (var, cv->v_ptr, val); break; case STRING: handle_string (var, cv->v_ptr, val); break; case N_ARRAY: handle_array (var, cv->v_ptr, cv->n_ptr, val); break; } } fclose (cfg); }
void handle(node *n) { if (n->type == type_id) { vlog("[code_gen] handle: identifier\n"); handle_identifier(n); } else if (n->type == type_con) { vlog("[code_gen] handle: constant\n"); handle_constant(n); } else if (n->type == type_string) { vlog("[code_gen] handle: string constant\n"); handle_string(n); } else { if (strcmp(n->id,"postfix_expr") == 0) { vlog("[code_gen] handle: postfix_expr \n"); handle_postfix_expr(n); } else if (strcmp(n->id,"argument_expr_list") == 0) { vlog("[code_gen] handle: argument_expr_list \n"); handle_argument_expr_list(n); } else if (strcmp(n->id,"unary_expr") == 0) { vlog("[code_gen] handle: unary_expr \n"); handle_unary_expr(n); } else if (strcmp(n->id,"sizeof") == 0) { vlog("[code_gen] handle: sizeof \n"); handle_sizeof(n); } else if (strcmp(n->id,"cast_expr") == 0) { vlog("[code_gen] handle: cast_expr \n"); handle_cast_expr(n); } else if (strcmp(n->id,"multiply") == 0) { vlog("[code_gen] handle: multiply \n"); handle_multiply(n); } else if (strcmp(n->id,"divide") == 0) { vlog("[code_gen] handle: divide \n"); handle_divide(n); } else if (strcmp(n->id,"mod") == 0) { vlog("[code_gen] handle: mod \n"); handle_mod(n); } else if (strcmp(n->id,"add") == 0) { vlog("[code_gen] handle: add \n"); handle_add(n); } else if (strcmp(n->id,"sub") == 0) { vlog("[code_gen] handle: sub \n"); handle_sub(n); } else if (strcmp(n->id,"shift_left") == 0) { vlog("[code_gen] handle: shift_left \n"); handle_shift_left(n); } else if (strcmp(n->id,"shift_right") == 0) { vlog("[code_gen] handle: shift_right \n"); handle_shift_right(n); } else if (strcmp(n->id,"less_than") == 0) { vlog("[code_gen] handle: less_than \n"); handle_less_than(n); } else if (strcmp(n->id,"greater_than") == 0) { vlog("[code_gen] handle: greater_than \n"); handle_greater_than(n); } else if (strcmp(n->id,"less_equal_than") == 0) { vlog("[code_gen] handle: less_equal_than \n"); handle_less_equal_than(n); } else if (strcmp(n->id,"greater_equal_than") == 0) { vlog("[code_gen] handle: greater_equal_than \n"); handle_greater_equal_than(n); } else if (strcmp(n->id,"equality") == 0) { vlog("[code_gen] handle: equality \n"); handle_equality(n); } else if (strcmp(n->id,"equality_not") == 0) { vlog("[code_gen] handle: equality_not \n"); handle_equality_not(n); } else if (strcmp(n->id,"bitwise_and") == 0) { vlog("[code_gen] handle: bitwise_and \n"); handle_bitwise_and(n); } else if (strcmp(n->id,"bitwise_xor") == 0) { vlog("[code_gen] handle: bitwise_xor \n"); handle_bitwise_xor(n); } else if (strcmp(n->id,"bitwise_or") == 0) { vlog("[code_gen] handle: bitwise_or \n"); handle_bitwise_or(n); } else if (strcmp(n->id,"logical_and") == 0) { vlog("[code_gen] handle: logical_and \n"); handle_logical_and(n); } else if (strcmp(n->id,"logical_or") == 0) { vlog("[code_gen] handle: logical_or \n"); handle_logical_or(n); } else if (strcmp(n->id,"conditional") == 0) { vlog("[code_gen] handle: conditional \n"); handle_conditional(n); } else if (strcmp(n->id,"assignment") == 0) { vlog("[code_gen] handle: assignment \n"); handle_assignment(n); } else if (strcmp(n->id,"expression") == 0) { vlog("[code_gen] handle: expression \n"); handle_expression(n); } else if (strcmp(n->id,"declaration") == 0) { vlog("[code_gen] handle: declaration \n"); handle_declaration(n); } else if (strcmp(n->id,"declaration_specifier") == 0) { vlog("[code_gen] handle: declaration_specifier \n"); handle_declaration_specifier(n); } else if (strcmp(n->id,"init_declarator_list") == 0) { vlog("[code_gen] handle: init_declarator_list \n"); handle_init_declarator_list(n); } else if (strcmp(n->id,"init_declarator") == 0) { vlog("[code_gen] handle: init_declarator \n"); handle_init_declarator(n); } else if (strcmp(n->id,"struct_union") == 0) { vlog("[code_gen] handle: struct_union \n"); handle_struct_union(n); } else if (strcmp(n->id,"struct_declaration_list") == 0) { vlog("[code_gen] handle: struct_declaration_list \n"); handle_struct_declaration_list(n); } else if (strcmp(n->id,"struct_declaration") == 0) { vlog("[code_gen] handle: struct_declaration \n"); handle_struct_declaration(n); } else if (strcmp(n->id,"specifier_qualifier_list") == 0) { vlog("[code_gen] handle: specifier_qualifier_list \n"); handle_specifier_qualifier_list(n); } else if (strcmp(n->id,"struct_declarator_list") == 0) { vlog("[code_gen] handle: struct_declarator_list \n"); handle_struct_declarator_list(n); } else if (strcmp(n->id,"struct_declarator") == 0) { vlog("[code_gen] handle: struct_declarator \n"); handle_struct_declarator(n); } else if (strcmp(n->id,"enum_specifier") == 0) { vlog("[code_gen] handle: enum_specifier \n"); handle_enum_specifier(n); } else if (strcmp(n->id,"enum_list") == 0) { vlog("[code_gen] handle: enum_list \n"); handle_enum_list(n); } else if (strcmp(n->id,"enumerator") == 0) { vlog("[code_gen] handle: enumerator \n"); handle_enumerator(n); } else if (strcmp(n->id,"declarator") == 0) { vlog("[code_gen] handle: declarator \n"); handle_declarator(n); } else if (strcmp(n->id,"direct_declarator") == 0) { vlog("[code_gen] handle: direct_declarator \n"); handle_direct_declarator(n); } else if (strcmp(n->id,"pointer") == 0) { vlog("[code_gen] handle: pointer \n"); handle_pointer(n); } else if (strcmp(n->id,"type_qualifier_list") == 0) { vlog("[code_gen] handle: type_qualifier_list \n"); handle_type_qualifier_list(n); } else if (strcmp(n->id,"parameter_type_list") == 0) { vlog("[code_gen] handle: parameter_type_list \n"); handle_parameter_type_list(n); } else if (strcmp(n->id,"parameter_list") == 0) { vlog("[code_gen] handle: parameter_list \n"); handle_parameter_list(n); } else if (strcmp(n->id,"parameter_declaration") == 0) { vlog("[code_gen] handle: parameter_declaration \n"); handle_parameter_declaration(n); } else if (strcmp(n->id,"identifier_list") == 0) { vlog("[code_gen] handle: identifier_list \n"); handle_identifier_list(n); } else if (strcmp(n->id,"type_name") == 0) { vlog("[code_gen] handle: type_name \n"); handle_type_name(n); } else if (strcmp(n->id,"abstract_declarator") == 0) { vlog("[code_gen] handle: abstract_declarator \n"); handle_abstract_declarator(n); } else if (strcmp(n->id,"direct_abstract_declarator") == 0) { vlog("[code_gen] handle: direct_abstract_declarator \n"); handle_direct_abstract_declarator(n); } else if (strcmp(n->id,"initializer") == 0) { vlog("[code_gen] handle: initializer \n"); handle_initializer(n); } else if (strcmp(n->id,"initializer_list") == 0) { vlog("[code_gen] handle: initializer_list \n"); handle_initializer_list(n); } else if (strcmp(n->id,"labeled_statement") == 0) { vlog("[code_gen] handle: labeled_statement \n"); handle_labeled_statement(n); } else if (strcmp(n->id,"compound_statement") == 0) { vlog("[code_gen] handle: compound_statement \n"); handle_compound_statement(n); } else if (strcmp(n->id,"declaration_list") == 0) { vlog("[code_gen] handle: declaration_list \n"); handle_declaration_list(n); } else if (strcmp(n->id,"statement_list") == 0) { vlog("[code_gen] handle: statement_list \n"); handle_statement_list(n); } else if (strcmp(n->id,"expression_statement") == 0) { vlog("[code_gen] handle: expression_statement \n"); handle_expression_statement(n); } else if (strcmp(n->id,"selection_statement") == 0) { vlog("[code_gen] handle: selection_statement \n"); handle_selection_statement(n); } else if (strcmp(n->id,"iteration_statement") == 0) { vlog("[code_gen] handle: iteration_statement \n"); handle_iteration_statement(n); } else if (strcmp(n->id,"jump_statement") == 0) { vlog("[code_gen] handle: jump_statement \n"); handle_jump_statement(n); } else if (strcmp(n->id,"translation_unit") == 0) { vlog("[code_gen] handle: translation_unit \n"); handle_translation_unit(n); } else if (strcmp(n->id,"function_definition") == 0) { vlog("[code_gen] handle: function_definition \n"); handle_function_definition(n); } else if (strcmp(n->id,"asm") == 0) { vlog("[code_gen] handle: inline_assembly \n"); handle_asm(n); } } }