9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] c code differencing
@ 2011-08-31 13:01 Steve Simon
  2011-08-31 14:01 ` Rodolfo kix Garcia
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Steve Simon @ 2011-08-31 13:01 UTC (permalink / raw)
  To: 9fans

Anyone have any pointers to a diff for C code.

I have two libraries, A and B.

B is and expanded and modified version of A and I have been
asked to extract A from B to build two libraries one
built on top of the other.

What I think I need is a program which parses C and will
do diffs at the level of functions, globals , #defines and enums.

it would ideally have two input files and generate two outputs
one output being the common code, one with the extensions on the common.

I don't expect this to be fully automated, there is going to be a load
of hand edition before I am done, but is there somthing which can do
the easy stuff for me?

-Steve



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] c code differencing
  2011-08-31 13:01 [9fans] c code differencing Steve Simon
@ 2011-08-31 14:01 ` Rodolfo kix Garcia
  2011-09-01 13:16 ` Ethan Grammatikidis
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Rodolfo kix Garcia @ 2011-08-31 14:01 UTC (permalink / raw)
  To: 9fans

On Wed, 31 Aug 2011 14:01:34 +0100, Steve Simon wrote:
> Anyone have any pointers to a diff for C code.
>
> I have two libraries, A and B.
>
> B is and expanded and modified version of A and I have been
> asked to extract A from B to build two libraries one
> built on top of the other.
>
> What I think I need is a program which parses C and will
> do diffs at the level of functions, globals , #defines and enums.
>
> it would ideally have two input files and generate two outputs
> one output being the common code, one with the extensions on the
> common.
>
> I don't expect this to be fully automated, there is going to be a
> load
> of hand edition before I am done, but is there somthing which can do
> the easy stuff for me?
>
> -Steve

Why don't use a C preprocessor to do that?
You can have one file with ifdefs, and print the two files using an
argument

Example:

#ifdef LIBA
#include <windows.h>
#else
#include <unistd.h>
#endif

and run

"cpp -DLIBA ..." and
"cpp -ULIBA ..." or "cpp ..."


--
||// //\\// Rodolfo "kix" Garcia
||\\// //\\ http://www.kix.es/



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] c code differencing
  2011-08-31 13:01 [9fans] c code differencing Steve Simon
  2011-08-31 14:01 ` Rodolfo kix Garcia
@ 2011-09-01 13:16 ` Ethan Grammatikidis
  2011-09-01 14:33 ` FENG Yu Ning
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Ethan Grammatikidis @ 2011-09-01 13:16 UTC (permalink / raw)
  To: 9fans

On Wed, 31 Aug 2011 14:01:34 +0100
"Steve Simon" <steve@quintile.net> wrote:

> What I think I need is a program which parses C and will
> do diffs at the level of functions, globals , #defines and enums.

This won't work at the level of functions but I've found diff -c output
to be nice to use with acme. It assumes no spaces in filenames, :)
I don't suppose everyone has Erik's rc patch yet.

!#/bin/rc

fn cd

flist = `{@{cd B && du -a | awk '{print $2}'}}

for(f in $flist) {
	if(test -e A/$f) {
		diff -c A/$f B/$f
	}
	if not {
		echo B/$f':	new file'
	}
	echo
}



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] c code differencing
  2011-08-31 13:01 [9fans] c code differencing Steve Simon
  2011-08-31 14:01 ` Rodolfo kix Garcia
  2011-09-01 13:16 ` Ethan Grammatikidis
@ 2011-09-01 14:33 ` FENG Yu Ning
  2011-09-01 14:51 ` Anthony Sorace
  2011-09-03 12:17 ` Comeau At9Fans
  4 siblings, 0 replies; 7+ messages in thread
From: FENG Yu Ning @ 2011-09-01 14:33 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Steve Simon
> What I think I need is a program which parses C and will
> do diffs at the level of functions, globals , #defines and enums.

Code Token Comparator
http://minnie.tuhs.org/Programs/Ctcompare/index.html

Not a close match, but should be a little better than diff.

yn



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] c code differencing
  2011-08-31 13:01 [9fans] c code differencing Steve Simon
                   ` (2 preceding siblings ...)
  2011-09-01 14:33 ` FENG Yu Ning
@ 2011-09-01 14:51 ` Anthony Sorace
  2011-09-01 14:59   ` Anthony Sorace
  2011-09-03 12:17 ` Comeau At9Fans
  4 siblings, 1 reply; 7+ messages in thread
From: Anthony Sorace @ 2011-09-01 14:51 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 329 bytes --]

There's a tool called "sim" which does some level of what
you want. I don't think it's at the level of cleverness you're
looking for, but I found it useful for similar tasks.

I'm fairly sure I got it from someone on this list, but I can't
find the source now (all I've got is a MacOSX/power
binary). I'll keep looking.


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 210 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] c code differencing
  2011-09-01 14:51 ` Anthony Sorace
@ 2011-09-01 14:59   ` Anthony Sorace
  0 siblings, 0 replies; 7+ messages in thread
From: Anthony Sorace @ 2011-09-01 14:59 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 86 bytes --]

Ah, yup. Charles ported sim here:
	http://www.terzarima.net/plan9/soft/index.html


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 210 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] c code differencing
  2011-08-31 13:01 [9fans] c code differencing Steve Simon
                   ` (3 preceding siblings ...)
  2011-09-01 14:51 ` Anthony Sorace
@ 2011-09-03 12:17 ` Comeau At9Fans
  4 siblings, 0 replies; 7+ messages in thread
From: Comeau At9Fans @ 2011-09-03 12:17 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 1149 bytes --]

On Wed, Aug 31, 2011 at 9:01 AM, Steve Simon <steve@quintile.net> wrote:

> Anyone have any pointers to a diff for C code.
>
> I have two libraries, A and B.
>
> B is and expanded and modified version of A and I have been
> asked to extract A from B to build two libraries one
> built on top of the other.
>

I'm unclear what you're seeking.  For instance, given this:

// original/a.c
// ...mumbly...
void foo()
{
    int i;

    i = x();
    i = y()
}

and

// new/a.c
// ...mumbly...
void foo()
{
    int i;

    i = y();
    i = z();
}

the obvious line of difference is the removal of i = x() and the addition of
i = z();  So what will the diff'd version look like, conceptually would it
be this? :

// diffd/a.c
// ...mumbly...
// ...possible more mumbly...
void foo()
{
    int i;

    diffd_old();
    i = y();
    diffd_new();
}

--
Greg Comeau / 4.3.10.1 with C++0xisms now in beta!
Comeau C/C++ ONLINE ==>     http://www.comeaucomputing.com/tryitout
World Class Compilers:  Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?

[-- Attachment #2: Type: text/html, Size: 1923 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-09-03 12:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-31 13:01 [9fans] c code differencing Steve Simon
2011-08-31 14:01 ` Rodolfo kix Garcia
2011-09-01 13:16 ` Ethan Grammatikidis
2011-09-01 14:33 ` FENG Yu Ning
2011-09-01 14:51 ` Anthony Sorace
2011-09-01 14:59   ` Anthony Sorace
2011-09-03 12:17 ` Comeau At9Fans

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).