* Fix of the list of files in the browser for terminals that need to erase
[alpine.git] / pico / estruct.h
blob95152b6af7c4e2dedd502c4c7fca396840f819c2
1 /*
2 * $Id: estruct.h 767 2007-10-24 00:03:59Z hubert@u.washington.edu $
4 * ========================================================================
5 * Copyright 2006-2007 University of Washington
6 * Copyright 2013-2021 Eduardo Chappa
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * ========================================================================
16 * Program: Struct and preprocessor definitions
20 /* ESTRUCT: Structure and preprocesser defined for
21 MicroEMACS 3.6
23 written by Dave G. Conroy
24 modified by Steve Wilhite, George Jones
25 greatly modified by Daniel Lawrence
28 #ifndef ESTRUCT_H
29 #define ESTRUCT_H
31 /* Configuration options */
33 #define CVMVAS 1 /* arguments to page forward/back in pages */
34 #define NFWORD 1 /* forward word jumps to beginning of word */
35 #define TYPEAH 0 /* type ahead causes update to be skipped */
36 #define REVSTA 1 /* Status line appears in reverse video */
39 /* internal constants */
41 #define NBINDS 50 /* max # of bound keys */
42 #ifdef MAXPATH
43 #define NFILEN MAXPATH /* # of bytes, file name */
44 #else
45 #define NFILEN 200 /* # of bytes, file name */
46 #endif
47 #define NBUFN 16 /* # of bytes, buffer name */
48 #define NLINE 500 /* # of bytes, line */
49 #define NSTRING 256 /* # of bytes, string buffers */
50 #define NPAT 80 /* # of bytes, pattern */
51 #define FARAWAY 1000 /* Huge number */
52 #define NLOCKS 100 /* max # of file locks active */
54 #define AGRAVE 0x60 /* M- prefix, Grave (LK201) */
55 #define METACH 0x1B /* M- prefix, Control-[, ESC */
56 #define CTMECH 0x1C /* C-M- prefix, Control-\ */
57 #define EXITCH 0x1D /* Exit level, Control-] */
58 #define CTRLCH 0x1E /* C- prefix, Control-^ */
59 #define HELPCH 0x1F /* Help key, Control-_ */
61 #define QNORML 0x0000 /* Flag meaning no flag ;) */
62 #define QFFILE 0x0001 /* Flag buffer for file neme */
63 #define QDEFLT 0x0002 /* Flag to use default answer */
64 #define QBOBUF 0x0004 /* Start with cursor at BOL */
65 #define QNODQT 0x0008 /* Don't accept double quotes */
67 #define FIOSUC 0 /* File I/O, success. */
68 #define FIOFNF 1 /* File I/O, file not found. */
69 #define FIOEOF 2 /* File I/O, end of file. */
70 #define FIOERR 3 /* File I/O, error. */
71 #define FIOLNG 4 /*line longer than allowed len */
72 #define FIODIR 5 /* File is a directory */
73 #define FIONWT 6 /* File lacks write permission */
74 #define FIONRD 7 /* File lacks read permission */
75 #define FIONEX 8 /* File lacks exec permission */
76 #define FIOSYM 9 /* File is a symbolic link */
77 #define FIOPER 10 /* Generic permission denied */
80 #define CFCPCN 0x0001 /* Last command was C-P, C-N */
81 #define CFKILL 0x0002 /* Last command was a kill */
82 #define CFFILL 0x0004 /* Last command was a fill */
83 #define CFSRCH 0x0008 /* Last command was WhereIs */
84 #define CFFLBF 0x0010 /* Last cmd was full buf fill */
85 #define CFFLPA 0x0020 /* Last cmd was paragraph fill */
87 /* Constants for search functions */
88 #define SR_ORIGMEN 0x0001 /* search original menu */
89 #define SR_OPTNMEN 0x0002 /* search options menu */
90 #define SR_FORWARD 0x0010 /* search forward */
91 #define SR_BACKWRD 0x0020 /* search backward */
92 #define SR_BEGLINE 0x0040 /* search pattern at beginning of line */
93 #define SR_ENDLINE 0x0080 /* search pattern at end of line */
94 #define SR_EXACTSR 0x0100 /* search exact pattern */
95 #define SR_NOEXACT 0x0200 /* search case insensitive */
99 * macros to help filter character input
101 #define CELLMASK 0xffffff
102 #define LOBIT_CHAR(C) ((C) > 0x1f && (C) < 0x7f)
103 #define HIBIT_CHAR(C) ((C) > 0x7f && (C) <= CELLMASK)
104 #define HIBIT_OK(C) (!(gmode & MDHBTIGN))
105 #define VALID_KEY(C) (LOBIT_CHAR(C) || (HIBIT_OK(C) && HIBIT_CHAR(C)))
106 #define ctrl(c) ((c) & 0x1f) /* control character mapping */
110 * Placeholders for keymenu tags used in some ports (well, only in the
111 * windows port for now) to turn on commands in the Menu Bar.
113 #ifndef KS_OSDATAVAR
114 #define KS_OSDATAVAR
115 #define KS_OSDATAGET(X)
116 #define KS_OSDATASET(X, Y)
118 #define KS_NONE
119 #define KS_VIEW
120 #define KS_EXPUNGE
121 #define KS_ZOOM
122 #define KS_SORT
123 #define KS_HDRMODE
124 #define KS_MAINMENU
125 #define KS_FLDRLIST
126 #define KS_FLDRINDEX
127 #define KS_COMPOSER
128 #define KS_PREVPAGE
129 #define KS_PREVMSG
130 #define KS_NEXTMSG
131 #define KS_ADDRBOOK
132 #define KS_WHEREIS
133 #define KS_PRINT
134 #define KS_REPLY
135 #define KS_FORWARD
136 #define KS_BOUNCE
137 #define KS_DELETE
138 #define KS_UNDELETE
139 #define KS_FLAG
140 #define KS_SAVE
141 #define KS_EXPORT
142 #define KS_TAKEADDR
143 #define KS_SELECT
144 #define KS_APPLY
145 #define KS_POSTPONE
146 #define KS_SEND
147 #define KS_CANCEL
148 #define KS_ATTACH
149 #define KS_TOADDRBOOK
150 #define KS_READFILE
151 #define KS_JUSTIFY
152 #define KS_ALTEDITOR
153 #define KS_GENERALHELP
154 #define KS_SCREENHELP
155 #define KS_EXIT
156 #define KS_NEXTPAGE
157 #define KS_SAVEFILE
158 #define KS_CURPOSITION
159 #define KS_GOTOFLDR
160 #define KS_JUMPTOMSG
161 #define KS_RICHHDR
162 #define KS_EXITMODE
163 #define KS_REVIEW
164 #define KS_KEYMENU
165 #define KS_SELECTCUR
166 #define KS_UNDO
167 #define KS_SPELLCHK
168 #endif /* !KS_OSDATAVAR */
172 * There is a window structure allocated for every active display window. The
173 * windows are kept in a big list, in top to bottom screen order, with the
174 * listhead at "wheadp". Each window contains its own values of dot and mark.
175 * The flag field contains some bits that are set by commands to guide
176 * redisplay; although this is a bit of a compromise in terms of decoupling,
177 * the full blown redisplay is just too expensive to run for every input
178 * character.
180 typedef struct WINDOW {
181 struct WINDOW *w_wndp; /* Next window */
182 struct BUFFER *w_bufp; /* Buffer displayed in window */
183 struct LINE *w_linep; /* Top line in the window */
184 struct LINE *w_dotp; /* Line containing "." */
185 int w_doto; /* Byte offset for "." */
186 struct LINE *w_markp; /* Line containing "mark" */
187 int w_marko; /* Byte offset for "mark" */
188 struct LINE *w_imarkp; /* INTERNAL Line with "mark" */
189 int w_imarko; /* INTERNAL "mark" byte offset */
190 int w_toprow; /* Origin 0 top row of window */
191 int w_ntrows; /* # of rows of text in window */
192 char w_force; /* If NZ, forcing row. */
193 char w_flag; /* Flags. */
194 } WINDOW;
196 #define WFFORCE 0x01 /* Window needs forced reframe */
197 #define WFMOVE 0x02 /* Movement from line to line */
198 #define WFEDIT 0x04 /* Editing within a line */
199 #define WFHARD 0x08 /* Better to a full display */
200 #define WFMODE 0x10 /* Update mode line. */
203 * Text is kept in buffers. A buffer header, described below, exists for every
204 * buffer in the system. The buffers are kept in a big list, so that commands
205 * that search for a buffer by name can find the buffer header. There is a
206 * safe store for the dot and mark in the header, but this is only valid if
207 * the buffer is not being displayed (that is, if "b_nwnd" is 0). The text for
208 * the buffer is kept in a circularly linked list of lines, with a pointer to
209 * the header line in "b_linep".
210 * Buffers may be "Inactive" which means the files accosiated with them
211 * have not been read in yet. These get read in at "use buffer" time.
213 typedef struct BUFFER {
214 struct BUFFER *b_bufp; /* Link to next BUFFER */
215 struct LINE *b_dotp; /* Link to "." LINE structure */
216 int b_doto; /* Offset of "." in above LINE */
217 struct LINE *b_markp; /* The same as the above two, */
218 int b_marko; /* but for the "mark" */
219 struct LINE *b_linep; /* Link to the header LINE */
220 long b_linecnt; /* Lines in buffer (mswin only) */
221 long b_mode; /* editor mode of this buffer */
222 char b_active; /* window activated flag */
223 char b_nwnd; /* Count of windows on buffer */
224 char b_flag; /* Flags */
225 char b_fname[NFILEN]; /* File name */
226 char b_bname[NBUFN]; /* Buffer name */
227 } BUFFER;
229 #define BFTEMP 0x01 /* Internal temporary buffer */
230 #define BFCHG 0x02 /* Changed since last write */
231 #define BFWRAPOPEN 0x04 /* Wordwrap should open new line */
235 * The starting position of a region, and the size of the region in
236 * characters, is kept in a region structure. Used by the region commands.
238 typedef struct {
239 struct LINE *r_linep; /* Origin LINE address. */
240 int r_offset; /* Origin LINE offset. */
241 long r_size; /* Length in characters. */
242 } REGION;
246 * character and attribute pair. The basic building block
247 * of the editor. The bitfields may have to be changed to a char
248 * and short if there are problems...
250 typedef struct CELL {
251 unsigned int c : 24; /* Character value in cell */
252 unsigned int a : 7; /* Its attributes */
253 unsigned int d : 1; /* direction */
254 } CELL;
256 /* flags for color_options */
257 #define COLOR_ANSI8_OPT 0x01
258 #define COLOR_ANSI16_OPT 0x02
259 #define COLOR_ANSI256_OPT 0x04
260 #define COLOR_TRANS_OPT 0x08
263 * All text is kept in circularly linked lists of "LINE" structures. These
264 * begin at the header line (which is the blank line beyond the end of the
265 * buffer). This line is pointed to by the "BUFFER". Each line contains the
266 * number of bytes in the line (the "used" size), the size of the text array,
267 * and the text. The end of line is not stored as a byte; it's implied. Future
268 * additions will include update hints, and a list of marks into the line.
270 typedef struct LINE {
271 struct LINE *l_fp; /* Link to the next line */
272 struct LINE *l_bp; /* Link to the previous line */
273 int l_sig; /* line is part of signature */
274 int l_size; /* Allocated size */
275 int l_used; /* Used size */
276 CELL l_text[1]; /* A bunch of characters. */
277 } LINE;
279 #define lforw(lp) ((lp)->l_fp)
280 #define lback(lp) ((lp)->l_bp)
281 #define lgetc(lp, n) ((lp)->l_text[(n)])
282 #define lputc(lp, n, c) ((lp)->l_text[(n)]=(c))
283 #define llength(lp) ((lp)->l_used)
286 * The editor communicates with the display using a high level interface. A
287 * "TERM" structure holds useful variables, and indirect pointers to routines
288 * that do useful operations. The low level get and put routines are here too.
289 * This lets a terminal, in addition to having non standard commands, have
290 * funny get and put character code too. The calls might get changed to
291 * "termp->t_field" style in the future, to make it possible to run more than
292 * one terminal type.
294 typedef struct {
295 short t_nrow; /* Number of rows - 1. */
296 short t_ncol; /* Number of columns. */
297 short t_margin; /* min margin for extended lines*/
298 short t_mrow; /* Number of rows in menu */
299 int (*t_open)(void); /* Open terminal at the start. */
300 int (*t_terminalinfo)(int); /* Set up terminal info */
301 int (*t_close)(void); /* Close terminal at end. */
302 int (*t_getchar)(int return_on_intr,
303 int (*recorder)(int),
304 void (*bail_handler)(void));
305 /* Get character from keyboard. */
306 int (*t_putchar)(UCS); /* Put character to display. */
307 int (*t_flush)(void); /* Flush output buffers. */
308 int (*t_move)(int, int); /* Move the cursor, origin 0. */
309 int (*t_eeol)(void); /* Erase to end of line. */
310 int (*t_eeop)(void); /* Erase to end of page. */
311 int (*t_beep)(void); /* Beep. */
312 int (*t_rev)(int); /* set reverse video state */
313 int (*t_eri)(void); /* erase reverse inverse */
314 } TERM;
316 /* structure for the table of initial key bindings */
318 typedef struct {
319 UCS k_code; /* Key code */
320 int (*k_fp)(); /* Routine to handle it */
321 } KEYTAB;
323 /* structure used for key menu painting */
325 typedef struct {
326 char *name; /* key to display (UTF-8) */
327 char *label; /* function name key invokes (UTF-8) */
328 KS_OSDATAVAR /* port-specific data */
329 } KEYMENU;
331 typedef struct {
332 char *name; /* key to display */
333 char *label; /* function name key invokes */
334 UCS key; /* what to watch for and return */
335 KS_OSDATAVAR /* port-specific data */
336 } EXTRAKEYS;
338 typedef struct lmlist {
339 char *dir; /* these 3 are all UTF-8 strings */
340 char *fname;
341 char size[32];
342 struct lmlist *next;
343 } LMLIST;
346 typedef struct VIDEO {
347 short v_flag; /* Flags */
348 int v_length; /* length of line */
349 CELL v_text[1]; /* Screen data. */
350 } VIDEO;
353 typedef union eml {
354 char *s;
355 int d;
356 long l;
357 UCS c;
358 } EML;
360 typedef struct _file_io_data {
361 FILE *fp; /* stdio stream into file */
362 long flags; /* state flags */
363 char *name; /* pointer to file name */
364 } FIOINFO;
366 #define FIOINFO_READ 0x01
367 #define FIOINFO_WRITE 0x02
369 #define ISCONTROL(C) ((C) < 0x20 || (C) == 0x7F \
370 || ((gmode & P_HICTRL) && ((C) > 0x7F && (C) < 0xA0)))
372 #ifdef MOUSE
374 /* Test if mouse position (R, C) is in menu item (X) */
375 #define M_ACTIVE(R, C, X) (((unsigned)(R)) >= (X)->tl.r \
376 && ((unsigned)(R)) <= (X)->br.r \
377 && ((unsigned)(C)) >= (X)->tl.c \
378 && ((unsigned)(C)) < (X)->br.c)
379 #endif /* MOUSE */
381 #endif /* ESTRUCT_H */