Upgrading echo

Change-Id: Idaa5da742b3cc9a1ee2f5c03f10e0627690556fa
This commit is contained in:
Lionel Sambuc 2013-01-30 18:49:19 +01:00
parent 3a19ae756f
commit 059578953d
7 changed files with 160 additions and 70 deletions

View file

@ -1,7 +1,7 @@
# $NetBSD: Makefile,v 1.22 2007/12/31 15:31:24 ad Exp $
# @(#)Makefile 8.1 (Berkeley) 5/31/93
SUBDIR= cat date ed \
SUBDIR= cat date echo ed \
mkdir pax rm rmdir test
.include <bsd.subdir.mk>

6
bin/echo/Makefile Normal file
View file

@ -0,0 +1,6 @@
# $NetBSD: Makefile,v 1.8 1997/07/20 22:36:53 christos Exp $
# @(#)Makefile 8.1 (Berkeley) 5/31/93
PROG= echo
.include <bsd.prog.mk>

68
bin/echo/echo.1 Normal file
View file

@ -0,0 +1,68 @@
.\" $NetBSD: echo.1,v 1.13 2003/08/07 09:05:12 agc Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" the Institute of Electrical and Electronics Engineers, Inc.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)echo.1 8.1 (Berkeley) 7/22/93
.\"
.Dd July 22, 1993
.Dt ECHO 1
.Os
.Sh NAME
.Nm echo
.Nd write arguments to the standard output
.Sh SYNOPSIS
.Nm
.Op Fl n
.Op Ar string ...
.Sh DESCRIPTION
The
.Nm
utility writes any specified operands, separated by single blank (`` '')
characters and followed by a newline (``\en'') character, to the standard
output.
.Pp
The following option is available:
.Bl -tag -width flag
.It Fl n
Do not print the trailing newline character.
.El
.Sh EXIT STATUS
The
.Nm
utility exits 0 on success, and \*[Gt]0 if an error occurs.
.Sh SEE ALSO
.Xr printf 1
.Sh STANDARDS
The
.Nm
utility is expected to be
.St -p1003.2
compatible.

83
bin/echo/echo.c Normal file
View file

@ -0,0 +1,83 @@
/* $NetBSD: echo.c,v 1.18 2008/09/18 05:42:08 dholland Exp $ */
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
__COPYRIGHT(
"@(#) Copyright (c) 1989, 1993\
The Regents of the University of California. All rights reserved.");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)echo.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: echo.c,v 1.18 2008/09/18 05:42:08 dholland Exp $");
#endif
#endif /* not lint */
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int, char *[]);
/* ARGSUSED */
int
main(int argc, char *argv[])
{
int nflag;
setprogname(argv[0]);
(void)setlocale(LC_ALL, "");
/* This utility may NOT do getopt(3) option parsing. */
if (*++argv && !strcmp(*argv, "-n")) {
++argv;
nflag = 1;
}
else
nflag = 0;
while (*argv) {
(void)printf("%s", *argv);
if (*++argv)
(void)putchar(' ');
}
if (nflag == 0)
(void)putchar('\n');
fflush(stdout);
if (ferror(stdout))
exit(1);
exit(0);
/* NOTREACHED */
}

View file

@ -3,7 +3,7 @@ MAN= ash.1 at.1 banner.1 basename.1 \
chmod.1 cmp.1 comm.1 compress.1 \
cp.1 crc.1 crontab.1 dd.1 \
df.1 dhrystone.1 dosdir.1 dosread.1 doswrite.1 \
dumpcore.1 echo.1 eject.1 \
dumpcore.1 eject.1 \
env.1 expand.1 expr.1 factor.1 \
finger.1 flexdoc.1 fold.1 format.1 fortune.1 \
fsck.mfs.1 head.1 host.1 hostaddr.1 ifdef.1 \

View file

@ -1,68 +0,0 @@
.TH ECHO 1
.SH NAME \" Copyright (C) 1989 by Kenneth Almquist.
echo \- produce message in a shell script
.SH SYNOPSIS
.B echo
[
.B -n
|
.B -e
]
.I args...
.SH DESCRIPTION
.I Echo
prints its arguments on the standard output, separated by spaces.
Unless the
.B -n
option is present, a newline is output following the arguments.
The
.B -e
option causes
.I echo
to treat the escape sequences specially, as described in the following
paragraph.
Only one of the options
.B -n
and
.B -e
may be given.
.PP
If any of the following sequences of characters is encountered during
output, the sequence is not output. Instead, the specified action is
performed:
.de i
.IP "\\fB\\$1\\fR" 5
..
.i \eb
A backspace character is output.
.i \ec
Subsequent output is suppressed. This is normally used at the end of the
last argument to suppress the trailing newline that
.I echo
would otherwise output.
.i \ef
Output a form feed.
.i \en
Output a newline character.
.i \er
Output a carriage return.
.i \et
Output a (horizontal) tab character.
.i \ev
Output a vertical tab.
.i \e0\fIdigits\fR
Output the character whose value is given by zero to three digits.
If there are zero digits, a nul character is output.
.i \e\e
Output a backslash.
.SH HINTS
Remember that backslash is special to the shell and needs to be escaped.
To output a message to standard error, say
.sp
.ti +1i
echo message >&2
.SH BUGS
The octal character escape mechanism (\e0\fIdigits\fR) differs from the
C language mechanism.
.SH AUTHOR
Kenneth Almquist.

View file

@ -8,6 +8,7 @@
# netbsdpath: path in BSD source tree (starting from src/)
2012/01/16 18:47:57,bin/cat
2011/08/27 12:55:09,bin/date
2012/10/17 12:00:00,bin/echo
2012/01/16 18:47:57,bin/ed
2012/10/17 12:00:00,bin/Makefile
2012/10/17 12:00:00,bin/Makefile.inc