int main() { int i; UT_string *t; UT_vector v; utvector_init(&v, utstring_mm); UT_string s; utstring_init(&s); for(i=0; i<16; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } dump(&v); t = (UT_string*)utvector_head(&v); printf("head: %s %s\n", t?"non-null":"null", t?utstring_body(t):"-"); t = (UT_string*)utvector_tail(&v); printf("tail: %s %s\n", t?"non-null":"null", t?utstring_body(t):"-"); printf("extend\n"); t = (UT_string*)utvector_extend(&v); utstring_bincpy(t, "hello", 5); dump(&v); t = (UT_string*)utvector_head(&v); printf("head: %s %s\n", t?"non-null":"null", t?utstring_body(t):"-"); t = (UT_string*)utvector_tail(&v); printf("tail: %s %s\n", t?"non-null":"null", t?utstring_body(t):"-"); utvector_fini(&v); utstring_done(&s); return 0; }
int main() { int i; UT_string *t; UT_vector v; utvector_init(&v, utvector_utstring); UT_string s; utstring_init(&s); for(i=0; i<16; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } dump(&v); t = (UT_string*)utvector_head(&v); printf("head: %s %s\n", t?"non-null":"null", t?utstring_body(t):"-"); t = (UT_string*)utvector_tail(&v); printf("tail: %s %s\n", t?"non-null":"null", t?utstring_body(t):"-"); for(i=0; i<16; i++) { printf("shift\n"); utvector_shift(&v); t = (UT_string*)utvector_head(&v); printf("len: %d, head: %s %s\n", utvector_len(&v), t?"non-null":"null", t?utstring_body(t):"-"); } printf("extend\n"); t= (UT_string*)utvector_extend(&v); utstring_printf(t,"extended"); t = (UT_string*)utvector_head(&v); printf("len: %d, head: %s %s\n", utvector_len(&v), t?"non-null":"null", t?utstring_body(t):"-"); utvector_fini(&v); utstring_done(&s); return 0; }
static void dump(struct nbt_tag *tag, UT_vector *nbt_stack) { nbt_stack_frame *top; uint32_t seen; int indent; indent = utvector_len(nbt_stack); while(indent--) fprintf(stderr," "); /* print list elements by their position, others by their name */ top = (nbt_stack_frame*)utvector_tail(nbt_stack); if (top && (top->tag.type == TAG_List)) { // is list item seen = top->list.total - top->list.left; fprintf(stderr,"%u/%u (%s)\n", seen, top->list.total, nbt_tag_str[top->list.type]); } else { fprintf(stderr,"%.*s (%s)\n", (int)tag->len, tag->name, nbt_tag_str[tag->type]); } }
/* this function is consults the stack. if we're parsing a list, we are not * expecting a named tag, so it returns 0. in that case, it also sets tag_type * to the list's per-element type, and decrements the list count. if we're not * in a list, return 1. */ static int expect_named_tag(UT_vector *nbt_stack, char *tag_type) { nbt_stack_frame *top; top = (nbt_stack_frame*)utvector_tail(nbt_stack); if (top == NULL) return 1; if (top->tag.type == TAG_Compound) return 1; assert(top->tag.type == TAG_List); if (top->list.left == 0) { utvector_pop(nbt_stack); return 1; } /* in a list with remaining elements */ *tag_type = top->list.type; top->list.left--; return 0; }
int main() { int i,*p=NULL; UT_vector v; utvector_init(&v, utmm_int); for(i=0; i<16; i++) utvector_push(&v, &i); p=NULL; while ( (p=(int*)utvector_next(&v,p))) printf("%d\n",*p); p = (int*)utvector_head(&v); printf("head: (%s) %d\n", p?"non-null":"null", p?*p:0); p = (int*)utvector_tail(&v); printf("tail: (%s) %d\n", p?"non-null":"null", p?*p:0); utvector_fini(&v); return 0; }
void nbt_record_tag(struct nbt_tag *tag, off_t pos, uint32_t count, UT_vector /* of nbt_stack_frame */ *nbt_stack, UT_vector /* of struct nbt_record */ *records) { /* do not record each item of a list; we record the list itself */ nbt_stack_frame *top; top = (nbt_stack_frame*)utvector_tail(nbt_stack); if (top && (top->tag.type == TAG_List)) return; /* record the tag. prepend stack tags to "fully-qualify" the name */ struct nbt_record *r = (struct nbt_record*)utvector_extend(records); r->tag = *tag; r->pos = pos; r->count = count; nbt_stack_frame *f = NULL; while ( (f = (nbt_stack_frame*)utvector_next(nbt_stack,f))) { utstring_printf(&r->fqname, "%.*s.", (int)f->tag.len, f->tag.name); } utstring_printf(&r->fqname, "%.*s", (int)tag->len, tag->name); }