source: trunk/minix/commands/mined/mined.h@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 11.7 KB
Line 
1/*========================================================================*
2 * Mined.h *
3 *========================================================================*/
4
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>
11
12#ifndef YMAX
13#ifdef UNIX
14#include <stdio.h>
15#undef putchar
16#undef getchar
17#undef NULL
18#undef EOF
19extern 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. */
24extern char *enter_string; /* String printed on entering mined */
25extern char *rev_video; /* String for starting reverse video */
26extern char *normal_video; /* String for leaving reverse video */
27extern char *rev_scroll; /* String for reverse scrolling */
28extern 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 */
32
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 */
39
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 */
44
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
48
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)
54
55#define STD_OUT 1 /* File descriptor for terminal */
56
57#if (CHIP == INTEL)
58#define MEMORY_SIZE (50 * 1024) /* Size of data space to malloc */
59#endif
60
61#define REPORT 2 /* Report change of lines on # lines */
62
63typedef int FLAG;
64
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
72
73/* Expression flags */
74#define FORWARD 6
75#define REVERSE 7
76
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
86
87/*
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).
91 */
92struct Line {
93 struct Line *next;
94 struct Line *prev;
95 char *text;
96 unsigned char shift_count;
97};
98
99typedef struct Line LINE;
100
101/* Dummy line indicator */
102#define DUMMY 0x80
103#define DUMMY_MASK 0x7F
104
105/* Expression definitions */
106#define NO_MATCH 0
107#define MATCH 1
108#define REG_ERROR 2
109
110#define BEGIN_LINE (2 * REG_ERROR)
111#define END_LINE (2 * BEGIN_LINE)
112
113/*
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.
117 */
118struct regex {
119 union {
120 char *err_mess;
121 int *expression;
122 } result;
123 char status;
124 char *start_ptr;
125 char *end_ptr;
126};
127
128typedef struct regex REGEX;
129
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)
135
136/*
137 * Forward declarations
138 */
139extern int nlines; /* Number of lines in file */
140extern LINE *header; /* Head of line list */
141extern LINE *tail; /* Last line in line list */
142extern LINE *top_line; /* First line of screen */
143extern LINE *bot_line; /* Last line of screen */
144extern LINE *cur_line; /* Current line in use */
145extern char *cur_text; /* Pointer to char on current line in use */
146extern int last_y; /* Last y of screen. Usually SCREENMAX */
147extern int ymax;
148extern int screenmax;
149extern char screen[SCREEN_SIZE];/* Output buffer for "writes" and "reads" */
150
151extern int x, y; /* x, y coordinates on screen */
152extern FLAG modified; /* Set when file is modified */
153extern FLAG stat_visible; /* Set if status_line is visible */
154extern FLAG writable; /* Set if file cannot be written */
155extern FLAG quit; /* Set when quit character is typed */
156extern FLAG rpipe; /* Set if file should be read from stdin */
157extern int input_fd; /* Fd for command input */
158extern FLAG loading; /* Set if we're loading a file */
159extern int out_count; /* Index in output buffer */
160extern char file_name[LINE_LEN]; /* Name of file in use */
161extern char text_buffer[MAX_CHARS]; /* Buffer for modifying text */
162extern char *blank_line; /* Clear line to end */
163
164extern char yank_file[]; /* Temp file for buffer */
165extern FLAG yank_status; /* Status of yank_file */
166extern long chars_saved; /* Nr of chars saved in buffer */
167
168/*
169 * Empty output buffer
170 */
171#define clear_buffer() (out_count = 0)
172
173/*
174 * Print character on terminal
175 */
176#define putchar(c) (void) write_char(STD_OUT, (c))
177
178/*
179 * Ring bell on terminal
180 */
181#define ring_bell() putchar('\07')
182
183/*
184 * Print string on terminal
185 */
186#define string_print(str) (void) writeline(STD_OUT, (str))
187
188/*
189 * Flush output buffer
190 */
191#define flush() (void) flush_buffer(STD_OUT)
192
193/*
194 * Convert cnt to nearest tab position
195 */
196#define tab(cnt) (((cnt) + 8) & ~07)
197#define is_tab(c) ((c) == '\t')
198
199/*
200 * Word defenitions
201 */
202#define white_space(c) ((c) == ' ' || (c) == '\t')
203#define alpha(c) ((c) != ' ' && (c) != '\t' && (c) != '\n')
204
205/*
206 * Print line on terminal at offset 0 and clear tail of line
207 */
208#define line_print(line) put_line(line, 0, TRUE)
209
210/*
211 * Move to coordinates and set textp. (Don't use address)
212 */
213#define move_to(nx, ny) move((nx), NIL_PTR, (ny))
214
215/*
216 * Move to coordinates on screen as indicated by textp.
217 */
218#define move_address(address) move(0, (address), y)
219
220/*
221 * Functions handling status_line. ON means in reverse video.
222 */
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, \
229 NIL_PTR, FALSE)
230
231/*
232 * Print info about current file and buffer.
233 */
234#define fstatus(mess, cnt) file_status((mess), (cnt), file_name, \
235 nlines, writable, modified)
236
237/*
238 * Get real shift value.
239 */
240#define get_shift(cnt) ((cnt) & DUMMY_MASK)
241
242#endif /* YMAX */
243
244/* mined1.c */
245
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 ));
275/*
276#ifdef UNIX
277_PROTOTYPE(void (*key_map [128]), (void));
278#else
279_PROTOTYPE(void (*key_map [256]), (void));
280#endif
281*/
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 ));
296#if __STDC__
297void build_string(char *buf, char *fmt, ...);
298#else
299void build_string();
300#endif
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));
309
310/* mined2.c */
311
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));
Note: See TracBrowser for help on using the repository browser.