Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtksh / builtins.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: builtins.c /main/3 1995/11/01 15:50:47 rswiston $ */
24 /***************************************************************
25 *                                                              *
26 *                      AT&T - PROPRIETARY                      *
27 *                                                              *
28 *        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF        *
29 *                    AT&T BELL LABORATORIES                    *
30 *         AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN         *
31 *            ACCORDANCE WITH APPLICABLE AGREEMENTS             *
32 *                                                              *
33 *          Copyright (c) 1994 AT&T Bell Laboratories           *
34 *              Unpublished & Not for Publication               *
35 *                     All Rights Reserved                      *
36 *                                                              *
37 *       The copyright notice above does not evidence any       *
38 *      actual or intended publication of such source code      *
39 *                                                              *
40 *               This software was created by the               *
41 *           Advanced Software Technology Department            *
42 *                    AT&T Bell Laboratories                    *
43 *                                                              *
44 *               For further information contact                *
45 *                    {research,attmail}!dgk                    *
46 *                     dgk@research.att.com                     *
47 *                   David Korn 908-582-7975                    *
48 *                                                              *
49 ***************************************************************/
50
51 /* : : generated by proto : : */
52
53 #line 1
54
55 #if !defined(__PROTO__)
56 #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
57 #if defined(__cplusplus)
58 #define __MANGLE__      "C"
59 #else
60 #define __MANGLE__
61 #endif
62 #define __STDARG__
63 #define __PROTO__(x)    x
64 #define __OTORP__(x)
65 #define __PARAM__(n,o)  n
66 #if !defined(__STDC__) && !defined(__cplusplus)
67 #if !defined(c_plusplus)
68 #define const
69 #endif
70 #define signed
71 #define void            int
72 #define volatile
73 #define __V_            char
74 #else
75 #define __V_            void
76 #endif
77 #else
78 #define __PROTO__(x)    ()
79 #define __OTORP__(x)    x
80 #define __PARAM__(n,o)  o
81 #define __MANGLE__
82 #define __V_            char
83 #define const
84 #define signed
85 #define void            int
86 #define volatile
87 #endif
88 #if defined(__cplusplus) || defined(c_plusplus)
89 #define __VARARG__      ...
90 #else
91 #define __VARARG__
92 #endif
93 #if defined(__STDARG__)
94 #define __VA_START__(p,a)       va_start(p,a)
95 #else
96 #define __VA_START__(p,a)       va_start(p)
97 #endif
98 #endif
99
100 #line 3
101 #define mount   _AST_mount
102 #include        <shell.h>
103 #include        <signal.h>
104 #include        "shtable.h"
105 #include        "name.h"
106 #ifdef KSHELL
107 #   include     "builtins.h"
108 #   include     "jobs.h"
109 #   include     "FEATURE/cmds"
110 #if defined(__STDC__) || defined(__STDPP__)
111 #   define      bltin(x)        (b_##x)
112 #else
113 #   define      bltin(x)        (b_/**/x)
114 #endif
115
116 #line 13
117 #else
118 #   define bltin(x)     0
119 #endif
120
121 #include <X11/X.h>
122 #include <X11/Intrinsic.h>
123 #include <X11/IntrinsicP.h>
124 #define NO_AST
125 #include "dtksh.h"
126 #undef NO_AST
127 #include "dtextra.h"
128 #include "xmextra.h"
129 #include "msgs.h"
130
131
132 /*
133  * The order up through "[" is significant
134  */
135 const struct shtable3 shtab_builtins[] =
136 {
137         "login",        NV_BLTIN|BLT_ENV|BLT_SPC,       bltin(login),
138         "exec",         NV_BLTIN|BLT_ENV|BLT_SPC,       bltin(exec),
139         "set",          NV_BLTIN|BLT_ENV|BLT_SPC,       bltin(set),     
140         ":",            NV_BLTIN|BLT_ENV|BLT_SPC,       bltin(true),
141         "true",         NV_BLTIN|BLT_ENV,               bltin(true),
142         "command",      NV_BLTIN|BLT_ENV|BLT_EXIT,      bltin(command),
143         "cd",           NV_BLTIN|BLT_ENV,               bltin(cd),
144         "break",        NV_BLTIN|BLT_ENV|BLT_SPC,       bltin(brk_cont),
145         "continue",     NV_BLTIN|BLT_ENV|BLT_SPC,       bltin(brk_cont),
146         "typeset",      NV_BLTIN|BLT_ENV|BLT_SPC|BLT_DCL,bltin(typeset),
147         "test",         NV_BLTIN|BLT_ENV|NV_NOFREE,     bltin(test),
148         "[",            NV_BLTIN|BLT_ENV,               bltin(test),
149 #ifdef _bin_newgrp
150         "newgrp",       NV_BLTIN|BLT_ENV|BLT_SPC,       bltin(login),
151 #endif  /* _bin_newgrp */
152         ".",            NV_BLTIN|BLT_ENV|BLT_SPC,       bltin(dot_cmd),
153         "alias",        NV_BLTIN|BLT_SPC|BLT_DCL,       bltin(alias),
154         "hash",         NV_BLTIN|BLT_SPC|BLT_DCL,       bltin(alias),
155         "exit",         NV_BLTIN|BLT_ENV|BLT_SPC,       bltin(ret_exit),
156         "export",       NV_BLTIN|BLT_SPC|BLT_DCL,       bltin(read_export),
157         "eval",         NV_BLTIN|BLT_ENV|BLT_SPC|BLT_EXIT,bltin(eval),
158         "fc",           NV_BLTIN|BLT_ENV|BLT_EXIT,      bltin(hist),
159         "hist",         NV_BLTIN|BLT_ENV|BLT_EXIT,      bltin(hist),
160         "readonly",     NV_BLTIN|BLT_ENV|BLT_SPC|BLT_DCL,bltin(read_export),
161         "return",       NV_BLTIN|BLT_ENV|BLT_SPC,       bltin(ret_exit),
162         "shift",        NV_BLTIN|BLT_ENV|BLT_SPC,       bltin(shift),
163         "trap",         NV_BLTIN|BLT_ENV|BLT_SPC,       bltin(trap),
164         "unalias",      NV_BLTIN|BLT_ENV|BLT_SPC,       bltin(unalias),
165         "unset",        NV_BLTIN|BLT_ENV|BLT_SPC,       bltin(unset),
166         "builtin",      NV_BLTIN,                       bltin(builtin),
167 #ifdef SHOPT_ECHOPRINT
168         "echo",         NV_BLTIN|BLT_ENV,               bltin(print),
169 #else
170         "echo",         NV_BLTIN|BLT_ENV,               bltin(echo),
171 #endif /* SHOPT_ECHOPRINT */
172 #ifdef JOBS
173 #   ifdef SIGTSTP
174         "bg",           NV_BLTIN|BLT_ENV,               bltin(bg_fg),
175         "fg",           NV_BLTIN|BLT_ENV|BLT_EXIT,      bltin(bg_fg),
176         "disown",       NV_BLTIN|BLT_ENV,               bltin(bg_fg),
177         "kill",         NV_BLTIN|BLT_ENV|NV_NOFREE,     bltin(kill),
178 #   else
179         "/bin/kill",    NV_BLTIN|BLT_ENV|NV_NOFREE,     bltin(kill),
180 #   endif       /* SIGTSTP */
181         "jobs",         NV_BLTIN|BLT_ENV,               bltin(jobs),
182 #endif  /* JOBS */
183         "false",        NV_BLTIN|BLT_ENV,               bltin(false),
184         "getconf",      NV_BLTIN|BLT_ENV,               bltin(getconf),
185         "getopts",      NV_BLTIN|BLT_ENV,               bltin(getopts),
186         "let",          NV_BLTIN|BLT_ENV,               bltin(let),
187         "print",        NV_BLTIN|BLT_ENV,               bltin(print),
188         "printf",       NV_BLTIN|NV_NOFREE,             bltin(printf),
189         "pwd",          NV_BLTIN|NV_NOFREE,             bltin(pwd),
190         "read",         NV_BLTIN|BLT_ENV,               bltin(read),
191         "sleep",        NV_BLTIN|NV_NOFREE,             bltin(sleep),
192         "alarm",        NV_BLTIN,                       bltin(alarm),
193         "ulimit",       NV_BLTIN|BLT_ENV,               bltin(ulimit),
194         "umask",        NV_BLTIN|BLT_ENV,               bltin(umask),
195 #ifdef _cmd_universe
196         "universe",     NV_BLTIN|BLT_ENV,               bltin(universe),
197 #endif /* _cmd_universe */
198 #ifdef SHOPT_FS_3D
199         "vpath",        NV_BLTIN|BLT_ENV,               bltin(vpath_map),
200         "vmap",         NV_BLTIN|BLT_ENV,               bltin(vpath_map),
201 #endif /* SHOPT_FS_3D */
202         "wait",         NV_BLTIN|BLT_ENV|BLT_EXIT,      bltin(wait),
203         "type",         NV_BLTIN|BLT_ENV,               bltin(whence),
204         "whence",       NV_BLTIN|BLT_ENV,               bltin(whence),
205 #ifdef apollo
206         "inlib",        NV_BLTIN|BLT_ENV,               bltin(inlib),
207         "rootnode",     NV_BLTIN,                       bltin(rootnode),
208         "ver",          NV_BLTIN,                       bltin(ver),
209 #endif  /* apollo */
210         "/bin/basename",NV_BLTIN|NV_NOFREE,             bltin(basename),
211         "/bin/chmod",   NV_BLTIN|NV_NOFREE,             bltin(chmod),
212         "/bin/dirname", NV_BLTIN|NV_NOFREE,             bltin(dirname),
213         "/bin/head",    NV_BLTIN|NV_NOFREE,             bltin(head),
214         "/bin/mkdir",   NV_BLTIN|NV_NOFREE,             bltin(mkdir),
215 #if defined(_usr_bin_logname)  && !defined(_bin_logname)
216         "/usr/bin/logname",     NV_BLTIN|NV_NOFREE,     bltin(logname),
217 #else
218         "/bin/logname", NV_BLTIN|NV_NOFREE,             bltin(logname),
219 #endif
220         "/bin/cat",     NV_BLTIN|NV_NOFREE,             bltin(cat),
221         "/bin/cmp",     NV_BLTIN|NV_NOFREE,             bltin(cmp),
222 #if defined(_usr_bin_cut)  && !defined(_bin_cut)
223         "/usr/bin/cut", NV_BLTIN|NV_NOFREE,             bltin(cut),
224 #else
225         "/bin/cut",     NV_BLTIN|NV_NOFREE,             bltin(cut),
226 #endif
227         "/bin/uname",   NV_BLTIN|NV_NOFREE,             bltin(uname),
228 #if defined(_usr_bin_wc)  && !defined(_bin_wc)
229         "/usr/bin/wc",  NV_BLTIN|NV_NOFREE,             bltin(wc),
230 #else
231 #   if defined(_usr_ucb_wc)  && !defined(_bin_wc)
232         "/usr/ucb/wc",  NV_BLTIN|NV_NOFREE,             bltin(wc),
233 #   else
234         "/bin/wc",      NV_BLTIN|NV_NOFREE,             bltin(wc),
235 #   endif
236 #endif
237 DTK_EXTRA_TABLE
238 DTK_EXTRA_TABLE2
239 DTK_TK_EXTRA_TABLE
240 DTK_TK_LIST_TABLE
241 DTK_TK_TEXT_TABLE
242         "",             0, 0 
243 };
244
245 const char sh_optalarm[]        = "r [varname seconds]";
246 const char sh_optalias[]        = "ptx [name=[value]...]";
247 const char sh_optbuiltin[]      = "dsf:[library] [name...]";
248 const char sh_optcd[]           = "LP [dir] [change]";
249 const char sh_optcflow[]        = " [n]";
250 const char sh_optcommand[]      = "pvV name [arg]...";
251 const char sh_optdot[]          = " name [arg...]";
252 #ifndef ECHOPRINT
253     const char sh_optecho[]     = " [-n] [arg...]";
254 #endif /* !ECHOPRINT */
255 const char sh_opteval[]         = " [arg...]";
256 const char sh_optexec[]         = "a:[name]c [command [args...] ]";
257 const char sh_optexport[]       = "p [name[=value]...]";
258 const char sh_optgetopts[]      = ":a:[name] optstring name [args...]";
259 const char sh_optgetconf[]      = " [name [pathname] ]";
260 const char sh_optjoblist[]      = " [job...]";
261 const char sh_opthist[]         = "e:[editor]lnrsN# [first] [last]";
262 const char sh_optjobs[]         = "nlp [job...]";
263 const char sh_optkill[]         = "ln#[signum]s:[signame] sig...";
264 const char sh_optlet[]          = " expr...";
265 const char sh_optprint[]        = "f:[format]enprsu:[filenum] [arg...]";
266 const char sh_optprintf[]       = " format [arg...]";
267 const char sh_optpwd[]          = "LP";
268 const char sh_optread[]         = "Ad:[delim]prst#[timeout]u#[filenum] [name...]";
269 #ifdef SHOPT_KIA
270     const char sh_optksh[]            = "+DircabefhkmnpstuvxCR:[file]o:?[option] [arg...]";
271     const char sh_optset[]            = "+abefhkmnpstuvxCR:[file]o:?[option]A:[name] [arg...]";
272 #else
273     const char sh_optksh[]            = "+DircabefhkmnpstuvxCo:?[option] [arg...]";
274     const char sh_optset[]            = "+abefhkmnpstuvxCo:?[option]A:[name] [arg...]";
275 #endif /* SHOPT_KIA */
276 const char sh_optsleep[]        = " seconds";
277 const char sh_opttrap[]         = "p [action condition...]";
278 #ifdef SHOPT_OO
279     const char sh_opttypeset[]        = "+AC:E#?F#?H:[name]L#?R#?Z#?fi#?[base]lnprtux [name=[value]...]";
280 #else
281     const char sh_opttypeset[]        = "+AE#?F#?HL#?R#?Z#?fi#?[base]lnprtux [name=[value]...]";
282 #endif /* SHOPT_OO */
283 const char sh_optulimit[]       = "HSacdfmnstv [limit]";
284 const char sh_optumask[]        = "S [mask]";
285 const char sh_optuniverse[]     = " [name]";
286 const char sh_optunset[]        = "fnv name...";
287 const char sh_optunalias[]      = "a name...";
288 #ifdef SHOPT_FS_3D
289     const char sh_optvpath[]    = " [top] [base]";
290     const char sh_optvmap[]     = " [dir] [list]";
291 #endif /* SHOPT_FS_3D */
292 const char sh_optwhence[]       = "afpv name...";
293
294
295
296 const char e_alrm1[]            = "alarm -r %s +%.3g\n";
297 const char e_alrm2[]            = "alarm %s %.3f\n";
298 const char e_badfun[]           = "%s: illegal function name";
299 const char e_baddisc[]          = "%s: invalid discipline function";
300 const char e_nospace[]          = "out of memory";
301 const char e_nofork[]           = "cannot fork";
302 const char e_nosignal[]         = "%s: unknown signal name";
303 const char e_numeric[]          = "*([0-9])?(.)*([0-9])";
304 const char e_condition[]        = "condition(s) required";
305 const char e_cneedsarg[]        = "-c requires argument";