about summary refs log tree commit diff stats
path: root/arc/trace.arc.t
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-06-23 14:02:12 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-06-23 14:02:12 -0700
commitdbe124108b7a3529feeeba91339928c4ac737072 (patch)
tree6da7f748b04ec70cf5f778863ae4f86403943eb2 /arc/trace.arc.t
parentfedebaf5dbc1b39347ad3e3a1580fa0190c320b6 (diff)
downloadmu-dbe124108b7a3529feeeba91339928c4ac737072.tar.gz
1631 - update html versions
Html is a little more readable thanks to feedback from J David Eisenberg
(https://news.ycombinator.com/item?id=9766330), in particular the
suggestion to use https://addons.mozilla.org/En-us/firefox/addon/wcag-contrast-checker.
Diffstat (limited to 'arc/trace.arc.t')
0 files changed, 0 insertions, 0 deletions
d='n82' href='#n82'>82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157




























































































































































                                                                                
#include "HTUtils.h"
#include "tcp.h"		/* for standard io */

#include "HTHistory.h"

#include "LYLeaks.h"

static HTList * history;	/* List of visited anchors */


/*				Navigation
**				==========
*/

/*		Record the jump to an anchor
**		----------------------------
*/

void HTHistory_record
  ARGS1 (HTAnchor *,destination)
{
  if (destination) {
    if (! history)
      history = HTList_new();
    HTList_addObject (history, destination);
  }
}

/*		Go back in history (find the last visited node)
**		------------------
*/

HTAnchor * HTHistory_backtrack
  NOARGS  /* FIXME: Should we add a `sticky' option ? */
{
  if (HTHistory_canBacktrack())
    HTList_removeLastObject(history);
  return(HTAnchor *)HTList_lastObject(history); /* is Home if can't backtrack */
}

BOOL HTHistory_canBacktrack
  NOARGS
{
  return (HTList_objectAt (history, 1) != NULL);
}

/*		Browse through references in the same parent node
**		-------------------------------------------------
**
**	Take the n-th child's link after or before the one we took to get here.
**	Positive offset means go towards most recently added children.
*/

HTAnchor * HTHistory_moveBy
 ARGS1 (int,offset)
{
  HTAnchor * last = (HTAnchor *)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 = (HTAnchor *)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, (void*)kids);
      return NULL;
    }
  } else {  /* Was a parent */
    return NULL;  /* FIXME we could possibly follow the next link... */
  }
}

BOOL HTHistory_canMoveBy
 ARGS1 (int,offset)
{
  HTAnchor * last = (HTAnchor *)HTList_objectAt (history, 1);
  if (! last)
    return NO;  /* No last visited node */
  if (last != (HTAnchor *) last->parent) {  /* Was a child */
    HTList * kids = last->parent->children;
    int i = HTList_indexOf (kids, last); 
    return (HTList_objectAt (kids, i - offset) != NULL);
  } else {  /* Was a parent */
    return NO;  /* FIXME we could possibly follow the next link... */
  }
}


/*				Retrieval
**				=========
*/

/*		Read numbered visited anchor (1 is the oldest)
**		----------------------------
*/

HTAnchor * HTHistory_read
  ARGS1 (int,number)
{
  return (HTAnchor *)HTList_objectAt(history, HTList_count (history) - number);
}


/*		Recall numbered visited anchor (1 is the oldest)
**		------------------------------
**	This reads the anchor and stores it again in the list, except if last.
*/

HTAnchor * HTHistory_recall
  ARGS1 (int,number)
{
  HTAnchor * destination =
    (HTAnchor *)HTList_objectAt (history, HTList_count (history) - number);
  if (destination && destination != (HTAnchor *)HTList_lastObject (history))
    HTList_addObject (history, destination);
  return destination;
}

/*		Number of Anchors stored
**		------------------------
**
**	This is needed in order to check the validity of certain commands
**	for menus, etc.
(not needed for now. Use canBacktrack, etc.)
int HTHistory_count
  NOARGS
{
  return HTList_count (history);
}
*/

/*		Change last history entry
**		-------------------------
**
**	Sometimes we load a node by one anchor but leave by a different
**	one, and it is the one we left from which we want to remember.
*/

void HTHistory_leavingFrom
  ARGS1 (HTAnchor *,anchor)
{
  if (HTList_removeLastObject (history))
    HTList_addObject (history, anchor);
  else
    if (TRACE) fprintf(stderr, "HTHistory_leavingFrom: empty history !\n");
}