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