opt-gather.awk revision 169690
176116Sdcs# Copyright (C) 2003,2004 Free Software Foundation, Inc. 276116Sdcs# Contributed by Kelley Cook, June 2004. 376116Sdcs# Original code from Neil Booth, May 2003. 476116Sdcs# 576116Sdcs# This program is free software; you can redistribute it and/or modify it 676116Sdcs# under the terms of the GNU General Public License as published by the 794290Sdcs# Free Software Foundation; either version 2, or (at your option) any 876116Sdcs# later version. 976116Sdcs# 1076116Sdcs# This program is distributed in the hope that it will be useful, 1176116Sdcs# but WITHOUT ANY WARRANTY; without even the implied warranty of 1276116Sdcs# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1376116Sdcs# GNU General Public License for more details. 1476116Sdcs# 1594290Sdcs# You should have received a copy of the GNU General Public License 1694290Sdcs# along with this program; if not, write to the Free Software 1794290Sdcs# Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 1894290Sdcs 1994290Sdcs# This Awk script takes a list of *.opt files and combines them into 2076116Sdcs# a three-field sorted list suitable for input into opt[ch]-gen.awk. 2176116Sdcs# 2276116Sdcs# Usage: awk -f opt-gather.awk file1.opt [...] > outputfile 2376116Sdcs 2476116Sdcsfunction sort(ARRAY, ELEMENTS) 2576116Sdcs{ 2676116Sdcs for (i = 2; i <= ELEMENTS; ++i) { 2776116Sdcs for (j = i; ARRAY[j-1] > ARRAY[j]; --j) { 2876116Sdcs temp = ARRAY[j] 2976116Sdcs ARRAY[j] = ARRAY[j-1] 3076116Sdcs ARRAY[j-1] = temp 3176116Sdcs } 3276116Sdcs } 3376116Sdcs return 3476116Sdcs} 3576116Sdcs 3676116SdcsBEGIN { numrec = 0 } 3776116Sdcs 3876116Sdcs# Ignore comments and blank lines 3976116Sdcs/^[ \t]*(;|$)/ { flag = 0; next } 4076116Sdcs/^[^ \t]/ { if (flag == 0) { 4176116Sdcs record[++numrec] = $0 4276116Sdcs flag = 1 } 4376116Sdcs else { 4476116Sdcs record[numrec] = record[numrec] SUBSEP $0 4576116Sdcs } 4676116Sdcs} 4776116Sdcs 4876116Sdcs# Sort it and output it 4976116SdcsEND { 5076116Sdcs sort(record,numrec) 5176116Sdcs 5276116Sdcs for (i = 1; i <= numrec; i++) { 5376116Sdcs print record[i] } 5476116Sdcs} 5576116Sdcs