Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
06-23-2005, 11:04 AM
|
#1
|
|
Member
Registered: Mar 2005
Distribution: FC, Gentoo
Posts: 276
Rep:
|
replace empty function from the old format to the new format
I have about 300 files which has the function getDBBackend().
How to write a program to change the empty function from the old format to the new format?
Old empty function format are either:
function getDBBackend()
{
// Not available
} // getDBBackend
or:
function getDBBackend()
{
} // getDBBackend
New empty function format is:
function getDBBackend()
{
// DB backend not applicable, use test backend
getTestObject();
} // getDBBackend
If the function is not empty, then it will not be changed:
function getDBBackend() {
$msg = db_start_dget(MIO_DGET_DATA);
//...
}
|
|
|
|
07-10-2005, 01:02 PM
|
#2
|
|
Senior Member
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524
Rep:
|
I think it's easiest in python
Code:
oldform1 = "function getDBBackend()\n{\n ..."
oldform2 = """function getDBBackend()
{
} // getDBBackend"""
filenames = ["file1", "file2", ]
for fname in filenames:
data = file(fname).read()
data = data.replace(oldform1, newform)
data = data.replace(oldform2, newform)
file(fname, "w").write(data)
with appropriate values of filenames, oldform{1,2} and newform.
hth --Jonas
|
|
|
|
07-10-2005, 02:18 PM
|
#3
|
|
Member
Registered: Oct 2003
Location: Canada
Distribution: Slackware
Posts: 340
Rep:
|
sed
|
|
|
|
07-11-2005, 05:06 PM
|
#4
|
|
Senior Member
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524
Rep:
|
to lowpro2k3:
sed struck me first too--but I can't seem to be able to do it in a fairly simple way (i.e. without stuffing lines into the holding space and doing nasty things with them there).
So if you have a script of about, say, 1-5 lines, please post it
--Jonas
|
|
|
|
07-12-2005, 08:07 PM
|
#5
|
|
Member
Registered: Oct 2003
Location: Canada
Distribution: Slackware
Posts: 340
Rep:
|
Agreed, I know it can be done but I'm far from slick enough to write a pretty one liner. It would be a mess of temp files that would work for me - ugly, but gets the job done 
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 03:51 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|