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
         More File Primitives
         . . .
      Operating System Primitives
         System Primitives
         Window System Primitives
         Timing
         Calling Windows DLLs
         Running a Process
      . . .

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


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

Line Translation Primitives

Epsilon normally deals with files with lines separated by the <Newline> character. Windows, DOS and OS/2, however, generally separate one line from the next with a <Return> character followed by a <Newline> character. For this reason, Epsilon normally removes all <Return> characters from a file when it's read from disk, and places a <Return> character before each <Newline> character when a buffer is written to disk, in these environments. But Epsilon has several other line translation methods:

The FILETYPE_BINARY translation type tells Epsilon not to modify the file at all when reading or writing.

The FILETYPE_MSDOS translation type tells Epsilon to remove <Return> characters when reading a file, and insert a <Return> character before each <Newline> when writing a file.

The FILETYPE_UNIX translation type tells Epsilon not to modify the file at all when reading or writing. It's similar to FILETYPE_BINARY (but Epsilon copies buffer text to the system clipboard in a different way).

The FILETYPE_MAC translation type tells Epsilon to convert <Return> characters to <Newline> characters when reading a file, and to convert <Newline> characters to <Return> characters when writing a file.

The FILETYPE_AUTO translation type tells Epsilon to examine the contents of a file as it's read, and determine the proper translation type using a heuristic. Epsilon then reads the file using that translation type, and sets translation-type to the new value. Normally this value is only used when reading a file, not when writing one. If you try to write a file and specify a translation type of FILETYPE_AUTO, it will behave the same as FILETYPE_MSDOS (except in Epsilon for Unix, where it's the same as FILETYPE_UNIX.

user buffer int translation_type;  /* EEL variable */
#define FORCED_TRANS               (8)
#define MAKE_TRANSLATE(e, t, f)    (((e) << 4) | ((t) & 7) \
                                   | ((f) ? FORCED_TRANS : 0))
#define GET_ENCODING(t)            ((t) >> 4)
#define GET_LINE_TRANSLATE(t)      ((t) & 7)
#define SET_TRANSLATE(t, trans)    (((t) & ~7) | ((trans) & 7))
#define SET_ENCODING(t, e)         (((t) & 15) | ((e) << 4))

The buffer-specific variable translation-type includes the current buffer's translation type as one of the above codes, combined with an encoding number that specifies the current buffer's encoding. Most functions for reading or writing a file take such a value as a transl parameter.

You can combine one of the above translation codes with an encoding number using the MAKE_TRANSLATE() macro. It takes a translation code t, an encoding code e, and a code f which, if nonzero, indicates that the resulting translation value was explicitly specified by the user in some way, not auto-detected.

Use the macros GET_ENCODING() and GET_LINE_TRANSLATE() to extract the encoding code or the line translation code, respectively, from a translation type value.

Use the macros SET_ENCODING() and SET_TRANSLATE() to combine an existing translation type value t with a new encoding code or line translation code, respectively.

user int default_translation_type;
user int new_buffer_translation_type;
int give_line_translate(char *fname)
int ask_line_translate()
get_fallback_translation_type()
buffer int fallback_translation_type;

A user can set the default-translation-type variable to one of the above translation codes to force Epsilon to use a specific translation when it reads an existing file. If this variable is set to its default value of FILETYPE_AUTO, Epsilon examines the file to determine a translation method. Setting this variable to any other value forces Epsilon to use that line translation method for all files. (The variable can specify only an encoding, or only a line translation, or both.)

When Epsilon creates a new buffer, it sets the buffer's translation-type variable to the value of the new-buffer-translation-type variable. Epsilon does the same when you try to read a file that doesn't exist. You can set this variable if you want Epsilon to examine existing files to determine their translation type, but create new files with a specific translation type. By default this variable is set to FILETYPE_AUTO, so the type for new buffers becomes FILETYPE_UNIX in Epsilon for Unix, and FILETYPE_MSDOS elsewhere.

The give_line_translate( ) subroutine defined in files.e helps to select the desired translation method and encoding. Many commands that read a user-specified file call it. If a numeric prefix argument was not specified, it returns the default translation type, often the value of the default-translation-type variable. (See that variable for details.) But if a numeric prefix argument was specified, it prompts the user for the desired translation type and encoding.

The ask_line_translate( ) subroutine is similar, but doesn't take a file name, and won't use any setting that might override the default-translation-type variable. New EEL code should use give_line_translate( ) instead.

The get_fallback_translation_type( ) primitive returns the translation type code Epsilon would assign when reading an empty file, or when writing a buffer whose translation type code was set to FILETYPE_AUTO. It returns FILETYPE_UNIX under Unix and FILETYPE_MSDOS on other platforms, but may be overridden for the current buffer by setting the buffer-specific fallback_translation_type variable.



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


Lugaru Copyright (C) 1984, 2020 by Lugaru Software Ltd. All rights reserved.