2000-08-07 01:13:45 +04:00
|
|
|
/* $Id$ */
|
2000-06-06 09:53:49 +04:00
|
|
|
/**************************************************************************
|
|
|
|
* nano.c *
|
|
|
|
* *
|
2004-01-10 02:04:55 +03:00
|
|
|
* Copyright (C) 1999-2004 Chris Allegretta *
|
2000-06-06 09:53:49 +04:00
|
|
|
* 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 *
|
2001-10-24 15:33:54 +04:00
|
|
|
* the Free Software Foundation; either version 2, or (at your option) *
|
2000-06-06 09:53:49 +04:00
|
|
|
* 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. *
|
|
|
|
* *
|
|
|
|
**************************************************************************/
|
|
|
|
|
2001-04-28 22:03:52 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-06-06 09:53:49 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/param.h>
|
2000-11-05 19:52:21 +03:00
|
|
|
#include <sys/wait.h>
|
2000-06-06 09:53:49 +04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <limits.h>
|
2000-06-07 07:56:54 +04:00
|
|
|
#include <assert.h>
|
2000-06-06 09:53:49 +04:00
|
|
|
#include "proto.h"
|
|
|
|
#include "nano.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_TERMIOS_H
|
|
|
|
#include <termios.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_TERMIO_H
|
|
|
|
#include <termio.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_GETOPT_H
|
|
|
|
#include <getopt.h>
|
|
|
|
#endif
|
|
|
|
|
2004-05-18 05:20:36 +04:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
#include <setjmp.h>
|
|
|
|
#endif
|
|
|
|
|
2001-05-21 16:56:25 +04:00
|
|
|
#ifndef DISABLE_WRAPJUSTIFY
|
2004-07-12 20:07:14 +04:00
|
|
|
static ssize_t fill = 0; /* Fill - where to wrap lines,
|
|
|
|
basically */
|
2001-05-21 16:56:25 +04:00
|
|
|
#endif
|
2003-09-11 00:08:00 +04:00
|
|
|
#ifndef DISABLE_WRAPPING
|
2004-06-22 19:38:47 +04:00
|
|
|
static int same_line_wrap = FALSE; /* Whether wrapped text should
|
|
|
|
be prepended to the next
|
|
|
|
line */
|
2003-09-11 00:08:00 +04:00
|
|
|
#endif
|
2001-01-12 10:51:05 +03:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
static struct termios oldterm; /* The user's original term settings */
|
2001-05-05 21:45:54 +04:00
|
|
|
static struct sigaction act; /* For all our fun signal handlers */
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2004-05-18 05:20:36 +04:00
|
|
|
#ifndef NANO_SMALL
|
2004-06-22 19:38:47 +04:00
|
|
|
static sigjmp_buf jmpbuf; /* Used to return to mainloop after
|
|
|
|
SIGWINCH */
|
2004-05-18 05:20:36 +04:00
|
|
|
#endif
|
2001-01-30 02:37:54 +03:00
|
|
|
|
2004-05-25 23:41:11 +04:00
|
|
|
/* What we do when we're all set to exit. */
|
|
|
|
void finish(void)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
2004-05-18 05:20:36 +04:00
|
|
|
if (!ISSET(NO_HELP))
|
|
|
|
blank_bottombars();
|
|
|
|
else
|
|
|
|
blank_statusbar();
|
2001-04-12 07:01:53 +04:00
|
|
|
|
2000-06-06 09:53:49 +04:00
|
|
|
wrefresh(bottomwin);
|
|
|
|
endwin();
|
|
|
|
|
2004-05-18 05:20:36 +04:00
|
|
|
/* Restore the old terminal settings. */
|
2000-06-21 07:00:43 +04:00
|
|
|
tcsetattr(0, TCSANOW, &oldterm);
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2003-03-11 06:50:40 +03:00
|
|
|
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
|
|
|
|
if (!ISSET(NO_RCFILE) && ISSET(HISTORYLOG))
|
|
|
|
save_history();
|
|
|
|
#endif
|
|
|
|
|
2002-05-12 23:52:15 +04:00
|
|
|
#ifdef DEBUG
|
2002-02-27 07:14:16 +03:00
|
|
|
thanks_for_all_the_fish();
|
2002-05-12 23:52:15 +04:00
|
|
|
#endif
|
2002-02-27 07:14:16 +03:00
|
|
|
|
2004-05-25 23:41:11 +04:00
|
|
|
exit(0);
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Die (gracefully?) */
|
2002-07-19 05:08:59 +04:00
|
|
|
void die(const char *msg, ...)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2003-02-03 06:32:08 +03:00
|
|
|
endwin();
|
|
|
|
curses_ended = TRUE;
|
|
|
|
|
2004-05-18 05:20:36 +04:00
|
|
|
/* Restore the old terminal settings. */
|
2001-07-11 06:08:33 +04:00
|
|
|
tcsetattr(0, TCSANOW, &oldterm);
|
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
va_start(ap, msg);
|
|
|
|
vfprintf(stderr, msg, ap);
|
|
|
|
va_end(ap);
|
2001-07-11 06:08:33 +04:00
|
|
|
|
2002-01-02 18:12:21 +03:00
|
|
|
/* save the currently loaded file if it's been modified */
|
|
|
|
if (ISSET(MODIFIED))
|
|
|
|
die_save_file(filename);
|
2001-07-11 06:08:33 +04:00
|
|
|
|
2001-07-14 23:32:47 +04:00
|
|
|
#ifdef ENABLE_MULTIBUFFER
|
2002-01-02 18:12:21 +03:00
|
|
|
/* then save all of the other modified loaded files, if any */
|
2002-12-22 19:30:00 +03:00
|
|
|
if (open_files != NULL) {
|
2002-04-10 06:31:20 +04:00
|
|
|
openfilestruct *tmp;
|
2001-07-11 06:08:33 +04:00
|
|
|
|
|
|
|
tmp = open_files;
|
|
|
|
|
2002-12-22 19:30:00 +03:00
|
|
|
while (open_files->prev != NULL)
|
2001-07-11 06:08:33 +04:00
|
|
|
open_files = open_files->prev;
|
|
|
|
|
2002-12-22 19:30:00 +03:00
|
|
|
while (open_files->next != NULL) {
|
2001-07-11 06:08:33 +04:00
|
|
|
|
2004-04-05 05:08:14 +04:00
|
|
|
/* if we already saved the file above (i.e, if it was the
|
2001-07-11 06:08:33 +04:00
|
|
|
currently loaded file), don't save it again */
|
|
|
|
if (tmp != open_files) {
|
2002-05-11 07:04:44 +04:00
|
|
|
/* make sure open_files->fileage and fileage, and
|
|
|
|
open_files->filebot and filebot, are in sync; they
|
|
|
|
might not be if lines have been cut from the top or
|
|
|
|
bottom of the file */
|
2002-04-10 06:31:20 +04:00
|
|
|
fileage = open_files->fileage;
|
2002-05-11 07:04:44 +04:00
|
|
|
filebot = open_files->filebot;
|
2002-01-02 18:12:21 +03:00
|
|
|
/* save the file if it's been modified */
|
2002-05-11 07:04:44 +04:00
|
|
|
if (open_files->file_flags & MODIFIED)
|
2002-04-10 06:31:20 +04:00
|
|
|
die_save_file(open_files->filename);
|
2001-07-11 06:08:33 +04:00
|
|
|
}
|
|
|
|
open_files = open_files->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
exit(1); /* We have a problem: exit w/ errorlevel(1) */
|
2001-07-11 06:08:33 +04:00
|
|
|
}
|
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
void die_save_file(const char *die_filename)
|
2001-07-11 06:08:33 +04:00
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
char *ret;
|
2002-02-22 07:30:50 +03:00
|
|
|
int i = -1;
|
2001-07-11 06:08:33 +04:00
|
|
|
|
2004-05-29 05:20:17 +04:00
|
|
|
/* If we're using restricted mode, don't write any emergency backup
|
|
|
|
* files, since that would allow reading from or writing to files
|
|
|
|
* not specified on the command line. */
|
2004-04-30 08:49:02 +04:00
|
|
|
if (ISSET(RESTRICTED))
|
|
|
|
return;
|
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
/* If we can't save, we have REAL bad problems, but we might as well
|
|
|
|
TRY. */
|
|
|
|
if (die_filename[0] == '\0')
|
|
|
|
ret = get_next_filename("nano.save");
|
2002-02-22 07:30:50 +03:00
|
|
|
else {
|
2001-07-11 06:08:33 +04:00
|
|
|
char *buf = charalloc(strlen(die_filename) + 6);
|
2002-07-19 05:08:59 +04:00
|
|
|
|
2001-07-11 06:08:33 +04:00
|
|
|
strcpy(buf, die_filename);
|
2000-12-02 05:36:22 +03:00
|
|
|
strcat(buf, ".save");
|
2002-02-22 07:30:50 +03:00
|
|
|
ret = get_next_filename(buf);
|
2002-04-06 09:02:14 +04:00
|
|
|
free(buf);
|
2000-07-17 07:04:54 +04:00
|
|
|
}
|
2002-07-19 05:08:59 +04:00
|
|
|
if (ret[0] != '\0')
|
2004-05-28 04:15:28 +04:00
|
|
|
i = write_file(ret, TRUE, FALSE, TRUE);
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2000-12-02 07:36:50 +03:00
|
|
|
if (i != -1)
|
2002-07-19 05:08:59 +04:00
|
|
|
fprintf(stderr, _("\nBuffer written to %s\n"), ret);
|
2000-12-02 07:36:50 +03:00
|
|
|
else
|
2002-07-19 05:08:59 +04:00
|
|
|
fprintf(stderr, _("\nNo %s written (too many backup files?)\n"), ret);
|
2002-02-22 07:30:50 +03:00
|
|
|
|
|
|
|
free(ret);
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
|
|
|
|
2001-01-14 08:18:27 +03:00
|
|
|
/* Die with an error message that the screen was too small if, well, the
|
2002-07-19 05:08:59 +04:00
|
|
|
* screen is too small. */
|
2002-08-21 20:10:37 +04:00
|
|
|
void die_too_small(void)
|
2001-01-14 08:18:27 +03:00
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
die(_("Window size is too small for nano...\n"));
|
2001-01-14 08:18:27 +03:00
|
|
|
}
|
|
|
|
|
2000-06-06 09:53:49 +04:00
|
|
|
void print_view_warning(void)
|
|
|
|
{
|
|
|
|
statusbar(_("Key illegal in VIEW mode"));
|
|
|
|
}
|
|
|
|
|
2004-01-10 02:04:55 +03:00
|
|
|
/* Initialize global variables -- no better way for now. If
|
2002-07-19 05:08:59 +04:00
|
|
|
* save_cutbuffer is nonzero, don't set cutbuffer to NULL. */
|
2002-08-21 20:10:37 +04:00
|
|
|
void global_init(int save_cutbuffer)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
|
|
|
current_x = 0;
|
|
|
|
current_y = 0;
|
2001-01-14 08:18:27 +03:00
|
|
|
|
2003-02-10 05:43:48 +03:00
|
|
|
editwinrows = LINES - 5 + no_help();
|
|
|
|
if (editwinrows < MIN_EDITOR_ROWS || COLS < MIN_EDITOR_COLS)
|
2001-01-14 08:18:27 +03:00
|
|
|
die_too_small();
|
|
|
|
|
2000-06-06 09:53:49 +04:00
|
|
|
fileage = NULL;
|
2001-09-27 06:46:53 +04:00
|
|
|
if (!save_cutbuffer)
|
|
|
|
cutbuffer = NULL;
|
2000-06-06 09:53:49 +04:00
|
|
|
current = NULL;
|
|
|
|
edittop = NULL;
|
|
|
|
totlines = 0;
|
2001-09-27 06:46:53 +04:00
|
|
|
totsize = 0;
|
2000-06-06 09:53:49 +04:00
|
|
|
placewewant = 0;
|
2001-01-14 08:18:27 +03:00
|
|
|
|
2001-05-21 16:56:25 +04:00
|
|
|
#ifndef DISABLE_WRAPJUSTIFY
|
2002-07-19 05:08:59 +04:00
|
|
|
fill = wrap_at;
|
2002-07-24 05:02:26 +04:00
|
|
|
if (fill <= 0)
|
2002-07-19 05:08:59 +04:00
|
|
|
fill += COLS;
|
2003-02-10 05:43:48 +03:00
|
|
|
if (fill < 0)
|
|
|
|
fill = 0;
|
2001-05-21 16:56:25 +04:00
|
|
|
#endif
|
2001-01-14 08:18:27 +03:00
|
|
|
|
2001-05-17 15:35:43 +04:00
|
|
|
hblank = charalloc(COLS + 1);
|
2001-01-23 05:35:04 +03:00
|
|
|
memset(hblank, ' ', COLS);
|
2002-06-13 04:40:19 +04:00
|
|
|
hblank[COLS] = '\0';
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
void window_init(void)
|
|
|
|
{
|
2003-02-10 05:43:48 +03:00
|
|
|
editwinrows = LINES - 5 + no_help();
|
|
|
|
if (editwinrows < MIN_EDITOR_ROWS)
|
2002-09-07 00:35:28 +04:00
|
|
|
die_too_small();
|
|
|
|
|
2003-01-26 07:15:56 +03:00
|
|
|
if (topwin != NULL)
|
|
|
|
delwin(topwin);
|
2004-03-29 22:36:39 +04:00
|
|
|
if (edit != NULL)
|
|
|
|
delwin(edit);
|
2003-01-26 07:15:56 +03:00
|
|
|
if (bottomwin != NULL)
|
|
|
|
delwin(bottomwin);
|
|
|
|
|
2004-03-29 22:36:39 +04:00
|
|
|
/* Set up the windows. */
|
2002-09-07 00:35:28 +04:00
|
|
|
topwin = newwin(2, COLS, 0, 0);
|
2004-03-29 22:36:39 +04:00
|
|
|
edit = newwin(editwinrows, COLS, 2, 0);
|
2002-09-07 00:35:28 +04:00
|
|
|
bottomwin = newwin(3 - no_help(), COLS, LINES - 3 + no_help(), 0);
|
|
|
|
|
2004-05-18 05:20:36 +04:00
|
|
|
/* Turn the keypad back on. */
|
2002-09-07 00:35:28 +04:00
|
|
|
keypad(edit, TRUE);
|
|
|
|
keypad(bottomwin, TRUE);
|
|
|
|
}
|
|
|
|
|
2003-10-04 00:26:25 +04:00
|
|
|
#ifndef DISABLE_MOUSE
|
2002-09-07 00:35:28 +04:00
|
|
|
void mouse_init(void)
|
|
|
|
{
|
|
|
|
if (ISSET(USE_MOUSE)) {
|
|
|
|
mousemask(BUTTON1_RELEASED, NULL);
|
|
|
|
mouseinterval(50);
|
|
|
|
} else
|
|
|
|
mousemask(0, NULL);
|
|
|
|
}
|
2002-12-22 19:30:00 +03:00
|
|
|
#endif
|
2002-09-07 00:35:28 +04:00
|
|
|
|
|
|
|
#ifndef DISABLE_HELP
|
|
|
|
/* This function allocates help_text, and stores the help string in it.
|
|
|
|
* help_text should be NULL initially. */
|
|
|
|
void help_init(void)
|
|
|
|
{
|
2003-01-15 14:18:58 +03:00
|
|
|
size_t allocsize = 1; /* space needed for help_text */
|
2002-09-07 00:35:28 +04:00
|
|
|
char *ptr = NULL;
|
2004-03-20 00:46:34 +03:00
|
|
|
const shortcut *s;
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
const toggle *t;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* First set up the initial help text for the current function */
|
|
|
|
if (currshortcut == whereis_list || currshortcut == replace_list
|
|
|
|
|| currshortcut == replace_list_2)
|
|
|
|
ptr = _("Search Command Help Text\n\n "
|
|
|
|
"Enter the words or characters you would like to search "
|
|
|
|
"for, then hit enter. If there is a match for the text you "
|
|
|
|
"entered, the screen will be updated to the location of the "
|
|
|
|
"nearest match for the search string.\n\n "
|
2003-01-06 01:00:41 +03:00
|
|
|
"The previous search string will be shown in brackets after "
|
|
|
|
"the Search: prompt. Hitting Enter without entering any text "
|
|
|
|
"will perform the previous search.\n\n The following function "
|
|
|
|
"keys are available in Search mode:\n\n");
|
2002-09-07 00:35:28 +04:00
|
|
|
else if (currshortcut == goto_list)
|
|
|
|
ptr = _("Go To Line Help Text\n\n "
|
|
|
|
"Enter the line number that you wish to go to and hit "
|
|
|
|
"Enter. If there are fewer lines of text than the "
|
|
|
|
"number you entered, you will be brought to the last line "
|
|
|
|
"of the file.\n\n The following function keys are "
|
|
|
|
"available in Go To Line mode:\n\n");
|
|
|
|
else if (currshortcut == insertfile_list)
|
|
|
|
ptr = _("Insert File Help Text\n\n "
|
|
|
|
"Type in the name of a file to be inserted into the current "
|
|
|
|
"file buffer at the current cursor location.\n\n "
|
|
|
|
"If you have compiled nano with multiple file buffer "
|
|
|
|
"support, and enable multiple buffers with the -F "
|
|
|
|
"or --multibuffer command line flags, the Meta-F toggle, or "
|
|
|
|
"a nanorc file, inserting a file will cause it to be "
|
|
|
|
"loaded into a separate buffer (use Meta-< and > to switch "
|
|
|
|
"between file buffers).\n\n If you need another blank "
|
|
|
|
"buffer, do not enter any filename, or type in a "
|
|
|
|
"nonexistent filename at the prompt and press "
|
|
|
|
"Enter.\n\n The following function keys are "
|
|
|
|
"available in Insert File mode:\n\n");
|
|
|
|
else if (currshortcut == writefile_list)
|
|
|
|
ptr = _("Write File Help Text\n\n "
|
|
|
|
"Type the name that you wish to save the current file "
|
|
|
|
"as and hit Enter to save the file.\n\n If you have "
|
|
|
|
"selected text with Ctrl-^, you will be prompted to "
|
|
|
|
"save only the selected portion to a separate file. To "
|
|
|
|
"reduce the chance of overwriting the current file with "
|
|
|
|
"just a portion of it, the current filename is not the "
|
|
|
|
"default in this mode.\n\n The following function keys "
|
|
|
|
"are available in Write File mode:\n\n");
|
|
|
|
#ifndef DISABLE_BROWSER
|
|
|
|
else if (currshortcut == browser_list)
|
|
|
|
ptr = _("File Browser Help Text\n\n "
|
|
|
|
"The file browser is used to visually browse the "
|
|
|
|
"directory structure to select a file for reading "
|
|
|
|
"or writing. You may use the arrow keys or Page Up/"
|
|
|
|
"Down to browse through the files, and S or Enter to "
|
|
|
|
"choose the selected file or enter the selected "
|
|
|
|
"directory. To move up one level, select the directory "
|
|
|
|
"called \"..\" at the top of the file list.\n\n The "
|
|
|
|
"following function keys are available in the file "
|
|
|
|
"browser:\n\n");
|
|
|
|
else if (currshortcut == gotodir_list)
|
|
|
|
ptr = _("Browser Go To Directory Help Text\n\n "
|
|
|
|
"Enter the name of the directory you would like to "
|
|
|
|
"browse to.\n\n If tab completion has not been disabled, "
|
|
|
|
"you can use the TAB key to (attempt to) automatically "
|
|
|
|
"complete the directory name.\n\n The following function "
|
|
|
|
"keys are available in Browser Go To Directory mode:\n\n");
|
|
|
|
#endif
|
2003-02-05 05:51:19 +03:00
|
|
|
#ifndef DISABLE_SPELLER
|
2002-09-07 00:35:28 +04:00
|
|
|
else if (currshortcut == spell_list)
|
|
|
|
ptr = _("Spell Check Help Text\n\n "
|
|
|
|
"The spell checker checks the spelling of all text "
|
|
|
|
"in the current file. When an unknown word is "
|
|
|
|
"encountered, it is highlighted and a replacement can "
|
|
|
|
"be edited. It will then prompt to replace every "
|
|
|
|
"instance of the given misspelled word in the "
|
|
|
|
"current file.\n\n The following other functions are "
|
|
|
|
"available in Spell Check mode:\n\n");
|
2003-02-05 05:51:19 +03:00
|
|
|
#endif
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
else if (currshortcut == extcmd_list)
|
|
|
|
ptr = _("External Command Help Text\n\n "
|
|
|
|
"This menu allows you to insert the output of a command "
|
|
|
|
"run by the shell into the current buffer (or a new "
|
|
|
|
"buffer in multibuffer mode).\n\n The following keys are "
|
|
|
|
"available in this mode:\n\n");
|
|
|
|
#endif
|
|
|
|
else /* Default to the main help list */
|
|
|
|
ptr = _(" nano help text\n\n "
|
|
|
|
"The nano editor is designed to emulate the functionality and "
|
|
|
|
"ease-of-use of the UW Pico text editor. There are four main "
|
|
|
|
"sections of the editor: The top line shows the program "
|
|
|
|
"version, the current filename being edited, and whether "
|
|
|
|
"or not the file has been modified. Next is the main editor "
|
|
|
|
"window showing the file being edited. The status line is "
|
|
|
|
"the third line from the bottom and shows important messages. "
|
|
|
|
"The bottom two lines show the most commonly used shortcuts "
|
|
|
|
"in the editor.\n\n "
|
|
|
|
"The notation for shortcuts is as follows: Control-key "
|
2003-08-31 20:44:10 +04:00
|
|
|
"sequences are notated with a caret (^) symbol and can be "
|
|
|
|
"entered either by using the Control (Ctrl) key or pressing the "
|
|
|
|
"Esc key twice. Escape-key sequences are notated with the Meta "
|
|
|
|
"(M) symbol and can be entered using either the Esc, Alt or "
|
|
|
|
"Meta key depending on your keyboard setup. Also, pressing Esc "
|
|
|
|
"twice and then typing a three-digit number from 000 to 255 "
|
|
|
|
"will enter the character with the corresponding ASCII code. "
|
|
|
|
"The following keystrokes are available in the main editor "
|
|
|
|
"window. Alternative keys are shown in parentheses:\n\n");
|
2002-09-07 00:35:28 +04:00
|
|
|
|
2003-01-15 14:18:58 +03:00
|
|
|
allocsize += strlen(ptr);
|
2002-09-07 00:35:28 +04:00
|
|
|
|
|
|
|
/* The space needed for the shortcut lists, at most COLS characters,
|
|
|
|
* plus '\n'. */
|
2003-01-15 14:18:58 +03:00
|
|
|
allocsize += (COLS + 1) * length_of_list(currshortcut);
|
2002-09-07 00:35:28 +04:00
|
|
|
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
/* If we're on the main list, we also count the toggle help text.
|
|
|
|
* Each line has "M-%c\t\t\t", which fills 24 columns, plus at most
|
|
|
|
* COLS - 24 characters, plus '\n'.*/
|
2003-02-10 05:32:58 +03:00
|
|
|
if (currshortcut == main_list) {
|
|
|
|
size_t endislen = strlen(_("enable/disable"));
|
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
for (t = toggles; t != NULL; t = t->next)
|
2003-02-10 05:32:58 +03:00
|
|
|
allocsize += 8 + strlen(t->desc) + endislen;
|
|
|
|
}
|
2002-09-07 00:35:28 +04:00
|
|
|
#endif /* !NANO_SMALL */
|
|
|
|
|
|
|
|
/* help_text has been freed and set to NULL unless the user resized
|
|
|
|
* while in the help screen. */
|
|
|
|
free(help_text);
|
|
|
|
|
|
|
|
/* Allocate space for the help text */
|
2003-01-15 14:18:58 +03:00
|
|
|
help_text = charalloc(allocsize);
|
2002-09-07 00:35:28 +04:00
|
|
|
|
|
|
|
/* Now add the text we want */
|
|
|
|
strcpy(help_text, ptr);
|
|
|
|
ptr = help_text + strlen(help_text);
|
|
|
|
|
|
|
|
/* Now add our shortcut info */
|
|
|
|
for (s = currshortcut; s != NULL; s = s->next) {
|
2003-12-24 11:03:54 +03:00
|
|
|
/* true if the character in s->metaval is shown in first column */
|
2004-07-01 22:59:52 +04:00
|
|
|
int meta_shortcut = FALSE;
|
2002-09-07 00:35:28 +04:00
|
|
|
|
2004-03-20 00:46:34 +03:00
|
|
|
if (s->ctrlval != NANO_NO_KEY) {
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifndef NANO_SMALL
|
2004-03-20 00:46:34 +03:00
|
|
|
if (s->ctrlval == NANO_HISTORY_KEY)
|
2003-12-24 06:33:09 +03:00
|
|
|
ptr += sprintf(ptr, "%.2s", _("Up"));
|
|
|
|
else
|
2003-11-28 22:47:42 +03:00
|
|
|
#endif
|
2004-03-20 00:46:34 +03:00
|
|
|
if (s->ctrlval == NANO_CONTROL_SPACE)
|
2003-12-24 06:33:09 +03:00
|
|
|
ptr += sprintf(ptr, "^%.5s", _("Space"));
|
2004-03-20 00:46:34 +03:00
|
|
|
else if (s->ctrlval == NANO_CONTROL_8)
|
2003-11-28 22:47:42 +03:00
|
|
|
ptr += sprintf(ptr, "^?");
|
|
|
|
else
|
2004-03-20 00:46:34 +03:00
|
|
|
ptr += sprintf(ptr, "^%c", s->ctrlval + 64);
|
2003-11-28 22:47:42 +03:00
|
|
|
}
|
|
|
|
#ifndef NANO_SMALL
|
2003-12-24 11:03:54 +03:00
|
|
|
else if (s->metaval != NANO_NO_KEY) {
|
2004-07-01 22:59:52 +04:00
|
|
|
meta_shortcut = TRUE;
|
2003-12-24 11:03:54 +03:00
|
|
|
if (s->metaval == NANO_ALT_SPACE)
|
2003-12-24 06:33:09 +03:00
|
|
|
ptr += snprintf(ptr, 8, "M-%.5s", _("Space"));
|
|
|
|
else
|
2003-12-24 11:03:54 +03:00
|
|
|
ptr += sprintf(ptr, "M-%c", toupper(s->metaval));
|
2003-11-28 22:47:42 +03:00
|
|
|
}
|
2002-09-07 00:35:28 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
*(ptr++) = '\t';
|
|
|
|
|
2004-03-20 00:46:34 +03:00
|
|
|
if (s->funcval != NANO_NO_KEY)
|
|
|
|
ptr += sprintf(ptr, "(F%d)", s->funcval - KEY_F0);
|
2002-09-07 00:35:28 +04:00
|
|
|
|
|
|
|
*(ptr++) = '\t';
|
|
|
|
|
2003-12-24 11:03:54 +03:00
|
|
|
if (!meta_shortcut && s->metaval != NANO_NO_KEY)
|
|
|
|
ptr += sprintf(ptr, "(M-%c)", toupper(s->metaval));
|
2004-03-20 00:46:34 +03:00
|
|
|
else if (meta_shortcut && s->miscval != NANO_NO_KEY)
|
|
|
|
ptr += sprintf(ptr, "(M-%c)", toupper(s->miscval));
|
2002-09-07 00:35:28 +04:00
|
|
|
|
|
|
|
*(ptr++) = '\t';
|
|
|
|
|
|
|
|
assert(s->help != NULL);
|
2003-02-10 05:32:58 +03:00
|
|
|
ptr += sprintf(ptr, "%.*s\n", COLS > 24 ? COLS - 24 : 0, s->help);
|
2002-09-07 00:35:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
/* And the toggles... */
|
2004-03-20 00:46:34 +03:00
|
|
|
if (currshortcut == main_list) {
|
2002-09-07 00:35:28 +04:00
|
|
|
for (t = toggles; t != NULL; t = t->next) {
|
|
|
|
assert(t->desc != NULL);
|
2003-11-28 22:47:42 +03:00
|
|
|
ptr += sprintf(ptr, "M-%c\t\t\t%s %s\n", toupper(t->val), t->desc,
|
2003-02-10 05:32:58 +03:00
|
|
|
_("enable/disable"));
|
2002-09-07 00:35:28 +04:00
|
|
|
}
|
2004-03-20 00:46:34 +03:00
|
|
|
}
|
2002-09-07 00:35:28 +04:00
|
|
|
#endif /* !NANO_SMALL */
|
|
|
|
|
|
|
|
/* If all went well, we didn't overwrite the allocated space for
|
|
|
|
help_text. */
|
2003-01-15 14:18:58 +03:00
|
|
|
assert(strlen(help_text) < allocsize);
|
2002-09-07 00:35:28 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Create a new filestruct node. Note that we specifically do not set
|
|
|
|
* prevnode->next equal to the new line. */
|
|
|
|
filestruct *make_new_node(filestruct *prevnode)
|
|
|
|
{
|
|
|
|
filestruct *newnode = (filestruct *)nmalloc(sizeof(filestruct));
|
|
|
|
|
|
|
|
newnode->data = NULL;
|
|
|
|
newnode->prev = prevnode;
|
|
|
|
newnode->next = NULL;
|
|
|
|
newnode->lineno = prevnode != NULL ? prevnode->lineno + 1 : 1;
|
|
|
|
|
|
|
|
return newnode;
|
|
|
|
}
|
|
|
|
|
2002-06-21 07:20:06 +04:00
|
|
|
/* Make a copy of a node to a pointer (space will be malloc()ed). */
|
2002-07-19 05:08:59 +04:00
|
|
|
filestruct *copy_node(const filestruct *src)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
filestruct *dst = (filestruct *)nmalloc(sizeof(filestruct));
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
assert(src != NULL);
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
dst->data = charalloc(strlen(src->data) + 1);
|
2000-06-06 09:53:49 +04:00
|
|
|
dst->next = src->next;
|
|
|
|
dst->prev = src->prev;
|
|
|
|
strcpy(dst->data, src->data);
|
|
|
|
dst->lineno = src->lineno;
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
/* Splice a node into an existing filestruct. */
|
2004-07-08 21:15:10 +04:00
|
|
|
void splice_node(filestruct *begin, filestruct *newnode, filestruct
|
|
|
|
*end)
|
2002-09-07 00:35:28 +04:00
|
|
|
{
|
|
|
|
if (newnode != NULL) {
|
|
|
|
newnode->next = end;
|
|
|
|
newnode->prev = begin;
|
|
|
|
}
|
|
|
|
if (begin != NULL)
|
|
|
|
begin->next = newnode;
|
|
|
|
if (end != NULL)
|
|
|
|
end->prev = newnode;
|
|
|
|
}
|
|
|
|
|
2002-04-10 06:31:20 +04:00
|
|
|
/* Unlink a node from the rest of the filestruct. */
|
2002-07-19 05:08:59 +04:00
|
|
|
void unlink_node(const filestruct *fileptr)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
assert(fileptr != NULL);
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-04-10 06:31:20 +04:00
|
|
|
if (fileptr->prev != NULL)
|
|
|
|
fileptr->prev->next = fileptr->next;
|
|
|
|
|
|
|
|
if (fileptr->next != NULL)
|
|
|
|
fileptr->next->prev = fileptr->prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete a node from the filestruct. */
|
2002-07-19 05:08:59 +04:00
|
|
|
void delete_node(filestruct *fileptr)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
if (fileptr != NULL) {
|
|
|
|
if (fileptr->data != NULL)
|
|
|
|
free(fileptr->data);
|
|
|
|
free(fileptr);
|
|
|
|
}
|
2002-04-10 06:31:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Okay, now let's duplicate a whole struct! */
|
2002-07-19 05:08:59 +04:00
|
|
|
filestruct *copy_filestruct(const filestruct *src)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
filestruct *head; /* copy of src, top of the copied list */
|
|
|
|
filestruct *prev; /* temp that traverses the list */
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
assert(src != NULL);
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
prev = copy_node(src);
|
|
|
|
prev->prev = NULL;
|
|
|
|
head = prev;
|
|
|
|
src = src->next;
|
|
|
|
while (src != NULL) {
|
|
|
|
prev->next = copy_node(src);
|
|
|
|
prev->next->prev = prev;
|
|
|
|
prev = prev->next;
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
src = src->next;
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
prev->next = NULL;
|
2000-06-06 09:53:49 +04:00
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
2002-04-10 06:31:20 +04:00
|
|
|
/* Frees a filestruct. */
|
2002-07-19 05:08:59 +04:00
|
|
|
void free_filestruct(filestruct *src)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
if (src != NULL) {
|
|
|
|
while (src->next != NULL) {
|
|
|
|
src = src->next;
|
|
|
|
delete_node(src->prev);
|
2000-06-06 09:53:49 +04:00
|
|
|
#ifdef DEBUG
|
2003-08-05 23:31:12 +04:00
|
|
|
fprintf(stderr, "%s: free'd a node, YAY!\n", "delete_node()");
|
2000-06-06 09:53:49 +04:00
|
|
|
#endif
|
2002-07-19 05:08:59 +04:00
|
|
|
}
|
|
|
|
delete_node(src);
|
2002-04-10 06:31:20 +04:00
|
|
|
#ifdef DEBUG
|
2003-08-05 23:31:12 +04:00
|
|
|
fprintf(stderr, "%s: free'd last node.\n", "delete_node()");
|
2002-04-10 06:31:20 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
void renumber_all(void)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
|
|
|
filestruct *temp;
|
2002-03-06 06:30:40 +03:00
|
|
|
int i = 1;
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
assert(fileage == NULL || fileage != fileage->next);
|
|
|
|
for (temp = fileage; temp != NULL; temp = temp->next)
|
2000-06-06 09:53:49 +04:00
|
|
|
temp->lineno = i++;
|
|
|
|
}
|
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
void renumber(filestruct *fileptr)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
if (fileptr == NULL || fileptr->prev == NULL || fileptr == fileage)
|
2000-06-06 09:53:49 +04:00
|
|
|
renumber_all();
|
2002-07-19 05:08:59 +04:00
|
|
|
else {
|
|
|
|
int lineno = fileptr->prev->lineno;
|
2001-10-23 03:22:19 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
assert(fileptr != fileptr->next);
|
|
|
|
for (; fileptr != NULL; fileptr = fileptr->next)
|
|
|
|
fileptr->lineno = ++lineno;
|
|
|
|
}
|
2000-07-28 05:41:29 +04:00
|
|
|
}
|
|
|
|
|
2002-03-09 21:51:58 +03:00
|
|
|
/* Print one usage string to the screen, removes lots of duplicate
|
2002-07-19 05:08:59 +04:00
|
|
|
* strings to translate and takes out the parts that shouldn't be
|
|
|
|
* translatable (the flag names). */
|
2004-07-08 21:15:10 +04:00
|
|
|
void print1opt(const char *shortflag, const char *longflag, const char
|
|
|
|
*desc)
|
2002-03-09 21:51:58 +03:00
|
|
|
{
|
|
|
|
printf(" %s\t", shortflag);
|
|
|
|
if (strlen(shortflag) < 8)
|
|
|
|
printf("\t");
|
|
|
|
|
|
|
|
#ifdef HAVE_GETOPT_LONG
|
|
|
|
printf("%s\t", longflag);
|
|
|
|
if (strlen(longflag) < 8)
|
|
|
|
printf("\t\t");
|
|
|
|
else if (strlen(longflag) < 16)
|
|
|
|
printf("\t");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
printf("%s\n", desc);
|
|
|
|
}
|
|
|
|
|
2002-08-21 20:10:37 +04:00
|
|
|
void usage(void)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
|
|
|
#ifdef HAVE_GETOPT_LONG
|
2002-07-19 05:08:59 +04:00
|
|
|
printf(_("Usage: nano [+LINE] [GNU long option] [option] [file]\n\n"));
|
|
|
|
printf(_("Option\t\tLong option\t\tMeaning\n"));
|
2000-06-06 09:53:49 +04:00
|
|
|
#else
|
2002-07-19 05:08:59 +04:00
|
|
|
printf(_("Usage: nano [+LINE] [option] [file]\n\n"));
|
|
|
|
printf(_("Option\t\tMeaning\n"));
|
2002-03-09 21:51:58 +03:00
|
|
|
#endif /* HAVE_GETOPT_LONG */
|
|
|
|
|
2002-06-29 02:45:14 +04:00
|
|
|
print1opt("-h, -?", "--help", _("Show this message"));
|
2002-07-19 05:08:59 +04:00
|
|
|
print1opt(_("+LINE"), "", _("Start at line number LINE"));
|
2001-09-22 04:42:10 +04:00
|
|
|
#ifndef NANO_SMALL
|
2004-05-23 00:15:20 +04:00
|
|
|
print1opt("-A", "--smarthome", _("Enable smart home key"));
|
2002-06-29 02:45:14 +04:00
|
|
|
print1opt("-B", "--backup", _("Backup existing files on save"));
|
2002-03-09 21:51:58 +03:00
|
|
|
print1opt("-D", "--dos", _("Write file in DOS format"));
|
2004-06-09 12:36:46 +04:00
|
|
|
print1opt(_("-E [dir]"), _("--backupdir=[dir]"), _("Directory for writing backup files"));
|
2001-09-22 04:42:10 +04:00
|
|
|
#endif
|
2001-07-14 23:32:47 +04:00
|
|
|
#ifdef ENABLE_MULTIBUFFER
|
2002-03-09 21:51:58 +03:00
|
|
|
print1opt("-F", "--multibuffer", _("Enable multiple file buffers"));
|
2002-07-19 05:08:59 +04:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_NANORC
|
2003-09-07 01:44:37 +04:00
|
|
|
#ifndef NANO_SMALL
|
2003-01-22 04:13:25 +03:00
|
|
|
print1opt("-H", "--historylog", _("Log & read search/replace string history"));
|
2003-09-07 01:44:37 +04:00
|
|
|
#endif
|
2002-07-19 05:08:59 +04:00
|
|
|
print1opt("-I", "--ignorercfiles", _("Don't look at nanorc files"));
|
2001-09-22 08:20:25 +04:00
|
|
|
#endif
|
|
|
|
#ifndef NANO_SMALL
|
2002-03-09 21:51:58 +03:00
|
|
|
print1opt("-M", "--mac", _("Write file in Mac format"));
|
|
|
|
print1opt("-N", "--noconvert", _("Don't convert files from DOS/Mac format"));
|
2002-03-04 01:36:36 +03:00
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_JUSTIFY
|
2002-07-19 05:08:59 +04:00
|
|
|
print1opt(_("-Q [str]"), _("--quotestr=[str]"), _("Quoting string, default \"> \""));
|
2001-07-14 23:32:47 +04:00
|
|
|
#endif
|
2002-06-29 02:45:14 +04:00
|
|
|
#ifdef HAVE_REGEX_H
|
|
|
|
print1opt("-R", "--regexp", _("Do regular expression searches"));
|
|
|
|
#endif
|
2001-09-22 23:02:04 +04:00
|
|
|
#ifndef NANO_SMALL
|
2002-03-09 21:51:58 +03:00
|
|
|
print1opt("-S", "--smooth", _("Smooth scrolling"));
|
2001-09-22 23:02:04 +04:00
|
|
|
#endif
|
2004-02-25 06:19:29 +03:00
|
|
|
print1opt(_("-T [#cols]"), _("--tabsize=[#cols]"), _("Set width of a tab in cols to #cols"));
|
2002-03-09 21:51:58 +03:00
|
|
|
print1opt("-V", "--version", _("Print version information and exit"));
|
2002-05-04 08:23:30 +04:00
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
print1opt(_("-Y [str]"), _("--syntax [str]"), _("Syntax definition to use"));
|
|
|
|
#endif
|
2004-04-30 08:49:02 +04:00
|
|
|
print1opt(_("-Z"), _("--restricted"), _("Restricted mode"));
|
2002-03-09 21:51:58 +03:00
|
|
|
print1opt("-c", "--const", _("Constantly show cursor position"));
|
2000-07-12 22:14:51 +04:00
|
|
|
#ifndef NANO_SMALL
|
2003-12-24 06:33:09 +03:00
|
|
|
print1opt("-d", "--rebinddelete", _("Fix Backspace/Delete confusion problem"));
|
2002-03-09 21:51:58 +03:00
|
|
|
print1opt("-i", "--autoindent", _("Automatically indent new lines"));
|
|
|
|
print1opt("-k", "--cut", _("Let ^K cut from cursor to end of line"));
|
2000-07-12 22:14:51 +04:00
|
|
|
#endif
|
2002-03-09 21:51:58 +03:00
|
|
|
print1opt("-l", "--nofollow", _("Don't follow symbolic links, overwrite"));
|
2003-10-04 00:26:25 +04:00
|
|
|
#ifndef DISABLE_MOUSE
|
2002-03-09 21:51:58 +03:00
|
|
|
print1opt("-m", "--mouse", _("Enable mouse"));
|
2000-06-06 09:53:49 +04:00
|
|
|
#endif
|
2001-09-19 07:19:43 +04:00
|
|
|
#ifndef DISABLE_OPERATINGDIR
|
2002-03-09 23:05:26 +03:00
|
|
|
print1opt(_("-o [dir]"), _("--operatingdir=[dir]"), _("Set operating directory"));
|
2000-06-06 09:53:49 +04:00
|
|
|
#endif
|
2003-01-19 01:42:34 +03:00
|
|
|
print1opt("-p", "--preserve", _("Preserve XON (^Q) and XOFF (^S) keys"));
|
2001-05-21 16:56:25 +04:00
|
|
|
#ifndef DISABLE_WRAPJUSTIFY
|
2002-03-09 23:05:26 +03:00
|
|
|
print1opt(_("-r [#cols]"), _("--fill=[#cols]"), _("Set fill cols to (wrap lines at) #cols"));
|
2001-05-21 16:56:25 +04:00
|
|
|
#endif
|
2001-01-12 10:51:05 +03:00
|
|
|
#ifndef DISABLE_SPELLER
|
2002-03-09 23:05:26 +03:00
|
|
|
print1opt(_("-s [prog]"), _("--speller=[prog]"), _("Enable alternate speller"));
|
2001-01-12 10:51:05 +03:00
|
|
|
#endif
|
2002-03-09 21:51:58 +03:00
|
|
|
print1opt("-t", "--tempfile", _("Auto save on exit, don't prompt"));
|
|
|
|
print1opt("-v", "--view", _("View (read only) mode"));
|
2001-04-02 09:36:08 +04:00
|
|
|
#ifndef DISABLE_WRAPPING
|
2002-03-09 21:51:58 +03:00
|
|
|
print1opt("-w", "--nowrap", _("Don't wrap long lines"));
|
2000-06-06 09:53:49 +04:00
|
|
|
#endif
|
2002-03-09 21:51:58 +03:00
|
|
|
print1opt("-x", "--nohelp", _("Don't show help window"));
|
|
|
|
print1opt("-z", "--suspend", _("Enable suspend"));
|
2002-07-19 05:08:59 +04:00
|
|
|
|
|
|
|
/* this is a special case */
|
|
|
|
printf(" %s\t\t\t%s\n","-a, -b, -e, -f, -g, -j", _("(ignored, for Pico compatibility)"));
|
2002-03-09 21:51:58 +03:00
|
|
|
|
2000-06-06 09:53:49 +04:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2002-08-21 20:10:37 +04:00
|
|
|
void version(void)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
2001-02-14 17:28:27 +03:00
|
|
|
printf(_(" GNU nano version %s (compiled %s, %s)\n"),
|
2000-06-06 09:53:49 +04:00
|
|
|
VERSION, __TIME__, __DATE__);
|
2000-10-26 05:44:42 +04:00
|
|
|
printf(_
|
2002-11-04 19:05:42 +03:00
|
|
|
(" Email: nano@nano-editor.org Web: http://www.nano-editor.org/"));
|
2000-11-24 23:45:14 +03:00
|
|
|
printf(_("\n Compiled options:"));
|
2000-12-01 21:46:01 +03:00
|
|
|
|
2003-01-17 06:39:41 +03:00
|
|
|
#ifndef ENABLE_NLS
|
|
|
|
printf(" --disable-nls");
|
|
|
|
#endif
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf(" --enable-debug");
|
|
|
|
#endif
|
2000-11-24 23:45:14 +03:00
|
|
|
#ifdef NANO_EXTRA
|
|
|
|
printf(" --enable-extra");
|
2002-01-17 15:40:33 +03:00
|
|
|
#endif
|
2001-01-12 10:51:05 +03:00
|
|
|
#ifdef NANO_SMALL
|
|
|
|
printf(" --enable-tiny");
|
|
|
|
#else
|
2001-04-12 07:01:53 +04:00
|
|
|
#ifdef DISABLE_BROWSER
|
2001-01-05 08:41:07 +03:00
|
|
|
printf(" --disable-browser");
|
2001-04-12 07:01:53 +04:00
|
|
|
#endif
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifdef DISABLE_HELP
|
|
|
|
printf(" --disable-help");
|
2001-04-12 07:01:53 +04:00
|
|
|
#endif
|
|
|
|
#ifdef DISABLE_JUSTIFY
|
2000-12-01 21:46:01 +03:00
|
|
|
printf(" --disable-justify");
|
2001-04-12 07:01:53 +04:00
|
|
|
#endif
|
2003-10-04 00:26:25 +04:00
|
|
|
#ifdef DISABLE_MOUSE
|
2001-04-12 18:51:48 +04:00
|
|
|
printf(" --disable-mouse");
|
2000-12-18 08:36:51 +03:00
|
|
|
#endif
|
2001-09-19 07:19:43 +04:00
|
|
|
#ifdef DISABLE_OPERATINGDIR
|
|
|
|
printf(" --disable-operatingdir");
|
|
|
|
#endif
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifdef DISABLE_SPELLER
|
|
|
|
printf(" --disable-speller");
|
|
|
|
#endif
|
|
|
|
#ifdef DISABLE_TABCOMP
|
|
|
|
printf(" --disable-tabcomp");
|
|
|
|
#endif
|
|
|
|
#endif /* NANO_SMALL */
|
|
|
|
#ifdef DISABLE_WRAPPING
|
|
|
|
printf(" --disable-wrapping");
|
|
|
|
#endif
|
2002-10-25 20:08:53 +04:00
|
|
|
#ifdef DISABLE_ROOTWRAP
|
|
|
|
printf(" --disable-wrapping-as-root");
|
|
|
|
#endif
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
printf(" --enable-color");
|
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_MULTIBUFFER
|
|
|
|
printf(" --enable-multibuffer");
|
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_NANORC
|
|
|
|
printf(" --enable-nanorc");
|
|
|
|
#endif
|
2000-11-24 23:45:14 +03:00
|
|
|
#ifdef USE_SLANG
|
|
|
|
printf(" --with-slang");
|
|
|
|
#endif
|
|
|
|
printf("\n");
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int no_help(void)
|
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
return ISSET(NO_HELP) ? 2 : 0;
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
void nano_disabled_msg(void)
|
2000-12-01 21:46:01 +03:00
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
statusbar(_("Sorry, support for this function has been disabled"));
|
2000-12-01 21:46:01 +03:00
|
|
|
}
|
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
#ifndef NANO_SMALL
|
2003-11-28 22:47:42 +03:00
|
|
|
static int pid; /* This is the PID of the newly forked process
|
2002-09-07 00:35:28 +04:00
|
|
|
* below. It must be global since the signal
|
|
|
|
* handler needs it. */
|
|
|
|
RETSIGTYPE cancel_fork(int signal)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
2002-12-22 19:30:00 +03:00
|
|
|
if (kill(pid, SIGKILL) == -1)
|
|
|
|
nperror("kill");
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
int open_pipe(const char *command)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
2002-09-07 00:35:28 +04:00
|
|
|
int fd[2];
|
|
|
|
FILE *f;
|
|
|
|
struct sigaction oldaction, newaction;
|
|
|
|
/* original and temporary handlers for SIGINT */
|
|
|
|
int cancel_sigs = 0;
|
2002-11-04 19:05:42 +03:00
|
|
|
/* cancel_sigs == 1 means that sigaction() failed without changing
|
|
|
|
* the signal handlers. cancel_sigs == 2 means the signal handler
|
2004-05-18 05:20:36 +04:00
|
|
|
* was changed, but the tcsetattr() didn't succeed.
|
2002-11-04 19:05:42 +03:00
|
|
|
*
|
2002-09-07 00:35:28 +04:00
|
|
|
* I use this variable since it is important to put things back when
|
|
|
|
* we finish, even if we get errors. */
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
/* Make our pipes. */
|
2000-12-02 02:49:48 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
if (pipe(fd) == -1) {
|
|
|
|
statusbar(_("Could not pipe"));
|
|
|
|
return 1;
|
2000-12-02 02:49:48 +03:00
|
|
|
}
|
2001-10-14 23:05:10 +04:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
/* Fork a child. */
|
2001-10-14 23:05:10 +04:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
if ((pid = fork()) == 0) {
|
|
|
|
close(fd[0]);
|
|
|
|
dup2(fd[1], fileno(stdout));
|
|
|
|
dup2(fd[1], fileno(stderr));
|
|
|
|
/* If execl() returns at all, there was an error. */
|
|
|
|
|
2002-11-04 19:05:42 +03:00
|
|
|
execl("/bin/sh", "sh", "-c", command, 0);
|
2002-09-07 00:35:28 +04:00
|
|
|
exit(0);
|
|
|
|
}
|
2001-10-14 23:05:10 +04:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
/* Else continue as parent. */
|
|
|
|
|
|
|
|
close(fd[1]);
|
|
|
|
|
|
|
|
if (pid == -1) {
|
|
|
|
close(fd[0]);
|
|
|
|
statusbar(_("Could not fork"));
|
|
|
|
return 1;
|
2001-10-14 23:05:10 +04:00
|
|
|
}
|
2002-07-19 05:08:59 +04:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
/* Before we start reading the forked command's output, we set
|
|
|
|
* things up so that ^C will cancel the new process. */
|
2004-05-18 05:20:36 +04:00
|
|
|
|
2004-05-19 20:04:27 +04:00
|
|
|
/* Enable interpretation of the special control keys so that we get
|
|
|
|
* SIGINT when Ctrl-C is pressed. */
|
2004-05-18 05:20:36 +04:00
|
|
|
enable_signals();
|
|
|
|
|
2002-11-04 19:05:42 +03:00
|
|
|
if (sigaction(SIGINT, NULL, &newaction) == -1) {
|
2002-09-07 00:35:28 +04:00
|
|
|
cancel_sigs = 1;
|
|
|
|
nperror("sigaction");
|
2002-07-19 05:08:59 +04:00
|
|
|
} else {
|
2002-09-07 00:35:28 +04:00
|
|
|
newaction.sa_handler = cancel_fork;
|
2002-11-04 19:05:42 +03:00
|
|
|
if (sigaction(SIGINT, &newaction, &oldaction) == -1) {
|
2002-09-07 00:35:28 +04:00
|
|
|
cancel_sigs = 1;
|
|
|
|
nperror("sigaction");
|
|
|
|
}
|
2002-07-19 05:08:59 +04:00
|
|
|
}
|
2002-09-07 00:35:28 +04:00
|
|
|
/* Note that now oldaction is the previous SIGINT signal handler,
|
|
|
|
* to be restored later. */
|
2001-10-14 23:05:10 +04:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
f = fdopen(fd[0], "rb");
|
2002-12-22 19:30:00 +03:00
|
|
|
if (f == NULL)
|
2002-09-07 00:35:28 +04:00
|
|
|
nperror("fdopen");
|
|
|
|
|
|
|
|
read_file(f, "stdin", 0);
|
|
|
|
/* if multibuffer mode is on, we could be here in view mode; if so,
|
|
|
|
don't set the modification flag */
|
|
|
|
if (!ISSET(VIEW_MODE))
|
|
|
|
set_modified();
|
|
|
|
|
|
|
|
if (wait(NULL) == -1)
|
|
|
|
nperror("wait");
|
|
|
|
|
2002-11-04 19:05:42 +03:00
|
|
|
if (cancel_sigs != 1 && sigaction(SIGINT, &oldaction, NULL) == -1)
|
2002-09-07 00:35:28 +04:00
|
|
|
nperror("sigaction");
|
|
|
|
|
2004-05-19 20:04:27 +04:00
|
|
|
/* Disable interpretation of the special control keys so that we can
|
|
|
|
* use Ctrl-C for other things. */
|
2004-05-18 05:20:36 +04:00
|
|
|
disable_signals();
|
|
|
|
|
2002-05-12 23:52:15 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2004-03-05 22:54:58 +03:00
|
|
|
#endif /* !NANO_SMALL */
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2003-10-04 00:26:25 +04:00
|
|
|
#ifndef DISABLE_MOUSE
|
2002-09-07 00:35:28 +04:00
|
|
|
void do_mouse(void)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
2003-11-28 22:47:42 +03:00
|
|
|
int mouse_x, mouse_y;
|
2002-04-06 09:02:14 +04:00
|
|
|
|
2004-07-01 22:59:52 +04:00
|
|
|
if (get_mouseinput(&mouse_x, &mouse_y, TRUE) == FALSE) {
|
2003-11-28 22:47:42 +03:00
|
|
|
/* Click in the edit window to move the cursor, but only when
|
|
|
|
we're not in a subfunction. */
|
|
|
|
if (wenclose(edit, mouse_y, mouse_x) && currshortcut == main_list) {
|
|
|
|
int sameline;
|
|
|
|
/* Did they click on the line with the cursor? If they
|
|
|
|
clicked on the cursor, we set the mark. */
|
|
|
|
size_t xcur;
|
|
|
|
/* The character they clicked on. */
|
2000-06-07 07:56:54 +04:00
|
|
|
|
2003-11-28 22:47:42 +03:00
|
|
|
/* Subtract out size of topwin. Perhaps we need a constant
|
|
|
|
somewhere? */
|
|
|
|
mouse_y -= 2;
|
2000-06-07 07:56:54 +04:00
|
|
|
|
2003-11-28 22:47:42 +03:00
|
|
|
sameline = (mouse_y == current_y);
|
2003-01-28 04:36:38 +03:00
|
|
|
|
2003-11-28 22:47:42 +03:00
|
|
|
/* Move to where the click occurred. */
|
|
|
|
for (; current_y < mouse_y && current->next != NULL; current_y++)
|
|
|
|
current = current->next;
|
|
|
|
for (; current_y > mouse_y && current->prev != NULL; current_y--)
|
|
|
|
current = current->prev;
|
2003-01-28 04:36:38 +03:00
|
|
|
|
2003-11-28 22:47:42 +03:00
|
|
|
xcur = actual_x(current->data, get_page_start(xplustabs()) +
|
|
|
|
mouse_x);
|
2003-01-28 04:36:38 +03:00
|
|
|
|
2004-07-01 22:59:52 +04:00
|
|
|
/* Selecting where the cursor is toggles the mark, as does
|
2003-11-28 22:47:42 +03:00
|
|
|
selecting beyond the line length with the cursor at the
|
|
|
|
end of the line. */
|
|
|
|
if (sameline && xcur == current_x) {
|
|
|
|
if (ISSET(VIEW_MODE)) {
|
|
|
|
print_view_warning();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
do_mark();
|
2002-09-07 00:35:28 +04:00
|
|
|
}
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2003-11-28 22:47:42 +03:00
|
|
|
current_x = xcur;
|
|
|
|
placewewant = xplustabs();
|
|
|
|
edit_refresh();
|
|
|
|
}
|
2002-07-19 05:08:59 +04:00
|
|
|
}
|
2003-11-28 22:47:42 +03:00
|
|
|
/* FIXME: If we clicked on a location in the statusbar, the cursor
|
|
|
|
should move to the location we clicked on. */
|
2002-09-07 00:35:28 +04:00
|
|
|
}
|
2002-04-06 09:02:14 +04:00
|
|
|
#endif
|
2000-06-07 07:56:54 +04:00
|
|
|
|
2003-11-28 22:47:42 +03:00
|
|
|
/* The user typed a character; add it to the edit buffer. */
|
2002-09-07 00:35:28 +04:00
|
|
|
void do_char(char ch)
|
|
|
|
{
|
|
|
|
size_t current_len = strlen(current->data);
|
|
|
|
#if !defined(DISABLE_WRAPPING) || defined(ENABLE_COLOR)
|
2004-05-29 00:44:09 +04:00
|
|
|
int do_refresh = FALSE;
|
|
|
|
/* Do we have to call edit_refresh(), or can we get away with
|
2002-09-07 00:35:28 +04:00
|
|
|
* update_line()? */
|
|
|
|
#endif
|
2001-04-12 07:01:53 +04:00
|
|
|
|
2003-11-28 22:47:42 +03:00
|
|
|
if (ch == '\0') /* Null to newline, if needed. */
|
|
|
|
ch = '\n';
|
|
|
|
else if (ch == '\n') { /* Newline to Enter, if needed. */
|
|
|
|
do_enter();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(current != NULL && current->data != NULL);
|
|
|
|
|
|
|
|
/* When a character is inserted on the current magicline, it means
|
|
|
|
* we need a new one! */
|
2004-03-19 05:15:42 +03:00
|
|
|
if (filebot == current)
|
2002-09-07 00:35:28 +04:00
|
|
|
new_magicline();
|
2002-04-06 09:02:14 +04:00
|
|
|
|
2003-11-28 22:47:42 +03:00
|
|
|
/* More dangerousness fun =) */
|
2003-06-15 00:41:34 +04:00
|
|
|
current->data = charealloc(current->data, current_len + 2);
|
2002-09-07 00:35:28 +04:00
|
|
|
assert(current_x <= current_len);
|
2003-11-28 22:47:42 +03:00
|
|
|
charmove(¤t->data[current_x + 1], ¤t->data[current_x],
|
|
|
|
current_len - current_x + 1);
|
2002-09-07 00:35:28 +04:00
|
|
|
current->data[current_x] = ch;
|
|
|
|
totsize++;
|
|
|
|
set_modified();
|
2000-06-18 00:36:35 +04:00
|
|
|
|
2002-04-06 09:02:14 +04:00
|
|
|
#ifndef NANO_SMALL
|
2003-11-28 22:47:42 +03:00
|
|
|
/* Note that current_x has not yet been incremented. */
|
2002-09-07 00:35:28 +04:00
|
|
|
if (current == mark_beginbuf && current_x < mark_beginx)
|
|
|
|
mark_beginx++;
|
2002-04-06 09:02:14 +04:00
|
|
|
#endif
|
2000-06-07 07:56:54 +04:00
|
|
|
|
2004-05-29 00:44:09 +04:00
|
|
|
do_right(FALSE);
|
2000-06-07 07:56:54 +04:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifndef DISABLE_WRAPPING
|
2004-05-29 00:44:09 +04:00
|
|
|
/* If we're wrapping text, we need to call edit_refresh(). */
|
2002-09-07 00:35:28 +04:00
|
|
|
if (!ISSET(NO_WRAP) && ch != '\t')
|
2004-05-29 00:44:09 +04:00
|
|
|
do_refresh = do_wrap(current);
|
2002-09-07 00:35:28 +04:00
|
|
|
#endif
|
2000-06-21 07:00:43 +04:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifdef ENABLE_COLOR
|
2004-05-29 00:44:09 +04:00
|
|
|
/* If color syntaxes are turned on, we need to call
|
|
|
|
* edit_refresh(). */
|
2004-01-14 09:38:00 +03:00
|
|
|
if (ISSET(COLOR_SYNTAX))
|
2004-05-29 00:44:09 +04:00
|
|
|
do_refresh = TRUE;
|
2002-09-07 00:35:28 +04:00
|
|
|
#endif
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
#if !defined(DISABLE_WRAPPING) || defined(ENABLE_COLOR)
|
2004-05-29 00:44:09 +04:00
|
|
|
if (do_refresh)
|
2002-09-07 00:35:28 +04:00
|
|
|
edit_refresh();
|
2004-05-29 00:44:09 +04:00
|
|
|
else
|
2002-09-07 00:35:28 +04:00
|
|
|
#endif
|
2004-05-29 00:44:09 +04:00
|
|
|
update_line(current, current_x);
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_verbatim_input(void)
|
2003-11-28 22:47:42 +03:00
|
|
|
{
|
2004-05-28 21:23:33 +04:00
|
|
|
int *v_kbinput = NULL; /* Used to hold verbatim input. */
|
|
|
|
size_t v_len; /* Length of verbatim input. */
|
2004-04-22 07:41:04 +04:00
|
|
|
size_t i;
|
2003-11-28 22:47:42 +03:00
|
|
|
|
|
|
|
statusbar(_("Verbatim input"));
|
2004-05-28 21:23:33 +04:00
|
|
|
|
|
|
|
v_kbinput = get_verbatim_kbinput(edit, v_kbinput, &v_len, TRUE);
|
2003-11-28 22:47:42 +03:00
|
|
|
|
|
|
|
/* Turn on DISABLE_CURPOS while inserting character(s) and turn it
|
|
|
|
* off afterwards, so that if constant cursor position display is
|
|
|
|
* on, it will be updated properly. */
|
|
|
|
SET(DISABLE_CURPOS);
|
2004-05-28 21:23:33 +04:00
|
|
|
for (i = 0; i < v_len; i++)
|
|
|
|
do_char((char)v_kbinput[i]);
|
2003-11-28 22:47:42 +03:00
|
|
|
UNSET(DISABLE_CURPOS);
|
|
|
|
|
2004-05-28 21:23:33 +04:00
|
|
|
free(v_kbinput);
|
2003-11-28 22:47:42 +03:00
|
|
|
}
|
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_backspace(void)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
2003-09-08 03:57:24 +04:00
|
|
|
if (current != fileage || current_x > 0) {
|
2004-05-29 00:44:09 +04:00
|
|
|
do_left(FALSE);
|
2003-09-08 03:57:24 +04:00
|
|
|
do_delete();
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_delete(void)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
2004-05-29 00:44:09 +04:00
|
|
|
int do_refresh = FALSE;
|
|
|
|
/* Do we have to call edit_refresh(), or can we get away with
|
|
|
|
* update_line()? */
|
|
|
|
|
2004-04-19 06:44:13 +04:00
|
|
|
assert(current != NULL && current->data != NULL && current_x <=
|
|
|
|
strlen(current->data));
|
2002-07-30 03:46:38 +04:00
|
|
|
|
2004-04-19 06:44:13 +04:00
|
|
|
placewewant = xplustabs();
|
2001-11-29 06:43:08 +03:00
|
|
|
|
2004-04-19 06:44:13 +04:00
|
|
|
if (current->data[current_x] != '\0') {
|
|
|
|
size_t linelen = strlen(current->data + current_x);
|
2001-11-29 06:43:08 +03:00
|
|
|
|
2004-04-19 06:44:13 +04:00
|
|
|
assert(current_x < strlen(current->data));
|
2002-07-20 17:57:41 +04:00
|
|
|
|
2004-04-19 06:44:13 +04:00
|
|
|
/* Let's get dangerous. */
|
2003-09-16 06:04:00 +04:00
|
|
|
charmove(¤t->data[current_x], ¤t->data[current_x + 1],
|
2004-04-19 06:44:13 +04:00
|
|
|
linelen);
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2004-04-19 06:44:13 +04:00
|
|
|
null_at(¤t->data, linelen + current_x - 1);
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
if (current_x < mark_beginx && mark_beginbuf == current)
|
|
|
|
mark_beginx--;
|
2002-07-30 03:46:38 +04:00
|
|
|
#endif
|
2004-04-19 06:44:13 +04:00
|
|
|
} else if (current != filebot && (current->next != filebot ||
|
|
|
|
current->data[0] == '\0')) {
|
2002-05-12 23:52:15 +04:00
|
|
|
/* We can delete the line before filebot only if it is blank: it
|
2004-05-24 09:05:07 +04:00
|
|
|
* becomes the new magicline then. */
|
2004-04-19 06:44:13 +04:00
|
|
|
filestruct *foo = current->next;
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2004-04-19 06:44:13 +04:00
|
|
|
assert(current_x == strlen(current->data));
|
2004-05-29 00:44:09 +04:00
|
|
|
|
|
|
|
/* If we're deleting at the end of a line, we need to call
|
|
|
|
* edit_refresh(). */
|
|
|
|
if (current->data[current_x] == '\0')
|
|
|
|
do_refresh = TRUE;
|
|
|
|
|
2004-04-19 06:44:13 +04:00
|
|
|
current->data = charealloc(current->data, current_x +
|
|
|
|
strlen(foo->data) + 1);
|
|
|
|
strcpy(current->data + current_x, foo->data);
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
if (mark_beginbuf == current->next) {
|
|
|
|
mark_beginx += current_x;
|
|
|
|
mark_beginbuf = current;
|
|
|
|
}
|
|
|
|
#endif
|
2004-03-19 05:15:42 +03:00
|
|
|
if (filebot == foo)
|
2000-06-06 09:53:49 +04:00
|
|
|
filebot = current;
|
|
|
|
|
|
|
|
unlink_node(foo);
|
|
|
|
delete_node(foo);
|
|
|
|
renumber(current);
|
|
|
|
totlines--;
|
2004-04-19 06:44:13 +04:00
|
|
|
wrap_reset();
|
2000-06-06 09:53:49 +04:00
|
|
|
} else
|
2004-07-02 18:31:03 +04:00
|
|
|
return;
|
2000-06-06 09:53:49 +04:00
|
|
|
|
|
|
|
totsize--;
|
|
|
|
set_modified();
|
2004-05-29 00:44:09 +04:00
|
|
|
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
/* If color syntaxes are turned on, we need to call
|
|
|
|
* edit_refresh(). */
|
|
|
|
if (ISSET(COLOR_SYNTAX))
|
|
|
|
do_refresh = TRUE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (do_refresh)
|
|
|
|
edit_refresh();
|
|
|
|
else
|
|
|
|
update_line(current, current_x);
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_tab(void)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
2002-09-07 00:35:28 +04:00
|
|
|
do_char('\t');
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
/* Someone hits return *gasp!* */
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_enter(void)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
2004-05-28 00:09:52 +04:00
|
|
|
filestruct *newnode = make_new_node(current);
|
|
|
|
size_t extra = 0;
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
assert(current != NULL && current->data != NULL);
|
2002-01-21 23:32:22 +03:00
|
|
|
|
2002-06-13 04:40:19 +04:00
|
|
|
#ifndef NANO_SMALL
|
2002-09-07 00:35:28 +04:00
|
|
|
/* Do auto-indenting, like the neolithic Turbo Pascal editor. */
|
|
|
|
if (ISSET(AUTOINDENT)) {
|
2004-05-28 00:09:52 +04:00
|
|
|
/* If we are breaking the line in the indentation, the new
|
|
|
|
* indentation should have only current_x characters, and
|
|
|
|
* current_x should not change. */
|
|
|
|
extra = indent_length(current->data);
|
|
|
|
if (extra > current_x)
|
2002-09-07 00:35:28 +04:00
|
|
|
extra = current_x;
|
|
|
|
totsize += extra;
|
2004-05-28 00:09:52 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
newnode->data = charalloc(strlen(current->data + current_x) +
|
|
|
|
extra + 1);
|
|
|
|
strcpy(&newnode->data[extra], current->data + current_x);
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
if (ISSET(AUTOINDENT))
|
2002-09-07 00:35:28 +04:00
|
|
|
strncpy(newnode->data, current->data, extra);
|
|
|
|
#endif
|
2004-05-28 00:09:52 +04:00
|
|
|
null_at(¤t->data, current_x);
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
if (current == mark_beginbuf && current_x < mark_beginx) {
|
|
|
|
mark_beginbuf = newnode;
|
|
|
|
mark_beginx += extra - current_x;
|
2002-09-07 00:35:28 +04:00
|
|
|
}
|
2004-05-28 00:09:52 +04:00
|
|
|
#endif
|
|
|
|
current_x = extra;
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2004-05-28 00:09:52 +04:00
|
|
|
if (current == filebot)
|
2002-09-07 00:35:28 +04:00
|
|
|
filebot = newnode;
|
|
|
|
splice_node(current, newnode, current->next);
|
2002-01-21 23:32:22 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
totsize++;
|
|
|
|
renumber(current);
|
|
|
|
current = newnode;
|
2004-05-28 00:09:52 +04:00
|
|
|
|
2002-12-22 19:30:00 +03:00
|
|
|
#ifndef NANO_SMALL
|
2004-05-28 00:09:52 +04:00
|
|
|
/* If we're in smooth scrolling mode and we're on the last line of
|
|
|
|
* the edit window, move edittop down one line so that current is
|
|
|
|
* onscreen. This prevents edit_refresh() from centering the
|
|
|
|
* screen. */
|
|
|
|
if (ISSET(SMOOTHSCROLL) && current_y == editwinrows - 1)
|
|
|
|
edittop = edittop->next;
|
2002-12-22 19:30:00 +03:00
|
|
|
#endif
|
2004-05-28 00:09:52 +04:00
|
|
|
edit_refresh();
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
totlines++;
|
|
|
|
set_modified();
|
|
|
|
placewewant = xplustabs();
|
2000-11-05 19:52:21 +03:00
|
|
|
}
|
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifndef NANO_SMALL
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_next_word(void)
|
2000-11-05 19:52:21 +03:00
|
|
|
{
|
2004-05-30 07:19:52 +04:00
|
|
|
int old_pww = placewewant;
|
2004-05-29 00:44:09 +04:00
|
|
|
const filestruct *current_save = current;
|
2002-09-07 00:35:28 +04:00
|
|
|
assert(current != NULL && current->data != NULL);
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
/* Skip letters in this word first. */
|
|
|
|
while (current->data[current_x] != '\0' &&
|
|
|
|
isalnum((int)current->data[current_x]))
|
|
|
|
current_x++;
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
for (; current != NULL; current = current->next) {
|
|
|
|
while (current->data[current_x] != '\0' &&
|
|
|
|
!isalnum((int)current->data[current_x]))
|
|
|
|
current_x++;
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
if (current->data[current_x] != '\0')
|
|
|
|
break;
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
current_x = 0;
|
|
|
|
}
|
|
|
|
if (current == NULL)
|
|
|
|
current = filebot;
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
placewewant = xplustabs();
|
2000-11-10 21:15:43 +03:00
|
|
|
|
2004-03-13 22:42:58 +03:00
|
|
|
/* Refresh the screen. If current has run off the bottom, this
|
|
|
|
* call puts it at the center line. */
|
2004-05-30 07:19:52 +04:00
|
|
|
edit_redraw(current_save, old_pww);
|
2002-09-07 00:35:28 +04:00
|
|
|
}
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
/* The same thing for backwards. */
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_prev_word(void)
|
2002-09-07 00:35:28 +04:00
|
|
|
{
|
2004-05-30 07:19:52 +04:00
|
|
|
int old_pww = placewewant;
|
2004-05-29 00:44:09 +04:00
|
|
|
const filestruct *current_save = current;
|
2002-12-22 19:30:00 +03:00
|
|
|
assert(current != NULL && current->data != NULL);
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
/* Skip letters in this word first. */
|
|
|
|
while (current_x >= 0 && isalnum((int)current->data[current_x]))
|
|
|
|
current_x--;
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
for (; current != NULL; current = current->prev) {
|
|
|
|
while (current_x >= 0 && !isalnum((int)current->data[current_x]))
|
|
|
|
current_x--;
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
if (current_x >= 0)
|
|
|
|
break;
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
if (current->prev != NULL)
|
|
|
|
current_x = strlen(current->prev->data);
|
2000-11-05 19:52:21 +03:00
|
|
|
}
|
|
|
|
|
2004-05-24 06:35:02 +04:00
|
|
|
if (current == NULL) {
|
2002-09-07 00:35:28 +04:00
|
|
|
current = fileage;
|
|
|
|
current_x = 0;
|
2004-05-24 06:35:02 +04:00
|
|
|
} else {
|
|
|
|
while (current_x > 0 && isalnum((int)current->data[current_x - 1]))
|
|
|
|
current_x--;
|
2002-03-25 06:26:27 +03:00
|
|
|
}
|
2000-11-10 21:15:43 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
placewewant = xplustabs();
|
2000-11-10 21:15:43 +03:00
|
|
|
|
2004-03-14 04:42:17 +03:00
|
|
|
/* Refresh the screen. If current has run off the top, this call
|
|
|
|
* puts it at the center line. */
|
2004-05-30 07:19:52 +04:00
|
|
|
edit_redraw(current_save, old_pww);
|
2002-09-07 00:35:28 +04:00
|
|
|
}
|
2000-11-10 21:15:43 +03:00
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_mark(void)
|
2002-09-07 00:35:28 +04:00
|
|
|
{
|
2003-09-29 01:26:49 +04:00
|
|
|
TOGGLE(MARK_ISSET);
|
|
|
|
if (ISSET(MARK_ISSET)) {
|
2002-09-07 00:35:28 +04:00
|
|
|
statusbar(_("Mark Set"));
|
|
|
|
mark_beginbuf = current;
|
|
|
|
mark_beginx = current_x;
|
|
|
|
} else {
|
|
|
|
statusbar(_("Mark UNset"));
|
|
|
|
edit_refresh();
|
|
|
|
}
|
|
|
|
}
|
2004-04-30 08:49:02 +04:00
|
|
|
#endif /* !NANO_SMALL */
|
2000-11-10 21:15:43 +03:00
|
|
|
|
2003-09-11 00:08:00 +04:00
|
|
|
#ifndef DISABLE_WRAPPING
|
2002-09-07 00:35:28 +04:00
|
|
|
void wrap_reset(void)
|
|
|
|
{
|
2004-06-22 19:38:47 +04:00
|
|
|
same_line_wrap = FALSE;
|
2000-11-05 19:52:21 +03:00
|
|
|
}
|
2003-09-11 00:08:00 +04:00
|
|
|
#endif
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifndef DISABLE_WRAPPING
|
2004-05-31 18:58:59 +04:00
|
|
|
/* We wrap the given line. Precondition: we assume the cursor has been
|
|
|
|
* moved forward since the last typed character. Return value: whether
|
|
|
|
* we wrapped. */
|
2002-09-07 00:35:28 +04:00
|
|
|
int do_wrap(filestruct *inptr)
|
2000-11-05 19:52:21 +03:00
|
|
|
{
|
2004-05-31 18:58:59 +04:00
|
|
|
size_t len = strlen(inptr->data);
|
|
|
|
/* Length of the line we wrap. */
|
|
|
|
size_t i = 0;
|
|
|
|
/* Generic loop variable. */
|
|
|
|
int wrap_loc = -1;
|
|
|
|
/* Index of inptr->data where we wrap. */
|
2002-09-07 00:35:28 +04:00
|
|
|
int word_back = -1;
|
2002-06-13 04:40:19 +04:00
|
|
|
#ifndef NANO_SMALL
|
2002-09-07 00:35:28 +04:00
|
|
|
const char *indentation = NULL;
|
2004-05-31 18:58:59 +04:00
|
|
|
/* Indentation to prepend to the new line. */
|
2004-07-17 23:49:12 +04:00
|
|
|
size_t indent_len = 0; /* strlen(indentation) */
|
2002-06-13 04:40:19 +04:00
|
|
|
#endif
|
2004-05-31 18:58:59 +04:00
|
|
|
const char *after_break; /* Text after the wrap point. */
|
|
|
|
size_t after_break_len; /* strlen(after_break) */
|
|
|
|
int wrapping = FALSE; /* Do we prepend to the next line? */
|
2002-09-07 00:35:28 +04:00
|
|
|
const char *wrap_line = NULL;
|
2004-07-17 23:49:12 +04:00
|
|
|
/* The next line, minus indentation. */
|
2004-05-31 18:58:59 +04:00
|
|
|
size_t wrap_line_len = 0; /* strlen(wrap_line) */
|
|
|
|
char *newline = NULL; /* The line we create. */
|
|
|
|
size_t new_line_len = 0; /* Eventual length of newline. */
|
2002-06-13 04:40:19 +04:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
/* There are three steps. First, we decide where to wrap. Then, we
|
|
|
|
* create the new wrap line. Finally, we clean up. */
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2004-07-17 23:49:12 +04:00
|
|
|
/* Step 1, finding where to wrap. We are going to add a new line
|
2004-05-29 20:47:52 +04:00
|
|
|
* after a whitespace character. In this step, we set wrap_loc as the
|
2002-09-07 00:35:28 +04:00
|
|
|
* location of this replacement.
|
|
|
|
*
|
|
|
|
* Where should we break the line? We need the last "legal wrap point"
|
|
|
|
* such that the last word before it ended at or before fill. If there
|
|
|
|
* is no such point, we settle for the first legal wrap point.
|
|
|
|
*
|
2004-05-29 21:05:52 +04:00
|
|
|
* A "legal wrap point" is a whitespace character that is not followed
|
|
|
|
* by whitespace.
|
2002-09-07 00:35:28 +04:00
|
|
|
*
|
|
|
|
* If there is no legal wrap point or we found the last character of the
|
|
|
|
* line, we should return without wrapping.
|
|
|
|
*
|
|
|
|
* Note that the initial indentation does not count as a legal wrap
|
|
|
|
* point if we are going to auto-indent!
|
|
|
|
*
|
2004-05-29 21:05:52 +04:00
|
|
|
* Note that the code below could be optimized, by not calling
|
|
|
|
* strnlenpt() so often. */
|
2001-01-27 22:25:00 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
if (ISSET(AUTOINDENT))
|
|
|
|
i = indent_length(inptr->data);
|
|
|
|
#endif
|
|
|
|
wrap_line = inptr->data + i;
|
2003-11-06 01:04:08 +03:00
|
|
|
for (; i < len; i++, wrap_line++) {
|
2004-05-31 18:58:59 +04:00
|
|
|
/* Record where the last word ended. */
|
2004-05-13 21:19:54 +04:00
|
|
|
if (!isblank(*wrap_line))
|
2002-09-07 00:35:28 +04:00
|
|
|
word_back = i;
|
2004-05-31 18:58:59 +04:00
|
|
|
/* If we have found a "legal wrap point" and the current word
|
|
|
|
* extends too far, then we stop. */
|
2002-09-07 00:35:28 +04:00
|
|
|
if (wrap_loc != -1 && strnlenpt(inptr->data, word_back + 1) > fill)
|
|
|
|
break;
|
2004-05-31 18:58:59 +04:00
|
|
|
/* We record the latest "legal wrap point". */
|
2004-05-13 21:19:54 +04:00
|
|
|
if (word_back != i && !isblank(wrap_line[1]))
|
2002-09-07 00:35:28 +04:00
|
|
|
wrap_loc = i;
|
2001-01-27 22:25:00 +03:00
|
|
|
}
|
2004-05-31 18:58:59 +04:00
|
|
|
if (i == len)
|
|
|
|
return FALSE;
|
2000-11-10 21:15:43 +03:00
|
|
|
|
2004-05-31 18:58:59 +04:00
|
|
|
/* Step 2, making the new wrap line. It will consist of indentation
|
|
|
|
* + after_break + " " + wrap_line (although indentation and
|
|
|
|
* wrap_line are conditional on flags and #defines). */
|
2000-11-10 21:15:43 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
/* after_break is the text that will be moved to the next line. */
|
|
|
|
after_break = inptr->data + wrap_loc + 1;
|
|
|
|
after_break_len = len - wrap_loc - 1;
|
|
|
|
assert(after_break_len == strlen(after_break));
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
/* new_line_len will later be increased by the lengths of indentation
|
|
|
|
* and wrap_line. */
|
|
|
|
new_line_len = after_break_len;
|
2000-11-10 21:15:43 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
/* We prepend the wrapped text to the next line, if the flag is set,
|
|
|
|
* and there is a next line, and prepending would not make the line
|
|
|
|
* too long. */
|
2003-09-11 00:08:00 +04:00
|
|
|
if (same_line_wrap && inptr->next) {
|
2002-09-07 00:35:28 +04:00
|
|
|
wrap_line = inptr->next->data;
|
|
|
|
wrap_line_len = strlen(wrap_line);
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2004-05-31 18:58:59 +04:00
|
|
|
/* +1 for the space between after_break and wrap_line. */
|
2002-09-07 00:35:28 +04:00
|
|
|
if ((new_line_len + 1 + wrap_line_len) <= fill) {
|
2004-05-31 18:58:59 +04:00
|
|
|
wrapping = TRUE;
|
2002-09-07 00:35:28 +04:00
|
|
|
new_line_len += (1 + wrap_line_len);
|
|
|
|
}
|
|
|
|
}
|
2001-04-20 05:59:55 +04:00
|
|
|
|
2002-06-13 04:40:19 +04:00
|
|
|
#ifndef NANO_SMALL
|
2002-09-07 00:35:28 +04:00
|
|
|
if (ISSET(AUTOINDENT)) {
|
2002-09-21 06:19:45 +04:00
|
|
|
/* Indentation comes from the next line if wrapping, else from
|
|
|
|
* this line. */
|
2002-09-07 00:35:28 +04:00
|
|
|
indentation = (wrapping ? wrap_line : inptr->data);
|
|
|
|
indent_len = indent_length(indentation);
|
|
|
|
if (wrapping)
|
2002-09-21 06:19:45 +04:00
|
|
|
/* The wrap_line text should not duplicate indentation.
|
|
|
|
* Note in this case we need not increase new_line_len. */
|
2002-09-07 00:35:28 +04:00
|
|
|
wrap_line += indent_len;
|
|
|
|
else
|
|
|
|
new_line_len += indent_len;
|
2002-08-21 20:10:37 +04:00
|
|
|
}
|
2002-06-13 04:40:19 +04:00
|
|
|
#endif
|
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
/* Now we allocate the new line and copy into it. */
|
|
|
|
newline = charalloc(new_line_len + 1); /* +1 for \0 */
|
2004-06-22 19:38:47 +04:00
|
|
|
new_line_len = 0;
|
2002-09-07 00:35:28 +04:00
|
|
|
*newline = '\0';
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
if (ISSET(AUTOINDENT)) {
|
|
|
|
strncpy(newline, indentation, indent_len);
|
|
|
|
newline[indent_len] = '\0';
|
2004-05-31 18:58:59 +04:00
|
|
|
new_line_len = indent_len;
|
2000-12-02 07:36:50 +03:00
|
|
|
}
|
2001-09-19 07:19:43 +04:00
|
|
|
#endif
|
2002-09-07 00:35:28 +04:00
|
|
|
strcat(newline, after_break);
|
2004-05-31 18:58:59 +04:00
|
|
|
new_line_len += after_break_len;
|
|
|
|
/* We end the old line after wrap_loc. Note that this does not eat
|
|
|
|
* the space. */
|
2002-09-20 03:19:34 +04:00
|
|
|
null_at(&inptr->data, wrap_loc + 1);
|
|
|
|
totsize++;
|
2002-09-07 00:35:28 +04:00
|
|
|
if (wrapping) {
|
2002-09-20 03:19:34 +04:00
|
|
|
/* In this case, totsize increases by 1 since we add a space
|
2002-09-21 06:19:45 +04:00
|
|
|
* between after_break and wrap_line. If the line already ends
|
2002-09-21 19:41:33 +04:00
|
|
|
* in a tab or a space, we don't add a space and decrement
|
|
|
|
* totsize to account for that. */
|
2004-05-31 18:58:59 +04:00
|
|
|
if (!isblank(newline[new_line_len - 1]))
|
2002-09-21 06:19:45 +04:00
|
|
|
strcat(newline, " ");
|
|
|
|
else
|
|
|
|
totsize--;
|
2002-09-07 00:35:28 +04:00
|
|
|
strcat(newline, wrap_line);
|
|
|
|
free(inptr->next->data);
|
|
|
|
inptr->next->data = newline;
|
|
|
|
} else {
|
|
|
|
filestruct *temp = (filestruct *)nmalloc(sizeof(filestruct));
|
2001-09-19 07:19:43 +04:00
|
|
|
|
2004-05-31 18:58:59 +04:00
|
|
|
/* In this case, the file size changes by +1 for the new line,
|
|
|
|
* and +indent_len for the new indentation. */
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
totsize += indent_len;
|
|
|
|
#endif
|
|
|
|
totlines++;
|
|
|
|
temp->data = newline;
|
|
|
|
temp->prev = inptr;
|
|
|
|
temp->next = inptr->next;
|
|
|
|
temp->prev->next = temp;
|
2002-12-22 19:30:00 +03:00
|
|
|
/* If temp->next is NULL, then temp is the last line of the
|
|
|
|
* file, so we must set filebot. */
|
|
|
|
if (temp->next != NULL)
|
2002-09-07 00:35:28 +04:00
|
|
|
temp->next->prev = temp;
|
|
|
|
else
|
|
|
|
filebot = temp;
|
|
|
|
}
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2004-05-31 18:58:59 +04:00
|
|
|
/* Step 3, clean up. Here we reposition the cursor and mark, and do
|
|
|
|
* some other sundry things. */
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2004-07-17 23:49:12 +04:00
|
|
|
/* Later wraps of this line will be prepended to the next line. */
|
2004-06-22 19:38:47 +04:00
|
|
|
same_line_wrap = TRUE;
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
/* Each line knows its line number. We recalculate these if we
|
|
|
|
* inserted a new line. */
|
|
|
|
if (!wrapping)
|
|
|
|
renumber(inptr);
|
2000-11-05 19:52:21 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
/* If the cursor was after the break point, we must move it. */
|
|
|
|
if (current_x > wrap_loc) {
|
|
|
|
current = current->next;
|
|
|
|
current_x -=
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
-indent_len +
|
2000-07-03 07:10:14 +04:00
|
|
|
#endif
|
2002-09-07 00:35:28 +04:00
|
|
|
wrap_loc + 1;
|
|
|
|
wrap_reset();
|
|
|
|
placewewant = xplustabs();
|
|
|
|
}
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-03-29 19:31:29 +03:00
|
|
|
#ifndef NANO_SMALL
|
2004-07-17 23:49:12 +04:00
|
|
|
/* If the mark was on this line after the wrap point, we move it
|
|
|
|
* down. If it was on the next line and we wrapped, we move it
|
2002-09-07 00:35:28 +04:00
|
|
|
* right. */
|
|
|
|
if (mark_beginbuf == inptr && mark_beginx > wrap_loc) {
|
|
|
|
mark_beginbuf = inptr->next;
|
|
|
|
mark_beginx -= wrap_loc - indent_len + 1;
|
|
|
|
} else if (wrapping && mark_beginbuf == inptr->next)
|
|
|
|
mark_beginx += after_break_len;
|
|
|
|
#endif /* !NANO_SMALL */
|
2002-03-29 19:31:29 +03:00
|
|
|
|
2004-05-31 18:58:59 +04:00
|
|
|
return TRUE;
|
2002-03-29 19:31:29 +03:00
|
|
|
}
|
2002-09-07 00:35:28 +04:00
|
|
|
#endif /* !DISABLE_WRAPPING */
|
2002-03-29 19:31:29 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifndef DISABLE_SPELLER
|
2003-08-31 20:44:10 +04:00
|
|
|
/* A word is misspelled in the file. Let the user replace it. We
|
2004-02-24 23:41:39 +03:00
|
|
|
* return zero if the user cancels. */
|
2002-09-07 00:35:28 +04:00
|
|
|
int do_int_spell_fix(const char *word)
|
2002-03-29 19:31:29 +03:00
|
|
|
{
|
2002-09-07 00:35:28 +04:00
|
|
|
char *save_search;
|
|
|
|
char *save_replace;
|
2004-02-24 23:41:39 +03:00
|
|
|
size_t current_x_save = current_x;
|
2004-05-29 00:44:09 +04:00
|
|
|
filestruct *current_save = current;
|
2003-01-26 22:57:44 +03:00
|
|
|
filestruct *edittop_save = edittop;
|
|
|
|
/* Save where we are. */
|
|
|
|
int i = 0;
|
|
|
|
/* The return value. */
|
|
|
|
int reverse_search_set = ISSET(REVERSE_SEARCH);
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifndef NANO_SMALL
|
2003-01-26 22:57:44 +03:00
|
|
|
int case_sens_set = ISSET(CASE_SENSITIVE);
|
|
|
|
int mark_set = ISSET(MARK_ISSET);
|
2002-03-29 19:31:29 +03:00
|
|
|
|
2002-12-10 03:53:21 +03:00
|
|
|
SET(CASE_SENSITIVE);
|
2004-02-24 23:41:39 +03:00
|
|
|
/* Make sure the marking highlight is off during spell-check. */
|
2002-09-07 00:35:28 +04:00
|
|
|
UNSET(MARK_ISSET);
|
|
|
|
#endif
|
2004-02-24 23:41:39 +03:00
|
|
|
/* Make sure spell-check goes forward only. */
|
2003-01-26 22:57:44 +03:00
|
|
|
UNSET(REVERSE_SEARCH);
|
2002-03-29 19:31:29 +03:00
|
|
|
|
2004-02-24 23:41:39 +03:00
|
|
|
/* Save the current search/replace strings. */
|
2002-09-07 00:35:28 +04:00
|
|
|
search_init_globals();
|
|
|
|
save_search = last_search;
|
|
|
|
save_replace = last_replace;
|
2002-03-29 19:31:29 +03:00
|
|
|
|
2004-02-24 23:41:39 +03:00
|
|
|
/* Set search/replace strings to misspelled word. */
|
2002-09-07 00:35:28 +04:00
|
|
|
last_search = mallocstrcpy(NULL, word);
|
|
|
|
last_replace = mallocstrcpy(NULL, word);
|
2002-03-29 19:31:29 +03:00
|
|
|
|
2004-02-24 23:41:39 +03:00
|
|
|
/* Start from the top of the file. */
|
2002-09-07 00:35:28 +04:00
|
|
|
current = fileage;
|
2003-01-26 22:57:44 +03:00
|
|
|
current_x = -1;
|
2002-03-29 19:31:29 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
search_last_line = FALSE;
|
2002-03-29 19:31:29 +03:00
|
|
|
|
2004-02-24 23:41:39 +03:00
|
|
|
/* Find the first whole-word occurrence of word. */
|
|
|
|
while (findnextstr(TRUE, TRUE, fileage, 0, word, FALSE) != 0)
|
2003-01-26 22:57:44 +03:00
|
|
|
if (is_whole_word(current_x, current->data, word)) {
|
|
|
|
edit_refresh();
|
2002-03-29 19:31:29 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
do_replace_highlight(TRUE, word);
|
2002-03-29 19:31:29 +03:00
|
|
|
|
2004-02-24 23:41:39 +03:00
|
|
|
/* Allow the replace word to be corrected. */
|
2004-03-15 23:26:30 +03:00
|
|
|
i = statusq(FALSE, spell_list, word,
|
2003-01-13 04:35:15 +03:00
|
|
|
#ifndef NANO_SMALL
|
2003-01-26 22:57:44 +03:00
|
|
|
NULL,
|
2003-01-13 04:35:15 +03:00
|
|
|
#endif
|
2003-01-26 22:57:44 +03:00
|
|
|
_("Edit a replacement"));
|
2002-03-29 19:31:29 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
do_replace_highlight(FALSE, word);
|
2002-03-29 19:31:29 +03:00
|
|
|
|
2003-01-26 22:57:44 +03:00
|
|
|
if (i != -1 && strcmp(word, answer)) {
|
|
|
|
search_last_line = FALSE;
|
|
|
|
current_x--;
|
2004-02-24 23:41:39 +03:00
|
|
|
do_replace_loop(word, current_save, ¤t_x_save, TRUE);
|
2002-09-07 00:35:28 +04:00
|
|
|
}
|
2003-01-26 22:57:44 +03:00
|
|
|
|
|
|
|
break;
|
2001-07-11 06:08:33 +04:00
|
|
|
}
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2004-02-24 23:41:39 +03:00
|
|
|
/* Restore the search/replace strings. */
|
|
|
|
free(last_search);
|
|
|
|
last_search = save_search;
|
|
|
|
free(last_replace);
|
|
|
|
last_replace = save_replace;
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2004-02-24 23:41:39 +03:00
|
|
|
/* Restore where we were. */
|
2003-01-26 22:57:44 +03:00
|
|
|
current = current_save;
|
|
|
|
current_x = current_x_save;
|
|
|
|
edittop = edittop_save;
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2004-02-24 23:41:39 +03:00
|
|
|
/* Restore search/replace direction. */
|
2002-09-07 00:35:28 +04:00
|
|
|
if (reverse_search_set)
|
|
|
|
SET(REVERSE_SEARCH);
|
2001-07-11 06:08:33 +04:00
|
|
|
|
2003-01-26 22:57:44 +03:00
|
|
|
#ifndef NANO_SMALL
|
2002-12-10 03:53:21 +03:00
|
|
|
if (!case_sens_set)
|
|
|
|
UNSET(CASE_SENSITIVE);
|
|
|
|
|
2004-02-24 23:41:39 +03:00
|
|
|
/* Restore marking highlight. */
|
2002-09-07 00:35:28 +04:00
|
|
|
if (mark_set)
|
|
|
|
SET(MARK_ISSET);
|
2001-07-11 06:08:33 +04:00
|
|
|
#endif
|
|
|
|
|
2003-01-26 22:57:44 +03:00
|
|
|
return i != -1;
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
|
|
|
|
2002-12-22 19:30:00 +03:00
|
|
|
/* Integrated spell checking using 'spell' program. Return value: NULL
|
|
|
|
* for normal termination, otherwise the error string. */
|
2004-05-24 01:11:14 +04:00
|
|
|
const char *do_int_speller(char *tempfile_name)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
2002-09-07 00:35:28 +04:00
|
|
|
char *read_buff, *read_buff_ptr, *read_buff_word;
|
|
|
|
size_t pipe_buff_size, read_buff_size, read_buff_read, bytesread;
|
2003-01-13 02:54:05 +03:00
|
|
|
int spell_fd[2], sort_fd[2], uniq_fd[2], tempfile_fd = -1;
|
2002-12-09 03:58:51 +03:00
|
|
|
pid_t pid_spell, pid_sort, pid_uniq;
|
|
|
|
int spell_status, sort_status, uniq_status;
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Create all three pipes up front. */
|
2003-01-13 02:54:05 +03:00
|
|
|
if (pipe(spell_fd) == -1 || pipe(sort_fd) == -1 || pipe(uniq_fd) == -1)
|
|
|
|
return _("Could not create pipe");
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-12-10 03:16:27 +03:00
|
|
|
statusbar(_("Creating misspelled word list, please wait..."));
|
2001-04-12 07:01:53 +04:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* A new process to run spell in. */
|
2002-09-07 00:35:28 +04:00
|
|
|
if ((pid_spell = fork()) == 0) {
|
2001-04-12 07:01:53 +04:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Child continues (i.e, future spell process). */
|
2001-09-28 01:07:39 +04:00
|
|
|
|
2002-12-09 03:58:51 +03:00
|
|
|
close(spell_fd[0]);
|
2002-02-15 22:17:02 +03:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Replace the standard input with the temp file. */
|
2003-01-13 02:54:05 +03:00
|
|
|
if ((tempfile_fd = open(tempfile_name, O_RDONLY)) == -1)
|
|
|
|
goto close_pipes_and_exit;
|
|
|
|
|
|
|
|
if (dup2(tempfile_fd, STDIN_FILENO) != STDIN_FILENO)
|
|
|
|
goto close_pipes_and_exit;
|
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
close(tempfile_fd);
|
2001-04-12 07:01:53 +04:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Send spell's standard output to the pipe. */
|
2003-01-13 02:54:05 +03:00
|
|
|
if (dup2(spell_fd[1], STDOUT_FILENO) != STDOUT_FILENO)
|
|
|
|
goto close_pipes_and_exit;
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-12-09 03:58:51 +03:00
|
|
|
close(spell_fd[1]);
|
2001-04-12 07:01:53 +04:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Start spell program; we are using PATH. */
|
2002-09-07 00:35:28 +04:00
|
|
|
execlp("spell", "spell", NULL);
|
2001-04-12 07:01:53 +04:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Should not be reached, if spell is found. */
|
2002-09-07 00:35:28 +04:00
|
|
|
exit(1);
|
2001-04-12 07:01:53 +04:00
|
|
|
}
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Parent continues here. */
|
2002-12-09 03:58:51 +03:00
|
|
|
close(spell_fd[1]);
|
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* A new process to run sort in. */
|
2002-12-09 03:58:51 +03:00
|
|
|
if ((pid_sort = fork()) == 0) {
|
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Child continues (i.e, future spell process). Replace the
|
|
|
|
* standard input with the standard output of the old pipe. */
|
2003-01-13 02:54:05 +03:00
|
|
|
if (dup2(spell_fd[0], STDIN_FILENO) != STDIN_FILENO)
|
|
|
|
goto close_pipes_and_exit;
|
|
|
|
|
2002-12-09 03:58:51 +03:00
|
|
|
close(spell_fd[0]);
|
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Send sort's standard output to the new pipe. */
|
2003-01-13 02:54:05 +03:00
|
|
|
if (dup2(sort_fd[1], STDOUT_FILENO) != STDOUT_FILENO)
|
|
|
|
goto close_pipes_and_exit;
|
2002-12-09 03:58:51 +03:00
|
|
|
|
|
|
|
close(sort_fd[1]);
|
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Start sort program. Use -f to remove mixed case without
|
|
|
|
* having to have ANOTHER pipe for tr. If this isn't portable,
|
|
|
|
* let me know. */
|
2002-12-09 03:58:51 +03:00
|
|
|
execlp("sort", "sort", "-f", NULL);
|
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Should not be reached, if sort is found. */
|
2002-12-09 03:58:51 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2003-01-16 06:11:23 +03:00
|
|
|
close(spell_fd[0]);
|
2002-12-09 03:58:51 +03:00
|
|
|
close(sort_fd[1]);
|
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* A new process to run uniq in. */
|
2002-12-09 03:58:51 +03:00
|
|
|
if ((pid_uniq = fork()) == 0) {
|
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Child continues (i.e, future uniq process). Replace the
|
|
|
|
* standard input with the standard output of the old pipe. */
|
2003-01-13 02:54:05 +03:00
|
|
|
if (dup2(sort_fd[0], STDIN_FILENO) != STDIN_FILENO)
|
|
|
|
goto close_pipes_and_exit;
|
|
|
|
|
2002-12-09 03:58:51 +03:00
|
|
|
close(sort_fd[0]);
|
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Send uniq's standard output to the new pipe. */
|
2003-01-13 02:54:05 +03:00
|
|
|
if (dup2(uniq_fd[1], STDOUT_FILENO) != STDOUT_FILENO)
|
|
|
|
goto close_pipes_and_exit;
|
2002-12-09 03:58:51 +03:00
|
|
|
|
|
|
|
close(uniq_fd[1]);
|
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Start uniq program; we are using PATH. */
|
2002-12-09 03:58:51 +03:00
|
|
|
execlp("uniq", "uniq", NULL);
|
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Should not be reached, if uniq is found. */
|
2002-12-09 03:58:51 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2003-01-16 06:11:23 +03:00
|
|
|
close(sort_fd[0]);
|
2002-12-09 03:58:51 +03:00
|
|
|
close(uniq_fd[1]);
|
2001-06-28 20:52:52 +04:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Child process was not forked successfully. */
|
2002-12-09 03:58:51 +03:00
|
|
|
if (pid_spell < 0 || pid_sort < 0 || pid_uniq < 0) {
|
|
|
|
close(uniq_fd[0]);
|
2002-12-16 07:25:53 +03:00
|
|
|
return _("Could not fork");
|
2002-09-07 00:35:28 +04:00
|
|
|
}
|
2000-09-04 07:20:38 +04:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Get system pipe buffer size. */
|
2002-12-09 03:58:51 +03:00
|
|
|
if ((pipe_buff_size = fpathconf(uniq_fd[0], _PC_PIPE_BUF)) < 1) {
|
|
|
|
close(uniq_fd[0]);
|
2002-12-16 07:25:53 +03:00
|
|
|
return _("Could not get size of pipe buffer");
|
2002-09-07 00:35:28 +04:00
|
|
|
}
|
2002-07-19 05:08:59 +04:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Read in the returned spelling errors. */
|
2002-09-07 00:35:28 +04:00
|
|
|
read_buff_read = 0;
|
|
|
|
read_buff_size = pipe_buff_size + 1;
|
|
|
|
read_buff = read_buff_ptr = charalloc(read_buff_size);
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-12-09 03:58:51 +03:00
|
|
|
while ((bytesread = read(uniq_fd[0], read_buff_ptr, pipe_buff_size)) > 0) {
|
2002-09-07 00:35:28 +04:00
|
|
|
read_buff_read += bytesread;
|
|
|
|
read_buff_size += pipe_buff_size;
|
2003-06-15 00:41:34 +04:00
|
|
|
read_buff = read_buff_ptr = charealloc(read_buff, read_buff_size);
|
2002-09-07 00:35:28 +04:00
|
|
|
read_buff_ptr += read_buff_read;
|
2002-12-09 03:58:51 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
}
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-12-22 19:30:00 +03:00
|
|
|
*read_buff_ptr = (char)NULL;
|
2002-12-09 03:58:51 +03:00
|
|
|
close(uniq_fd[0]);
|
2001-01-14 08:18:27 +03:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Process the spelling errors. */
|
2002-09-07 00:35:28 +04:00
|
|
|
read_buff_word = read_buff_ptr = read_buff;
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-12-22 19:30:00 +03:00
|
|
|
while (*read_buff_ptr != '\0') {
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
if ((*read_buff_ptr == '\n') || (*read_buff_ptr == '\r')) {
|
2002-12-22 19:30:00 +03:00
|
|
|
*read_buff_ptr = (char)NULL;
|
2002-09-07 00:35:28 +04:00
|
|
|
if (read_buff_word != read_buff_ptr) {
|
|
|
|
if (!do_int_spell_fix(read_buff_word)) {
|
|
|
|
read_buff_word = read_buff_ptr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
read_buff_word = read_buff_ptr + 1;
|
|
|
|
}
|
|
|
|
read_buff_ptr++;
|
|
|
|
}
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Special case where last word doesn't end with \n or \r. */
|
2002-09-07 00:35:28 +04:00
|
|
|
if (read_buff_word != read_buff_ptr)
|
|
|
|
do_int_spell_fix(read_buff_word);
|
2000-06-19 09:45:52 +04:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
free(read_buff);
|
|
|
|
replace_abort();
|
2003-01-26 22:57:44 +03:00
|
|
|
edit_refresh();
|
2001-01-30 02:37:54 +03:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Process end of spell process. */
|
2002-12-16 07:25:53 +03:00
|
|
|
waitpid(pid_spell, &spell_status, 0);
|
|
|
|
waitpid(pid_sort, &sort_status, 0);
|
|
|
|
waitpid(pid_uniq, &uniq_status, 0);
|
2002-12-09 03:58:51 +03:00
|
|
|
|
2002-12-16 07:25:53 +03:00
|
|
|
if (WIFEXITED(spell_status) == 0 || WEXITSTATUS(spell_status))
|
|
|
|
return _("Error invoking \"spell\"");
|
2002-09-07 00:35:28 +04:00
|
|
|
|
2002-12-16 07:25:53 +03:00
|
|
|
if (WIFEXITED(sort_status) == 0 || WEXITSTATUS(sort_status))
|
|
|
|
return _("Error invoking \"sort -f\"");
|
|
|
|
|
|
|
|
if (WIFEXITED(uniq_status) == 0 || WEXITSTATUS(uniq_status))
|
|
|
|
return _("Error invoking \"uniq\"");
|
|
|
|
|
|
|
|
/* Otherwise... */
|
|
|
|
return NULL;
|
2003-01-13 02:54:05 +03:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
close_pipes_and_exit:
|
2003-01-13 02:54:05 +03:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Don't leak any handles. */
|
2003-01-13 02:54:05 +03:00
|
|
|
close(tempfile_fd);
|
|
|
|
close(spell_fd[0]);
|
|
|
|
close(spell_fd[1]);
|
|
|
|
close(sort_fd[0]);
|
|
|
|
close(sort_fd[1]);
|
|
|
|
close(uniq_fd[0]);
|
|
|
|
close(uniq_fd[1]);
|
|
|
|
exit(1);
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
|
|
|
|
2002-12-22 19:30:00 +03:00
|
|
|
/* External spell checking. Return value: NULL for normal termination,
|
|
|
|
* otherwise the error string. */
|
2004-05-24 01:11:14 +04:00
|
|
|
const char *do_alt_speller(char *tempfile_name)
|
2000-09-01 17:32:47 +04:00
|
|
|
{
|
2002-09-07 00:35:28 +04:00
|
|
|
int alt_spell_status, lineno_cur = current->lineno;
|
|
|
|
int x_cur = current_x, y_cur = current_y, pww_cur = placewewant;
|
|
|
|
pid_t pid_spell;
|
|
|
|
char *ptr;
|
|
|
|
static int arglen = 3;
|
|
|
|
static char **spellargs = (char **)NULL;
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
int mark_set = ISSET(MARK_ISSET);
|
|
|
|
int mbb_lineno_cur = 0;
|
|
|
|
/* We're going to close the current file, and open the output of
|
2004-01-23 22:34:03 +03:00
|
|
|
* the alternate spell command. The line that mark_beginbuf
|
|
|
|
* points to will be freed, so we save the line number and
|
|
|
|
* restore afterwards. */
|
2002-09-07 00:35:28 +04:00
|
|
|
|
|
|
|
if (mark_set) {
|
|
|
|
mbb_lineno_cur = mark_beginbuf->lineno;
|
|
|
|
UNSET(MARK_ISSET);
|
|
|
|
}
|
2001-06-30 08:09:09 +04:00
|
|
|
#endif
|
2000-09-01 17:32:47 +04:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
endwin();
|
2000-09-01 17:32:47 +04:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Set up an argument list to pass execvp(). */
|
2002-09-07 00:35:28 +04:00
|
|
|
if (spellargs == NULL) {
|
2003-06-15 00:41:34 +04:00
|
|
|
spellargs = (char **)nmalloc(arglen * sizeof(char *));
|
2001-06-28 20:52:52 +04:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
spellargs[0] = strtok(alt_speller, " ");
|
|
|
|
while ((ptr = strtok(NULL, " ")) != NULL) {
|
|
|
|
arglen++;
|
2003-06-15 00:41:34 +04:00
|
|
|
spellargs = (char **)nrealloc(spellargs, arglen * sizeof(char *));
|
2002-09-07 00:35:28 +04:00
|
|
|
spellargs[arglen - 3] = ptr;
|
|
|
|
}
|
|
|
|
spellargs[arglen - 1] = NULL;
|
|
|
|
}
|
|
|
|
spellargs[arglen - 2] = tempfile_name;
|
2001-12-17 07:34:23 +03:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Start a new process for the alternate speller. */
|
2002-09-07 00:35:28 +04:00
|
|
|
if ((pid_spell = fork()) == 0) {
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Start alternate spell program; we are using PATH. */
|
2002-09-07 00:35:28 +04:00
|
|
|
execvp(spellargs[0], spellargs);
|
2001-12-17 07:34:23 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
/* Should not be reached, if alternate speller is found!!! */
|
|
|
|
exit(1);
|
|
|
|
}
|
2001-12-17 07:34:23 +03:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
/* Could not fork?? */
|
|
|
|
if (pid_spell < 0)
|
2002-12-16 07:25:53 +03:00
|
|
|
return _("Could not fork");
|
2002-09-07 00:35:28 +04:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Wait for alternate speller to complete. */
|
2002-09-07 00:35:28 +04:00
|
|
|
wait(&alt_spell_status);
|
2004-01-23 22:34:03 +03:00
|
|
|
|
2002-12-16 07:25:53 +03:00
|
|
|
if (!WIFEXITED(alt_spell_status) || WEXITSTATUS(alt_spell_status) != 0) {
|
|
|
|
char *altspell_error = NULL;
|
|
|
|
char *invoke_error = _("Could not invoke \"%s\"");
|
|
|
|
int msglen = strlen(invoke_error) + strlen(alt_speller) + 2;
|
|
|
|
|
|
|
|
altspell_error = charalloc(msglen);
|
|
|
|
snprintf(altspell_error, msglen, invoke_error, alt_speller);
|
|
|
|
return altspell_error;
|
|
|
|
}
|
2002-09-07 00:35:28 +04:00
|
|
|
|
|
|
|
refresh();
|
|
|
|
#ifndef NANO_SMALL
|
2004-01-23 22:34:03 +03:00
|
|
|
if (!mark_set) {
|
|
|
|
/* Only reload the temp file if it isn't a marked selection. */
|
|
|
|
#endif
|
|
|
|
free_filestruct(fileage);
|
2004-07-27 20:46:35 +04:00
|
|
|
terminal_init();
|
2004-07-01 22:59:52 +04:00
|
|
|
global_init(TRUE);
|
2004-07-12 07:10:30 +04:00
|
|
|
open_file(tempfile_name, FALSE, TRUE);
|
2004-01-23 22:34:03 +03:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
}
|
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
if (mark_set) {
|
|
|
|
do_gotopos(mbb_lineno_cur, mark_beginx, y_cur, 0);
|
|
|
|
mark_beginbuf = current;
|
2004-01-23 22:34:03 +03:00
|
|
|
/* In case the line got shorter, assign mark_beginx. */
|
2002-09-07 00:35:28 +04:00
|
|
|
mark_beginx = current_x;
|
|
|
|
SET(MARK_ISSET);
|
|
|
|
}
|
|
|
|
#endif
|
2001-12-17 07:34:23 +03:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Go back to the old position, mark the file as modified, and make
|
|
|
|
* sure that the titlebar is refreshed. */
|
2002-09-07 00:35:28 +04:00
|
|
|
do_gotopos(lineno_cur, x_cur, y_cur, pww_cur);
|
|
|
|
set_modified();
|
|
|
|
clearok(topwin, FALSE);
|
|
|
|
titlebar(NULL);
|
2001-06-30 08:09:09 +04:00
|
|
|
|
2002-12-16 07:25:53 +03:00
|
|
|
return NULL;
|
2002-09-07 00:35:28 +04:00
|
|
|
}
|
2001-06-30 08:09:09 +04:00
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_spell(void)
|
2002-09-07 00:35:28 +04:00
|
|
|
{
|
2004-01-23 22:34:03 +03:00
|
|
|
int i;
|
2004-05-24 01:11:14 +04:00
|
|
|
char *temp = safe_tempnam(0, "nano.");
|
|
|
|
const char *spell_msg;
|
2001-06-28 20:52:52 +04:00
|
|
|
|
2004-05-24 01:11:14 +04:00
|
|
|
if (temp == NULL) {
|
|
|
|
statusbar(_("Could not create temp file: %s"), strerror(errno));
|
2004-07-02 18:31:03 +04:00
|
|
|
return;
|
2002-09-07 00:35:28 +04:00
|
|
|
}
|
2000-09-01 17:32:47 +04:00
|
|
|
|
2004-01-23 22:34:03 +03:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
if (ISSET(MARK_ISSET))
|
2004-05-28 04:15:28 +04:00
|
|
|
i = write_marked(temp, TRUE, FALSE);
|
2004-01-23 22:34:03 +03:00
|
|
|
else
|
|
|
|
#endif
|
2004-05-28 04:15:28 +04:00
|
|
|
i = write_file(temp, TRUE, FALSE, FALSE);
|
2004-01-23 22:34:03 +03:00
|
|
|
|
|
|
|
if (i == -1) {
|
2004-05-24 01:11:14 +04:00
|
|
|
statusbar(_("Unable to write temp file: %s"), strerror(errno));
|
2002-09-07 00:35:28 +04:00
|
|
|
free(temp);
|
2004-07-02 18:31:03 +04:00
|
|
|
return;
|
2000-09-04 07:20:38 +04:00
|
|
|
}
|
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifdef ENABLE_MULTIBUFFER
|
2004-01-23 22:34:03 +03:00
|
|
|
/* Update the current open_files entry before spell-checking, in
|
|
|
|
* case any problems occur. */
|
2004-07-02 18:31:03 +04:00
|
|
|
add_open_file(TRUE);
|
2001-12-17 07:34:23 +03:00
|
|
|
#endif
|
2000-09-13 18:03:27 +04:00
|
|
|
|
2004-05-24 01:11:14 +04:00
|
|
|
spell_msg = alt_speller != NULL ? do_alt_speller(temp) :
|
|
|
|
do_int_speller(temp);
|
2004-01-23 22:34:03 +03:00
|
|
|
unlink(temp);
|
2003-02-12 05:52:04 +03:00
|
|
|
free(temp);
|
2001-01-04 05:33:52 +03:00
|
|
|
|
2003-02-12 05:52:04 +03:00
|
|
|
if (spell_msg != NULL) {
|
2004-05-24 01:11:14 +04:00
|
|
|
statusbar(_("Spell checking failed: %s: %s"), spell_msg,
|
|
|
|
strerror(errno));
|
2004-07-02 18:31:03 +04:00
|
|
|
return;
|
2004-05-24 01:11:14 +04:00
|
|
|
} else
|
|
|
|
statusbar(_("Finished checking spelling"));
|
2000-09-01 17:32:47 +04:00
|
|
|
}
|
2004-04-30 08:49:02 +04:00
|
|
|
#endif /* !DISABLE_SPELLER */
|
2000-09-01 17:32:47 +04:00
|
|
|
|
2004-03-30 08:17:10 +04:00
|
|
|
#if !defined(NANO_SMALL) || !defined(DISABLE_JUSTIFY)
|
2004-05-29 21:05:52 +04:00
|
|
|
/* The "indentation" of a line is the whitespace between the quote part
|
|
|
|
* and the non-whitespace of the line. */
|
2002-09-07 00:35:28 +04:00
|
|
|
size_t indent_length(const char *line)
|
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
size_t len = 0;
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
assert(line != NULL);
|
2004-05-13 21:19:54 +04:00
|
|
|
while (isblank(*line)) {
|
2002-07-19 05:08:59 +04:00
|
|
|
line++;
|
|
|
|
len++;
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
2002-07-19 05:08:59 +04:00
|
|
|
return len;
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
2004-03-30 08:17:10 +04:00
|
|
|
#endif /* !NANO_SMALL || !DISABLE_JUSTIFY */
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
#ifndef DISABLE_JUSTIFY
|
2004-05-14 02:23:58 +04:00
|
|
|
/* justify_format() replaces Tab by Space and multiple spaces by 1
|
|
|
|
* (except it maintains 2 after a . ! or ?). Note the terminating \0
|
2002-07-19 05:08:59 +04:00
|
|
|
* counts as a space.
|
|
|
|
*
|
2004-05-18 00:32:51 +04:00
|
|
|
* justify_format() might make line->data shorter, and change the actual
|
|
|
|
* pointer with null_at().
|
2002-07-19 05:08:59 +04:00
|
|
|
*
|
2002-11-04 19:05:42 +03:00
|
|
|
* justify_format() will not look at the first skip characters of line.
|
2004-05-14 02:23:58 +04:00
|
|
|
* skip should be at most strlen(line->data). The character at
|
|
|
|
* line[skip + 1] must not be whitespace. */
|
2004-05-18 00:32:51 +04:00
|
|
|
void justify_format(filestruct *line, size_t skip)
|
2002-08-21 20:10:37 +04:00
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
char *back, *front;
|
|
|
|
|
|
|
|
/* These four asserts are assumptions about the input data. */
|
|
|
|
assert(line != NULL);
|
|
|
|
assert(line->data != NULL);
|
2003-03-11 06:50:40 +03:00
|
|
|
assert(skip < strlen(line->data));
|
2004-05-13 21:19:54 +04:00
|
|
|
assert(!isblank(line->data[skip]));
|
2002-07-19 05:08:59 +04:00
|
|
|
|
|
|
|
back = line->data + skip;
|
2003-02-20 01:27:53 +03:00
|
|
|
for (front = back; ; front++) {
|
2004-05-13 21:28:03 +04:00
|
|
|
int remove_space = FALSE;
|
2002-10-17 06:19:31 +04:00
|
|
|
/* Do we want to remove this space? */
|
|
|
|
|
2004-05-18 00:32:51 +04:00
|
|
|
if (*front == '\t')
|
2002-07-19 05:08:59 +04:00
|
|
|
*front = ' ';
|
2004-05-18 00:32:51 +04:00
|
|
|
|
2004-05-14 03:19:01 +04:00
|
|
|
/* These tests are safe since line->data + skip is not a
|
|
|
|
* space. */
|
2003-02-20 01:27:53 +03:00
|
|
|
if ((*front == '\0' || *front == ' ') && *(front - 1) == ' ') {
|
2002-10-17 06:19:31 +04:00
|
|
|
const char *bob = front - 2;
|
|
|
|
|
2004-05-13 21:28:03 +04:00
|
|
|
remove_space = TRUE;
|
2003-02-20 01:27:53 +03:00
|
|
|
for (bob = back - 2; bob >= line->data + skip; bob--) {
|
2002-10-17 06:19:31 +04:00
|
|
|
if (strchr(punct, *bob) != NULL) {
|
2004-05-13 21:28:03 +04:00
|
|
|
remove_space = FALSE;
|
2002-10-17 06:19:31 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strchr(brackets, *bob) == NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (remove_space) {
|
2002-07-19 05:08:59 +04:00
|
|
|
/* Now *front is a space we want to remove. We do that by
|
2002-10-17 06:19:31 +04:00
|
|
|
* simply failing to assign it to *back. */
|
2002-07-19 05:08:59 +04:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
if (mark_beginbuf == line && back - line->data < mark_beginx)
|
|
|
|
mark_beginx--;
|
|
|
|
#endif
|
2003-02-20 01:27:53 +03:00
|
|
|
if (*front == '\0')
|
|
|
|
*(back - 1) = '\0';
|
2002-07-19 05:08:59 +04:00
|
|
|
} else {
|
|
|
|
*back = *front;
|
|
|
|
back++;
|
|
|
|
}
|
2003-02-20 01:27:53 +03:00
|
|
|
if (*front == '\0')
|
|
|
|
break;
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
|
|
|
|
2003-02-20 01:27:53 +03:00
|
|
|
back--;
|
2003-03-11 06:50:40 +03:00
|
|
|
assert(*back == '\0' && *front == '\0');
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
/* Now back is the new end of line->data. */
|
|
|
|
if (back != front) {
|
2003-03-11 06:50:40 +03:00
|
|
|
totsize -= front - back;
|
2002-07-19 05:08:59 +04:00
|
|
|
null_at(&line->data, back - line->data);
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
if (mark_beginbuf == line && back - line->data < mark_beginx)
|
|
|
|
mark_beginx = back - line->data;
|
|
|
|
#endif
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
2002-07-19 05:08:59 +04:00
|
|
|
}
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
/* The "quote part" of a line is the largest initial substring matching
|
|
|
|
* the quote string. This function returns the length of the quote part
|
|
|
|
* of the given line.
|
|
|
|
*
|
|
|
|
* Note that if !HAVE_REGEX_H then we match concatenated copies of
|
|
|
|
* quotestr. */
|
|
|
|
#ifdef HAVE_REGEX_H
|
2002-08-21 20:10:37 +04:00
|
|
|
size_t quote_length(const char *line, const regex_t *qreg)
|
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
regmatch_t matches;
|
|
|
|
int rc = regexec(qreg, line, 1, &matches, 0);
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
if (rc == REG_NOMATCH || matches.rm_so == (regoff_t) -1)
|
|
|
|
return 0;
|
|
|
|
/* matches.rm_so should be 0, since the quote string should start with
|
|
|
|
* the caret ^. */
|
|
|
|
return matches.rm_eo;
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
2002-07-19 05:08:59 +04:00
|
|
|
#else /* !HAVE_REGEX_H */
|
2002-08-21 20:10:37 +04:00
|
|
|
size_t quote_length(const char *line)
|
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
size_t qdepth = 0;
|
|
|
|
size_t qlen = strlen(quotestr);
|
2002-03-04 01:36:36 +03:00
|
|
|
|
2004-07-17 23:49:12 +04:00
|
|
|
/* Compute quote depth level. */
|
2002-07-19 05:08:59 +04:00
|
|
|
while (!strcmp(line + qdepth, quotestr))
|
|
|
|
qdepth += qlen;
|
|
|
|
return qdepth;
|
|
|
|
}
|
|
|
|
#endif /* !HAVE_REGEX_H */
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
/* a_line and b_line are lines of text. The quotation part of a_line is
|
|
|
|
* the first a_quote characters. Check that the quotation part of
|
|
|
|
* b_line is the same. */
|
2004-05-14 05:17:25 +04:00
|
|
|
int quotes_match(const char *a_line, size_t a_quote, IFREG(const char
|
|
|
|
*b_line, const regex_t *qreg))
|
2002-08-21 20:10:37 +04:00
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
/* Here is the assumption about a_quote: */
|
|
|
|
assert(a_quote == quote_length(IFREG(a_line, qreg)));
|
2002-07-30 03:46:38 +04:00
|
|
|
return a_quote == quote_length(IFREG(b_line, qreg)) &&
|
2002-07-19 05:08:59 +04:00
|
|
|
!strncmp(a_line, b_line, a_quote);
|
|
|
|
}
|
2002-03-04 01:36:36 +03:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
/* We assume a_line and b_line have no quote part. Then, we return whether
|
|
|
|
* b_line could follow a_line in a paragraph. */
|
2004-05-14 05:17:25 +04:00
|
|
|
size_t indents_match(const char *a_line, size_t a_indent, const char
|
|
|
|
*b_line, size_t b_indent)
|
2002-08-21 20:10:37 +04:00
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
assert(a_indent == indent_length(a_line));
|
|
|
|
assert(b_indent == indent_length(b_line));
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
return b_indent <= a_indent && !strncmp(a_line, b_line, b_indent);
|
|
|
|
}
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
/* Put the next par_len lines, starting with first_line, in the cut
|
2004-03-30 08:17:10 +04:00
|
|
|
* buffer, not allowing them to be concatenated. We assume there are
|
|
|
|
* enough lines after first_line. We leave copies of the lines in
|
|
|
|
* place, too. We return the new copy of first_line. */
|
2004-05-14 05:17:25 +04:00
|
|
|
filestruct *backup_lines(filestruct *first_line, size_t par_len, size_t
|
|
|
|
quote_len)
|
2002-08-21 20:10:37 +04:00
|
|
|
{
|
2004-05-18 00:32:51 +04:00
|
|
|
/* We put the original lines, not copies, into the cutbuffer, just
|
|
|
|
* out of a misguided sense of consistency, so if you uncut, you get
|
|
|
|
* the actual same paragraph back, not a copy. */
|
2003-01-15 14:18:58 +03:00
|
|
|
filestruct *alice = first_line;
|
2000-06-06 09:53:49 +04:00
|
|
|
|
|
|
|
set_modified();
|
2000-11-27 03:23:41 +03:00
|
|
|
cutbuffer = NULL;
|
2003-11-06 01:04:08 +03:00
|
|
|
for (; par_len > 0; par_len--) {
|
2003-01-15 14:18:58 +03:00
|
|
|
filestruct *bob = copy_node(alice);
|
2002-07-19 05:08:59 +04:00
|
|
|
|
2003-01-15 14:18:58 +03:00
|
|
|
if (alice == first_line)
|
2002-07-19 05:08:59 +04:00
|
|
|
first_line = bob;
|
2003-01-15 14:18:58 +03:00
|
|
|
if (alice == current)
|
2002-07-19 05:08:59 +04:00
|
|
|
current = bob;
|
2003-01-15 14:18:58 +03:00
|
|
|
if (alice == edittop)
|
2002-07-19 05:08:59 +04:00
|
|
|
edittop = bob;
|
|
|
|
#ifndef NANO_SMALL
|
2003-01-15 14:18:58 +03:00
|
|
|
if (alice == mark_beginbuf)
|
2002-07-19 05:08:59 +04:00
|
|
|
mark_beginbuf = bob;
|
|
|
|
#endif
|
|
|
|
|
2003-01-15 14:18:58 +03:00
|
|
|
assert(alice != NULL && bob != NULL);
|
2004-03-30 08:17:10 +04:00
|
|
|
add_to_cutbuffer(alice, FALSE);
|
2002-07-19 05:08:59 +04:00
|
|
|
splice_node(bob->prev, bob, bob->next);
|
2003-01-15 14:18:58 +03:00
|
|
|
alice = bob->next;
|
2002-07-19 05:08:59 +04:00
|
|
|
}
|
|
|
|
return first_line;
|
|
|
|
}
|
|
|
|
|
2003-02-03 06:22:02 +03:00
|
|
|
/* Is it possible to break line at or before goal? */
|
|
|
|
int breakable(const char *line, int goal)
|
|
|
|
{
|
2003-11-06 01:04:08 +03:00
|
|
|
for (; *line != '\0' && goal >= 0; line++) {
|
2004-05-13 21:19:54 +04:00
|
|
|
if (isblank(*line))
|
2003-02-03 06:22:02 +03:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (is_cntrl_char(*line) != 0)
|
|
|
|
goal -= 2;
|
|
|
|
else
|
|
|
|
goal -= 1;
|
|
|
|
}
|
2003-02-12 06:21:45 +03:00
|
|
|
/* If goal is not negative, the whole line (one word) was short
|
|
|
|
* enough. */
|
|
|
|
return goal >= 0;
|
2003-02-03 06:22:02 +03:00
|
|
|
}
|
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
/* We are trying to break a chunk off line. We find the last space such
|
|
|
|
* that the display length to there is at most goal + 1. If there is
|
|
|
|
* no such space, and force is not 0, then we find the first space.
|
|
|
|
* Anyway, we then take the last space in that group of spaces. The
|
|
|
|
* terminating '\0' counts as a space. */
|
2002-08-21 20:10:37 +04:00
|
|
|
int break_line(const char *line, int goal, int force)
|
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
/* Note that we use int instead of size_t, since goal is at most COLS,
|
|
|
|
* the screen width, which will always be reasonably small. */
|
|
|
|
int space_loc = -1;
|
|
|
|
/* Current tentative return value. Index of the last space we
|
|
|
|
* found with short enough display width. */
|
|
|
|
int cur_loc = 0;
|
2004-05-13 21:28:03 +04:00
|
|
|
/* Current index in line. */
|
2002-07-19 05:08:59 +04:00
|
|
|
|
|
|
|
assert(line != NULL);
|
2003-11-06 01:04:08 +03:00
|
|
|
for (; *line != '\0' && goal >= 0; line++, cur_loc++) {
|
2002-07-19 05:08:59 +04:00
|
|
|
if (*line == ' ')
|
|
|
|
space_loc = cur_loc;
|
|
|
|
assert(*line != '\t');
|
|
|
|
|
2002-07-20 17:57:41 +04:00
|
|
|
if (is_cntrl_char(*line))
|
2002-07-19 05:08:59 +04:00
|
|
|
goal -= 2;
|
|
|
|
else
|
|
|
|
goal--;
|
|
|
|
}
|
|
|
|
if (goal >= 0)
|
|
|
|
/* In fact, the whole line displays shorter than goal. */
|
|
|
|
return cur_loc;
|
|
|
|
if (space_loc == -1) {
|
|
|
|
/* No space found short enough. */
|
|
|
|
if (force)
|
2003-11-06 01:04:08 +03:00
|
|
|
for (; *line != '\0'; line++, cur_loc++)
|
2003-02-20 01:27:53 +03:00
|
|
|
if (*line == ' ' && *(line + 1) != ' ' && *(line + 1) != '\0')
|
2002-07-19 05:08:59 +04:00
|
|
|
return cur_loc;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* Perhaps the character after space_loc is a space. But because
|
2002-11-04 19:05:42 +03:00
|
|
|
* of justify_format(), there can be only two adjacent. */
|
2002-07-19 05:08:59 +04:00
|
|
|
if (*(line - cur_loc + space_loc + 1) == ' ' ||
|
|
|
|
*(line - cur_loc + space_loc + 1) == '\0')
|
|
|
|
space_loc++;
|
|
|
|
return space_loc;
|
|
|
|
}
|
|
|
|
|
2004-05-24 09:52:35 +04:00
|
|
|
/* Search a paragraph. If search_type is JUSTIFY, search for the
|
|
|
|
* beginning of the current paragraph or, if we're at the end of it, the
|
|
|
|
* beginning of the next paragraph. If search_type is BEGIN, search for
|
|
|
|
* the beginning of the current paragraph or, if we're already there,
|
|
|
|
* the beginning of the previous paragraph. If search_type is END,
|
|
|
|
* search for the end of the current paragraph or, if we're already
|
|
|
|
* there, the end of the next paragraph. Afterwards, save the quote
|
|
|
|
* length, paragraph length, and indentation length in *quote, *par, and
|
|
|
|
* *indent if they aren't NULL, and refresh the screen if do_refresh is
|
|
|
|
* TRUE. Return 0 if we found a paragraph, or 1 if there was an error
|
|
|
|
* or we didn't find a paragraph.
|
2003-09-05 00:25:29 +04:00
|
|
|
*
|
2004-02-27 21:54:04 +03:00
|
|
|
* To explain the searching algorithm, I first need to define some
|
2002-07-19 05:08:59 +04:00
|
|
|
* phrases about paragraphs and quotation:
|
|
|
|
* A line of text consists of a "quote part", followed by an
|
|
|
|
* "indentation part", followed by text. The functions quote_length()
|
|
|
|
* and indent_length() calculate these parts.
|
|
|
|
*
|
|
|
|
* A line is "part of a paragraph" if it has a part not in the quote
|
|
|
|
* part or the indentation.
|
|
|
|
*
|
2003-11-06 01:04:08 +03:00
|
|
|
* A line is "the beginning of a paragraph" if it is part of a
|
|
|
|
* paragraph and
|
2002-07-19 05:08:59 +04:00
|
|
|
* 1) it is the top line of the file, or
|
|
|
|
* 2) the line above it is not part of a paragraph, or
|
|
|
|
* 3) the line above it does not have precisely the same quote
|
|
|
|
* part, or
|
2003-11-06 01:04:08 +03:00
|
|
|
* 4) the indentation of this line is not an initial substring of
|
|
|
|
* the indentation of the previous line, or
|
2002-07-19 05:08:59 +04:00
|
|
|
* 5) this line has no quote part and some indentation, and
|
|
|
|
* AUTOINDENT is not set.
|
|
|
|
* The reason for number 5) is that if AUTOINDENT is not set, then an
|
2003-11-06 01:04:08 +03:00
|
|
|
* indented line is expected to start a paragraph, like in books.
|
|
|
|
* Thus, nano can justify an indented paragraph only if AUTOINDENT is
|
|
|
|
* turned on.
|
2002-07-19 05:08:59 +04:00
|
|
|
*
|
|
|
|
* A contiguous set of lines is a "paragraph" if each line is part of
|
2003-11-06 01:04:08 +03:00
|
|
|
* a paragraph and only the first line is the beginning of a
|
2003-12-24 06:33:09 +03:00
|
|
|
* paragraph. */
|
2004-05-24 09:52:35 +04:00
|
|
|
int do_para_search(justbegend search_type, size_t *quote, size_t *par,
|
|
|
|
size_t *indent, int do_refresh)
|
2004-02-27 21:54:04 +03:00
|
|
|
{
|
2004-05-30 07:19:52 +04:00
|
|
|
int old_pww = placewewant;
|
2004-05-29 00:44:09 +04:00
|
|
|
const filestruct *current_save = current;
|
2002-07-19 05:08:59 +04:00
|
|
|
size_t quote_len;
|
2003-11-06 01:04:08 +03:00
|
|
|
/* Length of the initial quotation of the paragraph we
|
2004-02-27 21:54:04 +03:00
|
|
|
* search. */
|
2002-07-19 05:08:59 +04:00
|
|
|
size_t par_len;
|
|
|
|
/* Number of lines in that paragraph. */
|
2004-05-29 00:44:09 +04:00
|
|
|
size_t indent_len;
|
|
|
|
/* Generic indentation length. */
|
|
|
|
filestruct *line;
|
|
|
|
/* Generic line of text. */
|
2003-09-05 00:25:29 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
#ifdef HAVE_REGEX_H
|
2004-02-27 21:54:04 +03:00
|
|
|
regex_t qreg; /* qreg is the compiled quotation regexp. We no
|
|
|
|
* longer care about quotestr. */
|
2002-07-19 05:08:59 +04:00
|
|
|
int rc = regcomp(&qreg, quotestr, REG_EXTENDED);
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2004-02-27 21:54:04 +03:00
|
|
|
if (rc != 0) {
|
2002-07-19 05:08:59 +04:00
|
|
|
size_t size = regerror(rc, &qreg, NULL, 0);
|
|
|
|
char *strerror = charalloc(size);
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
regerror(rc, &qreg, strerror, size);
|
|
|
|
statusbar(_("Bad quote string %s: %s"), quotestr, strerror);
|
|
|
|
free(strerror);
|
2004-02-27 21:54:04 +03:00
|
|
|
return 1;
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
2002-07-19 05:08:59 +04:00
|
|
|
#endif
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
/* Here is an assumption that is always true anyway. */
|
|
|
|
assert(current != NULL);
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2003-09-05 00:25:29 +04:00
|
|
|
current_x = 0;
|
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
quote_len = quote_length(IFREG(current->data, &qreg));
|
|
|
|
indent_len = indent_length(current->data + quote_len);
|
2001-01-22 02:23:48 +03:00
|
|
|
|
2004-06-27 04:54:08 +04:00
|
|
|
/* Here we find the last or first line of the paragraph to search.
|
|
|
|
* If the current line is in a paragraph, then we move back to the
|
|
|
|
* first line of the paragraph. Otherwise, we move to the last or
|
|
|
|
* first line that is in a paragraph. */
|
|
|
|
start_para_search:
|
2002-07-19 05:08:59 +04:00
|
|
|
if (current->data[quote_len + indent_len] != '\0') {
|
|
|
|
/* This line is part of a paragraph. So we must search back to
|
2003-11-06 01:04:08 +03:00
|
|
|
* the first line of this paragraph. First we check items 1)
|
|
|
|
* and 3) above. */
|
2002-12-22 19:30:00 +03:00
|
|
|
while (current->prev != NULL && quotes_match(current->data,
|
2002-07-19 05:08:59 +04:00
|
|
|
quote_len, IFREG(current->prev->data, &qreg))) {
|
2002-09-13 22:14:04 +04:00
|
|
|
size_t temp_id_len =
|
2002-07-19 05:08:59 +04:00
|
|
|
indent_length(current->prev->data + quote_len);
|
2002-09-13 22:14:04 +04:00
|
|
|
/* The indentation length of the previous line. */
|
2002-08-21 20:10:37 +04:00
|
|
|
|
2002-09-13 22:14:04 +04:00
|
|
|
/* Is this line the beginning of a paragraph, according to
|
2004-02-27 21:54:04 +03:00
|
|
|
* items 2), 5), or 4) above? If so, stop. */
|
2002-09-13 22:14:04 +04:00
|
|
|
if (current->prev->data[quote_len + temp_id_len] == '\0' ||
|
2004-05-17 20:11:18 +04:00
|
|
|
(quote_len == 0 && indent_len > 0
|
2002-09-13 22:14:04 +04:00
|
|
|
#ifndef NANO_SMALL
|
2004-05-17 20:11:18 +04:00
|
|
|
&& !ISSET(AUTOINDENT)
|
2002-09-13 22:14:04 +04:00
|
|
|
#endif
|
2004-05-17 20:11:18 +04:00
|
|
|
) || !indents_match(current->prev->data + quote_len,
|
|
|
|
temp_id_len, current->data + quote_len, indent_len))
|
2002-09-13 22:14:04 +04:00
|
|
|
break;
|
|
|
|
indent_len = temp_id_len;
|
|
|
|
current = current->prev;
|
|
|
|
current_y--;
|
2002-04-06 09:02:14 +04:00
|
|
|
}
|
2004-06-27 04:54:08 +04:00
|
|
|
|
|
|
|
/* If we're searching for the beginning of the paragraph,
|
|
|
|
* we're not on the first line of the file, and we're on the
|
|
|
|
* same line we started on, move up one line and search
|
|
|
|
* again, so that we end up on the first line of the previous
|
|
|
|
* paragraph. */
|
|
|
|
if (search_type == BEGIN && current->prev != NULL &&
|
|
|
|
current == current_save) {
|
|
|
|
current = current->prev;
|
|
|
|
current_y--;
|
|
|
|
goto start_para_search;
|
|
|
|
}
|
2004-05-24 09:52:35 +04:00
|
|
|
} else if (search_type == BEGIN) {
|
2003-09-05 00:25:29 +04:00
|
|
|
/* This line is not part of a paragraph. Move up until we get
|
2004-06-27 04:54:08 +04:00
|
|
|
* to a non "blank" line. */
|
2003-09-05 00:25:29 +04:00
|
|
|
do {
|
|
|
|
/* There is no previous paragraph, so nothing to move to. */
|
|
|
|
if (current->prev == NULL) {
|
|
|
|
placewewant = 0;
|
2004-05-17 20:11:18 +04:00
|
|
|
if (do_refresh)
|
2004-05-30 07:19:52 +04:00
|
|
|
edit_redraw(current_save, old_pww);
|
2004-02-27 21:54:04 +03:00
|
|
|
#ifdef HAVE_REGEX_H
|
2004-06-27 04:54:08 +04:00
|
|
|
regfree(&qreg);
|
2004-02-27 21:54:04 +03:00
|
|
|
#endif
|
|
|
|
return 1;
|
2003-09-05 00:25:29 +04:00
|
|
|
}
|
|
|
|
current = current->prev;
|
|
|
|
current_y--;
|
|
|
|
quote_len = quote_length(IFREG(current->data, &qreg));
|
|
|
|
indent_len = indent_length(current->data + quote_len);
|
|
|
|
} while (current->data[quote_len + indent_len] == '\0');
|
2002-07-19 05:08:59 +04:00
|
|
|
} else {
|
2002-07-30 03:46:38 +04:00
|
|
|
/* This line is not part of a paragraph. Move down until we get
|
|
|
|
* to a non "blank" line. */
|
2002-07-19 05:08:59 +04:00
|
|
|
do {
|
2004-02-27 21:54:04 +03:00
|
|
|
/* There is no next paragraph, so nothing to move to. */
|
2002-08-21 20:10:37 +04:00
|
|
|
if (current->next == NULL) {
|
|
|
|
placewewant = 0;
|
2004-02-27 21:54:04 +03:00
|
|
|
if (do_refresh)
|
2004-05-30 07:19:52 +04:00
|
|
|
edit_redraw(current_save, old_pww);
|
2003-02-12 06:21:45 +03:00
|
|
|
#ifdef HAVE_REGEX_H
|
|
|
|
regfree(&qreg);
|
|
|
|
#endif
|
2004-02-27 21:54:04 +03:00
|
|
|
return 1;
|
2002-08-21 20:10:37 +04:00
|
|
|
}
|
2002-07-19 05:08:59 +04:00
|
|
|
current = current->next;
|
2002-08-21 20:10:37 +04:00
|
|
|
current_y++;
|
2002-07-19 05:08:59 +04:00
|
|
|
quote_len = quote_length(IFREG(current->data, &qreg));
|
|
|
|
indent_len = indent_length(current->data + quote_len);
|
|
|
|
} while (current->data[quote_len + indent_len] == '\0');
|
|
|
|
}
|
2004-02-27 21:54:04 +03:00
|
|
|
|
2004-06-27 04:54:08 +04:00
|
|
|
/* Now current is the last line in the paragraph if we're searching
|
|
|
|
* for the beginning of it or the first line of the paragraph
|
|
|
|
* otherwise, and quote_len is the quotation length of that line. */
|
2002-07-19 05:08:59 +04:00
|
|
|
|
2004-05-17 20:11:18 +04:00
|
|
|
/* Next step, compute par_len, the number of lines in this
|
|
|
|
* paragraph. */
|
2002-07-19 05:08:59 +04:00
|
|
|
line = current;
|
|
|
|
par_len = 1;
|
|
|
|
indent_len = indent_length(line->data + quote_len);
|
|
|
|
|
2004-06-27 04:54:08 +04:00
|
|
|
if (search_type == BEGIN) {
|
|
|
|
while (line->prev != NULL && quotes_match(current->data,
|
|
|
|
quote_len, IFREG(line->prev->data, &qreg))) {
|
|
|
|
size_t temp_id_len = indent_length(line->prev->data +
|
|
|
|
quote_len);
|
|
|
|
|
|
|
|
if (!indents_match(line->data + quote_len, indent_len,
|
|
|
|
line->prev->data + quote_len, temp_id_len) ||
|
|
|
|
line->prev->data[quote_len + temp_id_len] == '\0' ||
|
|
|
|
(quote_len == 0 && temp_id_len > 0
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
&& !ISSET(AUTOINDENT)
|
|
|
|
#endif
|
|
|
|
))
|
|
|
|
break;
|
|
|
|
indent_len = temp_id_len;
|
|
|
|
line = line->prev;
|
|
|
|
par_len++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (line->next != NULL && quotes_match(current->data,
|
|
|
|
quote_len, IFREG(line->next->data, &qreg))) {
|
|
|
|
size_t temp_id_len = indent_length(line->next->data +
|
|
|
|
quote_len);
|
2002-07-19 05:08:59 +04:00
|
|
|
|
2004-06-27 04:54:08 +04:00
|
|
|
if (!indents_match(line->data + quote_len, indent_len,
|
2004-05-17 20:11:18 +04:00
|
|
|
line->next->data + quote_len, temp_id_len) ||
|
2002-07-19 05:08:59 +04:00
|
|
|
line->next->data[quote_len + temp_id_len] == '\0' ||
|
|
|
|
(quote_len == 0 && temp_id_len > 0
|
|
|
|
#ifndef NANO_SMALL
|
2004-06-27 04:54:08 +04:00
|
|
|
&& !ISSET(AUTOINDENT)
|
2002-07-19 05:08:59 +04:00
|
|
|
#endif
|
|
|
|
))
|
2004-06-27 04:54:08 +04:00
|
|
|
break;
|
|
|
|
indent_len = temp_id_len;
|
|
|
|
line = line->next;
|
|
|
|
par_len++;
|
|
|
|
}
|
2004-02-27 21:54:04 +03:00
|
|
|
}
|
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
#ifdef HAVE_REGEX_H
|
2004-02-27 21:54:04 +03:00
|
|
|
/* We no longer need to check quotation. */
|
|
|
|
regfree(&qreg);
|
|
|
|
#endif
|
|
|
|
|
2004-05-17 20:11:18 +04:00
|
|
|
/* Now par_len is the number of lines in this paragraph. We should
|
|
|
|
* never call quotes_match() or quote_length() again. */
|
2004-02-27 21:54:04 +03:00
|
|
|
|
2004-06-27 04:54:08 +04:00
|
|
|
/* If we're searching for the beginning of the paragraph, move up
|
|
|
|
* the number of lines in the paragraph minus one, since we want to
|
|
|
|
* end up on the first line of the paragraph. If we're searching
|
|
|
|
* for the end of the paragraph, move down the number of lines in
|
|
|
|
* the paragraph, since we want to end up on the line after the
|
|
|
|
* last line of the paragraph. */
|
|
|
|
if (search_type == BEGIN) {
|
|
|
|
for (; par_len > 1; current_y--, par_len--)
|
|
|
|
current = current->prev;
|
|
|
|
} else if (search_type == END) {
|
2004-02-27 21:54:04 +03:00
|
|
|
for (; par_len > 0; current_y++, par_len--)
|
2003-09-05 03:22:47 +04:00
|
|
|
current = current->next;
|
2004-02-27 21:54:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Refresh the screen if needed. */
|
2004-05-17 20:11:18 +04:00
|
|
|
if (do_refresh)
|
2004-05-30 07:19:52 +04:00
|
|
|
edit_redraw(current_save, old_pww);
|
2004-02-27 21:54:04 +03:00
|
|
|
|
|
|
|
/* Save the values of quote_len, par_len, and indent_len if
|
|
|
|
* needed. */
|
|
|
|
if (quote != NULL)
|
|
|
|
*quote = quote_len;
|
|
|
|
if (par != NULL)
|
|
|
|
*par = par_len;
|
|
|
|
if (indent != NULL)
|
|
|
|
*indent = indent_len;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_para_begin(void)
|
2004-02-27 21:54:04 +03:00
|
|
|
{
|
2004-07-02 18:31:03 +04:00
|
|
|
do_para_search(BEGIN, NULL, NULL, NULL, TRUE);
|
2004-02-27 21:54:04 +03:00
|
|
|
}
|
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_para_end(void)
|
2004-02-27 21:54:04 +03:00
|
|
|
{
|
2004-07-02 18:31:03 +04:00
|
|
|
do_para_search(END, NULL, NULL, NULL, TRUE);
|
2004-02-27 21:54:04 +03:00
|
|
|
}
|
|
|
|
|
2004-05-13 21:28:03 +04:00
|
|
|
/* If full_justify is TRUE, justify the entire file. Otherwise, justify
|
|
|
|
* the current paragraph. */
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_justify(int full_justify)
|
2004-02-27 21:54:04 +03:00
|
|
|
{
|
|
|
|
size_t quote_len;
|
|
|
|
/* Length of the initial quotation of the paragraph we
|
|
|
|
* justify. */
|
|
|
|
size_t par_len;
|
|
|
|
/* Number of lines in that paragraph. */
|
2004-05-18 00:32:51 +04:00
|
|
|
filestruct *first_par_line = NULL;
|
|
|
|
/* Will be the first line of the resulting justified paragraph.
|
|
|
|
* For restoring after uncut. */
|
2004-05-18 00:38:00 +04:00
|
|
|
filestruct *last_par_line;
|
2004-02-27 21:54:04 +03:00
|
|
|
/* Will be the last line of the result, also for uncut. */
|
|
|
|
filestruct *cutbuffer_save = cutbuffer;
|
|
|
|
/* When the paragraph gets modified, all lines from the changed
|
2004-05-18 00:32:51 +04:00
|
|
|
* one down are stored in the cutbuffer. We back up the
|
2004-02-27 21:54:04 +03:00
|
|
|
* original to restore it later. */
|
2004-07-03 18:15:58 +04:00
|
|
|
int allow_respacing;
|
|
|
|
/* Whether we should change the spacing at the end of a line
|
2004-07-05 18:27:29 +04:00
|
|
|
* after justifying it. This should be TRUE whenever we move
|
2004-07-03 18:15:58 +04:00
|
|
|
* to the next line after justifying the current line. */
|
2004-02-27 21:54:04 +03:00
|
|
|
|
|
|
|
/* We save these global variables to be restored if the user
|
|
|
|
* unjustifies. Note we don't need to save totlines. */
|
|
|
|
int current_x_save = current_x;
|
|
|
|
int current_y_save = current_y;
|
2004-07-03 07:09:12 +04:00
|
|
|
long flags_save = flags;
|
2004-02-27 21:54:04 +03:00
|
|
|
long totsize_save = totsize;
|
2004-05-29 00:44:09 +04:00
|
|
|
filestruct *current_save = current;
|
2004-02-27 21:54:04 +03:00
|
|
|
filestruct *edittop_save = edittop;
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
filestruct *mark_beginbuf_save = mark_beginbuf;
|
|
|
|
int mark_beginx_save = mark_beginx;
|
|
|
|
#endif
|
2004-07-01 22:59:52 +04:00
|
|
|
int kbinput;
|
|
|
|
int meta_key;
|
2004-02-27 21:54:04 +03:00
|
|
|
|
|
|
|
size_t indent_len; /* Generic indentation length. */
|
|
|
|
|
2004-05-18 00:32:51 +04:00
|
|
|
/* If we're justifying the entire file, start at the beginning. */
|
|
|
|
if (full_justify)
|
2004-05-13 21:28:03 +04:00
|
|
|
current = fileage;
|
2004-05-18 00:32:51 +04:00
|
|
|
|
|
|
|
last_par_line = current;
|
2004-05-13 21:28:03 +04:00
|
|
|
|
|
|
|
while (TRUE) {
|
|
|
|
/* First, search for the beginning of the current paragraph or,
|
|
|
|
* if we're at the end of it, the beginning of the next
|
|
|
|
* paragraph. Save the quote length, paragraph length, and
|
|
|
|
* indentation length and don't refresh the screen yet (since
|
|
|
|
* we'll do that after we justify). If the search failed and
|
|
|
|
* we're justifying the whole file, move the last line of the
|
|
|
|
* text we're justifying to just before the magicline, which is
|
|
|
|
* where it'll be anyway if we've searched the entire file, and
|
|
|
|
* break out of the loop; otherwise, refresh the screen and get
|
|
|
|
* out. */
|
2004-05-24 09:52:35 +04:00
|
|
|
if (do_para_search(JUSTIFY, "e_len, &par_len, &indent_len,
|
|
|
|
FALSE) != 0) {
|
2004-05-13 21:28:03 +04:00
|
|
|
if (full_justify) {
|
|
|
|
/* This should be safe in the event of filebot->prev's
|
|
|
|
* being NULL, since only last_par_line->next is used if
|
|
|
|
* we eventually unjustify. */
|
|
|
|
last_par_line = filebot->prev;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
edit_refresh();
|
2004-07-02 18:31:03 +04:00
|
|
|
return;
|
2004-05-13 21:28:03 +04:00
|
|
|
}
|
|
|
|
}
|
2003-09-05 00:25:29 +04:00
|
|
|
|
2004-05-13 21:28:03 +04:00
|
|
|
/* Next step, we loop through the lines of this paragraph,
|
|
|
|
* justifying each one individually. */
|
|
|
|
for (; par_len > 0; current_y++, par_len--) {
|
|
|
|
size_t line_len;
|
|
|
|
size_t display_len;
|
|
|
|
/* The width of current in screen columns. */
|
|
|
|
int break_pos;
|
|
|
|
/* Where we will break the line. */
|
|
|
|
|
2004-07-03 18:15:58 +04:00
|
|
|
/* We'll be moving to the next line after justifying the
|
|
|
|
* current line in almost all cases, so allow changing the
|
|
|
|
* spacing at the ends of justified lines by default. */
|
|
|
|
allow_respacing = TRUE;
|
|
|
|
|
2004-05-24 01:11:14 +04:00
|
|
|
indent_len = quote_len + indent_length(current->data +
|
|
|
|
quote_len);
|
2004-05-13 21:28:03 +04:00
|
|
|
|
2004-06-25 05:52:10 +04:00
|
|
|
/* If we haven't already done it, copy the original
|
|
|
|
* paragraph to the cutbuffer for unjustification. */
|
2004-05-18 00:32:51 +04:00
|
|
|
if (first_par_line == NULL)
|
|
|
|
first_par_line = backup_lines(current, full_justify ?
|
2004-05-13 21:28:03 +04:00
|
|
|
filebot->lineno - current->lineno : par_len, quote_len);
|
|
|
|
|
2004-06-25 05:52:10 +04:00
|
|
|
/* Now we call justify_format() on the current line of the
|
|
|
|
* paragraph, which will remove excess spaces from it and
|
|
|
|
* change tabs to spaces. */
|
|
|
|
justify_format(current, quote_len +
|
|
|
|
indent_length(current->data + quote_len));
|
|
|
|
|
2004-05-13 21:28:03 +04:00
|
|
|
line_len = strlen(current->data);
|
|
|
|
display_len = strlenpt(current->data);
|
|
|
|
|
|
|
|
if (display_len > fill) {
|
|
|
|
/* The line is too long. Try to wrap it to the next. */
|
|
|
|
break_pos = break_line(current->data + indent_len,
|
|
|
|
fill - strnlenpt(current->data, indent_len), TRUE);
|
|
|
|
if (break_pos == -1 || break_pos + indent_len == line_len)
|
|
|
|
/* We can't break the line, or don't need to, so
|
|
|
|
* just go on to the next. */
|
|
|
|
goto continue_loc;
|
|
|
|
break_pos += indent_len;
|
|
|
|
assert(break_pos < line_len);
|
|
|
|
if (par_len == 1) {
|
|
|
|
/* There is no next line in this paragraph. We make
|
|
|
|
* a new line and copy text after break_pos into
|
|
|
|
* it. */
|
|
|
|
splice_node(current, make_new_node(current), current->next);
|
|
|
|
/* In a non-quoted paragraph, we copy the indent
|
|
|
|
* only if AUTOINDENT is turned on. */
|
2004-05-17 20:11:18 +04:00
|
|
|
if (quote_len == 0
|
2003-02-12 06:21:45 +03:00
|
|
|
#ifndef NANO_SMALL
|
2004-05-17 20:11:18 +04:00
|
|
|
&& !ISSET(AUTOINDENT)
|
2004-05-13 21:28:03 +04:00
|
|
|
#endif
|
2004-05-17 20:11:18 +04:00
|
|
|
)
|
2004-05-13 21:28:03 +04:00
|
|
|
indent_len = 0;
|
|
|
|
current->next->data = charalloc(indent_len + line_len -
|
|
|
|
break_pos);
|
|
|
|
strncpy(current->next->data, current->data, indent_len);
|
|
|
|
strcpy(current->next->data + indent_len,
|
2002-07-19 05:08:59 +04:00
|
|
|
current->data + break_pos + 1);
|
2004-05-13 21:28:03 +04:00
|
|
|
assert(strlen(current->next->data) ==
|
2002-07-19 05:08:59 +04:00
|
|
|
indent_len + line_len - break_pos - 1);
|
2004-05-13 21:28:03 +04:00
|
|
|
totlines++;
|
|
|
|
totsize += indent_len;
|
|
|
|
par_len++;
|
|
|
|
} else {
|
|
|
|
size_t next_line_len = strlen(current->next->data);
|
2002-07-19 05:08:59 +04:00
|
|
|
|
2004-05-13 21:28:03 +04:00
|
|
|
indent_len = quote_len +
|
2002-07-19 05:08:59 +04:00
|
|
|
indent_length(current->next->data + quote_len);
|
2004-05-13 21:28:03 +04:00
|
|
|
current->next->data = charealloc(current->next->data,
|
2003-04-15 05:15:09 +04:00
|
|
|
next_line_len + line_len - break_pos + 1);
|
2002-07-19 05:08:59 +04:00
|
|
|
|
2004-05-13 21:28:03 +04:00
|
|
|
charmove(current->next->data + indent_len + line_len -
|
|
|
|
break_pos, current->next->data + indent_len,
|
2002-07-19 05:08:59 +04:00
|
|
|
next_line_len - indent_len + 1);
|
2004-05-13 21:28:03 +04:00
|
|
|
strcpy(current->next->data + indent_len,
|
2002-07-19 05:08:59 +04:00
|
|
|
current->data + break_pos + 1);
|
2004-06-25 02:39:24 +04:00
|
|
|
current->next->data[indent_len + line_len -
|
|
|
|
break_pos - 1] = ' ';
|
2002-07-19 05:08:59 +04:00
|
|
|
#ifndef NANO_SMALL
|
2004-05-13 21:28:03 +04:00
|
|
|
if (mark_beginbuf == current->next) {
|
|
|
|
if (mark_beginx < indent_len)
|
|
|
|
mark_beginx = indent_len;
|
|
|
|
mark_beginx += line_len - break_pos;
|
|
|
|
}
|
2002-07-19 05:08:59 +04:00
|
|
|
#endif
|
2004-05-13 21:28:03 +04:00
|
|
|
}
|
2002-07-19 05:08:59 +04:00
|
|
|
#ifndef NANO_SMALL
|
2004-05-13 21:28:03 +04:00
|
|
|
if (mark_beginbuf == current && mark_beginx > break_pos) {
|
|
|
|
mark_beginbuf = current->next;
|
|
|
|
mark_beginx -= break_pos + 1 - indent_len;
|
|
|
|
}
|
2002-07-19 05:08:59 +04:00
|
|
|
#endif
|
2004-05-13 21:28:03 +04:00
|
|
|
null_at(¤t->data, break_pos);
|
2004-07-03 18:15:58 +04:00
|
|
|
|
|
|
|
/* Go to the next line. */
|
2004-05-13 21:28:03 +04:00
|
|
|
current = current->next;
|
|
|
|
} else if (display_len < fill && par_len > 1) {
|
|
|
|
size_t next_line_len;
|
2002-07-19 05:08:59 +04:00
|
|
|
|
2004-05-13 21:28:03 +04:00
|
|
|
indent_len = quote_len +
|
2002-07-19 05:08:59 +04:00
|
|
|
indent_length(current->next->data + quote_len);
|
2004-05-13 21:28:03 +04:00
|
|
|
/* If we can't pull a word from the next line up to this
|
|
|
|
* one, just go on. */
|
|
|
|
if (!breakable(current->next->data + indent_len,
|
|
|
|
fill - display_len - 1))
|
|
|
|
goto continue_loc;
|
|
|
|
|
|
|
|
break_pos = break_line(current->next->data + indent_len,
|
|
|
|
fill - display_len - 1, FALSE);
|
|
|
|
assert(break_pos != -1);
|
|
|
|
|
|
|
|
current->data = charealloc(current->data,
|
|
|
|
line_len + break_pos + 2);
|
|
|
|
current->data[line_len] = ' ';
|
|
|
|
strncpy(current->data + line_len + 1,
|
2002-07-19 05:08:59 +04:00
|
|
|
current->next->data + indent_len, break_pos);
|
2004-05-13 21:28:03 +04:00
|
|
|
current->data[line_len + break_pos + 1] = '\0';
|
2002-07-19 05:08:59 +04:00
|
|
|
#ifndef NANO_SMALL
|
2004-05-13 21:28:03 +04:00
|
|
|
if (mark_beginbuf == current->next) {
|
|
|
|
if (mark_beginx < indent_len + break_pos) {
|
2004-05-24 01:11:14 +04:00
|
|
|
mark_beginbuf = current;
|
2004-05-13 21:28:03 +04:00
|
|
|
if (mark_beginx <= indent_len)
|
|
|
|
mark_beginx = line_len + 1;
|
|
|
|
else
|
2004-05-24 09:52:35 +04:00
|
|
|
mark_beginx = line_len + 1 + mark_beginx -
|
|
|
|
indent_len;
|
2004-05-13 21:28:03 +04:00
|
|
|
} else
|
|
|
|
mark_beginx -= break_pos + 1;
|
|
|
|
}
|
2002-07-19 05:08:59 +04:00
|
|
|
#endif
|
2004-05-13 21:28:03 +04:00
|
|
|
next_line_len = strlen(current->next->data);
|
|
|
|
if (indent_len + break_pos == next_line_len) {
|
|
|
|
filestruct *line = current->next;
|
|
|
|
|
|
|
|
/* Don't destroy edittop! */
|
|
|
|
if (line == edittop)
|
|
|
|
edittop = current;
|
|
|
|
|
|
|
|
unlink_node(line);
|
|
|
|
delete_node(line);
|
|
|
|
totlines--;
|
|
|
|
totsize -= indent_len;
|
|
|
|
current_y--;
|
2004-07-03 09:23:19 +04:00
|
|
|
|
2004-07-03 18:15:58 +04:00
|
|
|
/* Don't go to the next line. Accordingly, don't
|
|
|
|
* allow changing the spacing at the end of the
|
2004-07-03 18:34:03 +04:00
|
|
|
* previous justified line, so that we don't end up
|
|
|
|
* doing it more than once on the same line. */
|
2004-07-03 18:15:58 +04:00
|
|
|
allow_respacing = FALSE;
|
2004-05-13 21:28:03 +04:00
|
|
|
} else {
|
|
|
|
charmove(current->next->data + indent_len,
|
2002-07-19 05:08:59 +04:00
|
|
|
current->next->data + indent_len + break_pos + 1,
|
|
|
|
next_line_len - break_pos - indent_len);
|
2004-05-13 21:28:03 +04:00
|
|
|
null_at(¤t->next->data, next_line_len - break_pos);
|
2004-07-03 09:23:19 +04:00
|
|
|
|
|
|
|
/* Go to the next line. */
|
2004-05-13 21:28:03 +04:00
|
|
|
current = current->next;
|
|
|
|
}
|
|
|
|
} else
|
2002-08-21 20:10:37 +04:00
|
|
|
continue_loc:
|
2004-05-18 00:32:51 +04:00
|
|
|
/* Go to the next line. */
|
2004-05-13 21:28:03 +04:00
|
|
|
current = current->next;
|
2003-04-15 05:15:09 +04:00
|
|
|
|
2004-07-03 18:15:58 +04:00
|
|
|
/* We've moved to the next line after justifying the
|
|
|
|
* current line. If the justified line was not the last
|
|
|
|
* line of the paragraph, add a space to the end of it to
|
|
|
|
* replace the one removed or left out by justify_format().
|
|
|
|
* If it was the last line of the paragraph, and
|
|
|
|
* justify_format() left a space on the end of it, remove
|
|
|
|
* the space. */
|
|
|
|
if (allow_respacing) {
|
2004-05-18 00:32:51 +04:00
|
|
|
size_t prev_line_len = strlen(current->prev->data);
|
2004-06-06 02:09:56 +04:00
|
|
|
|
|
|
|
if (par_len > 1) {
|
|
|
|
current->prev->data = charealloc(current->prev->data,
|
2004-05-18 00:32:51 +04:00
|
|
|
prev_line_len + 2);
|
2004-06-06 02:09:56 +04:00
|
|
|
current->prev->data[prev_line_len] = ' ';
|
|
|
|
current->prev->data[prev_line_len + 1] = '\0';
|
|
|
|
totsize++;
|
|
|
|
} else if (par_len == 1 &&
|
|
|
|
current->prev->data[prev_line_len - 1] == ' ') {
|
|
|
|
current->prev->data = charealloc(current->prev->data,
|
|
|
|
prev_line_len);
|
|
|
|
current->prev->data[prev_line_len - 1] = '\0';
|
|
|
|
totsize--;
|
|
|
|
}
|
2004-05-18 00:32:51 +04:00
|
|
|
}
|
2004-05-13 21:28:03 +04:00
|
|
|
}
|
|
|
|
|
2004-05-18 00:32:51 +04:00
|
|
|
/* We've just justified a paragraph. If we're not justifying the
|
|
|
|
* entire file, break out of the loop. Otherwise, continue the
|
|
|
|
* loop so that we justify all the paragraphs in the file. */
|
2004-05-13 21:28:03 +04:00
|
|
|
if (!full_justify)
|
|
|
|
break;
|
|
|
|
|
|
|
|
} /* while (TRUE) */
|
2000-06-20 06:50:33 +04:00
|
|
|
|
2004-05-18 00:32:51 +04:00
|
|
|
/* We are now done justifying the paragraph or the file, so clean
|
|
|
|
* up. totlines, totsize, and current_y have been maintained above.
|
|
|
|
* Set last_par_line to the new end of the paragraph, update
|
2004-07-23 16:30:40 +04:00
|
|
|
* fileage, and renumber() since edit_refresh() needs the line
|
|
|
|
* numbers to be right (but only do the last two if we actually
|
|
|
|
* justified something). */
|
2004-05-18 00:32:51 +04:00
|
|
|
last_par_line = current->prev;
|
2004-07-23 16:30:40 +04:00
|
|
|
if (first_par_line != NULL) {
|
|
|
|
if (first_par_line->prev == NULL)
|
|
|
|
fileage = first_par_line;
|
|
|
|
renumber(first_par_line);
|
|
|
|
}
|
2004-05-18 00:32:51 +04:00
|
|
|
|
2004-05-17 20:11:18 +04:00
|
|
|
edit_refresh();
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2000-11-27 03:23:41 +03:00
|
|
|
statusbar(_("Can now UnJustify!"));
|
2004-05-13 21:28:03 +04:00
|
|
|
/* Display the shortcut list with UnJustify. */
|
2004-07-01 22:59:52 +04:00
|
|
|
shortcut_init(TRUE);
|
2000-11-28 01:58:23 +03:00
|
|
|
display_main_list();
|
2000-11-27 03:23:41 +03:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
/* Now get a keystroke and see if it's unjustify; if not, unget the
|
2002-09-07 00:35:28 +04:00
|
|
|
* keystroke and return. */
|
2004-07-01 22:59:52 +04:00
|
|
|
kbinput = get_kbinput(edit, &meta_key);
|
|
|
|
|
2003-10-04 00:26:25 +04:00
|
|
|
#ifndef DISABLE_MOUSE
|
2004-07-01 22:59:52 +04:00
|
|
|
/* If it was a mouse click, parse it with do_mouse() and it
|
|
|
|
* might become the unjustify key. Else give it back to the
|
|
|
|
* input stream. */
|
|
|
|
if (kbinput == KEY_MOUSE) {
|
|
|
|
do_mouse();
|
|
|
|
kbinput = get_kbinput(edit, &meta_key);
|
2003-12-24 06:33:09 +03:00
|
|
|
}
|
2004-07-01 22:59:52 +04:00
|
|
|
#endif
|
2001-05-06 06:34:31 +04:00
|
|
|
|
2004-07-01 22:59:52 +04:00
|
|
|
if (meta_key || (kbinput != NANO_UNJUSTIFY_KEY &&
|
|
|
|
kbinput != NANO_UNJUSTIFY_FKEY)) {
|
|
|
|
ungetch(kbinput);
|
|
|
|
if (meta_key)
|
|
|
|
ungetch(NANO_CONTROL_3);
|
2002-07-19 05:08:59 +04:00
|
|
|
placewewant = 0;
|
2001-02-05 21:24:33 +03:00
|
|
|
} else {
|
2004-05-18 00:32:51 +04:00
|
|
|
/* Else restore the justify we just did (ungrateful user!). */
|
|
|
|
filestruct *cutbottom = get_cutbottom();
|
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
current = current_save;
|
|
|
|
current_x = current_x_save;
|
|
|
|
current_y = current_y_save;
|
|
|
|
edittop = edittop_save;
|
|
|
|
|
2004-07-23 16:30:40 +04:00
|
|
|
/* Splice the cutbuffer back into the file, but only if we
|
|
|
|
* actually justified something. */
|
|
|
|
if (first_par_line != NULL) {
|
|
|
|
cutbottom->next = last_par_line->next;
|
|
|
|
cutbottom->next->prev = cutbottom;
|
2004-05-18 00:32:51 +04:00
|
|
|
/* The line numbers after the end of the paragraph have been
|
|
|
|
* changed, so we change them back. */
|
2004-07-23 16:30:40 +04:00
|
|
|
renumber(cutbottom->next);
|
|
|
|
if (first_par_line->prev != NULL) {
|
|
|
|
cutbuffer->prev = first_par_line->prev;
|
|
|
|
cutbuffer->prev->next = cutbuffer;
|
|
|
|
} else
|
|
|
|
fileage = cutbuffer;
|
|
|
|
|
|
|
|
last_par_line->next = NULL;
|
|
|
|
free_filestruct(first_par_line);
|
|
|
|
}
|
2004-05-18 00:32:51 +04:00
|
|
|
|
|
|
|
/* Restore global variables from before the justify. */
|
|
|
|
totsize = totsize_save;
|
|
|
|
totlines = filebot->lineno;
|
2002-07-19 05:08:59 +04:00
|
|
|
#ifndef NANO_SMALL
|
2004-05-18 00:32:51 +04:00
|
|
|
mark_beginbuf = mark_beginbuf_save;
|
|
|
|
mark_beginx = mark_beginx_save;
|
2002-07-19 05:08:59 +04:00
|
|
|
#endif
|
2004-05-18 00:32:51 +04:00
|
|
|
flags = flags_save;
|
2004-05-24 01:11:14 +04:00
|
|
|
if (!ISSET(MODIFIED))
|
2004-05-18 00:32:51 +04:00
|
|
|
titlebar(NULL);
|
2002-07-19 05:08:59 +04:00
|
|
|
edit_refresh();
|
2000-11-27 03:23:41 +03:00
|
|
|
}
|
2004-07-01 22:59:52 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
cutbuffer = cutbuffer_save;
|
2004-05-24 01:11:14 +04:00
|
|
|
/* Note that now cutbottom is invalid, but that's okay. */
|
|
|
|
blank_statusbar();
|
2004-05-13 21:28:03 +04:00
|
|
|
/* Display the shortcut list with UnCut. */
|
2004-07-01 22:59:52 +04:00
|
|
|
shortcut_init(FALSE);
|
2000-11-28 01:59:40 +03:00
|
|
|
display_main_list();
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
2004-05-13 21:28:03 +04:00
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_justify_void(void)
|
2004-05-13 21:28:03 +04:00
|
|
|
{
|
2004-07-02 18:31:03 +04:00
|
|
|
do_justify(FALSE);
|
2004-05-13 21:28:03 +04:00
|
|
|
}
|
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_full_justify(void)
|
2004-05-13 21:28:03 +04:00
|
|
|
{
|
2004-07-02 18:31:03 +04:00
|
|
|
do_justify(TRUE);
|
2004-05-13 21:28:03 +04:00
|
|
|
}
|
2004-04-30 08:49:02 +04:00
|
|
|
#endif /* !DISABLE_JUSTIFY */
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_exit(void)
|
2000-06-06 09:53:49 +04:00
|
|
|
{
|
2002-09-07 00:35:28 +04:00
|
|
|
int i;
|
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
if (!ISSET(MODIFIED))
|
|
|
|
i = 0; /* Pretend the user chose not to save. */
|
2004-07-03 07:09:12 +04:00
|
|
|
else if (ISSET(TEMP_FILE))
|
2002-09-07 00:35:28 +04:00
|
|
|
i = 1;
|
2003-12-24 06:33:09 +03:00
|
|
|
else
|
2004-07-02 18:31:03 +04:00
|
|
|
i = do_yesno(FALSE,
|
|
|
|
_("Save modified buffer (ANSWERING \"No\" WILL DESTROY CHANGES) ? "));
|
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
dump_buffer(fileage);
|
2001-10-22 07:15:31 +04:00
|
|
|
#endif
|
2002-09-07 00:35:28 +04:00
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
if (i == 0 || (i == 1 && do_writeout(TRUE) > 0)) {
|
2002-09-07 00:35:28 +04:00
|
|
|
#ifdef ENABLE_MULTIBUFFER
|
2004-07-02 18:31:03 +04:00
|
|
|
/* Exit only if there are no more open buffers. */
|
|
|
|
if (close_open_file() != 0)
|
2002-09-07 00:35:28 +04:00
|
|
|
#endif
|
2004-05-25 23:41:11 +04:00
|
|
|
finish();
|
2004-07-02 18:31:03 +04:00
|
|
|
} else if (i != 1)
|
2002-09-07 00:35:28 +04:00
|
|
|
statusbar(_("Cancelled"));
|
|
|
|
|
|
|
|
display_main_list();
|
|
|
|
}
|
|
|
|
|
|
|
|
void signal_init(void)
|
|
|
|
{
|
2004-04-07 04:44:35 +04:00
|
|
|
/* Trap SIGINT and SIGQUIT because we want them to do useful
|
|
|
|
* things. */
|
2002-09-07 00:35:28 +04:00
|
|
|
memset(&act, 0, sizeof(struct sigaction));
|
|
|
|
act.sa_handler = SIG_IGN;
|
|
|
|
sigaction(SIGINT, &act, NULL);
|
2004-01-26 23:56:20 +03:00
|
|
|
sigaction(SIGQUIT, &act, NULL);
|
2002-09-07 00:35:28 +04:00
|
|
|
|
2004-04-07 04:44:35 +04:00
|
|
|
/* Trap SIGHUP and SIGTERM because we want to write the file out. */
|
2002-10-17 06:19:31 +04:00
|
|
|
act.sa_handler = handle_hupterm;
|
2002-09-07 00:35:28 +04:00
|
|
|
sigaction(SIGHUP, &act, NULL);
|
2002-10-17 06:19:31 +04:00
|
|
|
sigaction(SIGTERM, &act, NULL);
|
2002-09-07 00:35:28 +04:00
|
|
|
|
2002-03-21 08:07:28 +03:00
|
|
|
#ifndef NANO_SMALL
|
2004-04-07 04:44:35 +04:00
|
|
|
/* Trap SIGWINCH because we want to handle window resizes. */
|
2002-09-07 00:35:28 +04:00
|
|
|
act.sa_handler = handle_sigwinch;
|
|
|
|
sigaction(SIGWINCH, &act, NULL);
|
2004-02-16 23:32:40 +03:00
|
|
|
allow_pending_sigwinch(FALSE);
|
2002-03-21 08:07:28 +03:00
|
|
|
#endif
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2004-05-18 05:20:36 +04:00
|
|
|
/* Trap normal suspend (^Z) so we can handle it ourselves. */
|
2002-09-07 00:35:28 +04:00
|
|
|
if (!ISSET(SUSPEND)) {
|
|
|
|
act.sa_handler = SIG_IGN;
|
|
|
|
sigaction(SIGTSTP, &act, NULL);
|
|
|
|
} else {
|
2004-04-07 04:44:35 +04:00
|
|
|
/* Block all other signals in the suspend and continue handlers.
|
|
|
|
* If we don't do this, other stuff interrupts them! */
|
2002-09-07 00:35:28 +04:00
|
|
|
sigfillset(&act.sa_mask);
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
act.sa_handler = do_suspend;
|
|
|
|
sigaction(SIGTSTP, &act, NULL);
|
2002-05-12 23:52:15 +04:00
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
act.sa_handler = do_cont;
|
|
|
|
sigaction(SIGCONT, &act, NULL);
|
|
|
|
}
|
|
|
|
}
|
2000-09-01 17:32:47 +04:00
|
|
|
|
2004-05-18 05:20:36 +04:00
|
|
|
/* Handler for SIGHUP (hangup) and SIGTERM (terminate). */
|
2002-10-17 06:19:31 +04:00
|
|
|
RETSIGTYPE handle_hupterm(int signal)
|
2002-09-07 00:35:28 +04:00
|
|
|
{
|
2003-02-03 06:32:08 +03:00
|
|
|
die(_("Received SIGHUP or SIGTERM\n"));
|
2002-09-07 00:35:28 +04:00
|
|
|
}
|
2002-06-21 07:20:06 +04:00
|
|
|
|
2004-05-18 05:20:36 +04:00
|
|
|
/* Handler for SIGTSTP (suspend). */
|
2002-09-07 00:35:28 +04:00
|
|
|
RETSIGTYPE do_suspend(int signal)
|
|
|
|
{
|
|
|
|
endwin();
|
2003-02-13 02:54:34 +03:00
|
|
|
printf("\n\n\n\n\n%s\n", _("Use \"fg\" to return to nano"));
|
2002-09-07 00:35:28 +04:00
|
|
|
fflush(stdout);
|
2000-09-01 17:32:47 +04:00
|
|
|
|
2004-05-18 05:20:36 +04:00
|
|
|
/* Restore the old terminal settings. */
|
2002-09-07 00:35:28 +04:00
|
|
|
tcsetattr(0, TCSANOW, &oldterm);
|
2002-02-15 22:17:02 +03:00
|
|
|
|
2003-09-29 11:21:11 +04:00
|
|
|
/* Trap SIGHUP and SIGTERM so we can properly deal with them while
|
2004-05-18 05:20:36 +04:00
|
|
|
* suspended. */
|
2003-09-29 11:21:11 +04:00
|
|
|
act.sa_handler = handle_hupterm;
|
|
|
|
sigaction(SIGHUP, &act, NULL);
|
|
|
|
sigaction(SIGTERM, &act, NULL);
|
|
|
|
|
2004-05-18 05:20:36 +04:00
|
|
|
/* Do what mutt does: send ourselves a SIGSTOP. */
|
2002-09-07 00:35:28 +04:00
|
|
|
kill(0, SIGSTOP);
|
|
|
|
}
|
2002-06-21 07:20:06 +04:00
|
|
|
|
2004-05-18 05:20:36 +04:00
|
|
|
/* Handler for SIGCONT (continue after suspend). */
|
2002-09-07 00:35:28 +04:00
|
|
|
RETSIGTYPE do_cont(int signal)
|
|
|
|
{
|
2002-04-23 14:56:06 +04:00
|
|
|
#ifndef NANO_SMALL
|
2004-05-18 05:20:36 +04:00
|
|
|
/* Perhaps the user resized the window while we slept. Handle it
|
|
|
|
* and update the screen in the process. */
|
2002-09-07 00:35:28 +04:00
|
|
|
handle_sigwinch(0);
|
2004-04-07 04:44:35 +04:00
|
|
|
#else
|
2004-05-18 05:20:36 +04:00
|
|
|
/* Just update the screen. */
|
|
|
|
doupdate();
|
2002-09-07 00:35:28 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
void handle_sigwinch(int s)
|
|
|
|
{
|
|
|
|
const char *tty = ttyname(0);
|
|
|
|
int fd;
|
|
|
|
int result = 0;
|
|
|
|
struct winsize win;
|
|
|
|
|
2002-12-22 19:30:00 +03:00
|
|
|
if (tty == NULL)
|
2002-09-07 00:35:28 +04:00
|
|
|
return;
|
|
|
|
fd = open(tty, O_RDWR);
|
|
|
|
if (fd == -1)
|
|
|
|
return;
|
|
|
|
result = ioctl(fd, TIOCGWINSZ, &win);
|
|
|
|
close(fd);
|
|
|
|
if (result == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Could check whether the COLS or LINES changed, and return
|
|
|
|
* otherwise. EXCEPT, that COLS and LINES are ncurses global
|
|
|
|
* variables, and in some cases ncurses has already updated them.
|
|
|
|
* But not in all cases, argh. */
|
|
|
|
COLS = win.ws_col;
|
|
|
|
LINES = win.ws_row;
|
2003-02-10 05:43:48 +03:00
|
|
|
editwinrows = LINES - 5 + no_help();
|
|
|
|
if (editwinrows < MIN_EDITOR_ROWS || COLS < MIN_EDITOR_COLS)
|
2002-09-07 00:35:28 +04:00
|
|
|
die_too_small();
|
|
|
|
|
|
|
|
#ifndef DISABLE_WRAPJUSTIFY
|
|
|
|
fill = wrap_at;
|
|
|
|
if (fill <= 0)
|
|
|
|
fill += COLS;
|
2003-02-10 05:43:48 +03:00
|
|
|
if (fill < 0)
|
|
|
|
fill = 0;
|
2002-09-07 00:35:28 +04:00
|
|
|
#endif
|
|
|
|
|
2003-06-15 00:41:34 +04:00
|
|
|
hblank = charealloc(hblank, COLS + 1);
|
2002-09-07 00:35:28 +04:00
|
|
|
memset(hblank, ' ', COLS);
|
|
|
|
hblank[COLS] = '\0';
|
|
|
|
|
2004-05-18 05:20:36 +04:00
|
|
|
#ifdef USE_SLANG
|
|
|
|
/* Slang curses emulation brain damage, part 1: If we just do what
|
|
|
|
* curses does here, it'll only work properly if the resize made the
|
|
|
|
* window smaller. Do what mutt does: Leave and immediately reenter
|
|
|
|
* Slang screen management mode. */
|
|
|
|
SLsmg_reset_smg();
|
|
|
|
SLsmg_init_smg();
|
|
|
|
#else
|
|
|
|
/* Do the equivalent of what Minimum Profit does: Leave and
|
|
|
|
* immediately reenter curses mode. */
|
|
|
|
endwin();
|
|
|
|
refresh();
|
|
|
|
#endif
|
2002-09-07 00:35:28 +04:00
|
|
|
|
2004-07-27 20:46:35 +04:00
|
|
|
/* Restore the terminal to its previous state. */
|
|
|
|
terminal_init();
|
|
|
|
|
2004-05-18 05:20:36 +04:00
|
|
|
/* Do the equivalent of what both mutt and Minimum Profit do:
|
|
|
|
* Reinitialize all the windows based on the new screen
|
|
|
|
* dimensions. */
|
|
|
|
window_init();
|
|
|
|
|
|
|
|
/* Redraw the contents of the windows that need it. */
|
2002-09-07 00:35:28 +04:00
|
|
|
blank_statusbar();
|
2004-05-18 05:20:36 +04:00
|
|
|
display_main_list();
|
2002-09-07 00:35:28 +04:00
|
|
|
total_refresh();
|
|
|
|
|
2004-01-30 07:20:28 +03:00
|
|
|
/* Turn cursor back on for sure. */
|
2002-09-07 00:35:28 +04:00
|
|
|
curs_set(1);
|
|
|
|
|
2004-05-28 21:23:33 +04:00
|
|
|
/* Reset all the input routines that rely on character sequences. */
|
|
|
|
reset_kbinput();
|
|
|
|
|
2004-01-30 07:20:28 +03:00
|
|
|
/* Jump back to the main loop. */
|
2002-09-07 00:35:28 +04:00
|
|
|
siglongjmp(jmpbuf, 1);
|
|
|
|
}
|
2004-02-16 23:32:40 +03:00
|
|
|
|
|
|
|
void allow_pending_sigwinch(int allow)
|
|
|
|
{
|
|
|
|
sigset_t winch;
|
|
|
|
sigemptyset(&winch);
|
|
|
|
sigaddset(&winch, SIGWINCH);
|
|
|
|
if (allow)
|
|
|
|
sigprocmask(SIG_UNBLOCK, &winch, NULL);
|
|
|
|
else
|
|
|
|
sigprocmask(SIG_BLOCK, &winch, NULL);
|
|
|
|
}
|
2002-04-23 14:56:06 +04:00
|
|
|
#endif /* !NANO_SMALL */
|
2002-06-21 07:20:06 +04:00
|
|
|
|
2002-04-23 14:56:06 +04:00
|
|
|
#ifndef NANO_SMALL
|
2002-08-21 20:10:37 +04:00
|
|
|
void do_toggle(const toggle *which)
|
2000-09-01 17:32:47 +04:00
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
int enabled;
|
2000-09-02 22:44:21 +04:00
|
|
|
|
2001-06-14 06:54:22 +04:00
|
|
|
/* Even easier! */
|
2002-02-15 22:17:02 +03:00
|
|
|
TOGGLE(which->flag);
|
2000-09-13 03:02:49 +04:00
|
|
|
|
2002-02-15 22:17:02 +03:00
|
|
|
switch (which->val) {
|
2000-09-01 17:32:47 +04:00
|
|
|
case TOGGLE_SUSPEND_KEY:
|
|
|
|
signal_init();
|
|
|
|
break;
|
2003-10-04 00:26:25 +04:00
|
|
|
#ifndef DISABLE_MOUSE
|
2000-09-01 17:32:47 +04:00
|
|
|
case TOGGLE_MOUSE_KEY:
|
|
|
|
mouse_init();
|
|
|
|
break;
|
2002-12-22 19:30:00 +03:00
|
|
|
#endif
|
2000-09-01 17:32:47 +04:00
|
|
|
case TOGGLE_NOHELP_KEY:
|
2004-05-18 05:20:36 +04:00
|
|
|
blank_statusbar();
|
|
|
|
blank_bottombars();
|
2000-09-13 03:02:49 +04:00
|
|
|
wrefresh(bottomwin);
|
|
|
|
window_init();
|
|
|
|
edit_refresh();
|
|
|
|
display_main_list();
|
2000-09-01 17:32:47 +04:00
|
|
|
break;
|
2001-09-23 06:45:27 +04:00
|
|
|
case TOGGLE_DOS_KEY:
|
|
|
|
UNSET(MAC_FILE);
|
|
|
|
break;
|
|
|
|
case TOGGLE_MAC_KEY:
|
|
|
|
UNSET(DOS_FILE);
|
|
|
|
break;
|
2002-12-22 19:30:00 +03:00
|
|
|
#ifdef ENABLE_COLOR
|
2002-10-13 22:43:45 +04:00
|
|
|
case TOGGLE_SYNTAX_KEY:
|
|
|
|
edit_refresh();
|
2002-12-22 19:30:00 +03:00
|
|
|
break;
|
2004-05-29 20:25:30 +04:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_NANORC
|
|
|
|
case TOGGLE_WHITESPACE_KEY:
|
|
|
|
edit_refresh();
|
|
|
|
break;
|
2002-12-22 19:30:00 +03:00
|
|
|
#endif
|
2000-09-01 17:32:47 +04:00
|
|
|
}
|
2000-09-13 03:02:49 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
/* We are assuming here that shortcut_init() above didn't free and
|
|
|
|
* reallocate the toggles. */
|
|
|
|
enabled = ISSET(which->flag);
|
|
|
|
if (which->val == TOGGLE_NOHELP_KEY || which->val == TOGGLE_WRAP_KEY)
|
|
|
|
enabled = !enabled;
|
|
|
|
statusbar("%s %s", which->desc,
|
|
|
|
enabled ? _("enabled") : _("disabled"));
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
2002-04-23 14:56:06 +04:00
|
|
|
#endif /* !NANO_SMALL */
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2004-05-18 05:20:36 +04:00
|
|
|
void disable_signals(void)
|
|
|
|
{
|
|
|
|
struct termios term;
|
|
|
|
|
|
|
|
tcgetattr(0, &term);
|
|
|
|
term.c_lflag &= ~ISIG;
|
|
|
|
tcsetattr(0, TCSANOW, &term);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
void enable_signals(void)
|
|
|
|
{
|
|
|
|
struct termios term;
|
|
|
|
|
|
|
|
tcgetattr(0, &term);
|
|
|
|
term.c_lflag |= ISIG;
|
|
|
|
tcsetattr(0, TCSANOW, &term);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void disable_flow_control(void)
|
|
|
|
{
|
|
|
|
struct termios term;
|
|
|
|
|
|
|
|
tcgetattr(0, &term);
|
|
|
|
term.c_iflag &= ~(IXON|IXOFF);
|
|
|
|
tcsetattr(0, TCSANOW, &term);
|
|
|
|
}
|
|
|
|
|
|
|
|
void enable_flow_control(void)
|
|
|
|
{
|
|
|
|
struct termios term;
|
|
|
|
|
|
|
|
tcgetattr(0, &term);
|
|
|
|
term.c_iflag |= (IXON|IXOFF);
|
|
|
|
tcsetattr(0, TCSANOW, &term);
|
|
|
|
}
|
|
|
|
|
2004-07-27 20:46:35 +04:00
|
|
|
/* Set up the terminal state. Put the terminal in cbreak mode (read one
|
|
|
|
* character at a time and interpret the special control keys), disable
|
|
|
|
* translation of carriage return (^M) into newline (^J) so that we can
|
|
|
|
* tell the difference between the Enter key and Ctrl-J, and disable
|
|
|
|
* echoing of characters as they're typed. Finally, disable
|
|
|
|
* interpretation of the special control keys, and if we're not in
|
|
|
|
* preserve mode, disable interpretation of the flow control characters
|
|
|
|
* too. */
|
|
|
|
void terminal_init(void)
|
|
|
|
{
|
|
|
|
cbreak();
|
|
|
|
nonl();
|
|
|
|
noecho();
|
|
|
|
disable_signals();
|
|
|
|
if (!ISSET(PRESERVE))
|
|
|
|
disable_flow_control();
|
|
|
|
}
|
|
|
|
|
2000-06-06 09:53:49 +04:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int optchr;
|
2002-06-13 04:40:19 +04:00
|
|
|
int startline = 0; /* Line to try and start at */
|
2004-06-13 01:03:14 +04:00
|
|
|
int fill_flag_used = FALSE; /* Was the fill option used? */
|
2002-07-19 05:08:59 +04:00
|
|
|
const shortcut *s;
|
2004-06-13 01:03:14 +04:00
|
|
|
int keyhandled = FALSE; /* Have we handled the keystroke yet? */
|
2004-01-10 01:38:09 +03:00
|
|
|
int kbinput; /* Input from keyboard */
|
2004-03-20 00:46:34 +03:00
|
|
|
int meta_key;
|
2003-02-13 03:52:49 +03:00
|
|
|
|
2002-03-06 18:27:44 +03:00
|
|
|
#ifndef NANO_SMALL
|
2002-07-19 05:08:59 +04:00
|
|
|
const toggle *t;
|
2002-03-06 18:27:44 +03:00
|
|
|
#endif
|
2000-06-06 09:53:49 +04:00
|
|
|
#ifdef HAVE_GETOPT_LONG
|
2002-12-22 19:30:00 +03:00
|
|
|
const struct option long_options[] = {
|
2002-06-29 02:45:14 +04:00
|
|
|
{"help", 0, 0, 'h'},
|
|
|
|
#ifdef ENABLE_MULTIBUFFER
|
|
|
|
{"multibuffer", 0, 0, 'F'},
|
2002-07-19 05:08:59 +04:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_NANORC
|
2003-09-07 01:44:37 +04:00
|
|
|
#ifndef NANO_SMALL
|
2003-01-17 02:44:46 +03:00
|
|
|
{"historylog", 0, 0, 'H'},
|
2003-09-07 01:44:37 +04:00
|
|
|
#endif
|
2002-07-19 05:08:59 +04:00
|
|
|
{"ignorercfiles", 0, 0, 'I'},
|
2002-06-29 02:45:14 +04:00
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_JUSTIFY
|
|
|
|
{"quotestr", 1, 0, 'Q'},
|
|
|
|
#endif
|
2000-09-06 17:39:17 +04:00
|
|
|
#ifdef HAVE_REGEX_H
|
2000-10-26 05:44:42 +04:00
|
|
|
{"regexp", 0, 0, 'R'},
|
2000-07-07 06:35:34 +04:00
|
|
|
#endif
|
2002-06-29 02:45:14 +04:00
|
|
|
{"tabsize", 1, 0, 'T'},
|
2000-06-06 09:53:49 +04:00
|
|
|
{"version", 0, 0, 'V'},
|
2002-06-29 02:45:14 +04:00
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
{"syntax", 1, 0, 'Y'},
|
2001-05-21 16:56:25 +04:00
|
|
|
#endif
|
2002-06-29 02:45:14 +04:00
|
|
|
{"const", 0, 0, 'c'},
|
2003-08-17 06:48:43 +04:00
|
|
|
{"rebinddelete", 0, 0, 'd'},
|
2002-06-29 02:45:14 +04:00
|
|
|
{"nofollow", 0, 0, 'l'},
|
2003-10-04 00:26:25 +04:00
|
|
|
#ifndef DISABLE_MOUSE
|
2000-06-06 09:53:49 +04:00
|
|
|
{"mouse", 0, 0, 'm'},
|
2002-12-22 19:30:00 +03:00
|
|
|
#endif
|
2001-09-19 07:19:43 +04:00
|
|
|
#ifndef DISABLE_OPERATINGDIR
|
|
|
|
{"operatingdir", 1, 0, 'o'},
|
|
|
|
#endif
|
2003-01-06 02:35:44 +03:00
|
|
|
{"preserve", 0, 0, 'p'},
|
2002-06-29 02:45:14 +04:00
|
|
|
#ifndef DISABLE_WRAPJUSTIFY
|
|
|
|
{"fill", 1, 0, 'r'},
|
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_SPELLER
|
|
|
|
{"speller", 1, 0, 's'},
|
2001-07-11 06:08:33 +04:00
|
|
|
#endif
|
2002-06-29 02:45:14 +04:00
|
|
|
{"tempfile", 0, 0, 't'},
|
|
|
|
{"view", 0, 0, 'v'},
|
2002-10-17 06:19:31 +04:00
|
|
|
#ifndef DISABLE_WRAPPING
|
2002-06-29 02:45:14 +04:00
|
|
|
{"nowrap", 0, 0, 'w'},
|
2002-10-17 06:19:31 +04:00
|
|
|
#endif
|
2002-06-29 02:45:14 +04:00
|
|
|
{"nohelp", 0, 0, 'x'},
|
|
|
|
{"suspend", 0, 0, 'z'},
|
2001-09-22 23:02:04 +04:00
|
|
|
#ifndef NANO_SMALL
|
2004-05-23 00:15:20 +04:00
|
|
|
{"smarthome", 0, 0, 'A'},
|
2002-06-29 02:45:14 +04:00
|
|
|
{"backup", 0, 0, 'B'},
|
|
|
|
{"dos", 0, 0, 'D'},
|
2004-02-28 19:24:31 +03:00
|
|
|
{"backupdir", 1, 0, 'E'},
|
2002-06-29 02:45:14 +04:00
|
|
|
{"mac", 0, 0, 'M'},
|
|
|
|
{"noconvert", 0, 0, 'N'},
|
2001-09-22 23:02:04 +04:00
|
|
|
{"smooth", 0, 0, 'S'},
|
2004-04-30 08:49:02 +04:00
|
|
|
{"restricted", 0, 0, 'Z'},
|
2002-06-29 02:45:14 +04:00
|
|
|
{"autoindent", 0, 0, 'i'},
|
|
|
|
{"cut", 0, 0, 'k'},
|
2002-05-04 08:23:30 +04:00
|
|
|
#endif
|
2000-06-06 09:53:49 +04:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
setlocale(LC_ALL, "");
|
2004-07-27 19:46:58 +04:00
|
|
|
#ifdef ENABLE_NLS
|
2000-06-06 09:53:49 +04:00
|
|
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
|
|
|
textdomain(PACKAGE);
|
|
|
|
#endif
|
|
|
|
|
2003-01-13 04:35:15 +03:00
|
|
|
#if !defined(ENABLE_NANORC) && defined(DISABLE_ROOTWRAP) && !defined(DISABLE_WRAPPING)
|
2002-10-25 20:08:53 +04:00
|
|
|
/* if we don't have rcfile support, we're root, and
|
|
|
|
--disable-wrapping-as-root is used, turn wrapping off */
|
2004-03-04 09:33:52 +03:00
|
|
|
if (geteuid() == NANO_ROOT_UID)
|
2002-10-25 20:08:53 +04:00
|
|
|
SET(NO_WRAP);
|
|
|
|
#endif
|
2001-04-18 08:28:54 +04:00
|
|
|
|
2000-06-06 09:53:49 +04:00
|
|
|
#ifdef HAVE_GETOPT_LONG
|
2004-05-23 00:15:20 +04:00
|
|
|
while ((optchr = getopt_long(argc, argv, "h?ABDE:FHIMNQ:RST:VY:Zabcdefgijklmo:pr:s:tvwxz",
|
2003-12-24 06:33:09 +03:00
|
|
|
long_options, NULL)) != -1) {
|
2000-06-06 09:53:49 +04:00
|
|
|
#else
|
2001-04-12 07:01:53 +04:00
|
|
|
while ((optchr =
|
2004-05-23 00:15:20 +04:00
|
|
|
getopt(argc, argv, "h?ABDE:FHIMNQ:RST:VY:Zabcdefgijklmo:pr:s:tvwxz")) != -1) {
|
2000-06-06 09:53:49 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (optchr) {
|
2001-07-11 06:08:33 +04:00
|
|
|
|
2002-06-29 02:45:14 +04:00
|
|
|
case 'a':
|
|
|
|
case 'b':
|
|
|
|
case 'e':
|
|
|
|
case 'f':
|
|
|
|
case 'g':
|
|
|
|
case 'j':
|
|
|
|
/* Pico compatibility flags */
|
|
|
|
break;
|
2001-09-22 04:42:10 +04:00
|
|
|
#ifndef NANO_SMALL
|
2004-05-23 00:15:20 +04:00
|
|
|
case 'A':
|
|
|
|
SET(SMART_HOME);
|
|
|
|
break;
|
2002-06-29 02:45:14 +04:00
|
|
|
case 'B':
|
|
|
|
SET(BACKUP_FILE);
|
|
|
|
break;
|
2001-09-22 04:42:10 +04:00
|
|
|
case 'D':
|
|
|
|
SET(DOS_FILE);
|
|
|
|
break;
|
2004-02-28 19:24:31 +03:00
|
|
|
case 'E':
|
|
|
|
backup_dir = mallocstrcpy(backup_dir, optarg);
|
|
|
|
break;
|
2001-09-22 04:42:10 +04:00
|
|
|
#endif
|
2001-07-14 23:32:47 +04:00
|
|
|
#ifdef ENABLE_MULTIBUFFER
|
2001-07-16 00:25:33 +04:00
|
|
|
case 'F':
|
2001-07-14 23:32:47 +04:00
|
|
|
SET(MULTIBUFFER);
|
2001-07-11 06:08:33 +04:00
|
|
|
break;
|
2002-07-19 05:08:59 +04:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_NANORC
|
2003-09-07 01:44:37 +04:00
|
|
|
#ifndef NANO_SMALL
|
2003-01-17 02:44:46 +03:00
|
|
|
case 'H':
|
|
|
|
SET(HISTORYLOG);
|
|
|
|
break;
|
2003-09-07 01:44:37 +04:00
|
|
|
#endif
|
2002-07-19 05:08:59 +04:00
|
|
|
case 'I':
|
2003-01-13 04:35:15 +03:00
|
|
|
SET(NO_RCFILE);
|
|
|
|
break;
|
2001-07-11 06:08:33 +04:00
|
|
|
#endif
|
2001-09-22 08:20:25 +04:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
case 'M':
|
|
|
|
SET(MAC_FILE);
|
|
|
|
break;
|
2002-02-15 22:17:02 +03:00
|
|
|
case 'N':
|
|
|
|
SET(NO_CONVERT);
|
2000-06-20 03:19:07 +04:00
|
|
|
break;
|
2002-03-04 01:36:36 +03:00
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_JUSTIFY
|
2002-12-22 19:30:00 +03:00
|
|
|
case 'Q':
|
2003-01-13 04:35:15 +03:00
|
|
|
quotestr = mallocstrcpy(quotestr, optarg);
|
2002-03-04 01:36:36 +03:00
|
|
|
break;
|
2002-02-15 22:17:02 +03:00
|
|
|
#endif
|
2000-09-06 17:39:17 +04:00
|
|
|
#ifdef HAVE_REGEX_H
|
2000-07-07 05:49:52 +04:00
|
|
|
case 'R':
|
|
|
|
SET(USE_REGEXP);
|
|
|
|
break;
|
2001-09-22 23:02:04 +04:00
|
|
|
#endif
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
case 'S':
|
|
|
|
SET(SMOOTHSCROLL);
|
|
|
|
break;
|
2000-07-07 06:35:34 +04:00
|
|
|
#endif
|
2002-02-15 22:17:02 +03:00
|
|
|
case 'T':
|
2004-07-12 20:07:14 +04:00
|
|
|
if (parse_num(optarg, &tabsize) == -1 || tabsize <= 0) {
|
|
|
|
fprintf(stderr, _("Requested tab size %s invalid"), optarg);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
exit(1);
|
2002-02-15 22:17:02 +03:00
|
|
|
}
|
|
|
|
break;
|
2000-06-06 09:53:49 +04:00
|
|
|
case 'V':
|
|
|
|
version();
|
|
|
|
exit(0);
|
2002-05-04 08:23:30 +04:00
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
case 'Y':
|
|
|
|
syntaxstr = mallocstrcpy(syntaxstr, optarg);
|
|
|
|
break;
|
|
|
|
#endif
|
2004-04-30 08:49:02 +04:00
|
|
|
case 'Z':
|
|
|
|
SET(RESTRICTED);
|
|
|
|
break;
|
2000-06-06 09:53:49 +04:00
|
|
|
case 'c':
|
|
|
|
SET(CONSTUPDATE);
|
|
|
|
break;
|
2003-08-17 06:48:43 +04:00
|
|
|
case 'd':
|
|
|
|
SET(REBIND_DELETE);
|
|
|
|
break;
|
2001-09-17 17:48:00 +04:00
|
|
|
#ifndef NANO_SMALL
|
2000-06-06 09:53:49 +04:00
|
|
|
case 'i':
|
|
|
|
SET(AUTOINDENT);
|
|
|
|
break;
|
2000-07-12 06:09:17 +04:00
|
|
|
case 'k':
|
|
|
|
SET(CUT_TO_END);
|
|
|
|
break;
|
2000-07-12 22:14:51 +04:00
|
|
|
#endif
|
2000-06-06 09:53:49 +04:00
|
|
|
case 'l':
|
2002-12-22 19:30:00 +03:00
|
|
|
SET(NOFOLLOW_SYMLINKS);
|
2000-06-06 09:53:49 +04:00
|
|
|
break;
|
2003-10-04 00:26:25 +04:00
|
|
|
#ifndef DISABLE_MOUSE
|
2000-06-06 09:53:49 +04:00
|
|
|
case 'm':
|
|
|
|
SET(USE_MOUSE);
|
|
|
|
break;
|
2002-12-22 19:30:00 +03:00
|
|
|
#endif
|
2001-09-19 07:19:43 +04:00
|
|
|
#ifndef DISABLE_OPERATINGDIR
|
|
|
|
case 'o':
|
2002-05-06 03:03:54 +04:00
|
|
|
operating_dir = mallocstrcpy(operating_dir, optarg);
|
2001-09-19 07:19:43 +04:00
|
|
|
break;
|
|
|
|
#endif
|
2000-06-06 09:53:49 +04:00
|
|
|
case 'p':
|
2003-01-06 02:35:44 +03:00
|
|
|
SET(PRESERVE);
|
2000-06-06 09:53:49 +04:00
|
|
|
break;
|
2001-05-21 16:56:25 +04:00
|
|
|
#ifndef DISABLE_WRAPJUSTIFY
|
2002-07-19 05:08:59 +04:00
|
|
|
case 'r':
|
2004-07-12 20:07:14 +04:00
|
|
|
if (parse_num(optarg, &wrap_at) == -1) {
|
|
|
|
fprintf(stderr, _("Requested fill size %s invalid"), optarg);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
exit(1);
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
2004-06-13 01:03:14 +04:00
|
|
|
fill_flag_used = TRUE;
|
2000-06-06 09:53:49 +04:00
|
|
|
break;
|
2001-05-21 16:56:25 +04:00
|
|
|
#endif
|
2001-01-12 10:51:05 +03:00
|
|
|
#ifndef DISABLE_SPELLER
|
2000-06-06 09:53:49 +04:00
|
|
|
case 's':
|
2002-05-06 03:03:54 +04:00
|
|
|
alt_speller = mallocstrcpy(alt_speller, optarg);
|
2000-06-06 09:53:49 +04:00
|
|
|
break;
|
2001-01-12 10:51:05 +03:00
|
|
|
#endif
|
2000-06-06 09:53:49 +04:00
|
|
|
case 't':
|
2004-07-03 07:09:12 +04:00
|
|
|
SET(TEMP_FILE);
|
2000-06-06 09:53:49 +04:00
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
SET(VIEW_MODE);
|
|
|
|
break;
|
2003-01-02 19:32:20 +03:00
|
|
|
#ifndef DISABLE_WRAPPING
|
2002-12-22 19:30:00 +03:00
|
|
|
case 'w':
|
2000-06-06 09:53:49 +04:00
|
|
|
SET(NO_WRAP);
|
|
|
|
break;
|
2002-12-22 19:30:00 +03:00
|
|
|
#endif
|
2000-06-06 09:53:49 +04:00
|
|
|
case 'x':
|
|
|
|
SET(NO_HELP);
|
|
|
|
break;
|
|
|
|
case 'z':
|
|
|
|
SET(SUSPEND);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-29 05:20:17 +04:00
|
|
|
/* If the executable filename starts with 'r', we use restricted
|
|
|
|
* mode. */
|
2004-04-30 08:49:02 +04:00
|
|
|
if (*(tail(argv[0])) == 'r')
|
|
|
|
SET(RESTRICTED);
|
|
|
|
|
2004-05-29 05:20:17 +04:00
|
|
|
/* If we're using restricted mode, disable suspending, backups, and
|
|
|
|
* reading rcfiles, since they all would allow reading from or
|
|
|
|
* writing to files not specified on the command line. */
|
2004-04-30 08:49:02 +04:00
|
|
|
if (ISSET(RESTRICTED)) {
|
|
|
|
UNSET(SUSPEND);
|
|
|
|
UNSET(BACKUP_FILE);
|
|
|
|
SET(NO_RCFILE);
|
|
|
|
}
|
|
|
|
|
2003-01-13 04:35:15 +03:00
|
|
|
/* We've read through the command line options. Now back up the flags
|
|
|
|
and values that are set, and read the rcfile(s). If the values
|
|
|
|
haven't changed afterward, restore the backed-up values. */
|
|
|
|
#ifdef ENABLE_NANORC
|
|
|
|
if (!ISSET(NO_RCFILE)) {
|
|
|
|
#ifndef DISABLE_OPERATINGDIR
|
|
|
|
char *operating_dir_cpy = operating_dir;
|
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_WRAPPING
|
2004-07-12 20:07:14 +04:00
|
|
|
ssize_t wrap_at_cpy = wrap_at;
|
2003-01-13 04:35:15 +03:00
|
|
|
#endif
|
2004-02-28 19:24:31 +03:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
char *backup_dir_cpy = backup_dir;
|
|
|
|
#endif
|
2003-01-13 04:35:15 +03:00
|
|
|
#ifndef DISABLE_JUSTIFY
|
|
|
|
char *quotestr_cpy = quotestr;
|
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_SPELLER
|
|
|
|
char *alt_speller_cpy = alt_speller;
|
|
|
|
#endif
|
2004-07-12 20:07:14 +04:00
|
|
|
ssize_t tabsize_cpy = tabsize;
|
2003-01-13 04:35:15 +03:00
|
|
|
long flags_cpy = flags;
|
|
|
|
|
2003-02-05 05:39:34 +03:00
|
|
|
#ifndef DISABLE_OPERATINGDIR
|
2003-01-13 04:35:15 +03:00
|
|
|
operating_dir = NULL;
|
2003-02-05 05:39:34 +03:00
|
|
|
#endif
|
2004-02-28 19:24:31 +03:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
backup_dir = NULL;
|
|
|
|
#endif
|
2003-02-05 05:39:34 +03:00
|
|
|
#ifndef DISABLE_JUSTIFY
|
2003-01-13 04:35:15 +03:00
|
|
|
quotestr = NULL;
|
2003-02-05 05:39:34 +03:00
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_SPELLER
|
2003-01-13 04:35:15 +03:00
|
|
|
alt_speller = NULL;
|
2003-02-05 05:39:34 +03:00
|
|
|
#endif
|
2003-01-13 04:35:15 +03:00
|
|
|
|
|
|
|
do_rcfile();
|
|
|
|
|
|
|
|
#ifndef DISABLE_OPERATINGDIR
|
|
|
|
if (operating_dir_cpy != NULL) {
|
|
|
|
free(operating_dir);
|
|
|
|
operating_dir = operating_dir_cpy;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_WRAPPING
|
|
|
|
if (fill_flag_used)
|
|
|
|
wrap_at = wrap_at_cpy;
|
|
|
|
#endif
|
2004-02-28 19:24:31 +03:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
if (backup_dir_cpy != NULL) {
|
|
|
|
free(backup_dir);
|
|
|
|
backup_dir = backup_dir_cpy;
|
|
|
|
}
|
|
|
|
#endif
|
2003-01-13 04:35:15 +03:00
|
|
|
#ifndef DISABLE_JUSTIFY
|
|
|
|
if (quotestr_cpy != NULL) {
|
|
|
|
free(quotestr);
|
|
|
|
quotestr = quotestr_cpy;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_SPELLER
|
|
|
|
if (alt_speller_cpy != NULL) {
|
|
|
|
free(alt_speller);
|
|
|
|
alt_speller = alt_speller_cpy;
|
|
|
|
}
|
|
|
|
#endif
|
2004-07-18 22:13:54 +04:00
|
|
|
if (tabsize_cpy != -1)
|
2003-01-13 04:35:15 +03:00
|
|
|
tabsize = tabsize_cpy;
|
|
|
|
flags |= flags_cpy;
|
|
|
|
}
|
|
|
|
#if defined(DISABLE_ROOTWRAP) && !defined(DISABLE_WRAPPING)
|
2004-03-04 09:33:52 +03:00
|
|
|
else if (geteuid() == NANO_ROOT_UID)
|
2003-01-13 04:35:15 +03:00
|
|
|
SET(NO_WRAP);
|
|
|
|
#endif
|
|
|
|
#endif /* ENABLE_NANORC */
|
|
|
|
|
2003-03-11 06:50:40 +03:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
history_init();
|
|
|
|
#ifdef ENABLE_NANORC
|
|
|
|
if (!ISSET(NO_RCFILE) && ISSET(HISTORYLOG))
|
|
|
|
load_history();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2004-02-28 19:24:31 +03:00
|
|
|
#ifndef NANO_SMALL
|
2004-05-29 03:45:25 +04:00
|
|
|
/* Set up the backup directory (unless we're using restricted mode,
|
2004-05-29 05:20:17 +04:00
|
|
|
* in which case backups are disabled, since they would allow
|
|
|
|
* reading from or writing to files not specified on the command
|
|
|
|
* line). This entails making sure it exists and is a directory, so
|
|
|
|
* that backup files will be saved there. */
|
2004-05-29 03:45:25 +04:00
|
|
|
if (!ISSET(RESTRICTED))
|
|
|
|
init_backup_dir();
|
2004-02-28 19:24:31 +03:00
|
|
|
#endif
|
|
|
|
|
2002-09-13 22:14:04 +04:00
|
|
|
#ifndef DISABLE_OPERATINGDIR
|
2003-01-13 04:35:15 +03:00
|
|
|
/* Set up the operating directory. This entails chdir()ing there,
|
2004-05-29 03:45:25 +04:00
|
|
|
* so that file reads and writes will be based there. */
|
2002-09-13 22:14:04 +04:00
|
|
|
init_operating_dir();
|
|
|
|
#endif
|
|
|
|
|
2003-01-13 04:35:15 +03:00
|
|
|
#ifndef DISABLE_JUSTIFY
|
2004-05-29 20:38:57 +04:00
|
|
|
if (punct == NULL)
|
2004-06-13 01:03:14 +04:00
|
|
|
punct = mallocstrcpy(punct, ".?!");
|
2004-05-29 20:38:57 +04:00
|
|
|
|
|
|
|
if (brackets == NULL)
|
2004-06-13 01:03:14 +04:00
|
|
|
brackets = mallocstrcpy(brackets, "'\")}]>");
|
2004-05-29 20:38:57 +04:00
|
|
|
|
2003-01-13 04:35:15 +03:00
|
|
|
if (quotestr == NULL)
|
2004-06-13 01:03:14 +04:00
|
|
|
quotestr = mallocstrcpy(NULL,
|
2003-01-13 04:35:15 +03:00
|
|
|
#ifdef HAVE_REGEX_H
|
2004-06-13 01:03:14 +04:00
|
|
|
"^([ \t]*[|>:}#])+"
|
2003-01-13 04:35:15 +03:00
|
|
|
#else
|
2004-06-13 01:03:14 +04:00
|
|
|
"> "
|
2003-01-13 04:35:15 +03:00
|
|
|
#endif
|
2004-06-13 01:03:14 +04:00
|
|
|
);
|
2003-01-13 04:35:15 +03:00
|
|
|
#endif /* !DISABLE_JUSTIFY */
|
2004-02-28 19:24:31 +03:00
|
|
|
|
2004-05-29 02:42:41 +04:00
|
|
|
#ifndef DISABLE_SPELLER
|
|
|
|
/* If we don't have an alternative spell checker after reading the
|
2004-05-29 05:20:17 +04:00
|
|
|
* command line and/or rcfile(s), check $SPELL for one, as Pico
|
2004-05-29 03:45:25 +04:00
|
|
|
* does (unless we're using restricted mode, in which case spell
|
2004-05-29 05:20:17 +04:00
|
|
|
* checking is disabled, since it would allow reading from or
|
|
|
|
* writing to files not specified on the command line). */
|
2004-05-29 03:45:25 +04:00
|
|
|
if (!ISSET(RESTRICTED) && alt_speller == NULL) {
|
2004-05-29 02:42:41 +04:00
|
|
|
char *spellenv = getenv("SPELL");
|
|
|
|
if (spellenv != NULL)
|
|
|
|
alt_speller = mallocstrcpy(NULL, spellenv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-05-29 20:25:30 +04:00
|
|
|
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
|
|
|
|
if (whitespace == NULL)
|
|
|
|
whitespace = mallocstrcpy(NULL, " ");
|
|
|
|
#endif
|
|
|
|
|
2003-01-13 04:35:15 +03:00
|
|
|
if (tabsize == -1)
|
|
|
|
tabsize = 8;
|
|
|
|
|
2002-06-13 04:40:19 +04:00
|
|
|
/* Clear the filename we'll be using */
|
|
|
|
filename = charalloc(1);
|
|
|
|
filename[0] = '\0';
|
|
|
|
|
2003-01-13 04:35:15 +03:00
|
|
|
/* If there's a +LINE flag, it is the first non-option argument. */
|
|
|
|
if (0 < optind && optind < argc && argv[optind][0] == '+') {
|
|
|
|
startline = atoi(&argv[optind][1]);
|
|
|
|
optind++;
|
|
|
|
}
|
|
|
|
if (0 < optind && optind < argc)
|
|
|
|
filename = mallocstrcpy(filename, argv[optind]);
|
2000-06-06 09:53:49 +04:00
|
|
|
|
|
|
|
/* See if there's a non-option in argv (first non-option is the
|
|
|
|
filename, if +LINE is not given) */
|
2002-06-13 04:40:19 +04:00
|
|
|
if (argc > 1 && argc > optind) {
|
2000-06-06 09:53:49 +04:00
|
|
|
/* Look for the +line flag... */
|
|
|
|
if (argv[optind][0] == '+') {
|
|
|
|
startline = atoi(&argv[optind][1]);
|
|
|
|
optind++;
|
2002-07-19 05:08:59 +04:00
|
|
|
if (argc > optind)
|
2000-12-14 16:56:28 +03:00
|
|
|
filename = mallocstrcpy(filename, argv[optind]);
|
|
|
|
} else
|
|
|
|
filename = mallocstrcpy(filename, argv[optind]);
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
|
|
|
|
2004-05-18 05:20:36 +04:00
|
|
|
/* Back up the old terminal settings so that they can be restored. */
|
2002-03-29 19:00:59 +03:00
|
|
|
tcgetattr(0, &oldterm);
|
2002-03-29 18:38:17 +03:00
|
|
|
|
2004-07-27 20:46:35 +04:00
|
|
|
/* Curses initialization stuff: Start curses and set up the
|
|
|
|
* terminal state. */
|
2000-06-06 09:53:49 +04:00
|
|
|
initscr();
|
2004-07-27 20:46:35 +04:00
|
|
|
terminal_init();
|
2004-01-12 06:28:06 +03:00
|
|
|
|
2004-02-16 23:32:40 +03:00
|
|
|
/* Set up the global variables and the shortcuts. */
|
2004-07-01 22:59:52 +04:00
|
|
|
global_init(FALSE);
|
|
|
|
shortcut_init(FALSE);
|
2004-02-16 23:32:40 +03:00
|
|
|
|
|
|
|
/* Set up the signal handlers. */
|
2002-03-29 19:00:59 +03:00
|
|
|
signal_init();
|
2000-06-06 09:53:49 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2003-08-05 23:31:12 +04:00
|
|
|
fprintf(stderr, "Main: set up windows\n");
|
2000-06-06 09:53:49 +04:00
|
|
|
#endif
|
|
|
|
|
2001-11-29 05:42:27 +03:00
|
|
|
window_init();
|
2003-10-04 00:26:25 +04:00
|
|
|
#ifndef DISABLE_MOUSE
|
2001-11-29 05:42:27 +03:00
|
|
|
mouse_init();
|
2002-12-22 19:30:00 +03:00
|
|
|
#endif
|
2001-11-29 05:42:27 +03:00
|
|
|
|
2000-06-06 09:53:49 +04:00
|
|
|
#ifdef DEBUG
|
2003-08-05 23:31:12 +04:00
|
|
|
fprintf(stderr, "Main: bottom win\n");
|
2000-06-06 09:53:49 +04:00
|
|
|
#endif
|
2001-05-05 21:45:54 +04:00
|
|
|
/* Set up bottom of window */
|
2000-06-06 09:53:49 +04:00
|
|
|
display_main_list();
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2003-08-05 23:31:12 +04:00
|
|
|
fprintf(stderr, "Main: open file\n");
|
2000-06-06 09:53:49 +04:00
|
|
|
#endif
|
|
|
|
|
2004-07-12 07:10:30 +04:00
|
|
|
open_file(filename, FALSE, FALSE);
|
2003-01-13 04:35:15 +03:00
|
|
|
#ifdef ENABLE_MULTIBUFFER
|
|
|
|
/* If we're using multibuffers and more than one file is specified
|
|
|
|
on the command line, load them all and switch to the first one
|
|
|
|
afterward */
|
2004-05-14 21:57:00 +04:00
|
|
|
if (optind + 1 < argc) {
|
|
|
|
int old_multibuffer = ISSET(MULTIBUFFER);
|
|
|
|
SET(MULTIBUFFER);
|
2003-01-13 04:35:15 +03:00
|
|
|
for (optind++; optind < argc; optind++) {
|
2004-07-02 18:31:03 +04:00
|
|
|
add_open_file(TRUE);
|
2003-01-13 04:35:15 +03:00
|
|
|
new_file();
|
|
|
|
filename = mallocstrcpy(filename, argv[optind]);
|
2004-07-12 07:10:30 +04:00
|
|
|
open_file(filename, FALSE, FALSE);
|
2004-07-02 18:31:03 +04:00
|
|
|
load_file(FALSE);
|
2003-01-13 04:35:15 +03:00
|
|
|
}
|
|
|
|
open_nextfile_void();
|
2004-05-14 21:57:00 +04:00
|
|
|
if (!old_multibuffer)
|
|
|
|
UNSET(MULTIBUFFER);
|
2003-01-13 04:35:15 +03:00
|
|
|
}
|
|
|
|
#endif
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2002-05-11 07:04:44 +04:00
|
|
|
titlebar(NULL);
|
|
|
|
|
2000-06-06 09:53:49 +04:00
|
|
|
if (startline > 0)
|
2004-07-12 20:07:14 +04:00
|
|
|
do_gotoline(startline, FALSE);
|
2000-06-06 09:53:49 +04:00
|
|
|
|
2004-05-18 05:20:36 +04:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
/* Return here after a SIGWINCH. */
|
2001-04-12 07:01:53 +04:00
|
|
|
sigsetjmp(jmpbuf, 1);
|
2004-05-18 05:20:36 +04:00
|
|
|
#endif
|
2001-01-30 02:37:54 +03:00
|
|
|
|
2000-07-08 18:23:32 +04:00
|
|
|
edit_refresh();
|
|
|
|
|
2004-03-15 23:26:30 +03:00
|
|
|
while (TRUE) {
|
2004-06-13 01:03:14 +04:00
|
|
|
keyhandled = FALSE;
|
2000-09-06 19:19:18 +04:00
|
|
|
|
2004-07-13 21:09:24 +04:00
|
|
|
reset_cursor();
|
2003-01-28 04:16:47 +03:00
|
|
|
if (ISSET(CONSTUPDATE))
|
2004-07-01 23:41:09 +04:00
|
|
|
do_cursorpos(TRUE);
|
2003-01-28 04:16:47 +03:00
|
|
|
|
2003-10-04 00:26:25 +04:00
|
|
|
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE)
|
2001-04-12 07:01:53 +04:00
|
|
|
currshortcut = main_list;
|
2001-05-21 16:56:25 +04:00
|
|
|
#endif
|
2001-04-12 07:01:53 +04:00
|
|
|
|
2004-03-20 00:46:34 +03:00
|
|
|
kbinput = get_kbinput(edit, &meta_key);
|
2001-01-06 21:12:43 +03:00
|
|
|
#ifdef DEBUG
|
2003-08-05 23:31:12 +04:00
|
|
|
fprintf(stderr, "AHA! %c (%d)\n", kbinput, kbinput);
|
2001-01-06 21:12:43 +03:00
|
|
|
#endif
|
2004-03-20 00:57:56 +03:00
|
|
|
if (meta_key == TRUE) {
|
2004-03-20 00:46:34 +03:00
|
|
|
/* Check for the metaval and miscval defs... */
|
2004-06-13 01:03:14 +04:00
|
|
|
for (s =
|
|
|
|
#if !defined(DISABLE_BROWSER) || !defined (DISABLE_HELP) || !defined(DISABLE_MOUSE)
|
|
|
|
currshortcut
|
|
|
|
#else
|
|
|
|
main_list
|
|
|
|
#endif
|
|
|
|
; s != NULL && !keyhandled; s = s->next) {
|
2003-12-24 11:03:54 +03:00
|
|
|
if ((s->metaval != NANO_NO_KEY && kbinput == s->metaval) ||
|
2004-03-20 00:46:34 +03:00
|
|
|
(s->miscval != NANO_NO_KEY && kbinput == s->miscval)) {
|
2003-11-28 22:47:42 +03:00
|
|
|
if (ISSET(VIEW_MODE) && !s->viewok)
|
|
|
|
print_view_warning();
|
|
|
|
else {
|
|
|
|
if (s->func != do_cut_text)
|
2004-05-29 19:36:58 +04:00
|
|
|
cutbuffer_reset();
|
2003-11-28 22:47:42 +03:00
|
|
|
s->func();
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
2004-06-13 01:03:14 +04:00
|
|
|
keyhandled = TRUE;
|
2003-11-28 22:47:42 +03:00
|
|
|
}
|
2000-09-01 17:32:47 +04:00
|
|
|
#ifndef NANO_SMALL
|
2004-06-13 01:03:14 +04:00
|
|
|
if (!keyhandled) {
|
2003-04-15 05:15:09 +04:00
|
|
|
/* And for toggle switches */
|
2004-06-13 01:03:14 +04:00
|
|
|
for (t = toggles; t != NULL; t = t->next) {
|
2003-11-28 22:47:42 +03:00
|
|
|
if (kbinput == t->val) {
|
2004-05-29 19:36:58 +04:00
|
|
|
cutbuffer_reset();
|
2003-04-15 05:15:09 +04:00
|
|
|
do_toggle(t);
|
2004-06-13 01:03:14 +04:00
|
|
|
keyhandled = TRUE;
|
2003-04-15 05:15:09 +04:00
|
|
|
}
|
2004-06-13 01:03:14 +04:00
|
|
|
}
|
|
|
|
}
|
2000-09-01 17:32:47 +04:00
|
|
|
#endif
|
2004-06-13 01:03:14 +04:00
|
|
|
}
|
2000-06-06 09:53:49 +04:00
|
|
|
#ifdef DEBUG
|
2004-07-27 23:40:39 +04:00
|
|
|
fprintf(stderr, "I got Alt-%c! (%d)\n", kbinput, kbinput);
|
2000-06-06 09:53:49 +04:00
|
|
|
#endif
|
|
|
|
}
|
2000-12-18 05:23:50 +03:00
|
|
|
|
2000-06-06 09:53:49 +04:00
|
|
|
/* Look through the main shortcut list to see if we've hit a
|
2003-11-28 22:47:42 +03:00
|
|
|
shortcut key or function key */
|
2002-09-07 00:35:28 +04:00
|
|
|
|
2004-06-13 01:03:14 +04:00
|
|
|
if (!keyhandled) {
|
|
|
|
for (s =
|
2003-10-04 00:26:25 +04:00
|
|
|
#if !defined(DISABLE_BROWSER) || !defined (DISABLE_HELP) || !defined(DISABLE_MOUSE)
|
2004-06-13 01:03:14 +04:00
|
|
|
currshortcut
|
2002-02-27 07:14:16 +03:00
|
|
|
#else
|
2004-06-13 01:03:14 +04:00
|
|
|
main_list
|
2002-02-27 07:14:16 +03:00
|
|
|
#endif
|
2004-06-13 01:03:14 +04:00
|
|
|
; s != NULL && !keyhandled; s = s->next) {
|
2004-03-20 00:46:34 +03:00
|
|
|
if ((s->ctrlval != NANO_NO_KEY && kbinput == s->ctrlval) ||
|
|
|
|
(s->funcval != NANO_NO_KEY && kbinput == s->funcval)) {
|
2003-04-15 05:15:09 +04:00
|
|
|
if (ISSET(VIEW_MODE) && !s->viewok)
|
|
|
|
print_view_warning();
|
|
|
|
else {
|
|
|
|
if (s->func != do_cut_text)
|
2004-05-29 19:36:58 +04:00
|
|
|
cutbuffer_reset();
|
2003-04-15 05:15:09 +04:00
|
|
|
s->func();
|
|
|
|
}
|
2004-06-13 01:03:14 +04:00
|
|
|
keyhandled = TRUE;
|
2003-04-15 05:15:09 +04:00
|
|
|
}
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
2004-06-13 01:03:14 +04:00
|
|
|
}
|
2003-04-15 05:15:09 +04:00
|
|
|
|
|
|
|
if (!keyhandled)
|
2004-05-29 19:36:58 +04:00
|
|
|
cutbuffer_reset();
|
2002-10-15 04:27:55 +04:00
|
|
|
|
|
|
|
/* Don't even think about changing this string */
|
2004-07-01 22:59:52 +04:00
|
|
|
if (kbinput == NANO_XON_KEY)
|
2003-01-06 02:35:44 +03:00
|
|
|
statusbar(_("XON ignored, mumble mumble."));
|
2004-07-01 22:59:52 +04:00
|
|
|
if (kbinput == NANO_XOFF_KEY)
|
2003-08-17 06:48:43 +04:00
|
|
|
statusbar(_("XOFF ignored, mumble mumble."));
|
2004-07-01 22:59:52 +04:00
|
|
|
if (kbinput == NANO_XON_KEY || kbinput == NANO_XOFF_KEY)
|
2004-06-13 01:03:14 +04:00
|
|
|
keyhandled = TRUE;
|
2000-09-06 19:19:18 +04:00
|
|
|
|
2003-08-17 06:48:43 +04:00
|
|
|
/* Catch ^Z by hand when triggered also */
|
|
|
|
if (kbinput == NANO_SUSPEND_KEY) {
|
2000-09-06 19:19:18 +04:00
|
|
|
if (ISSET(SUSPEND))
|
|
|
|
do_suspend(0);
|
2004-06-13 01:03:14 +04:00
|
|
|
keyhandled = TRUE;
|
2000-09-06 19:19:18 +04:00
|
|
|
}
|
|
|
|
|
2000-06-06 09:53:49 +04:00
|
|
|
/* Last gasp, stuff that's not in the main lists */
|
2004-06-13 01:03:14 +04:00
|
|
|
if (!keyhandled) {
|
2000-06-06 09:53:49 +04:00
|
|
|
switch (kbinput) {
|
2003-10-04 00:26:25 +04:00
|
|
|
#ifndef DISABLE_MOUSE
|
2004-06-13 01:03:14 +04:00
|
|
|
case KEY_MOUSE:
|
|
|
|
do_mouse();
|
|
|
|
break;
|
2000-06-06 09:53:49 +04:00
|
|
|
#endif
|
2004-06-13 01:03:14 +04:00
|
|
|
case NANO_CONTROL_3: /* Ctrl-[ (Esc), which should
|
|
|
|
* have been handled before we
|
|
|
|
* got here */
|
|
|
|
case NANO_CONTROL_5: /* Ctrl-] */
|
|
|
|
break;
|
|
|
|
default:
|
2000-06-06 09:53:49 +04:00
|
|
|
#ifdef DEBUG
|
2004-06-13 01:03:14 +04:00
|
|
|
fprintf(stderr, "I got %c (%d)!\n", kbinput, kbinput);
|
2000-06-06 09:53:49 +04:00
|
|
|
#endif
|
2004-06-13 01:03:14 +04:00
|
|
|
/* We no longer stop unhandled sequences so that
|
|
|
|
people with odd character sets can type... */
|
|
|
|
if (ISSET(VIEW_MODE))
|
|
|
|
print_view_warning();
|
|
|
|
else
|
|
|
|
do_char((char)kbinput);
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
2004-06-13 01:03:14 +04:00
|
|
|
}
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|
2004-03-20 00:57:56 +03:00
|
|
|
assert(FALSE);
|
2000-06-06 09:53:49 +04:00
|
|
|
}
|