コード例 #1
0
bool data_file_section::section_new(int line, char *p_line)
{
  char token[MAX_TOKEN_LEN] = "";
  char value[MAX_TOKEN_LEN] = "";

  assert(p_line);  
  
  tokenize_line_param(p_line, token, value);
  
  if(token[0] && value[0]) {
    if(!strcasecmp(token,SECTION_NAME_NAME)) {
      name_set(value);
      source_line_set(line);
    }
    else if(!strcasecmp(token,SECTION_NAME_TYPE)) {
      strncpy(section_type,value,MAX_NAME);
      source_line_set(line);
    }
    else {
      section_new(line, p_line, token, value);
    }
    return(TRUE);
  }
  else {
    // A raw string
    section_new(line, p_line,
                token[0] ? token : NULL,
                value[0] ? value : NULL);
  }
  return(FALSE);
}
コード例 #2
0
ファイル: outcoff.c プロジェクト: 7ym0n/note
/***********************************************************
 * 需要讲一下符号表的存储结构,内存存储结构与文件存储结构
 * 功能:			新建存储COFF符号表的节
 * symtab:			COFF符号表名
 * Characteristics: 节属性
 * strtab_name:		与符号表相关的字符串表
 * 返回值:			存储COFF符号表的节
 **********************************************************/
Section *new_coffsym_section(char *symtab_name, int Characteristics, char *strtab_name)
{
	Section *sec;
	sec = section_new(symtab_name, Characteristics);
	sec->link = section_new(strtab_name, Characteristics);
	sec->hashtab = mallocz(sizeof(int)*MAXKEY);
	return sec;
}
コード例 #3
0
void data_file_section::load(void)
{
  bool in_comment = FALSE;
  
  char line[MAX_TOKEN_LEN];
  while(p_file->load_line(line)) {
    
    LINE_TYPE type = line_type_get(line);

    /*
     * Skip comments in input file
     */
    if(type == LINE_COMMENT_START) {
      in_comment = TRUE;
      continue;
    }
    else if(type == LINE_COMMENT_STOP) {
      in_comment = FALSE;
      continue;
    } else if(in_comment) {
      continue;
    }
    
    /*
     * Process lines
     */
    switch(type) {
      case LINE_NONE:
      case LINE_SECTION_INCLUDE:
      case LINE_COMMENT:
      case LINE_COMMENT_START:
      case LINE_COMMENT_STOP:
        break;
      
      // Create and load new sub-section
      case LINE_SECTION_START:
      {
        data_file_section *p_new = section_new(p_file->current_line_get(), NULL,NULL,NULL);
        p_new->load();
        break;
      }   
      // Load a line to current section
      case LINE_SECTION_ITEM:
      {
        section_new(p_file->current_line_get(), line);
        break;
      }
      // Close this section
      case LINE_SECTION_STOP:
      {
        return;
      }
    }
  }
}
コード例 #4
0
ファイル: camconfig.c プロジェクト: mvanderkolff/navi-misc
static
CamConfigSection *camconfig_add_section( CamConfig *ccfg, char *newsec )
{
  CamConfigSection *res;
  char *keyval;
  hnode_t *node;

  if( hash_lookup( ccfg->mainhash, newsec ) != NULL ){
    camserv_log( "camconfig", "Section \"%s\" multi-defined in cfg",
		 newsec );
    return NULL;
  }
    
  if( (res = section_new( newsec )) == NULL )
    return NULL;

  if( (keyval = strdup( newsec )) == NULL ){
    section_dest( res );
    return NULL;
  }

  if( (node = hnode_create( res )) == NULL ){
    section_dest( res );
    free( keyval );
    return NULL;
  }

  hash_insert( ccfg->mainhash, node, keyval );
  return res;
}
コード例 #5
0
ファイル: sections.c プロジェクト: mralexgray/MagicHat
/*
 * section_set() sets the current section to passed section pointer struct.
 * This is used by dwarf2dbg.c before emiting the debug sections.
 */
void
section_set(
frchainS *frcP)
{
	section_new(frcP->frch_section.segname, frcP->frch_section.sectname,
		    frcP->frch_section.flags & SECTION_TYPE,
		    frcP->frch_section.flags & SECTION_ATTRIBUTES,
		    frcP->frch_section.reserved2);
}
コード例 #6
0
ファイル: BFD.c プロジェクト: hexgolems/opdis-ruby
static void add_section_to_hash( bfd * abfd, asection * s, PTR data ) {
	VALUE sec;
	VALUE * hash = (VALUE *) data;
	if (! abfd || ! s ) {
		return;
	}
	sec = section_new(abfd, s);
	rb_hash_aset( *hash, rb_iv_get(sec, IVAR(SEC_ATTR_NAME)), sec);
}
コード例 #7
0
ファイル: matfuncs.c プロジェクト: aylusltd/gretl
static int 
maybe_add_section (xmlDocPtr doc, xmlNodePtr node, sectlist *slist)
{
    section *sect, **sects = NULL;
    char *tmp;
    int ns, err = 0;

    tmp = (char *) xmlGetProp(node, (UTF) "section");
    if (tmp == NULL) {
	missing_attrib("function", "section");
	return 1;
    }

    if (not_wanted(tmp)) {
	return 0;
    }

    if (!approved_section_title(tmp)) {
	fprintf(stderr, "*** Found unapproved section heading '%s'\n", tmp);
	return 1;
    }

#if VERBOSE
    fprintf(stderr, "looking at section '%s'\n", tmp);
#endif

    if (!section_already_recorded(slist, tmp)) {
#if VERBOSE
	fprintf(stderr, " not recorded: adding new section\n");
#endif

	sect = section_new(tmp);
	if (sect == NULL) {
	    return 1;
	}

	ns = slist->nsects + 1;

	sects = realloc(slist->sections, ns * sizeof *sects);
	if (sects == NULL) {
	    fprintf(stderr, "Out of memory\n");
	    return 1;
	}

	slist->sections = sects;
	slist->sections[ns - 1] = sect;
	slist->nsects = ns;
    } 

    free(tmp);

    return err;
}
コード例 #8
0
ファイル: outcoff.c プロジェクト: 7ym0n/note
/***********************************************************
 * 功能:	COFF初始化
 **********************************************************/
void init_coff()
{
	dynarray_init(&sections,8);
    nsec_image = 0;

	sec_text = section_new(".text",
				IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_CNT_CODE);
	sec_data = section_new(".data",
				IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE |
				IMAGE_SCN_CNT_INITIALIZED_DATA);
	sec_rdata = section_new(".rdata",
				IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_INITIALIZED_DATA);
	sec_idata = section_new(".idata",
				IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | 
				IMAGE_SCN_CNT_INITIALIZED_DATA);
	sec_bss = section_new(".bss",
				IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | 
				IMAGE_SCN_CNT_UNINITIALIZED_DATA);
	sec_rel = section_new(".rel",
				IMAGE_SCN_LNK_REMOVE | IMAGE_SCN_MEM_READ);


	sec_symtab = new_coffsym_section(".symtab",
				IMAGE_SCN_LNK_REMOVE | IMAGE_SCN_MEM_READ,".strtab");

	sec_dynsymtab = new_coffsym_section(".dynsym",
				IMAGE_SCN_LNK_REMOVE | IMAGE_SCN_MEM_READ,".dynstr");

	coffsym_add(sec_symtab,"",0,0,0,IMAGE_SYM_CLASS_NULL);
	coffsym_add(sec_symtab,".data",0,sec_data->index,0,IMAGE_SYM_CLASS_STATIC);
	coffsym_add(sec_symtab,".bss",0,sec_bss->index,0,IMAGE_SYM_CLASS_STATIC);
	coffsym_add(sec_symtab,".rdata",0,sec_rdata->index,0,IMAGE_SYM_CLASS_STATIC);
	coffsym_add(sec_dynsymtab,"",0,0,0,IMAGE_SYM_CLASS_NULL);
}
コード例 #9
0
void config_set_string(config_t *config, const char *section, const char *key, const char *value) {
  section_t *sec = section_find(config, section);
  if (!sec) {
    sec = section_new(section);
    list_append(config->sections, sec);
  }

  for (const list_node_t *node = list_begin(sec->entries); node != list_end(sec->entries); node = list_next(node)) {
    entry_t *entry = list_node(node);
    if (!strcmp(entry->key, key)) {
      free(entry->value);
      entry->value = strdup(value);
      return;
    }
  }

  entry_t *entry = entry_new(key, value);
  list_append(sec->entries, entry);
}
コード例 #10
0
ファイル: config.c プロジェクト: Detegr/HBot
void config_add(struct config* conf, const char* section, const char* key, const char* val)
{
	struct configsection* sect;
	if((sect=config_find_section(conf, section)))
	{
		struct configitem* item;
		if((item=config_find_item(conf, key, section)))
		{
			if(item->val) free(item->val);
			if(val) item->val=strdup(val);
			else item->val=NULL;
		}
		else item_add(sect, key, val);
	}
	else
	{
		section_new(conf, section);
		config_add(conf, section, key, val);
	}
}
コード例 #11
0
ファイル: main.c プロジェクト: GlebDavydov/Davydov-KP-52
int main(void){
    my_test();
    int errcheck = 0;
    int *ERR = &errcheck;
    section_t *fourteen = section_new(ERR);
    if(error_output(ERR))
       return 0;
    section_auditory_add(fourteen, 67, 25, ERR);
    if(error_output(ERR))
       return 0;
    int plc = section_total_places(fourteen, ERR);
    if(error_output(ERR))
       return 0;
    printf("\nPlaces: %d", plc);
    auditory_occupy(fourteen, 67,  "Hadyniak", ERR);
    if(error_output(ERR))
       return 0;
    char *name = auditory_isoccupied(fourteen, 67, ERR);
    if(error_output(ERR))
       return 0;
    printf("Auditory 67-14 is occupied by %s", name);
    return 0;
}
コード例 #12
0
ファイル: section.c プロジェクト: meonwax/acme
// setup outermost section
void section_passinit(void)
{
	scope_localcount = SCOPE_GLOBAL;	// will be incremented by next line
	section_new(&outer_section, s_Zone, s_untitled, FALSE);
}
コード例 #13
0
bool data_file::load(void)
{  
  DATA_FILE_SECTION *p_current = NULL;
  bool in_comment = FALSE;
  
  char line[MAX_TOKEN_LEN];
  while(load_line(line)) {
    LINE_TYPE type = line_type_get(line);
    
    /*
     * Skip comments in input file
     */
    if(type == LINE_COMMENT_START) {
      in_comment = TRUE;
      continue;
    }
    else if(type == LINE_COMMENT_STOP) {
      in_comment = FALSE;
      continue;
    } else if(in_comment) {
      continue;
    }
    
    switch(type) {
      case LINE_NONE:
      case LINE_COMMENT:
      case LINE_COMMENT_START:
      case LINE_COMMENT_STOP:
        break;
      // Create and load whole section
      case LINE_SECTION_START:
        p_current = section_new();
        p_current->load();
        break;
      case LINE_SECTION_ITEM:
        // Should not be here
        break;
      case LINE_SECTION_STOP:
        // Should not be here
        break;
      case LINE_SECTION_INCLUDE:
        {
          // Load sub-file
          char value[MAX_TOKEN_LEN];
          if(tokenize_line_command(line, NULL, value)) {
            DATA_FILE file;
            if(!file.load(value, FALSE)) {
              char local_file[MAX_FILENAME];
              return_path(current_dir, value, local_file, MAX_FILENAME);
              if(!file.load(local_file, FALSE)) {
                return(FALSE);
              }
            }
            
            import(&file);
          }
        }
        break;
    }
  }  
  return(TRUE);
}
コード例 #14
0
static GList*
load_stream(FILE *fp)
{
    assert(fp);

    GList *sections = NULL;
    section_t *master = section_new("%description");
    section_t *sec = NULL;

    sections = g_list_append(sections, master);

    char *line;
    while ((line = xmalloc_fgetline(fp)) != NULL)
    {
        /* Skip comments */
        char first = *skip_whitespace(line);
        if (first == '#')
            goto free_line;

        /* Handle trailing backslash continuation */
 check_continuation: ;
        unsigned len = strlen(line);
        if (len && line[len-1] == '\\')
        {
            line[len-1] = '\0';
            char *next_line = xmalloc_fgetline(fp);
            if (next_line)
            {
                line = append_to_malloced_string(line, next_line);
                free(next_line);
                goto check_continuation;
            }
        }

        /* We are reusing line buffer to form temporary
         * "key\0values\0..." in its beginning
         */
        bool summary_line = false;
        char *value = NULL;
        char *src;
        char *dst;
        for (src = dst = line; *src; src++)
        {
            char c = *src;
            /* did we reach the value list? */
            if (!value && c == ':' && src[1] == ':')
            {
                *dst++ = '\0'; /* terminate key */
                src += 1;
                value = dst; /* remember where value starts */
                summary_line = (strcmp(line, "%summary") == 0);
                if (summary_line)
                {
                    value = (src + 1);
                    break;
                }
                continue;
            }
            /* skip whitespace in value list */
            if (value && isspace(c))
                continue;
            *dst++ = c; /* store next key or value char */
        }

        GList *item_list = NULL;
        if (summary_line)
        {
            /* %summary is special */
            item_list = g_list_append(NULL, xstrdup(skip_whitespace(value)));
        }
        else
        {
            *dst = '\0'; /* terminate value (or key) */
            if (value)
                item_list = split_string_on_char(value, ',');
        }

        sec = section_new(line);
        sec->items = item_list;

        if (sec->name[0] == '%')
        {
            if (!summary_line && strcmp(sec->name, "%attach") != 0)
            {
                master->children = g_list_reverse(master->children);
                master = sec;
            }

            sections = g_list_prepend(sections, sec);
        }
        else
            master->children = g_list_prepend(master->children, sec);

 free_line:
        free(line);
    }

    /* If master equals sec, then master's children list was not yet reversed.
     *
     * %description is the default section (i.e is not explicitly mentioned)
     * and %summary nor %attach cause its children list to reverse.
     */
    if (master == sec || strcmp(master->name, "%description") == 0)
        master->children = g_list_reverse(master->children);

    return sections;
}