summaryrefslogtreecommitdiffhomepage
path: root/auto/echo
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2017-01-17 20:00:00 +0300
committerIgor Sysoev <igor@sysoev.ru>2017-01-17 20:00:00 +0300
commit16cbf3c076a0aca6d47adaf3f719493674cf2363 (patch)
treee6530480020f62a2bdbf249988ec3e2a751d3927 /auto/echo
downloadunit-16cbf3c076a0aca6d47adaf3f719493674cf2363.tar.gz
unit-16cbf3c076a0aca6d47adaf3f719493674cf2363.tar.bz2
Initial version.
Diffstat (limited to 'auto/echo')
-rw-r--r--auto/echo/Makefile3
-rw-r--r--auto/echo/build26
-rw-r--r--auto/echo/echo.c43
3 files changed, 72 insertions, 0 deletions
diff --git a/auto/echo/Makefile b/auto/echo/Makefile
new file mode 100644
index 00000000..28a519c3
--- /dev/null
+++ b/auto/echo/Makefile
@@ -0,0 +1,3 @@
+
+echo.exe: echo.c
+ mingw32-gcc -o echo.exe -O2 echo.c
diff --git a/auto/echo/build b/auto/echo/build
new file mode 100644
index 00000000..10670f74
--- /dev/null
+++ b/auto/echo/build
@@ -0,0 +1,26 @@
+
+# Copyright (C) Igor Sysoev
+# Copyright (C) NGINX, Inc.
+
+
+$echo 'building an "echo" program'
+
+rm -f $NXT_BUILD_DIR/echo
+
+nxt_echo_test="$CC -o $NXT_BUILD_DIR/echo -O $NXT_CC_OPT
+ auto/echo/echo.c $NXT_LD_OPT"
+
+nxt_echo_err=`$nxt_echo_test 2>&1`
+
+if [ ! -x $NXT_BUILD_DIR/echo ]; then
+ $echo
+ $echo $0: error: cannot build an \"echo\" program:
+ $echo
+ $echo $nxt_echo_test
+ $echo
+ $echo $nxt_echo_err
+ $echo
+ exit 1
+fi
+
+echo=$NXT_BUILD_DIR/echo
diff --git a/auto/echo/echo.c b/auto/echo/echo.c
new file mode 100644
index 00000000..937483af
--- /dev/null
+++ b/auto/echo/echo.c
@@ -0,0 +1,43 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ * Copyright (C) NGINX, Inc.
+ *
+ * A portable "echo" program that supports "-n" option:
+ * echo Hello world!
+ * echo "Hello world!"
+ * echo -n Hello world!
+ * echo
+ *
+ * It also passes "\c" characters as is.
+ */
+
+
+#include <stdio.h>
+#include <string.h>
+
+
+int
+main(int argc, char *const *argv)
+{
+ int i = 1;
+ int nl = 1;
+
+ if (argc > 1) {
+ if (strcmp(argv[1], "-n") == 0) {
+ nl = 0;
+ i++;
+ }
+
+ while (i < argc) {
+ printf("%s%s", argv[i], (i == argc - 1) ? "" : " ");
+ i++;
+ }
+ }
+
+ if (nl) {
+ printf("\n");
+ }
+
+ return 0;
+}