findunref.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Finds all unreferenced files in a source tree that do not match a list of
* permitted pathnames.
*/
#include <ctype.h>
#include <errno.h>
#include <fnmatch.h>
#include <ftw.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
/*
* Pathname set: a simple datatype for storing pathname pattern globs and
* for checking whether a given pathname is matched by a pattern glob in
* the set.
*/
typedef struct {
char **paths;
unsigned int npath;
unsigned int maxpaths;
} pnset_t;
static int pnset_check(const pnset_t *, const char *);
static void pnset_empty(pnset_t *);
static pnset_t *make_exset(const char *);
static void warn(const char *, ...);
static void die(const char *, ...);
static const char *progname;
int
{
int c;
char path[MAXPATHLEN];
char *tstampfile = ".build.tstamp";
else
progname++;
switch (c) {
case 'a':
break;
case 's':
break;
case 't':
tstampfile = optarg;
break;
default:
case '?':
goto usage;
}
}
if (argc != 2) {
"[-t tstampfile] srcroot exceptfile\n", progname);
return (EXIT_FAILURE);
}
/*
* Interpret a relative timestamp path as relative to srcroot.
*/
if (tstampfile[0] == '/')
else
/*
* Create the exception pathname set.
*/
die("cannot make exception pathname set\n");
/*
* Walk the specified subtree of the tree rooted at argv[0].
*/
return (EXIT_SUCCESS);
}
/*
* Using `exceptfile' and a built-in list of exceptions, build and return a
* pnset_t consisting of all of the pathnames globs which are allowed to be
* unreferenced in the source tree.
*/
static pnset_t *
make_exset(const char *exceptfile)
{
char line[MAXPATHLEN];
char *newline;
unsigned int i;
"*.flg", NULL };
return (NULL);
/*
* Add the built-in exceptions.
*/
goto fail;
}
/*
* Add any exceptions from the file.
*/
goto fail;
}
*newline = '\0';
;
continue;
goto fail;
}
}
return (pnsetp);
fail:
return (NULL);
}
/*
* FTW callback: print `path' if it's older than `tstamp' and not in `exsetp'.
*/
static int
{
char sccspath[MAXPATHLEN];
switch (type) {
case FTW_F:
/*
* Skip if the file is referenced or in the exception list.
*/
return (0);
/*
* If not explicitly checking all files, restrict ourselves
* to unreferenced files under SCCS control.
*/
if (!allfiles) {
return (0);
}
return (0);
case FTW_D:
/*
* Prune any directories in the exception list.
*/
return (0);
case FTW_DNR:
return (0);
case FTW_NS:
return (0);
default:
break;
}
return (0);
}
/*
* Add `path' to the pnset_t pointed to by `pnsetp'.
*/
static int
{
char **newpaths;
return (0);
}
return (0);
return (1);
}
/*
* Check `path' against the pnset_t pointed to by `pnsetp'.
*/
static int
{
unsigned int i;
return (1);
}
return (0);
}
/*
* Empty the pnset_t pointed to by `pnsetp'.
*/
static void
{
}
/* PRINTFLIKE1 */
static void
{
errstr = "<unknown error>";
}
/* PRINTFLIKE1 */
static void
{
errstr = "<unknown error>";
}