--- compressdoc.orig	2009-12-10 23:23:49.000000000 +0300
+++ compressdoc	2009-12-10 23:08:36.000000000 +0300
@@ -398,19 +398,37 @@
     else # !dir
       if ! check_unique "$DIR" "$FILE"; then continue; fi
 
+      # echo -n "Processing $FILE... "
+
       # With automatic compression, get the uncompressed file size of
       # the file (dereferencing symlinks), and choose an appropriate
       # compression method.
       if [ "$COMP_METHOD" = "--automatic" ]; then
         declare -i SIZE
-        case "$FILE" in
-          *.bz2)
-            SIZE=$(bzcat "$FILE" | wc -c) ;;
-          *.gz)
-            SIZE=$(zcat "$FILE" | wc -c) ;;
-          *)
-            SIZE=$(wc -c < "$FILE") ;;
-        esac
+        if [ -h "$FILE" ]; then
+          FILE_DEST=`ls -l "$FILE" | cut -d ">" -f2 \
+                     | tr -d " "`
+          FILE_DEST=`basename "$FILE_DEST" .gz`
+          FILE_DEST=`basename "$FILE_DEST" .bz2`
+          if [ -a "${FILE_DEST}.gz" ]; then
+              SIZE=$(zcat "${FILE_DEST}.gz" | wc -c)
+          elif [ -a "${FILE_DEST}.bz2" ]; then
+              SIZE=$(bzcat "${FILE_DEST}.bz2" | wc -c)
+          else
+              SIZE=$(wc -c < "$FILE")
+          fi
+          # echo "this is a link; it points to file with size $SIZE bytes"
+        else
+          case "$FILE" in
+            *.bz2)
+              SIZE=$(bzcat "$FILE" | wc -c) ;;
+            *.gz)
+              SIZE=$(zcat "$FILE" | wc -c) ;;
+            *)
+              SIZE=$(wc -c < "$FILE") ;;
+          esac
+          # echo "this is a file with size $SIZE bytes"
+        fi
         if (( $SIZE >= (5 * 2**10) )); then
           COMP_SUF=.bz2
         elif (( $SIZE >= (1 * 2**10) )); then
