1#  Copyright (C) 2003,2004 Free Software Foundation, Inc.
2#  Contributed by Kelley Cook, June 2004.
3#  Original code from Neil Booth, May 2003.
4#
5# This program is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License as published by the
7# Free Software Foundation; either version 2, or (at your option) any
8# later version.
9# 
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14# 
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19# This Awk script takes a list of *.opt files and combines them into 
20# a three-field sorted list suitable for input into opt[ch]-gen.awk.
21#
22# Usage: awk -f opt-gather.awk file1.opt [...] > outputfile
23
24function sort(ARRAY, ELEMENTS)
25{
26	for (i = 2; i <= ELEMENTS; ++i) {
27		for (j = i; ARRAY[j-1] > ARRAY[j]; --j) {
28			temp = ARRAY[j]
29			ARRAY[j] = ARRAY[j-1]
30			ARRAY[j-1] = temp
31		}
32	}
33	return
34}
35
36BEGIN {	numrec = 0 }
37
38# Ignore comments and blank lines
39/^[ \t]*(;|$)/  { flag = 0; next }
40/^[^ \t]/       { if (flag == 0) {
41                    record[++numrec] = $0
42		    flag = 1 }
43		  else {
44		    record[numrec] = record[numrec] SUBSEP $0
45	          }
46}
47
48# Sort it and output it
49END {
50	sort(record,numrec)
51	
52	for (i = 1; i <= numrec; i++) {
53		print record[i] }
54}
55