Author Topic: Case sensitive/insensitive 2da patching  (Read 2769 times)

Offline cmorgan

  • Planewalker
  • *****
  • Posts: 1424
  • Gender: Male
  • Searcher of Bugs
Case sensitive/insensitive 2da patching
« on: January 02, 2007, 11:47:39 AM »
in BG1 NPC Project BG1NPC.tp2:
Code: [Select]
/* .2da patching */
ACTION_IF FILE_EXISTS_IN_GAME ~FW0100.are~ THEN BEGIN
  APPEND ~interdia.2da~ ~IMOEN                    _BIMOEN~ UNLESS ~_BIMOEN~
END ELSE BEGIN  /* BGT Versions */
  COPY_EXISTING ~interdia.2da~ ~override~
    REPLACE_TEXTUALLY CASE_INSENSITIVE ~IMOEN2[ %tab%]+NONE[ %tab%]+BIMOEN25~
      ~IMOEN2      BIMOEN2       BIMOEN25~
    BUT_ONLY_IF_IT_CHANGES
END
This code results in a duplicate entry for Imoen in the Tutu interdia.2da on some installs
_imoen       _bimoen
_IMOEN      _BIMOEN

due to multiple fixes being applied. While I think the engine couldn't care less (and we cannot prove any error results) I am not completely positive; is there a way of either using CASE_INSENSITIVE or an aditional qualifier to UNLESS or something to
APPEND ~interdia.2da~ ~IMOEN                    _BIMOEN~ UNLESS ~_BIMOEN~
with the result being only one entry?

Nythrun@work

  • Guest
Re: Case sensitive/insensitive 2da patching
« Reply #1 on: January 02, 2007, 12:17:15 PM »
UNLESS ~_\(IMOEN\|imoen\)~

Offline cmorgan

  • Planewalker
  • *****
  • Posts: 1424
  • Gender: Male
  • Searcher of Bugs
Re: Case sensitive/insensitive 2da patching
« Reply #2 on: January 02, 2007, 12:20:22 PM »
there are times when i simply cannot connect the simplest of dots...

thank you!  ;D

I just realized - my blue portion was wrong, so the correct regexp to append ~IMOEN _BIMOEN~ UNLESS ~_BIMOEN~
should be
UNLESS ~_\(BIMOEN\|bimoen\)~, meaning the UNLESS looks for _BIMOEN or _bimoen...

back to look at regular expressions usage again!
« Last Edit: January 02, 2007, 12:30:35 PM by cmorgan »

Nythrun@work

  • Guest
Re: Case sensitive/insensitive 2da patching
« Reply #3 on: January 02, 2007, 12:45:52 PM »
You might even want ~_[bB][iI][mM][oO][eE][nN]~ (so ugly!)

It's also okay to do multiple when clauses:

APPEND ~blah~ ~blah~
UNLESS ~_bimoen~
UNLESS ~_BIMOEN~

Sleepytime!

Offline cmorgan

  • Planewalker
  • *****
  • Posts: 1424
  • Gender: Male
  • Searcher of Bugs
Re: Case sensitive/insensitive 2da patching
« Reply #4 on: January 02, 2007, 12:48:23 PM »
and since I am clouding up things by regexp I might as well ask here, too...


I am trying to simplify
Code: [Select]
/* Patching BG1NPC added creatures for Walking Speeds */
COPY_EXISTING ~X#KABAND.CRE~ ~override~
              ~X#BANDK1.CRE~ ~override~
              ~X#BANDK2.CRE~ ~override~
              ~X#BANDK3.CRE~ ~override~
              ~X#ASSI11.CRE~ ~override~ etc.etc. for lots of .cres
I think I am not understanding something with usage. If I do

COPY_EXISTING_REGEXP GLOB ~^X#\[A-Za-z0-9]\.cre$~ ~override~
  PATCH_IF etc., etc.

do I C_E_R G all things that begin with X#  and have anything consisting of letters and numbers of any case here and end with .cre ?

/edit-
ahhh - cross posting - good night, and thank you :)
« Last Edit: January 02, 2007, 12:49:55 PM by cmorgan »

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: Case sensitive/insensitive 2da patching
« Reply #5 on: January 02, 2007, 12:53:55 PM »
I should add the multiple choices to UNLESS & related constraints, were it not for the fact that Weimer, in his infinite wisdom, decided to copy-and-paste the UNLESS code in thirty different places, rather than doing it once, making me cautious about changing that. Seriously, if a number of things were implemented just once, rather than being pasted every time it was used, the WeiDU source code would be 27000 lines of code, rather than 30000 (not to mention the risks involved with maintaining the same code in more than one place).

Also, COPY_EXISTING_REGEXP (and other stuff using regexp on file names) are in most cases case-insensitive. In your case, COPY_EXISTING ~^X#.*\.cre$~ would work (the . matches any character, so X#s1-8.cre would be matched, if used).
Author or Co-Author: WeiDU (http://j.mp/bLtjOn) - Widescreen (http://j.mp/aKAiqG) - Generalized Biffing (http://j.mp/aVgw3U) - Refinements (http://j.mp/bLHoCc) - TB#Tweaks (http://j.mp/ba02Eg) - IWD2Tweaks (http://j.mp/98OFYY) - TB#Characters (http://j.mp/ak8J55) - Traify Tool (http://j.mp/g1Ry9A) - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics (http://j.mp/9UeIwB) - Nalia Mod (http://j.mp/dng9l0) - Nvidia Fix (http://j.mp/aRWjjg)
Code dumps: Detect custom secondary types (http://j.mp/hVzzXG) - Stutter Investigator (http://j.mp/gdtBn8)

If possible, send diffs, translations and other contributions using Git (http://j.mp/aBZFrq).

Offline devSin

  • Planewalker
  • *****
  • Posts: 1632
  • Gender: Male
Re: Case sensitive/insensitive 2da patching
« Reply #6 on: January 02, 2007, 12:57:21 PM »
Aren't UNLESS and just about everything else that matches text (and the default behavior of OCaml grep) case-insensitive (other than the strcmp stuff)?

I know REPLACE_TEXTUALLY WHATEVER SOMETHING will match whatever or Whatever (blah blah exhaustive list), but I don't use any of the funky constraints.

Whatever.

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: Case sensitive/insensitive 2da patching
« Reply #7 on: January 02, 2007, 01:03:48 PM »
Aren't UNLESS and just about everything else that matches text (and the default behavior of OCaml grep) case-insensitive (other than the strcmp stuff)?
UNLESS uses regexp, which are case-sensitive (at least so on Windows and Linux). Since apparently the regexp available on Mac are different than those on Windows, YMMV.
Author or Co-Author: WeiDU (http://j.mp/bLtjOn) - Widescreen (http://j.mp/aKAiqG) - Generalized Biffing (http://j.mp/aVgw3U) - Refinements (http://j.mp/bLHoCc) - TB#Tweaks (http://j.mp/ba02Eg) - IWD2Tweaks (http://j.mp/98OFYY) - TB#Characters (http://j.mp/ak8J55) - Traify Tool (http://j.mp/g1Ry9A) - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics (http://j.mp/9UeIwB) - Nalia Mod (http://j.mp/dng9l0) - Nvidia Fix (http://j.mp/aRWjjg)
Code dumps: Detect custom secondary types (http://j.mp/hVzzXG) - Stutter Investigator (http://j.mp/gdtBn8)

If possible, send diffs, translations and other contributions using Git (http://j.mp/aBZFrq).

Offline devSin

  • Planewalker
  • *****
  • Posts: 1632
  • Gender: Male
Re: Case sensitive/insensitive 2da patching
« Reply #8 on: January 02, 2007, 01:07:51 PM »
That doesn't extend to REPLACE_TEXTUALLY though, right? I've never needed to use the constraints and never have, but R_T has always been case-insensitive here.

The grep behavior is likely the same between Mac OS X and Linux (I've never payed attention to it), but I don't place any faith in OCaml's regexp stuff doing anything right (in cases where it does anything at all).

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: Case sensitive/insensitive 2da patching
« Reply #9 on: January 02, 2007, 01:11:41 PM »
That doesn't extend to REPLACE_TEXTUALLY though, right? I've never needed to use the constraints and never have, but R_T has always been case-insensitive here.
It's possible that R_T uses Str.regexp_case_fold rather than Str.regexp, making it case-insensitive. Usually, you may assume that Weimer used whatever suited him the better when he was coding a given command, rather than following any kind of project document, making the possibility of some commands being c-s and some others being c-i quite probable.
Author or Co-Author: WeiDU (http://j.mp/bLtjOn) - Widescreen (http://j.mp/aKAiqG) - Generalized Biffing (http://j.mp/aVgw3U) - Refinements (http://j.mp/bLHoCc) - TB#Tweaks (http://j.mp/ba02Eg) - IWD2Tweaks (http://j.mp/98OFYY) - TB#Characters (http://j.mp/ak8J55) - Traify Tool (http://j.mp/g1Ry9A) - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics (http://j.mp/9UeIwB) - Nalia Mod (http://j.mp/dng9l0) - Nvidia Fix (http://j.mp/aRWjjg)
Code dumps: Detect custom secondary types (http://j.mp/hVzzXG) - Stutter Investigator (http://j.mp/gdtBn8)

If possible, send diffs, translations and other contributions using Git (http://j.mp/aBZFrq).

Offline cmorgan

  • Planewalker
  • *****
  • Posts: 1424
  • Gender: Male
  • Searcher of Bugs
Re: Case sensitive/insensitive 2da patching
« Reply #10 on: January 02, 2007, 01:21:18 PM »
I see that to make case not matter for REPLACE_TEXTUALLY I just add CASE_INSENSITIVE, so for my purposes the current WeiDU code does great stuff -

and I think that you are saying, the bigg, that I don't need to use COPY_EXISTING_REGEXP GLOB here, I should leave the
ALLOW_MISSING  ~X#KABAND.CRE~              
~X#BANDK1.CRE~
~X#BANDK2.CRE~              
~X#BANDK3.CRE~
~X#ASSI11.CRE~ etc.etc. for lots of .cres

and then use

/* Patching BG1NPC added creatures for Walking Speeds */
COPY_EXISTING ~^X#*.cre$~ ~override~
  PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN
    PATCH_IF (("%adjust_speed%" = 1) AND ("%eff_version%" < 2)) BEGIN
    READ_BYTE  0x33  "eff_version" ELSE 2

I have standardized the .cre names to capital letters, even though the docs say that case does not matter with tp2 writing AnD i Do NoT wAnT tO WiN YoUr DoCuMeNtEd ChAlLeNgE rEgArDiNg CaPtAlIzAtIoN!

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: Case sensitive/insensitive 2da patching
« Reply #11 on: January 02, 2007, 01:25:33 PM »
and I think that you are saying, the bigg, that I don't need to use COPY_EXISTING_REGEXP GLOB here[...]
No, that was a typo - you should use COPY_EXISTING_REGEXP_GLOB. ALLOW_MISSING can be ditched.

Quote
I have standardized the .cre names to capital letters, even though the docs say that case does not matter with tp2 writing AnD i Do NoT wAnT tO WiN YoUr DoCuMeNtEd ChAlLeNgE rEgArDiNg CaPtAlIzAtIoN!
If anything, using lowercase is good for Linux users. However, we have a simple program to lowercase all the bg2 directory, so that isn't as boring as it sounds.
Author or Co-Author: WeiDU (http://j.mp/bLtjOn) - Widescreen (http://j.mp/aKAiqG) - Generalized Biffing (http://j.mp/aVgw3U) - Refinements (http://j.mp/bLHoCc) - TB#Tweaks (http://j.mp/ba02Eg) - IWD2Tweaks (http://j.mp/98OFYY) - TB#Characters (http://j.mp/ak8J55) - Traify Tool (http://j.mp/g1Ry9A) - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics (http://j.mp/9UeIwB) - Nalia Mod (http://j.mp/dng9l0) - Nvidia Fix (http://j.mp/aRWjjg)
Code dumps: Detect custom secondary types (http://j.mp/hVzzXG) - Stutter Investigator (http://j.mp/gdtBn8)

If possible, send diffs, translations and other contributions using Git (http://j.mp/aBZFrq).

Offline cmorgan

  • Planewalker
  • *****
  • Posts: 1424
  • Gender: Male
  • Searcher of Bugs
Re: Case sensitive/insensitive 2da patching
« Reply #12 on: January 02, 2007, 01:37:46 PM »
aaargh - I just standardized the dv's as lowercase to match older usages, and standardized the files and file extensions to uppercase - manually!

Good old DOS 4 - still coming back to haunt me. It sounds like I had better go read your posts on Linux/Wine compatible modding, and do some rechecks.

To recap (and make sure I have it correct) I have several mod components which add creatures and can be installed (or not) by user choice. As far as I can tell, the ALLOW_MISSING was only there to accomodae a manual list of all BG1 NPC Project creatures being loaded via COPY_EXISTING.


I can
1. delete the ALLOW_MISSING block of the tp2
2. replace the C_E list of added creatures with
/* Patching BG1NPC added creatures for Walking Speeds */
COPY_EXISTING_REGEXP GLOB  ~^X#*.cre$~ ~override~
  PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN
    PATCH_IF (("%adjust_speed%" = 1) AND ("%eff_version%" < 2)) BEGIN
    READ_BYTE  0x33  "eff_version" ELSE 2

and this will avoid having to rebuild the lists for the walking speeds component; I can use the same code in any situations where I need to do mass checks/patches on all project-related .cres as they all use the X# prefix.
i.e.
COPY_EXISTING_REGEXP GLOB  ~^X#*.cre$~ ~override~
  PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN
     LAUNCH_PATCH_MACRO ~tutu_items_to_bgt_items~
  END
and the resulting behavior will be each creature that begins with X# and ends with .cre (that is not a 0 byte file) will be patched,

right?



Offline the bigg

  • The Avatar of Fighter / Thieves
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: Case sensitive/insensitive 2da patching
« Reply #13 on: January 02, 2007, 01:47:11 PM »
Yes, exactly.
Author or Co-Author: WeiDU (http://j.mp/bLtjOn) - Widescreen (http://j.mp/aKAiqG) - Generalized Biffing (http://j.mp/aVgw3U) - Refinements (http://j.mp/bLHoCc) - TB#Tweaks (http://j.mp/ba02Eg) - IWD2Tweaks (http://j.mp/98OFYY) - TB#Characters (http://j.mp/ak8J55) - Traify Tool (http://j.mp/g1Ry9A) - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics (http://j.mp/9UeIwB) - Nalia Mod (http://j.mp/dng9l0) - Nvidia Fix (http://j.mp/aRWjjg)
Code dumps: Detect custom secondary types (http://j.mp/hVzzXG) - Stutter Investigator (http://j.mp/gdtBn8)

If possible, send diffs, translations and other contributions using Git (http://j.mp/aBZFrq).

Offline cmorgan

  • Planewalker
  • *****
  • Posts: 1424
  • Gender: Male
  • Searcher of Bugs
Re: Case sensitive/insensitive 2da patching
« Reply #14 on: January 02, 2007, 02:13:51 PM »
 8) I am off to modify project files - thank you!

Offline cmorgan

  • Planewalker
  • *****
  • Posts: 1424
  • Gender: Male
  • Searcher of Bugs
Re: Case sensitive/insensitive 2da patching
« Reply #15 on: January 03, 2007, 03:03:13 PM »
Unfortunately, this code
Code: [Select]
/* Patching all creatures in component for Tutu > BGT items */
ACTION_IF FILE_EXISTS ~data/BG1ARE.bif~ THEN BEGIN
  COPY_EXISTING_REGEXP GLOB  ~^X#*.cre$~ ~override~
    PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN
     LAUNCH_PATCH_MACRO ~tutu_items_to_bgt~
    END
  COPY_EXISTING_REGEXP GLOB  ~^P#*.cre$~ ~override~
    PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN
     LAUNCH_PATCH_MACRO ~tutu_items_to_bgt~
    END
END
results in
Code: [Select]
ERROR locating resource for 'COPY'
Resource [^X#*.cre$] not found in KEY file:
[./chitin.key]
Stopping installation because of error.
Stopping installation because of error.

COPY_EXISTING_REGEXP GLOB ~^.+\.cre$~ ~override~

works, so I must still be doing something wrong...

hold on -


I bet i forgot the wildcard...
« Last Edit: January 03, 2007, 03:11:06 PM by cmorgan »

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: Case sensitive/insensitive 2da patching
« Reply #16 on: January 03, 2007, 03:09:36 PM »
Your regexp is invalid - it should be ^X#.*\.cre  (in particular, it uses dot-asterisk rather than plain asterisk: #* means match zero or more #, #.* means match a # followed by zero or more any character).
Author or Co-Author: WeiDU (http://j.mp/bLtjOn) - Widescreen (http://j.mp/aKAiqG) - Generalized Biffing (http://j.mp/aVgw3U) - Refinements (http://j.mp/bLHoCc) - TB#Tweaks (http://j.mp/ba02Eg) - IWD2Tweaks (http://j.mp/98OFYY) - TB#Characters (http://j.mp/ak8J55) - Traify Tool (http://j.mp/g1Ry9A) - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics (http://j.mp/9UeIwB) - Nalia Mod (http://j.mp/dng9l0) - Nvidia Fix (http://j.mp/aRWjjg)
Code dumps: Detect custom secondary types (http://j.mp/hVzzXG) - Stutter Investigator (http://j.mp/gdtBn8)

If possible, send diffs, translations and other contributions using Git (http://j.mp/aBZFrq).

Offline cmorgan

  • Planewalker
  • *****
  • Posts: 1424
  • Gender: Male
  • Searcher of Bugs
Re: Case sensitive/insensitive 2da patching
« Reply #17 on: January 03, 2007, 05:31:27 PM »
Thank you --- I will give that a shot

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: