static struct narray * allocate_darray(ngraph_arg *arg) { struct narray *array, *ptr; int i; if (arg == NULL) { return NULL; } if (arg->num < 1) { return NULL; } array = arraynew(sizeof(double)); if (array == NULL) { return NULL; } for (i = 0; i < arg->num; i++) { ptr = arrayadd(array, &arg->ary[i].d); if (ptr == NULL) { arrayfree(array); return NULL; } } return array; }
static void add_str_with_int_to_array(struct menu_config *cfg, struct narray *conf) { char *buf; buf = g_strdup_printf("%s=%d", cfg->name, * (int *) cfg->data); if (buf) { arrayadd(conf, &buf); } }
static void add_str_to_array(struct narray *conf, char *str) { char *buf; buf = g_strdup(str); if (buf) { arrayadd(conf, &buf); } }
void gra2cairo_save_config(void) { char *buf; struct fontmap *fcur; struct narray conf; arrayinit(&conf, sizeof(char *)); if (gra2cairo_get_fontmap_num() == 0) { buf = g_strdup("font"); if (buf) { arrayadd(&conf, &buf); removeconfig(CAIROCONF, &conf); } } else { fcur = Gra2cairoConf->fontmap_list_root; while (fcur) { buf = g_strdup_printf("font=%s,%s%s%s", fcur->fontalias, fcur->fontname, (fcur->alternative) ? "," : "", CHK_STR(fcur->alternative)); if (buf) { arrayadd(&conf, &buf); } fcur = fcur->next; } replaceconfig(CAIROCONF, &conf); } /* for backward compatibility */ if (OldConfigExist) { buf = g_strdup("font_map"); if (buf) { arrayadd(&conf, &buf); removeconfig(CAIROCONF, &conf); } OldConfigExist = FALSE; } arraydel2(&conf); }
static void add_prm_str_to_array(struct menu_config *cfg, struct narray *conf) { char *buf, *prm; prm = CHK_STR(* (char **) cfg->data); buf = g_strdup_printf("%s=%s", cfg->name, prm); if (buf) { arrayadd(conf, &buf); } }
static void add_color_to_array(struct menu_config *cfg, struct narray *conf) { char *buf; buf = g_strdup_printf("%s=%02x%02x%02x", cfg->name, (int) (Menulocal.bg_r * 255), (int) (Menulocal.bg_g * 255), (int) (Menulocal.bg_b * 255)); if (buf) { arrayadd(conf, &buf); } }
static int curve_expand(double c[], double x0, double y0, diffunc gdiff, intpfunc gintpf, struct narray *expand_points) { double d, dx, dy, ddx, ddy, dd, x, y; int gx2, gy2; d = 0; while (d < 1) { gdiff(d, c, &dx, &dy, &ddx, &ddy, NULL); if (fabs(dx) + fabs(ddx) / 3 <= 1E-100) { dx = 1; } else { dx = sqrt(fabs(2 / (fabs(dx) + fabs(ddx) / 3))); } if (fabs(dy) + fabs(ddy) / 3 <= 1E-100) { dy = 1; } else { dy = sqrt(fabs(2 / (fabs(dy) + fabs(ddy) / 3))); } dd = (dx < dy) ? dx : dy; d += dd; if (d > 1) { d = 1; } gintpf(d, c, x0, y0, &x, &y, NULL); gx2 = nround(x); gy2 = nround(y); arrayadd(expand_points, &gx2); arrayadd(expand_points, &gy2); } return TRUE; }
static int agridinit(struct objlist *obj,N_VALUE *inst,N_VALUE *rval,int argc,char **argv) { int wid1,wid2,wid3,dot,grid; int r,g,b,br,bg,bb,ba; struct narray *style1; if (_exeparent(obj,(char *)argv[1],inst,rval,argc,argv)) return 1; wid1=5; wid2=10; wid3=20; r=0; g=255; b=255; br=255; bg=255; bb=255; ba=255; style1=arraynew(sizeof(int)); dot=150; grid=TRUE; arrayadd(style1,&dot); arrayadd(style1,&dot); if (_putobj(obj,"width1",inst,&wid1)) return 1; if (_putobj(obj,"width2",inst,&wid2)) return 1; if (_putobj(obj,"width3",inst,&wid3)) return 1; if (_putobj(obj,"style1",inst,style1)) return 1; if (_putobj(obj,"R",inst,&r)) return 1; if (_putobj(obj,"G",inst,&g)) return 1; if (_putobj(obj,"B",inst,&b)) return 1; if (_putobj(obj,"BR",inst,&br)) return 1; if (_putobj(obj,"BG",inst,&bg)) return 1; if (_putobj(obj,"BB",inst,&bb)) return 1; if (_putobj(obj,"BA",inst,&ba)) return 1; if (_putobj(obj,"grid_x",inst,&grid)) return 1; if (_putobj(obj,"grid_y",inst,&grid)) return 1; return 0; }
static void add_child_geometry_to_array(struct menu_config *cfg, struct narray *conf) { char *buf; int **data; struct child_win_stat *stat; stat = cfg->data; data = stat->stat; buf = g_strdup_printf("%s=%d,%d,%d,%d,%d", cfg->name, *data[0], *data[1], *data[2], *data[3], *data[4]); if (buf) { sub_window_save_geometry(stat->win); sub_window_save_visibility(stat->win); arrayadd(conf, &buf); } }
static void save_char_map_config(struct narray *conf) { char *title, *data, *buf; struct character_map_list *pcur; pcur = Menulocal.char_map; while (pcur) { title = CHK_STR(pcur->title); data = CHK_STR(pcur->data); buf = g_strdup_printf("character_map=%s,%s", title, data); if (buf) { arrayadd(conf, &buf); } pcur = pcur->next; } }
static void save_ext_driver_config(struct narray *conf) { char *buf, *driver, *ext, *option; struct extprinter *pcur; pcur = Menulocal.extprinterroot; while (pcur) { driver = CHK_STR(pcur->driver); ext = CHK_STR(pcur->ext); option= CHK_STR(pcur->option); buf = g_strdup_printf("ext_driver=%s,%s,%s,%s", pcur->name, driver, ext, option); if (buf) { arrayadd(conf, &buf); } pcur = pcur->next; } }
static void save_script_config(struct narray *conf) { char *buf, *script, *option, *description; struct script *scur; scur = Menulocal.scriptroot; while (scur) { script = CHK_STR(scur->script); option = CHK_STR(scur->option); description = CHK_STR(scur->description); buf = g_strdup_printf("script=%s,%s,%s,%s", scur->name, script, description, option); if (buf) { arrayadd(conf, &buf); } scur = scur->next; } }
static int regexp_match(struct objlist *obj,N_VALUE *inst,N_VALUE *rval,int argc,char **argv) { struct oregexp_local *local; GMatchInfo *info; int r; char *str, **match; str = (char *) argv[2]; rval->i = 0; _getobj(obj, "_local", inst, &local); if (local->regexp == NULL) { return 1; } del_array_element(local->array); if (str == NULL || str[0] == '\0') { return 1; } info = NULL; r = g_regex_match(local->regexp, str, 0, &info); if (! r) { g_match_info_free(info); return 1; } while (g_match_info_matches(info)) { match = g_match_info_fetch_all(info); arrayadd(local->array, &match); g_match_info_next(info, NULL); } g_match_info_free(info); rval->i = arraynum(local->array); return 0; }
static void add_geometry_to_array(struct menu_config *cfg, struct narray *conf) { char *buf; gint x, y, w, h; get_window_geometry(TopLevel, &x, &y, &w, &h); Menulocal.menux = x; Menulocal.menuy = y; Menulocal.menuwidth = w; Menulocal.menuheight = h; buf = g_strdup_printf("%s=%d,%d,%d,%d", cfg->name, Menulocal.menux, Menulocal.menuy, Menulocal.menuwidth, Menulocal.menuheight); if (buf) { arrayadd(conf, &buf); } }
static int arrowbbox(struct objlist *obj, N_VALUE *inst, N_VALUE *rval, int argc, char **argv) { int minx, miny, maxx, maxy; int x, y, num, num2, type, intp, stroke, fill; struct narray *points; int *pdata; struct narray *array; int i, j, width; int headlen, headwidth; int head; int *points2; int x0, y0, x1, y1, x2, y2, x3, y3; int ap[6], ap2[6]; array = rval->array; if (arraynum(array) != 0) { return 0; } _getobj(obj, "type", inst, &type); _getobj(obj, "fill", inst, &fill); _getobj(obj, "stroke", inst, &stroke); if (fill == 0 && stroke == 0) { return 0; } if (type == PATH_TYPE_CURVE) { _getobj(obj, "interpolation", inst, &intp); _getobj(obj, "_points", inst, &points); if (arraynum(points) == 0) { curve_expand_points(obj, inst, intp, points); } } else { _getobj(obj, "points", inst, &points); } _getobj(obj, "width", inst, &width); _getobj(obj, "arrow", inst, &head); _getobj(obj, "arrow_length", inst, &headlen); _getobj(obj, "arrow_width", inst, &headwidth); num = arraynum(points) / 2; pdata = arraydata(points); points2 = g_malloc(sizeof(int) * num * 2); if (points2 == NULL) { return 1; } j = 0; x1 = y1 = 0; for (i = 0; i < num; i++) { x0 = pdata[2 * i]; y0 = pdata[2 * i + 1]; if (i == 0 || x0 != x1 || y0 != y1) { points2[2 * j] = x0; points2[2 * j + 1] = y0; j++; x1 = x0; y1 = y0; } } num2 = j; if (num2 < 2) { g_free(points2); return 0; } x0 = points2[0]; y0 = points2[1]; x1 = points2[2]; y1 = points2[3]; x2 = points2[2 * num2 - 4]; y2 = points2[2 * num2 - 3]; x3 = points2[2 * num2 - 2]; y3 = points2[2 * num2 - 1]; g_free(points2); if (head==ARROW_POSITION_BEGIN || head==ARROW_POSITION_BOTH) { get_arrow_pos(NULL, 0, width, headlen, headwidth, x0, y0, x1, y1, ap); } if (head==ARROW_POSITION_END || head==ARROW_POSITION_BOTH) { get_arrow_pos(NULL, 0, width, headlen, headwidth, x3, y3, x2, y2, ap2); } if (array == NULL && (array = arraynew(sizeof(int))) == NULL) { return 1; } maxx = minx = pdata[0]; maxy = miny = pdata[1]; arrayadd(array, &(pdata[0])); arrayadd(array, &(pdata[1])); for (i = 1; i < num; i++) { x = pdata[i * 2]; y = pdata[i * 2 + 1]; if (x < minx) minx = x; if (x > maxx) maxx = x; if (y < miny) miny = y; if (y > maxy) maxy = y; } if (type == PATH_TYPE_CURVE) { _getobj(obj, "points", inst, &points); num = arraynum(points) / 2; pdata = arraydata(points); } for (i = 1; i < num; i++) { x = pdata[i * 2]; y = pdata[i * 2 + 1]; arrayadd(array, &x); arrayadd(array, &y); } if (stroke) { if (head == ARROW_POSITION_BEGIN || head == ARROW_POSITION_BOTH) { for (i = 0; i < 3; i++) { if (ap[i * 2] < minx) minx = ap[i * 2]; if (ap[i * 2] > maxx) maxx = ap[i * 2]; if (ap[i * 2 + 1] < miny) miny = ap[i * 2 + 1]; if (ap[i * 2 + 1] > maxy) maxy = ap[i * 2 + 1]; } } if (head == ARROW_POSITION_END || head == ARROW_POSITION_BOTH) { for (i = 0; i < 3 ; i++) { if (ap2[i * 2] < minx) minx = ap2[i * 2]; if (ap2[i * 2] > maxx) maxx = ap2[i * 2]; if (ap2[i * 2 + 1] < miny) miny = ap2[i * 2+ 1]; if (ap2[i * 2 + 1] > maxy) maxy = ap2[i * 2 + 1]; } } minx -= width / 2; miny -= width / 2; maxx += width / 2; maxy += width / 2; } arrayins(array, &(maxy), 0); arrayins(array, &(maxx), 0); arrayins(array, &(miny), 0); arrayins(array, &(minx), 0); if (arraynum(array) == 0) { arrayfree(array); rval->array = NULL; return 1; } rval->array = array; return 0; }
static int curve_expand_points(struct objlist *obj, N_VALUE *inst, int intp, struct narray *expand_points) { int i, j, num, bsize, spcond, x, y; struct narray *points; double c[8]; double *buf; double bs1[7], bs2[7], bs3[4], bs4[4]; int *pdata; _getobj(obj, "points", inst, &points); num = arraynum(points)/2; pdata = arraydata(points); arrayclear(expand_points); switch (intp) { case INTERPOLATION_TYPE_SPLINE: case INTERPOLATION_TYPE_SPLINE_CLOSE: if (num < 2) return 0; bsize = num + 1; buf = g_malloc(sizeof(double) * 9 * bsize); if (buf == NULL) return 1; for (i = 0; i < bsize; i++) buf[i]=i; for (i = 0; i < num; i++) { buf[bsize + i] = pdata[i * 2]; buf[bsize * 2 + i] = pdata[i * 2 + 1]; } if (intp == INTERPOLATION_TYPE_SPLINE) { spcond = SPLCND2NDDIF; } else { spcond = SPLCNDPERIODIC; if (buf[num - 1 + bsize] != buf[bsize] || buf[num - 1 + 2 * bsize] != buf[2 * bsize]) { buf[num + bsize] = buf[bsize]; buf[num + 2 * bsize] = buf[2 * bsize]; num++; } } if (spline(buf, buf + bsize, buf + 3 * bsize, buf + 4 * bsize, buf + 5 * bsize, num, spcond, spcond, 0, 0)) { g_free(buf); error(obj, ERRSPL); return 1; } if (spline(buf, buf + 2 * bsize, buf + 6 * bsize, buf + 7 * bsize, buf + 8 * bsize, num, spcond, spcond, 0, 0)) { g_free(buf); error(obj, ERRSPL); return 1; } x = nround(buf[bsize]); y = nround(buf[bsize * 2]); arrayadd(expand_points, &x); arrayadd(expand_points, &y); for (i = 0; i < num - 1; i++) { for (j = 0; j < 6; j++) { c[j] = buf[i + (j + 3) * bsize]; } if (! curve_expand(c, buf[i + bsize], buf[i + 2 * bsize], splinedif, splineint, expand_points)) { break; } } g_free(buf); break; case INTERPOLATION_TYPE_BSPLINE: if (num < 7) { return 0; } for (i = 0; i < 7; i++) { bs1[i] = pdata[i * 2]; bs2[i] = pdata[i * 2 + 1]; } for (j = 0; j < 2; j++) { bspline(j + 1, bs1 + j, c); bspline(j + 1, bs2 + j, c + 4); if (j == 0) { x = nround(c[0]); y = nround(c[4]); arrayadd(expand_points, &x); arrayadd(expand_points, &y); } if (! curve_expand(c, c[0], c[4], bsplinedif, bsplineint, expand_points)) { return 0; } } for (; i < num; i++) { for (j = 1; j < 7; j++) { bs1[j - 1] = bs1[j]; bs2[j - 1] = bs2[j]; } bs1[6] = pdata[i*2]; bs2[6] = pdata[i*2+1]; bspline(0, bs1 + 1, c); bspline(0, bs2 + 1, c + 4); if (! curve_expand(c, c[0], c[4], bsplinedif, bsplineint, expand_points)) { return 0; } } for (j = 0; j < 2; j++) { bspline(j + 3, bs1 + j + 2, c); bspline(j + 3, bs2 + j + 2, c + 4); if (! curve_expand(c, c[0], c[4], bsplinedif, bsplineint, expand_points)) { return 0; } } break; case INTERPOLATION_TYPE_BSPLINE_CLOSE: if (num < 4) { return 0; } for (i = 0; i < 4; i++) { bs1[i] = pdata[i * 2]; bs3[i] = pdata[i * 2]; bs2[i] = pdata[i * 2 + 1]; bs4[i] = pdata[i * 2 + 1]; } bspline(0, bs1, c); bspline(0, bs2, c + 4); x = nround(c[0]); y = nround(c[4]); arrayadd(expand_points, &x); arrayadd(expand_points, &y); if (! curve_expand(c, c[0], c[4], bsplinedif, bsplineint, expand_points)) { return 0; } for (; i < num; i++) { for (j = 1; j < 4; j++) { bs1[j - 1] = bs1[j]; bs2[j - 1] = bs2[j]; } bs1[3] = pdata[i * 2]; bs2[3] = pdata[i * 2 + 1]; bspline(0, bs1, c); bspline(0, bs2, c + 4); if (! curve_expand(c, c[0], c[4], bsplinedif, bsplineint, expand_points)) { return 0; } } for (j = 0; j < 3; j++) { bs1[4 + j] = bs3[j]; bs2[4 + j] = bs4[j]; bspline(0, bs1 + j + 1, c); bspline(0, bs2 + j + 1, c + 4); if (! curve_expand(c, c[0], c[4], bsplinedif, bsplineint, expand_points)) { return 0; } } break; } return 0; }
void tpl_ctx_add_searchpath(tpl_ctx *t, const char *path) { arrayadd(&(t->searchpaths), strdup(path)); }