473,395 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Global change of naming convention

Hi,
is there any tool to change naming convention in c++ sources?
I mean something, that parses cpp and h files in my project, and it finds,
what variables are there declared. I think, it should have a public
"CALLBACK" function (which would be impemented by me), which would tell the
program, how to rename variables and functions.

It should work like that:

I have sourcecode:

const int GLOBALX=1;

int main()
{
int VAR=2;
};

This program would parse this file, and find, that there are 2 variables:
GLOBALX and VAR. This function to tell, how to change names (created by me)
would look like this:

char * ChangeNameToWhatName(char *OldName,char *Type,bool IsGlobal)
{
char *dup=strdup(OldName); // make a copy
for(int a=0;a<strlen(dup);++a) // make to lower
dup[a]=tolower(dup[a]);
if(IsGlobal) // if global variable, change first letter to uppercase
dup[0]=toupper(dup[0]);
}

and after that, this program should change my sourcecode to:

const int Globalx=1;

int main()
{
int var=2;
};

I know, that sometimes there are variables of the same name dclared in 2 or
more different places, but this program could exclude these variables from
changing, so that exrything would compile after that without problems.

Are there any such parsing programs? I want to change naming convention in
my program, and don't want to do it manually ;)

I don't use many macros, so this program don't have to be "#define - aware".
Sep 1 '06 #1
8 2652

Użytkownik "bim_bom" <ju******@go2.plnapisał w wiadomości
news:ed**********@news.onet.pl...
char * ChangeNameToWhatName(char *OldName,char *Type,bool IsGlobal)
{
char *dup=strdup(OldName); // make a copy
for(int a=0;a<strlen(dup);++a) // make to lower
dup[a]=tolower(dup[a]);
if(IsGlobal) // if global variable, change first letter to uppercase
dup[0]=toupper(dup[0]);
}
Of course it should end like that: "return dup;"
Sep 1 '06 #2
bim_bom schrieb:
Hi,
is there any tool to change naming convention in c++ sources?
I mean something, that parses cpp and h files in my project, and it finds,
what variables are there declared. I think, it should have a public
If all your variables are VARIABLES and all your functions are
FunctionsDoingSomething() those should be recognizable patterns. Any
good text editor or a simple sed script would do that. Google for
"regular expressions".

Sep 1 '06 #3

Uzytkownik "F.J.K." <fe***********@gmail.comnapisal w wiadomosci
news:11*********************@m73g2000cwd.googlegro ups.com...
bim_bom schrieb:
>Hi,
is there any tool to change naming convention in c++ sources?
I mean something, that parses cpp and h files in my project, and it
finds,
what variables are there declared. I think, it should have a public

If all your variables are VARIABLES and all your functions are
FunctionsDoingSomething() those should be recognizable patterns. Any
good text editor or a simple sed script would do that. Google for
"regular expressions".
Is it that simple? I think, that finding declarations is quite easy, but I
wanted to make my naming convention based on more things - if this is const,
or if this is a pointer, or if this variable is a member of function, of
class, or is it global. I would not be able to write it in "regular
expressions" - this is not a language for me ;) If nobody helps me, I think
I will write this "parser" by myself.
Sep 1 '06 #4
bim_bom wrote:
If all your variables are VARIABLES and all your functions are
FunctionsDoingSomething() those should be recognizable patterns. Any
good text editor or a simple sed script would do that. Google for
"regular expressions".

Is it that simple?
Yes it is
I think, that finding declarations is quite easy, but I
No it isn't, at least not in the general case.
wanted to make my naming convention based on more things - if this is const,
or if this is a pointer, or if this variable is a member of function, of
class, or is it global.
Are you trying to create reasons why you can't just do it now? In that
case the following recipee should quell all that efforts ;-)
a) find all tokens to change with ctags -x
b) use the output to get valid substitution rules for sed or a text
editor.
c) apply the substitution rules
Automate this as much as you (want/need/it makes you finish faster) by
scripting. (Tcl/TK/bash/python/perl..., whatever turns you on).
I would not be able to write it in "regular
expressions" - this is not a language for me ;)
"Those who don't understand regular expressions are doomed to reinvent
them - poorly."
If nobody helps me, I think
I will write this "parser" by myself.
Have fun!

What you describe is a C++ syntax parser and will need the efforts of
at least several months. Oh, btw, I think the whole project is
pointless to start with. Use the new convention for new code and let
the old code rot in peace.

Anyway, not really a C++ issue, rather an issue of bad time management
;-(

FJK

Sep 1 '06 #5
F.J.K. wrote:
What you describe is a C++ syntax parser and will need the efforts of
at least several months. Oh, btw, I think the whole project is
pointless to start with. Use the new convention for new code and let
the old code rot in peace.
There are C++ parsers already, naturally, that could be used to build
something on top of that with this functionality.

It is not unconceivable that such a tool exists, and it would certainly
be useful, so I think the question is valid an interesting. I don't
think there is such a tool though.

Jens
Sep 1 '06 #6
Użytkownik "bim_bom" <ju******@go2.plnapisał w wiadomości
news:ed**********@news.onet.pl...

I found a tool which does many thing, including "changing naming
convention", but it costs 1000USD ;)
Sep 2 '06 #7
Jens Theisen wrote:
It is not unconceivable that such a tool exists, and it would certainly
be useful, so I think the question is valid an interesting. I don't
think there is such a tool though.
A tool would only be useful, if changing naming conventions was. And it
is not, in 99.9% of all cases ;-) See
http://www.parashift.com/c++-faq-lit...html#faq-27.12

But go ahead, everybody is entitled to waste his time the way he likes
it best ;-)

Sep 5 '06 #8

Uzytkownik "F.J.K." <fe***********@gmail.comnapisal w wiadomosci
news:11**********************@b28g2000cwb.googlegr oups.com...
Jens Theisen wrote:
>It is not unconceivable that such a tool exists, and it would certainly
be useful, so I think the question is valid an interesting. I don't
think there is such a tool though.

A tool would only be useful, if changing naming conventions was. And it
is not, in 99.9% of all cases ;-) See
http://www.parashift.com/c++-faq-lit...html#faq-27.12

But go ahead, everybody is entitled to waste his time the way he likes
it best ;-)
I know that changing everything manually would be very long, but if it would
be done automantically, it would henp very much. In my programs all
functions, methods, macros, and variables are in the same naming convention
and changint it automatically would make my code look better and simpier to
read
Sep 5 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Derek | last post by:
The company where I work uses a naming convention that I have never used before. They use mixed-case letters for public member functions, but lower-case with underscores for the rest, like this:...
4
by: Mark Broadbent | last post by:
stupid question time again to most of you experts but this is something that continually bothers me. I am trying to get into the habit of naming variables and controls in an assembly as per...
14
by: 42 | last post by:
Hi, Stupid question: I keep bumping into the desire to create classes and properties with the same name and the current favored naming conventions aren't automatically differentiating them......
3
by: Sam | last post by:
Hi all What's standard naming convention for module and global variables in .net? Do we still use lower case prefix "m" for module (or class) scope and "g" for global scope? Regards, Sam
6
by: rlrcstr | last post by:
The DBA team at the office controls the naming conventions for the database structure, but their naming convention are rather tedious. So typically I create a global module that I use as a mapping...
6
by: dm1608 | last post by:
I'm relatively new to ASP.NET 2.0 and am struggling with trying to find the best naming convention for the BAL and DAL objects within my database. Does anyone have any recommendations or best...
114
by: Jonathan Wood | last post by:
I was just wondering what naming convention most of you use for class variables. Underscore, "m_" prefix, camel case, capitalized, etc? Has one style emerged as the most popular? Thanks for...
35
by: Smithers | last post by:
Is it common practise to begin the name of form classes with "frm" (e.g., frmOneForm, frmAnotherForm). Or is that generally considered an outdated convention? If not "frm" what is a common or...
23
by: Thorsten Kampe | last post by:
Okay, I hear you saying 'not another naming conventions thread'. I've read through Google and the 'naming conventions' threads were rather *spelling conventions* threads. I'm not interested...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.