[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Sat, 24 Feb 2024 20:18:48 -0500 (EST) |
branch: master
commit 610d0e5677da882d1089c1243800232e7e9aee16
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Feb 25 02:18:43 2024 +0100
Add const. Replace some int by size_t.
---
ChangeLog | 4 +
tp/Texinfo/XS/convert/ConvertXS.xs | 4 +-
tp/Texinfo/XS/convert/convert_html.c | 103 +++++++++++----------
tp/Texinfo/XS/convert/convert_html.h | 5 +-
tp/Texinfo/XS/main/errors.c | 16 ++--
tp/Texinfo/XS/main/errors.h | 14 +--
tp/Texinfo/XS/main/manipulate_tree.c | 45 ++++-----
tp/Texinfo/XS/main/manipulate_tree.h | 8 +-
tp/Texinfo/XS/main/output_unit.c | 10 +-
tp/Texinfo/XS/main/output_unit.h | 10 +-
tp/Texinfo/XS/main/tree.c | 2 +-
tp/Texinfo/XS/main/tree.h | 2 +-
tp/Texinfo/XS/parsetexi/source_marks.c | 11 +--
tp/Texinfo/XS/structuring_transfo/structuring.c | 2 +-
tp/Texinfo/XS/structuring_transfo/structuring.h | 3 +-
.../XS/structuring_transfo/transformations.c | 52 ++++++-----
.../XS/structuring_transfo/transformations.h | 4 +-
17 files changed, 153 insertions(+), 142 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 6aed72a64e..ae191f6501 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2024-02-24 Patrice Dumas <pertusus@free.fr>
+
+ Add const. Replace some int by size_t.
+
2024-02-24 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/main/manipulate_tree.c (add_source_mark): correct used
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 5d373b626c..e3de677c83 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -980,7 +980,7 @@ html_command_contents_target (SV *converter_in, SV
*element_sv, cmdname)
char *cmdname = (char *)SvPVutf8_nolen($arg);
PREINIT:
CONVERTER *self;
- char *id = 0;
+ const char *id = 0;
const ELEMENT *element;
CODE:
element = element_converter_from_sv (converter_in, element_sv,
@@ -1031,7 +1031,7 @@ html_command_filename (SV *converter_in, SV *element_sv)
&self);
if (element)
{
- FILE_NUMBER_NAME *file_number_name
+ const FILE_NUMBER_NAME *file_number_name
= html_command_filename (self, element);
if (file_number_name)
{
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index d5aba515cf..638f9d8071 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -2867,7 +2867,7 @@ static const char *direction_type_translation_context[] =
"button label", "description", "string"
};
-char *
+const char *
direction_string (CONVERTER *self, int direction,
enum direction_string_type string_type,
enum direction_string_context context)
@@ -2973,7 +2973,7 @@ html_get_target (const CONVERTER *self, const ELEMENT
*element)
const char *
html_command_id (const CONVERTER *self, const ELEMENT *command)
{
- HTML_TARGET *target_info = html_get_target (self, command);
+ const HTML_TARGET *target_info = html_get_target (self, command);
if (target_info)
return target_info->target;
else
@@ -3339,7 +3339,7 @@ external_node_href (CONVERTER *self, const ELEMENT
*external_node,
return result.text;
}
-FILE_NUMBER_NAME *
+const FILE_NUMBER_NAME *
html_command_filename (CONVERTER *self, const ELEMENT *command)
{
HTML_TARGET *target_info;
@@ -3464,12 +3464,12 @@ html_internal_command_href (CONVERTER *self, const
ELEMENT *command,
const char *source_filename,
const char *specified_target)
{
- HTML_TARGET *target_info;
+ const HTML_TARGET *target_info;
TEXT href;
const char *filename_from;
const char *target = 0;
- FILE_NUMBER_NAME *target_filename;
- int target_filename_to_be_freed = 0;
+ const FILE_NUMBER_NAME *target_filename;
+ FILE_NUMBER_NAME *set_target_filename = 0;
if (source_filename)
filename_from = source_filename;
@@ -3506,13 +3506,13 @@ html_internal_command_href (CONVERTER *self, const
ELEMENT *command,
= retrieve_output_units (self->document_units_descriptor);
if (output_units->list[0]->unit_filename)
{ /* In that case use the first page. */
- target_filename = (FILE_NUMBER_NAME *)
+ set_target_filename = (FILE_NUMBER_NAME *)
malloc (sizeof (FILE_NUMBER_NAME));
- target_filename->filename = output_units->list[0]->unit_filename;
- target_filename->file_number
+ set_target_filename->filename = output_units->list[0]->unit_filename;
+ set_target_filename->file_number
= self->output_unit_file_indices[0] +1;
- target_filename_to_be_freed = 1;
}
+ target_filename = set_target_filename;
}
if (target_filename && target_filename->filename)
@@ -3527,7 +3527,7 @@ html_internal_command_href (CONVERTER *self, const
ELEMENT *command,
one element in file and there is a file in the href */
if (filename_from && command_root_element)
{
- ELEMENT *associated_section
+ const ELEMENT *associated_section
= lookup_extra_element (command_root_element,
"associated_section");
if (command_root_element == command
@@ -3553,8 +3553,8 @@ html_internal_command_href (CONVERTER *self, const
ELEMENT *command,
text_append (&href, target);
}
- if (target_filename_to_be_freed)
- free (target_filename);
+ if (set_target_filename)
+ free (set_target_filename);
if (href.end <= 0)
{
@@ -3576,7 +3576,7 @@ html_command_href (CONVERTER *self, const ELEMENT
*command,
const ELEMENT *source_command,
const char *specified_target)
{
- ELEMENT *manual_content = lookup_extra_element (command,
+ const ELEMENT *manual_content = lookup_extra_element (command,
"manual_content");
if (manual_content)
{
@@ -3587,11 +3587,11 @@ html_command_href (CONVERTER *self, const ELEMENT
*command,
specified_target);
}
-char *
+const char *
html_command_contents_target (CONVERTER *self, const ELEMENT *command,
enum command_id contents_or_shortcontents)
{
- HTML_TARGET *target_info;
+ const HTML_TARGET *target_info;
if (contents_or_shortcontents == CM_summarycontents)
contents_or_shortcontents = CM_shortcontents;
@@ -3646,13 +3646,13 @@ html_command_contents_href (CONVERTER *self, const
ELEMENT *command,
for (j = 0; self->command_special_variety_name_index[j].cmd; j++)
{
- COMMAND_ID_INDEX cmd_variety_index
+ const COMMAND_ID_INDEX cmd_variety_index
= self->command_special_variety_name_index[j];
if (cmd_variety_index.cmd == contents_or_shortcontents)
{
TEXT href;
- FILE_NUMBER_NAME *target_filename = 0;
- char *special_unit_variety
+ const FILE_NUMBER_NAME *target_filename = 0;
+ const char *special_unit_variety
= self->special_unit_varieties.list[cmd_variety_index.index];
int special_unit_direction_index
= html_special_unit_variety_direction_index (self,
@@ -3819,7 +3819,7 @@ html_internal_command_tree (CONVERTER *self, const
ELEMENT *command,
}
else
{
- char *section_number
+ const char *section_number
= lookup_extra_string (command, "section_number");
if (section_number && !self->conf->NUMBER_SECTIONS.integer == 0)
{
@@ -5153,15 +5153,15 @@ html_prepare_output_units_global_targets (CONVERTER
*self,
for (i = 0; i < 2; i++)
{
int special_units_descriptor = special_output_units_lists[i];
- OUTPUT_UNIT_LIST *units_list
- = retrieve_output_units (special_units_descriptor);
+ const OUTPUT_UNIT_LIST *units_list
+ = retrieve_output_units (special_units_descriptor);
if (units_list && units_list->number)
{
int j;
for (j = 0; j < units_list->number; j++)
{
const OUTPUT_UNIT *special_unit = units_list->list[j];
- char *special_unit_variety = special_unit->special_unit_variety;
+ const char *special_unit_variety =
special_unit->special_unit_variety;
int special_unit_direction_index
= html_special_unit_variety_direction_index (self,
special_unit_variety);
@@ -5549,10 +5549,10 @@ html_set_pages_files (CONVERTER *self, const
OUTPUT_UNIT_LIST *output_units,
for (i = 0; i < output_units->number; i++)
{
size_t output_unit_file_idx = 0;
- FILE_NAME_PATH_COUNTER *output_unit_file;
+ const FILE_NAME_PATH_COUNTER *output_unit_file;
OUTPUT_UNIT *output_unit = output_units->list[i];
char *filename = unit_file_name_paths[i];
- FILE_SOURCE_INFO *file_source_info
+ const FILE_SOURCE_INFO *file_source_info
= find_file_source_info (files_source_info, filename);
const char *filepath = file_source_info->path;
@@ -5614,7 +5614,7 @@ html_set_pages_files (CONVERTER *self, const
OUTPUT_UNIT_LIST *output_units,
for (i = 0; i < special_units->number; i++)
{
size_t special_unit_file_idx = 0;
- FILE_NAME_PATH_COUNTER *special_unit_file;
+ const FILE_NAME_PATH_COUNTER *special_unit_file;
OUTPUT_UNIT *special_unit = special_units->list[i];
const ELEMENT *unit_command = special_unit->unit_command;
const HTML_TARGET *special_unit_target
@@ -5683,7 +5683,7 @@ html_set_pages_files (CONVERTER *self, const
OUTPUT_UNIT_LIST *output_units,
= find_element_target (self->html_targets, unit_command);
if (!element_target->special_unit_filename)
- {
+ {/* set the file if not already set */
char *unit_filename = 0;
if (associated_output_unit)
unit_filename = strdup (associated_output_unit->unit_filename);
@@ -5859,7 +5859,7 @@ convert_text (CONVERTER *self, const enum element_type
type,
contents_used_to_be_freed = 1;
}
else
- /* cast needed to avoid a compiler warning */
+ /* cast needed to drop const to avoid a compiler warning */
content_used = (char *) content;
if (html_in_preformatted_context (self))
@@ -5907,7 +5907,7 @@ void
format_separate_anchor (CONVERTER *self, const char *id,
const char *class, TEXT *result)
{
- FORMATTING_REFERENCE *formatting_reference
+ const FORMATTING_REFERENCE *formatting_reference
= &self->current_formatting_references[FR_format_separate_anchor];
if (formatting_reference->status == FRS_status_default_set)
{
@@ -5928,7 +5928,7 @@ direction_href_attributes (CONVERTER *self, int
direction, TEXT *result)
{
if (self->conf->USE_ACCESSKEY.integer > 0)
{
- char *accesskey
+ const char *accesskey
= direction_string (self, direction, TDS_type_accesskey,
TDS_context_string);
if (accesskey && strlen (accesskey))
@@ -5937,7 +5937,7 @@ direction_href_attributes (CONVERTER *self, int
direction, TEXT *result)
if (self->conf->USE_REL_REV.integer)
{
- char *button_rel
+ const char *button_rel
= direction_string (self, direction, TDS_type_rel,
TDS_context_string);
if (button_rel && strlen (button_rel))
@@ -6068,7 +6068,7 @@ html_default_format_contents (CONVERTER *self, const enum
command_id cmd,
if (self->document->sections_list
&& self->document->sections_list->number >= 0)
{
- ELEMENT *first = self->document->sections_list->list[0];
+ const ELEMENT *first = self->document->sections_list->list[0];
section_root = lookup_extra_element (first, "sectioning_root");
}
else
@@ -6081,7 +6081,7 @@ html_default_format_contents (CONVERTER *self, const enum
command_id cmd,
for (i = 0; i < root_children->number; i++)
{
- ELEMENT *top_section = root_children->list[i];
+ const ELEMENT *top_section = root_children->list[i];
int section_level = lookup_extra_integer (top_section, "section_level",
&status);
if (section_level < min_root_level)
@@ -6137,8 +6137,8 @@ html_default_format_contents (CONVERTER *self, const enum
command_id cmd,
for (i = 0; i < root_children->number; i++)
{
- ELEMENT *top_section = root_children->list[i];
- ELEMENT *section = top_section;
+ const ELEMENT *top_section = root_children->list[i];
+ const ELEMENT *section = top_section;
while (section)
{
int section_level = lookup_extra_integer (section, "section_level",
@@ -6149,7 +6149,7 @@ html_default_format_contents (CONVERTER *self, const enum
command_id cmd,
{
char *text;
char *href;
- char *toc_id = html_command_contents_target (self, section, cmd);
+ const char *toc_id = html_command_contents_target (self,
section, cmd);
text = html_command_text (self, section, 0);
@@ -7126,7 +7126,7 @@ get_links (CONVERTER* self, const char *filename,
char *link_string
= from_element_direction (self, link->direction, HTT_string,
output_unit, 0, 0);
- char *button_rel
+ const char *button_rel
= direction_string (self, link->direction, TDS_type_rel,
TDS_context_string);
text_printf (result, "<link href=\"%s\"", link_href);
@@ -7499,7 +7499,7 @@ html_default_format_button (CONVERTER *self,
&& strlen
(self->conf->ACTIVE_ICONS.icons->list[button->direction]))
{
- char *button_name_string = direction_string (self,
+ const char *button_name_string = direction_string (self,
button->direction, TDS_type_button,
TDS_context_string);
formatted_button->active
@@ -7525,7 +7525,8 @@ html_default_format_button (CONVERTER *self,
/* button is active */
TEXT active_text;
char *active_icon = 0;
- char *description = direction_string (self, button->direction,
+ const char *description
+ = direction_string (self, button->direction,
TDS_type_description, TDS_context_string);
if (self->conf->ICONS.integer > 0
@@ -7546,15 +7547,17 @@ html_default_format_button (CONVERTER *self,
text_printf (&active_text, " title=\"%s\"", description);
if (self->conf->USE_ACCESSKEY.integer > 0)
{
- char *accesskey = direction_string (self, button->direction,
- TDS_type_accesskey, TDS_context_string);
+ const char *accesskey
+ = direction_string (self, button->direction,
+ TDS_type_accesskey,
TDS_context_string);
if (accesskey && strlen (accesskey))
text_printf (&active_text, " accesskey=\"%s\"", accesskey);
}
if (self->conf->USE_REL_REV.integer > 0)
{
- char *button_rel = direction_string (self, button->direction,
- TDS_type_rel, TDS_context_string);
+ const char *button_rel
+ = direction_string (self, button->direction,
+ TDS_type_rel, TDS_context_string);
if (button_rel && strlen (button_rel))
text_printf (&active_text, " rel=\"%s\"", button_rel);
}
@@ -7610,9 +7613,9 @@ html_default_format_button (CONVERTER *self,
}
if (passive_icon)
{
- char *button_name_string = direction_string (self,
- button->direction, TDS_type_button,
- TDS_context_string);
+ const char *button_name_string
+ = direction_string (self, button->direction,
+ TDS_type_button, TDS_context_string);
char *icon_name = from_element_direction (self,
button->direction,
HTT_string,
@@ -7627,8 +7630,9 @@ html_default_format_button (CONVERTER *self,
}
else
{
- const char *button_text_string = direction_string (self,
- button->direction, TDS_type_text, 0);
+ const char *button_text_string
+ = direction_string (self, button->direction,
+ TDS_type_text, 0);
text_append_n (&passive_text, "[", 1);
if (button_text_string)
text_append (&passive_text, button_text_string);
@@ -15581,7 +15585,8 @@ default_format_special_body_about (CONVERTER *self,
&& self->conf->ACTIVE_ICONS.icons->list[direction]
&& strlen (self->conf->ACTIVE_ICONS.icons->list[direction]))
{
- char *button_name_string = direction_string (self, direction,
+ const char *button_name_string
+ = direction_string (self, direction,
TDS_type_button, TDS_context_string);
char *button = format_button_icon_img (self, button_name_string,
self->conf->ACTIVE_ICONS.icons->list[direction], 0);
diff --git a/tp/Texinfo/XS/convert/convert_html.h
b/tp/Texinfo/XS/convert/convert_html.h
index 315a7fb594..c02694b86d 100644
--- a/tp/Texinfo/XS/convert/convert_html.h
+++ b/tp/Texinfo/XS/convert/convert_html.h
@@ -95,11 +95,12 @@ int html_special_unit_variety_direction_index (CONVERTER
*self,
HTML_TARGET *html_get_target (const CONVERTER *self, const ELEMENT *element);
const char *html_command_id (const CONVERTER *self, const ELEMENT *command);
-char *html_command_contents_target (CONVERTER *self, const ELEMENT *command,
+const char *html_command_contents_target (CONVERTER *self,
+ const ELEMENT *command,
enum command_id contents_or_shortcontents);
const char *html_footnote_location_target (const CONVERTER *self,
const ELEMENT *command);
-FILE_NUMBER_NAME *html_command_filename (CONVERTER *self,
+const FILE_NUMBER_NAME *html_command_filename (CONVERTER *self,
const ELEMENT *command);
const ELEMENT *html_command_root_element_command (CONVERTER *self,
const ELEMENT *command);
diff --git a/tp/Texinfo/XS/main/errors.c b/tp/Texinfo/XS/main/errors.c
index e534b96980..241cfa20fc 100644
--- a/tp/Texinfo/XS/main/errors.c
+++ b/tp/Texinfo/XS/main/errors.c
@@ -149,7 +149,7 @@ vmessage_list_line_error (ERROR_MESSAGE_LIST
*error_messages,
void
message_list_document_formatted_message (ERROR_MESSAGE_LIST *error_messages,
- OPTIONS *conf,
+ const OPTIONS *conf,
enum error_type type, int
continuation,
char *message)
{
@@ -214,7 +214,7 @@ message_list_document_formatted_message (ERROR_MESSAGE_LIST
*error_messages,
static void
message_list_document_error_internal (ERROR_MESSAGE_LIST *error_messages,
- OPTIONS *conf,
+ const OPTIONS *conf,
enum error_type type, int continuation,
const char *format, va_list v)
{
@@ -233,7 +233,7 @@ message_list_document_error_internal (ERROR_MESSAGE_LIST
*error_messages,
void
message_list_line_error_ext (ERROR_MESSAGE_LIST *error_messages,
- OPTIONS *conf,
+ const OPTIONS *conf,
enum error_type type, int continuation,
const SOURCE_INFO *cmd_source_info, const char *format, ...)
{
@@ -247,7 +247,7 @@ message_list_line_error_ext (ERROR_MESSAGE_LIST
*error_messages,
void
message_list_command_warn (ERROR_MESSAGE_LIST *error_messages,
- OPTIONS *conf,
+ const OPTIONS *conf,
const ELEMENT *e, const char *format, ...)
{
va_list v;
@@ -262,7 +262,7 @@ message_list_command_warn (ERROR_MESSAGE_LIST
*error_messages,
function already has a variable argument */
void
vmessage_list_command_warn (ERROR_MESSAGE_LIST *error_messages,
- OPTIONS *conf,
+ const OPTIONS *conf,
const ELEMENT *e, const char *format, va_list v)
{
vmessage_list_line_error (error_messages, MSG_warning, 0,
@@ -272,7 +272,7 @@ vmessage_list_command_warn (ERROR_MESSAGE_LIST
*error_messages,
void
message_list_command_error (ERROR_MESSAGE_LIST *error_messages,
- OPTIONS *conf,
+ const OPTIONS *conf,
const ELEMENT *e, const char *format, ...)
{
va_list v;
@@ -285,7 +285,7 @@ message_list_command_error (ERROR_MESSAGE_LIST
*error_messages,
void
message_list_document_error (ERROR_MESSAGE_LIST *error_messages,
- OPTIONS *conf, int continuation,
+ const OPTIONS *conf, int continuation,
const char *format, ...)
{
va_list v;
@@ -299,7 +299,7 @@ message_list_document_error (ERROR_MESSAGE_LIST
*error_messages,
void
message_list_document_warn (ERROR_MESSAGE_LIST *error_messages,
- OPTIONS *conf, int continuation,
+ const OPTIONS *conf, int continuation,
const char *format, ...)
{
va_list v;
diff --git a/tp/Texinfo/XS/main/errors.h b/tp/Texinfo/XS/main/errors.h
index c8922ec4eb..5c5411ae21 100644
--- a/tp/Texinfo/XS/main/errors.h
+++ b/tp/Texinfo/XS/main/errors.h
@@ -20,28 +20,28 @@ void vmessage_list_line_error (ERROR_MESSAGE_LIST
*error_messages,
const SOURCE_INFO *cmd_source_info,
const char *format, va_list v);
void message_list_line_error_ext (ERROR_MESSAGE_LIST *error_messages,
- OPTIONS *conf,
+ const OPTIONS *conf,
enum error_type type, int continuation,
const SOURCE_INFO *cmd_source_info, const char *format, ...);
void message_list_command_error (ERROR_MESSAGE_LIST *error_messages,
- OPTIONS *conf,
+ const OPTIONS *conf,
const ELEMENT *e, const char *format, ...);
void message_list_command_warn (ERROR_MESSAGE_LIST *error_messages,
- OPTIONS *conf,
+ const OPTIONS *conf,
const ELEMENT *e, const char *format, ...);
void message_list_document_formatted_message (ERROR_MESSAGE_LIST
*error_messages,
- OPTIONS *conf,
+ const OPTIONS *conf,
enum error_type type, int
continuation,
char *message);
void message_list_document_error (ERROR_MESSAGE_LIST *error_messages,
- OPTIONS *conf, int continuation,
+ const OPTIONS *conf, int continuation,
const char *format, ...);
void message_list_document_warn (ERROR_MESSAGE_LIST *error_messages,
- OPTIONS *conf, int continuation,
+ const OPTIONS *conf, int continuation,
const char *format, ...);
void vmessage_list_command_warn (ERROR_MESSAGE_LIST *error_messages,
- OPTIONS *conf,
+ const OPTIONS *conf,
const ELEMENT *e, const char *format, va_list v);
#endif
diff --git a/tp/Texinfo/XS/main/manipulate_tree.c
b/tp/Texinfo/XS/main/manipulate_tree.c
index e2744d7e9e..bb9ce64924 100644
--- a/tp/Texinfo/XS/main/manipulate_tree.c
+++ b/tp/Texinfo/XS/main/manipulate_tree.c
@@ -393,7 +393,7 @@ copy_contents (ELEMENT *element, enum element_type type)
void
add_source_mark (SOURCE_MARK *source_mark, ELEMENT *e)
{
- SOURCE_MARK_LIST *s_mark_list = &(e->source_mark_list);
+ SOURCE_MARK_LIST *s_mark_list = &e->source_mark_list;
if (s_mark_list->number == s_mark_list->space)
{
s_mark_list->space++;
@@ -407,8 +407,8 @@ add_source_mark (SOURCE_MARK *source_mark, ELEMENT *e)
s_mark_list->number++;
}
-SOURCE_MARK *
-remove_from_source_mark_list (SOURCE_MARK_LIST *list, int where)
+static SOURCE_MARK *
+remove_from_source_mark_list (SOURCE_MARK_LIST *list, size_t where)
{
SOURCE_MARK *removed;
@@ -434,10 +434,10 @@ size_t
relocate_source_marks (SOURCE_MARK_LIST *source_mark_list, ELEMENT *new_e,
size_t begin_position, size_t len)
{
- int i = 0;
- int j;
- int list_number = source_mark_list->number;
- int *indices_to_remove;
+ size_t i = 0;
+ size_t j;
+ size_t list_number = source_mark_list->number;
+ size_t *indices_to_remove;
size_t end_position;
if (list_number == 0)
@@ -445,8 +445,8 @@ relocate_source_marks (SOURCE_MARK_LIST *source_mark_list,
ELEMENT *new_e,
end_position = begin_position + len;
- indices_to_remove = malloc (sizeof (int) * list_number);
- memset (indices_to_remove, 0, sizeof (int) * list_number);
+ indices_to_remove = malloc (sizeof (size_t) * list_number);
+ memset (indices_to_remove, 0, sizeof (size_t) * list_number);
while (i < list_number)
{
@@ -484,10 +484,12 @@ relocate_source_marks (SOURCE_MARK_LIST
*source_mark_list, ELEMENT *new_e,
}
/* i is past the last index with a potential source mark to remove
(to be ready for the next pass in the loop above). So remove one */
- for (j = i - 1; j >= 0; j--)
+ for (j = i - 1; ; j--)
{
if (indices_to_remove[j] == 1)
remove_from_source_mark_list (source_mark_list, j);
+ if (j == 0)
+ break;
}
free (indices_to_remove);
@@ -847,7 +849,8 @@ modify_tree (ELEMENT *tree,
}
ELEMENT *
-new_asis_command_with_text (char *text, ELEMENT *parent, enum element_type
type)
+new_asis_command_with_text (const char *text, ELEMENT *parent,
+ enum element_type type)
{
ELEMENT *new_command = new_element (ET_NONE);
ELEMENT *brace_command_arg = new_element (ET_brace_command_arg);
@@ -861,7 +864,7 @@ new_asis_command_with_text (char *text, ELEMENT *parent,
enum element_type type)
}
ELEMENT_LIST *
-protect_text (ELEMENT *current, char *to_protect)
+protect_text (ELEMENT *current, const char *to_protect)
{
if (current->text.end > 0 && !(current->type == ET_raw
|| current->type == ET_rawline_arg)
@@ -872,7 +875,7 @@ protect_text (ELEMENT *current, char *to_protect)
/* count UTF-8 encoded Unicode characters for source marks locations */
uint8_t *u8_text = 0;
size_t current_position;
- uint8_t *u8_p = 0;
+ const uint8_t *u8_p = 0;
size_t u8_len;
if (current->source_mark_list.number)
@@ -885,7 +888,7 @@ protect_text (ELEMENT *current, char *to_protect)
while (*p)
{
- int leading_nr = strcspn (p, to_protect);
+ size_t leading_nr = strcspn (p, to_protect);
ELEMENT *text_elt = new_element (current->type);
text_elt->parent = current->parent;
if (leading_nr)
@@ -904,7 +907,7 @@ protect_text (ELEMENT *current, char *to_protect)
u8_p += u8_len;
current_position
- = relocate_source_marks (&(current->source_mark_list),
+ = relocate_source_marks (¤t->source_mark_list,
text_elt,
current_position, u8_len);
}
@@ -916,10 +919,10 @@ protect_text (ELEMENT *current, char *to_protect)
if (*p)
{
- int to_protect_nr = strspn (p, to_protect);
+ size_t to_protect_nr = strspn (p, to_protect);
if (!strcmp (to_protect, ","))
{
- int i;
+ size_t i;
for (i = 0; i < to_protect_nr; i++)
{
ELEMENT *comma = new_element (ET_NONE);
@@ -935,7 +938,7 @@ protect_text (ELEMENT *current, char *to_protect)
u8_p += u8_len;
current_position
- = relocate_source_marks
(&(current->source_mark_list),
+ = relocate_source_marks (¤t->source_mark_list,
comma,
current_position, u8_len);
}
@@ -956,7 +959,7 @@ protect_text (ELEMENT *current, char *to_protect)
u8_p += u8_len;
current_position
- = relocate_source_marks (&(current->source_mark_list),
+ = relocate_source_marks (¤t->source_mark_list,
new_command->args.list[0]->contents.list[0],
current_position, u8_len);
}
@@ -975,13 +978,13 @@ protect_text (ELEMENT *current, char *to_protect)
-char *
+const char *
normalized_menu_entry_internal_node (const ELEMENT *entry)
{
int i;
for (i = 0; i < entry->contents.number; i++)
{
- ELEMENT *content = entry->contents.list[i];
+ const ELEMENT *content = entry->contents.list[i];
if (content->type == ET_menu_entry_node)
{
if (!lookup_extra_element (content, "manual_content"))
diff --git a/tp/Texinfo/XS/main/manipulate_tree.h
b/tp/Texinfo/XS/main/manipulate_tree.h
index e8b3f95c33..b24aa1c0fe 100644
--- a/tp/Texinfo/XS/main/manipulate_tree.h
+++ b/tp/Texinfo/XS/main/manipulate_tree.h
@@ -37,17 +37,17 @@ NODE_SPEC_EXTRA *parse_node_manual (ELEMENT *node, int
modify_node);
ELEMENT *modify_tree (ELEMENT *tree,
- ELEMENT_LIST *(*operation)(const char *type, ELEMENT *element, void*
argument),
+ ELEMENT_LIST *(*operation)(const char *type, ELEMENT *element, void
*argument),
void *argument);
-ELEMENT *new_asis_command_with_text (char *text, ELEMENT *parent,
+ELEMENT *new_asis_command_with_text (const char *text, ELEMENT *parent,
enum element_type type);
-ELEMENT_LIST *protect_text (ELEMENT *current, char *to_protect);
+ELEMENT_LIST *protect_text (ELEMENT *current, const char *to_protect);
-char *normalized_menu_entry_internal_node (const ELEMENT *entry);
+const char *normalized_menu_entry_internal_node (const ELEMENT *entry);
ELEMENT *normalized_entry_associated_internal_node (const ELEMENT *entry,
const LABEL_LIST
*identifiers_target);
ELEMENT *first_menu_node (ELEMENT *node, LABEL_LIST *identifiers_target);
diff --git a/tp/Texinfo/XS/main/output_unit.c b/tp/Texinfo/XS/main/output_unit.c
index a3e6d42380..3678596ec0 100644
--- a/tp/Texinfo/XS/main/output_unit.c
+++ b/tp/Texinfo/XS/main/output_unit.c
@@ -35,7 +35,7 @@
#include "convert_to_texinfo.h"
#include "output_unit.h"
-char *relative_unit_direction_name[] = {
+const char *relative_unit_direction_name[] = {
#define rud_type(name) #name,
RUD_DIRECTIONS_TYPES_LIST
RUD_FILE_DIRECTIONS_TYPES
@@ -135,7 +135,7 @@ add_to_output_unit_list (OUTPUT_UNIT_LIST *list,
OUTPUT_UNIT *output_unit)
/* in addition to splitting, register the output_units list */
int
-split_by_node (ELEMENT *root)
+split_by_node (const ELEMENT *root)
{
int output_units_descriptor = new_output_units_descriptor ();
OUTPUT_UNIT_LIST *output_units
@@ -204,7 +204,7 @@ split_by_node (ELEMENT *root)
/* in addition to splitting, register the output_units list */
int
-split_by_section (ELEMENT *root)
+split_by_section (const ELEMENT *root)
{
int output_units_descriptor = new_output_units_descriptor ();
OUTPUT_UNIT_LIST *output_units
@@ -263,7 +263,7 @@ split_by_section (ELEMENT *root)
}
int
-unsplit (ELEMENT *root)
+unsplit (const ELEMENT *root)
{
int unsplit_needed = 0;
int i;
@@ -346,7 +346,7 @@ static LEVEL_SPLIT_STRING split_level_table[3] = {
that is the first in the output page.
*/
void
-split_pages (OUTPUT_UNIT_LIST *output_units, char *split)
+split_pages (OUTPUT_UNIT_LIST *output_units, const char *split)
{
int split_level = -2;
int i;
diff --git a/tp/Texinfo/XS/main/output_unit.h b/tp/Texinfo/XS/main/output_unit.h
index 1ba8f1542b..d0f76a7d09 100644
--- a/tp/Texinfo/XS/main/output_unit.h
+++ b/tp/Texinfo/XS/main/output_unit.h
@@ -6,15 +6,15 @@
#include "tree_types.h"
-extern char *relative_unit_direction_name[];
+extern const char *relative_unit_direction_name[];
OUTPUT_UNIT_LIST *retrieve_output_units (int output_units_descriptor);
size_t new_output_units_descriptor (void);
-int split_by_node (ELEMENT *root);
-int split_by_section (ELEMENT *root);
-int unsplit (ELEMENT *root);
-void split_pages (OUTPUT_UNIT_LIST *output_units, char *split);
+int split_by_node (const ELEMENT *root);
+int split_by_section (const ELEMENT *root);
+int unsplit (const ELEMENT *root);
+void split_pages (OUTPUT_UNIT_LIST *output_units, const char *split);
OUTPUT_UNIT *new_output_unit (enum output_unit_type unit_type);
void add_to_output_unit_list (OUTPUT_UNIT_LIST *list,
diff --git a/tp/Texinfo/XS/main/tree.c b/tp/Texinfo/XS/main/tree.c
index f105a886aa..5fd699d70b 100644
--- a/tp/Texinfo/XS/main/tree.c
+++ b/tp/Texinfo/XS/main/tree.c
@@ -424,7 +424,7 @@ remove_from_args (ELEMENT *parent, int where)
}
ELEMENT *
-remove_element_from_list (ELEMENT_LIST *list, ELEMENT *e)
+remove_element_from_list (ELEMENT_LIST *list, const ELEMENT *e)
{
int i;
int index = -1;
diff --git a/tp/Texinfo/XS/main/tree.h b/tp/Texinfo/XS/main/tree.h
index ac04f2b42f..b8419ab6dd 100644
--- a/tp/Texinfo/XS/main/tree.h
+++ b/tp/Texinfo/XS/main/tree.h
@@ -16,7 +16,7 @@ void add_to_element_args (ELEMENT *parent, ELEMENT *e);
void insert_into_element_list (ELEMENT_LIST *list, ELEMENT *e, int where);
void insert_into_contents (ELEMENT *parent, ELEMENT *e, int where);
void insert_into_args (ELEMENT *parent, ELEMENT *e, int where);
-ELEMENT *remove_element_from_list (ELEMENT_LIST *list, ELEMENT *e);
+ELEMENT *remove_element_from_list (ELEMENT_LIST *list, const ELEMENT *e);
void add_element_if_not_in_list (ELEMENT_LIST *list, ELEMENT *e);
void insert_list_slice_into_list (ELEMENT_LIST *to, int where,
const ELEMENT_LIST *from, int start, int
end);
diff --git a/tp/Texinfo/XS/parsetexi/source_marks.c
b/tp/Texinfo/XS/parsetexi/source_marks.c
index 32b2cf7c51..e5c13c86f5 100644
--- a/tp/Texinfo/XS/parsetexi/source_marks.c
+++ b/tp/Texinfo/XS/parsetexi/source_marks.c
@@ -31,10 +31,7 @@ static int name##_counter = 0;
SM_TYPES_LIST
#undef sm_type
-/* it isn't much readable to use here the SM_TYPES_LIST macro defined
- in a header file, but the table should be allocated in files using
- it only if static (or in only one file if extern) */
-static char *source_marks_names[SM_type_expanded_conditional_command + 1] =
+static const char *source_marks_names[SM_type_expanded_conditional_command +
1] =
{
#define sm_type(name) #name,
SM_TYPES_LIST
@@ -61,7 +58,7 @@ place_source_mark (ELEMENT *e, SOURCE_MARK *source_mark)
{
ELEMENT *mark_element;
/* for debug string */
- char *add_element_string = "no-add";
+ const char *add_element_string = "no-add";
source_mark->position = 0;
if (e->contents.number > 0)
@@ -124,10 +121,10 @@ register_source_mark (ELEMENT *e, SOURCE_MARK
*source_mark)
void
transfer_source_marks (ELEMENT *from_e, ELEMENT *e)
{
- SOURCE_MARK_LIST *source_mark_list = &(from_e->source_mark_list);
+ SOURCE_MARK_LIST *source_mark_list = &from_e->source_mark_list;
if (source_mark_list->number)
{
- int i;
+ size_t i;
for (i = 0; i < source_mark_list->number; i++)
{
add_source_mark (source_mark_list->list[i], e);
diff --git a/tp/Texinfo/XS/structuring_transfo/structuring.c
b/tp/Texinfo/XS/structuring_transfo/structuring.c
index adeaa555f8..8f662284c5 100644
--- a/tp/Texinfo/XS/structuring_transfo/structuring.c
+++ b/tp/Texinfo/XS/structuring_transfo/structuring.c
@@ -1657,7 +1657,7 @@ number_floats (DOCUMENT *document)
to NODE.
if USE_SECTIONS is set, use the section name as menu entry name. */
ELEMENT *
-new_node_menu_entry (ELEMENT *node, int use_sections)
+new_node_menu_entry (const ELEMENT *node, int use_sections)
{
ELEMENT *node_name_element = 0;
ELEMENT *menu_entry_name;
diff --git a/tp/Texinfo/XS/structuring_transfo/structuring.h
b/tp/Texinfo/XS/structuring_transfo/structuring.h
index 6528509951..a7e02b04a9 100644
--- a/tp/Texinfo/XS/structuring_transfo/structuring.h
+++ b/tp/Texinfo/XS/structuring_transfo/structuring.h
@@ -10,14 +10,13 @@ void associate_internal_references (DOCUMENT *document);
ELEMENT_LIST *sectioning_structure (DOCUMENT *document);
ELEMENT_LIST *nodes_tree (DOCUMENT *document);
ELEMENT_LIST *get_node_node_childs_from_sectioning (const ELEMENT *node);
-char *normalized_menu_entry_internal_node (const ELEMENT *entry);
void warn_non_empty_parts (DOCUMENT *document);
void set_menus_node_directions (DOCUMENT *document);
void complete_node_tree_with_menus (DOCUMENT *document);
void check_nodes_are_referenced (DOCUMENT *document);
void number_floats (DOCUMENT *document);
-ELEMENT *new_node_menu_entry (ELEMENT *node, int use_sections);
+ELEMENT *new_node_menu_entry (const ELEMENT *node, int use_sections);
ELEMENT *new_complete_node_menu (const ELEMENT *node, DOCUMENT *document,
const OPTIONS *options, int use_sections);
void new_block_command (ELEMENT *element, enum command_id cmd);
diff --git a/tp/Texinfo/XS/structuring_transfo/transformations.c
b/tp/Texinfo/XS/structuring_transfo/transformations.c
index 049e317e88..3d220992cc 100644
--- a/tp/Texinfo/XS/structuring_transfo/transformations.c
+++ b/tp/Texinfo/XS/structuring_transfo/transformations.c
@@ -916,7 +916,7 @@ prepend_new_menu_in_node_section (ELEMENT * node, ELEMENT
*section,
}
typedef struct EXISTING_ENTRY {
- char *normalized;
+ const char *normalized;
ELEMENT *menu;
ELEMENT *entry;
} EXISTING_ENTRY;
@@ -952,7 +952,7 @@ complete_node_menu (ELEMENT *node, int use_sections)
ELEMENT *entry = menu->contents.list[j];
if (entry->type == ET_menu_entry)
{
- char *normalized_entry_node
+ const char *normalized_entry_node
= normalized_menu_entry_internal_node (entry);
if (normalized_entry_node)
{
@@ -975,8 +975,8 @@ complete_node_menu (ELEMENT *node, int use_sections)
for (i = 0; i < node_childs->number; i++)
{
- ELEMENT *node_entry = node_childs->list[i];
- char *normalized = lookup_extra_string (node_entry, "normalized");
+ const ELEMENT *node_entry = node_childs->list[i];
+ const char *normalized = lookup_extra_string (node_entry,
"normalized");
if (normalized)
{
int j;
@@ -1040,7 +1040,8 @@ complete_node_menu (ELEMENT *node, int use_sections)
else
{
int offset_at_end = -1;
- ELEMENT *last_menu_content = last_contents_child (current_menu);
+ const ELEMENT *last_menu_content
+ = last_contents_child (current_menu);
if (last_menu_content->cmd != CM_end)
offset_at_end = 0;
@@ -1061,7 +1062,7 @@ complete_node_menu (ELEMENT *node, int use_sections)
}
static ELEMENT_LIST *
-get_non_automatic_nodes_with_sections (ELEMENT *root)
+get_non_automatic_nodes_with_sections (const ELEMENT *root)
{
ELEMENT_LIST *non_automatic_nodes = new_list ();
int i;
@@ -1072,7 +1073,7 @@ get_non_automatic_nodes_with_sections (ELEMENT *root)
if (content->cmd && content->cmd == CM_node
&& content->args.number <= 1)
{
- ELEMENT *associated_section
+ const ELEMENT *associated_section
= lookup_extra_element (content, "associated_section");
if (associated_section)
add_to_element_list (non_automatic_nodes, content);
@@ -1083,7 +1084,7 @@ get_non_automatic_nodes_with_sections (ELEMENT *root)
/* This should be called after structuring.c sectioning_structure */
void
-complete_tree_nodes_menus (ELEMENT *root, int use_sections)
+complete_tree_nodes_menus (const ELEMENT *root, int use_sections)
{
ELEMENT_LIST *non_automatic_nodes
= get_non_automatic_nodes_with_sections (root);
@@ -1097,7 +1098,7 @@ complete_tree_nodes_menus (ELEMENT *root, int
use_sections)
}
void
-complete_tree_nodes_missing_menu (ELEMENT *root, DOCUMENT *document,
+complete_tree_nodes_missing_menu (const ELEMENT *root, DOCUMENT *document,
OPTIONS *options, int use_sections)
{
ELEMENT_LIST *non_automatic_nodes
@@ -1127,13 +1128,13 @@ Here we use the document.
int
regenerate_master_menu (DOCUMENT *document, int use_sections)
{
- LABEL_LIST *identifiers_target = document->identifiers_target;
+ const LABEL_LIST *identifiers_target = document->identifiers_target;
- ELEMENT *top_node = find_identifier_target (identifiers_target, "Top");
+ const ELEMENT *top_node = find_identifier_target (identifiers_target, "Top");
const ELEMENT_LIST *menus;
ELEMENT *master_menu;
ELEMENT *last_menu;
- ELEMENT *last_content;
+ const ELEMENT *last_content;
int i;
int index;
@@ -1160,10 +1161,10 @@ regenerate_master_menu (DOCUMENT *document, int
use_sections)
for (detailmenu_index = 0; detailmenu_index < menu->contents.number;
detailmenu_index++)
{
- ELEMENT *entry = menu->contents.list[detailmenu_index];
+ const ELEMENT *entry = menu->contents.list[detailmenu_index];
if (entry->cmd == CM_detailmenu)
{
- int j;
+ size_t j;
ELEMENT *removed = remove_from_contents (menu, detailmenu_index);
replace_element_in_list (
&document->global_commands->detailmenu, removed, master_menu);
@@ -1175,17 +1176,17 @@ regenerate_master_menu (DOCUMENT *document, int
use_sections)
/* remove internal refs of removed entries */
for (j = 0; j < removed->contents.number; j++)
{
- ELEMENT *content = removed->contents.list[j];
+ const ELEMENT *content = removed->contents.list[j];
if (content->type == ET_menu_entry)
{
- int k;
+ size_t k;
for (k = 0; k < content->contents.number; k++)
{
- ELEMENT *entry_content = content->contents.list[k];
+ const ELEMENT *entry_content =
content->contents.list[k];
if (entry_content->type == ET_menu_entry_node)
{
- ELEMENT *removed_internal_ref =
- remove_element_from_list (
+ const ELEMENT *removed_internal_ref =
+ remove_element_from_list (
document->internal_references,
entry_content);
if (!removed_internal_ref)
@@ -1195,6 +1196,7 @@ regenerate_master_menu (DOCUMENT *document, int
use_sections)
fprintf (stderr,
"BUG: %s: not found in internal refs\n",
removed_internal_texi);
+ free (removed_internal_texi);
}
}
}
@@ -1217,7 +1219,7 @@ regenerate_master_menu (DOCUMENT *document, int
use_sections)
if (index)
{
- ELEMENT *last_element = last_menu->contents.list[index-1];
+ const ELEMENT *last_element = last_menu->contents.list[index-1];
ELEMENT *preformatted = 0;
if (last_element->type == ET_menu_comment
&& last_element->contents.number > 0)
@@ -1258,7 +1260,7 @@ regenerate_master_menu (DOCUMENT *document, int
use_sections)
ELEMENT_LIST *
protect_comma (const char *type, ELEMENT *current, void *argument)
{
- return protect_text(current, ",");
+ return protect_text (current, ",");
}
ELEMENT *
@@ -1270,7 +1272,7 @@ protect_comma_in_tree (ELEMENT *tree)
ELEMENT_LIST *
protect_node_after_label (const char *type, ELEMENT *current, void *argument)
{
- return protect_text(current, ".\t,");
+ return protect_text (current, ".\t,");
}
ELEMENT *
@@ -1288,7 +1290,7 @@ protect_hashchar_at_line_beginning_internal (const char
*type,
{
DOCUMENT *document = (DOCUMENT *) argument;
ERROR_MESSAGE_LIST *error_messages = document->error_messages;
- OPTIONS *options = document->options;
+ const OPTIONS *options = document->options;
if (current->text.end > 0)
{
@@ -1353,7 +1355,7 @@ protect_hashchar_at_line_beginning_internal (const char
*type,
ELEMENT_LIST *container = new_list ();
char *current_text = strdup (current->text.text);
char *p = current_text;
- int leading_spaces_nr;
+ size_t leading_spaces_nr;
ELEMENT *leading_spaces = new_element (ET_NONE);
ELEMENT *hashchar = new_element (ET_NONE);
ELEMENT *arg = new_element (ET_brace_command_arg);
@@ -1361,7 +1363,7 @@ protect_hashchar_at_line_beginning_internal (const char
*type,
source marks locations */
uint8_t *u8_text = 0;
size_t current_position;
- uint8_t *u8_p;
+ const uint8_t *u8_p;
size_t u8_len;
SOURCE_MARK_LIST source_mark_list;
diff --git a/tp/Texinfo/XS/structuring_transfo/transformations.h
b/tp/Texinfo/XS/structuring_transfo/transformations.h
index 9fe00fbb05..b8750a6c3e 100644
--- a/tp/Texinfo/XS/structuring_transfo/transformations.h
+++ b/tp/Texinfo/XS/structuring_transfo/transformations.h
@@ -13,8 +13,8 @@ void move_index_entries_after_items_in_tree (ELEMENT *tree);
ELEMENT *reference_to_arg_in_tree (ELEMENT *tree, DOCUMENT *document);
ELEMENT *protect_comma_in_tree (ELEMENT *tree);
ELEMENT *protect_node_after_label_in_tree (ELEMENT *tree);
-void complete_tree_nodes_menus (ELEMENT *root, int use_sections);
-void complete_tree_nodes_missing_menu (ELEMENT *root, DOCUMENT *document,
+void complete_tree_nodes_menus (const ELEMENT *root, int use_sections);
+void complete_tree_nodes_missing_menu (const ELEMENT *root, DOCUMENT *document,
OPTIONS *options, int use_sections);
int regenerate_master_menu (DOCUMENT *document, int use_sections);
ELEMENT_LIST *insert_nodes_for_sectioning_commands (DOCUMENT *document);