From 1b639b22eb9e94892080e1846608337f34b27b7b Mon Sep 17 00:00:00 2001 From: Jean-Francois Brousseau Date: Fri, 25 Feb 2005 20:05:43 +0000 Subject: add rcsnum_parse() to simplify the most common case --- usr.bin/cvs/rcs.h | 3 ++- usr.bin/cvs/rcsnum.c | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/usr.bin/cvs/rcs.h b/usr.bin/cvs/rcs.h index 3a4f8064fd5..002892460bf 100644 --- a/usr.bin/cvs/rcs.h +++ b/usr.bin/cvs/rcs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.h,v 1.7 2005/01/13 20:50:57 jfb Exp $ */ +/* $OpenBSD: rcs.h,v 1.8 2005/02/25 20:05:41 jfb Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -158,6 +158,7 @@ BUF* rcs_patch (const char *, const char *); size_t rcs_stresc (int, const char *, char *, size_t *); RCSNUM* rcsnum_alloc (void); +RCSNUM* rcsnum_parse (const char *); void rcsnum_free (RCSNUM *); int rcsnum_aton (const char *, char **, RCSNUM *); char* rcsnum_tostr (const RCSNUM *, char *, size_t); diff --git a/usr.bin/cvs/rcsnum.c b/usr.bin/cvs/rcsnum.c index 693af871326..ac7462f2be2 100644 --- a/usr.bin/cvs/rcsnum.c +++ b/usr.bin/cvs/rcsnum.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsnum.c,v 1.6 2005/01/03 22:10:12 jfb Exp $ */ +/* $OpenBSD: rcsnum.c,v 1.7 2005/02/25 20:05:42 jfb Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -58,12 +58,34 @@ rcsnum_alloc(void) } +/* + * rcsnum_parse() + * + * Parse a string specifying an RCS number and return the corresponding RCSNUM. + */ +RCSNUM* +rcsnum_parse(const char *str) +{ + char *ep; + RCSNUM *num; + + if ((num = rcsnum_alloc()) == NULL) + return (NULL); + + if (rcsnum_aton(str, &ep, num) < 0) { + rcsnum_free(num); + return (NULL); + } + + return (num); +} + + /* * rcsnum_free() * * Free an RCSNUM structure previously allocated with rcsnum_alloc(). */ - void rcsnum_free(RCSNUM *rn) { -- cgit v1.2.3