diff --git a/builtin.c b/builtin.c
index 018507ff7..7b0250445 100644
--- a/builtin.c
+++ b/builtin.c
@@ -6,15 +6,15 @@
1). Create a function in builtin.c with the following signature:
static int builtin_NAME( wchar_t ** args )
-
- where NAME is the name of the builtin, and args is a zero-terminated list of arguments.
+
+ where NAME is the name of the builtin, and args is a zero-terminated list of arguments.
2). Add a line like hash_put( &builtin, L"NAME", &builtin_NAME ); to builtin_init. This will enable the parser to find the builtin function.
3). Add a line like hash_put( desc, L"NAME", _(L"Bla bla bla") ); to the proper part of builtin_get_desc, containing a short description of what the builtin does. This description is used by the completion system.
4). Create a file doc_src/NAME.txt, containing the manual for the builtin in Doxygen-format. Check the other builtin manuals for proper syntax.
-
+
5). Add an entry to the BUILTIN_DOC_SRC variable of Makefile.in. Note that the entries should be sorted alphabetically!
6). Add an entry to the manual at the builtin-overview subsection. Note that the entries should be sorted alphabetically!
@@ -109,7 +109,7 @@ string_buffer_t *sb_out=0, *sb_err=0;
*/
static array_list_t io_stack;
-/**
+/**
The file from which builtin functions should attempt to read, use
instead of stdin.
*/
@@ -141,9 +141,9 @@ void builtin_wperror( const wchar_t *s)
wchar_t *werr = str2wcs( err );
if( werr )
{
- sb_append2( sb_err, werr, L"\n", (void *)0 );
+ sb_append2( sb_err, werr, L"\n", (void *)0 );
free( werr );
- }
+ }
}
@@ -176,7 +176,7 @@ void builtin_print_help( wchar_t *cmd, string_buffer_t *b )
if( b == sb_err )
{
- sb_append( sb_err,
+ sb_append( sb_err,
parser_current_line() );
}
@@ -185,8 +185,8 @@ void builtin_print_help( wchar_t *cmd, string_buffer_t *b )
if( !h )
return;
-
-
+
+
wchar_t *str = str2wcs(builtin_help_get( cmd ));
if( str )
{
@@ -201,34 +201,34 @@ static int builtin_bind( wchar_t **argv )
{
int i;
int argc=builtin_count_args( argv );
-
+
woptind=0;
const static struct woption
long_options[] =
{
{
- L"set-mode", required_argument, 0, 'M'
+ L"set-mode", required_argument, 0, 'M'
}
,
- {
- 0, 0, 0, 0
+ {
+ 0, 0, 0, 0
}
}
- ;
-
+ ;
+
while( 1 )
{
int opt_index = 0;
-
+
int opt = wgetopt_long( argc,
- argv,
- L"M:",
- long_options,
+ argv,
+ L"M:",
+ long_options,
&opt_index );
if( opt == -1 )
break;
-
+
switch( opt )
{
case 0:
@@ -237,33 +237,33 @@ static int builtin_bind( wchar_t **argv )
sb_printf( sb_err,
BUILTIN_ERR_UNKNOWN,
argv[0],
- long_options[opt_index].name );
+ long_options[opt_index].name );
builtin_print_help( argv[0], sb_err );
-
+
return 1;
-
- case 'M':
+
+ case 'M':
input_set_mode( woptarg );
break;
case '?':
builtin_print_help( argv[0], sb_err );
-
+
return 1;
-
+
}
-
- }
+
+ }
for( i=woptind; itype = type;
switch( scope )
@@ -413,11 +413,11 @@ static int builtin_block( wchar_t **argv )
{
eb->next = global_event_block;
global_event_block=eb;
- }
+ }
}
return 0;
-
+
}
/**
@@ -427,38 +427,38 @@ static int builtin_builtin( wchar_t **argv )
{
int argc=builtin_count_args( argv );
int list=0;
-
+
woptind=0;
const static struct woption
long_options[] =
{
{
- L"names", no_argument, 0, 'n'
+ L"names", no_argument, 0, 'n'
}
,
{
- L"help", no_argument, 0, 'h'
+ L"help", no_argument, 0, 'h'
}
,
- {
- 0, 0, 0, 0
+ {
+ 0, 0, 0, 0
}
}
- ;
-
+ ;
+
while( 1 )
{
int opt_index = 0;
-
+
int opt = wgetopt_long( argc,
- argv,
- L"nh",
- long_options,
+ argv,
+ L"nh",
+ long_options,
&opt_index );
if( opt == -1 )
break;
-
+
switch( opt )
{
case 0:
@@ -469,52 +469,52 @@ static int builtin_builtin( wchar_t **argv )
argv[0],
long_options[opt_index].name );
builtin_print_help( argv[0], sb_err );
-
-
+
+
return 1;
case 'h':
builtin_print_help( argv[0], sb_err );
return 0;
-
+
case 'n':
list=1;
break;
-
+
case '?':
builtin_print_help( argv[0], sb_err );
-
+
return 1;
-
+
}
-
- }
+
+ }
if( list )
{
array_list_t names;
wchar_t **names_arr;
int i;
-
+
al_init( &names );
builtin_get_names( &names );
names_arr = list_to_char_arr( &names );
- qsort( names_arr,
- al_get_count( &names ),
- sizeof(wchar_t *),
+ qsort( names_arr,
+ al_get_count( &names ),
+ sizeof(wchar_t *),
(int (*)(const void *, const void *))&wcsfilecmp );
for( i=0; itype = EVENT_SIGNAL;
e->param1.signal = sig;
- e->function_name=0;
+ e->function_name=0;
al_push( events, e );
- break;
+ break;
}
-
+
case 'v':
{
event_t *e;
if( !wcsvarname( woptarg ) )
{
- sb_printf( sb_err,
+ sb_printf( sb_err,
_( L"%ls: Invalid variable name '%ls'\n" ),
argv[0],
woptarg );
res=1;
break;
}
-
+
e = calloc( 1, sizeof(event_t));
if( !e )
die_mem();
e->type = EVENT_VARIABLE;
e->param1.variable = wcsdup( woptarg );
- e->function_name=0;
+ e->function_name=0;
al_push( events, e );
break;
}
-
+
case 'j':
case 'p':
{
pid_t pid;
wchar_t *end;
event_t *e;
-
+
e = calloc( 1, sizeof(event_t));
if( !e )
die_mem();
- if( ( opt == 'j' ) &&
+ if( ( opt == 'j' ) &&
( wcscasecmp( woptarg, L"caller" ) == 0 ) )
{
int job_id = -1;
-
- if( is_subshell )
+
+ if( is_subshell )
{
block_t *b = current_block;
-
+
while( b && (b->type != SUBST) )
b = b->outer;
-
+
if( b )
{
b=b->outer;
@@ -1132,7 +1132,7 @@ static int builtin_function( wchar_t **argv )
job_id = b->job->job_id;
}
}
-
+
if( job_id == -1 )
{
sb_printf( sb_err,
@@ -1145,12 +1145,12 @@ static int builtin_function( wchar_t **argv )
e->type = EVENT_JOB_ID;
e->param1.job_id = job_id;
}
-
+
}
else
{
errno = 0;
- pid = wcstol( woptarg, &end, 10 );
+ pid = wcstol( woptarg, &end, 10 );
if( errno || !end || *end )
{
sb_printf( sb_err,
@@ -1159,9 +1159,9 @@ static int builtin_function( wchar_t **argv )
woptarg );
res=1;
break;
- }
-
-
+ }
+
+
e->type = EVENT_EXIT;
e->param1.pid = (opt=='j'?-1:1)*abs(pid);
}
@@ -1171,59 +1171,59 @@ static int builtin_function( wchar_t **argv )
}
else
{
- e->function_name=0;
+ e->function_name=0;
al_push( events, e );
}
- break;
+ break;
}
-
+
case '?':
builtin_print_help( argv[0], sb_err );
- res = 1;
+ res = 1;
break;
-
+
}
-
- }
-
+
+ }
+
if( !res )
- {
+ {
if( argc-woptind != 1 )
{
- sb_printf( sb_err,
+ sb_printf( sb_err,
_( L"%ls: Expected one argument, got %d\n" ),
argv[0],
argc-woptind );
res=1;
}
else if( !(is_binding?wcsbindingname( argv[woptind] ) : wcsvarname( argv[woptind] ) ))
- {
- sb_printf( sb_err,
- _( L"%ls: Illegal function name '%ls'\n" ),
+ {
+ sb_printf( sb_err,
+ _( L"%ls: Illegal function name '%ls'\n" ),
argv[0],
argv[woptind] );
-
- res=1;
- }
+
+ res=1;
+ }
else if( parser_is_reserved(argv[woptind] ) )
{
-
+
sb_printf( sb_err,
_( L"%ls: The name '%ls' is reserved,\nand can not be used as a function name\n" ),
argv[0],
argv[woptind] );
-
+
res=1;
}
}
-
+
if( res )
{
int i;
array_list_t names;
wchar_t **names_arr;
int chars=0;
-
+
// builtin_print_help( argv[0], sb_err );
const wchar_t *cfa = _( L"Current functions are: " );
sb_append( sb_err, cfa );
@@ -1232,9 +1232,9 @@ static int builtin_function( wchar_t **argv )
al_init( &names );
function_get_names( &names, 0 );
names_arr = list_to_char_arr( &names );
- qsort( names_arr,
- al_get_count( &names ),
- sizeof(wchar_t *),
+ qsort( names_arr,
+ al_get_count( &names ),
+ sizeof(wchar_t *),
(int (*)(const void *, const void *))&wcsfilecmp );
for( i=0; iparam1.function_name=wcsdup(argv[woptind]);
current_block->param2.function_description=desc?wcsdup(desc):0;
current_block->param3.function_is_binding = is_binding;
- current_block->param4.function_events = events;
+ current_block->param4.function_events = events;
for( i=0; itok_pos = parser_get_pos();
current_block->skip = 1;
-
+
return 0;
-
+
}
-/**
+/**
The random builtin. For generating random numbers.
*/
static int builtin_random( wchar_t **argv )
{
- static int seeded=0;
+ static int seeded=0;
int argc = builtin_count_args( argv );
-
+
woptind=0;
-
+
const static struct woption
long_options[] =
{
{
- L"help", no_argument, 0, 'h'
+ L"help", no_argument, 0, 'h'
}
,
- {
- 0, 0, 0, 0
+ {
+ 0, 0, 0, 0
}
}
- ;
-
+ ;
+
while( 1 )
{
int opt_index = 0;
-
+
int opt = wgetopt_long( argc,
- argv,
- L"h",
- long_options,
+ argv,
+ L"h",
+ long_options,
&opt_index );
if( opt == -1 )
break;
-
+
switch( opt )
{
case 0:
@@ -1328,21 +1328,21 @@ static int builtin_random( wchar_t **argv )
argv[0],
long_options[opt_index].name );
builtin_print_help( argv[0], sb_err );
-
+
return 1;
-
- case 'h':
+
+ case 'h':
builtin_print_help( argv[0], sb_err );
break;
case '?':
builtin_print_help( argv[0], sb_err );
-
+
return 1;
-
+
}
-
- }
+
+ }
switch( argc-woptind )
{
@@ -1357,28 +1357,28 @@ static int builtin_random( wchar_t **argv )
sb_printf( sb_out, L"%d\n", rand()%32767 );
break;
}
-
+
case 1:
{
int foo;
wchar_t *end=0;
-
+
errno=0;
foo = wcstol( argv[woptind], &end, 10 );
if( errno || *end )
{
sb_printf( sb_err,
- _( L"%ls: Seed value '%ls' is not a valid number\n" ),
+ _( L"%ls: Seed value '%ls' is not a valid number\n" ),
argv[0],
argv[woptind] );
-
+
return 1;
}
seeded=1;
srand( foo );
break;
}
-
+
default:
{
sb_printf( sb_err,
@@ -1389,7 +1389,7 @@ static int builtin_random( wchar_t **argv )
return 1;
}
}
- return 0;
+ return 0;
}
@@ -1405,7 +1405,7 @@ static int builtin_read( wchar_t **argv )
wchar_t *nxt;
wchar_t *prompt = DEFAULT_READ_PROMPT;
wchar_t *commandline = L"";
-
+
woptind=0;
while( 1 )
@@ -1441,22 +1441,22 @@ static int builtin_read( wchar_t **argv )
L"command", required_argument, 0, 'c'
}
,
- {
- 0, 0, 0, 0
+ {
+ 0, 0, 0, 0
}
}
- ;
-
+ ;
+
int opt_index = 0;
-
+
int opt = wgetopt_long( argc,
- argv,
- L"xglUup:c:",
- long_options,
+ argv,
+ L"xglUup:c:",
+ long_options,
&opt_index );
if( opt == -1 )
break;
-
+
switch( opt )
{
case 0:
@@ -1469,20 +1469,20 @@ static int builtin_read( wchar_t **argv )
builtin_print_help( argv[0], sb_err );
return 1;
-
- case L'x':
+
+ case L'x':
place |= ENV_EXPORT;
break;
- case L'g':
+ case L'g':
place |= ENV_GLOBAL;
break;
- case L'l':
+ case L'l':
place |= ENV_LOCAL;
break;
- case L'U':
+ case L'U':
place |= ENV_UNIVERSAL;
break;
- case L'u':
+ case L'u':
place |= ENV_UNEXPORT;
break;
case L'p':
@@ -1491,15 +1491,15 @@ static int builtin_read( wchar_t **argv )
case L'c':
commandline = woptarg;
break;
-
+
case L'?':
builtin_print_help( argv[0], sb_err );
-
- return 1;
+
+ return 1;
}
-
- }
+
+ }
if( ( place & ENV_UNEXPORT ) && ( place & ENV_EXPORT ) )
{
@@ -1507,50 +1507,50 @@ static int builtin_read( wchar_t **argv )
BUILTIN_ERR_EXPUNEXP,
argv[0],
parser_current_line() );
-
-
- builtin_print_help( argv[0], sb_err );
- return 1;
+
+
+ builtin_print_help( argv[0], sb_err );
+ return 1;
}
-
+
if( (place&ENV_LOCAL?1:0) + (place & ENV_GLOBAL?1:0) + (place & ENV_UNIVERSAL?1:0) > 1)
{
sb_printf( sb_err,
BUILTIN_ERR_GLOCAL,
argv[0],
parser_current_line() );
- builtin_print_help( argv[0], sb_err );
-
- return 1;
+ builtin_print_help( argv[0], sb_err );
+
+ return 1;
}
-
+
if( woptind == argc )
{
sb_printf( sb_err,
BUILTIN_ERR_MISSING,
- argv[0] );
-
+ argv[0] );
+
sb_append2( sb_err,
parser_current_line(),
L"\n",
(void *)0 );
- builtin_print_help( argv[0], sb_err );
- return 1;
+ builtin_print_help( argv[0], sb_err );
+ return 1;
}
- /*
+ /*
Verify all variable names
*/
for( i=woptind; iparam1.source_dest = wcsdup( argv[1] );
current_block->param3.call_lineno = lineno;
current_block->param4.call_filename = file;
- res = reader_read( fd );
+ res = reader_read( fd );
parser_pop_block();
if( res )
{
@@ -2078,17 +2100,17 @@ static void make_first( job_t *j )
static int builtin_fg( wchar_t **argv )
{
job_t *j;
-
+
if( argv[1] == 0 )
{
/*
- Select last constructed job (I.e. first job in the job que) that is possible to put in the foreground
+ Select last constructed job (I.e. first job in the job que) that is possible to put in the foreground
*/
for( j=first_job; j; j=j->next )
{
if( j->constructed && (!job_is_completed(j)) && ( (job_is_stopped(j) || !j->fg) && (j->job_control)))
break;
- }
+ }
if( !j )
{
sb_printf( sb_err,
@@ -2109,21 +2131,21 @@ static int builtin_fg( wchar_t **argv )
j = job_get_from_pid( pid );
if( j != 0 )
{
- sb_printf( sb_err,
+ sb_printf( sb_err,
_( L"%ls: Ambiguous job\n" ),
- argv[0] );
+ argv[0] );
}
else
{
sb_printf( sb_err,
- _( L"%ls: '%ls' is not a job\n" ),
- argv[0],
+ _( L"%ls: '%ls' is not a job\n" ),
+ argv[0],
argv[1] );
}
builtin_print_help( argv[0], sb_err );
-
+
j=0;
-
+
}
else
{
@@ -2147,16 +2169,16 @@ static int builtin_fg( wchar_t **argv )
builtin_print_help( argv[0], sb_err );
j=0;
}
-
+
}
-
+
if( j )
{
if( builtin_err_redirect )
{
- sb_printf( sb_err,
+ sb_printf( sb_err,
FG_MSG,
- j->job_id,
+ j->job_id,
j->command );
}
else
@@ -2168,7 +2190,7 @@ static int builtin_fg( wchar_t **argv )
*/
fwprintf( stderr,
FG_MSG,
- j->job_id,
+ j->job_id,
j->command );
}
@@ -2177,10 +2199,10 @@ static int builtin_fg( wchar_t **argv )
env_set( L"_", ft, ENV_EXPORT );
free(ft);
reader_write_title();
-
+
make_first( j );
j->fg=1;
-
+
job_continue( j, job_is_stopped(j) );
}
return j != 0;
@@ -2193,13 +2215,13 @@ static int send_to_bg( job_t *j, const wchar_t *name )
{
if( j == 0 )
{
- sb_printf( sb_err,
+ sb_printf( sb_err,
_( L"%ls: Unknown job '%ls'\n" ),
L"bg",
name );
builtin_print_help( L"bg", sb_err );
return 1;
- }
+ }
else if( !j->job_control )
{
sb_printf( sb_err,
@@ -2212,7 +2234,7 @@ static int send_to_bg( job_t *j, const wchar_t *name )
}
else
{
- sb_printf( sb_err,
+ sb_printf( sb_err,
_(L"Send job %d '%ls' to background\n"),
j->job_id,
j->command );
@@ -2230,7 +2252,7 @@ static int send_to_bg( job_t *j, const wchar_t *name )
static int builtin_bg( wchar_t **argv )
{
int res = 0;
-
+
if( argv[1] == 0 )
{
job_t *j;
@@ -2239,7 +2261,7 @@ static int builtin_bg( wchar_t **argv )
if( job_is_stopped(j) && j->job_control && (!job_is_completed(j)) )
break;
}
-
+
if( !j )
{
sb_printf( sb_err,
@@ -2272,20 +2294,20 @@ static int cpu_use( job_t *j )
{
double u=0;
process_t *p;
-
+
for( p=j->first_process; p; p=p->next )
{
struct timeval t;
int jiffies;
gettimeofday( &t, 0 );
jiffies = proc_get_jiffies( p );
-
+
double t1 = 1000000.0*p->last_time.tv_sec+p->last_time.tv_usec;
double t2 = 1000000.0*t.tv_sec+t.tv_usec;
-
+
/* fwprintf( stderr, L"t1 %f t2 %f p1 %d p2 %d\n",
t1, t2, jiffies, p->last_jiffies );
-*/
+*/
u += ((double)(jiffies-p->last_jiffies))/(t2-t1);
}
@@ -2315,17 +2337,17 @@ static void builtin_jobs_print( job_t *j, int mode, int header )
#endif
sb_append( sb_out, _( L"State\tCommand\n" ) );
}
-
+
sb_printf( sb_out, L"%d\t%d\t", j->job_id, j->pgid );
-
+
#ifdef HAVE__PROC_SELF_STAT
sb_printf( sb_out, L"%d%%\t", cpu_use(j) );
#endif
- sb_append2( sb_out,
- job_is_stopped(j)?_(L"stopped"):_(L"running"),
- L"\t",
- j->command,
- L"\n",
+ sb_append2( sb_out,
+ job_is_stopped(j)?_(L"stopped"):_(L"running"),
+ L"\t",
+ j->command,
+ L"\n",
(void *)0 );
break;
}
@@ -2342,9 +2364,9 @@ static void builtin_jobs_print( job_t *j, int mode, int header )
sb_printf( sb_out, L"%d\n", j->pgid );
break;
}
-
+
case JOBS_PRINT_PID:
- {
+ {
if( header )
{
/*
@@ -2356,12 +2378,12 @@ static void builtin_jobs_print( job_t *j, int mode, int header )
for( p=j->first_process; p; p=p->next )
{
sb_printf( sb_out, L"%d\n", p->pid );
- }
+ }
break;
}
-
+
case JOBS_PRINT_COMMAND:
- {
+ {
if( header )
{
/*
@@ -2373,11 +2395,11 @@ static void builtin_jobs_print( job_t *j, int mode, int header )
for( p=j->first_process; p; p=p->next )
{
sb_printf( sb_out, L"%ls\n", p->argv[0] );
- }
+ }
break;
- }
+ }
}
-
+
}
@@ -2386,14 +2408,14 @@ static void builtin_jobs_print( job_t *j, int mode, int header )
Builtin for printing running jobs
*/
static int builtin_jobs( wchar_t **argv )
-{
+{
int argc=0;
- int found=0;
+ int found=0;
int mode=JOBS_DEFAULT;
int print_last = 0;
job_t *j;
-
- argc = builtin_count_args( argv );
+
+ argc = builtin_count_args( argv );
woptind=0;
while( 1 )
@@ -2417,22 +2439,22 @@ static int builtin_jobs( wchar_t **argv )
L"last", no_argument, 0, 'l'
}
,
- {
- 0, 0, 0, 0
+ {
+ 0, 0, 0, 0
}
}
- ;
-
+ ;
+
int opt_index = 0;
-
+
int opt = wgetopt_long( argc,
- argv,
- L"pclg",
- long_options,
+ argv,
+ L"pclg",
+ long_options,
&opt_index );
if( opt == -1 )
break;
-
+
switch( opt )
{
case 0:
@@ -2442,42 +2464,42 @@ static int builtin_jobs( wchar_t **argv )
BUILTIN_ERR_UNKNOWN,
argv[0],
long_options[opt_index].name );
-
- sb_append( sb_err,
+
+ sb_append( sb_err,
parser_current_line() );
// builtin_print_help( argv[0], sb_err );
-
+
return 1;
-
-
- case 'p':
+
+
+ case 'p':
mode=JOBS_PRINT_PID;
break;
-
- case 'c':
+
+ case 'c':
mode=JOBS_PRINT_COMMAND;
break;
- case 'g':
+ case 'g':
mode=JOBS_PRINT_GROUP;
break;
case 'l':
{
- print_last = 1;
+ print_last = 1;
break;
}
-
+
case '?':
// builtin_print_help( argv[0], sb_err );
-
+
return 1;
-
+
}
- }
-
+ }
+
/*
Do not babble if not interactive
@@ -2486,7 +2508,7 @@ static int builtin_jobs( wchar_t **argv )
{
found=1;
}
-
+
if( print_last )
{
/*
@@ -2494,11 +2516,11 @@ static int builtin_jobs( wchar_t **argv )
*/
for( j=first_job; j; j=j->next )
{
- if( j->constructed )
+ if( j->constructed )
{
builtin_jobs_print( j, mode, !found );
return 0;
- }
+ }
}
}
@@ -2509,24 +2531,24 @@ static int builtin_jobs( wchar_t **argv )
int i;
found = 1;
-
+
for( i=woptind; iparam2.for_vars);
-
+
int i;
current_block->tok_pos = parser_get_pos();
current_block->param1.for_variable = wcsdup( argv[1] );
-
+
for( i=argc-1; i>3; i-- )
{
al_push( ¤t_block->param2.for_vars, wcsdup(argv[ i ] ));
@@ -2628,7 +2650,7 @@ static int builtin_for( wchar_t **argv )
else
{
current_block->skip=1;
- }
+ }
}
return res;
}
@@ -2642,12 +2664,12 @@ static int builtin_begin( wchar_t **argv )
current_block->tok_pos = parser_get_pos();
return 0;
}
-
+
/**
Builtin for ending a block of code, such as a for-loop or an if statement.
- The end command is whare a lot of the block-level magic happens.
+ The end command is whare a lot of the block-level magic happens.
*/
static int builtin_end( wchar_t **argv )
{
@@ -2656,7 +2678,7 @@ static int builtin_end( wchar_t **argv )
sb_printf( sb_err,
_( L"%ls: Not inside of block\n" ),
argv[0] );
-
+
builtin_print_help( argv[0], sb_err );
return 1;
}
@@ -2668,7 +2690,7 @@ static int builtin_end( wchar_t **argv )
variables in the current loop scope won't die between laps.
*/
int kill_block = 1;
-
+
switch( current_block->type )
{
case WHILE:
@@ -2685,17 +2707,17 @@ static int builtin_end( wchar_t **argv )
parser_set_pos( current_block->tok_pos);
current_block->param1.while_state = WHILE_TEST_AGAIN;
}
-
+
break;
}
-
+
case IF:
case SUBST:
case BEGIN:
/*
Nothing special happens at the end of these. The scope just ends.
*/
-
+
break;
case FOR:
@@ -2710,7 +2732,7 @@ static int builtin_end( wchar_t **argv )
free( (void *)al_pop( ¤t_block->param2.for_vars ) );
}
}
-
+
if( al_get_count( ¤t_block->param2.for_vars ) )
{
wchar_t *val = (wchar_t *)al_pop( ¤t_block->param2.for_vars );
@@ -2718,17 +2740,17 @@ static int builtin_end( wchar_t **argv )
current_block->loop_status = LOOP_NORMAL;
current_block->skip = 0;
free(val);
-
+
kill_block = 0;
parser_set_pos( current_block->tok_pos );
-/*
- fwprintf( stderr,
+/*
+ fwprintf( stderr,
L"jump to %d\n",
current_block->tok_pos ); */
}
break;
}
-
+
case FUNCTION_DEF:
{
/**
@@ -2736,36 +2758,36 @@ static int builtin_end( wchar_t **argv )
until the end command and use as the new definition
for the specified function
*/
- wchar_t *def = wcsndup( parser_get_buffer()+current_block->tok_pos,
+ wchar_t *def = wcsndup( parser_get_buffer()+current_block->tok_pos,
parser_get_job_pos()-current_block->tok_pos );
-
+
//fwprintf( stderr, L"Function: %ls\n", def );
-
+
if( !is_interactive || !parser_test( def, 1 ) )
{
- function_add( current_block->param1.function_name,
+ function_add( current_block->param1.function_name,
def,
current_block->param2.function_description,
current_block->param4.function_events,
current_block->param3.function_is_binding );
- }
-
+ }
+
free(def);
}
break;
-
+
}
if( kill_block )
{
parser_pop_block();
}
-
+
/*
If everything goes ok, return status of last command to execute.
*/
return proc_get_last_status();
- }
+ }
}
/**
@@ -2773,7 +2795,7 @@ static int builtin_end( wchar_t **argv )
*/
static int builtin_else( wchar_t **argv )
{
- if( current_block == 0 ||
+ if( current_block == 0 ||
current_block->type != IF ||
current_block->param1.if_state != 1)
{
@@ -2805,9 +2827,9 @@ static int builtin_break_continue( wchar_t **argv )
{
int is_break = (wcscmp(argv[0],L"break")==0);
int argc = builtin_count_args( argv );
-
+
block_t *b = current_block;
-
+
if( argc != 1 )
{
sb_printf( sb_err,
@@ -2816,28 +2838,28 @@ static int builtin_break_continue( wchar_t **argv )
argv[1] );
builtin_print_help( argv[0], sb_err );
- return 1;
+ return 1;
}
-
- while( (b != 0) &&
- ( b->type != WHILE) &&
+
+ while( (b != 0) &&
+ ( b->type != WHILE) &&
(b->type != FOR ) )
{
b = b->outer;
}
-
+
if( b == 0 )
{
- sb_printf( sb_err,
- _( L"%ls: Not inside of loop\n" ),
+ sb_printf( sb_err,
+ _( L"%ls: Not inside of loop\n" ),
argv[0] );
builtin_print_help( argv[0], sb_err );
return 1;
}
-
+
b = current_block;
- while( ( b->type != WHILE) &&
+ while( ( b->type != WHILE) &&
(b->type != FOR ) )
{
b->skip=1;
@@ -2854,10 +2876,10 @@ static int builtin_break_continue( wchar_t **argv )
static int builtin_return( wchar_t **argv )
{
int argc = builtin_count_args( argv );
- int status = 0;
-
+ int status = 0;
+
block_t *b = current_block;
-
+
switch( argc )
{
case 1:
@@ -2865,44 +2887,44 @@ static int builtin_return( wchar_t **argv )
case 2:
{
wchar_t *end;
- errno = 0;
+ errno = 0;
status = wcstol(argv[1],&end,10);
if( errno || *end != 0)
{
sb_printf( sb_err,
- _( L"%ls: Argument '%ls' must be an integer\n" ),
- argv[0],
+ _( L"%ls: Argument '%ls' must be an integer\n" ),
+ argv[0],
argv[1] );
- builtin_print_help( argv[0], sb_err );
+ builtin_print_help( argv[0], sb_err );
return 1;
}
// fwprintf( stderr, L"Return with status %d\n", status );
- break;
+ break;
}
default:
- sb_printf( sb_err,
- _( L"%ls: Too many arguments\n" ),
+ sb_printf( sb_err,
+ _( L"%ls: Too many arguments\n" ),
argv[0] );
builtin_print_help( argv[0], sb_err );
- return 1;
+ return 1;
}
-
- while( (b != 0) &&
+
+ while( (b != 0) &&
( b->type != FUNCTION_CALL) )
{
b = b->outer;
}
-
+
if( b == 0 )
{
sb_printf( sb_err,
- _( L"%ls: Not inside of function\n" ),
+ _( L"%ls: Not inside of function\n" ),
argv[0] );
builtin_print_help( argv[0], sb_err );
return 1;
}
-
+
b = current_block;
while( ( b->type != FUNCTION_CALL))
{
@@ -2911,7 +2933,7 @@ static int builtin_return( wchar_t **argv )
}
b->skip=1;
// proc_set_last_status( status );
-
+
return status;
}
@@ -2920,16 +2942,16 @@ static int builtin_return( wchar_t **argv )
*/
static int builtin_switch( wchar_t **argv )
{
- int res=0;
+ int res=0;
int argc = builtin_count_args( argv );
-
+
if( argc != 2 )
{
- sb_printf( sb_err,
+ sb_printf( sb_err,
_( L"%ls: Expected exactly one argument, got %d\n" ),
argv[0],
argc-1 );
-
+
builtin_print_help( argv[0], sb_err );
res=1;
parser_push_block( FAKE );
@@ -2941,7 +2963,7 @@ static int builtin_switch( wchar_t **argv )
current_block->skip=1;
current_block->param2.switch_taken=0;
}
-
+
return res;
}
@@ -2962,14 +2984,14 @@ static int builtin_case( wchar_t **argv )
builtin_print_help( argv[0], sb_err );
return 1;
}
-
+
current_block->skip = 1;
if( current_block->param2.switch_taken )
{
return 0;
}
-
+
for( i=1; iskip = 0;
current_block->param2.switch_taken = 1;
- break;
+ break;
}
}
free( unescaped );
-
- return 0;
+
+ return 0;
}
@@ -2998,13 +3020,13 @@ void builtin_init()
al_init( &io_stack );
hash_init( &builtin, &hash_wcs_func, &hash_wcs_cmp );
- hash_put( &builtin, L"exit", (void*) &builtin_exit );
- hash_put( &builtin, L"block", (void*) &builtin_block );
- hash_put( &builtin, L"builtin", (void*) &builtin_builtin );
+ hash_put( &builtin, L"exit", (void*) &builtin_exit );
+ hash_put( &builtin, L"block", (void*) &builtin_block );
+ hash_put( &builtin, L"builtin", (void*) &builtin_builtin );
hash_put( &builtin, L"cd", (void*) &builtin_cd );
- hash_put( &builtin, L"function", (void*) &builtin_function );
- hash_put( &builtin, L"functions", (void*) &builtin_functions );
- hash_put( &builtin, L"complete", (void*) &builtin_complete );
+ hash_put( &builtin, L"function", (void*) &builtin_function );
+ hash_put( &builtin, L"functions", (void*) &builtin_functions );
+ hash_put( &builtin, L"complete", (void*) &builtin_complete );
hash_put( &builtin, L"end", (void*) &builtin_end );
hash_put( &builtin, L"else", (void*) &builtin_else );
hash_put( &builtin, L"eval", (void*) &builtin_eval );
@@ -3015,45 +3037,45 @@ void builtin_init()
hash_put( &builtin, L"bg", (void*) &builtin_bg );
hash_put( &builtin, L"jobs", (void*) &builtin_jobs );
hash_put( &builtin, L"read", (void*) &builtin_read );
- hash_put( &builtin, L"break", (void*) &builtin_break_continue );
+ hash_put( &builtin, L"break", (void*) &builtin_break_continue );
hash_put( &builtin, L"continue", (void*) &builtin_break_continue );
hash_put( &builtin, L"return", (void*) &builtin_return );
hash_put( &builtin, L"commandline", (void*) &builtin_commandline );
hash_put( &builtin, L"switch", (void*) &builtin_switch );
hash_put( &builtin, L"case", (void*) &builtin_case );
hash_put( &builtin, L"bind", (void*) &builtin_bind );
- hash_put( &builtin, L"random", (void*) &builtin_random );
- hash_put( &builtin, L"status", (void*) &builtin_status );
- hash_put( &builtin, L"ulimit", (void*) &builtin_ulimit );
-
- /*
+ hash_put( &builtin, L"random", (void*) &builtin_random );
+ hash_put( &builtin, L"status", (void*) &builtin_status );
+ hash_put( &builtin, L"ulimit", (void*) &builtin_ulimit );
+
+ /*
Builtins that are handled directly by the parser. They are
bound to a noop function only so that they show up in the
listings of builtin commands, etc..
*/
- hash_put( &builtin, L"command", (void*) &builtin_ignore );
- hash_put( &builtin, L"if", (void*) &builtin_ignore );
- hash_put( &builtin, L"while", (void*) &builtin_ignore );
- hash_put( &builtin, L"not", (void*) &builtin_generic );
- hash_put( &builtin, L"and", (void*) &builtin_generic );
- hash_put( &builtin, L"or", (void*) &builtin_generic );
- hash_put( &builtin, L"exec", (void*) &builtin_exec );
- hash_put( &builtin, L"begin", (void*) &builtin_begin );
+ hash_put( &builtin, L"command", (void*) &builtin_ignore );
+ hash_put( &builtin, L"if", (void*) &builtin_ignore );
+ hash_put( &builtin, L"while", (void*) &builtin_ignore );
+ hash_put( &builtin, L"not", (void*) &builtin_generic );
+ hash_put( &builtin, L"and", (void*) &builtin_generic );
+ hash_put( &builtin, L"or", (void*) &builtin_generic );
+ hash_put( &builtin, L"exec", (void*) &builtin_exec );
+ hash_put( &builtin, L"begin", (void*) &builtin_begin );
/*
This is not a builtin, but fish handles it's help display
internally, to do some ugly special casing to make sure 'count
-h', but 'count (echo -h)' does not.
*/
- hash_put( &builtin, L"count", (void*) &builtin_ignore );
+ hash_put( &builtin, L"count", (void*) &builtin_ignore );
- intern_static( L"exit" );
- intern_static( L"builtin" );
- intern_static( L"block" );
+ intern_static( L"exit" );
+ intern_static( L"builtin" );
+ intern_static( L"block" );
intern_static( L"cd" );
- intern_static( L"function" );
- intern_static( L"functions" );
- intern_static( L"complete" );
+ intern_static( L"function" );
+ intern_static( L"functions" );
+ intern_static( L"complete" );
intern_static( L"end" );
intern_static( L"else" );
intern_static( L"eval" );
@@ -3064,26 +3086,26 @@ void builtin_init()
intern_static( L"bg" );
intern_static( L"jobs" );
intern_static( L"read" );
- intern_static( L"break" );
+ intern_static( L"break" );
intern_static( L"continue" );
intern_static( L"return" );
intern_static( L"commandline" );
intern_static( L"switch" );
intern_static( L"case" );
intern_static( L"bind" );
- intern_static( L"random" );
- intern_static( L"command" );
- intern_static( L"if" );
- intern_static( L"while" );
- intern_static( L"exec" );
- intern_static( L"count" );
- intern_static( L"not" );
- intern_static( L"and" );
- intern_static( L"or" );
- intern_static( L"begin" );
- intern_static( L"status" );
- intern_static( L"ulimit" );
-
+ intern_static( L"random" );
+ intern_static( L"command" );
+ intern_static( L"if" );
+ intern_static( L"while" );
+ intern_static( L"exec" );
+ intern_static( L"count" );
+ intern_static( L"not" );
+ intern_static( L"and" );
+ intern_static( L"or" );
+ intern_static( L"begin" );
+ intern_static( L"status" );
+ intern_static( L"ulimit" );
+
builtin_help_init();
}
@@ -3091,10 +3113,10 @@ void builtin_destroy()
{
if( desc )
{
- hash_destroy( desc );
+ hash_destroy( desc );
free( desc );
}
-
+
al_destroy( &io_stack );
hash_destroy( &builtin );
builtin_help_destroy();
@@ -3108,7 +3130,7 @@ int builtin_exists( wchar_t *cmd )
*/
if( wcscmp( cmd, L"count" )==0)
return 0;
-
+
return (hash_get(&builtin, cmd) != 0 );
}
@@ -3123,7 +3145,7 @@ static int internal_help( wchar_t *cmd )
wcscmp( cmd, L"function" ) == 0 ||
wcscmp( cmd, L"if" ) == 0 ||
wcscmp( cmd, L"end" ) == 0 ||
- wcscmp( cmd, L"switch" ) == 0 )
+ wcscmp( cmd, L"switch" ) == 0 )
return 1;
return 0;
}
@@ -3133,7 +3155,7 @@ int builtin_run( wchar_t **argv )
{
int (*cmd)(wchar_t **argv)=0;
cmd = hash_get( &builtin, argv[0] );
-
+
if( argv[1] != 0 && !internal_help(argv[0]) )
{
if( argv[2] == 0 && (parser_is_help( argv[1], 0 ) ) )
@@ -3142,22 +3164,22 @@ int builtin_run( wchar_t **argv )
return 0;
}
}
-
+
if( cmd != 0 )
{
int status;
-
+
status = cmd(argv);
// fwprintf( stderr, L"Builtin: Set status of %ls to %d\n", argv[0], status );
-
+
return status;
-
+
}
else
{
debug( 0, _( L"Unknown builtin '%ls'" ), argv[0] );
}
- return 1;
+ return 1;
}
@@ -3168,25 +3190,25 @@ void builtin_get_names( array_list_t *list )
const wchar_t *builtin_get_desc( const wchar_t *b )
{
-
+
if( !desc )
{
desc = malloc( sizeof( hash_table_t ) );
- if( !desc)
+ if( !desc)
return 0;
-
+
hash_init( desc, &hash_wcs_func, &hash_wcs_cmp );
- hash_put( desc, L"block", N_( L"Temporarily block delivery of events" ) );
- hash_put( desc, L"builtin", N_( L"Run a builtin command instead of a function" ) );
- hash_put( desc, L"complete", N_( L"Edit command specific completions" ) );
- hash_put( desc, L"cd", N_( L"Change working directory" ) );
- hash_put( desc, L"exit", N_( L"Exit the shell" ) );
- hash_put( desc, L"function", N_( L"Define a new function" ) );
- hash_put( desc, L"functions", N_( L"List or remove functions" ) );
+ hash_put( desc, L"block", N_( L"Temporarily block delivery of events" ) );
+ hash_put( desc, L"builtin", N_( L"Run a builtin command instead of a function" ) );
+ hash_put( desc, L"complete", N_( L"Edit command specific completions" ) );
+ hash_put( desc, L"cd", N_( L"Change working directory" ) );
+ hash_put( desc, L"exit", N_( L"Exit the shell" ) );
+ hash_put( desc, L"function", N_( L"Define a new function" ) );
+ hash_put( desc, L"functions", N_( L"List or remove functions" ) );
hash_put( desc, L"end", N_( L"End a block of commands" ) );
hash_put( desc, L"else", N_( L"Evaluate block if condition is false" ) );
- hash_put( desc, L"eval", N_( L"Evaluate parameters as a command" ) );
+ hash_put( desc, L"eval", N_( L"Evaluate parameters as a command" ) );
hash_put( desc, L"for", N_( L"Perform a set of commands multiple times" ) );
hash_put( desc, L".", N_( L"Evaluate contents of file" ) );
hash_put( desc, L"set", N_( L"Handle environment variables" ) );
@@ -3194,15 +3216,15 @@ const wchar_t *builtin_get_desc( const wchar_t *b )
hash_put( desc, L"bg", N_( L"Send job to background" ) );
hash_put( desc, L"jobs", N_( L"Print currently running jobs" ) );
hash_put( desc, L"read", N_( L"Read a line of input into variables" ) );
- hash_put( desc, L"break", N_( L"Stop the innermost loop" ) );
+ hash_put( desc, L"break", N_( L"Stop the innermost loop" ) );
hash_put( desc, L"continue", N_( L"Skip the rest of the current lap of the innermost loop" ) );
hash_put( desc, L"return", N_( L"Stop the currently evaluated function" ) );
hash_put( desc, L"commandline", N_( L"Set or get the commandline" ) );
- hash_put( desc, L"switch", N_( L"Conditionally execute a block of commands" ) );
- hash_put( desc, L"case", N_( L"Conditionally execute a block of commands" ) );
- hash_put( desc, L"command", N_( L"Run a program instead of a function or builtin" ) );
+ hash_put( desc, L"switch", N_( L"Conditionally execute a block of commands" ) );
+ hash_put( desc, L"case", N_( L"Conditionally execute a block of commands" ) );
+ hash_put( desc, L"command", N_( L"Run a program instead of a function or builtin" ) );
hash_put( desc, L"if", N_( L"Evaluate block if condition is true" ) );
- hash_put( desc, L"while", N_( L"Perform a command multiple times" ) );
+ hash_put( desc, L"while", N_( L"Perform a command multiple times" ) );
hash_put( desc, L"bind", N_( L"Handle fish key bindings" ));
hash_put( desc, L"random", N_( L"Generate random number" ));
hash_put( desc, L"exec", N_( L"Run command in current process" ));
@@ -3214,7 +3236,7 @@ const wchar_t *builtin_get_desc( const wchar_t *b )
hash_put( desc, L"ulimit", N_( L"Set or get the shells resource usage limits" ) );
}
- return _( hash_get( desc, b ));
+ return _( hash_get( desc, b ));
}
void builtin_push_io( int in)
@@ -3223,13 +3245,13 @@ void builtin_push_io( int in)
{
al_push( &io_stack, (void *)(long)builtin_stdin );
al_push( &io_stack, sb_out );
- al_push( &io_stack, sb_err );
+ al_push( &io_stack, sb_err );
}
builtin_stdin = in;
sb_out = malloc(sizeof(string_buffer_t));
sb_err = malloc(sizeof(string_buffer_t));
sb_init( sb_out );
- sb_init( sb_err );
+ sb_init( sb_err );
}
void builtin_pop_io()
@@ -3239,7 +3261,7 @@ void builtin_pop_io()
sb_destroy( sb_err );
free( sb_out);
free(sb_err);
-
+
if( al_get_count( &io_stack ) >0 )
{
sb_err = (string_buffer_t *)al_pop( &io_stack );
diff --git a/complete.c b/complete.c
index afeb6d661..28064902f 100644
--- a/complete.c
+++ b/complete.c
@@ -141,7 +141,7 @@
#define CC_FALSE L"false"
/**
- Struct describing a completion option entry.
+ Struct describing a completion option entry.
If short_opt and long_opt are both zero, the comp field must not be
empty and contains a list of arguments to the command.
@@ -149,7 +149,7 @@
If either short_opt or long_opt are non-zero, they specify a switch
for the command. If \c comp is also not empty, it contains a list
of arguments that may only follow after the specified switch.
-
+
*/
typedef struct complete_entry_opt
{
@@ -228,9 +228,9 @@ static void condition_cache_clear()
if( condition_cache )
{
hash_destroy( condition_cache );
- free( condition_cache );
+ free( condition_cache );
condition_cache = 0;
- }
+ }
}
/**
@@ -242,38 +242,38 @@ static void condition_cache_clear()
static int condition_test( const wchar_t *condition )
{
const void *test_res;
-
+
if( !condition || !wcslen(condition) )
{
// fwprintf( stderr, L"No condition specified\n" );
return 1;
}
-
+
if( !condition_cache )
{
condition_cache = malloc( sizeof( hash_table_t ) );
if( !condition_cache )
{
die_mem();
-
+
}
-
- hash_init( condition_cache,
+
+ hash_init( condition_cache,
&hash_wcs_func,
&hash_wcs_cmp );
-
-
+
+
}
-
+
test_res = hash_get( condition_cache, condition );
-
+
if (test_res == CC_NOT_TESTED )
{
test_res = exec_subshell( condition, 0 )?CC_FALSE:CC_TRUE;
-// debug( 1, L"Eval returns %ls for '%ls'", test_res, condition );
+// debug( 1, L"Eval returns %ls for '%ls'", test_res, condition );
hash_put( condition_cache, condition, test_res );
-
+
/*
Restore previous status information
*/
@@ -281,13 +281,13 @@ static int condition_test( const wchar_t *condition )
if( test_res == CC_TRUE )
{
-// debug( 1, L"Use conditional completion on condition %ls", condition );
- return 1;
+// debug( 1, L"Use conditional completion on condition %ls", condition );
+ return 1;
}
// debug( 1, L"Skip conditional completion on condition %ls", condition );
return 0;
-
+
}
@@ -341,15 +341,15 @@ void complete_destroy()
complete_free_entry( prev );
}
first_entry = 0;
-
+
if( suffix_hash )
{
hash_foreach( suffix_hash, &clear_hash_entry );
hash_destroy( suffix_hash );
- free( suffix_hash );
+ free( suffix_hash );
suffix_hash=0;
}
-
+
if( loaded_completions )
{
hash_foreach( loaded_completions,
@@ -404,8 +404,8 @@ void complete_add( const wchar_t *cmd,
{
if( !(c = malloc( sizeof(complete_entry) )))
die_mem();
-
-
+
+
c->next = first_entry;
first_entry = c;
@@ -419,7 +419,7 @@ void complete_add( const wchar_t *cmd,
/* wprintf( L"Add completion to option (short %lc, long %ls)\n", short_opt, long_opt );*/
if( !(opt = malloc( sizeof( complete_entry_opt ) )))
die_mem();
-
+
opt->next = c->first_option;
c->first_option = opt;
c->authorative = authorative;
@@ -526,12 +526,12 @@ void complete_remove( const wchar_t *cmd,
}
else
{
- eprev->next = e->next;
+ eprev->next = e->next;
}
-
+
free( e->short_opt_str );
free( e );
- e=0;
+ e=0;
}
}
@@ -615,12 +615,12 @@ int complete_is_valid_option( const wchar_t *str,
return 0;
}
-
-
+
+
if( !(short_validated = malloc( wcslen( opt ) )))
die_mem();
-
+
memset( short_validated, 0, wcslen( opt ) );
hash_init( &gnu_match_hash,
@@ -899,7 +899,7 @@ static const wchar_t *complete_get_desc_suffix( const wchar_t *suff_orig )
const wchar_t *complete_get_desc( const wchar_t *filename )
{
struct stat buf;
-
+
if( !get_desc_buff )
{
get_desc_buff = malloc(sizeof(string_buffer_t) );
@@ -909,17 +909,17 @@ const wchar_t *complete_get_desc( const wchar_t *filename )
{
sb_clear( get_desc_buff );
}
-
+
if( lwstat( filename, &buf )==0)
- {
+ {
if( S_ISCHR(buf.st_mode) )
{
- sb_printf( get_desc_buff, L"%lc%ls", COMPLETE_SEP, COMPLETE_CHAR_DESC );
+ sb_printf( get_desc_buff, L"%lc%ls", COMPLETE_SEP, COMPLETE_CHAR_DESC );
}
else if( S_ISBLK(buf.st_mode) )
- sb_printf( get_desc_buff, L"%lc%ls", COMPLETE_SEP, COMPLETE_BLOCK_DESC );
+ sb_printf( get_desc_buff, L"%lc%ls", COMPLETE_SEP, COMPLETE_BLOCK_DESC );
else if( S_ISFIFO(buf.st_mode) )
- sb_printf( get_desc_buff, L"%lc%ls", COMPLETE_SEP, COMPLETE_FIFO_DESC );
+ sb_printf( get_desc_buff, L"%lc%ls", COMPLETE_SEP, COMPLETE_FIFO_DESC );
else if( S_ISLNK(buf.st_mode))
{
struct stat buf2;
@@ -931,7 +931,7 @@ const wchar_t *complete_get_desc( const wchar_t *filename )
sb_printf( get_desc_buff, L"/%lc%ls", COMPLETE_SEP, COMPLETE_SYMLINK_DESC );
}
else if( waccess( filename, X_OK ) == 0 )
- sb_printf( get_desc_buff, L"%lc%ls", COMPLETE_SEP, COMPLETE_EXEC_LINK_DESC );
+ sb_printf( get_desc_buff, L"%lc%ls", COMPLETE_SEP, COMPLETE_EXEC_LINK_DESC );
else
sb_printf( get_desc_buff, L"%lc%ls", COMPLETE_SEP, COMPLETE_SYMLINK_DESC );
}
@@ -951,7 +951,7 @@ const wchar_t *complete_get_desc( const wchar_t *filename )
{
sb_printf( get_desc_buff, L"%lc%ls", COMPLETE_SEP, COMPLETE_LOOP_SYMLINK_DESC );
}
-
+
/*
Some kind of broken symlink. We ignore it
here, and it will get a 'file' description,
@@ -981,16 +981,16 @@ const wchar_t *complete_get_desc( const wchar_t *filename )
sb_printf( get_desc_buff,
L"%lc%ls",
COMPLETE_SEP,
- complete_get_desc_suffix( suffix ) );
+ complete_get_desc_suffix( suffix ) );
}
else
- {
+ {
sb_printf( get_desc_buff,
- L"%lc%ls",
- COMPLETE_SEP,
+ L"%lc%ls",
+ COMPLETE_SEP,
COMPLETE_FILE_DESC );
}
-
+
}
return (wchar_t *)get_desc_buff->buff;
@@ -998,7 +998,7 @@ const wchar_t *complete_get_desc( const wchar_t *filename )
/**
Copy any strings in possible_comp which have the specified prefix
- to the list comp_out. The prefix may contain wildcards.
+ to the list comp_out. The prefix may contain wildcards.
There are three ways to specify descriptions for each
completion. Firstly, if a description has already been added to the
@@ -1068,7 +1068,7 @@ static void complete_cmd_desc( const wchar_t *cmd, array_list_t *comp )
cmd_start++;
else
cmd_start = cmd;
-
+
cmd_len = wcslen(cmd_start);
/*
@@ -1083,9 +1083,9 @@ static void complete_cmd_desc( const wchar_t *cmd, array_list_t *comp )
{
return;
}
-
- esc = expand_escape( cmd_start, 1 );
-
+
+ esc = expand_escape( cmd_start, 1 );
+
if( whatis_path )
{
apropos_cmd =wcsdupcat2( L"grep ^/dev/null -F <", whatis_path, L" ", esc, 0 );
@@ -1094,8 +1094,8 @@ static void complete_cmd_desc( const wchar_t *cmd, array_list_t *comp )
{
apropos_cmd = wcsdupcat( L"apropos ^/dev/null ", esc );
}
- free(esc);
-
+ free(esc);
+
al_init( &list );
hash_init( &lookup, &hash_wcs_func, &hash_wcs_cmp );
@@ -1111,23 +1111,23 @@ static void complete_cmd_desc( const wchar_t *cmd, array_list_t *comp )
Then discard anything that is not a possible completion and put
the result into a hashtable with the completion as key and the
description as value.
-
+
Should be reasonably fast, since no memory allocations are needed.
*/
for( i=0; icondition ))
{
-
+
/* wprintf( L"Use option with desc %ls\n", o->desc ); */
use_common &= ((o->result_mode & NO_COMMON )==0);
use_files &= ((o->result_mode & NO_FILES )==0);
@@ -1706,13 +1706,13 @@ static int complete_param( wchar_t *cmd_orig,
*/
if( !o->old_mode && wcslen(o->long_opt) && !(o->result_mode & NO_COMMON) )
continue;
-
+
if( param_match( o, popt ) && condition_test( o->condition ))
{
use_common &= ((o->result_mode & NO_COMMON )==0);
use_files &= ((o->result_mode & NO_FILES )==0);
complete_from_args( str, o->comp, o->desc, comp_out );
-
+
}
}
}
@@ -1727,15 +1727,15 @@ static int complete_param( wchar_t *cmd_orig,
If this entry is for the base command,
check if any of the arguments match
*/
-
+
if( !condition_test( o->condition ))
continue;
-
+
if( (o->short_opt == L'\0' ) && (o->long_opt[0]==L'\0'))
{
use_files &= ((o->result_mode & NO_FILES )==0);
-// debug( 0, L"Running argument command %ls", o->comp );
+// debug( 0, L"Running argument command %ls", o->comp );
complete_from_args( str, o->comp, o->desc, comp_out );
}
@@ -1751,10 +1751,10 @@ static int complete_param( wchar_t *cmd_orig,
malloc( sizeof(wchar_t)*(3 + wcslen(o->desc)));
if( !next_opt )
die_mem();
-
+
next_opt[0]=o->short_opt;
- next_opt[1]=COMPLETE_SEP;
- next_opt[2]=L'\0';
+ next_opt[1]=COMPLETE_SEP;
+ next_opt[2]=L'\0';
wcscat( next_opt, o->desc );
al_push( comp_out, next_opt );
}
@@ -1767,9 +1767,9 @@ static int complete_param( wchar_t *cmd_orig,
string_buffer_t whole_opt;
sb_init( &whole_opt );
sb_append2( &whole_opt, o->old_mode?L"-":L"--", o->long_opt, (void *)0 );
-
+
if( wcsncmp( str, (wchar_t *)whole_opt.buff, wcslen(str) )==0)
- {
+ {
/*
If the option requires arguments, add
option with an appended '=' . If the
@@ -1784,14 +1784,14 @@ static int complete_param( wchar_t *cmd_orig,
wcsdupcat2(&((wchar_t *)whole_opt.buff)[wcslen(str)], COMPLETE_SEP_STR, o->desc, (void *)0) );
// fwprintf( stderr, L"Add without param %ls\n", o->long_opt );
}
-
+
if( !o->old_mode && ( wcslen(o->comp) || (o->result_mode & NO_COMMON ) ) )
{
al_push( comp_out,
wcsdupcat2(&((wchar_t *)whole_opt.buff)[wcslen(str)], L"=", COMPLETE_SEP_STR, o->desc, (void *)0) );
// fwprintf( stderr, L"Add with param %ls\n", o->long_opt );
}
-
+
// fwprintf( stderr, L"Matching long option %ls\n", o->long_opt );
}
sb_destroy( &whole_opt );
@@ -1808,8 +1808,8 @@ static int complete_param( wchar_t *cmd_orig,
/**
Perform file completion on the specified string
*/
-static void complete_param_expand( wchar_t *str,
- array_list_t *comp_out,
+static void complete_param_expand( wchar_t *str,
+ array_list_t *comp_out,
int do_file )
{
wchar_t *comp_str;
@@ -1819,19 +1819,19 @@ static void complete_param_expand( wchar_t *str,
}
else
comp_str = str;
-
- debug( 2,
- L"expand_string( \"%ls\", comp_out, EXPAND_SKIP_SUBSHELL | ACCEPT_INCOMPLETE | %ls );",
- comp_str,
+
+ debug( 2,
+ L"expand_string( \"%ls\", comp_out, EXPAND_SKIP_SUBSHELL | ACCEPT_INCOMPLETE | %ls );",
+ comp_str,
do_file?L"0":L"EXPAND_SKIP_WILDCARDS" );
-
+
expand_string( wcsdup(comp_str), comp_out, EXPAND_SKIP_SUBSHELL | ACCEPT_INCOMPLETE | (do_file?0:EXPAND_SKIP_WILDCARDS) );
}
/**
Complete the specified string as an environment variable
*/
-static int complete_variable( const wchar_t *var,
+static int complete_variable( const wchar_t *var,
array_list_t *comp )
{
int i;
@@ -1877,7 +1877,7 @@ static int complete_variable( const wchar_t *var,
/**
Search the specified string for the \$ sign, try to complete as an environment variable
*/
-static int try_complete_variable( const wchar_t *cmd,
+static int try_complete_variable( const wchar_t *cmd,
array_list_t *comp )
{
int len = wcslen( cmd );
@@ -1904,7 +1904,7 @@ static int try_complete_variable( const wchar_t *cmd,
Try to complete the specified string as a username. This is used by ~USER type expansion.
*/
-static int try_complete_user( const wchar_t *cmd,
+static int try_complete_user( const wchar_t *cmd,
array_list_t *comp )
{
const wchar_t *first_char=0;
@@ -1983,8 +1983,8 @@ static int try_complete_user( const wchar_t *cmd,
{
if( wcsncmp( user_name, pw_name, name_len )==0 )
{
- wchar_t *blarg = wcsdupcat2( &pw_name[name_len],
- L"/",
+ wchar_t *blarg = wcsdupcat2( &pw_name[name_len],
+ L"/",
COMPLETE_SEP_STR,
COMPLETE_USER_DESC,
0 );
@@ -2015,12 +2015,12 @@ void complete( const wchar_t *cmd,
int on_command=0;
int pos;
-
+
int old_error_max = error_max;
int done=0;
int cursor_pos = wcslen(cmd );
-
+
error_max=0;
/**
@@ -2031,11 +2031,11 @@ void complete( const wchar_t *cmd,
if( try_complete_variable( cmd, comp ))
{
done=1;
-
+
}
else if( try_complete_user( cmd, comp ))
{
- done=1;
+ done=1;
}
/*
@@ -2051,10 +2051,10 @@ void complete( const wchar_t *cmd,
if( !begin )
done=1;
}
-
+
if( !done )
{
-
+
pos = cursor_pos-(begin-cmd);
buff = wcsndup( begin, end-begin );
@@ -2062,14 +2062,14 @@ void complete( const wchar_t *cmd,
if( !buff )
done=1;
}
-
+
if( !done )
{
int had_cmd=0;
int end_loop=0;
-
+
tok_init( &tok, buff, TOK_ACCEPT_UNFINISHED );
-
+
while( tok_has_next( &tok) && !end_loop )
{
switch( tok_last_type( &tok ) )
@@ -2079,31 +2079,31 @@ void complete( const wchar_t *cmd,
{
if( parser_is_subcommand( tok_last( &tok ) ) )
break;
-
+
current_command = wcsdup( tok_last( &tok ) );
-
+
on_command = (pos <= tok_get_pos( &tok) + wcslen( tok_last( &tok ) ) );
had_cmd=1;
}
break;
-
+
case TOK_END:
case TOK_PIPE:
case TOK_BACKGROUND:
had_cmd=0;
break;
-
-
+
+
case TOK_ERROR:
end_loop=1;
break;
-
+
}
if( tok_get_pos( &tok ) >= pos )
end_loop=1;
-
+
tok_next( &tok );
-
+
}
tok_destroy( &tok );
@@ -2120,10 +2120,10 @@ void complete( const wchar_t *cmd,
prev_token = prev_begin ? wcsndup( prev_begin, prev_end - prev_begin ): wcsdup(L"");
// fwprintf( stderr, L"on_command: %d, %ls %ls\n", on_command, current_compmand, current_token );
-
+
if( current_token && current_command && prev_token )
{
-
+
if( on_command )
{
/* Complete command filename */
@@ -2164,11 +2164,11 @@ void complete( const wchar_t *cmd,
non-null and longer than 0 characters.
*/
static void append_switch( string_buffer_t *out,
- const wchar_t *opt,
+ const wchar_t *opt,
const wchar_t *argument )
{
wchar_t *esc;
-
+
if( !argument || argument==L"" )
return;
@@ -2180,7 +2180,7 @@ static void append_switch( string_buffer_t *out,
void complete_print( string_buffer_t *out )
{
complete_entry *e;
-
+
for( e = first_entry; e; e=e->next )
{
complete_entry_opt *o;
@@ -2198,11 +2198,11 @@ void complete_print( string_buffer_t *out )
sb_printf( out,
L"complete%ls",
modestr[o->result_mode] );
-
+
append_switch( out,
e->cmd_type?L"path":L"command",
e->cmd );
-
+
if( o->short_opt != 0 )
{
@@ -2210,24 +2210,24 @@ void complete_print( string_buffer_t *out )
L" --short-option '%lc'",
o->short_opt );
}
-
-
+
+
append_switch( out,
o->old_mode?L"old-option":L"long-option",
o->long_opt );
-
+
append_switch( out,
L"description",
o->desc );
-
+
append_switch( out,
L"arguments",
o->comp );
-
+
append_switch( out,
L"condition",
o->condition );
-
+
sb_printf( out, L"\n" );
}
}
diff --git a/expand.c b/expand.c
index 48ccbabd8..de1869cea 100644
--- a/expand.c
+++ b/expand.c
@@ -122,7 +122,7 @@ parameter expansion.
*/
static int is_clean( const wchar_t *in )
{
-
+
const wchar_t * str = in;
/*
@@ -130,7 +130,7 @@ static int is_clean( const wchar_t *in )
*/
if( wcschr( UNCLEAN_FIRST, *str ) )
return 0;
-
+
/*
Test characters that have a special meaning in any character position
*/
@@ -140,12 +140,12 @@ static int is_clean( const wchar_t *in )
return 0;
str++;
}
-
+
return 1;
}
/**
- Return the environment variable value for the string starting at \c in.
+ Return the environment variable value for the string starting at \c in.
*/
static wchar_t *expand_var( wchar_t *in )
{
@@ -160,7 +160,7 @@ void expand_variable_array( const wchar_t *val, array_list_t *out )
{
wchar_t *cpy = wcsdup( val );
wchar_t *pos, *start;
-
+
if( !cpy )
{
die_mem();
@@ -176,8 +176,8 @@ void expand_variable_array( const wchar_t *val, array_list_t *out )
}
}
al_push( out, wcsdup(start) );
-
- free(cpy);
+
+ free(cpy);
}
}
@@ -198,41 +198,41 @@ static int is_quotable( wchar_t *str )
{
case 0:
return 1;
-
+
case L'\n':
case L'\t':
case L'\r':
case L'\b':
case L'\e':
return 0;
-
+
default:
- return is_quotable(str+1);
+ return is_quotable(str+1);
}
return 0;
-
+
}
wchar_t *expand_escape_variable( const wchar_t *in )
{
-
+
array_list_t l;
string_buffer_t buff;
-
+
al_init( &l );
expand_variable_array( in, &l );
sb_init( &buff );
-
+
switch( al_get_count( &l) )
{
case 0:
sb_append( &buff, L"''");
- break;
+ break;
case 1:
{
wchar_t *el = (wchar_t *)al_get( &l, 0 );
-
+
if( wcschr( el, L' ' ) && is_quotable( el ) )
{
sb_append2( &buff,
@@ -243,7 +243,7 @@ wchar_t *expand_escape_variable( const wchar_t *in )
}
else
{
- wchar_t *val = expand_escape( el, 1 );
+ wchar_t *val = expand_escape( el, 1 );
sb_append( &buff, val );
free( val );
}
@@ -258,7 +258,7 @@ wchar_t *expand_escape_variable( const wchar_t *in )
wchar_t *el = (wchar_t *)al_get( &l, j );
if( j )
sb_append( &buff, L" " );
-
+
if( is_quotable( el ) )
{
sb_append2( &buff,
@@ -269,19 +269,19 @@ wchar_t *expand_escape_variable( const wchar_t *in )
}
else
{
- wchar_t *val = expand_escape( el, 1 );
+ wchar_t *val = expand_escape( el, 1 );
sb_append( &buff, val );
free( val );
}
-
+
free( el );
- }
- }
+ }
+ }
}
al_destroy( &l );
return (wchar_t *)buff.buff;
-
+
}
/**
@@ -312,31 +312,31 @@ static int iswnumeric( const wchar_t *n )
See if the process described by \c proc matches the commandline \c
cmd
*/
-static int match_pid( const wchar_t *cmd,
+static int match_pid( const wchar_t *cmd,
const wchar_t *proc,
int flags )
{
/* Test for direct match */
-
+
if( wcsncmp( cmd, proc, wcslen( proc ) ) == 0 )
return 1;
-
+
if( flags & ACCEPT_INCOMPLETE )
return 0;
- /*
+ /*
Test if the commandline is a path to the command, if so we try
to match against only the command part
*/
wchar_t *first_token = tok_first( cmd );
if( first_token == 0 )
return 0;
-
+
wchar_t *start=0;
wchar_t prev=0;
wchar_t *p;
-
- /*
+
+ /*
This should be done by basename(), if it wasn't for the fact
that is does not accept wide strings
*/
@@ -348,7 +348,7 @@ static int match_pid( const wchar_t *cmd,
}
if( start )
{
-
+
if( wcsncmp( start+1, proc, wcslen( proc ) ) == 0 )
{
free( first_token );
@@ -356,9 +356,9 @@ static int match_pid( const wchar_t *cmd,
}
}
free( first_token );
-
+
return 0;
-
+
}
/**
@@ -375,8 +375,8 @@ static int match_pid( const wchar_t *cmd,
filesystem, all the users processes are searched for matches.
*/
-static int find_process( const wchar_t *proc,
- int flags,
+static int find_process( const wchar_t *proc,
+ int flags,
array_list_t *out )
{
DIR *dir;
@@ -386,14 +386,14 @@ static int find_process( const wchar_t *proc,
wchar_t *cmd=0;
int sz=0;
int found = 0;
- wchar_t *result;
-
+ wchar_t *result;
+
job_t *j;
-
+
if( iswnumeric(proc) || (wcslen(proc)==0) )
{
/*
- This is a numeric job string, like '%2'
+ This is a numeric job string, like '%2'
*/
// fwprintf( stderr, L"Numeric\n\n\n" );
@@ -408,30 +408,30 @@ static int find_process( const wchar_t *proc,
swprintf( jid, 16, L"%d", j->job_id );
// fwprintf( stderr, L"Jid %ls\n", jid );
-
+
if( wcsncmp( proc, jid, wcslen(proc ) )==0 )
{
- al_push( out,
- wcsdupcat2( jid+wcslen(proc),
+ al_push( out,
+ wcsdupcat2( jid+wcslen(proc),
COMPLETE_SEP_STR,
- COMPLETE_JOB_DESC_VAL,
- j->command,
+ COMPLETE_JOB_DESC_VAL,
+ j->command,
(void *)0 ) );
-
-
+
+
}
}
-
+
}
else
{
-
+
int jid = wcstol( proc, 0, 10 );
-
+
j = job_get( jid );
if( (j != 0) && (j->command != 0 ) )
{
-
+
{
result = malloc(sizeof(wchar_t)*16 );
swprintf( result, 16, L"%d", j->pgid );
@@ -439,7 +439,7 @@ static int find_process( const wchar_t *proc,
al_push( out, result );
found = 1;
}
- }
+ }
}
}
if( found )
@@ -450,19 +450,19 @@ static int find_process( const wchar_t *proc,
// fwprintf( stderr, L"..." );
if( j->command == 0 )
continue;
-
+
// fwprintf( stderr, L"match '%ls' '%ls'\n\n\n", j->command, proc );
-
+
if( match_pid( j->command, proc, flags ) )
{
if( flags & ACCEPT_INCOMPLETE )
{
- wchar_t *res = wcsdupcat2( j->command + wcslen(proc),
+ wchar_t *res = wcsdupcat2( j->command + wcslen(proc),
COMPLETE_SEP_STR,
COMPLETE_JOB_DESC,
(void *)0 );
// fwprintf( stderr, L"Woot %ls\n", res );
-
+
al_push( out, res );
}
else
@@ -487,18 +487,18 @@ static int find_process( const wchar_t *proc,
continue;
for( p=j->first_process; p; p=p->next )
{
-
+
// fwprintf( stderr, L"..." );
if( p->actual_cmd == 0 )
continue;
-
+
// fwprintf( stderr, L"match '%ls' '%ls'\n\n\n", j->command, proc );
-
+
if( match_pid( p->actual_cmd, proc, flags ) )
{
if( flags & ACCEPT_INCOMPLETE )
{
- wchar_t *res = wcsdupcat2( p->actual_cmd + wcslen(proc),
+ wchar_t *res = wcsdupcat2( p->actual_cmd + wcslen(proc),
COMPLETE_SEP_STR,
COMPLETE_CHILD_PROCESS_DESC,
(void *)0);
@@ -523,15 +523,15 @@ static int find_process( const wchar_t *proc,
if( !(dir = opendir( "/proc" )))
{
/*
- This system does not have a /proc filesystem.
+ This system does not have a /proc filesystem.
*/
return 1;
}
-
+
pdir_name = malloc( 256 );
pfile_name = malloc( 64 );
strcpy( pdir_name, "/proc/" );
-
+
while( (next=readdir(dir))!=0 )
{
char *name = next->d_name;
@@ -544,29 +544,29 @@ static int find_process( const wchar_t *proc,
if( stat( pdir_name, &buf ) )
{
continue;
- }
+ }
if( buf.st_uid != getuid() )
{
continue;
}
strcpy( pfile_name, pdir_name );
strcat( pfile_name, "/cmdline" );
-
+
if( !stat( pfile_name, &buf ) )
{
/*
the 'cmdline' file exists, it should contain the commandline
*/
FILE *cmdfile;
-
+
if((cmdfile=fopen( pfile_name, "r" ))==0)
{
wperror( L"fopen" );
continue;
}
-
- fgetws2( &cmd, &sz, cmdfile );
-
+
+ fgetws2( &cmd, &sz, cmdfile );
+
fclose( cmdfile );
}
else
@@ -579,13 +579,13 @@ static int find_process( const wchar_t *proc,
psinfo_t info;
FILE *psfile;
-
+
if((psfile=fopen( pfile_name, "r" ))==0)
{
wperror( L"fopen" );
continue;
}
-
+
if( fread( &info, sizeof(info), 1, psfile ) )
{
if( cmd != 0 )
@@ -603,11 +603,11 @@ static int find_process( const wchar_t *proc,
}
}
}
-
+
if( cmd != 0 )
{
if( match_pid( cmd, proc, flags ) )
- {
+ {
if( flags & ACCEPT_INCOMPLETE )
{
wchar_t *res = wcsdupcat2( cmd + wcslen(proc),
@@ -626,22 +626,22 @@ static int find_process( const wchar_t *proc,
}
}
}
-
+
if( cmd != 0 )
free( cmd );
-
+
free( pdir_name );
free( pfile_name );
-
- closedir( dir );
-
+
+ closedir( dir );
+
return 1;
}
/**
Process id expansion
*/
-static int expand_pid( wchar_t *in,
+static int expand_pid( wchar_t *in,
int flags,
array_list_t *out )
{
@@ -656,13 +656,13 @@ static int expand_pid( wchar_t *in,
if( wcsncmp( in+1, SELF_STR, wcslen(in+1) )==0 )
{
wchar_t *res = wcsdupcat2( SELF_STR+wcslen(in+1), COMPLETE_SEP_STR, COMPLETE_SELF_DESC, (void *)0 );
- al_push( out, res );
- }
+ al_push( out, res );
+ }
else if( wcsncmp( in+1, LAST_STR, wcslen(in+1) )==0 )
{
wchar_t *res = wcsdupcat2( LAST_STR+wcslen(in+1), COMPLETE_SEP_STR, COMPLETE_LAST_DESC, (void *)0 );
- al_push( out, res );
- }
+ al_push( out, res );
+ }
}
else
{
@@ -672,9 +672,9 @@ static int expand_pid( wchar_t *in,
free(in);
swprintf( str, 32, L"%d", getpid() );
al_push( out, str );
-
- return 1;
- }
+
+ return 1;
+ }
if( wcscmp( (in+1), LAST_STR )==0 )
{
wchar_t *str;
@@ -686,20 +686,20 @@ static int expand_pid( wchar_t *in,
swprintf( str, 32, L"%d", proc_last_bg_pid );
al_push( out, str );
}
-
- return 1;
- }
- }
-
+
+ return 1;
+ }
+ }
+
// fwprintf( stderr, L"expand_pid() %ls\n", in );
int prev = al_get_count( out );
if( !find_process( in+1, flags, out ) )
return 0;
-
+
if( prev == al_get_count( out ) )
{
// fwprintf( stderr, L"no match\n" );
-
+
if( flags & ACCEPT_INCOMPLETE )
free( in );
else
@@ -708,19 +708,19 @@ static int expand_pid( wchar_t *in,
// fwprintf( stderr, L"return %ls\n", in );
al_push( out, in );
}
- }
+ }
else
{
// fwprintf( stderr, L"match\n" );
free( in );
}
-
+
return 1;
}
/**
- Expand all environment variables in the string *ptr.
+ Expand all environment variables in the string *ptr.
*/
static int expand_variables( wchar_t *in, array_list_t *out )
{
@@ -729,7 +729,7 @@ static int expand_variables( wchar_t *in, array_list_t *out )
int i, j;
int is_ok= 1;
int empty=0;
-
+
for( i=wcslen(in)-1; (i>=0) && is_ok && !empty; i-- )
{
c = in[i];
@@ -740,10 +740,10 @@ static int expand_variables( wchar_t *in, array_list_t *out )
int var_len, new_len;
wchar_t *var_name;
wchar_t * var_val;
- wchar_t * new_in;
+ wchar_t * new_in;
array_list_t l;
int is_single = (c==VARIABLE_EXPAND_SINGLE);
-
+
stop_pos = start_pos;
while( 1 )
@@ -753,12 +753,12 @@ static int expand_variables( wchar_t *in, array_list_t *out )
if( !( iswalnum( in[stop_pos] ) ||
(wcschr(L"_", in[stop_pos])!= 0) ) )
break;
-
+
stop_pos++;
}
-
+
/* printf( "Stop for '%c'\n", in[stop_pos]);*/
-
+
var_len = stop_pos - start_pos;
if( var_len == 0 )
@@ -768,19 +768,19 @@ static int expand_variables( wchar_t *in, array_list_t *out )
case BRACKET_BEGIN:
{
error( SYNTAX_ERROR,
- -1,
+ -1,
COMPLETE_VAR_BRACKET_DESC );
break;
}
-
+
case INTERNAL_SEPARATOR:
{
error( SYNTAX_ERROR,
- -1,
+ -1,
COMPLETE_VAR_PARAN_DESC );
break;
}
-
+
case 0:
{
error( SYNTAX_ERROR,
@@ -789,23 +789,23 @@ static int expand_variables( wchar_t *in, array_list_t *out )
in[stop_pos] );
break;
}
-
+
default:
{
error( SYNTAX_ERROR,
-1,
COMPLETE_VAR_DESC,
in[stop_pos] );
- break;
+ break;
}
}
-
-
+
+
is_ok = 0;
break;
}
-
-
+
+
if( !(var_name = malloc( sizeof(wchar_t)*(var_len+1) )))
{
die_mem();
@@ -814,29 +814,29 @@ static int expand_variables( wchar_t *in, array_list_t *out )
var_name[var_len]='\0';
/* printf( "Variable name is %s, len is %d\n", var_name, var_len );*/
wchar_t *var_val_orig = expand_var( var_name );
-
+
if( var_val_orig && (var_val = wcsdup( var_val_orig) ) )
{
int all_vars=1;
array_list_t idx;
al_init( &idx );
al_init( &l );
-
+
if( in[stop_pos] == L'[' )
- {
+ {
wchar_t *end;
-
+
all_vars = 0;
-
+
stop_pos++;
while( 1 )
{
int tmp;
-
+
while( iswspace(in[stop_pos]) || (in[stop_pos]==INTERNAL_SEPARATOR))
stop_pos++;
-
-
+
+
if( in[stop_pos] == L']' )
{
stop_pos++;
@@ -847,10 +847,10 @@ static int expand_variables( wchar_t *in, array_list_t *out )
tmp = wcstol( &in[stop_pos], &end, 10 );
if( ( errno ) || ( end == &in[stop_pos] ) )
{
- error( SYNTAX_ERROR,
- -1,
+ error( SYNTAX_ERROR,
+ -1,
L"Expected integer or \']\'" );
-
+
is_ok = 0;
break;
}
@@ -858,25 +858,25 @@ static int expand_variables( wchar_t *in, array_list_t *out )
stop_pos = end-in;
}
}
-
+
if( is_ok )
- {
+ {
expand_variable_array( var_val, &l );
if( !all_vars )
- {
+ {
int j;
for( j=0; j al_get_count( &l ) )
{
- error( SYNTAX_ERROR,
+ error( SYNTAX_ERROR,
-1,
L"Array index out of bounds" );
is_ok=0;
al_truncate( &idx, j );
break;
- }
+ }
else
{
/* Move string from list l to list idx */
@@ -887,84 +887,84 @@ static int expand_variables( wchar_t *in, array_list_t *out )
/* Free remaining strings in list l and truncate it */
al_foreach( &l, (void (*)(const void *))&free );
al_truncate( &l, 0 );
- /* Add items from list idx back to list l */
- al_push_all( &l, &idx );
+ /* Add items from list idx back to list l */
+ al_push_all( &l, &idx );
}
free( var_val );
- }
-
+ }
+
if( is_single )
{
string_buffer_t res;
sb_init( &res );
-
+
in[i]=0;
-
+
sb_append( &res, in );
sb_append_char( &res, INTERNAL_SEPARATOR );
for( j=0; j1 && new_in[start_pos-2]!=VARIABLE_EXPAND)
- {
+ {
new_in[start_pos-1]=INTERNAL_SEPARATOR;
new_in[start_pos]=L'\0';
}
else
new_in[start_pos-1]=L'\0';
-
+
wcscat( new_in, next );
wcscat( new_in, &in[stop_pos] );
-
+
// fwprintf( stderr, L"New value %ls\n", new_in );
is_ok &= expand_variables( new_in, out );
}
}
free( next );
- }
+ }
}
-
+
al_destroy( &l );
al_destroy( &idx );
free(in);
free(var_name );
- return is_ok;
+ return is_ok;
}
else
{
@@ -981,13 +981,13 @@ static int expand_variables( wchar_t *in, array_list_t *out )
else
{
/*
- Expansion to single argument.
+ Expansion to single argument.
*/
string_buffer_t res;
sb_init( &res );
-
+
in[i]=0;
-
+
sb_append( &res, in );
sb_append( &res, &in[stop_pos] );
@@ -998,16 +998,16 @@ static int expand_variables( wchar_t *in, array_list_t *out )
free(var_name );
return is_ok;
}
-
+
}
-
- free(var_name );
-
+
+ free(var_name );
+
}
-
- prev_char = c;
+
+ prev_char = c;
}
-
+
if( !empty )
{
al_push( out, in );
@@ -1016,7 +1016,7 @@ static int expand_variables( wchar_t *in, array_list_t *out )
{
free( in );
}
-
+
return is_ok;
}
@@ -1027,19 +1027,19 @@ static int expand_brackets( wchar_t *in, int flags, array_list_t *out )
{
wchar_t *pos;
int syntax_error=0;
- int bracket_count=0;
+ int bracket_count=0;
wchar_t *bracket_begin=0, *bracket_end=0;
wchar_t *last_sep=0;
-
+
wchar_t *item_begin;
int len1, len2, tot_len;
// fwprintf( stderr, L"expand %ls\n", in );
-
-
- for( pos=in;
- (!bracket_end) && (*pos) && !syntax_error;
+
+
+ for( pos=in;
+ (!bracket_end) && (*pos) && !syntax_error;
pos++ )
{
switch( *pos )
@@ -1048,17 +1048,17 @@ static int expand_brackets( wchar_t *in, int flags, array_list_t *out )
{
if(( bracket_count == 0)&&(bracket_begin==0))
bracket_begin = pos;
-
+
bracket_count++;
break;
-
+
}
case BRACKET_END:
{
bracket_count--;
if( (bracket_count == 0) && (bracket_end == 0) )
bracket_end = pos;
-
+
if( bracket_count < 0 )
{
syntax_error = 1;
@@ -1072,14 +1072,14 @@ static int expand_brackets( wchar_t *in, int flags, array_list_t *out )
}
}
}
-
+
if( bracket_count > 0 )
{
if( !(flags & ACCEPT_INCOMPLETE) )
syntax_error = 1;
else
{
-
+
string_buffer_t mod;
sb_init( &mod );
if( last_sep )
@@ -1093,22 +1093,22 @@ static int expand_brackets( wchar_t *in, int flags, array_list_t *out )
sb_append( &mod, in );
sb_append_char( &mod, BRACKET_END );
}
-
-
+
+
return expand_brackets( (wchar_t*)mod.buff, 1, out );
}
}
-
+
if( syntax_error )
{
- error( SYNTAX_ERROR,
+ error( SYNTAX_ERROR,
-1,
L"Mismatched brackets" );
return 0;
}
-
+
if( bracket_begin == 0 )
{
al_push( out, in );
@@ -1127,32 +1127,32 @@ static int expand_brackets( wchar_t *in, int flags, array_list_t *out )
{
wchar_t *whole_item;
int item_len = pos-item_begin;
-
+
whole_item = malloc( sizeof(wchar_t)*(tot_len + item_len + 1) );
wcsncpy( whole_item, in, len1 );
- wcsncpy( whole_item+len1, item_begin, item_len );
+ wcsncpy( whole_item+len1, item_begin, item_len );
wcscpy( whole_item+len1+item_len, bracket_end+1 );
-
+
expand_brackets( whole_item, flags, out );
-
+
item_begin = pos+1;
if( pos == bracket_end )
break;
- }
+ }
}
-
+
if( *pos == BRACKET_BEGIN )
{
bracket_count++;
}
-
+
if( *pos == BRACKET_END )
{
bracket_count--;
}
}
- free(in);
- return 1;
+ free(in);
+ return 1;
}
/**
@@ -1168,24 +1168,24 @@ static int expand_subshell( wchar_t *in, array_list_t *out )
int i, j;
const wchar_t *item_begin;
- switch( parse_util_locate_cmdsubst(in,
+ switch( parse_util_locate_cmdsubst(in,
¶n_begin,
¶n_end,
0 ) )
{
case -1:
- error( SYNTAX_ERROR,
+ error( SYNTAX_ERROR,
-1,
L"Mismatched parans" );
return 0;
case 0:
al_push( out, in );
- return 1;
+ return 1;
case 1:
-
+
break;
-
- }
+
+ }
len1 = (paran_begin-in);
len2 = wcslen(paran_end)-1;
@@ -1196,58 +1196,58 @@ static int expand_subshell( wchar_t *in, array_list_t *out )
if( !(subcmd = malloc( sizeof(wchar_t)*(paran_end-paran_begin) )))
{
al_destroy( &sub_res );
- return 0;
+ return 0;
}
-
+
wcsncpy( subcmd, paran_begin+1, paran_end-paran_begin-1 );
- subcmd[ paran_end-paran_begin-1]=0;
-
+ subcmd[ paran_end-paran_begin-1]=0;
+
if( exec_subshell( subcmd, &sub_res)==-1 )
{
al_foreach( &sub_res, (void (*)(const void *))&free );
al_destroy( &sub_res );
free( subcmd );
return 0;
- }
-
+ }
+
al_init( &tail_expand );
expand_subshell( wcsdup(paran_end+1), &tail_expand );
-
+
for( i=0; ipw_dir);
+ home = str2wcs(userinfo->pw_dir);
if( !home )
{
*in = L'~';
tilde_error = 1;
}
}
-
+
free( name_str );
free(name);
}
-
+
if( !tilde_error && home && old_in )
{
- new_in = wcsdupcat( home, old_in );
+ new_in = wcsdupcat( home, old_in );
}
free(home);
free( in );
- return new_in;
+ return new_in;
}
return in;
-}
+}
wchar_t *expand_tilde( wchar_t *in)
{
@@ -1348,7 +1348,7 @@ wchar_t *expand_tilde( wchar_t *in)
in[0] = HOME_DIRECTORY;
return expand_tilde_internal( in );
}
- return in;
+ return in;
}
/**
@@ -1367,7 +1367,7 @@ static void remove_internal_separator( const void *s, int conv )
case INTERNAL_SEPARATOR:
in++;
break;
-
+
case ANY_CHAR:
in++;
*out++ = conv?L'?':ANY_CHAR;
@@ -1377,7 +1377,7 @@ static void remove_internal_separator( const void *s, int conv )
in++;
*out++ = conv?L'*':ANY_STRING;
break;
-
+
default:
*out++ = *in++;
}
@@ -1390,18 +1390,18 @@ static void remove_internal_separator( const void *s, int conv )
The real expansion function. expand_one is just a wrapper around this one.
*/
int expand_string( wchar_t *str,
- array_list_t *end_out,
+ array_list_t *end_out,
int flags )
{
array_list_t list1, list2;
array_list_t *in, *out;
-
+
int i;
int subshell_ok = 1;
int res = EXPAND_OK;
-
+
// debug( 1, L"Expand %ls", str );
-
+
if( (!(flags & ACCEPT_INCOMPLETE)) && is_clean( str ) )
{
@@ -1415,13 +1415,13 @@ int expand_string( wchar_t *str,
if( EXPAND_SKIP_SUBSHELL & flags )
{
wchar_t *pos = str;
-
+
while( 1 )
{
pos = wcschr( pos, L'(' );
if( pos == 0 )
break;
-
+
if( (pos == str) || ( *(pos-1) != L'\\' ) )
{
error( SUBSHELL_ERROR, -1, L"Subshells not allowed" );
@@ -1431,7 +1431,7 @@ int expand_string( wchar_t *str,
return EXPAND_ERROR;
}
pos++;
- }
+ }
al_push( &list1, str );
}
else
@@ -1452,15 +1452,15 @@ int expand_string( wchar_t *str,
for( i=0; iouter)+1);
@@ -348,15 +348,15 @@ void parser_push_block( int type )
new->skip = 0;
if( type == FAKE )
new->skip = 1;
-
- new->job = 0;
-
+
+ new->job = 0;
+
new->loop_status=LOOP_NORMAL;
current_block = new;
- if( (new->type != FUNCTION_DEF) &&
- (new->type != FAKE) &&
+ if( (new->type != FUNCTION_DEF) &&
+ (new->type != FAKE) &&
(new->type != TOP) )
{
env_push( type == FUNCTION_CALL );
@@ -369,19 +369,19 @@ void parser_pop_block()
debug( 3, L"Block pop %ls %d\n", parser_get_block_desc(current_block->type), block_count(current_block)-1 );
event_block_t *eb, *eb_next;
- if( (current_block->type != FUNCTION_DEF ) &&
- (current_block->type != FAKE) &&
+ if( (current_block->type != FUNCTION_DEF ) &&
+ (current_block->type != FAKE) &&
(current_block->type != TOP) )
{
env_pop();
}
-
+
switch( current_block->type)
{
case FOR:
{
free( current_block->param1.for_variable );
- al_foreach( ¤t_block->param2.for_vars,
+ al_foreach( ¤t_block->param2.for_vars,
(void (*)(const void *))&free );
al_destroy( ¤t_block->param2.for_vars );
break;
@@ -399,7 +399,7 @@ void parser_pop_block()
free( current_block->param2.function_description );
al_foreach( current_block->param4.function_events,
(void (*)(const void *))&event_free );
- al_destroy( current_block->param4.function_events );
+ al_destroy( current_block->param4.function_events );
free( current_block->param4.function_events );
break;
}
@@ -408,7 +408,7 @@ void parser_pop_block()
{
free( current_block->param1.function_name );
free( current_block->param4.call_filename );
- al_foreach( ¤t_block->param2.function_vars,
+ al_foreach( ¤t_block->param2.function_vars,
(void (*)(const void *))&free );
al_destroy( ¤t_block->param2.function_vars );
break;
@@ -427,7 +427,7 @@ void parser_pop_block()
{
eb_next = eb->next;
free(eb);
- }
+ }
block_t *old = current_block;
current_block = current_block->outer;
@@ -440,37 +440,37 @@ const wchar_t *parser_get_block_desc( int block )
{
case WHILE:
return WHILE_BLOCK;
-
+
case FOR:
return FOR_BLOCK;
-
+
case IF:
return IF_BLOCK;
case FUNCTION_DEF:
return FUNCTION_DEF_BLOCK;
-
+
case FUNCTION_CALL:
return FUNCTION_CALL_BLOCK;
-
+
case SWITCH:
return SWITCH_BLOCK;
-
+
case FAKE:
return FAKE_BLOCK;
-
+
case TOP:
return TOP_BLOCK;
-
+
case SUBST:
return SUBST_BLOCK;
-
+
case BEGIN:
return BEGIN_BLOCK;
-
+
case SOURCE:
return SOURCE_BLOCK;
-
+
default:
return UNKNOWN_BLOCK;
}
@@ -484,7 +484,7 @@ const wchar_t *parser_get_block_desc( int block )
*/
static int parser_skip_arguments( const wchar_t *cmd )
{
-
+
return contains_str( cmd,
L"else",
L"begin",
@@ -493,11 +493,11 @@ static int parser_skip_arguments( const wchar_t *cmd )
int parser_is_subcommand( const wchar_t *cmd )
{
-
+
return parser_skip_arguments( cmd ) ||
contains_str( cmd,
- L"command",
- L"builtin",
+ L"command",
+ L"builtin",
L"while",
L"exec",
L"if",
@@ -513,12 +513,12 @@ int parser_is_subcommand( const wchar_t *cmd )
static int parser_is_block( wchar_t *word)
{
- return contains_str( word,
+ return contains_str( word,
L"for",
- L"while",
- L"if",
+ L"while",
+ L"if",
L"function",
- L"switch",
+ L"switch",
L"begin",
(void *)0 );
}
@@ -527,10 +527,10 @@ int parser_is_reserved( wchar_t *word)
{
return parser_is_block(word) ||
parser_is_subcommand( word ) ||
- contains_str( word,
- L"end",
- L"case",
- L"else",
+ contains_str( word,
+ L"end",
+ L"case",
+ L"else",
L"return",
L"continue",
L"break",
@@ -544,24 +544,24 @@ static int parser_is_pipe_forbidden( wchar_t *word )
{
return contains_str( word,
L"exec",
- L"case",
+ L"case",
L"break",
- L"return",
- L"continue",
+ L"return",
+ L"continue",
(void *)0 );
}
/**
Search the text for the end of the current block
*/
-static const wchar_t *parser_find_end( const wchar_t * buff )
+static const wchar_t *parser_find_end( const wchar_t * buff )
{
tokenizer tok;
int had_cmd=0;
int count = 0;
int error=0;
int mark=0;
-
+
for( tok_init( &tok, buff, 0 );
tok_has_next( &tok ) && !error;
tok_next( &tok ) )
@@ -590,13 +590,13 @@ static const wchar_t *parser_find_end( const wchar_t * buff )
}
break;
}
-
+
case TOK_END:
{
had_cmd = 0;
break;
}
-
+
case TOK_PIPE:
case TOK_BACKGROUND:
{
@@ -609,7 +609,7 @@ static const wchar_t *parser_find_end( const wchar_t * buff )
error = 1;
}
break;
-
+
}
case TOK_ERROR:
@@ -618,24 +618,24 @@ static const wchar_t *parser_find_end( const wchar_t * buff )
default:
break;
-
- }
+
+ }
if(!count)
{
- tok_next( &tok );
- mark = tok_get_pos( &tok );
- break;
+ tok_next( &tok );
+ mark = tok_get_pos( &tok );
+ break;
}
-
+
}
-
- tok_destroy( &tok );
+
+ tok_destroy( &tok );
if(!count && !error){
return buff+mark;
}
return 0;
-
+
}
wchar_t *parser_cdpath_get( wchar_t *dir )
@@ -674,12 +674,12 @@ wchar_t *parser_cdpath_get( wchar_t *dir )
nxt_path = path;
path_cpy = wcsdup( path );
-
+
if( !path_cpy )
{
- die_mem();
+ die_mem();
}
-
+
for( nxt_path = wcstok( path_cpy, ARRAY_SEP_STR, &state );
nxt_path != 0;
nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) )
@@ -695,7 +695,7 @@ wchar_t *parser_cdpath_get( wchar_t *dir )
continue;
}
- whole_path =
+ whole_path =
wcsdupcat2( expanded_path,
( expanded_path[path_len-1] != L'/' )?L"/":L"",
dir, 0 );
@@ -747,7 +747,7 @@ void error( int ec, int p, const wchar_t *str, ... )
va_start( va, str );
vswprintf( err_str, 256, str, va );
- va_end( va );
+ va_end( va );
}
@@ -778,9 +778,9 @@ wchar_t *get_filename( const wchar_t *cmd )
Allocate string long enough to hold the whole command
*/
wchar_t *new_cmd = malloc( sizeof(wchar_t)*(wcslen(cmd)+wcslen(path)+2) );
- /*
+ /*
We tokenize a copy of the path, since strtok modifies
- its arguments
+ its arguments
*/
wchar_t *path_cpy = wcsdup( path );
wchar_t *nxt_path = path;
@@ -789,7 +789,7 @@ wchar_t *get_filename( const wchar_t *cmd )
if( (new_cmd==0) || (path_cpy==0) )
{
die_mem();
-
+
}
for( nxt_path = wcstok( path_cpy, ARRAY_SEP_STR, &state );
@@ -849,34 +849,34 @@ void parser_init()
al_init( &profile_data);
}
forbidden_function = al_new();
-
+
}
/**
Print profiling information to the specified stream
*/
-static void print_profile( array_list_t *p,
- int pos,
+static void print_profile( array_list_t *p,
+ int pos,
FILE *out )
{
profile_element_t *me, *prev;
- int i;
+ int i;
int my_time;
-
+
if( pos >= al_get_count( p ) )
return;
-
+
me= (profile_element_t *)al_get( p, pos );
if( !me->skipped )
{
my_time=me->parse+me->exec;
-
+
for( i=pos+1; iskipped )
continue;
-
+
if( prev->level <= me->level )
break;
if( prev->level > me->level+1 )
@@ -884,7 +884,7 @@ static void print_profile( array_list_t *p,
my_time -= prev->parse;
my_time -= prev->exec;
}
-
+
if( me->cmd )
{
fwprintf( out, L"%d\t%d\t", my_time, me->parse+me->exec );
@@ -895,9 +895,9 @@ static void print_profile( array_list_t *p,
fwprintf( out, L"> %ls\n", me->cmd );
}
}
- print_profile( p, pos+1, out );
- free( me->cmd );
- free( me );
+ print_profile( p, pos+1, out );
+ free( me->cmd );
+ free( me );
}
void parser_destroy()
@@ -916,7 +916,7 @@ void parser_destroy()
}
else
{
- fwprintf( f,
+ fwprintf( f,
_(L"Time\tSum\tCommand\n"),
al_get_count( &profile_data ) );
print_profile( &profile_data, 0, f );
@@ -924,7 +924,7 @@ void parser_destroy()
}
al_destroy( &profile_data );
}
-
+
if( lineinfo )
{
sb_destroy( lineinfo );
@@ -934,7 +934,7 @@ void parser_destroy()
al_destroy( forbidden_function );
free( forbidden_function );
-
+
}
/**
@@ -952,7 +952,7 @@ static void print_errors()
current_tokenizer_pos = err_pos;
fwprintf( stderr, L"%ls", parser_current_line() );
-
+
current_tokenizer_pos=tmp;
}
}
@@ -964,7 +964,7 @@ int eval_args( const wchar_t *line, array_list_t *args )
eval_args may be called while evaulating another command, so we
save the previous tokenizer and restore it on exit
*/
- tokenizer *previous_tokenizer=current_tokenizer;
+ tokenizer *previous_tokenizer=current_tokenizer;
int previous_pos=current_tokenizer_pos;
int do_loop=1;
tok_init( &tok, line, 0 );
@@ -987,12 +987,12 @@ int eval_args( const wchar_t *line, array_list_t *args )
do_loop=0;
break;
}
-
+
default:
{
break;
}
-
+
}
break;
@@ -1005,7 +1005,7 @@ int eval_args( const wchar_t *line, array_list_t *args )
tok_get_pos( &tok ),
TOK_ERR_MSG,
tok_last(&tok) );
-
+
do_loop=0;
break;
}
@@ -1015,7 +1015,7 @@ int eval_args( const wchar_t *line, array_list_t *args )
tok_get_pos( &tok ),
UNEXPECTED_TOKEN_ERR_MSG,
tok_get_desc( tok_last_type(&tok)) );
-
+
do_loop=0;
break;
@@ -1035,7 +1035,7 @@ void parser_stack_trace( block_t *b, string_buffer_t *buff)
{
if( !b )
return;
-
+
if( b->type == FUNCTION_CALL || b->type==SOURCE)
{
int i;
@@ -1048,31 +1048,31 @@ void parser_stack_trace( block_t *b, string_buffer_t *buff)
const wchar_t *file = b->param4.call_filename;
if( file )
- sb_printf( buff,
+ sb_printf( buff,
_(L"\tcalled on line %d of file '%ls',\n"),
- b->param3.call_lineno,
+ b->param3.call_lineno,
file );
else
- sb_printf( buff,
+ sb_printf( buff,
_(L"\tcalled on standard input,\n") );
-
+
if( al_get_count( &b->param2.function_vars ) )
{
string_buffer_t tmp;
sb_init( &tmp );
-
+
for( i=0; iparam2.function_vars ); i++ )
{
sb_append2( &tmp, i?L" ":L"", (wchar_t *)al_get( &b->param2.function_vars, i ), (void *)0 );
}
sb_printf( buff, _(L"\twith parameter list '%ls'\n"), (wchar_t *)tmp.buff );
-
+
sb_destroy( &tmp );
- }
- sb_printf( buff,
+ }
+ sb_printf( buff,
L"\n" );
- }
- parser_stack_trace( b->outer, buff );
+ }
+ parser_stack_trace( b->outer, buff );
}
static const wchar_t *is_function()
@@ -1098,7 +1098,7 @@ int parser_get_lineno()
int i;
const wchar_t *whole_str = tok_string( current_tokenizer );
const wchar_t *function_name;
-
+
int lineno = 1;
for( i=0; itype == FUNCTION_CALL )
{
return function_get_definition_file(b->param1.function_name );
}
b=b->outer;
- }
+ }
}
static int printed_width( const wchar_t *str, int len )
@@ -1167,18 +1167,18 @@ wchar_t *parser_current_line()
int current_line_width;
const wchar_t *function_name=0;
int current_line_start=0;
-
-
+
+
if( !line )
return L"";
-
+
if( !lineinfo )
{
lineinfo = malloc( sizeof(string_buffer_t) );
sb_init( lineinfo );
}
- sb_clear( lineinfo );
-
+ sb_clear( lineinfo );
+
/*
Calculate line number, line offset, etc.
*/
@@ -1197,7 +1197,7 @@ wchar_t *parser_current_line()
if( (function_name = is_function()) )
{
lineno += function_get_definition_offset( function_name );
- }
+ }
/*
Copy current line from whole string
@@ -1232,7 +1232,7 @@ wchar_t *parser_current_line()
}
// debug( 1, L"Current pos %d, line pos %d, file_length %d, is_interactive %d, offset %d\n", current_tokenizer_pos, current_line_pos, wcslen(whole_str), is_interactive, offset);
- /*
+ /*
Skip printing character position if we are in interactive mode
and the error was on the first character of the line.
*/
@@ -1249,12 +1249,12 @@ wchar_t *parser_current_line()
}
else
{
- sb_printf( lineinfo,
+ sb_printf( lineinfo,
L"%ls\n^\n",
line );
}
}
-
+
free( line );
parser_stack_trace( current_block, lineinfo );
@@ -1309,10 +1309,10 @@ static void parse_job_main_loop( process_t *p,
int proc_is_count=0;
int matched_wildcard = 0, unmatched_wildcard = 0;
-
+
wchar_t *unmatched = 0;
int unmatched_pos=0;
-
+
/*
Test if this is the 'count' command. We need to special case
count, since it should display a help message on 'count .h',
@@ -1327,12 +1327,12 @@ static void parse_job_main_loop( process_t *p,
woot++;
proc_is_count = wcscmp( woot, L"count" )==0;
}
-
+
while( 1 )
{
-
+
/* debug( 2, L"Read token %ls\n", wcsdup(tok_last( tok )) ); */
-
+
switch( tok_last_type( tok ) )
{
case TOK_PIPE:
@@ -1341,7 +1341,7 @@ static void parse_job_main_loop( process_t *p,
error( SYNTAX_ERROR,
tok_get_pos( tok ),
EXEC_ERR_MSG );
- return;
+ return;
}
p->pipe_fd = wcstol( tok_last( tok ), 0, 10 );
p->argv = list_to_char_arr( args );
@@ -1356,7 +1356,7 @@ static void parse_job_main_loop( process_t *p,
/*
Don't do anything on failiure. parse_job will notice the error flag beeing set
*/
-
+
}
is_finished = 1;
break;
@@ -1369,9 +1369,9 @@ static void parse_job_main_loop( process_t *p,
p->argv = list_to_char_arr( args );
if( tok_has_next(tok))
tok_next(tok);
-
+
is_finished = 1;
-
+
break;
}
@@ -1385,11 +1385,11 @@ static void parse_job_main_loop( process_t *p,
If this command should be skipped, we do not expand the arguments
*/
skip=1;
-
+
/*
But if this is in fact a case statement, then it should be evaluated
*/
-
+
if( (current_block->type == SWITCH) &&
(wcscmp( al_get( args, 0), L"case" )==0) &&
p->type == INTERNAL_BUILTIN )
@@ -1397,7 +1397,7 @@ static void parse_job_main_loop( process_t *p,
skip=0;
}
}
-
+
if( !skip )
{
if( proc_is_count &&
@@ -1410,7 +1410,7 @@ static void parse_job_main_loop( process_t *p,
p->type = INTERNAL_BUILTIN;
wcscpy( p->actual_cmd, L"count" );
}
-
+
switch( expand_string( wcsdup(tok_last( tok )), args, 0 ) )
{
@@ -1423,11 +1423,11 @@ static void parse_job_main_loop( process_t *p,
tok_get_pos( tok ),
_(L"Could not expand string '%ls'"),
tok_last(tok) );
-
+
}
break;
}
-
+
case EXPAND_WILDCARD_NO_MATCH:
{
unmatched_wildcard = 1;
@@ -1436,21 +1436,21 @@ static void parse_job_main_loop( process_t *p,
unmatched = wcsdup(tok_last( tok ));
unmatched_pos = tok_get_pos( tok );
}
-
+
break;
}
-
+
case EXPAND_WILDCARD_MATCH:
{
matched_wildcard = 1;
break;
}
-
+
case EXPAND_OK:
{
break;
}
-
+
}
}
@@ -1466,7 +1466,7 @@ static void parse_job_main_loop( process_t *p,
int type = tok_last_type( tok );
io_data_t *new_io;
wchar_t *target = 0;
-
+
/*
Don't check redirections in skipped part
@@ -1483,14 +1483,14 @@ static void parse_job_main_loop( process_t *p,
REDIRECT_TOKEN_ERR_MSG,
tok_get_desc( tok_last_type(tok)) );
}
-
+
break;
}
-
+
new_io = calloc( 1, sizeof(io_data_t) );
if( !new_io )
die_mem();
-
+
new_io->fd = wcstol( tok_last( tok ),
0,
10 );
@@ -1507,7 +1507,7 @@ static void parse_job_main_loop( process_t *p,
tok_get_pos( tok ),
REDIRECT_TOKEN_ERR_MSG,
tok_last( tok ) );
-
+
}
}
break;
@@ -1517,7 +1517,7 @@ static void parse_job_main_loop( process_t *p,
REDIRECT_TOKEN_ERR_MSG,
tok_get_desc( tok_last_type(tok)) );
}
-
+
if( target == 0 || wcslen( target )==0 )
{
if( error_code == 0 )
@@ -1528,7 +1528,7 @@ static void parse_job_main_loop( process_t *p,
}
else
{
-
+
switch( type )
{
@@ -1568,7 +1568,7 @@ static void parse_job_main_loop( process_t *p,
tok_get_pos( tok ),
_(L"Requested redirection to something that is not a file descriptor %ls"),
target );
-
+
tok_next(tok);
}
free(target);
@@ -1576,19 +1576,19 @@ static void parse_job_main_loop( process_t *p,
break;
}
}
-
+
j->io = io_add( j->io, new_io );
}
break;
case TOK_ERROR:
- {
+ {
error( SYNTAX_ERROR,
tok_get_pos( tok ),
TOK_ERR_MSG,
tok_last(tok) );
-
+
return;
}
@@ -1597,14 +1597,14 @@ static void parse_job_main_loop( process_t *p,
tok_get_pos( tok ),
UNEXPECTED_TOKEN_ERR_MSG,
tok_get_desc( tok_last_type(tok)) );
-
+
tok_next(tok);
break;
}
if( (is_finished) || (error_code != 0) )
break;
-
+
tok_next( tok );
}
@@ -1617,16 +1617,16 @@ static void parse_job_main_loop( process_t *p,
if( is_interactive && !is_block )
{
int tmp;
-
+
debug( 1, WILDCARD_ERR_MSG, unmatched );
tmp = current_tokenizer_pos;
current_tokenizer_pos = unmatched_pos;
fwprintf( stderr, L"%ls", parser_current_line() );
-
+
current_tokenizer_pos=tmp;
}
-
+
}
}
free( unmatched );
@@ -1651,10 +1651,10 @@ static int parse_job( process_t *p,
array_list_t args; // The list that will become the argc array for the program
int use_function = 1; // May functions be considered when checking what action this command represents
int use_builtin = 1; // May builtins be considered when checking what action this command represents
- int is_new_block=0; // Does this command create a new block?
+ int is_new_block=0; // Does this command create a new block?
+
+ block_t *prev_block = current_block;
- block_t *prev_block = current_block;
-
debug( 2, L"begin parse_job()\n" );
al_init( &args );
@@ -1677,20 +1677,20 @@ static int parse_job( process_t *p,
tok_get_pos( tok ),
ILLEGAL_CMD_ERR_MSG,
tok_last( tok ) );
-
+
al_destroy( &args );
return 0;
}
break;
}
-
+
case TOK_ERROR:
{
error( SYNTAX_ERROR,
tok_get_pos( tok ),
TOK_ERR_MSG,
tok_last(tok) );
-
+
al_destroy( &args );
return 0;
}
@@ -1712,23 +1712,23 @@ static int parse_job( process_t *p,
CMD_ERR_MSG,
tok_get_desc( tok_last_type(tok) ) );
}
-
+
al_destroy( &args );
return 0;
}
-
+
default:
{
error( SYNTAX_ERROR,
tok_get_pos( tok ),
CMD_ERR_MSG,
tok_get_desc( tok_last_type(tok) ) );
-
+
al_destroy( &args );
return 0;
}
}
-
+
int mark = tok_get_pos( tok );
if( wcscmp( L"command", nxt )==0 )
@@ -1783,7 +1783,7 @@ static int parse_job( process_t *p,
}
else
{
- j->skip = proc_get_last_status();
+ j->skip = proc_get_last_status();
free( nxt );
continue;
}
@@ -1797,7 +1797,7 @@ static int parse_job( process_t *p,
}
else
{
- j->skip = !proc_get_last_status();
+ j->skip = !proc_get_last_status();
free( nxt );
continue;
}
@@ -1810,10 +1810,10 @@ static int parse_job( process_t *p,
tok_get_pos( tok ),
EXEC_ERR_MSG );
al_destroy( &args );
- free(nxt);
+ free(nxt);
return 0;
}
-
+
tok_next( tok );
if( tok_last(tok)[0] == L'-' )
{
@@ -1823,7 +1823,7 @@ static int parse_job( process_t *p,
{
use_function = 0;
use_builtin=0;
- p->type=INTERNAL_EXEC;
+ p->type=INTERNAL_EXEC;
free( nxt );
continue;
}
@@ -1845,17 +1845,17 @@ static int parse_job( process_t *p,
{
new_block = 1;
}
-
+
if( new_block )
{
parser_push_block( WHILE );
current_block->param1.while_state=WHILE_TEST_FIRST;
current_block->tok_pos = mark;
}
-
+
free( nxt );
is_new_block=1;
-
+
continue;
}
else if( wcscmp( L"if", nxt ) ==0 )
@@ -1913,12 +1913,12 @@ static int parse_job( process_t *p,
{
p->type = INTERNAL_BUILTIN;
is_new_block = parser_is_block( (wchar_t *)al_get( &args, 0 ) );
- }
+ }
}
if( !p->type || (p->type == INTERNAL_EXEC) )
{
- /*
+ /*
If we are not executing the current block, allow
non-existent commands.
*/
@@ -1928,17 +1928,17 @@ static int parse_job( process_t *p,
}
else
{
-
+
p->actual_cmd = get_filename( (wchar_t *)al_get( &args, 0 ) );
debug( 2, L"filename '%ls' -> '%ls'", (wchar_t *)al_get( &args, 0 ), p->actual_cmd?p->actual_cmd:L"0" );
-
+
/*
Check if the specified command exists
*/
if( p->actual_cmd == 0 )
{
-
+
/*
That is not a command! Test if it is a
directory, in which case, we use 'cd' as the
@@ -1950,13 +1950,13 @@ static int parse_job( process_t *p,
{
wchar_t *tmp;
free( pp );
-
+
tmp = (wchar_t *)al_get( &args, 0 );
al_truncate( &args, 0 );
al_push( &args, wcsdup( L"cd" ) );
al_push( &args, tmp );
/*
- If we have defined a wrapper around cd, use it,
+ If we have defined a wrapper around cd, use it,
otherwise use the cd builtin
*/
if( function_exists( L"cd" ) )
@@ -1972,7 +1972,7 @@ static int parse_job( process_t *p,
tok_get_pos( tok ),
COMMAND_ASSIGN_ERR_MSG,
(wchar_t *)al_get( &args, 0 ) );
-
+
}
else
@@ -1981,7 +1981,7 @@ static int parse_job( process_t *p,
tok_get_pos( tok ),
_(L"Unknown command '%ls'"),
(wchar_t *)al_get( &args, 0 ) );
-
+
}
}
}
@@ -1991,11 +1991,11 @@ static int parse_job( process_t *p,
if( is_new_block )
{
- const wchar_t *end=parser_find_end( tok_string( tok ) +
+ const wchar_t *end=parser_find_end( tok_string( tok ) +
current_tokenizer_pos );
tokenizer subtok;
int make_sub_block = j->first_process != p;
-
+
if( !end )
{
error( SYNTAX_ERROR,
@@ -2010,7 +2010,7 @@ static int parse_job( process_t *p,
{
case TOK_END:
break;
-
+
case TOK_REDIRECT_OUT:
case TOK_REDIRECT_APPEND:
case TOK_REDIRECT_IN:
@@ -2018,9 +2018,9 @@ static int parse_job( process_t *p,
case TOK_PIPE:
{
make_sub_block = 1;
- break;
+ break;
}
-
+
default:
{
error( SYNTAX_ERROR,
@@ -2030,32 +2030,32 @@ static int parse_job( process_t *p,
}
tok_destroy( &subtok );
}
-
+
if( make_sub_block )
{
int end_pos = end-tok_string( tok );
- wchar_t *sub_block= wcsndup( tok_string( tok ) + current_tokenizer_pos,
+ wchar_t *sub_block= wcsndup( tok_string( tok ) + current_tokenizer_pos,
end_pos - current_tokenizer_pos);
-
+
p->type = INTERNAL_BLOCK;
free( (void *)al_get( &args, 0 ) );
al_set( &args, 0, sub_block );
- tok_set_pos( tok,
+ tok_set_pos( tok,
end_pos );
while( prev_block != current_block )
{
parser_pop_block();
}
-
+
}
else tok_next( tok );
-
+
}
else tok_next( tok );
-
+
if( !error_code )
{
if( p->type == INTERNAL_BUILTIN && parser_skip_arguments( (wchar_t *)al_get(&args, 0) ) )
@@ -2068,7 +2068,7 @@ static int parse_job( process_t *p,
parse_job_main_loop( p, j, tok, &args );
}
}
-
+
if( error_code )
{
/*
@@ -2077,8 +2077,8 @@ static int parse_job( process_t *p,
*/
al_foreach( &args,
(void (*)(const void *))&free );
- free(p->argv);
- p->argv=0;
+ free(p->argv);
+ p->argv=0;
/*
Make sure the block stack is consistent
*/
@@ -2086,10 +2086,10 @@ static int parse_job( process_t *p,
{
parser_pop_block();
}
-
+
}
al_destroy( &args );
-
+
// debug( 2, L"end parse_job()\n" );
return !error_code;
}
@@ -2100,7 +2100,7 @@ static int parse_job( process_t *p,
preformed.
\param j the job to execute
-
+
*/
static void skipped_exec( job_t * j )
{
@@ -2154,7 +2154,7 @@ static void skipped_exec( job_t * j )
\param tok The tokenizer to read tokens from
*/
-
+
static void eval_job( tokenizer *tok )
{
job_t *j;
@@ -2168,12 +2168,12 @@ static void eval_job( tokenizer *tok )
if( profile )
{
p=malloc( sizeof(profile_element_t));
- p->cmd=0;
+ p->cmd=0;
al_push( &profile_data, p );
p->skipped=1;
t1 = get_time();
}
-
+
switch( tok_last_type( tok ) )
{
case TOK_STRING:
@@ -2183,9 +2183,9 @@ static void eval_job( tokenizer *tok )
j->fg=1;
j->constructed=0;
j->skip_notification = is_subshell || is_block || is_event || (!is_interactive);
-
+
current_block->job = j;
-
+
if( is_interactive )
{
if( tcgetattr (0, &j->tmodes) )
@@ -2196,7 +2196,7 @@ static void eval_job( tokenizer *tok )
break;
}
}
-
+
j->first_process = calloc( 1, sizeof( process_t ) );
@@ -2206,35 +2206,35 @@ static void eval_job( tokenizer *tok )
if( job_start_pos < tok_get_pos( tok ) )
{
int stop_pos = tok_get_pos( tok );
- wchar_t *newline = wcschr( tok_string(tok)+start_pos,
+ wchar_t *newline = wcschr( tok_string(tok)+start_pos,
L'\n' );
if( newline )
stop_pos = mini( stop_pos, newline - tok_string(tok) );
-
+
j->command = wcsndup( tok_string(tok)+start_pos,
stop_pos-start_pos );
}
else
j->command = wcsdup( L"" );
-
+
if( profile )
{
t2 = get_time();
- p->cmd = wcsdup( j->command );
+ p->cmd = wcsdup( j->command );
p->skipped=current_block->skip;
}
-
+
skip |= current_block->skip;
skip |= j->wildcard_error;
skip |= j->skip;
-
+
if(!skip )
{
int was_builtin = 0;
// if( j->first_process->type==INTERNAL_BUILTIN && !j->first_process->next)
// was_builtin = 1;
-
- exec( j );
+
+ exec( j );
/* Only external commands require a new fishd barrier */
if( !was_builtin )
@@ -2242,9 +2242,9 @@ static void eval_job( tokenizer *tok )
}
else
{
- skipped_exec( j );
+ skipped_exec( j );
}
-
+
if( profile )
{
t3 = get_time();
@@ -2255,7 +2255,7 @@ static void eval_job( tokenizer *tok )
if( current_block->type == WHILE )
{
-
+
switch( current_block->param1.while_state )
{
case WHILE_TEST_FIRST:
@@ -2276,7 +2276,7 @@ static void eval_job( tokenizer *tok )
current_block->param1.if_state++;
}
}
-
+
}
else
{
@@ -2290,7 +2290,7 @@ static void eval_job( tokenizer *tok )
current_block->job = 0;
break;
}
-
+
case TOK_END:
{
if( tok_has_next( tok ))
@@ -2315,33 +2315,33 @@ static void eval_job( tokenizer *tok )
CMD_ERR_MSG,
tok_get_desc( tok_last_type(tok) ) );
}
-
+
return;
}
-
+
case TOK_ERROR:
{
error( SYNTAX_ERROR,
tok_get_pos( tok ),
TOK_ERR_MSG,
tok_last(tok) );
-
+
return;
}
-
+
default:
{
error( SYNTAX_ERROR,
tok_get_pos( tok ),
CMD_ERR_MSG,
tok_get_desc( tok_last_type(tok)) );
-
+
return;
}
}
-
+
job_reap( 0 );
-
+
// debug( 2, L"end eval_job()\n" );
}
@@ -2358,16 +2358,16 @@ int eval( const wchar_t *cmd, io_data_t *io, int block_type )
{
forbidden_function = al_new();
}
-
+
forbid_count = al_get_count( forbidden_function );
-
+
block_io = io;
-
+
job_reap( 0 );
debug( 4, L"eval: %ls", cmd );
-
-
+
+
if( !cmd )
{
debug( 1,
@@ -2378,30 +2378,30 @@ int eval( const wchar_t *cmd, io_data_t *io, int block_type )
return 1;
}
- if( (block_type!=TOP) &&
+ if( (block_type!=TOP) &&
(block_type != FUNCTION_CALL) &&
(block_type != SUBST))
{
debug( 1,
INVALID_SCOPE_ERR_MSG,
parser_get_block_desc( block_type ) );
-
+
debug( 1,
BUGREPORT_MSG,
PACKAGE_BUGREPORT );
return 1;
}
-
+
eval_level++;
current_tokenizer = malloc( sizeof(tokenizer));
-
+
parser_push_block( block_type );
-
-
+
+
tok_init( current_tokenizer, cmd, 0 );
error_code = 0;
-
- event_fire( 0 );
+
+ event_fire( 0 );
while( tok_has_next( current_tokenizer ) &&
!error_code &&
@@ -2409,11 +2409,11 @@ int eval( const wchar_t *cmd, io_data_t *io, int block_type )
!exit_status() )
{
eval_job( current_tokenizer );
- event_fire( 0 );
+ event_fire( 0 );
}
-
- int prev_block_type = current_block->type;
-
+
+ int prev_block_type = current_block->type;
+
parser_pop_block();
while( start_current_block != current_block )
@@ -2423,31 +2423,31 @@ int eval( const wchar_t *cmd, io_data_t *io, int block_type )
debug( 0,
_(L"End of block mismatch. Program terminating.") );
debug( 0,
- BUGREPORT_MSG,
+ BUGREPORT_MSG,
PACKAGE_BUGREPORT );
exit(1);
break;
}
-
+
if( (!error_code) && (!exit_status()) && (!proc_get_last_status()) )
{
char *h;
//debug( 2, L"Status %d\n", proc_get_last_status() );
- debug( 1,
+ debug( 1,
L"%ls", parser_get_block_desc( current_block->type ) );
- debug( 1,
+ debug( 1,
BLOCK_END_ERR_MSG );
fwprintf( stderr, L"%ls", parser_current_line() );
-
+
h = builtin_help_get( L"end" );
if( h )
fwprintf( stderr, L"%s", h );
break;
-
+
}
- prev_block_type = current_block->type;
+ prev_block_type = current_block->type;
parser_pop_block();
}
@@ -2462,15 +2462,15 @@ int eval( const wchar_t *cmd, io_data_t *io, int block_type )
if( block_type == SUBST )
{
al_destroy( forbidden_function );
- free( forbidden_function );
+ free( forbidden_function );
}
-
- /*
+
+ /*
Restore previous eval state
*/
- forbidden_function = prev_forbidden;
+ forbidden_function = prev_forbidden;
current_tokenizer=previous_tokenizer;
- block_io = prev_io;
+ block_io = prev_io;
eval_level--;
code=error_code;
@@ -2497,9 +2497,9 @@ int parser_test( wchar_t * buff,
int forbid_pipeline = 0;
int needs_cmd=0;
int require_additional_commands=0;
-
+
current_tokenizer = &tok;
-
+
for( tok_init( &tok, buff, 0 );
tok_has_next( &tok ) && !err;
tok_next( &tok ) )
@@ -2515,7 +2515,7 @@ int parser_test( wchar_t * buff,
{
int mark = tok_get_pos( &tok );
had_cmd = 1;
-
+
if( require_additional_commands )
{
if( contains_str( tok_last(&tok),
@@ -2524,15 +2524,15 @@ int parser_test( wchar_t * buff,
{
err=1;
if( babble )
- {
+ {
error( SYNTAX_ERROR,
tok_get_pos( &tok ),
COND_ERR_MSG );
-
- print_errors();
+
+ print_errors();
}
}
-
+
require_additional_commands--;
}
@@ -2545,7 +2545,7 @@ int parser_test( wchar_t * buff,
count--;
tok_set_pos( &tok, mark );
}
-
+
/*
Handle block commands
*/
@@ -2553,10 +2553,10 @@ int parser_test( wchar_t * buff,
{
if( count >= BLOCK_MAX_COUNT )
{
- error( SYNTAX_ERROR,
- tok_get_pos( &tok ),
+ error( SYNTAX_ERROR,
+ tok_get_pos( &tok ),
BLOCK_ERR_MSG );
-
+
print_errors();
}
else
@@ -2573,11 +2573,11 @@ int parser_test( wchar_t * buff,
block_type[count] = FUNCTION_DEF;
else if( wcscmp( tok_last(&tok), L"begin") == 0 )
block_type[count] = BEGIN;
- else
- block_type[count] = -1;
-
+ else
+ block_type[count] = -1;
+
// debug( 2, L"add block of type %d after cmd %ls\n", block_type[count], tok_last(&tok) );
-
+
block_pos[count] = current_tokenizer_pos;
tok_next( &tok );
@@ -2585,7 +2585,7 @@ int parser_test( wchar_t * buff,
tok_set_pos( &tok, mark );
}
}
-
+
/*
If parser_is_subcommand is true, the command
accepts a second command as it's first
@@ -2610,18 +2610,18 @@ int parser_test( wchar_t * buff,
{
err=1;
if( babble )
- {
+ {
error( SYNTAX_ERROR,
tok_get_pos( &tok ),
EXEC_ERR_MSG );
-
- print_errors();
-
+
+ print_errors();
+
}
}
require_additional_commands=1;
}
-
+
/*
There are a lot of situations where pipelines
are forbidden, inclusing when using the exec
@@ -2633,18 +2633,18 @@ int parser_test( wchar_t * buff,
{
err=1;
if( babble )
- {
+ {
error( SYNTAX_ERROR,
tok_get_pos( &tok ),
EXEC_ERR_MSG );
-
- print_errors();
-
+
+ print_errors();
+
}
}
- forbid_pipeline = 1;
+ forbid_pipeline = 1;
}
-
+
/*
Test that the case builtin is only used in a switch block
*/
@@ -2653,25 +2653,25 @@ int parser_test( wchar_t * buff,
if( !count || block_type[count-1]!=SWITCH )
{
err=1;
-
+
// debug( 2, L"Error on block type %d\n", block_type[count-1] );
-
+
if( babble )
{
error( SYNTAX_ERROR,
tok_get_pos( &tok ),
INVALID_CASE_ERR_MSG );
-
+
print_errors();
}
}
- }
+ }
/*
Test that break and continue are only used in loop blocks
*/
- if( wcscmp( L"break", tok_last( &tok ) )==0 ||
+ if( wcscmp( L"break", tok_last( &tok ) )==0 ||
wcscmp( L"continue", tok_last( &tok ) )==0)
{
int found_loop=0;
@@ -2685,11 +2685,11 @@ int parser_test( wchar_t * buff,
break;
}
}
-
+
if( !found_loop )
{
err=1;
-
+
if( babble )
{
error( SYNTAX_ERROR,
@@ -2697,9 +2697,9 @@ int parser_test( wchar_t * buff,
INVALID_LOOP_ERR_MSG );
print_errors();
}
- }
+ }
}
-
+
/*
Test that else is only used in an if-block
*/
@@ -2713,13 +2713,13 @@ int parser_test( wchar_t * buff,
error( SYNTAX_ERROR,
tok_get_pos( &tok ),
INVALID_ELSE_ERR_MSG );
-
+
print_errors();
}
}
}
-
+
/*
Test that end is not used when not inside a blovk
*/
@@ -2732,7 +2732,7 @@ int parser_test( wchar_t * buff,
tok_get_pos( &tok ),
INVALID_END_ERR_MSG );
print_errors();
- }
+ }
}
}
break;
@@ -2761,7 +2761,7 @@ int parser_test( wchar_t * buff,
{
if( needs_cmd && !had_cmd )
{
- err = 1;
+ err = 1;
if( babble )
{
error( SYNTAX_ERROR,
@@ -2770,10 +2770,10 @@ int parser_test( wchar_t * buff,
tok_get_desc( tok_last_type(&tok)));
print_errors();
}
- }
- needs_cmd=0;
+ }
+ needs_cmd=0;
had_cmd = 0;
- is_pipeline=0;
+ is_pipeline=0;
forbid_pipeline=0;
break;
}
@@ -2784,35 +2784,35 @@ int parser_test( wchar_t * buff,
{
err=1;
if( babble )
- {
+ {
error( SYNTAX_ERROR,
tok_get_pos( &tok ),
EXEC_ERR_MSG );
-
- print_errors();
+
+ print_errors();
}
}
- needs_cmd=0;
+ needs_cmd=0;
is_pipeline=1;
}
-
+
case TOK_BACKGROUND:
{
if( needs_cmd && !had_cmd )
{
- err = 1;
+ err = 1;
if( babble )
{
error( SYNTAX_ERROR,
tok_get_pos( &tok ),
CMD_ERR_MSG,
tok_get_desc( tok_last_type(&tok)));
-
+
print_errors();
}
- }
-
+ }
+
if( had_cmd )
{
had_cmd = 0;
@@ -2829,29 +2829,29 @@ int parser_test( wchar_t * buff,
tok_get_pos( &tok ),
TOK_ERR_MSG,
tok_last(&tok) );
-
-
+
+
print_errors();
//debug( 2, tok_last( &tok) );
}
break;
}
}
-
+
if( require_additional_commands )
{
err=1;
if( babble )
- {
+ {
error( SYNTAX_ERROR,
- tok_get_pos( &tok ),
+ tok_get_pos( &tok ),
COND_ERR_MSG );
-
- print_errors();
+
+ print_errors();
}
}
-
-
+
+
if( babble && count>0 )
{
error( SYNTAX_ERROR,
@@ -2859,9 +2859,9 @@ int parser_test( wchar_t * buff,
BLOCK_END_ERR_MSG );
print_errors();
}
-
+
tok_destroy( &tok );
-
+
current_tokenizer=previous_tokenizer;
current_tokenizer_pos = previous_pos;
diff --git a/reader.c b/reader.c
index 8d6b5a2c6..4fdd693d0 100644
--- a/reader.c
+++ b/reader.c
@@ -321,14 +321,14 @@ static void term_donate()
break;
}
-
+
}
/**
Grab control of terminal
*/
static void term_steal()
-{
+{
while( 1 )
{
@@ -345,7 +345,7 @@ static void term_steal()
break;
}
- common_handle_winch(0 );
+ common_handle_winch(0 );
if( tcsetattr(0,TCSANOW,&old_modes))/* return to previous mode */
{
@@ -431,7 +431,7 @@ static int check_size()
data->new_color == 0 )
{
die_mem();
-
+
}
}
return 1;
@@ -510,7 +510,7 @@ static int calc_output()
{
data->output[0]=ellipsis_char;
data->output[1]=0;
-
+
}
wcsncat( data->output,
@@ -520,7 +520,7 @@ static int calc_output()
if( offset_endbuff_len )
{
int l = wcslen(data->output);
-
+
data->output[l]=ellipsis_char;
data->output[l+1]=0;
@@ -537,7 +537,7 @@ static int calc_output()
/**
- Compare two completions, ignoring their description.
+ Compare two completions, ignoring their description.
*/
static int fldcmp( wchar_t *a, wchar_t *b )
{
@@ -606,7 +606,7 @@ void reader_write_title()
wchar_t *title;
array_list_t l;
wchar_t *term = env_get( L"TERM" );
-
+
/*
This is a pretty lame heuristic for detecting terminals that do
not support setting the title. If we recognise the terminal name
@@ -650,16 +650,16 @@ void reader_write_title()
static int try_sequence( char *seq, wchar_t *str )
{
int i;
-
+
for( i=0;; i++ )
{
if( !seq[i] )
return i;
-
+
if( seq[i] != str[i] )
return 0;
}
-
+
return 0;
}
@@ -672,11 +672,11 @@ static int calc_prompt_width( array_list_t *arr )
{
int res = 0;
int i, j, k;
-
+
for( i=0; ibuff_len;
-
+
data->buff_len += len;
check_size();
-
+
/* Insert space for extra characters at the right position */
if( data->buff_pos < old_len )
{
@@ -1168,17 +1168,17 @@ static int insert_str(wchar_t *str)
data->buff[data->buff_len]='\0';
/* Syntax highlight */
-
+
reader_super_highlight_me_plenty( data->buff,
data->new_color,
data->buff_pos-1,
0 );
memcpy( data->color, data->new_color, sizeof(int) * data->buff_len );
-
+
/* repaint */
repaint();
-
+
}
return 1;
}
@@ -1409,49 +1409,49 @@ static void run_pager( wchar_t *prefix, int is_quoted, array_list_t *comp )
prefix_esc = escape( prefix,1);
sb_init( &cmd );
- sb_printf( &cmd,
- L"fish_pager %d %ls",
- is_quoted,
+ sb_printf( &cmd,
+ L"fish_pager %d %ls",
+ is_quoted,
prefix_esc );
-
+
free( prefix_esc );
-
+
for( i=0; iparam2.out_buffer, &nil, 1 );
-
+
wchar_t *tmp;
wchar_t *str = str2wcs((char *)out->param2.out_buffer->buff);
-
+
if( str )
{
for( tmp = str + wcslen(str)-1; tmp >= str; tmp-- )
{
input_unreadch( *tmp );
- }
+ }
free( str );
}
-
+
io_buffer_destroy( out);
-
+
}
/**
@@ -1527,7 +1527,7 @@ static int handle_completions( array_list_t *comp )
0 );
len = &data->buff[data->buff_pos]-prefix_start+1;
-
+
if( len <= PREFIX_MAX_LEN )
{
prefix = malloc( sizeof(wchar_t)*(len+1) );
@@ -1542,11 +1542,11 @@ static int handle_completions( array_list_t *comp )
0
}
;
-
+
prefix = wcsdupcat( tmp,
prefix_start + (len - PREFIX_MAX_LEN) );
prefix[PREFIX_MAX_LEN] = 0;
-
+
}
{
@@ -1559,7 +1559,7 @@ static int handle_completions( array_list_t *comp )
writech(L'\n');
run_pager( prefix, is_quoted, comp );
-
+
/*
Try to print a list of completions. First try with five
@@ -1638,8 +1638,8 @@ static void reader_interactive_init()
history_init();
- common_handle_winch(0);
-
+ common_handle_winch(0);
+
tcgetattr(0,&shell_modes); /* get the current terminal modes */
memcpy( &saved_modes,
&shell_modes,
@@ -1744,7 +1744,7 @@ static void handle_history( const wchar_t *new_str )
Check if the specified string is contained in the list, using
wcscmp as a comparison function
*/
-static int contains( const wchar_t *needle,
+static int contains( const wchar_t *needle,
array_list_t *haystack )
{
int i;
@@ -1754,7 +1754,7 @@ static int contains( const wchar_t *needle,
return 1;
}
return 0;
-
+
}
/**
@@ -1771,7 +1771,7 @@ static void reset_token_history()
}
else
data->search_buff[0]=0;
-
+
data->token_history_pos = -1;
data->search_pos=0;
al_foreach( &data->search_prev, (void (*)(const void *))&free );
@@ -1798,7 +1798,7 @@ static void handle_token_history( int forward, int reset )
Start a new token search using the current token
*/
reset_token_history();
-
+
}
@@ -1851,13 +1851,13 @@ static void handle_token_history( int forward, int reset )
}
else
{
- return;
- }
+ return;
+ }
}
else
{
- debug( 3, L"new '%ls'", data->token_history_buff );
+ debug( 3, L"new '%ls'", data->token_history_buff );
for( tok_init( &tok, data->token_history_buff, TOK_ACCEPT_UNFINISHED );
tok_has_next( &tok);
@@ -1882,7 +1882,7 @@ static void handle_token_history( int forward, int reset )
data->token_history_pos = tok_get_pos( &tok );
str = wcsdup(tok_last( &tok ));
}
-
+
}
}
}
@@ -1890,7 +1890,7 @@ static void handle_token_history( int forward, int reset )
tok_destroy( &tok );
}
-
+
if( str )
{
reader_replace_current_token( str );
@@ -1912,10 +1912,10 @@ static void handle_token_history( int forward, int reset )
Move buffer position one word or erase one word. This function
updates both the internal buffer and the screen. It is used by
M-left, M-right and ^W to do block movement or block erase.
-
+
\param dir Direction to move/erase. 0 means move left, 1 means move right.
\param erase Whether to erase the characters along the way or only move past them.
-
+
*/
static void move_word( int dir, int erase )
{
@@ -1952,7 +1952,7 @@ static void move_word( int dir, int erase )
if( !dir )
end_buff_pos -= step;
mode++;
- }
+ }
break;
/*
case 2:
@@ -1985,9 +1985,9 @@ static void move_word( int dir, int erase )
data->buff_len -= remove_count;
data->buff_pos = first_char;
data->buff[data->buff_len]=0;
-
+
reader_super_highlight_me_plenty( data->buff, data->color, data->buff_pos, 0 );
-
+
repaint();
}
else
@@ -2063,7 +2063,7 @@ int reader_get_cursor_pos()
void reader_run_command( wchar_t *cmd )
{
-
+
wchar_t *ft;
ft= tok_first( cmd );
@@ -2073,12 +2073,12 @@ void reader_run_command( wchar_t *cmd )
free(ft);
reader_write_title();
-
+
term_donate();
-
+
eval( cmd, 0, TOP );
job_reap( 1 );
-
+
term_steal();
env_set( L"_", L"fish", ENV_GLOBAL );
@@ -2087,7 +2087,7 @@ void reader_run_command( wchar_t *cmd )
proc_update_jiffies();
#endif
-
+
}
@@ -2161,11 +2161,11 @@ void reader_pop()
Clean up after history search
*/
al_foreach( &n->search_prev, (void (*)(const void *))&free );
- al_destroy( &n->search_prev );
+ al_destroy( &n->search_prev );
free( (void *)n->token_history_buff);
-
+
free(n);
-
+
if( data == 0 )
{
reader_interactive_destroy();
@@ -2271,9 +2271,9 @@ static int read_i()
that we can handle a call to reader_set_buffer
during evaluation.
*/
-
+
tmp = wcsdup( reader_readline() );
-
+
data->buff_pos=data->buff_len=0;
data->buff[data->buff_len]=L'\0';
reader_run_command( tmp );
@@ -2308,7 +2308,7 @@ static int can_read( int fd )
{
struct timeval can_read_timeout = { 0, 0 };
fd_set fds;
-
+
FD_ZERO(&fds);
FD_SET(fd, &fds);
return select(fd + 1, &fds, 0, 0, &can_read_timeout) == 1;
@@ -2378,13 +2378,13 @@ wchar_t *reader_readline()
wchar_t arr[READAHEAD_MAX+1];
int i;
-
+
memset( arr, 0, sizeof( arr ) );
arr[0] = c;
-
+
for( i=1; icomplete_func )
break;
@@ -2509,10 +2509,10 @@ wchar_t *reader_readline()
wchar_t *str = wcsndup( data->buff, data->buff_pos );
if( !str )
die_mem();
-
+
kill_add( str );
free( str );
-
+
data->buff_len = wcslen(data->buff +data->buff_pos);
memmove( data->buff, data->buff +data->buff_pos, sizeof(wchar_t)*data->buff_len );
data->buff[data->buff_len]=L'\0';
@@ -2544,7 +2544,7 @@ wchar_t *reader_readline()
// wcscpy(data->search_buff,data->buff);
break;
}
-
+
/* rotate killring*/
case R_YANK_POP:
{
@@ -2559,16 +2559,16 @@ wchar_t *reader_readline()
}
break;
}
-
+
/* Escape was pressed */
case L'\e':
{
if( *data->search_buff )
{
if( data->token_history_pos==-1 )
- {
+ {
history_reset();
- reader_set_buffer( data->search_buff,
+ reader_set_buffer( data->search_buff,
wcslen(data->search_buff ) );
}
else
@@ -2577,26 +2577,26 @@ wchar_t *reader_readline()
}
*data->search_buff=0;
check_colors();
-
+
}
-
+
break;
}
-
+
/* delete backward*/
case R_BACKWARD_DELETE_CHAR:
{
remove_backward();
break;
}
-
+
/* delete forward*/
case R_DELETE_CHAR:
{
remove_forward();
break;
}
-
+
/* exit, but only if line is empty */
case R_EXIT:
{
@@ -2607,7 +2607,7 @@ wchar_t *reader_readline()
}
break;
}
-
+
/* Newline, evaluate*/
case L'\n':
{
@@ -2633,7 +2633,7 @@ wchar_t *reader_readline()
writech('\n');
repaint();
}
-
+
break;
}
@@ -2650,7 +2650,7 @@ wchar_t *reader_readline()
handle_history(history_prev_match(data->search_buff));
break;
}
-
+
/* History down */
case R_HISTORY_SEARCH_FORWARD:
{
@@ -2664,7 +2664,7 @@ wchar_t *reader_readline()
handle_history(history_next_match(data->search_buff));
break;
}
-
+
/* Token search for a earlier match */
case R_HISTORY_TOKEN_SEARCH_BACKWARD:
{
@@ -2697,7 +2697,7 @@ wchar_t *reader_readline()
break;
}
-
+
/* Move left*/
case R_BACKWARD_CHAR:
if( data->buff_pos > 0 )
@@ -2735,7 +2735,7 @@ wchar_t *reader_readline()
}
break;
}
-
+
case R_DELETE_LINE:
{
data->buff[0]=0;
@@ -2744,35 +2744,35 @@ wchar_t *reader_readline()
repaint();
break;
}
-
+
/* kill one word left */
case R_BACKWARD_KILL_WORD:
{
move_word(0,1);
break;
}
-
+
/* kill one word right */
case R_KILL_WORD:
{
move_word(1,1);
break;
}
-
+
/* move one word left*/
case R_BACKWARD_WORD:
{
move_word(0,0);
break;
}
-
+
/* move one word right*/
case R_FORWARD_WORD:
{
move_word( 1,0);
break;
}
-
+
case R_CLEAR_SCREEN:
{
writembs( clear_screen );
@@ -2813,7 +2813,7 @@ wchar_t *reader_readline()
data->search_buff[0]=0;
history_reset();
data->token_history_pos=-1;
-
+
}
@@ -2845,21 +2845,21 @@ static int read_ni( int fd )
int des = fd == 0 ? dup(0) : fd;
int res=0;
-
+
if (des == -1)
{
wperror( L"dup" );
return 1;
}
-
+
b_init( &acc );
-
+
in_stream = fdopen( des, "r" );
if( in_stream != 0 )
{
wchar_t *str;
int acc_used;
-
+
while(!feof( in_stream ))
{
char buff[4096];
@@ -2868,7 +2868,7 @@ static int read_ni( int fd )
c = fread(buff, 1, 4096, in_stream);
if( ferror( in_stream ) )
{
- debug( 1,
+ debug( 1,
_( L"Error while reading commands" ) );
/*
@@ -2877,7 +2877,7 @@ static int read_ni( int fd )
acc.used=0;
break;
}
-
+
b_append( &acc, buff, c );
}
b_append( &acc, "\0", 1 );
@@ -2887,16 +2887,16 @@ static int read_ni( int fd )
if( fclose( in_stream ))
{
- debug( 1,
+ debug( 1,
_( L"Error while closing input stream" ) );
wperror( L"fclose" );
res = 1;
}
-
+
// fwprintf( stderr, L"Woot is %d chars\n", wcslen( acc.buff ) );
-
+
if( str )
- {
+ {
if( !parser_test( str, 1 ) )
{
//fwprintf( stderr, L"We parse it\n" );
@@ -2916,21 +2916,21 @@ static int read_ni( int fd )
if( acc_used > 1 )
{
debug( 1,
- _( L"Could not convert input. Read %d bytes." ),
+ _( L"Could not convert input. Read %d bytes." ),
acc_used-1 );
}
else
{
- debug( 1,
+ debug( 1,
_( L"Could not read input stream" ) );
}
- res=1;
- }
+ res=1;
+ }
}
else
{
- debug( 1,
+ debug( 1,
_( L"Error while opening input stream" ) );
wperror( L"fdopen" );
free( buff );
@@ -2949,18 +2949,18 @@ int reader_read( int fd )
original state. We also update the signal handlers.
*/
int shell_was_interactive = is_interactive;
-
+
is_interactive = ((fd == 0) && isatty(STDIN_FILENO));
signal_set_handlers();
-
+
res= is_interactive?read_i():read_ni( fd );
-
+
/*
If the exit command was called in a script, only exit the
script, not the program
*/
end_loop = 0;
-
+
is_interactive = shell_was_interactive;
signal_set_handlers();
return res;
diff --git a/tokenizer.c b/tokenizer.c
index 8f5b841fd..435281b7b 100644
--- a/tokenizer.c
+++ b/tokenizer.c
@@ -116,15 +116,15 @@ static void tok_error( tokenizer *tok, const wchar_t *err )
void tok_init( tokenizer *tok, const wchar_t *b, int flags )
{
// fwprintf( stderr, L"CREATE: \'%ls\'\n", b );
-
+
memset( tok, 0, sizeof( tokenizer) );
-
+
tok->accept_unfinished = flags & TOK_ACCEPT_UNFINISHED;
tok->show_comments = flags & TOK_SHOW_COMMENTS;
- tok->has_next=1;
+ tok->has_next=1;
- /*
+ /*
Before we copy the buffer we need to check that it is not
null. But before that, we need to init the tokenizer far enough
so that errors can be properly flagged
@@ -137,7 +137,7 @@ void tok_init( tokenizer *tok, const wchar_t *b, int flags )
tok->has_next = (*b != L'\0');
tok->orig_buff = tok->buff = (wchar_t *)(b);
-
+
if( tok->accept_unfinished )
{
int l = wcslen( tok->orig_buff );
@@ -149,7 +149,7 @@ void tok_init( tokenizer *tok, const wchar_t *b, int flags )
tok->orig_buff = tok->buff = wcsdup( tok->orig_buff );
if( !tok->orig_buff )
{
- die_mem();
+ die_mem();
}
tok->orig_buff[l-1] = L'\0';
}
@@ -223,7 +223,7 @@ static void read_string( tokenizer *tok )
while( 1 )
{
-
+
if( !myal( *tok->buff ) )
{
// debug(1, L"%lc", *tok->buff );
@@ -260,7 +260,7 @@ static void read_string( tokenizer *tok )
mode = 1;
break;
}
-
+
case L'[':
{
if( tok->buff != start )
@@ -271,7 +271,7 @@ static void read_string( tokenizer *tok )
case L'\'':
case L'"':
{
-
+
wchar_t *end = quote_end( tok->buff );
tok->last_quote = *tok->buff;
if( end )
@@ -281,14 +281,14 @@ static void read_string( tokenizer *tok )
else
{
tok->buff += wcslen( tok->buff );
-
+
if( (!tok->accept_unfinished) )
{
tok_error( tok, EOL_ERROR );
return;
}
do_loop = 0;
-
+
}
break;
}
@@ -303,7 +303,7 @@ static void read_string( tokenizer *tok )
}
break;
}
-
+
case 3:
case 1:
switch( *tok->buff )
@@ -355,7 +355,7 @@ static void read_string( tokenizer *tok )
break;
}
}
-
+
if( !do_loop )
break;
@@ -408,7 +408,7 @@ static void read_comment( tokenizer *tok )
static void read_redirect( tokenizer *tok, int fd )
{
int mode = -1;
-
+
if( (*tok->buff == L'>') ||
(*tok->buff == L'^') )
{
@@ -430,7 +430,7 @@ static void read_redirect( tokenizer *tok, int fd )
tok_error( tok, PIPE_ERROR );
return;
}
- check_size( tok, FD_STR_MAX_LEN );
+ check_size( tok, FD_STR_MAX_LEN );
tok->buff++;
swprintf( tok->last, FD_STR_MAX_LEN, L"%d", fd );
tok->last_type = TOK_PIPE;
@@ -446,14 +446,14 @@ static void read_redirect( tokenizer *tok, int fd )
{
tok_error( tok, REDIRECT_ERROR);
}
-
+
if( !check_size( tok, 2 ))
{
return;
}
-
+
swprintf( tok->last, tok->last_len, L"%d", fd );
-
+
if( *tok->buff == L'&' )
{
tok->buff++;
@@ -496,10 +496,10 @@ void tok_next( tokenizer *tok )
if( tok_last_type( tok ) == TOK_ERROR )
{
- tok->has_next=0;
- return;
+ tok->has_next=0;
+ return;
}
-
+
if( !tok->has_next )
{
/* wprintf( L"EOL\n" );*/
@@ -551,9 +551,9 @@ void tok_next( tokenizer *tok )
case L'|':
check_size( tok, 2 );
-
+
tok->last[0]=L'1';
- tok->last[1]=L'\0';
+ tok->last[1]=L'\0';
tok->last_type = TOK_PIPE;
tok->buff++;
break;
@@ -567,9 +567,9 @@ void tok_next( tokenizer *tok )
default:
{
-
+
if( iswdigit( *tok->buff ) )
- {
+ {
wchar_t *orig = tok->buff;
int fd = 0;
while( iswdigit( *tok->buff ) )
@@ -583,11 +583,11 @@ void tok_next( tokenizer *tok )
read_redirect( tok, fd );
return;
}
- tok->buff = orig;
+ tok->buff = orig;
}
read_string( tok );
}
-
+
}
}
@@ -603,7 +603,7 @@ wchar_t *tok_first( const wchar_t *str )
wchar_t *res=0;
tok_init( &t, str, 0 );
-
+
switch( tok_last_type( &t ) )
{
case TOK_STRING: