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