Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/pdomins/SO_TP2 into main
Browse files Browse the repository at this point in the history
  • Loading branch information
JuArce committed May 23, 2021
2 parents 9d5041e + 89a6bb5 commit 10ddcac
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
8 changes: 7 additions & 1 deletion Kernel/drivers/keyboardDriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,14 @@ void keyboard_management(uint64_t *rsp) {
secondChar = blockMayus ? 1 - shiftPressed : shiftPressed;
}
if (ctrlPressed) {
if (pressCodes[scan_code][secondChar] == 's')
if (pressCodes[scan_code][secondChar] == 's') {
takeSnapshot(rsp);
return;
}
if (pressCodes[scan_code][secondChar] == 'c') {
buffer[curr++] = -1;
curr %= BUFFER_SIZE;
}
return;
}
buffer[curr++] = pressCodes[scan_code][secondChar];
Expand Down
8 changes: 7 additions & 1 deletion Userland/SampleCodeModule/include/apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <stdint.h>

#define PROGRAMS 14
#define PROGRAMS 17

typedef struct {
char name[12];
Expand Down Expand Up @@ -47,4 +47,10 @@ void block(int args, char argv[][25]);

void mem(int args, char argv[][25]);

void cat(int args, char argv[][25]);

void wc(int args, char argv[][25]);

void filter(int args, char argv[][25]);

#endif
68 changes: 68 additions & 0 deletions Userland/SampleCodeModule/utilities/apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ programs commands[] = {{"about", about, " Information about
{"nice", nice, " Changes the given process priority."},
{"block", block, " Changes the process state given its ID."},
{"mem", mem, " Displays the current state of the memory."},
{"cat", cat, " Prints from STDIN as received."},
{"wc", wc, " Retrieves the amount of lines from input."},
{"filter", filter, " Filters the vowels of the input."},
{"exceptionZ", throwDivZero, " Throws a divide by zero exception"},
{"exceptionOP", throwInvOpCode, "Throws an invalid Operation Code Exception"}
};
Expand Down Expand Up @@ -195,3 +198,68 @@ void mem(int args, char argv[][25]) {
println(buffer);
}

void cat(int args, char argv[][25]){
int i = 0;
char c, buffer[50] = {0};
while((c=getChar()) != -1) {
if (c != 0) {
switch (c) {
case '\b':
if (i > 0) {
buffer[--i] = 0;
removeChar();
}
break;
case '\n':
println("");
buffer[i] = 0;
println(buffer);
i = 0;
break;
default:
buffer[i++] = c;
putChar(c);
}
}
}
}

void wc(int args, char argv[][25]){
int lines = 0;
int c;
while((c=getChar())!= -1) {
putChar(c);
if (c == '\n'){
lines++;
}
}
print("Total lines: ");
printInt(lines); println("");
}

#define VOWEL(c) (((c) == 'a') || ((c) == 'e') || ((c) == 'i') || ((c) == 'o') || ((c) == 'u') || ((c) == 'A') || ((c) == 'E') || ((c) == 'I') || ((c) == 'O') || ((c) == 'U'))
void filter(int args, char argv[][25]){
int i = 0;
char c, buffer[50] = {0};
while((c=getChar()) != -1) {
if (c != 0) {
switch (c) {
case '\b':
if (i > 0) {
buffer[--i] = 0;
removeChar();
}
break;
case '\n':
println("");
buffer[i] = 0;
println(buffer);
i = 0;
break;
default:
if(!VOWEL(c)) buffer[i++] = c;
putChar(c);
}
}
}
}

0 comments on commit 10ddcac

Please sign in to comment.