/* 7.1 */ const SWmlNode * lookupElement(SDocData *data) { /* 1. Pick up the name of the current element from event list. * 2. Look into table of tags/elements of SWmlDescriptor for it. * 3. Return the corresponding node, or the node of the unknown element. * * Note: The value of the current XML event must exits. * Assume the calling takes place from the proper context. *--------------------------------------------------------------------------- */ /* Data Structures */ PString _str; /* name of the element */ unsigned _idx; /* the index of element in the table */ const SWmlNode * _node; /* traverses the list */ /* Code */ _str = data->m_eventList.m_head->m_tokenValue; _idx = (!STR_LEN(_str)) ? 0 : (*STR_DATA(_str))&0x7f; _node = FIRST_NODE(data->m_desc->m_elements[_idx]); while(_node && !STR_SAME(_node->m_name, _str)) _node = _node->m_next; return _node ? _node : g_unknownElement; }
void main(int argc, char *argv[]) { int i; /* char *s; */ p3dc_LIST *link = p3dc_new_list(P3DC_UNKNOWN, P3DC_LIST_SORTED); p3dc_LIST other; p3dc_NODE *n; p3dc_log_open((argc > 1) ? argv[1] : "list002.log"); if (link == NULL) { fprintf(stderr, "Couldn't allocate a list.\n"); exit(1); } for (i = 0; payloads[i] != NULL; i++) { n = p3dc_new_node(payloads[i], payloads[i], 0); if (n == NULL) { fprintf(stderr, "Couldn't allocate node %d.\n", i+1); exit(1); } p3dc_add_node(link, n, P3DC_LIST_BYNAME, n->name); } for (n = FIRST_NODE(link); n != NULL; n = NEXT_NODE(link)) { p3dc_log("Node : %s\n", (char *)(n->data.p)); } p3dc_log("--------\n"); p3dc_rbprint_list(link); p3dc_log("--------\n"); p3dc_init_list(&other, P3DC_UNKNOWN, P3DC_LIST_LINKED); while(1) { n = p3dc_get_node(link, P3DC_NODE_FIRST); if (n == NULL) break; p3dc_log("REMOVE -- %s\n", n->name); p3dc_remove_node(link, P3DC_NODE_FIRST); p3dc_rbprint_list(link); p3dc_add_node(&other, n, P3DC_LIST_HEAD); } for (n = FIRST_NODE(&other); n != NULL; n = NEXT_NODE(&other)) { p3dc_log("Node : %s\n", (char *)(n->data.p)); } exit(0); }
static int merge(struct w_heap* heap){ uint32 brk = 0; struct w_listnode* it1 = FIRST_NODE(heap->block_list_head); struct w_listnode* it2 = it1; while(it1->next){ struct w_block* b1 = LIST_ENTRY(it1, struct w_block, block_node); it2 = it1->next; while(it2){ struct w_block* b2 = LIST_ENTRY(it2, struct w_block, block_node); /* List is unsorted... figure out block order */ if(b2->start > b1->start){ /* block 1 then block 2 */ if(b1->end + HEAP_OVERHEAD + 1 >= b2->start){ printf("HEAP MERGE\n"); b1->end = b2->end; list_remove( &heap->block_list_head, it2); zero(b2, sizeof(struct w_block)); brk = 1; break; } } else{ /* block 2 then block 1 */ if(b2->end + HEAP_OVERHEAD + 1 >= b1->start){ printf("HEAP MERGE\n"); b2->end = b1->end; list_remove( &heap->block_list_head, it1); zero(b1, sizeof(struct w_block)); brk = 1; break; } } it2 = it2->next; } if(brk){ heap_dump(heap); return 1; } it1 = NEXT_NODE(it1); } return 0; }
void outlist(p3dc_LIST *list) { int i = 0; p3dc_NODE *n; for (n = FIRST_NODE(list); n != NULL; n = NEXT_NODE(list)) { p3dc_log("%d - %s\n", i+1, n->name); i++; } }
/* 7.8 */ void lookupGenVal(SDocData *data, Segment *seg) { /* The string of the segment can contain subststrings what were specified * as 'Attribute value tokens' in SWmlDescriptor. ('.com/','.edu', etc.) * Search for these strings and substitute them, breaking the segment into * furter segments. *--------------------------------------------------------------------------- */ /* Data Structures */ PString str = seg->m_str; UINT16 pos = 0; const WCHAR *s = STR_DATA(str); const SWmlNode *node; /* Code */ for(; pos<STR_LEN(str); ++pos, ++s) { node = FIRST_NODE(data->m_desc->m_generalValues[(*s)&0x7f]); for(; node; node=node->m_next) { DBG_LOG2( (DBG_WML, node->m_name, " :") ); if(STR_LEN(str)>=(STR_LEN(node->m_name)+pos)) { const WCHAR *p = STR_DATA(node->m_name); const WCHAR *e = p + STR_LEN(node->m_name); const WCHAR *t = s; for(; p<e && *p==*t; p++,t++) ; if(p==e) { if(pos) { seg->m_str = newSubString(str, 0, pos, DOCPOOL); seg = newSegment(data,0,0,seg); } seg->m_str = 0; seg->m_code = node->m_code; if(STR_LEN(str)>(STR_LEN(node->m_name)+pos)) { newSegment(data, newSubString(str, (UINT16)(pos+STR_LEN(node->m_name)), (UINT16) STR_LEN(str), DOCPOOL), 0, seg); } deleteString(str, DOCPOOL); return; } } } } }
/* * This function sets *ALL* of the colors in the model to have the * passed in color value. * * Returns -1 if the name wasn't found. * -2 if the name wasn't a color. * -3 if the name was ill formed. * -4 texture could not be loaded. * 0 on success. */ int p3dc_model_set_all_colors(p3dc_MODEL *m, p3dc_CLR *color) { p3dc_NODE *n; p3dc_CLR *cc; for (n = FIRST_NODE(&(m->parts)); n != NULL; n = NEXT_NODE(&(m->parts))) { if (n->data.t == P3DC_CLR) { cc = (p3dc_CLR *)(n->data.p); *cc = *color; } } return 0; }
/* * This function sets *ALL* of the textures in the model to have the value * passed as a texture. * * Returns -1 if the name wasn't found. * -2 if the name wasn't a color. * -3 if the name was ill formed. * -4 texture could not be loaded. * 0 on success. */ int p3dc_model_set_all_textures(p3dc_MODEL *m, char *texture) { p3dc_NODE *n; p3dc_TDATA *cc; for (n = FIRST_NODE(&(m->parts)); n != NULL; n = NEXT_NODE(&(m->parts))) { if (n->data.t == P3DC_TDATA) { cc = (p3dc_TDATA *)(n->data.p); if (p3dc_load_texture(texture, cc)) return -1; } } return 0; }
/* 7.2 */ const SWmlNode * lookupAttr(SDocData *data, const SWmlNode *element) { /* 1. Pick up the name of the current current attribute from event list. * 2. If the 'element' had that attribute: return it. * 3. If the attribute was found in the table of attributes of the * SWmlDescriptor: return it. * 4. Otherwise return the 'unknown' attribute. * * Note: The value of the current XML event must exits. * Assume the calling takes place from the proper context. *--------------------------------------------------------------------------- */ /* Data Structures */ PString _str = data->m_eventList.m_head->m_tokenValue; const SWmlNode * _node = FIRST_NODE(element->m_children); unsigned _idx; /* Code */ DBG_LOG2( (DBG_WML, _str, "lookupAttr:") ); while(_node && !STR_SAME(_node->m_name, _str)) { DBG_LOG2( (DBG_WML, _node->m_name, " ?:") ); _node = _node->m_next; } if(!_node) { /* global attributes */ _idx = (!STR_LEN(_str)) ? 0 : (*STR_DATA(_str))&0x7f; _node = FIRST_NODE(data->m_desc->m_attributes[_idx]); while(_node && !STR_SAME(_node->m_name, _str)) _node = _node->m_next; } DBG_LOG( (DBG_WML, "lookupAttr: found: %p",_node ) ); return _node ? _node : g_unknownAttribute; }
static void heap_dump(struct w_heap* heap){ printf("HEAP DUMP:\n"); struct w_listnode* it = FIRST_NODE(heap->block_list_head); uint32 count = 0; while(it){ struct w_block* data = LIST_ENTRY(it, struct w_block, block_node); printf(" %p. node: 0x%p, start: 0x%p, end:0x%p\n",count++, it, data->start, data->end); it = NEXT_NODE(it); } }
/* 7.3 */ SWmlString * lookupString(SDocData *data, PString str) { /* Search for 'str' in 'stringTable' of DocData. * Return the node or NULL. *--------------------------------------------------------------------------- */ /* Data Structures */ unsigned _idx = (!STR_LEN(str)) ? 0 : (*STR_DATA(str))&0x7f; SWmlString * _node = FIRST_NODE(data->m_stringTable[_idx]); /* Code */ while(_node && !STR_SAME(_node->m_string, str)) _node = _node->m_next; return _node; }
void p3dc_draw_model_bbox(p3dc_VIEW *vp, p3dc_CLR *cc, int flags, p3dc_MODEL *m) { int i; p3dc_NODE *t; p3dc_LINE *tL; if (m->box.head == NULL) { for (i = 0; i < 12; i++) { if (cc == NULL) cc = &(m->color); tL = p3dc_new_line(cc, &(m->corners[mboxx[i]].v), &(m->corners[mboxy[i]].v)); p3dc_add_node(&(m->box), p3dc_new_node(tL, NULL, 0), P3DC_LIST_TAIL); } } else if (cc != NULL) { for (t = FIRST_NODE(&(m->box)); t != NULL; t = NEXT_NODE(&(m->box))) { tL = (p3dc_LINE *)(t->data.p); *(tL->color) = *(cc); } } p3dc_draw_list(vp, &(m->V), flags, &(m->box)); }
/* * This code is used for both clipping polygons and faces. When * clipping polygons 'nLists' will be 1 (vertices only) When clipping * faces it could be 2, 3, 4, or 5 lists depending on how detailed * the face is. */ int p3dc_clip_lists(p3dc_LIST f_src[], p3dc_LIST f_clip[], int nLists) { p3dc_NODE *t; CLIP_CONTEXT clip_lists[5]; int i; int out_code, accept = 0, reject = 0; int plane, did_clip = 0, dupe_it = 1; for (t = p3dc_get_node(&(f_src[P3DC_FACE_VERTEX]), P3DC_NODE_FIRST); t != NULL; t = p3dc_get_node(&(f_src[P3DC_FACE_VERTEX]),P3DC_NODE_NEXT)) { out_code = ((p3dc_VRTX *)(t->data.p))->ccode; accept |= out_code; reject &= out_code; } if (accept == 0) return CLIP_A_B; if (reject != 0) return CLIP_NONE; /* * Set up the lists we'll be clipping. The interesting bit here * is that we only _clip_ the vertices, then with the results * we adjust the other lists appropriately. */ for (i = 0; i < nLists; i++) { clip_lists[i].src = f_src[list_map[i]]; clip_lists[i].active = (clip_lists[i].src.head != NULL); } for (plane = 0; plane < 6; plane++) { int mask; mask = 1 << plane; /* Only do the clipping if there are nodes outside this plane */ if ((accept & mask) != 0) { /* Set up the destination for all lists */ for (i = 0; i < nLists; i++) { if (clip_lists[i].active) { p3dc_init_list(&(clip_lists[i].dst), clip_lists[i].src.n_type, P3DC_LIST_LINKED); } } /* Actually do the clipping */ clip_contexts(clip_lists, plane, dupe_it, nLists); /* note that clipping did occur */ did_clip++; /* If we clipped everything then we're not visible so stop */ if (clip_lists[0].dst.tail == NULL) return CLIP_NONE; /* Now get ready for the next plane */ for (i = 0; i < nLists; i++) { #ifdef PARANOID_LIST p3dc_NODE *tn; #endif if (clip_lists[i].active) { /* * Very weird case I've not optimized out. If the * FIRST node in the list gets dropped, because it * is outside the plane, we don't reuse it because * that will screw us up later, instead we copy it. * Now that we've done the clip, if its still here * then it needs to be freed. */ if ((dupe_it == 0) && (FIRST_NODE(&(clip_lists[i].src)) != NULL)) { p3dc_LIST *tL = &(clip_lists[i].src); /* Must only be one node left!! */ assert(tL->head == tL->tail); p3dc_free_node(tL->head); } /* Src lists get what used to be the destination */ clip_lists[i].src = clip_lists[i].dst; #ifdef PARANOID_LIST for (tn = clip_lists[i].src.head; tn != NULL; tn = tn->nxt) { tn->owner = &(clip_lists[i].src); } #endif clip_lists[i].srcNodes = clip_lists[i].dstNodes; } } /* After the first round we're running on copies so turn this off */ if (dupe_it) dupe_it = 0; } } for (i = 0; i < nLists; i++) { if (f_clip[list_map[i]].head != NULL) p3dc_free_list(&(f_clip[list_map[i]])); f_clip[list_map[i]] = clip_lists[i].src; } /* if somehow we never clipped we return CLIP_A_B XX that should be a bug! */ return (did_clip) ? CLIP_X_X : CLIP_A_B; }
void* kalloc(uint32 size){ struct w_heap* heap = &kern_heap; struct w_listnode* it = FIRST_NODE(heap->block_list_head); struct w_block* blk; /* We need a new list node which holds a block pointer. * This will allow us to add to free list once freed */ uint32 eff_size = size + HEAP_OVERHEAD; while( it != NULL){ blk = LIST_ENTRY(it, struct w_block, block_node); if((blk->end - blk->start) > eff_size){ /* Found a big enough block! */ break; } it = it->next; } if(it == NULL){ /* Not enough contiguous memory available */ return NULL; } /* Remove this node from the free list */ struct w_listnode* alloc_node = list_remove( &heap->block_list_head, it); uint32 start = blk->start; blk->start += eff_size; /* First initizlize the block */ struct w_block* nblock = (struct w_block*)(start + size); nblock->start = start; nblock->end = start + size; /* swap the two nodes to keep descriptors in order */ //struct w_listnode temp = nblock->block_node; //nblock->block_node = *alloc_node; //*alloc_node = temp; uint32 t1,t2; t1 = nblock->start; t2 = nblock->end; nblock->start = blk->start; nblock->end = blk->end; blk->start = t1; blk->end = t2; /* Is there still enough room for another allocation? */ if((blk->end - blk->start) > 0) list_add( &heap->block_list_head, &nblock->block_node); //list_remove(&heap->block_list_head, &nblock->block_node); //list_add(&heap->block_list_head, alloc_node); heap_dump(heap); return (void*)start; }