Exemplo n.º 1
0
void GraphState::reinsertEdge () {
    GSDeletedEdge &deletededge = deletededges.back ();
    vector<GSEdge> &edges1 = nodes[deletededge.tonode].edges;
    vector_push_back ( GSEdge, edges1, edge );
    edge.edgelabel = deletededge.edgelabel;
    edge.cyclemark = deletededge.cyclemark;
    edge.close = deletededge.close;
    edge.tonode = deletededge.fromnode;
    edge.postonode = deletededge.posfromnode;
    if ( deletededge.postonode != (int) edges1.size () - 1 ) {
        // reinsert at original location by swapping with the element at that position again
        GSEdge &edge3 = edges1[deletededge.postonode];
        nodes[edge3.tonode].edges[edge3.postonode].postonode = edges1.size () - 1;
        swap ( edge, edge3 );
    }
    vector<GSEdge> &edges2 = nodes[deletededge.fromnode].edges;
    vector_push_back ( GSEdge, edges2, edge2 );
    edge2.edgelabel = deletededge.edgelabel;
    edge2.tonode = deletededge.tonode;
    edge2.cyclemark = deletededge.cyclemark;
    edge2.close = deletededge.close;
    edge2.postonode = deletededge.postonode;
    if ( deletededge.posfromnode != (int)edges2.size () - 1 ) {
        // reinsert at original location by swapping with the element at that position again
        GSEdge &edge3 = edges2[deletededge.posfromnode];
        nodes[edge3.tonode].edges[edge3.postonode].postonode = edges2.size () - 1;
        swap ( edge2, edge3 );
    }
    deletededges.pop_back ();
    edgessize++;
    closecount -= deletededge.close;
}
Exemplo n.º 2
0
/**
 Przetwarza jedno słowo
 @param[in,out] index Indeks znaku w buforze
 @param[in,out] char_number Nr znaku w aktualnie przetwarzanej linii
 @param[in,out] line_number Nr linii przetwarzanej
 @param[in] buffer Bufor
 @param[in] dict Słownik
 @param[in] v_option Czy włączono opcję -v
 */
void parse_word(int *index, int *char_number, int *line_number, wchar_t *buffer, struct dictionary *dict, bool v_option)
{
	const int first_char = *char_number;
	vector *word = vector_new(sizeof(wchar_t), BUFFER_START_SIZE);
	for(; iswalpha(buffer[*index]); (*index)++, (*char_number)++)
		vector_push_back(word, buffer + *index);
	vector_push_back(word, L"\0");
	(*index)--;
	(*char_number)--;
	wchar_t *word_content = vector_content(word);
	wchar_t *word_small = malloc(vector_size(word) * sizeof(wchar_t));
	for(int i = 0; i < vector_size(word); i++)
		word_small[i] = towlower(word_content[i]);
	if(!dictionary_find(dict, word_small))
	{
		wprintf(L"#");
		if(v_option)
		{
			fwprintf(stderr, L"%d,%d %ls:", *line_number, first_char, word_content);
			struct word_list list;
			dictionary_hints(dict, word_small, &list);
			const wchar_t * const *hints = word_list_get(&list);
			int number_of_hints = word_list_size(&list);
			for(int i = 0; i < number_of_hints; i++)
				fwprintf(stderr, L" %ls", hints[i]);
			if(number_of_hints == 0)
				fwprintf(stderr, L" ");
			fwprintf(stderr, L"\n");
		}
	}
	wprintf(L"%ls", word_content);
	free(word_small);
	vector_done(word);
}
Exemplo n.º 3
0
/* CHAR DETECTION PART */
struct vector *lines_to_char(struct matrix *img, struct vector *lines) {
    struct vector *imgs = vector_make((img->height) * (img->width));
    for (size_t k = 0; k < lines->size; k++) {
	struct coords actual_coords;
	actual_coords.w1 = 0;
	actual_coords.w2 = 0;
	actual_coords.h1 = lines->data[k].h1;
	actual_coords.h2 = lines->data[k].h2;
	int recording = 0;

	for (size_t i = 0; i < img->width; i++) {
	    if (!recording) {
		if (!column_is_empty(img, i, lines->data[k].h1,
			    lines->data[k].h2)) {
		    recording = 1;
		    actual_coords.w1 = i;
		    actual_coords.w2 = i;
		}
	    } else {
		if (!column_is_empty(img, i, lines->data[k].h1,
			    lines->data[k].h2)) {
		    actual_coords.w2++;
		} else {
		    vector_push_back(imgs, actual_coords);
		    recording = 0;
		}
	    }
	}
	actual_coords.w1 = -1;
	vector_push_back(imgs, actual_coords);
    }
    return imgs;
}
Exemplo n.º 4
0
static void tcp_process(fd_set* set, vector_t* for_del)
{
    active_vector_iterator_t iter = active_vector_begin(&this.clients);
    while (!active_vector_is_end(iter))
    {
        client_t* client = iter.data;
        if (FD_ISSET(client->fd, set))
        {
            ssize_t rc = read_pre(client->fd, client->read, client->want);
            if (rc <= 0)
            {
                if (errno == EAGAIN || errno == EWOULDBLOCK) goto end;
                perror("read");
                vector_push_back(for_del, (void*)(long)active_vector_iterator_idx(iter), sizeof(active_vector_iterator_idx(iter)));
                goto end;
            }
            client->read += rc;
            client->want -= rc;
            if (client->want == 0)
            {
                if (IS_CLIENT_STATUS_WAITING_HEADER(client->status))
                {
                    size_t len = msg_data_length((msg_t*)client->buffer);
                    if (len)
                    {
                        msg_t* msg = (msg_t*)client->buffer;
                        client->status = (client->status & ~CLIENT_STATUS_WAITING_HEADER) | CLIENT_STATUS_WAITING_BODY;
                        if (msg->zone.clip)
                        {
                            if (msg->zone.last) client->want = len % client->max_length;
                            else client->want = client->max_length;
                        }
                        else client->want = len;
                        client->buffer_len = sizeof(msg_t) + client->want;
                        client->buffer = group_pool_room_realloc(&this.group_pool, client->buffer, sizeof(msg_t) + client->want);
                        if (client->buffer == NULL)
                        {
                            SYSLOG(LOG_ERR, "Not enough memory");
                            vector_push_back(for_del, (void*)(long)active_vector_iterator_idx(iter), sizeof(active_vector_iterator_idx(iter)));
                            exit(1);
                        }
                        client->read = ((msg_t*)client->buffer)->data;
                    }
                    else process_msg(client, (msg_t*)client->buffer, for_del, active_vector_iterator_idx(iter));
                }
                else process_msg(client, (msg_t*)client->buffer, for_del, active_vector_iterator_idx(iter));
            }
        }
        checkout_ttl(&client->recv_table);
end:
        iter = active_vector_next(iter);
    }
}
Exemplo n.º 5
0
// --------------------------------------------------------- console_print ---
void
console_print( console_t *self, wchar_t *text )
{
    // Make sure there is at least one line
    if( self->lines->size == 0 )
    {
        wchar_t *line = wcsdup( L"" );
        vector_push_back( self->lines, &line );
    }

    // Make sure last line does not end with '\n'
    wchar_t *last_line = *(wchar_t **) vector_get( self->lines, self->lines->size-1 ) ;
    if( wcslen( last_line ) != 0 )
    {
        if( last_line[wcslen( last_line ) - 1] == L'\n' )
        {
            wchar_t *line = wcsdup( L"" );
            vector_push_back( self->lines, &line );
        }
    }
    last_line = *(wchar_t **) vector_get( self->lines, self->lines->size-1 ) ;

    wchar_t *start = text;
    wchar_t *end   = wcschr(start, L'\n');
    size_t len = wcslen( last_line );
    if( end != NULL)
    {
        wchar_t *line = (wchar_t *) malloc( (len + end - start + 2)*sizeof( wchar_t ) );
        wcpncpy( line, last_line, len );
        wcpncpy( line + len, text, end-start+1 );

        line[len+end-start+1] = L'\0';

        vector_set( self->lines, self->lines->size-1, &line );
        free( last_line );
        if( (end-start)  < (wcslen( text )-1) )
        {
            console_print(self, end+1 );
        }
        return;
    }
    else
    {
        wchar_t *line = (wchar_t *) malloc( (len + wcslen(text) + 1) * sizeof( wchar_t ) );
        wcpncpy( line, last_line, len );
        wcpcpy( line + len, text );
        vector_set( self->lines, self->lines->size-1, &line );
        free( last_line );
        return;
    }
}
Exemplo n.º 6
0
// --------------------------------------------------------- console_print ---
void
console_print( console_t *self, char *text )
{
    // Make sure there is at least one line
    if( self->lines->size == 0 )
    {
        char *line = strdup( "" );
        vector_push_back( self->lines, &line );
    }

    // Make sure last line does not end with '\n'
    char *last_line = *(char **) vector_get( self->lines, self->lines->size-1 ) ;
    if( strlen( last_line ) != 0 )
    {
        if( last_line[strlen( last_line ) - 1] == '\n' )
        {
            char *line = strdup( "" );
            vector_push_back( self->lines, &line );
        }
    }
    last_line = *(char **) vector_get( self->lines, self->lines->size-1 ) ;

    char *start = text;
    char *end   = strchr(start, '\n');
    size_t len = strlen( last_line );
    if( end != NULL)
    {
        char *line = (char *) malloc( (len + end - start + 2)*sizeof( char ) );
        strncpy( line, last_line, len );
        strncpy( line + len, text, end-start+1 );

        line[len+end-start+1] = '\0';

        vector_set( self->lines, self->lines->size-1, &line );
        free( last_line );
        if( (end-start)  < (strlen( text )-1) )
        {
            console_print(self, end+1 );
        }
        return;
    }
    else
    {
        char *line = (char *) malloc( (len + strlen(text) + 1) * sizeof( char ) );
        strncpy( line, last_line, len );
        strcpy( line + len, text );
        vector_set( self->lines, self->lines->size-1, &line );
        free( last_line );
        return;
    }
}
int main() {
    struct vector_t myVector, secondVector;

    vector_init(&myVector);

    vector_push_back(&myVector,3);
    vector_push_back(&myVector,1);
    vector_push_back(&myVector,4);
    vector_push_back(&myVector,1);
    vector_push_back(&myVector,5);
    vector_push_back(&myVector,9);
    vector_push_back(&myVector,2);
    vector_push_back(&myVector,6);

    vector_copy(&myVector, &secondVector);
    printf("Size of copied vector: %d\n", vector_get_size(secondVector));

    printf("Size: %d\n", vector_get_size(myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Size: %d\n", vector_get_size(myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Size: %d\n", vector_get_size(myVector));

    vector_destroy(&myVector);
    return 0;
}
Exemplo n.º 8
0
int
main(int argc, char **argv)
{
	int *a, *b, *c, *d, *e, *f, *g;
	a = (int *)malloc(sizeof(int));
	b = (int *)malloc(sizeof(int));
	c = (int *)malloc(sizeof(int));
	d = (int *)malloc(sizeof(int));
	e = (int *)malloc(sizeof(int));
	f = (int *)malloc(sizeof(int));
	g = (int *)malloc(sizeof(int));
	*a = 6;
	*b = 1;
	*c = 99;
	*d = -17;
	*e = 22;
	*f = 9;
	*g = 6;

	struct Vector *iv = create_vector(2, free);
	vector_push_back(iv, a);
	vector_push_back(iv, b);
	vector_push_back(iv, c);
	vector_push_back(iv, d);
	vector_push_front(iv, e);
	vector_push_front(iv, f);
	vector_insert(iv, g, 5);

	vector_foreach(iv, print);
	printf("\nCount: %d, Capacity: %d--------------\n", vector_count(iv), vector_capacity(iv));

	printf("%d\n", *f);
	vector_remove(iv, f, compare, TRUE);
	vector_foreach(iv, print);
	printf("\nCount: %d, Capacity: %d--------------\n", vector_count(iv), vector_capacity(iv));

	vector_sort(iv, compare);
	vector_foreach(iv, print);
	printf("\nCount: %d, Capacity: %d--------------\n", vector_count(iv), vector_capacity(iv));

	printf("\nBsearch: %d, Lower: %d, Upper: %d\n", vector_bsearch(iv, a, compare), 
			vector_lower(iv, a, compare), vector_upper(iv, a, compare));

	vector_shuffle(iv);
	vector_foreach(iv, print);
	printf("\nCount: %d, Capacity: %d--------------\n", vector_count(iv), vector_capacity(iv));

	destroy_vector(iv, TRUE);
}
Exemplo n.º 9
0
void test_iterator_init_destroy(){
	Vector* vec = vector_init(1);
	int *a = NULL, *b = NULL, *c = NULL;

	vector_push_back(vec, a);
	vector_push_back(vec, b);
	vector_push_back(vec, c);

	Iterator* it = iterator_init(vec);
	assert(it->container == vec);
	assert(it->curent == vec->array);
	assert(*(it->curent) == a);

	iterator_destroy(it);
	vector_destroy(vec);
}
Exemplo n.º 10
0
/* ------------------------------------------------------------------------- */
TextureAtlas *
texture_atlas_new( size_t width, size_t height, size_t depth )
{
    assert( (depth == 1) || (depth == 3) );

    TextureAtlas *self = (TextureAtlas *) malloc( sizeof(TextureAtlas) );
    if( !self )
    {
        return NULL;
    }
    self->nodes = vector_new( sizeof(Node) );
    self->used = 0;
    self->width = width;
    self->height = height;
    self->depth = depth;
    Node node = {0,0,width};
    vector_push_back( self->nodes, &node );
    self->texid = 0;
    self->data = (unsigned char *)
        calloc( width*height*depth, sizeof(unsigned char) );

    // This is a special region that is used for background and underlined
    // decorations of glyphs
    int n = 4;
    unsigned char buffer[n*n];
    memset(buffer, 255, n*n);
    Region1 r = texture_atlas_get_region( self, n, n );
    texture_atlas_set_region( self, r.x, r.y, r.width, r.height, buffer, 1);
    self->black.x     = r.x + 1;
    self->black.y     = r.y + 1;
    self->black.width = r.width - 2;
    self->black.height= r.height - 2;

    return self;
}
// ------------------------------------------------------------------- init ---
void init( void )
{
    atlas = texture_atlas_new( 512, 512, 1 );
    font = texture_font_new_from_file( atlas, 32, "../media/fonts/Vera.ttf" );

    texture_glyph_t *glyph;

    // Generate the glyp at 512 points, compute distance field and scale it
    // back to 32 points
    // Just load another glyph if you want to see difference (draw render a '@')
    glyph = load_glyph( "../media/fonts/Vera.ttf", "@", 512, 64, 0.1);
    vector_push_back( font->glyphs, &glyph );

    texture_atlas_upload( atlas );

    glyph = texture_font_get_glyph( font, "@");

    GLuint indices[6] = {0,1,2, 0,2,3};
    vertex_t vertices[4] = { { -.5,-.5,0,  glyph->s0,glyph->t1,  0,0,0,1 },
                             { -.5, .5,0,  glyph->s0,glyph->t0,  0,0,0,1 },
                             {  .5, .5,0,  glyph->s1,glyph->t0,  0,0,0,1 },
                             {  .5,-.5,0,  glyph->s1,glyph->t1,  0,0,0,1 } };
    buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f" );
    vertex_buffer_push_back( buffer, vertices, 4, indices, 6 );

    program = shader_load( "../media/shaders/distance-field.vert",
                           "../media/shaders/distance-field-2.frag" );
    mat4_set_identity( &projection );
    mat4_set_identity( &model );
    mat4_set_identity( &view );
}
Exemplo n.º 12
0
// ----------------------------------------- font_manager_get_from_filename ---
texture_font_t *
font_manager_get_from_filename( font_manager_t *self,
                                const char * filename,
                                const float size )
{
    size_t i;
    texture_font_t *font;

    assert( self );
    for( i=0; i<vector_size(self->fonts); ++i )
    {
        font = * (texture_font_t **) vector_get( self->fonts, i );
        if( (strcmp(font->filename, filename) == 0) && ( font->size == size) )
        {
            return font;
        }
    }
    font = texture_font_new_from_file( self->atlas, size, filename );
    if( font )
    {
        vector_push_back( self->fonts, &font );
        texture_font_load_glyphs( font, self->cache );
        return font;
    }
    fprintf( stderr, "Unable to load \"%s\" (size=%.1f)\n", filename, size );
    return 0;
}
Exemplo n.º 13
0
int file_hiding_cfs_hide(CFS_t * cfs, inode_t ino)
{
	Dprintf("%s(\"%s\", 0x%x)\n", __FUNCTION__, path, path_cfs);
	file_hiding_state_t * state = (file_hiding_state_t *) cfs;
	int r;

	/* make sure this is really a table classifier */
	if (OBJMAGIC(cfs) != FILE_HIDING_MAGIC)
		return -EINVAL;

	/* NOTE: hiding ino only prevents future actions from seeing/using ino */

	const int already_hidden = hide_lookup(state->hide_table, ino);
	if (0 <= already_hidden)
		return -EINVAL;

	hide_entry_t * me = hide_entry_create(ino);
	if (!me)
		return -ENOMEM;

	if ((r = vector_push_back(state->hide_table, me)) < 0)
	{
		hide_entry_destroy(me);
		return r;
	}

	fprintf(stderr, "file_hiding_cfs: hiding %u\n", ino);
	return 0;
}
Exemplo n.º 14
0
TextureFont *
font_manager_get_from_filename( FontManager *self,
                                const char * filename,
                                const float size )
{
    size_t i;
    TextureFont *font;

    assert( self );

    for( i=0; i<self->fonts->size;++i )
    {
        font = (TextureFont *) vector_get( self->fonts, i );
        if( (strcmp(font->filename, filename) == 0) && ( font->size == size) )
        {
            return font;
        }
    }
    font = texture_font_new( self->atlas, filename, size );
    texture_font_cache_glyphs( font, self->cache );
    if( font )
    {
        vector_push_back( self->fonts, font );
    }
    return font;
}
Exemplo n.º 15
0
int haar_feat(int width, int heigh, int II[width][heigh],
              struct vector* vect_val_feat, size_t size_FD, size_t x, size_t y)
{
    int nb_feat = 0;
    int width_rec, height_rec, add_width, add_height;
    for(int type_feat=1; type_feat <= 5; type_feat++)  // numéro de la feature
    {
        type_advance(&width_rec, &height_rec, &add_width, &add_height,
                     type_feat);
        for(int w = width_rec; w<(int)size_FD; w++) // largeur de la feature
        {
            for(int h = height_rec; h<(int)size_FD; h++) // hauteur de la feature
            {
                for(int pos_featx=0; (pos_featx+ w - (int)x) < (int)size_FD;
                        pos_featx++) // position de la feature dans le carré en x
                {
                    for(int pos_featy=0; (pos_featy + h - (int)y) <(int)size_FD;
                            pos_featy++) // position de la feature dans le carré en y
                    {
                        int result = calcul(width, heigh, II, type_feat,
                                            pos_featx,pos_featy, w, h);
                        vector_push_back(vect_val_feat, result);
                        nb_feat++;
                    }
                }
            }
        }
    }
    return nb_feat;
}
Exemplo n.º 16
0
void GraphState::deleteEdge ( GSEdge &edge ) {
    vector_push_back ( GSDeletedEdge, deletededges, deletededge );
    // fill in the info about the deleted edge
    deletededge.tonode = edge.tonode;
    deletededge.edgelabel = edge.edgelabel;
    deletededge.postonode = edge.postonode;
    deletededge.cyclemark = edge.cyclemark;
    deletededge.close = edge.close;
    GSEdge &edge2 = nodes[edge.tonode].edges[edge.postonode];
    deletededge.fromnode = edge2.tonode;
    deletededge.posfromnode = edge2.postonode;
    // remove the edge from the state
    if ( (int) nodes[deletededge.tonode].edges.size () != deletededge.postonode + 1 ) {
        // edge2 not the last
        GSEdge &edge3 = nodes[deletededge.tonode].edges.back ();
        nodes[edge3.tonode].edges[edge3.postonode].postonode = deletededge.postonode;
        swap ( edge2, edge3 );
    }

    nodes[deletededge.tonode].edges.pop_back ();

    if ( (int) nodes[deletededge.fromnode].edges.size () != deletededge.posfromnode + 1 ) {
        GSEdge &edge3 = nodes[deletededge.fromnode].edges.back ();
        nodes[edge3.tonode].edges[edge3.postonode].postonode = deletededge.posfromnode;
        swap ( edge, edge3 );
    }
    nodes[deletededge.fromnode].edges.pop_back ();
    edgessize--;
    closecount += deletededge.close;
}
Exemplo n.º 17
0
struct vector *img_to_lines(struct matrix *img, struct vector *blocks) {
    struct vector *lines = vector_make((img->height) * (img->width));
    int status = 0; // not on a line
    size_t h = 0;
    for(; blocks->size != 0;)
    {
	struct coords current_block;
	vector_pop_front(blocks, &current_block);
	int w1 = current_block.w1, w2 = current_block.w2;

	for (; h < img->height; h++) {
	    if (status) {
		struct coords line;
		line.w1 = 1;
		line.w2 = 1;
		line.h1 = h - 1;
		for (; h < img->height && !line_is_empty(img, h, w1, w2); h++) {
		}
		line.h2 = h - 1;
		vector_push_back(lines, line);
		status = 0;
	    } else {
		for (; h < img->height && line_is_empty(img, h, w1, w2); h++) {
		}
		status = 1;
	    }
	}
    }
    free(blocks);
    return lines;
}
Exemplo n.º 18
0
int fuse_serve_mount_remove(mount_t * m)
{
	queue_entry_t * qe;
	char b = 1;
	Dprintf("%s(\"%s\")\n", __FUNCTION__, m->fstitch_path);

	if (!m || !m->mounted)
		return -EINVAL;

	if (shutdown_has_started())
		return 0; // m is already scheduled to be unmounted

	if (!(qe = calloc(1, sizeof(*qe))))
		return -ENOMEM;
	qe->mount = m;
	qe->action = QEUNMOUNT;

	if (write(unmount_pipe[1], &b, 1) != 1)
	{
		perror("fuse_serve_mount_remove(): write");
		return -1;
	}

	return vector_push_back(remove_queue, qe);
}
Exemplo n.º 19
0
/* ------------------------------------------------------------------------- */
void
texture_atlas_clear( TextureAtlas *self )
{

    vector_clear( self->nodes );
    self->used = 0;
	{
    Node node = {0,0,self->width};
    vector_push_back( self->nodes, &node );

    memset( self->data, 0, self->width*self->height*self->depth );


	{
    // This is a special region that is used for background and underlined
    // decorations of glyphs
    int n = 4;
    //unsigned char buffer[n*n];
	unsigned char buffer[16];
    memset(buffer, 255, n*n);
	{
    Region r = texture_atlas_get_region( self, n, n );
    texture_atlas_set_region( self, r.x, r.y, r.width, r.height, buffer, 1);
    self->black.x     = r.x + 1;
    self->black.y     = r.y + 1;
    self->black.width = r.width - 2;
    self->black.height= r.height - 2;
	}
	}
	}
}
int main() 
{
	struct vector_t vec;
	struct vector_t vec2;
	int i;
	printf("Original vector test\n");
	vector_init(&vec);
	printf("Pushing into vector\n");

	for(i=0; i<10; i++)
	{
		vector_push_back(&vec, i);
		printf("Index: %d\n", vector_get_size(vec));
	}

	printf("Popping out of vector\n");

	for(i=0; i<10; i++)
	{
		vector_pop_back(&vec);
		printf("Index: %d\n", vector_get_size(vec));
	}

	vector_copy(&vec, &vec2);
	vector_destroy(&vec);

	printf("Copied vector test\n");
	printf("Pushing in vector\n");

	for(i=0; i<10; i++)
	{
		vector_push_back(&vec2, i);
		printf("Index: %d\n", vector_get_size(vec2));
	}

	printf("Popping out of vector\n");

	for(i=0; i<10; i++)
	{
		vector_pop_back(&vec2);
		printf("Index: %d\n", vector_get_size(vec2));
	}
	
	vector_destroy(&vec2);
return 0;
}
Exemplo n.º 21
0
static void add_domain(size_t start, size_t size, const char *name)
{
  struct mem_domain *domain = vector_push_back(&domains, 1, NULL);
  domain->start = start;
  domain->size = size;
  domain->name = name;
  domain->view_offset = 0;
}
Exemplo n.º 22
0
/**
 Wczytuje cały input
 @return vector znaków, które wczytano
 */
vector * read_input(void)
{
	vector *buffer = vector_new(sizeof(wchar_t), BUFFER_START_SIZE);
	wchar_t c;
	while((c = getwc(stdin)) != (wchar_t)WEOF)
		vector_push_back(buffer, &c);
	return buffer;
}
Exemplo n.º 23
0
void test_vector()
{
   size_t arr[10], arr2[10];
   size_t i, j;
   vector vec;

   j = 200;

   vector_init(&vec, &malloc, &free);

   for (i = 0; i < 10; ++i)
   {
      arr[i] = i;

      vector_push_back(&vec, &arr[i]);

   }

   for (i = 0; i < 10; ++i)
   {
      arr2[i] = i + 10;

      vector_push_back(&vec, &arr2[i]);

   }

   vector_insert(&vec, &j, vec.size);
   vector_remove(&vec, 0);

   printf("-----\nVector testing\n-----\nSize: %d\nMax size: %d\nContents: ", vector_size(&vec), vector_max_size(&vec));

   for (i = 0; i < 20; ++i) printf("%d ", *(size_t*)vector_pop_back(&vec));

   vector_push_back(&vec, &j);

   printf("\nFront: %d\nBack: %d\n", *(size_t*)vector_front(&vec), *(size_t*)vector_back(&vec));

   vector_clear(&vec);

   printf("Vector cleared\nSize: %d\n", vec.size);

   vector_free(&vec);

   printf("\n");

}
Exemplo n.º 24
0
static _Bool parse_line(const char *line, const char **err_str)
{
  const char *p = line;
  /* skip whitespace, check for comment or empty line */
  while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n')
    ++p;
  if (*p == '#' || *p == 0)
    return 1;
  /* read name part */
  if (*p++ != '"')
    goto syntax_err;
  const char *name_s = p;
  const char *name_e = strchr(p, '"');
  if (!name_e || name_e == name_s)
    goto syntax_err;
  int name_l = name_e - name_s;
  p = name_e + 1;
  while (*p == ' ' || *p == '\t')
    ++p;
  /* read type part */
  const char *type_s = p;
  while (*p && *p != ' ' && *p != '\t')
    ++p;
  while (*p == ' ' || *p == '\t')
    ++p;
  const char *expr_s = p;
  /* construct entry */
  struct watchfile_entry entry;
  entry.type = -1;
  for (int i = 0; i < sizeof(watch_type_name) / sizeof(*watch_type_name);
       ++i)
  {
    int l = strlen(watch_type_name[i]);
    if (strncmp(type_s, watch_type_name[i], l) == 0) {
      entry.type = i;
      break;
    }
  }
  if (entry.type == -1)
    goto syntax_err;
  enum adex_error e = adex_parse(&entry.adex, expr_s);
  if (e) {
    *err_str = adex_error_name[e];
    goto err;
  }
  entry.name = malloc(name_l + 1);
  memcpy(entry.name, name_s, name_l);
  entry.name[name_l] = 0;
  entry.anim_state = 0;
  /* insert entry */
  vector_push_back(&watchfile_entries, 1, &entry);
  return 1;
syntax_err:
  *err_str = adex_error_name[ADEX_ERROR_SYNTAX];
  goto err;
err:
  return 0;
}
Exemplo n.º 25
0
void fdset_add(fdset *fds, vector *v, int fd, void *opaque, ev_callback_t callback) {
    select_event_t se;
    se.fd = fd;
    se.opaque = opaque;
    se.callback = callback;

    fdset_remove(fds, v, fd);
    vector_push_back(v, &se);
}
void vector_copy(struct vector_t* from, struct vector_t* to) {
	to->size = from->size;
	to->index = from->index;
	to->data = (int*) malloc(from->size * sizeof(int));
	int i;
	for (i = 0; i < from->size; i++) {
		vector_push_back(to, from->data[i]);
	}
}
Exemplo n.º 27
0
// ----------------------------------------------------------------------------
void
vertex_buffer_push_back_index ( vertex_buffer_t *self,
                                GLuint index )
{
    assert( self );

    self->dirty = 1;
    vector_push_back( self->indices, &index );
}
Exemplo n.º 28
0
void test1(void)
{
    vector_t vec = vector_create2(0, 4);
    int value = 1;
    for (int i = 0; i < 1000; i++)
        vector_push_back(vec, &value);
    vector_foreach(vec, test1_walker, NULL);
    vector_destroy(vec);
}
Exemplo n.º 29
0
// ----------------------------------------------------------------------------
void
vertex_buffer_push_back_vertex ( vertex_buffer_t *self,
                                 void *vertex )
{
    assert( self );

    self->dirty = 1;
    vector_push_back( self->vertices, vertex );
}
Exemplo n.º 30
0
static int enqueue_helper_request(queue_entry_t * qe)
{
	int r;
	Dprintf("%s(%d, \"%s\")\n", __FUNCTION__, qe->action, qe->mount->fstitch_path);
	mutex_lock(&helper.mutex);
	r = vector_push_back(helper.queue, qe);
	mutex_unlock(&helper.mutex);
	return r;
}