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

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

1.3     ! joris       1: /*     $OpenBSD: co.c,v 1.2 2005/09/29 15:21:57 joris Exp $    */
1.1       joris       2: /*
                      3:  * Copyright (c) 2005 Joris Vink <joris@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:
                     27: #include <sys/param.h>
                     28: #include <sys/stat.h>
                     29:
                     30: #include <stdio.h>
                     31: #include <stdlib.h>
                     32: #include <string.h>
                     33:
                     34: #include "log.h"
                     35: #include "rcs.h"
                     36: #include "rcsprog.h"
                     37:
                     38: extern char *__progname;
                     39:
                     40: int
                     41: checkout_main(int argc, char **argv)
                     42: {
                     43:        int i, ch;
                     44:        RCSNUM *rev;
                     45:        RCSFILE *file;
                     46:        BUF *bp;
                     47:        char buf[16];
                     48:        char *s, fpath[MAXPATHLEN];
                     49:
                     50:        rev = RCS_HEAD_REV;
1.3     ! joris      51:        while ((ch = getopt(argc, argv, "qr:")) != -1) {
1.1       joris      52:                switch (ch) {
1.3     ! joris      53:                case 'q':
        !            54:                        verbose = 0;
        !            55:                        break;
1.1       joris      56:                case 'r':
                     57:                        if ((rev = rcsnum_parse(optarg)) == NULL) {
                     58:                                cvs_log(LP_ERR, "bad revision number");
                     59:                                exit(1);
                     60:                        }
                     61:                        break;
                     62:                default:
                     63:                        (usage)();
                     64:                        exit(1);
                     65:                }
                     66:        }
                     67:
                     68:        argc -= optind;
                     69:        argv += optind;
                     70:
                     71:        if (argc == 0) {
                     72:                cvs_log(LP_ERR, "no input file");
                     73:                (usage)();
                     74:                exit (1);
                     75:        }
                     76:
                     77:        for (i = 0; i < argc; i++) {
                     78:                if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0)
                     79:                        continue;
                     80:
                     81:                if ((file = rcs_open(fpath, RCS_READ)) == NULL)
                     82:                        continue;
                     83:
                     84:                if ((s = strrchr(fpath, ',')) != NULL)
                     85:                        *s = '\0';
                     86:
                     87:                if ((bp = rcs_getrev(file, rev)) == NULL) {
                     88:                        cvs_log(LP_ERR, "cannot find '%s' in %s",
                     89:                            rcsnum_tostr(rev, buf, sizeof(buf)), fpath);
                     90:                        rcs_close(file);
                     91:                        continue;
                     92:                }
                     93:
                     94:                if (cvs_buf_write(bp, fpath, 0644) < 0)
                     95:                        cvs_log(LP_ERR, "failed to write revision to file");
                     96:
                     97:                cvs_buf_free(bp);
                     98:                rcs_close(file);
                     99:        }
                    100:
                    101:        if (rev != RCS_HEAD_REV)
                    102:                rcsnum_free(rev);
                    103:
                    104:        return (0);
                    105: }
                    106:
                    107: void
                    108: checkout_usage(void)
                    109: {
1.2       joris     110:        fprintf(stderr, "usage %s [-r rev] file ...\n", __progname);
1.1       joris     111: }