API documentation, code style cleanup, etc.

darcs-hash:20060220131146-ac50b-6ec3664e5e3eaefa2296a93d39014058df37fdf2.gz
This commit is contained in:
axel 2006-02-20 23:11:46 +10:00
parent ea0005e16d
commit 6b544bc3c2
4 changed files with 73 additions and 32 deletions

View File

@ -143,7 +143,9 @@ void set_color( int c, int c2 )
{ {
c = c2 = FISH_COLOR_NORMAL; c = c2 = FISH_COLOR_NORMAL;
if( fg ) if( fg )
{
writembs( tparm( fg, 0 ) ); writembs( tparm( fg, 0 ) );
}
writembs( exit_attribute_mode ); writembs( exit_attribute_mode );
return; return;
} }
@ -203,12 +205,14 @@ void set_color( int c, int c2 )
if( c==FISH_COLOR_NORMAL ) if( c==FISH_COLOR_NORMAL )
{ {
if( fg ) if( fg )
{
writembs( tparm( fg, 0 ) ); writembs( tparm( fg, 0 ) );
}
writembs( exit_attribute_mode ); writembs( exit_attribute_mode );
last_color2 = FISH_COLOR_NORMAL; last_color2 = FISH_COLOR_NORMAL;
} }
else if( ( c >= 0) && ( c < FISH_COLOR_NORMAL ) ) else if( ( c >= 0 ) && ( c < FISH_COLOR_NORMAL ) )
{ {
if( fg ) if( fg )
{ {
@ -228,15 +232,15 @@ void set_color( int c, int c2 )
writembs( tparm( bg, 0 ) ); writembs( tparm( bg, 0 ) );
} }
writembs(exit_attribute_mode); writembs( exit_attribute_mode );
if(( last_color != FISH_COLOR_NORMAL ) && fg ) if( ( last_color != FISH_COLOR_NORMAL ) && fg )
{ {
writembs(tparm( fg, last_color )); writembs( tparm( fg, last_color ) );
} }
last_color2 = c2; last_color2 = c2;
} }
else if ((c2 >= 0 ) &&(c2 < FISH_COLOR_NORMAL)) else if ( ( c2 >= 0 ) && ( c2 < FISH_COLOR_NORMAL ) )
{ {
if( bg ) if( bg )
{ {
@ -290,7 +294,9 @@ int writembs( char *str )
{ {
#ifdef TPUTS_KLUDGE #ifdef TPUTS_KLUDGE
while( *str ) while( *str )
{
out( *str ); out( *str );
}
#else #else
tputs(str,1,writeb); tputs(str,1,writeb);
#endif #endif
@ -305,7 +311,9 @@ int writech( wint_t ch )
int i; int i;
for( i=0; i<bytes; i++ ) for( i=0; i<bytes; i++ )
{
out( buff[i] ); out( buff[i] );
}
return 0; return 0;
} }
@ -335,14 +343,15 @@ void writestr( const wchar_t *str )
if( writestr_buff_sz < len ) if( writestr_buff_sz < len )
{ {
if( !writestr_buff ) if( !writestr_buff )
{
halloc_register_function_void( global_context, &output_destroy ); halloc_register_function_void( global_context, &output_destroy );
}
writestr_buff = realloc( writestr_buff, len ); writestr_buff = realloc( writestr_buff, len );
if( !writestr_buff ) if( !writestr_buff )
{
die_mem(); die_mem();
}
writestr_buff_sz = len; writestr_buff_sz = len;
} }
@ -357,8 +366,9 @@ void writestr( const wchar_t *str )
Write Write
*/ */
for( pos = writestr_buff; *pos; pos++ ) for( pos = writestr_buff; *pos; pos++ )
{
out( *pos ); out( *pos );
}
} }
@ -377,7 +387,9 @@ void writestr_ellipsis( const wchar_t *str, int max_width )
{ {
int w = wcwidth( *str ); int w = wcwidth( *str );
if( written+w+wcwidth( ellipsis_char )>max_width ) if( written+w+wcwidth( ellipsis_char )>max_width )
{
break; break;
}
written+=w; written+=w;
writech( *(str++) ); writech( *(str++) );
} }
@ -438,7 +450,9 @@ int writespace( int c )
int i; int i;
for( i=0; i<c; i++ ) for( i=0; i<c; i++ )
{
out( ' ' ); out( ' ' );
}
} }
return 0; return 0;
} }
@ -458,7 +472,11 @@ int output_color_code( const wchar_t *val )
} }
if( color >= 0 ) if( color >= 0 )
{
return color; return color;
}
else else
{
return FISH_COLOR_NORMAL; return FISH_COLOR_NORMAL;
}
} }

View File

@ -133,7 +133,9 @@ int writeb( tputs_arg_t b );
/** /**
Set the function used for writing in move_cursor, writespace and Set the function used for writing in move_cursor, writespace and
set_color. By default, writembs is used. set_color and all other output functions in this library. By
default, the write call is used to give completely unbuffered
output to stdout.
*/ */
void output_set_writer( int (*writer)(char) ); void output_set_writer( int (*writer)(char) );

View File

@ -345,8 +345,6 @@ void parser_push_block( int type )
new->src_lineno = parser_get_lineno(); new->src_lineno = parser_get_lineno();
new->src_filename = parser_current_filename()?intern(parser_current_filename()):0; new->src_filename = parser_current_filename()?intern(parser_current_filename()):0;
// debug( 3, L"Block push %ls %d\n", parser_get_block_desc(type), block_count( current_block)+1 );
new->outer = current_block; new->outer = current_block;
new->type = (current_block && current_block->skip)?FAKE:type; new->type = (current_block && current_block->skip)?FAKE:type;
@ -357,9 +355,13 @@ void parser_push_block( int type )
*/ */
new->skip=current_block?current_block->skip:0; new->skip=current_block?current_block->skip:0;
if( type == TOP || type == SUBST ) if( type == TOP || type == SUBST )
{
new->skip = 0; new->skip = 0;
}
if( type == FAKE ) if( type == FAKE )
{
new->skip = 1; new->skip = 1;
}
new->job = 0; new->job = 0;
new->loop_status=LOOP_NORMAL; new->loop_status=LOOP_NORMAL;
@ -759,7 +761,9 @@ wchar_t *get_filename( const wchar_t *cmd )
if( wstat( new_cmd, &buff )==-1 ) if( wstat( new_cmd, &buff )==-1 )
{ {
if( errno != EACCES ) if( errno != EACCES )
{
wperror( L"stat" ); wperror( L"stat" );
}
continue; continue;
} }
if( S_ISREG(buff.st_mode) ) if( S_ISREG(buff.st_mode) )
@ -778,10 +782,12 @@ wchar_t *get_filename( const wchar_t *cmd )
case ENOTDIR: case ENOTDIR:
break; break;
default: default:
{
debug( 1, debug( 1,
MISSING_COMMAND_ERR_MSG, MISSING_COMMAND_ERR_MSG,
new_cmd ); new_cmd );
wperror( L"access" ); wperror( L"access" );
}
} }
} }
} }
@ -814,8 +820,10 @@ static void print_profile( array_list_t *p,
int my_time; int my_time;
if( pos >= al_get_count( p ) ) if( pos >= al_get_count( p ) )
{
return; return;
}
me= (profile_element_t *)al_get( p, pos ); me= (profile_element_t *)al_get( p, pos );
if( !me->skipped ) if( !me->skipped )
{ {
@ -825,12 +833,20 @@ static void print_profile( array_list_t *p,
{ {
prev = (profile_element_t *)al_get( p, i ); prev = (profile_element_t *)al_get( p, i );
if( prev->skipped ) if( prev->skipped )
{
continue; continue;
}
if( prev->level <= me->level ) if( prev->level <= me->level )
{
break; break;
}
if( prev->level > me->level+1 ) if( prev->level > me->level+1 )
{
continue; continue;
}
my_time -= prev->parse; my_time -= prev->parse;
my_time -= prev->exec; my_time -= prev->exec;
} }
@ -931,26 +947,20 @@ int eval_args( const wchar_t *line, array_list_t *args )
switch(tok_last_type( &tok ) ) switch(tok_last_type( &tok ) )
{ {
case TOK_STRING: case TOK_STRING:
switch( expand_string( 0, wcsdup(tok_last( &tok )), args, 0 ) ) {
if( expand_string( 0, wcsdup(tok_last( &tok )), args, 0 ) == EXPAND_ERROR )
{ {
case EXPAND_ERROR: err_pos=tok_get_pos( &tok );
{ do_loop=0;
err_pos=tok_get_pos( &tok );
do_loop=0;
break;
}
default:
{
break;
}
} }
break; break;
}
case TOK_END: case TOK_END:
{
break; break;
}
case TOK_ERROR: case TOK_ERROR:
{ {
error( SYNTAX_ERROR, error( SYNTAX_ERROR,
@ -963,6 +973,7 @@ int eval_args( const wchar_t *line, array_list_t *args )
} }
default: default:
{
error( SYNTAX_ERROR, error( SYNTAX_ERROR,
tok_get_pos( &tok ), tok_get_pos( &tok ),
UNEXPECTED_TOKEN_ERR_MSG, UNEXPECTED_TOKEN_ERR_MSG,
@ -970,6 +981,7 @@ int eval_args( const wchar_t *line, array_list_t *args )
do_loop=0; do_loop=0;
break; break;
}
} }
} }
@ -1003,27 +1015,37 @@ void parser_stack_trace( block_t *b, string_buffer_t *buff)
switch( b->type) switch( b->type)
{ {
case SOURCE: case SOURCE:
{
sb_printf( buff, _(L"in . (source) call of file '%ls',\n"), b->param1.source_dest ); sb_printf( buff, _(L"in . (source) call of file '%ls',\n"), b->param1.source_dest );
break; break;
}
case FUNCTION_CALL: case FUNCTION_CALL:
{
sb_printf( buff, _(L"in function '%ls',\n"), b->param1.function_name ); sb_printf( buff, _(L"in function '%ls',\n"), b->param1.function_name );
break; break;
}
case SUBST: case SUBST:
{
sb_printf( buff, _(L"in command substitution\n") ); sb_printf( buff, _(L"in command substitution\n") );
break; break;
}
} }
const wchar_t *file = b->src_filename; const wchar_t *file = b->src_filename;
if( file ) if( file )
{
sb_printf( buff, sb_printf( buff,
_(L"\tcalled on line %d of file '%ls',\n"), _(L"\tcalled on line %d of file '%ls',\n"),
b->src_lineno, b->src_lineno,
file ); file );
}
else else
{
sb_printf( buff, sb_printf( buff,
_(L"\tcalled on standard input,\n") ); _(L"\tcalled on standard input,\n") );
}
if( b->type == FUNCTION_CALL ) if( b->type == FUNCTION_CALL )
{ {
if( b->param2.function_call_process->argv[1] ) if( b->param2.function_call_process->argv[1] )
@ -1975,7 +1997,7 @@ static int parse_job( process_t *p,
current_tokenizer_pos = tok_get_pos(tok); current_tokenizer_pos = tok_get_pos(tok);
fwprintf( stderr, L"%ls", parser_current_line() ); fwprintf( stderr, L"%ls", parser_current_line() );
current_tokenizer_pos=tmp; current_tokenizer_pos=tmp;
j->skip=1; j->skip=1;

1
proc.h
View File

@ -298,7 +298,6 @@ int job_reap( int interactive );
*/ */
void job_handle_signal( int signal, siginfo_t *info, void *con ); void job_handle_signal( int signal, siginfo_t *info, void *con );
#ifdef HAVE__PROC_SELF_STAT #ifdef HAVE__PROC_SELF_STAT
/** /**
Use the procfs filesystem to look up how many jiffies of cpu time Use the procfs filesystem to look up how many jiffies of cpu time