opt-gather.awk revision 285830
138096Speter#  Copyright (C) 2003,2004 Free Software Foundation, Inc.
264567Sgshapiro#  Contributed by Kelley Cook, June 2004.
338096Speter#  Original code from Neil Booth, May 2003.
480029Sobrien#
580029Sobrien# This program is free software; you can redistribute it and/or modify it
638096Speter# under the terms of the GNU General Public License as published by the
738096Speter# Free Software Foundation; either version 2, or (at your option) any
890798Sgshapiro# later version.
974816Sru# 
1038096Speter# This program is distributed in the hope that it will be useful,
1190798Sgshapiro# but WITHOUT ANY WARRANTY; without even the implied warranty of
1280029Sobrien# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1380029Sobrien# GNU General Public License for more details.
14201390Sed# 
15201390Sed# You should have received a copy of the GNU General Public License
16147225Sdes# along with this program; if not, write to the Free Software
17147225Sdes# Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1890798Sgshapiro
19147225Sdes# This Awk script takes a list of *.opt files and combines them into 
20147225Sdes# a three-field sorted list suitable for input into opt[ch]-gen.awk.
2164567Sgshapiro#
22147225Sdes# Usage: awk -f opt-gather.awk file1.opt [...] > outputfile
23147225Sdes
2464567Sgshapirofunction sort(ARRAY, ELEMENTS)
2590798Sgshapiro{
2690798Sgshapiro	for (i = 2; i <= ELEMENTS; ++i) {
2764567Sgshapiro		for (j = i; ARRAY[j-1] > ARRAY[j]; --j) {
2890798Sgshapiro			temp = ARRAY[j]
2990798Sgshapiro			ARRAY[j] = ARRAY[j-1]
3090798Sgshapiro			ARRAY[j-1] = temp
3165970Sgshapiro		}
3280029Sobrien	}
3365970Sgshapiro	return
3480029Sobrien}
3580029Sobrien
3665970SgshapiroBEGIN {	numrec = 0 }
3790798Sgshapiro
3890798Sgshapiro# Ignore comments and blank lines
3990798Sgshapiro/^[ \t]*(;|$)/  { flag = 0; next }
4038096Speter/^[^ \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