Archive: Need some advice on slashconverting


Need some advice on slashconverting
Dear Guys -

Can somebody help me on slashconverting? I have to open a file parse it through the slash-converting function (convert backslashes to normal slashes) and close it under the same name!

I found this slash-converter here @ the archive but didn't understood how to get it work...

Thx in advance
Mo


Open the file, read a line, pass it to the function, write the output to another file, repeat until you've read the entire file, close both files and replace the old one with the new one.


So I can use this function? What I don't understood are the comments above:

; Push $filenamestring (e.g. 'c:\this\and\that\filename.htm')
; Push "\"
; Call StrSlash
; Pop $0
; $0 == 'c:/this/and/that/filename.htm'


Mo

It's an example of usage.

Push "line that contains a \"
Push "\" ;Char to convert
Call StrSplash
Pop $R0 ;Or another variable
;Now $R0 will contain the same string with \ converted to /

You will have to use this function for the lines you read from the file.


That file name is just an example of a string conatining backslashes. You should push the line you read from the file instead of that.


Uuuhh,

could please give me an example? I tried some things, but with no luck!


What's wrong with Joost's example?


I don't know the lines which have to be converted. This can vary from and I don't know the exact content to be converted, because these lines (with an $INSTDIR) are set with the installation process, so this depends on the path set by the user...


You're not supposed to push constant strings to that function, you're supposed to push it strings that you read from the file.

If it's $INSTDIR that you're trying to convert, why not preconvert it? Just push $INSTDIR to that function and have your file replacement functions replace your file constants with the converted $INSTDIR instead of the original one.


Because I don't know how!

I have one function for editing the file. This replaces some place holder with an installation path:

Function ModibWebAdmin
ClearErrors
FileOpen $0 "$INSTDIR\test.tmp.php" "r"
GetTempFileName $R0
FileOpen $1 $R0 "w"
loop:
FileRead $0 $2
IfErrors done
StrCmp $2 "@@BINPATH@@$\r$\n" 0 +3
FileWrite $1 "define($\'BINPATH$\', $\'$INSTDIR\DB\FireBird\bin\$\');$\r$\n"
Goto loop
StrCmp $2 "@@TMPPATH@@$\r$\n" 0 +3
FileWrite $1 "define($\'TMPPATH$\', $\'$INSTDIR\DB\FireBird\tmp\$\');$\r$\n"
Goto loop
StrCmp $2 "@@DEFAULTPATH@@$\r$\n" 0 +3
FileWrite $1 "define($\'DEFAULT_PATH$\', $\'$INSTDIR\DB\FireBird\$\');$\r$\n"
Goto loop
FileWrite $1 $2
Goto loop
done:
FileClose $0
FileClose $1
Delete "$INSTDIR\test.tmp.php"
Rename $R0 "$INSTDIR\test.tmp1.php"
FunctionEnd


But these replaced lines show the path with backslashes. Don't know why but these file (php-script) doesn't work with backslashes. So these lines should be converted. I would have prepared the file with '/' instead of '\', but I have no influence on the front part set through $INSTDIR ...

So what was your idea on Push $INSTDIR? How can this be achieved?

Use this:

Push $INSTDIR
Push "\"
Call StrSlash
Pop $0

$0 will contain the string you should use instead of $INSTDIR in the file replacement function.


Okay I think I almost got it kichik :-D

One last question:

Push $INSTDIR
Push "\"
Call StrSlash
Pop $0


Can this be used in a section (at any place), or do I have to make a seperate function out of it which has to be called with
 Call FunctionName


Mo!

It can be used anywhere you want as long as you know $INSTDIR will be set to the right value (after directory selection page) and that $0 will not change until the file replacement function is called.


I can't get it work...
Could somebody review and correct it, pleeaaase

Mo


You are still using $INSTDIR in the Replace function. Use $R0 instead.


YEEEEAAAAAAHHHHHH !!!! :up:

Got it!
Thx Kichik (you rock!) great help!
Mo
:D

P.S.: can the used variables be cleared at the end or do they have no effect on following functions and sections?


As long as you don't call that function again you can clear it. If you're worried you might need it sometime you can use Var to create a special variable just for it (assuming you're using the latest CVS version).


So best/safest would be

 Var NAME_OF_VAR

(in the beginning of the script)
and than call it at the line
Pop $NAME_OF_VAR

Is that right?

Yes, and in the replacement function too. Replace $R0 with $NAME_OF_VAR.


So thx kichik: Your my man! :D