From: Mary Ann Horton <mah@mhorton.net>
To: tuhs@minnie.tuhs.org
Subject: Re: [TUHS] Data structures in Unix editors
Date: Mon, 5 Apr 2021 16:23:00 -0700 [thread overview]
Message-ID: <2f984847-0eb4-031b-5691-bc4311da1e47@mhorton.net> (raw)
In-Reply-To: <bba5ddda-726f-5a0-11c0-6b17f785c4b4@dotat.at>
This is actually what ed, ex, and vi do as well, albeit not with a
standard interface.
The buffer is an array of integer offsets into a file. Line n in the
buffer is pointed at by buffer[n], whose contents are an offset into the
temp file. That offset points to a null terminated line of buffer text.
When a new line of text is created (or changed) the new line is appended
to the temp file and the corresponding offset goes into the buffer array.
One big reason for this was that ed was originally written for a 16 bit
machine, and buffers didn't fit in memory.
This works very well to insert or delete lines, you only have to copy
the line references in the buffer array. It's also convenient for undo,
since putting things back just means restoring the original array. My
enhanced ed (hed at Wisconsin, Portable ed at Bell Labs) had a second
array for undo, and a full copy of the array was made before a change.
Bill Joy wrote a fancier implementation in vi, where only lines added or
deleted were saved, command-specific. Undo knew which command it had to
undo and special-cased each one.
The big disadvantage to this structure is that ends of lines are not
just newline characters. You can't backspace over a newline, or change
newlines to something else.
Mary Ann
On 4/1/21 5:56 AM, Tony Finch wrote:
> David C. Brock <dbrock@computerhistory.org> wrote:
>> I’d like to read similar discussions of the data structures for ed, em,
>> ex/vi. If anyone has suggestions of references, they would be very
>> welcome!
> A curious one is nvi, which uses the Berkeley DB RECNO interface to access
> a text file as an array of lines (RECNO = record number).
>
> Tony.
next prev parent reply other threads:[~2021-04-05 23:23 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-31 17:39 David C. Brock
2021-03-31 18:07 ` arnold
2021-03-31 18:23 ` Richard Salz
2021-03-31 18:20 ` Lars Brinkhoff
2021-03-31 18:49 ` Bakul Shah
2021-04-01 12:56 ` Tony Finch
2021-04-01 14:24 ` Richard Salz
2021-04-01 21:25 ` Dave Horsfall
2021-04-01 21:32 ` John Cowan
2021-04-02 22:40 ` Dave Horsfall
2021-04-02 23:20 ` Adam Thornton
2021-04-03 0:34 ` Jon Forrest
2021-04-05 23:23 ` Mary Ann Horton [this message]
2021-04-01 20:12 Noel Chiappa
2021-04-01 20:57 ` John Cowan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2f984847-0eb4-031b-5691-bc4311da1e47@mhorton.net \
--to=mah@mhorton.net \
--cc=tuhs@minnie.tuhs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).