2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: checktree.c /main/8 1998/02/06 11:23:04 kaleb $ */
27 Copyright (c) 1993, 1998 The Open Group
31 The above copyright notice and this permission notice shall be included in
32 all copies or substantial portions of the Software.
34 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
38 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
39 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41 Except as contained in this notice, the name of The Open Group shall not be
42 used in advertising or otherwise to promote the sale, use or other dealings
43 in this Software without prior written authorization from The Open Group.
49 #include <sys/param.h>
75 #define CHARSALLOWED \
76 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_."
78 #define fmode_bits_minset 0444
79 #define fmode_bits_maxset 0777
80 #define fmode_bits_write 0222
81 #define dmode_bits_minset 0775
87 int dorcs = 1; /* check RCS file */
88 int do83 = 1; /* check for 8+3 clash */
89 int doro = 1; /* disallow writable (checked out) files */
90 int dodot = 1; /* disallow .files */
91 int dotwiddle = 1; /* disallow file~ */
98 if (fn[strlen(fn) - 1] == '~')
100 cp = strrchr(fn, '.');
101 return cp && (!strcmp(cp + 1, "Z") || !strcmp(cp + 1, "PS"));
104 checkfile(fullname, fn, fs)
112 if (dodot && fn[0] == '.') {
113 printf("dot file: %s\n", fullname);
116 for (len = 0, cp = fn; *cp; len++, cp++) {
117 if (!strchr(CHARSALLOWED, *cp)) {
118 if (dotwiddle || *cp != '~' || cp[1])
119 printf ("bad character: %s\n", fullname);
123 if (len > maxlen && !dontcare(fn))
124 printf("too long (%d): %s\n", len, fullname);
126 if ((fs->st_mode & S_IFLNK) == S_IFLNK) {
127 printf("symbolic link: %s\n", fullname);
131 mode = fs->st_mode & (~S_IFMT);
132 if ((fs->st_mode & S_IFDIR) == S_IFDIR) {
134 if ((mode & dmode_bits_minset) != dmode_bits_minset)
135 printf("directory mode 0%o not minimum 0%o: %s\n",
136 mode, dmode_bits_minset, fullname);
137 } else if ((fs->st_mode & S_IFREG) != S_IFREG)
138 printf("not a regular file: %s\n", fullname);
140 if ((mode & fmode_bits_minset) != fmode_bits_minset)
141 printf("file mode 0%o not minimum 0%o: %s\n",
142 fs->st_mode, fmode_bits_minset, fullname);
143 if (fs->st_nlink != 1)
144 printf("%d links instead of 1: %s\n", fs->st_nlink, fullname);
145 if (doro && (mode & fmode_bits_write) && !dontcare(fn))
146 printf("writable: %s\n", fullname);
148 if ((mode & ~fmode_bits_maxset) != 0)
149 printf("mode 0%o outside maximum set 0%o: %s\n",
150 mode, fmode_bits_maxset, fullname);
163 if (!(df = opendir(dir))) {
164 fprintf(stderr, "cannot open: %s\n", dir);
167 while (dp = readdir(df)) {
168 i = strlen(dp->d_name);
169 if (dp->d_name[i - 1] == 'v' && dp->d_name[i - 2] == ',') {
170 strcpy(p, dp->d_name);
172 if (Stat(dir, &fs) < 0) {
174 strcat(p, dp->d_name);
175 printf("not used: %s\n", dir);
189 for (; --n >= 0 && *cp1 && *cp2; cp1++, cp2++) {
193 if (c1 >= 'A' && c1 <= 'Z')
197 if (c2 >= 'A' && c2 <= 'Z')
202 return (int)c1 - (int)c2;
207 return (int)*cp1 - (int)*cp2;
218 i = Strncmp(*n1, *n2, 8);
220 cp1 = strrchr(*n1, '.');
221 cp2 = strrchr(*n2, '.');
227 i = Strncmp(cp1 + 1, cp2 + 1, 3);
244 if (!(df = opendir(dir))) {
245 fprintf(stderr, "cannot open: %s\n", dir);
248 p = dir + strlen(dir);
254 while (dp = readdir(df)) {
255 strcpy(p, dp->d_name);
256 if (Stat(dir, &fs) < 0) {
260 if ((fs.st_mode & S_IFDIR) == S_IFDIR) {
261 if (dp->d_name[0] == '.' &&
262 (dp->d_name[1] == '\0' || (dp->d_name[1] == '.' &&
263 dp->d_name[2] == '\0')))
265 if (!strcmp (dp->d_name, "RCS")) {
270 if (!strcmp (dp->d_name, "SCCS"))
272 if (!strcmp (dp->d_name, "CVS.adm"))
274 checkfile(dir, p, &fs);
278 checkfile(dir, p, &fs);
279 if (dorcs && !dontcare(dp->d_name)) {
281 strcat(p, dp->d_name);
283 if (Stat(dir, &fs) < 0) {
284 strcpy(p, dp->d_name);
285 printf("no RCS: %s\n", dir);
289 s = (char *)malloc(strlen(dp->d_name) + 1);
290 strcpy(s, dp->d_name);
294 names = (char **)realloc((char *)names,
295 (max + 1) * sizeof(char *));
297 names = (char **)malloc((max + 1) * sizeof(char *));
304 qsort((char *)names, i, sizeof(char *), fncomp);
307 for (i = 0; i < max; i++) {
308 if (!fncomp(&names[i], &names[i + 1]))
309 printf("8+3 clash: %s%s and %s\n",
310 dir, names[i], names[i + 1]);
329 if (!strcmp(*argv, "-rcs")) {
333 } else if (!strcmp(*argv, "-83")) {
337 } else if (!strcmp(*argv, "-ro")) {
341 } else if (!strcmp(*argv, "-dot")) {
345 } else if (!strcmp(*argv, "-twiddle")) {
356 while (--argc >= 0) {
357 strcpy(buf, *argv++);