-
Notifications
You must be signed in to change notification settings - Fork 1
/
debug_toggle
executable file
·88 lines (80 loc) · 2.06 KB
/
debug_toggle
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
#!/bin/bash
#A script to toggle the debug flags used in fortran source code
#Options and usage
usage()
{
cat <<EOF
usage: $0 Options
This script toggles specially formatted debug statments in fortran source code.
Assumes long form of logical variables used (i.e. .FALSE. and .TRUE.)
OPTIONS:
-h Show this message
-f Force all flags off
-n Force all flags on
-t Toggle the flags (default)
-v <VAL> Sets name of debug variable (defaults to debug)
-i <VAL> Quoted string for file pattern upon which to apply toggle. Defaults to "*.f??"
EOF
}
#GLOBALS
DO_ON=0
DO_OFF=1
DO_TOG=2
DEBUG_VAR="debug"
FILE_PAT="*.f??"
#/Defaults
MODE=${DO_TOG}
while getopts “hfntv:i:” OPTIONS
do
case $OPTIONS in
h)
usage
exit 0
;;
n)
MODE=${DO_ON}
;;
t)
MODE=${DO_TOG}
;;
f)
MODE=${DO_OFF}
;;
v)
DEBUG_VAR=${OPTARG}
;;
i)
FILE_PAT="${OPTARG}"
;;
*)
usage
exit 1
;;
esac
done
#/Do the replacing in all matching files
for i in `ls ${FILE_PAT}`
do
case ${MODE} in
${DO_TOG})
sed --in-place 's/\b'"${DEBUG_VAR}"'\b\([ ]*\)=\([ ]*\).false.\(.*\)$/'"${DEBUG_VAR}"'\1=\2 VAR_REPLACE_T !.false./gI' ${i}
sed --in-place 's/\b'"${DEBUG_VAR}"'\b\( *\)=\( *\)\.true\.\(.*\)$/'"${DEBUG_VAR}"'\1=\2VAR_REPLACE_F !.true./gI' ${i}
sed --in-place 's/VAR_REPLACE_T/.true./gI' ${i}
sed --in-place 's/VAR_REPLACE_F/.false./gI' ${i}
;;
${DO_ON})
sed --in-place 's/\b'"${DEBUG_VAR}"'\b\( *\)=\( *\)\.false\.\(.*\)$/'"${DEBUG_VAR}"'\1=\2.true. !.false./gI' ${i}
;;
${DO_OFF})
sed --in-place 's/\b'"${DEBUG_VAR}"'\b\( *\)=\( *\)\.true\.\(.*\)$/'"${DEBUG_VAR}"'\1=\2.false. !.true./gI' ${i}
;;
*)
#Should never get here
echo "Error: Invalid value of MODE (${MODE})"
exit 1
;;
esac
done
#/Done!
#echo "Done!"
exit 0