[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.12

1.12    ! xsa         1: /*     $OpenBSD: rcsmerge.c,v 1.11 2005/12/10 20:27:46 joris Exp $     */
1.1       xsa         2: /*
                      3:  * Copyright (c) 2005 Xavier Santolaria <xsa@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 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:
                     29: #include "log.h"
                     30: #include "rcs.h"
                     31: #include "diff.h"
                     32: #include "rcsprog.h"
                     33:
                     34: static int kflag = RCS_KWEXP_ERR;
                     35:
                     36: int
                     37: rcsmerge_main(int argc, char **argv)
                     38: {
                     39:        int i, ch;
1.2       joris      40:        char *fcont, fpath[MAXPATHLEN];
1.1       xsa        41:        RCSFILE *file;
1.2       joris      42:        RCSNUM *baserev, *rev2, *frev;
                     43:        BUF *bp;
1.1       xsa        44:
1.2       joris      45:        baserev = rev2 = RCS_HEAD_REV;
1.1       xsa        46:
1.9       xsa        47:        while ((ch = rcs_getopt(argc, argv, "k:p::q::r:TVx:")) != -1) {
1.1       xsa        48:                switch (ch) {
                     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
                     72:                                cvs_log(LP_WARN, "ignored excessive -r option");
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:
                    112:                if (rev2 == RCS_HEAD_REV)
                    113:                        frev = file->rf_head;
                    114:                else
                    115:                        frev = rev2;
1.8       xsa       116:
                    117:                printf("RCS file: %s\n", fpath);
1.2       joris     118:
                    119:                if ((bp = cvs_diff3(file, argv[i], baserev, frev)) == NULL) {
                    120:                        cvs_log(LP_ERR, "failed to merge");
                    121:                        rcs_close(file);
                    122:                        continue;
                    123:                }
                    124:
                    125:                if (pipeout == 1) {
                    126:                        if (cvs_buf_putc(bp, '\0') < 0) {
                    127:                                rcs_close(file);
                    128:                                continue;
                    129:                        }
                    130:
                    131:                        fcont = cvs_buf_release(bp);
                    132:                        printf("%s", fcont);
1.11      joris     133:                        xfree(fcont);
1.2       joris     134:                } else {
                    135:                        /* XXX mode */
                    136:                        if (cvs_buf_write(bp, argv[i], 0644) < 0)
                    137:                                cvs_log(LP_ERR, "failed to write new file");
                    138:
                    139:                        cvs_buf_free(bp);
1.3       joris     140:                }
                    141:
                    142:                if (diff3_conflicts > 0) {
                    143:                        cvs_log(LP_WARN, "%d conflict%s found during merge",
                    144:                            diff3_conflicts, (diff3_conflicts > 1) ? "s": "");
1.2       joris     145:                }
1.1       xsa       146:
                    147:                rcs_close(file);
                    148:        }
                    149:
                    150:        return (0);
                    151: }
                    152:
                    153: void
                    154: rcsmerge_usage(void)
                    155: {
                    156:        fprintf(stderr,
1.7       xsa       157:            "usage: rcsmerge [-TV] [-kmode] [-p[rev]] [-q[rev]] "
1.10      xsa       158:            "[-rrev] [-xsuffixes] file ...\n");
1.1       xsa       159: }