1
0
Fork 0
mirror of https://github.com/vbatts/bvi.git synced 2025-08-01 15:10:28 +00:00

bvi-1.3.2.src.tar.gz

This commit is contained in:
Gerhard Bürgmann 2005-01-07 00:00:00 +00:00 committed by Vincent Batts
parent 16baacb54f
commit 12a0ed970c
63 changed files with 2580 additions and 1159 deletions

224
bmore.c
View file

@ -5,11 +5,12 @@
* 2000-05-31 V 1.3.0 beta
* 2000-10-18 V 1.3.0 final
* 2002-01-16 V 1.3.1
* 2004-01-09 V 1.3.2
*
* NOTE: Edit this file with tabstop=4 !
*
* Copyright 1990-2002 by Gerhard Buergmann
* Gerhard.Buergmann@altavista.net
* Copyright 1990-2004 by Gerhard Buergmann
* gerhard@puon.at
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@ -31,20 +32,25 @@
# include <locale.h>
#endif
#ifdef __MSDOS__
#if defined(__MSDOS__) && !defined(DJGPP)
# define PRINTF cprintf
#else
# define PRINTF printf
#ifndef HELPFILE
# define HELPFILE "/usr/local/share/bmore.help"
# ifdef DJGPP
# define HELPFILE "/dev/env/DJDIR/lib/bmore.help"
# else
# define HELPFILE "/usr/local/lib/bmore.help"
# endif
#endif
#endif
#include "bmore.h"
char *copyright = "Copyright (C) 1990-2002 by Gerhard Buergmann";
char *copyright = "Copyright (C) 1990-2004 by Gerhard Buergmann";
int maxx, maxy;
int mymaxx = 0, mymaxy = 0;
char *name = NULL;
char sstring[MAXCMD] = ""; /* string for search */
char estring[MAXCMD] = ""; /* string for shell escape */
@ -62,11 +68,12 @@ char numarr[64]; /* string for collecting number */
char addr_form[15];
int ascii_flag = 0;
int d_flag = 0;
int c_flag = 0, d_flag = 0;
int exval = 0;
int init_search = 0;
char buffer1[MAXCMD], buffer2[MAXCMD];
int out_len;
int corr = 0, to_print;
int corr = 0, do_header = 0, to_print;
off_t init_byte = 0;
off_t last_search = 0;
off_t screen_home, filesize;
@ -74,7 +81,7 @@ off_t bytepos, oldpos;
int prompt = 1;
char helppath[MAXCMD];
static char *progname;
static char progname[10];
static char cmdbuf[MAXCMD];
static int cnt = 0;
static int icnt = 0;
@ -86,12 +93,15 @@ char *emptyclass = "Empty byte class '[]' or '[^]'";
/* -a ASCII mode
* -d beginners mode
* -c clear before displaying
* -i ignore case
* -n number of lines/screen
* -w width of screen
*/
void
usage()
{
fprintf(stderr, "Usage: %s [-adi] [+linenum | +/pattern] name1 name2 ...\n", progname);
fprintf(stderr, "Usage: %s [-acdi] [-lines] [+linenum | +/pattern] name1 name2 ...\n", progname);
exit(1);
}
@ -108,15 +118,14 @@ main(argc, argv)
long count;
int i, n = 1;
int d_line, r_line, z_line;
#ifdef __MSDOS__
char *poi;
#if defined(__MSDOS__) && !defined(DJGPP)
strcpy(helppath, argv[0]);
poi = strrchr(helppath, '\\');
*poi = '\0';
strcat(helppath, "\\MORE.HLP");
strcat(helppath, "\\BMORE.HLP");
#else
strncpy(helppath, HELPFILE, MAXCMD - 1);
#endif
@ -125,23 +134,46 @@ main(argc, argv)
setlocale(LC_ALL, "");
#endif
progname = argv[0];
poi = strrchr(argv[0], DELIM);
if (poi) strncpy(progname, ++poi, 9);
else strncpy(progname, argv[0], 9);
strtok(progname, ".");
while (n < argc) {
switch (argv[n][0]) {
case '-':
i = 1;
while (argv[n][i] != '\0') {
switch (argv[n][i]) {
case 'a': ascii_flag++;
break;
case 'd': d_flag++;
break;
case 'i': ignore_case++;
break;
default: usage();
if (argv[n][1] >= '0' && argv[n][1] <= '9') {
sscanf(&argv[n][1], "%dx%d", &mymaxy, &mymaxx);
} else if (argv[n][1] == 'n') {
if (argv[n+1] == NULL || argv[n+1][0] == '-') {
usage();
} else {
sscanf(&argv[++n][0], "%d", &mymaxy);
}
} else if (argv[n][1] == 'w') {
if (argv[n+1] == NULL || argv[n+1][0] == '-') {
usage();
} else {
sscanf(&argv[++n][0], "%d", &mymaxx);
}
} else {
i = 1;
while (argv[n][i] != '\0') {
switch (argv[n][i]) {
case 'a': ascii_flag++;
break;
case 'c': c_flag++;
break;
case 'd': d_flag++;
break;
case 'i': ignore_case++;
break;
default:
usage();
}
i++;
}
i++;
}
n++;
break;
@ -166,24 +198,35 @@ main(argc, argv)
break;
}
}
if (numfiles == 0) {
curr_file = stdin;
if (isatty(fileno(stdin)) != 0) usage();
} else {
open_file(name);
file_nr = 1;
fseek(curr_file, init_byte, SEEK_SET);
bytepos += init_byte;
}
screen_home = bytepos;
initterm();
set_tty();
maxy -= 2;
if (mymaxy) {
maxy = mymaxy;
}
z_line = maxy;
d_line = maxy / 2;
r_line = 1;
if (numfiles == 0) {
curr_file = stdin;
if (isatty(fileno(stdin)) != 0) {
reset_tty();
usage();
}
} else {
file_nr = 1;
while (open_file(name)) {
do_next(1);
}
if (exval) {
} else {
fseek(curr_file, init_byte, SEEK_SET);
bytepos += init_byte;
}
}
screen_home = bytepos;
AnzAdd = 10;
strcpy(addr_form, "%08lX ");
@ -191,24 +234,42 @@ main(argc, argv)
out_len = ((maxx - AnzAdd - 1) / 4) * 4;
else
out_len = ((maxx - AnzAdd - 1) / 16) * 4;
if (mymaxx) {
out_len = mymaxx;
}
if (init_search)
bmsearch(init_search);
if (no_tty) {
while(!printout(1));
int fileloop;
for (fileloop = 0; fileloop < numfiles; fileloop++) {
while(!printout(1));
do_next(1);
open_file(name);
}
fclose(curr_file);
reset_tty();
exit(0);
exit(exval);
}
if (printout(maxy)) {
do_next(1);
if (!exval) {
if (printout(maxy)) {
do_next(1);
}
}
signal(SIGINT, sig);
signal(SIGQUIT, sig);
/* main loop */
do {
to_print = 0;
if (prompt) {
highvideo();
if (prompt == 2) {
while (open_file(name)) {
do_next(1);
}
}
highlight();
PRINTF("--More--");
if (prompt == 2) {
PRINTF("(Next file: %s)", name);
@ -217,13 +278,15 @@ main(argc, argv)
}
if (d_flag) PRINTF("[Press space to continue, 'q' to quit]");
normvideo();
normal();
fflush(stdout);
}
ch = vgetc();
/*
if (prompt == 2) {
open_file(name);
}
*/
prompt = 1;
PRINTF("\r");
while (ch >= '0' && ch <= '9') {
@ -262,10 +325,10 @@ main(argc, argv)
break;
case 'q':
case 'Q':
clreol();
cleartoeol();
fclose(curr_file);
reset_tty();
exit(0);
exit(exval);
case ':' :
switch (colon) {
case 'f':
@ -282,7 +345,7 @@ main(argc, argv)
if (precount < 1) precount = 1;
do_next(precount);
PRINTF("\r");
clreol();
cleartoeol();
PRINTF("\n...Skipping to file %s\r\n\r\n", name);
prompt = 2;
break;
@ -290,19 +353,19 @@ main(argc, argv)
if (precount < 1) precount = 1;
do_next(-precount);
PRINTF("\r");
clreol();
cleartoeol();
PRINTF("\n...Skipping back to file %s\r\n\r\n", name);
prompt = 2;
break;
case 'q':
clreol();
cleartoeol();
fclose(curr_file);
reset_tty();
exit(0);
exit(exval);
break;
case '!':
if (!no_intty) {
clreol();
cleartoeol();
if (rdline(colon, estring)) break;
doshell(estring);
PRINTF("------------------------\r\n");
@ -314,7 +377,7 @@ main(argc, argv)
break;
case '!':
if (!no_intty) {
clreol();
cleartoeol();
if (rdline(ch, estring)) break;
doshell(estring);
PRINTF("------------------------\r\n");
@ -329,7 +392,7 @@ main(argc, argv)
if (no_intty) {
bmbeep();
} else {
clrscr();
clearscreen();
to_print = maxy + 1;
fseek(curr_file, screen_home, SEEK_SET);
bytepos = screen_home;
@ -363,7 +426,7 @@ main(argc, argv)
count = precount;
}
putchar('\r');
clreol();
cleartoeol();
PRINTF("\n...skipping %ld line", count);
if (count > 1) {
PRINTF("s\r\n\r\n");
@ -382,7 +445,7 @@ main(argc, argv)
}
case '/': /**** Search String ****/
if (!repeat) {
clreol();
cleartoeol();
if (rdline(ch, sstring)) break;
}
case 'n': /**** Search Next ****/
@ -401,13 +464,13 @@ main(argc, argv)
screen_home = bytepos;
to_print = maxy;
PRINTF("\r");
clreol();
cleartoeol();
PRINTF("\n\r\n***Back***\r\n\r\n");
}
break;
case '=':
prompt = 0;
clreol();
cleartoeol();
PRINTF("%lX hex %lu dec", (unsigned long)bytepos,
(unsigned long)bytepos);
fflush(stdout);
@ -426,7 +489,7 @@ main(argc, argv)
case 'w':
case 'v':
if (!no_intty) {
clreol();
cleartoeol();
if (ch == 'v') {
sprintf(string, "bvi +%lu %s",
(unsigned long)(screen_home +
@ -482,7 +545,7 @@ rdline(ch, sstring)
if (i) {
sstring[--i] = '\0';
PRINTF("\r%c%s", ch, sstring);
clreol();
cleartoeol();
} else {
ch1 = ESC;
break;
@ -504,7 +567,7 @@ rdline(ch, sstring)
}
if (ch1 == ESC) {
putchar('\r');
clreol();
cleartoeol();
return 1;
}
if (i) sstring[i] = '\0';
@ -520,7 +583,7 @@ do_next(n)
if (n == 1 && file_nr == numfiles) {
fclose(curr_file);
reset_tty();
exit(0);
exit(exval);
}
if ((file_nr + n) > numfiles)
file_nr = numfiles;
@ -534,12 +597,12 @@ do_next(n)
} else {
fclose(curr_file);
reset_tty();
exit(0);
exit(exval);
}
}
void
int
open_file(name)
char *name;
{
@ -548,19 +611,15 @@ open_file(name)
if (stat(name, &buf) > -1) {
filesize = buf.st_size;
}
if (numfiles > 1) {
PRINTF("\r");
clreol();
PRINTF("\n::::::::::::::\r\n%s\r\n::::::::::::::\r\n", name);
corr = 2;
}
if (curr_file != NULL) fclose(curr_file);
if (numfiles > 1) do_header = 1;
if ((curr_file = fopen(name, "rb")) == NULL) {
/* reset_tty(); */
perror(name);
exit(1);
exval = 1;
return 1;
}
bytepos = screen_home = 0;
return 0;
}
@ -572,7 +631,7 @@ putline(buf, num)
int print_pos;
unsigned char ch;
PRINTF(addr_form, bytepos);
PRINTF(addr_form, (unsigned long)bytepos);
for (print_pos = 0; print_pos < num; print_pos++) {
ch = buf[print_pos];
if (!ascii_flag) {
@ -592,7 +651,8 @@ putline(buf, num)
*(string + print_pos) = ' ';
}
*(string + num) = '\0';
PRINTF("%s\r\n", string);
if (no_tty) PRINTF("%s\n", string);
else PRINTF("%s\r\n", string);
}
@ -604,6 +664,20 @@ printout(lns)
int doub = 0;
static int flag;
if (c_flag) {
clearscreen();
}
if (do_header) {
if (no_tty) {
PRINTF("::::::::::::::\n%s\n::::::::::::::\n", name);
} else {
PRINTF("\r");
cleartoeol();
PRINTF("::::::::::::::\r\n%s\r\n::::::::::::::\r\n", name);
}
do_header = 0;
corr = 2;
}
if (corr && (lns > maxy - 2)) lns -= corr;
corr = 0;
do {
@ -619,7 +693,7 @@ printout(lns)
lns--;
} else {
if (flag) {
clreol();
cleartoeol();
PRINTF("*\r\n");
lns--;
} else {
@ -855,10 +929,10 @@ emsg(s)
char *s;
{
putchar('\r');
clreol();
highvideo();
cleartoeol();
highlight();
PRINTF(s);
normvideo();
normal();
fflush(stdout);
prompt = 0;
}