add opendir alias
[minix.git] / commands / mined / mined.h
blobfad5acfebdb09c97b9aab408fda8ca15c887cb6c
1 /*========================================================================*
2 * Mined.h *
3 *========================================================================*/
5 #include <minix/config.h>
6 #include <sys/types.h>
7 #include <fcntl.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <limits.h>
12 #ifndef YMAX
13 #ifdef UNIX
14 #include <stdio.h>
15 #undef putchar
16 #undef getchar
17 #undef NULL
18 #undef EOF
19 extern char *CE, *VS, *SO, *SE, *CL, *AL, *CM;
20 #define YMAX 49
21 #else
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 */
31 #endif /* UNIX */
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 \
42 - 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 */
50 #define ERRORS -1
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 */
57 #if defined(__i386__)
58 #define MEMORY_SIZE (50 * 1024) /* Size of data space to malloc */
59 #endif
61 #define REPORT 2 /* Report change of lines on # lines */
63 typedef int FLAG;
65 /* General flags */
66 #define FALSE 0
67 #define TRUE 1
68 #define NOT_VALID 2
69 #define VALID 3
70 #define OFF 4
71 #define ON 5
73 /* Expression flags */
74 #define FORWARD 6
75 #define REVERSE 7
77 /* Yank flags */
78 #define SMALLER 8
79 #define BIGGER 9
80 #define SAME 10
81 #define EMPTY 11
82 #define NO_DELETE 12
83 #define DELETE 13
84 #define READ 14
85 #define WRITE 15
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).
92 struct Line {
93 struct Line *next;
94 struct Line *prev;
95 char *text;
96 unsigned char shift_count;
99 typedef struct Line LINE;
101 /* Dummy line indicator */
102 #define DUMMY 0x80
103 #define DUMMY_MASK 0x7F
105 /* Expression definitions */
106 #define NO_MATCH 0
107 #define MATCH 1
108 #define REG_ERROR 2
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.
118 struct regex {
119 union {
120 char *err_mess;
121 int *expression;
122 } result;
123 char status;
124 char *start_ptr;
125 char *end_ptr;
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 */
143 extern int ymax;
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')
196 * Word defenitions
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), \
220 (str2), NULL, FALSE)
221 #define error(str1, str2) (void) bottom_line(ON, (str1), \
222 (str2), NULL, FALSE)
223 #define get_string(str1,str2, fl) bottom_line(ON, (str1), NULL, (str2), fl)
224 #define clear_status() (void) bottom_line(OFF, NULL, NULL, \
225 NULL, FALSE)
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)
238 #endif /* YMAX */
240 /* mined1.c */
242 void FS(void);
243 void VI(void);
244 int WT(void);
245 void XWT(void);
246 void SH(void);
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);
259 int getchar(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 );
273 #ifdef UNIX
274 void(*key_map [128]) (void);
275 #else
276 void(*key_map [256]) (void);
277 #endif
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 []);
285 void RD(void);
286 void I(void);
287 void XT(void);
288 void ESC(void);
289 int ask_save(void);
290 int line_number(void);
291 void file_status(char *message, long count, char *file, int lines, FLAG
292 writefl, FLAG changed );
293 #if __STDC__
294 void build_string(char *buf, char *fmt, ...);
295 #else
296 void build_string();
297 #endif
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 );
302 int _getchar(void);
303 void _flush(void);
304 void _putchar(int c );
305 void get_term(void);
307 /* mined2.c */
309 void UP(void);
310 void DN(void);
311 void LF(void);
312 void RT(void);
313 void HIGH(void);
314 void LOW(void);
315 void BL(void);
316 void EL(void);
317 void GOTO(void);
318 void PD(void);
319 void PU(void);
320 void HO(void);
321 void EF(void);
322 void SU(void);
323 void SD(void);
324 int forward_scroll(void);
325 int reverse_scroll(void);
326 void MP(void);
327 void move_previous_word(FLAG remove );
328 void MN(void);
329 void move_next_word(FLAG remove );
330 void DCC(void);
331 void DPC(void);
332 void DLN(void);
333 void DNW(void);
334 void DPW(void);
335 void S(int character );
336 void CTL(void);
337 void LIB(void);
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
342 *end_textp );
343 void PT(void);
344 void IF(void);
345 void file_insert(int fd, FLAG old_pos );
346 void WB(void);
347 void MA(void);
348 void YA(void);
349 void DT(void);
350 void set_up(FLAG remove );
351 FLAG checkmark(void);
352 int legal(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 );
356 void SF(void);
357 void SR(void);
358 REGEX *get_expression(char *message );
359 void GR(void);
360 void LR(void);
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
371 *expression );
372 int in_list(int *list, int c, int list_length, int opcode );
373 void dummy_line(void);