9ce32b74ffbaa79180fb213212b9f86d9b30ad3b
[openwrt/svn-archive/archive.git] / package / base-files / default / usr / lib / parse-config.awk
1 # Copyright (C) 2006 OpenWrt.org
2
3 {
4 line=$0
5 gsub(/^[ \t]*/, "")
6 gsub(/[ \t]*$/, "")
7 }
8
9 $1 == "@define" {
10 v[$2] = $3
11 }
12
13 $1 == "@ifdef" {
14 if_open = 1
15 if (v[$2] != "") noprint = 0
16 else noprint = 1
17 }
18
19 $1 == "@ifndef" {
20 if_open = 1
21 if (v[$2] != "") noprint = 1
22 else noprint = 0
23 }
24
25 $1 == "@else" {
26 if (noprint == 1) noprint = 0
27 else noprint = 1
28 }
29
30 ($1 !~ /^@[a-zA-Z]/) && (noprint != 1) {
31 n=split(line "@@", a, /@@/)
32 for (i=1; i<=n; i++) {
33 if ((i % 2) == 1) printf a[i]
34 else printf v[a[i]]
35 }
36 print ""
37 }
38
39 $1 == "@endif" {
40 if_open = 0
41 noprint = 0
42 }