mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-23 01:24:23 +08:00
Cleanup event_get_desc
This commit is contained in:
parent
1bbe901bcd
commit
b3d0561c09
39
event.cpp
39
event.cpp
|
@ -25,8 +25,6 @@
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "signal.h"
|
#include "signal.h"
|
||||||
|
|
||||||
#include "halloc_util.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Number of signals that can be queued before an overflow occurs
|
Number of signals that can be queued before an overflow occurs
|
||||||
*/
|
*/
|
||||||
|
@ -181,48 +179,35 @@ static int event_is_blocked( event_t *e )
|
||||||
return event_block_list_blocks_type(parser.global_event_blocks, e->type);
|
return event_block_list_blocks_type(parser.global_event_blocks, e->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
const wchar_t *event_get_desc( event_t *e )
|
wcstring event_get_desc( event_t *e )
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
|
||||||
String buffer used for formating event descriptions in event_get_desc()
|
|
||||||
*/
|
|
||||||
static string_buffer_t *get_desc_buff=0;
|
|
||||||
|
|
||||||
CHECK( e, 0 );
|
CHECK( e, 0 );
|
||||||
|
|
||||||
if( !get_desc_buff )
|
wcstring result;
|
||||||
{
|
|
||||||
get_desc_buff=sb_halloc( global_context );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sb_clear( get_desc_buff );
|
|
||||||
}
|
|
||||||
|
|
||||||
switch( e->type )
|
switch( e->type )
|
||||||
{
|
{
|
||||||
|
|
||||||
case EVENT_SIGNAL:
|
case EVENT_SIGNAL:
|
||||||
sb_printf( get_desc_buff, _(L"signal handler for %ls (%ls)"), sig2wcs(e->param1.signal ), signal_get_desc( e->param1.signal ) );
|
result = format_string(_(L"signal handler for %ls (%ls)"), sig2wcs(e->param1.signal ), signal_get_desc( e->param1.signal ));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVENT_VARIABLE:
|
case EVENT_VARIABLE:
|
||||||
sb_printf( get_desc_buff, _(L"handler for variable '%ls'"), e->param1.variable );
|
result = format_string(_(L"handler for variable '%ls'"), e->param1.variable );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVENT_EXIT:
|
case EVENT_EXIT:
|
||||||
if( e->param1.pid > 0 )
|
if( e->param1.pid > 0 )
|
||||||
{
|
{
|
||||||
sb_printf( get_desc_buff, _(L"exit handler for process %d"), e->param1.pid );
|
result = format_string(_(L"exit handler for process %d"), e->param1.pid );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
job_t *j = job_get_from_pid( -e->param1.pid );
|
job_t *j = job_get_from_pid( -e->param1.pid );
|
||||||
if( j )
|
if( j )
|
||||||
sb_printf( get_desc_buff, _(L"exit handler for job %d, '%ls'"), j->job_id, j->command_cstr() );
|
result = format_string(_(L"exit handler for job %d, '%ls'"), j->job_id, j->command_cstr() );
|
||||||
else
|
else
|
||||||
sb_printf( get_desc_buff, _(L"exit handler for job with process group %d"), -e->param1.pid );
|
result = format_string(_(L"exit handler for job with process group %d"), -e->param1.pid );
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -231,24 +216,24 @@ const wchar_t *event_get_desc( event_t *e )
|
||||||
{
|
{
|
||||||
job_t *j = job_get( e->param1.job_id );
|
job_t *j = job_get( e->param1.job_id );
|
||||||
if( j )
|
if( j )
|
||||||
sb_printf( get_desc_buff, _(L"exit handler for job %d, '%ls'"), j->job_id, j->command_cstr() );
|
result = format_string(_(L"exit handler for job %d, '%ls'"), j->job_id, j->command_cstr() );
|
||||||
else
|
else
|
||||||
sb_printf( get_desc_buff, _(L"exit handler for job with job id %d"), j->job_id );
|
result = format_string(_(L"exit handler for job with job id %d"), j->job_id );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EVENT_GENERIC:
|
case EVENT_GENERIC:
|
||||||
sb_printf( get_desc_buff, _(L"handler for generic event '%ls'"), e->param1.param );
|
result = format_string(_(L"handler for generic event '%ls'"), e->param1.param );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
sb_printf( get_desc_buff, _(L"Unknown event type") );
|
result = format_string(_(L"Unknown event type") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (const wchar_t *)get_desc_buff->buff;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
5
event.h
5
event.h
|
@ -157,10 +157,9 @@ void event_destroy();
|
||||||
void event_free( event_t *e );
|
void event_free( event_t *e );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns a string describing the specified event. The string should
|
Returns a string describing the specified event.
|
||||||
not be freed.
|
|
||||||
*/
|
*/
|
||||||
const wchar_t *event_get_desc( event_t *e );
|
wcstring event_get_desc( event_t *e );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fire a generic event with the specified name
|
Fire a generic event with the specified name
|
||||||
|
|
|
@ -881,7 +881,8 @@ void parser_t::stack_trace( block_t *b, string_buffer_t *buff)
|
||||||
/*
|
/*
|
||||||
This is an event handler
|
This is an event handler
|
||||||
*/
|
*/
|
||||||
sb_printf( buff, _(L"in event handler: %ls\n"), event_get_desc( b->state1<event_t *>() ));
|
wcstring description = event_get_desc( b->state1<event_t *>() );
|
||||||
|
sb_printf( buff, _(L"in event handler: %ls\n"), description.c_str());
|
||||||
sb_printf( buff,
|
sb_printf( buff,
|
||||||
L"\n" );
|
L"\n" );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user