#!/usr/public/perl

# makeIndex
# 
# $Id: makeIndex,v 1.13 97/07/17 16:24:51 lawrence Exp $
#
# Usage:
#  makeIndex IXInfo
#
# This script takes a file full of index information (as generated 
# by the extractIXInfo script) and creates a bunch of pages from it.
# Run makeIndex in the top of the techdoc HTML tree--after you've 
# generated the IXInfo there.

$bullet = "<IMG SRC=\"../../docImages/ix.gif\" BORDER=\"0\" ALT=\"x\">" ;

$ixTop1 = <<"EO1" ;
<HTML>
<HEAD>
<META NAME="copyright" CONTENT="Copyright 1997 GEOWORKS">
<META NAME="description" CONTENT="GEOS SDK TechDocs: Index"> 
<!-- <META NAME="keywords" CONTENT=""> -->
<LINK REL="STYLESHEET" HREF="../../docHelpers/style.css">
<LINK REV="MADE" HREF="mailto:doc-feedback\@geoworks.com">
EO1

$ixTop2 = <<"EO2" ;
</HEAD>
<BODY BGCOLOR="#dfdfff">
<strong>
<A HREF="index_.htm">&nbsp;[symbols]&nbsp;</A>
<A HREF="indexA.htm">&nbsp;A&nbsp;</A>
<A HREF="indexB.htm">&nbsp;B&nbsp;</A>
<A HREF="indexC.htm">&nbsp;C&nbsp;</A>
<A HREF="indexD.htm">&nbsp;D&nbsp;</A>
<A HREF="indexE.htm">&nbsp;E&nbsp;</A>
<A HREF="indexF.htm">&nbsp;F&nbsp;</A>
<A HREF="indexG.htm">&nbsp;G&nbsp;</A>
<A HREF="indexH.htm">&nbsp;H&nbsp;</A>
<A HREF="indexI.htm">&nbsp;I&nbsp;</A>
<A HREF="indexJ.htm">&nbsp;J&nbsp;</A>
<A HREF="indexK.htm">&nbsp;K&nbsp;</A>
<A HREF="indexL.htm">&nbsp;L&nbsp;</A>
<A HREF="indexM.htm">&nbsp;M&nbsp;</A>
<A HREF="indexN.htm">&nbsp;N&nbsp;</A>
<A HREF="indexO.htm">&nbsp;O&nbsp;</A>
<A HREF="indexP.htm">&nbsp;P&nbsp;</A>
<A HREF="indexQ.htm">&nbsp;Q&nbsp;</A>
<A HREF="indexR.htm">&nbsp;R&nbsp;</A>
<A HREF="indexS.htm">&nbsp;S&nbsp;</A>
<A HREF="indexT.htm">&nbsp;T&nbsp;</A>
<A HREF="indexU.htm">&nbsp;U&nbsp;</A>
<A HREF="indexV.htm">&nbsp;V&nbsp;</A>
<A HREF="indexW.htm">&nbsp;W&nbsp;</A>
<A HREF="indexX.htm">&nbsp;X&nbsp;</A>
<A HREF="indexY.htm">&nbsp;Y&nbsp;</A>
</strong>
EO2

$ixBottom =<<"EO3" ;
<HR>
<strong>
<A HREF="index_.htm">&nbsp;[symbols]&nbsp;</A>
<A HREF="indexA.htm">&nbsp;A&nbsp;</A>
<A HREF="indexB.htm">&nbsp;B&nbsp;</A>
<A HREF="indexC.htm">&nbsp;C&nbsp;</A>
<A HREF="indexD.htm">&nbsp;D&nbsp;</A>
<A HREF="indexE.htm">&nbsp;E&nbsp;</A>
<A HREF="indexF.htm">&nbsp;F&nbsp;</A>
<A HREF="indexG.htm">&nbsp;G&nbsp;</A>
<A HREF="indexH.htm">&nbsp;H&nbsp;</A>
<A HREF="indexI.htm">&nbsp;I&nbsp;</A>
<A HREF="indexJ.htm">&nbsp;J&nbsp;</A>
<A HREF="indexK.htm">&nbsp;K&nbsp;</A>
<A HREF="indexL.htm">&nbsp;L&nbsp;</A>
<A HREF="indexM.htm">&nbsp;M&nbsp;</A>
<A HREF="indexN.htm">&nbsp;N&nbsp;</A>
<A HREF="indexO.htm">&nbsp;O&nbsp;</A>
<A HREF="indexP.htm">&nbsp;P&nbsp;</A>
<A HREF="indexQ.htm">&nbsp;Q&nbsp;</A>
<A HREF="indexR.htm">&nbsp;R&nbsp;</A>
<A HREF="indexS.htm">&nbsp;S&nbsp;</A>
<A HREF="indexT.htm">&nbsp;T&nbsp;</A>
<A HREF="indexU.htm">&nbsp;U&nbsp;</A>
<A HREF="indexV.htm">&nbsp;V&nbsp;</A>
<A HREF="indexW.htm">&nbsp;W&nbsp;</A>
<A HREF="indexX.htm">&nbsp;X&nbsp;</A>
<A HREF="indexY.htm">&nbsp;Y&nbsp;</A>
</strong>
</BODY>
</HTML>
EO3

$lastTextRoot = "XXX_HOPSCOTCH"; 
$lastKey = "XXX_HOPSCOTCH";
$lastFirstChar = "\@\@\@";
open( INDEXFILE, ">docIndexes/bigIndex/index_.htm" );
print( INDEXFILE $ixTop1 );
print( INDEXFILE "<TITLE>GEOS SDK Index: symbols</TITLE>\n" );
print( INDEXFILE $ixTop2 );
print(INDEXFILE "<H1><A HREF=\"../../index.htm\">GEOS SDK</A> Index: symbols</H1>\n"); 

@unsortedInfo = <>;

@monsterArray = sort withoutCase @unsortedInfo;

foreach $dummy (@monsterArray) {
   $_ = $dummy;

   ( $theKey, $theURL ) = /(.*)\t(.*)/ ;

   $theText = $theURL;
   $theText =~ s/.*IX_// ;
   $theText =~ s/&ldots;/\.\.\./g ;
   $theText =~ s/\[;.*\]// ;
   $theText =~ s/([^\\]):\s*/\1<BR>&nbsp;&nbsp;&nbsp;&nbsp;/ ;
   $theText =~ s/\\:/:/g;
   $theText =~ s/&qmark;/\?/g; 

   $theTextRoot = $theText;
   $theTextRoot =~ s/<BR>.*// ;

   if ( $theText eq $lastText ) {
     $outText = "<A HREF=\"../../" . $theURL . "\"> " . $bullet . "</A>" ;
   }
   elsif ( $theTextRoot eq $lastTextRoot ) {
     $outText = $theText;
     $outText =~ s/.*<BR>&nbsp;&nbsp;&nbsp;&nbsp;// ;
     $outText = "<A HREF=\"../../" . $theURL . "\">" . $outText . " " . $bullet . "</A>" ;
     print( INDEXFILE "<BR>\n&nbsp;&nbsp;&nbsp;&nbsp;");
   } 
   else {
     $bb = $theKey; $bb =~ tr/a-z/A-Z/; $bb =~ tr/A-Z/ /c ; 
     if ( $bb gt $lastFirstChar ) {
       $_ = $bb;
       ($lastFirstChar) = /^(.)/ ;
       print( INDEXFILE $ixBottom );
       close( INDEXFILE );
       $indexFileName = "docIndexes/bigIndex/index" . $lastFirstChar . "\.htm";
       open( INDEXFILE, ">$indexFileName"); 
       print( INDEXFILE $ixTop1 );
       print( INDEXFILE "<TITLE>GEOS SDK Index: $lastFirstChar</TITLE>\n" );
       print( INDEXFILE $ixTop2 );
       print(INDEXFILE "<H1><A HREF=\"../../index.htm\">GEOS SDK</A> Index: $lastFirstChar</H1>\n"); 
       $lastFirstChar .= "z";
     }
     $outText = "<BR>\n<A HREF=\"../../" . $theURL . "\"> " . $theText . " " . $bullet . "</A>" ;      
   }
   $lastTextRoot = $theTextRoot;
   $lastText = $theText;
   
   print(INDEXFILE $outText); 
   
}
print( INDEXFILE $ixBottom );

sub withoutCase {

  $aa = $a ; $bb = $b;

  # non-alphabetic keys should always sort earlier than alphabetics.
  $aa =~ s/^([^A-Za-z])/.\1/; 
  $bb =~ s/^([^A-Za-z])/.\1/; 

  $aa =~ tr/A-Z:|/a-z\031,/ ;
  $bb =~ tr/A-Z:|/a-z\031,/ ;
  ( $aa cmp $bb) || ($a cmp $b);
}
