xref: /onnv-gate/usr/src/lib/libpkg/common/gpkglist.c (revision 9781:ccf49524d5dc)
1*9781SMoriah.Waterland@Sun.COM /*
2*9781SMoriah.Waterland@Sun.COM  * CDDL HEADER START
3*9781SMoriah.Waterland@Sun.COM  *
4*9781SMoriah.Waterland@Sun.COM  * The contents of this file are subject to the terms of the
5*9781SMoriah.Waterland@Sun.COM  * Common Development and Distribution License (the "License").
6*9781SMoriah.Waterland@Sun.COM  * You may not use this file except in compliance with the License.
7*9781SMoriah.Waterland@Sun.COM  *
8*9781SMoriah.Waterland@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*9781SMoriah.Waterland@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*9781SMoriah.Waterland@Sun.COM  * See the License for the specific language governing permissions
11*9781SMoriah.Waterland@Sun.COM  * and limitations under the License.
12*9781SMoriah.Waterland@Sun.COM  *
13*9781SMoriah.Waterland@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*9781SMoriah.Waterland@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*9781SMoriah.Waterland@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*9781SMoriah.Waterland@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*9781SMoriah.Waterland@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*9781SMoriah.Waterland@Sun.COM  *
19*9781SMoriah.Waterland@Sun.COM  * CDDL HEADER END
20*9781SMoriah.Waterland@Sun.COM  */
21*9781SMoriah.Waterland@Sun.COM 
22*9781SMoriah.Waterland@Sun.COM /*
23*9781SMoriah.Waterland@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24*9781SMoriah.Waterland@Sun.COM  * Use is subject to license terms.
25*9781SMoriah.Waterland@Sun.COM  */
26*9781SMoriah.Waterland@Sun.COM 
27*9781SMoriah.Waterland@Sun.COM /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*9781SMoriah.Waterland@Sun.COM /* All Rights Reserved */
29*9781SMoriah.Waterland@Sun.COM 
30*9781SMoriah.Waterland@Sun.COM 
31*9781SMoriah.Waterland@Sun.COM 
32*9781SMoriah.Waterland@Sun.COM #include <stdio.h>
33*9781SMoriah.Waterland@Sun.COM #include <ctype.h>
34*9781SMoriah.Waterland@Sun.COM #include <string.h>
35*9781SMoriah.Waterland@Sun.COM #include <signal.h>
36*9781SMoriah.Waterland@Sun.COM #include <errno.h>
37*9781SMoriah.Waterland@Sun.COM #include <stdlib.h>
38*9781SMoriah.Waterland@Sun.COM #include <valtools.h>
39*9781SMoriah.Waterland@Sun.COM #include "pkginfo.h"
40*9781SMoriah.Waterland@Sun.COM #include "pkglib.h"
41*9781SMoriah.Waterland@Sun.COM #include "pkglibmsgs.h"
42*9781SMoriah.Waterland@Sun.COM #include "pkgstrct.h"
43*9781SMoriah.Waterland@Sun.COM #include "pkglocale.h"
44*9781SMoriah.Waterland@Sun.COM 
45*9781SMoriah.Waterland@Sun.COM extern char	*pkgdir; 		/* WHERE? */
46*9781SMoriah.Waterland@Sun.COM 
47*9781SMoriah.Waterland@Sun.COM /* libadm.a */
48*9781SMoriah.Waterland@Sun.COM extern CKMENU	*allocmenu(char *label, int attr);
49*9781SMoriah.Waterland@Sun.COM extern int	ckitem(CKMENU *menup, char *item[], short max, char *defstr,
50*9781SMoriah.Waterland@Sun.COM 				char *error, char *help, char *prompt);
51*9781SMoriah.Waterland@Sun.COM extern int	pkgnmchk(register char *pkg, register char *spec,
52*9781SMoriah.Waterland@Sun.COM 				int presvr4flg);
53*9781SMoriah.Waterland@Sun.COM extern int	fpkginfo(struct pkginfo *info, char *pkginst);
54*9781SMoriah.Waterland@Sun.COM extern char	*fpkginst(char *pkg, ...);
55*9781SMoriah.Waterland@Sun.COM extern int	setinvis(CKMENU *menup, char *choice);
56*9781SMoriah.Waterland@Sun.COM extern int	setitem(CKMENU *menup, char *choice);
57*9781SMoriah.Waterland@Sun.COM 
58*9781SMoriah.Waterland@Sun.COM #define	CMDSIZ			512
59*9781SMoriah.Waterland@Sun.COM #define	LSIZE			256
60*9781SMoriah.Waterland@Sun.COM #define	MAXSIZE			128
61*9781SMoriah.Waterland@Sun.COM #define	MALLOCSIZ		128
62*9781SMoriah.Waterland@Sun.COM #define	MAX_CAT_ARGS	64
63*9781SMoriah.Waterland@Sun.COM #define	MAX_CAT_LEN		16
64*9781SMoriah.Waterland@Sun.COM 
65*9781SMoriah.Waterland@Sun.COM static int	cont_in_list = 0;	/* live continuation */
66*9781SMoriah.Waterland@Sun.COM static char	cont_keyword[PKGSIZ+1];	/* the continuation keyword */
67*9781SMoriah.Waterland@Sun.COM 
68*9781SMoriah.Waterland@Sun.COM /*
69*9781SMoriah.Waterland@Sun.COM  * Allocate memory for the next package name. This function attempts the
70*9781SMoriah.Waterland@Sun.COM  * allocation and if that succeeds, returns a pointer to the new memory
71*9781SMoriah.Waterland@Sun.COM  * location and increments "n". Otherwise, it returens NULL and n is
72*9781SMoriah.Waterland@Sun.COM  * unchanged.
73*9781SMoriah.Waterland@Sun.COM  */
74*9781SMoriah.Waterland@Sun.COM static char **
next_n(int * n,char ** nwpkg)75*9781SMoriah.Waterland@Sun.COM next_n(int *n, char **nwpkg)
76*9781SMoriah.Waterland@Sun.COM {
77*9781SMoriah.Waterland@Sun.COM 	int loc_n = *n;
78*9781SMoriah.Waterland@Sun.COM 
79*9781SMoriah.Waterland@Sun.COM 	if ((++loc_n % MALLOCSIZ) == 0) {
80*9781SMoriah.Waterland@Sun.COM 		nwpkg = (char **)realloc(nwpkg,
81*9781SMoriah.Waterland@Sun.COM 			(loc_n+MALLOCSIZ) * sizeof (char **));
82*9781SMoriah.Waterland@Sun.COM 		if (nwpkg == NULL) {
83*9781SMoriah.Waterland@Sun.COM 			progerr(pkg_gt(ERR_MEMORY), errno);
84*9781SMoriah.Waterland@Sun.COM 			errno = ENOMEM;
85*9781SMoriah.Waterland@Sun.COM 			return (NULL);
86*9781SMoriah.Waterland@Sun.COM 		}
87*9781SMoriah.Waterland@Sun.COM 	}
88*9781SMoriah.Waterland@Sun.COM 
89*9781SMoriah.Waterland@Sun.COM 	*n = loc_n;
90*9781SMoriah.Waterland@Sun.COM 	return (nwpkg);
91*9781SMoriah.Waterland@Sun.COM }
92*9781SMoriah.Waterland@Sun.COM 
93*9781SMoriah.Waterland@Sun.COM /*
94*9781SMoriah.Waterland@Sun.COM  * This informs gpkglist() to put a keyword at the head of the pkglist. This
95*9781SMoriah.Waterland@Sun.COM  * was originally intended for live continue, but it may have other
96*9781SMoriah.Waterland@Sun.COM  * applications as well.
97*9781SMoriah.Waterland@Sun.COM  */
98*9781SMoriah.Waterland@Sun.COM void
pkglist_cont(char * keyword)99*9781SMoriah.Waterland@Sun.COM pkglist_cont(char *keyword)
100*9781SMoriah.Waterland@Sun.COM {
101*9781SMoriah.Waterland@Sun.COM 	cont_in_list = 1;
102*9781SMoriah.Waterland@Sun.COM 	(void) strncpy(cont_keyword, keyword, PKGSIZ);
103*9781SMoriah.Waterland@Sun.COM }
104*9781SMoriah.Waterland@Sun.COM 
105*9781SMoriah.Waterland@Sun.COM /*
106*9781SMoriah.Waterland@Sun.COM  * This function constructs the list of packages that the user wants managed.
107*9781SMoriah.Waterland@Sun.COM  * It may be a list on the command line, it may be some or all of the
108*9781SMoriah.Waterland@Sun.COM  * packages in a directory or it may be a continuation from a previous
109*9781SMoriah.Waterland@Sun.COM  * dryrun. It may also be a list of pkgs gathered from the CATEGORY parameter
110*9781SMoriah.Waterland@Sun.COM  * in a spooled or installed pkginfo file.
111*9781SMoriah.Waterland@Sun.COM  */
112*9781SMoriah.Waterland@Sun.COM char **
gpkglist(char * dir,char ** pkg,char ** catg)113*9781SMoriah.Waterland@Sun.COM gpkglist(char *dir, char **pkg, char **catg)
114*9781SMoriah.Waterland@Sun.COM {
115*9781SMoriah.Waterland@Sun.COM 	struct _choice_ *chp;
116*9781SMoriah.Waterland@Sun.COM 	struct pkginfo info;
117*9781SMoriah.Waterland@Sun.COM 	char	*inst;
118*9781SMoriah.Waterland@Sun.COM 	CKMENU	*menup;
119*9781SMoriah.Waterland@Sun.COM 	char	temp[LSIZE];
120*9781SMoriah.Waterland@Sun.COM 	char	*savedir, **nwpkg;
121*9781SMoriah.Waterland@Sun.COM 	int	i, n;
122*9781SMoriah.Waterland@Sun.COM 
123*9781SMoriah.Waterland@Sun.COM 	savedir = pkgdir;
124*9781SMoriah.Waterland@Sun.COM 	pkgdir = dir;
125*9781SMoriah.Waterland@Sun.COM 
126*9781SMoriah.Waterland@Sun.COM 	info.pkginst = NULL; /* initialize for memory handling */
127*9781SMoriah.Waterland@Sun.COM 	if (pkginfo(&info, "all", NULL, NULL)) {
128*9781SMoriah.Waterland@Sun.COM 		errno = ENOPKG; /* contains no valid packages */
129*9781SMoriah.Waterland@Sun.COM 		pkgdir = savedir;
130*9781SMoriah.Waterland@Sun.COM 		return (NULL);
131*9781SMoriah.Waterland@Sun.COM 	}
132*9781SMoriah.Waterland@Sun.COM 
133*9781SMoriah.Waterland@Sun.COM 	/*
134*9781SMoriah.Waterland@Sun.COM 	 * If no explicit list was provided and this is not a continuation
135*9781SMoriah.Waterland@Sun.COM 	 * (implying a certain level of direction on the caller's part)
136*9781SMoriah.Waterland@Sun.COM 	 * present a menu of available packages for installation.
137*9781SMoriah.Waterland@Sun.COM 	 */
138*9781SMoriah.Waterland@Sun.COM 	if (pkg[0] == NULL && !cont_in_list) {
139*9781SMoriah.Waterland@Sun.COM 		menup = allocmenu(pkg_gt(HEADER), CKALPHA);
140*9781SMoriah.Waterland@Sun.COM 		if (setinvis(menup, "all")) {
141*9781SMoriah.Waterland@Sun.COM 			errno = EFAULT;
142*9781SMoriah.Waterland@Sun.COM 			return (NULL);
143*9781SMoriah.Waterland@Sun.COM 		}
144*9781SMoriah.Waterland@Sun.COM 		do {
145*9781SMoriah.Waterland@Sun.COM 			/* bug id 1087404 */
146*9781SMoriah.Waterland@Sun.COM 			if (!info.pkginst || !info.name || !info.arch ||
147*9781SMoriah.Waterland@Sun.COM 			    !info.version)
148*9781SMoriah.Waterland@Sun.COM 				continue;
149*9781SMoriah.Waterland@Sun.COM 			(void) sprintf(temp, "%s %s\n(%s) %s", info.pkginst,
150*9781SMoriah.Waterland@Sun.COM 				info.name, info.arch, info.version);
151*9781SMoriah.Waterland@Sun.COM 			if (setitem(menup, temp)) {
152*9781SMoriah.Waterland@Sun.COM 				errno = EFAULT;
153*9781SMoriah.Waterland@Sun.COM 				return (NULL);
154*9781SMoriah.Waterland@Sun.COM 			}
155*9781SMoriah.Waterland@Sun.COM 		} while (pkginfo(&info, "all", NULL, NULL) == 0);
156*9781SMoriah.Waterland@Sun.COM 		/* clear memory usage by pkginfo */
157*9781SMoriah.Waterland@Sun.COM 		(void) pkginfo(&info, NULL, NULL, NULL);
158*9781SMoriah.Waterland@Sun.COM 		pkgdir = savedir; 	/* restore pkgdir to orig value */
159*9781SMoriah.Waterland@Sun.COM 
160*9781SMoriah.Waterland@Sun.COM 		nwpkg = (char **)calloc(MALLOCSIZ, sizeof (char **));
161*9781SMoriah.Waterland@Sun.COM 		n = ckitem(menup, nwpkg, MALLOCSIZ, "all", NULL,
162*9781SMoriah.Waterland@Sun.COM 		    pkg_gt(HELP), pkg_gt(PROMPT));
163*9781SMoriah.Waterland@Sun.COM 		if (n) {
164*9781SMoriah.Waterland@Sun.COM 			free(nwpkg);
165*9781SMoriah.Waterland@Sun.COM 			errno = ((n == 3) ? EINTR : EFAULT);
166*9781SMoriah.Waterland@Sun.COM 			pkgdir = savedir;
167*9781SMoriah.Waterland@Sun.COM 			return (NULL);
168*9781SMoriah.Waterland@Sun.COM 		}
169*9781SMoriah.Waterland@Sun.COM 		if (strcmp(nwpkg[0], "all") == 0) {
170*9781SMoriah.Waterland@Sun.COM 			chp = menup->choice;
171*9781SMoriah.Waterland@Sun.COM 			for (n = 0; chp; /* void */) {
172*9781SMoriah.Waterland@Sun.COM 				nwpkg[n] = strdup(chp->token);
173*9781SMoriah.Waterland@Sun.COM 				nwpkg = next_n(&n, nwpkg);
174*9781SMoriah.Waterland@Sun.COM 				chp = chp->next;
175*9781SMoriah.Waterland@Sun.COM 				nwpkg[n] = NULL;
176*9781SMoriah.Waterland@Sun.COM 			}
177*9781SMoriah.Waterland@Sun.COM 		} else {
178*9781SMoriah.Waterland@Sun.COM 			for (n = 0; nwpkg[n]; n++)
179*9781SMoriah.Waterland@Sun.COM 				nwpkg[n] = strdup(nwpkg[n]);
180*9781SMoriah.Waterland@Sun.COM 		}
181*9781SMoriah.Waterland@Sun.COM 		(void) setitem(menup, NULL); /* free resources */
182*9781SMoriah.Waterland@Sun.COM 		free(menup);
183*9781SMoriah.Waterland@Sun.COM 		pkgdir = savedir;
184*9781SMoriah.Waterland@Sun.COM 		return (nwpkg);
185*9781SMoriah.Waterland@Sun.COM 	}
186*9781SMoriah.Waterland@Sun.COM 
187*9781SMoriah.Waterland@Sun.COM 	/* clear memory usage by pkginfo */
188*9781SMoriah.Waterland@Sun.COM 	(void) pkginfo(&info, NULL, NULL, NULL);
189*9781SMoriah.Waterland@Sun.COM 
190*9781SMoriah.Waterland@Sun.COM 	nwpkg = (char **)calloc(MALLOCSIZ, sizeof (char **));
191*9781SMoriah.Waterland@Sun.COM 
192*9781SMoriah.Waterland@Sun.COM 	/*
193*9781SMoriah.Waterland@Sun.COM 	 * pkg array contains the instance identifiers to
194*9781SMoriah.Waterland@Sun.COM 	 * be selected, or possibly wildcard definitions
195*9781SMoriah.Waterland@Sun.COM 	 */
196*9781SMoriah.Waterland@Sun.COM 	i = n = 0;
197*9781SMoriah.Waterland@Sun.COM 	do {
198*9781SMoriah.Waterland@Sun.COM 		if (cont_in_list) {	/* This is a live continuation. */
199*9781SMoriah.Waterland@Sun.COM 			nwpkg[n] = strdup(cont_keyword);
200*9781SMoriah.Waterland@Sun.COM 			nwpkg = next_n(&n, nwpkg);
201*9781SMoriah.Waterland@Sun.COM 			nwpkg[n] = NULL;
202*9781SMoriah.Waterland@Sun.COM 			cont_in_list = 0;	/* handled */
203*9781SMoriah.Waterland@Sun.COM 
204*9781SMoriah.Waterland@Sun.COM 			if (pkg[0] == NULL) {	/* It's just a continuation. */
205*9781SMoriah.Waterland@Sun.COM 				break;
206*9781SMoriah.Waterland@Sun.COM 			}
207*9781SMoriah.Waterland@Sun.COM 		} else if (pkgnmchk(pkg[i], "all", 1)) {
208*9781SMoriah.Waterland@Sun.COM 			/* wildcard specification */
209*9781SMoriah.Waterland@Sun.COM 			(void) fpkginst(NULL);
210*9781SMoriah.Waterland@Sun.COM 			inst = fpkginst(pkg[i], NULL, NULL);
211*9781SMoriah.Waterland@Sun.COM 			if (inst == NULL) {
212*9781SMoriah.Waterland@Sun.COM 				progerr(pkg_gt(ERR_NOPKG), pkg[i]);
213*9781SMoriah.Waterland@Sun.COM 				free(nwpkg);
214*9781SMoriah.Waterland@Sun.COM 				nwpkg = NULL;
215*9781SMoriah.Waterland@Sun.COM 				errno = ESRCH;
216*9781SMoriah.Waterland@Sun.COM 				break;
217*9781SMoriah.Waterland@Sun.COM 			}
218*9781SMoriah.Waterland@Sun.COM 			do {
219*9781SMoriah.Waterland@Sun.COM 				if (catg != NULL) {
220*9781SMoriah.Waterland@Sun.COM 					pkginfo(&info, inst, NULL, NULL);
221*9781SMoriah.Waterland@Sun.COM 					if (!is_same_CATEGORY(catg,
222*9781SMoriah.Waterland@Sun.COM 							info.catg))
223*9781SMoriah.Waterland@Sun.COM 						continue;
224*9781SMoriah.Waterland@Sun.COM 				}
225*9781SMoriah.Waterland@Sun.COM 				nwpkg[n] = strdup(inst);
226*9781SMoriah.Waterland@Sun.COM 				nwpkg = next_n(&n, nwpkg);
227*9781SMoriah.Waterland@Sun.COM 				nwpkg[n] = NULL;
228*9781SMoriah.Waterland@Sun.COM 			} while (inst = fpkginst(pkg[i], NULL, NULL));
229*9781SMoriah.Waterland@Sun.COM 		} else {
230*9781SMoriah.Waterland@Sun.COM 			if (fpkginfo(&info, pkg[i])) {
231*9781SMoriah.Waterland@Sun.COM 				progerr(pkg_gt(ERR_NOPKG), pkg[i]);
232*9781SMoriah.Waterland@Sun.COM 				free(nwpkg);
233*9781SMoriah.Waterland@Sun.COM 				nwpkg = NULL;
234*9781SMoriah.Waterland@Sun.COM 				errno = ESRCH;
235*9781SMoriah.Waterland@Sun.COM 				break;
236*9781SMoriah.Waterland@Sun.COM 			}
237*9781SMoriah.Waterland@Sun.COM 			nwpkg[n] = strdup(pkg[i]);
238*9781SMoriah.Waterland@Sun.COM 			nwpkg = next_n(&n, nwpkg);
239*9781SMoriah.Waterland@Sun.COM 			nwpkg[n] = NULL;
240*9781SMoriah.Waterland@Sun.COM 		}
241*9781SMoriah.Waterland@Sun.COM 	} while (pkg[++i]);
242*9781SMoriah.Waterland@Sun.COM 
243*9781SMoriah.Waterland@Sun.COM 	(void) fpkginst(NULL);
244*9781SMoriah.Waterland@Sun.COM 	(void) fpkginfo(&info, NULL);
245*9781SMoriah.Waterland@Sun.COM 	pkgdir = savedir; 	/* restore pkgdir to orig value */
246*9781SMoriah.Waterland@Sun.COM 
247*9781SMoriah.Waterland@Sun.COM 	if (catg != NULL) {
248*9781SMoriah.Waterland@Sun.COM 		if (nwpkg[0] == NULL) {
249*9781SMoriah.Waterland@Sun.COM 
250*9781SMoriah.Waterland@Sun.COM 			/*
251*9781SMoriah.Waterland@Sun.COM 			 * No pkgs in the spooled directory matched the
252*9781SMoriah.Waterland@Sun.COM 			 * category specified by the user.
253*9781SMoriah.Waterland@Sun.COM 			 */
254*9781SMoriah.Waterland@Sun.COM 
255*9781SMoriah.Waterland@Sun.COM 			free(nwpkg);
256*9781SMoriah.Waterland@Sun.COM 			return (NULL);
257*9781SMoriah.Waterland@Sun.COM 		}
258*9781SMoriah.Waterland@Sun.COM 	}
259*9781SMoriah.Waterland@Sun.COM 	return (nwpkg);
260*9781SMoriah.Waterland@Sun.COM }
261*9781SMoriah.Waterland@Sun.COM 
262*9781SMoriah.Waterland@Sun.COM /*
263*9781SMoriah.Waterland@Sun.COM  * Check category passed in on the command line to see if it is valid.
264*9781SMoriah.Waterland@Sun.COM  *
265*9781SMoriah.Waterland@Sun.COM  * returns 0 if the category is valid
266*9781SMoriah.Waterland@Sun.COM  * returns 1 if the category is invalid
267*9781SMoriah.Waterland@Sun.COM  */
268*9781SMoriah.Waterland@Sun.COM 
269*9781SMoriah.Waterland@Sun.COM int
is_not_valid_category(char ** category,char * progname)270*9781SMoriah.Waterland@Sun.COM is_not_valid_category(char **category, char *progname)
271*9781SMoriah.Waterland@Sun.COM {
272*9781SMoriah.Waterland@Sun.COM 	if (strcasecmp(progname, "pkgrm") == 0) {
273*9781SMoriah.Waterland@Sun.COM 		if (is_same_CATEGORY(category, "system"))
274*9781SMoriah.Waterland@Sun.COM 			return (1);
275*9781SMoriah.Waterland@Sun.COM 	}
276*9781SMoriah.Waterland@Sun.COM 
277*9781SMoriah.Waterland@Sun.COM 	return (0);
278*9781SMoriah.Waterland@Sun.COM }
279*9781SMoriah.Waterland@Sun.COM 
280*9781SMoriah.Waterland@Sun.COM /*
281*9781SMoriah.Waterland@Sun.COM  * Check category length
282*9781SMoriah.Waterland@Sun.COM  *
283*9781SMoriah.Waterland@Sun.COM  * returns 0 if the category length is valid
284*9781SMoriah.Waterland@Sun.COM  * returns 1 if a category has length > 16 chars as defined by the SVr4 ABI
285*9781SMoriah.Waterland@Sun.COM  */
286*9781SMoriah.Waterland@Sun.COM 
287*9781SMoriah.Waterland@Sun.COM int
is_not_valid_length(char ** category)288*9781SMoriah.Waterland@Sun.COM is_not_valid_length(char **category)
289*9781SMoriah.Waterland@Sun.COM {
290*9781SMoriah.Waterland@Sun.COM 	int i;
291*9781SMoriah.Waterland@Sun.COM 
292*9781SMoriah.Waterland@Sun.COM 	for (i = 0; category[i] != NULL; i++) {
293*9781SMoriah.Waterland@Sun.COM 		if (strlen(category[i]) > MAX_CAT_LEN)
294*9781SMoriah.Waterland@Sun.COM 			return (1);
295*9781SMoriah.Waterland@Sun.COM 	}
296*9781SMoriah.Waterland@Sun.COM 
297*9781SMoriah.Waterland@Sun.COM 	return (0);
298*9781SMoriah.Waterland@Sun.COM }
299*9781SMoriah.Waterland@Sun.COM 
300*9781SMoriah.Waterland@Sun.COM /*
301*9781SMoriah.Waterland@Sun.COM  * Check category passed in on the command line against the CATEGORY in the
302*9781SMoriah.Waterland@Sun.COM  * spooled or installed packages pkginfo file.
303*9781SMoriah.Waterland@Sun.COM  *
304*9781SMoriah.Waterland@Sun.COM  * returns 0 if categories match
305*9781SMoriah.Waterland@Sun.COM  * returns 1 if categories don't match
306*9781SMoriah.Waterland@Sun.COM  */
307*9781SMoriah.Waterland@Sun.COM 
308*9781SMoriah.Waterland@Sun.COM int
is_same_CATEGORY(char ** category,char * persistent_category)309*9781SMoriah.Waterland@Sun.COM is_same_CATEGORY(char **category, char *persistent_category)
310*9781SMoriah.Waterland@Sun.COM {
311*9781SMoriah.Waterland@Sun.COM 	int i, j, n = 0;
312*9781SMoriah.Waterland@Sun.COM 	char *pers_catg, **pers_catgs;
313*9781SMoriah.Waterland@Sun.COM 
314*9781SMoriah.Waterland@Sun.COM 	pers_catg = strdup(persistent_category);
315*9781SMoriah.Waterland@Sun.COM 
316*9781SMoriah.Waterland@Sun.COM 	pers_catgs = (char **)calloc(MAX_CAT_LEN, sizeof (char **));
317*9781SMoriah.Waterland@Sun.COM 
318*9781SMoriah.Waterland@Sun.COM 	pers_catgs[n++] = strtok(pers_catg, " \t\n, ");
319*9781SMoriah.Waterland@Sun.COM 	while (pers_catgs[n] = strtok(NULL, " \t\n, "))
320*9781SMoriah.Waterland@Sun.COM 		n++;
321*9781SMoriah.Waterland@Sun.COM 
322*9781SMoriah.Waterland@Sun.COM 	for (i = 0; category[i] != NULL; i++) {
323*9781SMoriah.Waterland@Sun.COM 		for (j = 0; j < n; j++) {
324*9781SMoriah.Waterland@Sun.COM 			if (strcasecmp(category[i], pers_catgs[j]) == 0) {
325*9781SMoriah.Waterland@Sun.COM 				return (1);
326*9781SMoriah.Waterland@Sun.COM 			}
327*9781SMoriah.Waterland@Sun.COM 		}
328*9781SMoriah.Waterland@Sun.COM 	}
329*9781SMoriah.Waterland@Sun.COM 
330*9781SMoriah.Waterland@Sun.COM 	return (0);
331*9781SMoriah.Waterland@Sun.COM }
332*9781SMoriah.Waterland@Sun.COM 
333*9781SMoriah.Waterland@Sun.COM /*
334*9781SMoriah.Waterland@Sun.COM  * Given a string of categories, construct a null-terminated array of
335*9781SMoriah.Waterland@Sun.COM  * categories.
336*9781SMoriah.Waterland@Sun.COM  *
337*9781SMoriah.Waterland@Sun.COM  * returns the array of categories or NULL
338*9781SMoriah.Waterland@Sun.COM  */
339*9781SMoriah.Waterland@Sun.COM 
340*9781SMoriah.Waterland@Sun.COM char **
get_categories(char * catg_arg)341*9781SMoriah.Waterland@Sun.COM get_categories(char *catg_arg)
342*9781SMoriah.Waterland@Sun.COM {
343*9781SMoriah.Waterland@Sun.COM 	int n = 0;
344*9781SMoriah.Waterland@Sun.COM 	char *tmp_catg;
345*9781SMoriah.Waterland@Sun.COM 	char **catgs;
346*9781SMoriah.Waterland@Sun.COM 
347*9781SMoriah.Waterland@Sun.COM 	tmp_catg = strdup(catg_arg);
348*9781SMoriah.Waterland@Sun.COM 
349*9781SMoriah.Waterland@Sun.COM 	catgs = (char **)calloc(MAX_CAT_LEN, sizeof (char **));
350*9781SMoriah.Waterland@Sun.COM 
351*9781SMoriah.Waterland@Sun.COM 	catgs[n++] = strtok(tmp_catg, " \t\n, ");
352*9781SMoriah.Waterland@Sun.COM 	while (catgs[n] = strtok(NULL, " \t\n, "))
353*9781SMoriah.Waterland@Sun.COM 		n++;
354*9781SMoriah.Waterland@Sun.COM 
355*9781SMoriah.Waterland@Sun.COM 	if (*catgs == NULL)
356*9781SMoriah.Waterland@Sun.COM 		return (NULL);
357*9781SMoriah.Waterland@Sun.COM 	else
358*9781SMoriah.Waterland@Sun.COM 		return (catgs);
359*9781SMoriah.Waterland@Sun.COM }
360