Annotation of src/usr.bin/cvs/watch.c, Revision 1.6
1.6 ! xsa 1: /* $OpenBSD: watch.c,v 1.5 2005/07/25 12:13:08 xsa 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:
27: #include <sys/types.h>
28:
29: #include <errno.h>
30: #include <fcntl.h>
31: #include <stdio.h>
32: #include <stdlib.h>
33: #include <string.h>
34: #include <unistd.h>
35:
36: #include "cvs.h"
37: #include "log.h"
38: #include "proto.h"
39:
1.5 xsa 40: static int cvs_watch_init(struct cvs_cmd *, int, char **, int *);
41: static int cvs_watch_remote(CVSFILE *, void*);
42: static int cvs_watch_local(CVSFILE *, void*);
1.1 xsa 43:
1.5 xsa 44: static int cvs_watchers_remote(CVSFILE *, void*);
45: static int cvs_watchers_local(CVSFILE *, void*);
1.1 xsa 46:
47:
48: struct cvs_cmd cvs_cmd_watch = {
49: CVS_OP_WATCH, CVS_REQ_NOOP, "watch",
50: {},
1.3 xsa 51: "Set watches",
1.1 xsa 52: "on | off | add | remove [-lR] [-a action] [file ...]",
53: "a:lR",
54: NULL,
55: CF_SORT | CF_RECURSE,
56: cvs_watch_init,
57: NULL,
58: cvs_watch_remote,
59: cvs_watch_local,
60: NULL,
61: NULL,
62: 0
63: };
64:
65: struct cvs_cmd cvs_cmd_watchers = {
1.4 joris 66: CVS_OP_WATCHERS, CVS_REQ_WATCHERS, "watchers",
67: {},
68: "See who is watching a file",
69: "[-lR] [file ...]",
70: "lR",
71: NULL,
72: CF_SORT | CF_RECURSE,
73: cvs_watch_init,
74: NULL,
75: cvs_watchers_remote,
76: cvs_watchers_local,
77: NULL,
78: NULL,
1.6 ! xsa 79: CVS_CMD_SENDDIR | CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2
1.1 xsa 80: };
81:
82:
83:
84: static int
85: cvs_watch_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
86: {
87: int ch;
1.4 joris 88:
1.1 xsa 89: while ((ch = getopt(argc, argv, cmd->cmd_opts)) != -1) {
90: switch (ch) {
91: case 'a':
1.2 xsa 92: /*
93: * The `watchers' command does not have the
94: * -a option. Check which command has been issued.
95: */
1.1 xsa 96: if (cvs_cmdop != CVS_OP_WATCH)
97: return (CVS_EX_USAGE);
98: break;
99: case 'l':
100: cmd->file_flags &= ~CF_RECURSE;
101: break;
102: case 'R':
103: cmd->file_flags |= CF_RECURSE;
104: break;
105: default:
106: return (CVS_EX_USAGE);
107: }
108: }
109:
110: *arg = optind;
111: return (CVS_EX_OK);
112: }
113:
114:
115: /*
116: * cvs_watch_remote()
117: *
118: */
119: static int
1.6 ! xsa 120: cvs_watch_remote(CVSFILE *cf, void *arg)
1.1 xsa 121: {
122: return (CVS_EX_OK);
123: }
124:
125:
126: /*
127: * cvs_watch_local()
128: *
129: */
130: static int
1.6 ! xsa 131: cvs_watch_local(CVSFILE *cf, void *arg)
1.1 xsa 132: {
133: return (CVS_EX_OK);
134: }
135:
136:
137: /*
138: * cvs_watchers_remote()
139: *
140: */
141: static int
1.6 ! xsa 142: cvs_watchers_remote(CVSFILE *cf, void *arg)
1.1 xsa 143: {
1.6 ! xsa 144: int ret;
! 145: struct cvsroot *root;
! 146:
! 147: ret = 0;
! 148: root = CVS_DIR_ROOT(cf);
! 149:
! 150: if (cf->cf_type == DT_DIR) {
! 151: if (cf->cf_cvstat == CVS_FST_UNKNOWN)
! 152: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
! 153: cf->cf_name);
! 154: else
! 155: ret = cvs_senddir(root, cf);
! 156:
! 157: if (ret == -1)
! 158: ret = CVS_EX_PROTO;
! 159:
! 160: return (ret);
! 161: }
! 162:
! 163: if (cvs_sendentry(root, cf) < 0)
! 164: return (CVS_EX_PROTO);
! 165:
! 166: switch (cf->cf_cvstat) {
! 167: case CVS_FST_UNKNOWN:
! 168: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
! 169: break;
! 170: case CVS_FST_UPTODATE:
! 171: ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, cf->cf_name);
! 172: break;
! 173: case CVS_FST_ADDED:
! 174: case CVS_FST_MODIFIED:
! 175: ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED, cf->cf_name);
! 176: break;
! 177: default:
! 178: break;
! 179: }
! 180:
! 181: if (ret == -1)
! 182: ret = CVS_EX_PROTO;
! 183:
! 184: return (ret);
1.1 xsa 185: }
1.4 joris 186:
1.1 xsa 187: /*
188: * cvs_watchers_local()
189: *
190: */
191: static int
1.6 ! xsa 192: cvs_watchers_local(CVSFILE *cf, void *arg)
1.1 xsa 193: {
194: return (CVS_EX_OK);
195: }