feat(dev): expansion
This commit is contained in:
parent
609c1667af
commit
4fc43e4678
8 changed files with 36 additions and 32 deletions
|
|
@ -115,11 +115,10 @@ static bool expand_var(char **str, size_t pos, const struct hash_map *vars)
|
|||
return false;
|
||||
}
|
||||
|
||||
struct ast_command *expand(struct ast_command *command,
|
||||
const struct hash_map *vars)
|
||||
bool expand(struct ast_command *command, const struct hash_map *vars)
|
||||
{
|
||||
if (command == NULL)
|
||||
return NULL;
|
||||
return false;
|
||||
|
||||
char *str;
|
||||
size_t len;
|
||||
|
|
@ -150,7 +149,7 @@ struct ast_command *expand(struct ast_command *command,
|
|||
// variable expansion
|
||||
bool r = expand_var(&str, i, vars);
|
||||
if (r == false || str == NULL)
|
||||
return NULL;
|
||||
return false;
|
||||
|
||||
i--; // -1 because loop will increment i
|
||||
}
|
||||
|
|
@ -160,7 +159,7 @@ struct ast_command *expand(struct ast_command *command,
|
|||
{
|
||||
// error: quote not closed
|
||||
fprintf(stderr, "Error: quote not closed in string: %s\n", str);
|
||||
return NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (len != strlen(str))
|
||||
|
|
@ -169,12 +168,12 @@ struct ast_command *expand(struct ast_command *command,
|
|||
if (new_str == NULL)
|
||||
{
|
||||
// error: realloc fail
|
||||
return NULL;
|
||||
return false;
|
||||
}
|
||||
l->data = new_str;
|
||||
}
|
||||
|
||||
l = l->next;
|
||||
}
|
||||
return command;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef EXPANSION_H
|
||||
#define EXPANSION_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "../utils/hash_map/hash_map.h"
|
||||
|
|
@ -20,7 +21,6 @@ size_t parse_var_name(char *str, char **res);
|
|||
* @param vars The hash map containing variables.
|
||||
* @return A new AST command with variables expanded, or NULL on error.
|
||||
*/
|
||||
struct ast_command *expand(struct ast_command *command,
|
||||
const struct hash_map *vars);
|
||||
bool expand(struct ast_command *command, const struct hash_map *vars);
|
||||
|
||||
#endif /* ! EXPANSION_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue