-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "shell.h" | ||
|
||
/** | ||
* clear_info - initializes info_t struct | ||
* @info: struct address | ||
*/ | ||
void clear_info(info_t *info) | ||
{ | ||
info->arg = NULL; | ||
info->argv = NULL; | ||
info->path = NULL; | ||
info->argc = 0; | ||
} | ||
|
||
/** | ||
* set_info - initializes info_t struct | ||
* @info: struct address | ||
* @av: argument vector | ||
*/ | ||
void set_info(info_t *info, char **av) | ||
{ | ||
int i = 0; | ||
|
||
info->fname = av[0]; | ||
if (info->arg) | ||
{ | ||
info->argv = strtow(info->arg, " \t"); | ||
if (!info->argv) | ||
{ | ||
|
||
info->argv = malloc(sizeof(char *) * 2); | ||
if (info->argv) | ||
{ | ||
info->argv[0] = _strdup(info->arg); | ||
info->argv[1] = NULL; | ||
} | ||
} | ||
for (i = 0; info->argv && info->argv[i]; i++) | ||
; | ||
info->argc = i; | ||
|
||
replace_alias(info); | ||
replace_vars(info); | ||
} | ||
} | ||
|
||
/** | ||
* free_info - frees info_t struct fields | ||
* @info: struct address | ||
* @all: true if freeing all fields | ||
*/ | ||
void free_info(info_t *info, int all) | ||
{ | ||
ffree(info->argv); | ||
info->argv = NULL; | ||
info->path = NULL; | ||
if (all) | ||
{ | ||
if (!info->cmd_buf) | ||
free(info->arg); | ||
if (info->env) | ||
free_list(&(info->env)); | ||
if (info->history) | ||
free_list(&(info->history)); | ||
if (info->alias) | ||
free_list(&(info->alias)); | ||
ffree(info->environ); | ||
info->environ = NULL; | ||
bfree((void **)info->cmd_buf); | ||
if (info->readfd > 2) | ||
close(info->readfd); | ||
_putchar(BUF_FLUSH); | ||
} | ||
} |