=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/less/edit.c,v retrieving revision 1.1.1.2 retrieving revision 1.1.1.3 diff -c -r1.1.1.2 -r1.1.1.3 *** src/usr.bin/less/edit.c 2003/04/13 18:21:21 1.1.1.2 --- src/usr.bin/less/edit.c 2011/09/16 17:47:04 1.1.1.3 *************** *** 1,5 **** /* ! * Copyright (C) 1984-2002 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. --- 1,5 ---- /* ! * Copyright (C) 1984-2011 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. *************** *** 10,15 **** --- 10,18 ---- #include "less.h" + #if HAVE_STAT + #include + #endif public int fd0 = 0; *************** *** 36,41 **** --- 39,49 ---- extern char *namelogfile; #endif + #if HAVE_STAT_INO + public dev_t curr_dev; + public ino_t curr_ino; + #endif + char *curr_altfilename = NULL; static void *curr_altpipe; *************** *** 178,183 **** --- 186,194 ---- curr_altfilename = NULL; } curr_ifile = NULL_IFILE; + #if HAVE_STAT_INO + curr_ino = curr_dev = 0; + #endif } /* *************** *** 322,327 **** --- 333,346 ---- /* * Re-open the current file. */ + if (was_curr_ifile == ifile) + { + /* + * Whoops. The "current" ifile is the one we just deleted. + * Just give up. + */ + quit(QUIT_ERROR); + } reedit_ifile(was_curr_ifile); return (1); } else if ((f = open(qopen_filename, OPEN_READ)) < 0) *************** *** 352,358 **** } } } - free(qopen_filename); /* * Get the new ifile. --- 371,376 ---- *************** *** 377,386 **** --- 395,417 ---- if (namelogfile != NULL && is_tty) use_logfile(namelogfile); #endif + #if HAVE_STAT_INO + /* Remember the i-number and device of the opened file. */ + { + struct stat statbuf; + int r = stat(qopen_filename, &statbuf); + if (r == 0) + { + curr_ino = statbuf.st_ino; + curr_dev = statbuf.st_dev; + } + } + #endif if (every_first_cmd != NULL) ungetsc(every_first_cmd); } + free(qopen_filename); no_display = !any_display; flush(); any_display = TRUE; *************** *** 498,504 **** /* ! * Edit the next or previous file in the command line (ifile) list. */ static int edit_istep(h, n, dir) --- 529,535 ---- /* ! * Edit the n-th next or previous file in the command line (ifile) list. */ static int edit_istep(h, n, dir) *************** *** 547,560 **** IFILE h; int n; { ! return (edit_istep(h, n, 1)); } public int edit_next(n) int n; { ! return edit_istep(curr_ifile, n, 1); } static int --- 578,591 ---- IFILE h; int n; { ! return (edit_istep(h, n, +1)); } public int edit_next(n) int n; { ! return edit_istep(curr_ifile, n, +1); } static int *************** *** 649,654 **** --- 680,693 ---- quit(QUIT_ERROR); } + public void + reopen_curr_ifile() + { + IFILE save_ifile = save_curr_ifile(); + close_file(); + reedit_ifile(save_ifile); + } + /* * Edit standard input. */ *************** *** 739,745 **** * Append: open the file and seek to the end. */ logfile = open(filename, OPEN_APPEND); ! if (lseek(logfile, (off_t)0, 2) == BAD_LSEEK) { close(logfile); logfile = -1; --- 778,784 ---- * Append: open the file and seek to the end. */ logfile = open(filename, OPEN_APPEND); ! if (lseek(logfile, (off_t)0, SEEK_END) == BAD_LSEEK) { close(logfile); logfile = -1;