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 */
131 #define NIL_PTR ((char *) 0)
132 #define NIL_LINE ((LINE *) 0)
133 #define NIL_REG ((REGEX *) 0)
134 #define NIL_INT ((int *) 0)
137 * Forward declarations
139 extern int nlines
; /* Number of lines in file */
140 extern LINE
*header
; /* Head of line list */
141 extern LINE
*tail
; /* Last line in line list */
142 extern LINE
*top_line
; /* First line of screen */
143 extern LINE
*bot_line
; /* Last line of screen */
144 extern LINE
*cur_line
; /* Current line in use */
145 extern char *cur_text
; /* Pointer to char on current line in use */
146 extern int last_y
; /* Last y of screen. Usually SCREENMAX */
148 extern int screenmax
;
149 extern char screen
[SCREEN_SIZE
];/* Output buffer for "writes" and "reads" */
151 extern int x
, y
; /* x, y coordinates on screen */
152 extern FLAG modified
; /* Set when file is modified */
153 extern FLAG stat_visible
; /* Set if status_line is visible */
154 extern FLAG writable
; /* Set if file cannot be written */
155 extern FLAG quit
; /* Set when quit character is typed */
156 extern FLAG rpipe
; /* Set if file should be read from stdin */
157 extern int input_fd
; /* Fd for command input */
158 extern FLAG loading
; /* Set if we're loading a file */
159 extern int out_count
; /* Index in output buffer */
160 extern char file_name
[LINE_LEN
]; /* Name of file in use */
161 extern char text_buffer
[MAX_CHARS
]; /* Buffer for modifying text */
162 extern char *blank_line
; /* Clear line to end */
164 extern char yank_file
[]; /* Temp file for buffer */
165 extern FLAG yank_status
; /* Status of yank_file */
166 extern long chars_saved
; /* Nr of chars saved in buffer */
169 * Empty output buffer
171 #define clear_buffer() (out_count = 0)
174 * Print character on terminal
176 #define putchar(c) (void) write_char(STD_OUT, (c))
179 * Ring bell on terminal
181 #define ring_bell() putchar('\07')
184 * Print string on terminal
186 #define string_print(str) (void) writeline(STD_OUT, (str))
189 * Flush output buffer
191 #define flush() (void) flush_buffer(STD_OUT)
194 * Convert cnt to nearest tab position
196 #define tab(cnt) (((cnt) + 8) & ~07)
197 #define is_tab(c) ((c) == '\t')
202 #define white_space(c) ((c) == ' ' || (c) == '\t')
203 #define alpha(c) ((c) != ' ' && (c) != '\t' && (c) != '\n')
206 * Print line on terminal at offset 0 and clear tail of line
208 #define line_print(line) put_line(line, 0, TRUE)
211 * Move to coordinates and set textp. (Don't use address)
213 #define move_to(nx, ny) move((nx), NIL_PTR, (ny))
216 * Move to coordinates on screen as indicated by textp.
218 #define move_address(address) move(0, (address), y)
221 * Functions handling status_line. ON means in reverse video.
223 #define status_line(str1, str2) (void) bottom_line(ON, (str1), \
224 (str2), NIL_PTR, FALSE)
225 #define error(str1, str2) (void) bottom_line(ON, (str1), \
226 (str2), NIL_PTR, FALSE)
227 #define get_string(str1,str2, fl) bottom_line(ON, (str1), NIL_PTR, (str2), fl)
228 #define clear_status() (void) bottom_line(OFF, NIL_PTR, NIL_PTR, \
232 * Print info about current file and buffer.
234 #define fstatus(mess, cnt) file_status((mess), (cnt), file_name, \
235 nlines, writable, modified)
238 * Get real shift value.
240 #define get_shift(cnt) ((cnt) & DUMMY_MASK)
246 _PROTOTYPE(void FS
, (void));
247 _PROTOTYPE(void VI
, (void));
248 _PROTOTYPE(int WT
, (void));
249 _PROTOTYPE(void XWT
, (void));
250 _PROTOTYPE(void SH
, (void));
251 _PROTOTYPE(LINE
*proceed
, (LINE
*line
, int count
));
252 _PROTOTYPE(int bottom_line
, (FLAG revfl
, char *s1
, char *s2
, char *inbuf
, FLAG statfl
));
253 _PROTOTYPE(int count_chars
, (LINE
*line
));
254 _PROTOTYPE(void move
, (int new_x
, char *new_address
, int new_y
));
255 _PROTOTYPE(int find_x
, (LINE
*line
, char *address
));
256 _PROTOTYPE(char *find_address
, (LINE
*line
, int x_coord
, int *old_x
));
257 _PROTOTYPE(int length_of
, (char *string
));
258 _PROTOTYPE(void copy_string
, (char *to
, char *from
));
259 _PROTOTYPE(void reset
, (LINE
*head_line
, int screen_y
));
260 _PROTOTYPE(void set_cursor
, (int nx
, int ny
));
261 _PROTOTYPE(void open_device
, (void));
262 _PROTOTYPE(int getchar
, (void));
263 _PROTOTYPE(void display
, (int x_coord
, int y_coord
, LINE
*line
, int count
));
264 _PROTOTYPE(int write_char
, (int fd
, int c
));
265 _PROTOTYPE(int writeline
, (int fd
, char *text
));
266 _PROTOTYPE(void put_line
, (LINE
*line
, int offset
, FLAG clear_line
));
267 _PROTOTYPE(int flush_buffer
, (int fd
));
268 _PROTOTYPE(void bad_write
, (int fd
));
269 _PROTOTYPE(void catch, (int sig
));
270 _PROTOTYPE(void abort_mined
, (void));
271 _PROTOTYPE(void raw_mode
, (FLAG state
));
272 _PROTOTYPE(void panic
, (char *message
));
273 _PROTOTYPE(char *alloc
, (int bytes
));
274 _PROTOTYPE(void free_space
, (char *p
));
277 _PROTOTYPE(void (*key_map [128]), (void));
279 _PROTOTYPE(void (*key_map [256]), (void));
282 _PROTOTYPE(void initialize
, (void));
283 _PROTOTYPE(char *basename
, (char *path
));
284 _PROTOTYPE(void load_file
, (char *file
));
285 _PROTOTYPE(int get_line
, (int fd
, char *buffer
));
286 _PROTOTYPE(LINE
*install_line
, (char *buffer
, int length
));
287 _PROTOTYPE(void main
, (int argc
, char *argv
[]));
288 _PROTOTYPE(void RD
, (void));
289 _PROTOTYPE(void I
, (void));
290 _PROTOTYPE(void XT
, (void));
291 _PROTOTYPE(void ESC
, (void));
292 _PROTOTYPE(int ask_save
, (void));
293 _PROTOTYPE(int line_number
, (void));
294 _PROTOTYPE(void file_status
, (char *message
, long count
, char *file
, int lines
,
295 FLAG writefl
, FLAG changed
));
297 void build_string(char *buf
, char *fmt
, ...);
301 _PROTOTYPE(char *num_out
, (long number
));
302 _PROTOTYPE(int get_number
, (char *message
, int *result
));
303 _PROTOTYPE(int input
, (char *inbuf
, FLAG clearfl
));
304 _PROTOTYPE(int get_file
, (char *message
, char *file
));
305 _PROTOTYPE(int _getchar
, (void));
306 _PROTOTYPE(void _flush
, (void));
307 _PROTOTYPE(void _putchar
, (int c
));
308 _PROTOTYPE(void get_term
, (void));
312 _PROTOTYPE(void UP
, (void));
313 _PROTOTYPE(void DN
, (void));
314 _PROTOTYPE(void LF
, (void));
315 _PROTOTYPE(void RT
, (void));
316 _PROTOTYPE(void HIGH
, (void));
317 _PROTOTYPE(void LOW
, (void));
318 _PROTOTYPE(void BL
, (void));
319 _PROTOTYPE(void EL
, (void));
320 _PROTOTYPE(void GOTO
, (void));
321 _PROTOTYPE(void PD
, (void));
322 _PROTOTYPE(void PU
, (void));
323 _PROTOTYPE(void HO
, (void));
324 _PROTOTYPE(void EF
, (void));
325 _PROTOTYPE(void SU
, (void));
326 _PROTOTYPE(void SD
, (void));
327 _PROTOTYPE(int forward_scroll
, (void));
328 _PROTOTYPE(int reverse_scroll
, (void));
329 _PROTOTYPE(void MP
, (void));
330 _PROTOTYPE(void move_previous_word
, (FLAG remove
));
331 _PROTOTYPE(void MN
, (void));
332 _PROTOTYPE(void move_next_word
, (FLAG remove
));
333 _PROTOTYPE(void DCC
, (void));
334 _PROTOTYPE(void DPC
, (void));
335 _PROTOTYPE(void DLN
, (void));
336 _PROTOTYPE(void DNW
, (void));
337 _PROTOTYPE(void DPW
, (void));
338 _PROTOTYPE(void S
, (int character
));
339 _PROTOTYPE(void CTL
, (void));
340 _PROTOTYPE(void LIB
, (void));
341 _PROTOTYPE(LINE
*line_insert
, (LINE
*line
, char *string
, int len
));
342 _PROTOTYPE(int insert
, (LINE
*line
, char *location
, char *string
));
343 _PROTOTYPE(LINE
*line_delete
, (LINE
*line
));
344 _PROTOTYPE(void delete, (LINE
*start_line
, char *start_textp
, LINE
*end_line
, char *end_textp
));
345 _PROTOTYPE(void PT
, (void));
346 _PROTOTYPE(void IF
, (void));
347 _PROTOTYPE(void file_insert
, (int fd
, FLAG old_pos
));
348 _PROTOTYPE(void WB
, (void));
349 _PROTOTYPE(void MA
, (void));
350 _PROTOTYPE(void YA
, (void));
351 _PROTOTYPE(void DT
, (void));
352 _PROTOTYPE(void set_up
, (FLAG remove
));
353 _PROTOTYPE(FLAG checkmark
, (void));
354 _PROTOTYPE(int legal
, (void));
355 _PROTOTYPE(void yank
, (LINE
*start_line
, char *start_textp
, LINE
*end_line
, char *end_textp
, FLAG remove
));
356 _PROTOTYPE(int scratch_file
, (FLAG mode
));
357 _PROTOTYPE(void SF
, (void));
358 _PROTOTYPE(void SR
, (void));
359 _PROTOTYPE(REGEX
*get_expression
, (char *message
));
360 _PROTOTYPE(void GR
, (void));
361 _PROTOTYPE(void LR
, (void));
362 _PROTOTYPE(void change
, (char *message
, FLAG file
));
363 _PROTOTYPE(char *substitute
, (LINE
*line
, REGEX
*program
, char *replacement
));
364 _PROTOTYPE(void search
, (char *message
, FLAG method
));
365 _PROTOTYPE(int find_y
, (LINE
*match_line
));
366 _PROTOTYPE(void finished
, (REGEX
*program
, int *last_exp
));
367 _PROTOTYPE(void compile
, (char *pattern
, REGEX
*program
));
368 _PROTOTYPE(LINE
*match
, (REGEX
*program
, char *string
, FLAG method
));
369 _PROTOTYPE(int line_check
, (REGEX
*program
, char *string
, FLAG method
));
370 _PROTOTYPE(int check_string
, (REGEX
*program
, char *string
, int *expression
));
371 _PROTOTYPE(int star
, (REGEX
*program
, char *end_position
, char *string
, int *expression
));
372 _PROTOTYPE(int in_list
, (int *list
, int c
, int list_length
, int opcode
));
373 _PROTOTYPE(void dummy_line
, (void));