• Re: Running an editor from ANSI C

    From Lawrence D'Oliveiro@21:1/5 to Malcolm McLean on Thu Jun 6 01:18:45 2024
    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).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Malcolm McLean on Thu Jun 6 06:40:36 2024
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Malcolm McLean on Thu Jun 6 04:46:24 2024
    On Thu, 6 Jun 2024 03:47:04 +0100, 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.

    Does ANSI C include functions for escaping shell specials?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Janis Papanagnou on Thu Jun 6 04:47:07 2024
    On Thu, 6 Jun 2024 06:40:36 +0200, Janis Papanagnou wrote:

    It's IMO generally a good approach to not force folks to use some
    specific (or even proprietary) editor in context of an application.

    Checking the $EDITOR environment variable is common practice.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to Malcolm McLean on Thu Jun 6 11:07:16 2024
    On 06/06/2024 10:27, Malcolm McLean wrote:

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


    I presume you mean "tmpnam()" here. No, it has not been deprecated -
    not even in C23. I could be wrong, but this sounds like one of MSVC's arbitrary self-declared deprecations, using scare tactics to encourage
    people to use MSVC's own functions rather than standard C functions,
    thus locking you into their tools and platform.

    I gather you are doing all this for fun, which is great. You have set
    yourself a challenge with a total disregard for practicality or reality,
    and are writing this stuff for your own enjoyment. We all need that
    kind of project at times.

    But it seems strange to limit yourself to an ancient and impractical
    language (C89/C90, which you inaccurately call "ANSI C") for
    "portability" and then worry about compiler-specific warnings.

    If you want to check if something is /actually/ deprecated or
    obsolescent, I'd recommend using a good source - such as future C
    standards (<https://open-std.org/JTC1/SC22/WG14/www/docs/n3220.pdf>) or
    the cppreference.com site <https://en.cppreference.com/w/c/io/tmpnam>.


    (Of course, tmpnam() does have plenty of potential problems, and for
    real code, you'd be better off using Windows-specific and/or
    POSIX-specific functions for this kind of thing. But that would be
    against your rules.)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Harnden@21:1/5 to Scott Lurndal on Thu Jun 6 15:13:55 2024
    On 06/06/2024 14:54, Scott Lurndal wrote:
    David Brown <david.brown@hesbynett.no> writes:
    On 06/06/2024 10:27, Malcolm McLean wrote:

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


    I presume you mean "tmpnam()" here. No, it has not been deprecated -

    True, but at least one form of it is not thread-safe.


    My man page (Linux man-pages 6.04, 2023-03-30) says that both tmpnam and tmpnam_r are deprecated, and you should use mkstemp(3) or tmpfile(3)
    instead.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to David Brown on Thu Jun 6 13:54:55 2024
    David Brown <david.brown@hesbynett.no> writes:
    On 06/06/2024 10:27, Malcolm McLean wrote:

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


    I presume you mean "tmpnam()" here. No, it has not been deprecated -

    True, but at least one form of it is not thread-safe.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mikko@21:1/5 to Malcolm McLean on Thu Jun 6 18:42:22 2024
    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.

    And you just can't edit files without non-ASCII keys.

    I have edited files without non-ASCII keys so I know it can be done.
    However, non-ASCII keys make it easier, especially if the files contain non-ASCII characters.

    So at the moment I call system with nano, and it wotks. But it's a
    clunky solution.

    --
    Mikko

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Malcolm McLean on Thu Jun 6 17:56:45 2024
    Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
    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

    Cursor? What's that?

    A text editor should be able to work on a teletype, for example ed(1).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Scott Lurndal on Thu Jun 6 22:56:49 2024
    On Thu, 06 Jun 2024 17:56:45 GMT, Scott Lurndal wrote:

    A text editor should be able to work on a teletype, for example ed(1).

    Teletype? What’s that?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Malcolm McLean on Fri Jun 7 00:40:44 2024
    On Thu, 6 Jun 2024 15:35:53 +0100, Malcolm McLean wrote:

    The only way I can get the Baby X shell to run nano is to use tmpnam().
    I've tried mkstemp insteaad, and I just can't find a way.

    mkstemp opens the temporary file, which is not much use if you want to run
    an external program which requires a filename.

    To solve the potential race conditions with creating temporary files, I
    think the right solution is to use mkdtemp(3) instead. That creates and
    returns the name of a temporary directory. Now you are free to create as
    many files (and subdirectories) as you like with whatever names you like
    within that, secure in the knowledge that nobody else can interfere with
    you.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Keith Thompson on Fri Jun 7 00:36:27 2024
    On Thu, 06 Jun 2024 12:54:57 -0700, Keith Thompson wrote:

    (mkstemp() is more flexible, but is not defined by ISO C.)

    I’ve said this before: C is essentially crippled without a POSIX layer underneath.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Malcolm McLean on Fri Jun 7 04:46:13 2024
    On 2024-06-06, Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
    I want to run nano (or vi, or ed), in a shell running a pure ansi C
    program. So the way to do it is to create a file, write the text you
    want edit to it, them call system("nano readme.txt"). Nano then grabs
    the cobsole, which is what you want. You then read the file to get the edited data.

    In the TXR project, I took Antirez's Linenoise library and did a lot
    of work on it. One of the features I added is Ctrl-X Ctrl-E to edit
    the input in an external editor.

    There are some non-standard-C bitws in it, but the main gist of it is
    as you say. The temporary file is written using some I/O functions in a callback API used by linenoise and the editor is run via system().

    https://www.kylheku.com/cgit/txr/tree/linenoise/linenoise.c

    Function to look for is edit_in_editor.

    In that code I made the decision to try to plant the temporary file
    in the user's home directory, or else just the current directory
    if the home directory can't be identified for whatever reason.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to Lawrence D'Oliveiro on Fri Jun 7 11:31:01 2024
    On 07/06/2024 02:36, Lawrence D'Oliveiro wrote:
    On Thu, 06 Jun 2024 12:54:57 -0700, Keith Thompson wrote:

    (mkstemp() is more flexible, but is not defined by ISO C.)

    I’ve said this before: C is essentially crippled without a POSIX layer underneath.

    And you were also wrong the last time you said that.

    Pure standard C89/C90 and its standard library is not sufficient for a
    good implementation of the kind of thing Malcolm is trying to make here.
    But that's not surprising - it was never designed or intended to be sufficient for such projects.

    But many people have lots of use of programming in C without any kind of
    POSIX functionality - your claim is clearly wild and unhelpful
    exaggeration at best.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to David Brown on Fri Jun 7 10:46:48 2024
    On Fri, 7 Jun 2024 11:31:01 +0200, David Brown wrote:

    But many people have lots of use of programming in C without any kind of POSIX functionality ...

    And all those same programs work in the presence of POSIX functionality,
    plus you get access to a whole lot more besides.

    The fact that cases keep arising where POSIX functionality would solve
    problems that are discussed in this group belies your point.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Keith Thompson on Fri Jun 7 10:47:57 2024
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael S@21:1/5 to Lawrence D'Oliveiro on Fri Jun 7 14:24:29 2024
    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);

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to Lawrence D'Oliveiro on Fri Jun 7 09:32:26 2024
    On 6/7/24 06:46, Lawrence D'Oliveiro wrote:
    On Fri, 7 Jun 2024 11:31:01 +0200, David Brown wrote:

    But many people have lots of use of programming in C without any kind of
    POSIX functionality ...

    And all those same programs work in the presence of POSIX functionality,

    Even those that rely upon some other operating system's corresponding functionality instead? If I write C code that makes lots of VMS system
    calls (which I did a few decades ago, though I no longer remember the
    details), would it still have worked correctly under POSIX?

    You're right that C is not complete, but POSIX isn't the only thing you
    can add to make it complete. Of the available options, I do prefer
    POSIX, but POSIX is not the be-all and end-all of operating systems.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Malcolm McLean on Fri Jun 7 14:02:41 2024
    Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
    On 06/06/2024 23:55, Keith Thompson wrote:

    One suggestion: rather than always using nano (which not everyone is
    familiar with), try reading the $EDITOR environment variable to
    determine what editor to use. Concatenating the value of
    getenv("EDITOR"), followed by a space, followed by the file name, is
    likely to give you a valid command you can pass to system(). Fall back
    to nano if getenv("EDITOR") returns a null pointer.

    (For historical reasons, the convention is to use $VISUAL if it's set,
    otherwise $EDITOR if it's set, otherwise some default. Originally
    $VISUAL typically referred to a full-screen editor like vi and $EDITOR
    to a line editor like ed, to be used when full-screen editing is not
    available. That's unlikely to be relevant nowadays, and users typically
    either don't set $VISUAL or set it to the same thing as $EDITOR.)

    Don't do this for me; I'm not likely to use this. But others are likely
    to find it more user-friendly if they can use a chosen editor.



    Ah thank you. But then main has to take an extra parameter. Now will
    the shell still be absolutely robust, and completely portable, and run
    just anywhere?

    POSIX already defines the 'env' parameter to main which holds
    the exported shell environment variables.

    int main(int arg const char **argv, const char **envp)

    Then there is also a getenv(3) library function.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to Lawrence D'Oliveiro on Fri Jun 7 16:48:29 2024
    On 07/06/2024 12:46, Lawrence D'Oliveiro wrote:
    On Fri, 7 Jun 2024 11:31:01 +0200, David Brown wrote:

    But many people have lots of use of programming in C without any kind of
    POSIX functionality ...

    And all those same programs work in the presence of POSIX functionality,
    plus you get access to a whole lot more besides.

    No, they do not.

    And even if POSIX functionality were "present", whatever you mean by
    that, it would be of no help to many C programs.


    The fact that cases keep arising where POSIX functionality would solve problems that are discussed in this group belies your point.

    There's no doubt that for some C programming, there are POSIX functions
    that could help. And no doubt that this is the case for Malcolm's project.

    That does not in any way demonstrate that POSIX is required for all C programming, or that C is "essentially crippled" if POSIX is not available.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Malcolm McLean on Fri Jun 7 19:56:47 2024
    On 07.06.2024 14:57, Malcolm McLean wrote:
    On 07/06/2024 10:37, Keith Thompson wrote:
    Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:

    Ah thank you. But then main has to take an extra parameter. Now will
    the shell still be absolutely robust, and completely portable, and run
    just anywhere?

    What? Why would main need an extra parameter?

    Hre's the main function for the shell.

    int main(int argc, char **argv)
    {
    [...]
    }

    Now to get the $EDITOR variable I will have to modify this function.

    int main(int argc, char **argv, char **envp)

    Now what are the implications of doing that? [...]

    I'm certainly not the most qualified person to answer that, so
    just two comments...
    Declaring the extra parameter doesn't spoil the code, does it?
    (If you don't use it you don't need to specify it. If you have
    declared it you can use it or not.)
    Personally my first reflex would be to use a dedicated function
    to obtain a specific environment variable, specifically getenv();
    I thought it wouldn't require the 'envp' to work?

    For me it works

    #include <stdlib.h>
    #include <stdio.h>
    void main (int argc, char * argv[])
    {
    printf ("%s\t%s\n", argv[1], getenv(argv[1]));
    }


    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Janis Papanagnou on Fri Jun 7 18:10:06 2024
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 07.06.2024 14:57, Malcolm McLean wrote:
    On 07/06/2024 10:37, Keith Thompson wrote:
    Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:

    Ah thank you. But then main has to take an extra parameter. Now will
    the shell still be absolutely robust, and completely portable, and run >>>> just anywhere?

    What? Why would main need an extra parameter?

    Hre's the main function for the shell.

    int main(int argc, char **argv)
    {
    [...]
    }

    Now to get the $EDITOR variable I will have to modify this function.

    int main(int argc, char **argv, char **envp)

    Now what are the implications of doing that? [...]

    I'm certainly not the most qualified person to answer that, so
    just two comments...
    Declaring the extra parameter doesn't spoil the code, does it?
    (If you don't use it you don't need to specify it. If you have
    declared it you can use it or not.)
    Personally my first reflex would be to use a dedicated function
    to obtain a specific environment variable, specifically getenv();
    I thought it wouldn't require the 'envp' to work?

    For me it works

    #include <stdlib.h>
    #include <stdio.h>
    void main (int argc, char * argv[])
    {
    printf ("%s\t%s\n", argv[1], getenv(argv[1]));
    }


    You are correct, it is not necessary to declare 'envp' in
    the main function in order to use getenv(3) to retrieve the
    value of a named environment variable.

    If one wishes to eschew getenv(3), the external symbol __environ
    points to the first environment table entry.

    $ cat /tmp/a.c
    #include <stddef.h>
    #include <stdio.h>
    #include <stdlib.h>

    int
    main(int argc, const char **argv, const char **envp)
    {
    extern char **__environ;

    printf("%p %p\n", envp, __environ);
    return 0;
    }

    $ cc -o /tmp/a /tmp/a.c
    $ /tmp/a
    0x7fff64c2fe78 0x7fff64c2fe78
    $

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Harnden@21:1/5 to Malcolm McLean on Fri Jun 7 20:08:03 2024
    On 07/06/2024 19:52, Malcolm McLean wrote:
    On 07/06/2024 18:56, Janis Papanagnou wrote:
    On 07.06.2024 14:57, Malcolm McLean wrote:
    On 07/06/2024 10:37, Keith Thompson wrote:
    Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:

    Ah thank you. But then main has to take an extra parameter. Now  will >>>>> the shell still be absolutely robust, and completely portable, and run >>>>> just anywhere?

    What?  Why would main need an extra parameter?

    Hre's the main function for the shell.

    int main(int argc, char **argv)
    {
    [...]
    }

    Now to get the $EDITOR variable I will have to modify this function.

    int main(int argc, char **argv, char **envp)

    Now what are the implications of doing that? [...]

    I'm certainly not the most qualified person to answer that, so
    just two comments...
    Declaring the extra parameter doesn't spoil the code, does it?
    (If you don't use it you don't need to specify it. If you have
    declared it you can use it or not.)
    Personally my first reflex would be to use a dedicated function
    to obtain a specific environment variable, specifically getenv();
    I thought it wouldn't require the 'envp' to work?

    For me it works

       #include <stdlib.h>
       #include <stdio.h>
       void main (int argc, char * argv[])
       {
           printf ("%s\t%s\n", argv[1], getenv(argv[1]));
       }


    Janis

    Is getenv() standard now? When did it come in?

    C11, I think.


    --
    This email has been checked for viruses by AVG antivirus software.
    www.avg.com

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Malcolm McLean on Fri Jun 7 20:09:35 2024
    Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:

    On 07/06/2024 18:56, Janis Papanagnou wrote:
    On 07.06.2024 14:57, Malcolm McLean wrote:
    On 07/06/2024 10:37, Keith Thompson wrote:
    Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:

    Ah thank you. But then main has to take an extra parameter. Now will >>>>> the shell still be absolutely robust, and completely portable, and run >>>>> just anywhere?

    What? Why would main need an extra parameter?

    Hre's the main function for the shell.

    int main(int argc, char **argv)
    {
    [...]
    }

    Now to get the $EDITOR variable I will have to modify this function.

    int main(int argc, char **argv, char **envp)

    Now what are the implications of doing that? [...]
    I'm certainly not the most qualified person to answer that, so
    just two comments...
    Declaring the extra parameter doesn't spoil the code, does it?
    (If you don't use it you don't need to specify it. If you have
    declared it you can use it or not.)
    Personally my first reflex would be to use a dedicated function
    to obtain a specific environment variable, specifically getenv();
    I thought it wouldn't require the 'envp' to work?
    For me it works
    #include <stdlib.h>
    #include <stdio.h>
    void main (int argc, char * argv[])
    {
    printf ("%s\t%s\n", argv[1], getenv(argv[1]));
    }
    Janis

    Is getenv() standard now? When did it come in?

    It was in the first C standard. Basically it predates standardisation:

    https://bsb.me.uk/ansi-c/ansi-c.html#sec_4_10_4_4

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Malcolm McLean on Fri Jun 7 20:04:30 2024
    Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
    On 07/06/2024 15:48, David Brown wrote:
    On 07/06/2024 12:46, Lawrence D'Oliveiro wrote:
    On Fri, 7 Jun 2024 11:31:01 +0200, David Brown wrote:

    But many people have lots of use of programming in C without any kind of >>>> POSIX functionality ...

    And all those same programs work in the presence of POSIX functionality, >>> plus you get access to a whole lot more besides.

    No, they do not.

    And even if POSIX functionality were "present", whatever you mean by
    that, it would be of no help to many C programs.


    The fact that cases keep arising where POSIX functionality would solve
    problems that are discussed in this group belies your point.

    There's no doubt that for some C programming, there are POSIX functions
    that could help.  And no doubt that this is the case for Malcolm's project. >>
    That does not in any way demonstrate that POSIX is required for all C
    programming, or that C is "essentially crippled" if POSIX is not available. >>
    Any idiot can write a shell using Posix.

    The whole point is to it in pure C.

    How does your pure "C" shell
    spawn a new process without using posix or other OS-specific
    APIs?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Malcolm McLean on Fri Jun 7 20:06:01 2024
    Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
    On 06/06/2024 23:55, Keith Thompson wrote:
    Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
    On 06/06/2024 20:54, Keith Thompson wrote:
    David Brown <david.brown@hesbynett.no> writes:
    On 06/06/2024 10:27, Malcolm McLean wrote:
    It does work. But my compiler warns about rmpnam() being deprecated. >>>>>
    I presume you mean "tmpnam()" here. No, it has not been deprecated - >>>>> not even in C23. I could be wrong, but this sounds like one of MSVC's >>>>> arbitrary self-declared deprecations, using scare tactics to encourage >>>>> people to use MSVC's own functions rather than standard C functions, >>>>> thus locking you into their tools and platform.
    [...]
    You're right, tmpnam() is not deprecated either by ISO C or by
    POSIX.
    But tmpfile() is likely to be better for most purposes. It creates
    a
    file and returns a FILE*. tmpnam() returns a string pointer, and it's >>>> possible that some other process could create a file with the same name >>>> before the caller has a chance to create it.
    (mkstemp() is more flexible, but is not defined by ISO C.)

    I want to run nano (or vi, or ed), in a shell running a pure ansi C
    program. So the way to do it is to create a file, write the text you
    want edit to it, them call system("nano readme.txt"). Nano then grabs
    the cobsole, which is what you want. You then read the file to get
    the edited data.

    The shell isn't just a proof og concept. It has a practical purpose,
    because it is FileSystem XML file editor. Whilst I'm playing about
    putting Basic into it for fun, the real purpose is serious. And the
    user must have an easy way of editing text files in the FileSystem
    file.

    But it becomes effectively a virtual computer in its own right.

    OK -- but that has nothing at all to do with my post, which was about
    how to generate the temporary file name.

    One suggestion: rather than always using nano (which not everyone is
    familiar with), try reading the $EDITOR environment variable to
    determine what editor to use. Concatenating the value of
    getenv("EDITOR"), followed by a space, followed by the file name, is
    likely to give you a valid command you can pass to system(). Fall back
    to nano if getenv("EDITOR") returns a null pointer.

    (For historical reasons, the convention is to use $VISUAL if it's set,
    otherwise $EDITOR if it's set, otherwise some default. Originally
    $VISUAL typically referred to a full-screen editor like vi and $EDITOR
    to a line editor like ed, to be used when full-screen editing is not
    available. That's unlikely to be relevant nowadays, and users typically
    either don't set $VISUAL or set it to the same thing as $EDITOR.)

    Just Tried it out. On my Mac, which is the whizzy machine I used for >professional development, and now repurposed, because I was allowed to
    keep it, getenv(EDITOR) returns null, and VISUAL also returns null. So
    this system has been broken by some wicked person.

    VISUAL and EDITOR are undefined out of the box. It's up to the user to configure
    them before needing them, usually in their login '.profile' script.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Malcolm McLean on Fri Jun 7 20:37:05 2024
    On 2024-06-07, Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
    Is getenv() standard now? When did it come in?

    I believe, in 1989, ANSI C.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Michael S on Fri Jun 7 23:57:58 2024
    On Fri, 7 Jun 2024 14:24:29 +0300, Michael S wrote:

    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);

    On Windows, that combines the command-line arguments into a single string. Which then has to be teased apart by the receiving program. Assuming the
    two ends can agree on consistent rules for doing so.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to James Kuyper on Fri Jun 7 23:59:39 2024
    On Fri, 7 Jun 2024 09:32:26 -0400, James Kuyper wrote:

    On 6/7/24 06:46, Lawrence D'Oliveiro wrote:

    On Fri, 7 Jun 2024 11:31:01 +0200, David Brown wrote:

    But many people have lots of use of programming in C without any kind
    of POSIX functionality ...

    And all those same programs work in the presence of POSIX
    functionality,

    Even those that rely upon some other operating system's corresponding functionality instead?

    If it really was “corresponding”, then it would already be available via some POSIX-compatible wrapper for that OS.

    ... POSIX is not the be-all and end-all of operating systems.

    You’re right. It’s not. Linux is.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Malcolm McLean on Sat Jun 8 00:34:49 2024
    On Fri, 7 Jun 2024 13:57:25 +0100, Malcolm McLean wrote:

    Now to get the $EDITOR variable I will have to modify this function.

    int main(int argc, char **argv, char **envp)

    No, actually you don’t. The environment block is odd, in that you can
    access it via getenv(3) and friends, without having to go through the
    argument list to main().

    (And my man page says this is a “standard C library” routine, so no need for POSIX even.)

    For some reason this does not apply to argc and argv. I’ve often wished it did.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Malcolm McLean on Sat Jun 8 00:36:28 2024
    On 2024-06-07, Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
    On 07/06/2024 21:04, Scott Lurndal wrote:
    How does your pure "C" shell
    spawn a new process without using posix or other OS-specific
    APIs?

    It can call "system".

    1. System is an interface to someone else's existing shell1

    2. To do process coordination using "system", you will have to
    rely on implementation-specific syntax, like POSIX.
    For instance system("command1 | command2 > file").
    As soon as you rely on any specific command syntax in
    system(), your program is no longer maximally portable ISO C;
    it is a mixed-language program.

    3. A conforming C implementation need not provide a command
    interpreter, in which case system(NULL) returns zero.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Malcolm McLean on Sat Jun 8 00:32:05 2024
    On 2024-06-07, Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
    On 07/06/2024 15:48, David Brown wrote:
    On 07/06/2024 12:46, Lawrence D'Oliveiro wrote:
    On Fri, 7 Jun 2024 11:31:01 +0200, David Brown wrote:

    But many people have lots of use of programming in C without any kind of >>>> POSIX functionality ...

    And all those same programs work in the presence of POSIX functionality, >>> plus you get access to a whole lot more besides.

    No, they do not.

    And even if POSIX functionality were "present", whatever you mean by
    that, it would be of no help to many C programs.


    The fact that cases keep arising where POSIX functionality would solve
    problems that are discussed in this group belies your point.

    There's no doubt that for some C programming, there are POSIX functions
    that could help.  And no doubt that this is the case for Malcolm's project. >>
    That does not in any way demonstrate that POSIX is required for all C
    programming, or that C is "essentially crippled" if POSIX is not available. >>
    Any idiot can write a shell using Posix.

    The whole point is to it in pure C. Without a single call to a function
    that isn't in the C standard library.

    A shell written using nothing but the standard library ends up being
    a shell to that library: a user interface making available the services
    of the library to the user.

    When you think about what those are, they are not much.

    Your shell won't be able to juggle multiple processes between the
    foreground and background, or arrange pipes or anything of the sort.

    Remember, the system() function is an API to a command interpreter.

    A strictly conforming ISO C programm cannot rely on it.

    The command syntax is not specified, and command execution is
    required to work at all. If system(NULL) returns zero, it means
    that a command interpreter is not available.

    Relying another command interpreter while purporting to be writing one
    is a kind of fraud, too.

    And make it fully functional. A real shell, that people will want to
    really use. That's my hobby project. I'm a free man now. I've got the
    time. I don't have to write code that makes money any more.

    When I mentally survey what is possible in a purely ANSI C shell,
    what it will enable the user to do as a shell, I can't imagine why
    anyone would want to use it.

    I mean, of course, it could contain, say, a fairly engaging and deep
    text adventure game. Or a complex and capable programming language (with
    poor system access, but interesting nevertheless).

    Bug I take it that by shell you mean something which is primarily a
    command interpreter for driving an operating system, not an adventure
    game engine, or sophsticated programming language run-time.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to Lawrence D'Oliveiro on Sat Jun 8 01:40:48 2024
    On 6/7/24 19:59, Lawrence D'Oliveiro wrote:
    On Fri, 7 Jun 2024 09:32:26 -0400, James Kuyper wrote:

    On 6/7/24 06:46, Lawrence D'Oliveiro wrote:

    On Fri, 7 Jun 2024 11:31:01 +0200, David Brown wrote:

    But many people have lots of use of programming in C without any kind
    of POSIX functionality ...

    And all those same programs work in the presence of POSIX
    functionality,

    Even those that rely upon some other operating system's corresponding
    functionality instead?

    If it really was “corresponding”, then it would already be available via some POSIX-compatible wrapper for that OS.

    I didn't mean that kind of "corresponding". It might correspond only in
    the sense that it serves a similar purpose - but does so in a very
    different way. That doesn't necessarily make a fully POSIX compatible
    wrapper impossible (though it might be), but it does mean that even if
    such wrappers do exist, they might suffer serious disadvantages compared
    to making direct calls to operation-system specific functions that
    aren't POSIX compatible. When that is the case, it's very likely that
    the code was not written to use such wrappers.

    ... POSIX is not the be-all and end-all of operating systems.

    You’re right. It’s not. Linux is.

    I've been programming on Unix-like operating systems for more than 30
    years, and most of that time was on Linux systems, but even I'm not
    foolish enough to make such a claim for Linux. The last few years before
    I retired I worked on Windows systems doing maintenance on huge code
    bases that were required to work on both Windows and Linux systems. They
    didn't do so by being written to use only POSIX functionality, and rely
    upon POSIX-compatible wrappers on to work on Windows systems. They
    relied upon non-POSIX functions that did different things on POSIX and
    Windows systems. The code was built quite differently on the two
    operating systems - CMake was involved. I don't know a lot of the
    details of how all of that worked, my assigned tasks kept me far away
    from that part of the code - but I was aware of the complications that
    it caused for building the software.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to Malcolm McLean on Sat Jun 8 01:54:56 2024
    On 2024-06-07, Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
    On 07/06/2024 21:04, Scott Lurndal wrote:
    How does your pure "C" shell
    spawn a new process without using posix or other OS-specific
    APIs?

    It can call "system".

    I gather that you insist on using C90, so I'll quote from the C90
    standard, but everything I'm about to say is equally a problem with the
    current C standard:

    7.10.4.5:

    "Description
    The system function passes the string pointed to by string to the host environment to be executed by a command processor in an
    implementation-defined manner. A null pointer may be used for string to
    inquire whether a command processor exists.

    Returns
    If the argument is a null pointer, the system function returns nonzero
    only if a command processor is available. If the argument is not a null pointer, the system function returns an implementation-defined value."

    Note in particular: whether the system even has a a command processor
    depends upon the operating system. The manner in which the command
    string is processed and the meaning of system()'s nonzero return values
    depend upon the operating system as well, though the C implementation is required to document it. There's no way to write portable C code that
    calls system().

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to James Kuyper on Sat Jun 8 08:21:52 2024
    On Sat, 8 Jun 2024 01:40:48 -0400, James Kuyper wrote:

    On 6/7/24 19:59, Lawrence D'Oliveiro wrote:

    On Fri, 7 Jun 2024 09:32:26 -0400, James Kuyper wrote:

    ... POSIX is not the be-all and end-all of operating systems.

    You’re right. It’s not. Linux is.

    ... even I'm not foolish enough to make such a claim for Linux.

    I wouldn’t have been either, say, 20 years ago. But it’s now become quite clear that it dominates everywhere except the desktop. And if you think of fully-featured “workstation” OSes instead of cut-down “desktop” OSes, then
    Linux dominates there, too.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Chris M. Thomasson on Sat Jun 8 08:24:48 2024
    On Fri, 7 Jun 2024 23:35:26 -0700, Chris M. Thomasson wrote:

    nano might run a text editor... Or it might run something else... Fair enough?

    “Shall we play a little game?”

    But then, if you go via $EDITOR, you might still be invoking an
    Explosively Deadly Incendiary Tool Of Retribution.

    “Hey, your system isn’t standards-compliant.”

    “Tell it to the boss ... what’s left of him.”

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Malcolm McLean on Sat Jun 8 18:07:47 2024
    On 2024-06-08, Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
    On 08/06/2024 01:32, Kaz Kylheku wrote:
    Bug I take it that by shell you mean something which is primarily a
    command interpreter for driving an operating system, not an adventure
    game engine, or sophsticated programming language run-time.

    It calls system so that real users can use it for real.

    User wants to run their program in the background, and so using
    their knowledge of the host's actual shell, does this:

    > system ./simulation --duration 1h &

    Now what?

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael S@21:1/5 to Lawrence D'Oliveiro on Sat Jun 8 22:13:49 2024
    On Fri, 7 Jun 2024 23:57:58 -0000 (UTC)
    Lawrence D'Oliveiro <ldo@nz.invalid> wrote:

    On Fri, 7 Jun 2024 14:24:29 +0300, Michael S wrote:

    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);

    On Windows, that combines the command-line arguments into a single
    string. Which then has to be teased apart by the receiving program.
    Assuming the two ends can agree on consistent rules for doing so.

    You asked for something that is better *for user* than $EDITOR.
    The one above is very clearly better for user than $EDITOR.
    It is smarter - different editors are selected for different file types.
    And it achieves that with zero effort on part of app developer.
    I would be surprised if good Unices don't have something similar. But
    those better ways of lounching editor are not in POSIX.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Keith Thompson on Sun Jun 9 00:27:31 2024
    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/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Malcolm McLean on Sun Jun 9 03:30:51 2024
    On Sat, 8 Jun 2024 13:43:38 +0100, Malcolm McLean wrote:

    But it's just no good for consumer software. Ganes are no fun without
    sound. But it took about an afternoon to add fantastic audio to Baby X Windows, which inclues an MPEG codec, I just couldn't work out gow to do
    it on Linux in any way that wouln't break.

    I know this doesn’t help with your specific problem, but the fact is,
    Linux is making inroads in consumer software, particularly games, and that includes sound.

    Look at the Steam Deck. Even with WINE, its compatibility with Windows
    games is maybe only 50-60%. But that seems to be enough for it to sell, certainly encouraging enough for Valve to keep investing in it and
    bringing out revised, improved hardware.

    What’s the secret? It runs a purpose-built UI for handheld gaming.
    Microsoft has been demoing something called “Windows Handheld Mode” to try to respond to this, but even after two years, it still doesn’t have
    anything to ship.

    Meanwhile, the Steam Deck rivals like the Asus ROG Ally and MSI Claw are running regular Windows, and they are just so clunky by comparison,
    according to the reviews. Even with the 100% compatibility with Windows
    games that they can claim, they still don’t seem as attractive.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Michael S on Sun Jun 9 07:29:44 2024
    On Fri, 7 Jun 2024 14:24:29 +0300, Michael S wrote:

    ShellExecute(NULL, "edit", filename, NULL, NULL, SW_NORMAL);

    Would help to have some light shed on what the arguments mean <https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea>:

    From which I get

    ShellExecute
    (
    /*hwnd =*/ NULL,
    /*lpOperation =*/ "edit",
    /*lpFile =*/ filename,
    /*lpParameters =*/ NULL,
    /*lpDirectory =*/ NULL,
    /*nShowCmd =*/ SW_NORMAL
    );

    which makes things a bit clearer, doesn’t it? By the way, I love the explanation of what the returned value means ... an HINSTANCE which is
    not an HINSTANCE ...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Keith Thompson on Sun Jun 9 07:30:25 2024
    On Sat, 08 Jun 2024 13:51:30 -0700, Keith Thompson wrote:

    On Unix-like systems, xdg-open does something similar.

    But note that xdg-open is just a binary. It’s not part of any “system shell” or anything like that.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Michael S on Sun Jun 9 07:24:14 2024
    On Sat, 8 Jun 2024 22:13:49 +0300, Michael S wrote:

    On Fri, 7 Jun 2024 23:57:58 -0000 (UTC)
    Lawrence D'Oliveiro <ldo@nz.invalid> wrote:

    On Fri, 7 Jun 2024 14:24:29 +0300, Michael S wrote:

    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);

    On Windows, that combines the command-line arguments into a single
    string. Which then has to be teased apart by the receiving program.
    Assuming the two ends can agree on consistent rules for doing so.

    You asked for something that is better *for user* than $EDITOR.
    The one above is very clearly better for user than $EDITOR.

    Neglecting the various potential pitfalls in how the invocation works,
    fine.

    It is smarter - different editors are selected for different file types.
    And it achieves that with zero effort on part of app developer.

    If that’s what you want, then we have xdg-open for that <https://askubuntu.com/questions/1279623/what-is-xdg-open>.

    VISUAL and EDITOR are about editing text files, that’s all.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael S@21:1/5 to Lawrence D'Oliveiro on Sun Jun 9 11:36:04 2024
    On Sun, 9 Jun 2024 07:24:14 -0000 (UTC)
    Lawrence D'Oliveiro <ldo@nz.invalid> wrote:

    On Sat, 8 Jun 2024 22:13:49 +0300, Michael S wrote:

    On Fri, 7 Jun 2024 23:57:58 -0000 (UTC)
    Lawrence D'Oliveiro <ldo@nz.invalid> wrote:

    On Fri, 7 Jun 2024 14:24:29 +0300, Michael S wrote:

    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);

    On Windows, that combines the command-line arguments into a single
    string. Which then has to be teased apart by the receiving program.
    Assuming the two ends can agree on consistent rules for doing so.

    You asked for something that is better *for user* than $EDITOR.
    The one above is very clearly better for user than $EDITOR.

    Neglecting the various potential pitfalls in how the invocation
    works, fine.


    Imaginary pitfalls in this case. All you want to pass to editor is a
    file name. Pay attention how the 4th parameter in the call is NULL.

    It is smarter - different editors are selected for different file
    types. And it achieves that with zero effort on part of app
    developer.

    If that’s what you want, then we have xdg-open for that <https://askubuntu.com/questions/1279623/what-is-xdg-open>.


    Which is non-POSIX.
    Which was my point - there are not just "worthwhile" alternatives to
    POSIX ways, but obviously superior alternatives. Both on POSIX-compliant
    and on none-POSIX-compliant systems.

    VISUAL and EDITOR are about editing text files, that’s all.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Malcolm McLean on Sun Jun 9 14:28:32 2024
    Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
    On 08/06/2024 20:13, Michael S wrote:
    On Fri, 7 Jun 2024 23:57:58 -0000 (UTC)
    Lawrence D'Oliveiro <ldo@nz.invalid> wrote:

    On Fri, 7 Jun 2024 14:24:29 +0300, Michael S wrote:

    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);

    On Windows, that combines the command-line arguments into a single
    string. Which then has to be teased apart by the receiving program.
    Assuming the two ends can agree on consistent rules for doing so.

    You asked for something that is better *for user* than $EDITOR.
    The one above is very clearly better for user than $EDITOR.
    It is smarter - different editors are selected for different file types.
    And it achieves that with zero effort on part of app developer.
    I would be surprised if good Unices don't have something similar. But
    those better ways of lounching editor are not in POSIX.

    Yes. What you do is you call the shell with a option "-editor" which
    tells it which editor to use. That' beter than messing about with
    environment variables.

    No, it is not better than 'messing about with environment variables'.

    EDITOR specifies the user's desired editor on a system that provides
    dozens of possibilities.

    If one wishes to use the editor directly from the command line,
    they don't use the environment variable, they just type the
    appropriate command.

    EDITOR (and VISUAL) are intended for use by applications that need
    to invoke an editor at runtime and allow an application to
    automatically invoke the user's preferred editor without the
    user needing to do anything specific (e.g. a mail reading
    utility would use EDITOR/VISUAL to determine which editor
    to invoke).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to Malcolm McLean on Sun Jun 9 17:49:15 2024
    On 07/06/2024 20:38, Malcolm McLean wrote:
    On 07/06/2024 15:48, David Brown wrote:
    On 07/06/2024 12:46, Lawrence D'Oliveiro wrote:
    On Fri, 7 Jun 2024 11:31:01 +0200, David Brown wrote:

    But many people have lots of use of programming in C without any
    kind of
    POSIX functionality ...

    And all those same programs work in the presence of POSIX functionality, >>> plus you get access to a whole lot more besides.

    No, they do not.

    And even if POSIX functionality were "present", whatever you mean by
    that, it would be of no help to many C programs.


    The fact that cases keep arising where POSIX functionality would solve
    problems that are discussed in this group belies your point.

    There's no doubt that for some C programming, there are POSIX
    functions that could help.  And no doubt that this is the case for
    Malcolm's project.

    That does not in any way demonstrate that POSIX is required for all C
    programming, or that C is "essentially crippled" if POSIX is not
    available.

    Any idiot can write a shell using Posix.

    Only an idiot /would/ write a shell, unless they thought they could
    create something significantly better in some way than the multitude of existing shells.


    The whole point is to it in pure C. Without a single call to a function
    that isn't in the C standard library.

    That's not a point - that is /pointless/.

    There are two purposes to writing a program. One is for the fun or
    educational purposes of writing the program - and then you can pick
    whatever restrictions you want because it is purely for your own
    enjoyment, and it is not something that anyone will ever use. (And I
    believe fun is always a perfectly good reason for doing anything in this
    life, as long as it doesn't bother anyone else.)

    The other purpose is to make software that people can use. Writing
    something in "pure" long-outdated dialects of a language adds nothing to
    its use for other people. Will your shell be faster, use fewer
    resources, or have more features than bash, or zsh, or PowerShell, or
    any alternatives people already have? If not, it is pointless as a program.


    And make it fully functional. A real shell, that people will want to
    really use. That's my hobby project. I'm a free man now. I've got the
    time. I don't have to write code that makes money any more.


    You have the choice. You can write things that you want to write in the
    way you want to write them, simply for the fun of it. Or you can write
    things that people will use. Both are perfectly good ways to spend your
    time, and both can be rewarding. But don't kid yourself that you are
    writing a shell that people will use, or that it is better for potential
    users if you impose silly and arbitrary restrictions on the way you
    write your code. Be honest about what you are doing - it's a project
    you are working on for your own fun, and there is absolutely nothing
    wrong with that. You don't have to try to delude yourself to justify
    having a hobby!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Michael S on Sun Jun 9 22:29:46 2024
    On Sun, 9 Jun 2024 11:36:04 +0300, Michael S wrote:

    On Sun, 9 Jun 2024 07:24:14 -0000 (UTC)
    Lawrence D'Oliveiro <ldo@nz.invalid> wrote:

    If that’s what you want, then we have xdg-open for that
    <https://askubuntu.com/questions/1279623/what-is-xdg-open>.


    Which is non-POSIX.

    POSIX is not the end, but it is the starting point.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to Malcolm McLean on Mon Jun 10 14:12:25 2024
    On 10/06/2024 13:31, Malcolm McLean wrote:

    My shell can mount a FileSystem.xml file as a filing system and use that
    as backing store. No other shell can do that. That's why I need a shell. Because a shell is effectively an editor for a filing system.


    If this is an essential feature for the shell you want to use, and it is
    worth the effort writing it and all the limitations your shell has
    compared to existing shells, fair enough.

    Perhaps I am missing something, but I have yet to see a point in your "FileSystem.xml" in the first place, never mind a point in being able to
    treat it as a mounted filesystem where you can edit files directly.
    What does your shell give that a user could not do by unpacking the FileSystem.xml to a directory tree, working with the files using
    whatever tools they want, then packing them up again to a new version of
    the FileSystem.xml file?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Harnden@21:1/5 to Malcolm McLean on Mon Jun 10 18:14:09 2024
    On 10/06/2024 14:19, Malcolm McLean wrote:

    Well that's a way of doing it. But it's pretty inconvenient. The shell
    lets you edit a FileSystem, XML file in place. Then of course I've got
    to test bbx_filesystem.c very rigorously because it must work, it's the
    heart of BabyXFS. So by writing the shell, I flush out any problems with
    it.

    And of course now the fun part of the project comes in. I add MiniBasic
    to the shell, so you can run basic programs from it.


    I'd expect to run ksh commands from within ksh, bash commands from
    within bash, etc.

    I wouldn't expect a filesystem to be part of the shell at all.





    --
    This email has been checked for viruses by AVG antivirus software.
    www.avg.com

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Richard Harnden on Mon Jun 10 17:37:21 2024
    Richard Harnden <richard.nospam@gmail.invalid> writes:
    On 10/06/2024 14:19, Malcolm McLean wrote:

    Well that's a way of doing it. But it's pretty inconvenient. The shell
    lets you edit a FileSystem, XML file in place. Then of course I've got
    to test bbx_filesystem.c very rigorously because it must work, it's the
    heart of BabyXFS. So by writing the shell, I flush out any problems with
    it.

    And of course now the fun part of the project comes in. I add MiniBasic
    to the shell, so you can run basic programs from it.


    I'd expect to run ksh commands from within ksh, bash commands from
    within bash, etc.

    There's not much difference between them, and the vast majority
    of *nix commands aren't part of either shell, or the c shell variants,
    but rather just programs that happen to be located via $PATH.


    I wouldn't expect a filesystem to be part of the shell at all.

    Indeed. I've not yet understood the advantages of a purported XML filesystem.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Malcolm McLean on Tue Jun 11 05:52:02 2024
    On Tue, 11 Jun 2024 05:24:42 +0100, Malcolm McLean wrote:

    You embed the XML in the program as a string, and then mount an internal filesystem over it. So you can use stdio functions on internal data.

    Interestingly, Microsoft added a similar feature to PowerShell to let you browse the Windows Registry as though it were a filesystem.

    Of course, nobody is supposed to point out that representing system configuration as a bunch of (editable, text) files in a dedicated
    directory is exactly how *nix systems have been doing things since the
    early days...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to Malcolm McLean on Wed Jun 12 11:00:00 2024
    On 12/06/2024 10:08, Malcolm McLean wrote:
    On 10/06/2024 18:14, Richard Harnden wrote:
    On 10/06/2024 14:19, Malcolm McLean wrote:

    Well that's a way of doing it. But it's pretty inconvenient. The
    shell lets you edit a FileSystem, XML file in place. Then of course
    I've got to test bbx_filesystem.c very rigorously because it must
    work, it's the heart of BabyXFS. So by writing the shell, I flush out
    any problems with it.

    And of course now the fun part of the project comes in. I add
    MiniBasic to the shell, so you can run basic programs from it.


    I'd expect to run ksh commands from within ksh, bash commands from
    within bash, etc.

    I wouldn't expect a filesystem to be part of the shell at all.


    On 10/06/2024 18:14, Richard Harnden wrote:
    On 10/06/2024 14:19, Malcolm McLean wrote:

    Well that's a way of doing it. But it's pretty inconvenient. The shell
    lets you edit a FileSystem, XML file in place. Then of course I've got
    to test bbx_filesystem.c very rigorously because it must work, it's
    the heart of BabyXFS. So by writing the shell, I flush out any
    problems with it.

    And of course now the fun part of the project comes in. I add
    MiniBasic to the shell, so you can run basic programs from it.


    I'd expect to run ksh commands from within ksh, bash commands from
    within bash, etc.

    I wouldn't expect a filesystem to be part of the shell at all.



    You'd expect to have a FileSystem file, and to type in at your ksh orz
    zsh, cd "myfilesysyem.xml" and for ksh to mount it. But of course ksh
    can't do that, because it doesn't recognise that format. So you have to switch to the Baby X shell. And so your $ ksh promt is replaced by BBX$ prompt, to remind you that you are now in the Baby X shell and have a
    limited set of commands, though of course you have cd, ls, cp, mv, rm,
    edit invokes the text editor, and, though it doesn't do anything useful
    yet, bb runs the MiniBasic interpreter.

    And of course you also need "import" and "export" to transfer files int
    he FileSystem XML file to and from the host.

    And I've just written an ls which runs on a host computer, and that will become the ls command. Currently it just prints out a list of files in
    the current directory.

    The when that is done, the next challenge is to add a grep as an
    external command, not built into the shell like the other commands.

    Are you really intending to replicate the entire suite of common *nix
    command line programs with your own versions, just so that they can
    access the original data within your "filesystem xml" files?

    Do you think that people used to bash, or PowerShell, and all the
    command-line tools they use now and in the future, will be happy to swap
    that out for something akin to a weak copy of MS-DOS 2.0, just so that
    they can pretend your "filesystem xml" is like a directory? Seriously?

    I have yet to hear any realistic possible use of your "filesystem xml"
    format, but it seems blindingly obvious that the way it would be used in practice is for people to have their resource files in a normal
    directory with normal files. When they want to build an executable
    image with these files embedded, their build process (makefile, bat
    file, or whatever they like) will pack that directory into an xml file
    using your tools, then embed it within their executable image.

    If you /really/ believe that people will want to edit files within the
    xml file directly, as well as move data and files in and out of them,
    then there is a vastly better way to deal with that. Make a fuse
    filesystem wrapper, so that the /OS/ can treat it as a filesystem. Then
    people can use their normal shells, or editors, or gui programs, or
    whatever they want. I use fuse filesystems all the time on Linux (sshfs mounts), and I gather they are quite practical to implement on Linux and Windows. I'm sure there is an equivalent for Macs too.


    If you are doing all this for fun and a personal challenge, that's
    another matter - I'm fully supportive of that. But you write as though
    you think you are writing code that you think will be useful and
    important to other people, and that boggles the mind.

    (I can imagine that your "Baby X" gui toolkit and your "resource
    compiler" might have some interest to others - it's your shell and your "filesystem xml" that I am talking about here.)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From tTh@21:1/5 to Malcolm McLean on Wed Jun 12 12:37:11 2024
    On 6/12/24 10:08, Malcolm McLean wrote:

    I'd expect to run ksh commands from within ksh, bash commands from
    within bash, etc.

    I wouldn't expect a filesystem to be part of the shell at all.


    You'd expect to have a FileSystem file, and to type in at your ksh orz
    zsh, cd "myfilesysyem.xml" and for ksh to mount it. But of course ksh
    can't do that, because it doesn't recognise that format.

    Unless someone writes a module for fuse that allows this kind
    of manipulation.

    I've already come across this kind of thing, which made it
    possible to read images from floppy disks of old systems.

    --
    +---------------------------------------------------------------------+
    | https://tube.interhacker.space/a/tth/video-channels | +---------------------------------------------------------------------+

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Harnden@21:1/5 to Malcolm McLean on Wed Jun 12 13:43:51 2024
    On 12/06/2024 10:57, Malcolm McLean wrote:

    But yes, my view is the Baby X FileSystem is going to enhance Baby X and
    lift it to a new level. The ability to mount an internal filesystem in a small program is very useful indeed.


    Why?

    You have an xml file, which is just a text file, and you want to slurp
    that into your babyx - fine, so now you have a large char*.

    Now you want to 'mount' that.
    So you can opendir, readdir, ..., fopen something.

    All just so that you can fgets?
    Just so you can get a string out of a 'file'.
    A string you basically had a pointer to already.

    I'm sorry, but I just cannot see the point. Seems like you're making it
    way more complicated than it needs to be. I'm not sure why you think it
    needs to exist at all. Or why you think it's a good idea.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to Richard Harnden on Wed Jun 12 14:54:31 2024
    On 12/06/2024 14:43, Richard Harnden wrote:
    On 12/06/2024 10:57, Malcolm McLean wrote:

    But yes, my view is the Baby X FileSystem is going to enhance Baby X
    and lift it to a new level. The ability to mount an internal
    filesystem in a small program is very useful indeed.


    Why?

    You have an xml file, which is just a text file, and you want to slurp
    that into your babyx - fine, so now you have a large char*.

    Now you want to 'mount' that.
    So you can opendir, readdir, ..., fopen something.

    All just so that you can fgets?
    Just so you can get a string out of a 'file'.
    A string you basically had a pointer to already.

    I'm sorry, but I just cannot see the point.  Seems like you're making it
    way more complicated than it needs to be.  I'm not sure why you think it needs to exist at all.  Or why you think it's a good idea.



    Exactly my thoughts.

    I can appreciate wanting to do this for the fun of it, or the challenge
    of it. People have picked weirder things for their hobby projects.

    But I am at a loss to understand why Malcolm thinks this could possibly
    be /useful/ for anyone. We've had lots of "you want to be able to do
    this or that", without the slightest hint as to who "you" might be, or
    why "you" would want to do anything of the sort.

    And /if/ access to the contents of the xml file as individual files is important and useful, then libfuse would be a vastly more useful and
    powerful way to handle it.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to Malcolm McLean on Wed Jun 12 15:04:19 2024
    On 12/06/2024 13:10, Malcolm McLean wrote:
    On 12/06/2024 11:37, tTh wrote:
    On 6/12/24 10:08, Malcolm McLean wrote:

    I'd expect to run ksh commands from within ksh, bash commands from
    within bash, etc.

    I wouldn't expect a filesystem to be part of the shell at all.


    You'd expect to have a FileSystem file, and to type in at your ksh orz
    zsh, cd "myfilesysyem.xml" and for ksh to mount it. But of course ksh
    can't do that, because it doesn't recognise that format.

        Unless someone writes a module for fuse that allows this kind
        of manipulation.

        I've already come across this kind of thing, which made it
        possible to read images from floppy disks of old systems.

    I'd be interested in doing that. And may thnaks to David Brown for
    mentining that this isnpossible. However it wouldn't be part of Baby X.

    I had a quick look at the fuse webite, and I couldn't for the life of me
    work out how to write a short fuse script to mount such a simple
    directory structure as a FileSystem XML file.

    I'm sure it's possible and not too hard to do. But it's the sort of
    thing people do for money.


    I'm sure some people do it for money - but I think others make libfuse filesystems for fun. Typical uses include accessing remote data (such
    as over ssh, webdav, google drives), supporting weird, awkward or
    outdated filesystems (like NTFS), accessing data within packed or
    encrypted files (like zip files or backup files), prototyping
    filesystems that you hope will make it to the Linux kernel one day,
    exposing interfaces or control information like a file system, and so on.

    At its simplest, it's just a matter of implementing functions for
    listing a directory, opening and closing files, reading and writing
    them, and similar functions. I'd imagine that write support for files
    within your XML file would be awkward, but I would be very surprised if anything in a libfuse solution is at all harder than implementing the
    same thing in your shell.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)