texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Mon, 24 Jul 2023 17:50:17 -0400 (EDT)

branch: master
commit d72ea4d9d167f325bd581ec0e024091088c688d3
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Jul 24 23:19:52 2023 +0200

    * tp/Texinfo/XS/xspara.c (xspara__add_pending_word): reset
    state.space_counter too when indent and !state.unfilled.
    
    * tp/Texinfo/XS/xspara.c (xspara__print_escaped_spaces)
    (xspara__add_pending_word, xspara_end, xspara__add_next)
    (xspara_add_text): add debug similar to the perl Paragraph module.
    Enabled by changing a variable in the source file and recompiling.
---
 ChangeLog              | 10 +++++++
 tp/Texinfo/XS/xspara.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f61ca0a401..ed950d70ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2023-07-24  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/xspara.c (xspara__add_pending_word): reset
+       state.space_counter too when indent and !state.unfilled.
+
+       * tp/Texinfo/XS/xspara.c (xspara__print_escaped_spaces)
+       (xspara__add_pending_word, xspara_end, xspara__add_next)
+       (xspara_add_text): add debug similar to the perl Paragraph module.
+       Enabled by changing a variable in the source file and recompiling.
+
 2023-07-23  Patrice Dumas  <pertusus@free.fr>
 
        Complete Plaintext/Info menus with nodedescription
diff --git a/tp/Texinfo/XS/xspara.c b/tp/Texinfo/XS/xspara.c
index 9afc4d6a6d..2d3535ce32 100644
--- a/tp/Texinfo/XS/xspara.c
+++ b/tp/Texinfo/XS/xspara.c
@@ -48,6 +48,8 @@
 
 #include "text.h"
 
+int debug = 0;
+
 typedef struct {
     TEXT space; /* Pending space, to be output before the pending word. */
     TEXT word; /* Pending word.  If outputting this would have led to
@@ -234,6 +236,32 @@ iswupper (wint_t wi)
 
 #endif
 
+char *
+print_escaped_spaces (char *string)
+{
+  static TEXT t;
+  char *p = string;
+  text_reset (&t);
+  while (*p)
+    {
+      if (*p == ' ')
+        text_append_n (&t, p, 1);
+      else if (*p == '\n')
+        text_append_n (&t, "\\n", 2);
+      else if (*p == '\f')
+        text_append_n (&t, "\\f", 2);
+      else if (isspace(*p))
+        {
+          char *protected_string = malloc (7 * sizeof (char));
+          sprintf (protected_string, "\\x%04x", *p);
+          text_append (&t, protected_string);
+          free (protected_string);
+        }
+      p++;
+    }
+  return t.text;
+}
+
 int
 xspara_init (int unused, char *unused2)
 {
@@ -582,10 +610,16 @@ xspara__add_pending_word (TEXT *result, int add_spaces)
         text_append (result, " ");
       state.counter = state.indent_length;
 
+      if (debug)
+        fprintf (stderr, "INDENT(%d+%d)\n", state.counter, state.word_counter);
+
       /* Do not output leading spaces after the indent, unless 'unfilled'
          is on.  */
       if (!state.unfilled)
-        state.space.end = 0;
+        {
+          state.space.end = 0;
+          state.space_counter = 0;
+        }
     }
 
   if (state.space.end > 0)
@@ -593,6 +627,11 @@ xspara__add_pending_word (TEXT *result, int add_spaces)
       text_append_n (result, state.space.text, state.space.end);
 
       state.counter += state.space_counter;
+
+      if (debug)
+        fprintf (stderr, "ADD_SPACES(%d+%d)\n", state.counter,
+                                                state.word_counter);
+
       state.space.end = 0;
       state.space_counter = 0;
     }
@@ -602,6 +641,10 @@ xspara__add_pending_word (TEXT *result, int add_spaces)
       text_append_n (result, state.word.text, state.word.end);
       state.counter += state.word_counter;
 
+      if (debug)
+        fprintf (stderr, "ADD_WORD[%s]+%d (%d)\n", state.word.text,
+                 state.word_counter, state.counter);
+
       state.word.end = 0;
       state.word_counter = 0;
       state.invisible_pending_word = 0;
@@ -630,6 +673,10 @@ xspara_end (void)
   static TEXT ret;
   text_reset (&ret);
   state.end_line_count = 0;
+
+  if (debug)
+    fprintf (stderr, "PARA END\n");
+
   xspara__add_pending_word (&ret, state.add_final_space);
   if (!state.no_final_newline && state.counter != 0)
     {
@@ -770,6 +817,9 @@ xspara__add_next (TEXT *result, char *word, int word_len, 
int transparent)
           xspara__cut_line (result);
         }
     }
+  if (debug)
+    fprintf (stderr, "WORD+ %s -> %s\n", word, state.word.space == 0 ?
+                "UNDEF" : state.word.text);
 }
 
 /* Like _add_next but zero end_line_count at beginning. */
@@ -864,10 +914,29 @@ xspara_add_text (char *text, int len)
 
   while (len > 0)
     {
+      if (debug)
+        {
+          char *word = "UNDEF";
+          if (state.word.end > 0)
+            word = state.word.text;
+          fprintf(stderr, "p (%d+%d) s `%s', w `%s'\n", state.counter,
+                  state.word_counter, state.space.end == 0 ? ""
+                   : print_escaped_spaces (state.space.text),
+                  word);
+        }
       if (isspace ((unsigned char) *p))
         {
           state.last_letter = L'\0';
 
+          if (debug)
+            {
+              char t[2];
+              t[0] = *p;
+              t[1] = '\0';
+              fprintf(stderr, "SPACES(%d) `%s'\n", state.counter,
+                      print_escaped_spaces (t));
+            }
+
           if (state.unfilled)
             {
               xspara__add_pending_word (&result, 0);
@@ -1067,4 +1136,3 @@ xspara_add_text (char *text, int len)
   return result;
 }
 
-



reply via email to

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