xref: /titanic_52/usr/src/lib/libbsm/mkhdr.sh (revision ba4e3c84e6b9390bbf7df80b5f1d11dec34cc525)
1#!/bin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26# ident	"%Z%%M%	%I%	%E% SMI"
27#
28
29# Automagically generate the audit_uevents.h header file.
30#
31DATABASE=audit_event.txt
32HEADER_FILE=audit_uevents.h
33
34cat <<EOF > $HEADER_FILE
35/*
36 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
37 * Use is subject to license terms.
38 */
39
40#ifndef	_BSM_AUDIT_UEVENTS_H
41#define	_BSM_AUDIT_UEVENTS_H
42
43EOF
44
45grep '^# ident' $DATABASE | sed -e 's/^#/#pragma/' \
46	-e "s/$DATABASE/$HEADER_FILE/" >> $HEADER_FILE
47
48cat <<EOF >> $HEADER_FILE
49
50/*
51 * User level audit event numbers.
52 *
53 *     0		Reserved as an invalid event number.
54 *     1 - 2047		Reserved for the Solaris Kernel events.
55 *  2048 - 32767	Reserved for the Solaris TCB programs.
56 * 32768 - 65535	Available for third party TCB applications.
57 *
58 */
59
60#ifdef	__cplusplus
61extern "C" {
62#endif
63
64EOF
65
66nawk -F: '{if ((NF == 4) && substr($1,0,1) != "#")
67		if ($1 >= 2048) {
68			# compute total output line length first
69			tlen = length($2);
70			llen = 8 + tlen;
71			llen += 8 - (llen % 8);
72			if (llen < 32)
73				llen = 32;
74			llen += length($1);
75			llen += 8 - (llen % 8);
76			llen += 5 + length($4) + length($3) + 3;
77
78			# if line is too long, then print the comment first
79			if (llen > 80)
80				printf("/* =%s %s */\n", $4, $3);
81
82			printf("#define\t%s\t", $2)
83			if (tlen < 8)
84				printf("\t");
85			if (tlen < 16)
86				printf("\t")
87			printf("%s", $1);
88
89			if (llen > 80)
90				printf("\n");
91			else
92				printf("\t/* =%s %s */\n", $4, $3);
93		}
94	  }' \
95< $DATABASE >> $HEADER_FILE
96
97cat <<EOF >> $HEADER_FILE
98
99#ifdef	__cplusplus
100}
101#endif
102
103#endif	/* _BSM_AUDIT_UEVENTS_H */
104EOF
105
106exit 0
107