|
@ -170,14 +170,26 @@ void parseCommand(char *input, char **command, char ***argv, int *argc){ |
|
|
strcpy((*argv)[(*argc) - 1], *command); |
|
|
strcpy((*argv)[(*argc) - 1], *command); |
|
|
(*argv)[(*argc) - 1][strlen((*argv)[(*argc) - 1])] = '\0'; |
|
|
(*argv)[(*argc) - 1][strlen((*argv)[(*argc) - 1])] = '\0'; |
|
|
|
|
|
|
|
|
//Parses rest of the arguments
|
|
|
//Parses the rest of the arguments
|
|
|
token = strtok(NULL, " "); |
|
|
token = strtok(NULL, " "); |
|
|
while (token != NULL){ |
|
|
while (token != NULL){ |
|
|
++(*argc); |
|
|
++(*argc); |
|
|
*argv = (char**)(realloc(*argv, (*argc) * sizeof(char*))); |
|
|
*argv = (char**)(realloc(*argv, (*argc) * sizeof(char*))); |
|
|
(*argv)[(*argc) - 1] = (char*)(malloc((strlen(token) + 1) * sizeof(char))); |
|
|
|
|
|
strcpy((*argv)[(*argc) - 1], trimWhitespaces(token)); |
|
|
//Checks if argument is wrapped inside " or ' characters
|
|
|
(*argv)[(*argc) - 1][strlen((*argv)[(*argc) - 1])] = '\0'; |
|
|
if ( (token[0] == '"' && token[strlen(token) - 1] == '"' ) || |
|
|
|
|
|
(token[0] == '\'' && token[strlen(token) - 1] == '\'' ) ){ |
|
|
|
|
|
token++; |
|
|
|
|
|
token[strlen(token) - 1] = '\0'; |
|
|
|
|
|
|
|
|
|
|
|
(*argv)[(*argc) - 1] = (char*)(malloc((strlen(token)) * sizeof(char))); |
|
|
|
|
|
strcpy((*argv)[(*argc) - 1], trimWhitespaces(token)); |
|
|
|
|
|
} else { |
|
|
|
|
|
(*argv)[(*argc) - 1] = (char*)(malloc((strlen(token) + 1) * sizeof(char))); |
|
|
|
|
|
strcpy((*argv)[(*argc) - 1], trimWhitespaces(token)); |
|
|
|
|
|
(*argv)[(*argc) - 1][strlen((*argv)[(*argc) - 1])] = '\0'; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
token = strtok(NULL, " "); |
|
|
token = strtok(NULL, " "); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|