miscellaneous cleanups, updates, and fixes

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1506 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
David Lawrence Ramsey 2003-06-14 20:41:34 +00:00
parent d995e9a762
commit 70047eef7d
12 changed files with 259 additions and 148 deletions

View File

@ -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.

33
TODO
View File

@ -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]

View File

@ -43,9 +43,9 @@ AC_CHECK_HEADER(regex.h,
AC_TRY_RUN([
#include <sys/types.h>
#include <regex.h>
int main() { regex_t reg; size_t n; regmatch_t r; regcomp(&reg, ".", 0); regexec(&reg, "", n, &r, 0); return 0; }],
int main () { regex_t reg; size_t n = 1; regmatch_t r; regcomp(&reg, "\\<", 0); regexec(&reg, "", n, &r, 0); regfree(&reg); 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.])
)
)

2
cut.c
View File

@ -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);

40
files.c
View File

@ -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));

View File

@ -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;
}

14
nano.c
View File

@ -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(&current->data[current_x + 1],
&current->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';

View File

@ -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 <option>"
##
## For the options that take parameters, the default value is given.
## Other options are unset by default.
## Use auto-indentation
# set autoindent
@ -10,23 +14,27 @@
## Backup files to filename~
# set backup
## Constantly update the cursor position
## Constantly display the cursor position in the status bar.
# set const
## Use cut to end of line with ^K by default
# set cut
## Use this value instead of the default
## An out-of-range negative value can make nano die complaining that the
## screen is too small
## set fill -8
## Set the line length for wrapping text and justifying paragraphs.
## If fill is negative, the line length will be the screen width less
## this number.
##
# set fill -8
## Enable ~/.nano_history for saving and reading search/replace strings.
# set historylog
## Use alternate keypad routines
# set keypad
## Allow multiple file buffers (using ^R inserts into separate buffer)
## Allow multiple file buffers (using ^R inserts into separate buffer).
## You must have configured with --enable-multibuffer or --enable-extra
## for this to work
## for this to work.
##
## set multibuffer
@ -42,33 +50,41 @@
## Don't wrap text at all
# set nowrap
## Set operating directory (chroot of sorts)
# set operatingdir "~"
## Set operating directory. nano will not read or write files outside
## this directory and its subdirectories. Also, the current directory
## is changed to here, so files are inserted from this dir. A blank
## string means the operating directory feature is turned off.
##
# set operatingdir ""
## Preserve the XON and XOFF keys (^Q and ^S)
# set preserve
## The email-quote string. This is a "regular expression" if your
## system supports them, otherwise a literal string. Default
# set quotestr "^([ \t]*[|>:}#])+" if you have regexps, otherwise
# set quotestr "> ".
## The email-quote string, used to justify email-quoted paragraphs.
## This is an extended regular expression if your system supports them,
## otherwise a literal string. Default:
# set quotestr "^([ ]*[\|>:}#])+"
## if you have regexps, otherwise:
# set quotestr "> "
## You can get old nano quoted-justify behavior via:
# set quotestr "(> )+"
## Do regular expression searches by default
## Do extended regular expression searches by default
# set regexp
## Use smooth scrolling as the default
# set smooth
## Use this spelling checker instead of the default one
# set speller aspell
## Use this spelling checker instead of the internal one. This option
## does not properly have a default value.
##
# set speller "aspell -c"
## Allow nano to be suspended with ^Z
# set suspend
## Use this tab size instead of the default; it must be greater than 0
# set tabsize 4
# set tabsize 8
## Save automatically on exit, don't prompt
# set tempfile
@ -84,94 +100,112 @@
## syntax "short description" ["filename regex" ...]
## color foreground,background "regex" ["regex"...]
##
## Legal colors are: white, black, red, blue, green, yellow, magenta,
## cyan. You may use the prefix "bright" to mean a stronger color
## highlight.
## Legal colors: white, black, red, blue, green, yellow, magenta, cyan.
## You may use the prefix "bright" to mean a stronger color highlight.
##
## To use multi-line regexes use the start="regex" end="regex" format.
##
## If your system supports transparency, not specifying a background
## color will use a transparent color. If you don't want this, be sure
## to set the background color to black or white.
# syntax "c-file" ".*\.c$" ".*\.h$"
##
# syntax "c-file" "\.(c|h)$"
# color red "\<[A-Z_]{2,}\>"
# color green "\<float\>" "\<char\>" "\<int\>" "\<void\>"
# color green "\<static\>" "\<const\>" "\<struct\>"
# color brightyellow "\<if\>" "\<while\>" "\<do\>" "\<else\>" "\<case\>" "\<switch\>"
# color brightcyan "#define" "#include" "#ifn*def" "#endif"
# color brightcyan "#elif" "#else" "#if"
# color green "\<(float|char|int|void|static|const|struct)\>"
# color brightyellow "\<(if|while|do|else|case|switch)\>"
# color brightcyan "^#( )*(define|include|ifn?def|endif|elif|else|if)"
##
## You will in general want your comments and strings to come last,
## because syntax highlighting rules will be applied in the order they
## are read in. Note that quotes in regexes should not be escaped (use "
## instead of \").
# color brightyellow "<[^= ]*>" ""(\\.|[^\"])*""
## are read in.
##
# color brightyellow "<[^= ]*>" ""(\\.|[^\"])*""
##
## This string is VERY resource intensive!!!
# color brightyellow start=""(\\.|[^\"])*\\( | )*$" end="^(\\.|[^\"])*""
##
## And we want to have some nice comment highlighting too
# color brightblue "//.*"
# color brightblue start="/\*" end="\*/"
## Here are some short examples for TeX files and HTML
## Here is a short example for HTML
# syntax "HTML" "\.html$"
#
# color blue start="<" end=">"
# color red "&([^; ])*;"
#
# color red "&[^; ]*;"
## Here is a short example for TeX files
# syntax "TeX" "\.tex$"
#
# color green "\\(.|([A-Za-z]*))"
# color magenta "\{" "\}"
# color green "\\.|\\[A-Za-z]*"
# color magenta "[{}]"
# color blue "%.*"
## For this you will probably want to set your editor to "nano -Y mutt"
## Here is an example for quoted emails (under e.g. mutt)
# syntax "mutt"
# color green "^>.*"
## Here is are examples for groff and for your .nanorc
#syntax "groff" "\.ms$" "\.mm$" "\.me$" "\.tmac$" "^tmac." ".rof"
## Here is an example for groff
##
# syntax "groff" "\.ms$" "\.mm$" "\.me$" "\.tmac$" "^tmac." ".rof"
## The argument of .nr or .ds
#color cyan "^\.ds [^ ]*"
#color cyan "^\.nr [^ ]*"
# color cyan "^\.ds [^ ]*"
# color cyan "^\.nr [^ ]*"
## Single character escapes
#color brightmagenta "\\."
## Highlight the argument of \f or \s in the same colour
#color brightmagenta "\\f."
#color brightmagenta "\\f\(.."
#color brightmagenta "\\s(\+|\-)?[0-9]"
# color brightmagenta "\\."
## Highlight the argument of \f or \s in the same color
# color brightmagenta "\\f."
# color brightmagenta "\\f\(.."
# color brightmagenta "\\s(\+|\-)?[0-9]"
## \n
#color cyan "(\\|\\\\)n."
#color cyan "(\\|\\\\)n\(.."
#color cyan start="(\\|\\\\)n\[" end="]"
# color cyan "(\\|\\\\)n."
# color cyan "(\\|\\\\)n\(.."
# color cyan start="(\\|\\\\)n\[" end="]"
## Requests
#color brightgreen "^\. *[^ ]*"
# color brightgreen "^\. *[^ ]*"
## Comments
#color yellow "^\.\\\".*$"
# color yellow "^\.\\\".*$"
## Strings
#color green "(\\|\\\\)\*."
#color green "(\\|\\\\)\*\(.."
#color green start="(\\|\\\\)\*\[" end="]"
# color green "(\\|\\\\)\*."
# color green "(\\|\\\\)\*\(.."
# color green start="(\\|\\\\)\*\[" end="]"
## Characters
#color brightred "\\\(.."
#color brightred start="\\\[" end="]"
# color brightred "\\\(.."
# color brightred start="\\\[" end="]"
## Macro arguments
#color brightcyan "\\\\\$[1-9]"
# color brightcyan "\\\\\$[1-9]"
## Here is an example for perl
##
# syntax "perl" "\.p[lm]$"
# color red "\<(accept|alarm|atan2|bin(d|mode)|c(aller|h(dir|mod|op|own|root)|lose(dir)?|onnect|os|rypt)|d(bm(close|open)|efined|elete|ie|o|ump)|e(ach|of|val|x(ec|ists|it|p))|f(cntl|ileno|lock|ork)|get(c|login|peername|pgrp|ppid|priority|pwnam|(host|net|proto|serv)byname|pwuid|grgid|(host|net)byaddr|protobynumber|servbyport)|([gs]et|end)(pw|gr|host|net|proto|serv)ent|getsock(name|opt)|gmtime|goto|grep|hex|index|int|ioctl|join|keys|kill|last|length|link|listen|local(time)?|log|lstat|m|mkdir|msg(ctl|get|snd|rcv)|next|oct|open(dir)?|ord|pack|pipe|pop|printf?|push|q|qq|qx|rand|re(ad(dir|link)?|cv|do|name|quire|set|turn|verse|winddir)|rindex|rmdir|s|scalar|seek|seekdir|se(lect|mctl|mget|mop|nd|tpgrp|tpriority|tsockopt)|shift|shm(ctl|get|read|write)|shutdown|sin|sleep|socket(pair)?|sort|spli(ce|t)|sprintf|sqrt|srand|stat|study|substr|symlink|sys(call|read|tem|write)|tell(dir)?|time|tr|y|truncate|umask|un(def|link|pack|shift)|utime|values|vec|wait(pid)?|wantarray|warn|write)\>"
# color magenta "\<(continue|else|elsif|do|for|foreach|if|unless|until|while|eq|ne|lt|gt|le|ge|cmp|x|my|sub|use|package|can|isa)\>"
# color cyan start="[$@%]" end="( |\\W|-)"
# color yellow "".*"|qq\|.*\|"
# color white "[sm]/.*/"
# color white start="(^use| = new)" end=";"
# color green "#.*"
# color yellow start="<< 'STOP'" end="STOP"
#syntax "nanorc" "[\.]*nanorc$"
#color white "^ *(set|unset).*$"
#color cyan "^ *(set|unset) (autoindent|backup|const|cut|fill|keypad|multibuffer|noconvert|nofollow|nohelp|nowrap|operatingdir|preserve|quotestr|regexp|smooth|speller|suspend|tabsize|tempfile|historylog|view)"
#color brightwhite "^ *syntax [^ ]*"
#color brightblue "^ *set\>" "^ *unset\>" "^ *syntax\>"
#color white "^ *color\>.*"
#color yellow "^ *color (bright)?(white|black|red|blue|green|yellow|magenta|cyan)\>"
#color magenta "^ *color\>"
#color green "^#.*$"
## Here is an example for Java source
##
# syntax "Java source" "\.java$"
# color green "\<(boolean|byte|char|double|float|int|long|new|short|this|transient|void)\>"
# color red "\<(break|case|catch|continue|default|do|else|finally|for|if|return|switch|throw|try|while)\>"
# color cyan "\<(abstract|class|extends|final|implements|import|instanceof|interface|native|package|private|protected|public|static|strictfp|super|synchronized|throws|volatile)\>"
# color red ""[^\"]*""
# color yellow "\<(true|false|null)\>"
# color blue "//.*"
# color blue start="/\*" end="\*/"
# color brightblue start="/\*\*" end="\*/"
# color brightgreen,brightgreen "[ ]+$"
## Here is an example for your .nanorc
##
# syntax "nanorc" "[\.]*nanorc$"
# color white "^ *(set|unset).*$"
# color cyan "^ *(set|unset) (autoindent|backup|const|cut|fill|keypad|multibuffer|noconvert|nofollow|nohelp|nowrap|operatingdir|preserve|quotestr|regexp|smooth|speller|suspend|tabsize|tempfile|historylog|view)"
# color brightwhite "^ *syntax [^ ]*"
# color brightblue "^ *set\>" "^ *unset\>" "^ *syntax\>"
# color white "^ *color\>.*"
# color yellow "^ *color (bright)?(white|black|red|blue|green|yellow|magenta|cyan)\>"
# color magenta "^ *color\>"
# color green "^#.*$"

View File

@ -640,7 +640,7 @@ void do_rcfile(void)
/* Rely on $HOME, fall back on getpwuid() */
if (homenv != NULL) {
nanorc = nrealloc(nanorc, strlen(homenv) + 10);
nanorc = charealloc(nanorc, strlen(homenv) + 10);
sprintf(nanorc, "%s/.nanorc", homenv);
} else {
userage = getpwuid(euid);
@ -650,7 +650,7 @@ void do_rcfile(void)
rcfile_error(_("I can't find my home directory! Wah!"));
SET(NO_RCFILE);
} else {
nanorc = nrealloc(nanorc, strlen(userage->pw_dir) + 9);
nanorc = charealloc(nanorc, strlen(userage->pw_dir) + 9);
sprintf(nanorc, "%s/.nanorc", userage->pw_dir);
}

View File

@ -960,7 +960,7 @@ void insert_node(historytype *h, const char *s)
{
historytype *a;
a = nmalloc(sizeof(historytype));
a = (historytype *)nmalloc(sizeof(historytype));
a->next = h->next;
a->prev = h->next->prev;
h->next->prev = a;

View File

@ -66,8 +66,9 @@ int num_of_digits(int n)
/* Fix the memory allocation for a string. */
void align(char **strp)
{
if (strp != NULL)
*strp = nrealloc(*strp, strlen(*strp) + 1);
assert(strp != NULL);
if (*strp != NULL)
*strp = charealloc(*strp, strlen(*strp) + 1);
}
/* Null a string at a certain index and align it. */
@ -259,7 +260,7 @@ char *mallocstrcpy(char *dest, const char *src)
/* Append a new magic-line to filebot. */
void new_magicline(void)
{
filebot->next = nmalloc(sizeof(filestruct));
filebot->next = (filestruct *)nmalloc(sizeof(filestruct));
filebot->next->data = charalloc(1);
filebot->next->data[0] = '\0';
filebot->next->prev = filebot;

72
winio.c
View File

@ -210,7 +210,15 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
char *history = NULL;
char *currentbuf = NULL;
char *complete = NULL;
int last_kbinput = 0, ret2cb = 0;
int last_kbinput = 0;
/* This variable is used in the search history code. use_cb == 0
means that we're using the existing history and ignoring
currentbuf. use_cb == 1 means that the entry in answer should be
moved to currentbuf or restored from currentbuf to answer.
use_cb == 2 means that the entry in currentbuf should be moved to
answer or restored from answer to currentbuf. */
int use_cb = 0;
#endif
xend = strlen(def);
@ -361,16 +369,34 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
do_upkey:
if (history_list != NULL) {
/* If there's no previous temp holder, or if we already
arrowed back down to it and (possibly edited it),
update the holder */
if (currentbuf == NULL || (ret2cb == 1 && strcmp(currentbuf, answer))) {
/* if currentbuf is NULL, or if use_cb is 1, currentbuf
isn't NULL, and currentbuf is different from answer,
it means that we're scrolling up at the top of the
search history, and we need to save the current
answer in currentbuf; do this and reset use_cb to
0 */
if (currentbuf == NULL || (use_cb == 1 && strcmp(currentbuf, answer))) {
currentbuf = mallocstrcpy(currentbuf, answer);
ret2cb = 0;
use_cb = 0;
}
/* get older search from the history list */
if ((history = get_history_older(history_list)) != NULL) {
/* if currentbuf isn't NULL, use_cb is 2, and currentbuf
is different from answer, it means that we're
scrolling up at the bottom of the search history, and
we need to make the string in currentbuf the current
answer; do this, blow away currentbuf since we don't
need it anymore, and reset use_cb to 0 */
if (currentbuf != NULL && use_cb == 2 && strcmp(currentbuf, answer)) {
answer = mallocstrcpy(answer, currentbuf);
free(currentbuf);
currentbuf = NULL;
xend = strlen(answer);
use_cb = 0;
/* else get older search from the history list and save
it in answer; if there is no older search, blank out
answer */
} else if ((history = get_history_older(history_list)) != NULL) {
answer = mallocstrcpy(answer, history);
xend = strlen(history);
} else {
@ -386,22 +412,38 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
#ifndef NANO_SMALL
do_downkey:
if (history_list != NULL) {
/* get newer search from the history list */
/* get newer search from the history list and save it
in answer */
if ((history = get_history_newer(history_list)) != NULL) {
answer = mallocstrcpy(answer, history);
xend = strlen(history);
/* else if we ran out of history, regurgitate the temporary
buffer and blow away currentbuf */
} else if (currentbuf != NULL) {
/* if there is no newer search, we're here */
/* if currentbuf isn't NULL and use_cb isn't 2, it means
that we're scrolling down at the bottom of the search
history and we need to make the string in currentbuf
the current answer; do this, blow away currentbuf
since we don't need it anymore, and set use_cb to
1 */
} else if (currentbuf != NULL && use_cb != 2) {
answer = mallocstrcpy(answer, currentbuf);
free(currentbuf);
currentbuf = NULL;
xend = strlen(answer);
ret2cb = 1;
} else {
use_cb = 1;
/* otherwise, if currentbuf is NULL and use_cb isn't 2,
it means that we're scrolling down at the bottom of
the search history and the current answer needs to be
saved in currentbuf; do this, blank out answer, and
set use_cb to 2 */
} else if (use_cb != 2) {
currentbuf = mallocstrcpy(currentbuf, answer);
answer = mallocstrcpy(answer, "");
xend = 0;
use_cb = 2;
}
x = xend;
}
@ -486,7 +528,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
default:
if (kbinput < 32)
break;
answer = nrealloc(answer, xend + 2);
answer = charealloc(answer, xend + 2);
memmove(answer + x + 1, answer + x, xend - x + 1);
xend++;
answer[x] = kbinput;