version 1.1.1.2, 2003/04/13 18:21:21 |
version 1.1.1.3, 2011/09/16 17:47:04 |
|
|
/* |
/* |
* Copyright (C) 1984-2002 Mark Nudelman |
* Copyright (C) 1984-2011 Mark Nudelman |
* |
* |
* You may distribute under the terms of either the GNU General Public |
* You may distribute under the terms of either the GNU General Public |
* License or the Less License, as specified in the README file. |
* License or the Less License, as specified in the README file. |
|
|
|
|
|
|
#include "less.h" |
#include "less.h" |
|
#if HAVE_STAT |
|
#include <sys/stat.h> |
|
#endif |
|
|
public int fd0 = 0; |
public int fd0 = 0; |
|
|
|
|
extern char *namelogfile; |
extern char *namelogfile; |
#endif |
#endif |
|
|
|
#if HAVE_STAT_INO |
|
public dev_t curr_dev; |
|
public ino_t curr_ino; |
|
#endif |
|
|
char *curr_altfilename = NULL; |
char *curr_altfilename = NULL; |
static void *curr_altpipe; |
static void *curr_altpipe; |
|
|
|
|
curr_altfilename = NULL; |
curr_altfilename = NULL; |
} |
} |
curr_ifile = NULL_IFILE; |
curr_ifile = NULL_IFILE; |
|
#if HAVE_STAT_INO |
|
curr_ino = curr_dev = 0; |
|
#endif |
} |
} |
|
|
/* |
/* |
|
|
/* |
/* |
* Re-open the current file. |
* 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); |
reedit_ifile(was_curr_ifile); |
return (1); |
return (1); |
} else if ((f = open(qopen_filename, OPEN_READ)) < 0) |
} else if ((f = open(qopen_filename, OPEN_READ)) < 0) |
|
|
} |
} |
} |
} |
} |
} |
free(qopen_filename); |
|
|
|
/* |
/* |
* Get the new ifile. |
* Get the new ifile. |
|
|
if (namelogfile != NULL && is_tty) |
if (namelogfile != NULL && is_tty) |
use_logfile(namelogfile); |
use_logfile(namelogfile); |
#endif |
#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) |
if (every_first_cmd != NULL) |
ungetsc(every_first_cmd); |
ungetsc(every_first_cmd); |
} |
} |
|
|
|
free(qopen_filename); |
no_display = !any_display; |
no_display = !any_display; |
flush(); |
flush(); |
any_display = TRUE; |
any_display = TRUE; |
|
|
|
|
|
|
/* |
/* |
* Edit the next or previous file in the command line (ifile) list. |
* Edit the n-th next or previous file in the command line (ifile) list. |
*/ |
*/ |
static int |
static int |
edit_istep(h, n, dir) |
edit_istep(h, n, dir) |
|
|
IFILE h; |
IFILE h; |
int n; |
int n; |
{ |
{ |
return (edit_istep(h, n, 1)); |
return (edit_istep(h, n, +1)); |
} |
} |
|
|
public int |
public int |
edit_next(n) |
edit_next(n) |
int n; |
int n; |
{ |
{ |
return edit_istep(curr_ifile, n, 1); |
return edit_istep(curr_ifile, n, +1); |
} |
} |
|
|
static int |
static int |
|
|
quit(QUIT_ERROR); |
quit(QUIT_ERROR); |
} |
} |
|
|
|
public void |
|
reopen_curr_ifile() |
|
{ |
|
IFILE save_ifile = save_curr_ifile(); |
|
close_file(); |
|
reedit_ifile(save_ifile); |
|
} |
|
|
/* |
/* |
* Edit standard input. |
* Edit standard input. |
*/ |
*/ |
|
|
* Append: open the file and seek to the end. |
* Append: open the file and seek to the end. |
*/ |
*/ |
logfile = open(filename, OPEN_APPEND); |
logfile = open(filename, OPEN_APPEND); |
if (lseek(logfile, (off_t)0, 2) == BAD_LSEEK) |
if (lseek(logfile, (off_t)0, SEEK_END) == BAD_LSEEK) |
{ |
{ |
close(logfile); |
close(logfile); |
logfile = -1; |
logfile = -1; |