diff options
Diffstat (limited to 'fitz/obj_dict.c')
-rw-r--r-- | fitz/obj_dict.c | 144 |
1 files changed, 72 insertions, 72 deletions
diff --git a/fitz/obj_dict.c b/fitz/obj_dict.c index d1cc22cc..6f3ba9da 100644 --- a/fitz/obj_dict.c +++ b/fitz/obj_dict.c @@ -6,20 +6,20 @@ static int keyvalcmp(const void *ap, const void *bp) { const fz_keyval *a = ap; const fz_keyval *b = bp; - if (fz_isname(a->k) && fz_isname(b->k)) - return strcmp(fz_toname(a->k), fz_toname(b->k)); + if (fz_is_name(a->k) && fz_is_name(b->k)) + return strcmp(fz_to_name(a->k), fz_to_name(b->k)); return -1; } static inline int keystrcmp(fz_obj *key, char *s) { - if (fz_isname(key)) - return strcmp(fz_toname(key), s); + if (fz_is_name(key)) + return strcmp(fz_to_name(key), s); return -1; } fz_obj * -fz_newdict(int initialcap) +fz_new_dict(int initialcap) { fz_obj *obj; int i; @@ -35,68 +35,68 @@ fz_newdict(int initialcap) obj->u.d.items = fz_calloc(obj->u.d.cap, sizeof(fz_keyval)); for (i = 0; i < obj->u.d.cap; i++) { - obj->u.d.items[i].k = nil; - obj->u.d.items[i].v = nil; + obj->u.d.items[i].k = NULL; + obj->u.d.items[i].v = NULL; } return obj; } fz_obj * -fz_copydict(fz_obj *obj) +fz_copy_dict(fz_obj *obj) { fz_obj *new; int i; - if (fz_isindirect(obj) || !fz_isdict(obj)) + if (fz_is_indirect(obj) || !fz_is_dict(obj)) fz_throw("assert: not a dict (%s)", fz_objkindstr(obj)); - new = fz_newdict(fz_dictlen(obj)); - for (i = 0; i < fz_dictlen(obj); i++) - fz_dictput(new, fz_dictgetkey(obj, i), fz_dictgetval(obj, i)); + new = fz_new_dict(fz_dict_len(obj)); + for (i = 0; i < fz_dict_len(obj); i++) + fz_dict_put(new, fz_dict_get_key(obj, i), fz_dict_get_val(obj, i)); return new; } int -fz_dictlen(fz_obj *obj) +fz_dict_len(fz_obj *obj) { - obj = fz_resolveindirect(obj); - if (!fz_isdict(obj)) + obj = fz_resolve_indirect(obj); + if (!fz_is_dict(obj)) return 0; return obj->u.d.len; } fz_obj * -fz_dictgetkey(fz_obj *obj, int i) +fz_dict_get_key(fz_obj *obj, int i) { - obj = fz_resolveindirect(obj); + obj = fz_resolve_indirect(obj); - if (!fz_isdict(obj)) - return nil; + if (!fz_is_dict(obj)) + return NULL; if (i < 0 || i >= obj->u.d.len) - return nil; + return NULL; return obj->u.d.items[i].k; } fz_obj * -fz_dictgetval(fz_obj *obj, int i) +fz_dict_get_val(fz_obj *obj, int i) { - obj = fz_resolveindirect(obj); + obj = fz_resolve_indirect(obj); - if (!fz_isdict(obj)) - return nil; + if (!fz_is_dict(obj)) + return NULL; if (i < 0 || i >= obj->u.d.len) - return nil; + return NULL; return obj->u.d.items[i].v; } static inline int -fz_dictfinds(fz_obj *obj, char *key) +fz_dict_finds(fz_obj *obj, char *key) { if (obj->u.d.sorted) { @@ -127,56 +127,56 @@ fz_dictfinds(fz_obj *obj, char *key) } fz_obj * -fz_dictgets(fz_obj *obj, char *key) +fz_dict_gets(fz_obj *obj, char *key) { int i; - obj = fz_resolveindirect(obj); + obj = fz_resolve_indirect(obj); - if (!fz_isdict(obj)) - return nil; + if (!fz_is_dict(obj)) + return NULL; - i = fz_dictfinds(obj, key); + i = fz_dict_finds(obj, key); if (i >= 0) return obj->u.d.items[i].v; - return nil; + return NULL; } fz_obj * -fz_dictget(fz_obj *obj, fz_obj *key) +fz_dict_get(fz_obj *obj, fz_obj *key) { - if (fz_isname(key)) - return fz_dictgets(obj, fz_toname(key)); - return nil; + if (fz_is_name(key)) + return fz_dict_gets(obj, fz_to_name(key)); + return NULL; } fz_obj * -fz_dictgetsa(fz_obj *obj, char *key, char *abbrev) +fz_dict_getsa(fz_obj *obj, char *key, char *abbrev) { fz_obj *v; - v = fz_dictgets(obj, key); + v = fz_dict_gets(obj, key); if (v) return v; - return fz_dictgets(obj, abbrev); + return fz_dict_gets(obj, abbrev); } void -fz_dictput(fz_obj *obj, fz_obj *key, fz_obj *val) +fz_dict_put(fz_obj *obj, fz_obj *key, fz_obj *val) { char *s; int i; - obj = fz_resolveindirect(obj); + obj = fz_resolve_indirect(obj); - if (!fz_isdict(obj)) + if (!fz_is_dict(obj)) { fz_warn("assert: not a dict (%s)", fz_objkindstr(obj)); return; } - if (fz_isname(key)) - s = fz_toname(key); + if (fz_is_name(key)) + s = fz_to_name(key); else { fz_warn("assert: key is not a name (%s)", fz_objkindstr(obj)); @@ -189,11 +189,11 @@ fz_dictput(fz_obj *obj, fz_obj *key, fz_obj *val) return; } - i = fz_dictfinds(obj, s); + i = fz_dict_finds(obj, s); if (i >= 0) { - fz_dropobj(obj->u.d.items[i].v); - obj->u.d.items[i].v = fz_keepobj(val); + fz_drop_obj(obj->u.d.items[i].v); + obj->u.d.items[i].v = fz_keep_obj(val); return; } @@ -203,8 +203,8 @@ fz_dictput(fz_obj *obj, fz_obj *key, fz_obj *val) obj->u.d.items = fz_realloc(obj->u.d.items, obj->u.d.cap, sizeof(fz_keyval)); for (i = obj->u.d.len; i < obj->u.d.cap; i++) { - obj->u.d.items[i].k = nil; - obj->u.d.items[i].v = nil; + obj->u.d.items[i].k = NULL; + obj->u.d.items[i].v = NULL; } } @@ -213,33 +213,33 @@ fz_dictput(fz_obj *obj, fz_obj *key, fz_obj *val) if (keystrcmp(obj->u.d.items[obj->u.d.len - 1].k, s) > 0) obj->u.d.sorted = 0; - obj->u.d.items[obj->u.d.len].k = fz_keepobj(key); - obj->u.d.items[obj->u.d.len].v = fz_keepobj(val); + obj->u.d.items[obj->u.d.len].k = fz_keep_obj(key); + obj->u.d.items[obj->u.d.len].v = fz_keep_obj(val); obj->u.d.len ++; } void -fz_dictputs(fz_obj *obj, char *key, fz_obj *val) +fz_dict_puts(fz_obj *obj, char *key, fz_obj *val) { - fz_obj *keyobj = fz_newname(key); - fz_dictput(obj, keyobj, val); - fz_dropobj(keyobj); + fz_obj *keyobj = fz_new_name(key); + fz_dict_put(obj, keyobj, val); + fz_drop_obj(keyobj); } void -fz_dictdels(fz_obj *obj, char *key) +fz_dict_dels(fz_obj *obj, char *key) { - obj = fz_resolveindirect(obj); + obj = fz_resolve_indirect(obj); - if (!fz_isdict(obj)) + if (!fz_is_dict(obj)) fz_warn("assert: not a dict (%s)", fz_objkindstr(obj)); else { - int i = fz_dictfinds(obj, key); + int i = fz_dict_finds(obj, key); if (i >= 0) { - fz_dropobj(obj->u.d.items[i].k); - fz_dropobj(obj->u.d.items[i].v); + fz_drop_obj(obj->u.d.items[i].k); + fz_drop_obj(obj->u.d.items[i].v); obj->u.d.sorted = 0; obj->u.d.items[i] = obj->u.d.items[obj->u.d.len-1]; obj->u.d.len --; @@ -248,29 +248,29 @@ fz_dictdels(fz_obj *obj, char *key) } void -fz_dictdel(fz_obj *obj, fz_obj *key) +fz_dict_del(fz_obj *obj, fz_obj *key) { - if (fz_isname(key)) - fz_dictdels(obj, fz_toname(key)); + if (fz_is_name(key)) + fz_dict_dels(obj, fz_to_name(key)); else fz_warn("assert: key is not a name (%s)", fz_objkindstr(obj)); } void -fz_freedict(fz_obj *obj) +fz_free_dict(fz_obj *obj) { int i; - obj = fz_resolveindirect(obj); + obj = fz_resolve_indirect(obj); - if (!fz_isdict(obj)) + if (!fz_is_dict(obj)) return; for (i = 0; i < obj->u.d.len; i++) { if (obj->u.d.items[i].k) - fz_dropobj(obj->u.d.items[i].k); + fz_drop_obj(obj->u.d.items[i].k); if (obj->u.d.items[i].v) - fz_dropobj(obj->u.d.items[i].v); + fz_drop_obj(obj->u.d.items[i].v); } fz_free(obj->u.d.items); @@ -278,10 +278,10 @@ fz_freedict(fz_obj *obj) } void -fz_sortdict(fz_obj *obj) +fz_sort_dict(fz_obj *obj) { - obj = fz_resolveindirect(obj); - if (!fz_isdict(obj)) + obj = fz_resolve_indirect(obj); + if (!fz_is_dict(obj)) return; if (!obj->u.d.sorted) { |