coding convention conversion

Stephen D Evans stevee at recombinant.demon.co.uk
Sat Dec 23 16:30:22 EST 2000


Issac

There is a utility by the name of fixcid.py with the python distribution in the
Tools\scripts directory that does 'massive identifier substitution on C source
files'. It looks like it will work on C++ too. You'd probably have to get the
(unmangled) function names from the linker.

Stephen D Evans


Issac Trotts wrote:

> OK, that should do the trick for python.  Any ideas about how to
> do it for C++ (using python, so that this isn't off-topic ;).
>
> Issac
>
> On Sat, Dec 23, 2000 at 04:29:08AM +0000, Bruce Dodson wrote:
> > Better yet, import the file as a module, and scan through its public symbols
> > (via dir()) to find out which names need to be changed, and then use that
> > information to build a sed script which can be applied globally.  You can
> > easily take advantage of other meta-information such as the type, e.g. limit
> > it to just functions if you want.  This approach is good because the parser
> > will recognize more variations than a regexp.
> >
> >
> > Something like this is what I had in mind:
> >
> > from types import ModuleType, ClassType
> >
> > def print_symbols(symbols, prefix=''):
> >     for sym in dir(symbols):
> >         if sym[:2] == '__': continue
> >
> >         v = getattr(symbols, sym)
> >         if type(v) is ModuleType: continue
> >
> >         print prefix + sym
> >
> >         if type(v) is ClassType:
> >             print_symbols(v, prefix + sym + '.')
> >
> >
> > See also the pyclbr module for a way to do something similar without
> > executing the module.
> >
> > Bruce
> >
> >
> >
> > "D-Man" <dsh8290 at rit.edu> wrote in message
> > news:mailman.977522226.5104.python-list at python.org...
> > >
> > > This shouldn't be too hard with a python script and some regexes with
> > > some more string processing in between (or maybe multiple pass).
> > >
> > > Everything you want to change is bounded by "def" on one side and "("
> > > on the other.  Then replace the capitals with _ followed by the lower
> > > case version.
> > >
> > > A quick (partial) solution:
> > >
> > > re = re.compile( "def ([a-z]+)([A-Z])([a-z]*)\(" )
> > >
> > > for line in source.readlines() :
> > > match = re.match( line )
> > > if ( match ) :
> > > res = "def " + re.group( 0 ) + "_" + \
> > > string.lower( re.group( 1 ) + re.group( 2 ) + "("
> > >
> > >
> > > This isn't complete and won't have the arguments in the result (nor
> > > preserve indentation before the "def").
> > >
> > > I think the re.sub() function will do more of what you want it to.
> > >
> > >
> > > HTH,
> > > -D
> > >
> > >
> > > On Fri, Dec 22, 2000 at 12:20:15PM -0800, Issac Trotts wrote:
> > > > Does anyone know of a utility to change between the coding conventions
> > > > of
> > > >
> > > > def fooBarBaz(): pass
> > > >
> > > > and
> > > >
> > > > def foo_bar_baz(): pass
> > > >
> > > > It is a pain to do this by hand.
> > > >
> > > > Thanks,
> > > > Issac
> > >
> >
> > --
> > http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list