tasty change to add a new category. this is definitely still a fred-realm script...
[feisty_meow.git] / scripts / generator / wrapdoze.sh
old mode 100644 (file)
new mode 100755 (executable)
index 758fc76..ab0a999
@@ -2,41 +2,75 @@
 
 source $FEISTY_MEOW_SCRIPTS/core/functions.sh
 
+#hmmm: make this support multiple vars as parameters.
+# replaces a specific environment variable with a dos approved equivalent.
+function dossify_environment_variable()
+{
+  local var="$1"; shift
+
+  old_value="${!var}"
+  if [[ ! "$old_value" =~ \/cygdrive\/ ]]; then
+#echo didnt have a cygdrive in it: $old_value
+    return 0
+#hmmm: want this to continue in multi parm version.
+  fi
+
+  # replace single back-slashes with double ones.
+  local new_value="$(unix_to_dos_path "${old_value}")"
+
+  # remove any quote characters in the value.
+  new_value="${new_value//\"/}"
+
+#  echo "new value: $var  =  $new_value"
+  eval "export $var=\"$new_value\""
+}
+
+# for a windows build, this will replace any forward slashes
+# and other cygwin notation with the appropriate dos style paths.
 function dossify_and_run_commands()
 {
+  if [ "$OS" != "Windows_NT" ]; then
+    # for non windows, just run the commands straight up.
+    eval "${@}"
+    return $?
+  fi
+
+  # force all slashes to be dossy.
+#  export SERIOUS_SLASH_TREATMENT=true
+
+  dossify_environment_variable INCLUDE
+
   declare -a darc_commands=()
 
   for i in "$@"; do
-    # we only mess with the command line on windows.
-    if [ "$OS" == "Windows_NT" ]; then
-      if [[ "$i" =~ ^-[a-zA-z][/\"].* ]]; then
-#echo matched on our pattern for parameters
-        flag="${i:0:2}"
-        filename="$(unix_to_dos_path ${i:2})"
-
+    if [[ "$i" =~ ^-[a-zA-z][/\"].* ]]; then
+      flag="${i:0:2}"
+      filename="$(unix_to_dos_path ${i:2})"
 #echo "first two chars are $flag"
 #echo "last after that are $filename"
-#combined="$flag$filename"
-#echo combined is $combined
-      
-        darc_commands+=("$flag$filename")
-      else 
-        darc_commands+=($(unix_to_dos_path $i))
-      fi
-    else
-      darc_commands+=("$i")
+      recombined="$flag$filename"
+#echo combined flag and file is $recombined
+      darc_commands+=("$recombined")
+    else 
+      darc_commands+=($(unix_to_dos_path $i))
     fi
   done
 
-#temp!
-  echo commands are now: >>/tmp/wrapdoze.log
+  declare -a real_commands=()
   for i in "${darc_commands[@]}"; do
-    echo $i >>/tmp/wrapdoze.log
+    real_commands+=($(echo $i | sed -e 's/\\/\\\\/g'))
   done
-#end temp
 
-  # now actually run the possibly chewed command.
-  "${darc_commands[@]}"
+  if [ ! -z "$SHELL_DEBUG" ]; then
+    echo commands are now:
+    for i in "${real_commands[@]}"; do
+      echo -n "$i "
+    done
+    echo
+  fi
+
+  # now actually run the chewed command.
+  cmd /c "${real_commands[@]}"
 }
 
 dossify_and_run_commands "$@"