Sujet : Re: Running an editor from ANSI C
De : cr88192 (at) *nospam* gmail.com (BGB)
Groupes : comp.lang.cDate : 06. Jun 2024, 06:34:42
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v3rhps$1c8tl$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 6/5/2024 9:47 PM, Malcolm McLean wrote:
On 06/06/2024 02:18, Lawrence D'Oliveiro wrote:
On Wed, 5 Jun 2024 11:59:19 +0100, Malcolm McLean wrote:
>
So I just call system with nano.
>
The trouble with system(3) is it requires a shell as an intermediary, with
consequent pitfalls involving command-line parsing.
>
More robust to use posix_spawn(3).
>
The concept is an ANSI C only shell.
I can write my own text editor on top of Posix easily enough.
But I want to implent an "edit" command so that users can edit files.
And you just can't edit files without non-ASCII keys.
So at the moment I call system with nano, and it wotks. But it's a clunky solution.
Theoretically, if you do a text editor with a similar interface to "ed" or "edlin", it could be done entirely within the limits of ANSI C.
Well, or use slightly more verbose/"intuitive" commands, like old style BASIC.
Say:
10 first line
20 second line
30 third line
list // prints previously entered lines
15 new line between first and second line
...
When saving files, it would likely discard the line numbers, and then regenerate new line numbers when loading a file (possibly following the de-facto convention of line numbers that step in units of 10).
Say, because this might be slightly easier to make sense of than, say:
a
first line
second line
third line
.
,p
2i
new line between first and second line
.
Well, and 'ed' having its notably unhelpful error message style of:
?
...