Archive: problems with textfunc/wordfunc headers and cr-lf :(


problems with textfunc/wordfunc headers and cr-lf :(
got the following problem:
with textfunc i'm reading a textfile line by line with an LineRead loop.

...
loop:
IntOp $R0 $R0 + 1
${LineRead} "$R9\$R2" $R0 $R3
IfErrors end
...

every line is searched by WordFind for the third word, delimiter is space (" ").
${WordFind} $R3 " " "+3" $R4

now, when the third word is the last one in this line (most common case), it includes the following carriage return and line feed.
the WordReplace macro failes, this doesn't work:
"${WordReplace} $1 "$\r" "" "+" $1

is there a way to fix this?

ps: the posted codes are just some lines out of many. hope, it will help you with helping me :)

pps: the whole thing is inside the callback function of a ${Locate} macro (FileFunc header), but this should not cause the problem

1. Attach script.
2. Use LineFind instead of LineRead if you need to read more then 1 line (faster).
3. ${WordReplace}: Give an example string (like "123abc$\r$\npoiuy321$\r$\n")


Replace this line:


"${WordReplace} $1 "$\r" "" "+" $1
with:
${WordReplace} $1 "$\r" "" "+" $1
:)

1. Attach script.
the most interesting parts are already posted, maybe i'll upload it later with example files.
2. Use LineFind instead of LineRead if you need to read more then 1 line (faster).
this is bad, as it always want's to write to a file. so i'll have to delete the new one or it will scrap the old one.
3. ${WordReplace}: Give an example string (like "123abc$\r$\npoiuy321$\r$\n")
here is, what it looks like:
"abc def ghi$\r$\n"


to your last post: just a typo in the post not in my real script.

ok, here's the script source with example files attached. copy anything to one folder and compile the script, then run it.
the only output of the script is the WriteINIStr line (to $EXEDIR\test.lst).

ps: the Objects folder is from the game Battlefield 1942. don't wonder about the sense of this script, it's related to game modding.


I don't see any problem. If I correctly understand you missed:

        ${WordReplace} $geometryTemplateFile "$\r" "" "+" $geometryTemplateFile
${WordReplace} $geometryTemplateFile "$\n" "" "+" $geometryTemplateFile
But easy to use ${TrimNewLines} in TextFunc.nsh

this is bad, as it always want's to write to a file. so i'll have to delete the new one or it will scrap the old one.
Thanks, I will try to make LineFind also only read.

I don't see any problem. If I correctly understand you missed:
${WordReplace} $geometryTemplateFile "$\r" "" "+" $geometryTemplateFile
${WordReplace} $geometryTemplateFile "$\n" "" "+" $geometryTemplateFile
this is, what did not work :(

But easy to use ${TrimNewLines} in TextFunc.nsh
thanks, will try this one.

Thanks, I will try to make LineFind also only read.
this would indeed be very nice, but be sure to make it optional! i have another tool where i need it to edit a config file.
also, as the tool i'm working on doesn't need to be run very often, the speed difference between lineread and linefind doesn't matter.

TrimNewLines works great, thanks!


P.S. ${WordReplace} work fine :):

        geo_end:

${WordReplace} $objectTemplateName "$\r" "" "+" $objectTemplateName
${WordReplace} $objectTemplateName "$\n" "" "+" $objectTemplateName

;This lines you missed:
${WordReplace} $geometryTemplateFile "$\r" "" "+" $geometryTemplateFile
${WordReplace} $geometryTemplateFile "$\n" "" "+" $geometryTemplateFile

yes, but as i don't need wordReplace for other things, usage of TrimNewLines makes teh exe head smaller and works. :)