texinfo-commits
[Top][All Lists]
Advanced

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

[7972] update xs_abort_empty_line


From: gavinsmith0123
Subject: [7972] update xs_abort_empty_line
Date: Wed, 25 Oct 2017 17:28:49 -0400 (EDT)

Revision: 7972
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7972
Author:   gavin
Date:     2017-10-25 17:28:49 -0400 (Wed, 25 Oct 2017)
Log Message:
-----------
update xs_abort_empty_line

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/tp/Texinfo/MiscXS/misc.c
    trunk/tp/Texinfo/Parser.pm

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2017-10-25 20:23:05 UTC (rev 7971)
+++ trunk/ChangeLog     2017-10-25 21:28:49 UTC (rev 7972)
@@ -1,5 +1,11 @@
 2017-10-25  Gavin Smith  <address@hidden>
 
+       * tp/Texinfo/MiscXS/misc.c (xs_abort_empty_line): Update to
+       match Perl implementation.
+       * tp/Texinfo/Parser.pm (import): Re-enable XS overrides.
+
+2017-10-25  Gavin Smith  <address@hidden>
+
        * tp/Texinfo/Parser.pm (_parse_texi): Rename reference to spaces 
        element from 'spaces_before_argument' to 'spaces_before_argument_elt'.
        (_abort_empty_line): Replace 'spaces_before_argument_elt' value

Modified: trunk/tp/Texinfo/MiscXS/misc.c
===================================================================
--- trunk/tp/Texinfo/MiscXS/misc.c      2017-10-25 20:23:05 UTC (rev 7971)
+++ trunk/tp/Texinfo/MiscXS/misc.c      2017-10-25 21:28:49 UTC (rev 7972)
@@ -1,4 +1,4 @@
-/* Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free Software
+/* Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Free Software
    Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
@@ -47,13 +47,18 @@
 const char *whitespace_chars = " \t\f\v\r\n";
 
 int
-xs_abort_empty_line (HV *self, HV *current, SV *additional_text_in)
+xs_abort_empty_line (HV *self, HV *current, SV *additional_spaces_in)
 {
-  char *additional_text;
+  char *additional_spaces;
   AV *contents_array;
   SV **svp;
   int contents_num;
-  HV *last_elt;
+  HV *spaces_elt;
+  char *key;
+  HV *test_elt;
+  HV *test_extra;
+
+  HV *owning_elt = 0;
   char *type;
   SV *existing_text_sv;
 
@@ -60,20 +65,20 @@
   dTHX;
 
   /* Get additional text in UTF-8. */
-  if (additional_text_in)
+  if (additional_spaces_in)
     {
       STRLEN len;
       static char *new_string;
-      additional_text = SvPV (additional_text_in, len);
-      if (!SvUTF8 (additional_text_in))
+      additional_spaces = SvPV (additional_spaces_in, len);
+      if (!SvUTF8 (additional_spaces_in))
         {
           free (new_string);
-          new_string = bytes_to_utf8 (additional_text, &len);
-          additional_text = new_string;
+          new_string = bytes_to_utf8 (additional_spaces, &len);
+          additional_spaces = new_string;
         }
     }
   else
-    additional_text = "";
+    additional_spaces = "";
 
   svp = hv_fetch (current, "contents", strlen("contents"), 0);
   if (!svp)
@@ -84,9 +89,9 @@
   if (contents_num == 0)
     return 0;
 
-  last_elt = (HV *) SvRV (*av_fetch (contents_array, contents_num - 1, 0));
+  spaces_elt = (HV *) SvRV (*av_fetch (contents_array, contents_num - 1, 0));
 
-  svp = hv_fetch (last_elt, "type", strlen ("type"), 0);
+  svp = hv_fetch (spaces_elt, "type", strlen ("type"), 0);
   if (!svp)
     return 0;
 
@@ -105,34 +110,43 @@
   
   //fprintf (stderr, "ABORT EMPTY\n");
 
-  svp = hv_fetch (last_elt, "text", strlen ("text"), 0);
-  if (!svp)
-    return 0; /* or create it? change last arg from 0 to 1 */
-  existing_text_sv = *svp;
+  /* Look for another reference to spaces_elt. */
+  test_elt = current;
 
-  /* Append the 'additional_text' argument. */
-  sv_utf8_upgrade (existing_text_sv);
-  sv_catpv (existing_text_sv, additional_text);
-
-  if (!*SvPV_nolen (existing_text_sv)) /* existing text is empty */
+  svp = hv_fetch (test_elt, "extra", strlen ("extra"), 0);
+  if (svp)
     {
-      HV *test_extra;
-      char *key;
-      HV *test_elt;
+      test_extra = (HV *) SvRV (*svp);
+      key = "spaces_before_argument_elt";
+      svp = hv_fetch (test_extra, key, strlen (key), 0);
+      if (svp)
+        {
+          if ((HV *) SvRV (*svp) == spaces_elt)
+            goto found;
+        }
 
-      /* Look for another reference to last_elt. */
+      key = "spaces_after_command";
+      svp = hv_fetch (test_extra, key, strlen (key), 0);
+      if (svp)
+        {
+          if ((HV *) SvRV (*svp) == spaces_elt)
+            goto found;
+        }
+    }
 
-      test_elt = current;
-
+  svp = hv_fetch (current, "parent", strlen ("parent"), 0);
+  if (svp)
+    {
+      test_elt = (HV *) SvRV (*svp);
       svp = hv_fetch (test_elt, "extra", strlen ("extra"), 0);
       if (svp)
         {
           test_extra = (HV *) SvRV (*svp);
-          key = "spaces_before_argument";
+          key = "spaces_before_argument_elt";
           svp = hv_fetch (test_extra, key, strlen (key), 0);
           if (svp)
             {
-              if ((HV *) SvRV (*svp) == last_elt)
+              if ((HV *) SvRV (*svp) == spaces_elt)
                 goto found;
             }
 
@@ -140,40 +154,34 @@
           svp = hv_fetch (test_extra, key, strlen (key), 0);
           if (svp)
             {
-              if ((HV *) SvRV (*svp) == last_elt)
+              if ((HV *) SvRV (*svp) == spaces_elt)
                 goto found;
             }
         }
+    }
 
-      svp = hv_fetch (current, "parent", strlen ("parent"), 0);
-      if (svp)
-        {
-          test_elt = (HV *) SvRV (*svp);
-          svp = hv_fetch (test_elt, "extra", strlen ("extra"), 0);
-          if (svp)
-            {
-              test_extra = (HV *) SvRV (*svp);
-              key = "spaces_before_argument";
-              svp = hv_fetch (test_extra, key, strlen (key), 0);
-              if (svp)
-                {
-                  if ((HV *) SvRV (*svp) == last_elt)
-                    goto found;
-                }
+  if (0)
+    {
+found:
+      owning_elt = test_elt;
+    }
 
-              key = "spaces_after_command";
-              svp = hv_fetch (test_extra, key, strlen (key), 0);
-              if (svp)
-                {
-                  if ((HV *) SvRV (*svp) == last_elt)
-                    goto found;
-                }
-            }
-        }
+  svp = hv_fetch (spaces_elt, "text", strlen ("text"), 0);
+  if (!svp)
+    return 0; /* or create it? change last arg from 0 to 1 */
+  existing_text_sv = *svp;
 
-      if (0)
+  /* Append the 'additional_spaces' argument. */
+  sv_utf8_upgrade (existing_text_sv);
+  sv_catpv (existing_text_sv, additional_spaces);
+
+  if (!*SvPV_nolen (existing_text_sv)) /* existing text is empty */
+    {
+      /* Remove spaces_elt */
+      av_pop (contents_array);
+
+      if (owning_elt)
         {
-found:
           /* We found an "extra" reference to this element.  Remove it. */
           hv_delete (test_extra, key, strlen (key), G_DISCARD);
 
@@ -182,9 +190,6 @@
           if (!hv_iternext (test_extra))
             hv_delete (test_elt, "extra", strlen ("extra"), G_DISCARD);
         }
-
-      /* Remove last_elt */
-      av_pop (contents_array);
     }
   else if (!strcmp (type, "empty_line"))
     {
@@ -232,20 +237,40 @@
           && strcmp (top_context, "def")
           && strcmp (top_context, "inlineraw"))
         {
-          hv_store (last_elt, "type", strlen ("type"),
+          hv_store (spaces_elt, "type", strlen ("type"),
                     newSVpv ("empty_spaces_before_paragraph", 0), 0);
         }
       else
         {
 delete_type:
-          hv_delete (last_elt, "type", strlen ("type"), G_DISCARD);
+          hv_delete (spaces_elt, "type", strlen ("type"), G_DISCARD);
         }
     }
   else if (!strcmp (type, "empty_line_after_command"))
     {
-      hv_store (last_elt, "type", strlen ("type"),
+      hv_store (spaces_elt, "type", strlen ("type"),
                 newSVpv ("empty_spaces_after_command", 0), 0);
     }
+  else if (!strcmp (type, "empty_spaces_before_argument"))
+    {
+      STRLEN len;
+      char *ptr;
+
+      /* Remove spaces_elt */
+      av_pop (contents_array);
+
+      ptr = SvPV(existing_text_sv, len);
+      /* Replace element reference with a simple string. */
+      hv_store (test_extra,
+                 "spaces_before_argument",
+                 strlen ("spaces_before_argument"),
+                 newSVpv(ptr, len),
+                 0);
+      hv_delete (test_extra,
+                 "spaces_before_argument_elt",
+                 strlen ("spaces_before_argument_elt"),
+                 G_DISCARD);
+    }
   return 1;
 }
 

Modified: trunk/tp/Texinfo/Parser.pm
===================================================================
--- trunk/tp/Texinfo/Parser.pm  2017-10-25 20:23:05 UTC (rev 7971)
+++ trunk/tp/Texinfo/Parser.pm  2017-10-25 21:28:49 UTC (rev 7972)
@@ -66,7 +66,7 @@
 
 our $module_loaded = 0;
 sub import {
-  if (0 and !$module_loaded) {
+  if (!$module_loaded) {
     Texinfo::XSLoader::override ("Texinfo::Parser::_merge_text",
       "Texinfo::MiscXS::merge_text");
     Texinfo::XSLoader::override ("Texinfo::Parser::_abort_empty_line",




reply via email to

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