Author Topic: BUFFER_LENGTH; ACTION_BASH_FOR and inlined files  (Read 2944 times)

-Turambar90-

  • Guest
BUFFER_LENGTH; ACTION_BASH_FOR and inlined files
« on: February 11, 2011, 07:57:36 AM »
Buffer length appears not to be working: if I've correctly understood the description, the following code should print 4, or perhaps 0:
Code: [Select]
OUTER_INNER_PATCH_SAVE test ~test~ BEGIN
PATCH_PRINT ~%BUFFER_LENGTH%~
END
Instead, the variable was not substituted, and it just printed %BUFFER_LENGTH%. Trying to set a variable to %BUFFER_LENGTH% causes an error: can not convert B_L or %B_L% to an integer. The same happens without the _SAVE and with INNER_PATCHes. Is it a bug or am I using it in the wrong context?

Concerning ACTION_BASH_FOR, I would find it useful if it could also 'see' inlined files, as I think it's a good way to deal with any resource which can't be simply patched or copied from one file to another with just one action.
For example, I was thinking about ACTION_BASH_FOR - (as the sign - is not ambiguous here, and is already used for inlined options), which performs all ACTIONS listed, both for each file really existing on the disk, and for each currently inlined file which matches the same directory-file-regexp as well.
I'd actually also find it useful if the MAKE_BIFF action could be called on inlined files, but, if I've understood correctly, that would be quite difficult, as MAKE_BIFF directly works with the physical files.

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: BUFFER_LENGTH; ACTION_BASH_FOR and inlined files
« Reply #1 on: February 11, 2011, 08:14:34 AM »
BUFFER_LENGTH is a patch expression, not a variable; as such, it won't be recognized inside PATCH_PRINT or work if quoted with %%s (in the same way as PATCH_PRINT ~%x + y%~ wouldn't work). The following would be correct:
SET length = BUFFER_LENGTH // without ~~ or "" or %% around BUFFER_LENGTH
PATCH_PRINT ~%length%~

Regarding ACTION_BASH_FOR - and MAKE_BIFF -, they are possible to code, but there's an issue of code safety here, since you should on principle never have inlined files defined in any actually possible file path (or, even worse, in an existing directory); aside from A_B_F not reading them, you're running the risk of having a physical file and an inlined file with the same name, which leads to undefined results (some commands would read the physical file, other commands the inlined one).
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).

-Turambar90-

  • Guest
Re: BUFFER_LENGTH; ACTION_BASH_FOR and inlined files
« Reply #2 on: February 11, 2011, 08:41:48 AM »
BUFFER_LENGTH is a patch expression, not a variable; as such, it won't be recognized inside PATCH_PRINT or work if quoted with %%s (in the same way as PATCH_PRINT ~%x + y%~ wouldn't work). The following would be correct:
SET length = BUFFER_LENGTH // without ~~ or "" or %% around BUFFER_LENGTH
PATCH_PRINT ~%length%~
I understand, thanks. it works now
Regarding ACTION_BASH_FOR - and MAKE_BIFF -, they are possible to code, but there's an issue of code safety here, since you should on principle never have inlined files defined in any actually possible file path (or, even worse, in an existing directory); aside from A_B_F not reading them, you're running the risk of having a physical file and an inlined file with the same name, which leads to undefined results (some commands would read the physical file, other commands the inlined one).
For how I'd use this command, I'd first move any existing file with the same name to the backup folder, and only afterwards inline the new ones.
Enabling that behaviour only if there's a - after the command would not cause problems unless one is intentionally using that option, in which case he should know what the risks are (and do some appropriate tests)

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: BUFFER_LENGTH; ACTION_BASH_FOR and inlined files
« Reply #3 on: February 11, 2011, 09:54:32 AM »
For how I'd use this command, I'd first move any existing file with the same name to the backup folder, and only afterwards inline the new ones.
Enabling that behaviour only if there's a - after the command would not cause problems unless one is intentionally using that option, in which case he should know what the risks are (and do some appropriate tests)
Mixing and otherwise operating on files in the same component sounds like an unsafe design (even if it currently works, there's a risk that I change an implementation detail and break your mod). Why can't you just leave the physical file there?
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).

-Turambar90-

  • Guest
Re: BUFFER_LENGTH; ACTION_BASH_FOR and inlined files
« Reply #4 on: February 13, 2011, 09:56:05 AM »
Why can't you just leave the physical file there?
I usually prefer having backed up files in the backup folder, and not scattered around the mod folder,  for instance, in the wed folder and so on; I'd also prefer to avoid duplicating all files which will also be biffed (especially as the only files which are usually immediately biffed are wavs, tis, ... , which are all quite heavy).
Anyway, I've changed the code using arrays to memorize the names and new locations.
The only thing is, in order not to have problems with 'strange' names, I've seen there's the command 'QUOTE'. Is it possible to introduce an OUTER_QUOTE or ACTION_QUOTE, in order to avoid calling thousands of OUTER_PATCH ~0~ BEGIN QUOTE ... END? And is it possible to allow the array construct $ to be used in more expressions, such as INNER_PATCH, MAKE_BIFF and so on? For example,
Code: [Select]
MAKE_BIFF ~biff%i%~ BEGIN ~folder~ $array("%i%") END //results in parse error, as well as
OUTER_INNER_PATCH $array("%i%") BEGIN...[code]
[/code]

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: BUFFER_LENGTH; ACTION_BASH_FOR and inlined files
« Reply #5 on: February 13, 2011, 10:26:43 AM »
I usually prefer having backed up files in the backup folder, and not scattered around the mod folder,  for instance, in the wed folder and so on; I'd also prefer to avoid duplicating all files which will also be biffed (especially as the only files which are usually immediately biffed are wavs, tis, ... , which are all quite heavy).
Anyway, I've changed the code using arrays to memorize the names and new locations.
BIFF the files and MOVE them later if you find the thought of leaving them in wed/ rather than backup/ so sickening.

Quote
The only thing is, in order not to have problems with 'strange' names, I've seen there's the command 'QUOTE'. Is it possible to introduce an OUTER_QUOTE or ACTION_QUOTE, in order to avoid calling thousands of OUTER_PATCH ~0~ BEGIN QUOTE ... END? And is it possible to allow the array construct $ to be used in more expressions, such as INNER_PATCH, MAKE_BIFF and so on? For example,
Code: [Select]
MAKE_BIFF ~biff%i%~ BEGIN ~folder~ $array("%i%") END //results in parse error, as well as
OUTER_INNER_PATCH $array("%i%") BEGIN...[code]
[/code]
Sure for all (list the positions where you want array syntax to be enabled - I can't easily enable it globally).
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).

-Turambar90-

  • Guest
Re: BUFFER_LENGTH; ACTION_BASH_FOR and inlined files
« Reply #6 on: February 13, 2011, 11:08:45 AM »
list the positions where you want array syntax to be enabled - I can't easily enable it globally.
I'd say, generally, wherever a string is expected and variable substitution is performed, and where the $ symbol doesn't have a role yet, but I'm not sure that all places I'll list would not create problems; I could also mention places where it does work.
I'd say: WRITE_EVALUATED_ASCII and similar commands
(OUTER_)INNER_PATCH(_SAVE) (both for string and savevar)
ACTION_BASH_FOR; MAKE_BIFF; for the latter, it would work maybe even better (as it would allow to use a string containing an array instead of just an array) to allow any number of EVALUATE_BUFFER to be put before the file regexp, eg
Code: [Select]
MAKE_BIFF ~biff~ BEGIN ~folder~ EVALUATE_BUFFER ~string%array_%arg%%~ ENDCOPY, MOVE, APPEND(_COL), EXTEND_TOP/BOTTOM, QUOTE, SPACES, PRINT, LOG, WARN, SAY, REPLACE(_TEXTUALLY), SET_2DA_ENTRY
EVALUATE_BUFFER

Actually, would it be possible, instead of  just accepting an array instead of a string on each commands, that every time a string is evaluated (because the command automatically does it or because of E_B), after changing everything between %s, the installer also checks if any string preceded by $ and followed by brackets has been inited as an array? For instance, to interpret ~abc$def(g)~ as ~abc[value of argument g of array def]~?

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: BUFFER_LENGTH; ACTION_BASH_FOR and inlined files
« Reply #7 on: February 13, 2011, 03:37:09 PM »
I'd say: WRITE_EVALUATED_ASCII and similar commands
WRITE_ASCIIE already handles arrays; moreover, "and similar commands" means that I have to read the list of commands available and randomly guess which ones people will want to use with arrays.

Quote
to allow any number of EVALUATE_BUFFER to be put before the file regexp
Not testing before posting doesn't do you any favors. EVALUATE_BUFFER EVALUATE_BUFFER ~%array_%arg%%~ works for me (E.G. in WRITE_ASCIIE).

Quote
PRINT
Can't do (ditto for anything that allows @ references).

Quote
Actually, would it be possible, instead of  just accepting an array instead of a string on each commands, that every time a string is evaluated (because the command automatically does it or because of E_B), after changing everything between %s, the installer also checks if any string preceded by $ and followed by brackets has been inited as an array? For instance, to interpret ~abc$def(g)~ as ~abc[value of argument g of array def]~?
No, but you can use the fact that ~abc$def(g)~ = EVALUATE_BUFFER EVALUATE_BUFFER ~abc%def_%g%%~. It looks like poo, but altering how strings work is even worse.
« Last Edit: February 13, 2011, 03:40:09 PM by the bigg »
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 the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: BUFFER_LENGTH; ACTION_BASH_FOR and inlined files
« Reply #8 on: February 13, 2011, 03:53:19 PM »
Sorry, it appears that I'll have to rewrite too much of the parser to make this worth the effort. Add an extra SPRINT to extract your variables from the arrays in the couple of places where you'd need it.
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).

-Turambar90-

  • Guest
Re: BUFFER_LENGTH; ACTION_BASH_FOR and inlined files
« Reply #9 on: February 13, 2011, 04:30:19 PM »
Quote
Sorry, it appears that I'll have to rewrite too much of the parser to make this worth the effort. Add an extra SPRINT to extract your variables from the arrays in the couple of places where you'd need it.
I understand, thanks anyway for checking
Quote
to allow any number of EVALUATE_BUFFER to be put before the file regexp
Not testing before posting doesn't do you any favors. EVALUATE_BUFFER EVALUATE_BUFFER ~%array_%arg%%~ works for me (E.G. in WRITE_ASCIIE).
ops, I meant directory-file-regexp. I tried to use it in ACTION_BASH_FOR ~directory~ EVALUATE_BUFFER ~%array_%arg%%~, but it did not accept EVALUATE_BUFFER to be put there; the same happened with PATCH_BASH_FOR and MAKE_BIFF.

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: BUFFER_LENGTH; ACTION_BASH_FOR and inlined files
« Reply #10 on: February 13, 2011, 05:46:30 PM »
In general, you can put an OUTER_TEXT_SPRINT and then call ACTION_BASH_FOR (or whatever action you're using currently).
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).

 

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)?: