Make posix line mode the default always.
This commit is contained in:
@@ -24,9 +24,9 @@ struct Shard {
|
|||||||
static void retain(Shard *n);
|
static void retain(Shard *n);
|
||||||
static void release(Shard *n);
|
static void release(Shard *n);
|
||||||
|
|
||||||
static Shard *from_file(const std::filesystem::path &path, bool posix_ending);
|
static Shard *from_file(const std::filesystem::path &path);
|
||||||
static Shard *from_string(const char *data, uint64_t len, bool posix_ending);
|
static Shard *from_string(const char *data, uint64_t len);
|
||||||
static Shard *from_command(const char *cmd, bool posix_ending);
|
static Shard *from_command(const char *cmd);
|
||||||
|
|
||||||
static std::pair<Shard *, Shard *> split(Shard *n, uint64_t offset);
|
static std::pair<Shard *, Shard *> split(Shard *n, uint64_t offset);
|
||||||
static Shard *concat(Shard *a, Shard *b);
|
static Shard *concat(Shard *a, Shard *b);
|
||||||
|
|||||||
@@ -11,14 +11,14 @@ bool ClipBuffer::waste() {
|
|||||||
void ClipBuffer::saved_hook() {}
|
void ClipBuffer::saved_hook() {}
|
||||||
|
|
||||||
uint64_t ClipBuffer::lines() {
|
uint64_t ClipBuffer::lines() {
|
||||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||||
uint64_t lines = s ? s->lines + 1 : 0;
|
uint64_t lines = s ? s->lines + 1 : 0;
|
||||||
vase::Shard::release(s);
|
vase::Shard::release(s);
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ClipBuffer::bytes() {
|
uint64_t ClipBuffer::bytes() {
|
||||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||||
uint64_t length = s ? s->length + 1 : 0;
|
uint64_t length = s ? s->length + 1 : 0;
|
||||||
vase::Shard::release(s);
|
vase::Shard::release(s);
|
||||||
return length;
|
return length;
|
||||||
@@ -57,7 +57,7 @@ void ClipBuffer::append(BEd &ctx, vase::Shard *text, uint64_t line) {
|
|||||||
ctx.prev().buffername = name;
|
ctx.prev().buffername = name;
|
||||||
ctx.prev().start = line + 1;
|
ctx.prev().start = line + 1;
|
||||||
ctx.prev().end = line + (text ? text->lines + 1 : 0);
|
ctx.prev().end = line + (text ? text->lines + 1 : 0);
|
||||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||||
s = vase::insert(&ctx.append, s, text, line);
|
s = vase::insert(&ctx.append, s, text, line);
|
||||||
clip_write(s);
|
clip_write(s);
|
||||||
vase::Shard::release(s);
|
vase::Shard::release(s);
|
||||||
@@ -65,7 +65,7 @@ void ClipBuffer::append(BEd &ctx, vase::Shard *text, uint64_t line) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ClipBuffer::remove(BEd &ctx, uint64_t start_line, uint64_t end_line) {
|
void ClipBuffer::remove(BEd &ctx, uint64_t start_line, uint64_t end_line) {
|
||||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||||
s = vase::erase(s, start_line, end_line);
|
s = vase::erase(s, start_line, end_line);
|
||||||
clip_write(s);
|
clip_write(s);
|
||||||
ctx.prev().buffername = name;
|
ctx.prev().buffername = name;
|
||||||
@@ -85,7 +85,7 @@ void ClipBuffer::replace(BEd &ctx, vase::Shard *text, uint64_t start_line, uint6
|
|||||||
ctx.prev().end = start_line + text->lines;
|
ctx.prev().end = start_line + text->lines;
|
||||||
uint64_t new_count = text->lines + 1;
|
uint64_t new_count = text->lines + 1;
|
||||||
uint64_t old_count = end_line - start_line + 1;
|
uint64_t old_count = end_line - start_line + 1;
|
||||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||||
s = vase::replace(s, text, start_line, end_line);
|
s = vase::replace(s, text, start_line, end_line);
|
||||||
clip_write(s);
|
clip_write(s);
|
||||||
vase::Shard::release(s);
|
vase::Shard::release(s);
|
||||||
@@ -99,7 +99,7 @@ void ClipBuffer::replace(BEd &ctx, vase::Shard *text, uint64_t start_line, uint6
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ClipBuffer::join(BEd &ctx, uint64_t start_line, uint64_t end_line) {
|
void ClipBuffer::join(BEd &ctx, uint64_t start_line, uint64_t end_line) {
|
||||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||||
s = vase::join(s, start_line, end_line);
|
s = vase::join(s, start_line, end_line);
|
||||||
clip_write(s);
|
clip_write(s);
|
||||||
vase::Shard::release(s);
|
vase::Shard::release(s);
|
||||||
@@ -116,7 +116,7 @@ void ClipBuffer::substitute(
|
|||||||
ctx.prev().buffername = name;
|
ctx.prev().buffername = name;
|
||||||
ctx.prev().start = start_line;
|
ctx.prev().start = start_line;
|
||||||
ctx.prev().end = end_line;
|
ctx.prev().end = end_line;
|
||||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||||
s = vase::substitute(
|
s = vase::substitute(
|
||||||
&ctx.append,
|
&ctx.append,
|
||||||
s,
|
s,
|
||||||
@@ -138,21 +138,21 @@ void ClipBuffer::substitute(
|
|||||||
}
|
}
|
||||||
|
|
||||||
vase::Shard *ClipBuffer::copy(uint64_t start_line, uint64_t end_line) {
|
vase::Shard *ClipBuffer::copy(uint64_t start_line, uint64_t end_line) {
|
||||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||||
vase::Shard *o = vase::copy(s, start_line, end_line);
|
vase::Shard *o = vase::copy(s, start_line, end_line);
|
||||||
vase::Shard::release(s);
|
vase::Shard::release(s);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ClipBuffer::find_next(std::string_view pattern, uint64_t start) {
|
uint64_t ClipBuffer::find_next(std::string_view pattern, uint64_t start) {
|
||||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||||
uint64_t line = vase::find_next(s, pattern, start);
|
uint64_t line = vase::find_next(s, pattern, start);
|
||||||
vase::Shard::release(s);
|
vase::Shard::release(s);
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ClipBuffer::find_prev(std::string_view pattern, uint64_t start) {
|
uint64_t ClipBuffer::find_prev(std::string_view pattern, uint64_t start) {
|
||||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||||
uint64_t line = vase::find_prev(s, pattern, start);
|
uint64_t line = vase::find_prev(s, pattern, start);
|
||||||
vase::Shard::release(s);
|
vase::Shard::release(s);
|
||||||
return line;
|
return line;
|
||||||
@@ -176,7 +176,7 @@ void ClipBuffer::print(BEd &ctx, uint64_t start_line, uint64_t end_line) {
|
|||||||
ctx.prev().buffername = name;
|
ctx.prev().buffername = name;
|
||||||
ctx.prev().start = start_line;
|
ctx.prev().start = start_line;
|
||||||
ctx.prev().end = end_line;
|
ctx.prev().end = end_line;
|
||||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||||
vase::Iterator it(s, start_line - 1, Direction::Forward);
|
vase::Iterator it(s, start_line - 1, Direction::Forward);
|
||||||
while (it.next() && start_line++ <= end_line)
|
while (it.next() && start_line++ <= end_line)
|
||||||
ctx.io.write_line(it.line);
|
ctx.io.write_line(it.line);
|
||||||
@@ -190,7 +190,7 @@ void ClipBuffer::number_print(BEd &ctx, uint64_t start_line, uint64_t end_line)
|
|||||||
uint8_t width = 1;
|
uint8_t width = 1;
|
||||||
for (uint64_t n = end_line; n >= 10; n /= 10)
|
for (uint64_t n = end_line; n >= 10; n /= 10)
|
||||||
++width;
|
++width;
|
||||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||||
vase::Iterator it(s, start_line - 1, Direction::Forward);
|
vase::Iterator it(s, start_line - 1, Direction::Forward);
|
||||||
while (it.next() && start_line <= end_line)
|
while (it.next() && start_line <= end_line)
|
||||||
ctx.io.write_line(std::format("{:>{}}\t{}", start_line++, width, it.line));
|
ctx.io.write_line(std::format("{:>{}}\t{}", start_line++, width, it.line));
|
||||||
@@ -201,7 +201,7 @@ void ClipBuffer::list_print(BEd &ctx, uint64_t start_line, uint64_t end_line) {
|
|||||||
ctx.prev().buffername = name;
|
ctx.prev().buffername = name;
|
||||||
ctx.prev().start = start_line;
|
ctx.prev().start = start_line;
|
||||||
ctx.prev().end = end_line;
|
ctx.prev().end = end_line;
|
||||||
auto s = vase::Shard::from_command("xclip -selection clipboard -o", true);
|
auto s = vase::Shard::from_command("xclip -selection clipboard -o");
|
||||||
vase::Iterator it(s, start_line - 1, Direction::Forward);
|
vase::Iterator it(s, start_line - 1, Direction::Forward);
|
||||||
while (it.next() && start_line++ <= end_line)
|
while (it.next() && start_line++ <= end_line)
|
||||||
ctx.io.write_line(list_string(it.line));
|
ctx.io.write_line(list_string(it.line));
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ void Function::register_extented(BEd &ctx) {
|
|||||||
ctx.io.write("=> ", 3);
|
ctx.io.write("=> ", 3);
|
||||||
auto parser = syntax::MiniParser(
|
auto parser = syntax::MiniParser(
|
||||||
*ctx.languages["ruby"],
|
*ctx.languages["ruby"],
|
||||||
vase::Shard::from_string(line.data(), line.size(), true),
|
vase::Shard::from_string(line.data(), line.size()),
|
||||||
nullptr
|
nullptr
|
||||||
);
|
);
|
||||||
const auto &tokens = parser.lines[0].second;
|
const auto &tokens = parser.lines[0].second;
|
||||||
|
|||||||
@@ -144,17 +144,17 @@ void Function::register_posix(BEd &ctx) {
|
|||||||
vase::Shard *s = nullptr;
|
vase::Shard *s = nullptr;
|
||||||
if (std::holds_alternative<std::filesystem::path>(arg)) {
|
if (std::holds_alternative<std::filesystem::path>(arg)) {
|
||||||
auto path = std::get<std::filesystem::path>(arg);
|
auto path = std::get<std::filesystem::path>(arg);
|
||||||
s = vase::Shard::from_file(path, true);
|
s = vase::Shard::from_file(path);
|
||||||
buf.set_filename(path);
|
buf.set_filename(path);
|
||||||
} else if (std::holds_alternative<ShellArg>(arg)) {
|
} else if (std::holds_alternative<ShellArg>(arg)) {
|
||||||
auto cmd = std::get<ShellArg>(arg).cmd;
|
auto cmd = std::get<ShellArg>(arg).cmd;
|
||||||
ctx.escape_command(cmd, buf.filename().string());
|
ctx.escape_command(cmd, buf.filename().string());
|
||||||
s = vase::Shard::from_command(cmd.c_str(), true);
|
s = vase::Shard::from_command(cmd.c_str());
|
||||||
} else {
|
} else {
|
||||||
auto path = buf.filename();
|
auto path = buf.filename();
|
||||||
if (path.empty())
|
if (path.empty())
|
||||||
throw ed_error("Need filename.");
|
throw ed_error("Need filename.");
|
||||||
s = vase::Shard::from_file(path, true);
|
s = vase::Shard::from_file(path);
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
buf.load(ctx, s);
|
buf.load(ctx, s);
|
||||||
@@ -190,17 +190,17 @@ void Function::register_posix(BEd &ctx) {
|
|||||||
vase::Shard *s = nullptr;
|
vase::Shard *s = nullptr;
|
||||||
if (std::holds_alternative<std::filesystem::path>(arg)) {
|
if (std::holds_alternative<std::filesystem::path>(arg)) {
|
||||||
auto path = std::get<std::filesystem::path>(arg);
|
auto path = std::get<std::filesystem::path>(arg);
|
||||||
s = vase::Shard::from_file(path, true);
|
s = vase::Shard::from_file(path);
|
||||||
buf.set_filename(path);
|
buf.set_filename(path);
|
||||||
} else if (std::holds_alternative<ShellArg>(arg)) {
|
} else if (std::holds_alternative<ShellArg>(arg)) {
|
||||||
auto cmd = std::get<ShellArg>(arg).cmd;
|
auto cmd = std::get<ShellArg>(arg).cmd;
|
||||||
ctx.escape_command(cmd, buf.filename().string());
|
ctx.escape_command(cmd, buf.filename().string());
|
||||||
s = vase::Shard::from_command(cmd.c_str(), true);
|
s = vase::Shard::from_command(cmd.c_str());
|
||||||
} else {
|
} else {
|
||||||
auto path = buf.filename();
|
auto path = buf.filename();
|
||||||
if (path.empty())
|
if (path.empty())
|
||||||
throw ed_error("Need filename.");
|
throw ed_error("Need filename.");
|
||||||
s = vase::Shard::from_file(path, true);
|
s = vase::Shard::from_file(path);
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
buf.load(ctx, s);
|
buf.load(ctx, s);
|
||||||
@@ -588,18 +588,18 @@ void Function::register_posix(BEd &ctx) {
|
|||||||
vase::Shard *s = nullptr;
|
vase::Shard *s = nullptr;
|
||||||
if (std::holds_alternative<std::filesystem::path>(arg)) {
|
if (std::holds_alternative<std::filesystem::path>(arg)) {
|
||||||
auto path = std::get<std::filesystem::path>(arg);
|
auto path = std::get<std::filesystem::path>(arg);
|
||||||
s = vase::Shard::from_file(path, true);
|
s = vase::Shard::from_file(path);
|
||||||
if (buf.filename().empty())
|
if (buf.filename().empty())
|
||||||
buf.set_filename(path);
|
buf.set_filename(path);
|
||||||
} else if (std::holds_alternative<ShellArg>(arg)) {
|
} else if (std::holds_alternative<ShellArg>(arg)) {
|
||||||
auto cmd = std::get<ShellArg>(arg).cmd;
|
auto cmd = std::get<ShellArg>(arg).cmd;
|
||||||
ctx.escape_command(cmd, buf.filename().string());
|
ctx.escape_command(cmd, buf.filename().string());
|
||||||
s = vase::Shard::from_command(cmd.c_str(), true);
|
s = vase::Shard::from_command(cmd.c_str());
|
||||||
} else {
|
} else {
|
||||||
auto path = buf.filename();
|
auto path = buf.filename();
|
||||||
if (path.empty())
|
if (path.empty())
|
||||||
throw ed_error("Need filename.");
|
throw ed_error("Need filename.");
|
||||||
s = vase::Shard::from_file(path, true);
|
s = vase::Shard::from_file(path);
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
buf.append(ctx, s, addr.number);
|
buf.append(ctx, s, addr.number);
|
||||||
|
|||||||
+20
-22
@@ -202,7 +202,7 @@ Shard *Shard::build(Shard **pieces, uint64_t lo, uint64_t hi) {
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shard *Shard::from_command(const char *cmd, bool posix_ending) {
|
Shard *Shard::from_command(const char *cmd) {
|
||||||
auto o = new OriginalStorage("/tmp");
|
auto o = new OriginalStorage("/tmp");
|
||||||
int dest_fd = o->fd;
|
int dest_fd = o->fd;
|
||||||
if (dest_fd == -1) {
|
if (dest_fd == -1) {
|
||||||
@@ -278,23 +278,21 @@ Shard *Shard::from_command(const char *cmd, bool posix_ending) {
|
|||||||
io::IO::enable_raw();
|
io::IO::enable_raw();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (posix_ending) {
|
if (ending[1] == '\n') {
|
||||||
if (ending[1] == '\n') {
|
Petal *last = (Petal *)pieces.back();
|
||||||
Petal *last = (Petal *)pieces.back();
|
last->lines--;
|
||||||
last->lines--;
|
last->length--;
|
||||||
last->length--;
|
if (last->length == 0) {
|
||||||
if (last->length == 0) {
|
Shard::release(last);
|
||||||
Shard::release(last);
|
pieces.pop_back();
|
||||||
pieces.pop_back();
|
last = nullptr;
|
||||||
last = nullptr;
|
if (!pieces.empty())
|
||||||
if (!pieces.empty())
|
last = (Petal *)pieces.back();
|
||||||
last = (Petal *)pieces.back();
|
else
|
||||||
else
|
return nullptr;
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
if (last && ending[0] == '\r')
|
|
||||||
last->length--;
|
|
||||||
}
|
}
|
||||||
|
if (last && ending[0] == '\r')
|
||||||
|
last->length--;
|
||||||
}
|
}
|
||||||
o->initialize();
|
o->initialize();
|
||||||
io::IO::enable_raw();
|
io::IO::enable_raw();
|
||||||
@@ -303,7 +301,7 @@ Shard *Shard::from_command(const char *cmd, bool posix_ending) {
|
|||||||
return build(pieces.data(), 0, pieces.size());
|
return build(pieces.data(), 0, pieces.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
Shard *Shard::from_file(const std::filesystem::path &path, bool posix_ending) {
|
Shard *Shard::from_file(const std::filesystem::path &path) {
|
||||||
auto o = new OriginalStorage("/tmp");
|
auto o = new OriginalStorage("/tmp");
|
||||||
int dest_fd = o->fd;
|
int dest_fd = o->fd;
|
||||||
if (dest_fd == -1) {
|
if (dest_fd == -1) {
|
||||||
@@ -313,10 +311,10 @@ Shard *Shard::from_file(const std::filesystem::path &path, bool posix_ending) {
|
|||||||
int src_fd = open(path.c_str(), O_RDONLY);
|
int src_fd = open(path.c_str(), O_RDONLY);
|
||||||
if (src_fd == -1) {
|
if (src_fd == -1) {
|
||||||
delete o;
|
delete o;
|
||||||
return nullptr;
|
throw ed_error("Couldn't open file.");
|
||||||
}
|
}
|
||||||
uint64_t total = std::filesystem::file_size(path);
|
uint64_t total = std::filesystem::file_size(path);
|
||||||
if (posix_ending && total > 0) {
|
if (total > 0) {
|
||||||
char last;
|
char last;
|
||||||
if (pread(src_fd, &last, 1, (off_t)(total - 1)) != 1) {
|
if (pread(src_fd, &last, 1, (off_t)(total - 1)) != 1) {
|
||||||
delete o;
|
delete o;
|
||||||
@@ -381,7 +379,7 @@ Shard *Shard::from_file(const std::filesystem::path &path, bool posix_ending) {
|
|||||||
return build(pieces.data(), 0, pieces.size());
|
return build(pieces.data(), 0, pieces.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
Shard *Shard::from_string(const char *data, uint64_t len, bool posix_ending) {
|
Shard *Shard::from_string(const char *data, uint64_t len) {
|
||||||
auto o = new OriginalStorage("/tmp");
|
auto o = new OriginalStorage("/tmp");
|
||||||
int dest_fd = o->fd;
|
int dest_fd = o->fd;
|
||||||
if (dest_fd == -1 || data == nullptr) {
|
if (dest_fd == -1 || data == nullptr) {
|
||||||
@@ -389,7 +387,7 @@ Shard *Shard::from_string(const char *data, uint64_t len, bool posix_ending) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
uint64_t total = len;
|
uint64_t total = len;
|
||||||
if (posix_ending && total > 0) {
|
if (total > 0) {
|
||||||
if (data[total - 1] == '\n') {
|
if (data[total - 1] == '\n') {
|
||||||
total--;
|
total--;
|
||||||
if (total > 0 && data[total - 1] == '\r')
|
if (total > 0 && data[total - 1] == '\r')
|
||||||
|
|||||||
Reference in New Issue
Block a user