3 #include "tcp.h" /* for standard io */
5 static HTList * history; /* List of visited anchors */
12 /* Record the jump to an anchor
13 ** ----------------------------
17 ARGS1 (HTAnchor *,destination)
21 history = HTList_new();
22 HTList_addObject (history, destination);
26 /* Go back in history (find the last visited node)
30 HTAnchor * HTHistory_backtrack
31 NOARGS /* FIXME: Should we add a `sticky' option ? */
33 if (HTHistory_canBacktrack())
34 HTList_removeLastObject (history);
35 return HTList_lastObject (history); /* is Home if can't backtrack */
38 BOOL HTHistory_canBacktrack
41 return (HTList_objectAt (history, 1) != NULL);
44 /* Browse through references in the same parent node
45 ** -------------------------------------------------
47 ** Take the n-th child's link after or before the one we took to get here.
48 ** Positive offset means go towards most recently added children.
51 HTAnchor * HTHistory_moveBy
54 HTAnchor * last = HTList_objectAt (history, 1);
56 return NULL; /* No last visited node */
57 if (last != (HTAnchor *) last->parent) { /* Was a child */
58 HTList * kids = last->parent->children;
59 int i = HTList_indexOf (kids, last);
60 HTAnchor * nextOne = HTList_objectAt (kids, i - offset);
62 HTAnchor * destination = HTAnchor_followMainLink (nextOne);
64 HTList_removeLastObject (history);
65 HTList_removeLastObject (history);
66 HTList_addObject (history, nextOne);
67 HTList_addObject (history, destination);
72 "HTHistory_moveBy: offset by %+d goes out of list %p.\n",
76 } else { /* Was a parent */
77 return NULL; /* FIXME we could possibly follow the next link... */
81 BOOL HTHistory_canMoveBy
84 HTAnchor * last = HTList_objectAt (history, 1);
86 return NO; /* No last visited node */
87 if (last != (HTAnchor *) last->parent) { /* Was a child */
88 HTList * kids = last->parent->children;
89 int i = HTList_indexOf (kids, last);
90 return (HTList_objectAt (kids, i - offset) != NULL);
91 } else { /* Was a parent */
92 return NO; /* FIXME we could possibly follow the next link... */
101 /* Read numbered visited anchor (1 is the oldest)
102 ** ----------------------------
105 HTAnchor * HTHistory_read
108 return HTList_objectAt (history, HTList_count (history) - number);
112 /* Recall numbered visited anchor (1 is the oldest)
113 ** ------------------------------
114 ** This reads the anchor and stores it again in the list, except if last.
117 HTAnchor * HTHistory_recall
120 HTAnchor * destination =
121 HTList_objectAt (history, HTList_count (history) - number);
122 if (destination && destination != HTList_lastObject (history))
123 HTList_addObject (history, destination);
127 /* Number of Anchors stored
128 ** ------------------------
130 ** This is needed in order to check the validity of certain commands
132 (not needed for now. Use canBacktrack, etc.)
136 return HTList_count (history);
140 /* Change last history entry
141 ** -------------------------
143 ** Sometimes we load a node by one anchor but leave by a different
144 ** one, and it is the one we left from which we want to remember.
147 void HTHistory_leavingFrom
148 ARGS1 (HTAnchor *,anchor)
150 if (HTList_removeLastObject (history))
151 HTList_addObject (history, anchor);
153 if (TRACE) fprintf(stderr, "HTHistory_leavingFrom: empty history !\n");