about summary refs log tree commit diff
path: root/scripts/merge-abilist.awk
blob: 016debc62872e293f58d7a0572a0a2975e9d4dc1 (plain) (blame)
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
# awk script to merge a config-specific .symlist file with others.
# The input files should be an existing .abilist file, and a .symlist file.
# This must be passed run with awk -v config=REGEXP to specify a regexp
# matching configuration tuples for which the .symlist input defines an ABI.
# The result merges all duplicate occurrences of any symbol in a version set
# into a stanza listing the regexps matching configurations that contain it.

/^[^ ]/ {
  if (NF < 2 && config == "") {
    print "BAD LINE:", $0 > "/dev/stderr";
    exit 2;
  }

  if (NF < 2) {
    current = $1 ":" config;
  }
  else {
    current = $1 ":" $2;
    for (i = 3; i <= NF; ++i) {
      current = current "," $1 ":" $i;
    }
  }

  next;
}

{
  if ($0 in seen) {
    seen[$0] = seen[$0] "\n" current;
  }
  else {
    seen[$0] = current;
  }

  next;
}

END {
  for (line in seen) {
    split(seen[line], setlist, "\n");
    for (i in setlist) {
      split(setlist[i], configs, ",");
      for (j in configs) {
	split(configs[j], temp, ":");
	version = temp[1];
	conf = temp[2];

	if ((version,conf) in have) continue;
	have[version,conf] = 1;

	if (version in confs) {
	  split(confs[version], c, " ");
	  if (conf < c[1]) {
	    confs[version] = conf;
	    for (k = 1; k <= nconfs[version]; ++k) {
	      confs[version] = confs[version] " " c[k];
	    }
	  }
	  else {
	    confs[version] = c[1];
	    for (k = 2; k <= nconfs[version]; ++k) {
	      if (conf < c[k]) break;
	      confs[version] = confs[version] " " c[k];
	    }
	    confs[version] = confs[version] " " conf;
	    for (; k <= nconfs[version]; ++k) {
	      confs[version] = confs[version] " " c[k];
	    }
	  }
	  ++nconfs[version];
	}
	else {
	  confs[version] = conf;
	  nconfs[version] = 1;
	}
      }
    }
    for (idx in have) delete have[idx];

    for (version in confs) {
      idx = version " " confs[version];
      if (idx in final) {
	final[idx] = final[idx] "\n" line;
      }
      else {
	final[idx] = line;
      }
      delete confs[version];
      delete nconfs[version];
    }
  }

  nstanzas = 0;
  for (stanza in final) {
    if (nstanzas == 0) {
      stanzas = stanza;
      nstanzas = 1;
      continue;
    }
    split(stanzas, s, "\n");
    if (stanza < s[1]) {
      stanzas = stanza;
      for (i = 1; i <= nstanzas; ++i) {
	stanzas = stanzas "\n" s[i];
      }
    }
    else {
      stanzas = s[1];
      for (i = 2; i <= nstanzas; ++i) {
	if (stanza < s[i]) break;
	stanzas = stanzas "\n" s[i];
      }
      stanzas = stanzas "\n" stanza;
      for (; i <= nstanzas; ++i) {
	stanzas = stanzas "\n" s[i];
      }
    }
    ++nstanzas;
  }

  split(stanzas, order, "\n");
  for (i = 1; i <= nstanzas; ++i) {
    stanza = order[i];
    print stanza;
    outpipe = "sort";
    print final[stanza] | outpipe;
    close(outpipe);
  }
}