TEST(wchar, wmemmove) {
  const wchar_t const_wstr[] = L"This is a test of something or other.....";
  wchar_t* wstr = new wchar_t[sizeof(const_wstr)];

  wmemmove(wstr, const_wstr, sizeof(const_wstr)/sizeof(wchar_t));
  EXPECT_STREQ(const_wstr, wstr);

  wmemmove(wstr+5, wstr, sizeof(const_wstr)/sizeof(wchar_t) - 6);
  EXPECT_STREQ(L"This This is a test of something or other", wstr);
}
Example #2
0
TEST(wchar, wmemmove_smoke) {
  const wchar_t const_wstr[] = L"This is a test of something or other.....";
  wchar_t wstr[NUM_WCHARS(sizeof(const_wstr))];

  EXPECT_EQ(wstr, wmemmove(wstr, const_wstr, NUM_WCHARS(sizeof(const_wstr))));
  EXPECT_STREQ(const_wstr, wstr);

  EXPECT_EQ(wstr+5, wmemmove(wstr+5, wstr, NUM_WCHARS(sizeof(const_wstr)) - 6));
  EXPECT_STREQ(L"This This is a test of something or other", wstr);
}
Example #3
0
UnicodeString& UnicodeString::Replace(size_t Pos, size_t Len, const wchar_t* Data, size_t DataLen)
{
	// Pos & Len must be valid
	assert(Pos <= m_pData->GetLength());
	assert(Len <= m_pData->GetLength());
	assert(Pos + Len <= m_pData->GetLength());
	// Data and *this must not intersect (but Data can be located entirely within *this)
	assert(!(Data < m_pData->GetData() && Data + DataLen > m_pData->GetData()));
	assert(!(Data < m_pData->GetData() + m_pData->GetLength() && Data + DataLen > m_pData->GetData() + m_pData->GetLength()));

	if (!Len && !DataLen)
		return *this;

	size_t NewLength = m_pData->GetLength() + DataLen - Len;

	if (m_pData->GetRef() == 1 && NewLength + 1 <= m_pData->GetSize())
	{
		if (NewLength)
		{
			if (Data >= m_pData->GetData() && Data + DataLen <= m_pData->GetData() + m_pData->GetLength())
			{
				// copy data from self
				UnicodeString TmpStr(Data, DataLen);
				wmemmove(m_pData->GetData() + Pos + DataLen, m_pData->GetData() + Pos + Len, m_pData->GetLength() - Pos - Len);
				wmemcpy(m_pData->GetData() + Pos, TmpStr.CPtr(), TmpStr.GetLength());
			}
			else
			{
				wmemmove(m_pData->GetData() + Pos + DataLen, m_pData->GetData() + Pos + Len, m_pData->GetLength() - Pos - Len);
				wmemcpy(m_pData->GetData() + Pos, Data, DataLen);
			}
		}

		m_pData->SetLength(NewLength);
	}
	else
	{
		if (!NewLength)
		{
			m_pData->DecRef();
			SetEUS();
			return *this;
		}

		UnicodeStringData *NewData = new UnicodeStringData(NewLength + 1);
		wmemcpy(NewData->GetData(), m_pData->GetData(), Pos);
		wmemcpy(NewData->GetData() + Pos, Data, DataLen);
		wmemcpy(NewData->GetData() + Pos + DataLen, m_pData->GetData() + Pos + Len, m_pData->GetLength() - Pos - Len);
		NewData->SetLength(NewLength);
		m_pData->DecRef();
		m_pData = NewData;
	}

	return *this;
}
Example #4
0
bool ExtractIfExistCommand(string &strCommandText)
{
	bool Result=true;
	const wchar_t *wPtrCmd=PrepareOSIfExist(strCommandText);

	// Во! Условие не выполнено!!!
	// (например, пока рассматривали менюху, в это время)
	// какой-то злобный чебурашка стер файл!
	if (wPtrCmd)
	{
		if (!*wPtrCmd)
		{
			Result=false;
		}
		else
		{
			size_t offset = wPtrCmd-strCommandText.CPtr();
			wchar_t *CommandText = strCommandText.GetBuffer();
			wchar_t *PtrCmd = CommandText+offset;
			// прокинем "if exist"
			wmemmove(CommandText+(*CommandText==L'@'?1:0),PtrCmd,StrLength(PtrCmd)+1);
			strCommandText.ReleaseBuffer();
		}
	}

	return Result;
}
Example #5
0
/**
 * Regular handling of a key-press.
 */
static void
handle_key(volatile struct readline_session_context *ctx, wint_t wc)
{
    if (ctx->no_bufspc) {
	term_beep();
	return;
    }

    if (hiLim_isset(ctx->act)) {
	magic_swap_panels(ctx, true);
    }

    if (ctx->insert_mode) {
	wchar_t				*ptr = &ctx->buffer[ctx->bufpos];
	struct current_cursor_pos	 yx;

	(void) wmemmove(ptr + 1, ptr, wcslen(ptr));
	*ptr = wc;
	ctx->bufpos++, ctx->n_insert++;
	readline_winsch(ctx->act, wc);
	yx = term_get_pos(ctx->act);

	if (wmove(ctx->act, yx.cury, yx.curx + 1) == ERR) {
	    readline_error(EPERM, "wmove");
	}
    } else {
	ctx->buffer[ctx->bufpos] = wc;
	ctx->bufpos++, ctx->n_insert++;
	readline_waddch(ctx->act, wc);
    }

    update_panels();
    (void) doupdate();
}
Example #6
0
static void ForcePathQuoteSpaces( WCHAR * _quotePath, const std::wstring & _path )
{
	if( _path.empty() == true )
	{
		wcscpy_s( _quotePath, 2, L"" );

		return;
	}

	std::wstring true_path = _path;

	if( _path[0] == L'/' )
	{
		true_path[0] = true_path[1];
		true_path[1] = L':';
	}

	const WCHAR * pathBuffer = true_path.c_str();
	size_t pathSize = true_path.size();

	PathCanonicalize( _quotePath, pathBuffer );
	if( PathQuoteSpaces( _quotePath ) == FALSE )
	{
		wmemmove( _quotePath + 1, _quotePath, pathSize );
		_quotePath[0] = '\"';
		_quotePath[pathSize + 1] = '\"';
		_quotePath[pathSize + 2] = 0;
	}
};
Example #7
0
/* Deletes all characters from line starting at pos and going backwards
   until we find a space or run out of characters.
   Return 0 on success, -1 if nothing to delete */
int del_word_buf(ChatContext *ctx)
{
    if (ctx->len == 0 || ctx->pos == 0)
        return -1;

    int i = ctx->pos, count = 0;

    /* traverse past empty space */
    while (i > 0 && ctx->line[i - 1] == L' ') {
        ++count;
        --i;
    }

    /* traverse past last entered word */
    while (i > 0 && ctx->line[i - 1] != L' ') {
        ++count;
        --i;
    }

    wmemmove(&ctx->line[i], &ctx->line[ctx->pos], ctx->len - ctx->pos);

    ctx->start = MAX(0, ctx->start - count);   /* TODO: take into account widechar */
    ctx->len -= count;
    ctx->pos -= count;
    ctx->line[ctx->len] = L'\0';

    return 0;
}
// -----------------------------------------------------------------------------
// CTestLibcwchar::wmemmove4L
// Description:wmemmove test method function 
// This test function checks if the API copies n characters from ws2 to ws1 where ws1
// and ws2 overlap.
// -----------------------------------------------------------------------------
//
TInt CTestLibcwchar::wmemmove4L(  )
    {
	
	wchar_t ws1[50]=L"abcdefghij",*retval,*ws2,temp[50];
		
	ws2 = ws1 + 2; // to make the two memory area ws1 and ws2 overlap

	wcscpy(temp,ws2);

	retval = wmemmove(ws1,ws2,7);

	INFO_PRINTF1(_L("wmemmove4 result is"));

	int i;

	for(i=0;i<10;i++)
		{
		INFO_PRINTF5(_L("ws1[%d]=%x retval[%d]=%x"),i,ws1[i],i,retval[i]);
		}

	for(i=0;i<7;i++)
		{
		if(ws1[i] != temp[i] || retval[i] != temp[i])
			{
			return KErrGeneral;
			}
		}

	return KErrNone;

    }
TInt CTestLibcwchar::wmemmove1L(  )
    {

    wchar_t ws1[50]=L"abcdefghij",*retval,ws2[5] = L"abc";
		
	retval = wmemmove(ws1,ws2,3);

	INFO_PRINTF1(_L("wmemmove1 result is"));

	int i;

	for(i=0;i<10;i++)
		{
		INFO_PRINTF5(_L("retval[%d]=%x ws1[%d]=%x"),i,retval[i],i,ws1[i]);
		}

	for(i=0;i<3;i++)
		{
		if(ws1[i] != ws2[i])
			{
			return KErrGeneral;
			}
		}

	return KErrNone;
    
    }
Example #10
0
void test_wmemmove( void )
{
    wchar_t string1[60] = L"The quick brown dog jumps over the lazy fox";
    wchar_t string2[60] = L"The quick brown fox jumps over the lazy dog";

    wprintf( L"Wmemcpy without overlap\n" );
    wprintf( L"Source:\t\t%s\n", string1 + 40 );
    wprintf( L"Destination:\t%s\n", string1 + 16 );
    wmemcpy( string1 + 16, string1 + 40, 3 );
    wprintf( L"Result:\t\t%s\n", string1 );
    wprintf( L"Length:\t\t%d characters\n\n", wcslen( string1 ) );
    wmemcpy( string1 + 16, string2 + 40, 3 );

    wprintf( L"Wmemmove with overlap\n" );
    wprintf( L"Source:\t\t%s\n", string2 + 4 );
    wprintf( L"Destination:\t%s\n", string2 + 10 );
    wmemmove( string2 + 10, string2 + 4, 40 );
    wprintf( L"Result:\t\t%s\n", string2 );
    wprintf( L"Length:\t\t%d characters\n\n", wcslen( string2 ) );

    wprintf( L"Wmemcpy with overlap\n" );
    wprintf( L"Source:\t\t%s\n", string1 + 4 );
    wprintf( L"Destination:\t%s\n", string1 + 10 );
    wmemcpy( string1 + 10, string1 + 4, 40 );
    wprintf( L"Result:\t\t%s\n", string1 );
    wprintf( L"Length:\t\t%d characters\n\n", wcslen( string1 ) );
}
Example #11
0
	void SetData(int Type,const wchar_t *Str,const wchar_t *Eol,int StrNum,int StrPos,int Length=-1)
	{
		if (Length == -1 && Str)
			Length=(int)StrLength(Str);

		this->Type=Type;
		this->StrPos=StrPos;
		this->StrNum=StrNum;
		this->Length=Length;
		xwcsncpy(EOL,Eol?Eol:L"",ARRAYSIZE(EOL)-1);

		if (this->Str)
		{
			delete[] this->Str;
		}

		if (Str)
		{
			this->Str=new wchar_t[Length+1];

			if (this->Str)
				wmemmove(this->Str,Str,Length);
		}
		else
			this->Str=nullptr;
	}
Example #12
0
wchar_t* WINAPI TruncStr(wchar_t *Str,int MaxLength)
{
	assert(MaxLength >= 0);

	MaxLength=Max(0, MaxLength);

	if (Str)
	{
		int Length=StrLength(Str);

		if (MaxLength<0)
			MaxLength=0;

		if (Length > MaxLength)
		{
			if (MaxLength>3)
			{
				wchar_t *MovePos = Str+Length-MaxLength+3;
				wmemmove(Str+3, MovePos, StrLength(MovePos)+1);
				wmemcpy(Str,L"...",3);
			}

			Str[MaxLength]=0;
		}
	}

	return Str;
}
Example #13
0
wchar_t* TruncStrFromCenter(wchar_t *Str, int MaxLength)
{
	assert(MaxLength >= 0);

	MaxLength=Max(0, MaxLength);

	if (Str)
	{
		int Length = StrLength(Str);

		if (MaxLength < 0)
			MaxLength=0;

		if (Length > MaxLength)
		{
			const int DotsLen = 3;

			if (MaxLength > DotsLen)
			{
				int Len1 = (MaxLength - DotsLen) / 2;
				int Len2 = MaxLength - DotsLen - Len1;
				wmemcpy(Str + Len1, L"...", DotsLen);
				wmemmove(Str + Len1 + DotsLen, Str + Length - Len2, Len2);
			}

			Str[MaxLength] = 0;
		}
	}

	return Str;
}
Example #14
0
// pKey нужен для того чтобы выбрать имя значения, в котором будут храниться линки
void RegConfig::BookmarksGet(RegPath* pKey, BOOL bRemote, TCHAR** ppszBookmarks, DWORD* pnBookmarksCount)
{
	if (bUseInternalBookmarks)
		BookmarksLoadInt(pKey, bRemote);
	else
		BookmarksLoadExt(pKey, bRemote);

	if (ppszBookmarks)
	{
		if (!cchBookmarksLen || !pszBookmarks)
		{
			*ppszBookmarks = (TCHAR*)calloc(2,sizeof(TCHAR));
			if (pnBookmarksCount) *pnBookmarksCount = 0;
		}
		else
		{
			_ASSERTE(pszBookmarks);
			*ppszBookmarks = (TCHAR*)calloc(cchBookmarksLen,sizeof(TCHAR));
			#ifdef _UNICODE
			wmemmove(*ppszBookmarks, pszBookmarks, cchBookmarksLen);
			#else
			WideCharToMultiByte(nAnsiCodePage, 0, pszBookmarks, cchBookmarksLen, *ppszBookmarks, cchBookmarksLen, 0,0);
			#endif
			if (pnBookmarksCount)
				BookmarksLen(pnBookmarksCount);
		}
	}
}
Example #15
0
// Заменить в строке Str Count вхождений подстроки FindStr на подстроку ReplStr
// Если Count < 0 - заменять "до полной победы"
// Return - количество замен
int ReplaceStrings(string &strStr,const wchar_t *FindStr,const wchar_t *ReplStr,int Count,BOOL IgnoreCase)
{
	const int LenFindStr=StrLength(FindStr);
	if ( !LenFindStr || !Count )
		return 0;
	const int LenReplStr=StrLength(ReplStr);
	size_t L=strStr.GetLength();

	const int Delta = LenReplStr-LenFindStr;
	const int AllocDelta = Delta > 0 ? Delta*10 : 0;

	size_t I=0;
	int J=0;
	while (I+LenFindStr <= L)
	{
		int Res=IgnoreCase?StrCmpNI(&strStr[I], FindStr, LenFindStr):StrCmpN(&strStr[I], FindStr, LenFindStr);

		if (!Res)
		{
			wchar_t *Str;
			if (L+Delta+1 > strStr.GetSize())
				Str = strStr.GetBuffer(L+AllocDelta);
			else
				Str = strStr.GetBuffer();

			if (Delta > 0)
				wmemmove(Str+I+Delta,Str+I,L-I+1);
			else if (Delta < 0)
				wmemmove(Str+I,Str+I-Delta,L-I+Delta+1);

			wmemcpy(Str+I,ReplStr,LenReplStr);
			I += LenReplStr;

			L+=Delta;
			strStr.ReleaseBuffer(L);

			if (++J == Count && Count > 0)
				break;
		}
		else
		{
			I++;
		}
	}

	return J;
}
Example #16
0
void MakeUrlHex(LPTSTR url, LPCTSTR tid)
{
	ULARGE_INTEGER iTid; iTid.QuadPart = _tstoi64(tid);
	LPTSTR tidInUrl = _tcsstr(url, tid);
	LPTSTR trail = tidInUrl + mir_tstrlen(tid);
	wsprintf(tidInUrl, _T("%x%08x"), iTid.HighPart, iTid.LowPart); //!!!!!!!!!!!!
	wmemmove(tidInUrl + mir_tstrlen(tidInUrl), trail, mir_tstrlen(trail) + 1);
}
Example #17
0
void UnicodeString::Init(const wchar_t * Str, intptr_t Length)
{
  Data.resize(Length);
  if (Length > 0)
  {
    wmemmove(const_cast<wchar_t *>(Data.c_str()), Str, Length);
  }
  Data = Data.c_str();
}
Example #18
0
/* Deletes the character at pos. Return 0 on success, -1 if nothing to delete. */
int del_char_buf_frnt(ChatContext *ctx)
{
    if (ctx->pos >= ctx->len)
        return -1;

    wmemmove(&ctx->line[ctx->pos], &ctx->line[ctx->pos + 1], ctx->len - ctx->pos - 1);
    ctx->line[--ctx->len] = L'\0';

    return 0;
}
Example #19
0
wchar_t *InsertString(wchar_t *Str,int Pos,const wchar_t *InsStr,int InsSize)
{
	int InsLen=StrLength(InsStr);

	if (InsSize && InsSize < InsLen)
		InsLen=InsSize;

	wmemmove(Str+Pos+InsLen, Str+Pos, (StrLength(Str+Pos)+1));
	wmemcpy(Str+Pos, InsStr, InsLen);
	return Str;
}
Example #20
0
/* Adds char to line at pos. Return 0 on success, -1 if line buffer is full */
int add_char_to_buf(ChatContext *ctx, wint_t ch)
{
    if (ctx->len >= MAX_STR_SIZE - 1)
        return -1;

    wmemmove(&ctx->line[ctx->pos + 1], &ctx->line[ctx->pos], ctx->len - ctx->pos);
    ctx->line[ctx->pos++] = ch;
    ctx->line[++ctx->len] = L'\0';

    return 0;
}
Example #21
0
/* Deletes the character before pos. Return 0 on success, -1 if nothing to delete */
int del_char_buf_bck(ChatContext *ctx)
{
    if (ctx->pos <= 0)
        return -1;

    wmemmove(&ctx->line[ctx->pos - 1], &ctx->line[ctx->pos], ctx->len - ctx->pos);
    --ctx->pos;
    ctx->line[--ctx->len] = L'\0';

    return 0;
}
Example #22
0
wchar_t* WINAPI RemoveLeadingSpaces(wchar_t *Str)
{
	wchar_t *ChPtr = Str;

	if (!ChPtr)
		return nullptr;

	for (; IsSpace(*ChPtr) || IsEol(*ChPtr); ChPtr++)
		;

	if (ChPtr!=Str)
		wmemmove(Str,ChPtr,StrLength(ChPtr)+1);

	return Str;
}
Example #23
0
void FileFilterParams::SetMask(bool Used, const wchar_t *Mask)
{
	FMask.Used = Used;
	FMask.strMask = Mask;
	/* Обработка %PATHEXT% */
	string strMask = FMask.strMask;
	size_t pos;

	// проверим
	if (strMask.PosI(pos,L"%PATHEXT%"))
	{
		{
			size_t IQ1=(strMask.At(pos+9) == L',' || strMask.At(pos+9) == L';')?10:9;
			wchar_t *Ptr = strMask.GetBuffer();
			// Если встречается %pathext%, то допишем в конец...
			wmemmove(Ptr+pos,Ptr+pos+IQ1,strMask.GetLength()-pos-IQ1+1);
			strMask.ReleaseBuffer();
		}
		size_t posSeparator;

		if (strMask.Pos(posSeparator, EXCLUDEMASKSEPARATOR))
		{
			if (pos > posSeparator) // PATHEXT находится в масках исключения
			{
				Add_PATHEXT(strMask); // добавляем то, чего нету.
			}
			else
			{
				string strTmp = strMask;
				strTmp.LShift(posSeparator);
				strMask.SetLength(posSeparator);
				Add_PATHEXT(strMask);
				strMask += strTmp;
			}
		}
		else
		{
			Add_PATHEXT(strMask); // добавляем то, чего нету.
		}
	}

	// Проверка на валидность текущих настроек фильтра
	if (!FMask.FilterMask.Set(strMask,FMF_SILENT))
	{
		FMask.strMask = L"*";
		FMask.FilterMask.Set(FMask.strMask,FMF_SILENT);
	}
}
Example #24
0
/*
 * Fold the contents of standard input to fit within WIDTH columns (or bytes)
 * and write to standard output.
 *
 * If sflag is set, split the line at the last space character on the line.
 * This flag necessitates storing the line in a buffer until the current
 * column > width, or a newline or EOF is read.
 *
 * The buffer can grow larger than WIDTH due to backspaces and carriage
 * returns embedded in the input stream.
 */
void
fold(int width)
{
	static wchar_t *buf;
	static int buf_max;
	int col, i, indx, space;
	wint_t ch;

	col = indx = 0;
	while ((ch = getwchar()) != WEOF) {
		if (ch == '\n') {
			wprintf(L"%.*ls\n", indx, buf);
			col = indx = 0;
			continue;
		}
		if ((col = newpos(col, ch)) > width) {
			if (sflag) {
				i = indx;
				while (--i >= 0 && !iswblank(buf[i]))
					;
				space = i;
			}
			if (sflag && space != -1) {
				space++;
				wprintf(L"%.*ls\n", space, buf);
				wmemmove(buf, buf + space, indx - space);
				indx -= space;
				col = 0;
				for (i = 0; i < indx; i++)
					col = newpos(col, buf[i]);
			} else {
				wprintf(L"%.*ls\n", indx, buf);
				col = indx = 0;
			}
			col = newpos(col, ch);
		}
		if (indx + 1 > buf_max) {
			buf_max += LINE_MAX;
			buf = realloc(buf, sizeof(*buf) * buf_max);
			if (buf == NULL)
				err(1, "realloc()");
		}
		buf[indx++] = ch;
	}

	if (indx != 0)
		wprintf(L"%.*ls", indx, buf);
}
Example #25
0
/* Inserts string in ctx->yank into line at pos.
   Return 0 on success, -1 if yank buffer is empty or too long */
int yank_buf(ChatContext *ctx)
{
    if (!ctx->yank[0])
        return -1;

    if (ctx->yank_len + ctx->len >= MAX_STR_SIZE)
        return -1;

    wmemmove(&ctx->line[ctx->pos + ctx->yank_len], &ctx->line[ctx->pos], ctx->len - ctx->pos);
    wmemcpy(&ctx->line[ctx->pos], ctx->yank, ctx->yank_len);

    ctx->pos += ctx->yank_len;
    ctx->len += ctx->yank_len;
    ctx->line[ctx->len] = L'\0';
    return 0;
}
Example #26
0
/* Deletes the line from beginning to pos and puts discarded portion in yank buffer.
   Return 0 on success, -1 if noting to discard. */
int discard_buf(ChatContext *ctx)
{
    if (ctx->pos <= 0)
        return -1;

    ctx->yank_len = ctx->pos;
    wmemcpy(ctx->yank, ctx->line, ctx->yank_len);
    ctx->yank[ctx->yank_len] = L'\0';

    wmemmove(ctx->line, &ctx->line[ctx->pos], ctx->len - ctx->pos);
    ctx->len -= ctx->pos;
    ctx->pos = 0;
    ctx->start = 0;
    ctx->line[ctx->len] = L'\0';

    return 0;
}
Example #27
0
static wchar_t * WINAPI InsertCustomQuote(wchar_t *Str,wchar_t QuoteChar)
{
	size_t l = StrLength(Str);

	if (*Str != QuoteChar)
	{
		wmemmove(Str+1,Str,++l);
		*Str=QuoteChar;
	}

	if (l==1 || Str[l-1] != QuoteChar)
	{
		Str[l++] = QuoteChar;
		Str[l] = 0;
	}

	return Str;
}
extern "C" errno_t __cdecl wmemmove_s(
    wchar_t*       const destination,
    size_t         const size_in_elements,
    wchar_t const* const source,
    size_t         const count
    )
{
    if (count == 0)
        return 0;

#pragma warning(suppress:__WARNING_HIGH_PRIORITY_OVERFLOW_POSTCONDITION)
    _VALIDATE_RETURN_ERRCODE(destination != nullptr, EINVAL);
    _VALIDATE_RETURN_ERRCODE(source != nullptr, EINVAL);
    _VALIDATE_RETURN_ERRCODE(size_in_elements >= count, ERANGE);

#pragma warning(suppress:__WARNING_BANNED_API_USAGEL2 __WARNING_BUFFER_COPY_NO_KNOWN_SIZEEXPR) /* 28726 22104 */
    wmemmove(destination, source, count);
    return 0;
}
Example #29
0
wchar_t* WINAPI TruncPathStr(wchar_t *Str, int MaxLength)
{
	assert(MaxLength >= 0);

	MaxLength=Max(0, MaxLength);

	if (Str)
	{
		int nLength = (int)wcslen(Str);

		if ((MaxLength > 0) && (nLength > MaxLength) && (nLength >= 2))
		{
			wchar_t *lpStart = nullptr;

			if (*Str && (Str[1] == L':') && IsSlash(Str[2]))
				lpStart = Str+3;
			else
			{
				if ((Str[0] == L'\\') && (Str[1] == L'\\'))
				{
					if ((lpStart = const_cast<wchar_t*>(FirstSlash(Str+2))) )
					{
						wchar_t *lpStart2=lpStart;

						if ((lpStart-Str < nLength) && ((lpStart=const_cast<wchar_t*>(FirstSlash(lpStart2+1)))))
							lpStart++;
					}
				}
			}

			if (!lpStart || (lpStart-Str > MaxLength-5))
				return TruncStr(Str, MaxLength);

			wchar_t *lpInPos = lpStart+3+(nLength-MaxLength);
			wmemmove(lpStart+3, lpInPos, (wcslen(lpInPos)+1));
			wmemcpy(lpStart, L"...", 3);
		}
	}

	return Str;
}
Example #30
0
/**
 * Key backspace.
 */
static void
case_key_backspace(volatile struct readline_session_context *ctx)
{
    struct current_cursor_pos yx;

    if (ctx->bufpos == 0) {
	term_beep();
	return;
    }

    if (loLim_isset(ctx->act, ctx->prompt_size)) {
	magic_swap_panels(ctx, false);
    }

    if (ctx->insert_mode) {
	wchar_t *ptr = &ctx->buffer[ctx->bufpos--];

	(void) wmemmove(ptr - 1, ptr, wcslen(ptr));
	ctx->buffer[--ctx->n_insert] = 0L;
	yx = term_get_pos(ctx->act);

	if (wmove(ctx->act, yx.cury, yx.curx - 1) == ERR ||
	    wdelch(ctx->act) == ERR || wclrtoeol(ctx->act) == ERR) {
	    readline_error(EPERM, "wmove, wdelch or wclrtoeol");
	}

	readline_winsnstr(ctx->act, &ctx->buffer[ctx->bufpos], -1);
    } else { /* not insert_mode */
	ctx->buffer[--ctx->bufpos] = 0L;
	ctx->n_insert--;
	yx = term_get_pos(ctx->act);

	if (wmove(ctx->act, yx.cury, yx.curx - 1) == ERR ||
	    wdelch(ctx->act) == ERR) {
	    readline_error(EPERM, "wmove or wdelch");
	}
    }

    update_panels();
    (void) doupdate();
}