#!/bin/sh ###################################################################### # tirframe - Generate tir HTML document with frame elements for # content in standart input. # Created 2006-8-13 by David Meyer. # 2009-02-17 Version 0.2.1 - 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.1 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 MV=/bin/mv SED=/bin/sed : ${TIRROOT:=/home/zaurus/cave/green} : ${TIRCONFIG:=.tir_config} : ${TIRCSS:=$TIRROOT/.tir.css} # 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 ########################################################## # Main driver ######################################################## fdir=`$DIRNAME $FILE` # Read configuration. Inherit root configuration, but local configuration takes precedence. if [ ! $fdir -ef $TIRROOT ]; then test -f $TIRROOT/$TIRCONFIG && . $TIRROOT/$TIRCONFIG # (adjust relative path for file names in config inherited from TIR root...) : ${tir_nameplate:+../$tir_nameplate} : ${tir_stylesheet:+../$tir_stylesheet} : ${tir_exit_icon:+../$tir_exit_icon} : ${tir_object_icon:+../$tir_object_icon} : ${tir_favicon:+../$tir_favicon} fi test -f $fdir/$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 '