summaryrefslogtreecommitdiff
path: root/usr.bin/dc
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2017-02-23 06:40:18 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2017-02-23 06:40:18 +0000
commitacd8d88de2de6e987af42b9951b7bcc232421a0c (patch)
tree03faa00ff5fee3697bdb80eb895cfb75bbd79fa7 /usr.bin/dc
parentd39cf144e2d108c30aaa4a6b99c9805430d43c67 (diff)
Introduce e command, equivalent to p, but writes to stderr
Diffstat (limited to 'usr.bin/dc')
-rw-r--r--usr.bin/dc/bcode.c16
-rw-r--r--usr.bin/dc/dc.18
2 files changed, 21 insertions, 3 deletions
diff --git a/usr.bin/dc/bcode.c b/usr.bin/dc/bcode.c
index 1e416967b75..8e50c1e8037 100644
--- a/usr.bin/dc/bcode.c
+++ b/usr.bin/dc/bcode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bcode.c,v 1.49 2016/03/27 15:55:13 otto Exp $ */
+/* $OpenBSD: bcode.c,v 1.50 2017/02/23 06:40:17 otto Exp $ */
/*
* Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
@@ -67,6 +67,7 @@ static __inline struct number *pop_number(void);
static __inline char *pop_string(void);
static __inline void clear_stack(void);
static __inline void print_tos(void);
+static void print_err(void);
static void pop_print(void);
static void pop_printn(void);
static __inline void print_stack(void);
@@ -195,6 +196,7 @@ static const struct jump_entry jump_table_data[] = {
{ 'a', to_ascii },
{ 'c', clear_stack },
{ 'd', dup },
+ { 'e', print_err },
{ 'f', print_stack },
{ 'i', set_ibase },
{ 'k', set_scale },
@@ -497,6 +499,18 @@ print_tos(void)
}
static void
+print_err(void)
+{
+ struct value *value = tos();
+ if (value != NULL) {
+ print_value(stderr, value, "", bmachine.obase);
+ (void)putc('\n', stderr);
+ }
+ else
+ warnx("stack empty");
+}
+
+static void
pop_print(void)
{
struct value *value = pop();
diff --git a/usr.bin/dc/dc.1 b/usr.bin/dc/dc.1
index 4e35c0e9db6..8c2a4d1a7c7 100644
--- a/usr.bin/dc/dc.1
+++ b/usr.bin/dc/dc.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: dc.1,v 1.29 2016/12/10 21:13:25 schwarze Exp $
+.\" $OpenBSD: dc.1,v 1.30 2017/02/23 06:40:17 otto Exp $
.\"
.\" Copyright (C) Caldera International Inc. 2001-2002.
.\" All rights reserved.
@@ -34,7 +34,7 @@
.\"
.\" @(#)dc.1 8.1 (Berkeley) 6/6/93
.\"
-.Dd $Mdocdate: December 10 2016 $
+.Dd $Mdocdate: February 23 2017 $
.Dt DC 1
.Os
.Sh NAME
@@ -185,6 +185,10 @@ operator is a non-portable extension.
All values on the stack are popped.
.It Ic d
The top value on the stack is duplicated.
+.It Ic e
+Equivalent to
+.Ic p ,
+except that the output is written to the standard error stream.
.It Ic f
All values on the stack are printed, separated by newlines.
.It Ic G