summaryrefslogtreecommitdiff
path: root/src/commands/yes.c
blob: 39cf75db6d5e8c86cee988d5996c7cbe79f9b5c3 (plain)
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
#include "../command.h"

static void help(void) {
    printf("Usage: yes [STRING]\n\n");
    printf("Repeatedly output a line with all specified STRING(s), or 'y'.\n");
}

COMMAND(yes) {

    parse_help(argc, argv, help);

    const char* repeat;
    if (argc == 0) {
        repeat = "y";
    } else {
        repeat = argv[0];
        for (int i = 1; i < argc; i++) {
            *(argv[i]-1) = ' ';
        }
    }

    while (true) {
        printf("%s\n", repeat);
    }
}