diff options
author | 2006-04-12 08:23:30 +0000 | |
---|---|---|
committer | 2006-04-12 08:23:30 +0000 | |
commit | 36076781ed349d9f1c1781c3a0d2fc4f41e78ef1 (patch) | |
tree | 9685eb016cd630e4198cf39af0e03449c68c8147 /usr.bin/rcs/rcsprog.c | |
parent | xmalloc(); memset(); -> xcalloc(); (diff) | |
download | wireguard-openbsd-36076781ed349d9f1c1781c3a0d2fc4f41e78ef1.tar.xz wireguard-openbsd-36076781ed349d9f1c1781c3a0d2fc4f41e78ef1.zip |
Clean up <rev> handling. Whenever a revision is specified after a
flag, it calls one of two new functions: rcs_setrevstr() or
rcs_setrevstr2(). rcs_setrevstr() sets a string to another string,
and complains if it was set more than once. rcs_setrevstr2() takes
two strings, sets one after the other, and fatal()s if more than
two strings were given.
All <rev> handling is now done in the loop that goes through each
argv. This is necessary for parsing symbols, which will be much
easier after this.
Along the way a lot of memory leaks were cleaned up. There is one
area where rcs_set_rev() is called, which allocates a RCSNUM and
stores it in pb.newrev, but it segfaults whenever I try to rcsnum_free()
it. I put an /* XXX */ comment there for now.
Passes regression tests and the code is less complicated in some
ways (to me).
Suggestions and OK xsa@
Diffstat (limited to 'usr.bin/rcs/rcsprog.c')
-rw-r--r-- | usr.bin/rcs/rcsprog.c | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/usr.bin/rcs/rcsprog.c b/usr.bin/rcs/rcsprog.c index d69d6e9a433..33045e38742 100644 --- a/usr.bin/rcs/rcsprog.c +++ b/usr.bin/rcs/rcsprog.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsprog.c,v 1.96 2006/04/11 08:07:35 ray Exp $ */ +/* $OpenBSD: rcsprog.c,v 1.97 2006/04/12 08:23:30 ray Exp $ */ /* * Copyright (c) 2005 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -75,16 +75,13 @@ sighdlr(int sig) _exit(1); } +/* + * Allocate an RCSNUM and store in <rev>. + */ void rcs_set_rev(const char *str, RCSNUM **rev) { - if (str == NULL) - return; - - if ((*rev != NULL) && (*rev != RCS_HEAD_REV)) - cvs_log(LP_WARN, "redefinition of revision number"); - - if ((*rev = rcsnum_parse(str)) == NULL) + if (str == NULL || (*rev = rcsnum_parse(str)) == NULL) fatal("bad revision number '%s'", str); } @@ -361,6 +358,36 @@ rcs_statfile(char *fname, char *out, size_t len) return (0); } +/* + * Set <str> to <new_str>. Print warning if <str> is redefined. + */ +void +rcs_setrevstr(char **str, char *new_str) +{ + if (new_str == NULL) + return; + if (*str != NULL) + cvs_log(LP_WARN, "redefinition of revision number"); + *str = new_str; +} + +/* + * Set <str1> or <str2> to <new_str>, depending on which is not set. + * If both are set, error out. + */ +void +rcs_setrevstr2(char **str1, char **str2, char *new_str) +{ + if (new_str == NULL) + return; + if (*str1 == NULL) + *str1 = new_str; + else if (*str2 == NULL) + *str2 = new_str; + else + fatal("too many revision numbers"); +} + int main(int argc, char **argv) { |