Cover V09, I04
Article
Listing 1
Listing 2
Sidebar 1

apr2000.tar


Listing 2 rcs_recover.ss

#!/bin/ksh
# this script uses either Bourne or Korn shell. 
#
# Listing 2:
# Title:   rcs_recover.ss
# Subject: RCS head branch retrieval script.
# Author:  Mike Dunham
# Date:    12/02/1999
# Description:
#   Retrieve the head branch of code from a former RCS
#   file. Intended for quick use when retrieving data from
#   old RCS archives without the time consuming step of configuring 
#   the RCS archive directories and environments.

# retrieve list of file names is passed to the shell script.
file_list=$*

# create a sub directory for the output of the head branch source
# with the original file name under the current working directory.
output_dir=./tst

# Define the awk command. this may be nawk, gawk, etc
awk_cmd=awk

# Setup a var for the awk script to get the header revision number.
awk_header=$output_dir/header.awk.$$

# Setup a var for the awk script to get the source code
awk_version=$output_dir/version.awk.$$

# Create output directory if it doesn't exist and make it writable
if [ ! -d $output_dir ]
then
    mkdir $output_dir
    chmod 755 $output_dir 
fi

# Build an awk script using the shell's here facility to strip the 
# header version from the RCS file.  Add the process id to the end 
# of file to make sure the name is unique.
cat <<EOF >$awk_header
/^head/ {
        version=\$2;
        semi=index(version,";");
        final=substr(version,1,(semi-1));
        printf "%s", final;
}
EOF

# loop through the files in the list
for work_file in $file_list
do
    # Get the header version from the file with the awk command
    header_version='$awk_cmd -f $awk_header $work_file'

    # If there was no header information, we may not have an RCS
    # file, so inform the user and terminate
    if [ ! $header_version ]
    then
        echo "Unable to find the RCS HEAD block in file $work_file"
        echo "Can not continue!"
        exit 1
    fi

    # build another awk script to capture the source code for the 
    # header reversion
cat <<EOF >$awk_version
BEGIN { 
        first_line_flg=0;
        text_line_flg=0;
        first_at_flg=0;
        last_at_flg=0;
}

/^${header_version}/ {
        if (first_line_flg==0) {
                first_line_flg=1;
        }
}

/^text/ {
        if (first_line_flg==1 && text_line_flg==0) {
                text_line_flg=1;
        }
}

/^@/ {
        if (first_at_flg==0) {
                if (first_line_flg==1 && text_line_flg==1) {
                        first_at_flg=1; 
                        tmp_str=substr(\$0,2);
                        printf("%s\n",tmp_str);
                        getline;
                }
        }
        else {
                if (first_line_flg==1 && text_line_flg==1) {
                        last_at_flg=1; 
                }
        }
}

{
        if (first_line_flg==1 && text_line_flg==1 && \
            first_at_flg==1 && last_at_flg==0) 
                print \$0;
}
EOF

    # Name of our work directory and output file
    output_file=$output_dir/$work_file.tmp
        
    # Execute AWK script and redirect to output file
    $awk_cmd -f $awk_version $work_file >$output_file

    # Strip out any double @ signs and tack .src on just to prevent
    # overwriting of the original files if an error condition occurs.
    sed -e '/\@\@/s/\@\@/\@/g' \
      $output_file >$output_dir/$work_file.src

    # Cleanup temp work file from AWK/SED step
    rm $output_file
done

# remove temporary files
rm -f $awk_header $awk_version

exit 0