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