texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Gavin D. Smith
Date: Wed, 16 Mar 2022 16:35:35 -0400 (EDT)

branch: master
commit e2303c86eab4da9d07c8f90ef57fff2c119a4989
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Wed Mar 16 19:34:25 2022 +0000

    Split info/info-utils.c
    
    * info/info-utils.c, info/util.c:
    (file_buffer_of_window, node_printed_rep, filename_non_directory)
    (internal_info_node_p, name_internal_node, get_internal_info_window)
    (text_buffer_init, text_buffer_free, text_buffer_vprintf)
    (text_buffer_alloc, text_buffer_space_left, text_buffer_iconv)
    (text_buffer_add_string, text_buffer_fill, text_buffer_add_char)
    (text_buffer_printf, fncmp):
    New file util.c to hold some of the functions from info-utils.c.
    Include new header file where required.
---
 ChangeLog         |  14 +++
 info/Makefile.am  |   2 +-
 info/display.c    |   1 +
 info/echo-area.c  |   1 +
 info/footnotes.c  |   1 +
 info/indices.c    |   1 +
 info/info-utils.c | 250 +-----------------------------------------------------
 info/info-utils.h |  55 +-----------
 info/info.c       |   1 +
 info/infodoc.c    |   1 +
 info/infopath.c   |   1 +
 info/nodemenu.c   |   1 +
 info/nodes.c      |   1 +
 info/session.c    |   1 +
 info/tag.c        |   1 +
 info/util.h       |  64 ++++++++++++++
 info/window.c     |   1 +
 17 files changed, 93 insertions(+), 304 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3241b07ba9..f3bc3ea89e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2022-03-16  Gavin Smith  <gavinsmith0123@gmail.com>
+
+       Split info/info-utils.c
+
+       * info/info-utils.c, info/util.c:
+       (file_buffer_of_window, node_printed_rep, filename_non_directory)
+       (internal_info_node_p, name_internal_node, get_internal_info_window)
+       (text_buffer_init, text_buffer_free, text_buffer_vprintf)
+       (text_buffer_alloc, text_buffer_space_left, text_buffer_iconv)
+       (text_buffer_add_string, text_buffer_fill, text_buffer_add_char)
+       (text_buffer_printf, fncmp):
+       New file util.c to hold some of the functions from info-utils.c.
+       Include new header file where required.
+
 2022-03-16  Gavin Smith  <gavinsmith0123@gmail.com>
 
        Move functions
diff --git a/info/Makefile.am b/info/Makefile.am
index a64b52b124..15ad2714b0 100644
--- a/info/Makefile.am
+++ b/info/Makefile.am
@@ -36,7 +36,7 @@ ginfo_SOURCES = dir.c display.c display.h doc.h dribble.c 
dribble.h \
   infomap.c infomap.h infopath.c m-x.c man.c man.h nodemenu.c \
   nodes.c nodes.h search.c search.h session.c session.h signals.c signals.h \
   tag.c tag.h termdep.h terminal.c terminal.h tilde.c tilde.h \
-  variables.c variables.h window.c window.h
+  util.c util.h variables.c variables.h window.c window.h
 nodist_ginfo_SOURCES = doc.c funs.h
 
 # The files `doc.c' and `funs.h' are created by ./makedoc run over the
diff --git a/info/display.c b/info/display.c
index 4b8c932448..03508b6bef 100644
--- a/info/display.c
+++ b/info/display.c
@@ -20,6 +20,7 @@
 #include "info.h"
 #include "display.h"
 #include "session.h"
+#include "util.h"
 #include "tag.h"
 #include "signals.h"
 #include "variables.h"
diff --git a/info/echo-area.c b/info/echo-area.c
index 89296a7118..910297ec18 100644
--- a/info/echo-area.c
+++ b/info/echo-area.c
@@ -21,6 +21,7 @@
 #include "session.h"
 #include "display.h"
 #include "info-utils.h"
+#include "util.h"
 #include "echo-area.h"
 
 /* Non-zero means that C-g was used to quit reading input. */
diff --git a/info/footnotes.c b/info/footnotes.c
index aa7d2ea845..4f4bd19442 100644
--- a/info/footnotes.c
+++ b/info/footnotes.c
@@ -20,6 +20,7 @@
 #include "info.h"
 #include "session.h"
 #include "info-utils.h"
+#include "util.h"
 #include "footnotes.h"
 
 /* Nonzero means attempt to show footnotes when displaying a new window. */
diff --git a/info/indices.c b/info/indices.c
index f798c61290..078de86b4e 100644
--- a/info/indices.c
+++ b/info/indices.c
@@ -19,6 +19,7 @@
 
 #include "info.h"
 #include "info-utils.h"
+#include "util.h"
 #include "session.h"
 #include "echo-area.h"
 #include "indices.h"
diff --git a/info/info-utils.c b/info/info-utils.c
index 8d52bb6006..45cce26c33 100644
--- a/info/info-utils.c
+++ b/info/info-utils.c
@@ -20,6 +20,7 @@
 #include "info.h"
 #include "session.h"
 #include "info-utils.h"
+#include "util.h"
 #include "tag.h"
 
 #include <langinfo.h>
@@ -1780,252 +1781,3 @@ not_a_reference:
     }
 }
 
-
-/* Various utility functions */
-
-/* Return the file buffer which belongs to WINDOW's node. */
-FILE_BUFFER *
-file_buffer_of_window (WINDOW *window)
-{
-  /* If this window has no node, then it has no file buffer. */
-  if (!window->node)
-    return NULL;
-
-  if (window->node->fullpath)
-    return info_find_file (window->node->fullpath);
-
-  return NULL;
-}
-
-/* Return "(FILENAME)NODENAME" for NODE, or just "NODENAME" if NODE's
-   filename is not set.  Return value should not be freed. */
-char *
-node_printed_rep (NODE *node)
-{
-  static char *rep;
-
-  if (node->fullpath)
-    {
-      char *filename = filename_non_directory (node->fullpath);
-      rep = xrealloc (rep, 1 + strlen (filename) + 1 + strlen (node->nodename) 
+ 1);
-      sprintf (rep, "(%s)%s", filename, node->nodename);
-      return rep;
-    }
-  else
-    return node->nodename;
-}
-
-
-/* Return a pointer to the part of PATHNAME that simply defines the file. */
-char *
-filename_non_directory (char *pathname)
-{
-  register char *filename = pathname + strlen (pathname);
-
-  if (HAVE_DRIVE (pathname))
-    pathname += 2;
-
-  while (filename > pathname && !IS_SLASH (filename[-1]))
-    filename--;
-
-  return filename;
-}
-
-/* Return non-zero if NODE is one especially created by Info. */
-int
-internal_info_node_p (NODE *node)
-{
-  return (node != NULL) && (node->flags & N_IsInternal);
-}
-
-/* Make NODE appear to be one especially created by Info. */
-void
-name_internal_node (NODE *node, char *name)
-{
-  if (!node)
-    return;
-
-  node->fullpath = "";
-  node->subfile = 0;
-  node->nodename = name;
-  node->flags |= N_IsInternal;
-}
-
-/* Return the window displaying NAME, the name of an internally created
-   Info window. */
-WINDOW *
-get_internal_info_window (char *name)
-{
-  WINDOW *win;
-
-  for (win = windows; win; win = win->next)
-    if (internal_info_node_p (win->node) &&
-        (strcmp (win->node->nodename, name) == 0))
-      break;
-
-  return win;
-}
-
-/* Flexible Text Buffer */
-
-void
-text_buffer_init (struct text_buffer *buf)
-{
-  memset (buf, 0, sizeof *buf);
-}
-
-void
-text_buffer_free (struct text_buffer *buf)
-{
-  free (buf->base);
-}
-
-size_t
-text_buffer_vprintf (struct text_buffer *buf, const char *format, va_list ap)
-{
-  ssize_t n;
-  va_list ap_copy;
-
-  if (!buf->base)
-    {
-      if (buf->size == 0)
-       buf->size = MIN_TEXT_BUF_ALLOC; /* Initial allocation */
-      
-      buf->base = xmalloc (buf->size);
-    }
-  
-  for (;;)
-    {
-      va_copy (ap_copy, ap);
-      n = vsnprintf (buf->base + buf->off, buf->size - buf->off,
-                    format, ap_copy);
-      va_end (ap_copy);
-      if (n < 0 || buf->off + n >= buf->size ||
-         !memchr (buf->base + buf->off, '\0', buf->size - buf->off + 1))
-       {
-         size_t newlen = buf->size * 2;
-         if (newlen < buf->size)
-           xalloc_die ();
-         buf->size = newlen;
-         buf->base = xrealloc (buf->base, buf->size);
-       }
-      else
-       {
-         buf->off += n;
-         break;
-       }
-    }
-  return n;
-}
-
-/* Make sure there are LEN free bytes at end of BUF. */
-void
-text_buffer_alloc (struct text_buffer *buf, size_t len)
-{
-  if (buf->off + len > buf->size)
-    {
-      buf->size = buf->off + len;
-      if (buf->size < MIN_TEXT_BUF_ALLOC)
-       buf->size = MIN_TEXT_BUF_ALLOC;
-      buf->base = xrealloc (buf->base, buf->size);
-    }
-}
-
-/* Return number of bytes that can be written to text buffer without
-   reallocating the text buffer. */
-size_t
-text_buffer_space_left (struct text_buffer *buf)
-{
-  /* buf->size is the offset of the first byte after the allocated space.
-     buf->off is the offset of the first byte to be written to. */
-  return buf->size - buf->off;
-}
-
-#if HAVE_ICONV
-
-/* Run iconv using text buffer as output buffer. */
-size_t
-text_buffer_iconv (struct text_buffer *buf, iconv_t iconv_state,
-                   ICONV_CONST char **inbuf, size_t *inbytesleft)
-{
-  size_t out_bytes_left;
-  char *outptr;
-  size_t iconv_ret;
-
-  outptr = text_buffer_base (buf) + text_buffer_off (buf);
-  out_bytes_left = text_buffer_space_left (buf);
-  iconv_ret = iconv (iconv_state, inbuf, inbytesleft,
-                     &outptr, &out_bytes_left);
-
-  text_buffer_off (buf) = outptr - text_buffer_base (buf);    
-
-  return iconv_ret;
-}
-
-#endif /* HAVE_ICONV */
-
-size_t
-text_buffer_add_string (struct text_buffer *buf, const char *str, size_t len)
-{
-  text_buffer_alloc (buf, len);
-  memcpy (buf->base + buf->off, str, len);
-  buf->off += len;
-  return len;
-}
-
-size_t
-text_buffer_fill (struct text_buffer *buf, int c, size_t len)
-{
-  char *p;
-  int i;
-  
-  text_buffer_alloc (buf, len);
-  
-  for (i = 0, p = buf->base + buf->off; i < len; i++)
-    *p++ = c;
-  buf->off += len;
-  
-  return len;
-}
-
-void
-text_buffer_add_char (struct text_buffer *buf, int c)
-{
-  char ch = c;
-  text_buffer_add_string (buf, &ch, 1);
-}
-
-size_t
-text_buffer_printf (struct text_buffer *buf, const char *format, ...)
-{
-  va_list ap;
-  size_t n;
-  
-  va_start (ap, format);
-  n = text_buffer_vprintf (buf, format, ap);
-  va_end (ap);
-  return n;
-}
-
-#if defined(__MSDOS__) || defined(__MINGW32__)
-/* Cannot use FILENAME_CMP here, since that does not consider forward-
-   and back-slash characters equal.  */
-int
-fncmp (const char *fn1, const char *fn2)
-{
-  const char *s1 = fn1, *s2 = fn2;
-
-  while (tolower (*s1) == tolower (*s2)
-        || (IS_SLASH (*s1) && IS_SLASH (*s2)))
-    {
-      if (*s1 == 0)
-       return 0;
-      s1++;
-      s2++;
-    }
-
-  return tolower (*s1) - tolower (*s2);
-}
-#endif
-
-
diff --git a/info/info-utils.h b/info/info-utils.h
index 25748ffb5f..4dbd6e1bc6 100644
--- a/info/info-utils.h
+++ b/info/info-utils.h
@@ -24,10 +24,6 @@
 #include "window.h"
 #include "search.h"
 
-#if HAVE_ICONV
-# include <iconv.h>
-#endif
-
 /* Variable which holds the most recent filename parsed as a result of
    calling info_parse_xxx (). */
 extern char *info_parsed_filename;
@@ -87,55 +83,6 @@ char *printed_representation (mbi_iterator_t *iter,
                                      int *delim, size_t pl_chars,
                                      size_t *pchars, size_t *pbytes);
 
-FILE_BUFFER *file_buffer_of_window (WINDOW *window);
-
-char *node_printed_rep (NODE *node);
-
-/* Return a pointer to the part of PATHNAME that simply defines the file. */
-char *filename_non_directory (char *pathname);
-
-/* Return non-zero if NODE is one especially created by Info. */
-int internal_info_node_p (NODE *node);
-
-/* Make NODE appear to be one especially created by Info, and give it NAME. */
-void name_internal_node (NODE *node, char *name);
-
-/* Return the window displaying NAME, the name of an internally created
-   Info window. */
-WINDOW *get_internal_info_window (char *name);
-
-struct text_buffer
-{
-  char *base;
-  size_t size;
-  size_t off;
-};
-
-#define MIN_TEXT_BUF_ALLOC 512
-
-void text_buffer_init (struct text_buffer *buf);
-void text_buffer_free (struct text_buffer *buf);
-void text_buffer_alloc (struct text_buffer *buf, size_t len);
-size_t text_buffer_vprintf (struct text_buffer *buf, const char *format,
-                           va_list ap);
-size_t text_buffer_space_left (struct text_buffer *buf);
-#if HAVE_ICONV
-size_t text_buffer_iconv (struct text_buffer *buf, iconv_t iconv_state,
-                          ICONV_CONST char **inbuf, size_t *inbytesleft);
-#endif
-size_t text_buffer_add_string (struct text_buffer *buf, const char *str,
-                              size_t len);
-size_t text_buffer_fill (struct text_buffer *buf, int c, size_t len);
-void text_buffer_add_char (struct text_buffer *buf, int c);
-size_t text_buffer_printf (struct text_buffer *buf, const char *format, ...);
-#define text_buffer_reset(buf) ((buf)->off = 0)
-#define text_buffer_base(buf) ((buf)->base)
-#define text_buffer_off(buf) ((buf)->off)
-
-#if defined(__MSDOS__) || defined(__MINGW32__)
-int fncmp (const char *fn1, const char *fn2);
-#else
-# define fncmp(s,t) strcmp(s,t)
-#endif
+
 
 #endif /* not INFO_UTILS_H */
diff --git a/info/info.c b/info/info.c
index 8ce5e47327..33fbeb481a 100644
--- a/info/info.c
+++ b/info/info.c
@@ -20,6 +20,7 @@
 #include "info.h"
 #include "filesys.h"
 #include "info-utils.h"
+#include "util.h"
 #include "session.h"
 #include "indices.h"
 #include "dribble.h"
diff --git a/info/infodoc.c b/info/infodoc.c
index 640fd0622b..144470d070 100644
--- a/info/infodoc.c
+++ b/info/infodoc.c
@@ -19,6 +19,7 @@
 
 #include "info.h"
 #include "info-utils.h"
+#include "util.h"
 #include "filesys.h"
 #include "session.h"
 #include "doc.h"
diff --git a/info/infopath.c b/info/infopath.c
index 18806d5404..07ed3d1383 100644
--- a/info/infopath.c
+++ b/info/infopath.c
@@ -18,6 +18,7 @@
 
 #include "info.h"
 #include "info-utils.h"
+#include "util.h"
 #include "session.h"
 #include "filesys.h"
 
diff --git a/info/nodemenu.c b/info/nodemenu.c
index a870c07642..88ef04da08 100644
--- a/info/nodemenu.c
+++ b/info/nodemenu.c
@@ -19,6 +19,7 @@
 
 #include "info.h"
 #include "session.h"
+#include "util.h"
 #include "echo-area.h"
 #include "variables.h"
 
diff --git a/info/nodes.c b/info/nodes.c
index 9a52c807a3..f98f418912 100644
--- a/info/nodes.c
+++ b/info/nodes.c
@@ -23,6 +23,7 @@
 #include "search.h"
 #include "filesys.h"
 #include "info-utils.h"
+#include "util.h"
 #include "tag.h"
 #include "man.h"
 #include "variables.h"
diff --git a/info/session.c b/info/session.c
index 6cbad3ce92..5da5099ed0 100644
--- a/info/session.c
+++ b/info/session.c
@@ -20,6 +20,7 @@
 #include "info.h"
 #include "display.h"
 #include "session.h"
+#include "util.h"
 #include "echo-area.h"
 #include "search.h"
 #include "footnotes.h"
diff --git a/info/tag.c b/info/tag.c
index 18ef7d13af..1f4226c73d 100644
--- a/info/tag.c
+++ b/info/tag.c
@@ -19,6 +19,7 @@
 #include "info.h"
 #include "tag.h" 
 #include "info-utils.h"
+#include "util.h"
 
 struct tag_handler
 {
diff --git a/info/util.h b/info/util.h
new file mode 100644
index 0000000000..6161158ceb
--- /dev/null
+++ b/info/util.h
@@ -0,0 +1,64 @@
+#ifndef UTIL_H
+#define UTIL_H
+
+#include "nodes.h"
+#include "window.h"
+#include "search.h"
+
+#if HAVE_ICONV
+# include <iconv.h>
+#endif
+
+FILE_BUFFER *file_buffer_of_window (WINDOW *window);
+
+char *node_printed_rep (NODE *node);
+
+/* Return a pointer to the part of PATHNAME that simply defines the file. */
+char *filename_non_directory (char *pathname);
+
+/* Return non-zero if NODE is one especially created by Info. */
+int internal_info_node_p (NODE *node);
+
+/* Make NODE appear to be one especially created by Info, and give it NAME. */
+void name_internal_node (NODE *node, char *name);
+
+/* Return the window displaying NAME, the name of an internally created
+   Info window. */
+WINDOW *get_internal_info_window (char *name);
+
+struct text_buffer
+{
+  char *base;
+  size_t size;
+  size_t off;
+};
+
+#define MIN_TEXT_BUF_ALLOC 512
+
+void text_buffer_init (struct text_buffer *buf);
+void text_buffer_free (struct text_buffer *buf);
+void text_buffer_alloc (struct text_buffer *buf, size_t len);
+size_t text_buffer_vprintf (struct text_buffer *buf, const char *format,
+                           va_list ap);
+size_t text_buffer_space_left (struct text_buffer *buf);
+#if HAVE_ICONV
+size_t text_buffer_iconv (struct text_buffer *buf, iconv_t iconv_state,
+                          ICONV_CONST char **inbuf, size_t *inbytesleft);
+#endif
+size_t text_buffer_add_string (struct text_buffer *buf, const char *str,
+                              size_t len);
+size_t text_buffer_fill (struct text_buffer *buf, int c, size_t len);
+void text_buffer_add_char (struct text_buffer *buf, int c);
+size_t text_buffer_printf (struct text_buffer *buf, const char *format, ...);
+#define text_buffer_reset(buf) ((buf)->off = 0)
+#define text_buffer_base(buf) ((buf)->base)
+#define text_buffer_off(buf) ((buf)->off)
+
+#if defined(__MSDOS__) || defined(__MINGW32__)
+int fncmp (const char *fn1, const char *fn2);
+#else
+# define fncmp(s,t) strcmp(s,t)
+#endif
+
+#endif /* UTIL_H */
+
diff --git a/info/window.c b/info/window.c
index 49eb2e80ed..4112d514cb 100644
--- a/info/window.c
+++ b/info/window.c
@@ -21,6 +21,7 @@
 #include "session.h"
 #include "display.h"
 #include "info-utils.h"
+#include "util.h"
 #include "doc.h"
 #include "tag.h"
 #include "variables.h"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]