#!/bin/sh # # .txt2html.sh - Process a story-format text file and # copy it out to a .html file. # # Author: Jack C Lipton, cupasoup@softhome.net # # Note: This is fairly naive and doesn't do much # formatting; It's mostly there to provide # a wrapper that *isn't* just a
# file. # # Note: Because of the placement of the awk scripts, # it's not a good idea to run this as root. # Capische? # # $Id: .txt2html.sh,v 1.5 2003/03/08 03:36:44 jcl Exp jcl $ # # $Log: .txt2html.sh,v $ # Revision 1.5 2003/03/08 03:36:44 jcl # added new lines for the story eval "snippet" # # , # # Revision 1.4 2003/02/19 01:13:13 jcl # modified to use extra field from Lix # code review snippet. # # Revision 1.3 2003/02/11 22:57:57 jcl # Give "End Ch..." same treatment as "Fini". # # Revision 1.2 2003/01/25 01:45:39 jcl # Updated to ensure that the rate/review button is also on the # bottom of the generated HTML file. # # Revision 1.1 2003/01/24 21:45:25 jcl # Initial revision # # # # AWK1=/tmp/txt2htmlA1.$$ # awk script for "normal" stories AWK2=/tmp/txt2htmlA2.$$ # awk script for poetry (retains lines) TMP=/tmp/txt2htmlT.$$ # temporary file ... ACRRSTMP=/tmp/txt2htmlS.$$ # contains preconditioning flags... REVU=/tmp/txt2htmlR.$$ # Rate/Review Snippet (from Lix) # # Author information for the Rate/Review logic: # AUTHNAME="Jack C Lipton" #EMAILADDR="liptonsoup1951@yahoo.com" EMAILADDR="cupasoup@softhome.net" MAINPAGE="index.html" WEBSPACE="http://www.asstr-mirror.org/files/Authors/CupaSoup/www" # # This awk fragment is the preface of the actual script and # is used to process the headings, which will generate the # initial HEAD and top of the BODY # cat >$AWK1 <
\n");
skips = 0;
}
print; # pass the line through directly
}
AWK1SCRIPT
#
# 2nd AWK script forces per-line format, useful for poetry
#
cat >>$AWK2 < \n");
skips = 0;
}
#
# We make sure we close the line
#
printf( "%s
\n", \$0); }
#
#
#
{
if ( crap > 0 ) {
crap--;
next;
}
#
# A blank line between paragraphs is handy
# so I can insert paragraph breaks...
#
if ( skips != 0 ) {
printf( "
\n", \$0);
}
AWK2SCRIPT
#
# Ensure proper closure of the text file...
#
cat >>$TMP <
\n");
if ( ACRRS != 0 )
{
printf( "");
}
printf( "\n
\n
\n
\n");
printf( "Copyright (c) 2002, 2003 $AUTHNAME;\n");
printf( "Derivatives are allowed (and encouraged) but\n");
printf( "should reference the Title/Author of\n");
printf( "this source material in some way.\n");
printf( "\n
\n
\n
\n\n");
for ( i = 1 ; i <= headings ; i++ ) {
printf( "%s\n", SHSheader[i]);
}
printf( "
\n");
printf( "\n\n\n\n");
}
CLOSURE
cat $TMP >>$AWK1
cat $TMP >>$AWK2
#
# Using the scripts above, process each file as it's presented
#
SCRIPT=$AWK1 # set default script
for F in $@
do
case $F in
-1) SCRIPT=$AWK1 # "normal" story format
;;
-2) SCRIPT=$AWK2 # "poem" format w/ line breaks
;;
*) : process a file
#ACRRS=`grep $F .acrrs | wc -l`
ACRRS=1
echo $F $ACRRS >/dev/tty
>$ACRRSTMP
[ $ACRRS = 1 ] && echo "!" >>$ACRRSTMP
CORENAME=`echo $F | awk -F. '{print $1}'`
WEBNAME=$CORENAME.html
awk -f $SCRIPT $ACRRSTMP $F >$WEBNAME
;;
esac
done
#
# All done here, clean up the scripts...
#
rm -f $AWK1 $AWK2 $TMP
exit 0