Пример #1
0
int     hist_down(t_line *rdl, void *data)
{
  (void)data;
  if (rdl->cur_hist == NULL)
    return (TRUE);
  gbgc_free(NULL, rdl->cur_hist->data);
  if ((rdl->cur_hist->data =
       (unsigned char*)my_strdup((char*)rdl->line)) == NULL)
    return (my_perror(MALLOC_FAILED));
  rdl->cur_hist = rdl->cur_hist->prev;
  return_to_beg(rdl, data, 1);
  if (!(hist_down_management(rdl)))
    return (FALSE);
  my_putstr((char*)rdl->line);
  return (TRUE);
}
Пример #2
0
bool	openables(char **argv)
{
	int	i;
	int	handle;

	for (i = 1; i < 3; ++i)
	{
		if ((handle = open(argv[i], O_RDONLY)) == -1)
		{
			my_putstr("Cannot open the files\n");
			return (FALSE);
		}
		close(handle);
	}
	return (TRUE);
}
Пример #3
0
static void	profondeur(char *file)
{
  t_solver	maze;
  t_pile	list;
  char		**map;

  map = parser(file, &maze);
  list.prev = NULL;
  map = algorithm(&list, &maze, map);
  if (map == NULL)
    {
      my_putstr("No solution found\n");
      exit (0);
    }
  display(&maze, map);
}
Пример #4
0
int	exec_cmd(char **tabcmd, char **env)
{
  int	pid;

  pid = fork();
  if (pid == -1)
    return (-1);
  if (pid == 0)
    {
      if (execve(tabcmd[0], tabcmd, env) == -1)
	my_putstr("$> Command not found.\n");
      exit(pid);
    }
  wait(&pid);
  return (0);
}
Пример #5
0
void	ls_alone()
{
  t_my_struct	s;

  s.dirp = opendir("./");
  while ((s.dp = readdir(s.dirp)) != NULL)
  {
    if (s.dp->d_name[0] != '.')
      {
	my_putstr(s.dp->d_name);
	my_putchar(' ');
      }
  }
  my_putchar('\n');
  closedir(s.dirp);
}
Пример #6
0
int		my_aff(t_vm *vm, t_proc *proc, int opcode)
{
  t_arg		arg[MAX_ARGS_NUMBER];
  int		pc;

  my_putstr("aff\n", 1);
  if (vm == NULL || proc == NULL)
    return (1);
  if ((pc = my_parse_arg(arg, vm->mem, opcode, proc->pc)) == -1)
    return (1);
  if (my_load_in_mem(arg, proc, vm->mem, opcode))
    return (1);
  my_put_unsigned_char(arg[0].value % 256);
  proc->pc = pc % MEM_SIZE;
  return (0);
}
Пример #7
0
int	print_hist(t_env *history, t_env *tmp, int fd, int nb)
{
  int	line;

  line = size_history(history, nb);
  while (tmp != history)
    {
      my_put_nbr(line, fd);
      my_putchar('\t', fd);
      my_putstr(tmp->str, fd);
      my_putchar('\n', fd);
      tmp = tmp->next;
      line++;
    }
  return (0);
}
Пример #8
0
int             swap_sa(t_list **l_a)
{
  t_list        *tmp;

  if (*l_a == NULL)
    return (0);
  else
    {
      tmp = *l_a;
      *l_a = (*l_a)->nxt;
      tmp->nxt = (*l_a)->nxt;
      (*l_a)->nxt = tmp;
    }
  my_putstr("sa ");
  return (0);
}
Пример #9
0
int	my_str_isnum(char *str)
{
  int	i;

  i = 0;
  while (str[i] != '\0')
    {
      if (str[i] < '0' || str[i] >  '9')
	{
	  my_putstr("Error: invalid input (positive number expected)\n");
	  return (-1);
	}
      i += 1;
    }
  return (my_getnbr(str));
}
Пример #10
0
int	val_cha(char *begin, char *ref_num,char *ref_op)
{
  int	i;

  i = 0;
  while (begin[i])
    {
      if (isop(begin[i], ref_op) == -1 && isnum(begin[i], ref_num) == 0)
	{
	  my_putstr("WARNING : Invalid character are delete for calcul\n");
	  return (0);
	}
      i = i + 1;
    }
  return (0);
}
Пример #11
0
int	my_msg(t_clt *data, char **com)
{
  if (data->s <= 2)
    {
      my_putstr("Not connected to a server\n", 2);
      return (0);
    }
  if (handle_args(com, 3, 3, 1) == 1)
    return (0);
  fill_cb("PRIVMSG ", 8, &data->wcb);
  fill_cb(com[1], strlen(com[1]), &data->wcb);
  fill_cb(" ", 1, &data->wcb);
  fill_cb(com[2], strlen(com[2]), &data->wcb);
  fill_cb("\r\n", 2, &data->wcb);
  return (0);
}
Пример #12
0
  int	main(int argc, char **argv)
  {
  
  if (argc == 3)
    {

      init_my_add(t_addition *my_add, int argc, char **argv);
      
    }
    //  if (init_my_add (&my_add, argv) = 1))
  else
    {
      my_putstr("Error !\n");
      return (1);
    }
}
Пример #13
0
t_element	*sa(t_element *list, char *letter)
{
  t_element	*temp;
  t_element	*out;

  if (len_elem(list) < 2)
    return (list);
  my_putstr(letter);
  out = list->next;
  temp = out;
  out->next = list;
  out->prev = list->prev;
  list->next = temp->next;
  list->prev = out;
  return (out);
}
Пример #14
0
void    my_error(char *str)
{
  if (str != NULL)
    {
      my_putstr("If '");
      my_putstr(str);
      my_putstr("' is not a typo you can use ");
      my_putstr("command-not-found to lookup the package ");
      my_putstr("that contains in, like this:\n");
      my_putstr("    cnf ");
      my_putstr(str);
      my_putchar('\n');
    }
}
Пример #15
0
int             swap_sb(t_list **l_b)
{
  t_list        *tmp;

  if (*l_b == NULL)
    return (0);
  else
    {
      tmp = *l_b;
      *l_b = (*l_b)->nxt;
      tmp->nxt = (*l_b)->nxt;
      (*l_b)->nxt = tmp;
    }
  my_putstr("sb ");
  return (0);
}
Пример #16
0
int	exec_complexins(t_dtf *map, char **tab)
{
  if (get_crtreturn(NULL))
    return (0);
  if (map == NULL || tab == NULL)
    return (0);
  if (count_els((void **)tab) == 4 && !my_strcmp(tab[1], MOVECD) &&
      !my_strcmp(tab[2], TOWARD))
    return (map->move(map, my_atoi(tab[0]), tab[3]));
  else
    {
      my_putstr(ERRCMD);
      return (dbgerr("Error: exec_simpleins: Unknow command"));
    }
  return (1);
}
Пример #17
0
int	check_arg(int ac, char **av)
{
    int	i;

    i = 1;
    while (i != ac)
    {
        if (av[i][0] == '-' && av[i][1] == 'v')
        {
            my_putstr("OK");
            return (1);
        }
        i++;
    }
    return (0);
}
Пример #18
0
int	my_cd_go_back(t_shell *shell)
{
  if (shell->old_dir == NULL)
    {
      my_putstr_err(": No such file or directory.\n");
      return (1);
    }
  my_putstr(shell->old_dir);
  my_putchar('\n');
  chdir(shell->old_dir);
  free(shell->old_dir);
  find_oldpwd(shell);
  set_oldpwd_and_pwd(shell);
  free(shell->cd_move);
  return (0);
}
Пример #19
0
void	restart_check_user(FILE *fd, char *users, char *tofind,
			   struct s_static_socket *socket)
{
  xfree(users);
  xfree(tofind);
  errno = 0;
  rewind(fd);
  if (errno != 0)
    {
      my_putstr("Error of rewind\n");
      xwrite(socket->cs, "451 Internal Server Error\n", 26);
      xfclose(fd);
      shut_client_socket(0);
    }
  xwrite(socket->cs, "530 Incorrect login or password\n", 32);
}
Пример #20
0
static int		init_values_champions(t_champions *champions)
{
  while (champions)
  {
    if ((champions->reg = (int*)malloc(sizeof(int) * (REG_NUMBER + 1)))
	== NULL)
      return (my_putstr(ALLOC_FAILED, 2));
    init_reg(champions->reg, champions->prog_number);
    champions->pc = champions->load_address;
    champions->carry = 0;
    champions->last_live = 0;
    champions->cycle_to_wait = 0;
    champions = champions->next;
  }
  return (0);
}
Пример #21
0
void	print_hexa(char *str, int size)
{
  int	i;

  i = 0;
  while (i < 16)
    {
      if ((i % 2) == 0)
	my_putchar(' ');
      if (i < size)
	my_put_nbr_base_pad(str[i], "0123456789abcdef", 2);
      else
	my_putstr( " ");
      i++;
    }
}
Пример #22
0
char	*my_revstr(char *str)
{
  int	count;
  int	len;
  int	tmp;

  count = 0;
  len = my_strlen(str);

  while ( count < len / 2)
    {
      my_swap(str + count, str + len - count - 1);
      count = count + 1;
    }
  my_putstr(str);
}
Пример #23
0
int		check_gravity_b(t_struct *st, int how)
{
  if (how > 4)
    {
      st->boss.life = 0;
      my_putstr("Boss dead by Gravity.\n");
    }
  how = down_b(st, 1, how);
  how = down_b(st, 2, how);
  how = down_b(st, 4, how);
  while (how > 0)
    how = down_b(st, 16, how);
  if (st->tmap[st->boss.y + 1][st->boss.x] == 'i')
    st->heros.life = 0;
  return (0);
}
Пример #24
0
int             swap_pb(t_list **l_a, t_list **l_b)
{
  t_list        *tmp;

  if (*l_a == NULL)
    return (0);
  else
    {
      tmp = *l_a;
      *l_a = (*l_a)->nxt;
      tmp->nxt = *l_b;
      *l_b = tmp;
    }
  my_putstr("pb ");
  return (0);
}
Пример #25
0
int	disp_encrypted_message(int *k_matrix, int *m_matrix, int len, int nb)
{
  int	c_m;
  int	c_m_init;
  int	c_k;
  int	c_k_init;
  int	nb_matrix;
  int	i;
  int	count_nb;
  int	space;

  c_m = 0;
  c_m_init = 0;
  c_k = 0;
  c_k_init = 0;
  i = 0;
  count_nb = 0;
  space = 0;
  my_putstr("Encrypted message :\n");
  while (i != len)
    {
      nb_matrix = 0;
      c_k = c_k_init;
      while (count_nb < nb)
	{
	  nb_matrix = nb_matrix + m_matrix[c_m] * k_matrix[c_k];
	  c_m += 1;
	  c_k += nb;
	  count_nb = count_nb + 1;
	}
      if (space != 0)
	my_putchar(' ');
      space = 1;
      my_put_nbr(nb_matrix);
      count_nb = 0;
      c_k_init = c_k_init + 1;
      c_m = c_m - nb;
      if (c_k_init == nb)
	{
	  c_k_init = 0;
	  c_m += nb;
	}
      i = i + 1;
    }
  my_putchar('\n');
  return (0);
}
Пример #26
0
void	print_start(t_all *all)
{
  if (is_same_str(all->name, "root", 4) == 0)
    {
      my_putstr(RED);
      my_putstr("\e[4;7m");
      my_putstr(all->name);
      my_putstr("\e[24;27m");
      my_putstr(YELLOW);
      my_putstr(" || ");
      my_putstr(all->floca);
      if (all->result != 0)
	my_putstr(RED);
      else
	my_putstr(GREEN);
      my_putstr(" => ");
      my_putstr("\e[0;39m");
    }
Пример #27
0
void	cent(char *str, int j)
{
  if(str[j] == '1')
    my_putstr("cent");
  if(str[j] == '2')
    my_putstr("deux cent");
  if(str[j] == '3')
    my_putstr("trois cent");
  if(str[j] == '4')
    my_putstr("quatre cent");
  if(str[j] == '5')
    my_putstr("cinq cent");
  if(str[j] == '6')
    my_putstr("six cent");
  if(str[j] == '7')
    my_putstr("sept cent");
  if(str[j] == '8')
    my_putstr("huit cent");
  if(str[j] == '9')
    my_putstr("neuf cent");
  dix(str[j]);
}
Пример #28
0
int     main()
{
  char  *term;
  char  bp[1024];
  char  t[4096];
  char  *area;
  int   li;
  int   co;
  struct winsize        w;

  signal(SIGWINCH, sigwinch);
  if ((term = getenv("TERM")) == NULL)
    {
      my_putstr("can't determine terminal\n");
      exit(1);
    }
  if (tgetent(bp, term) != 1)
    {
      my_putstr("problem with tgetent\n");
      exit(1);
    }
  if (ioctl(0, TIOCGWINSZ, &w) < 0)
    my_putstr("ioctl");
  area = t;
  li = tgetnum("li");
  co = tgetnum("co");
  my_putstr("ws_row=");
  my_put_nbr(w.ws_row);
  my_putstr("ws_col=");
  my_put_nbr(w.ws_col);
  my_putstr("\n");
  my_putstr("li=");
  my_put_nbr(li);
  my_putstr("co=");
  my_put_nbr(co);
  my_putstr("\n");
  while (1)
    pause();
}
Пример #29
0
void		entering_passive(struct s_static_socket *br)
{
  int		pasvsock;
  size_t	port;

  my_putstr("PASV Request\n");
  if (br->pasv == -1 && br->ctrl == -1)
    {
      port = 1025;
      if ((pasvsock = init_pasv_socket(&port)) > -1)
	get_host_and_connect(br, pasvsock, port);
      else
	xwrite(br->cs, "425 Opening data connection failed\n", 35);
    }
  else
    xwrite(br->cs, "125 Data connection already open\n", 33);
}
Пример #30
0
int	gere_key(int keycode, t_img *img)
{
  if (keycode == 65307)
    {
      my_putstr("Echap !\n");
      exit(0);
    }
  else if (keycode == 65362)
    {
      gere_expose(img);
    }
  else if (keycode == 65364)
    {
      gere_expose(img);
    }
  return (0);
}