Lindent – amazing script for lazy C coder

For you a lazy C coder, sometimes indentation could be a big mess when you only think about code’s performance and not so into a cosmetic and style. Anyway, I was in that time too, I never thought about the importance of style when I wrote a code until I have to review someone’s code. It’s crappy and PITA, it ended up by me writing the whole code from scratch.

Thanks to kernel source script: Lindent now that cosmetic stuff is over, you can just write the code your way, and in the end call this script to make your code better and readable, and the most important is: it conforms Linux CodingStyle ;-).

Here we go, you can get it from Linux source in script directory: linux-source/scripts/Lindent. Or you can make a leftover from the snippet below:

   2PARAM="-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1"
   3RES=`indent --version`
   4V1=`echo $RES | cut -d' ' -f3 | cut -d'.' -f1`
   5V2=`echo $RES | cut -d' ' -f3 | cut -d'.' -f2`
   6V3=`echo $RES | cut -d' ' -f3 | cut -d'.' -f3`
   7if [ $V1 -gt 2 ]; then
   8  PARAM="$PARAM -il0"
   9elif [ $V1 -eq 2 ]; then
  10  if [ $V2 -gt 2 ]; then
  11    PARAM="$PARAM -il0";
  12  elif [ $V2 -eq 2 ]; then
  13    if [ $V3 -ge 10 ]; then
  14      PARAM="$PARAM -il0"
  15    fi
  16  fi
  18indent $PARAM "$@"

You can use it as follow:

$ /path/to/Lindent source.c

Consider following images:

1. before

2. After

Lindent uses the features of GNU indent. A tool to change the appearance of a C program by inserting or deleting whitespace.