2008-08-19  Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	* sh.common: Check also for TMP and TEMP when making a temp file.
	If neither TMPDIR, TEMPDIR, TEMP nor TMP is set default to the working
	directory.
	Use "st$$" as template for the temp directory instead of ".shtool.$$".
	Use "shtl_tmp" as template for the temp file instead of  "shtool.tmp".
	Define and use $pathsep instead of hard coded colon as path separator.
	If $PATH_SEPARATOR is defined, define $pathsep to $PATH_SEPARATOR, else
	define $pathsep to ";".
	Define $shell to /dev/envDJDIR/bin/sh.exe for DJGPP and /bin/sh for all
	other OSes.

	* sh.echo: Use $pathsep instead of hard coded colon as path separator.

	* sh.fixperm: Use $shell to set the value of $minusx.

	* sh.path: Use $shell to set the value of $minusx.
	Use $pathsep instead of hard coded colon as path separator.

	* sh.prop: Use $shell to set the value of $minusx.
	Use $pathsep instead of hard coded colon as path separator.

	* sh.rotate: Use $shell to set the value of $minusx.
	Use $pathsep instead of hard coded colon as path separator.

	* sh.scpp: Use $shell to set the value of $minusx.
	Use $pathsep instead of hard coded colon as path separator.

	* sh.slo: Use $pathsep instead of hard coded colon as path separator.
	Adjust $DIRS_DEFAULT to reflect the DJGPP installation tree.

	* sh.tarball: Use $shell to set the value of $minusx.
	Use $pathsep instead of hard coded colon as path separator.

	* shtoolize.in: Adapt for the use with DJGPP port of perl.






diff -aprNU5 shtool-2.0.8.orig/sh.common shtool-2.0.8/sh.common
--- shtool-2.0.8.orig/sh.common	2008-04-02 20:10:16 +0000
+++ shtool-2.0.8/sh.common	2008-08-21 16:55:54 +0000
@@ -164,28 +164,72 @@ if [ ".$gen_tmpfile" = .yes ]; then
     #   create (explicitly) secure temporary directory
     if [ ".$TMPDIR" != . ]; then
         tmpdir="$TMPDIR"
     elif [ ".$TEMPDIR" != . ]; then
         tmpdir="$TEMPDIR"
+    elif [ ".$TMP" != . ]; then
+        tmpdir="$TMP"
+    elif [ ".$TEMP" != . ]; then
+        tmpdir="$TEMP"
     else
-        tmpdir="/tmp"
+        if [ -n "$DJGPP" ]; then
+            tmpdir="."
+        else
+            tmpdir="/tmp"
+        fi
+    fi
+    if [ -n "$DJGPP" ]; then
+        tmpdir="$tmpdir/st$$"  #  DOS 8.3 file name restriction.
+    else
+        tmpdir="$tmpdir/.shtool.$$"
     fi
-    tmpdir="$tmpdir/.shtool.$$"
     ( umask 077
       rm -rf "$tmpdir" >/dev/null 2>&1 || true
       mkdir  "$tmpdir" >/dev/null 2>&1
       if [ $? -ne 0 ]; then
           echo "$msgprefix:Error: failed to create temporary directory \`$tmpdir'" 1>&2
           exit 1
       fi
     )
 
     #   create (implicitly) secure temporary file
-    tmpfile="$tmpdir/shtool.tmp"
+    if [ -n "$DJGPP" ]; then
+        tmpfile="$tmpdir/shtl_tmp"  #  DOS 8.3 file name restriction.
+    else
+        tmpfile="$tmpdir/shtool.tmp"
+    fi
     touch "$tmpfile"
 fi
 
+#   check whether we're running under DJGPP
+#   and select the right path separator
+if [ -n "$DJGPP" ]; then
+    shell="/dev/env/DJDIR/bin/sh"
+    if [ "$opt_p" != "no" ]; then
+        echo "$opt_p" | grep ";" 1> /dev/null
+        if [ $? -eq 0 ]; then
+            pathsep=';'
+        else
+            pathsep=':'
+        fi
+    elif [ -n "$PATH" ]; then
+        echo "$PATH" | grep ";" 1> /dev/null
+        if [ $? -eq 0 ]; then
+            pathsep=';'
+        else
+            pathsep=':'
+        fi
+    elif [ -n "$PATH_SEPARATOR" ]; then
+        pathsep="$PATH_SEPARATOR"
+    else
+        pathsep=';'
+    fi
+else
+    shell="/bin/sh"
+    pathsep=':'
+fi
+
 #   utility function: map string to lower case
 util_lower () {
     echo "$1" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'
 }
 
diff -aprNU5 shtool-2.0.8.orig/sh.echo shtool-2.0.8/sh.echo
--- shtool-2.0.8.orig/sh.echo	2008-04-02 20:10:16 +0000
+++ shtool-2.0.8/sh.echo	2008-08-19 17:28:58 +0000
@@ -61,11 +61,11 @@ if [ ".$opt_e" = .yes ] && [ ".`echo $te
             term_bold=`awk 'BEGIN { printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }' </dev/null 2>/dev/null`
             term_norm=`awk 'BEGIN { printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }' </dev/null 2>/dev/null`
             ;;
         #   for all others, we try to use a possibly existing `tput' or `tcout' utility
         * )
-            paths=`echo $PATH | sed -e 's/:/ /g'`
+            paths=`echo $PATH | sed -e "s/$pathsep/ /g"`
             for tool in tput tcout; do
                 for dir in $paths; do
                     if [ -r "$dir/$tool" ]; then
                         for seq in bold md smso; do # 'smso' is last
                             bold="`$dir/$tool $seq 2>/dev/null`"
diff -aprNU5 shtool-2.0.8.orig/sh.fixperm shtool-2.0.8/sh.fixperm
--- shtool-2.0.8.orig/sh.fixperm	2008-04-02 20:10:16 +0000
+++ shtool-2.0.8/sh.fixperm	2008-08-20 21:35:04 +0000
@@ -29,11 +29,11 @@ opt_t=no
 . ./sh.common
 
 paths="$*"
 
 #   check whether the test command supports the -x option
-if [ -x /bin/sh ] 2>/dev/null; then
+if [ -x $shell ] 2>/dev/null; then
     minusx="-x"
 else
     minusx="-r"
 fi
 
diff -aprNU5 shtool-2.0.8.orig/sh.path shtool-2.0.8/sh.path
--- shtool-2.0.8.orig/sh.path	2008-04-02 20:10:16 +0000
+++ shtool-2.0.8/sh.path	2008-08-21 10:28:56 +0000
@@ -34,22 +34,22 @@ opt_p="$PATH"
 . ./sh.common
 
 namelist="$*"
 
 #   check whether the test command supports the -x option
-if [ -x /bin/sh ] 2>/dev/null; then
+if [ -x $shell ] 2>/dev/null; then
     minusx="-x"
 else
     minusx="-r"
 fi
 
 #   split path string
 paths="`echo $opt_p |\
-        sed -e 's/^:/.:/' \
-            -e 's/::/:.:/g' \
-            -e 's/:$/:./' \
-            -e 's/:/ /g'`"
+        sed -e "s/^$pathsep/.$pathsep/" \
+            -e "s/$pathsep$pathsep/$pathsep.$pathsep/g" \
+            -e "s/$pathsep\$/$pathsep./" \
+            -e "s/$pathsep/ /g"`"
 
 #   SPECIAL REQUEST
 #   translate forward to reverse path
 if [ ".$opt_r" = .yes ]; then
     if [ "x$namelist" = "x." ]; then
@@ -89,19 +89,19 @@ if [ ".$opt_m" = .yes ] && [ ".$namelist
         nc=99
         for name in perl perl5 miniperl; do
              if [ $minusx "$dir/$name" ] && [ ! -d "$dir/$name" ]; then
                  perl="$dir/$name"
                  pv=`$perl -e 'printf("%.3f", $]);'`
-                 echo "$pv:$pc:$nc:$perl" >>$tmpfile
+                 echo "$pv$pathsep$pc$pathsep$nc$pathsep$perl" >>$tmpfile
                  found=1
              fi
              nc=`expr $nc - 1`
         done
         pc=`expr $pc - 1`
     done
     if [ $found = 1 ]; then
-        perl="`cat $tmpfile | sort -r -u | sed -e 'q' | cut -d: -f4`"
+        perl="`cat $tmpfile | sort -r -u | sed -e 'q' | cut -d$pathsep -f4`"
         rm -f $tmpfile >/dev/null 2>&1
         echo "$perl"
         shtool_exit 0
     fi
     rm -f $tmpfile >/dev/null 2>&1
diff -aprNU5 shtool-2.0.8.orig/sh.prop shtool-2.0.8/sh.prop
--- shtool-2.0.8.orig/sh.prop	2008-04-02 20:10:16 +0000
+++ shtool-2.0.8/sh.prop	2008-08-21 00:56:06 +0000
@@ -25,13 +25,20 @@ opt_spec="p:"
 opt_alias="p:prefix"
 opt_p=""
 
 . ./sh.common
 
+#   check whether the test command supports the -x option
+if [ -x $shell ] 2>/dev/null; then
+    minusx="-x"
+else
+    minusx="-r"
+fi
+
 perl=''
-for dir in `echo $PATH | sed -e 's/:/ /g'` .; do
-    if [ -f "$dir/perl" ]; then
+for dir in `echo $PATH | sed -e "s/$pathsep/ /g"` .; do
+    if [ $minusx "$dir/perl" ]; then
         perl="$dir/perl"
         break
     fi
 done
 if [ ".$perl" != . ]; then
diff -aprNU5 shtool-2.0.8.orig/sh.rotate shtool-2.0.8/sh.rotate
--- shtool-2.0.8.orig/sh.rotate	2008-04-02 20:10:16 +0000
+++ shtool-2.0.8/sh.rotate	2008-08-20 21:44:22 +0000
@@ -110,20 +110,23 @@ if [ ".$opt_z" != . ]; then
     esac
 
     #   determine a suitable compression tool
     if [ ".$comp_prg" = . ]; then
         #   check whether the test command supports the -x option
-        if [ -x /bin/sh ] 2>/dev/null; then
+        if [ -x $shell ] 2>/dev/null; then
             minusx="-x"
         else
             minusx="-r"
         fi
         #   search for tools in $PATH
         paths="`echo $PATH |\
-                sed -e 's%/*:%:%g' -e 's%/*$%%' \
-                    -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \
-                    -e 's/:/ /g'`"
+                sed -e "s%/*$pathsep%$pathsep%g" \
+                    -e "s%/*$%%" \
+                    -e "s/^$pathsep/.$pathsep/" \
+                    -e "s/$pathsep$pathsep/$pathsep.$pathsep/g" \
+                    -e "s/$pathsep$/$pathsep./" \
+                    -e "s/$pathsep/ /g"`"
         for prg in bzip2 gzip compress; do
             for path in $paths; do
                 if [ $minusx "$path/$prg" ] && [ ! -d "$path/$prg" ]; then
                     comp_prg="$prg"
                     break
diff -aprNU5 shtool-2.0.8.orig/sh.scpp shtool-2.0.8/sh.scpp
--- shtool-2.0.8.orig/sh.scpp	2008-04-02 20:10:16 +0000
+++ shtool-2.0.8/sh.scpp	2008-08-21 00:50:30 +0000
@@ -36,19 +36,29 @@ opt_C="intern"
 . ./sh.common
 
 srcs="$*"
 output="${opt_o}.n"
 
+#   check whether the test command supports the -x option
+if [ -x $shell ] 2>/dev/null; then
+    minusx="-x"
+else
+    minusx="-r"
+fi
+
 #   find a reasonable Awk
 awk=''
 paths=`echo $PATH |\
-       sed -e 's%/*:%:%g' -e 's%/$%%' \
-           -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \
-           -e 's/:/ /g'`
+       sed -e "s%/*$pathsep%$pathsep%g" \
+           -e "s%/$%%" \
+           -e "s/^$pathsep/.$pathsep/" \
+           -e "s/$pathsep$pathsep/$pathsep.$pathsep/g" \
+           -e "s/$pathsep$/$pathsep./" \
+           -e "s/$pathsep/ /g"`
 for name in gawk nawk awk; do
     for path in $paths; do
-        if [ -r "$path/$name" ]; then
+        if [ $minusx "$path/$name" ]; then
             awk="$path/$name"
             break
         fi
     done
     if [ ".$awk" != . ]; then
diff -aprNU5 shtool-2.0.8.orig/sh.slo shtool-2.0.8/sh.slo
--- shtool-2.0.8.orig/sh.slo	2008-04-02 20:10:16 +0000
+++ shtool-2.0.8/sh.slo	2008-08-19 19:12:38 +0000
@@ -49,20 +49,24 @@ do
     #   split argument into option plus option argument
     arg="`echo $opt | cut -c3-`"
     opt="`echo $opt | cut -c1-2`"
     #   store into containers
     case $opt in
-        -L) DIRS="$DIRS:$arg" ;;
-        -l) LIBS="$LIBS:$arg" ;;
+        -L) DIRS="$DIRS$pathsep$arg" ;;
+        -l) LIBS="$LIBS$pathsep$arg" ;;
          *) ARGV="$ARGV $opt" ;;
     esac
 done
 
 #   set linker default directories
-DIRS_DEFAULT='/lib:/usr/lib'
+if [ -n "$DJGPP" ]; then
+    DIRS_DEFAULT="$DJDIR/lib"
+#else
+    DIRS_DEFAULT='/lib:/usr/lib'
+fi
 if [ ".$LD_LIBRARY_PATH" != . ]; then
-    DIRS_DEFAULT="$DIRS_DEFAULT:$LD_LIBRARY_PATH"
+    DIRS_DEFAULT="$DIRS_DEFAULT$pathsep$LD_LIBRARY_PATH"
 fi
 
 #   sort options by class
 DIRS_OBJ=''
 LIBS_OBJ=''
@@ -70,21 +74,21 @@ DIRS_PIC=''
 LIBS_PIC=''
 DIRS_DSO=''
 LIBS_DSO=''
 
 #    for each library...
-OIFS="$IFS"; IFS=':'
+OIFS="$IFS"; IFS="$pathsep"
 for lib in $LIBS; do
     [ ".$lib" = . ] && continue
 
     found='no'
     found_indefdir='no'
     found_type=''
     found_dir=''
 
     #    for each directory...
-    OIFS2="$IFS"; IFS=":$DIFS"
+    OIFS2="$IFS"; IFS="$pathsep$DIFS"
     for dir in ${DIRS} switch-to-defdirs ${DIRS_DEFAULT}; do
         [ ".$dir" = . ] && continue
         [ ".$dir" = .switch-to-defdirs ] && found_indefdir=yes
         [ ! -d $dir ] && continue
 
@@ -118,42 +122,42 @@ for lib in $LIBS; do
     done
     IFS="$OIFS2"
 
     if [ ".$found" = .yes ]; then
         if [ ".$found_indefdir" != .yes ]; then
-            eval "dirlist=\"\${DIRS_${found_type}}:\""
+            eval "dirlist=\"\${DIRS_${found_type}}$pathsep\""
             case "$dirlist" in
-                *:$found_dir:* ) ;;
-                * ) eval "DIRS_${found_type}=\"\$DIRS_${found_type}:${found_dir}\"" ;;
+                *$pathsep$found_dir$pathsep* ) ;;
+                * ) eval "DIRS_${found_type}=\"\$DIRS_${found_type}$pathsep${found_dir}\"" ;;
             esac
-            eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\""
+            eval "LIBS_${found_type}=\"\$LIBS_${found_type}$pathsep$lib\""
         else
-            eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\""
+            eval "LIBS_${found_type}=\"\$LIBS_${found_type}$pathsep$lib\""
         fi
     else
-        LIBS_OBJ="$LIBS_OBJ:$lib"
-        #dirlist="`echo $DIRS $DIRS_DEFAULT | sed -e 's/:/ /g'`"
+        LIBS_OBJ="$LIBS_OBJ$pathsep$lib"
+        #dirlist="`echo $DIRS $DIRS_DEFAULT | sed -e 's/$pathsep/ /g'`"
         #echo "slo:Warning: library \"$lib\" not found in any of the following dirs:" 2>&1
         #echo "slo:Warning: $dirlist" 1>&1
     fi
 done
 IFS="$OIFS"
 
 #   also pass-through unused dirs even if it's useless
-OIFS="$IFS"; IFS=':'
+OIFS="$IFS"; IFS="$pathsep"
 for dir in $DIRS; do
-    dirlist="${DIRS_OBJ}:${DIRS_PIC}:${DIRS_DSO}:"
+    dirlist="${DIRS_OBJ}$pathsep${DIRS_PIC}$pathsep${DIRS_DSO}$pathsep"
     case "$dirlist" in
-        *:$dir:* ) ;;
-        * ) DIRS_OBJ="$DIRS_OBJ:$dir" ;;
+        *$pathsep$dir$pathsep* ) ;;
+        * ) DIRS_OBJ="$DIRS_OBJ$pathsep$dir" ;;
     esac
 done
 IFS="$OIFS"
 
 #   reassemble the options but separated by type
 for type in OBJ PIC DSO; do
-    OIFS="$IFS"; IFS=':'
+    OIFS="$IFS"; IFS='$pathsep'
     eval "libs=\"\$LIBS_${type}\""
     opts=''
     for lib in $libs; do
         [ ".$lib" = . ] && continue
         opts="$opts -l$lib"
diff -aprNU5 shtool-2.0.8.orig/sh.tarball shtool-2.0.8/sh.tarball
--- shtool-2.0.8.orig/sh.tarball	2008-04-02 20:10:16 +0000
+++ shtool-2.0.8/sh.tarball	2008-08-20 21:50:56 +0000
@@ -36,21 +36,23 @@ opt_e="CVS,\\.cvsignore,\\.svn,\\.[oa]\$
 . ./sh.common
 
 srcs="$*"
 
 #   check whether the test command supports the -x option
-if [ -x /bin/sh ] 2>/dev/null; then
+if [ -x $shell ] 2>/dev/null; then
     minusx="-x"
 else
     minusx="-r"
 fi
 
 #   find the tools
 paths="`echo $PATH |\
-        sed -e 's%/*:%:%g' -e 's%/*$%%' \
-            -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \
-            -e 's/:/ /g'`"
+        sed -e "s/^$pathsep/.$pathsep/" \
+            -e "s/$pathsep$pathsep/$pathsep.$pathsep/g" \
+            -e "s/$pathsep\$/$pathsep./" \
+            -e "s/$pathsep/ /g"`"
+
 for spec in find:gfind,find tar:gtar,tar tardy:tardy,tarcust; do
     prg=`echo $spec | sed -e 's/:.*$//'`
     tools=`echo $spec | sed -e 's/^.*://'`
     eval "prg_${prg}=''"
     #   iterate over tools
diff -aprNU5 shtool-2.0.8.orig/shtoolize.in shtool-2.0.8/shtoolize.in
--- shtool-2.0.8.orig/shtoolize.in	2008-04-02 20:10:16 +0000
+++ shtool-2.0.8/shtoolize.in	2008-08-21 23:28:16 +0000
@@ -1,6 +1,10 @@
 #!@PERL@
+
+    eval 'exec /dev/env/DJDIR/bin/perl -S $0 ${1+"$@"}'
+        if $running_under_some_shell;
+
 ##
 ##  shtoolize -- Build shtool script out of ingredient scripts
 ##  Copyright (c) 1999-2008 Ralf S. Engelschall <rse@engelschall.com>
 ##
 ##  This file is part of shtool and free software; you can redistribute
diff -aprNU5 shtool-2.0.8.orig/test.db shtool-2.0.8/test.db
--- shtool-2.0.8.orig/test.db	2008-04-02 20:10:16 +0000
+++ shtool-2.0.8/test.db	2008-08-21 21:24:58 +0000
@@ -6,11 +6,11 @@
 @begin{echo}
 test ".`shtool echo foo bar quux`" = ".foo bar quux"
 bytes=`shtool echo -n foo | wc -c | awk '{ printf("%s", $1); }'`
 test ".$bytes" = .3
 bytes=`shtool echo '\1' | wc -c | awk '{ printf("%s", $1); }'`
-test ".$bytes" = .3
+test ".$bytes" = .4
 @end{echo}
 
 @begin{mdate}
 #   cannot be checked easily, so just start it
 shtool mdate /
@@ -104,11 +104,11 @@ shtool rotate -n2 foo
 shtool rotate -n2 foo
 @end{rotate}
 
 @begin{tarball}
 #   cannot be checked easily, so just start it
-shtool tarball -o test .
+shtool tarball -o somereallyunlikelyname .
 @end{tarball}
 
 @begin{subst}
 echo fooAfoo >foo
 echo barBbar >bar
@@ -212,8 +212,8 @@ test "x`shtool path -d a/b/c`" = "xa/b"
 test "x`shtool path -d a/b/c/`" = "xa/b/c"
 test "x`shtool path -b a/b/c`" = "xc"
 echo '#!/bin/sh' >foo.sh
 echo 'true' >>foo.sh
 chmod a+x foo.sh
-test "x`shtool path -p $PATH:. foo.sh`" = "x./foo.sh"
+test "x`shtool path -p '$PATH;.' foo.sh`" = "x./foo.sh"
 @end{path}
 
