From bf2482154d14333b0eb2641423f3406f08c06973 Mon Sep 17 00:00:00 2001
From: dan <me@danrh.co.uk>
Date: Fri, 26 May 2023 15:08:31 -0400
Subject: refactor: switch case to pick optype; isnumber tidy up;

---
 forth.c | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/forth.c b/forth.c
index a9407ef..f5f629a 100644
--- a/forth.c
+++ b/forth.c
@@ -12,16 +12,17 @@
 #include "optable.h"
 #endif
 
-//https://stackoverflow.com/a/58585995
-char isnumber(char *text) {
-    int j;
-    j = strlen(text);
-    while(j--) {
-        if(text[j] >= '0' && text[j] <= '9')
-            continue;
-        return 0;
+bool isnumber(char *text) {
+    for(int j = strlen(text); j > 0; j--) {
+        if(text[j] < '0' && text[j] > '9') {
+            return false;
+        }
     }
-    return 1;
+    return true;
+}
+
+bool notdelim(char c) {
+    return c != ' ' && c != '\n' && c != '\t' && c != '\0';
 }
 
 void eval(stack* s, int len, char* line);
@@ -29,22 +30,22 @@ void eval(stack* s, int len, char* line);
 void exec(stack *s, char *word, int len, char* line, int* i) {
     wordop* op = getop(word);
     if (op) {
-        if (op->optype == script) {
-            eval(s, op->scriptlen, op->script);
-        } else if (op->optype == builtin) {
-            op->op(s);
-        } else if (op->optype == directive) {
-            op->directive(s, len, line, i);
+        switch (op->optype) {
+            case script:
+                eval(s, op->scriptlen, op->script);
+                break;
+            case builtin:
+                op->op(s);
+                break;
+            case directive:
+                op->directive(s, len, line, i);
+                break;
         }
     } else if (isnumber(word)) {
         push(s, atoi(word));
     }
 }
 
-bool notdelim(char c) {
-    return c != ' ' && c != '\n' && c != '\t' && c != '\0';
-}
-
 void eval(stack* s, int len, char* line) {
         char word[WORD_LEN_LIMIT];
         int wordi = 0;
-- 
cgit v1.2.3