summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <curtis.mcenroe@adgear.com>2016-10-04 12:44:16 -0400
committerJune McEnroe <curtis.mcenroe@adgear.com>2016-10-04 12:44:46 -0400
commit88d2ac66ccfe3f433315ab448802a52da05a3b59 (patch)
tree1c582f4c61f4e77e47d769bb05ccdddabc16b7d8
parentTry ops first in rpn (diff)
downloadsrc-88d2ac66ccfe3f433315ab448802a52da05a3b59.tar.gz
src-88d2ac66ccfe3f433315ab448802a52da05a3b59.zip
Add quoting to rpn
-rwxr-xr-x.bin/rpn.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/.bin/rpn.c b/.bin/rpn.c
index 0fcf7933..d3fe0667 100755
--- a/.bin/rpn.c
+++ b/.bin/rpn.c
@@ -35,6 +35,7 @@ static struct {
     int64_t data[1024];
     size_t len;
     int radix;
+    char op;
 } stack = { .radix = 10 };
 
 static void push(int64_t val) {
@@ -48,6 +49,19 @@ static int64_t pop(void) {
 }
 
 static bool stack_op(char op) {
+    if (stack.op == '\'') {
+        push(op);
+        stack.op = 0;
+        return true;
+    }
+    if (stack.op == '"') {
+        if (op == '"')
+            stack.op = 0;
+        else
+            push(op);
+        return true;
+    }
+
     int64_t a, b;
     switch (op) {
         case '$': pop();
@@ -71,6 +85,7 @@ static bool stack_op(char op) {
         break; case 'o': stack.radix = 8;
         break; case 'd': stack.radix = 10;
         break; case 'x': stack.radix = 16;
+        break; case '\'': case '"': stack.op = op;
         break; default: return false;
     }
     return true;