/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1982-2011 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* David Korn
* AT&T Labs
*
* shell deparser
*
*/
#include "defs.h"
#include "shnodes.h"
#include "test.h"
#define BEGIN 0
/* flags that can be specified with p_tree() */
static void p_keyword(const char*,int);
static void p_redirect(const struct ionod*);
static int level;
static int begin_line;
static int end_line;
{
}
/*
* print script corresponding to shell tree <t>
*/
{
register char *cp;
tflags &= ~NEED_BRACE;
if(tflags&NO_NEWLINE)
end_line = ' ';
else
end_line = '\n';
{
case TTIME:
else
level--;
break;
case TCOM:
if(begin_line && level>0)
begin_line = 0;
break;
case TSETIO:
tflags |= NEED_BRACE;
else
break;
case TFORK:
if(needbrace)
tflags |= NEED_BRACE;
{
end_line = ' ';
}
tflags = NO_NEWLINE;
{
begin_line = 1;
}
{
begin_line = 1;
}
break;
case TIF:
{
}
break;
case TWH:
cp = "for";
cp = "until";
else
cp = "while";
{
forinit = "";
}
else
goto dolist;
case TLST:
{
{
/* arithmetic for statement */
break;
}
if(needbrace)
if(needbrace)
tflags = 0;
if(needbrace)
break;
}
case TAND:
cp = "&&";
goto andor;
case TORF:
cp = "||";
goto andor;
case TFIL:
cp = "|";
{
int bracket = 0;
{
tflags |= NO_NEWLINE;
if(!(tflags&NO_BRACKET))
{
tflags |= NO_BRACKET;
bracket=1;
}
}
{
{
return;
}
}
if(here_doc)
{
here_doc = 0;
}
level++;
if(bracket)
level--;
break;
}
case TPAR:
break;
case TARITH:
{
if(begin_line && level)
if(!(tflags&NO_NEWLINE))
begin_line=1;
break;
}
case TFOR:
{
end_line = '\n';
}
else
begin_line = 1;
p_tree(t,0);
break;
case TSW:
{
begin_line = 1;
end_line = '\n';
}
break;
case TFUN:
{
}
else
{
{
end_line = '\n';
}
}
begin_line = 1;
begin_line = 1;
break;
/* new test compound command */
case TTST:
if(!(tflags&NO_BRACKET))
{
}
else
{
{
}
else
{
}
}
if(!(tflags&NO_BRACKET))
}
while(begin_line && here_doc)
{
here_doc = 0;
}
return;
}
/*
* print a keyword
* increment indent level for flag==BEGIN
* decrement indent level for flag==END
*/
{
register int sep;
sep = ' ';
else
sep = '\t';
level--;
if(begin_line && level)
if(sep=='\n')
begin_line=1;
else
begin_line=0;
level++;
}
{
register const char *cp;
register int flag;
do
{
{
/* case alternation lists in reverse order */
}
else if(opts)
flag = ' ';
{
/* compound assignment */
if(--level)
}
if(flag=='\n')
begin_line = 1;
}
return;
}
{
register char *cp;
{
{
cp++;
}
else
{
cp++;
}
else
{
cp++;
}
io_op[2] = 0;
io_op[3] = 0;
{
}
{
/* here document */
#ifdef xxx
#endif
#ifdef future
#endif
}
iof = ' ';
else
{
begin_line = 1;
}
{
}
else
}
return;
}
{
flag = ' ';
{
else
}
return;
}
{
do
{
if(cp)
argv++;
else
cp = "";
if(*argv==0)
{
begin_line = 1;
}
special = 0;
}
return;
}
{
if(level>1)
begin_line = 0;
level++;
else
return;
}
/*
* output here documents
*/
{
#ifdef xxx
#endif
else
}