[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Sat, 21 Oct 2023 16:23:12 -0400 (EDT) |
branch: master
commit b83b739b1e4c4d5e9e8eba2d2c633eeee7cb1449
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Oct 21 16:32:27 2023 +0200
* tp/Texinfo/Convert/HTML.pm (_prepare_special_units_directions):
return if $special_units is not defined.
* tp/Texinfo/Structuring.pm (units_file_directions): remove unused
variable and set my in the right block.
* tp/Texinfo/XS/main/tree_types.h (RUD_FILE_DIRECTIONS_TYPES)
(enum relative_unit_direction_type): rename enum
relative_unit_direction as enum relative_unit_direction_type.
Add RUD_FILE_DIRECTIONS_TYPES to complete
relative_unit_direction_type.
* tp/Texinfo/XS/main/output_unit.c (relative_unit_direction_name)
(print_output_unit_directions): setup direction names and use them in
print_output_unit_directions.
* tp/Texinfo/XS/convert/convert_html.c
(prepare_special_units_directions)
(html_prepare_units_directions_files),
tp/Texinfo/XS/main/output_unit.c (units_file_directions),
tp/Texinfo/XS/main/utils.h (FILE_NAME_PATH_COUNTER): finish
implementation of html_prepare_units_directions_files, with
prepare_special_units_directions, units_file_directions and
setting of elements_in_file_count.
---
ChangeLog | 27 ++++++++++
tp/Texinfo/Convert/HTML.pm | 8 +--
tp/Texinfo/Structuring.pm | 4 +-
tp/Texinfo/XS/convert/convert_html.c | 36 +++++++++++++
tp/Texinfo/XS/main/output_unit.c | 101 +++++++++++++++++++++++++++++++++--
tp/Texinfo/XS/main/output_unit.h | 2 +
tp/Texinfo/XS/main/tree_types.h | 11 +++-
tp/Texinfo/XS/main/utils.h | 2 +
8 files changed, 181 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 07383ff161..607235da49 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+2023-10-21 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/HTML.pm (_prepare_special_units_directions):
+ return if $special_units is not defined.
+
+ * tp/Texinfo/Structuring.pm (units_file_directions): remove unused
+ variable and set my in the right block.
+
+ * tp/Texinfo/XS/main/tree_types.h (RUD_FILE_DIRECTIONS_TYPES)
+ (enum relative_unit_direction_type): rename enum
+ relative_unit_direction as enum relative_unit_direction_type.
+ Add RUD_FILE_DIRECTIONS_TYPES to complete
+ relative_unit_direction_type.
+
+ * tp/Texinfo/XS/main/output_unit.c (relative_unit_direction_name)
+ (print_output_unit_directions): setup direction names and use them in
+ print_output_unit_directions.
+
+ * tp/Texinfo/XS/convert/convert_html.c
+ (prepare_special_units_directions)
+ (html_prepare_units_directions_files),
+ tp/Texinfo/XS/main/output_unit.c (units_file_directions),
+ tp/Texinfo/XS/main/utils.h (FILE_NAME_PATH_COUNTER): finish
+ implementation of html_prepare_units_directions_files, with
+ prepare_special_units_directions, units_file_directions and
+ setting of elements_in_file_count.
+
2023-10-21 Gavin Smith <gavinsmith0123@gmail.com>
Handle blocks of word characters in XS paragraph formatter
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 04355eb644..c3eda4533a 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -9324,13 +9324,13 @@ sub _prepare_units_directions_files($$$$$$$$)
_prepare_special_units_directions($self, $special_units);
# do element directions related to files.
- # FIXME do it here or before? Here it means that
- # PrevFile and NextFile can be set.
+ # Here such that PrevFile and NextFile can be set.
Texinfo::Structuring::units_file_directions($output_units);
$self->_prepare_frames_filenames($document_name);
- # only in HTML, not in Texinfo::Convert::Converter
+ # elements_in_file_count is only set in HTML, not in
+ # Texinfo::Convert::Converter
$self->{'elements_in_file_count'} = {};
# condition could also be based on $output_file ne ''
if ($self->{'file_counters'}) {
@@ -9604,6 +9604,8 @@ sub _prepare_special_units_directions($$)
my $self = shift;
my $special_units = shift;
+ return unless $special_units;
+
foreach my $special_unit (@$special_units) {
$special_unit->{'directions'}->{'This'} = $special_unit;
}
diff --git a/tp/Texinfo/Structuring.pm b/tp/Texinfo/Structuring.pm
index 8953cadfa2..8450307fdc 100644
--- a/tp/Texinfo/Structuring.pm
+++ b/tp/Texinfo/Structuring.pm
@@ -2256,10 +2256,8 @@ sub units_file_directions($)
# are added to the first element in the file.
my @first_unit_in_file_directions;
foreach my $output_unit (@$output_units) {
- my $directions;
- my $filename;
if (defined($output_unit->{'unit_filename'})) {
- $filename = $output_unit->{'unit_filename'};
+ my $filename = $output_unit->{'unit_filename'};
my $current_output_unit = $output_unit;
if (not defined($current_filename)
or $filename ne $current_filename) {
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index fa54387a3e..43399fc73e 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -2051,6 +2051,22 @@ html_set_pages_files (CONVERTER *self, OUTPUT_UNIT_LIST
*output_units,
return files_source_info;
}
+static void
+prepare_special_units_directions (CONVERTER *self,
+ OUTPUT_UNIT_LIST *special_units)
+{
+ int i;
+
+ if (!special_units)
+ return;
+
+ for (i = 0; i < special_units->number; i++)
+ {
+ OUTPUT_UNIT *special_unit = special_units->list[i];
+ special_unit->directions[RUD_type_This] = special_unit;
+ }
+}
+
FILE_SOURCE_INFO_LIST *
html_prepare_units_directions_files (CONVERTER *self,
int output_units_descriptor,
@@ -2058,6 +2074,7 @@ html_prepare_units_directions_files (CONVERTER *self,
char *output_file, char *destination_directory, char
*output_filename,
char *document_name)
{
+ int i;
FILE_SOURCE_INFO_LIST *files_source_info = 0;
OUTPUT_UNIT_LIST *output_units
= retrieve_output_units (output_units_descriptor);
@@ -2083,5 +2100,24 @@ html_prepare_units_directions_files (CONVERTER *self,
units_directions (self->conf, self->document->identifiers_target,
output_units);
+ prepare_special_units_directions (self, special_units);
+
+ units_file_directions (output_units);
+
+ /* elements_in_file_count is only set in HTML, not in
+ Texinfo::Convert::Converter */
+ if (self->output_unit_files)
+ {
+ for (i = 0; i < self->output_unit_files->number; i++)
+ {
+ FILE_NAME_PATH_COUNTER *file_counter
+ = &self->output_unit_files->list[i];
+
+ /* counter is dynamic, decreased when the element is encountered
+ elements_in_file_count is not modified afterwards */
+ file_counter->elements_in_file_count = file_counter->counter;
+ }
+ }
+
return files_source_info;
}
diff --git a/tp/Texinfo/XS/main/output_unit.c b/tp/Texinfo/XS/main/output_unit.c
index a56a8de3b6..c683140f3c 100644
--- a/tp/Texinfo/XS/main/output_unit.c
+++ b/tp/Texinfo/XS/main/output_unit.c
@@ -13,6 +13,9 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+/* corresponds to Texinfo::Structuring code related to output units and
+ used in converters */
+
#include <config.h>
#include <stdlib.h>
#include <string.h>
@@ -32,6 +35,17 @@
#include "convert_to_texinfo.h"
#include "output_unit.h"
+char *relative_unit_direction_name[] = {
+ #define rud_type(name) #name,
+ RUD_DIRECTIONS_TYPES_LIST
+ RUD_FILE_DIRECTIONS_TYPES
+ #undef rud_type
+ #define rud_type(name) "FirstInFile" #name,
+ RUD_DIRECTIONS_TYPES_LIST
+ #undef rud_type
+};
+
+
static OUTPUT_UNIT_LIST *output_units_list;
static size_t output_units_number;
static size_t output_units_space;
@@ -444,7 +458,7 @@ print_output_unit_directions (OUTPUT_UNIT *output_unit)
OUTPUT_UNIT *direction = output_unit->directions[i];
if (direction)
{
- text_printf (&result, " $direction: %s\n",
+ text_printf (&result, " %s: %s\n", relative_unit_direction_name[i],
output_unit_texi (direction));
with_direction++;
}
@@ -456,12 +470,12 @@ print_output_unit_directions (OUTPUT_UNIT *output_unit)
}
-static enum relative_unit_direction node_unit_directions[]
+static enum relative_unit_direction_type node_unit_directions[]
= {RUD_type_NodeNext,
RUD_type_NodePrev,
RUD_type_NodeUp};
-static enum relative_unit_direction section_unit_directions[]
+static enum relative_unit_direction_type section_unit_directions[]
= {RUD_type_Next,
RUD_type_Prev,
RUD_type_Up};
@@ -744,3 +758,84 @@ units_directions (OPTIONS *customization_information,
}
}
}
+
+void
+units_file_directions (OUTPUT_UNIT_LIST *output_units)
+{
+ int i;
+ char *current_filename = 0;
+ OUTPUT_UNIT *first_unit_in_file = 0;
+
+ if (!output_units || !output_units->number)
+ return;
+
+ for (i = 0; i < output_units->number; i++)
+ {
+ OUTPUT_UNIT *output_unit = output_units->list[i];
+
+ if (output_unit->unit_filename)
+ {
+ char *filename = output_unit->unit_filename;
+ OUTPUT_UNIT *current_output_unit = output_unit;
+
+ if (!current_filename || strcmp (filename, current_filename))
+ {
+ first_unit_in_file = output_unit;
+ current_filename = filename;
+ }
+
+ while (1)
+ {
+ if (current_output_unit->tree_unit_directions[D_prev])
+ {
+ current_output_unit
+ = current_output_unit->tree_unit_directions[D_prev];
+ if (current_output_unit->unit_filename)
+ {
+ if (strcmp (current_output_unit->unit_filename,
filename))
+ {
+ output_unit->directions[RUD_type_PrevFile]
+ = current_output_unit;
+ break;
+ }
+ }
+ else
+ break;
+ }
+ else
+ break;
+ }
+ current_output_unit = output_unit;
+ while (1)
+ {
+ if (current_output_unit->tree_unit_directions[D_next])
+ {
+ current_output_unit
+ = current_output_unit->tree_unit_directions[D_next];
+ if (current_output_unit->unit_filename)
+ {
+ if (strcmp (current_output_unit->unit_filename,
filename))
+ {
+ output_unit->directions[RUD_type_NextFile]
+ = current_output_unit;
+ break;
+ }
+ }
+ else
+ break;
+ }
+ else
+ break;
+
+ }
+ }
+ /* set the directions of the first elements in file, to
+ be used in footers for example */
+ if (first_unit_in_file)
+ {
+ memcpy (&output_unit->directions[RUD_type_FirstInFileThis],
+ &first_unit_in_file->directions[RUD_type_This],
+ (RUD_type_NodeUp - RUD_type_This +1) * sizeof (OUTPUT_UNIT
*));
+ }
+ }
+}
diff --git a/tp/Texinfo/XS/main/output_unit.h b/tp/Texinfo/XS/main/output_unit.h
index 246490cd6c..76ec30e490 100644
--- a/tp/Texinfo/XS/main/output_unit.h
+++ b/tp/Texinfo/XS/main/output_unit.h
@@ -23,4 +23,6 @@ char *output_unit_texi (OUTPUT_UNIT *output_unit);
void units_directions (OPTIONS *customization_information,
LABEL_LIST *identifiers_target,
OUTPUT_UNIT_LIST *output_units);
+void units_file_directions (OUTPUT_UNIT_LIST *output_units);
+
#endif
diff --git a/tp/Texinfo/XS/main/tree_types.h b/tp/Texinfo/XS/main/tree_types.h
index 160321c554..e61809ae62 100644
--- a/tp/Texinfo/XS/main/tree_types.h
+++ b/tp/Texinfo/XS/main/tree_types.h
@@ -94,15 +94,24 @@ enum output_unit_type {
rud_type(NodePrev) \
rud_type(NodeUp)
-enum relative_unit_direction {
+/* relative output unit file directions */
+#define RUD_FILE_DIRECTIONS_TYPES \
+ rud_type(PrevFile) \
+ rud_type(NextFile)
+
+enum relative_unit_direction_type {
#define rud_type(name) RUD_type_## name,
RUD_DIRECTIONS_TYPES_LIST
+ RUD_FILE_DIRECTIONS_TYPES
#undef rud_type
#define rud_type(name) RUD_type_FirstInFile## name,
RUD_DIRECTIONS_TYPES_LIST
#undef rud_type
};
+/* in output_units.c */
+extern char *relative_unit_direction_name[];
+
typedef struct KEY_PAIR {
char *key;
enum extra_type type;
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/utils.h
index 085bf38807..106afcbedb 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/utils.h
@@ -273,6 +273,8 @@ typedef struct FILE_NAME_PATH_COUNTER {
char *filename;
char *filepath;
int counter;
+ int elements_in_file_count; /* only used in HTML, corresponds to
+ 'elements_in_file_count' */
} FILE_NAME_PATH_COUNTER;
typedef struct FILE_NAME_PATH_COUNTER_LIST {