#!/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 <=1)&&(substr(\$1,1,2)=="//") { \$0 = ""; } (NF==1)&&(\$1=="|") { \$0 = ""; } (NF==1)&&(/^!/) { ACRRS = 1; next; } /^$/ { # # Assuming the headers start on the first # line, we want to know when we're done # reading them. This is when the HTML # header gets built. Cruel, ain't I? # if ( SHSrdr != 0 ) { # establish structure printf( "\n\n\n"); printf( " %s \n\n", title); printf( "\n"); printf( "\n", title); printf( "\n", part); printf( "\n", author); printf( "\n", codes); printf( "\n", "`date`"); printf( "\n", universe); printf( "\n", summary); printf( "\n", revision); printf( ""); printf( "\n\n"); printf( "

\n"); printf( "%s\n", title); if ( part != "" ) { printf( "(part %s)\n", part); } printf( "

\n"); printf( "
\n"); if ( codes != "" ) { printf( "codes: %s\t
\n", codes); } printf( "by %s
\n", author); printf( "(Main Page)
\n"); curfile = FILENAME; corefile = substr( curfile, 1, length(curfile)-2); if ( ACRRS != 0 ) { printf( "
"); printf( " ", corefile); printf( ""); printf( " "); printf( " ", title); printf( " ", author); printf( "
"); } printf( "
\n"); printf( "

\n"); SHSrdr = 0; next; } skips++; # blank lines delimit paragraphs? next; } (SHSrdr!=0) { # # We'll capture each header line verbatim # so that we can append it at the end... # SHSheader[++headings] = \$0; } (SHSrdr!=0) && \$1=="Author:" { author = \$2; for ( f = 3 ; f <= NF ; f++ ) { if ( substr( \$f, 1, 1) == "<" ) { break; } author = author " " \$f; } } (SHSrdr!=0) && \$1=="Title:" { title = \$2; for ( f = 3 ; f <= NF ; f++ ) { title = title " " \$f; } } (SHSrdr!=0) && \$1=="Part:" { part = \$2; for ( f = 3 ; f <= NF ; f++ ) { part = part " " \$f; } } (SHSrdr!=0) && \$1=="Universe:" { universe = \$2; for ( f = 3 ; f <= NF ; f++ ) { universe = universe " " \$f; } } (SHSrdr!=0) && \$1=="Summary:" { summary = \$2; for ( f = 3 ; f <= NF ; f++ ) { summary = summary " " \$f; } } (SHSrdr!=0) && \$1=="Keywords:" { codes = \$2; for ( f = 3 ; f <= NF ; f++ ) { codes = codes " " \$f; } } (SHSrdr!=0) && \$1=="Revision:" { revision = \$2; for ( f = 3 ; f <= NF ; f++ ) { revision = revision " " \$f; } } (SHSrdr!=0) { next; } # # Recognize my "Fini" line so that it can be centered. # /[ ]Fini[$ ]/ || /^Fini$/ || /[ ]End Ch[$ ]/ { printf( "
\n") printf( "%s\n", \$0); printf( "
\n") next; } AWK1SCRIPT # # Make a copy to the second awk2 script, used to process # poetry (which wants to retain line breaks). I could've # just embedded it in a PRE-formatted text block but that'd # be *way* to lazy # cat $AWK1 >$AWK2 # # Normal story line processing. Knock yourself out. # cat >>$AWK1 < 0 ) { crap--; } ; next; } # # I've been stupid and inserted some extra commentary with # a single "-" in front of it, so it'll be displayed as a # line that's been italicized. More non-generic code. # \$1=="-" { printf( "%s
\n", \$0); } # # Main processing of story lines: # { if ( crap > 0 ) { # skip any bullshit crap--; next; } # # A blank line between paragraphs is handy # so I can insert paragraph breaks... # if ( skips != 0 ) { printf( "

\n"); skips = 0; } print; # pass the line through directly } AWK1SCRIPT # # 2nd AWK script forces per-line format, useful for poetry # cat >>$AWK2 < 0 ) { crap--; } ; next; } # # I've been stupid and inserted some extra commentary with # a single "-" in front of it, so it'll be displayed as a # line that's been italicized. More non-generic code. # \$1=="-" { 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"); skips = 0; } # # We make sure we close the line # printf( "%s
\n", \$0); } AWK2SCRIPT # # Ensure proper closure of the text file... # cat >>$TMP <
\n"); if ( ACRRS != 0 ) { printf( "

"); printf( " ", corefile); printf( ""); printf( " "); printf( " ", title); printf( " ", author); 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