bool Data_Range::Add_Breaks (string text) { int low, high; double d1, d2; Strings breaks; Str_Itr itr; //---- check for special conditions ---- if (text.empty () || text [0] == '\n') return (true); if (String_Ptr (text)->Equals ("None")) { return (Add_Range (minimum, maximum)); } //---- unpack the break string ---- low = minimum; String_Ptr (text)->Parse (breaks); for (itr = breaks.begin (); itr != breaks.end (); itr++) { if (!String_Ptr (*itr)->Range (d1, d2)) continue; if (d1 == 0.0 && d2 == 0.0) continue; if (d2 > d1) goto break_error; high = DTOI (d2 * factor); if (low > high || low < minimum || high > maximum) goto break_error; if (low < high) { if (!Add_Range (low, high)) return (false); } low = high; } high = maximum; if (low < high) { return (Add_Range (low, high)); } return (Num_Ranges () > 0); break_error: if (exe->Send_Messages ()) { exe->Error (String ("Range Breaks %s are Illogical") % text); } return (false); }
bool User_Program::Compile (string &text, bool list_flag) { Strings lines; Str_Itr line_itr; //---- split the text into lines ---- String_Ptr (text)->Parse (lines, "\n\r\f"); for (line_itr = lines.begin (); line_itr != lines.end (); line_itr++) { line_num++; if (list_flag) { exe->Print (1, "\t") << *line_itr; } line_itr->Clean (); if (line_itr->empty ()) continue; if (declare_flag) { if (!Initial_Declare (*line_itr)) break; } else if (table_flag) { if (!Initial_Table (*line_itr)) break; } else { while (Get_Token (*line_itr)) { if (!Process_Token ()) break; } } } return (true); }
void c_private_radial_shading(OBJ_PTR fmkr, FM *p, double x0, double y0, double r0, double x1, double y1, double r1, OBJ_PTR colormap, double a, double b, double c, double d, bool extend_start, bool extend_end, int *ierr) { int len = Array_Len(colormap, ierr); if (*ierr != 0) return; if (len != 2) { RAISE_ERROR("Sorry: colormap must be array [hivalue, lookup]", ierr); return; } OBJ_PTR hival = Array_Entry(colormap, 0, ierr); OBJ_PTR lookup = Array_Entry(colormap, 1, ierr); int hi_value = Number_to_int(hival, ierr); int lookup_len = String_Len(lookup, ierr); unsigned char *lookup_ptr = (unsigned char *)(String_Ptr(lookup, ierr)); if (*ierr != 0) return; c_radial_shading(p, x0, y0, r0, x1, y1, r1, hi_value, lookup_len, lookup_ptr, convert_figure_to_output_dx(p, a), convert_figure_to_output_dy(p, b), convert_figure_to_output_dx(p, c), convert_figure_to_output_dy(p, d), convert_figure_to_output_x(p, 0.0), convert_figure_to_output_y(p, 0.0), extend_start, extend_end); }
bool Data_Range::Add_Ranges (string text) { int low, high; double d1, d2; Strings ranges; Str_Itr itr; //---- check for special conditions ---- if (text.empty () || text [0] == '\n') return (true); if (String_Ptr (text)->Equals ("All")) { return (Add_Range (minimum, maximum, increment)); } //---- unpack the range string ---- String_Ptr (text)->Parse (ranges); for (itr = ranges.begin (); itr != ranges.end (); itr++) { if (!String_Ptr (*itr)->Range (d1, d2)) continue; if (d1 == 0.0 && d2 == 0.0 && !itr->Equals ("0")) continue; low = DTOI (d1 * factor); high = DTOI (d2 * factor); if (low > high || low < minimum || high > maximum) { if (exe->Send_Messages ()) { exe->Error (String ("Range %g-%g is Out of Range") % d1 % d2); } } if (!Add_Range (low, high, increment)) return (false); } return (Num_Ranges () > 0); }
OBJ_PTR c_get_color_from_colormap(OBJ_PTR fmkr, FM *p, OBJ_PTR color_map, double x, int *ierr) { // x is from 0 to 1. this returns a vector for the RGB color from // the given colormap OBJ_PTR cm_len_obj; OBJ_PTR lookup_obj; unsigned char *buff; unsigned char r, g, b; int i, cm_len, lu_len; cm_len_obj = Array_Entry(color_map, 0, ierr); if (*ierr != 0) RETURN_NIL; cm_len = Number_to_int(cm_len_obj, ierr) + 1; if (*ierr != 0) RETURN_NIL; lookup_obj = Array_Entry(color_map, 1, ierr); if (*ierr != 0) RETURN_NIL; buff = (unsigned char *)(String_Ptr(lookup_obj,ierr)); if (*ierr != 0) RETURN_NIL; lu_len = String_Len(lookup_obj,ierr); if (*ierr != 0) RETURN_NIL; if (3*cm_len != lu_len) { RAISE_ERROR("Sorry: lookup length must be 3 times colormap length " "(for R G B components)", ierr); RETURN_NIL; } // Make sure x is non-negative if (x < 0.0) x = -x; i = 3 * (ROUND(x * (cm_len-1)) % cm_len); r = buff[i]; g = buff[i+1]; b = buff[i+2]; OBJ_PTR result = Array_New(3); Array_Store(result, 0, Float_New(r/255.0), ierr); Array_Store(result, 1, Float_New(g/255.0), ierr); Array_Store(result, 2, Float_New(b/255.0), ierr); if (*ierr != 0) RETURN_NIL; return result; }
bool Db_Record::Set_Field_Number (int number, string text) { Buffer &rec = Record (); if (!rec.OK ()) return (Status (RECORD_SIZE)); int i, max_num, num; Strings fields; String buffer = rec.Data (); String_Ptr (text)->Trim (); num = buffer.Parse (fields, delimiters); max_num = MAX (num, number); number--; buffer.clear (); for (i=0; i < max_num; i++) { if (i > 0) buffer += *delimiters; if (*delimiters == ' ') { buffer += '\"'; } if (i == number) { buffer += text; } else if (i < num) { buffer += fields [i]; } if (*delimiters == ' ') { buffer += '\"'; } } return (Record ((void *) buffer.data (), (int) buffer.size ())); }
static void PrintString(value_t v) { printf("%s\n",String_Ptr(v)->s); }
int c_private_register_image(OBJ_PTR fmkr, FM *p, int image_type, bool interpolate, bool reversed, int w, int h, unsigned char* data, long len, OBJ_PTR mask_min, OBJ_PTR mask_max, OBJ_PTR hivalue, OBJ_PTR lookup_data, int mask_obj_num, int components, const char * filters, int *ierr) { unsigned char *lookup = NULL; int value_mask_min = 256, value_mask_max = 256, lookup_len = 0, hival = 0; if (constructing_path) { RAISE_ERROR("Sorry: must finish with current path before calling " "show_image", ierr); RETURN_NIL; } if (image_type == COLORMAP_IMAGE) { value_mask_min = Number_to_int(mask_min, ierr); value_mask_max = Number_to_int(mask_max, ierr); hival = Number_to_int(hivalue, ierr); lookup = (unsigned char *)(String_Ptr(lookup_data, ierr)); lookup_len = String_Len(lookup_data, ierr); if (*ierr != 0) RETURN_NIL; } Sampled_Info *xo = (Sampled_Info *)calloc(1, sizeof(Sampled_Info)); xo->xobj_subtype = SAMPLED_SUBTYPE; double a, b, c, d, e, f; // the transform to position the image //int ir, ic, id; xo->next = xobj_list; xobj_list = (XObject_Info *)xo; xo->xo_num = next_available_xo_number++; xo->obj_num = next_available_object_number++; xo->image_data = ALLOC_N_unsigned_char(len); xo->length = len; xo->interpolate = interpolate; xo->reversed = reversed; xo->components = components; memcpy(xo->image_data, data, len); xo->image_type = image_type; if(filters) { int len = strlen(filters) + 1; xo->filters = calloc(1, len); memcpy(xo->filters, filters, len); } else xo->filters = NULL; if (image_type != COLORMAP_IMAGE) xo->lookup = NULL; else { if ((hival+1)*3 > lookup_len) { RAISE_ERROR_ii("Sorry: color space hival (%i) is too large for " "length of lookup table (%i)", hival, lookup_len, ierr); RETURN_NIL; } xo->hival = hival; lookup_len = (hival+1) * 3; xo->lookup = ALLOC_N_unsigned_char(lookup_len); xo->lookup_len = lookup_len; memcpy(xo->lookup, lookup, lookup_len); } xo->width = w; xo->height = h; xo->value_mask_min = value_mask_min; xo->value_mask_max = value_mask_max; xo->mask_obj_num = mask_obj_num; return xo->obj_num; }