xref: /titanic_52/usr/src/cmd/sgs/tools/getmessage.awk (revision 10db1377dafab8ba3feedef26db9c5d8539a5cd1)
1#
2# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3# Use is subject to license terms.
4#
5# CDDL HEADER START
6#
7# The contents of this file are subject to the terms of the
8# Common Development and Distribution License, Version 1.0 only
9# (the "License").  You may not use this file except in compliance
10# with the License.
11#
12# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
13# or http://www.opensolaris.org/os/licensing.
14# See the License for the specific language governing permissions
15# and limitations under the License.
16#
17# When distributing Covered Code, include this CDDL HEADER in each
18# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
19# If applicable, add the following below this CDDL HEADER, with the
20# fields enclosed by brackets "[]" replaced with your own identifying
21# information: Portions Copyright [yyyy] [name of copyright owner]
22#
23# CDDL HEADER END
24#
25# ident	"%Z%%M%	%I%	%E% SMI"
26#
27
28#
29# Extract MACROs referenced by MSG_INTL and MSG_ORIG
30#	The MACROS referenced by MSG_INTL() go to MSG_INTL_LIST
31#	The MACROS referenced by MSG_ORIG() go to MSG_ORIG_LIST
32#
33
34BEGIN {
35	FS = "[,(){]|[ ]+|[\t]+"
36
37	# These variables are used to handle the lines such as:
38	#		MSG_INTL(
39	#		MSG_FORMAT);
40	watchme_intl = 0
41	watchme_orig = 0
42}
43
44#
45# If the input line has MSG_INTL or MSG_ORIG, collect the
46# MACRO used. Assumption is that the MACRO names have to be
47# composed of upper characters.
48#
49/MSG_INTL|MSG_ORIG|_elf_seterr/ {
50	for (i = 1; i <= NF; ++i) {
51		if ($i == "MSG_INTL" || $i == "_elf_seterr") {
52			if (i == NF - 1) {
53				watchme_intl = 1
54				next
55			}
56			j = i + 1
57			while ($j == "")
58				j++
59			if (match($j, /[a-z]/) == 0 &&
60			    match($j, /[A-Z]/) != 0)
61				print $j	> "MSG_INTL_LIST"
62		}
63
64		if ($i == "MSG_ORIG") {
65			if (i == NF - 1) {
66				watchme_orig = 1
67				next
68			}
69			j = i + 1
70			while ($j == "")
71				j++
72			if (match($j, /[a-z]/) == 0 &&
73			    match($j, /[A-Z]/) != 0)
74				print $j	> "MSG_ORIG_LIST"
75		}
76	}
77}
78
79#
80# If the previous line ended with MSG_INTL or MSG_ORIG not
81# having the MACRO name, pick it from the next line.
82#
83{
84	if (watchme_intl == 1) {
85		if (match($1, /[a-z]/) == 0 &&
86		    match($1, /[A-Z]/) != 0)
87			print $1	> "MSG_INTL_LIST"
88		watchme_intl = 0;
89	} else if (watchme_orig == 1) {
90		if (match($1, /[a-z]/) == 0 &&
91		    match($1, /[A-Z]/) != 0)
92			print $1	> "MSG_INTL_ORIG"
93		watchme_orig = 0;
94	}
95}
96