Sujet : Re: Running an editor from ANSI C
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.cDate : 07. Jun 2024, 18:56:47
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v3vhl0$25r3d$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
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