Like I've said before, I'm trying not to flood Rob with patches. And poking 
about the
larger todo items every week wouldn't be helpful to anybody. So here's some of 
the smaller
patches that are >1 week old:

UTF-8 Handling Patchs:
http://lists.landley.net/pipermail/toybox-landley.net/2024-April/030285.html -- 
Comment Change in utf8towc()
http://lists.landley.net/pipermail/toybox-landley.net/2024-April/030290.html -- 
Swap out old UTF8 conversion function with wctoutf8()
A note on this: wctoutf8 has a bug where if you give MAX_INT it writes one 0xff 
byte, actual invalid UTF-8. I've touched lib.c
enough in these patches that I don't wanna create merge conflicts by submitting 
yet another lib.c patch
(http://lists.landley.net/pipermail/toybox-landley.net/2024-April/030293.html)

Config system:
http://lists.landley.net/pipermail/toybox-landley.net/2024-April/030289.html -- 
Add config symbols so "make ipsubcmd" works
http://lists.landley.net/pipermail/toybox-landley.net/2024-April/030291.html -- 
Fix some single command Builds (The "make ipsubcmd" problem)

I also submitted another bc.c cleanup patch that removes the -w and -s options, 
and shrinks the codebase by about 400 lines I think.
I can't dig it up on the list archive, so it's attached.

-   Oliver Webb <aquahobby...@proton.me>

From 0ab688638da60fb2275f3a09cc698bc342c47671 Mon Sep 17 00:00:00 2001
From: Oliver Webb <aquahobby...@proton.me>
Date: Sun, 24 Mar 2024 21:27:17 -0500
Subject: [PATCH] bc: Get rid of -s and -w and the code for it, unneeded
 parentheses in case statements, CHAR_MAX, move data closer to code,
 formatting

---
 toys/pending/bc.c | 589 ++++++++--------------------------------------
 1 file changed, 103 insertions(+), 486 deletions(-)

diff --git a/toys/pending/bc.c b/toys/pending/bc.c
index 2a47bf92..fdb4e37b 100644
--- a/toys/pending/bc.c
+++ b/toys/pending/bc.c
@@ -27,8 +27,6 @@ config BC
                          j(n, x)  =  Bessel function of integer order n of x
 
       -q  --quiet        don't print version and copyright
-      -s  --standard     error if any non-POSIX extensions are used
-      -w  --warn         warn if any non-POSIX extensions are used
 
 */
 
@@ -41,7 +39,7 @@ GLOBALS(
   char *vm;
 
   size_t nchars;
-  char *file, sig, max_ibase;
+  char *file, sig;
   uint16_t line_len;
 )
 
@@ -53,7 +51,6 @@ struct str_len {
 #define BC_VM ((BcVm*) TT.vm)
 
 typedef enum BcStatus {
-
   BC_STATUS_SUCCESS = 0,
   BC_STATUS_ERROR,
   BC_STATUS_EOF,
@@ -63,8 +60,7 @@ typedef enum BcStatus {
 
 } BcStatus;
 
-typedef enum BcError {
-
+enum BcError {
   BC_ERROR_VM_ALLOC_ERR,
   BC_ERROR_VM_IO_ERR,
   BC_ERROR_VM_BIN_FILE,
@@ -105,29 +101,12 @@ typedef enum BcError {
   BC_ERROR_EXEC_UNDEF_FUNC,
   BC_ERROR_EXEC_VOID_VAL,
 
-  BC_ERROR_POSIX_START,
-
-  BC_ERROR_POSIX_NAME_LEN = BC_ERROR_POSIX_START,
-  BC_ERROR_POSIX_COMMENT,
-  BC_ERROR_POSIX_KW,
-  BC_ERROR_POSIX_DOT,
-  BC_ERROR_POSIX_RET,
-  BC_ERROR_POSIX_BOOL,
-  BC_ERROR_POSIX_REL_POS,
-  BC_ERROR_POSIX_MULTIREL,
-  BC_ERROR_POSIX_FOR1,
-  BC_ERROR_POSIX_FOR2,
-  BC_ERROR_POSIX_FOR3,
-  BC_ERROR_POSIX_BRACE,
-  BC_ERROR_POSIX_REF,
-
 } BcError;
 
 #define BC_ERR_IDX_VM (0)
 #define BC_ERR_IDX_PARSE (1)
 #define BC_ERR_IDX_MATH (2)
 #define BC_ERR_IDX_EXEC (3)
-#define BC_ERR_IDX_POSIX (4)
 
 #define BC_VEC_START_CAP (1<<5)
 
@@ -154,7 +133,7 @@ typedef struct BcNum {
 
 // A crude, but always big enough, calculation of
 // the size required for ibase and obase BcNum's.
-#define BC_NUM_LONG_LOG10 ((CHAR_BIT * sizeof(unsigned long) + 1) / 2 + 1)
+#define BC_NUM_LONG_LOG10 ((8 * sizeof(long) + 1) / 2 + 1)
 
 #define BC_NUM_NEG(n, neg) ((((ssize_t) (n)) ^ -((ssize_t) (neg))) + (neg))
 
@@ -329,7 +308,6 @@ int bc_id_cmp(struct str_len *e1, struct str_len *e2);
 
 // BC_LEX_NEG is not used in lexing; it is only for parsing.
 typedef enum BcLexType {
-
   BC_LEX_EOF,
   BC_LEX_INVALID,
 
@@ -464,15 +442,8 @@ typedef struct BcLexKeyword {
 
 #define BC_LEX_CHAR_MSB(bit) ((bit) << (CHAR_BIT - 1))
 
-#define BC_LEX_KW_POSIX(kw) ((kw)->data & (BC_LEX_CHAR_MSB(1)))
 #define BC_LEX_KW_LEN(kw) ((size_t) ((kw)->data & ~(BC_LEX_CHAR_MSB(1))))
 
-#define BC_LEX_KW_ENTRY(a, b, c) \
-  { .data = ((b) & ~(BC_LEX_CHAR_MSB(1))) | BC_LEX_CHAR_MSB(c),.name = a }
-
-#define bc_lex_posixErr(l, e) (bc_vm_posixError((e), (l)->line))
-#define bc_lex_vposixErr(l, e, ...) \
-  (bc_vm_posixError((e), (l)->line, __VA_ARGS__))
 
 BcStatus bc_lex_token(BcLex *l);
 
@@ -514,7 +485,6 @@ BcStatus bc_lex_token(BcLex *l);
 #define BC_PARSE_BLOCK_STMT(f) \
   ((f) & (BC_PARSE_FLAG_ELSE | BC_PARSE_FLAG_LOOP_INNER))
 
-#define BC_PARSE_OP(p, l) (((p) & ~(BC_LEX_CHAR_MSB(1))) | (BC_LEX_CHAR_MSB(l)))
 
 #define BC_PARSE_OP_DATA(t) bc_parse_ops[((t) - BC_LEX_OP_INC)]
 #define BC_PARSE_OP_LEFT(op) (BC_PARSE_OP_DATA(op) & BC_LEX_CHAR_MSB(1))
@@ -535,10 +505,8 @@ BcStatus bc_lex_token(BcLex *l);
 // the first in the expr enum. Note: This only works for binary operators.
 #define BC_PARSE_TOKEN_INST(t) ((char) ((t) - BC_LEX_NEG + BC_INST_NEG))
 
-#define bc_parse_posixErr(p, e) (bc_vm_posixError((e), (p)->l.line))
-
 BcStatus bc_parse_parse(BcParse *p);
-BcStatus bc_parse_expr_status(BcParse *p, uint8_t flags, BcParseNext next);
+BcStatus bc_parse_expr_status(BcParse *p, char flags, BcParseNext next);
 void bc_parse_noElse(BcParse *p);
 
 #define BC_PROG_ONE_CAP (1)
@@ -593,17 +561,12 @@ unsigned long bc_program_len(BcNum *n);
 void bc_program_negate(BcResult *r, BcNum *n);
 void bc_program_not(BcResult *r, BcNum *n);
 
-#define BC_FLAG_TTYIN (1<<7)
-#define BC_TTYIN (toys.optflags & BC_FLAG_TTYIN)
-
 #define BC_MAX_OBASE ((unsigned long) INT_MAX)
 #define BC_MAX_DIM ((unsigned long) INT_MAX)
 #define BC_MAX_SCALE ((unsigned long) UINT_MAX)
 #define BC_MAX_STRING ((unsigned long) UINT_MAX - 1)
 #define BC_MAX_NAME BC_MAX_STRING
 #define BC_MAX_NUM BC_MAX_STRING
-#define BC_MAX_EXP ((unsigned long) ULONG_MAX)
-#define BC_MAX_VARS ((unsigned long) SIZE_MAX - 1)
 
 #define bc_vm_err(e) (bc_vm_error((e), 0))
 #define bc_vm_verr(e, ...) (bc_vm_error((e), 0, __VA_ARGS__))
@@ -613,27 +576,15 @@ typedef struct BcVm {
   BcProgram prog;
 } BcVm;
 
-BcStatus bc_vm_posixError(BcError e, size_t line, ...);
-
-BcStatus bc_vm_error(BcError e, size_t line, ...);
+BcStatus bc_vm_error(enum BcError e, size_t line, ...);
 
 char bc_sig_msg[] = "\ninterrupt (type \"quit\" to exit)\n";
 
-char bc_copyright[] =
-  "Copyright (c) 2018 Gavin D. Howard and contributors\n"
-  "Report bugs at: https://github.com/gavinhoward/bc\n\n";
-  "This is free software with ABSOLUTELY NO WARRANTY.\n";
-
-char *bc_err_fmt = "\n%s error: ";
-char *bc_warn_fmt = "\n%s warning: ";
-char *bc_err_line = ":%zu";
-
 char *bc_errs[] = {
   "VM",
   "Parse",
   "Math",
   "Runtime",
-  "POSIX",
 };
 
 char bc_err_ids[] = {
@@ -647,10 +598,6 @@ char bc_err_ids[] = {
   BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
   BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
   BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
-  BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX,
-  BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX,
-  BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX, BC_ERR_IDX_POSIX,
-  BC_ERR_IDX_POSIX,
 };
 
 char *bc_err_msgs[] = {
@@ -695,26 +642,13 @@ char *bc_err_msgs[] = {
   "mismatched parameters; need %zu, have %zu",
   "undefined function: %s()",
   "cannot use a void value in an expression",
-
-  "POSIX does not allow names longer than 1 character, like \"%s\"",
-  "POSIX does not allow '#' script comments",
-  "POSIX does not allow \"%s\" as a keyword",
-  "POSIX does not allow a period ('.') as a shortcut for the last result",
-  "POSIX requires parentheses around return expressions",
-  "POSIX does not allow the \"%s\" operators",
-  "POSIX does not allow comparison operators outside if or loops",
-  "POSIX requires zero or one comparison operator per condition",
-  "POSIX does not allow an empty init expression in a for loop",
-  "POSIX does not allow an empty condition expression in a for loop",
-  "POSIX does not allow an empty update expression in a for loop",
-  "POSIX requires the left brace be on the same line as the function header",
-  "POSIX does not allow array references as function parameters",
-
 };
 
 char bc_func_main[] = "(main)";
 char bc_func_read[] = "(read)";
 
+#define BC_LEX_KW_ENTRY(a, b, c) \
+  { .data = ((b) & ~(BC_LEX_CHAR_MSB(1))) | BC_LEX_CHAR_MSB(c),.name = a }
 BcLexKeyword bc_lex_kws[] = {
   BC_LEX_KW_ENTRY("auto", 4, 1),
   BC_LEX_KW_ENTRY("break", 5, 1),
@@ -741,9 +675,8 @@ BcLexKeyword bc_lex_kws[] = {
 
 size_t bc_lex_kws_len = sizeof(bc_lex_kws) / sizeof(BcLexKeyword);
 
-char *bc_parse_const1 = "1";
-
 // This is an array of data for operators that correspond to token types.
+#define BC_PARSE_OP(p, l) (((p) & ~(BC_LEX_CHAR_MSB(1))) | (BC_LEX_CHAR_MSB(l)))
 char bc_parse_ops[] = {
   BC_PARSE_OP(0, 0), BC_PARSE_OP(0, 0),
   BC_PARSE_OP(1, 0), BC_PARSE_OP(1, 0),
@@ -771,8 +704,6 @@ BcParseNext bc_parse_next_for = BC_PARSE_NEXT(1, BC_LEX_SCOLON);
 BcParseNext bc_parse_next_read =
   BC_PARSE_NEXT(2, BC_LEX_NLINE, BC_LEX_EOF);
 
-char bc_num_hex_digits[] = "0123456789ABCDEF";
-
 BcNumBinaryOp bc_program_ops[] = {
   bc_num_pow, bc_num_mul, bc_num_div, bc_num_mod, bc_num_add, bc_num_sub,
 };
@@ -788,8 +719,6 @@ BcProgramUnary bc_program_unarys[] = {
 
 char bc_program_ready_msg[] = "ready for more input\n";
 
-char *bc_lib_name = "gen/lib.bc";
-
 char *bc_lib =
 "scale=20;\n"
 
@@ -999,9 +928,9 @@ void bc_vec_pushIndex(BcVec *v, size_t idx) {
   char amt, nums[sizeof(size_t)];
 
   for (amt = 0; idx; ++amt) {
-    nums[amt] = (char) idx;
-    idx &= ((size_t) ~(UCHAR_MAX));
-    idx >>= sizeof(char) * CHAR_BIT;
+    nums[amt] = idx;
+    idx &= ((size_t) ~(255));
+    idx >>= 8;
   }
 
   bc_vec_push(v, &amt);
@@ -1116,7 +1045,7 @@ BcStatus bc_read_chars(BcVec *vec, char *prompt) {
 
   bc_vec_npop(vec, vec->len);
 
-  if (BC_TTYIN && !FLAG(s)) {
+  if (FLAG(i) && !FLAG(s)) {
     fputs(prompt, stderr);
     fflush(stderr);
   }
@@ -1133,7 +1062,7 @@ BcStatus bc_read_chars(BcVec *vec, char *prompt) {
 
         TT.sig = 0;
 
-        if (BC_TTYIN) {
+        if (FLAG(i)) {
           fputs(bc_program_ready_msg, stderr);
           if (!FLAG(s)) fputs(prompt, stderr);
           fflush(stderr);
@@ -1174,7 +1103,7 @@ BcStatus bc_read_line(BcVec *vec, char *prompt) {
 
 BcStatus bc_read_file(char *path, char **buf) {
 
-  BcError e = BC_ERROR_VM_IO_ERR;
+  enum BcError e = BC_ERROR_VM_IO_ERR;
   FILE *f;
   size_t size, read;
   long res;
@@ -1576,7 +1505,7 @@ static BcStatus bc_num_k(BcNum *a, BcNum *b, BcNum *c) {
       carry = 0;
 
       for (j = 0; !TT.sig && j < a->len; ++j) {
-        unsigned int in = (char) ptr[j];
+        unsigned int in = ptr[j];
         in += ((unsigned int) a->num[j]) * ((unsigned int) b->num[i]);
         carry = bc_num_addDigit(ptr + j, in, carry);
       }
@@ -2008,7 +1937,7 @@ static void bc_num_printDigits(size_t n, size_t len, int rdx) {
     bc_num_printNewline();
     dig = n / pow;
     n -= dig * pow;
-    putchar(((char) dig) + '0');
+    putchar(dig + '0');
   }
 }
 
@@ -2021,7 +1950,7 @@ static void bc_num_printHex(size_t n, size_t len, int rdx) {
   }
 
   bc_num_printNewline();
-  putchar(bc_num_hex_digits[n]);
+  putchar("0123456789ABCDEF"[n]);
   TT.nchars += len;
 }
 
@@ -2051,7 +1980,7 @@ static BcStatus bc_num_printNum(BcNum *n, BcNum *base,
     return BC_STATUS_SUCCESS;
   }
 
-  bc_vec_init(&stack, sizeof(unsigned long), NULL);
+  bc_vec_init(&stack, sizeof(long), NULL);
   bc_num_init(&fracp, n->rdx);
   bc_num_init(&digit, len);
   bc_num_init(&frac_len, BC_NUM_INT(n));
@@ -2222,7 +2151,7 @@ BcStatus bc_num_ulong(BcNum *n, unsigned long *result) {
     if (prev == SIZE_MAX || prev / 10 != r)
       return bc_vm_err(BC_ERROR_MATH_OVERFLOW);
 
-    r = prev + ((char) n->num[--i]);
+    r = prev + (n->num[--i]);
 
     if (r == SIZE_MAX || r < prev) return bc_vm_err(BC_ERROR_MATH_OVERFLOW);
   }
@@ -2443,7 +2372,7 @@ BcStatus bc_func_insert(BcFunc *f, char *name, BcType type, size_t line) {
 }
 
 void bc_func_init(BcFunc *f, char *name) {
-  bc_vec_init(&f->code, sizeof(char), NULL);
+  bc_vec_init(&f->code, 1, NULL);
   bc_vec_init(&f->strs, sizeof(char*), bc_string_free);
   bc_vec_init(&f->consts, sizeof(char*), bc_string_free);
   bc_vec_init(&f->autos, sizeof(struct str_len), bc_id_free);
@@ -2657,10 +2586,6 @@ BcStatus bc_lex_name(BcLex *l) {
   return BC_STATUS_SUCCESS;
 }
 
-void bc_lex_init(BcLex *l) {
-  bc_vec_init(&l->str, sizeof(char), NULL);
-}
-
 void bc_lex_file(BcLex *l, char *file) {
   l->line = 1;
   TT.file = file;
@@ -2711,11 +2636,6 @@ static BcStatus bc_lex_identifier(BcLex *l) {
     {
       l->t = BC_LEX_KEY_AUTO + (BcLexType) i;
 
-      if (!BC_LEX_KW_POSIX(kw)) {
-        s = bc_lex_vposixErr(l, BC_ERROR_POSIX_KW, kw->name);
-        if (s) return s;
-      }
-
       // We minus 1 because the index has already been incremented.
       l->i += len - 1;
       return BC_STATUS_SUCCESS;
@@ -2725,9 +2645,7 @@ static BcStatus bc_lex_identifier(BcLex *l) {
   s = bc_lex_name(l);
   if (s) return s;
 
-  if (l->str.len - 1 > 1) s = bc_lex_vposixErr(l, BC_ERROR_POSIX_NAME_LEN, buf);
-
-  return s;
+  return 0;
 }
 
 static BcStatus bc_lex_string(BcLex *l) {
@@ -2776,85 +2694,55 @@ BcStatus bc_lex_token(BcLex *l) {
 
     case '\0':
     case '\n':
-    {
       l->t = !c ? BC_LEX_EOF : BC_LEX_NLINE;
       break;
-    }
 
     case '\t':
     case '\v':
     case '\f':
     case '\r':
     case ' ':
-    {
       bc_lex_whitespace(l);
       break;
-    }
 
     case '!':
-    {
       bc_lex_assign(l, BC_LEX_OP_REL_NE, BC_LEX_OP_BOOL_NOT);
-
-      if (l->t == BC_LEX_OP_BOOL_NOT) {
-        s = bc_lex_vposixErr(l, BC_ERROR_POSIX_BOOL, "!");
-        if (s) return s;
-      }
-
       break;
-    }
 
     case '"':
-    {
       s = bc_lex_string(l);
       break;
-    }
 
     case '#':
-    {
-      s = bc_lex_posixErr(l, BC_ERROR_POSIX_COMMENT);
-      if (s) return s;
-
       bc_lex_lineComment(l);
-
       break;
-    }
 
     case '%':
-    {
       bc_lex_assign(l, BC_LEX_OP_ASSIGN_MODULUS, BC_LEX_OP_MODULUS);
       break;
-    }
 
     case '&':
-    {
       c2 = l->buf[l->i];
       if (c2 == '&') {
-
-        s = bc_lex_vposixErr(l, BC_ERROR_POSIX_BOOL, "&&");
-        if (s) return s;
-
         ++l->i;
         l->t = BC_LEX_OP_BOOL_AND;
       }
       else s = bc_lex_invalidChar(l, c);
 
       break;
-    }
+
     case '(':
     case ')':
-    {
       l->t = (BcLexType) (c - '(' + BC_LEX_LPAREN);
       break;
-    }
+
 
     case '*':
-    {
       bc_lex_assign(l, BC_LEX_OP_ASSIGN_MULTIPLY, BC_LEX_OP_MULTIPLY);
       break;
-    }
+
 
     case '+':
-    {
       c2 = l->buf[l->i];
       if (c2 == '+') {
         ++l->i;
@@ -2862,16 +2750,12 @@ BcStatus bc_lex_token(BcLex *l) {
       }
       else bc_lex_assign(l, BC_LEX_OP_ASSIGN_PLUS, BC_LEX_OP_PLUS);
       break;
-    }
 
     case ',':
-    {
       l->t = BC_LEX_COMMA;
       break;
-    }
 
     case '-':
-    {
       c2 = l->buf[l->i];
       if (c2 == '-') {
         ++l->i;
@@ -2879,149 +2763,67 @@ BcStatus bc_lex_token(BcLex *l) {
       }
       else bc_lex_assign(l, BC_LEX_OP_ASSIGN_MINUS, BC_LEX_OP_MINUS);
       break;
-    }
 
     case '.':
-    {
       c2 = l->buf[l->i];
       if (BC_LEX_NUM_CHAR(c2, 'Z', 1)) s = bc_lex_number(l, c);
       else {
         l->t = BC_LEX_KEY_LAST;
-        s = bc_lex_posixErr(l, BC_ERROR_POSIX_DOT);
       }
       break;
-    }
 
     case '/':
-    {
       c2 = l->buf[l->i];
       if (c2 =='*') s = bc_lex_comment(l);
       else bc_lex_assign(l, BC_LEX_OP_ASSIGN_DIVIDE, BC_LEX_OP_DIVIDE);
       break;
-    }
 
-    case '0':
-    case '1':
-    case '2':
-    case '3':
-    case '4':
-    case '5':
-    case '6':
-    case '7':
-    case '8':
-    case '9':
-    case 'A':
-    case 'B':
-    case 'C':
-    case 'D':
-    case 'E':
-    case 'F':
+    case '0' ... '9':
+    case 'A' ... 'F':
     // Apparently, GNU bc (and maybe others) allows any uppercase letter as a
     // number. When single digits, they act like the ones above. When multi-
     // digit, any letter above the input base is automatically set to the
     // biggest allowable digit in the input base.
-    case 'G':
-    case 'H':
-    case 'I':
-    case 'J':
-    case 'K':
-    case 'L':
-    case 'M':
-    case 'N':
-    case 'O':
-    case 'P':
-    case 'Q':
-    case 'R':
-    case 'S':
-    case 'T':
-    case 'U':
-    case 'V':
-    case 'W':
-    case 'X':
-    case 'Y':
-    case 'Z':
-    {
+    case 'G' ... 'Z':
       s = bc_lex_number(l, c);
       break;
-    }
 
     case ';':
-    {
       l->t = BC_LEX_SCOLON;
       break;
-    }
 
     case '<':
-    {
       bc_lex_assign(l, BC_LEX_OP_REL_LE, BC_LEX_OP_REL_LT);
       break;
-    }
 
     case '=':
-    {
       bc_lex_assign(l, BC_LEX_OP_REL_EQ, BC_LEX_OP_ASSIGN);
       break;
-    }
 
     case '>':
-    {
       bc_lex_assign(l, BC_LEX_OP_REL_GE, BC_LEX_OP_REL_GT);
       break;
-    }
 
     case '[':
     case ']':
-    {
       l->t = (BcLexType) (c - '[' + BC_LEX_LBRACKET);
       break;
-    }
 
     case '\\':
-    {
       if (l->buf[l->i] == '\n') {
         l->t = BC_LEX_WHITESPACE;
         ++l->i;
       }
       else s = bc_lex_invalidChar(l, c);
       break;
-    }
 
     case '^':
-    {
       bc_lex_assign(l, BC_LEX_OP_ASSIGN_POWER, BC_LEX_OP_POWER);
       break;
-    }
 
-    case 'a':
-    case 'b':
-    case 'c':
-    case 'd':
-    case 'e':
-    case 'f':
-    case 'g':
-    case 'h':
-    case 'i':
-    case 'j':
-    case 'k':
-    case 'l':
-    case 'm':
-    case 'n':
-    case 'o':
-    case 'p':
-    case 'q':
-    case 'r':
-    case 's':
-    case 't':
-    case 'u':
-    case 'v':
-    case 'w':
-    case 'x':
-    case 'y':
-    case 'z':
-    {
+    case 'a' ... 'z':
       s = bc_lex_identifier(l);
       break;
-    }
 
     case '{':
     case '}':
@@ -3035,10 +2837,6 @@ BcStatus bc_lex_token(BcLex *l) {
       c2 = l->buf[l->i];
 
       if (c2 == '|') {
-
-        s = bc_lex_vposixErr(l, BC_ERROR_POSIX_BOOL, "||");
-        if (s) return s;
-
         ++l->i;
         l->t = BC_LEX_OP_BOOL_OR;
       }
@@ -3064,7 +2862,7 @@ void bc_parse_updateFunc(BcParse *p, size_t fidx) {
 
 void bc_parse_pushName(BcParse *p, char *name) {
   bc_vec_npush(&p->func->code, strlen(name), name);
-  bc_parse_push(p, UCHAR_MAX);
+  bc_parse_push(p, 255);
 }
 
 void bc_parse_pushIndex(BcParse *p, size_t idx) {
@@ -3120,13 +2918,13 @@ void bc_parse_free(BcParse *p) {
 void bc_parse_init(BcParse *p, BcProgram *prog, size_t func)
 {
   uint16_t flag = 0;
-  bc_vec_init(&p->flags, sizeof(uint16_t), NULL);
+  bc_vec_init(&p->flags, 16, NULL);
   bc_vec_push(&p->flags, &flag);
   bc_vec_init(&p->exits, sizeof(BcInstPtr), NULL);
   bc_vec_init(&p->conds, sizeof(size_t), NULL);
   bc_vec_init(&p->ops, sizeof(BcLexType), NULL);
 
-  bc_lex_init(&p->l);
+  bc_vec_init(&p->l.str, 1, NULL);
 
   p->prog = prog;
   p->auto_part = 0;
@@ -3135,7 +2933,7 @@ void bc_parse_init(BcParse *p, BcProgram *prog, size_t func)
 
 static BcStatus bc_parse_else(BcParse *p);
 static BcStatus bc_parse_stmt(BcParse *p);
-static BcStatus bc_parse_expr_err(BcParse *p, uint8_t flags, BcParseNext next);
+static BcStatus bc_parse_expr_err(BcParse *p, char flags, BcParseNext next);
 
 static int bc_parse_inst_isLeaf(BcInst t) {
   return (t >= BC_INST_NUM && t <= BC_INST_ABS) ||
@@ -3263,7 +3061,7 @@ static BcStatus bc_parse_rightParen(BcParse *p, size_t ops_bgn, size_t *nexs) {
   return bc_lex_next(&p->l);
 }
 
-static BcStatus bc_parse_params(BcParse *p, uint8_t flags) {
+static BcStatus bc_parse_params(BcParse *p, char flags) {
 
   BcStatus s;
   int comma = 0;
@@ -3292,7 +3090,7 @@ static BcStatus bc_parse_params(BcParse *p, uint8_t flags) {
   return BC_STATUS_SUCCESS;
 }
 
-static BcStatus bc_parse_call(BcParse *p, char *name, uint8_t flags) {
+static BcStatus bc_parse_call(BcParse *p, char *name, char flags) {
 
   BcStatus s;
   struct str_len id;
@@ -3325,7 +3123,7 @@ err:
   return s;
 }
 
-static BcStatus bc_parse_name(BcParse *p, BcInst *type, uint8_t flags) {
+static BcStatus bc_parse_name(BcParse *p, BcInst *type, char flags) {
 
   BcStatus s;
   char *name;
@@ -3409,7 +3207,7 @@ static BcStatus bc_parse_read(BcParse *p) {
 }
 
 static BcStatus bc_parse_builtin(BcParse *p, BcLexType type,
-                                 uint8_t flags, BcInst *prev)
+                                 char flags, BcInst *prev)
 {
   BcStatus s;
 
@@ -3434,7 +3232,7 @@ static BcStatus bc_parse_builtin(BcParse *p, BcLexType type,
   return bc_lex_next(&p->l);
 }
 
-static BcStatus bc_parse_scale(BcParse *p, BcInst *type, uint8_t flags) {
+static BcStatus bc_parse_scale(BcParse *p, BcInst *type, char flags) {
 
   BcStatus s;
 
@@ -3463,7 +3261,7 @@ static BcStatus bc_parse_scale(BcParse *p, BcInst *type, uint8_t flags) {
 }
 
 static BcStatus bc_parse_incdec(BcParse *p, BcInst *prev,
-                                size_t *nexs, uint8_t flags)
+                                size_t *nexs, char flags)
 {
   BcStatus s;
   BcLexType type;
@@ -3578,10 +3376,7 @@ static BcStatus bc_parse_print(BcParse *p) {
 }
 
 static BcStatus bc_parse_return(BcParse *p) {
-
   BcStatus s;
-  BcLexType t;
-  int paren;
   char inst = BC_INST_RET0;
 
   if (!BC_PARSE_FUNC(p)) return bc_parse_err(p, BC_ERROR_PARSE_TOKEN);
@@ -3591,9 +3386,6 @@ static BcStatus bc_parse_return(BcParse *p) {
   s = bc_lex_next(&p->l);
   if (s) return s;
 
-  t = p->l.t;
-  paren = t == BC_LEX_LPAREN;
-
   if (bc_parse_isDelimiter(p)) bc_parse_push(p, inst);
   else {
 
@@ -3605,11 +3397,7 @@ static BcStatus bc_parse_return(BcParse *p) {
       if (s) return s;
     }
 
-    if (!paren || p->l.last != BC_LEX_RPAREN) {
-      s = bc_parse_posixErr(p, BC_ERROR_POSIX_RET);
-      if (s) return s;
-    }
-    else if (p->func->voidfn)
+    if (p->func->voidfn)
       return bc_parse_verr(p, BC_ERROR_PARSE_RET_VOID, p->func->name);
 
     bc_parse_push(p, BC_INST_RET);
@@ -3793,7 +3581,6 @@ static BcStatus bc_parse_while(BcParse *p) {
 }
 
 static BcStatus bc_parse_for(BcParse *p) {
-
   BcStatus s;
   size_t cond_idx, exit_idx, body_idx, update_idx;
 
@@ -3807,7 +3594,7 @@ static BcStatus bc_parse_for(BcParse *p) {
     s = bc_parse_expr_status(p, 0, bc_parse_next_for);
     if (!s) bc_parse_push(p, BC_INST_POP);
   }
-  else s = bc_parse_posixErr(p, BC_ERROR_POSIX_FOR1);
+  else;
 
   if (s) return s;
   if (p->l.t != BC_LEX_SCOLON) return bc_parse_err(p, BC_ERROR_PARSE_TOKEN);
@@ -3828,10 +3615,9 @@ static BcStatus bc_parse_for(BcParse *p) {
     // Set this for the next call to bc_parse_number.
     // This is safe to set because the current token
     // is a semicolon, which has no string requirement.
-    bc_vec_string(&p->l.str, strlen(bc_parse_const1), bc_parse_const1);
+    bc_vec_string(&p->l.str, 1, "1");
     bc_parse_number(p);
 
-    s = bc_parse_posixErr(p, BC_ERROR_POSIX_FOR2);
   }
 
   if (s) return s;
@@ -3851,7 +3637,7 @@ static BcStatus bc_parse_for(BcParse *p) {
     s = bc_parse_expr_status(p, 0, bc_parse_next_rel);
     if (!s) bc_parse_push(p, BC_INST_POP);
   }
-  else s = bc_parse_posixErr(p, BC_ERROR_POSIX_FOR3);
+  else;
 
   if (s) return s;
 
@@ -3867,8 +3653,8 @@ static BcStatus bc_parse_for(BcParse *p) {
   return s;
 }
 
-static BcStatus bc_parse_loopExit(BcParse *p, BcLexType type) {
-
+static BcStatus bc_parse_loopExit(BcParse *p, BcLexType type)
+{
   size_t i;
   BcInstPtr *ip;
 
@@ -3895,8 +3681,8 @@ static BcStatus bc_parse_loopExit(BcParse *p, BcLexType type) {
   return bc_lex_next(&p->l);
 }
 
-static BcStatus bc_parse_func(BcParse *p) {
-
+static BcStatus bc_parse_func(BcParse *p)
+{
   BcStatus s;
   int comma = 0, voidfn;
   uint16_t flags;
@@ -3977,8 +3763,6 @@ static BcStatus bc_parse_func(BcParse *p) {
   s = bc_lex_next(&p->l);
   if (s) return s;
 
-  if (p->l.t != BC_LEX_LBRACE) s = bc_parse_posixErr(p, BC_ERROR_POSIX_BRACE);
-
   return s;
 
 err:
@@ -4045,8 +3829,8 @@ err:
   return s;
 }
 
-static BcStatus bc_parse_body(BcParse *p, int brace) {
-
+static BcStatus bc_parse_body(BcParse *p, int brace)
+{
   BcStatus s = BC_STATUS_SUCCESS;
   uint16_t *flag_ptr = BC_PARSE_TOP_FLAG_PTR(p);
 
@@ -4079,8 +3863,8 @@ static BcStatus bc_parse_body(BcParse *p, int brace) {
   return s;
 }
 
-static BcStatus bc_parse_stmt(BcParse *p) {
-
+static BcStatus bc_parse_stmt(BcParse *p)
+{
   BcStatus s = BC_STATUS_SUCCESS;
   size_t len;
   uint16_t flags;
@@ -4121,7 +3905,6 @@ static BcStatus bc_parse_stmt(BcParse *p) {
   flags = BC_PARSE_TOP_FLAG(p);
 
   switch (type) {
-
     case BC_LEX_OP_INC:
     case BC_LEX_OP_DEC:
     case BC_LEX_OP_MINUS:
@@ -4137,108 +3920,64 @@ static BcStatus bc_parse_stmt(BcParse *p) {
     case BC_LEX_KEY_SCALE:
     case BC_LEX_KEY_SQRT:
     case BC_LEX_KEY_ABS:
-    {
       s = bc_parse_expr_status(p, BC_PARSE_PRINT, bc_parse_next_expr);
       break;
-    }
 
     case BC_LEX_KEY_ELSE:
-    {
       s = bc_parse_else(p);
       break;
-    }
 
     case BC_LEX_SCOLON:
-    {
       // Do nothing.
       break;
-    }
 
     case BC_LEX_RBRACE:
-    {
       s = bc_parse_endBody(p, 1);
       break;
-    }
 
     case BC_LEX_STR:
-    {
       s = bc_parse_str(p, BC_INST_PRINT_STR);
       break;
-    }
 
     case BC_LEX_KEY_BREAK:
     case BC_LEX_KEY_CONTINUE:
-    {
       s = bc_parse_loopExit(p, p->l.t);
       break;
-    }
 
     case BC_LEX_KEY_FOR:
-    {
       s = bc_parse_for(p);
       break;
-    }
 
     case BC_LEX_KEY_HALT:
-    {
       bc_parse_push(p, BC_INST_HALT);
       s = bc_lex_next(&p->l);
       break;
-    }
 
     case BC_LEX_KEY_IF:
-    {
       s = bc_parse_if(p);
       break;
-    }
-
-    case BC_LEX_KEY_LIMITS:
-    {
-      printf("BC_BASE_MAX     = %lu\n", BC_MAX_OBASE);
-      printf("BC_DIM_MAX      = %lu\n", BC_MAX_DIM);
-      printf("BC_SCALE_MAX    = %lu\n", BC_MAX_SCALE);
-      printf("BC_STRING_MAX   = %lu\n", BC_MAX_STRING);
-      printf("BC_NAME_MAX     = %lu\n", BC_MAX_NAME);
-      printf("BC_NUM_MAX      = %lu\n", BC_MAX_NUM);
-      printf("MAX Exponent    = %lu\n", BC_MAX_EXP);
-      printf("Number of vars  = %lu\n", BC_MAX_VARS);
-
-      s = bc_lex_next(&p->l);
-
-      break;
-    }
 
     case BC_LEX_KEY_PRINT:
-    {
       s = bc_parse_print(p);
       break;
-    }
 
     case BC_LEX_KEY_QUIT:
-    {
       // Quit is a compile-time command. We don't exit directly,
       // so the vm can clean up. Limits do the same thing.
       s = BC_STATUS_QUIT;
       break;
-    }
 
     case BC_LEX_KEY_RETURN:
-    {
       s = bc_parse_return(p);
       break;
-    }
 
     case BC_LEX_KEY_WHILE:
-    {
       s = bc_parse_while(p);
       break;
-    }
 
     default:
-    {
       s = bc_parse_err(p, BC_ERROR_PARSE_TOKEN);
       break;
-    }
   }
 
   if (!s && len == p->flags.len && flags == BC_PARSE_TOP_FLAG(p)) {
@@ -4251,8 +3990,8 @@ static BcStatus bc_parse_stmt(BcParse *p) {
   return s;
 }
 
-BcStatus bc_parse_parse(BcParse *p) {
-
+BcStatus bc_parse_parse(BcParse *p)
+{
   BcStatus s;
 
   if (p->l.t == BC_LEX_EOF) s = bc_parse_err(p, BC_ERROR_PARSE_EOF);
@@ -4267,12 +4006,12 @@ BcStatus bc_parse_parse(BcParse *p) {
   return s;
 }
 
-static BcStatus bc_parse_expr_err(BcParse *p, uint8_t flags, BcParseNext next) {
+static BcStatus bc_parse_expr_err(BcParse *p, char flags, BcParseNext next) {
   BcStatus s = BC_STATUS_SUCCESS;
   BcInst prev = BC_INST_PRINT;
   BcLexType top, t = p->l.t;
   size_t nexprs = 0, ops_bgn = p->ops.len;
-  uint32_t i, nparens, nrelops;
+  unsigned i, nparens, nrelops;
   int pfirst, rprn, done, get_token, assign, bin_last, incdec;
   char valid[] = {0xfc, 0xff, 0xff, 0x67, 0xc0, 0x00, 0x7c, 0x0b};
 
@@ -4427,8 +4166,8 @@ static BcStatus bc_parse_expr_err(BcParse *p, uint8_t flags, BcParseNext next) {
         if (BC_PARSE_LEAF(prev, bin_last, rprn))
           return bc_parse_err(p, BC_ERROR_PARSE_EXPR);
 
-        prev = (char) (t - BC_LEX_KEY_LAST + BC_INST_LAST);
-        bc_parse_push(p, (char) prev);
+        prev = (t - BC_LEX_KEY_LAST + BC_INST_LAST);
+        bc_parse_push(p, prev);
 
         get_token = 1;
         rprn = bin_last = 0;
@@ -4511,15 +4250,6 @@ static BcStatus bc_parse_expr_err(BcParse *p, uint8_t flags, BcParseNext next) {
   if (i == next.len && !bc_parse_isDelimiter(p))
     return bc_parse_err(p, BC_ERROR_PARSE_EXPR);
 
-  if (!(flags & BC_PARSE_REL) && nrelops) {
-    s = bc_parse_posixErr(p, BC_ERROR_POSIX_REL_POS);
-    if (s) return s;
-  }
-  else if ((flags & BC_PARSE_REL) && nrelops > 1) {
-    s = bc_parse_posixErr(p, BC_ERROR_POSIX_MULTIREL);
-    if (s) return s;
-  }
-
   if (flags & BC_PARSE_PRINT) {
     if (pfirst || !assign) bc_parse_push(p, BC_INST_PRINT);
     bc_parse_push(p, BC_INST_POP);
@@ -4536,7 +4266,7 @@ static BcStatus bc_parse_expr_err(BcParse *p, uint8_t flags, BcParseNext next) {
   return s;
 }
 
-BcStatus bc_parse_expr_status(BcParse *p, uint8_t flags, BcParseNext next) {
+BcStatus bc_parse_expr_status(BcParse *p, char flags, BcParseNext next) {
 
   BcStatus s = bc_parse_expr_err(p, flags, next);
 
@@ -4571,12 +4301,11 @@ static char *bc_program_str(BcProgram *p, size_t idx, int str) {
 }
 
 static size_t bc_program_index(char *code, size_t *bgn) {
-
-  char amt = (char) code[(*bgn)++], i = 0;
+  char amt = code[(*bgn)++], i = 0;
   size_t res = 0;
 
   for (; i < amt; ++i, ++(*bgn)) {
-    size_t temp = ((size_t) ((int) (char) code[*bgn]) & UCHAR_MAX);
+    size_t temp = code[*bgn] & 255;
     res |= (temp << (i * CHAR_BIT));
   }
 
@@ -4584,16 +4313,15 @@ static size_t bc_program_index(char *code, size_t *bgn) {
 }
 
 static char *bc_program_name(char *code, size_t *bgn) {
-
   size_t i;
   char c;
   char *s;
-  char *str = code + *bgn, *ptr = strchr(str, UCHAR_MAX);
+  char *str = code + *bgn, *ptr = strchr(str, 255);
 
   s = xmalloc(((unsigned long) ptr) - ((unsigned long) str) + 1);
 
-  for (i = 0; (c = (char) code[(*bgn)++]) && c != UCHAR_MAX; ++i)
-    s[i] = (char) c;
+  for (i = 0; (c = code[(*bgn)++]) && c != 255; ++i)
+    s[i] = c;
 
   s[i] = '\0';
 
@@ -4601,7 +4329,6 @@ static char *bc_program_name(char *code, size_t *bgn) {
 }
 
 static BcVec* bc_program_search(BcProgram *p, char *id, BcType type) {
-
   struct str_len e, *ptr;
   BcVec *v, *map;
   size_t i;
@@ -4627,7 +4354,6 @@ static BcVec* bc_program_search(BcProgram *p, char *id, BcType type) {
 }
 
 static BcStatus bc_program_num(BcProgram *p, BcResult *r, BcNum **num) {
-
   BcStatus s = BC_STATUS_SUCCESS;
   BcNum *n = &r->d.n;
 
@@ -4655,15 +4381,12 @@ static BcStatus bc_program_num(BcProgram *p, BcResult *r, BcNum **num) {
     case BC_RESULT_IBASE:
     case BC_RESULT_SCALE:
     case BC_RESULT_OBASE:
-    {
       *num = n;
       break;
-    }
 
     case BC_RESULT_VAR:
     case BC_RESULT_ARRAY:
     case BC_RESULT_ARRAY_ELEM:
-    {
       BcVec *v;
       BcType type = (r->t == BC_RESULT_VAR) ? BC_TYPE_VAR : BC_TYPE_ARRAY;
 
@@ -4681,25 +4404,18 @@ static BcStatus bc_program_num(BcProgram *p, BcResult *r, BcNum **num) {
       else *num = bc_vec_top(v);
 
       break;
-    }
 
     case BC_RESULT_LAST:
-    {
       *num = &p->last;
       break;
-    }
 
     case BC_RESULT_ONE:
-    {
       *num = &p->one;
       break;
-    }
 
     case BC_RESULT_VOID:
-    {
       s = bc_vm_err(BC_ERROR_EXEC_VOID_VAL);
       break;
-    }
   }
 
   return s;
@@ -4708,7 +4424,6 @@ static BcStatus bc_program_num(BcProgram *p, BcResult *r, BcNum **num) {
 static BcStatus bc_program_operand(BcProgram *p, BcResult **r,
                                    BcNum **n, size_t idx)
 {
-
   *r = bc_vec_item_rev(&p->results, idx);
 
   return bc_program_num(p, *r, n);
@@ -4781,7 +4496,6 @@ static void bc_program_binOpRetire(BcProgram *p, BcResult *r) {
 }
 
 static BcStatus bc_program_prep(BcProgram *p, BcResult **r, BcNum **n) {
-
   BcStatus s;
 
   s = bc_program_operand(p, r, n, 0);
@@ -4797,7 +4511,6 @@ static void bc_program_retire(BcProgram *p, BcResult *r, BcResultType t) {
 }
 
 static BcStatus bc_program_op(BcProgram *p, char inst) {
-
   BcStatus s;
   BcResult *opd1, *opd2, res;
   BcNum *n1 = NULL, *n2 = NULL;
@@ -4837,7 +4550,7 @@ static BcStatus bc_program_read(BcProgram *p) {
   file = TT.file;
   bc_lex_file(&parse.l, "<stdin>");
   bc_vec_npop(&f->code, f->code.len);
-  bc_vec_init(&buf, sizeof(char), NULL);
+  bc_vec_init(&buf, 1, NULL);
 
   s = bc_read_line(&buf, "read> ");
   if (s) {
@@ -4902,7 +4615,6 @@ static void bc_program_printString(char *str)
 }
 
 static BcStatus bc_program_print(BcProgram *p, char inst, size_t idx) {
-
   BcStatus s = BC_STATUS_SUCCESS;
   BcResult *r;
   char *str;
@@ -4995,46 +4707,14 @@ static BcStatus bc_program_logical(BcProgram *p, char inst) {
   else if (inst == BC_INST_BOOL_OR)
     cond = BC_NUM_CMP_ZERO(n1) || BC_NUM_CMP_ZERO(n2);
   else {
-
     cmp = bc_num_cmp(n1, n2);
-
     switch (inst) {
-
-      case BC_INST_REL_EQ:
-      {
-        cond = cmp == 0;
-        break;
-      }
-
-      case BC_INST_REL_LE:
-      {
-        cond = cmp <= 0;
-        break;
-      }
-
-      case BC_INST_REL_GE:
-      {
-        cond = cmp >= 0;
-        break;
-      }
-
-      case BC_INST_REL_NE:
-      {
-        cond = cmp != 0;
-        break;
-      }
-
-      case BC_INST_REL_LT:
-      {
-        cond = cmp < 0;
-        break;
-      }
-
-      case BC_INST_REL_GT:
-      {
-        cond = cmp > 0;
-        break;
-      }
+      case BC_INST_REL_EQ: cond = cmp == 0; break;
+      case BC_INST_REL_LE: cond = cmp <= 0; break;
+      case BC_INST_REL_GE: cond = cmp >= 0; break;
+      case BC_INST_REL_NE: cond = cmp != 0; break;
+      case BC_INST_REL_LT: cond = cmp < 0; break;
+      case BC_INST_REL_GT: cond = cmp > 0; break;
     }
   }
 
@@ -5111,7 +4791,7 @@ static BcStatus bc_program_assign(BcProgram *p, char inst) {
 
     size_t *ptr;
     unsigned long val, max, min;
-    BcError e;
+    enum BcError e;
 
     s = bc_num_ulong(l, &val);
     if (s) return s;
@@ -5123,7 +4803,7 @@ static BcStatus bc_program_assign(BcProgram *p, char inst) {
       ptr = &p->scale;
     }
     else {
-      max = ib ? TT.max_ibase : BC_MAX_OBASE;
+      max = ib ? 36 : BC_MAX_OBASE;
       min = 2;
       ptr = ib ? &p->ib_t : &p->ob_t;
     }
@@ -5389,18 +5069,6 @@ static void bc_program_pushGlobal(BcProgram *p, char inst) {
   bc_vec_push(&p->results, &res);
 }
 
-void bc_program_free(BcProgram *p) {
-  bc_vec_free(&p->fns);
-  bc_vec_free(&p->fn_map);
-  bc_vec_free(&p->vars);
-  bc_vec_free(&p->var_map);
-  bc_vec_free(&p->arrs);
-  bc_vec_free(&p->arr_map);
-  bc_vec_free(&p->results);
-  bc_vec_free(&p->stack);
-  bc_num_free(&p->last);
-}
-
 void bc_program_init(BcProgram *p) {
 
   BcInstPtr ip;
@@ -5480,7 +5148,7 @@ BcStatus bc_program_reset(BcProgram *p, BcStatus s) {
   TT.sig = 0;
 
   if (!s || s == BC_STATUS_SIGNAL) {
-    if (BC_TTYIN) {
+    if (FLAG(i)) {
       fputs(bc_program_ready_msg, stderr);
       fflush(stderr);
       s = BC_STATUS_SUCCESS;
@@ -5504,62 +5172,48 @@ BcStatus bc_program_exec(BcProgram *p) {
 
   while (!s && ip->idx < func->code.len) {
 
-    char inst = (char) code[(ip->idx)++];
+    char inst = code[(ip->idx)++];
 
     switch (inst) {
 
       case BC_INST_JUMP_ZERO:
-      {
         s = bc_program_prep(p, &ptr, &num);
         if (s) return s;
         cond = !BC_NUM_CMP_ZERO(num);
         bc_vec_pop(&p->results);
-      }
       // Fallthrough.
       case BC_INST_JUMP:
-      {
         size_t *addr;
         idx = bc_program_index(code, &ip->idx);
         addr = bc_vec_item(&func->labels, idx);
         if (inst == BC_INST_JUMP || cond) ip->idx = *addr;
         break;
-      }
 
       case BC_INST_CALL:
-      {
         s = bc_program_call(p, code, &ip->idx);
         break;
-      }
 
       case BC_INST_INC_PRE:
       case BC_INST_DEC_PRE:
       case BC_INST_INC_POST:
       case BC_INST_DEC_POST:
-      {
         s = bc_program_incdec(p, inst);
         break;
-      }
 
       case BC_INST_HALT:
-      {
         s = BC_STATUS_QUIT;
         break;
-      }
 
       case BC_INST_RET:
       case BC_INST_RET0:
       case BC_INST_RET_VOID:
-      {
         s = bc_program_return(p, inst);
         break;
-      }
 
       case BC_INST_LAST:
-      {
         r.t = BC_RESULT_LAST;
         bc_vec_push(&p->results, &r);
         break;
-      }
 
       case BC_INST_BOOL_OR:
       case BC_INST_BOOL_AND:
@@ -5569,76 +5223,56 @@ BcStatus bc_program_exec(BcProgram *p) {
       case BC_INST_REL_NE:
       case BC_INST_REL_LT:
       case BC_INST_REL_GT:
-      {
         s = bc_program_logical(p, inst);
         break;
-      }
 
       case BC_INST_READ:
-      {
         s = bc_program_read(p);
         break;
-      }
 
       case BC_INST_VAR:
-      {
         s = bc_program_pushVar(p, code, &ip->idx);
         break;
-      }
 
       case BC_INST_ARRAY_ELEM:
       case BC_INST_ARRAY:
-      {
         s = bc_program_pushArray(p, code, &ip->idx, inst);
         break;
-      }
 
       case BC_INST_IBASE:
       case BC_INST_SCALE:
       case BC_INST_OBASE:
-      {
         bc_program_pushGlobal(p, inst);
         break;
-      }
 
       case BC_INST_LENGTH:
       case BC_INST_SCALE_FUNC:
       case BC_INST_SQRT:
       case BC_INST_ABS:
-      {
         s = bc_program_builtin(p, inst);
         break;
-      }
 
       case BC_INST_NUM:
-      {
         r.t = BC_RESULT_CONSTANT;
         r.d.id.len = bc_program_index(code, &ip->idx);
         bc_vec_push(&p->results, &r);
         break;
-      }
 
       case BC_INST_POP:
-      {
         bc_vec_pop(&p->results);
         break;
-      }
 
       case BC_INST_PRINT:
       case BC_INST_PRINT_POP:
       case BC_INST_PRINT_STR:
-      {
         s = bc_program_print(p, inst, 0);
         break;
-      }
 
       case BC_INST_STR:
-      {
         r.t = BC_RESULT_STR;
         r.d.id.len = bc_program_index(code, &ip->idx);
         bc_vec_push(&p->results, &r);
         break;
-      }
 
       case BC_INST_POWER:
       case BC_INST_MULTIPLY:
@@ -5646,17 +5280,13 @@ BcStatus bc_program_exec(BcProgram *p) {
       case BC_INST_MODULUS:
       case BC_INST_PLUS:
       case BC_INST_MINUS:
-      {
         s = bc_program_op(p, inst);
         break;
-      }
 
       case BC_INST_NEG:
       case BC_INST_BOOL_NOT:
-      {
         s = bc_program_unary(p, inst);
         break;
-      }
 
       case BC_INST_ASSIGN_POWER:
       case BC_INST_ASSIGN_MULTIPLY:
@@ -5665,10 +5295,8 @@ BcStatus bc_program_exec(BcProgram *p) {
       case BC_INST_ASSIGN_PLUS:
       case BC_INST_ASSIGN_MINUS:
       case BC_INST_ASSIGN:
-      {
         s = bc_program_assign(p, inst);
         break;
-      }
     }
 
     if ((s && s != BC_STATUS_QUIT) || TT.sig) s = bc_program_reset(p, s);
@@ -5682,9 +5310,9 @@ BcStatus bc_program_exec(BcProgram *p) {
   return s;
 }
 
-static void bc_vm_sig(int sig) {
+static void bc_vm_sig(int sig)
+{
   int err = errno;
-
   // If you run bc 2>/dev/full ctrl-C is ignored. Why? No idea.
   if (sig == SIGINT) {
     size_t len = strlen(bc_sig_msg);
@@ -5694,25 +5322,20 @@ static void bc_vm_sig(int sig) {
   errno = err;
 }
 
-void bc_vm_info(void) {
-  printf("%s %s\n", toys.which->name, "1.1.0");
-  fputs(bc_copyright, stdout);
-}
-
-static void bc_vm_printError(BcError e, char *fmt,
+static void bc_vm_printError(enum BcError e, char *fmt,
                              size_t line, va_list args)
 {
   // Make sure all of stdout is written first.
   fflush(stdout);
 
-  fprintf(stderr, fmt, bc_errs[(size_t) bc_err_ids[e]]);
+  fprintf(stderr, fmt, bc_errs[bc_err_ids[e]]);
   vfprintf(stderr, bc_err_msgs[e], args);
 
   // This is the condition for parsing vs runtime.
   // If line is not 0, it is parsing.
   if (line) {
     fprintf(stderr, "\n    %s", TT.file);
-    fprintf(stderr, bc_err_line, line);
+    fprintf(stderr, ":%zu", line);
   }
   else {
     BcInstPtr *ip = bc_vec_item_rev(&BC_VM->prog.stack, 0);
@@ -5724,30 +5347,17 @@ static void bc_vm_printError(BcError e, char *fmt,
   fflush(stderr);
 }
 
-BcStatus bc_vm_error(BcError e, size_t line, ...) {
-
+BcStatus bc_vm_error(enum BcError e, size_t line, ...)
+{
   va_list args;
 
   va_start(args, line);
-  bc_vm_printError(e, bc_err_fmt, line, args);
+  bc_vm_printError(e, "\n%s error:", line, args);
   va_end(args);
 
   return BC_STATUS_ERROR;
 }
 
-BcStatus bc_vm_posixError(BcError e, size_t line, ...) {
-
-  va_list args;
-
-  if (!(FLAG(s) || FLAG(w))) return BC_STATUS_SUCCESS;
-
-  va_start(args, line);
-  bc_vm_printError(e, FLAG(s) ? bc_err_fmt : bc_warn_fmt, line, args);
-  va_end(args);
-
-  return FLAG(s) ? BC_STATUS_ERROR : BC_STATUS_SUCCESS;
-}
-
 static void bc_vm_clean()
 {
   BcProgram *prog = &BC_VM->prog;
@@ -5768,7 +5378,6 @@ static void bc_vm_clean()
 }
 
 static BcStatus bc_vm_process(char *text, int is_stdin) {
-
   BcStatus s;
   uint16_t *flags;
 
@@ -5817,7 +5426,6 @@ err:
 }
 
 static BcStatus bc_vm_stdin(void) {
-
   BcStatus s = BC_STATUS_SUCCESS;
   BcVec buf, buffer;
   size_t string = 0;
@@ -5825,8 +5433,8 @@ static BcStatus bc_vm_stdin(void) {
 
   bc_lex_file(&BC_VM->prs.l, "<stdin>");
 
-  bc_vec_init(&buffer, sizeof(char), NULL);
-  bc_vec_init(&buf, sizeof(char), NULL);
+  bc_vec_init(&buffer, 1, NULL);
+  bc_vec_init(&buf, 1, NULL);
   bc_vec_pushByte(&buffer, '\0');
 
   // This loop is complex because the vm tries not to send any lines that end
@@ -5849,7 +5457,7 @@ static BcStatus bc_vm_stdin(void) {
     for (i = 0; i < len; ++i) {
 
       int notend = len > i + 1;
-      char c = (char) str[i];
+      char c = str[i];
 
       if (!comment && (i - 1 > len || str[i - 1] != '\\')) string ^= c == '"';
 
@@ -5909,8 +5517,7 @@ void bc_main(void)
   sigaction(SIGQUIT, &sa, NULL);
 
   TT.line_len = 69;
-  ss = getenv("BC_LINE_LENGTH");
-  if (ss) {
+  if ((ss = getenv("BC_LINE_LENGTH"))) {
     int len = atoi(ss);
     if (len>=2 && len <= UINT16_MAX) TT.line_len = len;
   }
@@ -5919,17 +5526,19 @@ void bc_main(void)
   bc_program_init(&BC_VM->prog);
   bc_parse_init(&BC_VM->prs, &BC_VM->prog, BC_PROG_MAIN);
 
-  if (getenv("POSIXLY_CORRECT")) toys.optflags |= FLAG_s;
-  toys.optflags |= isatty(0) ? BC_FLAG_TTYIN : 0;
-  toys.optflags |= BC_TTYIN && isatty(1) ? FLAG_i : 0;
+  toys.optflags |= isatty(0) ? FLAG_i : 0;
+  toys.optflags |= FLAG(i) && isatty(1) ? FLAG_i : 0;
 
-  TT.max_ibase = !FLAG(s) && !FLAG(w) ? 16 : 36;
-
-  if (FLAG(i) && !(toys.optflags & FLAG_q)) bc_vm_info();
+  if (FLAG(i) && !(toys.optflags & FLAG_q)) {
+    printf("%s 1.1.0\n", toys.which->name);
+    puts("Copyright (c) 2018 Gavin D. Howard and contributors\n"
+  "Report bugs at: https://github.com/gavinhoward/bc\n";
+  "This is free software with ABSOLUTELY NO WARRANTY.");
+  }
 
   // load -l library (if any)
   if (FLAG(l)) {
-    bc_lex_file(&BC_VM->prs.l, bc_lib_name);
+    bc_lex_file(&BC_VM->prs.l, "");
     s = bc_parse_text(&BC_VM->prs, bc_lib);
 
     while (!s && BC_VM->prs.l.t != BC_LEX_EOF) s = bc_parse_parse(&BC_VM->prs);
@@ -5944,7 +5553,15 @@ void bc_main(void)
   }
 
   if (CFG_TOYBOX_FREE) {
-    bc_program_free(&BC_VM->prog);
+    bc_vec_free(&BC_VM->prog.fns);
+    bc_vec_free(&BC_VM->prog.fn_map);
+    bc_vec_free(&BC_VM->prog.vars);
+    bc_vec_free(&BC_VM->prog.var_map);
+    bc_vec_free(&BC_VM->prog.arrs);
+    bc_vec_free(&BC_VM->prog.arr_map);
+    bc_vec_free(&BC_VM->prog.results);
+    bc_vec_free(&BC_VM->prog.stack);
+    bc_num_free(&BC_VM->prog.last);
     bc_parse_free(&BC_VM->prs);
     free(TT.vm);
   }
-- 
2.44.0

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to