[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[5490] simplify dir node retrieval slightly
From: |
Gavin D. Smith |
Subject: |
[5490] simplify dir node retrieval slightly |
Date: |
Thu, 24 Apr 2014 13:36:41 +0000 |
Revision: 5490
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5490
Author: gavin
Date: 2014-04-24 13:36:40 +0000 (Thu, 24 Apr 2014)
Log Message:
-----------
simplify dir node retrieval slightly
Modified Paths:
--------------
trunk/ChangeLog
trunk/info/dir.c
trunk/info/info-utils.c
trunk/info/info.c
trunk/info/info.h
trunk/info/man.c
trunk/info/nodes.c
trunk/info/nodes.h
trunk/info/session.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2014-04-23 22:44:01 UTC (rev 5489)
+++ trunk/ChangeLog 2014-04-24 13:36:40 UTC (rev 5490)
@@ -1,3 +1,26 @@
+2014-04-24 Gavin Smith <address@hidden>
+
+ * info/info.h [HANDLE_MAN_PAGES]: #define removed. All
+ usages updated.
+
+ * info/man.c (get_manpage_node): Use correct variable.
+
+ * info/nodes.c (info_load_file, get_node_length): Declared static.
+
+ * info/session.c (nearest_xref): Unused function deleted.
+
+ * info/dir.c (maybe_create_dir_node, dir_node, create_dir_buffer)
+ (build_dir_node): maybe_create_dir_node split up and behaviour
+ changed.
+ (dir_buffer): New file-level variable.
+ (insert_text_into_fb_at_binding, insert_text_into_node): Renamed
+ and arguments changed.
+ (add_menu_to_file_buffer, add_menu_to_node): Renamed and arguments
+ changed.
+ * info/nodes.c (info_find_file_internal): Special treatment of
+ dir file buffers removed.
+ (info_get_node_with_defaults): Call dir_node to get dir node.
+
2014-04-23 Gavin Smith <address@hidden>
* info/info-utils.c (info_parse_node): Don't use saven_filename
Modified: trunk/info/dir.c
===================================================================
--- trunk/info/dir.c 2014-04-23 22:44:01 UTC (rev 5489)
+++ trunk/info/dir.c 2014-04-24 13:36:40 UTC (rev 5490)
@@ -28,16 +28,15 @@
with the addition of the menus of every file named in the array
dirs_to_add which are found in INFOPATH. */
-static void add_menu_to_file_buffer (char *contents, size_t size,
- FILE_BUFFER *fb);
-static void insert_text_into_fb_at_binding (FILE_BUFFER *fb,
- SEARCH_BINDING *binding, char *text, int textlen);
-void maybe_build_dir_node (char *dirname);
+static void add_menu_to_node (char *contents, size_t size, NODE *node);
+static void insert_text_into_node (NODE *node, long start,
+ char *text, int textlen);
static char *dirs_to_add[] = {
"dir", "localdir", NULL
};
+FILE_BUFFER *dir_buffer = 0;
/* Return zero if the file represented in the stat structure TEST has
already been seen, nonzero otherwise. */
@@ -74,29 +73,73 @@
return 1;
}
+static void create_dir_buffer (void);
+static NODE *build_dir_node (void);
-void
-maybe_build_dir_node (char *dirname)
+NODE *
+dir_node (char *dirname)
{
+ NODE *node;
+
+ if (!dir_buffer)
+ create_dir_buffer ();
+
+ if (!dir_buffer->tags || !dir_buffer->tags[0])
+ {
+ NODE *tag;
+ int i = 0;
+ tag = build_dir_node ();
+ /* Create and save dir node. */
+ add_pointer_to_array (tag, i,
+ dir_buffer->tags,
+ dir_buffer->tags_slots, 2);
+ }
+
+ node = xmalloc (sizeof (NODE));
+ *node = *dir_buffer->tags[0]; /* Only one entry in tags table. */
+ return node;
+}
+
+static void
+create_dir_buffer (void)
+{
+ dir_buffer = make_file_buffer ();
+ dir_buffer->filename = xstrdup ("dir");
+ dir_buffer->fullpath = xstrdup ("dir");
+ dir_buffer->finfo.st_size = 0;
+ dir_buffer->filesize = 0;
+ dir_buffer->contents = NULL;
+ dir_buffer->flags = (N_IsInternal | N_CannotGC);
+
+ /* Initialize empty tags table. */
+ dir_buffer->tags = xmalloc (sizeof (NODE *));
+ dir_buffer->tags[0] = 0;
+}
+
+static NODE *
+build_dir_node (void)
+{
int path_index, update_tags;
char *this_dir;
- FILE_BUFFER *dir_buffer = info_find_file (dirname);
+ NODE *node;
- /* If there is no "dir" in the current info path, we cannot build one
- from nothing. */
- if (!dir_buffer)
- return;
+ node = info_create_node ();
+ node->nodename = xstrdup ("dir");
+ node->filename = xstrdup ("dir");
+ node->contents = xstrdup (
+ " File: dir, Node: Top This is the top of the INFO tree\n"
+ "\n"
+ "This (the Directory node) gives a menu of major topics.\n"
+ "Typing \"q\" exits, \"?\" lists all Info commands, \"d\" returns here,\n"
+ "\"h\" gives a primer for first-timers,\n"
+ "\"mEmacs<Return>\" visits the Emacs manual, etc.\n"
+ "\n"
+ "In Emacs, you can click mouse button 2 on a menu item or cross reference\n"
+ "to select it.\n"
+ );
- /* If this directory has already been built, return now. */
- if (dir_buffer->flags & N_CannotGC)
- return;
+ node->nodelen = strlen (node->contents);
- /* Initialize the list we use to avoid reading the same dir file twice
- with the dir file just found. */
- new_dir_file_p (&dir_buffer->finfo);
-
- update_tags = 0;
-
/* Using each element of the path, check for one of the files in
DIRS_TO_ADD. Do not check for "localdir.info.Z" or anything else.
Only files explictly named are eligible. This is a design decision.
@@ -146,8 +189,7 @@
&finfo, &compressed);
if (contents)
{
- update_tags++;
- add_menu_to_file_buffer (contents, filesize, dir_buffer);
+ add_menu_to_node (contents, filesize, node);
free (contents);
}
}
@@ -157,18 +199,20 @@
free (this_dir);
}
- if (update_tags)
- build_tags_and_nodes (dir_buffer);
-
- /* Flag that the dir buffer has been built. */
- dir_buffer->flags |= N_CannotGC;
+ {
+ char *old_contents = node->contents;
+ scan_node_contents (0, &node);
+ if (node->flags & N_WasRewritten)
+ free (old_contents);
+ }
+ return node;
}
/* Given CONTENTS and FB (a file buffer), add the menu found in CONTENTS
to the menu found in FB->contents. Second argument SIZE is the total
size of CONTENTS. */
static void
-add_menu_to_file_buffer (char *contents, size_t size, FILE_BUFFER *fb)
+add_menu_to_node (char *contents, size_t size, NODE *node)
{
SEARCH_BINDING contents_binding, fb_binding;
long contents_offset, fb_offset;
@@ -178,9 +222,9 @@
contents_binding.end = size;
contents_binding.flags = S_FoldCase | S_SkipDest;
- fb_binding.buffer = fb->contents;
+ fb_binding.buffer = node->contents;
fb_binding.start = 0;
- fb_binding.end = fb->filesize;
+ fb_binding.end = node->nodelen;
fb_binding.flags = S_FoldCase | S_SkipDest;
/* Move to the start of the menus in CONTENTS and FB. */
@@ -198,35 +242,14 @@
if (search_forward (INFO_MENU_LABEL, &fb_binding, &fb_offset)
!= search_success)
{
- /* Find the start of the second node in this file buffer. If there
- is only one node, we will be adding the contents to the end of
- this node. */
- fb_offset = find_node_separator (&fb_binding);
+ fb_binding.start = node->nodelen;
- /* If not even a single node separator, give up. */
- if (fb_offset == -1)
- return;
+ insert_text_into_node
+ (node, fb_binding.start, INFO_MENU_LABEL, strlen (INFO_MENU_LABEL));
- fb_binding.start = fb_offset;
- fb_binding.start +=
- skip_node_separator (fb_binding.buffer + fb_binding.start);
-
- /* Try to find the next node separator. */
- fb_offset = find_node_separator (&fb_binding);
-
- /* If found one, consider that the start of the menu. Otherwise, the
- start of this menu is the end of the file buffer (i.e., fb->size). */
- if (fb_offset != -1)
- fb_binding.start = fb_offset;
- else
- fb_binding.start = fb_binding.end;
-
- insert_text_into_fb_at_binding
- (fb, &fb_binding, INFO_MENU_LABEL, strlen (INFO_MENU_LABEL));
-
- fb_binding.buffer = fb->contents;
+ fb_binding.buffer = node->contents;
fb_binding.start = 0;
- fb_binding.end = fb->filesize;
+ fb_binding.end = node->nodelen;
if (search_forward (INFO_MENU_LABEL, &fb_binding, &fb_offset)
!= search_success)
abort ();
@@ -262,32 +285,29 @@
else
{
/* Do it the hard way. */
- insert_text_into_fb_at_binding (fb, &fb_binding, "\n\n", 2);
+ insert_text_into_node (node, fb_binding.start, "\n\n", 2);
fb_binding.start += 2;
}
}
/* Insert the new menu. */
- insert_text_into_fb_at_binding
- (fb, &fb_binding, contents + contents_offset, size - contents_offset);
+ insert_text_into_node
+ (node, fb_binding.start, contents + contents_offset, size -
contents_offset);
}
static void
-insert_text_into_fb_at_binding (FILE_BUFFER *fb,
- SEARCH_BINDING *binding, char *text, int textlen)
+insert_text_into_node (NODE *node, long start, char *text, int textlen)
{
char *contents;
- long start, end;
+ long end;
- start = binding->start;
- end = fb->filesize;
+ end = node->nodelen;
- contents = xmalloc (fb->filesize + textlen + 1);
- memcpy (contents, fb->contents, start);
+ contents = xmalloc (node->nodelen + textlen + 1);
+ memcpy (contents, node->contents, start);
memcpy (contents + start, text, textlen);
- memcpy (contents + start + textlen, fb->contents + start, end - start);
- free (fb->contents);
- fb->contents = contents;
- fb->filesize += textlen;
- fb->finfo.st_size = fb->filesize;
+ memcpy (contents + start + textlen, node->contents + start, end - start);
+ free (node->contents);
+ node->contents = contents;
+ node->nodelen += textlen;
}
Modified: trunk/info/info-utils.c
===================================================================
--- trunk/info/info-utils.c 2014-04-23 22:44:01 UTC (rev 5489)
+++ trunk/info/info-utils.c 2014-04-24 13:36:40 UTC (rev 5490)
@@ -29,10 +29,6 @@
# include <iconv.h>
#endif
-#if defined (HANDLE_MAN_PAGES)
-# include "man.h"
-#endif /* HANDLE_MAN_PAGES */
-
#ifdef __hpux
#define va_copy(ap1,ap2) memcpy((&ap1),(&ap2),sizeof(va_list))
#endif
Modified: trunk/info/info.c
===================================================================
--- trunk/info/info.c 2014-04-23 22:44:01 UTC (rev 5489)
+++ trunk/info/info.c 2014-04-24 13:36:40 UTC (rev 5490)
@@ -25,9 +25,6 @@
#include "dribble.h"
#include "getopt.h"
#include "variables.h"
-#if defined (HANDLE_MAN_PAGES)
-# include "man.h"
-#endif /* HANDLE_MAN_PAGES */
char *program_name = "info";
Modified: trunk/info/info.h
===================================================================
--- trunk/info/info.h 2014-04-23 22:44:01 UTC (rev 5489)
+++ trunk/info/info.h 2014-04-24 13:36:40 UTC (rev 5490)
@@ -23,7 +23,6 @@
#define INFO_H
/* We always want these, so why clutter up the compile command? */
-#define HANDLE_MAN_PAGES
#define NAMED_FUNCTIONS
#define INFOKEY
Modified: trunk/info/man.c
===================================================================
--- trunk/info/man.c 2014-04-23 22:44:01 UTC (rev 5489)
+++ trunk/info/man.c 2014-04-24 13:36:40 UTC (rev 5490)
@@ -87,7 +87,6 @@
tag->filename = MANPAGE_FILE_BUFFER_NAME;
tag->nodename = xstrdup (pagename);
tag->flags |= (N_HasTagsTable | N_IsManPage);
- tag->contents = 0;
tag->up = "(dir)";
@@ -117,8 +116,8 @@
hlen = strlen (header);
tag->contents = xcalloc (1, hlen + plen + 1);
- memcpy (node->contents, header, hlen);
- memcpy (node->contents + hlen, page, plen);
+ memcpy (tag->contents, header, hlen);
+ memcpy (tag->contents + hlen, page, plen);
/* Set nodelen. */
tag->nodelen = hlen + plen;
Modified: trunk/info/nodes.c
===================================================================
--- trunk/info/nodes.c 2014-04-23 22:44:01 UTC (rev 5489)
+++ trunk/info/nodes.c 2014-04-24 13:36:40 UTC (rev 5490)
@@ -26,11 +26,8 @@
#include "filesys.h"
#include "info-utils.h"
#include "tag.h"
+#include "man.h"
-#if defined (HANDLE_MAN_PAGES)
-# include "man.h"
-#endif /* HANDLE_MAN_PAGES */
-
/* Global variables. */
@@ -575,6 +572,7 @@
static FILE_BUFFER *info_find_file_internal (char *filename, int get_tags);
static void get_file_character_encoding (FILE_BUFFER *fb);
+static FILE_BUFFER *info_load_file (char *filename);
static FILE_BUFFER *info_load_file_internal (char *filename, int get_tags);
static void remember_info_file (FILE_BUFFER *file_buffer);
static void info_reload_file_buffer_contents (FILE_BUFFER *fb);
@@ -590,9 +588,10 @@
return info_find_file_internal (filename, INFO_GET_TAGS);
}
-/* Load the info file FILENAME, remembering information about it in a
- file buffer. */
-FILE_BUFFER *
+/* Force load the file named FILENAME, and return the information structure
+ describing this file. Even if the file was already loaded, this loads
+ a new buffer, rebuilds tags and nodes, and returns a new FILE_BUFFER *. */
+static FILE_BUFFER *
info_load_file (char *filename)
{
return info_load_file_internal (filename, INFO_GET_TAGS);
@@ -622,13 +621,8 @@
{
struct stat new_info, *old_info;
- /* This file is loaded. If the filename that we want is
- specifically "dir", then simply return the file buffer. */
- if (is_dir_name (filename_non_directory (filename)))
- return file_buffer;
-
- /* The file appears to be already loaded, and is not "dir". Check
- to see if it's changed since the last time it was loaded. */
+ /* Check to see if the file has changed since the last
+ time it was loaded. */
if (stat (file_buffer->fullpath, &new_info) == -1)
{
filesys_error_number = errno;
@@ -895,6 +889,7 @@
/* Functions for node creation and retrieval. */
+static long get_node_length (SEARCH_BINDING *binding);
static int get_filename_and_nodename (int flag, WINDOW *window,
char **filename, char **nodename,
char *filename_in, char *nodename_in);
@@ -927,7 +922,7 @@
}
/* Return the length of the node which starts at BINDING. */
-long
+static long
get_node_length (SEARCH_BINDING *binding)
{
int i;
@@ -959,7 +954,7 @@
char *filename = 0, *nodename = 0;
/* Used to build `dir' menu from `localdir' files found in INFOPATH. */
- extern void maybe_build_dir_node (char *dirname);
+ extern NODE *dir_node (void);
info_recent_file_error = NULL;
@@ -969,15 +964,16 @@
/* If the file to be looked up is "dir", build the contents from all of
the "dir"s and "localdir"s found in INFOPATH. */
if (is_dir_name (filename))
- maybe_build_dir_node (filename);
+ {
+ node = dir_node ();
+ goto cleanup_and_exit;
+ }
-#ifdef HANDLE_MAN_PAGES
if (mbscasecmp (filename, MANPAGE_FILE_BUFFER_NAME) == 0)
{
node = get_manpage_node (nodename);
goto cleanup_and_exit;
}
-#endif
/* Find the correct info file, or give up. */
file_buffer = info_find_file (filename);
@@ -987,7 +983,6 @@
node = info_get_node_of_file_buffer (nodename, file_buffer);
}
-#ifdef HANDLE_MAN_PAGES
if (!file_buffer)
{
/* Try to find a man page with this name as a fall back. */
@@ -999,7 +994,6 @@
filesys_error_string (filename, filesys_error_number);
}
}
-#endif
/* If the node not found was "Top", try again with different case. */
if (!node && (nodename && mbscasecmp (nodename, "Top") == 0))
Modified: trunk/info/nodes.h
===================================================================
--- trunk/info/nodes.h 2014-04-23 22:44:01 UTC (rev 5489)
+++ trunk/info/nodes.h 2014-04-24 13:36:40 UTC (rev 5490)
@@ -136,9 +136,6 @@
/* 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;
@@ -152,11 +149,6 @@
return a NULL FILE_BUFFER *. */
extern FILE_BUFFER *info_find_file (char *filename);
-/* Force load the file named FILENAME, and return the information structure
- describing this file. Even if the file was already loaded, this loads
- a new buffer, rebuilds tags and nodes, and returns a new FILE_BUFFER *. */
-extern FILE_BUFFER *info_load_file (char *filename);
-
/* Return a pointer to a new NODE structure. */
extern NODE *info_create_node (void);
Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c 2014-04-23 22:44:01 UTC (rev 5489)
+++ trunk/info/session.c 2014-04-24 13:36:40 UTC (rev 5490)
@@ -21,6 +21,7 @@
#include "info.h"
#include "search.h"
+#include "man.h"
#ifndef __MINGW32__
#include <sys/ioctl.h>
@@ -35,10 +36,6 @@
# define HAVE_STRUCT_TIMEVAL
#endif /* HAVE_SYS_TIME_H */
-#if defined (HANDLE_MAN_PAGES)
-# include "man.h"
-#endif
-
static void info_gc_file_buffers (void);
static void info_clear_pending_input (void);
@@ -2317,68 +2314,6 @@
return;
}
-/* Return a pointer to the xref in XREF_LIST that is nearest to POS, or
- NULL if XREF_LIST is empty. That is, if POS is within any of the
- given xrefs, return that one. Otherwise, return the one with the
- nearest beginning or end. If there are two that are equidistant,
- prefer the one forward. The return is in newly-allocated memory,
- since the caller frees it.
-
- This is called from info_menu_or_ref_item with XREF_LIST being all
- the xrefs in the node, and POS being point. The ui function that
- starts it all off is select-reference-this-line.
-
- This is not the same logic as in info.el. Info-get-token prefers
- searching backwards to searching forwards, and has a hardwired search
- limit of 200 chars (in Emacs 21.2). */
-
-static REFERENCE **
-nearest_xref (REFERENCE **xref_list, long int pos)
-{
- int this_xref;
- int nearest = -1;
- long best_delta = -1;
-
- for (this_xref = 0; xref_list[this_xref]; this_xref++)
- {
- long delta;
- REFERENCE *xref = xref_list[this_xref];
- if (xref->start <= pos && pos <= xref->end)
- { /* POS is within this xref, we're done */
- nearest = this_xref;
- break;
- }
-
- /* See how far POS is from this xref. Take into account the
- `*Note' that begins the xref, since as far as the user is
- concerned, that's where it starts. */
- delta = MIN (labs (pos - (xref->start - strlen (INFO_XREF_LABEL))),
- labs (pos - xref->end));
-
- /* It's the <= instead of < that makes us choose the forward xref
- of POS if two are equidistant. Of course, because of all the
- punctuation surrounding xrefs, it's not necessarily obvious
- where one ends. */
- if (delta <= best_delta || best_delta < 0)
- {
- nearest = this_xref;
- best_delta = delta;
- }
- }
-
- /* Maybe there was no list to search through. */
- if (nearest < 0)
- return NULL;
-
- /* Ok, we have a nearest xref, make a list of it. */
- {
- REFERENCE **ret = xmalloc (sizeof (REFERENCE *) * 2);
- ret[0] = info_copy_reference (xref_list[nearest]);
- ret[1] = NULL;
- return ret;
- }
-}
-
static int exclude_cross_references (REFERENCE *r)
{
return r->type == REFERENCE_XREF;
@@ -3260,7 +3195,6 @@
free (default_program_name);
}
-#if defined (HANDLE_MAN_PAGES)
DECLARE_INFO_COMMAND (info_man, _("Read a manpage reference and select it"))
{
char *line;
@@ -3286,7 +3220,6 @@
if (!info_error_was_printed)
window_clear_echo_area ();
}
-#endif /* HANDLE_MAN_PAGES */
/* Move to the "Top" node in this file. */
DECLARE_INFO_COMMAND (info_top_node, _("Select the node `Top' in this file"))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [5490] simplify dir node retrieval slightly,
Gavin D. Smith <=