1169689Skan# Copyright (C) 2003,2004 Free Software Foundation, Inc. 2169689Skan# Contributed by Kelley Cook, June 2004. 3169689Skan# Original code from Neil Booth, May 2003. 4169689Skan# 5169689Skan# This program is free software; you can redistribute it and/or modify it 6169689Skan# under the terms of the GNU General Public License as published by the 7169689Skan# Free Software Foundation; either version 2, or (at your option) any 8169689Skan# later version. 9169689Skan# 10169689Skan# This program is distributed in the hope that it will be useful, 11169689Skan# but WITHOUT ANY WARRANTY; without even the implied warranty of 12169689Skan# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13169689Skan# GNU General Public License for more details. 14169689Skan# 15169689Skan# You should have received a copy of the GNU General Public License 16169689Skan# along with this program; if not, write to the Free Software 17169689Skan# Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18169689Skan 19169689Skan# This Awk script takes a list of *.opt files and combines them into 20169689Skan# a three-field sorted list suitable for input into opt[ch]-gen.awk. 21169689Skan# 22169689Skan# Usage: awk -f opt-gather.awk file1.opt [...] > outputfile 23169689Skan 24169689Skanfunction sort(ARRAY, ELEMENTS) 25169689Skan{ 26169689Skan for (i = 2; i <= ELEMENTS; ++i) { 27169689Skan for (j = i; ARRAY[j-1] > ARRAY[j]; --j) { 28169689Skan temp = ARRAY[j] 29169689Skan ARRAY[j] = ARRAY[j-1] 30169689Skan ARRAY[j-1] = temp 31169689Skan } 32169689Skan } 33169689Skan return 34169689Skan} 35169689Skan 36169689SkanBEGIN { numrec = 0 } 37169689Skan 38169689Skan# Ignore comments and blank lines 39169689Skan/^[ \t]*(;|$)/ { flag = 0; next } 40169689Skan/^[^ \t]/ { if (flag == 0) { 41169689Skan record[++numrec] = $0 42169689Skan flag = 1 } 43169689Skan else { 44169689Skan record[numrec] = record[numrec] SUBSEP $0 45169689Skan } 46169689Skan} 47169689Skan 48169689Skan# Sort it and output it 49169689SkanEND { 50169689Skan sort(record,numrec) 51169689Skan 52169689Skan for (i = 1; i <= numrec; i++) { 53169689Skan print record[i] } 54169689Skan} 55