User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

Reply
Thread Tools Display Modes
Unread 10 Feb 2004, 12:44   #1
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Somebody do me a HUGE favour?

I'm amazingly crap at regexps. Don't know why. I just have this insane mental block when it comes to them.

If you've not read about my PHP upgrade issue, then:

http://pirate.planetarion.com/showthread.php?t=175133

Can somebody do me a HUGE favour (I mean, HUGE) and write me a little bit of code that will search through a string and replace below. The string is actually a .php file. I intend to have this program recurse through all my projects and fix the code!! I really don't want to manually edit about 3 years worth of PHP code!

Code:
if (!$foo)
if (!$foo2)
if (!$foo3)
So it becomes

Code:
if (empty($foo))
if (empty($foo2))
if (empty($foo3))
I've written the code to recurse through dirs, and open the file, etc, but it's the pattern matchin I can't do...

I'm just totally terrible at regexps, and I've just spent 2 hours trying to do it! Also I'm doing in PHP, which is prolly dumb!?

THANKS!!!

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 10 Feb 2004, 13:54   #2
Freedom
Howling Rain
 
Join Date: Jul 2003
Location: England
Posts: 32
Freedom will become famous soon enoughFreedom will become famous soon enough
Re: Somebody do me a HUGE favour?

Why not just open all the files into a good text editor (editpad) and then just set it to find and replace in all files then re-upload the files. Thats what I'd do anyways, but i'm lazy
__________________
To live in Freedom we must dwell in War.
Freedom is offline   Reply With Quote
Unread 10 Feb 2004, 14:13   #3
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Re: Somebody do me a HUGE favour?

Cos it won't work mate.

It'd work if each file was the same, and each var was the same.

But I want to search thru lots of different files, to replace lots of different statements. I need to actually process the files, in order to get the variable name.

Thanks anyway,

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 10 Feb 2004, 14:18   #4
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Re: Somebody do me a HUGE favour?

I've managed this thusfar, which kinda works actually...

Code:
function fixit ($filetofix)
{
	$filename = $filetofix;
	$handle = fopen($filename, "r");
	$content = fread($handle, filesize($filename));
	
	$start = strpos ($content, '!$');
	echo $filename.'<br />';//.substr ($content, $start, 1).'<br />';
	$end = strpos ($content, ' ');
	$tempcontent = substr ($content, $start, $end);
	$var = preg_replace ("/[!$()]/i", "", $tempcontent);
	$var = 'empty($'.$var.')';
	echo $var;
	echo '<hr />';
}
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 10 Feb 2004, 16:55   #5
JetLinus
Friendly geek of GD :-/
 
JetLinus's Avatar
 
Join Date: Nov 2000
Location: On my metal roid
Posts: 923
JetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud of
Arrow Re: Somebody do me a HUGE favour?

Ok, basically you want to replace
Code:
if (!$*)
by
Code:
if (empty($*))
right? (where I used * in the way of dos/win-filename-matching, and assumed * would "store" its content)


Ok, here is my algorithm approach I would use in VB:
  1. Take the next line in queue (if needed, open the next file, until there aren't any left)
  2. In this string, search for "if (!$". Remember position!
  3. Now replace "if (!$" by "if (empty($". I know you cannot really just "replace" it but need to delete the old bit from the string and insert the new bit, as its a tad longer. I'm sure you / PHP will manage somehow.
  4. To the position you remembered (the occurance of the first string), you add the length of the stuff you replaced it with. In this case, that would be Length("if (empty($"), which is 11 if I counted correctly. This "OldPosition + 11" will be your new start for the next start:
  5. Now you search for a ")" (starting from said position). To make the algorithm more bug-proof for complex boolean expressions, better search for the last ")" in that "word" (i.e. until next space) or expression or line (you decide, depends a bit on your writing style).
  6. Insert another ")" just behind it.
  7. Repeat from step 2 until end of this line.
  8. Repeat from step 1 until all lines (files) are processed!


This is all easy to implement using InStr() and Mid$() in Visual Basic. (I'm just saying... Probably could have done the tool by know, but I can't be bothered doing UI and recursive file stuff programming)

Note: If you put 2 or more spaces in between "if" and "(!$foo)" somewhere accidentally, i.e. like "if (!$foo)", this all won't work obviously. You need to parse / replace / remove multiple spaces before then, or adapt the pattern matching.
__________________
[»] Entropy increases! :-/
JetLinus is offline   Reply With Quote
Unread 10 Feb 2004, 16:57   #6
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Re: Somebody do me a HUGE favour?

Hi, it's the * bit that's the problem. I'm using PHP to do this, and I can't get * to store the value.

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 10 Feb 2004, 16:58   #7
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Re: Somebody do me a HUGE favour?

Or I should clarify:

I CAN get * to store the value. So I've actually done the regexp bit. What I CAN'T do is make it work on the whole file, running the operation as it goes.

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 10 Feb 2004, 17:03   #8
JetLinus
Friendly geek of GD :-/
 
JetLinus's Avatar
 
Join Date: Nov 2000
Location: On my metal roid
Posts: 923
JetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud of
Arrow Re: Somebody do me a HUGE favour?

Well, that's why my "algorithm" tries to skip the *-bit.

Anyway... I personally use UltraEdit32, which CAN replace strings in multiple files using regular expressions. But, regexps don't really help you (as you said, it's hard to store the *-bit). At least I can't work it out, as I don't know much about regexps apart what I learned in the last 20min...

Probably Cyp will have a 5-line-Perl or C approach or anything...

Look for a sort of Dos-Tool, that replaces
Code:
if (!$%1)
by
Code:
if (empty($%1))
I know a MP3-Tool that does exactly the same thing from parsing filenames to variables to put them into ID3-Tags... All you need is find a tool that does it with fulltext-file-replacing.


BUT BEWARE!!!! Having said this, what is with complex expressions using multiple ((())) etc? Be carefuly there! Maybe ask for user input if it's not a trivial case. So that you don't get invalid syntax (or, WORSE) wrong boolean expressions that will really bug up your code without you noticing.
__________________
[»] Entropy increases! :-/
JetLinus is offline   Reply With Quote
Unread 10 Feb 2004, 17:07   #9
JetLinus
Friendly geek of GD :-/
 
JetLinus's Avatar
 
Join Date: Nov 2000
Location: On my metal roid
Posts: 923
JetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud of
Re: Somebody do me a HUGE favour?

And how the hell can they change the syntax in PHP so badly???

It must have been a non-recommended "dialect" or "spelling" you used, that eventually fired back now.


Like people in VB using lblMyLabel = "Hello World" instead of lblMyLabel.Caption = "Hello World", and then start moaning around when the defaul property changes from .Caption to something else (which MS would probably never do as said people would moan).

So go and blame PHP, or yourself, or both!

Or me for a change ^^
__________________
[»] Entropy increases! :-/
JetLinus is offline   Reply With Quote
Unread 10 Feb 2004, 17:09   #10
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Re: Somebody do me a HUGE favour?

That's exactly what happened.

Many people simply used if (!$foo) cos then you'd test positive if $foo was false, empty, or not declared. A nice easy way of doing it. But now it returns an error if $foo wasn't declared.

Annoying.

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 10 Feb 2004, 17:09   #11
JetLinus
Friendly geek of GD :-/
 
JetLinus's Avatar
 
Join Date: Nov 2000
Location: On my metal roid
Posts: 923
JetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud of
Arrow Re: Somebody do me a HUGE favour?

Quote:
Originally Posted by Mong
Or I should clarify:

I CAN get * to store the value. So I've actually done the regexp bit. What I CAN'T do is make it work on the whole file, running the operation as it goes.

M.
Oh

Probably misunderstood you. So, hmm... Where exactly doesn't it work?
Split your string to lines, and process each line on its own.
Do each line over and over until there is no match anymore.
Or count how many ifs you got in that line and only do it that often.


The possibilities are endless.



Well, not endless, but not limited to one at least
__________________
[»] Entropy increases! :-/
JetLinus is offline   Reply With Quote
Unread 10 Feb 2004, 17:10   #12
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Re: Somebody do me a HUGE favour?

Oh and I use Ultraedit too, it's nice isn't it?
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 10 Feb 2004, 17:14   #13
JetLinus
Friendly geek of GD :-/
 
JetLinus's Avatar
 
Join Date: Nov 2000
Location: On my metal roid
Posts: 923
JetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud of
Arrow Re: Somebody do me a HUGE favour?

Quote:
Originally Posted by Mong
Many people simply used if (!$foo) cos then you'd test positive if $foo was false, empty, or not declared. A nice easy way of doing it. But now it returns an error if $foo wasn't declared.
Because you're sort of "really using" the undeclared $foo in an expression, but checking with "empty()" doesn't really count as declare? I see...


So why don't you go and declare all your variables? That would reduce evilness as well ^^


Or go and try to implement the "algorithm" I suggested and then be mad at me coz it only works 99% :eek:
__________________
[»] Entropy increases! :-/
JetLinus is offline   Reply With Quote
Unread 10 Feb 2004, 17:18   #14
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Re: Somebody do me a HUGE favour?

Quote:
Originally Posted by JetLinus
So why don't you go and declare all your variables? That would reduce evilness as well ^^
Ah but in PHP, you don't declare variables :-)

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 10 Feb 2004, 17:24   #15
JetLinus
Friendly geek of GD :-/
 
JetLinus's Avatar
 
Join Date: Nov 2000
Location: On my metal roid
Posts: 923
JetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud of
Arrow Re: Somebody do me a HUGE favour?

But somebody somewhere recently mentioned "so I wouldn't get informed if I misspelled a variable elsewhere". How in the world would a compiler decide if a variable was misspelled, if it never got declared?


And HOW can there be a "high-level-language" without forcing you to define your vars?

ouh ouh ouh what a world
__________________
[»] Entropy increases! :-/
JetLinus is offline   Reply With Quote
Unread 10 Feb 2004, 17:37   #16
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Re: Somebody do me a HUGE favour?

Quote:
Originally Posted by JetLinus
How in the world would a compiler decide if a variable was misspelled, if it never got declared?
EXACTLY!!!!!!!x10^10000
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 10 Feb 2004, 17:51   #17
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Re: Somebody do me a HUGE favour?

I made it, weeeee....

http://paul.m5i.net/dev/RecurseAndChange.txt

Only does the simple if (!$foo) and not nested/multiple. But still... weeeee....

Gonna test it massively first tho!

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 10 Feb 2004, 20:39   #18
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
Re: Somebody do me a HUGE favour?

From the top of my head:

$pattern = "#\(\!\$([a-zA-Z0-9]+)\)#si"; //match on pattern "(!$ <alphanumeric+> )"
$replace= "(empty($\\1))";

$text = preg_replace($pattern,$replace,$text);

Where $text is the whole file in one string.
I'd be surprised if it works because I'm not too sure if it matches on the '!' and '$' characters.
__________________
"Yay"

Last edited by Structural Integrity; 10 Feb 2004 at 21:26.
Structural Integrity is offline   Reply With Quote
Unread 10 Feb 2004, 21:05   #19
Intrepid00
Registered User
 
Join Date: Aug 2000
Posts: 1,967
Intrepid00 is an unknown quantity at this point
Re: Somebody do me a HUGE favour?

Quote:
Originally Posted by Mong
I'm amazingly crap at regexps. Don't know why. I just have this insane mental block when it comes to them.

If you've not read about my PHP upgrade issue, then:

http://pirate.planetarion.com/showthread.php?t=175133

Can somebody do me a HUGE favour (I mean, HUGE) and write me a little bit of code that will search through a string and replace below. The string is actually a .php file. I intend to have this program recurse through all my projects and fix the code!! I really don't want to manually edit about 3 years worth of PHP code!

Code:
if (!$foo)
if (!$foo2)
if (!$foo3)
So it becomes

Code:
if (empty($foo))
if (empty($foo2))
if (empty($foo3))
I've written the code to recurse through dirs, and open the file, etc, but it's the pattern matchin I can't do...

I'm just totally terrible at regexps, and I've just spent 2 hours trying to do it! Also I'm doing in PHP, which is prolly dumb!?

THANKS!!!

M.
Open Project > Edit > Find and Replace > Replace Files

Opps, I am sorry. I thought you using the '1337' VS .NET 2003

(Not really, I just want to taunt you how easy it is in VS)
Intrepid00 is offline   Reply With Quote
Unread 10 Feb 2004, 22:13   #20
pablissimo
Henry Kelly
 
pablissimo's Avatar
 
Join Date: Apr 2000
Posts: 7,374
pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: Somebody do me a HUGE favour?

VS .NET <3 <3 <3
__________________
You're now playing ketchup
pablissimo is offline   Reply With Quote
Unread 10 Feb 2004, 22:59   #21
Dante Hicks
Clerk
 
Join Date: Jun 2001
Posts: 13,940
Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: Somebody do me a HUGE favour?

Some text editors allow you to use Regular Expressions in their Search / Replace functions, although I'm not exactly sure how
Dante Hicks is offline   Reply With Quote
Unread 10 Feb 2004, 23:34   #22
pablissimo
Henry Kelly
 
pablissimo's Avatar
 
Join Date: Apr 2000
Posts: 7,374
pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: Somebody do me a HUGE favour?

Textpad does, iirc it involves tagging the pieces of what's matched that you want to replace but the specifics are lost on me. Help file gives some level of guidance though.
__________________
You're now playing ketchup
pablissimo is offline   Reply With Quote
Unread 10 Feb 2004, 23:49   #23
meglamaniac
Born Sinful
 
meglamaniac's Avatar
 
Join Date: Nov 2000
Location: Loughborough, UK
Posts: 4,059
meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: Somebody do me a HUGE favour?

Pab beat me to it
FYI, here is the Textpad replace dialog.

IMO, Textpad is one of the best all-round editors for windows available, especially with custom plugins and addons. For example, I have a custom PHP4/HTML syntax def which allows it to highlight the PHP in PHP files as PHP, and the HTML in PHP files (ie. things between ?> <?php) as HTML.
Result: life is a lot easier.

It can do a multitude of other things.
For example, I also have it set up to give correct syntax highlighting of Java files, and hotkeys which will run the java compiler on the current file, and another to run the current file when it's compiled.

Funky monkey.
__________________
Worth dying for. Worth killing for. Worth going to hell for. Amen.
meglamaniac is offline   Reply With Quote
Unread 10 Feb 2004, 23:53   #24
Intrepid00
Registered User
 
Join Date: Aug 2000
Posts: 1,967
Intrepid00 is an unknown quantity at this point
Re: Somebody do me a HUGE favour?

Quote:
Originally Posted by meglamaniac
Pab beat me to it
FYI, here is the Textpad replace dialog.

IMO, Textpad is one of the best all-round editors for windows available, especially with custom plugins and addons. For example, I have a custom PHP4/HTML syntax def which allows it to highlight the PHP in PHP files as PHP, and the HTML in PHP files (ie. things between ?> <?php) as HTML.
Result: life is a lot easier.

It can do a multitude of other things.
For example, I also have it set up to give correct syntax highlighting of Java files, and hotkeys which will run the java compiler on the current file, and another to run the current file when it's compiled.

Funky monkey.
Well, techinically. Visual Studio is a glorfied notepad (The coding part)
Intrepid00 is offline   Reply With Quote
Unread 11 Feb 2004, 02:19   #25
JetLinus
Friendly geek of GD :-/
 
JetLinus's Avatar
 
Join Date: Nov 2000
Location: On my metal roid
Posts: 923
JetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud of
Arrow Re: Somebody do me a HUGE favour?

Quote:
Originally Posted by JetLinus
Anyway... I personally use UltraEdit32, which CAN replace strings in multiple files using regular expressions.
Quote:
Originally Posted by Mong
Oh and I use Ultraedit too, it's nice isn't it?
Quote:
Originally Posted by Dante Hicks
Some text editors allow you to use Regular Expressions in their Search / Replace functions, although I'm not exactly sure how
Quote:
Originally Posted by pablissimo
Textpad does, iirc it involves tagging the pieces of what's matched that you want to replace but the specifics are lost on me. Help file gives some level of guidance though.
__________________
[»] Entropy increases! :-/
JetLinus is offline   Reply With Quote
Unread 11 Feb 2004, 03:24   #26
NEWSBOT3
NEWSBOT
 
Join Date: Dec 2000
Location: The enby cave!
Posts: 4,872
NEWSBOT3 needs a job and a girlfriendNEWSBOT3 needs a job and a girlfriendNEWSBOT3 needs a job and a girlfriendNEWSBOT3 needs a job and a girlfriendNEWSBOT3 needs a job and a girlfriendNEWSBOT3 needs a job and a girlfriendNEWSBOT3 needs a job and a girlfriendNEWSBOT3 needs a job and a girlfriendNEWSBOT3 needs a job and a girlfriendNEWSBOT3 needs a job and a girlfriendNEWSBOT3 needs a job and a girlfriend
Re: Somebody do me a HUGE favour?

ultraedit32 is very nice.

glad to se im not the only one using it.
__________________
[20:27:47] <nodrog-aawy> **** i think my housemate just caught me masturbating
[11:25:32] <idimmu> you are a little piggy arent you
[13:17:00] <KaneED> i'm so closet i'm like narnia
__________________
Pretty parks and funky scrap metal things here
NEWSBOT3 is offline   Reply With Quote
Unread 11 Feb 2004, 11:35   #27
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Re: Somebody do me a HUGE favour?

But none of the text editors will allow you to change it properly. They don't store the variable.

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 11 Feb 2004, 12:06   #28
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Re: Somebody do me a HUGE favour?

Quote:
Originally Posted by NEWSBOT3
ultraedit32 is very nice.

glad to se im not the only one using it.
I love it. I can't get Ctags to work though.

I have the PHP4 autocomplete for UE tho, that's lovely.

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 11 Feb 2004, 13:15   #29
pablissimo
Henry Kelly
 
pablissimo's Avatar
 
Join Date: Apr 2000
Posts: 7,374
pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: Somebody do me a HUGE favour?

Quote:
Originally Posted by Mong
But none of the text editors will allow you to change it properly. They don't store the variable.

M.
Erm...

You use \1, \2... \9 in the Replace box of Textpad and it inserts the nth group in the matched string into its place.

So for what you want something like

Find:
if\x20?(!\$\(.*\))

Replace with
if\x20(empty(\$\1))

Now, I'm shit with regex's but it seems to work for ones of the form if (!$foo) and elseif(!$foo) but it won't match ones with spaces inside the brackets. Shouldn't be much trouble to sort that out with a couple of \x20?'s though.

Edit:
Change the 'Find' regex to something like
if\x20?(\x20?!\$\([a-zA-Z0-9_]*\)\x20?)

and it'll match if(!$foo) and if( !$foo ) which is the way I code.
__________________
You're now playing ketchup

Last edited by pablissimo; 11 Feb 2004 at 13:32.
pablissimo is offline   Reply With Quote
Unread 11 Feb 2004, 15:21   #30
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Re: Somebody do me a HUGE favour?

I made the following, which can be run recurssively. They must be done in order.

Thanks to those who pointed out that Ultraedit can do replacement ranges!!!

___________________________________________________________________
FIRST:
Finds:
- if (!foo)
- if (!arr['foo'])
- if (!arr[1])

SEARCH: if \(!\$([a-zA-Z0-9\[\]\']*)\)
REPLACE: if \(empty\(\$\1\)
-------------------------------------------------------------------

___________________________________________________________________
SECOND:
Finds:
- if ((!$foo) and (!$arr['foo'])) etc...

SEARCH: \(!\$([a-zA-Z0-9\[\]\']*)\)
REPLACE: empty \(\$\1\)
-------------------------------------------------------------------
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 15 Feb 2004, 21:38   #31
Epcylon
Registered User
 
Join Date: Apr 2000
Location: Oslo, Norway
Posts: 78
Epcylon is a glorious beacon of lightEpcylon is a glorious beacon of lightEpcylon is a glorious beacon of lightEpcylon is a glorious beacon of lightEpcylon is a glorious beacon of light
Re: Somebody do me a HUGE favour?

I see you have sorted it out (or close to it anyway), but I whipped this up in 5 mins, so figured I might as well post it..

No testing what-so-ever, so could break horribly, but I think it should work right..

Word of warning though.. it processes inplace (kinda), so if I should have made a blunder on the regex, it would destroy the original... might be a good idea to test on a single file first..

Just run from commandline, listing all the files you want to process as parameters to the prog. Just remember that you need atleast python 2, possibly even 2.2... don't remember atm..

Code:
#!/usr/bin/env python

import re

search_string = r"if\s*\(\s*(\w+)\s*\)"
replace_string = r"if(empty(\1))"
replacer = re.compile(search_string)

def do_file(filename):
    # Read the entire file into a string
    file = "".join(open(filename,"r").readlines())
    # Replace
    newfile = replacer.sub(replace_string,file)
    # Write it all out again
    f = open(filename,"w")
    f.write(newfile)
    f.close()

if __name__ == "__main__":
    import sys
    for file in sys.argv[1:]:
        do_file(file)
__________________
Epcylon
[R1]: noob | [R2]: B8S/ICD | [R3-5]: ICD | [R6]: HR | [R7-9.5]: HR/NoS |
[R10]: HR RecOff | [R10.5]: HR RO -> HR HC -> HR pe0n | [R11]: HR pe0n -> Leave of Absence |
[R12]: HR free-pe0n | [R13-]: HR pe0n
Epcylon is offline   Reply With Quote
Unread 16 Feb 2004, 10:20   #32
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Re: Somebody do me a HUGE favour?

Quote:
Originally Posted by Epcylon
No testing what-so-ever, so could break horribly, but I think it should work right..

Word of warning though.. it processes inplace (kinda), so if I should have made a blunder on the regex, it would destroy the original... might be a good idea to test on a single file first..
P&D at its best!!!
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 16 Feb 2004, 13:44   #33
MT
/dev/zero
Retired Mod
 
MT's Avatar
 
Join Date: May 2000
Posts: 415
MT is an unknown quantity at this point
Re: Somebody do me a HUGE favour?

erm
Code:
find . -name '*.php' | xargs perl -i -pae 's/if\s*\(!\$([^)]+)\)/if (empty(\$$1))/'
__________________
#linux : Home of Genius

<idimmu> ok i was chained to a desk with this oriental dude
MT is offline   Reply With Quote
Reply



Forum Jump


All times are GMT +1. The time now is 20:07.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018