texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/XS/convert/convert_html.c (convert_t


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/convert/convert_html.c (convert_today_command) (commands_internal_conversion_table), tp/Texinfo/XS/main/convert_to_text.c (convert_to_text_internal), tp/Texinfo/XS/main/convert_utils.c (expand_today): implement expand_today. Use it in convert_to_text and in implementation of convert_today_command for HTML in C.
Date: Wed, 13 Dec 2023 15:35:34 -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 0a591e031f * tp/Texinfo/XS/convert/convert_html.c 
(convert_today_command) (commands_internal_conversion_table), 
tp/Texinfo/XS/main/convert_to_text.c (convert_to_text_internal), 
tp/Texinfo/XS/main/convert_utils.c (expand_today): implement expand_today.  Use 
it in convert_to_text and in implementation of convert_today_command for HTML 
in C.
0a591e031f is described below

commit 0a591e031f5e46d0eac4c20c0fa09fafd479f412
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Dec 13 21:35:25 2023 +0100

    * tp/Texinfo/XS/convert/convert_html.c (convert_today_command)
    (commands_internal_conversion_table),
    tp/Texinfo/XS/main/convert_to_text.c (convert_to_text_internal),
    tp/Texinfo/XS/main/convert_utils.c (expand_today): implement
    expand_today.  Use it in convert_to_text and in implementation of
    convert_today_command for HTML in C.
---
 ChangeLog                            |  9 ++++++
 tp/Texinfo/XS/convert/convert_html.c | 16 ++++++++++
 tp/Texinfo/XS/main/convert_to_text.c | 17 ++++++-----
 tp/Texinfo/XS/main/convert_utils.c   | 57 ++++++++++++++++++++++++++++++++++++
 tp/Texinfo/XS/main/convert_utils.h   |  2 ++
 5 files changed, 93 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 93880917bd..e107a09759 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-12-13  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/convert_html.c (convert_today_command)
+       (commands_internal_conversion_table),
+       tp/Texinfo/XS/main/convert_to_text.c (convert_to_text_internal),
+       tp/Texinfo/XS/main/convert_utils.c (expand_today): implement
+       expand_today.  Use it in convert_to_text and in implementation of
+       convert_today_command for HTML in C.
+
 2023-12-13  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/convert_to_text.c (copy_options_for_convert_text)
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index 82df4e9ced..55b41aee52 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -6807,6 +6807,21 @@ css_string_convert_no_arg_command (CONVERTER *self,
     self->html_command_conversion[formatted_cmd][HCC_type_css_string].text);
 }
 
+void
+convert_today_command (CONVERTER *self, const enum command_id cmd,
+                       const ELEMENT *element,
+                       const HTML_ARGS_FORMATTED *args_formatted,
+                       const char *content, TEXT *result)
+{
+  ELEMENT *today_element = expand_today (self->conf);
+
+  add_to_element_list (&self->tree_to_build, today_element);
+
+  convert_to_html_internal (self, today_element, result, "convert today");
+
+  remove_element_from_list (&self->tree_to_build, today_element);
+  destroy_element_and_children (today_element);
+}
 
 void
 convert_w_command (CONVERTER *self, const enum command_id cmd,
@@ -7799,6 +7814,7 @@ convert_contents_command (CONVERTER *self, const enum 
command_id cmd,
 /* associate command to the C function implementing the conversion */
 static COMMAND_INTERNAL_CONVERSION commands_internal_conversion_table[] = {
   {CM_w, &convert_w_command},
+  {CM_today, &convert_today_command},
 
   {CM_contents, &convert_contents_command},
   {CM_shortcontents, &convert_contents_command},
diff --git a/tp/Texinfo/XS/main/convert_to_text.c 
b/tp/Texinfo/XS/main/convert_to_text.c
index 2becdc2304..88b53cf3c0 100644
--- a/tp/Texinfo/XS/main/convert_to_text.c
+++ b/tp/Texinfo/XS/main/convert_to_text.c
@@ -524,13 +524,14 @@ convert_to_text_internal (const ELEMENT *element, 
TEXT_OPTIONS *text_options,
               ADD(sort_brace_no_arg_commands[data_cmd]);
               return;
             }
-/* TODO when this can be tested with other converters
-      elsif ($options->{'converter'}) {
-        return _convert(Texinfo::Convert::Utils::expand_today(
-                                         $options->{'converter'}),
-                        $options);
-      }
-*/
+          else if (text_options->other_converter_options)
+            {
+              ELEMENT *today_element
+                = expand_today (text_options->other_converter_options);
+              convert_to_text_internal (today_element,
+                                        text_options, result);
+              destroy_element_and_children (today_element);
+            }
           else if (text_options->TEST)
             {
               ADD("a sunny day");
@@ -541,7 +542,7 @@ convert_to_text_internal (const ELEMENT *element, 
TEXT_OPTIONS *text_options,
               time_t tloc;
               struct tm *time_tm;
               int year;
-              time (&tloc);
+              tloc = time (NULL);
               time_tm = localtime (&tloc);
               year = time_tm->tm_year + 1900;
               text_printf (result, "%s %d, %d",
diff --git a/tp/Texinfo/XS/main/convert_utils.c 
b/tp/Texinfo/XS/main/convert_utils.c
index 675adbdb02..8068e83ed5 100644
--- a/tp/Texinfo/XS/main/convert_utils.c
+++ b/tp/Texinfo/XS/main/convert_utils.c
@@ -21,6 +21,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <errno.h>
+#include <time.h>
 
 #include "options_types.h"
 #include "element_types.h"
@@ -52,6 +53,62 @@ element_associated_processing_encoding (const ELEMENT 
*element)
   return input_encoding;
 }
 
+ELEMENT *
+expand_today (OPTIONS *options)
+{
+  time_t tloc;
+  struct tm *time_tm;
+  int year;
+  char *source_date_epoch;
+  NAMED_STRING_ELEMENT_LIST *substrings;
+  ELEMENT *month_tree;
+  ELEMENT *day_element;
+  ELEMENT *year_element;
+  ELEMENT *result;
+
+  if (options->TEST > 0)
+    {
+      result = new_element (ET_NONE);
+      text_append (&result->text, "a sunny day");
+      return result;
+    }
+
+  /* See https://reproducible-builds.org/specs/source-date-epoch/ */
+  source_date_epoch = getenv ("SOURCE_DATE_EPOCH");
+
+  if (source_date_epoch)
+    {
+   /* This assumes that the SOURCE_DATE_EPOCH environment variable will contain
+      a correct, positive integer in the time_t range */
+      tloc = (time_t)strtoll(source_date_epoch, NULL, 10);
+      time_tm = gmtime (&tloc);
+    }
+  else
+    {
+      tloc = time (NULL);
+      time_tm = localtime (&tloc);
+    }
+
+  year = time_tm->tm_year + 1900;
+
+  month_tree = gdt_tree (convert_utils_month_name[time_tm->tm_mon], 0, options,
+                         0, 0, 0);
+  day_element = new_element (ET_NONE);
+  year_element = new_element (ET_NONE);
+  text_printf (&day_element->text, "%d", time_tm->tm_mday);
+  text_printf (&year_element->text, "%d", year);
+
+  substrings = new_named_string_element_list ();
+  add_element_to_named_string_element_list (substrings, "month", month_tree);
+  add_element_to_named_string_element_list (substrings, "day", day_element);
+  add_element_to_named_string_element_list (substrings, "year", year_element);
+
+  result = gdt_tree ("{month} {day}, {year}", 0, options, substrings, 0, 0);
+  destroy_named_string_element_list (substrings);
+
+  return result;
+}
+
 ACCENTS_STACK *
 find_innermost_accent_contents (const ELEMENT *element)
 {
diff --git a/tp/Texinfo/XS/main/convert_utils.h 
b/tp/Texinfo/XS/main/convert_utils.h
index af39999eb6..bbb907fe48 100644
--- a/tp/Texinfo/XS/main/convert_utils.h
+++ b/tp/Texinfo/XS/main/convert_utils.h
@@ -19,6 +19,8 @@ typedef struct PARSED_DEF {
     ELEMENT *args;
 } PARSED_DEF;
 
+ELEMENT *expand_today (OPTIONS *options);
+
 ACCENTS_STACK *find_innermost_accent_contents (const ELEMENT *element);
 
 char *add_heading_number (OPTIONS *options, const ELEMENT *current, char *text,



reply via email to

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