summaryrefslogtreecommitdiffstats
path: root/debian/uncrustify-trinity/uncrustify-trinity-0.74.0/scripts/compare_the_gcov.awk
blob: 30dba1ad43af2aecb79dcf9a9230fae8a8b1086d (plain)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
BEGIN {
  number_of_lines    = 0;
  number_of_header   = 0;
  T_number_of_lines  = 0;
  T_number_of_header = 0;
  input_file  = in_file;
  output_file = out_file;
  #
  # get the first line, if any.
  getline aaa <input_file;
  if (ERRNO != "") {
    #printf("ERRNO is %s\n", ERRNO);
    #printf("a new file will be created at %s\n", output_file);
    # totals-file not found, this is the first run.
    first_run = "yes";
  } else {
    # totals-file is found. Read it into the arrays
    first_run = "no";
    for ( i = 1; i < 20000; i++) {
      theLine = aaa;
      where_is_colon_1 = index(theLine, ":");
      part_1 = substr(theLine, 1, where_is_colon_1 - 1);
      rest_1 = substr(theLine, where_is_colon_1 + 1);
      where_is_colon_2 = index(rest_1, ":");
      part_2 = substr(rest_1, 1, where_is_colon_2 - 1) + 0;
      rest_2 = substr(rest_1, where_is_colon_2 + 1);
      if (part_2 == 0) {
        # header part
        T_number_of_header = T_number_of_header + 1;
        T_header_part1[T_number_of_header] = part_1;
        T_header_part2[T_number_of_header] = part_2;
        T_header_part3[T_number_of_header] = rest_2;
      } else {
        # source lines
        # a new line
        T_number_of_lines = part_2;
        T_source_part1[T_number_of_lines] = part_1;
        T_source_part2[T_number_of_lines] = part_2;
        T_source_part3[T_number_of_lines] = rest_2;
      }

      aaa = "";
      # get the next line
      getline aaa <input_file;
      if (aaa == "") {
        # EOF
        break;
      }
    }
    close(input_file);
    # Test it
    #printf("Test it\n");
    #for (i = 1; i <= T_number_of_header; i++) {
    #  printf("%8s:%5d:%s\n", T_header_part1[i], T_header_part2[i], T_header_part3[i]);
    #}
    #for (i = 1; i <= T_number_of_lines; i++) {
    #  printf("%8s:%5d:%s\n", T_source_part1[i], T_source_part2[i], T_source_part3[i]);
    #}
  }
}

{
  theLine = $0;
  where_is_colon_1 = index(theLine, ":");
  part_1 = substr(theLine, 1, where_is_colon_1 - 1);
  rest_1 = substr(theLine, where_is_colon_1 + 1);
  where_is_colon_2 = index(rest_1, ":");
  part_2 = substr(rest_1, 1, where_is_colon_2 - 1) + 0;
  rest_2 = substr(rest_1, where_is_colon_2 + 1);
  if (part_2 == 0) {
    # header part
    number_of_header = number_of_header + 1;
    header_part1[number_of_header] = part_1;
    header_part2[number_of_header] = part_2;
    header_part3[number_of_header] = rest_2;
  } else {
    # source lines
    # a new line
    number_of_lines = part_2;
    source_part1[number_of_lines] = part_1;
    source_part2[number_of_lines] = part_2;
    source_part3[number_of_lines] = rest_2;
    where_ = index(part_1, "-");
    if (where_ > 0) {
      # don't take care
    } else {
      where_2 = index(part_1, "#####");
      if (where_2 > 0) {
        # don't take care
      } else {
        d_part_1 = part_1 + 0;
        # look at T_source_part1[part_2]
        where_3 = index(T_source_part1[part_2], "#####");
        if (where_3 > 0) {
          sum = d_part_1;
          # write the sum to T_source_part1
          T_source_part1[part_2] = d_part_1; 
        } else {
          d_T = T_source_part1[part_2] + 0;
          sum = d_part_1 + d_T;
          # write the sum back to T_source_part1
          T_source_part1[part_2] = sum; 
        }
      }
    }
  }
}
END {
  if (first_run == "yes") {
    # copy to T_
    T_number_of_header = number_of_header;
    T_number_of_lines  = number_of_lines;
    for(i = 1; i <= T_number_of_header; i++) {
      T_header_part1[i] = header_part1[i]; 
      T_header_part2[i] = header_part2[i]; 
      T_header_part3[i] = header_part3[i]; 
    }
    for (i = 1; i <= T_number_of_lines; i++) {
      T_source_part1[i] = source_part1[i]; 
      T_source_part2[i] = source_part2[i]; 
      T_source_part3[i] = source_part3[i]; 
    }
  }
  #printf("T_number_of_header is %d\n", T_number_of_header);
  #printf("T_number_of_lines  is %d\n", T_number_of_lines);

  # delete the previous version
  printf("") > output_file;
  for(i = 1; i <= T_number_of_header; i++) {
    printf("%9s:%5d:%s\n", T_header_part1[i], T_header_part2[i], T_header_part3[i]) >> output_file;
  }
  for (i = 1; i <= T_number_of_lines; i++) {
    printf("%9s:%5d:%s\n", T_source_part1[i], T_source_part2[i], T_source_part3[i]) >> output_file;
  }
  close(output_file);
}