/* Makeinfo -- convert texinfo format files into info files
Copyright (C) 1987 Free Software Foundation, Inc.
This file is part of GNU Info.
GNU Info is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
GNU Info is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Info; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* **************************************************************** */
/* Include File Declarations */
/* **************************************************************** */
#if defined (SYSV) || defined (VMS)
#define bcopy(source, dest, count) memcpy (dest, source, count)
#define alloca __builtin_alloca
/* Forward declarations. */
char *xmalloc (), *xrealloc ();
extern int in_fixed_width_font
;
/* Some systems don't declare this function in pwd.h. */
struct passwd
*getpwnam ();
/* **************************************************************** */
/* **************************************************************** */
/* How to allocate permanent storage for STRING. */
((char *)strcpy (xmalloc (1 + ((x) ? strlen (x) : 0)), (x) ? (x) : ""))
/* C's standard macros don't check to make sure that the characters being
changed are within range. So I have to check explicitly. */
/* GNU Library doesn't have toupper(). Until GNU gets this fixed, I will
#define toupper(c) ((c) - 32)
#define coerce_to_upper(c) ((islower(c) ? toupper(c) : (c)))
#define coerce_to_lower(c) ((isupper(c) ? tolower(c) : (c)))
#define control_character_bit 0x40 /* %01000000, must be off. */
#define meta_character_bit 0x080/* %10000000, must be on. */
#define CTL(c) ((c) & (~control_character_bit))
#define UNCTL(c) coerce_to_upper(((c)|control_character_bit))
#define META(c) ((c) | (meta_character_bit))
#define UNMETA(c) ((c) & (~meta_character_bit))
#define whitespace(c) (((c) == '\t') || ((c) == ' '))
#define sentence_ender(c) ((c) == '.' || (c) == '?' || (c) == '!')
#define cr_or_whitespace(c) (((c) == '\t') || ((c) == ' ') || ((c) == '\n'))
#define member(c, s) (index (s, c) != NULL)
#define COMMAND_PREFIX '@'
/* Stuff for splitting large files. */
#define SPLIT_SIZE_THRESHOLD 70000 /* What's good enough for Stallman... */
#define DEFAULT_SPLIT_SIZE 50000/* Is probably good enough for me. */
boolean splitting
= true; /* Always true for now. */
typedef int FUNCTION (); /* So I can say FUNCTION *foo; */
/* **************************************************************** */
/* **************************************************************** */
/* Global pointer to argv[0]. */
/* The current input file state. */
#define curchar() input_text[input_text_offset]
#define command_char(c) ((!whitespace(c)) && \
#define skip_whitespace() while (input_text_offset != size_of_input_text \
&& whitespace(curchar()))\
/* And writing to the output. */
/* The output file name. */
char *output_filename
, *pretty_output_filename
;
/* Current output stream. */
/* Position in the output file. */
/* Output paragraph buffer. */
/* Offset into OUTPUT_PARAGRAPH. */
int output_paragraph_offset
;
/* The output paragraph "cursor" horizontal position. */
/* non-zero means output_paragraph contains text. */
boolean paragraph_is_open
= false;
#define INITIAL_PARAGRAPH_SPACE 5000
int paragraph_buffer_len
= INITIAL_PARAGRAPH_SPACE
;
/* True indicates that filling will take place on long lines. */
boolean filling_enabled
= true;
/* Non-zero means that words are not to be split, even in long lines. This
gets changed for cm_w (). */
int non_splitting_words
= 0;
/* True indicates that filling a line also indents the new line. */
boolean indented_fill
= false;
/* The column at which long lines are broken. */
/* The amount of indentation to apply at the start of each line. */
/* The amount of indentation to add at the starts of paragraphs.
0 means don't change existing indentation at paragraph starts.
> 0 is amount to indent new paragraphs by.
< 0 means indent to column zero by removing indentation if necessary.
This is normally zero, but some people prefer paragraph starts to be
somewhat more indented than paragraph bodies. A pretty value for
int paragraph_start_indent
= 3;
/* Non-zero means that the use of paragraph_start_indent is inhibited.
@example uses this to line up the left columns of the example text. */
int inhibit_paragraph_indentation
= 0;
/* Indentation that is pending insertion. We have this for hacking lines
which look blank, but contain whitespace. We want to treat those as
/* The amount that indentation increases/decreases by. */
int default_indentation_increment
= 5;
/* True indicates that indentation is temporarily turned off. */
boolean no_indent
= true;
/* Command name in the process of being hacked. */
/* The index in our internal command table of the currently
/* A stack of file information records. If a new file is read in with
"@input", we remember the old input file state on this stack. */
FSTACK
*filestack
= (FSTACK
*) NULL
;
/* The current nodes node name */
/* The current nodes section level. */
/* The filename of the current input file. This is never freed. */
char *node_filename
= (char *)NULL
;
/* What we remember for each node. */
char *node
; /* name of this node. */
char *prev
; /* name of "Prev:" for this node. */
char *next
; /* name of "Next:" for this node. */
char *up
; /* name of "Up:" for this node. */
int position
; /* output file position of this node. */
int line_no
; /* defining line in source file. */
char *filename
; /* The file that this node was found in. */
int touched
; /* non-zero means this node has been referenced. */
int flags
; /* Room for growth. Right now, contains 1 bit. */
/* If node-a has a "Next" for node-b, but node-b has no "Prev" for node-a,
we turn on this flag bit in node-b's tag entry. This means that when
it is time to validate node-b, we don't report an additional error
if there was no "Prev" field. */
TAG_ENTRY
*tag_table
= (TAG_ENTRY
*) NULL
;
/* Menu reference, *note reference, and validation hacking. */
/* The various references that we know about. */
menu_reference
, followed_reference
/* A structure to remember references with. A reference to a node is
either an entry in a menu, or a cross-reference made with [px]ref. */
char *node
; /* Name of node referred to. */
char *containing_node
; /* Name of node containing this reference. */
int line_no
; /* Line number where the reference occurs. */
int section
; /* Section level where the reference occurs. */
char *filename
; /* Name of file where the reference occurs. */
enum reftype type
; /* Type of reference, either menu or note. */
/* The linked list of such structures. */
NODE_REF
*node_references
= (NODE_REF
*) NULL
;
/* Flag which tells us whether to examine menu lines or not. */
/* Flags controlling the operation of the program. */
/* Default is to notify users of bad choices. */
boolean print_warnings
= true;
/* Default is to check node references. */
boolean validating
= true;
/* Number of errors that we tolerate on a given fileset. */
int max_error_level
= 100;
/* Maximum number of references to a single node before complaining. */
int reference_warning_limit
= 1000;
/* Non-zero means print out information about what is going on when it
/* The list of commands that we hack in texinfo. Each one
has an associated function. When the command is encountered in the
text, the associated function is called with START as the argument.
If the function expects arguments in braces, it remembers itself on
the stack. When the corresponding close brace is encountered, the
function is called with END as the argument. */
typedef struct brace_element
struct brace_element
*next
;
BRACE_ELEMENT
*brace_stack
= (BRACE_ELEMENT
*) NULL
;
/* Forward declarations. */
insert_self (), cm_tex (), cm_asterisk (), cm_dots (), cm_bullet (),
cm_TeX (), cm_copyright (), cm_code (), cm_samp (), cm_file (), cm_kbd (),
cm_key (), cm_ctrl (), cm_var (), cm_dfn (), cm_emph (), cm_strong (),
cm_cite (), cm_italic (), cm_bold (), cm_roman (), cm_title (), cm_w (),
cm_chapter (), cm_unnumbered (), cm_appendix (),
cm_section (), cm_unnumberedsec (), cm_appendixsec (),
cm_subsection (), cm_unnumberedsubsec (), cm_appendixsubsec (),
cm_subsubsection (), cm_unnumberedsubsubsec (), cm_appendixsubsubsec (),
cm_heading (), cm_chapheading (), cm_subheading (), cm_subsubheading (),
/* All @defxxx commands map to cm_defun (). */
cm_node (), cm_menu (), cm_xref (),
cm_pxref (), cm_inforef (), cm_quotation (), cm_display (), cm_itemize (),
cm_enumerate (), cm_table (), cm_itemx (), cm_noindent (), cm_setfilename (),
cm_comment (), cm_ignore (), cm_br (), cm_sp (), cm_page (), cm_group (),
cm_need (), cm_center (), cm_include (), cm_bye (), cm_item (), cm_end (),
cm_infoinclude (), cm_ifinfo (), cm_iftex (), cm_titlepage (),
cm_titlespec (),cm_kindex (), cm_cindex (), cm_findex (), cm_pindex (),
cm_vindex (), cm_tindex (), cm_asis (), cm_synindex (), cm_settitle (),
cm_setchapternewpage (), cm_printindex (), cm_minus (), cm_footnote (),
cm_force_abbreviated_whitespace (), cm_force_sentence_end (), cm_example (),
cm_smallexample (), cm_lisp (), cm_format (), cm_exdent (), cm_defindex (),
cm_defcodeindex (), cm_sc (), cm_result (), cm_expansion (), cm_equiv (),
cm_print (), cm_error (), cm_point (), cm_smallbook ();
int misplaced_brace (), cm_obsolete ();
boolean argument_in_braces
;
/* Stuff for defining commands on the fly. */
COMMAND
**user_command_array
= (COMMAND
**) NULL
;
int user_command_array_len
= 0;
static COMMAND CommandTable
[] = {
{"!", cm_force_sentence_end
, false},
{"'", insert_self
, false},
{"*", cm_asterisk
, false},
{".", cm_force_sentence_end
, false},
{":", cm_force_abbreviated_whitespace
, false},
{"?", cm_force_sentence_end
, false},
{"@", insert_self
, false},
{" ", insert_self
, false},
{"\n", insert_self
, false},
{"`", insert_self
, false},
{"appendix", cm_appendix
, false},
{"appendixsec", cm_appendixsec
, false},
{"appendixsubsec", cm_appendixsubsec
, false},
{"appendixsubsubsec", cm_appendixsubsubsec
, false},
{"bullet", cm_bullet
, true},
{"c", cm_comment
, false},
{"center", cm_center
, false},
{"chapheading", cm_chapheading
, false},
{"chapter", cm_chapter
, false},
{"cindex", cm_cindex
, false},
{"comment", cm_comment
, false},
{"contents", do_nothing
, false},
{"copyright", cm_copyright
, true},
{"defcodeindex", cm_defcodeindex
, false},
{"defindex", cm_defindex
, false},
/* The `def' commands. */
{"defun", cm_defun
, false},
{"defunx", cm_defun
, false},
{"defvar", cm_defun
, false},
{"defvarx", cm_defun
, false},
{"defopt", cm_defun
, false},
{"defoptx", cm_defun
, false},
{"deffn", cm_defun
, false},
{"deffnx", cm_defun
, false},
{"defspec", cm_defun
, false},
{"defspecx", cm_defun
, false},
{"defmac", cm_defun
, false},
{"defmacx", cm_defun
, false},
/* The end of the `def' commands. */
{"display", cm_display
, false},
{"enumerate", cm_enumerate
, false},
{"equiv", cm_equiv
, true},
{"error", cm_error
, true},
{"example", cm_example
, false},
{"exdent", cm_exdent
, false},
{"expansion", cm_expansion
, true},
{"findex", cm_findex
, false},
{"format", cm_format
, false},
{"group", cm_group
, false},
{"heading", cm_heading
, false},
{"iappendix", cm_appendix
, false},
{"iappendixsec", cm_appendixsec
, false},
{"iappendixsubsec", cm_appendixsubsec
, false},
{"iappendixsubsubsec", cm_appendixsubsubsec
, false},
{"ichapter", cm_chapter
, false},
{"ifinfo", cm_ifinfo
, false},
{"iftex", cm_iftex
, false},
{"ignore", cm_ignore
, false},
{"include", cm_include
, false},
{"inforef", cm_inforef
, true},
{"input", cm_include
, false},
{"isection", cm_section
, false},
{"isubsection", cm_subsection
, false},
{"isubsubsection", cm_subsubsection
, false},
{"item", cm_item
, false},
{"itemize", cm_itemize
, false},
{"itemx", cm_itemx
, false},
{"iunnumbered", cm_unnumbered
, false},
{"iunnumberedsec", cm_unnumberedsec
, false},
{"iunnumberedsubsec", cm_unnumberedsubsec
, false},
{"iunnumberedsubsubsec", cm_unnumberedsubsubsec
, false},
{"kindex", cm_kindex
, false},
{"lisp", cm_lisp
, false},
{"majorheading", cm_majorheading
, false},
{"minus", cm_minus
, true},
{"need", cm_need
, false},
{"node", cm_node
, false},
{"noindent", cm_noindent
, false},
{"page", do_nothing
, false},
{"pindex", cm_pindex
, false},
{"point", cm_point
, true},
{"print", cm_print
, true},
{"printindex", cm_printindex
, false},
{"pxref", cm_pxref
, true},
{"quotation", cm_quotation
, false},
{"refill", cm_refill
, false},
{"result", cm_result
, true},
{"section", cm_section
, false},
{"setchapternewpage", cm_setchapternewpage
, false},
{"setfilename", cm_setfilename
, false},
{"settitle", cm_settitle
, false},
{"smallexample", cm_smallexample
, false},
{"smallbook", cm_smallbook
, false},
{"strong", cm_strong
, true},
{"subheading", cm_subheading
, false},
{"subsection", cm_subsection
, false},
{"subsubheading", cm_subsubheading
, false},
{"subsubsection", cm_subsubsection
, false},
{"summarycontents", do_nothing
, false},
{"syncodeindex", cm_synindex
, false},
{"synindex", cm_synindex
, false},
{"table", cm_table
, false},
{"tindex", cm_tindex
, false},
{"titlepage", cm_titlepage
, false},
{"titlespec", cm_titlespec
, false},
{"unnumbered", cm_unnumbered
, false},
{"unnumberedsec", cm_unnumberedsec
, false},
{"unnumberedsubsec", cm_unnumberedsubsec
, false},
{"unnumberedsubsubsec", cm_unnumberedsubsubsec
, false},
{"vindex", cm_vindex
, false},
{"{", insert_self
, false},
{"}", insert_self
, false},
/* Now @include does what this was supposed to. */
{"infoinclude", cm_infoinclude
, false},
{"footnote", cm_footnote
, false}, /* self-arg eater */
{(char *) NULL
, (FUNCTION
*) NULL
}, false};
/* Non-zero means we are running inside of Emacs. */
int major_version
= MAKEINFO_MAJOR
;
int minor_version
= MAKEINFO_MINOR
;
struct option long_options
[] =
{ "no-validate", 0, &validating
, false }, /* formerly -nv */
{ "no-warn", 0, &print_warnings
, false }, /* formerly -nw */
{ "no-split", 0, &splitting
, false }, /* formerly -ns */
{ "verbose", 0, &verbose_mode
, 1 }, /* formerly -verbose */
{ "fill-column", 1, 0, 'f' }, /* formerly -fc */
{ "paragraph-indent", 1, 0, 'p' }, /* formerly -pi */
{ "error-limit", 1, 0, 'e' }, /* formerly -el */
{ "reference-limit", 1, 0, 'r' }, /* formerly -rl */
{ "footnote-style", 1, 0, 's' }, /* formerly -ft */
{ "version", 0, 0, 'V' },
/* **************************************************************** */
/* Main () Start of code */
/* **************************************************************** */
/* For each file mentioned in the command line, process it, turning
texinfo commands into wonderfully formatted output text. */
char *t
= (char *) getenv ("EMACS");
if (t
&& strcmp (t
, "t") == 0)
/* Parse argument flags from the input line. */
while ((c
= getopt_long (argc
, argv
, "", long_options
, &ind
)) != EOF
)
if (c
== 0 && long_options
[ind
].flag
== 0)
c
= long_options
[ind
].val
;
/* user specified fill_column? */
if (sscanf (optarg
, "%d", &fill_column
) != 1)
/* User specified paragraph indent (paragraph_start_index)? */
if (sscanf (optarg
, "%d", ¶graph_start_indent
) != 1)
/* User specified error level? */
if (sscanf (optarg
, "%d", &max_error_level
) != 1)
/* User specified reference warning limit? */
if (sscanf (optarg
, "%d", &reference_warning_limit
) != 1)
/* User specified footnote style? */
set_footnote_style (optarg
);
case 'V': /* Use requested version info? */
fprintf (stderr
, "Makeinfo verison %d.%d.\n",
major_version
, minor_version
);
/* Remaining arguments are file names of texinfo files.
Convert them, one by one. */
convert (argv
[optind
++]);
/* **************************************************************** */
/* **************************************************************** */
/* Just like malloc, but kills the program in case of fatal error. */
char *temp
= (char *) malloc (nbytes
);
if (temp
== (char *) NULL
)
error ("Virtual memory exhausted! Needed %d bytes.", nbytes
);
/* Like realloc (), but barfs if there isn't enough memory. */
xrealloc (pointer
, nbytes
)
pointer
= (char *) realloc (pointer
, nbytes
);
error ("Virtual memory exhausted in realloc ().");
/* Tell the user how to use this program. */
fprintf (stderr
, "Usage: %s [options] texinfo-file...\n\
This program accepts as input files of texinfo commands and text\n\
and outputs a file suitable for reading with GNU Info.\n\
`+no-validate' to suppress node cross reference validation.\n\
`+no-warn' to suppress warning messages (errors are still output).\n\
`+no-split' to suppress the splitting of large files.\n\
`+verbose' to print information about what is being done.\n\
`+version' to print the version number of Makeinfo.\n\
`+paragraph-indent NUM' to set the paragraph indent to NUM (default %d).\n\
`+fill-column NUM' to set the filling column to NUM (default %d).\n\
`+error-limit NUM' to set the error limit to NUM (default %d).\n\
`+reference-limit NUM' to set the reference warning limit to NUM (default %d).\n\
`+footnote-style STYLE' to set the footnote style to STYLE. STYLE should\n\
either be `MN' for `make node', or `BN' for `bottom node'.\n\n",
progname
, paragraph_start_indent
,
fill_column
, max_error_level
, reference_warning_limit
);
/* **************************************************************** */
/* **************************************************************** */
typedef struct generic_list
struct generic_list
*next
;
/* 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. */
register GENERIC_LIST
*list
;
register GENERIC_LIST
*next
;
register GENERIC_LIST
*prev
= (GENERIC_LIST
*) NULL
;
/* **************************************************************** */
/* Pushing and Popping Files */
/* **************************************************************** */
/* Find and load the file named FILENAME. Return a pointer to
the loaded file, or NULL if it can't be loaded. */
int file
, n
, i
, count
= 0;
char *result
= (char *) NULL
;
if (stat (filename
, &fileinfo
) != 0)
file
= open (filename
, O_RDONLY
);
result
= xmalloc (fileinfo
.st_size
);
/* VMS stat lies about the st_size value. The actual number of
readable bytes is always less than this value. The arcane
mysteries of VMS/RMS are too much to probe, so this hack
suffices to make things work. */
while ((n
= read (file
, result
+count
, fileinfo
.st_size
)) > 0)
count
= fileinfo
.st_size
;
if (read (file
, result
, fileinfo
.st_size
) != fileinfo
.st_size
)
/* Set the globals to the new file. */
size_of_input_text
= fileinfo
.st_size
;
input_filename
= savestring (filename
);
node_filename
= savestring (filename
);
/* Save the state of the current input file. */
FSTACK
*newstack
= (FSTACK
*) xmalloc (sizeof (FSTACK
));
newstack
->filename
= input_filename
;
newstack
->text
= input_text
;
newstack
->size
= size_of_input_text
;
newstack
->offset
= input_text_offset
;
newstack
->line_number
= line_number
;
newstack
->next
= filestack
;
/* Make the current file globals be what is on top of the file stack. */
extern int executing_string
;
FSTACK
*temp
= filestack
;
abort (); /* My fault. I wonder what I did? */
/* Make sure that commands with braces have been satisfied. */
/* Get the top of the stack into the globals. */
input_filename
= filestack
->filename
;
input_text
= filestack
->text
;
size_of_input_text
= filestack
->size
;
input_text_offset
= filestack
->offset
;
line_number
= filestack
->line_number
;
filestack
= filestack
->next
;
/* Flush all open files on the file stack. */
int node_filename_stack_index
= 0;
int node_filename_stack_size
= 0;
char **node_filename_stack
= (char **)NULL
;
if (node_filename_stack_index
+ 1 > node_filename_stack_size
)
if (!node_filename_stack
)
(char **)xmalloc ((node_filename_stack_size
+= 10)
(char **)xrealloc (node_filename_stack
,
(node_filename_stack_size
+ 10)
node_filename_stack
[node_filename_stack_index
] = node_filename
;
node_filename_stack_index
++;
node_filename
= node_filename_stack
[--node_filename_stack_index
];
/* Return just the simple part of the filename; i.e. the
filename without the path information, or extensions.
This conses up a new string. */
register int i
= strlen (filename
) - 1;
while (i
&& filename
[i
] != '/')
#ifdef REMOVE_OUTPUT_EXTENSIONS
result
= savestring (&filename
[i
]);
/* See if there is an extension to remove. If so, remove it. */
if (rindex (result
, '.'))
*(rindex (result
, '.')) = '\0';
return (savestring (&filename
[i
]));
#endif /* REMOVE_OUTPUT_EXTENSIONS */
/* Return the pathname part of filename. This can be NULL. */
char *expand_filename ();
char *result
= (char *) NULL
;
filename
= expand_filename (filename
, "");
i
= strlen (filename
) - 1;
while (i
&& filename
[i
] != '/')
result
= xmalloc (1 + i
);
strncpy (result
, filename
, i
);
/* Return the expansion of FILENAME. */
expand_filename (filename
, input_name
)
char *filename
, *input_name
;
filename
= full_pathname (filename
);
if (filename
[0] != '/' && input_name
[0] == '/')
/* Make it so that relative names work. */
char *result
= xmalloc (1 + strlen (input_name
)
int i
= strlen (input_name
) - 1;
strcpy (result
, input_name
);
while (result
[i
] != '/' && i
)
strcpy (&result
[i
], filename
);
/* Return the full path to FILENAME. */
if (filename
&& (initial_character
= *filename
))
if (initial_character
== '/')
return (savestring (filename
));
if (initial_character
!= '~')
return (savestring (filename
));
/* Return the concatenation of HOME and the rest of the string. */
char *temp_home
= (char *) getenv ("HOME");
char *temp_name
= xmalloc (strlen (&filename
[2])
+ temp_home
? strlen (temp_home
)
strcpy (temp_name
, temp_home
);
strcat (temp_name
, &filename
[2]);
struct passwd
*user_entry
;
char *username
= xmalloc (257);
for (i
= 1; c
= filename
[i
]; i
++)
user_entry
= getpwnam (username
);
return (savestring (filename
));
temp_name
= xmalloc (1 + strlen (user_entry
->pw_dir
)
+ strlen (&filename
[i
]));
strcpy (temp_name
, user_entry
->pw_dir
);
strcat (temp_name
, &filename
[i
]);
return (savestring (filename
));
/* **************************************************************** */
/* **************************************************************** */
/* Number of errors encountered. */
/* Print the last error gotten from the file system. */
/* Print an error message, and return false. */
error (format
, arg1
, arg2
, arg3
, arg4
, arg5
)
fprintf (stderr
, format
, arg1
, arg2
, arg3
, arg4
, arg5
);
/* Just like error (), but print the line number as well. */
line_error (format
, arg1
, arg2
, arg3
, arg4
, arg5
)
fprintf (stderr
, "%s:%d: ", input_filename
, line_number
);
fprintf (stderr
, format
, arg1
, arg2
, arg3
, arg4
, arg5
);
warning (format
, arg1
, arg2
, arg3
, arg4
, arg5
)
fprintf (stderr
, "%s:%d: Warning: ", input_filename
, line_number
);
fprintf (stderr
, format
, arg1
, arg2
, arg3
, arg4
, arg5
);
/* Remember that an error has been printed. If this is the first
error printed, then tell them which program is printing them.
If more than max_error_level have been printed, then exit the
if (max_error_level
&& (errors_printed
> max_error_level
))
fprintf (stderr
, "Too many errors! Gave up.");
/* **************************************************************** */
/* Hacking Tokens and Strings */
/* **************************************************************** */
/* Return the next token as a string pointer. We cons the
/* Hack special case. If the first character to be read is
self-delimiting, then that is the command itself. */
if (self_delimiting (character
))
result
= savestring (" ");
for (i
= 0; ((input_text_offset
!= size_of_input_text
)
&& (character
= curchar ())
&& command_char (character
));
i
++, input_text_offset
++);
result
= xmalloc (i
+ 1);
strncpy (result
, &input_text
[input_text_offset
- i
], i
);
/* Return TRUE if CHARACTER is self-delimiting. */
self_delimiting (character
)
return (member (character
, "{}:.@*'`,!?; \n"));
/* Clear whitespace from the front and end of string. */
int len
= strlen (string
);
for (x
= 0; x
< len
; x
++)
if (!whitespace (string
[x
]))
strcpy (string
, string
+ x
);
while (len
> -1 && cr_or_whitespace (string
[len
]))
/* Bash STRING, replacing all whitespace with just one space. */
char *temp
= xmalloc (strlen (string
) + 1);
while (string
[string_index
])
c
= temp
[temp_index
++] = string
[string_index
++];
if (c
== ' ' || c
== '\n' || c
== '\t')
temp
[temp_index
- 1] = ' ';
while ((c
= string
[string_index
]) && (c
== ' ' ||
/* Discard text until the desired string is found. The string is
included in the discarded text. */
int temp
= search_forward (string
, input_text_offset
);
int tt
= (temp
< 0) ? size_of_input_text
: temp
+ strlen (string
);
int from
= input_text_offset
;
/* Find out what line we are on. */
if (input_text
[from
++] == '\n')
input_text_offset
= size_of_input_text
- strlen (string
);
if (strcmp (string
, "\n") != 0)
line_error ("Expected `%s'", string
);
input_text_offset
= temp
;
input_text_offset
+= strlen (string
);
/* Read characters from the file until we are at MATCH.
Place the characters read into STRING.
On exit input_text_offset is after the match string.
Return the length of STRING. */
get_until (match
, string
)
int current_point
= input_text_offset
;
int new_point
= search_forward (match
, input_text_offset
);
new_point
= size_of_input_text
;
len
= new_point
- current_point
;
/* Keep track of which line number we are at. */
if (input_text
[x
++] == '\n')
*string
= xmalloc (len
+ 1);
strncpy (*string
, &input_text
[current_point
], len
);
/* Now leave input_text_offset in a consistent state. */
input_text_offset
= new_point
+ (strlen (match
) - 1);
if (input_text_offset
> size_of_input_text
)
input_text_offset
= size_of_input_text
;
/* Read characters from the file until we are at MATCH or end of line.
Place the characters read into STRING. */
get_until_in_line (match
, string
)
int real_bottom
= size_of_input_text
;
int temp
= search_forward ("\n", input_text_offset
);
temp
= size_of_input_text
;
size_of_input_text
= temp
;
get_until (match
, string
);
size_of_input_text
= real_bottom
;
get_rest_of_line (string
)
get_until ("\n", string
);
{ /* as opposed to the end of the file... */
/* Read characters from the file until we are at MATCH or closing brace.
Place the characters read into STRING. */
get_until_in_braces (match
, string
)
int match_len
= strlen (match
);
for (i
= input_text_offset
; i
< size_of_input_text
; i
++)
if (input_text
[i
] == '{')
if (input_text
[i
] == '}')
if (input_text
[i
] == '\n')
(brace
== 0 && strncmp (input_text
+ i
, match
, match_len
) == 0))
match_len
= i
- input_text_offset
;
temp
= xmalloc (2 + match_len
);
strncpy (temp
, input_text
+ input_text_offset
, match_len
);
/* **************************************************************** */
/* Converting the File */
/* **************************************************************** */
/* Convert the file named by NAME. The output is saved on the file
named as the argument to the @setfilename command. */
char *real_output_filename
, *expand_filename (), *filename_part ();
if (!find_and_load (name
))
/* For some reason, the file couldn't be loaded. Print a message
to that affect, and split. */
input_filename
= savestring (name
);
/* Search this file looking for the special string which starts conversion.
Once found, we may truly begin. */
input_text_offset
= search_forward ("@setfilename", 0);
if (input_text_offset
< 0)
error ("No `@setfilename' found in `%s'", name
);
input_text_offset
+= strlen ("@setfilename");
get_until ("\n", &output_filename
); /* no braces expected. */
canon_white (output_filename
);
printf ("Making info file `%s' from `%s'.\n", output_filename
, name
);
real_output_filename
= expand_filename (output_filename
, name
);
output_stream
= fopen (real_output_filename
, "w");
if (output_stream
== NULL
)
fs_error (real_output_filename
);
/* Make the displayable filename from output_filename. Only the root
portion of the filename need be displayed. */
pretty_output_filename
= filename_part (output_filename
);
/* For this file only, count the number of newlines from the top of
the file to here. This way, we keep track of line numbers for
error reporting. Line_number starts at 1, since the user isn't
while (temp
!= input_text_offset
)
if (input_text
[temp
++] == '\n')
add_word_args ("Info file %s, produced by Makeinfo, -*- Text -*-\n\
from input file %s.\n", output_filename
, input_filename
);
if (output_stream
!= NULL
)
tag_table
= (TAG_ENTRY
*) reverse_list (tag_table
);
/* If validating, then validate the entire file right now. */
validate_file (real_output_filename
, tag_table
);
/* This used to test && !errors_printed.
But some files might have legit warnings. So split anyway. */
split_file (real_output_filename
, 0);
if ((*pointer
) != (char *) NULL
)
*pointer
= (char *) NULL
;
/* Initialize some state. */
free_and_clear (¤t_node
);
free_and_clear (&output_filename
);
free_and_clear (&command
);
free_and_clear (&input_filename
);
free_and_clear (&output_paragraph
);
output_paragraph
= xmalloc (paragraph_buffer_len
);
output_paragraph
[0] = '\0';
output_paragraph_offset
= 0;
paragraph_is_open
= false;
/* Okay, we are ready to start the conversion. Call the reader on
some text, and fill the text as it is output. Handle commands by
remembering things like open braces and the current file position on a
stack, and when the corresponding close brace is found, you can call
the function with the proper arguments. */
if (input_text_offset
>= size_of_input_text
)
if (!in_fixed_width_font
&&
(character
== '\'' || character
== '`') &&
input_text
[input_text_offset
+ 1] == character
)
if (dash_count
== 3 && !in_fixed_width_font
)
if (in_menu
&& input_text_offset
+ 1 < size_of_input_text
)
/* If the following line is all whitespace, advance to the carriage
register int i
= input_text_offset
+ 1;
while (i
< size_of_input_text
&& whitespace (input_text
[i
]))
if (i
== size_of_input_text
|| input_text
[i
] == '\n')
input_text_offset
= i
- 1;
if (strcmp (command
, "bye") == 0)
/* Special case. I'm not supposed to see this character by itself.
If I do, it means there is a syntax error in the input text.
Report the error here, but remember this brace on the stack so
you can ignore its partner. */
line_error ("Misplaced `{'");
remember_brace (misplaced_brace
);
/* Don't advance input_text_offset since this happens in
/* Find the command corresponding to STRING. If the command
is found, return a pointer to the data structure. Otherwise
get_command_entry (string
)
for (i
= 0; CommandTable
[i
].name
; i
++)
if (strcmp (CommandTable
[i
].name
, string
) == 0)
return (&CommandTable
[i
]);
/* This command is not in our predefined command table. Perhaps
it is a user defined command. */
for (i
= 0; i
< user_command_array_len
; i
++)
if (user_command_array
[i
] &&
(strcmp (user_command_array
[i
]->name
, string
) == 0))
return (user_command_array
[i
]);
/* Nope, we never heard of this command. */
return ((COMMAND
*) - 1);
/* input_text_offset is right at the command prefix character.
Read the next token to determine what to do. */
free_and_clear (&command
);
entry
= get_command_entry (command
);
line_error ("Unknown info command `%s'", command
);
if (entry
->argument_in_braces
)
remember_brace (entry
->proc
);
(*(entry
->proc
)) (START
);
/* Return the string which invokes PROC; a pointer to a function. */
for (i
= 0; CommandTable
[i
].name
; i
++)
if (proc
== CommandTable
[i
].proc
)
return (CommandTable
[i
].name
);
brace_stack
= (BRACE_ELEMENT
*) NULL
;
line_error ("@%s expected `{..}'", command
);
remember_brace_1 (proc
, output_paragraph_offset
);
/* Remember the current output position here. Save PROC
along with it so you can call it later. */
remember_brace_1 (proc
, position
)
BRACE_ELEMENT
*new = (BRACE_ELEMENT
*) xmalloc (sizeof (BRACE_ELEMENT
));
/* Pop the top of the brace stack, and call the associated function
with the args END and POS. */
if (brace_stack
== (BRACE_ELEMENT
*) NULL
)
return (line_error ("Unmatched close bracket"));
proc
= brace_stack
->proc
;
temp
= brace_stack
->next
;
return ((*proc
) (END
, pos
, output_paragraph_offset
));
/* You call discard_braces () when you shouldn't have any braces on the stack.
I used to think that this happens for commands that don't take arguments
in braces, but that was wrong because of things like @code{foo @@}. So now
I only detect it at the beginning of nodes. */
int temp_line_number
= line_number
;
line_number
= brace_stack
->line
;
proc_name
= find_proc_name (brace_stack
->proc
);
line_error ("@%s missing close brace", proc_name
);
line_number
= temp_line_number
;
/* Return the printed length of the character. */
len
= (output_column
+ 8) & 0xf7;
len
= fill_column
- output_column
;
len
= len
- output_column
;
len
= fill_column
- output_column
;
add_word_args (format
, arg1
, arg2
, arg3
, arg4
, arg5
)
sprintf (buffer
, format
, arg1
, arg2
, arg3
, arg4
, arg5
);
/* Add STRING to output_paragraph. */
boolean last_char_was_newline
= true;
int last_inserted_character
= 0;
/* Add the character to the current paragraph. If filling_enabled is
true, then do filling as well. */
extern int must_start_paragraph
;
/* If we are adding a character now, then we don't have to
ignore close_paragraph () calls any more. */
if (must_start_paragraph
)
must_start_paragraph
= 0;
if (current_indent
> output_column
)
indent (current_indent
- output_column
);
output_column
= current_indent
;
if (non_splitting_words
&& member (character
, " \t\n"))
/* Should I be flushing output here? * /
indent (output_column
= current_indent
);
if (sentence_ender (last_inserted_character
))
last_inserted_character
= character
;
if (last_char_was_newline
)
last_char_was_newline
= true;
int len
= get_char_len (character
);
if ((character
== ' ') && (last_char_was_newline
))
/* If the paragraph is supposed to be indented a certain way,
then discard all of the pending whitespace. Otherwise, we
let the whitespace stay. */
if (!paragraph_start_indent
)
if ((output_column
+= len
) >= fill_column
)
int temp
= output_paragraph_offset
- 1;
while (temp
> 0 && output_paragraph
[--temp
] != '\n')
if (output_paragraph
[temp
] == ' ')
output_paragraph
[temp
++] = '\n';
/* We have correctly broken the line where we want
to. What we don't want is spaces following where
we have decided to break the line. We get rid of
while (t1
< output_paragraph_offset
&& whitespace (output_paragraph
[t1
]))
strncpy (&output_paragraph
[temp
],
(output_paragraph_offset
- t1
));
output_paragraph_offset
-= (t1
- temp
);
/* Filled, but now indent if that is right. */
if (indented_fill
&& current_indent
)
int buffer_len
= ((output_paragraph_offset
- temp
)
char *temp_buffer
= xmalloc (buffer_len
);
/* We have to shift any markers that are in
front of the wrap point. */
register BRACE_ELEMENT
*stack
= brace_stack
;
stack
->pos
+= current_indent
;
while (indentation
!= current_indent
)
temp_buffer
[indentation
++] = ' ';
strncpy (&temp_buffer
[current_indent
],
buffer_len
- current_indent
);
if (output_paragraph_offset
+ buffer_len
(char *) xrealloc (output_paragraph
,
(paragraph_buffer_len
+= buffer_len
));
strncpy (&output_paragraph
[temp
], temp_buffer
, buffer_len
);
output_paragraph_offset
+= current_indent
;
while (temp
!= output_paragraph_offset
)
output_column
+= get_char_len (output_paragraph
[temp
++]);
last_char_was_newline
= false;
last_inserted_character
= character
;
/* Insert CHARACTER into OUTPUT_PARAGRAPH. */
output_paragraph
[output_paragraph_offset
++] = character
;
if (output_paragraph_offset
== paragraph_buffer_len
)
(char *) xrealloc (output_paragraph
,
(paragraph_buffer_len
+= 100));
/* Remove upto COUNT characters of whitespace from the
the current output line. If COUNT is less than zero,
then remove until none left. */
/* Handle infinite case first. */
while (output_paragraph_offset
)
if (whitespace (output_paragraph
[output_paragraph_offset
- 1]))
output_paragraph_offset
--;
while (output_paragraph_offset
&& count
--)
if (whitespace (output_paragraph
[output_paragraph_offset
- 1]))
output_paragraph_offset
--;
if (!output_paragraph_offset
)
for (i
= 0; i
< output_paragraph_offset
; i
++)
output_paragraph
[i
] &= 0x7f;
fwrite (output_paragraph
, 1, output_paragraph_offset
, output_stream
);
output_position
+= output_paragraph_offset
;
output_paragraph_offset
= 0;
/* How to close a paragraph controlling the number of lines between
this one and the last one. */
/* Paragraph spacing is controlled by this variable. It is the number of
blank lines that you wish to appear between paragraphs. A value of
1 creates a single blank line between paragraphs. */
int paragraph_spacing
= 1;
/* Close the current paragraph, leaving no blank lines between them. */
close_single_paragraph ()
close_paragraph_with_lines (0);
close_paragraph_with_lines (lines
)
int old_spacing
= paragraph_spacing
;
paragraph_spacing
= lines
;
paragraph_spacing
= old_spacing
;
/* Non-zero means that start_paragraph () MUST be called before we pay
any attention to close_paragraph () calls. */
int must_start_paragraph
= 0;
/* Close the currently open paragraph. */
if (paragraph_is_open
&& !must_start_paragraph
)
/* Gobble up blank lines that are extra... */
register int tindex
= output_paragraph_offset
;
((c
= output_paragraph
[tindex
- 1]) == ' ' || c
== '\n'))
output_paragraph
[--tindex
] = '\n';
output_paragraph_offset
= tindex
;
for (i
= 0; i
< paragraph_spacing
; i
++)
paragraph_is_open
= false;
last_char_was_newline
= true;
/* Begin a new paragraph. */
close_paragraph (); /* First close existing one. */
paragraph_is_open
= true;
if (!must_start_paragraph
)
/* If doing indentation, then insert the appropriate amount. */
if (inhibit_paragraph_indentation
|| paragraph_start_indent
< 0)
output_column
= current_indent
;
output_column
= current_indent
+ paragraph_start_indent
;
must_start_paragraph
= 0;
/* Insert the indentation specified by AMOUNT. */
/* Search forward for STRING in input_text.
FROM says where where to start. */
search_forward (string
, from
)
int len
= strlen (string
);
while (from
< size_of_input_text
)
if (strnicmp (input_text
+ from
, string
, len
) == 0)
/* Whoops, Unix doesn't have stricmp, or strnicmp. */
/* Case independent string compare. */
stricmp (string1
, string2
)
ch1
= coerce_to_upper (ch1
);
ch2
= coerce_to_upper (ch2
);
/* Compare at most COUNT characters from string1 to string2. Case
strnicmp (string1
, string2
, count
)
if (coerce_to_upper (ch1
) == coerce_to_upper (ch2
))
menu
, quotation
, lisp
, example
, smallexample
, display
,
itemize
, format
, enumerate
, table
, group
, ifinfo
,
defun
, defvar
, defopt
, deffn
, defspec
, defmac
,
char *insertion_type_names
[] = {
"menu", "quotation", "lisp", "example", "smallexample", "display",
"itemize", "format", "enumerate", "table", "group", "ifinfo",
"defun", "defvar", "defopt", "deffn", "defspec", "defmac",
typedef struct istack_elt
enum insertion_type insertion
;
INSERTION_ELT
*insertion_stack
= (INSERTION_ELT
*) NULL
;
insertion_stack
= (INSERTION_ELT
*) NULL
;
/* Return the type of the current insertion. */
current_insertion_type ()
return (insertion_stack
->insertion
);
/* Return a pointer to the string which is the function
return (insertion_stack
->item_function
);
get_until ("\n", &item_function
);
canon_white (item_function
);
/* Push the state of the current insertion on the stack. */
push_insertion (type
, item_function
)
enum insertion_type type
;
INSERTION_ELT
*new = (INSERTION_ELT
*) xmalloc (sizeof (INSERTION_ELT
));
new->item_function
= item_function
;
new->filling_enabled
= filling_enabled
;
new->indented_fill
= indented_fill
;
new->line_number
= line_number
;
new->inhibited
= inhibit_paragraph_indentation
;
new->next
= insertion_stack
;
/* Pop the value on top of the insertion stack into the
INSERTION_ELT
*temp
= insertion_stack
;
if (temp
== (INSERTION_ELT
*) NULL
)
inhibit_paragraph_indentation
= temp
->inhibited
;
filling_enabled
= insertion_stack
->filling_enabled
;
indented_fill
= insertion_stack
->indented_fill
;
free_and_clear (&(temp
->item_function
));
insertion_stack
= insertion_stack
->next
;
/* Return a pointer to the print name of this
insertion_type_pname (type
)
enum insertion_type type
;
if ((int) type
< (int) bad_type
)
return (insertion_type_names
[(int) type
]);
return ("Broken-Type in insertion_type_pname");
/* Return the insertion_type associated with NAME.
If the type is not one of the known ones, return BAD_TYPE. */
find_type_from_name (name
)
while (index
< (int) bad_type
)
if (stricmp (name
, insertion_type_names
[index
]) == 0)
return (enum insertion_type
) index
;
enum insertion_type type
;
/* Non-zero means that we are currently hacking the insides of an
insertion which would use a fixed width font. */
int in_fixed_width_font
= 0;
/* This is where the work for all the "insertion" style
commands is done. A huge switch statement handles the
various setups, and generic code is on both sides. */
enum insertion_type type
;
if (defun_insertion (type
))
push_insertion (type
, savestring (""));
push_insertion (type
, get_item_function ());
filling_enabled
= false; /* the general case for insertions. */
inhibit_paragraph_indentation
= 1;
/* discard_until () has already counted the newline. Discount it. */
/* I think @quotation is meant to do filling.
If you don't want filling, then use @example. */
last_char_was_newline
= 0;
indented_fill
= filling_enabled
= true;
current_indent
+= default_indentation_increment
;
/* Just like @example, but no indentation. */
last_char_was_newline
= 0;
current_indent
+= default_indentation_increment
;
current_indent
+= default_indentation_increment
;
filling_enabled
= indented_fill
= true;
/* Make things work for losers who forget the itemize syntax. */
if (!(*insertion_stack
->item_function
))
free (insertion_stack
->item_function
);
insertion_stack
->item_function
= savestring ("*");
inhibit_paragraph_indentation
= 0;
current_indent
+= default_indentation_increment
;
filling_enabled
= indented_fill
= true;
inhibit_paragraph_indentation
= 0;
/* Undo whatever we just did. This is a no-op. */
inhibit_paragraph_indentation
= 0;
filling_enabled
= insertion_stack
->filling_enabled
;
indented_fill
= insertion_stack
->indented_fill
;
filling_enabled
= indented_fill
= true;
current_indent
+= default_indentation_increment
;
/* Try to end the quotation with the specified type.
Like begin_insertion (), this uses a giant switch statement as
well. A big difference is that you *must* pass a valid type to
this function, and a value of bad_type gets translated to match
the value currently on top of the stack. If, however, the value
passed is a valid type, and it doesn't match the top of the
stack, then we produce an error. Should fix this, somewhat
enum insertion_type type
;
enum insertion_type temp_type
;
temp_type
= current_insertion_type ();
line_error ("Expected `%s', but saw `%s'. Token unread",
insertion_type_pname (temp_type
), insertion_type_pname (type
));
in_menu
--; /* no longer hacking menus. */
current_indent
-= default_indentation_increment
;
current_indent
-= default_indentation_increment
;
current_indent
-= default_indentation_increment
;
/* Insertions cannot cross certain boundaries, such as node beginnings. In
code that creates such boundaries, you should call discard_insertions ()
before doing anything else. It prints the errors for you, and cleans up
int real_line_number
= line_number
;
if (insertion_stack
->insertion
== ifinfo
)
char *offender
= (char *) insertion_type_pname (insertion_stack
->insertion
);
line_number
= insertion_stack
->line_number
;
line_error ("This `%s' doesn't have a matching `%cend %s'", offender
,
COMMAND_PREFIX
, offender
);
line_number
= real_line_number
;
/* MAX_NS is the maximum nesting level for enumerations. I picked 100
which seemed reasonable. This doesn't control the number of items,
just the number of nested lists. */
int number_stack
[max_ns
];
int the_current_number
= 0;
start_numbering (at_number
)
if (number_offset
+ 1 == max_ns
)
line_error ("Enumeration stack overflow");
number_stack
[number_offset
++] = the_current_number
;
the_current_number
= at_number
;
the_current_number
= number_stack
[--number_offset
];
/* Place a number into the output stream. */
sprintf (temp
, "%d. ", the_current_number
);
indent (output_column
+= (current_indent
- strlen (temp
)));
/* The actual commands themselves. */
/* Commands which insert themselves. */
/* Force a line break in the output. */
indent (output_column
= current_indent
);
extern int printing_index
;
/* Convert the character at position-1 into CTL. */
output_paragraph
[position
- 1] = CTL (output_paragraph
[position
- 1]);
/* Small Caps in makeinfo just does all caps. */
cm_sc (arg
, start_pos
, end_pos
)
int arg
, start_pos
, end_pos
;
while (start_pos
< end_pos
)
output_paragraph
[start_pos
] =
coerce_to_upper (output_paragraph
[start_pos
]);
/* @var in makeinfo just uppercases the text. */
cm_var (arg
, start_pos
, end_pos
)
int arg
, start_pos
, end_pos
;
while (start_pos
< end_pos
)
output_paragraph
[start_pos
] =
coerce_to_upper (output_paragraph
[start_pos
]);
cm_strong (arg
, position
)
/* Prevent the argument from being split across two lines. */
/* Explain that this command is obsolete, thus the user shouldn't
warning ("The command `@%s' is obsolete", command
);
/* Insert the text following input_text_offset up to the end of the line
in a new, separate paragraph. Directly underneath it, insert a
line of WITH_CHAR, the same length of the inserted text. */
insert_and_underscore (with_char
)
int len
, i
, old_no_indent
;
filling_enabled
= indented_fill
= false;
old_no_indent
= no_indent
;
get_rest_of_line (&temp
);
execute_string ("%s\n", temp
);
len
= ((output_position
+ output_paragraph_offset
) - 1) - len
;
for (i
= 0; i
< len
; i
++)
no_indent
= old_no_indent
;
insert_and_underscore ('*');
insert_and_underscore ('=');
insert_and_underscore ('-');
insert_and_underscore ('.');
cm_unnumberedsubsubsec ()
/* **************************************************************** */
/* Adding nodes, and making tags */
/* **************************************************************** */
/* Start a new tag table. */
while (tag_table
!= (TAG_ENTRY
*) NULL
)
TAG_ENTRY
*temp
= tag_table
;
tag_table
= tag_table
->next_ent
;
return (write_tag_table_internal (false)); /* Not indirect. */
write_tag_table_indirect ()
return (write_tag_table_internal (true));
/* Write out the contents of the existing tag table.
INDIRECT_P says how to format the output. */
write_tag_table_internal (indirect_p
)
TAG_ENTRY
*node
= tag_table
;
must_start_paragraph
= 0;
add_word_args ("\037\nTag Table:\n%s", indirect_p
? "(Indirect)\n" : "");
while (node
!= (TAG_ENTRY
*) NULL
)
add_word_args ("Node: %s\177%d\n", node
->node
, node
->position
);
add_word ("\037\nEnd Tag Table\n");
get_until_in_line (",", &string
);
/* Allow things like @@nodename. */
normalize_node_name (string
);
/* Given a node name in STRING, remove double @ signs, replacing them
normalize_node_name (string
)
register int i
, l
= strlen (string
);
if (string
[i
] == '@' && string
[i
+ 1] == '@')
strncpy (string
+ i
, string
+ i
+ 1, l
- i
);
/* Look up NAME in the tag table, and return the associated
tag_entry. If the node is not in the table return NULL. */
TAG_ENTRY
*tag
= tag_table
;
while (tag
!= (TAG_ENTRY
*) NULL
)
if (stricmp (tag
->node
, name
) == 0)
return ((TAG_ENTRY
*) NULL
);
/* Remember NODE and associates. */
remember_node (node
, prev
, next
, up
, position
, line_no
, no_warn
)
char *node
, *prev
, *next
, *up
;
int position
, line_no
, no_warn
;
/* Check for existence of this tag already. */
register TAG_ENTRY
*tag
= find_node (node
);
line_error ("Node `%s' multiply defined (%d is first definition)",
/* First, make this the current node. */
/* Now add it to the list. */
TAG_ENTRY
*new = (TAG_ENTRY
*) xmalloc (sizeof (TAG_ENTRY
));
new->position
= position
;
new->filename
= node_filename
;
new->touched
= 0; /* not yet referenced. */
new->next_ent
= tag_table
;
/* Here is a structure which associates sectioning commands with
an integer, hopefully to reflect the `depth' of the current
{ "unnumberedsubsec", 3},
{ "unnumberedsubsubsec", 4},
{ "appendixsubsubsec", 4},
/* Return an integer which identifies the type section present in TEXT. */
for (j
= 0; text
[j
] && whitespace (text
[j
]) || text
[j
] == '\n'; j
++);
/* Handle italicized sectioning commands. */
for (i
= 0; t
= section_alist
[i
].name
; i
++)
if (strncmp (t
, text
, strlen (t
)) == 0)
return (section_alist
[i
].level
);
/* The order is: nodename, nextnode, prevnode, upnode.
The next, prev, and up fields can be defaulted.
You must follow a node command which has those fields
defaulted with a sectioning command (e.g. @chapter) giving
the "level" of that node. It is an error not to do so.
The defaults come from the menu in this nodes parent. */
char *node
, *prev
, *next
, *up
;
int new_node_pos
, defaulting
, this_section
, no_warn
= 0;
extern int already_outputting_pending_notes
;
if (strcmp (command
, "nwnode") == 0)
/* Get rid of unmatched brace arguments from previous commands. */
/* There also might be insertions left lying around that haven't been
ended yet. Do that also. */
if (!already_outputting_pending_notes
)
filling_enabled
= indented_fill
= false;
new_node_pos
= output_position
+ 1;
node
= get_node_token ();
next
= get_node_token ();
prev
= get_node_token ();
this_section
= what_section (input_text
+ input_text_offset
);
/* ??? The first \n in the following string shouldn't be there, but I have
to revamp the @example & @group things so that they always leave a \n
as the last character output. Until that time, this is the only way
I can produce reliable output. */
add_word_args ("\n\037\nFile: %s, Node: %s", pretty_output_filename
, node
);
/* Check for defaulting of this node's next, prev, and up fields. */
defaulting
= ((strlen (next
) == 0) &&
/* If we are defaulting, then look at the immediately following
sectioning command (error if none) to determine the node's
level. Find the node that contains the menu mentioning this node
that is one level up (error if not found). That node is the "Up"
of this node. Default the "Next" and "Prev" from the menu. */
NODE_REF
*last_ref
= (NODE_REF
*)NULL
;
NODE_REF
*ref
= node_references
;
char *polite_section_name
= "chapter";
for (i
= 0; section_alist
[i
].name
; i
++)
if (section_alist
[i
].level
== current_section
+ 1)
polite_section_name
= section_alist
[i
].name
;
("Node `%s' requires a sectioning command (e.g. @%s)",
node
, polite_section_name
);
if (ref
->section
== (this_section
- 1) &&
ref
->type
== menu_reference
&&
stricmp (ref
->node
, node
) == 0)
up
= savestring (ref
->containing_node
);
(last_ref
->containing_node
, ref
->containing_node
) == 0)
next
= savestring (last_ref
->node
);
(ref
->next
->containing_node
, ref
->containing_node
) == 0)
prev
= savestring (ref
->next
->node
);
add_word_args (", Next: %s", next
);
add_word_args (", Prev: %s", prev
);
add_word_args (", Up: %s", up
);
line_error ("No node name specified for `@%s' command", command
);
if (!*next
) { free (next
); next
= (char *)NULL
; }
if (!*prev
) { free (prev
); prev
= (char *)NULL
; }
if (!*up
) { free (up
); up
= (char *)NULL
; }
remember_node (node
, prev
, next
, up
, new_node_pos
, line_number
, no_warn
);
/* Change the section only if there was a sectioning command. */
current_section
= this_section
;
/* Validation of an info file.
Scan through the list of tag entrys touching the Prev, Next, and Up
elements of each. It is an error not to be able to touch one of them,
except in the case of external node references, such as "(DIR)".
If the Prev is different from the Up,
then the Prev node must have a Next pointing at this node.
Every node except Top must have an Up.
The Up node must contain some sort of reference, other than a Next,
If the Next is different from the Next of the Up,
then the Next node must have a Prev pointing at this node. */
validate_file (filename
, tag_table
)
char *old_input_filename
= input_filename
;
TAG_ENTRY
*tags
= tag_table
;
while (tags
!= (TAG_ENTRY
*) NULL
)
register TAG_ENTRY
*temp_tag
;
input_filename
= tags
->filename
;
line_number
= tags
->line_no
;
/* If this node has a Next, then make sure that the Next exists. */
validate (tags
->next
, tags
->line_no
, "Next");
/* If the Next node exists, and there is no Up, then make
sure that the Prev of the Next points back. */
if (temp_tag
= find_node (tags
->next
))
char *prev
= temp_tag
->prev
;
if (!prev
|| (stricmp (prev
, tags
->node
) != 0))
("Node `%s''s Next field not pointed back to", tags
->node
);
line_number
= temp_tag
->line_no
;
input_filename
= temp_tag
->filename
;
("This node (`%s') is the one with the bad `Prev'",
input_filename
= tags
->filename
;
line_number
= tags
->line_no
;
temp_tag
->flags
|= PREV_ERROR
;
/* Validate the Prev field if there is one, and we haven't already
complained about it in some way. You don't have to have a Prev
if (!(tags
->flags
& PREV_ERROR
) && tags
->prev
)
int valid
= validate (tags
->prev
, tags
->line_no
, "Prev");
tags
->flags
|= PREV_ERROR
;
/* If the Prev field is not the same as the Up field,
then the node pointed to by the Prev field must have
a Next field which points to this node. */
if (tags
->up
&& (stricmp (tags
->prev
, tags
->up
) != 0))
temp_tag
= find_node (tags
->prev
);
(stricmp (temp_tag
->next
, tags
->node
) != 0))
line_error ("Node `%s''s Prev field not pointed back to",
line_number
= temp_tag
->line_no
;
input_filename
= temp_tag
->filename
;
("This node (`%s') is the one with the bad `Next'",
input_filename
= tags
->filename
;
line_number
= tags
->line_no
;
temp_tag
->flags
|= NEXT_ERROR
;
if (!tags
->up
&& (stricmp (tags
->node
, "Top") != 0))
line_error ("Node `%s' is missing an \"Up\" field", tags
->node
);
int valid
= validate (tags
->up
, tags
->line_no
, "Up");
/* If node X has Up: Y, then warn if Y fails to have a menu item
or note pointing at X, if Y isn't of the form "(Y)". */
if (valid
&& *tags
->up
!= '(')
NODE_REF
*nref
, *tref
, *list
;
NODE_REF
*find_node_reference ();
tref
= (NODE_REF
*) NULL
;
if (!(nref
= find_node_reference (tags
->node
, list
)))
if (stricmp (nref
->containing_node
, tags
->up
) == 0)
if (nref
->type
!= menu_reference
)
temp_tag
= find_node (tags
->up
);
line_number
= temp_tag
->line_no
;
filename
= temp_tag
->filename
;
line_error ("`%s' has an Up field of `%s', but `%s' has no menu item for `%s'",
tags
->node
, tags
->up
, tags
->up
, tags
->node
);
line_number
= tags
->line_no
;
filename
= tags
->filename
;
validate_other_references (node_references
);
/* We have told the user about the references which didn't exist.
Now tell him about the nodes which aren't referenced. */
while (tags
!= (TAG_ENTRY
*) NULL
)
/* Special hack. If the node in question appears to have
been referenced more than REFERENCE_WARNING_LIMIT times,
if (tags
->touched
> reference_warning_limit
)
input_filename
= tags
->filename
;
line_number
= tags
->line_no
;
warning ("Node `%s' has been referenced %d times",
tags
->node
, tags
->touched
);
input_filename
= tags
->filename
;
line_number
= tags
->line_no
;
/* Notice that the node "Top" is special, and doesn't have to
if (stricmp (tags
->node
, "Top") != 0)
warning ("Unreferenced node `%s'", tags
->node
);
input_filename
= old_input_filename
;
/* Return 1 if tag correctly validated, or 0 if not. */
validate (tag
, line
, label
)
/* If there isn't a tag to verify, or if the tag is in another file,
if (!tag
|| !*tag
|| *tag
== '(')
/* Otherwise, the tag must exist. */
result
= find_node (tag
);
line_error ("Validation error. `%s' field points to node `%s', which doesn't exist",
/* Split large output files into a series of smaller files. Each file
is pointed to in the tag table, which then gets written out as the
original file. The new files have the same name as the original file
with a "-num" attached. SIZE is the largest number of bytes to allow
in any single split file. */
split_file (filename
, size
)
char *root_filename
, *root_pathname
;
char *the_file
, *filename_part ();
/* Can only do this to files with tag tables. */
size
= DEFAULT_SPLIT_SIZE
;
if ((stat (filename
, &fileinfo
) != 0) ||
(fileinfo
.st_size
< SPLIT_SIZE_THRESHOLD
))
the_file
= find_and_load (filename
);
root_filename
= filename_part (filename
);
root_pathname
= pathname_part (filename
);
root_pathname
= savestring ("");
/* Start splitting the file. Walk along the tag table
outputting sections of the file. When we have written
all of the nodes in the tag table, make the top-level
pointer file, which contains indirect pointers and
TAG_ENTRY
*tags
= tag_table
;
char *indirect_info
= (char *)NULL
;
/* Remember the `header' of this file. The first tag in the file is
the bottom of the header; the top of the file is the start. */
the_header
= xmalloc (1 + (header_size
= (tags
->position
- 2)));
bcopy (the_file
, the_header
, header_size
);
int file_top
, file_bot
, limit
;
/* Have to include the Control-_. */
file_top
= file_bot
= tags
->position
- 2;
/* If the rest of this file is only one node, then
that is the entire subfile. */
int i
= tags
->position
+ 1;
char last_char
= the_file
[i
];
while (i
< fileinfo
.st_size
)
if ((the_file
[i
] == '\037') &&
/* Otherwise, find the largest number of nodes that can fit in
for (; tags
; tags
= tags
->next_ent
)
/* This entry is the last node. Search forward for the end
of this node, and that is the end of this file. */
int i
= tags
->position
+ 1;
char last_char
= the_file
[i
];
while (i
< fileinfo
.st_size
)
if ((the_file
[i
] == '\037') &&
/* Here we want to write out everything before the last
node, and then write the last node out in a file
file_bot
= tags
->position
;
if (tags
->next_ent
->position
> limit
)
if ((tags
->position
) - 2 == file_top
)
file_bot
= tags
->position
;
char *split_file
= xmalloc (10 + strlen (root_pathname
)
+ strlen (root_filename
));
"%s%s-%d", root_pathname
, root_filename
, which_file
);
if (((fd
= open (split_file
, O_WRONLY
| O_TRUNC
| O_CREAT
, 0666)) < 0)
|| (write (fd
, the_header
, header_size
) != header_size
)
|| (write (fd
, the_file
+ file_top
, file_bot
- file_top
)
!= (file_bot
- file_top
))
indirect_info
= the_file
+ file_top
;
sprintf (indirect_info
, "\037\nIndirect:\n");
indirect_info
+= strlen (indirect_info
);
sprintf (indirect_info
, "%s-%d: %d\n",
root_filename
, which_file
, file_top
);
indirect_info
+= strlen (indirect_info
);
/* We have sucessfully created the subfiles. Now write out the
original again. We must use `output_stream', or
write_tag_table_indirect () won't know where to place the output. */
output_stream
= fopen (filename
, "w");
int distance
= indirect_info
- the_file
;
fwrite (the_file
, 1, distance
, output_stream
);
paragraph_is_open
= false;
write_tag_table_indirect ();
/* Some menu hacking. This is used to remember menu references while
reading the input file. After the output file has been written, if
validation is on, then we use the contents of NODE_REFERENCES as a
list of nodes to validate. */
reftype_type_string (type
)
return ("Followed-Reference");
return ("Internal-bad-reference-type");
/* Remember this node name for later validation use. */
remember_node_reference (node
, line
, type
)
NODE_REF
*temp
= (NODE_REF
*) xmalloc (sizeof (NODE_REF
));
temp
->next
= node_references
;
temp
->node
= savestring (node
);
temp
->section
= current_section
;
temp
->containing_node
= savestring (current_node
);
temp
->filename
= node_filename
;
validate_other_references (ref_list
)
register NODE_REF
*ref_list
;
char *old_input_filename
= input_filename
;
while (ref_list
!= (NODE_REF
*) NULL
)
input_filename
= ref_list
->filename
;
validate (ref_list
->node
, ref_list
->line_no
,
reftype_type_string (ref_list
->type
));
ref_list
= ref_list
->next
;
input_filename
= old_input_filename
;
/* Find NODE in REF_LIST. */
find_node_reference (node
, ref_list
)
register NODE_REF
*ref_list
;
if (stricmp (node
, ref_list
->node
) == 0)
ref_list
= ref_list
->next
;
register NODE_REF
*list
, *temp
;
free (list
->containing_node
);
node_references
= (NODE_REF
*) NULL
;
#define menu_starter "* "
/* This function gets called at the start of every line while inside of
a menu. It checks to see if the line starts with "* ", and if so,
remembers the node reference that this menu refers to.
input_text_offset is at the \n just before the line start. */
int i
, orig_offset
= input_text_offset
;
if (strncmp (&input_text
[input_text_offset
+ 1],
strlen (menu_starter
)) != 0)
input_text_offset
+= strlen (menu_starter
) + 1;
get_until_in_line (":", &nodename
);
get_rest_of_line (&nodename
);
/* Special hack: If the nodename follows the menu item name,
then we have to read the rest of the line in order to find
out what the nodename is. But we still have to read the
line later, in order to process any formatting commands that
might be present. So un-count the carriage return that has just
for (i
= 0; i
< strlen (nodename
); i
++)
if (nodename
[i
] == '\t' ||
normalize_node_name (nodename
);
if (i
&& nodename
[i
- 1] == ':')
remember_node_reference (nodename
, line_number
, menu_reference
);
input_text_offset
= orig_offset
;
/* **************************************************************** */
/* Cross Reference Hacking */
/* **************************************************************** */
get_until_in_braces (",", &string
);
normalize_node_name (string
);
int px_ref_flag
= 0; /* Controls initial output string. */
/* Make a cross reference. */
char *arg1
, *arg2
, *arg3
, *arg4
, *arg5
;
arg1
= get_xref_token ();
arg2
= get_xref_token ();
arg3
= get_xref_token ();
arg4
= get_xref_token ();
arg5
= get_xref_token ();
add_word_args ("%s", px_ref_flag
? "*note " : "*Note ");
add_word_args ("%s: (%s)%s", arg2
, arg4
, arg1
);
remember_node_reference (arg1
, line_number
, followed_reference
);
add_word_args ("%s: %s", arg3
, arg1
);
add_word_args ("%s: %s", arg2
, arg1
);
execute_string ("%s", arg2
);
add_word_args (": %s", arg1
);
add_word_args ("%s::", arg1
);
/* Check to make sure that the next non-whitespace character is either
a period or a comma. input_text_offset is pointing at the "}" which
ended the xref or pxref command. */
int temp
= input_text_offset
+ 1;
if (output_paragraph
[output_paragraph_offset
- 2] == ':' &&
output_paragraph
[output_paragraph_offset
- 1] == ':')
while (temp
< size_of_input_text
)
if (cr_or_whitespace (input_text
[temp
]))
if (input_text
[temp
] == '.' ||
input_text
[temp
] == ',' ||
input_text
[temp
] == '\t')
line_error ("Cross-reference must be terminated with a period or a comma");
char *node
, *pname
, *file
;
node
= get_xref_token ();
pname
= get_xref_token ();
file
= get_xref_token ();
add_word_args ("*note %s: (%s)%s", pname
, file
, node
);
/* **************************************************************** */
/* Insertion Command Stubs */
/* **************************************************************** */
begin_insertion (quotation
);
begin_insertion (example
);
begin_insertion (smallexample
);
begin_insertion (format
);
begin_insertion (display
);
begin_insertion (itemize
);
begin_insertion (enumerate
);
begin_insertion (ifinfo
);
discard_until ("\n@end tex");
discard_until ("\n@end iftex");
discard_until ("\n@end titlespec");
discard_until ("\n@end titlepage");
discard_until ("\n@end ignore");
/* **************************************************************** */
/* **************************************************************** */
/* Non-zero means a string is in execution, as opposed to a file. */
int executing_string
= 0;
/* Execute the string produced by formatting the ARGs with FORMAT. This
is like submitting a new file with @include. */
execute_string (format
, arg1
, arg2
, arg3
, arg4
, arg5
)
static char temp_string
[4000];
sprintf (temp_string
, format
, arg1
, arg2
, arg3
, arg4
, arg5
);
strcat (temp_string
, "@bye\n");
input_text
= temp_string
;
input_filename
= savestring (input_filename
);
size_of_input_text
= strlen (temp_string
);
free_and_clear (&command
);
command
= savestring ("not bye");
char *rest_of_line
, *item_func
;
/* Can only hack "@item" while inside of an insertion. */
get_until ("\n", &rest_of_line
);
canon_white (rest_of_line
);
item_func
= current_item_function ();
/* Okay, do the right thing depending on which insertion function
switch (current_insertion_type ())
line_error ("The `@%s' command is meaningless within a `@%s' block",
insertion_type_pname (current_insertion_type ()));
line_error ("@itemx is not meaningful inside of a `%s' block",
insertion_type_pname (current_insertion_type ()));
filling_enabled
= indented_fill
= true;
if (current_insertion_type () == itemize
)
indent (output_column
= current_indent
- 2);
/* I need some way to determine whether this command
takes braces or not. I believe the user can type
either "@bullet" or "@bullet{}". Of course, they
can also type "o" or "#" or whatever else they want. */
if (item_func
&& *item_func
)
if (item_func
[strlen (item_func
) - 1] != '}')
execute_string ("%s{}", item_func
);
execute_string ("%s", item_func
);
execute_string ("%s", item_func
);
/* Special hack. This makes close paragraph ignore you until
the start_paragraph () function has been called. */
must_start_paragraph
= 1;
/* Get rid of extra characters. */
/* close_paragraph () almost does what we want. The problem
is when paragraph_is_open, and last_char_was_newline, and
the last newline has been turned into a space, because
filling_enabled. I handle it here. */
if (last_char_was_newline
&& filling_enabled
&& paragraph_is_open
)
/* Indent on a new line, but back up one indentation level. */
/* force existing indentation. */
output_paragraph_offset
--;
kill_self_indent (default_indentation_increment
+ 1);
/* Add item's argument to the line. */
if (!item_func
&& !(*item_func
))
execute_string ("%s", rest_of_line
);
execute_string ("%s{%s}", item_func
, rest_of_line
);
/* Start a new line, and let start_paragraph ()
do the indenting of it for you. */
close_single_paragraph ();
indented_fill
= filling_enabled
= true;
line_error ("@%s found outside of an insertion block", command
);
/* **************************************************************** */
/* **************************************************************** */
/* The list of args that were passed to the def**** command. */
char **defun_args
= (char **)NULL
;
/* An alist mapping defun insertion types to the text that we use
enum insertion_type type
;
{ defspec
, "Special form" },
{ (enum insertion_type
)0, (char *)NULL
}
/* Return the title string for this type of defun. */
enum insertion_type type
;
for (i
= 0; type_title_alist
[i
].type
|| type_title_alist
[i
].title
; i
++)
if (type_title_alist
[i
].type
== type
)
return (type_title_alist
[i
].title
);
/* Return a list of words from the contents of STRING.
You can group words with braces. */
args_from_string (string
)
char **result
= (char **) NULL
;
register int i
, start
, result_index
, size
;
int len
, skip_til_brace
= 0;
i
= result_index
= size
= 0;
/* Get a token, and stuff it into RESULT. The tokens are split
/* Skip leading whitespace. */
for (; string
[i
] && whitespace (string
[i
]); i
++);
/* If this is a command which takes it's argument in braces, then
gobble the whole thing. */
if (string
[i
] == COMMAND_PREFIX
)
!whitespace (string
[j
]) &&
while (string
[j
] && string
[j
] != '}')
if (string
[i
] == '{' && !whitespace (string
[i
+ 1]))
/* Skip until whitespace or close brace. */
((skip_til_brace
&& string
[i
] != '}') ||
(!skip_til_brace
&& !whitespace (string
[i
]))))
if (result_index
+ 2 >= size
)
result
= (char **) xmalloc ((size
= 10) * (sizeof (char *)));
(char **) xrealloc (result
, ((size
+= 10) * (sizeof (char *))));
result
[result_index
] = (char *) xmalloc (1 + len
);
strncpy (result
[result_index
], string
+ start
, len
);
result
[result_index
][len
] = '\0';
result
[result_index
] = (char *) NULL
;
get_rest_of_line (&line
);
for (i
= 0; defun_args
[i
]; i
++)
defun_args
= args_from_string (line
);
insert_defun_arg (string
, where
)
for (i
= 0; defun_args
[i
]; i
++);
defun_args
= (char **)xrealloc (defun_args
, (i
+ 2) * sizeof (char *));
defun_args
[i
+ 1] = (char *)NULL
;
defun_args
[i
] = defun_args
[i
- 1];
defun_args
[i
] = savestring (string
);
/* Make the defun type insertion.
TYPE says which insertion this is.
TITLE is the string to describe the object being described, or NULL
X_P says not to start a new insertion if non-zero. */
defun_internal (type
, title
, x_p
)
enum insertion_type type
;
char *type_name
, *func_name
;
int old_no_indent
= no_indent
;
insert_defun_arg (title
, 0);
type_name
= defun_args
[0];
func_name
= defun_args
[1];
execute_string (" * %s: %s", type_name
, func_name
);
no_indent
= old_no_indent
;
for (; defun_args
[i
]; i
++)
if (*defun_args
[i
] == '&')
add_word_args (" %s", defun_args
[i
]);
execute_string (" @var{%s}", defun_args
[i
]);
if (type
== defvar
|| type
== defopt
)
execute_string ("@vindex %s\n", func_name
);
execute_string ("@findex %s\n", func_name
);
/* Add an entry for a function, macro, special form, variable, or option.
If the name of the calling command ends in `x', then this is an extra
entry included in the body of an insertion of the same type. */
enum insertion_type type
;
char *title
, *temp
= savestring (command
);
x_p
= (command
[strlen (command
) - 1] == 'x');
temp
[strlen (temp
) - 1] = '\0';
type
= find_type_from_name (temp
);
/* If we are adding to an already existing insertion, then make sure
that we are already in an insertion of type TYPE. */
(!insertion_level
|| insertion_stack
->insertion
!= type
))
line_error ("Must be in a `%s' insertion in order to use `%s'x",
title
= defun_title (type
);
defun_internal (type
, title
, x_p
);
/* End existing insertion block. */
enum insertion_type type
;
line_error ("Unmatched `@%s'", command
);
get_rest_of_line (&temp
);
line_error ("`@%s' needs something after it", command
);
type
= find_type_from_name (temp
);
line_error ("Bad argument to `%s', `%s', using `%s'",
command
, temp
, insertion_type_pname (current_insertion_type ()));
/* **************************************************************** */
/* Other Random Commands */
/* **************************************************************** */
/* noindent () used to do something valueable, but it didn't follow the
spec for noindent in the texinfo manual. Now it does nothing, which,
in the case of makeinfo, is correct. */
indented_fill = false; */
/* I don't know exactly what to do with this. Should I allow
someone to switch filenames in the middle of output? Since the
file could be partially written, this doesn't seem to make sense.
Another option: ignore it, since they don't *really* want to
switch files. Finally, complain, or at least warn. */
get_rest_of_line (&filename
);
/* warning ("`@%s %s' encountered and ignored", command, filename); */
/* Insert the number of blank lines passed as argument. */
/* close_paragraph (); */
get_rest_of_line (&line
);
sscanf (line
, "%d", &lines
);
/* Start a new line with just this text on it.
Then center the line of text.
This always ends the current paragraph. */
filling_enabled
= indented_fill
= false;
get_rest_of_line (&line
);
if (strlen (line
) < fill_column
)
int i
= (fill_column
- strlen (line
)) / 2;
/* Show what an expression returns. */
/* What an expression expands to. */
/* Indicates two expressions are equivalent. */
/* What an expression may print. */
/* The location of point in an example of a buffer. */
/* Start a new line with just this text on it.
The text is outdented one level if possible. */
current_indent
-= default_indentation_increment
;
get_rest_of_line (&line
);
close_single_paragraph ();
add_word_args ("%s", line
);
close_single_paragraph ();
/* Remember this file, and move onto the next. */
get_rest_of_line (&filename
);
/* In verbose mode we print info about including another file. */
register FSTACK
*stack
= filestack
;
for (i
= 0, stack
= filestack
; stack
; stack
= stack
->next
, i
++);
printf ("%c%s %s\n", COMMAND_PREFIX
, command
, filename
);
if (!find_and_load (filename
))
extern char *sys_errlist
[];
extern int errno
, sys_nerr
;
/* Cannot "@include foo", in line 5 of "/wh/bar". */
line_error ("`%c%s %s': %s", COMMAND_PREFIX
, command
, filename
,
sys_errlist
[errno
] : "Unknown file system error"));
/* The other side of a malformed expression. */
line_error ("Misplaced `}'");
/* Don't let the filling algorithm insert extra whitespace here. */
cm_force_abbreviated_whitespace ()
/* Make the output paragraph end the sentence here, even though it
looks like it shouldn't. This also inserts the character which
add_char (META ((*command
)));
/* Signals end of processing. Easy to make this happen. */
input_text_offset
= size_of_input_text
;
/* **************************************************************** */
/* **************************************************************** */
/* An index element... */
char *entry
; /* The index entry itself. */
char *node
; /* The node from whence it came. */
int code
; /* Non-zero means add `@code{...}' when
printing this element. */
/* A list of short-names for each index, and the index to that index in our
index array, the_indices. In addition, for each index, it is remembered
whether that index is a code index or not. Code indices have @code{}
inserted around the first word when they are printed with printindex. */
INDEX_ALIST
**name_index_alist
= (INDEX_ALIST
**) NULL
;
/* An array of pointers. Each one is for a different index. The
"synindex" command changes which array slot is pointed to by a
INDEX_ELT
**the_indices
= (INDEX_ELT
**) NULL
;
/* The number of defined indices. */
/* We predefine these. */
/* Create the default data structures. */
/* Initialize data space. */
the_indices
= (INDEX_ELT
**) xmalloc ((1 + defined_indices
) *
the_indices
[defined_indices
] = (INDEX_ELT
*) NULL
;
name_index_alist
= (INDEX_ALIST
**) xmalloc ((1 + defined_indices
) *
name_index_alist
[defined_indices
] = (INDEX_ALIST
*) NULL
;
/* If there were existing indices, get rid of them now. */
for (i
= 0; i
< defined_indices
; i
++)
undefindex (name_index_alist
[i
]->name
);
/* Add the default indices. */
defindex ("fn", 1); /* "fn" is a code index. */
/* Find which element in the known list of indices has this name.
Returns -1 if NAME isn't found. */
for (i
= 0; i
< defined_indices
; i
++)
if (name_index_alist
[i
] &&
stricmp (name
, name_index_alist
[i
]->name
) == 0)
return (name_index_alist
[i
]->index
);
/* Return a pointer to the entry of (name . index) for this name.
Return NULL if the index doesn't exist. */
int offset
= find_index_offset (name
);
return (name_index_alist
[offset
]);
return ((INDEX_ALIST
*) NULL
);
/* Given an index name, return the offset in the_indices of this index,
or -1 if there is no such index. */
INDEX_ALIST
*which
= find_index (name
);
/* Return the index list which belongs to NAME. */
int which
= translate_index (name
);
return ((INDEX_ELT
*) - 1);
return (the_indices
[which
]);
/* Please release me, let me go... */
while ((temp
= index
) != (INDEX_ELT
*) NULL
)
/* Flush an index by name. */
int which
= find_index_offset (name
);
i
= name_index_alist
[which
]->index
;
free_index (the_indices
[i
]);
the_indices
[i
] = (INDEX_ELT
*) NULL
;
free (name_index_alist
[which
]->name
);
free (name_index_alist
[which
]);
name_index_alist
[which
] = (INDEX_ALIST
*) NULL
;
/* Define an index known as NAME. We assign the slot number.
CODE if non-zero says to make this a code index. */
/* If it already exists, flush it. */
/* Try to find an empty slot. */
for (i
= 0; i
< defined_indices
; i
++)
if (!name_index_alist
[i
])
/* No such luck. Make space for another index. */
name_index_alist
= (INDEX_ALIST
**) xrealloc (name_index_alist
,
* sizeof (INDEX_ALIST
*));
the_indices
= (INDEX_ELT
**) xrealloc (the_indices
,
/* We have a slot. Start assigning. */
name_index_alist
[slot
] = (INDEX_ALIST
*) xmalloc (sizeof (INDEX_ALIST
));
name_index_alist
[slot
]->name
= savestring (name
);
name_index_alist
[slot
]->index
= slot
;
name_index_alist
[slot
]->code
= code
;
the_indices
[slot
] = (INDEX_ELT
*) NULL
;
/* Add the arguments to the current index command to the index NAME. */
which
= tem
? tem
->index
: -1;
/* close_paragraph (); */
get_rest_of_line (&index_entry
);
line_error ("Unknown index reference `%s'", name
);
INDEX_ELT
*new = (INDEX_ELT
*) xmalloc (sizeof (INDEX_ELT
));
new->next
= the_indices
[which
];
new->entry
= index_entry
;
new->node
= current_node
;
the_indices
[which
] = new;
#define INDEX_COMMAND_SUFFIX "index"
/* The function which user defined index commands call. */
char *name
= savestring (command
);
if (strlen (name
) >= strlen ("index"))
name
[strlen (name
) - strlen ("index")] = '\0';
/* Define a new index command. Arg is name of index. */
get_rest_of_line (&name
);
line_error ("Index `%s' already exists", name
);
char *temp
= (char *) alloca (1 + strlen (name
) + strlen ("index"));
sprintf (temp
, "%sindex", name
);
define_user_command (temp
, gen_index
, 0);
/* Append LIST2 to LIST1. Return the head of the list. */
index_append (head
, tail
)
register INDEX_ELT
*t_head
= head
;
/* Expects 2 args, on the same line. Both are index abbreviations.
Make the first one be a synonym for the second one, i.e. make the
first one have the same index as the second one. */
int redirector
, redirectee
;
get_until_in_line (" ", &temp
);
redirectee
= find_index_offset (temp
);
get_until_in_line (" ", &temp
);
redirector
= find_index_offset (temp
);
if (redirector
< 0 || redirectee
< 0)
line_error ("Unknown index reference");
/* I think that we should let the user make indices synonymous to
each other without any lossage of info. This means that one can
say @synindex cp dt anywhere in the file, and things that used to
be in cp will go into dt. */
INDEX_ELT
*i1
= the_indices
[redirectee
], *i2
= the_indices
[redirector
];
the_indices
[redirectee
] = index_append (i1
, i2
);
the_indices
[redirectee
] = index_append (i2
, i1
);
name_index_alist
[redirectee
]->index
=
name_index_alist
[redirector
]->index
;
cm_pindex () /* Pinhead index. */
cm_vindex () /* variable index */
cm_kindex () /* key index */
cm_cindex () /* concept index */
cm_findex () /* function index */
cm_tindex () /* data type index */
index_element_compare (element1
, element2
)
INDEX_ELT
**element1
, **element2
;
/* This needs to ignore leading non-text characters. */
return (strcmp ((*element1
)->entry
, (*element2
)->entry
));
/* Sort the index passed in INDEX, returning an array of
pointers to elements. The array is terminated with a NULL
pointer. We call qsort because it's supposed to be fast.
I think this looks bad. */
while (temp
!= (INDEX_ELT
*) NULL
)
/* We have the length. Make an array. */
array
= (INDEX_ELT
**) xmalloc ((count
+ 1) * sizeof (INDEX_ELT
*));
while (temp
!= (INDEX_ELT
*) NULL
)
array
[count
] = (INDEX_ELT
*) NULL
; /* terminate the array. */
qsort (array
, count
, sizeof (INDEX_ELT
*), index_element_compare
);
/* Non-zero means that we are in the middle of printing an index. */
/* Takes one arg, a short name of an index to print.
Outputs a menu of the sorted elements of the index. */
int old_inhibitions
= inhibit_paragraph_indentation
;
boolean previous_filling_enabled_value
= filling_enabled
;
get_rest_of_line (&index_name
);
index
= index_list (index_name
);
line_error ("Unknown index name `%s'", index_name
);
array
= sort_index (index
);
inhibit_paragraph_indentation
= 1;
add_word ("* Menu:\n\n");
for (item
= 0; (index
= array
[item
]); item
++)
/* If this particular entry should be printed as a "code" index,
then wrap the entry with "@code{...}". */
execute_string ("* @code{%s}: %s.\n", index
->entry
, index
->node
);
execute_string ("* %s: %s.\n", index
->entry
, index
->node
);
filling_enabled
= previous_filling_enabled_value
;
inhibit_paragraph_indentation
= old_inhibitions
;
/* **************************************************************** */
/* Making User Defined Commands */
/* **************************************************************** */
define_user_command (name
, proc
, needs_braces_p
)
int slot
= user_command_array_len
;
user_command_array_len
++;
user_command_array
= (COMMAND
**) xmalloc (1 * sizeof (COMMAND
*));
user_command_array
= (COMMAND
**) xrealloc (user_command_array
,
(1 + user_command_array_len
) *
user_command_array
[slot
] = (COMMAND
*) xmalloc (sizeof (COMMAND
));
user_command_array
[slot
]->name
= savestring (name
);
user_command_array
[slot
]->proc
= proc
;
user_command_array
[slot
]->argument_in_braces
= needs_braces_p
;
/* Make ALIAS run the named FUNCTION. Copies properties from FUNCTION. */
define_alias (alias
, function
)
/* Some support for footnotes. */
/* Footnotes are a new construct in Info. We don't know the best method
of implementing them for sure, so we present two possiblities.
MN 1) Make them look like followed references, with the reference
destinations in a makeinfo manufactured node or,
BN 2) Make them appear at the bottom of the node that they originally
boolean first_footnote_this_node
= true;
/* Set the footnote style based on he style identifier in STRING. */
set_footnote_style (string
)
if (stricmp (string
, "MN") == 0)
if (stricmp (string
, "BN") == 0)
FN
*pending_notes
= (FN
*) NULL
;
/* A method for remembering footnotes. Note that this list gets output
at the end of the current node. */
remember_note (marker
, note
)
FN
*temp
= (FN
*) xmalloc (sizeof (FN
));
temp
->marker
= savestring (marker
);
temp
->note
= savestring (note
);
temp
->next
= pending_notes
;
/* How to get rid of existing footnotes. */
while ((temp
= pending_notes
) != (FN
*) NULL
)
pending_notes
= pending_notes
->next
;
first_footnote_this_node
= true;
/* What to do when you see a @footnote construct. */
footnote *{this is a footnote}
where "*" is the marker character for this note. */
get_until ("{", &marker
);
/* Read the argument in braces. */
line_error ("`@%s' expected more than just `%s'. It needs something in `{...}'", command
, marker
);
int temp
= ++input_text_offset
;
if (temp
== size_of_input_text
)
line_error ("No closing brace for footnote `%s'", marker
);
if (input_text
[temp
] == '{')
else if (input_text
[temp
] == '}')
len
= (temp
- input_text_offset
) - 1;
note
= xmalloc (len
+ 1);
strncpy (note
, &input_text
[input_text_offset
], len
);
input_text_offset
= temp
;
if (!current_node
|| !*current_node
)
line_error ("Footnote defined without parent node");
remember_note (marker
, note
);
{ /* your method should at least insert marker. */
add_word_args ("(%s)", marker
);
if (first_footnote_this_node
)
char *temp_string
= xmalloc ((strlen (current_node
))
+ (strlen ("-Footnotes")) + 1);
add_word_args (" (*note %s-Footnotes::)", current_node
);
strcpy (temp_string
, current_node
);
strcat (temp_string
, "-Footnotes");
remember_node_reference (temp_string
, line_number
, followed_reference
);
first_footnote_this_node
= false;
add_word_args ("(%s)", marker
);
/* Non-zero means that we are currently in the process of outputting
int already_outputting_pending_notes
= 0;
/* Output the footnotes. We are at the end of the current node. */
FN
*footnote
= pending_notes
;
char *old_current_node
= current_node
;
char *old_command
= savestring (command
);
already_outputting_pending_notes
++;
execute_string ("@node %s-Footnotes,,,%s\n", current_node
, current_node
);
already_outputting_pending_notes
--;
current_node
= old_current_node
;
execute_string ("---------- Footnotes ----------\n\n");
/* Handle the footnotes in reverse order. */
FN
**array
= (FN
**) xmalloc ((footnote_count
+ 1) * sizeof (FN
*));
array
[footnote_count
] = (FN
*) NULL
;
while (--footnote_count
> -1)
array
[footnote_count
] = footnote
;
footnote
= footnote
->next
;
while (footnote
= array
[++footnote_count
])
execute_string ("(%s) %s", footnote
->marker
, footnote
->note
);
* compile-command: "gcc -g -Bstatic -o makeinfo makeinfo.c getopt.c"