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);
=71a18bd0d47ba9586a73e4ff02749aa5784b3151&follow=1'>Fix comparison warning in ttpreJune McEnroe 2019-05-20Add AuthorityJune McEnroe 2019-05-19Specify precedence of unary versions of operatorsJune McEnroe 2019-05-18Add compound assignment operators to orderJune McEnroe 2019-05-15Support simple assignment in orderJune McEnroe 2019-05-15Implement sizeof in orderJune McEnroe 2019-05-15Add orderJune McEnroe 2019-05-12Add T suffix in bitJune McEnroe 2019-05-10Highlight yacc and lex files as CJune McEnroe 2019-05-10Use val instead of suboptargJune McEnroe 2019-05-09Add Parable of the SowerJune McEnroe 2019-05-07Add bit without buildJune McEnroe 2019-05-04Fix MANDIR typoJune McEnroe 2019-05-04Move relay to binJune McEnroeize this out anyway. 2013-03-20cgit.mk: Use SHELL_PATH_SQ to run gen-version.shJohn Keeping On some platforms (notably Solaris) /bin/sh doesn't support enough of POSIX for gen-version.sh to run. Git's Makefile provides SHELL_PATH_SQ to address this issue so we just have to use it. Signed-off-by: John Keeping <john@keeping.me.uk> 2013-03-20cgit.mk: don't rebuild everything if CGIT_VERSION changesJohn Keeping If CGIT_VERSION is in CGIT_CFLAGS then a change in version (for example because you have committed your changes) causes all of the CGit objects to be rebuilt. Avoid this by using EXTRA_CPPFLAGS to add the version for only those files that are affected and make them depend on VERSION. Signed-off-by: John Keeping <john@keeping.me.uk> 2013-03-20ui-patch: use cgit_version not CGIT_VERSIONJohn Keeping We already have a global cgit_version which is set from the #define'd CGIT_VERSION in cgit.c. Change ui-patch.c to use this so that we only need to rebuild cgit.o when the version changes. Signed-off-by: John Keeping <john@keeping.me.uk> 2013-03-20Makefile: re-use Git's Makefile where possibleJohn Keeping