Added Ken's patch, DLR's latest fixes and a little cleanup to bottombars()

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1076 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2002-02-16 20:03:44 +00:00
parent 7e65d2f5ad
commit bc72e366d2
7 changed files with 102 additions and 77 deletions

View File

@ -4,7 +4,8 @@ CVS code -
- New option, noconvert (-N, --noconvert) to completely stop - New option, noconvert (-N, --noconvert) to completely stop
the translation of files from DOS or Mac format (DLR). the translation of files from DOS or Mac format (DLR).
- New functions wheck_writable_directory() and safe_tempnam() - New functions wheck_writable_directory() and safe_tempnam()
to get around the tempnam warning. (DLR) Needs testing to get around the tempnam warning. More improvements (DLR)
Still eeds testing.
- Added DOS and Mac format options to write file routine. - Added DOS and Mac format options to write file routine.
Changes to shortcut_init() and do_writeout(). Changes to shortcut_init() and do_writeout().
- Removed stupid static definitions of toggles and shortcut - Removed stupid static definitions of toggles and shortcut
@ -31,12 +32,18 @@ CVS code -
main() main()
- Add 407 as equiv of 26, this seems to be sent when using - Add 407 as equiv of 26, this seems to be sent when using
^Z in linux console with keypad() enabled. ^Z in linux console with keypad() enabled.
- rcfile.c:
- Get rid of unneeded relativechars from rcopts (DLR).
- search.c
do_replace(), findnextstr()
- Fixes for various search issues (Ken Tyler)
- winio.c: - winio.c:
do_cursorpos() do_cursorpos()
- Rewritten to show col place as well as charcter place, without - Rewritten to show col place as well as charcter place, without
needing an entirely separate flag. needing an entirely separate flag.
bottombars(), onekey() bottombars(), onekey()
- Make bottom list dynamic with screen size (Guus Sliepen & Chris). - Make bottom list dynamic with screen size (Guus Sliepen & Chris).
- More cleanups w/width of shortcut.
- utils.c: - utils.c:
strstrwrapper() strstrwrapper()
- NANO_SMALL test was backwards (Ken Tyler). - NANO_SMALL test was backwards (Ken Tyler).

57
files.c
View File

@ -1024,36 +1024,35 @@ char *get_full_path(const char *origpath)
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
/* /*
* This function accepts a path and a pointer to an integer, and returns * This function accepts a path and returns the full path (via
* the full path (via get_full_path()). It also sets the integer * get_full_path()). On error, if the path doesn't reference a
* pointer's referenced value to 1 if the full path is writable, and 0 * directory, or if the directory isn't writable, it returns NULL.
* otherwise. On error, it returns NULL, and sets the pointer's
* referenced value to 0.
*/ */
char *check_writable_directory(const char *path, int *writable) { char *check_writable_directory(const char *path) {
char *full_path = get_full_path(path); char *full_path = get_full_path(path);
int writable;
struct stat fileinfo; struct stat fileinfo;
/* if get_full_path() failed, set *writable to 0 and return NULL */ /* if get_full_path() failed, return NULL */
if (!full_path) { if (!full_path)
*writable = 0;
return NULL; return NULL;
}
else { /* otherwise, stat() the full path to see if it's writable by the
/* otherwise, stat() the full path to see if it's writable by the user; set writable to 1 if it is, or 0 if it isn't */
user; set *writable to 1 if it is, or 0 if it isn't */ stat(path, &fileinfo);
stat(path, &fileinfo); if (fileinfo.st_mode & S_IWUSR)
if (fileinfo.st_mode & S_IWUSR) writable = 1;
*writable = 1; else
else writable = 0;
*writable = 0;
}
/* if the full path doesn't end in a slash (meaning get_full_path() /* if the full path doesn't end in a slash (meaning get_full_path()
found that it isn't a directory) or isn't writable, return NULL */ found that it isn't a directory) or isn't writable, free full_path
if (full_path[strlen(full_path) - 1] != '/' || *writable == 0) and return NULL */
if (full_path[strlen(full_path) - 1] != '/' || writable == 0) {
free(full_path);
return NULL; return NULL;
}
/* otherwise, return the full path */ /* otherwise, return the full path */
return full_path; return full_path;
@ -1064,12 +1063,18 @@ char *check_writable_directory(const char *path, int *writable) {
* way that tempnam() does, determines the location for its temporary * way that tempnam() does, determines the location for its temporary
* file the same way that tempnam() does, safely creates the temporary * file the same way that tempnam() does, safely creates the temporary
* file there via mkstemp(), and returns the name of the temporary file * file there via mkstemp(), and returns the name of the temporary file
* the same way that tempnam() does. * the same way that tempnam() does. It does not reference the value of
* TMP_MAX because the total number of random filenames that it can
* generate using one prefix is equal to 256**6, which is a sufficiently
* large number to handle most cases. Since the behavior after tempnam()
* generates TMP_MAX random filenames is implementation-defined, my
* implementation is to go on generating random filenames regardless of
* it.
*/ */
char *safe_tempnam(const char *dirname, const char *filename_prefix) { char *safe_tempnam(const char *dirname, const char *filename_prefix) {
char *buf, *tempdir = NULL, *full_tempdir = NULL; char *buf, *tempdir = NULL, *full_tempdir = NULL;
int writable = 0, filedesc; int filedesc;
/* if $TMPDIR is set and non-empty, set tempdir to it, run it through /* if $TMPDIR is set and non-empty, set tempdir to it, run it through
get_full_path(), and save the result in full_tempdir; otherwise, get_full_path(), and save the result in full_tempdir; otherwise,
@ -1080,7 +1085,7 @@ char *safe_tempnam(const char *dirname, const char *filename_prefix) {
get_full_path(), and save the result in full_tempdir */ get_full_path(), and save the result in full_tempdir */
tempdir = charalloc(strlen(getenv("TMPDIR")) + 1); tempdir = charalloc(strlen(getenv("TMPDIR")) + 1);
sprintf(tempdir, "%s", getenv("TMPDIR")); sprintf(tempdir, "%s", getenv("TMPDIR"));
full_tempdir = check_writable_directory(tempdir, &writable); full_tempdir = check_writable_directory(tempdir);
/* we don't need the value of tempdir anymore */ /* we don't need the value of tempdir anymore */
free(tempdir); free(tempdir);
@ -1094,7 +1099,7 @@ char *safe_tempnam(const char *dirname, const char *filename_prefix) {
if (dirname) { if (dirname) {
tempdir = charalloc(strlen(dirname) + 1); tempdir = charalloc(strlen(dirname) + 1);
strcpy(tempdir, dirname); strcpy(tempdir, dirname);
full_tempdir = check_writable_directory(tempdir, &writable); full_tempdir = check_writable_directory(tempdir);
/* we don't need the value of tempdir anymore */ /* we don't need the value of tempdir anymore */
free(tempdir); free(tempdir);
@ -1106,7 +1111,7 @@ char *safe_tempnam(const char *dirname, const char *filename_prefix) {
if (!full_tempdir) { if (!full_tempdir) {
tempdir = charalloc(strlen(P_tmpdir) + 1); tempdir = charalloc(strlen(P_tmpdir) + 1);
strcpy(tempdir, P_tmpdir); strcpy(tempdir, P_tmpdir);
full_tempdir = check_writable_directory(tempdir, &writable); full_tempdir = check_writable_directory(tempdir);
/* we don't need the value of tempdir anymore */ /* we don't need the value of tempdir anymore */
free(tempdir); free(tempdir);

View File

@ -224,7 +224,7 @@ char *get_full_path(const char *origpath);
#endif #endif
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
char *check_writable_directory(const char *path, int *writable); char *check_writable_directory(const char *path);
char *safe_tempnam(const char *dirname, const char *filename_prefix); char *safe_tempnam(const char *dirname, const char *filename_prefix);
#endif #endif

View File

@ -40,7 +40,7 @@
#define _(string) (string) #define _(string) (string)
#endif #endif
#define NUM_RCOPTS 21 #define NUM_RCOPTS 20
/* Static stuff for the nanorc file */ /* Static stuff for the nanorc file */
rcoption rcopts[NUM_RCOPTS] = { rcoption rcopts[NUM_RCOPTS] = {
@ -63,7 +63,6 @@ rcoption rcopts[NUM_RCOPTS] = {
{"multibuffer", MULTIBUFFER}, {"multibuffer", MULTIBUFFER},
{"smooth", SMOOTHSCROLL}, {"smooth", SMOOTHSCROLL},
{"keypad", ALT_KEYPAD}, {"keypad", ALT_KEYPAD},
{"relative", RELATIVECHARS},
{"noconvert", NO_CONVERT} {"noconvert", NO_CONVERT}
}; };

View File

@ -239,15 +239,14 @@ int is_whole_word(int curr_pos, filestruct *fileptr, char *searchword)
return FALSE; return FALSE;
} }
int past_editbuff; /* search is now looking through lines not displayed */ int past_editbuff; /* findnextstr() is now searching lines not displayed */
filestruct *findnextstr(int quiet, int bracket_mode, filestruct * begin, int beginx, filestruct *findnextstr(int quiet, int bracket_mode, filestruct * begin, int beginx,
char *needle) char *needle)
{ {
filestruct *fileptr; filestruct *fileptr;
char *searchstr, *rev_start = NULL, *found = NULL; char *searchstr, *rev_start = NULL, *found = NULL;
int current_x_find = 0; int current_x_find;
fileptr = current; fileptr = current;
past_editbuff = 0; past_editbuff = 0;
@ -315,13 +314,13 @@ filestruct *findnextstr(int quiet, int bracket_mode, filestruct * begin, int beg
else { /* reverse search */ else { /* reverse search */
current_x_find = current_x - 1; current_x_find = current_x - 1;
#if 0
/* Are we now back to the place where the search started) */ /* Are we now back to the place where the search started) */
if ((fileptr == begin) && (current_x_find > beginx)) if ((fileptr == begin) && (current_x_find > beginx))
search_last_line = 1; search_last_line = 1;
#endif
/* Make sure we haven't passed the begining of the string */ /* Make sure we haven't passed the begining of the string */
#if 1 /* Is this required here ? */ #if 0 /* Is this required here ? */
if (!(&fileptr->data[current_x_find] - fileptr->data)) if (!(&fileptr->data[current_x_find] - fileptr->data))
current_x_find++; current_x_find++;
#endif #endif
@ -596,7 +595,8 @@ int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx,
int wholewords, int *i) int wholewords, int *i)
{ {
int replaceall = 0, numreplaced = 0; int replaceall = 0, numreplaced = 0;
filestruct *fileptr;
filestruct *fileptr = NULL;
char *copy; char *copy;
switch (*i) { switch (*i) {
@ -624,7 +624,14 @@ int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx,
while (1) { while (1) {
/* Sweet optimization by Rocco here */ /* Sweet optimization by Rocco here */
#if 0
fileptr = findnextstr(replaceall, FALSE, begin, *beginx, prevanswer); fileptr = findnextstr(replaceall, FALSE, begin, *beginx, prevanswer);
#else
if (fileptr != 0)
fileptr = findnextstr(1, FALSE, begin, *beginx, prevanswer);
else
fileptr = findnextstr(replaceall || (search_last_line ? 1 : 0), FALSE, begin, *beginx, prevanswer);
#endif
/* No more matches. Done! */ /* No more matches. Done! */
if (!fileptr) if (!fileptr)
@ -663,17 +670,29 @@ int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx,
current->data = copy; current->data = copy;
totsize += strlen(current->data); totsize += strlen(current->data);
/* Stop bug where we replace a substring of the replacement text */ if (!ISSET(REVERSE_SEARCH)) {
current_x += strlen(last_replace) - 1; /* Stop bug where we replace a substring of the replacement text */
current_x += strlen(last_replace) - 1;
/* Adjust the original cursor position - COULD BE IMPROVED */ /* Adjust the original cursor position - COULD BE IMPROVED */
if (search_last_line) { if (search_last_line) {
*beginx += strlen(last_replace) - strlen(last_search); *beginx += strlen(last_replace) - strlen(last_search);
/* For strings that cross the search start/end boundary */ /* For strings that cross the search start/end boundary */
/* Don't go outside of allocated memory */ /* Don't go outside of allocated memory */
if (*beginx < 1) if (*beginx < 1)
*beginx = 1; *beginx = 1;
}
} else {
if (current_x > 1)
current_x--;
if (search_last_line) {
*beginx += strlen(last_replace) - strlen(last_search);
if (*beginx > strlen(current->data))
*beginx = strlen(current->data);
}
} }
edit_refresh(); edit_refresh();
@ -755,15 +774,23 @@ int do_replace(void)
/* save where we are */ /* save where we are */
begin = current; begin = current;
#if 0
/* why + 1 ? isn't this taken care of in findnextstr() ? */
beginx = current_x + 1; beginx = current_x + 1;
#else
beginx = current_x;
#endif
search_last_line = 0; search_last_line = 0;
numreplaced = do_replace_loop(prevanswer, begin, &beginx, FALSE, &i); numreplaced = do_replace_loop(prevanswer, begin, &beginx, FALSE, &i);
/* restore where we were */ /* restore where we were */
current = begin; current = begin;
#if 0
current_x = beginx - 1; current_x = beginx - 1;
#else
current_x = beginx;
#endif
renumber_all(); renumber_all();
edit_update(current, CENTER); edit_update(current, CENTER);
print_replaced(numreplaced); print_replaced(numreplaced);

View File

@ -112,16 +112,15 @@ char *strstrwrapper(char *haystack, char *needle, char *rev_start)
} else { } else {
char *i, *j; char *i, *j;
/* do quick check first */ /* do a quick search forward first */
if (!(regexec(&search_regexp, haystack, 10, regmatches, 0))) { if (!(regexec(&search_regexp, haystack, 10, regmatches, 0))) {
/* there is a match */ /* there's a match somewhere in the line - now search for it backwards, much slower */
for(i = rev_start ; i >= haystack ; --i) for(i = rev_start ; i >= haystack ; --i)
if (!(result = regexec(&search_regexp, i, 10, regmatches, 0))) { if (!(result = regexec(&search_regexp, i, 10, regmatches, 0))) {
j = i + regmatches[0].rm_so; j = i + regmatches[0].rm_so;
if (j <= rev_start) if (j <= rev_start)
return j; return j;
} }
} }
#endif #endif
} }

42
winio.c
View File

@ -598,7 +598,7 @@ void clear_bottomwin(void)
void bottombars(shortcut *s) void bottombars(shortcut *s)
{ {
int i, k; int i, j, numcols;
char keystr[10]; char keystr[10];
shortcut *t; shortcut *t;
int slen; int slen;
@ -620,41 +620,29 @@ void bottombars(shortcut *s)
/* Determine how many extra spaces are needed to fill the bottom of the screen */ /* Determine how many extra spaces are needed to fill the bottom of the screen */
if (slen < 2) if (slen < 2)
k = COLS / 6; numcols = 6;
else else
k = COLS / ((slen + (slen % 2)) / 2); numcols = (slen + (slen % 2)) / 2;
clear_bottomwin(); clear_bottomwin();
t = s; t = s;
for (i = 0; i < slen / 2; i++) { for (i = 0; i < numcols; i++) {
for (j = 0; j <= 1; j++) {
wmove(bottomwin, 1, i * k); wmove(bottomwin, 1 + j, i * ((COLS - 1) / numcols));
if (t->val < 97) if (t->val < 97)
snprintf(keystr, 10, "^%c", t->val + 64); snprintf(keystr, 10, "^%c", t->val + 64);
else else
snprintf(keystr, 10, "M-%c", t->val - 32); snprintf(keystr, 10, "M-%c", t->val - 32);
onekey(keystr, t->desc, k); onekey(keystr, t->desc, (COLS - 1) / numcols);
if (t->next == NULL) if (t->next == NULL)
break; break;
t = t->next; t = t->next;
}
wmove(bottomwin, 2, i * k);
if (t->val < 97)
snprintf(keystr, 10, "^%c", t->val + 64);
else
snprintf(keystr, 10, "M-%c", t->val - 32);
onekey(keystr, t->desc, k);
if (t->next == NULL)
break;
t = t->next;
} }