summaryrefslogtreecommitdiff
path: root/usr.bin/cvs
diff options
context:
space:
mode:
authorXavier Santolaria <xsa@cvs.openbsd.org>2006-03-17 08:51:46 +0000
committerXavier Santolaria <xsa@cvs.openbsd.org>2006-03-17 08:51:46 +0000
commit54c45ec4af9c4db50ed7a048accb4d2848d0a767 (patch)
tree8da4136138f8118eab762112eac24a4f5268fdbe /usr.bin/cvs
parent7b682b3417ffb86bfa19d25ced33eca7604ca193 (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@.
Diffstat (limited to 'usr.bin/cvs')
-rw-r--r--usr.bin/cvs/util.c29
-rw-r--r--usr.bin/cvs/util.h5
2 files changed, 31 insertions, 3 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 */