int EBuffer::BlockUnTab() { EPoint B, E; ELine *L; int O, C; AutoExtend = 0; if (CheckBlock() == 0) return 0; if (RCount <= 0) return 0; B = BB; E = BE; Draw(B.Row, E.Row); for (int i = B.Row; i < E.Row; i++) { L = RLine(i); O = 0; C = 0; while (O < L->Count) { if (L->Chars[O] == '\t') { C = NextTab(C, BFI(this, BFI_TabSize)); if (DelChars(i, O, 1) != 1) return 0; if (InsChars(i, O, C - O, 0) != 1) return 0; O = C; } else { O++; C++; } } } return 1; }
int EBuffer::BlockSort(int Reverse) { int rq; ELine *oldL; if (CheckBlock() == 0) return 0; if (RCount == 0) return 0; SortMinRow = BB.Row; SortMaxRow = BE.Row; if (BlockMode != bmStream || BE.Col == 0) SortMaxRow--; if (SortMinRow >= SortMaxRow) return 1; SortBuffer = this; SortReverse = Reverse; switch (BlockMode) { case bmLine: case bmStream: SortMinCol = -1; SortMaxCol = -1; break; case bmColumn: SortMinCol = BB.Col; SortMaxCol = BE.Col; break; } SortRows = (int *)malloc((SortMaxRow - SortMinRow + 1) * sizeof(int)); if (SortRows == 0) { free(SortRows); return 0; } for (rq = 0; rq <= SortMaxRow - SortMinRow; rq++) SortRows[rq] = rq + SortMinRow; qsort(SortRows, SortMaxRow - SortMinRow + 1, sizeof(int), SortProc); // now change the order of lines according to new order in Rows array. for (rq = 0; rq <= SortMaxRow - SortMinRow; rq++) { oldL = RLine(SortRows[rq]); if (InsLine(1 + rq + SortMaxRow, 0) == 0) return 0; if (InsChars(1 + rq + SortMaxRow, 0, oldL->Count, oldL->Chars) == 0) return 0; } for (rq = 0; rq <= SortMaxRow - SortMinRow; rq++) if (DelLine(SortMinRow) == 0) return 0; free(SortRows); return 1; }
int EBuffer::LineDuplicate() { int Y = VToR(CP.Row); if (InsLine(Y, 1) == 0) return 0; if (InsChars(Y + 1, 0, RLine(Y)->Count, RLine(Y)->Chars) == 0) return 0; return 1; }
int EBuffer::BlockEnTab() { EPoint B, E; ELine *L; int O, C, O1, C1; char tab = '\t'; AutoExtend = 0; if (CheckBlock() == 0) return 0; if (RCount <= 0) return 0; B = BB; E = BE; Draw(B.Row, E.Row); for (int i = B.Row; i < E.Row; i++) { L = RLine(i); O = C = 0; O1 = C1 = 0; while (O < L->Count) { if (L->Chars[O] == '\t') { // see if there are spaces to remove int C2 = NextTab(C, BFI(this, BFI_TabSize)); int N = BFI(this, BFI_TabSize) - (C2 - C); if (O - O1 < N) N = O - O1; if (N > 0) { if (DelChars(i, O - N, N) != 1) return 0; O -= N; C = C2; O++; C1 = C; O1 = O; } else { O++; C = C2; O1 = O; C1 = C; } } else if (L->Chars[O] != ' ') { // nope, cannot put tab here O++; C++; C1 = C; O1 = O; } else if (((C % BFI(this, BFI_TabSize)) == (BFI(this, BFI_TabSize) - 1)) && (C - C1 > 0)) { // reached a tab and can put one int N = BFI(this, BFI_TabSize); if (O - O1 + 1 < N) { N = O - O1 + 1; } else if (O - O1 + 1 > N) { O1 = O - N + 1; } if (DelChars(i, O1, N) != 1) return 0; if (InsChars(i, O1, 1, &tab) != 1) return 0; O1++; O = O1; C++; C1 = C; } else { O++; C++; } } } return 1; }