texinfo-commits
[Top][All Lists]
Advanced

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

[6476] xspara_add_next transparent argument


From: Gavin D. Smith
Subject: [6476] xspara_add_next transparent argument
Date: Mon, 27 Jul 2015 19:05:33 +0000

Revision: 6476
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=6476
Author:   gavin
Date:     2015-07-27 19:05:31 +0000 (Mon, 27 Jul 2015)
Log Message:
-----------
xspara_add_next transparent argument

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.pm
    trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.xs
    trunk/tp/Texinfo/Convert/XSParagraph/xspara.c
    trunk/tp/Texinfo/Convert/XSParagraph/xspara.h
    trunk/tp/t/paragraph.t

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2015-07-27 12:57:27 UTC (rev 6475)
+++ trunk/ChangeLog     2015-07-27 19:05:31 UTC (rev 6476)
@@ -1,5 +1,17 @@
 2015-07-27  Gavin Smith  <address@hidden>
 
+       * tp/Texinfo/Convert/XSParagraph/XSParagraph.xs
+       (xspara_new): Optional conf parameter.
+       (xspara_add_next): Propagate 'transparent' argument.
+       * tp/Texinfo/Convert/XSParagraph/xspara.c
+       (xspara_add_next, xspara__add_next): Update state.last_letter, 
+       taking into account 'transparent' argument.
+
+       * tp/t/paragraph.t: Run tests for XSParagraph module as well as 
+       Texinfo::Convert::XSParagraph.
+
+2015-07-27  Gavin Smith  <address@hidden>
+
        * tp/Texinfo/Convert/XSParagraph/xspara.c: Remove all comments 
        with out-of-date line numbers for Paragraph.pm.
 

Modified: trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.pm
===================================================================
--- trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.pm 2015-07-27 12:57:27 UTC 
(rev 6475)
+++ trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.pm 2015-07-27 19:05:31 UTC 
(rev 6476)
@@ -1,4 +1,4 @@
-# Copyright 2010, 2011, 2012, 2014 Free Software Foundation, Inc.
+# Copyright 2014, 2015 Free Software Foundation, Inc.
 
 package XSParagraph;
 require DynaLoader;

Modified: trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.xs
===================================================================
--- trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.xs 2015-07-27 12:57:27 UTC 
(rev 6475)
+++ trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.xs 2015-07-27 19:05:31 UTC 
(rev 6476)
@@ -26,18 +26,21 @@
 # Return a reference blessed into the XSParagraph class
 # CLASS is ignored because we know it is "XSParagraph".  Optional
 # CONF parameter.
-# CONF is supposed to be optional.  Just make it non-optional, because
-# I'm having problems getting the conf in and I may not be reading it
-# properly
 SV *
-xspara_new (class, conf)
+xspara_new (class, ...)
         SV * class
-        HV * conf
     PREINIT:
         HV *hv;
         HV *pkg;
+        HV *conf = 0;
         int id;
     CODE:
+        items--;
+        if (items > 0)
+          {
+            if (SvROK(ST(1)) && SvTYPE(SvRV(ST(1))) == SVt_PVHV)
+              conf = (HV *) SvRV(ST(1));
+          }
         /* id is ignored at the moment.  This call simply
            resets the state of the paragraph formatter. */
         id = xspara_new (conf);
@@ -188,10 +191,18 @@
     PREINIT:
         char *text;
         STRLEN text_len;
-        //int utf8;
         char *retval;
+        SV *arg_in;
+        int transparent = 0;
     CODE:
-        /* TODO: Propagate 'transparent' argument. */
+        items -= 2;
+        if (items > 0)
+          {
+            items--;
+            arg_in = ST(2);
+            if (SvOK(arg_in))
+              transparent = (int)SvIV(arg_in);
+          }
 
         /* Always convert the input to UTF8 with sv_utf8_upgrade, so we can 
            process it properly in xspara_add_next. */
@@ -200,7 +211,7 @@
         text = SvPV (text_in, text_len);
 
         //xspara_set_state (paragraph);
-        retval = xspara_add_next (text, text_len);
+        retval = xspara_add_next (text, text_len, transparent);
         xspara_get_state (paragraph);
 
         RETVAL = newSVpv (retval, 0);

Modified: trunk/tp/Texinfo/Convert/XSParagraph/xspara.c
===================================================================
--- trunk/tp/Texinfo/Convert/XSParagraph/xspara.c       2015-07-27 12:57:27 UTC 
(rev 6475)
+++ trunk/tp/Texinfo/Convert/XSParagraph/xspara.c       2015-07-27 19:05:31 UTC 
(rev 6476)
@@ -523,105 +523,138 @@
 /* Add WORD to paragraph in RESULT, not refilling WORD.  If we go past the end 
    of the line start a new one. */
 void
-xspara__add_next (TEXT *result,
-                  char *word, int word_len, int transparent)
+xspara__add_next (TEXT *result, char *word, int word_len, int transparent)
 {
-  if (word)
+  int disinhibit = 0;
+  if (!word)
+    return;
+
+  //printf ("LAST CHAR IS NOW %lc\n", (wchar_t) state.last_letter);
+  if (word_len >= 1 && word[word_len - 1] == '\b')
     {
-      if (state.word.end == 0 && !state.invisible_pending_word)
+      word[--word_len] = '\0';
+      disinhibit = 1;
+    }
+
+  if (state.word.end == 0 && !state.invisible_pending_word)
+    {
+      /* Check if we are at the end of a sentence and if we need to
+         output two spaces after the full stop.  If so, check if the
+         word we are given begins with whitespace.  If it doesn't,
+         double the pending space.
+
+         We checked above if there was a pending word because if there
+         was, it is due to be output after the end-sentence whitespace,
+         not the string that was passed as an argument to this function.  
+       */
+      state.last_letter = L'\0';
+
+      if (state.counter != 0 && state.space.end > 0
+          && state.end_sentence == 1 && !state.french_spacing)
         {
-          /* Check if we are at the end of a sentence and if we need to
-             output two spaces after the full stop.  If so, check if the
-             word we are given begins with whitespace.  If it doesn't,
-             double the pending space.
+          wchar_t wc;
+          size_t char_len;
 
-             We checked above if there was a pending word because if there
-             was, it is due to be output after the end-sentence whitespace,
-             not the string that was passed as an argument to this function.  
-           */
-
-          if (state.counter != 0 && state.space.end > 0
-              && state.end_sentence == 1 && !state.french_spacing)
+          char_len = mbrtowc (&wc, word, 10, NULL);
+          if ((long) char_len > 0 && !iswspace (wc))
             {
-              wchar_t wc;
-              size_t char_len;
-
-              char_len = mbrtowc (&wc, word, 10, NULL);
-              if ((long) char_len > 0 && !iswspace (wc))
+              /* Make the pending space up to two spaces. */
+              while (state.space_counter < 2)
                 {
-                  /* Make the pending space up to two spaces. */
-                  while (state.space_counter < 2)
-                    {
-                      text_append_n (&state.space, " ", 1);
-                      state.space_counter++;
-                    }
+                  text_append_n (&state.space, " ", 1);
+                  state.space_counter++;
                 }
+            }
 
-              state.end_sentence = -2;
-            }
+          state.end_sentence = -2;
         }
+    }
 
-      text_append_n (&state.word, word, word_len);
+  text_append_n (&state.word, word, word_len);
 
-      if (strchr (word, '\n'))
-        {
-          /* If there was a newline in the word we just added, put the entire
-             pending ouput in the results string, and start a new line.
-             TODO: Does line_counter get incremented properly in this 
-             circumstance? */
-          /* TODO: Could we just call _add_pending_word here? */
-          text_append_n (result, state.space.text, state.space.end);
-          state.space.end = 0;
-          state.space_counter = 0;
-          text_append_n (result, state.word.text, state.word.end);
-          state.word.end = 0;
-          state.word_counter = 0;
-          state.invisible_pending_word = 0;
-
-          xspara__end_line ();
-        }
+  if (!transparent)
+    {
+      if (disinhibit)
+        state.last_letter = L'a'; /* a lower-case letter */
       else
         {
-          /* The possibility of two-column characters is ignored here. */
-
-          /* Calculate length of multibyte string in characters. */
-          int len = 0;
-          int left = word_len;
-          wchar_t w;
-          char *p = word;
-
-          while (left > 0)
+          /* Save last character in WORD */
+          char *p = word + word_len;
+          while (p > word)
             {
-              int char_len = mbrtowc (&w, p, 10, NULL);
-              left -= char_len;
-              p += char_len;
-              len++;
+              p--;
+              if ((long) mbrlen(p, 10, NULL) > 0)
+                {
+                  wchar_t wc = L'\0';
+                  mbrtowc (&wc, p, 10, NULL);
+                  if (!wcschr (L".?!\"')]", wc))
+                    {
+                      state.last_letter = wc;
+                      break;
+                    }
+                }
             }
 
-          state.word_counter += len;
         }
+    }
 
-      /* TODO: Shift this into the "else" clause above, because 
-         xspara__end_line would have set state.counter to 0. */
-      if (state.counter != 0
-          && state.counter + state.word_counter + state.space_counter
-              > state.max)
+  if (strchr (word, '\n'))
+    {
+      /* If there was a newline in the word we just added, put the entire
+         pending ouput in the results string, and start a new line.
+         TODO: Does line_counter get incremented properly in this 
+         circumstance? */
+      /* TODO: Could we just call _add_pending_word here? */
+      text_append_n (result, state.space.text, state.space.end);
+      state.space.end = 0;
+      state.space_counter = 0;
+      text_append_n (result, state.word.text, state.word.end);
+      state.word.end = 0;
+      state.word_counter = 0;
+      state.invisible_pending_word = 0;
+
+      xspara__end_line ();
+    }
+  else
+    {
+      /* The possibility of two-column characters is ignored here. */
+
+      /* Calculate length of multibyte string in characters. */
+      int len = 0;
+      int left = word_len;
+      wchar_t w;
+      char *p = word;
+
+      while (left > 0)
         {
-          xspara__cut_line (result);
+          int char_len = mbrtowc (&w, p, 10, NULL);
+          left -= char_len;
+          p += char_len;
+          len++;
         }
+
+      state.word_counter += len;
     }
+
+  /* TODO: Shift this into the "else" clause above, because 
+     xspara__end_line would have set state.counter to 0. */
+  if (state.counter != 0
+      && state.counter + state.word_counter + state.space_counter
+          > state.max)
+    {
+      xspara__cut_line (result);
+    }
 }
 
 /* Like _add_next but zero end_line_count at beginning. */
 char *
-xspara_add_next (char *text, int text_len)
+xspara_add_next (char *text, int text_len, int transparent)
 {
   TEXT t;
 
   text_init (&t);
   state.end_line_count = 0;
-  //fprintf (stderr, "PASSED EOS %d\n", end_sentence);
-  xspara__add_next (&t, text, text_len, 0);
+  xspara__add_next (&t, text, text_len, transparent);
 
   if (t.space > 0)
     return t.text;

Modified: trunk/tp/Texinfo/Convert/XSParagraph/xspara.h
===================================================================
--- trunk/tp/Texinfo/Convert/XSParagraph/xspara.h       2015-07-27 12:57:27 UTC 
(rev 6475)
+++ trunk/tp/Texinfo/Convert/XSParagraph/xspara.h       2015-07-27 19:05:31 UTC 
(rev 6476)
@@ -2,7 +2,7 @@
 void xspara_set_state (HV *state);
 void xspara_get_state (HV *state);
 int xspara_init (void);
-char *xspara_add_next (char *, int);
+char *xspara_add_next (char *, int, int transparent);
 char *xspara_add_text (char *);
 char *xspara_set_space_protection (int space_protection, int ignore_columns,
                              int keep_end_lines, int french_spacing);

Modified: trunk/tp/t/paragraph.t
===================================================================
--- trunk/tp/t/paragraph.t      2015-07-27 12:57:27 UTC (rev 6475)
+++ trunk/tp/t/paragraph.t      2015-07-27 19:05:31 UTC (rev 6476)
@@ -2,19 +2,29 @@
 
 use Test::More;
 use File::Spec;
-BEGIN { plan tests => 127;
+
+BEGIN { plan tests => 127 * 2 - 45;
         if (defined($ENV{'top_srcdir'})) {
           unshift @INC, File::Spec->catdir($ENV{'top_srcdir'}, 'tp');
           my $lib_dir = File::Spec->catdir($ENV{'top_srcdir'}, 'tp', 
'maintain');
           unshift @INC, (File::Spec->catdir($lib_dir, 'lib', 'libintl-perl', 
'lib'),
                          File::Spec->catdir($lib_dir, 'lib', 
'Unicode-EastAsianWidth', 'lib'),
                          File::Spec->catdir($lib_dir, 'lib', 'Text-Unidecode', 
'lib'));
-      }};
+      }
+    };
 
 use lib 'maintain/lib/Unicode-EastAsianWidth/lib/';
 use Texinfo::Convert::Paragraph;
+use lib 'Texinfo/Convert/XSParagraph';
+use Texinfo::Convert::XSParagraph::XSParagraph;
 use Texinfo::Convert::Line;
 use Texinfo::Convert::UnFilled;
+
+# We do the test for Texinfo::Convert::Paragraph tests twice, once with 
+# Texinfo::Convert::Paragraph, once with XSParagraph.  A few them are only 
done 
+# once, though.
+my $testing_XSParagraph;
+DOITAGAIN:
 ok(1, "modules loading"); # If we made it this far, we're ok.
 
 sub test_para($$$;$)
@@ -484,6 +494,7 @@
 is ($result, 'aa   ggg', 'space protected space');
 $para->end();
 
+if (!$testing_XSParagraph) {
 $para = Texinfo::Convert::Paragraph->new({'max' => 8});
 $result = $para->add_text('aa ');
 is ($para->{'lines_counter'}, 0, 'count lines first');
@@ -492,6 +503,11 @@
 $result .= $para->end();
 is ($para->{'lines_counter'}, 2, 'count lines end paragraph');
 
+  *Texinfo::Convert::Paragraph:: = *XSParagraph::;
+  $testing_XSParagraph = 1;
+  goto DOITAGAIN;
+}
+
 sub test_line($$$;$)
 {
   my $args = shift;




reply via email to

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