轉自:https://blog.csdn.net/jiangjingui2011/article/details/7197069
常用的設置: indent -npro -kr -i8 -ts8 -sob -l80 -ss -bl -bli 0 參數說明: -npro或--ignore-profile 不要讀取indent的配置文件.indent.pro。 -kr 指定使用Kernighan&Ritchie的格式。 -i8 --indent-level 設置縮排的格數為8。 -ts8 設置tab的長度 -sob或--swallow-optional-blank-lines 刪除多余的空白行。 -l80 代碼超過80換行 -ss或--space-special-semicolon 若for區段只有一行時,在分號前加上空格。 -ncs或--no-space-after-casts 不要在cast之后空一格。 -bl {分行顯示 -bli 0 括號縮進為0 功能說明:調整C原始代碼文件的格式。 語 法:indent [參數][源文件] 或 indent [參數][源文件][-o 目標文件] 補充說明:indent可辨識C的原始代碼文件,並加以格式化,以方便程序設計師閱讀。 參 數: -bad或--blank-lines-after-declarations 在聲明區段或加上空白行。 -bap或--blank-lines-after-procedures 在程序或加上空白行。 -bbb或--blank-lines-after-block-comments 在注釋區段后加上空白行。 -bc或--blank-lines-after-commas 在聲明區段中,若出現逗號即換行。 -bl或--braces-after-if-line if(或是else,for等等)與后面執行區段的"{"不同行,且"}"自成一行。 -bli<縮排格數>或--brace-indent<縮排格數> 設置{ }縮排的格數。 -br或--braces-on-if-line if(或是else,for等等)與后面執行跛段的"{"不同行,且"}"自成一行。 -bs或--blank-before-sizeof 在sizeof之后空一格。 -c<欄數>或--comment-indentation<欄數> 將注釋置於程序碼右側指定的欄位。 -cd<欄數>或--declaration-comment-column<欄數> 將注釋置於聲明右側指定的欄位。 -cdb或--comment-delimiters-on-blank-lines 注釋符號自成一行。 -ce或--cuddle-else 將else置於"}"(if執行區段的結尾)之后。 -ci<縮排格數>或--continuation-indentation<縮排格數> 敘述過長而換行時,指定換行后縮排的格數。 -cli<縮排格數>或--case-indentation-<縮排格數> 使用case時,switch縮排的格數。 -cp<欄數>或-else-endif-column<欄數> 將注釋置於else與elseif敘述右側定的欄位。 -cs或--space-after-cast 在cast之后空一格。 -d<縮排格數>或-line-comments-indentation<縮排格數> 針對不是放在程序碼右側的注釋,設置其縮排格數。 -di<欄數>或--declaration-indentation<欄數> 將聲明區段的變量置於指定的欄位。 -fc1或--format-first-column-comments 針對放在每行最前端的注釋,設置其格式。 -fca或--format-all-comments 設置所有注釋的格式。 -gnu或--gnu-style. 指定使用GNU的格式,此為預設值。 -i<格數>或--indent-level<格數> 設置縮排的格數。 -ip<格數>或--parameter-indentation<格數> 設置參數的縮排格數。 -kr或--k-and-r-style. 指定使用Kernighan&Ritchie的格式。 -lp或--continue-at-parentheses 敘述過長而換行,且敘述中包含了括弧時,將括弧中的每行起始欄位內容垂直對其排列。 -nbad或--no-blank-lines-after-declarations 在聲明區段后不要加上空白行。 -nbap或--no-blank-lines-after-procedures 在程序后不要加上空白行。 -nbbb或--no-blank-lines-after-block-comments 在注釋區段后不要加上空白行。 -nbc或--no-blank-lines-after-commas 在聲明區段中,即使出現逗號,仍舊不要換行。 -ncdb或--no-comment-delimiters-on-blank-lines 注釋符號不要自成一行。 -nce或--dont-cuddle-else 不要將else置於"}"之后。 -ncs或--no-space-after-casts 不要在cast之后空一格。 -nfc1或--dont-format-first-column-comments 不要格式化放在每行最前端的注釋。 -nfca或--dont-format-comments 不要格式化任何的注釋。 -nip或--no-parameter-indentation 參數不要縮排。 -nlp或--dont-line-up-parentheses 敘述過長而換行,且敘述中包含了括弧時,不用將括弧中的每行起始欄位垂直對其排列。 -npcs或--no-space-after-function-call-names 在調用的函數名稱之后,不要加上空格。 -npro或--ignore-profile 不要讀取indent的配置文件.indent.pro。 -npsl或--dont-break-procedure-type 程序類型與程序名稱放在同一行。 -nsc或--dont-star-comments 注解左側不要加上星號(*)。 -nsob或--leave-optional-semicolon 不用處理多余的空白行。 -nss或--dont-space-special-semicolon 若for或while區段僅有一行時,在分號前不加上空格。 -nv或--no-verbosity 不顯示詳細的信息。 -orig或--original 使用Berkeley的格式。 -pcs或--space-after-procedure-calls 在調用的函數名稱與"{"之間加上空格。 -psl或--procnames-start-lines 程序類型置於程序名稱的前一行。 -sc或--start-left-side-of-comments 在每行注釋左側加上星號(*)。 -sob或--swallow-optional-blank-lines 刪除多余的空白行。 -ss或--space-special-semicolon 若for或swile區段今有一行時,在分號前加上空格。 -st或--standard-output 將結果顯示在標准輸出設備。 -T 數據類型名稱縮排。 -ts<格數>或--tab-size<格數> 設置tab的長度。 -v或--verbose 執行時顯示詳細的信息。 -version 顯示版本信息。 如果你不想在參數上花太多時間來研究,你也可以在你的linux下的源代碼里面,也就是/usr/src/linux/scripts/Lindent,找到Lindent腳本,這個是linux內核源代碼格式,你可以直接拿過來用。比如 #cp /usr/src/linux/scripts/Lindent /usr/bin $Lindent test.c # Lindent腳本 #!/bin/sh PARAM="-npro -kr -i8 -ts8 -sob -l80 -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 "$@"