Nagios indentation

Andreas Ericsson ae at op5.se
Fri Nov 19 10:38:56 CET 2010


The nagios indentation has been discussed quite a few times, and once
upon a time we agreed that it would be nifty if we could use a style
that's supported by a program so contributors can auto-format their
code before submitting it upstream.

Having spent all of 30 minutes on the problem this morning, I think
I've come up with something.

astyle --indent=tab --unpad-paren --pad-oper --pad-header --brackets=linux

seems to create a very sensible indentation for all the files we have.
The GNU indent program simply can't be convinced to indent with tabs
and align with spaces. Or rather, it can, but not without unbreaking
long lines that are broken manually.

Using the options set above causes code to be indented with tabs and
aligned with spaces, and makes it look like this:

int some_function_name(int a_function_param, const char *lala_param)
{
	if (something) {
		do_something();
	} else {
		do_something_else();
	}

	switch (some_value) {
	case SOME_VALUE_MACRO1:
		lalala();
		break;
	default:
		lalala_default(some_value);
		break;
	}

	return something;
}


It touches only indentation and spaces surrounding operators and
parentheses, which is, imo, a good thing since it won't cause a lot
of unwanted changes each and every time it's run.

Unless someone complains before monday I'll add a Makefile target
to indent the sources, run it once and then commit the results, with
a note added so that future contributors know what to do to make
their code conform to the standard.

vim and emacs users should look into using their editors respective
'smart tabs' settings. Most decent editors support aligning with
spaces and indenting with tabs nowadays, but if you're not using one
of them, you can just run 'make pretty' or 'make indent' before you
submit your patches.

-- 
Andreas Ericsson                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev




More information about the Developers mailing list