📄 ovview.c
字号:
/* 034 23-May-87 ovview.c
Copyright (c) 1987 by Blue Sky Software. All rights reserved.
*/
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "ov.h"
#include "overr.h"
#include "menu.h"
#include "direct.h"
#include "strmem.h"
#define H_bar (0xcd)
#define V_bar (179)
#define FSTR_LEN (40) /* max find str length */
#define Vnextch(fh) ((curp < endp) ? *curp++ : vnextch(fh)) /* speed up */
#define Vprevch(fh) ((curp > bufp) ? *--curp : vprevch(fh)) /* buffer access */
extern unsigned char far *curp; /* current char position */
extern unsigned char far *bufp, far *endp; /* buffer begin/end pointers */
static int (*mark_func)(); /* pointer to marker function */
static int nlines; /* # lines displayed on screen */
static unsigned char ascmode; /* true means ascii mode display */
static unsigned char bitmask; /* for 7 or 8 bit display mode */
static int inf; /* handle for file being viewed */
static int margin; /* margin for right/left scrolling */
static long tos; /* top of screen offset in file */
static long markers[5]; /* marker positions */
static char *findstr = NULL; /* string to find in view */
static long findloc; /* offset of last find */
static long hiline; /* offset of highlighted line */
static int igncase = 1; /* NZ if ignoring case in find */
/* function delcarations created by -Zg option - ALTCALL added
NOTE: anything called by menu routine cannot be ALTCALL */
void vfind(int);
static int view_prev(void), view_tof(void), view_eof(void);
int view(void), view_move(int), view_fignore(void), view_fexact(void);
static int view_exit(void), view_down(void), view_up(void), view_next(void);
static int view_right(void), view_left(void), view_set(void), view_goto(void);
static int view_fnxt(void), view_fprv(void), view_fstr(void), view_fopt(void);
static int do_mark(void), setmark(void), gomark(void), ALTCALL view_line(void);
static int view_7bit(void), view_8bit(void), view_asc(void), view_hex(void);
static int ALTCALL nsol(void), ALTCALL more2view(void);
static int ALTCALL align(void), ALTCALL backup(int), ALTCALL peol(void);
static int ALTCALL fmt_asc_line(char *,int *), ALTCALL fmt_hex_line(char *,int *);
static struct key_ent { /* table mapping movement keys to functions */
int key;
int (*func)();
} key2func[] = { { DOWN, view_next }, { UP, view_prev }, { PGDN, view_down },
{ PGUP, view_up }, { HOME, view_tof }, { END, view_eof },
{ RIGHT, view_right }, { LEFT, view_left } };
#define NMOVKEYS (8)
extern MENU_STATE curmenu;
extern MENU top_file_menu[], *top_menu;
static char setgo[] = "Set/Goto marker";
static MENU fopt_menu[] = {
{ "Ignore", "Ignore case when searching", view_fignore, NULL },
{ "Exact", "Match case of string when searching", view_fexact, NULL },
{ NULL, NULL, NULL, NULL }
};
static MENU find_menu[] = {
{ "Next", "Find next occurance", view_fnxt, NULL },
{ "Prev", "Find previous occurance", view_fprv, NULL },
{ "String", "Set string to find", view_fstr, NULL },
{ "Options", "Set find options", NULL, fopt_menu },
{ NULL, NULL, NULL, NULL }
};
static MENU mark_menu[] = {
{ "1", setgo, do_mark, NULL },
{ "2", setgo, do_mark, NULL },
{ "3", setgo, do_mark, NULL },
{ "4", setgo, do_mark, NULL },
{ "5", setgo, do_mark, NULL },
{ NULL, NULL, NULL, NULL }
};
MENU top_view_menu[] = {
{ "Dwn", "Page down in the file", view_down, NULL },
{ "Up", "Page up in the file", view_up, NULL },
{ "Nxt", "Advance one line", view_next, NULL },
{ "Prv", "Backup one line", view_prev, NULL },
{ "Rght", "Scroll right 8 characters", view_right, NULL },
{ "Left", "Scroll left 8 characters", view_left, NULL },
{ "TOF", "Goto Top Of File", view_tof, NULL },
{ "EOF", "Goto End Of File", view_eof, NULL },
{ "Set", "Set marker at current position", view_set, mark_menu },
{ "Goto", "Goto set marker position", view_goto, mark_menu },
{ "Find", "Find string", NULL, find_menu },
{ "Asc", "Display file in ASCII", view_asc, NULL },
{ "Hex", "Display file in hex", view_hex, NULL },
{ "7b", "Display 7 bits per character", view_7bit, NULL },
{ "8b", "Display 8 bits per character", view_8bit, NULL },
{ "Quit", "Return to file display", view_exit, top_file_menu },
{ NULL, NULL, NULL, NULL }
};
extern WINDOW cw;
extern char *cantopen;
extern FILE_ENT files[];
extern unsigned char view_display, restricted;
int ALTCALL vbuf_init(int ); /* declarations for buffer routines */
int ALTCALL vbuf_free(void);
unsigned long ALTCALL vtell(void);
int ALTCALL vseek(int ,long ), ALTCALL vnextch(int ), ALTCALL vprevch(int );
#define view_seek(off) vseek(inf,off)
/******************************************************************************
** V I E W **
*****************************************************************************/
view() { /* view the current file at the terminal */
int i;
register char *fn;
register FILE_ENT *fp;
/* don't try to view file if its empty */
fp = &files[cw.curidx]; /* a couple of quick pointers */
if (fp->size == 0)
show_error(0,EMPTY_FILE,1,"This file is empty!");
bitmask = 0xff; /* defaults: 8 bit, ascii, left edge */
ascmode = TRUE;
margin = 0;
/* open the file to be viewed, error out if can't open */
if ((inf = open((fn = fname(fp)),O_RDONLY|O_BINARY)) == -1) {
free(fn);
show_error(SHOW_DOS,CANT_OPEN,3,cantopen,fp->name,": ");
}
savescreen(); /* save current display image */
restricted = TRUE; /* disable special file commands */
view_display = TRUE; /* yes, we are viewing */
for (i = 0; i < 5; i++) /* set markers to TOF */
markers[i] = 0L;
hiline = findloc = -1L; /* indicate no finds/no highlighted lines yet */
vbuf_init(inf); /* initialize view buffer system */
center_text(FIRST_VROW-1,fn); /* show file name */
free(fn);
view_down(); /* display the first screen of file data */
top_menu = top_view_menu; /* setup the view menu as the main menu */
}
/******************************************************************************
** V I E W _ E X I T **
*****************************************************************************/
static int
view_exit() { /* exit the view display, return to file display */
close(inf); /* close file */
vbuf_free(); /* release memory */
top_menu = top_file_menu; /* restore file menu as main */
restricted = FALSE; /* all commands are enabled */
view_display = FALSE; /* not viewing */
restorescreen(); /* redisplay prior screen image */
}
/******************************************************************************
** V I E W _ D O W N **
*****************************************************************************/
static int
view_down() { /* page down into the view buffer/file */
register int i;
if (!more2view()) /* nothing to do if no more data to view */
return;
nlines = 0; /* no lines displayed yet */
tos = vtell(); /* remember where top of screen is */
/* display up to a screen full of file data, clear the screen as we go */
for (i = 0; i < VIEW_ROWS; i++) {
gotorc(i+FIRST_VROW,0); /* position to line */
if (view_line()) /* display a single line */
nlines++; /* count lines displayed */
}
}
/******************************************************************************
** V I E W _ U P **
*****************************************************************************/
static int
view_up() { /* page up into the view buffer */
long curoff;
/* back two screen's worth, or to the top line in memory and use
view_down() to display the screen - only display if we really
backed up (might be at TOF) */
curoff = vtell(); /* where we were */
view_seek(tos); /* quickly to top of screen */
if (backup(VIEW_ROWS)) /* try to backup another screen */
view_down(); /* display prior screen if backed up */
else
view_seek(curoff); /* must be tof, back to where we were */
}
/******************************************************************************
** V I E W _ N E X T **
*****************************************************************************/
static int
view_next() { /* display the next line in the buffer/file */
long curoff;
if (!more2view()) /* nothing to do if no more data to view */
return;
/* set the new top of screen location */
if (ascmode) { /* ascii mode display? */
curoff = vtell(); /* save where we are */
view_seek(tos); /* to top of screen */
nsol(); /* to start of next line */
tos = vtell(); /* its the new top of screen */
view_seek(curoff); /* back to bottom of screen */
} else /* hex mode */
tos += 16; /* tos is just the next hex line */
/* scroll the screen up one line to make room for the new line at bottom */
delete_line(FIRST_VROW,VIEW_ROWS-1);
gotorc(FIRST_VROW+VIEW_ROWS-1,0); /* cursor to the last display line */
view_line(); /* display the line */
}
/******************************************************************************
** V I E W _ P R E V **
*****************************************************************************/
static int
view_prev() { /* display the previous line in the buffer */
long curoff;
curoff = vtell(); /* where we are now */
view_seek(tos); /* old top of screen */
if (backup(1)) { /* can we backup another line */
tos = vtell(); /* if so, its new tos */
insert_line(FIRST_VROW+1,VIEW_ROWS-1); /* insert a blank line */
gotorc(FIRST_VROW,0); /* cursor to first line */
view_line(); /* display the line */
view_seek(curoff); /* back to old bottom */
if (nlines < VIEW_ROWS) /* is a full screen displayed? */
nlines++; /* no, one more displyed now */
else
backup(1); /* yes, back one line */
} else /* couldn't backup, must be tof */
view_seek(curoff);
}
/******************************************************************************
** V I E W _ T O F **
*****************************************************************************/
static int
view_tof() { /* backup and display the top of the file */
view_seek(0L); /* just go to top of file */
view_down(); /* and display a screen */
}
/******************************************************************************
** V I E W _ E O F **
*****************************************************************************/
static int
view_eof() { /* display the end of the file */
view_seek(files[cw.curidx].size); /* seek to eof */
backup(VIEW_ROWS); /* backup a screen full */
view_down(); /* display a screen full */
}
/******************************************************************************
** V I E W _ M O V E **
*****************************************************************************/
view_move(mov_cmd) /* move around the view buffer/file in response to */
int mov_cmd; /* single key commands when viewing a file */
{
register int i;
/* basically, we just map the special keys to the same functions
performed by the menu options */
for (i = 0; i < NMOVKEYS; i++)
if (mov_cmd == key2func[i].key) {
(*key2func[i].func)();
break;
}
}
/*****************************************************************************
V I E W _ S E T / G O T O / M A R K
*****************************************************************************/
static int
view_set() { /* prepare to set a marker to current position */
mark_func = setmark; /* use the setmark routine later */
}
static int
view_goto() { /* prepare to goto a marker position */
mark_func = gomark; /* use the gomark routine later */
}
static int
do_mark() { /* set or goto a marker position */
(*mark_func)();
}
static int
setmark() { /* set a marker position */
markers[curmenu.current_selection] = tos;
}
static int
gomark() { /* goto a marker position */
tos = markers[curmenu.current_selection]; /* where tos should be */
align(); /* start at begining of line */
view_down(); /* display screen full */
}
/*****************************************************************************
V I E W _ F N X T / P R V / I G N O R E / E X A C T
*****************************************************************************/
static int
view_fnxt() { /* find the string in forward direction */
vfind(1); /* 1 means search forward */
}
static int /* find the string in backward direction */
view_fprv() {
vfind(0); /* 0 means search backward */
}
static int /* ignore case */
view_fignore() {
igncase = 1;
}
static int /* require exact case match */
view_fexact() {
igncase = 0;
}
/**************************************************************************
V F I N D
**************************************************************************/
void
vfind(forward) /* find a string in selected direction */
register int forward;
{
int fch;
long temploc;
register int ch;
char *fcp, nfmsg[11+FSTR_LEN];
if (findstr == NULL)
show_error(0,NO_FND_STR,1,"No find string has been selected");
/* pick where to start the search from - if this is the first find or the
last find location isn't currently displayed, start from the tos (if
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -