This document describes the recommended coding style for kdepim. Nobody is forced to use this style, but to have consistent formatting of the source code files it is strongly recommended to make use of it.
In short: Kdepim coding style follows the Kdelibs coding style.
As discussed at the KDEPIM meeting, Berlin, 3 March 2013, all the files of KDEPIM will be reviewed to follow the coding style. This will be done over a long time, directory after directory, for each of the rules defined above. For each rule, one can find one or two script(s).
As a first approach, not any object may have binary change after applying one of the rules. To check this, one uses the Check-the-Objects.sh. Download the script: Media:Check-the-Objects.sh.gz
The script can be used with one of the commands:
An example:
cd <some_kdepim_directory> mkdir build cd build ccmake ../ make
Scanning dependencies of target gpgmepp [ 0%] Building CXX object gpgme++/CMakeFiles/gpgmepp.dir/gpgmepp_automoc.cpp.o [ 0%] Building CXX object gpgme++/CMakeFiles/gpgmepp.dir/exception.cpp.o [ 0%] Building CXX object gpgme++/CMakeFiles/gpgmepp.dir/context.cpp.o ...
Check-the-Objects.sh save
The script makes a copy of all the objects and a "time stamp":
save the object ./kholidays/tests/CMakeFiles/testzodiac.dir/testzodiac.cpp.o save the object ./kholidays/tests/CMakeFiles/testzodiac.dir/testzodiac_automoc.cpp.o ... all objects are saved
Now, one makes somes change(s) on the source(s) and:
make
Depending on the Makefile, some objects will be compiled again:
Scanning dependencies of target akonadi-kde [ 17%] Building CXX object akonadi/CMakeFiles/akonadi-kde.dir/entitytreeview.cpp.o [ 17%] Building CXX object akonadi/CMakeFiles/akonadi-kde.dir/itemfetchjob.cpp.o [ 17%] Building CXX object akonadi/CMakeFiles/akonadi-kde.dir/statisticsproxymodel.cpp.o ... Scanning dependencies of target akonadi-kmime [ 56%] Building CXX object akonadi/kmime/CMakeFiles/akonadi-kmime.dir/standardmailactionmanager.cpp.o
Check-the-Objects.sh test
The script finds all the new objects, makes a comparision with the saved version:
test the object ./akonadi/CMakeFiles/akonadi-kde.dir/statisticsproxymodel.cpp.o test the object ./akonadi/CMakeFiles/akonadi-kde.dir/entitytreeview.cpp.o test the object ./akonadi/CMakeFiles/akonadi-kde.dir/itemfetchjob.cpp.o test the object ./akonadi/kmime/CMakeFiles/akonadi-kmime.dir/standardmailactionmanager.cpp.o all tests are OK
If we add or remove some lines, the debug informations included in the object file will be change also.
This is the case with the test/change of "Only single empty lines should be used", "First line, last line(s) may not be empty" and some more test/change below (adding some blocks with { and }).
For this reason it is no more possible to compare the objects. We have to compare the assembler files. This works pretty well for the version with CMAKE_BUILD_TYPE set to release. For the version with CMAKE_BUILD_TYPE set to debug, we must remove all the debug informations before the comparision could take place.
To generate the assembler files, we only need to modify the build.make in every folder.
The script Prepare-build_make_files.sh works on the all directory, finds the line with the compiler command, duplicates the line, add a -S option and changes the name of the output to somename.s. After a new make command, we can save all the assembler files with the script Check-the-assembler_code.sh. Download the script: Media:Prepare-build_make_files.sh.gz
The biggest part of the debug informations beginns with the directive line
We drop all the next lines.
We drop also the lines with the directive .loc They contain an information about the source line (here 123) we need later to drop the lines
The lines with
will be also removed.
The script to check the assembler files can be used in the same way as the one above (Check-the-Objects.sh). To check this, one uses the Check-the-assembler_code.sh. Download the script: Media:Check-the-assembler_code.sh.gz
The script can be used with one of the commands:
The first script is to check a single file or a complete directory for all .h and .cpp files.
If present, the second script makes the changes for a single file or a complete directory for all .h and .cpp files. For some complicated situations, the script makes no change.
One can use the scripts for own work.It is recommanded to use them in this order.
Download the scripts: Media:Tabs.tar.gz
The output of the check script is:
check the file /home/guy-kde/projects/kdepimlibs/ktnef/ktnefparser.cpp 1->308: Tab at 16: stream_ >> i; // i <- attribute type & name 2->311: Tab at 16: stream_ >> i; // i <- data length 3->326: Tab at 22: case attATTACHMENT: // try to get attachment info 4->367: Tab at 16: stream_ >> u; // u <- checksum a b c d
This shows:
The change script:
Download the scripts: Media:Trim.tar.gz
The output of the check script is:
check the file /home/guy-kde/Software/coding-style-check/trim.cpp 1->51: Space(s) at end of line (28): QVariant m_matchData;
This shows:
The change script:
The output of the check script is:
check the file /home/guy-kde/projects/kdepimlibs/syndication/rss2/enclosure.cpp 1->25: next empty line found 2->26: next empty line found 3->30: next empty line found
This shows:
The change script:
Some of the sources have a first empty lines, some have one or more empty last line(s).
The output of the check script is:
check the file /home/guy-kde/Software/coding-style-check/trim.cpp The first line is empty The last line is empty
The change script:
The following code:
if ( a > b ) c = 123;
is correct, but we prefer the block:
if ( a > b ) { c = 123; }
which is easier to read, to modify.
It is also possible to put a breakpoint at the line in the block.
As the awk-script is too simple to recognize all the if-statements, we get some false alarm and we can't make the changes automatically.