Ejemplo n.º 1
0
/**
 * Loads properties from file stored on the file system
 *
 * @param unicodeFileName file name
 * @param fileNameLen length of the file name
 * @return handle to the properties storage
 */
javacall_handle configdb_load_from_fs(javacall_utf16* unicodeFileName, int fileNameLen) {
    string_db*   d;
    char    line[MAX_LINE_LENGTH+1];
    char    sec[MAX_STR_LENGTH+1];
    char    key[MAX_STR_LENGTH+1];
    char    val[MAX_STR_LENGTH+1];
    char*   where;
    int lineno;
    char sep = '=';
    javacall_handle file_handle;
    javacall_result res;


    res = javacall_file_open(unicodeFileName,
                             fileNameLen,
                             JAVACALL_FILE_O_RDWR,
                             &file_handle);
    if (res != JAVACALL_OK) {
        javacall_print("Error: Unable to open the dynamic properties file.  "
                        "Check that jwc_properties.ini exists in your "
                        "application directory.\n");
        return NULL;
    }

    sec[0] = 0;

    /*
     * Initialize a new string_db entry
     */
    d = javacall_string_db_new(0);
    if (NULL == d) {
        return NULL;
    }
    lineno = 0;
    while (configdb_fgets(line, MAX_LINE_LENGTH, file_handle) != NULL) {
        lineno++;
        where = javautil_string_skip_leading_blanks(line); /* Skip leading spaces */
        if (*where==';' || *where=='#' || *where == 0){
            continue; /* Comment lines */
        }
        else {
            if (JAVACALL_OK == read_section_name(where, sec) == 1) {
                /* Valid section name */
                configdb_add_entry(d, sec, NULL, NULL);
            }
            else if (JAVACALL_OK == parse_line(where, key, val, sep)) {
                javautil_string_strip(key);
                javautil_string_strip(val);
                remove_escape_characters(val);
                configdb_add_entry(d, sec, key, val);
            }
        }
    }
    javacall_file_close(file_handle);
    return(javacall_handle)d ;
}
Ejemplo n.º 2
0
Archivo: elf32.c Proyecto: gz/aos10
static int
init_sections(struct edit_file *efile)
{
	uint16_t e_shnum;
	uint32_t e_shoff;
	int i;
	struct edit_section *current_section, *prev_section;
	
	e_shnum = read16(offsetof(Elf32_Ehdr, e_shnum) + efile->mmap, 
			efile->endianness);
	e_shoff = read32(offsetof(Elf32_Ehdr, e_shoff) + efile->mmap, 
			efile->endianness);

	efile->first_section = NULL;
	/* NB start with i=1 because section 0 always exists and is defined to be of type NULL */
	for (i=1; i < e_shnum; i++) {
		char *section_offset;;
		current_section = malloc(sizeof(struct edit_section));
		current_section -> next = NULL;

		section_offset = efile->mmap + e_shoff + (sizeof(Elf32_Shdr) * i);
		strcpy(current_section->name, ".");
		strcat(current_section->name, efile->ditname);
		strcat(current_section->name, read_section_name(efile, i)); 
		current_section->type = read32(offsetof(Elf32_Shdr, sh_type) + section_offset,
				efile->endianness);
		current_section->addr = read32(offsetof(Elf32_Shdr, sh_addr) + section_offset,
				efile->endianness);
		current_section->orig_offset = read32(offsetof(Elf32_Shdr, sh_offset) + section_offset,
						      efile->endianness);
		current_section->size = read32(offsetof(Elf32_Shdr, sh_size) + section_offset,
				efile->endianness);
		current_section->addralign = read32(offsetof(Elf32_Shdr, sh_addralign) + section_offset, 
				efile->endianness);
		current_section->entsize = read32(offsetof(Elf32_Shdr, sh_entsize) + section_offset,
				efile->endianness);
		current_section->flags = read32(offsetof(Elf32_Shdr, sh_flags) + section_offset,
				efile->endianness);

		if (i==1) {
			efile->first_section = current_section;
		} else {
			prev_section->next = current_section;
		}
		prev_section = current_section;
	}
}
Ejemplo n.º 3
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;
}