From 443ddb509e71356e7530e056a304a4e1fb6ad9f4 Mon Sep 17 00:00:00 2001 From: axel Date: Sat, 17 Dec 2005 22:25:46 +1000 Subject: [PATCH] make the functions builtin output descriptions and event handlers for functions darcs-hash:20051217122546-ac50b-2bf9b1118fcbf9079398e113fb201ddde813e40a.gz --- builtin.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 79 insertions(+), 14 deletions(-) diff --git a/builtin.c b/builtin.c index 48410264f..745a09cfb 100644 --- a/builtin.c +++ b/builtin.c @@ -658,6 +658,82 @@ static int builtin_exec( wchar_t **argv ) return 1; } +static void functions_def( wchar_t *name ) +{ + const wchar_t *desc = function_get_desc( name ); + const wchar_t *def = function_get_definition(name); + + array_list_t ev; + event_t search; + + int i; + + search.function_name = name; + search.type = EVENT_ANY; + + al_init( &ev ); + event_get( &search, &ev ); + + sb_append2( sb_out, + L"function ", + name, + (void *)0); + + if( desc && wcslen(desc) ) + { + wchar_t *esc_desc = escape( desc, 1 ); + + sb_append2( sb_out, L" --description ", esc_desc, (void *)0 ); + free( esc_desc ); + } + + for( i=0; itype ) + { + case EVENT_SIGNAL: + { + sb_printf( sb_out, L" --on-signal %ls", sig2wcs( next->param1.signal ) ); + break; + } + + case EVENT_VARIABLE: + { + sb_printf( sb_out, L" --on-variable %ls", next->param1.variable ); + break; + } + + case EVENT_EXIT: + { + if( next->param1.pid > 0 ) + sb_printf( sb_out, L" --on-process-exit %d", next->param1.pid ); + else + sb_printf( sb_out, L" --on-job-exit %d", -next->param1.pid ); + break; + } + + case EVENT_JOB_ID: + { + job_t *j = job_get( next->param1.job_id ); + if( j ) + sb_printf( sb_out, L" --on-job-exit %d", j->pgid ); + break; + } + + } + + } + + al_destroy( &ev ); + + sb_append2( sb_out, + L"\n\t", + def, + L"\nend\n\n", + (void *)0); +} + /** The functions builtin, used for listing and erasing functions. @@ -847,13 +923,8 @@ static int builtin_functions( wchar_t **argv ) (int (*)(const void *, const void *))&wcsfilecmp ); for( i=0; i