Added some missing calls to setup_fork_guards() in utilities.

Made echo a builtin
This commit is contained in:
ridiculousfish 2012-03-07 11:35:22 -08:00
parent 8ed20f3c28
commit ce859c9e92
7 changed files with 40 additions and 4 deletions

View file

@ -1442,7 +1442,32 @@ static int builtin_functions( parser_t &parser, wchar_t **argv )
}
return res;
}
/** The echo builtin.
bash only respects -n if it's the first argument. We'll do the same. */
static int builtin_echo( parser_t &parser, wchar_t **argv )
{
/* Skip first arg */
if (! *argv++)
return STATUS_BUILTIN_ERROR;
/* Process -n */
bool show_newline = true;
if (*argv && ! wcscmp(*argv, L"-n")) {
show_newline = false;
argv++;
}
for (size_t idx = 0; argv[idx]; idx++) {
if (idx > 0)
stdout_buffer.push_back(' ');
stdout_buffer.append(argv[idx]);
}
if (show_newline)
stdout_buffer.push_back('\n');
return STATUS_BUILTIN_OK;
}
@ -3562,6 +3587,7 @@ static const builtin_data_t builtin_datas[]=
{ L"contains", &builtin_contains, N_( L"Search for a specified string in a list" ) },
{ L"continue", &builtin_break_continue, N_( L"Skip the rest of the current lap of the innermost loop" ) },
{ L"count", &builtin_count, N_( L"Count the number of arguments" ) },
{ L"echo", &builtin_echo, N_( L"Print arguments" ) },
{ L"else", &builtin_else, N_( L"Evaluate block if condition is false" ) },
{ L"emit", &builtin_emit, N_( L"Emit an event" ) },
{ L"end", &builtin_end, N_( L"End a block of commands" ) },

View file

@ -1238,8 +1238,12 @@ void exec( parser_t &parser, job_t *j )
const char *actual_cmd = actual_cmd_str.c_str();
const wchar_t *reader_current_filename();
if (g_log_forks)
if (g_log_forks) {
printf("forking for '%s' in '%ls'\n", actual_cmd, reader_current_filename());
if (std::string(actual_cmd) == "/usr/bin/getopt") {
puts("wat");
}
}
pid = execute_fork(true /* must drain threads */);
if( pid == 0 )
{

View file

@ -279,7 +279,9 @@ static void trim( wcstring &str )
int main( int argc, char **argv )
{
int do_indent=1;
set_main_thread();
set_main_thread();
setup_fork_guards();
wsetlocale( LC_ALL, L"" );
program_name=L"fish_indent";

View file

@ -1190,7 +1190,9 @@ int main( int argc, char **argv )
int mangle_descriptors = 0;
int result_fd = -1;
set_main_thread();
set_main_thread();
setup_fork_guards();
/*
This initialization is made early, so that the other init code
can use global_context for memory managment

View file

@ -827,6 +827,7 @@ int main( int argc, char ** argv )
fd_set read_fd, write_fd;
set_main_thread();
setup_fork_guards();
program_name=L"fishd";
wsetlocale( LC_ALL, L"" );

View file

@ -28,6 +28,7 @@ int writestr( char *str )
int main( int argc, char **argv)
{
set_main_thread();
setup_fork_guards();
setlocale( LC_ALL, "" );

View file

@ -227,7 +227,7 @@ function __fish_config_interactive -d "Initializations that should be performed
end
else
# Ubuntu Feisty places this command in the regular path instead
if type -p command-not-found >/dev/null
if which command-not-found >/dev/null
function fish_command_not_found_handler --on-event fish_command_not_found
command-not-found $argv
end