DLR's latest and greatest

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1256 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Chris Allegretta 2002-07-29 23:46:38 +00:00
parent d793cc186f
commit d865da108f
5 changed files with 88 additions and 48 deletions

View File

@ -3,6 +3,27 @@ CVS code -
- Translation updates (see po/ChangeLog for details).
- configure.ac:
- Added pt_BR to ALL_LINGUAS (Jordi).
- files.c:
real_dir_from_tilde()
- Rework to use getpwent() exclusively and end reliance on
$HOME. Adapted from equivalent code in do_rcfile(). (DLR)
input_tab()
- Most likely fixed the check marked with FIXME, so that tab
completion works properly when we're trying to tab-complete a
username and the string already contains data. (DLR)
- nano.c:
do_next_word(), do_prev_word()
- If we're on the last/first line of the file, don't center the
screen; Pico doesn't in the former case. (DLR)
do_backspace()
- Rework to call edit_refresh() regardless of the value of
current_x if ENABLE_COLOR is defined, so that multiple-line
color regexes are properly updated onscreen as they are in
do_delete(). (DLR)
do_delete()
- Rework to only call edit_refresh() unconditionally if
ENABLE_COLOR is defined; if it isn't, and we're not deleting
the end of the line, only call update_line(). (DLR)
GNU nano 1.1.10 - 07/25/2002
- General:
@ -72,7 +93,7 @@ GNU nano 1.1.10 - 07/25/2002
- Add a comment to nanorc.sample warning that an out-of-range
negative value for fill can make nano die complaining that
the screen is too small (which may not be immediately
obvious. (DLR)
obvious). (DLR)
- There were some opendir() calls in files.c without
corresponding closedir() calls; add them. (DLR)
- Move align() and null_at() from nano.c to utils.c, and move

48
files.c
View File

@ -1899,7 +1899,7 @@ int do_writeout_void(void)
*/
char *real_dir_from_tilde(char *buf)
{
char *dirtmp = NULL, *find_user = NULL;
char *dirtmp = NULL;
int i = 1;
struct passwd *userdata;
@ -1908,16 +1908,15 @@ char *real_dir_from_tilde(char *buf)
if (buf[0] == '~') {
if (buf[1] == 0 || buf[1] == '/') {
if (getenv("HOME") != NULL) {
free(dirtmp);
dirtmp = charalloc(strlen(buf) + 2 + strlen(getenv("HOME")));
sprintf(dirtmp, "%s%s", getenv("HOME"), &buf[1]);
}
/* Determine home directory using getpwent(), don't rely on
$HOME */
uid_t euid = geteuid();
do {
userdata = getpwent();
} while (userdata != NULL && userdata->pw_uid != euid);
}
else {
char *find_user = NULL;
/* Figure how how much of the str we need to compare */
for (i = 1; buf[i] != '/' && buf[i] != 0; i++)
@ -1926,21 +1925,18 @@ char *real_dir_from_tilde(char *buf)
find_user = mallocstrcpy(find_user, &buf[1]);
find_user[i - 1] = '\0';
for (userdata = getpwent(); userdata != NULL &&
strcmp(userdata->pw_name, find_user);
userdata = getpwent());
for (userdata = getpwent(); userdata != NULL &&
strcmp(userdata->pw_name, find_user);
userdata = getpwent());
free(find_user);
}
endpwent();
if (userdata != NULL) { /* User found */
free(dirtmp);
dirtmp = charalloc(strlen(buf) + 2 + strlen(userdata->pw_dir));
sprintf(dirtmp, "%s%s", userdata->pw_dir, &buf[i]);
}
endpwent();
if (userdata != NULL) { /* User found */
free(dirtmp);
dirtmp = charalloc(strlen(buf) + 2 + strlen(userdata->pw_dir));
sprintf(dirtmp, "%s%s", userdata->pw_dir, &buf[i]);
}
}
@ -2189,9 +2185,15 @@ char *input_tab(char *buf, int place, int *lastwastab, int *newplace, int *list)
/* If the word starts with `~' and there is no slash in the word,
* then try completing this word as a username. */
/* FIXME -- this check is broken! */
if (*tmp == '~' && !strchr(tmp, '/'))
/* If the original string begins with a tilde, and the part
we're trying to tab-complete doesn't contain a slash, copy
the part we're tab-completing into buf, so tab completion
will result in buf's containing only the tab-completed
username. */
if (buf[0] == '~' && !strchr(tmp, '/')) {
buf = mallocstrcpy(buf, tmp);
matches = username_tab_completion(tmp, &num_matches);
}
/* Try to match everything in the current working directory that
* matches. */

View File

@ -378,9 +378,7 @@ void shortcut_init(int unjustify)
nano_reverse_msg = _("Search backwards");
nano_dos_msg = _("Write file out in DOS format");
nano_mac_msg = _("Write file out in Mac format");
#ifndef NANO_SMALL
nano_backup_msg = _("Back up original file when saving");
#endif
#ifdef HAVE_REGEX_H
nano_regexp_msg = _("Use regular expressions");
nano_bracket_msg = _("Find other bracket");
@ -589,7 +587,7 @@ void shortcut_init(int unjustify)
sc_init_one(&whereis_list, NANO_OTHERSEARCH_KEY, _("Replace"),
IFHELP(nano_replace_msg, 0), 0, 0, VIEW, do_replace);
sc_init_one(&whereis_list, NANO_FROMSEARCHTOGOTO_KEY, _("Go To Line"),
sc_init_one(&whereis_list, NANO_FROMSEARCHTOGOTO_KEY, _("Go To Line"),
IFHELP(nano_goto_msg, 0), 0, 0, VIEW, do_gotoline_void);
#ifndef NANO_SMALL

59
nano.c
View File

@ -529,8 +529,7 @@ int no_help(void)
return ISSET(NO_HELP) ? 2 : 0;
}
#if defined(DISABLE_JUSTIFY) || defined(DISABLE_SPELLER) || \
defined(DISABLE_HELP) || defined(NANO_SMALL)
#if defined(DISABLE_JUSTIFY) || defined(DISABLE_SPELLER) || defined(DISABLE_HELP) || defined(NANO_SMALL)
void nano_disabled_msg(void)
{
statusbar(_("Sorry, support for this function has been disabled"));
@ -691,8 +690,13 @@ int do_next_word(void)
placewewant = xplustabs();
if (current->lineno >= editbot->lineno)
edit_update(current, CENTER);
if (current->lineno >= editbot->lineno) {
/* If we're on the last line, don't center the screen. */
if (current->lineno == filebot->lineno)
edit_refresh();
else
edit_update(current, CENTER);
}
else {
/* If we've jumped lines, refresh the old line. We can't just
use current->prev here, because we may have skipped over some
@ -746,8 +750,13 @@ int do_prev_word(void)
placewewant = xplustabs();
if (current->lineno <= edittop->lineno)
edit_update(current, CENTER);
if (current->lineno <= edittop->lineno) {
/* If we're on the first line, don't center the screen. */
if (current->lineno == fileage->lineno)
edit_refresh();
else
edit_update(current, CENTER);
}
else {
/* If we've jumped lines, refresh the old line. We can't just
use current->prev here, because we may have skipped over some
@ -980,6 +989,7 @@ void do_early_abort(void)
int do_backspace(void)
{
int refresh = 0;
if (current_x > 0) {
assert(current_x <= strlen(current->data));
/* Let's get dangerous */
@ -994,6 +1004,9 @@ int do_backspace(void)
mark_beginx--;
#endif
do_left();
#ifdef ENABLE_COLOR
refresh = 1;
#endif
} else {
filestruct *previous;
const filestruct *tmp;
@ -1046,16 +1059,20 @@ int do_backspace(void)
fprintf(stderr, _("After, data = \"%s\"\n"), current->data);
#endif
UNSET(KEEP_CUTBUFFER);
edit_refresh();
refresh = 1;
}
totsize--;
set_modified();
if (refresh)
edit_refresh();
return 1;
}
int do_delete(void)
{
int refresh = 0;
/* blbf -> blank line before filebot (see below) */
int blbf = 0;
@ -1070,7 +1087,9 @@ int do_delete(void)
strlen(current->data) - current_x);
align(&current->data);
#ifdef ENABLE_COLOR
refresh = 1;
#endif
} 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. */
@ -1091,16 +1110,17 @@ int do_delete(void)
unlink_node(foo);
delete_node(foo);
renumber(current);
/* Have to renumber before doing update_line(). */
update_line(current, current_x);
totlines--;
refresh = 1;
} else
return 0;
totsize--;
set_modified();
UNSET(KEEP_CUTBUFFER);
edit_refresh();
update_line(current, current_x);
if (refresh)
edit_refresh();
return 1;
}
@ -1925,8 +1945,7 @@ int do_tab(void)
return 1;
}
#if !defined(DISABLE_WRAPPING) && !defined(NANO_SMALL) || \
!defined(DISABLE_JUSTIFY)
#if !defined(DISABLE_WRAPPING) && !defined(NANO_SMALL) || !defined(DISABLE_JUSTIFY)
/* The "indentation" of a line is the white-space between the quote part
* and the non-white-space of the line. */
size_t indent_length(const char *line) {
@ -1974,8 +1993,8 @@ static int justify_format(int changes_allowed, filestruct *line,
*front = ' ';
}
/* these tests are safe since line->data + skip is not a space */
if (*front == ' ' && *(front-1) == ' ' && *(front-2) != '.' &&
*(front-2) != '!' && *(front-2) != '?') {
if (*front == ' ' && *(front - 1) == ' ' && *(front - 2) != '.' &&
*(front - 2) != '!' && *(front - 2) != '?') {
/* Now *front is a space we want to remove. We do that by
* simply failing to assign it to *back */
if (!changes_allowed)
@ -2001,7 +2020,7 @@ static int justify_format(int changes_allowed, filestruct *line,
return 1;
/* This assert merely documents a fact about the loop above. */
assert(changes_allowed || back==front);
assert(changes_allowed || back == front);
/* Now back is the new end of line->data. */
if (back != front) {
@ -2057,7 +2076,7 @@ static int quotes_match(const char *a_line, size_t a_quote,
IFREG(const char *b_line, const regex_t *qreg)) {
/* Here is the assumption about a_quote: */
assert(a_quote == quote_length(IFREG(a_line, qreg)));
return a_quote==quote_length(IFREG(b_line, qreg)) &&
return a_quote == quote_length(IFREG(b_line, qreg)) &&
!strncmp(a_line, b_line, a_quote);
}
@ -2222,7 +2241,7 @@ int do_justify(void) {
#ifdef HAVE_REGEX_H
regex_t qreg; /* qreg is the compiled quotation regexp.
* We no longer care about quotestr */
* We no longer care about quotestr. */
int rc = regcomp(&qreg, quotestr, REG_EXTENDED);
if (rc) {
@ -2270,8 +2289,8 @@ int do_justify(void) {
}
}
} else {
/* this line is not part of a paragraph. Move down until we get
* to a non "blank" line */
/* This line is not part of a paragraph. Move down until we get
* to a non "blank" line. */
do {
/* There is no next paragraph, so nothing to justify. */
if (current->next == NULL)

2
nano.h
View File

@ -374,4 +374,4 @@ typedef enum {
/* Minimum fill length (space available for text before wrapping occurs) */
#define MIN_FILL_LENGTH 10
#endif /* !NANO_H */
#endif /* !NANO_H */