Skip to content
Snippets Groups Projects
Select Git revision
  • bc0ac8e80d43e6cb6d2785dbbf952f793c27d56a
  • master default
2 results

utils.c

Blame
  • Forked from spring-2018-operating-systems / mysh-0
    Source project has a limited visibility.
    utils.c 965 B
    #include <string.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include "utils.h"
    #define MAX 250
    
    void mysh_parse_command(const char* command,
                            int *argc, char*** argv)
    {
      // TODO: Fill this!
    	
    	char *token=NULL;
    	char command1[MAX];
    	char *tmp = NULL;
    	strcpy(command1,command);
    	if(command1[strlen(command1)-1] == '\n')
    			command1[strlen(command1)-1] = '\0';
    	token = strtok(command1," =\n\"\0");
    //	**argv = (char*)malloc(sizeof(char)*MAX);
    	*argv = (char**)malloc(sizeof(char)*MAX);
    	*argc = 0;
    	while(1)
    	{
    		//printf("while\n");
    		if(token==NULL){
    				//*(*argv+(*argc)) = (char*)malloc(sizeof(char)*MAX);
    				
    				break;
    		}
    		else {
    			//printf("else\n");
    			*(*argv+(*argc)) = (char*)malloc(sizeof(char)*MAX);
    			//printf("malloc\n");
    			strcpy(*(*argv+(*argc)),token);
    			//printf("intoken\n");
    			token = strtok(NULL," =\n\0\"");
    			printf("%s\n",*(*argv+(*argc)));
    			(*argc)++;
    			//printf("%s\n",*(*argv+(*argc)));		
    		}
    	}
    
    
    
    }