xref: /dragonfly/bin/mined/mined.h (revision 6bd457ed)
1 /*
2  *      Copyright (c) 1987,1997, Prentice Hall
3  *      All rights reserved.
4  *
5  *      Redistribution and use of the MINIX operating system in source and
6  *      binary forms, with or without modification, are permitted provided
7  *      that the following conditions are met:
8  *
9  *         * Redistributions of source code must retain the above copyright
10  *           notice, this list of conditions and the following disclaimer.
11  *
12  *         * Redistributions in binary form must reproduce the above
13  *           copyright notice, this list of conditions and the following
14  *           disclaimer in the documentation and/or other materials provided
15  *           with the distribution.
16  *
17  *         * Neither the name of Prentice Hall nor the names of the software
18  *           authors or contributors may be used to endorse or promote
19  *           products derived from this software without specific prior
20  *           written permission.
21  *
22  *      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND
23  *      CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24  *      INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  *      MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  *      IN NO EVENT SHALL PRENTICE HALL OR ANY AUTHORS OR CONTRIBUTORS BE
27  *      LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  *      CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  *      SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30  *      BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31  *      WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32  *      OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33  *      EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  * [original code from minix codebase]
36  * $DragonFly: src/bin/mined/mined.h,v 1.4 2005/03/15 02:32:57 dillon Exp $*
37  */
38 /*========================================================================*
39  *				Mined.h					  *
40  *========================================================================*/
41 
42 #define _PROTOTYPE(a, b)	a b
43 #define INTEL	1
44 #define CHIP	INTEL
45 #define ASSUME_CONS25
46 #define ASSUME_XTERM
47 
48 #include <sys/types.h>
49 #include <fcntl.h>
50 #include <stdlib.h>
51 #include <unistd.h>
52 #include <limits.h>
53 
54 #ifndef YMAX
55 #ifdef UNIX
56 #include <stdio.h>
57 #undef putchar
58 #undef getchar
59 #undef NULL
60 #undef EOF
61 extern char *CE, *VS, *SO, *SE, *CL, *AL, *CM;
62 #define YMAX		49
63 #else
64 #define YMAX		24		/* Maximum y coordinate starting at 0 */
65 /* Escape sequences. */
66 extern char *enter_string;	/* String printed on entering mined */
67 extern char *rev_video;		/* String for starting reverse video */
68 extern char *normal_video;	/* String for leaving reverse video */
69 extern char *rev_scroll;	/* String for reverse scrolling */
70 extern char *pos_string;	/* Absolute cursor positioning */
71 #define X_PLUS	' '		/* To be added to x for cursor sequence */
72 #define Y_PLUS	' '		/* To be added to y for cursor sequence */
73 #endif /* UNIX */
74 
75 #define XMAX		79		/* Maximum x coordinate starting at 0*/
76 #define SCREENMAX	(YMAX - 1)	/* Number of lines displayed */
77 #define XBREAK		(XMAX - 1)	/* Line shift at this coordinate */
78 #define SHIFT_SIZE	25		/* Number of chars to shift */
79 #define SHIFT_MARK	'!'		/* Char indicating line continues */
80 #define MAX_CHARS	1024		/* Maximum chars on one line */
81 
82 /* LINE_START must be rounded up to the lowest SHIFT_SIZE */
83 #define LINE_START	(((-MAX_CHARS - 1) / SHIFT_SIZE) * SHIFT_SIZE \
84   				   - SHIFT_SIZE)
85 #define LINE_END	(MAX_CHARS + 1)	/* Highest x-coordinate for line */
86 
87 #define LINE_LEN	(XMAX + 1)	/* Number of characters on line */
88 #define SCREEN_SIZE	(XMAX * YMAX)	/* Size of I/O buffering */
89 #define BLOCK_SIZE	1024
90 
91 /* Return values of functions */
92 #define ERRORS		-1
93 #define NO_LINE		(ERRORS - 1)	/* Must be < 0 */
94 #define FINE	 	(ERRORS + 1)
95 #define NO_INPUT	(ERRORS + 2)
96 
97 #define STD_OUT	 	1		/* File descriptor for terminal */
98 
99 #if (CHIP == INTEL)
100 #define MEMORY_SIZE	(50 * 1024)	/* Size of data space to malloc */
101 #endif
102 
103 #define REPORT	2			/* Report change of lines on # lines */
104 
105 typedef int FLAG;
106 
107 /* General flags */
108 #define	FALSE		0
109 #define	TRUE		1
110 #define	NOT_VALID	2
111 #define	VALID		3
112 #define	OFF		4
113 #define	ON		5
114 
115 /* Expression flags */
116 #define	FORWARD		6
117 #define	REVERSE		7
118 
119 /* Yank flags */
120 #define	SMALLER		8
121 #define	BIGGER		9
122 #define	SAME		10
123 #define	EMPTY		11
124 #define	NO_DELETE	12
125 #define	DELETE		13
126 #define	READ		14
127 #define	WRITE		15
128 
129 /*
130  * The Line structure.  Each line entry contains a pointer to the next line,
131  * a pointer to the previous line, a pointer to the text and an unsigned char
132  * telling at which offset of the line printing should start (usually 0).
133  */
134 struct Line {
135   struct Line *next;
136   struct Line *prev;
137   char *text;
138   unsigned char shift_count;
139 };
140 
141 typedef struct Line LINE;
142 
143 /* Dummy line indicator */
144 #define DUMMY		0x80
145 #define DUMMY_MASK	0x7F
146 
147 /* Expression definitions */
148 #define NO_MATCH	0
149 #define MATCH		1
150 #define REG_ERROR	2
151 
152 #define BEGIN_LINE	(2 * REG_ERROR)
153 #define END_LINE	(2 * BEGIN_LINE)
154 
155 /*
156  * The regex structure. Status can be any of 0, BEGIN_LINE or REG_ERROR. In
157  * the last case, the result.err_mess field is assigned. Start_ptr and end_ptr
158  * point to the match found. For more details see the documentation file.
159  */
160 struct regex {
161   union {
162   	char *err_mess;
163   	int *expression;
164   } result;
165   char status;
166   char *start_ptr;
167   char *end_ptr;
168 };
169 
170 typedef struct regex REGEX;
171 
172 /* NULL definitions */
173 #define NIL_PTR		((char *) 0)
174 #define NIL_LINE	((LINE *) 0)
175 #define NIL_REG		((REGEX *) 0)
176 #define NIL_INT		((int *) 0)
177 
178 /*
179  * Forward declarations
180  */
181 extern int nlines;		/* Number of lines in file */
182 extern LINE *header;		/* Head of line list */
183 extern LINE *tail;		/* Last line in line list */
184 extern LINE *top_line;		/* First line of screen */
185 extern LINE *bot_line;		/* Last line of screen */
186 extern LINE *cur_line;		/* Current line in use */
187 extern char *cur_text;		/* Pointer to char on current line in use */
188 extern int last_y;		/* Last y of screen. Usually SCREENMAX */
189 extern int ymax;
190 extern int screenmax;
191 extern char screen[SCREEN_SIZE];/* Output buffer for "writes" and "reads" */
192 
193 extern int x, y;			/* x, y coordinates on screen */
194 extern FLAG modified;			/* Set when file is modified */
195 extern FLAG stat_visible;		/* Set if status_line is visible */
196 extern FLAG writable;			/* Set if file cannot be written */
197 extern FLAG quit;			/* Set when quit character is typed */
198 extern FLAG rpipe;		/* Set if file should be read from stdin */
199 extern int input_fd;			/* Fd for command input */
200 extern FLAG loading;			/* Set if we're loading a file */
201 extern int out_count;			/* Index in output buffer */
202 extern char file_name[LINE_LEN];	/* Name of file in use */
203 extern char text_buffer[MAX_CHARS];	/* Buffer for modifying text */
204 extern char *blank_line;		/* Clear line to end */
205 
206 extern char yank_file[];		/* Temp file for buffer */
207 extern FLAG yank_status;		/* Status of yank_file */
208 extern long chars_saved;		/* Nr of chars saved in buffer */
209 
210 /*
211  * Empty output buffer
212  */
213 #define clear_buffer()			(out_count = 0)
214 
215 /*
216  * Print character on terminal
217  */
218 #define putchar(c)			(void) write_char(STD_OUT, (c))
219 
220 /*
221  * Ring bell on terminal
222  */
223 #define ring_bell()			putchar('\07')
224 
225 /*
226  * Print string on terminal
227  */
228 #define string_print(str)		(void) writeline(STD_OUT, (str))
229 
230 /*
231  * Flush output buffer
232  */
233 #define flush()				(void) flush_buffer(STD_OUT)
234 
235 /*
236  * Convert cnt to nearest tab position
237  */
238 #define tab(cnt)			(((cnt) + 8) & ~07)
239 #define is_tab(c)			((c) == '\t')
240 
241 /*
242  * Word defenitions
243  */
244 #define white_space(c)	((c) == ' ' || (c) == '\t')
245 #define alpha(c)	((c) != ' ' && (c) != '\t' && (c) != '\n')
246 
247 /*
248  * Print line on terminal at offset 0 and clear tail of line
249  */
250 #define line_print(line)		put_line(line, 0, TRUE)
251 
252 /*
253  * Move to coordinates and set textp. (Don't use address)
254  */
255 #define move_to(nx, ny)			move((nx), NIL_PTR, (ny))
256 
257 /*
258  * Move to coordinates on screen as indicated by textp.
259  */
260 #define move_address(address)		move(0, (address), y)
261 
262 /*
263  * Functions handling status_line. ON means in reverse video.
264  */
265 #define status_line(str1, str2)	(void) bottom_line(ON, (str1), \
266 						    (str2), NIL_PTR, FALSE)
267 #define error(str1, str2)	(void) bottom_line(ON, (str1), \
268 						    (str2), NIL_PTR, FALSE)
269 #define get_string(str1,str2, fl) bottom_line(ON, (str1), NIL_PTR, (str2), fl)
270 #define clear_status()		(void) bottom_line(OFF, NIL_PTR, NIL_PTR, \
271 						    NIL_PTR, FALSE)
272 
273 /*
274  * Print info about current file and buffer.
275  */
276 #define fstatus(mess, cnt)	file_status((mess), (cnt), file_name, \
277 					     nlines, writable, modified)
278 
279 /*
280  * Get real shift value.
281  */
282 #define get_shift(cnt)		((cnt) & DUMMY_MASK)
283 
284 #endif /* YMAX */
285 
286 /* mined1.c */
287 
288 _PROTOTYPE(void FS, (void));
289 _PROTOTYPE(void VI, (void));
290 _PROTOTYPE(int WT, (void));
291 _PROTOTYPE(void XWT, (void));
292 _PROTOTYPE(void SH, (void));
293 _PROTOTYPE(LINE *proceed, (LINE *line, int count ));
294 _PROTOTYPE(int bottom_line, (FLAG revfl, char *s1, char *s2, char *inbuf, FLAG statfl ));
295 _PROTOTYPE(int count_chars, (LINE *line ));
296 _PROTOTYPE(void move, (int new_x, char *new_address, int new_y ));
297 _PROTOTYPE(int find_x, (LINE *line, char *address ));
298 _PROTOTYPE(char *find_address, (LINE *line, int x_coord, int *old_x ));
299 _PROTOTYPE(int length_of, (char *string ));
300 _PROTOTYPE(void copy_string, (char *to, char *from ));
301 _PROTOTYPE(void reset, (LINE *head_line, int screen_y ));
302 _PROTOTYPE(void set_cursor, (int nx, int ny ));
303 _PROTOTYPE(void open_device, (void));
304 _PROTOTYPE(int getchar, (void));
305 _PROTOTYPE(void display, (int x_coord, int y_coord, LINE *line, int count ));
306 _PROTOTYPE(int write_char, (int fd, int c ));
307 _PROTOTYPE(int writeline, (int fd, char *text ));
308 _PROTOTYPE(void put_line, (LINE *line, int offset, FLAG clear_line ));
309 _PROTOTYPE(int flush_buffer, (int fd ));
310 _PROTOTYPE(void bad_write, (int fd ));
311 _PROTOTYPE(void catch, (int sig ));
312 _PROTOTYPE(void abort_mined, (void));
313 _PROTOTYPE(void raw_mode, (FLAG state ));
314 _PROTOTYPE(void panic, (char *message ));
315 _PROTOTYPE(char *alloc, (int bytes ));
316 _PROTOTYPE(void free_space, (char *p ));
317 /*
318 #ifdef UNIX
319 _PROTOTYPE(void (*key_map [128]), (void));
320 #else
321 _PROTOTYPE(void (*key_map [256]), (void));
322 #endif
323 */
324 _PROTOTYPE(void initialize, (void));
325 _PROTOTYPE(char *basename, (char *path ));
326 _PROTOTYPE(void load_file, (char *file ));
327 _PROTOTYPE(int get_line, (int fd, char *buffer ));
328 _PROTOTYPE(LINE *install_line, (char *buffer, int length ));
329 _PROTOTYPE(int main, (int argc, char *argv []));
330 _PROTOTYPE(void RD, (void));
331 _PROTOTYPE(void I, (void));
332 _PROTOTYPE(void XT, (void));
333 _PROTOTYPE(void ESC, (void));
334 _PROTOTYPE(int ask_save, (void));
335 _PROTOTYPE(int line_number, (void));
336 _PROTOTYPE(void file_status, (char *message, long count, char *file, int lines,
337 						 FLAG writefl, FLAG changed ));
338 #if __STDC__
339 void build_string(char *buf, char *fmt, ...);
340 #else
341 void build_string();
342 #endif
343 _PROTOTYPE(char *num_out, (long number ));
344 _PROTOTYPE(int get_number, (char *message, int *result ));
345 _PROTOTYPE(int input, (char *inbuf, FLAG clearfl ));
346 _PROTOTYPE(int get_file, (char *message, char *file ));
347 _PROTOTYPE(int _getchar, (void));
348 _PROTOTYPE(void _flush, (void));
349 _PROTOTYPE(void _putchar, (int c ));
350 _PROTOTYPE(void get_term, (void));
351 
352 /* mined2.c */
353 
354 _PROTOTYPE(void UP, (void));
355 _PROTOTYPE(void DN, (void));
356 _PROTOTYPE(void LF, (void));
357 _PROTOTYPE(void RT, (void));
358 _PROTOTYPE(void HIGH, (void));
359 _PROTOTYPE(void LOW, (void));
360 _PROTOTYPE(void BL, (void));
361 _PROTOTYPE(void EL, (void));
362 _PROTOTYPE(void GOTO, (void));
363 _PROTOTYPE(void HLP, (void));
364 _PROTOTYPE(void ST, (void));
365 _PROTOTYPE(void PD, (void));
366 _PROTOTYPE(void PU, (void));
367 _PROTOTYPE(void HO, (void));
368 _PROTOTYPE(void EF, (void));
369 _PROTOTYPE(void SU, (void));
370 _PROTOTYPE(void SD, (void));
371 _PROTOTYPE(int forward_scroll, (void));
372 _PROTOTYPE(int reverse_scroll, (void));
373 _PROTOTYPE(void MP, (void));
374 _PROTOTYPE(void move_previous_word, (FLAG remove ));
375 _PROTOTYPE(void MN, (void));
376 _PROTOTYPE(void move_next_word, (FLAG remove ));
377 _PROTOTYPE(void DCC, (void));
378 _PROTOTYPE(void DPC, (void));
379 _PROTOTYPE(void DLN, (void));
380 _PROTOTYPE(void DNW, (void));
381 _PROTOTYPE(void DPW, (void));
382 _PROTOTYPE(void S, (int character ));
383 _PROTOTYPE(void CTL, (void));
384 _PROTOTYPE(void LIB, (void));
385 _PROTOTYPE(LINE *line_insert, (LINE *line, char *string, int len ));
386 _PROTOTYPE(int insert, (LINE *line, char *location, char *string ));
387 _PROTOTYPE(LINE *line_delete, (LINE *line ));
388 _PROTOTYPE(void delete, (LINE *start_line, char *start_textp, LINE *end_line, char *end_textp ));
389 _PROTOTYPE(void PT, (void));
390 _PROTOTYPE(void IF, (void));
391 _PROTOTYPE(void file_insert, (int fd, FLAG old_pos ));
392 _PROTOTYPE(void WB, (void));
393 _PROTOTYPE(void MA, (void));
394 _PROTOTYPE(void YA, (void));
395 _PROTOTYPE(void DT, (void));
396 _PROTOTYPE(void set_up, (FLAG remove ));
397 _PROTOTYPE(FLAG checkmark, (void));
398 _PROTOTYPE(int legal, (void));
399 _PROTOTYPE(void yank, (LINE *start_line, char *start_textp, LINE *end_line, char *end_textp, FLAG remove ));
400 _PROTOTYPE(int scratch_file, (FLAG mode ));
401 _PROTOTYPE(void SF, (void));
402 _PROTOTYPE(void SR, (void));
403 _PROTOTYPE(REGEX *get_expression, (char *message ));
404 _PROTOTYPE(void GR, (void));
405 _PROTOTYPE(void LR, (void));
406 _PROTOTYPE(void change, (char *message, FLAG file ));
407 _PROTOTYPE(char *substitute, (LINE *line, REGEX *program, char *replacement ));
408 _PROTOTYPE(void search, (char *message, FLAG method ));
409 _PROTOTYPE(int find_y, (LINE *match_line ));
410 _PROTOTYPE(void finished, (REGEX *program, int *last_exp ));
411 _PROTOTYPE(void compile, (char *pattern, REGEX *program ));
412 _PROTOTYPE(LINE *match, (REGEX *program, char *string, FLAG method ));
413 _PROTOTYPE(int line_check, (REGEX *program, char *string, FLAG method ));
414 _PROTOTYPE(int check_string, (REGEX *program, char *string, int *expression ));
415 _PROTOTYPE(int star, (REGEX *program, char *end_position, char *string, int *expression ));
416 _PROTOTYPE(int in_list, (int *list, int c, int list_length, int opcode ));
417 _PROTOTYPE(void dummy_line, (void));
418