bug-texinfo
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: [PATCH] different approach to --split html


From: janneke
Subject: Fwd: [PATCH] different approach to --split html
Date: 08 Nov 2000 10:46:41 +0100
User-agent: Gnus/5.0807 (Gnus v5.8.7) Emacs/20.7

Hi Eli,

It seems that Karl is not very on-line, I haven't yet had a response
from him, that's why I'm forwarding this patch to you.  Have you by
chance taken over texinfo maintenance?

It's still work in progress, new versions will be at
    http://appel.lilypond.org/fred/software


Greetings,

Jan.

To: Karl Berry <address@hidden>
Subject: [PATCH] different approach to --split html

Hi Karl,

We're in dire need for the split option in html; a part of our LilyPond
auto-generated documentation reaches about 500Kb html, see

    
http://appel.lilypond.org/lilypond/links/lilypond-1.3.104/Documentation/user/oud-www/lilypond-internals.html

Therefore, I've looked at html splitting for makeinfo, and found that
quite some code was already in place.  It seemed, however, that (you?)
wanted to take a rather diffcult approach: numbering the nodes and using
filenames like node<number>.html.  That way, you have to know the number
of a node to be able to link to it.

I decided to take a quick look at a more simplistic approach: mapping
nodenames to filenames, simply by substituting or removing unwanted
characters.  This way, the html files have friendlier names too.  You
can view the current result at:

    
http://appel.lilypond.org/lilypond/links/lilypond-1.3.104/Documentation/user/out-www/lilypond-internals.html

The patch has some rough edges, eg, you can't link to anchors within
other nodes.  But before I start to look at that, please tell me if
this approach/patch has any chance to be included, and how.  Maybe you
want the numbered nodes code removed, maybe you want it as an option?




diff -urN --exclude=*~ --exclude=#* --exclude=Makefile.in --exclude=Makefile 
--exclude=configure --exclude=aclocal.m4 --exclude=.deps 
../texinfo-4.0.jcn1/ChangeLog ./ChangeLog
--- ../texinfo-4.0.jcn1/ChangeLog       Tue Sep 28 21:39:54 1999
+++ ./ChangeLog Tue Nov  7 21:19:00 2000
@@ -1,3 +1,21 @@
+2000-11-07  Jan Nieuwenhuizen  <address@hidden>
+
+       * toc.c (toc_add_entry): 
+       (contents_update_html): 
+       (shortcontents_update_html): [SPLIT_JCN]: use hrefs for nodename based
+       html files.
+
+       * node.c (cm_node): [SPLIT_JCN]: create html filename based on
+       nodename (instead of a numbered node<num>.html filename).
+
+       * makeinfo/makeinfo.c (main): [SPLIT_JCN]: enable splitting of
+       html output.
+
+       * makeinfo/html.c
+       (add_url_name,add_nodename_to_filename,nodename_to_filename): new
+       functions.
+       
+
 2000-04-14    <address@hidden>
 
        * applied texinfo-3.12s.jcn4 patch
diff -urN --exclude=*~ --exclude=#* --exclude=Makefile.in --exclude=Makefile 
--exclude=configure --exclude=aclocal.m4 --exclude=.deps 
../texinfo-4.0.jcn1/configure.in ./configure.in
--- ../texinfo-4.0.jcn1/configure.in    Tue Sep 28 21:39:54 1999
+++ ./configure.in      Tue Nov  7 20:13:51 2000
@@ -5,7 +5,7 @@
 AC_PREREQ(2.13)dnl Minimum Autoconf version required.
 AM_CONFIG_HEADER(config.h:config.in)dnl Keep filename to 8.3 for MS-DOS.
 
-AM_INIT_AUTOMAKE([texinfo], [4.0.jcn1])
+AM_INIT_AUTOMAKE([texinfo], [4.0.jcn2])
 
 AM_CONDITIONAL(TEXINFO_MAINT, test -n "$TEXINFO_MAINT")
 
diff -urN --exclude=*~ --exclude=#* --exclude=Makefile.in --exclude=Makefile 
--exclude=configure --exclude=aclocal.m4 --exclude=.deps 
../texinfo-4.0.jcn1/doc/stamp-vti ./doc/stamp-vti
--- ../texinfo-4.0.jcn1/doc/stamp-vti   Tue Sep 28 21:40:40 1999
+++ ./doc/stamp-vti     Tue Nov  7 21:37:14 2000
@@ -1,3 +1,3 @@
address@hidden UPDATED 28 September 1999
address@hidden EDITION 4.0
address@hidden VERSION 4.0
address@hidden UPDATED 14 April 2000
address@hidden EDITION 4.0.jcn2
address@hidden VERSION 4.0.jcn2
diff -urN --exclude=*~ --exclude=#* --exclude=Makefile.in --exclude=Makefile 
--exclude=configure --exclude=aclocal.m4 --exclude=.deps 
../texinfo-4.0.jcn1/doc/stamp-vti1 ./doc/stamp-vti1
--- ../texinfo-4.0.jcn1/doc/stamp-vti1  Thu Jan  1 01:00:00 1970
+++ ./doc/stamp-vti1    Tue Nov  7 21:37:14 2000
@@ -0,0 +1,3 @@
address@hidden UPDATED 25 June 1999
address@hidden EDITION 4.0.jcn2
address@hidden VERSION 4.0.jcn2
diff -urN --exclude=*~ --exclude=#* --exclude=Makefile.in --exclude=Makefile 
--exclude=configure --exclude=aclocal.m4 --exclude=.deps 
../texinfo-4.0.jcn1/doc/version.texi ./doc/version.texi
--- ../texinfo-4.0.jcn1/doc/version.texi        Tue Sep 28 21:40:40 1999
+++ ./doc/version.texi  Tue Nov  7 21:37:14 2000
@@ -1,3 +1,3 @@
address@hidden UPDATED 28 September 1999
address@hidden EDITION 4.0
address@hidden VERSION 4.0
address@hidden UPDATED 14 April 2000
address@hidden EDITION 4.0.jcn2
address@hidden VERSION 4.0.jcn2
diff -urN --exclude=*~ --exclude=#* --exclude=Makefile.in --exclude=Makefile 
--exclude=configure --exclude=aclocal.m4 --exclude=.deps 
../texinfo-4.0.jcn1/makeinfo/html.c ./makeinfo/html.c
--- ../texinfo-4.0.jcn1/makeinfo/html.c Sat Sep 18 21:27:41 1999
+++ ./makeinfo/html.c   Tue Nov  7 21:07:11 2000
@@ -50,6 +50,7 @@
   add_word_args ("<meta name=description content=\"%s\">\n", html_title);
   add_word_args ("<meta name=generator content=\"makeinfo %s\">\n", VERSION);
   add_word ("<link href=\"http://texinfo.org/\"; rel=generator-home>\n");
+  add_word ("<link href=\"http://appel.lilypond.org/fred/software\"; 
rel=generator-patches>\n");
   add_word ("</head><body>\n\n");
 }
 
@@ -136,13 +137,13 @@
 /* Output an HTML <link> to the filename for NODE, including the
    other string as extra attributes. */
 void
-add_link (node, attributes)
-     char *node, *attributes;
+add_link (nodename, attributes)
+     char *nodename, *attributes;
 {
-  if (node)
+  if (nodename)
     {
       add_word_args ("<link %s href=\"", attributes);
-      add_anchor_name (node, 1);
+      add_anchor_name (nodename, 1);
       add_word ("\">\n");
     }
 }
@@ -175,8 +176,65 @@
      char *nodename;
      int href;
 {
+#ifndef SPLIT_JCN
   if (href)
     add_char ('#');
 
-  add_escaped_anchor_name (nodename);
+   add_escaped_anchor_name (nodename);
+#else
+   add_url_name (nodename, href);
+#endif
+}
+
+/* Insert the text for the name of a reference in an HTML url, aprropriate
+   for NODENAME */
+void
+add_url_name (nodename, href)
+     char *nodename;
+     int href;
+{
+    add_nodename_to_filename (nodename);
+}
+
+/*
+  As we (Most probably, if not, I don't understand why splitting html
+  in makinfo would be complicated and hasn't been fixed years ago --
+  should check this) can't look-up the nodes' html filename from the
+  tentry, we take the easy way out.  We assume that nodenames are
+  unique, and generate the html filename from the nodename, that's
+  always known.
+*/
+char *
+nodename_to_filename (nodename)
+     char *nodename;
+{
+  char *p;
+  char *filename;
+  if (!strcasecmp (nodename, "Top"))
+    return xstrdup (filename_part (toplevel_output_filename));
+  filename = xmalloc (strlen (nodename) + 5);
+  strcpy (filename, nodename);
+  for (p = filename; *p; p++)
+    {
+      if (strchr (" !#$%&'", *p)
+         || (int)*p < 32 || (int)*p > 127)
+       *p = '-';
+      else if (strchr ("()", *p))
+       memmove (p, p+1, strlen (p));
+    }
+  strcat (filename, ".html");
+  return filename;
+}
+
+/* If necessary, ie, if current filename != filename of node,
+   ouput the node name.
+*/
+void
+add_nodename_to_filename (nodename)
+     char *nodename;
+{
+  /* for now, don't check: always output filename */
+  char *filename = nodename_to_filename (nodename);
+  add_word (filename);
+  free (filename);
 }
diff -urN --exclude=*~ --exclude=#* --exclude=Makefile.in --exclude=Makefile 
--exclude=configure --exclude=aclocal.m4 --exclude=.deps 
../texinfo-4.0.jcn1/makeinfo/html.h ./makeinfo/html.h
--- ../texinfo-4.0.jcn1/makeinfo/html.h Sun Apr 25 22:53:34 1999
+++ ./makeinfo/html.h   Tue Nov  7 20:32:39 2000
@@ -40,5 +40,8 @@
 
 /* See html.c.  */
 extern void add_anchor_name (/* nodename, href */);
+extern void add_url_name ( /*nodename, href */ );
+extern char* nodename_to_filename ( /* nodename */ );
+extern void add_nodename_to_filename ( /*nodename*/ );
 
 #endif /* !HTML_H */
diff -urN --exclude=*~ --exclude=#* --exclude=Makefile.in --exclude=Makefile 
--exclude=configure --exclude=aclocal.m4 --exclude=.deps 
../texinfo-4.0.jcn1/makeinfo/makeinfo.c ./makeinfo/makeinfo.c
--- ../texinfo-4.0.jcn1/makeinfo/makeinfo.c     Sun Sep 19 17:24:44 1999
+++ ./makeinfo/makeinfo.c       Tue Nov  7 20:37:07 2000
@@ -625,7 +625,11 @@
           html = 1;
           process_html = 1;
           process_info = 0;
-          splitting = 0; /* too complicated for now */
+#ifdef SPLIT_JCN
+         /* too complicated why, sez who? */
+#else
+         splitting = 0; /* too complicated for now */
+#endif
           break;
 
         case '?':
@@ -1297,6 +1301,13 @@
     }
 
   canon_white (output_filename);
+
+  /*
+    FIXME. Wow, how hairy can you get?
+    It seems that in any case, we have the output filename here.
+      -- jcn
+   */
+  toplevel_output_filename = xstrdup (output_filename);
 
   if (real_output_filename && strcmp (real_output_filename, "-") == 0)
     {
diff -urN --exclude=*~ --exclude=#* --exclude=Makefile.in --exclude=Makefile 
--exclude=configure --exclude=aclocal.m4 --exclude=.deps 
../texinfo-4.0.jcn1/makeinfo/makeinfo.h ./makeinfo/makeinfo.h
--- ../texinfo-4.0.jcn1/makeinfo/makeinfo.h     Tue Sep 28 21:39:54 1999
+++ ./makeinfo/makeinfo.h       Tue Nov  7 19:58:41 2000
@@ -144,6 +144,7 @@
 DECLARE (int, input_text_length, 0);
 DECLARE (int, input_text_offset, 0);
 DECLARE (int, line_number, 0);
+DECLARE (char *, toplevel_output_filename, NULL);
 #define curchar() input_text[input_text_offset]
 
 /* A colon separated list of directories to search for files included
diff -urN --exclude=*~ --exclude=#* --exclude=Makefile.in --exclude=Makefile 
--exclude=configure --exclude=aclocal.m4 --exclude=.deps 
../texinfo-4.0.jcn1/makeinfo/node.c ./makeinfo/node.c
--- ../texinfo-4.0.jcn1/makeinfo/node.c Mon Sep 20 14:31:21 1999
+++ ./makeinfo/node.c   Tue Nov  7 23:42:24 2000
@@ -24,6 +24,7 @@
 #include "macro.h"
 #include "makeinfo.h"
 #include "node.h"
+#include "html.h"
 #include "sectioning.h"
 #include "insertion.h"
 
@@ -457,10 +458,12 @@
 void
 cm_node ()
 {
+  /* URG, naming: node, prev, next, up are `nodename', ie char*, not tentry */
   char *node, *prev, *next, *up;
   int new_node_pos, defaulting, this_section;
   int no_warn = 0;
 
+  no_warn = 0;
   if (strcmp (command, "nwnode") == 0)
     no_warn = TAG_FLAG_NO_WARN;
 
@@ -477,23 +480,7 @@
       output_pending_notes ();
     }
 
-  if (html && splitting && top_node_seen)
-    {
-      /* End the current split output file. */
-      close_paragraph ();
-      output_pending_notes ();
-      start_paragraph ();
-      /* Fixme: html: need a navigation bar here. */
-      add_word ("</body></html>\n");
-      close_paragraph ();
-      fclose (output_stream);
-      output_stream = NULL;
-    }
-
-  filling_enabled = indented_fill = 0;
   new_node_pos = output_position;
-  if (!html || (html && splitting))
-    current_footnote_number = 1;
 
   if (macro_expansion_output_stream && !executing_string)
     append_to_expansion_output (input_text_offset + 1);
@@ -510,6 +497,38 @@
   prev = get_node_token (0);
   up = get_node_token (0);
 
+
+  if (html && splitting && top_node_seen)
+    {
+#ifdef SPLIT_JCN
+      if (current_output_filename && output_stream)
+       {
+         char *filename = nodename_to_filename (node);
+         if (strcmp (filename, filename_part (current_output_filename)))
+           {
+             
+#endif
+             /* End the current split output file. */
+             close_paragraph ();
+             output_pending_notes ();
+             start_paragraph ();
+             /* Fixme: html: need a navigation bar here. */
+             add_word ("</body></html>\n");
+             close_paragraph ();
+             fclose (output_stream);
+             output_stream = NULL;
+           }
+#ifdef SPLIT_JCN
+         free (filename);
+       }
+#endif
+    }
+
+
+  filling_enabled = indented_fill = 0;
+  if (!html || (html && splitting))
+    current_footnote_number = 1;
+  
   if (verbose_mode)
     printf (_("Formatting node %s...\n"), node);
 
@@ -739,16 +758,36 @@
 
       if (splitting)
         { /* this code not operational, we do not currently split html */
+#ifndef SPLIT_JCN
           char filename[20];
-
-          sprintf (filename, "node%d.html", number_of_node (node));
-          output_stream = fopen (filename, "w");
+         sprintf (filename, "node%d.html", number_of_node (node));
+#else
+         char *basename;
+         char *dirname;
+         char *filename;
+         /* URG, `node' is `nodename', ie a char*, not a tentry */
+         basename = nodename_to_filename (node);
+         dirname = pathname_part (toplevel_output_filename);
+         /*
+           Can't we just use PATH_MAX?
+          */
+         filename = xmalloc (strlen (dirname) + strlen (basename) + 1);
+         strcpy (filename, dirname);
+         strcat (filename, basename);
+         free (dirname);
+         free (basename);
+#endif
+         if (output_stream == NULL)
+           output_stream = fopen (filename, "w");
           if (output_stream == NULL)
             {
               fs_error (filename);
               xexit (1);
             }
           set_current_output_filename (filename);
+#ifdef SPLIT_JCN
+         free (filename);
+#endif
           /* FIXME: when this code is operational, we will need to
              expand node, next, prev, and up before output.  */
           add_word_args ("<html><head><title>%s</title>", node);
diff -urN --exclude=*~ --exclude=#* --exclude=Makefile.in --exclude=Makefile 
--exclude=configure --exclude=aclocal.m4 --exclude=.deps 
../texinfo-4.0.jcn1/makeinfo/toc.c ./makeinfo/toc.c
--- ../texinfo-4.0.jcn1/makeinfo/toc.c  Mon Aug  9 22:28:18 1999
+++ ./makeinfo/toc.c    Tue Nov  7 16:58:56 2000
@@ -25,6 +25,7 @@
 #include "files.h"
 #include "macro.h"
 #include "node.h"
+#include "html.h"
 #include "lang.h"
 #include "makeinfo.h"
 #include "sectioning.h"
@@ -83,6 +84,7 @@
         So instead we store in the tocname member the expanded node
         name and the TOC name concatenated together (with the necessary
         HTML markup), since that's how they are output.  */
+#ifndef SPLIT_JCN
       if (!anchor)
        s = expanded_node = expand_node_name (node_name);
       else
@@ -124,6 +126,9 @@
       free (tocname);       /* it was malloc'ed by substring() */
       free (expanded_node);
       toc_entry_alist[toc_counter]->name = tocname_and_node;
+#else
+      toc_entry_alist[toc_counter]->name = xstrdup (node_name);
+#endif
     }
   else
     toc_entry_alist[toc_counter]->name = tocname;
@@ -231,7 +236,17 @@
             fputs ("</ul>\n", fp);
         }
 
-      fprintf (fp, "<li><a href=\"#%s</a>\n", toc_entry_alist[i]->name);
+#ifndef SPLIT_JCN
+      fprintf (fp, "<li><a href=\"#%s\"</a>\n", toc_entry_alist[i]->name);
+#else
+      {
+       char *filename = nodename_to_filename (toc_entry_alist[i]->name);
+       fprintf (fp, "<li><a href=\"%s\">%s</a>\n",
+                filename,
+                toc_entry_alist[i]->name);
+       free (filename);
+      }
+#endif
 
       last_level = toc_entry_alist[i]->level;
     }
@@ -295,11 +310,20 @@
     {
       if ((toc_entry_alist[i])->level == 0)
         {
-          fputs ("<li>", fp);
-          fprintf (fp, "<a href=\"#%s\n", toc_entry_alist[i]->name);
-        }
+#ifndef SPLIT_JCN
+         fputs ("<li>", fp);
+         fprintf (fp, "<a href=\"#%s\"\n", toc_entry_alist[i]->name);
+#else
+
+         char *filename = nodename_to_filename (toc_entry_alist[i]->name);
+         fprintf (fp, "<li><a href=\"%s\">%s</a>\n",
+                  filename,
+                  toc_entry_alist[i]->name);
+         free (filename);
+#endif
+       }
     }
-
+  
   fputs ("</ul>\n\n", fp);
 }
 


-- 
Jan Nieuwenhuizen <address@hidden> | GNU LilyPond - The music typesetter
http://www.xs4all.nl/~jantien       | http://www.lilypond.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]