[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/XS/main/debug.c (debug_protect_eol):
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/XS/main/debug.c (debug_protect_eol): always allocate the returned string. Update callers. |
Date: |
Mon, 20 May 2024 13:33:21 -0400 |
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 7b50b3c5b9 * tp/Texinfo/XS/main/debug.c (debug_protect_eol): always
allocate the returned string. Update callers.
7b50b3c5b9 is described below
commit 7b50b3c5b9e60ec1fdac114e0b66272304835c46
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon May 20 19:33:22 2024 +0200
* tp/Texinfo/XS/main/debug.c (debug_protect_eol): always allocate the
returned string. Update callers.
* tp/Texinfo/XS/parsetexi/commands.c (close_preformatted_command):
remove obsolete check of index_entry_command.
* tp/Texinfo/XS/parsetexi/macro.c (parse_macro_command_line):
distinguish the line and pointers on line.
* tp/Texinfo/XS/*/*.c: add const. Use strndup instead of modifying
temporarily an input line otherwise not modified to add an end of line.
---
ChangeLog | 14 ++++++
tp/Texinfo/XS/convert/convert_html.c | 6 +--
tp/Texinfo/XS/main/debug.c | 16 +++---
tp/Texinfo/XS/main/debug.h | 2 +-
tp/Texinfo/XS/main/get_perl_info.c | 7 +--
tp/Texinfo/XS/main/translations.c | 2 +-
tp/Texinfo/XS/main/utils.c | 20 ++++----
tp/Texinfo/XS/main/utils.h | 4 +-
tp/Texinfo/XS/parsetexi/commands.c | 7 ++-
tp/Texinfo/XS/parsetexi/commands.h | 6 +--
tp/Texinfo/XS/parsetexi/debug_parser.c | 22 ++++-----
tp/Texinfo/XS/parsetexi/debug_parser.h | 10 ++--
tp/Texinfo/XS/parsetexi/end_line.c | 28 +++++------
tp/Texinfo/XS/parsetexi/handle_commands.c | 39 +++++++--------
tp/Texinfo/XS/parsetexi/handle_commands.h | 8 +--
tp/Texinfo/XS/parsetexi/macro.c | 67 ++++++++++++-------------
tp/Texinfo/XS/parsetexi/macro.h | 4 +-
tp/Texinfo/XS/parsetexi/menus.c | 4 +-
tp/Texinfo/XS/parsetexi/parser.c | 81 +++++++++++++++----------------
tp/Texinfo/XS/parsetexi/parser.h | 21 ++++----
tp/Texinfo/XS/parsetexi/separator.c | 14 +++---
21 files changed, 190 insertions(+), 192 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 1da3640630..99b800aeac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2024-05-20 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/main/debug.c (debug_protect_eol): always allocate the
+ returned string. Update callers.
+
+ * tp/Texinfo/XS/parsetexi/commands.c (close_preformatted_command):
+ remove obsolete check of index_entry_command.
+
+ * tp/Texinfo/XS/parsetexi/macro.c (parse_macro_command_line):
+ distinguish the line and pointers on line.
+
+ * tp/Texinfo/XS/*/*.c: add const. Use strndup instead of modifying
+ temporarily an input line otherwise not modified to add an end of line.
+
2024-05-20 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/parsetexi/source_marks.c (source_marks_counters)
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index 7867da408f..5d469aa30c 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -18022,11 +18022,9 @@ convert_to_html_internal (CONVERTER *self, const
ELEMENT *element,
{
if (element->text.end > 0)
{
- int allocated;
- char *text = debug_protect_eol (element->text.text, &allocated);
+ char *text = debug_protect_eol (element->text.text);
text_printf (&debug_str, " text: %s", text);
- if (allocated)
- free (text);
+ free (text);
}
else
text_append_n (&debug_str, " text(EMPTY)", 12);
diff --git a/tp/Texinfo/XS/main/debug.c b/tp/Texinfo/XS/main/debug.c
index 4f236b09ef..3aaf91255b 100644
--- a/tp/Texinfo/XS/main/debug.c
+++ b/tp/Texinfo/XS/main/debug.c
@@ -38,21 +38,19 @@ debug_element_command_name (const ELEMENT *e)
}
char *
-debug_protect_eol (char *input_string, int *allocated)
+debug_protect_eol (const char *input_string)
{
char *end_of_line;
- *allocated = 0;
if (!input_string)
- return "[NULL]";
+ return strdup ("[NULL]");
end_of_line = strchr (input_string, '\n');
if (end_of_line)
{
- char *p = input_string;
+ const char *p = input_string;
TEXT text;
- *allocated = 1;
text_init (&text);
while (end_of_line)
{
@@ -72,7 +70,7 @@ debug_protect_eol (char *input_string, int *allocated)
}
return text.text;
}
- return input_string;
+ return strdup (input_string);
}
char *
@@ -89,11 +87,9 @@ print_element_debug (const ELEMENT *e, int print_parent)
text_printf (&text, "(%s)", element_type_names[e->type]);
if (e->text.end > 0)
{
- int allocated = 0;
- char *element_text = debug_protect_eol (e->text.text, &allocated);
+ char *element_text = debug_protect_eol (e->text.text);
text_printf (&text, "[T: %s]", element_text);
- if (allocated)
- free (element_text);
+ free (element_text);
}
if (e->args.number)
text_printf (&text, "[A%d]", e->args.number);
diff --git a/tp/Texinfo/XS/main/debug.h b/tp/Texinfo/XS/main/debug.h
index b16b520377..e3076c5243 100644
--- a/tp/Texinfo/XS/main/debug.h
+++ b/tp/Texinfo/XS/main/debug.h
@@ -9,6 +9,6 @@
char *print_element_debug (const ELEMENT *e, int print_parent);
char *print_element_debug_details (const ELEMENT *e, int print_parent);
-char *debug_protect_eol (char *input_string, int *allocated);
+char *debug_protect_eol (const char *input_string);
#endif
diff --git a/tp/Texinfo/XS/main/get_perl_info.c
b/tp/Texinfo/XS/main/get_perl_info.c
index 3cac46c132..848f7fff9b 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -77,13 +77,10 @@ debug_print_element_hv (HV *element_hv)
FETCH(text)
if (text_sv)
{
- int allocated = 0;
char *text = SvPVutf8_nolen (*text_sv);
- char *protected_text = debug_protect_eol (text,
- &allocated);
+ char *protected_text = debug_protect_eol (text);
text_printf (&msg, "[T: %s]", protected_text);
- if (allocated)
- free (protected_text);
+ free (protected_text);
}
fprintf (stderr, "ELT_sv: %s\n", msg.text);
free (msg.text);
diff --git a/tp/Texinfo/XS/main/translations.c
b/tp/Texinfo/XS/main/translations.c
index fbf9c7cc01..c177f909db 100644
--- a/tp/Texinfo/XS/main/translations.c
+++ b/tp/Texinfo/XS/main/translations.c
@@ -331,7 +331,7 @@ replace_substrings (const char *string,
while (*p)
{
- char *q = strchr (p, '{');
+ const char *q = strchr (p, '{');
if (q)
{
int found = 0;
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index af10fb98d1..d79d1a1741 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -698,9 +698,9 @@ index_number_index_by_name (const SORTED_INDEX_NAMES
*sorted_indices,
/* text parsing functions used in diverse situations */
/* Read a name used for @set, @value and translations arguments. */
char *
-read_flag_name (char **ptr)
+read_flag_name (const char **ptr)
{
- char *p = *ptr, *q;
+ const char *p = *ptr, *q;
char *ret = 0;
q = p;
@@ -761,10 +761,11 @@ collapse_spaces (const char *text)
have a \0.
*/
char *
-parse_line_directive (char *line, int *retval, int *out_line_no)
+parse_line_directive (const char *line, int *retval, int *out_line_no)
{
- char *p = line;
- char *q;
+ const char *p = line;
+ const char *q;
+ char *digit_end;
char *filename = 0;
int line_no = 0;
@@ -787,20 +788,17 @@ parse_line_directive (char *line, int *retval, int
*out_line_no)
/* p should now be at the line number */
if (!strchr (digit_chars, *p))
return 0;
- line_no = strtoul (p, &p, 10);
+ line_no = strtoul (p, &digit_end, 10);
+ p += (digit_end - p);
p += strspn (p, " \t");
if (*p == '"')
{
- char saved;
p++;
q = strchr (p, '"');
if (!q)
return 0;
- saved = *q;
- *q = 0;
- filename = strdup (p);
- *q = saved;
+ filename = strndup (p, q - p);
p = q + 1;
p += strspn (p, " \t");
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/utils.h
index 2f3254599b..fa1d668d8f 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/utils.h
@@ -186,11 +186,11 @@ INDEX *indices_info_index_by_name (const INDEX_LIST
*indices_information,
INDEX *ultimate_index (INDEX *index);
size_t index_number_index_by_name (const SORTED_INDEX_NAMES *sorted_indices,
const char *name);
-char *read_flag_name (char **ptr);
+char *read_flag_name (const char **ptr);
int section_level (const ELEMENT *section);
enum command_id section_level_adjusted_command_name (const ELEMENT *element);
char *collapse_spaces (const char *text);
-char *parse_line_directive (char *line, int *retval, int *out_line_no);
+char *parse_line_directive (const char *line, int *retval, int *out_line_no);
int is_content_empty (const ELEMENT *tree, int do_not_ignore_index_entries);
STRING_LIST *new_string_list (void);
diff --git a/tp/Texinfo/XS/parsetexi/commands.c
b/tp/Texinfo/XS/parsetexi/commands.c
index 3a3bf9ff1a..117a09b073 100644
--- a/tp/Texinfo/XS/parsetexi/commands.c
+++ b/tp/Texinfo/XS/parsetexi/commands.c
@@ -32,7 +32,7 @@ static size_t user_defined_space = 0;
/* Return element number. Return 0 if not found. */
enum command_id
-lookup_command (char *cmdname)
+lookup_command (const char *cmdname)
{
enum command_id cmd;
int i;
@@ -63,7 +63,7 @@ lookup_command (char *cmdname)
/* Add a new user-defined Texinfo command, like an index or macro command.
No reference to NAME is retained. */
enum command_id
-add_texinfo_command (char *name)
+add_texinfo_command (const char *name)
{
enum command_id existing_cmd = lookup_command (name);
@@ -139,7 +139,6 @@ int
close_preformatted_command (enum command_id cmd_id)
{
return cmd_id != CM_sp
- && command_data(cmd_id).flags & CF_close_paragraph
- && !(command_data(cmd_id).flags & CF_index_entry_command);
+ && command_data(cmd_id).flags & CF_close_paragraph;
}
diff --git a/tp/Texinfo/XS/parsetexi/commands.h
b/tp/Texinfo/XS/parsetexi/commands.h
index b3e6822d11..863eaf5524 100644
--- a/tp/Texinfo/XS/parsetexi/commands.h
+++ b/tp/Texinfo/XS/parsetexi/commands.h
@@ -23,7 +23,7 @@ extern COMMAND *user_defined_command_data;
/* Command ID's with this bit set represent a user-defined command. */
#define USER_COMMAND_BIT 0x8000
-enum command_id lookup_command (char *cmdname);
+enum command_id lookup_command (const char *cmdname);
#define command_data(id) \
(!((id) & USER_COMMAND_BIT) \
@@ -34,8 +34,8 @@ enum command_id lookup_command (char *cmdname);
#define command_name(cmd) (command_data(cmd).cmdname)
int close_preformatted_command (enum command_id cmd_id);
-int item_line_command (enum command_id cmd_id);
-enum command_id add_texinfo_command (char *name);
+
+enum command_id add_texinfo_command (const char *name);
void remove_texinfo_command (enum command_id cmd);
void wipe_user_commands (void);
diff --git a/tp/Texinfo/XS/parsetexi/debug_parser.c
b/tp/Texinfo/XS/parsetexi/debug_parser.c
index 81e156a18f..b2d6ae5c7f 100644
--- a/tp/Texinfo/XS/parsetexi/debug_parser.c
+++ b/tp/Texinfo/XS/parsetexi/debug_parser.c
@@ -28,7 +28,7 @@
/* debug functions used in parser, depending on parser_conf.debug */
void
-debug (char *s, ...)
+debug (const char *s, ...)
{
va_list v;
@@ -40,7 +40,7 @@ debug (char *s, ...)
}
void
-debug_nonl (char *s, ...)
+debug_nonl (const char *s, ...)
{
va_list v;
@@ -63,15 +63,13 @@ debug_print_element (const ELEMENT *e, int print_parent)
}
void
-debug_print_protected_string (char *input_string)
+debug_print_protected_string (const char *input_string)
{
if (parser_conf.debug)
{
- int allocated = 0;
- char *result = debug_protect_eol (input_string, &allocated);
+ char *result = debug_protect_eol (input_string);
fputs (result, stderr);
- if (allocated)
- free (result);
+ free (result);
}
}
@@ -94,7 +92,7 @@ debug_parser_command_name (enum command_id cmd)
}
char *
-print_element_debug_parser (ELEMENT *e, int print_parent)
+print_element_debug_parser (const ELEMENT *e, int print_parent)
{
TEXT text;
char *result;
@@ -107,11 +105,9 @@ print_element_debug_parser (ELEMENT *e, int print_parent)
text_printf (&text, "(%s)", element_type_names[e->type]);
if (e->text.end > 0)
{
- int allocated = 0;
- char *element_text = debug_protect_eol (e->text.text, &allocated);
+ char *element_text = debug_protect_eol (e->text.text);
text_printf (&text, "[T: %s]", element_text);
- if (allocated)
- free (element_text);
+ free (element_text);
}
if (e->args.number)
text_printf (&text, "[A%d]", e->args.number);
@@ -131,7 +127,7 @@ print_element_debug_parser (ELEMENT *e, int print_parent)
}
void
-debug_parser_print_element (ELEMENT *e, int print_parent)
+debug_parser_print_element (const ELEMENT *e, int print_parent)
{
if (parser_conf.debug)
{
diff --git a/tp/Texinfo/XS/parsetexi/debug_parser.h
b/tp/Texinfo/XS/parsetexi/debug_parser.h
index 7e8673c939..657adf0d52 100644
--- a/tp/Texinfo/XS/parsetexi/debug_parser.h
+++ b/tp/Texinfo/XS/parsetexi/debug_parser.h
@@ -4,13 +4,13 @@
#include "tree_types.h"
-void debug (char *s, ...);
-void debug_nonl (char *s, ...);
+void debug (const char *s, ...);
+void debug_nonl (const char *s, ...);
void debug_print_element (const ELEMENT *e, int print_parent);
-void debug_print_protected_string (char *input_string);
+void debug_print_protected_string (const char *input_string);
-char *print_element_debug_parser (ELEMENT *e, int print_parent);
+char *print_element_debug_parser (const ELEMENT *e, int print_parent);
const char *debug_parser_command_name (enum command_id cmd);
-void debug_parser_print_element (ELEMENT *e, int print_parent);
+void debug_parser_print_element (const ELEMENT *e, int print_parent);
#endif
diff --git a/tp/Texinfo/XS/parsetexi/end_line.c
b/tp/Texinfo/XS/parsetexi/end_line.c
index 75d89d500e..f439e37236 100644
--- a/tp/Texinfo/XS/parsetexi/end_line.c
+++ b/tp/Texinfo/XS/parsetexi/end_line.c
@@ -55,11 +55,11 @@
#include "node_name_normalization.h"
static int
-is_decimal_number (char *string)
+is_decimal_number (const char *string)
{
- char *p = string;
- char *first_digits = 0;
- char *second_digits = 0;
+ const char *p = string;
+ const char *first_digits = 0;
+ const char *second_digits = 0;
if (string[0] == '\0')
return 0;
@@ -86,7 +86,7 @@ is_decimal_number (char *string)
}
static int
-is_whole_number (char *string)
+is_whole_number (const char *string)
{
if (string[strspn (string, digit_chars)] == '\0')
return 1;
@@ -109,7 +109,7 @@ parse_line_command_args (ELEMENT *line_command)
ELEMENT *arg = line_command->args.list[0];
ELEMENT *line_args;
enum command_id cmd;
- char *line;
+ const char *line;
cmd = line_command->cmd;
if (arg->contents.number == 0)
@@ -282,7 +282,7 @@ parse_line_command_args (ELEMENT *line_command)
{
/* @multitable @columnfractions .33 .33 .33 */
ELEMENT *new;
- char *p, *q;
+ const char *p, *q;
if (!*line)
{
@@ -338,7 +338,7 @@ parse_line_command_args (ELEMENT *line_command)
break;
char *name = 0;
- char *p = line;
+ const char *p = line;
name = read_command_name (&p);
if (*p)
@@ -349,14 +349,14 @@ parse_line_command_args (ELEMENT *line_command)
BASE.NAME in the same directory. This is to prevent such
files being overwritten by the files read by texindex. */
{
- static char *forbidden_index_names[] = {
+ static const char *forbidden_index_names[] = {
"cp", "fn", "ky", "pg", "tp", "vr",
"cps", "fns", "kys", "pgs", "tps", "vrs",
"info", "ps", "pdf", "htm", "html",
"log", "aux", "dvi", "texi", "txi",
"texinfo", "tex", "bib", 0
};
- char **ptr;
+ const char **ptr;
for (ptr = forbidden_index_names; *ptr; ptr++)
if (!strcmp (name, *ptr))
goto defindex_reserved;
@@ -384,7 +384,7 @@ parse_line_command_args (ELEMENT *line_command)
char *index_name_from = 0, *index_name_to = 0;
INDEX *from_index;
INDEX *to_index;
- char *p = line;
+ const char *p = line;
if (!isascii_alnum (*p))
goto synindex_invalid;
@@ -454,7 +454,7 @@ parse_line_command_args (ELEMENT *line_command)
case CM_printindex:
{
char *arg;
- char *p = line;
+ const char *p = line;
arg = read_command_name (&p);
if (!arg || *p)
line_error ("bad argument to @printindex: %s", line);
@@ -1104,7 +1104,7 @@ end_line_starting_block (ELEMENT *current)
}
else
{
- char *p = name;
+ const char *p = name;
char *flag = read_flag_name (&p);
if (flag && !*p)
{
@@ -1265,7 +1265,7 @@ end_line_misc_line (ELEMENT *current)
add_extra_string (current, "text_arg", text);
if (current->cmd == CM_end)
{
- char *line = text;
+ const char *line = text;
/* Set end_command - used below. */
end_command = read_command_name (&line);
diff --git a/tp/Texinfo/XS/parsetexi/handle_commands.c
b/tp/Texinfo/XS/parsetexi/handle_commands.c
index 082d960421..162c31403c 100644
--- a/tp/Texinfo/XS/parsetexi/handle_commands.c
+++ b/tp/Texinfo/XS/parsetexi/handle_commands.c
@@ -114,10 +114,11 @@ in_paragraph (ELEMENT *current)
}
/* Return end of argument before comment and whitespace. */
-char *
-skip_to_comment (char *q, int *has_comment)
+const char *
+skip_to_comment (const char *text, int *has_comment)
{
- char *q1;
+ const char *q = text;
+ const char *q1;
while (1)
{
@@ -150,11 +151,11 @@ skip_to_comment (char *q, int *has_comment)
/* Return end of argument before comment and whitespace if the
line is followed either by whitespaces or a comment. */
-char *
-skip_to_comment_if_comment_or_spaces (char *after_argument,
- int *has_comment)
+const char *
+skip_to_comment_if_comment_or_spaces (const char *after_argument,
+ int *has_comment)
{
- char *r = skip_to_comment (after_argument, has_comment);
+ const char *r = skip_to_comment (after_argument, has_comment);
if (!strchr (whitespace_chars, *after_argument)
&& *after_argument != '@')
@@ -171,7 +172,7 @@ skip_to_comment_if_comment_or_spaces (char *after_argument,
/* Process argument to raw line command. */
ELEMENT *
-parse_rawline_command (char *line, enum command_id cmd,
+parse_rawline_command (const char *line, enum command_id cmd,
int *has_comment, int *special_arg)
{
#define ADD_ARG(string, len) do { \
@@ -181,7 +182,9 @@ parse_rawline_command (char *line, enum command_id cmd,
} while (0)
ELEMENT *args = new_element (ET_NONE);
- char *p = 0, *q = 0, *r = 0;
+ const char *p = 0;
+ const char *q = 0;
+ const char *r = 0;
char *value = 0;
*special_arg = 1;
@@ -331,12 +334,12 @@ parse_rawline_command (char *line, enum command_id cmd,
/* symbol skipspace other */
ELEMENT *
-handle_other_command (ELEMENT *current, char **line_inout,
+handle_other_command (ELEMENT *current, const char **line_inout,
enum command_id cmd, int *status,
ELEMENT **command_element)
{
ELEMENT *command_e = 0;
- char *line = *line_inout;
+ const char *line = *line_inout;
int arg_spec;
*status = STILL_MORE_TO_PROCESS;
@@ -520,12 +523,12 @@ handle_other_command (ELEMENT *current, char **line_inout,
/* data_cmd (used for the information on the command) and cmd (for the
command name) is different for the only multicategory command, @item */
ELEMENT *
-handle_line_command (ELEMENT *current, char **line_inout,
+handle_line_command (ELEMENT *current, const char **line_inout,
enum command_id cmd, enum command_id data_cmd,
int *status, ELEMENT **command_element)
{
ELEMENT *command_e = 0;
- char *line = *line_inout;
+ const char *line = *line_inout;
int arg_spec;
*status = STILL_MORE_TO_PROCESS;
@@ -991,11 +994,11 @@ parser_format_expanded_p (const char *format)
end in @end <command name>. The block will be processed until
"end_line_misc_line" in end_line.c processes the @end command. */
ELEMENT *
-handle_block_command (ELEMENT *current, char **line_inout,
+handle_block_command (ELEMENT *current, const char **line_inout,
enum command_id cmd, int *get_new_line,
ELEMENT **command_element)
{
- char *line = *line_inout;
+ const char *line = *line_inout;
unsigned long flags = command_data(cmd).flags;
ELEMENT *block = 0;
@@ -1174,10 +1177,9 @@ funexit:
}
ELEMENT *
-handle_brace_command (ELEMENT *current, char **line_inout, enum command_id cmd,
- ELEMENT **command_element)
+handle_brace_command (ELEMENT *current, const char **line_inout,
+ enum command_id cmd, ELEMENT **command_element)
{
- char *line = *line_inout;
ELEMENT *command_e;
debug ("OPEN BRACE @%s", command_name(cmd));
@@ -1228,7 +1230,6 @@ handle_brace_command (ELEMENT *current, char
**line_inout, enum command_id cmd,
command_name(cmd));
}
- *line_inout = line;
*command_element = command_e;
return current;
}
diff --git a/tp/Texinfo/XS/parsetexi/handle_commands.h
b/tp/Texinfo/XS/parsetexi/handle_commands.h
index 0c6de63d53..3f10c65a49 100644
--- a/tp/Texinfo/XS/parsetexi/handle_commands.h
+++ b/tp/Texinfo/XS/parsetexi/handle_commands.h
@@ -5,16 +5,16 @@
#include "tree_types.h"
#include "document_types.h"
-ELEMENT *handle_other_command (ELEMENT *current, char **line_inout,
+ELEMENT *handle_other_command (ELEMENT *current, const char **line_inout,
enum command_id cmd_id, int *status,
ELEMENT **command_element);
-ELEMENT *handle_line_command (ELEMENT *current, char **line_inout,
+ELEMENT *handle_line_command (ELEMENT *current, const char **line_inout,
enum command_id cmd_id, enum command_id data_cmd,
int *status, ELEMENT **command_element);
-ELEMENT *handle_block_command (ELEMENT *current, char **line_inout,
+ELEMENT *handle_block_command (ELEMENT *current, const char **line_inout,
enum command_id cmd_id, int *new_line,
ELEMENT **command_element);
-ELEMENT *handle_brace_command (ELEMENT *current, char **line_inout,
+ELEMENT *handle_brace_command (ELEMENT *current, const char **line_inout,
enum command_id cmd_id, ELEMENT
**command_element);
int check_no_text (const ELEMENT *current);
diff --git a/tp/Texinfo/XS/parsetexi/macro.c b/tp/Texinfo/XS/parsetexi/macro.c
index 809442bb8b..ef0873ae36 100644
--- a/tp/Texinfo/XS/parsetexi/macro.c
+++ b/tp/Texinfo/XS/parsetexi/macro.c
@@ -116,12 +116,14 @@ new_macro (char *name, ELEMENT *macro)
name and the arguments it takes, and return this information in a new
ELEMENT. */
ELEMENT *
-parse_macro_command_line (enum command_id cmd, char **line_inout,
+parse_macro_command_line (enum command_id cmd, const char **line_inout,
ELEMENT *parent)
{
- char *line = *line_inout;
+ const char *line = *line_inout;
+ const char *pline = line;
ELEMENT *macro, *macro_name;
- char *name, *args_ptr;
+ char *name;
+ const char *args_ptr;
int index;
macro = new_element (ET_NONE);
@@ -130,8 +132,8 @@ parse_macro_command_line (enum command_id cmd, char
**line_inout,
add_info_string_dup (macro, "arg_line", line);
- line += strspn (line, whitespace_chars);
- name = read_command_name (&line);
+ pline += strspn (pline, whitespace_chars);
+ name = read_command_name (&pline);
if (!name)
{
@@ -140,8 +142,8 @@ parse_macro_command_line (enum command_id cmd, char
**line_inout,
return macro;
}
- if (*line && *line != '{' && *line != '@'
- && !strchr (whitespace_chars, *line))
+ if (*pline && *pline != '{' && *pline != '@'
+ && !strchr (whitespace_chars, *pline))
{
line_error ("bad name for @%s", command_name (cmd));
add_extra_integer (macro, "invalid_syntax", 1);
@@ -156,7 +158,7 @@ parse_macro_command_line (enum command_id cmd, char
**line_inout,
free (name);
add_to_element_args (macro, macro_name);
- args_ptr = line;
+ args_ptr = pline;
args_ptr += strspn (args_ptr, whitespace_chars);
if (*args_ptr != '{')
@@ -172,7 +174,7 @@ parse_macro_command_line (enum command_id cmd, char
**line_inout,
/* args_ptr is after a '{' or ','. INDEX holds the number of
the macro argument */
- char *q, *q2;
+ const char *q, *q2;
ELEMENT *arg;
args_ptr += strspn (args_ptr, whitespace_chars);
@@ -214,15 +216,15 @@ parse_macro_command_line (enum command_id cmd, char
**line_inout,
/* Check the argument name. */
{
- char *p;
+ const char *p;
for (p = args_ptr; p < q2; p++)
{
if (!isascii_alnum (*p) && *p != '_' && *p != '-')
{
- char saved = *q2; *q2 = 0;
+ char *formal_arg = strndup (args_ptr, q2 - args_ptr);
line_error ("bad or empty @%s formal argument: %s",
- command_name(cmd), args_ptr);
- *q2 = saved;
+ command_name(cmd), formal_arg);
+ free (formal_arg);
add_extra_integer (macro, "invalid_syntax", 1);
break;
}
@@ -239,11 +241,11 @@ parse_macro_command_line (enum command_id cmd, char
**line_inout,
}
check_trailing:
- line = args_ptr;
- line += strspn (line, whitespace_chars);
- if (*line && *line != '@')
+ pline = args_ptr;
+ pline += strspn (pline, whitespace_chars);
+ if (*pline && *pline != '@')
{
- char *argument_str = strdup (line);
+ char *argument_str = strdup (pline);
/* remove new line for the message */
char *end_line = strchr (argument_str, '\n');
@@ -254,9 +256,8 @@ parse_macro_command_line (enum command_id cmd, char
**line_inout,
free (argument_str);
add_extra_integer (macro, "invalid_syntax", 1);
}
- //line += strlen (line); /* Discard rest of line. */
- *line_inout = line;
+ *line_inout = pline;
return macro;
}
@@ -267,7 +268,7 @@ parse_macro_command_line (enum command_id cmd, char
**line_inout,
Return -1 if not found. */
int
-lookup_macro_parameter (char *name, ELEMENT *macro)
+lookup_macro_parameter (const char *name, ELEMENT *macro)
{
int i, pos;
ELEMENT **args;
@@ -308,11 +309,11 @@ remove_empty_arg (ELEMENT *argument)
identifier of the macro command. Return array of the arguments. Return
value to be freed by caller. */
void
-expand_macro_arguments (ELEMENT *macro, char **line_inout, enum command_id cmd,
- ELEMENT *current)
+expand_macro_arguments (ELEMENT *macro, const char **line_inout,
+ enum command_id cmd, ELEMENT *current)
{
- char *line = *line_inout;
- char *pline = line;
+ const char *line = *line_inout;
+ const char *pline = line;
TEXT *arg;
int braces_level = 1;
int args_total;
@@ -343,7 +344,7 @@ expand_macro_arguments (ELEMENT *macro, char **line_inout,
enum command_id cmd,
{
/* At the beginning of this loop pline is at the start
of an argument. */
- char *sep;
+ const char *sep;
sep = pline + strcspn (pline, "\\,{}");
if (!*sep)
@@ -402,7 +403,7 @@ expand_macro_arguments (ELEMENT *macro, char **line_inout,
enum command_id cmd,
{
if (current->args.number < args_total)
{
- char *p = pline;
+ const char *p = pline;
remove_empty_content (argument);
@@ -462,11 +463,11 @@ set_toplevel_braces_nr (COUNTER *counter, ELEMENT*
element)
}
void
-expand_linemacro_arguments (ELEMENT *macro, char **line_inout,
+expand_linemacro_arguments (ELEMENT *macro, const char **line_inout,
enum command_id cmd, ELEMENT *current)
{
- char *line = *line_inout;
- char *pline = line;
+ const char *line = *line_inout;
+ const char *pline = line;
TEXT *arg;
int braces_level = 0;
int args_total;
@@ -497,7 +498,7 @@ expand_linemacro_arguments (ELEMENT *macro, char
**line_inout,
while (1)
{
- char *sep;
+ const char *sep;
sep = pline + strcspn (pline, linecommand_expansion_delimiters);
if (!*sep)
@@ -673,7 +674,7 @@ expand_macro_body (MACRO *macro_record, ELEMENT *arguments,
TEXT *expanded)
int pos; /* Index into arguments. */
ELEMENT *macro;
char *macrobody;
- char *ptext;
+ const char *ptext;
macro = macro_record->element;
@@ -799,9 +800,9 @@ wipe_macros (void)
The returned element is an out of tree element holding the call
arguments also associated to the macro expansion source mark */
ELEMENT *
-handle_macro (ELEMENT *current, char **line_inout, enum command_id cmd)
+handle_macro (ELEMENT *current, const char **line_inout, enum command_id cmd)
{
- char *line, *p;
+ const char *line, *p;
MACRO *macro_record;
ELEMENT *macro;
TEXT expanded;
diff --git a/tp/Texinfo/XS/parsetexi/macro.h b/tp/Texinfo/XS/parsetexi/macro.h
index a3b500777b..c50a114516 100644
--- a/tp/Texinfo/XS/parsetexi/macro.h
+++ b/tp/Texinfo/XS/parsetexi/macro.h
@@ -33,9 +33,9 @@ typedef struct {
} MACRO;
void new_macro (char *name, ELEMENT *macro);
-ELEMENT *parse_macro_command_line (enum command_id, char **line_inout,
+ELEMENT *parse_macro_command_line (enum command_id, const char **line_inout,
ELEMENT *parent);
-ELEMENT *handle_macro (ELEMENT *current, char **line_inout,
+ELEMENT *handle_macro (ELEMENT *current, const char **line_inout,
enum command_id cmd_id);
void delete_macro (char *name);
void unset_macro_record (MACRO *m);
diff --git a/tp/Texinfo/XS/parsetexi/menus.c b/tp/Texinfo/XS/parsetexi/menus.c
index 5562f64bb5..078bfde810 100644
--- a/tp/Texinfo/XS/parsetexi/menus.c
+++ b/tp/Texinfo/XS/parsetexi/menus.c
@@ -112,10 +112,10 @@ enter_menu_entry_node (ELEMENT *current)
/* Called from 'process_remaining_on_line' in parser.c. Return 1 if we find
menu syntax to process, otherwise return 0. */
int
-handle_menu_entry_separators (ELEMENT **current_inout, char **line_inout)
+handle_menu_entry_separators (ELEMENT **current_inout, const char **line_inout)
{
ELEMENT *current = *current_inout;
- char *line = *line_inout;
+ const char *line = *line_inout;
int retval = 1;
/* A "*" at the start of a line beginning a menu entry. */
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index 0cb039deb6..1acb3adba8 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -71,7 +71,7 @@ DOCUMENT *parsed_document = 0;
/* Check if the contents of S2 appear at S1). */
int
-looking_at (char *s1, char *s2)
+looking_at (const char *s1, const char *s2)
{
return !strncmp (s1, s2, strlen (s2));
}
@@ -81,9 +81,9 @@ looking_at (char *s1, char *s2)
commands, but is also used elsewhere. Return value to be freed by caller.
*PTR is advanced past the read name. Return 0 if name is invalid. */
char *
-read_command_name (char **ptr)
+read_command_name (const char **ptr)
{
- char *p = *ptr, *q;
+ const char *p = *ptr, *q;
char *ret = 0;
q = p;
@@ -104,9 +104,9 @@ read_command_name (char **ptr)
if the command is a single character command.
Return 0 if name is invalid or the empty string */
char *
-parse_command_name (char **ptr, int *single_char)
+parse_command_name (const char **ptr, int *single_char)
{
- char *p = *ptr;
+ const char *p = *ptr;
char *ret = 0;
*single_char = 0;
@@ -133,10 +133,10 @@ parse_command_name (char **ptr, int *single_char)
/* the pointer returned is past @c/@comment, whether there is indeed
a comment or not. If there is a comment, *has_comment is set to 1 */
-char *
-read_comment (char *line, int *has_comment)
+const char *
+read_comment (const char *line, int *has_comment)
{
- char *p = line;
+ const char *p = line;
int len = strlen (line);
*has_comment = 0;
@@ -647,7 +647,7 @@ end_preformatted (ELEMENT *current,
from that element.
*/
ELEMENT *
-merge_text (ELEMENT *current, char *text, ELEMENT *transfer_marks_element)
+merge_text (ELEMENT *current, const char *text, ELEMENT
*transfer_marks_element)
{
int no_merge_with_following_text = 0;
int leading_spaces = strspn (text, whitespace_chars);
@@ -976,10 +976,10 @@ isolate_last_space (ELEMENT *current)
or commands starting a block, that will end up in COMMAND extra spaces
value. */
void
-start_empty_line_after_command (ELEMENT *current, char **line_inout,
+start_empty_line_after_command (ELEMENT *current, const char **line_inout,
ELEMENT *command)
{
- char *line = *line_inout;
+ const char *line = *line_inout;
ELEMENT *e;
int len;
@@ -1077,10 +1077,10 @@ new_value_element (enum command_id cmd, char *flag,
ELEMENT *spaces_element)
/* Check if line is "@end ..." for current command. If so, advance LINE. */
int
-is_end_current_command (ELEMENT *current, char **line,
+is_end_current_command (ELEMENT *current, const char **line,
enum command_id *end_cmd)
{
- char *linep;
+ const char *linep;
char *cmdname;
linep = *line;
@@ -1335,12 +1335,12 @@ check_valid_nesting_context (enum command_id cmd)
GET_A_NEW_LINE when we need to read a new line
FINISHED_TOTALLY when @bye was found */
int
-process_remaining_on_line (ELEMENT **current_inout, char **line_inout)
+process_remaining_on_line (ELEMENT **current_inout, const char **line_inout)
{
ELEMENT *current = *current_inout;
ELEMENT *macro_call_element = 0;
- char *line = *line_inout;
- char *line_after_command;
+ const char *line = *line_inout;
+ const char *line_after_command;
int retval = STILL_MORE_TO_PROCESS;
enum command_id end_cmd;
enum command_id from_alias = CM_NONE;
@@ -1357,7 +1357,7 @@ process_remaining_on_line (ELEMENT **current_inout, char
**line_inout)
if (command_flags(current) & CF_block
&& (command_data(current->cmd).data == BLOCK_raw))
{
- char *p = line;
+ const char *p = line;
enum command_id cmd = 0;
int closed_nested_raw = 0;
/* Check if we are using a macro within a macro. */
@@ -1507,7 +1507,7 @@ process_remaining_on_line (ELEMENT **current_inout, char
**line_inout)
else if (command_flags(current) & CF_block
&& (command_data(current->cmd).data == BLOCK_conditional))
{
- char *p = line;
+ const char *p = line;
/* check for nested @ifset (so that @end ifset doesn't end the
the outermost @ifset). */
@@ -1576,9 +1576,9 @@ process_remaining_on_line (ELEMENT **current_inout, char
**line_inout)
/* Check if parent element is 'verb' */
else if (current->parent && current->parent->cmd == CM_verb)
{
- char *q;
-
- char *delimiter = lookup_info_string (current->parent, "delimiter");
+ const char *q;
+ const char *delimiter
+ = lookup_info_string (current->parent, "delimiter");
if (strcmp (delimiter, ""))
{
@@ -1609,10 +1609,7 @@ process_remaining_on_line (ELEMENT **current_inout, char
**line_inout)
add_to_element_contents (current, e);
}
debug ("END VERB");
- if (strcmp (delimiter, ""))
- line = q + strlen (delimiter);
- else
- line = q;
+ line = q + strlen (delimiter);
/* The '}' will close the @verb command in handle_separator below. */
}
else
@@ -1634,7 +1631,7 @@ process_remaining_on_line (ELEMENT **current_inout, char
**line_inout)
ELEMENT *e_elided_rawpreformatted;
ELEMENT *e_empty_line;
enum command_id dummy;
- char *line_dummy;
+ const char *line_dummy;
int n;
e_elided_rawpreformatted = new_element (ET_elided_rawpreformatted);
@@ -1744,7 +1741,7 @@ process_remaining_on_line (ELEMENT **current_inout, char
**line_inout)
{
static char *allocated_line;
- line = line_after_command;
+ line += (line_after_command - line);
macro_call_element = handle_macro (current, &line, cmd);
if (macro_call_element)
{
@@ -1772,7 +1769,7 @@ process_remaining_on_line (ELEMENT **current_inout, char
**line_inout)
and early value expansion may be needed to provide with an argument. */
else if (cmd == CM_value)
{
- char *remaining_line = line_after_command;
+ const char *remaining_line = line_after_command;
ELEMENT *spaces_element = 0;
if (parser_conf.ignore_space_after_braced_command_name)
{
@@ -1839,7 +1836,7 @@ process_remaining_on_line (ELEMENT **current_inout, char
**line_inout)
/* Move 'line' to end of string so next input to
be processed is taken from input stack. */
- line = remaining_line + strlen (remaining_line);
+ line += (remaining_line - line) + strlen
(remaining_line);
}
if (value)
{
@@ -1962,15 +1959,15 @@ process_remaining_on_line (ELEMENT **current_inout,
char **line_inout)
/* do not consider the end of line to be possibly between
the @-command and the argument if at the end of a
line or block @-command. */
- char saved; /* TODO: Have a length argument to
merge_text? */
+ char *space_text;
if (current->contents.number > 0)
gather_spaces_after_cmd_before_arg (current);
current = current->parent;
- saved = line[whitespaces_len];
- line[whitespaces_len] = '\0';
- current = merge_text (current, line, 0);
+ /* TODO: Have a length argument to merge_text? */
+ space_text = strndup (line, whitespaces_len);
+ current = merge_text (current, space_text, 0);
+ free (space_text);
line += whitespaces_len;
- *line = saved;
isolate_last_space (current);
current = end_line (current);
retval = GET_A_NEW_LINE;
@@ -2094,7 +2091,7 @@ process_remaining_on_line (ELEMENT **current_inout, char
**line_inout)
/* @value not expanded (expansion is done above), and @txiinternalvalue
*/
if ((cmd == CM_value) || (cmd == CM_txiinternalvalue))
{
- char *arg_start;
+ const char *arg_start;
char *flag;
ELEMENT *spaces_element = 0;
if (parser_conf.ignore_space_after_braced_command_name)
@@ -2393,13 +2390,13 @@ process_remaining_on_line (ELEMENT **current_inout,
char **line_inout)
/* Output until next command, separator or newline. */
{
- char saved; /* TODO: Have a length argument to merge_text? */
+ char *sep_text;
len = strcspn (line, "{}@,:\t.\n\f");
- saved = line[len];
- line[len] = '\0';
- current = merge_text (current, line, 0);
+ /* TODO: Have a length argument to merge_text? */
+ sep_text = strndup (line, len);
+ current = merge_text (current, sep_text, 0);
+ free (sep_text);
line += len;
- *line = saved;
}
}
else /* End of line */
@@ -2432,7 +2429,7 @@ funexit:
/* Check for a #line directive. */
static int
-check_line_directive (char *line)
+check_line_directive (const char *line)
{
int line_no = 0;
int status = 0;
@@ -2464,7 +2461,7 @@ parse_texi (ELEMENT *root_elt, ELEMENT *current_elt)
{
ELEMENT *current = current_elt;
static char *allocated_line;
- char *line;
+ const char *line;
int status;
DOCUMENT *document = parsed_document;
diff --git a/tp/Texinfo/XS/parsetexi/parser.h b/tp/Texinfo/XS/parsetexi/parser.h
index ca73ea0b19..df4e080cae 100644
--- a/tp/Texinfo/XS/parsetexi/parser.h
+++ b/tp/Texinfo/XS/parsetexi/parser.h
@@ -56,9 +56,9 @@ ELEMENT *end_line_misc_line (ELEMENT *current);
ELEMENT *end_line_starting_block (ELEMENT *current);
/* In separator.c */
-ELEMENT * handle_open_brace (ELEMENT *current, char **line_inout);
-ELEMENT * handle_close_brace (ELEMENT *current, char **line_inout);
-ELEMENT * handle_comma (ELEMENT *current, char **line_inout);
+ELEMENT *handle_open_brace (ELEMENT *current, const char **line_inout);
+ELEMENT *handle_close_brace (ELEMENT *current, const char **line_inout);
+ELEMENT *handle_comma (ELEMENT *current, const char **line_inout);
/* In parser.c */
typedef struct {
@@ -87,19 +87,19 @@ ELEMENT *begin_preformatted (ELEMENT *current);
ELEMENT *end_preformatted (ELEMENT *current,
enum command_id closed_block_command,
enum command_id interrupting_command);
-char *read_command_name (char **ptr);
-char *read_comment (char *line, int *has_comment);
+char *read_command_name (const char **ptr);
+const char *read_comment (const char *line, int *has_comment);
char *text_contents_to_plain_text (ELEMENT *e, int *superfluous_arg);
-ELEMENT *merge_text (ELEMENT *current, char *text,
+ELEMENT *merge_text (ELEMENT *current, const char *text,
ELEMENT *transfer_marks_element);
-void start_empty_line_after_command (ELEMENT *current, char **line_inout,
+void start_empty_line_after_command (ELEMENT *current, const char **line_inout,
ELEMENT *command);
ELEMENT *begin_paragraph (ELEMENT *current);
-int is_end_current_command (ELEMENT *current, char **line,
+int is_end_current_command (ELEMENT *current, const char **line,
enum command_id *end_cmd);
int check_space_element (ELEMENT *e);
void gather_spaces_after_cmd_before_arg (ELEMENT *current);
-char *parse_command_name (char **ptr, int *single_char);
+char *parse_command_name (const char **ptr, int *single_char);
/* Return values */
#define GET_A_NEW_LINE 0
@@ -131,6 +131,7 @@ ELEMENT *item_multitable_parent (ELEMENT *current);
void gather_previous_item (ELEMENT *current, enum command_id next_command);
/* In menus.c */
-int handle_menu_entry_separators (ELEMENT **current_inout, char **line_inout);
+int handle_menu_entry_separators (ELEMENT **current_inout,
+ const char **line_inout);
ELEMENT *end_line_menu_entry (ELEMENT *current);
#endif
diff --git a/tp/Texinfo/XS/parsetexi/separator.c
b/tp/Texinfo/XS/parsetexi/separator.c
index 1f21bcc348..9372066371 100644
--- a/tp/Texinfo/XS/parsetexi/separator.c
+++ b/tp/Texinfo/XS/parsetexi/separator.c
@@ -44,9 +44,9 @@
#include "parser.h"
ELEMENT *
-handle_open_brace (ELEMENT *current, char **line_inout)
+handle_open_brace (ELEMENT *current, const char **line_inout)
{
- char *line = *line_inout;
+ const char *line = *line_inout;
if (command_flags(current) & CF_brace)
{
@@ -269,9 +269,9 @@ check_empty_expansion (ELEMENT *e)
}
ELEMENT *
-handle_close_brace (ELEMENT *current, char **line_inout)
+handle_close_brace (ELEMENT *current, const char **line_inout)
{
- char *line = *line_inout;
+ const char *line = *line_inout;
debug ("CLOSE BRACE");
@@ -606,9 +606,9 @@ handle_close_brace (ELEMENT *current, char **line_inout)
/* Handle a comma separating arguments to a Texinfo command. */
ELEMENT *
-handle_comma (ELEMENT *current, char **line_inout)
+handle_comma (ELEMENT *current, const char **line_inout)
{
- char *line = *line_inout;
+ const char *line = *line_inout;
enum element_type type;
ELEMENT *new_arg, *e;
@@ -621,7 +621,7 @@ handle_comma (ELEMENT *current, char **line_inout)
if (command_data(current->cmd).data == BRACE_inline)
{
int expandp = 0;
- char *format = lookup_extra_string (current, "format");
+ const char *format = lookup_extra_string (current, "format");
if (!format)
{
ELEMENT *arg = 0;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/XS/main/debug.c (debug_protect_eol): always allocate the returned string. Update callers.,
Patrice Dumas <=