1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Another build system overhaul (re: 35672208, 580ff616, 6cc2f6a0)

So far we've been handling AST release build and git commit flags
and ksh SHOPT_* compile time options in the generic package build
script. That was a hack that was necessary before I had sufficient
understanding of the build system. Some of it did not work very
well, e.g. the correct git commit did not show up in ${.sh.version}
when compiling from a git repo.

As of this commit, this is properly included in the mamake
dependency tree by handling it from the libast and ksh93 Mamfiles,
guaranteeing they are properly up to date.

For a release build, the _AST_ksh_release macro is renamed to
_AST_release, because some aspects of libast also use this.

This commit also adds my first attempt at documenting the (very
simple, six-command) mamake language as it is currently implemented
-- which is significantly different from Glenn Fowler's original
paper. This is mostly based on reading the mamake.c source code.

src/cmd/INIT/README-mamake.md:
- Added.

bin/package, src/cmd/INIT/package.sh:
- Delete the hack.

**/Mamfile:
- Remove KSH_RELFLAGS and KSH_SHOPTFLAGS, which supported the hack.
- Delete 'meta' commands. They were no-ops; mamake.c ignores them.
  They also did not add any informative value.

src/lib/libast/Mamfile:
- Add a 'virtual' target that obtains the current git commit,
  examines the git branch, and decides whether to auto-set an
  _AST_git_commit and/or or _AST_release #define to a new
  releaseflags.h header file. This is overwritten on each run.
- Add code to the install target that copies limit.h to
  include/ast, but only if it doesn't exist or the content of the
  original changed. This allows '#include <releaseflags.h>' from
  any program using libast while avoiding needless recompiles.
- When there are uncommitted changes, add /MOD (modified) to the
  commit hash instead of not defining it at all.

src/cmd/ksh93/**:
- Mamfile: Add a shopt.h target that reads SHOPT.sh and converts it
  into a new shopt.h header file in the object code directory. The
  shopt.h header only contains SHOPT_* directives that have a value
  in SHOPT.sh (not the empty/probe ones). They also do not redefine
  the macros if they already exist, so overriding with something
  like CCFLAGS+=' -DSHOPT_FOO=1' remains possible.
- **.c: Every c file now #includes "shopt.h" first. So SHOPT_*
  macros are no longer passed via environment/MAM variables.
* SHOPT.sh: The AUDITFILE and CMDLIB_DIR macros no longer need an
  extra backslash-escape for the double quotes in their values.
  (The old way required this because mamake inserts MAM variables
  directly into shell scripts as literals without quoting.  :-/ )

src/cmd/INIT/mamake.c:
- Import the two minor changes between from 93u+ and 93v-: bind()
  is renamed to bindfile() and there is a tweak to detecting an
  "improper done statement".
- Allow arbitrary whitespace (isspace()) everywhere, instead of
  spaces only. This obsoletes my earlier indentation workaround
  from 6cc2f6a0; turns out mamake always supported indentation, but
  with spaces only.
- Do not skip line numbers at the beginning of each line. This
  undocumented feature is not and (AFAICT) never has been used.
- Throw an error on unknown command or rule attribute. Quite an
  important feature for manual maintenance: catches typos, etc.
This commit is contained in:
Martijn Dekker 2022-06-12 05:35:15 +01:00
parent ed5d561a72
commit 148a8a3f46
84 changed files with 1924 additions and 1896 deletions

File diff suppressed because it is too large Load diff

View file

@ -8,11 +8,11 @@
SHOPT ACCT=0 # accounting
SHOPT ACCTFILE=0 # per-user accounting info
SHOPT AUDIT=1 # enable auditing per SHOPT_AUDITFILE
SHOPT AUDITFILE='\"/etc/ksh_audit\"' # auditing file
SHOPT AUDITFILE='"/etc/ksh_audit"' # auditing file
SHOPT BGX=1 # one SIGCHLD trap per completed job
SHOPT BRACEPAT=1 # C-shell {...,...} expansions (, required)
SHOPT CMDLIB_HDR= # '<cmdlist.h>' # custom -lcmd list for path-bound builtins
SHOPT CMDLIB_DIR= # '\"/opt/ast/bin\"' # virtual directory prefix for path-bound builtins
SHOPT CMDLIB_DIR= # '"/opt/ast/bin"' # virtual directory prefix for path-bound builtins
SHOPT CRNL= # accept MS Windows newlines (<cr><nl>) for <nl>
SHOPT DEVFD= # use /dev/fd instead of FIFOs for process substitutions
SHOPT DYNAMIC=1 # dynamic loading for builtins

View file

@ -36,6 +36,7 @@
* > it is blocked and it should return and then handle the trap.
*/
#include "shopt.h"
#include "defs.h"
#include <error.h>
#include <stak.h>

View file

@ -29,6 +29,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include <stak.h>
#include <error.h>

View file

@ -30,6 +30,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include <ast.h>
#include <error.h>

View file

@ -18,6 +18,7 @@
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#include "shopt.h"
#include "defs.h"
#define ENUM_ID "enum (ksh 93u+m) 2022-03-05"

View file

@ -27,6 +27,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include "variables.h"
#include <error.h>

View file

@ -18,6 +18,7 @@
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#include "shopt.h"
#include "defs.h"
#include <stak.h>
#include <ls.h>

View file

@ -39,6 +39,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include "variables.h"
#include "shnodes.h"

View file

@ -25,6 +25,7 @@
* AT&T Labs
*/
#include "shopt.h"
#if !SHOPT_MKSERVICE
void _STUB_b_mkservice(){}
#else

View file

@ -27,6 +27,7 @@
* AT&T Labs
*/
#include "shopt.h"
#include "defs.h"
#include <error.h>
#include <stak.h>

View file

@ -26,6 +26,7 @@
*
*/
#include "shopt.h"
#include <ast.h>
#include <error.h>
#include "defs.h"

View file

@ -29,6 +29,7 @@
* AT&T Research
*/
#include "shopt.h"
#include "defs.h"
#if SHOPT_REGRESS

View file

@ -26,6 +26,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include <error.h>
#include <errno.h>

View file

@ -27,6 +27,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include <error.h>
#include <ls.h>

View file

@ -31,6 +31,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include "jobs.h"
#include "builtins.h"

View file

@ -40,6 +40,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include <error.h>
#include "path.h"

View file

@ -26,6 +26,7 @@
*
*/
#include "shopt.h"
#include <ast.h>
#include <sfio.h>
#include <error.h>

View file

@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
@ -27,6 +27,7 @@
*
*/
#include "shopt.h"
#include <ast.h>
#include <sfio.h>
#include <error.h>

View file

@ -28,6 +28,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include <error.h>
#include "shtable.h"

View file

@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
@ -18,6 +18,7 @@
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#include "shopt.h"
#include "defs.h"
#include <signal.h>
#include "FEATURE/options"

View file

@ -20,6 +20,7 @@
***********************************************************************/
#include "shopt.h"
#include "defs.h"
#include "shtable.h"
#include <signal.h>

View file

@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
@ -18,6 +18,7 @@
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#include "shopt.h"
#include "shell.h"
#include "shlex.h"
#include "FEATURE/options"

View file

@ -19,8 +19,8 @@
* *
***********************************************************************/
#include "shopt.h"
#include <ast.h>
#include "FEATURE/options"
#include "lexstates.h"

View file

@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
@ -19,6 +19,7 @@
* *
***********************************************************************/
#include "shopt.h"
#include <ast.h>
#include "ulimit.h"

View file

@ -27,6 +27,7 @@
*
*/
#include "shopt.h"
#include <ast.h>
#include <errno.h>
#include "defs.h"

View file

@ -19,6 +19,7 @@
* *
***********************************************************************/
#include "shopt.h"
#include "defs.h"
#include "name.h"
#include "shtable.h"

View file

@ -18,6 +18,7 @@
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#include "shopt.h"
#include "defs.h"
#include "jobs.h"

View file

@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2011 AT&T Intellectual Property *
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
@ -22,6 +22,7 @@
* data for string evaluator library
*/
#include "shopt.h"
#include <ast_standards.h>
#include "FEATURE/options"
#include "streval.h"

View file

@ -23,8 +23,8 @@
* tables for the test builtin [[ ... ]] and [ ... ]
*/
#include "shopt.h"
#include <ast.h>
#include "defs.h"
#include "test.h"

View file

@ -19,6 +19,7 @@
* *
***********************************************************************/
#include "shopt.h"
#include <ast.h>
#include "FEATURE/options"
#include "FEATURE/dynamic"

View file

@ -23,6 +23,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include <ast_wchar.h>
#include "lexstates.h"

View file

@ -27,6 +27,7 @@
* Coded April 1983.
*/
#include "shopt.h"
#include <ast.h>
#include <errno.h>
#include <ccode.h>

View file

@ -61,9 +61,12 @@ One line screen editor for any program
* but you can use them to separate features.
*/
#include "shopt.h"
#if SHOPT_ESH
#include <ast.h>
#include <releaseflags.h>
#include "FEATURE/cmds"
#include "defs.h"
#include "io.h"
@ -1313,7 +1316,7 @@ static void xcommands(register Emacs_t *ep,int count)
show_info(ep,hbuf);
return;
}
# if !_AST_ksh_release /* debugging, modify as required */
# if !_AST_release /* debugging, modify as required */
case cntl('D'): /* ^X^D show debugging info */
{
char debugbuf[MAXLINE];

View file

@ -32,6 +32,7 @@
*/
#include "shopt.h"
#include "defs.h"
#include "edit.h"

View file

@ -39,6 +39,8 @@
*/
#include "shopt.h"
#define HIST_MAX (sizeof(int)*HIST_BSIZE)
#define HIST_BIG (0100000-1024) /* 1K less than maximum short */
#define HIST_LINE 32 /* typical length for history line */

View file

@ -28,6 +28,8 @@
* cbosgd!pds
-*/
#include "shopt.h"
#if SHOPT_VSH
#include "defs.h"

View file

@ -48,6 +48,7 @@
#include <sfio.h>
#include <error.h>
#include "shopt.h"
#include "FEATURE/externs"
#include "FEATURE/options"
#include <cdt.h>

View file

@ -19,6 +19,8 @@
* *
***********************************************************************/
#include <releaseflags.h>
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
#define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */
#define SH_RELEASE_DATE "2022-06-09" /* must be in this format for $((.sh.version)) */
@ -26,7 +28,7 @@
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */
/* Arithmetic $((.sh.version)) uses the last 10 chars, so the date must be at the end. */
#if _AST_ksh_release
#if _AST_release
# define SH_RELEASE SH_RELEASE_FORK "/" SH_RELEASE_SVER " " SH_RELEASE_DATE
#else
# ifdef _AST_git_commit

View file

@ -27,6 +27,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include "path.h"
#include "jobs.h"

View file

@ -24,6 +24,7 @@
* AT&T Labs
*/
#include "shopt.h"
#include "defs.h"
#include "lexstates.h"
#include "name.h"

View file

@ -27,6 +27,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include <stak.h>
#include "name.h"

View file

@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2011 AT&T Intellectual Property *
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
@ -24,6 +24,7 @@
* This file defines all the read/write shell global variables
*/
#include "shopt.h"
#include "defs.h"
#include "jobs.h"
#include "shlex.h"

603
src/cmd/ksh93/sh/deparse.c Normal file
View file

@ -0,0 +1,603 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1982-2011 AT&T Intellectual Property *
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* 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> *
* *
***********************************************************************/
/*
* David Korn
* AT&T Labs
*
* shell deparser
*
*/
#include "shopt.h"
#include "defs.h"
#include "shnodes.h"
#include "test.h"
#define HUGE_INT (((unsigned)-1)>>1)
#define BEGIN 0
#define MIDDLE 1
#define END 2
#define PRE 1
#define POST 2
/* flags that can be specified with p_tree() */
#define NO_NEWLINE (1 << 0)
#define NEED_BRACE (1 << 1)
#define NO_BRACKET (1 << 2)
#define PROCSUBST (1 << 3)
static void p_comlist(const struct dolnod*,int);
static void p_arg(const struct argnod*, int endchar, int opts);
static void p_comarg(const struct comnod*);
static void p_keyword(const char*,int);
static void p_redirect(const struct ionod*);
static void p_switch(const struct regnod*);
static void here_body(const struct ionod*);
static void p_tree(const Shnode_t*,int);
static int level;
static int begin_line;
static int end_line;
static char io_op[7];
static char un_op[3] = "-?";
static const struct ionod *here_doc;
static Sfio_t *outfile;
static const char *forinit = "";
void sh_deparse(Sfio_t *out, const Shnode_t *t,int tflags)
{
outfile = out;
p_tree(t,tflags);
}
/*
* print script corresponding to shell tree <t>
*/
static void p_tree(register const Shnode_t *t,register int tflags)
{
register char *cp=0;
int save = end_line;
int needbrace = (tflags&NEED_BRACE);
int procsub = (tflags&PROCSUBST);
tflags &= ~NEED_BRACE;
if(tflags&NO_NEWLINE)
end_line = ' ';
else if(procsub)
end_line = ')';
else
end_line = '\n';
switch(t->tre.tretyp&COMMSK)
{
case TTIME:
if(t->tre.tretyp&COMSCAN)
p_keyword("!",BEGIN);
else
p_keyword("time",BEGIN);
if(t->par.partre)
p_tree(t->par.partre,tflags);
level--;
break;
case TCOM:
if(begin_line && level>0)
sfnputc(outfile,'\t',level);
begin_line = 0;
p_comarg((struct comnod*)t);
break;
case TSETIO:
if(t->tre.tretyp&FPCL)
tflags |= NEED_BRACE;
else
tflags = NO_NEWLINE|NEED_BRACE;
p_tree(t->fork.forktre,tflags);
p_redirect(t->fork.forkio);
break;
case TFORK:
if(needbrace)
tflags |= NEED_BRACE;
if((t->tre.tretyp&(FAMP|FCOOP)) && (t->tre.tretyp&(FAMP|FINT))!=FAMP)
{
tflags = NEED_BRACE|NO_NEWLINE;
end_line = ' ';
}
else if(t->fork.forkio)
tflags = NO_NEWLINE;
p_tree(t->fork.forktre,tflags);
if(t->fork.forkio)
p_redirect(t->fork.forkio);
if(t->tre.tretyp&FCOOP)
{
sfputr(outfile,"|&",procsub?')':'\n');
begin_line = 1;
}
else if((t->tre.tretyp&(FAMP|FINT))==(FAMP|FINT))
{
sfputr(outfile,"&",procsub?')':'\n');
begin_line = 1;
}
break;
case TIF:
p_keyword("if",BEGIN);
p_tree(t->if_.iftre,0);
p_keyword("then",MIDDLE);
p_tree(t->if_.thtre,0);
if(t->if_.eltre)
{
p_keyword("else",MIDDLE);
p_tree(t->if_.eltre,0);
}
p_keyword("fi",END);
break;
case TWH:
if(t->wh.whinc)
cp = "for";
else if(t->tre.tretyp&COMSCAN)
cp = "until";
else
cp = "while";
p_keyword(cp,BEGIN);
if(t->wh.whinc)
{
struct argnod *arg = (t->wh.whtre)->ar.arexpr;
sfprintf(outfile,"(( %s; ",forinit);
forinit = "";
sfputr(outfile,arg->argval,';');
arg = (t->wh.whinc)->arexpr;
sfprintf(outfile," %s))\n",arg->argval);
}
else
p_tree(t->wh.whtre,0);
t = t->wh.dotre;
goto dolist;
case TLST:
{
Shnode_t *tr = t->lst.lstrit;
if(tr->tre.tretyp==TWH && tr->wh.whinc && t->lst.lstlef->tre.tretyp==TARITH)
{
/* arithmetic for statement */
struct argnod *init = (t->lst.lstlef)->ar.arexpr;
forinit= init->argval;
p_tree(t->lst.lstrit,tflags);
break;
}
if(needbrace)
p_keyword("{",BEGIN);
p_tree(t->lst.lstlef,0);
if(needbrace)
tflags = 0;
p_tree(t->lst.lstrit,tflags);
if(needbrace)
p_keyword("}",END);
break;
}
case TAND:
cp = "&&";
goto andor;
case TORF:
cp = "||";
goto andor;
case TFIL:
cp = "|";
andor:
{
int bracket = 0;
if(t->tre.tretyp&TTEST)
{
tflags |= NO_NEWLINE;
if(!(tflags&NO_BRACKET))
{
p_keyword("[[",BEGIN);
tflags |= NO_BRACKET;
bracket=1;
}
}
p_tree(t->lst.lstlef,NEED_BRACE|NO_NEWLINE|(tflags&NO_BRACKET));
if(tflags&FALTPIPE)
{
Shnode_t *tt = t->lst.lstrit;
if(tt->tre.tretyp!=TFIL || !(tt->lst.lstlef->tre.tretyp&FALTPIPE))
{
sfputc(outfile,'\n');
return;
}
}
sfputr(outfile,cp,here_doc?'\n':' ');
if(here_doc)
{
here_body(here_doc);
here_doc = 0;
}
level++;
p_tree(t->lst.lstrit,tflags|NEED_BRACE);
if(bracket)
p_keyword("]]",END);
level--;
break;
}
case TPAR:
p_keyword("(",BEGIN);
p_tree(t->par.partre,0);
p_keyword(")",END);
break;
case TARITH:
{
register struct argnod *ap = t->ar.arexpr;
if(begin_line && level)
sfnputc(outfile,'\t',level);
sfprintf(outfile,"(( %s ))%c",ap->argval,end_line);
if(!(tflags&NO_NEWLINE))
begin_line=1;
break;
}
case TFOR:
cp = ((t->tre.tretyp&COMSCAN)?"select":"for");
p_keyword(cp,BEGIN);
sfputr(outfile,t->for_.fornam,' ');
if(t->for_.forlst)
{
sfputr(outfile,"in",' ');
tflags = end_line;
end_line = '\n';
p_comarg(t->for_.forlst);
end_line = tflags;
}
else
sfputc(outfile,'\n');
begin_line = 1;
t = t->for_.fortre;
dolist:
p_keyword("do",MIDDLE);
p_tree(t,0);
p_keyword("done",END);
break;
case TSW:
p_keyword("case",BEGIN);
p_arg(t->sw.swarg,' ',0);
if(t->sw.swlst)
{
begin_line = 1;
sfputr(outfile,"in",'\n');
tflags = end_line;
end_line = '\n';
p_switch(t->sw.swlst);
end_line = tflags;
}
p_keyword("esac",END);
break;
case TFUN:
if(t->tre.tretyp&FPOSIX)
{
sfprintf(outfile,"%s",t->funct.functnam);
p_keyword("()\n",BEGIN);
}
else
{
p_keyword("function",BEGIN);
tflags = (t->funct.functargs?' ':'\n');
sfputr(outfile,t->funct.functnam,tflags);
if(t->funct.functargs)
{
tflags = end_line;
end_line = '\n';
p_comarg(t->funct.functargs);
end_line = tflags;
}
}
begin_line = 1;
p_keyword("{\n",MIDDLE);
begin_line = 1;
p_tree(t->funct.functtre,0);
p_keyword("}",END);
break;
/* new test compound command */
case TTST:
if(!(tflags&NO_BRACKET))
p_keyword("[[",BEGIN);
if((t->tre.tretyp&TPAREN)==TPAREN)
{
p_keyword("(",BEGIN);
p_tree(t->lst.lstlef,NO_BRACKET|NO_NEWLINE);
p_keyword(")",END);
}
else
{
int flags = (t->tre.tretyp)>>TSHIFT;
if(t->tre.tretyp&TNEGATE)
sfputr(outfile,"!",' ');
if(t->tre.tretyp&TUNARY)
{
un_op[1] = flags;
sfputr(outfile,un_op,' ');
}
else
cp = ((char*)(shtab_testops+(flags&037)-1)->sh_name);
p_arg(&(t->lst.lstlef->arg),' ',0);
if(t->tre.tretyp&TBINARY)
{
sfputr(outfile,cp,' ');
p_arg(&(t->lst.lstrit->arg),' ',0);
}
}
if(!(tflags&NO_BRACKET))
p_keyword("]]",END);
}
while(begin_line && here_doc)
{
here_body(here_doc);
here_doc = 0;
}
end_line = save;
return;
}
/*
* print a keyword
* increment indent level for flag==BEGIN
* decrement indent level for flag==END
*/
static void p_keyword(const char *word,int flag)
{
register int sep;
if(flag==END)
sep = end_line;
else if(*word=='[' || *word=='(')
sep = ' ';
else
sep = '\t';
if(flag!=BEGIN)
level--;
if(begin_line && level)
sfnputc(outfile,'\t',level);
sfputr(outfile,word,sep);
if(sep=='\n')
begin_line=1;
else
begin_line=0;
if(flag!=END)
level++;
}
static void p_arg(register const struct argnod *arg,register int endchar,int opts)
{
register const char *cp;
register int flag=0;
do
{
if(!arg->argnxt.ap)
flag = endchar;
else if(opts&PRE)
{
/* case alternation lists in reverse order */
p_arg(arg->argnxt.ap,'|',opts);
flag = endchar;
}
else if(opts)
flag = ' ';
cp = arg->argval;
if(*cp==0 && (arg->argflag&ARG_EXP) && arg->argchn.ap)
{
/* process substitution */
int c = (arg->argflag&ARG_RAW)?'>':'<';
sfputc(outfile,c);
sfputc(outfile,'(');
p_tree((Shnode_t*)arg->argchn.ap,PROCSUBST);
}
else if(*cp==0 && opts==POST && arg->argchn.ap)
{
/* compound assignment */
struct fornod *fp=(struct fornod*)arg->argchn.ap;
sfprintf(outfile,"%s=(\n",fp->fornam);
sfnputc(outfile,'\t',++level);
p_tree(fp->fortre,0);
if(--level)
sfnputc(outfile,'\t',level);
sfputc(outfile,')');
}
else if((arg->argflag&ARG_RAW) && (cp[1] || (*cp!='[' && *cp!=']')))
cp = sh_fmtq(cp);
sfputr(outfile,cp,flag);
if(flag=='\n')
begin_line = 1;
arg = arg->argnxt.ap;
}
while((opts&POST) && arg);
return;
}
static void p_redirect(register const struct ionod *iop)
{
register char *cp;
register int iof,iof2;
for(;iop;iop=iop->ionxt)
{
iof=iop->iofile;
cp = io_op;
if(iop->iovname)
{
sfwrite(outfile,"(;",2);
sfputr(outfile,iop->iovname,')');
cp++;
}
else
*cp = '0'+(iof&IOUFD);
if(iof&IOPUT)
{
if(*cp == '1' && !iop->iovname)
cp++;
io_op[1] = '>';
}
else
{
if(*cp == '0' && !iop->iovname)
cp++;
io_op[1] = '<';
}
io_op[2] = 0;
io_op[3] = 0;
if(iof&IOLSEEK)
{
io_op[1] = '#';
if(iof&IOARITH)
strcpy(&io_op[3]," ((");
}
else if(iof&IOMOV)
io_op[2] = '&';
else if(iof&(IORDW|IOAPP))
io_op[2] = '>';
else if(iof&IOCLOB)
io_op[2] = '|';
if(iop->iodelim)
{
/* here document */
here_doc = iop;
io_op[2] = '<';
}
sfputr(outfile,cp,' ');
if(iop->ionxt)
iof = ' ';
else
{
if((iof=end_line)=='\n')
begin_line = 1;
}
if((iof&IOLSEEK) && (iof&IOARITH))
iof2 = iof, iof = ' ';
if((iop->iofile & IOPROCSUB) && !(iop->iofile & IOLSEEK))
{
/* process substitution as argument to redirection */
if(iop->iofile & IOPUT)
sfwrite(outfile,">(",2);
else
sfwrite(outfile,"<(",2);
p_tree((Shnode_t*)iop->ioname,PROCSUBST);
sfputc(outfile,iof);
}
else if(iop->iodelim)
{
if(!(iop->iofile&IODOC))
sfwrite(outfile,"''",2);
sfputr(outfile,sh_fmtq(iop->iodelim),iof);
}
else if(iop->iofile&IORAW)
sfputr(outfile,sh_fmtq(iop->ioname),iof);
else
sfputr(outfile,iop->ioname,iof);
if((iof&IOLSEEK) && (iof&IOARITH))
sfputr(outfile, "))", iof2);
}
return;
}
static void p_comarg(register const struct comnod *com)
{
register int flag = end_line;
if(com->comtyp&FAMP)
sfwrite(outfile,"& ",2);
if(com->comarg || com->comio)
flag = ' ';
if(com->comset)
p_arg(com->comset,flag,POST);
if(com->comarg)
{
if(!com->comio)
flag = end_line;
if(com->comtyp&COMSCAN)
p_arg(com->comarg,flag,POST);
else
p_comlist((struct dolnod*)com->comarg,flag);
}
if(com->comio)
p_redirect(com->comio);
return;
}
static void p_comlist(const struct dolnod *dol,int endchar)
{
register char *cp, *const*argv;
register int flag = ' ', special;
argv = dol->dolval+ARG_SPARE;
cp = *argv;
special = (*cp=='[' && cp[1]==0);
do
{
if(cp)
argv++;
else
cp = "";
if(*argv==0)
{
if((flag=endchar)=='\n')
begin_line = 1;
special = (*cp==']' && cp[1]==0);
}
sfputr(outfile,special?cp:sh_fmtq(cp),flag);
special = 0;
}
while(cp = *argv);
return;
}
static void p_switch(register const struct regnod *reg)
{
if(level>1)
sfnputc(outfile,'\t',level-1);
p_arg(reg->regptr,')',PRE);
begin_line = 0;
sfputc(outfile,'\t');
if(reg->regcom)
p_tree(reg->regcom,0);
level++;
if(reg->regflag)
p_keyword(";&",END);
else
p_keyword(";;",END);
if(reg->regnxt)
p_switch(reg->regnxt);
return;
}
/*
* output here documents
*/
static void here_body(register const struct ionod *iop)
{
Sfio_t *infile;
if(iop->iofile&IOSTRG)
infile = sfnew((Sfio_t*)0,iop->ioname,iop->iosize,-1,SF_STRING|SF_READ);
else
sfseek(infile=sh.heredocs,iop->iooffset,SEEK_SET);
sfmove(infile,outfile,iop->iosize,-1);
if(iop->iofile&IOSTRG)
sfclose(infile);
sfputr(outfile,iop->iodelim,'\n');
}

View file

@ -26,6 +26,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include "variables.h"
#include "test.h"

View file

@ -26,6 +26,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include <fcin.h>
#include "io.h"

View file

@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2011 AT&T Intellectual Property *
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
@ -26,6 +26,7 @@
*
*/
#include "shopt.h"
#include <ast.h>
#include <sfio.h>
#include <error.h>

View file

@ -27,6 +27,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include <stak.h>
#include <ccode.h>

View file

@ -27,6 +27,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include <fcin.h>
#include <ls.h>

View file

@ -50,6 +50,7 @@
* may be temporarily turned off without turning off the option.
*/
#include "shopt.h"
#include "defs.h"
#include <wait.h>
#include "io.h"

View file

@ -26,7 +26,9 @@
*
*/
#include "shopt.h"
#include <ast.h>
#include <releaseflags.h>
#include <stak.h>
#include <fcin.h>
#include <nval.h>
@ -1410,7 +1412,7 @@ breakloop:
alt = ">="; /* '-ge' --> '>=' */
break;
default:
#if _AST_ksh_release
#if _AST_release
alt = NIL(char*); /* output '(null)' (should never happen) */
#else
abort();

View file

@ -31,6 +31,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include <fcin.h>
#include <pwd.h>

View file

@ -27,6 +27,7 @@
*
*/
#include "shopt.h"
#include <ast.h>
#include <sfio.h>
#include <stak.h>

View file

@ -25,6 +25,7 @@
#define putenv ___putenv
#include "shopt.h"
#include "defs.h"
#include "variables.h"
#include "path.h"

View file

@ -23,6 +23,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include "variables.h"
#include "builtins.h"

View file

@ -27,6 +27,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include "name.h"
#include "argnod.h"

View file

@ -23,6 +23,7 @@
* AT&T Labs
*
*/
#include "shopt.h"
#include "defs.h"
#include "io.h"
#include "variables.h"

View file

@ -28,6 +28,7 @@
* This is the parser for a shell language
*/
#include "shopt.h"
#include "defs.h"
#include <fcin.h>
#include <error.h>

View file

@ -24,6 +24,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include <fcin.h>
#include <ls.h>

View file

@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2011 AT&T Intellectual Property *
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
@ -19,8 +19,8 @@
* *
***********************************************************************/
#include "shopt.h"
#include <shell.h>
#include "FEATURE/externs"
#if defined(__sun) && _sys_mman && _lib_memcntl && defined(MHA_MAPSIZE_STACK) && defined(MC_HAT_ADVISE)

View file

@ -26,6 +26,7 @@
*
*/
#include "shopt.h"
#include "version.h"
static const char usage[] =

View file

@ -29,6 +29,7 @@
* and has a separate executor
*/
#include "shopt.h"
#include "streval.h"
#include <ctype.h>
#include <error.h>

View file

@ -23,6 +23,7 @@
*
*/
#include "shopt.h"
#include <ast.h>
#include <ast_wchar.h>
#include "defs.h"

View file

@ -26,6 +26,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include <ls.h>
#include "io.h"

View file

@ -26,6 +26,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include "shnodes.h"
#include "path.h"

View file

@ -19,6 +19,7 @@
* *
***********************************************************************/
#include "shopt.h"
#include <ast.h>
#include <sig.h>
#include <error.h>

View file

@ -26,6 +26,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include "shnodes.h"
#include "path.h"

View file

@ -19,6 +19,7 @@
* *
***********************************************************************/
#include "shopt.h"
#include "defs.h"
/*
* This installs a hook to allow the processing of events when

View file

@ -26,6 +26,7 @@
*
*/
#include "shopt.h"
#include "defs.h"
#include <fcin.h>
#include "variables.h"

View file

@ -2,7 +2,7 @@
# #
# This software is part of the ast package #
# Copyright (c) 1982-2011 AT&T Intellectual Property #
# Copyright (c) 2020-2021 Contributors to ksh 93u+m #
# Copyright (c) 2020-2022 Contributors to ksh 93u+m #
# and is licensed under the #
# Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property #