Annotation of src/usr.bin/cvs/edit.c, Revision 1.9
1.9 ! xsa 1: /* $OpenBSD: edit.c,v 1.8 2005/07/25 12:05:43 xsa Exp $ */
1.1 jfb 2: /*
3: * Copyright (c) 2005 Jean-Francois Brousseau <jfb@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>
1.5 xsa 31: #include <libgen.h>
1.1 jfb 32: #include <stdio.h>
33: #include <stdlib.h>
34: #include <string.h>
35: #include <unistd.h>
36:
37: #include "cvs.h"
38: #include "log.h"
39: #include "proto.h"
40:
41:
42:
1.8 xsa 43: static int cvs_edit_init(struct cvs_cmd *, int, char **, int *);
44: static int cvs_edit_remote(CVSFILE *, void *);
45: static int cvs_edit_local(CVSFILE *, void *);
1.1 jfb 46:
1.9 ! xsa 47: static int cvs_editors_remote(CVSFILE *, void *);
! 48:
1.1 jfb 49:
50: struct cvs_cmd cvs_cmd_edit = {
51: CVS_OP_EDIT, CVS_REQ_NOOP, "edit",
52: { },
53: "Mark a file as being edited",
1.2 xsa 54: "[-lR] [-a action] [file ...]",
1.1 jfb 55: "a:lR",
56: NULL,
57: CF_SORT | CF_RECURSE,
58: cvs_edit_init,
59: NULL,
60: cvs_edit_remote,
61: cvs_edit_local,
62: NULL,
63: NULL,
64: 0
65: };
66:
67: struct cvs_cmd cvs_cmd_editors = {
68: CVS_OP_EDITORS, CVS_REQ_EDITORS, "editors",
69: { },
70: "List editors on a file",
1.3 xsa 71: "[-lR] [file ...]",
72: "lR",
1.1 jfb 73: NULL,
1.9 ! xsa 74: CF_SORT | CF_RECURSE,
1.1 jfb 75: cvs_edit_init,
76: NULL,
1.9 ! xsa 77: cvs_editors_remote,
! 78: NULL,
1.1 jfb 79: NULL,
80: NULL,
1.9 ! xsa 81: CVS_CMD_SENDDIR | CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2
1.1 jfb 82: };
83:
84:
85: struct cvs_cmd cvs_cmd_unedit = {
86: CVS_OP_UNEDIT, CVS_REQ_NOOP, "unedit",
87: { },
88: "Undo an edit command",
1.3 xsa 89: "[-lR] [file ...]",
1.1 jfb 90: "lR",
91: NULL,
92: CF_SORT | CF_RECURSE,
93: cvs_edit_init,
94: NULL,
95: cvs_edit_remote,
96: cvs_edit_local,
97: NULL,
98: NULL,
99: 0
100: };
101:
102:
103:
104: static int
105: cvs_edit_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
106: {
1.7 joris 107: int ch, dflag, mod_count;
1.1 jfb 108:
109: dflag = 0;
110: mod_count = 0;
111:
112: while ((ch = getopt(argc, argv, cmd->cmd_opts)) != -1) {
113: switch (ch) {
114: case 'a':
1.6 xsa 115: /*
116: * The `editors' and `unedit' commands do not have
117: * the -a option. Check which command has been issued.
118: */
1.1 jfb 119: if (cvs_cmdop != CVS_OP_EDIT)
120: return (CVS_EX_USAGE);
121: break;
122: case 'l':
123: cmd->file_flags &= ~CF_RECURSE;
124: break;
125: case 'R':
126: cmd->file_flags |= CF_RECURSE;
127: break;
128: default:
129: return (CVS_EX_USAGE);
130: }
131: }
132:
133: *arg = optind;
134: return (CVS_EX_OK);
135: }
136:
137:
138: /*
139: * cvs_edit_remote()
140: *
141: */
142: static int
1.9 ! xsa 143: cvs_edit_remote(CVSFILE *cf, void *arg)
1.1 jfb 144: {
145: int *mod_count;
146:
147: mod_count = (int *)arg;
148:
149: return (CVS_EX_OK);
150: }
151:
152:
153: /*
154: * cvs_edit_local()
155: *
156: */
157: static int
1.9 ! xsa 158: cvs_edit_local(CVSFILE *cf, void *arg)
1.1 jfb 159: {
160: int *mod_count;
161:
162: mod_count = (int *)arg;
163:
164: return (CVS_EX_OK);
1.9 ! xsa 165: }
! 166:
! 167:
! 168: /*
! 169: * cvs_editors_remote()
! 170: *
! 171: */
! 172: static int
! 173: cvs_editors_remote(CVSFILE *cf, void *arg)
! 174: {
! 175: int ret;
! 176: struct cvsroot *root;
! 177:
! 178: ret = 0;
! 179: root = CVS_DIR_ROOT(cf);
! 180:
! 181: if (cf->cf_type == DT_DIR) {
! 182: if (cf->cf_cvstat == CVS_FST_UNKNOWN)
! 183: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
! 184: cf->cf_name);
! 185: else
! 186: ret = cvs_senddir(root, cf);
! 187:
! 188: if (ret == -1)
! 189: ret = CVS_EX_PROTO;
! 190:
! 191: return (ret);
! 192: }
! 193:
! 194: if (cvs_sendentry(root, cf) < 0)
! 195: return (CVS_EX_PROTO);
! 196:
! 197: switch (cf->cf_cvstat) {
! 198: case CVS_FST_UNKNOWN:
! 199: ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
! 200: break;
! 201: case CVS_FST_UPTODATE:
! 202: ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, cf->cf_name);
! 203: break;
! 204: case CVS_FST_ADDED:
! 205: case CVS_FST_MODIFIED:
! 206: ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED, cf->cf_name);
! 207: break;
! 208: default:
! 209: break;
! 210: }
! 211:
! 212:
! 213: if (ret == -1)
! 214: ret = CVS_EX_PROTO;
! 215:
! 216: return (ret);
1.1 jfb 217: }