Пример #1
0
/*!
   \brief Add new line to updated

   \param Plus pointer to Plus_head structure
   \param line line id
   \param offset line offset (negative offset is ignored)
 */
void dig_line_add_updated(struct Plus_head *Plus, int line)
{
    int i;
    
    G_debug(3, "dig_line_add_updated(): line = %d", line);

    /* Check if already in list */
    for (i = 0; i < Plus->uplist.n_uplines; i++) {
	if (Plus->uplist.uplines[i] == line) {
            G_debug(3, "\tskipped");
	    return;
        }
    }
    
    /* Alloc space if needed */
    if (Plus->uplist.n_uplines == Plus->uplist.alloc_uplines) {
	Plus->uplist.alloc_uplines += 1000;
	Plus->uplist.uplines =
	    (int *)G_realloc(Plus->uplist.uplines,
			     Plus->uplist.alloc_uplines * sizeof(int));
	Plus->uplist.uplines_offset =
	    (off_t *)G_realloc(Plus->uplist.uplines_offset,
			     Plus->uplist.alloc_uplines * sizeof(off_t));
    }

    Plus->uplist.uplines[Plus->uplist.n_uplines] = line;
    Plus->uplist.n_uplines++;
}
Пример #2
0
/*!
   \brief Add new line to updated

   \param Plus pointer to Plus_head structure
   \param line line id
   \param offset line offset (negative offset is ignored)
 */
void dig_line_add_updated(struct Plus_head *Plus, int line, off_t offset)
{
    int i;
    
    G_debug(3, "dig_line_add_updated(): line = %d", line);

    /* undo/redo in the digitizer needs all steps, 
     * disable check */
#if 0
    /* Check if already in list */
    for (i = 0; i < Plus->uplist.n_uplines; i++) {
	if (Plus->uplist.uplines[i] == line) {
            G_debug(3, "\tskipped");
	    return;
        }
    }
#endif
    
    /* Alloc space if needed */
    if (Plus->uplist.n_uplines == Plus->uplist.alloc_uplines) {
	Plus->uplist.alloc_uplines += 1000;
	Plus->uplist.uplines =
	    (int *)G_realloc(Plus->uplist.uplines,
			     Plus->uplist.alloc_uplines * sizeof(int));
	Plus->uplist.uplines_offset =
	    (off_t *)G_realloc(Plus->uplist.uplines_offset,
			     Plus->uplist.alloc_uplines * sizeof(off_t));
    }

    Plus->uplist.uplines[Plus->uplist.n_uplines] = line;
    Plus->uplist.uplines_offset[Plus->uplist.n_uplines] = offset;
    Plus->uplist.n_uplines++;
}
Пример #3
0
static int draw_cell(int A_row,
		     const void *array,
		     struct Colors *colors, RASTER_MAP_TYPE data_type)
{
    static unsigned char *red, *grn, *blu, *set;
    static int nalloc;

    int ncols = src[0][1] - src[0][0];
    int i;

    if (nalloc < ncols) {
	nalloc = ncols;
	red = G_realloc(red, nalloc);
	grn = G_realloc(grn, nalloc);
	blu = G_realloc(blu, nalloc);
	set = G_realloc(set, nalloc);
    }

    Rast_lookup_colors(array, red, grn, blu, set, ncols, colors,
			   data_type);

    if (D__overlay_mode)
	for (i = 0; i < ncols; i++) {
	    set[i] = Rast_is_null_value(array, data_type);
	    array = G_incr_void_ptr(array, Rast_cell_size(data_type));
	}

    A_row =
	COM_raster(ncols, A_row, red, grn, blu, D__overlay_mode ? set : NULL);

    return (A_row < src[1][1])
	? A_row : -1;
}
Пример #4
0
/*!
   \brief Convert ordered array of integers to cat_list structure.

   \param vals array of integers
   \param nvals number of values
   \param[in,out] list pointer to cat_list structure

   \return number of ranges
 */
int Vect_array_to_cat_list(const int *vals, int nvals, struct cat_list *list)
{
    int i, range;

    G_debug(1, "Vect_array_to_cat_list()");
    range = -1;
    for (i = 0; i < nvals; i++) {
	if (i == 0 || (vals[i] - list->max[range]) > 1) {
	    range++;
	    if (range == list->alloc_ranges) {
		list->alloc_ranges += 1000;
		list->min = (int *)G_realloc((void *)list->min,
					     list->alloc_ranges *
					     sizeof(int));
		list->max =
		    (int *)G_realloc((void *)list->max,
				     list->alloc_ranges * sizeof(int));
	    }
	    list->min[range] = vals[i];
	    list->max[range] = vals[i];
	}
	else {
	    list->max[range] = vals[i];
	}
    }

    list->n_ranges = range + 1;

    return (list->n_ranges);
}
Пример #5
0
int I_new_control_point(struct Control_Points *cp,
			double e1, double n1, double e2, double n2,
			int status)
{
    int i;
    unsigned int size;

    if (status < 0)
	return 1;
    i = (cp->count)++;
    size = cp->count * sizeof(double);
    cp->e1 = (double *)G_realloc(cp->e1, size);
    cp->e2 = (double *)G_realloc(cp->e2, size);
    cp->n1 = (double *)G_realloc(cp->n1, size);
    cp->n2 = (double *)G_realloc(cp->n2, size);
    size = cp->count * sizeof(int);
    cp->status = (int *)G_realloc(cp->status, size);

    cp->e1[i] = e1;
    cp->e2[i] = e2;
    cp->n1[i] = n1;
    cp->n2[i] = n2;
    cp->status[i] = status;

    return 0;
}
Пример #6
0
int G_rasprintf(char **out, size_t *size, const char *fmt, ...)
{
    va_list ap;
    int count;
    char *buf = *out;
    size_t osize = *size;

    if (osize < strlen(fmt) + 50) {
	osize = strlen(fmt) + 50;
	buf = G_realloc(buf, osize);
    }

    for (;;) {
	va_start(ap, fmt);
	count = vsnprintf(buf, osize, fmt, ap);
	va_end(ap);
	if (count >= 0 && count < osize)
	    break;
	if (count > -1)
	    osize = count + 1;
	else
	    osize *= 2;
	
	buf = G_realloc(buf, osize);
    }

    *out = buf;
    *size = osize;

    return count;
}
Пример #7
0
int G_vasprintf(char **out, const char *fmt, va_list ap)
{
#ifdef HAVE_ASPRINTF
    return vasprintf(out, fmt, ap);
#else
    size_t size = strlen(fmt) + 50;
    char *buf = G_malloc(size);
    int count;

    for (;;) {
	/* BUG: according to man vsnprintf,
	 * va_start() should be called immediately before vsnprintf(),
	 * and va_end() immediately after vsnprintf()
	 * otherwise there will be memory corruption */
	count = vsnprintf(buf, size, fmt, ap);
	if (count >= 0 && count < size)
	    break;
	size *= 2;
	buf = G_realloc(buf, size);
    }

    buf = G_realloc(buf, count + 1);
    *out = buf;

    return count;
#endif /* HAVE_ASPRINTF */
}
Пример #8
0
int
I_new_ref_point(struct Ortho_Photo_Points *cp, double e1, double n1,
		double e2, double n2, int status)
{
    int i;
    size_t size;

    /*fprintf (stderr, "Try to new_ref_point \n"); */
    if (status < 0)
	return 0;
    i = (cp->count)++;
    size = cp->count * sizeof(double);
    cp->e1 = (double *)G_realloc(cp->e1, size);
    cp->e2 = (double *)G_realloc(cp->e2, size);
    cp->n1 = (double *)G_realloc(cp->n1, size);
    cp->n2 = (double *)G_realloc(cp->n2, size);
    size = cp->count * sizeof(int);
    cp->status = (int *)G_realloc(cp->status, size);

    cp->e1[i] = e1;
    cp->e2[i] = e2;
    cp->n1[i] = n1;
    cp->n2[i] = n2;
    cp->status[i] = status;

    return 0;
}
Пример #9
0
void newpoint(double z, double east, double north, int noindex)
{
    int row, column;

    row = (int)((window.north - north) / window.ns_res);
    column = (int)((east - window.west) / window.ew_res);

    if (!noindex) {
        if (row < 0 || row >= window.rows || column < 0 ||
                column >= window.cols) ;
        else {			/* Ignore sites outside current region as can't be indexed */

            points[row][column] =
                (struct Point *)G_realloc(points[row][column],
                                          (1 +
                                           npoints_currcell[row][column]) *
                                          sizeof(struct Point));
            points[row][column][npoints_currcell[row][column]].north = north;
            points[row][column][npoints_currcell[row][column]].east = east;
            points[row][column][npoints_currcell[row][column]].z = z;
            npoints_currcell[row][column]++;
            npoints++;
        }
    }
    else {
        noidxpoints = (struct Point *)G_realloc(noidxpoints,
                                                (1 +
                                                        npoints) *
                                                sizeof(struct Point));
        noidxpoints[npoints].north = north;
        noidxpoints[npoints].east = east;
        noidxpoints[npoints].z = z;
        npoints++;
    }
}
Пример #10
0
/* Add item to box list, does not check for duplicates */
int dig_boxlist_add(struct boxlist *list, int id, struct bound_box box)
{
    if (list->n_values == list->alloc_values) {
	size_t size = (list->n_values + 1000) * sizeof(int);
	void *p = G_realloc((void *)list->id, size);

	if (p == NULL)
	    return 0;
	list->id = (int *)p;

	if (list->have_boxes) {
	    size = (list->n_values + 1000) * sizeof(struct bound_box);
	    p = G_realloc((void *)list->box, size);

	    if (p == NULL)
		return 0;
	    list->box = (struct bound_box *)p;
	}

	list->alloc_values = list->n_values + 1000;
    }

    list->id[list->n_values] = id;
    if (list->have_boxes)
	list->box[list->n_values] = box;
    list->n_values++;

    return 1;
}
Пример #11
0
void add_coor(SYMBCHAIN *chain, double x, double y)
{
    G_debug(5, "    add_coor %f, %f", x, y);
    if (chain->scount == chain->salloc) {
	chain->salloc += 10;
	chain->sx = (double *)G_realloc(chain->sx, chain->salloc * sizeof(double));
	chain->sy = (double *)G_realloc(chain->sy, chain->salloc * sizeof(double));
    }
    chain->sx[chain->scount] = x;
    chain->sy[chain->scount] = y;
    chain->scount++;
}
Пример #12
0
int loadSiteCoordinates(struct Map_info *Map, struct Point **points, int region,
			struct Cell_head *window, int field, struct cat_list *cat_list)
{
    int i, pointIdx;
    struct line_pnts *sites;
    struct line_cats *cats;
    struct bound_box box;
    int type;

    sites = Vect_new_line_struct();
    cats = Vect_new_cats_struct();

    *points = NULL;
    pointIdx = 0;
    
    /* copy window to box */
    Vect_region_box(window, &box);

    while ((type = Vect_read_next_line(Map, sites, cats)) > -1) {

	if (type != GV_POINT && !(type & GV_LINES))
	    continue;

	if (field > 0 && !Vect_cats_in_constraint(cats, field, cat_list))
	    continue;
	
	for (i = 0; i < sites->n_points; i++) {
	    G_debug(4, "Point: %f|%f|%f", sites->x[i], sites->y[i],
		    sites->z[i]);
	    
	    if (region && !Vect_point_in_box(sites->x[i], sites->y[i], sites->z[i], &box))
		continue;
	    
	    G_debug(4, "Point in the box");

	    if ((pointIdx % ALLOC_CHUNK) == 0)
		*points = (struct Point *) G_realloc(*points,
						     (pointIdx + ALLOC_CHUNK) * sizeof(struct Point));
	    
	    (*points)[pointIdx].x = sites->x[i];
	    (*points)[pointIdx].y = sites->y[i];
	    (*points)[pointIdx].z = sites->z[i];
	    pointIdx++;
	}
    }

    if (pointIdx > 0)
	*points = (struct Point *)G_realloc(*points,
					    (pointIdx + 1) * sizeof(struct Point));
    
    return pointIdx;
}
Пример #13
0
/*!
  \brief Draw raster row in RGB mode

  \param A_row row number
  \param r_raster red data buffer
  \param g_raster green data buffer
  \param b_raster blue data buffer
  \param r_colors colors used for red channel
  \param g_colors colors used for green channel
  \param b_colors colors used for blue channel
  \param r_type raster type used for red channel
  \param g_type raster type used for red channel
  \param b_type raster type used for red channel

  \return
*/
int D_draw_raster_RGB(int A_row,
		      const void *r_raster, const void *g_raster,
		      const void *b_raster, struct Colors *r_colors,
		      struct Colors *g_colors, struct Colors *b_colors,
		      RASTER_MAP_TYPE r_type, RASTER_MAP_TYPE g_type,
		      RASTER_MAP_TYPE b_type)
{
    static unsigned char *r_buf, *g_buf, *b_buf, *n_buf;
    static int nalloc;

    int r_size = Rast_cell_size(r_type);
    int g_size = Rast_cell_size(g_type);
    int b_size = Rast_cell_size(b_type);
    int ncols = src[0][1] - src[0][0];
    int i;

    /* reallocate color_buf if necessary */
    if (nalloc < ncols) {
	nalloc = ncols;
	r_buf = G_realloc(r_buf, nalloc);
	g_buf = G_realloc(g_buf, nalloc);
	b_buf = G_realloc(b_buf, nalloc);
	n_buf = G_realloc(n_buf, nalloc);
    }

    /* convert cell values to bytes */
    Rast_lookup_colors(r_raster, r_buf, n_buf, n_buf, n_buf, ncols,
			   r_colors, r_type);
    Rast_lookup_colors(g_raster, n_buf, g_buf, n_buf, n_buf, ncols,
			   g_colors, g_type);
    Rast_lookup_colors(b_raster, n_buf, n_buf, b_buf, n_buf, ncols,
			   b_colors, b_type);

    if (D__overlay_mode)
	for (i = 0; i < ncols; i++) {
	    n_buf[i] = (Rast_is_null_value(r_raster, r_type) ||
			Rast_is_null_value(g_raster, g_type) ||
			Rast_is_null_value(b_raster, b_type));

	    r_raster = G_incr_void_ptr(r_raster, r_size);
	    g_raster = G_incr_void_ptr(g_raster, g_size);
	    b_raster = G_incr_void_ptr(b_raster, b_size);
	}

    A_row = COM_raster(ncols, A_row, r_buf, g_buf, b_buf,
		       D__overlay_mode ? n_buf : NULL);

    return (A_row < src[1][1])
	? A_row : -1;
}
Пример #14
0
/* add point to line */
void add_point(SYMBEL * el, double x, double y)
{
    if (el->coor.line.count == el->coor.line.alloc) {
	el->coor.line.alloc += 10;
	el->coor.line.x =
	    (double *)G_realloc(el->coor.line.x,
				el->coor.line.alloc * sizeof(double));
	el->coor.line.y =
	    (double *)G_realloc(el->coor.line.y,
				el->coor.line.alloc * sizeof(double));
    }
    el->coor.line.x[el->coor.line.count] = x;
    el->coor.line.y[el->coor.line.count] = y;
    el->coor.line.count++;
}
Пример #15
0
/*!
  \brief Get list of color rules for Option->options
  
  \return allocated string buffer with options
*/
char *G_color_rules_options(void)
{
    char *list, **rules;
    const char *name;
    int size, len, nrules;
    int i, n;

    list = NULL;
    size = len = 0;

    rules = scan_rules(&nrules);
    
    for (i = 0; i < nrules; i++) {
        name = rules[i];
        n = strlen(name);

        if (size < len + n + 2) {
            size = len + n + 200;
            list = G_realloc(list, size);
        }

        if (len > 0)
            list[len++] = ',';

        memcpy(&list[len], name, n + 1);
        len += n;
    }

    G_free(rules);
    
    return list;
}
Пример #16
0
Файл: list.c Проект: caomw/grass
/* get list of running monitors */
void list_mon(char ***list, int *n)
{
    int i;
    const char *name;
    const char *env_prefix = "MONITOR_";
    int env_prefix_len;
    char **tokens;
    
    env_prefix_len = strlen(env_prefix);
    
    *list = NULL;
    *n    = 0;
    tokens = NULL;
    for (i = 0; (name = G_get_env_name(i)); i++) {
	if (strncmp(env_prefix, name, env_prefix_len) == 0) {
	    tokens = G_tokenize(name, "_");
	    if (G_number_of_tokens(tokens) != 3 ||
		strcmp(tokens[2], "ENVFILE") != 0)
		continue;
	    *list = G_realloc(*list, (*n + 1) * sizeof(char *));
	    /* GRASS variable names are upper case, but monitor names are lower
	     * case. */
	    (*list)[*n] = G_store_lower(tokens[1]);
	    (*n)++;
	    G_free_tokens(tokens);
	    tokens = NULL;
	}
    }
    
}
Пример #17
0
char *G_rc_path(const char *element, const char *item)
{
    size_t len;
    char *path, *ptr;

    assert(!(element == NULL && item == NULL));

    /* Simple item in top-level */
    if (element == NULL) {
	path = _make_toplevel();
    }
    else if (item == NULL) {
	return _make_sublevels(element);
    }
    else {
	path = _make_sublevels(element);
    }


    assert(*item != '.');
    assert(path != NULL);
    ptr = strchr(item, '/');	/* should not have slashes */
    assert(ptr == NULL);
    len = strlen(path) + strlen(item) + 2;
    if ((ptr = G_realloc(path, len)) == NULL) {
	G_free(path);
	return NULL;
    }
    path = ptr;
    ptr = strchr(path, '\0');
    sprintf(ptr, "/%s", item);

    return path;
}				/* G_rc_path */
Пример #18
0
static void _get_list(char ***list, int *count)
{
    char **a;
    int n;
    char *buf;

    *list = NULL;
    *count = 0;

    buf = _get_text_2();

    for (n = 0; *buf; n++) {
	if (n == 0)
	    a = G_malloc(sizeof(char *));
	else
	    a = G_realloc(a, (n + 1) * sizeof(char *));

	a[n] = G_strdup(buf);

	buf = _get_text_2();
    }

    *list = a;
    *count = n;
}
Пример #19
0
int set_cat(CELL result, CELL * cat, struct Categories *pcats)
{
    int i, n;
    static char *buf = NULL;
    static int len = 0;
    char *lbl;


    if (result == 0)
	return 1;

    n = 0;
    for (i = 0; i < nfiles; i++) {
	lbl = get_label(cat[i], &labels[i]);
	n += strlen(lbl) + 2;
    }
    if (len < n)
	buf = G_realloc(buf, len = n);

    *buf = 0;
    for (i = 0; i < nfiles; i++) {
	if (i)
	    strcat(buf, "; ");
	lbl = get_label(cat[i], &labels[i]);
	strcat(buf, lbl);
    }
    G_set_cat(result, buf, pcats);
    return 0;
}
Пример #20
0
static int add_to_list(int x, int y)
{
    int n, i;
    struct equiv_table *e_list_y;

    e_list_y = e_list + y;
    n = e_list_y->count;
    if (n == 0) {		/* first time through--start list */
	e_list_y->length = 20;	/* initial guess at storage needed */
	e_list_y->ptr = (int *)G_malloc(e_list_y->length * sizeof(int));
	*(e_list_y->ptr) = x;
	(e_list_y->count)++;
    }
    else {			/* list already started */

	for (i = 0; i < n; i++) {	/* check whether x is already *//*   in list */
	    if (*(e_list_y->ptr + i) == x)
		return (0);	/* if so, we don't need to add it */
	}

	if (n + 1 >= e_list_y->length) {	/* add more space for storage *//*   if necessary */
	    e_list_y->length += 10;
	    e_list_y->ptr =
		(int *)G_realloc(e_list_y->ptr,
				 e_list_y->length * sizeof(int));
	}

	*(e_list_y->ptr + n) = x;	/* add x to list */
	(e_list_y->count)++;
    }

    return (1);			/* indicate addition made */
}
Пример #21
0
static char *rules_list(void)
{
    char *list = NULL;
    int size = 0;
    int len = 0;
    int i;

    for (i = 0; i < nrules; i++) {
	const char *name = rules[i];
	int n = strlen(name);

	if (size < len + n + 2) {
	    size = len + n + 200;
	    list = G_realloc(list, size);
	}

	if (len > 0)
	    list[len++] = ',';

	memcpy(&list[len], name, n + 1);
	len += n;
    }

    return list;
}
Пример #22
0
struct SubSig *I_NewSubSig(struct SigSet *S, struct ClassSig *C)
{
    struct SubSig *Sp;
    int i;

    if (C->nsubclasses == 0)
	C->SubSig = (struct SubSig *)G_malloc(sizeof(struct SubSig));
    else
	C->SubSig = (struct SubSig *)G_realloc((char *)C->SubSig,
					       sizeof(struct SubSig) *
					       (C->nsubclasses + 1));

    Sp = &C->SubSig[C->nsubclasses++];
    Sp->used = 1;
    Sp->R = (double **)G_calloc(S->nbands, sizeof(double *));
    Sp->R[0] = (double *)G_calloc(S->nbands * S->nbands, sizeof(double));
    for (i = 1; i < S->nbands; i++)
	Sp->R[i] = Sp->R[i - 1] + S->nbands;
    Sp->Rinv = (double **)G_calloc(S->nbands, sizeof(double *));
    Sp->Rinv[0] = (double *)G_calloc(S->nbands * S->nbands, sizeof(double));
    for (i = 1; i < S->nbands; i++)
	Sp->Rinv[i] = Sp->Rinv[i - 1] + S->nbands;
    Sp->means = (double *)G_calloc(S->nbands, sizeof(double));
    Sp->N = 0;
    Sp->pi = 0;
    Sp->cnst = 0;
    return Sp;
}
Пример #23
0
static int try_get_colors(Colormap cmap, int nr, int ng, int nb)
{
    XColor xcolor;
    int n_pixels;
    int r, g, b;

    xpixels = (unsigned long *)G_realloc(xpixels,
					 nr * ng * nb *
					 sizeof(unsigned long));
    n_pixels = 0;

    xcolor.flags = DoRed | DoGreen | DoBlue;

    for (r = 0; r < nr; r++) {
	for (g = 0; g < ng; g++) {
	    for (b = 0; b < nb; b++) {
		xcolor.red = (unsigned short)(r * 0xFFFF / (nr - 1));
		xcolor.green = (unsigned short)(g * 0xFFFF / (ng - 1));
		xcolor.blue = (unsigned short)(b * 0xFFFF / (nb - 1));
		if (!XAllocColor(dpy, cmap, &xcolor)) {
		    XFreeColors(dpy, cmap, xpixels, n_pixels,
				(unsigned long)0);
		    return 0;
		}

		xpixels[n_pixels++] = xcolor.pixel;
	    }
	}
    }

    return 1;
}
Пример #24
0
/* add table to database */
int add_table(char *table, char *name)
{
    G_debug(2, "add_table(): table = %s name = %s", table, name);

    if (db.atables == db.ntables) {
        db.atables += 15;
        db.tables =
            (TABLE *) G_realloc(db.tables, db.atables * sizeof(TABLE));
    }

    strcpy(db.tables[db.ntables].name, table);

#ifdef __MINGW32__
    sprintf(db.tables[db.ntables].file, "%s\\%s", db.name, name);
#else
    sprintf(db.tables[db.ntables].file, "%s/%s", db.name, name);
#endif

    db.tables[db.ntables].alive = TRUE;
    db.tables[db.ntables].described = FALSE;
    db.tables[db.ntables].loaded = FALSE;
    db.tables[db.ntables].updated = FALSE;
    db.tables[db.ntables].cols = NULL;
    db.tables[db.ntables].rows = NULL;
    db.tables[db.ntables].acols = 0;
    db.tables[db.ntables].ncols = 0;
    db.tables[db.ntables].arows = 0;
    db.tables[db.ntables].nrows = 0;

    db.ntables++;

    return DB_OK;
}
Пример #25
0
static void ensure(struct buffer *b, size_t n)
{
    if (b->size <= b->len + n + 1) {
	b->size = b->len + n + INCREMENT;
	b->str = G_realloc(b->str, b->size);
    }
}
Пример #26
0
static int try_get_grays(Colormap cmap, int ny)
{
    XColor xcolor;
    int n_pixels;
    int y;

    xpixels = (unsigned long *)G_realloc(xpixels, ny * sizeof(unsigned long));
    n_pixels = 0;

    xcolor.flags = DoRed | DoGreen | DoBlue;

    for (y = 0; y < ny; y++) {
	unsigned short v = (unsigned short)(y * 0xFFFF / (ny - 1));

	xcolor.red = v;
	xcolor.green = v;
	xcolor.blue = v;

	if (!XAllocColor(dpy, cmap, &xcolor)) {
	    XFreeColors(dpy, cmap, xpixels, n_pixels, (unsigned long)0);
	    return y;
	}

	xpixels[n_pixels++] = xcolor.pixel;
    }

    return ny;
}
Пример #27
0
static void add_search_dir(const char *name)
{
    char envvar_name[256];
    char *fullname = NULL;

    if (sscanf(name, "${%255[^}]}", envvar_name) == 1) {
	char *envvar_value = getenv(envvar_name);

	/* N.B. If the envvar isn't set, directory is skipped completely */
	if (envvar_value)
	    G_asprintf(&fullname, "%s%s", envvar_value,
		       (name + strlen(envvar_name) + 3));
    }
    else
	fullname = G_store(name);

    if (fullname) {
	searchdirs = (char **)G_realloc(searchdirs,
					(numsearchdirs + 1) * sizeof(char *));
	searchdirs[numsearchdirs] = fullname;
	G_convert_dirseps_to_host(searchdirs[numsearchdirs]);
	numsearchdirs++;
    }

    return;
}
Пример #28
0
static void draw_bitmap(FT_Bitmap * bitmap, FT_Int x, FT_Int y)
{
    static unsigned char *buf;
    static int nalloc;
    int w, h;
    int bw = bitmap->width;
    int bh = bitmap->rows;
    const unsigned char *sbuf = bitmap->buffer;
    int offset, i, j;
    double x1, y1, x2, y2;

    x1 = x;
    y1 = y;
    x2 = x1 + bw;
    y2 = y1 + bh;

    w = x2 - x1;
    h = y2 - y1;
    if (w <= 0 || h <= 0)
	return;

    offset = ((int)y1 - y) * bw + (int)x1 - x;

    if (nalloc < w * h) {
	nalloc = w * h;
	buf = G_realloc(buf, nalloc);
    }

    for (j = 0; j < h; j++)
	for (i = 0; i < w; i++)
	    buf[j * w + i] = sbuf[offset + j * bw + i];

    COM_Pos_abs(x1, y1);
    COM_Bitmap(w, h, 128, buf);
}
Пример #29
0
/*!
   \brief Add node to updated

   \param Plus pointer to Plus_head structure
   \param node node id
 */
void dig_node_add_updated(struct Plus_head *Plus, int node)
{
    int i;

    G_debug(3, "dig_node_add_updated(): node = %d", node);

    /* Check if already in list */
    for (i = 0; i < Plus->uplist.n_upnodes; i++) {
	if (abs(Plus->uplist.upnodes[i]) == abs(node)) {
            G_debug(3, "\tskipped");
	    return;
        }
    }

    /* Alloc space if needed */
    if (Plus->uplist.n_upnodes == Plus->uplist.alloc_upnodes) {
	Plus->uplist.alloc_upnodes += 1000;
	Plus->uplist.upnodes =
	    (int *)G_realloc(Plus->uplist.upnodes,
			     Plus->uplist.alloc_upnodes * sizeof(int));
    }

    Plus->uplist.upnodes[Plus->uplist.n_upnodes] = node;
    Plus->uplist.n_upnodes++;
}
Пример #30
0
/*! Add new fringe

  \param data nviz data
  \param id surface id
  \param color color
  \param elev fringe elevation
  \param nw,ne,sw,se 1 (turn on) 0 (turn off)

  \return pointer to allocated fringe_data structure
  \return NULL on error
*/
struct fringe_data *Nviz_new_fringe(nv_data *data,
				    int id, unsigned long color,
				    double elev, int nw, int ne, int sw, int se)
{
    int num;
    int *surf;
    struct fringe_data *f;

    if (!GS_surf_exists(id)) {
	/* select first surface from the list */
	surf = GS_get_surf_list(&num);
	if (num < 1)
	    return NULL;
	id = surf[0];
	G_free(surf);
    }
     

    f = (struct fringe_data *) G_malloc(sizeof(struct fringe_data));
    f->id = id;
    f->color = color;
    f->elev = elev;
    f->where[0] = nw;
    f->where[1] = ne;
    f->where[2] = sw;
    f->where[3] = se;

    data->fringe = (struct fringe_data **) G_realloc(data->fringe, data->num_fringes + 1 * sizeof(struct fringe_data *));
    data->fringe[data->num_fringes++] = f;
    
    return f;
}