Post Reply 
Stuck with basic filters
Jan. 25, 2008, 05:06 PM
Post: #1
Stuck with basic filters
Hi,

I run BFilter on Leopard, managed the install and under Apple/Location there is a (BF) Automatic. Selecting that, BF seems to be working, some ads are blocked. Viewing the source, there is the BF removing comment. All fine with predefined rules I think.

I also found the rules under App-Support/BFilters. For testing I added the following lines to the file common annoyance filter:

[upper]
search = /a/
replace = A
replacement_type = text

without any effect... Banging Head

Do I have to restart/refresh the filters anywhere? Or is there a problem with the regexp, I suppose it to uppercase every "a" to "A"....

Thanks for any help!
Add Thank You Quote this message in a reply
Jan. 25, 2008, 08:06 PM
Post: #2
RE: Stuck with basic filters
Because BFilter on OSX doesn't have a GUI, you have to enable filters manually. This is done by complementing a filter file with another file that has the same name plus the .enabled extension. In that file you can have a list of individual filters to enable (one on a line) or just an asterisk to enable all of them.
To recap:
If you've saved your filter to a file called "My Filter", then you create "My Filter.enabled" in the same directory and put * to it.
Add Thank You Quote this message in a reply
Jan. 25, 2008, 09:51 PM
Post: #3
RE: Stuck with basic filters
Hm....inside the directory filter I have two files now:

test, content:
[upper]
search = /a/
replace = A
replacement_type = text

and test.enabled, content:
*

I expect the search/replace above to substitute every "a" on a page with "A" but nothing happes. Again, commercial is blocked, so BF is still running.
Maybe my search/replace is the problem? Do you have a simple rule you know that it is working?
Add Thank You Quote this message in a reply
Jan. 25, 2008, 11:08 PM
Post: #4
RE: Stuck with basic filters
One more thing. You need to restart BFilter to make it apply new filters.
Open the Terminal application and run this command:
Code:
sudo /Library/StartupItems/BFilter/BFilter restart
Alternatively, you can just reboot your machine.
Add Thank You Quote this message in a reply
Jan. 26, 2008, 02:27 PM
Post: #5
RE: Stuck with basic filters
Great....all working. And I managed to write some simple filters.
The restart messes my terminal with several lines, but in fact, it works:
Quote:Starting BFilter
mkdir: /Library/Caches/net.sourceforge.bfilter: File exists
Unknown-00-16-cb-b6-94-ec:filters markus$ The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
......
Repeated several times


A final question as you seem to be the expert here:
Can I create dependent rules? Something like that:
search="some string"
if some string exists then search for "some other string" at arbitrary (and totally different) position and replace it with xyz
Add Thank You Quote this message in a reply
Jan. 26, 2008, 05:05 PM
Post: #6
RE: Stuck with basic filters
The errors you see are probably Leopard-related. I haven't switched to Leopard yet, so I can't investigate.

As for your question about filter dependencies, yes you can have one filter depend on another as long as they are in the same file. Filter flags (set_flag + if_flag) can be used for that. They are documented here: http://bfilter.sourceforge.net/doc/conte....php#flags
Add Thank You Quote this message in a reply
Jan. 27, 2008, 01:14 PM
Post: #7
RE: Stuck with basic filters
BFilter is great - I've written 5 pages of filters Cool

Do you grant me a final pair of questions?
1.) I need to process the current URL of the page - something like that
search = /<h1>Test</h1>/ <-- find that and at the same time, process the current URL (http://www.test.us)/([0-9]+)
replace = $1/$2

2.) greedy vs. laszy
I would expect .+ to be greedy and .+? to be laszy but somehow, my assumption is wrong. I rewrote the regexp to avoid the laszy expression but I am still interested, why it did not work.
Add Thank You Quote this message in a reply
Jan. 27, 2008, 01:34 PM
Post: #8
RE: Stuck with basic filters
Unfortunatelly you can't reference the current URL from your search / replace expressions. It would not be that hard to implement (at least for javascript replacements), but currently I am focusing on another project, so don't count on me to implement that. If you are good at C++, you are welcome to contribute this feature.

Lazy expressions should be fine. If you provide your expression, I may be able to tell what's wrong with it.
Add Thank You Quote this message in a reply
Jan. 27, 2008, 02:07 PM
Post: #9
RE: Stuck with basic filters
Oh...YOU are the author? Great work!
No, I am not good at C, I probably could write some Hello-World Programs Wink
Sad that there is no URL - I have to fetch an ID and the ID is not within the document - looks like I am stuck....
Add Thank You Quote this message in a reply
Jan. 28, 2008, 10:39 AM
Post: #10
RE: Stuck with basic filters
In your search: does (.*) include line-breaks or not? In the reference link it says:
"Most regex engines have a "dot matches all" or "single line" mode that makes the dot match any single character, including line breaks."

I have something like that:
search=/<body>(.*)(SomeTextToFind)/
replace = <body onload=...>$1$2

(in fact, .*?, laszy)


Edit: it seems, my assumption of RegExp is the main problem ^^
search = /(Test1|Test2|Test3)/
replace = -$1-

works for Test1, but not for Test2...
Add Thank You Quote this message in a reply
Jan. 28, 2008, 02:42 PM
Post: #11
RE: Stuck with basic filters
Quote:In your search: does (.*) include line-breaks or not?
It does.

Quote:I have something like that:
search=/<body>(.*)(SomeTextToFind)/
replace = <body onload=...>$1$2
So, you are saying it works with ".*" but doesn't work with ".*?", right?
I don't see where the problem could be. BTW, a greedy "match anything" is a problematic construct in BFilter because of a limitation in the underlying regex engine. It works but it's greed is undefined.
With your example, if you have more then one copies of SomeTextToFind in your page, your regex may catch any of them. A lazy match doesn't have this problem and will always catch the first one.

Quote:search = /(Test1|Test2|Test3)/
replace = -$1-

works for Test1, but not for Test2...
You keep confusing me. Again I see no reason for it to replace Test1 but not Test2.
Add Thank You Quote this message in a reply
Jan. 29, 2008, 07:20 PM
Post: #12
RE: Stuck with basic filters
I finally found the problem with the "SomeTextExample": inside SomeText there was an "ü" - an this leads to no match. All äöü have to be replaced with .

Regarding the Test1|Test2....my mistake. The page's source looked similar, but I missed one little difference: color: #ff0000 vs. color:#ff0000 - no wonder, Test2 did not match Wink

If you find someone to continue to work on BFilter, kindly lead him or her to include the URL to be used/parsed in the seach regexp.
Add Thank You Quote this message in a reply
Post Reply 


Forum Jump: