[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 1700ec6771fff71ea9ea2da96b198145dd771ba1
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Wed Mar 16 20:35:16 2022 +0000
Move functions between files
* info/scan.c, info/util.c (ansi_escape, printed_representation):
Move to util.c.
---
ChangeLog | 7 +++
info/man.c | 2 +-
info/scan.c | 139 ------------------------------------------------------------
info/scan.h | 14 +-----
info/util.h | 13 ++++++
5 files changed, 22 insertions(+), 153 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ce18af6bd0..752a57443e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-03-16 Gavin Smith <gavinsmith0123@gmail.com>
+
+ Move functions between files
+
+ * info/scan.c, info/util.c (ansi_escape, printed_representation):
+ Move to util.c.
+
2022-03-16 Gavin Smith <gavinsmith0123@gmail.com>
Rename info/info-utils.c
diff --git a/info/man.c b/info/man.c
index 8eae36cb40..16958992bb 100644
--- a/info/man.c
+++ b/info/man.c
@@ -31,7 +31,7 @@
#include "nodes.h"
#include "man.h"
#include "variables.h"
-#include "scan.h"
+#include "util.h"
#if !defined (_POSIX_VERSION)
#define pid_t int
diff --git a/info/scan.c b/info/scan.c
index 8fda9a266a..051a92ea4a 100644
--- a/info/scan.c
+++ b/info/scan.c
@@ -426,145 +426,6 @@ canonicalize_whitespace (char *string)
free (temp);
}
-/* If ITER points to an ANSI escape sequence, process it, set PLEN to its
- length in bytes, and return 1.
- Otherwise, return 0.
- */
-int
-ansi_escape (mbi_iterator_t iter, size_t *plen)
-{
- if (raw_escapes_p && *mbi_cur_ptr (iter) == '\033' && mbi_avail (iter))
- {
- mbi_advance (iter);
- if (*mbi_cur_ptr (iter) == '[' && mbi_avail (iter))
- {
- ITER_SETBYTES (iter, 1);
- mbi_advance (iter);
- if (isdigit (*mbi_cur_ptr (iter)) && mbi_avail (iter))
- {
- ITER_SETBYTES (iter, 1);
- mbi_advance (iter);
- if (*mbi_cur_ptr (iter) == 'm')
- {
- *plen = 4;
- return 1;
- }
- else if (isdigit (*mbi_cur_ptr (iter)) && mbi_avail (iter))
- {
- ITER_SETBYTES (iter, 1);
- mbi_advance (iter);
- if (*mbi_cur_ptr (iter) == 'm')
- {
- *plen = 5;
- return 1;
- }
- }
- }
- }
- }
-
- return 0;
-}
-
-static struct text_buffer printed_rep = { 0 };
-
-/* Return pointer to string that is the printed representation of character
- (or other logical unit) at ITER if it were printed at screen column
- PL_CHARS. Use ITER_SETBYTES (scan.h) on ITER if we need to advance
- past a unit that the multibyte iteractor doesn't know about (like an ANSI
- escape sequence). If ITER points at an end-of-line character, set *DELIM
to
- this character. *PCHARS gets the number of screen columns taken up by
- outputting the return value, and *PBYTES the number of bytes in returned
- string. Return value is not null-terminated. Return value must not be
- freed by caller. */
-char *
-printed_representation (mbi_iterator_t *iter, int *delim, size_t pl_chars,
- size_t *pchars, size_t *pbytes)
-{
- struct text_buffer *rep = &printed_rep;
-
- char *cur_ptr = (char *) mbi_cur_ptr (*iter);
- size_t cur_len = mb_len (mbi_cur (*iter));
-
- text_buffer_reset (&printed_rep);
-
- if (mb_isprint (mbi_cur (*iter)))
- {
- /* cur.wc gives a wchar_t object. See mbiter.h in the
- gnulib/lib directory. */
- *pchars = wcwidth ((*iter).cur.wc);
- *pbytes = cur_len;
- return cur_ptr;
- }
- else if (cur_len == 1)
- {
- if (*cur_ptr == '\n' || *cur_ptr == '\r')
- {
- /* If this is a CRLF line ending, ignore this character. */
- if (*cur_ptr == '\r' && cur_ptr[1] == '\n')
- {
- *pchars = 0;
- *pbytes = 0;
- return cur_ptr;
- }
-
- *pchars = 1;
- *pbytes = cur_len;
- *delim = *cur_ptr;
- text_buffer_add_char (rep, ' ');
- return cur_ptr;
- }
- else if (ansi_escape (*iter, &cur_len))
- {
- *pchars = 0;
- *pbytes = cur_len;
- ITER_SETBYTES (*iter, cur_len);
-
- return cur_ptr;
- }
- else if (*cur_ptr == '\t')
- {
- int i = 0;
-
- *pchars = ((pl_chars + 8) & 0xf8) - pl_chars;
- *pbytes = *pchars;
-
- /* We must output spaces instead of the tab because a tab may
- not clear characters already on the screen. */
- for (i = 0; i < *pbytes; i++)
- text_buffer_add_char (rep, ' ');
- return text_buffer_base (rep);
- }
- }
-
- /* Show CTRL-x as "^X". */
- if (iscntrl (*cur_ptr) && *(unsigned char *)cur_ptr < 127)
- {
- *pchars = 2;
- *pbytes = 2;
- text_buffer_add_char (rep, '^');
- text_buffer_add_char (rep, *cur_ptr | 0x40);
- return text_buffer_base (rep);
- }
- else if (*cur_ptr == DEL)
- {
- *pchars = 0;
- *pbytes = 0;
- return text_buffer_base (rep);
- }
- else
- {
- /* Original byte was not recognized as anything. Display its octal
- value. This could happen in the C locale for bytes above 128,
- or for bytes 128-159 in an ISO-8859-1 locale. Don't output the bytes
- as they are, because they could have special meaning to the
- terminal. */
- *pchars = 4;
- *pbytes = 4;
- text_buffer_printf (rep, "\\%o", *(unsigned char *)cur_ptr);
- return text_buffer_base (rep);
- }
-}
/* **************************************************************** */
diff --git a/info/scan.h b/info/scan.h
index 7ad95369aa..fdf74f6d44 100644
--- a/info/scan.h
+++ b/info/scan.h
@@ -71,18 +71,6 @@ REFERENCE *info_new_reference (char *filename, char
*nodename);
start and end of string. */
void canonicalize_whitespace (char *string);
-/* Used with multibyte iterator mbi_iterator_t. */
-#define ITER_SETBYTES(iter,n) ((iter).cur.bytes = n)
-#define ITER_LIMIT(iter) ((iter).limit - (iter).cur.ptr)
-int ansi_escape (mbi_iterator_t iter, size_t *plen);
-/* Return a pointer to a string which is the printed representation
- of CHARACTER if it were printed at HPOS. */
-char *printed_representation (mbi_iterator_t *iter,
- int *delim, size_t pl_chars,
- size_t *pchars, size_t *pbytes);
-
-
-
-#endif /* not INFO_UTILS_H */
+#endif /* not SCAN_H */
diff --git a/info/util.h b/info/util.h
index 6161158ceb..461d0979bd 100644
--- a/info/util.h
+++ b/info/util.h
@@ -26,6 +26,19 @@ void name_internal_node (NODE *node, char *name);
Info window. */
WINDOW *get_internal_info_window (char *name);
+/* Used with multibyte iterator mbi_iterator_t. */
+#define ITER_SETBYTES(iter,n) ((iter).cur.bytes = n)
+#define ITER_LIMIT(iter) ((iter).limit - (iter).cur.ptr)
+
+int ansi_escape (mbi_iterator_t iter, size_t *plen);
+
+/* Return a pointer to a string which is the printed representation
+ of CHARACTER if it were printed at HPOS. */
+char *printed_representation (mbi_iterator_t *iter,
+ int *delim, size_t pl_chars,
+ size_t *pchars, size_t *pbytes);
+
+
struct text_buffer
{
char *base;