xref: /netbsd-src/external/ibm-public/postfix/dist/src/postconf/extract_cfg.sh (revision f3bc92a4f25066883a5d85d66df30605583c883c)
1#!/bin/sh
2
3# To view the formatted manual page of this file, type:
4#	POSTFIXSOURCE/mantools/srctoman - extract_cfg.sh | nroff -man
5
6#++
7# NAME
8#	extract_cfg 1
9# SUMMARY
10#	extract database parameter names from cfg_get_xxx() calls
11# SYNOPSIS
12#	\fBextract_cfg [-d|-s] [\fIfile...\fB]\fR
13# DESCRIPTION
14#	The \fBextract_cfg\fR command extracts the parameter names
15#	from cfg_get_{str,int,bool}() calls in dict_xxx.c files. The
16#	output is one parameter name per line, formatted as a C string
17#	followed by comma.
18#
19#	Options:
20# .IP \fB-d\fR
21#	Add the "domain" parameter to the output. This is used by
22#	the LDAP, memcache, and *SQL* tables.
23# .IP \fB-s\fR
24#	Add the legacy SQL query parameters: "select_field", "table",
25#	"where_field", and "additional_conditions".
26# LICENSE
27# .ad
28# .fi
29#	The Secure Mailer license must be distributed with this software.
30# HISTORY
31# .ad
32# .fi
33#	This command was introduced with Postfix 3.3.
34# AUTHOR(S)
35#	Wietse Venema
36#	Google, Inc.
37#	111 8th Avenue
38#	New York, NY 10011, USA
39#--
40
41# In case not installed.
42m4 </dev/null || exit 1
43
44# Flags to add db_common parameter names.
45add_legacy_sql_query_params=
46add_domain_param=
47
48# Parse JCL.
49
50while :
51do
52    case "$1" in
53    -d) add_domain_param=1;;
54    -s) add_legacy_sql_query_params=1;;
55    -*) echo Bad option: $1 1>&2; exit 1;;
56     *) break;;
57    esac
58    shift
59done
60
61# We use m4 macros to extract arguments from cfg_get_xxx() calls that
62# may span multiple lines. We sandwich information of interest between
63# control-A characters. Multiple cfg_get_xxx() calls on the same line
64# should be OK, as long as the calls don't nest.
65
66(
67cat <<'EOF'
68define(`cfg_get_str',`$2
69')dnl
70define(`cfg_get_int',`$2
71')dnl
72define(`cfg_get_bool',`$2
73')dnl
74EOF
75# Convert selected C macro definitions into m4 macro definitions.
76sed 's/^#define[ 	]*\([DICT_MC_NAME_A-Za-z0-9_]*\)[ 	]*\("[^"]*"\)/define(`\1'"'"',`\2'"'"')/' "$@"
77) | m4 | awk -F '// { print $2 }' | (
78test -n "$add_domain_param" && {
79cat <<EOF
80"domain"
81EOF
82}
83test -n "$add_legacy_sql_query_params" && {
84cat <<EOF
85"table"
86"select_field"
87"where_field"
88"additional_conditions"
89EOF
90}
91cat -
92) | sort -u | sed 's/$/,/'
93