#!/bin/sh
# help_gen - generates help.h include file from  help.txt and Changelog
# $Id: help_gen,v 1.3 2001/06/03 18:04:31 duncan_haldane Exp $

rm -f help.h
echo \/\* help.h , generated by help_gen from help.txt \*\/ > help.h
echo static char \*help_txt\[\] = \{ >> help.h
awk '{
  p=index($0,"^");
  if(p>0) line="\"@i@C4" substr($0,1,p-1) "\",";
  else line="\"" $0 "\",";
  print line
}' help.txt >> help.h
echo \"@N\", >> help.h
echo \"@N\", >> help.h
echo \"@N@C4@c@b@lWhat\'s new in this version\", >> help.h
echo \"@N\", >> help.h
echo \"@N\", >> help.h
awk '{ if ($0 == "changes start" && n == 1) n = 2 ; if ($0 == "changes end" && n == 2) n = 1;if (n == 2) print quot $0 quot comm }' n=1 quot=\" comm=\, ../../ChangeLog | grep -v "^\"changes start" >> help.h
echo \"%END\" >> help.h
echo \} \; >> help.h

egrep -n "\\^|^%" help.txt |  sort -n |
awk -F: '
{
  if (substr($2,1,1)=="%") {
    indices[$2]=$1;
  } else {
    p=index($2,"^")+1;
    links["%"substr($2,p)]=$1 "/" links["%"substr($2,p)];
    anz++;
  }
} END {
  print "static int chapters[] = {";
  print indices["%Start"]","
  print indices["%Overview"]","
  print indices["%Folders"]","
  print indices["%Messages"]","
  print indices["%ButtonPad"]","
  print indices["%MainMenu"]","
  print indices["%AddressBook"]","
  print indices["%Signature"]","
  print indices["%Config"]","
  print indices["%Rules"]","
  print indices["%Viewmsg"]","
  print indices["%Editmsg"]","
  print indices["%attach"]","
  print indices["%Search"]","
  print indices["%Config-Misc"]","
  print indices["%Config-Appearance"]","
  print indices["%Config-Receive"]","
  print indices["%Config-Display"]","
  print indices["%Config-View"]","
  print indices["%Config-Edit"]","
  print indices["%Config-POP"]","
  print indices["%Config-SPOP"]","
  print indices["%Config-Send"]","
  print indices["%Config-Timers"]","
  print indices["%Config-Faces"]","
  print indices["%Config-MIME"]","
  print indices["%Config-repfwd"]","
  print indices["%Config-Int"]","
  print indices["%Config-IMAP"]","
  print indices["%Config-PGP"]","
  print indices["%Config-Charset"]","
  print indices["%Config-Folders"]","
  print indices["%Config-Keymap"]","
  print indices["%What-New"]","
  print indices["%Config-Ispell"]","
  print indices["%Spellchecker"]","
  print indices["%PGPKeyIdLookup"]","
  print indices["%Config-Messages"]","
  print indices["%Create-Folder"]","
  print indices["%Config-Header"]","
  print indices["%Create-Subfolder"]","
  print indices["%Config-NEWS"]","
  print indices["%Config-Spool"]","
  print indices["%Select-Mcap"]","
  print indices["%Preview"]","
  print indices["%Config-LDAP"]","
  print indices["%Config-SMTP"]","
  print indices["%Config-SMTPacct"]","
  print "};"
  print "#define NrOfLinks "anz;
  print "static int HelpLinks[NrOfLinks][2]={";
  for (elem in links) {
    n=split(links[elem],splitted,"/");
    for (i=1;i<n;i++)
      print " {" splitted[i] "," indices[elem]"},";
  }
  print "};";
}' >> help.h
