coreutils

General Software Utilities
git clone http://git.omkov.net/coreutils
Log | Tree | Refs | README | LICENCE | Download

AuthorJamozed <[email protected]>
Date2020-06-26 04:58:05
Commitba7d1e07caa6a6caa403fd4668912e21fbc8d6ee
Parentfe244531940bfab39ac3472a689af6a3c90cd1f9

echo: Add POSIX echo

Diffstat

M CMakeLists.txt | 1 +
M README.md | 1 +
A man/echo.1 | 22 ++++++++++++++++++++++
A src/echo.c | 26 ++++++++++++++++++++++++++

4 files changed, 50 insertions, 0 deletions

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3869543..1e05d39 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,5 +13,6 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/ext)
 ADD_EXECUTABLE(basename ${CMAKE_SOURCE_DIR}/src/basename.c)
 ADD_EXECUTABLE(cat      ${CMAKE_SOURCE_DIR}/src/cat.c)
 ADD_EXECUTABLE(dirname  ${CMAKE_SOURCE_DIR}/src/dirname.c)
+ADD_EXECUTABLE(echo     ${CMAKE_SOURCE_DIR}/src/echo.c)
 ADD_EXECUTABLE(false    ${CMAKE_SOURCE_DIR}/src/false.c)
 ADD_EXECUTABLE(true     ${CMAKE_SOURCE_DIR}/src/true.c)
diff --git a/README.md b/README.md
index f593066..0ba8b2e 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,7 @@ commonly found on UNIX-like systems.
 | basename         | Return non-directory portion of a path   | POSIX    |
 | cat              | Concatenate and print files              | POSIX    |
 | dirname          | Return the directory portion of a path   | POSIX    |
+| echo             | Write arguments to standard output       | POSIX    |
 | false            | Return false value                       | POSIX    |
 | true             | Return true value                        | POSIX    |
 
diff --git a/man/echo.1 b/man/echo.1
new file mode 100644
index 0000000..9d33dd3
--- /dev/null
+++ b/man/echo.1
@@ -0,0 +1,22 @@
+.TH ECHO 1 2020-06-26 "OMKOV coreutils" "General Commands Manual"
+.SH NAME
+echo \(em write arguments to standard output
+.SH SYNOPSYS
+\fBecho\fR [\fIstring\fR...]
+.SH DESCRIPTION
+Write arguments to standard output, seperated by a single space and followed by
+a newline.
+.SH OPERANDS
+The following operand is supported:
+.TP
+.I string
+A string to be written to standard output.
+.SH STANDARDS
+The \fIecho\fR utility is compliant with the IEEE Std 1003.2-1992 ("POSIX.2")
+specification.
+.SH COPYRIGHT
+.nf
+Copyright (C) 2020, Jakob Wakeling
+All rights reserved.
+OMKOV Public Domain Licence (https://www.omkov.net/OLPD)
+.fi
diff --git a/src/echo.c b/src/echo.c
new file mode 100644
index 0000000..ee0cf19
--- /dev/null
+++ b/src/echo.c
@@ -0,0 +1,26 @@
+// echo.c, version 1.0.0
+// OMKOV coreutils implementation of POSIX echo
+// Copyright (C) 2020, Jakob Wakeling
+// All rights reserved.
+
+/*
+OMKOV Public Domain Licence, version 1.0
+
+Permission is hereby granted to deal with this software and its associated
+documentation files without restriction.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT
+HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
+*/
+
+#include <stdio.h>
+
+int main(int argc, char *argv[]) {
+	register char **p = &argv[1]; if (*p) { fputs(*p, stdout);
+		for (++p; *p; ++p) { fputc(' ', stdout); fputs(*p, stdout); }
+	} fputc('\n', stdout); return 0;
+}