HTAnchor * HTHistory_moveBy ARGS1 (int,offset) { HTAnchor * last = HTList_objectAt (history, 1); if (! last) return NULL; /* No last visited node */ if (last != (HTAnchor *) last->parent) { /* Was a child */ HTList * kids = last->parent->children; int i = HTList_indexOf (kids, last); HTAnchor * nextOne = HTList_objectAt (kids, i - offset); if (nextOne) { HTAnchor * destination = HTAnchor_followMainLink (nextOne); if (destination) { HTList_removeLastObject (history); HTList_removeLastObject (history); HTList_addObject (history, nextOne); HTList_addObject (history, destination); } return destination; } else { if (TRACE) fprintf(stderr, "HTHistory_moveBy: offset by %+d goes out of list %p.\n", offset, kids); return NULL; } } else { /* Was a parent */ return NULL; /* FIXME we could possibly follow the next link... */ } }
/* Delete a parent anchor and all its children. If a hyperdoc object ** is found hanging off the parent anchor then this is returned */ PRIVATE void * delete_family (HTAnchor * me) { HTParentAnchor * parent = NULL; if (!me) { HTTRACE(ANCH_TRACE, "AnchorDelete No anchor found\n"); return NULL; } parent = me->parent; HTTRACE(ANCH_TRACE, "AnchorDelete Remove parent %p and children\n" _ parent); /* Delete children */ if (parent->children) { int cnt = 0; for (; cnt<CHILD_HASH_SIZE; cnt++) { HTList * kids = parent->children[cnt]; if (kids) { HTChildAnchor * child; while ((child=(HTChildAnchor*)HTList_removeLastObject(kids))) { HT_FREE(child->tag); if (child->links) { HTList * cur = child->links; HTLink * pres; while ((pres = (HTLink *) HTList_nextObject(cur))) HTLink_delete(pres); HTList_delete(child->links); } HT_FREE(child); } HTList_delete(kids); parent->children[cnt] = NULL; } } } return delete_parent(parent); }
void HTHistory_leavingFrom ARGS1 (HTAnchor *,anchor) { if (HTList_removeLastObject (history)) HTList_addObject (history, anchor); else if (TRACE) fprintf(stderr, "HTHistory_leavingFrom: empty history !\n"); }
PUBLIC BOOL CSUserList_destroy(void) { char * userName; while ((userName = (char *) HTList_removeLastObject(UserList))) HT_FREE(userName); HTList_delete(UserList); UserList = NULL; return YES; }
static void free_alloced_lynxcgi(void) { void *ptr; while ((ptr = HTList_removeLastObject(alloced)) != NULL) { FREE(ptr); } FREE(alloced); #ifdef LYNXCGI_LINKS FREE(user_agent); FREE(server_software); #endif }
PUBLIC int EventOrder_executeAndDelete (void) { HTList * cur = EventOrderList; EventOrder * pres; int i = 0; HTTRACE(THD_TRACE, "EventOrder.. execute ordered events\n"); if (cur == NULL) return NO; while ((pres=(EventOrder *) HTList_removeLastObject(cur)) && i<EVENTS_TO_EXECUTE) { HTEvent * event = pres->event; int ret; HTTRACE(THD_TRACE, "EventList... calling socket %d, request %p handler %p type %s\n" _ pres->s _ (void *) event->request _ (void *) event->cbf _ HTEvent_type2str(pres->type)); ret = (*pres->event->cbf)(pres->s, pres->event->param, pres->type); HT_FREE(pres); if (ret != HT_OK) return ret; i++; } return HT_OK; }
/* ** cleans up all memory used by icons. Should be called by ** HTLibTerminate() (but it isn't) ** */ PUBLIC void HTIcon_deleteAll (void) { if(icons != NULL) { HTList * iconList = icons; HTIconNode * node; while((node = (HTIconNode*)HTList_removeLastObject(iconList))) { HTIconNode_delete(node); } /* delete the list as well */ HTList_delete(icons); icons = NULL; } HTIconNode_delete(icon_unknown); icon_unknown = NULL; HTIconNode_delete(icon_blank); icon_blank = NULL; HTIconNode_delete(icon_parent); icon_parent = NULL; HTIconNode_delete(icon_dir); icon_dir = NULL; }
PRIVATE void delete_links (HTAnchor * me) { if (! me) return; /* Recursively try to delete target anchors */ if (me->mainLink.dest) { HTParentAnchor *parent = me->mainLink.dest->parent; HTList_removeObject (parent->sources, me); if (! parent->document) /* Test here to avoid calling overhead */ HTAnchor_delete (parent); } if (me->links) { /* Extra destinations */ HTLink *target; while ((target = (HTLink *) HTList_removeLastObject (me->links))) { HTParentAnchor *parent = target->dest->parent; HTList_removeObject (parent->sources, me); if (! parent->document) /* Test here to avoid calling overhead */ HTAnchor_delete (parent); } } }
PUBLIC BOOL HTAnchor_delete (HTParentAnchor * me) { /* Don't delete if document is loaded */ if (!me || me->document) { HTTRACE(ANCH_TRACE, "Anchor...... Not deleted\n"); return NO; } /* Recursively try to delete target anchors */ delete_links ((HTAnchor *) me); if (!HTList_isEmpty(me->sources)) { /* There are still incoming links */ /* ** Delete all outgoing links from children, if any */ if (me->children) { int cnt = 0; for (; cnt<CHILD_HASH_SIZE; cnt++) { HTList * kids = me->children[cnt]; if (kids) { HTChildAnchor * child; while ((child = (HTChildAnchor *) HTList_nextObject(kids))) delete_links((HTAnchor *) child); return NO; /* Parent not deleted */ } } } /* ** No more incoming links : kill everything ** First, recursively delete children */ if (me->children) { int cnt = 0; for (; cnt<CHILD_HASH_SIZE; cnt++) { HTList * kids = me->children[cnt]; if (kids) { HTChildAnchor * child; while ((child=(HTChildAnchor *) HTList_removeLastObject(kids))) delete_links((HTAnchor *) child); HT_FREE(child->tag); HT_FREE(child); } } } } /* 2001/03/06: Bug fix by Serge Adda <*****@*****.**> HTAnchor_delete wasn't removing the reference to the deleted anchor. This caused a bug whenever requesting another anchor for the same URL. */ if (adult_table) { int hash; const char *p; HTList * adults; HTList * grownups; HTList * last; HTParentAnchor * foundAnchor; /* Select list from hash table */ for(p=me->address, hash=0; *p; p++) hash = (int) ((hash * 3 + (*(unsigned char*)p)) % PARENT_HASH_SIZE); adults = adult_table[hash]; /* Search list for anchor */ grownups = adults; last = grownups; while ((foundAnchor = (HTParentAnchor *) HTList_nextObject(grownups))){ if (!strcmp(foundAnchor->address, me->address)) { HTList_quickRemoveElement (grownups, last); break; } last = grownups; } } /* Now kill myself */ delete_parent(me); return YES; /* Parent deleted */ #if 0 if (! HTList_isEmpty (me->sources)) { /* There are still incoming links */ /* Delete all outgoing links from children, if any */ HTList *kids = me->children; while ((child = (HTChildAnchor *) HTList_nextObject (kids))) delete_links ((HTAnchor *) child); return NO; /* Parent not deleted */ } /* No more incoming links : kill everything */ /* First, recursively delete children */ while ((child = (HTChildAnchor *) HTList_removeLastObject (me->children))) { delete_links ((HTAnchor *) child); HT_FREE(child->tag); HT_FREE(child); } #endif }