mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-05 00:01:15 -03:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d58e58d7b | ||
|
|
c8c3715aac | ||
|
|
7ffcebb9f8 | ||
|
|
831d95b600 | ||
|
|
0ffeb41c28 | ||
|
|
e8d02159da | ||
|
|
b78fba810c | ||
|
|
43213ee458 | ||
|
|
da316dd588 | ||
|
|
c8bc79005c | ||
|
|
5ba0affdd7 | ||
|
|
721f616964 | ||
|
|
ef4345968e | ||
|
|
319956c26b | ||
|
|
a9bf64465c | ||
|
|
ddcb84aa07 | ||
|
|
d332293245 | ||
|
|
48afe8062e | ||
|
|
277f9b7e60 | ||
|
|
f8de9de13d | ||
|
|
ba6ad5025e |
@@ -106,7 +106,7 @@ CMD_DOC_SRC := doc_src/count.txt doc_src/dirh.txt doc_src/dirs.txt \
|
||||
doc_src/nextd.txt doc_src/open.txt doc_src/popd.txt \
|
||||
doc_src/prevd.txt doc_src/psub.txt doc_src/pushd.txt \
|
||||
doc_src/set_color.txt doc_src/tokenize.txt doc_src/type.txt \
|
||||
doc_src/umask.txt
|
||||
doc_src/umask.txt doc_src/vared.txt
|
||||
|
||||
#
|
||||
# Files generated by running doxygen on the files in $(CMD_DOC_SRC)
|
||||
|
||||
12
builtin.c
12
builtin.c
@@ -724,6 +724,9 @@ static int wcsbindingname( wchar_t *str )
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
Debug function to print the current block stack
|
||||
*/
|
||||
static void print_block_stack( block_t *b )
|
||||
{
|
||||
if( !b )
|
||||
@@ -1414,6 +1417,9 @@ static int builtin_read( wchar_t **argv )
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
The status builtin. Gives various status information on fish.
|
||||
*/
|
||||
static int builtin_status( wchar_t **argv )
|
||||
{
|
||||
enum
|
||||
@@ -2458,6 +2464,9 @@ static int builtin_for( wchar_t **argv )
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
The begin builtin. Creates a nex block.
|
||||
*/
|
||||
static int builtin_begin( wchar_t **argv )
|
||||
{
|
||||
parser_push_block( BEGIN );
|
||||
@@ -2564,7 +2573,8 @@ static int builtin_end( wchar_t **argv )
|
||||
parser_get_job_pos()-current_block->tok_pos );
|
||||
|
||||
//fwprintf( stderr, L"Function: %ls\n", def );
|
||||
if( !parser_test( def, 1 ) )
|
||||
|
||||
if( !is_interactive || !parser_test( def, 1 ) )
|
||||
{
|
||||
function_add( current_block->param1.function_name,
|
||||
def,
|
||||
|
||||
30
builtin.h
30
builtin.h
@@ -17,10 +17,29 @@ enum
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
Error message on missing argument
|
||||
*/
|
||||
#define BUILTIN_ERR_MISSING L": Expected argument"
|
||||
|
||||
/**
|
||||
Error message on invalid combination of options
|
||||
*/
|
||||
#define BUILTIN_ERR_COMBO L": Invalid combination of options"
|
||||
|
||||
/**
|
||||
Error message on multiple scope levels for variables
|
||||
*/
|
||||
#define BUILTIN_ERR_GLOCAL L": Variable can only be one of universal, global and local"
|
||||
|
||||
/**
|
||||
Error message for specifying both export and unexport to set/read
|
||||
*/
|
||||
#define BUILTIN_ERR_EXPUNEXP L": Variable can't be both exported and unexported"
|
||||
|
||||
/**
|
||||
Error message for unknown switch
|
||||
*/
|
||||
#define BUILTIN_ERR_UNKNOWN L": Unknown option"
|
||||
|
||||
/**
|
||||
@@ -103,8 +122,19 @@ int builtin_count_args( wchar_t **argv );
|
||||
void builtin_print_help( wchar_t *cmd, string_buffer_t *b );
|
||||
|
||||
|
||||
/**
|
||||
The set builtin, used for setting variables. Defined in builtin_set.c.
|
||||
*/
|
||||
int builtin_set(wchar_t **argv);
|
||||
|
||||
/**
|
||||
The commandline builtin, used for setting and getting the contents of the commandline. Defined in builtin_commandline.c.
|
||||
*/
|
||||
int builtin_commandline(wchar_t **argv);
|
||||
|
||||
/**
|
||||
The ulimit builtin, used for setting resource limits. Defined in builtin_ulimit.c.
|
||||
*/
|
||||
int builtin_ulimit(wchar_t **argv);
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,6 +47,14 @@ enum
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
Replace/append/insert the selection with/at/after the specified string.
|
||||
|
||||
\param begin beginning of selection
|
||||
\param end end of selection
|
||||
\param insert the string to insert
|
||||
\param append_mode can be one of REPLACE_MODE, INSERT_MODE or APPEND_MODE, affects the way the test update is performed
|
||||
*/
|
||||
static void replace_part( wchar_t *begin,
|
||||
wchar_t *end,
|
||||
wchar_t *insert,
|
||||
@@ -95,10 +103,18 @@ static void replace_part( wchar_t *begin,
|
||||
sb_destroy( &out );
|
||||
}
|
||||
|
||||
void write_part( wchar_t *begin,
|
||||
wchar_t *end,
|
||||
int cut_at_cursor,
|
||||
int tokenize )
|
||||
/**
|
||||
Output the specified selection.
|
||||
|
||||
\param begin start of selection
|
||||
\param end end of selection
|
||||
\param cut_at_cursor whether printing should stop at the surrent cursor position
|
||||
\param tokenize whether the string should be tokenized, printing one string token on every line and skipping non-string tokens
|
||||
*/
|
||||
static void write_part( wchar_t *begin,
|
||||
wchar_t *end,
|
||||
int cut_at_cursor,
|
||||
int tokenize )
|
||||
{
|
||||
tokenizer tok;
|
||||
string_buffer_t out;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/** \file builtin_commandline.c Functions defining the commandline builtin
|
||||
/** \file builtin_ulimit.c Functions defining the ulimit builtin
|
||||
|
||||
Functions used for implementing the commandline builtin.
|
||||
Functions used for implementing the ulimit builtin.
|
||||
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
@@ -18,14 +18,29 @@ Functions used for implementing the commandline builtin.
|
||||
#include "common.h"
|
||||
#include "wgetopt.h"
|
||||
|
||||
/**
|
||||
Struct describing a resource limit
|
||||
*/
|
||||
struct resource_t
|
||||
{
|
||||
/**
|
||||
Resource id
|
||||
*/
|
||||
int resource;
|
||||
/**
|
||||
Description of resource
|
||||
*/
|
||||
const wchar_t *desc;
|
||||
/**
|
||||
Switch used on commandline to specify resource
|
||||
*/
|
||||
wchar_t switch_char;
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
Array of resource_t structs, describing all known resource types.
|
||||
*/
|
||||
const static struct resource_t resource_arr[] =
|
||||
{
|
||||
{
|
||||
@@ -76,6 +91,9 @@ const static struct resource_t resource_arr[] =
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
Get the implicit multiplication factor for the specified resource limit
|
||||
*/
|
||||
static int get_multiplier( int what )
|
||||
{
|
||||
if( ( what == RLIMIT_NPROC ) ||
|
||||
@@ -87,7 +105,9 @@ static int get_multiplier( int what )
|
||||
return 1024;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Return the value for the specified resource limit
|
||||
*/
|
||||
static rlim_t get( int resource, int hard )
|
||||
{
|
||||
struct rlimit ls;
|
||||
@@ -97,6 +117,9 @@ static rlim_t get( int resource, int hard )
|
||||
return hard ? ls.rlim_max:ls.rlim_cur;
|
||||
}
|
||||
|
||||
/**
|
||||
Print the value of the specified resource limit
|
||||
*/
|
||||
static void print( int resource, int hard )
|
||||
{
|
||||
rlim_t l = get( resource, hard );
|
||||
@@ -108,7 +131,9 @@ static void print( int resource, int hard )
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Print values of all resource limits
|
||||
*/
|
||||
static void print_all( int hard )
|
||||
{
|
||||
int i;
|
||||
@@ -142,6 +167,9 @@ static void print_all( int hard )
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the description for the specified resource limit
|
||||
*/
|
||||
static const wchar_t *get_desc( int what )
|
||||
{
|
||||
int i;
|
||||
@@ -156,7 +184,9 @@ static const wchar_t *get_desc( int what )
|
||||
return L"Not a resource";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Set the new value of the specified resource limit
|
||||
*/
|
||||
static int set( int resource, int hard, int soft, rlim_t value )
|
||||
{
|
||||
struct rlimit ls;
|
||||
@@ -194,6 +224,9 @@ static int set( int resource, int hard, int soft, rlim_t value )
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Set all resource limits
|
||||
*/
|
||||
static int set_all( int hard, int soft, rlim_t value )
|
||||
{
|
||||
int i;
|
||||
|
||||
34
common.c
34
common.c
@@ -26,6 +26,11 @@ parts of fish.
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifndef HOST_NAME_MAX
|
||||
/**
|
||||
Maximum length of hostname return. It is ok if this is too short,
|
||||
getting the actual hostname is not critical, so long as the string
|
||||
is unique in the filesystem namespace.
|
||||
*/
|
||||
#define HOST_NAME_MAX 255
|
||||
#endif
|
||||
|
||||
@@ -93,6 +98,9 @@ int debug_level=1;
|
||||
static struct winsize termsize;
|
||||
|
||||
|
||||
/**
|
||||
Number of nested calls to the block function. Unblock when this reaches 0.
|
||||
*/
|
||||
static int block_count=0;
|
||||
|
||||
void common_destroy()
|
||||
@@ -291,7 +299,7 @@ char *wcs2str( const wchar_t *in )
|
||||
in,
|
||||
MAX_UTF8_BYTES*wcslen(in)+1 );
|
||||
|
||||
res = realloc( res, strlen( res )+1 );
|
||||
// res = realloc( res, strlen( res )+1 );
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -583,6 +591,9 @@ wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz)
|
||||
/* count does not include NUL */
|
||||
}
|
||||
|
||||
/**
|
||||
Fallback implementation if missing from libc
|
||||
*/
|
||||
wchar_t *wcsdup( const wchar_t *in )
|
||||
{
|
||||
size_t len=wcslen(in);
|
||||
@@ -598,6 +609,9 @@ wchar_t *wcsdup( const wchar_t *in )
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Fallback implementation if missing from libc
|
||||
*/
|
||||
int wcscasecmp( const wchar_t *a, const wchar_t *b )
|
||||
{
|
||||
if( *a == 0 )
|
||||
@@ -615,6 +629,9 @@ int wcscasecmp( const wchar_t *a, const wchar_t *b )
|
||||
return wcscasecmp( a+1,b+1);
|
||||
}
|
||||
|
||||
/**
|
||||
Fallback implementation if missing from libc
|
||||
*/
|
||||
int wcsncasecmp( const wchar_t *a, const wchar_t *b, int count )
|
||||
{
|
||||
if( count == 0 )
|
||||
@@ -894,7 +911,7 @@ void debug( int level, wchar_t *msg, ... )
|
||||
|
||||
}
|
||||
putwc( L'\n', stderr );
|
||||
|
||||
sb_destroy( &sb );
|
||||
}
|
||||
|
||||
wchar_t *escape( const wchar_t *in,
|
||||
@@ -1254,8 +1271,8 @@ static int sprint_rand_digits( char *str, int maxlen )
|
||||
|
||||
/**
|
||||
Generate a filename unique in an NFS namespace by creating a copy of str and
|
||||
appending .<hostname>.<pid> to it. If gethostname() fails then a pseudo-
|
||||
random string is substituted for <hostname> - the randomness of the string
|
||||
appending .{hostname}.{pid} to it. If gethostname() fails then a pseudo-
|
||||
random string is substituted for {hostname} - the randomness of the string
|
||||
should be strong enough across different machines. The main assumption
|
||||
though is that gethostname will not fail and this is just a "safe enough"
|
||||
fallback.
|
||||
@@ -1303,15 +1320,6 @@ static char *gen_unique_nfs_filename( const char *filename )
|
||||
return newname;
|
||||
}
|
||||
|
||||
/**
|
||||
Attempt to acquire a lock based on a lockfile, waiting LOCKPOLLINTERVAL
|
||||
milliseconds between polls and timing out after timeout seconds,
|
||||
thereafter forcibly attempting to obtain the lock if force is non-zero.
|
||||
Returns 1 on success, 0 on failure.
|
||||
To release the lock the lockfile must be unlinked.
|
||||
A unique temporary file named by appending characters to the lockfile name
|
||||
is used; any pre-existing file of the same name is subject to deletion.
|
||||
*/
|
||||
int acquire_lock_file( const char *lockfile, const int timeout, int force )
|
||||
{
|
||||
int fd, timed_out = 0;
|
||||
|
||||
41
common.h
41
common.h
@@ -3,6 +3,9 @@
|
||||
*/
|
||||
|
||||
#ifndef FISH_COMMON_H
|
||||
/**
|
||||
Header guard
|
||||
*/
|
||||
#define FISH_COMMON_H
|
||||
|
||||
#include <wchar.h>
|
||||
@@ -64,6 +67,7 @@ extern char *profile;
|
||||
debug function.
|
||||
*/
|
||||
extern wchar_t *program_name;
|
||||
|
||||
/**
|
||||
Take an array_list_t containing wide strings and converts them to a wchar_t **.
|
||||
*/
|
||||
@@ -223,6 +227,9 @@ int read_blocked(int fd, void *buf, size_t count);
|
||||
*/
|
||||
int writeb( tputs_arg_t b );
|
||||
|
||||
/**
|
||||
Exit program at once, leaving an error message about running out of memory
|
||||
*/
|
||||
void die_mem();
|
||||
|
||||
/**
|
||||
@@ -236,7 +243,7 @@ void common_destroy();
|
||||
program_name, followed by a colon and a whitespace.
|
||||
|
||||
\param level the priority of the message. Lower number means higher priority. Messages with a priority_number higher than \c debug_level will be ignored..
|
||||
\param the message format string.
|
||||
\param msg the message format string.
|
||||
|
||||
Example:
|
||||
|
||||
@@ -258,11 +265,39 @@ void debug( int level, wchar_t *msg, ... );
|
||||
wchar_t *escape( const wchar_t *in,
|
||||
int escape_all );
|
||||
|
||||
wchar_t *unescape( const wchar_t * in, int escape_special );
|
||||
/**
|
||||
Expand backslashed escapes and substitute them with their unescaped
|
||||
counterparts. Also optionally change the wildcards, the tilde
|
||||
character and a few more into constants which are defined in a
|
||||
private use area of Unicode. This assumes wchar_t is a unicode
|
||||
character set.
|
||||
|
||||
The result must be free()d. The original string is not modified. If
|
||||
an invalid sequence is specified, 0 is returned.
|
||||
|
||||
*/
|
||||
wchar_t *unescape( const wchar_t * in,
|
||||
int escape_special );
|
||||
|
||||
/**
|
||||
Block SIGCHLD. Calls to block/unblock may be nested, and only once the nest count reaches zero wiull the block be removed.
|
||||
*/
|
||||
void block();
|
||||
|
||||
/**
|
||||
undo call to block().
|
||||
*/
|
||||
void unblock();
|
||||
|
||||
/**
|
||||
Attempt to acquire a lock based on a lockfile, waiting LOCKPOLLINTERVAL
|
||||
milliseconds between polls and timing out after timeout seconds,
|
||||
thereafter forcibly attempting to obtain the lock if force is non-zero.
|
||||
Returns 1 on success, 0 on failure.
|
||||
To release the lock the lockfile must be unlinked.
|
||||
A unique temporary file named by appending characters to the lockfile name
|
||||
is used; any pre-existing file of the same name is subject to deletion.
|
||||
*/
|
||||
int acquire_lock_file( const char *lockfile, const int timeout, int force );
|
||||
|
||||
/**
|
||||
@@ -282,7 +317,7 @@ int common_get_width();
|
||||
*/
|
||||
int common_get_height();
|
||||
|
||||
/*
|
||||
/**
|
||||
Handle a window change event by looking up the new window size and
|
||||
saving it in an internal variable used by common_get_wisth and
|
||||
common_get_height().
|
||||
|
||||
15
complete.c
15
complete.c
@@ -309,7 +309,9 @@ static void clear_hash_entry( const void *key, const void *data )
|
||||
free( (void *)data );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Free hash value, but not hash key
|
||||
*/
|
||||
static void clear_hash_value( const void *key, const void *data )
|
||||
{
|
||||
free( (void *)data );
|
||||
@@ -1763,10 +1765,10 @@ static void complete_param_expand( wchar_t *str,
|
||||
}
|
||||
else
|
||||
comp_str = str;
|
||||
|
||||
// fwprintf( stderr, L"expand_string( \"%ls\", [list], ACCEPT_INCOMPLETE | %ls )\n", comp_str, do_file?L"0":L"EXPAND_SKIP_WILDCARDS" );
|
||||
|
||||
expand_string( wcsdup(comp_str), comp_out, ACCEPT_INCOMPLETE | (do_file?0:EXPAND_SKIP_WILDCARDS) );
|
||||
// fwprintf( stderr, L"expand_string( \"%ls\", [list], EXPAND_SKIP_SUBSHELL | ACCEPT_INCOMPLETE | %ls )\n", 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) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2094,6 +2096,11 @@ void complete( const wchar_t *cmd,
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Print the GNU longopt style switch \c opt, and the argument \c
|
||||
argument to the specified stringbuffer, but only if arguemnt is
|
||||
non-null and longer than 0 characters.
|
||||
*/
|
||||
static void append_switch( string_buffer_t *out,
|
||||
const wchar_t *opt,
|
||||
const wchar_t *argument )
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
*/
|
||||
|
||||
#ifndef FISH_COMPLETE_H
|
||||
/**
|
||||
Header guard
|
||||
*/
|
||||
#define FISH_COMPLETE_H
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
12
configure.ac
12
configure.ac
@@ -1,5 +1,5 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
AC_INIT(fish,1.16.0,axel@liljencrantz.se)
|
||||
AC_INIT(fish,1.16.2,axel@liljencrantz.se)
|
||||
|
||||
AC_CANONICAL_TARGET
|
||||
|
||||
@@ -36,20 +36,14 @@ else
|
||||
fi
|
||||
|
||||
if [[ "$prefix" = NONE ]]; then
|
||||
AC_DEFINE_UNQUOTED( [PREFIX], L"/usr/local", [Installation directory])
|
||||
AC_DEFINE_UNQUOTED( [PREFIX], L"/usr/local", [Installation directory])
|
||||
AC_SUBST( PREFIX, /usr/local)
|
||||
AC_SUBST(sysconfdir,[/etc])
|
||||
export prefix=/usr/local
|
||||
else
|
||||
AC_DEFINE_UNQUOTED( [PREFIX], L"$prefix", [Installation directory])
|
||||
AC_SUBST( PREFIX, [$prefix])
|
||||
AC_SUBST(sysconfdir,[/etc])
|
||||
fi
|
||||
|
||||
if echo $prefix | grep \^$HOME >/dev/null; then
|
||||
AC_SUBST(sysconfdir,[$HOME/etc])
|
||||
AC_MSG_NOTICE(["Install in $HOME"])
|
||||
fi
|
||||
AC_SUBST(fishdir,[/fish.d])
|
||||
AC_SUBST(fishfile,[/fish])
|
||||
AC_SUBST(fishinputfile,[/fish_inputrc])
|
||||
@@ -61,7 +55,7 @@ if test -z $docdir; then
|
||||
fi
|
||||
|
||||
AC_DEFINE_UNQUOTED( DOCDIR, [L"$(eval echo $docdir)"], [Documentation directory] )
|
||||
AC_DEFINE_UNQUOTED( SYSCONFDIR, [L"$sysconfdir"], [System configuration directory] )
|
||||
AC_DEFINE_UNQUOTED( SYSCONFDIR, [L"$(eval echo $sysconfdir)"], [System configuration directory] )
|
||||
|
||||
# See if Linux procfs is present
|
||||
AC_CHECK_FILES([/proc/self/stat])
|
||||
|
||||
@@ -503,7 +503,7 @@ inherited by any commands started by fish. It is convention that
|
||||
exported variables are in uppercase and unexported variables are in
|
||||
lowercase.
|
||||
|
||||
Variables can be explicitly set to be exportes with the \c -x or \c
|
||||
Variables can be explicitly set to be exported with the \c -x or \c
|
||||
--export switch, or not exported with the \c -u or \c --unexport
|
||||
switch. The exporting rules when creating or updating a variable are
|
||||
identical to the scoping rules for variables:
|
||||
@@ -557,24 +557,28 @@ echo $smurf
|
||||
\subsection variables-special Special variables
|
||||
|
||||
The user can change the settings of \c fish by changing the values of
|
||||
certain environment variables.These are:
|
||||
certain environment variables.
|
||||
|
||||
- \c BROWSER, which is the users preferred web browser. If this variable is set, fish will use the specified browser instead of the system default browser to display the fish documentation.
|
||||
- \c CDPATH, which is an array of directories in which to search for the new directory for the \c cd builtin.
|
||||
- \c fish_color_normal, \c fish_color_command, \c fish_color_substitution, \c fish_color_redirection, \c fish_color_end, \c fish_color_error, \c fish_color_param, \c fish_color_comment, \c fish_color_match, \c fish_color_search_match, \c fish_color_cwd, \c fish_pager_color_prefix, \c fish_pager_color_completion, \c fish_pager_color_description and \c fish_pager_color_progress are used to change the color of various elements in \c fish. These variables are universal, i.e. when changing them, their new value will be used by all running fish sessions. The new value will also be retained when restarting fish.
|
||||
- \c PATH, which is an array of directories in which to search for commands
|
||||
- \c umask, which is the current file creation mask. The preffered way to change the umask variable is through the <a href="commands.html#umask">umask shellscript function</a>. An attempt to set umask to an invalid value will always fail.
|
||||
|
||||
\c fish also sends additional information to the user through the
|
||||
values of certain environment variables. The user can not change the values of these variables. They are:
|
||||
|
||||
- \c _, which is the name of the currently running command.
|
||||
- \c history, which is an array containing the last commands that where entered
|
||||
- \c HOME, which is the users home directory. This variable can be changed by the root user.
|
||||
- \c HOME, which is the users home directory. This variable can only be changed by the root user.
|
||||
- \c PWD, which is the current working directory.
|
||||
- \c status, which is the exit status of the last foreground job to exit. If a job contains pipelines, the status of the last command in the pipeline is the status for the job.
|
||||
- \c USER, which is the username. This variable can only be changed by the root user.
|
||||
|
||||
\c fish also uses several variables internally. Such variables are
|
||||
prefixed with the string __FISH or __fish. These should be ignored by the user.
|
||||
Variables whose name are in uppercase are exported to the commands
|
||||
started by fish. \c fish also uses several variables internally. Such
|
||||
variables are prefixed with the string __FISH or __fish. These should
|
||||
be ignored by the user.
|
||||
|
||||
\section builtin-overview Builtins
|
||||
|
||||
@@ -632,6 +636,7 @@ builtins or shellscript functions, and can only be used inside fish.
|
||||
- <a href="builtins.html#switch">switch</a>, conditionally execute a block of commands
|
||||
- <a href="commands.html#tokenize">tokenize</a>, split a string up into multiple tokens
|
||||
- <a href="builtins.html#ulimit">ulimit</a>, set or get the shells resurce usage limits
|
||||
- <a href="commandss.html#umask">umask</a>, set or get the file creation mask
|
||||
- <a href="builtins.html#while">while</a>, perform a block of commands while a condition is met
|
||||
|
||||
For more information about these commands, use the <tt>--help</tt>
|
||||
|
||||
@@ -10,11 +10,13 @@ Change the foreground and/or background color of the terminal.
|
||||
COLOR is one of black, red, green, brown, yellow, blue, magenta,
|
||||
purple, cyan, white and normal.
|
||||
|
||||
- \c -c, \c --print-colors Prints a list of all valid color names
|
||||
- \c -b, \c --background Set the background color
|
||||
- \c -o, \c --bold Set bold or extra bright mode
|
||||
- \c -h, \c --help Display help message and exit
|
||||
- \c -v, \c --version Display version and exit
|
||||
|
||||
|
||||
Calling <tt>set_color normal</tt> will set the terminal color to
|
||||
whatever is the default color of the terminal.
|
||||
|
||||
|
||||
@@ -10,9 +10,30 @@ With no argument, the current file-creation mask is printed, if an
|
||||
argument is specified, it is the new file creation mask. The mask may
|
||||
be specified as an octal number, in which case it is interpreted as
|
||||
the rights that should be masked away, i.e. it is the inverse of the
|
||||
file permissions any new files will have. If a synbolic mask is
|
||||
specified, the actual file permission bits, and not the inverse, are
|
||||
specified.
|
||||
file permissions any new files will have.
|
||||
|
||||
If a symbolic mask is specified, the actual file permission bits, and
|
||||
not the inverse, should be specified. A symbolic mask is a comma
|
||||
separated list of rights. Each right consists of three parts:
|
||||
|
||||
- The first part specifies to whom this set of right applies, and can
|
||||
be one of \c u, \c g, \c o or \c a, where \c u specifies the user who
|
||||
owns the file, \c g specifies the group owner of the file, \c o
|
||||
specifiec other users rights and \c a specifies all three should be
|
||||
changed.
|
||||
- The second part of a right specifies the mode, and can be one of \c
|
||||
=, \c + or \c -, where \c = specifies that the rights should be set to
|
||||
the new value, \c + specifies that the specified right should be added
|
||||
to those previously specified and \c - specifies that the specified
|
||||
rights should be removed from those previously specified.
|
||||
- The third part of a right specifies what rights should be changed
|
||||
and can be any compination of \c r, \c w and \c x, representing
|
||||
read, write and execute rights.
|
||||
|
||||
If the first and second parts are skipped, they are assumed to be \c a
|
||||
and \c =, respectively. As an example, <code>r,u+w</code> means all
|
||||
users should have read access and the file owner should also have
|
||||
write access.
|
||||
|
||||
- <code>-h</code> or <code>--help</code> print this message
|
||||
- <code>-S</code> or <code>--symbolic</code> prints the file-creation mask in symbolic form instead of octal form. Use <code>man chmod</code> for more information.
|
||||
|
||||
15
doc_src/vared.txt
Normal file
15
doc_src/vared.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
\section vared vared - Interactively edit the value of an environment variable
|
||||
|
||||
\subsection vared-synopsis Synopsis
|
||||
<tt>vared VARIABLE_NAME</tt>
|
||||
|
||||
\subsection vared-description Description
|
||||
|
||||
vared is used to interactively edit the value of an environment
|
||||
variable. Array variables as a whole can not be edited using vared,
|
||||
but individual array elements can.
|
||||
|
||||
\subsection vared-example Example
|
||||
|
||||
<code>vared PATH[3]</code> edits the third element of the PATH array
|
||||
146
env.c
146
env.c
@@ -47,6 +47,9 @@
|
||||
*/
|
||||
#define FISHD_CMD L"if which fishd >/dev/null; fishd ^/tmp/fish.%s.log; end"
|
||||
|
||||
/**
|
||||
Value denoting a null string
|
||||
*/
|
||||
#define ENV_NULL L"\x1d"
|
||||
|
||||
/**
|
||||
@@ -116,6 +119,11 @@ static hash_table_t *global;
|
||||
*/
|
||||
static hash_table_t env_read_only;
|
||||
|
||||
/**
|
||||
Table of variables whose value is dynamically calculated, such as umask, status, etc
|
||||
*/
|
||||
static hash_table_t env_electric;
|
||||
|
||||
/**
|
||||
Exported variable array used by execv
|
||||
*/
|
||||
@@ -194,6 +202,21 @@ static void start_fishd()
|
||||
sb_destroy( &cmd );
|
||||
}
|
||||
|
||||
/**
|
||||
Return the current umask value.
|
||||
*/
|
||||
static mode_t get_umask()
|
||||
{
|
||||
mode_t res;
|
||||
res = umask( 0 );
|
||||
umask( res );
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
Universal variable callback function. This function makes sure the
|
||||
proper events are triggered when an event occurs.
|
||||
*/
|
||||
static void universal_callback( int type,
|
||||
const wchar_t *name,
|
||||
const wchar_t *val )
|
||||
@@ -234,6 +257,8 @@ static void universal_callback( int type,
|
||||
void env_init()
|
||||
{
|
||||
char **p;
|
||||
struct passwd *pw;
|
||||
wchar_t *uname, *path;
|
||||
|
||||
sb_init( &dyn_var );
|
||||
|
||||
@@ -253,11 +278,22 @@ void env_init()
|
||||
hash_put( &env_read_only, L"PWD", L"" );
|
||||
|
||||
/*
|
||||
HOME should be writeable by root, since this is often a
|
||||
Names of all dynamically calculated variables
|
||||
*/
|
||||
hash_init( &env_electric, &hash_wcs_func, &hash_wcs_cmp );
|
||||
hash_put( &env_electric, L"history", L"" );
|
||||
hash_put( &env_electric, L"status", L"" );
|
||||
hash_put( &env_electric, L"umask", L"" );
|
||||
|
||||
/*
|
||||
HOME and USER should be writeable by root, since this can be a
|
||||
convenient way to install software.
|
||||
*/
|
||||
if( getuid() != 0 )
|
||||
{
|
||||
hash_put( &env_read_only, L"HOME", L"" );
|
||||
hash_put( &env_read_only, L"USER", L"" );
|
||||
}
|
||||
|
||||
top = malloc( sizeof(env_node_t) );
|
||||
top->next = 0;
|
||||
@@ -266,7 +302,7 @@ void env_init()
|
||||
hash_init( &top->env, &hash_wcs_func, &hash_wcs_cmp );
|
||||
global_env = top;
|
||||
global = &top->env;
|
||||
|
||||
|
||||
/*
|
||||
Import environment variables
|
||||
*/
|
||||
@@ -276,12 +312,13 @@ void env_init()
|
||||
wchar_t *pos;
|
||||
|
||||
key = str2wcs(*p);
|
||||
|
||||
|
||||
if( !key )
|
||||
continue;
|
||||
|
||||
val = wcschr( key, L'=' );
|
||||
|
||||
|
||||
if( val == 0 )
|
||||
env_set( key, L"", ENV_EXPORT );
|
||||
else
|
||||
@@ -296,12 +333,68 @@ void env_init()
|
||||
*pos = ARRAY_SEP;
|
||||
pos++;
|
||||
}
|
||||
|
||||
|
||||
env_set( key, val, ENV_EXPORT | ENV_GLOBAL );
|
||||
}
|
||||
free(key);
|
||||
}
|
||||
}
|
||||
|
||||
path = env_get( L"PATH" );
|
||||
if( !path )
|
||||
{
|
||||
env_set( L"PATH", L"/bin" ARRAY_SEP_STR L"/usr/bin", ENV_EXPORT | ENV_GLOBAL );
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
array_list_t l;
|
||||
int has_bin=0, has_usr_bin=0;
|
||||
|
||||
al_init( &l );
|
||||
expand_variable_array( path, &l );
|
||||
|
||||
for( i=0; i<al_get_count( &l); i++ )
|
||||
{
|
||||
wchar_t * el = (wchar_t *)al_get( &l, i );
|
||||
if( contains_str( el, L"/bin", L"/bin/", (void *)0) )
|
||||
{
|
||||
has_bin = 1;
|
||||
}
|
||||
if( contains_str( el, L"/usr/bin", L"/usr/bin/", (void *)0) )
|
||||
{
|
||||
has_bin = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if( !( has_bin && has_usr_bin ) )
|
||||
{
|
||||
string_buffer_t b;
|
||||
sb_init( &b );
|
||||
sb_append( &b, path );
|
||||
if( !has_bin )
|
||||
sb_append( &b, ARRAY_SEP_STR L"/bin" );
|
||||
if( !has_usr_bin )
|
||||
sb_append( &b, ARRAY_SEP_STR L"/usr/bin" );
|
||||
|
||||
env_set( L"PATH", (wchar_t *)b.buff, ENV_GLOBAL | ENV_EXPORT );
|
||||
sb_destroy( &b );
|
||||
}
|
||||
|
||||
al_foreach( &l, (void (*)(const void *))&free );
|
||||
al_destroy( &l );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
pw = getpwuid( getuid() );
|
||||
if( pw )
|
||||
{
|
||||
uname = str2wcs( pw->pw_name );
|
||||
env_set( L"USER", uname, ENV_GLOBAL | ENV_EXPORT );
|
||||
free( uname );
|
||||
}
|
||||
|
||||
env_universal_init( env_get( L"FISHD_SOKET_DIR"),
|
||||
env_get( L"USER" ),
|
||||
&start_fishd,
|
||||
@@ -321,6 +414,8 @@ void env_destroy()
|
||||
env_pop();
|
||||
|
||||
hash_destroy( &env_read_only );
|
||||
|
||||
hash_destroy( &env_electric );
|
||||
|
||||
hash_foreach( global, &clear_hash_entry );
|
||||
hash_destroy( global );
|
||||
@@ -389,17 +484,24 @@ void env_set( const wchar_t *key,
|
||||
{
|
||||
wchar_t *end;
|
||||
int mask;
|
||||
|
||||
|
||||
/*
|
||||
Set the new umask
|
||||
*/
|
||||
if( val && wcslen(val) )
|
||||
{
|
||||
errno=0;
|
||||
mask = wcstol( val, &end, 8 );
|
||||
|
||||
if( !errno && !*end )
|
||||
if( !errno && (!*end) && (mask <= 0777) && (mask >= 0) )
|
||||
{
|
||||
umask( mask );
|
||||
}
|
||||
}
|
||||
/*
|
||||
Do not actually create a umask variable, on env_get, it will be calculated dynamically
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -656,6 +758,12 @@ wchar_t *env_get( const wchar_t *key )
|
||||
sb_printf( &dyn_var, L"%d", proc_get_last_status() );
|
||||
return (wchar_t *)dyn_var.buff;
|
||||
}
|
||||
else if( wcscmp( key, L"umask" )==0 )
|
||||
{
|
||||
sb_clear( &dyn_var );
|
||||
sb_printf( &dyn_var, L"0%0.3o", get_umask() );
|
||||
return (wchar_t *)dyn_var.buff;
|
||||
}
|
||||
|
||||
while( env != 0 )
|
||||
{
|
||||
@@ -694,7 +802,7 @@ int env_exist( const wchar_t *key )
|
||||
env_node_t *env = top;
|
||||
wchar_t *item;
|
||||
|
||||
if( hash_get( &env_read_only, key ) )
|
||||
if( hash_get( &env_read_only, key ) || hash_get( &env_electric, key ) )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@@ -720,6 +828,9 @@ int env_exist( const wchar_t *key )
|
||||
return item != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns true if the specified scope or any non-shadowed non-global subscopes contain an exported variable.
|
||||
*/
|
||||
static int local_scope_exports( env_node_t *n )
|
||||
{
|
||||
|
||||
@@ -791,6 +902,9 @@ static void add_key_to_hash( const void *key,
|
||||
hash_put( (hash_table_t *)aux, key, 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
Add key to hashtable
|
||||
*/
|
||||
static void add_to_hash( const void *k, void *aux )
|
||||
{
|
||||
hash_put( (hash_table_t *)aux,
|
||||
@@ -798,6 +912,16 @@ static void add_to_hash( const void *k, void *aux )
|
||||
0 );
|
||||
}
|
||||
|
||||
/**
|
||||
Add key to list
|
||||
*/
|
||||
static void add_key_to_list( const void * key,
|
||||
const void * val,
|
||||
void *aux )
|
||||
{
|
||||
al_push( (array_list_t *)aux, key );
|
||||
}
|
||||
|
||||
|
||||
void env_get_names( array_list_t *l, int flags )
|
||||
{
|
||||
@@ -844,11 +968,9 @@ void env_get_names( array_list_t *l, int flags )
|
||||
hash_foreach2( &global_env->env,
|
||||
add_key_to_hash,
|
||||
&names );
|
||||
|
||||
if( get_names_show_unexported )
|
||||
{
|
||||
al_push( l, L"history" );
|
||||
al_push( l, L"status" );
|
||||
}
|
||||
hash_foreach2( &env_electric, &add_key_to_list, l );
|
||||
|
||||
if( get_names_show_exported )
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/** \file env_universl.h
|
||||
/** \file env_universal.h
|
||||
Universal variable client library
|
||||
*/
|
||||
|
||||
@@ -18,7 +18,7 @@ extern connection_t env_universal_server;
|
||||
Initialize the envuni library
|
||||
*/
|
||||
void env_universal_init();
|
||||
/*
|
||||
/**
|
||||
Free memory used by envuni
|
||||
*/
|
||||
void env_universal_destroy();
|
||||
|
||||
@@ -65,12 +65,12 @@
|
||||
should be exported. Obviously, it needs to be allocated large
|
||||
enough to fit the value string.
|
||||
*/
|
||||
typedef struct var_entry
|
||||
typedef struct var_uni_entry
|
||||
{
|
||||
int export; /**< Whether the variable should be exported */
|
||||
wchar_t val[0]; /**< The value of the variable */
|
||||
}
|
||||
var_entry_t;
|
||||
var_uni_entry_t;
|
||||
|
||||
|
||||
static void parse_message( wchar_t *msg,
|
||||
@@ -81,6 +81,9 @@ static void parse_message( wchar_t *msg,
|
||||
*/
|
||||
hash_table_t env_universal_var;
|
||||
|
||||
/**
|
||||
Callback function, should be called on all events
|
||||
*/
|
||||
void (*callback)( int type,
|
||||
const wchar_t *key,
|
||||
const wchar_t *val );
|
||||
@@ -105,6 +108,9 @@ void env_universal_common_init( void (*cb)(int type, const wchar_t *key, const w
|
||||
hash_init( &env_universal_var, &hash_wcs_func, &hash_wcs_cmp );
|
||||
}
|
||||
|
||||
/**
|
||||
Free both key and data
|
||||
*/
|
||||
static void erase( const void *key,
|
||||
const void *data )
|
||||
{
|
||||
@@ -186,6 +192,9 @@ void read_message( connection_t *src )
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Remove variable with specified name
|
||||
*/
|
||||
static void remove_entry( wchar_t *name )
|
||||
{
|
||||
void *k, *v;
|
||||
@@ -197,6 +206,9 @@ static void remove_entry( wchar_t *name )
|
||||
free( v );
|
||||
}
|
||||
|
||||
/**
|
||||
Test if the message msg contains the command cmd
|
||||
*/
|
||||
static int match( const wchar_t *msg, const wchar_t *cmd )
|
||||
{
|
||||
size_t len = wcslen( cmd );
|
||||
@@ -209,7 +221,9 @@ static int match( const wchar_t *msg, const wchar_t *cmd )
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Parse message msg
|
||||
*/
|
||||
static void parse_message( wchar_t *msg,
|
||||
connection_t *src )
|
||||
{
|
||||
@@ -239,8 +253,8 @@ static void parse_message( wchar_t *msg,
|
||||
|
||||
val = unescape( val, 0 );
|
||||
|
||||
var_entry_t *entry =
|
||||
malloc( sizeof(var_entry_t) + sizeof(wchar_t)*(wcslen(val)+1) );
|
||||
var_uni_entry_t *entry =
|
||||
malloc( sizeof(var_uni_entry_t) + sizeof(wchar_t)*(wcslen(val)+1) );
|
||||
if( !entry )
|
||||
die_mem();
|
||||
entry->export=export;
|
||||
@@ -307,8 +321,13 @@ static void parse_message( wchar_t *msg,
|
||||
}
|
||||
}
|
||||
|
||||
int try_send( message_t *msg,
|
||||
int fd )
|
||||
/**
|
||||
Attempt to send the specified message to the specified file descriptor
|
||||
|
||||
\return 1 on sucess, 0 if the message could not be sent without blocking and -1 on error
|
||||
*/
|
||||
static int try_send( message_t *msg,
|
||||
int fd )
|
||||
{
|
||||
|
||||
debug( 3,
|
||||
@@ -478,7 +497,7 @@ static void add_key_to_hash( const void *key,
|
||||
const void *data,
|
||||
void *aux )
|
||||
{
|
||||
var_entry_t *e = (var_entry_t *)data;
|
||||
var_uni_entry_t *e = (var_uni_entry_t *)data;
|
||||
if( ( e->export && get_names_show_exported) ||
|
||||
( !e->export && get_names_show_unexported) )
|
||||
al_push( (array_list_t *)aux, key );
|
||||
@@ -498,7 +517,7 @@ void env_universal_common_get_names( array_list_t *l,
|
||||
|
||||
wchar_t *env_universal_common_get( const wchar_t *name )
|
||||
{
|
||||
var_entry_t *e = (var_entry_t *)hash_get( &env_universal_var, name );
|
||||
var_uni_entry_t *e = (var_uni_entry_t *)hash_get( &env_universal_var, name );
|
||||
if( e )
|
||||
return e->val;
|
||||
return 0;
|
||||
@@ -506,18 +525,28 @@ wchar_t *env_universal_common_get( const wchar_t *name )
|
||||
|
||||
int env_universal_common_get_export( const wchar_t *name )
|
||||
{
|
||||
var_entry_t *e = (var_entry_t *)hash_get( &env_universal_var, name );
|
||||
var_uni_entry_t *e = (var_uni_entry_t *)hash_get( &env_universal_var, name );
|
||||
if( e )
|
||||
return e->export;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Adds a variable creation message about the specified variable to
|
||||
the specified queue. The function signature is non-obvious since
|
||||
this function is used together with hash_foreach2, which requires
|
||||
the specified function signature.
|
||||
|
||||
\param k the variable name
|
||||
\param v the variable value
|
||||
\param q the queue to add the message to
|
||||
*/
|
||||
static void enqueue( const void *k,
|
||||
const void *v,
|
||||
void *q)
|
||||
{
|
||||
const wchar_t *key = (const wchar_t *)k;
|
||||
const var_entry_t *val = (const var_entry_t *)v;
|
||||
const var_uni_entry_t *val = (const var_uni_entry_t *)v;
|
||||
dyn_queue_t *queue = (dyn_queue_t *)q;
|
||||
|
||||
message_t *msg = create_message( val->export?SET_EXPORT:SET, key, val->val );
|
||||
|
||||
@@ -88,7 +88,13 @@ typedef struct connection
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/**
|
||||
Number of queues that contain this message. Once this reaches zero, the message should be deleted
|
||||
*/
|
||||
int count;
|
||||
/**
|
||||
Message body. The message must be allocated using enough memory to actually contain the message.
|
||||
*/
|
||||
char body[0];
|
||||
}
|
||||
message_t;
|
||||
@@ -136,6 +142,9 @@ wchar_t *env_universal_common_get( const wchar_t *name );
|
||||
*/
|
||||
int env_universal_common_get_export( const wchar_t *name );
|
||||
|
||||
/**
|
||||
Add messages about all existing variables to the specified connection
|
||||
*/
|
||||
void enqueue_all( connection_t *c );
|
||||
|
||||
|
||||
|
||||
15
event.c
15
event.c
@@ -1,6 +1,6 @@
|
||||
/** \file function.c
|
||||
/** \file event.c
|
||||
|
||||
Functions for storing and retrieving function information.
|
||||
Functions for handling event triggers
|
||||
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
@@ -31,13 +31,22 @@
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/**
|
||||
Number of delivered signals
|
||||
*/
|
||||
int count;
|
||||
/**
|
||||
Whether signals have been skipped
|
||||
*/
|
||||
int overflow;
|
||||
/**
|
||||
Array of signal events
|
||||
*/
|
||||
int signal[SIG_UNHANDLED_MAX];
|
||||
}
|
||||
signal_list_t;
|
||||
|
||||
/*
|
||||
/**
|
||||
The signal event list. Actually two separate lists. One which is
|
||||
active, which is the one that new events is written to. The inactive
|
||||
one contains the events that are currently beeing performed.
|
||||
|
||||
2
event.h
2
event.h
@@ -1,6 +1,6 @@
|
||||
/** \file event.h
|
||||
|
||||
Event handling library
|
||||
Functions for handling event triggers
|
||||
|
||||
*/
|
||||
#ifndef FISH_EVENT_H
|
||||
|
||||
64
exec.c
64
exec.c
@@ -40,7 +40,7 @@
|
||||
/**
|
||||
Prototype for the getpgid library function. The prototype for this
|
||||
function seems to be missing in glibc, at least I've not found any
|
||||
combination of #includes, macros and compiler switches that will
|
||||
combination of includes, macros and compiler switches that will
|
||||
include it.
|
||||
*/
|
||||
pid_t getpgid( pid_t pid );
|
||||
@@ -103,7 +103,7 @@ void exec_close( int fd )
|
||||
int exec_pipe( int fd[2])
|
||||
{
|
||||
int res;
|
||||
|
||||
|
||||
while( ( res=pipe( fd ) ) )
|
||||
{
|
||||
if( errno != EINTR )
|
||||
@@ -111,23 +111,18 @@ int exec_pipe( int fd[2])
|
||||
wperror(L"pipe");
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debug( 4, L"Created pipe using fds %d and %d", fd[0], fd[1]);
|
||||
|
||||
if( open_fds == 0 )
|
||||
{
|
||||
open_fds = malloc( sizeof( array_list_t ) );
|
||||
if(!open_fds )
|
||||
die_mem();
|
||||
al_init( open_fds );
|
||||
open_fds = al_new();
|
||||
}
|
||||
|
||||
if( res != -1 )
|
||||
{
|
||||
debug( 4, L"Created pipe using fds %d and %d", fd[0], fd[1]);
|
||||
|
||||
al_push( open_fds, (void *)(long)fd[0] );
|
||||
al_push( open_fds, (void *)(long)fd[1] );
|
||||
}
|
||||
al_push( open_fds, (void *)(long)fd[0] );
|
||||
al_push( open_fds, (void *)(long)fd[1] );
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -183,7 +178,6 @@ static void close_unused_internal_pipes( io_data_t *io )
|
||||
|
||||
void exec_init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void exec_destroy()
|
||||
@@ -672,7 +666,7 @@ void exec( job_t *j )
|
||||
pipe_write.io_mode=IO_PIPE;
|
||||
pipe_read.next=0;
|
||||
pipe_write.next=0;
|
||||
pipe_write.param1.pipe_fd[0]=pipe_write.param1.pipe_fd[1]=0;
|
||||
pipe_write.param1.pipe_fd[0]=pipe_write.param1.pipe_fd[1]=-1;
|
||||
|
||||
//fwprintf( stderr, L"Run command %ls\n", j->command );
|
||||
|
||||
@@ -696,7 +690,7 @@ void exec( job_t *j )
|
||||
The loop also has to handle pipelining between the jobs.
|
||||
*/
|
||||
|
||||
for (p = j->first_process; p; p = p->next)
|
||||
for( p=j->first_process; p; p = p->next )
|
||||
{
|
||||
mypipe[1]=-1;
|
||||
skip_fork=0;
|
||||
@@ -722,9 +716,11 @@ void exec( job_t *j )
|
||||
j->io = io_add( j->io, &pipe_read );
|
||||
}
|
||||
|
||||
if (p->next)
|
||||
if( p->next )
|
||||
{
|
||||
if (exec_pipe( mypipe ) == -1)
|
||||
// debug( 1, L"%ls|%ls" , p->argv[0], p->next->argv[0]);
|
||||
|
||||
if( exec_pipe( mypipe ) == -1 )
|
||||
{
|
||||
debug( 1, PIPE_ERROR );
|
||||
wperror (L"pipe");
|
||||
@@ -775,7 +771,7 @@ void exec( job_t *j )
|
||||
{
|
||||
sb_init( &sb );
|
||||
|
||||
for( i=1,arg = p->argv+1; *arg; i++, arg++ )
|
||||
for( i=1, arg=p->argv+1; *arg; i++, arg++ )
|
||||
{
|
||||
if( i != 1 )
|
||||
sb_append( &sb, ARRAY_SEP_STR );
|
||||
@@ -948,7 +944,7 @@ void exec( job_t *j )
|
||||
to buffer such io, since otherwisethe internal pipe
|
||||
buffer might overflow.
|
||||
*/
|
||||
if( !io_buffer)
|
||||
if( !io_buffer )
|
||||
{
|
||||
p->completed = 1;
|
||||
break;
|
||||
@@ -962,8 +958,8 @@ void exec( job_t *j )
|
||||
{
|
||||
|
||||
|
||||
pid = fork ();
|
||||
if (pid == 0)
|
||||
pid = fork();
|
||||
if( pid == 0 )
|
||||
{
|
||||
/*
|
||||
This is the child process. Write out the contents of the pipeline.
|
||||
@@ -975,7 +971,7 @@ void exec( job_t *j )
|
||||
io_buffer->param2.out_buffer->used );
|
||||
exit( status );
|
||||
}
|
||||
else if (pid < 0)
|
||||
else if( pid < 0 )
|
||||
{
|
||||
/* The fork failed. */
|
||||
debug( 0, FORK_ERROR );
|
||||
@@ -1024,7 +1020,7 @@ void exec( job_t *j )
|
||||
|
||||
io_data_t *io = io_get( j->io, 1 );
|
||||
int buffer_stdout = io && io->io_mode == IO_BUFFER;
|
||||
|
||||
|
||||
if( ( !sb_err->used ) &&
|
||||
( !p->next ) &&
|
||||
( sb_out->used ) &&
|
||||
@@ -1050,10 +1046,9 @@ void exec( job_t *j )
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
pid = fork ();
|
||||
if (pid == 0)
|
||||
pid = fork();
|
||||
if( pid == 0 )
|
||||
{
|
||||
/*
|
||||
This is the child process.
|
||||
@@ -1068,7 +1063,7 @@ void exec( job_t *j )
|
||||
exit( p->status );
|
||||
|
||||
}
|
||||
else if (pid < 0)
|
||||
else if( pid < 0 )
|
||||
{
|
||||
/* The fork failed. */
|
||||
debug( 0, FORK_ERROR );
|
||||
@@ -1098,7 +1093,7 @@ void exec( job_t *j )
|
||||
// fwprintf( stderr,
|
||||
// L"fork on %ls\n", j->command );
|
||||
pid = fork ();
|
||||
if (pid == 0)
|
||||
if( pid == 0 )
|
||||
{
|
||||
/*
|
||||
This is the child process.
|
||||
@@ -1111,7 +1106,7 @@ void exec( job_t *j )
|
||||
launch_process _never_ returns...
|
||||
*/
|
||||
}
|
||||
else if (pid < 0)
|
||||
else if( pid < 0 )
|
||||
{
|
||||
/* The fork failed. */
|
||||
debug( 0, FORK_ERROR );
|
||||
@@ -1138,11 +1133,10 @@ void exec( job_t *j )
|
||||
}
|
||||
|
||||
|
||||
if(p->type == INTERNAL_BUILTIN)
|
||||
if( p->type == INTERNAL_BUILTIN )
|
||||
builtin_pop_io();
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Close the pipe the current process uses to read from the previous process_t
|
||||
*/
|
||||
@@ -1223,7 +1217,7 @@ int exec_subshell( const wchar_t *cmd,
|
||||
b_append( io_buffer->param2.out_buffer, &z, 1 );
|
||||
|
||||
begin=end=io_buffer->param2.out_buffer->buff;
|
||||
|
||||
|
||||
if( l )
|
||||
{
|
||||
while( 1 )
|
||||
|
||||
5
exec.h
5
exec.h
@@ -3,6 +3,9 @@
|
||||
*/
|
||||
|
||||
#ifndef FISH_EXEC_H
|
||||
/**
|
||||
Header guard
|
||||
*/
|
||||
#define FISH_EXEC_H
|
||||
|
||||
#include <wchar.h>
|
||||
@@ -20,7 +23,7 @@
|
||||
*/
|
||||
void exec_init();
|
||||
|
||||
/*
|
||||
/**
|
||||
Destroy dynamically allocated data and other resources used by the
|
||||
exec library
|
||||
*/
|
||||
|
||||
75
expand.c
75
expand.c
@@ -78,7 +78,43 @@ parameter expansion.
|
||||
#define LAST_STR L"last"
|
||||
|
||||
/**
|
||||
Return the environment variable value for the string starting at in
|
||||
Characters which make a string unclean if they are the first
|
||||
character of the string. See \c is_clean().
|
||||
*/
|
||||
#define UNCLEAN_FIRST L"~%"
|
||||
/**
|
||||
Unclean characters. See \c is_clean().
|
||||
*/
|
||||
#define UNCLEAN L"$*?\\\"'({})"
|
||||
|
||||
/**
|
||||
Test if the specified argument is clean, i.e. it does not contain
|
||||
any tokens which need to be expanded or otherwise altered. Clean
|
||||
strings can be passed through expand_string and expand_one without
|
||||
changing them. About 90% of all strings are clean, so skipping
|
||||
expantion on them actually does save a small amount of time.
|
||||
*/
|
||||
static int is_clean( const wchar_t *in )
|
||||
{
|
||||
|
||||
const wchar_t * str = in;
|
||||
|
||||
if( wcschr( UNCLEAN_FIRST, *str ) )
|
||||
return 0;
|
||||
while( *str )
|
||||
{
|
||||
if( wcschr( UNCLEAN, *str ) )
|
||||
return 0;
|
||||
str++;
|
||||
}
|
||||
|
||||
// debug( 1, L"%ls", in );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
Return the environment variable value for the string starting at \c in.
|
||||
*/
|
||||
static wchar_t *expand_var( wchar_t *in )
|
||||
{
|
||||
@@ -1085,9 +1121,7 @@ static int expand_subshell( wchar_t *in, array_list_t *out )
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
len1 = (paran_begin-in);
|
||||
len2 = wcslen(paran_end)-1;
|
||||
@@ -1111,10 +1145,10 @@ static int expand_subshell( wchar_t *in, array_list_t *out )
|
||||
free( subcmd );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
al_init( &tail_expand );
|
||||
expand_subshell( wcsdup(paran_end+1), &tail_expand );
|
||||
|
||||
|
||||
for( i=0; i<al_get_count( &sub_res ); i++ )
|
||||
{
|
||||
wchar_t *sub_item, *sub_item2;
|
||||
@@ -1122,20 +1156,20 @@ static int expand_subshell( wchar_t *in, array_list_t *out )
|
||||
sub_item2 = expand_escape( sub_item, 1 );
|
||||
free(sub_item);
|
||||
int item_len = wcslen( sub_item2 );
|
||||
|
||||
|
||||
for( j=0; j<al_get_count( &tail_expand ); j++ )
|
||||
{
|
||||
string_buffer_t whole_item;
|
||||
wchar_t *tail_item = (wchar_t *)al_get( &tail_expand, j );
|
||||
|
||||
|
||||
sb_init( &whole_item );
|
||||
|
||||
|
||||
sb_append_substring( &whole_item, in, len1 );
|
||||
sb_append_char( &whole_item, INTERNAL_SEPARATOR );
|
||||
sb_append_substring( &whole_item, sub_item2, item_len );
|
||||
sb_append_char( &whole_item, INTERNAL_SEPARATOR );
|
||||
sb_append( &whole_item, tail_item );
|
||||
|
||||
|
||||
al_push( out, whole_item.buff );
|
||||
}
|
||||
|
||||
@@ -1147,7 +1181,7 @@ static int expand_subshell( wchar_t *in, array_list_t *out )
|
||||
|
||||
al_foreach( &tail_expand, (void (*)(const void *))&free );
|
||||
al_destroy( &tail_expand );
|
||||
|
||||
|
||||
free( subcmd );
|
||||
return 1;
|
||||
}
|
||||
@@ -1210,7 +1244,7 @@ static int tilde_expand( wchar_t **ptr )
|
||||
old_in = name_end;
|
||||
|
||||
char *name_str = wcs2str( name );
|
||||
|
||||
|
||||
struct passwd *userinfo =
|
||||
getpwnam( name_str );
|
||||
|
||||
@@ -1311,7 +1345,13 @@ int expand_string( wchar_t *str,
|
||||
|
||||
int i;
|
||||
int subshell_ok = 1;
|
||||
|
||||
|
||||
if( (!(flags & ACCEPT_INCOMPLETE)) && is_clean( str ) )
|
||||
{
|
||||
al_push( end_out, str );
|
||||
return 1;
|
||||
}
|
||||
|
||||
al_init( &list1 );
|
||||
al_init( &list2 );
|
||||
|
||||
@@ -1328,6 +1368,7 @@ int expand_string( wchar_t *str,
|
||||
if( (pos == str) || ( *(pos-1) != L'\\' ) )
|
||||
{
|
||||
error( SUBSHELL_ERROR, L"Subshells not allowed", -1 );
|
||||
free( str );
|
||||
al_destroy( &list1 );
|
||||
al_destroy( &list2 );
|
||||
return 0;
|
||||
@@ -1354,7 +1395,7 @@ int expand_string( wchar_t *str,
|
||||
for( i=0; i<al_get_count( in ); i++ )
|
||||
{
|
||||
wchar_t *next;
|
||||
|
||||
|
||||
next = expand_unescape( (wchar_t *)al_get( in, i ),
|
||||
1);
|
||||
|
||||
@@ -1500,12 +1541,14 @@ wchar_t *expand_one( wchar_t *string, int flags )
|
||||
array_list_t l;
|
||||
int res;
|
||||
wchar_t *one;
|
||||
|
||||
if( (!(flags & ACCEPT_INCOMPLETE)) && is_clean( string ) )
|
||||
return string;
|
||||
|
||||
al_init( &l );
|
||||
res = expand_string( string, &l, flags );
|
||||
if( !res )
|
||||
{
|
||||
free( string );
|
||||
one = 0;
|
||||
}
|
||||
else
|
||||
@@ -1520,7 +1563,7 @@ wchar_t *expand_one( wchar_t *string, int flags )
|
||||
al_set( &l, 0, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
al_foreach( &l, (void(*)(const void *))&free );
|
||||
al_destroy( &l );
|
||||
return one;
|
||||
|
||||
15
expand.h
15
expand.h
@@ -10,6 +10,9 @@
|
||||
*/
|
||||
|
||||
#ifndef FISH_EXPAND_H
|
||||
/**
|
||||
Header guard
|
||||
*/
|
||||
#define FISH_EXPAND_H
|
||||
|
||||
#include <wchar.h>
|
||||
@@ -51,7 +54,7 @@
|
||||
|
||||
#define DIRECTORIES_ONLY 32
|
||||
|
||||
/*
|
||||
/**
|
||||
Use unencoded private-use keycodes for internal characters
|
||||
*/
|
||||
#define EXPAND_RESERVED 0xf000
|
||||
@@ -122,11 +125,9 @@ wchar_t *expand_one( wchar_t *in, int flag );
|
||||
/**
|
||||
Expand backslashed escapes and substitute them with their unescaped
|
||||
counterparts. Also optionally change the wildcards, the tilde
|
||||
character and a few more into constants which are defined to be
|
||||
outside of the valid character space, but still inside the valid
|
||||
space for a wchar_t. This assumes that a wchar_t is at least 32
|
||||
bits long AND that the characterset is UCS4 or some other 31-bit
|
||||
character set.
|
||||
character and a few more into constants which are defined in a
|
||||
private use area of Unicode. This assumes wchar_t is a unicode
|
||||
character. character set.
|
||||
|
||||
The result must be free()d. The original string is not modified. If
|
||||
an invalid sequence is specified, 0 is returned.
|
||||
@@ -161,7 +162,7 @@ wchar_t *expand_escape_variable( const wchar_t *in );
|
||||
wchar_t *expand_tilde(wchar_t *in);
|
||||
|
||||
/**
|
||||
Locate the last subshell in the specified string.
|
||||
Locate the first subshell in the specified string.
|
||||
|
||||
\param in the string to search for subshells
|
||||
\param begin the starting paranthesis of the subshell
|
||||
|
||||
70
fish_tests.c
70
fish_tests.c
@@ -1,4 +1,4 @@
|
||||
/** \file main.c
|
||||
/** \file fish_tests.c
|
||||
Various bug and feature tests. Compiled and run by make test.
|
||||
*/
|
||||
|
||||
@@ -38,11 +38,23 @@
|
||||
#include "expand.h"
|
||||
#include "parser.h"
|
||||
#include "tokenizer.h"
|
||||
#include "output.h"
|
||||
#include "exec.h"
|
||||
#include "event.h"
|
||||
|
||||
/**
|
||||
Number of laps to run performance testing loop
|
||||
*/
|
||||
#define LAPS 50
|
||||
|
||||
/**
|
||||
Number of encountered errors
|
||||
*/
|
||||
static int err_count=0;
|
||||
|
||||
/**
|
||||
Print formatted output
|
||||
*/
|
||||
static void say( wchar_t *blah, ... )
|
||||
{
|
||||
va_list va;
|
||||
@@ -52,6 +64,9 @@ static void say( wchar_t *blah, ... )
|
||||
wprintf( L"\n" );
|
||||
}
|
||||
|
||||
/**
|
||||
Print formatted error string
|
||||
*/
|
||||
static void err( wchar_t *blah, ... )
|
||||
{
|
||||
va_list va;
|
||||
@@ -64,16 +79,25 @@ static void err( wchar_t *blah, ... )
|
||||
wprintf( L"\n" );
|
||||
}
|
||||
|
||||
/**
|
||||
Print ok message
|
||||
*/
|
||||
static void ok()
|
||||
{
|
||||
wprintf( L"OK\n" );
|
||||
}
|
||||
|
||||
/**
|
||||
Compare two pointers
|
||||
*/
|
||||
static int pq_compare( void *e1, void *e2 )
|
||||
{
|
||||
return e1-e2;
|
||||
}
|
||||
|
||||
/**
|
||||
Test priority queue functionality
|
||||
*/
|
||||
static int pq_test( int elements )
|
||||
{
|
||||
int i;
|
||||
@@ -114,7 +138,9 @@ static int pq_test( int elements )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Test stack functionality
|
||||
*/
|
||||
static int stack_test( int elements )
|
||||
{
|
||||
int i;
|
||||
@@ -160,7 +186,9 @@ static int stack_test( int elements )
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Hash function for pointers
|
||||
*/
|
||||
static int hash_func( const void *data )
|
||||
{
|
||||
/* srand( (int)data );
|
||||
@@ -170,12 +198,18 @@ static int hash_func( const void *data )
|
||||
return 127*((foo^0xefc7e214)) ^(foo<<11);
|
||||
}
|
||||
|
||||
/**
|
||||
Pointer hash comparison function
|
||||
*/
|
||||
static int compare_func( const void *key1, const void *key2 )
|
||||
{
|
||||
return key1==key2;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Hashtable test
|
||||
*/
|
||||
static int hash_test( int elements )
|
||||
{
|
||||
int i;
|
||||
@@ -249,6 +283,9 @@ static int hash_test( int elements )
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Arraylist test
|
||||
*/
|
||||
static int al_test( int sz)
|
||||
{
|
||||
int i;
|
||||
@@ -280,6 +317,9 @@ static int al_test( int sz)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Stringbuffer test
|
||||
*/
|
||||
static void sb_test()
|
||||
{
|
||||
string_buffer_t b;
|
||||
@@ -299,7 +339,9 @@ static void sb_test()
|
||||
say( (wchar_t *)b.buff );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Performs all tests of the util library
|
||||
*/
|
||||
static void test_util()
|
||||
{
|
||||
int i;
|
||||
@@ -346,8 +388,9 @@ static void test_util()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Test the tokenizer
|
||||
*/
|
||||
static void test_tok()
|
||||
{
|
||||
tokenizer t;
|
||||
@@ -412,6 +455,9 @@ static void test_tok()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Test the parser
|
||||
*/
|
||||
static void test_parser()
|
||||
{
|
||||
say( L"Testing parser" );
|
||||
@@ -514,7 +560,9 @@ static int expand_test( const wchar_t *in, int flags, ... )
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Test globbing and other parameter expantion
|
||||
*/
|
||||
static void test_expand()
|
||||
{
|
||||
say( L"Testing parameter expantion" );
|
||||
@@ -536,7 +584,9 @@ static void test_expand()
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Test speed of completion calculations
|
||||
*/
|
||||
void perf_complete()
|
||||
{
|
||||
wchar_t c;
|
||||
@@ -607,7 +657,9 @@ void perf_complete()
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Main test
|
||||
*/
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
|
||||
|
||||
11
fishd.c
11
fishd.c
@@ -350,12 +350,17 @@ void load_or_save( int save)
|
||||
close( c.fd );
|
||||
}
|
||||
|
||||
/**
|
||||
Load variables from disk
|
||||
*/
|
||||
static void load()
|
||||
{
|
||||
load_or_save(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Save variables to disk
|
||||
*/
|
||||
static void save()
|
||||
{
|
||||
load_or_save(1);
|
||||
@@ -376,7 +381,9 @@ static void init()
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Main function for fishd
|
||||
*/
|
||||
int main( int argc, char ** argv )
|
||||
{
|
||||
int child_socket, t;
|
||||
|
||||
@@ -357,7 +357,7 @@ void highlight_shell( wchar_t * buff,
|
||||
/*
|
||||
Locate and syntax highlight subshells recursively
|
||||
*/
|
||||
|
||||
|
||||
wchar_t *buffcpy = wcsdup( buff );
|
||||
wchar_t *subpos=buffcpy;
|
||||
int done=0;
|
||||
@@ -386,8 +386,9 @@ void highlight_shell( wchar_t * buff,
|
||||
break;
|
||||
|
||||
subpos = end+1;
|
||||
|
||||
}
|
||||
free( buffcpy );
|
||||
free( buffcpy);
|
||||
|
||||
|
||||
last_val=0;
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
#Completions for make
|
||||
complete -x -c make -a "(grep -h -E '^[^#%=\t$][^#%=$]*:([^=]|$)' Makefile makefile GNUmakefile | cut -d ":" -f 1 | sed -r 's/^ *//;s/ *$//;s/ +/\n/g' ^/dev/null)" -d "Target"
|
||||
|
||||
function __fish_print_make_targets
|
||||
set files Makefile makefile GNUmakefile
|
||||
grep -h -E '^[^#%=$[:space:]][^#%=$]*:([^=]|$)' $files | cut -d ":" -f 1 | sed -r 's/^ *//;s/ *$//;s/ +/\n/g' ^/dev/null
|
||||
end
|
||||
|
||||
complete -x -c make -a "(__fish_print_make_targets)" -d "Target"
|
||||
complete -r -c make -s f -d "Use file as makefile" -r
|
||||
complete -x -c make -s C -x -a "(__fish_complete_directory (commandline -ct))" -d "Change directory"
|
||||
complete -c make -s d -d "Debug"
|
||||
|
||||
@@ -43,4 +43,4 @@ function __fish_set_is_color -d 'Test if We are specifying a color value for the
|
||||
end
|
||||
end
|
||||
|
||||
complete -c set -n '__fish_set_is_color' -x -a '$__fish_colors' -d Color
|
||||
complete -c set -n '__fish_set_is_color' -x -a '(set_color --print-colors)' -d Color
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
set -g __fish_colors black red green brown blue magenta cyan white normal
|
||||
|
||||
complete -c set_color -x -d "Color" -a '$__fish_colors'
|
||||
complete -c set_color -s b -l background -x -a '$__fish_colors' -d "Change background color"
|
||||
complete -c set_color -x -d "Color" -a '(set_color --print-colors)'
|
||||
complete -c set_color -s b -l background -x -a '(set_color --print-colors)' -d "Change background color"
|
||||
complete -c set_color -s o -l bold -d 'Make font bold'
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
# Set default field separators
|
||||
#
|
||||
|
||||
set IFS \ \t\n
|
||||
|
||||
set -g IFS \ \t\n
|
||||
|
||||
#
|
||||
# Add a few common directories to path, if they exists. Note that pure
|
||||
@@ -18,14 +17,12 @@ set IFS \ \t\n
|
||||
|
||||
for i in /bin /usr/bin /usr/X11R6/bin @PREFIX@/bin
|
||||
if test -d $i
|
||||
if echo $PATH|grep $i >/dev/null
|
||||
else
|
||||
if not echo $PATH|grep $i >/dev/null
|
||||
set PATH $PATH $i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
#
|
||||
# Set some value for LANG if nothing was set before
|
||||
#
|
||||
|
||||
@@ -32,7 +32,7 @@ function _contains_help -d "Helper function for contains"
|
||||
end
|
||||
|
||||
function contains -d "Test if a key is contained in a set of values"
|
||||
while count $argv >/dev/null
|
||||
while set -q argv
|
||||
switch $argv[1]
|
||||
case '-h' '--h' '--he' '--hel' '--help'
|
||||
_contains_help
|
||||
@@ -56,8 +56,7 @@ function contains -d "Test if a key is contained in a set of values"
|
||||
set -e argv[1]
|
||||
end
|
||||
|
||||
if count $argv >/dev/null
|
||||
else
|
||||
if not set -q argv
|
||||
echo "contains: Key not specified"
|
||||
return 1
|
||||
end
|
||||
@@ -288,18 +287,18 @@ function vared -d "Edit variable value"
|
||||
else
|
||||
|
||||
printf "vared: %s is an array variable. Use " $argv
|
||||
set_color $FISH_COLOR_COMMAND
|
||||
set_color $fish_color_command
|
||||
printf vared
|
||||
set_color $FISH_COLOR_NORMAL
|
||||
set_color $fish_color_normal
|
||||
printf " %s[n] to edit the n:th element of %s\n" $argv $argv
|
||||
|
||||
end
|
||||
end
|
||||
else
|
||||
printf "vared: Expected exactly one argument, got %s.\n\nSynopsis:\n\t" (count $argv)
|
||||
set_color $FISH_COLOR_COMMAND
|
||||
set_color $fish_color_command
|
||||
printf vared
|
||||
set_color $FISH_COLOR_NORMAL
|
||||
set_color $fish_color_normal
|
||||
printf " VARIABLE\n"
|
||||
end
|
||||
end
|
||||
@@ -724,36 +723,6 @@ function type -d "Print the type of a command"
|
||||
return $status
|
||||
end
|
||||
|
||||
function __fish_umask_help
|
||||
|
||||
set bullet \*
|
||||
if count $LANG >/dev/null
|
||||
if test (expr match $LANG ".*UTF") -gt 0
|
||||
set bullet \u2022
|
||||
end
|
||||
end
|
||||
|
||||
echo \tumask - Set or get the user file-creation mask
|
||||
echo
|
||||
echo (__bold Synopsis)
|
||||
echo
|
||||
echo \t(set_color $fish_color_command)umask(set_color normal) [OPTIONS] [mask]
|
||||
echo
|
||||
echo (__bold Description)
|
||||
echo
|
||||
echo \tWith no argument, the current file-creation mask is printed, if an\n\targument is specified, it is the new file creation mask.
|
||||
echo
|
||||
echo \t$bullet (__bold -h) or (__bold --help) print this message
|
||||
echo \t$bullet (__bold -S) or (__bold --symbolic) prints the file-creation mask in symbolic\n\t\ \ form instead of octal form. Use \'(set_color $fish_color_command)man(set_color $fish_color_normal) chmod\' for more information.
|
||||
echo \t$bullet (__bold -p) or (__bold --as-command) prints any output in a form that may be reused\n\t\ \ as input
|
||||
echo
|
||||
echo (__bold Example)
|
||||
echo
|
||||
echo \t\'(set_color $fish_color_command)umask(set_color normal) 600\' sets the file creation mask to read and write for the\n\towner and no permissions at all for any other users.
|
||||
echo
|
||||
|
||||
end
|
||||
|
||||
function __fish_umask_parse -d "Parses a file permission specification as into an octal version"
|
||||
# Test if already a valid octal mask, and pad it with zeros
|
||||
if echo $argv | grep -E '^(0|)[0-7]{1,3}$' >/dev/null
|
||||
@@ -768,19 +737,6 @@ function __fish_umask_parse -d "Parses a file permission specification as into a
|
||||
|
||||
set -e implicit_all
|
||||
|
||||
# Make sure the current umask is defined
|
||||
if not set -q umask
|
||||
set umask 0000
|
||||
end
|
||||
|
||||
# If umask is invalid, reset it
|
||||
if not echo $umask | grep -E '^(0|)[0-7]{1,3}$' >/dev/null
|
||||
set umask 0000
|
||||
end
|
||||
|
||||
# Pad umask with zeros
|
||||
for i in (seq (echo 5-(echo $umask|wc -c)|bc)); set -- argv 0$umask; end
|
||||
|
||||
# Insert inverted umask into res variable
|
||||
|
||||
set tmp $umask
|
||||
@@ -875,19 +831,6 @@ function __fish_umask_print_symbolic
|
||||
set -l res ""
|
||||
set -l letter a u g o
|
||||
|
||||
# Make sure the current umask is defined
|
||||
if not set -q umask
|
||||
set umask 0000
|
||||
end
|
||||
|
||||
# If umask is invalid, reset it
|
||||
if not echo $umask | grep -E '^(0|)[0-7]{1,3}$' >/dev/null
|
||||
set umask 0000
|
||||
end
|
||||
|
||||
# Pad umask with zeros
|
||||
for i in (seq (echo 5-(echo $umask|wc -c)|bc)); set -- argv 0$umask; end
|
||||
|
||||
for i in 2 3 4
|
||||
set res $res,$letter[$i]=
|
||||
set val (echo $umask|cut -c $i)
|
||||
@@ -933,7 +876,7 @@ function umask -d "Set default file permission mask"
|
||||
|
||||
switch $opt[1]
|
||||
case -h --help
|
||||
__fish_umask_help
|
||||
help umask
|
||||
return 0
|
||||
|
||||
case -p --as-command
|
||||
@@ -984,6 +927,9 @@ end
|
||||
|
||||
function psub -d "Read from stdin into a file and output the filename. Remove the file when the command that calles psub exits."
|
||||
|
||||
set -l filename
|
||||
set -l funcname
|
||||
|
||||
if count $argv >/dev/null
|
||||
switch $argv[1]
|
||||
case '-h*' --h --he --hel --help
|
||||
@@ -998,7 +944,7 @@ function psub -d "Read from stdin into a file and output the filename. Remove th
|
||||
end
|
||||
|
||||
if not status --is-command-substitution
|
||||
echo psub: Not inside of command substitution
|
||||
echo psub: Not inside of command substitution >&2
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
@@ -53,10 +53,15 @@ end
|
||||
# Set various color values
|
||||
#
|
||||
|
||||
function set_default -d "Set an universal variable, unless it has already been set"
|
||||
function set_default_color -d "Set an universal variable, unless it has already been set. If set, verify that it is a valid color name"
|
||||
if not set -q $argv[1]
|
||||
set -U -- $argv
|
||||
return
|
||||
end
|
||||
if contains -- $$argv[1] (set_color --print-colors)
|
||||
return
|
||||
end
|
||||
set -U -- $argv
|
||||
end
|
||||
|
||||
function set_exported_default -d "Set an exported universal variable, unless it has already been set"
|
||||
@@ -67,28 +72,28 @@ end
|
||||
|
||||
|
||||
# Regular syntax highlighting colors
|
||||
set_default fish_color_normal normal
|
||||
set_default fish_color_command green
|
||||
set_default fish_color_redirection normal
|
||||
set_default fish_color_comment brown
|
||||
set_default fish_color_error red
|
||||
set_default_color fish_color_normal normal
|
||||
set_default_color fish_color_command green
|
||||
set_default_color fish_color_redirection normal
|
||||
set_default_color fish_color_comment brown
|
||||
set_default_color fish_color_error red
|
||||
|
||||
set_default fish_color_cwd green
|
||||
set_default_color fish_color_cwd green
|
||||
|
||||
# Background color for matching quotes and parenthesis
|
||||
set_default fish_color_match cyan
|
||||
set_default_color fish_color_match cyan
|
||||
|
||||
# Background color for search matches
|
||||
set_default fish_color_search_match purple
|
||||
set_default_color fish_color_search_match purple
|
||||
|
||||
# Pager colors
|
||||
set_default fish_pager_color_prefix cyan
|
||||
set_default fish_pager_color_completion normal
|
||||
set_default fish_pager_color_description normal
|
||||
set_default fish_pager_color_progress cyan
|
||||
set_default_color fish_pager_color_prefix cyan
|
||||
set_default_color fish_pager_color_completion normal
|
||||
set_default_color fish_pager_color_description normal
|
||||
set_default_color fish_pager_color_progress cyan
|
||||
|
||||
# Directory history colors
|
||||
set_default fish_color_history_current cyan
|
||||
set_default_color fish_color_history_current cyan
|
||||
|
||||
|
||||
#
|
||||
@@ -115,5 +120,5 @@ if command ls --color=auto --help 1>/dev/null 2>/dev/null
|
||||
end
|
||||
|
||||
|
||||
functions -e set_default
|
||||
functions -e set_default_color
|
||||
functions -e set_exported_default
|
||||
|
||||
28
input.c
28
input.c
@@ -263,6 +263,9 @@ void input_set_application( wchar_t *name )
|
||||
current_application_mappings = (array_list_t *)hash_get( &all_mappings, name );
|
||||
}
|
||||
|
||||
/**
|
||||
Get the mapping with the specified name
|
||||
*/
|
||||
static array_list_t *get_mapping( const wchar_t *mode )
|
||||
{
|
||||
|
||||
@@ -1109,6 +1112,9 @@ static void add_terminfo_mapping( const wchar_t *mode,
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Call input_expand_sequence on seq, and add the result as a mapping
|
||||
*/
|
||||
static void add_escaped_mapping( const wchar_t *mode,
|
||||
const wchar_t *seq,
|
||||
const wchar_t *desc,
|
||||
@@ -1122,7 +1128,9 @@ static void add_escaped_mapping( const wchar_t *mode,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Add bindings common to emacs and vi
|
||||
*/
|
||||
static void add_common_bindings()
|
||||
{
|
||||
static const wchar_t *name[] =
|
||||
@@ -1204,6 +1212,9 @@ static void add_common_bindings()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Add emacs-specific bindings
|
||||
*/
|
||||
static void add_emacs_bindings()
|
||||
{
|
||||
add_escaped_mapping( L"emacs", (L"\\C-a"), L"Control-a", L"beginning-of-line" );
|
||||
@@ -1216,6 +1227,9 @@ static void add_emacs_bindings()
|
||||
add_terminfo_mapping( L"emacs", (key_npage), L"Page Down", L"end-of-history" );
|
||||
}
|
||||
|
||||
/**
|
||||
Add vi-specific bindings
|
||||
*/
|
||||
static void add_vi_bindings()
|
||||
{
|
||||
add_mapping( L"vi", L"\e", L"Escape", L"bind -M vi-command" );
|
||||
@@ -1246,6 +1260,10 @@ static void add_vi_bindings()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Handle interruptions to key reading by reaping finshed jobs and
|
||||
propagating the interrupt to the reader.
|
||||
*/
|
||||
static int interrupt_handler()
|
||||
{
|
||||
if( job_reap( 1 ) )
|
||||
@@ -1313,6 +1331,9 @@ int input_init()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Free memory used by the specified mapping
|
||||
*/
|
||||
static void destroy_mapping( const void *key, const void *val )
|
||||
{
|
||||
int i;
|
||||
@@ -1344,7 +1365,9 @@ void input_destroy()
|
||||
del_curterm( cur_term );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Perform the action of the specified binding
|
||||
*/
|
||||
static wint_t input_exec_binding( mapping *m, const wchar_t *seq )
|
||||
{
|
||||
// fwprintf( stderr, L"Binding %ls\n", m->command );
|
||||
@@ -1398,7 +1421,6 @@ static wint_t input_exec_binding( mapping *m, const wchar_t *seq )
|
||||
/**
|
||||
Try reading the specified function mapping
|
||||
*/
|
||||
|
||||
static wint_t input_try_mapping( mapping *m)
|
||||
{
|
||||
int j, k;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/** \file input_common.h
|
||||
/** \file input_common.c
|
||||
|
||||
Implementation file for the low level input library
|
||||
|
||||
|
||||
6
intern.c
6
intern.c
@@ -17,6 +17,9 @@
|
||||
hash_table_t *intern_table=0;
|
||||
hash_table_t *intern_static_table=0;
|
||||
|
||||
/**
|
||||
Load static strings that are universally common. Currently only loads the empty string.
|
||||
*/
|
||||
static void intern_load_common_static()
|
||||
{
|
||||
intern_static( L"" );
|
||||
@@ -94,6 +97,9 @@ const wchar_t *intern_static( const wchar_t *in )
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
Free the specified key/value pair. Should only be called by intern_free_all at shutdown
|
||||
*/
|
||||
static void clear_value( const void *key, const void *data )
|
||||
{
|
||||
debug( 3, L"interned string: '%ls'", data );
|
||||
|
||||
6
intern.h
6
intern.h
@@ -12,7 +12,7 @@
|
||||
/**
|
||||
Return an identical copy of the specified string from a pool of unique strings. If the string was not in the pool, add a copy.
|
||||
|
||||
\param The string to return an interned copy of
|
||||
\param in the string to return an interned copy of
|
||||
*/
|
||||
const wchar_t *intern( const wchar_t *in );
|
||||
|
||||
@@ -20,11 +20,13 @@ const wchar_t *intern( const wchar_t *in );
|
||||
Insert the specified string literal into the pool of unique
|
||||
strings. The string will not first be copied, and it will not be
|
||||
free'd on exit.
|
||||
|
||||
\param in the string to add to the interned pool
|
||||
*/
|
||||
const wchar_t *intern_static( const wchar_t *in );
|
||||
|
||||
/**
|
||||
Free all interned strings
|
||||
Free all interned strings. Only call this at shutdown.
|
||||
*/
|
||||
void intern_free_all();
|
||||
|
||||
|
||||
1
io.c
1
io.c
@@ -95,7 +95,6 @@ io_data_t *io_buffer_create()
|
||||
b_init( buffer_redirect->param2.out_buffer );
|
||||
buffer_redirect->fd=1;
|
||||
|
||||
|
||||
if( exec_pipe( buffer_redirect->param1.pipe_fd ) == -1 )
|
||||
{
|
||||
debug( 1, PIPE_ERROR );
|
||||
|
||||
7
io.h
7
io.h
@@ -17,7 +17,9 @@ typedef struct io_data
|
||||
int io_mode;
|
||||
/** FD to redirect */
|
||||
int fd;
|
||||
/** parameter for redirection */
|
||||
/**
|
||||
Type-specific parameter for redirection
|
||||
*/
|
||||
union
|
||||
{
|
||||
/** Fds for IO_PIPE and for IO_BUFFER */
|
||||
@@ -28,6 +30,9 @@ typedef struct io_data
|
||||
int old_fd;
|
||||
} param1
|
||||
;
|
||||
/**
|
||||
Second type-specific paramter for redirection
|
||||
*/
|
||||
union
|
||||
{
|
||||
/** file creation flags to send to open for IO_FILE */
|
||||
|
||||
11
main.c
11
main.c
@@ -202,25 +202,26 @@ int main( int argc, char **argv )
|
||||
is_interactive_session &= (cmd == 0);
|
||||
is_interactive_session &= (my_optind == argc);
|
||||
is_interactive_session &= isatty(STDIN_FILENO);
|
||||
|
||||
|
||||
// fwprintf( stderr, L"%d %d %d\n", cmd==0, my_optind == argc, isatty(STDIN_FILENO) );
|
||||
|
||||
if( force_interactive )
|
||||
is_interactive_session=1;
|
||||
|
||||
|
||||
proc_init();
|
||||
output_init();
|
||||
event_init();
|
||||
exec_init();
|
||||
wutil_init();
|
||||
parser_init();
|
||||
builtin_init();
|
||||
function_init();
|
||||
env_init();
|
||||
complete_init();
|
||||
reader_init();
|
||||
|
||||
reader_init();
|
||||
|
||||
reader_push_current_filename( L"(internal)" );
|
||||
|
||||
|
||||
if( read_init() )
|
||||
{
|
||||
if( cmd != 0 )
|
||||
|
||||
24
parser.c
24
parser.c
@@ -51,6 +51,10 @@ The fish parser. Contains functions for parsing code.
|
||||
*/
|
||||
#define MAX_RECURSION_DEPTH 128
|
||||
|
||||
/**
|
||||
Message about reporting bugs, used on weird internal error to
|
||||
hopefully get them to report stuff.
|
||||
*/
|
||||
#define BUGREPORT_MSG L"If this error can be reproduced, please send a bug report to %s."
|
||||
|
||||
/**
|
||||
@@ -147,7 +151,25 @@ static int parse_job( process_t *p,
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int exec, parse, level, skipped;
|
||||
/**
|
||||
Time spent executing the specified command, including parse time for nested blocks
|
||||
*/
|
||||
int exec;
|
||||
/**
|
||||
Time spent parsing the specified command, incvluding execution time for command substitutions
|
||||
*/
|
||||
int parse;
|
||||
/**
|
||||
The block level of the specified command
|
||||
*/
|
||||
int level;
|
||||
/**
|
||||
If the execution of this command was skipped
|
||||
*/
|
||||
int skipped;
|
||||
/**
|
||||
The command string
|
||||
*/
|
||||
wchar_t *cmd;
|
||||
} profile_element_t;
|
||||
|
||||
|
||||
1
proc.c
1
proc.c
@@ -486,7 +486,6 @@ static void fire_process_event( const wchar_t *msg, int type, pid_t pid, int sta
|
||||
{
|
||||
static event_t ev;
|
||||
event_t e;
|
||||
|
||||
|
||||
e.function_name=0;
|
||||
|
||||
|
||||
55
reader.c
55
reader.c
@@ -93,7 +93,7 @@ commence.
|
||||
|
||||
/**
|
||||
The maximum number of characters to read from the keyboard without
|
||||
repainting. Note that this readahead wil only occur if new
|
||||
repainting. Note that this readahead will only occur if new
|
||||
characters are avaialble for reading, fish will never block for
|
||||
more input without repainting.
|
||||
*/
|
||||
@@ -1007,12 +1007,13 @@ static int insert_str(wchar_t *str)
|
||||
}
|
||||
else
|
||||
{
|
||||
int old_len = data->buff_len;
|
||||
|
||||
data->buff_len += len;
|
||||
check_size();
|
||||
|
||||
/* Insert space for extra character at the right position */
|
||||
if( data->buff_pos < data->buff_len )
|
||||
/* Insert space for extra characters at the right position */
|
||||
if( data->buff_pos < old_len )
|
||||
{
|
||||
memmove( &data->buff[data->buff_pos+len],
|
||||
&data->buff[data->buff_pos],
|
||||
@@ -1548,9 +1549,9 @@ void reader_sanity_check()
|
||||
|
||||
void reader_current_subshell_extent( wchar_t **a, wchar_t **b )
|
||||
{
|
||||
wchar_t *buffcpy = wcsdup( data->buff );
|
||||
wchar_t *begin, *end;
|
||||
|
||||
wchar_t *pos;
|
||||
|
||||
if( a )
|
||||
*a=0;
|
||||
if( b )
|
||||
@@ -1559,35 +1560,41 @@ void reader_current_subshell_extent( wchar_t **a, wchar_t **b )
|
||||
if( !data )
|
||||
return;
|
||||
|
||||
pos = data->buff;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
int bc, ec;
|
||||
|
||||
if( expand_locate_subshell( buffcpy,
|
||||
|
||||
if( expand_locate_subshell( pos,
|
||||
&begin,
|
||||
&end,
|
||||
1 ) <= 0)
|
||||
{
|
||||
begin=buffcpy;
|
||||
end = buffcpy + wcslen(data->buff);
|
||||
begin=data->buff;
|
||||
end = data->buff + wcslen(data->buff);
|
||||
break;
|
||||
}
|
||||
bc = begin-buffcpy;
|
||||
ec = end-buffcpy;
|
||||
|
||||
if( !end )
|
||||
{
|
||||
end = data->buff + wcslen(data->buff);
|
||||
}
|
||||
|
||||
bc = begin-data->buff;
|
||||
ec = end-data->buff;
|
||||
|
||||
if(( bc < data->buff_pos ) && (ec >= data->buff_pos) )
|
||||
{
|
||||
begin++;
|
||||
|
||||
//fwprintf( stderr, L"Subshell!\n" );
|
||||
break;
|
||||
}
|
||||
*begin=0;
|
||||
pos = end+1;
|
||||
}
|
||||
if( a )
|
||||
*a = data->buff + (begin-buffcpy);
|
||||
*a = begin;
|
||||
if( b )
|
||||
*b = data->buff + (end-buffcpy);
|
||||
free( buffcpy );
|
||||
*b = end;
|
||||
}
|
||||
|
||||
static void reader_current_job_or_process_extent( wchar_t **a,
|
||||
@@ -2383,14 +2390,12 @@ static int read_i()
|
||||
*/
|
||||
static int can_read( int fd )
|
||||
{
|
||||
struct pollfd pfd[] =
|
||||
{
|
||||
{
|
||||
fd, POLLIN, 0
|
||||
}
|
||||
}
|
||||
;
|
||||
return poll( pfd, 1, 0 ) == 1;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
23
set_color.c
23
set_color.c
@@ -96,13 +96,22 @@ int translate_color( char *str )
|
||||
|
||||
}
|
||||
|
||||
void print_colors()
|
||||
{
|
||||
int i;
|
||||
for( i=0; i<COLORS; i++ )
|
||||
{
|
||||
printf( "%s\n", col[i] );
|
||||
}
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
char *bgcolor=0;
|
||||
char *fgcolor=0;
|
||||
int fg, bg;
|
||||
int bold=0;
|
||||
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
#ifdef __GLIBC__
|
||||
@@ -125,6 +134,10 @@ int main( int argc, char **argv )
|
||||
"version", no_argument, 0, 'v'
|
||||
}
|
||||
,
|
||||
{
|
||||
"print-colors", no_argument, 0, 'c'
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
@@ -135,13 +148,13 @@ int main( int argc, char **argv )
|
||||
|
||||
int opt = getopt_long( argc,
|
||||
argv,
|
||||
"b:hvo",
|
||||
"b:hvoc",
|
||||
long_options,
|
||||
&opt_index );
|
||||
#else
|
||||
int opt = getopt( argc,
|
||||
argv,
|
||||
"b:hvo" );
|
||||
"b:hvoc" );
|
||||
#endif
|
||||
if( opt == -1 )
|
||||
break;
|
||||
@@ -166,6 +179,10 @@ int main( int argc, char **argv )
|
||||
fprintf( stderr, "set_color, version %s\n", PACKAGE_VERSION );
|
||||
exit( 0 );
|
||||
|
||||
case 'c':
|
||||
print_colors();
|
||||
exit(0);
|
||||
|
||||
case '?':
|
||||
return 1;
|
||||
|
||||
|
||||
2
signal.c
2
signal.c
@@ -500,5 +500,3 @@ void signal_unblock()
|
||||
|
||||
sigprocmask(SIG_UNBLOCK, &chldset, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
21
tokenizer.c
21
tokenizer.c
@@ -46,7 +46,7 @@
|
||||
/**
|
||||
Characters that separate tokens. They are ordered by frequency of occurrence to increase parsing speed.
|
||||
*/
|
||||
#define SEP L" \n;|#\t\r<>^&"
|
||||
#define SEP L" \n|\t;#\r<>^&"
|
||||
/**
|
||||
Tests if the tokenizer buffer is large enough to hold contents of
|
||||
the specified length, and if not, reallocates the tokenizer buffer.
|
||||
@@ -192,8 +192,18 @@ static int is_string_char( wchar_t c )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
/**
|
||||
Quick test to catch the most common 'non-magical' characters, makes
|
||||
read_string slightly faster by adding a fast path for the most
|
||||
common characters. This is obviously not a suitable replacement for
|
||||
iswalpha.
|
||||
*/
|
||||
static int myal( wchar_t c )
|
||||
{
|
||||
return (c>=L'a' && c<=L'z') || (c>=L'A'&&c<=L'Z');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,6 +222,11 @@ static void read_string( tokenizer *tok )
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
|
||||
if( !myal( *tok->buff ) )
|
||||
{
|
||||
// debug(1, L"%lc", *tok->buff );
|
||||
|
||||
if( *tok->buff == L'\\' )
|
||||
{
|
||||
tok->buff++;
|
||||
@@ -338,6 +353,8 @@ static void read_string( tokenizer *tok )
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( !do_loop )
|
||||
break;
|
||||
|
||||
57
util.c
57
util.c
@@ -27,11 +27,16 @@
|
||||
#include "wutil.h"
|
||||
|
||||
/**
|
||||
Minimum allocated size for data structures. Used to avoid excessive
|
||||
memory allocations for lists, hash tables, etc, which are nearly
|
||||
empty.
|
||||
Minimum allocated size for data structures. Used to avoid excessive
|
||||
memory allocations for lists, hash tables, etc, which are nearly
|
||||
empty.
|
||||
*/
|
||||
#define MIN_SIZE 128
|
||||
#define MIN_SIZE 32
|
||||
|
||||
/**
|
||||
Minimum size for hash tables
|
||||
*/
|
||||
#define HASH_MIN_SIZE 7
|
||||
|
||||
/**
|
||||
Maximum number of characters that can be inserted using a single
|
||||
@@ -191,7 +196,11 @@ void hash_init( hash_table_t *h,
|
||||
int (*hash_func)(const void *key),
|
||||
int (*compare_func)(const void *key1, const void *key2) )
|
||||
{
|
||||
hash_init2( h, hash_func, compare_func, 31 );
|
||||
h->arr = 0;
|
||||
h->size = 0;
|
||||
h->count=0;
|
||||
h->hash_func = hash_func;
|
||||
h->compare_func = compare_func;
|
||||
}
|
||||
|
||||
|
||||
@@ -207,8 +216,11 @@ void hash_destroy( hash_table_t *h )
|
||||
static int hash_search( hash_table_t *h,
|
||||
const void *key )
|
||||
{
|
||||
int hv = h->hash_func( key );
|
||||
int pos = abs(hv) % h->size;
|
||||
int hv;
|
||||
int pos;
|
||||
|
||||
hv = h->hash_func( key );
|
||||
pos = abs(hv) % h->size;
|
||||
while(1)
|
||||
{
|
||||
if( (h->arr[pos].key == 0 ) ||
|
||||
@@ -229,13 +241,13 @@ static int hash_realloc( hash_table_t *h,
|
||||
{
|
||||
|
||||
/* Avoid reallocating when using pathetically small tables */
|
||||
if( ( sz < h->size ) && (h->size < MIN_SIZE))
|
||||
if( ( sz < h->size ) && (h->size < HASH_MIN_SIZE))
|
||||
return 1;
|
||||
sz = maxi( sz, MIN_SIZE );
|
||||
|
||||
sz = maxi( sz, HASH_MIN_SIZE );
|
||||
|
||||
hash_struct_t *old_arr = h->arr;
|
||||
int old_size = h->size;
|
||||
|
||||
|
||||
int i;
|
||||
|
||||
h->arr = malloc( sizeof( hash_struct_t) * sz );
|
||||
@@ -294,7 +306,10 @@ int hash_put( hash_table_t *h,
|
||||
const void *hash_get( hash_table_t *h,
|
||||
const void *key )
|
||||
{
|
||||
int pos = hash_search( h, key );
|
||||
if( !h->count )
|
||||
return 0;
|
||||
|
||||
int pos = hash_search( h, key );
|
||||
if( h->arr[pos].key == 0 )
|
||||
return 0;
|
||||
else
|
||||
@@ -303,7 +318,10 @@ const void *hash_get( hash_table_t *h,
|
||||
|
||||
const void *hash_get_key( hash_table_t *h,
|
||||
const void *key )
|
||||
{
|
||||
{
|
||||
if( !h->count )
|
||||
return 0;
|
||||
|
||||
int pos = hash_search( h, key );
|
||||
if( h->arr[pos].key == 0 )
|
||||
return 0;
|
||||
@@ -321,6 +339,16 @@ void hash_remove( hash_table_t *h,
|
||||
const void **old_key,
|
||||
const void **old_val )
|
||||
{
|
||||
if( !h->count )
|
||||
{
|
||||
|
||||
if( old_key != 0 )
|
||||
*old_key = 0;
|
||||
if( old_val != 0 )
|
||||
*old_val = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
int pos = hash_search( h, key );
|
||||
int next_pos;
|
||||
|
||||
@@ -377,6 +405,9 @@ void hash_remove( hash_table_t *h,
|
||||
int hash_contains( hash_table_t *h,
|
||||
const void *key )
|
||||
{
|
||||
if( !h->count )
|
||||
return 0;
|
||||
|
||||
int pos = hash_search( h, key );
|
||||
return h->arr[pos].key != 0;
|
||||
}
|
||||
|
||||
77
util.h
77
util.h
@@ -136,14 +136,17 @@ typedef buffer_t string_buffer_t;
|
||||
Returns the larger of two ints
|
||||
*/
|
||||
int maxi( int a, int b );
|
||||
|
||||
/**
|
||||
Returns the smaller of two ints
|
||||
*/
|
||||
int mini( int a, int b );
|
||||
|
||||
/**
|
||||
Returns the larger of two floats
|
||||
*/
|
||||
float maxf( float a, float b );
|
||||
|
||||
/**
|
||||
Returns the smaller of two floats
|
||||
*/
|
||||
@@ -161,14 +164,19 @@ float minf( float a, float b );
|
||||
returned.
|
||||
*/
|
||||
void q_init( dyn_queue_t *q );
|
||||
|
||||
/** Destroy the queue */
|
||||
void q_destroy( dyn_queue_t *q );
|
||||
|
||||
/** Insert element into queue */
|
||||
int q_put( dyn_queue_t *q, void *e );
|
||||
|
||||
/** Remove and return next element from queue */
|
||||
void *q_get( dyn_queue_t *q);
|
||||
|
||||
/** Return next element from queue without removing it */
|
||||
void *q_peek( dyn_queue_t *q);
|
||||
|
||||
/** Returns 1 if the queue is empty, 0 otherwise */
|
||||
int q_empty( dyn_queue_t *q );
|
||||
|
||||
@@ -224,6 +232,7 @@ void hash_remove( hash_table_t *h,
|
||||
const void *key,
|
||||
const void **old_key,
|
||||
const void **old_data );
|
||||
|
||||
/**
|
||||
Checks whether the specified key is in the hash table
|
||||
*/
|
||||
@@ -235,16 +244,23 @@ int hash_contains( hash_table_t *h,
|
||||
*/
|
||||
void hash_get_keys( hash_table_t *h,
|
||||
array_list_t *arr );
|
||||
|
||||
/**
|
||||
Appends all data elements in the table to the specified list
|
||||
*/
|
||||
void hash_get_data( hash_table_t *h,
|
||||
array_list_t *arr );
|
||||
/** Call the function func for each key/data pair in the table*/
|
||||
|
||||
/**
|
||||
Call the function func for each key/data pair in the table
|
||||
*/
|
||||
void hash_foreach( hash_table_t *h,
|
||||
void (*func)( const void *, const void * ) );
|
||||
/** Same as hash_foreach, but the function func takes an additional
|
||||
* argument, which is provided by the caller in the variable aux */
|
||||
|
||||
/**
|
||||
Same as hash_foreach, but the function func takes an additional
|
||||
argument, which is provided by the caller in the variable aux
|
||||
*/
|
||||
void hash_foreach2( hash_table_t *h, void (*func)( const void *,
|
||||
const void *,
|
||||
void *),
|
||||
@@ -269,10 +285,11 @@ int hash_wcs_func( const void *data );
|
||||
*/
|
||||
int hash_wcs_cmp( const void *a, const void *b );
|
||||
|
||||
/** Initialize the priority queue
|
||||
|
||||
\param q the queue to initialize
|
||||
\param compare a comparison function that can compare two entries in the queue
|
||||
/**
|
||||
Initialize the priority queue
|
||||
|
||||
\param q the queue to initialize
|
||||
\param compare a comparison function that can compare two entries in the queue
|
||||
*/
|
||||
void pq_init( priority_queue_t *q,
|
||||
int (*compare)(void *e1, void *e2) );
|
||||
@@ -289,6 +306,7 @@ int pq_put( priority_queue_t *q,
|
||||
Removes and returns the last entry in the priority queue
|
||||
*/
|
||||
void *pq_get( priority_queue_t *q );
|
||||
|
||||
/**
|
||||
Returns the last entry in the priority queue witout removing it.
|
||||
*/
|
||||
@@ -314,10 +332,16 @@ void pq_destroy( priority_queue_t *q );
|
||||
*/
|
||||
array_list_t *al_new();
|
||||
|
||||
/** Initialize the list. */
|
||||
/**
|
||||
Initialize the list.
|
||||
*/
|
||||
void al_init( array_list_t *l );
|
||||
/** Destroy the list and free memory used by it.*/
|
||||
|
||||
/**
|
||||
Destroy the list and free memory used by it.
|
||||
*/
|
||||
void al_destroy( array_list_t *l );
|
||||
|
||||
/**
|
||||
Append element to list
|
||||
|
||||
@@ -327,6 +351,7 @@ void al_destroy( array_list_t *l );
|
||||
\return 1 if succesfull, 0 otherwise
|
||||
*/
|
||||
int al_push( array_list_t *l, const void *o );
|
||||
|
||||
/**
|
||||
Append all elements of a list to another
|
||||
|
||||
@@ -335,6 +360,7 @@ int al_push( array_list_t *l, const void *o );
|
||||
\return 1 if succesfull, 0 otherwise
|
||||
*/
|
||||
int al_push_all( array_list_t *a, array_list_t *b );
|
||||
|
||||
/**
|
||||
Sets the element at the specified index
|
||||
|
||||
@@ -343,6 +369,7 @@ int al_push_all( array_list_t *a, array_list_t *b );
|
||||
\param o The element
|
||||
*/
|
||||
int al_set( array_list_t *l, int pos, const void *o );
|
||||
|
||||
/**
|
||||
Returns the element at the specified index
|
||||
|
||||
@@ -351,26 +378,37 @@ int al_set( array_list_t *l, int pos, const void *o );
|
||||
\return The element
|
||||
*/
|
||||
const void *al_get( array_list_t *l, int pos );
|
||||
|
||||
/**
|
||||
Truncates the list to new_sz items.
|
||||
*/
|
||||
void al_truncate( array_list_t *l, int new_sz );
|
||||
|
||||
/**
|
||||
Removes and returns the last entry in the list
|
||||
*/
|
||||
const void *al_pop( array_list_t *l );
|
||||
|
||||
/**
|
||||
Returns the number of elements in the list
|
||||
*/
|
||||
int al_get_count( array_list_t *l );
|
||||
|
||||
/**
|
||||
Returns the last entry in the list witout removing it.
|
||||
*/
|
||||
const void *al_peek( array_list_t *l );
|
||||
/** Returns 1 if the list is empty, 0 otherwise*/
|
||||
|
||||
/**
|
||||
Returns 1 if the list is empty, 0 otherwise
|
||||
*/
|
||||
int al_empty( array_list_t *l);
|
||||
/** Call the function func for each entry in the list*/
|
||||
|
||||
/**
|
||||
Call the function func for each entry in the list
|
||||
*/
|
||||
void al_foreach( array_list_t *l, void (*func)(const void * ));
|
||||
|
||||
/**
|
||||
Same as al_foreach, but the function func takes an additional
|
||||
argument, which is provided by the caller in the variable aux
|
||||
@@ -400,7 +438,9 @@ void al_foreach2( array_list_t *l, void (*func)(const void *, void *), void *aux
|
||||
|
||||
Which most people would find more intuitive.
|
||||
|
||||
The system breaks down if the user is using numbers of a base larger than 10.
|
||||
This won't return the optimum results for numbers in bases higher
|
||||
than ten, such as hexadecimal, but at least a stable sort order
|
||||
will result.
|
||||
*/
|
||||
int wcsfilecmp( const wchar_t *a, const wchar_t *b );
|
||||
|
||||
@@ -432,19 +472,21 @@ void sb_append_char( string_buffer_t *, wchar_t );
|
||||
Append a null terminated list of strings to the buffer.
|
||||
Example:
|
||||
|
||||
sb_append2( my_buff, L"foo", L"bar", 0 );
|
||||
sb_append2( my_buff, L"foo", L"bar", (void *)0 );
|
||||
|
||||
Do not forget to cast the last 0 to (void *), or you might encounter errors on 64-bit platforms!
|
||||
*/
|
||||
void sb_append2( string_buffer_t *, ... );
|
||||
|
||||
/**
|
||||
Append formated string data to the buffer. This function internally
|
||||
relies on \c vswprintf, so any filter options supported by that
|
||||
function is also supported by this function
|
||||
function is also supported by this function.
|
||||
*/
|
||||
int sb_printf( string_buffer_t *buffer, const wchar_t *format, ... );
|
||||
|
||||
/**
|
||||
Vararg version of sb_printf
|
||||
Vararg version of sb_printf.
|
||||
*/
|
||||
int sb_vprintf( string_buffer_t *buffer, const wchar_t *format, va_list va_orig );
|
||||
|
||||
@@ -454,15 +496,16 @@ int sb_vprintf( string_buffer_t *buffer, const wchar_t *format, va_list va_orig
|
||||
void sb_destroy( string_buffer_t * );
|
||||
|
||||
/**
|
||||
Truncate the buffer.
|
||||
Truncate the buffer. This will not deallocate the memory used, it will only set the contents of the string to L"\0".
|
||||
*/
|
||||
void sb_clear( string_buffer_t * );
|
||||
|
||||
|
||||
/**
|
||||
Initialize the specified buffer_t
|
||||
*/
|
||||
*/
|
||||
void b_init( buffer_t *b);
|
||||
|
||||
/**
|
||||
Destroy the specified buffer_t
|
||||
*/
|
||||
|
||||
19
wgetopt.c
19
wgetopt.c
@@ -1,3 +1,22 @@
|
||||
/** \file wgetopt.c
|
||||
A version of the getopt library for use with wide character strings.
|
||||
|
||||
This is simply the gnu getopt library, but converted for use with
|
||||
wchar_t instead of char. This is not usually useful since the argv
|
||||
array is always defined to be of type char**, but in fish, all
|
||||
internal commands use wide characters and hence this library is
|
||||
useful.
|
||||
|
||||
If you want to use this version of getopt in your program, simply
|
||||
copy wgetopt.c and wgetopt.h into your program, include wgetopt.h,
|
||||
and use all the regular getopt functions, prefixing every
|
||||
function, global variable and structure with a 'w', and use only
|
||||
wide character strings. There are no other functional changes in
|
||||
this version of getopt besides using wide character strings.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* Getopt for GNU.
|
||||
NOTE: getopt is now part of the C library, so if you don't know what
|
||||
"Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
|
||||
|
||||
85
wgetopt.h
85
wgetopt.h
@@ -1,7 +1,19 @@
|
||||
/** \file wgetopt.h
|
||||
The getopt librar for wide character strings.
|
||||
A version of the getopt library for use with wide character strings.
|
||||
|
||||
This is simply the gnu getopt library, but converted for use with
|
||||
wchar_t instead of char. This is not usually useful since the argv
|
||||
array is always defined to be of type char**, but in fish, all
|
||||
internal commands use wide characters and hence this library is
|
||||
useful.
|
||||
|
||||
If you want to use this version of getopt in your program, simply
|
||||
copy wgetopt.c and wgetopt.h into your program, include wgetopt.h,
|
||||
and use all the regular getopt functions, prefixing every
|
||||
function, global variable and structure with a 'w', and use only
|
||||
wide character strings. There are no other functional changes in
|
||||
this version of getopt besides using wide character strings.
|
||||
|
||||
This is simply the gnu getopt library, but converted for use with wchar_t instead of char. This is not usually useful since the argv array is always defined to be of type char**, but in fish, all internal commands use wide characters and hence this library is usefull.
|
||||
*/
|
||||
|
||||
|
||||
@@ -52,7 +64,7 @@ extern wchar_t *woptarg;
|
||||
When `getopt' returns EOF, this is the index of the first of the
|
||||
non-option elements that the caller should itself scan.
|
||||
|
||||
Otherwise, `optind' communicates from one call to the next
|
||||
Otherwise, `woptind' communicates from one call to the next
|
||||
how much of ARGV has been scanned so far. */
|
||||
|
||||
extern int woptind;
|
||||
@@ -89,54 +101,99 @@ extern int woptopt;
|
||||
|
||||
struct woption
|
||||
{
|
||||
/**
|
||||
long name for switch
|
||||
*/
|
||||
#if defined (__STDC__) && __STDC__
|
||||
const wchar_t *name;
|
||||
#else
|
||||
wchar_t *name;
|
||||
#endif
|
||||
/* has_arg can't be an enum because some compilers complain about
|
||||
type mismatches in all the code that assumes it is an int. */
|
||||
/**
|
||||
Must be one of no_argument, required_argument and
|
||||
optional_argument.
|
||||
|
||||
has_arg can't be an enum because some compilers complain about
|
||||
type mismatches in all the code that assumes it is an int.
|
||||
*/
|
||||
int has_arg;
|
||||
|
||||
/**
|
||||
If non-null, the flag whose value should be set if this switch is encountered
|
||||
*/
|
||||
int *flag;
|
||||
|
||||
/**
|
||||
If \c flag is non-null, this is the value that flag will be set
|
||||
to. Otherwise, this is the return-value of the function call.
|
||||
*/
|
||||
int val;
|
||||
};
|
||||
|
||||
/* Names for the values of the `has_arg' field of `struct option'. */
|
||||
|
||||
/**
|
||||
Specifies that a switch does not accept an argument
|
||||
*/
|
||||
#define no_argument 0
|
||||
/**
|
||||
Specifies that a switch requires an argument
|
||||
*/
|
||||
#define required_argument 1
|
||||
/**
|
||||
Specifies that a switch accepts an optional argument
|
||||
*/
|
||||
#define optional_argument 2
|
||||
|
||||
#if defined (__STDC__) && __STDC__
|
||||
#ifdef __GNU_LIBRARY__
|
||||
/* Get options from argument list */
|
||||
/**
|
||||
Get options from argument list. See the glibc manual for information on how to use this function.
|
||||
*/
|
||||
extern int wgetopt (int argc, wchar_t *const *argv, const wchar_t *shortopts);
|
||||
#else /* not __GNU_LIBRARY__ */
|
||||
/* Get options from argument list */
|
||||
|
||||
extern int wgetopt ();
|
||||
#endif /* __GNU_LIBRARY__ */
|
||||
/* Get options from argument list */
|
||||
/**
|
||||
Get options from argument list. See the glibc manual for information on how to use this function.
|
||||
*/
|
||||
extern int wgetopt_long (int argc, wchar_t *const *argv, const wchar_t *shortopts,
|
||||
const struct woption *longopts, int *longind);
|
||||
/* Get options from argument list */
|
||||
/**
|
||||
Get options from argument list. See the glibc manual for information on how to use this function.
|
||||
*/
|
||||
extern int wgetopt_long_only (int argc, wchar_t *const *argv,
|
||||
const wchar_t *shortopts,
|
||||
const struct woption *longopts, int *longind);
|
||||
|
||||
/** Internal only. Users should not call this directly. */
|
||||
/**
|
||||
Internal only. Users should not call this directly.
|
||||
*/
|
||||
extern int _wgetopt_internal (int argc, wchar_t *const *argv,
|
||||
const wchar_t *shortopts,
|
||||
const struct woption *longopts, int *longind,
|
||||
int long_only);
|
||||
#else /* not __STDC__ */
|
||||
/* Get options from argument list */
|
||||
|
||||
/**
|
||||
Get options from argument list. See the glibc manual for information on how to use this function.
|
||||
*/
|
||||
extern int wgetopt ();
|
||||
/* Get options from argument list */
|
||||
|
||||
/**
|
||||
Get options from argument list. See the glibc manual for information on how to use this function.
|
||||
*/
|
||||
extern int wgetopt_long ();
|
||||
/* Get options from argument list */
|
||||
|
||||
/**
|
||||
Get options from argument list. See the glibc manual for information on how to use this function.
|
||||
*/
|
||||
extern int wgetopt_long_only ();
|
||||
|
||||
/* Get options from argument list */
|
||||
/**
|
||||
Internal only. Users should not call this directly.
|
||||
*/
|
||||
extern int _wgetopt_internal ();
|
||||
#endif /* __STDC__ */
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
*/
|
||||
|
||||
#ifndef FISH_WILDCARD_H
|
||||
/**
|
||||
Header guard
|
||||
*/
|
||||
#define FISH_WILDCARD_H
|
||||
|
||||
#include <wchar.h>
|
||||
@@ -20,6 +23,9 @@
|
||||
|
||||
#define WILDCARD_RESERVED 0xf400
|
||||
|
||||
/**
|
||||
Enumeration of all wildcard types
|
||||
*/
|
||||
enum
|
||||
{
|
||||
/** Character representing any character except '/' */
|
||||
|
||||
40
wutil.c
40
wutil.c
@@ -22,28 +22,49 @@
|
||||
#include "common.h"
|
||||
#include "wutil.h"
|
||||
|
||||
#define TMP_LEN_MIN 256
|
||||
|
||||
/**
|
||||
Buffer for converting wide arguments to narrow arguments, used by
|
||||
the \c wutil_wcs2str() function.
|
||||
*/
|
||||
static char *tmp=0;
|
||||
/**
|
||||
Length of the \c tmp buffer.
|
||||
*/
|
||||
static size_t tmp_len=0;
|
||||
|
||||
int c = 0;
|
||||
/**
|
||||
Counts the number of calls to the wutil wrapper functions
|
||||
*/
|
||||
static int wutil_calls = 0;
|
||||
|
||||
void wutil_init()
|
||||
{
|
||||
}
|
||||
|
||||
void wutil_destroy()
|
||||
{
|
||||
free( tmp );
|
||||
tmp=0;
|
||||
tmp_len=0;
|
||||
debug( 3, L"wutil functions called %d times", c );
|
||||
debug( 3, L"wutil functions called %d times", wutil_calls );
|
||||
}
|
||||
|
||||
/**
|
||||
Convert the specified wide aharacter string to a narrow character
|
||||
string. This function uses an internal temporary buffer for storing
|
||||
the result so subsequent results will overwrite previous results.
|
||||
*/
|
||||
static char *wutil_wcs2str( const wchar_t *in )
|
||||
{
|
||||
c++;
|
||||
wutil_calls++;
|
||||
|
||||
size_t new_sz =MAX_UTF8_BYTES*wcslen(in)+1;
|
||||
if( tmp_len < new_sz )
|
||||
{
|
||||
free( tmp );
|
||||
tmp = malloc( new_sz );
|
||||
new_sz = maxi( new_sz, TMP_LEN_MIN );
|
||||
tmp = realloc( tmp, new_sz );
|
||||
if( !tmp )
|
||||
{
|
||||
die_mem();
|
||||
@@ -109,14 +130,17 @@ int wopen(const wchar_t *pathname, int flags, ...)
|
||||
|
||||
if( tmp )
|
||||
{
|
||||
va_start( argp, flags );
|
||||
|
||||
if( ! (flags & O_CREAT) )
|
||||
{
|
||||
res = open(tmp, flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
va_start( argp, flags );
|
||||
res = open(tmp, flags, va_arg(argp, int) );
|
||||
|
||||
va_end( argp );
|
||||
va_end( argp );
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
Reference in New Issue
Block a user