texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/XS/xspara.c (PARAGRAPH): rename fren


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/xspara.c (PARAGRAPH): rename french_spacing as frenchspacing to match exactly the Perl key.
Date: Thu, 14 Nov 2024 15:28:47 -0500

This is an automated email from the git hooks/post-receive script.

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 146e8aa77e * tp/Texinfo/XS/xspara.c (PARAGRAPH): rename french_spacing 
as frenchspacing to match exactly the Perl key.
146e8aa77e is described below

commit 146e8aa77eb2da3a620fc7a74d0723488f09689e
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Thu Nov 14 21:28:41 2024 +0100

    * tp/Texinfo/XS/xspara.c (PARAGRAPH): rename french_spacing as
    frenchspacing to match exactly the Perl key.
    
    * tp/Texinfo/XS/XSParagraph.xs (xspara_new), tp/Texinfo/XS/xspara.c
    (xspara_init_state): modify xspara_init_state to be C only and get all
    the configuration variables in argument.  Get Perl conf in xspara_new
    with code similar to former xspara_init_state code in XSParagraph.xs
    and call xspara_init_state.
    
    * tp/Texinfo/XS/xspara.c: do not include Perl headers now that there
    is only pure C.
---
 ChangeLog                    |  14 ++++++
 tp/Texinfo/XS/XSParagraph.xs |  45 ++++++++++++++++++-
 tp/Texinfo/XS/xspara.c       | 103 +++++++++++++------------------------------
 tp/Texinfo/XS/xspara.h       |   6 ++-
 4 files changed, 93 insertions(+), 75 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index df45d2c714..1e732cc6b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2024-11-14  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/xspara.c (PARAGRAPH): rename french_spacing as
+       frenchspacing to match exactly the Perl key.
+
+       * tp/Texinfo/XS/XSParagraph.xs (xspara_new), tp/Texinfo/XS/xspara.c
+       (xspara_init_state): modify xspara_init_state to be C only and get all
+       the configuration variables in argument.  Get Perl conf in xspara_new
+       with code similar to former xspara_init_state code in XSParagraph.xs
+       and call xspara_init_state.
+
+       * tp/Texinfo/XS/xspara.c: do not include Perl headers now that there
+       is only pure C.
+
 2024-11-14  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/XSParagraph.xs (xspara_new), tp/Texinfo/XS/xspara.c
diff --git a/tp/Texinfo/XS/XSParagraph.xs b/tp/Texinfo/XS/XSParagraph.xs
index ba8416bbcf..89f48a422a 100644
--- a/tp/Texinfo/XS/XSParagraph.xs
+++ b/tp/Texinfo/XS/XSParagraph.xs
@@ -49,6 +49,25 @@ xspara_new (class, ...)
     PREINIT:
         HV *conf = 0;
         int id;
+        SV **val;
+        int end_sentence = -1;
+        int max = -1;
+        int indent_length = -1;
+        int indent_length_next = -1;
+        int counter = -1;
+        int word_counter = -1;
+        int lines_counter = -1;
+        int end_line_count = -1;
+        int no_break = -1;
+        int ignore_columns = -1;
+        int keep_end_lines = -1;
+        int frenchspacing = -1;
+        int unfilled = -1;
+        int no_final_newline = -1;
+        int add_final_space = -1;
+#define FETCH(key) hv_fetch (conf, key, strlen (key), 0)
+#define FETCH_INT(variable) { val = FETCH(#variable); \
+                               if (val) { variable = SvIV (*val); } }
     CODE:
         items--;
         if (items > 0)
@@ -59,13 +78,37 @@ xspara_new (class, ...)
         id = xspara_new ();
 
         if (conf)
-          xspara_init_state (conf);
+          {
+            FETCH_INT(end_sentence)
+            FETCH_INT(max)
+            FETCH_INT(indent_length)
+            FETCH_INT(indent_length_next)
+            FETCH_INT(counter)
+            FETCH_INT(word_counter)
+            FETCH_INT(lines_counter)
+            FETCH_INT(end_line_count)
+            FETCH_INT(no_break)
+            FETCH_INT(ignore_columns)
+            FETCH_INT(keep_end_lines)
+            FETCH_INT(frenchspacing)
+            FETCH_INT(unfilled)
+            FETCH_INT(no_final_newline)
+            FETCH_INT(add_final_space)
+            xspara_init_state (end_sentence, max, indent_length,
+                               indent_length_next, counter, word_counter,
+                               lines_counter, end_line_count, no_break,
+                               ignore_columns, keep_end_lines, frenchspacing,
+                               unfilled, no_final_newline, add_final_space);
+          }
 
         /* Create an integer, which the other functions
            need as their first argument. */
         RETVAL = newSViv (id);
     OUTPUT:
         RETVAL
+    CLEANUP:
+#undef FETCH
+#undef FETCH_INT
 
 
 int
diff --git a/tp/Texinfo/XS/xspara.c b/tp/Texinfo/XS/xspara.c
index 8cd115425c..b5b0a6cf7d 100644
--- a/tp/Texinfo/XS/xspara.c
+++ b/tp/Texinfo/XS/xspara.c
@@ -19,6 +19,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <ctype.h>
 
 #include <unitypes.h>
 #include <uniwidth.h>
@@ -26,17 +27,6 @@
 #include <unistr.h>
 #include <uchar.h>
 
-/* See "How do I use all this in extensions" in 'man perlguts'. */
-#define PERL_NO_GET_CONTEXT
-
-#include "EXTERN.h"
-#include "perl.h"
-#if defined _WIN32 && !defined __CYGWIN__
-/* See comment in XSParagraph.xs for why we #undef free. */
-# undef free
-#endif
-#include "XSUB.h"
-
 #include "main/text.h"
 #include "xspara.h"
 
@@ -85,7 +75,7 @@ typedef struct {
                            @flushleft and @flushright. */
     int keep_end_lines; /* A newline in the input ends a line in the output.
                            Used by @flushleft and @flushright. */
-    int french_spacing; /* Only one space, not two, after a full stop. */
+    int frenchspacing;  /* Only one space, not two, after a full stop. */
     int double_width_no_break; /* No line break between double width chars. */
 
     /* No wrapping of lines and spaces are kept as-is. */
@@ -209,58 +199,33 @@ xspara_set_state (int paragraph)
   xspara__switch_state (paragraph);
 }
 
-/* Set the state internal to this C module from the Perl hash. */
+#define SET_CONF(variable) \
+  if (variable != -1) {state.variable = variable;}
+
 void
-xspara_init_state (HV *hash)
+xspara_init_state (int end_sentence, int max, int indent_length,
+                   int indent_length_next, int counter, int word_counter,
+                   int lines_counter, int end_line_count, int no_break,
+                   int ignore_columns, int keep_end_lines, int frenchspacing,
+                   int unfilled, int no_final_newline, int add_final_space)
 {
-#define FETCH(key) hv_fetch (hash, key, strlen (key), 0)
-#define FETCH_INT(key,where) { val = FETCH(key); \
-                               if (val) { where = SvIV (*val); } }
-
-  SV **val;
-  
-  dTHX; /* This is boilerplate for interacting with Perl. */
-
-  /* Fetch all these so they are set, and reset for each paragraph. */
-  FETCH_INT("end_sentence", state.end_sentence);
-  FETCH_INT("max", state.max);
-
-  FETCH_INT("indent_length", state.indent_length);
-  FETCH_INT("indent_length_next", state.indent_length_next);
-  FETCH_INT("counter", state.counter); 
-
-  FETCH_INT("word_counter", state.word_counter);
-
-  FETCH_INT("lines_counter", state.lines_counter);
-  FETCH_INT("end_line_count", state.end_line_count);
-
-  FETCH_INT("no_break", state.no_break);
-  FETCH_INT("ignore_columns", state.ignore_columns);
-  FETCH_INT("keep_end_lines", state.keep_end_lines);
-  FETCH_INT("frenchspacing", state.french_spacing);
-
-  FETCH_INT("unfilled", state.unfilled);
-  FETCH_INT("no_final_newline", state.no_final_newline);
-  FETCH_INT("add_final_space", state.add_final_space);
-
-  val = FETCH("word");
-  if (val)
-    {
-      fprintf (stderr, "Bug: setting 'word' is not supported.\n");
-      abort ();
-    }
-  val = FETCH("space");
-  if (val)
-    {
-      fprintf (stderr, "Bug: setting 'space' is not supported.\n");
-      abort ();
-    }
-  return;
-
-#undef FETCH
-#undef FETCH_INT
+  SET_CONF(end_sentence)
+  SET_CONF(max)
+  SET_CONF(indent_length)
+  SET_CONF(indent_length_next)
+  SET_CONF(counter)
+  SET_CONF(word_counter)
+  SET_CONF(lines_counter)
+  SET_CONF(end_line_count)
+  SET_CONF(no_break)
+  SET_CONF(ignore_columns)
+  SET_CONF(keep_end_lines)
+  SET_CONF(frenchspacing)
+  SET_CONF(unfilled)
+  SET_CONF(no_final_newline)
+  SET_CONF(add_final_space)
 }
-
+#undef SET_CONF
 
 /************************************************************************/
 
@@ -336,8 +301,6 @@ xspara_get_pending (void)
 void
 xspara__add_pending_word (TEXT *result, int add_spaces)
 {
-  dTHX;
-
   if (state.word.end == 0 && !state.invisible_pending_word && !add_spaces)
     return;
 
@@ -414,8 +377,6 @@ xspara_end (void)
 {
   static TEXT ret;
 
-  dTHX;
-
   text_reset (&ret);
   state.end_line_count = 0;
 
@@ -464,8 +425,6 @@ void
 xspara__add_next (TEXT *result, char *word, int word_len,
                   int transparent, int col_count)
 {
-  dTHX;
-
   if (!word)
     return;
 
@@ -612,7 +571,7 @@ xspara_set_space_protection (int no_break,
   if (double_width_no_break != -1)
     state.double_width_no_break = double_width_no_break;
   if (french_spacing != -1)
-    state.french_spacing = french_spacing;
+    state.frenchspacing = french_spacing;
 
   /*fprintf (stderr, "SETTING SPACE (%d, %d, %d, %d)\n",
                                    no_break,
@@ -658,8 +617,6 @@ xspara_add_text (char *text, int len)
      zeroed when the block is output. */
   int regular_col_count = 0;
 
-  dTHX;
-
   text_reset (&result);
 
   state.end_line_count = 0;
@@ -783,7 +740,7 @@ xspara_add_text (char *text, int len)
                   || state.word.text[state.word.end - 1] != ' ')
                 {
                   if (state.end_sentence == eos_present
-                      && !state.french_spacing)
+                      && !state.frenchspacing)
                     {
                       text_append_n (&state.word, "  ", 2);
                       state.word_counter += 2;
@@ -812,7 +769,7 @@ xspara_add_text (char *text, int len)
                   /* If we are at the end of a sentence where two spaces
                      are required. */
                   if (state.end_sentence == eos_present
-                      && !state.french_spacing)
+                      && !state.frenchspacing)
                     {
                       state.space.end = 0;
                       text_append_n (&state.space, "  ", 2);
@@ -898,7 +855,7 @@ xspara_add_text (char *text, int len)
                   /* Doesn't count if preceded by an upper-case letter. */
                   if (!uc_is_upper (state.last_letter))
                     {
-                      if (state.french_spacing)
+                      if (state.frenchspacing)
                         state.end_sentence = eos_present_frenchspacing;
                       else
                         state.end_sentence = eos_present;
diff --git a/tp/Texinfo/XS/xspara.h b/tp/Texinfo/XS/xspara.h
index 9a0640c3a0..4cc260a27a 100644
--- a/tp/Texinfo/XS/xspara.h
+++ b/tp/Texinfo/XS/xspara.h
@@ -1,7 +1,11 @@
 #include "main/text.h"
 
 int xspara_new (void);
-void xspara_init_state (HV *hash);
+void xspara_init_state (int end_sentence, int max, int indent_length,
+                   int indent_length_next, int counter, int word_counter,
+                   int lines_counter, int end_line_count, int no_break,
+                   int ignore_columns, int keep_end_lines, int french_spacing,
+                   int unfilled, int no_final_newline, int add_final_space);
 void xspara_set_state (int paragraph);
 TEXT xspara_add_next (char *, int, int transparent);
 TEXT xspara_add_text (char *, int);



reply via email to

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