예제 #1
0
파일: parsing.c 프로젝트: typp/mipc
void	parse_config(char *file, t_conf *conf)
{
  int	fd;
  char	*line;
  int	line_nb;

  if ((fd = open(file, O_RDONLY)) < 0)
    {
      fprintf(stderr, "Open failed\n");
      return ;
    }
  line_nb = 1;
  while ((line = get_next_line(fd)) != NULL)
    {
      replace_comm(line);
      epur_str(line);
      if (strlen(line))
	{
	  parse_line(line, conf, line_nb);
	}
      free(line);
      ++line_nb;
    }
  close(fd);
}
예제 #2
0
파일: parsing.c 프로젝트: abelcha/corewar
int		asm_parsing(header_t *header, char **stock, char *name)
{
  int		i;
  t_args	*args;
  t_list	*list;

  i = -1;
  if (!(args = my_calloc(1, sizeof(*args))))
    return (FAILURE);
  if (!(list = init_list()))
    return (FAILURE);
  while (stock[++i])
    {
      stock[i] = epur_str(stock[i]);
      if (split_list(stock[i], args) == FAILURE)
	return (FAILURE);
      if (line_parsing(args, list, name) == FAILURE)
	return (FAILURE);
    }
  double_free(stock);
  remplace_label(list);
  get_every_label_value(list);
  write_in_file(list, header, name);
  return (SUCCESS);
}
예제 #3
0
파일: epur_str.c 프로젝트: jaubere/maze
int	main(int ac, char **av)
{
  if (ac == 2)
    epur_str(av[1]);
  my_putchar('\n');
  return (0);
}
예제 #4
0
파일: run_client.c 프로젝트: quito/my_ftp
static int	login_user(t_info *info, t_rep *rep)
{
  char		buffer[512];
  t_rep		rep_login;

  if (!(IS_200(rep->code)) || write(1, "User: "******"USER", buffer))
	return (0);
      if (!get_answer(info, &rep_login))
	return (0);
      if (IS_200(rep_login.code))
	return (1);
      if (IS_300(rep_login.code))
	return (login_pass(info));
      return (0);
    }
  else
    return (0);
  return (1);
}
예제 #5
0
파일: check_empty.c 프로젝트: peauc/Corewar
char		*get_line_not_empty(int fd, int *line)
{
  char		*str;

  if ((str = get_next_line(fd)) == NULL ||
      (str = epur_str(str)) == NULL)
    return (NULL);
  (*line)++;
  while (str != NULL && check_empty(str) == 0)
    {
      if ((str = get_next_line(fd)) == NULL ||
 	  (str = epur_str(str)) == NULL)
	return (NULL);
      (*line)++;
    }
  return (str);
}
예제 #6
0
int	main(int argc, char **argv)
{
  char buffer[] = "    a   b  c de   f e g    ";
  char *tmp;


  tmp = epur_str(buffer);
  printf("%s\n", tmp);
  printf("%d\n", my_strlen(tmp));
}
예제 #7
0
char			*prompt_dispatcher(t_glob *glob, t_prompt *prompt)
{
  char			*str;

  if (isatty(0) && init_termcaps(glob))
    {
      str = termcap_prompt(glob, prompt);
      str = epur_str(str, 1, 0);
      reset_term();
      return (str);
    }
  else
    {
      reset_term();
      str = basic_prompt(glob, prompt);
      str = epur_str(str, 1, 0);
      return (str);
    }
}
예제 #8
0
char		*get_name(char *line)
{
  int		index_start;
  int		index_end;
  char		*name;

  line = epur_str(line);
  index_start = get_nindex_of(line, '"', 1);
  index_end = get_nindex_of(line, '"', 2);
  name = my_substr(line, index_start, index_end);
  return (name);
}
예제 #9
0
char		*get_comment(char *line)
{
  int		index_start;
  int		index_end;
  char		*comment;

  line = epur_str(line);
  index_start = get_nindex_of(line, '"', 1);
  index_end = get_nindex_of(line, '"', 2);
  comment = my_substr(line, index_start, index_end);
  return (comment);
}
예제 #10
0
파일: hist2.c 프로젝트: jalcim/42sh
void	ft_hp(t_linez *l, t_sh *term)
{
	unlink("hist_cmd");
	while (l && l->prev)
	{
		if (l->line)
			ft_strdel(&l->line);
		l->line = ft_strnew(0);
		l = l->prev;
	}
	l->line = ft_strnew(0);
	l->ep_l = epur_str(l->line, term);
}
예제 #11
0
void		my_cmd(t_list *list, char *s, char **env, int i)
{
  char		*epur_s;
  char		**tab;

  epur_s = epur_str(s);
  tab = my_str_to_wordtab(epur_s, &i);
  if ((my_builtin(list, s, tab, env)) == 0 &&		\
      check_redir(epur_s, tab, env, i) == 0)
      my_fork(tab[0], tab, env);
  if (check_env(tab, env) == 1)
    env = env_cpy(list);
  check_recurs(list, s, env, i - 1);
  my_mini_free(epur_s, tab);
}
예제 #12
0
파일: server.c 프로젝트: simbaste/myirc
static int	run_func(t_server *server, t_client *client, char *cmd)
{
  int		i;
  char		*ft;

  i = 0;
  ft = strtok(strdup(cmd), " \n");
  while (i < 11)
    {
      if (ft != NULL && strcasecmp(ft, g_funcs[i].cmd) == 0)
	return (g_funcs[i].p(server, client, epur_str(strdup(&cmd[strlen(ft)]))));
      i++;
    }
  dprintf(client->socket, ":127.0.0.1 421 %s :Unknown command\r\n", ft);
  return (0);
}
예제 #13
0
파일: server.c 프로젝트: simbaste/myirc
static int	run_cmd(t_server *server, t_client *client)
{
  int		n;
  char		*cmd;
  char		*new;

  n = 0;
  cmd = strdup(read_in_ring(client->buffer));
  cmd = epur_str(cmd);
  while ((new = strtok(strdup(&cmd[n]), "\r\n")))
    {
      run_func(server, client, new);
      n += strlen(new) + 2;
    }
  return (0);
}
예제 #14
0
char	*wordcpy(char *str, char *sep, int i)
{
  char	*word;
  int	j;

  j = i;
  while (find_char(str[j], sep) == 1 && str[j] != '\0')
    j++;
  if ((word = malloc(sizeof(char) * j - i + 1)) == NULL)
    return (NULL);
  j = 0;
  while (find_char(str[i], sep) == 1 && str[i] != '\0')
    word[j++] = str[i++];
  word[j] = '\0';
  word = epur_str(word);
  return (word);
}
예제 #15
0
파일: mod_env.c 프로젝트: jalcim/42sh
void		modif_e2(t_sh *t, t_linez *lz, int k, int *j)
{
	char	*tmp;
	int x = 0;
	if (ft_strncmp("unsetenv", lz->ep_l, 8))
	{
		tmp = ft_strdup(lz->ep_l);
		t->env = realloc_tb(t->env);
		if (search_oplen(&lz->ep_l[k], " =", 10000)
			< search_oplen(&lz->ep_l[k], "<>|&;", 10000))
		{
			if (ft_strchr(&(tmp[k]), '='))
			{
				t->env[++j[1]] = cpy_to(&(tmp[k]), '=');
				x = strchri(&(tmp[k]), '=');
				while (tmp[k + x] == ' ' || tmp[k + x] == '=')
					x++;
			}
			else
			{
				t->env[++j[1]] = cpy_to(&(tmp[k]), ' ');
				x = strchri(&(tmp[k]), ' ');
				while (tmp[k + x] == ' ' || tmp[k + x] == '=')
					x++;
			}
		}
		else
			t->env[++j[1]] = ft_strdup(&(tmp[k]));
		if (x && tmp[k + x])
		{
			replace_char(t->env[j[1]], '=', ' ');
			t->env[j[1]] = epur_str(t->env[j[1]], t);
			if (t->env[j[1]][len(t->env[j[1]]) - 1] == ' ')
				t->env[j[1]][len(t->env[j[1]]) - 1] = '\0';
			t->env[j[1]] = ft_strjoin_free(t->env[j[1]], "=", 1);
			t->env[j[1]] = ft_strjoin_free(t->env[j[1]], &tmp[k + x], 1);
		}
		else
			t->env[j[1]] = ft_strjoin_free(t->env[j[1]], "=", 1);
		ft_strdel(&tmp);
	}
	t->env[++j[1]] = 0;
}
예제 #16
0
파일: lexer.c 프로젝트: girards/42sh
int	lexer(char *cmd, t_token **token, t_42sh *shell)
{
  char	*error;
  t_lex	*lexi;

  lexi = xmalloc(sizeof(*lexi));
  cmd = check_carac(cmd);
  lexi->cmd = epur_str(strdup(cmd));
  if (!(lexi->cmd[0]))
    return (0);
  lex(lexi->cmd, token);
  if ((error = check_token(token, lexi)) != NULL)
    {
      printf("42sh : Syntax error near unexpected token `%s`\n", error);
      return (0);
    }
  else
    return (parser(token, shell));
  return (0);
}
예제 #17
0
static int	recup_data_loop(t_list *list, t_recup *data)
{
  to_mini(data->str);
  if ((data->cpy = my_strdup(data->str)) == NULL)
    return (-1);
  epur_str(data->cpy);
  if (my_strcmp(data->cpy, "\0") == 0)
    {
      data->flag = 1;
      if (list->tail)
	if (check_data(list->tail) == -1)
	  return (-1);
    }
  else
    if (case_add_list(list, &(data->flag), &(data->flag2)) == -1
	|| data_line(list->tail, data->str) == -1)
      return (-1);
  free(data->str);
  free(data->cpy);
  return (0);
}
예제 #18
0
파일: shell.c 프로젝트: GayKevin/42sh
int		shell(t_shell *sh)
{
  int		r;

  while (42)
    {
      sh->i_tree = -1;
      sh->check = 0;
      if (find_path(sh) == -1)
	return (-1);
      if ((r = read_buffer(sh)) > 1)
	{
	  if (parsing_main(epur_str(sh->buffer), sh) == -1)
	    return (-1);
	}
      else if (r == 0)
	return (-1);
      my_free(sh->path);
    }
  return (0);
}
예제 #19
0
파일: run_client.c 프로젝트: quito/my_ftp
static int	login_pass(t_info *info)
{
  char		buffer[512];
  t_rep		rep;

  memset(buffer, 0, sizeof(buffer));
  if (write(1, "Pass: "******"PASS", buffer))
	return (0);
      if (!get_answer(info, &rep))
	return (0);
      if (!(IS_200(rep.code)))
	return (0);
      return (1);
    }
  else
    return (0);
  return (1);
}
예제 #20
0
파일: start_shell.c 프로젝트: girards/42sh
char	*read_line(int fd)
{
  int	nb;
  char	*cmd;
  char	*buffer;

  buffer = xcalloc(4096, sizeof(char));
  nb = xread(0, buffer, 4096);
  if (nb == 0)
    {
      puts("exit");
      return ("exit");
    }
  buffer[nb - 1] = '\0';
  cmd = strdup(buffer);
  free(buffer);
  cmd = epur_str(cmd);
  if (cmd[nb - 2] == '|' || cmd[nb - 2] == '>')
    cmd = cat_if_pipe(cmd);
  write(fd, cmd, strlen(cmd));
  write(fd, "\n", 1);
  return (cmd);
}
예제 #21
0
파일: lexer.c 프로젝트: girards/42sh
int	word_check(char *str, int i, t_token **token)
{
  char	*word;
  int	j;

  j = 0;
  word = xmalloc((strlen(str) + 1) * sizeof(char*));
  word = memset(word, 0, (strlen(str) + 1));
  while (((check_letter(str[i]) != -1) || str[i] == '\t' ) && (str[i] != '\0'))
    {
      word[j] = str[i];
      j++;
      i++;
    }
  word[i] = '\0';
  if (word[0] != '\0')
    {
      word = epur_str(word);
      *token = insert(*token, TOKEN_WORD, strdup(word), i);
    }
  free(word);
  return (i);
}