示例#1
0
文件: main.c 项目: mizielr/my_cat
int	main(int argc, char **argv)
{
  int	i;
  t_opt	opts;

  if (my_opts(argc, argv, &opts))
    return (-1);
  if (argc == 1 || only_opts(argc, argv))
    read_cat(opts);
  for (i = 1; i < argc; i++)
    {
      if (argv[i] && argv[i][0] != '-')
	my_cat(argv[i], opts);
      else if (argv[i][0] == '-' && my_strlen(argv[i]) == 1)
	read_cat(opts);
    }
  return (0);
}
示例#2
0
/* Fonction: internal_command
 * Entrees: un entier représentant la position de la commande
 * a effectuer dans le tableau commande[]
 * 
 * Sortie: aucune
 * 
 * Execute une commande externe
 */
int internal_command(int pos) {
	if( strcmp(commande[pos], "exit") == 0)
	    {stockCommande(); my_exit(commande); return 1;}
	    
	else if(strcmp(commande[pos], "cd") == 0)
	    {stockCommande(); chdir(commande[pos+1]); return 1;}
	    
	else if(strcmp(commande[pos], "cat") == 0)
	    {stockCommande(); my_cat(commande[pos+1], commande[pos+2]); return 1;}
	    
	else if(strcmp(commande[pos], "history") == 0)
	    {stockCommande(); my_history(); return 1;}
	    
	else if(strcmp(commande[pos], "cp") == 0)
	    {stockCommande(); my_copy(commande[pos+1], commande[pos+2]); return 1;}  
	    
	else if(strcmp(commande[pos], "find") == 0)
		{stockCommande(); my_find(0); return 1;}
	    
	else return 0;
}
示例#3
0
文件: tests.c 项目: dbhoekman/CS360
int test_cat()
{
	char path[64] = "tiny";
	char cat1[1024], cat2[1024], cat3[1024], cat4[1024];
	int test1, test2, test3, test4;
	int passed = 1;

	printf("CAT TESTS SHOW ONLY THE LAST 64 BYTES\n");

	my_cat(path);

	test1 = strcmp(cat_test, "this is a tiny file\nend of tiny file\n");
	strcpy(cat1, cat_test);

	strcpy(path, "/X/tiny");

	my_cat(path);

	test2 = strcmp(cat_test, "this is a tiny file\nend of tiny file\n");
	strcpy(cat2, cat_test);

	strcpy(path, "/Y/bigfile");

	my_cat(path);

	test3 = strcmp(cat_test, "certainly makes sense since each .c file\n# depends on the TYPEs ");
	strcpy(cat3, cat_test);

	strcpy(path, "/Z/hugefile");

	my_cat(path);

	test4 = strcmp(cat_test, "o the data block */\n     get_block(mip->dev, blk, wbuf);   // re");
	strcpy(cat4, cat_test);

	//printf("\033[H\033[J");
	system("clear");
	system("clear");
	system("clear");
	system("clear");

	//test 1
	printf("EXPECTED:\n");

	printf("this is a tiny file\nend of tiny file\n");

	printf("\nACTUAL:\n%s\n", cat1);

	if(test1)
	{
		printf("cat tiny failed\n");
		passed = 0;
	}
	else
		printf("cat tiny passed\n");

	//test 2
	printf("\nEXPECTED:\n");

	printf("this is a tiny file\nend of tiny file\n");

	printf("\nACTUAL:\n%.64s\n", cat2);

	if(test2)
	{
		printf("cat /X/tiny failed\n");
		passed = 0;
	}
	else
		printf("cat /X/tiny passed\n");

	//test 3
	printf("\nEXPECTED:\n");

	printf("certainly makes sense since each .c file\n# depends on the TYPEs ");

	printf("\nACTUAL:\n%.64s\n\n", cat3);

	if(test3)
	{
		printf("cat /Y/bigfile failed\n");
		passed = 0;
	}
	else
		printf("cat /Y/bigfile passed\n");

	//test 4
	printf("\nEXPECTED:\n");

	printf("o the data block */\n     get_block(mip->dev, blk, wbuf);   // re\n");

	printf("\nACTUAL:\n%.64s\n\n", cat4);

	if(test4)
	{
		printf("cat /Z/hugefile failed\n");
		passed = 0;
	}
	else
		printf("cat /Z/hugefile passed\n");


	printf("ALL CAT TESTS PASSED\n\n\n");
  strcpy(pathname, "");
  cd(pathname);
	//did all tests pass?
	return passed;
}