summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArun Prakash Jana <engineerarun@gmail.com>2021-11-19 21:13:13 +0530
committerArun Prakash Jana <engineerarun@gmail.com>2021-11-19 21:27:32 +0530
commitd643a1d9e0b8cf3a21f2e5f20c6d9488f6beef5b (patch)
tree73b0a014d9b9a92700b54a9d95f7c4980b5379e7
parentdfdd5170201d6b94fb2b54f5631c13decc23ab5a (diff)
Fix #38: support "exit" and "quit" at prompt
-rw-r--r--src/bcal.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/bcal.c b/src/bcal.c
index c3f9738..940bed2 100644
--- a/src/bcal.c
+++ b/src/bcal.c
@@ -169,6 +169,13 @@ static size_t bstrlcpy(char *dest, const char *src, size_t n)
return len;
}
+static bool program_exit(const char *str)
+{
+ if (!(strcmp(str, "exit") && strcmp(str, "quit")))
+ return TRUE;
+ return FALSE;
+}
+
/*
* Try to evaluate en expression using bc
* If argument is NULL, global curexpr is picked
@@ -190,7 +197,7 @@ static int try_bc(char *expr)
log(DEBUG, "expression: \"%s\"\n", expr);
- if (!strcmp(expr, "quit") || !strcmp(expr, "exit"))
+ if (program_exit(expr))
exit(0);
if (pipe(pipe_pc) == -1 || pipe(pipe_cp) == -1) {
@@ -2140,6 +2147,11 @@ int main(int argc, char **argv)
if (!tmp)
exit(0);
+ if (program_exit(tmp)) {
+ free(tmp);
+ exit(0);
+ }
+
/* Quit on double Enter */
if (tmp[0] == '\0') {
if (enters == 1) {