forked from fredlcore/BSB-LAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze.sh
116 lines (107 loc) · 3.01 KB
/
analyze.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
FILE=BSB_lan_defs.h
if [ $# -gt 0 ]; then
FILE=$1
fi
cat $FILE | gawk -F ',' '
/^{0x|^{CMD/{
# delete leading and trailing spaces
gsub(/^[ \t]+|[ \t]+$/,"",$1);
gsub(/^[ \t]+|[ \t]+$/,"",$2);
gsub(/^[ \t]+|[ \t]+$/,"",$3);
gsub(/^[ \t]+|[ \t]+$/,"",$4);
gsub(/^[ \t]+|[ \t]+$/,"",$5);
gsub(/^[ \t]+|[ \t]+$/,"",$6);
gsub(/^[ \t]+|[ \t]+$/,"",$7);
gsub(/^[ \t]+|[ \t]+$/,"",$8);
gsub(/^[ \t]+|[ \t]+$/,"",$9);
gsub(/^[ \t]+|[ \t]+$/,"",$10);
# ensure all command IDs are in lower case
# if($1 ~ /0x/) $1=tolower($1);
# statistics
total_cnt++;
if($1 ~ /CMD_UNKNOWN/){
cmd_unknown_cnt++;
if($3 ~ /VT_UNKNOWN/){
cmd_unknown_without_type_cnt++;
}
}else{
if($3 ~ /VT_UNKNOWN/){
cmd_known_without_type_cnt++;
}
}
if($1 !~ /CMD_UNKNOWN/){
cmd[$1"-"$9]++;
if(cmd[$1"-"$9]>1){
print "// !FIXME! !AUTOGENERATED! same cmd as "cmd_first_line[$1"-"$9];
}else{
cmd_first_line[$1"-"$9]=$4;
}
}
# regex="STR"$4;
# if($5 !~ regex ){
# print "DESC ERROR: " $0 > "/dev/stderr";
# wrong_desc_cnt++;
# }
if($6 != 0){
enum_cnt++;
# regex="ENUM"$4;
# if($6 !~ regex){
# print "ENUM SIZE ERROR (regex "regex"!~"$6"): " $0 > "/dev/stderr";
# wrong_enum_size_cnt++;
# }
# regex="ENUM"$4;
# if($7 !~ regex && $7 !~ /ENUM_ERROR/ && $7 !~ /ENUM_WEEKDAY/){
# print "ENUM ERROR: " $0 > "/dev/stderr";
# wrong_enum_cnt++;
# }
if($3 !~ /VT_ENUM/ && $3 !~ /VT_ERRORCODE/ && $3 !~ /VT_BIT/){
print "ENUM TYPE ERROR: " $0 > "/dev/stderr";
wrong_type_enum_cnt++;
}
}
# append separator
$1=$1","; # cmdID
$2=$2","; # category
$3=$3","; # type
$4=$4","; # line number
$5=$5","; # description
$6=$6","; # size of enum
$7=$7","; # enum
$8=$8","; # flags
$9=$9","; # devices
# output with indentation
printf("%-13s %-21s %-18s %-6s %-9s %-21s %-13s %-13s %-8s ", $1, $2, $3, $4, $5, $6, $7, $8, $9);
# output of rest of the line (comment)
for(i=10;i<=NF;i++) printf("%s",$i);
printf("\n");
# analyses of field length for indentation
for(i=1;i<=NF;i++){
l=length($i);
len[i]=l>len[i]?l:len[i];
}
next;
}
{
print
}
END{
# analyses of field length for indentation
for(i in len){
printf("len[%d]: %d\n",i,len[i]) > "/dev/stderr"
}
printf("total: %d\n",total_cnt) > "/dev/stderr"
printf("unknown cmds: %d\n",cmd_unknown_cnt) > "/dev/stderr"
printf("unknown cmds without type: %d\n",cmd_unknown_without_type_cnt) > "/dev/stderr"
printf("known cmds without type: %d\n",cmd_known_without_type_cnt) > "/dev/stderr"
printf("cmds with wrong description: %d\n",wrong_desc_cnt) > "/dev/stderr"
printf("cmds with enum type: %d\n",enum_cnt) > "/dev/stderr"
printf("cmds with wrong enum size: %d\n",wrong_enum_size_cnt) > "/dev/stderr"
printf("cmds with wrong enum: %d\n",wrong_enum_cnt) > "/dev/stderr"
printf("cmds with enum but wrong type: %d\n",wrong_type_enum_cnt) > "/dev/stderr"
for(i in cmd){
if(cmd[i]>1)
printf("cmdid %s occurs %d times\n",i,cmd[i]) > "/dev/stderr"
}
}
'