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

Annotation of src/usr.bin/rcs/rcsmerge.c, Revision 1.14

1.14    ! xsa         1: /*     $OpenBSD: rcsmerge.c,v 1.13 2006/01/05 10:28:24 xsa Exp $       */
1.1       xsa         2: /*
1.14    ! xsa         3:  * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org>
1.1       xsa         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 conditions
                      8:  * are met:
                      9:  *
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions 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:
1.12      xsa        27: #include "includes.h"
1.1       xsa        28:
1.13      xsa        29: #include "rcsprog.h"
1.1       xsa        30: #include "diff.h"
                     31:
                     32: static int kflag = RCS_KWEXP_ERR;
                     33:
                     34: int
                     35: rcsmerge_main(int argc, char **argv)
                     36: {
                     37:        int i, ch;
1.2       joris      38:        char *fcont, fpath[MAXPATHLEN];
1.1       xsa        39:        RCSFILE *file;
1.2       joris      40:        RCSNUM *baserev, *rev2, *frev;
                     41:        BUF *bp;
1.1       xsa        42:
1.2       joris      43:        baserev = rev2 = RCS_HEAD_REV;
1.1       xsa        44:
1.14    ! xsa        45:        while ((ch = rcs_getopt(argc, argv, "AEek:p::q::r:TVx:")) != -1) {
1.1       xsa        46:                switch (ch) {
1.14    ! xsa        47:                case 'A': case 'E': case 'e':
        !            48:                        break;
1.1       xsa        49:                case 'k':
                     50:                        kflag = rcs_kflag_get(rcs_optarg);
                     51:                        if (RCS_KWEXP_INVAL(kflag)) {
                     52:                                cvs_log(LP_ERR,
                     53:                                    "invalid RCS keyword expansion mode");
                     54:                                (usage)();
                     55:                                exit(1);
                     56:                        }
                     57:                        break;
1.2       joris      58:                case 'p':
                     59:                        rcs_set_rev(rcs_optarg, &baserev);
                     60:                        pipeout = 1;
                     61:                        break;
1.1       xsa        62:                case 'q':
1.7       xsa        63:                        rcs_set_rev(rcs_optarg, &baserev);
1.1       xsa        64:                        verbose = 0;
                     65:                        break;
                     66:                case 'r':
1.2       joris      67:                        if (baserev == RCS_HEAD_REV)
                     68:                                rcs_set_rev(rcs_optarg, &baserev);
                     69:                        else if (rev2 == RCS_HEAD_REV)
                     70:                                rcs_set_rev(rcs_optarg, &rev2);
                     71:                        else
1.14    ! xsa        72:                                fatal("too many revision numbers");
1.1       xsa        73:                        break;
                     74:                case 'T':
                     75:                        /*
                     76:                         * kept for compatibility
                     77:                         */
                     78:                        break;
                     79:                case 'V':
                     80:                        printf("%s\n", rcs_version);
                     81:                        exit(0);
1.9       xsa        82:                case 'x':
                     83:                        rcs_suffixes = rcs_optarg;
                     84:                        break;
1.1       xsa        85:                default:
                     86:                        break;
                     87:                }
                     88:        }
                     89:
                     90:        argc -= rcs_optind;
                     91:        argv += rcs_optind;
                     92:
                     93:        if (argc < 0) {
                     94:                cvs_log(LP_ERR, "no input file");
                     95:                (usage)();
                     96:                exit(1);
                     97:        }
                     98:
1.2       joris      99:        if (baserev == RCS_HEAD_REV) {
1.4       xsa       100:                cvs_log(LP_ERR, "no base revision number given");
1.2       joris     101:                (usage)();
                    102:                exit(1);
                    103:        }
                    104:
1.1       xsa       105:        for (i = 0; i < argc; i++) {
                    106:                if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0)
                    107:                        continue;
                    108:
                    109:                if ((file = rcs_open(fpath, RCS_READ)) == NULL)
                    110:                        continue;
1.2       joris     111:
1.14    ! xsa       112:                printf("RCS file: %s\n", fpath);
        !           113:
1.2       joris     114:                if (rev2 == RCS_HEAD_REV)
                    115:                        frev = file->rf_head;
                    116:                else
                    117:                        frev = rev2;
1.8       xsa       118:
1.14    ! xsa       119:                if (rcsnum_cmp(baserev, frev, 0) == 0) {
        !           120:                        rcs_close(file);
        !           121:                        continue;
        !           122:                }
1.2       joris     123:
                    124:                if ((bp = cvs_diff3(file, argv[i], baserev, frev)) == NULL) {
                    125:                        cvs_log(LP_ERR, "failed to merge");
                    126:                        rcs_close(file);
                    127:                        continue;
                    128:                }
                    129:
                    130:                if (pipeout == 1) {
                    131:                        if (cvs_buf_putc(bp, '\0') < 0) {
                    132:                                rcs_close(file);
                    133:                                continue;
                    134:                        }
                    135:
                    136:                        fcont = cvs_buf_release(bp);
                    137:                        printf("%s", fcont);
1.11      joris     138:                        xfree(fcont);
1.2       joris     139:                } else {
                    140:                        /* XXX mode */
                    141:                        if (cvs_buf_write(bp, argv[i], 0644) < 0)
                    142:                                cvs_log(LP_ERR, "failed to write new file");
                    143:
                    144:                        cvs_buf_free(bp);
1.3       joris     145:                }
1.1       xsa       146:                rcs_close(file);
                    147:        }
                    148:
                    149:        return (0);
                    150: }
                    151:
                    152: void
                    153: rcsmerge_usage(void)
                    154: {
                    155:        fprintf(stderr,
1.7       xsa       156:            "usage: rcsmerge [-TV] [-kmode] [-p[rev]] [-q[rev]] "
1.10      xsa       157:            "[-rrev] [-xsuffixes] file ...\n");
1.1       xsa       158: }