Beispiel #1
0
/*
 * rewrite_pos_to_end()
 *
 * Redraw a number in history from the position specified by pos to the end
 *
 * Precondition: History is initialized, pos <  gl_env.count
 * Postcondition: The line is redrawn
 *
 * @param int pos The position to redraw from
 * @param int history_num The history number to redraw
 */
void    rewrite_pos_to_end(int pos, int history_num)
{
    int pos_backup;

    pos_backup = pos;

    while(pos_backup++ < gl_env.count)
    {
        tputs(gl_env.move_right, 1, my_termprint);
    }

    while(pos_backup-- > pos + 1)
    {
        tputs(gl_env.backspace, 1, my_termprint);
        my_char(' ');
        tputs(gl_env.backspace, 1, my_termprint);
    }

    while(pos_backup++ < gl_env.count)
    {
        my_char(gl_env.history[history_num][pos_backup - 1]);
    }

    while(pos_backup-- > pos + 1)
    {
        tputs(gl_env.backspace, 1, my_termprint);
    }
}
Beispiel #2
0
void test_my_strrindex()
{
    my_int(my_strrindex("hello", 'l'));
    my_char('\n');
    my_int(my_strrindex("hello", 'k'));
    my_char('\n');
}
Beispiel #3
0
void my_num_base(int input, char *alpha)
{
    if (alpha)
    {
        long num = 0;
        unsigned int base = 0, i = 0;

        if (input < 0)
        {
            my_char('-');
            if (input == INT_MIN)
                num = (long)INT_MAX + 1;
            else
            {   
                input *= -1;
                num = (long)input;
            }
        }
        else
            num = (long)input;
        if (num > 0)
        {
            for (base = 0; alpha[base] != '\0'; base++)
                ;
            if (base > 1)
                my_num_base_rec(num, base, alpha);
            else
                for (i = 0; i < num; i++)
                    my_char(alpha[0]);
        }
        else
            my_char(alpha[0]);
    }
}
Beispiel #4
0
void test_my_char()
{
    my_char(' ');
    my_char('\n');
    my_char('a');
    my_char('\n');
}
Beispiel #5
0
void test_my_str()
{
    my_str("hello");
    my_char('\n');
    my_str(" ");
    my_char('\n');
}
Beispiel #6
0
/*
 * my_int()
 *
 * Prints an integer to stdout
 *
 * Precondition: num is a valid integer
 * Postcondition: num is printed to the screen
 *
 * @param num - The integer to be printed
 */
void my_int(int num)
{
    unsigned int power = 1;
    unsigned int newNum;

    if(num < 0)
    {
        my_char('-');
        newNum = num * -1;
    }
    else
    {
        newNum = num;
    }
    
    while(power <= (newNum / 10))
        power *= 10;

    do
    {
        my_char('0' + (newNum / power));
        newNum %= power;
        power /= 10;
    } while(power);
}
Beispiel #7
0
void debug_char(struct s_node *head)
{
    if (head)
    {
        my_str("(");
        if (head->prev && (head->prev)->elem)
            my_char(*((char *)((head->prev)->elem)));
        else
            my_str("NULL");
        my_str(" <- ");
        if (head->elem)
            my_char(*((char *)(head->elem)));
        else
            my_str("NULL");
        my_str(" -> ");

        if (head->next)
        {
            my_char(*((char *)((head->next)->elem)));
            my_str("), ");
        }
        else
            my_str("NULL)");
        debug_char(head->next);
    }
}
Beispiel #8
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 #9
0
/*pre: takes in an int
*post: prints that int to stdout
*/
void my_int(int i)
{
	unsigned int u;
	unsigned int exp;

	if(i < 0)
		my_char('-');
	u = (i < 0)? -i : i;
	for(exp = 1; u / exp >= 10; exp *= 10)
		;
	for(; exp; u %= exp, exp /= 10)
		my_char('0' + u / exp);
}
Beispiel #10
0
void test_my_revstr()
{
    my_str("Begin my_revstr \n");
    char str[] = "hey!";
    my_str(str);
    char str1[] = "hello";
    my_revstr(str);
    my_str(str);
    my_char('\n');
    my_revstr(str1);
    my_str(str1);
    my_char('\n');

}
Beispiel #11
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 #12
0
void getout(char c)
{
  int i;
  if(c)
    {
      for(i=0; i<gl_env.nbelems; i++)
	{
	  my_str(gl_env.elements[i].elem);
	  my_char(' ');
	}
    }
  my_char('\n');
  exit(1);
}
Beispiel #13
0
/*
 * getout()
 *
 * Quit the program
 *
 * Precondition: input is not null
 * Postcondition: Program exits
 *
 * @param char* input The input character
 */
void    getout(char* input)
{
    int count;

    if(input != NULL)
    {
        if(!my_strcmp(input, "\n"))
        {
            restore_terminal();
            for(count = 0; count < gl_env.nbelems; count++)
            {
                if(gl_env.elements[count].mode)
                {
                    my_str(gl_env.elements[count].elem);
                    my_str(" ");
                }
            }
            my_char('\n');
            exit(0);
        }
        else if(!my_strcmp(input, "\E"))
        {
            restore_terminal();
            exit(0);
        }
    }
}
Beispiel #14
0
void testMY_CHAR(void){
    char c = 'c';

    if(temp_file != NULL){
        CU_ASSERT(my_char(c) == 1);
    }
}
Beispiel #15
0
void debug_int(struct s_node* head)
{
	assert(head != NULL);
	if(head != NULL)
	{
		while(head != NULL)
		{
			my_char('(');
			if(head->prev == NULL)
				my_str("NULL <- ");
			else
			{
				print_int(head->prev);
				my_str(" <- ");
			}

			print_int(head);

			if(head->next == NULL)
				my_str(" -> NULL)");
			else
			{
				my_str(" -> ");
				print_int(head->next);
				my_str("), ");
			}

			head = head->next;
		}
	}
}
Beispiel #16
0
/*
 * Callback for signal function in order to print a message
 * Precondition: N/A
 * Postcondition: every 8 bits is interpreted as a character and printed tro the screen
 */
void getmessage(int sig)
{
  static char thischar = 0;
  static int i = 0;
  
  thischar <<= 1;
  
  if(sig == SIGUSR1)
    {
      thischar |= 1;
    }
  i++;
  if(i >= 8)
    {
      if(thischar == '\0')
	{
	  gl_env.done = 1;
	  kill(gl_env.clientpid, SIGUSR1);
	}
      else
	{
	  my_char(thischar);
	}
      thischar = 0;
      i = 0;
    }
  
  kill(gl_env.clientpid, SIGUSR2);
}
Beispiel #17
0
/*
 Prints the elem of node as a char
*/
void print_char(struct s_node* node){
  if(node == 0 || node->elem == 0){/*might be too safe, there shouldnt be a node with a null elem*/
    my_str("NULL");
    return;
  }
  my_char(*(char*)(node->elem));
}
Beispiel #18
0
/*
 *driver and file reader function
*/
int main()
{
  FILE *file = fopen("../cipher.txt", "r");
  int n = 0;
  int c;
  char i;
  char j;
  char k;
  char *inputcsv = (char *)malloc(4096*sizeof(char));
  char *cleanctxt;
  char *key = (char *)malloc(4*sizeof(char));
  char *dec;
  
  while ((c = fgetc(file)) != EOF)
    inputcsv[n++] = (char)c;
  if (n<0)
    exit(1);
  fclose(file);

  cleanctxt = parsecsv(inputcsv,n);
  
  key[3] = '\0';

  /*try all combinations of aaa - zzz*/
  for (i=95; i<123; ++i)
    {
      key[0] = i;
      for (j=95; j<123; ++j)
	{
	  key[1] = j;
	  for (k=95; k<123; ++k)
	    {
	      key[2] = k;
	      /*if found, print relevant stats on the decrypted text*/
	      if ( checkenglish(xordecrypt(key,gl_cleanbytes-1,cleanctxt), 95, gl_cleanbytes) )
		{
		  dec = xordecrypt(key,gl_cleanbytes,cleanctxt);
		  my_str("Key: "); my_str(key); my_char('\n');
		  my_str("Sum of ASCII Values: "); printf("%d\n",(addasciivals(dec)));
		  my_str(dec); my_char('\n');
		  return 0;
		}
	    }
	}
    }
  return 1;
}
Beispiel #19
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 #20
0
int main()
{
    static_assert(val<'1'>(100) == 101, " should be 1");
    static_assert(val<'0'>(100) == 100, " should be 0");
    static_assert(val<my_char()>(100) == 101, " should be 1");
    static_assert(val<cstr("1001")[0]>(100)  == 101, "");
    return 0;
}
Beispiel #21
0
void my_str(char* s){
    int i = 0;
    if(!s) return;
    while(*(s + i) != '\0'){
        my_char(*(s + i));
        i++;
    }
}
void backspace()
{
	tputs(gl_env.backspace, 1, my_termprint);
	my_char(' ');
	tputs(gl_env.backspace, 1, my_termprint);
	gl_env.history[0][gl_env.count--] = '\0';
	gl_env.pos--;
}
Beispiel #23
0
void my_str(char* str)
{
	while(str != 0 && str[0] != '\0')
	{
		my_char(str[0]);
		str++;
	}
}
Beispiel #24
0
/*Prints all digits from 0 to 1*/
void my_digits(){
  char c = '0'; /*Character that increments from '0' to '9'*/
  int i; /*Iterator*/
  /*for loop iterates through digits from 0 to 10 and prints them*/
  for(i = 0; i < 10; i++){
    my_char(c++);
  }
}
Beispiel #25
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 #26
0
/*pre: takes in a t_node* pHead
*post: prints out each element as a char or NULL if the element is NULL
*/
void traverse_char(t_node *pHead)
{
	if(pHead != NULL)
	{
		for( ; pHead != NULL; pHead = pHead->next)
		{
			if(pHead->elem == NULL)
				my_str("NULL");
			else
				my_char(*((char*)(pHead->elem)));
			my_char(' ');
		}
	}
	else
	{
		my_str("The list is empty!\n");
	}
}
Beispiel #27
0
void show_selection()
{
	int i;
	//term_move(gl_env.elements[gl_env])
	//term_clear();
	for(i=0; i<gl_env.nbelems-1; i++)
		if(gl_env.elements[i].mode)
		{
			my_str(gl_env.elements[i].elem);
			my_char(' ');
		}
	my_char('\n');
	/*if(gl_env.elements[gl_env.nbelems-1].mode)
	{
		gl_env.elements[gl_env.nbelems-1].elem[gl_env.elements[gl_env.nbelems-1].size] = '\0';
		my_str(gl_env.elements[gl_env.nbelems-1].elem);
	}*/
}
Beispiel #28
0
int my_revstr(char* s){
  int len = my_strlen(s);    
  int i = len - 1;
    if(!s) return -1;
    while(i >= 0){
        my_char(*(s + i));
        i--;
    }
    return len;
}
Beispiel #29
0
void my_int(int num)
{
  unsigned int posNum;
  unsigned int power;

  if(num < 0)
    {
      my_char('-');
      posNum = num * -1;
    }
  else
      posNum = num;

  for(power = 1; power <= (posNum / 10); power *= 10); /* Find where to start from the left*/
    
  do 
    {
      my_char('0' +  (posNum / power)); /* use the character 0 so that posNum prints as char*/
      posNum %= power;
      power /= 10;
    } while(power);
}
Beispiel #30
0
void debug_string(t_node* n) {
    t_node* listptr;
    if (n != NULL) {
        listptr = n;
        while (listptr->next != NULL) {
            print_string(listptr);
            listptr = listptr->next;
            my_char(' ');
        }
        print_string(listptr);
    } else
        my_str("The list is empty");
}