lzwScript |
| #!/bin/bash # Run this file from your ex9 package directory # # Set up a directory inside your ex9 directory with your test files in it # # Change the variables below to reflect your directory names # # This script will take each of the files # located in the tests directory, # and run your compress program on it. # It will then display the size of the compressed file # and indicate whether the LZW has made the file # larger or smaller than the original # Change this to suit your directory structure ROOTDIR=$JAVA_DEV_ROOT/src/jlittle_ex9 # Directory your LZW Compress program is in COMPRESSDIR=$ROOTDIR/compress # Directory your LZW Decompress program is in DECOMPRESSDIR=$ROOTDIR/decompress # Directory your test files are in TESTDIR=$ROOTDIR/LZWtests # Directory to store temporary files TEMPDIR=$ROOTDIR/LZWtemp # The Script # -------------------------------------------------------- # DO NOT ALTER THIS UNLESS YOU KNOW WHAT YOU ARE DOING !!! # -------------------------------------------------------- # Create the temp directory mkdir $TEMPDIR # Make your compress program echo ---------------------------------------------------------------- echo Making compression program...... echo cd $COMPRESSDIR make -s cd $TESTDIR echo Now compress each test file and compare size to orginal echo # for each test file compress and compare size to original for testfile in `ls` do # Get the original size origsize=`ls -l | grep " ${testfile}$" | awk '{print $5} ;'` # Header for report echo $testfile echo ------------------------------ echo Original Size: ' '$origsize # perform compression cd $COMPRESSDIR make run < ${TESTDIR}/${testfile} > ${TEMPDIR}/${testfile} cd $TEMPDIR # get the new size compsize=`ls -l | grep " $testfile$" | awk '{print $5} ;'` # compare and output if [ $origsize == $compsize ] then echo Compressed Size: $compsize = Same size else if [ $origsize -gt $compsize ] then echo Compressed Size: $compsize = Reduction in size else echo Compressed Size: $compsize = Increase in size fi fi cd $TESTDIR echo done # Make your decompression program echo --------------------------------------------------------------------- echo Making decompression program...... cd $DECOMPRESSDIR make -s echo echo Now decompress each file and compare to orginal........... echo # See if decompression results in original file. for testfile in `ls $TEMPDIR` do make run < ${TEMPDIR}/${testfile} > ${TEMPDIR}/${testfile}.tmp.txt # Find the difference diff ${TEMPDIR}/${testfile}.tmp.txt ${TESTDIR}/${testfile} > /dev/null # output result if [ $? -eq 0 ]; then echo Compress / Decompress successful for $testfile else echo Compress / Decompress UNSUCCESSFUL for $testfile fi # remove temporary file rm -f ${TEMPDIR}/${testfile}.tmp.txt done # remove temporary directory rm -rf $TEMPDIR # end script # # Peter Eaton # 23/4/01 # For cosc241 students |
James Little |