整理代码脚本

indent_find.sh 通过find命令,优点:代码简单,缺点:没有显示正在整理的文件

#!/bin/sh
#################################################################################
#        Filename: Indent C/C++ code according to K&R 
#          Author: Sun Yubo
#         Created: 2010-1-25
#     Description: Indent C/C++ code according to K&R by find 
#           Usage: indent.sh [PATH]
#                  "indet.sh" will indent file at the PATH you gived. 
#                  The current directory by default.
10  ################################################################################ 
11   
12  WORK_PATH=$1
13  if [ -z "$WORK_PATH" ]; then
14                  echo "Indent C files in current directory ? Please input y or n"
15                  read FLAG
16                  if [ "$FLAG" == "y" ]; then
17                          WORK_PATH="."
18                  else 
19                          echo "Input error. Please run script again."
20                          exit 1;
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 -type f -iname "*.[c,h]" | xargs indent $OPT 
27   

 

indent_rec.sh 通过函数实现递归整理,优点:显示正在整理的文件,缺点:编写递归函数

#!/bin/sh
#################################################################################
#        Filename: Indent C/C++ code according to K&R 
#          Author: Sun Yubo
#         Created: 2010-1-25
#     Description: Indent C/C++ code according to K&R by recursive
#           Usage: indent.sh [PATH]
#                  "indet.sh" will indent file at the PATH you gived. 
#                  The current directory by default.
10  ################################################################################ 
11   
12  function indent_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 "Indenting File:"$cfiles
19  #                                       indent_kr $cfiles
20  function processfile() {
21          if [ -d $1 ]; then
22                  cd $1
23                  for currentfile in `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                  cd ..
37          fi
38  } 
39   
40  processfile $1
41   
posted on 2010-01-27 09:51  SunBo 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/sunyubo/archive/2010/01/27/2282192.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值