Print this page
11545 Want configurable output field separator for libofmt
Portions contributed by: Cody Peter Mello <cody.mello@joyent.com>
Reviewed by: Jason King <jason.king@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libofmt/common/ofmt.h
          +++ new/usr/src/lib/libofmt/common/ofmt.h
↓ open down ↓ 17 lines elided ↑ open up ↑
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25   25   */
  26   26  
  27   27  /*
       28 + * Copyright (c) 2015 by Delphix. All rights reserved.
  28   29   * Copyright 2017 Joyent, Inc.
  29   30   */
  30   31  
  31   32  #ifndef _OFMT_H
  32   33  #define _OFMT_H
  33   34  
  34   35  /*
  35   36   * Data structures and routines for printing output.
  36   37   *
  37   38   * All output is assumed to be in a columnar format, where each column
↓ open down ↓ 82 lines elided ↑ open up ↑
 120  121   *
 121  122   * The calling application should invoke ofmt_close(ofmt_handle) to free up any
 122  123   * resources allocated for the handle after all printing is completed.
 123  124   *
 124  125   * The printing library computes the current size of the output window when the
 125  126   * handle is first created. If the caller wishes to adjust the window size
 126  127   * after the handle has been created (e.g., on the reception of SIGWINCH by the
 127  128   * caller), the function ofmt_update_winsize(handle) may be called.
 128  129   */
 129  130  
 130      -#include <sys/types.h>
 131      -
 132  131  #ifdef __cplusplus
 133  132  extern "C" {
 134  133  #endif
 135  134  
      135 +#include <sys/types.h>
      136 +
 136  137  /*
 137  138   * Recommended buffer size for buffers passed, for example, to ofmt_strerror().
 138  139   */
 139  140  #define OFMT_BUFSIZE            256
 140  141  
 141  142  typedef enum {
 142  143          OFMT_SUCCESS = 0,
 143  144          OFMT_ENOMEM,            /* out of memory */
 144  145          OFMT_EBADFIELDS,        /* one or more bad fields with good fields */
 145  146          OFMT_ENOFIELDS,         /* no valid output fields */
↓ open down ↓ 34 lines elided ↑ open up ↑
 180  181   * for the handle are freed by ofmt_close();
 181  182   */
 182  183  typedef struct ofmt_state_s *ofmt_handle_t;
 183  184  extern ofmt_status_t ofmt_open(const char *, const ofmt_field_t *, uint_t,
 184  185      uint_t, ofmt_handle_t *);
 185  186  
 186  187  #define OFMT_PARSABLE   0x00000001 /* machine parsable mode */
 187  188  #define OFMT_WRAP       0x00000002 /* wrap output if field width is exceeded */
 188  189  #define OFMT_MULTILINE  0x00000004 /* "long" output: "name: value" lines */
 189  190  #define OFMT_RIGHTJUST  0x00000008 /* right justified output */
      191 +#define OFMT_NOHEADER   0x00000010 /* do not automatically print header lines */
 190  192  
 191  193  /*
 192  194   * ofmt_close() must be called to free resources associated
 193  195   * with the ofmt_handle_t
 194  196   */
 195  197  extern void ofmt_close(ofmt_handle_t);
 196  198  
 197  199  /*
      200 + * Set the field separator used in parsable output (default is ':').
      201 + */
      202 +extern void ofmt_set_fs(ofmt_handle_t, char);
      203 +
      204 +/*
 198  205   * ofmt_print() emits one row of output
 199  206   */
 200  207  extern void ofmt_print(ofmt_handle_t, void *);
 201  208  
 202  209  /*
      210 + * ofmt_print_header() prints the header line. It can be used with
      211 + * OFMT_NOHEADER to control exactly when the header gets printed.
      212 + */
      213 +extern void ofmt_print_header(ofmt_handle_t);
      214 +
      215 +/*
 203  216   * ofmt_update_winsize() updates the window size information for ofmt_handle_t
 204  217   */
 205  218  extern void ofmt_update_winsize(ofmt_handle_t);
 206  219  
 207  220  /*
 208  221   * ofmt_strerror() provides error diagnostics in the buffer that it is passed.
 209  222   */
 210  223  extern char *ofmt_strerror(ofmt_handle_t, ofmt_status_t, char *, uint_t);
 211  224  
 212  225  extern void ofmt_check(ofmt_status_t oferr, boolean_t parsable,
 213  226      ofmt_handle_t ofmt,
 214  227      void (*die)(const char *, ...), void (*warn)(const char *, ...));
 215  228  
 216  229  #ifdef __cplusplus
 217  230  }
 218  231  #endif
 219  232  
 220  233  #endif /* _OFMT_H */
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX