Opened 12 years ago
Closed 12 years ago
#1663 closed defect (invalid)
Tabs in C source code
| Reported by: | wenzeslaus | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Default | Version: | unspecified |
| Keywords: | indent tabs spaces | Cc: | grass-dev@… |
| CPU: | All | Platform: | All |
Description
I assume that GRASS C source code should be indented with spaces, more precisely with spaces only. And more over, mixing tabs and spaces is a bad practice.
But C source files contains both spaces and tabs.
For example changeset r47676 "code layout fixes with indent" only adds another tabs which are mixed with spaces. Here is a part of file worker.c (http://trac.osgeo.org/grass/browser/grass/trunk/raster/r.li/r.li.daemon/worker.c):
(tab)case FCELL_TYPE:{
(tab)(tab)for (i = 0; i < ad->rl - used; i++) {
(tab)(tab)(4spaces)fm->cache[used + i] = Rast_allocate_f_buf();
(tab)(tab)}
(tab)(4spaces)}
Here is minimal working example which produces badly intended source code (GRASS indent script, tested on Ubuntu 10.04 with GNU indent 2.2.10).
// file test.c
void test()
{
int a,b,i;
a =5;
if ( a==5 ){
for (i = 0; i < 10; i++) { b++; }
b= b*10;
}
}
./tools/grass_indent.sh test.c
// file test.c
void test()
{
(4spaces)int a, b, i;
(4spaces)a = 5;
(4spaces)if (a == 5) {
(tab)for (i = 0; i < 10; i++) {
(tab)(4spaces)b++;
(tab)}
(tab)b = b * 10;
(4spaces)}
}

Replying to wenzeslaus:
This is not a problem, so long as the code is indented correctly for 8-column tabs. Trying to enforce a spaces-only policy isn't worth the trouble.
If you configure your text editor with something other than 8-column tabs, you're on your own (just don't commit code which relies upon something other than 8-column tabs).