bug-texinfo
[Top][All Lists]
Advanced

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

Texindex: Leave out \initial{x} if there's only one


From: Zack Weinberg
Subject: Texindex: Leave out \initial{x} if there's only one
Date: Tue, 26 Mar 2002 17:20:06 -0800
User-agent: Mutt/1.3.28i

I find it looks somewhat silly to have just one initial-header in an
index.  This happens, for instance, in the GNU CPP manual's index of
directives, where all the entries begin with '#'.

This patch causes Texindex to leave out the \initial command if there
would be just one of them.

Patch vs. 4.1.

zw

        * util/texindex.c (need_initials, first_initial): New globals.
        (main): Clear them for each index.
        (parsefile): Set need_initials when there is more than one
        initial in this index.
        (indexify): Do not emit \initial commands unless need_initials
        is set.  Use toupper.

*** texinfo-4.1/util/texindex.c Fri Jan 18 17:12:54 2002
--- texinfo-4.1z/util/texindex.c        Tue Mar 26 17:04:42 2002
*************** int last_deleted_tempcount;
*** 111,116 ****
--- 111,123 ----
     which contains all the lines of data.  */
  char *text_base;
  
+ /* Initially 0; changed to 1 if we want initials in this index.  */
+ int need_initials;
+ 
+ /* Remembers the first initial letter seen in this index, so we can
+    determine whether we need initials in the sorted form.  */
+ char first_initial;
+ 
  /* Additional command switches .*/
  
  /* Nonzero means do not delete tempfiles -- for debugging. */
*************** main (argc, argv)
*** 217,222 ****
--- 224,232 ----
            outfile = concat (infiles[i], "s", "");
          }
  
+       need_initials = 0;
+       first_initial = '\0';
+ 
        if (ptr < MAX_IN_CORE_SORT)
          /* Sort a small amount of data. */
          sort_in_core (infiles[i], ptr, outfile);
*************** parsefile (filename, nextline, data, siz
*** 1100,1105 ****
--- 1110,1132 ----
          return 0;
  
        *line = p;
+ 
+       /* Find the first letter of the first field of this line.  If it
+        is different from the first letter of the first field of the
+        first line, we need initial headers in the output index.  */
+       while (*p && *p != '{')
+       p++;
+       if (p == end)
+       return 0;
+       p++;
+       if (first_initial)
+       {
+         if (first_initial != toupper (*p))
+           need_initials = 1;
+       }
+       else
+       first_initial = toupper (*p);
+       
        while (*p && *p != '\n')
          p++;
        if (p != end)
*************** indexify (line, ostream)
*** 1209,1220 ****
    else
      {
        initial = initial1;
!       initial1[0] = *p;
        initial1[1] = 0;
        initiallength = 1;
- 
-       if (initial1[0] >= 'a' && initial1[0] <= 'z')
-         initial1[0] -= 040;
      }
  
    pagenumber = find_braced_pos (line, 1, 0, 0);
--- 1236,1244 ----
    else
      {
        initial = initial1;
!       initial1[0] = toupper (*p);
        initial1[1] = 0;
        initiallength = 1;
      }
  
    pagenumber = find_braced_pos (line, 1, 0, 0);
*************** indexify (line, ostream)
*** 1242,1249 ****
  
        /* If this primary has a different initial, include an entry for
           the initial. */
!       if (initiallength != lastinitiallength ||
!           strncmp (initial, lastinitial, initiallength))
          {
            fprintf (ostream, "\\initial {");
            fwrite (initial, 1, initiallength, ostream);
--- 1266,1274 ----
  
        /* If this primary has a different initial, include an entry for
           the initial. */
!       if (need_initials &&
!         (initiallength != lastinitiallength ||
!          strncmp (initial, lastinitial, initiallength)))
          {
            fprintf (ostream, "\\initial {");
            fwrite (initial, 1, initiallength, ostream);



reply via email to

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