Ejemplo n.º 1
0
/* init_terminal.c
pre: Takes nothing
post: Backups old terminal env, sets new one
*/
void init_terminal(){
  int term_fd;
  struct termio line;
  char* term;
  extern t_env gl_env;
#ifdef DEBUG
  my_str("INIT TERM\n");
#endif
  term_fd = 0;
  ioctl(term_fd, TCGETA, &line);
  gl_env.line_backup = line;

  line.c_lflag &= ~(ICANON | ECHO | ISIG);
  line.c_cc[VTIME] = READTIME;
  line.c_cc[VMIN] = READMIN;
  ioctl(term_fd, TCSETA, &line);
  
  ioctl(term_fd, TIOCGWINSZ, &(gl_env.win));
  
  term = ttyname(term_fd);
  term_fd = open(term, O_WRONLY);
  gl_env.stdio_backup = dup(1);
  dup2(term_fd, 1);
#ifdef DEBUG
  my_str("TERM INIT DONE\n");
#endif
}
Ejemplo n.º 2
0
void test_my_str()
{
    my_str("hello");
    my_char('\n');
    my_str(" ");
    my_char('\n');
}
Ejemplo n.º 3
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;
		}
	}
}
Ejemplo n.º 4
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);
        }
    }
}
Ejemplo n.º 5
0
void	my_iu(t_all *a, char *str)
{
  my_str(a->mr);
  my_str(a->us);
  my_str(str);
  my_str(a->me);
  my_str(a->ue);
}
Ejemplo n.º 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");
}
Ejemplo n.º 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;
}
Ejemplo n.º 8
0
void testMY_STR(void){
    char str[] = "test";

    if(temp_file != NULL){
        CU_ASSERT(my_str(str) == 4);
        CU_ASSERT(my_str("") == 0);
        CU_ASSERT(my_str(NULL) == 0);
    }
}
Ejemplo n.º 9
0
/*pre: called from a child process in the server
*post: disconnects the client and ends the child process
*/
void disconnect()
{
	if(close(gl_env.clientfd))
		my_err("ERROR: cannot close client socket\n");
	my_str("***");
	my_str(gl_env.clientname);
	my_str(" disconnected...\n");
	exit(0);
}
Ejemplo n.º 10
0
/*
 * connect()
 *
 * Connect to the server
 *
 * Precondition: The server is running, and all fields are filled out
 * Postcondition: A connection to the server is established, the connect window is destroyed,
 *                  and the main window's widgets are reenabled
 *
 * @param GtkWidget* w The widget clicked. In this case, the ok button
 * @param gpointer d The connect window
 */
void        connect_server(GtkWidget* w, gpointer d)
{
    char*  message;
    char*  host;
    int    port;
    struct sockaddr_in  serv_addr;
    struct hostent* server;

    port = my_atoi((char*) gtk_entry_get_text((GtkEntry*) gl_env.user_input[1]));
    message = (char*) gtk_entry_get_text((GtkEntry*) gl_env.user_input[2]);
    host = (char*) gtk_entry_get_text((GtkEntry*) gl_env.user_input[0]);

    if(port == 0 || my_strcmp(message, "") == 0 || my_strcmp(host, "") == 0) {
        g_print("Please fill out all fields\n");
        return;
    }

    if(port <= 0 || port > 65535)
    {
        my_str("Invalid port number!\n");
        return;
    }

    memset(&serv_addr.sin_zero, 0, 8);

    gl_env.sockfd = socket(AF_INET, SOCK_STREAM, 0);

    if((server = gethostbyname(host)) == NULL)
    {
        my_str("Couldn't find the server hostname!\n");
        return;
    }

    serv_addr.sin_family = AF_INET;
    serv_addr.sin_port = htons(port);

    memcpy(&serv_addr.sin_addr.s_addr, server->h_addr, server->h_length);

    if(connect(gl_env.sockfd, (struct sockaddr*) &serv_addr, sizeof(serv_addr)) < 0)
    {
        my_str("Connection to server failed!\n");
        return;
    }

    if(write(gl_env.sockfd, message, my_strlen(message) + 1) < 0)
    {
        my_str("Communication with server failed!\n");
        return;
    }

    enable_main();
    g_print("Connected!\n");
    gtk_button_set_label((GtkButton*) gl_env.connect_button, "Disconnect");
    gtk_widget_destroy(d);
}
Ejemplo n.º 11
0
void debug_char(struct s_node* head){
	while(head != NULL){
		my_str("(");
		print_char(head -> prev);
		my_str(" <- ");
		print_char(head);
		my_str(" -> ");
		print_char(head -> next);
		my_str(")");
		if(head -> next != NULL)
			my_str(", ");
		head = head -> next;
	}
}
Ejemplo n.º 12
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');

}
Ejemplo n.º 13
0
int main(int argc, char **argv)
{
    int n;
    int fd;
    int i;
    char **vect;
    char buffer[BUFF_SIZE];
    char *san;

    while(1)
    {
        my_str("[--MyMiniShell--]$ ");
        if((n = read(1, buffer, BUFF_SIZE-1)) < 0)
        {
            my_str("Something bad happened.\n");
            exit(0);
        }
        else
        {
            san = my_stripbuffer(buffer);
            vect = my_str2vect(san);

            if(my_strcmp(vect[0], "cd") == 0)
            {
                if((n = chdir(vect[1])) < 0)
                {
                    my_str("Execution of cd failed.\n");
                }
            }
            else if(my_strcmp(vect[0], "exit") == 0)
            {
                my_str("Goodbye!\n");
                exit(0);
            }
            else
            {
                if((fd = fork()) < 0)
                {
                    my_str("Fork Fail");
                    exit(0);
                }
                if(fd > 0)
                {
                    wait();
                }
                else
                {
                    if((n = execvp(vect[0], vect)) < 0)
                    {
                        my_str("Execution of ");
                        my_str(vect[0]);
                        my_str(" failed.\n");
                        exit(0);
                    }
                }
            }
        }
    }
}
Ejemplo n.º 14
0
void    aff_res(t_all *a)
{
  int   y;
  int	x;

  y = 0;
  x = 0;
  while (y <= (a->ty - 1))
    {
      while (a->tab[y][x])
	{
	  if ((x >= a->x && x < (a->x + a->t)) && (y >= a->y && y < (a->y + a->t)))
	    {
	      my_putchar('x');
	      x++;
	    }
	  else
	    {
	      my_putchar(a->tab[y][x]);
	      x++;
	    }
	}
      my_str("\n");
      y++;
      x = 0;
    }
}
Ejemplo n.º 15
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));
}
Ejemplo n.º 16
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");
    }
  }
}
Ejemplo n.º 17
0
void show_params(){
  int maxsize, i, x, y;
  ioctl(1, TIOCGWINSZ, &(gl_env.win));
  // error check?
  gl_env.flag = 0;
  term_clear();
  /*my_int(gl_env.nbelems);
    my_char('\n');*/
  for (i=0,x=0,y=0,maxsize=0;i<gl_env.nbelems;i++,y++){
    if (y >= gl_env.win.ws_row) {
      y = 0;
      x += maxsize + 2;
      maxsize = 0;
    }
    if (maxsize < gl_env.elems[i].size)
      maxsize = gl_env.elems[i].size;
    if (x+maxsize >= gl_env.win.ws_col){
      term_clear();
      term_pos(0, 0);
      my_str("Please enlarge your terminal.");
      gl_env.flag = TRUE;
      break;
    }
    gl_env.elems[i].x = x;
    gl_env.elems[i].y = y;
    term_pos(x, y);
    refreshout(i);
  }
  if (!gl_env.flag)
    refreshin(); //underlines selected
}
Ejemplo n.º 18
0
void print_GTree(t_dir* lroot, int tab)
{
	int i;
	int j;
	p_node *dirChild;
	p_node *fileChild;
	
	if(lroot == NULL)
		return;
		
	for(i=0; i<tab; i++)
		my_str("    ");
	if (lroot == root)
		printf("\033[01;34mroot \033[01;37m \n");	
	printf("\033[01;34m%s \033[01;37m \n", lroot->name);	

	if (lroot->GDir->head == NULL)
		return;
	
//printf("debug:21 %s\n", lroot->name);	
	dirChild = lroot->GDir->head;
	t_dir *cd;
	cd = (t_dir*)dirChild->object;
//printf("debug:22 %s\n", lroot->name);	

	for (i = 0; i < (lroot->GDir->size) ; i++){
		print_GTree(cd, tab+1);
		dirChild = dirChild->next;
	  	cd = (t_dir*)dirChild->object;
	}

	if (lroot->GFiles->head == NULL)
		return;		
 
	fileChild = lroot->GFiles->head;
	t_metafile *cf;	
	cf = (t_metafile*)fileChild->object;

	for (i = 0; i < (lroot->GFiles->size) ;i++){
		for(j=0; j<tab; j++)
			my_str("    ");		
		printf("%s \n", cf->filename);
		fileChild = fileChild->next;
		cf = (t_metafile*)fileChild->object;
	}
	return;
}
Ejemplo n.º 19
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;
}
Ejemplo n.º 20
0
void theEndOfTheCli(int sig)
{
	if(sig == SIGINT)
	{
		my_str("\nEnd of ze Client\n");
		exit(1);
	}
}
Ejemplo n.º 21
0
/*pre: takes in an int pos
*post: refreshes the item at pos
*/
void refreshout(int pos)
{
	term_move_to_item(pos);
	if(gl_env.elements[pos].mode)
		term_standout();
	my_str(gl_env.elements[pos].elem);
	term_standend();
}
Ejemplo n.º 22
0
void sendstring(int spid, char* send)
{
    char t;
    char c;
    char i;

    c = 0x80;

    my_str("--STRING-->");
    my_str(send);
    my_str("<--\n");
    while(!gl_ack)
    {
        i = 0;
        while(i < 8 && !gl_ack)
        {
            t = *send & c;
            if(!t && !gl_ack)
            {
                /*
                my_str("---->");
                my_str("Sent Zero");
                my_str("<--\n");
                */
                kill(spid, SIGUSR1);
            }

            else if(t && !gl_ack)
            {
                /*
                my_str("---->");
                my_str("Sent One");
                my_str("<--\n");
                */
                kill(spid, SIGUSR2);
            }

            *send = *send << 1;
            usleep(5000);
            i++;
        }
        send ++;
    }

}
Ejemplo n.º 23
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);
    }
}
Ejemplo n.º 24
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");
	}
}
Ejemplo n.º 25
0
void sig_bye(){
  extern pid_t pid;
  extern int servfd;
  if(pid != 0){
    close(servfd);
    my_str("\nmyirc_server shutting down.\n");
  }
  exit(0);
}
Ejemplo n.º 26
0
/* refreshin.c
pre: Takes nothing
post: Prints underlines selected elem
*/
void refreshin(){
  extern t_env gl_env;
  term_move_to_item(gl_env.pos);
  term_underline();
  if(gl_env.elements[gl_env.pos].mode)
    term_standout();
  my_str(gl_env.elements[gl_env.pos].elem);
  term_standend();
  term_underend();
}
Ejemplo n.º 27
0
void set_html5_attribute_value(leaf_t self, const char* val)
{
	html_attr_t attr = (html_attr_t) self->leaf;
    switch(attr->name_id) {
		case attribute_class:
		// ...
			break;
		default:
		    attr->value.string = my_str(val); 	
	}
}
Ejemplo n.º 28
0
void*	my_xmalloc(int size)
{
	void* ret;
	ret=malloc(size);
	
	if(ret==NULL)
	{
		my_str("Virtual Memory exausted\n");
		exit(1);
	}
	return ret;
}
Ejemplo n.º 29
0
void		refresh_in()
{
    term_move_to_item(gl_env.pos);
    term_underline();
    if(gl_env.elements[gl_env.pos].mode == 1)
        term_standout();
    if(gl_env.elements[gl_env.pos].elem != NULL)
        my_str(gl_env.elements[gl_env.pos].elem);
    //my_char('<');
    term_underend();
    term_standend();
}
Ejemplo n.º 30
0
void		refresh_out(int i)
{
    term_move_to_item(i);
    term_underend();
    if(gl_env.elements[i].mode == 1)
        term_standout();
    if(gl_env.elements[i].elem != NULL)
        my_str(gl_env.elements[i].elem);
    //my_char('<');
    //my_int(i);
    term_standend();
}