Exemple #1
0
void 		my_set_env(t_mysh *mysh)
{
  char 		*param_in_env;
  int 		i;

  i = 0;
  while (mysh->tab_com[i])
    i++;
  if (comp_str(mysh->tab_com[0], "setenv") == 1 && mysh->tab_com[1] && i < 4)
    {
      if ((param_in_env = src_env(mysh->env, mysh->tab_com[1])))
	update_env(mysh);
      else
	add_env(mysh);
      if (param_in_env)
	free (param_in_env);
    }
  else if (comp_str(mysh->tab_com[0], "setenv") == 1 && i == 1)
    {
      i = -1;
      while (mysh->env && mysh->env[++i])
	my_printf("%s\n", mysh->env[i]);
    }
  else if (comp_str(mysh->tab_com[0], "setenv") == 1 && i >= 4)
    my_error("setenv: Too many arguments.\n");
}
Exemple #2
0
struct Node *insert_node(struct Node *tree, struct Node *node)
{
        struct Node *tmp=tree;
        struct Node *next=NULL;

        if (tree==NULL) return node;
        next=comp_str(node->id,tmp->id,tmp);
        while (NULL!= next)
        {
                tmp=next;
                next=comp_str(node->id,tmp->id,tmp);
        };
        if (strcmp(node->id,tmp->id)>0) tmp->right=node; else tmp->left=node;
        return tree;
}
Exemple #3
0
void 		my_cd(t_mysh *mysh)
{
  int 		ret;
  char 		*pwd;

  pwd = my_strdup("OLDPWD=");
  pwd = my_strcat_free(pwd, getcwd(NULL, 1000)); /* getcwd a free*/
  ret = 0;
  if (comp_str(mysh->tab_com[0], "cd") == 1)
    {
      if (mysh->tab_com[1] && mysh->tab_com[1][0] == '-')
	ret = chdir(src_env(mysh->env, "OLDPWD"));
      else if (!mysh->tab_com[1])
	ret = chdir(src_env(mysh->env, "HOME"));
      else
	ret = chdir(mysh->tab_com[1]);
      if (ret == -1)
	{
	  my_error("cd: no such file or directory: ");
	  my_error(mysh->tab_com[1]);
	  my_error("\n");
	}
      else
	update_pwd(mysh, pwd);
    }
  free (pwd);
}
Exemple #4
0
void		exec_multi_command(t_mysh *mysh, char *com)
{
  if (com)
    {
      mysh->tab_com = get_command(com);
      if (comp_str(com, "<<") || comp_str(com, ">>") || comp_str(com, "<")
	  || comp_str(com, ">") || comp_str(com, "|"))
	{
	  my_putstr("Ambiguous output redirect.\n");
	  clean_mem(mysh);
	  exit(42);
	}
      my_builtins(mysh);
      exec_command(mysh);
    }
  else
    clean_mem(mysh);
}
Exemple #5
0
void 		my_exit(t_mysh *mysh)
{
  int 		exite;

  exite = (mysh->tab_com[1]) ? check_str(mysh->tab_com[1]) : 0;
  if (comp_str(mysh->tab_com[0], "exit") == 1)
    {
      if (aff_prompt() == 1)
	my_putstr("exit\n");
      free_command(mysh);
      free_struct(mysh);
      exit(exite);
    }
}
Exemple #6
0
void		put_in_stdin_dd_redir_left(char *com, int fd, t_com *elem)
{
  char		**tab;
  char		*tmp;

  tab = get_command(com);
  my_putstr("? ");
  while ((tmp = get_next_line(0)) && comp_str(tmp, tab[0]) == 0)
    {
      my_write(fd, tmp, my_strlen(tmp));
      my_write(fd, "\n", 1);
      free(tmp);
      my_putstr("? ");
    }
  free_tab(tab);
  tmp = my_strdup(elem->com);
  free(elem->com);
  elem->com = my_strdup(elem->prev->prev->com);
  free(elem->prev->prev->com);
  elem->prev->prev->com = my_strdup(tmp);
  free(tmp);
}
Exemple #7
0
/*! \brief eval_elem helping function, returns an op param */
inline static int comp_ip(struct sip_msg *msg, int op, struct ip_addr* ip,
		operand_t *opd)
{
	struct hostent* he;
	char ** h;
	int ret;
	str tmp;

	ret=-1;
	switch(opd->type){
		case NET_ST:
			switch(op){
				case EQUAL_OP:
					ret=(matchnet(ip, (struct net*)opd->v.data)==1);
					break;
				case DIFF_OP:
					ret=(matchnet(ip, (struct net*)opd->v.data)!=1);
					break;
				default:
					goto error_op;
			}
			break;
		case STR_ST:
		case RE_ST:
			switch(op){
				case EQUAL_OP:
				case MATCH_OP:
					/* 1: compare with ip2str*/
					ret=comp_str(ip_addr2a(ip), opd->v.data, op, opd->type);
					if (ret==1) break;
					/* 2: resolve (name) & compare w/ all the ips */
					if (opd->type==STR_ST){
						he=resolvehost((char*)opd->v.data,0);
						if (he==0){
							LM_DBG("could not resolve %s\n",(char*)opd->v.data);
						}else if (he->h_addrtype==(int)ip->af){
							for(h=he->h_addr_list;(ret!=1)&& (*h); h++){
								ret=(memcmp(ip->u.addr, *h, ip->len)==0);
							}
							if (ret==1) break;
						}
					}
					/* 3: (slow) rev dns the address
					* and compare with all the aliases
					* !!??!! review: remove this? */
					if(received_dns & DO_REV_DNS)
					{
						he=rev_resolvehost(ip);
						if (he==0){
							print_ip("comp_ip: could not rev_resolve ip"
									" address: ", ip, "\n");
						ret=0;
						}else{
							/*  compare with primary host name */
							ret=comp_str(he->h_name, opd->v.data, op,
									opd->type);
							/* compare with all the aliases */
							for(h=he->h_aliases; (ret!=1) && (*h); h++){
								ret=comp_str(*h, opd->v.data, op, opd->type);
							}
						}
					} else {
						return 0;
					}
					break;
				case DIFF_OP:
					ret=comp_ip(msg, op, ip, opd);
					if (ret>=0) ret=!ret;
					break;
				default:
					goto error_op;
			}
			break;
		case MYSELF_ST: /* check if it's one of our addresses*/
			tmp.s=ip_addr2a(ip);
			tmp.len=strlen(tmp.s);
			ret=check_self_op(op, &tmp, 0);
			break;
		default:
			LM_CRIT("invalid type for src_ip or dst_ip (%d)\n", opd->type);
			ret=-1;
	}
	return ret;
error_op:
	LM_CRIT("invalid operator %d\n", op);
	return -1;
	
}
Exemple #8
0
/* eval_elem helping function, returns an op param */
inline static int comp_ip(struct ip_addr* ip, void* param, int op, int subtype)
{
	struct hostent* he;
	char ** h;
	int ret;
	str tmp;

	ret=-1;
	switch(subtype){
		case NET_ST:
			switch(op){
				case EQUAL_OP:
					ret=(matchnet(ip, (struct net*) param)==1);
					break;
				case DIFF_OP:
					ret=(matchnet(ip, (struct net*) param)!=1);
					break;
				default:
					goto error_op;
			}
			break;
		case STRING_ST:
		case RE_ST:
			switch(op){
				case EQUAL_OP:
				case MATCH_OP:
					/* 1: compare with ip2str*/
					ret=comp_str(ip_addr2a(ip), param, op, subtype);
					if (ret==1) break;
					/* 2: resolve (name) & compare w/ all the ips */
					if (subtype==STRING_ST){
						he=resolvehost((char*)param);
						if (he==0){
							DBG("comp_ip: could not resolve %s\n",
									(char*)param);
						}else if (he->h_addrtype==ip->af){
							for(h=he->h_addr_list;(ret!=1)&& (*h); h++){
								ret=(memcmp(ip->u.addr, *h, ip->len)==0);
							}
							if (ret==1) break;
						}
					}
					/* 3: (slow) rev dns the address
					* and compare with all the aliases
					* !!??!! review: remove this? */
					he=rev_resolvehost(ip);
					if (he==0){
						print_ip( "comp_ip: could not rev_resolve ip address:"
									" ", ip, "\n");
					ret=0;
					}else{
						/*  compare with primary host name */
						ret=comp_str(he->h_name, param, op, subtype);
						/* compare with all the aliases */
						for(h=he->h_aliases; (ret!=1) && (*h); h++){
							ret=comp_str(*h, param, op, subtype);
						}
					}
					break;
				case DIFF_OP:
					ret=comp_ip(ip, param, EQUAL_OP, subtype);
					if (ret>=0) ret=!ret;
					break;
				default:
					goto error_op;
			}
			break;
		case MYSELF_ST: /* check if it's one of our addresses*/
			tmp.s=ip_addr2a(ip);
			tmp.len=strlen(tmp.s);
			ret=check_self_op(op, &tmp, 0);
			break;
		default:
			LOG(L_CRIT, "BUG: comp_ip: invalid type for "
						" src_ip or dst_ip (%d)\n", subtype);
			ret=-1;
	}
	return ret;
error_op:
	LOG(L_CRIT, "BUG: comp_ip: invalid operator %d\n", op);
	return -1;
	
}
ShapeParser::ShapeParseResult ShapeParser::serialized(const XMLNode& node, ParserState& S)
{
	auto filename = S.map_asset_filepath(S.def_storage.prop_string(node, "filename"));
	int submesh_index = S.def_storage.prop_int(node, "shapeIndex");
	bool flipNormals = S.def_storage.prop_bool(node, "flipNormals", false);
	bool faceNormals = S.def_storage.prop_bool(node, "faceNormals", false);
	float maxSmoothAngle = S.def_storage.prop_float(node, "maxSmoothAngle", 0.0f);

	auto name = boost::filesystem::path(filename).stem().string();
	auto compiled_tar_folder = S.scene.getFileManager()->getCompiledMeshPath("") + name + "/";

	auto get_compiled_submesh_filename = [&](size_t i)
	{
		return compiled_tar_folder + std::to_string(i) + ".xmsh";
	};

	if (!boost::filesystem::exists(compiled_tar_folder) || !boost::filesystem::exists(get_compiled_submesh_filename(0)))
	{
		boost::filesystem::create_directory(compiled_tar_folder);

		enum DataPresentFlag : uint32_t
		{
			VertexNormals = 0x0001,
			TextureCoords = 0x0002,
			VertexColors = 0x0008,
			UseFaceNormals = 0x0010,
			SinglePrecision = 0x1000,
			DoublePrecision = 0x2000,
		};

		struct inflateStream
		{
			std::ifstream& m_childStream;
			size_t str_length;
			z_stream m_inflateStream;
			uint8_t m_inflateBuffer[32768];
			inflateStream(std::ifstream& str)
				:m_childStream(str)
			{
				size_t pos = m_childStream.tellg();
				m_childStream.seekg(0, m_childStream.end);
				str_length = m_childStream.tellg();
				m_childStream.seekg(pos, m_childStream.beg);

				m_inflateStream.zalloc = Z_NULL;
				m_inflateStream.zfree = Z_NULL;
				m_inflateStream.opaque = Z_NULL;
				m_inflateStream.avail_in = 0;
				m_inflateStream.next_in = Z_NULL;

				int windowBits = 15;
				auto retval = inflateInit2(&m_inflateStream, windowBits);
				if (retval != Z_OK)
					std::cout << "erro, ret : " << retval << std::endl;
			}

			void read(void *ptr, size_t size)
			{
				uint8_t *targetPtr = (uint8_t *)ptr;
				while (size > 0) {
					if (m_inflateStream.avail_in == 0) {
						size_t remaining = str_length - m_childStream.tellg();
						m_inflateStream.next_in = m_inflateBuffer;
						m_inflateStream.avail_in = (uInt)std::min(remaining, sizeof(m_inflateBuffer));
						if (m_inflateStream.avail_in == 0)
							std::cout << "more bytes req : " << size << std::endl;
						m_childStream.read((char*)m_inflateBuffer, m_inflateStream.avail_in);
					}

					m_inflateStream.avail_out = (uInt)size;
					m_inflateStream.next_out = targetPtr;

					int retval = inflate(&m_inflateStream, Z_NO_FLUSH);
					switch (retval) {
					case Z_STREAM_ERROR:
						throw std::runtime_error("inflate(): stream error!");
					case Z_NEED_DICT:
						throw std::runtime_error("inflate(): need dictionary!");
					case Z_DATA_ERROR:
						throw std::runtime_error("inflate(): data error!");
					case Z_MEM_ERROR:
						throw std::runtime_error("inflate(): memory error!");
					};

					size_t outputSize = size - (size_t)m_inflateStream.avail_out;
					targetPtr += outputSize;
					size -= outputSize;

					if (size > 0 && retval == Z_STREAM_END)
						throw std::runtime_error("inflate(): attempting to read past the end of the stream!");
				}
			}
		};

		std::ifstream ser_str(filename, std::ios::binary);

		uint16_t magic_maj, version_maj;
		ser_str.read((char*)&magic_maj, 2);
		if (magic_maj != 1052)
			throw std::runtime_error("corrupt file");
		ser_str.read((char*)&version_maj, 2);

		ser_str.seekg(-4, ser_str.end);
		uint32_t n_meshes;
		ser_str.read((char*)&n_meshes, sizeof(n_meshes));
		ser_str.seekg(-(sizeof(uint32_t) + (version_maj == 4 ? sizeof(uint64_t) : sizeof(uint32_t)) * n_meshes), ser_str.end);
		std::vector<uint64_t> mesh_offsets(n_meshes);
		if (version_maj == 4)
			ser_str.read((char*)mesh_offsets.data(), n_meshes * sizeof(uint64_t));
		else
		{
			auto q = std::vector<uint32_t>(n_meshes);
			ser_str.read((char*)q.data(), n_meshes * sizeof(uint32_t));
			for (size_t i = 0; i < n_meshes; i++)
				mesh_offsets[i] = q[i];
		}

		for (size_t num_submesh = 0; num_submesh < n_meshes; num_submesh++)
		{
			ser_str.seekg(mesh_offsets[num_submesh], ser_str.beg);
			uint16_t magic, version;
			ser_str.read((char*)&magic, 2);
			if (magic == 0)
				break;
			ser_str.read((char*)&version, 2);
			if (version != 3 && version != 4)
				throw std::runtime_error("invalid version in serialized mesh file");

			inflateStream comp_str(ser_str);
			DataPresentFlag flag;
			comp_str.read(&flag, sizeof(flag));
			std::string name = "default";
			if (version == 4)
			{
				name = "";
				char last_read;
				do
				{
					comp_str.read(&last_read, sizeof(last_read));
					name += last_read;
				} while (last_read != 0);
			}
			uint64_t nVertices, nTriangles;
			comp_str.read(&nVertices, sizeof(nVertices));
			comp_str.read(&nTriangles, sizeof(nTriangles));

			std::vector<Vec3f> positions(nVertices), normals(nVertices), colors(nVertices);
			std::vector<Vec2f> uvcoords(nVertices);
			std::vector<uint32_t> indices(nTriangles * 3);

			bool isSingle = true;

			auto read_n_vector = [&](int dim, float* buffer)
			{
				if (isSingle)
					comp_str.read((char*)buffer, sizeof(float) * dim * nVertices);
				else
				{
					double* double_storage = (double*)alloca(dim * sizeof(double));
					for (size_t i = 0; i < nVertices; i++)
					{
						comp_str.read((char*)double_storage, dim * sizeof(double));
						for (int j = 0; j < dim; j++)
							buffer[i * dim + j] = float(double_storage[j]);
					}
				}
			};

			read_n_vector(3, (float*)positions.data());
			if ((flag & DataPresentFlag::VertexNormals) == DataPresentFlag::VertexNormals)
				read_n_vector(3, (float*)normals.data());
			if ((flag & DataPresentFlag::TextureCoords) == DataPresentFlag::TextureCoords)
				read_n_vector(2, (float*)uvcoords.data());
			else std::fill(uvcoords.begin(), uvcoords.end(), Vec2f(0.0f));
			if ((flag & DataPresentFlag::VertexColors) == DataPresentFlag::VertexColors)
				read_n_vector(3, (float*)colors.data());

			comp_str.read((char*)indices.data(), sizeof(uint32_t) * nTriangles * 3);
			for (size_t i = 0; i < nTriangles * 3; i += 3)
				std::swap(indices[i + 0], indices[i + 2]);

			auto compiled_submesh_filename = get_compiled_submesh_filename(num_submesh);
			FileOutputStream fOut(compiled_submesh_filename);
			fOut << (unsigned int)MeshCompileType::Static;
			auto mat = Material(name.size() > 60 ? name.substr(0, 60) : name);
			mat.bsdf = CreateAggregate<BSDFALL>(diffuse());
			Mesh::CompileMesh(positions.data(), (int)positions.size(), normals.data(), uvcoords.data(), indices.data(), (int)indices.size(), mat, 0.0f, fOut, flipNormals, faceNormals, maxSmoothAngle);
			fOut.Close();
		}
		ser_str.close();
	}

	auto obj = S.scene.CreateNode(get_compiled_submesh_filename(submesh_index));
	parseGeneric(obj, node, S);
	return obj;
}
int commands(void *arg)
{
	char *p = NULL;
	char c[500];
	sbool running = TRUE;
	p = c;

	puts("Type /help for a list of commands");
reloop:
	while(running){
		if(gets(p)){
			switch(*p){
			case '/':
				{
					switch(*(++p)){
					case 's':
						{
							if(comp_str(p, "setgroup")){
								char user[MAX_NAME_LENGTH];
								int i = 0;
								uint16 user_id = 0;
								int group;
								p += 8; //move to name.

								while(*p){
									if(i > MAX_NAME_LENGTH){
										puts("Invalid User Name");
										goto reloop;
									}
									user[i] = *(++p);
									if(user[i] == ' '){
										user[i] = '\0';
										break;
									}
									i++;
								}

								switch(*(++p)){
								case '0': group = GROUP_USER; break;
								case '1': group = GROUP_MONITOR; break;
								case '2': group = GROUP_MAPPER; break;
								case '3': group = GROUP_DEVELOPER; break;
								case '4': group = GROUP_CREATOR; break;
								default: goto reloop;
								}

								user_id = find_player(user);

								if(user_id > -1){
									player(user_id)->group = group;
									puts("Group was changed");
								}
								else
									puts("User Not Found");
								break;
							}

							if( comp_str(++p, "hutdown")){
								set_shut_down();
							}

							break;
						}
					case 'c':
						if( comp_str(++p, "lose")){
							set_server_offline();
							return 0;
						}
						break;
					case 'h':
						if( comp_str(++p, "elp")){
							puts("::::Server Commands::::");
							puts("/close: Instant shutdown of server.");
							puts("/shutdown: Timed shutdown of server.");
							puts("/setgroup username groupid: Sets a players group via server.");
						}
						break;
					default:
						puts("Invalid command, Type /help for a list of commands"); break;
					}
					break;
				}
			default:
				puts("invalid command, type /help for a list of commands"); break;
			}
		}
	}
	return 0;
}