indent_find.sh 通过find命令,优点:代码简单,缺点:没有显示正在整理的文件
1 | #!/bin/sh |
2 | ################################################################################# |
3 | #Filename:IndentC/C++codeaccordingtoK&R |
4 | #Author:SunYubo |
5 | #Created:2010-1-25 |
6 | #Description:IndentC/C++codeaccordingtoK&Rbyfind |
7 | #Usage:indent.sh[PATH] |
8 | #"indet.sh"willindentfileatthePATHyougived. |
9 | #Thecurrentdirectorybydefault. |
10 | ################################################################################ |
11 | |
12 | WORK_PATH=$1 |
13 | if[-z"$WORK_PATH"];then |
14 | echo"IndentCfilesincurrentdirectory?Pleaseinputyorn" |
15 | readFLAG |
16 | if["$FLAG"=="y"];then |
17 | WORK_PATH="." |
18 | else |
19 | echo"Inputerror.Pleaserunscriptagain." |
20 | exit1; |
21 | fi |
22 | fi |
23 | |
24 | OPT="-nbad-bap-bbo-nbc-br-brs-c33-cd33-ncdb-ce-ci8-cli8-cp33-cs-d0-di0-nfc1-nfca-hnl-i8-ip0-lp-pcs-nprs-psl-saf-sai-saw-cdb-sc-nsob-nss-npro-ts8-sob-l80-ss-bli0-bfda-ppi3-bs-T-v" |
25 | |
26 | find$WORK_PATH-typef-iname"*.[c,h]"|xargsindent$OPT |
27 |
indent_rec.sh 通过函数实现递归整理,优点:显示正在整理的文件,缺点:编写递归函数
1 | #!/bin/sh |
2 | ################################################################################# |
3 | #Filename:IndentC/C++codeaccordingtoK&R |
4 | #Author:SunYubo |
5 | #Created:2010-1-25 |
6 | #Description:IndentC/C++codeaccordingtoK&Rbyrecursive |
7 | #Usage:indent.sh[PATH] |
8 | #"indet.sh"willindentfileatthePATHyougived. |
9 | #Thecurrentdirectorybydefault. |
10 | ################################################################################ |
11 | |
12 | functionindent_kr(){ |
13 | `indent-nbad-bap-bbo-nbc-br-brs-c33-cd33-ncdb-ce-ci8-cli8-cp33-cs-d0-di0-nfc1-nfca-hnl-i8-ip0-lp-pcs-nprs-psl-saf-sai-saw-cdb-sc-nsob-nss-npro-ts8-sob-l80-ss-bli0-bfda-ppi3-bs-T-v$1` |
14 | } |
15 | #if[-z$cfiles];then |
16 | #echo-e"" |
17 | #else |
18 | #echo-e"IndentingFile:"$cfiles |
19 | #indent_kr$cfiles |
20 | functionprocessfile(){ |
21 | if[-d$1];then |
22 | cd$1 |
23 | forcurrentfilein`ls` |
24 | do |
25 | if[-d$currentfile];then |
26 | echo-e"Dir:$currentfile" |
27 | processfile$currentfile |
28 | elif[-f$currentfile];then |
29 | cfiles=$(echo$currentfile|grep'\.[c,h]$') |
30 | if["$cfiles"!=""];then |
31 | echo-e"Indenting:"$cfiles |
32 | indent_kr$cfiles |
33 | fi |
34 | fi |
35 | done |
36 |