Beispiel #1
0
int main(int argc, char* argv[])
{


      if (argc == 1)                                   				 /*if there is no argument is specify*/
  
         execute_ls();
      
      if (argc ==2){
                  if (!strcmp(argv[1], "-a")){					/* if user selict "-a" */
                                                              
                          excecute_a();
                  }

                 if (!strcmp(argv[1], "-l")){					/* if user selict "-l" */
                       
                          excecute_lp();                                    
                  }
      }

      if (argc == 3){
         strcpy(pathname, argv[2]);
         excecute_l();
      }
                                                 

 
    }
Beispiel #2
0
int main(int argc, char *argv[]){
	int i, mode = NORMAL, cmdArgc;
	size_t len = INPUT_STRING_SIZE;
	char *cpt, *inputString, *cmdArgv[INPUT_STRING_SIZE], *supplement = NULL;
	inputString = (char*)malloc(sizeof(char)*INPUT_STRING_SIZE);
	while(1){
		mode = NORMAL;
		printf("OSassignment_shell-> $");
		getline( &inputString, &len, stdin);
		if(strcmp(inputString, "exit\n")== 0)
			exit(0);
		cmdArgc = parse(inputString, cmdArgv, &supplement, &mode);
		if(strcmp(*cmdArgv, "cd") == 0){
			chdir(cmdArgv[1]);
		}
		else if(strcmp(*cmdArgv,"ls")==0){
				execute_ls();
		}
		else if (strcmp(*cmdArgv,"ls-a")==0){
				excecute_a();
		}
		else if(strcmp(*cmdArgv,"ls-l")==0){
				excecute_lp();
		}
		else if(strcmp(*cmdArgv,"ps")==0){
				pidaux();
		}

	
		else
			execute(cmdArgv, mode, &supplement);//cmdargv-total input string, mode-e.g -elf -l, supplement- check the pipe supplement
	}
	return 0;
}
Beispiel #3
0
int main(int argc, char* argv[])
{
      
      if (argc ==3)
              {
                  if (!strcmp(argv[2], "-a"))                                       
                       {                                                    
                          excecute_a();
                       }

                 if (!strcmp(argv[2], "-l"))                                        
                       {
                          excecute_lp();                                    
                        }
              }
       if (argc == 2)
                       {
                          
			  printf("Enter path:\n");
                          scanf("%s",dirname);
                          p=opendir(dirname);
                          if(p==NULL)
                          {
                            perror("Cannot find directory");
                             exit(-1);
                          }
                          while(d=readdir(p))
                          {
                            if((d->d_name[0])!='.')

                              printf("%s\n",d->d_name);      
                          }
                       }                                                
                       
 
    if (argc == 1)                                  
  
       execute_ls();
	
}