blob: 1b0bed625219b7840cfba3471dcd693796f8063c [file] [log] [blame]
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001/**************************************************************************
Benno Schulenberg514cd9a2016-08-29 17:10:49 +02002 * nano.h -- This file is part of GNU nano. *
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00003 * *
Chris Allegretta8a07a962009-12-02 03:36:22 +00004 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, *
Benno Schulenberg7a9f4a42014-04-30 20:18:26 +00005 * 2008, 2009, 2010, 2011, 2013, 2014 Free Software Foundation, Inc. *
Benno Schulenberg406e5242016-08-29 15:14:18 +02006 * Copyright (C) 2014, 2015, 2016 Benno Schulenberg *
Benno Schulenberg57d17552016-09-03 12:14:08 +02007 * *
Benno Schulenberg514cd9a2016-08-29 17:10:49 +02008 * GNU nano is free software: you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published *
10 * by the Free Software Foundation, either version 3 of the License, *
11 * or (at your option) any later version. *
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000012 * *
Benno Schulenberg514cd9a2016-08-29 17:10:49 +020013 * GNU nano is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty *
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
16 * See the GNU General Public License for more details. *
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000017 * *
18 * You should have received a copy of the GNU General Public License *
Benno Schulenberg514cd9a2016-08-29 17:10:49 +020019 * along with this program. If not, see http://www.gnu.org/licenses/. *
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000020 * *
21 **************************************************************************/
22
David Lawrence Ramsey24ae56c2004-02-27 03:06:28 +000023#ifndef NANO_H
24#define NANO_H 1
25
David Lawrence Ramseye527e452005-04-15 18:07:26 +000026#ifdef HAVE_CONFIG_H
27#include <config.h>
28#endif
29
Chris Allegretta5a3464b2009-03-01 00:50:19 +000030#ifdef NEED_XOPEN_SOURCE_EXTENDED
31#ifndef _XOPEN_SOURCE_EXTENDED
32#define _XOPEN_SOURCE_EXTENDED 1
Benno Schulenberg492e9f62014-06-20 10:48:26 +000033#endif
34#endif
Chris Allegretta5a3464b2009-03-01 00:50:19 +000035
David Lawrence Ramseya619ae62004-03-04 06:33:52 +000036#ifdef __TANDEM
David Lawrence Ramsey0a4b7372006-07-18 18:28:10 +000037/* Tandem NonStop Kernel support. */
David Lawrence Ramseya619ae62004-03-04 06:33:52 +000038#include <floss.h>
39#define NANO_ROOT_UID 65535
40#else
41#define NANO_ROOT_UID 0
42#endif
43
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000044#ifdef HAVE_LIMITS_H
45#include <limits.h>
46#endif
47
David Lawrence Ramsey96dce262006-06-06 18:41:58 +000048#ifdef HAVE_SYS_PARAM_H
49#include <sys/param.h>
50#endif
51
Chris Allegretta5a3464b2009-03-01 00:50:19 +000052#ifdef HAVE_STDARG_H
53#include <stdarg.h>
54#endif
55
Benno Schulenberg044e4d22014-05-13 21:11:59 +000056/* Suppress warnings for __attribute__((warn_unused_result)). */
Chris Allegrettaa97cb812009-12-02 03:24:18 +000057#define IGNORE_CALL_RESULT(call) do { if (call) {} } while(0)
58
Benno Schulenbergeb91ad52014-05-15 13:11:55 +000059/* Macros for flags, indexing each bit in a small array. */
60#define FLAGS(flag) flags[((flag) / (sizeof(unsigned) * 8))]
Benno Schulenberg04b9b9c2016-07-22 15:35:22 +020061#define FLAGMASK(flag) ((unsigned)1 << ((flag) % (sizeof(unsigned) * 8)))
Chris Allegrettaa48507d2009-08-14 03:18:29 +000062#define SET(flag) FLAGS(flag) |= FLAGMASK(flag)
63#define UNSET(flag) FLAGS(flag) &= ~FLAGMASK(flag)
64#define ISSET(flag) ((FLAGS(flag) & FLAGMASK(flag)) != 0)
65#define TOGGLE(flag) FLAGS(flag) ^= FLAGMASK(flag)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000066
David Lawrence Ramsey6335fb52007-01-01 05:15:32 +000067/* Macros for character allocation and more. */
Chris Allegretta7662c862003-01-13 01:35:15 +000068#define charalloc(howmuch) (char *)nmalloc((howmuch) * sizeof(char))
Chris Allegrettaf80a59c2003-01-30 00:57:33 +000069#define charealloc(ptr, howmuch) (char *)nrealloc(ptr, (howmuch) * sizeof(char))
David Lawrence Ramsey5ffbec52003-09-16 01:16:49 +000070#define charmove(dest, src, n) memmove(dest, src, (n) * sizeof(char))
David Lawrence Ramsey3db0dc32005-06-12 15:24:36 +000071#define charset(dest, src, n) memset(dest, src, (n) * sizeof(char))
David Lawrence Ramseyd08348b2004-09-18 22:02:21 +000072
David Lawrence Ramsey092af142005-06-08 01:35:10 +000073/* Set a default value for PATH_MAX if there isn't one. */
David Lawrence Ramsey3e0c8a62004-11-04 04:08:18 +000074#ifndef PATH_MAX
David Lawrence Ramsey6e0ed3c2005-03-26 04:42:28 +000075#define PATH_MAX 4096
David Lawrence Ramsey5db0cdc2002-06-28 22:45:14 +000076#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000077
David Lawrence Ramseyf78bc852007-12-18 15:55:48 +000078#ifdef USE_SLANG
79/* Slang support. */
80#include <slcurses.h>
81/* Slang curses emulation brain damage, part 3: Slang doesn't define the
82 * curses equivalents of the Insert or Delete keys. */
83#define KEY_DC SL_KEY_DELETE
84#define KEY_IC SL_KEY_IC
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000085/* Ncurses support. */
Chris Allegretta2e4228f2013-01-10 03:29:59 +000086#elif defined(HAVE_NCURSESW_NCURSES_H)
87#include <ncursesw/ncurses.h>
David Lawrence Ramseyf78bc852007-12-18 15:55:48 +000088#elif defined(HAVE_NCURSES_H)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000089#include <ncurses.h>
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000090#else
91/* Curses support. */
David Lawrence Ramseyc97acfb2003-09-10 20:08:00 +000092#include <curses.h>
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000093#endif /* CURSES_H */
94
Benno Schulenberg8c7a3852016-07-12 21:05:09 +020095#if defined(NCURSES_VERSION_MAJOR) && (NCURSES_VERSION_MAJOR < 6)
96#define USING_OLD_NCURSES yes
97#endif
98
David Lawrence Ramsey2ab03f62002-10-17 02:19:31 +000099#ifdef ENABLE_NLS
David Lawrence Ramseyc1c818e2006-05-14 18:22:01 +0000100/* Native language support. */
David Lawrence Ramsey637b8bb2005-01-17 05:06:55 +0000101#ifdef HAVE_LIBINTL_H
102#include <libintl.h>
103#endif
104#define _(string) gettext(string)
105#define P_(singular, plural, number) ngettext(singular, plural, number)
David Lawrence Ramsey2ab03f62002-10-17 02:19:31 +0000106#else
David Lawrence Ramsey637b8bb2005-01-17 05:06:55 +0000107#define _(string) (string)
108#define P_(singular, plural, number) (number == 1 ? singular : plural)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000109#endif
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000110#define gettext_noop(string) (string)
111#define N_(string) gettext_noop(string)
David Lawrence Ramseyafbcf682005-03-21 06:33:41 +0000112 /* Mark a string that will be sent to gettext() later. */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000113
David Lawrence Ramseyfc693212004-12-23 17:43:27 +0000114#include <stddef.h>
Rashed Abdel-Tawabc5112622015-10-18 16:56:55 +0000115#include <stdio.h>
David Lawrence Ramsey691698a2005-07-24 19:57:51 +0000116#include <stdlib.h>
David Lawrence Ramsey5db0cdc2002-06-28 22:45:14 +0000117#include <sys/types.h>
118#include <sys/stat.h>
David Lawrence Ramsey691698a2005-07-24 19:57:51 +0000119#include <dirent.h>
120#ifdef HAVE_REGEX_H
121#include <regex.h>
122#endif
Benno Schulenberg75d64e62015-05-28 13:02:29 +0000123#include <signal.h>
David Lawrence Ramsey691698a2005-07-24 19:57:51 +0000124#include <assert.h>
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000125
David Lawrence Ramseyda50e732005-07-04 04:22:30 +0000126/* If no vsnprintf(), use the version from glib 2.x. */
David Lawrence Ramsey3a1fc8f2005-01-16 18:49:19 +0000127#ifndef HAVE_VSNPRINTF
David Lawrence Ramseyda50e732005-07-04 04:22:30 +0000128#include <glib.h>
David Lawrence Ramsey3a1fc8f2005-01-16 18:49:19 +0000129#define vsnprintf g_vsnprintf
130#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000131
David Lawrence Ramseyd8640482005-06-12 17:48:46 +0000132/* If no isblank(), iswblank(), strcasecmp(), strncasecmp(),
133 * strcasestr(), strnlen(), getdelim(), or getline(), use the versions
134 * we have. */
135#ifndef HAVE_ISBLANK
136#define isblank nisblank
137#endif
138#ifndef HAVE_ISWBLANK
139#define iswblank niswblank
140#endif
David Lawrence Ramseyadc30a82005-03-20 07:24:49 +0000141#ifndef HAVE_STRCASECMP
142#define strcasecmp nstrcasecmp
143#endif
144#ifndef HAVE_STRNCASECMP
145#define strncasecmp nstrncasecmp
146#endif
147#ifndef HAVE_STRCASESTR
148#define strcasestr nstrcasestr
149#endif
150#ifndef HAVE_STRNLEN
151#define strnlen nstrnlen
152#endif
David Lawrence Ramseya27bd652004-08-17 05:23:38 +0000153#ifndef HAVE_GETDELIM
154#define getdelim ngetdelim
155#endif
David Lawrence Ramseya27bd652004-08-17 05:23:38 +0000156#ifndef HAVE_GETLINE
157#define getline ngetline
158#endif
159
David Lawrence Ramsey6e308c02006-07-19 02:44:56 +0000160/* If we aren't using ncurses with mouse support, turn the mouse support
161 * off, as it's useless then. */
David Lawrence Ramseyf5b256b2003-10-03 20:26:25 +0000162#ifndef NCURSES_MOUSE_VERSION
163#define DISABLE_MOUSE 1
164#endif
David Lawrence Ramsey935594b2006-07-18 18:16:30 +0000165
David Lawrence Ramsey32a3ce42006-07-18 18:25:56 +0000166#if defined(DISABLE_WRAPPING) && defined(DISABLE_JUSTIFY)
167#define DISABLE_WRAPJUSTIFY 1
David Lawrence Ramsey935594b2006-07-18 18:16:30 +0000168#endif
Chris Allegretta6fe61492001-05-21 12:56:25 +0000169
David Lawrence Ramsey3e0c8a62004-11-04 04:08:18 +0000170/* Enumeration types. */
171typedef enum {
172 NIX_FILE, DOS_FILE, MAC_FILE
173} file_format;
174
175typedef enum {
Benno Schulenbergc8f530a2016-05-19 20:43:08 +0200176 HUSH, MILD, ALERT
177} message_type;
178
179typedef enum {
David Lawrence Ramseybf0e47d2005-08-01 18:27:10 +0000180 OVERWRITE, APPEND, PREPEND
Benno Schulenbergc2a0c782016-07-15 12:59:59 +0200181} kind_of_writing_type;
David Lawrence Ramseybf0e47d2005-08-01 18:27:10 +0000182
183typedef enum {
Benno Schulenberg382c9d72016-04-24 11:28:28 +0200184 SOFTMARK, HARDMARK
185} mark_type;
186
187typedef enum {
Benno Schulenbergce0ea442014-06-23 18:20:12 +0000188 UPWARD, DOWNWARD
David Lawrence Ramseybf0e47d2005-08-01 18:27:10 +0000189} scroll_dir;
David Lawrence Ramsey3e0c8a62004-11-04 04:08:18 +0000190
191typedef enum {
Benno Schulenbergcb177322016-04-07 13:58:51 +0200192 CENTERING, FLOWING, STATIONARY
David Lawrence Ramseybf0e47d2005-08-01 18:27:10 +0000193} update_type;
David Lawrence Ramsey3e0c8a62004-11-04 04:08:18 +0000194
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000195typedef enum {
Benno Schulenbergc35eb5a2014-06-09 10:35:44 +0000196 ADD, DEL, BACK, CUT, CUT_EOF, REPLACE,
197#ifndef DISABLE_WRAPPING
198 SPLIT_BEGIN, SPLIT_END,
199#endif
Mike Scalora6a2032f2016-05-25 22:13:50 +0200200#ifndef DISABLE_COMMENT
201 COMMENT, UNCOMMENT, PREFLIGHT,
202#endif
Benno Schulenberg45fe2ad2014-06-18 20:11:52 +0000203 JOIN, PASTE, INSERT, ENTER, OTHER
Chris Allegretta07fcc4c2008-07-10 20:13:04 +0000204} undo_type;
205
Benno Schulenberg02555372015-06-18 19:07:56 +0000206/* Structure types. */
Benno Schulenberg00389922014-04-04 11:59:03 +0000207#ifndef DISABLE_COLOR
David Lawrence Ramseydb958022005-07-13 20:18:46 +0000208typedef struct colortype {
Chris Allegretta22c83ec2013-03-17 22:09:38 +0000209 short fg;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000210 /* This syntax's foreground color. */
Chris Allegretta22c83ec2013-03-17 22:09:38 +0000211 short bg;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000212 /* This syntax's background color. */
213 bool bright;
214 /* Is this color A_BOLD? */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000215 int pairnum;
216 /* The color pair number used for this foreground color and
217 * background color. */
Rishabh Dave4c566c72016-07-17 18:59:07 +0530218 int attributes;
219 /* Pair number and brightness composed into ready-to-use attributes. */
Benno Schulenberg6ed64622016-03-13 19:37:21 +0000220 int rex_flags;
221 /* The regex compilation flags (with or without REG_ICASE). */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000222 char *start_regex;
223 /* The start (or all) of the regex string. */
224 regex_t *start;
225 /* The compiled start (or all) of the regex string. */
226 char *end_regex;
227 /* The end (if any) of the regex string. */
228 regex_t *end;
229 /* The compiled end (if any) of the regex string. */
David Lawrence Ramseydb958022005-07-13 20:18:46 +0000230 struct colortype *next;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000231 /* Next set of colors. */
Benno Schulenberg8f615112014-04-14 09:57:06 +0000232 int id;
Benno Schulenberg817707e2014-04-04 12:29:28 +0000233 /* Basic id for assigning to lines later. */
David Lawrence Ramseydb958022005-07-13 20:18:46 +0000234} colortype;
235
Benno Schulenberg1d5134d2014-05-12 14:31:54 +0000236typedef struct regexlisttype {
Benno Schulenberg35227512016-02-26 20:09:29 +0000237 char *full_regex;
238 /* A regex string to match things that imply a certain syntax. */
Benno Schulenberg1d5134d2014-05-12 14:31:54 +0000239 struct regexlisttype *next;
Benno Schulenberg07441ad2016-02-26 20:19:13 +0000240 /* The next regex. */
Benno Schulenberg1d5134d2014-05-12 14:31:54 +0000241} regexlisttype;
David Lawrence Ramseydb958022005-07-13 20:18:46 +0000242
243typedef struct syntaxtype {
Benno Schulenberga24aee42016-02-29 09:17:03 +0000244 char *name;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000245 /* The name of this syntax. */
Benno Schulenberg1d5134d2014-05-12 14:31:54 +0000246 regexlisttype *extensions;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000247 /* The list of extensions that this syntax applies to. */
Benno Schulenberg1d5134d2014-05-12 14:31:54 +0000248 regexlisttype *headers;
Benno Schulenbergcf4f80d2014-05-12 13:52:50 +0000249 /* The list of headerlines that this syntax applies to. */
Benno Schulenberg1d5134d2014-05-12 14:31:54 +0000250 regexlisttype *magics;
Benno Schulenbergcf4f80d2014-05-12 13:52:50 +0000251 /* The list of libmagic results that this syntax applies to. */
Chris Allegretta5575bfa2014-02-24 10:18:15 +0000252 char *linter;
Benno Schulenberg773fc442016-02-29 10:54:48 +0000253 /* The command with which to lint this type of file. */
Chris Allegretta4b3f2772015-01-03 07:24:17 +0000254 char *formatter;
Benno Schulenberg773fc442016-02-29 10:54:48 +0000255 /* The formatting command (for programming languages mainly). */
Mike Scalora6a2032f2016-05-25 22:13:50 +0200256 char *comment;
257 /* The line comment prefix (and postfix) for this type of file. */
Benno Schulenberg773fc442016-02-29 10:54:48 +0000258 colortype *color;
259 /* The colors and their regexes used in this syntax. */
Chris Allegrettad47d8cd2009-01-25 07:25:17 +0000260 int nmultis;
Benno Schulenberg773fc442016-02-29 10:54:48 +0000261 /* How many multiline regex strings this syntax has. */
David Lawrence Ramseydb958022005-07-13 20:18:46 +0000262 struct syntaxtype *next;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000263 /* Next syntax. */
David Lawrence Ramseydb958022005-07-13 20:18:46 +0000264} syntaxtype;
Chris Allegretta364763f2009-02-03 05:05:58 +0000265
Chris Allegretta5575bfa2014-02-24 10:18:15 +0000266typedef struct lintstruct {
267 ssize_t lineno;
268 /* Line number of the error. */
269 ssize_t colno;
270 /* Column # of the error. */
271 char *msg;
Benno Schulenberg817707e2014-04-04 12:29:28 +0000272 /* Error message text. */
Chris Allegretta5575bfa2014-02-24 10:18:15 +0000273 char *filename;
Benno Schulenberg817707e2014-04-04 12:29:28 +0000274 /* Filename. */
Chris Allegretta5575bfa2014-02-24 10:18:15 +0000275 struct lintstruct *next;
276 /* Next error. */
277 struct lintstruct *prev;
Benno Schulenberg817707e2014-04-04 12:29:28 +0000278 /* Previous error. */
Chris Allegretta5575bfa2014-02-24 10:18:15 +0000279} lintstruct;
280
Benno Schulenberg02555372015-06-18 19:07:56 +0000281/* Flags that indicate how a multiline regex applies to a line. */
Benno Schulenberga65ef422014-03-17 21:36:37 +0000282#define CNONE (1<<1)
Chris Allegretta364763f2009-02-03 05:05:58 +0000283 /* Yay, regex doesn't apply to this line at all! */
Benno Schulenberga65ef422014-03-17 21:36:37 +0000284#define CBEGINBEFORE (1<<2)
Benno Schulenberg817707e2014-04-04 12:29:28 +0000285 /* Regex starts on an earlier line, ends on this one. */
Benno Schulenberga65ef422014-03-17 21:36:37 +0000286#define CENDAFTER (1<<3)
Benno Schulenberg817707e2014-04-04 12:29:28 +0000287 /* Regex starts on this line and ends on a later one. */
Benno Schulenberga65ef422014-03-17 21:36:37 +0000288#define CWHOLELINE (1<<4)
Benno Schulenberg817707e2014-04-04 12:29:28 +0000289 /* Whole line engulfed by the regex, start < me, end > me. */
Benno Schulenberga65ef422014-03-17 21:36:37 +0000290#define CSTARTENDHERE (1<<5)
Benno Schulenberg817707e2014-04-04 12:29:28 +0000291 /* Regex starts and ends within this line. */
Benno Schulenberg7ef5c532017-02-12 22:34:31 +0100292#define CWOULDBE (1<<6)
293 /* An unpaired start match on or before this line. */
Benno Schulenberg00389922014-04-04 11:59:03 +0000294#endif /* !DISABLE_COLOR */
David Lawrence Ramseydb958022005-07-13 20:18:46 +0000295
Benno Schulenberg02555372015-06-18 19:07:56 +0000296/* More structure types. */
Chris Allegrettaa1171632009-01-19 19:10:39 +0000297typedef struct filestruct {
298 char *data;
299 /* The text of this line. */
300 ssize_t lineno;
301 /* The number of this line. */
302 struct filestruct *next;
303 /* Next node. */
304 struct filestruct *prev;
305 /* Previous node. */
Benno Schulenberg00389922014-04-04 11:59:03 +0000306#ifndef DISABLE_COLOR
Benno Schulenberg817707e2014-04-04 12:29:28 +0000307 short *multidata;
308 /* Array of which multi-line regexes apply to this line. */
Chris Allegrettaa1171632009-01-19 19:10:39 +0000309#endif
310} filestruct;
311
312typedef struct partition {
313 filestruct *fileage;
314 /* The top line of this portion of the file. */
315 filestruct *top_prev;
316 /* The line before the top line of this portion of the file. */
317 char *top_data;
318 /* The text before the beginning of the top line of this portion
319 * of the file. */
320 filestruct *filebot;
321 /* The bottom line of this portion of the file. */
322 filestruct *bot_next;
323 /* The line after the bottom line of this portion of the
324 * file. */
325 char *bot_data;
326 /* The text after the end of the bottom line of this portion of
327 * the file. */
328} partition;
329
Chris Allegretta07fcc4c2008-07-10 20:13:04 +0000330#ifndef NANO_TINY
Mike Scalora6a2032f2016-05-25 22:13:50 +0200331typedef struct undo_group {
332 ssize_t top_line;
333 /* First line of group. */
334 ssize_t bottom_line;
335 /* Last line of group. */
336 struct undo_group *next;
337} undo_group;
338
Chris Allegretta07fcc4c2008-07-10 20:13:04 +0000339typedef struct undo {
Chris Allegretta12dc8ca2008-07-31 04:24:04 +0000340 ssize_t lineno;
Chris Allegretta07fcc4c2008-07-10 20:13:04 +0000341 undo_type type;
Benno Schulenberg817707e2014-04-04 12:29:28 +0000342 /* What type of undo this was. */
Benno Schulenberg60815462014-05-15 20:00:46 +0000343 size_t begin;
Benno Schulenberg817707e2014-04-04 12:29:28 +0000344 /* Where did this action begin or end. */
Chris Allegretta07fcc4c2008-07-10 20:13:04 +0000345 char *strdata;
Benno Schulenberg817707e2014-04-04 12:29:28 +0000346 /* String type data we will use for copying the affected line back. */
Benno Schulenberg66e21412015-11-30 16:21:51 +0000347 size_t wassize;
348 /* The file size before the action. */
349 size_t newsize;
350 /* The file size after the action. */
Chris Allegretta0b499d42008-07-14 07:18:22 +0000351 int xflags;
Benno Schulenberg817707e2014-04-04 12:29:28 +0000352 /* Some flag data we need. */
Mike Scalora6a2032f2016-05-25 22:13:50 +0200353 undo_group *grouping;
354 /* Undo info specific to groups of lines. */
Chris Allegretta12dc8ca2008-07-31 04:24:04 +0000355
Benno Schulenberg817707e2014-04-04 12:29:28 +0000356 /* Cut-specific stuff we need. */
Chris Allegretta12dc8ca2008-07-31 04:24:04 +0000357 filestruct *cutbuffer;
Benno Schulenberg817707e2014-04-04 12:29:28 +0000358 /* Copy of the cutbuffer. */
Chris Allegretta12dc8ca2008-07-31 04:24:04 +0000359 filestruct *cutbottom;
Benno Schulenberg817707e2014-04-04 12:29:28 +0000360 /* Copy of cutbottom. */
Chris Allegretta12dc8ca2008-07-31 04:24:04 +0000361 ssize_t mark_begin_lineno;
Benno Schulenberg83b89a42016-06-07 11:52:57 +0200362 /* Mostly the line number of the current line; sometimes something else. */
Benno Schulenberg60815462014-05-15 20:00:46 +0000363 size_t mark_begin_x;
Benno Schulenberg83b89a42016-06-07 11:52:57 +0200364 /* The x position corresponding to the above line number. */
Chris Allegretta12dc8ca2008-07-31 04:24:04 +0000365 struct undo *next;
Benno Schulenberg83b89a42016-06-07 11:52:57 +0200366 /* A pointer to the undo item of the preceding action. */
Chris Allegretta07fcc4c2008-07-10 20:13:04 +0000367} undo;
Benno Schulenbergb341f292014-06-19 20:05:24 +0000368#endif /* !NANO_TINY */
Chris Allegretta12dc8ca2008-07-31 04:24:04 +0000369
Benno Schulenbergb341f292014-06-19 20:05:24 +0000370#ifndef DISABLE_HISTORIES
Chris Allegretta9bfda912011-02-16 06:52:30 +0000371typedef struct poshiststruct {
372 char *filename;
Benno Schulenberg5df7c0d2014-04-16 09:32:53 +0000373 /* The file. */
Chris Allegretta9bfda912011-02-16 06:52:30 +0000374 ssize_t lineno;
Benno Schulenberg817707e2014-04-04 12:29:28 +0000375 /* Line number we left off on. */
Chris Allegretta9bfda912011-02-16 06:52:30 +0000376 ssize_t xno;
Benno Schulenberg817707e2014-04-04 12:29:28 +0000377 /* x position in the file we left off on. */
Chris Allegretta9bfda912011-02-16 06:52:30 +0000378 struct poshiststruct *next;
379} poshiststruct;
Benno Schulenbergb341f292014-06-19 20:05:24 +0000380#endif
Chris Allegretta12dc8ca2008-07-31 04:24:04 +0000381
Chris Allegrettaf2387fb2002-04-10 02:31:20 +0000382typedef struct openfilestruct {
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000383 char *filename;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000384 /* The file's name. */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000385 filestruct *fileage;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000386 /* The file's first line. */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000387 filestruct *filebot;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000388 /* The file's last line. */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000389 filestruct *edittop;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000390 /* The current top of the edit window for this file. */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000391 filestruct *current;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000392 /* The current line for this file. */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000393 size_t totsize;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000394 /* The file's total number of characters. */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000395 size_t current_x;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000396 /* The file's x-coordinate position. */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000397 size_t placewewant;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000398 /* The file's x position we would like. */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000399 ssize_t current_y;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000400 /* The file's y-coordinate position. */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000401 bool modified;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000402 /* Whether the file has been modified. */
Benno Schulenbergf6dd0ad2016-08-02 17:26:25 +0200403 struct stat *current_stat;
404 /* The file's current stat information. */
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000405#ifndef NANO_TINY
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000406 bool mark_set;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000407 /* Whether the mark is on in this file. */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000408 filestruct *mark_begin;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000409 /* The file's line where the mark is, if any. */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000410 size_t mark_begin_x;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000411 /* The file's mark's x-coordinate position, if any. */
Benno Schulenberg382c9d72016-04-24 11:28:28 +0200412 mark_type kind_of_mark;
413 /* Whether this is a soft or a hard mark. */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000414 file_format fmt;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000415 /* The file's format. */
Chris Allegretta07fcc4c2008-07-10 20:13:04 +0000416 undo *undotop;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000417 /* The top of the undo list. */
Chris Allegretta07fcc4c2008-07-10 20:13:04 +0000418 undo *current_undo;
Benno Schulenberg817707e2014-04-04 12:29:28 +0000419 /* The current (i.e. next) level of undo. */
Chris Allegretta07fcc4c2008-07-10 20:13:04 +0000420 undo_type last_action;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000421 /* The type of the last action the user performed. */
Benno Schulenberg9fcde232015-07-10 15:54:06 +0000422 char *lock_filename;
Benno Schulenberg5df7c0d2014-04-16 09:32:53 +0000423 /* The path of the lockfile, if we created one. */
Chris Allegretta2d7893d2001-07-11 02:08:33 +0000424#endif
Benno Schulenberg00389922014-04-04 11:59:03 +0000425#ifndef DISABLE_COLOR
Chris Allegrettad47d8cd2009-01-25 07:25:17 +0000426 syntaxtype *syntax;
Benno Schulenberg817707e2014-04-04 12:29:28 +0000427 /* The syntax struct for this file, if any. */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000428 colortype *colorstrings;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000429 /* The file's associated colors. */
David Lawrence Ramseydb958022005-07-13 20:18:46 +0000430#endif
David Lawrence Ramsey6ad59cd2005-07-08 20:09:16 +0000431 struct openfilestruct *next;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000432 /* The next open file, if any. */
David Lawrence Ramsey6ad59cd2005-07-08 20:09:16 +0000433 struct openfilestruct *prev;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000434 /* The preceding open file, if any. */
David Lawrence Ramsey6ad59cd2005-07-08 20:09:16 +0000435} openfilestruct;
Chris Allegretta2d7893d2001-07-11 02:08:33 +0000436
Benno Schulenbergeea09082014-04-13 20:50:20 +0000437#ifndef DISABLE_NANORC
Chris Allegretta8d8e0122001-04-18 04:28:54 +0000438typedef struct rcoption {
Benno Schulenberg17cf8332016-05-30 09:09:36 +0200439 const char *name;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000440 /* The name of the rcfile option. */
Benno Schulenberg17cf8332016-05-30 09:09:36 +0200441 long flag;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000442 /* The flag associated with it, if any. */
Chris Allegretta8d8e0122001-04-18 04:28:54 +0000443} rcoption;
David Lawrence Ramsey6d9aa082004-11-03 14:58:04 +0000444#endif
Chris Allegretta8d8e0122001-04-18 04:28:54 +0000445
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000446typedef struct sc {
Benno Schulenberg3930a692016-07-30 12:44:23 +0200447 const char *keystr;
Benno Schulenberg1c9ab8b2016-07-24 21:49:07 +0200448 /* The string that describes a keystroke, like "^C" or "M-R". */
Benno Schulenberge2950702016-07-23 14:42:40 +0200449 bool meta;
450 /* Whether this is a Meta keystroke. */
Benno Schulenberg1c9ab8b2016-07-24 21:49:07 +0200451 int keycode;
452 /* The integer that, together with meta, identifies the keystroke. */
Benno Schulenberg1f866c22015-07-15 20:13:05 +0000453 int menus;
454 /* Which menus this applies to. */
Chris Allegretta637daa82011-02-07 14:45:56 +0000455 void (*scfunc)(void);
Benno Schulenberg5df7c0d2014-04-16 09:32:53 +0000456 /* The function we're going to run. */
Benno Schulenberg7b7d2bf2016-09-01 09:36:47 +0200457#ifndef NANO_TINY
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000458 int toggle;
Benno Schulenberg5df7c0d2014-04-16 09:32:53 +0000459 /* If a toggle, what we're toggling. */
Benno Schulenberg5ac6a872015-07-06 17:51:17 +0000460 int ordinal;
461 /* The how-manieth toggle this is, in order to be able to
462 * keep them in sequence. */
Benno Schulenberg7b7d2bf2016-09-01 09:36:47 +0200463#endif
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000464 struct sc *next;
Benno Schulenberg5df7c0d2014-04-16 09:32:53 +0000465 /* Next in the list. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000466} sc;
467
468typedef struct subnfunc {
Chris Allegretta637daa82011-02-07 14:45:56 +0000469 void (*scfunc)(void);
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000470 /* The actual function to call. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000471 int menus;
Benno Schulenberg817707e2014-04-04 12:29:28 +0000472 /* In what menus this function applies. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000473 const char *desc;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000474 /* The function's short description, for example "Where Is". */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000475#ifndef DISABLE_HELP
476 const char *help;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000477 /* The help-screen text for this function. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000478 bool blank_after;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000479 /* Whether there should be a blank line after the help text
480 * for this function. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000481#endif
482 bool viewok;
Benno Schulenberg5df7c0d2014-04-16 09:32:53 +0000483 /* Is this function allowed when in view mode? */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000484 long toggle;
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000485 /* If this is a toggle, which toggle to affect. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000486 struct subnfunc *next;
Benno Schulenberg817707e2014-04-04 12:29:28 +0000487 /* Next item in the list. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000488} subnfunc;
489
Benno Schulenberg68a03142016-12-07 13:10:40 +0100490#ifdef ENABLE_WORDCOMPLETION
Sumedh Pendurkardca4ab52016-12-07 09:43:47 +0530491typedef struct completion_word {
492 char *word;
493 struct completion_word *next;
494} completion_word;
495#endif
496
Benno Schulenberg16639942014-05-03 18:24:45 +0000497/* The elements of the interface that can be colored differently. */
498enum
499{
500 TITLE_BAR = 0,
Benno Schulenbergde2aa4f2016-10-20 10:07:48 +0200501 LINE_NUMBER,
Benno Schulenberg16639942014-05-03 18:24:45 +0000502 STATUS_BAR,
503 KEY_COMBO,
504 FUNCTION_TAG,
505 NUMBER_OF_ELEMENTS
506};
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000507
Benno Schulenbergeb91ad52014-05-15 13:11:55 +0000508/* Enumeration used in the flags array. See the definition of FLAGMASK. */
Chris Allegrettaa48507d2009-08-14 03:18:29 +0000509enum
510{
Chris Allegretta795be592009-11-07 16:56:17 +0000511 DONTUSE,
Chris Allegrettaa48507d2009-08-14 03:18:29 +0000512 CASE_SENSITIVE,
513 CONST_UPDATE,
514 NO_HELP,
Chris Allegrettaa48507d2009-08-14 03:18:29 +0000515 SUSPEND,
516 NO_WRAP,
517 AUTOINDENT,
518 VIEW_MODE,
519 USE_MOUSE,
520 USE_REGEXP,
521 TEMP_FILE,
522 CUT_TO_END,
523 BACKWARDS_SEARCH,
524 MULTIBUFFER,
525 SMOOTH_SCROLL,
526 REBIND_DELETE,
527 REBIND_KEYPAD,
528 NO_CONVERT,
529 BACKUP_FILE,
Chris Allegretta0acca272010-06-21 03:10:10 +0000530 INSECURE_BACKUP,
Chris Allegrettaa48507d2009-08-14 03:18:29 +0000531 NO_COLOR_SYNTAX,
532 PRESERVE,
533 HISTORYLOG,
534 RESTRICTED,
535 SMART_HOME,
536 WHITESPACE_DISPLAY,
537 MORE_SPACE,
538 TABS_TO_SPACES,
539 QUICK_BLANK,
540 WORD_BOUNDS,
541 NO_NEWLINES,
542 BOLD_TEXT,
543 QUIET,
Chris Allegretta9bfda912011-02-16 06:52:30 +0000544 SOFTWRAP,
Chris Allegrettabf88d272013-01-01 03:24:39 +0000545 POS_HISTORY,
Benno Schulenbergdb7064b2014-04-08 18:59:30 +0000546 LOCKING,
Benno Schulenberg70cbbda2015-08-04 18:49:57 +0000547 NOREAD_MODE,
Chris Allegretta6a0ae5a2016-02-22 15:10:32 +0000548 MAKE_IT_UNIX,
Benno Schulenbergb92d35d2016-09-11 09:41:09 +0200549 JUSTIFY_TRIM,
Faissal Bensefiade95ca62016-10-20 09:44:29 +0100550 SHOW_CURSOR,
551 LINE_NUMBERS
Chris Allegrettaa48507d2009-08-14 03:18:29 +0000552};
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000553
Benno Schulenberg817707e2014-04-04 12:29:28 +0000554/* Flags for the menus in which a given function should be present. */
Benno Schulenberg5df7c0d2014-04-16 09:32:53 +0000555#define MMAIN (1<<0)
556#define MWHEREIS (1<<1)
557#define MREPLACE (1<<2)
558#define MREPLACEWITH (1<<3)
559#define MGOTOLINE (1<<4)
560#define MWRITEFILE (1<<5)
561#define MINSERTFILE (1<<6)
562#define MEXTCMD (1<<7)
563#define MHELP (1<<8)
564#define MSPELL (1<<9)
565#define MBROWSER (1<<10)
566#define MWHEREISFILE (1<<11)
567#define MGOTODIR (1<<12)
568#define MYESNO (1<<13)
569#define MLINTER (1<<14)
Benno Schulenberg4c9573d2014-04-16 09:12:13 +0000570/* This is an abbreviation for all menus except Help and YesNo. */
Benno Schulenbergbf84e592015-11-02 10:40:06 +0000571#define MMOST (MMAIN|MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE|MWRITEFILE|MINSERTFILE|\
572 MEXTCMD|MBROWSER|MWHEREISFILE|MGOTODIR|MSPELL|MLINTER)
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000573
Benno Schulenberg90a90362016-08-01 12:56:05 +0200574/* Basic control codes. */
575#define TAB_CODE 0x09
576#define ESC_CODE 0x1B
577#define DEL_CODE 0x7F
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000578
Benno Schulenbergf08d79d2015-11-23 08:52:23 +0000579/* Codes for "modified" Arrow keys, beyond KEY_MAX of ncurses. */
580#define CONTROL_LEFT 0x401
581#define CONTROL_RIGHT 0x402
Benno Schulenbergc6dbcf92016-06-25 15:16:52 +0200582#define CONTROL_UP 0x403
583#define CONTROL_DOWN 0x404
Benno Schulenberg382c9d72016-04-24 11:28:28 +0200584#define SHIFT_CONTROL_LEFT 0x405
585#define SHIFT_CONTROL_RIGHT 0x406
586#define SHIFT_CONTROL_UP 0x407
587#define SHIFT_CONTROL_DOWN 0x408
588#define SHIFT_ALT_LEFT 0x409
589#define SHIFT_ALT_RIGHT 0x40a
590#define SHIFT_ALT_UP 0x40b
591#define SHIFT_ALT_DOWN 0x40c
592#define SHIFT_PAGEUP 0x40d
593#define SHIFT_PAGEDOWN 0x40e
Benno Schulenberg272a9532016-08-30 10:11:29 +0200594#define SHIFT_HOME 0x40f
595#define SHIFT_END 0x410
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000596
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000597#ifndef NANO_TINY
Benno Schulenberg75d64e62015-05-28 13:02:29 +0000598/* An imaginary key for when we get a SIGWINCH (window resize). */
599#define KEY_WINCH -2
600
Benno Schulenbergf0bb5032015-06-27 09:27:19 +0000601/* Some extra flags for the undo function. */
602#define WAS_FINAL_BACKSPACE (1<<1)
Benno Schulenberg83b89a42016-06-07 11:52:57 +0200603#define WAS_WHOLE_LINE (1<<2)
604/* The flags for the mark need to be the highest. */
605#define MARK_WAS_SET (1<<3)
606#define WAS_MARKED_FORWARD (1<<4)
Chris Allegretta2d1bdd02009-01-28 05:11:57 +0000607#endif /* !NANO_TINY */
608
David Lawrence Ramseyfc0f8f82006-05-10 13:41:53 +0000609/* The maximum number of entries displayed in the main shortcut list. */
Benno Schulenberg8977c4b2014-03-16 16:58:18 +0000610#define MAIN_VISIBLE (((COLS + 40) / 20) * 2)
David Lawrence Ramseyfc0f8f82006-05-10 13:41:53 +0000611
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000612/* The default number of characters from the end of the line where
613 * wrapping occurs. */
Chris Allegrettae61e8302001-01-14 05:18:27 +0000614#define CHARS_FROM_EOL 8
615
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000616/* The default width of a tab in spaces. */
David Lawrence Ramsey02517e02004-09-05 21:40:31 +0000617#define WIDTH_OF_TAB 8
618
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000619/* The maximum number of search/replace history strings saved, not
620 * counting the blank lines at their ends. */
Chris Allegretta5beed502003-01-05 20:41:21 +0000621#define MAX_SEARCH_HISTORY 100
Chris Allegretta7662c862003-01-13 01:35:15 +0000622
David Lawrence Ramsey91493252006-03-19 19:25:29 +0000623/* The maximum number of bytes buffered at one time. */
David Lawrence Ramsey5b2f17e2005-04-19 21:47:01 +0000624#define MAX_BUF_SIZE 128
625
Benno Schulenberg660584c2016-06-01 21:29:44 +0200626/* The largest size_t number that doesn't have the high bit set. */
627#define HIGHEST_POSITIVE ((~(size_t)0) >> 1)
628
Chris Allegrettad865da12002-07-29 23:46:38 +0000629#endif /* !NANO_H */