-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.c
50 lines (48 loc) · 896 Bytes
/
parse.c
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
45
46
47
48
49
50
#include "hsh.h"
/**
* parse - parse input
* @info: shell information
*
* Description: This function expands aliases, variables, and word splitting
*
* Return: the final number of tokens
*/
int parse(info_t *info)
{
char **tokens, *tok;
size_t n = 0;
cmdlist_t *cmd = info->commands = cmd_to_list(info->line);
while (cmd)
{
remove_comments(cmd);
if (!cmd->tokens)
{
cmd = cmd->next;
del_cmd(&(info->commands), n);
continue;
}
expand_aliases(info->aliases, &(cmd->tokens));
if (!cmd->tokens)
{
cmd = cmd->next;
del_cmd(&(info->commands), n);
continue;
}
expand_vars(info, &(cmd->tokens));
if (!cmd->tokens)
{
cmd = cmd->next;
del_cmd(&(info->commands), n);
continue;
}
tokens = cmd->tokens;
for (tok = *tokens; tok; tok = *(++tokens))
{
*tokens = dequote(tok);
free(tok);
}
cmd = cmd->next;
++n;
}
return (n);
}