texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: Use enum symbols for end-of-sentence status


From: Gavin D. Smith
Subject: branch master updated: Use enum symbols for end-of-sentence status
Date: Wed, 25 Oct 2023 15:51:57 -0400

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

gavin pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 1a3c09d2db Use enum symbols for end-of-sentence status
1a3c09d2db is described below

commit 1a3c09d2db1bfe26986c8888e0bb6dc928eec5c4
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Wed Oct 25 20:51:49 2023 +0100

    Use enum symbols for end-of-sentence status
    
    * tp/Texinfo/Convert/ParagraphNonXS.pm (remove_end_sentence)
    (add_text): Use Perl constants for the various possible values
    of $paragraph->{'end_sentence'}, rather than integer literals.
    * tp/Texinfo/XS/xspara.c (enum eos_status): New.
    (xspara_remove_end_sentence, xspara_add_text, PARAGRAPH):
    Use throughout.
---
 ChangeLog                            | 11 +++++++++++
 tp/Texinfo/Convert/ParagraphNonXS.pm | 19 +++++++++++++------
 tp/Texinfo/XS/xspara.c               | 33 +++++++++++++++++++--------------
 3 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 97c4965fd3..dfff655341 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2023-10-25  Gavin Smith <gavinsmith0123@gmail.com>
+
+       Use enum symbols for end-of-sentence status
+
+       * tp/Texinfo/Convert/ParagraphNonXS.pm (remove_end_sentence)
+       (add_text): Use Perl constants for the various possible values
+       of $paragraph->{'end_sentence'}, rather than integer literals.
+       * tp/Texinfo/XS/xspara.c (enum eos_status): New.
+       (xspara_remove_end_sentence, xspara_add_text, PARAGRAPH):
+       Use throughout.
+
 2023-10-25  Gavin Smith <gavinsmith0123@gmail.com>
 
        * tp/Texinfo/XS/xspara.c (xspara__add_next) [debugging output]:
diff --git a/tp/Texinfo/Convert/ParagraphNonXS.pm 
b/tp/Texinfo/Convert/ParagraphNonXS.pm
index 36fdef3aa0..dbb92db179 100644
--- a/tp/Texinfo/Convert/ParagraphNonXS.pm
+++ b/tp/Texinfo/Convert/ParagraphNonXS.pm
@@ -243,10 +243,17 @@ sub _add_next($;$$$)
   return $result;
 }
 
+# Values for 'end_sentence'.  'end_sentence' can also be undef.
+use constant {
+  eos_inhibited => 0,
+  eos_present => 1,
+  eos_present_frenchspacing => -1,
+};
+
 sub remove_end_sentence($)
 {
   my $paragraph = shift;
-  $paragraph->{'end_sentence'} = 0;
+  $paragraph->{'end_sentence'} = eos_inhibited;
 }
 
 sub add_end_sentence($;$) {
@@ -332,9 +339,9 @@ sub add_text($$)
         }
       } else {
         my $at_end_sentence = 0;
-        $at_end_sentence = 1 if ($paragraph->{'end_sentence'} 
-                                   and $paragraph->{'end_sentence'} > 0
-                                   and !$paragraph->{'frenchspacing'});
+        $at_end_sentence = 1 if (defined($paragraph->{'end_sentence'})
+                               and  $paragraph->{'end_sentence'} == eos_present
+                               and !$paragraph->{'frenchspacing'});
         if ($paragraph->{'no_break'}) {
           if (substr($paragraph->{'word'}, -1) ne ' ') {
             my $new_spaces = $at_end_sentence ? '  ' : ' ';
@@ -403,9 +410,9 @@ sub add_text($$)
          [$after_punctuation_characters]*[$end_sentence_characters]
          [$end_sentence_characters$after_punctuation_characters]*$/ox) {
         if ($paragraph->{'frenchspacing'}) {
-          $paragraph->{'end_sentence'} = -1;
+          $paragraph->{'end_sentence'} = eos_present_frenchspacing;
         } else {
-          $paragraph->{'end_sentence'} = 1;
+          $paragraph->{'end_sentence'} = eos_present;
         }
         print STDERR "END_SENTENCE\n" if ($paragraph->{'DEBUG'});
       } else {
diff --git a/tp/Texinfo/XS/xspara.c b/tp/Texinfo/XS/xspara.c
index f0dbd91ecb..60e3eba02a 100644
--- a/tp/Texinfo/XS/xspara.c
+++ b/tp/Texinfo/XS/xspara.c
@@ -50,6 +50,14 @@
 
 static int debug = 0;
 
+enum eos_status { eos_undef = -2, eos_inhibited = 0, eos_present = 1,
+                  eos_present_frenchspacing = -1 };
+/* eos_undef                 - not at the end of a sentence (undef in Perl),
+   eos_inhibited             - end of sentence is inhibited
+   eos_present               - at end of sentence
+   eos_present_frenchspacing - at end of sentence but frenchspacing is on. */
+
+
 typedef struct {
     TEXT space; /* Pending space, to be output before the pending word. */
     TEXT word; /* Pending word.  If outputting this would have led to
@@ -65,11 +73,7 @@ typedef struct {
     /* Characters added so far in current word. */
     int word_counter; 
 
-    /* -2 means we are not at the end of a sentence (undefined in Perl),
-       1 means we are at the end of a sentence and French spacing is off,
-       -1 means we are at the end of a sentence and French spacing is on.
-       0 means it is "inhibited". */
-    int end_sentence;
+    enum eos_status end_sentence;
 
     int max; /* Maximum length of line. */
     int indent_length; /* Columns to indent this line. */
@@ -418,7 +422,7 @@ xspara_new (HV *conf)
   /* Default values. */
   state.max = 72;
   state.indent_length_next = -1; /* Special value meaning undefined. */
-  state.end_sentence = -2; /* Special value meaning undefined. */
+  state.end_sentence = eos_undef;
   state.last_letter = L'\0';
 
   if (conf)
@@ -817,7 +821,7 @@ xspara_add_next (char *text, int text_len, int transparent)
 void
 xspara_remove_end_sentence (void)
 {
-  state.end_sentence = 0;
+  state.end_sentence = eos_inhibited;
 }
 
 void
@@ -1026,7 +1030,8 @@ xspara_add_text (char *text, int len)
               if (state.word.end == 0
                   || state.word.text[state.word.end - 1] != ' ')
                 {
-                  if (state.end_sentence == 1 && !state.french_spacing)
+                  if (state.end_sentence == eos_present
+                      && !state.french_spacing)
                     {
                       text_append_n (&state.word, "  ", 2);
                       state.word_counter += 2;
@@ -1054,7 +1059,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 == 1
+                  if (state.end_sentence == eos_present
                       && !state.french_spacing)
                     {
                       state.space.end = 0;
@@ -1117,7 +1122,7 @@ xspara_add_text (char *text, int len)
             {
               xspara__add_pending_word (&result, 0);
             }
-          state.end_sentence = -2;
+          state.end_sentence = eos_undef;
         }
       else if (type == type_EOS)
         {
@@ -1141,9 +1146,9 @@ xspara_add_text (char *text, int len)
                   if (!iswupper (state.last_letter))
                     {
                       if (state.french_spacing)
-                        state.end_sentence = -1;
+                        state.end_sentence = eos_present_frenchspacing;
                       else
-                        state.end_sentence = 1;
+                        state.end_sentence = eos_present;
                       if (debug)
                         fprintf (stderr, "END_SENTENCE\n");
                       break;
@@ -1157,10 +1162,10 @@ xspara_add_text (char *text, int len)
               else
                 {
                   /* Not at the end of a sentence. */
-                  if (debug && state.end_sentence != -2)
+                  if (debug && state.end_sentence != eos_undef)
                     fprintf (stderr, "delete END_SENTENCE(%d)\n",
                                       state.end_sentence);
-                  state.end_sentence = -2;
+                  state.end_sentence = eos_undef;
                   break;
                 }
             }



reply via email to

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