xref: /illumos-gate/usr/src/cmd/prtfru/main.c (revision 2a8bcb4e)
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 #include <libintl.h>
28*7c478bd9Sstevel@tonic-gate #include <locale.h>
29*7c478bd9Sstevel@tonic-gate #include <stdio.h>
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #include "libfru.h"
32*7c478bd9Sstevel@tonic-gate #include "prtfru.h"
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate static void
usage(const char * command)36*7c478bd9Sstevel@tonic-gate usage(const char *command)
37*7c478bd9Sstevel@tonic-gate {
38*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
39*7c478bd9Sstevel@tonic-gate 		gettext("Usage:  %s [ -d ] | [ -clx ] [ container ]\n"),
40*7c478bd9Sstevel@tonic-gate 		command);
41*7c478bd9Sstevel@tonic-gate }
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate int
main(int argc,char * argv[])44*7c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
45*7c478bd9Sstevel@tonic-gate {
46*7c478bd9Sstevel@tonic-gate 	char  *command = argv[0], *searchpath = NULL;
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate 	int   containers_only = 0, dtd = 0, list_only = 0, nodtd = 0, option,
49*7c478bd9Sstevel@tonic-gate 		status, xml = 0;
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
53*7c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate 	opterr = 0;	/*  "getopt" should not print to "stderr"  */
56*7c478bd9Sstevel@tonic-gate 	while ((option = getopt(argc, argv, "cdlx")) != EOF) {
57*7c478bd9Sstevel@tonic-gate 		switch (option) {
58*7c478bd9Sstevel@tonic-gate 		case 'c':
59*7c478bd9Sstevel@tonic-gate 			containers_only = 1;
60*7c478bd9Sstevel@tonic-gate 			nodtd = 1;
61*7c478bd9Sstevel@tonic-gate 			break;
62*7c478bd9Sstevel@tonic-gate 		case 'd':
63*7c478bd9Sstevel@tonic-gate 			dtd = 1;
64*7c478bd9Sstevel@tonic-gate 			break;
65*7c478bd9Sstevel@tonic-gate 		case 'l':
66*7c478bd9Sstevel@tonic-gate 			list_only = 1;
67*7c478bd9Sstevel@tonic-gate 			nodtd = 1;
68*7c478bd9Sstevel@tonic-gate 			break;
69*7c478bd9Sstevel@tonic-gate 		case 'x':
70*7c478bd9Sstevel@tonic-gate 			xml = 1;
71*7c478bd9Sstevel@tonic-gate 			nodtd = 1;
72*7c478bd9Sstevel@tonic-gate 			break;
73*7c478bd9Sstevel@tonic-gate 		default:
74*7c478bd9Sstevel@tonic-gate 			usage(command);
75*7c478bd9Sstevel@tonic-gate 			return (1);
76*7c478bd9Sstevel@tonic-gate 		}
77*7c478bd9Sstevel@tonic-gate 	}
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate 	argc -= optind;
80*7c478bd9Sstevel@tonic-gate 	argv += optind;
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate 	if (dtd) {
83*7c478bd9Sstevel@tonic-gate 		if (nodtd || (argc > 0)) {
84*7c478bd9Sstevel@tonic-gate 			usage(command);
85*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
86*7c478bd9Sstevel@tonic-gate 			    gettext("Specify \"-d\" alone\n"));
87*7c478bd9Sstevel@tonic-gate 			return (1);
88*7c478bd9Sstevel@tonic-gate 		}
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate 		return (output_dtd());
91*7c478bd9Sstevel@tonic-gate 	}
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate 	switch (argc) {
94*7c478bd9Sstevel@tonic-gate 	case 0:
95*7c478bd9Sstevel@tonic-gate 		break;
96*7c478bd9Sstevel@tonic-gate 	case 1:
97*7c478bd9Sstevel@tonic-gate 		searchpath = argv[0];
98*7c478bd9Sstevel@tonic-gate 		if (!searchpath[0]) {
99*7c478bd9Sstevel@tonic-gate 			usage(command);
100*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
101*7c478bd9Sstevel@tonic-gate 			    gettext("\"container\" should not be empty\n"));
102*7c478bd9Sstevel@tonic-gate 			return (1);
103*7c478bd9Sstevel@tonic-gate 		}
104*7c478bd9Sstevel@tonic-gate 		break;
105*7c478bd9Sstevel@tonic-gate 	default:
106*7c478bd9Sstevel@tonic-gate 		usage(command);
107*7c478bd9Sstevel@tonic-gate 		return (1);
108*7c478bd9Sstevel@tonic-gate 	}
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate 	/*
112*7c478bd9Sstevel@tonic-gate 	 * Select the data source and print all the data
113*7c478bd9Sstevel@tonic-gate 	 */
114*7c478bd9Sstevel@tonic-gate 	if ((status = fru_open_data_source("picl")) != FRU_SUCCESS) {
115*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
116*7c478bd9Sstevel@tonic-gate 		    gettext("Error opening FRU ID data source:  %s\n"),
117*7c478bd9Sstevel@tonic-gate 		    fru_strerror(status));
118*7c478bd9Sstevel@tonic-gate 		return (1);
119*7c478bd9Sstevel@tonic-gate 	}
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate 	return (prtfru(searchpath, containers_only, list_only, xml));
122*7c478bd9Sstevel@tonic-gate }
123