version 1.25, 2019/09/03 23:08:42 |
version 1.26, 2024/04/14 18:11:54 |
|
|
dev_t curr_dev; |
dev_t curr_dev; |
ino_t curr_ino; |
ino_t curr_ino; |
|
|
char *curr_altfilename = NULL; |
|
static void *curr_altpipe; |
|
|
|
|
|
/* |
/* |
* 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. |
|
|
* Close the file descriptor, unless it is a pipe. |
* Close the file descriptor, unless it is a pipe. |
*/ |
*/ |
ch_close(); |
ch_close(); |
/* |
|
* If we opened a file using an alternate name, |
|
* do special stuff to close it. |
|
*/ |
|
if (curr_altfilename != NULL) { |
|
close_altfile(curr_altfilename, get_filename(curr_ifile), |
|
curr_altpipe); |
|
free(curr_altfilename); |
|
curr_altfilename = NULL; |
|
} |
|
curr_ifile = NULL; |
curr_ifile = NULL; |
curr_ino = curr_dev = 0; |
curr_ino = curr_dev = 0; |
} |
} |
|
|
int no_display; |
int no_display; |
int chflags; |
int chflags; |
char *filename; |
char *filename; |
char *open_filename; |
|
char *qopen_filename; |
char *qopen_filename; |
char *alt_filename; |
|
void *alt_pipe; |
|
IFILE was_curr_ifile; |
IFILE was_curr_ifile; |
PARG parg; |
PARG parg; |
|
|
|
|
} |
} |
|
|
/* |
/* |
* We must close the currently open file now. |
* We close the currently open file now. This was done before |
* This is necessary to make the open_altfile/close_altfile pairs |
* to avoid linked popen/pclose pairs from LESSOPEN, but there |
* nest properly (or rather to avoid nesting at all). |
* may other code that has come to rely on this restriction. |
* {{ Some stupid implementations of popen() mess up if you do: |
|
* fA = popen("A"); fB = popen("B"); pclose(fA); pclose(fB); }} |
|
*/ |
*/ |
end_logfile(); |
end_logfile(); |
was_curr_ifile = save_curr_ifile(); |
was_curr_ifile = save_curr_ifile(); |
|
|
} |
} |
|
|
filename = estrdup(get_filename(ifile)); |
filename = estrdup(get_filename(ifile)); |
/* |
qopen_filename = shell_unquote(filename); |
* See if LESSOPEN specifies an "alternate" file to open. |
|
*/ |
|
alt_pipe = NULL; |
|
alt_filename = open_altfile(filename, &f, &alt_pipe); |
|
open_filename = (alt_filename != NULL) ? alt_filename : filename; |
|
qopen_filename = shell_unquote(open_filename); |
|
|
|
chflags = 0; |
chflags = 0; |
if (strcmp(open_filename, helpfile()) == 0) |
if (strcmp(filename, helpfile()) == 0) |
chflags |= CH_HELPFILE; |
chflags |= CH_HELPFILE; |
if (alt_pipe != NULL) { |
if (strcmp(filename, "-") == 0) { |
/* |
/* |
* The alternate "file" is actually a pipe. |
|
* f has already been set to the file descriptor of the pipe |
|
* in the call to open_altfile above. |
|
* Keep the file descriptor open because it was opened |
|
* via popen(), and pclose() wants to close it. |
|
*/ |
|
chflags |= CH_POPENED; |
|
} else if (strcmp(open_filename, "-") == 0) { |
|
/* |
|
* Use standard input. |
* Use standard input. |
* Keep the file descriptor open because we can't reopen it. |
* Keep the file descriptor open because we can't reopen it. |
*/ |
*/ |
f = fd0; |
f = fd0; |
chflags |= CH_KEEPOPEN; |
chflags |= CH_KEEPOPEN; |
} else if (strcmp(open_filename, FAKE_EMPTYFILE) == 0) { |
} else if (strcmp(filename, FAKE_EMPTYFILE) == 0) { |
f = -1; |
f = -1; |
chflags |= CH_NODATA; |
chflags |= CH_NODATA; |
} else if ((parg.p_string = bad_file(open_filename)) != NULL) { |
} else if ((parg.p_string = bad_file(filename)) != NULL) { |
/* |
/* |
* It looks like a bad file. Don't try to open it. |
* It looks like a bad file. Don't try to open it. |
*/ |
*/ |
error("%s", &parg); |
error("%s", &parg); |
free(parg.p_string); |
free(parg.p_string); |
err1: |
err1: |
if (alt_filename != NULL) { |
|
close_altfile(alt_filename, filename, alt_pipe); |
|
free(alt_filename); |
|
} |
|
del_ifile(ifile); |
del_ifile(ifile); |
free(qopen_filename); |
free(qopen_filename); |
free(filename); |
free(filename); |
|
|
unsave_ifile(was_curr_ifile); |
unsave_ifile(was_curr_ifile); |
} |
} |
curr_ifile = ifile; |
curr_ifile = ifile; |
curr_altfilename = alt_filename; |
|
curr_altpipe = alt_pipe; |
|
set_open(curr_ifile); /* File has been opened */ |
set_open(curr_ifile); /* File has been opened */ |
get_pos(curr_ifile, &initial_scrpos); |
get_pos(curr_ifile, &initial_scrpos); |
new_file = TRUE; |
new_file = TRUE; |