commit 2a5b217c3f70c00599e85187a964d3e3f6c30717 Author: Gavin Smith Date: Sun Mar 9 17:56:59 2014 +0000 Miscellaneous changes - * indices.c (info_indices_of_file_buffer): Quit if node is an anchor * info-utils.c (info_get_labeled_reference): Only look for menu items. * indices.c (apropos_in_all_indices): Free each file buffer after indices are read from file. * info-utils.c (info_concatenate_references) Do not free second argument and duplicate all strings which are fields in REFERENCE's found from the second argument. This allows freeing file structures in apropos_in_all_indices. * man.c (manpage_node_of_file_buffer): Set nodelen field in returned NODE. (xrefs_of_manpage): If no references, return array with a single null entry instead of null. Set type fields to REFERENCE_XREF. * nodes.c (get_node_length): Function no longer static. * window.c: (window_make_modeline) If preprocess_nodes_p is set, display less information in status bar. diff --git a/indices.c b/indices.c index 4e61a59..c516bd6 100644 --- a/indices.c +++ b/indices.c @@ -55,7 +55,8 @@ static size_t index_nodenames_index = 0; static size_t index_nodenames_slots = 0; /* Add the name of NODE, and the range of the associated index elements - (passed in ARRAY) to index_nodenames. */ + (passed in ARRAY) to index_nodenames. ARRAY must have at least one + element. */ static void add_index_to_index_nodenames (REFERENCE **array, NODE *node) { @@ -136,6 +137,10 @@ info_indices_of_file_buffer (FILE_BUFFER *file_buffer) NODE *node; REFERENCE **menu; + /* If this is an anchor, don't bother. */ + if (tag->nodelen == 0) continue; + + /* FIXME: Just do node = tag; ??? */ /* Found one. Get its menu. */ node = info_get_node (tag->filename, tag->nodename, PARSE_NODE_VERBATIM); @@ -588,9 +593,9 @@ apropos_in_all_indices (char *search_string, int inform) continue; } + char *files_name; /* Get the file buffer associated with this node. */ { - char *files_name; files_name = this_node->parent; if (!files_name) @@ -631,6 +636,8 @@ apropos_in_all_indices (char *search_string, int inform) /* Concatenate with the other indices. */ all_indices = info_concatenate_references (all_indices, this_index); } + /* Try to avoid running out of memory */ + forget_info_file (files_name); } /* Build a list of the references which contain SEARCH_STRING. */ diff --git a/info-utils.c b/info-utils.c index c23f65c..d33197a 100644 --- a/info-utils.c +++ b/info-utils.c @@ -190,6 +190,7 @@ info_get_labeled_reference (char *label, REFERENCE **references) for (i = 0; references && (entry = references[i]); i++) { + if (REFERENCE_MENU_ITEM != entry->type) continue; if (strcmp (label, entry->label) == 0) return entry; } @@ -198,7 +199,7 @@ info_get_labeled_reference (char *label, REFERENCE **references) /* A utility function for concatenating REFERENCE **. Returns a new REFERENCE ** which is the concatenation of REF1 and REF2. The REF1 - and REF2 arrays are freed, but their contents are not. */ + array is freed, but its contents are not. REF2 is not freed. */ REFERENCE ** info_concatenate_references (REFERENCE **ref1, REFERENCE **ref2) { @@ -206,31 +207,46 @@ info_concatenate_references (REFERENCE **ref1, REFERENCE **ref2) REFERENCE **result; int size; - /* With one argument passed as NULL, simply return the other arg. */ - if (!ref1) - return ref2; - else if (!ref2) + if (!ref2) return ref1; /* Get the total size of the slots that we will need. */ - for (i = 0; ref1[i]; i++); - size = i; + size = 0; + if (ref1) + { + for (i = 0; ref1[i]; i++); + size += i; + } for (i = 0; ref2[i]; i++); size += i; result = xmalloc ((1 + size) * sizeof (REFERENCE *)); - /* Copy the contents over. */ - for (i = 0; ref1[i]; i++) - result[i] = ref1[i]; + i = 0; + if (ref1) + /* Copy the contents over. */ + for (i = 0; ref1[i]; i++) + result[i] = ref1[i]; j = i; for (i = 0; ref2[i]; i++) - result[j++] = ref2[i]; + { + result[j] = xmalloc (sizeof (REFERENCE)); + + /* Copy REFERENCE structure */ + *(result[j]) = *(ref2[i]); + + if (result[j]->label) + result[j]->label = xstrdup (ref2[i]->label); + if (result[j]->filename) + result[j]->filename = xstrdup (ref2[i]->filename); + if (result[j]->nodename) + result[j]->nodename = xstrdup (ref2[i]->nodename); + j++; + } result[j] = NULL; free (ref1); - free (ref2); return result; } diff --git a/man.c b/man.c index 068c653..ed3262e 100644 --- a/man.c +++ b/man.c @@ -33,6 +33,7 @@ #include "tilde.h" #include "man.h" +#include "variables.h" #if !defined (_POSIX_VERSION) #define pid_t int @@ -406,12 +407,32 @@ manpage_node_of_file_buffer (FILE_BUFFER *file_buffer, char *pagename) node->nodename = xstrdup (tag->nodename); node->contents = file_buffer->contents + tag->nodestart; node->nodelen = tag->nodelen; + node->nodestart = tag->nodestart; node->flags = 0; node->display_pos = 0; node->parent = NULL; node->flags = (N_HasTagsTable | N_IsManPage); node->contents += skip_node_separator (node->contents); node->body_start = strcspn(node->contents, "\n"); + + node->up = "(dir)"; + node->prev = 0; + node->next = 0; + + /* Set nodelen, which is currently (size_t) -1. */ + + { + SEARCH_BINDING node_body; + + node_body.buffer = file_buffer->contents; + node_body.start = node->nodestart; + node_body.start += skip_node_separator (file_buffer->contents + node->nodestart); + node_body.end = file_buffer->filesize; + node_body.flags = S_FoldCase; + node->nodelen = get_node_length (&node_body); + + node->references = xrefs_of_manpage (node); + } } return node; @@ -545,10 +566,14 @@ xrefs_of_manpage (NODE *node) size_t refs_slots = 0; long position; + /* Initialize reference list to have a single null entry. */ + refs = calloc(1, sizeof (REFERENCE *)); + refs_slots = 1; + reference_section = find_reference_section (node); if (reference_section == NULL) - return NULL; + return refs; /* Grovel the reference section building a list of references found there. A reference is alphabetic characters followed by non-whitespace text @@ -593,6 +618,7 @@ xrefs_of_manpage (NODE *node) entry->nodename = xstrdup (entry->label); entry->start = start; entry->end = end; + entry->type = REFERENCE_XREF; add_pointer_to_array (entry, refs_index, refs, refs_slots, 10); } diff --git a/nodemenu.c b/nodemenu.c index 452fa55..b06c858 100644 --- a/nodemenu.c +++ b/nodemenu.c @@ -20,6 +20,7 @@ Originally written by Brian Fox. */ #include "info.h" +#include "variables.h" NODE *get_visited_nodes (Function *filter_func); @@ -195,6 +196,13 @@ get_visited_nodes (Function *filter_func) initialize_message_buffer (); + if (preprocess_nodes_p) { + /* Lead with a blank line so that if parse_node strips out the + first line, thinking it is a node information line (containing + File:", "Node:", etc.), nothing important will disappear. */ + printf_to_message_buffer ("\n", replace_in_documentation); + } + printf_to_message_buffer ("%s", replace_in_documentation (_("Here is the menu of nodes you have recently visited.\n\ @@ -212,7 +220,7 @@ Select one from this menu, or use `\\[history-node]' in another window.\n"), 0)) free (lines); node = message_buffer_to_node (); - add_gcable_pointer (node->contents); + return node; } diff --git a/nodes.c b/nodes.c index f0ee414..0399ab9 100644 --- a/nodes.c +++ b/nodes.c @@ -47,8 +47,6 @@ static FILE_BUFFER *info_find_file_internal (char *filename, int get_tags); static NODE *info_node_of_file_buffer_tags (FILE_BUFFER *file_buffer, char *nodename); -static long get_node_length (SEARCH_BINDING *binding); - /* Magic number that RMS used to decide how much a tags table pointer could be off by. I feel that it should be much smaller, like 4. */ #define DEFAULT_INFO_FUDGE 1000 @@ -609,7 +607,7 @@ get_nodes_of_info_file (FILE_BUFFER *file_buffer) } /* Return the length of the node which starts at BINDING. */ -static long +long get_node_length (SEARCH_BINDING *binding) { int i; @@ -1182,7 +1180,7 @@ forget_info_file (char *filename) } /* Free the tags (if any) associated with FILE_BUFFER. */ -static void +void free_file_buffer_tags (FILE_BUFFER *file_buffer) { int i; diff --git a/nodes.h b/nodes.h index c4885d7..5f0a23d 100644 --- a/nodes.h +++ b/nodes.h @@ -23,6 +23,7 @@ #define NODES_H #include "info.h" +#include "search.h" /* User code interface. */ @@ -124,6 +125,9 @@ typedef struct { /* Externally visible functions. */ +/* Return the length of the node which starts at BINDING. */ +long get_node_length (SEARCH_BINDING *binding); + /* Array of FILE_BUFFER * which represents the currently loaded info files. */ extern FILE_BUFFER **info_loaded_files; diff --git a/session.c b/session.c index 83af1d1..868964e 100644 --- a/session.c +++ b/session.c @@ -21,6 +21,8 @@ #include "info.h" #include "search.h" +#include "variables.h" + #ifndef __MINGW32__ #include #endif diff --git a/window.c b/window.c index 52ec24c..1e27041 100644 --- a/window.c +++ b/window.c @@ -26,6 +26,7 @@ #include "info-utils.h" #include "infomap.h" #include "tag.h" +#include "variables.h" /* The window which describes the screen. */ WINDOW *the_screen = NULL; @@ -1067,7 +1068,6 @@ window_make_modeline (WINDOW *window) if (node->parent) { parent = filename_non_directory (node->parent); - modeline_len += strlen ("Subfile: ") + strlen (node->filename); } if (node->filename) @@ -1077,36 +1077,63 @@ window_make_modeline (WINDOW *window) update_message = _("--*** Tags out of Date ***"); } - if (update_message) - modeline_len += strlen (update_message); - modeline_len += strlen (filename); - modeline_len += strlen (nodename); - modeline_len += 4; /* strlen (location_indicator). */ - - /* 10 for the decimal representation of the number of lines in this - node, and the remainder of the text that can appear in the line. */ - modeline_len += 10 + strlen (_("-----Info: (), lines ----, ")); - modeline_len += window->width; - - modeline = xmalloc (1 + modeline_len); - - /* Special internal windows have no filename. */ - if (!parent && !*filename) - sprintf (modeline, _("-%s---Info: %s, %d lines --%s--"), - (window->flags & W_NoWrap) ? "$" : "-", - nodename, window->line_count, location_indicator); + if (preprocess_nodes_p) + { + modeline_len += strlen ("--() --"); + if (parent) modeline_len += strlen (parent); + if (filename) modeline_len += strlen (filename); + if (nodename) modeline_len += strlen (nodename); + modeline_len += 3; /* strlen (location_indicator) */ + if (modeline_len < window->width) + modeline_len = window->width; + + modeline = xmalloc (1 + modeline_len); + + sprintf (modeline, _("%s--(%s) %s--"), + location_indicator, + parent ? parent : filename ? filename : "", + nodename); + } else - sprintf (modeline, _("-%s%s-Info: (%s)%s, %d lines --%s--"), - (window->flags & W_NoWrap) ? "$" : "-", - (node && (node->flags & N_IsCompressed)) ? "zz" : "--", - parent ? parent : filename, - nodename, window->line_count, location_indicator); - - if (parent) - sprintf (modeline + strlen (modeline), _(" Subfile: %s"), filename); + { + if (node && node->parent) + modeline_len += strlen ("Subfile: ") + strlen (node->filename); - if (update_message) - sprintf (modeline + strlen (modeline), "%s", update_message); + if (update_message) + modeline_len += strlen (update_message); + modeline_len += strlen (filename); + modeline_len += strlen (nodename); + modeline_len += 4; /* strlen (location_indicator). */ + + /* 10 for the decimal representation of the number of lines in this + node, and the remainder of the text that can appear in the line. */ + modeline_len += 10 + strlen (_("-----Info: (), lines ----, ")); + modeline_len += window->width; + + modeline = xmalloc (1 + modeline_len); + + /* Special internal windows have no filename. */ + if (!parent && !*filename) + sprintf (modeline, _("-%s---Info: %s, %d lines --%s--"), + (window->flags & W_NoWrap) ? "$" : "-", + nodename, window->line_count, location_indicator); + else + sprintf (modeline, _("-%s%s-Info: (%s)%s, %d lines --%s--"), + (window->flags & W_NoWrap) ? "$" : "-", + (node && (node->flags & N_IsCompressed)) ? "zz" : "--", + parent ? parent : filename, + nodename, window->line_count, location_indicator); + + if (window->node->next) + sprintf (modeline + strlen (modeline), + "Next: %s--", window->node->next); + + if (parent) + sprintf (modeline + strlen (modeline), _(" Subfile: %s"), filename); + + if (update_message) + sprintf (modeline + strlen (modeline), "%s", update_message); + } i = strlen (modeline);