示例#1
0
static void str_rtrim(char *str)
{
	int i = str_length(str)-1;
	while(i >= 0)
	{
		if(i > 23 || str[i] <= 32)
			str[i] = 0;
		else
			break;
		i--;
	}
}
示例#2
0
void CGameConsole::CInstance::PrintLine(const char *pLine)
{
	int Len = str_length(pLine);

	if (Len > 255)
		Len = 255;

	CBacklogEntry *pEntry = m_Backlog.Allocate(sizeof(CBacklogEntry)+Len);
	pEntry->m_YOffset = -1.0f;
	mem_copy(pEntry->m_aText, pLine, Len);
	pEntry->m_aText[Len] = 0;
}
示例#3
0
void Process(IStorage *pStorage, const char *pMapName, const char *pConfigName)
{
	CDataFileReader Map;
	if(!Map.Open(pStorage, pMapName, IStorage::TYPE_ALL))
	{
		dbg_msg("config_retrieve", "error opening map '%s'", pMapName);
		return;
	}
	bool ConfigFound = false;
	int Start, Num;
	Map.GetType(MAPITEMTYPE_INFO, &Start, &Num);
	for(int i = Start; i < Start + Num; i++)
	{
		int ItemID;
		CMapItemInfoSettings *pItem = (CMapItemInfoSettings *)Map.GetItem(i, 0, &ItemID);
		int ItemSize = Map.GetItemSize(i) - 8;
		if(!pItem || ItemID != 0)
			continue;

		if(ItemSize < (int)sizeof(CMapItemInfoSettings))
			break;
		if(!(pItem->m_Settings > -1))
			break;

		ConfigFound = true;
		IOHANDLE Config = pStorage->OpenFile(pConfigName, IOFLAG_WRITE, IStorage::TYPE_ALL);
		if(!Config)
		{
			dbg_msg("config_retrieve", "error opening config for writing '%s'", pConfigName);
			return;
		}

		int Size = Map.GetUncompressedDataSize(pItem->m_Settings);
		char *pSettings = (char *)Map.GetData(pItem->m_Settings);
		char *pNext = pSettings;
		while(pNext < pSettings + Size)
		{
			int StrSize = str_length(pNext) + 1;
			io_write(Config, pNext, StrSize - 1);
			io_write_newline(Config);
			pNext += StrSize;
		}
		Map.UnloadData(pItem->m_Settings);
		io_close(Config);
		break;
	}
	Map.Close();
	if(!ConfigFound)
	{
		fs_remove(pConfigName);
	}
}
示例#4
0
void print(int s)
{
if(s>=str_ptr){
normal_warning("print","bad string pointer");
return;
}else if(s<STRING_OFFSET){
if(s<0){
normal_warning("print","bad string offset");
}else{

if((false)&&(selector> pseudo)){

print_char(s);
return;
}
if(s==new_line_char_par){
if(selector<pseudo){
print_ln();
return;
}
}
if(s<=0x7F){
print_char(s);
}else if(s<=0x7FF){
print_char(0xC0+(s/0x40));
print_char(0x80+(s%0x40));
}else if(s<=0xFFFF){
print_char(0xE0+(s/0x1000));
print_char(0x80+((s%0x1000)/0x40));
print_char(0x80+((s%0x1000)%0x40));
}else if(s>=0x110000){
int c= s-0x110000;
if(c>=256){
formatted_warning("print","bad raw byte to print (c=%d), skipped",c);
}else{
print_char(c);
}
}else{
print_char(0xF0+(s/0x40000));
print_char(0x80+((s%0x40000)/0x1000));
print_char(0x80+(((s%0x40000)%0x1000)/0x40));
print_char(0x80+(((s%0x40000)%0x1000)%0x40));
}
}
return;
}
if(selector==new_string){
append_string(str_string(s),(unsigned)str_length(s));
return;
}
lprint(&str_lstring(s));
}
示例#5
0
void rev_string(char str[]){
	unsigned i = 0;
	int len = str_length(str);
	char temp;

	for(i = 0; i < len / 2; i++){
	    temp = str[i];
	    str[i] = str[len - i -1];
	    str[len - i -1] = temp;
	}
	str[len] = '\0';
	printf("%s", str);
}
示例#6
0
void CGameConsole::PossibleCommandsRenderCallback(const char *pStr, void *pUser)
{
	CRenderInfo *pInfo = static_cast<CRenderInfo *>(pUser);
	
	if(pInfo->m_EnumCount == pInfo->m_WantedCompletion)
	{
		float tw = pInfo->m_pSelf->TextRender()->TextWidth(pInfo->m_Cursor.m_pFont, pInfo->m_Cursor.m_FontSize, pStr, -1);
		pInfo->m_pSelf->Graphics()->TextureSet(-1);
		pInfo->m_pSelf->Graphics()->QuadsBegin();
			pInfo->m_pSelf->Graphics()->SetColor(229.0f/255.0f,185.0f/255.0f,4.0f/255.0f,0.85f);
			pInfo->m_pSelf->RenderTools()->DrawRoundRect(pInfo->m_Cursor.m_X-3, pInfo->m_Cursor.m_Y, tw+5, pInfo->m_Cursor.m_FontSize+4, pInfo->m_Cursor.m_FontSize/3);
		pInfo->m_pSelf->Graphics()->QuadsEnd();
		
		pInfo->m_pSelf->TextRender()->TextColor(0.05f, 0.05f, 0.05f,1);
		pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pStr, -1);
	}
	else
	{
		const char *pMatchStart = str_find_nocase(pStr, pInfo->m_pCurrentCmd);
		
		if(pMatchStart)
		{
			pInfo->m_pSelf->TextRender()->TextColor(0.5f,0.5f,0.5f,1);
			pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pStr, pMatchStart-pStr);
			pInfo->m_pSelf->TextRender()->TextColor(229.0f/255.0f,185.0f/255.0f,4.0f/255.0f,1);
			pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pMatchStart, str_length(pInfo->m_pCurrentCmd));
			pInfo->m_pSelf->TextRender()->TextColor(0.5f,0.5f,0.5f,1);
			pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pMatchStart+str_length(pInfo->m_pCurrentCmd), -1);
		}
		else
		{
			pInfo->m_pSelf->TextRender()->TextColor(0.75f,0.75f,0.75f,1);
			pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pStr, -1);
		}
	}
	
	pInfo->m_EnumCount++;
	pInfo->m_Cursor.m_X += 7.0f;
}
示例#7
0
文件: lineinput.cpp 项目: Laxa/ddnet
void CLineInput::Set(const char *pString)
{
	str_copy(m_Str, pString, sizeof(m_Str));
	m_Len = str_length(m_Str);
	m_CursorPos = m_Len;
	m_NumChars = 0;
	int Offset = 0;
	while(pString[Offset])
	{
		Offset = str_utf8_forward(pString, Offset);
		++m_NumChars;
	}
}
示例#8
0
bool CLocalizationDatabase::Load(const char *pFilename, IStorage *pStorage, IConsole *pConsole)
{
	// empty string means unload
	if(pFilename[0] == 0)
	{
		m_Strings.clear();
		m_CurrentVersion = 0;
		return true;
	}
	
	IOHANDLE IoHandle = pStorage->OpenFile(pFilename, IOFLAG_READ, IStorage::TYPE_ALL);
	if(!IoHandle)
		return false;
	
	char aBuf[256];
	str_format(aBuf, sizeof(aBuf), "loaded '%s'", pFilename);
	pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", aBuf);
	m_Strings.clear();
	
	CLineReader LineReader;
	LineReader.Init(IoHandle);
	char *pLine;
	while((pLine = LineReader.Get()))
	{
		if(!str_length(pLine))
			continue;
			
		if(pLine[0] == '#') // skip comments
			continue;
			
		char *pReplacement = LineReader.Get();
		if(!pReplacement)
		{
			pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", "unexpected end of file");
			break;
		}
		
		if(pReplacement[0] != '=' || pReplacement[1] != '=' || pReplacement[2] != ' ')
		{
			str_format(aBuf, sizeof(aBuf), "malform replacement line for '%s'", pLine);
			pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", aBuf);
			continue;
		}

		pReplacement += 3;
		AddString(pLine, pReplacement);
	}
	
	m_CurrentVersion = ++m_VersionCounter;
	return true;
}
示例#9
0
static int
insert_text (WInput * in, char *text, ssize_t size)
{
    int buff_len = str_length (in->buffer);

    size = min (size, (ssize_t) strlen (text)) + start - end;
    if (strlen (in->buffer) + size >= (size_t) in->current_max_size)
    {
        /* Expand the buffer */
        char *narea = g_try_realloc (in->buffer, in->current_max_size + size + in->field_width);
        if (narea != NULL)
        {
            in->buffer = narea;
            in->current_max_size += size + in->field_width;
        }
    }
    if (strlen (in->buffer) + 1 < (size_t) in->current_max_size)
    {
        if (size > 0)
        {
            int i = strlen (&in->buffer[end]);
            for (; i >= 0; i--)
                in->buffer[end + size + i] = in->buffer[end + i];
        }
        else if (size < 0)
        {
            char *p = in->buffer + end + size, *q = in->buffer + end;
            while (*q)
                *(p++) = *(q++);
            *p = 0;
        }
        memcpy (in->buffer + start, text, size - start + end);
        in->point += str_length (in->buffer) - buff_len;
        input_update (in, TRUE);
        end += size;
    }
    return size != 0;
}
struct String *string_to_struct(char *str)
{
  struct String *ptrString;

  ptrString = malloc(sizeof(struct String));
  if(ptrString == NULL)
  {
    return NULL;
  }
  ptrString->str = str;
  ptrString->length = str_length(str);

  return ptrString;
}
示例#11
0
int main(int argc, const char **argv) // ignore_convention
{
	IKernel *pKernel = IKernel::Create();
	s_pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_BASIC, argc, argv);
	s_pEngineMap = CreateEngineMap();

	bool RegisterFail = !pKernel->RegisterInterface(s_pStorage);
	RegisterFail |= !pKernel->RegisterInterface(s_pEngineMap);

	if(RegisterFail)
		return -1;

	s_File = s_pStorage->OpenFile("map_version.txt", IOFLAG_WRITE, 1);
	if(s_File)
	{
		io_write(s_File, "static CMapVersion s_aMapVersionList[] = {\n", str_length("static CMapVersion s_aMapVersionList[] = {\n"));
		s_pStorage->ListDirectory(1, "maps", MaplistCallback, 0);
		io_write(s_File, "};\n", str_length("};\n"));
		io_close(s_File);
	}

	return 0;
}
示例#12
0
文件: tok.c 项目: OpenSharp/NDceRpc
int
tokcat(TOKFILE *in, char *dst, char *dlim)
{
	int n;

	n = str_length(dst, dlim - 1);
	dst[n++] = ' ';
	if ((n = tokget(in, dst + n, dlim)) == -1) {
		AMSG("");
		return -1;
	}

	return n;
}
示例#13
0
void CNetBan::ConBansSave(IConsole::IResult *pResult, void *pUser)
{
	CNetBan *pThis = static_cast<CNetBan *>(pUser);

	char aBuf[256];
	IOHANDLE File = pThis->Storage()->OpenFile(pResult->GetString(0), IOFLAG_WRITE, IStorage::TYPE_SAVE);
	if(!File)
	{
		str_format(aBuf, sizeof(aBuf), "failed to save banlist to '%s'", pResult->GetString(0));
		pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aBuf);
		return;
	}

	int Now = time_timestamp();
	char aAddrStr1[NETADDR_MAXSTRSIZE], aAddrStr2[NETADDR_MAXSTRSIZE];
	for(CBanAddr *pBan = pThis->m_BanAddrPool.First(); pBan; pBan = pBan->m_pNext)
	{
		int Min = pBan->m_Info.m_Expires>-1 ? (pBan->m_Info.m_Expires-Now+59)/60 : -1;
		net_addr_str(&pBan->m_Data, aAddrStr1, sizeof(aAddrStr1), false);
		str_format(aBuf, sizeof(aBuf), "ban %s %i %s", aAddrStr1, Min, pBan->m_Info.m_aReason);
		io_write(File, aBuf, str_length(aBuf));
		io_write_newline(File);
	}
	for(CBanRange *pBan = pThis->m_BanRangePool.First(); pBan; pBan = pBan->m_pNext)
	{
		int Min = pBan->m_Info.m_Expires>-1 ? (pBan->m_Info.m_Expires-Now+59)/60 : -1;
		net_addr_str(&pBan->m_Data.m_LB, aAddrStr1, sizeof(aAddrStr1), false);
		net_addr_str(&pBan->m_Data.m_UB, aAddrStr2, sizeof(aAddrStr2), false);
		str_format(aBuf, sizeof(aBuf), "ban_range %s %s %i %s", aAddrStr1, aAddrStr2, Min, pBan->m_Info.m_aReason);
		io_write(File, aBuf, str_length(aBuf));
		io_write_newline(File);
	}

	io_close(File);
	str_format(aBuf, sizeof(aBuf), "saved banlist to '%s'", pResult->GetString(0));
	pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aBuf);
}
示例#14
0
LIB_EXPORT plc_tag plc_tag_create(const char *attrib_str)
{
	plc_tag tag = PLC_TAG_NULL;
	attr attribs = NULL;
	int rc = PLCTAG_STATUS_OK;

	if(!attrib_str || !str_length(attrib_str)) {
		return PLC_TAG_NULL;
	}

	attribs = attr_create_from_str(attrib_str);

	if(!attribs) {
		return PLC_TAG_NULL;
	}

	/*
	 * create the tag, this is protocol specific.
	 *
	 * If this routine wants to keep the attributes around, it needs
	 * to clone them.
	 */
	tag = ab_tag_create(attribs);

	/*
	 * FIXME - this really should be here???  Maybe not?  But, this is
	 * the only place it can be without making every protocol type do this automatically.
	 */
	if(tag && tag->status == PLCTAG_STATUS_OK) {
		rc = mutex_create(&tag->mut);

		tag->status = rc;

		tag->read_cache_expire = (uint64_t)0;
		tag->read_cache_ms = attr_get_int(attribs,"read_cache_ms",0);
	}

	/*
	 * Release memory for attributes
	 *
	 * some code is commented out that would have kept a pointer
	 * to the attributes in the tag and released the memory upon
	 * tag destruction. To prevent a memory leak without maintaining
	 * that pointer, the memory needs to be released here.
	 */
	attr_destroy(attribs);

	return tag;
}
示例#15
0
/** Find symbols that match the parameter forward and print them.
 *
 * @param name     Search string
 * @param startpos Starting position, changes to found position
 *
 * @return Pointer to the part of string that should be completed or NULL.
 *
 */
static const char *symtab_search_one(const char *name, size_t *startpos)
{
	size_t namelen = str_length(name);
	
	size_t pos;
	for (pos = *startpos; symbol_table[pos].address_le; pos++) {
		const char *curname = symbol_table[pos].symbol_name;
		
		/* Find a ':' in curname */
		const char *colon = str_chr(curname, ':');
		if (colon == NULL)
			continue;
		
		if (str_length(curname) < namelen)
			continue;
		
		if (str_lcmp(name, curname, namelen) == 0) {
			*startpos = pos;
			return (curname + str_lsize(curname, namelen));
		}
	}
	
	return NULL;
}
示例#16
0
文件: chat.cpp 项目: hamidkag/TBlock
bool CChat::LineShouldHighlight(const char *pLine, const char *pName)
{
	const char *pHL = str_find_nocase(pLine, pName);

	if (pHL)
	{
		int Length = str_length(pName);

		if((pLine == pHL || pHL[-1] == ' ') && (pHL[Length] == 0 || pHL[Length] == ' ' || pHL[Length] == '.' || pHL[Length] == '!' || pHL[Length] == ',' || pHL[Length] == '?' || pHL[Length] == ':'))
			return true;

	}

	return false;
}
示例#17
0
tag_create_function find_tag_create_func(attr attributes)
{
    int i = 0;
    const char *protocol = attr_get_str(attributes, "protocol", NULL);
    const char *make = attr_get_str(attributes, "make", attr_get_str(attributes, "manufacturer", NULL));
    const char *family = attr_get_str(attributes, "family", NULL);
    const char *model = attr_get_str(attributes, "model", NULL);
    int num_entries = (sizeof(tag_type_map)/sizeof(tag_type_map[0]));

    /* if protocol is set, then use it to match. */
    if(protocol && str_length(protocol) > 0) {
        for(i=0; i < num_entries; i++) {
            if(tag_type_map[i].protocol && str_cmp(tag_type_map[i].protocol, protocol) == 0) {
                pdebug(DEBUG_INFO,"Matched protocol=%s", protocol);
                return tag_type_map[i].tag_constructor;
            }
        }
    } else {
        /* match make/family/model */
        for(i=0; i < num_entries; i++) {
            if(tag_type_map[i].make && make && str_cmp_i(tag_type_map[i].make, make) == 0) {
                pdebug(DEBUG_INFO,"Matched make=%s",make);
                if(tag_type_map[i].family) {
                    if(family && str_cmp_i(tag_type_map[i].family, family) == 0) {
                        pdebug(DEBUG_INFO, "Matched make=%s family=%s", make, family);
                        if(tag_type_map[i].model) {
                            if(model && str_cmp_i(tag_type_map[i].model, model) == 0) {
                                pdebug(DEBUG_INFO, "Matched make=%s family=%s model=%s", make, family, model);
                                return tag_type_map[i].tag_constructor;
                            }
                        } else {
                            /* matches until a NULL */
                            pdebug(DEBUG_INFO, "Matched make=%s family=%s model=NULL", make, family);
                            return tag_type_map[i].tag_constructor;
                        }
                    }
                } else {
                    /* matched until a NULL, so we matched */
                    pdebug(DEBUG_INFO, "Matched make=%s family=NULL model=NULL", make);
                    return tag_type_map[i].tag_constructor;
                }
            }
        }
    }

    /* no match */
    return NULL;
}
示例#18
0
// general
void IGameController::Snap(int SnappingClient)
{
	CNetObj_GameInfo *pGameInfoObj = (CNetObj_GameInfo *)Server()->SnapNewItem(NETOBJTYPE_GAMEINFO, 0, sizeof(CNetObj_GameInfo));
	if(!pGameInfoObj)
		return;

	pGameInfoObj->m_GameFlags = m_GameFlags;

	pGameInfoObj->m_GameStateFlags = 0;
	pGameInfoObj->m_GameStateTimer = 0;
	switch(m_GameState)
	{
	case IGS_WARMUP_GAME:
	case IGS_WARMUP_USER:
		pGameInfoObj->m_GameStateFlags |= GAMESTATEFLAG_WARMUP;
		pGameInfoObj->m_GameStateTimer = m_GameStateTimer;
		break;
	case IGS_START_COUNTDOWN:
		pGameInfoObj->m_GameStateFlags |= GAMESTATEFLAG_STARTCOUNTDOWN|GAMESTATEFLAG_PAUSED;
		pGameInfoObj->m_GameStateTimer = m_GameStateTimer;
		break;
	case IGS_GAME_PAUSED:
		pGameInfoObj->m_GameStateFlags |= GAMESTATEFLAG_PAUSED;
		pGameInfoObj->m_GameStateTimer = m_GameStateTimer;
		break;
	case IGS_END_ROUND:
		pGameInfoObj->m_GameStateFlags |= GAMESTATEFLAG_ROUNDOVER;
		pGameInfoObj->m_GameStateTimer = Server()->Tick()-m_GameStartTick-10*Server()->TickSpeed()+m_GameStateTimer;
		break;
	case IGS_END_MATCH:
		pGameInfoObj->m_GameStateFlags |= GAMESTATEFLAG_GAMEOVER;
		pGameInfoObj->m_GameStateTimer = Server()->Tick()-m_GameStartTick-10*Server()->TickSpeed()+m_GameStateTimer;
		break;
	case IGS_GAME_RUNNING:
		// not effected
		break;
	}
	if(m_SuddenDeath)
		pGameInfoObj->m_GameStateFlags |= GAMESTATEFLAG_SUDDENDEATH;

	pGameInfoObj->m_GameStartTick = m_GameStartTick;

	pGameInfoObj->m_ScoreLimit = g_Config.m_SvScorelimit;
	pGameInfoObj->m_TimeLimit = g_Config.m_SvTimelimit;

	pGameInfoObj->m_MatchNum = (str_length(g_Config.m_SvMaprotation) && g_Config.m_SvMatchesPerMap) ? g_Config.m_SvMatchesPerMap : 0;
	pGameInfoObj->m_MatchCurrent = m_MatchCount+1;
}
示例#19
0
文件: input.c 项目: ilia-maslakov/mc
static void
move_buffer_backward (WInput * in, int start, int end)
{
    int i, pos, len;
    int str_len;

    str_len = str_length (in->buffer);
    if (start >= str_len || end > str_len + 1)
        return;

    pos = str_offset_to_pos (in->buffer, start);
    len = str_offset_to_pos (in->buffer, end) - pos;

    for (i = pos; in->buffer[i + len - 1]; i++)
        in->buffer[i] = in->buffer[i + len];
}
示例#20
0
文件: updater.cpp 项目: nheir/HClient
bool CUpdater::SelfDelete()
{
	#ifdef CONF_FAMILY_WINDOWS
        IOHANDLE bhFile = io_open("du.bat", IOFLAG_WRITE);
        if (!bhFile)
            return false;

        const char *fileCode = ":_R\r\ndel \"teeworlds.exe\"\r\nif exist \"teeworlds.exe\" goto _R\r\nrename \"tw_tmp.exe\" \"teeworlds.exe\"\r\n:_T\r\nif not exist \"teeworlds.exe\" goto _T\r\nstart teeworlds.exe\r\ndel \"du.bat\"\r\n\0";
        io_write(bhFile, fileCode, str_length(fileCode));
        io_close(bhFile);
	#else
		fs_remove("teeworlds");
	#endif

	return true;
}
示例#21
0
文件: tinput.c 项目: jvesely/helenos
static int tinput_display(tinput_t *ti)
{
	sysarg_t col0, row0;
	
	if (console_get_pos(ti->console, &col0, &row0) != EOK)
		return EIO;
	
	ti->prompt_coord = row0 * ti->con_cols + col0;
	ti->text_coord = ti->prompt_coord + str_length(ti->prompt);

	tinput_display_prompt(ti);
	tinput_display_tail(ti, 0, 0);
	tinput_position_caret(ti);

	return EOK;
}
示例#22
0
void CGameContext::ConAddVote(IConsole::IResult *pResult, void *pUserData)
{
	CGameContext *pSelf = (CGameContext *)pUserData;
	const char *pString = pResult->GetString(0);
	
	// check for valid option
	if(!pSelf->Console()->LineIsValid(pString))
	{
		char aBuf[256];
		str_format(aBuf, sizeof(aBuf), "skipped invalid option '%s'", pString);
		pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
		return;
	}
	
	CGameContext::CVoteOption *pOption = pSelf->m_pVoteOptionFirst;
	while(pOption)
	{
		if(str_comp_nocase(pString, pOption->m_aCommand) == 0)
		{
			char aBuf[256];
			str_format(aBuf, sizeof(aBuf), "option '%s' already exists", pString);
			pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
			return;
		}
		pOption = pOption->m_pNext;
	}
	
	int Len = str_length(pString);
	
	pOption = (CGameContext::CVoteOption *)pSelf->m_pVoteOptionHeap->Allocate(sizeof(CGameContext::CVoteOption) + Len);
	pOption->m_pNext = 0;
	pOption->m_pPrev = pSelf->m_pVoteOptionLast;
	if(pOption->m_pPrev)
		pOption->m_pPrev->m_pNext = pOption;
	pSelf->m_pVoteOptionLast = pOption;
	if(!pSelf->m_pVoteOptionFirst)
		pSelf->m_pVoteOptionFirst = pOption;
	
	mem_copy(pOption->m_aCommand, pString, Len+1);
	char aBuf[256];
	str_format(aBuf, sizeof(aBuf), "added option '%s'", pOption->m_aCommand);
	pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);

	CNetMsg_Sv_VoteOption OptionMsg;
	OptionMsg.m_pCommand = pOption->m_aCommand;
	pSelf->Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, -1);
}
示例#23
0
bool LOCALIZATIONDATABASE::load(const char *filename)
{
	// empty string means unload
	if(filename[0] == 0)
	{
		strings.clear();
		return true;
	}
	
	LINEREADER lr;
	IOHANDLE io = io_open(filename, IOFLAG_READ);
	if(!io)
		return false;
	
	dbg_msg("localization", "loaded '%s'", filename);
	strings.clear();
	
	linereader_init(&lr, io);
	char *line;
	while((line = linereader_get(&lr)))
	{
		if(!str_length(line))
			continue;
			
		if(line[0] == '#') // skip comments
			continue;
			
		char *replacement = linereader_get(&lr);
		if(!replacement)
		{
			dbg_msg("", "unexpected end of file");
			break;
		}
		
		if(replacement[0] != '=' || replacement[1] != '=' || replacement[2] != ' ')
		{
			dbg_msg("", "malform replacement line for '%s'", line);
			continue;
		}

		replacement += 3;
		localization.add_string(line, replacement);
	}
	
	current_version++;
	return true;
}
示例#24
0
void print_csnames(int hstart,int hfinish)
{
int h;
unsigned char*c,*l;
fprintf(stderr,"fmtdebug:csnames from %d to %d:",(int)hstart,(int)hfinish);
for(h= hstart;h<=hfinish;h++){
if(cs_text(h)> 0){

c= str_string(cs_text(h));
l= c+str_length(cs_text(h));
while(c<l){

fputc(*c++,stderr);
}
fprintf(stderr,"|");
}
}
}
示例#25
0
void CGameConsole::Dump(int Type)
{
	CInstance *pConsole = Type == CONSOLETYPE_REMOTE ? &m_RemoteConsole : &m_LocalConsole;
	char aFilename[128];
	char aDate[20];

	str_timestamp(aDate, sizeof(aDate));
	str_format(aFilename, sizeof(aFilename), "dumps/%s_dump_%s.txt", Type==CONSOLETYPE_REMOTE?"remote_console":"local_console", aDate);
	IOHANDLE io = Storage()->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
	if(io)
	{
		for(CInstance::CBacklogEntry *pEntry = pConsole->m_Backlog.First(); pEntry; pEntry = pConsole->m_Backlog.Next(pEntry))
		{
			io_write(io, pEntry->m_aText, str_length(pEntry->m_aText));
			io_write_newline(io);
		}
		io_close(io);
	}
}
示例#26
0
void CNetConnection::Disconnect(const char *pReason)
{
    if(State() == NET_CONNSTATE_OFFLINE)
        return;

    if(m_RemoteClosed == 0)
    {
        if(pReason)
            SendControl(NET_CTRLMSG_CLOSE, pReason, str_length(pReason)+1);
        else
            SendControl(NET_CTRLMSG_CLOSE, 0, 0);

        m_ErrorString[0] = 0;
        if(pReason && pReason != m_ErrorString)
            str_copy(m_ErrorString, pReason, sizeof(m_ErrorString));
    }

    Reset();
}
示例#27
0
文件: binds.cpp 项目: ftk/XXLDDRace
void CBinds::ConfigSaveCallback(IConfig *pConfig, void *pUserData)
{
    CBinds *pSelf = (CBinds *)pUserData;

    pConfig->WriteLine("unbindall");

    auto write_bind = [] (IConfig *pConfig, const char * key, const char * line) {
        char aBuffer[1024];
        char *pEnd = aBuffer+sizeof(aBuffer)-8;

        str_format(aBuffer, sizeof(aBuffer), "bind %s ", key);
        const char *pSrc = line;

        // process the string. we need to escape some characters
        char *pDst = aBuffer + str_length(aBuffer);
        *pDst++ = '"';
        while(*pSrc && pDst < pEnd)
        {
            if(*pSrc == '"' || *pSrc == '\\') // escape \ and "
                *pDst++ = '\\';
            *pDst++ = *pSrc++;
        }
        *pDst++ = '"';
        *pDst++ = 0;

        pConfig->WriteLine(aBuffer);
    };

    for(int i = 0; i < KEY_LAST; i++)
    {
        if(pSelf->m_aKeyBindings[i].empty())
            continue;

        if(!pSelf->m_aKeyBindings[i].line.empty())
            write_bind(pConfig, IInput::KeyName(i), pSelf->m_aKeyBindings[i].line.c_str());

        for(const auto& pair : pSelf->m_aKeyBindings[i].modbinds)
        {
            const std::string key = KeyCombName(i, pair.first);
            write_bind(pConfig, key.c_str(), pair.second.c_str());
        }
    }
}
示例#28
0
文件: add2.c 项目: bndao/FT_LS-Linux
char				*ft_uitoa_base(uintmax_t nbr, int base, char c)
{
	int		d;
	size_t	i;
	char	*str_number;

	if (!(str_length(&str_number, &i, &d)))
		return (NULL);
	if (nbr == 0)
		return (ft_strdup("0"));
	while (nbr)
	{
		d = nbr % base;
		str_number[i++] = (d > 9) ? (d - 10) + c : d + '0';
		nbr = nbr / base;
	}
	str_number[i] = '\0';
	return (ft_strrev(str_number));
}
示例#29
0
文件: tinput.c 项目: jvesely/helenos
static void tinput_insert_string(tinput_t *ti, const char *str)
{
	size_t ilen = min(str_length(str), INPUT_MAX_SIZE - ti->nc);
	if (ilen == 0)
		return;
	
	unsigned new_width = LIN_TO_COL(ti, ti->text_coord) + ti->nc + ilen;
	unsigned new_height = (new_width / ti->con_cols) + 1;
	if (new_height >= ti->con_rows) {
		/* Disallow text longer than 1 page for now. */
		return;
	}
	
	if (ti->nc > 0) {
		size_t i;
		for (i = ti->nc; i > ti->pos; i--)
			ti->buffer[i + ilen - 1] = ti->buffer[i - 1];
	}
	
	size_t off = 0;
	size_t i = 0;
	while (i < ilen) {
		wchar_t c = str_decode(str, &off, STR_NO_LIMIT);
		if (c == '\0')
			break;
		
		/* Filter out non-printable chars. */
		if (c < 32)
			c = 32;
		
		ti->buffer[ti->pos + i] = c;
		i++;
	}
	
	ti->pos += ilen;
	ti->nc += ilen;
	ti->buffer[ti->nc] = '\0';
	ti->sel_start = ti->pos;
	
	tinput_display_tail(ti, ti->pos - ilen, 0);
	tinput_update_origin(ti);
	tinput_position_caret(ti);
}
示例#30
0
void CGameContext::ConSave(IConsole::IResult *pResult, void *pUserData)
{
	CGameContext *pSelf = (CGameContext *) pUserData;
	if (!CheckClientID(pResult->m_ClientID))
		return;

	CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID];
	if (!pPlayer)
		return;

#if defined(CONF_SQL)
	if(!g_Config.m_SvSaveGames)
	{
		pSelf->SendChatTarget(pResult->m_ClientID, "Save-function is disabled on this server");
		return;
	}

	if(g_Config.m_SvUseSQL)
		if(pPlayer->m_LastSQLQuery + pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick())
			return;

	int Team = ((CGameControllerDDRace*) pSelf->m_pController)->m_Teams.m_Core.Team(pResult->m_ClientID);

	const char* pCode = pResult->GetString(0);
	char aCountry[4];
	if(str_length(pCode) > 3 && pCode[0] >= 'A' && pCode[0] <= 'Z' && pCode[1] >= 'A'
		&& pCode[1] <= 'Z' && pCode[2] >= 'A' && pCode[2] <= 'Z' && pCode[3] == ' ')
	{
		str_copy(aCountry, pCode, 4);
		pCode = pCode + 4;
	}
	else
	{
		str_copy(aCountry, g_Config.m_SvSqlServerName, 4);
	}

	pSelf->Score()->SaveTeam(Team, pCode, pResult->m_ClientID, aCountry);

	if(g_Config.m_SvUseSQL)
		pPlayer->m_LastSQLQuery = pSelf->Server()->Tick();
#endif
}