Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / tools / style / astyle-clean-cpp-format.sh
1 #!/bin/bash
2 # copy or move Artistic Style backup files to a backup directory
3
4 # CHANGE THE FOLLOWING 4 VARIABLES
5 # $indir is the input top level directory containing the .orig files
6 # $outdir is the output top level directory containing the moved files
7 # $fileext is the backup file extension
8 # $copyfiles is COPY (cp) or MOVE (mv) the files
9 # spaces ARE allowed in directory and file name (for Cygwin on Windows)
10
11 indir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
12 outdir="astyle_backup"
13 fileext=".orig"
14 fileext=".orig"
15 # USE ONE OF THE FOLLOWING TO COPY OR MOVE THE FILES
16 #copyfiles=cp
17 copyfiles=mv
18
19 # display the variables
20 echo
21 echo "\"$copyfiles\" Artistic Style backup files"
22 echo "FROM $indir"
23 echo "TO   $outdir"
24 echo
25
26 # validate input directory
27 if [ ! -d "$indir" ] ; then
28         echo "Input directory does not exist!"
29         echo
30         exit
31 fi
32 if [ "$indir" == "$outdir" ]; then
33         echo "Input and output directories are the same!"
34         echo
35         exit
36 fi
37
38 # optional statement to run Artistic Style
39 # astyle  -R  "%indir%\*.cpp"  "%indir%\*.h"
40 # if [ $? -ne 0 ] ; then  read -sn1 -p "Error executing astyle!"; fi
41
42 # variables for fle processing
43 #echo "processing files..."
44 fileHasSpaces=false         # a file or directory name has spaces
45 extLength=${#fileext}       # length of the file extension
46
47 # loop thru the input directory to find the .orig files
48 # then move the .orig file to the new directory
49 for file in `find  "$indir"  -type f  -name "*$fileext" ` ; do
50
51         # allow spaces in file names for Cygwiin on Windows
52         # test if this is a continuation line and build $infile
53         if [ $fileHasSpaces = true ] ; then
54                 infile+=' '$file
55         else
56                 infile=$file
57         fi
58  
59         # test end of string for no file extension
60         if [ ! "${infile:(-$extLength)}" = $fileext ] ; then    
61                 fileHasSpaces=true
62                 continue
63         fi
64
65         fileHasSpaces=false
66 #       echo $infile
67
68         # replace input file directory with output directory
69         # ${string/substring/replacement}
70         outfile=${infile/$indir/$outdir}
71 #       echo $outfile
72
73         # strip filename from back of the output file
74         # ${string%substring} - /* strips from last '/' to end
75         outpath=${outfile%/*}
76 #       echo $outpath
77
78         # create output directory
79         [ ! -d  "$outpath" ] && mkdir  -p  "$outpath"
80
81         #  copy or move the files
82         $copyfiles  -f  "$infile"  "$outpath"
83         if [ $? -ne 0 ] ; then  
84                 read -sn1 -p "press any key to continue!"
85                 echo
86         fi
87
88         # echo for every 100 files processed
89         let count++
90         let mod=count%100
91         [ $mod -eq 0 ] && echo $count files processed
92 done
93
94 echo $count files processed
95 echo