Skip to content

Commit

Permalink
History, pipe, redirections (?)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinusR committed May 12, 2017
1 parent e5f26ca commit 8215f5f
Show file tree
Hide file tree
Showing 28 changed files with 363 additions and 79 deletions.
14 changes: 13 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ File system :
- Duplication of function finddir
- Directories Improvement : open them as streams ?
- Add some malloc and free instead of 'buffer', but this will make unsafe a lot of currently safe functions !
- BUg of mv a b; rm b -> crash ? (twice)!!!

Global organisation :
- Folders ?
Expand All @@ -29,4 +30,15 @@ Malloc :
- Test
- Kernel one ?


Shell:
- Colors for directories in ls + alignement
- tree
- Implement fwrite (writes stdin into a file)
- Test redirection >
- Code cat properly to not display error message ? (special end character ?)
- Code commands to accept input from stdin ! (not all)
- Multiple arguments ?
- Options ?
- Cacatoes -> fg color ? (+print dans un fichier, le stocker, et ne faire que le charger)
- Cursor not disappearing when scroll
- Scroll with arrows
2 changes: 1 addition & 1 deletion programs/lib/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void init_error_msg() {
error_msg[43] = "Message too long";
error_msg[44] = "Too many processes";
error_msg[45] = "Too many streams";
error_msg[46] = "Protocol not supported";
error_msg[46] = "Alone on this channel";
error_msg[47] = "Socket type not supported";
error_msg[48] = "Operation not supported on socket";
error_msg[49] = "Protocol family not supported";
Expand Down
2 changes: 1 addition & 1 deletion programs/lib/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ typedef enum {
EMSGSIZE, //Message too long
EMPROC, //Too many processes
EMSTREAM, //Too many streams
EPROTONOSUPPORT, //Protocol not supported
EALONE, //Alone on this channel
ESOCKTNOSUPPORT, //Socket type not supported
EOPNOTSUPP, //Operation not supported on socket
EPFNOSUPPORT, //Protocol family not supported
Expand Down
4 changes: 4 additions & 0 deletions programs/lib/keycode.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ void initCharTable() {
chars[KEY_COLON] = ':';
chars[KEY_EXCLAMATION] = '!';
chars[KEY_COMP] = '<';
chars[KEY_UP] = 0x11;
chars[KEY_DOWN] = 0x12;
chars[KEY_LEFT] = 0x13;
chars[KEY_RIGHT] = 0x14;

char *shift = chars + 128;
shift[KEY_A] = 'A';
Expand Down
12 changes: 8 additions & 4 deletions programs/lib/keycode.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,23 @@
#define KEY_ALT_GR 56
#define KEY_SPACE 57
#define KEY_NUM_1 79
#define KEY_NUM_2 80
#define KEY_DOWN 80
#define KEY_NUM_3 81
#define KEY_NUM_4 75
#define KEY_LEFT 75
#define KEY_NUM_5 76
#define KEY_NUM_6 77
#define KEY_RIGHT 77
#define KEY_NUM_7 71
#define KEY_NUM_8 72
#define KEY_UP 72
#define KEY_NUM_9 73
#define KEY_NUM_0 82
// TODO ARROWS have same code ?! (ci dessus)
#define KEY_COMP 86
#define TERMINATION_KEY 0

#define CHAR_UP 0x11
#define CHAR_DOWN 0x12
#define CHAR_LEFT 0x13
#define CHAR_RIGHT 0x14
char getKeyChar(u8 key, u8 shift, u8 alt);
void initCharTable();

Expand Down
8 changes: 7 additions & 1 deletion programs/lib/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ void clear_screen(u8 color) {
set_char_at(' ', color, color, x , y);
}

u32 last_rand = 1351968;
u32 last_rand;

u32 rand() {

last_rand = (last_rand * 16807) % (((u32) 1 << 31) -1);
return last_rand;
}
Expand All @@ -27,6 +28,11 @@ void lib_init() {
create_channel_stream(1);
initCharTable();
init_error_msg();
rtc_time_t t;
gettimeofday(&t);
last_rand = ((u32) 16807 * 16807 * 16807 * ((u32) t.century - (u32) t.year + (u32) t.month) +
16807 * 16807 * ((u32)t.day - (u32)t.hours) +
16807 * ((u32)t.minutes + (u32)t.seconds) + 49 * (u32)t.mseconds) % (((u32) 1 << 31) - 1);
}

void *memcpy(void *dst, void *src, u32 n) {
Expand Down
2 changes: 1 addition & 1 deletion programs/lib/parsing.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ int string_to_int(char *src) {
}

void too_many_args(char *fun) {
fprintf(STDERR, "%s: Too many arguments", fun);
fprintf(STDERR, "%s: Too many arguments\n", fun);
exit(EXIT_FAILURE);
}
3 changes: 2 additions & 1 deletion programs/lib/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ int flush(sid_t sid) {
if (is_channel) {
int ready = wait_channel(stream->chanid, 1);
while (ready == -1) {
if (errno == EALONE)
return -1;
sleep(10);
ready = wait_channel(stream->chanid, 1);
}
wait_channel(stream->chanid, 1);
written = send(stream->chanid, index, remaining);
}
else {
Expand Down
1 change: 0 additions & 1 deletion programs/src/cacatoes/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ int main(char *args) {
break;
}
flush(STDOUT);
sleep(500);
exit(EXIT_SUCCESS);
return 0;
}
16 changes: 8 additions & 8 deletions programs/src/cat/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ int main(char *args) {
while (run) {
nb = wait_channel(STDIN, 0);
if (nb < 0) {
fprintf(STDERR, "cat: Cannot read input: %s", strerror(errno));
fprintf(STDERR, "cat: Cannot read input: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
nb = receive(STDIN, buffer, 512);
if (nb < 0) {
fprintf(STDERR, "cat: Cannot read input: %s", strerror(errno));
fprintf(STDERR, "cat: Cannot read input: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
for (int j = 0; j < nb; j++) {
Expand All @@ -32,12 +32,12 @@ int main(char *args) {
while (nb > 0) {
written = wait_channel(STDOUT, 1);
if (written < 0) {
fprintf(STDERR, "cat: Cannot write to output: %s", strerror(errno));
fprintf(STDERR, "cat: Cannot write to output: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
written = send(STDOUT, buffer, nb);
if (written < 0) {
fprintf(STDERR, "cat: Cannot write to output: %s", strerror(errno));
fprintf(STDERR, "cat: Cannot write to output: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
nb -= written;
Expand All @@ -47,7 +47,7 @@ int main(char *args) {
if (nb_args == 1) {
fd_t fd = fopen(path, O_RDONLY);
if (fd < 0) {
fprintf(STDERR, "cat: Couldn't open %s: %s", path, strerror(errno));
fprintf(STDERR, "cat: Couldn't open %s: %s\n", path, strerror(errno));
exit(EXIT_FAILURE);
}
char buffer[512];
Expand All @@ -60,20 +60,20 @@ int main(char *args) {
exit(EXIT_SUCCESS);
}
if (nb == -1) {
fprintf(STDERR, "cat: Failed to read file %s: %s", path, strerror(errno));
fprintf(STDERR, "cat: Failed to read file %s: %s\n", path, strerror(errno));
close(fd);
exit(EXIT_FAILURE);
}
while (nb > 0) {
written = wait_channel(STDOUT, 1);
if (written < 0) {
fprintf(STDERR, "cat: Cannot write to output: %s", strerror(errno));
fprintf(STDERR, "cat: Cannot write to output: %s\n", strerror(errno));
close(fd);
exit(EXIT_FAILURE);
}
written = send(STDOUT, buffer, nb);
if (written < 0) {
fprintf(STDERR, "cat: Cannot write to output: %s", strerror(errno));
fprintf(STDERR, "cat: Cannot write to output: %s\n", strerror(errno));
close(fd);
exit(EXIT_FAILURE);
}
Expand Down
6 changes: 3 additions & 3 deletions programs/src/cp/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ int main(char *args) {
too_many_args("cp");

if (nb == 0) {
fprintf(STDERR, "cp: Missing operands");
fprintf(STDERR, "cp: Missing operands\n");
exit(EXIT_FAILURE);
}
if (nb == 1) {
fprintf(STDERR, "cp: Missing destination operand");
fprintf(STDERR, "cp: Missing destination operand\n");
exit(EXIT_FAILURE);
}
char *src = paths[0];
char *dest = paths[1];

int res = fcopy(src, dest);
if (res != 0) {
fprintf(STDERR, "cp: Cannot copy %s to %s: %s", src, dest, strerror(errno));
fprintf(STDERR, "cp: Cannot copy %s to %s: %s\n", src, dest, strerror(errno));
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
Expand Down
4 changes: 2 additions & 2 deletions programs/src/kill/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ int main(char *args) {
return 0;
}
if (nb_args == 0) {
fprintf(STDERR, "kill: Missing poor target process");
fprintf(STDERR, "kill: Missing poor target process\n");
exit(EXIT_FAILURE);
}
if (nb_args == 1) {
errno = EINVAL;
pid = string_to_int(pid_string);
if (pid == -1 || kill_rec(pid) == -1) {
fprintf(STDERR, "kill: Cannot kill process %s: %s", pid_string, strerror(errno));
fprintf(STDERR, "kill: Cannot kill process %s: %s\n", pid_string, strerror(errno));
exit(EXIT_FAILURE);
}
}
Expand Down
5 changes: 3 additions & 2 deletions programs/src/ls/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main(char *args) {
}
fd_t fd = opendir(args);
if (fd < 0) {
fprintf(STDERR, "ls: Cannot open directory / %s: %s", args, strerror(errno));
fprintf(STDERR, "ls: Cannot open directory / %s: %s\n", args, strerror(errno));
exit(EXIT_FAILURE);
}
int res = readdir(fd, &dirent);
Expand All @@ -18,9 +18,10 @@ int main(char *args) {
int err = errno;
closedir(fd);
if (err != ENOENT) {
fprintf(STDERR, "\nls: An error occured while reading %s: %s", args, strerror(errno));
fprintf(STDERR, "\nls: An error occured while reading %s: %s\n", args, strerror(errno));
exit(EXIT_FAILURE);
}
printf("\n");
flush(STDOUT);
exit(EXIT_SUCCESS);
return 0;
Expand Down
4 changes: 2 additions & 2 deletions programs/src/mkdir/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

int main(char *args) {
if (!*args) {
fprintf(STDERR, "mkdir: Missing operand");
fprintf(STDERR, "mkdir: Missing operand\n");
exit(EXIT_FAILURE);
}
int res = mkdir(args, 0);
if (res != 0) {
fprintf(STDERR, "mkdir: Cannot create directory '%s': %s", args, strerror(errno));
fprintf(STDERR, "mkdir: Cannot create directory '%s': %s\n", args, strerror(errno));
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
Expand Down
6 changes: 3 additions & 3 deletions programs/src/mv/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ int main(char *args) {
too_many_args("mv");

if (nb == 0) {
fprintf(STDERR, "mv: Missing operands");
fprintf(STDERR, "mv: Missing operands\n");
exit(EXIT_FAILURE);
}
if (nb == 1) {
fprintf(STDERR, "mv: Missing destination operand");
fprintf(STDERR, "mv: Missing destination operand\n");
exit(EXIT_FAILURE);
}
char *src = paths[0];
char *dest = paths[1];

int res = aux_mv(src, dest);
if (res != 0) {
fprintf(STDERR, "mv: Cannot rename %s into %s: %s", src, dest, strerror(errno));
fprintf(STDERR, "mv: Cannot rename %s into %s: %s\n", src, dest, strerror(errno));
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
Expand Down
6 changes: 3 additions & 3 deletions programs/src/p/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
u8 recv_buff[513];

int main() {
clear_screen(COLOR_BLUE);
clear_screen(BLUE);
u8 c = '%';
if(send(1, &c, 1) < 0) {
int err = errno;
set_char_at('0'+err/10, COLOR_GREEN, COLOR_BLUE, 0, 0);
set_char_at('0'+err%10, COLOR_GREEN, COLOR_BLUE, 1, 0);
set_char_at('0'+err/10, GREEN, BLUE, 0, 0);
set_char_at('0'+err%10, GREEN, BLUE, 1, 0);
for(;;);
}
for(u8 i = 0;; i++) {
Expand Down
1 change: 1 addition & 0 deletions programs/src/ps/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ int main(char *args) {
pid++;
res = pinfo(pid, &p);
}
printf("\n");
exit(EXIT_SUCCESS);
return 0;
}
4 changes: 2 additions & 2 deletions programs/src/rm/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

int main(char *args) {
if (!*args) {
fprintf(STDERR, "rm: Missing operand");
fprintf(STDERR, "rm: Missing operand\n");
exit(EXIT_FAILURE);
}
int res = remove(args);
if (res != 0) {
fprintf(STDERR, "rm: Cannot delete '%s': %s", args, strerror(errno));
fprintf(STDERR, "rm: Cannot delete '%s': %s\n", args, strerror(errno));
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
Expand Down
4 changes: 2 additions & 2 deletions programs/src/rmdir/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

int main(char *args) {
if (!*args) {
fprintf(STDERR, "rmdir: Missing operand");
fprintf(STDERR, "rmdir: Missing operand\n");
exit(EXIT_FAILURE);
}
int res = rmdir(args);
if (res != 0) {
fprintf(STDERR, "rmdir: Cannot remove directory '%s': %s", args, strerror(errno));
fprintf(STDERR, "rmdir: Cannot remove directory '%s': %s\n", args, strerror(errno));
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
Expand Down
Loading

0 comments on commit 8215f5f

Please sign in to comment.