[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Sun, 12 Nov 2023 16:03:39 -0500 (EST) |
branch: master
commit a43aacc7cabb241868744aa7e3e55cda811517ed
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Nov 12 22:03:30 2023 +0100
Separate types for list of floats and list of listoffloats
* tp/Texinfo/XS/main/build_perl_info.c (build_document),
tp/Texinfo/XS/main/converter_types.h (DOCUMENT),
tp/Texinfo/XS/main/document.c
(destroy_document_information_except_tree),
tp/Texinfo/XS/main/floats.c (add_to_float_record_list)
(add_to_listoffloats_list, find_float_type)
(float_list_to_listoffloats_list, destroy_listoffloats_list),
tp/Texinfo/XS/main/tree_types.h (LISTOFFLOATS_TYPE)
(LISTOFFLOATS_TYPE_LIST, FLOAT_RECORD_LIST),
tp/Texinfo/XS/parsetexi/parser.c (store_document),
tp/Texinfo/XS/structuring_transfo/structuring.c (number_floats):
add new types for listoffloats lists LISTOFFLOATS_TYPE_LIST instead of
using the same as for floats lists. Rename a field of floats lists
structure. Add add_to_listoffloats_list as a distinct function to add
to LISTOFFLOATS_TYPE_LIST. Update DOCUMENT and functions to use the
relevant types.
* tp/Texinfo/XS/parsetexi/end_line.c (end_line_starting_block): no
initialization of float_type, it is not used and is confusing.
---
ChangeLog | 24 +++++++++
tp/Texinfo/XS/main/build_perl_info.c | 2 +-
tp/Texinfo/XS/main/converter_types.h | 2 +-
tp/Texinfo/XS/main/document.c | 2 +-
tp/Texinfo/XS/main/floats.c | 71 +++++++++++++++----------
tp/Texinfo/XS/main/floats.h | 5 +-
tp/Texinfo/XS/main/tree_types.h | 13 ++++-
tp/Texinfo/XS/parsetexi/end_line.c | 2 +-
tp/Texinfo/XS/parsetexi/parser.c | 4 +-
tp/Texinfo/XS/structuring_transfo/structuring.c | 8 +--
10 files changed, 93 insertions(+), 40 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 2d2ed5be55..26500e21e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2023-11-12 Patrice Dumas <pertusus@free.fr>
+
+ Separate types for list of floats and list of listoffloats
+
+ * tp/Texinfo/XS/main/build_perl_info.c (build_document),
+ tp/Texinfo/XS/main/converter_types.h (DOCUMENT),
+ tp/Texinfo/XS/main/document.c
+ (destroy_document_information_except_tree),
+ tp/Texinfo/XS/main/floats.c (add_to_float_record_list)
+ (add_to_listoffloats_list, find_float_type)
+ (float_list_to_listoffloats_list, destroy_listoffloats_list),
+ tp/Texinfo/XS/main/tree_types.h (LISTOFFLOATS_TYPE)
+ (LISTOFFLOATS_TYPE_LIST, FLOAT_RECORD_LIST),
+ tp/Texinfo/XS/parsetexi/parser.c (store_document),
+ tp/Texinfo/XS/structuring_transfo/structuring.c (number_floats):
+ add new types for listoffloats lists LISTOFFLOATS_TYPE_LIST instead of
+ using the same as for floats lists. Rename a field of floats lists
+ structure. Add add_to_listoffloats_list as a distinct function to add
+ to LISTOFFLOATS_TYPE_LIST. Update DOCUMENT and functions to use the
+ relevant types.
+
+ * tp/Texinfo/XS/parsetexi/end_line.c (end_line_starting_block): no
+ initialization of float_type, it is not used and is confusing.
+
2023-11-12 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/parsetexi/parser.h (parser_float_list),
diff --git a/tp/Texinfo/XS/main/build_perl_info.c
b/tp/Texinfo/XS/main/build_perl_info.c
index d3e8be3f45..7a7d3b2f3b 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -1176,7 +1176,7 @@ build_document (size_t document_descriptor, int no_store)
for example build_listoffloats_list that would create the
hv_listoffloats_list based on document->listoffloats. */
hv_listoffloats_list
- = build_float_types_list (document->floats->float_types,
+ = build_float_types_list (document->floats->list,
document->floats->number);
av_internal_xref = build_internal_xref_list (
diff --git a/tp/Texinfo/XS/main/converter_types.h
b/tp/Texinfo/XS/main/converter_types.h
index 3ef2e6ff12..147951724d 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -199,7 +199,7 @@ typedef struct DOCUMENT {
ELEMENT *tree;
INDEX **index_names;
FLOAT_RECORD_LIST *floats;
- FLOAT_RECORD_LIST *listoffloats;
+ LISTOFFLOATS_TYPE_LIST *listoffloats;
ELEMENT_LIST *internal_references;
LABEL_LIST *labels_list;
LABEL_LIST *identifiers_target;
diff --git a/tp/Texinfo/XS/main/document.c b/tp/Texinfo/XS/main/document.c
index 74aca3a651..99f188ae33 100644
--- a/tp/Texinfo/XS/main/document.c
+++ b/tp/Texinfo/XS/main/document.c
@@ -139,7 +139,7 @@ destroy_document_information_except_tree (DOCUMENT
*document)
free (document->global_commands);
free (document->internal_references->list);
free (document->internal_references);
- free (document->floats->float_types);
+ free (document->floats->list);
free (document->floats);
destroy_listoffloats_list (document->listoffloats);
free (document->labels_list->list);
diff --git a/tp/Texinfo/XS/main/floats.c b/tp/Texinfo/XS/main/floats.c
index cff889f3c3..168e20f822 100644
--- a/tp/Texinfo/XS/main/floats.c
+++ b/tp/Texinfo/XS/main/floats.c
@@ -1,5 +1,5 @@
/* Copyright 2010-2023 Free Software Foundation, Inc.
-
+
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
@@ -24,11 +24,11 @@
char *
parse_float_type (ELEMENT *current)
-{
+{
char *normalized;
if (current->args.number > 0)
normalized = convert_to_normalized (current->args.list[0]);
- else
+ else
normalized = strdup ("");
add_extra_string (current, "float_type", normalized);
return normalized;
@@ -40,33 +40,49 @@ add_to_float_record_list (FLOAT_RECORD_LIST *float_records,
char *type,
{
if (float_records->number == float_records->space)
{
- float_records->float_types
- = realloc (float_records->float_types,
+ float_records->list
+ = realloc (float_records->list,
(float_records->space += 5) * sizeof (FLOAT_RECORD));
}
- float_records->float_types[float_records->number].type = type;
- float_records->float_types[float_records->number].element = element;
+ /* string stored in element extra */
+ float_records->list[float_records->number].type = type;
+ float_records->list[float_records->number].element = element;
float_records->number++;
}
-FLOAT_RECORD *
-find_float_type (FLOAT_RECORD_LIST *float_records, char *float_type)
+void
+add_to_listoffloats_list (LISTOFFLOATS_TYPE_LIST *listoffloats_list, char
*type,
+ ELEMENT *element)
+{
+ if (listoffloats_list->number == listoffloats_list->space)
+ {
+ listoffloats_list->float_types
+ = realloc (listoffloats_list->float_types,
+ (listoffloats_list->space += 5) * sizeof
(LISTOFFLOATS_TYPE));
+ }
+ listoffloats_list->float_types[listoffloats_list->number].type = strdup
(type);
+ listoffloats_list->float_types[listoffloats_list->number].float_list =
element;
+ listoffloats_list->number++;
+}
+
+LISTOFFLOATS_TYPE *
+find_float_type (LISTOFFLOATS_TYPE_LIST *listoffloats_list, char *float_type)
{
size_t i;
- for (i = 0; i < float_records->number; i++)
+ for (i = 0; i < listoffloats_list->number; i++)
{
- FLOAT_RECORD *record = &float_records->float_types[i];
- if (!strcmp (record->type, float_type))
- return record;
+ LISTOFFLOATS_TYPE *listoffloats = &listoffloats_list->float_types[i];
+ if (!strcmp (listoffloats->type, float_type))
+ return listoffloats;
}
return 0;
}
-FLOAT_RECORD_LIST *
+LISTOFFLOATS_TYPE_LIST *
float_list_to_listoffloats_list (FLOAT_RECORD_LIST *floats_list)
{
- FLOAT_RECORD_LIST *result = malloc (sizeof (FLOAT_RECORD_LIST));
- memset (result, 0, sizeof (FLOAT_RECORD_LIST));
+ LISTOFFLOATS_TYPE_LIST *result = malloc (sizeof (LISTOFFLOATS_TYPE_LIST));
+ memset (result, 0, sizeof (LISTOFFLOATS_TYPE_LIST));
/* a zero floats_list is unusual, it cannot happen when a document
comes from parsing of Texinfo, but it may happen with a document
@@ -78,23 +94,23 @@ float_list_to_listoffloats_list (FLOAT_RECORD_LIST
*floats_list)
for (i = 0; i < floats_list->number; i++)
{
- FLOAT_RECORD *float_record = &floats_list->float_types[i];
+ FLOAT_RECORD *float_record = &floats_list->list[i];
char *float_type = float_record->type;
- ELEMENT *listoffloats_element;
+ ELEMENT *listoffloats_floats;
- FLOAT_RECORD *listoffloats_type_record = find_float_type (result,
- float_type);
+ LISTOFFLOATS_TYPE *listoffloats_type_record = find_float_type
(result,
+
float_type);
/* add a new container of floats by float_type */
if (!listoffloats_type_record)
{
- listoffloats_element = new_element (ET_NONE);
- add_to_float_record_list (result, strdup (float_type),
- listoffloats_element);
+ listoffloats_floats = new_element (ET_NONE);
+ add_to_listoffloats_list (result, float_type,
+ listoffloats_floats);
}
else
- listoffloats_element = listoffloats_type_record->element;
+ listoffloats_floats = listoffloats_type_record->float_list;
- add_to_contents_as_array (listoffloats_element,
+ add_to_contents_as_array (listoffloats_floats,
float_record->element);
}
}
@@ -102,15 +118,16 @@ float_list_to_listoffloats_list (FLOAT_RECORD_LIST
*floats_list)
}
void
-destroy_listoffloats_list (FLOAT_RECORD_LIST *listoffloats_list)
+destroy_listoffloats_list (LISTOFFLOATS_TYPE_LIST *listoffloats_list)
{
size_t i;
for (i = 0; i < listoffloats_list->number; i++)
{
free (listoffloats_list->float_types[i].type);
- destroy_element (listoffloats_list->float_types[i].element);
+ destroy_element (listoffloats_list->float_types[i].float_list);
}
free (listoffloats_list->float_types);
free (listoffloats_list);
}
+
diff --git a/tp/Texinfo/XS/main/floats.h b/tp/Texinfo/XS/main/floats.h
index 961e4f90f1..0b329bfadd 100644
--- a/tp/Texinfo/XS/main/floats.h
+++ b/tp/Texinfo/XS/main/floats.h
@@ -20,10 +20,11 @@
#include "tree_types.h"
char *parse_float_type (ELEMENT *current);
-FLOAT_RECORD_LIST *float_list_to_listoffloats_list (
+LISTOFFLOATS_TYPE_LIST *float_list_to_listoffloats_list (
FLOAT_RECORD_LIST *floats_list);
-void destroy_listoffloats_list (FLOAT_RECORD_LIST *listoffloats_list);
void add_to_float_record_list (FLOAT_RECORD_LIST *float_records,
char *type, ELEMENT *element);
+void destroy_listoffloats_list (LISTOFFLOATS_TYPE_LIST *listoffloats_list);
+
#endif
diff --git a/tp/Texinfo/XS/main/tree_types.h b/tp/Texinfo/XS/main/tree_types.h
index 9be477d138..1b06a8f731 100644
--- a/tp/Texinfo/XS/main/tree_types.h
+++ b/tp/Texinfo/XS/main/tree_types.h
@@ -264,6 +264,17 @@ typedef struct {
LABEL *list;
} LABEL_LIST;
+typedef struct {
+ char *type;
+ ELEMENT *float_list;
+} LISTOFFLOATS_TYPE;
+
+typedef struct {
+ size_t number;
+ size_t space;
+ LISTOFFLOATS_TYPE *float_types;
+} LISTOFFLOATS_TYPE_LIST;
+
typedef struct {
char *type;
ELEMENT *element;
@@ -272,7 +283,7 @@ typedef struct {
typedef struct {
size_t number;
size_t space;
- FLOAT_RECORD *float_types;
+ FLOAT_RECORD *list;
} FLOAT_RECORD_LIST;
typedef struct STRING_LIST {
diff --git a/tp/Texinfo/XS/parsetexi/end_line.c
b/tp/Texinfo/XS/parsetexi/end_line.c
index 1c7e17c290..14bcc99feb 100644
--- a/tp/Texinfo/XS/parsetexi/end_line.c
+++ b/tp/Texinfo/XS/parsetexi/end_line.c
@@ -836,7 +836,7 @@ end_line_starting_block (ELEMENT *current)
if (command == CM_float)
{
- char *float_type = "";
+ char *float_type;
ELEMENT *float_label_element = 0;
current->source_info = current_source_info;
if (current->args.number >= 2)
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index e7a1695daa..fe02e1c5bd 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -2510,10 +2510,10 @@ store_document (ELEMENT *root)
labels->space = labels_number;
floats = malloc (sizeof (FLOAT_RECORD_LIST));
- parser_float_list.float_types = realloc (parser_float_list.float_types,
+ parser_float_list.list = realloc (parser_float_list.list,
parser_float_list.number * sizeof (FLOAT_RECORD));
- floats->float_types = parser_float_list.float_types;
+ floats->list = parser_float_list.list;
floats->number = parser_float_list.number;
floats->space = parser_float_list.number;
diff --git a/tp/Texinfo/XS/structuring_transfo/structuring.c
b/tp/Texinfo/XS/structuring_transfo/structuring.c
index a718b2d231..1e3e050bd6 100644
--- a/tp/Texinfo/XS/structuring_transfo/structuring.c
+++ b/tp/Texinfo/XS/structuring_transfo/structuring.c
@@ -1575,7 +1575,7 @@ associate_internal_references (DOCUMENT *document)
void
number_floats (DOCUMENT *document)
{
- FLOAT_RECORD_LIST *listoffloats_list = document->listoffloats;
+ LISTOFFLOATS_TYPE_LIST *listoffloats_list = document->listoffloats;
size_t i;
if (!listoffloats_list)
@@ -1583,15 +1583,15 @@ number_floats (DOCUMENT *document)
for (i = 0; i < listoffloats_list->number; i++)
{
- FLOAT_RECORD *listoffloats = &listoffloats_list->float_types[i];
+ LISTOFFLOATS_TYPE *listoffloats = &listoffloats_list->float_types[i];
int float_index = 0;
int nr_in_chapter = 0;
ELEMENT *current_chapter = 0;
size_t j;
- for (j = 0; j < listoffloats->element->contents.number; j++)
+ for (j = 0; j < listoffloats->float_list->contents.number; j++)
{
static TEXT number;
- ELEMENT *float_elt = listoffloats->element->contents.list[j];
+ ELEMENT *float_elt = listoffloats->float_list->contents.list[j];
char *normalized = lookup_extra_string (float_elt, "normalized");
ELEMENT *up;