mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Move out argument parsing into it's own function
darcs-hash:20061025205443-ac50b-2889624cadb3b92be13da523df32b178c773dbf7.gz
This commit is contained in:
parent
3a128e1484
commit
1faf7df371
1 changed files with 29 additions and 18 deletions
47
main.c
47
main.c
|
@ -122,24 +122,12 @@ static int read_init()
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Calls a bunch of init functions, parses the init files and then
|
|
||||||
parses commands from stdin or files, depending on arguments
|
|
||||||
*/
|
|
||||||
|
|
||||||
int main( int argc, char **argv )
|
static int fish_parse_opt( int argc, char **argv, char **cmd_ptr )
|
||||||
{
|
{
|
||||||
int res=1;
|
|
||||||
int force_interactive=0;
|
|
||||||
int my_optind;
|
int my_optind;
|
||||||
|
int force_interactive=0;
|
||||||
|
|
||||||
char *cmd=0;
|
|
||||||
|
|
||||||
halloc_util_init();
|
|
||||||
|
|
||||||
wsetlocale( LC_ALL, L"" );
|
|
||||||
is_interactive_session=1;
|
|
||||||
program_name=L"fish";
|
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
|
@ -204,7 +192,7 @@ int main( int argc, char **argv )
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
{
|
{
|
||||||
cmd = optarg;
|
*cmd_ptr = optarg;
|
||||||
is_interactive_session = 0;
|
is_interactive_session = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -227,7 +215,7 @@ int main( int argc, char **argv )
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
{
|
{
|
||||||
cmd = "help";
|
*cmd_ptr = "help";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +254,7 @@ int main( int argc, char **argv )
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
{
|
{
|
||||||
return 1;
|
exit( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -276,11 +264,34 @@ int main( int argc, char **argv )
|
||||||
|
|
||||||
is_login |= (strcmp( argv[0], "-fish") == 0);
|
is_login |= (strcmp( argv[0], "-fish") == 0);
|
||||||
|
|
||||||
is_interactive_session &= (cmd == 0);
|
is_interactive_session &= (*cmd_ptr == 0);
|
||||||
is_interactive_session &= (my_optind == argc);
|
is_interactive_session &= (my_optind == argc);
|
||||||
is_interactive_session &= isatty(STDIN_FILENO);
|
is_interactive_session &= isatty(STDIN_FILENO);
|
||||||
is_interactive_session |= force_interactive;
|
is_interactive_session |= force_interactive;
|
||||||
|
|
||||||
|
return my_optind;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Calls a bunch of init functions, parses the init files and then
|
||||||
|
parses commands from stdin or files, depending on arguments
|
||||||
|
*/
|
||||||
|
|
||||||
|
int main( int argc, char **argv )
|
||||||
|
{
|
||||||
|
int res=1;
|
||||||
|
char *cmd=0;
|
||||||
|
int my_optind=0;
|
||||||
|
|
||||||
|
halloc_util_init();
|
||||||
|
|
||||||
|
wsetlocale( LC_ALL, L"" );
|
||||||
|
is_interactive_session=1;
|
||||||
|
program_name=L"fish";
|
||||||
|
|
||||||
|
my_optind = fish_parse_opt( argc, argv, &cmd );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
No-exec is prohibited when in interactive mode
|
No-exec is prohibited when in interactive mode
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue