mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
This fixes the following:
1. 'set --posix' now works as an equivalent of 'set -o posix'.
2. The posix option turns off braceexpand and turns on letoctal.
Any attempt to override that in a single command such as 'set -o
posix +o letoctal' was quietly ignored. This now works as long
as the overriding option follows the posix option in the command.
3. The --default option to 'set' now stops the 'posix' option, if
set or unset in the same 'set' command, from changing other
options. This allows the command output by 'set +o' to correctly
restore the current options.
src/cmd/ksh93/data/builtins.c:
- To make 'set --posix' work, we must explicitly list it in
sh_set[] as a supported option so that AST optget(3) recognises
it and won't override it with its own default --posix option,
which converts the optget(3) string to at POSIX getopt(3) string.
This means it will appear as a separate entry in --man output,
whether we want it to or not. So we might as well use it as an
example to document how --optionname == -o optionname, replacing
the original documentation that was part of the '-o' description.
src/cmd/ksh93/sh/args.c: sh_argopts():
- Add handling for explitit --posix option in data/builtins.c.
- Move SH_POSIX syncing SH_BRACEEXPAND and SH_LETOCTAL from
sh_applyopts() into the option parsing loop here. This fixes
the bug that letoctal was ignored in 'set -o posix +o letoctal'.
- Remember if --default was used in a flag, and do not sync options
with SH_POSIX if the flag is set. This makes 'set +o' work.
src/cmd/ksh93/include/argnod.h,
src/cmd/ksh93/data/msg.c,
src/cmd/ksh93/sh/args.c: sh_printopts():
- Do not potentially translate the 'on' and 'off' labels in 'set
-o' output. No other shell does, and some scripts parse these.
src/cmd/ksh93/sh/init.c: sh_init():
- Turn on SH_LETOCTAL early along with SH_POSIX if the shell was
invoked as sh; this makes 'sh -o' and 'sh +o' show expected
options (not that anyone does this, but correctness is good).
src/cmd/ksh93/include/defs.h,
src/cmd/ksh93/include/shell.h:
- The state flags were in defs.h and most (but not all) of the
shell options were in shell.h. Gather all the shell state and
option flag definitions into one place in shell.h for clarity.
- Remove unused SH_NOPROFILE and SH_XARGS option flags.
src/cmd/ksh93/tests/options.sh:
- Add tests for these bugs.
src/lib/libast/misc/optget.c: styles[]:
- Edit default optget(3) option self-documentation for clarity.
Several changed files:
- Some SHOPT_PFSH fixes to avoid compiling dead code.
150 lines
5.2 KiB
C
150 lines
5.2 KiB
C
/***********************************************************************
|
|
* *
|
|
* This software is part of the ast package *
|
|
* Copyright (c) 1982-2012 AT&T Intellectual Property *
|
|
* and is licensed under the *
|
|
* Eclipse Public License, Version 1.0 *
|
|
* by AT&T Intellectual Property *
|
|
* *
|
|
* A copy of the License is available at *
|
|
* http://www.eclipse.org/org/documents/epl-v10.html *
|
|
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
|
|
* *
|
|
* Information and Software Systems Research *
|
|
* AT&T Research *
|
|
* Florham Park NJ *
|
|
* *
|
|
* David Korn <dgk@research.att.com> *
|
|
* *
|
|
***********************************************************************/
|
|
#pragma prototyped
|
|
#ifndef PATH_OFFSET
|
|
|
|
/*
|
|
* UNIX shell path handling interface
|
|
* Written by David Korn
|
|
* These are the definitions for the lexical analyzer
|
|
*/
|
|
|
|
#include "FEATURE/options"
|
|
#include <nval.h>
|
|
#include "defs.h"
|
|
|
|
#if !defined(SHOPT_SPAWN)
|
|
# if _UWIN || _use_spawnveg || !_lib_fork
|
|
# define SHOPT_SPAWN 1
|
|
# endif
|
|
#endif /* !SHOPT_SPAWN */
|
|
|
|
#define PATH_PATH 0001
|
|
#define PATH_FPATH 0002
|
|
#define PATH_CDPATH 0004
|
|
#define PATH_BFPATH 0010
|
|
#define PATH_SKIP 0020
|
|
#define PATH_BUILTIN_LIB 0040
|
|
#define PATH_STD_DIR 0100 /* directory is on $(getconf PATH) */
|
|
|
|
#define PATH_OFFSET 2 /* path offset for path_join */
|
|
#define MAXDEPTH (sizeof(char*)==2?64:1024) /* maximum recursion depth*/
|
|
|
|
/*
|
|
* path component structure for path searching
|
|
*/
|
|
typedef struct pathcomp
|
|
{
|
|
struct pathcomp *next;
|
|
int refcount;
|
|
dev_t dev;
|
|
ino_t ino;
|
|
time_t mtime;
|
|
char *name;
|
|
char *lib;
|
|
char *bbuf;
|
|
char *blib;
|
|
unsigned short len;
|
|
unsigned short flags;
|
|
Shell_t *shp;
|
|
} Pathcomp_t;
|
|
|
|
#ifndef ARG_RAW
|
|
struct argnod;
|
|
#endif /* !ARG_RAW */
|
|
|
|
/* pathname handling routines */
|
|
extern void path_newdir(Shell_t*,Pathcomp_t*);
|
|
extern Pathcomp_t *path_dirfind(Pathcomp_t*,const char*,int);
|
|
extern Pathcomp_t *path_unsetfpath(Shell_t*);
|
|
extern Pathcomp_t *path_addpath(Shell_t*,Pathcomp_t*,const char*,int);
|
|
extern Pathcomp_t *path_dup(Pathcomp_t*);
|
|
extern void path_delete(Pathcomp_t*);
|
|
extern void path_alias(Namval_t*,Pathcomp_t*);
|
|
extern Pathcomp_t *path_absolute(Shell_t*, const char*, Pathcomp_t*, int);
|
|
extern char *path_basename(const char*);
|
|
extern char *path_fullname(Shell_t*,const char*);
|
|
extern int path_expand(Shell_t*,const char*, struct argnod**);
|
|
extern void path_exec(Shell_t*,const char*,char*[],struct argnod*);
|
|
extern pid_t path_spawn(Shell_t*,const char*,char*[],char*[],Pathcomp_t*,int);
|
|
#if defined(__EXPORT__) && defined(_BLD_DLL) && defined(_BLD_shell)
|
|
# define extern __EXPORT__
|
|
#endif
|
|
extern int path_open(Shell_t*,const char*,Pathcomp_t*);
|
|
extern Pathcomp_t *path_get(Shell_t*,const char*);
|
|
#undef extern
|
|
extern char *path_pwd(Shell_t*,int);
|
|
extern Pathcomp_t *path_nextcomp(Shell_t*,Pathcomp_t*,const char*,Pathcomp_t*);
|
|
extern int path_search(Shell_t*,const char*,Pathcomp_t**,int);
|
|
extern char *path_relative(Shell_t*,const char*);
|
|
extern int path_complete(Shell_t*,const char*, const char*,struct argnod**);
|
|
#if SHOPT_BRACEPAT
|
|
extern int path_generate(Shell_t*,struct argnod*,struct argnod**);
|
|
#endif /* SHOPT_BRACEPAT */
|
|
extern int path_xattr(Shell_t*, const char*, char*);
|
|
|
|
/* builtin/plugin routines */
|
|
extern int sh_addlib(Shell_t*,void*,char*,Pathcomp_t*);
|
|
extern Shbltin_f sh_getlib(Shell_t*,char*,Pathcomp_t*);
|
|
|
|
/* constant strings needed for whence */
|
|
extern const char e_timeformat[];
|
|
extern const char e_badtformat[];
|
|
extern const char e_dot[];
|
|
extern const char e_funload[];
|
|
#if SHOPT_PFSH
|
|
extern const char e_pfsh[];
|
|
#endif
|
|
extern const char e_pwd[];
|
|
extern const char e_logout[];
|
|
extern const char e_alphanum[];
|
|
extern const char e_mailmsg[];
|
|
extern const char e_suidprofile[];
|
|
extern const char e_sysprofile[];
|
|
extern const char e_traceprompt[];
|
|
#if SHOPT_SUID_EXEC
|
|
extern const char e_suidexec[];
|
|
#endif /* SHOPT_SUID_EXEC */
|
|
extern const char is_alias[];
|
|
extern const char is_builtin[];
|
|
extern const char is_spcbuiltin[];
|
|
extern const char is_builtver[];
|
|
extern const char is_reserved[];
|
|
extern const char is_talias[];
|
|
extern const char is_function[];
|
|
extern const char is_ufunction[];
|
|
extern const char e_autoloadfrom[];
|
|
#ifdef SHELLMAGIC
|
|
extern const char e_prohibited[];
|
|
#endif /* SHELLMAGIC */
|
|
|
|
#if SHOPT_ACCT
|
|
# include "FEATURE/acct"
|
|
# ifdef _sys_acct
|
|
extern void sh_accinit(void);
|
|
extern void sh_accbegin(const char*);
|
|
extern void sh_accend(void);
|
|
extern void sh_accsusp(void);
|
|
# else
|
|
# undef SHOPT_ACCT
|
|
# endif /* _sys_acct */
|
|
#endif /* SHOPT_ACCT */
|
|
|
|
#endif /*! PATH_OFFSET */
|