/* @documentlanguage. Maybe we'll do something useful with this in the future. For now, we just recognize it. */ void cm_documentlanguage () { language_code_type c; char *lang_arg; /* Read the line with the language code on it. */ get_rest_of_line (0, &lang_arg); /* Linear search is fine these days. */ for (c = aa; c != last_language_code; c++) { if (strcmp (lang_arg, language_table[c].abbrev) == 0) { /* Set current language code. */ language_code = c; break; } } /* If we didn't find this code, complain. */ if (c == last_language_code) warning (_("%s is not a valid ISO 639 language code"), lang_arg); free (lang_arg); }
void cm_footnotestyle (void) { char *arg; get_rest_of_line (1, &arg); /* If set on command line, do not change the footnote style. */ if (!footnote_style_preset && set_footnote_style (arg) != 0) line_error (_("Bad argument to %c%s"), COMMAND_PREFIX, command); free (arg); }
/* Make the defun type insertion. TYPE says which insertion this is. X_P, if nonzero, says not to start a new insertion. */ static void defun_internal (int type, int x_p) { int base_type; char **defun_args, **scan_args; const char *category; char *defined_name; char *type_name = NULL; char *type_name2 = NULL; { char *line; /* The @def.. line is the only place in Texinfo where you are allowed to use unquoted braces that don't delimit arguments of a command or a macro; in any other place it will trigger an error message from the reader loop. The special handling of this case inside `args_from_string' is an extra special hack which allows this. The side effect is that if we try to expand the rest of the line below, the recursive reader loop will signal an error if there are brace-delimited arguments on that line. The best solution to this would be to change the syntax of @def.. commands so that it doesn't violate Texinfo's own rules. But it's probably too late for this now, as it will break a lot of existing manuals. Unfortunately, this means that you can't call macros, use @value, etc. inside @def.. commands, sigh. */ get_rest_of_line (0, &line); /* Basic line continuation. If a line ends with \s*@\s* concatanate the next line. */ { char *next_line, *new_line; int i; line_continuation: i = strlen (line) - 1; if (line[i] == '@' && line[i-1] != '@') { get_rest_of_line (0, &next_line); new_line = (char *) xmalloc (i + strlen (next_line) + 2); strncpy (new_line, line, i); new_line[i] = '\0'; free (line); strcat (new_line, " "); strcat (new_line, next_line); line = xstrdup (new_line); free (next_line); free (new_line); goto line_continuation; } } defun_args = (args_from_string (line)); free (line); } scan_args = defun_args; /* Get base type and category string. */ base_type = get_base_type (type); /* xx all these const strings should be determined upon documentlanguage argument and NOT via gettext (kama). */ switch (type) { case defun: case deftypefun: category = _("Function"); break; case defmac: category = _("Macro"); break; case defspec: category = _("Special Form"); break; case defvar: case deftypevar: category = _("Variable"); break; case defopt: category = _("User Option"); break; case defivar: case deftypeivar: category = _("Instance Variable"); break; case defmethod: case deftypemethod: category = _("Method"); break; default: category = next_nonwhite_defun_arg (&scan_args); break; } /* The class name. */ if ((base_type == deftypecv) || (base_type == deftypefn) || (base_type == deftypevr) || (base_type == defcv) || (base_type == defop) || (base_type == deftypeivar) || (base_type == deftypemethod) || (base_type == deftypeop) ) type_name = next_nonwhite_defun_arg (&scan_args); /* The type name for typed languages. */ if ((base_type == deftypecv) || (base_type == deftypeivar) || (base_type == deftypemethod) || (base_type == deftypeop) ) type_name2 = next_nonwhite_defun_arg (&scan_args); /* The function or whatever that's actually being defined. */ defined_name = next_nonwhite_defun_arg (&scan_args); /* This hack exists solely for the purposes of formatting the Texinfo manual. I couldn't think of a better way. The token might be a simple @@ followed immediately by more text. If this is the case, then the next defun arg is part of this one, and we should concatenate them. */ if (*scan_args && **scan_args && !whitespace (**scan_args) && STREQ (defined_name, "@@")) { char *tem = xmalloc (3 + strlen (scan_args[0])); sprintf (tem, "@@%s", scan_args[0]); free (scan_args[0]); scan_args[0] = tem; scan_args++; defined_name = tem; } /* It's easy to write @defun foo(arg1 arg2), but a following ( is misparsed by texinfo.tex and this is next to impossible to fix. Warn about it. */ if (*scan_args && **scan_args && **scan_args == '(') warning ("`%c' follows defined name `%s' instead of whitespace", **scan_args, defined_name); if (!x_p) begin_insertion (type); /* Write the definition header line. This should start at the normal indentation. */ current_indent -= default_indentation_increment; start_paragraph (); if (!html && !xml) switch (base_type) { case deffn: case defvr: case deftp: execute_string (" --- %s: %s", category, defined_name); break; case deftypefn: case deftypevr: execute_string (" --- %s: %s %s", category, type_name, defined_name); break; case defcv: execute_string (" --- %s %s %s: %s", category, _("of"), type_name, defined_name); break; case deftypecv: case deftypeivar: execute_string (" --- %s %s %s: %s %s", category, _("of"), type_name, type_name2, defined_name); break; case defop: execute_string (" --- %s %s %s: %s", category, _("on"), type_name, defined_name); break; case deftypeop: execute_string (" --- %s %s %s: %s %s", category, _("on"), type_name, type_name2, defined_name); break; case deftypemethod: execute_string (" --- %s %s %s: %s %s", category, _("on"), type_name, type_name2, defined_name); break; } else if (html) { /* If this is not a @def...x version, it could only be a normal version @def.... So start the table here. */ if (!x_p) insert_string ("<div class=\"defun\">\n"); else rollback_empty_tag ("blockquote"); /* xx The single words (on, off) used here, should depend on documentlanguage and NOT on gettext --kama. */ switch (base_type) { case deffn: case defvr: case deftp: case deftypefn: case deftypevr: execute_string ("--- %s: ", category); break; case defcv: case deftypecv: case deftypeivar: execute_string ("--- %s %s %s: ", category, _("of"), type_name); break; case defop: case deftypemethod: case deftypeop: execute_string ("--- %s %s %s: ", category, _("on"), type_name); break; } /* switch (base_type)... */ switch (base_type) { case deffn: case defvr: case deftp: /* <var> is for the following function arguments. */ insert_html_tag (START, "b"); execute_string ("%s", defined_name); insert_html_tag (END, "b"); insert_html_tag (START, "var"); break; case deftypefn: case deftypevr: execute_string ("%s ", type_name); insert_html_tag (START, "b"); execute_string ("%s", defined_name); insert_html_tag (END, "b"); insert_html_tag (START, "var"); break; case defcv: case defop: insert_html_tag (START, "b"); execute_string ("%s", defined_name); insert_html_tag (END, "b"); insert_html_tag (START, "var"); break; case deftypecv: case deftypeivar: case deftypemethod: case deftypeop: execute_string ("%s ", type_name2); insert_html_tag (START, "b"); execute_string ("%s", defined_name); insert_html_tag (END, "b"); insert_html_tag (START, "var"); break; } } else if (xml) xml_begin_def_term (base_type, category, defined_name, type_name, type_name2); current_indent += default_indentation_increment; /* Now process the function arguments, if any. If these carry onto the next line, they should be indented by two increments to distinguish them from the body of the definition, which is indented by one increment. */ current_indent += default_indentation_increment; switch (base_type) { case deffn: case defop: process_defun_args (scan_args, 1); break; /* Through Makeinfo 1.67 we processed remaining args only for deftp, deftypefn, and deftypemethod. But the libc manual, for example, needs to say: @deftypevar {char *} tzname[2] And simply allowing the extra text seems far simpler than trying to invent yet more defn commands. In any case, we should either output it or give an error, not silently ignore it. */ default: process_defun_args (scan_args, 0); break; } current_indent -= default_indentation_increment; if (!html) close_single_paragraph (); /* Make an entry in the appropriate index. (XML and Docbook already got their entries, so skip them.) */ if (!xml) switch (base_type) { case deffn: case deftypefn: execute_string ("@findex %s\n", defined_name); break; case defcv: case deftypecv: case deftypevr: case defvr: execute_string ("@vindex %s\n", defined_name); break; case deftypeivar: execute_string ("@vindex %s %s %s\n", defined_name, _("of"), type_name); break; case defop: case deftypeop: case deftypemethod: execute_string ("@findex %s %s %s\n", defined_name, _("on"), type_name); break; case deftp: execute_string ("@tindex %s\n", defined_name); break; } if (xml) xml_end_def_term (); else if (html) { inhibit_paragraph_indentation = 1; no_indent = 1; insert_html_tag (END, "var"); insert_string ("<br>\n"); /* Indent the definition a bit. */ add_html_block_elt ("<blockquote>"); no_indent = 0; inhibit_paragraph_indentation = 0; paragraph_is_open = 0; } /* Deallocate the token list. */ scan_args = defun_args; while (1) { char * arg = (*scan_args++); if (arg == NULL) break; free (arg); } free (defun_args); }
/* Treat this just like @unnumbered. The only difference is in node defaulting. */ void cm_top (void) { /* It is an error to have more than one @top. */ if (top_node_seen && strcmp (current_node, "Top") != 0) { TAG_ENTRY *tag = tag_table; line_error (_("Node with %ctop as a section already exists"), COMMAND_PREFIX); while (tag) { if (tag->flags & TAG_FLAG_IS_TOP) { file_line_error (tag->filename, tag->line_no, _("Here is the %ctop node"), COMMAND_PREFIX); return; } tag = tag->next_ent; } } else { top_node_seen = 1; /* It is an error to use @top before using @node. */ if (!tag_table) { char *top_name; get_rest_of_line (0, &top_name); line_error (_("%ctop used before %cnode, defaulting to %s"), COMMAND_PREFIX, COMMAND_PREFIX, top_name); execute_string ("@node Top, , (dir), (dir)\n@top %s\n", top_name); free (top_name); return; } cm_unnumbered (); /* The most recently defined node is the top node. */ tag_table->flags |= TAG_FLAG_IS_TOP; /* Now set the logical hierarchical level of the Top node. */ { int orig_offset = input_text_offset; input_text_offset = search_forward (node_search_string, orig_offset); if (input_text_offset > 0) { int this_section; /* We have encountered a non-top node, so mark that one exists. */ non_top_node_seen = 1; /* Move to the end of this line, and find out what the sectioning command is here. */ while (input_text[input_text_offset] != '\n') input_text_offset++; if (input_text_offset < input_text_length) input_text_offset++; this_section = what_section (input_text + input_text_offset, NULL); /* If we found a sectioning command, then give the top section a level of this section - 1. */ if (this_section != -1) set_top_section_level (this_section - 1); } input_text_offset = orig_offset; } } }
void sectioning_html (int level, char *cmd) { static int toc_ref_count = 0; int index; int old_no_indent; unsigned char *starting_pos, *ending_pos; char *temp, *toc_anchor = NULL; close_paragraph (); filling_enabled = indented_fill = 0; old_no_indent = no_indent; no_indent = 1; /* level 0 (chapter) is <h2>, and we go down from there. */ add_html_block_elt_args ("<h%d class=\"%s\">", level + 2, cmd); /* If we are outside of any node, produce an anchor that the TOC could refer to. */ if (!current_node || !*current_node) { static const char a_name[] = "<a name=\""; starting_pos = output_paragraph + output_paragraph_offset; add_word_args ("%sTOC%d\">", a_name, toc_ref_count++); toc_anchor = substring (starting_pos + sizeof (a_name) - 1, output_paragraph + output_paragraph_offset); /* This must be added after toc_anchor is extracted, since toc_anchor cannot include the closing </a>. For details, see toc.c:toc_add_entry and toc.c:contents_update_html. Also, the anchor close must be output before the section name in case the name itself contains an anchor. */ add_word ("</a>"); } starting_pos = output_paragraph + output_paragraph_offset; if (macro_expansion_output_stream && !executing_string) append_to_expansion_output (input_text_offset + 1); get_rest_of_line (0, &temp); /* Use @settitle value if @top parameter is empty. */ if (STREQ (command, "top") && strlen(temp) == 0) temp = xstrdup (title ? title : ""); index = search_sectioning (cmd); if (index < 0) { /* should never happen, but a poor guy, named Murphy ... */ warning (_("Internal error (search_sectioning) \"%s\"!"), cmd); return; } /* Produce "X.Y" and add it to HTML output. */ { char *title_number = handle_enum_increment (level, index); if (strlen (title_number) > 0) add_word_args ("%s ", title_number); } /* add the section name to both HTML and macro-expanded output. */ if (macro_expansion_output_stream && !executing_string) { remember_itext (input_text, input_text_offset); me_execute_string (temp); write_region_to_macro_output ("\n", 0, 1); } else execute_string ("%s", temp); ending_pos = output_paragraph + output_paragraph_offset; /* Pluck ``X.Y SECTION-NAME'' from the output buffer and insert it into the TOC. */ if (section_alist[index].toc == TOC_YES) toc_add_entry (substring (starting_pos, ending_pos), level, current_node, toc_anchor); free (temp); if (outstanding_node) outstanding_node = 0; add_word_args ("</h%d>", level + 2); close_paragraph(); filling_enabled = 1; no_indent = old_no_indent; }
/* 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. */ void insert_and_underscore (int level, char *cmd) { int i, len; int index; int old_no_indent; unsigned char *starting_pos, *ending_pos; char *temp; char with_char = scoring_characters[level]; close_paragraph (); filling_enabled = indented_fill = 0; old_no_indent = no_indent; no_indent = 1; if (macro_expansion_output_stream && !executing_string) append_to_expansion_output (input_text_offset + 1); get_rest_of_line (0, &temp); /* Use @settitle value if @top parameter is empty. */ if (STREQ (command, "top") && strlen(temp) == 0) temp = xstrdup (title ? title : ""); starting_pos = output_paragraph + output_paragraph_offset; /* Poor man's cache for section title. */ if (strlen (last_sectioning_title)) free (last_sectioning_title); last_sectioning_title = xstrdup (temp); index = search_sectioning (cmd); if (index < 0) { /* should never happen, but a poor guy, named Murphy ... */ warning (_("Internal error (search_sectioning) `%s'!"), cmd); return; } /* This is a bit tricky: we must produce "X.Y SECTION-NAME" in the Info output and in TOC, but only SECTION-NAME in the macro-expanded output. */ /* Step 1: produce "X.Y" and add it to Info output. */ add_word_args ("%s ", handle_enum_increment (level, index)); /* Step 2: add "SECTION-NAME" to both Info and macro-expanded output. */ if (macro_expansion_output_stream && !executing_string) { char *temp1 = xmalloc (2 + strlen (temp)); sprintf (temp1, "%s\n", temp); remember_itext (input_text, input_text_offset); me_execute_string (temp1); free (temp1); } else execute_string ("%s\n", temp); /* Step 3: pluck "X.Y SECTION-NAME" from the output buffer and insert it into the TOC. */ ending_pos = output_paragraph + output_paragraph_offset; if (section_alist[index].toc == TOC_YES) toc_add_entry (substring (starting_pos, ending_pos - 1), level, current_node, NULL); free (temp); len = (ending_pos - starting_pos) - 1; for (i = 0; i < len; i++) add_char (with_char); insert ('\n'); close_paragraph (); filling_enabled = 1; no_indent = old_no_indent; }
void sectioning_underscore (char *cmd) { char *temp, *secname; int level; /* If we're not indenting the first paragraph, we shall make it behave like @noindent is called directly after the section heading. */ if (! do_first_par_indent) cm_noindent (); temp = xmalloc (2 + strlen (cmd)); temp[0] = COMMAND_PREFIX; strcpy (&temp[1], cmd); level = what_section (temp, &secname); level -= 2; if (level < 0) level = 0; free (temp); /* If the argument to @top is empty, we try using the one from @settitle. Warn if both are unusable. */ if (STREQ (command, "top")) { int save_input_text_offset = input_text_offset; get_rest_of_line (0, &temp); /* Due to get_rest_of_line ... */ line_number--; if (strlen (temp) == 0 && (!title || strlen (title) == 0)) warning ("Must specify a title with least one of @settitle or @top"); input_text_offset = save_input_text_offset; } if (xml) { /* If the section appears in the toc, it means it's a real section unlike majorheading, chapheading etc. */ if (section_alist[search_sectioning (cmd)].toc == TOC_YES) { xml_close_sections (level); /* Mark the beginning of the section If the next command is printindex, we will remove the section and put an Index instead */ flush_output (); xml_last_section_output_position = output_paragraph_offset; get_rest_of_line (0, &temp); /* Use @settitle value if @top parameter is empty. */ if (STREQ (command, "top") && strlen(temp) == 0) temp = xstrdup (title ? title : ""); /* Docbook does not support @unnumbered at all. So we provide numbers that other formats use. @appendix seems to be fine though, so we let Docbook handle that as usual. */ if (docbook && enum_marker != APPENDIX_MAGIC) { if (section_alist[search_sectioning (cmd)].num == ENUM_SECT_NO && section_alist[search_sectioning (cmd)].toc == TOC_YES) xml_insert_element_with_attribute (xml_element (secname), START, "label=\"%s\" xreflabel=\"%s\"", handle_enum_increment (level, search_sectioning (cmd)), text_expansion (temp)); else xml_insert_element_with_attribute (xml_element (secname), START, "label=\"%s\"", handle_enum_increment (level, search_sectioning (cmd))); } else xml_insert_element (xml_element (secname), START); xml_insert_element (TITLE, START); xml_open_section (level, secname); execute_string ("%s", temp); xml_insert_element (TITLE, END); free (temp); } else { if (docbook) { if (level > 0) xml_insert_element_with_attribute (xml_element (secname), START, "renderas=\"sect%d\"", level); else xml_insert_element_with_attribute (xml_element (secname), START, "renderas=\"other\""); } else xml_insert_element (xml_element (secname), START); get_rest_of_line (0, &temp); execute_string ("%s", temp); free (temp); xml_insert_element (xml_element (secname), END); } } else if (html) sectioning_html (level, secname); else insert_and_underscore (level, secname); }