Skip to content

Commit

Permalink
fix: syntax highlighting, cleanup: use namespace std by default
Browse files Browse the repository at this point in the history
There was a regression from b90c309
  • Loading branch information
ikozyris committed Nov 12, 2024
1 parent 9f7fa1e commit 96db7ba
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 23 deletions.
10 changes: 5 additions & 5 deletions headers/gapbuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void resize(gap_buf &a, unsigned size)
void mv_curs(gap_buf &a, unsigned pos)
{
if (a.gps == a.gpe) [[unlikely]]
resize(a, std::__bit_ceil(a.cpt));
resize(a, __bit_ceil(a.cpt));
if (pos > a.gps) // move gap to right
memmove(a.buffer + a.gps, a.buffer + a.gpe + 1, pos - a.gps);
else if (pos < a.gps) // move gap to left
Expand All @@ -78,7 +78,7 @@ void mv_curs(gap_buf &a, unsigned pos)
void insert_c(gap_buf &a, unsigned pos, char ch)
{
if (a.len == a.cpt) [[unlikely]]
resize(a, std::__bit_ceil(a.cpt));
resize(a, __bit_ceil(a.cpt));
if (ingap(a, pos)) { [[likely]]
a[pos] = ch;
++a.gps;
Expand All @@ -93,7 +93,7 @@ void insert_s(gap_buf &a, unsigned pos, const char *str, unsigned len)
{
// is this uneeded? (later it is also checked indirectly)
if (a.len + len >= a.cpt) [[unlikely]]
resize(a, std::__bit_ceil(a.len + len + 2));
resize(a, __bit_ceil(a.len + len + 2));
if (gaplen(a) <= len)
mv_curs(a, pos);
memcpy(a.buffer + pos, str, len);
Expand All @@ -104,7 +104,7 @@ void insert_s(gap_buf &a, unsigned pos, const char *str, unsigned len)
void apnd_c(gap_buf &a, char ch)
{
if (a.len >= a.cpt) [[unlikely]]
resize(a, std::__bit_ceil(a.cpt));
resize(a, __bit_ceil(a.cpt));
a[a.len] = ch;
++a.len;
++a.gps;
Expand All @@ -113,7 +113,7 @@ void apnd_c(gap_buf &a, char ch)
void apnd_s(gap_buf &a, const char *str, unsigned size)
{
if (a.len + size >= a.cpt) [[unlikely]]
resize(a, std::__bit_ceil(a.len + size + 2));
resize(a, __bit_ceil(a.len + size + 2));
memcpy(a.buffer + a.len, str, size);
a.len += size;
a.gps = a.len;
Expand Down
1 change: 1 addition & 0 deletions headers/headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
#include <deque>
#include <bit>
#include "funcdecl.h"
using namespace std;
6 changes: 3 additions & 3 deletions headers/vars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#endif
unsigned txt_cpt = DEFAULT_LINES; // alloc'ed nodes

std::list<gap_buf> text(DEFAULT_LINES);
std::list<gap_buf>::iterator it;
list<gap_buf> text(DEFAULT_LINES);
list<gap_buf>::iterator it;

// displayed characters of previous wrap (or cut|slice of line)
#define dchar first
// bytes printed in current wrap
#define byte second
std::deque<std::pair<unsigned, unsigned>> wrap;
deque<pair<unsigned, unsigned>> wrap;

WINDOW *header_win, *ln_win, *text_win;
wchar_t s[4];
Expand Down
6 changes: 3 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ int main(int argc, char *argv[])
} else
mvwdelch(text_win, y, x - 1);
} else if (y != 0) { // x = 0; merge lines
std::list<gap_buf>::iterator curln = it;
list<gap_buf>::iterator curln = it;
--it;
mv_curs(*it, it->len); // delete \n
it->gpe = it->cpt - 1;
Expand All @@ -162,7 +162,7 @@ int main(int argc, char *argv[])
if (rx + 1u > it->len)
break;
if (it->buffer[it->gpe + 1u] == '\n') { // similar to backspace
std::list<gap_buf>::iterator curln = it; // current line
list<gap_buf>::iterator curln = it; // current line
curln->gpe = curln->cpt - 1; // delete newline
curln->len--;
++it; // next line
Expand Down Expand Up @@ -208,7 +208,7 @@ int main(int argc, char *argv[])
else if (ch == SWITCH) { // switch file
argc = 2;
argv[1] = input_header("File to open: ");
std::list<gap_buf>::iterator iter;
list<gap_buf>::iterator iter;
unsigned i;
for (iter = text.begin(), i = 0; iter != text.end() && i <= curnum; ++iter, ++i) {
iter->len = iter->gps = 0;
Expand Down
2 changes: 1 addition & 1 deletion utils/highlight.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "init.c"

#define highlight {if (HIGHLIGHT) apply(y);}
#define highlight(y) {if (HIGHLIGHT) apply(y);}
bool eligible;

bool isc(const char *str)
Expand Down
12 changes: 6 additions & 6 deletions utils/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ unsigned print_line(const gap_buf &buffer, unsigned from = 0, unsigned to = 0)

void print_text(unsigned line)
{
std::list<gap_buf>::iterator iter = text.begin();
std::advance(iter, ofy + line);
list<gap_buf>::iterator iter = text.begin();
advance(iter, ofy + line);
wmove(text_win, line, 0);
wclrtobot(text_win);
wmove(text_win, line, 0);
for (unsigned ty = line; ty < min(curnum + ofy + 1, maxy) && iter != text.end(); ++iter) {
mvprint_line(ty++, 0, *iter, 0, 0);
highlight;
for (unsigned ty = line; ty < min(curnum + ofy + 1, maxy) && iter != text.end(); ++iter, ++ty) {
mvprint_line(ty, 0, *iter, 0, 0);
highlight(ty);
}
}

Expand All @@ -82,7 +82,7 @@ void save()
filename = (char*)input_header("Enter filename: ");
FILE *fo = fopen(filename, "w");
unsigned i;
std::list<gap_buf>::iterator iter;
list<gap_buf>::iterator iter;
for (iter = text.begin(), i = 0; iter != text.end() && i <= curnum; ++iter, ++i) {
data(*iter, 0, iter->len);
fputs(lnbuf, fo);
Expand Down
10 changes: 5 additions & 5 deletions utils/key_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void command()
print_lines();
wrefresh(ln_win);
print_text(0);
std::advance(it, ofy - ry);
advance(it, ofy - ry);
}
} else
print2header("command not found", 3);
Expand Down Expand Up @@ -168,7 +168,7 @@ void sol()
if (!wrap.empty()) { // line has been wrapped
clearline;
print_line(*it);
highlight;
highlight(y);
}
wrap.clear();
wmove(text_win, y, ofx = 0);
Expand All @@ -182,7 +182,7 @@ void scrolldown()
mvwprintw(ln_win, maxy - 1, 0, "%3u", ry + 2);
wrefresh(ln_win);
mvprint_line(y, 0, *it, 0, 0);
highlight;
highlight(y);
wmove(text_win, y, 0);
wrap.clear();
ofx = 0;
Expand All @@ -196,7 +196,7 @@ void scrollup()
--ofy;
--it;
mvprint_line(0, 0, *it, 0, 0);
highlight;
highlight(y);
wmove(text_win, 0, x);
wrefresh(ln_win);
wrap.clear();
Expand All @@ -210,7 +210,7 @@ void left()
ofx -= wrap.back().dchar;
wrap.pop_back();
print_line(*it, wrap.empty() ? 0 : wrap.back().byte);
highlight;
highlight(y);
wmove(text_win, y, flag + 1);
} else if (x > 0) {
wmove(text_win, y, x - 1);
Expand Down

0 comments on commit 96db7ba

Please sign in to comment.