CWB
|
#include <sys/stat.h>
#include <fcntl.h>
#include <glib.h>
#include "globals.h"
#include "fileutils.h"
Macros | |
#define | STREAM_IS_PIPE(type) (type == CL_STREAM_PIPE || type == CL_STREAM_GZIP || type == CL_STREAM_BZIP2) |
check whether stream type involves a pipe More... | |
Functions | |
off_t | file_length (char *filename) |
Gets the size of the specified file; returns EOF for error. More... | |
off_t | fd_file_length (FILE *fd) |
Gets the size of the specified file; returns EOF for error. More... | |
off_t | fi_file_length (int fileno) |
Gets the size of the specified file; returns EOF for error. More... | |
long | fprobe (char *fname) |
Gets the size of the specified file; returns EOF for error. More... | |
int | is_directory (char *path) |
Checks whether the specified path indicates a directory. More... | |
int | is_file (char *path) |
Checks whether the specified path indicates a regular file. More... | |
int | is_link (char *path) |
Checks whether the specified path indicates a link. More... | |
static void | cl_handle_sigpipe (int signum) |
FILE * | cl_open_stream (const char *filename, int mode, int type) |
Open stream of specified (or guessed) type for reading or writing. More... | |
int | cl_close_stream (FILE *handle) |
Close I/O stream. More... | |
Variables | |
CLStream | open_streams |
Implementation of automagic I/O streams. More... | |
int | cl_broken_pipe = 0 |
SIGPIPE handler and global status variable. More... | |
#define STREAM_IS_PIPE | ( | type | ) | (type == CL_STREAM_PIPE || type == CL_STREAM_GZIP || type == CL_STREAM_BZIP2) |
check whether stream type involves a pipe
Referenced by cl_close_stream(), and cl_open_stream().
int cl_close_stream | ( | FILE * | handle | ) |
Close I/O stream.
This function can only be used for FILE* objects opened with cl_open_stream()!
stream | An I/O stream that has been opened with cl_open_stream() |
References CDA_EATTTYPE, CDA_EPOSIX, CDA_OK, cl_broken_pipe, cl_errno, cl_free, CL_STREAM_BZIP2, CL_STREAM_FILE, CL_STREAM_GZIP, CL_STREAM_PIPE, CL_STREAM_STDIO, _CLStream::handle, _CLStream::next, open_streams, STREAM_IS_PIPE, and _CLStream::type.
Referenced by alignshow_goodbye(), close_input_stream(), close_stream(), encode_get_input_line(), lexdecode_show(), main(), open_input_stream(), open_stream(), and SetVariableValue().
|
static |
References cl_broken_pipe.
Referenced by cl_open_stream().
FILE* cl_open_stream | ( | const char * | filename, |
int | mode, | ||
int | type | ||
) |
Open stream of specified (or guessed) type for reading or writing.
I/O streams opened with this function must always be closed with cl_close_stream()!
filename | Filename or shell command |
mode | Open for reading (CL_STREAM_READ) or writing (CL_STREAM_WRITE) |
type | Type of stream (see above), or guess automagically from <filename> (CL_STREAM_MAGIC) |
References CDA_EACCESS, CDA_EARGS, CDA_EBUFFER, CDA_EPOSIX, CDA_OK, cl_broken_pipe, cl_errno, cl_handle_sigpipe(), cl_malloc(), CL_MAX_FILENAME_LENGTH, CL_STREAM_APPEND, CL_STREAM_BZIP2, CL_STREAM_FILE, CL_STREAM_GZIP, CL_STREAM_MAGIC, CL_STREAM_MAGIC_NOPIPE, CL_STREAM_PIPE, CL_STREAM_READ, CL_STREAM_STDIO, CL_STREAM_WRITE, _CLStream::handle, _CLStream::mode, mode, _CLStream::next, open_streams, STREAM_IS_PIPE, and _CLStream::type.
Referenced by encode_get_input_line(), lexdecode_show(), main(), open_input_stream(), open_pager(), open_stream(), sencode_parse_options(), and SetVariableValue().
off_t fd_file_length | ( | FILE * | fd | ) |
Gets the size of the specified file; returns EOF for error.
As file_length, but the file is specified by file handle, not name.
fd | The file to size up. |
off_t fi_file_length | ( | int | fileno | ) |
Gets the size of the specified file; returns EOF for error.
As file_length, but the file is specified by number, not name.
fileno | The file to size up. |
off_t file_length | ( | char * | filename | ) |
Gets the size of the specified file; returns EOF for error.
filename | The file to size up. |
Referenced by attach_subcorpus(), and comp_component_state().
long fprobe | ( | char * | fname | ) |
Gets the size of the specified file; returns EOF for error.
Duplicates functionality of file_length, but return is long instead of off_t.
fname | The file to size up. |
int is_directory | ( | char * | path | ) |
Checks whether the specified path indicates a directory.
path | Path to check. |
Referenced by makeall_do_attribute().
int is_file | ( | char * | path | ) |
Checks whether the specified path indicates a regular file.
path | Path to check. |
int is_link | ( | char * | path | ) |
Checks whether the specified path indicates a link.
Note this function always returns false in Windows, because Windows doesn't have Unix-style links. (.lnk files don't count.)
path | Path to check. |
int cl_broken_pipe = 0 |
SIGPIPE handler and global status variable.
This variable will be set to True if a SIGPIPE has been caught and ignored.
Referenced by ascii_print_group(), ascii_print_output(), cl_close_stream(), cl_handle_sigpipe(), cl_open_stream(), do_dump(), html_print_group(), html_print_output(), latex_print_group(), latex_print_output(), print_tabulation(), sgml_print_group(), sgml_print_output(), and SortSubcorpus().
CLStream open_streams |
Implementation of automagic I/O streams.
In order to make streams completely transparent to the caller and return them as standard FILE* objects, the CL keeps a list of all open streams with the necessary metadata information.
Referenced by cl_close_stream(), and cl_open_stream().