Lugaru's Epsilon
Programmer's
Editor

Context:
Epsilon User's Manual and Reference
   Primitives and EEL Subroutines
      . . .
      Display Primitives
         Creating & Destroying Windows
         Window Resizing Primitives
         Preserving Window Arrangements
         . . .
         Colors
      File Primitives
         . . .
         Line Translation Primitives
         Character Encoding Conversions
         More File Primitives
         File Properties
         Low-level File Primitives
         . . .
      Operating System Primitives
         System Primitives
         Window System Primitives
         Timing
         Calling Windows DLLs
         Running a Process
      . . .

Previous   Up    Next
Character Encoding Conversions  Primitives and EEL Subroutines   File Properties


Epsilon User's Manual and Reference > Primitives and EEL Subroutines > File Primitives >

More File Primitives

user buffer short modified;
int get_buf_modified(int buf)
set_buf_modified(int buf, int val)
int unsaved_buffers()
zeroed buffer char save_without_prompt;
int is_unsaved_buffer()
int buffer_unchanged()
char *get_file_read_kibitz()

Epsilon maintains a variable that tells whether the buffer was modified since it was last saved to a file. The buffer-specific variable modified is set to 1 each time the current buffer is modified. It is set to 0 by the file_read( ), file_write( ), new_file_read( ), and new_file_write( ) primitives, if they complete without error.

The get_buf_modified( ) and set_buf_modified( ) subroutines let you get or set the value of this variable for some other buffer buf.

The unsaved_buffers( ) subroutine defined in files.e returns 1 if there are any modified buffers. It doesn't count empty buffers, or those with no associated file names. If an EEL program creates a buffer that has an associated file name and is marked modified, but still doesn't require saving, it can set the buffer-specific variable discardable_buffer nonzero to indicate that the current buffer doesn't require any such warning. An EEL program can set the buffer-specific save_without_prompt variable nonzero for a buffer to have it silently saved without prompting, whenever Epsilon checks for unsaved buffers.

The unsaved_buffers( ) subroutine calls the is_unsaved_buffer( ) subroutine to check on an individual buffer. It tells if the current buffer shouldn't be deleted, and checks for the discardable_buffer variable as well as the buffer-not-saveable variable and other special kinds of buffers.

The buffer_unchanged( ) primitive returns a nonzero value if the current buffer has been modified since the last call of the refresh( ) or maybe_refresh( ) primitives. It returns zero if the buffer has not changed since that time. Epsilon calls maybe_refresh( ) to display the screen after each command.

The get_file_read_kibitz( ) primitive returns an explanatory message from the last time the current buffer was read, indicating why Epsilon chose a particular line translation. See the file-read-kibitz variable.

user buffer char *filename;
set_buffer_filename(char *file)
get_buffer_filename(char *fname)

The file reading and writing functions are normally used with the file name associated with each buffer, which is stored in the buffer-specific filename variable. To set this variable, use the syntax filename = new value;. Don't use strcpy( ), for example, to modify it.

The set_buffer_filename( ) subroutine defined in files.e sets the file name associated with the current buffer. However, unlike simply setting the primitive variable filename to the desired value, this function also modifies the current buffer's name to match the new file name, takes care of making sure the file name is in absolute form, and updates the buffer's access "timestamp". The bufed command uses this timestamp to display buffers sorted by access time.

Some buffers such as dired buffers have an associated file name, but since they aren't copies of files, they don't store it in the filename variable. Call the get_buffer_filename( ) subroutine to copy the current buffer's associated file name to fname, whether it's stored in filename or not.

user int errno;
file_error(int code, char *file, char *unknown)
char no_popup_errors;

File primitives that fail often place an error code in the errno variable. The file_error( ) primitive takes an error code and a file name and displays to the user a textual version of the error message. It also takes a message to print if the error code is unknown.

Under MS-Windows, the file_error( ) primitive pops up a message box to report the error. If EEL code sets the no_popup_errors variable nonzero, Epsilon will display such messages in the echo area instead, as it does under other operating systems.

int do_insert_file(char *file, int transl) /* files.e */
int write_part(char *file, int transl, int start, int end)

The do_insert_file( ) subroutine inserts a file into the current buffer, like the insert-file command. The write_part( ) subroutine writes only part of the current buffer to a file. Each displays an error message if the file could not be read or written, and returns either an error code or 0.

locate_window(char *buf, char *file)  /* buffer.e */
int buf_in_window(int bnum)
int is_buf_in_window(int bnum)
is_buffer_in_window(char *buf)
int count_windows_with_buf(int buf, int flags)

The locate_window( ) subroutine defined in window.e tries to display a given file or buffer by changing windows. If either of the arguments is an empty string "" it will be ignored. If a buffer with the specified name or a buffer displaying the specified file is shown in a window, the subroutine switches to that window. Otherwise, it makes the current window show the indicated buffer, if any.

The buf_in_window( ) primitive finds a window that displays a given buffer, and returns its window handle. It returns -1 if no window displays that buffer.

The is_buf_in_window( ) subroutine is similar, but excludes system windows. The is_buffer_in_window( ) subroutine takes a buffer name instead of a buffer number. They both return the handle of a non-system window displaying that buffer, or -1 if none.

The count_windows_with_buf( ) primitive returns the number of windows displaying the buffer. The flag bit 1 makes it skip system windows.

int delete_file(char *file)

The delete_file( ) primitive deletes a file. It returns 0 if the deletion succeeded, and -1 if it failed. The errno variable has a code describing the error in the latter case.

int rename_file(char *oldfile, char *newfile)

The rename_file( ) primitive changes a file's name. It returns zero if the file was successfully renamed, and nonzero otherwise. The errno variable has a code describing the error in the latter case. You can use this primitive to rename a file to a different directory, but you cannot use it to move a file to a different disk.

int copyfile(char *oldfile, char *newfile)

The copyfile( ) primitive makes a copy of the file named oldfile, giving it the name newfile, without reading the entire file into memory at once. The copy has the same time and date as the original. The primitive returns zero if it succeeds. If it fails to copy the file, it returns a nonzero value and sets errno to indicate the error.

int make_backup(char *file, char *backupname)

The make_backup( ) primitive does whatever is necessary to make a backup of a file. It takes the name of the original file and the name of the desired backup file, and returns 0 if the backup was made. Otherwise, it puts an error code in errno and returns a nonzero number. The primitive may simply rename the file, if this can be accomplished without losing any special attributes or permissions the original file has. If necessary, Epsilon copies the original file to its backup file.

int get_file_read_only(char *fname)
int set_file_read_only(char *fname, int val)
int set_file_opsys_attribute(char *fname, int attribute)

The get_file_read_only( ) primitive returns 1 if the file fname has been set read-only, 0 if it's writable, or -1 if the file's read-only status can't be determined (perhaps because the file doesn't exist). The set_file_read_only( ) primitive sets the file fname read-only (if val is nonzero) or writable (if val is zero). It returns 0 if an error occurred, otherwise nonzero.

Under Unix, set_file_read_only( ) sets the file writable for the current user, group and others, as modified by the current umask setting (as if you'd just created the file). Other permission bits aren't modified.

The set_file_opsys_attribute( ) primitive sets the raw attribute of a file. The precise meaning of the attribute depends on the operating system: under Unix this sets the file's permission bits, while in other environments it can set such attributes as Hidden or System. The primitive returns nonzero if it succeeds. See the opsysattr member of the structure set by check_file( ) to retrieve the raw attribute of a file.

int is_directory(char *str)
int is_pattern(char *str)

The is_directory( ) primitive takes a string, and asks the operating system if a directory by that name exists. If so, is_directory( ) returns 1; otherwise, it returns 0. Also see the check_file( ) primitive in File Properties, and the remote_file_type( ) subroutine in Manipulating File Names.

The is_pattern( ) primitive takes a string, and tells whether it forms a file pattern with wildcards that may match several files. It returns 2 if its file name argument contains the characters * or ?. These characters are always wildcard characters and never part of a legal file name. The function returns 1 if its file name argument contains any of the following characters: left square-bracket, left curly-bracket, comma, or semicolon. These characters can sometimes be part of a valid file name (depending upon the operating system and file system in use), but are also used as file pattern characters in Epsilon. It returns 3 if the file name contains both types of characters, and it returns 0 if the file name contains none of these characters.

user char file_pattern_wildcards;
#define FPAT_COMMA              (1)
#define FPAT_SEMICOLON          (2)
#define FPAT_SQUARE_BRACKET     (4)
#define FPAT_CURLY_BRACE        (8)
#define FPAT_ALL      (FPAT_COMMA | FPAT_SEMICOLON \
            | FPAT_SQUARE_BRACKET | FPAT_CURLY_BRACE)

You can control which of the characters []{},; Epsilon will consider a wildcard character in file patterns by setting the file-pattern-wildcards variable. This affects the do_dired( ), is_pattern( ), file_match( ), dired_standardize( ), check_file( ), and is_directory( ) primitives. Each bit in the variable enables a different set of characters.

FPAT_COMMA enables the , character, FPAT_SEMICOLON enables the ; character, FPAT_SQUARE_BRACKET enables recognizing [] sequences, and FPAT_CURLY_BRACE lets Epsilon recognize {} sequences. The default value enables all these characters.



Previous   Up    Next
Character Encoding Conversions  Primitives and EEL Subroutines   File Properties


Lugaru Copyright (C) 1984, 2012 Lugaru Software Ltd. All Rights Reserved.