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
         File Reading Primitives
         File Writing Primitives
         Line Translation Primitives
         Character Encoding Conversions
         . . .
      Operating System Primitives
         System Primitives
         Window System Primitives
         Timing
         Calling Windows DLLs
         Running a Process
      . . .

Previous   Up    Next
File Reading Primitives  Primitives and EEL Subroutines   Line Translation Primitives


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

File Writing Primitives

int file_write(char *file, int transl)

The file_write( ) primitive attempts to write the current buffer to the named file. It returns 0 if the write was successful, or an error code if an error occurred. The transl parameter specifies the line translation to be done while writing the file. See the description of translation-type below.

int new_file_write(char *name, int transl,
                   struct file_info *f_info,
                   int start, int max,
                   ?int lowstart, int highstart)

#define FILE_IO_ATSTART         -1
#define FILE_IO_NEWFILE         -2
#define FILE_IO_TEMPFILE        -3
char *get_tempfile_name()

The new_file_write( ) primitive writes a file, like file_write( ), but provides more options. The f_info parameter is a pointer to a structure, which Epsilon fills in with information on the file's write date, file type, and so forth, just after it finishes writing the file. The structure has the same format as the check_file( ) primitive uses (see File Properties). If the f_info parameter is null, Epsilon doesn't gather such information.

Different values for the start parameter change Epsilon's behavior. In the usual case, pass the value FILE_IO_ATSTART. That makes Epsilon open or create the file normally and start writing at its beginning, replacing its existing contents.

A start value of FILE_IO_NEWFILE makes the new_file_write( ) call fail if the file already exists. You can set the file_write_newfile variable nonzero when calling the higher-level writing functions described below to ensure that new_file_write( ) receives this value.

A start value of FILE_IO_TEMPFILE makes Epsilon ignore the specified file name and pick an unused file name for a temporary file, in a directory designated for temporary files. The get_tempfile_name( ) primitive returns a pointer to the most recent temporary file created in this way (in a static buffer that will be reused for the next temporary file name).

With any of the above start codes, whatever Epsilon writes replaces the previous contents of the file. If start is greater than or equal to zero, though, Epsilon only rewrites a section of the existing file, starting at the offset specified by start, and the rest of the file's data will not change.

If either lowstart or highstart are nonzero, Epsilon combines them to make a 64-bit number and uses that as the value of start, so that portions of very large files may be written, even when the whole file is too large for Epsilon.

If the max parameter is non-negative, Epsilon writes only the specified number of characters. (Epsilon counts the characters before adding any <Return> characters or performing any encoding; the count is of characters in the current buffer.) If max is negative, Epsilon writes the entire buffer to the file.

The file-writing primitives use the abort-file-io variable to decide what to do if the user presses the abort key; see File Reading Primitives.

int do_save_file(int backup, int checkdate,
                 int getdate) /* files.e */

The do_save_file( ) subroutine saves the current buffer like the save-file command, but lets you skip some of the things save-file does. Set the backup parameter to 0 if you don't want a backup file created, even if want-backups is nonzero. Set checkdate to 0 if you don't want Epsilon to check that the file on disk is unchanged since it was read. Set getdate to 0 if you don't want Epsilon to update its notion of the file's date, after the file has been written.

The function returns 0 if the write was successful, 1 if an error occurred, or 2 if the function asked the user to confirm a questionable write, and the user decided not to write the file after all.

int ask_save_buffer()
int warn_existing_file(char *s)

A command can call the ask_save_buffer( ) subroutine before deleting a buffer with unsaved changes. It asks the user if the buffer should be saved before it's deleted, and returns non-zero if the user asked that the buffer be saved. The caller is responsible for actually saving the file.

Before writing to a user-specified file, a command may call the warn_existing_file( ) subroutine. This will check if the file already exists and warn the user that it will be overwritten. The subroutine returns zero if the file didn't exist, or if the user said to go ahead and overwrite it, or nonzero if the user said not to overwrite it.



Previous   Up    Next
File Reading Primitives  Primitives and EEL Subroutines   Line Translation Primitives


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