History log of /openbsd-current/usr.bin/rcs/co.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.127 11-Aug-2023 guenther

Switch rcs_{get,set}_mtime() from returning and taking a time_t to
doing so with a struct timespec and then use tv_nsec = UTIME_OMIT
instead of a (time_t)-1 as a "do nothing" value. They can then
fully preserve the timestamp

ok millert@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.126 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


# 1.125 26-Apr-2019 millert

There was an extra newline in some cases and missing one in others.
OK joris@


Revision tags: OPENBSD_6_5_BASE
# 1.124 09-Jan-2019 joris

Delay keyword expansion in co until after the locks have been resolved.

This way the expansion can happen with the correct values and files do not
show up as modified.


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.123 29-Aug-2017 otto

kill const and string artithmetic related warnings; ok millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.122 21-Oct-2015 millert

Style fixes; from Ilya Kaliman


Revision tags: OPENBSD_5_8_BASE
# 1.121 13-Jun-2015 nicm

Convert xfree to free. From Fritjof Bornebusch. ok deraadt


Revision tags: OPENBSD_5_7_BASE
# 1.120 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.119 10-Oct-2014 otto

Zap some stored values never read; From Fritjof Bornebusch; ok nicm@


# 1.118 02-Oct-2014 otto

exit in usage functions themselves; from Fritjof Bornebusch; ok nicm@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.117 16-Apr-2013 deraadt

remove wrong casts; ok millert


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.116 03-Dec-2010 chl

add missing header needed by futimes()

ok stsp@


# 1.115 20-Oct-2010 tobias

Remove the need for rp_file in parser structure, instead keep only one
FILE pointer in RCSFILE. This fixes some ugliness in closing an
fdopen()ed FILE and its underlying file descriptor.

Notified by Joerg Sonnenberger <joerg at britannica dot bec to de>

discussed with and ok nicm


# 1.114 08-Sep-2010 tobias

Set rcs_suffixes to default value on initialization.

ok ray zinovik


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jul-2010 ray

Check date_parse return values.

OK xsa


# 1.112 28-Jul-2010 ray

Make BUFs autoextend by default. This was already done in OpenCVS
a while ago.

OK zinovik nicm


# 1.111 23-Jul-2010 ray

Reduce variable/function name and whitespace differences between
cvs/rcs.

OK xsa zinovik


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.110 25-Feb-2009 ray

Checking if a file is ASCII should only be done when diffing, because
the non-ASCII characters could be printed to the screen. For
checking in files, checking out files, merging files, and removing
revisions of files, we do so regardless of whether the files are
ASCII or binary.

Fixes PR6031.

OK joris and deraadt.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.109 03-Jul-2007 ray

Rename rcs_diffreg() to diffreg().

OK joris@


# 1.108 30-Jun-2007 xsa

Sync revisions and time buffers size to be consistent with each others.
Simplifies further size tweaks if needed.
OK ray@.


# 1.107 08-Jun-2007 xsa

If strict locking is disabled, make file writable by owner on checkout.
Matches GNU's behaviour. From Pierre Riteau (long time ago).


# 1.106 07-Jun-2007 xsa

Correct exit value when one of the files specified cannot be checked out.
Matches GNU's behaviour. From Pierre Riteau (long time ago).


Revision tags: OPENBSD_4_1_BASE
# 1.105 27-Feb-2007 xsa

As done in OpenCVS, general includes cleanup sweep. OK otto@.


# 1.104 22-Feb-2007 otto

If a ,suffix file is given as an arg to ci and co, strip it. Avoids
potential disasters. Initial diff from niallo@, ok niallo@ joris@


# 1.103 21-Feb-2007 niallo

make sure checkout_rev() sets correct file permissions via file->rf_mode
in case where fstat() of file->rf_fd won't give us right mode.

fixes PR #5383

ok xsa@


# 1.102 18-Feb-2007 xsa

keep correct permissions on the RCS file when locking/unlocking the file
with ci and co. fixes PR 5379.
OK millert@ joris@.


# 1.101 01-Feb-2007 millert

When checking to see if a checked-out copy of the file is the same
as what is in the repo, expand keywords before doing the diff.
OK xsa@


# 1.100 10-Nov-2006 millert

Unlike GNU rcs, our co will not overwrite an existing file, even
if the existing file is not writable. While safer, this can be
annoying. I've changed things to compare the version of the file
being checked out with its current contents and, if they are the
same, to allow the checkout without user intervention. The behavior
when there is a writable version of the file is unchanged. OK xsa@


# 1.99 09-Nov-2006 millert

Simplify stripping of write bits from file mode.
Add support for reusing the checkin message for multiple files, ala GNU
Fix the message when you abort a checkout and the file was not writable.
OK joris@ niallo@


# 1.98 12-Oct-2006 niallo

- convert some warnx() to warn(), which fixes a few stupidly un-informative error messages (found by tom@)
- make rcs_choosefile() save wrt errno, input from ray@

ok joris@ xsa@


Revision tags: OPENBSD_4_0_BASE
# 1.97 07-Aug-2006 ray

More strlcpy/strlcat -> snprintf/xasprintf cleanup.

OK joris@


# 1.96 01-Aug-2006 ray

Reduce rcs_buf_release() usage, improving binary support.

OK niallo@


# 1.95 03-Jun-2006 niallo

- correctly handle binary files; say bye bye to using c strings for deltatexts.

"slap it in" joris@


# 1.94 28-May-2006 ray

Remove a lot of xstrdup() calls in getopt() loops, which are usually
unnecessary. These xstrdup() calls don't call xfree() before anyway,
so if a flag is given multiple times memory leaks would have resulted.

OK joris@


# 1.93 27-May-2006 ray

Rename RCSFILE.fd to RCSFILE.rf_fd, plus minor spacing nits. No
binary change.

OK xsa@


# 1.92 27-May-2006 ray

Remove rcs_statfile(). It was just a wrapper for rcs_choosefile(),
handling exceptions oddly.

OK joris@


# 1.91 17-May-2006 xsa

fix printf's


# 1.90 11-May-2006 xsa

fix informative msg's wrt to -q and stderr. now matches gnu/usr.bin/rcs.


# 1.89 09-May-2006 ray

Remove /* NOTREACHED */ comments, now that lint is smart about
__dead. I never should have put them there.

OK xsa@.


# 1.88 05-May-2006 ray

o GNU ci returns 0 when a file is reverted (co -l file; ci file).
o Don't unlock file after revert.
o Fix spelling.

Passes extra tests in GNU rcstest.

OK niallo@.


# 1.87 29-Apr-2006 ray

Check return values for all strlcpy, and strlcat calls.

OK xsa@ and probably others.


# 1.86 26-Apr-2006 joris

prevent file races by obtaining an fd for the RCS file and
do our operations on that, this is safe and guarantees we
can operate on the file until we close(2) it.

a fix is coming for the remaining races in our diff code.
okay niallo@ and ray@


# 1.85 26-Apr-2006 joris

fork our code we shared between openrcs/cvs into the openrcs dir.

this was starting to become inhuman to maintain without
ugly ugly hacks in the shared code, and it will be easier
to make specific changes for openrcs without touching the
soon-to-be-replaced opencvs code.


# 1.84 25-Apr-2006 xsa

fatal() -> err()/errx() as we try to not depend on heavy cvs_log().
OK joriski.


# 1.83 24-Apr-2006 xsa

be consistent in error messages for wrongly specified keyword substitution
mode for `-k'.


# 1.82 21-Apr-2006 xsa

move shared functions into rcsutil.[ch]; this makes rcsprog.c cleaner;
"the voices in my head say OK!" joris@.


# 1.81 21-Apr-2006 xsa

remove overkill cvs_log() and rather use warn()/warnx().
OK ray@ and discussed with joris@.


# 1.80 21-Apr-2006 xsa

switch -p handling to bitwise flags; OK ray@.


# 1.79 19-Apr-2006 xsa

switch -q handling to bitwise flags; OK ray@ niallo@.


# 1.78 15-Apr-2006 pat

Plug some memory leaks; ok niallo@


# 1.77 14-Apr-2006 deraadt

excessive addition to brackets is a mental disease. you will go
blind, too. seek help. no binary change, ok joris


# 1.76 13-Apr-2006 joris

correctly handle RCS files without any revisions;
original diff from ray@, crafted into shape by myself.

okay ray@


# 1.75 13-Apr-2006 ray

*** empty log message ***


# 1.74 12-Apr-2006 deraadt

spaces


# 1.73 12-Apr-2006 ray

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@


# 1.72 10-Apr-2006 xsa

change rcs_kwexp_set() return type to void and simplify its use. OK niallo@.


# 1.71 09-Apr-2006 niallo

- don't print out warnings about locking when they are actually wrong and
just confuse the user.

ok and input joris@


# 1.70 06-Apr-2006 xsa

-z can take no argument.


# 1.69 30-Mar-2006 joris

first part of supporting branches in openrcs. right now we can only
check them out. commit is not working yet, but will be soon.

tested by myself and ray@
okay ray@


# 1.68 29-Mar-2006 ray

More closely matches GNU behavior, passes more GNU rcstest tests.

OK niallo@


# 1.67 27-Mar-2006 niallo

- properly implement GNU file modes. basically, checkout will inherit
permissions from rcs file and initial checkin will inherit permissions from
working file.

problem spotted by uwe@

ok ray@ xsa@


# 1.66 24-Mar-2006 ray

Allow the -x flag to be used without an extension.

``that makes sense'' xsa@


# 1.65 17-Mar-2006 niallo

- co usage() says we support -I, so set the flags and revision.

ok xsa@


# 1.64 16-Mar-2006 niallo

- checkout_rev() can fail, in which case we want a non-zero exit code.

ok joris@


# 1.63 16-Mar-2006 xsa

error message fix; respect -q too. Ok ray@.


# 1.62 16-Mar-2006 ray

Follow exit() with /* NOTREACHED*/ for lint.

``OK niallo@'' niallo@


# 1.61 16-Mar-2006 ray

Currently co(1) overwrites files that the current user doesn't have
write permissions for. If you own the directory, that means your
existing file, mode 000, is blown away without prompting you. GNU
RCS does this as well.

This fixes changes co(1) to always prompt if a file exists. This
breaks GNU compatibility but I think it's more important that we
prevent co(1) from overwriting files with strict permissions without
even prompting.

``makes sense'' xsa to an earlier diff


# 1.60 15-Mar-2006 niallo

- use shared cvs_yesno() for yesno prompt, fixing an issue spotted by
deraadt@

- while here, remove unecessary cast also spotted by deraadt@

ok ray@ xsa@


# 1.59 07-Mar-2006 joris

-z support for RCS;


# 1.58 06-Mar-2006 xsa

missing informative message after call to checkout_rev().


# 1.57 06-Mar-2006 xsa

should also have removed those newlines in previous commit.


# 1.56 06-Mar-2006 xsa

missing newline in checkout_rev(); spotted by joris@.


# 1.55 05-Mar-2006 niallo

our deltatexts were sometimes different from gnu. rcs_getrev() was
unconditionally doing keyword expansion, even when this wasn't what we
wanted e.g. in checkout_rev() and cvs_checkout_rev(). so:

- change semantics of rcs_getrev() to not do keyword expansion
- add an rcs.c api function rcs_kwexp_buf() which does this
- change both checkout_rev() and cvs_checkout_rev() to use this function.

eyeballed by xsa, joris and Ray Lai


Revision tags: OPENBSD_3_9_BASE
# 1.54 24-Feb-2006 xsa

remove extra printf;


# 1.53 14-Feb-2006 xsa

- fix behaviour when using -u and -l at the same time
- do not display some messages when checking in a file for the first time
OK niallo@.


# 1.52 05-Jan-2006 xsa

cleanup, move log.h and rcs.h inclusion into rcsprog.h;


# 1.51 02-Jan-2006 xsa

#include's cleanup; ok joris@ niallo@.


# 1.50 27-Dec-2005 niallo

- implement lazy-parsing of rcs files, that is only parse as much as we
need. this can save us much work, particularly with very large rcs files.

first of a few important performance improvements.

ok joris@


# 1.49 23-Dec-2005 joris

support co -d, which checks out the first revision who's
date is less than or equal to the given date.


# 1.48 19-Dec-2005 xsa

use fatal() if getlogin() fails;


# 1.47 10-Dec-2005 joris

switch to xmalloc stuff, me and xsa@ agreed on this a long
time ago, but we were being held back by jfb. too bad for him.

next step is to use fatal() through out the code for unrecoverable
errors instead of trying to be all nice and fluffy and reach main() again.

ok niallo@ and xsa@


# 1.46 09-Dec-2005 joris

if we are removing a lock that's not present, just check
out the file without complaining;


# 1.45 09-Dec-2005 joris

unused vars, my bad;


# 1.44 08-Dec-2005 joris

complete and correct rcs locking functionality,
it was only done partially and as a bonus, completely wrong.

seriously guys what was up with that?


# 1.43 05-Dec-2005 xsa

correctly handle `-wfoo' and `-sbar' errors; OK joris@.


# 1.42 02-Dec-2005 xsa

`-mmsg' does not belong here;


# 1.41 30-Nov-2005 xsa

check for ownership of already present writable file when checking out;


# 1.40 30-Nov-2005 xsa

writeable -> writable


# 1.39 29-Nov-2005 xsa

consistency in variables naming;


# 1.38 29-Nov-2005 xsa

some more bits for `-w[user]' support;


# 1.37 25-Nov-2005 xsa

add support for `-T' and enable it for co(1);
tested and OK niallo@. "Looks good" joris@.


# 1.36 24-Nov-2005 xsa

memset();


# 1.35 23-Nov-2005 xsa

cannot combine -kv and -l;


# 1.34 23-Nov-2005 xsa

initial bits for -T support;


# 1.33 23-Nov-2005 xsa

add support for `-kmode';


# 1.32 23-Nov-2005 xsa

sync SYNOPSIS with Reality and usage() accordingly;


# 1.31 22-Nov-2005 xsa

make `-p' work again as expected;


# 1.30 21-Nov-2005 xsa

enable `-xsuffixes' support as it has been added a few days ago
in rcs_statfile();
niallo ok


# 1.29 08-Nov-2005 xsa

nuke trailing whitespaces;


# 1.28 03-Nov-2005 niallo

- update comment for checkout_rev() for bitwise flags.


# 1.27 03-Nov-2005 niallo

- sync checkout_usage();


# 1.26 03-Nov-2005 niallo

- implement `-M' option.


# 1.25 02-Nov-2005 niallo

- update the comment for checkout_state(); it did not tell the truth
about values returned.


# 1.24 02-Nov-2005 niallo

changes from Venice:

- instead of using lots of individual flag variables, use a single int and
bitwise operations on it. while this saves memory, really it saves code
space and reduces complexity. checkout_rev() and checkout_state() in
particular benefit from these changes since their parameters where growing
really long.

- implement `-s' option in co

- implement `-M' option in ci

"I like this, go for it" joris@


# 1.23 25-Oct-2005 xsa

nuke trailing whitespaces;


# 1.22 20-Oct-2005 xsa

fix output if -p is specified; joris ok


# 1.21 19-Oct-2005 niallo

- make a bunch of changes to how we handle verbose output. this brings us
much closer in line with GNU RCS and cleans things up in general.

ok joris@, "looks fine to me" xsa@


# 1.20 19-Oct-2005 joris

add co -p support;
input from xsa@ and niallo@;


# 1.19 18-Oct-2005 joris

use rcs_set_rev() instead of duplicating code all over the
place to set a variable to the given revision number;


# 1.18 17-Oct-2005 joris

support -f flag for co;
'fine' niallo@


# 1.17 16-Oct-2005 joris

spacing;


# 1.16 16-Oct-2005 niallo

- sync checkout_usage();


# 1.15 15-Oct-2005 niallo

- if revision passed to checkout_rev() is > HEAD, assume HEAD
(like GNU RCS).
- move verbose output into checkout_rev() function itself.

"looks sane" joris@


# 1.14 15-Oct-2005 niallo

modularise checkout code into checkout_rev(). this shaves off a number
of lines in ci.c due to code re-use, and will simplify features which are in
the pipeline. no functional changes.

ok joris@


# 1.13 13-Oct-2005 joris

To be fully compatibly with the GNU RCS tools we need to have the
same way of parsing commandline options. Since getopt(3) allows spaces
between arguments and GNU RCS tools does not we needed to roll out our
own way of option handling, and here it is.

ok niallo@


# 1.12 12-Oct-2005 xsa

minor knf;


# 1.11 12-Oct-2005 deraadt

various usage cleanup; ok joris


# 1.10 10-Oct-2005 xsa

getlogin(2) sets errno;


# 1.9 10-Oct-2005 niallo

sync checkout_usage();


# 1.8 10-Oct-2005 niallo

- set permissions on checked out files correctly
- support bare `-u' and `-l' options which will check out HEAD.

note that with OpenRCS you must do `co -l -- <file>' and `co -u -- <file>'
when using bare arguments because our getopt(3) is POSIX compliant.

ok joris@


# 1.7 05-Oct-2005 joris

sync usage and add V flag;


# 1.6 05-Oct-2005 joris

- stop gcc's yapping;
- better output when locking and unlocking revisions;


# 1.5 05-Oct-2005 joris

- better output
- free frev when done


# 1.4 04-Oct-2005 joris

- support -l and -u flags;
- better output;


# 1.3 29-Sep-2005 joris

support -q flag in 'co' and 'rcs'


# 1.2 29-Sep-2005 joris

fix usage


# 1.1 29-Sep-2005 joris

put it basic checkout code


# 1.126 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


# 1.125 26-Apr-2019 millert

There was an extra newline in some cases and missing one in others.
OK joris@


Revision tags: OPENBSD_6_5_BASE
# 1.124 09-Jan-2019 joris

Delay keyword expansion in co until after the locks have been resolved.

This way the expansion can happen with the correct values and files do not
show up as modified.


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.123 29-Aug-2017 otto

kill const and string artithmetic related warnings; ok millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.122 21-Oct-2015 millert

Style fixes; from Ilya Kaliman


Revision tags: OPENBSD_5_8_BASE
# 1.121 13-Jun-2015 nicm

Convert xfree to free. From Fritjof Bornebusch. ok deraadt


Revision tags: OPENBSD_5_7_BASE
# 1.120 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.119 10-Oct-2014 otto

Zap some stored values never read; From Fritjof Bornebusch; ok nicm@


# 1.118 02-Oct-2014 otto

exit in usage functions themselves; from Fritjof Bornebusch; ok nicm@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.117 16-Apr-2013 deraadt

remove wrong casts; ok millert


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.116 03-Dec-2010 chl

add missing header needed by futimes()

ok stsp@


# 1.115 20-Oct-2010 tobias

Remove the need for rp_file in parser structure, instead keep only one
FILE pointer in RCSFILE. This fixes some ugliness in closing an
fdopen()ed FILE and its underlying file descriptor.

Notified by Joerg Sonnenberger <joerg at britannica dot bec to de>

discussed with and ok nicm


# 1.114 08-Sep-2010 tobias

Set rcs_suffixes to default value on initialization.

ok ray zinovik


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jul-2010 ray

Check date_parse return values.

OK xsa


# 1.112 28-Jul-2010 ray

Make BUFs autoextend by default. This was already done in OpenCVS
a while ago.

OK zinovik nicm


# 1.111 23-Jul-2010 ray

Reduce variable/function name and whitespace differences between
cvs/rcs.

OK xsa zinovik


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.110 25-Feb-2009 ray

Checking if a file is ASCII should only be done when diffing, because
the non-ASCII characters could be printed to the screen. For
checking in files, checking out files, merging files, and removing
revisions of files, we do so regardless of whether the files are
ASCII or binary.

Fixes PR6031.

OK joris and deraadt.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.109 03-Jul-2007 ray

Rename rcs_diffreg() to diffreg().

OK joris@


# 1.108 30-Jun-2007 xsa

Sync revisions and time buffers size to be consistent with each others.
Simplifies further size tweaks if needed.
OK ray@.


# 1.107 08-Jun-2007 xsa

If strict locking is disabled, make file writable by owner on checkout.
Matches GNU's behaviour. From Pierre Riteau (long time ago).


# 1.106 07-Jun-2007 xsa

Correct exit value when one of the files specified cannot be checked out.
Matches GNU's behaviour. From Pierre Riteau (long time ago).


Revision tags: OPENBSD_4_1_BASE
# 1.105 27-Feb-2007 xsa

As done in OpenCVS, general includes cleanup sweep. OK otto@.


# 1.104 22-Feb-2007 otto

If a ,suffix file is given as an arg to ci and co, strip it. Avoids
potential disasters. Initial diff from niallo@, ok niallo@ joris@


# 1.103 21-Feb-2007 niallo

make sure checkout_rev() sets correct file permissions via file->rf_mode
in case where fstat() of file->rf_fd won't give us right mode.

fixes PR #5383

ok xsa@


# 1.102 18-Feb-2007 xsa

keep correct permissions on the RCS file when locking/unlocking the file
with ci and co. fixes PR 5379.
OK millert@ joris@.


# 1.101 01-Feb-2007 millert

When checking to see if a checked-out copy of the file is the same
as what is in the repo, expand keywords before doing the diff.
OK xsa@


# 1.100 10-Nov-2006 millert

Unlike GNU rcs, our co will not overwrite an existing file, even
if the existing file is not writable. While safer, this can be
annoying. I've changed things to compare the version of the file
being checked out with its current contents and, if they are the
same, to allow the checkout without user intervention. The behavior
when there is a writable version of the file is unchanged. OK xsa@


# 1.99 09-Nov-2006 millert

Simplify stripping of write bits from file mode.
Add support for reusing the checkin message for multiple files, ala GNU
Fix the message when you abort a checkout and the file was not writable.
OK joris@ niallo@


# 1.98 12-Oct-2006 niallo

- convert some warnx() to warn(), which fixes a few stupidly un-informative error messages (found by tom@)
- make rcs_choosefile() save wrt errno, input from ray@

ok joris@ xsa@


Revision tags: OPENBSD_4_0_BASE
# 1.97 07-Aug-2006 ray

More strlcpy/strlcat -> snprintf/xasprintf cleanup.

OK joris@


# 1.96 01-Aug-2006 ray

Reduce rcs_buf_release() usage, improving binary support.

OK niallo@


# 1.95 03-Jun-2006 niallo

- correctly handle binary files; say bye bye to using c strings for deltatexts.

"slap it in" joris@


# 1.94 28-May-2006 ray

Remove a lot of xstrdup() calls in getopt() loops, which are usually
unnecessary. These xstrdup() calls don't call xfree() before anyway,
so if a flag is given multiple times memory leaks would have resulted.

OK joris@


# 1.93 27-May-2006 ray

Rename RCSFILE.fd to RCSFILE.rf_fd, plus minor spacing nits. No
binary change.

OK xsa@


# 1.92 27-May-2006 ray

Remove rcs_statfile(). It was just a wrapper for rcs_choosefile(),
handling exceptions oddly.

OK joris@


# 1.91 17-May-2006 xsa

fix printf's


# 1.90 11-May-2006 xsa

fix informative msg's wrt to -q and stderr. now matches gnu/usr.bin/rcs.


# 1.89 09-May-2006 ray

Remove /* NOTREACHED */ comments, now that lint is smart about
__dead. I never should have put them there.

OK xsa@.


# 1.88 05-May-2006 ray

o GNU ci returns 0 when a file is reverted (co -l file; ci file).
o Don't unlock file after revert.
o Fix spelling.

Passes extra tests in GNU rcstest.

OK niallo@.


# 1.87 29-Apr-2006 ray

Check return values for all strlcpy, and strlcat calls.

OK xsa@ and probably others.


# 1.86 26-Apr-2006 joris

prevent file races by obtaining an fd for the RCS file and
do our operations on that, this is safe and guarantees we
can operate on the file until we close(2) it.

a fix is coming for the remaining races in our diff code.
okay niallo@ and ray@


# 1.85 26-Apr-2006 joris

fork our code we shared between openrcs/cvs into the openrcs dir.

this was starting to become inhuman to maintain without
ugly ugly hacks in the shared code, and it will be easier
to make specific changes for openrcs without touching the
soon-to-be-replaced opencvs code.


# 1.84 25-Apr-2006 xsa

fatal() -> err()/errx() as we try to not depend on heavy cvs_log().
OK joriski.


# 1.83 24-Apr-2006 xsa

be consistent in error messages for wrongly specified keyword substitution
mode for `-k'.


# 1.82 21-Apr-2006 xsa

move shared functions into rcsutil.[ch]; this makes rcsprog.c cleaner;
"the voices in my head say OK!" joris@.


# 1.81 21-Apr-2006 xsa

remove overkill cvs_log() and rather use warn()/warnx().
OK ray@ and discussed with joris@.


# 1.80 21-Apr-2006 xsa

switch -p handling to bitwise flags; OK ray@.


# 1.79 19-Apr-2006 xsa

switch -q handling to bitwise flags; OK ray@ niallo@.


# 1.78 15-Apr-2006 pat

Plug some memory leaks; ok niallo@


# 1.77 14-Apr-2006 deraadt

excessive addition to brackets is a mental disease. you will go
blind, too. seek help. no binary change, ok joris


# 1.76 13-Apr-2006 joris

correctly handle RCS files without any revisions;
original diff from ray@, crafted into shape by myself.

okay ray@


# 1.75 13-Apr-2006 ray

*** empty log message ***


# 1.74 12-Apr-2006 deraadt

spaces


# 1.73 12-Apr-2006 ray

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@


# 1.72 10-Apr-2006 xsa

change rcs_kwexp_set() return type to void and simplify its use. OK niallo@.


# 1.71 09-Apr-2006 niallo

- don't print out warnings about locking when they are actually wrong and
just confuse the user.

ok and input joris@


# 1.70 06-Apr-2006 xsa

-z can take no argument.


# 1.69 30-Mar-2006 joris

first part of supporting branches in openrcs. right now we can only
check them out. commit is not working yet, but will be soon.

tested by myself and ray@
okay ray@


# 1.68 29-Mar-2006 ray

More closely matches GNU behavior, passes more GNU rcstest tests.

OK niallo@


# 1.67 27-Mar-2006 niallo

- properly implement GNU file modes. basically, checkout will inherit
permissions from rcs file and initial checkin will inherit permissions from
working file.

problem spotted by uwe@

ok ray@ xsa@


# 1.66 24-Mar-2006 ray

Allow the -x flag to be used without an extension.

``that makes sense'' xsa@


# 1.65 17-Mar-2006 niallo

- co usage() says we support -I, so set the flags and revision.

ok xsa@


# 1.64 16-Mar-2006 niallo

- checkout_rev() can fail, in which case we want a non-zero exit code.

ok joris@


# 1.63 16-Mar-2006 xsa

error message fix; respect -q too. Ok ray@.


# 1.62 16-Mar-2006 ray

Follow exit() with /* NOTREACHED*/ for lint.

``OK niallo@'' niallo@


# 1.61 16-Mar-2006 ray

Currently co(1) overwrites files that the current user doesn't have
write permissions for. If you own the directory, that means your
existing file, mode 000, is blown away without prompting you. GNU
RCS does this as well.

This fixes changes co(1) to always prompt if a file exists. This
breaks GNU compatibility but I think it's more important that we
prevent co(1) from overwriting files with strict permissions without
even prompting.

``makes sense'' xsa to an earlier diff


# 1.60 15-Mar-2006 niallo

- use shared cvs_yesno() for yesno prompt, fixing an issue spotted by
deraadt@

- while here, remove unecessary cast also spotted by deraadt@

ok ray@ xsa@


# 1.59 07-Mar-2006 joris

-z support for RCS;


# 1.58 06-Mar-2006 xsa

missing informative message after call to checkout_rev().


# 1.57 06-Mar-2006 xsa

should also have removed those newlines in previous commit.


# 1.56 06-Mar-2006 xsa

missing newline in checkout_rev(); spotted by joris@.


# 1.55 05-Mar-2006 niallo

our deltatexts were sometimes different from gnu. rcs_getrev() was
unconditionally doing keyword expansion, even when this wasn't what we
wanted e.g. in checkout_rev() and cvs_checkout_rev(). so:

- change semantics of rcs_getrev() to not do keyword expansion
- add an rcs.c api function rcs_kwexp_buf() which does this
- change both checkout_rev() and cvs_checkout_rev() to use this function.

eyeballed by xsa, joris and Ray Lai


Revision tags: OPENBSD_3_9_BASE
# 1.54 24-Feb-2006 xsa

remove extra printf;


# 1.53 14-Feb-2006 xsa

- fix behaviour when using -u and -l at the same time
- do not display some messages when checking in a file for the first time
OK niallo@.


# 1.52 05-Jan-2006 xsa

cleanup, move log.h and rcs.h inclusion into rcsprog.h;


# 1.51 02-Jan-2006 xsa

#include's cleanup; ok joris@ niallo@.


# 1.50 27-Dec-2005 niallo

- implement lazy-parsing of rcs files, that is only parse as much as we
need. this can save us much work, particularly with very large rcs files.

first of a few important performance improvements.

ok joris@


# 1.49 23-Dec-2005 joris

support co -d, which checks out the first revision who's
date is less than or equal to the given date.


# 1.48 19-Dec-2005 xsa

use fatal() if getlogin() fails;


# 1.47 10-Dec-2005 joris

switch to xmalloc stuff, me and xsa@ agreed on this a long
time ago, but we were being held back by jfb. too bad for him.

next step is to use fatal() through out the code for unrecoverable
errors instead of trying to be all nice and fluffy and reach main() again.

ok niallo@ and xsa@


# 1.46 09-Dec-2005 joris

if we are removing a lock that's not present, just check
out the file without complaining;


# 1.45 09-Dec-2005 joris

unused vars, my bad;


# 1.44 08-Dec-2005 joris

complete and correct rcs locking functionality,
it was only done partially and as a bonus, completely wrong.

seriously guys what was up with that?


# 1.43 05-Dec-2005 xsa

correctly handle `-wfoo' and `-sbar' errors; OK joris@.


# 1.42 02-Dec-2005 xsa

`-mmsg' does not belong here;


# 1.41 30-Nov-2005 xsa

check for ownership of already present writable file when checking out;


# 1.40 30-Nov-2005 xsa

writeable -> writable


# 1.39 29-Nov-2005 xsa

consistency in variables naming;


# 1.38 29-Nov-2005 xsa

some more bits for `-w[user]' support;


# 1.37 25-Nov-2005 xsa

add support for `-T' and enable it for co(1);
tested and OK niallo@. "Looks good" joris@.


# 1.36 24-Nov-2005 xsa

memset();


# 1.35 23-Nov-2005 xsa

cannot combine -kv and -l;


# 1.34 23-Nov-2005 xsa

initial bits for -T support;


# 1.33 23-Nov-2005 xsa

add support for `-kmode';


# 1.32 23-Nov-2005 xsa

sync SYNOPSIS with Reality and usage() accordingly;


# 1.31 22-Nov-2005 xsa

make `-p' work again as expected;


# 1.30 21-Nov-2005 xsa

enable `-xsuffixes' support as it has been added a few days ago
in rcs_statfile();
niallo ok


# 1.29 08-Nov-2005 xsa

nuke trailing whitespaces;


# 1.28 03-Nov-2005 niallo

- update comment for checkout_rev() for bitwise flags.


# 1.27 03-Nov-2005 niallo

- sync checkout_usage();


# 1.26 03-Nov-2005 niallo

- implement `-M' option.


# 1.25 02-Nov-2005 niallo

- update the comment for checkout_state(); it did not tell the truth
about values returned.


# 1.24 02-Nov-2005 niallo

changes from Venice:

- instead of using lots of individual flag variables, use a single int and
bitwise operations on it. while this saves memory, really it saves code
space and reduces complexity. checkout_rev() and checkout_state() in
particular benefit from these changes since their parameters where growing
really long.

- implement `-s' option in co

- implement `-M' option in ci

"I like this, go for it" joris@


# 1.23 25-Oct-2005 xsa

nuke trailing whitespaces;


# 1.22 20-Oct-2005 xsa

fix output if -p is specified; joris ok


# 1.21 19-Oct-2005 niallo

- make a bunch of changes to how we handle verbose output. this brings us
much closer in line with GNU RCS and cleans things up in general.

ok joris@, "looks fine to me" xsa@


# 1.20 19-Oct-2005 joris

add co -p support;
input from xsa@ and niallo@;


# 1.19 18-Oct-2005 joris

use rcs_set_rev() instead of duplicating code all over the
place to set a variable to the given revision number;


# 1.18 17-Oct-2005 joris

support -f flag for co;
'fine' niallo@


# 1.17 16-Oct-2005 joris

spacing;


# 1.16 16-Oct-2005 niallo

- sync checkout_usage();


# 1.15 15-Oct-2005 niallo

- if revision passed to checkout_rev() is > HEAD, assume HEAD
(like GNU RCS).
- move verbose output into checkout_rev() function itself.

"looks sane" joris@


# 1.14 15-Oct-2005 niallo

modularise checkout code into checkout_rev(). this shaves off a number
of lines in ci.c due to code re-use, and will simplify features which are in
the pipeline. no functional changes.

ok joris@


# 1.13 13-Oct-2005 joris

To be fully compatibly with the GNU RCS tools we need to have the
same way of parsing commandline options. Since getopt(3) allows spaces
between arguments and GNU RCS tools does not we needed to roll out our
own way of option handling, and here it is.

ok niallo@


# 1.12 12-Oct-2005 xsa

minor knf;


# 1.11 12-Oct-2005 deraadt

various usage cleanup; ok joris


# 1.10 10-Oct-2005 xsa

getlogin(2) sets errno;


# 1.9 10-Oct-2005 niallo

sync checkout_usage();


# 1.8 10-Oct-2005 niallo

- set permissions on checked out files correctly
- support bare `-u' and `-l' options which will check out HEAD.

note that with OpenRCS you must do `co -l -- <file>' and `co -u -- <file>'
when using bare arguments because our getopt(3) is POSIX compliant.

ok joris@


# 1.7 05-Oct-2005 joris

sync usage and add V flag;


# 1.6 05-Oct-2005 joris

- stop gcc's yapping;
- better output when locking and unlocking revisions;


# 1.5 05-Oct-2005 joris

- better output
- free frev when done


# 1.4 04-Oct-2005 joris

- support -l and -u flags;
- better output;


# 1.3 29-Sep-2005 joris

support -q flag in 'co' and 'rcs'


# 1.2 29-Sep-2005 joris

fix usage


# 1.1 29-Sep-2005 joris

put it basic checkout code


# 1.125 26-Apr-2019 millert

There was an extra newline in some cases and missing one in others.
OK joris@


Revision tags: OPENBSD_6_5_BASE
# 1.124 09-Jan-2019 joris

Delay keyword expansion in co until after the locks have been resolved.

This way the expansion can happen with the correct values and files do not
show up as modified.


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.123 29-Aug-2017 otto

kill const and string artithmetic related warnings; ok millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.122 21-Oct-2015 millert

Style fixes; from Ilya Kaliman


Revision tags: OPENBSD_5_8_BASE
# 1.121 13-Jun-2015 nicm

Convert xfree to free. From Fritjof Bornebusch. ok deraadt


Revision tags: OPENBSD_5_7_BASE
# 1.120 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.119 10-Oct-2014 otto

Zap some stored values never read; From Fritjof Bornebusch; ok nicm@


# 1.118 02-Oct-2014 otto

exit in usage functions themselves; from Fritjof Bornebusch; ok nicm@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.117 16-Apr-2013 deraadt

remove wrong casts; ok millert


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.116 03-Dec-2010 chl

add missing header needed by futimes()

ok stsp@


# 1.115 20-Oct-2010 tobias

Remove the need for rp_file in parser structure, instead keep only one
FILE pointer in RCSFILE. This fixes some ugliness in closing an
fdopen()ed FILE and its underlying file descriptor.

Notified by Joerg Sonnenberger <joerg at britannica dot bec to de>

discussed with and ok nicm


# 1.114 08-Sep-2010 tobias

Set rcs_suffixes to default value on initialization.

ok ray zinovik


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jul-2010 ray

Check date_parse return values.

OK xsa


# 1.112 28-Jul-2010 ray

Make BUFs autoextend by default. This was already done in OpenCVS
a while ago.

OK zinovik nicm


# 1.111 23-Jul-2010 ray

Reduce variable/function name and whitespace differences between
cvs/rcs.

OK xsa zinovik


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.110 25-Feb-2009 ray

Checking if a file is ASCII should only be done when diffing, because
the non-ASCII characters could be printed to the screen. For
checking in files, checking out files, merging files, and removing
revisions of files, we do so regardless of whether the files are
ASCII or binary.

Fixes PR6031.

OK joris and deraadt.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.109 03-Jul-2007 ray

Rename rcs_diffreg() to diffreg().

OK joris@


# 1.108 30-Jun-2007 xsa

Sync revisions and time buffers size to be consistent with each others.
Simplifies further size tweaks if needed.
OK ray@.


# 1.107 08-Jun-2007 xsa

If strict locking is disabled, make file writable by owner on checkout.
Matches GNU's behaviour. From Pierre Riteau (long time ago).


# 1.106 07-Jun-2007 xsa

Correct exit value when one of the files specified cannot be checked out.
Matches GNU's behaviour. From Pierre Riteau (long time ago).


Revision tags: OPENBSD_4_1_BASE
# 1.105 27-Feb-2007 xsa

As done in OpenCVS, general includes cleanup sweep. OK otto@.


# 1.104 22-Feb-2007 otto

If a ,suffix file is given as an arg to ci and co, strip it. Avoids
potential disasters. Initial diff from niallo@, ok niallo@ joris@


# 1.103 21-Feb-2007 niallo

make sure checkout_rev() sets correct file permissions via file->rf_mode
in case where fstat() of file->rf_fd won't give us right mode.

fixes PR #5383

ok xsa@


# 1.102 18-Feb-2007 xsa

keep correct permissions on the RCS file when locking/unlocking the file
with ci and co. fixes PR 5379.
OK millert@ joris@.


# 1.101 01-Feb-2007 millert

When checking to see if a checked-out copy of the file is the same
as what is in the repo, expand keywords before doing the diff.
OK xsa@


# 1.100 10-Nov-2006 millert

Unlike GNU rcs, our co will not overwrite an existing file, even
if the existing file is not writable. While safer, this can be
annoying. I've changed things to compare the version of the file
being checked out with its current contents and, if they are the
same, to allow the checkout without user intervention. The behavior
when there is a writable version of the file is unchanged. OK xsa@


# 1.99 09-Nov-2006 millert

Simplify stripping of write bits from file mode.
Add support for reusing the checkin message for multiple files, ala GNU
Fix the message when you abort a checkout and the file was not writable.
OK joris@ niallo@


# 1.98 12-Oct-2006 niallo

- convert some warnx() to warn(), which fixes a few stupidly un-informative error messages (found by tom@)
- make rcs_choosefile() save wrt errno, input from ray@

ok joris@ xsa@


Revision tags: OPENBSD_4_0_BASE
# 1.97 07-Aug-2006 ray

More strlcpy/strlcat -> snprintf/xasprintf cleanup.

OK joris@


# 1.96 01-Aug-2006 ray

Reduce rcs_buf_release() usage, improving binary support.

OK niallo@


# 1.95 03-Jun-2006 niallo

- correctly handle binary files; say bye bye to using c strings for deltatexts.

"slap it in" joris@


# 1.94 28-May-2006 ray

Remove a lot of xstrdup() calls in getopt() loops, which are usually
unnecessary. These xstrdup() calls don't call xfree() before anyway,
so if a flag is given multiple times memory leaks would have resulted.

OK joris@


# 1.93 27-May-2006 ray

Rename RCSFILE.fd to RCSFILE.rf_fd, plus minor spacing nits. No
binary change.

OK xsa@


# 1.92 27-May-2006 ray

Remove rcs_statfile(). It was just a wrapper for rcs_choosefile(),
handling exceptions oddly.

OK joris@


# 1.91 17-May-2006 xsa

fix printf's


# 1.90 11-May-2006 xsa

fix informative msg's wrt to -q and stderr. now matches gnu/usr.bin/rcs.


# 1.89 09-May-2006 ray

Remove /* NOTREACHED */ comments, now that lint is smart about
__dead. I never should have put them there.

OK xsa@.


# 1.88 05-May-2006 ray

o GNU ci returns 0 when a file is reverted (co -l file; ci file).
o Don't unlock file after revert.
o Fix spelling.

Passes extra tests in GNU rcstest.

OK niallo@.


# 1.87 29-Apr-2006 ray

Check return values for all strlcpy, and strlcat calls.

OK xsa@ and probably others.


# 1.86 26-Apr-2006 joris

prevent file races by obtaining an fd for the RCS file and
do our operations on that, this is safe and guarantees we
can operate on the file until we close(2) it.

a fix is coming for the remaining races in our diff code.
okay niallo@ and ray@


# 1.85 26-Apr-2006 joris

fork our code we shared between openrcs/cvs into the openrcs dir.

this was starting to become inhuman to maintain without
ugly ugly hacks in the shared code, and it will be easier
to make specific changes for openrcs without touching the
soon-to-be-replaced opencvs code.


# 1.84 25-Apr-2006 xsa

fatal() -> err()/errx() as we try to not depend on heavy cvs_log().
OK joriski.


# 1.83 24-Apr-2006 xsa

be consistent in error messages for wrongly specified keyword substitution
mode for `-k'.


# 1.82 21-Apr-2006 xsa

move shared functions into rcsutil.[ch]; this makes rcsprog.c cleaner;
"the voices in my head say OK!" joris@.


# 1.81 21-Apr-2006 xsa

remove overkill cvs_log() and rather use warn()/warnx().
OK ray@ and discussed with joris@.


# 1.80 21-Apr-2006 xsa

switch -p handling to bitwise flags; OK ray@.


# 1.79 19-Apr-2006 xsa

switch -q handling to bitwise flags; OK ray@ niallo@.


# 1.78 15-Apr-2006 pat

Plug some memory leaks; ok niallo@


# 1.77 14-Apr-2006 deraadt

excessive addition to brackets is a mental disease. you will go
blind, too. seek help. no binary change, ok joris


# 1.76 13-Apr-2006 joris

correctly handle RCS files without any revisions;
original diff from ray@, crafted into shape by myself.

okay ray@


# 1.75 13-Apr-2006 ray

*** empty log message ***


# 1.74 12-Apr-2006 deraadt

spaces


# 1.73 12-Apr-2006 ray

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@


# 1.72 10-Apr-2006 xsa

change rcs_kwexp_set() return type to void and simplify its use. OK niallo@.


# 1.71 09-Apr-2006 niallo

- don't print out warnings about locking when they are actually wrong and
just confuse the user.

ok and input joris@


# 1.70 06-Apr-2006 xsa

-z can take no argument.


# 1.69 30-Mar-2006 joris

first part of supporting branches in openrcs. right now we can only
check them out. commit is not working yet, but will be soon.

tested by myself and ray@
okay ray@


# 1.68 29-Mar-2006 ray

More closely matches GNU behavior, passes more GNU rcstest tests.

OK niallo@


# 1.67 27-Mar-2006 niallo

- properly implement GNU file modes. basically, checkout will inherit
permissions from rcs file and initial checkin will inherit permissions from
working file.

problem spotted by uwe@

ok ray@ xsa@


# 1.66 24-Mar-2006 ray

Allow the -x flag to be used without an extension.

``that makes sense'' xsa@


# 1.65 17-Mar-2006 niallo

- co usage() says we support -I, so set the flags and revision.

ok xsa@


# 1.64 16-Mar-2006 niallo

- checkout_rev() can fail, in which case we want a non-zero exit code.

ok joris@


# 1.63 16-Mar-2006 xsa

error message fix; respect -q too. Ok ray@.


# 1.62 16-Mar-2006 ray

Follow exit() with /* NOTREACHED*/ for lint.

``OK niallo@'' niallo@


# 1.61 16-Mar-2006 ray

Currently co(1) overwrites files that the current user doesn't have
write permissions for. If you own the directory, that means your
existing file, mode 000, is blown away without prompting you. GNU
RCS does this as well.

This fixes changes co(1) to always prompt if a file exists. This
breaks GNU compatibility but I think it's more important that we
prevent co(1) from overwriting files with strict permissions without
even prompting.

``makes sense'' xsa to an earlier diff


# 1.60 15-Mar-2006 niallo

- use shared cvs_yesno() for yesno prompt, fixing an issue spotted by
deraadt@

- while here, remove unecessary cast also spotted by deraadt@

ok ray@ xsa@


# 1.59 07-Mar-2006 joris

-z support for RCS;


# 1.58 06-Mar-2006 xsa

missing informative message after call to checkout_rev().


# 1.57 06-Mar-2006 xsa

should also have removed those newlines in previous commit.


# 1.56 06-Mar-2006 xsa

missing newline in checkout_rev(); spotted by joris@.


# 1.55 05-Mar-2006 niallo

our deltatexts were sometimes different from gnu. rcs_getrev() was
unconditionally doing keyword expansion, even when this wasn't what we
wanted e.g. in checkout_rev() and cvs_checkout_rev(). so:

- change semantics of rcs_getrev() to not do keyword expansion
- add an rcs.c api function rcs_kwexp_buf() which does this
- change both checkout_rev() and cvs_checkout_rev() to use this function.

eyeballed by xsa, joris and Ray Lai


Revision tags: OPENBSD_3_9_BASE
# 1.54 24-Feb-2006 xsa

remove extra printf;


# 1.53 14-Feb-2006 xsa

- fix behaviour when using -u and -l at the same time
- do not display some messages when checking in a file for the first time
OK niallo@.


# 1.52 05-Jan-2006 xsa

cleanup, move log.h and rcs.h inclusion into rcsprog.h;


# 1.51 02-Jan-2006 xsa

#include's cleanup; ok joris@ niallo@.


# 1.50 27-Dec-2005 niallo

- implement lazy-parsing of rcs files, that is only parse as much as we
need. this can save us much work, particularly with very large rcs files.

first of a few important performance improvements.

ok joris@


# 1.49 23-Dec-2005 joris

support co -d, which checks out the first revision who's
date is less than or equal to the given date.


# 1.48 19-Dec-2005 xsa

use fatal() if getlogin() fails;


# 1.47 10-Dec-2005 joris

switch to xmalloc stuff, me and xsa@ agreed on this a long
time ago, but we were being held back by jfb. too bad for him.

next step is to use fatal() through out the code for unrecoverable
errors instead of trying to be all nice and fluffy and reach main() again.

ok niallo@ and xsa@


# 1.46 09-Dec-2005 joris

if we are removing a lock that's not present, just check
out the file without complaining;


# 1.45 09-Dec-2005 joris

unused vars, my bad;


# 1.44 08-Dec-2005 joris

complete and correct rcs locking functionality,
it was only done partially and as a bonus, completely wrong.

seriously guys what was up with that?


# 1.43 05-Dec-2005 xsa

correctly handle `-wfoo' and `-sbar' errors; OK joris@.


# 1.42 02-Dec-2005 xsa

`-mmsg' does not belong here;


# 1.41 30-Nov-2005 xsa

check for ownership of already present writable file when checking out;


# 1.40 30-Nov-2005 xsa

writeable -> writable


# 1.39 29-Nov-2005 xsa

consistency in variables naming;


# 1.38 29-Nov-2005 xsa

some more bits for `-w[user]' support;


# 1.37 25-Nov-2005 xsa

add support for `-T' and enable it for co(1);
tested and OK niallo@. "Looks good" joris@.


# 1.36 24-Nov-2005 xsa

memset();


# 1.35 23-Nov-2005 xsa

cannot combine -kv and -l;


# 1.34 23-Nov-2005 xsa

initial bits for -T support;


# 1.33 23-Nov-2005 xsa

add support for `-kmode';


# 1.32 23-Nov-2005 xsa

sync SYNOPSIS with Reality and usage() accordingly;


# 1.31 22-Nov-2005 xsa

make `-p' work again as expected;


# 1.30 21-Nov-2005 xsa

enable `-xsuffixes' support as it has been added a few days ago
in rcs_statfile();
niallo ok


# 1.29 08-Nov-2005 xsa

nuke trailing whitespaces;


# 1.28 03-Nov-2005 niallo

- update comment for checkout_rev() for bitwise flags.


# 1.27 03-Nov-2005 niallo

- sync checkout_usage();


# 1.26 03-Nov-2005 niallo

- implement `-M' option.


# 1.25 02-Nov-2005 niallo

- update the comment for checkout_state(); it did not tell the truth
about values returned.


# 1.24 02-Nov-2005 niallo

changes from Venice:

- instead of using lots of individual flag variables, use a single int and
bitwise operations on it. while this saves memory, really it saves code
space and reduces complexity. checkout_rev() and checkout_state() in
particular benefit from these changes since their parameters where growing
really long.

- implement `-s' option in co

- implement `-M' option in ci

"I like this, go for it" joris@


# 1.23 25-Oct-2005 xsa

nuke trailing whitespaces;


# 1.22 20-Oct-2005 xsa

fix output if -p is specified; joris ok


# 1.21 19-Oct-2005 niallo

- make a bunch of changes to how we handle verbose output. this brings us
much closer in line with GNU RCS and cleans things up in general.

ok joris@, "looks fine to me" xsa@


# 1.20 19-Oct-2005 joris

add co -p support;
input from xsa@ and niallo@;


# 1.19 18-Oct-2005 joris

use rcs_set_rev() instead of duplicating code all over the
place to set a variable to the given revision number;


# 1.18 17-Oct-2005 joris

support -f flag for co;
'fine' niallo@


# 1.17 16-Oct-2005 joris

spacing;


# 1.16 16-Oct-2005 niallo

- sync checkout_usage();


# 1.15 15-Oct-2005 niallo

- if revision passed to checkout_rev() is > HEAD, assume HEAD
(like GNU RCS).
- move verbose output into checkout_rev() function itself.

"looks sane" joris@


# 1.14 15-Oct-2005 niallo

modularise checkout code into checkout_rev(). this shaves off a number
of lines in ci.c due to code re-use, and will simplify features which are in
the pipeline. no functional changes.

ok joris@


# 1.13 13-Oct-2005 joris

To be fully compatibly with the GNU RCS tools we need to have the
same way of parsing commandline options. Since getopt(3) allows spaces
between arguments and GNU RCS tools does not we needed to roll out our
own way of option handling, and here it is.

ok niallo@


# 1.12 12-Oct-2005 xsa

minor knf;


# 1.11 12-Oct-2005 deraadt

various usage cleanup; ok joris


# 1.10 10-Oct-2005 xsa

getlogin(2) sets errno;


# 1.9 10-Oct-2005 niallo

sync checkout_usage();


# 1.8 10-Oct-2005 niallo

- set permissions on checked out files correctly
- support bare `-u' and `-l' options which will check out HEAD.

note that with OpenRCS you must do `co -l -- <file>' and `co -u -- <file>'
when using bare arguments because our getopt(3) is POSIX compliant.

ok joris@


# 1.7 05-Oct-2005 joris

sync usage and add V flag;


# 1.6 05-Oct-2005 joris

- stop gcc's yapping;
- better output when locking and unlocking revisions;


# 1.5 05-Oct-2005 joris

- better output
- free frev when done


# 1.4 04-Oct-2005 joris

- support -l and -u flags;
- better output;


# 1.3 29-Sep-2005 joris

support -q flag in 'co' and 'rcs'


# 1.2 29-Sep-2005 joris

fix usage


# 1.1 29-Sep-2005 joris

put it basic checkout code


# 1.124 09-Jan-2019 joris

Delay keyword expansion in co until after the locks have been resolved.

This way the expansion can happen with the correct values and files do not
show up as modified.


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.123 29-Aug-2017 otto

kill const and string artithmetic related warnings; ok millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.122 21-Oct-2015 millert

Style fixes; from Ilya Kaliman


Revision tags: OPENBSD_5_8_BASE
# 1.121 13-Jun-2015 nicm

Convert xfree to free. From Fritjof Bornebusch. ok deraadt


Revision tags: OPENBSD_5_7_BASE
# 1.120 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.119 10-Oct-2014 otto

Zap some stored values never read; From Fritjof Bornebusch; ok nicm@


# 1.118 02-Oct-2014 otto

exit in usage functions themselves; from Fritjof Bornebusch; ok nicm@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.117 16-Apr-2013 deraadt

remove wrong casts; ok millert


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.116 03-Dec-2010 chl

add missing header needed by futimes()

ok stsp@


# 1.115 20-Oct-2010 tobias

Remove the need for rp_file in parser structure, instead keep only one
FILE pointer in RCSFILE. This fixes some ugliness in closing an
fdopen()ed FILE and its underlying file descriptor.

Notified by Joerg Sonnenberger <joerg at britannica dot bec to de>

discussed with and ok nicm


# 1.114 08-Sep-2010 tobias

Set rcs_suffixes to default value on initialization.

ok ray zinovik


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jul-2010 ray

Check date_parse return values.

OK xsa


# 1.112 28-Jul-2010 ray

Make BUFs autoextend by default. This was already done in OpenCVS
a while ago.

OK zinovik nicm


# 1.111 23-Jul-2010 ray

Reduce variable/function name and whitespace differences between
cvs/rcs.

OK xsa zinovik


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.110 25-Feb-2009 ray

Checking if a file is ASCII should only be done when diffing, because
the non-ASCII characters could be printed to the screen. For
checking in files, checking out files, merging files, and removing
revisions of files, we do so regardless of whether the files are
ASCII or binary.

Fixes PR6031.

OK joris and deraadt.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.109 03-Jul-2007 ray

Rename rcs_diffreg() to diffreg().

OK joris@


# 1.108 30-Jun-2007 xsa

Sync revisions and time buffers size to be consistent with each others.
Simplifies further size tweaks if needed.
OK ray@.


# 1.107 08-Jun-2007 xsa

If strict locking is disabled, make file writable by owner on checkout.
Matches GNU's behaviour. From Pierre Riteau (long time ago).


# 1.106 07-Jun-2007 xsa

Correct exit value when one of the files specified cannot be checked out.
Matches GNU's behaviour. From Pierre Riteau (long time ago).


Revision tags: OPENBSD_4_1_BASE
# 1.105 27-Feb-2007 xsa

As done in OpenCVS, general includes cleanup sweep. OK otto@.


# 1.104 22-Feb-2007 otto

If a ,suffix file is given as an arg to ci and co, strip it. Avoids
potential disasters. Initial diff from niallo@, ok niallo@ joris@


# 1.103 21-Feb-2007 niallo

make sure checkout_rev() sets correct file permissions via file->rf_mode
in case where fstat() of file->rf_fd won't give us right mode.

fixes PR #5383

ok xsa@


# 1.102 18-Feb-2007 xsa

keep correct permissions on the RCS file when locking/unlocking the file
with ci and co. fixes PR 5379.
OK millert@ joris@.


# 1.101 01-Feb-2007 millert

When checking to see if a checked-out copy of the file is the same
as what is in the repo, expand keywords before doing the diff.
OK xsa@


# 1.100 10-Nov-2006 millert

Unlike GNU rcs, our co will not overwrite an existing file, even
if the existing file is not writable. While safer, this can be
annoying. I've changed things to compare the version of the file
being checked out with its current contents and, if they are the
same, to allow the checkout without user intervention. The behavior
when there is a writable version of the file is unchanged. OK xsa@


# 1.99 09-Nov-2006 millert

Simplify stripping of write bits from file mode.
Add support for reusing the checkin message for multiple files, ala GNU
Fix the message when you abort a checkout and the file was not writable.
OK joris@ niallo@


# 1.98 12-Oct-2006 niallo

- convert some warnx() to warn(), which fixes a few stupidly un-informative error messages (found by tom@)
- make rcs_choosefile() save wrt errno, input from ray@

ok joris@ xsa@


Revision tags: OPENBSD_4_0_BASE
# 1.97 07-Aug-2006 ray

More strlcpy/strlcat -> snprintf/xasprintf cleanup.

OK joris@


# 1.96 01-Aug-2006 ray

Reduce rcs_buf_release() usage, improving binary support.

OK niallo@


# 1.95 03-Jun-2006 niallo

- correctly handle binary files; say bye bye to using c strings for deltatexts.

"slap it in" joris@


# 1.94 28-May-2006 ray

Remove a lot of xstrdup() calls in getopt() loops, which are usually
unnecessary. These xstrdup() calls don't call xfree() before anyway,
so if a flag is given multiple times memory leaks would have resulted.

OK joris@


# 1.93 27-May-2006 ray

Rename RCSFILE.fd to RCSFILE.rf_fd, plus minor spacing nits. No
binary change.

OK xsa@


# 1.92 27-May-2006 ray

Remove rcs_statfile(). It was just a wrapper for rcs_choosefile(),
handling exceptions oddly.

OK joris@


# 1.91 17-May-2006 xsa

fix printf's


# 1.90 11-May-2006 xsa

fix informative msg's wrt to -q and stderr. now matches gnu/usr.bin/rcs.


# 1.89 09-May-2006 ray

Remove /* NOTREACHED */ comments, now that lint is smart about
__dead. I never should have put them there.

OK xsa@.


# 1.88 05-May-2006 ray

o GNU ci returns 0 when a file is reverted (co -l file; ci file).
o Don't unlock file after revert.
o Fix spelling.

Passes extra tests in GNU rcstest.

OK niallo@.


# 1.87 29-Apr-2006 ray

Check return values for all strlcpy, and strlcat calls.

OK xsa@ and probably others.


# 1.86 26-Apr-2006 joris

prevent file races by obtaining an fd for the RCS file and
do our operations on that, this is safe and guarantees we
can operate on the file until we close(2) it.

a fix is coming for the remaining races in our diff code.
okay niallo@ and ray@


# 1.85 26-Apr-2006 joris

fork our code we shared between openrcs/cvs into the openrcs dir.

this was starting to become inhuman to maintain without
ugly ugly hacks in the shared code, and it will be easier
to make specific changes for openrcs without touching the
soon-to-be-replaced opencvs code.


# 1.84 25-Apr-2006 xsa

fatal() -> err()/errx() as we try to not depend on heavy cvs_log().
OK joriski.


# 1.83 24-Apr-2006 xsa

be consistent in error messages for wrongly specified keyword substitution
mode for `-k'.


# 1.82 21-Apr-2006 xsa

move shared functions into rcsutil.[ch]; this makes rcsprog.c cleaner;
"the voices in my head say OK!" joris@.


# 1.81 21-Apr-2006 xsa

remove overkill cvs_log() and rather use warn()/warnx().
OK ray@ and discussed with joris@.


# 1.80 21-Apr-2006 xsa

switch -p handling to bitwise flags; OK ray@.


# 1.79 19-Apr-2006 xsa

switch -q handling to bitwise flags; OK ray@ niallo@.


# 1.78 15-Apr-2006 pat

Plug some memory leaks; ok niallo@


# 1.77 14-Apr-2006 deraadt

excessive addition to brackets is a mental disease. you will go
blind, too. seek help. no binary change, ok joris


# 1.76 13-Apr-2006 joris

correctly handle RCS files without any revisions;
original diff from ray@, crafted into shape by myself.

okay ray@


# 1.75 13-Apr-2006 ray

*** empty log message ***


# 1.74 12-Apr-2006 deraadt

spaces


# 1.73 12-Apr-2006 ray

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@


# 1.72 10-Apr-2006 xsa

change rcs_kwexp_set() return type to void and simplify its use. OK niallo@.


# 1.71 09-Apr-2006 niallo

- don't print out warnings about locking when they are actually wrong and
just confuse the user.

ok and input joris@


# 1.70 06-Apr-2006 xsa

-z can take no argument.


# 1.69 30-Mar-2006 joris

first part of supporting branches in openrcs. right now we can only
check them out. commit is not working yet, but will be soon.

tested by myself and ray@
okay ray@


# 1.68 29-Mar-2006 ray

More closely matches GNU behavior, passes more GNU rcstest tests.

OK niallo@


# 1.67 27-Mar-2006 niallo

- properly implement GNU file modes. basically, checkout will inherit
permissions from rcs file and initial checkin will inherit permissions from
working file.

problem spotted by uwe@

ok ray@ xsa@


# 1.66 24-Mar-2006 ray

Allow the -x flag to be used without an extension.

``that makes sense'' xsa@


# 1.65 17-Mar-2006 niallo

- co usage() says we support -I, so set the flags and revision.

ok xsa@


# 1.64 16-Mar-2006 niallo

- checkout_rev() can fail, in which case we want a non-zero exit code.

ok joris@


# 1.63 16-Mar-2006 xsa

error message fix; respect -q too. Ok ray@.


# 1.62 16-Mar-2006 ray

Follow exit() with /* NOTREACHED*/ for lint.

``OK niallo@'' niallo@


# 1.61 16-Mar-2006 ray

Currently co(1) overwrites files that the current user doesn't have
write permissions for. If you own the directory, that means your
existing file, mode 000, is blown away without prompting you. GNU
RCS does this as well.

This fixes changes co(1) to always prompt if a file exists. This
breaks GNU compatibility but I think it's more important that we
prevent co(1) from overwriting files with strict permissions without
even prompting.

``makes sense'' xsa to an earlier diff


# 1.60 15-Mar-2006 niallo

- use shared cvs_yesno() for yesno prompt, fixing an issue spotted by
deraadt@

- while here, remove unecessary cast also spotted by deraadt@

ok ray@ xsa@


# 1.59 07-Mar-2006 joris

-z support for RCS;


# 1.58 06-Mar-2006 xsa

missing informative message after call to checkout_rev().


# 1.57 06-Mar-2006 xsa

should also have removed those newlines in previous commit.


# 1.56 06-Mar-2006 xsa

missing newline in checkout_rev(); spotted by joris@.


# 1.55 05-Mar-2006 niallo

our deltatexts were sometimes different from gnu. rcs_getrev() was
unconditionally doing keyword expansion, even when this wasn't what we
wanted e.g. in checkout_rev() and cvs_checkout_rev(). so:

- change semantics of rcs_getrev() to not do keyword expansion
- add an rcs.c api function rcs_kwexp_buf() which does this
- change both checkout_rev() and cvs_checkout_rev() to use this function.

eyeballed by xsa, joris and Ray Lai


Revision tags: OPENBSD_3_9_BASE
# 1.54 24-Feb-2006 xsa

remove extra printf;


# 1.53 14-Feb-2006 xsa

- fix behaviour when using -u and -l at the same time
- do not display some messages when checking in a file for the first time
OK niallo@.


# 1.52 05-Jan-2006 xsa

cleanup, move log.h and rcs.h inclusion into rcsprog.h;


# 1.51 02-Jan-2006 xsa

#include's cleanup; ok joris@ niallo@.


# 1.50 27-Dec-2005 niallo

- implement lazy-parsing of rcs files, that is only parse as much as we
need. this can save us much work, particularly with very large rcs files.

first of a few important performance improvements.

ok joris@


# 1.49 23-Dec-2005 joris

support co -d, which checks out the first revision who's
date is less than or equal to the given date.


# 1.48 19-Dec-2005 xsa

use fatal() if getlogin() fails;


# 1.47 10-Dec-2005 joris

switch to xmalloc stuff, me and xsa@ agreed on this a long
time ago, but we were being held back by jfb. too bad for him.

next step is to use fatal() through out the code for unrecoverable
errors instead of trying to be all nice and fluffy and reach main() again.

ok niallo@ and xsa@


# 1.46 09-Dec-2005 joris

if we are removing a lock that's not present, just check
out the file without complaining;


# 1.45 09-Dec-2005 joris

unused vars, my bad;


# 1.44 08-Dec-2005 joris

complete and correct rcs locking functionality,
it was only done partially and as a bonus, completely wrong.

seriously guys what was up with that?


# 1.43 05-Dec-2005 xsa

correctly handle `-wfoo' and `-sbar' errors; OK joris@.


# 1.42 02-Dec-2005 xsa

`-mmsg' does not belong here;


# 1.41 30-Nov-2005 xsa

check for ownership of already present writable file when checking out;


# 1.40 30-Nov-2005 xsa

writeable -> writable


# 1.39 29-Nov-2005 xsa

consistency in variables naming;


# 1.38 29-Nov-2005 xsa

some more bits for `-w[user]' support;


# 1.37 25-Nov-2005 xsa

add support for `-T' and enable it for co(1);
tested and OK niallo@. "Looks good" joris@.


# 1.36 24-Nov-2005 xsa

memset();


# 1.35 23-Nov-2005 xsa

cannot combine -kv and -l;


# 1.34 23-Nov-2005 xsa

initial bits for -T support;


# 1.33 23-Nov-2005 xsa

add support for `-kmode';


# 1.32 23-Nov-2005 xsa

sync SYNOPSIS with Reality and usage() accordingly;


# 1.31 22-Nov-2005 xsa

make `-p' work again as expected;


# 1.30 21-Nov-2005 xsa

enable `-xsuffixes' support as it has been added a few days ago
in rcs_statfile();
niallo ok


# 1.29 08-Nov-2005 xsa

nuke trailing whitespaces;


# 1.28 03-Nov-2005 niallo

- update comment for checkout_rev() for bitwise flags.


# 1.27 03-Nov-2005 niallo

- sync checkout_usage();


# 1.26 03-Nov-2005 niallo

- implement `-M' option.


# 1.25 02-Nov-2005 niallo

- update the comment for checkout_state(); it did not tell the truth
about values returned.


# 1.24 02-Nov-2005 niallo

changes from Venice:

- instead of using lots of individual flag variables, use a single int and
bitwise operations on it. while this saves memory, really it saves code
space and reduces complexity. checkout_rev() and checkout_state() in
particular benefit from these changes since their parameters where growing
really long.

- implement `-s' option in co

- implement `-M' option in ci

"I like this, go for it" joris@


# 1.23 25-Oct-2005 xsa

nuke trailing whitespaces;


# 1.22 20-Oct-2005 xsa

fix output if -p is specified; joris ok


# 1.21 19-Oct-2005 niallo

- make a bunch of changes to how we handle verbose output. this brings us
much closer in line with GNU RCS and cleans things up in general.

ok joris@, "looks fine to me" xsa@


# 1.20 19-Oct-2005 joris

add co -p support;
input from xsa@ and niallo@;


# 1.19 18-Oct-2005 joris

use rcs_set_rev() instead of duplicating code all over the
place to set a variable to the given revision number;


# 1.18 17-Oct-2005 joris

support -f flag for co;
'fine' niallo@


# 1.17 16-Oct-2005 joris

spacing;


# 1.16 16-Oct-2005 niallo

- sync checkout_usage();


# 1.15 15-Oct-2005 niallo

- if revision passed to checkout_rev() is > HEAD, assume HEAD
(like GNU RCS).
- move verbose output into checkout_rev() function itself.

"looks sane" joris@


# 1.14 15-Oct-2005 niallo

modularise checkout code into checkout_rev(). this shaves off a number
of lines in ci.c due to code re-use, and will simplify features which are in
the pipeline. no functional changes.

ok joris@


# 1.13 13-Oct-2005 joris

To be fully compatibly with the GNU RCS tools we need to have the
same way of parsing commandline options. Since getopt(3) allows spaces
between arguments and GNU RCS tools does not we needed to roll out our
own way of option handling, and here it is.

ok niallo@


# 1.12 12-Oct-2005 xsa

minor knf;


# 1.11 12-Oct-2005 deraadt

various usage cleanup; ok joris


# 1.10 10-Oct-2005 xsa

getlogin(2) sets errno;


# 1.9 10-Oct-2005 niallo

sync checkout_usage();


# 1.8 10-Oct-2005 niallo

- set permissions on checked out files correctly
- support bare `-u' and `-l' options which will check out HEAD.

note that with OpenRCS you must do `co -l -- <file>' and `co -u -- <file>'
when using bare arguments because our getopt(3) is POSIX compliant.

ok joris@


# 1.7 05-Oct-2005 joris

sync usage and add V flag;


# 1.6 05-Oct-2005 joris

- stop gcc's yapping;
- better output when locking and unlocking revisions;


# 1.5 05-Oct-2005 joris

- better output
- free frev when done


# 1.4 04-Oct-2005 joris

- support -l and -u flags;
- better output;


# 1.3 29-Sep-2005 joris

support -q flag in 'co' and 'rcs'


# 1.2 29-Sep-2005 joris

fix usage


# 1.1 29-Sep-2005 joris

put it basic checkout code


Revision tags: OPENBSD_6_2_BASE
# 1.123 29-Aug-2017 otto

kill const and string artithmetic related warnings; ok millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.122 21-Oct-2015 millert

Style fixes; from Ilya Kaliman


Revision tags: OPENBSD_5_8_BASE
# 1.121 13-Jun-2015 nicm

Convert xfree to free. From Fritjof Bornebusch. ok deraadt


Revision tags: OPENBSD_5_7_BASE
# 1.120 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.119 10-Oct-2014 otto

Zap some stored values never read; From Fritjof Bornebusch; ok nicm@


# 1.118 02-Oct-2014 otto

exit in usage functions themselves; from Fritjof Bornebusch; ok nicm@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.117 16-Apr-2013 deraadt

remove wrong casts; ok millert


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.116 03-Dec-2010 chl

add missing header needed by futimes()

ok stsp@


# 1.115 20-Oct-2010 tobias

Remove the need for rp_file in parser structure, instead keep only one
FILE pointer in RCSFILE. This fixes some ugliness in closing an
fdopen()ed FILE and its underlying file descriptor.

Notified by Joerg Sonnenberger <joerg at britannica dot bec to de>

discussed with and ok nicm


# 1.114 08-Sep-2010 tobias

Set rcs_suffixes to default value on initialization.

ok ray zinovik


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jul-2010 ray

Check date_parse return values.

OK xsa


# 1.112 28-Jul-2010 ray

Make BUFs autoextend by default. This was already done in OpenCVS
a while ago.

OK zinovik nicm


# 1.111 23-Jul-2010 ray

Reduce variable/function name and whitespace differences between
cvs/rcs.

OK xsa zinovik


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.110 25-Feb-2009 ray

Checking if a file is ASCII should only be done when diffing, because
the non-ASCII characters could be printed to the screen. For
checking in files, checking out files, merging files, and removing
revisions of files, we do so regardless of whether the files are
ASCII or binary.

Fixes PR6031.

OK joris and deraadt.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.109 03-Jul-2007 ray

Rename rcs_diffreg() to diffreg().

OK joris@


# 1.108 30-Jun-2007 xsa

Sync revisions and time buffers size to be consistent with each others.
Simplifies further size tweaks if needed.
OK ray@.


# 1.107 08-Jun-2007 xsa

If strict locking is disabled, make file writable by owner on checkout.
Matches GNU's behaviour. From Pierre Riteau (long time ago).


# 1.106 07-Jun-2007 xsa

Correct exit value when one of the files specified cannot be checked out.
Matches GNU's behaviour. From Pierre Riteau (long time ago).


Revision tags: OPENBSD_4_1_BASE
# 1.105 27-Feb-2007 xsa

As done in OpenCVS, general includes cleanup sweep. OK otto@.


# 1.104 22-Feb-2007 otto

If a ,suffix file is given as an arg to ci and co, strip it. Avoids
potential disasters. Initial diff from niallo@, ok niallo@ joris@


# 1.103 21-Feb-2007 niallo

make sure checkout_rev() sets correct file permissions via file->rf_mode
in case where fstat() of file->rf_fd won't give us right mode.

fixes PR #5383

ok xsa@


# 1.102 18-Feb-2007 xsa

keep correct permissions on the RCS file when locking/unlocking the file
with ci and co. fixes PR 5379.
OK millert@ joris@.


# 1.101 01-Feb-2007 millert

When checking to see if a checked-out copy of the file is the same
as what is in the repo, expand keywords before doing the diff.
OK xsa@


# 1.100 10-Nov-2006 millert

Unlike GNU rcs, our co will not overwrite an existing file, even
if the existing file is not writable. While safer, this can be
annoying. I've changed things to compare the version of the file
being checked out with its current contents and, if they are the
same, to allow the checkout without user intervention. The behavior
when there is a writable version of the file is unchanged. OK xsa@


# 1.99 09-Nov-2006 millert

Simplify stripping of write bits from file mode.
Add support for reusing the checkin message for multiple files, ala GNU
Fix the message when you abort a checkout and the file was not writable.
OK joris@ niallo@


# 1.98 12-Oct-2006 niallo

- convert some warnx() to warn(), which fixes a few stupidly un-informative error messages (found by tom@)
- make rcs_choosefile() save wrt errno, input from ray@

ok joris@ xsa@


Revision tags: OPENBSD_4_0_BASE
# 1.97 07-Aug-2006 ray

More strlcpy/strlcat -> snprintf/xasprintf cleanup.

OK joris@


# 1.96 01-Aug-2006 ray

Reduce rcs_buf_release() usage, improving binary support.

OK niallo@


# 1.95 03-Jun-2006 niallo

- correctly handle binary files; say bye bye to using c strings for deltatexts.

"slap it in" joris@


# 1.94 28-May-2006 ray

Remove a lot of xstrdup() calls in getopt() loops, which are usually
unnecessary. These xstrdup() calls don't call xfree() before anyway,
so if a flag is given multiple times memory leaks would have resulted.

OK joris@


# 1.93 27-May-2006 ray

Rename RCSFILE.fd to RCSFILE.rf_fd, plus minor spacing nits. No
binary change.

OK xsa@


# 1.92 27-May-2006 ray

Remove rcs_statfile(). It was just a wrapper for rcs_choosefile(),
handling exceptions oddly.

OK joris@


# 1.91 17-May-2006 xsa

fix printf's


# 1.90 11-May-2006 xsa

fix informative msg's wrt to -q and stderr. now matches gnu/usr.bin/rcs.


# 1.89 09-May-2006 ray

Remove /* NOTREACHED */ comments, now that lint is smart about
__dead. I never should have put them there.

OK xsa@.


# 1.88 05-May-2006 ray

o GNU ci returns 0 when a file is reverted (co -l file; ci file).
o Don't unlock file after revert.
o Fix spelling.

Passes extra tests in GNU rcstest.

OK niallo@.


# 1.87 29-Apr-2006 ray

Check return values for all strlcpy, and strlcat calls.

OK xsa@ and probably others.


# 1.86 26-Apr-2006 joris

prevent file races by obtaining an fd for the RCS file and
do our operations on that, this is safe and guarantees we
can operate on the file until we close(2) it.

a fix is coming for the remaining races in our diff code.
okay niallo@ and ray@


# 1.85 26-Apr-2006 joris

fork our code we shared between openrcs/cvs into the openrcs dir.

this was starting to become inhuman to maintain without
ugly ugly hacks in the shared code, and it will be easier
to make specific changes for openrcs without touching the
soon-to-be-replaced opencvs code.


# 1.84 25-Apr-2006 xsa

fatal() -> err()/errx() as we try to not depend on heavy cvs_log().
OK joriski.


# 1.83 24-Apr-2006 xsa

be consistent in error messages for wrongly specified keyword substitution
mode for `-k'.


# 1.82 21-Apr-2006 xsa

move shared functions into rcsutil.[ch]; this makes rcsprog.c cleaner;
"the voices in my head say OK!" joris@.


# 1.81 21-Apr-2006 xsa

remove overkill cvs_log() and rather use warn()/warnx().
OK ray@ and discussed with joris@.


# 1.80 21-Apr-2006 xsa

switch -p handling to bitwise flags; OK ray@.


# 1.79 19-Apr-2006 xsa

switch -q handling to bitwise flags; OK ray@ niallo@.


# 1.78 15-Apr-2006 pat

Plug some memory leaks; ok niallo@


# 1.77 14-Apr-2006 deraadt

excessive addition to brackets is a mental disease. you will go
blind, too. seek help. no binary change, ok joris


# 1.76 13-Apr-2006 joris

correctly handle RCS files without any revisions;
original diff from ray@, crafted into shape by myself.

okay ray@


# 1.75 13-Apr-2006 ray

*** empty log message ***


# 1.74 12-Apr-2006 deraadt

spaces


# 1.73 12-Apr-2006 ray

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@


# 1.72 10-Apr-2006 xsa

change rcs_kwexp_set() return type to void and simplify its use. OK niallo@.


# 1.71 09-Apr-2006 niallo

- don't print out warnings about locking when they are actually wrong and
just confuse the user.

ok and input joris@


# 1.70 06-Apr-2006 xsa

-z can take no argument.


# 1.69 30-Mar-2006 joris

first part of supporting branches in openrcs. right now we can only
check them out. commit is not working yet, but will be soon.

tested by myself and ray@
okay ray@


# 1.68 29-Mar-2006 ray

More closely matches GNU behavior, passes more GNU rcstest tests.

OK niallo@


# 1.67 27-Mar-2006 niallo

- properly implement GNU file modes. basically, checkout will inherit
permissions from rcs file and initial checkin will inherit permissions from
working file.

problem spotted by uwe@

ok ray@ xsa@


# 1.66 24-Mar-2006 ray

Allow the -x flag to be used without an extension.

``that makes sense'' xsa@


# 1.65 17-Mar-2006 niallo

- co usage() says we support -I, so set the flags and revision.

ok xsa@


# 1.64 16-Mar-2006 niallo

- checkout_rev() can fail, in which case we want a non-zero exit code.

ok joris@


# 1.63 16-Mar-2006 xsa

error message fix; respect -q too. Ok ray@.


# 1.62 16-Mar-2006 ray

Follow exit() with /* NOTREACHED*/ for lint.

``OK niallo@'' niallo@


# 1.61 16-Mar-2006 ray

Currently co(1) overwrites files that the current user doesn't have
write permissions for. If you own the directory, that means your
existing file, mode 000, is blown away without prompting you. GNU
RCS does this as well.

This fixes changes co(1) to always prompt if a file exists. This
breaks GNU compatibility but I think it's more important that we
prevent co(1) from overwriting files with strict permissions without
even prompting.

``makes sense'' xsa to an earlier diff


# 1.60 15-Mar-2006 niallo

- use shared cvs_yesno() for yesno prompt, fixing an issue spotted by
deraadt@

- while here, remove unecessary cast also spotted by deraadt@

ok ray@ xsa@


# 1.59 07-Mar-2006 joris

-z support for RCS;


# 1.58 06-Mar-2006 xsa

missing informative message after call to checkout_rev().


# 1.57 06-Mar-2006 xsa

should also have removed those newlines in previous commit.


# 1.56 06-Mar-2006 xsa

missing newline in checkout_rev(); spotted by joris@.


# 1.55 05-Mar-2006 niallo

our deltatexts were sometimes different from gnu. rcs_getrev() was
unconditionally doing keyword expansion, even when this wasn't what we
wanted e.g. in checkout_rev() and cvs_checkout_rev(). so:

- change semantics of rcs_getrev() to not do keyword expansion
- add an rcs.c api function rcs_kwexp_buf() which does this
- change both checkout_rev() and cvs_checkout_rev() to use this function.

eyeballed by xsa, joris and Ray Lai


Revision tags: OPENBSD_3_9_BASE
# 1.54 24-Feb-2006 xsa

remove extra printf;


# 1.53 14-Feb-2006 xsa

- fix behaviour when using -u and -l at the same time
- do not display some messages when checking in a file for the first time
OK niallo@.


# 1.52 05-Jan-2006 xsa

cleanup, move log.h and rcs.h inclusion into rcsprog.h;


# 1.51 02-Jan-2006 xsa

#include's cleanup; ok joris@ niallo@.


# 1.50 27-Dec-2005 niallo

- implement lazy-parsing of rcs files, that is only parse as much as we
need. this can save us much work, particularly with very large rcs files.

first of a few important performance improvements.

ok joris@


# 1.49 23-Dec-2005 joris

support co -d, which checks out the first revision who's
date is less than or equal to the given date.


# 1.48 19-Dec-2005 xsa

use fatal() if getlogin() fails;


# 1.47 10-Dec-2005 joris

switch to xmalloc stuff, me and xsa@ agreed on this a long
time ago, but we were being held back by jfb. too bad for him.

next step is to use fatal() through out the code for unrecoverable
errors instead of trying to be all nice and fluffy and reach main() again.

ok niallo@ and xsa@


# 1.46 09-Dec-2005 joris

if we are removing a lock that's not present, just check
out the file without complaining;


# 1.45 09-Dec-2005 joris

unused vars, my bad;


# 1.44 08-Dec-2005 joris

complete and correct rcs locking functionality,
it was only done partially and as a bonus, completely wrong.

seriously guys what was up with that?


# 1.43 05-Dec-2005 xsa

correctly handle `-wfoo' and `-sbar' errors; OK joris@.


# 1.42 02-Dec-2005 xsa

`-mmsg' does not belong here;


# 1.41 30-Nov-2005 xsa

check for ownership of already present writable file when checking out;


# 1.40 30-Nov-2005 xsa

writeable -> writable


# 1.39 29-Nov-2005 xsa

consistency in variables naming;


# 1.38 29-Nov-2005 xsa

some more bits for `-w[user]' support;


# 1.37 25-Nov-2005 xsa

add support for `-T' and enable it for co(1);
tested and OK niallo@. "Looks good" joris@.


# 1.36 24-Nov-2005 xsa

memset();


# 1.35 23-Nov-2005 xsa

cannot combine -kv and -l;


# 1.34 23-Nov-2005 xsa

initial bits for -T support;


# 1.33 23-Nov-2005 xsa

add support for `-kmode';


# 1.32 23-Nov-2005 xsa

sync SYNOPSIS with Reality and usage() accordingly;


# 1.31 22-Nov-2005 xsa

make `-p' work again as expected;


# 1.30 21-Nov-2005 xsa

enable `-xsuffixes' support as it has been added a few days ago
in rcs_statfile();
niallo ok


# 1.29 08-Nov-2005 xsa

nuke trailing whitespaces;


# 1.28 03-Nov-2005 niallo

- update comment for checkout_rev() for bitwise flags.


# 1.27 03-Nov-2005 niallo

- sync checkout_usage();


# 1.26 03-Nov-2005 niallo

- implement `-M' option.


# 1.25 02-Nov-2005 niallo

- update the comment for checkout_state(); it did not tell the truth
about values returned.


# 1.24 02-Nov-2005 niallo

changes from Venice:

- instead of using lots of individual flag variables, use a single int and
bitwise operations on it. while this saves memory, really it saves code
space and reduces complexity. checkout_rev() and checkout_state() in
particular benefit from these changes since their parameters where growing
really long.

- implement `-s' option in co

- implement `-M' option in ci

"I like this, go for it" joris@


# 1.23 25-Oct-2005 xsa

nuke trailing whitespaces;


# 1.22 20-Oct-2005 xsa

fix output if -p is specified; joris ok


# 1.21 19-Oct-2005 niallo

- make a bunch of changes to how we handle verbose output. this brings us
much closer in line with GNU RCS and cleans things up in general.

ok joris@, "looks fine to me" xsa@


# 1.20 19-Oct-2005 joris

add co -p support;
input from xsa@ and niallo@;


# 1.19 18-Oct-2005 joris

use rcs_set_rev() instead of duplicating code all over the
place to set a variable to the given revision number;


# 1.18 17-Oct-2005 joris

support -f flag for co;
'fine' niallo@


# 1.17 16-Oct-2005 joris

spacing;


# 1.16 16-Oct-2005 niallo

- sync checkout_usage();


# 1.15 15-Oct-2005 niallo

- if revision passed to checkout_rev() is > HEAD, assume HEAD
(like GNU RCS).
- move verbose output into checkout_rev() function itself.

"looks sane" joris@


# 1.14 15-Oct-2005 niallo

modularise checkout code into checkout_rev(). this shaves off a number
of lines in ci.c due to code re-use, and will simplify features which are in
the pipeline. no functional changes.

ok joris@


# 1.13 13-Oct-2005 joris

To be fully compatibly with the GNU RCS tools we need to have the
same way of parsing commandline options. Since getopt(3) allows spaces
between arguments and GNU RCS tools does not we needed to roll out our
own way of option handling, and here it is.

ok niallo@


# 1.12 12-Oct-2005 xsa

minor knf;


# 1.11 12-Oct-2005 deraadt

various usage cleanup; ok joris


# 1.10 10-Oct-2005 xsa

getlogin(2) sets errno;


# 1.9 10-Oct-2005 niallo

sync checkout_usage();


# 1.8 10-Oct-2005 niallo

- set permissions on checked out files correctly
- support bare `-u' and `-l' options which will check out HEAD.

note that with OpenRCS you must do `co -l -- <file>' and `co -u -- <file>'
when using bare arguments because our getopt(3) is POSIX compliant.

ok joris@


# 1.7 05-Oct-2005 joris

sync usage and add V flag;


# 1.6 05-Oct-2005 joris

- stop gcc's yapping;
- better output when locking and unlocking revisions;


# 1.5 05-Oct-2005 joris

- better output
- free frev when done


# 1.4 04-Oct-2005 joris

- support -l and -u flags;
- better output;


# 1.3 29-Sep-2005 joris

support -q flag in 'co' and 'rcs'


# 1.2 29-Sep-2005 joris

fix usage


# 1.1 29-Sep-2005 joris

put it basic checkout code