dhcpcd: update README.DRAGONFLY
[dragonfly.git] / bin / mined / mined.h
blob53dc6de32062199c721155f6d22701b92fcf590e
1 /*
2 * Copyright (c) 1987,1997, Prentice Hall
3 * All rights reserved.
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:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
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.
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.
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.
35 * [original code from minix codebase]
37 /*========================================================================*
38 * Mined.h *
39 *========================================================================*/
41 #define INTEL 1
42 #define CHIP INTEL
43 #define ASSUME_CONS25
44 #define ASSUME_XTERM
46 #include <sys/param.h>
47 #include <fcntl.h>
48 #include <stdlib.h>
49 #include <unistd.h>
50 #include <limits.h>
52 #ifndef YMAX
53 #ifdef UNIX
54 #include <stdio.h>
55 #undef putchar
56 #undef getchar
57 #undef NULL
58 #undef EOF
59 extern char *CE, *VS, *SO, *SE, *CL, *AL, *CM;
60 #define YMAX 49
61 #else
62 #define YMAX 24 /* Maximum y coordinate starting at 0 */
63 /* Escape sequences. */
64 extern const char *enter_string; /* String printed on entering mined */
65 extern const char *rev_video; /* String for starting reverse video */
66 extern const char *normal_video; /* String for leaving reverse video */
67 extern const char *rev_scroll; /* String for reverse scrolling */
68 extern const char *pos_string; /* Absolute cursor positioning */
69 #define X_PLUS ' ' /* To be added to x for cursor sequence */
70 #define Y_PLUS ' ' /* To be added to y for cursor sequence */
71 #endif /* UNIX */
73 #define XMAX 79 /* Maximum x coordinate starting at 0*/
74 #define SCREENMAX (YMAX - 1) /* Number of lines displayed */
75 #define XBREAK (XMAX - 1) /* Line shift at this coordinate */
76 #define SHIFT_SIZE 25 /* Number of chars to shift */
77 #define SHIFT_MARK '!' /* Char indicating line continues */
78 #define MAX_CHARS 1024 /* Maximum chars on one line */
80 /* LINE_START must be rounded up to the lowest SHIFT_SIZE */
81 #define LINE_START (rounddown(-MAX_CHARS - 1, SHIFT_SIZE) - SHIFT_SIZE)
82 #define LINE_END (MAX_CHARS + 1) /* Highest x-coordinate for line */
84 #define LINE_LEN (XMAX + 1) /* Number of characters on line */
85 #define SCREEN_SIZE (XMAX * YMAX) /* Size of I/O buffering */
86 #define BLOCK_SIZE 1024
88 /* Return values of functions */
89 #define ERRORS -1
90 #define NO_LINE (ERRORS - 1) /* Must be < 0 */
91 #define FINE (ERRORS + 1)
92 #define NO_INPUT (ERRORS + 2)
94 #define STD_OUT 1 /* File descriptor for terminal */
96 #if (CHIP == INTEL)
97 #define MEMORY_SIZE (50 * 1024) /* Size of data space to malloc */
98 #endif
100 #define REPORT 2 /* Report change of lines on # lines */
102 typedef int FLAG;
104 /* General flags */
105 #define FALSE 0
106 #define TRUE 1
107 #define NOT_VALID 2
108 #define VALID 3
109 #define OFF 4
110 #define ON 5
112 /* Expression flags */
113 #define FORWARD 6
114 #define REVERSE 7
116 /* Yank flags */
117 #define SMALLER 8
118 #define BIGGER 9
119 #define SAME 10
120 #define EMPTY 11
121 #define NO_DELETE 12
122 #define DELETE 13
123 #define READ 14
124 #define WRITE 15
127 * The Line structure. Each line entry contains a pointer to the next line,
128 * a pointer to the previous line, a pointer to the text and an unsigned char
129 * telling at which offset of the line printing should start (usually 0).
131 struct Line {
132 struct Line *next;
133 struct Line *prev;
134 char *text;
135 unsigned char shift_count;
138 typedef struct Line LINE;
140 /* Dummy line indicator */
141 #define DUMMY 0x80
142 #define DUMMY_MASK 0x7F
144 /* Expression definitions */
145 #define NO_MATCH 0
146 #define MATCH 1
147 #define REG_ERROR 2
149 #define BEGIN_LINE (2 * REG_ERROR)
150 #define END_LINE (2 * BEGIN_LINE)
153 * The regex structure. Status can be any of 0, BEGIN_LINE or REG_ERROR. In
154 * the last case, the result.err_mess field is assigned. Start_ptr and end_ptr
155 * point to the match found. For more details see the documentation file.
157 struct regex {
158 union {
159 const char *err_mess;
160 int *expression;
161 } result;
162 char status;
163 char *start_ptr;
164 char *end_ptr;
167 typedef struct regex REGEX;
169 /* NULL definitions */
170 #define NIL_PTR ((char *) 0)
171 #define NIL_LINE ((LINE *) 0)
172 #define NIL_REG ((REGEX *) 0)
173 #define NIL_INT ((int *) 0)
176 * Forward declarations
178 extern int nlines; /* Number of lines in file */
179 extern LINE *header; /* Head of line list */
180 extern LINE *tail; /* Last line in line list */
181 extern LINE *top_line; /* First line of screen */
182 extern LINE *bot_line; /* Last line of screen */
183 extern LINE *cur_line; /* Current line in use */
184 extern char *cur_text; /* Pointer to char on current line in use */
185 extern int last_y; /* Last y of screen. Usually SCREENMAX */
186 extern int ymax;
187 extern int screenmax;
188 extern char screen[SCREEN_SIZE];/* Output buffer for "writes" and "reads" */
190 extern int x, y; /* x, y coordinates on screen */
191 extern FLAG modified; /* Set when file is modified */
192 extern FLAG stat_visible; /* Set if status_line is visible */
193 extern FLAG writable; /* Set if file cannot be written */
194 extern FLAG quit; /* Set when quit character is typed */
195 extern FLAG rpipe; /* Set if file should be read from stdin */
196 extern int input_fd; /* Fd for command input */
197 extern FLAG loading; /* Set if we're loading a file */
198 extern int out_count; /* Index in output buffer */
199 extern char file_name[LINE_LEN]; /* Name of file in use */
200 extern char text_buffer[MAX_CHARS]; /* Buffer for modifying text */
201 extern const char *blank_line; /* Clear line to end */
203 extern char yank_file[]; /* Temp file for buffer */
204 extern FLAG yank_status; /* Status of yank_file */
205 extern long chars_saved; /* Nr of chars saved in buffer */
208 * Empty output buffer
210 #define clear_buffer() (out_count = 0)
213 * Print character on terminal
215 #define putchar(c) write_char(STD_OUT, (c))
218 * Ring bell on terminal
220 #define ring_bell() putchar('\07')
223 * Print string on terminal
225 #define string_print(str) writeline(STD_OUT, (str))
228 * Flush output buffer
230 #define flush() flush_buffer(STD_OUT)
233 * Convert cnt to nearest tab position
235 #define tab(cnt) (((cnt) + 8) & ~07)
236 #define is_tab(c) ((c) == '\t')
239 * Word defenitions
241 #define white_space(c) ((c) == ' ' || (c) == '\t')
242 #define alpha(c) ((c) != ' ' && (c) != '\t' && (c) != '\n')
245 * Print line on terminal at offset 0 and clear tail of line
247 #define line_print(line) put_line(line, 0, TRUE)
250 * Move to coordinates and set textp. (Don't use address)
252 #define move_to(nx, ny) move((nx), NIL_PTR, (ny))
255 * Move to coordinates on screen as indicated by textp.
257 #define move_address(address) move(0, (address), y)
260 * Functions handling status_line. ON means in reverse video.
262 #define status_line(str1, str2) bottom_line(ON, (str1), (str2), NIL_PTR, FALSE)
263 #define error(str1, str2) bottom_line(ON, (str1), (str2), NIL_PTR, FALSE)
264 #define get_string(str1,str2, fl) bottom_line(ON, (str1), NIL_PTR, (str2), fl)
265 #define clear_status() bottom_line(OFF, NIL_PTR, NIL_PTR, \
266 NIL_PTR, FALSE)
269 * Print info about current file and buffer.
271 #define fstatus(mess, cnt) file_status((mess), (cnt), file_name, \
272 nlines, writable, modified)
275 * Get real shift value.
277 #define get_shift(cnt) ((cnt) & DUMMY_MASK)
279 #endif /* YMAX */
281 /* mined1.c */
283 void FS(int);
284 void VI(int);
285 int WT(void);
286 void XWT(int);
287 void SH(int);
288 LINE *proceed(LINE *line, int count);
289 int bottom_line(FLAG revfl, const char *s1, const char *s2, char *inbuf, FLAG statfl);
290 int count_chars(LINE *line);
291 void move(int new_x, char *new_address, int new_y);
292 int find_x(LINE *line, char *address);
293 char *find_address(LINE *line, int x_coord, int *old_x);
294 int length_of(char *string);
295 void copy_string(char *to, const char *from);
296 void reset(LINE *head_line, int screen_y);
297 void set_cursor(int nx, int ny);
298 void open_device(void);
299 int getchar(void);
300 void display(int x_coord, int y_coord, LINE *line, int count);
301 int write_char(int fd, char c);
302 int writeline(int fd, const char *text);
303 void put_line(LINE *line, int offset, FLAG clear_line);
304 int flush_buffer(int fd);
305 void bad_write(int fd);
306 void catch(int sig);
307 void abort_mined(void);
308 void raw_mode(FLAG state);
309 void panic(const char *message) __dead2;
310 void *alloc(int bytes);
311 void free_space(char *p);
312 void initialize(void);
313 char *basename(char *path);
314 void load_file(const char *file);
315 int get_line(int fd, char *buffer);
316 LINE *install_line(const char *buffer, int length);
317 void RD(int);
318 void I(int);
319 void XT(int);
320 void ESC(int);
321 int ask_save(void);
322 int line_number(void);
323 void file_status(const char *message, long count, char *file, int lines,
324 FLAG writefl, FLAG changed);
325 void build_string(char *buf, const char *fmt, ...);
326 char *num_out(long number);
327 int get_number(const char *message, int *result);
328 int input(char *inbuf, FLAG clearfl);
329 int get_file(const char *message, char *file);
330 int _getchar(void);
331 void _flush(void);
332 void _putchar(int c);
333 void get_term(void);
335 /* mined2.c */
337 void UP(int);
338 void DN(int);
339 void LF(int);
340 void RT(int);
341 void HIGH(int);
342 void LOW(int);
343 void BL(int);
344 void EL(int);
345 void GOTO(int);
346 void HLP(int);
347 void ST(int);
348 void PD(int);
349 void PU(int);
350 void HO(int);
351 void EF(int);
352 void SU(int);
353 void SD(int);
354 int forward_scroll(void);
355 int reverse_scroll(void);
356 void MP(int);
357 void move_previous_word(FLAG remove);
358 void MN(int);
359 void move_next_word(FLAG remove);
360 void DCC(int);
361 void DPC(int);
362 void DLN(int);
363 void DNW(int);
364 void DPW(int);
365 void S(int character);
366 void CTL(int);
367 void LIB(int);
368 LINE *line_insert(LINE *line, const char *string, int len);
369 int insert(LINE *line, char *location, char *string);
370 LINE *line_delete(LINE *line);
371 void delete(LINE *start_line, char *start_textp,
372 LINE *end_line, char *end_textp);
373 void PT(int);
374 void IF(int);
375 void file_insert(int fd, FLAG old_pos);
376 void WB(int);
377 void MA(int);
378 void YA(int);
379 void DT(int);
380 void set_up(FLAG remove);
381 FLAG checkmark(void);
382 int legal(void);
383 void yank(LINE *start_line, char *start_textp,
384 LINE *end_line, char *end_textp, FLAG remove);
385 int scratch_file(FLAG mode);
386 void SF(int);
387 void SR(int);
388 REGEX *get_expression(const char *message);
389 void GR(int);
390 void LR(int);
391 void change(const char *message, FLAG file);
392 char *substitute(LINE *line, REGEX *program, char *replacement);
393 void search(const char *message, FLAG method);
394 int find_y(LINE *match_line);
395 void finished(REGEX *program, int *last_exp);
396 void compile(char *pattern, REGEX *program);
397 LINE *match(REGEX *program, char *string, FLAG method);
398 int line_check(REGEX *program, char *string, FLAG method);
399 int check_string(REGEX *program, char *string, int *expression);
400 int star(REGEX *program, char *end_position, char *string,
401 int *expression);
402 int in_list(int *list, char c, int list_length, int opcode);
403 void dummy_line(void);