xref: /illumos-gate/usr/src/lib/smbsrv/libsmb/common/smb_status_gen.awk (revision 66582b606a8194f7f3ba5b3a3a6dca5b0d346361)
1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or http://www.opensolaris.org/os/licensing.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24#
25
26#
27# Generate the table mapping NT status codes to strings.
28# The table is sorted in numerical order by putting the
29# numeric constants as a comment first on each line, and
30# then running the table body through sort(1).
31#
32
33BEGIN {
34	printf("/* Table generated by smb_status_gen.awk */\n");
35	printf("#include <smb/ntstatus.h>\n\n");
36	printf("typedef struct smb_status_table {\n");
37	printf("\tunsigned int value;\n");
38	printf("\tconst char *name;\n");
39	printf("} smb_status_table_t;\n\n");
40	printf("static const smb_status_table_t ntx_table[] = {\n");
41}
42/^#define.NT_STATUS_/ {
43	# Skip the _SEVERITY defines.
44	if ( $2 ~ /^NT_STATUS_SEVERITY_/ )
45		next
46
47
48	# Make sure the constant looks as expected.
49	if ( $3 !~ /^0x[0-9A-F]+$/ ) {
50		print "Warning: Unexpected format: "$0 > "/dev/stderr"
51		exit 1;
52	}
53
54	# print: comment { macro, string },
55	printf("\t/* %s */\t{ %s,\t\"%s\" },\n",
56		$3, $2, substr($2,11)) | "sort" ;
57}
58END {
59	close("sort");
60	printf("};\n");
61}
62