diff -u -r nano/files.c nano-caeuid/files.c --- nano/files.c Tue Apr 23 06:23:50 2002 +++ nano-caeuid/files.c Wed Apr 24 02:10:20 2002 @@ -50,15 +50,15 @@ #endif /* Load file into edit buffer - takes data from file struct */ -void load_file(int quiet) +void load_file(int update) { current = fileage; #ifdef ENABLE_MULTIBUFFER - /* if quiet is zero, add a new entry to the open_files structure; + /* if update is zero, add a new entry to the open_files structure; otherwise, update the current entry (the latter is needed in the case of the alternate spell checker) */ - add_open_file(quiet); + add_open_file(update); #endif wmove(edit, current_y, current_x); @@ -69,7 +69,7 @@ { fileage = nmalloc(sizeof(filestruct)); fileage->data = charalloc(1); - strcpy(fileage->data, ""); + fileage->data[0] = 0; fileage->prev = NULL; fileage->next = NULL; fileage->lineno = 1; @@ -84,7 +84,7 @@ /* if there aren't any entries in open_files, create the entry for 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, leading to problems later on */ + given no open_files entry */ if (!open_files) { add_open_file(0); /* turn off view mode in this case; this is for consistency @@ -100,7 +100,7 @@ } -filestruct *read_line(char *buf, filestruct * prev, int *line1ins) +filestruct *read_line(char *buf, filestruct *prev, int *line1ins) { filestruct *fileptr; @@ -148,10 +148,10 @@ return fileptr; } -int read_file(FILE *f, char *filename, int quiet) +int read_file(FILE *f, const char *filename, int quiet) { int num_lines = 0; - char input; /* current input character */ + signed char input; /* current input character */ char *buf; long i = 0, bufx = 128; filestruct *fileptr = current, *tmp = NULL; @@ -252,7 +252,9 @@ new_magicline(); totsize--; - /* Update the edit buffer */ + /* Update the edit buffer; note that if using multibuffers, a + quiet load will update the current open_files entry, while a + noisy load will add a new open_files entry */ load_file(quiet); } @@ -273,9 +275,8 @@ return 1; } - /* Open the file (and decide if it exists) */ -int open_file(char *filename, int insert, int quiet) +int open_file(const char *filename, int insert, int quiet) { int fd; FILE *f; @@ -305,7 +306,6 @@ /* Don't open character or block files. Sorry, /dev/sndstat! */ statusbar(_("File \"%s\" is a device file"), filename); - if (!insert) new_file(); return -1; @@ -323,7 +323,6 @@ return 1; } - /* This function will return the name of the first available extension of a filename (starting with the filename, then filename.1, etc). Memory is allocated for the return value. If no writable extension @@ -794,6 +793,9 @@ if (!open_files) return 1; + /* make sure open_files->fileage and fileage are in sync; they might + not be if lines have been cut from the top of the file (which + changes the location fileage points to) */ open_files->fileage = fileage; tmp = open_files; @@ -1207,8 +1209,9 @@ #ifndef DISABLE_OPERATINGDIR if (!tmp && operating_dir) { - /* if we're writing a temporary file, we're going outside the - operating directory, so skip the operating directory test */ + /* if we're writing a temporary file, we're probably going + outside the operating directory, so skip the operating + directory test */ if (check_operating_dir(realname, 0)) { statusbar(_("Can't write outside of %s"), operating_dir); @@ -2607,7 +2610,7 @@ } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY); curs_set(1); blank_edit(); - titlebar(NULL); + titlebar(NULL); edit_refresh(); kb = keypad_on(edit, kb); diff -u -r nano/nano.c nano-caeuid/nano.c --- nano/nano.c Tue Apr 23 07:50:40 2002 +++ nano-caeuid/nano.c Wed Apr 24 02:10:20 2002 @@ -1658,8 +1658,7 @@ #ifdef ENABLE_MULTIBUFFER /* update the current open_files entry before spell-checking, in case - any problems occur; the case of there being no open_files entries - is handled elsewhere (before we reach this point) */ + any problems occur */ add_open_file(1); #endif diff -u -r nano/nano.spec.in nano-caeuid/nano.spec.in --- nano/nano.spec.in Sat Mar 30 13:02:54 2002 +++ nano-caeuid/nano.spec.in Wed Apr 24 02:10:20 2002 @@ -9,7 +9,7 @@ Copyright : GPL Group : Console/Editors URL : http://www.nano-editor.org -Source : http://www.nano-editor.org/dist/v1.1/%{name}/%{name}-%{ver}.tar.gz +Source : http://www.nano-editor.org/dist/v1.1/%{name}-%{ver}.tar.gz BuildRoot : /var/tmp/%{name}-buildroot Requires : ncurses diff -u -r nano/proto.h nano-caeuid/proto.h --- nano/proto.h Tue Apr 23 07:50:40 2002 +++ nano-caeuid/proto.h Wed Apr 24 02:10:20 2002 @@ -127,11 +127,11 @@ int do_uncut_text(void); int no_help(void); int renumber_all(void); -int open_file(char *filename, int insert, int quiet); +int open_file(const char *filename, int insert, int quiet); int do_insertfile(int loading_file); int num_of_digits(int n); int open_pipe(char *command); -int read_file(FILE *f, char *filename, int quiet); +int read_file(FILE *f, const char *filename, int quiet); #ifdef ENABLE_MULTIBUFFER int add_open_file(int update); diff -u -r nano/rcfile.c nano-caeuid/rcfile.c --- nano/rcfile.c Fri Mar 29 14:41:57 2002 +++ nano-caeuid/rcfile.c Wed Apr 24 02:10:17 2002 @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include #include @@ -447,9 +449,7 @@ char *unable = _("Unable to open ~/.nanorc file, %s"); struct stat fileinfo; FILE *rcstream; - - if (getenv("HOME") == NULL) - return; + struct passwd *userage; nanorc = charalloc(strlen(SYSCONFDIR) + 10); sprintf(nanorc, "%s/nanorc", SYSCONFDIR); @@ -463,10 +463,21 @@ fclose(rcstream); } - nanorc = charalloc(strlen(getenv("HOME")) + 10); - sprintf(nanorc, "%s/.nanorc", getenv("HOME")); - lineno = 0; + + /* Determine home directory using getpwent(), don't rely on $HOME */ + for (userage = getpwent(); userage != NULL + && userage->pw_uid != geteuid(); userage = getpwent()) + ; + + if (userage == NULL) { + rcfile_error(_("I can't find my home directory! Wah!")); + return; + } + + nanorc = charalloc(strlen(userage->pw_dir) + 10); + sprintf(nanorc, "%s/.nanorc", userage->pw_dir); + if (stat(nanorc, &fileinfo) == -1) { /* Abort if the file doesn't exist and there's some other kind diff -u -r nano/winio.c nano-caeuid/winio.c --- nano/winio.c Tue Apr 23 07:50:41 2002 +++ nano-caeuid/winio.c Wed Apr 24 02:10:17 2002 @@ -111,9 +111,7 @@ for (i = start; tot <= xplus && fileptr->data[i] != 0; i++, tot++) if (fileptr->data[i] == NANO_CONTROL_I) { - if (tot % tabsize == 0) - tot++; - else + if (tot % tabsize != 0) tot += tabsize - (tot % tabsize); } else if (fileptr->data[i] & 0x80) tot++; /* Make 8 bit chars only 1 column (again) */