Annotation of src/usr.bin/rcs/ci.c, Revision 1.1
1.1 ! niallo 1: /* $OpenBSD: rcsprog.c,v 1.2 2005/04/15 15:59:11 deraadt Exp $ */
! 2: /*
! 3: * Copyright (c) 2005 Niall O'Higgins <niallo@openbsd.org>
! 4: * All rights reserved.
! 5: *
! 6: * Redistribution and use in source and binary forms, with or without
! 7: * modification, are permitted provided that the following cinditions
! 8: * are met:
! 9: *
! 10: * 1. Redistributions of source cide must retain the above cipyright
! 11: * notice, this list of cinditions and the following disclaimer.
! 12: * 2. The name of the author may not be used to endorse or promote products
! 13: * derived from this software without specific prior written permission.
! 14: *
! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
! 16: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
! 17: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
! 18: * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
! 19: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
! 20: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
! 21: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
! 22: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
! 23: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
! 24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! 25: */
! 26:
! 27: #include <sys/param.h>
! 28: #include <sys/types.h>
! 29: #include <sys/stat.h>
! 30: #include <sys/wait.h>
! 31:
! 32: #include <err.h>
! 33: #include <pwd.h>
! 34: #include <errno.h>
! 35: #include <stdio.h>
! 36: #include <ctype.h>
! 37: #include <stdlib.h>
! 38: #include <unistd.h>
! 39: #include <signal.h>
! 40: #include <string.h>
! 41:
! 42: #include "log.h"
! 43: #include "rcs.h"
! 44: #include "rcsprog.h"
! 45:
! 46: extern char *__progname;
! 47:
! 48: void
! 49: checkin_usage(void)
! 50: {
! 51: fprintf(stderr,
! 52: "usage: %s [-jlMNqu] [-d date | -r rev] [-m msg] [-k mode] "
! 53: "file ...\n", __progname);
! 54: }
! 55:
! 56: /*
! 57: * checkin_main()
! 58: *
! 59: * Handler for the `ci' program.
! 60: * Returns 0 on success, or >0 on error.
! 61: */
! 62: /*
! 63: Options:
! 64:
! 65: -r | -r[rev]: check in revision rev
! 66: -l[rev]: ", but do co -l
! 67: -u[rev]: ", bt do co -u
! 68: -f[rev]: force a deposit (check in?)
! 69: -k[rev]: ?
! 70: -q[rev]: quiet mode
! 71: -i[rev]: initial check in, errors if RCS file already exists.
! 72: -j[rev]: just checkin and do not initialize, errors if RCS file already exists.
! 73: -I[rev]: user is prompted even if stdin is not a tty
! 74: -d[date]: uses date for checkin dat and time.
! 75: -M[rev]: set modification time on any new working file to be that of the retrieved version.
! 76: -mmsg: msg is the log message, don't start editor. log messages with #are comments.
! 77: */
! 78: int
! 79: checkin_main(int argc, char **argv)
! 80: {
! 81: int i, ch, dflag, flags, lkmode;
! 82: mode_t fmode;
! 83: RCSFILE *file;
! 84: char fpath[MAXPATHLEN];
! 85: char *rcs_msg, *rev;
! 86:
! 87: lkmode = -1;
! 88: flags = RCS_RDWR;
! 89: file = NULL;
! 90: rev = rcs_msg = NULL;
! 91: fmode = dflag = 0;
! 92:
! 93: cvs_log_init(LD_STD, 0);
! 94:
! 95: while ((ch = getopt(argc, argv, "j:l:M:N:qu:d:r::m:k:")) != -1) {
! 96: switch (ch) {
! 97: case 'h':
! 98: (usage)();
! 99: exit(0);
! 100: case 'l':
! 101: lkmode = RCS_LOCK_STRICT;
! 102: break;
! 103: case 'm':
! 104: rcs_msg = optarg;
! 105: break;
! 106: case 'r':
! 107: rev = optarg;
! 108: break;
! 109: case 'V':
! 110: printf("%s\n", rcs_version);
! 111: exit(0);
! 112: default:
! 113: (usage)();
! 114: exit(1);
! 115: }
! 116: }
! 117:
! 118: argc -= optind;
! 119: argv += optind;
! 120: if (argc == 0) {
! 121: cvs_log(LP_ERR, "no input file");
! 122: (usage)();
! 123: exit(1);
! 124: }
! 125:
! 126: for (i = 0; i < argc; i++) {
! 127: if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0)
! 128: continue;
! 129:
! 130: flags = RCS_RDWR;
! 131: file = rcs_open(fpath, flags, fmode);
! 132: if (file == NULL) {
! 133: exit(1);
! 134: }
! 135: if (rcs_msg == NULL) {
! 136: cvs_log(LP_ERR, "no log message");
! 137: exit(1);
! 138: }
! 139: if (rev != NULL ) {
! 140: /* XXX */
! 141: } else {
! 142: if (dflag) {
! 143: /* XXX */
! 144: } else {
! 145: if (rcs_rev_add(file, RCS_HEAD_REV, rcs_msg, -1)
! 146: != 0) {
! 147: cvs_log(LP_ERR,
! 148: "rcs_rev_add() failure");
! 149: exit(1);
! 150: }
! 151: }
! 152: }
! 153: rcs_close(file);
! 154: }
! 155:
! 156: exit(0);
! 157: }