list_pointer search_item_in_list(object_type item, list_type *list) { list_pointer aux; /* If there is no item on the list, it returns NULL*/ if(!get_first_in_list(list, &aux)) return NULL; /* While there is an next item, keep searching */ do { if (compare_objects(aux->item, item)) { return aux; } go_next(list, &aux); } while (!is_last(aux, list)); /* Tests if the object is the last */ if (compare_objects(aux->item, item)) { return aux; } return NULL; }
/* returns 1 for all identical objects in the environment except the first one. */ varargs int duplicatep( object o ) { int i; object *obs; if (!o) o = previous_object(); obs = all_inventory(environment(o)); for (i=0; i<sizeof(obs); i++) { if (obs[i]==o) return 0; if (compare_objects(obs[i], o)) return 1; } }
static void selection_sort(struct problem_t *p) { int i; for (i = 0; i < p->n - 1; ++i) { int j, min; min = i; for (j = i + 1; j < p->n; ++j) if (compare_objects(&p->objs[j], &p->objs[i]) < 0) min = j; if (min != i) { struct object_t aux; memcpy(&aux, &p->objs[i], sizeof(p->objs[0])); memcpy(&p->objs[i], &p->objs[min], sizeof(p->objs[0])); memcpy(&p->objs[min], &aux, sizeof(p->objs[0])); } } }
varargs int count( object o ) { int num; object *obs; int i; if( !o ) { if (origin() == ORIGIN_LOCAL) o = this_object(); else o = previous_object(); } if(!objectp(environment(o))) return 1; obs = all_inventory(environment(o)); for (i=0; i<sizeof(obs); i++) if (compare_objects(obs[i],o)) num++; return num; }
/* Validate a group attributes dictionary */ static Bool pdf_validateGroupAttributes(PDFCONTEXT* pdfc, OBJECT attrib, Bool requireColorSpace, int32* colorspaceDimension) { OBJECT *object; enum { ad_Type, ad_S, ad_CS, ad_I, ad_K, ad_dummy } ; static NAMETYPEMATCH attribDictmatch[ad_dummy + 1] = { { NAME_Type | OOPTIONAL, 2, {ONAME, OINDIRECT}}, { NAME_S, 2, {ONAME, OINDIRECT}}, { NAME_CS | OOPTIONAL, 4, {ONAME, OARRAY, OPACKEDARRAY, OINDIRECT}}, { NAME_I | OOPTIONAL, 2, {OBOOLEAN, OINDIRECT}}, { NAME_K | OOPTIONAL, 2, {OBOOLEAN, OINDIRECT}}, DUMMY_END_MATCH }; PDF_CHECK_MC(pdfc); HQASSERT(oType(attrib) == ODICTIONARY, "pdf_validateGroupAttributes - attrib is not a dictionary"); /* Remove the optional flag on the colorspace if we require it */ if (requireColorSpace) attribDictmatch[ad_CS].name &= ~OOPTIONAL; else attribDictmatch[ad_CS].name |= OOPTIONAL; if (! pdf_dictmatch(pdfc, &attrib, attribDictmatch)) return FAILURE(FALSE) ; /* Type - must be Group */ object = attribDictmatch[ad_Type].result; if (object != NULL && oNameNumber(*object) != NAME_Group) return error_handler(UNDEFINED) ; /* Subtype (S). Must be Transparency */ object = attribDictmatch[ad_S].result; if (object != NULL && oNameNumber(*object) != NAME_Transparency) return error_handler(UNDEFINED) ; /* Group color space (CS) */ object = attribDictmatch[ad_CS].result; if (object != NULL) { OBJECT mappedColorSpace = OBJECT_NOTVM_NOTHING; if (! pdf_mapBlendSpace(pdfc, *object, &mappedColorSpace)) return FAILURE(FALSE) ; if (colorspaceDimension != NULL) { COLORSPACE_ID colorspaceid; if (! gsc_getcolorspacesizeandtype(gstateptr->colorInfo, &mappedColorSpace, &colorspaceid, colorspaceDimension)) return FAILURE(FALSE) ; } if (! compare_objects(object, &mappedColorSpace)) { OBJECT colorSpace = OBJECT_NOTVM_NOTHING; OBJECT colorSpaceName = OBJECT_NOTVM_NAME(NAME_CS, LITERAL); /* Insert the mapped color space back into the group attributes * dictionary. * Take a copy of the mapped object to prevent problems when freeing the * memory allocated for the attributes dictionary. The new object must be * unique (i.e. Not stored in the XREF cache) and allocated from the PDF * object pool since it is inserted back into the group attributes * dictionary. */ if (!pdf_copyobject(pdfc, &mappedColorSpace, &colorSpace) || !pdf_fast_insert_hash(pdfc, &attrib, &colorSpaceName, &colorSpace)) { return FAILURE(FALSE) ; } } } return TRUE; }