static gboolean found_in_addressbook(const gchar *address) { gchar *addr = NULL; gboolean found = FALSE; gint num_addr = 0; if (!address) return FALSE; addr = g_strdup(address); extract_address(addr); num_addr = complete_address(addr); if (num_addr > 1) { /* skip first item (this is the search string itself) */ int i = 1; for (; i < num_addr && !found; i++) { gchar *caddr = get_complete_address(i); extract_address(caddr); if (strcasecmp(caddr, addr) == 0) found = TRUE; g_free(caddr); } } g_free(addr); return found; }
/** * Initialize search term for address completion. * \param entry Address entry field. */ static gboolean address_completion_complete_address_in_entry(GtkEntry *entry, gboolean next) { gint ncount, cursor_pos; gchar *searchTerm, *new = NULL; cm_return_val_if_fail(entry != NULL, FALSE); if (!gtk_widget_has_focus(GTK_WIDGET(entry))) return FALSE; /* get an address component from the cursor */ searchTerm = get_address_from_edit( entry, &cursor_pos ); if( ! searchTerm ) return FALSE; /* g_print( "search for :::%s:::\n", searchTerm ); */ /* Clear any existing search */ g_free( _compWindow_->searchTerm ); _compWindow_->searchTerm = g_strdup( searchTerm ); /* Perform search on local completion index */ ncount = complete_address( searchTerm ); if( 0 < ncount ) { new = get_next_complete_address(); g_free( new ); }
int init_inode_table(struct file_system* lfs) { unsigned int inode_table[BLOCK_SIZE]; struct inode* root; struct inode* hello; int res = 0; unsigned int addr; int at = 0; printf("%s\n", "init_inode_table"); printf("inode_table: %p, %d\n", inode_table, sizeof(&inode_table)); hello = malloc(INODE_SIZE); if (!hello) { res = -ENOMEM; } else { memset(hello, 0, INODE_SIZE); hello->inode_number = INODE_NUMBERS_MIN + 1; memset(hello->file_name, 0, FILE_NAME_LENGTH_MAX); strcpy(hello->file_name, "hello.txt"); hello->is_dir = 0; memset(hello->block_placements, 0, BLOCKS_PR_INODE); memset(hello->blocks_changed, 0, BLOCKS_PR_INODE); hello->number_of_blocks = 0; hello->parent_inode_number = INODE_NUMBERS_MIN; hello->file_size = 0; root = malloc(INODE_SIZE); if (!root) { res = -ENOMEM; } else { memset(root, 0, INODE_SIZE); memset(root->file_name, 0, FILE_NAME_LENGTH_MAX); memcpy(root->file_name, "/", strlen("/")); root->inode_number = INODE_NUMBERS_MIN; memset(root->block_placements, 0, BLOCKS_PR_INODE); memset(root->blocks_changed, 0, BLOCKS_PR_INODE); root->parent_inode_number = root->inode_number; root->is_dir = 1; root->number_of_blocks = 0; root->number_of_children = 1; root->block_placements[0] = hello->inode_number; if (!res) { addr = block_start_in_segment(0); //printf("init table: addr = %d\n", addr); memset(inode_table, 0, BLOCK_SIZE); res = copy_one_block(&hello, lfs->buffer, 0, addr); if (!res) { lfs->buffer_summary[at] = BLOCK_TYPE_INODE; inode_table[hello->inode_number] = complete_address(lfs, addr); addr = block_start_in_segment(1); at++; lfs->number_of_inodes = 1; addr = block_start_in_segment(at); res = copy_one_block(&root, lfs->buffer, 0, addr); inode_table[root->inode_number] = complete_address(lfs, addr); lfs->buffer_summary[at] = BLOCK_TYPE_INODE; at++; lfs->number_of_inodes++; addr = block_start_in_segment(at); res = copy_one_block(inode_table, lfs->buffer, 0, addr); lfs->buffer_summary[at] = BLOCK_TYPE_ITBL; at++; } } //free(root); } //free(hello); } //printf("Storage size for int : %d \n", sizeof(int)); return res; }