xref: /openbsd-src/usr.bin/cvs/cmd.c (revision daf88648c0e349d5c02e1504293082072c981640)
1 /*	$OpenBSD: cmd.c,v 1.55 2006/11/27 14:19:53 xsa Exp $	*/
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 "includes.h"
28 
29 #include "cvs.h"
30 #include "log.h"
31 
32 extern char *cvs_rootstr;
33 
34 struct cvs_cmd *cvs_cdt[] = {
35 	&cvs_cmd_add,
36 	&cvs_cmd_admin,
37 	&cvs_cmd_annotate,
38 	&cvs_cmd_commit,
39 	&cvs_cmd_checkout,
40 	&cvs_cmd_diff,
41 	&cvs_cmd_export,
42 	&cvs_cmd_import,
43 	&cvs_cmd_init,
44 	&cvs_cmd_log,
45 	&cvs_cmd_remove,
46 	&cvs_cmd_server,
47 	&cvs_cmd_status,
48 	&cvs_cmd_tag,
49 	&cvs_cmd_update,
50 	&cvs_cmd_version,
51 #if 0
52 	&cvs_cmd_checkout,
53 	&cvs_cmd_edit,
54 	&cvs_cmd_editors,
55 	&cvs_cmd_history,
56 #if 0
57 	&cvs_cmd_login,
58 	&cvs_cmd_logout,
59 #endif
60 	&cvs_cmd_rdiff,
61 	&cvs_cmd_release,
62 	&cvs_cmd_rlog,
63 	&cvs_cmd_rtag,
64 	&cvs_cmd_unedit,
65 	&cvs_cmd_update,
66 	&cvs_cmd_watch,
67 	&cvs_cmd_watchers,
68 #endif
69 	NULL
70 };
71 
72 struct cvs_cmd *
73 cvs_findcmd(const char *cmd)
74 {
75 	int i, j;
76 	struct cvs_cmd *cmdp;
77 
78 	cmdp = NULL;
79 
80 	for (i = 0; (cvs_cdt[i] != NULL) && (cmdp == NULL); i++) {
81 		if (strcmp(cmd, cvs_cdt[i]->cmd_name) == 0)
82 			cmdp = cvs_cdt[i];
83 		else {
84 			for (j = 0; j < CVS_CMD_MAXALIAS; j++) {
85 				if (strcmp(cmd,
86 				    cvs_cdt[i]->cmd_alias[j]) == 0) {
87 					cmdp = cvs_cdt[i];
88 					break;
89 				}
90 			}
91 		}
92 	}
93 
94 	return (cmdp);
95 }
96 
97 struct cvs_cmd *
98 cvs_findcmdbyreq(int reqid)
99 {
100 	int i;
101 	struct cvs_cmd *cmdp;
102 
103 	cmdp = NULL;
104 	for (i = 0; cvs_cdt[i] != NULL; i++)
105 		if (cvs_cdt[i]->cmd_req == reqid) {
106 			cmdp = cvs_cdt[i];
107 			break;
108 		}
109 
110 	return (cmdp);
111 }
112