DB's latest patch, minus one totsize--. Also fixed a < in help_init that should be <=

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1206 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2002-05-12 19:52:15 +00:00
parent 403f8dc0a3
commit 6232d6659f
13 changed files with 190 additions and 156 deletions

View File

@ -29,6 +29,10 @@ CVS code -
- 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:
@ -37,6 +41,8 @@ CVS code -
- 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).
@ -44,6 +50,10 @@ CVS code -
- 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:
@ -57,13 +67,15 @@ CVS code -
- 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:

View File

@ -33,7 +33,7 @@
#include "proto.h"
#include "nano.h"
#ifndef NANO_SMALL
#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else

2
cut.c
View File

@ -27,7 +27,7 @@
#include "proto.h"
#include "nano.h"
#ifndef NANO_SMALL
#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else

View File

@ -37,7 +37,7 @@
#include "proto.h"
#include "nano.h"
#ifndef NANO_SMALL
#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else
@ -450,6 +450,13 @@ int do_insertfile(int loading_file)
}
#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);

View File

@ -26,7 +26,7 @@
#include "nano.h"
#include "proto.h"
#ifndef NANO_SMALL
#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else
@ -561,6 +561,15 @@ void shortcut_init(int unjustify)
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,
@ -820,13 +829,15 @@ void shortcut_init(int unjustify)
#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);
@ -871,29 +882,21 @@ void thanks_for_all_the_fish(void)
#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 */

2
move.c
View File

@ -27,7 +27,7 @@
#include "proto.h"
#include "nano.h"
#ifndef NANO_SMALL
#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else

153
nano.c
View File

@ -43,7 +43,7 @@
#include "proto.h"
#include "nano.h"
#ifndef NANO_SMALL
#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else
@ -100,7 +100,9 @@ RETSIGTYPE finish(int sigage)
/* Restore the old term settings */
tcsetattr(0, TCSANOW, &oldterm);
#ifdef DEBUG
thanks_for_all_the_fish();
#endif
exit(sigage);
}
@ -882,6 +884,11 @@ void do_next_word(void)
}
}
int do_next_word_void(void) {
do_next_word();
return 0;
}
/* the same thing for backwards */
void do_prev_word(void)
{
@ -955,6 +962,11 @@ void do_prev_word(void)
}
}
int do_prev_word_void(void) {
do_prev_word();
return 0;
}
#endif /* NANO_SMALL */
#ifndef DISABLE_WRAPPING
@ -1298,8 +1310,6 @@ int do_backspace(void)
int do_delete(void)
{
filestruct *foo;
/* blbf -> blank line before filebot (see below) */
int blbf = 0;
@ -1313,11 +1323,12 @@ int do_delete(void)
align(&current->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);
@ -1332,14 +1343,6 @@ int do_delete(void)
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
@ -2486,9 +2489,9 @@ int do_justify(void)
#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
@ -2612,64 +2615,60 @@ void help_init(void)
/* 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;
}
@ -2678,15 +2677,14 @@ void help_init(void)
/* 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
@ -3169,13 +3167,6 @@ int main(int argc, char *argv[])
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 */
@ -3310,19 +3301,16 @@ int main(int argc, char *argv[])
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
@ -3419,11 +3407,6 @@ int main(int argc, char *argv[])
#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-] */

10
nano.h
View File

@ -193,6 +193,9 @@ typedef struct syntaxtype {
/* 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
@ -256,6 +259,9 @@ typedef struct syntaxtype {
#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 */
@ -319,6 +325,10 @@ 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

View File

@ -105,7 +105,9 @@ extern toggle *toggles;
/* 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
@ -146,6 +148,11 @@ int add_open_file(int update);
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);
@ -193,7 +200,7 @@ void blank_statusbar(void);
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);

View File

@ -35,7 +35,7 @@
#ifdef ENABLE_NANORC
#ifndef NANO_SMALL
#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else
@ -222,7 +222,7 @@ void parse_syntax(FILE * rcstream, char *buf, char *ptr)
#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 {

View File

@ -29,7 +29,7 @@
#include "proto.h"
#include "nano.h"
#ifndef NANO_SMALL
#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else

View File

@ -30,7 +30,7 @@
#include "nano.h"
#include "proto.h"
#ifndef NANO_SMALL
#ifdef ENABLE_NLS
#include <libintl.h>
#define _(string) gettext(string)
#else

88
winio.c
View File

@ -25,10 +25,11 @@
#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
@ -578,17 +579,24 @@ void titlebar(char *path)
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)
@ -600,21 +608,21 @@ 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 ||
@ -622,40 +630,43 @@ void bottombars(shortcut *s)
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 */
@ -1396,7 +1407,6 @@ int do_yesno(int all, int leavecursor, char *msg, ...)
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;
@ -1420,18 +1430,20 @@ int do_yesno(int all, int leavecursor, char *msg, ...)
/* 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);