From 70047eef7d3ce129244ede19ad001bc3ab8a6d95 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Sat, 14 Jun 2003 20:41:34 +0000 Subject: [PATCH] miscellaneous cleanups, updates, and fixes git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1506 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 31 ++++++++ TODO | 33 +++++---- configure.ac | 4 +- cut.c | 2 +- files.c | 40 +++++------ global.c | 8 +-- nano.c | 14 ++-- nanorc.sample | 190 +++++++++++++++++++++++++++++--------------------- rcfile.c | 4 +- search.c | 2 +- utils.c | 7 +- winio.c | 72 +++++++++++++++---- 12 files changed, 259 insertions(+), 148 deletions(-) diff --git a/ChangeLog b/ChangeLog index 604d26e6..21abf8a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,40 @@ CVS code - - General: - Translation updates (see po/ChangeLog for details). + - Change uncast nrealloc()s assigned to char pointers/arrays to + charealloc()s, and cast all other nrealloc()s and all + nmalloc()s. (David Benbennick and DLR) +- utils.c: + align() + - Tweak to avoid a potential problem when strp is non-NULL but + *strp is NULL. (David Benbennick) +- winio.c: + nanogetstr() + - Fix problem with search history where a temporary string + added at the bottom of the history (but which was not in the + history) would not be preserved after scrolling down to the + blank bottom entry and then scrolling back up. (DLR) +- configure.ac: + - Change the program used to detect a broken regexec() function + so that it works properly, using information found at + http://sources.redhat.com/ml/libc-hacker/2001-06/msg00015.html. + (DLR) +- nanorc.sample: + - Revised comment explaining the non-escaping of quotes to cover + non-escaping of all shell-interpreted characters. (DLR) + - Fixes to the descriptions and examples in the comments, and + changes to some default values. (David Benbennick and DLR) + - Add regexes for Perl syntax. (Richard Smith, tweaked for + greater efficiency by David Benbennick) + - Add regexes for Java source syntax. (David Benbennick) + Regex for C++-style comments (colored the same way as C-style + comments) added by DLR. - THANKS: - Added Laurentiu Buzdugan, for Romanian. - Added Geir Helland, for Norwegian Bokmål. +- TODO: + - Move the items for nano 1.2 to the "Old Requests" section, + and mark color syntax highlighting as done. (David Benbennick) - nano.1, nanorc.5: - Formatting improvements by Jean-Philippe Guérard. diff --git a/TODO b/TODO index 4ce0a2fc..09698d2d 100644 --- a/TODO +++ b/TODO @@ -1,20 +1,6 @@ TODO file (? means the feature may be implemented, but not definitely) ----------------------------------------------------------------------------- -For version 1.2: -- Single line scroll up/down? [DONE] -- Color syntax highlighting? (certainly seems like there's a demand for it.) -- .nanorc [DONE] -- Backup making (filename~)? [DONE] -- Search (etc.) string history [DONE] -- Implement Pico's -j and -g flags, as they are pretty easy to do. [DONE] -- Make mouse support work with clicking on the shortcuts (-m). Must - make global variable pointing to current shortcut list to determine what - keystroke to ungetch(). [DONE]. -- Implement -o (chroot of sorts) [DONE] -- Allow -r to take a negative argument, meaning right margin instead of - left (allows resizing that way), formerly -W arg. [DONE] - For version 1.4: - UTF-8 support. - Support for Pico's paragraph searching ability. @@ -24,11 +10,28 @@ For version 1.4: - Spell check selected text only. - Make "To line" (^W^T) and "Read from Command" (^R^X) re-enter their parent menu when their keystroke is entered a second time (^W^T^T and - (^R^X^X)(requires figuring out when to keep cursor pos and when not to). + (^R^X^X)(requires figuring out when to keep cursor pos and when not + to). - Fix resetstatuspos global which we shouldn't have. Old requests: +For version 1.2: +- Single line scroll up/down? [DONE] +- Color syntax highlighting? (certainly seems like there's a demand for + it.) [DONE] +- .nanorc [DONE] +- Backup making (filename~)? [DONE] +- Search (etc.) string history [DONE] +- Implement Pico's -j and -g flags, as they are pretty easy to do. + [DONE] +- Make mouse support work with clicking on the shortcuts (-m). Must + make global variable pointing to current shortcut list to determine + what keystroke to ungetch(). [DONE]. +- Implement -o (chroot of sorts) [DONE] +- Allow -r to take a negative argument, meaning right margin instead of + left (allows resizing that way), formerly -W arg. [DONE] + For version 1.0: - Implement Spelling [DONE] - Implement Help [DONE] diff --git a/configure.ac b/configure.ac index c3cacda7..1820c548 100644 --- a/configure.ac +++ b/configure.ac @@ -43,9 +43,9 @@ AC_CHECK_HEADER(regex.h, AC_TRY_RUN([ #include #include -int main() { regex_t reg; size_t n; regmatch_t r; regcomp(®, ".", 0); regexec(®, "", n, &r, 0); return 0; }], +int main () { regex_t reg; size_t n = 1; regmatch_t r; regcomp(®, "\\<", 0); regexec(®, "", n, &r, 0); regfree(®); return 0; }], AC_MSG_RESULT(no), - AC_MSG_RESULT(yes); AC_DEFINE(BROKEN_REGEXEC, 1, [Define this if your regexec() function segfaults when passed an empty string.]) + AC_MSG_RESULT(yes); AC_DEFINE(BROKEN_REGEXEC, 1, [Define this if your regexec() function segfaults when passed an empty string under certain conditions.]) ) ) diff --git a/cut.c b/cut.c index 43b2ffdf..aca59292 100644 --- a/cut.c +++ b/cut.c @@ -361,7 +361,7 @@ int do_uncut_text(void) size_t buf_len = strlen(cutbuffer->data); size_t cur_len = strlen(current->data); - current->data = nrealloc(current->data, cur_len + buf_len + 1); + current->data = charealloc(current->data, cur_len + buf_len + 1); memmove(current->data + current_x + buf_len, current->data + current_x, cur_len - current_x + 1); strncpy(current->data + current_x, cutbuffer->data, buf_len); diff --git a/files.c b/files.c index 1d88bed0..5e19c9fa 100644 --- a/files.c +++ b/files.c @@ -236,7 +236,7 @@ int read_file(FILE *f, const char *filename, int quiet) decrease it at all. We do free it at the end, though. */ if (i >= bufx - 1) { bufx += 128; - buf = nrealloc(buf, bufx); + buf = charealloc(buf, bufx); } buf[i] = input; buf[i + 1] = '\0'; @@ -645,7 +645,7 @@ int do_insertfile_void(void) /* Create a new openfilestruct node. */ openfilestruct *make_new_opennode(openfilestruct *prevnode) { - openfilestruct *newnode = nmalloc(sizeof(openfilestruct)); + openfilestruct *newnode = (openfilestruct *)nmalloc(sizeof(openfilestruct)); newnode->filename = NULL; newnode->fileage = NULL; @@ -1038,7 +1038,7 @@ char *get_full_path(const char *origpath) align(&d_here); if (strcmp(d_here, "/")) { - d_here = nrealloc(d_here, strlen(d_here) + 2); + d_here = charealloc(d_here, strlen(d_here) + 2); strcat(d_here, "/"); } @@ -1060,9 +1060,9 @@ char *get_full_path(const char *origpath) if (path_only) { tmp = d_there[strlen(d_there) - 1]; if (tmp != '/') { - d_there = nrealloc(d_there, strlen(d_there) + 2); + d_there = charealloc(d_there, strlen(d_there) + 2); strcat(d_there, "/"); - d_there_file = nrealloc(d_there_file, strlen(d_there_file) + 2); + d_there_file = charealloc(d_there_file, strlen(d_there_file) + 2); strcat(d_there_file, "/"); } } @@ -1110,7 +1110,7 @@ char *get_full_path(const char *origpath) /* add a slash to d_there, unless it's "/", in which case we don't need it */ if (strcmp(d_there, "/")) { - d_there = nrealloc(d_there, strlen(d_there) + 2); + d_there = charealloc(d_there, strlen(d_there) + 2); strcat(d_there, "/"); } } @@ -1223,7 +1223,7 @@ char *safe_tempnam(const char *dirname, const char *filename_prefix) strcpy(full_tempdir, "/tmp/"); } - full_tempdir = nrealloc(full_tempdir, strlen(full_tempdir) + 12); + full_tempdir = charealloc(full_tempdir, strlen(full_tempdir) + 12); /* like tempnam(), use only the first 5 characters of the prefix */ strncat(full_tempdir, filename_prefix, 5); @@ -1970,7 +1970,7 @@ char **username_tab_completion(char *buf, int *num_matches) struct passwd *userdata; *num_matches = 0; - matches = nmalloc(BUFSIZ * sizeof(char *)); + matches = (char **)nmalloc(BUFSIZ * sizeof(char *)); strcat(buf, "*"); @@ -2017,7 +2017,7 @@ char **cwd_tab_completion(char *buf, int *num_matches) DIR *dir; struct dirent *next; - matches = nmalloc(BUFSIZ * sizeof(char *)); + matches = (char **)nmalloc(BUFSIZ * sizeof(char *)); /* Stick a wildcard onto the buf, for later use */ strcat(buf, "*"); @@ -2140,8 +2140,8 @@ char *input_tab(char *buf, int place, int *lastwastab, int *newplace, int *list) /* Make a local copy of the string -- up to the position of the cursor */ - matchbuf = (char *)nmalloc((strlen(buf) + 2) * sizeof(char)); - memset(matchbuf, '\0', (strlen(buf) + 2)); + matchbuf = charalloc(strlen(buf) + 2); + memset(matchbuf, '\0', strlen(buf) + 2); strncpy(matchbuf, buf, place); tmp = matchbuf; @@ -2197,7 +2197,7 @@ char *input_tab(char *buf, int place, int *lastwastab, int *newplace, int *list) break; case 1: - buf = nrealloc(buf, strlen(buf) + strlen(matches[0]) + 1); + buf = charealloc(buf, strlen(buf) + strlen(matches[0]) + 1); if (buf[0] != '\0' && strstr(buf, "/") != NULL) { for (tmp = buf + strlen(buf); *tmp != '/' && tmp != buf; @@ -2260,7 +2260,7 @@ char *input_tab(char *buf, int place, int *lastwastab, int *newplace, int *list) (i == num_matches || matches[i] != 0)) { /* All the matches have the same character at pos+1, so paste it into buf... */ - buf = nrealloc(buf, strlen(buf) + 2); + buf = charealloc(buf, strlen(buf) + 2); strncat(buf, matches[0] + pos, 1); *newplace += 1; pos++; @@ -2449,7 +2449,7 @@ char **browser_init(const char *path, int *longest, int *numents) rewinddir(dir); *longest += 10; - filelist = nmalloc(*numents * sizeof (char *)); + filelist = (char **)nmalloc(*numents * sizeof (char *)); if (!strcmp(path, "/")) path = ""; @@ -2876,12 +2876,12 @@ void load_history(void) if (homenv != NULL) { - nanohist = nrealloc(nanohist, strlen(homenv) + 15); + nanohist = charealloc(nanohist, strlen(homenv) + 15); sprintf(nanohist, "%s/.nano_history", homenv); } else { userage = getpwuid(geteuid()); endpwent(); - nanohist = nrealloc(nanohist, strlen(userage->pw_dir) + 15); + nanohist = charealloc(nanohist, strlen(userage->pw_dir) + 15); sprintf(nanohist, "%s/.nano_history", userage->pw_dir); } @@ -2931,12 +2931,12 @@ void save_history(void) return; if (homenv != NULL) { - nanohist = nrealloc(nanohist, strlen(homenv) + 15); + nanohist = charealloc(nanohist, strlen(homenv) + 15); sprintf(nanohist, "%s/.nano_history", homenv); } else { userage = getpwuid(geteuid()); endpwent(); - nanohist = nrealloc(nanohist, strlen(userage->pw_dir) + 15); + nanohist = charealloc(nanohist, strlen(userage->pw_dir) + 15); sprintf(nanohist, "%s/.nano_history", userage->pw_dir); } @@ -2949,7 +2949,7 @@ void save_history(void) chmod(nanohist, S_IRUSR | S_IWUSR); /* write oldest first */ for (h = search_history.tail ; h->prev ; h = h->prev) { - h->data = nrealloc(h->data, strlen(h->data) + 2); + h->data = charealloc(h->data, strlen(h->data) + 2); strcat(h->data, "\n"); if (fputs(h->data, hist) == EOF) { rcfile_msg(_("Unable to write ~/.nano_history file, %s"), strerror(errno)); @@ -2961,7 +2961,7 @@ void save_history(void) goto come_from; } for (h = replace_history.tail ; h->prev ; h = h->prev) { - h->data = nrealloc(h->data, strlen(h->data) + 2); + h->data = charealloc(h->data, strlen(h->data) + 2); strcat(h->data, "\n"); if (fputs(h->data, hist) == EOF) { rcfile_msg(_("Unable to write ~/.nano_history file, %s"), strerror(errno)); diff --git a/global.c b/global.c index 0173cd8b..85f9750a 100644 --- a/global.c +++ b/global.c @@ -174,12 +174,12 @@ void sc_init_one(shortcut **shortcutage, int key, const char *desc, shortcut *s; if (*shortcutage == NULL) { - *shortcutage = nmalloc(sizeof(shortcut)); + *shortcutage = (shortcut *)nmalloc(sizeof(shortcut)); s = *shortcutage; } else { for (s = *shortcutage; s->next != NULL; s = s->next) ; - s->next = nmalloc(sizeof(shortcut)); + s->next = (shortcut *)nmalloc(sizeof(shortcut)); s = s->next; } @@ -204,12 +204,12 @@ void toggle_init_one(int val, const char *desc, int flag) toggle *u; if (toggles == NULL) { - toggles = nmalloc(sizeof(toggle)); + toggles = (toggle *)nmalloc(sizeof(toggle)); u = toggles; } else { for (u = toggles; u->next != NULL; u = u->next) ; - u->next = nmalloc(sizeof(toggle)); + u->next = (toggle *)nmalloc(sizeof(toggle)); u = u->next; } diff --git a/nano.c b/nano.c index 478eebfb..7ac4c523 100644 --- a/nano.c +++ b/nano.c @@ -988,7 +988,7 @@ void do_char(char ch) } /* more dangerousness fun =) */ - current->data = nrealloc(current->data, current_len + 2); + current->data = charealloc(current->data, current_len + 2); assert(current_x <= current_len); memmove(¤t->data[current_x + 1], ¤t->data[current_x], @@ -1056,7 +1056,7 @@ int do_backspace(void) mark_beginbuf = previous; } #endif - previous->data = nrealloc(previous->data, + previous->data = charealloc(previous->data, current_x + strlen(current->data) + 1); strcpy(previous->data + current_x, current->data); @@ -1128,7 +1128,7 @@ int do_delete(void) filestruct *foo; - current->data = nrealloc(current->data, + current->data = charealloc(current->data, strlen(current->data) + strlen(current->next->data) + 1); strcat(current->data, current->next->data); @@ -1792,7 +1792,7 @@ char *do_int_speller(char *tempfile_name) while ((bytesread = read(uniq_fd[0], read_buff_ptr, pipe_buff_size)) > 0) { read_buff_read += bytesread; read_buff_size += pipe_buff_size; - read_buff = read_buff_ptr = nrealloc(read_buff, read_buff_size); + read_buff = read_buff_ptr = charealloc(read_buff, read_buff_size); read_buff_ptr += read_buff_read; } @@ -1885,12 +1885,12 @@ char *do_alt_speller(char *tempfile_name) /* Set up an argument list to pass the execvp function */ if (spellargs == NULL) { - spellargs = nmalloc(arglen * sizeof(char *)); + spellargs = (char **)nmalloc(arglen * sizeof(char *)); spellargs[0] = strtok(alt_speller, " "); while ((ptr = strtok(NULL, " ")) != NULL) { arglen++; - spellargs = nrealloc(spellargs, arglen * sizeof(char *)); + spellargs = (char **)nrealloc(spellargs, arglen * sizeof(char *)); spellargs[arglen - 3] = ptr; } spellargs[arglen - 1] = NULL; @@ -2865,7 +2865,7 @@ void handle_sigwinch(int s) fill = 0; #endif - hblank = nrealloc(hblank, COLS + 1); + hblank = charealloc(hblank, COLS + 1); memset(hblank, ' ', COLS); hblank[COLS] = '\0'; diff --git a/nanorc.sample b/nanorc.sample index d29b29cf..93deea9c 100644 --- a/nanorc.sample +++ b/nanorc.sample @@ -1,8 +1,12 @@ ## Sample initialization file for GNU nano -## Please note that you must have configured nano with -## --enable-nanorc for this file to be read! +## Please note that you must have configured nano with --enable-nanorc +## for this file to be read! Also note that characters specially +## interpreted by the shell should not be escaped here. ## ## To make sure a value is not enabled, use "unset