texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Gavin D. Smith
Date: Sun, 20 Mar 2022 04:55:21 -0400 (EDT)

branch: master
commit f940a3c7e286840d94089e68db31e0cbc682b745
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sun Oct 20 15:13:47 2019 +0100

    use packetize function to send index
---
 js/infog/extension.c | 107 +++++++++++++++++++++------------------------------
 1 file changed, 44 insertions(+), 63 deletions(-)

diff --git a/js/infog/extension.c b/js/infog/extension.c
index 05613fbb69..712fb89ded 100644
--- a/js/infog/extension.c
+++ b/js/infog/extension.c
@@ -221,6 +221,45 @@ find_indices (WebKitDOMHTMLCollection *links, gulong 
num_links)
   g_string_free (s, TRUE);
 }
 
+/* Split up msg into packets of size no more than PACKET_SIZE so it can
+   be sent over the socket. */
+void
+packetize (char *msg_type, GString *msg)
+{
+  GString *s;
+  char *p, *q;
+  int try = 0; /* To check if a single record is too long for a packet. */
+
+  p = msg->str;
+  s = g_string_new (NULL);
+
+next_packet:
+  g_string_truncate (s, 0);
+  g_string_append (s, msg_type);
+  g_string_append (s, "\n");
+
+  /* Get next two lines and try to fit them in the buffer. */
+  while ((q = strchr (p, '\n')) && (q = strchr (q + 1, '\n')))
+    {
+      gsize old_len = s->len;
+      g_string_append_len (s, p, q - p + 1);
+      if (s->len > PACKET_SIZE)
+        {
+          if (try == 1)
+            break;
+          g_string_truncate (s, old_len);
+          send_datagram (s);
+          try = 1;
+          goto next_packet;
+        }
+
+      try = 0;
+      p = q + 1;
+    }
+  send_datagram (s);
+  g_string_free (s, TRUE);
+}
+
 void
 send_index (WebKitDOMHTMLCollection *links, gulong num_links)
 {
@@ -229,11 +268,6 @@ send_index (WebKitDOMHTMLCollection *links, gulong 
num_links)
   gulong i = 0;
   GString *s = g_string_new (NULL);
 
-  /* Break index information up into datagrams each of size less
-     than PACKET_SIZE. */
-
-  g_string_assign (s, "index\n");
-
   for (; i < num_links; i++)
     {
       WebKitDOMNode *node
@@ -259,72 +293,19 @@ send_index (WebKitDOMHTMLCollection *links, gulong 
num_links)
       gchar *href = webkit_dom_element_get_attribute (element, "href");
       if (href && strstr (href, "#index-"))
         {
-          int try = 0;
-          gsize old_len = s->len;
-          do
-            {
-              g_string_append (s, webkit_dom_node_get_text_content (node));
-              g_string_append (s, "\n");
-              g_string_append (s, href);
-              g_string_append (s, "\n");
-
-              if (s->len > PACKET_SIZE && try != 1)
-                {
-                  g_string_truncate (s, old_len);
-                  // debug (2, "sending packet %u||%s||\n", s->len, s->str);
-                  send_datagram (s);
-                  g_string_assign (s, "index\n");
-                  try++;
-                  continue;
-                }
-            }
-          while (0);
+          g_string_append (s, webkit_dom_node_get_text_content (node));
+          g_string_append (s, "\n");
+          g_string_append (s, href);
+          g_string_append (s, "\n");
         }
     }
-  send_datagram (s);
+  packetize ("index", s);
 
   g_string_free (s, TRUE);
 
   debug (1, "index sent\n");
 }
 
-void
-packetize (char *msg_type, GString *msg)
-{
-  GString *s;
-  char *p, *q;
-  int try = 0; /* To check if a single record is too long for a packet. */
-
-  p = msg->str;
-  s = g_string_new (NULL);
-
-next_packet:
-  g_string_truncate (s, 0);
-  g_string_append (s, msg_type);
-  g_string_append (s, "\n");
-
-  /* Get next two lines and try to fit them in the buffer. */
-  while ((q = strchr (p, '\n')) && (q = strchr (q + 1, '\n')))
-    {
-      gsize old_len = s->len;
-      g_string_append_len (s, p, q - p + 1);
-      if (s->len > PACKET_SIZE)
-        {
-          if (try == 1)
-            break;
-          g_string_truncate (s, old_len);
-          send_datagram (s);
-          try = 1;
-          goto next_packet;
-        }
-
-      try = 0;
-      p = q + 1;
-    }
-  send_datagram (s);
-  g_string_free (s, TRUE);
-}
-
 void
 send_toc (WebKitDOMDocument *dom_document)
 {



reply via email to

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