oetiker/rrdtool-1.x — pull request #466 by sshipway (2014-05-07 22:16:43+00:00)
Title: Adding new RPN stack operations: DEPTH, INDEX, COPY, ROLL

My first attempt to create a github pull request. Hope it works.
I've made the RPN operations patch changes to a github repository fork and submitted them this way...

This adds four new RPN operations: DEPTH, COPY, INDEX, ROLL

*DEPTH*: push the number of stack elements onto the stack
```
a,b,c,DEPTH ==> a,b,c,3
```
*COPY*: pop the top value from the stack. Copy that number of elements on the stack. So, DUP is the same as 1,COPY
```
a,b,c,2,COPY ==> a,b,c,b,c
```
*INDEX*: identify the item that far down the stack and copy it onto the top of the stack (1-based). So, DUP is the same as 1,INDEX
```
a,b,c,d,e,2,INDEX ==> a,b,c,d,e,d
```
*ROLL*: rotate the top n items by s steps (can be positive or negative) So EXCH is the same as 2,1,ROLL or 2,-1,ROLL
```
a,b,c,d,e,3,-1,ROLL ==> a,b,d,e,c
```

This should allow much more extensive stack manipulation. Stack underflow and overflow are handled.