summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2006-03-15 03:29:02 +0000
committerRay Lai <ray@cvs.openbsd.org>2006-03-15 03:29:02 +0000
commitdabd393050e9b1258d79da096fc6c65aceaeb83a (patch)
tree27115caf56b6e954deac37d5435a73a39ca548cd
parent10e08d32a63fc63176250470c0ebd3addeed0fb0 (diff)
Move and rename checkin_choose_rcsfile() to rcs_choosefile().
ok joris
-rw-r--r--usr.bin/rcs/ci.c130
-rw-r--r--usr.bin/rcs/rcsprog.c127
-rw-r--r--usr.bin/rcs/rcsprog.h3
3 files changed, 130 insertions, 130 deletions
diff --git a/usr.bin/rcs/ci.c b/usr.bin/rcs/ci.c
index ad2e9f88323..d0de5a6783f 100644
--- a/usr.bin/rcs/ci.c
+++ b/usr.bin/rcs/ci.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ci.c,v 1.116 2006/03/14 03:33:30 ray Exp $ */
+/* $OpenBSD: ci.c,v 1.117 2006/03/15 03:29:01 ray Exp $ */
/*
* Copyright (c) 2005, 2006 Niall O'Higgins <niallo@openbsd.org>
* All rights reserved.
@@ -68,7 +68,6 @@ struct checkin_params {
static int checkin_attach_symbol(struct checkin_params *);
static int checkin_checklock(struct checkin_params *);
-static char *checkin_choose_rcsfile(const char *);
static char *checkin_diff_file(struct checkin_params *);
static char *checkin_getdesc(void);
static char *checkin_getinput(const char *);
@@ -252,7 +251,7 @@ checkin_main(int argc, char **argv)
* should go.
*/
if (pb.flags & NEWFILE) {
- char *fpath = checkin_choose_rcsfile(pb.filename);
+ char *fpath = rcs_choosefile(pb.filename);
if (fpath == NULL) {
status = 1;
continue;
@@ -838,131 +837,6 @@ checkin_mtimedate(struct checkin_params *pb)
}
/*
- * checkin_choose_rcsfile()
- *
- * Given a relative filename, decide where the corresponding RCS file
- * should be. Tries each extension until a file is found. If no file
- * was found, returns a path with the first extension.
- *
- * Returns pointer to a char array on success, NULL on failure.
- */
-static char *
-checkin_choose_rcsfile(const char *filename)
-{
- struct stat sb;
- char *ext, name[MAXPATHLEN], *next, *ptr, rcsdir[MAXPATHLEN],
- *ret, *suffixes, rcspath[MAXPATHLEN];
-
- /* If -x flag was not given, use default. */
- if (rcs_suffixes == NULL)
- rcs_suffixes = RCS_DEFAULT_SUFFIX;
-
- /*
- * If `filename' contains a directory, `rcspath' contains that
- * directory, including a trailing slash. Otherwise `rcspath'
- * contains an empty string.
- */
- if (strlcpy(rcspath, filename, sizeof(rcspath)) >= sizeof(rcspath))
- return (NULL);
- /* If `/' is found, end string after `/'. */
- if ((ptr = strrchr(rcspath, '/')) != NULL)
- *(++ptr) = '\0';
- else
- rcspath[0] = '\0';
-
- /* Append RCS/ to `rcspath' if it exists. */
- if (strlcpy(rcsdir, rcspath, sizeof(rcsdir)) >= sizeof(rcsdir) ||
- strlcat(rcsdir, RCSDIR, sizeof(rcsdir)) >= sizeof(rcsdir))
- return (NULL);
- if ((stat(rcsdir, &sb) == 0) && (sb.st_mode & S_IFDIR))
- if (strlcpy(rcspath, rcsdir, sizeof(rcspath)) >= sizeof(rcspath) ||
- strlcat(rcspath, "/", sizeof(rcspath)) >= sizeof(rcspath))
- return (NULL);
-
- /* Name of file without path. */
- if ((ptr = strrchr(filename, '/')) == NULL) {
- if (strlcpy(name, filename, sizeof(name)) >= sizeof(name))
- return (NULL);
- } else {
- /* Skip `/'. */
- if (strlcpy(name, ptr + 1, sizeof(name)) >= sizeof(name))
- return (NULL);
- }
-
- /* Name of RCS file without an extension. */
- if (strlcat(rcspath, name, sizeof(rcspath)) >= sizeof(rcspath))
- return (NULL);
-
- /*
- * If only the empty suffix was given, use existing rcspath.
- * This ensures that there is at least one suffix for strsep().
- */
- if (strcmp(rcs_suffixes, "") == 0) {
- if ((ret = strdup(rcspath)) == NULL);
- fatal("out of memory");
- return (ret);
- }
-
- /*
- * Cycle through slash-separated `rcs_suffixes', appending each
- * extension to `rcspath' and testing if the file exists. If it
- * does, return that string. Otherwise return path with first
- * extension.
- */
- if ((suffixes = strdup(rcs_suffixes)) == NULL)
- fatal("out of memory");
- for (ret = NULL, next = suffixes; (ext = strsep(&next, "/")) != NULL;) {
- char fpath[MAXPATHLEN];
-
- /* Construct RCS file path. */
- if (strlcpy(fpath, rcspath, sizeof(fpath)) >= sizeof(fpath) ||
- strlcat(fpath, ext, sizeof(fpath)) >= sizeof(fpath)) {
- xfree(suffixes);
- return (NULL);
- }
-
- /* Don't use `filename' as RCS file. */
- if (strcmp(fpath, filename) == 0)
- continue;
-
- if (stat(fpath, &sb) == 0) {
- if ((ret = strdup(fpath)) == NULL)
- fatal("out of memory");
- break;
- }
- }
- xfree(suffixes);
-
- /*
- * If `ret' is still NULL no RCS file with any extension exists
- * so we use the first extension.
- */
- if (ret == NULL) {
- /*
- * XXX - We shouldn't need to do strsep again,
- * suffixes should now be NUL separated.
- */
- if ((suffixes = strdup(rcs_suffixes)) == NULL)
- fatal("out of memory");
- next = suffixes;
- /* Get first extension again. */
- if ((ext = strsep(&next, "/")) == NULL) {
- xfree(suffixes);
- return (NULL);
- }
- if (strlcat(rcspath, ext, sizeof(rcspath)) >= sizeof(rcspath)) {
- xfree(suffixes);
- return (NULL);
- }
- if ((ret = strdup(rcspath)) == NULL)
- fatal("out of memory");
- xfree(suffixes);
- }
-
- return (ret);
-}
-
-/*
* checkin_keywordscan()
*
* Searches working file for keyword values to determine its revision
diff --git a/usr.bin/rcs/rcsprog.c b/usr.bin/rcs/rcsprog.c
index 7cad13ce45d..229b6830924 100644
--- a/usr.bin/rcs/rcsprog.c
+++ b/usr.bin/rcs/rcsprog.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsprog.c,v 1.73 2006/03/15 02:46:14 ray Exp $ */
+/* $OpenBSD: rcsprog.c,v 1.74 2006/03/15 03:29:01 ray Exp $ */
/*
* Copyright (c) 2005 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -227,6 +227,131 @@ rcs_getopt(int argc, char **argv, const char *optstr)
return (ret);
}
+/*
+ * rcs_choosefile()
+ *
+ * Given a relative filename, decide where the corresponding RCS file
+ * should be. Tries each extension until a file is found. If no file
+ * was found, returns a path with the first extension.
+ *
+ * Returns pointer to a char array on success, NULL on failure.
+ */
+char *
+rcs_choosefile(const char *filename)
+{
+ struct stat sb;
+ char *ext, name[MAXPATHLEN], *next, *ptr, rcsdir[MAXPATHLEN],
+ *ret, *suffixes, rcspath[MAXPATHLEN];
+
+ /* If -x flag was not given, use default. */
+ if (rcs_suffixes == NULL)
+ rcs_suffixes = RCS_DEFAULT_SUFFIX;
+
+ /*
+ * If `filename' contains a directory, `rcspath' contains that
+ * directory, including a trailing slash. Otherwise `rcspath'
+ * contains an empty string.
+ */
+ if (strlcpy(rcspath, filename, sizeof(rcspath)) >= sizeof(rcspath))
+ return (NULL);
+ /* If `/' is found, end string after `/'. */
+ if ((ptr = strrchr(rcspath, '/')) != NULL)
+ *(++ptr) = '\0';
+ else
+ rcspath[0] = '\0';
+
+ /* Append RCS/ to `rcspath' if it exists. */
+ if (strlcpy(rcsdir, rcspath, sizeof(rcsdir)) >= sizeof(rcsdir) ||
+ strlcat(rcsdir, RCSDIR, sizeof(rcsdir)) >= sizeof(rcsdir))
+ return (NULL);
+ if ((stat(rcsdir, &sb) == 0) && (sb.st_mode & S_IFDIR))
+ if (strlcpy(rcspath, rcsdir, sizeof(rcspath)) >= sizeof(rcspath) ||
+ strlcat(rcspath, "/", sizeof(rcspath)) >= sizeof(rcspath))
+ return (NULL);
+
+ /* Name of file without path. */
+ if ((ptr = strrchr(filename, '/')) == NULL) {
+ if (strlcpy(name, filename, sizeof(name)) >= sizeof(name))
+ return (NULL);
+ } else {
+ /* Skip `/'. */
+ if (strlcpy(name, ptr + 1, sizeof(name)) >= sizeof(name))
+ return (NULL);
+ }
+
+ /* Name of RCS file without an extension. */
+ if (strlcat(rcspath, name, sizeof(rcspath)) >= sizeof(rcspath))
+ return (NULL);
+
+ /*
+ * If only the empty suffix was given, use existing rcspath.
+ * This ensures that there is at least one suffix for strsep().
+ */
+ if (strcmp(rcs_suffixes, "") == 0) {
+ if ((ret = strdup(rcspath)) == NULL);
+ fatal("out of memory");
+ return (ret);
+ }
+
+ /*
+ * Cycle through slash-separated `rcs_suffixes', appending each
+ * extension to `rcspath' and testing if the file exists. If it
+ * does, return that string. Otherwise return path with first
+ * extension.
+ */
+ if ((suffixes = strdup(rcs_suffixes)) == NULL)
+ fatal("out of memory");
+ for (ret = NULL, next = suffixes; (ext = strsep(&next, "/")) != NULL;) {
+ char fpath[MAXPATHLEN];
+
+ /* Construct RCS file path. */
+ if (strlcpy(fpath, rcspath, sizeof(fpath)) >= sizeof(fpath) ||
+ strlcat(fpath, ext, sizeof(fpath)) >= sizeof(fpath)) {
+ xfree(suffixes);
+ return (NULL);
+ }
+
+ /* Don't use `filename' as RCS file. */
+ if (strcmp(fpath, filename) == 0)
+ continue;
+
+ if (stat(fpath, &sb) == 0) {
+ if ((ret = strdup(fpath)) == NULL)
+ fatal("out of memory");
+ break;
+ }
+ }
+ xfree(suffixes);
+
+ /*
+ * If `ret' is still NULL no RCS file with any extension exists
+ * so we use the first extension.
+ */
+ if (ret == NULL) {
+ /*
+ * XXX - We shouldn't need to do strsep again,
+ * suffixes should now be NUL separated.
+ */
+ if ((suffixes = strdup(rcs_suffixes)) == NULL)
+ fatal("out of memory");
+ next = suffixes;
+ /* Get first extension again. */
+ if ((ext = strsep(&next, "/")) == NULL) {
+ xfree(suffixes);
+ return (NULL);
+ }
+ if (strlcat(rcspath, ext, sizeof(rcspath)) >= sizeof(rcspath)) {
+ xfree(suffixes);
+ return (NULL);
+ }
+ if ((ret = strdup(rcspath)) == NULL)
+ fatal("out of memory");
+ xfree(suffixes);
+ }
+
+ return (ret);
+}
+
int
rcs_statfile(char *fname, char *out, size_t len)
{
diff --git a/usr.bin/rcs/rcsprog.h b/usr.bin/rcs/rcsprog.h
index e7045e470fb..b336d9413de 100644
--- a/usr.bin/rcs/rcsprog.h
+++ b/usr.bin/rcs/rcsprog.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsprog.h,v 1.37 2006/03/14 03:33:30 ray Exp $ */
+/* $OpenBSD: rcsprog.h,v 1.38 2006/03/15 03:29:01 ray Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -100,6 +100,7 @@ int rcs_init(char *, char **, int);
int rcs_getopt(int, char **, const char *);
int rcs_main(int, char **);
int rcs_set_mtime(const char *, time_t);
+char *rcs_choosefile(const char *);
int rcs_statfile(char *, char *, size_t);
time_t rcs_get_mtime(const char *);
void rcs_set_rev(const char *, RCSNUM **);