1

I have been merging all of source-code files used by various developers/CAD drafters for the past 15 or so years. It appears that everyone worked off the same code base until about 7 years ago, when everyone seems to have made a local copy of all the files and used/edited them locally.

I have successfully/painfully merged all of their files with the same names back together. However, I am finding that sometimes, files with different names contain functions with the same names and parameters. Tools that are expecting one implementation of a function may end up calling a different one depending on which files were loaded when.

Is there a simple way to search all of the files for repeated function names?

For Example, a function looks like this:

(defun MyInStr (SearchIn SearchFor)
    ...
)

How could I search all files for (defun MyInStr (SearchIn SearchFor)

jth41
  • 3,808
  • 9
  • 59
  • 109
  • What regex would identify function names? Apply it to the entire code base, then find non-unique elements, then find files containing those elements. – Carl Manaster Mar 13 '14 at 15:52
  • Sounds great but IDK how to do regexes. could you give me an example using some information from my edit? – jth41 Mar 13 '14 at 16:02

1 Answers1

0

I would suggest using ctags to generate the TAGS file, then searching it for duplicate lines:

$ ctags -R
$ sort TAGS -o - | uniq -c | grep -v '^ *1 '

The above will produce output like this:

...
3   defun MyInStr (SearchIn SearchFor)
...

which will tell you that MyInStr is re-defined 3 times in the codebase with the identical signature.

You can also extract just the function name using sed or do a more complicated processing of the TAGS file with perl or lisp or python any other scripting tool.

sds
  • 58,617
  • 29
  • 161
  • 278
  • I successfully get a tags file. But when I run the second command there is no output – jth41 Mar 13 '14 at 18:50
  • It means that there are no dupes. Do you understand how the command works? Basically, the `TAGS` file contains all the defuns from all the files - now you need to scan just one file. – sds Mar 13 '14 at 19:00
  • No there are dupes. I made sure to add one myself. and I checked the tags file and see that they exist, but I dont get a nice printout like you describe `3 defun MyInStr (SearchIn SearchFor)` its as if your second command does nothing – jth41 Mar 13 '14 at 19:02
  • Let me repeat: Do you understand how the command works? _When_ you do, you should be able to figure out how do modify it to suit your needs. You should also grep `TAGS` for the function you added. – sds Mar 13 '14 at 19:07