Skip to content

Commit

Permalink
Commands with params support [0.1.1]
Browse files Browse the repository at this point in the history
  • Loading branch information
ashokgelal committed Sep 17, 2011
1 parent 2806ee9 commit 6888efc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions src/dash.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,35 @@ void clearScreen(){
fprintf(stderr, "waitpid error");
}

void parseParameters(char const *line, char *params[])
{
char *delim = " ";
char *temp = strdup(line);
int i = 0;
params[i++] = strtok(temp, delim);

while(1) {
char * tok = strtok(NULL, delim);
params[i++] = tok;
if(tok == NULL)
break;
}
}

int handleCommand(char *line)
{
if(line==NULL || line=='\0')
return 0;

if(strcmp(line, "exit") == 0 || strcmp(line, "logout") == 0)
{
return EXIT_SHELL;
}

if((last_child_pid = fork()) < 0)
fprintf(stderr, "fork error\n");
else if(last_child_pid == 0){
execlp(line, line, (char *)0);
char *param[2050];
parseParameters(line, param);
execvp(param[0], param);
fprintf(stderr, "couldn't run %s\n", line);
exit(127);
}
Expand Down
2 changes: 1 addition & 1 deletion src/version.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "version.h"

const char* getVersion(){
const char* VERSION="0.0.7";
const char* VERSION="0.1.1";
return VERSION;
}

0 comments on commit 6888efc

Please sign in to comment.