Exemple #1
0
struct generic_section_config *
parse_param(char const *path,
            FILE *f,
            const struct config_section_info *params,
            int quiet_flag,
            int _ncond_var,
            cfg_cond_var_t *_cond_vars,
            int *p_cond_count)
{
  struct generic_section_config  *cfg = NULL;
  struct generic_section_config **psect = &cfg, *sect = NULL;
  const struct config_section_info *cur_info = NULL;

  char           sectname[32];
  char           varname[32];
  char           varvalue[1024];
  int            c, sindex;

  parsecfg_state.ncond_var = _ncond_var;
  parsecfg_state.cond_vars = _cond_vars;
  parsecfg_state.cond_stack = 0;
  parsecfg_state.output_enabled = 1;
  parsecfg_state.lineno = 1;
  if (p_cond_count) *p_cond_count = 0;

  /* found the global section description */
  for (sindex = 0; params[sindex].name; sindex++) {
    if (!strcmp(params[sindex].name, "global")) {
      cur_info = &params[sindex];
      break;
    }
  }
  /*
  if (!cur_info) {
    fprintf(stderr, "Cannot find description of section [global]\n");
    goto cleanup;
  }
  */

  if (!f && !(f = fopen(path, "r"))) {
    fprintf(stderr, "Cannot open configuration file %s\n", path);
    goto cleanup;
  }

  if (cur_info) {
    cfg = (struct generic_section_config*) xcalloc(1, cur_info->size);
    if (cur_info->init_func) cur_info->init_func(cfg);
    cfg->next = NULL;
    psect = &cfg->next;
  }

  while (1) {
    c = read_first_char(f);
    if (c == EOF || c == '[') break;
    if (c == '#' || c== '%' || c == ';') {
      read_comment(f);
      continue;
    }
    if (c == '@') {
      if (handle_conditional(f) < 0) goto cleanup;
      if (p_cond_count) (*p_cond_count)++;
      continue;
    }
    if (!parsecfg_state.output_enabled) {
      read_comment(f);
      continue;
    }
    if (read_variable(f, varname, sizeof(varname),
                      varvalue, sizeof(varvalue)) < 0) goto cleanup;
    if (!quiet_flag) {
      printf("%d: Value: %s = %s\n", parsecfg_state.lineno - 1, varname, varvalue);
    }
    if (!cur_info) {
      fprintf(stderr, "Cannot find description of section [global]\n");
      goto cleanup;
    }
    if (copy_param(cfg, cur_info, varname, varvalue) < 0) goto cleanup;
  }

  while (c != EOF) {
    if (read_section_name(f, sectname, sizeof(sectname)) < 0) goto cleanup;
    if (!quiet_flag) {
      printf("%d: New section %s\n", parsecfg_state.lineno - 1, sectname);
    }
    if (!strcmp(sectname, "global")) {
      fprintf(stderr, "Section global cannot be specified explicitly\n");
      goto cleanup;
    }
    for (sindex = 0; params[sindex].name; sindex++) {
      if (!strcmp(params[sindex].name, sectname)) {
        cur_info = &params[sindex];
        break;
      }
    }
    if (!cur_info) {
      fprintf(stderr, "Cannot find description of section [%s]\n", sectname);
      goto cleanup;
    }
    if (cur_info->pcounter) (*cur_info->pcounter)++;

    sect = (struct generic_section_config*) xcalloc(1, cur_info->size);
    strcpy(sect->name, sectname);
    if (cur_info->init_func) cur_info->init_func(sect);
    sect->next = NULL;
    *psect = sect;
    psect = &sect->next;

    while (1) {
      c = read_first_char(f);
      if (c == EOF || c == '[') break;
      if (c == '#' || c == '%' || c == ';') {
        read_comment(f);
        continue;
      }
      if (c == '@') {
        if (handle_conditional(f) < 0) goto cleanup;
        if (p_cond_count) (*p_cond_count)++;
        continue;
      }
      if (!parsecfg_state.output_enabled) {
        read_comment(f);
        continue;
      }
      if (read_variable(f, varname, sizeof(varname),
                        varvalue, sizeof(varvalue)) < 0) goto cleanup;
      if (!quiet_flag) {
        printf("%d: Value: %s = %s\n", parsecfg_state.lineno - 1, varname, varvalue);
      }
      if (copy_param(sect, cur_info, varname, varvalue) < 0) goto cleanup;
    }
  }

  if (parsecfg_state.cond_stack) {
    fprintf(stderr, "%d: unclosed conditional compilation\n", parsecfg_state.lineno);
    goto cleanup;
  }

  fflush(stdout);

  if (f) fclose(f);
  return cfg;

 cleanup:
  xfree(cfg);
  if (f) fclose(f);
  return NULL;
}
Exemple #2
0
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);
	}

	}
}