diff options
author | 2006-06-05 06:14:51 +1000 | |
---|---|---|
committer | 2006-06-05 06:14:51 +1000 | |
commit | 04b142208d6a62a24cc067df437e0af4b8a1f4ca (patch) | |
tree | b7af8ff58df2acc3587dc4fb665ca082373108fe /builtin_set.c | |
parent | cf35a8e3a5ee724f12f13175d81d89b8d74c997c (diff) |
Make it possible to specify scope of a variable to be erased or tested. Also make sure set exits with a non-zero exit status when erasing fails.
darcs-hash:20060604201451-ac50b-4ea0212c513b33be40559dfe8d65c1446c53f682.gz
Diffstat (limited to 'builtin_set.c')
-rw-r--r-- | builtin_set.c | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/builtin_set.c b/builtin_set.c index 0b888f08..bb52df1f 100644 --- a/builtin_set.c +++ b/builtin_set.c @@ -256,8 +256,7 @@ static int parse_index( array_list_t *indexes, indexes. The previous entries at the specidied position will be free'd. - \return The number of elements in the list after the modifications - have been made + \return 0 if the operation was successfull, non-zero otherwise */ static int update_values( array_list_t *list, array_list_t *indexes, @@ -270,11 +269,16 @@ static int update_values( array_list_t *list, { int ind = *(int *) al_get(indexes, i) - 1; void *new = (void *) al_get(values, i); + if( ind <= 0 ) + { + return 1; + } + free((void *) al_get(list, ind)); al_set(list, ind, new != 0 ? wcsdup(new) : wcsdup(L"")); } - return al_get_count(list); + return 0; } @@ -571,13 +575,13 @@ int builtin_set( wchar_t **argv ) if( query ) { /* - Query mode. Return the number variables that do not exist + Query mode. Return the number of variables that do not exist out of the specified variables. */ int i; for( i=woptind; i<argc; i++ ) { - if( !env_exist( argv[i] ) ) + if( !env_exist( argv[i], scope ) ) { retcode++; } @@ -616,7 +620,7 @@ int builtin_set( wchar_t **argv ) print_variables(0, 0, scope); return 0; } - + if( !(dest = wcsdup(argv[woptind]))) { die_mem(); @@ -636,6 +640,13 @@ int builtin_set( wchar_t **argv ) return 1; } + if( slice && erase && (scope != ENV_USER) ) + { + free( dest ); + sb_printf( sb_err, _(L"%ls: Can not specify scope when erasing array slice\n"), argv[0] ); + builtin_print_help( argv[0], sb_err ); + return 1; + } /* set assignment can work in two modes, either using slices or @@ -709,9 +720,14 @@ int builtin_set( wchar_t **argv ) al_push(&value, argv[woptind++]); } - update_values( &result, - &indexes, - &value ); + if( update_values( &result, + &indexes, + &value ) ) + { + sb_printf( sb_err, L"%ls: ", argv[0] ); + sb_printf( sb_err, ARRAY_BOUNDS_ERR ); + sb_append( sb_err, L"\n" ); + } my_env_set(dest, &result, @@ -750,7 +766,7 @@ int builtin_set( wchar_t **argv ) } else { - env_remove( dest, ENV_USER ); + retcode = env_remove( dest, scope ); } } else |