Пример #1
0
void create_about_gui(Sven *sven,GtkWidget *vbox1)
{ 
	GtkWidget *vbox;
	GtkWidget *notebook;
	GdkColor color;
	

	DEBUG_MSG("Start create_about_gui\n");

	gtk_box_pack_start (GTK_BOX (vbox1), create_header(_("Info")), FALSE, FALSE, 0);
	
	vbox =gtk_vbox_new (FALSE, BORDER);
	gtk_container_set_border_width (GTK_CONTAINER (vbox), BORDER);
	gtk_widget_show (vbox);
	gtk_box_pack_start (GTK_BOX (vbox1), vbox, TRUE, TRUE, 0);
	
  
 
	/* the notebook */
	notebook = gtk_notebook_new ();
	gtk_widget_show (notebook);
	gtk_widget_set_size_request (notebook, -1, 300);
	gtk_box_pack_start (GTK_BOX (vbox), notebook, TRUE, TRUE, 0);

	/* add pages */
	add_page (GTK_NOTEBOOK (notebook), _("Info"), INFO, FALSE);
	add_page (GTK_NOTEBOOK (notebook), _("Authors"), AUTHORS, FALSE);
	add_page (GTK_NOTEBOOK (notebook), _("Thanks To"), THANKS, TRUE);
	add_page (GTK_NOTEBOOK (notebook), _("Translators"), TRANSLATORS, TRUE);

	gtk_widget_show_all(vbox);
}
Пример #2
0
page * add_str_to_page(char * str, int type, book *b, page *p)
{
	char ** lines=NULL;
	char ** newlines=NULL;
	char ** newlines_ptr;
	int i;

	if(!str) return NULL;
	if(!p)p=add_page(b);
	
	newlines=get_lines(str, b->max_width);
	newlines_ptr = newlines;
	lines=p->lines;
	
	for(i=0;*lines;i++,lines++);

	if(type==_AUTHOR){
		*lines++=(char*)calloc(1,sizeof(char));
	} else if (type==_TITLE){
		*lines++=(char*)calloc(1,sizeof(char));
	}

	for(;newlines && *newlines;i++) {
		if(type==_AUTHOR){
			memmove(*newlines+1,*newlines,strlen(*newlines)+1);
			**newlines = to_color_char (c_orange3);
		} else if(type==_TITLE){
			memmove(*newlines+1,*newlines,strlen(*newlines)+1);
			**newlines = to_color_char (c_orange4);
		}
		if(i>=b->max_lines){
			*lines=NULL;
			p=add_page(b);
			lines=p->lines;
			i=0;
		}
		*lines++=*newlines++;
		// Grum: don't free *newlines, it's the pointer to actual line.
		// It's this pointer that is copied to p->lines, not the data
		// that it points to.
		//free(*newlines);
	}
	// This is a temporary array that holds the pointers to the lines. It 
	// can safely be freed.
	free(newlines_ptr);

	if(i<b->max_lines){
		if(type==_AUTHOR){
			*lines++=(char*)calloc(1,sizeof(char));
		} else if (type==_TITLE){
			*lines++=(char*)calloc(1,sizeof(char));
		}
	}
	*lines=NULL;

	return p;
}
Пример #3
0
page * add_image_to_page(char * in_text, _image *img, book * b, page * p)
{
	char **line;
	char *last_ptr;
	int i=0;
	int max_width;
	int max_lines;
	int h, w, x, y;

	if (img == NULL || b == NULL) return NULL;
	if(!p || p->image)p=add_page(b);
	
	max_width=b->max_width;
	max_lines=b->max_lines;

	h=img->h/16+1;
	y=img->y/16+1;
	w=img->w/9;
	x=img->x/10;

	if(y+h>max_lines || w+x>max_width) return NULL;
	
	line=p->lines;

	for(;line[i];i++);

	if(i+h>=max_lines||y<=i) {
		p=add_page(b);
		line=p->lines;
		i=0;
	}

	p->image=img;

	if(in_text){
		line+=i;

		last_ptr=in_text;

		for(i=0;i<h;i++,line++){//
			*line=(char*)malloc((max_width+2)*sizeof(char));
			if(i && (w<(max_width/3*2) && x+w<max_width) && last_ptr && *last_ptr){//If it's more than 2/3rd of the page width, don't work on it
				last_ptr=wrap_line_around_image(*line,w,x,b->max_width+1,last_ptr);
			} else {
				**line=0;
			}
		}

		if(*last_ptr)
			p=add_str_to_page(last_ptr,_IMAGE_TEXT,b,p);
	}

	return p;
}
Пример #4
0
int main (int argc, char **argv)
{
	GtkWidget *window, *notebook;
	GList *devices;

	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	if (gtk_clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) {
		g_critical ("Unable to initialize Clutter");
		return 1;
        }

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
	gtk_window_set_default_size (GTK_WINDOW (window), FIXED_WIDTH, -1);
	g_signal_connect (G_OBJECT (window), "delete-event",
			  G_CALLBACK (delete_event_cb), NULL);
	notebook = gtk_notebook_new ();
	gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
	gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE);
	gtk_widget_set_vexpand (notebook, TRUE);
	gtk_container_set_border_width (GTK_CONTAINER (notebook), 24);
	gtk_container_add (GTK_CONTAINER (window), notebook);
	gtk_widget_show (notebook);

	devices = create_fake_intuos4 ();
	add_page (devices, notebook);

	devices = create_fake_cintiq ();
	add_page (devices, notebook);

	devices = create_fake_bt ();
	add_page (devices, notebook);

	devices = create_fake_x201 ();
	add_page (devices, notebook);

	devices = create_fake_h610pro ();
	add_page (devices, notebook);

	gtk_widget_show (window);

	gtk_main ();

	return 0;
}
Пример #5
0
stored_object *create_object(size_t size)
{
    stored_object *obj = malloc(sizeof(stored_object));
    uint32_t page_id;

    // initialize to stored_object struct with size and initial pages
    obj->id = current_id++;
    obj->size = 0;
    obj->pages = NULL;

    // add the new object to the objects' hashtable
    HASH_ADD_INT(objects_table, id, obj); 

    while(size > obj->size)
    {
        if (GET_NEW_PAGE(VICTIM_OVERALL, EMPTY_TABLE_ENTRY_NB, &page_id) == FAIL)
        {
            // cleanup just in case we managed to do anything up until now
            remove_object(obj);
            return NULL;
        }

        if(!add_page(obj, page_id))
            return NULL;
        
        // mark new page as valid and used
        UPDATE_NEW_PAGE_MAPPING_NO_LOGICAL(page_id);
    }

    return obj;
}
Пример #6
0
void *
cache_alloc( struct cache *c ) {
  size_t i;
  size_t j;
  size_t entries_per_page;
  int new_page;
  char *current_page;
  char *locks;

  entries_per_page = c->page_size / ( c->entry_size + sizeof( char ) );
  for( i = 0; i < c->page_count; i++ ) {
    current_page = c->pages[i];
    locks = current_page + ( entries_per_page * c->entry_size );
    for( j = 0; j < entries_per_page; j++ ) {
      if( locks[j] == 0 ) {
        locks[j] = 1;
        return current_page + ( j * c->entry_size );
      }
    }
  }

  new_page = add_page( c );
  if( new_page < 0 ) {
    return NULL;
  }

  current_page = c->pages[new_page];
  locks = current_page + ( entries_per_page * c->entry_size );
  locks[0] = 1;
  return current_page;
}
Пример #7
0
void CHistory::add(POINT* grid, INT step, INT affected_amount)
{
	if (m_length >= m_page_amount * HISTORY_PAGE_SIZE)
		add_page();
	
	int page_no = m_length / HISTORY_PAGE_SIZE;
	INT offset_on_page = m_length % HISTORY_PAGE_SIZE;
	
	HISTORY_ENTRY* history_entry = *(m_pp_data + page_no) + offset_on_page;
	memcpy(&history_entry->grid_man_on, grid, sizeof(POINT));
	history_entry->step = step;
	history_entry->affected_amount = affected_amount;

	m_cursor = m_length;
	m_cursor_initial = m_cursor;
	m_length ++;

#ifdef __DEBUG__
TCHAR szDebug[128] = {0};
wsprintf(szDebug, "m_page_amount: %d, m_length: %d, m_cursor: %d ", m_page_amount, m_length, m_cursor);
wsprintf(szDebug, "%s   man_on(%d, %d), step: %d, attected_amount %d\r\n", szDebug, grid->y, grid->x, step, affected_amount);
CFileM file(DEBUG_FILE, OPEN_ALWAYS);
file.set_file_pointer(0, FILE_END);
file.write(szDebug, lstrlen(szDebug));
#endif
}
Пример #8
0
	void bin_index_t::file_node::add_item(const index_t& val,page_t& page)
	{
		page_pr pr(page);
		page_iter p=std::lower_bound(page.begin(),page.end(),val.key,pr);
		
		index_ref r=page[static_cast<size_t>(*p)];

		if(r.left()==0)
		{
			index_t cp(val);
			cp.index_in_page=static_cast<size_t>(*p);
			page.insert_item(cp);
			return;
		}

		page_ptr child_page=get_page(r.left());

		if(child_page->items_count()<child_page->page_max)
		{
			add_item(val,*child_page);
			return;
		}

		page_ptr new_right_page(create_page());

		split_page(*child_page,page,static_cast<size_t>(*p),*new_right_page);
		
		if(pr(val.key,*p)) add_item(val,*child_page);
		else add_item(val,*new_right_page);

		add_page(new_right_page);
	}
Пример #9
0
/*! \brief Update tree model of <B>pagesel</B>'s treeview.
 *  \par Function Description
 *  Updates the tree model of <B>pagesel</B>\'s treeview.
 *
 *  Right now, each time it is called, it rebuilds all the model from the
 *  list of pages passed in.
 *  It is a recursive function to populate the tree store
 *
 *  \param [in] model   GtkTreeModel to update.
 *  \param [in] parent  GtkTreeIter pointer to tree root.
 *  \param [in] pages   GedaPageList of pages for this toplevel.
 *  \param [in] page    The PAGE object to update tree model from.
 */
static void add_page (GtkTreeModel *model, GtkTreeIter *parent,
                      GedaPageList *pages, PAGE *page)
{
    GtkTreeIter iter;
    PAGE *p_current;
    GList *p_iter;

    /* add the page to the store */
    gtk_tree_store_append (GTK_TREE_STORE (model),
                           &iter,
                           parent);
    gtk_tree_store_set (GTK_TREE_STORE (model),
                        &iter,
                        COLUMN_PAGE, page,
                        COLUMN_NAME, page->page_filename,
                        COLUMN_CHANGED, page->CHANGED,
                        -1);

    /* search a page that has a up field == p_current->pid */
    for ( p_iter = geda_list_get_glist( pages );
            p_iter != NULL;
            p_iter = g_list_next( p_iter ) ) {

        p_current = (PAGE *)p_iter->data;
        if (p_current->up == page->pid) {
            add_page (model, &iter, pages, p_current);
        }
    }
}
Пример #10
0
/*! \todo Finish function documentation!!!
 *  \brief
 *  \par Function Description
 *
 */
void pagesel_update (Pagesel *pagesel)
{
    GtkTreeModel *model;
    TOPLEVEL *toplevel;
    PAGE *p_current;
    GList *iter;

    g_assert (IS_PAGESEL (pagesel));

    g_return_if_fail (GSCHEM_DIALOG (pagesel)->w_current);

    toplevel = GSCHEM_DIALOG (pagesel)->w_current->toplevel;
    model    = gtk_tree_view_get_model (pagesel->treeview);

    /* wipe out every thing in the store */
    gtk_tree_store_clear (GTK_TREE_STORE (model));
    /* now rebuild */
    for ( iter = geda_list_get_glist( toplevel->pages );
            iter != NULL;
            iter = g_list_next( iter ) ) {

        p_current = (PAGE *)iter->data;
        /* find every page that is not a hierarchy-down of another page */
        if (p_current->up < 0 ||
                s_page_search_by_page_id (toplevel->pages,
                                          p_current->up) == NULL) {
            add_page (model, NULL, toplevel->pages, p_current);
        }
    }

    /* select the current page in the treeview */
    select_page (pagesel->treeview, NULL, toplevel->page_current);
}
Пример #11
0
Packet PacketPool::allocate(int size)
{
	if (size <= 0)
		return Packet();
	Packet ret(m_pages[m_alloc_page].get(), m_alloc_ptr, size);

	// Advance the allocation location
	m_alloc_ptr += size;
	// If there is not enough room in the current page
	if (m_alloc_ptr >= m_page_size - m_packet_size) {
		// Try to find an empty one
		unsigned int i;
		for (i = 0; i < m_pages.size(); i++) {
			if (*reinterpret_cast<unsigned int*>(m_pages[i].get()) == 0) {
				break;
			}
		}
		m_alloc_page = i;
		m_alloc_ptr = PAGE_HEADER_SIZE;
		// If the page doesn't exist create it
		if (i == m_pages.size()) {
			add_page();
		}
	}

	return ret;
}
Пример #12
0
PacketPool::PacketPool(unsigned int maxPacketSize)
	: m_alloc_page(0)
	, m_alloc_ptr(PAGE_HEADER_SIZE)
	, m_page_size(maxPacketSize * 10 + PAGE_HEADER_SIZE)
	, m_packet_size(maxPacketSize)
{
	add_page();
}
WbPluginDbImport::WbPluginDbImport(grt::Module *module)
  : WizardPlugin(module)
{

  set_name("db_import_wizard");
  _db_rev_eng.grtm(grtm());
  
  _connection_page= new ConnectionPage(this);
  _connection_page->set_db_connection(db_plugin()->db_conn());

  _fetch_progress_page= new FetchSchemaNamesProgressPage(this);
  _fetch_progress_page->set_db_connection(db_plugin()->db_conn());
  _fetch_progress_page->set_load_schemas_slot(boost::bind(&WbPluginDbImport::load_schemas, this));

  _schema_selection_page= new SchemaSelectionPage(this);
  _schema_selection_page->set_db_plugin(db_plugin());

  _fetch_schemas_progress_page= new FetchSchemaContentsProgressPage(this);
  _fetch_schemas_progress_page->set_db_plugin(db_plugin());
  _object_selection_page= new ObjectSelectionPage(this);
//  _review_script_page= new ReviewScriptPage(this);
  _import_progress_page= new DBImportProgressPage(this);
  _finish_page= new FinishPage(this);
    
  add_page(mforms::manage(_connection_page));
  add_page(mforms::manage(_fetch_progress_page));
  add_page(mforms::manage(_schema_selection_page));
  add_page(mforms::manage(_fetch_schemas_progress_page));
  add_page(mforms::manage(_object_selection_page));
//  add_page(mforms::manage(_review_script_page));
  add_page(mforms::manage(_import_progress_page));
  add_page(mforms::manage(_finish_page));
  
  set_title("Reverse Engineer Database");
}
Пример #14
0
void read_server_book (const char *data, int len)
{
	char buffer[8192];
	book *b;
	page *p;
	int l = SDL_SwapLE16(*((Uint16*)(data+4)));
	int idx;

	if ( l >= sizeof (buffer) ) // Safer
		l = sizeof (buffer) - 1;
	memcpy (buffer, data+6, l);
	buffer[l] = '\0';
	
	b = get_book (SDL_SwapLE16 (*((Uint16*)(data+1))));
	if (b == NULL)
		b = create_book (buffer, data[0], SDL_SwapLE16 (*((Uint16*)(data+1))));

	b->server_pages = data[3];
	b->have_server_pages++;

	p=add_page(b);//Will create a page if pages is not found.

	idx = l + 6;
	while (idx <= len)
	{
		l = SDL_SwapLE16 (*((Uint16*)(&data[idx+1])));
		if ( l >= sizeof (buffer) ) // Safer.
			l = sizeof (buffer) - 1;
		memcpy (buffer, &data[idx+3], l);
		buffer[l]=0;

		switch (data[idx])
		{
			case _TEXT:
				p=add_str_to_page(buffer,_TEXT,b,p);
				break;
			case _AUTHOR:
				p=add_str_to_page(buffer,_AUTHOR,b,p);
				break;
			case _TITLE:
				p=add_str_to_page(buffer,_TITLE,b,p);
				break;
			case _IMAGE:
				p=add_image_from_server(buffer, b, p);
				break;
			case _PAGE:
				//p=add_page(b);
				break;
		}
		idx += l + 3;
	}

	b->active_page += b->pages_to_scroll;
	b->pages_to_scroll = 0;
	
	if (b) display_book_window (b); // Otherwise there's no point...
}
Пример #15
0
int main (int argc, char **argv)
{
	GtkWidget *window, *notebook;
	GList *devices;

	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	gtk_init (&argc, &argv);

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
	gtk_widget_set_size_request (window, FIXED_WIDTH, -1);
	g_signal_connect (G_OBJECT (window), "delete-event",
			  G_CALLBACK (delete_event_cb), NULL);
	notebook = gtk_notebook_new ();
	gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
	gtk_widget_set_vexpand (notebook, TRUE);
	gtk_container_set_border_width (GTK_CONTAINER (notebook), 24);
	gtk_container_add (GTK_CONTAINER (window), notebook);
	gtk_widget_show (notebook);

	devices = gsd_wacom_device_create_fake_intuos4 ();
	add_page (devices, notebook);

	devices = gsd_wacom_device_create_fake_cintiq ();
	add_page (devices, notebook);

	devices = gsd_wacom_device_create_fake_bt ();
	add_page (devices, notebook);

	devices = gsd_wacom_device_create_fake_x201 ();
	add_page (devices, notebook);

	gtk_widget_show (window);

	gtk_main ();

	return 0;
}
Пример #16
0
void push_frame(int sz_b) {
  sz_b = word_align(sz_b);
  if (top != NULL && have_space(sz_b+sizeof(void*))) { // can continue with current region
    //printf("push frame in page\n");
    *((void **)top->alloc_ptr) = top->frame_ptr;
    top->frame_ptr = top->alloc_ptr;
    top->alloc_ptr = (void *)((unsigned long)top->alloc_ptr + WORD_SZB);
  } else {
    //printf("push frame on new page\n");
    add_page(sz_b,0);
  }
}
Пример #17
0
// Relative path
static int process_mkd(char *filename, struct s_category *category)
{
	struct s_page *page;
	
	page = add_page(filename, category);
	if (page == NULL) {
		printf("Couldn't add page : %s\n", filename);
		return -1;
	} else {
		return 0;
	}
}
Пример #18
0
void apply_range(char* buffer, int npages, const char* range) {
    if (range != NULL) {
        int sr;
        int er;
        const char* t;
        enum {
            brange = 1,
            erange = 2,
            end = 4,
            none = 8
        } state;
        state = brange;
        memset(buffer, 1, npages); /* no pages. */
        t = range;
        while ((state & end) == 0) {
            switch (*range) {
                case '0': case '1': case '2': case '3': case '4':
                case '5': case '6': case '7': case '8': case '9':
                    ++range;  /* case [:digit:] */
                    break;
                case '-':
                    ++range;
                    if ((state & brange) != 0) {
                        sscanf(t, "%d-", &sr);
                        state &= ~brange;
                        state |= erange;
                    }
                    t = range;
                    break;
                case '\0':
                    state |= end;
                    --range; /* no break */
                case ',':
                    ++range;
                    if ((state & brange) != 0) {
                        sscanf(t, "%d,", &sr);
                        add_page(buffer, sr, npages);
                    } else if ((state & erange) != 0) {
                        state &= ~erange;
                        state |= brange;
                        sscanf(t, "%d-", &er);
                        add_pages(buffer, sr, er, npages);
                    }
                    t = range;
                    break;
                default:
                    t = range;
                    ++range;
            }
        }
    }
}
Пример #19
0
void *block_alloc(struct block *block, int size)
{
    assert(size && size <= page_size);
    void *page = last_page(block);
    int *page_offset = get_offset_ptr(page);
    if (page_size - *page_offset < size)
        if (!(page = add_page(block)))
            return NULL;
    page_offset = get_offset_ptr(page);
    void *ptr = (void *)((uintptr_t)page + *page_offset);
    *page_offset += size;
    return ptr;
}
Пример #20
0
void *stack_alloc(int sz_b) {
  assert(top != NULL);
  sz_b = word_align(sz_b);
 retry: if (have_space(sz_b)) { // can continue with current region
    void *res = top->alloc_ptr;
    //printf("allocated %d bytes\n", sz_b);
    top->alloc_ptr = (void *)((unsigned long)top->alloc_ptr + sz_b);
    return res;
  } else {
    //printf("adding page on demand\n");
    add_page(sz_b,1);
    goto retry;
  }
}
Пример #21
0
static void *pool_alloc(pool_t *p)
{
    if (allocd_bytes > collect_interval) {
        jl_gc_collect();
    }
    if (p->freelist == NULL) {
        add_page(p);
    }
    assert(p->freelist != NULL);
    gcval_t *v = p->freelist;
    p->freelist = p->freelist->next;
    v->flags = 0;
    return v;
}
Пример #22
0
int main(int argc, char *argv[])
{
	GtkWidget *button;
	GtkWidget *notebook;
	GtkWidget *vbox;
	GtkWidget *bbox;

	gtk_init(&argc, &argv);

	main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(main_window), PACKAGE_NAME);
	g_signal_connect(main_window, "delete_event", G_CALLBACK(quit_gtuxnes), NULL);
	gtk_container_set_border_width(GTK_CONTAINER(main_window), PAD_BORDER);

	vbox = gtk_vbox_new(FALSE, PAD_BORDER);


	/* Create the 'notebook' and add the pages to it */
	notebook = gtk_notebook_new();
	gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP);
	gtk_box_pack_start(GTK_BOX(vbox), notebook, FALSE, FALSE, 0);

	add_page(notebook, create_general_options_page(), "General");
	add_page(notebook, create_sound_options_page(),   "Sound");
	add_page(notebook, create_video_options_page(),   "Video");
	add_page(notebook, create_palette_options_page(), "Palette");
	add_page(notebook, create_input_options_page(),   "Input");
	add_page(notebook, create_debug_options_page(),   "Debug");


	/* Create the Run and Quit buttons */
	bbox = gtk_hbutton_box_new();
	gtk_box_set_spacing(GTK_BOX(bbox), PAD_BORDER);
	gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);

	button = gtk_button_new_from_stock(GTK_STOCK_EXECUTE);
	g_signal_connect(button, "clicked", G_CALLBACK(run_tuxnes), NULL);
	gtk_container_add(GTK_CONTAINER(bbox), button);

	button = gtk_button_new_from_stock(GTK_STOCK_QUIT);
	g_signal_connect(button, "clicked", G_CALLBACK(quit_gtuxnes), NULL);
	gtk_container_add(GTK_CONTAINER(bbox), button);

	gtk_box_pack_start(GTK_BOX(vbox), bbox, TRUE, TRUE, 0);

	gtk_container_add(GTK_CONTAINER(main_window), vbox);
	gtk_widget_show_all(main_window);

	config_file_name = g_build_filename(g_get_home_dir(), CONFIG_FILE_BASENAME, NULL);
	read_config_file(config_file_name);

	gtk_main();

	g_free(config_file_name);
	return(0);
}
Пример #23
0
void add_xml_page(xmlNode *cur, book * b)
{
	page *p=add_page(b);
	for(;cur;cur=cur->next){
		if(cur->type == XML_ELEMENT_NODE){
			if (!xmlStrcasecmp(cur->name,(xmlChar*)"title")){
				add_xml_str_to_page(cur,_TITLE,b,p);
			} else if (!xmlStrcasecmp(cur->name,(xmlChar*)"author")){
				add_xml_str_to_page(cur,_AUTHOR,b,p);
			} else if (!xmlStrcasecmp(cur->name,(xmlChar*)"text")){
				add_xml_str_to_page(cur,_TEXT,b,p);
			} else if (!xmlStrcasecmp(cur->name,(xmlChar*)"image")){
				add_xml_image_to_page(cur, b, p);
			}
		}
	}
}
Пример #24
0
void *block_alloc(struct block *block, size_t size) {
    if (size > block->page_size) {
        return NULL;
    }
    size_t offset = block->offsets[block->count - 1];
    void *page;
    if (block->page_size - offset < size) {
        page = add_page(block);
        if (!page) {
            return NULL;
        }
        offset = 0;
    } else {
        page = block->pages[block->count - 1];
    }
    block->offsets[block->count - 1] += size;
    return (void *)((uintptr_t)page + offset);
}
Пример #25
0
	bool bin_index_t::file_node::set(const data_t& key,const data_t& val)
	{
		validate_key_len(key);
		open_index_file();

		if(!root_page)
		{
			root_page=create_page();
			append_page(*root_page);
			save_index_data(0,root_page->page_offset);
			add_page(root_page);
		}
		
		index_t it;
		align_key(key,it);

		if(get_item(it))
		{
			index_t old_i=it;

			if(it.data_len>=val.size())save_data(it.data_offset,val);
			else it.data_offset=append_data(val);
			it.data_len=val.size();

			if(old_i.data_offset==it.data_offset&&
				old_i.data_len==it.data_len)
				return false;

			update_page(it);
			return false;
		}

		index_t v;
		v.key=key;
		align_key(key,v);
		v.data_len=val.size();
		v.data_offset=append_data(val);

		add_item(v);

		return true;
	}
Пример #26
0
	void bin_index_t::file_node::add_item(const index_t& val)
	{
		if(root_page->items_count()<root_page->page_max)
		{
			add_item(val,*root_page);
			return;
		}

		page_ptr new_root(create_page());
		index_ref r=(*new_root)[0];
		r.left()=root_page->page_offset;

		add_item(val,*new_root);

		root_page=new_root;
		append_page(*new_root);
		add_page(root_page);

		save_index_data(0,new_root->page_offset);
	}
Пример #27
0
void open_cb(GtkButton *button, GtkWindow *window)
{
	GtkWidget *dialog;
	int result;

	dialog = gtk_file_chooser_dialog_new("Open File", window,
					GTK_FILE_CHOOSER_ACTION_OPEN,
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
					NULL
	);

	result = gtk_dialog_run(GTK_DIALOG(dialog));
	if (result == GTK_RESPONSE_ACCEPT) {
		char *chosen_file_path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
		if (chosen_file_path != NULL)
			add_page(chosen_file_path);
	}

	gtk_widget_destroy(dialog);
}
Пример #28
0
std::shared_ptr<page_table_entry_x64>
page_table_x64::add_page(uintptr_t virt_addr, uint64_t bits)
{
    auto index = (virt_addr & ((INDEX_MASK) << bits)) >> bits;

    if (bits > PT_INDEX)
    {
        auto entry = std::dynamic_pointer_cast<page_table_x64>(m_entries[index]);

        if (!entry)
            m_entries[index] = entry = std::make_shared<page_table_x64>(&m_table[index]);

        return entry->add_page(virt_addr, bits - BITS_PER_INDEX);
    }
    else
    {
        if (m_entries[index])
            throw std::logic_error("add_page: page mapping already exists");

        return (m_entries[index] = std::make_shared<page_table_entry_x64>(&m_table[index]));
    }
}
Пример #29
0
	bin_index_t::page_ptr bin_index_t::file_node::get_page(file_offset_t page_offset)
	{
		pages_t::iterator it=pages.find(page_offset);

		if(it!=pages.end())
		{
			page_ptr p=it->second;
			if(!p->left.expired())
			{
				remove_from_list(p);
				insert_into_list(p,first_page.lock());
			}
			return p;
		}

		page_ptr p(create_page());
		p->self=p;
		p->page_offset=page_offset;
		load_page(*p);

		add_page(p);

		return p;
	}
Пример #30
0
struct cache *
cache_new( size_t size,
           void ( *entry_init ) ( void * ),
           void ( *entry_teardown ) ( void * ) ) {
  struct cache *c;
  size_t first_page;

  c = alloc_mem( sizeof( *c ) );
  if( !c ) {
    goto fail;
  }

  c->pages = alloc_mem( sizeof( char * ) );
  if( !c->pages ) {
    goto fail_pages;
  }

  c->entry_init = entry_init;
  c->entry_teardown = entry_teardown;
  c->entry_size = size;
  c->page_size = get_paged_size( size );
  c->page_count = 0;

  first_page = add_page( c );
  if( first_page != 0 ) {
    goto fail_pages;
  }

  return c;


fail_pages:
  free_mem( c );
fail:
  return NULL;
}