Home > Programming > DAMit Version 2

DAMit Version 2

November 18th, 2008

While working at Seelab at The University of Tennessee in 2006 one of my first tasks was to rename every function in what is now the Visualization CookBook, but was previously another name. We developed a simple Document for API Modification and called it the DAM document. I then wrote a Perl script to apply the DAM document to user’s source code to ease the pains of a major API modification and we named it “DAMit”. Yes, we too thought it was funny.

Recently, I have been paying much attention to the Kohana PHP framework which was introduced to me by a friend. It seems the community gets quite up-in-arms when the developers decide to make a major API change, which they do frequently and without reservation. Some loath it, some embrace it; I would fall somewhere in between. This situation reminded me of the DAMit script which had gone unused ever since it did it’s job so well when it was first created. Well, it is back, and with a vengance! To suit the needs of more advanced APIs, such as Kohana, I have added Perl-regex support; and without further ado I bring you DAMit2!

Example DAM document

header1\.h              ==> newheader.h
rotate_object\dd        ==> RotateObject$1D
new MyClass             ==> MyClass::factory
(MyClass1|MyOtherClass|AnotherClass|AndAnother)->   ==> MyNamespace::$1->
foo_\w+_bar             ==> Foo$1Bar


Usage: DAMit2 dam.txt file [file] ... [test]
The "test" option will output the log, but not apply changes.
DAM all files in current directory:
   DAMit dam.txt *.*
DAM all .h files in current directory (recursive), but do not apply changes:
   DAMit dam.txt `find -name \*.h` test
DAM all .h, .c, and .cpp files in current directory (recursive):
   DAMit dam.txt `find -name \*.cpp` `find -name \*.\[hc\]`

View Source


Disclaimer: Always backup your work before running this script. In fact, it would be wise to mirror the directory and after it is complete, run a recursive diff using your favorite diff tool to inspect the changes made. If you use SVN, apply it to a clean working copy and use svn diff to compare changes later. Of course, I take no responsibility for anything silly you do with this script. Test your regular expressions using the “test” argument to debug.

Programming ,