1
0
Fork 0
mirror of https://github.com/vbatts/bvi.git synced 2025-07-31 14:40:27 +00:00

git ls-files | xargs dos2unix

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2025-03-02 10:25:41 -05:00
parent 75fc14b579
commit 5ab3ef5609
5 changed files with 816 additions and 816 deletions

264
bm_dos.c
View file

@ -1,132 +1,132 @@
/* BM_DOS.C - DOS specific subroutines for BMORE
*
* 2000-05-10 V 1.3.0 alpha
* 2000-07-07 V 1.3.0 final
* 2001-12-07 V 1.3.1
* 2003-07-03 V 1.3.2
*
* NOTE: Edit this file with tabstop=4 !
*
* Copyright 1996-2003 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
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* See file COPYING for information on distribution conditions.
*/
/*
#define DEBUG 1
*/
#include "bmore.h"
#define TBUFSIZ 1024
extern off_t bytepos, screen_home;
extern FILE *curr_file;
/*
extern int screenlines;
*/
int got_int;
int no_intty, no_tty;
#ifdef DEBUG
FILE *dbug;
#endif
void
initterm()
{
maxx = 80;
maxy = 25;
}
void
set_tty ()
{
}
void
reset_tty ()
{
}
void
sig()
{
signal(SIGINT, sig);
got_int = TRUE;
}
/*
* doshell() - run a command or an interactive shell
*/
void
doshell(cmd)
char *cmd;
{
system(cmd);
printf("\r");
clearscreen();
fseek(curr_file, screen_home, SEEK_SET);
bytepos = screen_home;
}
void
highlight()
{
highvideo();
}
void
normal()
{
normvideo();
}
void
clearscreen()
{
clrscr();
}
void
home()
{
gotoxy(1, 1);
}
/* force clear to end of line */
cleartoeol()
{
clreol();
}
int
vgetc()
{
return ((char)bioskey(0));
}
/* BM_DOS.C - DOS specific subroutines for BMORE
*
* 2000-05-10 V 1.3.0 alpha
* 2000-07-07 V 1.3.0 final
* 2001-12-07 V 1.3.1
* 2003-07-03 V 1.3.2
*
* NOTE: Edit this file with tabstop=4 !
*
* Copyright 1996-2003 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
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* See file COPYING for information on distribution conditions.
*/
/*
#define DEBUG 1
*/
#include "bmore.h"
#define TBUFSIZ 1024
extern off_t bytepos, screen_home;
extern FILE *curr_file;
/*
extern int screenlines;
*/
int got_int;
int no_intty, no_tty;
#ifdef DEBUG
FILE *dbug;
#endif
void
initterm()
{
maxx = 80;
maxy = 25;
}
void
set_tty ()
{
}
void
reset_tty ()
{
}
void
sig()
{
signal(SIGINT, sig);
got_int = TRUE;
}
/*
* doshell() - run a command or an interactive shell
*/
void
doshell(cmd)
char *cmd;
{
system(cmd);
printf("\r");
clearscreen();
fseek(curr_file, screen_home, SEEK_SET);
bytepos = screen_home;
}
void
highlight()
{
highvideo();
}
void
normal()
{
normvideo();
}
void
clearscreen()
{
clrscr();
}
void
home()
{
gotoxy(1, 1);
}
/* force clear to end of line */
cleartoeol()
{
clreol();
}
int
vgetc()
{
return ((char)bioskey(0));
}

View file

@ -1,26 +1,26 @@
Most commands optionally preceded by integer argument k. Defaults in brackets.
Star (*) indicates argument becomes new default.
-------------------------------------------------------------------------------
<space> Display next k lines of bytes [current screen size]
z Display next k lines of bytes [current screen size]*
<return> Display next k lines of bytes [1]*
d or ctrl-D Scroll k lines [current scroll size, initially 11]*
q or Q or <interrupt> Exit from bmore
s Skip forward k lines of bytes [1]
f Skip forward k screenfuls of bytes [1]
b or ctrl-B Skip backwards k screenfuls of bytes [1]
' Go to place where previous search started
= Display current byte number
/<regular expression> Search for kth occurrence of ascii regular expr [1]
\<regular expression> Search for kth occurrence of binary regular expr [1]
n Search for kth occurrence of last r.e [1]
!<cmd> or :!<cmd> Execute <cmd> in a subshell
v Start up bvi at current position
w Start up bvi reading only a screenful of bytes [screen]
ctrl-L Redraw screen
:n Go to kth next file [1]
:p Go to kth previous file [1]
:f Display current file name and byte position
. Repeat previous command
-------------------------------------------------------------------------------
Most commands optionally preceded by integer argument k. Defaults in brackets.
Star (*) indicates argument becomes new default.
-------------------------------------------------------------------------------
<space> Display next k lines of bytes [current screen size]
z Display next k lines of bytes [current screen size]*
<return> Display next k lines of bytes [1]*
d or ctrl-D Scroll k lines [current scroll size, initially 11]*
q or Q or <interrupt> Exit from bmore
s Skip forward k lines of bytes [1]
f Skip forward k screenfuls of bytes [1]
b or ctrl-B Skip backwards k screenfuls of bytes [1]
' Go to place where previous search started
= Display current byte number
/<regular expression> Search for kth occurrence of ascii regular expr [1]
\<regular expression> Search for kth occurrence of binary regular expr [1]
n Search for kth occurrence of last r.e [1]
!<cmd> or :!<cmd> Execute <cmd> in a subshell
v Start up bvi at current position
w Start up bvi reading only a screenful of bytes [screen]
ctrl-L Redraw screen
:n Go to kth next file [1]
:p Go to kth previous file [1]
:f Display current file name and byte position
. Repeat previous command
-------------------------------------------------------------------------------

View file

@ -1,46 +1,46 @@
/* dosconf.h
*
* 1996-02-28 V 1.0.0
* 1999-01-21 V 1.1.0
* 1999-03-17 V 1.1.1
* 1999-07-01 V 1.2.0 beta
* 1999-08-27 V 1.2.0 final
*
* NOTE: Edit this file with tabstop=4 !
*
* Copyright 1996-2002 by Gerhard Buergmann
* Gerhard.Buergmann@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
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* See file COPYING for information on distribution conditions.
*/
/* Define if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define if you have the memmove function. */
#define HAVE_MEMMOVE 1
/* Define if you have the strdup function. */
#define HAVE_STRDUP 1
/* Define if you have the strtol function. */
#define HAVE_STRTOL 1
/* Define if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
/* Define if you have the <locale.h> header file. */
#if __TURBOC__ > 0x0400
# define HAVE_LOCALE_H 1
#endif
/* dosconf.h
*
* 1996-02-28 V 1.0.0
* 1999-01-21 V 1.1.0
* 1999-03-17 V 1.1.1
* 1999-07-01 V 1.2.0 beta
* 1999-08-27 V 1.2.0 final
*
* NOTE: Edit this file with tabstop=4 !
*
* Copyright 1996-2002 by Gerhard Buergmann
* Gerhard.Buergmann@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
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* See file COPYING for information on distribution conditions.
*/
/* Define if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define if you have the memmove function. */
#define HAVE_MEMMOVE 1
/* Define if you have the strdup function. */
#define HAVE_STRDUP 1
/* Define if you have the strtol function. */
#define HAVE_STRTOL 1
/* Define if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
/* Define if you have the <locale.h> header file. */
#if __TURBOC__ > 0x0400
# define HAVE_LOCALE_H 1
#endif

296
doscur.h
View file

@ -1,148 +1,148 @@
/* DOSCUR.H - CURSES.H for TURBO C
*
* Copyright 1996-2002 by Gerhard Buergmann
* Gerhard.Buergmann@puon.at
*
* 1996-02-28 V 1.0.0
* 1998-04-12 V 1.0.1
* 1999-01-14 V 1.1.1
* 1999-07-01 V 1.2.0
*
* 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
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* See file COPYING for information on distribution conditions.
*/
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#define TRUE 1
#define FALSE 0
#define ESC 27
#define KEY_F0 0x3A00
#define KEY_F(n) (KEY_F0+(n<<8))
#define KEY_DOWN 0x5000
#define KEY_UP 0x4800
#define KEY_LEFT 0x4B00
#define KEY_RIGHT 0x4D00
#define KEY_NPAGE 0x5100
#define KEY_PPAGE 0x4900
#define KEY_RETURN 0x0d
#define KEY_ENTER 0x0a
#define KEY_BACKSPACE 0x0E08
#define KEY_HOME 0x4700
#define KEY_LL 0x4f00 /* HOME DOWN, End */
#define KEY_DC 0x5300
#define KEY_IC 0x5200
#define A_NORMAL 3
#define A_STANDOUT 8
#define A_BOLD 8
#define A_REVERSE 127
#define A_BLINK 128
#define A_CHARTEXT 0x00ff
#define A_ATTRIBUTES 0xff00
#define chtype unsigned int
#define WINDOW text_info
extern struct WINDOW scr;
extern int stdscr;
extern int COLS;
extern int LINES;
extern int ECHO;
extern int NODEL;
void attrset(int);
#define initscr() clrscr();window(1,1,COLS,LINES);gettextinfo(&scr)
#define newwin(h,b,y,x) window(x+1,y+1,x+b+1,y+h+1);gettextinfo(&scr)
#define erasechar() KEY_ERASE
#define beep() putch(7)
#define flash() putch(7)
#define wclrtoeol(w) clreol()
#define clrtoeol() clreol()
#define werase(w) window(scr.winleft,scr.wintop,scr.winright,scr.winbottom)
#define erase() clrscr()
#define wclear(w) werase(w)
#define clear() clrscr()
/*
#define wattrset(w,a) textattr(a)
#define attrset(a) textattr(a)
*/
#define standout() highvideo()
#define standend() normvideo()
#define wmove(w,y,x) gotoxy(x+1,y+1)
#define move(y,x) gotoxy(x+1,y+1)
#define mvwaddch(w,y,x,c) gotoxy(x+1,y+1);putch(c)
#define mvaddch(y,x,c) gotoxy(x+1,y+1);putch(c)
#define waddch(w,c) putch(c)
#define addch(c) putch(c)
#define mvwaddstr(w,y,x,s) gotoxy(x+1,y+1);cputs(s)
#define mvaddstr(y,x,s) gotoxy(x+1,y+1);cputs(s)
#define waddstr(s) cputs(s)
#define addstr(s) cputs(s)
#define mvwprintw(w,y,x,s) gotoxy(x+1,y+1);cprintf(s)
#define mvprintw(y,x,s,a) gotoxy(x+1,y+1);cprintf(s,a)
#define wprintw(w,s) cprintf(s)
#define printw cprintf
#define getyx(w,y,x) x=wherex()-1;y=wherey()-1
#define getbegyx(w,y,x) x=scr.winleft;y=scr.wintop;
#define getmaxyx(w,y,x) x=(scr.winright)-(scr.winleft);y=(scr.winbottom)-(scr.wintop)+1
#define winsertln() insline()
#define insertln() insline()
#define wdeleteln(w) delline()
#define deleteln() delline()
#define mvwgetch(w,y,x) gotoxy(x+1,y+1);ugetch()
#define mvgetch(y,x) gotoxy(x+1,y+1);ugetch()
#define wgetch(w) ugetch()
#define mvwgetstr(w,y,x,s) gotoxy(x+1,y+1);gets(s)
#define mvgetstr(y,x,s) gotoxy(x+1,y+1);gets(s)
#define wgetstr(w,s) gets(s)
/*
#define getstr(s) gets(s)
*/
#define flushinp() fflush(stdin)
#define mvwscanw(w,y,x,s) gotoxy(x+1,y+1);cscanf(s)
#define mvscanw(y,x,s) gotoxy(x+1,y+1);cscanf(s)
#define wscanw(w,s) wscanw(s)
#define scanw cscanf
#define mvinsch(y,x,c) gotoxy(x+1,y+1);insch(c)
#define nodelay(w,b) NODEL=b
#define echo() ECHO=TRUE
#define noecho() ECHO=FALSE
#define nl()
#define nonl()
#define keypad(a,b)
#define refresh()
#define wrefresh(w)
#define cbreak()
#define endwin()
#define raw()
#define noraw()
#define notimeout(w,t)
#define idlok(w,b)
#define scrollok(a,b)
#define doupdate()
#define savetty()
#define resetty()
#define ERR (-1)
/* DOSCUR.H - CURSES.H for TURBO C
*
* Copyright 1996-2002 by Gerhard Buergmann
* Gerhard.Buergmann@puon.at
*
* 1996-02-28 V 1.0.0
* 1998-04-12 V 1.0.1
* 1999-01-14 V 1.1.1
* 1999-07-01 V 1.2.0
*
* 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
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* See file COPYING for information on distribution conditions.
*/
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#define TRUE 1
#define FALSE 0
#define ESC 27
#define KEY_F0 0x3A00
#define KEY_F(n) (KEY_F0+(n<<8))
#define KEY_DOWN 0x5000
#define KEY_UP 0x4800
#define KEY_LEFT 0x4B00
#define KEY_RIGHT 0x4D00
#define KEY_NPAGE 0x5100
#define KEY_PPAGE 0x4900
#define KEY_RETURN 0x0d
#define KEY_ENTER 0x0a
#define KEY_BACKSPACE 0x0E08
#define KEY_HOME 0x4700
#define KEY_LL 0x4f00 /* HOME DOWN, End */
#define KEY_DC 0x5300
#define KEY_IC 0x5200
#define A_NORMAL 3
#define A_STANDOUT 8
#define A_BOLD 8
#define A_REVERSE 127
#define A_BLINK 128
#define A_CHARTEXT 0x00ff
#define A_ATTRIBUTES 0xff00
#define chtype unsigned int
#define WINDOW text_info
extern struct WINDOW scr;
extern int stdscr;
extern int COLS;
extern int LINES;
extern int ECHO;
extern int NODEL;
void attrset(int);
#define initscr() clrscr();window(1,1,COLS,LINES);gettextinfo(&scr)
#define newwin(h,b,y,x) window(x+1,y+1,x+b+1,y+h+1);gettextinfo(&scr)
#define erasechar() KEY_ERASE
#define beep() putch(7)
#define flash() putch(7)
#define wclrtoeol(w) clreol()
#define clrtoeol() clreol()
#define werase(w) window(scr.winleft,scr.wintop,scr.winright,scr.winbottom)
#define erase() clrscr()
#define wclear(w) werase(w)
#define clear() clrscr()
/*
#define wattrset(w,a) textattr(a)
#define attrset(a) textattr(a)
*/
#define standout() highvideo()
#define standend() normvideo()
#define wmove(w,y,x) gotoxy(x+1,y+1)
#define move(y,x) gotoxy(x+1,y+1)
#define mvwaddch(w,y,x,c) gotoxy(x+1,y+1);putch(c)
#define mvaddch(y,x,c) gotoxy(x+1,y+1);putch(c)
#define waddch(w,c) putch(c)
#define addch(c) putch(c)
#define mvwaddstr(w,y,x,s) gotoxy(x+1,y+1);cputs(s)
#define mvaddstr(y,x,s) gotoxy(x+1,y+1);cputs(s)
#define waddstr(s) cputs(s)
#define addstr(s) cputs(s)
#define mvwprintw(w,y,x,s) gotoxy(x+1,y+1);cprintf(s)
#define mvprintw(y,x,s,a) gotoxy(x+1,y+1);cprintf(s,a)
#define wprintw(w,s) cprintf(s)
#define printw cprintf
#define getyx(w,y,x) x=wherex()-1;y=wherey()-1
#define getbegyx(w,y,x) x=scr.winleft;y=scr.wintop;
#define getmaxyx(w,y,x) x=(scr.winright)-(scr.winleft);y=(scr.winbottom)-(scr.wintop)+1
#define winsertln() insline()
#define insertln() insline()
#define wdeleteln(w) delline()
#define deleteln() delline()
#define mvwgetch(w,y,x) gotoxy(x+1,y+1);ugetch()
#define mvgetch(y,x) gotoxy(x+1,y+1);ugetch()
#define wgetch(w) ugetch()
#define mvwgetstr(w,y,x,s) gotoxy(x+1,y+1);gets(s)
#define mvgetstr(y,x,s) gotoxy(x+1,y+1);gets(s)
#define wgetstr(w,s) gets(s)
/*
#define getstr(s) gets(s)
*/
#define flushinp() fflush(stdin)
#define mvwscanw(w,y,x,s) gotoxy(x+1,y+1);cscanf(s)
#define mvscanw(y,x,s) gotoxy(x+1,y+1);cscanf(s)
#define wscanw(w,s) wscanw(s)
#define scanw cscanf
#define mvinsch(y,x,c) gotoxy(x+1,y+1);insch(c)
#define nodelay(w,b) NODEL=b
#define echo() ECHO=TRUE
#define noecho() ECHO=FALSE
#define nl()
#define nonl()
#define keypad(a,b)
#define refresh()
#define wrefresh(w)
#define cbreak()
#define endwin()
#define raw()
#define noraw()
#define notimeout(w,t)
#define idlok(w,b)
#define scrollok(a,b)
#define doupdate()
#define savetty()
#define resetty()
#define ERR (-1)

928
dosio.c
View file

@ -1,464 +1,464 @@
/* DOSIO.C - file I/O and alloc subroutines for MSDOS - BVI
*
* 1996-02-28 V 1.0.0
* 1998-04-12 V 1.0.1
* 1999-01-14 V 1.1.0
* 1999-04-27 V 1.1.1
* 1999-07-02 V 1.2.0 beta
* 1999-09-01 V 1.2.0 final
* 2000-05-02 V 1.3.0 alpha
*
* NOTE: Edit this file with tabstop=4 !
*
* Copyright 1996-2002 by Gerhard Buergmann
* Gerhard.Buergmann@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
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* See file COPYING for information on distribution conditions.
*/
#include <conio.h>
#include <alloc.h>
#include <fcntl.h>
#include <bios.h>
#include <io.h>
#include <mem.h>
#include "bvi.h"
#include "set.h"
char *terminal = "ansi";
extern maxy;
struct WINDOW scr;
int stdscr = 0;
int COLS = 80;
int LINES = 25;
int ECHO = TRUE;
int NODEL = FALSE;
static struct stat buf;
int filemode;
int inch(void);
void
attrset(int attr)
{
switch(attr) {
case A_NORMAL: textcolor(P(P_CO) & 0x07);
textbackground((P(P_CO) & 0xf0) >> 4);
break;
case A_BOLD: textcolor((P(P_CO) & 0x07) | 0x08);
textbackground((P(P_CO) & 0xf0) >> 4);
break;
case A_REVERSE: textcolor((P(P_CO) & 0xf0) >> 4);
textbackground(P(P_CO) & 0x0f);
break;
case A_BLINK: textcolor((P(P_CO) & 0xf0) >> 4);
textbackground(P(P_CO) & 0x0f);
break;
}
}
int
getch()
{
int x;
if (NODEL) if (!kbhit()) return(ERR);
x = bioskey(0);
if ((x & 0xff) == 0) return(x);
else {
x &= 0xff;
if (ECHO) putch(x);
return(x); }
}
void
delch()
{
int x, y;
x = wherex(); y = wherey();
movetext(x + 1, y, COLS - x, y, x, y);
gotoxy(COLS, y);
putch(' ');
gotoxy(x, y);
}
void
insch(int c)
{
char line[80];
int x, y;
x = wherex(); y = wherey();
gettext(x, y, COLS - x, y, line);
puttext(x + 1, y, COLS - x + 1, y, line);
putch(c);
}
int
inch()
{
return peek(0xb800, (wherex() - 1) + (wherey() - 1) * COLS);
}
int
mvinch(int y, int x)
{
gotoxy(x + 1, y + 1);
return inch();
}
/*********** Save the patched file ********************/
int
save(char *fname, PTR start, PTR end, int flags)
{
int fd;
char string[255];
char *newstr;
off_t written;
off_t filesize;
unsigned n, to_write;
if (!fname) {
emsg("No file|No current filename");
return 0;
}
if (stat(fname, &buf) == -1) {
newstr = "[New file] ";
} else {
if (S_ISDIR(buf.st_mode)) {
sprintf(string, "\"%s\" Is a directory", fname);
msg(string);
return 0;
}
newstr = "";
}
if (filemode == PARTIAL) flags = O_RDWR;
if ((fd = open(fname, flags, 0666)) < 0) {
sysemsg(fname);
return 0;
}
if (filemode == PARTIAL) {
if (block_read) {
filesize = block_read;
sprintf(string, "\"%s\" range %lu-%lu", fname,
(unsigned long)block_begin,
(unsigned long)(block_begin - 1 + filesize));
if (lseek(fd, block_begin, SEEK_SET) < 0) {
sysemsg(fname);
return 0;
}
} else {
msg("Null range");
return 0;
}
} else {
filesize = end - start + 1L;
sprintf(string, "\"%s\" %s%lu@bytes", fname, newstr, (long)filesize);
}
written = 0;
do {
to_write = (filesize - written) > 0xfffe ? 0xfffe : (filesize - written);
if ((n = write(fd, start + written, to_write)) == 0xffff) {
sysemsg(fname);
close(fd);
return(0L);
}
written += (off_t)n;
} while (written < filesize);
close(fd);
edits = 0;
msg(string);
return 1;
}
off_t
load(char *fname)
{
int fd = -1;
char string[MAXCMD];
unsigned chunk, n;
buf.st_size = filesize = 0L;
if (fname != NULL) {
if (stat(fname, &buf) == -1) {
filemode = NEW;
} else if (S_ISDIR(buf.st_mode)) {
filemode = DIRECTORY;
} else if (S_ISREG(buf.st_mode)) {
if ((fd = open(fname, O_RDONLY|O_BINARY)) > 0) {
filemode = REGULAR;
if (access(fname, 2)) {
P(P_RO) = TRUE;
params[P_RO].flags |= P_CHANGED;
}
} else {
sysemsg(fname);
filemode = ERROR;
}
}
} else {
filemode = NEW;
}
if (mem != NULL) farfree(mem);
if (block_flag) {
memsize = block_size + 1000;
} else if (filemode == REGULAR) {
memsize = buf.st_size + 100;
} else {
memsize = 1000;
}
if (farcoreleft() < memsize) {
move(maxy, 0);
endwin();
printf("\n\nOut of memory\n");
exit(0);
}
mem = (char huge *)farmalloc(memsize);
clear_marks();
if (block_flag && (filemode == REGULAR)) {
if (lseek(fd, block_begin, SEEK_SET) < 0) {
sysemsg(fname);
filemode = ERROR;
} else {
chunk = block_size > 0xfffe ? 0xfffe : block_size;
do {
if ((n = read(fd, mem + filesize, chunk)) == 0xffff) {
sysemsg(fname);
filemode = ERROR;
break;
}
filesize += (off_t)n;
} while (filesize < buf.st_size);
if ((filesize == 0) {
sprintf(string, "\"%s\" No such range: %lu-%lu", fname,
(unsigned long)block_begin, (unsigned long)(block_end));
} else {
sprintf(string, "\"%s\" range %lu-%lu", fname,
(unsigned long)block_begin,
(unsigned long)(block_begin + filesize - 1));
}
filemode = PARTIAL;
block_read = filesize;
msg(string);
P(P_OF) = block_begin;
params[P_OF].flags |= P_CHANGED;
}
} else if (filemode == REGULAR) {
chunk = buf.st_size > 0xfffe ? 0xfffe : buf.st_size;
do {
if ((n = read(fd, mem + filesize, chunk)) == 0xffff) {
sysemsg(fname);
filemode = ERROR;
break;
}
filesize += (off_t)n;
} while (filesize < buf.st_size);
}
if (fd > 0) close(fd);
if (filemode != REGULAR) {
filesize = 0L;
}
if (fname != NULL) {
switch (filemode) {
case NEW:
sprintf(string, "\"%s\" [New File]", fname);
break;
case REGULAR:
sprintf(string, "\"%s\" %s%lu bytes", fname,
P(P_RO) ? "[Read only] " : "", (long)filesize);
break;
case DIRECTORY:
sprintf(string, "\"%s\" Directory", fname);
break;
}
if (filemode != ERROR) msg(string);
}
pagepos = mem;
maxpos = (PTR)(mem + filesize);
loc = HEX;
x = AnzAdd; y = 0;
repaint();
return(filesize);
}
int
addfile(char *fname)
{
int fd;
off_t oldsize;
unsigned chunk, n;
if (stat(fname, &buf)) {
sysemsg(fname);
return 1;
}
if ((fd = open(fname, O_RDONLY)) == -1) {
sysemsg(fname);
return 1;
}
oldsize = filesize;
if (enlarge(buf.st_size)) return 1;
chunk = buf.st_size > 0xfffe ? 0xfffe : buf.st_size;
do {
if ((n = read(fd, mem + filesize, chunk)) == 0xffff) {
sysemsg(fname);
filemode = ERROR;
return 1;
}
filesize += (off_t)n;
} while (filesize < buf.st_size);
maxpos = mem + filesize;
close(fd);
setpage(mem + oldsize);
return 0;
}
void
bvi_init(char *dir)
{
char *poi;
char *initstr;
char rcpath[255];
shell = getenv("COMSPEC");
if (shell == NULL || *shell == '\0')
shell = "COMMAND.COM";
strcpy(rcpath, dir);
poi = strrchr(rcpath, '\\');
*poi = '\0';
strcat(rcpath, "\\BVI.RC");
if ((initstr = getenv("BVIINIT")) != NULL) {
docmdline(initstr);
}
read_rc("BVI.RC");
read_rc(rcpath);
}
int
enlarge(off_t add)
{
PTR newmem;
off_t savecur, savepag, savemax, saveundo;
savecur = curpos - mem;
savepag = pagepos - mem;
savemax = maxpos - mem;
saveundo = undo_start - mem;
newmem = (PTR)farrealloc(mem, memsize + add);
if (newmem == NULL) {
emsg("Out of memory");
return 1;
}
mem = newmem;
memsize += add;
curpos = mem + savecur;
pagepos = mem + savepag;
maxpos = mem + savemax;
undo_start = mem + saveundo;
current = curpos + 1;
return 0;
}
void
do_shell()
{
system("");
}
off_t
alloc_buf(off_t n, char **buffer)
{
if ((*buffer = (char *)farrealloc(*buffer, n)) == NULL) {
emsg("No buffer space available");
return 0L;
}
return n;
}
void
d_memmove(PTR dest, PTR src, off_t n)
{
unsigned len;
long chunk;
PTR source;
PTR destin;
chunk = n;
if (dest < src) {
/* copy forward */
source = src;
destin = dest;
while (chunk > 0L) {
len = chunk > 0x7ffe ? 0x7ffe : chunk;
movmem(source, destin, len);
chunk -= len;
source += len;
destin += len;
}
} else {
/* copy backward */
source = src + n;
destin = dest + n;
while (chunk > 0L) {
len = chunk > 0x7ffe ? 0x7ffe : chunk;
chunk -= len;
source -= len;
destin -= len;
movmem(source, destin, len);
}
}
}
void
d_memcpy(PTR dest, PTR src, off_t n)
{
unsigned len;
long chunk;
PTR source;
PTR destin;
source = src;
destin = dest;
chunk = n;
while (chunk > 0L) {
len = chunk > 0x7ffe ? 0x7ffe : chunk;
movmem(source, destin, len);
chunk -= len;
source += len;
destin += len;
}
}
/* DOSIO.C - file I/O and alloc subroutines for MSDOS - BVI
*
* 1996-02-28 V 1.0.0
* 1998-04-12 V 1.0.1
* 1999-01-14 V 1.1.0
* 1999-04-27 V 1.1.1
* 1999-07-02 V 1.2.0 beta
* 1999-09-01 V 1.2.0 final
* 2000-05-02 V 1.3.0 alpha
*
* NOTE: Edit this file with tabstop=4 !
*
* Copyright 1996-2002 by Gerhard Buergmann
* Gerhard.Buergmann@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
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* See file COPYING for information on distribution conditions.
*/
#include <conio.h>
#include <alloc.h>
#include <fcntl.h>
#include <bios.h>
#include <io.h>
#include <mem.h>
#include "bvi.h"
#include "set.h"
char *terminal = "ansi";
extern maxy;
struct WINDOW scr;
int stdscr = 0;
int COLS = 80;
int LINES = 25;
int ECHO = TRUE;
int NODEL = FALSE;
static struct stat buf;
int filemode;
int inch(void);
void
attrset(int attr)
{
switch(attr) {
case A_NORMAL: textcolor(P(P_CO) & 0x07);
textbackground((P(P_CO) & 0xf0) >> 4);
break;
case A_BOLD: textcolor((P(P_CO) & 0x07) | 0x08);
textbackground((P(P_CO) & 0xf0) >> 4);
break;
case A_REVERSE: textcolor((P(P_CO) & 0xf0) >> 4);
textbackground(P(P_CO) & 0x0f);
break;
case A_BLINK: textcolor((P(P_CO) & 0xf0) >> 4);
textbackground(P(P_CO) & 0x0f);
break;
}
}
int
getch()
{
int x;
if (NODEL) if (!kbhit()) return(ERR);
x = bioskey(0);
if ((x & 0xff) == 0) return(x);
else {
x &= 0xff;
if (ECHO) putch(x);
return(x); }
}
void
delch()
{
int x, y;
x = wherex(); y = wherey();
movetext(x + 1, y, COLS - x, y, x, y);
gotoxy(COLS, y);
putch(' ');
gotoxy(x, y);
}
void
insch(int c)
{
char line[80];
int x, y;
x = wherex(); y = wherey();
gettext(x, y, COLS - x, y, line);
puttext(x + 1, y, COLS - x + 1, y, line);
putch(c);
}
int
inch()
{
return peek(0xb800, (wherex() - 1) + (wherey() - 1) * COLS);
}
int
mvinch(int y, int x)
{
gotoxy(x + 1, y + 1);
return inch();
}
/*********** Save the patched file ********************/
int
save(char *fname, PTR start, PTR end, int flags)
{
int fd;
char string[255];
char *newstr;
off_t written;
off_t filesize;
unsigned n, to_write;
if (!fname) {
emsg("No file|No current filename");
return 0;
}
if (stat(fname, &buf) == -1) {
newstr = "[New file] ";
} else {
if (S_ISDIR(buf.st_mode)) {
sprintf(string, "\"%s\" Is a directory", fname);
msg(string);
return 0;
}
newstr = "";
}
if (filemode == PARTIAL) flags = O_RDWR;
if ((fd = open(fname, flags, 0666)) < 0) {
sysemsg(fname);
return 0;
}
if (filemode == PARTIAL) {
if (block_read) {
filesize = block_read;
sprintf(string, "\"%s\" range %lu-%lu", fname,
(unsigned long)block_begin,
(unsigned long)(block_begin - 1 + filesize));
if (lseek(fd, block_begin, SEEK_SET) < 0) {
sysemsg(fname);
return 0;
}
} else {
msg("Null range");
return 0;
}
} else {
filesize = end - start + 1L;
sprintf(string, "\"%s\" %s%lu@bytes", fname, newstr, (long)filesize);
}
written = 0;
do {
to_write = (filesize - written) > 0xfffe ? 0xfffe : (filesize - written);
if ((n = write(fd, start + written, to_write)) == 0xffff) {
sysemsg(fname);
close(fd);
return(0L);
}
written += (off_t)n;
} while (written < filesize);
close(fd);
edits = 0;
msg(string);
return 1;
}
off_t
load(char *fname)
{
int fd = -1;
char string[MAXCMD];
unsigned chunk, n;
buf.st_size = filesize = 0L;
if (fname != NULL) {
if (stat(fname, &buf) == -1) {
filemode = NEW;
} else if (S_ISDIR(buf.st_mode)) {
filemode = DIRECTORY;
} else if (S_ISREG(buf.st_mode)) {
if ((fd = open(fname, O_RDONLY|O_BINARY)) > 0) {
filemode = REGULAR;
if (access(fname, 2)) {
P(P_RO) = TRUE;
params[P_RO].flags |= P_CHANGED;
}
} else {
sysemsg(fname);
filemode = ERROR;
}
}
} else {
filemode = NEW;
}
if (mem != NULL) farfree(mem);
if (block_flag) {
memsize = block_size + 1000;
} else if (filemode == REGULAR) {
memsize = buf.st_size + 100;
} else {
memsize = 1000;
}
if (farcoreleft() < memsize) {
move(maxy, 0);
endwin();
printf("\n\nOut of memory\n");
exit(0);
}
mem = (char huge *)farmalloc(memsize);
clear_marks();
if (block_flag && (filemode == REGULAR)) {
if (lseek(fd, block_begin, SEEK_SET) < 0) {
sysemsg(fname);
filemode = ERROR;
} else {
chunk = block_size > 0xfffe ? 0xfffe : block_size;
do {
if ((n = read(fd, mem + filesize, chunk)) == 0xffff) {
sysemsg(fname);
filemode = ERROR;
break;
}
filesize += (off_t)n;
} while (filesize < buf.st_size);
if ((filesize == 0) {
sprintf(string, "\"%s\" No such range: %lu-%lu", fname,
(unsigned long)block_begin, (unsigned long)(block_end));
} else {
sprintf(string, "\"%s\" range %lu-%lu", fname,
(unsigned long)block_begin,
(unsigned long)(block_begin + filesize - 1));
}
filemode = PARTIAL;
block_read = filesize;
msg(string);
P(P_OF) = block_begin;
params[P_OF].flags |= P_CHANGED;
}
} else if (filemode == REGULAR) {
chunk = buf.st_size > 0xfffe ? 0xfffe : buf.st_size;
do {
if ((n = read(fd, mem + filesize, chunk)) == 0xffff) {
sysemsg(fname);
filemode = ERROR;
break;
}
filesize += (off_t)n;
} while (filesize < buf.st_size);
}
if (fd > 0) close(fd);
if (filemode != REGULAR) {
filesize = 0L;
}
if (fname != NULL) {
switch (filemode) {
case NEW:
sprintf(string, "\"%s\" [New File]", fname);
break;
case REGULAR:
sprintf(string, "\"%s\" %s%lu bytes", fname,
P(P_RO) ? "[Read only] " : "", (long)filesize);
break;
case DIRECTORY:
sprintf(string, "\"%s\" Directory", fname);
break;
}
if (filemode != ERROR) msg(string);
}
pagepos = mem;
maxpos = (PTR)(mem + filesize);
loc = HEX;
x = AnzAdd; y = 0;
repaint();
return(filesize);
}
int
addfile(char *fname)
{
int fd;
off_t oldsize;
unsigned chunk, n;
if (stat(fname, &buf)) {
sysemsg(fname);
return 1;
}
if ((fd = open(fname, O_RDONLY)) == -1) {
sysemsg(fname);
return 1;
}
oldsize = filesize;
if (enlarge(buf.st_size)) return 1;
chunk = buf.st_size > 0xfffe ? 0xfffe : buf.st_size;
do {
if ((n = read(fd, mem + filesize, chunk)) == 0xffff) {
sysemsg(fname);
filemode = ERROR;
return 1;
}
filesize += (off_t)n;
} while (filesize < buf.st_size);
maxpos = mem + filesize;
close(fd);
setpage(mem + oldsize);
return 0;
}
void
bvi_init(char *dir)
{
char *poi;
char *initstr;
char rcpath[255];
shell = getenv("COMSPEC");
if (shell == NULL || *shell == '\0')
shell = "COMMAND.COM";
strcpy(rcpath, dir);
poi = strrchr(rcpath, '\\');
*poi = '\0';
strcat(rcpath, "\\BVI.RC");
if ((initstr = getenv("BVIINIT")) != NULL) {
docmdline(initstr);
}
read_rc("BVI.RC");
read_rc(rcpath);
}
int
enlarge(off_t add)
{
PTR newmem;
off_t savecur, savepag, savemax, saveundo;
savecur = curpos - mem;
savepag = pagepos - mem;
savemax = maxpos - mem;
saveundo = undo_start - mem;
newmem = (PTR)farrealloc(mem, memsize + add);
if (newmem == NULL) {
emsg("Out of memory");
return 1;
}
mem = newmem;
memsize += add;
curpos = mem + savecur;
pagepos = mem + savepag;
maxpos = mem + savemax;
undo_start = mem + saveundo;
current = curpos + 1;
return 0;
}
void
do_shell()
{
system("");
}
off_t
alloc_buf(off_t n, char **buffer)
{
if ((*buffer = (char *)farrealloc(*buffer, n)) == NULL) {
emsg("No buffer space available");
return 0L;
}
return n;
}
void
d_memmove(PTR dest, PTR src, off_t n)
{
unsigned len;
long chunk;
PTR source;
PTR destin;
chunk = n;
if (dest < src) {
/* copy forward */
source = src;
destin = dest;
while (chunk > 0L) {
len = chunk > 0x7ffe ? 0x7ffe : chunk;
movmem(source, destin, len);
chunk -= len;
source += len;
destin += len;
}
} else {
/* copy backward */
source = src + n;
destin = dest + n;
while (chunk > 0L) {
len = chunk > 0x7ffe ? 0x7ffe : chunk;
chunk -= len;
source -= len;
destin -= len;
movmem(source, destin, len);
}
}
}
void
d_memcpy(PTR dest, PTR src, off_t n)
{
unsigned len;
long chunk;
PTR source;
PTR destin;
source = src;
destin = dest;
chunk = n;
while (chunk > 0L) {
len = chunk > 0x7ffe ? 0x7ffe : chunk;
movmem(source, destin, len);
chunk -= len;
source += len;
destin += len;
}
}