summaryrefslogtreecommitdiff
path: root/usr.bin/cvs
diff options
context:
space:
mode:
authorJean-Francois Brousseau <jfb@cvs.openbsd.org>2005-03-02 04:19:35 +0000
committerJean-Francois Brousseau <jfb@cvs.openbsd.org>2005-03-02 04:19:35 +0000
commite1daf3d4def1db357348b8737c704ec43905345c (patch)
treed41275601fc7b3371387b3bb9745fc4997669663 /usr.bin/cvs
parent5f119ab47b093c9775f042875dfc844aa9961dab (diff)
- rcs_write() is now static
- when setting a new expansion mode, do not attempt to free the previous expansion mode if the pointer is NULL - add a bunch of new functions: * rcs_sym_remove() to remove a symbol * rcs_sym_getrev() to retrieve the revision number of a symbol * rcs_desc_{s,g}et() to manipulate an RCS file's description
Diffstat (limited to 'usr.bin/cvs')
-rw-r--r--usr.bin/cvs/rcs.c109
-rw-r--r--usr.bin/cvs/rcs.h24
2 files changed, 119 insertions, 14 deletions
diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c
index 9f0e39e51af..33f39108c02 100644
--- a/usr.bin/cvs/rcs.c
+++ b/usr.bin/cvs/rcs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.c,v 1.26 2005/02/27 00:22:08 jfb Exp $ */
+/* $OpenBSD: rcs.c,v 1.27 2005/03/02 04:19:34 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -147,6 +147,7 @@ static struct rcs_key {
#define RCS_NKEYS (sizeof(rcs_keys)/sizeof(rcs_keys[0]))
+static int rcs_write (RCSFILE *);
static int rcs_parse (RCSFILE *);
static int rcs_parse_admin (RCSFILE *);
static int rcs_parse_delta (RCSFILE *);
@@ -314,7 +315,7 @@ rcs_close(RCSFILE *rfp)
* path is in <rf_path>.
* Returns 0 on success, or -1 on failure.
*/
-int
+static int
rcs_write(RCSFILE *rfp)
{
FILE *fp;
@@ -453,6 +454,107 @@ rcs_sym_add(RCSFILE *rfp, const char *sym, RCSNUM *snum)
/*
+ * rcs_sym_remove()
+ *
+ * Remove the symbol with name <sym> from the symbol list for the RCS file
+ * <file>. If no such symbol is found, the call fails and returns with an
+ * error.
+ * Returns 0 on success, or -1 on failure.
+ */
+int
+rcs_sym_remove(RCSFILE *file, const char *sym)
+{
+ struct rcs_sym *symp;
+
+ TAILQ_FOREACH(symp, &(file->rf_symbols), rs_list)
+ if (strcmp(symp->rs_name, sym) == 0)
+ break;
+
+ if (symp == NULL) {
+ cvs_log(LP_ERR, "%s: no such symbol `%s'", file->rf_path, sym);
+ return (-1);
+ }
+
+ TAILQ_REMOVE(&(file->rf_symbols), symp, rs_list);
+ free(symp->rs_name);
+ rcsnum_free(symp->rs_num);
+ free(symp);
+
+ /* not synced anymore */
+ file->rf_flags &= ~RCS_SYNCED;
+
+ return (0);
+}
+
+
+/*
+ * rcs_sym_getrev()
+ *
+ * Retrieve the RCS revision number associated with the symbol <sym> for the
+ * RCS file <file>. The returned value is a dynamically-allocated copy and
+ * should be freed by the caller once they are done with it.
+ * Returns the RCSNUM on success, or NULL on failure.
+ */
+RCSNUM*
+rcs_sym_getrev(RCSFILE *file, const char *sym)
+{
+ RCSNUM *num;
+ struct rcs_sym *symp;
+
+ num = NULL;
+
+ TAILQ_FOREACH(symp, &(file->rf_symbols), rs_list)
+ if (strcmp(symp->rs_name, sym) == 0)
+ break;
+
+ if (symp == NULL) {
+ /* XXX set error */
+ } else if (((num = rcsnum_alloc()) != NULL) &&
+ (rcsnum_cpy(symp->rs_num, num, 0) < 0)) {
+ rcsnum_free(num);
+ num = NULL;
+ }
+
+ return (num);
+}
+
+
+/*
+ * rcs_desc_get()
+ *
+ * Retrieve the description for the RCS file <file>.
+ */
+const char*
+rcs_desc_get(RCSFILE *file)
+{
+ return (file->rf_desc);
+}
+
+
+/*
+ * rcs_desc_set()
+ *
+ * Set the description for the RCS file <file>.
+ * Returns 0 on success, or -1 on failure.
+ */
+int
+rcs_desc_set(RCSFILE *file, const char *desc)
+{
+ char *tmp;
+
+ if ((tmp = strdup(desc)) == NULL)
+ return (-1);
+
+ if (file->rf_desc != NULL)
+ free(file->rf_desc);
+ file->rf_desc = tmp;
+ file->rf_flags &= ~RCS_SYNCED;
+
+ return (0);
+}
+
+
+/*
* rcs_patch()
*
* Apply an RCS-format patch pointed to by <patch> to the file contents
@@ -766,7 +868,8 @@ rcs_kwexp_set(RCSFILE *file, int mode)
return (-1);
}
- free(file->rf_expand);
+ if (file->rf_expand != NULL)
+ free(file->rf_expand);
file->rf_expand = tmp;
return (0);
diff --git a/usr.bin/cvs/rcs.h b/usr.bin/cvs/rcs.h
index 3731ff98965..fa4d8a8e06f 100644
--- a/usr.bin/cvs/rcs.h
+++ b/usr.bin/cvs/rcs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.h,v 1.9 2005/02/27 00:22:08 jfb Exp $ */
+/* $OpenBSD: rcs.h,v 1.10 2005/03/02 04:19:34 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -145,16 +145,18 @@ typedef struct rcs_file {
} RCSFILE;
-RCSFILE* rcs_open (const char *, int, ...);
-void rcs_close (RCSFILE *);
-int rcs_write (RCSFILE *);
-int rcs_sym_add (RCSFILE *, const char *, RCSNUM *);
-int rcs_sym_remove (RCSFILE *, const char *);
-BUF* rcs_getrev (RCSFILE *, RCSNUM *);
-BUF* rcs_gethead (RCSFILE *);
-RCSNUM* rcs_getrevbydate (RCSFILE *, struct tm *);
-int rcs_kwexp_set (RCSFILE *, int);
-int rcs_kwexp_get (RCSFILE *);
+RCSFILE* rcs_open (const char *, int, ...);
+void rcs_close (RCSFILE *);
+int rcs_sym_add (RCSFILE *, const char *, RCSNUM *);
+int rcs_sym_remove (RCSFILE *, const char *);
+RCSNUM* rcs_sym_getrev (RCSFILE *, const char *);
+BUF* rcs_getrev (RCSFILE *, RCSNUM *);
+BUF* rcs_gethead (RCSFILE *);
+RCSNUM* rcs_getrevbydate (RCSFILE *, struct tm *);
+const char* rcs_desc_get (RCSFILE *);
+int rcs_desc_set (RCSFILE *, const char *);
+int rcs_kwexp_set (RCSFILE *, int);
+int rcs_kwexp_get (RCSFILE *);
int rcs_kflag_get (const char *);
void rcs_kflag_usage (void);