mined: built without UNIX defined.
* Remove undef NULL, EOF, getchar, putchar * Rename putchar, getchar, _putchar, _getchar to putch, getch, _putch, _getch to avoid conflict with libc functions. * Rename UP() to UP1() (for UP 1 line) to avoid conflict with UP definition in termcap.h. Rename DN1 LF1 RT1 for consistency. * Add termcap.h for prototypes for tputs and friends. * Add libterminfo references to Makefile * Add return value to _putch() to make it work as tputs expects. * Make putch() call _putch() * Remove UNIX ifdefs and all code in the !UNIX branches. closes #43 Change-Id: I0a6f7298aa8b12a74225badc88d3c236a02669ea
This commit is contained in:
parent
fc850d580c
commit
e978660932
4 changed files with 85 additions and 210 deletions
|
@ -3,4 +3,9 @@
|
||||||
PROG= mined
|
PROG= mined
|
||||||
SRCS= mined1.c mined2.c
|
SRCS= mined1.c mined2.c
|
||||||
|
|
||||||
|
CPPFLAGS+= -I${.CURDIR}/../../../lib/libterminfo
|
||||||
|
|
||||||
|
DPADD+= ${LIBTERMINFO}
|
||||||
|
LDADD+= -lterminfo
|
||||||
|
|
||||||
.include <bsd.prog.mk>
|
.include <bsd.prog.mk>
|
||||||
|
|
|
@ -6,30 +6,13 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <termcap.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#ifndef YMAX
|
|
||||||
#ifdef UNIX
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#undef putchar
|
|
||||||
#undef getchar
|
|
||||||
#undef NULL
|
|
||||||
#undef EOF
|
|
||||||
extern char *CE, *VS, *SO, *SE, *CL, *AL, *CM;
|
|
||||||
#define YMAX 49
|
|
||||||
#else
|
|
||||||
#define YMAX 24 /* Maximum y coordinate starting at 0 */
|
|
||||||
/* Escape sequences. */
|
|
||||||
extern char *enter_string; /* String printed on entering mined */
|
|
||||||
extern char *rev_video; /* String for starting reverse video */
|
|
||||||
extern char *normal_video; /* String for leaving reverse video */
|
|
||||||
extern char *rev_scroll; /* String for reverse scrolling */
|
|
||||||
extern char *pos_string; /* Absolute cursor positioning */
|
|
||||||
#define X_PLUS ' ' /* To be added to x for cursor sequence */
|
|
||||||
#define Y_PLUS ' ' /* To be added to y for cursor sequence */
|
|
||||||
#endif /* UNIX */
|
|
||||||
|
|
||||||
|
extern char *CE, *VS, *SO, *SE, *CL, *AL, *CM;
|
||||||
|
#define YMAX 49 /* Maximum y coordinate starting at 0 */
|
||||||
#define XMAX 79 /* Maximum x coordinate starting at 0*/
|
#define XMAX 79 /* Maximum x coordinate starting at 0*/
|
||||||
#define SCREENMAX (YMAX - 1) /* Number of lines displayed */
|
#define SCREENMAX (YMAX - 1) /* Number of lines displayed */
|
||||||
#define XBREAK (XMAX - 0) /* Line shift at this coordinate */
|
#define XBREAK (XMAX - 0) /* Line shift at this coordinate */
|
||||||
|
@ -163,12 +146,12 @@ extern long chars_saved; /* Nr of chars saved in buffer */
|
||||||
/*
|
/*
|
||||||
* Print character on terminal
|
* Print character on terminal
|
||||||
*/
|
*/
|
||||||
#define putchar(c) (void) write_char(STD_OUT, (c))
|
#define putch(c) _putch((c))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ring bell on terminal
|
* Ring bell on terminal
|
||||||
*/
|
*/
|
||||||
#define ring_bell() putchar('\07')
|
#define ring_bell() putch('\07')
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print string on terminal
|
* Print string on terminal
|
||||||
|
@ -229,8 +212,6 @@ extern long chars_saved; /* Nr of chars saved in buffer */
|
||||||
*/
|
*/
|
||||||
#define get_shift(cnt) ((cnt) & DUMMY_MASK)
|
#define get_shift(cnt) ((cnt) & DUMMY_MASK)
|
||||||
|
|
||||||
#endif /* YMAX */
|
|
||||||
|
|
||||||
/* mined1.c */
|
/* mined1.c */
|
||||||
|
|
||||||
void FS(void);
|
void FS(void);
|
||||||
|
@ -250,7 +231,7 @@ void copy_string(char *to, char *from );
|
||||||
void reset(LINE *head_line, int screen_y );
|
void reset(LINE *head_line, int screen_y );
|
||||||
void set_cursor(int nx, int ny );
|
void set_cursor(int nx, int ny );
|
||||||
void open_device(void);
|
void open_device(void);
|
||||||
int getchar(void);
|
int getch(void);
|
||||||
void display(int x_coord, int y_coord, LINE *line, int count );
|
void display(int x_coord, int y_coord, LINE *line, int count );
|
||||||
int write_char(int fd, int c );
|
int write_char(int fd, int c );
|
||||||
int writeline(int fd, char *text );
|
int writeline(int fd, char *text );
|
||||||
|
@ -263,13 +244,6 @@ void raw_mode(FLAG state );
|
||||||
void panic(char *message );
|
void panic(char *message );
|
||||||
char *alloc(int bytes );
|
char *alloc(int bytes );
|
||||||
void free_space(char *p );
|
void free_space(char *p );
|
||||||
/*
|
|
||||||
#ifdef UNIX
|
|
||||||
void(*key_map [128]) (void);
|
|
||||||
#else
|
|
||||||
void(*key_map [256]) (void);
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
void initialize(void);
|
void initialize(void);
|
||||||
char *basename(char *path );
|
char *basename(char *path );
|
||||||
void load_file(char *file );
|
void load_file(char *file );
|
||||||
|
@ -293,17 +267,17 @@ char *num_out(long number );
|
||||||
int get_number(char *message, int *result );
|
int get_number(char *message, int *result );
|
||||||
int input(char *inbuf, FLAG clearfl );
|
int input(char *inbuf, FLAG clearfl );
|
||||||
int get_file(char *message, char *file );
|
int get_file(char *message, char *file );
|
||||||
int _getchar(void);
|
int _getch(void);
|
||||||
void _flush(void);
|
void _flush(void);
|
||||||
void _putchar(int c );
|
int _putch(int c );
|
||||||
void get_term(void);
|
void get_term(void);
|
||||||
|
|
||||||
/* mined2.c */
|
/* mined2.c */
|
||||||
|
|
||||||
void UP(void);
|
void UP1(void);
|
||||||
void DN(void);
|
void DN1(void);
|
||||||
void LF(void);
|
void LF1(void);
|
||||||
void RT(void);
|
void RT1(void);
|
||||||
void HIGH(void);
|
void HIGH(void);
|
||||||
void LOW(void);
|
void LOW(void);
|
||||||
void BL(void);
|
void BL(void);
|
||||||
|
|
|
@ -153,7 +153,7 @@
|
||||||
* 3.3 Moving around.
|
* 3.3 Moving around.
|
||||||
*
|
*
|
||||||
* Several commands are implemented for moving through the file.
|
* Several commands are implemented for moving through the file.
|
||||||
* Moving up (UP), down (DN) left (LF) and right (RT) are done by the
|
* Moving up (UP1), down (DN1) left (LF1) and right (RT1) are done by the
|
||||||
* arrow keys. Moving one line below the screen scrolls the screen one
|
* arrow keys. Moving one line below the screen scrolls the screen one
|
||||||
* line up. Moving one line above the screen scrolls the screen one line
|
* line up. Moving one line above the screen scrolls the screen one line
|
||||||
* down. The functions forward_scroll () and reverse_scroll () take care
|
* down. The functions forward_scroll () and reverse_scroll () take care
|
||||||
|
@ -304,7 +304,7 @@
|
||||||
* string). The functions status_line (string1, string2), error (string1,
|
* string). The functions status_line (string1, string2), error (string1,
|
||||||
* string2), clear_status () and bottom_line () all print information on
|
* string2), clear_status () and bottom_line () all print information on
|
||||||
* the status line.
|
* the status line.
|
||||||
* Get_string (message, buffer) reads a string and getchar () reads one
|
* Get_string (message, buffer) reads a string and getch () reads one
|
||||||
* character from the terminal.
|
* character from the terminal.
|
||||||
* Num_out ((long) number) prints the number into a 11 digit field
|
* Num_out ((long) number) prints the number into a 11 digit field
|
||||||
* without leading zero's. It returns a pointer to the resulting string.
|
* without leading zero's. It returns a pointer to the resulting string.
|
||||||
|
@ -314,7 +314,7 @@
|
||||||
* Output is done by four functions: writeline(fd,string), clear_buffer()
|
* Output is done by four functions: writeline(fd,string), clear_buffer()
|
||||||
* write_char (fd, c) and flush_buffer (fd). Three defines are provided
|
* write_char (fd, c) and flush_buffer (fd). Three defines are provided
|
||||||
* to write on filedescriptor STD_OUT (terminal) which is used normally:
|
* to write on filedescriptor STD_OUT (terminal) which is used normally:
|
||||||
* string_print (string), putchar (c) and flush (). All these functions
|
* string_print (string), putch (c) and flush (). All these functions
|
||||||
* use the global I/O buffer screen and the global index for this array
|
* use the global I/O buffer screen and the global index for this array
|
||||||
* called out_count. In this way I/O can be buffered, so that reads or
|
* called out_count. In this way I/O can be buffered, so that reads or
|
||||||
* writes can be done in blocks of SCREEN_SIZE size.
|
* writes can be done in blocks of SCREEN_SIZE size.
|
||||||
|
@ -447,11 +447,7 @@ void VI(void)
|
||||||
|
|
||||||
/* Free old linked list, initialize global variables and load new file */
|
/* Free old linked list, initialize global variables and load new file */
|
||||||
initialize();
|
initialize();
|
||||||
#ifdef UNIX
|
tputs(CL, 0, _putch);
|
||||||
tputs(CL, 0, _putchar);
|
|
||||||
#else
|
|
||||||
string_print (enter_string);
|
|
||||||
#endif /* UNIX */
|
|
||||||
load_file(new_file[0] == '\0' ? NULL : new_file);
|
load_file(new_file[0] == '\0' ? NULL : new_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -540,7 +536,7 @@ void SH(void)
|
||||||
return;
|
return;
|
||||||
case 0: /* This is the child */
|
case 0: /* This is the child */
|
||||||
set_cursor(0, ymax);
|
set_cursor(0, ymax);
|
||||||
putchar('\n');
|
putch('\n');
|
||||||
flush();
|
flush();
|
||||||
raw_mode(OFF);
|
raw_mode(OFF);
|
||||||
if (rpipe) { /* Fix stdin */
|
if (rpipe) { /* Fix stdin */
|
||||||
|
@ -608,11 +604,7 @@ int bottom_line(FLAG revfl, char *s1, char *s2, char *inbuf, FLAG statfl)
|
||||||
clear_status ();
|
clear_status ();
|
||||||
set_cursor(0, ymax);
|
set_cursor(0, ymax);
|
||||||
if (revfl == ON) { /* Print rev. start sequence */
|
if (revfl == ON) { /* Print rev. start sequence */
|
||||||
#ifdef UNIX
|
tputs(SO, 0, _putch);
|
||||||
tputs(SO, 0, _putchar);
|
|
||||||
#else
|
|
||||||
string_print(rev_video);
|
|
||||||
#endif /* UNIX */
|
|
||||||
stat_visible = TRUE;
|
stat_visible = TRUE;
|
||||||
}
|
}
|
||||||
else /* Used as clear_status() */
|
else /* Used as clear_status() */
|
||||||
|
@ -624,13 +616,8 @@ int bottom_line(FLAG revfl, char *s1, char *s2, char *inbuf, FLAG statfl)
|
||||||
ret = input(inbuf, statfl);
|
ret = input(inbuf, statfl);
|
||||||
|
|
||||||
/* Print normal video */
|
/* Print normal video */
|
||||||
#ifdef UNIX
|
tputs(SE, 0, _putch);
|
||||||
tputs(SE, 0, _putchar);
|
tputs(CE, 0, _putch); /* Clear the rest of the line */
|
||||||
tputs(CE, 0, _putchar);
|
|
||||||
#else
|
|
||||||
string_print(normal_video);
|
|
||||||
string_print(blank_line); /* Clear the rest of the line */
|
|
||||||
#endif /* UNIX */
|
|
||||||
if (inbuf != NULL)
|
if (inbuf != NULL)
|
||||||
set_cursor(0, ymax);
|
set_cursor(0, ymax);
|
||||||
else
|
else
|
||||||
|
@ -834,16 +821,7 @@ void reset(LINE *head_line, int screen_y)
|
||||||
*/
|
*/
|
||||||
void set_cursor(int nx, int ny)
|
void set_cursor(int nx, int ny)
|
||||||
{
|
{
|
||||||
#ifdef UNIX
|
tputs(tgoto(CM, nx, ny), 0, _putch);
|
||||||
extern char *tgoto();
|
|
||||||
|
|
||||||
tputs(tgoto(CM, nx, ny), 0, _putchar);
|
|
||||||
#else
|
|
||||||
char text_buffer[10];
|
|
||||||
|
|
||||||
build_string(text_buffer, pos_string, ny+1, nx+1);
|
|
||||||
string_print(text_buffer);
|
|
||||||
#endif /* UNIX */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -859,18 +837,9 @@ void open_device(void)
|
||||||
* Getchar() reads one character from the terminal. The character must be
|
* Getchar() reads one character from the terminal. The character must be
|
||||||
* masked with 0377 to avoid sign extension.
|
* masked with 0377 to avoid sign extension.
|
||||||
*/
|
*/
|
||||||
int getchar(void)
|
int getch(void)
|
||||||
{
|
{
|
||||||
#ifdef UNIX
|
return (_getch() & 0377);
|
||||||
return (_getchar() & 0377);
|
|
||||||
#else
|
|
||||||
char c;
|
|
||||||
|
|
||||||
if (read(input_fd, &c, 1) != 1 && quit == FALSE)
|
|
||||||
panic("Can't read one char from fd #0");
|
|
||||||
|
|
||||||
return c & 0377;
|
|
||||||
#endif /* UNIX */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -898,12 +867,8 @@ void display(int x_coord, int y_coord, register LINE *line, register int count)
|
||||||
/* Print the blank lines (if any) */
|
/* Print the blank lines (if any) */
|
||||||
if (loading == FALSE) {
|
if (loading == FALSE) {
|
||||||
while (count-- >= 0) {
|
while (count-- >= 0) {
|
||||||
#ifdef UNIX
|
tputs(CE, 0, _putch);
|
||||||
tputs(CE, 0, _putchar);
|
putch('\n');
|
||||||
#else
|
|
||||||
string_print(blank_line);
|
|
||||||
#endif /* UNIX */
|
|
||||||
putchar('\n');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -955,42 +920,30 @@ void put_line(LINE *line, int offset, FLAG clear_line)
|
||||||
tab_count = tab(count);
|
tab_count = tab(count);
|
||||||
while (count < XBREAK && count < tab_count) {
|
while (count < XBREAK && count < tab_count) {
|
||||||
count++;
|
count++;
|
||||||
putchar(' ');
|
putch(' ');
|
||||||
}
|
}
|
||||||
textp++;
|
textp++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (*textp >= '\01' && *textp <= '\037') {
|
if (*textp >= '\01' && *textp <= '\037') {
|
||||||
#ifdef UNIX
|
tputs(SO, 0, _putch);
|
||||||
tputs(SO, 0, _putchar);
|
putch(*textp++ + '\100');
|
||||||
#else
|
tputs(SE, 0, _putch);
|
||||||
string_print (rev_video);
|
|
||||||
#endif /* UNIX */
|
|
||||||
putchar(*textp++ + '\100');
|
|
||||||
#ifdef UNIX
|
|
||||||
tputs(SE, 0, _putchar);
|
|
||||||
#else
|
|
||||||
string_print (normal_video);
|
|
||||||
#endif /* UNIX */
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
putchar(*textp++);
|
putch(*textp++);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If line is longer than XBREAK chars, print the shift_mark */
|
/* If line is longer than XBREAK chars, print the shift_mark */
|
||||||
if (count == XBREAK && *textp != '\n')
|
if (count == XBREAK && *textp != '\n')
|
||||||
putchar(textp[1]=='\n' ? *textp : SHIFT_MARK);
|
putch(textp[1]=='\n' ? *textp : SHIFT_MARK);
|
||||||
|
|
||||||
/* Clear the rest of the line is clear_line is TRUE */
|
/* Clear the rest of the line is clear_line is TRUE */
|
||||||
if (clear_line == TRUE) {
|
if (clear_line == TRUE) {
|
||||||
#ifdef UNIX
|
tputs(CE, 0, _putch);
|
||||||
tputs(CE, 0, _putchar);
|
putch('\n');
|
||||||
#else
|
|
||||||
string_print(blank_line);
|
|
||||||
#endif /* UNIX */
|
|
||||||
putchar('\n');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1001,14 +954,11 @@ int flush_buffer(int fd)
|
||||||
{
|
{
|
||||||
if (out_count <= 0) /* There is nothing to flush */
|
if (out_count <= 0) /* There is nothing to flush */
|
||||||
return FINE;
|
return FINE;
|
||||||
#ifdef UNIX
|
|
||||||
if (fd == STD_OUT) {
|
if (fd == STD_OUT) {
|
||||||
printf("%.*s", out_count, screen);
|
printf("%.*s", out_count, screen);
|
||||||
_flush();
|
_flush();
|
||||||
}
|
}
|
||||||
else
|
else if (write(fd, screen, out_count) != out_count) {
|
||||||
#endif /* UNIX */
|
|
||||||
if (write(fd, screen, out_count) != out_count) {
|
|
||||||
bad_write(fd);
|
bad_write(fd);
|
||||||
return ERRORS;
|
return ERRORS;
|
||||||
}
|
}
|
||||||
|
@ -1050,7 +1000,7 @@ void abort_mined(void)
|
||||||
|
|
||||||
/* Ask for confirmation */
|
/* Ask for confirmation */
|
||||||
status_line("Really abort? ", NULL);
|
status_line("Really abort? ", NULL);
|
||||||
if (getchar() != 'y') {
|
if (getch() != 'y') {
|
||||||
clear_status();
|
clear_status();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1058,13 +1008,9 @@ void abort_mined(void)
|
||||||
/* Reset terminal */
|
/* Reset terminal */
|
||||||
raw_mode(OFF);
|
raw_mode(OFF);
|
||||||
set_cursor(0, ymax);
|
set_cursor(0, ymax);
|
||||||
putchar('\n');
|
putch('\n');
|
||||||
flush();
|
flush();
|
||||||
#ifdef UNIX
|
|
||||||
abort();
|
abort();
|
||||||
#else
|
|
||||||
exit(1);
|
|
||||||
#endif /* UNIX */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define UNDEF _POSIX_VDISABLE
|
#define UNDEF _POSIX_VDISABLE
|
||||||
|
@ -1109,12 +1055,8 @@ void panic(register char *message)
|
||||||
{
|
{
|
||||||
extern char yank_file[];
|
extern char yank_file[];
|
||||||
|
|
||||||
#ifdef UNIX
|
tputs(CL, 0, _putch);
|
||||||
tputs(CL, 0, _putchar);
|
|
||||||
build_string(text_buffer, "%s\nError code %d\n", message, errno);
|
build_string(text_buffer, "%s\nError code %d\n", message, errno);
|
||||||
#else
|
|
||||||
build_string(text_buffer, "%s%s\nError code %d\n", enter_string, message, errno);
|
|
||||||
#endif /* UNIX */
|
|
||||||
(void) write(STD_OUT, text_buffer, length_of(text_buffer));
|
(void) write(STD_OUT, text_buffer, length_of(text_buffer));
|
||||||
|
|
||||||
if (loading == FALSE)
|
if (loading == FALSE)
|
||||||
|
@ -1123,11 +1065,7 @@ void panic(register char *message)
|
||||||
(void) unlink(yank_file);
|
(void) unlink(yank_file);
|
||||||
raw_mode(OFF);
|
raw_mode(OFF);
|
||||||
|
|
||||||
#ifdef UNIX
|
|
||||||
abort();
|
abort();
|
||||||
#else
|
|
||||||
exit(1);
|
|
||||||
#endif /* UNIX */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *alloc(int bytes)
|
char *alloc(int bytes)
|
||||||
|
@ -1197,16 +1135,7 @@ char file_name[LINE_LEN]; /* Name of file in use */
|
||||||
char text_buffer[MAX_CHARS]; /* Buffer for modifying text */
|
char text_buffer[MAX_CHARS]; /* Buffer for modifying text */
|
||||||
|
|
||||||
/* Escape sequences. */
|
/* Escape sequences. */
|
||||||
#ifdef UNIX
|
|
||||||
char *CE, *VS, *SO, *SE, *CL, *AL, *CM;
|
char *CE, *VS, *SO, *SE, *CL, *AL, *CM;
|
||||||
#else
|
|
||||||
char *enter_string = "\033[H\033[J"; /* String printed on entering mined */
|
|
||||||
char *pos_string = "\033[%d;%dH"; /* Absolute cursor position */
|
|
||||||
char *rev_scroll = "\033M"; /* String for reverse scrolling */
|
|
||||||
char *rev_video = "\033[7m"; /* String for starting reverse video */
|
|
||||||
char *normal_video = "\033[m"; /* String for leaving reverse video */
|
|
||||||
char *blank_line = "\033[K"; /* Clear line to end */
|
|
||||||
#endif /* UNIX */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Yank variables.
|
* Yank variables.
|
||||||
|
@ -1385,13 +1314,9 @@ int main(int argc, char *argv[])
|
||||||
register int index; /* Index in key table */
|
register int index; /* Index in key table */
|
||||||
struct winsize winsize;
|
struct winsize winsize;
|
||||||
|
|
||||||
#ifdef UNIX
|
|
||||||
get_term();
|
get_term();
|
||||||
tputs(VS, 0, _putchar);
|
tputs(VS, 0, _putch);
|
||||||
tputs(CL, 0, _putchar);
|
tputs(CL, 0, _putch);
|
||||||
#else
|
|
||||||
string_print(enter_string); /* Hello world */
|
|
||||||
#endif /* UNIX */
|
|
||||||
if (ioctl(STD_OUT, TIOCGWINSZ, &winsize) == 0 && winsize.ws_row != 0) {
|
if (ioctl(STD_OUT, TIOCGWINSZ, &winsize) == 0 && winsize.ws_row != 0) {
|
||||||
ymax = winsize.ws_row - 1;
|
ymax = winsize.ws_row - 1;
|
||||||
screenmax = ymax - 1;
|
screenmax = ymax - 1;
|
||||||
|
@ -1423,7 +1348,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
/* Main loop of the editor. */
|
/* Main loop of the editor. */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
index = getchar();
|
index = getch();
|
||||||
if (stat_visible == TRUE)
|
if (stat_visible == TRUE)
|
||||||
clear_status();
|
clear_status();
|
||||||
if (quit == TRUE)
|
if (quit == TRUE)
|
||||||
|
@ -1448,23 +1373,15 @@ int main(int argc, char *argv[])
|
||||||
void RD(void)
|
void RD(void)
|
||||||
{
|
{
|
||||||
/* Clear screen */
|
/* Clear screen */
|
||||||
#ifdef UNIX
|
tputs(VS, 0, _putch);
|
||||||
tputs(VS, 0, _putchar);
|
tputs(CL, 0, _putch);
|
||||||
tputs(CL, 0, _putchar);
|
|
||||||
#else
|
|
||||||
string_print(enter_string);
|
|
||||||
#endif /* UNIX */
|
|
||||||
|
|
||||||
/* Print first page */
|
/* Print first page */
|
||||||
display(0, 0, top_line, last_y);
|
display(0, 0, top_line, last_y);
|
||||||
|
|
||||||
/* Clear last line */
|
/* Clear last line */
|
||||||
set_cursor(0, ymax);
|
set_cursor(0, ymax);
|
||||||
#ifdef UNIX
|
tputs(CE, 0, _putch);
|
||||||
tputs(CE, 0, _putchar);
|
|
||||||
#else
|
|
||||||
string_print(blank_line);
|
|
||||||
#endif /* UNIX */
|
|
||||||
move_to(x, y);
|
move_to(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1485,7 +1402,7 @@ void XT(void)
|
||||||
|
|
||||||
raw_mode(OFF);
|
raw_mode(OFF);
|
||||||
set_cursor(0, ymax);
|
set_cursor(0, ymax);
|
||||||
putchar('\n');
|
putch('\n');
|
||||||
flush();
|
flush();
|
||||||
(void) unlink(yank_file); /* Might not be necessary */
|
(void) unlink(yank_file); /* Might not be necessary */
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -1495,13 +1412,13 @@ void (*escfunc(int c))(void)
|
||||||
{
|
{
|
||||||
if (c == '[') {
|
if (c == '[') {
|
||||||
/* Start of ASCII escape sequence. */
|
/* Start of ASCII escape sequence. */
|
||||||
c = getchar();
|
c = getch();
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'H': return(HO);
|
case 'H': return(HO);
|
||||||
case 'A': return(UP);
|
case 'A': return(UP1);
|
||||||
case 'B': return(DN);
|
case 'B': return(DN1);
|
||||||
case 'C': return(RT);
|
case 'C': return(RT1);
|
||||||
case 'D': return(LF);
|
case 'D': return(LF1);
|
||||||
case '@': return(MA);
|
case '@': return(MA);
|
||||||
case 'G': return(FS);
|
case 'G': return(FS);
|
||||||
case 'S': return(SR);
|
case 'S': return(SR);
|
||||||
|
@ -1526,11 +1443,11 @@ void ESC(void)
|
||||||
register void (*func)();
|
register void (*func)();
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
index = getchar();
|
index = getch();
|
||||||
while (index >= '0' && index <= '9' && quit == FALSE) {
|
while (index >= '0' && index <= '9' && quit == FALSE) {
|
||||||
count *= 10;
|
count *= 10;
|
||||||
count += index - '0';
|
count += index - '0';
|
||||||
index = getchar();
|
index = getch();
|
||||||
}
|
}
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
count = 1;
|
count = 1;
|
||||||
|
@ -1538,7 +1455,7 @@ void ESC(void)
|
||||||
} else {
|
} else {
|
||||||
func = key_map[index];
|
func = key_map[index];
|
||||||
if (func == ESC)
|
if (func == ESC)
|
||||||
func = escfunc(getchar());
|
func = escfunc(getch());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (func == I) { /* Function assigned? */
|
if (func == I) { /* Function assigned? */
|
||||||
|
@ -1567,7 +1484,7 @@ int ask_save(void)
|
||||||
status_line(file_name[0] ? basename(file_name) : "[buffer]" ,
|
status_line(file_name[0] ? basename(file_name) : "[buffer]" ,
|
||||||
" has been modified. Save? (y/n)");
|
" has been modified. Save? (y/n)");
|
||||||
|
|
||||||
while((c = getchar()) != 'y' && c != 'n' && quit == FALSE) {
|
while((c = getch()) != 'y' && c != 'n' && quit == FALSE) {
|
||||||
ring_bell();
|
ring_bell();
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
@ -1723,7 +1640,7 @@ int get_number(char *message, int *result)
|
||||||
|
|
||||||
status_line(message, NULL);
|
status_line(message, NULL);
|
||||||
|
|
||||||
index = getchar();
|
index = getch();
|
||||||
if (quit == FALSE && (index < '0' || index > '9')) {
|
if (quit == FALSE && (index < '0' || index > '9')) {
|
||||||
error("Bad count", NULL);
|
error("Bad count", NULL);
|
||||||
return ERRORS;
|
return ERRORS;
|
||||||
|
@ -1733,7 +1650,7 @@ int get_number(char *message, int *result)
|
||||||
while (index >= '0' && index <= '9' && quit == FALSE) {
|
while (index >= '0' && index <= '9' && quit == FALSE) {
|
||||||
count *= 10;
|
count *= 10;
|
||||||
count += index - '0';
|
count += index - '0';
|
||||||
index = getchar();
|
index = getch();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (quit == TRUE) {
|
if (quit == TRUE) {
|
||||||
|
@ -1759,24 +1676,16 @@ int input(char *inbuf, FLAG clearfl)
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
while (quit == FALSE) {
|
while (quit == FALSE) {
|
||||||
flush();
|
flush();
|
||||||
switch (c = getchar()) {
|
switch (c = getch()) {
|
||||||
case '\b' : /* Erase previous char */
|
case '\b' : /* Erase previous char */
|
||||||
if (ptr > inbuf) {
|
if (ptr > inbuf) {
|
||||||
ptr--;
|
ptr--;
|
||||||
#ifdef UNIX
|
tputs(SE, 0, _putch);
|
||||||
tputs(SE, 0, _putchar);
|
|
||||||
#else
|
|
||||||
string_print(normal_video);
|
|
||||||
#endif /* UNIX */
|
|
||||||
if (is_tab(*ptr))
|
if (is_tab(*ptr))
|
||||||
string_print(" \b\b\b \b\b");
|
string_print(" \b\b\b \b\b");
|
||||||
else
|
else
|
||||||
string_print(" \b\b \b");
|
string_print(" \b\b \b");
|
||||||
#ifdef UNIX
|
tputs(SO, 0, _putch);
|
||||||
tputs(SO, 0, _putchar);
|
|
||||||
#else
|
|
||||||
string_print(rev_video);
|
|
||||||
#endif /* UNIX */
|
|
||||||
string_print(" \b");
|
string_print(" \b");
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
}
|
}
|
||||||
|
@ -1793,7 +1702,7 @@ int input(char *inbuf, FLAG clearfl)
|
||||||
if (c == '\t')
|
if (c == '\t')
|
||||||
string_print("^I");
|
string_print("^I");
|
||||||
else
|
else
|
||||||
putchar(c);
|
putch(c);
|
||||||
string_print(" \b");
|
string_print(" \b");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1824,10 +1733,7 @@ int get_file(char *message, char *file)
|
||||||
* UNIX I/O Routines *
|
* UNIX I/O Routines *
|
||||||
* ======================================================================== */
|
* ======================================================================== */
|
||||||
|
|
||||||
#ifdef UNIX
|
int _getch(void)
|
||||||
#undef putchar
|
|
||||||
|
|
||||||
int _getchar(void)
|
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
|
@ -1841,9 +1747,12 @@ void _flush(void)
|
||||||
(void) fflush(stdout);
|
(void) fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _putchar(char c)
|
int _putch(int c)
|
||||||
{
|
{
|
||||||
(void) write_char(STD_OUT, c);
|
if (write_char(STD_OUT, c) == FINE)
|
||||||
|
return c;
|
||||||
|
else
|
||||||
|
return EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_term(void)
|
void get_term(void)
|
||||||
|
@ -1873,4 +1782,3 @@ void get_term(void)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* UNIX */
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
/*
|
/*
|
||||||
* Move one line up.
|
* Move one line up.
|
||||||
*/
|
*/
|
||||||
void UP(void)
|
void UP1(void)
|
||||||
{
|
{
|
||||||
if (y == 0) { /* Top line of screen. Scroll one line */
|
if (y == 0) { /* Top line of screen. Scroll one line */
|
||||||
(void) reverse_scroll();
|
(void) reverse_scroll();
|
||||||
|
@ -25,12 +25,12 @@ void UP(void)
|
||||||
/*
|
/*
|
||||||
* Move one line down.
|
* Move one line down.
|
||||||
*/
|
*/
|
||||||
void DN(void)
|
void DN1(void)
|
||||||
{
|
{
|
||||||
if (y == last_y) { /* Last line of screen. Scroll one line */
|
if (y == last_y) { /* Last line of screen. Scroll one line */
|
||||||
if (bot_line->next == tail && bot_line->text[0] != '\n') {
|
if (bot_line->next == tail && bot_line->text[0] != '\n') {
|
||||||
dummy_line(); /* Create new empty line */
|
dummy_line(); /* Create new empty line */
|
||||||
DN();
|
DN1();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -45,11 +45,11 @@ void DN(void)
|
||||||
/*
|
/*
|
||||||
* Move left one position.
|
* Move left one position.
|
||||||
*/
|
*/
|
||||||
void LF(void)
|
void LF1(void)
|
||||||
{
|
{
|
||||||
if (x == 0 && get_shift(cur_line->shift_count) == 0) {/* Begin of line */
|
if (x == 0 && get_shift(cur_line->shift_count) == 0) {/* Begin of line */
|
||||||
if (cur_line->prev != header) {
|
if (cur_line->prev != header) {
|
||||||
UP(); /* Move one line up */
|
UP1(); /* Move one line up */
|
||||||
move_to(LINE_END, y);
|
move_to(LINE_END, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,11 +60,11 @@ void LF(void)
|
||||||
/*
|
/*
|
||||||
* Move right one position.
|
* Move right one position.
|
||||||
*/
|
*/
|
||||||
void RT(void)
|
void RT1(void)
|
||||||
{
|
{
|
||||||
if (*cur_text == '\n') {
|
if (*cur_text == '\n') {
|
||||||
if (cur_line->next != tail) { /* Last char of file */
|
if (cur_line->next != tail) { /* Last char of file */
|
||||||
DN(); /* Move one line down */
|
DN1(); /* Move one line down */
|
||||||
move_to(LINE_START, y);
|
move_to(LINE_START, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,11 +154,7 @@ void PU(void)
|
||||||
if (reverse_scroll() == ERRORS)
|
if (reverse_scroll() == ERRORS)
|
||||||
break; /* Top of file reached */
|
break; /* Top of file reached */
|
||||||
set_cursor(0, ymax); /* Erase very bottom line */
|
set_cursor(0, ymax); /* Erase very bottom line */
|
||||||
#ifdef UNIX
|
tputs(CE, 0, _putch);
|
||||||
tputs(CE, 0, _putchar);
|
|
||||||
#else
|
|
||||||
string_print(blank_line);
|
|
||||||
#endif /* UNIX */
|
|
||||||
if (y + i > screenmax) /* line no longer on screen */
|
if (y + i > screenmax) /* line no longer on screen */
|
||||||
move_to(0, screenmax >> 1);
|
move_to(0, screenmax >> 1);
|
||||||
else
|
else
|
||||||
|
@ -205,11 +201,7 @@ void SU(void)
|
||||||
|
|
||||||
(void) reverse_scroll();
|
(void) reverse_scroll();
|
||||||
set_cursor(0, ymax); /* Erase very bottom line */
|
set_cursor(0, ymax); /* Erase very bottom line */
|
||||||
#ifdef UNIX
|
tputs(CE, 0, _putch);
|
||||||
tputs(CE, 0, _putchar);
|
|
||||||
#else
|
|
||||||
string_print(blank_line);
|
|
||||||
#endif /* UNIX */
|
|
||||||
move_to(x, (y == screenmax) ? screenmax : y + 1);
|
move_to(x, (y == screenmax) ? screenmax : y + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,11 +251,7 @@ int reverse_scroll(void)
|
||||||
|
|
||||||
/* Perform the scroll */
|
/* Perform the scroll */
|
||||||
set_cursor(0, 0);
|
set_cursor(0, 0);
|
||||||
#ifdef UNIX
|
tputs(AL, 0, _putch);
|
||||||
tputs(AL, 0, _putchar);
|
|
||||||
#else
|
|
||||||
string_print(rev_scroll);
|
|
||||||
#endif /* UNIX */
|
|
||||||
set_cursor(0, 0);
|
set_cursor(0, 0);
|
||||||
line_print(top_line);
|
line_print(top_line);
|
||||||
|
|
||||||
|
@ -298,7 +286,7 @@ void move_previous_word(FLAG remove)
|
||||||
start_char = '\0';
|
start_char = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
LF();
|
LF1();
|
||||||
|
|
||||||
begin_line = cur_line->text;
|
begin_line = cur_line->text;
|
||||||
textp = cur_text;
|
textp = cur_text;
|
||||||
|
@ -352,7 +340,7 @@ void move_next_word(FLAG remove)
|
||||||
|
|
||||||
/* If we're at end of line. move to the first word on the next line. */
|
/* If we're at end of line. move to the first word on the next line. */
|
||||||
if (*textp == '\n' && cur_line->next != tail) {
|
if (*textp == '\n' && cur_line->next != tail) {
|
||||||
DN();
|
DN1();
|
||||||
move_to(LINE_START, y);
|
move_to(LINE_START, y);
|
||||||
textp = cur_text;
|
textp = cur_text;
|
||||||
while (*textp != '\n' && white_space(*textp))
|
while (*textp != '\n' && white_space(*textp))
|
||||||
|
@ -389,7 +377,7 @@ void DPC(void)
|
||||||
if (x == 0 && cur_line->prev == header)
|
if (x == 0 && cur_line->prev == header)
|
||||||
return; /* Top of file */
|
return; /* Top of file */
|
||||||
|
|
||||||
LF(); /* Move one left */
|
LF1(); /* Move one left */
|
||||||
DCC(); /* Delete character under cursor */
|
DCC(); /* Delete character under cursor */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,7 +457,7 @@ void CTL(void)
|
||||||
register char ctrl;
|
register char ctrl;
|
||||||
|
|
||||||
status_line("Enter control character.", NULL);
|
status_line("Enter control character.", NULL);
|
||||||
if ((ctrl = getchar()) >= '\01' && ctrl <= '\037') {
|
if ((ctrl = getch()) >= '\01' && ctrl <= '\037') {
|
||||||
S(ctrl); /* Insert the char */
|
S(ctrl); /* Insert the char */
|
||||||
clear_status();
|
clear_status();
|
||||||
}
|
}
|
||||||
|
@ -484,7 +472,7 @@ void CTL(void)
|
||||||
void LIB(void)
|
void LIB(void)
|
||||||
{
|
{
|
||||||
S('\n'); /* Insert the line */
|
S('\n'); /* Insert the line */
|
||||||
UP(); /* Move one line up */
|
UP1(); /* Move one line up */
|
||||||
move_to(LINE_END, y); /* Move to end of this line */
|
move_to(LINE_END, y); /* Move to end of this line */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue