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

Added MLFQ scheduling, Fixed library dependencies issue #10

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 11 additions & 9 deletions apps/echo/init.c
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
#include "minilibc.h"

long write(int fd, void *buf, unsigned long count);
int main(void)
{
char wmsg[] = "Welcome to Echo program (written in C)!\n";
char prompt[] = "> ";
char token[512];
char key[2];
int i, p;

_printf(wmsg);
_printf(prompt);
write(1,wmsg,sizeof(wmsg));
write(1,prompt,sizeof(prompt));
p = 0;
while (1) {
/* Read a key */
if (read(0, key, 1) > 0) {
if(read(0,key,1)>0){
switch (key[0]) {
case '\r':
case '\n':
token[p] = '\0';
_printf("Echo: %s\n", token);
_printf(prompt);
int j = 0;
while (token[j] != '\0' && j < p) {
write(1, &token[j], 1);
j++;
}
write(1,&"\n",1);
write(1,prompt,sizeof(prompt));
p = 0;
break;

default:
token[p++] = key[0];
}
}
}

for(;;);
return 0;
}

31 changes: 10 additions & 21 deletions apps/echo/stdlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,19 @@

int atoi(const char *nptr)
{
char *nstr = (char *)nptr;
char isneg = 0;
int sum = 0;
int mult = 1;
int res = 0;

if(*nstr == '-') {
isneg = 1;
nstr++;
}
int sign = 1;

while(*nstr++) {
if(*nstr && !isdigit(*nstr))
return(0);
}
int i = 0;

nstr--;
while(nstr-- != (nptr + isneg)) {
sum += (*nstr - '0') * mult;
mult *= 10;
}
if (nptr[0] == '-') {
sign = -1;
i++;
}

if(isneg)
return(sum * -1);
else
return(sum);
for (; nptr[i] != '\0'; ++i)
res = res * 10 + nptr[i] - '0';
return sign * res;
}

Loading