Skip to content

Commit

Permalink
fixing eof handling in shell (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
jduepmeier committed Apr 15, 2018
1 parent 54a59ef commit 1998a16
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion shell/headers/shell_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#define MAXLENGTH 100

void read_line(char dest[]);
int read_line(char dest[]);
2 changes: 1 addition & 1 deletion shell/headers/shell_sec.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void setUser(char* username);

void askPassword();

void checkLogin();
int checkLogin();

char* getPassword();

Expand Down
8 changes: 6 additions & 2 deletions shell/sources/shell_io.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#include "../headers/shell_io.h"
#include <stdio.h>

void read_line(char dest[]) {
int read_line(char dest[]) {
char buff[MAXLENGTH + 1];

fgets(buff, MAXLENGTH, stdin);
if (fgets(buff, MAXLENGTH, stdin) == NULL) {
return 0;
}

if (sscanf(buff, "%[^\n]", dest) != 1) {
dest = "";
}

return 1;
}
8 changes: 6 additions & 2 deletions shell/sources/shell_sec.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ void askPassword() {
login.password[i] = 0;
}

void checkLogin() {
int checkLogin() {

if (login.user == NULL || strlen(login.user) < 1) {
printf("We need a user: ");
char dest[MAXLENGTH];
read_line(dest);
if (!read_line(dest)) {
return 0;
}
setUser(dest);
}
if (!pgpass) {
Expand All @@ -73,6 +75,8 @@ void checkLogin() {
printf("\n");
}
}

return 1;
}

char* getPassword() {
Expand Down
8 changes: 6 additions & 2 deletions shell/sources/shell_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ void parseSet(char* input) {
int shell() {

debug("shell init");
checkLogin();
if (!checkLogin()) {
return 1;
}

char input[MAXLENGTH];
for (;;) {
printf("%s>", getUser());

read_line(input);
if (!read_line(input)) {
break;
}

if (sequals(input, "exit")) {
debug("shut down");
Expand Down

0 comments on commit 1998a16

Please sign in to comment.