You need to sign in or sign up before continuing.
Commit 02517e0a authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

add DB's overhaul of the file loading code to increase efficiency,

remove ugly workarounds for most cases of edittop's or current's being
NULL (as those cases no longer occur due to the overhaul), and remove
detection of binary files (since it wasn't always accurate and will only
cause problems when UTF-8 support is added); also add a few minor fixes
of mine


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1928 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent 8bf08097
Showing with 431 additions and 431 deletions
+431 -431
...@@ -15,6 +15,29 @@ CVS code - ...@@ -15,6 +15,29 @@ CVS code -
- Remove reference to @includedir@ in src/Makefile.am, as it's - Remove reference to @includedir@ in src/Makefile.am, as it's
unneeded and can break cross-compilation. (DLR, found by Mike unneeded and can break cross-compilation. (DLR, found by Mike
Frysinger) Frysinger)
- Overhaul the file opening, reading, and loading operations to
increase efficiency, avoid problems on invalid filenames
specified on the command line, and eliminate corner cases that
erroneously leave edittop or current NULL when they shouldn't
be. Also split out the code to execute a command into a
separate function, eliminate a workaround for one of the
aforementioned corner cases, handle files with a mix of DOS
and Mac format lines, and remove the code to turn on the
NO_CONVERT flag when opening a binary file, as it's not always
reliable and will cause problems with UTF-8 text files. New
functions open_file(), execute_command(), and mallocstrassn();
changes to read_line(), load_file(), read_file(), open_file(),
get_next_filename(), do_insertfile(), do_insertfile_void(),
do_alt_speller(), and edit_refresh(). (David Benbennick) DLR:
Add a few minor fixes to make sure that current is set
properly in all cases, indicate on the statusbar when the file
has a mix of DOS and Mac format lines, move the test for DOS
line endings from read_line() to read_file() to avoid
inaccurate statusbar messages and to reduce fileformat to a
local variable in read_file(), eliminate another workaround in
edit_update(), rename open_the_file() to open_file() since the
latter has been removed, and rename load_a_file() to
load_buffer().
- files.c: - files.c:
do_insertfile() do_insertfile()
- Readd the NANO_SMALL #ifdef around the start_again: label to - Readd the NANO_SMALL #ifdef around the start_again: label to
...@@ -23,14 +46,23 @@ CVS code - ...@@ -23,14 +46,23 @@ CVS code -
shortcut_init() shortcut_init()
- Remove redundant NANO_SMALL #ifdef. (DLR) - Remove redundant NANO_SMALL #ifdef. (DLR)
- nano.c: - nano.c:
die_save_file()
- Clarify the error message when there are too many backup files
and the current one can't be written. (DLR)
do_para_begin(), do_para_end() do_para_begin(), do_para_end()
- Maintain current_y's value when moving up or down lines so - Maintain current_y's value when moving up or down lines so
that smooth scrolling works correctly. (DLR) that smooth scrolling works correctly. (DLR)
- nano.h:
- Add WIDTH_OF_TAB #define, containing the default width of a
tab. (DLR)
- rcfile.c: - rcfile.c:
parse_rcfile() parse_rcfile()
- Add missing brackets around an if statement block so that - Add missing brackets around an if statement block so that
parsing the numeric argument after "tabsize" works properly parsing the numeric argument after "tabsize" works properly
again. (DLR, found by Mike Frysinger) again. (DLR, found by Mike Frysinger)
- Since flag values are longs, use "%ld" instead of "%d" in the
debugging messages indicating when a flag is set or unset.
(DLR)
- search.c: - search.c:
findnextstr() findnextstr()
- Take the no_sameline parameter after can_display_wrap and - Take the no_sameline parameter after can_display_wrap and
...@@ -56,6 +88,10 @@ CVS code - ...@@ -56,6 +88,10 @@ CVS code -
- If there are more than MAIN_VISIBLE shortcuts available, only - If there are more than MAIN_VISIBLE shortcuts available, only
register clicks on the first MAIN_VISIBLE shortcuts, since register clicks on the first MAIN_VISIBLE shortcuts, since
bottombars() only shows that many shortcuts. (DLR) bottombars() only shows that many shortcuts. (DLR)
reset_cursor()
- If this is called before any files have been opened, as it can
be by statusbar(), put the cursor at the top left corner of
the edit window before getting out. (DLR)
edit_refresh() edit_refresh()
- Call edit_update() with NONE instead of CENTER when smooth - Call edit_update() with NONE instead of CENTER when smooth
scrolling is on, for consistency with the movement routines. scrolling is on, for consistency with the movement routines.
......
This diff is collapsed.
...@@ -367,7 +367,8 @@ void shortcut_init(int unjustify) ...@@ -367,7 +367,8 @@ void shortcut_init(int unjustify)
); );
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
if (open_files != NULL && (open_files->prev != NULL || open_files->next != NULL)) if (open_files != NULL && (open_files->prev != NULL ||
open_files->next != NULL))
/* Translators: try to keep this string under 10 characters long */ /* Translators: try to keep this string under 10 characters long */
sc_init_one(&main_list, NANO_EXIT_KEY, N_("Close"), sc_init_one(&main_list, NANO_EXIT_KEY, N_("Close"),
IFHELP(nano_exit_msg, NANO_NO_KEY), NANO_EXIT_FKEY, IFHELP(nano_exit_msg, NANO_NO_KEY), NANO_EXIT_FKEY,
......
...@@ -179,7 +179,7 @@ void die_save_file(const char *die_filename) ...@@ -179,7 +179,7 @@ void die_save_file(const char *die_filename)
if (!failed) if (!failed)
fprintf(stderr, _("\nBuffer written to %s\n"), ret); fprintf(stderr, _("\nBuffer written to %s\n"), ret);
else else
fprintf(stderr, _("\nNo %s written (too many backup files?)\n"), ret); fprintf(stderr, _("\nBuffer not written to %s (too many backup files?)\n"), ret);
free(ret); free(ret);
} }
...@@ -856,7 +856,7 @@ bool open_pipe(const char *command) ...@@ -856,7 +856,7 @@ bool open_pipe(const char *command)
if (f == NULL) if (f == NULL)
nperror("fdopen"); nperror("fdopen");
read_file(f, "stdin", FALSE); read_file(f, "stdin");
/* If multibuffer mode is on, we could be here in view mode. If so, /* If multibuffer mode is on, we could be here in view mode. If so,
* don't set the modification flag. */ * don't set the modification flag. */
if (!ISSET(VIEW_MODE)) if (!ISSET(VIEW_MODE))
...@@ -1406,7 +1406,7 @@ bool do_int_spell_fix(const char *word) ...@@ -1406,7 +1406,7 @@ bool do_int_spell_fix(const char *word)
bool reverse_search_set = ISSET(REVERSE_SEARCH); bool reverse_search_set = ISSET(REVERSE_SEARCH);
#ifndef NANO_SMALL #ifndef NANO_SMALL
bool case_sens_set = ISSET(CASE_SENSITIVE); bool case_sens_set = ISSET(CASE_SENSITIVE);
bool mark_set = ISSET(MARK_ISSET); bool old_mark_set = ISSET(MARK_ISSET);
SET(CASE_SENSITIVE); SET(CASE_SENSITIVE);
/* Make sure the marking highlight is off during spell-check. */ /* Make sure the marking highlight is off during spell-check. */
...@@ -1475,7 +1475,7 @@ bool do_int_spell_fix(const char *word) ...@@ -1475,7 +1475,7 @@ bool do_int_spell_fix(const char *word)
UNSET(CASE_SENSITIVE); UNSET(CASE_SENSITIVE);
/* Restore marking highlight. */ /* Restore marking highlight. */
if (mark_set) if (old_mark_set)
SET(MARK_ISSET); SET(MARK_ISSET);
#endif #endif
...@@ -1678,16 +1678,17 @@ const char *do_alt_speller(char *tempfile_name) ...@@ -1678,16 +1678,17 @@ const char *do_alt_speller(char *tempfile_name)
pid_t pid_spell; pid_t pid_spell;
char *ptr; char *ptr;
static int arglen = 3; static int arglen = 3;
static char **spellargs = (char **)NULL; static char **spellargs = NULL;
FILE *f;
#ifndef NANO_SMALL #ifndef NANO_SMALL
bool mark_set = ISSET(MARK_ISSET); bool old_mark_set = ISSET(MARK_ISSET);
int mbb_lineno_cur = 0; int mbb_lineno_cur = 0;
/* We're going to close the current file, and open the output of /* We're going to close the current file, and open the output of
* the alternate spell command. The line that mark_beginbuf * the alternate spell command. The line that mark_beginbuf
* points to will be freed, so we save the line number and * points to will be freed, so we save the line number and
* restore afterwards. */ * restore afterwards. */
if (mark_set) { if (old_mark_set) {
mbb_lineno_cur = mark_beginbuf->lineno; mbb_lineno_cur = mark_beginbuf->lineno;
UNSET(MARK_ISSET); UNSET(MARK_ISSET);
} }
...@@ -1738,7 +1739,7 @@ const char *do_alt_speller(char *tempfile_name) ...@@ -1738,7 +1739,7 @@ const char *do_alt_speller(char *tempfile_name)
refresh(); refresh();
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (mark_set) { if (old_mark_set) {
do_gotopos(mbb_lineno_cur, mark_beginx, y_cur, 0); do_gotopos(mbb_lineno_cur, mark_beginx, y_cur, 0);
mark_beginbuf = current; mark_beginbuf = current;
/* In case the line got shorter, assign mark_beginx. */ /* In case the line got shorter, assign mark_beginx. */
...@@ -1750,7 +1751,13 @@ const char *do_alt_speller(char *tempfile_name) ...@@ -1750,7 +1751,13 @@ const char *do_alt_speller(char *tempfile_name)
free_filestruct(fileage); free_filestruct(fileage);
terminal_init(); terminal_init();
global_init(TRUE); global_init(TRUE);
open_file(tempfile_name, FALSE, TRUE);
/* Do what load_buffer() would do, except for making a new
* buffer for the temp file if multibuffer support is
* available. */
open_file(tempfile_name, FALSE, &f);
read_file(f, tempfile_name);
current = fileage;
#ifndef NANO_SMALL #ifndef NANO_SMALL
} }
#endif #endif
...@@ -2564,6 +2571,7 @@ void do_justify(bool full_justify) ...@@ -2564,6 +2571,7 @@ void do_justify(bool full_justify)
edit_refresh(); edit_refresh();
statusbar(_("Can now UnJustify!")); statusbar(_("Can now UnJustify!"));
/* Display the shortcut list with UnJustify. */ /* Display the shortcut list with UnJustify. */
shortcut_init(TRUE); shortcut_init(TRUE);
display_main_list(); display_main_list();
...@@ -2618,6 +2626,7 @@ void do_justify(bool full_justify) ...@@ -2618,6 +2626,7 @@ void do_justify(bool full_justify)
cutbuffer = cutbuffer_save; cutbuffer = cutbuffer_save;
/* Note that now cutbottom is invalid, but that's okay. */ /* Note that now cutbottom is invalid, but that's okay. */
blank_statusbar(); blank_statusbar();
/* Display the shortcut list with UnCut. */ /* Display the shortcut list with UnCut. */
shortcut_init(FALSE); shortcut_init(FALSE);
display_main_list(); display_main_list();
...@@ -2940,11 +2949,19 @@ void terminal_init(void) ...@@ -2940,11 +2949,19 @@ void terminal_init(void)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int optchr; int optchr;
int startline = 0; /* Line to try and start at */ int startline = 0;
/* Line to try and start at. */
#ifndef DISABLE_WRAPJUSTIFY #ifndef DISABLE_WRAPJUSTIFY
bool fill_flag_used = FALSE; /* Was the fill option used? */ bool fill_flag_used = FALSE;
/* Was the fill option used? */
#endif #endif
int kbinput; /* Input from keyboard */ #ifdef ENABLE_MULTIBUFFER
bool old_multibuffer;
/* The old value of the multibuffer option, restored after we
* load all files on the command line. */
#endif
int kbinput;
/* Input from keyboard. */
bool meta_key; bool meta_key;
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
const struct option long_options[] = { const struct option long_options[] = {
...@@ -3015,8 +3032,8 @@ int main(int argc, char **argv) ...@@ -3015,8 +3032,8 @@ int main(int argc, char **argv)
#endif #endif
#if !defined(ENABLE_NANORC) && defined(DISABLE_ROOTWRAP) && !defined(DISABLE_WRAPPING) #if !defined(ENABLE_NANORC) && defined(DISABLE_ROOTWRAP) && !defined(DISABLE_WRAPPING)
/* if we don't have rcfile support, we're root, and /* If we don't have rcfile support, we're root, and
--disable-wrapping-as-root is used, turn wrapping off */ * --disable-wrapping-as-root is used, turn wrapping off. */
if (geteuid() == NANO_ROOT_UID) if (geteuid() == NANO_ROOT_UID)
SET(NO_WRAP); SET(NO_WRAP);
#endif #endif
...@@ -3190,8 +3207,8 @@ int main(int argc, char **argv) ...@@ -3190,8 +3207,8 @@ int main(int argc, char **argv)
} }
/* We've read through the command line options. Now back up the flags /* We've read through the command line options. Now back up the flags
and values that are set, and read the rcfile(s). If the values * and values that are set, and read the rcfile(s). If the values
haven't changed afterward, restore the backed-up values. */ * haven't changed afterward, restore the backed-up values. */
#ifdef ENABLE_NANORC #ifdef ENABLE_NANORC
if (!ISSET(NO_RCFILE)) { if (!ISSET(NO_RCFILE)) {
#ifndef DISABLE_OPERATINGDIR #ifndef DISABLE_OPERATINGDIR
...@@ -3336,37 +3353,20 @@ int main(int argc, char **argv) ...@@ -3336,37 +3353,20 @@ int main(int argc, char **argv)
#endif #endif
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC) #if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
/* If whitespace wasn't specified, set its default value. */
if (whitespace == NULL) if (whitespace == NULL)
whitespace = mallocstrcpy(NULL, " "); whitespace = mallocstrcpy(NULL, " ");
#endif #endif
/* If tabsize wasn't specified, set its default value. */
if (tabsize == -1) if (tabsize == -1)
tabsize = 8; tabsize = WIDTH_OF_TAB;
/* Clear the filename we'll be using */
filename = charalloc(1);
filename[0] = '\0';
/* If there's a +LINE flag, it is the first non-option argument. */ /* If there's a +LINE flag, it is the first non-option argument. */
if (0 < optind && optind < argc && argv[optind][0] == '+') { if (0 < optind && optind < argc && argv[optind][0] == '+') {
startline = atoi(&argv[optind][1]); startline = atoi(&argv[optind][1]);
optind++; optind++;
} }
if (0 < optind && optind < argc)
filename = mallocstrcpy(filename, argv[optind]);
/* See if there's a non-option in argv (first non-option is the
filename, if +LINE is not given) */
if (argc > 1 && argc > optind) {
/* Look for the +line flag... */
if (argv[optind][0] == '+') {
startline = atoi(&argv[optind][1]);
optind++;
if (argc > optind)
filename = mallocstrcpy(filename, argv[optind]);
} else
filename = mallocstrcpy(filename, argv[optind]);
}
/* Back up the old terminal settings so that they can be restored. */ /* Back up the old terminal settings so that they can be restored. */
tcgetattr(0, &oldterm); tcgetattr(0, &oldterm);
...@@ -3392,44 +3392,55 @@ int main(int argc, char **argv) ...@@ -3392,44 +3392,55 @@ int main(int argc, char **argv)
mouse_init(); mouse_init();
#endif #endif
#ifdef DEBUG
fprintf(stderr, "Main: top and bottom win\n");
#endif
titlebar(NULL);
display_main_list();
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "Main: open file\n"); fprintf(stderr, "Main: open file\n");
#endif #endif
open_file(filename, FALSE, FALSE);
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
/* If we're using multibuffers and more than one file is specified old_multibuffer = ISSET(MULTIBUFFER);
on the command line, load them all and switch to the first one
afterward. */
if (optind + 1 < argc) {
bool old_multibuffer = ISSET(MULTIBUFFER), list = FALSE;
SET(MULTIBUFFER); SET(MULTIBUFFER);
for (optind++; optind < argc; optind++) {
add_open_file(TRUE); /* Read all the files after the first one on the command line into
new_file(); * new buffers. */
filename = mallocstrcpy(filename, argv[optind]); {
titlebar(NULL); int i;
open_file(filename, FALSE, FALSE); for (i = optind + 1; i < argc; i++)
load_file(FALSE); load_buffer(argv[i]);
/* Display the main list with "Close" if we haven't
* already. */
if (!list) {
shortcut_init(FALSE);
list = TRUE;
display_main_list();
} }
#endif
/* Read the first file on the command line into either the current
* buffer or a new buffer, depending on whether multibuffer mode is
* enabled. */
if (optind < argc)
load_buffer(argv[optind]);
/* We didn't open any files if all the command line arguments were
* invalid files like directories or if there were no command line
* arguments given. In this case, we have to load a blank buffer.
* Also, we unset view mode to allow editing. */
if (filename == NULL) {
filename = mallocstrcpy(NULL, "");
new_file();
UNSET(VIEW_MODE);
/* Add this new entry to the open_files structure if we have
* multibuffer support, or to the main filestruct if we don't. */
load_file();
} }
open_nextfile_void();
#ifdef ENABLE_MULTIBUFFER
if (!old_multibuffer) if (!old_multibuffer)
UNSET(MULTIBUFFER); UNSET(MULTIBUFFER);
}
#endif #endif
#ifdef DEBUG
fprintf(stderr, "Main: top and bottom win\n");
#endif
titlebar(NULL);
display_main_list();
if (startline > 0) if (startline > 0)
do_gotoline(startline, FALSE); do_gotoline(startline, FALSE);
......
...@@ -491,6 +491,9 @@ typedef enum { ...@@ -491,6 +491,9 @@ typedef enum {
* occurs. */ * occurs. */
#define CHARS_FROM_EOL 8 #define CHARS_FROM_EOL 8
/* Default width of a tab. */
#define WIDTH_OF_TAB 8
/* Maximum number of search history strings saved, same value used for /* Maximum number of search history strings saved, same value used for
* replace history. */ * replace history. */
#define MAX_SEARCH_HISTORY 100 #define MAX_SEARCH_HISTORY 100
......
...@@ -164,14 +164,18 @@ void do_cut_text(void); ...@@ -164,14 +164,18 @@ void do_cut_text(void);
void do_uncut_text(void); void do_uncut_text(void);
/* Public functions in files.c */ /* Public functions in files.c */
void load_file(int update);
void new_file(void); void new_file(void);
filestruct *read_line(char *buf, filestruct *prev, int *line1ins, size_t filestruct *read_line(char *buf, filestruct *prev, bool *first_line_ins,
len); size_t len);
void read_file(FILE *f, const char *filename, int quiet); void load_file(void);
bool open_file(const char *filename, int insert, int quiet); void read_file(FILE *f, const char *filename);
int open_file(const char *filename, bool newfie, FILE **f);
char *get_next_filename(const char *name); char *get_next_filename(const char *name);
void do_insertfile(int loading_file); #ifndef NANO_SMALL
void execute_command(const char *command);
#endif
void load_buffer(const char *name);
void do_insertfile(void);
void do_insertfile_void(void); void do_insertfile_void(void);
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
openfilestruct *make_new_opennode(openfilestruct *prevnode); openfilestruct *make_new_opennode(openfilestruct *prevnode);
...@@ -411,7 +415,7 @@ int do_replace_loop(const char *needle, const filestruct *real_current, ...@@ -411,7 +415,7 @@ int do_replace_loop(const char *needle, const filestruct *real_current,
void do_replace(void); void do_replace(void);
void do_gotoline(int line, bool save_pos); void do_gotoline(int line, bool save_pos);
void do_gotoline_void(void); void do_gotoline_void(void);
#if defined (ENABLE_MULTIBUFFER) || !defined (DISABLE_SPELLER) #if defined(ENABLE_MULTIBUFFER) || !defined(DISABLE_SPELLER)
void do_gotopos(int line, int pos_x, int pos_y, size_t pos_pww); void do_gotopos(int line, int pos_x, int pos_y, size_t pos_pww);
#endif #endif
void do_find_bracket(void); void do_find_bracket(void);
...@@ -479,6 +483,7 @@ void nperror(const char *s); ...@@ -479,6 +483,7 @@ void nperror(const char *s);
void *nmalloc(size_t howmuch); void *nmalloc(size_t howmuch);
void *nrealloc(void *ptr, size_t howmuch); void *nrealloc(void *ptr, size_t howmuch);
char *mallocstrcpy(char *dest, const char *src); char *mallocstrcpy(char *dest, const char *src);
char *mallocstrassn(char *dest, char *src);
void new_magicline(void); void new_magicline(void);
#ifndef NANO_SMALL #ifndef NANO_SMALL
void mark_order(const filestruct **top, size_t *top_x, const filestruct void mark_order(const filestruct **top, size_t *top_x, const filestruct
......
...@@ -619,13 +619,13 @@ void parse_rcfile(FILE *rcstream) ...@@ -619,13 +619,13 @@ void parse_rcfile(FILE *rcstream)
} else } else
SET(rcopts[i].flag); SET(rcopts[i].flag);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "set flag %d!\n", fprintf(stderr, "set flag %ld!\n",
rcopts[i].flag); rcopts[i].flag);
#endif #endif
} else { } else {
UNSET(rcopts[i].flag); UNSET(rcopts[i].flag);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "unset flag %d!\n", fprintf(stderr, "unset flag %ld!\n",
rcopts[i].flag); rcopts[i].flag);
#endif #endif
} }
......
...@@ -616,7 +616,7 @@ int do_replace_loop(const char *needle, const filestruct *real_current, ...@@ -616,7 +616,7 @@ int do_replace_loop(const char *needle, const filestruct *real_current,
bool begin_line = FALSE, bol_or_eol = FALSE; bool begin_line = FALSE, bol_or_eol = FALSE;
#endif #endif
#ifndef NANO_SMALL #ifndef NANO_SMALL
bool old_mark_isset = ISSET(MARK_ISSET); bool old_mark_set = ISSET(MARK_ISSET);
UNSET(MARK_ISSET); UNSET(MARK_ISSET);
edit_refresh(); edit_refresh();
...@@ -758,7 +758,7 @@ int do_replace_loop(const char *needle, const filestruct *real_current, ...@@ -758,7 +758,7 @@ int do_replace_loop(const char *needle, const filestruct *real_current,
new_magicline(); new_magicline();
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (old_mark_isset) if (old_mark_set)
SET(MARK_ISSET); SET(MARK_ISSET);
#endif #endif
......
...@@ -396,7 +396,7 @@ void *nrealloc(void *ptr, size_t howmuch) ...@@ -396,7 +396,7 @@ void *nrealloc(void *ptr, size_t howmuch)
} }
/* Copy one malloc()ed string to another pointer. Should be used as: /* Copy one malloc()ed string to another pointer. Should be used as:
* dest = mallocstrcpy(dest, src); */ * "dest = mallocstrcpy(dest, src);". */
char *mallocstrcpy(char *dest, const char *src) char *mallocstrcpy(char *dest, const char *src)
{ {
if (src == NULL) if (src == NULL)
...@@ -411,7 +411,16 @@ char *mallocstrcpy(char *dest, const char *src) ...@@ -411,7 +411,16 @@ char *mallocstrcpy(char *dest, const char *src)
return dest; return dest;
} }
/* Append a new magic-line to filebot. */ /* Free the malloc()ed string at dest and return the malloc()ed string
* at src. Should be used as: "answer = mallocstrassn(answer,
* real_dir_from_tilde(answer));". */
char *mallocstrassn(char *dest, char *src)
{
free(dest);
return src;
}
/* Append a new magicline to filebot. */
void new_magicline(void) void new_magicline(void)
{ {
filebot->next = (filestruct *)nmalloc(sizeof(filestruct)); filebot->next = (filestruct *)nmalloc(sizeof(filestruct));
......
...@@ -2385,13 +2385,15 @@ size_t get_page_start(size_t column) ...@@ -2385,13 +2385,15 @@ size_t get_page_start(size_t column)
} }
/* Resets current_y, based on the position of current, and puts the /* Resets current_y, based on the position of current, and puts the
* cursor at (current_y, current_x). */ * cursor in the edit window at (current_y, current_x). */
void reset_cursor(void) void reset_cursor(void)
{ {
/* Yuck. This condition can be true after open_file() when opening /* If we haven't opened any files yet, put the cursor in the top
* the first file. */ * left corner of the edit window and get out. */
if (edittop == NULL) if (edittop == NULL || current == NULL) {
wmove(edit, 0, 0);
return; return;
}
current_y = current->lineno - edittop->lineno; current_y = current->lineno - edittop->lineno;
if (current_y < editwinrows) { if (current_y < editwinrows) {
...@@ -2884,14 +2886,6 @@ void edit_redraw(const filestruct *old_current, size_t old_pww) ...@@ -2884,14 +2886,6 @@ void edit_redraw(const filestruct *old_current, size_t old_pww)
/* Refresh the screen without changing the position of lines. */ /* Refresh the screen without changing the position of lines. */
void edit_refresh(void) void edit_refresh(void)
{ {
/* 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 (current == NULL)
return;
if (edittop == NULL)
edittop = current;
if (current->lineno < edittop->lineno || if (current->lineno < edittop->lineno ||
current->lineno >= edittop->lineno + editwinrows) current->lineno >= edittop->lineno + editwinrows)
/* Note that edit_update() changes edittop so that it's in range /* Note that edit_update() changes edittop so that it's in range
...@@ -2932,10 +2926,6 @@ void edit_update(topmidnone location) ...@@ -2932,10 +2926,6 @@ void edit_update(topmidnone location)
{ {
filestruct *foo = current; filestruct *foo = current;
/* We shouldn't need this check. Yuck. */
if (current == NULL)
return;
if (location != TOP) { if (location != TOP) {
/* If location is CENTER, we move edittop up (editwinrows / 2) /* If location is CENTER, we move edittop up (editwinrows / 2)
* lines. This puts current at the center of the screen. If * lines. This puts current at the center of the screen. If
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment