Skip to content

Commit 90cd98a

Browse files
Update shell.c
1 parent 258ae84 commit 90cd98a

File tree

1 file changed

+177
-177
lines changed

1 file changed

+177
-177
lines changed

src/ext/shell.c

Lines changed: 177 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -7,190 +7,190 @@ int folderIndex(char *file, char parent, char *path);
77
// void createSymbolicLink(char currentDirectory, char *first, char *second);
88
void addParameter(char *param, char currentDirectory);
99

10-
// int main()
11-
// {
12-
// char command[256];
13-
// char program[256];
14-
// char parameter[256];
15-
// char secondParameter[256];
16-
// char file[1024];
17-
// char commandHistory[1024];
18-
// char fileBuffer[8192];
19-
// char currentDirectory = 0xFF;
10+
int main()
11+
{
12+
char command[256];
13+
char program[256];
14+
char parameter[256];
15+
char secondParameter[256];
16+
char file[1024];
17+
char commandHistory[1024];
18+
char fileBuffer[8192];
19+
char currentDirectory = 0xFF;
2020

21-
// int i;
22-
// int indexToMove;
23-
// int indexPath;
24-
// int flag;
25-
// int historyPointer;
26-
// int historyCount = 0;
27-
// int arrowPressed = 0;
28-
// historyPointer = -1;
29-
// // printString("Shell called\n");
30-
// clear(commandHistory, 256 * 4);
21+
int i;
22+
int indexToMove;
23+
int indexPath;
24+
int flag;
25+
int historyPointer;
26+
int historyCount = 0;
27+
int arrowPressed = 0;
28+
historyPointer = -1;
29+
// printString("Shell called\n");
30+
clear(commandHistory, 256 * 4);
3131

32-
// while (1)
33-
// {
34-
// clear(command, 256);
35-
// if (arrowPressed == 0)
36-
// {
37-
// printCurrentDirectory(currentDirectory);
38-
// }
39-
// readString(command);
40-
// // printString("Else called\n");
32+
while (1)
33+
{
34+
clear(command, 256);
35+
if (arrowPressed == 0)
36+
{
37+
printCurrentDirectory(currentDirectory);
38+
}
39+
readString(command);
40+
// printString("Else called\n");
4141

42-
// printString("\r\n");
43-
// // interrupt(0x21, 0x01, command, 0, 0);
44-
// if (command[0] == 0x00)
45-
// {
46-
// printString(command);
47-
// printString("\n");
48-
// if (command[1] == 0x48) // Key up
49-
// {
50-
// if (historyPointer < historyCount - 1) // Masih bisa up
51-
// {
52-
// historyPointer++;
53-
// printString(commandHistory + historyPointer * 256);
54-
// }
55-
// }
56-
// else if (command[1] == 0x50) // Key down
57-
// {
58-
// if (historyPointer >= 0) // Masih bisa down
59-
// {
60-
// historyPointer--;
61-
// if (historyPointer != -1)
62-
// {
63-
// printString(command + historyPointer * 256);
64-
// }
65-
// }
66-
// }
67-
// arrowPressed = 1;
68-
// }
69-
// else
70-
// {
71-
// if (strbcmp(command, 2, "cd"))
72-
// {
73-
// splitString(command, program, parameter, ' ');
74-
// readSector(file, 0x101);
75-
// readSector(file + 512, 0x102);
76-
// // printString(&currentDirectory);
77-
// // printString("\r\n");
42+
printString("\r\n");
43+
// interrupt(0x21, 0x01, command, 0, 0);
44+
if (command[0] == 0x00)
45+
{
46+
printString(command);
47+
printString("\n");
48+
if (command[1] == 0x48) // Key up
49+
{
50+
if (historyPointer < historyCount - 1) // Masih bisa up
51+
{
52+
historyPointer++;
53+
printString(commandHistory + historyPointer * 256);
54+
}
55+
}
56+
else if (command[1] == 0x50) // Key down
57+
{
58+
if (historyPointer >= 0) // Masih bisa down
59+
{
60+
historyPointer--;
61+
if (historyPointer != -1)
62+
{
63+
printString(command + historyPointer * 256);
64+
}
65+
}
66+
}
67+
arrowPressed = 1;
68+
}
69+
else
70+
{
71+
if (strbcmp(command, 2, "cd"))
72+
{
73+
splitString(command, program, parameter, ' ');
74+
readSector(file, 0x101);
75+
readSector(file + 512, 0x102);
76+
// printString(&currentDirectory);
77+
// printString("\r\n");
7878

79-
// indexToMove = folderIndex(file, currentDirectory, parameter);
80-
// if (indexToMove == -1)
81-
// {
82-
// printString("No such folder\r\n");
83-
// }
84-
// else
85-
// {
86-
// currentDirectory = indexToMove;
87-
// }
88-
// }
89-
// // else if (strbcmp(command, 2, "ls"))
90-
// // {
91-
// // // interrupt(0x21, 0x02, file, 0x101, 0);
92-
// // // interrupt(0x21, 0x02, file + 512, 0x102, 0);
93-
// // readSector(file, 0x101);
94-
// // readSector(file + 512, 0x102);
95-
// // for (i = 0; i < 64; i++)
96-
// // {
97-
// // if (file[i * 16] == currentDirectory)
98-
// // {
99-
// // printString(file + i * 16 + 2);
100-
// // printString("\r\n");
101-
// // }
102-
// // }
103-
// // }
104-
// // else if (strbcmp(command, 3, "cat"))
105-
// // {
106-
// // splitString(command, program, parameter, ' ');
107-
// // clear(fileBuffer, 8192);
108-
// // // printString(parameter);
109-
// // // printString("\r\n");
110-
// // // if (strcmp("test", parameter))
111-
// // // {
112-
// // // printString("sama hehe\r\n");
113-
// // // }
114-
// // // printString("\r\n");
115-
// // // printString(parameter);
116-
// // // printString("\r\n");
79+
indexToMove = folderIndex(file, currentDirectory, parameter);
80+
if (indexToMove == -1)
81+
{
82+
printString("No such folder\r\n");
83+
}
84+
else
85+
{
86+
currentDirectory = indexToMove;
87+
}
88+
}
89+
// else if (strbcmp(command, 2, "ls"))
90+
// {
91+
// // interrupt(0x21, 0x02, file, 0x101, 0);
92+
// // interrupt(0x21, 0x02, file + 512, 0x102, 0);
93+
// readSector(file, 0x101);
94+
// readSector(file + 512, 0x102);
95+
// for (i = 0; i < 64; i++)
96+
// {
97+
// if (file[i * 16] == currentDirectory)
98+
// {
99+
// printString(file + i * 16 + 2);
100+
// printString("\r\n");
101+
// }
102+
// }
103+
// }
104+
// else if (strbcmp(command, 3, "cat"))
105+
// {
106+
// splitString(command, program, parameter, ' ');
107+
// clear(fileBuffer, 8192);
108+
// // printString(parameter);
109+
// // printString("\r\n");
110+
// // if (strcmp("test", parameter))
111+
// // {
112+
// // printString("sama hehe\r\n");
113+
// // }
114+
// // printString("\r\n");
115+
// // printString(parameter);
116+
// // printString("\r\n");
117117

118-
// // // printInteger(strlen(parameter));
119-
// // // printString("\r\n");
120-
// // // interrupt(0x21, (currentDirectory << 8) + 0x04, fileBuffer, parameter, &flag);
121-
// // readFile(fileBuffer, parameter, &flag, currentDirectory);
122-
// // // printString("\r\n");
123-
// // // printInteger(flag);
124-
// // // printString("\r\n");
118+
// // printInteger(strlen(parameter));
119+
// // printString("\r\n");
120+
// // interrupt(0x21, (currentDirectory << 8) + 0x04, fileBuffer, parameter, &flag);
121+
// readFile(fileBuffer, parameter, &flag, currentDirectory);
122+
// // printString("\r\n");
123+
// // printInteger(flag);
124+
// // printString("\r\n");
125125

126-
// // if (flag == -1)
127-
// // {
128-
// // printString("No such file\n\r");
129-
// // }
130-
// // else
131-
// // {
132-
// // printString(fileBuffer);
133-
// // printString("\r\n");
134-
// // }
135-
// // }
136-
// // else if (strbcmp(command, 2, "ln"))
137-
// // {
138-
// // printString("Calling ln\r\n");
139-
// // splitStringThree(command, program, parameter, secondParameter, ' ');
140-
// // createSymbolicLink(currentDirectory, parameter, secondParameter);
141-
// // }
142-
// // else if (strbcmp(command, 7, "history"))
143-
// // {
144-
// // if (historyCount > 0)
145-
// // {
146-
// // printHistory(commandHistory, historyCount);
147-
// // }
148-
// // else
149-
// // {
150-
// // printString("No command history\r\n");
151-
// // }
152-
// // }
153-
// else
154-
// {
155-
// clear(program, 256);
156-
// clear(parameter, 256);
157-
// splitString(command, program, parameter, ' ');
158-
// printString(command);
159-
// addParameter(parameter, currentDirectory);
160-
// interrupt(0x21, 0xFF06, program, 0x3000, &flag);
161-
// if (flag == -1)
162-
// {
163-
// printString("No program found\n\r");
164-
// }
165-
// else
166-
// {
167-
// printString("\r\n");
168-
// }
169-
// }
126+
// if (flag == -1)
127+
// {
128+
// printString("No such file\n\r");
129+
// }
130+
// else
131+
// {
132+
// printString(fileBuffer);
133+
// printString("\r\n");
134+
// }
135+
// }
136+
// else if (strbcmp(command, 2, "ln"))
137+
// {
138+
// printString("Calling ln\r\n");
139+
// splitStringThree(command, program, parameter, secondParameter, ' ');
140+
// createSymbolicLink(currentDirectory, parameter, secondParameter);
141+
// }
142+
// else if (strbcmp(command, 7, "history"))
143+
// {
144+
// if (historyCount > 0)
145+
// {
146+
// printHistory(commandHistory, historyCount);
147+
// }
148+
// else
149+
// {
150+
// printString("No command history\r\n");
151+
// }
152+
// }
153+
else
154+
{
155+
clear(program, 256);
156+
clear(parameter, 256);
157+
splitString(command, program, parameter, ' ');
158+
printString(command);
159+
addParameter(parameter, currentDirectory);
160+
interrupt(0x21, 0xFF06, program, 0x3000, &flag);
161+
if (flag == -1)
162+
{
163+
printString("No program found\n\r");
164+
}
165+
else
166+
{
167+
printString("\r\n");
168+
}
169+
}
170170

171-
// if (historyCount < 4)
172-
// {
173-
// historyCount++;
174-
// }
175-
// // if (historyCount == 4)
171+
if (historyCount < 4)
172+
{
173+
historyCount++;
174+
}
175+
// if (historyCount == 4)
176176

177-
// for (i = historyCount; i >= 1; i--)
178-
// {
179-
// clear(commandHistory + i * 256, 256);
180-
// strcpy(commandHistory + (i - 1) * 256, commandHistory + 256 * i);
181-
// // printString(commandHistory + 256 * i);
182-
// // printString("\r\n");
183-
// }
184-
// clear(commandHistory, 256);
185-
// strcpy(command, commandHistory);
186-
// // printString(commandHistory);
187-
// historyPointer = -1;
188-
// arrowPressed = 0;
189-
// // printHistory(commandHistory, historyCount);
190-
// }
191-
// }
192-
// return 0;
193-
// }
177+
for (i = historyCount; i >= 1; i--)
178+
{
179+
clear(commandHistory + i * 256, 256);
180+
strcpy(commandHistory + (i - 1) * 256, commandHistory + 256 * i);
181+
// printString(commandHistory + 256 * i);
182+
// printString("\r\n");
183+
}
184+
clear(commandHistory, 256);
185+
strcpy(command, commandHistory);
186+
// printString(commandHistory);
187+
historyPointer = -1;
188+
arrowPressed = 0;
189+
// printHistory(commandHistory, historyCount);
190+
}
191+
}
192+
return 0;
193+
}
194194
// void printString(char *buffer)
195195
// {
196196
// interrupt(0x21, 0x00, buffer, 0, 0);
@@ -441,4 +441,4 @@ void splitStringThree(char *buffer, char *first, char *second, char *third, char
441441
second[secondLength] = 0x0;
442442
first[firstLength] = 0x0;
443443
third[thirdLength] = 0x0;
444-
}
444+
}

0 commit comments

Comments
 (0)