Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add report #211

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"traps.h": "c"
}
}
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ubuntu:latest

RUN apt-get update && apt-get install -y \
build-essential \
gcc \
gdb \
qemu \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /xv6

COPY . .

CMD ["bash"]
Binary file added Report/Report.pdf
Binary file not shown.
190 changes: 187 additions & 3 deletions console.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Console input and output.
// Input is from the keyboard or serial port.
// Output is written to the screen and serial port.

#include "types.h"
#include "defs.h"
#include "param.h"
Expand Down Expand Up @@ -178,6 +177,81 @@ consputc(int c)
cgaputc(c);
}

#define NULL ((void*)0)

#define MAX_CMD_SIZE 64
#define HIST_SIZE 10

typedef struct Node {
char string[MAX_CMD_SIZE];
struct Node* next;
} Node;

typedef struct {
Node* head;
Node* tail;
int size;
int capacity;
} CircularBuffer;

CircularBuffer hist;

void initCircularBuffer() {
hist.head = NULL;
hist.tail = NULL;
hist.size = 0;
hist.capacity = HIST_SIZE;
}

// Function to add a string (command) to the circular buffer
void addString(char* string) {
Node* newNode = malloc(sizeof(Node));
strncpy(newNode->string, string, MAX_CMD_SIZE);
newNode->next = NULL;

if (hist.size == 0) {
hist.head = newNode;
hist.tail = newNode;
} else {
hist.tail->next = newNode;
hist.tail = newNode;
if (hist.size == hist.capacity) {
Node* temp = hist.head;
hist.head = hist.head->next;
free(temp);
}
}
hist.size = (hist.size + 1) % hist.capacity;
}

// Function to remove the oldest string (command) from the circular buffer
void removeOldest() {
if (hist.size > 0) {
Node* temp = hist.head;
hist.head = hist.head->next;
free(temp);
hist.size--;
}
}

// Function to find a matching string (command) in the circular buffer
char* findMatchingString(char* A) {
Node* current = hist.tail;
while (current != NULL) {
if (strncmp(A, current->string, MAX_CMD_SIZE) == 0) {
return current->string;
}
current = current->next;
if (current == hist.head) {
// Reached the oldest string, stop traversing
break;
}
}
return NULL;
}



#define INPUT_BUF 128
struct {
char buf[INPUT_BUF];
Expand All @@ -188,6 +262,69 @@ struct {

#define C(x) ((x)-'@') // Control-x

#define K 4
char clipboard[K]; // saved buffer of copy-paste
int clipboard_size;

void format_string(char* format_string){
for (int i = 0; format_string[i] != '\0'; i++){
int c = format_string[i];
if (c == 32){} // space
else if (c >= 48 && c <= 57) // numbers
{
c += K;
if (c >= 58){ // if numbers goes bigger than 9
c += 7;
}
format_string[i] = (char)c;
}
else if (c >= 97 && c <= 122) // CAPITAL LETERS to small letters
{
c -= 32;
format_string[i] = (char)c;
}
else if (c >= 65 && c <= 90) // small letters to CAPITAL LETTERS
{
c += 32;
format_string[i] = (char)c;
}
else { // default for special characters -> remove
int j;
for (j = i; format_string[j] != '\0'; j++) {
format_string[j] = format_string[j + 1];
}
}
}
}

void
suggest_cmd() {
// Start from the current write index and move backwards until finding a newline character
int i = input.e - 1;
while (i >= 0 && input.buf[i % INPUT_BUF] != '\n') {
i--;
}

// Copy the incomplete command from the buffer
char input_cmd[INPUT_BUF+1];
int j = 0;
for (i++; i < input.e; i++) {
input_cmd[j++] = input.buf[i % INPUT_BUF];
}
input_cmd[j] = '\0';

// Find suggestions and display them
char* suggested_cmd = findMatchingString(input_cmd);
if (suggested_cmd != NULL) {
// Show the suggested command
consclear();
consputs(suggested_cmd);
} else {
// Beep if no suggestion found
consputc('\a');
}
}

void
consoleintr(int (*getc)(void))
{
Expand All @@ -200,6 +337,54 @@ consoleintr(int (*getc)(void))
// procdump() locks cons.lock indirectly; invoke later
doprocdump = 1;
break;

case 'C': case 'X': //copy & cut
clipboard_size = input.e - input.w > 4 ? 4 : input.e - input.w;
for (int i = 0; i < clipboard_size; i++) {
clipboard[i] = input.buf[(input.e - clipboard_size + i) % INPUT_BUF];
}

if (c == 'X'){
for (int i = 0; i < clipboard_size; i++){
if(input.e != input.w){
input.e--;
consputc(BACKSPACE);
}
}
}
break;
case 'V': //paste
for (int i = 0; i < clipboard_size; i++) {
input.buf[input.e++ % INPUT_BUF] = clipboard[i];
consputc(clipboard[i]);
}
break;

case 'E':
char input_str[INPUT_BUF];
int i = 0;
while(input.e != input.w){
input_str[i] = input.buf[i];
input.e--;
consputc(BACKSPACE);
i++;
}
input_str[i] = '\0';

format_string(input_str);

i = 0;
while(input_str[i] != '\0'){
input.buf[input.e++ % INPUT_BUF] = input_str[i];
consputc(input_str[i]);
i++;
}
break;

case '\t':
suggest_cmd(); // Call the function to suggest commands
break;

case C('U'): // Kill line.
while(input.e != input.w &&
input.buf[(input.e-1) % INPUT_BUF] != '\n'){
Expand Down Expand Up @@ -232,6 +417,7 @@ consoleintr(int (*getc)(void))
}
}


int
consoleread(struct inode *ip, char *dst, int n)
{
Expand Down Expand Up @@ -293,7 +479,5 @@ consoleinit(void)
devsw[CONSOLE].write = consolewrite;
devsw[CONSOLE].read = consoleread;
cons.locking = 1;

ioapicenable(IRQ_KBD, 0);
}

Empty file added export
Empty file.
7 changes: 7 additions & 0 deletions init.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ main(void)

for(;;){
printf(1, "init: starting sh\n");

// printing students name and id
printf(1, "Group #8 \n");
printf(1, "Ali Parvizi - 810100102 \n");
printf(1, "Mohammad Javad Afsari - 810198544 \n");
printf(1, "Mohammad Motaee - 810199493 \n");

pid = fork();
if(pid < 0){
printf(1, "init: fork failed\n");
Expand Down
Loading