/** * Global attribute parser. * @param [in] first Pointer to the first character of the attribute name. * @param [in] last Pointer to the last character of the attribute name. * @param [in,out] user_data PDS parser user data. * @return 1 upon success or 0 if an error occured. */ int parse_attribute_begin(const char *first, const char *last, void *user_data) { static PDS_attributes_infos base_attributes[] = { { "RECORD_BYTES", record_size } }; static const size_t base_attributes_count = ARRAY_SIZE(base_attributes); static PDS_attributes_infos image_attributes[] = { {"LINES", image_lines }, {"LINE_SAMPLES", image_samples_per_line }, {"SAMPLE_BITS", image_sample_bits }, {"SAMPLE_TYPE", image_sample_type }, {"BANDS", image_bands } }; static const size_t image_attributes_count = ARRAY_SIZE(image_attributes); PDS_attributes_infos *attributes; size_t count; size_t i; PDS_payload *payload = (PDS_payload*)user_data; if(NULL == payload) { return 0; } if(payload->ignore) { return 1; } payload->element_type = PDS_ATTRIBUTE; if(payload->image_object) { attributes = image_attributes; count = image_attributes_count; } else if(0 == payload->depth) { attributes = base_attributes; count = base_attributes_count; } else { return 1; } payload->op = NULL; for(i=0; i<count; i++) { if (PDS_string_case_compare(attributes[i].name, str_last(attributes[i].name), first, last)) { payload->op = attributes[i].parser; return 1; } } return 1; }
/** * Object end callback. * Only the specified image object is being parsed. * All other objects are ignored. * @param [in] first Pointer to the first character of the object name. * @param [in] last Pointer to the last character of the object name. * @param [in,out] user_data PDS parser user data. * @return 1 upon success, 0 otherwise. */ int object_end(const char *first, const char *last, void *user_data) { PDS_payload *payload = (PDS_payload*)user_data; if(NULL == payload) { return 0; } if(payload->ignore) { payload->ignore--; } else if((1 == payload->depth) && PDS_string_case_compare(g_image_string, str_last(g_image_string + strlen(g_image_string)), first, last)) { payload->image_object = 0; } payload->depth--; return 1; }
int str_val(char *s) { int v=0; unsigned char a; while(*s==' '){s++;} jstrupr(s); if(str_last(s)!='H' && s[0]!='$' ){return atoi(s);} while(*s!=0){ a=*s++; if(a==' '||a==',' || a=='='){break;} if(a>='0' && a<='9'){v=v<<4;v=v+(a-'0');} if(a>='A' && a<='F'){v=v<<4;v=v+(a-'A')+10;} } return v; }
/** * Object start callback. * Only the specified image object is being parsed. * All other objects are ignored. * @param [in] first Pointer to the first character of the object name. * @param [in] last Pointer to the last character of the object name. * @param [in,out] user_data PDS parser user data. * @return 1 upon success, 0 otherwise. */ int object_begin(const char *first, const char *last, void *user_data) { PDS_payload *payload = (PDS_payload*)user_data; if(NULL == payload) { return 0; } payload->depth++; if( payload->ignore || (payload->depth > 1) || (!PDS_string_case_compare(g_image_string, str_last(g_image_string), first, last)) ) { payload->ignore++; } else { payload->image_object = 1; } return 1; }
/** * Global pointer parser. * We are only interested in the pointer associated to the image. * The rest is ignored. * @param [in] first Pointer to the first character of the pointer name. * @param [in] last Pointer to the last character of the pointer name. * @param [in,out] user_data PDS parser user data. * @return 1 upon success or 0 if an error occured. */ int parse_pointer_begin(const char *first, const char *last, void *user_data) { PDS_payload *payload = (PDS_payload*)user_data; if(NULL == payload) { return 0; } if(payload->ignore) { return 1; } payload->element_type = PDS_POINTER; if(0 == payload->depth) { if (PDS_string_case_compare(g_image_string, str_last(g_image_string), first, last)) { payload->op = image_record; } } return 1; }