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

View file

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

View file

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

296
doscur.h
View file

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

928
dosio.c
View file

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