I've mentioned a few times that the lack of standard filenames in C++ can be
problematic. This is an example of the kind of situation where it becomes
so. I tend to switch between using Emacs[*] and KDevelop[**]. I often
find Emacs easier to use for simple test code, but KDevelop (when the cvs
image is healthy) tends to facilitate better overal project organization.
Not infrequently, I want to work on code written with one tool in the other.
Well, Emacs thinks of *.h files as C rather than C++ headers, and thus goes
into C mode when they are opened. If I don't catch it, the code is
fromatted and highlighted differently than it would be in C++ mode. I
therefore use *.hh nameing when using Emacs (as well as *.cc, because I
like it better than *.cpp). OTOH KDevelop doesn't deal with *.hh (nore
*.cc) files well, preferring *.h (and *.cpp).
OK, so I spin up some bash to convert a directory from one form to the
other:
function kdev2emacs()
{
test -d old || mkdir old;
for f in *.h; do
test -f $f && cat $f | sed -e /"#include "/s/"\.h\([\"\>]\)"/.hh\\1/ >
${f%%.h}.hh;
mv $f old;
done
for f in *.cpp; do
test -f $f && cat $f | sed -e /"#include "/s/"\.h\([\"\>]\)"/.hh\\1/ >
${f%%.cpp}.cc;
mv $f old;
done
}
$ ls
main.cpp ring.cpp ring.h torus.cpp torus.h torusscene.cpp torusscene.h
$ grep \#include *[ph]
main.cpp:#include "torusscene.h"
....
torusscene.cpp:#include "torus.h"
torusscene.cpp:#include "torus.moc"
$ kdev2emacs
$ ls
main.cc old ring.cc ring.hh torus.cc torus.hh torusscene.cc
torusscene.hh
$ grep \#include *[ch]
main.cc:#include "torusscene.hh"
....
torusscene.cc:#include "torus.hh"
torusscene.cc:#include "torus.moc"
Cool! It works! ...
Whoops!
torusscene.cc:#include <Inventor/Qt/SoQt.hh>
torusscene.cc:#include <Inventor/Qt/viewers/SoQtExaminerViewer.hh>
torusscene.cc:#include <Inventor/SbBasic.hh>
torusscene.cc:#include <Inventor/fields/SoMFVec3f.hh>
torusscene.cc:#include <Inventor/nodes/SoSeparator.hh>
torusscene.cc:#include <Inventor/nodes/SoTransform.hh>
torusscene.cc:#include <Inventor/nodes/SoCoordinate3.hh>
torusscene.cc:#include <Inventor/nodes/SoQuadMesh.hh>
torusscene.cc:#include <Inventor/nodes/SoShapeHints.hh>
These aren't mine. I can't simply rename or symlink them.
And as I've already said, *.c++ and *.h++ is the One True Way.[*] http://www.gnu.org/software/emacs/emacs.html
[**] http://www.kdevelop.org
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell