static void prepare_call(int calltype) { struct udvt_entry *udv; int argindex; if (calltype == 2) { call_argc = 0; while (!END_OF_COMMAND && call_argc <= 9) { call_args[call_argc] = try_to_get_string(); if (!call_args[call_argc]) { int save_token = c_token; /* This catches call "file" STRINGVAR (expression) */ if (type_udv(c_token) == STRING) { call_args[call_argc] = gp_strdup(add_udv(c_token)->udv_value.v.string_val); c_token++; /* Evaluates a parenthesized expression and store the result in a string */ } else if (equals(c_token, "(")) { char val_as_string[32]; struct value a; const_express(&a); switch(a.type) { case CMPLX: /* FIXME: More precision? Some way to provide a format? */ sprintf(val_as_string, "%g", a.v.cmplx_val.real); call_args[call_argc] = gp_strdup(val_as_string); break; default: int_error(save_token, "Unrecognized argument type"); break; case INTGR: sprintf(val_as_string, "%d", a.v.int_val); call_args[call_argc] = gp_strdup(val_as_string); break; } /* old (pre version 5) style wrapping of bare tokens as strings */ /* is still useful for passing unquoted numbers */ } else { m_capture(&call_args[call_argc], c_token, c_token); c_token++; } } call_argc++; } lf_head->c_token = c_token; if (!END_OF_COMMAND) int_error(++c_token, "too many arguments for 'call <file>'"); } else if (calltype == 5) { /* lf_push() moved our call arguments from call_args[] to lf->call_args[] */ /* call_argc was determined at program entry */ for (argindex = 0; argindex < 10; argindex++) { call_args[argindex] = lf_head->call_args[argindex]; lf_head->call_args[argindex] = NULL; /* just to be safe */ } } else { /* "load" command has no arguments */ call_argc = 0; } /* Old-style "call" arguments were referenced as $0 ... $9 and $# */ /* New-style has ARG0 = script-name, ARG1 ... ARG9 and ARGC */ /* FIXME: If we defined these on entry, we could use get_udv* here */ udv = add_udv_by_name("ARGC"); Ginteger(&(udv->udv_value), call_argc); udv->udv_undef = FALSE; udv = add_udv_by_name("ARG0"); gpfree_string(&(udv->udv_value)); Gstring(&(udv->udv_value), gp_strdup(lf_head->name)); udv->udv_undef = FALSE; for (argindex = 1; argindex <= 9; argindex++) { char *arg = gp_strdup(call_args[argindex-1]); udv = add_udv_by_name(argname[argindex]); gpfree_string(&(udv->udv_value)); Gstring(&(udv->udv_value), arg ? arg : gp_strdup("")); udv->udv_undef = FALSE; } }
/* <fillstyle> = {empty | solid {<density>} | pattern {<n>}} {noborder | border {<lt>}} */ void parse_fillstyle(struct fill_style_type *fs, int def_style, int def_density, int def_pattern, t_colorspec def_bordertype) { TBOOLEAN set_fill = FALSE; TBOOLEAN set_param = FALSE; TBOOLEAN transparent = FALSE; /* Set defaults */ fs->fillstyle = def_style; fs->filldensity = def_density; fs->fillpattern = def_pattern; fs->border_color = def_bordertype; if (END_OF_COMMAND) return; if (!equals(c_token, "fs") && !almost_equals(c_token, "fill$style")) return; c_token++; while (!END_OF_COMMAND) { if (almost_equals(c_token, "trans$parent")) { transparent = TRUE; c_token++; } if (almost_equals(c_token, "e$mpty")) { fs->fillstyle = FS_EMPTY; c_token++; } else if (almost_equals(c_token, "s$olid")) { fs->fillstyle = transparent ? FS_TRANSPARENT_SOLID : FS_SOLID; set_fill = TRUE; c_token++; } else if (almost_equals(c_token, "p$attern")) { fs->fillstyle = transparent ? FS_TRANSPARENT_PATTERN : FS_PATTERN; set_fill = TRUE; c_token++; } if (END_OF_COMMAND) continue; else if (almost_equals(c_token, "bo$rder")) { fs->border_color.type = TC_DEFAULT; c_token++; if (equals(c_token,"-") || isanumber(c_token)) { fs->border_color.type = TC_LT; fs->border_color.lt = int_expression() - 1; } else if (equals(c_token,"lc") || almost_equals(c_token,"linec$olor")) { parse_colorspec(&fs->border_color, TC_Z); } else if (equals(c_token,"rgb") || equals(c_token,"lt") || almost_equals(c_token,"linet$ype")) { c_token--; parse_colorspec(&fs->border_color, TC_Z); } continue; } else if (almost_equals(c_token, "nobo$rder")) { fs->border_color.type = TC_LT; fs->border_color.lt = LT_NODRAW; c_token++; continue; } /* We hit something unexpected */ if (!set_fill || set_param) break; if (!(isanumber(c_token) || type_udv(c_token) == INTGR || type_udv(c_token) == CMPLX)) break; if (fs->fillstyle == FS_SOLID || fs->fillstyle == FS_TRANSPARENT_SOLID) { /* user sets 0...1, but is stored as an integer 0..100 */ fs->filldensity = 100.0 * real_expression() + 0.5; if (fs->filldensity < 0) fs->filldensity = 0; if (fs->filldensity > 100) fs->filldensity = 100; set_param = TRUE; } else if (fs->fillstyle == FS_PATTERN || fs->fillstyle == FS_TRANSPARENT_PATTERN) { fs->fillpattern = int_expression(); if (fs->fillpattern < 0) fs->fillpattern = 0; set_param = TRUE; } } }
void parse_fillstyle(struct fill_style_type *fs, int def_style, int def_density, int def_pattern, t_colorspec def_bordertype) { TBOOLEAN set_fill = FALSE; TBOOLEAN set_border = FALSE; TBOOLEAN transparent = FALSE; /* Set defaults */ fs->fillstyle = def_style; fs->filldensity = def_density; fs->fillpattern = def_pattern; fs->border_color = def_bordertype; if (END_OF_COMMAND) return; if (!equals(c_token, "fs") && !almost_equals(c_token, "fill$style")) return; c_token++; while (!END_OF_COMMAND) { int i; if (almost_equals(c_token, "trans$parent")) { transparent = TRUE; c_token++; continue; } i = lookup_table(fs_opt_tbl, c_token); switch (i) { default: break; case FS_EMPTY: case FS_SOLID: case FS_PATTERN: if (set_fill && fs->fillstyle != i) int_error(c_token, "conflicting option"); fs->fillstyle = i; set_fill = TRUE; c_token++; if (isanumber(c_token) || type_udv(c_token) == INTGR || type_udv(c_token) == CMPLX) { if (fs->fillstyle == FS_SOLID) { /* user sets 0...1, but is stored as an integer 0..100 */ fs->filldensity = 100.0 * real_expression() + 0.5; if (fs->filldensity < 0) fs->filldensity = 0; if (fs->filldensity > 100) fs->filldensity = 100; } else if (fs->fillstyle == FS_PATTERN) { fs->fillpattern = int_expression(); if (fs->fillpattern < 0) fs->fillpattern = 0; } else int_error(c_token, "this fill style does not have a parameter"); } continue; } if (almost_equals(c_token, "bo$rder")) { if (set_border && fs->border_color.lt == LT_NODRAW) int_error(c_token, "conflicting option"); fs->border_color.type = TC_DEFAULT; set_border = TRUE; c_token++; if (END_OF_COMMAND) continue; if (equals(c_token,"-") || isanumber(c_token)) { fs->border_color.type = TC_LT; fs->border_color.lt = int_expression() - 1; } else if (equals(c_token,"lc") || almost_equals(c_token,"linec$olor")) { parse_colorspec(&fs->border_color, TC_Z); } else if (equals(c_token,"rgb") || equals(c_token,"lt") || almost_equals(c_token,"linet$ype")) { c_token--; parse_colorspec(&fs->border_color, TC_Z); } continue; } else if (almost_equals(c_token, "nobo$rder")) { if (set_border && fs->border_color.lt != LT_NODRAW) int_error(c_token, "conflicting option"); fs->border_color.type = TC_LT; fs->border_color.lt = LT_NODRAW; set_border = TRUE; c_token++; continue; } /* Keyword must belong to someone else */ break; } if (transparent) { if (fs->fillstyle == FS_SOLID) fs->fillstyle = FS_TRANSPARENT_SOLID; else if (fs->fillstyle == FS_PATTERN) fs->fillstyle = FS_TRANSPARENT_PATTERN; } }