faae8b345c808998fb6c5881d25aaa7bf5efa2f2
[openwrt/svn-archive/archive.git] / package / base-files / default / lib / config / template.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-Z0-9_]/) && (noprint != 1) {
31 n=split(line "@@", a, /@@/)
32 for (i=1; i<=n; i++) {
33 if ((i % 2) == 1) printf "%s" a[i]
34 else printf "%s" v[a[i]]
35 }
36 print ""
37 }
38
39 $1 == "@endif" {
40 if_open = 0
41 noprint = 0
42 }