/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1989-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 *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* expand.c and unexpand.c
* They can be linked together
* Written by David Korn
* Sat Oct 8 13:47:13 EDT 1994
*/
static const char expand_usage[] =
"[-?@(#)$Id: expand (AT&T Research) 1999-06-17 $\n]"
"[+NAME?expand - convert tabs to spaces]"
"[+DESCRIPTION?\bexpand\b writes the contents of each given file "
"to standard output with tab characters replaced with one or "
"more space characters needed to pad to the next tab stop. Each "
"backspace character copied to standard output causes the column "
"position to be decremented by 1 unless already in the first column.]" "[+?If no \afile\a is given, or if the \afile\a is \b-\b, \bexpand\b "
"copies from standard input. The start of the file is defined "
"as the current offset.]"
"[i:initial? Only convert initial tabs (those that precede all non "
"space or tab characters) on each line to spaces.]"
"[t:tabs]:[tablist:=8?\atablist\a is a comma or space separated list "
"of positive integers that specifies the tab stops. If only one "
"tab stop is specified, then tabs will be set at that many "
"column positions apart. Otherwise, the value in \atablist\a "
"must be in ascending order and the tab stops will be set to "
"these positions. In the event of \bexpand\b having to process "
"tab characters beyond the last specified tab stop, each tab "
"character is replaced by a single tab.]"
"\n"
"\n[file ...]\n"
"\n"
"[+EXIT STATUS]{"
"[+0?All files expanded successfully.]"
"[+>0?One or more files failed to open or could not be read.]"
"}"
"[+SEE ALSO?\bunexpand\b(1), \bpr\b(1)]"
;
static const char unexpand_usage[] =
"[-?@(#)$Id: unexpand (AT&T Research) 1999-06-07 $\n]"
"[+NAME?unexpand - convert spaces to tabs]"
"[+DESCRIPTION?\bunexpand\b writes the contents of each given file "
"to standard output with strings of two or more space and "
"tab characters at the beginning of each line converted "
"to as many tabs as possible followed by as many spaces needed "
"to fill the same number of column positions. By default, "
"tabs are set at every 8th column. Each backspace character copied "
"to standard output causes the column position to be decremented by 1 "
"unless already in the first column.]"
"[+?If no \afile\a is given, or if the \afile\a is \b-\b, \bunexpand\b "
"copies from standard input. The start of the file is defined "
"as the current offset.]"
"[a:all?Convert all strings of two or more spaces or tabs, not just "
"initial ones.]"
"[t:tabs]:[tablist:=8?\atablist\a is a comma or space separated list "
"of positive integers that specifies the tab stops. If only one "
"tab stop is specified, then tabs will be set at that many "
"column positions apart. Otherwise, the value in \atablist\a "
"must be in ascending order and the tab stops will be set to "
"these positions. This option implies the \b-a\b option.]"
"\n"
"\n[file ...]\n"
"\n"
"[+EXIT STATUS?]{"
"[+0?All files unexpanded successfully.]"
"[+>0?One or more files failed to open or could not be read.]"
"}"
"[+SEE ALSO?\bexpand\b(1), \bpr\b(1)]"
;
#include <cmd.h>
{
int *tablist;
while(c= *cp++)
{
if(c==' ' || c=='\t' || c==',')
n++;
}
n=0;
while(1)
{
cp++;
if(c==0)
break;
}
*ntab=n;
return(tablist);
}
{
register int n=0;
register int savec;
register char *cpend;
if(type)
else
errno=0;
{
savec = n;
while(1)
{
switch(n)
{
case S_SPACE:
{
n = 1;
cp -= 1;
if(tabmax==0)
while(cp[n]==' ')
n++;
/* check for end of buffer */
{
/* keep grabbing spaces */
register int c;
if(i)
i=0;
n++;
n++;
if(c!=EOF)
}
cp += n;
{
if(i)
{
i=0;
}
while(n >= tabspace)
{
n -= tabspace;
if(++i < tabmax)
else if(tabmax<=1)
else
break;
}
if(n>0)
}
}
if(tabmax)
state[' '] = 0;
break;
case S_TAB:
if(tabmax==1)
else
{
register int i=0;
while(1)
{
if(i>=tabmax)
n=1;
else if(tablist[i++]<=n)
continue;
else
n = tablist[i-1]-n;
break;
}
}
if(n<=1)
else
{
first -= (n-1);
}
if(initial)
state[' '] = 0;
break;
case S_BS:
break;
case S_EOF:
{
/* end of buffer */
}
break;
case S_NL:
if(type==0)
else
break;
}
{
break;
}
}
}
return(errno);
}
int
{
register int n,type;
register char *cp;
int initial=0;
const char *usage;
if(type)
else
{
case 't':
break;
case 'i':
initial = 1;
break;
case 'a':
if(ntabs < 0)
ntabs = 0;
break;
case ':':
else
break;
case '?':
break;
}
if(ntabs<0)
ntabs=1;
else if(ntabs==1)
tablist[0] += 1;
if(error_info.errors)
argv++;
do
{
{
continue;
}
return(error_info.errors);
}