summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2017-02-23 06:40:17 +0000
committerotto <otto@openbsd.org>2017-02-23 06:40:17 +0000
commit1b843d51ddae45a23a2231f82eb00b246d10943f (patch)
treef5e59748a0e0f612aa207e175b6366848991d00b
parentbe nicer to 32bit strict alignment archs that can do 64bit loads/stores. (diff)
downloadwireguard-openbsd-1b843d51ddae45a23a2231f82eb00b246d10943f.tar.xz
wireguard-openbsd-1b843d51ddae45a23a2231f82eb00b246d10943f.zip
Introduce e command, equivalent to p, but writes to stderr
-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