1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-17 09:38:05 +11:00
collapseos/apps/ed
Virgil Dupras 019d05f64c Make the shell a userspace app
That's my mega-commit you've all been waiting for.

The code for the shell share more routines with userspace apps than with kernel
units, because, well, its behavior is that of a userspace app, not a device
driver.

This created a weird situation with libraries and jump tables. Some routine
belonging to the `kernel/` directory felt weird there.

And then comes `apps/basic`, which will likely share even more code with the
shell. I was seeing myself creating huge jump tables to reuse code from the
shell. It didn't feel right.

Moreover, we'll probably want basic-like apps to optionnally replace the shell.

So here I am with this huge change in the project structure. I didn't test all
recipes on hardware yet, I will do later. I might have broken some...

But now, the structure feels better and the line between what belongs to
`kernel` and what belongs to `apps` feels clearer.
2019-11-15 15:37:49 -05:00
..
buf.asm Rename blockdev's API routines to GetB/PutB 2019-10-30 16:59:35 -04:00
cmd.asm Rename blockdev's API routines to GetB/PutB 2019-10-30 16:59:35 -04:00
glue.asm Make the shell a userspace app 2019-11-15 15:37:49 -05:00
io.asm Rename blockdev's API routines to GetB/PutB 2019-10-30 16:59:35 -04:00
main.asm Extract str.asm from core.asm and make core included by userspace 2019-11-14 10:14:15 -05:00
README.md Fix misc. source comment typos 2019-10-09 11:12:08 -04:00

ed - line editor

Collapse OS's ed is modeled after UNIX's ed (let's call it Ued). The goal is to have an editor that is tight on resources and that doesn't require ncurses-like screen management.

In general, we try to follow Ued's conventions and the "Usage" section is mostly a repeat of Ued's man page.

Differences

There are a couple of differences with Ued that are intentional. Differences not listed here are either bugs or simply aren't implemented yet.

  • Always has a prompt, :.
  • No size printing on load
  • Initial line is the first one
  • Line input is for one line at once. Less scriptable for Ued, but we can't script ed in Collapse OS anyway...
  • For the sake of code simplicity, some commands that make no sense are accepted. For example, 1,2a is the same as 2a.

Usage

ed is invoked from the shell with a single argument: the name of the file to edit. If the file doesn't exist, ed errors out. If it exists, a prompt is shown.

In normal mode, ed waits for a command and executes it. If the command is invalid, a line with ? is printed and ed goes back to waiting for a command.

A command can be invalid because it is unknown, malformed or if its address range is out of bounds.

Commands

  • (addrs)p: Print lines specified in addrs range. This is the default command. If only (addrs) is specified, it has the same effect.
  • (addrs)d: Delete lines specified in addrs range.
  • (addr)a: Appends a line after addr.
  • (addr)i: Insert a line before addr.
  • w: write to file. For now, q is implied in w.
  • q: quit ed without writing to file.

Current line

The current line is central to ed. Address ranges can be expressed relatively to it and makes the app much more usable. The current line starts at 1 and every command changes the current line to the last line that the command affects. For example, 42p changes the current line to 42, 3,7d, to 7.

Addresses

An "address" is a line number. The first line is 1. An address range is a start line and a stop line, expressed as start,stop. For example, 2,4 refer to lines 2, 3 and 4.

When expressing ranges, stop can be omitted. It will then have the same value as start. 42 is equivalent to 42,42.

Addresses can be expressed relatively to the current line with + and -. +3 means "current line + 3", -5, +2 means "address range starting at 5 lines before current line and ending 2 lines after it`.

+ alone means +1, - means -1.

. means current line. It can usually be omitted. p is the same as .p.

$ means the last line of the buffer.