From e6b16e56856f78377ad49244dc5f211043dba32a Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sun, 16 Oct 2016 15:16:00 -0400 Subject: Remove rpn.c --- .bin/rpn.c | 150 ------------------------------------------------------------- install.sh | 1 - 2 files changed, 151 deletions(-) delete mode 100755 .bin/rpn.c diff --git a/.bin/rpn.c b/.bin/rpn.c deleted file mode 100755 index 1d3bdaea..00000000 --- a/.bin/rpn.c +++ /dev/null @@ -1,150 +0,0 @@ -#if 0 -exec cc -Wall -Wextra $@ -ledit -o $(dirname $0)/rpn $0 -#endif - -#include -#include -#include -#include -#include -#include -#include - -static char *fmt(int radix, long val) { - static char buf[65]; - if (radix == 2) { - unsigned long u = val; - int i = sizeof(buf); - do { - buf[--i] = '0' + (u & 1); - } while (u >>= 1); - return &buf[i]; - } else if (radix == 8) { - snprintf(buf, sizeof(buf), "%lo", val); - } else if (radix == 10) { - snprintf(buf, sizeof(buf), "%ld", val); - } else if (radix == 16) { - snprintf(buf, sizeof(buf), "%lx", val); - } else abort(); - return buf; -} - -static struct { - long data[1024]; - size_t len; - int radix; - char op; -} stack = { .radix = 10 }; - -static void push(long val) { - stack.data[stack.len++] = val; - assert(stack.len < sizeof(stack.data)); -} - -static long pop(void) { - if (stack.len == 0) return 0; - return stack.data[--stack.len]; -} - -static bool stack_op(char op) { - if (stack.op == '@') { - stack.op = 0; - while (stack.len > 1) - stack_op(op); - return true; - } - if (stack.op == '\'') { - stack.op = 0; - push(op); - return true; - } - if (stack.op == '"') { - if (op == '"') stack.op = 0; - else push(op); - return true; - } - - long a, b; - switch (op) { - case '@': case '\'': case '"': stack.op = op; - break; case 'b': stack.radix = 2; - break; case 'o': stack.radix = 8; - break; case 'd': stack.radix = 10; - break; case 'x': stack.radix = 16; - break; case ';': a = pop(); - break; case ':': a = pop(); push(a); push(a); - break; case '\\': a = pop(); b = pop(); push(a); push(b); - break; case '_': a = pop(); push(-a); - break; case '+': a = pop(); push(pop() + a); - break; case '-': a = pop(); push(pop() - a); - break; case '*': a = pop(); push(pop() * a); - break; case '/': a = pop(); push(pop() / a); - break; case '%': a = pop(); push(pop() % a); - break; case '!': a = pop(); push(!a); - break; case '~': a = pop(); push(~a); - break; case '&': a = pop(); push(pop() & a); - break; case '|': a = pop(); push(pop() | a); - break; case '^': a = pop(); push(pop() ^ a); - break; case '<': a = pop(); push((unsigned long) pop() << a); - break; case '>': a = pop(); push((unsigned long) pop() >> a); - break; case '.': a = pop(); printf("%s\n", fmt(stack.radix, a)); - break; case ',': a = pop(); printf("%c\n", (char) a); - break; case ' ': - break; default: return false; - } - return true; -} - -static void process(const char *input) { - while (*input) { - if (stack_op(*input)) { - input++; - } else { - char *rest; - long val = strtol(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 "[] "; - - size_t q = 0; - for (size_t i = 0; i < stack.len; ++i) { - q += (size_t) snprintf(&p[q], sizeof(p) - 2 - q, " %s", fmt(stack.radix, stack.data[i])); - } - p[0] = '['; - p[q] = ']'; - p[++q] = ' '; - p[++q] = 0; - - return p; -} - -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); - - for (;;) { - int count; - const char *line = el_gets(el, &count); - if (count < 0) err(EX_IOERR, "el_gets"); - if (!line) break; - process(line); - } - - el_end(el); - return EX_OK; -} diff --git a/install.sh b/install.sh index fd0010c2..6e9a22ba 100755 --- a/install.sh +++ b/install.sh @@ -26,7 +26,6 @@ link .bin/manpager link .bin/pbcopy link .bin/pbd.c link .bin/pbpaste -link .bin/rpn.c link .bin/xx.c link .config/git/config link .config/git/ignore -- cgit 1.4.1 _CD in the remote sshd_config. 2020-10-07Use mandoc -T utf8 for text.June McEnroe Don't depend on LANG being set. 2020-09-20Add The Awakened KingdomJune McEnroe A cute extra novella. Finally finished this series. 2020-09-12Move /opt/local back, cheat port select to use system manJune McEnroe This is not really how you're supposed to use the select system, I don't think, since the mandoc package actually creates those files, but it does work. This lets me actually use the git installed by MacPorts. 2020-09-12Move /opt/local behind /usr againJune McEnroe The reason I did this with pkgsrc was because I actually don't want the man(1) from mandoc, since it won't follow MANSECT. Same applies to MacPorts. I wish I could disable its man(1) with a variant or whatever. 2020-09-12Enable toc in cgit renderings of man pagesJune McEnroe But keep it disabled for READMEs since they always use non-standard sections and the TOC is just distracting there, I think. Also add the style so its h1 is the same size as the ones inside sections... 2020-09-11Install mandoc on macOSJune McEnroe 2020-09-11Rewrite install script yet againJune McEnroe 2020-09-11Remove NetBSD from install scriptJune McEnroe I never use it. 2020-09-11Use MacPorts rather than pkgsrcJune McEnroe My system is probably such a mess now... 2020-09-11Add debian VM name to sshJune McEnroe 2020-09-11Add influencer tweetJune McEnroe 2020-09-10Add The Kingdom of GodsJune McEnroe Reading has really slowed down :( 2020-09-07Add SunglassesJune McEnroe An IRC find. 2020-09-06Add Between the BreathsJune McEnroe One of those good songs from a soundtrack of a film that probably isn't? The summary sounds a lot more interesting than the title implies, at least. 2020-09-04Open /dev/tty in nudgeJune McEnroe This makes it work even when it's run connected to a pipe, i.e. as the notify command of catgirl... 2020-09-04Add nudgeJune McEnroe 2020-09-03Build fbclock with -lzJune McEnroe I guess this got lost somewhere, long ago... 2020-08-29Add tweets from retweetsJune McEnroe