VirtualBox

source: vbox/trunk/include/iprt/message.h@ 70286

Last change on this file since 70286 was 69105, checked in by vboxsync, 7 years ago

include/iprt/: (C) year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.7 KB
Line 
1/** @file
2 * IPRT - Message Formatting.
3 */
4
5/*
6 * Copyright (C) 2009-2017 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_msg_h
27#define ___iprt_msg_h
28
29#include <iprt/cdefs.h>
30#include <iprt/types.h>
31#include <iprt/stdarg.h>
32
33RT_C_DECLS_BEGIN
34
35/** @defgroup grp_rt_msg RTMsg - Message Formatting
36 * @ingroup grp_rt
37 * @{
38 */
39
40/**
41 * Sets the program name to use.
42 *
43 * @returns IPRT status code.
44 * @param pszFormat The program name format string.
45 * @param ... Format arguments.
46 */
47RTDECL(int) RTMsgSetProgName(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
48
49/**
50 * Print error message to standard error.
51 *
52 * The message will be prefixed with the file name part of process image name
53 * (i.e. no path) and "error: ". If the message doesn't end with a new line,
54 * one will be added. The caller should call this with an empty string if
55 * unsure whether the cursor is currently position at the start of a new line.
56 *
57 * @returns IPRT status code.
58 * @param pszFormat The message format string.
59 * @param ... Format arguments.
60 */
61RTDECL(int) RTMsgError(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
62
63/**
64 * Print error message to standard error.
65 *
66 * The message will be prefixed with the file name part of process image name
67 * (i.e. no path) and "error: ". If the message doesn't end with a new line,
68 * one will be added. The caller should call this with an empty string if
69 * unsure whether the cursor is currently position at the start of a new line.
70 *
71 * @returns IPRT status code.
72 * @param pszFormat The message format string.
73 * @param va Format arguments.
74 */
75RTDECL(int) RTMsgErrorV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
76
77/**
78 * Same as RTMsgError() except for the return value.
79 *
80 * @returns @a enmExitCode
81 * @param enmExitCode What to exit code to return. This is mainly for
82 * saving some vertical space in the source file.
83 * @param pszFormat The message format string.
84 * @param ... Format arguments.
85 */
86RTDECL(RTEXITCODE) RTMsgErrorExit(RTEXITCODE enmExitCode, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
87
88/**
89 * Same as RTMsgErrorV() except for the return value.
90 *
91 * @returns @a enmExitCode
92 * @param enmExitCode What to exit code to return. This is mainly for
93 * saving some vertical space in the source file.
94 * @param pszFormat The message format string.
95 * @param va Format arguments.
96 */
97RTDECL(RTEXITCODE) RTMsgErrorExitV(RTEXITCODE enmExitCode, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
98
99/**
100 * Same as RTMsgError() except for always returning RTEXITCODE_FAILURE.
101 *
102 * @returns RTEXITCODE_FAILURE
103 * @param pszFormat The message format string.
104 * @param ... Format arguments.
105 */
106RTDECL(RTEXITCODE) RTMsgErrorExitFailure(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
107
108/**
109 * Same as RTMsgErrorV() except for always returning RTEXITCODE_FAILURE.
110 *
111 * @returns RTEXITCODE_FAILURE
112 * @param pszFormat The message format string.
113 * @param va Format arguments.
114 */
115RTDECL(RTEXITCODE) RTMsgErrorExitFailureV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
116
117/**
118 * Same as RTMsgError() except for the return value.
119 *
120 * @returns @a rcRet
121 * @param rcRet What IPRT status to return. This is mainly for
122 * saving some vertical space in the source file.
123 * @param pszFormat The message format string.
124 * @param ... Format arguments.
125 */
126RTDECL(int) RTMsgErrorRc(int rcRet, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
127
128/**
129 * Same as RTMsgErrorV() except for the return value.
130 *
131 * @returns @a rcRet
132 * @param rcRet What IPRT status to return. This is mainly for
133 * saving some vertical space in the source file.
134 * @param pszFormat The message format string.
135 * @param va Format arguments.
136 */
137RTDECL(int) RTMsgErrorRcV(int rcRet, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
138
139/**
140 * Print an error message for a RTR3Init failure and suggest an exit code.
141 *
142 * @code
143 *
144 * int rc = RTR3Init();
145 * if (RT_FAILURE(rc))
146 * return RTMsgInitFailure(rc);
147 *
148 * @endcode
149 *
150 * @returns Appropriate exit code.
151 * @param rcRTR3Init The status code returned by RTR3Init.
152 */
153RTDECL(RTEXITCODE) RTMsgInitFailure(int rcRTR3Init);
154
155/**
156 * Print informational message to standard error.
157 *
158 * The message will be prefixed with the file name part of process image name
159 * (i.e. no path) and "warning: ". If the message doesn't end with a new line,
160 * one will be added. The caller should call this with an empty string if
161 * unsure whether the cursor is currently position at the start of a new line.
162 *
163 * @returns IPRT status code.
164 * @param pszFormat The message format string.
165 * @param ... Format arguments.
166 */
167RTDECL(int) RTMsgWarning(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
168
169/**
170 * Print informational message to standard error.
171 *
172 * The message will be prefixed with the file name part of process image name
173 * (i.e. no path) and "warning: ". If the message doesn't end with a new line,
174 * one will be added. The caller should call this with an empty string if
175 * unsure whether the cursor is currently position at the start of a new line.
176 *
177 * @returns IPRT status code.
178 * @param pszFormat The message format string.
179 * @param va Format arguments.
180 */
181RTDECL(int) RTMsgWarningV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
182
183/**
184 * Print informational message to standard output.
185 *
186 * The message will be prefixed with the file name part of process image name
187 * (i.e. no path) and "info: ". If the message doesn't end with a new line,
188 * one will be added. The caller should call this with an empty string if
189 * unsure whether the cursor is currently position at the start of a new line.
190 *
191 * @returns IPRT status code.
192 * @param pszFormat The message format string.
193 * @param ... Format arguments.
194 */
195RTDECL(int) RTMsgInfo(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
196
197/**
198 * Print informational message to standard output.
199 *
200 * The message will be prefixed with the file name part of process image name
201 * (i.e. no path) and "info: ". If the message doesn't end with a new line,
202 * one will be added. The caller should call this with an empty string if
203 * unsure whether the cursor is currently position at the start of a new line.
204 *
205 * @returns IPRT status code.
206 * @param pszFormat The message format string.
207 * @param va Format arguments.
208 */
209RTDECL(int) RTMsgInfoV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
210
211
212
213/** @defgroup grp_rt_msg_refentry Help generated from refentry/manpage.
214 *
215 * The refentry/manpage docbook source in doc/manual/en_US/man_* is processed by
216 * doc/manual/docbook-refentry-to-C-help.xsl and turned a set of the structures
217 * defined here.
218 *
219 * @{
220 */
221
222/** The non-breaking space character.
223 * @remarks We could've used U+00A0, but it is easier both to encode and to
224 * search and replace a single ASCII character. */
225#define RTMSGREFENTRY_NBSP '\b'
226
227/** @name REFENTRYSTR_SCOPE_XXX - Common string scoping and flags.
228 * @{ */
229/** Same scope as previous string table entry, flags are reset and can be
230 * ORed in. */
231#define RTMSGREFENTRYSTR_SCOPE_SAME UINT64_C(0)
232/** Global scope. */
233#define RTMSGREFENTRYSTR_SCOPE_GLOBAL UINT64_C(0x00ffffffffffffff)
234/** Scope mask. */
235#define RTMSGREFENTRYSTR_SCOPE_MASK UINT64_C(0x00ffffffffffffff)
236/** Flags mask. */
237#define RTMSGREFENTRYSTR_FLAGS_MASK UINT64_C(0xff00000000000000)
238/** Command synopsis, special hanging indent rules applies. */
239#define RTMSGREFENTRYSTR_FLAGS_SYNOPSIS RT_BIT_64(63)
240/** @} */
241
242/** String table entry for a refentry. */
243typedef struct RTMSGREFENTRYSTR
244{
245 /** The scope of the string. There are two predefined scopes,
246 * REFENTRYSTR_SCOPE_SAME and REFENTRYSTR_SCOPE_GLOBAL. The rest are
247 * reference entry specific. */
248 uint64_t fScope;
249 /** The string. Non-breaking space is represented by the char
250 * REFENTRY_NBSP defines, just in case the string needs wrapping. There is
251 * no trailing newline, that's implicit. */
252 const char *psz;
253} RTMSGREFENTRYSTR;
254/** Pointer to a read-only string table entry. */
255typedef const RTMSGREFENTRYSTR *PCRTMSGREFENTRYSTR;
256
257/** Refentry string table. */
258typedef struct RTMSGREFENTRYSTRTAB
259{
260 /** Number of strings. */
261 uint16_t cStrings;
262 /** Reserved for future use. */
263 uint16_t fReserved;
264 /** Pointer to the string table. */
265 PCRTMSGREFENTRYSTR paStrings;
266} RTMSGREFENTRYSTRTAB;
267/** Pointer to a read-only string table. */
268typedef RTMSGREFENTRYSTRTAB const *PCRTMSGREFENTRYSTRTAB;
269
270/**
271 * Help extracted from a docbook refentry document.
272 */
273typedef struct RTMSGREFENTRY
274{
275 /** Internal reference entry identifier. */
276 int64_t idInternal;
277 /** Usage synopsis. */
278 RTMSGREFENTRYSTRTAB Synopsis;
279 /** Full help. */
280 RTMSGREFENTRYSTRTAB Help;
281 /** Brief command description. */
282 const char *pszBrief;
283} RTMSGREFENTRY;
284/** Pointer to a read-only refentry help extract structure. */
285typedef RTMSGREFENTRY const *PCRTMSGREFENTRY;
286
287
288typedef struct RTSTREAM *PRTSTREAM;
289
290
291/**
292 * Print the synopsis to the given stream.
293 *
294 * @returns Current number of pending blank lines.
295 * @param pStrm The output stream.
296 * @param pEntry The refentry to print the help for.
297 */
298RTDECL(int) RTMsgRefEntrySynopsis(PRTSTREAM pStrm, PCRTMSGREFENTRY pEntry);
299
300
301/**
302 * Print the synopsis to the given stream.
303 *
304 * @returns Current number of pending blank lines.
305 * @param pStrm The output stream.
306 * @param pEntry The refentry to print the help for.
307 * @param fScope The scope inclusion mask.
308 * @param fFlags RTMSGREFENTRY_SYNOPSIS_F_XXX.
309 */
310RTDECL(int) RTMsgRefEntrySynopsisEx(PRTSTREAM pStrm, PCRTMSGREFENTRY pEntry, uint64_t fScope, uint32_t fFlags);
311/** @name RTMSGREFENTRY_SYNOPSIS_F_XXX - Flags for RTMsgRefEntrySynopsisEx.
312 * @{ */
313/** Prefix the output with 'Usage:'. */
314#define RTMSGREFENTRY_SYNOPSIS_F_USAGE RT_BIT_32(0)
315/** @} */
316
317
318/**
319 * Print the help text to the given stream.
320 *
321 * @returns Current number of pending blank lines.
322 * @param pStrm The output stream.
323 * @param pEntry The refentry to print the help for.
324 */
325RTDECL(int) RTMsgRefEntryHelp(PRTSTREAM pStrm, PCRTMSGREFENTRY pEntry);
326
327/**
328 * Print the help text to the given stream, extended version.
329 *
330 * @returns Current number of pending blank lines.
331 * @param pStrm The output stream.
332 * @param pEntry The refentry to print the help for.
333 * @param fScope The scope inclusion mask.
334 * @param fFlags Reserved, MBZ.
335 */
336RTDECL(int) RTMsgRefEntryHelpEx(PRTSTREAM pStrm, PCRTMSGREFENTRY pEntry, uint64_t fScope, uint32_t fFlags);
337
338/**
339 * Prints a string table.
340 *
341 * @returns Current number of pending blank lines.
342 * @param pStrm The output stream.
343 * @param pStrTab The string table.
344 * @param fScope The selection scope.
345 * @param pcPendingBlankLines In: Pending blank lines from previous string
346 * table. Out: Pending blank lines.
347 * @param pcLinesWritten Pointer to variable that should be incremented
348 * by the number of lines written. Optional.
349 */
350RTDECL(int) RTMsgRefEntryPrintStringTable(PRTSTREAM pStrm, PCRTMSGREFENTRYSTRTAB pStrTab, uint64_t fScope,
351 uint32_t *pcPendingBlankLines, uint32_t *pcLinesWritten);
352
353/** @} */
354
355
356/** @} */
357
358RT_C_DECLS_END
359
360#endif
361
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette