* Update to version 2.19.5
[alpine.git] / pico / estruct.h
blobcff5a6de0a03090f01fddb237eb34167e24a440c
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-2014 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 begining 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 */
88 * macros to help filter character input
90 #define CELLMASK 0xffffff
91 #define LOBIT_CHAR(C) ((C) > 0x1f && (C) < 0x7f)
92 #define HIBIT_CHAR(C) ((C) > 0x7f && (C) <= CELLMASK)
93 #define HIBIT_OK(C) (!(gmode & MDHBTIGN))
94 #define VALID_KEY(C) (LOBIT_CHAR(C) || (HIBIT_OK(C) && HIBIT_CHAR(C)))
95 #define ctrl(c) ((c) & 0x1f) /* control character mapping */
99 * Placeholders for keymenu tags used in some ports (well, only in the
100 * windows port for now) to turn on commands in the Menu Bar.
102 #ifndef KS_OSDATAVAR
103 #define KS_OSDATAVAR
104 #define KS_OSDATAGET(X)
105 #define KS_OSDATASET(X, Y)
107 #define KS_NONE
108 #define KS_VIEW
109 #define KS_EXPUNGE
110 #define KS_ZOOM
111 #define KS_SORT
112 #define KS_HDRMODE
113 #define KS_MAINMENU
114 #define KS_FLDRLIST
115 #define KS_FLDRINDEX
116 #define KS_COMPOSER
117 #define KS_PREVPAGE
118 #define KS_PREVMSG
119 #define KS_NEXTMSG
120 #define KS_ADDRBOOK
121 #define KS_WHEREIS
122 #define KS_PRINT
123 #define KS_REPLY
124 #define KS_FORWARD
125 #define KS_BOUNCE
126 #define KS_DELETE
127 #define KS_UNDELETE
128 #define KS_FLAG
129 #define KS_SAVE
130 #define KS_EXPORT
131 #define KS_TAKEADDR
132 #define KS_SELECT
133 #define KS_APPLY
134 #define KS_POSTPONE
135 #define KS_SEND
136 #define KS_CANCEL
137 #define KS_ATTACH
138 #define KS_TOADDRBOOK
139 #define KS_READFILE
140 #define KS_JUSTIFY
141 #define KS_ALTEDITOR
142 #define KS_GENERALHELP
143 #define KS_SCREENHELP
144 #define KS_EXIT
145 #define KS_NEXTPAGE
146 #define KS_SAVEFILE
147 #define KS_CURPOSITION
148 #define KS_GOTOFLDR
149 #define KS_JUMPTOMSG
150 #define KS_RICHHDR
151 #define KS_EXITMODE
152 #define KS_REVIEW
153 #define KS_KEYMENU
154 #define KS_SELECTCUR
155 #define KS_UNDO
156 #define KS_SPELLCHK
157 #endif /* !KS_OSDATAVAR */
161 * There is a window structure allocated for every active display window. The
162 * windows are kept in a big list, in top to bottom screen order, with the
163 * listhead at "wheadp". Each window contains its own values of dot and mark.
164 * The flag field contains some bits that are set by commands to guide
165 * redisplay; although this is a bit of a compromise in terms of decoupling,
166 * the full blown redisplay is just too expensive to run for every input
167 * character.
169 typedef struct WINDOW {
170 struct WINDOW *w_wndp; /* Next window */
171 struct BUFFER *w_bufp; /* Buffer displayed in window */
172 struct LINE *w_linep; /* Top line in the window */
173 struct LINE *w_dotp; /* Line containing "." */
174 int w_doto; /* Byte offset for "." */
175 struct LINE *w_markp; /* Line containing "mark" */
176 int w_marko; /* Byte offset for "mark" */
177 struct LINE *w_imarkp; /* INTERNAL Line with "mark" */
178 int w_imarko; /* INTERNAL "mark" byte offset */
179 signed char w_toprow; /* Origin 0 top row of window */
180 signed char w_ntrows; /* # of rows of text in window */
181 char w_force; /* If NZ, forcing row. */
182 char w_flag; /* Flags. */
183 } WINDOW;
185 #define WFFORCE 0x01 /* Window needs forced reframe */
186 #define WFMOVE 0x02 /* Movement from line to line */
187 #define WFEDIT 0x04 /* Editing within a line */
188 #define WFHARD 0x08 /* Better to a full display */
189 #define WFMODE 0x10 /* Update mode line. */
192 * Text is kept in buffers. A buffer header, described below, exists for every
193 * buffer in the system. The buffers are kept in a big list, so that commands
194 * that search for a buffer by name can find the buffer header. There is a
195 * safe store for the dot and mark in the header, but this is only valid if
196 * the buffer is not being displayed (that is, if "b_nwnd" is 0). The text for
197 * the buffer is kept in a circularly linked list of lines, with a pointer to
198 * the header line in "b_linep".
199 * Buffers may be "Inactive" which means the files accosiated with them
200 * have not been read in yet. These get read in at "use buffer" time.
202 typedef struct BUFFER {
203 struct BUFFER *b_bufp; /* Link to next BUFFER */
204 struct LINE *b_dotp; /* Link to "." LINE structure */
205 int b_doto; /* Offset of "." in above LINE */
206 struct LINE *b_markp; /* The same as the above two, */
207 int b_marko; /* but for the "mark" */
208 struct LINE *b_linep; /* Link to the header LINE */
209 long b_linecnt; /* Lines in buffer (mswin only) */
210 long b_mode; /* editor mode of this buffer */
211 char b_active; /* window activated flag */
212 char b_nwnd; /* Count of windows on buffer */
213 char b_flag; /* Flags */
214 char b_fname[NFILEN]; /* File name */
215 char b_bname[NBUFN]; /* Buffer name */
216 } BUFFER;
218 #define BFTEMP 0x01 /* Internal temporary buffer */
219 #define BFCHG 0x02 /* Changed since last write */
220 #define BFWRAPOPEN 0x04 /* Wordwrap should open new line */
224 * The starting position of a region, and the size of the region in
225 * characters, is kept in a region structure. Used by the region commands.
227 typedef struct {
228 struct LINE *r_linep; /* Origin LINE address. */
229 int r_offset; /* Origin LINE offset. */
230 long r_size; /* Length in characters. */
231 } REGION;
235 * character and attribute pair. The basic building block
236 * of the editor. The bitfields may have to be changed to a char
237 * and short if there are problems...
239 typedef struct CELL {
240 unsigned int c : 24; /* Character value in cell */
241 unsigned int a : 8; /* Its attributes */
242 } CELL;
244 /* flags for color_options */
245 #define COLOR_ANSI8_OPT 0x01
246 #define COLOR_ANSI16_OPT 0x02
247 #define COLOR_ANSI256_OPT 0x04
248 #define COLOR_TRANS_OPT 0x08
251 * All text is kept in circularly linked lists of "LINE" structures. These
252 * begin at the header line (which is the blank line beyond the end of the
253 * buffer). This line is pointed to by the "BUFFER". Each line contains the
254 * number of bytes in the line (the "used" size), the size of the text array,
255 * and the text. The end of line is not stored as a byte; it's implied. Future
256 * additions will include update hints, and a list of marks into the line.
258 typedef struct LINE {
259 struct LINE *l_fp; /* Link to the next line */
260 struct LINE *l_bp; /* Link to the previous line */
261 int l_size; /* Allocated size */
262 int l_used; /* Used size */
263 CELL l_text[1]; /* A bunch of characters. */
264 } LINE;
266 #define lforw(lp) ((lp)->l_fp)
267 #define lback(lp) ((lp)->l_bp)
268 #define lgetc(lp, n) ((lp)->l_text[(n)])
269 #define lputc(lp, n, c) ((lp)->l_text[(n)]=(c))
270 #define llength(lp) ((lp)->l_used)
273 * The editor communicates with the display using a high level interface. A
274 * "TERM" structure holds useful variables, and indirect pointers to routines
275 * that do useful operations. The low level get and put routines are here too.
276 * This lets a terminal, in addition to having non standard commands, have
277 * funny get and put character code too. The calls might get changed to
278 * "termp->t_field" style in the future, to make it possible to run more than
279 * one terminal type.
281 typedef struct {
282 short t_nrow; /* Number of rows - 1. */
283 short t_ncol; /* Number of columns. */
284 short t_margin; /* min margin for extended lines*/
285 short t_mrow; /* Number of rows in menu */
286 int (*t_open)(void); /* Open terminal at the start. */
287 int (*t_terminalinfo)(int); /* Set up terminal info */
288 int (*t_close)(void); /* Close terminal at end. */
289 int (*t_getchar)(int return_on_intr,
290 int (*recorder)(int),
291 void (*bail_handler)(void));
292 /* Get character from keyboard. */
293 int (*t_putchar)(UCS); /* Put character to display. */
294 int (*t_flush)(void); /* Flush output buffers. */
295 int (*t_move)(int, int); /* Move the cursor, origin 0. */
296 int (*t_eeol)(void); /* Erase to end of line. */
297 int (*t_eeop)(void); /* Erase to end of page. */
298 int (*t_beep)(void); /* Beep. */
299 int (*t_rev)(int); /* set reverse video state */
300 } TERM;
302 /* structure for the table of initial key bindings */
304 typedef struct {
305 UCS k_code; /* Key code */
306 int (*k_fp)(); /* Routine to handle it */
307 } KEYTAB;
309 /* sturcture used for key menu painting */
311 typedef struct {
312 char *name; /* key to display (UTF-8) */
313 char *label; /* function name key invokes (UTF-8) */
314 KS_OSDATAVAR /* port-specific data */
315 } KEYMENU;
317 typedef struct {
318 char *name; /* key to display */
319 char *label; /* function name key invokes */
320 UCS key; /* what to watch for and return */
321 KS_OSDATAVAR /* port-specific data */
322 } EXTRAKEYS;
324 typedef struct lmlist {
325 char *dir; /* these 3 are all UTF-8 strings */
326 char *fname;
327 char size[32];
328 struct lmlist *next;
329 } LMLIST;
332 typedef struct VIDEO {
333 short v_flag; /* Flags */
334 CELL v_text[1]; /* Screen data. */
335 } VIDEO;
338 typedef union eml {
339 char *s;
340 int d;
341 long l;
342 UCS c;
343 } EML;
345 typedef struct _file_io_data {
346 FILE *fp; /* stdio stream into file */
347 long flags; /* state flags */
348 char *name; /* pointer to file name */
349 } FIOINFO;
351 #define FIOINFO_READ 0x01
352 #define FIOINFO_WRITE 0x02
354 #define ISCONTROL(C) ((C) < 0x20 || (C) == 0x7F \
355 || ((gmode & P_HICTRL) && ((C) > 0x7F && (C) < 0xA0)))
357 #ifdef MOUSE
359 /* Test if mouse position (R, C) is in menu item (X) */
360 #define M_ACTIVE(R, C, X) (((unsigned)(R)) >= (X)->tl.r \
361 && ((unsigned)(R)) <= (X)->br.r \
362 && ((unsigned)(C)) >= (X)->tl.c \
363 && ((unsigned)(C)) < (X)->br.c)
364 #endif /* MOUSE */
366 #endif /* ESTRUCT_H */