feat(builtin): add the founction to read exit status
This commit is contained in:
parent
d9f5d5a708
commit
0a3efb2bd9
3 changed files with 24 additions and 14 deletions
14
builtin.c
14
builtin.c
|
@ -2,7 +2,7 @@
|
|||
* @Author: 1ridic
|
||||
* @Date: 2022-09-18 14:16:19
|
||||
* @Last Modified by: 1ridic
|
||||
* @Last Modified time: 2022-09-18 20:46:12
|
||||
* @Last Modified time: 2022-09-18 23:32:50
|
||||
*/
|
||||
#include "builtin.h"
|
||||
#include <stdio.h>
|
||||
|
@ -18,12 +18,13 @@ int dish_clear(char **args);
|
|||
int dish_setenv(char **args);
|
||||
int dish_echo(char **args);
|
||||
int dish_unset(char **args);
|
||||
int dish_laststatus(char **args);
|
||||
|
||||
char *builtin_cmd[] = {"cd", "help", "exit", "clear", "setenv", "echo", "unset"};
|
||||
char *builtin_cmd[] = {"cd", "help", "exit", "clear", "setenv", "echo", "unset","laststatus"};
|
||||
|
||||
int (*builtin_func[])(char **) = {&dish_cd, &dish_help, &dish_exit,
|
||||
&dish_clear, &dish_setenv, &dish_echo,
|
||||
&dish_unset};
|
||||
&dish_unset,&dish_laststatus};
|
||||
|
||||
int getBuiltinNum() { return sizeof(builtin_cmd) / sizeof(char *); }
|
||||
|
||||
|
@ -79,3 +80,10 @@ int dish_unset(char **args) {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dish_laststatus(char **args)
|
||||
{
|
||||
extern int status;
|
||||
fprintf(stdout,"%d\n",status);
|
||||
return 0;
|
||||
}
|
4
exec.c
4
exec.c
|
@ -2,7 +2,7 @@
|
|||
* @Author: 1ridic
|
||||
* @Date: 2022-09-18 14:14:23
|
||||
* @Last Modified by: 1ridic
|
||||
* @Last Modified time: 2022-09-18 23:21:56
|
||||
* @Last Modified time: 2022-09-18 23:31:39
|
||||
*/
|
||||
#include "builtin.h"
|
||||
#include <stdio.h>
|
||||
|
@ -45,7 +45,7 @@ int forkExec(char **args) {
|
|||
return WTERMSIG(stat_val);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return -100;
|
||||
}
|
||||
|
||||
int commandExec(char **args) {
|
||||
|
|
12
loop.c
12
loop.c
|
@ -2,14 +2,16 @@
|
|||
* @Author: 1ridic
|
||||
* @Date: 2022-09-18 14:13:53
|
||||
* @Last Modified by: 1ridic
|
||||
* @Last Modified time: 2022-09-18 14:13:53
|
||||
* @Last Modified time: 2022-09-18 23:32:02
|
||||
*/
|
||||
#include "loop.h"
|
||||
#include "exec.h"
|
||||
#include "line.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "line.h"
|
||||
#include "loop.h"
|
||||
#include "exec.h"
|
||||
|
||||
int status;
|
||||
|
||||
int loop() {
|
||||
|
||||
|
@ -18,7 +20,7 @@ int loop() {
|
|||
printf("> ");
|
||||
line = readLine();
|
||||
args = splitLine(line);
|
||||
commandExec(args);
|
||||
status = commandExec(args);
|
||||
free(line);
|
||||
free(args);
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue