/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1992-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 *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* David Korn
* Glenn Fowler
* AT&T Bell Laboratories
*
* cat
*/
#include <cmd.h>
#include <fcntl.h>
static const char usage[] =
"[-?\n@(#)$Id: cat (AT&T Research) 2012-05-31 $\n]"
"[+NAME?cat - concatenate files]"
"[+DESCRIPTION?\bcat\b copies each \afile\a in sequence to the standard"
" output. If no \afile\a is given, or if the \afile\a is \b-\b,"
" \bcat\b copies from standard input starting at the current location.]"
"[b:number-nonblank?Number lines as with \b-n\b but omit line numbers from"
" blank lines.]"
"[d:dos-input?Input files are opened in \atext\amode which removes carriage"
" returns in front of new-lines on some systems.]"
"[e?Equivalent to \b-vE\b.]"
"[n:number?Causes a line number to be inserted at the beginning of each line.]"
"[s?Equivalent to \b-S\b for \aatt\a universe and \b-B\b otherwise.]"
"[t?Equivalent to \b-vT\b.]"
"[u:unbuffer?The output is not delayed by buffering.]"
"[v:show-nonprinting|print-chars?Print characters as follows: space and "
"printable characters as themselves; control characters as \b^\b "
"followed by a letter of the alphabet; and characters with the high bit "
"set as the lower 7 bit character prefixed by \bM^\b for 7 bit "
"non-printable characters and \bM-\b for all other characters. If the 7 "
"bit character encoding is not ASCII then the characters are converted "
"to ASCII to determine \ahigh bit set\a, and if set it is cleared and "
"converted back to the native encoding. Multibyte characters in the "
"current locale are treated as printable characters.]"
"[A:show-all?Equivalent to \b-vET\b.]"
"[B:squeeze-blank?Multiple adjacent new-line characters are replace by one"
" new-line.]"
"[D:dos-output?Output files are opened in \atext\amode which inserts carriage"
" returns in front of new-lines on some systems.]"
"[E:show-ends?Causes a \b$\b to be inserted before each new-line.]"
"[R:regress?Regression test defaults: \b-v\b buffer size 4.]"
"[S:silent?\bcat\b is silent about non-existent files.]"
"[T:show-blank?Causes tabs to be copied as \b^I\b and formfeeds as \b^L\b.]"
"\n"
"\n[file ...]\n"
"\n"
"[+SEE ALSO?\bcp\b(1), \bgetconf\b(1), \bpr\b(1)]"
;
/* control flags */
/* character types */
#ifndef sfvalue
#endif
static void*
{
void* r;
return r;
}
/*
* called for any special output processing
*/
static int
{
register unsigned char* cp;
register unsigned char* pp;
unsigned char* cur;
unsigned char* end;
unsigned char* buf;
unsigned char* nxt;
register int n;
register int line;
register int raw;
int last;
int c;
int m;
int any;
int header;
meta[0] = 'M';
last = -1;
any = 0;
line = 1;
for (;;)
{
if (raw)
else
for (;;)
{
if (n < T_CONTROL)
break;
cp += m - 1;
else
{
if (m <= 0)
{
{
if (last > 0)
{
last = -1;
{
any = 1;
if (header)
{
header = 0;
}
}
else
{
{
last = -1;
}
{
last = -1;
}
else
{
*end = 0;
}
mb:
n = sizeof(tmp) - c - 1;
{
any = 1;
if (header)
{
header = 0;
}
}
}
continue;
}
}
else
{
n = 0;
}
}
break;
}
}
c = *--cp;
{
any = 1;
if (header)
{
header = 0;
}
if (m)
}
switch (n)
{
case T_ERROR:
{
n = T_CONTROL;
goto flush;
}
return -1;
case T_EOF:
{
n = T_CONTROL;
goto flush;
}
return 0;
case T_ENDBUF:
{
n = T_CONTROL;
goto flush;
}
c = last;
{
last = -1;
}
{
last = -1;
}
else
{
*end = 0;
}
if (c >= 0)
{
if (!(n = states[c]))
{
m = 1;
goto flush;
}
{
cp--;
goto special;
}
tmp[0] = c;
c = 1;
goto mb;
}
break;
case T_CONTROL:
do
{
break;
case T_CNTL8BIT:
do
{
n = c & ~0200;
break;
case T_EIGHTBIT:
do
{
break;
case T_NEWLINE:
line++;
for (;;)
{
{
break;
{
*cp-- = 0;
last = -1;
}
{
*cp-- = 0;
last = -1;
}
else
{
*end = 0;
}
}
else if (n != T_NEWLINE)
break;
{
any = 0;
header = 0;
}
line++;
}
break;
}
}
}
int
{
register int n;
register int flags = 0;
register char* cp;
char* mode;
int att;
int dovcat = 0;
mode = "r";
for (;;)
{
n = 0;
{
case 'A':
break;
case 'B':
n = S_FLAG;
break;
case 'b':
n = B_FLAG;
break;
case 'd':
continue;
case 'D':
n = d_FLAG;
break;
case 'E':
n = E_FLAG;
break;
case 'e':
break;
case 'n':
n = N_FLAG;
break;
case 'R':
continue;
case 's':
break;
case 'S':
n = F_FLAG;
break;
case 'T':
n = T_FLAG;
break;
case 't':
break;
case 'u':
n = U_FLAG;
break;
case 'v':
n = V_FLAG;
break;
case ':':
break;
case '?':
break;
}
if (!n)
break;
flags |= n;
else
flags &= ~n;
}
if (error_info.errors)
{
states['\n'] = 0;
}
if (att)
{
{
{
}
}
}
else if (flags)
{
states['\t'] = 0;
}
{
dovcat = 1;
}
argv++;
do
{
{
}
{
continue;
}
if (dovcat)
n = 0;
else
n = -1;
{
if (cp)
else
}
break;
return error_info.errors;
}