Build system: use SPDX identifiers
[urcu.git] / m4 / ae_pprint.m4
CommitLineData
d001c886
MJ
1# SPDX-FileCopyrightText: 2016 Philippe Proulx <pproulx@efficios.com>
2#
3# SPDX-License-Identifier: GPL-2.0-or-later WITH Autoconf-exception-2.0
4
5#serial 2
6
7# AE_PPRINT_INIT(): initializes the pretty printing system.
8#
9# Use this macro before using any other AE_PPRINT_* macro.
10AC_DEFUN([AE_PPRINT_INIT], [
11 m4_define([AE_PPRINT_CONFIG_TS], [50])
12 m4_define([AE_PPRINT_CONFIG_INDENT], [2])
13 AE_PPRINT_YES_MSG=yes
14 AE_PPRINT_NO_MSG=no
15
16 # find tput, which tells us if colors are supported and gives us color codes
17 AC_PATH_PROG([ae_pprint_tput], [tput])
18
19 AS_IF([test -n "$ae_pprint_tput"], [
20 AS_IF([test -n "$PS1" && test `"$ae_pprint_tput" colors` -eq 256 && test -t 1], [
21 # interactive shell and colors supported and standard output
22 # file descriptor is opened on a terminal
23 AE_PPRINT_COLOR_TXTBLK="`"$ae_pprint_tput" setaf 0`"
24 AE_PPRINT_COLOR_TXTBLU="`"$ae_pprint_tput" setaf 4`"
25 AE_PPRINT_COLOR_TXTGRN="`"$ae_pprint_tput" setaf 2`"
26 AE_PPRINT_COLOR_TXTCYN="`"$ae_pprint_tput" setaf 6`"
27 AE_PPRINT_COLOR_TXTRED="`"$ae_pprint_tput" setaf 1`"
28 AE_PPRINT_COLOR_TXTPUR="`"$ae_pprint_tput" setaf 5`"
29 AE_PPRINT_COLOR_TXTYLW="`"$ae_pprint_tput" setaf 3`"
30 AE_PPRINT_COLOR_TXTWHT="`"$ae_pprint_tput" setaf 7`"
31 AE_PPRINT_COLOR_BLD=`"$ae_pprint_tput" bold`
32 AE_PPRINT_COLOR_BLDBLK="$AE_PPRINT_COLOR_BLD$AE_PPRINT_COLOR_TXTBLK"
33 AE_PPRINT_COLOR_BLDBLU="$AE_PPRINT_COLOR_BLD$AE_PPRINT_COLOR_TXTBLU"
34 AE_PPRINT_COLOR_BLDGRN="$AE_PPRINT_COLOR_BLD$AE_PPRINT_COLOR_TXTGRN"
35 AE_PPRINT_COLOR_BLDCYN="$AE_PPRINT_COLOR_BLD$AE_PPRINT_COLOR_TXTCYN"
36 AE_PPRINT_COLOR_BLDRED="$AE_PPRINT_COLOR_BLD$AE_PPRINT_COLOR_TXTRED"
37 AE_PPRINT_COLOR_BLDPUR="$AE_PPRINT_COLOR_BLD$AE_PPRINT_COLOR_TXTPUR"
38 AE_PPRINT_COLOR_BLDYLW="$AE_PPRINT_COLOR_BLD$AE_PPRINT_COLOR_TXTYLW"
39 AE_PPRINT_COLOR_BLDWHT="$AE_PPRINT_COLOR_BLD$AE_PPRINT_COLOR_TXTWHT"
40 AE_PPRINT_COLOR_RST="`"$ae_pprint_tput" sgr0`"
41
42 # colored yes and no
43 AE_PPRINT_YES_MSG="$AE_PPRINT_COLOR_BLDGRN$AE_PPRINT_YES_MSG$AE_PPRINT_COLOR_RST"
44 AE_PPRINT_NO_MSG="$AE_PPRINT_COLOR_BLDRED$AE_PPRINT_NO_MSG$AE_PPRINT_COLOR_RST"
45
46 # subtitle color
47 AE_PPRINT_COLOR_SUBTITLE="$AE_PPRINT_COLOR_BLDCYN"
48 ])
49 ])
50])
51
52# AE_PPRINT_SET_INDENT(indent): sets the current indentation.
53#
54# Use AE_PPRINT_INIT() before using this macro.
55AC_DEFUN([AE_PPRINT_SET_INDENT], [
56 m4_define([AE_PPRINT_CONFIG_INDENT], [$1])
57])
58
59# AE_PPRINT_SET_TS(ts): sets the current tab stop.
60#
61# Use AE_PPRINT_INIT() before using this macro.
62AC_DEFUN([AE_PPRINT_SET_TS], [
63 m4_define([AE_PPRINT_CONFIG_TS], [$1])
64])
65
66# AE_PPRINT_SUBTITLE(subtitle): pretty prints a subtitle.
67#
68# The subtitle is put as is in a double-quoted shell string so the user
69# needs to escape ".
70#
71# Use AE_PPRINT_INIT() before using this macro.
72AC_DEFUN([AE_PPRINT_SUBTITLE], [
73 AS_ECHO(["${AE_PPRINT_COLOR_SUBTITLE}$1$AE_PPRINT_COLOR_RST"])
74])
75
76AC_DEFUN([_AE_PPRINT_INDENT], [
77 m4_if(AE_PPRINT_CONFIG_INDENT, 0, [
78 ], [
79 m4_for([ae_pprint_i], [0], m4_eval(AE_PPRINT_CONFIG_INDENT * 2 - 1), [1], [
80 AS_ECHO_N([" "])
81 ])
82 ])
83])
84
85# AE_PPRINT_PROP_STRING(title, value, title_color?): pretty prints a
86# string property.
87#
88# The title is put as is in a double-quoted shell string so the user
89# needs to escape ".
90#
91# The $AE_PPRINT_CONFIG_INDENT variable must be set to the desired indentation
92# level.
93#
94# Use AE_PPRINT_INIT() before using this macro.
95AC_DEFUN([AE_PPRINT_PROP_STRING], [
96 m4_pushdef([ae_pprint_title], [$1])
97 m4_pushdef([ae_pprint_value], [$2])
98 m4_pushdef([ae_pprint_title_color], m4_default([$3], []))
99 m4_pushdef([ae_pprint_title_len], m4_len(ae_pprint_title))
100 m4_pushdef([ae_pprint_spaces_cnt], m4_eval(AE_PPRINT_CONFIG_TS - ae_pprint_title_len - (AE_PPRINT_CONFIG_INDENT * 2) - 1))
101
102 m4_if(m4_eval(ae_pprint_spaces_cnt <= 0), [1], [
103 m4_define([ae_pprint_spaces_cnt], [1])
104 ])
105
106 m4_pushdef([ae_pprint_spaces], [])
107
108 m4_for([ae_pprint_i], 0, m4_eval(ae_pprint_spaces_cnt - 1), [1], [
109 m4_append([ae_pprint_spaces], [ ])
110 ])
111
112 _AE_PPRINT_INDENT
113
114 AS_ECHO_N(["ae_pprint_title_color""ae_pprint_title$AE_PPRINT_COLOR_RST:ae_pprint_spaces"])
115 AS_ECHO(["${AE_PPRINT_COLOR_BLD}ae_pprint_value$AE_PPRINT_COLOR_RST"])
116
117 m4_popdef([ae_pprint_spaces])
118 m4_popdef([ae_pprint_spaces_cnt])
119 m4_popdef([ae_pprint_title_len])
120 m4_popdef([ae_pprint_title_color])
121 m4_popdef([ae_pprint_value])
122 m4_popdef([ae_pprint_title])
123])
124
125# AE_PPRINT_PROP_BOOL(title, value, title_color?): pretty prints a boolean
126# property.
127#
128# The title is put as is in a double-quoted shell string so the user
129# needs to escape ".
130#
131# The value is evaluated at shell runtime. Its evaluation must be
132# 0 (false) or 1 (true).
133#
134# Uses the AE_PPRINT_PROP_STRING() with the "yes" or "no" string.
135#
136# Use AE_PPRINT_INIT() before using this macro.
137AC_DEFUN([AE_PPRINT_PROP_BOOL], [
138 m4_pushdef([ae_pprint_title], [$1])
139 m4_pushdef([ae_pprint_value], [$2])
140
141 test ae_pprint_value -eq 0 && ae_pprint_msg="$AE_PPRINT_NO_MSG" || ae_pprint_msg="$AE_PPRINT_YES_MSG"
142
143 m4_if([$#], [3], [
144 AE_PPRINT_PROP_STRING(ae_pprint_title, [$ae_pprint_msg], $3)
145 ], [
146 AE_PPRINT_PROP_STRING(ae_pprint_title, [$ae_pprint_msg])
147 ])
148
149 m4_popdef([ae_pprint_value])
150 m4_popdef([ae_pprint_title])
151])
152
153# AE_PPRINT_PROP_BOOL_CUSTOM(title, value, no_msg, title_color?): pretty prints a boolean
154# property.
155#
156# The title is put as is in a double-quoted shell string so the user
157# needs to escape ".
158#
159# The value is evaluated at shell runtime. Its evaluation must be
160# 0 (false) or 1 (true).
161#
162# Uses the AE_PPRINT_PROP_STRING() with the "yes" or "no" string.
163#
164# Use AE_PPRINT_INIT() before using this macro.
165AC_DEFUN([AE_PPRINT_PROP_BOOL_CUSTOM], [
166 m4_pushdef([ae_pprint_title], [$1])
167 m4_pushdef([ae_pprint_value], [$2])
168 m4_pushdef([ae_pprint_value_no_msg], [$3])
169
170 test ae_pprint_value -eq 0 && ae_pprint_msg="$AE_PPRINT_NO_MSG (ae_pprint_value_no_msg)" || ae_pprint_msg="$AE_PPRINT_YES_MSG"
171
172 m4_if([$#], [4], [
173 AE_PPRINT_PROP_STRING(ae_pprint_title, [$ae_pprint_msg], $4)
174 ], [
175 AE_PPRINT_PROP_STRING(ae_pprint_title, [$ae_pprint_msg])
176 ])
177
178 m4_popdef([ae_pprint_value_no_msg])
179 m4_popdef([ae_pprint_value])
180 m4_popdef([ae_pprint_title])
181])
182
183# AE_PPRINT_WARN(msg): pretty prints a warning message.
184#
185# The message is put as is in a double-quoted shell string so the user
186# needs to escape ".
187#
188# Use AE_PPRINT_INIT() before using this macro.
189AC_DEFUN([AE_PPRINT_WARN], [
190 m4_pushdef([ae_pprint_msg], [$1])
191
192 _AE_PPRINT_INDENT
193 AS_ECHO(["${AE_PPRINT_COLOR_TXTYLW}WARNING:$AE_PPRINT_COLOR_RST ${AE_PPRINT_COLOR_BLDYLW}ae_pprint_msg$AE_PPRINT_COLOR_RST"])
194
195 m4_popdef([ae_pprint_msg])
196])
197
198# AE_PPRINT_ERROR(msg): pretty prints an error message and exits.
199#
200# The message is put as is in a double-quoted shell string so the user
201# needs to escape ".
202#
203# Use AE_PPRINT_INIT() before using this macro.
204AC_DEFUN([AE_PPRINT_ERROR], [
205 m4_pushdef([ae_pprint_msg], [$1])
206
207 AC_MSG_ERROR([${AE_PPRINT_COLOR_BLDRED}ae_pprint_msg$AE_PPRINT_COLOR_RST])
208
209 m4_popdef([ae_pprint_msg])
210])
This page took 0.029143 seconds and 4 git commands to generate.