2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: misc.c /main/3 1995/11/01 16:28:50 rswiston $ */
24 /***************************************************************
26 * AT&T - PROPRIETARY *
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 *
33 * Copyright (c) 1995 AT&T Corp. *
34 * Unpublished & Not for Publication *
35 * All Rights Reserved *
37 * The copyright notice above does not evidence any *
38 * actual or intended publication of such source code *
40 * This software was created by the *
41 * Advanced Software Technology Department *
42 * AT&T Bell Laboratories *
44 * For further information contact *
45 * {research,attmail}!dgk *
47 ***************************************************************/
49 /* : : generated by proto : : */
51 #if !defined(__PROTO__)
52 #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
53 #if defined(__cplusplus)
54 #define __MANGLE__ "C"
59 #define __PROTO__(x) x
61 #define __PARAM__(n,o) n
62 #if !defined(__STDC__) && !defined(__cplusplus)
63 #if !defined(c_plusplus)
74 #define __PROTO__(x) ()
75 #define __OTORP__(x) x
76 #define __PARAM__(n,o) o
84 #if defined(__cplusplus) || defined(c_plusplus)
85 #define __VARARG__ ...
89 #if defined(__STDARG__)
90 #define __VA_START__(p,a) va_start(p,a)
92 #define __VA_START__(p,a) va_start(p)
96 #include "variables.h"
102 #include "builtins.h"
105 #define DOTMAX 32 /* maximum level of . nesting */
108 static void noexport __PROTO__((Namval_t*));
111 int b_exec __PARAM__((int argc,char *argv[], __V_ *extra), (argc, argv, extra)) __OTORP__(int argc;char *argv[]; __V_ *extra;){
116 while (n = optget(argv, sh_optexec)) switch (n)
129 error(ERROR_usage(0), opt_arg);
133 if(error_info.errors)
134 error(ERROR_usage(2),optusage((char*)0));
136 b_login(argc,argv,0);
140 static void noexport __PARAM__((register Namval_t* np), (np)) __OTORP__(register Namval_t* np;){
141 nv_offattr(np,NV_EXPORT);
144 int b_login __PARAM__((int argc,char *argv[],__V_ *extra), (argc, argv, extra)) __OTORP__(int argc;char *argv[];__V_ *extra;){
146 struct checkpt *pp = (struct checkpt*)sh.jmplist;
148 if(sh_isoption(SH_RESTRICTED))
149 error(ERROR_exit(1),e_restricted,argv[0]);
152 register struct argnod *arg=sh.envlist;
153 register Namval_t* np;
158 nv_scan(sh.var_tree,noexport,NV_EXPORT,NV_EXPORT);
161 if((cp=strchr(arg->argval,'=')) &&
162 (*cp=0,np=nv_search(arg->argval,sh.var_tree,0)))
163 nv_onattr(np,NV_EXPORT);
175 /* force bad exec to terminate shell */
176 pp->mode = SH_JMPEXIT;
179 path_exec(pname,argv,NIL(struct argnod*));
185 int b_let __PARAM__((int argc,char *argv[],__V_ *extra), (argc, argv, extra)) __OTORP__(int argc;char *argv[];__V_ *extra;){
190 while (r = optget(argv,sh_optlet)) switch (r)
196 error(ERROR_usage(2), opt_arg);
200 if(error_info.errors || !*argv)
201 error(ERROR_usage(2),optusage((char*)0));
207 int b_eval __PARAM__((int argc,char *argv[], __V_ *extra), (argc, argv, extra)) __OTORP__(int argc;char *argv[]; __V_ *extra;){
211 while (r = optget(argv,sh_opteval)) switch (r)
217 error(ERROR_usage(0), opt_arg);
220 if(error_info.errors)
221 error(ERROR_usage(2),optusage((char*)0));
225 sh_offstate(SH_MONITOR);
226 sh_eval(sh_sfeval(argv),0);
231 int b_dot_cmd __PARAM__((register int n,char *argv[],__V_* extra), (n, argv, extra)) __OTORP__(register int n;char *argv[];__V_* extra;){
232 register char *script;
233 register Namval_t *np;
236 struct dolnod *argsave=0, *saveargfor;
241 while (n = optget(argv,sh_optdot)) switch (n)
247 error(ERROR_usage(0), opt_arg);
252 if(error_info.errors || !script)
253 error(ERROR_usage(2),optusage((char*)0));
254 if(!(np=sh.posix_fun))
256 /* check for KornShell style function first */
257 np = nv_search(script,sh.fun_tree,0);
258 if(np && is_afunction(np) && !nv_isattr(np,NV_FPOSIX))
262 path_search(script,NIL(char*),0);
265 if(nv_isattr(np,NV_FPOSIX))
269 error(ERROR_exit(1),e_found,script);
274 if(!np && (fd=path_open(script,path_get(script))) < 0)
275 error(ERROR_system(1),e_open,script);
278 if(sh.dot_depth++ > DOTMAX)
279 error(ERROR_exit(1),e_toodeep,script);
283 saveargv = sh.st.dolv;
284 argsave = sh_argnew(argv,&saveargfor);
286 sh_pushcontext(&buff,SH_JMPDOT);
287 jmpval = sigsetjmp(buff.buff,0);
291 sh_exec((union anynode*)(nv_funtree(np)),sh_isstate(SH_ERREXIT));
294 char buff[IOBSIZE+1];
295 iop = sfnew(NIL(Sfio_t*),buff,IOBSIZE,fd,SF_READ);
299 sh_popcontext(&buff);
301 if((np || argv[1]) && jmpval!=SH_JMPSCRIPT)
303 sh_argreset(argsave,saveargfor);
305 sh.st.dolv = saveargv;
307 if(sh.exitval > SH_EXITSIG)
308 sh_fault(sh.exitval&SH_EXITMASK);
309 if(jmpval && jmpval!=SH_JMPFUN)
310 siglongjmp(*sh.jmplist,jmpval);
317 int b_true __PARAM__((int argc,register char *argv[],__V_ *extra), (argc, argv, extra)) __OTORP__(int argc;register char *argv[];__V_ *extra;){
327 int b_false __PARAM__((int argc,register char *argv[], __V_ *extra), (argc, argv, extra)) __OTORP__(int argc;register char *argv[]; __V_ *extra;){
334 int b_shift __PARAM__((register int n, register char *argv[], __V_ *extra), (n, argv, extra)) __OTORP__(register int n; register char *argv[]; __V_ *extra;){
337 while((n = optget(argv,sh_optcflow))) switch(n)
343 error(ERROR_usage(0), opt_arg);
346 if(error_info.errors)
347 error(ERROR_usage(2),optusage((char*)0));
349 n = ((arg= *argv)?(int)sh_arith(arg):1);
350 if(n<0 || sh.st.dolc<n)
351 error(ERROR_exit(1),e_number,arg);
360 int b_wait __PARAM__((register int n,register char *argv[],__V_ *extra), (n, argv, extra)) __OTORP__(register int n;register char *argv[];__V_ *extra;){
362 while((n = optget(argv,sh_optjoblist))) switch(n)
368 error(ERROR_usage(2), opt_arg);
371 if(error_info.errors)
372 error(ERROR_usage(2),optusage((char*)0));
379 int b_bg_fg __PARAM__((register int n,register char *argv[],__V_ *extra), (n, argv, extra)) __OTORP__(register int n;register char *argv[];__V_ *extra;){
380 register int flag = **argv;
382 while((n = optget(argv,sh_optjoblist))) switch(n)
388 error(ERROR_usage(2), opt_arg);
391 if(error_info.errors)
392 error(ERROR_usage(2),optusage((char*)0));
394 if(!sh_isoption(SH_MONITOR) || !job.jobcontrol)
396 if(sh_isstate(SH_INTERACTIVE))
397 error(ERROR_exit(1),e_no_jctl);
400 if(flag=='d' && *argv==0)
402 if(job_walk(sfstdout,job_switch,flag,argv))
403 error(ERROR_exit(1),e_no_job);
407 int b_jobs __PARAM__((register int n,char *argv[],__V_ *extra), (n, argv, extra)) __OTORP__(register int n;char *argv[];__V_ *extra;){
408 register int flag = 0;
410 while((n = optget(argv,sh_optjobs))) switch(n)
425 error(ERROR_usage(2), opt_arg);
429 if(error_info.errors)
430 error(ERROR_usage(2),optusage((char*)0));
433 if(job_walk(sfstdout,job_list,flag,argv))
434 error(ERROR_exit(1),e_no_job);
442 * There are several universe styles that are masked by the getuniv(),
445 int b_universe __PARAM__((int argc, char *argv[],__V_ *extra), (argc, argv, extra)) __OTORP__(int argc; char *argv[];__V_ *extra;){
449 while((n = optget(argv,sh_optuniverse))) switch(n)
455 error(ERROR_usage(2), opt_arg);
460 if(error_info.errors || argc>1)
461 error(ERROR_usage(2),optusage((char*)0));
464 if(!astconf("_AST_UNIVERSE",0,arg))
465 error(ERROR_exit(1), e_badname,arg);
469 if(!(arg=astconf("_AST_UNIVERSE",0,0)))
470 error(ERROR_exit(1),e_nouniverse);
472 sfputr(sfstdout,arg,'\n');
476 #endif /* cmd_universe */
479 int b_vpath_map __PARAM__((register int argc,char *argv[], __V_ *extra), (argc, argv, extra)) __OTORP__(register int argc;char *argv[]; __V_ *extra;){
480 register int flag, n;
481 register const char *optstr;
486 optstr = sh_optvpath;
494 while(n = optget(argv, optstr)) switch(n)
500 error(ERROR_usage(2), opt_arg);
503 if(error_info.errors)
504 error(ERROR_usage(2),optusage((char*)0));
512 if((n = mount(*argv,(char*)0,flag,0)) >= 0)
514 vend = stakalloc(++n);
515 n = mount(*argv,vend,flag|FS3D_SIZE(n),0);
521 sfprintf(sfstdout,"%s\n",vend);
525 while(flag = *vend++)
529 flag = e_sptbnl[n+1];
532 sfputc(sfstdout,flag);
535 sfputc(sfstdout,'\n');
539 error(ERROR_usage(2),optusage((char*)0));
548 if(mount(argv[n+1],argv[n],flag,0)<0)
555 error(ERROR_exit(1),e_cantset,flag==2?e_mapping:e_versions);
557 error(ERROR_exit(1),e_cantget,flag==2?e_mapping:e_versions);
560 #endif /* SHOPT_FS_3D */