WeiDUorg / weidu

WeiDU is a program used to develop, distribute and install modifications for games based on the Infinity Engine.
http://www.weidu.org
GNU General Public License v2.0
88 stars 19 forks source link

Toggle for lower-casing IO calls doesn't affect results of BASH_FOR #126

Closed Argent77 closed 10 months ago

Argent77 commented 6 years ago

The CL switch --case-exact, added by commit 1bdf5bc677d83d178ec195af9d98c5b3eb96f250, doesn't affect variables set by the command (ACTION|PATCH)_BASH_FOR. Subsequent commands that are making use of them may fail to function because of it.

As a quick & dirty fix I have made this hack. However, since I don't know whether it introduces unwanted side effects, I'm posting it here instead of making a regular pull request.

diff --git a/src/case_ins_mac.ml b/src/case_ins_mac.ml
index 63a5d29..9dffdce 100755
--- a/src/case_ins_mac.ml
+++ b/src/case_ins_mac.ml
@@ -3,6 +3,9 @@ open Hashtblinit

 let case_exact = ref false

+let case_transform s =
+  String.uppercase s
+
 let backslash_to_slash s =
   let s = Str.global_replace (Str.regexp "\\\\") "/" s in
                s
diff --git a/src/case_ins_win.ml b/src/case_ins_win.ml
index 91a1c55..b5ae212 100755
--- a/src/case_ins_win.ml
+++ b/src/case_ins_win.ml
@@ -3,6 +3,9 @@ open Hashtblinit

 let case_exact = ref false

+let case_transform s =
+  String.uppercase s
+
 (* Pervasives FS calls *)
 let perv_open_out s = open_out s ;;
 let perv_open_out_gen m i s = open_out_gen m i s ;;
diff --git a/src/tppatch.ml b/src/tppatch.ml
index fc9b113..fa95b6d 100755
--- a/src/tppatch.ml
+++ b/src/tppatch.ml
@@ -632,7 +632,7 @@ let rec process_patch2_real process_action tp our_lang patch_filename game buff
                   if ((Case_ins.unix_stat
                          (directory ^ "/" ^ next)).Unix.st_kind =
                       Unix.S_REG) && (Str.string_match reg next 0) then
-                    find_list := (String.uppercase
+                    find_list := (Case_ins.case_transform
                                     (directory ^ "/" ^ next)) :: !find_list
                 done
               with End_of_file -> ());
FredrikLindgren commented 6 years ago

The problem here is that BASH_FOR is covered by backward-compatibility. The variables are expected to have uppercased content and I can't change that without potentially breaking something else. I'm honestly unsure what to do. You could fix this case by tying the uppercasing into the CL toggle, but I'm not eager to do that, because it's an ugly fix that will potentially cause complications further on. And then there are the other 11 million cases of String.upper/lowercase that WeiDU uses, possibly problematically, I don't know.