diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2006-04-12 08:23:31 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2006-04-12 08:23:31 +0000 |
commit | d168187781096ebce8875465a1ac0d8ef42bdef8 (patch) | |
tree | 16ed20858dec9d8349da6c6d839bb2bb8526fc6e /usr.bin/rcs/rcsdiff.c | |
parent | d9349acd8c7813ac3bc17ef771803b40fdf1bcbc (diff) |
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/rcsdiff.c')
-rw-r--r-- | usr.bin/rcs/rcsdiff.c | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/usr.bin/rcs/rcsdiff.c b/usr.bin/rcs/rcsdiff.c index 8178280ee2c..fa9b3f0f8b3 100644 --- a/usr.bin/rcs/rcsdiff.c +++ b/usr.bin/rcs/rcsdiff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsdiff.c,v 1.45 2006/04/10 19:49:45 joris Exp $ */ +/* $OpenBSD: rcsdiff.c,v 1.46 2006/04/12 08:23:30 ray Exp $ */ /* * Copyright (c) 2005 Joris Vink <joris@openbsd.org> * All rights reserved. @@ -38,12 +38,12 @@ int rcsdiff_main(int argc, char **argv) { int i, ch, status; - RCSNUM *rev, *rev2, *frev; + RCSNUM *rev1, *rev2; RCSFILE *file; - char fpath[MAXPATHLEN]; + char fpath[MAXPATHLEN], *rev_str1, *rev_str2; - rev = RCS_HEAD_REV; - rev2 = NULL; + rev1 = rev2 = NULL; + rev_str1 = rev_str2 = NULL; status = 0; strlcpy(diffargs, "diff", sizeof(diffargs)); @@ -75,13 +75,7 @@ rcsdiff_main(int argc, char **argv) diff_format = D_UNIFIED; break; case 'r': - if (rev == RCS_HEAD_REV) { - if ((rev = rcsnum_parse(rcs_optarg)) == NULL) - fatal("bad revision number"); - } else { - if ((rev2 = rcsnum_parse(rcs_optarg)) == NULL) - fatal("bad revision number"); - } + rcs_setrevstr2(&rev_str1, &rev_str2, rcs_optarg); break; case 'T': /* @@ -123,10 +117,14 @@ rcsdiff_main(int argc, char **argv) rcs_kwexp_set(file, kflag); - if (rev == RCS_HEAD_REV) - frev = file->rf_head; - else - frev = rev; + if (rev_str1 != NULL) { + if ((rev1 = rcsnum_parse(rev_str1)) == NULL) + fatal("bad revision number"); + } + if (rev_str2 != NULL) { + if ((rev2 = rcsnum_parse(rev_str2)) == NULL) + fatal("bad revision number"); + } if (verbose == 1) { fprintf(stderr, "%s\n", RCS_DIFF_DIV); @@ -135,21 +133,30 @@ rcsdiff_main(int argc, char **argv) diff_file = argv[i]; - if (rev2 == NULL) { - if (rcsdiff_file(file, frev, argv[i]) < 0) { - rcs_close(file); + /* No revisions given. */ + if (rev_str1 == NULL) { + if (rcsdiff_file(file, file->rf_head, argv[i]) < 0) status = 2; - continue; - } + /* One revision given. */ + } else if (rev_str2 == NULL) { + if (rcsdiff_file(file, rev1, argv[i]) < 0) + status = 2; + /* Two revisions given. */ } else { - if (rcsdiff_rev(file, rev, rev2) < 0) { - rcs_close(file); + if (rcsdiff_rev(file, rev1, rev2) < 0) status = 2; - continue; - } } rcs_close(file); + + if (rev1 != NULL) { + rcsnum_free(rev1); + rev1 = NULL; + } + if (rev2 != NULL) { + rcsnum_free(rev2); + rev2 = NULL; + } } return (status); |