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