summaryrefslogtreecommitdiffstats
path: root/contrib/texinfo/makeinfo
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2005-05-23 10:50:32 +0000
committerru <ru@FreeBSD.org>2005-05-23 10:50:32 +0000
commit8b2f0a4d7f08415b66667ee1937a24f1b1333e09 (patch)
treeab8801c7bc6a071e5dfe8c658d4b0ea907acf620 /contrib/texinfo/makeinfo
parentadfa5ff0fcbcb100e0392141216bc92735980e19 (diff)
downloadFreeBSD-src-8b2f0a4d7f08415b66667ee1937a24f1b1333e09.zip
FreeBSD-src-8b2f0a4d7f08415b66667ee1937a24f1b1333e09.tar.gz
Use stock (FSF) version of this file.
Diffstat (limited to 'contrib/texinfo/makeinfo')
-rw-r--r--contrib/texinfo/makeinfo/makeinfo.c1705
1 files changed, 778 insertions, 927 deletions
diff --git a/contrib/texinfo/makeinfo/makeinfo.c b/contrib/texinfo/makeinfo/makeinfo.c
index a5e63fc..22ed4c4 100644
--- a/contrib/texinfo/makeinfo/makeinfo.c
+++ b/contrib/texinfo/makeinfo/makeinfo.c
@@ -1,8 +1,8 @@
/* makeinfo -- convert Texinfo source into other formats.
- $Id: makeinfo.c,v 1.34 2003/06/02 12:32:29 karl Exp $
+ $Id: makeinfo.c,v 1.74 2004/12/19 17:15:42 karl Exp $
Copyright (C) 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+ 2000, 2001, 2002, 2003, 2004 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
@@ -18,7 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- Makeinfo was authored by Brian Fox (bfox@ai.mit.edu). */
+ Original author of makeinfo: Brian Fox (bfox@ai.mit.edu). */
#include "system.h"
#include "getopt.h"
@@ -27,6 +27,7 @@
#include "makeinfo.h"
#include "cmds.h"
#include "files.h"
+#include "float.h"
#include "footnote.h"
#include "html.h"
#include "index.h"
@@ -34,6 +35,7 @@
#include "lang.h"
#include "macro.h"
#include "node.h"
+#include "sectioning.h"
#include "toc.h"
#include "xml.h"
@@ -69,10 +71,6 @@ char *output_filename = NULL;
char *command_output_filename = NULL;
static char *save_command_output_filename = NULL;
-/* Flags which control initial output string for xrefs. */
-int px_ref_flag = 0;
-int ref_flag = 0;
-
#define INITIAL_PARAGRAPH_SPACE 5000
int paragraph_buffer_len = INITIAL_PARAGRAPH_SPACE;
@@ -135,9 +133,16 @@ int do_justification = 0;
/* Nonzero means don't replace whitespace with &nbsp; in HTML mode. */
int in_html_elt = 0;
+/* Nonzero means we are inserting a block level HTML element that must not be
+ enclosed in a <p>, such as <ul>, <ol> and <h?>. */
+int in_html_block_level_elt = 0;
+
/* True when expanding a macro definition. */
static int executing_macro = 0;
+/* True when we are inside a <li> block of a menu. */
+static int in_menu_item = 0;
+
typedef struct brace_element
{
struct brace_element *next;
@@ -149,64 +154,44 @@ typedef struct brace_element
BRACE_ELEMENT *brace_stack = NULL;
-extern void do_multitable (), end_multitable ();
-
-void push_node_filename (), pop_node_filename ();
-void remember_error ();
-void convert_from_stream (), convert_from_file (), convert_from_loaded_file ();
-void init_internals (), init_paragraph (), init_brace_stack ();
-void init_insertion_stack (), init_indices ();
-void init_tag_table (), write_tag_table (), write_tag_table_internal ();
-void validate_file (), validate_other_references (), split_file ();
-void free_node_references (), handle_variable ();
-void handle_variable_internal ();
-void normalize_node_name ();
-void add_anchor_name ();
-void free_node_node_references (), remember_node_node_reference ();
-
-char **get_brace_args ();
-int array_len ();
-void free_array ();
-static int end_of_sentence_p ();
-void reader_loop ();
-void remember_brace (), remember_brace_1 ();
-void pop_and_call_brace (), discard_braces ();
-void add_word (), add_char (), insert (), flush_output ();
-void insert_string ();
-void close_paragraph ();
-void ignore_blank_line ();
-void do_flush_right_indentation (), discard_insertions ();
-void start_paragraph (), indent ();
-void inhibit_output_flushing (), uninhibit_output_flushing ();
-int set_paragraph_indent ();
-int self_delimiting (), search_forward ();
-int multitable_item (), number_of_node ();
-
-void me_execute_string_keep_state ();
-void maybe_update_execution_strings ();
-
-extern char *escape_string ();
-extern void insert_html_tag ();
-extern void sectioning_html ();
-
-#if defined (VA_FPRINTF) && __STDC__
-/* Unfortunately we must use prototypes if we are to use <stdarg.h>. */
-void add_word_args (const char *, ...);
-void execute_string (char *, ...);
-#else
-void add_word_args ();
-void execute_string ();
-#endif /* no prototypes */
+static void convert_from_file (char *name);
+static void convert_from_loaded_file (char *name);
+static void convert_from_stream (FILE *stream, char *name);
+static void do_flush_right_indentation (void);
+static void handle_variable (int action);
+static void handle_variable_internal (int action, char *name);
+static void init_brace_stack (void);
+static void init_internals (void);
+static void pop_and_call_brace (void);
+static void remember_brace (COMMAND_FUNCTION (*proc));
+static int end_of_sentence_p (void);
+
+void maybe_update_execution_strings (char **text, unsigned int new_len);
/* Error handling. */
/* Number of errors encountered. */
int errors_printed = 0;
+/* Remember that an error has been printed. If more than
+ max_error_level have been printed, then exit the program. */
+static void
+remember_error (void)
+{
+ errors_printed++;
+ if (max_error_level && (errors_printed > max_error_level))
+ {
+ fprintf (stderr, _("Too many errors! Gave up.\n"));
+ flush_file_stack ();
+ if (errors_printed - max_error_level < 2)
+ cm_bye ();
+ xexit (1);
+ }
+}
+
/* Print the last error gotten from the file system. */
int
-fs_error (filename)
- char *filename;
+fs_error (char *filename)
{
remember_error ();
perror (filename);
@@ -329,24 +314,9 @@ warning (format, va_alist)
}
-/* Remember that an error has been printed. If more than
- max_error_level have been printed, then exit the program. */
-void
-remember_error ()
-{
- errors_printed++;
- if (max_error_level && (errors_printed > max_error_level))
- {
- fprintf (stderr, _("Too many errors! Gave up.\n"));
- flush_file_stack ();
- cm_bye ();
- xexit (1);
- }
-}
-
/* The other side of a malformed expression. */
-void
-misplaced_brace ()
+static void
+misplaced_brace (void)
{
line_error (_("Misplaced %c"), '}');
}
@@ -355,7 +325,7 @@ misplaced_brace ()
/* Display the version info of this invocation of Makeinfo. */
static void
-print_version_info ()
+print_version_info (void)
{
printf ("makeinfo (GNU %s) %s\n", PACKAGE, VERSION);
}
@@ -364,8 +334,7 @@ print_version_info ()
Otherwise, just say to use --help for more info.
Then exit with EXIT_VALUE. */
static void
-usage (exit_value)
- int exit_value;
+usage (int exit_value)
{
if (exit_value != 0)
fprintf (stderr, _("Try `%s --help' for more information.\n"), progname);
@@ -389,14 +358,15 @@ General options:\n\
-v, --verbose explain what is being done.\n\
--version display version information and exit.\n"),
max_error_level, reference_warning_limit);
- puts ("\n");
+ puts ("");
/* xgettext: no-wrap */
puts (_("\
Output format selection (default is to produce Info):\n\
- --docbook output DocBook XML rather than Info.\n\
+ --docbook output Docbook XML rather than Info.\n\
--html output HTML rather than Info.\n\
--xml output Texinfo XML rather than Info.\n\
+ --plaintext output plain text rather than Info.\n\
"));
puts (_("\
@@ -428,7 +398,7 @@ Options for Info and plain text:\n\
--split-size=NUM split Info files at size NUM (default %d).\n"),
fill_column, paragraph_start_indent,
DEFAULT_SPLIT_SIZE);
- puts ("\n");
+ puts ("");
puts (_("\
Options for HTML:\n\
@@ -436,6 +406,13 @@ Options for HTML:\n\
read stdin if FILE is -.\n\
"));
+ printf (_("\
+Options for XML and Docbook:\n\
+ --output-indent=VAL indent XML elements by VAL spaces (default %d).\n\
+ If VAL is 0, ignorable whitespace is dropped.\n\
+"), xml_indentation_increment);
+ puts ("");
+
puts (_("\
Input file options:\n\
--commands-in-node-names allow @ commands in node names.\n\
@@ -447,16 +424,21 @@ Input file options:\n\
puts (_("\
Conditional processing in input:\n\
+ --ifdocbook process @ifdocbook and @docbook even if\n\
+ not generating Docbook.\n\
--ifhtml process @ifhtml and @html even if not generating HTML.\n\
--ifinfo process @ifinfo even if not generating Info.\n\
--ifplaintext process @ifplaintext even if not generating plain text.\n\
--iftex process @iftex and @tex; implies --no-split.\n\
--ifxml process @ifxml and @xml.\n\
+ --no-ifdocbook do not process @ifdocbook and @docbook text.\n\
--no-ifhtml do not process @ifhtml and @html text.\n\
--no-ifinfo do not process @ifinfo text.\n\
--no-ifplaintext do not process @ifplaintext text.\n\
--no-iftex do not process @iftex and @tex text.\n\
--no-ifxml do not process @ifxml and @xml text.\n\
+\n\
+ Also, for the --no-ifFORMAT options, do process @ifnotFORMAT text.\n\
"));
puts (_("\
@@ -502,6 +484,7 @@ struct option long_options[] =
{ "force", 0, &force, 1 },
{ "help", 0, 0, 'h' },
{ "html", 0, 0, 'w' },
+ { "ifdocbook", 0, &process_docbook, 1 },
{ "ifhtml", 0, &process_html, 1 },
{ "ifinfo", 0, &process_info, 1 },
{ "ifplaintext", 0, &process_plaintext, 1 },
@@ -509,6 +492,7 @@ struct option long_options[] =
{ "ifxml", 0, &process_xml, 1 },
{ "macro-expand", 1, 0, 'E' },
{ "no-headers", 0, &no_headers, 1 },
+ { "no-ifdocbook", 0, &process_docbook, 0 },
{ "no-ifhtml", 0, &process_html, 0 },
{ "no-ifinfo", 0, &process_info, 0 },
{ "no-ifplaintext", 0, &process_plaintext, 0 },
@@ -523,7 +507,9 @@ struct option long_options[] =
{ "number-footnotes", 0, &number_footnotes, 1 },
{ "number-sections", 0, &number_sections, 1 },
{ "output", 1, 0, 'o' },
+ { "output-indent", 1, 0, 'i' },
{ "paragraph-indent", 1, 0, 'p' },
+ { "plaintext", 0, 0, 't' },
{ "reference-limit", 1, 0, 'r' },
{ "split-size", 1, 0, 'S'},
{ "verbose", 0, &verbose_mode, 1 },
@@ -532,14 +518,24 @@ struct option long_options[] =
{NULL, 0, NULL, 0}
};
+/* We use handle_variable_internal for -D and -U, and it depends on
+ execute_string, which depends on input_filename, which is not defined
+ while we are handling options. :-\ So we save these defines in this
+ struct, and handle them later. */
+typedef struct command_line_define
+{
+ struct command_line_define *next;
+ int action;
+ char *define;
+} COMMAND_LINE_DEFINE;
+
+static COMMAND_LINE_DEFINE *command_line_defines = NULL;
+
/* For each file mentioned in the command line, process it, turning
Texinfo commands into wonderfully formatted output text. */
int
-main (argc, argv)
- int argc;
- char **argv;
+main (int argc, char **argv)
{
- extern int errors_printed;
int c, ind;
int reading_from_stdin = 0;
@@ -547,17 +543,69 @@ main (argc, argv)
/* Do not use LC_ALL, because LC_NUMERIC screws up the scanf parsing
of the argument to @multicolumn. */
setlocale (LC_TIME, "");
+#ifdef LC_MESSAGES /* ultrix */
setlocale (LC_MESSAGES, "");
+#endif
setlocale (LC_CTYPE, "");
setlocale (LC_COLLATE, "");
#endif
+#ifdef ENABLE_NLS
/* Set the text message domain. */
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+#endif
+
+ /* If TEXINFO_OUTPUT_FORMAT envvar is set, use it to set default output.
+ Can be overridden with one of the output options. */
+ if (getenv ("TEXINFO_OUTPUT_FORMAT") != NULL)
+ {
+ if (STREQ (getenv ("TEXINFO_OUTPUT_FORMAT"), "docbook"))
+ {
+ splitting = 0;
+ html = 0;
+ docbook = 1;
+ xml = 1;
+ process_docbook = 1;
+ }
+ else if (STREQ (getenv ("TEXINFO_OUTPUT_FORMAT"), "html"))
+ {
+ html = 1;
+ docbook = 0;
+ xml = 0;
+ process_html = 1;
+ }
+ else if (STREQ (getenv ("TEXINFO_OUTPUT_FORMAT"), "info"))
+ {
+ html = 0;
+ docbook = 0;
+ xml = 0;
+ }
+ else if (STREQ (getenv ("TEXINFO_OUTPUT_FORMAT"), "plaintext"))
+ {
+ splitting = 0;
+ no_headers = 1;
+ html = 0;
+ docbook = 0;
+ xml = 0;
+ process_plaintext = 1;
+ }
+ else if (STREQ (getenv ("TEXINFO_OUTPUT_FORMAT"), "xml"))
+ {
+ splitting = 0;
+ html = 0;
+ docbook = 0;
+ xml = 1;
+ process_xml = 1;
+ }
+ else
+ fprintf (stderr,
+ _("%s: Ignoring unrecognized TEXINFO_OUTPUT_FORMAT value `%s'.\n"),
+ progname, getenv ("TEXINFO_OUTPUT_FORMAT"));
+ }
/* Parse argument flags from the input line. */
- while ((c = getopt_long (argc, argv, "D:de:E:f:hI:o:p:P:r:s:U:vV:wx",
+ while ((c = getopt_long (argc, argv, "D:de:E:f:hI:i:o:p:P:r:s:t:U:vV:wx",
long_options, &ind)) != EOF)
{
if (c == 0 && long_options[ind].flag == 0)
@@ -572,13 +620,24 @@ main (argc, argv)
case 'D':
case 'U':
/* User specified variable to set or clear. */
- handle_variable_internal ((c == 'D') ? SET : CLEAR, optarg);
+ if (xml && !docbook)
+ {
+ COMMAND_LINE_DEFINE *new = xmalloc (sizeof (COMMAND_LINE_DEFINE));
+ new->action = (c == 'D') ? SET : CLEAR;
+ new->define = xstrdup (optarg);
+ new->next = command_line_defines;
+ command_line_defines = new;
+ }
+ else
+ handle_variable_internal ((c == 'D' ? SET : CLEAR), optarg);
break;
case 'd': /* --docbook */
splitting = 0;
xml = 1;
docbook = 1;
+ html = 0;
+ process_docbook = 1;
break;
case 'e': /* --error-limit */
@@ -586,7 +645,7 @@ main (argc, argv)
{
fprintf (stderr,
_("%s: %s arg must be numeric, not `%s'.\n"),
- "--error-limit", progname, optarg);
+ progname, "--error-limit", optarg);
usage (1);
}
break;
@@ -598,10 +657,13 @@ main (argc, argv)
macro_expansion_output_stream
= strcmp (optarg, "-") == 0 ? stdout : fopen (optarg, "w");
if (!macro_expansion_output_stream)
- error (_("Couldn't open macro expansion output `%s'"), optarg);
+ error (_("%s: could not open macro expansion output `%s'"),
+ progname, optarg);
}
else
- error (_("Cannot specify more than one macro expansion output"));
+ fprintf (stderr,
+ _("%s: ignoring second macro expansion output `%s'.\n"),
+ progname, optarg);
break;
case 'f': /* --fill-column */
@@ -609,7 +671,7 @@ main (argc, argv)
{
fprintf (stderr,
_("%s: %s arg must be numeric, not `%s'.\n"),
- "--fill-column", progname, optarg);
+ progname, "--fill-column", optarg);
usage (1);
}
break;
@@ -620,14 +682,17 @@ main (argc, argv)
case 'I':
/* Append user-specified dir to include file path. */
- if (!include_files_path)
- include_files_path = xstrdup (".");
-
- include_files_path = (char *)
- xrealloc (include_files_path,
- 2 + strlen (include_files_path) + strlen (optarg));
- strcat (include_files_path, PATH_SEP);
- strcat (include_files_path, optarg);
+ append_to_include_path (optarg);
+ break;
+
+ case 'i':
+ if (sscanf (optarg, "%d", &xml_indentation_increment) != 1)
+ {
+ fprintf (stderr,
+ _("%s: %s arg must be numeric, not `%s'.\n"),
+ progname, "--output-indent", optarg);
+ usage (1);
+ }
break;
case 'o': /* --output */
@@ -647,23 +712,7 @@ main (argc, argv)
case 'P':
/* Prepend user-specified include dir to include path. */
- if (!include_files_path)
- {
- include_files_path = xstrdup (optarg);
- include_files_path = xrealloc (include_files_path,
- strlen (include_files_path) + 3); /* 3 for ":.\0" */
- strcat (strcat (include_files_path, PATH_SEP), ".");
- }
- else
- {
- char *tmp = xstrdup (include_files_path);
- include_files_path = xrealloc (include_files_path,
- strlen (include_files_path) + strlen (optarg) + 2); /* 2 for ":\0" */
- strcpy (include_files_path, optarg);
- strcat (include_files_path, ":");
- strcat (include_files_path, tmp);
- free (tmp);
- }
+ prepend_to_include_path (optarg);
break;
case 'r': /* --reference-limit */
@@ -671,7 +720,7 @@ main (argc, argv)
{
fprintf (stderr,
_("%s: %s arg must be numeric, not `%s'.\n"),
- "--reference-limit", progname, optarg);
+ progname, "--reference-limit", optarg);
usage (1);
}
break;
@@ -680,7 +729,7 @@ main (argc, argv)
if (set_footnote_style (optarg) < 0)
{
fprintf (stderr,
- _("%s: --footnote-style arg must be `separate' or `end', not `%s'.\n"),
+ _("%s: --footnote-style arg must be `separate' or `end', not `%s'.\n"),
progname, optarg);
usage (1);
}
@@ -692,11 +741,20 @@ main (argc, argv)
{
fprintf (stderr,
_("%s: %s arg must be numeric, not `%s'.\n"),
- "--split-size", progname, optarg);
+ progname, "--split-size", optarg);
usage (1);
}
break;
+ case 't': /* --plaintext */
+ splitting = 0;
+ no_headers = 1;
+ html = 0;
+ docbook = 0;
+ xml = 0;
+ process_plaintext = 1;
+ break;
+
case 'v':
verbose_mode++;
break;
@@ -704,21 +762,24 @@ main (argc, argv)
case 'V': /* --version */
print_version_info ();
puts ("");
- printf (_("Copyright (C) %s Free Software Foundation, Inc.\n\
-There is NO warranty. You may redistribute this software\n\
+ puts ("Copyright (C) 2004 Free Software Foundation, Inc.");
+ printf (_("There is NO warranty. You may redistribute this software\n\
under the terms of the GNU General Public License.\n\
-For more information about these matters, see the files named COPYING.\n"),
- "2003");
+For more information about these matters, see the files named COPYING.\n"));
xexit (0);
break;
case 'w': /* --html */
+ xml = 0;
+ docbook = 0;
html = 1;
process_html = 1;
break;
case 'x': /* --xml */
splitting = 0;
+ html = 0;
+ docbook = 0;
xml = 1;
process_xml = 1;
break;
@@ -729,6 +790,9 @@ For more information about these matters, see the files named COPYING.\n"),
}
}
+ if (macro_expansion_output_stream)
+ validating = 0;
+
if (!validating)
expensive_validation = 0;
@@ -746,6 +810,10 @@ For more information about these matters, see the files named COPYING.\n"),
if (no_headers)
{
+ /* If the user did not specify an output file, use stdout. */
+ if (!command_output_filename)
+ command_output_filename = xstrdup ("-");
+
if (html && splitting && !STREQ (command_output_filename, "-"))
{ /* --no-headers --no-split --html indicates confusion. */
fprintf (stderr,
@@ -756,10 +824,6 @@ For more information about these matters, see the files named COPYING.\n"),
/* --no-headers implies --no-split. */
splitting = 0;
-
- /* If the user did not specify an output file, use stdout. */
- if (!command_output_filename)
- command_output_filename = xstrdup ("-");
}
if (process_info == -1)
@@ -790,7 +854,6 @@ For more information about these matters, see the files named COPYING.\n"),
xexit (errors_printed ? 2 : 0);
return 0; /* Avoid bogus warnings. */
}
-
/* Hacking tokens and strings. */
@@ -808,8 +871,8 @@ For more information about these matters, see the files named COPYING.\n"),
&& (c) != '^' \
)
-char *
-read_token ()
+static char *
+read_token (void)
{
int i, character;
char *result;
@@ -841,8 +904,7 @@ read_token ()
/* Return nonzero if CHARACTER is self-delimiting. */
int
-self_delimiting (character)
- int character;
+self_delimiting (int character)
{
/* @; and @\ are not Texinfo commands, but they are listed here
anyway. I don't know why. --karl, 10aug96. */
@@ -851,35 +913,35 @@ self_delimiting (character)
/* Clear whitespace from the front and end of string. */
void
-canon_white (string)
- char *string;
+canon_white (char *string)
{
- int len = strlen (string);
- int x;
+ char *p = string;
+ unsigned len;
- if (!len)
+ if (!*p)
return;
- for (x = 0; x < len; x++)
+ do
{
- if (!cr_or_whitespace (string[x]))
- {
- strcpy (string, string + x);
- break;
- }
+ if (!cr_or_whitespace (*p))
+ break;
+ ++p;
}
- len = strlen (string);
- if (len)
- len--;
- while (len > -1 && cr_or_whitespace (string[len]))
- len--;
- string[len + 1] = 0;
+ while (*p);
+
+ len = strlen (p);
+ while (len && cr_or_whitespace (p[len-1]))
+ --len;
+
+ if (p != string)
+ memmove (string, p, len);
+
+ string[len] = 0;
}
/* Bash STRING, replacing all whitespace with just one space. */
void
-fix_whitespace (string)
- char *string;
+fix_whitespace (char *string)
{
char *temp = xmalloc (strlen (string) + 1);
int string_index = 0;
@@ -909,8 +971,7 @@ fix_whitespace (string)
/* Discard text until the desired string is found. The string is
included in the discarded text. */
void
-discard_until (string)
- char *string;
+discard_until (char *string)
{
int temp = search_forward (string, input_text_offset);
@@ -924,18 +985,26 @@ discard_until (string)
if (temp < 0)
{
- input_text_offset = input_text_length - strlen (string);
-
+ /* not found, move current position to end of string */
+ input_text_offset = input_text_length;
if (strcmp (string, "\n") != 0)
- {
- line_error (_("Expected `%s'"), string);
+ { /* Give a more descriptive feedback, if we are looking for ``@end ''
+ during macro execution. That means someone used a multiline
+ command as an argument to, say, @section ... style commands. */
+ char *end_block = xmalloc (8);
+ sprintf (end_block, "\n%cend ", COMMAND_PREFIX);
+ if (executing_string && strstr (string, end_block))
+ line_error (_("Multiline command %c%s used improperly"),
+ COMMAND_PREFIX, command);
+ else
+ line_error (_("Expected `%s'"), string);
+ free (end_block);
return;
}
}
else
- input_text_offset = temp;
-
- input_text_offset += strlen (string);
+ /* found, move current position to after the found string */
+ input_text_offset = temp + strlen (string);
}
/* Read characters from the file until we are at MATCH.
@@ -943,8 +1012,7 @@ discard_until (string)
On exit input_text_offset is after the match string.
Return the offset where the string starts. */
int
-get_until (match, string)
- char *match, **string;
+get_until (char *match, char **string)
{
int len, current_point, x, new_point, tem;
@@ -977,8 +1045,7 @@ get_until (match, string)
/* Replace input_text[FROM .. TO] with its expansion. */
void
-replace_with_expansion (from, to)
- int from, *to;
+replace_with_expansion (int from, int *to)
{
char *xp;
unsigned xp_len, new_len;
@@ -1054,9 +1121,7 @@ replace_with_expansion (from, to)
expand the text before looking for MATCH for those cases where
MATCH might be produced by some macro. */
void
-get_until_in_line (expand, match, string)
- int expand;
- char *match, **string;
+get_until_in_line (int expand, char *match, char **string)
{
int real_bottom = input_text_length;
int limit = search_forward ("\n", input_text_offset);
@@ -1088,9 +1153,7 @@ get_until_in_line (expand, match, string)
}
void
-get_rest_of_line (expand, string)
- int expand;
- char **string;
+get_rest_of_line (int expand, char **string)
{
xml_no_para ++;
if (expand)
@@ -1121,7 +1184,7 @@ get_rest_of_line (expand, string)
/* Backup the input pointer to the previous character, keeping track
of the current line number. */
void
-backup_input_pointer ()
+backup_input_pointer (void)
{
if (input_text_offset)
{
@@ -1134,8 +1197,7 @@ backup_input_pointer ()
/* Read characters from the file until we are at MATCH or closing brace.
Place the characters read into STRING. */
void
-get_until_in_braces (match, string)
- char *match, **string;
+get_until_in_braces (char *match, char **string)
{
char *temp;
int i, brace = 0;
@@ -1192,8 +1254,8 @@ static char *suffixes[] = {
NULL
};
-void
-initialize_conversion ()
+static void
+initialize_conversion (void)
{
init_tag_table ();
init_indices ();
@@ -1207,16 +1269,11 @@ initialize_conversion ()
output_position = 0;
}
-typedef struct generic_list {
- struct generic_list *next;
-} GENERIC_LIST;
-
/* Reverse the chain of structures in LIST. Output the new head
of the chain. You should always assign the output value of this
function to something, or you will lose the chain. */
GENERIC_LIST *
-reverse_list (list)
- GENERIC_LIST *list;
+reverse_list (GENERIC_LIST *list)
{
GENERIC_LIST *next;
GENERIC_LIST *prev = NULL;
@@ -1237,10 +1294,8 @@ reverse_list (list)
/* Convert the Texinfo file coming from the open stream STREAM. Assume the
source of the stream is named NAME. */
-void
-convert_from_stream (stream, name)
- FILE *stream;
- char *name;
+static void
+convert_from_stream (FILE *stream, char *name)
{
char *buffer = NULL;
int buffer_offset = 0, buffer_size = 0;
@@ -1287,13 +1342,15 @@ convert_from_stream (stream, name)
convert_from_loaded_file (name);
}
-void
-convert_from_file (name)
- char *name;
+static void
+convert_from_file (char *name)
{
int i;
char *filename = xmalloc (strlen (name) + 50);
+ /* Prepend file directory to the search path, so relative links work. */
+ prepend_to_include_path (pathname_part (name));
+
initialize_conversion ();
/* Try to load the file specified by NAME, concatenated with our
@@ -1304,7 +1361,7 @@ convert_from_file (name)
strcpy (filename, name);
strcat (filename, suffixes[i]);
- if (find_and_load (filename))
+ if (find_and_load (filename, 1))
break;
if (!suffixes[i][0] && strrchr (filename, '.'))
@@ -1325,6 +1382,38 @@ convert_from_file (name)
input_filename = filename;
convert_from_loaded_file (name);
+
+ /* Pop the prepended path, so multiple filenames in the
+ command line do not screw each others include paths. */
+ pop_path_from_include_path ();
+}
+
+static int
+create_html_directory (char *dir, int can_remove_file)
+{
+ struct stat st;
+
+ /* Already exists. */
+ if (stat (dir, &st) == 0)
+ {
+ /* And it's a directory, so silently reuse it. */
+ if (S_ISDIR (st.st_mode))
+ return 1;
+ /* Not a directory, so move it out of the way if we are allowed. */
+ else if (can_remove_file)
+ {
+ if (unlink (dir) != 0)
+ return 0;
+ }
+ else
+ return 0;
+ }
+
+ if (mkdir (dir, 0777) == 0)
+ /* Success! */
+ return 1;
+ else
+ return 0;
}
/* Given OUTPUT_FILENAME == ``/foo/bar/baz.html'', return
@@ -1339,13 +1428,11 @@ convert_from_file (name)
foo.whatever unchanged. */
static char *
-insert_toplevel_subdirectory (output_filename)
- char *output_filename;
+insert_toplevel_subdirectory (char *output_filename)
{
static const char index_name[] = "index.html";
char *dir, *subdir, *base, *basename, *p;
char buf[PATH_MAX];
- struct stat st;
const int index_len = sizeof (index_name) - 1;
strcpy (buf, output_filename);
@@ -1375,41 +1462,34 @@ insert_toplevel_subdirectory (output_filename)
if (strlen (dir))
strcat (output_filename, "/");
strcat (output_filename, subdir);
- if ((mkdir (output_filename, 0777) == -1 && errno != EEXIST)
- /* output_filename might exist, but be a non-directory. */
- || (stat (output_filename, &st) == 0 && !S_ISDIR (st.st_mode)))
- { /* that failed, try subdir name with .html */
+
+ /* First try, do not remove existing file. */
+ if (!create_html_directory (output_filename, 0))
+ {
+ /* That failed, try subdir name with .html.
+ Remove it if it exists. */
strcpy (output_filename, dir);
if (strlen (dir))
strcat (output_filename, "/");
strcat (output_filename, basename);
- if (mkdir (output_filename, 0777) == -1)
- {
- const char *errmsg = strerror (errno);
- if ((errno == EEXIST
-#ifdef __MSDOS__
- || errno == EACCES
-#endif
- )
- && (stat (output_filename, &st) == 0 && !S_ISDIR (st.st_mode)))
- errmsg = _("File exists, but is not a directory");
+ if (!create_html_directory (output_filename, 1))
+ {
+ /* Last try failed too :-\ */
line_error (_("Can't create directory `%s': %s"),
- output_filename, errmsg);
+ output_filename, strerror (errno));
xexit (1);
}
- strcat (output_filename, "/");
}
- else if (strlen (subdir))
- strcat (output_filename, "/");
+
+ strcat (output_filename, "/");
strcat (output_filename, index_name);
return output_filename;
}
/* FIXME: this is way too hairy */
-void
-convert_from_loaded_file (name)
- char *name;
+static void
+convert_from_loaded_file (char *name)
{
char *real_output_filename = NULL;
@@ -1476,8 +1556,6 @@ convert_from_loaded_file (name)
if (!command_output_filename)
{
get_until ("\n", &output_filename); /* read rest of line */
- if (xml && !docbook)
- xml_begin_document (output_filename);
if (html || xml)
{ /* Change any extension to .html or .xml. */
char *html_name, *directory_part, *basename_part, *temp;
@@ -1553,6 +1631,9 @@ convert_from_loaded_file (name)
set_current_output_filename (real_output_filename);
+ if (xml && !docbook)
+ xml_begin_document (filename_part (output_filename));
+
if (verbose_mode)
printf (_("Making %s file `%s' from `%s'.\n"),
no_headers ? "text"
@@ -1593,6 +1674,19 @@ convert_from_loaded_file (name)
output_filename, VERSION, input_filename);
close_paragraph ();
+
+ if (xml && !docbook)
+ {
+ /* Just before the real main loop, let's handle the defines. */
+ COMMAND_LINE_DEFINE *temp;
+
+ for (temp = command_line_defines; temp; temp = temp->next)
+ {
+ handle_variable_internal (temp->action, temp->define);
+ free(temp->define);
+ }
+ }
+
reader_loop ();
if (xml)
xml_end_document ();
@@ -1611,7 +1705,8 @@ finished:
&& FILENAME_CMP (macro_expansion_filename, NULL_DEVICE) != 0
&& FILENAME_CMP (macro_expansion_filename, ALSO_NULL_DEVICE) != 0)
{
- fprintf (stderr, _("%s: Removing macro output file `%s' due to errors; use --force to preserve.\n"),
+ fprintf (stderr,
+_("%s: Removing macro output file `%s' due to errors; use --force to preserve.\n"),
progname, macro_expansion_filename);
if (unlink (macro_expansion_filename) < 0)
perror (macro_expansion_filename);
@@ -1621,15 +1716,10 @@ finished:
if (output_stream)
{
output_pending_notes ();
- if (tag_table)
- {
- tag_table = (TAG_ENTRY *) reverse_list (tag_table);
- if (!no_headers && !html)
- write_tag_table ();
- }
if (html)
{
+ no_indent = 1;
start_paragraph ();
add_word ("</body></html>\n");
close_paragraph ();
@@ -1638,14 +1728,19 @@ finished:
/* maybe we want local variables in info output. */
{
char *trailer = info_trailer ();
- if (trailer)
+ if (!xml && !docbook && trailer)
{
+ if (html)
+ insert_string ("<!--");
insert_string (trailer);
free (trailer);
+ if (html)
+ insert_string ("\n-->\n");
}
}
- flush_output (); /* in case there was no @bye */
+ /* Write stuff makeinfo generates after @bye, ie. info_trailer. */
+ flush_output ();
if (output_stream != stdout)
fclose (output_stream);
@@ -1654,19 +1749,28 @@ finished:
if (validating)
validate_file (tag_table);
- /* If we need to output the table of contents, do it now. */
- if (contents_filename || shortcontents_filename)
- toc_update ();
+ handle_delayed_writes ();
+
+ if (tag_table)
+ {
+ tag_table = (TAG_ENTRY *) reverse_list ((GENERIC_LIST *) tag_table);
+ if (!no_headers && !html && !STREQ (current_output_filename, "-"))
+ write_tag_table (real_output_filename);
+ }
if (splitting && !html && (!errors_printed || force))
- split_file (real_output_filename, split_size);
+ {
+ clean_old_split_files (real_output_filename);
+ split_file (real_output_filename, split_size);
+ }
else if (errors_printed
&& !force
&& strcmp (real_output_filename, "-") != 0
&& FILENAME_CMP (real_output_filename, NULL_DEVICE) != 0
&& FILENAME_CMP (real_output_filename, ALSO_NULL_DEVICE) != 0)
{ /* If there were errors, and no --force, remove the output. */
- fprintf (stderr, _("%s: Removing output file `%s' due to errors; use --force to preserve.\n"),
+ fprintf (stderr,
+ _("%s: Removing output file `%s' due to errors; use --force to preserve.\n"),
progname, real_output_filename);
if (unlink (real_output_filename) < 0)
perror (real_output_filename);
@@ -1674,33 +1778,35 @@ finished:
}
free (real_output_filename);
}
-
-
-/* If enable_encoding and document_encoding are both set, return a Local
- Variables section (as a malloc-ed string) so that Emacs' locale
- features can work. Else return NULL. */
-
+/* If enable_encoding is set and @documentencoding is used, return a
+ Local Variables section (as a malloc-ed string) so that Emacs'
+ locale features can work. Else return NULL. */
char *
-info_trailer ()
+info_trailer (void)
{
- if (!enable_encoding || document_encoding_code <= US_ASCII)
+ char *encoding;
+
+ if (!enable_encoding)
return NULL;
- {
-#define LV_FMT "\n\037\nLocal Variables:\ncoding: %s\nEnd:\n"
- char *enc_name = encoding_table[document_encoding_code].encname;
- char *lv = xmalloc (sizeof (LV_FMT) + strlen (enc_name));
- sprintf (lv, LV_FMT, enc_name);
- return lv;
- }
-}
+ encoding = current_document_encoding ();
+ if (encoding && *encoding)
+ {
+#define LV_FMT "\n\037\nLocal Variables:\ncoding: %s\nEnd:\n"
+ char *lv = xmalloc (sizeof (LV_FMT) + strlen (encoding));
+ sprintf (lv, LV_FMT, encoding);
+ free (encoding);
+ return lv;
+ }
+ free (encoding);
+ return NULL;
+}
void
-free_and_clear (pointer)
- char **pointer;
+free_and_clear (char **pointer)
{
if (*pointer)
{
@@ -1710,8 +1816,8 @@ free_and_clear (pointer)
}
/* Initialize some state. */
-void
-init_internals ()
+static void
+init_internals (void)
{
free_and_clear (&output_filename);
free_and_clear (&command);
@@ -1731,9 +1837,9 @@ init_internals ()
}
void
-init_paragraph ()
+init_paragraph (void)
{
- free_and_clear (&output_paragraph);
+ free (output_paragraph);
output_paragraph = xmalloc (paragraph_buffer_len);
output_paragraph[0] = 0;
output_paragraph_offset = 0;
@@ -1747,7 +1853,7 @@ init_paragraph ()
menu line. */
static void
-handle_menu_entry ()
+handle_menu_entry (void)
{
char *tem;
@@ -1773,23 +1879,21 @@ handle_menu_entry ()
if (had_menu_commentary)
{
- add_word ("<ul class=\"menu\">\n");
+ add_html_block_elt ("<ul class=\"menu\">\n");
had_menu_commentary = 0;
in_paragraph = 0;
}
- else if (!in_paragraph && !paragraph_is_open)
- {
- add_word ("<p>\n");
- in_paragraph = 1;
- }
if (in_paragraph)
{
- add_word ("</p>");
+ add_html_block_elt ("</p>\n");
+ add_html_block_elt ("<ul class=\"menu\">\n");
in_paragraph = 0;
}
- add_word ("<li><a");
+ in_menu_item = 1;
+
+ add_html_block_elt ("<li><a");
if (next_menu_item_number <= 9)
{
add_word(" accesskey=");
@@ -1819,7 +1923,18 @@ handle_menu_entry ()
free (string);
}
input_text_offset++; /* discard the second colon or the period */
- add_word (": ");
+
+ /* Insert a colon only if there is a description of this menu item. */
+ {
+ int save_input_text_offset = input_text_offset;
+ int save_line_number = line_number;
+ char *test_string;
+ get_rest_of_line (0, &test_string);
+ if (strlen (test_string) > 0)
+ add_word (": ");
+ input_text_offset = save_input_text_offset;
+ line_number = save_line_number;
+ }
}
else if (xml && tem)
{
@@ -1840,8 +1955,7 @@ handle_menu_entry ()
/* Find the command corresponding to STRING. If the command is found,
return a pointer to the data structure. Otherwise return -1. */
static COMMAND *
-get_command_entry (string)
- char *string;
+get_command_entry (char *string)
{
int i;
@@ -1864,7 +1978,7 @@ get_command_entry (string)
Read the next token to determine what to do. Return zero
if there's no known command or macro after the prefix character. */
static int
-read_command ()
+read_command (void)
{
COMMAND *entry;
int old_text_offset = input_text_offset++;
@@ -1894,7 +2008,7 @@ read_command ()
return 1;
}
- }
+ }
if (only_macro_expansion)
{
@@ -1970,11 +2084,10 @@ read_command ()
the function with the proper arguments. Although the filling isn't
necessary for HTML, it should do no harm. */
void
-reader_loop ()
+reader_loop (void)
{
int character;
int done = 0;
- int dash_count = 0;
while (!done)
{
@@ -1986,25 +2099,79 @@ reader_loop ()
/* If only_macro_expansion, only handle macros and leave
everything else intact. */
if (!only_macro_expansion && !in_fixed_width_font
+ && ((!html && !xml) || escape_html)
&& (character == '\'' || character == '`')
&& input_text[input_text_offset + 1] == character)
{
- input_text_offset++;
- character = '"'; /* html fixxme */
+ if (html)
+ {
+ input_text_offset += 2;
+ add_word (character == '`' ? "&ldquo;" : "&rdquo;");
+ continue;
+ }
+ else if (xml)
+ {
+ input_text_offset += 2;
+ xml_insert_entity (character == '`' ? "ldquo" : "rdquo");
+ continue;
+ }
+ else
+ {
+ input_text_offset++;
+ character = '"';
+ }
}
/* Convert --- to --. */
- if (!only_macro_expansion && character == '-')
+ if (!only_macro_expansion && character == '-' && !in_fixed_width_font
+ && ((!html && !xml) || escape_html))
{
- dash_count++;
- if (dash_count == 2 && !in_fixed_width_font)
+ int dash_count = 0;
+
+ /* Get the number of consequtive dashes. */
+ while (input_text[input_text_offset] == '-')
{
+ dash_count++;
input_text_offset++;
- continue;
}
+
+ /* Eat one dash. */
+ dash_count--;
+
+ if (html || xml)
+ {
+ if (dash_count == 0)
+ add_char ('-');
+ else
+ while (dash_count > 0)
+ {
+ if (dash_count >= 2)
+ {
+ if (html)
+ add_word ("&mdash;");
+ else
+ xml_insert_entity ("mdash");
+ dash_count -= 2;
+ }
+ else if (dash_count >= 1)
+ {
+ if (html)
+ add_word ("&ndash;");
+ else
+ xml_insert_entity ("ndash");
+ dash_count--;
+ }
+ }
+ }
+ else
+ {
+ add_char ('-');
+ while (--dash_count > 0)
+ add_char ('-');
+ }
+
+ continue;
}
- else if (dash_count > 0)
- dash_count = 0;
/* If this is a whitespace character, then check to see if the line
is blank. If so, advance to the carriage return. */
@@ -2094,10 +2261,8 @@ reader_loop ()
remember_brace (misplaced_brace);
}
else
- { /* We don't mind `extra' braces inside @math. */
- extern void cm_no_op ();
- remember_brace (cm_no_op);
- }
+ /* We don't mind `extra' braces inside @math. */
+ remember_brace (cm_no_op);
/* remember_brace advances input_text_offset. */
break;
}
@@ -2121,29 +2286,16 @@ reader_loop ()
maybe_write_itext (input_text, input_text_offset);
}
-void
-init_brace_stack ()
+static void
+init_brace_stack (void)
{
brace_stack = NULL;
}
-void
-remember_brace (proc)
- COMMAND_FUNCTION *proc;
-{
- if (curchar () != '{')
- line_error (_("%c%s expected braces"), COMMAND_PREFIX, command);
- else
- input_text_offset++;
- remember_brace_1 (proc, output_paragraph_offset);
-}
-
/* Remember the current output position here. Save PROC
along with it so you can call it later. */
-void
-remember_brace_1 (proc, position)
- COMMAND_FUNCTION *proc;
- int position;
+static void
+remember_brace_1 (COMMAND_FUNCTION (*proc), int position)
{
BRACE_ELEMENT *new = xmalloc (sizeof (BRACE_ELEMENT));
new->next = brace_stack;
@@ -2155,10 +2307,20 @@ remember_brace_1 (proc, position)
brace_stack = new;
}
+static void
+remember_brace (COMMAND_FUNCTION (*proc))
+{
+ if (curchar () != '{')
+ line_error (_("%c%s expected braces"), COMMAND_PREFIX, command);
+ else
+ input_text_offset++;
+ remember_brace_1 (proc, output_paragraph_offset);
+}
+
/* Pop the top of the brace stack, and call the associated function
with the args END and POS. */
-void
-pop_and_call_brace ()
+static void
+pop_and_call_brace (void)
{
if (brace_stack == NULL)
{
@@ -2186,9 +2348,8 @@ pop_and_call_brace ()
}
/* Shift all of the markers in `brace_stack' by AMOUNT. */
-void
-adjust_braces_following (here, amount)
- int here, amount;
+static void
+adjust_braces_following (int here, int amount)
{
BRACE_ELEMENT *stack = brace_stack;
@@ -2204,8 +2365,7 @@ adjust_braces_following (here, amount)
Always returns the first function in the command table if more than
one matches PROC. */
static const char *
-find_proc_name (proc)
- COMMAND_FUNCTION *proc;
+find_proc_name (COMMAND_FUNCTION (*proc))
{
int i;
@@ -2220,7 +2380,7 @@ find_proc_name (proc)
in braces, but that was wrong because of things like @code{foo @@}. So now
I only detect it at the beginning of nodes. */
void
-discard_braces ()
+discard_braces (void)
{
if (!brace_stack)
return;
@@ -2247,9 +2407,8 @@ discard_braces ()
}
}
-int
-get_char_len (character)
- int character;
+static int
+get_char_len (int character)
{
/* Return the printed length of the character. */
int len;
@@ -2307,8 +2466,7 @@ add_word_args (format, va_alist)
/* Add STRING to output_paragraph. */
void
-add_word (string)
- char *string;
+add_word (char *string)
{
while (*string)
add_char (*string++);
@@ -2318,14 +2476,49 @@ add_word (string)
Use this to output HTML directives with embedded blanks, to make
them @w-safe. */
void
-add_html_elt (string)
- char *string;
+add_html_elt (char *string)
{
in_html_elt++;
add_word (string);
in_html_elt--;
}
+/* These two functions below, add_html_block_elt and add_html_block_elt_args,
+ are mixtures of add_html_elt and add_word_args. They inform makeinfo that
+ the current HTML element being inserted should not be enclosed in a <p>
+ element. */
+void
+add_html_block_elt (char *string)
+{
+ in_html_block_level_elt++;
+ add_word (string);
+ in_html_block_level_elt--;
+}
+
+void
+#if defined (VA_FPRINTF) && __STDC__
+add_html_block_elt_args (const char *format, ...)
+#else
+add_html_block_elt_args (format, va_alist)
+ const char *format;
+ va_dcl
+#endif
+{
+ char buffer[2000]; /* xx no fixed limits */
+#ifdef VA_FPRINTF
+ va_list ap;
+#endif
+
+ VA_START (ap, format);
+#ifdef VA_SPRINTF
+ VA_SPRINTF (buffer, format, ap);
+#else
+ sprintf (buffer, format, a1, a2, a3, a4, a5, a6, a7, a8);
+#endif /* not VA_SPRINTF */
+ va_end (ap);
+ add_html_block_elt (buffer);
+}
+
/* Here is another awful kludge, used in add_char. Ordinarily, macro
expansions take place in the body of the document, and therefore we
should html_output_head when we see one. But there's an exception: a
@@ -2335,7 +2528,7 @@ add_html_elt (string)
So we need to be able to check if we are defining the @copying text.
We do this by looking back through the insertion stack. */
static int
-defining_copying ()
+defining_copying (void)
{
INSERTION_ELT *i;
for (i = insertion_stack; i; i = i->next)
@@ -2350,8 +2543,7 @@ defining_copying ()
/* Add the character to the current paragraph. If filling_enabled is
nonzero, then do filling as well. */
void
-add_char (character)
- int character;
+add_char (int character)
{
if (xml)
{
@@ -2463,6 +2655,7 @@ add_char (character)
any order and with any omissions, and we'll still output
the html <head> `just in time'. */
if ((executing_macro || !executing_string)
+ && !only_macro_expansion
&& html && !html_output_head_p && !defining_copying ())
html_output_head ();
@@ -2476,12 +2669,16 @@ add_char (character)
indent (pending_indent);
pending_indent = 0;
- /* This horrible kludge of checking for a < prevents <p>
- from being inserted when we already have html markup
- starting a paragraph, as with <ul> and <h1> and the like. */
- if ((html || xml) && escape_html && character != '<'
- && (!in_fixed_width_font || in_menu || in_detailmenu))
+ /* This check for in_html_block_level_elt prevents <p> from being
+ inserted when we already have html markup starting a paragraph,
+ as with <ul> and <h1> and the like. */
+ if (html && !in_html_block_level_elt)
{
+ if ((in_menu || in_detailmenu) && in_menu_item)
+ {
+ insert_string ("</li></ul>\n");
+ in_menu_item = 0;
+ }
insert_string ("<p>");
in_paragraph = 1;
adjust_braces_following (0, 3); /* adjust for <p> */
@@ -2536,9 +2733,9 @@ add_char (character)
if (t1 != temp)
{
adjust_braces_following (temp, (- (t1 - temp)));
- strncpy ((char *) &output_paragraph[temp],
- (char *) &output_paragraph[t1],
- (output_paragraph_offset - t1));
+ memmove (&output_paragraph[temp],
+ &output_paragraph[t1],
+ output_paragraph_offset - t1);
output_paragraph_offset -= (t1 - temp);
}
}
@@ -2600,8 +2797,7 @@ add_char (character)
/* Add a character and store its position in meta_char_pos. */
void
-add_meta_char (character)
- int character;
+add_meta_char (int character)
{
meta_char_pos = output_paragraph_offset;
add_char (character);
@@ -2609,9 +2805,19 @@ add_meta_char (character)
/* Insert CHARACTER into `output_paragraph'. */
void
-insert (character)
- int character;
+insert (int character)
{
+ /* We don't want to strip trailing whitespace in multitables. Otherwise
+ horizontal separators confuse the font locking in Info mode in Emacs,
+ because it looks like a @subsection. Adding a trailing space to those
+ lines fixes it. */
+ if (character == '\n' && !html && !xml && !multitable_active)
+ {
+ while (output_paragraph_offset
+ && whitespace (output_paragraph[output_paragraph_offset-1]))
+ output_paragraph_offset--;
+ }
+
output_paragraph[output_paragraph_offset++] = character;
if (output_paragraph_offset == paragraph_buffer_len)
{
@@ -2622,8 +2828,7 @@ insert (character)
/* Insert the null-terminated string STRING into `output_paragraph'. */
void
-insert_string (string)
- char *string;
+insert_string (const char *string)
{
while (*string)
insert (*string++);
@@ -2637,7 +2842,7 @@ insert_string (string)
/* Return true if at an end-of-sentence character, possibly followed by
post-sentence punctuation to ignore. */
static int
-end_of_sentence_p ()
+end_of_sentence_p (void)
{
int loc = output_paragraph_offset - 1;
@@ -2660,8 +2865,7 @@ end_of_sentence_p ()
the current output line. If COUNT is less than zero,
then remove until none left. */
void
-kill_self_indent (count)
- int count;
+kill_self_indent (int count)
{
/* Handle infinite case first. */
if (count < 0)
@@ -2690,20 +2894,20 @@ static int flushing_ignored = 0;
/* Prevent calls to flush_output () from having any effect. */
void
-inhibit_output_flushing ()
+inhibit_output_flushing (void)
{
flushing_ignored++;
}
/* Allow calls to flush_output () to write the paragraph data. */
void
-uninhibit_output_flushing ()
+uninhibit_output_flushing (void)
{
flushing_ignored--;
}
void
-flush_output ()
+flush_output (void)
{
int i;
@@ -2712,6 +2916,12 @@ flush_output ()
for (i = 0; i < output_paragraph_offset; i++)
{
+ if (output_paragraph[i] == '\n')
+ {
+ output_line_number++;
+ node_line_number++;
+ }
+
/* If we turned on the 8th bit for a space inside @w, turn it
back off for output. This might be problematic, since the
0x80 character may be used in 8-bit character sets. Sigh.
@@ -2741,8 +2951,7 @@ flush_output ()
int paragraph_spacing = DEFAULT_PARAGRAPH_SPACING;
static void
-close_paragraph_with_lines (lines)
- int lines;
+close_paragraph_with_lines (int lines)
{
int old_spacing = paragraph_spacing;
paragraph_spacing = lines;
@@ -2752,14 +2961,14 @@ close_paragraph_with_lines (lines)
/* Close the current paragraph, leaving no blank lines between them. */
void
-close_single_paragraph ()
+close_single_paragraph (void)
{
close_paragraph_with_lines (0);
}
/* Close a paragraph after an insertion has ended. */
void
-close_insertion_paragraph ()
+close_insertion_paragraph (void)
{
if (!insertion_paragraph_closed)
{
@@ -2795,18 +3004,21 @@ close_insertion_paragraph ()
/* Close the currently open paragraph. */
void
-close_paragraph ()
+close_paragraph (void)
{
int i;
+ /* We don't need these newlines in XML and Docbook outputs for
+ paragraph seperation. We have <para> element for that. */
+ if (xml)
+ return;
+
/* The insertion paragraph is no longer closed. */
insertion_paragraph_closed = 0;
if (paragraph_is_open && !must_start_paragraph)
{
- int tindex, c;
-
- tindex = output_paragraph_offset;
+ int tindex = output_paragraph_offset;
/* Back up to last non-newline/space character, forcing all such
subsequent characters to be newlines. This isn't strictly
@@ -2814,7 +3026,7 @@ close_paragraph ()
to make decisions. */
for (tindex = output_paragraph_offset - 1; tindex >= 0; --tindex)
{
- c = output_paragraph[tindex];
+ int c = output_paragraph[tindex];
if (c == ' '|| c == '\n')
output_paragraph[tindex] = '\n';
@@ -2858,15 +3070,15 @@ close_paragraph ()
/* Make the last line just read look as if it were only a newline. */
void
-ignore_blank_line ()
+ignore_blank_line (void)
{
last_inserted_character = '\n';
last_char_was_newline = 1;
}
/* Align the end of the text in output_paragraph with fill_column. */
-void
-do_flush_right_indentation ()
+static void
+do_flush_right_indentation (void)
{
char *temp;
int temp_len;
@@ -2903,7 +3115,7 @@ do_flush_right_indentation ()
/* Begin a new paragraph. */
void
-start_paragraph ()
+start_paragraph (void)
{
/* First close existing one. */
if (paragraph_is_open)
@@ -2950,8 +3162,7 @@ start_paragraph ()
/* Insert the indentation specified by AMOUNT. */
void
-indent (amount)
- int amount;
+indent (int amount)
{
/* For every START_POS saved within the brace stack which will be affected
by this indentation, bump that start pos forward. */
@@ -2964,9 +3175,7 @@ indent (amount)
/* Search forward for STRING in input_text.
FROM says where where to start. */
int
-search_forward (string, from)
- char *string;
- int from;
+search_forward (char *string, int from)
{
int len = strlen (string);
@@ -2978,518 +3187,64 @@ search_forward (string, from)
}
return -1;
}
-
-/* Cross references. */
-
-/* Return next comma-delimited argument, but do not cross a close-brace
- boundary. Clean up whitespace, too. If EXPAND is nonzero, replace
- the entire brace-delimited argument list with its expansion before
- looking for the next comma. */
-char *
-get_xref_token (expand)
- int expand;
-{
- char *string;
-
- if (docbook)
- xml_in_xref_token = 1;
-
- if (expand)
- {
- int old_offset = input_text_offset;
- int old_lineno = line_number;
-
- get_until_in_braces ("}", &string);
- if (curchar () == '}') /* as opposed to end of text */
- input_text_offset++;
- if (input_text_offset > old_offset)
- {
- int limit = input_text_offset;
-
- input_text_offset = old_offset;
- line_number = old_lineno;
- only_macro_expansion++;
- replace_with_expansion (input_text_offset, &limit);
- only_macro_expansion--;
- }
- free (string);
- }
-
- get_until_in_braces (",", &string);
- if (curchar () == ',')
- input_text_offset++;
- fix_whitespace (string);
-
- if (docbook)
- xml_in_xref_token = 0;
-
- return string;
-}
-/* NOTE: If you wonder why the HTML output is produced with such a
- peculiar mix of calls to add_word and execute_string, here's the
- reason. get_xref_token (1) expands all macros in a reference, but
- any other commands, like @value, @@, etc., are left intact. To
- expand them, we need to run the arguments through execute_string.
- However, characters like <, &, > and others cannot be let into
- execute_string, because they will be escaped. See the mess? */
-
-/* Make a cross reference. */
-void
-cm_xref (arg)
+/* search_forward until n characters. */
+int
+search_forward_until_pos (char *string, int from, int end_pos)
{
- if (arg == START)
- {
- char *arg1 = get_xref_token (1); /* expands all macros in xref */
- char *arg2 = get_xref_token (0);
- char *arg3 = get_xref_token (0);
- char *arg4 = get_xref_token (0);
- char *arg5 = get_xref_token (0);
- char *tem;
-
- /* "@xref{,Foo,, Bar, Baz} is not valid usage of @xref. The
- first argument must never be blank." --rms.
- We hereby comply by disallowing such constructs. */
- if (!*arg1)
- line_error (_("First argument to cross-reference may not be empty"));
-
- if (xml && docbook)
- {
- if (!*arg4 && !*arg5)
- {
- char *arg1_id = xml_id (arg1);
- if (*arg2)
- {
- xml_insert_element_with_attribute (XREFNODENAME, START,
- "linkend=\"%s\"", arg1_id);
- free (arg1_id);
- if (*arg2)
- execute_string (arg2);
- xml_insert_element (XREFNODENAME, END);
- }
- else
- {
- xml_insert_element_with_attribute (XREF, START,
- "linkend=\"%s\"", arg1_id);
- free (arg1_id);
- xml_pop_current_element ();
- }
- }
- }
- else if (xml)
- {
- xml_insert_element (XREF, START);
- xml_insert_element (XREFNODENAME, START);
- execute_string (arg1);
- xml_insert_element (XREFNODENAME, END);
- if (*arg2)
- {
- xml_insert_element (XREFINFONAME, START);
- execute_string (arg2);
- xml_insert_element (XREFINFONAME, END);
- }
- if (*arg3)
- {
- xml_insert_element (XREFPRINTEDDESC, START);
- execute_string (arg3);
- xml_insert_element (XREFPRINTEDDESC, END);
- }
- if (*arg4)
- {
- xml_insert_element (XREFINFOFILE, START);
- execute_string (arg4);
- xml_insert_element (XREFINFOFILE, END);
- }
- if (*arg5)
- {
- xml_insert_element (XREFPRINTEDNAME, START);
- execute_string (arg5);
- xml_insert_element (XREFPRINTEDNAME, END);
- }
- xml_insert_element (XREF, END);
- }
- else if (html)
- {
- if (!ref_flag)
- add_word_args ("%s", px_ref_flag ? _("see ") : _("See "));
- }
- else
- add_word_args ("%s", px_ref_flag ? "*note " : "*Note ");
-
- if (!xml)
- {
- if (*arg5 || *arg4)
- {
- /* arg1 - node name
- arg2 - reference name
- arg3 - title or topic (and reference name if arg2 is NULL)
- arg4 - info file name
- arg5 - printed manual title */
- char *ref_name;
-
- if (!*arg2)
- {
- if (*arg3)
- ref_name = arg3;
- else
- ref_name = arg1;
- }
- else
- ref_name = arg2;
-
- if (html)
- {
- /* html fixxme: revisit this; external node name not
- much use to us with numbered nodes. */
- add_html_elt ("<a href=");
- /* Note that if we are splitting, and the referenced
- tag is an anchor rather than a node, we will
- produce a reference to a file whose name is
- derived from the anchor name. However, only
- nodes create files, so we are referencing a
- non-existent file. cm_anchor, which see, deals
- with that problem. */
- if (splitting)
- execute_string ("\"../%s/", arg4);
- else
- execute_string ("\"%s.html", arg4);
- /* Do not collapse -- to -, etc., in references. */
- in_fixed_width_font++;
- tem = expansion (arg1, 0); /* expand @-commands in node */
- in_fixed_width_font--;
- add_anchor_name (tem, 1);
- free (tem);
- add_word ("\">");
- execute_string ("%s", ref_name);
- add_word ("</a>");
- }
- else
- {
- execute_string ("%s:", ref_name);
- in_fixed_width_font++;
- execute_string (" (%s)%s%s", arg4, arg1, px_ref_flag ? "." : "");
- in_fixed_width_font--;
- }
+ int save_input_text_length = input_text_length;
+ input_text_length = end_pos;
- /* Free all of the arguments found. */
- if (arg1) free (arg1);
- if (arg2) free (arg2);
- if (arg3) free (arg3);
- if (arg4) free (arg4);
- if (arg5) free (arg5);
- return;
- }
- else
- remember_node_reference (arg1, line_number, followed_reference);
+ from = search_forward (string, from);
- if (*arg3)
- {
- if (html)
- {
- add_html_elt ("<a href=\"");
- in_fixed_width_font++;
- tem = expansion (arg1, 0);
- in_fixed_width_font--;
- add_anchor_name (tem, 1);
- free (tem);
- add_word ("\">");
- execute_string ("%s", *arg2 ? arg2 : arg3);
- add_word ("</a>");
- }
- else
- {
- execute_string ("%s:", *arg2 ? arg2 : arg3);
- in_fixed_width_font++;
- execute_string (" %s%s", arg1, px_ref_flag ? "." : "");
- in_fixed_width_font--;
- }
- }
- else
- {
- if (html)
- {
- add_html_elt ("<a href=\"");
- in_fixed_width_font++;
- tem = expansion (arg1, 0);
- in_fixed_width_font--;
- add_anchor_name (tem, 1);
- free (tem);
- add_word ("\">");
- execute_string ("%s", *arg2 ? arg2 : arg1);
- add_word ("</a>");
- }
- else
- {
- if (*arg2)
- {
- execute_string ("%s:", arg2);
- in_fixed_width_font++;
- execute_string (" %s%s", arg1, px_ref_flag ? "." : "");
- in_fixed_width_font--;
- }
- else
- {
- in_fixed_width_font++;
- execute_string ("%s::", arg1);
- in_fixed_width_font--;
- }
- }
- }
- }
- /* Free all of the arguments found. */
- if (arg1) free (arg1);
- if (arg2) free (arg2);
- if (arg3) free (arg3);
- if (arg4) free (arg4);
- if (arg5) free (arg5);
- }
- else
- { /* Check to make sure that the next non-whitespace character is
- valid to follow an xref (so info readers can find the node
- names). `input_text_offset' is pointing at the "}" which ended
- the xref or ref command. */
- int temp;
+ input_text_length = save_input_text_length;
- for (temp = input_text_offset + 1; temp < input_text_length; )
- {
- if (cr_or_whitespace (input_text[temp]))
- temp++;
- else
- {
- if (input_text[temp] != '.' && input_text[temp] != ',')
- warning (_("`.' or `,' must follow cross reference, not %c"),
- input_text[temp]);
- break;
- }
- }
- }
+ return from;
}
-void
-cm_pxref (arg)
- int arg;
-{
- if (arg == START)
- {
- px_ref_flag++;
- cm_xref (arg);
- px_ref_flag--;
- }
- /* Note that cm_xref isn't called with arg == END, which disables
- the code near the end of cm_xref that checks for `.' or `,'
- after the cross-reference. This is because @pxref{} generates
- the required character itself, when needed. */
-}
-
-void
-cm_ref (arg)
- int arg;
+/* Return next non-whitespace and non-cr character. */
+int
+next_nonwhitespace_character (void)
{
- if (arg == START)
- {
- ref_flag++;
- cm_xref (arg);
- ref_flag--;
- }
-}
+ /* First check the current input_text. Start from the next char because
+ we already have input_text[input_text_offset] in ``current''. */
+ int pos = input_text_offset + 1;
-void
-cm_inforef (arg)
- int arg;
-{
- if (arg == START)
+ while (pos < input_text_length)
{
- char *node = get_xref_token (1); /* expands all macros in inforef */
- char *pname = get_xref_token (0);
- char *file = get_xref_token (0);
-
- /* (see comments at cm_xref). */
- if (!*node)
- line_error (_("First argument to @inforef may not be empty"));
-
- if (xml && !docbook)
- {
- xml_insert_element (INFOREF, START);
- xml_insert_element (INFOREFNODENAME, START);
- execute_string (node);
- xml_insert_element (INFOREFNODENAME, END);
- if (*pname)
- {
- xml_insert_element (INFOREFREFNAME, START);
- execute_string (pname);
- xml_insert_element (INFOREFREFNAME, END);
- }
- xml_insert_element (INFOREFINFONAME, START);
- execute_string (file);
- xml_insert_element (INFOREFINFONAME, END);
-
- xml_insert_element (INFOREF, END);
- }
- else if (html)
- {
- char *tem;
-
- add_word (_("see "));
- /* html fixxme: revisit this */
- add_html_elt ("<a href=");
- if (splitting)
- execute_string ("\"../%s/", file);
- else
- execute_string ("\"%s.html", file);
- tem = expansion (node, 0);
- add_anchor_name (tem, 1);
- add_word ("\">");
- execute_string ("%s", *pname ? pname : tem);
- add_word ("</a>");
- free (tem);
- }
- else
- {
- if (*pname)
- execute_string ("*note %s: (%s)%s", pname, file, node);
- else
- execute_string ("*note (%s)%s::", file, node);
- }
-
- free (node);
- free (pname);
- free (file);
+ if (!cr_or_whitespace(input_text[pos]))
+ return input_text[pos];
+ pos++;
}
-}
-/* A URL reference. */
-void
-cm_uref (arg)
- int arg;
-{
- if (arg == START)
- {
- extern int printing_index;
- char *url = get_xref_token (1); /* expands all macros in uref */
- char *desc = get_xref_token (0);
- char *replacement = get_xref_token (0);
+ { /* Can't find a valid character, so go through filestack
+ in case we are doing @include or expanding a macro. */
+ FSTACK *tos = filestack;
- if (xml)
- {
- xml_insert_element (UREF, START);
- xml_insert_element (UREFURL, START);
- execute_string (url);
- xml_insert_element (UREFURL, END);
- if (*desc)
- {
- xml_insert_element (UREFDESC, START);
- execute_string (desc);
- xml_insert_element (UREFDESC, END);
- }
- if (*replacement)
- {
- xml_insert_element (UREFREPLACEMENT, START);
- execute_string (replacement);
- xml_insert_element (UREFREPLACEMENT, END);
- }
- xml_insert_element (UREF, END);
- }
- else if (html)
- { /* never need to show the url */
- add_html_elt ("<a href=");
- /* don't collapse `--' etc. in the url */
- in_fixed_width_font++;
- execute_string ("\"%s\"", url);
- in_fixed_width_font--;
- add_word (">");
- execute_string ("%s", *replacement ? replacement
- : (*desc ? desc : url));
- add_word ("</a>");
- }
- else if (*replacement) /* do not show the url */
- execute_string ("%s", replacement);
- else if (*desc) /* show both text and url */
- {
- execute_string ("%s ", desc);
- in_fixed_width_font++;
- execute_string ("(%s)", url);
- in_fixed_width_font--;
- }
- else /* no text at all, so have the url to show */
- {
- in_fixed_width_font++;
- execute_string ("%s%s%s",
- printing_index ? "" : "`",
- url,
- printing_index ? "" : "'");
- in_fixed_width_font--;
- }
- if (url)
- free (url);
- if (desc)
- free (desc);
- if (replacement)
- free (replacement);
- }
-}
+ while (tos)
+ {
+ int tmp_input_text_length = filestack->size;
+ int tmp_input_text_offset = filestack->offset;
+ char *tmp_input_text = filestack->text;
-/* An email reference. */
-void
-cm_email (arg)
- int arg;
-{
- if (arg == START)
- {
- char *addr = get_xref_token (1); /* expands all macros in email */
- char *name = get_xref_token (0);
+ while (tmp_input_text_offset < tmp_input_text_length)
+ {
+ if (!cr_or_whitespace(tmp_input_text[tmp_input_text_offset]))
+ return tmp_input_text[tmp_input_text_offset];
+ tmp_input_text_offset++;
+ }
- if (xml && docbook)
- {
- xml_insert_element_with_attribute (EMAIL, START, "url=\"mailto:%s\"", addr);
- if (*name)
- execute_string (name);
- xml_insert_element (EMAIL, END);
- }
- else if (xml)
- {
- xml_insert_element (EMAIL, START);
- xml_insert_element (EMAILADDRESS, START);
- execute_string (addr);
- xml_insert_element (EMAILADDRESS, END);
- if (*name)
- {
- xml_insert_element (EMAILNAME, START);
- execute_string (name);
- xml_insert_element (EMAILNAME, END);
- }
- xml_insert_element (EMAIL, END);
- }
- else if (html)
- {
- add_html_elt ("<a href=");
- /* don't collapse `--' etc. in the address */
- in_fixed_width_font++;
- execute_string ("\"mailto:%s\"", addr);
- in_fixed_width_font--;
- add_word (">");
- execute_string ("%s", *name ? name : addr);
- add_word ("</a>");
- }
- else
- {
- execute_string ("%s%s", name, *name ? " " : "");
- in_fixed_width_font++;
- execute_string ("<%s>", addr);
- in_fixed_width_font--;
- }
+ tos = tos->next;
+ }
+ }
- if (addr)
- free (addr);
- if (name)
- free (name);
- }
+ return -1;
}
-
+
/* An external image is a reference, kind of. The parsing is (not
coincidentally) similar, anyway. */
void
-cm_image (arg)
- int arg;
+cm_image (int arg)
{
char *name_arg, *w_arg, *h_arg, *alt_arg, *ext_arg;
@@ -3507,34 +3262,48 @@ cm_image (arg)
struct stat file_info;
char *pathname = NULL;
char *fullname = xmalloc (strlen (name_arg)
- + (ext_arg && *ext_arg ? strlen (ext_arg) + 1 : 4) + 1);
+ + (ext_arg && *ext_arg ? strlen (ext_arg) + 1: 4) + 1);
if (ext_arg && *ext_arg)
{
- sprintf (fullname, "%s.%s", name_arg, ext_arg);
+ sprintf (fullname, "%s%s", name_arg, ext_arg);
if (access (fullname, R_OK) != 0)
pathname = get_file_info_in_path (fullname, include_files_path,
&file_info);
+
+ if (pathname == NULL)
+ {
+ /* Backwards compatibility (4.6 <= version < 4.7):
+ try prefixing @image's EXTENSION parameter with a period. */
+ sprintf (fullname, "%s.%s", name_arg, ext_arg);
+ if (access (fullname, R_OK) != 0)
+ pathname = get_file_info_in_path (fullname, include_files_path,
+ &file_info);
+ }
}
else
{
sprintf (fullname, "%s.png", name_arg);
- if (access (fullname, R_OK) != 0)
- {
- pathname = get_file_info_in_path (fullname,
- include_files_path, &file_info);
- if (pathname == NULL)
- {
- sprintf (fullname, "%s.jpg", name_arg);
- if (access (fullname, R_OK) != 0)
- pathname = get_file_info_in_path (fullname,
+ if (access (fullname, R_OK) != 0) {
+ pathname = get_file_info_in_path (fullname,
+ include_files_path, &file_info);
+ if (pathname == NULL) {
+ sprintf (fullname, "%s.jpg", name_arg);
+ if (access (fullname, R_OK) != 0) {
+ sprintf (fullname, "%s.gif", name_arg);
+ if (access (fullname, R_OK) != 0) {
+ pathname = get_file_info_in_path (fullname,
include_files_path, &file_info);
}
+ }
}
+ }
}
if (html)
{
+ int image_in_div = 0;
+
if (pathname == NULL && access (fullname, R_OK) != 0)
{
line_error(_("@image file `%s' (for HTML) not readable: %s"),
@@ -3548,19 +3317,42 @@ cm_image (arg)
return;
}
+ if (!paragraph_is_open)
+ {
+ add_html_block_elt ("<div class=\"block-image\">");
+ image_in_div = 1;
+ }
+
add_html_elt ("<img src=");
add_word_args ("\"%s\"", fullname);
add_html_elt (" alt=");
- add_word_args ("\"%s\">", (*alt_arg) ? alt_arg : fullname);
+ add_word_args ("\"%s\">",
+ escape_string (*alt_arg ? text_expansion (alt_arg) : fullname));
+
+ if (image_in_div)
+ add_html_block_elt ("</div>");
}
else if (xml && docbook)
xml_insert_docbook_image (name_arg);
else if (xml)
{
- xml_insert_element_with_attribute (IMAGE, START, "width=\"%s\" height=\"%s\" alttext=\"%s\" extension=\"%s\"",
- w_arg, h_arg, alt_arg, ext_arg);
- add_word (name_arg);
- xml_insert_element (IMAGE, END);
+ extern int xml_in_para;
+ extern int xml_no_para;
+ int elt = xml_in_para ? INLINEIMAGE : IMAGE;
+
+ if (!xml_in_para)
+ xml_no_para++;
+
+ xml_insert_element_with_attribute (elt,
+ START, "width=\"%s\" height=\"%s\" name=\"%s\" extension=\"%s\"",
+ w_arg, h_arg, name_arg, ext_arg);
+ xml_insert_element (IMAGEALTTEXT, START);
+ execute_string ("%s", alt_arg);
+ xml_insert_element (IMAGEALTTEXT, END);
+ xml_insert_element (elt, END);
+
+ if (!xml_in_para)
+ xml_no_para--;
}
else
{ /* Try to open foo.EXT or foo.txt. */
@@ -3568,7 +3360,7 @@ cm_image (arg)
char *txtpath = NULL;
char *txtname = xmalloc (strlen (name_arg)
+ (ext_arg && *ext_arg
- ? strlen (ext_arg) + 1 : 4) + 1);
+ ? strlen (ext_arg) : 4) + 1);
strcpy (txtname, name_arg);
strcat (txtname, ".txt");
image_file = fopen (txtname, "r");
@@ -3587,49 +3379,72 @@ cm_image (arg)
int ch;
int save_inhibit_indentation = inhibit_paragraph_indentation;
int save_filling_enabled = filling_enabled;
+ int image_in_brackets = paragraph_is_open;
+
+ /* Write magic ^@^H[image ...^@^H] cookie in the info file, if
+ there's an accompanying bitmap. Otherwise just include the
+ text image. In the plaintext output, always include the text
+ image without the magic cookie. */
+ int use_magic_cookie = !no_headers
+ && access (fullname, R_OK) == 0 && !STREQ (fullname, txtname);
inhibit_paragraph_indentation = 1;
filling_enabled = 0;
last_char_was_newline = 0;
- /* Write magic ^@^H[image ...^@^H] cookie in the info file. */
- add_char ('\0');
- add_word ("\010[image");
+ if (use_magic_cookie)
+ {
+ add_char ('\0');
+ add_word ("\010[image");
- if (access (fullname, R_OK) == 0
- || (pathname != NULL && access (pathname, R_OK) == 0))
- add_word_args (" src=%s", fullname);
+ if (access (fullname, R_OK) == 0
+ || (pathname != NULL && access (pathname, R_OK) == 0))
+ add_word_args (" src=\"%s\"", fullname);
- if (*alt_arg)
- add_word_args (" alt=\"%s\"", alt_arg);
+ if (*alt_arg)
+ add_word_args (" alt=\"%s\"", alt_arg);
+ }
if (image_file != NULL)
{
- add_word (" text=\"");
+ if (use_magic_cookie)
+ add_word (" text=\"");
+
+ if (image_in_brackets)
+ add_char ('[');
+
/* Maybe we need to remove the final newline if the image
file is only one line to allow in-line images. On the
other hand, they could just make the file without a
final newline. */
while ((ch = getc (image_file)) != EOF)
{
- if (ch == '"' || ch == '\\')
+ if (use_magic_cookie && (ch == '"' || ch == '\\'))
add_char ('\\');
add_char (ch);
}
- add_char ('"');
+
+ if (image_in_brackets)
+ add_char (']');
+
+ if (use_magic_cookie)
+ add_char ('"');
if (fclose (image_file) != 0)
perror (txtname);
}
+ if (use_magic_cookie)
+ {
+ add_char ('\0');
+ add_word ("\010]");
+ }
+
inhibit_paragraph_indentation = save_inhibit_indentation;
filling_enabled = save_filling_enabled;
-
- add_char ('\0');
- add_word ("\010]");
}
else
- line_error (_("@image file `%s' (for text) unreadable: %s"),
+ warning (_("@image file `%s' (for text) unreadable: %s"),
txtname, strerror (errno));
}
@@ -3665,10 +3480,8 @@ typedef struct defines {
DEFINE *defines = NULL;
/* Add NAME to the list of `set' defines. */
-void
-set (name, value)
- char *name;
- char *value;
+static void
+set (char *name, char *value)
{
DEFINE *temp;
@@ -3685,12 +3498,18 @@ set (name, value)
temp->name = xstrdup (name);
temp->value = xstrdup (value);
defines = temp;
+
+ if (xml && !docbook)
+ {
+ xml_insert_element_with_attribute (SETVALUE, START, "name=\"%s\"", name);
+ execute_string ("%s", value);
+ xml_insert_element (SETVALUE, END);
+ }
}
/* Remove NAME from the list of `set' defines. */
-void
-clear (name)
- char *name;
+static void
+clear (char *name)
{
DEFINE *temp, *last;
@@ -3714,12 +3533,17 @@ clear (name)
last = temp;
temp = temp->next;
}
+
+ if (xml && !docbook)
+ {
+ xml_insert_element_with_attribute (CLEARVALUE, START, "name=\"%s\"", name);
+ xml_insert_element (CLEARVALUE, END);
+ }
}
/* Return the value of NAME. The return value is NULL if NAME is unset. */
-char *
-set_p (name)
- char *name;
+static char *
+set_p (char *name)
{
DEFINE *temp;
@@ -3732,26 +3556,26 @@ set_p (name)
/* Create a variable whose name appears as the first word on this line. */
void
-cm_set ()
+cm_set (void)
{
handle_variable (SET);
}
/* Remove a variable whose name appears as the first word on this line. */
void
-cm_clear ()
+cm_clear (void)
{
handle_variable (CLEAR);
}
void
-cm_ifset ()
+cm_ifset (void)
{
handle_variable (IFSET);
}
void
-cm_ifclear ()
+cm_ifclear (void)
{
handle_variable (IFCLEAR);
}
@@ -3763,7 +3587,7 @@ cm_ifclear ()
if ARG1 and ARG2 caselessly string compare to the same string, otherwise,
it produces no output. */
void
-cm_ifeq ()
+cm_ifeq (void)
{
char **arglist;
@@ -3783,11 +3607,16 @@ cm_ifeq ()
}
void
-cm_value (arg, start_pos, end_pos)
- int arg, start_pos, end_pos;
+cm_value (int arg, int start_pos, int end_pos)
{
static int value_level = 0, saved_meta_pos = -1;
+ /* xml_add_char() skips any content inside menus when output format is
+ Docbook, so @value{} is no use there. Also start_pos and end_pos does not
+ get updated, causing name to be empty string. So just return. */
+ if (docbook && in_menu)
+ return;
+
/* All the text after @value{ upto the matching } will eventually
disappear from output_paragraph, when this function is called
with ARG == END. If the text produced until then sets
@@ -3833,11 +3662,18 @@ cm_value (arg, start_pos, end_pos)
among other things. */
if (value)
- execute_string ("%s", value);
+ {
+ /* We need to get past the closing brace since the value may
+ expand to a context-sensitive macro (e.g. @xref) and produce
+ spurious warnings */
+ input_text_offset++;
+ execute_string ("%s", value);
+ input_text_offset--;
+ }
else
{
- warning (_("undefined flag: %s"), name);
- add_word_args (_("{No value for `%s'}"), name);
+ warning (_("undefined flag: %s"), name);
+ add_word_args (_("{No value for `%s'}"), name);
}
free (name);
@@ -3845,9 +3681,8 @@ cm_value (arg, start_pos, end_pos)
}
/* Set, clear, or conditionalize based on ACTION. */
-void
-handle_variable (action)
- int action;
+static void
+handle_variable (int action)
{
char *name;
@@ -3861,10 +3696,8 @@ handle_variable (action)
free (name);
}
-void
-handle_variable_internal (action, name)
- int action;
- char *name;
+static void
+handle_variable_internal (int action, char *name)
{
char *temp;
int delimiter, additional_text_present = 0;
@@ -4020,7 +3853,6 @@ handle_variable_internal (action, name)
}
/* Execution of random text not in file. */
-
typedef struct {
char *string; /* The string buffer. */
int size; /* The size of the buffer. */
@@ -4031,9 +3863,8 @@ static EXECUTION_STRING **execution_strings = NULL;
static int execution_strings_index = 0;
static int execution_strings_slots = 0;
-EXECUTION_STRING *
-get_execution_string (initial_size)
- int initial_size;
+static EXECUTION_STRING *
+get_execution_string (int initial_size)
{
int i = 0;
EXECUTION_STRING *es = NULL;
@@ -4081,9 +3912,7 @@ get_execution_string (initial_size)
entry in the execution_strings[] array and change the .STRING and
.SIZE members of that entry as appropriate. */
void
-maybe_update_execution_strings (text, new_len)
- char **text;
- unsigned new_len;
+maybe_update_execution_strings (char **text, unsigned int new_len)
{
int i = 0;
@@ -4127,10 +3956,11 @@ execute_string (format, va_alist)
#endif
{
EXECUTION_STRING *es;
- char *temp_string;
+ char *temp_string, *temp_input_filename;
#ifdef VA_FPRINTF
va_list ap;
#endif
+ int insertion_level_at_start = insertion_level;
es = get_execution_string (EXECUTE_STRING_MAX);
temp_string = es->string;
@@ -4147,28 +3977,50 @@ execute_string (format, va_alist)
pushfile ();
input_text_offset = 0;
input_text = temp_string;
- input_filename = xstrdup (input_filename);
input_text_length = strlen (temp_string);
+ input_filename = xstrdup (input_filename);
+ temp_input_filename = input_filename;
executing_string++;
reader_loop ();
- free (input_filename);
+
+ /* If insertion stack level changes during execution, that means a multiline
+ command is used inside braces or @section ... kind of commands. */
+ if (insertion_level_at_start != insertion_level && !executing_macro)
+ {
+ line_error (_("Multiline command %c%s used improperly"),
+ COMMAND_PREFIX,
+ command);
+ /* We also need to keep insertion_level intact to make sure warnings are
+ issued for @end ... command. */
+ while (insertion_level > insertion_level_at_start)
+ pop_insertion ();
+ }
popfile ();
executing_string--;
es->in_use = 0;
+ free (temp_input_filename);
}
/* Return what would be output for STR (in newly-malloced memory), i.e.,
- expand Texinfo commands. If IMPLICIT_CODE is set, expand @code{STR}.
- This is generally used for short texts; filling, indentation, and
- html escapes are disabled. */
+ expand Texinfo commands according to the current output format. If
+ IMPLICIT_CODE is set, expand @code{STR}. This is generally used for
+ short texts; filling, indentation, and html escapes are disabled. */
+
+char *
+expansion (char *str, int implicit_code)
+{
+ return maybe_escaped_expansion (str, implicit_code, 0);
+}
+
+
+/* Do HTML escapes according to DO_HTML_ESCAPE. Needed in
+ cm_printindex, q.v. */
char *
-expansion (str, implicit_code)
- char *str;
- int implicit_code;
+maybe_escaped_expansion (char *str, int implicit_code, int do_html_escape)
{
char *result;
@@ -4183,7 +4035,7 @@ expansion (str, implicit_code)
filling_enabled = 0;
indented_fill = 0;
no_indent = 1;
- escape_html = 0;
+ escape_html = do_html_escape;
result = full_expansion (str, implicit_code);
@@ -4198,12 +4050,10 @@ expansion (str, implicit_code)
/* Expand STR (or @code{STR} if IMPLICIT_CODE is nonzero). No change to
any formatting parameters -- filling, indentation, html escapes,
- etc., are not reset. */
+ etc., are not reset. Always returned in new memory. */
char *
-full_expansion (str, implicit_code)
- char *str;
- int implicit_code;
+full_expansion (char *str, int implicit_code)
{
int length;
char *result;
@@ -4260,18 +4110,20 @@ full_expansion (str, implicit_code)
format is. */
char *
-text_expansion (str)
- char *str;
+text_expansion (char *str)
{
char *ret;
int save_html = html;
int save_xml = xml;
+ int save_docbook = docbook;
html = 0;
xml = 0;
+ docbook = 0;
ret = expansion (str, 0);
html = save_html;
xml = save_xml;
+ docbook = save_docbook;
return ret;
}
@@ -4285,8 +4137,7 @@ text_expansion (str)
If NUM is zero, we assume `none'.
Returns 0 if successful, or nonzero if STRING isn't one of the above. */
int
-set_paragraph_indent (string)
- char *string;
+set_paragraph_indent (char *string)
{
if (strcmp (string, "asis") == 0 || strcmp (string, _("asis")) == 0)
paragraph_start_indent = 0;
OpenPOWER on IntegriCloud