file help.c; changes to help_init(), help_line_len(), and
do_help() (all moved to help.c). (DLR)
- Tweak a few functions to remove the assumption that the file
- always ends in a magicline. Changes to do_cut_till_end() and
- do_wordlinechar_count(). (DLR)
+ always ends in a magicline. Changes to do_cut_till_end(),
+ write_file(), and do_wordlinechar_count(). (DLR)
- Tweak a few functions to rely on fileage and filebot instead
of NULL for their checks to detect the top or bottom of the
file. Changes to cut_line(), cut_to_eol(), do_page_up(),
do_page_down(), do_para_end(), do_next_word(), do_prev_word(),
do_up(), do_down(), do_scroll_down(), do_right(), do_mouse(),
do_gotolinecolumn(), do_delete(), and find_paragraph(). (DLR)
+- files.c:
+ read_file()
+ - Remove apparently unneeded logic to handle a case where
+ current is NULL, since it shouldn't be NULL there. (DLR)
- nano.h:
- Readd MIN_EDITOR_COLS #define. (DLR)
- rcfile.c:
open_buffer("");
/* Did we try to insert a file of zero bytes? */
- if (num_lines != 0) {
- if (openfile->current != NULL) {
- fileptr->next = openfile->current;
- openfile->current->prev = fileptr;
- renumber(openfile->current);
- openfile->current_x = 0;
- openfile->placewewant = 0;
- } else if (fileptr->next == NULL) {
- openfile->filebot = fileptr;
- new_magicline();
- openfile->totsize--;
- }
+ if (num_lines > 0) {
+ fileptr->next = openfile->current;
+ openfile->current->prev = fileptr;
+ renumber(openfile->current);
+ openfile->current_x = 0;
+ openfile->placewewant = 0;
}
openfile->totsize += get_totsize(openfile->fileage,
* a selection. */
assert(openfile->fileage != NULL && openfile->filebot != NULL);
- while (fileptr != openfile->filebot) {
- size_t data_len = strlen(fileptr->data), size;
+ while (fileptr != NULL) {
+ size_t data_len, size;
+
+ /* If we're on the last line of the file and it's blank, skip
+ * over it, since the newline character we wrote after the
+ * next-to-last line of the file is equivalent to it. */
+ if (fileptr == openfile->filebot &&
+ openfile->filebot->data[0] == '\0')
+ continue;
+
+ data_len = strlen(fileptr->data);
/* Newlines to nulls, just before we write to disk. */
sunder(fileptr->data);
goto cleanup_and_exit;
}
+ /* If we're on the last line of the file and it isn't blank,
+ * don't write a newline character after it. */
+ if (fileptr != openfile->filebot ||
+ openfile->filebot->data[0] == '\0') {
#ifndef NANO_SMALL
- if (openfile->fmt == DOS_FILE || openfile->fmt == MAC_FILE) {
- if (putc('\r', f) == EOF) {
- statusbar(_("Error writing %s: %s"), realname,
+ if (openfile->fmt == DOS_FILE || openfile->fmt ==
+ MAC_FILE) {
+ if (putc('\r', f) == EOF) {
+ statusbar(_("Error writing %s: %s"), realname,
strerror(errno));
- fclose(f);
- goto cleanup_and_exit;
+ fclose(f);
+ goto cleanup_and_exit;
+ }
}
- }
- if (openfile->fmt != MAC_FILE) {
+ if (openfile->fmt != MAC_FILE) {
#endif
- if (putc('\n', f) == EOF) {
- statusbar(_("Error writing %s: %s"), realname,
+ if (putc('\n', f) == EOF) {
+ statusbar(_("Error writing %s: %s"), realname,
strerror(errno));
- fclose(f);
- goto cleanup_and_exit;
- }
+ fclose(f);
+ goto cleanup_and_exit;
+ }
#ifndef NANO_SMALL
- }
+ }
#endif
+ }
fileptr = fileptr->next;
lineswritten++;