From 69a52453f852dfcc264e1b848b8bbf26dfc4b3d6 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Mon, 17 Nov 2003 11:12:36 +0000 Subject: A basic stack operation that is missing from the original dc (and GNU dc as well): drop ('R'). --- usr.bin/dc/bcode.c | 14 ++++++++++++-- usr.bin/dc/dc.1 | 5 ++++- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/dc/bcode.c b/usr.bin/dc/bcode.c index 2021a408d3d..86cb98a93a9 100644 --- a/usr.bin/dc/bcode.c +++ b/usr.bin/dc/bcode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bcode.c,v 1.16 2003/11/14 20:25:16 otto Exp $ */ +/* $OpenBSD: bcode.c,v 1.17 2003/11/17 11:12:35 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek @@ -17,7 +17,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: bcode.c,v 1.16 2003/11/14 20:25:16 otto Exp $"; +static const char rcsid[] = "$OpenBSD: bcode.c,v 1.17 2003/11/17 11:12:35 otto Exp $"; #endif /* not lint */ #include @@ -71,6 +71,7 @@ static void pop_printn(void); static __inline void print_stack(); static __inline void dup(void); static void swap(void); +static void drop(void); static void get_scale(void); static void set_scale(void); @@ -179,6 +180,7 @@ static const struct jump_entry jump_table_data[] = { { 'O', get_obase }, { 'P', pop_print }, { 'Q', quitN }, + { 'R', drop }, { 'S', store_stack }, { 'X', push_scale }, { 'Z', num_digits }, @@ -515,6 +517,14 @@ swap(void) stack_swap(&bmachine.stack); } +static void +drop(void) +{ + struct value *v = pop(); + if (v != NULL) + stack_free_value(v); +} + static void get_scale(void) { diff --git a/usr.bin/dc/dc.1 b/usr.bin/dc/dc.1 index 58c4696d169..34beefe403a 100644 --- a/usr.bin/dc/dc.1 +++ b/usr.bin/dc/dc.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: dc.1,v 1.16 2003/11/14 20:25:16 otto Exp $ +.\" $OpenBSD: dc.1,v 1.17 2003/11/17 11:12:35 otto Exp $ .\" .\" Copyright (C) Caldera International Inc. 2001-2002. .\" All rights reserved. @@ -243,6 +243,9 @@ by that value. Exits the program. If executing a string, the recursion level is popped by two. +.It Ic R +The top of the stack is removed (popped). +This is a non-portable extension. .It Ic r The top two values on the stack are reversed (swapped). This is a non-portable extension. -- cgit v1.2.3