void FileSystemDevice::FileState::complete_readbuf(PacketHeader *packet_)
 {
  Packet<uint8,Sys::AsyncFile::ReadBufExt,ReadExt> packet=packet_;

  auto ext=packet.getExt();
  auto ext2=packet.getDeepExt<1>();

  if( ext->isOk() )
    {
     if( ext->off==ext2->off )
       {
        if( ext->data.len==ext2->len )
          {
           ext2->setData(ext->data.ptr);
          }
        else
          {
           ext2->setError(FileError_ReadLenMismatch);
          }
       }
     else
       {
        ext2->setError(FileError_BadPosition);
       }
    }
  else
    {
     ext2->setError(MakeError(ext,FileError_ReadFault));
    }

  packet.popExt().complete();
 }
示例#2
0
 void close()
  {
   error=MakeError(FileError_OpenFault);
       
   Win32::CloseHandle(handle); // ignore unprobable error
       
   handle=Win32::InvalidFileHandle;
  }
	TValueOrError<TArray<FCompiledToken>, FExpressionError> Compile()
	{
		auto Error = CompileGroup(nullptr, nullptr);
		if (Error.IsSet())
		{
			return MakeError(Error.GetValue());
		}
		return MakeValue(MoveTemp(Commands));
	}
示例#4
0
SMCResult CPluginInfoDatabase::ReadSMC_NewSection(const SMCStates *states, const char *name)
{
	if (!in_plugins)
	{
		/* If we're not in the main Plugins section, and we don't get it for the name, error out */
		if (strcmp(name, "Plugins") != 0)
		{
			return MakeError("Unknown root section: \"%s\"", name);
		}
		else 
		{
			/* Otherwise set our states */
			in_plugins = true;
			cur_plugin = -1;
			in_options = false;
		}
	}
	else
	{
		if (cur_plugin == -1)
		{
			/* If we get a plugin node and we don't have a current plugin, create a new one */
			PluginSettings *plugin;
			int i_name = m_strtab->AddString(name);
			cur_plugin = m_strtab->GetMemTable()->CreateMem(sizeof(PluginSettings), (void **)&plugin);
			plugin->Init();
			plugin->name = i_name;
			in_options = false;
		} 
		else 
		{
			if (!in_options && strcmp(name, "Options") == 0)
			{
				in_options = true;
			}
			else
			{
				return MakeError("Unknown plugin sub-section: \"%s\"", name);
			}
		}
	}

	return SMCResult_Continue;
}
	CompileResultType Compile(const TCHAR* InExpression, const FTokenDefinitions& InTokenDefinitions, const FExpressionGrammar& InGrammar)
	{
		TValueOrError<TArray<FExpressionToken>, FExpressionError> Result = Lex(InExpression, InTokenDefinitions);

		if (!Result.IsValid())
		{
			return MakeError(Result.GetError());
		}

		return Compile(MoveTemp(Result.GetValue()), InGrammar);
	}
	FExpressionResult Evaluate(const TCHAR* InExpression, const FTokenDefinitions& InTokenDefinitions, const FExpressionGrammar& InGrammar, const IOperatorEvaluationEnvironment& InEnvironment)
	{
		TValueOrError<TArray<FCompiledToken>, FExpressionError> CompilationResult = Compile(InExpression, InTokenDefinitions, InGrammar);

		if (!CompilationResult.IsValid())
		{
			return MakeError(CompilationResult.GetError());
		}

		return Evaluate(CompilationResult.GetValue(), InEnvironment);
	}
	LexResultType Lex(const TCHAR* InExpression, const FTokenDefinitions& TokenDefinitions)
	{
		FExpressionTokenConsumer TokenConsumer(InExpression);
		
		TOptional<FExpressionError> Error = TokenDefinitions.ConsumeTokens(TokenConsumer);
		if (Error.IsSet())
		{
			return MakeError(Error.GetValue());
		}

		return MakeValue(TokenConsumer.Extract());
	}
示例#8
0
 bool set(Win32::handle_t h_file)
  {
   handle=h_file;
     
   if( h_file==Win32::InvalidFileHandle )
     {
      error=MakeError(FileError_OpenFault);
         
      return false;
     }
   else
     {  
      error=FileError_Ok;
         
      return true;
     }
  }
void FileSystemDevice::complete_getFileList(PacketHeader *packet_)
 {
  Packet<uint8,Sys::AsyncFileSystem::FileExt,GetFileListExt> packet=packet_;

  auto ext=packet.getExt();
  auto ext2=packet.getDeepExt<1>();

  if( ext->isOk() )
    {
     CompleteFile(ext2,ext->file_id,ext->file_len);
    }
  else
    {
     CompleteFile(ext2,MakeError(ext,FileError_OpFault));
    }

  packet.popExt().complete();
 }
void FileSystemDevice::FileState::complete_write(PacketHeader *packet_)
 {
  Packet<uint8,Sys::AsyncFile::WriteExt,WriteExt> packet=packet_;

  auto ext=packet.getExt();
  auto ext2=packet.getDeepExt<1>();

  if( ext->isOk() )
    {
     ext2->setFileLen(ext->file_len);
    }
  else
    {
     ext2->setError(MakeError(ext,FileError_WriteFault));
    }

  packet.popExt().complete();
 }
void FileSystemDevice::complete_getFileUpdateTime(PacketHeader *packet_)
 {
  Packet<uint8,Sys::AsyncFileSystem::CmpFileTimeExt,GetFileUpdateTimeExt> packet=packet_;

  auto ext=packet.getExt();
  auto ext2=packet.getDeepExt<1>();

  if( ext->isOk() )
    {
     ext2->setFileTime(ext->file_time);
    }
  else
    {
     ext2->setError(MakeError(ext,FileError_OpFault));
    }

  packet.popExt().complete();
 }
void FileSystemDevice::FileState::complete_close(PacketHeader *packet_)
 {
  Packet<uint8,Sys::AsyncFile::CloseExt,CloseExt> packet=packet_;

  auto ext=packet.getExt();
  auto ext2=packet.getDeepExt<1>();

  if( ext->isOk() )
    {
     ext2->noError();
    }
  else
    {
     ext2->setError(MakeError(ext,FileError_CloseFault));
    }

  packet.popExt().complete();
 }
示例#13
0
void Web::main(std::string url) {
	struct timeval start, end;
	gettimeofday(&start, NULL);
	long mtime, seconds, useconds;
	
	
	std::string lock = GetFromConfig<std::string>("setup.lockfile");
	if (!Generic::FileSystem::Check(lock).ExistFile()) {
		if (url != "/setup"){
			response().set_redirect_header("/setup");
			return;
		}
	}
	if (!dispatcher().dispatch(url)) {
		MakeError("html",404,"Url " + url + " was not found");
	}
	gettimeofday(&end, NULL);
	
	seconds  = end.tv_sec  - start.tv_sec;
	useconds = end.tv_usec - start.tv_usec;
	mtime = ((seconds) * 1000 + useconds/1000.0) + 0.5;
	printf("Elapsed time: %ld milliseconds\n", mtime);
}
void FTextFormatData::Compile_NoLock()
{
	LexedExpression.Reset();
	if (SourceType == ESourceType::Text)
	{
		SourceExpression = SourceText.ToString();
		CompiledTextSnapshot = FTextSnapshot(SourceText);
	}
	CompiledExpressionType = FTextFormat::EExpressionType::Simple;
	BaseFormatStringLength = 0;
	FormatArgumentEstimateMultiplier = 1;

	TValueOrError<TArray<FExpressionToken>, FExpressionError> Result = ExpressionParser::Lex(*SourceExpression, FTextFormatter::Get().GetTextFormatDefinitions());
	bool bValidExpression = Result.IsValid();
	if (bValidExpression)
	{
		LexedExpression = Result.StealValue();

		// Quickly make sure the tokens are valid (argument modifiers may only follow an argument token)
		for (int32 TokenIndex = 0; TokenIndex < LexedExpression.Num(); ++TokenIndex)
		{
			const FExpressionToken& Token = LexedExpression[TokenIndex];

			if (const auto* Literal = Token.Node.Cast<TextFormatTokens::FStringLiteral>())
			{
				BaseFormatStringLength += Literal->StringLen;
			}
			else if (auto* Escaped = Token.Node.Cast<TextFormatTokens::FEscapedCharacter>())
			{
				BaseFormatStringLength += 1;
			}
			else if (const auto* ArgumentToken = Token.Node.Cast<TextFormatTokens::FArgumentTokenSpecifier>())
			{
				CompiledExpressionType = FTextFormat::EExpressionType::Complex;

				if (LexedExpression.IsValidIndex(TokenIndex + 1))
				{
					const FExpressionToken& NextToken = LexedExpression[TokenIndex + 1];

					// Peek to see if the next token is an argument modifier
					if (const auto* ArgumentModifierToken = NextToken.Node.Cast<TextFormatTokens::FArgumentModifierTokenSpecifier>())
					{
						int32 ArgModLength = 0;
						bool ArgModUsesFormatArgs = false;
						ArgumentModifierToken->TextFormatArgumentModifier->EstimateLength(ArgModLength, ArgModUsesFormatArgs);

						BaseFormatStringLength += ArgModLength;
						FormatArgumentEstimateMultiplier += (ArgModUsesFormatArgs) ? 1 : 0;

						++TokenIndex; // walk over the argument token so that the next iteration will skip over the argument modifier
						continue;
					}
				}
			}
			else if (Token.Node.Cast<TextFormatTokens::FArgumentModifierTokenSpecifier>())
			{
				// Unexpected argument modifier token!
				const FText ErrorSourceText = FText::FromString(Token.Context.GetString());
				Result = MakeError(FExpressionError(FText::Format(LOCTEXT("UnexpectedArgumentModifierToken", "Unexpected 'argument modifier' token: {0} (token started at index {1})"), ErrorSourceText, Token.Context.GetCharacterIndex())));
				bValidExpression = false;
				break;
			}
		}
	}
	
	if (!bValidExpression)
	{
		LexedExpression.Reset();
		CompiledExpressionType = FTextFormat::EExpressionType::Invalid;
		UE_LOG(LogTextFormatter, Warning, TEXT("Failed to compile text format string '%s': %s"), *SourceExpression, *Result.GetError().Text.ToString());
	}
}
示例#15
0
文件: type.cpp 项目: wh5a/xgill
Type* Type::Read(Buffer *buf)
{
  uint32_t kind = 0;
  uint32_t width = 0;
  uint32_t count = 0;
  bool sign = false;
  bool varargs = false;
  String *name = NULL;
  Type *target_type = NULL;
  TypeCSU *csu_type = NULL;
  Vector<Type*> argument_types;

  Try(ReadOpenTag(buf, TAG_Type));
  while (!ReadCloseTag(buf, TAG_Type)) {
    switch (PeekOpenTag(buf)) {
    case TAG_Kind: {
      Try(!kind);
      Try(ReadTagUInt32(buf, TAG_Kind, &kind));
      break;
    }
    case TAG_Width: {
      Try(ReadTagUInt32(buf, TAG_Width, &width));
      break;
    }
    case TAG_Sign: {
      Try(ReadTagEmpty(buf, TAG_Sign));
      sign = true;
      break;
    }
    case TAG_Name: {
      Try(!name);
      Try(kind == YK_CSU);
      name = String::ReadWithTag(buf, TAG_Name);
      break;
    }
    case TAG_Type: {
      Try(!target_type);
      Try(kind == YK_Pointer || kind == YK_Array || kind == YK_Function);
      target_type = Type::Read(buf);
      break;
    }
    case TAG_Count: {
      Try(kind == YK_Array);
      Try(ReadTagUInt32(buf, TAG_Count, &count));
      break;
    }
    case TAG_TypeFunctionCSU: {
      Try(!csu_type);
      Try(ReadOpenTag(buf, TAG_TypeFunctionCSU));
      csu_type = Type::Read(buf)->AsCSU();
      Try(ReadCloseTag(buf, TAG_TypeFunctionCSU));
      break;
    }
    case TAG_TypeFunctionVarArgs: {
      Try(kind == YK_Function);
      Try(ReadTagEmpty(buf, TAG_TypeFunctionVarArgs));
      varargs = true;
      break;
    }
    case TAG_TypeFunctionArguments: {
      Try(kind == YK_Function);
      Try(argument_types.Empty());
      Try(ReadOpenTag(buf, TAG_TypeFunctionArguments));
      while (!ReadCloseTag(buf, TAG_TypeFunctionArguments)) {
        Type *ntype = Type::Read(buf);
        argument_types.PushBack(ntype);
      }
      break;
    }
    default:
      Try(false);
    }
  }

  switch ((TypeKind)kind) {
  case YK_Error:
    return MakeError();
  case YK_Void:
    return MakeVoid();
  case YK_Int:
    return MakeInt(width, sign);
  case YK_Float:
    return MakeFloat(width);
  case YK_Pointer:
    Try(target_type);
    return MakePointer(target_type, width);
  case YK_Array:
    Try(target_type);
    return MakeArray(target_type, count);
  case YK_CSU:
    Try(name);
    return MakeCSU(name);
  case YK_Function:
    Try(target_type);
    return MakeFunction(target_type, csu_type, varargs, argument_types);
  default:
    Try(false);
  }
}
示例#16
0
SMCResult CPluginInfoDatabase::ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value)
{
	if (cur_plugin != -1)
	{
		PluginSettings *plugin = (PluginSettings *)m_strtab->GetMemTable()->GetAddress(cur_plugin);
		if (!in_options)
		{
			if (strcmp(key, "pause") == 0)
			{
				if (strcasecmp(value, "yes") == 0)
				{
					plugin->pause_val = true;
				} 
				else 
				{
					plugin->pause_val = false;
				}
			} 
			else if (strcmp(key, "lifetime") == 0) 
			{
				if (strcasecmp(value, "private") == 0)
				{
					plugin->type_val = PluginType_Private;
				} 
				else if (strcasecmp(value, "mapsync") == 0) 
				{
					plugin->type_val = PluginType_MapUpdated;
				}
				else if (strcasecmp(value, "maponly") == 0) 
				{
					plugin->type_val = PluginType_MapOnly;
				}
				else if (strcasecmp(value, "global") == 0) 
				{
					plugin->type_val = PluginType_Global;
				}
				else 
				{
					return MakeError("Unknown value for key \"lifetime\": \"%s\"", value);
				}
			}
			else if (strcmp(key, "blockload") == 0) 
			{
				plugin->blockload_val = true;
			} 
			else 
			{
				return MakeError("Unknown property key: \"%s\"", key);
			}
		}
		else 
		{
			/* Cache every option, valid or not */
			int keyidx = m_strtab->AddString(key);
			int validx = m_strtab->AddString(value);
			PluginOpts *table;
			BaseMemTable *memtab = m_strtab->GetMemTable();
			plugin = (PluginSettings *)memtab->GetAddress(cur_plugin);
			if (plugin->opts_num + 1 > plugin->opts_size)
			{
				unsigned int oldsize = plugin->opts_size;
				if (oldsize == 0)
				{
					//right now we don't have many
					plugin->opts_size = 2;
				} 
				else
				{
					plugin->opts_size *= 2;
				}
				int newidx = memtab->CreateMem(plugin->opts_size * sizeof(PluginOpts), (void **)&table);
				/* in case it resized */
				plugin = (PluginSettings *)memtab->GetAddress(cur_plugin);
				if (plugin->optarray != -1)
				{
					void *oldtable = memtab->GetAddress(plugin->optarray);
					memcpy(table, oldtable, oldsize * sizeof(PluginOpts));
				}
				plugin->optarray = newidx;
			}
			else
			{
				table = (PluginOpts *)memtab->GetAddress(plugin->optarray);
			}
			PluginOpts *opt = &table[plugin->opts_num++];
			opt->key = keyidx;
			opt->val = validx;
		}
	}
	else if (in_plugins)
	{
		return MakeError("Unknown property key: \"%s\"", key);
	}
	else 
	{
		/* Ignore anything we don't know about! */
	}

	return SMCResult_Continue;
}
	FExpressionResult Evaluate(const TArray<FCompiledToken>& CompiledTokens, const IOperatorEvaluationEnvironment& InEnvironment)
	{
		// Evaluation strategy: the supplied compiled tokens are const. To avoid copying the whole array, we store a separate array of
		// any tokens that are generated at runtime by the evaluator. The operand stack will consist of indices into either the CompiledTokens
		// array, or the RuntimeGeneratedTokens (where Index >= CompiledTokens.Num())
		TArray<FExpressionToken> RuntimeGeneratedTokens;
		TArray<int32> OperandStack;

		/** Get the token pertaining to the specified operand index */
		auto GetToken = [&](int32 Index) -> const FExpressionToken& {
			if (Index < CompiledTokens.Num())
			{
				return CompiledTokens[Index];
			}

			return RuntimeGeneratedTokens[Index - CompiledTokens.Num()];
		};

		/** Add a new token to the runtime generated array */
		auto AddToken = [&](FExpressionToken&& In) -> int32 {
			auto Index = CompiledTokens.Num() + RuntimeGeneratedTokens.Num();
			RuntimeGeneratedTokens.Emplace(MoveTemp(In));
			return Index;
		};


		for (int32 Index = 0; Index < CompiledTokens.Num(); ++Index)
		{
			const auto& Token = CompiledTokens[Index];

			switch(Token.Type)
			{
			case FCompiledToken::Benign:
				continue;

			case FCompiledToken::Operand:
				OperandStack.Push(Index);
				continue;

			case FCompiledToken::BinaryOperator:
				if (OperandStack.Num() >= 2)
				{
					// Binary
					const auto& R = GetToken(OperandStack.Pop());
					const auto& L = GetToken(OperandStack.Pop());

					auto OpResult = InEnvironment.ExecBinary(Token, L, R);
					if (OpResult.IsValid())
					{
						// Inherit the LHS context
						OperandStack.Push(AddToken(FExpressionToken(L.Context, MoveTemp(OpResult.GetValue()))));
					}
					else
					{
						return MakeError(OpResult.GetError());
					}
				}
				else
				{
					FFormatOrderedArguments Args;
					Args.Add(FText::FromString(Token.Context.GetString()));
					return MakeError(FText::Format(LOCTEXT("SyntaxError_NotEnoughOperandsBinary", "Not enough operands for binary operator {0}"), Args));
				}
				break;
			
			case FCompiledToken::PostUnaryOperator:
			case FCompiledToken::PreUnaryOperator:

				if (OperandStack.Num() >= 1)
				{
					const auto& Operand = GetToken(OperandStack.Pop());

					FExpressionResult OpResult = (Token.Type == FCompiledToken::PreUnaryOperator) ?
						InEnvironment.ExecPreUnary(Token, Operand) :
						InEnvironment.ExecPostUnary(Token, Operand);

					if (OpResult.IsValid())
					{
						// Inherit the LHS context
						OperandStack.Push(AddToken(FExpressionToken(Operand.Context, MoveTemp(OpResult.GetValue()))));
					}
					else
					{
						return MakeError(OpResult.GetError());
					}			
				}
				else
				{
					FFormatOrderedArguments Args;
					Args.Add(FText::FromString(Token.Context.GetString()));
					return MakeError(FText::Format(LOCTEXT("SyntaxError_NoUnaryOperand", "No operand for unary operator {0}"), Args));
				}
				break;
			}
		}

		if (OperandStack.Num() == 1)
		{
			return MakeValue(GetToken(OperandStack[0]).Node.Copy());
		}

		return MakeError(LOCTEXT("SyntaxError_InvalidExpression", "Could not evaluate expression"));
	}