From 5500b59c459afe212e4ee8d1c1847e051a9b7653 Mon Sep 17 00:00:00 2001 From: ru Date: Mon, 25 Mar 2002 13:08:32 +0000 Subject: Import of stripped down GNU texinfo 4.1 --- contrib/texinfo/makeinfo/insertion.c | 269 ++++++++++++++++++++++++++++++----- 1 file changed, 236 insertions(+), 33 deletions(-) (limited to 'contrib/texinfo/makeinfo/insertion.c') diff --git a/contrib/texinfo/makeinfo/insertion.c b/contrib/texinfo/makeinfo/insertion.c index 11b9089..c7087f2 100644 --- a/contrib/texinfo/makeinfo/insertion.c +++ b/contrib/texinfo/makeinfo/insertion.c @@ -1,7 +1,7 @@ /* insertion.c -- insertions for Texinfo. - $Id: insertion.c,v 1.27 1999/07/06 23:12:53 karl Exp $ + $Id: insertion.c,v 1.39 2002/03/02 15:05:21 karl Exp $ - Copyright (C) 1998, 99 Free Software Foundation, Inc. + Copyright (C) 1998, 99, 2000, 01, 02 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,20 +23,21 @@ #include "insertion.h" #include "macro.h" #include "makeinfo.h" +#include "xml.h" /* Must match list in insertion.h. */ static char *insertion_type_names[] = -{ +{ "cartouche", "defcv", "deffn", "defivar", "defmac", "defmethod", "defop", "defopt", "defspec", "deftp", "deftypefn", "deftypefun", "deftypeivar", "deftypemethod", "deftypeop", "deftypevar", "deftypevr", "defun", "defvar", "defvr", "detailmenu", "direntry", - "display", "enumerate", "example", "flushleft", "flushright", - "format", "ftable", "group", "ifclear", "ifhtml", "ifinfo", - "ifnothtml", "ifnotinfo", "ifnottex", "ifset", "iftex", "itemize", - "lisp", "menu", "multitable", "quotation", "rawhtml", "rawtex", - "smalldisplay", "smallexample", "smallformat", "smalllisp", "table", - "tex", "vtable", "bad_type" + "display", "documentdescription", "enumerate", "example", "flushleft", + "flushright", "format", "ftable", "group", "ifclear", "ifhtml", + "ifinfo", "ifnothtml", "ifnotinfo", "ifnottex", "ifset", "iftex", + "itemize", "lisp", "menu", "multitable", "quotation", "rawhtml", + "rawtex", "smalldisplay", "smallexample", "smallformat", "smalllisp", + "verbatim", "table", "tex", "vtable", "bad_type" }; /* All nested environments. */ @@ -359,7 +360,9 @@ begin_insertion (type) no_discard++; } else - push_insertion (type, get_item_function ()); + { + push_insertion (type, get_item_function ()); + } switch (type) { @@ -374,9 +377,12 @@ begin_insertion (type) { had_menu_commentary = 1; } - else if (!no_headers) + else if (!no_headers && !xml) add_word ("* Menu:\n"); + if (xml) + xml_insert_element (MENU, START); + in_menu++; in_fixed_width_font++; no_discard++; @@ -399,15 +405,29 @@ begin_insertion (type) break; case direntry: - if (html) - command_name_condition (); - else - { - close_single_paragraph (); - filling_enabled = no_indent = 0; - inhibit_paragraph_indentation = 1; - insert_string ("START-INFO-DIR-ENTRY\n"); - } + close_single_paragraph (); + filling_enabled = no_indent = 0; + inhibit_paragraph_indentation = 1; + insert_string ("START-INFO-DIR-ENTRY\n"); + break; + + case documentdescription: + { + char *desc; + int start_of_end; + int save_fixed_width; + + discard_until ("\n"); /* ignore the @documentdescription line */ + start_of_end = get_until ("\n@end documentdescription", &desc); + save_fixed_width = in_fixed_width_font; + + in_fixed_width_font = 0; + document_description = expansion (desc, 0); + free (desc); + + in_fixed_width_font = save_fixed_width; + input_text_offset = start_of_end; /* go back to the @end to match */ + } break; case quotation: @@ -443,7 +463,7 @@ begin_insertion (type) /* Kludge alert: if
 is followed by a newline, IE3
            renders an extra blank line before the pre-formatted block.
            Other browsers seem to not mind one way or the other.  */
-        add_word ("
");
+        add_word ("
");
 
       if (type != format && type != smallformat)
         current_indent += default_indentation_increment;
@@ -492,6 +512,8 @@ begin_insertion (type)
           else
             add_word (dl_tag);
         }
+      if (xml)
+	xml_begin_table (type, insertion_stack->item_function);
       break;
 
     case enumerate:
@@ -509,6 +531,9 @@ begin_insertion (type)
       if (html)
         enum_html ();
 
+      if (xml)
+	xml_begin_enumerate (enumeration_arg);
+      
       if (isdigit (*enumeration_arg))
         start_enumerating (atoi (enumeration_arg), ENUM_DIGITS);
       else
@@ -519,7 +544,9 @@ begin_insertion (type)
     case group:
       /* Only close the paragraph if we are not inside of an
          @example-like environment. */
-      if (!insertion_stack->next
+      if (xml)
+	xml_insert_element (GROUP, START);
+      else if (!insertion_stack->next
           || (insertion_stack->next->insertion != display
               && insertion_stack->next->insertion != smalldisplay
               && insertion_stack->next->insertion != example
@@ -581,6 +608,8 @@ begin_insertion (type)
       close_single_paragraph ();
       inhibit_paragraph_indentation = 1;
       filling_enabled = indented_fill = no_indent = 0;
+      if (html)
+	add_word ("
"); break; case flushright: @@ -588,6 +617,8 @@ begin_insertion (type) filling_enabled = indented_fill = no_indent = 0; inhibit_paragraph_indentation = 1; force_flush_right++; + if (html) + add_word ("
"); break; default: @@ -627,12 +658,64 @@ end_insertion (type) pop_insertion (); + if (xml) + { + switch (type) + { + case ifinfo: + case documentdescription: + break; + case quotation: + xml_insert_element (QUOTATION, END); + break; + case example: + xml_insert_element (EXAMPLE, END); + break; + case smallexample: + xml_insert_element (SMALLEXAMPLE, END); + break; + case lisp: + xml_insert_element (LISP, END); + break; + case smalllisp: + xml_insert_element (SMALLLISP, END); + break; + case cartouche: + xml_insert_element (CARTOUCHE, END); + break; + case format: + xml_insert_element (FORMAT, END); + break; + case smallformat: + xml_insert_element (SMALLFORMAT, END); + break; + case display: + xml_insert_element (DISPLAY, END); + break; + case smalldisplay: + xml_insert_element (SMALLDISPLAY, END); + break; + case table: + case ftable: + case vtable: + case itemize: + xml_end_table (type); + break; + case enumerate: + xml_end_enumerate (type); + break; + case group: + xml_insert_element (GROUP, END); + break; + } + } switch (type) { /* Insertions which have no effect on paragraph formatting. */ + case documentdescription: case ifclear: - case ifhtml: case ifinfo: + case ifhtml: case ifnothtml: case ifnotinfo: case ifnottex: @@ -680,6 +763,11 @@ end_insertion (type) break; case flushleft: + if (html) + add_word ("
\n"); + close_insertion_paragraph (); + break; + case group: case cartouche: close_insertion_paragraph (); @@ -724,6 +812,8 @@ end_insertion (type) case flushright: force_flush_right--; + if (html) + add_word ("
\n"); close_insertion_paragraph (); break; @@ -750,7 +840,7 @@ end_insertion (type) case deftypeivar: if (html) /* close the tables which has been opened in defun.c */ - add_word ("\n\n"); + add_word ("\n\n"); break; } /* switch (base_type)... */ @@ -790,12 +880,11 @@ discard_insertions (specials_ok) else { char *offender = insertion_type_pname (insertion_stack->insertion); - char *current_filename = input_filename; - input_filename = insertion_stack->filename; - line_number = insertion_stack->line_number; - line_error (_("No matching `%cend %s'"), COMMAND_PREFIX, offender); - input_filename = current_filename; + file_line_error (insertion_stack->filename, + insertion_stack->line_number, + _("No matching `%cend %s'"), COMMAND_PREFIX, + offender); pop_insertion (); } } @@ -807,75 +896,103 @@ discard_insertions (specials_ok) void cm_quotation () { + if (xml) + xml_insert_element (QUOTATION, START); begin_insertion (quotation); } void cm_example () { + if (xml) + xml_insert_element (EXAMPLE, START); begin_insertion (example); } void cm_smallexample () { + if (xml) + xml_insert_element (SMALLEXAMPLE, START); begin_insertion (smallexample); } void cm_lisp () { + if (xml) + xml_insert_element (LISP, START); begin_insertion (lisp); } void cm_smalllisp () { + if (xml) + xml_insert_element (SMALLLISP, START); begin_insertion (smalllisp); } -/* @cartouche/@end cartouche draws box with rounded corners in - TeX output. Right now, just a no-op insertion. */ void cm_cartouche () { + if (xml) + xml_insert_element (CARTOUCHE, START); begin_insertion (cartouche); } void cm_format () { + if (xml) + xml_insert_element (FORMAT, START); begin_insertion (format); } void cm_smallformat () { + if (xml) + xml_insert_element (SMALLFORMAT, START); begin_insertion (smallformat); } void cm_display () { + if (xml) + xml_insert_element (DISPLAY, START); begin_insertion (display); } void cm_smalldisplay () { + if (xml) + xml_insert_element (SMALLDISPLAY, START); begin_insertion (smalldisplay); } void cm_direntry () { - if (no_headers || html) + if (html || xml) command_name_condition (); else begin_insertion (direntry); } void +cm_documentdescription () +{ + if (html || xml) + begin_insertion (documentdescription); + else + command_name_condition (); +} + + +void cm_itemize () { begin_insertion (itemize); @@ -918,6 +1035,77 @@ cm_enumerate () do_enumeration (enumerate, "1"); } +/* Handle verbatim environment: + find_end_verbatim == 0: process until end of file + find_end_verbatim != 0: process until 'COMMAND_PREFIXend verbatim' + or end of file + + We cannot simply copy input stream onto output stream; as the + verbatim environment may be encapsulated in an @example environment, + for example. */ +void +handle_verbatim_environment (find_end_verbatim) + int find_end_verbatim; +{ + int character; + int seen_end = 0; + int save_filling_enabled = filling_enabled; + int save_inhibit_paragraph_indentation = inhibit_paragraph_indentation; + + close_single_paragraph (); + inhibit_paragraph_indentation = 1; + filling_enabled = 0; + in_fixed_width_font++; + last_char_was_newline = 0; + + /* No indentation: this is verbatim after all + If you want indent, enclose @verbatim in @example + current_indent += default_indentation_increment; + */ + + if (html) + add_word ("
");
+
+  while (input_text_offset < input_text_length)
+    {
+      character = curchar ();
+
+      if (character == '\n')
+        line_number++;
+      /*
+	Assume no newlines in END_VERBATIM
+      */
+      else if (find_end_verbatim && (character == COMMAND_PREFIX) /* @ */
+	  && (input_text_length - input_text_offset > sizeof (END_VERBATIM))
+	  && !strncmp (&input_text[input_text_offset+1], END_VERBATIM,
+		       sizeof (END_VERBATIM)-1))
+	{
+	  input_text_offset += sizeof (END_VERBATIM);
+	  seen_end = 1;
+	  break;
+	}
+
+      add_char (character);
+      input_text_offset++;
+    }
+
+  if (find_end_verbatim && !seen_end)
+    warning (_("end of file inside verbatim block"));
+
+  if (html)
+    add_word ("
"); + + in_fixed_width_font--; + filling_enabled = save_filling_enabled; + inhibit_paragraph_indentation = save_inhibit_paragraph_indentation; +} + +void +cm_verbatim () +{ + handle_verbatim_environment (1); +} + void cm_table () { @@ -1087,6 +1275,10 @@ cm_end () line_error (_("Bad argument to `%s', `%s', using `%s'"), command, temp, insertion_type_pname (current_insertion_type ())); } + if (xml && type == menu) /* fixme */ + { + xml_end_menu (); + } end_insertion (type); free (temp); } @@ -1096,7 +1288,7 @@ cm_end () static int itemx_flag = 0; /* Return whether CMD takes a brace-delimited {arg}. */ -static int +/*static */int command_needs_braces (cmd) char *cmd; { @@ -1195,6 +1387,8 @@ cm_item () } add_word ("
  • "); } + else if (xml) + xml_begin_item (); else { start_paragraph (); @@ -1289,6 +1483,15 @@ cm_item () last_html_output_position = output_position; add_word ("
    "); } + else if (xml) /* && docbook)*/ /* 05-08 */ + { + xml_begin_table_item (); + if (item_func && *item_func) + execute_string ("%s{%s}", item_func, rest_of_line); + else + execute_string ("%s", rest_of_line); + xml_continue_table_item (); + } else { /* We need this to determine if we have two @item's in a row -- cgit v1.1