prtpicl.c revision da6837b3e07c5c71f29c61ce60821868f9fc3102
/*
* CDDL HEADER START
*
* 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
* 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]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <alloca.h>
#include <libintl.h>
#include <locale.h>
#include <unistd.h>
#include <assert.h>
#include <inttypes.h>
#include <picl.h>
/*
* Constant definitions and macros
*/
#define COL_DELIM "|"
#define ROOT_LEVEL 0
#define LEVEL_INDENT 4
#define PROP_INDENT 2
#define NCOLS 80
#define NODEINFO_LEFT_MARGIN(x) (x * LEVEL_INDENT)
#define PRIxPICLTBL PRIx64
#define PRIxPICLHDL PRIx64
/*
* Program variables
*/
static char *prog;
static int verbose_mode = 0;
/*
* Error codes
*/
#define EM_USAGE 0
#define EM_INIT 1
#define EM_GETROOT 2
#define EM_GETPVAL 3
#define EM_GETNXTBYCOL 4
#define EM_GETNXTBYROW 5
#define EM_GETPINFO 6
#define EM_GETPVALBYNAME 7
#define EM_GETPROPBYNAME 8
#define EM_INT_INVSIZE 9
#define EM_UINT_INVSIZE 10
#define EM_FLOAT_INVSIZE 11
#define EM_TS_INVALID 12
#define EM_TABLE_INVSIZE 13
#define EM_REF_INVSIZE 14
#define EM_TYPE_UNKNOWN 15
#define EM_TS_OVERFLOW 16
#define EM_TS_INVSIZE 17
/*
* Error mesage texts
*/
static char *err_msg[] = {
/* program usage */
"Usage: %s [-v] [-c <picl_class>]\n", /* 0 */
/* picl call failed messages */
"picl_initialize failed: %s\n", /* 1 */
"picl_get_root failed: %s\n", /* 2 */
"picl_get_propval failed: %s\n", /* 3 */
"picl_get_next_by_col failed: %s\n", /* 4 */
"picl_get_next_by_row failed: %s\n", /* 5 */
"picl_get_propinfo failed: %s\n", /* 6 */
"picl_get_propval_by_name failed: %s\n", /* 7 */
"picl_get_prop_by_name failed: %s\n", /* 8 */
/* invalid data error messages */
"picl_get_propval: invalid int size %d\n", /* 9 */
"picl_get_propval: invalid unsigned int size %d\n", /* 10 */
"picl_get_propval: invalid float size %d\n", /* 11 */
"picl_get_propval: invalid timestamp\n", /* 12 */
"picl_get_propval: invalid table handle size %d\n", /* 13 */
"picl_get_propval: invalid reference size %d\n", /* 14 */
"picl_get_propval: unknown type\n", /* 15 */
"picl_get_propval: timestamp value too large\n", /* 16 */
"picl_get_propval: invalid timestamp size\n" /* 17 */
};
/*PRINTFLIKE1*/
static void
print_errmsg(char *message, ...)
{
}
/*
* Print prtpicl usage
*/
static void
usage(void)
{
exit(1);
}
/*
* print a bytearray value and format it to fit in 80 columns
*/
static void
{
int cnum;
int columns;
char *s;
size_t i;
/*
* The COLUMNS_PER_BYTE is set to 4 to match the printf
* format used below, i.e. " %02x ", to print a byte
*/
#define COLUMNS_PER_BYTE 4
/*
* Kind of a hack to determine the width of the output...
*/
(void) printf("\n");
cnum = 0;
}
for (i = 0; i < nbytes; ++i) {
(void) printf("\n");
cnum = 0;
}
cnum += COLUMNS_PER_BYTE;
}
}
/*
* Print a property's value
* If the property is read protected, return success.
* other errors, print a message and return success.
*/
static int
{
int err;
void *vbuf;
char *str;
/*
* If property is read protected, print a message and continue
*/
return (PICL_SUCCESS);
}
return (PICL_SUCCESS);
/*
*/
(err == PICL_NORESPONSE))
return (err);
else if (err != PICL_SUCCESS) {
return (PICL_SUCCESS);
}
case PICL_PTYPE_CHARSTRING:
break;
case PICL_PTYPE_INT:
case sizeof (int8_t):
/* avoid using PRId8 until lint recognizes hh */
break;
case sizeof (int16_t):
break;
case sizeof (int32_t):
break;
case sizeof (int64_t):
break;
default:
return (PICL_FAILURE);
}
break;
case PICL_PTYPE_UNSIGNED_INT:
case sizeof (uint8_t):
/* avoid using PRIx8 until lint recognizes hh */
break;
case sizeof (uint16_t):
break;
case sizeof (uint32_t):
break;
case sizeof (uint64_t):
break;
default:
return (PICL_FAILURE);
}
break;
case PICL_PTYPE_FLOAT:
case sizeof (float):
break;
case sizeof (double):
break;
default:
return (PICL_FAILURE);
}
break;
case PICL_PTYPE_TIMESTAMP:
return (PICL_FAILURE);
}
return (PICL_FAILURE);
}
return (PICL_FAILURE);
}
break;
case PICL_PTYPE_TABLE:
return (PICL_FAILURE);
}
*(picl_prophdl_t *)vbuf);
break;
case PICL_PTYPE_REFERENCE:
return (PICL_FAILURE);
}
break;
case PICL_PTYPE_BYTEARRAY:
break;
default:
return (PICL_FAILURE);
}
return (PICL_SUCCESS);
}
/*
* print table property value
*/
static int
{
int err;
if (err != PICL_SUCCESS) {
picl_strerror(err));
return (err);
}
if (err != PICL_SUCCESS) {
picl_strerror(err));
return (err);
}
if (err != PICL_SUCCESS) {
picl_strerror(err));
return (err);
}
if (err != PICL_SUCCESS)
return (err);
}
(void) printf("\n");
}
return (PICL_SUCCESS);
}
/*
* Print the properties (name = value) of a node. If an error occurs
* when printing the property value, stop. print_propval() suppresses
* and no response errors.
*/
static int
{
int err;
if (err != PICL_SUCCESS) {
picl_strerror(err));
return (err);
}
else {
(void) printf("\n");
if (err != PICL_SUCCESS)
return (err);
}
/*
* Expand the table property
*/
if (err != PICL_SUCCESS) {
picl_strerror(err));
return (err);
}
if (err != PICL_SUCCESS)
return (err);
}
}
return (PICL_SUCCESS);
}
/*
* Recursively print the PICL tree
* When piclclass is specified, print only the nodes of that class.
*/
static int
{
char *nameval;
char classval[PICL_PROPNAMELEN_MAX];
int err;
/*
* First get the class name of the node to compare with piclclass
*/
sizeof (classval));
if (err != PICL_SUCCESS) {
picl_strerror(err));
return (err);
}
if (err != PICL_SUCCESS) {
picl_strerror(err));
return (err);
}
if (err != PICL_SUCCESS) {
picl_strerror(err));
return (err);
}
if (err != PICL_SUCCESS) {
picl_strerror(err));
return (err);
}
if (verbose_mode) {
if (err != PICL_SUCCESS)
return (err);
}
++lvl;
}
sizeof (picl_nodehdl_t))) {
if (err != PICL_SUCCESS) {
picl_strerror(err));
return (err);
}
if (err != PICL_SUCCESS)
return (err);
}
return (PICL_SUCCESS);
}
/*
* This program prints the PICL tree.
* If an invalid handle or stale handle is encountered while printing
* the tree, it starts over from the root node.
*/
int
{
int err;
int c;
int done;
char piclclass[PICL_CLASSNAMELEN_MAX];
int cflg;
(void) textdomain(TEXT_DOMAIN);
else
prog++;
cflg = 0;
switch (c) {
case 'v':
verbose_mode = 1;
break;
case 'c':
cflg = 1;
break;
case '?':
/*FALLTHROUGH*/
default:
usage();
/*NOTREACHED*/
}
}
usage();
err = picl_initialize();
if (err != PICL_SUCCESS) {
exit(1);
}
do {
done = 1;
if (err != PICL_SUCCESS) {
picl_strerror(err));
exit(1);
}
done = 0;
} while (!done);
(void) picl_shutdown();
return (0);
}