=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/dc/stack.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- src/usr.bin/dc/stack.c 2003/10/18 20:34:26 1.4 +++ src/usr.bin/dc/stack.c 2003/11/04 08:10:06 1.5 @@ -1,4 +1,4 @@ -/* $OpenBSD: stack.c,v 1.4 2003/10/18 20:34:26 otto Exp $ */ +/* $OpenBSD: stack.c,v 1.5 2003/11/04 08:10:06 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek @@ -17,7 +17,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: stack.c,v 1.4 2003/10/18 20:34:26 otto Exp $"; +static const char rcsid[] = "$OpenBSD: stack.c,v 1.5 2003/11/04 08:10:06 otto Exp $"; #endif /* not lint */ #include @@ -114,6 +114,20 @@ return; } stack_push(stack, stack_dup_value(value, ©)); +} + +void +stack_swap(struct stack *stack) +{ + struct value copy; + + if (stack->sp < 1) { + warnx("stack empty"); + return; + } + copy = stack->stack[stack->sp]; + stack->stack[stack->sp] = stack->stack[stack->sp-1]; + stack->stack[stack->sp-1] = copy; } static void