parse-config.awk 563 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (C) 2006 OpenWrt.org
  2. {
  3. line=$0
  4. gsub(/^[ \t]*/, "")
  5. gsub(/[ \t]*$/, "")
  6. }
  7. $1 == "@define" {
  8. v[$2] = $3
  9. }
  10. $1 == "@ifdef" {
  11. if_open = 1
  12. if (v[$2] != "") noprint = 0
  13. else noprint = 1
  14. }
  15. $1 == "@ifndef" {
  16. if_open = 1
  17. if (v[$2] != "") noprint = 1
  18. else noprint = 0
  19. }
  20. $1 == "@else" {
  21. if (noprint == 1) noprint = 0
  22. else noprint = 1
  23. }
  24. ($1 !~ /^@[a-zA-Z]/) && (noprint != 1) {
  25. n=split(line "@@", a, /@@/)
  26. for (i=1; i<=n; i++) {
  27. if ((i % 2) == 1) printf a[i]
  28. else printf v[a[i]]
  29. }
  30. print ""
  31. }
  32. $1 == "@endif" {
  33. if_open = 0
  34. noprint = 0
  35. }