summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorXavier Santolaria <xsa@cvs.openbsd.org>2005-09-05 19:29:43 +0000
committerXavier Santolaria <xsa@cvs.openbsd.org>2005-09-05 19:29:43 +0000
commit84cabb9dde419d41a6b7da8d5527837991e17af6 (patch)
tree20f55c6e3f47eaa096f500347ce50a2f0d96d4a7 /usr.bin
parent731ce31b5e8927582379e4784d1f82336529a595 (diff)
add new functions: cvs_write_tagfile() and cvs_parse_tagfile(),
write and parse a CVS/Tag file. Ok joris@.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/cvs/cvs.h7
-rw-r--r--usr.bin/cvs/util.c122
2 files changed, 125 insertions, 4 deletions
diff --git a/usr.bin/cvs/cvs.h b/usr.bin/cvs/cvs.h
index 0d16dbc8080..ec2491d05a3 100644
--- a/usr.bin/cvs/cvs.h
+++ b/usr.bin/cvs/cvs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cvs.h,v 1.80 2005/08/16 16:34:19 xsa Exp $ */
+/* $OpenBSD: cvs.h,v 1.81 2005/09/05 19:29:42 xsa Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -139,6 +139,7 @@
#define CVS_PATH_LOGENTRIES CVS_PATH_CVSDIR "/Entries.Log"
#define CVS_PATH_ROOTSPEC CVS_PATH_CVSDIR "/Root"
#define CVS_PATH_REPOSITORY CVS_PATH_CVSDIR "/Repository"
+#define CVS_PATH_TAG CVS_PATH_CVSDIR "/Tag"
/* flags for cmd_flags */
@@ -367,7 +368,7 @@ void cvsroot_free(struct cvsroot *);
struct cvsroot *cvsroot_get(const char *);
-/* Entries API */
+/* entries.c */
CVSENTRIES *cvs_ent_open(const char *, int);
struct cvs_ent *cvs_ent_get(CVSENTRIES *, const char *);
struct cvs_ent *cvs_ent_next(CVSENTRIES *);
@@ -412,6 +413,8 @@ int cvs_create_dir(const char *, int, char *, char *);
char *cvs_rcs_getpath(CVSFILE *, char *, size_t);
char **cvs_makeargv(const char *, int *);
void cvs_freeargv(char **, int);
+void cvs_write_tagfile(char *, char *, int);
+void cvs_parse_tagfile(char **, char **, int *);
size_t cvs_path_cat(const char *, const char *, char *, size_t);
diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c
index 285a65b431c..0136acafeb8 100644
--- a/usr.bin/cvs/util.c
+++ b/usr.bin/cvs/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.50 2005/08/17 08:35:53 xsa Exp $ */
+/* $OpenBSD: util.c,v 1.51 2005/09/05 19:29:42 xsa Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -281,7 +281,6 @@ cvs_splitpath(const char *path, char *base, size_t blen, char **file)
return (0);
}
-
/*
* cvs_getargv()
*
@@ -789,3 +788,122 @@ cvs_rcs_getpath(CVSFILE *file, char *buf, size_t len)
return (buf);
}
+
+/*
+ * cvs_write_tagfile()
+ *
+ * Write the CVS/Tag file for current directory.
+ */
+void
+cvs_write_tagfile(char *tag, char *date, int nb)
+{
+ FILE *fp;
+ char tagpath[MAXPATHLEN];
+
+ if (cvs_noexec == 1)
+ return;
+
+ if (strlcpy(tagpath, CVS_PATH_TAG, sizeof(tagpath)) >= sizeof(tagpath))
+ return;
+
+ if ((tag != NULL) || (date != NULL)) {
+ fp = fopen(tagpath, "w+");
+ if (fp == NULL) {
+ if (errno != ENOENT)
+ cvs_log(LP_NOTICE,
+ "failed to open `%s' : %s", tagpath,
+ strerror(errno));
+ return;
+ }
+ if (tag != NULL) {
+ if (nb != 0)
+ fprintf(fp, "N%s\n", tag);
+ else
+ fprintf(fp, "T%s\n", tag);
+ } else {
+ fprintf(fp, "D%s\n", date);
+ }
+ (void)fclose(fp);
+ } else {
+ cvs_unlink(tagpath);
+ return;
+ }
+}
+
+/*
+ * cvs_parse_tagfile()
+ *
+ * Parse the CVS/Tag file for current directory.
+ *
+ * If it contains a branch tag, sets <tagp>.
+ * If it contains a date, sets <datep>.
+ * If it contains a non-branch tag, sets <nbp>.
+ *
+ * Returns nothing but an error message, and sets <tagp>, <datep> to NULL
+ * and <nbp> to 0.
+ */
+void
+cvs_parse_tagfile(char **tagp, char **datep, int *nbp)
+{
+ FILE *fp;
+ int linenum;
+ size_t len;
+ char linebuf[128], tagpath[MAXPATHLEN];
+
+ if (tagp != NULL)
+ *tagp = (char *)NULL;
+
+ if (datep != NULL)
+ *datep = (char *)NULL;
+
+ if (nbp != NULL)
+ *nbp = 0;
+
+ if (strlcpy(tagpath, CVS_PATH_TAG, sizeof(tagpath)) >= sizeof(tagpath))
+ return;
+
+ fp = fopen(tagpath, "r");
+ if (fp == NULL) {
+ if (errno != ENOENT)
+ cvs_log(LP_NOTICE, "failed to open `%s' : %s", tagpath,
+ strerror(errno));
+ return;
+ }
+
+ linenum = 0;
+
+ while (fgets(linebuf, (int)sizeof(linebuf), fp) != NULL) {
+ linenum++;
+ if ((len = strlen(linebuf)) == 0)
+ continue;
+ if (linebuf[len -1] != '\n') {
+ cvs_log(LP_WARN, "line too long in `%s:%d'", tagpath,
+ linenum);
+ break;
+ }
+ linebuf[--len] = '\0';
+
+ switch(*linebuf) {
+ case 'T':
+ if (tagp != NULL)
+ *tagp = strdup(linebuf);
+ break;
+ case 'D':
+ if (datep != NULL)
+ *datep = strdup(linebuf);
+ break;
+ case 'N':
+ if (tagp != NULL)
+ *tagp = strdup(linebuf);
+ if (nbp != NULL)
+ *nbp = 1;
+ break;
+ default:
+ break;
+ }
+ }
+ if (ferror(fp))
+ cvs_log(LP_NOTICE, "failed to read line from `%s'", tagpath);
+
+ (void)fclose(fp);
+}