nano.h 12.1 KB
Newer Older
Chris Allegretta's avatar
Chris Allegretta committed
1
/* $Id$ */
Chris Allegretta's avatar
Chris Allegretta committed
2
3
4
/**************************************************************************
 *   nano.h                                                               *
 *                                                                        *
5
 *   Copyright (C) 1999-2002 Chris Allegretta                             *
Chris Allegretta's avatar
Chris Allegretta committed
6
7
 *   This program is free software; you can redistribute it and/or modify *
 *   it under the terms of the GNU General Public License as published by *
8
 *   the Free Software Foundation; either version 2, or (at your option)  *
Chris Allegretta's avatar
Chris Allegretta committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 *   any later version.                                                   *
 *                                                                        *
 *   This program is distributed in the hope that it will be useful,      *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of       *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
 *   GNU General Public License for more details.                         *
 *                                                                        *
 *   You should have received a copy of the GNU General Public License    *
 *   along with this program; if not, write to the Free Software          *
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            *
 *                                                                        *
 **************************************************************************/

#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif

#ifndef NANO_H
#define NANO_H 1

/* Macros for the flags int... */
#define SET(bit) flags |= bit
#define UNSET(bit) flags &= ~bit
#define ISSET(bit) (flags & bit)
33
#define TOGGLE(bit) flags ^= bit
Chris Allegretta's avatar
Chris Allegretta committed
34

35
36
37
38
#ifndef NANO_SMALL
  /* For the backup file copy ... */
# define COPYFILEBLOCKSIZE 1024
#endif
Chris Allegretta's avatar
Chris Allegretta committed
39
40
41

#ifdef USE_SLANG	/* Slang support enabled */
#include <slcurses.h>
42
43
#define KEY_IC SL_KEY_IC
#define KEY_DC SL_KEY_DELETE
Chris Allegretta's avatar
Chris Allegretta committed
44
45
46
47
48
49
#elif defined(HAVE_NCURSES_H)
#include <ncurses.h>
#else /* Uh oh */
#include <curses.h> 
#endif /* CURSES_H */

50
51
52
53
54
#ifdef ENABLE_NLS
#  ifdef HAVE_LIBINTL_H
#    include <libintl.h>
#  endif
#  define _(string) gettext(string)
55
#  define __(singular, plural, number) ngettext(singular, plural, number)
56
57
#else
#  define _(string) (string)
58
#  define __(singular, plural, number) (number == 1 ? singular : plural)
Chris Allegretta's avatar
Chris Allegretta committed
59
60
#endif

61
62
#include <sys/types.h>
#include <sys/stat.h>
Chris Allegretta's avatar
Chris Allegretta committed
63
64
65
66
67
68
69
70
71
72
73
74
#include "config.h"

#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
#include <glib.h>
# ifndef HAVE_SNPRINTF
#  define snprintf	g_snprintf
# endif
# ifndef HAVE_VSNPRINTF
#  define vsnprintf	g_vsnprintf
# endif
#endif

75
76
77
78
79
80
81
82
83
#if !defined(HAVE_STRCASECMP) || !defined(HAVE_STRNCASECMP)
# ifndef HAVE_STRCASECMP
#  define strcasecmp strcmp
# endif
# ifndef HAVE_STRNCASECMP
#  define strncasecmp strncmp
# endif
#endif

84
85
86
87
88
89
90
91
92
/* HP-UX 10 & 11 do not seem to support KEY_HOME and KEY_END */
#ifndef KEY_HOME
#define KEY_HOME -1
#endif /* KEY_HOME */

#ifndef KEY_END
#define KEY_END -1
#endif /* KEY_END */

Chris Allegretta's avatar
Chris Allegretta committed
93
#define VERMSG "GNU nano " VERSION
Chris Allegretta's avatar
Chris Allegretta committed
94

95
96
97
98
#if defined(DISABLE_WRAPPING) && defined(DISABLE_JUSTIFY)
#define DISABLE_WRAPJUSTIFY 1
#endif

Chris Allegretta's avatar
Chris Allegretta committed
99
100
101
102
103
/* Structure types */
typedef struct filestruct {
    char *data;
    struct filestruct *next;	/* Next node */
    struct filestruct *prev;	/* Previous node */
104
105
    int lineno;			/* The line number */
} filestruct;
106

107
#ifdef ENABLE_MULTIBUFFER
108
109
typedef struct openfilestruct {
    char *filename;
110
111
112
#ifndef NANO_SMALL
    struct stat originalfilestat;
#endif
113
114
115
    struct openfilestruct *next;	/* Next node */
    struct openfilestruct *prev;	/* Previous node */
    struct filestruct *fileage;	/* Current file */
Chris Allegretta's avatar
Chris Allegretta committed
116
117
118
119
120
121
122
    struct filestruct *filebot;	/* Current file's last line */
#ifndef NANO_SMALL
    struct filestruct *file_mark_beginbuf;
				/* Current file's beginning marked line */
    int file_mark_beginx;	/* Current file's beginning marked line's
				   x-coordinate position */
#endif
123
124
    int file_current_x;		/* Current file's x-coordinate position */
    int file_current_y;		/* Current file's y-coordinate position */
Chris Allegretta's avatar
Chris Allegretta committed
125
126
127
    int file_flags;		/* Current file's flags: modification
				   status (and marking status, if
				   available) */
128
129
    int file_placewewant;	/* Current file's place we want */
    int file_totlines;		/* Current file's total number of lines */
130
    long file_totsize;		/* Current file's total size */
131
132
    int file_lineno;		/* Current file's line number */
} openfilestruct;
133
134
#endif

Chris Allegretta's avatar
Chris Allegretta committed
135
136
137
138
139
140
141
typedef struct shortcut {
   int val;		/* Actual sequence that generates the keystroke */
   int altval;		/* Alt key # for this function, or 0 for none */
   int misc1;		/* Other int functions we want bound */
   int misc2;
   int viewok;		/* is this function legal in view mode? */
   int (*func) (void);	/* Function to call when we catch this key */
142
143
144
145
   const char *desc;	/* Description, e.g. "Page Up" */
#ifndef DISABLE_HELP
   const char *help;	/* Help file entry text */
#endif
146
   struct shortcut *next;
Chris Allegretta's avatar
Chris Allegretta committed
147
148
} shortcut;

Chris Allegretta's avatar
Chris Allegretta committed
149
#ifndef NANO_SMALL
150
151
typedef struct toggle {
   int val;		/* Sequence to toggle the key.  Should only need 1 */
152
   const char *desc;	/* Description for when toggle is, uh, toggled,
153
			   e.g. "Pico Messages"; we'll append Enabled or
154
155
			   Disabled */
   int flag;		/* What flag actually gets toggled */
156
   struct toggle *next;
157
} toggle;
Chris Allegretta's avatar
Chris Allegretta committed
158
#endif /* !NANO_SMALL */
159

160
161
#ifdef ENABLE_NANORC
typedef struct rcoption {
162
   const char *name;
163
164
165
166
   int flag;
} rcoption;
#endif /* ENABLE_NANORC */

167
168
169
#ifdef ENABLE_COLOR

typedef struct colortype {
170
171
172
173
174
175
    int fg;			/* fg color */
    int bg;			/* bg color */
    int bright;			/* Is this color A_BOLD? */
    int pairnum;		/* Color pair number used for this fg/bg */
    char *start;		/* Start (or all) of the regex string */
    char *end;			/* End of the regex string */
176
177
178
    struct colortype *next;
} colortype;

179
180
181
182
183
184
185
typedef struct exttype {
    char *val;
    struct exttype *next;
} exttype;

typedef struct syntaxtype {
    char *desc;			/* Name of this syntax type */
Chris Allegretta's avatar
Chris Allegretta committed
186
    exttype *extensions;	/* List of extensions that this applies to */
187
188
189
190
    colortype *color;		/* color struct for this syntax */
    struct syntaxtype *next;
} syntaxtype;

191
192
193
#endif /* ENABLE_COLOR */


Chris Allegretta's avatar
Chris Allegretta committed
194
195
196
197
198
199
200
201
/* Bitwise flags so we can save space (or more correctly, not waste it) */

#define MODIFIED		(1<<0)
#define KEEP_CUTBUFFER		(1<<1)
#define CASE_SENSITIVE		(1<<2)
#define MARK_ISSET		(1<<3)
#define CONSTUPDATE		(1<<4)
#define NO_HELP			(1<<5)
202
#define PICO_MODE		(1<<6)
203
#define NOFOLLOW_SYMLINKS	(1<<7)
Chris Allegretta's avatar
Chris Allegretta committed
204
205
206
207
208
209
#define SUSPEND			(1<<8)
#define NO_WRAP			(1<<9)
#define AUTOINDENT		(1<<10)
#define SAMELINEWRAP		(1<<11)
#define VIEW_MODE		(1<<12)
#define USE_MOUSE		(1<<13)
210
211
212
213
#define USE_REGEXP		(1<<14)
#define REGEXP_COMPILED		(1<<15)
#define TEMP_OPT		(1<<16)
#define CUT_TO_END		(1<<17)
214
215
216
#define REVERSE_SEARCH		(1<<18)
#define MULTIBUFFER		(1<<19)
#define CLEAR_BACKUPSTRING	(1<<20)
217
#define DOS_FILE		(1<<21)
Chris Allegretta's avatar
Chris Allegretta committed
218
#define MAC_FILE		(1<<22)
219
#define SMOOTHSCROLL		(1<<23)
220
#define DISABLE_CURPOS		(1<<24)	/* Damn, we still need it */
221
#define ALT_KEYPAD		(1<<25)
222
#define NO_CONVERT		(1<<26)
223
#define BACKUP_FILE		(1<<27)
Chris Allegretta's avatar
Chris Allegretta committed
224
#define NO_RCFILE		(1<<28)
225
#define COLOR_SYNTAX		(1<<29)
Chris Allegretta's avatar
Chris Allegretta committed
226

227
/* Control key sequences, changing these would be very very bad */
Chris Allegretta's avatar
Chris Allegretta committed
228

Chris Allegretta's avatar
Chris Allegretta committed
229
#define NANO_CONTROL_SPACE 0
Chris Allegretta's avatar
Chris Allegretta committed
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#define NANO_CONTROL_A 1
#define NANO_CONTROL_B 2
#define NANO_CONTROL_C 3
#define NANO_CONTROL_D 4
#define NANO_CONTROL_E 5
#define NANO_CONTROL_F 6
#define NANO_CONTROL_G 7
#define NANO_CONTROL_H 8
#define NANO_CONTROL_I 9
#define NANO_CONTROL_J 10
#define NANO_CONTROL_K 11
#define NANO_CONTROL_L 12
#define NANO_CONTROL_M 13
#define NANO_CONTROL_N 14
#define NANO_CONTROL_O 15
#define NANO_CONTROL_P 16
#define NANO_CONTROL_Q 17
#define NANO_CONTROL_R 18
#define NANO_CONTROL_S 19
#define NANO_CONTROL_T 20
#define NANO_CONTROL_U 21
#define NANO_CONTROL_V 22
#define NANO_CONTROL_W 23
#define NANO_CONTROL_X 24
#define NANO_CONTROL_Y 25
#define NANO_CONTROL_Z 26

#define NANO_CONTROL_4 28
#define NANO_CONTROL_5 29
#define NANO_CONTROL_6 30
#define NANO_CONTROL_7 31

#define NANO_ALT_A 'a'
#define NANO_ALT_B 'b'
#define NANO_ALT_C 'c'
#define NANO_ALT_D 'd'
#define NANO_ALT_E 'e'
#define NANO_ALT_F 'f'
#define NANO_ALT_G 'g'
#define NANO_ALT_H 'h'
#define NANO_ALT_I 'i'
#define NANO_ALT_J 'j'
#define NANO_ALT_K 'k'
#define NANO_ALT_L 'l'
#define NANO_ALT_M 'm'
#define NANO_ALT_N 'n'
#define NANO_ALT_O 'o'
#define NANO_ALT_P 'p'
#define NANO_ALT_Q 'q'
#define NANO_ALT_R 'r'
#define NANO_ALT_S 's'
#define NANO_ALT_T 't'
#define NANO_ALT_U 'u'
#define NANO_ALT_V 'v'
#define NANO_ALT_W 'w'
#define NANO_ALT_X 'x'
#define NANO_ALT_Y 'y'
#define NANO_ALT_Z 'z'
288
289
#define NANO_ALT_PERIOD '.'
#define NANO_ALT_COMMA ','
290
291
#define NANO_ALT_LCARAT '<'
#define NANO_ALT_RCARAT '>'
292
#define NANO_ALT_BRACKET ']'
293
#define NANO_ALT_SPACE ' '
Chris Allegretta's avatar
Chris Allegretta committed
294

295
/* Some semi-changeable keybindings; don't play with unless you're sure you
Chris Allegretta's avatar
Chris Allegretta committed
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
know what you're doing */

#define NANO_INSERTFILE_KEY	NANO_CONTROL_R
#define NANO_INSERTFILE_FKEY	KEY_F(5)
#define NANO_EXIT_KEY 		NANO_CONTROL_X
#define NANO_EXIT_FKEY 		KEY_F(2)
#define NANO_WRITEOUT_KEY	NANO_CONTROL_O
#define NANO_WRITEOUT_FKEY	KEY_F(3)
#define NANO_GOTO_KEY		NANO_CONTROL_7
#define NANO_GOTO_FKEY		KEY_F(13)
#define NANO_ALT_GOTO_KEY	NANO_ALT_G
#define NANO_HELP_KEY		NANO_CONTROL_G
#define NANO_HELP_FKEY		KEY_F(1)
#define NANO_WHEREIS_KEY	NANO_CONTROL_W
#define NANO_WHEREIS_FKEY	KEY_F(6)
#define NANO_REPLACE_KEY	NANO_CONTROL_4
#define NANO_REPLACE_FKEY	KEY_F(14)
#define NANO_ALT_REPLACE_KEY	NANO_ALT_R
314
#define NANO_OTHERSEARCH_KEY	NANO_CONTROL_R
Chris Allegretta's avatar
Chris Allegretta committed
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#define NANO_PREVPAGE_KEY	NANO_CONTROL_Y
#define NANO_PREVPAGE_FKEY	KEY_F(7)
#define NANO_NEXTPAGE_KEY	NANO_CONTROL_V
#define NANO_NEXTPAGE_FKEY	KEY_F(8)
#define NANO_CUT_KEY		NANO_CONTROL_K
#define NANO_CUT_FKEY		KEY_F(9)
#define NANO_UNCUT_KEY		NANO_CONTROL_U
#define NANO_UNCUT_FKEY		KEY_F(10)
#define NANO_CURSORPOS_KEY	NANO_CONTROL_C
#define NANO_CURSORPOS_FKEY	KEY_F(11)
#define NANO_SPELL_KEY		NANO_CONTROL_T
#define NANO_SPELL_FKEY		KEY_F(12)
#define NANO_FIRSTLINE_KEY	NANO_PREVPAGE_KEY
#define NANO_LASTLINE_KEY	NANO_NEXTPAGE_KEY
#define NANO_CANCEL_KEY		NANO_CONTROL_C
#define NANO_REFRESH_KEY	NANO_CONTROL_L
#define NANO_JUSTIFY_KEY	NANO_CONTROL_J
#define NANO_JUSTIFY_FKEY	KEY_F(4)
333
#define NANO_UNJUSTIFY_KEY	NANO_CONTROL_U
Chris Allegretta's avatar
Chris Allegretta committed
334
335
336
337
338
#define NANO_UP_KEY		NANO_CONTROL_P
#define NANO_DOWN_KEY		NANO_CONTROL_N
#define NANO_FORWARD_KEY	NANO_CONTROL_F
#define NANO_BACK_KEY		NANO_CONTROL_B
#define NANO_MARK_KEY		NANO_CONTROL_6
339
#define NANO_ALT_MARK_KEY	NANO_ALT_A
Chris Allegretta's avatar
Chris Allegretta committed
340
341
342
343
344
345
346
#define NANO_HOME_KEY		NANO_CONTROL_A
#define NANO_END_KEY		NANO_CONTROL_E
#define NANO_DELETE_KEY		NANO_CONTROL_D
#define NANO_BACKSPACE_KEY	NANO_CONTROL_H
#define NANO_TAB_KEY		NANO_CONTROL_I
#define NANO_SUSPEND_KEY	NANO_CONTROL_Z
#define NANO_ENTER_KEY		NANO_CONTROL_M
347
#define NANO_FROMSEARCHTOGOTO_KEY NANO_CONTROL_T
Chris Allegretta's avatar
Chris Allegretta committed
348
#define NANO_TOFILES_KEY	NANO_CONTROL_T
349
#define NANO_APPEND_KEY		NANO_ALT_A
350
#define NANO_PREPEND_KEY	NANO_ALT_P
351
352
#define NANO_OPENPREV_KEY	NANO_ALT_LCARAT
#define NANO_OPENNEXT_KEY	NANO_ALT_RCARAT
353
354
#define NANO_OPENPREV_ALTKEY	NANO_ALT_COMMA
#define NANO_OPENNEXT_ALTKEY	NANO_ALT_PERIOD
355
#define NANO_BRACKET_KEY	NANO_ALT_BRACKET
356
#define NANO_EXTCMD_KEY		NANO_CONTROL_X
357
358
#define NANO_NEXTWORD_KEY	NANO_CONTROL_SPACE
#define NANO_PREVWORD_KEY	NANO_ALT_SPACE
Chris Allegretta's avatar
Chris Allegretta committed
359

Chris Allegretta's avatar
Chris Allegretta committed
360
361
#ifndef NANO_SMALL
/* Toggles do not exist with NANO_SMALL. */
362
363
364
365
366
367
368
#define TOGGLE_CONST_KEY	NANO_ALT_C
#define TOGGLE_AUTOINDENT_KEY	NANO_ALT_I
#define TOGGLE_SUSPEND_KEY	NANO_ALT_Z
#define TOGGLE_NOHELP_KEY	NANO_ALT_X
#define TOGGLE_PICOMODE_KEY	NANO_ALT_P
#define TOGGLE_MOUSE_KEY	NANO_ALT_M
#define TOGGLE_CUTTOEND_KEY	NANO_ALT_K
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
369
#define TOGGLE_REGEXP_KEY	NANO_ALT_R
370
#define TOGGLE_WRAP_KEY		NANO_ALT_W
371
#define TOGGLE_BACKWARDS_KEY	NANO_ALT_B
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
372
#define TOGGLE_CASE_KEY		NANO_ALT_C
373
#define TOGGLE_LOAD_KEY		NANO_ALT_F
374
#define TOGGLE_DOS_KEY		NANO_ALT_D
375
#define TOGGLE_MAC_KEY		NANO_ALT_O
376
#define TOGGLE_SMOOTH_KEY	NANO_ALT_S
377
#define TOGGLE_NOCONVERT_KEY	NANO_ALT_N
378
#define TOGGLE_BACKUP_KEY	NANO_ALT_B
379
#define TOGGLE_SYNTAX_KEY	NANO_ALT_Y
Chris Allegretta's avatar
Chris Allegretta committed
380
#endif /* !NANO_SMALL */
381

382
#define MAIN_VISIBLE 12
Chris Allegretta's avatar
Chris Allegretta committed
383

Chris Allegretta's avatar
Chris Allegretta committed
384
385
386
#define VIEW 1
#define NOVIEW 0

Chris Allegretta's avatar
Chris Allegretta committed
387
388
389
typedef enum {
    CENTER, TOP, NONE
} topmidbotnone;
390

Chris Allegretta's avatar
Chris Allegretta committed
391
/* Minimum editor window rows required for nano to work correctly */
392
393
394
395
396
397
398
399
#define MIN_EDITOR_ROWS 3

/* Default number of characters from end-of-line where text wrapping occurs */
#define CHARS_FROM_EOL 8

/* Minimum fill length (space available for text before wrapping occurs) */
#define MIN_FILL_LENGTH 10

Chris Allegretta's avatar
Chris Allegretta committed
400
#endif /* !NANO_H */