Archive: Advanced :) search in a text file


Advanced :) search in a text file
  Your comments and remarks, please:

Advanced search in text file


Hi WarmAr :)


1) First of all, welcome to the forums :)

2) Then, thanks for your contribution...

Well, there is another search function you could check, written by Afrow UK. It ouputs also the number of times the string has been found in the file, and the number of lines.. but it doesn't make the difference between commented and uncommented lines. Maybe you could "merge" the features...

The function can be found here:

http://nsis.sourceforge.net/archive/...b.php?page=315


3) About the parameter "dummy"

I don't know how in another way to get the necessary order of the stack elements
Well, your 'exch' instructions should look like this:


SearchInFile

Exch$3 ; search mode
Exch 3
Exch$2 ; file handle
Exch 2
Exch$1 ; comments delimiter
Exch
Exch$0 ; search sample

>; ...

Pop $3
Pop $2
Pop $1
Pop $0
FunctionEnd
>

And then if you don't want to change the variables in the function, you just have to change the order of the elements pushed on the stack as follows:


 Push $handle

Push '#'
>Push 'gds_db'
>Push 'no'
Call SearchInFile
Pop$0
>
And "dummy" has disapeared :D


evilO/Olive

Thanks for remarks! I shall bring in changes to function by the end of the next week


Hi again !

Thanks for remarks!
You're more than welcome :)

Just another thought: there is no need to pass the file handle to the function trough the stack, you could open the file in the function itself.. the less parameters, the better :D

evilO/Olive

here is no need to pass the file handle to the function trough the stack, you could open the file in the function itself.. the less parameters, the better
I disagree. If don't push the handle it is necessary to push the filename. Here there are no less parameters :)

Why the handle, instead of filename? Before working with file it is necessary to check up still its existence, to check up an opportunity of it to open. All this does not concern to search in file, we shall take out of context.

Hi WarmAr :)

I disagree. If don't push the handle it is necessary to push the filename. Here there are no less parameters
It's true, I probably wasn't fully awake at the time I wrote the post :D

Why the handle, instead of filename? Before working with file it is necessary to check up still its existence, to check up an opportunity of it to open. All this does not concern to search in file, we shall take out of context.
Well, it depends actually, there are several ways..

- if you want to perform several operation on this file, you can check the file's existence and pass the handle to all the functions that need it. In this case the functions assume the file's handle is correct.

- if you want to perform a single operation on a file, you can pass the filename to the functions that perform the check and open steps.


In the 1st case, there are less open/close operations as the handle is kept from one function call to another. In the 2nd case, the advantage is that the function can be used "on it's own"...

Well, both are good :D


evilO/Olive

evilO, thanks for help in mastering operations with stack!

I have edited function.

In addition to suggested by you changes I have added some more 'Exch' for the purposes of the standard order of the initial registers values in a stack