cat.c revision da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1992-2007 AT&T Knowledge Ventures *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Knowledge Ventures *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* 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) 2006-05-17 $\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?Causes non-printing characters (whith the exception of"
" tabs, new-lines, and form-feeds) to be output as printable charater"
" sequences. ASCII control characters are printed as \b^\b\an\a,"
" where \an\a is the corresponding ASCII character in the range"
" octal 100-137. The DEL character (octal 0177) is copied"
" as \b^?\b. Other non-printable characters are copied as \bM-\b\ax\a"
" where \ax\a is the ASCII character specified by the low-order seven"
" bits. 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.]"
"[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)]"
;
#define RUBOUT 0177
/* control flags */
#define B_FLAG (1<<0)
/* character types */
#define T_ENDBUF 1
#define T_CONTROL 2
#define T_NEWLINE 3
#define T_EIGHTBIT 4
#define T_CNTL8BIT 5
#define printof(c) ((c)^0100)
/*
* called for any special output processing
*/
static int
{
register unsigned char* cp;
register unsigned char* cpold;
register int n;
register int m;
register int line = 1;
register unsigned char* endbuff;
unsigned char* inbuff;
int lastchar;
unsigned char meta[4];
meta[0] = 'M';
for (;;)
{
/* read in a buffer full */
return n;
*endbuff = 0;
if (printdefer)
{
printdefer = 0;
}
while (endbuff)
{
/* skip over printable characters */
if (mbwide())
else
if (n==T_ENDBUF)
{
{
{
cp++;
}
else
{
*++endbuff = 0;
if (n==T_ENDBUF)
n = T_CONTROL;
}
endbuff = 0;
}
else n = T_CONTROL;
}
switch(n)
{
case T_CNTL8BIT:
do
{
n = (*cp++)&~0200;
}
break;
case T_EIGHTBIT:
do
{
}
break;
case T_CONTROL:
do
{
n = *cp++;
}
break;
case T_NEWLINE:
{
line++;
cp--;
}
do
{
cp++;
continue;
line++;
else printdefer = 1;
}
break;
}
}
}
}
int
{
register int n;
register int flags = 0;
register char* cp;
char* mode;
int att;
int dovcat=0;
mode = "r";
for (;;)
{
{
case 'A':
continue;
case 'B':
continue;
case 'b':
continue;
case 'E':
continue;
case 'e':
continue;
case 'n':
continue;
case 's':
continue;
case 'S':
continue;
case 'T':
continue;
case 't':
continue;
case 'u':
continue;
case 'v':
continue;
case 'd':
mode = "rt";
continue;
case 'D':
continue;
case ':':
break;
case '?':
break;
}
break;
}
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;
}