mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-24 15:04:13 +00:00
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
159 lines
5.5 KiB
C
159 lines
5.5 KiB
C
/***********************************************************************
|
|
* *
|
|
* This software is part of the ast package *
|
|
* Copyright (c) 1982-2011 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 NOTSYM
|
|
/*
|
|
* UNIX shell
|
|
* Written by David Korn
|
|
* These are the definitions for the lexical analyzer
|
|
*/
|
|
|
|
#include <cdt.h>
|
|
#include "FEATURE/options"
|
|
#include "shnodes.h"
|
|
#include "shtable.h"
|
|
#include "lexstates.h"
|
|
|
|
|
|
typedef struct _shlex_
|
|
{
|
|
Shell_t *sh; /* pointer to the interpreter */
|
|
struct argnod *arg; /* current word */
|
|
struct ionod *heredoc; /* pending here document list */
|
|
int token; /* current token number */
|
|
int lastline; /* last line number */
|
|
int lasttok; /* previous token number */
|
|
int digits; /* numerical value with word token */
|
|
char aliasok; /* on when alias is legal */
|
|
char assignok; /* on when name=value is legal */
|
|
char inexec; /* on when processing exec */
|
|
char intypeset; /* on when processing typeset */
|
|
char comp_assign; /* in compound assignment */
|
|
char comsub; /* parsing command substitution */
|
|
char noreserv; /* reserved works not legal */
|
|
int inlineno; /* saved value of sh.inlineno */
|
|
int firstline; /* saved value of sh.st.firstline */
|
|
#if SHOPT_KIA
|
|
Sfio_t *kiafile; /* kia output file */
|
|
Sfio_t *kiatmp; /* kia reference file */
|
|
unsigned long script; /* script entity number */
|
|
unsigned long fscript; /* script file entity number */
|
|
unsigned long current; /* current entity number */
|
|
unsigned long unknown; /* <unknown> entity number */
|
|
off_t kiabegin; /* offset of first entry */
|
|
char *scriptname; /* name of script file */
|
|
Dt_t *entity_tree; /* for entity ids */
|
|
#endif /* SHOPT_KIA */
|
|
#ifdef _SHLEX_PRIVATE
|
|
_SHLEX_PRIVATE
|
|
#endif
|
|
} Lex_t;
|
|
|
|
/* symbols for parsing */
|
|
#define NL '\n'
|
|
#define NOTSYM '!'
|
|
#define SYMRES 0400 /* reserved word symbols */
|
|
#define DOSYM (SYMRES|01)
|
|
#define FISYM (SYMRES|02)
|
|
#define ELIFSYM (SYMRES|03)
|
|
#define ELSESYM (SYMRES|04)
|
|
#define INSYM (SYMRES|05)
|
|
#define THENSYM (SYMRES|06)
|
|
#define DONESYM (SYMRES|07)
|
|
#define ESACSYM (SYMRES|010)
|
|
#define IFSYM (SYMRES|011)
|
|
#define FORSYM (SYMRES|012)
|
|
#define WHILESYM (SYMRES|013)
|
|
#define UNTILSYM (SYMRES|014)
|
|
#define CASESYM (SYMRES|015)
|
|
#define FUNCTSYM (SYMRES|016)
|
|
#define SELECTSYM (SYMRES|017)
|
|
#define TIMESYM (SYMRES|020)
|
|
#define NSPACESYM (SYMRES|021)
|
|
|
|
#define SYMREP 01000 /* symbols for doubled characters */
|
|
#define BREAKCASESYM (SYMREP|';')
|
|
#define ANDFSYM (SYMREP|'&')
|
|
#define ORFSYM (SYMREP|'|')
|
|
#define IOAPPSYM (SYMREP|'>')
|
|
#define IODOCSYM (SYMREP|'<')
|
|
#define EXPRSYM (SYMREP|'(')
|
|
#define BTESTSYM (SYMREP|'[')
|
|
#define ETESTSYM (SYMREP|']')
|
|
|
|
#define SYMMASK 0170000
|
|
#define SYMPIPE 010000 /* trailing '|' */
|
|
#define SYMLPAR 020000 /* trailing LPAREN */
|
|
#define SYMAMP 040000 /* trailing '&' */
|
|
#define SYMGT 0100000 /* trailing '>' */
|
|
#define SYMSEMI 0110000 /* trailing ';' */
|
|
#define SYMSHARP 0120000 /* trailing '#' */
|
|
#define IOSEEKSYM (SYMSHARP|'<')
|
|
#define IOMOV0SYM (SYMAMP|'<')
|
|
#define IOMOV1SYM (SYMAMP|'>')
|
|
#define FALLTHRUSYM (SYMAMP|';')
|
|
#define COOPSYM (SYMAMP|'|')
|
|
#define IORDWRSYM (SYMGT|'<')
|
|
#define IORDWRSYMT (SYMSEMI|'<')
|
|
#define IOCLOBSYM (SYMPIPE|'>')
|
|
#define PIPESYM2 (SYMPIPE|'&')
|
|
#define IPROCSYM (SYMLPAR|'<')
|
|
#define OPROCSYM (SYMLPAR|'>')
|
|
#define EOFSYM 04000 /* end-of-file */
|
|
#define TESTUNOP 04001
|
|
#define TESTBINOP 04002
|
|
#define LABLSYM 04003
|
|
#define IOVNAME 04004
|
|
|
|
/* additional parser flag, others in <shell.h> */
|
|
#define SH_EMPTY 04
|
|
#define SH_NOIO 010
|
|
#define SH_ASSIGN 020
|
|
#define SH_FUNDEF 040
|
|
#define SH_ARRAY 0100
|
|
#define SH_SEMI 0200 /* semi-colon after NL ok */
|
|
|
|
#define SH_COMPASSIGN 010 /* allow compound assignments only */
|
|
|
|
extern const char e_unexpected[];
|
|
extern const char e_unmatched[];
|
|
extern const char e_endoffile[];
|
|
extern const char e_newline[];
|
|
|
|
/* odd chars */
|
|
#define LBRACE '{'
|
|
#define RBRACE '}'
|
|
#define LPAREN '('
|
|
#define RPAREN ')'
|
|
#define LBRACT '['
|
|
#define RBRACT ']'
|
|
|
|
extern int sh_lex(Lex_t*);
|
|
extern Shnode_t *sh_dolparen(Lex_t*);
|
|
extern Lex_t *sh_lexopen(Lex_t*, Shell_t*, int);
|
|
extern void sh_lexskip(Lex_t*,int,int,int);
|
|
extern void sh_syntax(Lex_t*);
|
|
#if SHOPT_KIA
|
|
extern int kiaclose(Lex_t *);
|
|
extern unsigned long kiaentity(Lex_t*, const char*,int,int,int,int,unsigned long,int,int,const char*);
|
|
#endif /* SHOPT_KIA */
|
|
|
|
|
|
#endif /* !NOTSYM */
|