commit c346bdfcb6d755703f12b1a07be115776144963d
parent 62c1d8a40ede5eb8b33b27c5b488be74ae6ed20a
Author: ssnf <ssnf@ssnf.xyz>
Date: Tue, 19 Oct 2021 16:34:39 +0000
bug fixes
Diffstat:
2 files changed, 22 insertions(+), 24 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -2,7 +2,7 @@
Key keys[] = {
{ 'c', change },
- { 'C', change , 'c' },
+ { 'C', change , '\n' + 0x7f },
{ 'r', change, 'x' },
{ '0', count, 0 },
{ '1', count, 1 },
diff --git a/sim.c b/sim.c
@@ -108,7 +108,7 @@ static void fr_update();
static void fr_zero(Frame*);
static void paste(int arg);
static void search(int arg);
-static int select(int arg);
+static int selection(int arg);
static void str_init(String* p);
static void str_close(String* p);
static void str_zero(String* p);
@@ -260,7 +260,7 @@ change(int arg)
case 't': arg = Till; break;
}
count = counter;
- arg = select(arg);
+ arg = selection(arg);
if (arg == Word || arg == Letter || arg > 0x7f)
++f->dot.p1;
str_init(&s);
@@ -311,7 +311,7 @@ delete(int arg)
}
}
count = counter;
- if ((arg = select(arg)) < 0)
+ if ((arg = selection(arg)) < 0)
return;
str_init(&s);
str_zero(&istr);
@@ -350,7 +350,7 @@ dot(int arg)
case Change:
str_init(&ds);
if (buf->ds[f->i].n) {
- select(arg);
+ selection(arg);
if (arg == Word || arg == Letter || arg > 0x7f)
++f->dot.p1;
str_adds(&ds, f->s->s + f->dot.p0, f->dot.p1 - f->dot.p0);
@@ -407,8 +407,6 @@ input(String* s, ushort line, char* msg)
str_zero(s);
case '\n':
return;
- case '\t':
- continue;
case Del:
str_delc(s);
break;
@@ -438,6 +436,10 @@ insert(int arg)
{
String s, c;
+ if (f->s->s[f->s->n - 1] != '\n') {
+ str_addc(f->s, '\n');
+ move(Right);
+ }
str_init(&s), str_init(&c);
str_addc(&c, '\0');
switch (arg) {
@@ -453,10 +455,6 @@ insert(int arg)
++f->dot.p1;
break;
}
- if (f->s->s[f->s->n - 1] != '\n' && f->dot.p0 >= f->s->n) {
- str_addc(f->s, '\n');
- move(Right);
- }
for (;;) {
win_query(&w);
fr_update();
@@ -569,8 +567,11 @@ file_save(int arg)
if (arg == -1)
arg = f - file;
- if (!file[arg].name->n)
+ if (!file[arg].name->n) {
input(file[arg].name, w.wy/2, "File name: ");
+ if (!file[arg].name->n)
+ return;
+ }
disk = fopen(file[arg].name->s, "w");
fwrite(file[arg].s->s, file[arg].s->n, 1, disk);
fclose(disk);
@@ -785,7 +786,7 @@ static void
search(int arg)
{
Posn pos;
- uchar* p;
+ char* p;
if (arg == '/' || arg == '?') {
str_zero(&srch);
@@ -796,13 +797,11 @@ search(int arg)
}
if (arg == '/' || arg == 'n') {
move(Right);
- p = (uchar*)strstr(f->s->s + f->dot.p0, srch.s);
- if (p == NULL) {
+ p = strstr(f->s->s + f->dot.p0, srch.s);
+ if (p == NULL || p - f->s->s > f->s->n) {
move(Left);
return;
}
- if (srch.s[0] == '\n')
- ++p;
} else {
for (;;) {
pos = f->dot.p1;
@@ -816,13 +815,13 @@ search(int arg)
}
if (srch.s[0] == '\n')
move(Right);
- p = (uchar*)f->s->s + f->dot.p1;
+ p = f->s->s + f->dot.p1;
}
- f->dot.p0 = f->dot.p1 = p - (uchar*)f->s->s;
+ f->dot.p0 = f->dot.p1 = p - f->s->s;
}
static int
-select(int arg)
+selection(int arg)
{
Posn p0;
@@ -870,9 +869,8 @@ select(int arg)
return 0;
till:
p0 = f->dot.p0;
- for (;counter; --counter)
- if (f->dot.p1 + 1 < f->s->n)
- for (++f->dot.p1; f->dot.p1 + 1 < f->s->n && f->s->s[f->dot.p1 + 1] != arg; ++f->dot.p1);
+ for (;counter && f->dot.p1 + 1 < f->s->n; --counter)
+ for (++f->dot.p1; f->dot.p1 + 1 < f->s->n && f->s->s[f->dot.p1 + 1] != arg; ++f->dot.p1);
if (f->s->s[f->dot.p1 + 1] != arg) {
f->dot.p1 = f->dot.p0;
return -1;
@@ -987,7 +985,7 @@ yank(int arg)
return;
}
}
- if ((arg = select(arg)) < 0)
+ if ((arg = selection(arg)) < 0)
return;
str_zero(&istr);
str_adds(&istr, f->s->s + f->dot.p0, f->dot.p1 + 1 - f->dot.p0);