[BACK]Return to ci.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / rcs

Annotation of src/usr.bin/rcs/ci.c, Revision 1.3

1.3     ! joris       1: /*     $OpenBSD: ci.c,v 1.2 2005/09/30 16:49:37 joris Exp $    */
1.1       niallo      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:
1.3     ! joris      93:        while ((ch = getopt(argc, argv, "j:l:M:N:qu:d:r::m:k:V")) != -1) {
1.1       niallo     94:                switch (ch) {
                     95:                case 'h':
                     96:                        (usage)();
                     97:                        exit(0);
                     98:                case 'l':
                     99:                        lkmode = RCS_LOCK_STRICT;
                    100:                        break;
                    101:                case 'm':
                    102:                        rcs_msg = optarg;
1.3     ! joris     103:                        break;
        !           104:                case 'q':
        !           105:                        verbose = 0;
1.1       niallo    106:                        break;
                    107:                case 'r':
                    108:                        rev = optarg;
                    109:                        break;
                    110:                case 'V':
                    111:                        printf("%s\n", rcs_version);
                    112:                        exit(0);
                    113:                default:
                    114:                        (usage)();
                    115:                        exit(1);
                    116:                }
                    117:        }
                    118:
                    119:        argc -= optind;
                    120:        argv += optind;
                    121:        if (argc == 0) {
                    122:                cvs_log(LP_ERR, "no input file");
                    123:                (usage)();
                    124:                exit(1);
                    125:        }
                    126:
                    127:        for (i = 0; i < argc; i++) {
                    128:                if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0)
                    129:                        continue;
                    130:
                    131:                flags = RCS_RDWR;
                    132:                file = rcs_open(fpath, flags, fmode);
                    133:                if (file == NULL) {
                    134:                        exit(1);
                    135:                }
                    136:                if (rcs_msg == NULL) {
                    137:                        cvs_log(LP_ERR, "no log message");
                    138:                        exit(1);
                    139:                }
                    140:                if (rev != NULL ) {
                    141:                 /* XXX */
                    142:                } else {
                    143:                        if (dflag) {
                    144:                                /* XXX */
                    145:                        } else {
                    146:                                if (rcs_rev_add(file, RCS_HEAD_REV, rcs_msg, -1)
                    147:                                    != 0) {
                    148:                                        cvs_log(LP_ERR,
                    149:                                            "rcs_rev_add() failure");
                    150:                                        exit(1);
                    151:                                }
                    152:                        }
                    153:                }
                    154:                rcs_close(file);
                    155:        }
                    156:
                    157:        exit(0);
                    158: }