Commit 68241659 authored by pêle-mêle's avatar pêle-mêle
Browse files

fix parse variables

parent 805d63a5
......@@ -79,6 +79,7 @@ typedef struct s_xe
int backup_stdin;
int backup_stdout;
int stat_loc;
uint8_t pad[4];
char *line;
char **env;
char **exported;
......
......@@ -53,7 +53,8 @@ typedef struct s_state_machine
enum e_state state;
int stat_loc;
t_byte pipe_flag;
uint8_t pad[7];
t_byte var_state;
uint8_t pad[6];
} t_state_machine;
typedef char *(*t_parse)(t_state_machine *, char *);
......
......@@ -24,5 +24,5 @@ char *get_var_value(char **vars, char *name, size_t name_len)
vars++;
}
}
return (NULL);
return (ft_strdup(""));
}
......@@ -101,8 +101,6 @@ int handle_execution(t_xe *xe, int fd_in, int proc)
cur_command = parse_one_command(xe);
if (cur_command == NULL)
return (MALLOC_ERR);
(void)fd_in;
(void)proc;
if (cur_command->args != NULL)
{
return (handle_command(cur_command, xe, fd_in, proc));
......
......@@ -130,6 +130,7 @@ char *parse_variable(t_state_machine *machine, char *line)
}
free(var_value);
line += var_name_len;
machine->var_state = TRUE;
return (line);
}
......@@ -137,7 +138,9 @@ int add_arg(t_state_machine *machine)
{
if (reset_buf(machine) == FAILURE)
return (FAILURE);
*machine->cur_token_stack = push_str_to_array(*machine->cur_token_stack, machine->cur_arg);
if (machine->var_state == FALSE || machine->cur_arg[0] != '\0')
*machine->cur_token_stack = push_str_to_array(*machine->cur_token_stack, machine->cur_arg);
machine->var_state = FALSE;
if (*machine->cur_token_stack == NULL)
{
free(machine->cur_arg);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment