Skip to content

Commit

Permalink
clean up, remove unused function
Browse files Browse the repository at this point in the history
  • Loading branch information
ikozyris committed Jul 15, 2024
1 parent 7e416f0 commit 07d01dd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 25 deletions.
2 changes: 1 addition & 1 deletion headers/gapbuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ unsigned data(const gap_buf &src, unsigned from, unsigned to)
lnbuf[to - from] = 0;
lnbuf[to - from + 1] = 0;
// try some special cases where 1 copy is required
if (src.gps == src.len && src.gpe == src.cpt) // gap ends at end so don't bother
if (src.gps == src.len && src.gpe == src.cpt) // gap ends at end
memcpy(lnbuf, src.buffer + from, min(to, src.gps));
else if (src.gps == 0) // x = 0; gap at start
memcpy(lnbuf, src.buffer + from + src.gpe + 1, min(to, src.len) - from);
Expand Down
6 changes: 3 additions & 3 deletions headers/vars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ std::list<gap_buf>::iterator it;
WINDOW *header_win, *ln_win, *text_win;
wchar_t s[6];
char s2[6];
unsigned char y, x, rx, len;
// offset in y axis of text and screen
unsigned char y, x, len;
// offset in y axis of text and screen, x axis equivalents are in gapbuffer
long ofy;
unsigned ry;
unsigned ry, rx;
unsigned buf_indx, printed, previndx, ppi;
unsigned maxy, maxx; // to store the maximum rows and columns
int ch;
Expand Down
3 changes: 2 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ int main(int argc, char *argv[])
//goto stop;
while (1) {
getyx(text_win, y, x);
if (x >= min(ry < curnum ? (it->len - 1 - ofx) : (it->len - ofx), maxx)) // if out of bounds: move (to avoid bugs)
// if out of bounds: move (to avoid bugs)
if (x >= min(ry < curnum ? (it->len - 1 - ofx) : (it->len - ofx), maxx))
wmove(text_win, y, min((ry != curnum ? it->len - ofx - 1 : it->len - ofx), maxx));
getyx(text_win, y, x);
ry = y + ofy; // calculate offsets
Expand Down
23 changes: 3 additions & 20 deletions utils/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ long print_line(gap_buf &buffer)
if (buffer.len == 0)
return 0;
unsigned rlen = data(buffer, 0, min(buffer.len, maxx)) - 1;
if (lnbuf[rlen-1] == '\n')
if (lnbuf[rlen - 1] == '\n')
--rlen;
for (unsigned i = 0; i < rlen && getcurx(text_win) < maxx-1; ++i)
for (unsigned i = 0; i < rlen && getcurx(text_win) < maxx - 1; ++i)
waddnstr(text_win, lnbuf + i, 1);
return rlen;
}
Expand Down Expand Up @@ -111,23 +111,6 @@ void read_fgets(FILE *fi)
}
}

inline void ins_b(char ch)
{
it->buffer[it->len++] = ch;
if (it->len >= it->cpt) { [[likely]]
it->cpt *= 2;
it->buffer = (char*)realloc(it->buffer, it->cpt);
} if (ch == '\n') { [[unlikely]]
it->gps = it->len;
it->gpe = it->cpt;
if (++curnum >= txt_cpt) { [[unlikely]]
txt_cpt *= 2;
text.resize(txt_cpt);
}
++it;
}
}

inline long whereis(const char *str, char ch)
{
const char *end = strchr(str, ch);
Expand All @@ -151,7 +134,7 @@ void read_fread(FILE *fi)
unsigned a, j = 0;
long res;
while ((a = fread(tmp, sizeof(tmp[0]), SZ, fi))) {
tmp[a+1] = 0;
tmp[a + 1] = 0;
res = whereis(tmp, '\n');
if (res > 0) { // found newline
while ((res = whereis(tmp + j, '\n')) > -1) {
Expand Down

0 comments on commit 07d01dd

Please sign in to comment.