#! /bin/bash # Copyleft 2003, 2004 by Syd Bauman # Convert each file to XML using RCS (so that it is ready to be # checked out, and the complete file history is still accessible). # Intended to be handed the list of RCS files, not working # files. I.e., move over all the whatever/RCS/*,v files, then issue # $0 whatever/RCS/*,v # This routine, after checking that it's got the right kind of file, # simply # * removes the access list from the RCS file; # * checks out the file; # * reads work file in, writes it out converted to XML by Perl script # with .xml extension; # * renames the RCS file to .xml; # * checks .xml file back in with label and log message. #---------------------------# # # error function spits out the given number and msg to STDERR # function errfnc { echo "$myname: error #$1; $2" >&2 return $1 } # # get my own name and path # mypath=${0%/*} myname=${0##/*/} # # loop through each of the files specified on cmdline # for filepath in $@; do # rcs_v_ext=",v" # # separate path from filename, and create path and filename for working file, too # RCS_path=${filepath%/*} RCS_file=${filepath##*/} RCS_ext=${filepath##*.} RCS_root=${filepath%.*} WORK_path=${filepath%/RCS/*} WORK_file=${RCS_file%$rcs_v_ext} new_WORK_file=$WORK_path/${WORK_file%.sg*}.xml new_RCS_file=${RCS_root}.xml${rcs_v_ext} # echo "RCS_path=${RCS_path}" # echo "RCS_file=${RCS_file}" # echo "RCS_ext=${RCS_ext}" # echo "RCS_root=${RCS_root}" # echo "WORK_path=${WORK_path}" # echo "WORK_file=${WORK_file}" # echo "new_WORK_file=${new_WORK_file}" # echo "new_RCS_file=${new_RCS_file}" echo " " echo "--------- starting $filepath ..." # # do some error checking to ensure this file is the kind # we want to play with # if [ -z "$filepath" ]; then errfnc 1 "$filepath is empty, ignoring" elif [ -d "$filepath" ]; then errfnc 2 "$filepath is a directory, I need a file; ignoring" elif [ ! -e "$filepath" ]; then errfnc 3 "$filepath does not exist; ignoring" elif [ ! -w "$WORK_path" ]; then errfnc 4 "no write access to $WORK_path; ignoring" elif [ ! ${filepath%#} = ${filepath%\~} ]; then errfnc 5 "$filepath ends in # or ~; ignoring" elif [ ! "$RCS_path/$WORK_file$rcs_v_ext" = $filepath ]; then errfnc 7 "$filepath != $path/$WORK_file$rcs_v_ext, so does not seem to be an RCS file; ignoring" elif [ ! -e "${WORK_path}/${WORK_file}" ]; then errfnc 9 "$WORK_path/$WORK_file does not exist; ignoring" else if [ -e "$WORK_path/$WORK_file" ]; then # following Perl is a crude way to ascertain whether or # not file is checdked out if perl -ne'if ( m/^\s*locks\s*/ ) { exit ( m/;/ ); }' < $filepath then errfnc 8 "$WORK_path/$WORK_file is checked-out; ignoring" fi fi # So, if we made it this far, this is a file we want to convert echo "... starting ${WORK_path}/${WORK_file} ---------" # 1. Remove access list cmd="rcs -e $filepath" echo $cmd ; $cmd # 2. check out cmd="co -f -l -zLT ${WORK_path}/${WORK_file}" echo $cmd ; $cmd # 3. convert (why didn't "cmd" indirection work?) echo "/srv/home/sbauman/bin/wwp-store_sgml2xml_for_real.perl < ${WORK_path}/${WORK_file} > ${new_WORK_file}" /srv/home/sbauman/bin/wwp-store_sgml2xml_for_real.perl < ${WORK_path}/${WORK_file} > ${new_WORK_file} # 4. rename to .xml cmd="mv ${RCS_path}/${RCS_file} ${new_RCS_file}" echo $cmd ; $cmd # 5. check back in echo "ci -j -u -zLT -nfirstXML -m'Auto converted from P3 SGML on mama to P4 XML on cushing, I hope' ${new_WORK_file}" ci -j -u -zLT -nfirstXML -m'Auto converted from P3 SGML on mama to P4 XML on cushing, I hope' ${new_WORK_file} fi done