#define INTEL 1
#define CHIP INTEL
#define ASSUME_CONS25
#define ASSUME_XTERM
#include <sys/param.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
extern const char *enter_string;
extern const char *rev_video;
extern const char *normal_video;
extern const char *rev_scroll;
extern const char *pos_string;
#define X_PLUS ' '
#define Y_PLUS ' '
#endif
#define XMAX 79
#define SCREENMAX (YMAX - 1)
#define XBREAK (XMAX - 1)
#define SHIFT_SIZE 25
#define SHIFT_MARK '!'
#define MAX_CHARS 1024
#define LINE_START (rounddown(-MAX_CHARS - 1, SHIFT_SIZE) - SHIFT_SIZE)
#define LINE_END (MAX_CHARS + 1)
#define LINE_LEN (XMAX + 1)
#define SCREEN_SIZE (XMAX * YMAX)
#define BLOCK_SIZE 1024
#define ERRORS -1
#define NO_LINE (ERRORS - 1)
#define FINE (ERRORS + 1)
#define NO_INPUT (ERRORS + 2)
#define STD_OUT 1
#if (CHIP == INTEL)
#define MEMORY_SIZE (50 * 1024)
#endif
#define REPORT 2
typedef int FLAG;
#define FALSE 0
#define TRUE 1
#define NOT_VALID 2
#define VALID 3
#define OFF 4
#define ON 5
#define FORWARD 6
#define REVERSE 7
#define SMALLER 8
#define BIGGER 9
#define SAME 10
#define EMPTY 11
#define NO_DELETE 12
#define DELETE 13
#define READ 14
#define WRITE 15
struct Line {
struct Line *next;
struct Line *prev;
char *text;
unsigned char shift_count;
};
typedef struct Line LINE;
#define DUMMY 0x80
#define DUMMY_MASK 0x7F
#define NO_MATCH 0
#define MATCH 1
#define REG_ERROR 2
#define BEGIN_LINE (2 * REG_ERROR)
#define END_LINE (2 * BEGIN_LINE)
struct regex {
union {
const char *err_mess;
int *expression;
} result;
char status;
char *start_ptr;
char *end_ptr;
};
typedef struct regex REGEX;
#define NIL_PTR ((char *) 0)
#define NIL_LINE ((LINE *) 0)
#define NIL_REG ((REGEX *) 0)
#define NIL_INT ((int *) 0)
extern int nlines;
extern LINE *header;
extern LINE *tail;
extern LINE *top_line;
extern LINE *bot_line;
extern LINE *cur_line;
extern char *cur_text;
extern int last_y;
extern int ymax;
extern int screenmax;
extern char screen[SCREEN_SIZE];
extern int x, y;
extern FLAG modified;
extern FLAG stat_visible;
extern FLAG writable;
extern FLAG quit;
extern FLAG rpipe;
extern int input_fd;
extern FLAG loading;
extern int out_count;
extern char file_name[LINE_LEN];
extern char text_buffer[MAX_CHARS];
extern const char *blank_line;
extern char yank_file[];
extern FLAG yank_status;
extern long chars_saved;
#define clear_buffer() (out_count = 0)
#define putchar(c) write_char(STD_OUT, (c))
#define ring_bell() putchar('\07')
#define string_print(str) writeline(STD_OUT, (str))
#define flush() flush_buffer(STD_OUT)
#define tab(cnt) (((cnt) + 8) & ~07)
#define is_tab(c) ((c) == '\t')
#define white_space(c) ((c) == ' ' || (c) == '\t')
#define alpha(c) ((c) != ' ' && (c) != '\t' && (c) != '\n')
#define line_print(line) put_line(line, 0, TRUE)
#define move_to(nx, ny) move((nx), NIL_PTR, (ny))
#define move_address(address) move(0, (address), y)
#define status_line(str1, str2) bottom_line(ON, (str1), (str2), NIL_PTR, FALSE)
#define error(str1, str2) bottom_line(ON, (str1), (str2), NIL_PTR, FALSE)
#define get_string(str1,str2, fl) bottom_line(ON, (str1), NIL_PTR, (str2), fl)
#define clear_status() bottom_line(OFF, NIL_PTR, NIL_PTR, \
NIL_PTR, FALSE)
#define fstatus(mess, cnt) file_status((mess), (cnt), file_name, \
nlines, writable, modified)
#define get_shift(cnt) ((cnt) & DUMMY_MASK)
#endif
void FS(int);
void VI(int);
int WT(void);
void XWT(int);
void SH(int);
LINE *proceed(LINE *line, int count);
int bottom_line(FLAG revfl, const char *s1, const char *s2, char *inbuf, FLAG statfl);
int count_chars(LINE *line);
void move(int new_x, char *new_address, int new_y);
int find_x(LINE *line, char *address);
char *find_address(LINE *line, int x_coord, int *old_x);
int length_of(char *string);
void copy_string(char *to, const char *from);
void reset(LINE *head_line, int screen_y);
void set_cursor(int nx, int ny);
void open_device(void);
int getchar(void);
void display(int x_coord, int y_coord, LINE *line, int count);
int write_char(int fd, char c);
int writeline(int fd, const char *text);
void put_line(LINE *line, int offset, FLAG clear_line);
int flush_buffer(int fd);
void bad_write(int fd);
void catch(int sig);
void abort_mined(void);
void raw_mode(FLAG state);
void panic(const char *message) __dead2;
void *alloc(int bytes);
void free_space(char *p);
void initialize(void);
char *basename(char *path);
void load_file(const char *file);
int get_line(int fd, char *buffer);
LINE *install_line(const char *buffer, int length);
void RD(int);
void I(int);
void XT(int);
void ESC(int);
int ask_save(void);
int line_number(void);
void file_status(const char *message, long count, char *file, int lines,
FLAG writefl, FLAG changed);
void build_string(char *buf, const char *fmt, ...);
char *num_out(long number);
int get_number(const char *message, int *result);
int input(char *inbuf, FLAG clearfl);
int get_file(const char *message, char *file);
int _getchar(void);
void _flush(void);
void _putchar(int c);
void get_term(void);
void UP(int);
void DN(int);
void LF(int);
void RT(int);
void HIGH(int);
void LOW(int);
void BL(int);
void EL(int);
void GOTO(int);
void HLP(int);
void ST(int);
void PD(int);
void PU(int);
void HO(int);
void EF(int);
void SU(int);
void SD(int);
int forward_scroll(void);
int reverse_scroll(void);
void MP(int);
void move_previous_word(FLAG remove);
void MN(int);
void move_next_word(FLAG remove);
void DCC(int);
void DPC(int);
void DLN(int);
void DNW(int);
void DPW(int);
void S(int character);
void CTL(int);
void LIB(int);
LINE *line_insert(LINE *line, const char *string, int len);
int insert(LINE *line, char *location, char *string);
LINE *line_delete(LINE *line);
void delete(LINE *start_line, char *start_textp,
LINE *end_line, char *end_textp);
void PT(int);
void IF(int);
void file_insert(int fd, FLAG old_pos);
void WB(int);
void MA(int);
void YA(int);
void DT(int);
void set_up(FLAG remove);
FLAG checkmark(void);
int legal(void);
void yank(LINE *start_line, char *start_textp,
LINE *end_line, char *end_textp, FLAG remove);
int scratch_file(FLAG mode);
void SF(int);
void SR(int);
REGEX *get_expression(const char *message);
void GR(int);
void LR(int);
void change(const char *message, FLAG file);
char *substitute(LINE *line, REGEX *program, char *replacement);
void search(const char *message, FLAG method);
int find_y(LINE *match_line);
void finished(REGEX *program, int *last_exp);
void compile(char *pattern, REGEX *program);
LINE *match(REGEX *program, char *string, FLAG method);
int line_check(REGEX *program, char *string, FLAG method);
int check_string(REGEX *program, char *string, int *expression);
int star(REGEX *program, char *end_position, char *string,
int *expression);
int in_list(int *list, char c, int list_length, int opcode);
void dummy_line(void);