File types -- text files and binary files – Crunch CRiSP File Editor 6 User Manual

Page 39

Advertising
background image

Page 39

timer(pg.
45).

CriSP supports callbacks based on an elapsed real-time clock.

window(pg.
33).

A window is a character mode window with a view on to a buffer. A single screen
can contain multiple character mode windows.

Buffers(pg. 33).

Macros(pg. 41).

File Types -- Text files and Binary Files

CRiSP allows any file type to be edited, whether the file is binary or text. Editing binary files is allowed
although CRiSP does not contain any special facilities (yet) to perform editing on these files.

Binary files are identified by looking for non-printable characters in the first 100 or so characters of the file. If
there are too many, CRiSP reads the file in, but makes each line only 32 characters wide. This avoids
performance problems with CRiSP whereby if it did not do this, then it would read the whole file into a single
line, making editing and scanning difficult.

Editing binary files can be useful, e.g. as an alternative to the strings(1) utility, to look at the printable strings
in a binary. It can also be useful to make small edits to binary files. For example, to patch string literals in the
file. Care is needed when editing executable files, since the file size needs to be exactly the same before
editing the file as afterwards.

CRiSP notes buffers containing binary files, to ensure that an arbitrary newline character is not inserted at
the end of each 32-character line.

Backing up Files

Backups are created when a file is actually saved. Every time a new file is edited, the old file is renamed so
that even after writing a file away to the disk, the previous version of the file can be recovered. CRiSP can
be configured to create backup files in a separate directory (useful for doing mass deletions when disk
space is low) or for creating a '.bak' file in the current directory. To some users it may be distracting to have
lots of directories filled with .bak files.

In addition, CRiSP supports the ability to keep multiple copies of old backed up files. Again, this is
implemented via the set_backup() primitive. When this variable is set, crisp creates a set of sub-directories
in the main backup directory, named .../0, .../1, etc (the higher the number the older the backup). When a file
is written away, the most recent backup is put in the backup directory. The previous version in the backup
directory is moved to the .../0 sub-directory. That is, the backup directory contains the most recent backup,
.../0 contains the second most recent backup, and .../N-1 contains the oldest backup.

It is sometimes useful to turn off backup file generation for certain files, e.g. very large log files; you can tell
CRiSP to turn off creating a backup file for the current file by using the set_backup macro.

In addition to the above two features, CRiSP has a builtin facility to save buffers in an emergency. If CRiSP
detects an internal error (e.g. segmentation violation) all the currently modified buffers are written away to
the current directory, with filenames called BUFFER-0, BUFFER-1, and so on. This should never happen,
but bugs have a habit of laying dormant until the most unfriendly time.

To optimise performance, CRiSP uses the following algorithm when trying to backup a file:

1. If the file has multiple links to it, the file is copied to the destination directory. (See below). If the file has

only a single link, then it may be link()ed to the destination directory.

(Linking is much faster than copying because the actual contents of the file need not be copied -- just
the file name is changed).

2. For each directory in the backup directory list try to link() the file to the specified directory. This

operation may fail if the directory is on a different file system. (This step is skipped if the
BACKUP_SLOW flag is set).

3. If step 2 fails, then for each directory in the backup directory list, try and copy the file to the resultant

directory. This may fail because of permissions.

4. If steps 2 & 3 fail, try and create a file with a .bak extension. If the file has multiple links, then the old file

is copied to the new file. If the file has a single link, then it is link()ed to the .bak file.

Autosaving

Advertising