summaryrefslogtreecommitdiff
path: root/usr/src/man/man3c/fmtmsg.3c
blob: ad389bfa34e70bcea7e642c0ca629ab17432ba43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
'\" te
.\"  Copyright 1989 AT&T  Copyright (c) 2002, Sun Microsystems, Inc.  All Rights Reserved
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH FMTMSG 3C "Jul 24, 2002"
.SH NAME
fmtmsg \- display a message on stderr or system console
.SH SYNOPSIS
.LP
.nf
#include <fmtmsg.h>

\fBint\fR \fBfmtmsg\fR(\fBlong\fR \fIclassification\fR, \fBconst  char *\fR\fIlabel\fR, \fBint\fR \fIseverity\fR,
\fBconst char *\fR\fItext\fR, \fBconst char *\fR\fIaction\fR, \fBconst char *\fR\fItag\fR);
.fi

.SH DESCRIPTION
.sp
.LP
The \fBfmtmsg()\fR function writes a formatted message to \fBstderr\fR, to the
console, or to both, on a message's classification component. It can be used
instead of the traditional \fBprintf\fR(3C) interface to display messages to
\fBstderr\fR, and in conjunction with \fBgettxt\fR(3C), provides a simple
interface for producing language-independent applications.
.sp
.LP
A formatted message consists of up to five standard components ( \fIlabel\fR,
\fIseverity\fR, \fItext\fR, \fIaction\fR, and \fItag\fR) as described below.
The \fIclassification\fR component is not part of the standard message
displayed to the user, but rather defines the source of the message and directs
the display of the formatted message.
.sp
.ne 2
.na
\fB\fIclassification\fR\fR
.ad
.RS 18n
Contains identifiers from the following groups of major classifications and
subclassifications. Any one identifier from a subclass may be used in
combination by ORing the values together with a single identifier from a
different subclass. Two or more identifiers from the same subclass should not
be used together, with the exception of identifiers from the display subclass.
(Both display subclass identifiers may be used so that messages can be
displayed to both \fBstderr\fR and the system console).
.RS +4
.TP
.ie t \(bu
.el o
"Major classifications" identify the source of the condition. Identifiers are:
\fBMM_HARD\fR (hardware), \fBMM_SOFT\fR (software), and \fBMM_FIRM\fR
(firmware).
.RE
.RS +4
.TP
.ie t \(bu
.el o
"Message source subclassifications" identify the type of software in which the
problem is spotted. Identifiers are: \fBMM_APPL\fR (application), \fBMM_UTIL\fR
(utility), and \fBMM_OPSYS\fR (operating system).
.RE
.RS +4
.TP
.ie t \(bu
.el o
"Display subclassifications" indicate where the message is to be displayed.
Identifiers are: \fBMM_PRINT\fR to display the message on the standard error
stream, \fBMM_CONSOLE\fR to display the message on the system console. Neither,
either, or both identifiers may be used.
.RE
.RS +4
.TP
.ie t \(bu
.el o
"Status subclassifications" indicate whether the application will recover from
the condition. Identifiers are: \fBMM_RECOVER\fR (recoverable) and
\fBMM_NRECOV\fR (non-recoverable).
.RE
.RS +4
.TP
.ie t \(bu
.el o
An additional identifier, \fBMM_NULLMC\fR, indicates that no classification
component is supplied for the message.
.RE
.RE

.sp
.ne 2
.na
\fB\fIlabel\fR\fR
.ad
.RS 18n
Identifies the source of the message. The format of this component is two
fields separated by a colon. The first field is up to 10 characters long; the
second is up to 14 characters. Suggested usage is that \fIlabel\fR identifies
the package in which the application resides as well as the program or
application name. For example, the \fIlabel\fR \fBUX:cat\fR indicates the
\fBUNIX\fR System V package and the \fBcat\fR(1) utility.
.RE

.sp
.ne 2
.na
\fB\fIseverity\fR\fR
.ad
.RS 18n
Indicates the seriousness of the condition. Identifiers for the standard levels
of \fIseverity\fR are:
.RS +4
.TP
.ie t \(bu
.el o
\fBMM_HALT\fR indicates that the application has encountered a severe fault and
is halting. Produces the print string \fBHALT\fR.
.RE
.RS +4
.TP
.ie t \(bu
.el o
\fBMM_ERROR\fR indicates that the application has detected a fault. Produces
the print string \fBERROR\fR.
.RE
.RS +4
.TP
.ie t \(bu
.el o
\fBMM_WARNING\fR indicates a condition out of the ordinary that might be a
problem and should be watched. Produces the print string \fBWARNING\fR.
.RE
.RS +4
.TP
.ie t \(bu
.el o
\fBMM_INFO\fR provides information about a condition that is not in error.
Produces the print string \fBINFO\fR.
.RE
.RS +4
.TP
.ie t \(bu
.el o
\fBMM_NOSEV\fR indicates that no severity level is supplied for the message.
.RE
Other severity levels may be added by using the \fBaddseverity()\fR routine.
.RE

.sp
.ne 2
.na
\fB\fItext\fR\fR
.ad
.RS 18n
Describes the condition that produced the message. The \fItext\fR string is not
limited to a specific size.
.RE

.sp
.ne 2
.na
\fB\fIaction\fR\fR
.ad
.RS 18n
Describes the first step to be taken in the error recovery process.
\fBfmtmsg()\fR precedes each action string with the prefix: \fBTO\fRFIX\fB:.\fR
The \fIaction\fR string is not limited to a specific size.
.RE

.sp
.ne 2
.na
\fB\fItag\fR\fR
.ad
.RS 18n
An identifier which references on-line documentation for the message. Suggested
usage is that \fItag\fR includes the \fIlabel\fR and a unique identifying
number. A sample \fItag\fR is \fBUX:cat:146\fR.
.RE

.SS "Environment Variables"
.sp
.LP
The \fBMSGVERB\fR and \fBSEV_LEVEL\fR environment variables control the
behavior of \fBfmtmsg()\fR as follows:
.sp
.ne 2
.na
\fB\fBMSGVERB\fR\fR
.ad
.RS 13n
This variable determines which message components \fBfmtmsg()\fR selects when
writing messages to \fBstderr\fR. Its value is a colon-separated list of
optional keywords and can be set as follows:
.sp
.in +2
.nf
\fBMSGVERB=\fR[\fIkeyword\fR[\fB:\fR\fIkeyword\fR[\fB:\fR\|.\|.\|.]]]
\fBexport MSGVERB\fR
.fi
.in -2

Valid \fIkeywords\fR are: \fBlabel\fR, \fBseverity\fR, \fBtext\fR,
\fBaction\fR, and \fBtag\fR. If \fBMSGVERB\fR contains a keyword for a
component and the component's value is not the component's null value,
\fBfmtmsg()\fR includes that component in the message when writing the message
to \fBstderr\fR. If \fBMSGVERB\fR does not include a keyword for a message
component, that component is not included in the display of the message. The
keywords may appear in any order. If \fBMSGVERB\fR is not defined, if its value
is the null string, if its value is not of the correct format, or if it
contains keywords other than the valid ones listed above, \fBfmtmsg()\fR
selects all components.
.sp
The first time \fBfmtmsg()\fR is called, it examines \fBMSGVERB\fR to determine
which message components are to be selected when generating a message to write
to the standard error stream, \fBstderr\fR. The values accepted on the initial
call are saved for future calls.
.sp
The \fBMSGVERB\fR environment variable affects only those components that are
selected for display to the standard error stream. All message components are
included in console messages.
.RE

.sp
.ne 2
.na
\fB\fBSEV_LEVEL\fR\fR
.ad
.RS 13n
This variable defines severity levels and associates print strings with them
for use by \fBfmtmsg()\fR. The standard severity levels listed below cannot be
modified. Additional severity levels can also be defined, redefined, and
removed using \fBaddseverity()\fR (see \fBaddseverity\fR(3C)). If the same
severity level is defined by both \fBSEV_LEVEL\fR and \fBaddseverity()\fR, the
definition by \fBaddseverity()\fR takes precedence.
.sp
.ne 2
.na
\fB0\fR
.ad
.RS 5n
(no severity is used)
.RE

.sp
.ne 2
.na
\fB1\fR
.ad
.RS 5n
\fBHALT\fR
.RE

.sp
.ne 2
.na
\fB2\fR
.ad
.RS 5n
\fBERROR\fR
.RE

.sp
.ne 2
.na
\fB3\fR
.ad
.RS 5n
\fBWARNING\fR
.RE

.sp
.ne 2
.na
\fB4\fR
.ad
.RS 5n
\fBINFO\fR
.RE

The \fBSEV_LEVEL\fR variable can be set as follows:
.sp
.in +2
.nf
\fBSEV_LEVEL=\fR[\fIdescription\fR[\fB:\fR\fIdescription\fR[\fB:\fR\|.\|.\|.]]]
\fBexport SEV_LEVEL\fR
.fi
.in -2

where \fIdescription\fR is a comma-separated list containing three fields:
.sp
\fIdescription\fR=\fIseverity_keyword\fR,\fIlevel\fR,\fIprintstring\fR
.sp
The \fIseverity_keyword\fR field is a character string that is used as the
keyword on the \fB\fR\fB-s\fR\fB \fR\fIseverity\fR option to the
\fBfmtmsg\fR(1) utility. (This field is not used by the \fBfmtmsg()\fR
function.)
.sp
The \fIlevel\fR field is a character string that evaluates to a positive
integer (other than 0, 1, 2, 3, or 4, which are reserved for the standard
severity levels). If the keyword \fIseverity_keyword\fR is used, \fIlevel\fR is
the severity value passed on to the \fBfmtmsg()\fR function.
.sp
The \fIprintstring\fR field is the character string used by \fBfmtmsg()\fR in
the standard message format whenever the severity value \fIlevel\fR is used.
.sp
If a \fIdescription\fR in the colon list is not a three-field comma list, or if
the second field of a comma list does not evaluate to a positive integer, that
\fIdescription\fR in the colon list is ignored.
.sp
The first time \fBfmtmsg()\fR is called, it examines the \fBSEV_LEVEL\fR
environment variable, if defined, to determine whether the environment expands
the levels of severity beyond the five standard levels and those defined using
\fBaddseverity()\fR. The values accepted on the initial call are saved for
future calls.
.RE

.SS "Use in Applications"
.sp
.LP
One or more message components may be systematically omitted from messages
generated by an application by using the null value of the argument for that
component.
.sp
.LP
The table below indicates the null values and identifiers for \fBfmtmsg()\fR
arguments.
.sp

.sp
.TS
box;
l l l l
l l l l .
Argument	Type	Null-Value	Identifier
\fIlabel\fR	\fBchar*\fR	\fB(char*) NULL\fR	\fBMM_NULLLBL\fR
\fIseverity\fR	\fBint\fR	\fB0\fR	\fBMM_NULLSEV\fR
\fIclass\fR	\fBlong\fR	\fB0L\fR	\fBMM_NULLMC\fR
\fItext\fR	\fBchar*\fR	\fB(char*) NULL\fR	\fBMM_NULLTXT\fR
\fIaction\fR	\fBchar*\fR	\fB(char*) NULL\fR	\fBMM_NULLACT\fR
\fItag\fR	\fBchar*\fR	\fB(char*) NULL\fR	\fBMM_NULLTAG\fR
.TE

.sp
.LP
Another means of systematically omitting a component is by omitting the
component keyword(s) when defining the \fBMSGVERB\fR environment variable (see
the \fBEnvironment Variables\fR section above).
.SH RETURN VALUES
.sp
.LP
The \fBfmtmsg()\fR returns the following values:
.sp
.ne 2
.na
\fB\fBMM_OK\fR\fR
.ad
.RS 12n
The function succeeded.
.RE

.sp
.ne 2
.na
\fB\fBMM_NOTOK\fR\fR
.ad
.RS 12n
The function failed completely.
.RE

.sp
.ne 2
.na
\fB\fBMM_NOMSG\fR\fR
.ad
.RS 12n
The function was unable to generate a message on the standard error stream, but
otherwise succeeded.
.RE

.sp
.ne 2
.na
\fB\fBMM_NOCON\fR\fR
.ad
.RS 12n
The function was unable to generate a console message, but otherwise succeeded.
.RE

.SH EXAMPLES
.LP
\fBExample 1 \fRThe following example of \fBfmtmsg()\fR:
.sp
.in +2
.nf
fmtmsg(MM_PRINT, "UX:cat", MM_ERROR, "invalid syntax",
"refer to manual", "UX:cat:001")
.fi
.in -2

.sp
.LP
produces a complete message in the standard message format:

.sp
.in +2
.nf
UX:cat: ERROR: invalid syntax
TO FIX: refer to manual   UX:cat:001
.fi
.in -2

.LP
\fBExample 2 \fRWhen the environment variable \fBMSGVERB\fR is set as follows:
.sp
.in +2
.nf
MSGVERB=severity:text:action
.fi
.in -2

.sp
.LP
and the Example 1 is used, \fBfmtmsg()\fR produces:

.sp
.in +2
.nf
ERROR: invalid syntax
TO FIX: refer to manual
.fi
.in -2

.LP
\fBExample 3 \fRWhen the environment variable \fBSEV_LEVEL\fR is set as
follows:
.sp
.in +2
.nf
SEV_LEVEL=note,5,NOTE
.fi
.in -2

.sp
.LP
the following call to \fBfmtmsg()\fR

.sp
.in +2
.nf
fmtmsg(MM_UTIL | MM_PRINT, "UX:cat", 5, "invalid syntax",
"refer to manual", "UX:cat:001")
.fi
.in -2

.sp
.LP
produces

.sp
.in +2
.nf
UX:cat: NOTE: invalid syntax
TO FIX: refer to manual   UX:cat:001
.fi
.in -2

.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Standard
_
MT-Level	Safe
.TE

.SH SEE ALSO
.sp
.LP
\fBfmtmsg\fR(1), \fBaddseverity\fR(3C), \fBgettxt\fR(3C), \fBprintf\fR(3C),
\fBattributes\fR(5), \fBstandards\fR(5)