1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2002 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <libintl.h> 30*7c478bd9Sstevel@tonic-gate #include <locale.h> 31*7c478bd9Sstevel@tonic-gate #include <stdio.h> 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #include "libfru.h" 34*7c478bd9Sstevel@tonic-gate #include "prtfru.h" 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate static void 38*7c478bd9Sstevel@tonic-gate usage(const char *command) 39*7c478bd9Sstevel@tonic-gate { 40*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 41*7c478bd9Sstevel@tonic-gate gettext("Usage: %s [ -d ] | [ -clx ] [ container ]\n"), 42*7c478bd9Sstevel@tonic-gate command); 43*7c478bd9Sstevel@tonic-gate } 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate int 46*7c478bd9Sstevel@tonic-gate main(int argc, char *argv[]) 47*7c478bd9Sstevel@tonic-gate { 48*7c478bd9Sstevel@tonic-gate char *command = argv[0], *searchpath = NULL; 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate int containers_only = 0, dtd = 0, list_only = 0, nodtd = 0, option, 51*7c478bd9Sstevel@tonic-gate status, xml = 0; 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 55*7c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate opterr = 0; /* "getopt" should not print to "stderr" */ 58*7c478bd9Sstevel@tonic-gate while ((option = getopt(argc, argv, "cdlx")) != EOF) { 59*7c478bd9Sstevel@tonic-gate switch (option) { 60*7c478bd9Sstevel@tonic-gate case 'c': 61*7c478bd9Sstevel@tonic-gate containers_only = 1; 62*7c478bd9Sstevel@tonic-gate nodtd = 1; 63*7c478bd9Sstevel@tonic-gate break; 64*7c478bd9Sstevel@tonic-gate case 'd': 65*7c478bd9Sstevel@tonic-gate dtd = 1; 66*7c478bd9Sstevel@tonic-gate break; 67*7c478bd9Sstevel@tonic-gate case 'l': 68*7c478bd9Sstevel@tonic-gate list_only = 1; 69*7c478bd9Sstevel@tonic-gate nodtd = 1; 70*7c478bd9Sstevel@tonic-gate break; 71*7c478bd9Sstevel@tonic-gate case 'x': 72*7c478bd9Sstevel@tonic-gate xml = 1; 73*7c478bd9Sstevel@tonic-gate nodtd = 1; 74*7c478bd9Sstevel@tonic-gate break; 75*7c478bd9Sstevel@tonic-gate default: 76*7c478bd9Sstevel@tonic-gate usage(command); 77*7c478bd9Sstevel@tonic-gate return (1); 78*7c478bd9Sstevel@tonic-gate } 79*7c478bd9Sstevel@tonic-gate } 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate argc -= optind; 82*7c478bd9Sstevel@tonic-gate argv += optind; 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate if (dtd) { 85*7c478bd9Sstevel@tonic-gate if (nodtd || (argc > 0)) { 86*7c478bd9Sstevel@tonic-gate usage(command); 87*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 88*7c478bd9Sstevel@tonic-gate gettext("Specify \"-d\" alone\n")); 89*7c478bd9Sstevel@tonic-gate return (1); 90*7c478bd9Sstevel@tonic-gate } 91*7c478bd9Sstevel@tonic-gate 92*7c478bd9Sstevel@tonic-gate return (output_dtd()); 93*7c478bd9Sstevel@tonic-gate } 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate switch (argc) { 96*7c478bd9Sstevel@tonic-gate case 0: 97*7c478bd9Sstevel@tonic-gate break; 98*7c478bd9Sstevel@tonic-gate case 1: 99*7c478bd9Sstevel@tonic-gate searchpath = argv[0]; 100*7c478bd9Sstevel@tonic-gate if (!searchpath[0]) { 101*7c478bd9Sstevel@tonic-gate usage(command); 102*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 103*7c478bd9Sstevel@tonic-gate gettext("\"container\" should not be empty\n")); 104*7c478bd9Sstevel@tonic-gate return (1); 105*7c478bd9Sstevel@tonic-gate } 106*7c478bd9Sstevel@tonic-gate break; 107*7c478bd9Sstevel@tonic-gate default: 108*7c478bd9Sstevel@tonic-gate usage(command); 109*7c478bd9Sstevel@tonic-gate return (1); 110*7c478bd9Sstevel@tonic-gate } 111*7c478bd9Sstevel@tonic-gate 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate /* 114*7c478bd9Sstevel@tonic-gate * Select the data source and print all the data 115*7c478bd9Sstevel@tonic-gate */ 116*7c478bd9Sstevel@tonic-gate if ((status = fru_open_data_source("picl")) != FRU_SUCCESS) { 117*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 118*7c478bd9Sstevel@tonic-gate gettext("Error opening FRU ID data source: %s\n"), 119*7c478bd9Sstevel@tonic-gate fru_strerror(status)); 120*7c478bd9Sstevel@tonic-gate return (1); 121*7c478bd9Sstevel@tonic-gate } 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate return (prtfru(searchpath, containers_only, list_only, xml)); 124*7c478bd9Sstevel@tonic-gate } 125