opt-gather.awk 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (C) 2003-2015 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 3, 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; see the file COPYING3. If not see
  17. # <http://www.gnu.org/licenses/>.
  18. # This Awk script takes a list of *.opt files and combines them into
  19. # a three-field sorted list suitable for input into opt[ch]-gen.awk.
  20. #
  21. # Usage: awk -f opt-gather.awk file1.opt [...] > outputfile
  22. function sort(ARRAY, ELEMENTS)
  23. {
  24. for (i = 2; i <= ELEMENTS; ++i) {
  25. for (j = i; ARRAY[j-1] > ARRAY[j]; --j) {
  26. temp = ARRAY[j]
  27. ARRAY[j] = ARRAY[j-1]
  28. ARRAY[j-1] = temp
  29. }
  30. }
  31. return
  32. }
  33. BEGIN { numrec = 0 }
  34. # Ignore comments and blank lines
  35. /^[ \t]*(;|$)/ { flag = 0; next }
  36. /^[^ \t]/ { if (flag == 0) {
  37. record[++numrec] = $0
  38. flag = 1 }
  39. else {
  40. record[numrec] = record[numrec] SUBSEP $0
  41. }
  42. }
  43. # Sort it and output it
  44. END {
  45. sort(record,numrec)
  46. for (i = 1; i <= numrec; i++) {
  47. print record[i] }
  48. }