1071ca66eSYuri Pankov.\" 2071ca66eSYuri Pankov.\" This file and its contents are supplied under the terms of the 3071ca66eSYuri Pankov.\" Common Development and Distribution License ("CDDL"), version 1.0. 4071ca66eSYuri Pankov.\" You may only use this file in accordance with the terms of version 5071ca66eSYuri Pankov.\" 1.0 of the CDDL. 6071ca66eSYuri Pankov.\" 7071ca66eSYuri Pankov.\" A full copy of the text of the CDDL should have accompanied this 8071ca66eSYuri Pankov.\" source. A copy of the CDDL is also available via the Internet at 9071ca66eSYuri Pankov.\" http://www.illumos.org/license/CDDL. 10071ca66eSYuri Pankov.\" 11071ca66eSYuri Pankov.\" 12071ca66eSYuri Pankov.\" Copyright 2010 Sun Microsystems, Inc. All rights reserved. 13071ca66eSYuri Pankov.\" Copyright 2017 Nexenta Systems, Inc. 14071ca66eSYuri Pankov.\" 15071ca66eSYuri Pankov.Dd June 1, 2017 16071ca66eSYuri Pankov.Dt OFMT 3OFMT 17071ca66eSYuri Pankov.Os 18071ca66eSYuri Pankov.Sh NAME 19071ca66eSYuri Pankov.Nm ofmt_open , 20071ca66eSYuri Pankov.Nm ofmt_print , 21071ca66eSYuri Pankov.Nm ofmt_update_winsize , 22071ca66eSYuri Pankov.Nm ofmt_strerror , 23071ca66eSYuri Pankov.Nm ofmt_close 24071ca66eSYuri Pankov.Nd data structures and routines for printing output 25071ca66eSYuri Pankov.Sh LIBRARY 26071ca66eSYuri Pankov.Lb libofmt 27071ca66eSYuri Pankov.Sh SYNOPSIS 28071ca66eSYuri Pankov.In ofmt.h 29071ca66eSYuri Pankov.Ft ofmt_status_t 30071ca66eSYuri Pankov.Fo ofmt_open 31071ca66eSYuri Pankov.Fa "const char *fields" 32071ca66eSYuri Pankov.Fa "const ofmt_field_t *template" 33071ca66eSYuri Pankov.Fa "uint_t flags" 34071ca66eSYuri Pankov.Fa "uint_t maxcols" 35071ca66eSYuri Pankov.Fa "ofmt_handle_t *ofmt" 36071ca66eSYuri Pankov.Fc 37071ca66eSYuri Pankov.Ft void 38071ca66eSYuri Pankov.Fo ofmt_print 39071ca66eSYuri Pankov.Fa "ofmt_handle_t ofmt" 40071ca66eSYuri Pankov.Fa "void *cbarg" 41071ca66eSYuri Pankov.Fc 42071ca66eSYuri Pankov.Ft void 43071ca66eSYuri Pankov.Fo ofmt_update_winsize 44071ca66eSYuri Pankov.Fa "ofmt_handle_t ofmt" 45071ca66eSYuri Pankov.Fc 46071ca66eSYuri Pankov.Ft "char *" 47071ca66eSYuri Pankov.Fo ofmt_strerror 48071ca66eSYuri Pankov.Fa "ofmt_handle_t ofmt" 49071ca66eSYuri Pankov.Fa "ofmt_status_t error" 50071ca66eSYuri Pankov.Fa "char *buf" 51071ca66eSYuri Pankov.Fa "uint_t bufsize" 52071ca66eSYuri Pankov.Fc 53071ca66eSYuri Pankov.Ft void 54071ca66eSYuri Pankov.Fo ofmt_close 55071ca66eSYuri Pankov.Fa "ofmt_handle_t ofmt" 56071ca66eSYuri Pankov.Fc 57071ca66eSYuri Pankov.Sh DESCRIPTION 58071ca66eSYuri PankovThe 59071ca66eSYuri Pankov.Nm libofmt 60071ca66eSYuri Pankovlibrary provides data structures and routines for printing output. 61071ca66eSYuri Pankov.Pp 62071ca66eSYuri PankovCurrently this is an internal interface. 63071ca66eSYuri PankovThe interface can and will change without notice as the project needs, at any 64071ca66eSYuri Pankovtime. 65071ca66eSYuri Pankov.Pp 66071ca66eSYuri PankovAll output is assumed to be in a columnar format, where each column represents 67071ca66eSYuri Pankova field to be printed out. 68071ca66eSYuri PankovMultiple fields in parsable output are separated by 69071ca66eSYuri Pankov.Sq \&: , 70071ca66eSYuri Pankovwith the 71071ca66eSYuri Pankov.Sq \&: 72071ca66eSYuri Pankovcharacter itself escaped by a 73071ca66eSYuri Pankov.Sq \e 74071ca66eSYuri Pankov.Po e.g., IPv6 addresses may be printed as 75071ca66eSYuri Pankov.Qq fe80\e:\e:1 76071ca66eSYuri Pankov.Pc ; 77071ca66eSYuri Pankovsingle field output is printed as-is. 78071ca66eSYuri PankovIn multiline mode, every 79071ca66eSYuri Pankov.Bq field,value 80071ca66eSYuri Pankovpair is printed in a line of its own, thus: 81071ca66eSYuri Pankov.Qq field: value . 82071ca66eSYuri Pankov.Ss Data Structures 83071ca66eSYuri PankovThe 84071ca66eSYuri Pankov.Vt ofmt_field_t 85071ca66eSYuri Pankovdata structure used in 86071ca66eSYuri Pankov.Sx ofmt_open 87071ca66eSYuri Pankovis defined as follows: 88071ca66eSYuri Pankov.Bd -literal 89071ca66eSYuri Pankovtypedef struct ofmt_field_s { 90071ca66eSYuri Pankov char *of_name; /* column name */ 91071ca66eSYuri Pankov uint_t of_width; /* output column width */ 92071ca66eSYuri Pankov uint_t of_id; /* implementation specific cookie */ 93071ca66eSYuri Pankov ofmt_cb_t *of_cb; /* callback function defined by caller */ 94071ca66eSYuri Pankov} ofmt_field_t; 95071ca66eSYuri Pankov.Ed 96071ca66eSYuri Pankov.Pp 97071ca66eSYuri PankovThe 98071ca66eSYuri Pankov.Vt ofmt_arg_t 99071ca66eSYuri Pankovdata structure which is passed to callback function is defined as follows: 100071ca66eSYuri Pankov.Bd -literal 101071ca66eSYuri Pankovtypedef struct ofmt_arg_s { 102071ca66eSYuri Pankov uint_t ofmt_id; /* implementation specific cookie */ 103071ca66eSYuri Pankov uint_t ofmt_width; /* output column width */ 104071ca66eSYuri Pankov uint_t ofmt_index; /* unused */ 105071ca66eSYuri Pankov void *ofmt_cbarg; /* argument passed to ofmt_print() */ 106071ca66eSYuri Pankov} ofmt_arg_t; 107071ca66eSYuri Pankov.Ed 108071ca66eSYuri Pankov.Ss Fn ofmt_open 109071ca66eSYuri PankovThe 110071ca66eSYuri Pankov.Fn ofmt_open 111071ca66eSYuri Pankovfunction opens a handle returned in 112071ca66eSYuri Pankov.Fa ofmt 113071ca66eSYuri Pankovfor each set of fields to be printed. 114071ca66eSYuri Pankov.Pp 115071ca66eSYuri Pankov.Fa fields 116071ca66eSYuri Pankovis a comma-separated list of the fields that have been selected for output 117071ca66eSYuri Pankov.Po typically the string passed to 118071ca66eSYuri Pankov.Fl o 119071ca66eSYuri Pankovin the command-line 120071ca66eSYuri Pankov.Pc . 121071ca66eSYuri PankovColumns selected for output are identified by a match between the 122071ca66eSYuri Pankov.Va of_name 123071ca66eSYuri Pankovvalue in the 124071ca66eSYuri Pankov.Fa template 125071ca66eSYuri Pankovand the 126071ca66eSYuri Pankov.Fa fields 127071ca66eSYuri Pankovrequested. 128071ca66eSYuri PankovIn human-friendly 129071ca66eSYuri Pankov.Pq non machine-parsable 130071ca66eSYuri Pankovmode, 131071ca66eSYuri Pankov.Dv NULL 132071ca66eSYuri Pankov.Fa fields , 133071ca66eSYuri Pankovor a value of 134071ca66eSYuri Pankov.Qq all 135071ca66eSYuri Pankovis treated as a request to print all allowable fields that fit other applicable 136071ca66eSYuri Pankovconstraints. 137071ca66eSYuri Pankov.Pp 138071ca66eSYuri Pankov.Fa template 139071ca66eSYuri Pankovspecifies the list of supported fields, along with formatting information 140071ca66eSYuri Pankov.Pq e.g., field width , 141071ca66eSYuri Pankovand a pointer to a callback function that can provide a string representation of 142071ca66eSYuri Pankovthe value to be printed out. 143071ca66eSYuri PankovThe set of supported fields must be a 144071ca66eSYuri Pankov.Dv NULL 145071ca66eSYuri Pankovterminated array of type 146071ca66eSYuri Pankov.Vt ofmt_field_t , 147071ca66eSYuri Pankovdescribed in 148071ca66eSYuri Pankov.Sx Data Structures , 149071ca66eSYuri Pankovas follows: 150071ca66eSYuri Pankov.Bd -literal -offset indent 151071ca66eSYuri Pankov{<of_name>, <of_width>, <of_id>, <of_cb> }, 152071ca66eSYuri Pankov\&.\&.\&. 153071ca66eSYuri Pankov{<of_name>, <of_width>, <of_id>, <of_cb> }, 154071ca66eSYuri Pankov{NULL, 0, 0, NULL} 155071ca66eSYuri Pankov.Ed 156071ca66eSYuri Pankov.Pp 157071ca66eSYuri Pankov.Va of_cb 158071ca66eSYuri Pankovis the application-specified callback function with the following prototype that 159071ca66eSYuri Pankovprovides a string representation of the value to be printed for the field: 160071ca66eSYuri Pankov.Bd -literal -offset indent 161071ca66eSYuri Pankov(*of_cb)(ofmt_arg_t *ofmt_arg, char *buf, uint_t bufsize) 162071ca66eSYuri Pankov.Ed 163071ca66eSYuri Pankov.Pp 164071ca66eSYuri PankovThe interpretation of the 165071ca66eSYuri Pankov.Va of_id 166071ca66eSYuri Pankovfield is completely private to the caller, and can be optionally used by the 167071ca66eSYuri Pankovcallback function as a cookie to identify the field being printed when a single 168071ca66eSYuri Pankovcallback function is shared between multiple 169071ca66eSYuri Pankov.Fa template 170071ca66eSYuri Pankoventries. 171071ca66eSYuri Pankov.Pp 172071ca66eSYuri PankovThe 173071ca66eSYuri Pankov.Fa flags 174071ca66eSYuri Pankovcan be any valid combination of the following: 175071ca66eSYuri Pankov.Pp 176071ca66eSYuri Pankov.Bl -tag -width "OFMT_MULTILINE" -compact 177071ca66eSYuri Pankov.It Dv OFMT_PARSABLE 178071ca66eSYuri PankovMachine-parsable mode. 179071ca66eSYuri PankovSpecifying a null or empty 180071ca66eSYuri Pankov.Va fields 181071ca66eSYuri Pankovin the machine-parsable mode will result in a returned error value of 182071ca66eSYuri Pankov.Dv OFMT_EPARSENONE . 183071ca66eSYuri PankovAn attempt to create a handle in machine-parsable mode with the 184071ca66eSYuri Pankov.Fa fields 185071ca66eSYuri Pankovset to 186071ca66eSYuri Pankov.Qq all 187071ca66eSYuri Pankovwill result in a returned error value of 188071ca66eSYuri Pankov.Dv OFMT_EPARSEALL . 189071ca66eSYuri Pankov.It Dv OFMT_WRAP 190071ca66eSYuri PankovWrap output if field width is exceeded. 191071ca66eSYuri PankovCurrently output is wrapped at whitespace or comma characters. 192071ca66eSYuri Pankov.It Dv OFMT_MULTILINE 193071ca66eSYuri PankovMultiline mode. 194071ca66eSYuri PankovSpecifying both 195071ca66eSYuri Pankov.Dv OFMT_MULTILINE 196071ca66eSYuri Pankovand 197071ca66eSYuri Pankov.Dv OFMT_PARSABLE 198071ca66eSYuri Pankovwill result in 199071ca66eSYuri Pankov.Dv OFMT_EPARSEMULTI . 200071ca66eSYuri Pankov.It Dv OFMT_RIGHTJUST 201071ca66eSYuri PankovRight justified output. 202071ca66eSYuri Pankov.El 203071ca66eSYuri Pankov.Pp 204071ca66eSYuri PankovThe non-zero 205071ca66eSYuri Pankov.Fa maxcols 206071ca66eSYuri Pankovlimits the number of output columns. 207071ca66eSYuri Pankov.Ss Fn ofmt_print 208071ca66eSYuri PankovThe 209071ca66eSYuri Pankov.Fn ofmt_print 210071ca66eSYuri Pankovfunction prints a row of output. 211071ca66eSYuri Pankov.Pp 212071ca66eSYuri Pankov.Fa cbarg 213071ca66eSYuri Pankovpoints at the arguments to be passed to the callback function for each column in 214071ca66eSYuri Pankovthe row. 215071ca66eSYuri PankovThe call to 216071ca66eSYuri Pankov.Fn ofmt_print 217071ca66eSYuri Pankovwill result in the callback function of each selected field invoked with 218071ca66eSYuri Pankov.Va of_id , 219071ca66eSYuri Pankov.Va of_width 220071ca66eSYuri Pankovand 221071ca66eSYuri Pankov.Fa cbarg 222071ca66eSYuri Pankovembedded in 223071ca66eSYuri Pankov.Fa ofmt_arg , 224071ca66eSYuri Pankovdescribed in 225071ca66eSYuri Pankov.Sx Data Structures . 226071ca66eSYuri Pankov.Pp 227071ca66eSYuri PankovThe callback function should fill 228071ca66eSYuri Pankov.Fa buf 229071ca66eSYuri Pankovwith the string to be printed for the field using the data in 230071ca66eSYuri Pankov.Fa cbarg . 231071ca66eSYuri Pankov.Ss Fn ofmt_update_winsize 232071ca66eSYuri PankovThe 233071ca66eSYuri Pankov.Fn ofmt_update_winsize 234071ca66eSYuri Pankovfunction updates the window size information 235071ca66eSYuri Pankov.Pq which is initially computed when the handle is created 236071ca66eSYuri Pankovin the 237071ca66eSYuri Pankov.Fa ofmt . 238071ca66eSYuri PankovIf the 239071ca66eSYuri Pankov.Dv TIOCGWINSZ 240071ca66eSYuri Pankovioctl fails, the window size is set to 80x24. 241071ca66eSYuri Pankov.Ss Fn ofmt_strerror 242071ca66eSYuri PankovThe 243071ca66eSYuri Pankov.Fn ofmt_strerror 244071ca66eSYuri Pankovfunction returns error diagnostics in 245071ca66eSYuri Pankov.Fa buf 246071ca66eSYuri Pankovusing the information in the 247071ca66eSYuri Pankov.Fa ofmt 248071ca66eSYuri Pankovand 249071ca66eSYuri Pankov.Fa error . 250071ca66eSYuri Pankov.Pp 251071ca66eSYuri PankovUsing a 252071ca66eSYuri Pankov.Fa buf 253071ca66eSYuri Pankovsize of 254071ca66eSYuri Pankov.Dv OFMT_BUFSIZE 255071ca66eSYuri Pankovis recommended. 256071ca66eSYuri Pankov.Ss Fn ofmt_close 257071ca66eSYuri PankovThe 258071ca66eSYuri Pankov.Fn ofmt_close 259071ca66eSYuri Pankovfunction frees any resources allocated for the handle after printing is 260071ca66eSYuri Pankovcompleted. 261071ca66eSYuri Pankov.Sh RETURN VALUES 262071ca66eSYuri PankovIf successful, the 263071ca66eSYuri Pankov.Fn ofmt_open 264071ca66eSYuri Pankovfunction will return 265071ca66eSYuri Pankov.Dv OFMT_SUCCESS , 266071ca66eSYuri Pankovwith a non-null 267071ca66eSYuri Pankov.Fa ofmt_handle . 268071ca66eSYuri PankovThe function returns one of the failure codes 269071ca66eSYuri Pankov.Po enumerated in 270071ca66eSYuri Pankov.Vt ofmt_status_t 271071ca66eSYuri Pankov.Pc 272071ca66eSYuri Pankovlisted below otherwise: 273071ca66eSYuri Pankov.Pp 274071ca66eSYuri Pankov.Bl -tag -width "OFMT_ENOTEMPLATE" -compact 275071ca66eSYuri Pankov.It Dv OFMT_ENOMEM 276071ca66eSYuri Pankovout of memory 277071ca66eSYuri Pankov.It Dv OFMT_EBADFIELDS 278071ca66eSYuri Pankovone or more bad fields with good fields 279071ca66eSYuri Pankov.It Dv OFMT_ENOFIELDS 280071ca66eSYuri Pankovno valid output fields 281071ca66eSYuri Pankov.It Dv OFMT_EPARSEALL 282071ca66eSYuri Pankov"all" is invalid in parsable mode 283071ca66eSYuri Pankov.It Dv OFMT_EPARSENONE 284071ca66eSYuri Pankovoutput fields missing in parsable mode 285071ca66eSYuri Pankov.It Dv OFMT_EPARSEWRAP 286071ca66eSYuri Pankovparsable mode incompatible with wrap mode 287071ca66eSYuri Pankov.It Dv OFMT_ENOTEMPLATE 288071ca66eSYuri Pankovno template provided for fields 289071ca66eSYuri Pankov.It Dv OFMT_EPARSEMULTI 290071ca66eSYuri Pankovparsable and multiline don't mix 291071ca66eSYuri Pankov.El 292071ca66eSYuri Pankov.Pp 293071ca66eSYuri PankovMore information about the type of failure can be obtained by calling 294071ca66eSYuri Pankov.Fn ofmt_strerror . 295071ca66eSYuri Pankov.Pp 296071ca66eSYuri PankovThe 297071ca66eSYuri Pankov.Fn ofmt_strerror 298071ca66eSYuri Pankovfunction returns the 299071ca66eSYuri Pankov.Fa buf . 300071ca66eSYuri Pankov.Sh INTERFACE STABILITY 301071ca66eSYuri Pankov.Sy Private . 302071ca66eSYuri Pankov.Sh SEE ALSO 303071ca66eSYuri Pankov.Xr ioctl 2 , 304071ca66eSYuri Pankov.Xr strerror 3C , 305071ca66eSYuri Pankov.Xr attributes 5 306