40
40
int ELine::Allocate(size_t Bytes) {
41
return ((Chars = (char*)realloc(Chars, Bytes | CHAR_TRESHOLD)) != NULL) ? 1 : 0;
41
Chars = (char*)realloc(Chars, Bytes | CHAR_TRESHOLD);
42
return (Chars != NULL);
44
45
int EBuffer::ScreenPos(ELine *L, int Offset) {
45
46
int ExpandTabs = BFI(this, BFI_ExpandTabs);
46
47
int TabSize = BFI(this, BFI_TabSize);
61
Pos = NextTab(Pos, TabSize);
64
Pos += Ofs - L->Count;
70
Pos = NextTab(Pos, TabSize);
62
Pos = NextTab(Pos, TabSize);
65
Pos += Ofs - L->Count;
71
Pos = NextTab(Pos, TabSize);
78
78
int EBuffer::CharOffset(ELine *L, int ScreenPos) {
79
79
int ExpandTabs = BFI(this, BFI_ExpandTabs);
80
80
int TabSize = BFI(this, BFI_TabSize);
94
Pos = NextTab(Pos, TabSize);
100
return Ofs + ScreenPos - Pos;
94
Pos = NextTab(Pos, TabSize);
101
return Ofs + ScreenPos - Pos;
104
104
int EBuffer::Allocate(int ACount) {
107
if (ACount > 1024 * 1024) // FIXME: - let's crash, before OOOM kills us
107
if (ACount > 10 * 1024 * 1024) // FIXME: - let's crash, before OOOM kills us
110
110
L = (PELine *) realloc(LL, sizeof(PELine) * (ACount + 1));
111
if (L == 0 && ACount != 0)
111
if (!L && ACount != 0)
113
113
RAllocated = ACount;
118
119
int EBuffer::MoveRGap(int RPos) {
119
120
int GapSize = RAllocated - RCount;
121
if (RGap == RPos) return 1;
122
if (RPos < 0 || RPos > RCount) return 0;
124
if (RPos < 0 || RPos > RCount)
124
127
if (RGap < RPos) {
125
if (RPos - RGap == 1) {
128
if (RPos - RGap == 1)
126
129
LL[RGap] = LL[RGap + GapSize];
128
131
memmove(LL + RGap,
129
132
LL + RGap + GapSize,
130
133
sizeof(PELine) * (RPos - RGap));
133
if (RGap - RPos == 1) {
135
if (RGap - RPos == 1)
134
136
LL[RPos + GapSize] = LL[RPos];
136
138
memmove(LL + RPos + GapSize,
138
140
sizeof(PELine) * (RGap - RPos));
145
147
int EBuffer::AllocVis(int ACount) {
148
V = (int *) realloc(VV, sizeof(int) * (ACount + 1));
149
if (V == 0 && ACount != 0) return 0;
148
int *V = (int *) realloc(VV, sizeof(int) * (ACount + 1));
149
if (!V && ACount != 0)
150
151
VAllocated = ACount;
155
157
int EBuffer::MoveVGap(int VPos) {
156
158
int GapSize = VAllocated - VCount;
158
160
if (VGap == VPos) return 1;
159
161
if (VPos < 0 || VPos > VCount) return 0;
161
163
if (VGap < VPos) {
162
if (VPos - VGap == 1) {
164
if (VPos - VGap == 1)
163
165
VV[VGap] = VV[VGap + GapSize];
165
167
memmove(VV + VGap,
166
168
VV + VGap + GapSize,
167
169
sizeof(VV[0]) * (VPos - VGap));
170
171
if (VGap - VPos == 1) {
171
172
VV[VPos + GapSize] = VV[VPos];