|
|
@ -156,7 +156,7 @@ int check_redirect(char **args, char *redirect_filename, char **redirect_args) |
|
|
|
i++; |
|
|
|
} |
|
|
|
|
|
|
|
if (redirect_flag == 1) /* redirect output */ |
|
|
|
if ((redirect_flag == 1) || (redirect_flag == 2)) |
|
|
|
{ |
|
|
|
strcpy(redirect_filename, args[i + 1]); |
|
|
|
for (j = 0; j < i; j++) |
|
|
@ -164,15 +164,7 @@ int check_redirect(char **args, char *redirect_filename, char **redirect_args) |
|
|
|
redirect_args[j] = args[j]; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (redirect_flag == 2) /* redirect input */ |
|
|
|
{ |
|
|
|
redirect_filename = args[0]; |
|
|
|
i++; |
|
|
|
while (args[i] != NULL) |
|
|
|
{ |
|
|
|
redirect_args[j++] = args[i++]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return redirect_flag; |
|
|
|
} |
|
|
|
|
|
|
@ -181,16 +173,15 @@ int execute(char *cmdline, char **args) |
|
|
|
int bg = 0, i = 0, redirect_flag = 0, fd = 1; |
|
|
|
pid_t pid; |
|
|
|
char *redirect_filename = NULL; |
|
|
|
redirect_filename = (char *)calloc(32, sizeof(char)); |
|
|
|
redirect_filename = (char *)calloc(REDIRECT_FILENAME_MAX_SIZE, sizeof(char)); |
|
|
|
char *redirect_args[ARGS_MAX_QUANTITY]; |
|
|
|
memset(redirect_args, NULL, sizeof(redirect_args)); |
|
|
|
sigset_t mask_all, mask_prev; |
|
|
|
sigprocmask(SIG_BLOCK, NULL, &mask_all); |
|
|
|
sigaddset(&mask_all, SIGCHLD); |
|
|
|
bg = parseline(cmdline, args); |
|
|
|
redirect_flag = check_redirect(args, redirect_filename, redirect_args); |
|
|
|
|
|
|
|
printf("%s %s %s %s", redirect_args[0], redirect_args[1], redirect_args[2], redirect_filename); |
|
|
|
|
|
|
|
if (args[0] == NULL) |
|
|
|
{ |
|
|
|
return 1; |
|
|
|