- Many chanes to allow marked cutting to work with multiple
file buffers: changes to openfilestruct type in nano.h and
files.c (David Lawrence Ramsey).
+ - Changed NANO_SMALL to ENABLE_NLS for gettext disabling
+ (David Benbennick).
+ - Move next_key and pev_key definitions out of main() and into
+ global.c where they belong (David Benbennick).
- configure.ac:
- Define NDEBUG to silence asserts (David Benbennick).
- files.c:
- global.c:
shortcut_init()
- Add missing free_shortcutage()s (David Benbennick).
+ thanks_for_all_the_fish()
+ - Only defined when using DEBUG, makes sense (David Benbennick).
- nano.c:
die_save_file()
- Add missing free (David Benbennick).
- Optimizations (David Benbennick).
do_wrap()
- Complete rewrite (David Benbennick).
+ help_init()
+ - A little les readable, a lot shorer :-) (David Benbennick).
+ - Fix Meta-A not getting capitalized, and convert the ASCII
+ #s to their character equivalent.
main()
- Changed charalloc(), strcpy()s to mallocstrcpy()s.
- nano.h:
- Changed references to Debian GNU/Linux to Debian GNU (Jordi).
- nano.1.html:
- Updated for -Y option (David Lawrence Ramsey).
-- rcfile.c
+- rcfile.c:
- Made some rc file errors less fatal.
- Added in my patch for getpwent instead of relying on $HOME
(David Lawrence Ramsey).
- winio.c:
edit_add()
- Changed some syntax hilight computations for the sake of COLS.
+ botombars(), onekey()
+ - Cleanups (David Benbennick).
- po/gl.po:
- Galician translation updates (Jacobo Tarrio).
- po/de.po:
#include "proto.h"
#include "nano.h"
-#ifndef NANO_SMALL
+#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else
#include "proto.h"
#include "nano.h"
-#ifndef NANO_SMALL
+#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else
#include "proto.h"
#include "nano.h"
-#ifndef NANO_SMALL
+#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else
}
#endif
+ /* Here is a kludge. If the current file is blank (including
+ * after new_file()), then totlines==1 and totsize==0. Thus
+ * after open_pipe() or open_file() below, the totsize is short
+ * by one. */
+ if (totlines==1 && totsize==0)
+ totsize++;
+
#ifndef NANO_SMALL
if (i == NANO_EXTCMD_KEY) {
i = open_pipe(answer);
#include "nano.h"
#include "proto.h"
-#ifndef NANO_SMALL
+#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else
NANO_OPENNEXT_KEY, 0, 0, VIEW, open_nextfile_void);
#endif
+#ifndef NANO_SMALL
+ sc_init_one(&main_list, NANO_NEXTWORD_KEY, _("Next Word"),
+ IFHELP(_("Move forward one word"),)
+ 0, 0, 0, VIEW, do_next_word_void);
+ sc_init_one(&main_list, -9, _("Prev Word"),
+ IFHELP(_("Move backward one word"),) NANO_PREVWORD_KEY, 0, 0,
+ VIEW, do_prev_word_void);
+#endif
+
free_shortcutage(&whereis_list);
sc_init_one(&whereis_list, NANO_HELP_KEY,
#endif
}
+/* This function is called just before calling exit(). Practically, the
+ * only effect is to cause a segmentation fault if the various data
+ * structures got bolloxed earlier. Thus, we don't bother having this
+ * function unless debugging is turned on.
+ */
+#ifdef DEBUG
/* added by SPK for memory cleanup, gracefully return our malloc()s */
void thanks_for_all_the_fish(void)
{
-#ifdef ENABLE_MULTIBUFFER
- openfilestruct * current_open_file;
-#endif
-
#ifndef DISABLE_OPERATINGDIR
if (operating_dir != NULL)
free(operating_dir);
#endif
#ifdef ENABLE_MULTIBUFFER
-/* Cleanup of Multibuffers . . .
- Do not cleanup the current one, that is fileage . . . do the
- rest of them though! (should be none if all went well) */
- current_open_file = open_files;
if (open_files != NULL) {
- while (open_files->prev != NULL)
+ /* We free the memory associated with each open file. */
+ openfilestruct *next;
+
+ while (open_files->prev != NULL)
open_files = open_files->prev;
- while (open_files->next != NULL) {
- /* cleanup of a multi buf . . . */
- open_files = open_files->next;
- if (open_files->prev != current_open_file)
- free_openfilestruct(open_files->prev);
- }
- /* cleanup of last multi buf . . . */
- free_openfilestruct(open_files);
+ do {
+ next = open_files->next;
+ free_openfilestruct(open_files);
+ open_files = next;
+ } while (open_files != NULL);
}
#else
- /* starting the cleanup of fileage now . . . */
-
if (fileage != NULL)
free_filestruct(fileage);
#endif
-
- /* that is all for now */
-
}
+#endif /* DEBUG */
#include "proto.h"
#include "nano.h"
-#ifndef NANO_SMALL
+#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else
#include "proto.h"
#include "nano.h"
-#ifndef NANO_SMALL
+#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else
/* Restore the old term settings */
tcsetattr(0, TCSANOW, &oldterm);
+#ifdef DEBUG
thanks_for_all_the_fish();
+#endif
exit(sigage);
}
}
}
+int do_next_word_void(void) {
+ do_next_word();
+ return 0;
+}
+
/* the same thing for backwards */
void do_prev_word(void)
{
}
}
+
+int do_prev_word_void(void) {
+ do_prev_word();
+ return 0;
+}
#endif /* NANO_SMALL */
#ifndef DISABLE_WRAPPING
int do_delete(void)
{
- filestruct *foo;
-
/* blbf -> blank line before filebot (see below) */
int blbf = 0;
align(¤t->data);
- /* Now that we have a magic line again, we can check for both being
- on the line before filebot as well as at filebot; it's a special
- case if we're on the line before filebot and it's blank, since we
- should be able to delete it */
} else if (current->next != NULL && (current->next != filebot || blbf)) {
+ /* We can delete the line before filebot only if it is blank: it
+ * becomes the new magic line then. */
+
+ filestruct *foo;
+
current->data = nrealloc(current->data,
strlen(current->data) +
strlen(current->next->data) + 1);
unlink_node(foo);
delete_node(foo);
update_line(current, current_x);
-
- /* Please see the comment in do_backspace if you don't understand
- this test */
- if (current == filebot && current->data[0] != '\0') {
- new_magicline();
- fix_editbot();
- totsize++;
- }
renumber(current);
totlines--;
} else
#ifndef DISABLE_HELP
void help_init(void)
{
- int i, sofar = 0, meta_shortcut = 0, helplen;
+ int i, sofar = 0, helplen;
long allocsize = 1; /* How much space we're gonna need for the help text */
- char buf[BUFSIZ] = "", *ptr = NULL;
+ char *ptr = NULL;
#ifndef NANO_SMALL
toggle *t;
#endif
/* Now add the text we want */
strcpy(help_text, ptr);
+ sofar = strlen(help_text);
/* Now add our shortcut info */
s = currshortcut;
for (i = 0; i <= helplen - 1; i++) {
- if (s->val > 0 && s->val < 'a')
- sofar = snprintf(buf, BUFSIZ, "^%c ", s->val + 64);
- else {
- if (s->altval > 0) {
- sofar = 0;
- meta_shortcut = 1;
- }
- else
- sofar = snprintf(buf, BUFSIZ, " ");
- }
+ int meta_shortcut = 0;
+
+ if (s->val > 0 && s->val < 32)
+ sofar += sprintf(help_text + sofar, "^%c\t", s->val + 64);
+#ifndef NANO_SMALL
+ else if (s->val == NANO_CONTROL_SPACE)
+ sofar += sprintf(help_text + sofar, "^%s\t", _("Space"));
+#endif
+ else if (s->altval > 0)
+ meta_shortcut = 1;
+ else
+ help_text[sofar++] = '\t';
if (!meta_shortcut) {
if (s->misc1 > KEY_F0 && s->misc1 <= KEY_F(64))
- sofar += snprintf(&buf[sofar], BUFSIZ - sofar, "(F%d) ",
- s->misc1 - KEY_F0);
- else
- sofar += snprintf(&buf[sofar], BUFSIZ - sofar, " ");
+ sofar += sprintf(help_text + sofar, "(F%d)",
+ s->misc1 - KEY_F0);
+ help_text[sofar++] = '\t';
}
- if (s->altval > 0 && s->altval < 91
- && (s->altval - 32) > 32)
- sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
- (meta_shortcut ? "M-%c " : "(M-%c) "),
- s->altval - 32);
- else if (s->altval >= 'a')
- sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
- (meta_shortcut ? "M-%c " : "(M-%c) "),
- s->altval - 32);
- else if (s->altval > 0)
- sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
- (meta_shortcut ? "M-%c " : "(M-%c) "),
- s->altval);
+#ifndef NANO_SMALL
+ if (s->altval == NANO_ALT_SPACE)
+ sofar += sprintf(help_text + sofar, "M-%s", _("Space"));
+ else
+#endif
+ if (s->altval > 0)
+ sofar += sprintf(help_text + sofar,
+ (meta_shortcut ? "M-%c" : "(M-%c)"), s->altval -
+ (('A' <= s->altval && s->altval <= 'Z') || 'a' <= s->altval
+ ? 32 : 0));
/* Hack */
else if (s->val >= 'a')
- sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
- (meta_shortcut ? "(M-%c) " : "M-%c "),
- s->val - 32);
- else
- sofar += snprintf(&buf[sofar], BUFSIZ - sofar, " ");
+ sofar += sprintf(help_text + sofar,
+ (meta_shortcut ? "(M-%c)\t" : "M-%c\t"), s->val - 32);
+
+ help_text[sofar++] = '\t';
if (meta_shortcut) {
if (s->misc1 > KEY_F0 && s->misc1 <= KEY_F(64))
- sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
- "(F%d) ", s->misc1 - KEY_F0);
- else
- sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
- " ");
+ sofar += sprintf(help_text + sofar,
+ "(F%d)", s->misc1 - KEY_F0);
+ help_text[sofar++] = '\t';
+ help_text[sofar++] = '\t';
}
if (s->help != NULL)
- snprintf(&buf[sofar], BUFSIZ - sofar, "%s", s->help);
+ sofar += sprintf(help_text + sofar, "%s", s->help);
- strcat(help_text, buf);
- strcat(help_text, "\n");
+ help_text[sofar++] = '\n';
s = s->next;
}
/* And the toggles... */
if (currshortcut == main_list)
for (t = toggles; t != NULL; t = t->next) {
- sofar = snprintf(buf, BUFSIZ,
- "M-%c ", t->val - 32);
+ sofar += sprintf(help_text + sofar, "M-%c\t\t\t",
+ t->val - 32);
if (t->desc != NULL) {
- snprintf(&buf[sofar], BUFSIZ - sofar, _("%s enable/disable"),
- t->desc);
+ sofar += sprintf(help_text + sofar,
+ _("%s enable/disable"), t->desc);
+ }
+ help_text[sofar++] = '\n';
}
- strcat(help_text, buf);
- strcat(help_text, "\n");
- }
#endif /* !NANO_SMALL */
}
#endif
modify_control_seq = 1;
keyhandled = 1;
break;
-#ifndef NANO_SMALL
- case ' ':
- /* If control-space is next word, Alt-space should be previous word */
- do_prev_word();
- keyhandled = 1;
- break;
-#endif
case '[':
switch (kbinput = wgetch(edit)) {
case '1': /* Alt-[-1-[0-5,7-9] = F1-F8 in X at least */
break;
#endif
-#if !defined (NANO_SMALL) && defined (HAVE_REGEX_H)
- case NANO_BRACKET_KEY:
- do_find_bracket();
- keyhandled = 1;
- break;
-#endif
-
default:
/* Check for the altkey defs.... */
for (s = main_list; s != NULL; s = s->next)
if (kbinput == s->altval ||
- kbinput == s->altval - 32) {
- kbinput = s->val;
+ kbinput == s->altval - 32) {
+ if (ISSET(VIEW_MODE) && !s->viewok)
+ print_view_warning();
+ else
+ s->func();
+ keyhandled = 1;
break;
}
#ifndef NANO_SMALL
#endif
case 0: /* Erg */
-#ifndef NANO_SMALL
- do_next_word();
- break;
-#endif
-
case -1: /* Stuff that we don't want to do squat */
case 410: /* Must ignore this, it gets sent when we resize */
case 29: /* Ctrl-] */
/* Control key sequences, changing these would be very very bad */
+#ifndef NANO_SMALL
+# define NANO_CONTROL_SPACE 0
+#endif
#define NANO_CONTROL_A 1
#define NANO_CONTROL_B 2
#define NANO_CONTROL_C 3
#define NANO_ALT_LCARAT '<'
#define NANO_ALT_RCARAT '>'
#define NANO_ALT_BRACKET ']'
+#ifndef NANO_SMALL
+# define NANO_ALT_SPACE ' '
+#endif
/* Some semi-changeable keybindings; don't play with unless you're sure you
know what you're doing */
#define NANO_OPENNEXT_ALTKEY NANO_ALT_PERIOD
#define NANO_BRACKET_KEY NANO_ALT_BRACKET
#define NANO_EXTCMD_KEY NANO_CONTROL_X
+#ifndef NANO_SMALL
+# define NANO_NEXTWORD_KEY NANO_CONTROL_SPACE
+# define NANO_PREVWORD_KEY NANO_ALT_SPACE
+#endif
#define TOGGLE_CONST_KEY NANO_ALT_C
#define TOGGLE_AUTOINDENT_KEY NANO_ALT_I
/* public functions in global.c */
int length_of_list(const shortcut *s);
void shortcut_init(int unjustify);
+#ifdef DEBUG
void thanks_for_all_the_fish(void);
+#endif
int check_operating_dir(char *currpath, int allow_tabcomp);
#endif
+#ifndef NANO_SMALL
+int do_next_word_void(void);
+int do_prev_word_void(void);
+#endif /* !NANO_SMALL */
+
int do_writeout(char *path, int exiting, int append);
int do_gotoline(int line, int save_pos);
int is_whole_word(int curr_pos, filestruct *fileptr, char *searchword);
void titlebar(char *path);
void previous_line(void);
void center_cursor(void);
-void bottombars(shortcut *s);
+void bottombars(const shortcut *s);
void blank_statusbar_refresh(void);
void nperror(const char *s);
void *mallocstrcpy(char *dest, char *src);
#ifdef ENABLE_NANORC
-#ifndef NANO_SMALL
+#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else
#ifdef DEBUG
fprintf(stderr,
"Starting a new syntax type\n");
- fprintf(stderr, "string val=%s\n", tmp);
+ fprintf(stderr, "string val=%s\n", nameptr);
#endif
} else {
#include "proto.h"
#include "nano.h"
-#ifndef NANO_SMALL
+#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else
#include "nano.h"
#include "proto.h"
-#ifndef NANO_SMALL
+#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
+#include <assert.h>
#include "proto.h"
#include "nano.h"
-#ifndef NANO_SMALL
+#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else
reset_cursor();
}
-void onekey(char *keystroke, const char *desc, int len)
+/* Write a shortcut key to the help area at the bottom of the window.
+ * keystroke is e.g. "^G" and desc is e.g. "Get Help".
+ * We are careful to write exactly len characters, even if len is
+ * very small and keystroke and desc are long. */
+static void onekey(const char *keystroke, const char *desc, int len)
{
- int i;
-
wattron(bottomwin, A_REVERSE);
- waddstr(bottomwin, keystroke);
+ waddnstr(bottomwin, keystroke, len);
wattroff(bottomwin, A_REVERSE);
- waddch(bottomwin, ' ');
- waddnstr(bottomwin, desc, len - 3);
- for (i = strlen(desc); i < len - 3; i++)
- waddch(bottomwin, ' ');
+ len -= strlen(keystroke);
+ if (len > 0) {
+ waddch(bottomwin, ' ');
+ len--;
+ waddnstr(bottomwin, desc, len);
+ len -= strlen(desc);
+ for (; len > 0; len--)
+ waddch(bottomwin, ' ');
+ }
}
void clear_bottomwin(void)
mvwaddstr(bottomwin, 2, 0, hblank);
}
-void bottombars(shortcut *s)
+void bottombars(const shortcut *s)
{
int i, j, numcols;
- char keystr[10];
- shortcut *t;
+ char keystr[4];
int slen;
- if (s == main_list)
- slen = MAIN_VISIBLE;
- else
- slen = length_of_list(s);
-
if (ISSET(NO_HELP))
return;
+ if (s == main_list) {
+ slen = MAIN_VISIBLE;
+ assert(MAIN_VISIBLE <= length_of_list(s));
+ } else
+ slen = length_of_list(s);
+
#ifdef ENABLE_COLOR
color_on(bottomwin, COLOR_BOTTOMBARS);
if (!colors[COLOR_BOTTOMBARS - FIRST_COLORNUM].set ||
wattroff(bottomwin, A_REVERSE);
#endif
- /* Determine how many extra spaces are needed to fill the bottom of the screen */
- if (slen < 2)
- numcols = 6;
- else
- numcols = (slen + (slen % 2)) / 2;
+ /* There will be this many columns of shortcuts */
+ numcols = (slen + (slen % 2)) / 2;
clear_bottomwin();
- t = s;
for (i = 0; i < numcols; i++) {
for (j = 0; j <= 1; j++) {
- wmove(bottomwin, 1 + j, i * ((COLS - 1) / numcols));
+ wmove(bottomwin, 1 + j, i * (COLS / numcols));
- if (t->val < 97)
- snprintf(keystr, 10, "^%c", t->val + 64);
+#ifndef NANO_SMALL
+ if (s->val == NANO_CONTROL_SPACE)
+ strcpy(keystr, "^ ");
else
- snprintf(keystr, 10, "M-%c", t->val - 32);
+#endif /* !NANO_SMALL */
+ if (s->val > 0) {
+ if (s->val < 64)
+ sprintf(keystr, "^%c", s->val + 64);
+ else
+ sprintf(keystr, "M-%c", s->val - 32);
+ } else if (s->altval > 0)
+ sprintf(keystr, "M-%c", s->altval);
- onekey(keystr, t->desc, (COLS - 1) / numcols);
+ onekey(keystr, s->desc, COLS / numcols);
- if (t->next == NULL)
- break;
- t = t->next;
- }
-
+ s = s->next;
+ if (s == NULL)
+ goto break_completely_out;
+ }
}
+break_completely_out:
#ifdef ENABLE_COLOR
color_off(bottomwin, COLOR_BOTTOMBARS);
#endif
wrefresh(bottomwin);
-
}
/* If modified is not already set, set it and update titlebar */
char *yesstr; /* String of yes characters accepted */
char *nostr; /* Same for no */
char *allstr; /* And all, surprise! */
- char shortstr[5]; /* Temp string for above */
#ifndef DISABLE_MOUSE
#ifdef NCURSES_MOUSE_VERSION
MEVENT mevent;
/* Remove gettext call for keybindings until we clear the thing up */
if (!ISSET(NO_HELP)) {
+ char shortstr[3]; /* Temp string for Y, N, A */
+
wmove(bottomwin, 1, 0);
- snprintf(shortstr, 3, " %c", yesstr[0]);
+ sprintf(shortstr, " %c", yesstr[0]);
onekey(shortstr, _("Yes"), 16);
if (all) {
- snprintf(shortstr, 3, " %c", allstr[0]);
+ shortstr[1] = allstr[0];
onekey(shortstr, _("All"), 16);
}
wmove(bottomwin, 2, 0);
- snprintf(shortstr, 3, " %c", nostr[0]);
+ shortstr[1] = nostr[0];
onekey(shortstr, _("No"), 16);
onekey("^C", _("Cancel"), 16);