1 /* $XConsortium: lndir.c,v 1.5 91/07/21 15:52:11 rws Exp $ */
2 /* Create shadow link tree (after X11R4 script of the same name)
3 Mark Reinhold (mbr@lcs.mit.edu)/3 January 1990 */
5 /* Copyright 1990, Massachusetts Institute of Technology
7 Permission to use, copy, modify, and distribute this program for any purpose
8 and without fee is hereby granted, provided that this copyright and
9 permission notice appear on all copies and supporting documentation, that
10 the name of MIT not be used in advertising or publicity pertaining to
11 distribution of this program without specific prior permission, and that
12 notice be given in supporting documentation that copying and distribution is
13 by permission of MIT. MIT makes no representations about the suitability of
14 this software for any purpose. It is provided "as is" without expressed or
18 /* From the original /bin/sh script:
20 Used to create a copy of the a directory tree that has links for all
21 non-directories (except those named RCS or SCCS). If you are
22 building the distribution on more than one machine, you should use
25 If your master sources are located in /usr/local/src/X and you would like
26 your link tree to be in /usr/local/src/new-X, do the following:
28 % mkdir /usr/local/src/new-X
29 % cd /usr/local/src/new-X
33 #include "lndir-Xos.h"
36 #include <sys/param.h>
60 quit (code, fmt, a1, a2, a3)
62 int code, a1, a2, a3; /* partain */
64 fprintf (stderr, fmt, a1, a2, a3);
72 int code; /* partain */
81 int a1, a2, a3; /* partain */
83 fprintf (stderr, fmt, a1, a2, a3);
88 /* Recursively create symbolic links from the current directory to the "from"
89 directory. Assumes that files described by fs and ts are directories. */
92 dodir (fn, fs, ts, rel)
93 char *fn; /* name of "from" directory, either absolute or
95 struct stat *fs, *ts; /* stats for the "from" directory and cwd */
96 int rel; /* if true, prepend "../" to fn before using */
100 char buf[MAXPATHLEN + 1], *p;
101 char symbuf[MAXPATHLEN + 1];
105 if ((fs->st_dev == ts->st_dev) && (fs->st_ino == ts->st_ino)) {
106 msg ("%s: From and to directories are identical!", fn);
116 if (!(df = opendir (buf))) {
117 msg ("%s: Cannot opendir", buf);
121 p = buf + strlen (buf);
123 n_dirs = fs->st_nlink;
124 while (dp = readdir (df)) {
125 strcpy (p, dp->d_name);
128 if (stat (buf, &sb) < 0) {
133 if (sb.st_mode & S_IFDIR) {
136 if (dp->d_name[0] == '.' &&
137 (dp->d_name[1] == '\0' || (dp->d_name[1] == '.' &&
138 dp->d_name[2] == '\0')))
140 if (!strcmp (dp->d_name, "CVS")) /* partain */
142 if (!strcmp (dp->d_name, "RCS"))
144 if (!strcmp (dp->d_name, "SCCS"))
147 printf ("%s:\n", buf);
148 if ((stat (dp->d_name, &sc) < 0) && (errno == ENOENT)) {
149 if (mkdir (dp->d_name, 0777) < 0 ||
150 stat (dp->d_name, &sc) < 0) {
155 if (readlink (dp->d_name, symbuf, sizeof(symbuf) - 1) >= 0) {
156 msg ("%s: is a link instead of a directory\n", dp->d_name);
159 if (chdir (dp->d_name) < 0) {
163 dodir (buf, &sb, &sc, (buf[0] != '/'));
164 if (chdir ("..") < 0)
171 if (symlink (buf, dp->d_name) < 0) {
172 int saverrno = errno;
174 symlen = readlink(dp->d_name, symbuf, sizeof(symbuf) - 1);
177 symbuf[symlen] = '\0';
178 if (symlen < 0 || strcmp(symbuf, buf))
196 if (ac > 1 && !strcmp(av[1], "-silent")) {
199 if (ac < silent + 2 || ac > silent + 3)
200 quit (1, "usage: %s [-silent] fromdir [todir]", av[0]);
203 if (ac == silent + 3)
209 if (stat (tn, &ts) < 0)
211 if (!(ts.st_mode & S_IFDIR))
212 quit (2, "%s: Not a directory", tn);
217 if (stat (fn, &fs) < 0)
219 if (!(fs.st_mode & S_IFDIR))
220 quit (2, "%s: Not a directory", fn);
222 exit (dodir (fn, &fs, &ts, 0));