1 /*========================================================================*
3 *========================================================================*/
5 #include <minix/config.h>
19 extern char *CE
, *VS
, *SO
, *SE
, *CL
, *AL
, *CM
;
22 #define YMAX 24 /* Maximum y coordinate starting at 0 */
23 /* Escape sequences. */
24 extern char *enter_string
; /* String printed on entering mined */
25 extern char *rev_video
; /* String for starting reverse video */
26 extern char *normal_video
; /* String for leaving reverse video */
27 extern char *rev_scroll
; /* String for reverse scrolling */
28 extern char *pos_string
; /* Absolute cursor positioning */
29 #define X_PLUS ' ' /* To be added to x for cursor sequence */
30 #define Y_PLUS ' ' /* To be added to y for cursor sequence */
33 #define XMAX 79 /* Maximum x coordinate starting at 0*/
34 #define SCREENMAX (YMAX - 1) /* Number of lines displayed */
35 #define XBREAK (XMAX - 0) /* Line shift at this coordinate */
36 #define SHIFT_SIZE 25 /* Number of chars to shift */
37 #define SHIFT_MARK '!' /* Char indicating line continues */
38 #define MAX_CHARS 1024 /* Maximum chars on one line */
40 /* LINE_START must be rounded up to the lowest SHIFT_SIZE */
41 #define LINE_START (((-MAX_CHARS - 1) / SHIFT_SIZE) * SHIFT_SIZE \
43 #define LINE_END (MAX_CHARS + 1) /* Highest x-coordinate for line */
45 #define LINE_LEN (XMAX + 1) /* Number of characters on line */
46 #define SCREEN_SIZE (XMAX * YMAX) /* Size of I/O buffering */
47 #define BLOCK_SIZE 1024
49 /* Return values of functions */
51 #define NO_LINE (ERRORS - 1) /* Must be < 0 */
52 #define FINE (ERRORS + 1)
53 #define NO_INPUT (ERRORS + 2)
55 #define STD_OUT 1 /* File descriptor for terminal */
58 #define MEMORY_SIZE (50 * 1024) /* Size of data space to malloc */
61 #define REPORT 2 /* Report change of lines on # lines */
73 /* Expression flags */
88 * The Line structure. Each line entry contains a pointer to the next line,
89 * a pointer to the previous line, a pointer to the text and an unsigned char
90 * telling at which offset of the line printing should start (usually 0).
96 unsigned char shift_count
;
99 typedef struct Line LINE
;
101 /* Dummy line indicator */
103 #define DUMMY_MASK 0x7F
105 /* Expression definitions */
110 #define BEGIN_LINE (2 * REG_ERROR)
111 #define END_LINE (2 * BEGIN_LINE)
114 * The regex structure. Status can be any of 0, BEGIN_LINE or REG_ERROR. In
115 * the last case, the result.err_mess field is assigned. Start_ptr and end_ptr
116 * point to the match found. For more details see the documentation file.
128 typedef struct regex REGEX
;
130 /* NULL definitions */
133 * Forward declarations
135 extern int nlines
; /* Number of lines in file */
136 extern LINE
*header
; /* Head of line list */
137 extern LINE
*tail
; /* Last line in line list */
138 extern LINE
*top_line
; /* First line of screen */
139 extern LINE
*bot_line
; /* Last line of screen */
140 extern LINE
*cur_line
; /* Current line in use */
141 extern char *cur_text
; /* Pointer to char on current line in use */
142 extern int last_y
; /* Last y of screen. Usually SCREENMAX */
144 extern int screenmax
;
145 extern char screen
[SCREEN_SIZE
];/* Output buffer for "writes" and "reads" */
147 extern int x
, y
; /* x, y coordinates on screen */
148 extern FLAG modified
; /* Set when file is modified */
149 extern FLAG stat_visible
; /* Set if status_line is visible */
150 extern FLAG writable
; /* Set if file cannot be written */
151 extern FLAG quit
; /* Set when quit character is typed */
152 extern FLAG rpipe
; /* Set if file should be read from stdin */
153 extern int input_fd
; /* Fd for command input */
154 extern FLAG loading
; /* Set if we're loading a file */
155 extern int out_count
; /* Index in output buffer */
156 extern char file_name
[LINE_LEN
]; /* Name of file in use */
157 extern char text_buffer
[MAX_CHARS
]; /* Buffer for modifying text */
158 extern char *blank_line
; /* Clear line to end */
160 extern char yank_file
[]; /* Temp file for buffer */
161 extern FLAG yank_status
; /* Status of yank_file */
162 extern long chars_saved
; /* Nr of chars saved in buffer */
165 * Empty output buffer
167 #define clear_buffer() (out_count = 0)
170 * Print character on terminal
172 #define putchar(c) (void) write_char(STD_OUT, (c))
175 * Ring bell on terminal
177 #define ring_bell() putchar('\07')
180 * Print string on terminal
182 #define string_print(str) (void) writeline(STD_OUT, (str))
185 * Flush output buffer
187 #define flush() (void) flush_buffer(STD_OUT)
190 * Convert cnt to nearest tab position
192 #define tab(cnt) (((cnt) + 8) & ~07)
193 #define is_tab(c) ((c) == '\t')
198 #define white_space(c) ((c) == ' ' || (c) == '\t')
199 #define alpha(c) ((c) != ' ' && (c) != '\t' && (c) != '\n')
202 * Print line on terminal at offset 0 and clear tail of line
204 #define line_print(line) put_line(line, 0, TRUE)
207 * Move to coordinates and set textp. (Don't use address)
209 #define move_to(nx, ny) move((nx), NULL, (ny))
212 * Move to coordinates on screen as indicated by textp.
214 #define move_address(address) move(0, (address), y)
217 * Functions handling status_line. ON means in reverse video.
219 #define status_line(str1, str2) (void) bottom_line(ON, (str1), \
221 #define error(str1, str2) (void) bottom_line(ON, (str1), \
223 #define get_string(str1,str2, fl) bottom_line(ON, (str1), NULL, (str2), fl)
224 #define clear_status() (void) bottom_line(OFF, NULL, NULL, \
228 * Print info about current file and buffer.
230 #define fstatus(mess, cnt) file_status((mess), (cnt), file_name, \
231 nlines, writable, modified)
234 * Get real shift value.
236 #define get_shift(cnt) ((cnt) & DUMMY_MASK)
247 LINE
*proceed(LINE
*line
, int count
);
248 int bottom_line(FLAG revfl
, char *s1
, char *s2
, char *inbuf
, FLAG statfl
250 int count_chars(LINE
*line
);
251 void move(int new_x
, char *new_address
, int new_y
);
252 int find_x(LINE
*line
, char *address
);
253 char *find_address(LINE
*line
, int x_coord
, int *old_x
);
254 int length_of(char *string
);
255 void copy_string(char *to
, char *from
);
256 void reset(LINE
*head_line
, int screen_y
);
257 void set_cursor(int nx
, int ny
);
258 void open_device(void);
260 void display(int x_coord
, int y_coord
, LINE
*line
, int count
);
261 int write_char(int fd
, int c
);
262 int writeline(int fd
, char *text
);
263 void put_line(LINE
*line
, int offset
, FLAG clear_line
);
264 int flush_buffer(int fd
);
265 void bad_write(int fd
);
266 void catch(int sig
);
267 void abort_mined(void);
268 void raw_mode(FLAG state
);
269 void panic(char *message
);
270 char *alloc(int bytes
);
271 void free_space(char *p
);
274 void(*key_map [128]) (void);
276 void(*key_map [256]) (void);
279 void initialize(void);
280 char *basename(char *path
);
281 void load_file(char *file
);
282 int get_line(int fd
, char *buffer
);
283 LINE
*install_line(char *buffer
, int length
);
284 int main(int argc
, char *argv
[]);
290 int line_number(void);
291 void file_status(char *message
, long count
, char *file
, int lines
, FLAG
292 writefl
, FLAG changed
);
294 void build_string(char *buf
, char *fmt
, ...);
298 char *num_out(long number
);
299 int get_number(char *message
, int *result
);
300 int input(char *inbuf
, FLAG clearfl
);
301 int get_file(char *message
, char *file
);
304 void _putchar(int c
);
324 int forward_scroll(void);
325 int reverse_scroll(void);
327 void move_previous_word(FLAG remove
);
329 void move_next_word(FLAG remove
);
335 void S(int character
);
338 LINE
*line_insert(LINE
*line
, char *string
, int len
);
339 int insert(LINE
*line
, char *location
, char *string
);
340 LINE
*line_delete(LINE
*line
);
341 void delete(LINE
*start_line
, char *start_textp
, LINE
*end_line
, char
345 void file_insert(int fd
, FLAG old_pos
);
350 void set_up(FLAG remove
);
351 FLAG
checkmark(void);
353 void yank(LINE
*start_line
, char *start_textp
, LINE
*end_line
, char
354 *end_textp
, FLAG remove
);
355 int scratch_file(FLAG mode
);
358 REGEX
*get_expression(char *message
);
361 void change(char *message
, FLAG file
);
362 char *substitute(LINE
*line
, REGEX
*program
, char *replacement
);
363 void search(char *message
, FLAG method
);
364 int find_y(LINE
*match_line
);
365 void finished(REGEX
*program
, int *last_exp
);
366 void compile(char *pattern
, REGEX
*program
);
367 LINE
*match(REGEX
*program
, char *string
, FLAG method
);
368 int line_check(REGEX
*program
, char *string
, FLAG method
);
369 int check_string(REGEX
*program
, char *string
, int *expression
);
370 int star(REGEX
*program
, char *end_position
, char *string
, int
372 int in_list(int *list
, int c
, int list_length
, int opcode
);
373 void dummy_line(void);