Пример #1
0
int		check_sel(int nb, t_struct *st)
{
  if (nb == 3)
    exit(-1);
  else
    {
      if (nb == 2)
	{
	  write_in(WORLD, "1");
	  write_in(LEVEL1, "1");
	  write_in(LEVEL2, "1");
	  write_in(LEVEL3, "1");
	  write_in(OK, "0");
	  menu(st);
	}
      else
	execute(st);
      return (0);
    }
}
Пример #2
0
Файл: pipe.c Проект: mdugot/42sh
void			pipe_in(t_list *list, t_command *c, int input, int receive_from)
{
	t_in	*in;

	if (receive_from > -1)
		pipe_from_file(input, receive_from);
	if (list == NULL)
		return ;
	in = (t_in*)list->content;
	if (c->fd_in[in->id] && !c->fd_in[CLOSED])
		write_in(in, input);
	pipe_in(list->next, c, input, -1);
}
Пример #3
0
void		write2_conf(t_struct *st, char *str)
{
  char		*file;
  char		*tmp;
  int		nb;

  file = str_nb(st->map_sel);
  tmp = get_file_content(str);
  nb = my_getnbr(tmp);
  free(tmp);
  if (st->map_sel > nb)
    write_in(str, file);
  free(file);
}
Пример #4
0
/******************************************************************************
函    数:    my_register
功    能:    完成用户的注册工作
传入参数:    confd : 服务器和客户端的通信接口
传出参数:    无
返    回:    -1:程序错误返回
              0:程序正确执行
******************************************************************************/
int my_register(int confd, struct user *temp_user)
{
	debug_msg("d: my_reg- %s",temp_user->name);
	char buf[MAXSIZE];
	memset(buf,0,MAXSIZE);
	int n_write;
	
	/*判断用户名是否已经存在*/
	if(check_user(temp_user->name) == 1)
	{
		strcpy(buf,"Sorry!Register failed, user has existed\n");
		n_write = Write(confd,buf,strlen(buf));
		if(n_write <= 0)
		{
			fputs("Write error in my_register\n",stderr);
			close(confd);
			return -1;
		}
	}	
	else
	{
		pthread_mutex_lock(&reg_lock);  //链表和文件操作地方上锁
		
		write_in(temp_user);
		struct user_link *temp = user_node(temp_user,-1);
		insert_link(temp);
		
		pthread_mutex_unlock(&reg_lock);
		
		strcpy(buf,"Register success!\n");
		n_write = Write(confd,buf,strlen(buf));
		if(n_write <= 0)
		{
			fputs("Write error in my_register\n",stderr);
			close(confd);
			return -1;
		}

	}
	return 0;
}
Пример #5
0
void		write_in_conf_file(t_struct *st)
{
  char		*str;
  int		nb;
  char		*file;

  str = get_file_content(WORLD);
  nb = my_getnbr(str);
  file = my_strcat("conf/map/world", str);
  free(str);
  str = my_strcat(file, "/level");
  free(file);
  if (nb < st->world_sel)
    {
      file = str_nb(st->world_sel);
      write_in(WORLD, file);
      free(file);
    }
  else
    write2_conf(st, str);
  free(str);
}