summaryrefslogtreecommitdiff
path: root/42sh/src/builtins/unset.c
blob: 77b323ae1e4678c1ddd8021aae7ba413ad8df5e5 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "builtins.h"
#include "utils/env.h"

int unset(struct string **args)
{
    size_t i = 0;
    int var = 0;
    int fun = 0;
    while (args[i] != NULL && args[i]->data[0] == '-')
    {
        if (args[i]->data[1] == 'v')
        {
            var = 1;
            i += 1;
        }
        else if (args[i]->data[1] == 'f')
        {
            fun = 1;
            i += 1;
        }
        else
        {
            break;
        }
    }
    if (var == 0 && fun == 0)
    {
        var = 1;
        fun = 1;
    }
    // TODO unset with flag -f
    while (args[i] != NULL)
    {
        env_unset(args[i]->data);
        i += 1;
    }
    fflush(stdout);
    return 0;
}