#ifndef DISABLE_MOUSE
if (kbinput == KEY_MOUSE) {
- int mouse_x, mouse_y;
-
- /* We can click on the edit window to select a
- * filename. */
- if (get_mouseinput(&mouse_x, &mouse_y, TRUE) == 0 &&
- wmouse_trafo(edit, &mouse_y, &mouse_x, FALSE)) {
- /* longest is the width of each column. There
- * are two spaces between each column. */
- selected = (fileline / editwinrows) *
+ int mouse_x, mouse_y;
+
+ /* We can click on the edit window to select a
+ * filename. */
+ if (get_mouseinput(&mouse_x, &mouse_y, TRUE) == 0 &&
+ wmouse_trafo(edit, &mouse_y, &mouse_x, FALSE)) {
+ /* longest is the width of each column. There
+ * are two spaces between each column. */
+ selected = (fileline / editwinrows) *
(editwinrows * width) + (mouse_y *
width) + (mouse_x / (longest + 2));
- /* If they clicked beyond the end of a row,
- * select the filename at the end of that
- * row. */
- if (mouse_x > width * (longest + 2))
- selected--;
-
- /* If we're off the screen, select the last
- * filename. */
- if (selected > filelist_len - 1)
- selected = filelist_len - 1;
-
- /* If we selected the same filename as last
- * time, put back the Enter key so that it's
- * read in. */
- if (old_selected == selected)
- unget_kbinput(sc_seq_or(do_enter_void, 0), FALSE, FALSE);
- }
+ /* If they clicked beyond the end of a row,
+ * select the filename at the end of that
+ * row. */
+ if (mouse_x > width * (longest + 2))
+ selected--;
+
+ /* If we're off the screen, select the last
+ * filename. */
+ if (selected > filelist_len - 1)
+ selected = filelist_len - 1;
+
+ /* If we selected the same filename as last
+ * time, put back the Enter key so that it's
+ * read in. */
+ if (old_selected == selected)
+ unget_kbinput(sc_seq_or(do_enter_void, 0), FALSE, FALSE);
+ }
}
#endif /* !DISABLE_MOUSE */
break;
if (f->scfunc == total_refresh) {
- total_redraw();
+ total_redraw();
} else if (f->scfunc == do_help_void) {
#ifndef DISABLE_HELP
do_help_void();
#else
nano_disabled_msg();
#endif
- /* Search for a filename. */
} else if (f->scfunc == do_search) {
- curs_set(1);
- do_filesearch();
- curs_set(0);
- /* Search for another filename. */
+ /* Search for a filename. */
+ curs_set(1);
+ do_filesearch();
+ curs_set(0);
} else if (f->scfunc == do_research) {
- do_fileresearch();
+ /* Search for another filename. */
+ do_fileresearch();
} else if (f->scfunc == do_page_up) {
- if (selected >= (editwinrows + fileline % editwinrows) *
- width)
- selected -= (editwinrows + fileline % editwinrows) *
- width;
- else
- selected = 0;
+ if (selected >= (editwinrows + fileline % editwinrows) * width)
+ selected -= (editwinrows + fileline % editwinrows) * width;
+ else
+ selected = 0;
} else if (f->scfunc == do_page_down) {
- selected += (editwinrows - fileline % editwinrows) *
- width;
- if (selected > filelist_len - 1)
- selected = filelist_len - 1;
+ selected += (editwinrows - fileline % editwinrows) * width;
+ if (selected > filelist_len - 1)
+ selected = filelist_len - 1;
} else if (f->scfunc == do_first_file) {
- if (meta_key)
- selected = 0;
+ if (meta_key)
+ selected = 0;
} else if (f->scfunc == do_last_file) {
- if (meta_key)
- selected = filelist_len - 1;
- /* Go to a specific directory. */
+ if (meta_key)
+ selected = filelist_len - 1;
} else if (f->scfunc == goto_dir_void) {
- curs_set(1);
-
- i = do_prompt(TRUE,
+ /* Go to a specific directory. */
+ curs_set(1);
+ i = do_prompt(TRUE,
#ifndef DISABLE_TABCOMP
FALSE,
#endif
/* TRANSLATORS: This is a prompt. */
browser_refresh, _("Go To Directory"));
- curs_set(0);
+ curs_set(0);
#if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE)
- currmenu = MBROWSER;
+ currmenu = MBROWSER;
#endif
- bottombars(MBROWSER);
-
- /* If the directory begins with a newline (i.e. an
- * encoded null), treat it as though it's blank. */
- if (i < 0 || *answer == '\n') {
- /* We canceled. Indicate that on the statusbar, and
- * blank out ans, since we're done with it. */
- statusbar(_("Cancelled"));
- ans = mallocstrcpy(ans, "");
- continue;
- } else if (i != 0) {
- /* Put back the "Go to Directory" key and save
- * answer in ans, so that the file list is displayed
- * again, the prompt is displayed again, and what we
- * typed before at the prompt is displayed again. */
- unget_kbinput(sc_seq_or(do_gotolinecolumn_void, 0), FALSE, FALSE);
- ans = mallocstrcpy(ans, answer);
- continue;
- }
-
- /* We have a directory. Blank out ans, since we're done
- * with it. */
+ bottombars(MBROWSER);
+
+ /* If the directory begins with a newline (i.e. an
+ * encoded null), treat it as though it's blank. */
+ if (i < 0 || *answer == '\n') {
+ /* We canceled. Indicate that on the statusbar, and
+ * blank out ans, since we're done with it. */
+ statusbar(_("Cancelled"));
ans = mallocstrcpy(ans, "");
+ continue;
+ } else if (i != 0) {
+ /* Put back the "Go to Directory" key and save
+ * answer in ans, so that the file list is displayed
+ * again, the prompt is displayed again, and what we
+ * typed before at the prompt is displayed again. */
+ unget_kbinput(sc_seq_or(do_gotolinecolumn_void, 0), FALSE, FALSE);
+ ans = mallocstrcpy(ans, answer);
+ continue;
+ }
+
+ /* We have a directory. Blank out ans, since we're done
+ * with it. */
+ ans = mallocstrcpy(ans, "");
- /* Convert newlines to nulls, just before we go to the
- * directory. */
- sunder(answer);
- align(&answer);
+ /* Convert newlines to nulls, just before we go to the
+ * directory. */
+ sunder(answer);
+ align(&answer);
- new_path = real_dir_from_tilde(answer);
+ new_path = real_dir_from_tilde(answer);
- if (new_path[0] != '/') {
- new_path = charealloc(new_path, strlen(path) +
- strlen(answer) + 1);
- sprintf(new_path, "%s%s", path, answer);
- }
+ if (new_path[0] != '/') {
+ new_path = charealloc(new_path, strlen(path) +
+ strlen(answer) + 1);
+ sprintf(new_path, "%s%s", path, answer);
+ }
#ifndef DISABLE_OPERATINGDIR
- if (check_operating_dir(new_path, FALSE)) {
- statusbar(
- _("Can't go outside of %s in restricted mode"),
- operating_dir);
- free(new_path);
- continue;
- }
+ if (check_operating_dir(new_path, FALSE)) {
+ statusbar(_("Can't go outside of %s in restricted mode"),
+ operating_dir);
+ free(new_path);
+ continue;
+ }
#endif
- dir = opendir(new_path);
- if (dir == NULL) {
- /* We can't open this directory for some reason.
- * Complain. */
- statusbar(_("Error reading %s: %s"), answer,
- strerror(errno));
- beep();
- free(new_path);
- continue;
- }
-
- /* Start over again with the new path value. */
- free(path);
- path = new_path;
- goto change_browser_directory;
+ dir = opendir(new_path);
+ if (dir == NULL) {
+ /* We can't open this directory for some reason.
+ * Complain. */
+ statusbar(_("Error reading %s: %s"), answer,
+ strerror(errno));
+ beep();
+ free(new_path);
+ continue;
+ }
+
+ /* Start over again with the new path value. */
+ free(path);
+ path = new_path;
+ goto change_browser_directory;
} else if (f->scfunc == do_up_void) {
- if (selected >= width)
- selected -= width;
+ if (selected >= width)
+ selected -= width;
} else if (f->scfunc == do_left) {
- if (selected > 0)
- selected--;
+ if (selected > 0)
+ selected--;
} else if (f->scfunc == do_down_void) {
- if (selected + width <= filelist_len - 1)
- selected += width;
+ if (selected + width <= filelist_len - 1)
+ selected += width;
} else if (f->scfunc == do_right) {
- if (selected < filelist_len - 1)
- selected++;
+ if (selected < filelist_len - 1)
+ selected++;
} else if (f->scfunc == do_enter_void) {
- /* We can't move up from "/". */
- if (strcmp(filelist[selected], "/..") == 0) {
- statusbar(_("Can't move up a directory"));
- beep();
- continue;
- }
+ /* We can't move up from "/". */
+ if (strcmp(filelist[selected], "/..") == 0) {
+ statusbar(_("Can't move up a directory"));
+ beep();
+ continue;
+ }
#ifndef DISABLE_OPERATINGDIR
- /* Note: The selected file can be outside the operating
- * directory if it's ".." or if it's a symlink to a
- * directory outside the operating directory. */
- if (check_operating_dir(filelist[selected], FALSE)) {
- statusbar(
- _("Can't go outside of %s in restricted mode"),
- operating_dir);
- beep();
- continue;
- }
+ /* Note: The selected file can be outside the operating
+ * directory if it's ".." or if it's a symlink to a
+ * directory outside the operating directory. */
+ if (check_operating_dir(filelist[selected], FALSE)) {
+ statusbar(_("Can't go outside of %s in restricted mode"),
+ operating_dir);
+ beep();
+ continue;
+ }
#endif
- if (stat(filelist[selected], &st) == -1) {
- /* We can't open this file for some reason.
- * Complain. */
- statusbar(_("Error reading %s: %s"),
- filelist[selected], strerror(errno));
- beep();
- continue;
- }
-
- /* If we've successfully opened a file, we're done, so
- * get out. */
- if (!S_ISDIR(st.st_mode)) {
- retval = mallocstrcpy(NULL, filelist[selected]);
- abort = TRUE;
- continue;
+ if (stat(filelist[selected], &st) == -1) {
+ /* We can't open this file for some reason.
+ * Complain. */
+ statusbar(_("Error reading %s: %s"),
+ filelist[selected], strerror(errno));
+ beep();
+ continue;
+ }
+
+ /* If we've successfully opened a file, we're done, so
+ * get out. */
+ if (!S_ISDIR(st.st_mode)) {
+ retval = mallocstrcpy(NULL, filelist[selected]);
+ abort = TRUE;
+ continue;
/* If we've successfully opened a directory, and it's
* "..", save the current directory in prev_dir, so that
- * we can select it later. */
- } else if (strcmp(tail(filelist[selected]), "..") == 0)
- prev_dir = mallocstrcpy(NULL,
- striponedir(filelist[selected]));
-
- dir = opendir(filelist[selected]);
- if (dir == NULL) {
- /* We can't open this directory for some reason.
- * Complain. */
- statusbar(_("Error reading %s: %s"),
- filelist[selected], strerror(errno));
- beep();
- continue;
- }
-
- path = mallocstrcpy(path, filelist[selected]);
-
- /* Start over again with the new path value. */
- goto change_browser_directory;
- /* Abort the file browser. */
+ * we can easily return to it by hitting Enter. */
+ } else if (strcmp(tail(filelist[selected]), "..") == 0)
+ prev_dir = mallocstrcpy(NULL, striponedir(filelist[selected]));
+
+ dir = opendir(filelist[selected]);
+ if (dir == NULL) {
+ /* We can't open this directory for some reason.
+ * Complain. */
+ statusbar(_("Error reading %s: %s"),
+ filelist[selected], strerror(errno));
+ beep();
+ continue;
+ }
+
+ path = mallocstrcpy(path, filelist[selected]);
+
+ /* Start over again with the new path value. */
+ goto change_browser_directory;
} else if (f->scfunc == do_exit) {
- abort = TRUE;
+ /* Abort the file browser. */
+ abort = TRUE;
}
}
titlebar(NULL);
void do_insertfile_void(void)
{
if (ISSET(RESTRICTED)) {
- nano_disabled_msg();
+ nano_disabled_msg();
return;
}
/* Complain if the file exists, the name hasn't changed,
* and the stat information we had before does not match
* what we have now. */
- else if (name_exists && openfile->current_stat && (openfile->current_stat->st_mtime < st.st_mtime ||
- openfile->current_stat->st_dev != st.st_dev || openfile->current_stat->st_ino != st.st_ino)) {
+ else if (name_exists && openfile->current_stat &&
+ (openfile->current_stat->st_mtime < st.st_mtime ||
+ openfile->current_stat->st_dev != st.st_dev ||
+ openfile->current_stat->st_ino != st.st_ino)) {
i = do_yesno_prompt(FALSE,
_("File was modified since you opened it, continue saving ? "));
if (i == 0 || i == -1)
void history_error(const char *msg, ...)
{
- va_list ap;
+ va_list ap;
va_start(ap, msg);
vfprintf(stderr, _(msg), ap);
* history file. */
chmod(poshist, S_IRUSR | S_IWUSR);
- for (posptr = poshistory; posptr != NULL; posptr = posptr->next) {
+ for (posptr = poshistory; posptr != NULL; posptr = posptr->next) {
statusstr = charalloc(strlen(posptr->filename) + 2 * sizeof(ssize_t) + 4);
sprintf(statusstr, "%s %ld %ld\n", posptr->filename, (long)posptr->lineno,
(long)posptr->xno);
* and a column. If no entry is found, add a new one at the end. */
void update_poshistory(char *filename, ssize_t lineno, ssize_t xpos)
{
- poshiststruct *posptr, *posprev = NULL;
- char *fullpath = get_full_path(filename);
+ poshiststruct *posptr, *posprev = NULL;
+ char *fullpath = get_full_path(filename);
if (fullpath == NULL)
- return;
+ return;
for (posptr = poshistory; posptr != NULL; posptr = posptr->next) {
- if (!strcmp(posptr->filename, fullpath)) {
+ if (!strcmp(posptr->filename, fullpath)) {
posptr->lineno = lineno;
posptr->xno = xpos;
- return;
- }
+ return;
+ }
posprev = posptr;
}
ssize_t read, lineno, xno;
poshiststruct *posptr;
- /* See if we can find the file we're currently editing. */
+ /* Read and parse each line, and put the data into the
+ * positions history structure. */
while ((read = getline(&line, &buf_len, hist)) >= 0) {
if (read > 0 && line[read - 1] == '\n') {
read--;
line[read] = '\0';
}
- if (read > 0) {
+ if (read > 0)
unsunder(line, read);
- }
lineptr = parse_next_word(line);
xptr = parse_next_word(lineptr);
lineno = atoi(lineptr);
posptr->next->xno = xno;
posptr->next->next = NULL;
}
-
}
fclose(hist);
sc *s;
for (s = sclist; s != NULL; s = s->next)
- if (s->scfunc == oldfunc) {
+ if (s->scfunc == oldfunc)
s->scfunc = newfunc;
- }
}
/* Return the given menu's first shortcut sequence, or the default value
* for each flag. */
const char *flagtostr(int flag)
{
- switch (flag) {
+ switch (flag) {
case NO_HELP:
/* TRANSLATORS: The next seventeen strings are toggle descriptions;
* they are best kept shorter than 40 characters, but may be longer. */
s->scfunc = do_wordlinechar_count;
else if (!strcasecmp(input, "undo"))
s->scfunc = do_undo;
- else if (!strcasecmp(input, "redo"))
+ else if (!strcasecmp(input, "redo")) {
s->scfunc = do_redo;
+#endif
#ifndef DISABLE_HISTORIES
- else if (!strcasecmp(input, "prevhistory")) {
- s->scfunc = get_history_older_void;
+ } else if (!strcasecmp(input, "prevhistory")) {
+ s->scfunc = get_history_older_void;
s->execute = FALSE;
} else if (!strcasecmp(input, "nexthistory")) {
- s->scfunc = get_history_newer_void;
+ s->scfunc = get_history_newer_void;
s->execute = FALSE;
- }
#endif
- else if (!strcasecmp(input, "nohelp")) {
- s->scfunc = do_toggle_void;
+#ifndef NANO_TINY
+ } else if (!strcasecmp(input, "nohelp")) {
+ s->scfunc = do_toggle_void;
s->execute = FALSE;
s->toggle = NO_HELP;
} else if (!strcasecmp(input, "constupdate")) {
- s->scfunc = do_toggle_void;
+ s->scfunc = do_toggle_void;
s->execute = FALSE;
s->toggle = CONST_UPDATE;
} else if (!strcasecmp(input, "morespace")) {
- s->scfunc = do_toggle_void;
+ s->scfunc = do_toggle_void;
s->execute = FALSE;
s->toggle = MORE_SPACE;
} else if (!strcasecmp(input, "smoothscroll")) {
- s->scfunc = do_toggle_void;
+ s->scfunc = do_toggle_void;
s->execute = FALSE;
s->toggle = SMOOTH_SCROLL;
} else if (!strcasecmp(input, "softwrap")) {
- s->scfunc = do_toggle_void;
+ s->scfunc = do_toggle_void;
s->execute = FALSE;
s->toggle = SOFTWRAP;
} else if (!strcasecmp(input, "whitespacedisplay")) {
- s->scfunc = do_toggle_void;
+ s->scfunc = do_toggle_void;
s->execute = FALSE;
s->toggle = WHITESPACE_DISPLAY;
#ifndef DISABLE_COLOR
} else if (!strcasecmp(input, "nosyntax")) {
- s->scfunc = do_toggle_void;
+ s->scfunc = do_toggle_void;
s->execute = FALSE;
s->toggle = NO_COLOR_SYNTAX;
#endif
} else if (!strcasecmp(input, "smarthome")) {
- s->scfunc = do_toggle_void;
+ s->scfunc = do_toggle_void;
s->execute = FALSE;
s->toggle = SMART_HOME;
} else if (!strcasecmp(input, "autoindent")) {
- s->scfunc = do_toggle_void;
+ s->scfunc = do_toggle_void;
s->execute = FALSE;
s->toggle = AUTOINDENT;
} else if (!strcasecmp(input, "cuttoend")) {
- s->scfunc = do_toggle_void;
+ s->scfunc = do_toggle_void;
s->execute = FALSE;
s->toggle = CUT_TO_END;
#ifndef DISABLE_WRAPPING
} else if (!strcasecmp(input, "nowrap")) {
- s->scfunc = do_toggle_void;
+ s->scfunc = do_toggle_void;
s->execute = FALSE;
s->toggle = NO_WRAP;
#endif
} else if (!strcasecmp(input, "tabstospaces")) {
- s->scfunc = do_toggle_void;
+ s->scfunc = do_toggle_void;
s->execute = FALSE;
s->toggle = TABS_TO_SPACES;
} else if (!strcasecmp(input, "backupfile")) {
- s->scfunc = do_toggle_void;
+ s->scfunc = do_toggle_void;
s->execute = FALSE;
s->toggle = BACKUP_FILE;
#ifndef DISABLE_MULTIBUFFER
} else if (!strcasecmp(input, "multibuffer")) {
- s->scfunc = do_toggle_void;
+ s->scfunc = do_toggle_void;
s->execute = FALSE;
s->toggle = MULTIBUFFER;
#endif
#ifndef DISABLE_MOUSE
} else if (!strcasecmp(input, "mouse")) {
- s->scfunc = do_toggle_void;
+ s->scfunc = do_toggle_void;
s->execute = FALSE;
s->toggle = USE_MOUSE;
#endif
} else if (!strcasecmp(input, "noconvert")) {
- s->scfunc = do_toggle_void;
+ s->scfunc = do_toggle_void;
s->execute = FALSE;
s->toggle = NO_CONVERT;
} else if (!strcasecmp(input, "suspendenable")) {
- s->scfunc = do_toggle_void;
+ s->scfunc = do_toggle_void;
s->execute = FALSE;
s->toggle = SUSPEND;
}
s->scfunc = dos_format_void;
s->execute = FALSE;
} else if (!strcasecmp(input, "macformat")) {
- s->scfunc = mac_format_void;
+ s->scfunc = mac_format_void;
s->execute = FALSE;
} else if (!strcasecmp(input, "append")) {
- s->scfunc = append_void;
+ s->scfunc = append_void;
s->execute = FALSE;
} else if (!strcasecmp(input, "prepend")) {
- s->scfunc = prepend_void;
+ s->scfunc = prepend_void;
s->execute = FALSE;
} else if (!strcasecmp(input, "backup")) {
- s->scfunc = backup_file_void;
+ s->scfunc = backup_file_void;
s->execute = FALSE;
#ifndef ENABLE_TINY
} else if (!strcasecmp(input, "flipexecute")) {
#endif
#ifndef DISABLE_MULTIBUFFER
} else if (!strcasecmp(input, "newbuffer")) {
- s->scfunc = new_buffer_void;
+ s->scfunc = new_buffer_void;
s->execute = FALSE;
#endif
#ifndef DISABLE_BROWSER
} else if (!strcasecmp(input, "firstfile")) {
- s->scfunc = do_first_file;
+ s->scfunc = do_first_file;
s->execute = FALSE;
} else if (!strcasecmp(input, "lastfile")) {
s->scfunc = do_last_file;