about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cmds.c1
-rw-r--r--main.c4
-rw-r--r--state.h1
3 files changed, 4 insertions, 2 deletions
diff --git a/cmds.c b/cmds.c
index ec7efa6..07707df 100644
--- a/cmds.c
+++ b/cmds.c
@@ -55,6 +55,7 @@ int search(const void *s1, const void *s2) {
 void init_state(state *s) {
   int numel = sizeof(CMD_LIST)/sizeof(CMD_LIST[0]);
   qsort(&CMD_LIST, numel, sizeof(CMD_LIST[0]), compare);
+  s->numel = numel;
   s->sorted = CMD_LIST;
 }
 
diff --git a/main.c b/main.c
index 9484a5f..c369290 100644
--- a/main.c
+++ b/main.c
@@ -37,7 +37,7 @@ int main() {
     fprintf(s.defout, s.prompt, s.command_count, s.last_op);
     s.last_op = 0;
     char *endptr = NULL;
-    if (s.stk.count == STACK_SIZE) err(1, "exceeded stk size");
+    if (s.stk.count == STACK_SIZE) errx(1, "exceeded stk size");
     fgets(buf, BUF_SIZE, s.defbuf);
     buf[strcspn(buf, "\n")] = 0;
     double interpreted = strtod(buf, &endptr);
@@ -77,7 +77,7 @@ int main() {
 	  free (s.sorted);
 	  exit(0);
 	} else if (strcmp(buf, "list") == 0) {
-	  for (int i = 0; s.sorted[i].name != 0; i++) {
+	  for (int i = 0; i < s.numel; i++) {
 	    fprintf(s.defout, "[%s]\t->\t%s\n", s.sorted[i].name, s.sorted[i].description);
 	    continue;
 	  }
diff --git a/state.h b/state.h
index a9b1a7b..fc7a4e5 100644
--- a/state.h
+++ b/state.h
@@ -26,6 +26,7 @@ typedef struct {
   stack stk;
   /* btree elements */
   command *sorted; /* sorted by function name */
+  int numel;
 } state;
 
 #endif