summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-x.bin/rpn.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/.bin/rpn.c b/.bin/rpn.c
index d5be9cbf..9a88298b 100755
--- a/.bin/rpn.c
+++ b/.bin/rpn.c
@@ -97,6 +97,21 @@ static bool stack_op(char op) {
     return true;
 }
 
+static void process(const char *input) {
+    while (*input) {
+        if (stack_op(*input)) {
+            input++;
+        } else {
+            char *rest;
+            int64_t val = strtoll(input, &rest, stack.radix);
+            if (rest != input) {
+                input = rest;
+                push(val);
+            } else input++;
+        }
+    }
+}
+
 static char *prompt(EditLine *el __attribute((unused))) {
     static char p[4096];
     if (stack.len == 0) return "[] ";
@@ -113,7 +128,13 @@ static char *prompt(EditLine *el __attribute((unused))) {
     return p;
 }
 
-int main(int argc __attribute((unused)), char *argv[]) {
+int main(int argc, char *argv[]) {
+    if (argc > 1) {
+        for (int i = 1; i < argc; ++i)
+            process(argv[i]);
+        return EX_OK;
+    }
+
     EditLine *el = el_init(argv[0], stdin, stdout, stderr);
     el_set(el, EL_PROMPT, prompt);
     el_set(el, EL_SIGNAL, true);
@@ -123,19 +144,7 @@ int main(int argc __attribute((unused)), char *argv[]) {
         const char *line = el_gets(el, &count);
         if (count < 0) err(EX_IOERR, "el_gets");
         if (!line) break;
-
-        while (*line) {
-            if (stack_op(*line)) {
-                line++;
-            } else {
-                char *rest;
-                int64_t val = strtoll(line, &rest, stack.radix);
-                if (rest != line) {
-                    line = rest;
-                    push(val);
-                } else line++;
-            }
-        }
+        process(line);
     }
 
     el_end(el);
d>Disable menu bar in GVimJune McEnroe 2012-01-30Set shiftwidth to 4 for LuaJune McEnroe 2012-01-29Don't show Syntastic errors automaticallyJune McEnroe 2012-01-28Update to Quicktask 1.1June McEnroe 2012-01-22Use space-test branch of quicktaskJune McEnroe 2012-01-22Enable syntax-based foldingJune McEnroe 2012-01-22Update quicktaskJune McEnroe 2012-01-22Revert "Add AutoClose"June McEnroe 2012-01-22Revert "Disable powerline for now"June McEnroe 2012-01-22Revert "Add VCS repo directories to wildignore"June McEnroe 2012-01-22Disable powerline for nowJune McEnroe 2012-01-22Update some pluginsJune McEnroe 2012-01-22Add VCS repo directories to wildignoreJune McEnroe 2012-01-22Map ,e and ,b to CtrlP file and buffer respectivelyJune McEnroe 2012-01-22Add vim-spaceJune McEnroe 2012-01-22Add AutoCloseJune McEnroe 2012-01-22Add binding for GundoJune McEnroe 2012-01-22Add GundoJune McEnroe 2012-01-22Add Jellybeans colorschemeJune McEnroe 2012-01-22Add syntasticJune McEnroe 2012-01-21Add PowerlineJune McEnroe 2012-01-21Add quicktaskJune McEnroe 2012-01-15Moved comments out of mapsJune McEnroe 2012-01-14Disable scrollbarsJune McEnroe