Beispiel #1
0
void test_my_strrindex()
{
    my_int(my_strrindex("hello", 'l'));
    my_char('\n');
    my_int(my_strrindex("hello", 'k'));
    my_char('\n');
}
Beispiel #2
0
void testMY_INT(void){
    int i = 55;

    if(temp_file != NULL){
        CU_ASSERT(my_int(i) == 2);
        CU_ASSERT(my_int(-i) == 3);
    }
}
Beispiel #3
0
void test_my_strlen()
{
    my_int(my_strlen("hello"));
    my_char('\n');
    my_int(my_strlen(""));
    my_char('\n');
    my_int(my_strlen(NULL));
    my_char('\n');
}
Beispiel #4
0
void test_my_strindex()
{
    my_int(my_strindex("hello", 'l'));
    my_char('\n');
    my_int(my_strindex("hello", 'k'));
    my_char('\n');
   /* my_strindex("hello", NULL);
    my_strindex(NULL, 'l');
    my_strindex(NULL, NULL);
    my_strindex("H", 'l');
    my_strindex(20, 'k');
    my_strindex("hello", 10);
    my_strindex(10, 10); */
}
Beispiel #5
0
/* traverse_int.c
pre: takes a t_node*
post: posts every int contained within the nodes in the linked list pointed to by the t_node*
*/
void traverse_int(t_node* node){
  if(node){
    if(node->elem)
      my_int(*((int*)node->elem));
    else
      my_str("NULL");
    node = node->next;
    for(; node; node = node->next){
      my_char(' ');
      if(node->elem)
	my_int(*((int*)node->elem));
      else
	my_str("NULL");
    }
  }
}
Beispiel #6
0
/*pre: none
*post: prints the server application's welcome information
*/
void welcome()
{
	my_str("Server running on pid: ");
	my_int(getpid());
	my_char('\n');
	my_str("To shut it down use: ^C\n");
	my_str("=========================\n\n");
}
Beispiel #7
0
/*pre: takes in int argc and char **argv
*post: runs the minishell program 
*	with argc number of command line arguments defined by argv
*/
int main(int argc, char **argv)
{
	int n;
	int pid;
	char *s;
	char **v;

	s = (char*)xmalloc(256*sizeof(char));
	while(1)
	{
		my_str("minishell> ");
		n = read(0, s, 256);
		#ifdef DEBUG
			my_str("n= ");
			my_int(n);
			my_char('\n');
		#endif
		s[n - 1] = '\0';
		if(n > 1)/*1 character is just a \0 (read in \n user just hit enter)*/
		{
			v = my_str2vect(s);
			if(my_strcmp(v[0], "cd") == 0)
				my_chdir(v[1]);
			else if(my_strcmp(v[0], "exit") == 0)
				break;
			else if(v[0] != NULL)/*if not just whitespace, we're going to need to fork*/
			{
				#ifdef DEBUG
					my_str("command:>");
					my_str(v[0]);
					my_str("<\n");
					my_str("going to fork\n");
				#endif
				if((pid = fork()) < 0)
					my_err("minishell: ERROR forking process!\n");
				else if(pid > 0)
					wait(NULL);
				else
				{
					my_execvp(v[0], v);
					#ifdef DEBUG
						my_str("exiting forked process\n");
					#endif
					exit(0);/*for processes that end in error*/
				}
			}
			#ifdef DEBUG
				my_str("freeing vector\n");
			#endif
			my_freevect(v);
		}
		else if(n < 0)
			my_str("minishell: ERROR reading command\n");
	}
	free(s);
	my_str("Thank you for using myminishell, live long and prosper.\n");
	return 0;
}
Beispiel #8
0
int main(int argc, char **argv)
{
    test_my_char();
    test_my_str();
    test_my_int();
    test_my_alpha();
    test_my_digits();
    test_my_strindex();
    test_my_strlen();
    test_my_revstr();
    my_num_base(123, "01");
    my_char('\n');
    my_num_base(123, "0123456789ABCDEF");
    my_char('\n');
    my_num_base(100, "0123456789");
    my_char('\n');
    test_my_strrindex();
    my_str("-->");
    my_str(my_vect2str(&argv[1]));
    my_str("<--\n");
    my_str("-->");
    my_printvect(&argv[1]);
    my_str("<--\n");
    my_printvect(my_str2vect(my_strdup("hello  world      bro")));
    my_char('\n');
    my_int(my_atoi("100"));
    my_char('\n');
    my_int(my_atoi("-100"));
    my_char('\n');
    my_int(my_atoi(""));
    my_char('\n');
    my_int(my_atoi("\n\n\n"));
    my_char('\n');

    return 0;
}
Beispiel #9
0
/*pre: takes in a t_node* pHead
*post: prints out each element as an integer or NULL if the element is NULL
*/
void traverse_int(t_node *pHead)
{
	if(pHead != NULL)
	{
		for( ; pHead != NULL; pHead = pHead->next)
		{
			if(pHead->elem == NULL)
				my_str("NULL");
			else
				my_int(*((int*)(pHead->elem)));
			my_char(' ');
		}
	}
	else
	{
		my_str("The list is empty!\n");
	}
}
Beispiel #10
0
void test_my_int()
{
    my_int(123);
    my_char('\n');
    my_int(-123);
    my_char('\n');
    my_int(0);
    my_char('\n');
    my_int(100);
    my_char('\n');
    my_int(101);
    my_char('\n');
    my_int(((int)(((unsigned int)-1)/2))+1);
    my_char('\n');
}
Beispiel #11
0
void test_integer (void)
{
  std::cerr << "************* INTEGER: GETTING AND SETTING*************\n";
  knowledge::KnowledgeBase knowledge;
  containers::Integer my_int ("my_int", knowledge);

  std::cerr << "Integer value: " << *my_int << "\n";
  
  std::cerr << "Changing value...\n";

  my_int = 15;
  
  std::cerr << "Integer value: " << *my_int << "\n";
  
  if (my_int.get_name () == "my_int" && *my_int == 15)
    std::cerr << "SUCCESS. my_int was the correct name and value.\n";
  else
    std::cerr << "FAIL. my_int was not the correct name and value.\n";

  knowledge.print ();
}
Beispiel #12
0
int main(int argc, char** argv)
{
    int serpid;

    serpid = 0;
    if(argc >= 3)
    {
        if((serpid = atoi(argv[1])) > 0)
        {
            my_str("--CLIPID-->");
            my_int(getpid());
            my_str("<--\n");

            signal(SIGUSR1, ack);
            signal(SIGALRM, omg);
            sendpid(serpid, getpid());
            if(!gl_ack)
            {
                alarm(5);
                pause();
            }
            alarm(0);
            gl_ack = 0;

            my_str("--SENDING STRING-->");
            my_str("<--\n");

            sendstring(serpid, my_vect2str(&argv[2]));
            gl_ack = 0;

            my_str("--FINISHED SENDING STRING-->");
            my_str("<--\n");
        }
    }

    return 0;
}
Beispiel #13
0
my_int operator/(const my_int &a, int64_t b) { return my_int(a) /= b; }
Beispiel #14
0
my_int::my_int(int64_t num) {
  *this = my_int(abs(num));
  if (num < 0)
    sign = 0;
  return;
}
Beispiel #15
0
my_int operator*(const my_int &a, const my_int &b) { return my_int(a) *= b; }
Beispiel #16
0
my_int operator*(const my_int &a, int64_t b) { return my_int(a) *= b; }
Beispiel #17
0
my_int operator-(const my_int &a, const my_int &b) { return my_int(a) -= b; }
Beispiel #18
0
int main()
{	
  
	char val1[32] = "Roy Bayraktaryan Bahian";
	char val2[32] = "Hello";
	char val3[32] = "_World_!!!";
	char val4[32] = "";
	char *p;
	int i;		
  	char str[128] = "life is great!";

	my_str("\nmy_find()\n-----------------\n");
	my_str("1: my_find('Roy Bayraktaryan Bahian', 'y') = ");
	p = my_find(val1, 'y');
	if(p) my_char(*p);
	my_char('\n');	

	my_str("2: my_find('Roy Bayraktaryan Bahian', 'z') = ");
	p = my_find(val1, 'z');
	if(p) my_char(*p);
	my_char('\n');	

	my_str("3: my_find('', 'y') = ");
	p = my_find(val4, 'y');
	if(p) my_char(*p);
	my_char('\n');	

	my_str("4: my_find(NULL, 'y') = ");
	p = my_find(NULL, 'y');
	if(p) my_char(*p);
	my_char('\n');	

	my_str("5: my_find('Roy Bayraktaryan Bahian', space) = ");
	p = my_find(val1, ' ');
	if(p) my_char(*p);
	my_char('\n');	
/***********************************************************/
	my_str("\nmy_rfind()\n-----------------\n");
	my_str("1: my_rfind('Roy Bayraktaryan Bahian', 'y') = ");
	p = my_rfind(val1, 'y');
	my_char(*p);
	my_char('\t');	
	my_int(*p);
	my_char('\n');	

	my_str("2: my_rfind('Roy Bayraktaryan Bahian', 'z') = ");
	p = my_rfind(val1, 'z');
	my_char(*p);
	my_char('\t');	
	my_int(*p);
	my_char('\n');	

	my_str("3: my_rfind('', 'y') = ");
	p = my_rfind(val4, 'y');
	my_char(*p);
	my_char('\t');	
	my_int(*p);
	my_char('\n');	

	my_str("4: my_rfind(NULL, 'y') = ");
	p = my_rfind(NULL, 'y');
	if(p)my_char(*p);
	my_char('\n');	

	my_str("5: my_rfind('Roy Bayraktaryan Bahian', '') = ");
	p = my_rfind(val1, '@');/*it doesn't work NULL char of course*/
	my_char(*p);
	my_char('\t');	
	my_int(*p);
	my_char('\n');	

/***********************************************************/
	my_str("\nmy_strcat()\n-----------------\n");
	my_str("1: my_strcat('Hello', 'empty') = ");
	p = my_strcat(val2, val4);
	my_char(*p);
	my_char('\t');	
	my_int(*p);
	my_char('\t');	
	my_str(p);
	my_char('\n');
	
	my_str("2: my_strcat('Hello', '_World_!!!') = ");
	p = my_strcat(val2, val3);
	my_char(*p);
	my_char('\t');	
	my_int(*p);
	my_char('\t');	
	my_str(p);
	my_char('\n');	
	
	my_str("3: my_strcat('Hello', 'empty') = ");
	p = my_strcat(val2, val4);
	my_char(*p);
	my_char('\t');	
	my_int(*p);
	my_char('\t');	
	my_str(p);
	my_str("\t val2 changed NO MORE HELLO ");
	my_char('\n');	

	my_str("4: my_strcat('Hello_World_!!!', 'NULL') = ");
	p = my_strcat(val2, NULL);
	my_char(*p);
	my_char('\t');	
	my_int(*p);
	my_char('\t');	
	my_str(p);
	my_char('\n');	
	
	my_str("5: my_strcat('EMPTY', 'Hello World!!!') = ");
	p = my_strcat(val4, val2);
	my_char(*p);
	my_char('\t');	
	my_int(*p);
	my_char('\t');	
	my_str(p);
	my_char('\n');	

	my_str("6: my_strcat(NULL, 'Hello World!!!') = ");
	p = my_strcat(NULL, val2);
	if(p) my_char(*p);
	my_char('\n');	
	
	my_str("7: my_strcat(NULL, NULL) = ");
	p = my_strcat(NULL, NULL);
	if(p) my_char(*p);
	my_char('\n');	

/***********************************************************/
	my_str("\nmy_strcmp()\n-----------------\n");
	my_str("1: my_strcmp('Roy', 'Bahian') = ");
	my_int(my_strcmp("Roy", "Bahian"));
	my_char('\n');

	my_str("2: my_strcmp('Bahian', 'Roy') = ");
	my_int(my_strcmp("Bahian", "Roy"));
	my_char('\n');	
	
	my_str("3: my_strcmp('Roy', Empty) = ");
	my_int(my_strcmp("Roy", ""));
	my_char('\n');

	my_str("4: my_strcmp('Roy', NULL) = ");
	my_int(my_strcmp("Roy", NULL));
	my_char('\n');

	my_str("5: my_strcmp('Empty', 'Bahian') = ");
	my_int(my_strcmp("", "Bahian"));
	my_char('\n');
/*
	my_str("6: my_strcmp(NULL, 'Bahian') = ");
	my_int(my_strcmp(NULL, "Bahian"));
	my_char('\n');

	my_str("7: my_strcmp(NULL, NULL) = ");
	my_int(my_strcmp(NULL, NULL));
	my_char('\n');
*/
	my_str("8: my_strcmp('Roy', 'Roy') = ");
	my_int(my_strcmp("Roy","Roy"));
	my_char('\n');

	return 0;
}
Beispiel #19
0
my_int operator%(const my_int &a, const my_int &b) { return my_int(a) %= b; }
Beispiel #20
0
my_int operator+(const my_int &a, int64_t b) { return my_int(a) += b; }
Beispiel #21
0
void draw_ball(WINDOW* win, struct Ball* ball, int color)
{
    mvwaddch(win, my_int(ball->y), my_int(ball->x), 'O' | COLOR_PAIR(color));
}
Beispiel #22
0
//test function for libmy
int main() {
    //my_char takes in char and prints it
    int i;
    for (i = 0; i < 128; i++) { // testing my_char for all valid characters including null
        my_char(i);
    }
    my_char(-1);
    my_char(128); // should be too big
    my_char("david");
    my_char("");
    my_char('\0');

    //my_int takes in int and prints it
    my_int(0);
    my_int(1);
    my_int(-1);
    my_int(1000);
    my_int(-1000);
    my_int(2147483647); //max int on 32b machine
    my_int(2147483648); //max + 1
    my_int(-2147483647); //min int
    my_int(-2147483648);//min int - 1
    my_int("david");
    my_int('D');
    my_int(1.3);
    my_int("");
    my_int('\0');

    //my_alpha has no input and prints alphabet
    my_alpha();
    //any parameter will cause it not to compile

    //my_digits has no input and prints 0 - 9
    my_digits();
    //no return, can't pass anything in

    //my_str
    my_str(0);
    my_str("david");
    my_str("");
    my_str("asdfkljasdflkjhasdflkjhasdfkljasdfkalsdjfalksjdaklsjdflkasjdaslkdaskjdfaskldjaskljd");
    //my_str(65);
    //my_str('\0');//null char
    //my_str('A');
    my_str("dav\0id"); //null char in string
    //my_str(98723498723);

    //my_revstr
    my_revstr(0);
    my_revstr("david");
    my_revstr("");
    my_revstr("asdfkljasdflkjhasdflkjhasdfkljasdfkalsdjfalksjdaklsjdflkasjdaslkdaskjdfaskldjaskljd");
    //my_revstr(65);
    //my_revstr('\0');//null char
    //my_revstr('A');
    my_revstr("dav\0id"); //null char in string
    //my_revstr(98723498723);

    //my_strindex
    my_int(my_strindex("david", 'a'));
    my_int(my_strindex("david", 'd')); // there are two of them
    my_int(my_strindex("david", 'b')); // not in string
    my_int(my_strindex("david", '\0'));
    my_int(my_strindex("david", ""));
    my_int(my_strindex("", 'a'));
    my_int(my_strindex("dav\0id", 'i')); //should not find i
    my_int(my_strindex(0, 0));

    //my_strrindex
    my_int(my_strrindex("david", 'a'));
    my_int(my_strrindex("david", 'd')); // there are two of them
    my_int(my_strrindex("david", 'b')); // not in string
    my_int(my_strrindex("david", '\0'));
    my_int(my_strrindex("david", ""));
    my_int(my_strrindex("", 'a'));
    my_int(my_strrindex("dav\0id", 'i')); //should not find i
    my_int(my_strrindex(0, 0));

    //my_strlen
    my_int(my_strlen("david"));//should be 5
    my_int(my_strlen("dav\0id"));
    my_int(my_strlen(""));
    my_int(my_strlen(" "));
    //my_int(my_strlen('a'));
    my_int(my_strlen(0));
    //my_int(my_strlen(1234));

    //my_num_base
    my_num_base(0, 0);//print nothing
    my_num_base(0, "david");
    my_num_base(4, 0);
    my_num_base(-4, 0);
    my_num_base(4, "david");//should print d
    my_num_base(-4, "david");//-d
    my_num_base(5, "?");//?????
    my_num_base(-5, "?");
    //my_num_base("", "david");
    my_num_base('z', "david");

}
Beispiel #23
0
my_int operator/(const my_int &a, const my_int &b) { return my_int(a) /= b; }
Beispiel #24
0
my_int operator%(const my_int &a, int64_t b) { return my_int(a) %= b; }
Beispiel #25
0
my_int operator+(const my_int &a, const my_int &b) { return my_int(a) += b; }
void my_digits()
{
  unsigned char count;
  for(count = 0; count <= 9; count++)
    my_int(count);
}
Beispiel #27
0
my_int operator-(const my_int &a, int64_t b) { return my_int(a) -= b; }
Beispiel #28
0
int main()
{
	t_node *head;
	t_node *n1;
	t_node *n2;
	int *i1;
	int *i2;
	int *i3;
	int i;
	int j;
	int k;
	char *c1;
	char *c2;
	char *c3;
	char a;
	char b;
	char c;

	head = (t_node*)xmalloc(10*sizeof(t_node));
	
	/*new_node*/
	n1 = new_node("one\n", NULL);
	my_str(n1->elem);/*prints one*/
	n1->elem = NULL;
	free(n1);
	n1 = new_node(NULL, NULL);
	if(!n1->elem)
		my_str("create NULL node ok\n");
	else
		my_str("create NULL node FAIL!\n");
	free(n1);
	n1 = new_node("a", NULL);
	n2 = new_node("b", n1);
	my_str(n2->elem);
	my_str((n2->next)->elem);/*prints ba*/
	my_char('\n');
	my_str("---------------------------------------------------------------------\n");

	/*add_node*/
	add_node(n1, &head);
	my_str((*head).elem);/*prints a*/
	my_char('\n');
	add_node(n2, &head);
	my_str((*head).elem);/*prints b*/
	my_char('\n');
	add_node(NULL, &head);
	if(strcmp((*head).elem, n2->elem) == 0)
		my_str("add NULL ok\n");
	else
		my_str("add NULL FAIL!\n");
	add_node(new_node(NULL, NULL), &head);
	if(strcmp((*head).elem, n2->elem) == 0)
		my_str("add NULL node ok\n");
	else
		my_str("add NULL node FAIL!\n");
	add_node(new_node("something", NULL), NULL);/*if this line doesn't segfault then we're good!*/
	my_str("---------------------------------------------------------------------\n");

	/*traversals*/
	empty_list(&head);
	i = 3;
	i1 = &i;
	add_node(new_node(i1, NULL), &head);
	j = 2;
	i2 = &j;
	add_node(new_node(i2, NULL), &head);
	k = 1;
	i3 = &k;
	add_node(new_node(i3, NULL), &head);
	traverse_int(head);/*prints 1 2 3 */
	my_char('\n');
	head->next->elem = NULL;
	traverse_int(head);/*prints 1 NULL 3*/
	my_char('\n');
	traverse_int(NULL);/*prints The list is empty!*/

	empty_list(&head);
	c = 'c';
	c1 = &c;
	add_node(new_node(c1, NULL), &head);
	b = 'b';
	c2 = &b;
	add_node(new_node(c2, NULL), &head);
	a = 'a';
	c3 = &a;
	add_node(new_node(c3, NULL), &head);
	traverse_char(head);/*prints a b c */
	my_char('\n');
	head->elem = NULL;
	traverse_char(head);/*prints NULL b c*/
	my_char('\n');
	traverse_char(NULL);/*prints The list is empty!*/

	empty_list(&head);
	add_node(new_node("third", NULL), &head);
	add_node(new_node("second", NULL), &head);
	add_node(new_node("first", NULL), &head);
	traverse_string(head);/*prints first second third */
	my_char('\n');
	head->next->next->elem = NULL;
	traverse_string(head);/*prints first second NULL*/
	my_char('\n');
	traverse_string(NULL);/*prints The list is empty!*/
	empty_list(&head);
	my_str("---------------------------------------------------------------------\n");

	/*add_elem*/
	add_elem("a", &head);
	add_elem("b", &head);
	add_elem("c", &head);
	my_str(head->elem);/*prints c*/
	my_char('\n');
	add_elem(NULL, &head);
	if(strcmp(head->elem, "c") == 0)
		my_str("add NULL elem ok\n");
	else
		my_str("add NULL elem FAIL!\n");	
	my_str("---------------------------------------------------------------------\n");
	
	/*append*/
	append(new_node("z", NULL), &head);
	traverse_string(head);/*prints c b a z*/
	my_char('\n');
	append(NULL, &head);
	traverse_string(head);/*prints c b a z*/
	my_char('\n');
	append(new_node("stuff", NULL), NULL);/*if this line doesn't segfault then we're good!*/
	my_str("---------------------------------------------------------------------\n");

	/*add_node_at*/
	add_node_at(new_node("d", NULL), &head, 0);
	traverse_string(head);/*prints d c b a z*/
	my_char('\n');
	add_node_at(new_node("y", NULL), &head, 42);
	traverse_string(head);/*prints d c b a z y*/
	my_char('\n');
	add_node_at(new_node("0", NULL), &head, 4);
	traverse_string(head);/*prints d c b a 0 z y*/
	my_char('\n');
	add_node_at(NULL, &head, 2);
	traverse_string(head);/*prints d c b a 0 z y*/
	my_char('\n');
	add_node_at(new_node(NULL, NULL), &head, 1);
	traverse_string(head);/*prints d c b a 0 z y*/
	my_char('\n');
	add_node_at(new_node("something", NULL), NULL, 7);/*if this line doesn't segfault then we're good!*/
	my_str("---------------------------------------------------------------------\n");

	/*remove_node*/
	my_str(remove_node(&head));/*prints d*/
	my_str(": ");
	traverse_string(head);
	my_char('\n');
	if(!remove_node(NULL))
		my_str("remove node from NULL ok\n");
	else
		my_str("remove node from NULL FAIL!\n");
	my_str("---------------------------------------------------------------------\n");

	/*remove_node_at*/
	my_str(remove_node_at(&head, 0));/*prints c*/
	my_str(": ");
	traverse_string(head);
	my_char('\n');
	my_str(remove_node_at(&head, 42));/*prints y*/
	my_str(": ");
	traverse_string(head);
	my_char('\n');
	my_str(remove_node_at(&head, 2));/*prints 0*/
	my_str(": ");
	traverse_string(head);
	my_char('\n');
	if(!remove_node_at(NULL, 100))
		my_str("remove node from NULL ok\n");
	else
		my_str("remove node from NULL FAIL!\n");
	my_str("---------------------------------------------------------------------\n");

	/*remove_last*/
	my_str(remove_last(&head));/*prints z*/
	my_str(": ");
	traverse_string(head);
	my_char('\n');
	if(!remove_last(NULL))
		my_str("remove last from NULL ok\n");
	else
		my_str("remove last from NULL FAIL!\n");
	my_str("---------------------------------------------------------------------\n");

	/*count_nodes*/
	my_int(count_nodes(head));/*prints 2*/
	my_char('\n');
	my_int(count_nodes(NULL));/*prints 0*/
	my_char('\n');
	my_str("---------------------------------------------------------------------\n");

	/*node_at*/
	my_str((node_at(head, 1))->elem);/*prints a*/
	my_char('\n');
	my_str((node_at(head, 0))->elem);/*prints b*/
	my_char('\n');
	my_str((node_at(head, 42))->elem);/*prints a*/
	my_char('\n');
	if(!node_at(NULL, 12))
		my_str("node at with NULL ok\n");
	else
		my_str("node at with NULL FAIL!\n");
	my_str("---------------------------------------------------------------------\n");

	/*elem_at*/
	my_str(elem_at(head, 0));/*prints b*/
	my_char('\n');
	my_str(elem_at(head, 1));/*prints a*/
	my_char('\n');
	my_str(elem_at(head, 42));/*prints a*/
	my_char('\n');
	if(!elem_at(NULL, 3))
		my_str("elem at with NULL ok\n");
	else
		my_str("elem at with NULL FAIL!\n");
	my_str("---------------------------------------------------------------------\n");

	/*empty_list*/
	my_int(count_nodes(head));/*prints 2*/
	my_char('\n');
	empty_list(&head);
	my_int(count_nodes(head));/*prints 0*/
	my_char('\n');
	empty_list(NULL);/*if this doesn't segfault then we're good!*/
	my_str("---------------------------------------------------------------------\n");
	
	free(head);

	return 0;
}
Beispiel #29
0
void erase_ball(WINDOW* win, struct Ball* ball)
{
    mvwaddch(win, my_int(ball->py), my_int(ball->px), ' ');
}