static Section *ini_search_section(const Ini *ini, const char* section_name) { size_t i; assert(ini != NULL); assert(section_name != NULL); for (i = 0; i < ini->nsections; i++) { if (strcmp(section_get_name(ini->sections[i]), section_name) == 0) { return ini->sections[i]; } } return NULL; }
static int coff_make_section_header(block blk, section_list seclist, long offset) { struct coff_section_header shdr; section sec; int count = 0; long size = 0; long lflags; for (sec = section_list_search(seclist, NULL); sec; sec = section_get_next(sec)) { memset(&shdr, 0, sizeof(shdr)); strncpy(shdr.name, section_get_name(sec), sizeof(shdr.name)); b32w(&shdr.physical_addr, section_get_physical_addr(sec)); b32w(&shdr.virtual_addr, section_get_virtual_addr(sec)); b32w(&shdr.size, section_get_memory_size(sec)); if (section_get_file_size(sec)) b32w(&shdr.offset, offset + section_list_count_offset(seclist, sec)); else b32w(&shdr.offset, 0); b32w(&shdr.relocation, 0); b32w(&shdr.line_number, 0); b16w(&shdr.relocation_num, 0); b16w(&shdr.line_number_num, 0); lflags = 0; switch (section_get_type(sec)) { case SECTION_TYPE_TEXT: /* fall through */ case SECTION_TYPE_RODATA: lflags |= COFF_SHDR_FLAG_TEXT; break; case SECTION_TYPE_DATA: lflags |= COFF_SHDR_FLAG_DATA; break; case SECTION_TYPE_BSS: lflags |= COFF_SHDR_FLAG_BSS; break; case SECTION_TYPE_STRING: /* fall through */ case SECTION_TYPE_OTHER: /* fall through */ default: break; } b32w(&shdr.flags, lflags); count++; size += block_write(blk, sizeof(shdr), (char *)&shdr); } return count; }
/* * helpers: */ static gboolean _gui_get_first_account(Config *config, gchar **username, gchar **key, gchar **secret) { Section *section; Section *child; Value *value; gint count; gint result = 0; gboolean success = FALSE; g_debug("Getting account data from configuration..."); *username = NULL; *key = NULL; *secret = NULL; /* get root section from configuration */ section = config_get_root(config); /* find "Accounts" section */ if((section = section_find_first_child(section, "Twitter")) && (section = section_find_first_child(section, "Accounts"))) { count = section_n_children(section); /* set account data */ for(gint i = 0; i < count && !success; ++i) { child = section_nth_child(section, i); if(!g_ascii_strcasecmp(section_get_name(child), "Account")) { ++result; if((value = section_find_first_value(child, "username")) && VALUE_IS_STRING(value)) { *username = g_strdup(value_get_string(value)); g_debug("Found username: \"%s\"", *username); } if((value = section_find_first_value(child, "oauth_access_key")) && VALUE_IS_STRING(value)) { *key = g_strdup(value_get_string(value)); g_debug("Found username: \"%s\"", *key); } if((value = section_find_first_value(child, "oauth_access_secret")) && VALUE_IS_STRING(value)) { *secret = g_strdup(value_get_string(value)); g_debug("Found username: \"%s\"", *secret); } } if(*username && *key && *secret) { success = TRUE; } } } if(!success) { g_free(*username); g_free(*key); g_free(*secret); } return success; }