1 /* $OpenBSD: init.c,v 1.8 2014/10/16 18:23:26 deraadt Exp $ */ 2 /* $NetBSD: init.c,v 1.6 1995/03/21 09:03:05 cgd Exp $ */ 3 4 /*- 5 * Copyright (c) 1980, 1991, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the University nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33 #include <stdarg.h> 34 35 #include "csh.h" 36 #include "extern.h" 37 38 #define INF 1000 39 40 struct biltins bfunc[] = 41 { 42 { "@", dolet, 0, INF }, 43 { "alias", doalias, 0, INF }, 44 { "bg", dobg, 0, INF }, 45 { "break", dobreak, 0, 0 }, 46 { "breaksw", doswbrk, 0, 0 }, 47 { "case", dozip, 0, 1 }, 48 { "cd", dochngd, 0, INF }, 49 { "chdir", dochngd, 0, INF }, 50 { "continue", docontin, 0, 0 }, 51 { "default", dozip, 0, 0 }, 52 { "dirs", dodirs, 0, INF }, 53 { "echo", doecho, 0, INF }, 54 { "else", doelse, 0, INF }, 55 { "end", doend, 0, 0 }, 56 { "endif", dozip, 0, 0 }, 57 { "endsw", dozip, 0, 0 }, 58 { "eval", doeval, 0, INF }, 59 { "exec", execash, 1, INF }, 60 { "exit", doexit, 0, INF }, 61 { "fg", dofg, 0, INF }, 62 { "foreach", doforeach, 3, INF }, 63 { "glob", doglob, 0, INF }, 64 { "goto", dogoto, 1, 1 }, 65 { "hashstat", hashstat, 0, 0 }, 66 { "history", dohist, 0, 2 }, 67 { "if", doif, 1, INF }, 68 { "jobs", dojobs, 0, 1 }, 69 { "kill", dokill, 1, INF }, 70 { "limit", dolimit, 0, 3 }, 71 { "linedit", doecho, 0, INF }, 72 { "login", dologin, 0, 1 }, 73 { "logout", dologout, 0, 0 }, 74 { "nice", donice, 0, INF }, 75 { "nohup", donohup, 0, INF }, 76 { "notify", donotify, 0, INF }, 77 { "onintr", doonintr, 0, 2 }, 78 { "popd", dopopd, 0, INF }, 79 { "pushd", dopushd, 0, INF }, 80 { "rehash", dohash, 0, 0 }, 81 { "repeat", dorepeat, 2, INF }, 82 { "set", doset, 0, INF }, 83 { "setenv", dosetenv, 0, 2 }, 84 { "shift", shift, 0, 1 }, 85 { "source", dosource, 1, 2 }, 86 { "stop", dostop, 1, INF }, 87 { "suspend", dosuspend, 0, 0 }, 88 { "switch", doswitch, 1, INF }, 89 { "time", dotime, 0, INF }, 90 { "umask", doumask, 0, 1 }, 91 { "unalias", unalias, 1, INF }, 92 { "unhash", dounhash, 0, 0 }, 93 { "unlimit", dounlimit, 0, INF }, 94 { "unset", unset, 1, INF }, 95 { "unsetenv", dounsetenv, 1, INF }, 96 { "wait", dowait, 0, 0 }, 97 { "which", dowhich, 1, INF }, 98 { "while", dowhile, 1, INF } 99 }; 100 int nbfunc = sizeof bfunc / sizeof *bfunc; 101 102 struct srch srchn[] = 103 { 104 { "@", T_LET }, 105 { "break", T_BREAK }, 106 { "breaksw", T_BRKSW }, 107 { "case", T_CASE }, 108 { "default", T_DEFAULT }, 109 { "else", T_ELSE }, 110 { "end", T_END }, 111 { "endif", T_ENDIF }, 112 { "endsw", T_ENDSW }, 113 { "exit", T_EXIT }, 114 { "foreach", T_FOREACH }, 115 { "goto", T_GOTO }, 116 { "if", T_IF }, 117 { "label", T_LABEL }, 118 { "set", T_SET }, 119 { "switch", T_SWITCH }, 120 { "while", T_WHILE } 121 }; 122 int nsrchn = sizeof srchn / sizeof *srchn; 123 124