Sujet : Re: Running an editor from ANSI C
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 09. Jun 2024, 01:27:31
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240608172047.502@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-06-08, Keith Thompson <Keith.S.Thompson+
u@gmail.com> wrote:
Michael S <already5chosen@yahoo.com> writes:
On Fri, 7 Jun 2024 10:47:57 -0000 (UTC)
Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
On Fri, 07 Jun 2024 02:37:42 -0700, Keith Thompson wrote:
As for portability, I'm not aware of the $EDITOR convention being
used on non-POSIX systems.
Can non-POSIX systems offer anything better? Any worthwhile
alternative?
No.
>
Yes. The one below is better.
ShellExecute(NULL, "edit", filename, NULL, NULL, SW_NORMAL);
>
For those not familiar with Windows, "edit" is not a command name, it's
an "object verb". The above call invokes the user's configured command
to edit the specified file. It might invoke a text editor for foo.txt,
an image editor for foo.png. It's similar to right-clicking a file in
the file explorer and selecting "Edit". Other verbs include "open",
"print", and "properties".
That seems poor to use. If we know that the file is a text file
regardless of its suffix, it would make much more sense to use the
Windows APIs necessary to resolve the association between .txt and a
program, if one exists, and then use the indicated program.
Basically this:
1. Call getenv("EDITOR"); if that yields something use it.
2. Else, dig up the association between .txt and a program.
If it exists, use that program.
3. Fallback on notepad.exe or error out.
(Using EDITOR on Windows makes sense in a cross-platform tool
oriented toward cross-platform users.)
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca