summaryrefslogtreecommitdiff
path: root/programs/_include/_include.in
blob: 10a8a49e45f274401243e07983acb63ac8a72d71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#! /bin/sh
# implements nested file inclusion for control files, including wildcarding
# Copyright (C) 1998, 1999  Henry Spencer.
# 
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# RCSID $Id: _include.in,v 1.2 2004/03/15 21:03:06 as Exp $
#
# Output includes marker lines for file changes:
#	"#< filename lineno" signals entry into that file
#	"#> filename lineno" signals return to that file
# The lineno is the line number of the *next* line.
#
# Errors are reported with a "#:message" line rather than on stderr.
#
# Lines which look like marker and report lines are never passed through.

IPSEC_NAME="strongSwan"

usage="Usage: $0 file ..."
me="ipsec _include"

for dummy
do
	case "$1" in
	--inband)				;;	# back compatibility
	--help)		echo "$usage" ; exit 0	;;
	--version)	echo "$me $IPSEC_VERSION" ; exit 0		;;
	--)		shift ; break		;;
	-*)		echo "$0: unknown option \`$1'" >&2 ; exit 2	;;
	*)		break			;;
	esac
	shift
done

case $# in
0)	echo "$usage" >&2 ; exit 2	;;
esac

for f
do
	if test ! -r "$f"
	then
		if test ! "$f" = "/etc/ipsec.conf"
		then
			echo "#:cannot open configuration file \'$f\'"
			if test "$f" = "/etc/ipsec.secrets"
			then
				echo "#:Your secrets file will be created when you start $IPSEC_NAME for the first time."
			fi
			exit 1
		else
			exit 1
		fi
	fi
done

awk 'BEGIN {
	wasfile = ""
}
FNR == 1 {
	print ""
	print "#<", FILENAME, 1
	lineno = 0
	wasfile = FILENAME
}
{
	lineno++
	# lineno is now the number of this line
}
/^#[<>:]/ {
	next
}
/^include[ \t]+/ {
	orig = $0
	sub(/[ \t]+#.*$/, "")
	if (NF != 2) {
		msg = "(" FILENAME ", line " lineno ")"
		msg = msg " include syntax error in \"" orig "\""
		print "#:" msg
		exit 1
	}
	newfile = $2
	if (newfile !~ /^\// && FILENAME ~ /\//) {
		prefix = FILENAME
		sub("[^/]+$", "", prefix)
		newfile = prefix newfile
	}
	system("ipsec _include " newfile)
	print ""
	print "#>", FILENAME, lineno + 1
	next
}
{ print }' $*