summaryrefslogtreecommitdiff
path: root/src/pmgenmap/pmgenmap.sh
blob: f6e6b4cc5cc8168408eca1183ffd46c4c8490c2b (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
103
#! /bin/sh
#
# Copyright (c) 1997 Silicon Graphics, Inc.  All Rights Reserved.
# 
# 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.
# 
# 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.
# 
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Generate a Performance Metrics Name Space Map from a specification file
#

# Get standard environment
. $PCP_DIR/etc/pcp.env

prog=`basename $0`
if [ $# -gt 1 -o "X$1" = "X-?" ]
then
    echo "Usage: $prog [infile]"
    exit 1
fi
if [ $# -eq 0 ]
then
    pathnamename="<stdin>"
    name="<stdin>"
else
    if [ ! -f $1 ]
    then
	echo "$prog: cannot open \"$1\""
	exit 1
    fi
    pathname=`pwd`/$1
    name=$1
fi

cat <<End-of-File
/*
 * Performance Metrics Name Space Map
 * Built by $prog from the file
 * $name
 * on `date`
 *
 * Do not edit this file!
 */

End-of-File

# Deal with either Windows or Unix variants of text files
cat $1 | tr '\r\n' '\n' | $PCP_AWK_PROG '
$1 == "#"	{ if (comment) text = text "\n *"
		  comment++
		  for (i = 2; i <= NF; i++)
		    text = text " " $i
		  next
		}
comment > 0	{ if (comment == 1)
			print "/*" text " */"
		  else
		    print "/*\n *" text "\n */"
		  comment = 0
		  text = ""
		}
NF == 0		{ print; next }
NF == 2 && $2 == "{"	{ if (state != 0) {
				printf "[%s:%d] nested group?\n","'$1'",NR
				exit 1
			  }
			  printf "char *%s[] = {\n",$1
			  state = 1
			  ord = 0
			  next
			}
NF == 2 && state == 1	{ printf "#define %s	%d\n",$2,ord
			  ord++
			  printf "	\"%s\",\n",$1
			  next
			}
NF == 1 && $1 == "}"	{ printf "\n"
			  printf "};\n\n"
			  state = 0
			  next
			}
			{ printf "[%s:%d] syntax error\n","'$name'",NR
			  exit 1
			}
END			{ if (state) {
				printf "[%s:%d] unterminated group?\n","'$name'",NR
				exit 1
			  }
			  if (comment == 1)
				print "/*" text " */"
			  else if (comment > 1)
				print "/*\n *" text "\n */"
			}'