first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / tools / solution_solvers / check_resource_ids.sh
1 #!/bin/bash
2
3 # finds all the resource ids in resource headers (only those named the
4 # canonical resource.h name) and discovers any duplicates.  the duplicates
5 # are shown with their symbolic names and file locations.
6
7 TEMP_RESOURCE_HEADERS=/tmp/resrc_headers.txt
8
9 sp='[   ]'  # space and tab.
10
11 # find all the resource headers so we can look at their contents.
12 find "$BUILD_TOP" -type f -iname "resource.h" | \
13   grep -vi 3rdparty | \
14   grep -vi admin_items | \
15   grep -v app >"$TEMP_RESOURCE_HEADERS"
16 #hmmm: above ignores *anything* with app in the name.
17 #  grep -v app_src >"$TEMP_RESOURCE_HEADERS"
18
19 FULLDEFS=/tmp/full_definition_list.txt
20 # clean up prior versions.
21 rm -f "$FULLDEFS"
22
23 # iterate through all the resource headers we found.
24 while read line; do
25 #echo "file=$line"
26   # find any lines that define a resource id.  remove any that are part of
27   # visual studio's tracking system for next id to assign (_APS_NEXT crud).
28   chop_line="$(echo $line | sed -e 's/[\\\/]/+/g')"
29   grep "^$sp*#define$sp*[_A-Za-z0-9][_A-Za-z0-9]*$sp*[0-9][0-9]*$sp*$" <"$line" | \
30   grep -v "_APS_NEXT" | \
31   grep -v "_APS_3D" | \
32   grep -v "$sp*\/\/.*" | \
33   sed -e "s/^$sp*#define$sp*\([_A-Za-z0-9][_A-Za-z0-9]*\)$sp*\([0-9][0-9]*\)$sp*$/\1=\2#$chop_line/" >>"$FULLDEFS"
34 done <"$TEMP_RESOURCE_HEADERS"
35
36 # our accumulated lists of names and ids (in order per list).
37 declare -a resource_names=()
38 declare -a resource_ids=()
39 declare -a resource_files=()
40
41 # iterate through the definitions list and compile the set of known ids.
42 while read line; do
43   name=$(echo $line | sed -e 's/\([^=]*\)=[^#]*#.*/\1/')
44   id=$(echo $line | sed -e 's/[^=]*=\([^#]*\)#.*/\1/')
45   file=$(echo $line | sed -e 's/[^=]*=[^#]*#\(.*\)/\1/')
46
47 #echo got name $name
48 #echo got id $id
49 #echo got file $file
50   next_index=${#resource_names[*]}
51 #echo next ind is $next_index
52   resource_names[${next_index}]=$name
53   resource_ids[${next_index}]=$id
54   resource_files[${next_index}]=$id
55
56 done <"$FULLDEFS"
57
58 echo done reading all definitions.
59
60 JUST_IDS=/tmp/ids_list.txt
61 rm -f "$JUST_IDS"
62
63 i=0
64 while [[ i -le $next_index ]]; do
65   echo ${resource_ids[$i]} >>"$JUST_IDS"
66   ((i++))
67 done
68
69 echo done accumulating list of integer ids.
70
71 id_size=$(wc "$JUST_IDS")
72
73 JUST_IDS_TEMP=/tmp/ids_list_temp.txt
74
75 sort "$JUST_IDS" | uniq >"$JUST_IDS_TEMP"
76 id_temp_size=$(wc "$JUST_IDS_TEMP")
77 if [ "$id_size" == "$id_temp_size" ]; then
78   echo "Your IDs are all unique!  Ending analysis."
79   exit 0
80 fi
81
82 echo "Your ids are *NOT* all unique; the repeated ones are:"
83 sort "$JUST_IDS" | uniq -d >"$JUST_IDS_TEMP"
84
85 while read line; do
86   id="$line"
87   echo "=== identifier $id ==="
88   grep "=$line#" "$FULLDEFS" | sed -e 's/\+/\//g' | sed -e 's/#/\
89 /'
90 done <"$JUST_IDS_TEMP"
91
92