예제 #1
0
파일: display.c 프로젝트: Tastyep/corewar
void	cmd(t_all *g_all, t_sel *sel, t_dis *dis)
{
  char	buf[4];

  while (1)
    {
      init_control(sel, buf);
      if (read(0, buf, 4) == -1)
	error(2);
      if (ENTER)
      	send_select(g_all, sel);
      else if (ESC)
	{
	  myclear(g_all);
	  mfree();
	}
      else if (SPACE)
	mselect(sel);
      else if (UP || DOWN)
	displacement_verti(sel, buf[2]);
      else if (RIGHT || LEFT)
	displacement_hori(sel, buf[2]);
      else if (DEL || BSPACE)
	sup_elem(g_all, sel);
      else if (SELECT || POS)
      	adds(g_all, sel, buf[0]);
    }
}
예제 #2
0
int main(int argc, char** argv)
{
	int count=0, i=0, cmp, j, valid=0;
	char key[MAX];
	
	//run the shell till user inputs 'quit' or Ctrl-C
	while(strcmp(cmdline, "quit") != 0)
	{
		count = 0;
		
		//our shell's prompt
		printf("afreen@myShell $ ");
		//get command line input
		gets(cmdline);
		
		//tokenize the CL input delimited by " " using strtok() into args
		args[count++] = strtok(cmdline, " ");
		
		//tokenize the entire string till the next token encountered
		//does not have a NULL pointer
		while((args[count++] = strtok(NULL, " ")));
		count--;		//no of arguments (argc)
		
		//if user wants to clear screen
		if(strcmp(args[0], "clear") == 0)
		{
			myclear();
		}
		
		//checking for the input command
		strcpy(key, args[0]);
		for(i=0; i<18; i++)	//look through our check array for command
		{
		  if(strcmp(check[i], key) == 0)
		  {
		      valid = -1;
		      switch(i)
		      {
		        case 0:   mycat(count, args);
		                  break;
		        
		        case 1:   mycd(count, args);
		                  break;
          
		        case 2:   mycp(count, args);
		                  break;
		         
		        case 3:   mydate(count, args);
		                  break;
		          
		        case 4:   myhead(count, args);
		                  break;
		                  
		        case 5:   myls(count, args);
		                  break;
		                  
		        case 6:   myll(count, args);
		                  break;
		                  
		        case 7:   myln(count, args);
		                  break;
		                  
		        case 8:   myld(count, args);
		                  break;
		                  
		        case 9:   mymkdir(count, args);
		                  break;
		                  
		        case 10:  mymv(count, args);
		                  break;
		                  
		        case 11:  mypwd(count, args);
		                  break;
		                  
		        case 12:  myrm(count, args);
		                  break;
		                  
		        case 13:  myrmdir(count, args);
		                  break;
		                  
		        case 14:  mytail(count, args);
		                  break;
		                  
		        case 15:  mytime(count, args);
		                  break;
		                  
		        case 16:  mytouch(count, args);
		                  break;
		                  
		        case 17:  myuname(count, args);
		                  break;
		                  		        
		        default: printf("%s: Command not found\n", key);
		    		  break;
		      }	
		      break;  
		  }
		}
		
		
  	}
  	return 0;
}