Fix: relayd: rotation failure for multi-domain session
[lttng-tools.git] / m4 / pprint.m4
CommitLineData
6cc58d14 1# DESCRIPTION
9d8c7763 2#
6cc58d14
MD
3# Pretty printing macros.
4#
5# LICENSE
6#
7# Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com>
8#
9# This program is free software; you can redistribute it and/or modify it
10# under the terms of the GNU General Public License as published by the
11# Free Software Foundation; either version 2 of the License, or (at your
12# option) any later version.
13#
14# This program is distributed in the hope that it will be useful, but
15# WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17# Public License for more details.
18#
19# You should have received a copy of the GNU General Public License along
20# with this program. If not, see <https://www.gnu.org/licenses/>.
21#
22# As a special exception, the respective Autoconf Macro's copyright owner
23# gives unlimited permission to copy, distribute and modify the configure
24# scripts that are the output of Autoconf when processing the Macro. You
25# need not follow the terms of the GNU General Public License when using
26# or distributing such scripts, even though portions of the text of the
27# Macro appear in them. The GNU General Public License (GPL) does govern
28# all other use of the material that constitutes the Autoconf Macro.
29#
30# This special exception to the GPL applies to versions of the Autoconf
31# Macro released by the Autoconf Archive. When you make and distribute a
32# modified version of the Autoconf Macro, you may extend this special
33# exception to the GPL to apply to your modified version as well.
9d8c7763 34
c2aa7947
MJ
35#serial 1
36
9d8c7763
JG
37# PPRINT_INIT(): initializes the pretty printing system.
38#
39# Use this macro before using any other PPRINT_* macro.
40AC_DEFUN([PPRINT_INIT], [
5170ef08
PP
41 m4_define([PPRINT_CONFIG_TS], [50])
42 m4_define([PPRINT_CONFIG_INDENT], [2])
9d8c7763
JG
43 PPRINT_YES_MSG=yes
44 PPRINT_NO_MSG=no
45
46 # find tput, which tells us if colors are supported and gives us color codes
5170ef08 47 AC_PATH_PROG([pprint_tput], [tput])
9d8c7763
JG
48
49 AS_IF([test -n "$pprint_tput"], [
c2aa7947 50 AS_IF([test -n "$PS1" && test `"$pprint_tput" colors` -eq 256 && test -t 1], [
9d8c7763
JG
51 # interactive shell and colors supported and standard output
52 # file descriptor is opened on a terminal
c2aa7947
MJ
53 PPRINT_COLOR_TXTBLK="`"$pprint_tput" setaf 0`"
54 PPRINT_COLOR_TXTBLU="`"$pprint_tput" setaf 4`"
55 PPRINT_COLOR_TXTGRN="`"$pprint_tput" setaf 2`"
56 PPRINT_COLOR_TXTCYN="`"$pprint_tput" setaf 6`"
57 PPRINT_COLOR_TXTRED="`"$pprint_tput" setaf 1`"
58 PPRINT_COLOR_TXTPUR="`"$pprint_tput" setaf 5`"
59 PPRINT_COLOR_TXTYLW="`"$pprint_tput" setaf 3`"
60 PPRINT_COLOR_TXTWHT="`"$pprint_tput" setaf 7`"
9d8c7763 61 PPRINT_COLOR_BLD=`"$pprint_tput" bold`
5170ef08
PP
62 PPRINT_COLOR_BLDBLK="$PPRINT_COLOR_BLD$PPRINT_COLOR_TXTBLK"
63 PPRINT_COLOR_BLDBLU="$PPRINT_COLOR_BLD$PPRINT_COLOR_TXTBLU"
64 PPRINT_COLOR_BLDGRN="$PPRINT_COLOR_BLD$PPRINT_COLOR_TXTGRN"
65 PPRINT_COLOR_BLDCYN="$PPRINT_COLOR_BLD$PPRINT_COLOR_TXTCYN"
66 PPRINT_COLOR_BLDRED="$PPRINT_COLOR_BLD$PPRINT_COLOR_TXTRED"
67 PPRINT_COLOR_BLDPUR="$PPRINT_COLOR_BLD$PPRINT_COLOR_TXTPUR"
68 PPRINT_COLOR_BLDYLW="$PPRINT_COLOR_BLD$PPRINT_COLOR_TXTYLW"
69 PPRINT_COLOR_BLDWHT="$PPRINT_COLOR_BLD$PPRINT_COLOR_TXTWHT"
70 PPRINT_COLOR_RST="`"$pprint_tput" sgr0`"
9d8c7763
JG
71
72 # colored yes and no
73 PPRINT_YES_MSG="$PPRINT_COLOR_BLDGRN$PPRINT_YES_MSG$PPRINT_COLOR_RST"
74 PPRINT_NO_MSG="$PPRINT_COLOR_BLDRED$PPRINT_NO_MSG$PPRINT_COLOR_RST"
75
76 # subtitle color
5170ef08 77 PPRINT_COLOR_SUBTITLE="$PPRINT_COLOR_BLDCYN"
9d8c7763
JG
78 ])
79 ])
80])
81
82# PPRINT_SET_INDENT(indent): sets the current indentation.
83#
84# Use PPRINT_INIT() before using this macro.
85AC_DEFUN([PPRINT_SET_INDENT], [
5170ef08 86 m4_define([PPRINT_CONFIG_INDENT], [$1])
9d8c7763
JG
87])
88
89# PPRINT_SET_TS(ts): sets the current tab stop.
90#
91# Use PPRINT_INIT() before using this macro.
92AC_DEFUN([PPRINT_SET_TS], [
5170ef08 93 m4_define([PPRINT_CONFIG_TS], [$1])
9d8c7763
JG
94])
95
96# PPRINT_SUBTITLE(subtitle): pretty prints a subtitle.
97#
98# The subtitle is put as is in a double-quoted shell string so the user
99# needs to escape ".
100#
101# Use PPRINT_INIT() before using this macro.
102AC_DEFUN([PPRINT_SUBTITLE], [
5170ef08 103 AS_ECHO(["${PPRINT_COLOR_SUBTITLE}$1$PPRINT_COLOR_RST"])
9d8c7763
JG
104])
105
106AC_DEFUN([_PPRINT_INDENT], [
107 m4_if(PPRINT_CONFIG_INDENT, 0, [
108 ], [
5170ef08
PP
109 m4_for([pprint_i], [0], m4_eval(PPRINT_CONFIG_INDENT * 2 - 1), [1], [
110 AS_ECHO_N([" "])
9d8c7763
JG
111 ])
112 ])
113])
114
115# PPRINT_PROP_STRING(title, value, title_color?): pretty prints a
116# string property.
117#
118# The title is put as is in a double-quoted shell string so the user
119# needs to escape ".
120#
121# The $PPRINT_CONFIG_INDENT variable must be set to the desired indentation
122# level.
123#
124# Use PPRINT_INIT() before using this macro.
125AC_DEFUN([PPRINT_PROP_STRING], [
126 m4_pushdef([pprint_title], [$1])
127 m4_pushdef([pprint_value], [$2])
5170ef08 128 m4_pushdef([pprint_title_color], m4_default([$3], []))
9d8c7763
JG
129 m4_pushdef([pprint_title_len], m4_len(pprint_title))
130 m4_pushdef([pprint_spaces_cnt], m4_eval(PPRINT_CONFIG_TS - pprint_title_len - (PPRINT_CONFIG_INDENT * 2) - 1))
131
5170ef08
PP
132 m4_if(m4_eval(pprint_spaces_cnt <= 0), [1], [
133 m4_define([pprint_spaces_cnt], [1])
9d8c7763
JG
134 ])
135
136 m4_pushdef([pprint_spaces], [])
137
5170ef08 138 m4_for([pprint_i], 0, m4_eval(pprint_spaces_cnt - 1), [1], [
9d8c7763
JG
139 m4_append([pprint_spaces], [ ])
140 ])
141
142 _PPRINT_INDENT
143
5170ef08
PP
144 AS_ECHO_N(["pprint_title_color""pprint_title$PPRINT_COLOR_RST:pprint_spaces"])
145 AS_ECHO(["${PPRINT_COLOR_BLD}pprint_value$PPRINT_COLOR_RST"])
9d8c7763
JG
146
147 m4_popdef([pprint_spaces])
148 m4_popdef([pprint_spaces_cnt])
149 m4_popdef([pprint_title_len])
150 m4_popdef([pprint_title_color])
151 m4_popdef([pprint_value])
152 m4_popdef([pprint_title])
153])
154
155# PPRINT_PROP_BOOL(title, value, title_color?): pretty prints a boolean
156# property.
157#
158# The title is put as is in a double-quoted shell string so the user
159# needs to escape ".
160#
161# The value is evaluated at shell runtime. Its evaluation must be
162# 0 (false) or 1 (true).
163#
164# Uses the PPRINT_PROP_STRING() with the "yes" or "no" string.
165#
166# Use PPRINT_INIT() before using this macro.
167AC_DEFUN([PPRINT_PROP_BOOL], [
168 m4_pushdef([pprint_title], [$1])
169 m4_pushdef([pprint_value], [$2])
170
171 test pprint_value -eq 0 && pprint_msg="$PPRINT_NO_MSG" || pprint_msg="$PPRINT_YES_MSG"
172
5170ef08
PP
173 m4_if([$#], [3], [
174 PPRINT_PROP_STRING(pprint_title, [$pprint_msg], $3)
9d8c7763 175 ], [
5170ef08 176 PPRINT_PROP_STRING(pprint_title, [$pprint_msg])
9d8c7763
JG
177 ])
178
179 m4_popdef([pprint_value])
180 m4_popdef([pprint_title])
181])
182
c2aa7947
MJ
183# PPRINT_PROP_BOOL_CUSTOM(title, value, no_msg, title_color?): pretty prints a boolean
184# property.
185#
186# The title is put as is in a double-quoted shell string so the user
187# needs to escape ".
188#
189# The value is evaluated at shell runtime. Its evaluation must be
190# 0 (false) or 1 (true).
191#
192# Uses the PPRINT_PROP_STRING() with the "yes" or "no" string.
193#
194# Use PPRINT_INIT() before using this macro.
195AC_DEFUN([PPRINT_PROP_BOOL_CUSTOM], [
196 m4_pushdef([pprint_title], [$1])
197 m4_pushdef([pprint_value], [$2])
198 m4_pushdef([pprint_value_no_msg], [$3])
199
200 test pprint_value -eq 0 && pprint_msg="$PPRINT_NO_MSG (pprint_value_no_msg)" || pprint_msg="$PPRINT_YES_MSG"
201
202 m4_if([$#], [4], [
203 PPRINT_PROP_STRING(pprint_title, [$pprint_msg], $4)
204 ], [
205 PPRINT_PROP_STRING(pprint_title, [$pprint_msg])
206 ])
207
208 m4_popdef([pprint_value_no_msg])
209 m4_popdef([pprint_value])
210 m4_popdef([pprint_title])
211])
212
9d8c7763
JG
213# PPRINT_WARN(msg): pretty prints a warning message.
214#
215# The message is put as is in a double-quoted shell string so the user
216# needs to escape ".
217#
218# Use PPRINT_INIT() before using this macro.
219AC_DEFUN([PPRINT_WARN], [
220 m4_pushdef([pprint_msg], [$1])
221
222 _PPRINT_INDENT
a24d43ae 223 AS_ECHO(["${PPRINT_COLOR_TXTYLW}WARNING:$PPRINT_COLOR_RST ${PPRINT_COLOR_BLDYLW}pprint_msg$PPRINT_COLOR_RST"])
9d8c7763
JG
224
225 m4_popdef([pprint_msg])
226])
227
228# PPRINT_ERROR(msg): pretty prints an error message and exits.
229#
230# The message is put as is in a double-quoted shell string so the user
231# needs to escape ".
232#
233# Use PPRINT_INIT() before using this macro.
234AC_DEFUN([PPRINT_ERROR], [
235 m4_pushdef([pprint_msg], [$1])
236
5170ef08 237 AC_MSG_ERROR([${PPRINT_COLOR_BLDRED}pprint_msg$PPRINT_COLOR_RST])
9d8c7763
JG
238
239 m4_popdef([pprint_msg])
240])
This page took 0.044653 seconds and 4 git commands to generate.