version 1.7, 2010/07/03 16:29:46 |
version 1.8, 2011/09/16 18:12:09 |
|
|
/* |
/* |
* 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; |
|
|
|
#if EXAMINE || TAB_COMPLETE_FILENAME |
/* |
/* |
* Textlist functions deal with a list of words separated by spaces. |
* Textlist functions deal with a list of words separated by spaces. |
* init_textlist sets up a textlist structure. |
* init_textlist sets up a textlist structure. |
|
|
return (s); |
return (s); |
} |
} |
|
|
#ifndef SMALL_PROGRAM |
|
public char * |
public char * |
back_textlist(tlist, prev) |
back_textlist(tlist, prev) |
struct textlist *tlist; |
struct textlist *tlist; |
|
|
s--; |
s--; |
return (s); |
return (s); |
} |
} |
#endif /* SMALL_PROGRAM */ |
#endif /* EXAMINE || TAB_COMPLETE_FILENAME */ |
|
|
/* |
/* |
* Close the current input file. |
* Close the current input file. |
|
|
curr_altfilename = NULL; |
curr_altfilename = NULL; |
} |
} |
curr_ifile = NULL_IFILE; |
curr_ifile = NULL_IFILE; |
|
#if HAVE_STAT_INO |
|
curr_ino = curr_dev = 0; |
|
#endif |
} |
} |
|
|
/* |
/* |
|
|
{ |
{ |
chflags = ch_getflags(); |
chflags = ch_getflags(); |
close_file(); |
close_file(); |
|
#if !SMALL |
|
if ((chflags & CH_HELPFILE) && held_ifile(was_curr_ifile) <= 1) |
|
{ |
|
/* |
|
* Don't keep the help file in the ifile list. |
|
*/ |
|
del_ifile(was_curr_ifile); |
|
was_curr_ifile = old_ifile; |
|
} |
|
#endif /* !SMALL */ |
} |
} |
|
|
if (ifile == NULL_IFILE) |
if (ifile == NULL_IFILE) |
|
|
qopen_filename = shell_unquote(open_filename); |
qopen_filename = shell_unquote(open_filename); |
|
|
chflags = 0; |
chflags = 0; |
|
#if !SMALL |
|
if (strcmp(open_filename, HELPFILE) == 0) |
|
chflags |= CH_HELPFILE; |
|
#endif /* !SMALL */ |
if (alt_pipe != NULL) |
if (alt_pipe != NULL) |
{ |
{ |
/* |
/* |
|
|
/* |
/* |
* 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. |
|
|
new_file = TRUE; |
new_file = TRUE; |
ch_init(f, chflags); |
ch_init(f, chflags); |
|
|
|
if (!(chflags & CH_HELPFILE)) |
|
{ |
#if LOGFILE |
#if LOGFILE |
if (namelogfile != NULL && is_tty) |
if (namelogfile != NULL && is_tty) |
use_logfile(namelogfile); |
use_logfile(namelogfile); |
#endif |
#endif |
if (every_first_cmd != NULL) |
#if HAVE_STAT_INO |
ungetsc(every_first_cmd); |
/* 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; |
no_display = !any_display; |
flush(); |
flush(); |
any_display = TRUE; |
any_display = TRUE; |
|
|
return (0); |
return (0); |
} |
} |
|
|
#ifndef SMALL_PROGRAM |
#if EXAMINE |
/* |
/* |
* Edit a space-separated list of files. |
* Edit a space-separated list of files. |
* For each filename in the list, enter it into the ifile list. |
* For each filename in the list, enter it into the ifile list. |
|
|
reedit_ifile(save_ifile); |
reedit_ifile(save_ifile); |
return (edit(good_filename)); |
return (edit(good_filename)); |
} |
} |
#endif /* SMALL_PROGRAM */ |
#endif /* EXAMINE */ |
|
|
/* |
/* |
* Edit the first file in the command line (ifile) list. |
* Edit the first file in the command line (ifile) list. |
|
|
|
|
|
|
/* |
/* |
* 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 |
|
|
* If can't even open that, we're stuck. Just quit. |
* If can't even open that, we're stuck. Just quit. |
*/ |
*/ |
quit(QUIT_ERROR); |
quit(QUIT_ERROR); |
|
} |
|
|
|
public void |
|
reopen_curr_ifile() |
|
{ |
|
IFILE save_ifile = save_curr_ifile(); |
|
close_file(); |
|
reedit_ifile(save_ifile); |
} |
} |
|
|
/* |
/* |