rev.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* 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
/*
* rev [-l] [file ...]
*
* reverse the characters or lines of one or more files
*
* David Korn
* AT&T Laboratories
* dgk@research.att.com
*
*/
static const char usage[] =
"[-?\n@(#)$Id: rev (AT&T Research) 2007-11-29 $\n]"
"[+NAME?rev - reverse the characters or lines of one or more files]"
"[+DESCRIPTION?\brev\b copies one or more files to standard output "
"reversing the order of characters on every line of the file "
"or reversing the order of lines of the file if \b-l\b is specified.]"
"[+?If no \afile\a is given, or if the \afile\a is \b-\b, \brev\b "
"copies from standard input starting at the current offset.]"
"[l:line?Reverse the lines of the file.]"
"\n"
"\n[file ...]\n"
"\n"
"[+EXIT STATUS?]{"
"[+0?All files copied successfully.]"
"[+>0?One or more files did not copy.]"
"}"
"[+SEE ALSO?\bcat\b(1), \btail\b(1)]"
;
#include <cmd.h>
#include <rev.h>
/*
* reverse the characters within a line
*/
{
register int c;
register size_t n;
register size_t w;
if (mbwide())
{
wp = 0;
w = 0;
{
if (n > w)
{
{
return 0;
}
}
*cp++ = '\n';
{
if (wp)
return -1;
}
}
if (wp)
}
else
{
{
c = *--ep;
*bp++ = c;
}
return(-1);
}
return(0);
}
int
{
register char *cp;
register int n, line=0;
for (;;)
{
{
case 'l':
line=1;
continue;
case ':':
break;
case '?':
break;
}
break;
}
if(error_info.errors)
n=0;
argv++;
do
{
{
n=1;
continue;
}
if(line)
else
if(line < 0)
}
return(n);
}