-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsh.c
158 lines (115 loc) · 3.03 KB
/
sh.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// User space program: sh shell
#include "utypes.h"
#define MAXARGS 10
char *title = "ErwinOS shell loaded.\n";
void main()
{
char *line[64], *cmd, *argv[MAXARGS];
int n, i;
cmd = malloc(64);
printf(0,"sh: malloc returned: %x", cmd);
//argv = malloc(128);
//printf(0, "cmd loc: %d", (unsigned int)cmd);
printf(0,"%s", title);
for(;;){ // endless loop
printf(0,"\nErwinOS:/ $ ");
n = read(0, line, 64);
//printf(0,"sh: line>>>>>>%s<<<<<<", line);
n = splitline(line, cmd, n);
printf(0, "Executing: %s", cmd);
argv[0] = cmd;
argv[1] = 0;
if(fork() == 0) // child process
exec(cmd, argv);
waitt(); // parent waits for child to exit
}
}
int splitline(char *line, char *cmd, int len)
{
char *s, *space;
int k, i;// User space program: sh shell
#include "utypes.h"
char *title = "ErwinOS shell loaded.\n";
void main()
{
char *line[64], *cmd, *argv;
int n;
cmd = malloc(64);
printf(0,"sh: malloc returned: %x", cmd);
//argv = malloc(128);
// User space program: sh shell
#include "utypes.h"
char *title = "ErwinOS shell loaded.\n";
void main()
{
char *line[64], *cmd, *argv;
int n;
cmd = malloc(64);
printf(0,"sh: malloc returned: %x", cmd);
//argv = malloc(128);
//printf(0, "cmd loc: %d", (unsigned int)cmd);
printf(0,"%s", title);
printf(0,"ErwinOS:/ $ ");
n = read(0, line, 64);
//printf(0,"sh: line>>>>>>%s<<<<<<", line);
n = splitline(line, cmd, n);
printf(0, "Executing: %s", cmd);
if(fork() == 0) // child process
exec(cmd, 0);
waitt(); // parent waits for child to exit
}
int splitline(char *line, char *cmd, int len)
{
char *s, *space;
int k, i;
if((space = strchr(line, 0x20)) == 0){
i = strlen(line);
} else {
// printf(0,"\nparseline: line ptr: %x and cmd pitr: %x and fspace: %p", line, cmd, space);
i = (uint32_t)space - (uint32_t)line;
//printf(0, "\nparseline: i: %d", i);
}
memmove(cmd, line, i);
printf(0,"parseline: strchr returned");
return len;
}
// NEED MALLOC! GOT IT!
//printf(0, "cmd loc: %d", (unsigned int)cmd);
printf(0,"%s", title);
printf(0,"ErwinOS:/ $ ");
n = read(0, line, 64);
//printf(0,"sh: line>>>>>>%s<<<<<<", line);
n = splitline(line, cmd, n);
printf(0, "Executing: %s", cmd);
if(fork() == 0) // child process
exec(cmd, 0);
waitt(); // parent waits for child to exit
}
int splitline(char *line, char *cmd, int len)
{
char *s, *space;
int k, i;
if((space = strchr(line, 0x20)) == 0){
i = strlen(line);
} else {
// printf(0,"\nparseline: line ptr: %x and cmd pitr: %x and fspace: %p", line, cmd, space);
i = (uint32_t)space - (uint32_t)line;
//printf(0, "\nparseline: i: %d", i);
}
memmove(cmd, line, i);
printf(0,"parseline: strchr returned");
return len;
}
// NEED MALLOC! GOT IT!
if((space = strchr(line, 0x20)) == 0){
i = strlen(line);
} else {
// printf(0,"\nparseline: line ptr: %x and cmd pitr: %x and fspace: %p", line, cmd, space);
i = (uint32_t)space - (uint32_t)line;
//printf(0, "\nparseline: i: %d", i);
}
memmove(cmd, line, i);
printf(0,"parseline: strchr returned");
return len;
}
// NEED MALLOC! GOT IT!