1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-24 23:14:14 +00:00
cde/src/cmd/ksh93/include/io.h
Martijn Dekker 921bbcaeb7 Remove SHOPT_BASH; keep &> redir operator, '-o posix' option
On 16 June there was a call for volunteers to fix the bash
compatibility mode; it has never successfully compiled in 93u+.
Since no one showed up, it is now removed due to lack of interest.

A couple of things are kept, which are now globally enabled:

1. The &>file redirection shorthand (for >file 2>&1). As a matter
   of fact, ksh93 already supported this natively, but only while
   running rc/profile/login scripts, and it issued a warning. This
   makse it globally available and removes the warning, bringing
   ksh93 in line with mksh, bash and zsh.

2. The '-o posix' standard compliance option. It is now enabled on
   startup if ksh is invoked as 'sh' or if the POSIXLY_CORRECT
   variable exists in the environment. To begin with, it disables
   the aforementioned &> redirection shorthand. Further compliance
   tweaks will be added in subsequent commits. The differences will
   be fairly minimal as ksh93 is mostly compliant already.

In all changed files, code was removed that was compiled (more
precisely, failed to compile/link) if the SHOPT_BASH preprocessor
identifier was defined. Below are other changes worth mentioning:

src/cmd/ksh93/sh/bash.c,
src/cmd/ksh93/data/bash_pre_rc.sh:
- Removed.

src/cmd/ksh93/data/lexstates.c,
src/cmd/ksh93/include/shlex.h,
src/cmd/ksh93/sh/lex.c:
- Globally enable &> redirection operator if SH_POSIX not active.
- Remove warning that was issued when &> was used in rc scripts.

src/cmd/ksh93/data/options.c,
src/cmd/ksh93/include/defs.h,
src/cmd/ksh93/sh/args.c:
- Keep SH_POSIX option (-o posix).
- Replace SH_TYPE_BASH shell type by SH_TYPE_POSIX.

src/cmd/ksh93/sh/init.c:
- sh_type(): Return SH_TYPE_POSIX shell type if ksh was invoked
  as sh (or rsh, restricted sh).
- sh_init(): Enable posix option if the SH_TYPE_POSIX shell type
  was detected, or if the CONFORMANCE ast config variable was set
  to "standard" (which libast sets on init if POSIXLY_CORRECT
  exists in the environment).

src/cmd/ksh93/tests/options.sh,
src/cmd/ksh93/tests/io.sh:
- Replace regression tests for &> and move to io.sh. Since &> is
  now for general use, no longer test in an rc script, and don't
  check that a warning is issued.

Closes: #9
Progresses: #20
2020-09-01 06:19:19 +01:00

120 lines
3.9 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
/*
* UNIX shell
* David Korn
*
*/
#include <ast.h>
#include <sfio.h>
#ifndef IOBSIZE
# define IOBSIZE (SF_BUFSIZE*sizeof(char*))
#endif /* IOBSIZE */
#define IOMAXTRY 20
#ifndef SF_CLOSING
#define SF_CLOSING SF_CLOSE
#endif
#ifndef SF_APPENDWR
#define SF_APPENDWR SF_APPEND
#endif
/* used for output of shell errors */
#define ERRIO 2
#define IOREAD 001
#define IOWRITE 002
#define IODUP 004
#define IOSEEK 010
#define IONOSEEK 020
#define IOTTY 040
#define IOCLEX 0100
#define IOCLOSE (IOSEEK|IONOSEEK)
#define IOSUBSHELL 0x8000 /* must be larger than any file descriptor */
#define IOPICKFD 0x10000 /* file descriptor number was selected automatically */
#define IOHERESTRING 0x20000 /* allow here documents to be string streams */
/*
* The remainder of this file is only used when compiled with shell
*/
#if KSHELL
#ifndef ARG_RAW
struct ionod;
#endif /* !ARG_RAW */
extern int sh_iocheckfd(Shell_t*,int);
extern void sh_ioinit(Shell_t*);
extern int sh_iomovefd(int);
extern int sh_iorenumber(Shell_t*,int,int);
extern void sh_pclose(int[]);
extern int sh_rpipe(int[]);
extern void sh_iorestore(Shell_t*,int,int);
#if defined(__EXPORT__) && defined(_BLD_DLL) && defined(_BLD_shell)
__EXPORT__
#endif
extern Sfio_t *sh_iostream(Shell_t*,int);
extern int sh_redirect(Shell_t*,struct ionod*,int);
extern void sh_iosave(Shell_t *, int,int,char*);
extern int sh_iovalidfd(Shell_t*, int);
extern int sh_inuse(Shell_t*, int);
extern void sh_iounsave(Shell_t*);
extern int sh_chkopen(const char*);
extern int sh_ioaccess(int,int);
extern int sh_devtofd(const char*);
extern int sh_isdevfd(const char*);
extern int sh_source(Shell_t*, Sfio_t*, const char*);
/* the following are readonly */
extern const char e_pexists[];
extern const char e_query[];
extern const char e_history[];
extern const char e_argtype[];
extern const char e_create[];
extern const char e_tmpcreate[];
extern const char e_exists[];
extern const char e_file[];
extern const char e_redirect[];
extern const char e_formspec[];
extern const char e_badregexp[];
extern const char e_open[];
extern const char e_notseek[];
extern const char e_noread[];
extern const char e_badseek[];
extern const char e_badwrite[];
extern const char e_badpattern[];
extern const char e_toomany[];
extern const char e_pipe[];
extern const char e_unknown[];
extern const char e_devnull[];
extern const char e_profile[];
extern const char e_sysprofile[];
#if SHOPT_SYSRC
extern const char e_sysrc[];
#endif
extern const char e_stdprompt[];
extern const char e_supprompt[];
extern const char e_ambiguous[];
#endif /* KSHELL */