linux下使用indent整理代码

有时候在网上下载的代码代码风格是不很习惯,可以使用index来格式化

widon@widon-F3JR:~$ cat ~/.bin/indent_c.sh 
#!/bin/sh
## C
PARAM="-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1"
## C++
#PARAM="-bad -bap -bbb -bbo -nbc -bl -bli0 -bls -c33 -cd33 -ncdb -ncdw -nce -cli0 -cp33 -cs -d0 -nbfda -di2 -nfc1 -nfca -hnl -ip5 -l75 -lp -pcs -nprs -psl -saf -sai -saw -nsc -nsob -nss -i4 -ts4 -ut"
#PARAM="-npro -kr -i8 -ts8 -sob -l120 -ss -ncs -cp1"
RES=`indent --version`
V1=`echo $RES | cut -d' ' -f3 | cut -d'.' -f1`
V2=`echo $RES | cut -d' ' -f3 | cut -d'.' -f2`
V3=`echo $RES | cut -d' ' -f3 | cut -d'.' -f3`
if [ $V1 -gt 2 ]; then
  PARAM="$PARAM -il0"
elif [ $V1 -eq 2 ]; then
  if [ $V2 -gt 2 ]; then
    PARAM="$PARAM -il0";
  elif [ $V2 -eq 2 ]; then
    if [ $V3 -ge 10 ]; then
      PARAM="$PARAM -il0"
    fi
  fi
fi
indent $PARAM "$@"

在代码的根目录里面

find * -name *.c -o -name *.h | xargs indent_c.sh

代码就被格式化为内核风格了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章