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
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.
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]
22 /* Copyright (c) 1988 AT&T */
23 /* All Rights Reserved */
27 * Copyright (c) 1999 by Sun Microsystems, Inc.
28 * All rights reserved.
31 #pragma ident "%Z%%M% %I% %E% SMI"
33 /* vpinit - initialize vpdirs or update vpdirs based on currentdir */
35 #include <sys/types.h>
36 #include <string.h> /* string functions */
38 #include <stdio.h> /* stderr */
42 char **vpdirs
; /* directories (including current) in view path */
43 int vpndirs
; /* number of directories in view path */
45 char *argv0
= "libvp"; /* command name default for messages */
48 vpinit(char *currentdir
)
50 char *suffix
; /* path from view path node */
51 char *vpath
; /* VPATH environment variable value */
52 char buf
[MAXPATH
+ 1];
56 /* if an existing directory list is to be updated, free it */
57 if (currentdir
!= NULL
&& vpndirs
> 0) {
58 for (i
= 0; i
< vpndirs
; ++i
) {
64 /* return if the directory list has been computed */
65 /* or there isn't a view path environment variable */
66 if (vpndirs
> 0 || (vpath
= getenv("VPATH")) == NULL
||
70 /* if not given, get the current directory name */
71 if (currentdir
== NULL
&& (currentdir
= mygetwd(buf
)) == NULL
) {
72 (void) fprintf(stderr
,
73 "%s: cannot get current directory name\n", argv0
);
76 /* see if this directory is in the first view path node */
77 for (i
= 0; vpath
[i
] == currentdir
[i
] && vpath
[i
] != '\0'; ++i
) {
80 if (i
== 0 || (vpath
[i
] != ':' && vpath
[i
] != '\0') ||
81 (currentdir
[i
] != '/' && currentdir
[i
] != '\0')) {
84 suffix
= ¤tdir
[i
];
86 /* count the nodes in the view path */
88 for (s
= vpath
; *s
!= '\0'; ++s
) {
89 if (*s
== ':' && *(s
+ 1) != ':' && *(s
+ 1) != '\0') {
93 /* create the source directory list */
94 vpdirs
= (char **)mymalloc(vpndirs
* sizeof (char *));
96 /* don't change VPATH in the environment */
97 vpath
= stralloc(vpath
);
99 /* split the view path into nodes */
100 for (i
= 0, s
= vpath
; i
< vpndirs
&& *s
!= '\0'; ++i
) {
101 while (*s
== ':') { /* ignore null nodes */
105 while (*s
!= '\0' && *++s
!= ':') {
114 /* convert the view path nodes to directories */
115 for (i
= 0; i
< vpndirs
; ++i
) {
116 s
= mymalloc((strlen(vpdirs
[i
]) + strlen(suffix
) + 1));
117 (void) strcpy(s
, vpdirs
[i
]);
118 (void) strcat(s
, suffix
);