]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/uncrusticracy.sh
Viewmodels: clientside Vortex glow
[xonotic/xonotic-data.pk3dir.git] / qcsrc / uncrusticracy.sh
1 FILES=`find client common menu server warpzonelib -name \*.c -o -name \*.h -o -name \*.qc -o -name \*.qh`
2 out_raw()
3 {
4         printf "%s\n" "$LINE"
5 }
6 out()
7 {
8         printf "%-40s = %-8s # %s\n" "$KEY" "$VAL" "$COMMENT"
9 }
10 decide()
11 {
12         verybestchoice=
13         verybestscore=2147483647
14         bestchoice=
15         bestscore=2147483647
16         secondbestchoice=
17         secondbestscore=2147483647
18         worstscore=0
19         haveignore=false
20         havefalse=false
21         have0=false
22         seen=
23         for choice in "$VAL" "$@"; do
24                 case " $seen " in
25                         *" $choice "*)
26                                 continue
27                                 ;;
28                         *)
29                                 seen=$seen" $VAL"
30                                 ;;
31                 esac
32                 if [ x"$choice" = x"force" ]; then
33                         continue
34                 fi
35                 if [ x"$choice" = x"ignore" ]; then
36                         haveignore=true
37                 fi
38                 if [ x"$choice" = x"false" ]; then
39                         havefalse=true
40                 fi
41                 if [ x"$choice" = x"0" ]; then
42                         have0=true
43                 fi
44                 if [ x"$MODE" = x"initialize" ]; then
45                         if [ x"$choice" = x"ignore" ]; then
46                                 score=0
47                         else
48                                 score=2147483647
49                         fi
50                 else
51                         {
52                                 cat uncrustify.cfg
53                                 printf "%s = %s\n" "$KEY" "$choice"
54                         } > uncrustify.cfg.test
55                         UNCRUSTIFY_CONFIG=uncrustify.cfg.test sh uncrustify.sh $FILES >/dev/null 2>&1
56                         status=$?
57                         if [ $status -gt 1 ]; then
58                                 echo "# ERROR: $KEY = $choice crashes with status $status."
59                                 continue
60                         fi
61                         score=0
62                         git diff --numstat > diffstat.tmp
63                         while read -r add del rest; do
64                                 if [ x"$add" != x"-" ]; then
65                                         score=$(($score + $add))
66                                 fi
67                                 if [ x"$del" != x"-" ]; then
68                                         score=$(($score + $del))
69                                 fi
70                         done < diffstat.tmp
71                         git reset --hard >/dev/null 2>&1
72                 fi
73                 echo >&2 "$KEY = $choice: $score"
74                 if [ x"$choice" != x"ignore" ]; then
75                         if [ $score -lt $bestscore ]; then
76                                 secondbestscore=$bestscore
77                                 secondbestchoice=$bestchoice
78                                 bestscore=$score
79                                 bestchoice=$choice
80                         elif [ $score -lt $secondbestscore ]; then
81                                 secondbestscore=$score
82                                 secondbestchoice=$choice
83                         fi
84                 fi
85                 if [ $score -lt $verybestscore ]; then
86                         verybestscore=$score
87                         verybestchoice=$choice
88                 fi
89                 if [ $score -gt $worstscore ]; then
90                         worstscore=$score
91                         worstchoice=$choice
92                 fi
93         done
94         if [ -z "$bestchoice" ]; then
95                 echo "# WARNING: No best choice identified"
96         elif [ $verybestscore -ge $worstscore ]; then
97                 echo "# WARNING: Code doesn't seem to use this feature - delete from the config?"
98                 if $haveignore; then
99                         VAL=ignore
100                 elif $havefalse; then
101                         VAL=false
102                 elif $have0; then
103                         VAL=0
104                 fi
105         elif [ $bestscore -ge $worstscore ]; then
106                 echo "# WARNING: Indifferent... please decide manually."
107         elif [ $bestscore -ge $secondbestscore ]; then
108                 echo "# WARNING: Best is not unique ($bestchoice $secondbestchoice)"
109         elif [ $bestscore -gt $verybestscore ]; then
110                 echo "# NOTE: is $(($bestscore - $verybestscore)) worse than $verybestchoice"
111                 VAL=$bestchoice
112         else
113                 VAL=$bestchoice
114         fi
115 }
116 while read -r LINE; do
117         case "$LINE" in
118                 "# NOTE: "*)
119                         continue
120                         ;;
121                 "# WARNING: "*)
122                         continue
123                         ;;
124                 "# ERROR: "*)
125                         continue
126                         ;;
127                 "#"*)
128                         out_raw
129                         continue
130                         ;;
131                 *"#force"*|*"#ignore"*)
132                         out_raw
133                         continue
134                         ;;
135         esac
136         printf "%s\n" "$LINE" | while read KEY EQ VAL DELIM COMMENT; do
137                 if \
138                         [ x"$EQ" != x"=" ] || \
139                         [ x"$DELIM" != x"#" ]; then
140                         out_raw
141                         continue
142                 fi
143                 case "$COMMENT" in
144                         number)
145                                 case "$KEY" in
146                                         indent_columns|*tab*)
147                                                 decide 1 2 4 8
148                                                 ;;
149                                         *)
150                                                 decide 0 1 2 3 indent_columns
151                                                 ;;
152                                 esac
153                                 out
154                                 ;;
155                         string)
156                                 printf "# WARNING: unsupported %s\n" "$COMMENT"
157                                 out_raw
158                                 ;;
159                         *[!a-z/_]*)
160                                 printf "# ERROR: invalid characters %s\n" "$COMMENT"
161                                 out_raw
162                                 ;;
163                         */*)
164                                 decide `echo "$COMMENT" | tr / ' '`
165                                 out
166                                 ;;
167                         *)
168                                 printf "# ERROR: only once choice %s\n" "$COMMENT"
169                                 out_raw
170                                 ;;
171                 esac
172         done
173 done < uncrustify.cfg