aboutsummaryrefslogtreecommitdiff
path: root/loop.c
blob: 2067e21f7986b726fa11ab6b0bc3080a04125cbb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "spsh.h"

/* Loop through reading commands until we see an EOF (^D) */
void loop() {
    char *line;

    /* Loop until we break */
    while (1) {

        /* Read a line from the user */
        line = readline(PROMPT);

        /* If the line is valid, try to run it as a command */
        if (line != NULL) {
            if (strlen(line) > 0) {
                cmd(line);
            }
        }

        /* If the line is EOF (^D), break out of the loop */
        else {
            fputs("\n", stdout);
            break;
        }
    }

    return;
}