diff options
author | Xavier Santolaria <xsa@cvs.openbsd.org> | 2006-03-17 08:51:46 +0000 |
---|---|---|
committer | Xavier Santolaria <xsa@cvs.openbsd.org> | 2006-03-17 08:51:46 +0000 |
commit | 54c45ec4af9c4db50ed7a048accb4d2848d0a767 (patch) | |
tree | 8da4136138f8118eab762112eac24a4f5268fdbe | |
parent | 7b682b3417ffb86bfa19d25ced33eca7604ca193 (diff) |
rlog_strsplit() -> cvs_strsplit() and move it to util.c so it can be reused
by `cvs log' and some other RCS utilities. "Looks good" ray@.
-rw-r--r-- | usr.bin/cvs/util.c | 29 | ||||
-rw-r--r-- | usr.bin/cvs/util.h | 5 | ||||
-rw-r--r-- | usr.bin/rcs/rlog.c | 35 |
3 files changed, 35 insertions, 34 deletions
diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c index 161e06eb216..05abcf7b39c 100644 --- a/usr.bin/cvs/util.c +++ b/usr.bin/cvs/util.c @@ -1,6 +1,8 @@ -/* $OpenBSD: util.c,v 1.70 2006/03/15 19:59:36 niallo Exp $ */ +/* $OpenBSD: util.c,v 1.71 2006/03/17 08:51:45 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> + * Copyright (c) 2005, 2006 Joris Vink <joris@openbsd.org> + * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -1044,3 +1046,28 @@ cvs_yesno(void) return (ret); } +/* + * cvs_strsplit() + * + * Split a string <str> of <sep>-separated values and allocate + * an argument vector for the values found. + */ +char ** +cvs_strsplit(char *str, const char *sep) +{ + char **argv, **nargv; + char *cp, *p; + int i = 0; + + cp = xstrdup(str); + argv = (char **)xmalloc((i+1) * sizeof(char *)); + + while ((p = strsep(&cp, sep)) != NULL) { + argv[i++] = p; + nargv = (char **)xrealloc((void *)argv, (i+1) * sizeof(char *)); + argv = nargv; + } + argv[i] = NULL; + + return (argv); +} diff --git a/usr.bin/cvs/util.h b/usr.bin/cvs/util.h index 9bb8200b286..89d5aebe6c1 100644 --- a/usr.bin/cvs/util.h +++ b/usr.bin/cvs/util.h @@ -1,4 +1,4 @@ -/* $OpenBSD: util.h,v 1.1 2006/03/15 19:59:36 niallo Exp $ */ +/* $OpenBSD: util.h,v 1.2 2006/03/17 08:51:45 xsa Exp $ */ /* * Copyright (c) 2006 Niall O'Higgins <niallo@openbsd.org> * All rights reserved. @@ -75,5 +75,6 @@ BUF *cvs_patchfile(const char *, const char *, struct cvs_lines *cvs_splitlines(const char *); void cvs_freelines(struct cvs_lines *); int cvs_yesno(void); +char **cvs_strsplit(char *, const char *); -#endif +#endif /* UTIL_H */ diff --git a/usr.bin/rcs/rlog.c b/usr.bin/rcs/rlog.c index 819a497bbfd..b93c1e8e555 100644 --- a/usr.bin/rcs/rlog.c +++ b/usr.bin/rcs/rlog.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rlog.c,v 1.29 2006/03/16 04:04:57 ray Exp $ */ +/* $OpenBSD: rlog.c,v 1.30 2006/03/17 08:51:45 xsa Exp $ */ /* * Copyright (c) 2005 Joris Vink <joris@openbsd.org> * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org> @@ -32,7 +32,6 @@ static int rlog_file(const char *, const char *); static void rlog_rev_print(struct rcs_delta *); -static char **rlog_strsplit(char *, const char *); #define REVSEP "----------------------------" #define REVEND \ @@ -236,7 +235,7 @@ rlog_rev_print(struct rcs_delta *rdp) /* if locker is empty, no need to go further. */ if (rdp->rd_locker == NULL) return; - largv = rlog_strsplit(llist, ","); + largv = cvs_strsplit(llist, ","); for (i = 0; largv[i] != NULL; i++) { if (strcmp(rdp->rd_locker, largv[i]) == 0) { found++; @@ -248,7 +247,7 @@ rlog_rev_print(struct rcs_delta *rdp) } /* -sstates */ if (slist != NULL) { - sargv = rlog_strsplit(slist, ","); + sargv = cvs_strsplit(slist, ","); for (i = 0; sargv[i] != NULL; i++) { if (strcmp(rdp->rd_state, sargv[i]) == 0) { found++; @@ -260,7 +259,7 @@ rlog_rev_print(struct rcs_delta *rdp) /* -w[logins] */ if (wflag == 1) { if (wlist != NULL) { - wargv = rlog_strsplit(wlist, ","); + wargv = cvs_strsplit(wlist, ","); for (i = 0; wargv[i] != NULL; i++) { if (strcmp(rdp->rd_author, wargv[i]) == 0) { found++; @@ -301,29 +300,3 @@ rlog_rev_print(struct rcs_delta *rdp) rdp->rd_author, rdp->rd_state); printf("%s", rdp->rd_log); } - -/* - * rlog_strsplit() - * - * Split a string <str> of <sep>-separated values and allocate - * an argument vector for the values found. - */ -static char ** -rlog_strsplit(char *str, const char *sep) -{ - char **argv, **nargv; - char *cp, *p; - int i = 0; - - cp = xstrdup(str); - argv = (char **)xmalloc((i+1) * sizeof(char *)); - - while ((p = strsep(&cp, sep)) != NULL) { - argv[i++] = p; - nargv = (char **)xrealloc((void *)argv, (i+1) * sizeof(char *)); - argv = nargv; - } - argv[i] = NULL; - - return (argv); -} |