put the environment variable cleaner back in, although it didn't help.
[feisty_meow.git] / scripts / generator / wrapdoze.sh
1 #!/bin/bash
2
3 source $FEISTY_MEOW_SCRIPTS/core/functions.sh
4
5 #hmmm: make this support multiple vars as parameters.
6 # replaces a specific environment variable with a dos approved equivalent.
7 function dossify_environment_variable()
8 {
9   local var="$1"; shift
10
11   old_value="${!var}"
12   if [[ ! "$old_value" =~ \/cygdrive\/ ]]; then
13 #echo didnt have a cygdrive in it: $old_value
14     return 0
15 #hmmm: want this to continue in multi parm version.
16   fi
17
18   # replace single back-slashes with double ones.
19   local new_value="$(unix_to_dos_path "${old_value}")"
20
21   # remove any quote characters in the value.
22   new_value="${new_value//\"/}"
23
24 #  echo "new value: $var  =  $new_value"
25   eval "export $var=\"$new_value\""
26 }
27
28 # for a windows build, this will replace any forward slashes
29 # and other cygwin notation with the appropriate dos style paths.
30 function dossify_and_run_commands()
31 {
32   if [ "$OS" != "Windows_NT" ]; then
33     # for non windows, just run the commands straight up.
34     eval "${@}"
35     return $?
36   fi
37
38   # force all slashes to be dossy.
39 #  export SERIOUS_SLASH_TREATMENT=true
40
41   dossify_environment_variable INCLUDE
42
43   declare -a darc_commands=()
44
45   for i in "$@"; do
46     if [[ "$i" =~ ^-[a-zA-z][/\"].* ]]; then
47       flag="${i:0:2}"
48       filename="$(unix_to_dos_path ${i:2})"
49 #echo "first two chars are $flag"
50 #echo "last after that are $filename"
51       recombined="$flag$filename"
52 #echo combined flag and file is $recombined
53       darc_commands+=("$recombined")
54     else 
55       darc_commands+=($(unix_to_dos_path $i))
56     fi
57   done
58
59   declare -a real_commands=()
60   for i in "${darc_commands[@]}"; do
61     real_commands+=($(echo $i | sed -e 's/\\/\\\\/g'))
62   done
63
64   if [ ! -z "$SHELL_DEBUG" ]; then
65     echo commands are now:
66     for i in "${real_commands[@]}"; do
67       echo -n "$i "
68     done
69     echo
70   fi
71
72   # now actually run the chewed command.
73   cmd /c "${real_commands[@]}"
74 }
75
76 dossify_and_run_commands "$@"
77