예제 #1
0
void	annexe(char *str, char **tab, int i, char *opt)
{
  int	k;
  char	*tmp;
  int	n;

  k = 0;
  n = 0;
  tmp = my_xmalloc(sizeof(*tmp) * (my_strlen(str) + 2));
  while (str[i] != '\0')
    {
      if (str[i] == ':')
	{
	  tmp[k] = '/';
	  tab[n] = my_strcat(tmp, opt);
	  free(tmp);
	  n++;
	  tmp = my_xmalloc(sizeof(*tmp) * (my_strlen(str) + 2));
	  i++;
	  k = 0;
	}
      tmp[k++] = str[i++];
    }
  tmp[k] = '/';
  tab[n] = my_strcat(tmp, opt);
  free(tmp);
  sup(tab, n, opt);
}
예제 #2
0
void	annexe2(char *str, int n, char **tab)
{
  int	i;
  int	flag;
  char	*tmp;
  int	k;

  i = 0;
  k = 0;
  flag = 0;
  tmp = my_xmalloc(sizeof(*tmp) * (my_strlen(str) + 2));
  while (str[i] != '\0')
    {
      if ((str[i] == ' ') && (str[i + 1] != '\0'))
	{
	  tmp[k] = '\0';
	  tab[n++] = my_strdup(tmp);
	  free(tmp);
	  tmp = my_xmalloc(sizeof(*tmp) * (my_strlen(str) + 2));
	  i++;
	  k = 0;
	}
      flag = 1;
      tmp[k++] = str[i++];
    }
  ex(tab, n, tmp, flag);
}
예제 #3
0
char			*concat_opt_struct(t_opt *eye)
{
  char			*res;
  char			*ret;
  char			*eye_rot;
  char			*eye_pos;

  if (!(res = my_xmalloc((6 * sizeof(double)) + (3 * sizeof(char)) + 111))
      || !(ret = my_xmalloc(13)))
    return (NULL);
  bzero(res, (6 * sizeof(double)) + (3 * sizeof(char)) + 111);
  bzero(ret, 13);
  res[0] = 'E';
  res[1] = 'Y';
  res[2] = ';';
  if (!(eye_pos = get_double_som(0, NULL, NULL, eye))
      || !(eye_rot = get_double_som(1, NULL, NULL, eye)))
    return (NULL);
  strcat(res, eye_pos);
  strcat(res, eye_rot);
  sprintf(ret, "%d;%d*", eye->aa, eye->filter);
  strcat(res, ret);
  free(eye_pos);
  free(eye_rot);
  free(ret);
  return (res);
}
예제 #4
0
char			*get_obj_clust(t_obj *obj)
{
  char			*res;
  char			*ret;

  if (!(res = my_xmalloc((1024))) || !(ret = my_xmalloc(1024)))
    return (NULL);
  bzero(ret, 1024);
  bzero(res, 1024);
  if (!(res = set_res_objs(ret, res, obj)))
    return (NULL);
  return (res);
}
예제 #5
0
char		*get_next_line(int fd)
{
  char		file[BUFF_SIZE];
  char		*ret;
  static size_t	i = 0;
  int		x;

  x = 0;
  if (fd == -1)
    {
      i = 0;
      return (NULL);
    }
  if (lseek(fd, i, SEEK_SET) == -1)
    return (NULL);
  if ((x = read(fd, file, BUFF_SIZE)) <= 0)
    {
      i = 0;
      return (NULL);
    }
  gtnxln(file, &x, &i);
  if (!(ret = my_xmalloc(sizeof(char) * (x + 1))))
    exit(EXIT_FAILURE);
  ret[x] = 0;
  ret = strncpy(ret, file, x);
  i++;
  return (ret);
}
예제 #6
0
파일: backquote.c 프로젝트: gregballot/42sh
static int	replace_quote(char **str, char *replace)
{
  char		*new_string;
  int		n;

  n = 0;
  while (((*str)[n]) && (((*str)[n] != '`') || (!is_backslash(*str, n))))
    n++;
  if ((new_string = my_xmalloc((n + 1) * sizeof(char))) == NULL)
    return (-1);
  new_string[n] = 0;
  n = 0;
  while (((*str)[n]) && (((*str)[n] != '`') || (!is_backslash(*str, n))))
    {
      new_string[n] = (*str)[n];
      n++;
    }
  ++n;
  while (((*str)[n]) && (((*str)[n] != '`') || (!is_backslash(*str, n))))
    ++n;
  ++n;
  if (((new_string = my_strfreecat(new_string, replace, 1)) == NULL) ||
      ((new_string = my_strfreecat(new_string, &((*str)[n]), 0)) == NULL))
    return (-1);
  free(*str);
  *str = new_string;
  return (0);
}
예제 #7
0
파일: vm_getparams.c 프로젝트: mabm/corewar
char	*get_value_reg(int *address, t_arena *arena)
{
  char	*reg;

  reg = my_xmalloc(sizeof(char));
  reg[0] = arena->arena[*address];
  *address = increase_pc(*address, 1);
  return (reg);
}
예제 #8
0
파일: list.c 프로젝트: mabm/42sh
t_list		*create_list(char *str)
{
  t_list	*list;

  list = my_xmalloc(sizeof(*list));
  list->next = NULL;
  list->prev = NULL;
  list->data = str;
  return (list);
}
예제 #9
0
char	*my_realloc(char *str, int len)
{
  char	*dest;

  if (!(dest = my_xmalloc(len + 1)))
    return (NULL);
  dest = my_strcpy(dest, str);
  free(str);
  return (dest);
}
예제 #10
0
char		*my_int_to_char(int nb)
{
  char		*res;

  if (nb == 0)
    {
      if ((res = my_xmalloc(2)) == NULL)
	return (NULL);
      res[0] = '0';
      res[1] = '\0';
    }
  else
    {
      if ((res = my_xmalloc(my_int_len(nb) + 2)) == NULL)
	return (NULL);
      my_calc_int_to_char(nb, res, my_int_len(nb));
      res[my_int_len(nb) + 1] = '\0';
    }
  return (res);
}
예제 #11
0
파일: main.c 프로젝트: mabm/Rush-js
void		init_communication(char *ip, int port)
{
  pthread_t	thread;

  clt_com = my_xmalloc(sizeof(*clt_com));
  init_lib(clt_com, ip, port);
  signal(SIGINT, &end_connexion);
  clt_com->flag = 1;
  pthread_create(&thread, NULL, &game_thread, clt_com);
  pthread_join(thread, NULL);
}
int		redir_left(t_vars *v)
{
  t_vars	*redir;
  t_redir	*r_l;
  int		exe;

  r_l = my_xmalloc(sizeof(*r_l));
  redir = my_xmalloc(sizeof(*redir));
  init_vars(redir);
  init_redir_simp(v, r_l, '<');
  if (!check_nb(r_l) || !check_redir_left(redir, r_l))
    {
      redir = free_t_vars(redir);
      r_l = free_redirs_vars(r_l);
      return (EXIT_FAILURE);
    }
  exe = do_r_l(redir, r_l);
  redir = free_t_vars(redir);
  r_l = free_redirs_vars(r_l);
  return (exe);
}
예제 #13
0
파일: tree.c 프로젝트: mabm/42sh
t_tree		*init_tree(int type, int *access)
{
  t_tree	*tree;

  if ((tree = my_xmalloc(sizeof(*tree))) == NULL)
    return (NULL);
  tree->next = NULL;
  tree->prev = NULL;
  tree->curr_type = type;
  tree->access = access;
  return (tree);
}
int		redir_right(t_vars *v)
{
  t_vars	*redir;
  t_redir	*r_r;
  int		exe;

  r_r = my_xmalloc(sizeof(*r_r));
  redir = my_xmalloc(sizeof(*redir));
  init_vars(redir);
  init_redir_simp(v, r_r, '>');
  if (!check_nb(r_r) || !check_redir_right(redir, r_r))
    {
      redir = free_t_vars(redir);
      r_r = free_redirs_vars(r_r);
      return (EXIT_FAILURE);
    }
  exe = do_r_r(redir, r_r);
  redir = free_t_vars(redir);
  r_r = free_redirs_vars(r_r);
  return (exe);
}
예제 #15
0
파일: my_strdup.c 프로젝트: mabm/42sh
char	*my_strdup(char *src)
{
  char	*cpy;

  if (src[0] != '\0')
    {
      cpy = my_xmalloc((my_strlen(src) + 1) * sizeof(char));
      my_strcpy(cpy, src);
    }
  else
    return (NULL);
  return (cpy);
}
예제 #16
0
파일: my_strcpy.c 프로젝트: GeneralZero/ATF
char*	my_strcpy(char* dest, char* src)
{
	char* ret = dest;
	if(dest!=NULL && src !=NULL)
	{
		int count;
		ret =my_xmalloc(my_strlen(dest));
		for(count = 0; src[count]!='\0'; count++)
			ret[count] = src[count];
		ret[++count] = '\0';
	}
	return ret;
}
예제 #17
0
파일: vm_getparams.c 프로젝트: mabm/corewar
char	*get_value_index(int *address, t_arena *arena)
{
  int	i;
  char	*index;

  index = my_xmalloc(4 * sizeof(char));
  i = 0;
  while (i < 4)
    {
      index[i] = arena->arena[*address];
      *address = increase_pc(*address, 1);
      i++;
    }
  return (index);
}
예제 #18
0
파일: main.c 프로젝트: k0ink0in/42sh
char	*catch_pwd(char	*env, t_struct *pile)
{
  int	i;
  int	k;
  char	*str;

  i = 0;
  k = 0;
  str = my_xmalloc(sizeof(*str) * (my_strlen(env) + 1));
  while (env[i] != '=' && env[i] != '\0')
    i++;
  i++;
  while (env[i] != '\0')
    str[k++] = env[i++];
  pile->pwd = my_strdup(str);
  new_elem(str, &pile->save_cd);
  free(str);
  return (str);
}
예제 #19
0
파일: my_strcat.c 프로젝트: gregballot/42sh
char	*my_strncat(const char *s1, char *s2, int n)
{
  int	i;
  int	j;
  char	*ptr;

  j = 0;
  i = my_strlen(s1) + n;
  if ((ptr = my_xmalloc((i + 1) * sizeof(char))) == NULL)
    return (NULL);
  ptr[i] = 0;
  i = 0;
  while (s1 && s1[j])
      ptr[i++] = s1[j++];
  j = 0;
  while ((j < n) && (s2))
    ptr[i++] = s2[j++];
  return (ptr);
}
예제 #20
0
파일: backquote.c 프로젝트: gregballot/42sh
static int	fill_str(char **str, t_tab *tab, int i, int len)
{
  char		*s2;
  int		n;

  n = 0;
  tab->stock_pipe = NULL;
  if ((s2 = my_xmalloc((len + 1) * sizeof(char))) == NULL)
    return (-1);
  s2[len] = 0;
  ++i;
  while (((*str)[i]) && (((*str)[i] != '`') || (!is_backslash(*str, i))))
    s2[n++] = (*str)[i++];
  ++tab->bquote;
  exec_all(tab, s2);
  change_char(tab->stock_pipe);
  --tab->bquote;
  return (replace_quote(str, tab->stock_pipe));
}
예제 #21
0
파일: setenv.c 프로젝트: gregballot/42sh
int	my_setenv(t_tab *tab, t_btree **tree)
{
  char	**save;
  int	i;

  i = 0;
  while (tab->env && tab->env[i])
    ++i;
  if ((save = my_xmalloc((i + 2) * sizeof(char *))) == NULL)
    return (-1);
  i = -1;
  while (tab->env && tab->env[++i])
    save[i] = my_strdup(tab->env[i]);
  save[i] = add_equal((*tree)->right->stock);
  save[i + 1] = NULL;
  if (tab->env != NULL)
    free_tab(tab->env);
  tab->env = my_duptab(save);
  my_setpath(tab);
  return (0);
}
예제 #22
0
파일: main.c 프로젝트: chambo-e/raytracer
int		mbis(int ac, char **av)
{
  t_rt		*core;

  render = 0;
  redraw = 0;
  if (!(core = my_xmalloc(sizeof(t_rt))))
    return (-1);
  core->cluster = 1;
  core->save = NULL;
  if (ac >= 3 && (check_save_opt(&av[2], core)))
    {
      free(core);
      return (-1);
    }
  if (init_struct(core, av[1]) == -1
      || mlx_node(core) == -1)
    return (1);
  free_rt(core);
  return (0);
}
예제 #23
0
void setup_elem(int argc, char** argv)
{
	glob_t gt;
	int i;
	//my_str("before glob");
	glob(argv[1], GLOB_NOCHECK | GLOB_ERR, NULL, &gt);//
		
	for (i = 2; i < argc; i++)
	{
		glob(argv[i], GLOB_NOCHECK | GLOB_ERR | GLOB_APPEND, NULL, &gt);
	}
	
	gl_env.elements =(t_elem*)my_xmalloc(gt.gl_pathc*sizeof(t_elem));
	
	//my_int(gl_env.win.ws_row);
	//my_int(gt.gl_pathc);
	for(i=0; i<gt.gl_pathc; i++)
	{
		//my_str(gt.gl_pathv[i]);
		//my_str("0");
		gl_env.elements[i].elem = my_strdup(gt.gl_pathv[i]);
		//my_str("1");
		gl_env.elements[i].size = my_strlen(gt.gl_pathv[i]);
		//my_str("2");
		gl_env.elements[i].x = 0;
		//my_str("3");
		gl_env.elements[i].y = i%(gl_env.win.ws_row);
		//my_str("4");
		gl_env.elements[i].mode = 0;
		//my_str("5");
	}
	//my_int(gt.gl_pathc);
	gl_env.nbelems=gt.gl_pathc;
	//my_str("after blob setup");
	gl_env.pos = 0;
	//my_char('l');
	//my_str(gl_env.elements[4].elem);
	//my_int(gl_env.elements[1].y);
}
예제 #24
0
파일: my_echo.c 프로젝트: mabm/42sh
int		my_echo(t_shell *shell, char **cmd)
{
  t_echo	*echo;
  int		i;

  (void)shell;
  if ((echo = my_xmalloc(sizeof(*echo))) == NULL)
    return (-1);
  echo->opt_n = 0;
  echo->opt_e = 0;
  i = 1;
  while (cmd[i] != NULL)
    {
      i = get_opt_n(cmd, i, echo);
      i = get_opt_e(cmd, i, echo);
      i++;
    }
  if (do_echo(cmd, echo) == -1)
    return (-1);
  if (echo->opt_n != 1)
    my_putchar('\n');
  return (0);
}
예제 #25
0
파일: server_4.c 프로젝트: mabm/raytracer
void		check_new_client(t_libserver *libserver, int nb_cl_total, t_gui_serv *gui)
{
  char		*addr_client;

  addr_client = my_xmalloc(INET_ADDRSTRLEN * sizeof(*addr_client));
  if (id_exist(libserver->cli_addr[0].sin_addr.s_addr, libserver) == 0)
    {
      if (libserver->id_client >= 5)
	printf("Number maximum of player reached\n");
      else
	{
	  inet_ntop(AF_INET, &(libserver->cli_addr[0].sin_addr.s_addr),
		    addr_client, INET_ADDRSTRLEN);
	  printf("-------------------\nNouveau client : %s\
\n-------------------\n\n", addr_client);
	  send_first_data(libserver, nb_cl_total, gui);
	  libserver->fds[libserver->id_client] = libserver->newsockfd;
	  add_client(libserver->cli_addr[0].sin_addr.s_addr, libserver);
	  libserver->id_client++;
	}
    }
  free(addr_client);
}
예제 #26
0
파일: backquote.c 프로젝트: gregballot/42sh
char		*my_strfreecat(char *s1, char *s2, int is_free)
{
  int		len;
  int		i;
  char		*ptr;

  i = 0;
  len = my_strlen(s1) + my_strlen(s2);
  if ((ptr = my_xmalloc((len + 1) * sizeof(char))) == NULL)
    return (NULL);
  ptr[len] = 0;
  len = 0;
  while (s1 && s1[i])
    ptr[len++] = s1[i++];
  i = 0;
  while (s2 && s2[i])
    ptr[len++] = s2[i++];
  if (is_free == 1 || is_free == 2)
    free(s2);
  if (is_free == 2 || is_free == 3)
    free(s1);
  return (ptr);
}
예제 #27
0
char			*concat_obj_struct(t_obj *obj)
{
  t_obj			*tmp;
  char			*res;
  char			*ret;

  if (!obj->next && !obj->color)
    return (strdup(""));
  if (!(res = my_xmalloc(1)))
    return (NULL);
  res[0] = 0;
  tmp = obj;
  while (tmp && tmp->color)
    {
      if (!(ret = get_obj_clust(tmp)))
        return (NULL);
      if (!(res = realloc(res, strlen(res) + strlen(ret) + 1)))
        return (NULL);
      strcat(res, ret);
      free(ret);
      tmp = tmp->next;
    }
  return (res);
}
예제 #28
0
int main(int argc, char** argv)
{
	int sockfd;
	int n;
	int port_num;
	
	char buffer[BUFFSIZE];
	char* nname;
	
	struct sockaddr_in server_adderess;

	struct hostent* server;

	if(argc < 3)
	{
		my_str("Use: [Machine_Name] [port_num]\n");
		exit(1);
	}
	
	port_num = my_atoi(argv[2]);
	
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0) 
        my_str("ERROR opening socket");
    server = gethostbyname(argv[1]);
	
	if (server == NULL) 
	{
        my_str("ERROR, no such host\n");
        exit(0);
    }
	
	bzero((char*)&server_adderess, sizeof(server_adderess));

	server_adderess.sin_family = AF_INET;
	
	bcopy((char *)server->h_addr, (char *)&server_adderess.sin_addr.s_addr, server->h_length);
	server_adderess.sin_port = htons(port_num);
	
	//my_str("Try connection now\n");
	
	if(connect(sockfd,  (struct sockaddr *)&server_adderess, sizeof(server_adderess))<0)
	{
		my_str("Could not connect to ");
		my_str(argv[1]);
		my_char('\n');
		exit(0);
	}
	signal(SIGINT, theEndOfTheCli);
	//Initilizing Done
	//Starting Program
	
	bzero(buffer, BUFFSIZE);
	nname = (char*)my_xmalloc(50*sizeof(char));
	
	my_str("Nickname: ");
	n = read(0, nname, 49);
	nname[n] = '\0';
	
	
	int i=0;
	while(nname[i] != '\0')
	{
		if(nname[i++] == '\n')
			nname[--i] = '\0';
	}

	if(n <= 0)
		my_str("Invalid nick name\n");
	
	n = write(sockfd, nname, my_strlen(nname));
	
	if(n < 0)
		my_str("ERROR writing to socket\n");
	//my_str(buffer);
	while(1)
	{
		bzero(buffer, BUFFSIZE);
		my_str(nname);
		my_str(": ");
		n = read(0, buffer, BUFFSIZE-1);
		i=0;
		
		while(buffer[i] != '\0')
		{
			if(buffer[i++] == '\n')
				buffer[--i] = '\0';
		}
		
		if(n <= 0)
			my_str("Unable to read\n");
		
		n = write(sockfd, buffer, my_strlen(buffer));
		if(my_strncmp(buffer, "/exit", 5) == 0)
			exit(0);
		if(my_strncmp(buffer, "/nick", 5) == 0)
		{
			free(nname);
			nname = my_strdup(&buffer[6]);
		}
		if(n <= 0)
			my_str("Unable to Write\n");

	}
}
예제 #29
0
void	init_caps()
{	
	char area[2048];
	char* ptr;
	char tempBuff[1024];

	//my_str("1");
	
	if((ptr = (char *)getenv("TERM")) == NULL)
	{
		my_str("Error: getenv term");
		exit(1);
	}
	
	if((tgetent( tempBuff, ptr )) < 0)
	{
		my_str("Error: tgetent term");
		exit(1);
	}
	
	//my_str("Starting caps set up\n");
	
	if(!(gl_env.up = tgetstr(UP, (char**)(&area))))
	{
		gl_env.up = KU;
		my_str("up");
	}
	if(!(gl_env.down = (char *)tgetstr(DOWN, (char**)(&area))))
	{
		gl_env.down = KD;
		my_str("down");
	}	
	if(!(gl_env.left = (char *)tgetstr(LEFT, (char**)(&area))))
	{
		gl_env.left = KL;
		my_str("left");
	}	
	if(!(gl_env.right = (char *)tgetstr(RIGHT, (char**)(&area))))
	{
		gl_env.right = KR;
		my_str("right");
	}
	if(!(gl_env.clear = (char *)tgetstr(CLEAR, (char**)(&area))))
	{
		my_str("Error with seting clear");
		exit(1);
	}
		
	if(!(gl_env.move = (char *)tgetstr(MOVE, (char**)(&area))))
	{
		my_str("Error with seting clear");
		exit(1);
	}
		
	if(!(gl_env.standout = (char *)tgetstr(STANDOUT , (char**)(&area))))
	{
		my_str("Error with seting start highlite");
		exit(1);
	}
		
	if(!(gl_env.stand_end = (char *)tgetstr(STAND_END, (char**)(&area))))
	{
		my_str("Error with seting stop highlight");
		exit(1);
	}
		
		
	if(!(gl_env.underline = (char *)tgetstr(UNDERLINE, (char**)(&area))))
	{
		my_str("Error with seting start underline");
		exit(1);
	}
		
	if(!(gl_env.under_end = (char *)tgetstr(UNDER_END, (char**)(&area))))
	{
		my_str("Error with seting end underline");
		exit(1);
	}
		
	if(!(gl_env.cursoroff = (char *)tgetstr(CURSOROFF, (char**)(&area))))
	{
		my_str("Error with seting cursor off");
		gl_env.cursoroff = VECAP;
	}
	
	if(!(gl_env.cursoron = (char *)tgetstr(CURSORON, (char**)(&area))))
	{
		gl_env.cursoron = VICAP;
		my_str("Error with seting cursor on");
        }

	char* exc = (char*)my_xmalloc(2*sizeof(char));
	exc[0] = *((char*)ESC);
	exc[1] = '\0';
	gl_env.esc = exc;

        //my_str("Finished caps set up\n");
}
예제 #30
0
파일: ways.c 프로젝트: mabm/lem-in
void		init_path(t_path **path)
{
  *path = my_xmalloc(sizeof(**path));
  (*path)->access = NULL;
  (*path)->way = NULL;
}