commit bc107578774f3dec888a44effa4e372f032647e9 Author: Gavin Smith Date: Tue Mar 18 23:05:26 2014 +0000 Replace TAG structure with NODE diff --git a/indices.c b/indices.c index ae4afeb..1bb3ea1 100644 --- a/indices.c +++ b/indices.c @@ -127,7 +127,7 @@ info_indices_of_file_buffer (FILE_BUFFER *file_buffer) /* Grovel the names of the nodes found in this file. */ if (file_buffer->tags) { - TAG *tag; + NODE *tag; for (i = 0; (tag = file_buffer->tags[i]); i++) { @@ -818,7 +818,7 @@ static NODE * create_virtindex_node (FILE_BUFFER *file_buffer) { NODE *node; - TAG *tag = file_buffer->tags[0]; + NODE *tag = file_buffer->tags[0]; char *text = file_buffer->contents + tag->nodestart; text += skip_node_separator (text); diff --git a/man.c b/man.c index 054a5f2..068c653 100644 --- a/man.c +++ b/man.c @@ -386,7 +386,7 @@ static NODE * manpage_node_of_file_buffer (FILE_BUFFER *file_buffer, char *pagename) { NODE *node = NULL; - TAG *tag = NULL; + NODE *tag = NULL; if (file_buffer->contents) { diff --git a/nodes.c b/nodes.c index 4ad4170..4c3344a 100644 --- a/nodes.c +++ b/nodes.c @@ -34,7 +34,7 @@ static void remember_info_file (FILE_BUFFER *file_buffer); static void free_file_buffer_tags (FILE_BUFFER *file_buffer); -static void free_info_tag (TAG *tag); +static void free_info_tag (NODE *tag); static void get_nodes_of_tags_table (FILE_BUFFER *file_buffer, SEARCH_BINDING *buffer_binding); static void get_nodes_of_info_file (FILE_BUFFER *file_buffer); @@ -510,7 +510,7 @@ build_tags_and_nodes (FILE_BUFFER *file_buffer) get_nodes_of_info_file (file_buffer); } -/* Search through FILE_BUFFER->contents building an array of TAG *, +/* Search through FILE_BUFFER->contents building an array of NODE *, one entry per each node present in the file. Store the tags in FILE_BUFFER->tags, and the number of allocated slots in FILE_BUFFER->tags_slots. */ @@ -530,7 +530,7 @@ get_nodes_of_info_file (FILE_BUFFER *file_buffer) { int start, end; char *nodeline; - TAG *entry; + NODE *entry; int anchor = 0; /* Skip past the characters just found. */ @@ -563,7 +563,7 @@ get_nodes_of_info_file (FILE_BUFFER *file_buffer) /* Okay, we have isolated the node name, and we know where the node starts. Remember this information. */ - entry = xmalloc (sizeof (TAG)); + entry = xmalloc (sizeof (NODE)); entry->content_cache = NULL; entry->nodename = xmalloc (1 + (end - start)); strncpy (entry->nodename, nodeline + start, end - start); @@ -637,7 +637,7 @@ get_nodes_of_tags_table (FILE_BUFFER *file_buffer, Do each line until we find one that doesn't contain a node name. */ while (search_forward ("\n", tmp_search, &position) == search_success) { - TAG *entry; + NODE *entry; char *nodedef; unsigned p; int anchor = 0; @@ -668,7 +668,7 @@ get_nodes_of_tags_table (FILE_BUFFER *file_buffer, if (name_offset == -1) break; - entry = xmalloc (sizeof (TAG)); + entry = xmalloc (sizeof (NODE)); entry->content_cache = NULL; /* Find the beginning of the node definition. */ @@ -721,7 +721,7 @@ get_tags_of_indirect_tags_table (FILE_BUFFER *file_buffer, int i; SUBFILE **subfiles = NULL; size_t subfiles_index = 0, subfiles_slots = 0; - TAG *entry; + NODE *entry; /* First get the list of tags from the tags table. Then lookup the associated file in the indirect list for each tag, and update it. */ @@ -861,8 +861,7 @@ get_tags_of_indirect_tags_table (FILE_BUFFER *file_buffer, entry->nodestart -= subfiles[i - 1]->first_byte; entry->nodestart += header_length; } - - /* We have successfully built the tags table. Remember that it + /* We have successfully built the tags table. Remember that it was indirect. */ file_buffer->flags |= N_TagsIndirect; } @@ -881,16 +880,16 @@ get_tags_of_indirect_tags_table (FILE_BUFFER *file_buffer, /* Return the node that contains TAG in FILE_BUFFER, else (pathologically) NULL. Called from info_node_of_file_buffer_tags. */ static NODE * -find_node_of_anchor (FILE_BUFFER *file_buffer, TAG *tag) +find_node_of_anchor (FILE_BUFFER *file_buffer, NODE *tag) { int anchor_pos, node_pos; - TAG *node_tag; + NODE *node_tag; NODE *node; /* Look through the tag list for the anchor. */ for (anchor_pos = 0; file_buffer->tags[anchor_pos]; anchor_pos++) { - TAG *t = file_buffer->tags[anchor_pos]; + NODE *t = file_buffer->tags[anchor_pos]; if (t->nodestart == tag->nodestart) break; } @@ -951,7 +950,7 @@ find_node_of_anchor (FILE_BUFFER *file_buffer, TAG *tag) static NODE * info_node_of_file_buffer_tags (FILE_BUFFER *file_buffer, char *nodename) { - TAG *tag; + NODE *tag; int i; /* If no tags at all (possibly a misformatted info file), quit. */ @@ -979,10 +978,12 @@ info_node_of_file_buffer_tags (FILE_BUFFER *file_buffer, char *nodename) if (!(tag->nodestart >= 0 && tag->nodestart < subfile->filesize)) return NULL; - node = xmalloc (sizeof (NODE)); - node->filename = subfile->fullpath; - node->parent = NULL; - node->nodename = tag->nodename; + /* FIXME: why not just copy the NODE structure instead of + assigning the fields individually? */ + node = xmalloc (sizeof (NODE)); + node->filename = subfile->fullpath; + node->parent = NULL; + node->nodename = tag->nodename; if (tag->content_cache) node->contents = tag->content_cache; @@ -1161,7 +1162,7 @@ free_file_buffer_tags (FILE_BUFFER *file_buffer) if (file_buffer->tags) { - TAG *tag; + NODE *tag; for (i = 0; (tag = file_buffer->tags[i]); i++) free_info_tag (tag); @@ -1183,7 +1184,7 @@ free_file_buffer_tags (FILE_BUFFER *file_buffer) /* Free the data associated with TAG, as well as TAG itself. */ static void -free_info_tag (TAG *tag) +free_info_tag (NODE *tag) { free (tag->nodename); free (tag->content_cache); diff --git a/nodes.h b/nodes.h index 36fa741..ca45eb4 100644 --- a/nodes.h +++ b/nodes.h @@ -39,10 +39,14 @@ typedef struct { char *parent; /* Non-null is the logical file name. */ char *nodename; /* The name of this node. */ char *contents; /* Characters appearing in this node. */ - long nodelen; /* The length of the CONTENTS member. */ + size_t nodelen; /* The length of the CONTENTS member. */ unsigned long display_pos; /* Where to display at, if nonzero. */ long body_start; /* Offset of the actual node body */ int flags; /* See immediately below. */ + long nodestart; /* The offset of the start of this node. */ + char *content_cache; /* Cache of the node contents; used if the + node contents must be preprocessed before + displaying it. */ } NODE; /* Defines that can appear in NODE->flags. All informative. */ @@ -78,23 +82,6 @@ typedef struct { #define INFO_FF '\014' #define INFO_TAGSEP '\177' -/* For each logical file that we have loaded, we keep a list of the names - of the nodes that are found in that file. A pointer to a node in an - info file is called a "tag". For split files, the tag pointer is - "indirect"; that is, the pointer also contains the name of the split - file where the node can be found. For non-split files, the filename - member in the structure below simply contains the name of the current - file. The following structure describes a single node within a file. */ -typedef struct { - char *filename; /* The file where this node can be found. */ - char *nodename; /* The node pointed to by this tag. */ - long nodestart; /* The offset of the start of this node. */ - size_t nodelen; /* The length of this node. */ - char *content_cache; /* Cache of the node contents; used if the - node contents must be preprocessed before - displaying it. */ -} TAG; - /* The following structure is used to remember information about the contents of Info files that we have loaded at least once before. The FINFO member is present so that we can reload the file if it has been modified since @@ -109,7 +96,7 @@ typedef struct { char *contents; /* The contents of this particular file. */ size_t filesize; /* The number of bytes this file expands to. */ char **subfiles; /* If non-null, the list of subfiles. */ - TAG **tags; /* If non-null, the indirect tags table. */ + NODE **tags; /* If non-null, the indirect tags table. */ size_t tags_slots; /* Number of slots allocated for TAGS. */ int flags; /* Various flags. Mimics of N_* flags. */ } FILE_BUFFER; diff --git a/session.c b/session.c index 7510bf6..7661d01 100644 --- a/session.c +++ b/session.c @@ -3979,7 +3979,7 @@ info_search_internal (char *string, WINDOW *window, { register int current_tag = 0, number_of_tags; char *last_subfile; - TAG *tag; + NODE *tag; char *msg = NULL; /* Find number of tags and current tag. */