1 /*	$OpenBSD: lcmd.c,v 1.5 2003/06/03 02:56:23 millert Exp $	*/
2 /*	$NetBSD: lcmd.c,v 1.3 1995/09/28 10:34:21 tls Exp $	*/
3 
4 /*
5  * Copyright (c) 1983, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * Edward Wang at The University of California, Berkeley.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 
36 #ifndef lint
37 #if 0
38 static char sccsid[] = "@(#)lcmd.c	8.1 (Berkeley) 6/6/93";
39 #else
40 static char rcsid[] = "$OpenBSD: lcmd.c,v 1.5 2003/06/03 02:56:23 millert Exp $";
41 #endif
42 #endif /* not lint */
43 
44 #include "defs.h"
45 #include "value.h"
46 #include "lcmd.h"
47 
48 int l_alias();
49 int l_close();
50 int l_cursormodes();
51 int l_debug();
52 int l_def_nline();
53 int l_def_shell();
54 int l_def_smooth();
55 int l_echo();
56 int l_escape();
57 int l_foreground();
58 int l_iostat();
59 int l_label();
60 int l_list();
61 int l_select();
62 int l_smooth();
63 int l_source();
64 int l_terse();
65 int l_time();
66 int l_unalias();
67 int l_unset();
68 int l_variable();
69 int l_window();
70 int l_write();
71 
72 extern struct lcmd_arg arg_alias[];
73 extern struct lcmd_arg arg_cursormodes[];
74 extern struct lcmd_arg arg_debug[];
75 extern struct lcmd_arg arg_echo[];
76 extern struct lcmd_arg arg_escape[];
77 extern struct lcmd_arg arg_foreground[];
78 extern struct lcmd_arg arg_label[];
79 extern struct lcmd_arg arg_def_nline[];
80 extern struct lcmd_arg arg_def_shell[];
81 extern struct lcmd_arg arg_def_smooth[];
82 extern struct lcmd_arg arg_close[];
83 extern struct lcmd_arg arg_select[];
84 extern struct lcmd_arg arg_smooth[];
85 extern struct lcmd_arg arg_source[];
86 extern struct lcmd_arg arg_terse[];
87 extern struct lcmd_arg arg_time[];
88 extern struct lcmd_arg arg_unalias[];
89 extern struct lcmd_arg arg_unset[];
90 extern struct lcmd_arg arg_window[];
91 extern struct lcmd_arg arg_write[];
92 struct lcmd_arg arg_null[1] = { { 0 } };
93 
94 struct lcmd_tab lcmd_tab[] = {
95 	"alias",		1,	l_alias,	arg_alias,
96 	"close",		2,	l_close,	arg_close,
97 	"cursormodes",		2,	l_cursormodes,	arg_cursormodes,
98 	"debug",		1,	l_debug,	arg_debug,
99 	"default_nlines",	9,	l_def_nline,	arg_def_nline,
100 	"default_shell",	10,	l_def_shell,	arg_def_shell,
101 	"default_smooth",	10,	l_def_smooth,	arg_def_smooth,
102 	"echo",			2,	l_echo,		arg_echo,
103 	"escape",		2,	l_escape,	arg_escape,
104 	"foreground",		1,	l_foreground,	arg_foreground,
105 	"iostat",		1,	l_iostat,	arg_null,
106 	"label",		2,	l_label,	arg_label,
107 	"list",			2,	l_list,		arg_null,
108 	"nlines",		1,	l_def_nline,	arg_def_nline,
109 	"select",		2,	l_select,	arg_select,
110 	"shell",		2,	l_def_shell,	arg_def_shell,
111 	"smooth",		2,	l_smooth,	arg_smooth,
112 	"source",		2,	l_source,	arg_source,
113 	"terse",		2,	l_terse,	arg_terse,
114 	"time",			2,	l_time,		arg_time,
115 	"unalias",		3,	l_unalias,	arg_unalias,
116 	"unset",		3,	l_unset,	arg_unset,
117 	"variable",		1,	l_variable,	arg_null,
118 	"window",		2,	l_window,	arg_window,
119 	"write",		2,	l_write,	arg_write,
120 	0
121 };
122 
123 struct lcmd_tab *
lcmd_lookup(name)124 lcmd_lookup(name)
125 char *name;
126 {
127 	struct lcmd_tab *p;
128 
129 	for (p = lcmd_tab; p->lc_name != 0; p++)
130 		if (str_match(name, p->lc_name, p->lc_minlen))
131 			return p;
132 	return 0;
133 }
134 
dosource(filename)135 dosource(filename)
136 char *filename;
137 {
138 	if (cx_beginfile(filename) < 0)
139 		return -1;
140 	p_start();
141 	err_end();
142 	cx_end();
143 	return 0;
144 }
145 
dolongcmd(buffer,arg,narg)146 dolongcmd(buffer, arg, narg)
147 char *buffer;
148 struct value *arg;
149 int narg;
150 {
151 	if (cx_beginbuf(buffer, arg, narg) < 0)
152 		return -1;
153 	p_start();
154 	err_end();
155 	cx_end();
156 	return 0;
157 }
158