#!/bin/sh
#----------------------------------------------------------------------------
#  Name:     makeAsciiFromDb
#  Project:  Xdiary
#
#  Description:
#    Create the text file from the XDiary on-line documentation.
#
#  Filename:         makeAsciiFromDb
#
#  Authors:          Roger Larsson, Ulrika Bornetun
#  Creation date:    1991-09-09
#
#
#  (C) Copyright Ulrika Bornetun, Roger Larsson (1995)
#      All rights reserved
#
#  Permission to use, copy, modify, and distribute this software and its
#  documentation for any purpose and without fee is hereby granted,
#  provided that the above copyright notice appear in all copies. Ulrika
#  Bornetun and Roger Larsson make no representations about the usability
#  of this software for any purpose. It is provided "as is" without express
#  or implied warranty.
#----------------------------------------------------------------------------
#
# SCCSID = @(#) Module: makeAsciiFromDb, Version: 1.1, Date: 95/02/18 14:15:13

# Generate the awk file.
cat <<- EOT >/tmp/xd.awk.$$
	BEGIN { line="==================================================" }

	/^#H.*<[1-9]>/ {
	  split( \$0, elements, "'" )
	  match( elements[ 2 ], "[ ]*" )
	  header=substr( elements[ 2 ], RLENGTH + 1 )
	  getline
	  if( \$1 == "#L" ) { getline; next }
	  print ""
	  print header
	  print substr( line, 1, length( header ) )
	  next
	}

	/^#/  { 
	  next 
	}

	{ 
	  printf "  %s\n", \$0 
	}
EOT

# Manual in text format.
if [ -x "`which nawk`" ]; then
  nawk -f /tmp/xd.awk.$$ $1 >$2
else
  awk -f /tmp/xd.awk.$$ $1 >$2
fi

/bin/rm -f /tmp/xd.awk.$$
