Previous
|
Up
|
Next
|
More File Primitives |
Primitives and EEL Subroutines |
Low-level File Primitives |
Epsilon User's Manual and Reference >
Primitives and EEL Subroutines >
File Primitives >
File Properties
int check_file(char *file, ?struct file_info *f_info)
The
check_file( ) primitive gets miscellaneous information on a
file or subdirectory from the operating system. It returns codes
defined by macros in codes.h.
If its argument file denotes a pattern that may match multiple
files, it returns CHECK_PATTERN . (Use the file_match( )
primitive described in Listing Commands & Buffers & Files to retrieve the
matches. Note that CHECK_PATTERN checks only for the system-wide
wildcard characters * and ? , not for Epsilon's extended file
pattern characters. See the is_pattern( ) primitive described in More File Primitives to check for those.)
If file names a directory or a file, it returns
CHECK_DIR or CHECK_FILE , respectively. If file
names a device, it returns CHECK_DEVICE . If file has the
form of a URL, not a regular file, it returns CHECK_URL .
Under operating systems that support it, check_file( ) returns
CHECK_PIPE for a named pipe and CHECK_OTHER for an
unrecognized special file. Otherwise, it returns 0 .
If f_info has a non-null value, check_file( ) fills the
structure it points to with information on the file or directory,
except when it returns 0 or CHECK_URL. The structure has
the following format (defined in eel.h):
struct file_info { /* used by check_file() */
int fsize; /* file size in bytes */
int opsysattr; /* system dependent attribute */
int raw_file_date; /* opsys-dependent date */
short year;
short month; /* 1-12 */
short day; /* 1-31 */
short hour; /* 0-23 */
short minute; /* 0-59 */
short second; /* 0-59 */
byte attr; /* epsilon standardized attribute */
byte check_type; /* file/directory/device code */
};
#define ATTR_READONLY 1
#define ATTR_DIRECTORY 2
The check_type member contains the same value as
check_file( )'s return code. The attr member contains two
flags: ATTR_READONLY if the file cannot be written, or
ATTR_DIRECTORY if the operating system says the file is
actually a directory. The opsysattr member contains a raw
attribute code from the operating system: the meaning of bits here
depends on the operating system, and Epsilon doesn't interpret them.
(See the set_file_opsys_attribute( ) primitive to set raw
attribute codes for a file.)
Epsilon also provides the timestamp of a file, in two formats. The
interpreted format (year, month, etc.) uses local time, and is
intended to match the file timestamp shown in a directory listing. By
contrast, in most cases the raw timestamp won't be affected by a
change in time zones, the arrival of daylight saving time, or similar
things, as the interpreted format will be, so it's more convenient
when comparing timestamps. Under some operating systems Epsilon
doesn't provide a raw timestamp; this field will be zero in that case.
For the second parameter to check_file( ), make sure you provide
a pointer to a struct file_info , not the actual structure
itself. You can omit this parameter entirely if you only want the
function's return value.
unique_filename_identifier(char *fname, int id[3])
unique_file_ids_match(int a[3], int b[3])
The unique_filename_identifier( ) primitive takes a file name
and fills the id array with a set of values that uniquely describe
it. Two file names with the same array of values refer to the same
file. (This can happen under Unix due to symbolic or hard links.) If
the primitive sets id[0] to zero, no unique identifier was found;
comparisons between two file names, one or both of which return
id[0]==0 , must assume that the names might or might not refer to
the same file. At this writing only Epsilon for Unix supports this
feature; in other versions, unique_filename_identifier( ) will
always set id[0] to zero.
The unique_file_ids_match( ) subroutine compares two id
arrays from unique_filename_identifier( ), returning nonzero if
they indicate the two file names supplied to
unique_filename_identifier( ) refer to the same file, and zero if
they do not, or Epsilon cannot determine this.
int compare_dates(struct file_info *a,
struct file_info *b)
format_date(char *msg, int year, int month,
int day, int hour, int minute,
int second)
format_file_date(char *s, struct file_info *p)
The compare_dates( ) subroutine defined in filedate.e can be
used to compare the dates in two file_info structures. It returns
0 if they have the same date and time, nonzero if they differ.
The format_date( ) subroutine takes a date and converts it
to text form, using the format specified by the date-format
variable. The format_file_date( ) subroutine takes a
file_info structure and converts it to text form by calling
format_date( ).
int check_dates(int save) /* filedate.e */
The check_dates( ) subroutine defined in filedate.e compares
a file's time and date on disk with the date saved when the file was
last read or written. If the file on disk has a later date, it warns
the user and asks what to do. Its parameter should be nonzero if
Epsilon was about to save the file, otherwise zero. The function
returns nonzero if the user said not to save the file.
The following example command uses check_file( ) to display the
current file name and its date in the echo area.
#include "eel.h"
command show_file_date()
{
struct file_info ts;
if (check_file(filename, &ts))
say("%s: %d/%d/%d", filename,
ts.month, ts.day, ts.year);
}
Previous
|
Up
|
Next
|
More File Primitives |
Primitives and EEL Subroutines |
Low-level File Primitives |
Epsilon Programmer's Editor 14.04 manual. Copyright (C) 1984, 2021 by Lugaru Software Ltd. All rights reserved.
|