You are not logged in.

#1 2005-09-01 22:42:07

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

managing big messy complex code

So, I'm planning on doing some conversion of about 800K (compressed) of C source to C++.  It's already in a nice C-OO style of coding.  That is:

struct xyz { ... };
void xyz_move(struct xyz* pxyz, ...other args...)
void xyz_add(struct xyz* pxyz, ...other args...)

Yet it's also written K&R style which died in the 80s...

void
xyz_something(pxyz, a, b, c, d)
   struct xyz *pxyz,
   int a, b
   char *c
   int d
{
...body here
}

So the conversion isn't that hard.  The problem is that it's totally and wickedly unorganized... i.e. one file has 3 C "classes" listed, as well as the prototypes for 2 of the function sets.  The other function set is in a different header, and all 3 are in their own implementation files, along with other random functions prototyped in a totally different header.

Short story: it's a mess.  I'd like to convert it to a nice 1-to-1 header/implementation relationship, but there's alot of code.  I'm wondering if anyone knows of any tools (or even simple refactoring techniques) to aid me.  I can do it manually, it will just take me a long time.

Note: during this conversion I will not be switching the stuff over to C++ types (i.e. std::list<xyz*> instead of struct xyz**).  That will be done later, so in all honesty I only need C refactoring tools....

Offline

#2 2005-09-02 12:55:46

cmp
Member
Registered: 2005-01-03
Posts: 350

Re: managing big messy complex code

if it's only about creating header files, you could maybe write your own tool.
just collect all structs and search for something like struct_[w_]+([^)*]).

Offline

#3 2005-09-02 15:03:40

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: managing big messy complex code

Hmmm, yeah I guess I could collect code and things, but what I'd like to do, is take a struct, along with related prototypes into one header file, and cram the implementations on the function in a related file.  Bascially I'm trying to save myself a few days of random... "ok this is a XYZ function, copy, paste in xyh.c and xyz.h, delete from original"

There should be refactoring tools out there to do something similar... maybe I'll check the vim scripts...

Offline

#4 2005-09-04 03:44:23

kpiche
Forum Fellow
From: Ottawa, ON, Canada
Registered: 2004-03-30
Posts: 246
Website

Re: managing big messy complex code

Some tools I've heard of are cproto, protoize, and c2dep.

Offline

Board footer

Powered by FluxBB