Merge pull request #2212 from unxed/ctrl_yo
[far2l.git] / incsrch / util.c
blobe885b2986ec092be59acb69625a713bd848970a3
1 /*
2 FAR manager incremental search plugin, search as you type in editor.
3 Copyright (C) 1999-2019, Stanislav V. Mekhanoshin
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
18 #include "incsrch.h"
20 #if !defined(WINPORT_DIRECT)
22 #if !defined(__WATCOMC__) && (defined(__386__) || defined(_WIN32) || defined(__NT__))
23 void memmovel(void *dest, void *src, size_t count)
25 _asm {
26 mov edi, dest
27 mov esi, src
28 mov ecx, count
29 cld
30 rep movsb
33 #endif
35 #if !defined(__WATCOMC__) && (defined(__386__) || defined(_WIN32) || defined(__NT__))
36 void zeromem(void *pMem, size_t nLength)
38 _asm {
39 mov edi, pMem
40 mov ecx, nLength
41 cld
42 xor eax, eax
43 rep stosb
46 #endif
48 #ifndef __WATCOMC__
49 size_t utoar(unsigned int nNum, char *sBuff, size_t nBuffLen)
50 // returning index to first byte
52 _asm {
53 mov eax, nNum
54 mov edi, sBuff
55 mov ecx, nBuffLen
56 dec edi
57 mov ebx, 10
59 mov byte ptr [edi][ecx], 0 ; terminating null
60 dec ecx
62 Next: xor edx, edx
63 div ebx
64 add edx, 48 ; to ascii
65 mov byte ptr [edi][ecx], dl
66 dec ecx
67 jz Exit
68 test eax, eax
69 jz Exit
70 jmp short Next
71 Exit: mov eax, ecx
74 #endif
76 #ifndef __WATCOMC__
77 size_t sstrnlen(const char *sString, size_t count)
79 _asm {
80 mov edi, sString
81 mov ecx, count
82 cld
83 mov edx, ecx
84 xor eax, eax
85 repne scasb
86 jnz Len
87 inc ecx
88 Len: sub edx, ecx
89 mov eax, edx
92 #endif
94 BOOL WaitInput(BOOL Infinite)
96 return WaitForSingleObject(hInputHandle, Infinite ? INFINITE : 0) == WAIT_OBJECT_0;
98 #else // WINPORT_DIRECT
99 size_t utoar(unsigned int nNum, TCHAR *sBuff, size_t nBuffLen)
100 // returning index to first byte
102 apiSnprintf(sBuff, nBuffLen, _T("%*ud"), nBuffLen - 1, nNum);
103 sBuff[nBuffLen - 1] = 0;
104 size_t pos = 0;
105 for (; pos < nBuffLen; ++pos)
106 if (sBuff[pos] != _T(' '))
107 break;
108 return pos;
111 size_t lstrnlen(const TCHAR *str, size_t count)
113 size_t i = 0;
114 for (i = 0; i < count; i++)
115 if (!str[i])
116 break;
117 return i;
120 BOOL WaitInput(BOOL Infinite)
122 INPUT_RECORD rec;
123 DWORD ReadCount;
125 do {
126 WINPORT(PeekConsoleInput)(NULL, &rec, 1, &ReadCount);
127 if (Infinite)
128 WINPORT(Sleep(20));
129 } while (Infinite && ReadCount == 0);
131 return ReadCount != 0;
133 #endif // WINPORT_DIRECT