Sujet : Re: Running an editor from ANSI C
De : malcolm.arthur.mclean (at) *nospam* gmail.com (Malcolm McLean)
Groupes : comp.lang.cDate : 06. Jun 2024, 17:08:42
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v3smua$1io29$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla Thunderbird
On 06/06/2024 16:42, Mikko wrote:
On 2024-06-06 02:47:04 +0000, Malcolm McLean said:
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.
Just make the editor a part of the shell.
When I was learning C I was given a text editor to write as a starter exercise. So it's not exactly a challenging program to write. If you can
intercept arrow keys so that the user can move the cursor about the screen, and keypresses so that you write a character at the cursor location. And fundamentally you are moving a cursor over a raster in response to arrow keys, and that program takes an hour or so to write, and that is the heart of a simple editor.
There's more to it than that, of course, but basically you are editing short text files.
And you just can't do that in ANSI C. There is no way of intercepting the arrow keys (you can always ask the user for the dimensions of his terminal, output is not impossible). It's input which is the killer.
-- Check out Basic Algorithms and my other books:https://www.lulu.com/spotlight/bgy1mm