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