Deutsch   English   Français   Italiano  
<v3rrtm$1e6g8$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Malcolm McLean <malcolm.arthur.mclean@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: Running an editor from ANSI C
Date: Thu, 6 Jun 2024 09:27:34 +0100
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <v3rrtm$1e6g8$1@dont-email.me>
References: <v3pge7$uf2i$1@dont-email.me> <v3r2pl$16mtl$1@dont-email.me>
 <v3r7v8$1b57j$1@dont-email.me> <v3rek5$1c4i5$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 06 Jun 2024 10:27:34 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="e0edff7614c2fb0d5b8cdac9c846a7dd";
	logging-data="1513992"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19hr8ZALEiZZNK6GykO1zi+lbY01Qq7gik="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:KnejYmETj38SgchIBFeEhoc8QP8=
In-Reply-To: <v3rek5$1c4i5$1@dont-email.me>
Content-Language: en-GB
Bytes: 3254

On 06/06/2024 05:40, Janis Papanagnou wrote:
> On 06.06.2024 04:47, Malcolm McLean wrote:
>>>
>> 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.
> 
> What do you mean here? You certainly can edit files with Vi-like
> ASCII-key commands (as, for example, some shells do to allow edit
> their history file).
> 
>> So at the moment I call system with nano, and it wotks. But it's a
>> clunky solution.
> 
> Nano at least relies on some control-keys. (Is that no issue?)
> 
> There's a couple of professional systems that allow to spawn any
> editor (that fits basic calling conventions) that suits you, which
> is a Good Thing. It's IMO generally a good approach to not force
> folks to use some specific (or even proprietary) editor in context
> of an application. (Not that this design practice would be widely
> observable in practice.)
> 
> Janis
> 

This is the current code for the "edit" command.

  else if (!strcmp(command, "edit"))
    {
        char *exportargs[4];
        char *importargs[4];
        char buff[1024];
        if (argc == 2)
        {
            char *tempfile = 0;
            tempfile = tmpnam(0);
            if (tempfile)
            {
                exportargs[0] = "export";
                exportargs[1] = argv[1];
                exportargs[2] = tempfile;
                exportargs[3] = 0;
                export(shell, 3, exportargs);
                snprintf(buff, 1024, "%s %s\n", shell->editor, tempfile);
                system(buff);
                importargs[0] = "import";
                importargs[1] = tempfile;
                importargs[2] = argv[1];
                importargs[3] = 0;
                import(shell, 3, importargs);
            }
        }
    }

It does work. But my compiler warns about rmpnam() being deprecated.

-- 
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm