#!/bin/sh ###################################################################### # tirframe - Generate tir HTML document with frame elements for # content in standart input. # Created 2006-8-13 by David Meyer. # 2007-05-15 Version 0.2 - Build on 0.1.x1 success: # - Check for existing frame elements before # inserting. # - Backup and edit file in place. # - Compact frame elements. # - all customization in per-directory .tir_config files # 2007-05-14 Version 0.1.x1 - Experiment to achieve recent # design goals with minimal code changes. ###################################################################### # Identification ##################################################### PROGRAM='tirframe (Tears in Rain)' VERSION=0.2 COPYRIGHT='Copyright 2009 David Meyer' DESCRIPTION='Add Tears in Rain HTML frame elements to text file.' USAGE="Usage: $0 [-Vh] FILE [OUTFILE]" CONTACT='David Meyer ' # Initialize environment ############################################# unset IFS PATH= BASENAME=/usr/bin/basename CAT=/bin/cat CP=/bin/cp DIRNAME=/usr/bin/dirname ECHO=/bin/echo GREP=/bin/grep SED=/bin/sed : ${TIRROOT:=~/cave} : ${TIRCONFIG:=.tir_config} : ${TIRCSS:=$TIRROOT/.tir.css} # do I need this? # Arguments ########################################################## while getopts Vh option do case $option in # p ) PREFORMAT=true ;; # don't need because there'll be a file name to check (*.txt, x-bit,..) V ) $ECHO "$PROGRAM $VERSION" $ECHO $COPYRIGHT exit 0 ;; h ) $CAT << ENDHELP $USAGE $DESCRIPTION Options: -V Display version number -h Display this help message Report bugs to $CONTACT. ENDHELP exit 0 ;; * ) $ECHO $USAGE >&2 exit 1 ;; esac done shift $(( $OPTIND-1 )) if [ ! $1 ]; then echo $USAGE; exit; fi FILE=$1 OUTFILE=${2:-$FILE} # Functions ########################################################## cat_filter_root_path() { if [ $fdir -ef $TIRROOT ] then $SED -e 's:\.\./:./:' $1 else $CAT $1 fi } inherit_fn() { fn=${2:?"Insufficient arguments: inherit_fn $@"} if [ -f $fn ] then eval $1=$fn elif [ -f $TIRROOT/$fn ] then eval $1=$TIRROOT/$fn else eval $1=${3:-/dev/null} fi } # Main driver ######################################################## fdir=`$DIRNAME $FILE` # Read configuration. Inherit root configuration, but local configuration takes precedence. . $TIRROOT/$TIRCONFIG . $fdir/$TIRCONFIG # Check for missing frame elements. $GREP '/dev/null || nodoctype=true $GREP ' ]' $FILE >/dev/null || nohead=true $GREP ' ]' $FILE >/dev/null || nobody=true $GREP '