Commit 8213850d authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

add DB's overhaul of the cutting code and related file-writing code, his

fixes to check_operating_dir(), and a few minor cleanups and fixes of
mine


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1600 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 537 additions and 549 deletions
+537 -549
......@@ -29,13 +29,26 @@ CVS code -
shortcut display routines to handle them. Also modify the
shortcut list code to not treat non-control character values
of val as Meta-sequences, and fix dependencies on that
behavior. (DLR)
behavior. Also rename several variables: "alt" -> "meta",
"altval" -> "metaval". (DLR)
- Hook up the verbatim input functions so that verbatim input
can be used in the edit window. New function
do_verbatim_input(); changes to do_char(). (DLR) Additional
minor tweaks to do_char() by David Benbennick.
- Clarify the description of the --rebinddelete option. (DLR)
- cut.c:
- Overhaul to increase efficiency and add various cleanups.
Changes to add_to_cutbuffer(), cut_marked_segment(), and
do_uncut_text(). (David Benbennick)
- files.c:
check_operating_dir()
- Add an assert to ensure that full_operatingdir isn't NULL,
a fix for reporting nonexistent (incomplete) directory names
as being outside the operating directory when tab completion
is being used, and cosmetic cleanups. (David Benbennick)
copy_file()
- New function containing part of the functionality formerly in
do_writeout. (David Benbennick)
do_writeout()
- Prompt the user if we're trying to save an existing file (and
not just a selection of it) under a different name. (DLR;
......@@ -56,6 +69,10 @@ CVS code -
- Convert to use the new low-level input functions. (DLR)
main()
- Remove unused variable option_index. (DLR)
- Fix omission of NANO_NO_KEY in the shortcut list scanning
code. (DLR)
- nano.h:
- Comment additions and cosmetic tweaks. (DLR)
- search.c:
findnextstr(), do_replace_loop()
- Fix potential infinite loops and other misbehavior when doing
......@@ -95,6 +112,9 @@ CVS code -
- Modify to take an extra parameter indicating if we should
ungetch() the key equivalents of shortcuts we click on or not.
(DLR)
nanogetstr()
- Properly interpret the Meta key value in misc if we hit it at
the statusbar prompt. (DLR)
do_yesno()
- Add a few efficiency/extensibility tweaks. (David Benbennick)
- Convert to use the new low-level input functions, and remove
......
......@@ -28,15 +28,17 @@
#include "proto.h"
#include "nano.h"
static int marked_cut; /* Is the cutbuffer from a mark? */
static int marked_cut; /* Is the cutbuffer from a mark?
* 0 means whole-line cut, 1 means mark,
* 2 means cut-from-cursor. */
#ifndef NANO_SMALL
static int concatenate_cut; /* Should we add this cut string to the
end of the last one? */
* end of the last one? */
#endif
static filestruct *cutbottom = NULL;
/* Pointer to end of cutbuffer */
/* Pointer to end of cutbuffer. */
filestruct *get_cutbottom(void)
{
......@@ -46,29 +48,27 @@ filestruct *get_cutbottom(void)
void add_to_cutbuffer(filestruct *inptr)
{
#ifdef DEBUG
fprintf(stderr, "add_to_cutbuffer() called with inptr->data = %s\n",
inptr->data);
fprintf(stderr, "add_to_cutbuffer(): inptr->data = %s\n", inptr->data);
#endif
if (cutbuffer == NULL) {
if (cutbuffer == NULL)
cutbuffer = inptr;
inptr->prev = NULL;
#ifndef NANO_SMALL
} else if (concatenate_cut && !ISSET(JUSTIFY_MODE)) {
else if (concatenate_cut && !ISSET(JUSTIFY_MODE)) {
/* Just tack the text in inptr onto the text in cutbottom,
unless we're backing up lines while justifying text. */
* unless we're backing up lines while justifying text. */
cutbottom->data = charealloc(cutbottom->data,
strlen(cutbottom->data) + strlen(inptr->data) + 1);
strcat(cutbottom->data, inptr->data);
return;
}
#endif
} else {
else {
cutbottom->next = inptr;
inptr->prev = cutbottom;
}
inptr->next = NULL;
cutbottom = inptr;
cutbottom->next = NULL;
}
#ifndef NANO_SMALL
......@@ -78,112 +78,115 @@ void add_to_cutbuffer(filestruct *inptr)
* last cut line has length bot_x. That is, if bot_x > 0 then we cut to
* bot->data[bot_x - 1].
*
* destructive is whether to actually modify the file structure, if not
* then just copy the buffer into cutbuffer and don't pull it from the
* file.
* We maintain totsize, totlines, filebot, the magicline, and line
* numbers. Also, we set current and current_x so the cursor will be on
* the first character after what was cut. We do not do any screen
* updates.
*
* If destructive, then we maintain totsize, totlines, filebot, the
* magic line, and line numbers. Also, we set current and current_x so
* the cursor will be on the first character after what was cut. We do
* not do any screen updates. */
void cut_marked_segment(filestruct *top, size_t top_x, filestruct *bot,
size_t bot_x, int destructive)
* Note cutbuffer might not be NULL if "cut to end" is used. */
void cut_marked_segment(void)
{
filestruct *tmp, *next;
filestruct *top;
filestruct *bot;
filestruct *tmp;
size_t top_x;
size_t bot_x;
size_t newsize;
if (top == bot && top_x == bot_x)
/* If the mark doesn't cover any text, get out. */
if (current == mark_beginbuf && current_x == mark_beginx)
return;
assert(top != NULL && bot != NULL);
/* Make top be no later than bot. */
if (top->lineno > bot->lineno) {
filestruct *swap = top;
int swap2 = top_x;
assert(current != NULL && mark_beginbuf != NULL);
top = bot;
bot = swap;
/* Set up the top and bottom lines and coordinates of the marked
* text. */
mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x);
top_x = bot_x;
bot_x = swap2;
} else if (top == bot && top_x > bot_x) {
/* And bot_x can't be an earlier character than top_x. */
int swap = top_x;
top_x = bot_x;
bot_x = swap;
}
/* Make the first cut line manually. */
/* Make the first cut line manually. Move the cut part of the top
* line into tmp, and set newsize to that partial line's length. */
tmp = copy_node(top);
newsize = (top == bot ? bot_x - top_x : strlen(top->data + top_x));
charmove(tmp->data, top->data + top_x, newsize);
charmove(tmp->data, tmp->data + top_x, newsize);
null_at(&tmp->data, newsize);
add_to_cutbuffer(tmp);
/* And make the remainder line manually too. */
if (destructive) {
current_x = top_x;
totsize -= newsize;
totlines -= bot->lineno - top->lineno;
newsize = top_x + strlen(bot->data + bot_x) + 1;
if (top == bot) {
/* In this case, the remainder line is shorter, so we must
move text from the end forward first. */
charmove(top->data + top_x, bot->data + bot_x,
newsize - top_x);
top->data = charealloc(top->data, newsize);
} else {
totsize -= bot_x + 1;
/* Here, the remainder line might get longer, so we
realloc() it first. */
top->data = charealloc(top->data, newsize);
charmove(top->data + top_x, bot->data + bot_x,
newsize - top_x);
}
/* Add the contents of tmp to the cutbuffer. Note that cutbuffer
* might be non-NULL if we have cut to end enabled. */
if (cutbuffer == NULL) {
cutbuffer = tmp;
cutbottom = tmp;
} else {
cutbottom->next = tmp;
tmp->prev = cutbottom;
cutbottom = tmp;
}
/* And make the top remainder line manually too. Update current_x
* and totlines to account for all the cut text, and update totsize
* to account for the length of the cut part of the first line. */
current_x = top_x;
totsize -= newsize;
totlines -= bot->lineno - top->lineno;
/* Now set newsize to be the length of the top remainder line plus
* the bottom remainder line, plus one for the null terminator. */
newsize = top_x + strlen(bot->data + bot_x) + 1;
if (top == bot) {
/* In this case, we're only cutting one line or part of one
* line, so the remainder line is shorter. This means that we
* must move text from the end forward first. */
charmove(top->data + top_x, bot->data + bot_x, newsize - top_x);
top->data = charealloc(top->data, newsize);
cutbottom->next = NULL;
#ifdef DEBUG
dump_buffer(cutbuffer);
#endif
return;
}
tmp = top->next;
while (tmp != bot) {
next = tmp->next;
if (!destructive)
tmp = copy_node(tmp);
else
totsize -= strlen(tmp->data) + 1;
add_to_cutbuffer(tmp);
tmp = next;
}
/* Update totsize to account for the cut part of the last line. */
totsize -= bot_x + 1;
/* Make the last cut line manually. */
tmp = copy_node(bot);
null_at(&tmp->data, bot_x);
add_to_cutbuffer(tmp);
#ifdef DEBUG
dump_buffer(cutbuffer);
#endif
/* Here, the top remainder line might get longer (if the bottom
* remainder line is added to the end of it), so we realloc() it
* first. */
top->data = charealloc(top->data, newsize);
charmove(top->data + top_x, bot->data + bot_x, newsize - top_x);
if (destructive) {
top->next = bot->next;
if (top->next != NULL)
top->next->prev = top;
delete_node(bot);
renumber(top);
current = top;
if (bot == filebot) {
filebot = top;
assert(bot_x == 0);
if (top_x > 0)
new_magicline();
}
assert(cutbottom != NULL && cutbottom->next != NULL);
/* We're cutting multiple lines, so in particular the next line is
* cut too. */
cutbottom->next->prev = cutbottom;
/* Update totsize to account for all the complete lines that have
* been cut. After this, totsize is fully up to date. */
for (tmp = top->next; tmp != bot; tmp = tmp->next)
totsize -= strlen(tmp->data) + 1;
/* Make the last cut line manually. */
null_at(&bot->data, bot_x);
/* Move the rest of the cut text (other than the cut part of the top
* line) from the buffer to the end of the cutbuffer, and fix the
* edit buffer to account for the cut text. */
top->next = bot->next;
cutbottom = bot;
cutbottom->next = NULL;
if (top->next != NULL)
top->next->prev = top;
renumber(top);
current = top;
/* If the bottom line of the cut was the magicline, set filebot
* properly, and add a new magicline if the top remainder line
* (which is now the new bottom line) is non-blank. */
if (bot == filebot) {
filebot = top;
assert(bot_x == 0);
if (top_x > 0)
new_magicline();
}
#ifdef DEBUG
dump_buffer(cutbuffer);
......@@ -194,9 +197,6 @@ void cut_marked_segment(filestruct *top, size_t top_x, filestruct *bot,
int do_cut_text(void)
{
filestruct *fileptr;
#ifndef NANO_SMALL
int dontupdate = 0;
#endif
assert(current != NULL && current->data != NULL);
......@@ -214,8 +214,8 @@ int do_cut_text(void)
#endif
}
/* You can't cut the magic line except with the mark. But
trying does clear the cutbuffer if KEEP_CUTBUFFER is not set. */
/* You can't cut the magicline except with the mark. But trying
* does clear the cutbuffer if KEEP_CUTBUFFER is not set. */
if (current == filebot
#ifndef NANO_SMALL
&& !ISSET(MARK_ISSET)
......@@ -231,11 +231,12 @@ int do_cut_text(void)
if (current->data[current_x] == '\0') {
/* If the line is empty and we didn't just cut a non-blank
line, create a dummy line and add it to the cutbuffer */
* line, create a dummy blank line and add it to the
* cutbuffer. */
if (marked_cut != 1 && current->next != filebot) {
filestruct *junk = make_new_node(current);
junk->data = charalloc(1);
junk->data = charalloc(1);
junk->data[0] = '\0';
add_to_cutbuffer(junk);
#ifdef DEBUG
......@@ -251,33 +252,22 @@ int do_cut_text(void)
mark_beginx = strlen(current->data);
mark_beginbuf = current;
dontupdate = 1;
}
}
if (ISSET(MARK_ISSET)) {
/* Don't do_update() and move the screen position if the marked
area lies entirely within the screen buffer */
dontupdate |= current->lineno >= edittop->lineno &&
current->lineno <= editbot->lineno &&
mark_beginbuf->lineno >= edittop->lineno &&
mark_beginbuf->lineno <= editbot->lineno;
cut_marked_segment(current, current_x, mark_beginbuf,
mark_beginx, 1);
cut_marked_segment();
placewewant = xplustabs();
UNSET(MARK_ISSET);
/* If we just did a marked cut of part of a line, we should add
the first line of any cut done immediately afterward to the
end of this cut, as Pico does. */
* the first line of any cut done immediately afterward to the
* end of this cut, as Pico does. */
if (current == mark_beginbuf && current_x < strlen(current->data))
concatenate_cut = 1;
marked_cut = 1;
if (dontupdate)
edit_refresh();
else
edit_update(current, CENTER);
edit_refresh();
set_modified();
return 1;
......@@ -310,29 +300,26 @@ int do_cut_text(void)
#ifndef NANO_SMALL
concatenate_cut = 0;
#endif
placewewant = 0;
return 1;
}
int do_uncut_text(void)
{
filestruct *tmp = current, *fileptr = current;
filestruct *newbuf = NULL, *newend = NULL;
char *tmpstr, *tmpstr2;
filestruct *hold = current;
int i;
filestruct *tmp = current;
filestruct *newbuf = NULL;
filestruct *newend = NULL;
#ifndef DISABLE_WRAPPING
wrap_reset();
#endif
check_statblank();
if (cutbuffer == NULL || fileptr == NULL)
if (cutbuffer == NULL || current == NULL)
return 0; /* AIEEEEEEEEEEEE */
/* If we're uncutting a previously non-marked block, uncut to end if
we're not at the beginning of the line. If we are at the
beginning of the line, set placewewant to 0. Pico does both of
these. */
* we're not at the beginning of the line. If we are at the
* beginning of the line, set placewewant to 0. Pico does both of
* these. */
if (marked_cut == 0) {
if (current_x != 0)
marked_cut = 2;
......@@ -341,24 +328,22 @@ int do_uncut_text(void)
}
/* If we're going to uncut on the magicline, always make a new
magicline in advance. */
* magicline in advance, as Pico does. */
if (current->next == NULL)
new_magicline();
if (marked_cut == 0 || cutbuffer->next != NULL)
{
if (marked_cut == 0 || cutbuffer->next != NULL) {
newbuf = copy_filestruct(cutbuffer);
for (newend = newbuf; newend->next != NULL && newend != NULL;
newend = newend->next)
totlines++;
}
/* Hook newbuf into fileptr */
/* Hook newbuf in at current. */
if (marked_cut != 0) {
int recenter_me = 0;
/* Should we eventually use edit_update(CENTER)? */
filestruct *hold = current;
/* If there's only one line in the cutbuffer */
/* If there's only one line in the cutbuffer... */
if (cutbuffer->next == NULL) {
size_t buf_len = strlen(cutbuffer->data);
size_t cur_len = strlen(current->data);
......@@ -367,22 +352,24 @@ int do_uncut_text(void)
charmove(current->data + current_x + buf_len,
current->data + current_x, cur_len - current_x + 1);
strncpy(current->data + current_x, cutbuffer->data, buf_len);
/* Use strncpy() to not copy the terminal '\0'. */
/* Use strncpy() to not copy the null terminator. */
current_x += buf_len;
totsize += buf_len;
placewewant = xplustabs();
update_cursor();
} else { /* yuck -- no kidding! */
} else { /* Yuck -- no kidding! */
char *tmpstr, *tmpstr2;
tmp = current->next;
/* New beginning */
/* New beginning. */
tmpstr = charalloc(current_x + strlen(newbuf->data) + 1);
strncpy(tmpstr, current->data, current_x);
strcpy(&tmpstr[current_x], newbuf->data);
totsize += strlen(newbuf->data) + strlen(newend->data) + 1;
/* New end */
/* New end. */
tmpstr2 = charalloc(strlen(newend->data) +
strlen(&current->data[current_x]) + 1);
strcpy(tmpstr2, newend->data);
......@@ -401,35 +388,28 @@ int do_uncut_text(void)
newend->next = tmp;
/* If tmp isn't null, we're in the middle: update the
prev pointer. If it IS null, we're at the end; update
the filebot pointer */
/* If tmp isn't NULL, we're in the middle: update the
* prev pointer. If it IS NULL, we're at the end; update
* the filebot pointer. */
if (tmp != NULL)
tmp->prev = newend;
else {
/* Fix the editbot pointer too */
if (editbot == filebot)
editbot = newend;
filebot = newend;
new_magicline();
}
/* Now why don't we update the totsize also */
/* Now why don't we update the totsize also? */
for (tmp = current->next; tmp != newend; tmp = tmp->next)
totsize += strlen(tmp->data) + 1;
current = newend;
if (editbot->lineno < newend->lineno)
recenter_me = 1;
}
/* If marked cut == 2, that means that we're doing a cut to end
and we don't want anything else on the line, so we have to
screw up all the work we just did and separate the line.
There must be a better way to do this, but not at 1AM on a
work night. */
* and we don't want anything else on the line, so we have to
* screw up all the work we just did and separate the line.
* There must be a better way to do this, but not at 1 AM on a
* work night. */
if (marked_cut == 2) {
tmp = make_new_node(current);
tmp->data = mallocstrcpy(NULL, current->data + current_x);
......@@ -439,7 +419,7 @@ int do_uncut_text(void)
current_x = 0;
placewewant = 0;
/* Extra line added, update stuff */
/* Extra line added; update stuff. */
totlines++;
totsize++;
}
......@@ -451,41 +431,32 @@ int do_uncut_text(void)
dump_buffer(cutbuffer);
#endif
set_modified();
if (recenter_me)
edit_update(current, CENTER);
else
edit_refresh();
edit_refresh();
return 0;
}
if (fileptr != fileage) {
tmp = fileptr->prev;
if (current != fileage) {
tmp = current->prev;
tmp->next = newbuf;
newbuf->prev = tmp;
} else
fileage = newbuf;
totlines++; /* Unmarked uncuts don't split lines */
totlines++; /* Unmarked uncuts don't split lines. */
/* This is so uncutting at the top of the buffer will work => */
if (current_y == 0)
edittop = newbuf;
/* Connect the end of the buffer to the filestruct */
newend->next = fileptr;
fileptr->prev = newend;
/* Connect the end of the buffer to the filestruct. */
newend->next = current;
current->prev = newend;
/* Recalculate size *sigh* */
for (tmp = newbuf; tmp != fileptr; tmp = tmp->next)
for (tmp = newbuf; tmp != current; tmp = tmp->next)
totsize += strlen(tmp->data) + 1;
i = editbot->lineno;
renumber(newbuf);
/* Center the screen if we've moved beyond the line numbers of both
the old and new editbots */
if (i < newend->lineno && editbot->lineno < newend->lineno)
edit_update(fileptr, CENTER);
else
edit_refresh();
edit_refresh();
#ifdef DEBUG
dump_buffer_reverse();
......
This diff is collapsed.
......@@ -172,7 +172,7 @@ void sc_init_one(shortcut **shortcutage, int key, const char *desc,
#ifndef DISABLE_HELP
const char *help,
#endif
int alt, int func_key, int misc, int view, int (*func) (void))
int meta, int func_key, int misc, int view, int (*func) (void))
{
shortcut *s;
......@@ -191,7 +191,7 @@ void sc_init_one(shortcut **shortcutage, int key, const char *desc,
#ifndef DISABLE_HELP
s->help = help;
#endif
s->altval = alt;
s->metaval = meta;
s->func_key = func_key;
s->misc = misc;
s->viewok = view;
......
......@@ -403,7 +403,7 @@ void help_init(void)
/* Now add our shortcut info */
for (s = currshortcut; s != NULL; s = s->next) {
/* true if the character in s->altval is shown in first column */
/* true if the character in s->metaval is shown in first column */
int meta_shortcut = 0;
if (s->val != NANO_NO_KEY) {
......@@ -420,12 +420,12 @@ void help_init(void)
ptr += sprintf(ptr, "^%c", s->val + 64);
}
#ifndef NANO_SMALL
else if (s->altval != NANO_NO_KEY) {
else if (s->metaval != NANO_NO_KEY) {
meta_shortcut = 1;
if (s->altval == NANO_ALT_SPACE)
if (s->metaval == NANO_ALT_SPACE)
ptr += snprintf(ptr, 8, "M-%.5s", _("Space"));
else
ptr += sprintf(ptr, "M-%c", toupper(s->altval));
ptr += sprintf(ptr, "M-%c", toupper(s->metaval));
}
#endif
......@@ -436,8 +436,8 @@ void help_init(void)
*(ptr++) = '\t';
if (!meta_shortcut && s->altval != NANO_NO_KEY)
ptr += sprintf(ptr, "(M-%c)", toupper(s->altval));
if (!meta_shortcut && s->metaval != NANO_NO_KEY)
ptr += sprintf(ptr, "(M-%c)", toupper(s->metaval));
else if (meta_shortcut && s->misc != NANO_NO_KEY)
ptr += sprintf(ptr, "(M-%c)", toupper(s->misc));
......@@ -3516,10 +3516,10 @@ int main(int argc, char *argv[])
fprintf(stderr, "AHA! %c (%d)\n", kbinput, kbinput);
#endif
if (meta == 1) {
/* Check for the altkey and misc defs... */
/* Check for the metaval and misc defs... */
for (s = main_list; s != NULL; s = s->next)
if ((s->altval > 0 && kbinput == s->altval) ||
(s->misc > 0 && kbinput == s->misc)) {
if ((s->metaval != NANO_NO_KEY && kbinput == s->metaval) ||
(s->misc != NANO_NO_KEY && kbinput == s->misc)) {
if (ISSET(VIEW_MODE) && !s->viewok)
print_view_warning();
else {
......
......@@ -46,13 +46,14 @@
#endif
#ifdef USE_SLANG
/* Slang support enabled */
/* Slang support enabled. Work around Slang's not defining KEY_DC or
* KEY_IC. */
#include <slcurses.h>
#define KEY_DC SL_KEY_DELETE
#define KEY_IC SL_KEY_IC
#elif defined(HAVE_NCURSES_H)
#include <ncurses.h>
#else /* Uh oh */
#else /* Uh oh. */
#include <curses.h>
#endif /* CURSES_H */
......@@ -71,16 +72,18 @@
#include <sys/stat.h>
#include "config.h"
/* If no snprintf()/vsnprintf(), use the versions from glib. */
#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
#include <glib.h>
# ifndef HAVE_SNPRINTF
# define snprintf g_snprintf
# define snprintf g_snprintf
# endif
# ifndef HAVE_VSNPRINTF
# define vsnprintf g_vsnprintf
# define vsnprintf g_vsnprintf
# endif
#endif
/* If no strcasecmp()/strncasecmp(), use the versions we have. */
#ifndef HAVE_STRCASECMP
#define strcasecmp nstricmp
#endif
......@@ -90,11 +93,11 @@
#endif
/* Assume ERR is defined as -1. To avoid duplicate case values when
some key definitions are missing, we have to set all of these, and
all of the special sentinel values below, to different negative
values other than -1. */
* some key definitions are missing, we have to set all of these, and
* all of the special sentinel values below, to different negative
* values other than -1. */
/* HP-UX 10 & 11 do not seem to support KEY_HOME and KEY_END */
/* HP-UX 10 & 11 do not seem to support KEY_HOME and KEY_END. */
#ifndef KEY_HOME
#define KEY_HOME -2
#endif
......@@ -103,13 +106,13 @@
#define KEY_END -3
#endif
/* Slang and SunOS 5.7-5.9 do not seem to support KEY_RESIZE */
/* Slang and SunOS 5.7-5.9 do not seem to support KEY_RESIZE. */
#ifndef KEY_RESIZE
#define KEY_RESIZE -4
#endif
/* Slang does not seem to support KEY_SUSPEND, KEY_SLEFT, or
KEY_SRIGHT */
* KEY_SRIGHT. */
#ifndef KEY_SUSPEND
#define KEY_SUSPEND -5
#endif
......@@ -124,6 +127,8 @@
#define VERMSG "GNU nano " VERSION
/* If we aren't using ncurses, turn the mouse support off, as it's
* ncurses-specific. */
#ifndef NCURSES_MOUSE_VERSION
#define DISABLE_MOUSE 1
#endif
......@@ -132,12 +137,12 @@
#define DISABLE_WRAPJUSTIFY 1
#endif
/* Structure types */
/* Structure types. */
typedef struct filestruct {
char *data;
struct filestruct *next; /* Next node */
struct filestruct *prev; /* Previous node */
int lineno; /* The line number */
struct filestruct *next; /* Next node. */
struct filestruct *prev; /* Previous node. */
int lineno; /* The line number. */
} filestruct;
#ifdef ENABLE_MULTIBUFFER
......@@ -146,51 +151,56 @@ typedef struct openfilestruct {
#ifndef NANO_SMALL
struct stat originalfilestat;
#endif
struct openfilestruct *next; /* Next node */
struct openfilestruct *prev; /* Previous node */
struct filestruct *fileage; /* Current file */
struct filestruct *filebot; /* Current file's last line */
struct openfilestruct *next; /* Next node. */
struct openfilestruct *prev; /* Previous node. */
struct filestruct *fileage; /* Current file. */
struct filestruct *filebot; /* Current file's last line. */
#ifndef NANO_SMALL
struct filestruct *file_mark_beginbuf;
/* Current file's beginning marked line */
int file_mark_beginx; /* Current file's beginning marked line's
x-coordinate position */
/* Current file's beginning marked
* line. */
int file_mark_beginx; /* Current file's beginning marked
* line's x-coordinate position. */
#endif
int file_current_x; /* Current file's x-coordinate position */
int file_current_y; /* Current file's y-coordinate position */
int file_current_x; /* Current file's x-coordinate
* position. */
int file_current_y; /* Current file's y-coordinate
* position. */
int file_flags; /* Current file's flags: modification
status (and marking status, if
available) */
int file_placewewant; /* Current file's place we want */
int file_totlines; /* Current file's total number of lines */
long file_totsize; /* Current file's total size */
int file_lineno; /* Current file's line number */
* status (and marking status, if
* available). */
int file_placewewant; /* Current file's place we want. */
int file_totlines; /* Current file's total number of
* lines. */
long file_totsize; /* Current file's total size. */
int file_lineno; /* Current file's line number. */
} openfilestruct;
#endif
typedef struct shortcut {
/* Key values that aren't used should be set to NANO_NO_KEY */
/* Key values that aren't used should be set to NANO_NO_KEY. */
int val; /* Special sentinel key or control key we want
* bound */
int altval; /* Alt key we want bound */
int func_key; /* Function key we want bound */
int misc; /* Other Alt key we want bound */
* bound. */
int metaval; /* Meta key we want bound. */
int func_key; /* Function key we want bound. */
int misc; /* Other Meta key we want bound. */
int viewok; /* Is this function legal in view mode? */
int (*func) (void); /* Function to call when we catch this key */
const char *desc; /* Description, e.g. "Page Up" */
int (*func) (void); /* Function to call when we catch this key. */
const char *desc; /* Description, e.g. "Page Up". */
#ifndef DISABLE_HELP
const char *help; /* Help file entry text */
const char *help; /* Help file entry text. */
#endif
struct shortcut *next;
} shortcut;
#ifndef NANO_SMALL
typedef struct toggle {
int val; /* Sequence to toggle the key. Should only need 1 */
int val; /* Sequence to toggle the key. Should only need
* one. */
const char *desc; /* Description for when toggle is, uh, toggled,
e.g. "Pico Messages"; we'll append Enabled or
Disabled */
int flag; /* What flag actually gets toggled */
Disabled. */
int flag; /* What flag actually gets toggled. */
struct toggle *next;
} toggle;
#endif /* !NANO_SMALL */
......@@ -235,8 +245,10 @@ typedef struct historytype {
char *data;
} historytype;
typedef struct historyheadtype {
struct historytype *next; /* keep *next and *prev members together */
struct historytype *prev; /* and in same order as in historytype */
struct historytype *next; /* Keep *next and *prev members
* together. */
struct historytype *prev; /* And in same order as in
* historytype. */
struct historytype *tail;
struct historytype *current;
int count;
......@@ -244,8 +256,8 @@ typedef struct historyheadtype {
} historyheadtype;
#endif /* !NANO_SMALL */
/* Bitwise flags so we can save space (or more correctly, not waste it) */
/* Bitwise flags so we can save space (or more correctly, not waste
* it). */
#define MODIFIED (1<<0)
#define KEEP_CUTBUFFER (1<<1)
#define CASE_SENSITIVE (1<<2)
......@@ -267,7 +279,7 @@ typedef struct historyheadtype {
#define DOS_FILE (1<<18)
#define MAC_FILE (1<<19)
#define SMOOTHSCROLL (1<<20)
#define DISABLE_CURPOS (1<<21) /* Damn, we still need it */
#define DISABLE_CURPOS (1<<21) /* Damn, we still need it. */
#define REBIND_DELETE (1<<22)
#define NO_CONVERT (1<<23)
#define BACKUP_FILE (1<<24)
......@@ -278,8 +290,7 @@ typedef struct historyheadtype {
#define HISTORYLOG (1<<29)
#define JUSTIFY_MODE (1<<30)
/* Control key sequences, changing these would be very very bad */
/* Control key sequences, changing these would be very very bad. */
#define NANO_CONTROL_SPACE 0
#define NANO_CONTROL_A 1
#define NANO_CONTROL_B 2
......@@ -347,13 +358,13 @@ typedef struct historyheadtype {
#define NANO_ALT_RBRACKET ']'
#define NANO_ALT_SPACE ' '
/* Some semi-changeable keybindings; don't play with unless you're sure
you know what you're doing */
/* Some semi-changeable keybindings; don't play with these unless you're
* sure you know what you're doing. */
/* No key at all. */
#define NANO_NO_KEY -8
/* Special sentinel key. */
/* Special sentinel key used for search string history. */
#define NANO_HISTORY_KEY -9
/* Normal keys. */
......@@ -453,18 +464,18 @@ typedef enum {
TOP, CENTER, NONE
} topmidnone;
/* Minimum editor window rows required for nano to work correctly */
/* Minimum editor window rows required for nano to work correctly. */
#define MIN_EDITOR_ROWS 3
/* Minimum editor window cols required for nano to work correctly */
/* Minimum editor window cols required for nano to work correctly. */
#define MIN_EDITOR_COLS 10
/* Default number of characters from end-of-line where text wrapping
occurs */
* occurs. */
#define CHARS_FROM_EOL 8
/* Maximum number of search history strings saved, same value used for
replace history */
* replace history. */
#define MAX_SEARCH_HISTORY 100
#endif /* !NANO_H */
......@@ -140,8 +140,7 @@ void update_color(void);
/* Public functions in cut.c */
filestruct *get_cutbottom(void);
void add_to_cutbuffer(filestruct *inptr);
void cut_marked_segment(filestruct *top, size_t top_x, filestruct *bot,
size_t bot_x, int destructive);
void cut_marked_segment(void);
int do_cut_text(void);
int do_uncut_text(void);
......@@ -207,7 +206,7 @@ void sc_init_one(shortcut **shortcutage, int key, const char *desc,
#ifndef DISABLE_HELP
const char *help,
#endif
int alt, int func_key, int misc, int view, int (*func) (void));
int meta, int func_key, int misc, int view, int (*func) (void));
#ifndef NANO_SMALL
void toggle_init_one(int val, const char *desc, int flag);
void toggle_init(void);
......
......@@ -1090,12 +1090,12 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
fprintf(stderr, "Aha! \'%c\' (%d)\n", kbinput,
kbinput);
#endif
if (meta == 1 && kbinput == t->altval)
/* We hit an Alt key. Do like above. We don't
just ungetch() the letter and let it get
caught above cause that screws the
keypad... */
return t->altval;
if (meta == 1 && (kbinput == t->metaval || kbinput == t->misc))
/* We hit a Meta key. Do like above. We don't
* just ungetch() the letter and let it get
* caught above cause that screws the
* keypad... */
return kbinput;
}
if (is_cntrl_char(kbinput))
......@@ -1223,8 +1223,8 @@ void bottombars(const shortcut *s)
strcpy(keystr, "^?");
else
sprintf(keystr, "^%c", s->val + 64);
} else if (s->altval != NANO_NO_KEY)
sprintf(keystr, "M-%c", toupper(s->altval));
} else if (s->metaval != NANO_NO_KEY)
sprintf(keystr, "M-%c", toupper(s->metaval));
onekey(keystr, s->desc, COLS / numcols);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment