- Minor cosmetic tweaks to the ngettext() macro, and fix to
properly detect systems lacking ngettext() and correctly
compile on them; the previous fix didn't work. (DLR)
+ - Fix problems with some code sections' not being #ifdef'ed out
+ when they should be, or being #ifdef'ed out improperly. (David
+ Benbennick and DLR)
+ - Change FOLLOW_SYMLINKS to NOFOLLOW_SYMLINKS, and rework the
+ associated logic accordingly, throughout the code. (David
+ Benbennick)
+ - Rework #ifdefs to not include mouse_init() at all if
+ DISABLE_MOUSE is defined or NCURSES_MOUSE_VERSION isn't. (DLR)
+ - For consistency, change many references of (!x) to (x == NULL)
+ and (x) to (x != NULL). (DLR)
+ - Define KEY_IC properly (and KEY_DC more portably) when slang
+ support is enabled, and remove the hack to work around the
+ former's not being defined. (David Benbennick and DLR)
- configure.ac:
- Added tr to ALL_LINGUAS (Jordi).
+ - Fix now inaccurate description of --enable-tiny's effects; it
+ no longer disables NLS support. (DLR)
+ - Fix typo. (David Benbennick)
+ - Check for strcasecmp() and strncasecmp(), since they are
+ apparently only standard under BSD. (DLR)
+- cut.c:
+ do_cut_text()
+ - Fix a memory corruption problem caused by accessing edittop
+ after it was freed but before it was reset to a sane value
+ from current. (David Benbennick)
+ do_uncut_text()
+ - If uncutting more than one line of unmarked text at editbot,
+ don't center the screen, since Pico doesn't. (DLR)
+- files.c:
+ read_line()
+ - Miscellaneous cleanups. (David Benbennick)
+ read_file()
+ - Miscellaneous cleanups. (David Benbennick)
+ - Fix len's being off by one when reading in Mac-format files,
+ exposed by one of David Benbennick's cleanups. (DLR)
+ - If NO_CONVERT isn't set when we first enter, and it gets set
+ while reading in the file, unset it again afterwards. (DLR)
+ add_open_file()
+ - Fix minor logic error when determining when to resave fileage
+ and filebot. (DLR)
+ write_file()
+ - Change lineswritten from a long to an int, to match
+ filestruct->lineno. (DLR; mismatch found by David Benbennick)
+ input_tab()
+ - Variable name change: matchBuf -> matchbuf. (DLR)
+ diralphasort()
+ - Remove the HAVE_STRCASECMP #ifdef block; see the changes to
+ configure.ac and nano.h for why. (DLR)
+- move.c:
+ do_page_down()
+ - If there's a page or less of text, do an edit_update() if the
+ mark is on; otherwise, the highlight won't be displayed. (DLR)
- nano.c:
+ do_prev_word()
+ - Make the assert match that in do_next_word(). (DLR)
+ do_enter()
+ - If smooth scrolling is on, and Enter is pressed on the
+ magicline, don't center the screen. (DLR)
+ do_justify()
+ - Fix memory corruption problem triggered when edittop and
+ current->next pointed to the same value and current->next was
+ destroyed during justification. (DLR)
+ - Center the screen when justification moves the cursor entirely
+ off the bottom of the screen, instead of when it moves the
+ cursor near the bottom of the screen, to more closely match
+ Pico's behavior. (DLR)
version()
- Remove obsolete reference to --enable-undo. (David Benbennick)
do_int_speller()
- Programs now return char *, NULL for successful completion,
otherwise the error string to display. This allows us to give
more useful feedback to the user when spell checking fails.
+ ABCD()
+ - Renamed abcd(). (DLR)
+- nano.h:
+ - Make sure NO_RCFILE and COLOR_SYNTAX aren't set to the same
+ value. (DLR; discovered by Ken Tyler)
+ - If strcasecmp() and/or strncasecmp() aren't available, use
+ strcmp() and/or strncmp instead. (DLR)
+- utils.c:
+ is_cntrl_char()
+ - Rework to fix a problem with displaying certain high-bit
+ characters. (David Benbennick; reported by Andrzej Marecki)
- winio.c:
+ edit_refresh()
+ - Miscellaneous cleanups that fix a bug where the screen
+ isn't updated after uncutting chunks of upwardly marked cut
+ text that are over a page in length. (David Benbennick)
do_credits()
- Add David Benbennick to credits. (DLR)
- nanorc.sample:
defok = use_default_colors() != ERR;
#endif
- for (tmpcolor = colorstrings; tmpcolor != NULL;
+ for (tmpcolor = colorstrings; tmpcolor != NULL;
tmpcolor = tmpcolor->next) {
short background = tmpcolor->bg;
if (background == -1)
#ifdef HAVE_USE_DEFAULT_COLORS
- if (!defok)
+ if (defok == 0)
#endif
background = COLOR_BLACK;
fi])
AC_ARG_ENABLE(tiny,
-[ --enable-tiny Disable features for the sake of size
- (currently disables detailed help and i18n)],
+[ --enable-tiny Disable features for the sake of size],
[if test x$enableval = xyes; then
AC_DEFINE(NANO_SMALL, 1, [Define this to make the nano executable as small as possible.]) tiny_support=yes
AC_DEFINE(DISABLE_BROWSER, 1, [Define this to disable the built-in (crappy) file browser.])
esac], [AC_MSG_RESULT(no)])
dnl Checks for functions
-AC_CHECK_FUNCS(snprintf vsnprintf)
+AC_CHECK_FUNCS(snprintf vsnprintf strcasecmp strncasecmp)
if test "x$ac_cv_func_snprintf" = "xno" -o "xac_cv_func_vsnprintf" = "xno"
then
AM_PATH_GLIB(1.2.4,,
AC_CHECK_LIB([$CURSES_LIB_NAME], wresize, AC_DEFINE(HAVE_WRESIZE, 1, [Define this if you have the wresize function in your ncurses-type library.]))
AC_CHECK_LIB([$CURSES_LIB_NAME], resizeterm, AC_DEFINE(HAVE_RESIZETERM, 1, [Define this if you have the resizeterm function in your ncurses-type library.]))
- # Taken from aumix (can't tell form the variable name?)
+ # Taken from aumix (can't tell from the variable name?)
AC_CACHE_CHECK([for private member _use_keypad in WINDOW],
aumix_cv_struct_window_usekeypad,
[AC_TRY_COMPILE([#ifdef HAVE_NCURSES_H
#include "nano.h"
static int marked_cut; /* Is the cutbuffer from a mark? */
-static filestruct *cutbottom = NULL; /* Pointer to end of cutbuffer */
+static filestruct *cutbottom = NULL;
+ /* Pointer to end of cutbuffer */
filestruct *get_cutbottom(void)
{
void add_to_cutbuffer(filestruct *inptr)
{
#ifdef DEBUG
- fprintf(stderr, _("add_to_cutbuffer called with inptr->data = %s\n"),
+ fprintf(stderr, _("add_to_cutbuffer() called with inptr->data = %s\n"),
inptr->data);
#endif
#ifndef NANO_SMALL
/* Cut a marked segment instead of a whole line.
+ *
* The first cut character is top->data[top_x]. Unless top == bot, the
* last cut line has length bot_x. That is, if bot_x > 0 then we cut to
* bot->data[bot_x - 1].
} else {
totsize -= bot_x + 1;
- /* Here, the remainder line might get longer, so we realloc
- it first. */
+ /* Here, the remainder line might get longer, so we
+ realloc() it first. */
top->data = (char *)nrealloc(top->data,
sizeof(char) * newsize);
memmove(top->data + top_x, bot->data + bot_x,
UNSET(MARK_ISSET);
marked_cut = 1;
- set_modified();
- if (dontupdate) {
- fix_editbot();
+ if (dontupdate)
edit_refresh();
- } else
+ else
edit_update(current, CENTER);
+ set_modified();
return 1;
}
int do_uncut_text(void)
{
filestruct *tmp = current, *fileptr = current;
- filestruct *newbuf = NULL;
- filestruct *newend = NULL;
+ filestruct *newbuf = NULL, *newend = NULL;
#ifndef NANO_SMALL
char *tmpstr, *tmpstr2;
filestruct *hold = current;
return 0; /* AIEEEEEEEEEEEE */
#ifndef NANO_SMALL
- if (!marked_cut || cutbuffer->next != NULL)
+ if (marked_cut == 0 || cutbuffer->next != NULL)
#endif
{
newbuf = copy_filestruct(cutbuffer);
/* Hook newbuf into fileptr */
#ifndef NANO_SMALL
- if (marked_cut) {
+ if (marked_cut != 0) {
int recenter_me = 0;
/* Should we eventually use edit_update(CENTER)? */
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);
- /* Use strncpy to not copy the terminal '\0'. */
+ /* Use strncpy() to not copy the terminal '\0'. */
current_x += buf_len;
totsize += buf_len;
if (marked_cut == 2) {
tmp = make_new_node(current);
- tmp->data = charalloc(strlen(¤t->data[current_x]) + 1);
- strcpy(tmp->data, ¤t->data[current_x]);
+ tmp->data = mallocstrcpy(NULL, current->data + current_x);
splice_node(current, tmp, current->next);
null_at(¤t->data, current_x);
current = current->next;
i = editbot->lineno;
renumber(newbuf);
- if (i < newend->lineno)
+ /* Center the screen if we've moved beyond the line numbers of both
+ the old and new editbots */
+ if (i < newend->lineno && editbot->lineno < newend->lineno)
edit_update(fileptr, CENTER);
else
edit_refresh();
this new file; without this, if nano is started without a filename
on the command line, a new file will be created, but it will be
given no open_files entry */
- if (!open_files) {
+ if (open_files == NULL) {
add_open_file(0);
/* turn off view mode in this case; this is for consistency
whether multibuffers are compiled in or not */
filestruct *read_line(char *buf, filestruct *prev, int *line1ins, int len)
{
- filestruct *fileptr;
-
- fileptr = nmalloc(sizeof(filestruct));
+ filestruct *fileptr = (filestruct *)nmalloc(sizeof(filestruct));
/* nulls to newlines; len is the string's real length here */
unsunder(buf, len);
- fileptr->data = charalloc(strlen(buf) + 2);
- strcpy(fileptr->data, buf);
+ assert(strlen(buf) == len);
+
+ fileptr->data = mallocstrcpy(NULL, buf);
#ifndef NANO_SMALL
/* If it's a DOS file (CRLF), and file conversion isn't disabled,
strip out the CR part */
- if (!ISSET(NO_CONVERT) && buf[strlen(buf) - 1] == '\r') {
- fileptr->data[strlen(buf) - 1] = '\0';
+ if (!ISSET(NO_CONVERT) && len > 0 && buf[len - 1] == '\r') {
+ fileptr->data[len - 1] = '\0';
totsize--;
- if (!fileformat)
+ if (fileformat == 0)
fileformat = 1;
}
#endif
- if (*line1ins) {
+ if (*line1ins != 0 || fileage == NULL) {
/* Special case, insert with cursor on 1st line. */
fileptr->prev = NULL;
fileptr->next = fileage;
fileptr->lineno = 1;
- *line1ins = 0;
- /* If we're inserting into the first line of the file, then
- we want to make sure that our edit buffer stays on the
- first line (and that fileage stays up to date!) */
- fileage = fileptr;
- edittop = fileptr;
- } else if (fileage == NULL) {
+ if (*line1ins != 0) {
+ *line1ins = 0;
+ /* If we're inserting into the first line of the file, then
+ we want to make sure that our edit buffer stays on the
+ first line (and that fileage stays up to date!) */
+ edittop = fileptr;
+ } else
+ filebot = fileptr;
fileage = fileptr;
- fileage->lineno = 1;
- fileage->next = fileage->prev = NULL;
- fileptr = filebot = fileage;
- } else if (prev) {
+ } else {
+ assert(prev != NULL);
fileptr->prev = prev;
fileptr->next = NULL;
fileptr->lineno = prev->lineno + 1;
prev->next = fileptr;
- } else {
- die(_("read_line: not on first line and prev is NULL"));
}
return fileptr;
int read_file(FILE *f, const char *filename, int quiet)
{
int num_lines = 0, len = 0;
- char input = 0; /* current input character */
+ char input = '\0'; /* current input character */
char *buf;
long i = 0, bufx = 128;
filestruct *fileptr = current, *tmp = NULL;
+#ifndef NANO_SMALL
+ int old_no_convert = ISSET(NO_CONVERT);
+#endif
int line1ins = 0;
int input_int;
buf = charalloc(bufx);
buf[0] = '\0';
- if (fileptr != NULL && fileptr->prev != NULL) {
- fileptr = fileptr->prev;
+ if (current != NULL) {
+ if (current == fileage)
+ line1ins = 1;
+ else
+ fileptr = current->prev;
tmp = fileptr;
- } else if (fileptr != NULL && fileptr->prev == NULL) {
- tmp = fileage;
- current = fileage;
- line1ins = 1;
}
+
+ /* For the assertion in read_line(), it must be true that if current is
+ NULL then so is fileage. */
+ assert(current != NULL || fileage == NULL);
+
/* Read the entire file into file struct */
while ((input_int = getc(f)) != EOF) {
input = (char)input_int;
#ifndef NANO_SMALL
- if (!ISSET(NO_CONVERT) && is_cntrl_char((int)input)
- && input != '\t' && input != '\r' && input != '\n') {
- /* If the file has binary chars in it, don't stupidly
- assume it's a DOS or Mac formatted file! */
+ /* If the file has binary chars in it, don't stupidly
+ assume it's a DOS or Mac formatted file! */
+ if (!ISSET(NO_CONVERT) && is_cntrl_char((int)input) != 0
+ && input != '\t' && input != '\r' && input != '\n')
SET(NO_CONVERT);
- }
#endif
- /* calculate the total length of the line; it might have nulls in
- it, so we can't just use strlen() */
- len++;
-
if (input == '\n') {
- /* don't count the newline in the line length */
- len--;
-
/* read in the line properly */
fileptr = read_line(buf, fileptr, &line1ins, len);
} else if (!ISSET(NO_CONVERT) && i > 0 && buf[i - 1] == '\r') {
fileformat = 2;
- /* don't count the newline in the line length */
- len--;
-
/* read in the line properly */
fileptr = read_line(buf, fileptr, &line1ins, len);
- /* reset the line length, in preparation for the next line */
- len = 0;
+ /* reset the line length, in preparation for the next line;
+ since we've already read in the next character, reset it
+ to 1 instead of 0 */
+ len = 1;
num_lines++;
totsize++;
i = 1;
#endif
} else {
+
+ /* Calculate the total length of the line; it might have
+ nulls in it, so we can't just use strlen(). */
+ len++;
+
/* Now we allocate a bigger buffer 128 characters at a time.
- If we allocate a lot of space for one line, we may indeed
+ If we allocate a lot of space for one line, we may indeed
have to use a buffer this big later on, so we don't
decrease it at all. We do free it at the end, though. */
-
if (i >= bufx - 1) {
- buf = nrealloc(buf, bufx + 128);
bufx += 128;
+ buf = nrealloc(buf, bufx);
}
buf[i] = input;
buf[i + 1] = '\0';
totsize++;
}
- if (ferror(f)) {
- /* This conditional duplicates previous read_byte(); behavior;
- perhaps this could use some better handling. */
- nperror(filename);
- }
+ /* This conditional duplicates previous read_byte() behavior;
+ perhaps this could use some better handling. */
+ if (ferror(f))
+ nperror(filename);
+ fclose(f);
/* Did we not get a newline but still have stuff to do? */
if (len > 0) {
/* If file conversion isn't disabled, the last character in
this file is a CR and fileformat isn't set yet, make sure
it's set to Mac format */
- if (!ISSET(NO_CONVERT) && buf[len - 1] == '\r' && !fileformat)
+ if (!ISSET(NO_CONVERT) && buf[len - 1] == '\r' && fileformat == 0)
fileformat = 2;
#endif
buf[0] = '\0';
}
#ifndef NANO_SMALL
- else {
+ else if (!ISSET(NO_CONVERT) && input == '\r') {
/* If file conversion isn't disabled and the last character in
this file is a CR, read it in properly as a (Mac format)
line */
- if (!ISSET(NO_CONVERT) && input == '\r') {
- buf[0] = input;
- buf[1] = '\0';
- len = 1;
- fileptr = read_line(buf, fileptr, &line1ins, len);
- num_lines++;
- totsize++;
- buf[0] = '\0';
- }
+ buf[0] = input;
+ buf[1] = '\0';
+ len = 1;
+ fileptr = read_line(buf, fileptr, &line1ins, len);
+ num_lines++;
+ totsize++;
+ buf[0] = '\0';
}
#endif
+ free(buf);
+
+#ifndef NANO_SMALL
+ /* If NO_CONVERT wasn't set before we read the file, but it is now,
+ unset it again. */
+ if (!old_no_convert && ISSET(NO_CONVERT))
+ UNSET(NO_CONVERT);
+#endif
+
/* Did we even GET a file if we don't already have one? */
if (totsize == 0 || fileptr == NULL)
new_file();
totlines += num_lines;
- free(buf);
- fclose(f);
-
return 1;
}
if (!quiet)
statusbar(_("Reading File"));
f = fdopen(fd, "rb"); /* Binary for our own line-end munging */
- if (!f) {
+ if (f == NULL) {
nperror("fdopen");
return -1;
}
char *realname = NULL;
static char *inspath = NULL;
- if (inspath == NULL)
- inspath = mallocstrcpy(inspath, "");
+ if (inspath == NULL) {
+ inspath = charalloc(1);
+ inspath[0] = '\0';
+ }
wrap_reset();
-#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE)
+#if !defined(DISABLE_BROWSER) || (!defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION))
currshortcut = insertfile_list;
#endif
#ifndef DISABLE_OPERATINGDIR
- if (operating_dir && strcmp(operating_dir, "."))
+ if (operating_dir != NULL && strcmp(operating_dir, ".") != 0)
#ifdef ENABLE_MULTIBUFFER
if (ISSET(MULTIBUFFER))
i = statusq(1, insertfile_list, inspath, _("File to insert into new buffer [from %s] "),
if (i == NANO_TOFILES_KEY) {
char *tmp = do_browse_from(realname);
-#if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE)
+#if !defined(DISABLE_HELP) || (!defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION))
currshortcut = insertfile_list;
#endif
#ifdef DISABLE_TABCOMP
#endif
#ifndef DISABLE_OPERATINGDIR
- if (operating_dir && check_operating_dir(realname, 0)) {
+ if (operating_dir != NULL && check_operating_dir(realname, 0)) {
statusbar(_("Can't insert file from outside of %s"),
operating_dir);
return 0;
{
openfilestruct *tmp;
- if (!fileage || !current || !filename)
+ if (fileage == NULL || current == NULL || filename == NULL)
return 1;
/* if no entries, make the first one */
- if (!open_files)
+ if (open_files == NULL)
open_files = make_new_opennode(NULL);
else if (!update) {
/* if we're in view mode and updating, the file contents won't
have changed, so we won't bother resaving the filestruct
then; otherwise, we will */
- if (!(ISSET(VIEW_MODE) && !update)) {
+ if (!(ISSET(VIEW_MODE) || !update)) {
/* save current file buffer */
open_files->fileage = fileage;
open_files->filebot = filebot;
*/
int load_open_file(void)
{
- if (!open_files)
+ if (open_files == NULL)
return 1;
/* set up the filename, the file buffer, the total number of lines in
*/
int open_prevfile(int closing_file)
{
- if (!open_files)
+ if (open_files == NULL)
return 1;
/* if we're not about to close the current entry, update it before
if (!closing_file)
add_open_file(1);
- if (!open_files->prev && !open_files->next) {
+ if (open_files->prev == NULL && open_files->next == NULL) {
/* only one file open */
if (!closing_file)
return 1;
}
- if (open_files->prev) {
+ if (open_files->prev != NULL) {
open_files = open_files->prev;
#ifdef DEBUG
}
- else if (open_files->next) {
+ else if (open_files->next != NULL) {
/* if we're at the beginning, wrap around to the end */
- while (open_files->next)
+ while (open_files->next != NULL)
open_files = open_files->next;
#ifdef DEBUG
load_open_file();
statusbar(_("Switched to %s"),
- ((open_files->filename[0] == '\0') ? "New Buffer" : open_files->filename ));
+ ((open_files->filename[0] == '\0') ? "New Buffer" : open_files->filename));
#ifdef DEBUG
dump_buffer(current);
*/
int open_nextfile(int closing_file)
{
- if (!open_files)
+ if (open_files == NULL)
return 1;
/* if we're not about to close the current entry, update it before
if (!closing_file)
add_open_file(1);
- if (!open_files->prev && !open_files->next) {
+ if (open_files->prev == NULL && open_files->next == NULL) {
/* only one file open */
if (!closing_file)
return 1;
}
- if (open_files->next) {
+ if (open_files->next != NULL) {
open_files = open_files->next;
#ifdef DEBUG
#endif
}
- else if (open_files->prev) {
+ else if (open_files->prev != NULL) {
/* if we're at the end, wrap around to the beginning */
- while (open_files->prev) {
+ while (open_files->prev != NULL) {
open_files = open_files->prev;
#ifdef DEBUG
load_open_file();
statusbar(_("Switched to %s"),
- ((open_files->filename[0] == '\0') ? "New Buffer" : open_files->filename ));
+ ((open_files->filename[0] == '\0') ? "New Buffer" : open_files->filename));
#ifdef DEBUG
dump_buffer(current);
{
openfilestruct *tmp;
- if (!open_files)
+ if (open_files == NULL)
return 1;
/* make sure open_files->fileage and fileage, and open_files->filebot
d_here = getcwd(NULL, 0);
#endif
- if (d_here) {
+ if (d_here != NULL) {
align(&d_here);
if (strcmp(d_here, "/")) {
/* if we didn't find one, copy d_here into d_there; all data is
then set up */
- if (!last_slash)
+ if (last_slash == NULL)
d_there = mallocstrcpy(d_there, d_here);
else {
/* otherwise, remove all non-path elements from d_there
/* and remove all non-file elements from d_there_file (i. e.
everything before and including the last slash); if we
- have a path but no filename, don't do anything */
+ have a path but no filename, don't do anything */
if (!path_only) {
last_slash = strrchr(d_there_file, '/');
last_slash++;
#endif
align(&d_there);
- if (d_there) {
+ if (d_there != NULL) {
/* add a slash to d_there, unless it's "/", in which
case we don't need it */
struct stat fileinfo;
/* if get_full_path() failed, return NULL */
- if (!full_path)
+ if (full_path == NULL)
return NULL;
/* otherwise, stat() the full path to see if it's writable by the
/* 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,
- leave full_tempdir set to to NULL */
+ leave full_tempdir set to NULL */
TMPDIR_env = getenv("TMPDIR");
- if (TMPDIR_env && TMPDIR_env[0] != '\0')
+ if (TMPDIR_env != NULL && TMPDIR_env[0] != '\0')
full_tempdir = check_writable_directory(TMPDIR_env);
/* if $TMPDIR is blank or isn't set, or isn't a writable
directory, and dirname isn't NULL, try it; otherwise, leave
full_tempdir set to NULL */
- if (!full_tempdir && dirname)
+ if (full_tempdir == NULL && dirname != NULL)
full_tempdir = check_writable_directory(dirname);
/* if $TMPDIR is blank or isn't set, or if it isn't a writable
directory, and dirname is NULL, try P_tmpdir instead */
- if (!full_tempdir)
+ if (full_tempdir == NULL)
full_tempdir = check_writable_directory(P_tmpdir);
/* if P_tmpdir didn't work, use /tmp instead */
- if (!full_tempdir) {
+ if (full_tempdir == NULL) {
full_tempdir = charalloc(6);
strcpy(full_tempdir, "/tmp/");
}
{
assert(full_operating_dir == NULL);
- if (!operating_dir)
+ if (operating_dir == NULL)
return;
full_operating_dir = get_full_path(operating_dir);
/* If get_full_path() failed or the operating directory is
inaccessible, unset operating_dir. */
- if (!full_operating_dir || chdir(full_operating_dir) == -1) {
+ if (full_operating_dir == NULL || chdir(full_operating_dir) == -1) {
free(full_operating_dir);
full_operating_dir = NULL;
free(operating_dir);
const char *whereami1, *whereami2 = NULL;
/* if no operating directory is set, don't bother doing anything */
- if (!operating_dir)
+ if (operating_dir == NULL)
return 0;
fullpath = get_full_path(currpath);
- if (!fullpath)
+ if (fullpath == NULL)
return 1;
whereami1 = strstr(fullpath, full_operating_dir);
* append == 2 means we are prepending instead of overwriting.
*
* nonamechange means don't change the current filename, it is ignored
- * if tmp == 1 or if we're appending/prepending.
+ * if tmp is nonzero or if we're appending/prepending.
*/
int write_file(const char *name, int tmp, int append, int nonamechange)
{
int retval = -1;
/* Instead of returning in this function, you should always
* merely set retval then goto cleanup_and_exit. */
- long size, lineswritten = 0;
+ long size;
+ int lineswritten = 0;
char *buf = NULL;
const filestruct *fileptr;
FILE *f;
#ifndef DISABLE_OPERATINGDIR
/* If we're writing a temporary file, we're probably going outside
the operating directory, so skip the operating directory test. */
- if (!tmp && operating_dir && check_operating_dir(realname, 0)) {
+ if (!tmp && operating_dir != NULL && check_operating_dir(realname, 0)) {
statusbar(_("Can't write outside of %s"), operating_dir);
goto cleanup_and_exit;
}
the file has not been modified by someone else since nano opened
it. */
if (ISSET(BACKUP_FILE) && !tmp && realexists == 0 &&
- (append || ISSET(MARK_ISSET) ||
+ (append != 0 || ISSET(MARK_ISSET) ||
originalfilestat.st_mtime == st.st_mtime)) {
FILE *backup_file;
char *backupname = NULL;
/* open the original file to copy to the backup */
f = fopen(realname, "rb");
- if (!f) {
+ if (f == NULL) {
statusbar(_("Could not read %s for backup: %s"), realname,
strerror(errno));
return -1;
/* get a file descriptor for the destination backup file */
backup_file = fopen(backupname, "wb");
- if (!backup_file) {
+ if (backup_file == NULL) {
statusbar(_("Couldn't write backup: %s"), strerror(errno));
free(backupname);
return -1;
goto cleanup_and_exit;
/* NOTE: If you change this statement, you MUST CHANGE the if
statement below (that says:
- if (realexists == -1 || tmp || (!ISSET(FOLLOW_SYMLINKS) &&
+ if (realexists == -1 || tmp || (ISSET(NOFOLLOW_SYMLINKS) &&
S_ISLNK(lst.st_mode))) {
to reflect whether or not to link/unlink/rename the file */
- else if (append != 2 && (ISSET(FOLLOW_SYMLINKS) || !S_ISLNK(lst.st_mode)
+ else if (append != 2 && (!ISSET(NOFOLLOW_SYMLINKS) || !S_ISLNK(lst.st_mode)
|| tmp)) {
- /* Use O_EXCL if tmp == 1. This is now copied from joe, because
- wiggy says so *shrug*. */
- if (append)
+ /* Use O_EXCL if tmp is nonzero. This is now copied from joe,
+ because wiggy says so *shrug*. */
+ if (append != 0)
fd = open(realname, O_WRONLY | O_CREAT | O_APPEND, (S_IRUSR|S_IWUSR));
else if (tmp)
fd = open(realname, O_WRONLY | O_CREAT | O_EXCL, (S_IRUSR|S_IWUSR));
#endif
f = fdopen(fd, append == 1 ? "ab" : "wb");
- if (!f) {
+ if (f == NULL) {
statusbar(_("Could not open file for writing: %s"), strerror(errno));
goto cleanup_and_exit;
}
}
}
- if (fclose(f)) {
+ if (fclose(f) != 0) {
statusbar(_("Could not close %s: %s"), realname, strerror(errno));
unlink(buf);
goto cleanup_and_exit;
FILE *f_source, *f_dest;
int prechar;
- if ((fd_dest = open(buf, O_WRONLY | O_APPEND, (S_IRUSR|S_IWUSR))) == -1) {
+ if ((fd_dest = open(buf, O_WRONLY | O_APPEND, (S_IRUSR | S_IWUSR))) == -1) {
statusbar(_("Could not reopen %s: %s"), buf, strerror(errno));
goto cleanup_and_exit;
}
f_dest = fdopen(fd_dest, "wb");
- if (!f_dest) {
+ if (f_dest == NULL) {
statusbar(_("Could not reopen %s: %s"), buf, strerror(errno));
close(fd_dest);
goto cleanup_and_exit;
goto cleanup_and_exit;
}
f_source = fdopen(fd_source, "rb");
- if (!f_source) {
+ if (f_source == NULL) {
statusbar(_("Could not open %s for prepend: %s"), realname, strerror(errno));
fclose(f_dest);
close(fd_source);
}
if (realexists == -1 || tmp ||
- (!ISSET(FOLLOW_SYMLINKS) && S_ISLNK(lst.st_mode))) {
+ (ISSET(NOFOLLOW_SYMLINKS) && S_ISLNK(lst.st_mode))) {
/* Use default umask as file permissions if file is a new file. */
mask = umask(0);
mask = st.st_mode;
if (append == 2 ||
- (!tmp && (!ISSET(FOLLOW_SYMLINKS) && S_ISLNK(lst.st_mode)))) {
+ (!tmp && (ISSET(NOFOLLOW_SYMLINKS) && S_ISLNK(lst.st_mode)))) {
if (unlink(realname) == -1) {
if (errno != ENOENT) {
statusbar(_("Could not open %s for writing: %s"),
statusbar(_("Could not set permissions %o on %s: %s"),
mask, realname, strerror(errno));
- if (!tmp && !append) {
+ if (!tmp && append == 0) {
if (!nonamechange)
filename = mallocstrcpy(filename, realname);
static int did_cred = 0;
#endif
-#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE)
+#if !defined(DISABLE_BROWSER) || (!defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION))
currshortcut = writefile_list;
#endif
answer = mallocstrcpy(answer, path);
if (exiting && ISSET(TEMP_OPT)) {
- if (filename[0]) {
+ if (filename[0] != '\0') {
i = write_file(answer, 0, 0, 0);
display_main_list();
return i;
if (append == 2)
i = statusq(1, writefile_list, "",
"%s%s%s", _("Prepend Selection to File"), formatstr, backupstr);
- else if (append)
+ else if (append == 1)
i = statusq(1, writefile_list, "",
"%s%s%s", _("Append Selection to File"), formatstr, backupstr);
else
if (append == 2)
i = statusq(1, writefile_list, answer,
"%s%s%s", _("File Name to Prepend to"), formatstr, backupstr);
- else if (append)
+ else if (append == 1)
i = statusq(1, writefile_list, answer,
"%s%s%s", _("File Name to Append to"), formatstr, backupstr);
else
if (append == 2)
i = statusq(1, writefile_list, answer,
"%s", _("File Name to Prepend to"));
- else if (append)
+ else if (append == 1)
i = statusq(1, writefile_list, answer,
"%s", _("File Name to Append to"));
else
TOGGLE(BACKUP_FILE);
continue;
} else
-#endif /* ! NANO_SMALL */
+#endif /* !NANO_SMALL */
if (i == NANO_PREPEND_KEY) {
append = append == 2 ? 0 : 2;
continue;
return -1;
}
#endif
- if (!append && strcmp(answer, filename)) {
+ if (append == 0 && strcmp(answer, filename) != 0) {
struct stat st;
if (!stat(answer, &st)) {
}
endpwent();
- if (userdata != NULL) { /* User found */
+ if (userdata != NULL) { /* User found */
dirtmp = charalloc(strlen(userdata->pw_dir) + strlen(buf + i) + 1);
sprintf(dirtmp, "%s%s", userdata->pw_dir, &buf[i]);
}
/*
* These functions (username_tab_completion, cwd_tab_completion, and
- * input_tab were taken from busybox 0.46 (cmdedit.c). Here is the notice
- * from that file:
+ * input_tab) were taken from busybox 0.46 (cmdedit.c). Here is the
+ * notice from that file:
*
* Termios command line History and Editting, originally
* intended for NetBSD sh (ash)
char **username_tab_completion(char *buf, int *num_matches)
{
- char **matches = (char **) NULL;
+ char **matches = (char **)NULL;
char *matchline = NULL;
struct passwd *userdata;
/* ...unless the match exists outside the operating
directory, in which case just go to the next match */
- if (operating_dir) {
- if (check_operating_dir(userdata->pw_dir, 1))
+ if (operating_dir != NULL) {
+ if (check_operating_dir(userdata->pw_dir, 1) != 0)
continue;
}
#endif
}
endpwent();
- return (matches);
+ return matches;
}
/* This was originally called exe_n_cwd_tab_completion, but we're not
char **cwd_tab_completion(char *buf, int *num_matches)
{
char *dirname, *dirtmp = NULL, *tmp = NULL, *tmp2 = NULL;
- char **matches = (char **) NULL;
+ char **matches = (char **)NULL;
DIR *dir;
struct dirent *next;
strcat(buf, "*");
/* Okie, if there's a / in the buffer, strip out the directory part */
- if (buf[0] != '\0' && strstr(buf, "/")) {
+ if (buf[0] != '\0' && strstr(buf, "/") != NULL) {
dirname = charalloc(strlen(buf) + 1);
tmp = buf + strlen(buf);
while (*tmp != '/' && tmp != buf)
dir = opendir(dirname);
- if (!dir) {
+ if (dir == NULL) {
/* Don't print an error, just shut up and return */
*num_matches = 0;
beep();
- return (matches);
+ return matches;
}
while ((next = readdir(dir)) != NULL) {
directory name to the beginning of the proposed match
before we check it */
- if (operating_dir) {
+ if (operating_dir != NULL) {
tmp2 = charalloc(strlen(dirname) + strlen(next->d_name) + 2);
strcpy(tmp2, dirname);
strcat(tmp2, "/");
}
}
- return (matches);
+ return matches;
}
/* This function now has an arg which refers to how much the
{
/* Do TAB completion */
static int num_matches = 0, match_matches = 0;
- static char **matches = (char **) NULL;
+ static char **matches = (char **)NULL;
int pos = place, i = 0, col = 0, editline = 0;
int longestname = 0, is_dir = 0;
char *foo;
*list = 0;
if (*lastwastab == FALSE) {
- char *tmp, *copyto, *matchBuf;
+ char *tmp, *copyto, *matchbuf;
*lastwastab = 1;
/* 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 = (char *)nmalloc((strlen(buf) + 2) * sizeof(char));
+ memset(matchbuf, '\0', (strlen(buf) + 2));
- strncpy(matchBuf, buf, place);
- tmp = matchBuf;
+ strncpy(matchbuf, buf, place);
+ tmp = matchbuf;
/* skip any leading white space */
- while (*tmp && isspace((int) *tmp))
+ while (*tmp && isspace((int)*tmp))
++tmp;
/* Free up any memory already allocated */
for (i = i; i < num_matches; i++)
free(matches[i]);
free(matches);
- matches = (char **) NULL;
+ matches = (char **)NULL;
num_matches = 0;
}
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, '/')) {
+ if (buf[0] == '~' && strchr(tmp, '/') == NULL) {
buf = mallocstrcpy(buf, tmp);
matches = username_tab_completion(tmp, &num_matches);
}
/* Try to match everything in the current working directory that
* matches. */
- if (!matches)
+ if (matches == NULL)
matches = cwd_tab_completion(tmp, &num_matches);
/* Don't leak memory */
- free(matchBuf);
+ free(matchbuf);
#ifdef DEBUG
fprintf(stderr, "%d matches found...\n", num_matches);
buf = nrealloc(buf, strlen(buf) + strlen(matches[0]) + 1);
- if (buf[0] != '\0' && strstr(buf, "/")) {
+ if (buf[0] != '\0' && strstr(buf, "/") != NULL) {
for (tmp = buf + strlen(buf); *tmp != '/' && tmp != buf;
tmp--);
tmp++;
if (!strcmp(tmp, matches[0]))
is_dir = append_slash_if_dir(buf, lastwastab, newplace);
- if (is_dir)
+ if (is_dir != 0)
break;
copyto = tmp;
/* Check to see if all matches share a beginning, and, if so,
tack it onto buf and then beep */
- if (buf[0] != '\0' && strstr(buf, "/")) {
+ if (buf[0] != '\0' && strstr(buf, "/") != NULL) {
for (tmp = buf + strlen(buf); *tmp != '/' && tmp != buf;
tmp--);
tmp++;
} else
tmp = buf;
- for (pos = 0; *tmp == matches[0][pos] && *tmp != 0 &&
+ for (pos = 0; *tmp == matches[0][pos] && *tmp != '\0' &&
pos <= strlen(matches[0]); pos++)
tmp++;
/* Ok -- the last char was a TAB. Since they
* just hit TAB again, print a list of all the
* available choices... */
- if (matches && num_matches > 1) {
+ if (matches != NULL && num_matches > 1) {
/* Blank the edit window, and print the matches out there */
blank_edit();
int aisdir = stat(a, &fileinfo) != -1 && S_ISDIR(fileinfo.st_mode);
int bisdir = stat(b, &fileinfo) != -1 && S_ISDIR(fileinfo.st_mode);
- if (aisdir && !bisdir)
+ if (aisdir != 0 && bisdir == 0)
return -1;
- if (!aisdir && bisdir)
+ if (aisdir == 0 && bisdir != 0)
return 1;
-#ifdef HAVE_STRCASECMP
return strcasecmp(a, b);
-#else
- return strcmp(a, b);
-#endif
}
/* Free our malloc()ed memory */
size_t path_len;
dir = opendir(path);
- if (!dir)
+ if (dir == NULL)
return NULL;
*numents = 0;
int numents = 0, i = 0, j = 0, kbinput = 0, longest = 0, abort = 0;
int col = 0, selected = 0, editline = 0, width = 0, filecols = 0;
int lineno = 0, kb;
- char **filelist = (char **) NULL;
-#ifndef DISABLE_MOUSE
-#ifdef NCURSES_MOUSE_VERSION
+ char **filelist = (char **)NULL;
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
MEVENT mevent;
-#endif
#endif
assert(inpath != NULL);
blank_statusbar_refresh();
-#if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE)
+#if !defined(DISABLE_HELP) || (!defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION))
currshortcut = browser_list;
#endif
switch (kbinput) {
-#ifndef DISABLE_MOUSE
-#ifdef NCURSES_MOUSE_VERSION
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
case KEY_MOUSE:
if (getmouse(&mevent) == ERR)
return retval;
/* Longest is the width of each column. There are two
* spaces between each column. */
- selected = (lineno / editwinrows) * editwinrows * width
+ selected = (lineno / editwinrows) * editwinrows * width
+ mevent.y * width + mevent.x / (longest + 2);
/* If they clicked beyond the end of a row, select the
do_mouse();
break;
-#endif
#endif
case NANO_UP_KEY:
case KEY_UP:
/* Note: The case of the user's being completely outside the
operating directory is handled elsewhere, before this
point */
- if (operating_dir) {
+ if (operating_dir != NULL) {
if (check_operating_dir(path, 0)) {
statusbar(_("Can't visit parent in restricted mode"));
beep();
curs_set(0);
#ifndef DISABLE_OPERATINGDIR
- if (operating_dir) {
+ if (operating_dir != NULL) {
if (check_operating_dir(answer, 0)) {
statusbar(_("Can't go outside of %s in restricted mode"), operating_dir);
break;
blank_edit();
- if (width)
+ if (width != 0)
i = width * editwinrows * ((selected / width) / editwinrows);
else
i = 0;
else if (st.st_size >= (1 << 20)) /* at least 1 meg */
sprintf(foo + longest - 7, "%4d MB",
(int) st.st_size >> 20);
- else /* Its more than 1 k and less than a meg */
+ else /* It's more than 1 k and less than a meg */
sprintf(foo + longest - 7, "%4d KB",
(int) st.st_size >> 10);
}
char *from = getcwd(NULL, 0);
#endif
- bob = do_browser(from ? from : "./");
+ bob = do_browser(from != NULL ? from : "./");
free(from);
return bob;
}
- /* If the string is a directory, pass do_browser that */
+ /* If the string is a directory, pass do_browser() that */
st = filestat(inpath);
if (S_ISDIR(st.st_mode))
return do_browser(inpath);
shortcut *insertfile_list = NULL;
shortcut *help_list = NULL;
shortcut *spell_list = NULL;
+
#ifndef NANO_SMALL
shortcut *extcmd_list = NULL;
#endif
+
#ifndef DISABLE_BROWSER
shortcut *browser_list = NULL;
#endif
#ifdef ENABLE_COLOR
- const colortype *colorstrings = NULL;
- syntaxtype *syntaxes = NULL;
- char *syntaxstr = NULL;
+const colortype *colorstrings = NULL;
+syntaxtype *syntaxes = NULL;
+char *syntaxstr = NULL;
#endif
-#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) || !defined(DISABLE_HELP)
+#if !defined(DISABLE_BROWSER) || !defined(DISABLE_HELP) || (!defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION))
const shortcut *currshortcut; /* Current shortcut list we're using */
#endif
void toggle_init(void)
{
char *toggle_const_msg, *toggle_autoindent_msg, *toggle_suspend_msg,
- *toggle_nohelp_msg, *toggle_picomode_msg, *toggle_mouse_msg,
- *toggle_cuttoend_msg, *toggle_noconvert_msg, *toggle_dos_msg,
- *toggle_mac_msg, *toggle_backup_msg, *toggle_smooth_msg;
+ *toggle_nohelp_msg, *toggle_picomode_msg, *toggle_cuttoend_msg,
+ *toggle_noconvert_msg, *toggle_dos_msg, *toggle_mac_msg,
+ *toggle_backup_msg, *toggle_smooth_msg;
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
+ char *toggle_mouse_msg;
+#endif
#ifndef DISABLE_WRAPPING
char *toggle_wrap_msg;
#endif
toggle_suspend_msg = _("Suspend");
toggle_nohelp_msg = _("Help mode");
toggle_picomode_msg = _("Pico mode");
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
toggle_mouse_msg = _("Mouse support");
+#endif
toggle_cuttoend_msg = _("Cut to end");
toggle_noconvert_msg = _("No conversion from DOS/Mac format");
toggle_dos_msg = _("Writing file in DOS format");
#ifndef DISABLE_WRAPPING
toggle_init_one(TOGGLE_WRAP_KEY, toggle_wrap_msg, NO_WRAP);
#endif
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
toggle_init_one(TOGGLE_MOUSE_KEY, toggle_mouse_msg, USE_MOUSE);
+#endif
toggle_init_one(TOGGLE_CUTTOEND_KEY, toggle_cuttoend_msg, CUT_TO_END);
#ifdef ENABLE_MULTIBUFFER
toggle_init_one(TOGGLE_LOAD_KEY, toggle_load_msg, MULTIBUFFER);
do_help);
#ifdef ENABLE_MULTIBUFFER
- if (open_files != NULL && (open_files->prev || open_files->next))
+ if (open_files != NULL && (open_files->prev != NULL || open_files->next != NULL))
sc_init_one(&main_list, NANO_EXIT_KEY, _("Close"),
IFHELP(nano_exit_msg, 0), NANO_EXIT_FKEY, 0, VIEW,
do_exit);
IFHELP(nano_cancel_msg, 0), 0, 0, VIEW, 0);
#endif
-#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) || !defined (DISABLE_HELP)
+#if !defined(DISABLE_BROWSER) || !defined(DISABLE_HELP) || (!defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION))
currshortcut = main_list;
#endif
#ifndef NANO_SMALL
return 0;
/* AHEM, if we only have a screen or less of text, DON'T do an
- edit_update, just move the cursor to editbot! */
+ edit_update(), just move the cursor to editbot! */
if (edittop == fileage && editbot == filebot && totlines < editwinrows) {
current = editbot;
reset_cursor();
+#ifndef NANO_SMALL
+ /* ...unless marking is on, in which case we need it to update
+ the highlight. */
+ if (ISSET(MARK_ISSET))
+ edit_update(current, NONE);
+#endif
} else if (editbot != filebot || edittop == fileage) {
current_y = 0;
current = editbot;
/* Return value 1 means we moved down, 0 means we were already at the
* bottom. */
-int do_down(void) {
+int do_down(void)
+{
wrap_reset();
UNSET(KEEP_CUTBUFFER);
check_statblank();
if (current->data[current_x] != '\0')
current_x++;
- else if (current->next) {
+ else if (current->next != NULL) {
do_down();
current_x = 0;
}
#ifdef ENABLE_MULTIBUFFER
/* then save all of the other modified loaded files, if any */
- if (open_files) {
+ if (open_files != NULL) {
openfilestruct *tmp;
tmp = open_files;
- while (open_files->prev)
+ while (open_files->prev != NULL)
open_files = open_files->prev;
- while (open_files->next) {
+ while (open_files->next != NULL) {
/* if we already saved the file above (i. e. if it was the
currently loaded file), don't save it again */
bottomwin = newwin(3 - no_help(), COLS, LINES - 3 + no_help(), 0);
#ifdef PDCURSES
- /* Oops, I guess we need this again.
- Moved here so the keypad still works after a Meta-X, for example */
+ /* Oops, I guess we need this again. Moved here so the keypad still
+ works after a Meta-X, for example */
keypad(edit, TRUE);
keypad(bottomwin, TRUE);
#endif
}
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
void mouse_init(void)
{
-#ifndef DISABLE_MOUSE
-#ifdef NCURSES_MOUSE_VERSION
if (ISSET(USE_MOUSE)) {
keypad_on(edit, 1);
keypad_on(bottomwin, 1);
mouseinterval(50);
} else
mousemask(0, NULL);
-#endif
-#endif
}
+#endif
#ifndef DISABLE_HELP
/* This function allocates help_text, and stores the help string in it.
print1opt("-k", "--cut", _("Let ^K cut from cursor to end of line"));
#endif
print1opt("-l", "--nofollow", _("Don't follow symbolic links, overwrite"));
-#ifndef DISABLE_MOUSE
-#ifdef NCURSES_MOUSE_VERSION
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
print1opt("-m", "--mouse", _("Enable mouse"));
#endif
-#endif
#ifndef DISABLE_OPERATINGDIR
print1opt(_("-o [dir]"), _("--operatingdir=[dir]"), _("Set operating directory"));
#endif
#ifdef DISABLE_JUSTIFY
printf(" --disable-justify");
#endif
-#ifdef DISABLE_MOUSE
+#if defined(DISABLE_MOUSE) || !defined(NCURSES_MOUSE_VERSION)
printf(" --disable-mouse");
#endif
#ifndef ENABLE_NLS
RETSIGTYPE cancel_fork(int signal)
{
- if (kill(pid, SIGKILL)==-1) nperror("kill");
+ if (kill(pid, SIGKILL) == -1)
+ nperror("kill");
}
int open_pipe(const char *command)
/* original and temporary handlers for SIGINT */
#ifdef _POSIX_VDISABLE
struct termios term, newterm;
-#endif /* _POSIX_VDISABLE */
+#endif /* _POSIX_VDISABLE */
int cancel_sigs = 0;
/* cancel_sigs == 1 means that sigaction() failed without changing
* the signal handlers. cancel_sigs == 2 means the signal handler
/* See if the platform supports disabling individual control
* characters. */
#ifdef _POSIX_VDISABLE
- if (!cancel_sigs && tcgetattr(0, &term) == -1) {
+ if (cancel_sigs == 0 && tcgetattr(0, &term) == -1) {
cancel_sigs = 2;
nperror("tcgetattr");
}
- if (!cancel_sigs) {
+ if (cancel_sigs == 0) {
newterm = term;
/* Grab oldterm's VINTR key :-) */
newterm.c_cc[VINTR] = oldterm.c_cc[VINTR];
#endif /* _POSIX_VDISABLE */
f = fdopen(fd[0], "rb");
- if (!f)
+ if (f == NULL)
nperror("fdopen");
read_file(f, "stdin", 0);
nperror("wait");
#ifdef _POSIX_VDISABLE
- if (!cancel_sigs && tcsetattr(0, TCSANOW, &term) == -1)
+ if (cancel_sigs == 0 && tcsetattr(0, TCSANOW, &term) == -1)
nperror("tcsetattr");
#endif /* _POSIX_VDISABLE */
}
#endif /* NANO_SMALL */
-#ifndef DISABLE_MOUSE
-#ifdef NCURSES_MOUSE_VERSION
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
void do_mouse(void)
{
MEVENT mevent;
}
}
#endif
-#endif
/* The user typed a printable character; add it to the edit buffer. */
void do_char(char ch)
* where we think the cursor is.
*/
if (current_y == editwinrows - 1) {
- edit_update(current, CENTER);
+#ifndef NANO_SMALL
+ if (ISSET(SMOOTHSCROLL))
+ edit_update(current, NONE);
+ else
+#endif
+ edit_update(current, CENTER);
reset_cursor();
} else {
current_y++;
{
filestruct *old = current;
- assert(current != NULL);
+ assert(current != NULL && current->data != NULL);
/* Skip letters in this word first. */
while (current_x >= 0 && isalnum((int)current->data[current_x]))
temp->prev = inptr;
temp->next = inptr->next;
temp->prev->next = temp;
- /* If !temp->next, then temp is the last line of the file, so we
- * must set filebot. */
- if (temp->next)
+ /* If temp->next is NULL, then temp is the last line of the
+ * file, so we must set filebot. */
+ if (temp->next != NULL)
temp->next->prev = temp;
else
filebot = temp;
while (1) {
/* make sure word is still mis-spelt (i.e. when multi-errors) */
- if (findnextstr(TRUE, FALSE, fileage, beginx_top, word) != NULL) {
+ if (findnextstr(TRUE, FALSE, fileage, beginx_top, word)) {
/* find whole words only */
if (!is_whole_word(current_x, current->data, word))
return TRUE;
}
-/* Integrated spell checking using 'spell' program.
- Return value: NULL for normal termination, otherwise the error string */
+/* Integrated spell checking using 'spell' program. Return value: NULL
+ * for normal termination, otherwise the error string. */
char *do_int_speller(char *tempfile_name)
{
char *read_buff, *read_buff_ptr, *read_buff_word;
}
- *read_buff_ptr = (char) NULL;
+ *read_buff_ptr = (char)NULL;
close(uniq_fd[0]);
/* Process the spelling errors */
read_buff_word = read_buff_ptr = read_buff;
- while (*read_buff_ptr) {
+ while (*read_buff_ptr != '\0') {
if ((*read_buff_ptr == '\n') || (*read_buff_ptr == '\r')) {
- *read_buff_ptr = (char) NULL;
+ *read_buff_ptr = (char)NULL;
if (read_buff_word != read_buff_ptr) {
if (!do_int_spell_fix(read_buff_word)) {
read_buff_word = read_buff_ptr;
return NULL;
}
-/* External spell checking.
- Return value: NULL for normal termination, otherwise the error string */
+/* External spell checking. Return value: NULL for normal termination,
+ * otherwise the error string. */
char *do_alt_speller(char *tempfile_name)
{
int alt_spell_status, lineno_cur = current->lineno;
{
#ifdef DISABLE_SPELLER
nano_disabled_msg();
- return (TRUE);
+ return TRUE;
#else
char *temp, *spell_msg = _("Generic error");
add_open_file(1);
#endif
- if (alt_speller)
+ if (alt_speller != NULL)
spell_msg = do_alt_speller(temp);
else
spell_msg = do_int_speller(temp);
* not be whitespace. */
int justify_format(int changes_allowed, filestruct *line, size_t skip)
{
+ const char *punct = ".?!";
+ const char *brackets = "'\")}]>";
char *back, *front;
/* These four asserts are assumptions about the input data. */
*front = ' ';
}
/* these tests are safe since line->data + skip is not a space */
- if (*front == ' ' && *(front-1) == ' ') {
- const char *brackets = _("'\")}]>");
- const char *punct = _(".?!");
+ if (*front == ' ' && *(front - 1) == ' ') {
const char *bob = front - 2;
remove_space = 1;
/* Remove spaces from the end of the line, except maintain 1 after a
* sentence punctuation. */
- while (line->data < back && *(back-1) == ' ')
+ while (line->data < back && *(back - 1) == ' ')
back--;
if (line->data < back && *back == ' ' &&
- (*(back-1) == '.' || *(back-1) == '!' || *(back-1) == '?'))
+ strchr(punct, *(back - 1)) != NULL)
back++;
if (!changes_allowed && back != front)
return 1;
/* This assert merely documents a fact about the loop above. */
- assert(changes_allowed || back == front);
+ assert(changes_allowed != 0 || back == front);
/* Now back is the new end of line->data. */
if (back != front) {
/* This line is part of a paragraph. So we must search back to
* the first line of this paragraph. First we check items 1) and
* 3) above. */
- while (current->prev && quotes_match(current->data,
+ while (current->prev != NULL && quotes_match(current->data,
quote_len, IFREG(current->prev->data, &qreg))) {
size_t temp_id_len =
indent_length(current->prev->data + quote_len);
/* There is no next paragraph, so nothing to justify. */
if (current->next == NULL) {
placewewant = 0;
- if (current_y > editwinrows - 4)
+ if (current_y > editwinrows - 1)
edit_update(current, CENTER);
else
edit_refresh();
par_len = 1;
indent_len = indent_length(line->data + quote_len);
- while (line->next && quotes_match(current->data, quote_len,
+ while (line->next != NULL && quotes_match(current->data, quote_len,
IFREG(line->next->data, &qreg))) {
size_t temp_id_len = indent_length(line->next->data + quote_len);
* made. If there are, we do backup_lines(), which copies the
* original paragraph to the cutbuffer for unjustification, and
* then calls justify_format() on the remaining lines. */
- if (first_mod_line == NULL &&
- justify_format(0, current, indent_len))
+ if (first_mod_line == NULL && justify_format(0, current, indent_len))
first_mod_line = backup_lines(current, par_len, quote_len);
line_len = strlen(current->data);
#endif
if (indent_len + break_pos == next_line_len) {
line = current->next;
+
+ /* Don't destroy edittop! */
+ if (line == edittop)
+ edittop = current;
+
unlink_node(line);
delete_node(line);
totlines--;
renumber(first_mod_line);
}
- if (current_y > editwinrows - 4)
+ if (current_y > editwinrows - 1)
edit_update(current, CENTER);
else
edit_refresh();
/* Now get a keystroke and see if it's unjustify; if not, unget the
* keystroke and return. */
-#ifndef DISABLE_MOUSE
-#ifdef NCURSES_MOUSE_VERSION
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
/* If it was a mouse click, parse it with do_mouse() and it might
* become the unjustify key. Else give it back to the input stream. */
if ((i = wgetch(edit)) == KEY_MOUSE)
do_mouse();
else
ungetch(i);
-#endif
#endif
if ((i = wgetch(edit)) != NANO_UNJUSTIFY_KEY) {
tcsetattr(0, TCSANOW, &oldterm);
/* We used to re-enable the default SIG_DFL and raise SIGTSTP, but
- then we could be (and were) interrupted in the middle of the call.
- So we do it the mutt way instead */
+ then we could be (and were) interrupted in the middle of the call.
+ So we do it the mutt way instead */
kill(0, SIGSTOP);
}
int result = 0;
struct winsize win;
- if (!tty)
+ if (tty == NULL)
return;
fd = open(tty, O_RDWR);
if (fd == -1)
case TOGGLE_SUSPEND_KEY:
signal_init();
break;
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
case TOGGLE_MOUSE_KEY:
mouse_init();
break;
+#endif
case TOGGLE_NOHELP_KEY:
wclear(bottomwin);
wrefresh(bottomwin);
case TOGGLE_MAC_KEY:
UNSET(DOS_FILE);
break;
+#ifdef ENABLE_COLOR
case TOGGLE_SYNTAX_KEY:
edit_refresh();
- break;
+ break;
+#endif
}
/* We are assuming here that shortcut_init() above didn't free and
/* This function returns the correct keystroke, given the A,B,C or D
input key. This is a common sequence of many terms which send
Esc-O-[A-D] or Esc-[-[A-D]. */
-int ABCD(int input)
+int abcd(int input)
{
switch (input) {
case 'A':
case 'a':
- return (KEY_UP);
+ return KEY_UP;
case 'B':
case 'b':
- return (KEY_DOWN);
+ return KEY_DOWN;
case 'C':
case 'c':
- return (KEY_RIGHT);
+ return KEY_RIGHT;
case 'D':
case 'd':
- return (KEY_LEFT);
+ return KEY_LEFT;
default:
return 0;
}
#ifdef HAVE_GETOPT_LONG
int option_index = 0;
- struct option long_options[] = {
+ const struct option long_options[] = {
{"help", 0, 0, 'h'},
#ifdef ENABLE_MULTIBUFFER
{"multibuffer", 0, 0, 'F'},
#endif
{"const", 0, 0, 'c'},
{"nofollow", 0, 0, 'l'},
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
{"mouse", 0, 0, 'm'},
+#endif
#ifndef DISABLE_OPERATINGDIR
{"operatingdir", 1, 0, 'o'},
#endif
};
#endif
- /* Flag inits... */
- SET(FOLLOW_SYMLINKS);
-
-#ifndef NANO_SMALL
#ifdef ENABLE_NLS
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
#endif
-#endif
#ifdef ENABLE_NANORC
{
SET(NO_CONVERT);
break;
#endif
- case 'Q':
#ifndef DISABLE_JUSTIFY
+ case 'Q':
quotestr = optarg;
break;
-#else
- usage();
- exit(1);
#endif
#ifdef HAVE_REGEX_H
case 'R':
break;
#endif
case 'l':
- UNSET(FOLLOW_SYMLINKS);
+ SET(NOFOLLOW_SYMLINKS);
break;
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
case 'm':
SET(USE_MOUSE);
break;
+#endif
#ifndef DISABLE_OPERATINGDIR
case 'o':
operating_dir = mallocstrcpy(operating_dir, optarg);
case 'v':
SET(VIEW_MODE);
break;
- case 'w':
#ifdef DISABLE_WRAPPING
- usage();
- exit(0);
-#else
+ case 'w':
SET(NO_WRAP);
break;
-#endif /* DISABLE_WRAPPING */
+#endif
case 'x':
SET(NO_HELP);
break;
/* See if we were invoked with the name "pico" */
argv0 = strrchr(argv[0], '/');
- if ((argv0 && strstr(argv0, "pico"))
- || (!argv0 && strstr(argv[0], "pico")))
+ if ((argv0 != NULL && strstr(argv0, "pico") != NULL)
+ || (argv0 == NULL && strstr(argv[0], "pico") != NULL))
SET(PICO_MODE);
/* See if there's a non-option in argv (first non-option is the
#endif
window_init();
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
mouse_init();
+#endif
if (!ISSET(ALT_KEYPAD)) {
keypad(edit, TRUE);
while (1) {
-#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) || !defined(DISABLE_HELP)
+#if !defined(DISABLE_BROWSER) || !defined(DISABLE_HELP) || (!defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION))
currshortcut = main_list;
#endif
kbinput = wgetch(edit);
if ((kbinput <= 'D' && kbinput >= 'A') ||
(kbinput <= 'd' && kbinput >= 'a'))
- kbinput = ABCD(kbinput);
+ kbinput = abcd(kbinput);
else if (kbinput <= 'z' && kbinput >= 'j')
print_numlock_warning();
else if (kbinput <= 'S' && kbinput >= 'P')
case 'b':
case 'c':
case 'd':
- kbinput = ABCD(kbinput);
+ kbinput = abcd(kbinput);
break;
case 'H':
kbinput = KEY_HOME;
/* Look through the main shortcut list to see if we've hit a
shortcut key */
-#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) || !defined (DISABLE_HELP)
+#if !defined(DISABLE_BROWSER) || !defined (DISABLE_HELP) || (!defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION))
for (s = currshortcut; s != NULL && !keyhandled; s = s->next) {
#else
for (s = main_list; s != NULL && !keyhandled; s = s->next) {
keyhandled = 1;
}
-#ifndef USE_SLANG
/* Hack, make insert key do something useful, like insert file */
if (kbinput == KEY_IC) {
-#else
- if (0) {
-#endif
do_insertkey:
#ifdef ENABLE_MULTIBUFFER
/* Last gasp, stuff that's not in the main lists */
if (!keyhandled)
switch (kbinput) {
-#ifndef DISABLE_MOUSE
-#ifdef NCURSES_MOUSE_VERSION
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
case KEY_MOUSE:
do_mouse();
break;
-#endif
#endif
case 0: /* Erg */
#ifdef USE_SLANG /* Slang support enabled */
#include <slcurses.h>
-#define KEY_DC 0x113
+#define KEY_IC SL_KEY_IC
+#define KEY_DC SL_KEY_DELETE
#elif defined(HAVE_NCURSES_H)
#include <ncurses.h>
#else /* Uh oh */
# endif
#endif
+#if !defined(HAVE_STRCASECMP) || !defined(HAVE_STRNCASECMP)
+# ifndef HAVE_STRCASECMP
+# define strcasecmp strcmp
+# endif
+# ifndef HAVE_STRNCASECMP
+# define strncasecmp strncmp
+# endif
+#endif
+
/* HP-UX 10 & 11 do not seem to support KEY_HOME and KEY_END */
#ifndef KEY_HOME
#define KEY_HOME -1
#define KEY_END -1
#endif /* KEY_END */
-
#define VERMSG "GNU nano " VERSION
#if defined(DISABLE_WRAPPING) && defined(DISABLE_JUSTIFY)
#define CONSTUPDATE (1<<4)
#define NO_HELP (1<<5)
#define PICO_MODE (1<<6)
-#define FOLLOW_SYMLINKS (1<<7)
+#define NOFOLLOW_SYMLINKS (1<<7)
#define SUSPEND (1<<8)
#define NO_WRAP (1<<9)
#define AUTOINDENT (1<<10)
#define NO_CONVERT (1<<26)
#define BACKUP_FILE (1<<27)
#define NO_RCFILE (1<<28)
-#define COLOR_SYNTAX (1<<28)
+#define COLOR_SYNTAX (1<<29)
/* Control key sequences, changing these would be very very bad */
extern int editwinrows;
extern int current_x, current_y, totlines;
extern int placewewant;
+#ifndef NANO_SMALL
extern int mark_beginx;
+#endif
extern long totsize;
extern int temp_opt;
extern int wrap_at, flags, tabsize;
extern struct stat fileinfo;
extern filestruct *current, *fileage, *edittop, *editbot, *filebot;
-extern filestruct *cutbuffer, *mark_beginbuf;
+extern filestruct *cutbuffer;
+#ifndef NANO_SMALL
+extern filestruct *mark_beginbuf;
+#endif
#ifdef ENABLE_MULTIBUFFER
extern openfilestruct *open_files;
void print_view_warning(void);
void global_init(int save_cutbuffer);
void window_init(void);
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
void mouse_init(void);
+#endif
#ifndef DISABLE_HELP
void help_init(void);
#endif
#ifndef NANO_SMALL
void do_toggle(const toggle *which);
#endif
-int ABCD(int input);
+int abcd(int input);
/* Public functions in rcfile.c */
#ifdef ENABLE_NANORC
{"fill", 0},
#endif
{"keypad", ALT_KEYPAD},
-#ifndef DISABLE_MOUSE
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
{"mouse", USE_MOUSE},
#endif
#ifdef ENABLE_MULTIBUFFER
#ifndef NANO_SMALL
{"noconvert", NO_CONVERT},
#endif
- {"nofollow", FOLLOW_SYMLINKS},
+ {"nofollow", NOFOLLOW_SYMLINKS},
{"nohelp", NO_HELP},
#ifndef DISABLE_WRAPPING
{"nowrap", NO_WRAP},
{"operatingdir", 0},
#endif
{"pico", PICO_MODE},
-#ifndef NANO_SMALL
+#ifndef DISABLE_JUSTIFY
{"quotestr", 0},
#endif
#ifdef HAVE_REGEX_H
else {
if (ptr == NULL || strncasecmp(ptr, "end=", 4)) {
rcfile_error(_
- ("\n\t\"start=\" requires a corresponding \"end=\""));
+ ("\"start=\" requires a corresponding \"end=\""));
return;
}
/* Else skip to the next space */
keyword = ptr;
ptr = parse_next_word(ptr);
- if (!ptr)
+ if (ptr == NULL)
continue;
/* Else try to parse the keyword */
fprintf(stderr, _("parse_rcfile: Parsing option %s\n"),
rcopts[i].name);
#endif
- if (set == 1 || rcopts[i].flag == FOLLOW_SYMLINKS) {
+ if (set == 1) {
if (!strcasecmp(rcopts[i].name, "tabsize")
#ifndef DISABLE_OPERATINGDIR
|| !strcasecmp(rcopts[i].name, "operatingdir")
#include "proto.h"
#include "nano.h"
+static int past_editbuff;
+ /* findnextstr() is now searching lines not displayed */
+
/* Regular expression helper functions */
#ifdef HAVE_REGEX_H
search_init_globals();
/* Clear the backupstring if we've changed from Pico mode to regular
- mode */
+ mode */
if (ISSET(CLEAR_BACKUPSTRING)) {
free(backupstring);
backupstring = NULL;
last_search. */
if (ISSET(PICO_MODE)) {
- if (backupstring == NULL || !strcmp(backupstring, last_search))
- backupstring = mallocstrcpy(backupstring, "");
+ if (backupstring == NULL || !strcmp(backupstring, last_search)) {
+ backupstring = charalloc(1);
+ backupstring[0] = '\0';
+ }
}
else if (backupstring == NULL)
backupstring = mallocstrcpy(backupstring, last_search);
/* If using Pico messages, we do things the old fashioned way... */
- if (ISSET(PICO_MODE) && last_search[0]) {
+ if (ISSET(PICO_MODE) && last_search[0] != '\0') {
buf = charalloc(COLS / 3 + 7);
/* We use COLS / 3 here because we need to see more on the line */
sprintf(buf, " [%.*s%s]", COLS / 3, last_search,
(sln == strlen(datastr) || !isalpha((int) datastr[sln]));
}
-static int past_editbuff;
- /* findnextstr() is now searching lines not displayed */
-
filestruct *findnextstr(int quiet, int bracket_mode,
const filestruct *begin, int beginx,
const char *needle)
if (fileptr == edittop->prev)
past_editbuff = 1;
- /* SOF reached ?, wrap around once */
+ /* SOF reached?, wrap around once */
/* ? */ if (fileptr == NULL) {
if (bracket_mode)
return NULL;
search_last_line = 0;
didfind = findnextstr(FALSE, FALSE, current, current_x, answer);
- if ((fileptr == current) && (fileptr_x == current_x) &&
- didfind != NULL)
+ if ((fileptr == current) && (fileptr_x == current_x) && didfind != NULL)
statusbar(_("This is the only occurrence"));
search_abort();
* replacement using \1, \2, \3, etc. */
c = last_replace;
- while (*c) {
+ while (*c != '\0') {
if (*c != '\\') {
if (create_flag)
*string++ = *c;
strcat(copy, last_replace);
#ifdef HAVE_REGEX_H
else
- (void) replace_regexp(copy + current_x, 1);
+ replace_regexp(copy + current_x, 1);
#endif
/* The tail of the original line */
FALSE, begin, *beginx, prevanswer);
/* No more matches. Done! */
- if (!fileptr)
+ if (fileptr == NULL)
break;
/* Make sure only whole words are found */
replaceall = 1;
copy = replace_line();
- if (!copy) {
+ if (copy == NULL) {
statusbar(_("Replace failed: unknown subexpression!"));
replace_abort();
return 0;
current_x = 0;
- /* if save_pos is non-zero, don't change the cursor position when
+ /* if save_pos is nonzero, don't change the cursor position when
updating the edit window */
if (save_pos)
edit_update(current, NONE);
ch_under_cursor = current->data[current_x];
- if ((!(pos = strchr(brackets, ch_under_cursor))) || (!((offset = pos - brackets) < 8))) {
+ if (((pos = strchr(brackets, ch_under_cursor)) == NULL) || (((offset = pos - brackets) < 8) == 0)) {
statusbar(_("Not a bracket"));
return 1;
}
while (1) {
search_last_line = 0;
- if (findnextstr(1, 1, current, current_x, regexp_pat)) {
+ if (findnextstr(1, 1, current, current_x, regexp_pat) != NULL) {
have_past_editbuff |= past_editbuff;
if (current->data[current_x] == ch_under_cursor) /* found identical bracket */
count++;
int is_cntrl_char(int c)
{
- if (iscntrl(c) || ((c & 127) != 127 && iscntrl(c & 127)))
- return 1;
- else
- return 0;
+ return (-128 <= c && c < -96) || (0 <= c && c < 32) ||
+ (127 <= c && c < 160);
}
int num_of_digits(int n)
#endif /* !NANO_SMALL */
/* This is now mutt's version (called mutt_stristr) because it doesn't
- use memory allocation to do a simple search (yuck). */
+ * use memory allocation to do a simple search (yuck). */
const char *stristr(const char *haystack, const char *needle)
{
const char *p, *q;
- if (!haystack)
+ if (haystack == NULL)
return NULL;
- if (!needle)
- return (haystack);
+ if (needle == NULL)
+ return haystack;
- while (*(p = haystack)) {
- for (q = needle; *p && *q && tolower(*p) == tolower(*q); p++, q++)
+ while (*(p = haystack) != '\0') {
+ for (q = needle; *p != 0 && *q != 0 && tolower(*p) == tolower(*q); p++, q++)
;
- if (!*q)
+ if (*q == 0)
return haystack;
haystack++;
}
* screen. Note that nperror causes the window to flicker once. */
void nperror(const char *s)
{
- /* leave ncurses mode, go to the terminal */
+ /* leave ncurses mode, go to the terminal */
if (endwin() != ERR) {
perror(s); /* print the error */
total_refresh(); /* return to ncurses and repaint */
/* Panic save? */
- if (!(r = malloc(howmuch)))
+ if ((r = malloc(howmuch)) == NULL)
die(_("nano: malloc: out of memory!"));
return r;
}
-/* We're going to need this too - Hopefully this will minimize
- the transition cost of moving to the appropriate function. */
+/* We're going to need this too - Hopefully this will minimize the
+ * transition cost of moving to the appropriate function. */
char *charalloc(size_t howmuch)
{
char *r = (char *)malloc(howmuch * sizeof(char));
{
void *r;
- if (!(r = realloc(ptr, howmuch)))
+ if ((r = realloc(ptr, howmuch)) == NULL)
die(_("nano: realloc: out of memory!"));
return r;
if (src == dest)
return dest;
- if (dest)
+ if (dest != NULL)
free(dest);
- if (!src)
+ if (src == NULL)
return NULL;
dest = charalloc(strlen(src) + 1);
retrypat = NULL;
retrytext = NULL;
- while (*text || *pattern) {
+ while (*text != '\0' || *pattern != '\0') {
ch = *pattern++;
switch (ch) {
default:
if (*text == ch) {
- if (*text)
+ if (*text != '\0')
text++;
break;
}
- if (*text) {
+ if (*text != '\0') {
pattern = retrypat;
text = ++retrytext;
break;
return FALSE;
}
- if (!pattern)
+ if (pattern == NULL)
return FALSE;
}
else
answer[0] = '\0';
-#if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE)
+#if !defined(DISABLE_HELP) || (!defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION))
currshortcut = s;
#endif
case 545: /* Right alt again */
break;
#endif
-#ifndef DISABLE_MOUSE
-#ifdef NCURSES_MOUSE_VERSION
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
case KEY_MOUSE:
do_mouse();
break;
-#endif
#endif
case NANO_HOME_KEY:
case KEY_HOME:
s = s->next;
if (s == NULL)
goto break_completely_out;
- }
+ }
}
break_completely_out:
const filestruct *ptr = edittop;
size_t x;
- /* Yuck. This condition can be true after open_file when opening the
- * first file. */
+ /* Yuck. This condition can be true after open_file() when opening
+ * the first file. */
if (edittop == NULL)
return;
while (k < start + COLS) {
/* Note the fifth parameter to regexec. It says not to
* match the beginning-of-line character unless
- * k == 0. If regexec returns non-zero, there are
- * no more matches in the line. */
+ * k == 0. If regexec returns nonzero, there are no
+ * more matches in the line. */
if (regexec(&start_regexp, &fileptr->data[k], 1,
&startmatch, k == 0 ? 0 : REG_NOTBOL))
break;
* fileptr and after the start. Is there an end after
* the start at all? We don't paint unterminated starts. */
end_line = fileptr;
- while (end_line != NULL &&
- regexec(&end_regexp, end_line->data, 1,
- &endmatch, 0))
+ while (end_line != NULL && regexec(&end_regexp, end_line->data,
+ 1, &endmatch, 0))
end_line = end_line->next;
/* No end found, or it is too early. */
- if (end_line == NULL ||
- end_line->lineno < fileptr->lineno ||
+ if (end_line == NULL || end_line->lineno < fileptr->lineno ||
(end_line == fileptr && endmatch.rm_eo <= start))
goto step_two;
/* There is no end on this line. But we haven't
* yet looked for one on later lines. */
end_line = fileptr->next;
- while (end_line != NULL &&
- regexec(&end_regexp, end_line->data, 1,
- &endmatch, 0))
+ while (end_line != NULL && regexec(&end_regexp,
+ end_line->data, 1, &endmatch, 0))
end_line = end_line->next;
if (end_line != NULL) {
assert(0 <= x_start && x_start < COLS);
size_t pos;
size_t page_start;
- if (!fileptr)
+ if (fileptr == NULL)
return;
line = fileptr->lineno - edittop->lineno;
/* Refresh the screen without changing the position of lines. */
void edit_refresh(void)
{
- static int noloop = 0;
- int nlines = 0, currentcheck = 0;
-
/* Neither of these conditions should occur, but they do. edittop is
* NULL when you open an existing file on the command line, and
* ENABLE_COLOR is defined. Yuck. */
if (edittop == NULL)
edittop = current;
- /* Don't make the cursor jump around the screen whilst updating */
- leaveok(edit, TRUE);
-
- editbot = edittop;
- while (nlines < editwinrows) {
- update_line(editbot, current_x);
- if (editbot == current)
- currentcheck = 1;
-
- nlines++;
-
- if (editbot->next == NULL)
- break;
- editbot = editbot->next;
- }
-
- /* If noloop == 1, then we already did an edit_update without finishing
- this function. So we don't run edit_update again */
- if (!currentcheck && !noloop) {
- /* Then current has run off the screen... */
+ if (current->lineno >= edittop->lineno + editwinrows)
+ /* Note that edit_update() changes edittop so that
+ * current->lineno = edittop->lineno + editwinrows / 2. Thus
+ * when it then calls edit_refresh(), there is no danger of
+ * getting an infinite loop. */
edit_update(current, CENTER);
- noloop = 1;
- } else if (noloop)
- noloop = 0;
+ else {
+ int nlines = 0;
- while (nlines < editwinrows) {
- mvwaddstr(edit, nlines, 0, hblank);
- nlines++;
- }
+ /* Don't make the cursor jump around the screen whilst updating */
+ leaveok(edit, TRUE);
- /* What the hell are we expecting to update the screen if this isn't
- here? Luck?? */
- wrefresh(edit);
- leaveok(edit, FALSE);
+ editbot = edittop;
+ while (nlines < editwinrows) {
+ update_line(editbot, current_x);
+ nlines++;
+ if (editbot->next == NULL)
+ break;
+ editbot = editbot->next;
+ }
+ while (nlines < editwinrows) {
+ mvwaddstr(edit, nlines, 0, hblank);
+ nlines++;
+ }
+ /* What the hell are we expecting to update the screen if this
+ isn't here? Luck?? */
+ wrefresh(edit);
+ leaveok(edit, FALSE);
+ }
}
/*
/*
* Ask a simple yes/no question on the statusbar. Returns 1 for Y, 0
- * for N, 2 for All (if all is non-zero when passed in) and -1 for
- * abort (^C).
+ * for N, 2 for All (if all is nonzero when passed in) and -1 for abort
+ * (^C).
*/
int do_yesno(int all, int leavecursor, const char *msg, ...)
{
const char *yesstr; /* String of yes characters accepted */
const char *nostr; /* Same for no */
const char *allstr; /* And all, surprise! */
-#ifndef DISABLE_MOUSE
-#ifdef NCURSES_MOUSE_VERSION
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
MEVENT mevent;
-#endif
#endif
/* Yes, no and all are strings of any length. Each string consists of
kbinput = wgetch(edit);
switch (kbinput) {
-#ifndef DISABLE_MOUSE
-#ifdef NCURSES_MOUSE_VERSION
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
case KEY_MOUSE:
/* Look ma! We get to duplicate lots of code from do_mouse!! */
ungetch(yesnosquare[mevent.y][mevent.x / (COLS / 6)]);
}
break;
-#endif
#endif
case NANO_CONTROL_C:
ok = -2;
const char *ptr = help_text;
switch (kbinput) {
-#ifndef DISABLE_MOUSE
-#ifdef NCURSES_MOUSE_VERSION
+#if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
case KEY_MOUSE:
do_mouse();
break;
-#endif
#endif
case 27:
kbinput = wgetch(edit);
return 1;
}
-int keypad_on(WINDOW * win, int newval)
+int keypad_on(WINDOW *win, int newval)
{
/* This is taken right from aumix. Don't sue me. */
#ifdef HAVE_USEKEYPAD