1
0
Fork 0
mirror of https://github.com/vbatts/bvi.git synced 2025-08-02 23:50:28 +00:00

bvi-1.5.0.src.tar.gz

6540716a1a3b2b9711635108da14b26baea488881d4a682121c0bddbba6b74cb  bvi-1.5.0.src.tar.gz

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Gerhard Bürgmann 2025-07-27 10:02:07 -04:00 committed by Vincent Batts
parent 75fc14b579
commit 50898d8d59
Signed by: vbatts
GPG key ID: E30EFAA812C6E5ED
28 changed files with 1936 additions and 1473 deletions

177
edit.c
View file

@ -12,8 +12,9 @@
* 2006-04-05 V 1.3.3 alpha - binary representation
* 2014-09-30 V 1.4.0
* 2019-10-12 V 1.4.1
* 2025-07-19 V 1.5.0
*
* Copyright 1996-2019 by Gerhard Buergmann
* Copyright 1996-2025 by Gerhard Buergmann
* gerhard@puon.at
*
* This program is free software; you can redistribute it and/or modify it
@ -63,8 +64,7 @@ static char *getcnext = NULL;
* characters (for "." command)
*/
off_t
edit(mode)
int mode;
edit(int mode)
{
int ch, ch1;
size_t len;
@ -117,7 +117,7 @@ edit(mode)
setcur();
continue;
}
if (ch == KEY_BACKSPACE
if (ch == KEY_BACKSPACE
|| ch == ASCII_DEL
|| ch == BVICTRL('H')) {
if (count > 0) {
@ -286,8 +286,7 @@ escape:
* else setpage()
*/
PTR
do_ft(ch, flag)
int ch, flag;
do_ft(int ch, int flag)
{
static int chi;
static int chp = 1;
@ -298,7 +297,7 @@ do_ft(ch, flag)
switch (ch) {
/*
case 1: beep();
return NULL; no previous command
return NULL; no previous command
case -1: if (chp == 'f' || chp == 't') dir = BACKWARD;
else dir = FORWARD;
break;
@ -364,8 +363,7 @@ do_ft(ch, flag)
void
do_z(mode)
int mode;
do_z(int mode)
{
switch (mode) {
case '.': while (y != maxy / 2) {
@ -401,8 +399,7 @@ do_z(mode)
void
scrolldown(lns)
int lns;
scrolldown(int lns)
{
while (lns--) {
if (maxpos >= (pagepos + Anzahl)) pagepos += Anzahl;
@ -414,8 +411,7 @@ scrolldown(lns)
void
scrollup(lns)
int lns;
scrollup(int lns)
{
while (lns--) {
if (mem <= (PTR)(pagepos - Anzahl)) pagepos -= Anzahl;
@ -459,13 +455,14 @@ setcur()
void
statpos()
{
char bin_val [9];
char bin_val [9];
unsigned char Char1;
int i;
int i;
off_t bytepos;
char string[MAXCMD+1], str[6];
if (!P(P_MO)) return;
// if (!P(P_MO)) return;
if (!statusflag) return;
bytepos = current - mem;
if (bytepos >= filesize) {
// mvaddstr(maxy, status, " ");
@ -483,11 +480,19 @@ statpos()
}
}
bin_val[8] = '\0';
sprintf(string, "%08llX %s \\%03o 0x%02X %3d ",
(long long)(bytepos + P(P_OF)), bin_val, Char1, Char1, Char1);
attrset(A_BOLD);
status = maxx - 1 - statsize;
if (status > 0) {
sprintf(string, "%08llX %s \\%03o 0x%02X %3d ",
(long long)(bytepos + P(P_OF)), bin_val, Char1, Char1, Char1);
} else {
sprintf(string, "%08llX %3d ",
(long long)(bytepos + P(P_OF)), Char1);
mvaddstr(maxy, 0, string);
attrset(A_NORMAL);
return;
}
mvaddstr(maxy, status, string);
if (isprint(Char1)) {
@ -521,10 +526,9 @@ statpos()
}
void
printline(mempos, scpos)
PTR mempos;
int scpos;
printline(PTR mempos, int scpos)
{
PTR hl_start = 0;
PTR hl_end = 0;
@ -544,44 +548,44 @@ printline(mempos, scpos)
mv_pos = AnzAdd;
*linbuf = '\0';
if (hl_spat) {
f_start = (mempos - Anzahl) < mem ? mem : (mempos - Anzahl);
f_end = mempos + (2 * Anzahl);
hl_start = fsearch_end(f_start, f_end, search_pat, &hl_end);
f_start = (mempos - Anzahl) < mem ? mem : (mempos - Anzahl);
f_end = mempos + (2 * Anzahl);
hl_start = fsearch_end(f_start, f_end, search_pat, &hl_end);
}
for (print_pos = 0; print_pos < Anzahl; print_pos++) {
if (hl_spat) {
while (hl_start != NULL) {
if (hl_start < mempos) {
if (hl_end < mempos) {
f_start = hl_start + 1;
hl_start = fsearch_end(f_start, f_end, search_pat, &hl_end);
} else {
attrset(A_STANDOUT); /* start out highlighted */
break;
}
} else if (hl_start >= mempos) {
break;
}
}
if (hl_start != NULL) {
if ((hl_start - mempos) == print_pos) {
mvaddstr(scpos, mv_pos, linbuf);
mv_pos = AnzAdd + (3 * print_pos);
*linbuf = '\0';
attrset(A_STANDOUT);
}
if ((hl_end - mempos) == print_pos) {
mvaddstr(scpos, mv_pos, linbuf);
*linbuf = '\0';
mv_pos = AnzAdd + (3 * print_pos);
f_start = hl_end;
hl_start = fsearch_end(f_start, f_end, search_pat, &hl_end);
if (f_start != hl_start) {
attrset(A_NORMAL);
}
}
}
while (hl_start != NULL) {
if (hl_start < mempos) {
if (hl_end < mempos) {
f_start = hl_start + 1;
hl_start = fsearch_end(f_start, f_end, search_pat, &hl_end);
} else {
attrset(A_STANDOUT); /* start out highlighted */
break;
}
} else if (hl_start >= mempos) {
break;
}
}
if (hl_start != NULL) {
if ((hl_start - mempos) == print_pos) {
mvaddstr(scpos, mv_pos, linbuf);
mv_pos = AnzAdd + (3 * print_pos);
*linbuf = '\0';
attrset(A_STANDOUT);
}
if ((hl_end - mempos) == print_pos) {
mvaddstr(scpos, mv_pos, linbuf);
*linbuf = '\0';
mv_pos = AnzAdd + (3 * print_pos);
f_start = hl_end;
hl_start = fsearch_end(f_start, f_end, search_pat, &hl_end);
if (f_start != hl_start) {
attrset(A_NORMAL);
}
}
}
}
if (mempos + print_pos >= maxpos) {
sprintf(tmpbuf, " ");
@ -609,10 +613,10 @@ printline(mempos, scpos)
addstr(string);
attrset(A_NORMAL);
} else {
addstr(".");
addstr(".");
}
} else {
addstr(".");
addstr(".");
}
}
} else {
@ -660,8 +664,7 @@ repaint() /***** redraw screen *********************/
/******* display an arbitrary address on screen *******/
void
setpage(addr)
PTR addr;
setpage(PTR addr)
{
if ((addr >= pagepos) && ((addr - pagepos) < screen)) {
y = (addr - pagepos) / Anzahl;
@ -684,8 +687,7 @@ setpage(addr)
int
cur_forw(check)
int check;
cur_forw(int check)
{
if (check) {
if (current - mem >= filesize) {
@ -760,8 +762,7 @@ cur_back()
void
fileinfo(fname)
char *fname;
fileinfo(char *fname)
{
off_t bytepos;
char fstatus[MAXCMD];
@ -788,8 +789,8 @@ fileinfo(fname)
if (edits) strcat(string, "[Modified] ");
if (filesize) {
bytepos = (pagepos + y * Anzahl + xpos()) - mem + 1L;
sprintf(fstatus, "byte %llu of %llu --%llu%%--",
(unsigned long long)bytepos,
sprintf(fstatus, "byte %llu of %llu --%llu%%--",
(unsigned long long)bytepos,
(unsigned long long)filesize,
(unsigned long long)(bytepos * 100L / filesize));
strcat(string, fstatus);
@ -830,8 +831,7 @@ vgetc()
void
stuffin(s)
char *s;
stuffin(char *s)
{
if (s == NULL) { /* clear the stuff buffer */
getcnext = NULL;
@ -846,9 +846,7 @@ char *s;
void
do_back(n, start)
off_t n;
PTR start;
do_back(off_t n, PTR start)
{
if (start - n < mem) {
beep();
@ -870,9 +868,7 @@ do_back(n, start)
int
do_delete(n, start)
off_t n;
PTR start;
do_delete(off_t n, PTR start)
{
if (n + start > maxpos) {
beep();
@ -902,10 +898,7 @@ do_delete(n, start)
* The :insert, :append and :change command
*/
void
do_ins_chg(start, arg, mode)
PTR start;
char *arg;
int mode;
do_ins_chg(PTR start, char *arg, int mode)
{
int base;
off_t buffer = BUFFER;
@ -945,22 +938,22 @@ do_ins_chg(start, arg, mode)
if (base == 1) { /* ASCII */
while (*poi != '\0') {
if (*poi == '\\') {
switch (*(++poi)) {
case 'n': val = '\n'; break;
case 'r': val = '\r'; break;
case 't': val = '\t'; break;
case '0': val = '\0'; break;
case '\\': val = '\\'; break;
default : val = '\\'; poi--;
}
poi++;
switch (*(++poi)) {
case 'n': val = '\n'; break;
case 'r': val = '\r'; break;
case 't': val = '\t'; break;
case '0': val = '\0'; break;
case '\\': val = '\\'; break;
default : val = '\\'; poi--;
}
poi++;
} else {
val = *poi++;
}
*(tempbuf + count++) = val;
}
} else {
while (isspace(cmdstr[strlen(cmdstr) - 1]))
while (isspace(cmdstr[strlen(cmdstr) - 1]))
cmdstr[strlen(cmdstr) - 1] = '\0';
while (*poi != '\0') {
val = strtol(poi, &epoi, base);
@ -993,7 +986,7 @@ do_ins_chg(start, arg, mode)
case U_APPEND:
if ((undo_count = alloc_buf(count, &undo_buf)) == 0L) {
repaint();
goto mfree;
goto mfree;
}
do_append((off_t)count, tempbuf);
memcpy(undo_buf, tempbuf, count);
@ -1021,11 +1014,9 @@ clear_marks()
void
do_mark(mark, addr)
int mark;
PTR addr;
do_mark(int mark, PTR addr)
{
if (mark < 'a' || mark > 'z' || current >= maxpos)
if (mark < 'a' || mark > 'z' || current >= maxpos)
return;
markbuf[mark - 'a'] = addr;
}