Project

General

Profile

Bug #3132 ยป mined-unifdef.diff

mined unifdef patch - bcallah, 04/26/2018 08:32 PM

View differences:

bin/mined/mined.h
* Mined.h *
*========================================================================*/
#define INTEL 1
#define CHIP INTEL
#define ASSUME_CONS25
#define ASSUME_XTERM
#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#ifndef YMAX
#ifdef UNIX
#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 const char *enter_string; /* String printed on entering mined */
......
extern const 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 */
#define XMAX 79 /* Maximum x coordinate starting at 0*/
#define SCREENMAX (YMAX - 1) /* Number of lines displayed */
......
#define STD_OUT 1 /* File descriptor for terminal */
#if (CHIP == INTEL)
#define MEMORY_SIZE (50 * 1024) /* Size of data space to malloc */
#endif
#define REPORT 2 /* Report change of lines on # lines */
typedef int FLAG;
......
*/
#define get_shift(cnt) ((cnt) & DUMMY_MASK)
#endif /* YMAX */
/* mined1.c */
void FS(int);
bin/mined/mined1.c
/* Free old linked list, initialize global variables and load new file */
initialize();
#ifdef UNIX
tputs(CL, 0, _putchar);
#else
string_print (enter_string);
#endif /* UNIX */
load_file(new_file[0] == '\0' ? NIL_PTR : new_file);
}
......
clear_status ();
set_cursor(0, ymax);
if (revfl == ON) { /* Print rev. start sequence */
#ifdef UNIX
tputs(SO, 0, _putchar);
#else
string_print(rev_video);
#endif /* UNIX */
stat_visible = TRUE;
}
else /* Used as clear_status() */
......
ret = input(inbuf, statfl);
/* Print normal video */
#ifdef UNIX
tputs(SE, 0, _putchar);
tputs(CE, 0, _putchar);
#else
string_print(normal_video);
string_print(blank_line); /* Clear the rest of the line */
#endif /* UNIX */
if (inbuf != NIL_PTR)
set_cursor(0, ymax);
else
......
void
set_cursor(int nx, int ny)
{
#ifdef UNIX
tputs(tgoto(CM, nx, ny), 0, _putchar);
#else
char text_buf[10];
build_string(text_buf, pos_string, ny+1, nx+1);
string_print(text_buf);
#endif /* UNIX */
}
/*
......
int
getchar(void)
{
#ifdef UNIX
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 */
}
/*
......
/* Print the blank lines (if any) */
if (loading == FALSE) {
while (count-- >= 0) {
#ifdef UNIX
tputs(CE, 0, _putchar);
#else
string_print(blank_line);
#endif /* UNIX */
putchar('\n');
}
}
......
}
else {
if (*textp >= '\01' && *textp <= '\037') {
#ifdef UNIX
tputs(SO, 0, _putchar);
#else
string_print (rev_video);
#endif /* UNIX */
putchar(*textp++ + '\100');
#ifdef UNIX
tputs(SE, 0, _putchar);
#else
string_print (normal_video);
#endif /* UNIX */
}
else
putchar(*textp++);
......
/* Clear the rest of the line is clear_line is TRUE */
if (clear_line == TRUE) {
#ifdef UNIX
tputs(CE, 0, _putchar);
#else
string_print(blank_line);
#endif /* UNIX */
putchar('\n');
}
}
......
{
if (out_count <= 0) /* There is nothing to flush */
return FINE;
#ifdef UNIX
if (fd == STD_OUT) {
printf("%.*s", out_count, screen);
_flush();
}
else
#endif /* UNIX */
if (write(fd, screen, out_count) != out_count) {
bad_write(fd);
return ERRORS;
......
set_cursor(0, ymax);
putchar('\n');
flush();
#ifdef UNIX
abort();
#else
exit(1);
#endif /* UNIX */
}
#define UNDEF _POSIX_VDISABLE
......
void
panic(const char *message)
{
#ifdef UNIX
tputs(CL, 0, _putchar);
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 */
write(STD_OUT, text_buffer, length_of(text_buffer));
if (loading == FALSE)
......
unlink(yank_file);
raw_mode(OFF);
#ifdef UNIX
abort();
#else
exit(1);
#endif /* UNIX */
}
void *
......
char text_buffer[MAX_CHARS]; /* Buffer for modifying text */
/* Escape sequences. */
#ifdef UNIX
char *CE, *VS, *SO, *SE, *CL, *AL, *CM;
#else
const char *enter_string = "\033[H\033[J"; /* String printed on entering mined */
const char *pos_string = "\033[%d;%dH"; /* Absolute cursor position */
const char *rev_scroll = "\033M"; /* String for reverse scrolling */
const char *rev_video = "\033[7m"; /* String for starting reverse video */
const char *normal_video = "\033[m"; /* String for leaving reverse video */
const char *blank_line = "\033[K"; /* Clear line to end */
#endif /* UNIX */
/*
* Yank variables.
......
int index; /* Index in key table */
struct winsize winsize;
#ifdef UNIX
get_term();
tputs(VS, 0, _putchar);
tputs(CL, 0, _putchar);
#else
string_print(enter_string); /* Hello world */
#endif /* UNIX */
if (ioctl(STD_OUT, TIOCGWINSZ, &winsize) == 0 && winsize.ws_row != 0) {
ymax = winsize.ws_row - 1;
screenmax = ymax - 1;
......
RD(int u __unused)
{
/* Clear screen */
#ifdef UNIX
tputs(VS, 0, _putchar);
tputs(CL, 0, _putchar);
#else
string_print(enter_string);
#endif /* UNIX */
/* Print first page */
display(0, 0, top_line, last_y);
/* Clear last line */
set_cursor(0, ymax);
#ifdef UNIX
tputs(CE, 0, _putchar);
#else
string_print(blank_line);
#endif /* UNIX */
move_to(x, y);
}
......
static void
(*escfunc(int c))(int)
{
#if (CHIP == M68000)
#ifndef COMPAT
int ch;
#endif
#endif
if (c == '[') {
/* Start of ASCII escape sequence. */
c = getchar();
#if (CHIP == M68000)
#ifndef COMPAT
if ((c >= '0') && (c <= '9')) ch = getchar();
/* ch is either a tilde or a second digit */
#endif
#endif
switch (c) {
case 'H': return(HO);
case 'A': return(UP);
case 'B': return(DN);
case 'C': return(RT);
case 'D': return(LF);
#if (CHIP == M68000)
#ifndef COMPAT
/* F1 = ESC [ 1 ~ */
/* F2 = ESC [ 2 ~ */
/* F3 = ESC [ 3 ~ */
/* F4 = ESC [ 4 ~ */
/* F5 = ESC [ 5 ~ */
/* F6 = ESC [ 6 ~ */
/* F7 = ESC [ 17 ~ */
/* F8 = ESC [ 18 ~ */
case '1':
switch (ch) {
case '~': return(SF);
case '7': getchar(); return(MA);
case '8': getchar(); return(CTL);
}
case '2': return(SR);
case '3': return(PD);
case '4': return(PU);
case '5': return(FS);
case '6': return(EF);
#endif
#endif
#if (CHIP == INTEL)
#ifdef ASSUME_CONS25
case 'G': return(PD);
case 'I': return(PU);
case 'F': return(EF);
......
case 'P': return(GR);
/* Shift-F4 - line replace */
case 'b': return(LR);
#else
case 'G': return(FS);
case 'S': return(SR);
case 'T': return(SF);
case 'U': return(PD);
case 'V': return(PU);
case 'Y': return(EF);
#endif
#endif
}
return(I);
}
#ifdef ASSUME_XTERM
if (c == 'O') {
/* Start of ASCII function key escape sequence. */
switch (getchar()) {
......
break;
}
}
#endif
#if (CHIP == M68000)
#ifdef COMPAT
if (c == 'O') {
/* Start of ASCII function key escape sequence. */
switch (getchar()) {
case 'P': return(SF);
case 'Q': return(SR);
case 'R': return(PD);
case 'S': return(PU);
case 'T': return(FS);
case 'U': return(EF);
case 'V': return(MA);
case 'W': return(CTL);
}
}
#endif
#endif
return(I);
}
......
case '\b' : /* Erase previous char */
if (ptr > inbuf) {
ptr--;
#ifdef UNIX
tputs(SE, 0, _putchar);
#else
string_print(normal_video);
#endif /* UNIX */
if (is_tab(*ptr))
string_print(" \b\b\b \b\b");
else
string_print(" \b\b \b");
#ifdef UNIX
tputs(SO, 0, _putchar);
#else
string_print(rev_video);
#endif /* UNIX */
string_print(" \b");
*ptr = '\0';
}
......
}
return ret;
}
/* ======================================================================== *
* UNIX I/O Routines *
* ======================================================================== */
#ifdef UNIX
#undef putchar
int
_getchar(void)
{
char c;
if (read(input_fd, &c, 1) != 1 && quit == FALSE)
panic ("Cannot read 1 byte from input");
return c & 0377;
}
void
_flush(void)
{
fflush(stdout);
}
void
_putchar(char c)
{
write_char(STD_OUT, c);
}
void
get_term(void)
{
static char termbuf[50];
char *loc = termbuf;
char entry[1024];
if (tgetent(entry, getenv("TERM")) <= 0) {
printf("Unknown terminal.\n");
exit(1);
}
AL = tgetstr("al", &loc);
CE = tgetstr("ce", &loc);
VS = tgetstr("vs", &loc);
CL = tgetstr("cl", &loc);
SO = tgetstr("so", &loc);
SE = tgetstr("se", &loc);
CM = tgetstr("cm", &loc);
ymax = tgetnum("li") - 1;
screenmax = ymax - 1;
if (!CE || !SO || !SE || !CL || !AL || !CM) {
printf("Sorry, no mined on this type of terminal\n");
exit(1);
}
}
#endif /* UNIX */
bin/mined/mined2.c
if (reverse_scroll() == ERRORS)
break; /* Top of file reached */
set_cursor(0, ymax); /* Erase very bottom line */
#ifdef UNIX
tputs(CE, 0, _putchar);
#else
string_print(blank_line);
#endif /* UNIX */
if (y + i > screenmax) /* line no longer on screen */
move_to(0, screenmax >> 1);
else
......
reverse_scroll();
set_cursor(0, ymax); /* Erase very bottom line */
#ifdef UNIX
tputs(CE, 0, _putchar);
#else
string_print(blank_line);
#endif /* UNIX */
move_to(x, (y == screenmax) ? screenmax : y + 1);
}
......
/* Perform the scroll */
set_cursor(0, 0);
#ifdef UNIX
tputs(AL, 0, _putchar);
#else
string_print(rev_scroll);
#endif /* UNIX */
set_cursor(0, 0);
line_print(top_line);
    (1-1/1)