* Fix bug in new code that determines the name of the container if
[alpine.git] / pico / pico.h
blob73e1ffcd9f71c948d49cfa657ae5e1d34514e2dd
1 /*
2 * $Id: pico.h 1204 2009-02-02 19:54:23Z hubert@u.washington.edu $
4 * ========================================================================
5 * Copyright 2006-2009 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: pico.h - definitions for Pine's composer library
19 #ifndef PICO_H
20 #define PICO_H
22 #include "mode.h"
24 #include "../pith/osdep/color.h"
25 #include "../pith/osdep/err_desc.h"
26 #include "../pith/charconv/utf8.h"
28 #define errstr(n) error_description(n)
31 * Defined for attachment support
33 #define ATTACHMENTS 1
37 * defs of return codes from pine mailer composer.
39 #define BUF_CHANGED 0x01
40 #define COMP_CANCEL 0x02
41 #define COMP_EXIT 0x04
42 #define COMP_FAILED 0x08
43 #define COMP_SUSPEND 0x10
44 #define COMP_GOTHUP 0x20
48 * top line from the top of the screen for the editor to do
49 * its stuff
51 #define COMPOSER_TOP_LINE 2
52 #define COMPOSER_TITLE_LINE 0
56 #define HLSZ NLINE
59 * definitions of Mail header structures
61 struct hdr_line {
62 UCS text[HLSZ];
63 struct hdr_line *next;
64 struct hdr_line *prev;
68 /* must be the same as HelpType in pith/helptext.h */
69 #define HELP_T char **
72 /*
73 * This structure controls the header line items on the screen. An
74 * instance of this should be created and passed in as an argument when
75 * pico is called. The list is terminated by an entry with the name
76 * element NULL.
79 struct headerentry {
80 char *prompt;
81 char *name;
82 HELP_T help;
83 int prwid; /* prompt width on screen */
84 int maxlen;
85 char **realaddr;
86 int (*builder)(); /* Function to verify/canonicalize val */
87 struct headerentry *affected_entry, *next_affected;
88 /* entry builder's 4th arg affects */
89 char *(*selector)(); /* Browser for possible values */
90 char *key_label; /* Key label for key to call browser */
91 char *(*fileedit)(); /* Editor for file named in header */
92 int (*nickcmpl)(); /* routine that helps with nickname completion */
93 unsigned display_it:1; /* field is to be displayed by default */
94 unsigned break_on_comma:1; /* Field breaks on commas */
95 unsigned is_attach:1; /* Special case field for attachments */
96 unsigned rich_header:1; /* Field is part of rich header */
97 unsigned only_file_chars:1; /* Field is a file name */
98 unsigned single_space:1; /* Crush multiple spaces into one */
99 unsigned sticky:1; /* Can't change this via affected_entry*/
100 unsigned dirty:1; /* We've changed this entry */
101 unsigned start_here:1; /* begin composer on first on lit */
102 unsigned blank:1; /* blank line separator */
103 unsigned sticky_special:1; /* special treatment */
104 #ifdef KS_OSDATAVAR
105 KS_OSDATAVAR /* Port-Specific keymenu data */
106 #endif
107 void *bldr_private; /* Data managed by builders */
108 struct hdr_line *hd_text;
113 * Structure to pass as arg to builders.
115 * me -- A pointer to the bldr_private data for the entry currently
116 * being edited.
117 * tptr -- A malloc'd copy of the displayed text for the affected_entry
118 * pointed to by the aff argument.
119 * aff -- A pointer to the bldr_private data for the affected_entry (the
120 * entry that this entry affects).
121 * next -- The next affected_entry in the list. For example, the Lcc entry
122 * affects the To entry which affects the Fcc entry.
124 typedef struct bld_arg {
125 void **me;
126 char *tptr;
127 void **aff;
128 struct bld_arg *next;
129 } BUILDER_ARG;
133 * structure to keep track of header display
135 struct on_display {
136 int p_ind; /* index into line */
137 int p_len; /* length of line */
138 int p_line; /* physical line on screen */
139 int top_e; /* topline's header entry */
140 struct hdr_line *top_l; /* top line on display */
141 int cur_e; /* current header entry */
142 struct hdr_line *cur_l; /* current hd_line */
143 }; /* global on_display struct */
147 * Structure to handle attachments
149 typedef struct pico_atmt {
150 char *description; /* attachment description */
151 char *filename; /* file/pseudonym for attachment */
152 char *size; /* size of attachment */
153 char *id; /* attachment id */
154 unsigned short flags;
155 struct pico_atmt *next;
156 } PATMT;
159 * Structure to contain color options
161 typedef struct pico_colors {
162 COLOR_PAIR *tbcp; /* title bar color pair */
163 COLOR_PAIR *klcp; /* key label color pair */
164 COLOR_PAIR *kncp; /* key name color pair */
165 COLOR_PAIR *stcp; /* status color pair */
166 COLOR_PAIR *prcp; /* prompt color pair */
167 } PCOLORS;
170 * Flags for attachment handling
172 #define A_FLIT 0x0001 /* Accept literal file and size */
173 #define A_ERR 0x0002 /* Problem with specified attachment */
174 #define A_TMP 0x0004 /* filename is temporary, delete it */
178 * Master pine composer structure. Right now there's not much checking
179 * that any of these are pointing to something, so pine must have them pointing
180 * somewhere.
182 typedef struct pico_struct {
183 void *msgtext; /* ptrs to malloc'd arrays of char */
184 char *pine_anchor; /* ptr to pine anchor line */
185 char *pine_version; /* string containing Pine's version */
186 char *oper_dir; /* Operating dir (confine to tree) */
187 char *home_dir; /* Home directory that should be used (WINDOWS) */
188 char *quote_str; /* prepended to lines of quoted text */
189 char *exit_label; /* Label for ^X in keymenu */
190 char *ctrlr_label; /* Label for ^R in keymenu */
191 char *alt_spell; /* Checker to use other than "spell" */
192 char **alt_ed; /* name of alternate editor or NULL */
193 UCS *wordseps; /* word separator characters other than space */
194 int fillcolumn; /* where to wrap */
195 int menu_rows; /* number of rows in menu (0 or 2) */
196 int space_stuffed; /* space-stuffed for flowed, in case needs undoing */
197 long edit_offset; /* offset into hdr line or body */
198 PATMT *attachments; /* linked list of attachments */
199 PCOLORS *colors; /* colors for titlebar and keymenu */
200 void *input_cs; /* passed to mbtow() via kbseq() */
201 long pine_flags; /* entry mode flags */
202 /* The next few bits are features that don't fit in pine_flags */
203 /* If we had this to do over, it would probably be one giant bitmap */
204 unsigned always_spell_check:1; /* always spell-checking upon quit */
205 unsigned strip_ws_before_send:1; /* don't default strip bc of flowed */
206 unsigned allow_flowed_text:1; /* clean text when done to keep flowed */
207 int (*helper)(); /* Pine's help function */
208 int (*showmsg)(); /* Pine's display_message */
209 UCS (*suspend)(); /* Pine's suspend */
210 void (*keybinput)(); /* Pine's keyboard input indicator */
211 int (*tty_fix)(); /* Let Pine fix tty state */
212 long (*newmail)(); /* Pine's report_new_mail */
213 long (*msgntext)(); /* callback to get msg n's text */
214 int (*upload)(); /* callback to rcv uplaoded text */
215 char *(*ckptdir)(); /* callback for checkpoint file dir */
216 int (*exittest)(); /* callback to verify exit request */
217 char *(*canceltest)(); /* callback to verify cancel request */
218 int (*mimetype)(); /* callback to display mime type */
219 int (*expander)(); /* callback to expand address lists */
220 int (*user_says_noflow)(); /* callback to tell us we're not flowing */
221 void (*resize)(); /* callback handling screen resize */
222 void (*winch_cleanup)(); /* callback handling screen resize */
223 void (*newthread)(); /* callback to create new thread */
224 int arm_winch_cleanup; /* do the winch_cleanup if resized */
225 HELP_T search_help;
226 HELP_T ins_help;
227 HELP_T ins_m_help;
228 HELP_T composer_help;
229 HELP_T browse_help;
230 HELP_T attach_help;
231 struct headerentry *headents;
232 } PICO;
236 * Used to save and restore global pico variables that are destroyed by
237 * calling pico a second time. This happens when pico calls a selector
238 * in the HeaderEditor and that selector calls pico again.
240 typedef struct save_stuff {
241 int vtrow,
242 vtcol,
243 lbound;
244 VIDEO **vscreen,
245 **pscreen; /* save pointers */
246 struct on_display ods; /* save whole struct */
247 short delim_ps,
248 invert_ps;
249 int pico_all_done;
250 jmp_buf finstate;
251 UCS *pico_anchor; /* save pointer */
252 PICO *Pmaster; /* save pointer */
253 int fillcol;
254 UCS *pat; /* save array */
255 int ComposerTopLine,
256 ComposerEditing;
257 long gmode;
258 char *alt_speller; /* save pointer */
259 UCS *quote_str; /* save pointer */
260 UCS *wordseps; /* save pointer */
261 int currow,
262 curcol,
263 thisflag,
264 lastflag,
265 curgoal;
266 char *opertree; /* save array */
267 WINDOW *curwp; /* save pointer */
268 WINDOW *wheadp; /* save pointer */
269 BUFFER *curbp; /* save pointer */
270 BUFFER *bheadp; /* save pointer */
271 int km_popped;
272 int mrow;
273 } VARS_TO_SAVE;
276 #ifdef MOUSE
278 * Mouse buttons.
280 #define M_BUTTON_LEFT 0
281 #define M_BUTTON_MIDDLE 1
282 #define M_BUTTON_RIGHT 2
286 * Flags. (modifier keys)
288 #define M_KEY_CONTROL 0x01 /* Control key was down. */
289 #define M_KEY_SHIFT 0x02 /* Shift key was down. */
293 * Mouse Events
295 #define M_EVENT_DOWN 0x01 /* Mouse went down. */
296 #define M_EVENT_UP 0x02 /* Mouse went up. */
297 #define M_EVENT_TRACK 0x04 /* Mouse tracking */
300 * Mouse event information.
302 typedef struct mouse_struct {
303 unsigned long mevent; /* Indicates type of event: Down, Up or Track */
304 char down; /* TRUE when mouse down event */
305 char doubleclick; /* TRUE when double click. */
306 int button; /* button pressed. */
307 int flags; /* What other keys pressed. */
308 int row;
309 int col;
310 } MOUSEPRESS;
314 typedef unsigned long (*mousehandler_t)(unsigned long, int, int, int, int);
316 typedef struct point {
317 unsigned r:8; /* row value */
318 unsigned c:8; /* column value */
319 } MPOINT;
322 typedef struct menuitem {
323 unsigned val; /* return value */
324 mousehandler_t action; /* action to perform */
325 MPOINT tl; /* top-left corner of active area */
326 MPOINT br; /* bottom-right corner of active area */
327 MPOINT lbl; /* where the label starts */
328 char *label;
329 void (*label_hiliter)();
330 COLOR_PAIR *kncp; /* key name color pair */
331 COLOR_PAIR *klcp; /* key label color pair */
332 struct menuitem *next;
333 } MENUITEM;
334 #endif
338 * Structure used to manage keyboard input that comes as escape
339 * sequences (arrow keys, function keys, etc.)
341 typedef struct KBSTREE {
342 char value;
343 int func; /* Routine to handle it */
344 struct KBSTREE *down;
345 struct KBSTREE *left;
346 } KBESC_T;
350 * various flags that they may passed to PICO
352 #define P_HICTRL 0x80000000 /* overwrite mode */
353 #define P_CHKPTNOW 0x40000000 /* do the checkpoint on entry */
354 #define P_DELRUBS 0x20000000 /* map ^H to forwdel */
355 #define P_LOCALLF 0x10000000 /* use local vs. NVT EOL */
356 #define P_BODY 0x08000000 /* start composer in body */
357 #define P_HEADEND 0x04000000 /* start composer at end of header */
358 #define P_VIEW MDVIEW /* read-only */
359 #define P_FKEYS MDFKEY /* run in function key mode */
360 #define P_SECURE MDSCUR /* run in restricted (demo) mode */
361 #define P_TREE MDTREE /* restrict to a subtree */
362 #define P_SUSPEND MDSSPD /* allow ^Z suspension */
363 #define P_ADVANCED MDADVN /* enable advanced features */
364 #define P_CURDIR MDCURDIR /* use current dir for lookups */
365 #define P_ALTNOW MDALTNOW /* enter alt ed sans hesitation */
366 #define P_SUBSHELL MDSPWN /* spawn subshell for suspend */
367 #define P_COMPLETE MDCMPLT /* enable file name completion */
368 #define P_DOTKILL MDDTKILL /* kill from dot to eol */
369 #define P_SHOCUR MDSHOCUR /* cursor follows hilite in browser*/
370 #define P_HIBITIGN MDHBTIGN /* ignore chars with hi bit set */
371 #define P_DOTFILES MDDOTSOK /* browser displays dot files */
372 #define P_NOBODY MDHDRONLY /* Operate only on given headers */
373 #define P_ALLOW_GOTO MDGOTO /* support "Goto" in file browser */
374 #define P_REPLACE MDREPLACE /* allow "Replace" in "Where is" */
378 * Main defs
380 #ifdef maindef
381 PICO *Pmaster = NULL; /* composer specific stuff */
382 char *version = "5.07"; /* PICO version number */
384 #else
385 extern PICO *Pmaster; /* composer specific stuff */
386 extern char *version; /* pico version! */
388 #endif /* maindef */
392 * Flags for FileBrowser call
394 #define FB_READ 0x0001 /* Looking for a file to read. */
395 #define FB_SAVE 0x0002 /* Looking for a file to save. */
396 #define FB_ATTACH 0x0004 /* Looking for a file to attach */
397 #define FB_LMODEPOS 0x0008 /* ListMode is a possibility */
398 #define FB_LMODE 0x0010 /* Using ListMode now */
402 * Flags for pico_readc/pico_writec.
404 #define PICOREADC_NONE 0x00
405 #define PICOREADC_NOUCS 0x01
409 * number of keystrokes to delay removing an error message, or new mail
410 * notification, or checkpointing
412 #define MESSDELAY 25
413 #define NMMESSDELAY 60
414 #ifndef CHKPTDELAY
415 #define CHKPTDELAY 100
416 #endif
418 #include "./keydefs.h"
422 * useful function definitions
424 int pico(PICO *pm);
425 int pico_file_browse(PICO *, char *, size_t, char *, size_t, char *, size_t, int);
426 void *pico_get(void);
427 void pico_give(void *w);
428 int pico_readc(void *w, unsigned char *c, int flags);
429 int pico_writec(void *w, int c, int flags);
430 int pico_puts(void *w, char *s, int flags);
431 int pico_seek(void *w, long offset, int orig);
432 int pico_replace(void *, char *);
433 int pico_fncomplete(char *, char *, size_t);
434 #if defined(DOS) || defined(OS2)
435 int pico_nfsetcolor(char *);
436 int pico_nbsetcolor(char *);
437 int pico_rfsetcolor(char *);
438 int pico_rbsetcolor(char *);
439 #endif
440 #ifdef MOUSE
441 int register_mfunc(mousehandler_t, int, int, int, int);
442 void clear_mfunc(mousehandler_t);
443 unsigned long mouse_in_content(unsigned long, int, int, int, int);
444 unsigned long mouse_in_pico(unsigned long, int, int, int, int);
445 void mouse_get_last(mousehandler_t *, MOUSEPRESS *);
446 void register_key(int, unsigned, char *, void (*)(),
447 int, int, int, COLOR_PAIR *, COLOR_PAIR *);
448 int mouse_on_key(int, int);
449 #endif /* MOUSE */
452 #endif /* PICO_H */