OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / freeswan / utils / _include
1 #! /bin/sh
2 # implements nested file inclusion for control files, including wildcarding
3 # Copyright (C) 1998, 1999  Henry Spencer.
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 2 of the License, or (at your
8 # option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
9
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13 # for more details.
14 #
15 # RCSID $Id: _include,v 1.14 2001/06/01 15:49:13 henry Exp $
16 #
17 # Output includes marker lines for file changes:
18 #       "#< filename lineno" signals entry into that file
19 #       "#> filename lineno" signals return to that file
20 # The lineno is the line number of the *next* line.
21 #
22 # Errors are reported with a "#:message" line rather than on stderr.
23 #
24 # Lines which look like marker and report lines are never passed through.
25
26 usage="Usage: $0 file ..."
27 me="ipsec _include"
28
29 for dummy
30 do
31         case "$1" in
32         --inband)                               ;;      # back compatibility
33         --help)         echo "$usage" ; exit 0  ;;
34         --version)      echo "$me $IPSEC_VERSION" ; exit 0              ;;
35         --)             shift ; break           ;;
36         -*)             echo "$0: unknown option \`$1'" >&2 ; exit 2    ;;
37         *)              break                   ;;
38         esac
39         shift
40 done
41
42 case $# in
43 0)      echo "$usage" >&2 ; exit 2      ;;
44 esac
45
46 for f
47 do
48         if test ! -r $f
49         then
50                 echo "#:cannot open configuration file \"$f\""
51                 exit 1
52         fi
53 done
54
55 awk 'BEGIN {
56         wasfile = ""
57 }
58 FNR == 1 {
59         print ""
60         print "#<", FILENAME, 1
61         lineno = 0
62         wasfile = FILENAME
63 }
64 {
65         lineno++
66         # lineno is now the number of this line
67 }
68 /^#[<>:]/ {
69         next
70 }
71 /^include[ \t]+/ {
72         orig = $0
73         sub(/[ \t]+#.*$/, "")
74         if (NF != 2) {
75                 msg = "(" FILENAME ", line " lineno ")"
76                 msg = msg " include syntax error in \"" orig "\""
77                 print "#:" msg
78                 exit 1
79         }
80         newfile = $2
81         if (newfile !~ /^\// && FILENAME ~ /\//) {
82                 prefix = FILENAME
83                 sub("[^/]+$", "", prefix)
84                 newfile = prefix newfile
85         }
86         system("ipsec _include " newfile)
87         print ""
88         print "#>", FILENAME, lineno + 1
89         next
90 }
91 { print }' $*