Compare commits

..

172 Commits

Author SHA1 Message Date
ridiculousfish
71bff26607 Merge remote-tracking branch 'upstream/master' 2012-04-18 13:21:03 -07:00
Jan Kanis
23bc10dfe6 Add stddef.h to util.c, so ptrdiff_t is defined in all environments 2012-01-31 01:38:20 +01:00
Jan Kanis
8ae00697c9 Merge branch 'merge-requests/14' 2012-01-25 01:21:14 +01:00
Jan Kanis
b0c6d891e9 reviewed merge reqest 14:
* fixed some whitespace inconsistencies
* changed variable handling in __fish_complete_subcommand_root
2012-01-25 01:14:47 +01:00
Jan Kanis
548164cd5e do not escape 'commandline' output without the -o flag 2012-01-25 00:11:00 +01:00
ridiculousfish
f12fd3707e Added a missing header for ptrdiff_t 2012-01-15 15:23:05 -08:00
ridiculousfish
8b407a32ff Fix to use proper type to compute difference between two pointers, which fixes a crash when fish is compiled LP64 2011-12-26 21:08:45 -08:00
Jan Kanis
344b9bdba3 Merge branch 'master' into merge-requests/14 2011-12-17 14:19:29 +01:00
Jan Kanis
834ea94eb9 update aptitude completions, patch by Dániel Ugra, closes Launchpad bug 238282 2011-09-25 01:24:34 +02:00
Jan Kanis
a060cc5893 uniq doesn't filter duplicates that aren't consecutive, use sort -u 2011-09-23 21:59:50 +02:00
gonchar
7ef0b3b821 *wvdial completion fixed 2011-09-23 18:40:14 +04:00
gonchar
39a2fd1717 * git rm and git status options are added
* ssh subcomand completion
* __fish_complete_subcommand now can skip variable number of tokens
2011-09-23 14:51:14 +04:00
gonchar
c66ec4df3d * __fish_complete_subcommand_root now passes arguments to
__fish_complete_subcommand

* sudo:
  - now can be completed bu group and user (-u and -g keys).
  - subcommand completion is fixed

* __fish_complete_proc.fish is added to complete killall command with
  list of running processes

* __fish_complete_tex.fish is updated with common options

* __fish_make_completion_signals.fish is added to make a list of kill
  signals for kill and killall

* completions:
 - minor filetype completions are added for djview, xpdf, mupdf, gv,
   xdvi
 - adduser is copmleted by user and group
 - dlocate and dpkg are completed by packages
 - find: -executable options is added
 - htop: options
 - funced and funcsave are completed by function names
 - ifdown and ifup are copmleted by interfaces
 - kill and killall: options, signals and processes
 - latexmk, ln, nm: options
 - lualatex and xelatex copmletions
 - sudo: -u and -g options
 - wvdial: presets
2011-09-23 12:24:21 +04:00
Jan Kanis
c25c48f763 Merge commit 'refs/merge-requests/13' of git://gitorious.org/fish-shell/fish-shell into merge-requests/13 2011-09-21 16:31:40 +02:00
Jan Kanis
5105d8d87e fixed bug where case-insensitive completion of /path\ with\ spaces/ doesn't reposition the cursor correctly 2011-09-21 15:40:45 +02:00
Mark A. Miller
35af336ff6 Fix an old, old reference to a long-gone fish function for gem.fish 2011-08-13 23:50:54 -05:00
Grissiom
157ca12d4b Merge commit 'refs/merge-requests/12' of git://gitorious.org/fish-shell/fish-shell into merge-requests/12 2011-07-28 10:06:19 +08:00
Adam Cozzette
e9d1a54983 fix: Fish may hang in Linux virtual console
I find that if I have a config.fish consisting of the following two
lines

status --job-control full
. empty.fish

where empty.fish is just an empty file in ~/.config/fish,  Fish will
hang when I attempt to log in on a virtual console (e.g. tty1). If I run
Fish within X11 or with either of those lines commented out,
everything's fine. I think the second line can be any command that cause
Fish to perform a fork().

The fix is pretty simple and just involves replacing getpid() with
getpgrp() in terminal_return_from_job in proc.c. See below for the
detailed explanation. I'm certainly no expert so I would appreciate it
if anyone else can confirm that my fix looks ok.

Here's what causes the bug as far as I can tell:

1. When I login on a virtual console,  /bin/login calls Fish. When Fish
begins executing its process group and the process group controlling the
terminal are both the pid of the /bin/login process.

2. The ". empty.fish" line causes Fish to fork a new process. The new
process creates a new process group and takes control of the terminal
under the name of that process group.

3. When the child process finishes,  the parent prcoess attempts to take
back control of the terminal by setting its controlling process group id
to be its pid.

4. Now there is a mismatch between the process group id of the Fish
shell (= the pid of the /bin/login process) and the process group id
controlling the terminal (= the pid of the Fish shell).
reader_interactive_init detects the mismatch and it thinks that it
doesn't have control of the terminal,  so it hangs as it waits for
control.

My fix just solves the problem in step 3 by having the parent process
correctly reassign control of the terminal to its process group.

Signed-off-by: Grissiom <chaos.proton@gmail.com>
2011-07-28 09:50:39 +08:00
Chris Nilsson
c8981c048f Merge commit 'refs/merge-requests/10' of git://gitorious.org/fish-shell/fish-shell into merge-requests/10 2011-07-10 16:32:44 +10:00
Andreas Raster
1ae44c6b3c still didn't work correctly, there were delimiters missing in the conditional as well 2011-06-24 02:45:05 +02:00
Andreas Raster
b2887477e3 last commits fix now also applied in the 'else' clause 2011-06-21 23:17:03 +02:00
Andreas Raster
8e2db29c9a fixed an issue when trying to complete something like 'cd /mnt/windows7/Program\ Files\ \('
fish would always spew a huge error message all over my terminal complaining about
some kind of tokenizer error, this patch fixed that
2011-06-21 17:02:49 +02:00
Shaun Reich
d38de7365a Change git-symbolic-ref to git symbolic-ref.
On my system at least (fedora 15), git-symbolic-ref is an invalid
command. Not sure if it's a BIC change from git itself, a distribution
thing, or a mistake on my end. Either way, no harm in using the
extended version. Now I get git branch status (yay).
2011-06-19 14:14:40 -04:00
Jakukyo Friel
cde6067cae minor changes on user doc 2011-02-20 02:58:11 +08:00
Christopher Nilsson
2583638f4b Merge commit 'refs/merge-requests/8' of git://gitorious.org/fish-shell/fish-shell into merge_request_8 2011-01-11 23:22:27 +11:00
Dylan Smith
11360b018f mimedb: Search all the defaults.list files rather than just the first.
The first defaults.list file found should not override all the other ones,
it just needs to be searched first.

E.g. For me (cat ~/.local/share/applications/defaults.list) returns
[Default Applications]
text/html=chromium-browser.desktop

So this should be used for text/html mimetypes, but the other defaults.list
files should be searched for other mimetypes.

I had to refactor get_filename so that it can return all the filenames, so
I changed it to append_filenames that appends all the filenames to a list
and provided a wrapper function called get_filename.
2010-12-02 23:55:45 +08:00
Grissiom
bdfc62184d fish_indent: indent "case" with the same level as "swith" 2010-12-02 23:42:48 +08:00
Grissiom
74f06d550a fish_indent: don't indent commands after a pipe
commands after a pipe tend to be at the same line of previous command.
So don't indent them.
2010-12-02 23:42:24 +08:00
James Bowlin
46986ad4c2 Use eix instead of emerge when possible
On Gentoo the eix program is MUCH faster than emerge for listing package
names.  I've left the emerge code in as a 2nd choice because not every
Gentoo system has eix installed (although they should).  Also,  the
emerge code didn't seem to produce any output on my system.

Signed-off-by: Grissiom <chaos.proton@gmail.com>
2010-12-02 01:33:56 +08:00
Dylan Smith
6a5d6471c5 mimedb: Search for exact mime type match in search_ini. 2010-12-02 01:19:56 +08:00
Dylan Smith
cf0850edfd mimedb: Add seperator between directory and filename in file_exists.
get_filename tried to work around this with hardcoded strings that end with
a '/', but would fail to work properly for environment variables
XDG_DATA_HOME or XDG_DATA_DIRS that don't do the same.
2010-12-02 01:16:29 +08:00
Dylan Smith
fd4ac87382 funcsave: Fixed error and help handling.
Renamed references to the previous command name of save_function to
funcsave, and returned an error after printing the help text when no
arguments are specified.
2010-12-02 01:13:51 +08:00
Dylan Smith
164144f126 default_key_bindings: Added mappings for ctrl-arrow keys.
On debian and ubuntu these control sequences are output while using
gnome-terminal and xterm.
2010-12-02 01:13:04 +08:00
Dylan Smith
f2ad4a2e8e Makefile: test for xsel directory before trying to clean it.
This avoids the users seeing ignored errors for make -C  clean.
2010-12-02 01:12:34 +08:00
Grissiom
df23913bb8 fish_indent: only output fd number when have to
The original patch is own by Dylan. I just did some cleaning and
reformating.
2010-12-01 13:05:10 +08:00
Dylan Smith
4ccf26fbcc builtin: count should not accept options, not even help
It is documented this way, but the common builtin_run function was
checking for -h or --help before even calling the builtin_count. Without
this functions like funced can't use count to check the number of
arguments before checking for -h or --help.

Signed-off-by: Grissiom <chaos.proton@gmail.com>
2010-11-26 19:00:18 +08:00
Dylan Smith
081e277fe4 builtin: read's --shell long option should require an argument
The short option -s doesn't need it and it won't be used.

Signed-off-by: Grissiom <chaos.proton@gmail.com>
2010-11-25 19:09:31 +08:00
Christopher Nilsson
dcecab384a Merge commit 'refs/merge-requests/6' of git://gitorious.org/fish-shell/fish-shell into merge_req_6 2010-11-24 22:34:29 +11:00
James Vega
4f9b07e979 Allow fish_greeting to be NULL or an array
Treat fish_greeting as a whole when show up the greeting messages. And
the user may want to set fish_greeting to an null value or an array.
This requires that the variable be quoted when used as an argument for
switch in __fish_config_interactive.

Signed-off-by: James Vega <jamessan@debian.org>
[modified the commit message]
Signed-off-by: Grissiom <chaos.proton@gmail.com>
2010-11-24 00:49:15 +08:00
Grissiom
9b97c55546 add test case for 364d3dbbf8 2010-11-24 00:35:56 +08:00
Dylan Smith
364d3dbbf8 exec: Don't format status returned directly from builtin function
The builtin function returns the raw status, which is not the same as
the integer return by waitpid. Therefore, the WIF macros shouldn't be
used for checking or obtaining the status.

This bug can be seen by executing (eval false). The builtin eval
function returns 1, but proc_format_status misinterprets it as a signal
by checking WIFSIGNALED, so adds 128 to the status to return 129.

Signed-off-by: Grissiom <chaos.proton@gmail.com>
2010-11-24 00:27:16 +08:00
James Vega
9f3a4d1640 Fix some spelling mistakes
Fix spelling mistakes in various bits of the documentation.

Signed-off-by: James Vega <jamessan@debian.org>
Signed-off-by: Grissiom <chaos.proton@gmail.com>
2010-11-23 23:50:49 +08:00
Dylan Smith
5fca92994f help.fish: Fix the sed expression to find anchors with id or name
Previously the expression only searched for anchors with a name
attribute, but doxygen 1.7.1 is producing anchors with the id attribute
instead. The sed expression allows both cases for compatibility.

I also used single quotes for the sed expression to avoid escaping
double quotes.

Signed-off-by: Grissiom <chaos.proton@gmail.com>
2010-11-23 23:37:09 +08:00
Grissiom
fefd17fe5e add test case for 6b243fbc 2010-11-23 23:05:21 +08:00
Dylan Smith
6b243fbcd3 eval: (eval false) should return an error status
This also caused (isatty < /dev/null) to return 0 since it uses eval,
and (ls | cat) to output using the classify indicator style since it
uses isatty. This is how I found the bug.

Reviewed-by: Grissiom <chaos.proton@gmail.com>
2010-11-22 19:36:42 +08:00
Dylan Smith
82f8c3834e Makefile: Provide PACKAGE_TARNAME for autoconf default docdir
docdir was previously being set to "${prefix}/share/doc/${PACKAGE_NAME}"
when it wasn't explicitely set on configuration using --docdir. Without
this appearing in the Makefile, some files silently get silently
installed directly into ${prefix}/share/doc instead within a fish
subdirectory.

I also added datarootdir to fix an autoconf warning,  since autoconf
normally would use it for the directory paths (e.g. docdir =
${datarootdir}/doc/${PACKAGE_TARNAME}). The autoconf generated configure
script has a hack to fix this, but states: "FIXME: This hack should be
removed a few years after 2.60."
2010-11-22 19:05:06 +08:00
Grissiom
e0ba91db31 Revert "use is_interactive instead of isatty to test whether we are in interactive mode"
This reverts commit ceba377ab8.
2010-11-22 08:43:21 +08:00
Grissiom
fa148bf59f break long lines 2010-11-22 08:42:57 +08:00
Christopher Nilsson
1b0ce33669 Merged changes from codemonkey and grissiom branches
Conflicts:
	kill.c
	seq.in
2010-11-12 02:07:14 +11:00
David Frascone
0cf2a1eb33 Fixed negative indices in the seq command 2010-11-05 09:34:42 -06:00
David Frascone
8a46a8ecb2 This change allows for customizing of the clipboard buffer, by supplying
a command to accept the "copy".  So, you add your clipboard buffer command
to an environment variable, and custom commands will be used for the copy
program.  Very useful when your OS is not naitively supported by fish.
2010-11-05 09:32:05 -06:00
David Frascone
4f0221bc4f Modify getopt string to force posix compliance. I forgot why I
needed this -- but -- some options were not working right.
2010-11-05 09:29:10 -06:00
David Frascone
ce08bb2ad2 The grep on the commands would sometimes output errors, causing noise and
breaking scripts.
2010-11-05 09:26:26 -06:00
David Frascone
93f797326e Optimized the result of the xsel check, so that it is cached.
It is called very often, and causes a significant performace hit.  The
availability of xsel is not likely to change during the invocation of
the shell.
2010-11-05 09:22:28 -06:00
Grissiom
ceba377ab8 use is_interactive instead of isatty to test whether we are in interactive mode 2010-10-13 04:30:23 +08:00
Grissiom
b9b6e867df check allocated memory when setting SHLVL 2010-10-08 09:38:06 +08:00
Grissiom
f47caefdb9 fix a memory allocation bug in commit 1e27024d75 2010-10-08 09:01:25 +08:00
James Buren
41ae7bccc2 silences some warnings outputted by gcc with -Wall and -Wextra 2010-10-08 08:43:57 +08:00
Grissiom
1e27024d75 accumulate SHLVL env variable at startup 2010-10-08 08:35:22 +08:00
Grissiom
6654fff377 fix null reference when erase TERM env
Way to reproduce:

> set -e TERM
fish: function contains_internal called with null value for argument a.
fish: This is a bug. If you can reproduce it,  please send a bug report
to fish-users@lists.sf.net.
fish: Backtrace:
/home/grissiom/sysroot/bin/fish(show_stackframe+0x1a) [0x43519a]
/home/grissiom/sysroot/bin/fish(contains_internal+0xce) [0x4373ee]
/home/grissiom/sysroot/bin/fish(reader_write_title+0x59) [0x424179]
/home/grissiom/sysroot/bin/fish() [0x4242d5]
/home/grissiom/sysroot/bin/fish(reader_readline+0x54) [0x425974]
/home/grissiom/sysroot/bin/fish(reader_read+0xba) [0x42742a]
/home/grissiom/sysroot/bin/fish(main+0x4be) [0x43b19e]
/lib64/libc.so.6(__libc_start_main+0xfd) [0x7fcbe0dcbb6d]
/home/grissiom/sysroot/bin/fish() [0x408c29]
2010-10-06 20:58:13 +08:00
Grissiom
89d999df72 some optimization on filling prompt_buff 2010-10-06 20:37:30 +08:00
Grissiom
a941d82be3 don't expand variables in no_exec mode
We couldn't know variables values unless execute commands, so disable
variable expansion in no_exec mode.
2010-10-06 11:37:59 +08:00
Grissiom
694cdf5ae1 update .gitignore 2010-10-05 21:14:43 +08:00
Grissiom
2bfe4afea2 add prof target 2010-10-05 02:23:18 +08:00
Grissiom
d559c3fe2e fix bug in build debug targe 2010-10-05 02:22:33 +08:00
Grissiom
27df727ca1 don't parse the options that should be passed to fish scripts
This commit makes fish_parse_opt stop at first non-option argument,
which expected as fish script name and pass the remaining argument to
that script. I also updated the test cases.
2010-10-03 11:46:26 +08:00
Grissiom
8910226d2f only count the last line of promt when caculate prompt width 2010-09-24 19:01:13 +08:00
Grissiom
04f58b1a31 ignore tmp staff in tests/ 2010-09-24 11:34:35 +08:00
Grissiom
1b9dd0c75f Merge remote branch 'origin/otherchirps-dev' 2010-09-19 14:12:30 +08:00
Grissiom
a7af415b6a call original grep in sgrep
functions/grep.fish will set the GREP_OPTIONS, which will ruin sgrep's
effort.
2010-09-19 13:56:30 +08:00
Grissiom
f8a5a59513 Revert "match the whole command for git completion"
This reverts commit d957d23d8f.
Use __fish_git_using_command to test commands and __fish_contains_opt to
test arguments.
2010-09-19 11:04:24 +08:00
Grissiom
ac3dfb3f96 don't complete file names for git checkout 2010-09-19 00:19:44 +08:00
Grissiom
d957d23d8f match the whole command for git completion 2010-09-19 00:17:53 +08:00
Grissiom
d049947801 event_fire( 0 ); => event_fire( NULL ); 2010-09-18 21:30:02 +08:00
Grissiom
21a10c3c74 use $() in Makefile var expansion 2010-09-18 21:29:05 +08:00
Grissiom
04951f8b34 reader_read( 0... => reader_read( STDIN_FILENO 2010-09-18 20:26:54 +08:00
Grissiom
c08bae6aeb configure xsel in configure phase
... and with the same arguments of fish
2010-09-18 14:31:18 +08:00
Grissiom
3aa107c4ae add XSEL_BIN var in configure.ac 2010-09-18 13:49:03 +08:00
Grissiom
e196091714 make clean should clean xsel and make distclean should delete it 2010-09-18 13:41:27 +08:00
Grissiom
d35d65cc40 use variables as xsel target 2010-09-18 13:27:34 +08:00
Grissiom
7f7b30959b don't make xsel in subshell 2010-09-18 13:14:59 +08:00
Grissiom
70322077d2 remove trialing spaces #2 2010-09-18 10:18:26 +08:00
Grissiom
f529b2e057 upgrade xsel to 1.2.0
xsel 1.0 begin to support UFT-8.
2010-09-18 10:14:14 +08:00
Grissiom
c6372a1b3f remove trailing spaces
This is done by `sed -i -e 's/[ \t]*$//' *.[c,h]`, which should not
introduce any functionality change.
2010-09-18 09:51:16 +08:00
Grissiom
41b8db063c add git submodule completion
Merged from http://github.com/weavejester/fish-git
2010-09-17 16:38:26 +08:00
Grissiom
1b16758d7e Fix cd prompt fail on the case that CDPATH have variables 2010-09-17 16:01:44 +08:00
Grissiom
51b5adc306 ignore ~ backup files 2010-09-16 13:32:18 +08:00
Grissiom
56f8993b8c ignore po/*.gmo 2010-09-16 13:31:49 +08:00
Ben Hoskings
8c4d1ca587 Added .gitignore. 2010-09-16 13:30:59 +08:00
Christopher Nilsson
ec8b3593f3 added '-c' option to the functions.txt docs. 2010-09-12 20:29:34 +10:00
Christopher Nilsson
5c9b42e260 'functions --copy': added sanity check on new function name.
Now matches function create behaviour, running the new function name through
wcsfuncname() and parser_keywords_is_reserved(), before allowing the copy.
2010-09-12 13:16:11 +10:00
Christopher Nilsson
7914c92824 replaced the functions '--rename' option with '--copy'.
Copying the function implementation was the main point. Actually removing the original isn't necessary, as that
functionality already exists (functions -e).
2010-09-09 23:48:18 +10:00
Christopher Nilsson
208be0f4d4 Adding '--rename' option to 'functions' builtin.
Aim is to allow an existing function to be renamed, allowing some basic function chaining.

Example:

> function foo
     echo Hello
  end
> foo
Hello
> functions --rename foo bar
> foo
fish: Unknown command 'foo'
> bar
Hello
> functions --rename fish_prompt old_prompt
> function fish_prompt
      printf "{Boo!}%s" (old_prompt)
  end
{Boo!}>

Note in the last case, the new fish_prompt is calling its old definition.
2010-09-08 03:31:05 +10:00
Ben Hoskings
7cfac5bb59 Fix an fprintf() type warning in set_color.c by using "%s". 2010-04-09 16:05:19 -07:00
Ben Hoskings
1bd09bfd40 Fix casting warnings in screen.c / s_update() by casting al_get() twice to convert type and then size, instead of both at once. 2010-04-09 16:05:18 -07:00
Ben Hoskings
517751f2a3 Declare write_loop() in print_help.c to fix warning (it's declared in common.h, but including that file here breaks things badly). 2010-04-09 16:05:18 -07:00
Ben Hoskings
006952c571 Fixed incompatible pointer warning in env_universal_common.c / iconv() call. 2010-04-09 16:05:18 -07:00
Ben Hoskings
7a8b7201a1 Write formatted duration to ENV_DURATION after commands that run for > 1s wall time. 2010-04-09 15:56:32 -07:00
Ben Hoskings
1157e4d7b2 Allow newlines in fish_prompt, by joining prompt_list with newlines instead of nothing in exec_prompt(). 2010-04-09 15:56:15 -07:00
Ben Hoskings
6b8e7b16f6 Reduced timeout in select_try() from 5s to 10ms. 2010-04-09 15:56:09 -07:00
axel
1eb089d722 Bump version number
darcs-hash:20090308144106-ac50b-e64db4a3009f99b3c1d206bba1781775faef671c.gz
2009-03-09 00:41:06 +10:00
axel
e50d0c18b0 Update todo list
darcs-hash:20090308142007-ac50b-22e9cc31212ff9647f75426327cdf5aff2d30f79.gz
2009-03-09 00:20:07 +10:00
axel
810d5f9548 Fix interactive job in background busy wait bug, reported by Randall D. Wald
darcs-hash:20090301021441-ac50b-a9488a9e55f545c3b8bd52aa0fb00b2b967974a8.gz
2009-03-01 12:14:41 +10:00
James Vega
e0c317dfd4 Prevent potential infinite loop
Ignore-this: 24edfe9248e1b667fcf4d8e151dd50f2

darcs-hash:20090224183601-35ec8-5e86d44c77af33376bd80485689d60c761ff17c6.gz
2009-02-25 04:36:01 +10:00
axel
d5320fb9f9 Update copyright info, minor layout changes to section about licenses in fish
darcs-hash:20090222224540-ac50b-69c4f8dd027e4672b8d25f8240c1d5f625135ad1.gz
2009-02-23 08:45:40 +10:00
axel
14c84ffbcb Check return value of a few write calls and retry on EINTR, and fix a few other warnings, mostly by printing error messages before giving up.
darcs-hash:20090222202852-ac50b-b0e79142af5b7a99e55271d4001fa252d9684a1d.gz
2009-02-23 06:28:52 +10:00
axel
f71c6f3f0e Misc documentation updates
darcs-hash:20090222191714-ac50b-fdd090aafd60f71989ef5c63aac9f876dcad93eb.gz
2009-02-23 05:17:14 +10:00
axel
6dbb9e070d Hopefully make iconv detection work on OS X with non-gnu iconv implementation
darcs-hash:20090222191649-ac50b-4f7010fdbf662b71cb7c4c99d2ae6e00c7cccb83.gz
2009-02-23 05:16:49 +10:00
axel
47ae2a05ce Don't make complete builtin complain when used in non-interactive mode, as we can always launch a debug prompt. Who are we to question why?
darcs-hash:20090222162253-ac50b-bb3c9dc1d1fa33548a2ed7b3c7c4d21d527eba47.gz
2009-02-23 02:22:53 +10:00
axel
810262118a Fix read in noninteractive mode problems reported by James Reeves
darcs-hash:20090222162206-ac50b-c293945986f75103120606a64133b59fe82c02a6.gz
2009-02-23 02:22:06 +10:00
axel
f5be301a2f Handle exit status of processes terminated by signals
darcs-hash:20090221164656-ac50b-7bcbf6cb0bb8384560fbf9bf1059480cb4089def.gz
2009-02-22 02:46:56 +10:00
axel
b1357d11b2 Pressing Control-C (or otherwise changeing the command line content through the commandline builtin) should clear the search buffer.
darcs-hash:20090221154420-ac50b-52641fb6dd6e76aebc6244211e07c0861fb3eff0.gz
2009-02-22 01:44:20 +10:00
axel
5fc42fcaff prompt_pwd broken, this fix by James Reeves
darcs-hash:20090221104759-ac50b-35f7a896d3e62cd002605d47c090c7bec992317b.gz
2009-02-21 20:47:59 +10:00
axel
c1cf6a4071 Oops, I broke recursive wildcard completion
darcs-hash:20090221104330-ac50b-ab9d487d3fc77fab32d9c49045d23b3e9124e618.gz
2009-02-21 20:43:30 +10:00
axel
972f3e121e Document rename of save_function to func_save. Pointed out by Ovchinnikov George
darcs-hash:20090218202037-ac50b-0351e8564d3274cd4fb364c07b4a3260f8a45f20.gz
2009-02-19 06:20:37 +10:00
axel
0dd8ae4843 Added faw entry on history editing, written by Beni Cherniavsky
darcs-hash:20090216211940-ac50b-4175fb2ae8ec2f5a67ac3c6a33a48bc5ac35eea2.gz
2009-02-17 07:19:40 +10:00
axel
8a93b6f26d Make xdg-version of open handle multiple files.
darcs-hash:20090216211103-ac50b-f8268e8d50a84457bb49ac3d1e982cba09dbfec6.gz
2009-02-17 07:11:03 +10:00
axel
07717a3570 Add possibility to define greeting function, suggested by Chris Miller
darcs-hash:20090216210450-ac50b-9b4f7c5bf45afaf21d51e46ff8c2b11d171fcbf2.gz
2009-02-17 07:04:50 +10:00
Nick Pilon
79784d3e18 This patch fixes a problem where prompt_pwd was printing the full path twice under OS X and probably BSDs. (Which, needless to say, made for very long prompts) The problem was that (Free?)BSD sed and GNU sed handle ? differently. For BSD sed, ? is not special unless the -E flag is specified. The {0,1} syntax should work the same way in both.
darcs-hash:20080122180340-5b666-21f1cdb835cbfa458a0f3d7344370837db962388.gz
2008-01-23 04:03:40 +10:00
terceiro
c08c313c0a adds completion for Debian's invoke-rc.d command
Ignore-this: f9ff385e3c239cedfbc9850b06822bba

darcs-hash:20090204191757-69c1e-a55c2a720fd784c7be2534feacecd5e2ebdbeecd.gz
2009-02-05 05:17:57 +10:00
terceiro
dfd70057b3 function to put current git branch on the fish prompt
Ignore-this: 841402742571f399e012514315b8e4f0

darcs-hash:20090204190358-69c1e-2ebcf761a4e55bc049ff1d5bba272d722b2d4501.gz
2009-02-05 05:03:58 +10:00
terceiro
07dec5c3ed better git completion
Ignore-this: af7fede5c1ee1d92c89d2887cbe54c0b

darcs-hash:20090204185826-69c1e-f72e06ad575efee258b392afd17255166ac4a260.gz
2009-02-05 04:58:26 +10:00
axel
1ed5decf2c Fix warnings in FATAL_EXIT macro
darcs-hash:20090204224310-ac50b-111db6c8f5b74dad0a309441063d3d7e9bf8f55d.gz
2009-02-05 08:43:10 +10:00
Isaac Dupree
9b95dda6bf fix help for open
darcs-hash:20080605192305-6c1c4-ccf59a87bf7197b5d07a33d7aaeb31638aa0aa52.gz
2008-06-06 05:23:05 +10:00
axel
41015691db Make all fish that use universal variables binaries include iconv
darcs-hash:20090203002620-ac50b-6be533cd1bf7dd043d96547b2c2f3ab4cda30e10.gz
2009-02-03 10:26:20 +10:00
axel
7e1ac2d806 Actually escape the double-star recursive wildcard char when requested. This will make sure the syntax highlighting doesn't try to perform a recursive wildcard expansion when cheching command name existance, which killed performance
darcs-hash:20090202234751-ac50b-55dfd8b52f842826b02a69d6ab51c222108c30e3.gz
2009-02-03 09:47:51 +10:00
axel
35258bf1fb Make proper autoconf test for availability of posix nan function instead of fudging with the NAN macro.
darcs-hash:20090202232049-ac50b-0176955677ff39fdd05eeefa20dca883863c34e6.gz
2009-02-03 09:20:49 +10:00
axel
72025a6a38 Make fish avoid iterating through user list when completing file part of directory starting with tilde. Also add a timeout to the directory iteration, to protect against humongously large user databases.
darcs-hash:20090202224645-ac50b-353047a73e4d6f494f470fe2ea6c4a34b486d302.gz
2009-02-03 08:46:45 +10:00
axel
05341b055b ish's current hostname completion uses ~/.ssh/known_hosts as one of its sources of information, but ~/.ssh/config may also be useful. Gather all of the 'Host' declarations from ~/.ssh/config and filter out the ones with wildcards. Signed-off-by: James Vega <jamessan@debian.org>
darcs-hash:20090202210242-ac50b-cf50070ee33ab6113e32a4d997d464ac4b1faf24.gz
2009-02-03 07:02:42 +10:00
axel
9d7224d756 Add support for completing aliases in ssh. Written by David Bronke.
darcs-hash:20090201231805-ac50b-196d4c81981efe681677fe8ca7f1cc833a4734da.gz
2009-02-02 09:18:05 +10:00
axel
33ec8b45a0 Add effectv completions, written by Stefano Sabatini.
darcs-hash:20090201225558-ac50b-5704829043880d0264e3e3908d324a39857ada16.gz
2009-02-02 08:55:58 +10:00
axel
1dc49a4062 Fix color ls detection for BSD and OS X systems. Patch by Sven Axelsson.
darcs-hash:20090201222410-ac50b-e1e02244ae950c602d3b7e67fe567920c619024b.gz
2009-02-02 08:24:10 +10:00
axel
1123467991 Fix cd function to handle empty variables correctly. Patch by Sven Axelsson.
darcs-hash:20090201222058-ac50b-31a7ee2db9f68729c21ba153e1439cbeabff84ce.gz
2009-02-02 08:20:58 +10:00
axel
4f54da3795 Fix user completion so it can handle comments in the passwd file. Patch by Sven Axelsson.
darcs-hash:20090201221921-ac50b-ef0883afe4dc68b43c1c705d49b6b5505dbf1e73.gz
2009-02-02 08:19:21 +10:00
axel
c8de3d24c8 Add netcat completions, written by James Stanley
darcs-hash:20090201160411-ac50b-43c34e2a73477cde40f15887a810a7b365ec81c4.gz
2009-02-02 02:04:11 +10:00
axel
31439ffb52 Better warning message when trying to exit with jobs running. PAtch and suggestion from Josef Spillner.
darcs-hash:20090201151601-ac50b-64bf24877419a9087f37eda2486232dfdabea9d2.gz
2009-02-02 01:16:01 +10:00
axel
9111b85437 Fixed bug with configure.ac in autotools shipped with F10. This fix comes from James Reeves.
darcs-hash:20090201140928-ac50b-952a8ba0596e3cf4f4a4a94f226fd04ec607075f.gz
2009-02-02 00:09:28 +10:00
axel
c6427c5a47 Add mimedb infinite loop bug fix from James Reeves
darcs-hash:20090201133734-ac50b-96fb4735af616094ea57ba02266188f8a7038a0c.gz
2009-02-01 23:37:34 +10:00
axel
36c3bd4e8d Switch from ARG_MAX to getting value from sysconf, glibc no longer defines the latter. This was reported from Peter Alfredsen Matthew Wesley, among other people.
darcs-hash:20090201132329-ac50b-5b9d54731c2ea2da3868fd492e68628b7684bb76.gz
2009-02-01 23:23:29 +10:00
axel
dad549afd1 Fix slightly wrong LD_FLAG in Makefile
darcs-hash:20090201125628-ac50b-3e68d7165a6c19558c7c8d7189cb75d71b4a9875.gz
2009-02-01 22:56:28 +10:00
Ori Avtalion
e73c2be216 Add missing commas, letters and \c in the documentation
darcs-hash:20080210210053-57fc3-f7e03b3fca9dff8bdc02256dfb78478b68945015.gz
2008-02-11 07:00:53 +10:00
axel
b0d324f1a7 Fix dumb error causing fish not to compile...
darcs-hash:20080204230945-ac50b-a95529cf19c473f62b6104ae138cf8b8abcbd2ec.gz
2008-02-05 09:09:45 +10:00
axel
d7396ac59f Fix bug causing flood of error messages in terminal when trying to highlight an invalid command, reported by Denilson F. de Sa.
darcs-hash:20080204230905-ac50b-0829b69835347e5875656ae735181b724f10de2a.gz
2008-02-05 09:09:05 +10:00
liljencrantz
3f439e9cd3 Add quilt completions, written by Stefano Sabatini.
darcs-hash:20080123000021-75c98-b27ae979720c55ec2219f451c50e87e79fa38cd6.gz
2008-01-23 10:00:21 +10:00
liljencrantz
0b722864c0 Make string handling a bit more solid be making sure sb_printf returns a null terminated string even on failiure.
darcs-hash:20080120022045-75c98-a47aff63ce7278148ccf027d6ee3ff93b35ee350.gz
2008-01-20 12:20:45 +10:00
liljencrantz
75e26f0f94 Add completions for various user and group adding commands. Skip addgroup, since manual page was actually for adduser, most switches weren't applicable and I was too lazy to guess which ones.
darcs-hash:20080120020816-75c98-f937df6cb6789868a1385bfc3eb48f5ddefb3c43.gz
2008-01-20 12:08:16 +10:00
liljencrantz
8cacb33347 Add completions for m4
darcs-hash:20080119150149-75c98-d8e5060ef78c6103d51e453ee4d5265f0981c4af.gz
2008-01-20 01:01:49 +10:00
liljencrantz
bf7d62fd91 Add completions for badblocks
darcs-hash:20080119145849-75c98-657a11bc69fbf625b01f84f1f6638e0d4b767228.gz
2008-01-20 00:58:49 +10:00
liljencrantz
4ac31e637d Add completions for Battle of Wesnoth
darcs-hash:20080119145414-75c98-6d8f856062ea44cf5de56bb014765a65ac26706b.gz
2008-01-20 00:54:14 +10:00
liljencrantz
0ad64ad2e4 Improve documentaion for bind builtin, clarify how to specify key sequences.
darcs-hash:20080119003820-75c98-b1f9360ddab9206a1cdf77b94ce28e9978badb53.gz
2008-01-19 10:38:20 +10:00
liljencrantz
523096e5d8 Add simple git completions by Diggory Hardy
darcs-hash:20080118160327-75c98-33e4e011de409944143aecf4f7e7aa8995687c75.gz
2008-01-19 02:03:27 +10:00
liljencrantz
0de629e009 Fix spelling in docs and add a help page for the funced builtin. These changes where suggested by Emanuele Rusconi.
darcs-hash:20080118155413-75c98-eadff877b3af3c3271b098903f80a45082111424.gz
2008-01-19 01:54:13 +10:00
liljencrantz
1f6fa1208e Search for command-not-found in PATH on startup, since older implementations place it there
darcs-hash:20080115122953-75c98-05ef8cb650a942c59dfa35aa63b25ccd49614dde.gz
2008-01-15 22:29:53 +10:00
liljencrantz
b86856b454 In prompt_pwd, if a directory name starts with a dot, include first two characters. This patch was written by Denilson F. de Sá
darcs-hash:20080116223621-75c98-46f96c9f25d5e32cd10148d35713622e6eac50d7.gz
2008-01-17 08:36:21 +10:00
liljencrantz
6598320534 Remove useless stray argument in function call
darcs-hash:20080116222628-75c98-a307fbeacdd815edcedea05930dc8b4bb064acb3.gz
2008-01-17 08:26:28 +10:00
liljencrantz
0a66dc4a31 Correct completions for the function builtin
darcs-hash:20080116222602-75c98-c1a48b4a04fe71b25c5e004a282341148a95ab6d.gz
2008-01-17 08:26:02 +10:00
liljencrantz
88a2b622df Add more documentation on events
darcs-hash:20080116222531-75c98-ef30dabc492d7883dbb620c40ef95152469057a3.gz
2008-01-17 08:25:31 +10:00
liljencrantz
e10f75483f Fix minor bug, PWD was incorrectly set on startup
darcs-hash:20080116220738-75c98-2b7c886629857540efee8f1cab9da0aa9ed8f76d.gz
2008-01-17 08:07:38 +10:00
liljencrantz
1a66fc4c5d Drop vim feature of only completing text and gzip files
darcs-hash:20080116180249-75c98-2fdff83afcb286c7cc06d3ed66089c9cc02eca20.gz
2008-01-17 04:02:49 +10:00
liljencrantz
905b792de7 Improve code comment
darcs-hash:20080116010601-75c98-fc7e940543424479bf1016cec26af619f177f5fd.gz
2008-01-16 11:06:01 +10:00
liljencrantz
804f5ab334 Add an extra input validation check
darcs-hash:20080116010548-75c98-e6f198bb1eb5a456ce830c42f061428a9c6f755d.gz
2008-01-16 11:05:48 +10:00
liljencrantz
f974c7c416 Improve error messages on failed execve calls a bit more
darcs-hash:20080116010454-75c98-883050bf00f10bdb205724d7d273f10e6f0a1065.gz
2008-01-16 11:04:54 +10:00
liljencrantz
f3b6b74568 Oops. Made a minor but important typo in previous cleanup patch. :-(
darcs-hash:20080115004050-75c98-3f7f733cca054d8685ec5df68d6467057ea5be53.gz
2008-01-15 10:40:50 +10:00
liljencrantz
ab94a397c3 Drop minor typo, add a few code comments
darcs-hash:20080114225828-75c98-f67f17d7f3148b0bcc74ea53536d52da80667e55.gz
2008-01-15 08:58:28 +10:00
liljencrantz
537ab32dd9 Add support for the Ubuntu 'command-no-found' handler, which suggests a package to install in order to get a command.
darcs-hash:20080114223124-75c98-ab1658d54086394cf13f3a6210543c0b790362c4.gz
2008-01-15 08:31:24 +10:00
liljencrantz
a2660cfb76 Handle case insensitive completions of variables better
darcs-hash:20080114010032-75c98-6e570c2b095baeb2ed2ee4d09e32f4e7d6ae47de.gz
2008-01-14 11:00:32 +10:00
liljencrantz
3743a5758b The max size of the string buffer was too small. Push it up a bit.
darcs-hash:20080114005745-75c98-1bcad5c5e81d4257eb7e96e860f8c667f9ba3267.gz
2008-01-14 10:57:45 +10:00
James Vega
e510d10c77 Fixed various spelling errors.
darcs-hash:20080113200151-35ec8-c587f020aec07a5e613068677bd3dd4f5c6189ac.gz
2008-01-14 06:01:51 +10:00
liljencrantz
f5540ff958 Add canse insensitive tilde completion
darcs-hash:20080113193221-75c98-169804fe128001f73eaee6fab28bfb99dca7c93e.gz
2008-01-14 05:32:21 +10:00
liljencrantz
c2b28063e1 Improve Doxygen documentation generation a bit
darcs-hash:20080113164924-75c98-d9762465de42750728ac6cb9364f4739a29ae376.gz
2008-01-14 02:49:24 +10:00
liljencrantz
8d2564291d Make sure fish_indent handles io erros
darcs-hash:20080113164905-75c98-b090ce79fb50a260874951525218cac65a097a6d.gz
2008-01-14 02:49:05 +10:00
liljencrantz
87db9517e9 Add lots of new code comments.
darcs-hash:20080113164747-75c98-9d0cefd27be7aef7ba60772616d9da7e6bb52912.gz
2008-01-14 02:47:47 +10:00
281 changed files with 9020 additions and 7061 deletions

33
.gitignore vendored Normal file
View File

@@ -0,0 +1,33 @@
*.o
*~
Doxyfile.help
Makefile
autom4te.cache/
command_list.txt
config.h
config.h.in
config.log
config.status
configure
doc.h
doc_src/commands.hdr
doc_src/index.hdr
etc/config.fish
po/*.gmo
fish
fish.spec
fish_indent
fish_pager
fish_tests
fishd
mimedb
seq
set_color
share/config.fish
share/man/
toc.txt
user_doc/
xsel-1.2.0/
tests/*tmp.*
tests/foo.txt

3
CHANGELOG Normal file
View File

@@ -0,0 +1,3 @@
24-01-2012 Jan Kanis
* Added a changelog file
* removed unescaping if the 'commandline' builtin is called without the -o (tokenise) flag

939
Doxyfile

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -10,8 +10,8 @@ ABBREVIATE_BRIEF = YES
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = YES
STRIP_FROM_PATH =
STRIP_FROM_INC_PATH =
STRIP_FROM_PATH =
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = YES
MULTILINE_CPP_IS_BRIEF = NO
@@ -19,7 +19,7 @@ DETAILS_AT_TOP = NO
INHERIT_DOCS = YES
DISTRIBUTE_GROUP_DOC = NO
TAB_SIZE = 8
ALIASES =
ALIASES =
OPTIMIZE_OUTPUT_FOR_C = YES
OPTIMIZE_OUTPUT_JAVA = NO
SUBGROUPING = YES
@@ -44,7 +44,7 @@ GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
ENABLED_SECTIONS =
ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
SHOW_DIRECTORIES = YES
@@ -53,19 +53,19 @@ WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
INPUT =
WARN_LOGFILE =
INPUT =
FILE_PATTERNS = doc.h
RECURSIVE = NO
EXCLUDE =
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS =
EXCLUDE_PATTERNS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS =
EXAMPLE_RECURSIVE = NO
IMAGE_PATH =
INPUT_FILTER =
FILTER_PATTERNS =
IMAGE_PATH =
INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
SOURCE_BROWSER = NO
INLINE_SOURCES = NO
@@ -75,17 +75,17 @@ REFERENCES_RELATION = YES
VERBATIM_HEADERS = YES
ALPHABETICAL_INDEX = NO
COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
IGNORE_PREFIX =
GENERATE_HTML = YES
HTML_OUTPUT = html
HTML_FILE_EXTENSION = .html
HTML_HEADER = user_doc.head.html
HTML_FOOTER =
HTML_STYLESHEET =
HTML_FOOTER =
HTML_STYLESHEET =
HTML_ALIGN_MEMBERS = YES
GENERATE_HTMLHELP = NO
CHM_FILE =
HHC_LOCATION =
CHM_FILE =
HHC_LOCATION =
GENERATE_CHI = NO
BINARY_TOC = NO
TOC_EXPAND = NO
@@ -99,8 +99,8 @@ LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
COMPACT_LATEX = NO
PAPER_TYPE = a4wide
EXTRA_PACKAGES =
LATEX_HEADER =
EXTRA_PACKAGES =
LATEX_HEADER =
PDF_HYPERLINKS = YES
USE_PDFLATEX = YES
LATEX_BATCHMODE = NO
@@ -109,33 +109,33 @@ GENERATE_RTF = NO
RTF_OUTPUT = rtf
COMPACT_RTF = NO
RTF_HYPERLINKS = NO
RTF_STYLESHEET_FILE =
RTF_EXTENSIONS_FILE =
RTF_STYLESHEET_FILE =
RTF_EXTENSIONS_FILE =
GENERATE_MAN = NO
MAN_OUTPUT = man
MAN_EXTENSION = .3
MAN_LINKS = NO
GENERATE_XML = NO
XML_OUTPUT = xml
XML_SCHEMA =
XML_DTD =
XML_SCHEMA =
XML_DTD =
XML_PROGRAMLISTING = YES
GENERATE_AUTOGEN_DEF = NO
GENERATE_PERLMOD = NO
PERLMOD_LATEX = NO
PERLMOD_PRETTY = YES
PERLMOD_MAKEVAR_PREFIX =
PERLMOD_MAKEVAR_PREFIX =
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED =
EXPAND_AS_DEFINED =
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED =
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES
TAGFILES =
GENERATE_TAGFILE =
TAGFILES =
GENERATE_TAGFILE =
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
PERL_PATH = /usr/bin/perl
@@ -151,8 +151,8 @@ INCLUDED_BY_GRAPH = YES
CALL_GRAPH = YES
GRAPHICAL_HIERARCHY = YES
DOT_IMAGE_FORMAT = png
DOT_PATH =
DOTFILE_DIRS =
DOT_PATH =
DOTFILE_DIRS =
MAX_DOT_GRAPH_WIDTH = 750
MAX_DOT_GRAPH_HEIGHT = 1024
MAX_DOT_GRAPH_DEPTH = 0

View File

@@ -49,7 +49,7 @@ Then, use following commands to compile fish:
Finally, if you wish to use fish as your default shell, use the
following command:
% chsh -s /usr/local/bin/fish
% chsh -s /usr/local/bin/fish
chsh will prompt you for your password, and change your default shell.

View File

@@ -31,6 +31,8 @@
# hallucinations.
#
# Used by docdir
PACKAGE_TARNAME = @PACKAGE_TARNAME@
#
# Programs
@@ -46,6 +48,7 @@ INSTALL:=@INSTALL@
prefix = @prefix@
exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
datadir = @datadir@
bindir = @bindir@
mandir = @mandir@
@@ -53,16 +56,16 @@ sysconfdir = @sysconfdir@
docdir = @docdir@
localedir = @localedir@
prefix = @prefix@
optbindirs = @optbindirs@
optbindirs = @optbindirs@
#
# Various flags
#
MACROS = -DLOCALEDIR=\"$(localedir)\" -DPREFIX=L\"$(prefix)\" -DDATADIR=L\"$(datadir)\" -DSYSCONFDIR=L\"$(sysconfdir)\"
CFLAGS = @CFLAGS@ $(MACROS)
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LIBS@ @LDFLAGS@
MACROS = -DLOCALEDIR=\"$(localedir)\" -DPREFIX=L\"$(prefix)\" -DDATADIR=L\"$(datadir)\" -DSYSCONFDIR=L\"$(sysconfdir)\"
CFLAGS = @CFLAGS@ $(MACROS) $(EXTRA_CFLAGS)
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LIBS@ @LDFLAGS@
LDFLAGS_FISH = ${LDFLAGS} @LIBS_FISH@ @LDFLAGS_FISH@
LDFLAGS_FISH_INDENT = ${LDFLAGS} @LIBS_FISH_INDENT@
LDFLAGS_FISH_PAGER = ${LDFLAGS} @LIBS_FISH_PAGER@
@@ -158,7 +161,7 @@ HDR_FILES_SRC := doc_src/index.hdr.in doc_src/commands.hdr.in doc_src/design.hdr
HDR_FILES := $(subst .hdr.in,.hdr,$(HDR_FILES_SRC))
#
# Files containing documentation for external commands.
# Files containing documentation for external commands.
#
HELP_SRC := $(wildcard doc_src/*.txt)
@@ -208,7 +211,7 @@ MAIN_DIR_FILES := $(sort $(MAIN_DIR_FILES_UNSORTED))
# Files in ./etc/
#
ETC_DIR_FILES :=etc/config.fish.in
ETC_DIR_FILES :=etc/config.fish.in
#
@@ -245,7 +248,7 @@ FUNCTIONS_DIR_FILES := $(wildcard share/functions/*.fish)
#
SIMPLE_PROGRAMS := fish set_color mimedb fish_pager fishd fish_indent
PROGRAMS := $(SIMPLE_PROGRAMS) @XSEL@ @SEQ_FALLBACK@
PROGRAMS := $(SIMPLE_PROGRAMS) @XSEL_BIN@ @SEQ_FALLBACK@
#
@@ -264,12 +267,19 @@ TRANSLATIONS_SRC := $(wildcard po/*.po)
TRANSLATIONS := $(TRANSLATIONS_SRC:.po=.gmo)
#
# Extra util
#
XSEL := @XSEL@
XSEL_BIN := @XSEL_BIN@
#
# Make everything needed for installing fish
#
all: $(PROGRAMS) user_doc share/man etc/config.fish share/config.fish $(TRANSLATIONS)
@echo fish has now been built.
@echo fish has now been built.
@echo Use \'$(MAKE) install\' to install fish.
.PHONY: all
@@ -292,15 +302,18 @@ Makefile: Makefile.in configure
#
debug:
$(MAKE) fish CFLAGS="@CFLAGS@ $(MACROS) -O0 -Wno-unused -Werror -g"
$(MAKE) all EXTRA_CFLAGS="-O0 -Wno-unused -Werror -g"
.PHONY: debug
prof:
$(MAKE) all EXTRA_CFLAGS="-pg" LDFLAGS="-pg"
.PHONY: prof
#
# User documentation, describing the features of the fish shell.
#
# Depend on the sources (*.hdr.in) and manually make the
# Depend on the sources (*.hdr.in) and manually make the
# intermediate *.hdr and doc.h files if needed
user_doc: $(HDR_FILES_SRC) Doxyfile.user user_doc.head.html $(HELP_SRC)
@@ -313,19 +326,19 @@ user_doc: $(HDR_FILES_SRC) Doxyfile.user user_doc.head.html $(HELP_SRC)
# Source code documentation. Also includes user documentation.
#
doc: *.h *.c doc.h Doxyfile
doxygen;
doc: *.h *.c doc.h Doxyfile
doxygen;
#
# PDF version of the source code documentation.
#
doc/refman.pdf: doc
cd doc/latex;
make;
mv refman.pdf ..;
cd ../..;
doc/refman.pdf: doc
cd doc/latex;
make;
mv refman.pdf ..;
cd ../..;
rm -r doc/latex;
@@ -342,11 +355,8 @@ test: $(PROGRAMS) fish_tests
# Build the xsel program, which is maintained in its own tarball
#
xsel-0.9.6:
tar -xf xsel-0.9.6.tar
xsel-0.9.6/xsel: xsel-0.9.6
cd xsel-0.9.6; ./configure && make || echo "Failed to build xsel - either add the required dependencies or use './configure --without-xsel' to disable it."
$(XSEL_BIN):
$(MAKE) -C $(XSEL) || echo "Failed to build xsel - either add the required dependencies or use './configure --without-xsel' to disable it."
#
@@ -362,7 +372,7 @@ doc_src/commands.hdr:$(HELP_SRC) doc_src/commands.hdr.in
echo >>command_list.tmp; \
echo >>command_list.tmp; \
echo "Back to <a href='index.html#toc-commands'>index</a>". >>command_list.tmp; \
done
done
mv command_list.tmp command_list.txt
cat $@.in | awk '{if ($$0 ~ /@command_list@/){ system("cat command_list.txt");} else{ print $$0;}}' >$@
@@ -400,19 +410,19 @@ doc.h: $(HDR_FILES)
#
%.doxygen:%.txt
echo "/** \page " `basename $*` >$@;
cat $*.txt >>$@;
echo "/** \page " `basename $*` >$@;
cat $*.txt >>$@;
echo "*/" >>$@
%: %.in
%: %.in
sed <$@.in >$@ \
-e "s,@sysconfdir\@,$(sysconfdir),g" \
-e "s,@datadir\@,$(datadir),g" \
-e "s,@docdir\@,$(docdir),g" \
-e "s|@configure_input\@|$@, generated from $@.in by the Makefile. DO NOT MANUALLY EDIT THIS FILE!|g" \
-e "s,@prefix\@,$(prefix),g" \
-e "s,@optbindirs\@,$(optbindirs),g"
#-e "s,@\@,$(),"
-e "s,@optbindirs\@,$(optbindirs),g"
#-e "s,@\@,$(),"
#
@@ -477,8 +487,8 @@ common.o: $(COMMON_FILES)
# (__fish_print_help)
# ||
# \/
# formated text
# with escape
# formated text
# with escape
# sequences
#
#
@@ -500,7 +510,7 @@ share/man: $(HELP_SRC)
for i in $(HELP_SRC); do \
CMD_NAME=`basename $$i .txt`; \
sed -e "s/\(.\)\\.SH/\1/" -e "s/$$CMD_NAME *\\\\- *\"\(.*\)\"/\1/" <help_doc/man/man1/$$CMD_NAME.1 >share/man/$$CMD_NAME.1; \
done
done
rm doc_src/*.doxygen # Clean up intermediate files in doc_src/
rm -r help_doc # Clean up intermediate help_doc tree
@@ -565,7 +575,7 @@ install: all install-sh check-uninstall install-force
#
install-force: all install-translations
$(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
$(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
for i in $(PROGRAMS); do\
$(INSTALL) -m 755 $$i $(DESTDIR)$(bindir) ; \
done;
@@ -595,7 +605,7 @@ install-force: all install-translations
for i in $(MANUALS); do \
$(INSTALL) -m 644 $$i $(DESTDIR)$(mandir)/man1/; \
done;
@echo fish is now installed on your system.
@echo fish is now installed on your system.
@echo To run fish, type \'fish\' in your terminal.
@echo
@echo To use fish as your login shell:
@@ -652,7 +662,7 @@ uninstall-legacy: uninstall
-rmdir $(DESTDIR)$(sysconfdir)/fish.d/completions
-rmdir $(DESTDIR)$(sysconfdir)/fish.d
-rm $(DESTDIR)$(sysconfdir)/fish
@echo The previous fish installation has been removed.
@echo The previous fish installation has been removed.
.PHONY: uninstall-legacy
install-translations: $(TRANSLATIONS)
@@ -665,7 +675,7 @@ install-translations: $(TRANSLATIONS)
fi;
.PHONY: install-translations
uninstall-translations:
uninstall-translations:
if test $(HAVE_GETTEXT) = 1; then \
for i in $(TRANSLATIONS_SRC); do \
rm -f $(DESTDIR)$(datadir)/locale/*/LC_MESSAGES/fish.mo; \
@@ -682,7 +692,7 @@ uninstall-translations:
# Build the fish program.
#
fish: $(FISH_OBJS) fish.o
fish: $(FISH_OBJS) fish.o
$(CC) $(FISH_OBJS) fish.o $(LDFLAGS_FISH) -o $@
@@ -698,7 +708,7 @@ fish_pager: $(FISH_PAGER_OBJS)
# Build the fishd program.
#
fishd: $(FISHD_OBJS)
fishd: $(FISHD_OBJS)
$(CC) $(FISHD_OBJS) $(LDFLAGS_FISHD) -o $@
@@ -749,14 +759,14 @@ fish_indent: $(FISH_INDENT_OBJS)
#
key_reader: key_reader.o input_common.o common.o env_universal.o env_universal_common.o wutil.o
$(CC) key_reader.o input_common.o common.o env_universal.o env_universal_common.o wutil.o $(LDFLAGS) -o $@
$(CC) key_reader.o input_common.o common.o env_universal.o env_universal_common.o wutil.o $(LDFLAGS_FISH) -o $@
#
# Update dependencies
#
depend:
makedepend -fMakefile.in -Y *.c
makedepend -fMakefile.in -Y *.c
./config.status
.PHONY: depend
@@ -765,7 +775,7 @@ depend:
# an archive from it. Simplest way I could think of to make an archive
# witout backups, autogenerated files, etc.
#
# Uses install instead of mkdir so build won't fail if the directory
# Uses install instead of mkdir so build won't fail if the directory
# exists
#
@@ -817,7 +827,7 @@ dist: fish-@PACKAGE_VERSION@.tar.bz2
.PHONY: dist
#
# Build the RPM spec file.
# Build the RPM spec file.
#
fish.spec: fish.spec.in
@@ -854,9 +864,10 @@ rpm: fish-@PACKAGE_VERSION@.tar.bz2 fish.spec
#
distclean: clean
rm -f fish.spec Doxyfile.help
rm -f fish.spec Doxyfile.help
rm -f etc/config.fish seq share/config.fish
rm -f config.status config.log config.h Makefile
rm -rf $(XSEL)
.PHONY: distclean
@@ -868,15 +879,15 @@ distclean: clean
clean:
rm -f *.o doc.h doc.tmp doc_src/*.doxygen doc_src/*.c doc_src/*.o doc_src/commands.hdr
rm -f tests/tmp.err tests/tmp.out tests/tmp.status tests/foo.txt
rm -f $(PROGRAMS) fish_tests tokenizer_test key_reader
rm -f $(PROGRAMS) fish_tests tokenizer_test key_reader
rm -f share/config.fish etc/config.fish doc_src/index.hdr doc_src/commands.hdr
rm -f fish-@PACKAGE_VERSION@.tar
rm -f fish-@PACKAGE_VERSION@.tar.gz
rm -f fish-@PACKAGE_VERSION@.tar
rm -f fish-@PACKAGE_VERSION@.tar.gz
rm -f fish-@PACKAGE_VERSION@.tar.bz2
rm -rf doc;
rm -rf doc;
rm -rf fish-@PACKAGE_VERSION@
rm -rf xsel-0.9.6/
rm -f $(TRANSLATIONS)
test ! -d "$(XSEL)" || make -C $(XSEL) clean
.PHONY: clean

634
builtin.c

File diff suppressed because it is too large Load Diff

View File

@@ -64,7 +64,7 @@ enum
#define BUILTIN_FOR_ERR_IN _( L"%ls: Second argument must be 'in'\n" )
/**
Error message for insufficient number of arguments
Error message for insufficient number of arguments
*/
#define BUILTIN_FOR_ERR_COUNT _( L"%ls: Expected at least two arguments, got %d\n")
@@ -108,7 +108,7 @@ extern int builtin_err_redirect;
/**
Initialize builtin data.
Initialize builtin data.
*/
void builtin_init();
@@ -123,12 +123,13 @@ void builtin_destroy();
int builtin_exists( wchar_t *cmd );
/**
Execute a builtin command
Execute a builtin command
\param argv Array containing the command and parameters
\param argv Array containing the command and parameters
of the builtin. The list is terminated by a
null pointer. This syntax resembles the syntax
null pointer. This syntax resembles the syntax
for exec.
\param io the io redirections to perform on this builtin.
\return the exit status of the builtin command
*/

View File

@@ -1,6 +1,6 @@
/** \file builtin_commandline.c Functions defining the commandline builtin
Functions used for implementing the commandline builtin.
Functions used for implementing the commandline builtin.
*/
#include "config.h"
@@ -52,7 +52,15 @@ enum
}
;
/**
Pointer to what the commandline builtin considers to be the current
contents of the command line buffer.
*/
static wchar_t *current_buffer=0;
/**
What the commandline builtin considers to be the current cursor
position.
*/
static int current_cursor_pos = -1;
/**
@@ -88,20 +96,20 @@ static void replace_part( const wchar_t *begin,
const wchar_t *buff = get_buffer();
string_buffer_t out;
int out_pos=get_cursor_pos();
sb_init( &out );
sb_append_substring( &out, buff, begin-buff );
switch( append_mode)
{
case REPLACE_MODE:
{
sb_append( &out, insert );
out_pos = wcslen( insert ) + (begin-buff);
out_pos = wcslen( insert ) + (begin-buff);
break;
}
case APPEND_MODE:
{
@@ -115,7 +123,7 @@ static void replace_part( const wchar_t *begin,
sb_append_substring( &out, begin, cursor );
sb_append( &out, insert );
sb_append_substring( &out, begin+cursor, end-begin-cursor );
out_pos += wcslen( insert );
out_pos += wcslen( insert );
break;
}
}
@@ -123,7 +131,7 @@ static void replace_part( const wchar_t *begin,
reader_set_buffer( (wchar_t *)out.buff, out_pos );
sb_destroy( &out );
}
/**
Output the specified selection.
@@ -132,11 +140,11 @@ static void replace_part( const wchar_t *begin,
\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( const wchar_t *begin,
const wchar_t *end,
int cut_at_cursor,
static void write_part( const wchar_t *begin,
const wchar_t *end,
int cut_at_cursor,
int tokenize )
{
{
tokenizer tok;
string_buffer_t out;
wchar_t *buff;
@@ -149,7 +157,7 @@ static void write_part( const wchar_t *begin,
buff = wcsndup( begin, end-begin );
// fwprintf( stderr, L"Subshell: %ls, end char %lc\n", buff, *end );
sb_init( &out );
for( tok_init( &tok, buff, TOK_ACCEPT_UNFINISHED );
tok_has_next( &tok );
tok_next( &tok ) )
@@ -157,7 +165,7 @@ static void write_part( const wchar_t *begin,
if( (cut_at_cursor) &&
(tok_get_pos( &tok)+wcslen(tok_last( &tok)) >= pos) )
break;
switch( tok_last_type( &tok ) )
{
case TOK_STRING:
@@ -167,37 +175,35 @@ static void write_part( const wchar_t *begin,
free( tmp );
break;
}
}
}
}
sb_append( sb_out,
(wchar_t *)out.buff );
free( buff );
tok_destroy( &tok );
sb_destroy( &out );
}
else
{
wchar_t *buff, *esc;
wchar_t *buff;
if( cut_at_cursor )
{
end = begin+pos;
end = begin+pos;
}
buff = wcsndup( begin, end-begin );
esc = unescape( buff, UNESCAPE_INCOMPLETE );
// debug( 0, L"woot2 %ls -> %ls", buff, esc );
sb_append( sb_out, esc );
sb_append( sb_out, buff );
sb_append( sb_out, L"\n" );
free( esc );
free( buff );
}
}
@@ -211,14 +217,14 @@ static int builtin_commandline( wchar_t **argv )
int buffer_part=0;
int cut_at_cursor=0;
int argc = builtin_count_args( argv );
int append_mode=0;
int function_mode = 0;
int tokenize = 0;
int tokenize = 0;
int cursor_mode = 0;
int line_mode = 0;
int search_mode = 0;
@@ -246,7 +252,7 @@ static int builtin_commandline( wchar_t **argv )
*/
return 1;
}
sb_append( sb_err,
argv[0],
L": Can not set commandline in non-interactive mode\n",
@@ -259,7 +265,7 @@ static int builtin_commandline( wchar_t **argv )
while( 1 )
{
const static struct woption
static const struct woption
long_options[] =
{
{
@@ -285,11 +291,11 @@ static int builtin_commandline( wchar_t **argv )
{
L"current-token", no_argument, 0, 't'
}
,
,
{
L"current-buffer", no_argument, 0, 'b'
}
,
,
{
L"cut-at-cursor", no_argument, 0, 'c'
}
@@ -306,7 +312,7 @@ static int builtin_commandline( wchar_t **argv )
L"help", no_argument, 0, 'h'
}
,
{
{
L"input", required_argument, 0, 'I'
}
,
@@ -323,21 +329,21 @@ static int builtin_commandline( wchar_t **argv )
}
,
{
0, 0, 0, 0
0, 0, 0, 0
}
}
;
;
int opt_index = 0;
int opt = wgetopt_long( argc,
argv,
L"abijpctwforhI:CLS",
long_options,
argv,
L"abijpctwforhI:CLS",
long_options,
&opt_index );
if( opt == -1 )
break;
switch( opt )
{
case 0:
@@ -350,7 +356,7 @@ static int builtin_commandline( wchar_t **argv )
builtin_print_help( argv[0], sb_err );
return 1;
case L'a':
append_mode = APPEND_MODE;
break;
@@ -358,8 +364,8 @@ static int builtin_commandline( wchar_t **argv )
case L'b':
buffer_part = STRING_MODE;
break;
case L'i':
append_mode = INSERT_MODE;
break;
@@ -367,11 +373,11 @@ static int builtin_commandline( wchar_t **argv )
case L'r':
append_mode = REPLACE_MODE;
break;
case 'c':
cut_at_cursor=1;
break;
case 't':
buffer_part = TOKEN_MODE;
break;
@@ -396,33 +402,33 @@ static int builtin_commandline( wchar_t **argv )
current_buffer = woptarg;
current_cursor_pos = wcslen( woptarg );
break;
case 'C':
cursor_mode = 1;
break;
case 'L':
line_mode = 1;
break;
case 'S':
search_mode = 1;
break;
case 'h':
builtin_print_help( argv[0], sb_out );
return 0;
case L'?':
builtin_unknown_option( argv[0], argv[woptind-1] );
return 1;
return 1;
}
}
}
if( function_mode )
{
int i;
/*
Check for invalid switch combinations
*/
@@ -431,18 +437,18 @@ static int builtin_commandline( wchar_t **argv )
sb_printf(sb_err,
BUILTIN_ERR_COMBO,
argv[0] );
builtin_print_help( argv[0], sb_err );
return 1;
}
if( argc == woptind )
{
sb_printf( sb_err,
BUILTIN_ERR_MISSING,
argv[0] );
builtin_print_help( argv[0], sb_err );
return 1;
}
@@ -468,16 +474,16 @@ static int builtin_commandline( wchar_t **argv )
return 1;
}
}
return 0;
return 0;
}
/*
Check for invalid switch combinations
*/
if( (search_mode || line_mode || cursor_mode) && (argc-woptind > 1) )
{
sb_append( sb_err,
argv[0],
L": Too many arguments\n",
@@ -487,15 +493,15 @@ static int builtin_commandline( wchar_t **argv )
}
if( (buffer_part || tokenize || cut_at_cursor) && (cursor_mode || line_mode || search_mode) )
{
{
sb_printf( sb_err,
BUILTIN_ERR_COMBO,
argv[0] );
builtin_print_help( argv[0], sb_err );
return 1;
}
}
if( (tokenize || cut_at_cursor) && (argc-woptind) )
{
@@ -503,7 +509,7 @@ static int builtin_commandline( wchar_t **argv )
BUILTIN_ERR_COMBO2,
argv[0],
L"--cut-at-cursor and --tokenize can not be used when setting the commandline" );
builtin_print_help( argv[0], sb_err );
return 1;
@@ -516,7 +522,7 @@ static int builtin_commandline( wchar_t **argv )
argv[0],
L"insertion mode switches can not be used when not in insertion mode" );
builtin_print_help( argv[0], sb_err );
builtin_print_help( argv[0], sb_err );
return 1;
}
@@ -527,7 +533,7 @@ static int builtin_commandline( wchar_t **argv )
{
append_mode = REPLACE_MODE;
}
if( !buffer_part )
{
buffer_part = STRING_MODE;
@@ -540,7 +546,7 @@ static int builtin_commandline( wchar_t **argv )
wchar_t *endptr;
int new_pos;
errno = 0;
new_pos = wcstol( argv[woptind], &endptr, 10 );
if( *endptr || errno )
{
@@ -550,7 +556,7 @@ static int builtin_commandline( wchar_t **argv )
argv[woptind] );
builtin_print_help( argv[0], sb_err );
}
current_buffer = reader_get_buffer();
new_pos = maxi( 0, mini( new_pos, wcslen( current_buffer ) ) );
reader_set_buffer( current_buffer, new_pos );
@@ -561,98 +567,98 @@ static int builtin_commandline( wchar_t **argv )
sb_printf( sb_out, L"%d\n", reader_get_cursor_pos() );
return 0;
}
}
if( line_mode )
{
int pos = reader_get_cursor_pos();
wchar_t *buff = reader_get_buffer();
sb_printf( sb_out, L"%d\n", parse_util_lineno( buff, pos ) );
return 0;
}
if( search_mode )
{
return !reader_search_mode();
}
switch( buffer_part )
{
case STRING_MODE:
{
{
begin = get_buffer();
end = begin+wcslen(begin);
break;
break;
}
case PROCESS_MODE:
{
parse_util_process_extent( get_buffer(),
get_cursor_pos(),
&begin,
&begin,
&end );
break;
}
case JOB_MODE:
{
parse_util_job_extent( get_buffer(),
get_cursor_pos(),
&begin,
&end );
break;
&end );
break;
}
case TOKEN_MODE:
{
parse_util_token_extent( get_buffer(),
get_cursor_pos(),
&begin,
&end,
&begin,
&end,
0, 0 );
break;
break;
}
}
switch(argc-woptind)
{
case 0:
{
{
write_part( begin, end, cut_at_cursor, tokenize );
break;
}
case 1:
{
replace_part( begin, end, argv[woptind], append_mode );
break;
}
}
default:
{
string_buffer_t sb;
int i;
sb_init( &sb );
sb_append( &sb, argv[woptind] );
for( i=woptind+1; i<argc; i++ )
{
sb_append( &sb, L"\n" );
sb_append( &sb, argv[i] );
}
replace_part( begin, end, (wchar_t *)sb.buff, append_mode );
sb_destroy( &sb );
break;
}
}
}
return 0;
}

View File

@@ -1,6 +1,6 @@
/** \file builtin_complete.c Functions defining the complete builtin
Functions used for implementing the complete builtin.
Functions used for implementing the complete builtin.
*/
#include "config.h"
@@ -28,7 +28,7 @@ Functions used for implementing the complete builtin.
/**
Internal storage for the builtin_get_temporary_buffer() function.
*/
const static wchar_t *temporary_buffer;
static const wchar_t *temporary_buffer;
/*
builtin_complete_* are a set of rather silly looping functions that
@@ -46,8 +46,8 @@ static void builtin_complete_add2( const wchar_t *cmd,
int cmd_type,
const wchar_t *short_opt,
array_list_t *gnu_opt,
array_list_t *old_opt,
int result_mode,
array_list_t *old_opt,
int result_mode,
const wchar_t *condition,
const wchar_t *comp,
const wchar_t *desc,
@@ -55,10 +55,10 @@ static void builtin_complete_add2( const wchar_t *cmd,
{
int i;
const wchar_t *s;
for( s=short_opt; *s; s++ )
{
complete_add( cmd,
complete_add( cmd,
cmd_type,
*s,
0,
@@ -69,10 +69,10 @@ static void builtin_complete_add2( const wchar_t *cmd,
desc,
flags );
}
for( i=0; i<al_get_count( gnu_opt ); i++ )
{
complete_add( cmd,
complete_add( cmd,
cmd_type,
0,
(wchar_t *)al_get(gnu_opt, i ),
@@ -83,10 +83,10 @@ static void builtin_complete_add2( const wchar_t *cmd,
desc,
flags );
}
for( i=0; i<al_get_count( old_opt ); i++ )
{
complete_add( cmd,
complete_add( cmd,
cmd_type,
0,
(wchar_t *)al_get(old_opt, i ),
@@ -96,11 +96,11 @@ static void builtin_complete_add2( const wchar_t *cmd,
comp,
desc,
flags );
}
}
if( al_get_count( old_opt )+al_get_count( gnu_opt )+wcslen(short_opt) == 0 )
{
complete_add( cmd,
complete_add( cmd,
cmd_type,
0,
0,
@@ -110,18 +110,18 @@ static void builtin_complete_add2( const wchar_t *cmd,
comp,
desc,
flags );
}
}
}
/**
Silly function
*/
static void builtin_complete_add( array_list_t *cmd,
static void builtin_complete_add( array_list_t *cmd,
array_list_t *path,
const wchar_t *short_opt,
array_list_t *gnu_opt,
array_list_t *old_opt,
int result_mode,
array_list_t *old_opt,
int result_mode,
int authoritative,
const wchar_t *condition,
const wchar_t *comp,
@@ -129,17 +129,17 @@ static void builtin_complete_add( array_list_t *cmd,
int flags )
{
int i;
for( i=0; i<al_get_count( cmd ); i++ )
{
builtin_complete_add2( al_get( cmd, i ),
COMMAND,
short_opt,
short_opt,
gnu_opt,
old_opt,
result_mode,
condition,
comp,
old_opt,
result_mode,
condition,
comp,
desc,
flags );
@@ -149,19 +149,19 @@ static void builtin_complete_add( array_list_t *cmd,
COMMAND,
authoritative );
}
}
for( i=0; i<al_get_count( path ); i++ )
{
builtin_complete_add2( al_get( path, i ),
PATH,
short_opt,
short_opt,
gnu_opt,
old_opt,
result_mode,
condition,
comp,
old_opt,
result_mode,
condition,
comp,
desc,
flags );
@@ -171,8 +171,8 @@ static void builtin_complete_add( array_list_t *cmd,
PATH,
authoritative );
}
}
}
}
/**
@@ -181,17 +181,17 @@ static void builtin_complete_add( array_list_t *cmd,
static void builtin_complete_remove3( wchar_t *cmd,
int cmd_type,
wchar_t short_opt,
array_list_t *long_opt )
array_list_t *long_opt )
{
int i;
for( i=0; i<al_get_count( long_opt ); i++ )
{
complete_remove( cmd,
cmd_type,
short_opt,
(wchar_t *)al_get( long_opt, i ) );
}
}
}
/**
@@ -214,7 +214,7 @@ static void builtin_complete_remove2( wchar_t *cmd,
cmd_type,
*s,
0 );
}
else
{
@@ -239,42 +239,42 @@ static void builtin_complete_remove2( wchar_t *cmd,
cmd_type,
0,
old_opt );
}
}
}
/**
Silly function
*/
static void builtin_complete_remove( array_list_t *cmd,
static void builtin_complete_remove( array_list_t *cmd,
array_list_t *path,
const wchar_t *short_opt,
array_list_t *gnu_opt,
array_list_t *old_opt )
{
int i;
for( i=0; i<al_get_count( cmd ); i++ )
{
builtin_complete_remove2( (wchar_t *)al_get( cmd, i ),
COMMAND,
short_opt,
short_opt,
gnu_opt,
old_opt );
}
for( i=0; i<al_get_count( path ); i++ )
{
builtin_complete_remove2( (wchar_t *)al_get( path, i ),
PATH,
short_opt,
short_opt,
gnu_opt,
old_opt );
}
}
@@ -296,60 +296,55 @@ static int builtin_complete( wchar_t **argv )
int remove = 0;
int authoritative = -1;
int flags = COMPLETE_AUTO_SPACE;
string_buffer_t short_opt;
array_list_t gnu_opt, old_opt;
wchar_t *comp=L"", *desc=L"", *condition=L"";
wchar_t *do_complete = 0;
array_list_t cmd;
array_list_t path;
static int recursion_level=0;
if( !is_interactive_session )
{
debug( 1, _(L"%ls: Command only available in interactive sessions"), argv[0] );
}
al_init( &cmd );
al_init( &path );
sb_init( &short_opt );
al_init( &gnu_opt );
al_init( &old_opt );
argc = builtin_count_args( argv );
argc = builtin_count_args( argv );
woptind=0;
while( res == 0 )
{
const static struct woption
static const struct woption
long_options[] =
{
{
L"exclusive", no_argument, 0, 'x'
L"exclusive", no_argument, 0, 'x'
}
,
{
L"no-files", no_argument, 0, 'f'
L"no-files", no_argument, 0, 'f'
}
,
{
L"require-parameter", no_argument, 0, 'r'
L"require-parameter", no_argument, 0, 'r'
}
,
{
L"path", required_argument, 0, 'p'
}
,
,
{
L"command", required_argument, 0, 'c'
L"command", required_argument, 0, 'c'
}
,
,
{
L"short-option", required_argument, 0, 's'
L"short-option", required_argument, 0, 's'
}
,
{
@@ -357,7 +352,7 @@ static int builtin_complete( wchar_t **argv )
}
,
{
L"old-option", required_argument, 0, 'o'
L"old-option", required_argument, 0, 'o'
}
,
{
@@ -392,22 +387,22 @@ static int builtin_complete( wchar_t **argv )
L"help", no_argument, 0, 'h'
}
,
{
0, 0, 0, 0
{
0, 0, 0, 0
}
}
;
;
int opt_index = 0;
int opt = wgetopt_long( argc,
argv,
L"a:c:p:s:l:o:d:frxeuAn:C::h",
long_options,
argv,
L"a:c:p:s:l:o:d:frxeuAn:C::h",
long_options,
&opt_index );
if( opt == -1 )
break;
switch( opt )
{
case 0:
@@ -419,23 +414,23 @@ static int builtin_complete( wchar_t **argv )
long_options[opt_index].name );
builtin_print_help( argv[0], sb_err );
res = 1;
break;
case 'x':
case 'x':
result_mode |= EXCLUSIVE;
break;
case 'f':
case 'f':
result_mode |= NO_FILES;
break;
case 'r':
case 'r':
result_mode |= NO_COMMON;
break;
case 'p':
case 'p':
case 'c':
{
wchar_t *a = unescape( woptarg, 1);
@@ -446,31 +441,31 @@ static int builtin_complete( wchar_t **argv )
else
{
sb_printf( sb_err, L"%ls: Invalid token '%ls'\n", argv[0], woptarg );
res = 1;
}
res = 1;
}
break;
}
case 'd':
desc = woptarg;
break;
case 'u':
authoritative=0;
break;
case 'A':
authoritative=1;
break;
case 's':
sb_append( &short_opt, woptarg );
break;
case 'l':
al_push( &gnu_opt, woptarg );
break;
case 'o':
al_push( &old_opt, woptarg );
break;
@@ -478,7 +473,7 @@ static int builtin_complete( wchar_t **argv )
case 'a':
comp = woptarg;
break;
case 'e':
remove = 1;
break;
@@ -486,22 +481,22 @@ static int builtin_complete( wchar_t **argv )
case 'n':
condition = woptarg;
break;
case 'C':
do_complete = woptarg?woptarg:reader_get_buffer();
break;
case 'h':
builtin_print_help( argv[0], sb_out );
return 0;
case '?':
builtin_unknown_option( argv[0], argv[woptind-1] );
res = 1;
break;
}
}
if( !res )
@@ -511,17 +506,17 @@ static int builtin_complete( wchar_t **argv )
if( parser_test( condition, 0, 0, 0 ) )
{
sb_printf( sb_err,
L"%ls: Condition '%ls' contained a syntax error\n",
L"%ls: Condition '%ls' contained a syntax error\n",
argv[0],
condition );
parser_test( condition, 0, sb_err, argv[0] );
res = 1;
}
}
}
if( !res )
{
if( comp && wcslen( comp ) )
@@ -529,12 +524,12 @@ static int builtin_complete( wchar_t **argv )
if( parser_test_args( comp, 0, 0 ) )
{
sb_printf( sb_err,
L"%ls: Completion '%ls' contained a syntax error\n",
L"%ls: Completion '%ls' contained a syntax error\n",
argv[0],
comp );
parser_test_args( comp, sb_err, argv[0] );
res = 1;
}
}
@@ -552,22 +547,22 @@ static int builtin_complete( wchar_t **argv )
wchar_t *token;
parse_util_token_extent( do_complete, wcslen( do_complete ), &token, 0, 0, 0 );
temporary_buffer = do_complete;
temporary_buffer = do_complete;
if( recursion_level < 1 )
{
recursion_level++;
comp = al_halloc( 0 );
complete( do_complete, comp );
for( i=0; i<al_get_count( comp ); i++ )
{
completion_t *next = (completion_t *)al_get( comp, i );
wchar_t *prepend;
if( next->flags & COMPLETE_NO_CASE )
{
prepend = L"";
@@ -576,7 +571,7 @@ static int builtin_complete( wchar_t **argv )
{
prepend = token;
}
if( next->description )
{
@@ -587,17 +582,17 @@ static int builtin_complete( wchar_t **argv )
sb_printf( sb_out, L"%ls%ls\n", prepend, next->completion );
}
}
halloc_free( comp );
recursion_level--;
}
temporary_buffer = prev_temporary_buffer;
temporary_buffer = prev_temporary_buffer;
}
else if( woptind != argc )
{
sb_printf( sb_err,
sb_printf( sb_err,
_( L"%ls: Too many arguments\n" ),
argv[0] );
builtin_print_help( argv[0], sb_err );
@@ -608,7 +603,7 @@ static int builtin_complete( wchar_t **argv )
{
/* No arguments specified, meaning we print the definitions of
* all specified completions to stdout.*/
complete_print( sb_out );
complete_print( sb_out );
}
else
{
@@ -618,26 +613,26 @@ static int builtin_complete( wchar_t **argv )
&path,
(wchar_t *)short_opt.buff,
&gnu_opt,
&old_opt );
&old_opt );
}
else
{
builtin_complete_add( &cmd,
builtin_complete_add( &cmd,
&path,
(wchar_t *)short_opt.buff,
&gnu_opt,
&old_opt,
result_mode,
&old_opt,
result_mode,
authoritative,
condition,
comp,
desc,
flags );
flags );
}
}
}
}
al_foreach( &cmd, &free );
al_foreach( &path, &free );

View File

@@ -173,7 +173,7 @@ static int builtin_jobs( wchar_t **argv )
while( 1 )
{
const static struct woption
static const struct woption
long_options[] =
{
{
@@ -248,7 +248,7 @@ static int builtin_jobs( wchar_t **argv )
case 'h':
builtin_print_help( argv[0], sb_out );
return 0;
return 0;
case '?':
builtin_unknown_option( argv[0], argv[woptind-1] );

View File

@@ -1,6 +1,6 @@
/** \file builtin_set.c Functions defining the set builtin
Functions used for implementing the set builtin.
Functions used for implementing the set builtin.
*/
#include "config.h"
@@ -61,19 +61,19 @@ static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
int i;
int retcode = 0;
wchar_t *val_str=0;
if( is_path_variable( key ) )
{
int error = 0;
for( i=0; i<al_get_count( val ); i++ )
{
int show_perror = 0;
int show_hint = 0;
struct stat buff;
wchar_t *dir = (wchar_t *)al_get( val, i );
if( wstat( dir, &buff ) )
{
error = 1;
@@ -83,55 +83,55 @@ static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
if( !( S_ISDIR(buff.st_mode) ) )
{
error = 1;
}
if( error )
{
wchar_t *colon;
sb_printf( sb_err,
sb_printf( sb_err,
_(BUILTIN_SET_PATH_ERROR),
L"set",
dir,
L"set",
dir,
key );
colon = wcschr( dir, L':' );
if( colon && *(colon+1) )
if( colon && *(colon+1) )
{
show_hint = 1;
}
}
if( show_perror )
{
builtin_wperror( L"set" );
}
if( show_hint )
{
sb_printf( sb_err,
sb_printf( sb_err,
_(BUILTIN_SET_PATH_HINT),
L"set",
key,
key,
wcschr( dir, L':' )+1);
}
if( error )
{
break;
}
}
if( error )
{
return 1;
}
}
sb_init( &sb );
@@ -148,9 +148,9 @@ static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
}
}
val_str = (wchar_t *)sb.buff;
}
switch( env_set( key, val_str, scope | ENV_USER ) )
{
case ENV_PERM:
@@ -159,7 +159,7 @@ static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
retcode=1;
break;
}
case ENV_INVALID:
{
sb_printf( sb_err, _(L"%ls: Unknown error"), L"set" );
@@ -173,13 +173,13 @@ static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
return retcode;
}
/**
/**
Extract indexes from a destination argument of the form name[index1 index2...]
\param indexes the list to insert the new indexes into
\param src the source string to parse
\param name the name of the element. Return null if the name in \c src does not match this name
\param var_count the number of elements in the array to parse.
\param var_count the number of elements in the array to parse.
\return the total number of indexes parsed, or -1 on error
*/
@@ -189,57 +189,57 @@ static int parse_index( array_list_t *indexes,
int var_count )
{
int len;
int count = 0;
const wchar_t *src_orig = src;
if (src == 0)
{
return 0;
}
while (*src != L'\0' && (iswalnum(*src) || *src == L'_'))
{
src++;
}
if (*src != L'[')
{
sb_printf( sb_err, _(BUILTIN_SET_ARG_COUNT), L"set" );
sb_printf( sb_err, _(BUILTIN_SET_ARG_COUNT), L"set" );
return 0;
}
len = src-src_orig;
if( (wcsncmp( src_orig, name, len )!=0) || (wcslen(name) != (len)) )
{
sb_printf( sb_err,
sb_printf( sb_err,
_(L"%ls: Multiple variable names specified in single call (%ls and %.*ls)\n"),
L"set",
L"set",
name,
len,
src_orig);
return 0;
}
src++;
src++;
while (iswspace(*src))
while (iswspace(*src))
{
src++;
}
while (*src != L']')
while (*src != L']')
{
wchar_t *end;
long l_ind;
errno = 0;
l_ind = wcstol(src, &end, 10);
if( end==src || errno )
if( end==src || errno )
{
sb_printf(sb_err, _(L"%ls: Invalid index starting at '%ls'\n"), L"set", src);
return 0;
@@ -249,7 +249,7 @@ static int parse_index( array_list_t *indexes,
{
l_ind = var_count+l_ind+1;
}
al_push_long(indexes, l_ind);
src = end;
count++;
@@ -268,14 +268,14 @@ static int parse_index( array_list_t *indexes,
\return 0 if the operation was successfull, non-zero otherwise
*/
static int update_values( array_list_t *list,
static int update_values( array_list_t *list,
array_list_t *indexes,
array_list_t *values )
array_list_t *values )
{
int i;
/* Replace values where needed */
for( i = 0; i < al_get_count(indexes); i++ )
for( i = 0; i < al_get_count(indexes); i++ )
{
/*
The '- 1' below is because the indices in fish are
@@ -287,11 +287,11 @@ static int update_values( array_list_t *list,
{
return 1;
}
free((void *) al_get(list, ind));
al_set(list, ind, new != 0 ? wcsdup(new) : wcsdup(L""));
}
return 0;
}
@@ -305,42 +305,42 @@ static int al_contains_long( array_list_t *list,
{
int i;
for (i = 0; i < al_get_count(list); i++)
for (i = 0; i < al_get_count(list); i++)
{
long current = al_get_long(list, i);
if( current != 0 && current == val )
if( current != 0 && current == val )
{
return 1;
}
}
return 0;
}
/**
Erase from a list values at specified indexes
Erase from a list values at specified indexes
*/
static void erase_values(array_list_t *list, array_list_t *indexes)
static void erase_values(array_list_t *list, array_list_t *indexes)
{
long i;
array_list_t result;
al_init(&result);
for (i = 0; i < al_get_count(list); i++)
for (i = 0; i < al_get_count(list); i++)
{
if (!al_contains_long(indexes, i + 1))
if (!al_contains_long(indexes, i + 1))
{
al_push(&result, al_get(list, i));
}
else
else
{
free( (void *)al_get(list, i));
}
}
al_truncate(list,0);
al_truncate(list,0);
al_push_all( list, &result );
al_destroy(&result);
}
@@ -350,31 +350,31 @@ static void erase_values(array_list_t *list, array_list_t *indexes)
Print the names of all environment variables in the scope, with or without values,
with or without escaping
*/
static void print_variables(int include_values, int esc, int scope)
static void print_variables(int include_values, int esc, int scope)
{
array_list_t names;
int i;
al_init( &names );
env_get_names( &names, scope );
sort_list( &names );
for( i = 0; i < al_get_count(&names); i++ )
{
wchar_t *key = (wchar_t *)al_get( &names, i );
wchar_t *e_key = esc ? escape(key, 0) : wcsdup(key);
sb_append(sb_out, e_key);
if( include_values )
if( include_values )
{
wchar_t *value = env_get(key);
wchar_t *e_value;
if( value )
{
int shorten = 0;
if( wcslen( value ) > 64 )
{
shorten = 1;
@@ -384,12 +384,12 @@ static void print_variables(int include_values, int esc, int scope)
DIE_MEM();
}
}
e_value = esc ? expand_escape_variable(value) : wcsdup(value);
sb_append(sb_out, L" ", e_value, (void *)0);
free(e_value);
if( shorten )
{
sb_append(sb_out, L"\u2026");
@@ -398,7 +398,7 @@ static void print_variables(int include_values, int esc, int scope)
}
}
sb_append(sb_out, L"\n");
free(e_key);
}
@@ -411,57 +411,57 @@ static void print_variables(int include_values, int esc, int scope)
The set builtin. Creates, updates and erases environment variables
and environemnt variable arrays.
*/
static int builtin_set( wchar_t **argv )
static int builtin_set( wchar_t **argv )
{
/**
Variables used for parsing the argument list
*/
const static struct woption
long_options[] =
static const struct woption
long_options[] =
{
{
L"export", no_argument, 0, 'x'
{
L"export", no_argument, 0, 'x'
}
,
{
L"global", no_argument, 0, 'g'
{
L"global", no_argument, 0, 'g'
}
,
{
L"local", no_argument, 0, 'l'
{
L"local", no_argument, 0, 'l'
}
,
{
L"erase", no_argument, 0, 'e'
{
L"erase", no_argument, 0, 'e'
}
,
{
L"names", no_argument, 0, 'n'
}
{
L"names", no_argument, 0, 'n'
}
,
{
L"unexport", no_argument, 0, 'u'
}
{
L"unexport", no_argument, 0, 'u'
}
,
{
L"universal", no_argument, 0, 'U'
}
{
L"universal", no_argument, 0, 'U'
}
,
{
L"query", no_argument, 0, 'q'
}
{
L"query", no_argument, 0, 'q'
}
,
{
L"help", no_argument, 0, 'h'
}
{
L"help", no_argument, 0, 'h'
}
,
{
0, 0, 0, 0
{
0, 0, 0, 0
}
}
;
const wchar_t *short_options = L"+xglenuUqh";
int argc = builtin_count_args(argv);
@@ -472,7 +472,7 @@ static int builtin_set( wchar_t **argv )
int local = 0, global = 0, export = 0;
int erase = 0, list = 0, unexport=0;
int universal = 0, query=0;
/*
Variables used for performing the actual work
@@ -482,22 +482,22 @@ static int builtin_set( wchar_t **argv )
int scope;
int slice=0;
int i;
wchar_t *bad_char;
/* Parse options to obtain the requested operation and the modifiers */
woptind = 0;
while (1)
while (1)
{
int c = wgetopt_long(argc, argv, short_options, long_options, 0);
if (c == -1)
if (c == -1)
{
break;
}
switch(c)
switch(c)
{
case 0:
break;
@@ -561,18 +561,18 @@ static int builtin_set( wchar_t **argv )
sb_printf(sb_err,
BUILTIN_ERR_COMBO,
argv[0] );
builtin_print_help( argv[0], sb_err );
return 1;
}
/* We can't both list and erase varaibles */
if( erase && list )
if( erase && list )
{
sb_printf(sb_err,
BUILTIN_ERR_COMBO,
argv[0] );
argv[0] );
builtin_print_help( argv[0], sb_err );
return 1;
@@ -581,7 +581,7 @@ static int builtin_set( wchar_t **argv )
/*
Variables can only have one scope
*/
if( local + global + universal > 1 )
if( local + global + universal > 1 )
{
sb_printf( sb_err,
BUILTIN_ERR_GLOCAL,
@@ -593,7 +593,7 @@ static int builtin_set( wchar_t **argv )
/*
Variables can only have one export status
*/
if( export && unexport )
if( export && unexport )
{
sb_printf( sb_err,
BUILTIN_ERR_EXPUNEXP,
@@ -605,7 +605,7 @@ static int builtin_set( wchar_t **argv )
/*
Calculate the scope value for variable assignement
*/
scope = (local ? ENV_LOCAL : 0) | (global ? ENV_GLOBAL : 0) | (export ? ENV_EXPORT : 0) | (unexport ? ENV_UNEXPORT : 0) | (universal ? ENV_UNIVERSAL:0) | ENV_USER;
scope = (local ? ENV_LOCAL : 0) | (global ? ENV_GLOBAL : 0) | (export ? ENV_EXPORT : 0) | (unexport ? ENV_UNEXPORT : 0) | (universal ? ENV_UNIVERSAL:0) | ENV_USER;
if( query )
{
@@ -621,7 +621,7 @@ static int builtin_set( wchar_t **argv )
if( !(dest = wcsdup(arg)))
{
DIE_MEM();
DIE_MEM();
}
if( wcschr( dest, L'[' ) )
@@ -629,18 +629,18 @@ static int builtin_set( wchar_t **argv )
slice = 1;
*wcschr( dest, L'[' )=0;
}
if( slice )
{
array_list_t indexes;
array_list_t result;
int j;
al_init( &result );
al_init( &indexes );
tokenize_variable_array( env_get( dest ), &result );
if( !parse_index( &indexes, arg, dest, al_get_count( &result ) ) )
{
builtin_print_help( argv[0], sb_err );
@@ -663,32 +663,32 @@ static int builtin_set( wchar_t **argv )
retcode++;
}
}
free( dest );
}
return retcode;
}
if( list )
if( list )
{
/* Maybe we should issue an error if there are any other arguments? */
print_variables(0, 0, scope);
return 0;
}
}
if( woptind == argc )
{
/*
Print values of variables
*/
if( erase )
if( erase )
{
sb_printf( sb_err,
_(L"%ls: Erase needs a variable name\n%ls\n"),
_(L"%ls: Erase needs a variable name\n%ls\n"),
argv[0] );
builtin_print_help( argv[0], sb_err );
retcode = 1;
}
@@ -696,13 +696,13 @@ static int builtin_set( wchar_t **argv )
{
print_variables( 1, 1, scope );
}
return retcode;
}
if( !(dest = wcsdup(argv[woptind])))
{
DIE_MEM();
DIE_MEM();
}
if( wcschr( dest, L'[' ) )
@@ -710,7 +710,7 @@ static int builtin_set( wchar_t **argv )
slice = 1;
*wcschr( dest, L'[' )=0;
}
if( !wcslen( dest ) )
{
free( dest );
@@ -718,7 +718,7 @@ static int builtin_set( wchar_t **argv )
builtin_print_help( argv[0], sb_err );
return 1;
}
if( (bad_char = wcsvarname( dest ) ) )
{
sb_printf( sb_err, BUILTIN_ERR_VARCHAR, argv[0], *bad_char );
@@ -726,7 +726,7 @@ static int builtin_set( wchar_t **argv )
free( dest );
return 1;
}
if( slice && erase && (scope != ENV_USER) )
{
free( dest );
@@ -734,12 +734,12 @@ static int builtin_set( wchar_t **argv )
builtin_print_help( argv[0], sb_err );
return 1;
}
/*
set assignment can work in two modes, either using slices or
using the whole array. We detect which mode is used here.
*/
if( slice )
{
@@ -750,22 +750,22 @@ static int builtin_set( wchar_t **argv )
array_list_t values;
array_list_t indexes;
array_list_t result;
al_init(&values);
al_init(&indexes);
al_init(&result);
tokenize_variable_array( env_get(dest), &result );
for( ; woptind<argc; woptind++ )
{
{
if( !parse_index( &indexes, argv[woptind], dest, al_get_count( &result ) ) )
{
builtin_print_help( argv[0], sb_err );
retcode = 1;
break;
}
val_count = argc-woptind-1;
idx_count = al_get_count( &indexes );
@@ -784,7 +784,7 @@ static int builtin_set( wchar_t **argv )
break;
}
}
}
}
if( !retcode )
{
@@ -802,12 +802,12 @@ static int builtin_set( wchar_t **argv )
array_list_t value;
al_init(&value);
while( woptind < argc )
while( woptind < argc )
{
al_push(&value, argv[woptind++]);
}
if( update_values( &result,
if( update_values( &result,
&indexes,
&value ) )
{
@@ -815,14 +815,14 @@ static int builtin_set( wchar_t **argv )
sb_printf( sb_err, ARRAY_BOUNDS_ERR );
sb_append( sb_err, L"\n" );
}
my_env_set(dest,
&result,
scope);
al_destroy( &value );
}
}
}
al_foreach( &result, &free );
@@ -830,12 +830,12 @@ static int builtin_set( wchar_t **argv )
al_destroy(&indexes);
al_destroy(&values);
}
else
{
woptind++;
/*
No slicing
*/
@@ -843,7 +843,7 @@ static int builtin_set( wchar_t **argv )
{
if( woptind != argc )
{
sb_printf( sb_err,
sb_printf( sb_err,
_(L"%ls: Values cannot be specfied with erase\n"),
argv[0] );
builtin_print_help( argv[0], sb_err );
@@ -858,21 +858,21 @@ static int builtin_set( wchar_t **argv )
{
array_list_t val;
al_init( &val );
for( i=woptind; i<argc; i++ )
{
al_push( &val, argv[i] );
}
retcode = my_env_set( dest, &val, scope );
al_destroy( &val );
}
al_destroy( &val );
}
}
free( dest );
return retcode;
}

View File

@@ -1,6 +1,6 @@
/** \file builtin_ulimit.c Functions defining the ulimit builtin
Functions used for implementing the ulimit builtin.
Functions used for implementing the ulimit builtin.
*/
#include "config.h"
@@ -38,18 +38,18 @@ struct resource_t
/**
Switch used on commandline to specify resource
*/
wchar_t switch_char;
wchar_t switch_char;
/**
The implicit multiplier used when setting getting values
*/
int multiplier;
int multiplier;
}
;
/**
Array of resource_t structs, describing all known resource types.
*/
const static struct resource_t resource_arr[] =
static const struct resource_t resource_arr[] =
{
{
RLIMIT_CORE, L"Maximum size of core files created", L'c', 1024
@@ -96,7 +96,7 @@ const static struct resource_t resource_arr[] =
#ifdef RLIMIT_AS
{
RLIMIT_AS, L"Maximum amount of virtual memory available to the shell", L'v', 1024
}
}
,
#endif
{
@@ -111,7 +111,7 @@ const static struct resource_t resource_arr[] =
static int get_multiplier( int what )
{
int i;
for( i=0; resource_arr[i].desc; i++ )
{
if( resource_arr[i].resource == what )
@@ -130,9 +130,9 @@ static int get_multiplier( int what )
static rlim_t get( int resource, int hard )
{
struct rlimit ls;
getrlimit( resource, &ls );
return hard ? ls.rlim_max:ls.rlim_cur;
}
@@ -147,7 +147,7 @@ static void print( int resource, int hard )
sb_append( sb_out, L"unlimited\n" );
else
sb_printf( sb_out, L"%d\n", l / get_multiplier( resource ) );
}
/**
@@ -157,12 +157,12 @@ static void print_all( int hard )
{
int i;
int w=0;
for( i=0; resource_arr[i].desc; i++ )
{
w=maxi( w, my_wcswidth(resource_arr[i].desc));
}
for( i=0; resource_arr[i].desc; i++ )
{
struct rlimit ls;
@@ -171,14 +171,14 @@ static void print_all( int hard )
l = hard ? ls.rlim_max:ls.rlim_cur;
wchar_t *unit = ((resource_arr[i].resource==RLIMIT_CPU)?L"(seconds, ":(get_multiplier(resource_arr[i].resource)==1?L"(":L"(kB, "));
sb_printf( sb_out,
L"%-*ls %10ls-%lc) ",
w,
resource_arr[i].desc,
L"%-*ls %10ls-%lc) ",
w,
resource_arr[i].desc,
unit,
resource_arr[i].switch_char);
if( l == RLIM_INFINITY )
{
sb_append( sb_out, L"unlimited\n" );
@@ -188,7 +188,7 @@ static void print_all( int hard )
sb_printf( sb_out, L"%d\n", l/get_multiplier(resource_arr[i].resource) );
}
}
}
/**
@@ -197,7 +197,7 @@ static void print_all( int hard )
static const wchar_t *get_desc( int what )
{
int i;
for( i=0; resource_arr[i].desc; i++ )
{
if( resource_arr[i].resource == what )
@@ -217,26 +217,26 @@ static int set( int resource, int hard, int soft, rlim_t value )
{
struct rlimit ls;
getrlimit( resource, &ls );
if( hard )
{
ls.rlim_max = value;
}
if( soft )
{
ls.rlim_cur = value;
/*
Do not attempt to set the soft limit higher than the hard limit
*/
if( ( value == RLIM_INFINITY && ls.rlim_max != RLIM_INFINITY ) ||
if( ( value == RLIM_INFINITY && ls.rlim_max != RLIM_INFINITY ) ||
( value != RLIM_INFINITY && ls.rlim_max != RLIM_INFINITY && value > ls.rlim_max))
{
ls.rlim_cur = ls.rlim_max;
}
}
}
if( setrlimit( resource, &ls ) )
{
if( errno == EPERM )
@@ -244,8 +244,8 @@ static int set( int resource, int hard, int soft, rlim_t value )
else
builtin_wperror( L"ulimit" );
return 1;
}
return 0;
}
return 0;
}
/**
@@ -256,17 +256,17 @@ static int builtin_ulimit( wchar_t ** argv )
{
int hard=0;
int soft=0;
int what = RLIMIT_FSIZE;
int report_all = 0;
int argc = builtin_count_args( argv );
woptind=0;
while( 1 )
{
const static struct woption
static const struct woption
long_options[] =
{
{
@@ -321,27 +321,27 @@ static int builtin_ulimit( wchar_t ** argv )
L"virtual-memory-size", no_argument, 0, 'v'
}
,
{
L"help", no_argument, 0, 'h'
}
{
L"help", no_argument, 0, 'h'
}
,
{
0, 0, 0, 0
0, 0, 0, 0
}
}
;
;
int opt_index = 0;
int opt = wgetopt_long( argc,
argv,
L"aHScdflmnstuvh",
long_options,
argv,
L"aHScdflmnstuvh",
long_options,
&opt_index );
if( opt == -1 )
break;
switch( opt )
{
case 0:
@@ -354,7 +354,7 @@ static int builtin_ulimit( wchar_t ** argv )
builtin_print_help( argv[0], sb_err );
return 1;
case L'a':
report_all=1;
break;
@@ -364,17 +364,17 @@ static int builtin_ulimit( wchar_t ** argv )
break;
case L'S':
soft=1;
soft=1;
break;
case L'c':
what=RLIMIT_CORE;
break;
case L'd':
what=RLIMIT_DATA;
break;
case L'f':
what=RLIMIT_FSIZE;
break;
@@ -384,45 +384,45 @@ static int builtin_ulimit( wchar_t ** argv )
break;
#endif
#ifdef RLIMIT_RSS
#ifdef RLIMIT_RSS
case L'm':
what=RLIMIT_RSS;
break;
#endif
case L'n':
what=RLIMIT_NOFILE;
break;
case L's':
what=RLIMIT_STACK;
break;
case L't':
what=RLIMIT_CPU;
break;
#ifdef RLIMIT_NPROC
#ifdef RLIMIT_NPROC
case L'u':
what=RLIMIT_NPROC;
break;
#endif
#ifdef RLIMIT_AS
#ifdef RLIMIT_AS
case L'v':
what=RLIMIT_AS;
break;
#endif
case L'h':
builtin_print_help( argv[0], sb_out );
builtin_print_help( argv[0], sb_out );
return 0;
case L'?':
builtin_unknown_option( argv[0], argv[woptind-1] );
return 1;
return 1;
}
}
}
if( report_all )
{
@@ -442,7 +442,7 @@ static int builtin_ulimit( wchar_t ** argv )
return 0;
}
switch( argc - woptind )
{
case 0:
@@ -453,7 +453,7 @@ static int builtin_ulimit( wchar_t ** argv )
print( what, hard );
break;
}
case 1:
{
/*
@@ -469,7 +469,7 @@ static int builtin_ulimit( wchar_t ** argv )
{
hard=soft=1;
}
if( wcscasecmp( argv[woptind], L"unlimited" )==0)
{
new_limit = RLIM_INFINITY;
@@ -484,23 +484,23 @@ static int builtin_ulimit( wchar_t ** argv )
}
else
{
errno=0;
errno=0;
new_limit = wcstol( argv[woptind], &end, 10 );
if( errno || *end )
{
sb_printf( sb_err,
L"%ls: Invalid limit '%ls'\n",
argv[0],
sb_printf( sb_err,
L"%ls: Invalid limit '%ls'\n",
argv[0],
argv[woptind] );
builtin_print_help( argv[0], sb_err );
return 1;
}
new_limit *= get_multiplier( what );
}
return set( what, hard, soft, new_limit );
}
default:
{
sb_append( sb_err,
@@ -510,7 +510,7 @@ static int builtin_ulimit( wchar_t ** argv )
builtin_print_help( argv[0], sb_err );
return 1;
}
}
return 0;
return 0;
}

483
common.c

File diff suppressed because it is too large Load Diff

View File

@@ -40,11 +40,12 @@
*/
#define BYTE_MAX 0xffu
/*
Escape special fish syntax characters liek the semicolon
/**
Escape special fish syntax characters like the semicolon
*/
#define UNESCAPE_SPECIAL 1
/*
/**
Allow incomplete escape sequences
*/
#define UNESCAPE_INCOMPLETE 2
@@ -59,10 +60,10 @@
#define ESCAPE_NO_QUOTED 2
/**
/**
Save the shell mode on startup so we can restore them on exit
*/
extern struct termios shell_modes;
extern struct termios shell_modes;
/**
The character to use where the text has been truncated. Is an
@@ -108,14 +109,14 @@ extern wchar_t *program_name;
/**
Pause for input, then exit the program. If supported, print a backtrace first.
*/
#define FATAL_EXIT() \
{ \
char c; \
show_stackframe(); \
read( 0, &c, 1 ); \
exit( 1 ); \
} \
#define FATAL_EXIT() \
{ \
int exit_read_count;char exit_read_buff; \
show_stackframe(); \
exit_read_count=read( 0, &exit_read_buff, 1 ); \
exit( 1 ); \
} \
/**
Exit program at once, leaving an error message about running out of memory.
@@ -143,7 +144,7 @@ extern wchar_t *program_name;
show_stackframe(); \
return retval; \
}
/**
Shorthand for wgettext call
*/
@@ -151,14 +152,20 @@ extern wchar_t *program_name;
/**
Noop, used to tell xgettext that a string should be translated,
even though it is not directly sent to wgettext.
even though it is not directly sent to wgettext.
*/
#define N_(wstr) wstr
/**
Check if the specified stringelement is a part of the specified string list
*/
#define contains( str,... ) contains_internal( str, __VA_ARGS__, (void *)0 )
/**
Concatenate all the specified strings into a single newly allocated one
*/
#define wcsdupcat( str,... ) wcsdupcat_internal( str, __VA_ARGS__, (void *)0 )
/*
/**
Print a stack trace to stderr
*/
void show_stackframe();
@@ -174,7 +181,7 @@ wchar_t **list_to_char_arr( array_list_t *l );
Read a line from the stream f into the buffer buff of length len. If
buff is to small, it will be reallocated, and both buff and len will
be updated to reflect this. Returns the number of bytes read or -1
on failiure.
on failiure.
If the carriage return character is encountered, it is
ignored. fgetws() considers the line to end if reading the file
@@ -251,7 +258,7 @@ __sentinel wchar_t *wcsdupcat_internal( const wchar_t *a, ... );
/**
Test if the given string is a valid variable name.
Test if the given string is a valid variable name.
\return null if this is a valid name, and a pointer to the first invalid character otherwise
*/
@@ -260,7 +267,7 @@ wchar_t *wcsvarname( const wchar_t *str );
/**
Test if the given string is a valid function name.
Test if the given string is a valid function name.
\return null if this is a valid name, and a pointer to the first invalid character otherwise
*/
@@ -268,7 +275,7 @@ wchar_t *wcsvarname( const wchar_t *str );
wchar_t *wcsfuncname( const wchar_t *str );
/**
Test if the given string is valid in a variable name
Test if the given string is valid in a variable name
\return 1 if this is a valid name, 0 otherwise
*/
@@ -304,14 +311,14 @@ void error_reset();
This function behaves exactly like a wide character equivalent of
the C function setlocale, except that it will also try to detect if
the user is using a Unicode character set, and if so, use the
unicode ellipsis character as ellipsis, instead of '$'.
unicode ellipsis character as ellipsis, instead of '$'.
*/
const wchar_t *wsetlocale( int category, const wchar_t *locale );
/**
Checks if \c needle is included in the list of strings specified. A warning is printed if needle is zero.
\param needle the string to search for in the list
\param needle the string to search for in the list
\return zero if needle is not found, of if needle is null, non-zero otherwise
*/
@@ -324,6 +331,12 @@ __sentinel int contains_internal( const wchar_t *needle, ... );
*/
int read_blocked(int fd, void *buf, size_t count);
/**
Loop a write request while failiure is non-critical. Return -1 and set errno
in case of critical error.
*/
ssize_t write_loop(int fd, char *buff, size_t count);
/**
Issue a debug message with printf-style string formating and
@@ -333,9 +346,9 @@ int read_blocked(int fd, void *buf, size_t count);
Because debug is often called to tell the user about an error,
before using wperror to give a specific error message, debug will
never ever modify the value of errno.
\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 msg the message format string.
\param msg the message format string.
Example:
@@ -347,7 +360,7 @@ void debug( int level, const wchar_t *msg, ... );
/**
Replace special characters with backslash escape sequences. Newline is
replaced with \n, etc.
replaced with \n, etc.
\param in The string to be escaped
\param escape_all Whether all characters wich hold special meaning in fish (Pipe, semicolon, etc,) should be escaped, or only unprintable characters
@@ -367,21 +380,21 @@ wchar_t *escape( const wchar_t *in, int escape_all );
an invalid sequence is specified, 0 is returned.
*/
wchar_t *unescape( const wchar_t * in,
wchar_t *unescape( const wchar_t * in,
int escape_special );
/**
Attempt to acquire a lock based on a lockfile, waiting LOCKPOLLINTERVAL
milliseconds between polls and timing out after timeout seconds,
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
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 );
/**
/**
Returns the width of the terminal window, so that not all
functions that use these values continually have to keep track of
it separately.
@@ -415,9 +428,9 @@ void write_screen( const wchar_t *msg, string_buffer_t *buff );
Tokenize the specified string into the specified array_list_t.
Each new element is allocated using malloc and must be freed by the
caller.
\param val the input string. The contents of this string is not changed.
\param out the list in which to place the elements.
\param out the list in which to place the elements.
*/
void tokenize_variable_array( const wchar_t *val, array_list_t *out );
@@ -440,5 +453,15 @@ void bugreport();
void sb_format_size( string_buffer_t *sb,
long long sz );
/**
Return the number of seconds from the UNIX epoch, with subsecond
precision. This function uses the gettimeofday function, and will
have the same precision as that function.
If an error occurs, NAN is returned.
*/
double timef();
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -16,39 +16,39 @@
#include "util.h"
/**
Use all completions
/**
Use all completions
*/
#define SHARED 0
/**
Do not use file completion
/**
Do not use file completion
*/
#define NO_FILES 1
/**
Require a parameter after completion
/**
Require a parameter after completion
*/
#define NO_COMMON 2
/**
/**
Only use the argument list specifies with completion after
option. This is the same as (NO_FILES & NO_COMMON)
*/
#define EXCLUSIVE 3
/**
Command is a path
/**
Command is a path
*/
#define PATH 1
/**
Command is not a path
/**
Command is not a path
*/
#define COMMAND 0
/**
/**
Separator between completion and description
*/
#define COMPLETE_SEP L'\004'
/**
/**
Separator between completion and description
*/
#define COMPLETE_SEP_STR L"\004"
@@ -73,7 +73,7 @@
#define COMPLETE_NO_SPACE 1
/**
This compeltion is case insensitive.
This compeltion is case insensitive.
Warning: The contents of the completion_t structure is actually
different if this flag is set! Specifically, the completion string
@@ -94,6 +94,13 @@
*/
#define COMPLETE_AUTO_SPACE 8
/**
This completion should be inserted as-is, without escaping.
*/
#define COMPLETE_DONT_ESCAPE 16
typedef struct
{
@@ -108,7 +115,7 @@ typedef struct
const wchar_t *description;
/**
Flags determining the completion behaviour.
Flags determining the completion behaviour.
Determines whether a space should be inserted after this
compeltion if it is the only possible completion using the
@@ -125,17 +132,17 @@ typedef struct
/**
Add a completion.
Add a completion.
All supplied values are copied, they should be freed by or otherwise
disposed by the caller.
Examples:
Examples:
The command 'gcc -o' requires that a file follows it, so the
NO_COMMON option is suitable. This can be done using the following
line:
complete -c gcc -s o -r
The command 'grep -d' required that one of the strings 'read',
@@ -152,7 +159,7 @@ typedef struct
will be interpreted as the command name.
\param short_opt The single character name of an option. (-a is a short option, --all and -funroll are long options)
\param long_opt The multi character name of an option. (-a is a short option, --all and -funroll are long options)
\param long_mode Whether to use old style, single dash long options.
\param long_mode Whether to use old style, single dash long options.
\param result_mode Whether to search further completions when this
completion has been succesfully matched. If result_mode is SHARED,
any other completions may also be used. If result_mode is NO_FILES,
@@ -163,34 +170,34 @@ typedef struct
\param comp A space separated list of completions which may contain subshells.
\param desc A description of the completion.
\param condition a command to be run to check it this completion should be used. If \c condition is empty, the completion is always used.
\param flags A set of completion flags
*/
void complete_add( const wchar_t *cmd,
int cmd_type,
wchar_t short_opt,
const wchar_t *long_opt,
int long_mode,
int result_mode,
const wchar_t *condition,
const wchar_t *comp,
const wchar_t *desc,
int flags );
void complete_add( const wchar_t *cmd,
int cmd_type,
wchar_t short_opt,
const wchar_t *long_opt,
int long_mode,
int result_mode,
const wchar_t *condition,
const wchar_t *comp,
const wchar_t *desc,
int flags );
/**
Sets whether the completion list for this command is complete. If
true, any options not matching one of the provided options will be
flagged as an error by syntax highlighting.
*/
void complete_set_authoritative( const wchar_t *cmd,
int cmd_type,
int authoritative );
int cmd_type,
int authoritative );
/**
Remove a previously defined completion
*/
void complete_remove( const wchar_t *cmd,
int cmd_type,
wchar_t short_opt,
const wchar_t *long_opt );
void complete_remove( const wchar_t *cmd,
int cmd_type,
wchar_t short_opt,
const wchar_t *long_opt );
/**
Find all completions of the command cmd, insert them into out. The
@@ -205,7 +212,7 @@ void complete_remove( const wchar_t *cmd,
void complete( const wchar_t *cmd, array_list_t *out );
/**
Print a list of all current completions into the string_buffer_t.
Print a list of all current completions into the string_buffer_t.
\param out The string_buffer_t to write completions to
*/
@@ -214,16 +221,16 @@ void complete_print( string_buffer_t *out );
/**
Tests if the specified option is defined for the specified command
*/
int complete_is_valid_option( const wchar_t *str,
const wchar_t *opt,
int complete_is_valid_option( const wchar_t *str,
const wchar_t *opt,
array_list_t *errors );
/**
Tests if the specified argument is valid for the specified option
and command
*/
int complete_is_valid_argument( const wchar_t *str,
const wchar_t *opt,
int complete_is_valid_argument( const wchar_t *str,
const wchar_t *opt,
const wchar_t *arg );
@@ -242,7 +249,7 @@ void complete_load( const wchar_t *cmd, int reload );
Create a new completion entry
\param context The halloc context to use for allocating new memory
\pram comp The completion string
\param comp The completion string
\param desc The description of the completion
\param flags completion flags
*/

View File

@@ -9,29 +9,35 @@
# configure the build process.
#
AC_INIT(fish,1.23.0,fish-users@lists.sf.net)
AC_INIT(fish,1.23.1,fish-users@lists.sf.net)
#
# preserve configure arguments for xsel
#
conf_arg=$@
#
# List of output variables produced by this configure script
#
AC_SUBST( docdir )
AC_SUBST( HAVE_GETTEXT )
AC_SUBST( LDFLAGS_FISH )
AC_SUBST( LIBS_FISH )
AC_SUBST( LIBS_FISH_INDENT )
AC_SUBST( LIBS_FISH_PAGER )
AC_SUBST( LIBS_FISHD )
AC_SUBST( LIBS_MIMEDB )
AC_SUBST( LIBS_SET_COLOR )
AC_SUBST( localedir )
AC_SUBST( optbindirs )
AC_SUBST( prefix )
AC_SUBST( SEQ_FALLBACK )
AC_SUBST( XSEL )
AC_SUBST( XSEL_MAN )
AC_SUBST( XSEL_MAN_PATH )
AC_SUBST(docdir)
AC_SUBST(HAVE_GETTEXT)
AC_SUBST(LDFLAGS_FISH)
AC_SUBST(LIBS_FISH)
AC_SUBST(LIBS_FISH_INDENT)
AC_SUBST(LIBS_FISH_PAGER)
AC_SUBST(LIBS_FISHD)
AC_SUBST(LIBS_MIMEDB)
AC_SUBST(LIBS_SET_COLOR)
AC_SUBST(localedir)
AC_SUBST(optbindirs)
AC_SUBST(prefix)
AC_SUBST(SEQ_FALLBACK)
AC_SUBST(XSEL)
AC_SUBST(XSEL_MAN)
AC_SUBST(XSEL_BIN)
AC_SUBST(XSEL_MAN_PATH)
#
# If needed, run autoconf to regenerate the configure file
@@ -54,7 +60,7 @@ if test configure -ot configure.ac; then
fi
exit 1
else
AC_MSG_ERROR(
AC_MSG_ERROR(
[cannot find the autoconf program in your path.
This program needs to be run whenever the configure.ac file is modified.
Please install it and try again.]
@@ -79,7 +85,7 @@ if test ! -f ./config.h.in -o config.h.in -ot configure.ac; then
AC_MSG_NOTICE([running autoheader])
autoheader || exit 1
else
AC_MSG_ERROR(
AC_MSG_ERROR(
[cannot find the autoheader program in your path.
This program needs to be run whenever the configure.ac file is modified.
Please install it and try again.]
@@ -130,7 +136,7 @@ done
#
# Tell autoconf to create config.h header
# Tell autoconf to create config.h header
#
AC_CONFIG_HEADERS(config.h)
@@ -144,8 +150,8 @@ AH_BOTTOM([#if __GNUC__ >= 3
#define __warn_unused __attribute__ ((warn_unused_result))
#define __sentinel __attribute__ ((sentinel))
#else
#define __warn_unused
#define __sentinel
#define __warn_unused
#define __sentinel
#endif])
@@ -195,20 +201,22 @@ fi
# Optionally drop xsel command
#
AC_ARG_WITH(
xsel,
AC_ARG_WITH(
xsel,
AC_HELP_STRING(
[--without-xsel],
[do not build the xsel program needed for X clipboard integration]
[do not build the xsel program needed for X clipboard integration.
If build xsel, it will be configured with the same options as fish.]
),
[xsel=$withval],
[xsel=with_xsel]
[xsel=with_xsel]
)
if [[ "$xsel" = "with_xsel" ]]; then
XSEL=xsel-0.9.6/xsel
XSEL=xsel-1.2.0
XSEL_BIN=$XSEL/xsel
XSEL_MAN=xsel.1x
XSEL_MAN_PATH=xsel-0.9.6/xsel.1x
XSEL_MAN_PATH=$XSEL/xsel.1x
fi
@@ -226,7 +234,7 @@ AC_ARG_WITH(
[local_gettext=yes]
)
if test x$local_gettext != xno; then
if test x$local_gettext != xno; then
AC_DEFINE([USE_GETTEXT],[1],[Perform string translations with gettext])
fi
@@ -338,9 +346,9 @@ AC_RUN_IFELSE(
return STATUS;
]
)
],
[glibc=yes],
[glibc=no]
],
[glibc=yes],
[glibc=no]
)
if test "$glibc" = yes; then
@@ -383,7 +391,7 @@ fi
AC_MSG_CHECKING([if we are under Solaris])
case $target_os in
solaris*)
solaris*)
AC_DEFINE( __EXTENSIONS__, 1, [Macro to enable additional prototypes under Solaris])
AC_MSG_RESULT(yes)
;;
@@ -397,7 +405,7 @@ AC_MSG_CHECKING([if we are using non varargs tparm.])
AC_COMPILE_IFELSE(
[
AC_LANG_PROGRAM(
[
[
#include <curses.h>
#include <term.h>
],
@@ -406,8 +414,8 @@ AC_COMPILE_IFELSE(
]
)
],
[tparm_solaris_kludge=no],
[tparm_solaris_kludge=yes]
[tparm_solaris_kludge=no],
[tparm_solaris_kludge=yes]
)
if test "x$tparm_solaris_kludge" = "xyes"; then
AC_MSG_RESULT(yes)
@@ -427,7 +435,7 @@ fi
AC_MSG_CHECKING([if we are under BSD])
case $target_os in
*bsd*)
*bsd*)
AC_DEFINE( __BSD_VISIBLE, 1, [Macro to enable additional prototypes under BSD])
AC_DEFINE( _NETBSD_SOURCE, 1, [Macro to enable additional prototypes under BSD])
AC_MSG_RESULT(yes)
@@ -486,7 +494,7 @@ AC_CHECK_FILES([/proc/self/stat])
#
AC_DEFINE(
[HAVE_TRANSLATE_H],
[HAVE_TRANSLATE_H],
[1],
[Define to 1 if the wgettext function should be used for translating strings.]
)
@@ -505,67 +513,72 @@ LIBS=""
AC_SEARCH_LIBS( connect, socket, , [AC_MSG_ERROR([Cannot find the socket library, needed to build this package.] )] )
AC_SEARCH_LIBS( nanosleep, rt, , [AC_MSG_ERROR([Cannot find the rt library, needed to build this package.] )] )
AC_SEARCH_LIBS( setupterm, [ncurses curses], , [AC_MSG_ERROR([Could not find a curses implementation, needed to build fish])] )
AC_SEARCH_LIBS( [nan], [m], [AC_DEFINE( [HAVE_NAN], [1], [Define to 1 if you have the nan function])] )
LIBS_SHARED=$LIBS
LIBS=$LIBS_COMMON
#
# Check for libraries needed by fish.
# Check for libraries needed by fish.
#
LIBS_COMMON=$LIBS
LIBS="$LIBS_SHARED"
if test x$local_gettext != xno; then
if test x$local_gettext != xno; then
AC_SEARCH_LIBS( gettext, intl,,)
fi
# Check for libiconv_open if we can't find iconv_open. Silly OS X does
# weird macro magic for the sole purpose of amusing me.
AC_SEARCH_LIBS( iconv_open, iconv, , [AC_SEARCH_LIBS( libiconv_open, iconv, , [AC_MSG_ERROR([Could not find an iconv implementation, needed to build fish])] )] )
AC_SEARCH_LIBS( iconv_open, iconv, , [AC_MSG_ERROR([Could not find an iconv implementation, needed to build fish])] )
LIBS_FISH=$LIBS
LIBS=$LIBS_COMMON
#
# Check for libraries needed by fish_indent.
# Check for libraries needed by fish_indent.
#
LIBS_COMMON=$LIBS
LIBS="$LIBS_SHARED"
if test x$local_gettext != xno; then
if test x$local_gettext != xno; then
AC_SEARCH_LIBS( gettext, intl,,)
fi
LIBS_FISH_INDENT=$LIBS
LIBS=$LIBS_COMMON
#
# Check for libraries needed by fish_pager.
# Check for libraries needed by fish_pager.
#
LIBS_COMMON=$LIBS
LIBS="$LIBS_SHARED"
if test x$local_gettext != xno; then
if test x$local_gettext != xno; then
AC_SEARCH_LIBS( gettext, intl,,)
fi
AC_SEARCH_LIBS( iconv_open, iconv, , [AC_MSG_ERROR([Could not find an iconv implementation, needed to build fish])] )
LIBS_FISH_PAGER=$LIBS
LIBS=$LIBS_COMMON
#
# Check for libraries needed by fishd.
# Check for libraries needed by fishd.
#
LIBS_COMMON=$LIBS
LIBS="$LIBS_SHARED"
if test x$local_gettext != xno; then
if test x$local_gettext != xno; then
AC_SEARCH_LIBS( gettext, intl,,)
fi
AC_SEARCH_LIBS( iconv_open, iconv, , [AC_MSG_ERROR([Could not find an iconv implementation, needed to build fish])] )
LIBS_FISHD=$LIBS
LIBS=$LIBS_COMMON
#
# Check for libraries needed by mimedb.
# Check for libraries needed by mimedb.
#
LIBS_COMMON=$LIBS
LIBS="$LIBS_SHARED"
if test x$local_gettext != xno; then
if test x$local_gettext != xno; then
AC_SEARCH_LIBS( gettext, intl,,)
fi
LIBS_MIMEDB=$LIBS
@@ -573,12 +586,12 @@ LIBS=$LIBS_COMMON
#
# Check for libraries needed by set_color
# Check for libraries needed by set_color
#
LIBS_COMMON=$LIBS
LIBS="$LIBS_SHARED"
if test x$local_gettext != xno; then
if test x$local_gettext != xno; then
AC_SEARCH_LIBS( gettext, intl,,)
fi
LIBS_SET_COLOR=$LIBS
@@ -594,8 +607,8 @@ AC_CHECK_HEADER(
[regex.h],
[
AC_DEFINE(
[HAVE_REGEX_H],
[1],
[HAVE_REGEX_H],
[1],
[Define to 1 if you have the <regex.h> header file.]
)
],
@@ -692,10 +705,10 @@ for i in "" "-D_POSIX_C_SOURCE=200112L" "-D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=2
/* Extended-POSIX: might be unhidden by _XOPEN_SOURCE. */
ret += killpg( 0, 0 );
/* Non-standard: might be hidden by the macros. */
{
{
struct winsize termsize;
ret += (int)(void *)&termsize;
ret += SIGWINCH + TIOCGWINSZ + SIGIO;
ret += SIGWINCH + TIOCGWINSZ + SIGIO;
}
return ret;
@@ -739,7 +752,7 @@ AC_CHECK_FUNCS( dcgettext backtrace backtrace_symbols sysconf )
# the translations should be installed.
#
if test x$local_gettext != xno; then
if test x$local_gettext != xno; then
AC_CHECK_FUNC( gettext, HAVE_GETTEXT=1, HAVE_GETTEXT=0 )
fi
@@ -763,22 +776,22 @@ AC_RUN_IFELSE(
#include <stdlib.h>
],
[
int status;
char *res;
res = realpath( "somefile", 0 );
status = !(res != 0 || errno == ENOENT);
int status;
char *res;
res = realpath( "somefile", 0 );
status = !(res != 0 || errno == ENOENT);
exit( status );
]
)
],
[have_realpath_null=yes],
[have_realpath_null=no]
],
[have_realpath_null=yes],
[have_realpath_null=no]
)
if test "$have_realpath_null" = yes; then
AC_MSG_RESULT(yes)
AC_DEFINE(
[HAVE_REALPATH_NULL],
[HAVE_REALPATH_NULL],
[1],
[Define to 1 if realpath accepts null for its second argument.]
)
@@ -805,15 +818,15 @@ AC_LINK_IFELSE(
#endif
],
[
struct winsize termsize = {0};
struct winsize termsize = {0};
TIOCGWINSZ;
]
)
],
],
[
AC_MSG_RESULT(yes);
AC_MSG_RESULT(yes);
AC_DEFINE([HAVE_WINSIZE], [1], [Define to 1 if the winsize struct and TIOCGWINSZ macro exist])
],
],
[
AC_MSG_RESULT(no)
]
@@ -849,7 +862,7 @@ if test "$ac_cv_func_fwprintf" = yes; then
[
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_BROKEN_FWPRINTF], [1], [Define to 1 one if the implemented fwprintf is broken])
]
]
)
fi
@@ -865,19 +878,19 @@ AC_TRY_LINK(
],
[
extern int _nl_msg_cat_cntr;
int tmp = _nl_msg_cat_cntr;
int tmp = _nl_msg_cat_cntr;
exit(tmp);
],
have__nl_msg_cat_cntr=yes,
have__nl_msg_cat_cntr=yes,
have__nl_msg_cat_cntr=no
)
if test "$have__nl_msg_cat_cntr" = yes; then
AC_MSG_RESULT(yes)
AC_DEFINE(
[HAVE__NL_MSG_CAT_CNTR],
[HAVE__NL_MSG_CAT_CNTR],
[1],
[Define to 1 if the _nl_msg_cat_cntr symbol is exported.]
)
)
else
AC_MSG_RESULT(no)
fi
@@ -890,19 +903,19 @@ AC_TRY_LINK(
],
[
extern char **__environ;
char **tmp = __environ;
char **tmp = __environ;
exit(tmp!=0);
],
have___environ=yes,
have___environ=yes,
have___environ=no
)
if test "$have___environ" = yes; then
AC_MSG_RESULT(yes)
AC_DEFINE(
[HAVE___ENVIRON],
[HAVE___ENVIRON],
[1],
[Define to 1 if the __environ symbol is exported.]
)
)
else
AC_MSG_RESULT(no)
fi
@@ -919,26 +932,26 @@ AC_TRY_LINK(
static struct option
long_options[] =
{
0, 0, 0, 0
0, 0, 0, 0
}
;
int opt = getopt_long( 0,
0,
0,
long_options,
0,
long_options,
0 );
],
have_working_getopt_long=yes,
have_working_getopt_long=yes,
have_working_getopt_long=no
)
if test "$have_working_getopt_long" = yes; then
AC_MSG_RESULT(yes)
AC_DEFINE(
[HAVE_WORKING_GETOPT_LONG],
[HAVE_WORKING_GETOPT_LONG],
[1],
[Define to 1 if getopt_long exists and works.]
)
)
else
AC_MSG_RESULT(no)
fi
@@ -970,6 +983,12 @@ if test ! x$local_found_posix_switch = xyes; then
echo "Some fish features may be disabled."
fi
if [[ "$xsel" = "with_xsel" ]]; then
echo "Now configure xsel with $conf_arg"
rm -rf $XSEL
tar xf $XSEL.tar.gz
cd $XSEL && ./configure $conf_arg
fi
echo "fish is now configured."
echo "Use 'make' and 'make install' to build and install fish."

View File

@@ -12,7 +12,7 @@ shells. For other uses, it is recommended to define a <a
href='#function'>function</a>.
Alias does not keep track of which functions have been defined using
alias, nor does it allow erasing of aliases.
alias, nor does it allow erasing of aliases.
- NAME is the name of the function to define
- DEFINITION is the body of the function. The string " $argv" will be appended to the body.

View File

@@ -17,7 +17,7 @@ variable.
\subsection and-example Example
The following code runs the \c make command to build a program, if the
build succceeds, the program is installed. If either step fails,
build succeeds, the program is installed. If either step fails,
<tt>make clean</tt> is run, which removes the files created by the
build process

View File

@@ -37,7 +37,7 @@ In the following code, all output is redirected to the file out.html.
begin
echo $xml_header
echo $html_header
if test -e $file
if test -e $file
...
end
...

View File

@@ -8,9 +8,15 @@
The <tt>bind</tt> builtin causes fish to add a key binding from the specified sequence.
SEQUENCE is the character sequence to bind to. Usually, one would use
fish escape sequences to express them. For example, Alt-w can be
written as <tt>\\ew</tt>, and Control-x can be written as
<tt>\\cx</tt>.
fish escape sequences to express them. For example, because pressing
the Alt key and another character sends that character prefixed with
an escape character, Alt-based key bindings can be written using the
\c \\e escape. For example, Alt-w can be written as
<tt>\\ew</tt>. Control character can be written in much the same way
using the \c \\c escape, for example Control-x can be written as
<tt>\\cx</tt>. Note that Alt-based key bindings are case sensitive and
Control base key bindings are not. This is not a design choice in
fish, it is simply how terminals work.
If SEQUENCE is the empty string, i.e. an empty set of quotes, this is
interpreted as the default keybinding. It will be used whenever no

View File

@@ -19,7 +19,7 @@ regular wildcard expansion using filenames.
Note that fish does not fall through on case statements. Though the
syntax may look a bit like C switch statements, it behaves more like
the case statementes of traditional shells.
the case statements of traditional shells.
Also note that command substitutions in a case statement will be
evaluated even if it's body is not taken. This may seem

View File

@@ -13,9 +13,9 @@
The following switches change what the commandline builtin does
- \c -C or \c --cursor set or get the current cursor position, not
- \c -C or \c --cursor set or get the current cursor position, not
the contents of the buffer. If no argument is given, the current
cursor position is printed, otherwise the argument is interpreted
cursor position is printed, otherwise the argument is interpreted
as the new cursor position.
- \c -f or \c --function inject readline functions into the
reader. This option can not be combined with any other option. It
@@ -44,7 +44,7 @@ or updated
- \c -t or \c --current-token select the current token.
The following switch changes the way \c commandline prints the current
commandline buffer
commandline buffer
- \c -c or \c --cut-at-cursor only print selection up until the
current cursor position

View File

@@ -1,5 +1,5 @@
/** \page commands Commands, functions and builtins bundled with fish
Fish ships with a large number of builtin commands, shellscript functions and external commands. These are all described below.
Fish ships with a large number of builtin commands, shellscript functions and external commands. These are all described below.
@command_list@

View File

@@ -6,7 +6,7 @@
\subsection complete-description Description
For an introduction to how to specify completions, see the section <a
href='index.html#completions-own'>Writing your own completions</a> of
href='index.html#completion-own'>Writing your own completions</a> of
the fish manual.
- <tt>COMMAND</tt> is the name of the command for which to add a completion

View File

@@ -7,8 +7,8 @@ design fish. The fish design has three high level goals. These are:
-# Everything that can be done in other shell languages should be
possible to do in fish, though fish may rely on external commands in
doing so.
-# Fish should be user friendly, but not at the expense of expressiveness.
doing so.
-# Fish should be user friendly, but not at the expense of expressiveness.
Most tradeoffs between power and ease of use can be avoided with careful design.
-# Whenever possible without breaking the above goals, fish should
follow the Posix syntax.
@@ -33,7 +33,7 @@ program harder to maintain and update.
Examples:
- Here documents are too similar to using echo inside of a pipeline.
- Subshells, command substitution and process substitution are strongly related. \c fish only supports command substitution, the others can be achived either using a block or the psub shellscript function.
- Subshells, command substitution and process substitution are strongly related. \c fish only supports command substitution, the others can be achived either using a block or the psub shellscript function.
- Having both aliases and functions is confusing, especially since both of them have limitations and problems. \c fish functions have none of the drawbacks of either syntax.
- The many Posix quoting styles are silly, especially \$''.
@@ -57,14 +57,14 @@ take the whole system down.
Examples:
- Builtin commands should only be created when it cannot be
avoided. \c echo, \c kill, \c printf and \c time are among the commands
that fish does not implement internally since they can be provided as
external commands. Several other commands that are commonly implemented
avoided. \c echo, \c kill, \c printf and \c time are among the commands
that fish does not implement internally since they can be provided as
external commands. Several other commands that are commonly implemented
as builtins and can not be implemented as external commands,
including \c type, \c vared, \c pushd and \c popd are implemented as shellscript
functions in fish.
- Mathematical calculations, regex matching, generating lists of numbers
and many other funtions can easily be done in external programs. They
and many other funtions can easily be done in external programs. They
should not be supported internally by the shell.
The law of minimalism does not imply that a large feature set is
@@ -122,8 +122,8 @@ Examples:
- There should only be one type of input to the shell, lists of commands. Loops, conditionals and variable assignments are all performed through regular commands.
- The differences between builtin commands, shellscript functions and builtin commands should be made as small as possible. Builtins and shellscript functions should have exactly the same types of argument expansion as other commands, should be possible to use in any position in a pipeline, and should support any io redirection.
- Instead of forking when performing command substitution to provide a fake variable scope, all fish commands are performed from the same process, and fish instead supports true scoping
- All blocks end with the \c end builtin
- Instead of forking when performing command substitution to provide a fake variable scope, all fish commands are performed from the same process, and fish instead supports true scoping.
- All blocks end with the \c end builtin.
\section disc The law of discoverability
@@ -147,7 +147,7 @@ until the next time she/he uses the same program.
Examples:
- Everything should be tab-completable, and every tab completion should have a description
- Everything should be tab-completable, and every tab completion should have a description.
- Every syntax error and error in a builtin command should contain an error message describing what went wrong and a relevant help page. Whenever possible, errors should be flagged red by the syntax highlighter.
- The help manual should be easy to read, easily available from the shell, complete and contain many examples
- The language should be uniform, so that once the user understands the command/argument syntax, he will know the whole language, and be able to use tab-completion to discover new featues.

View File

@@ -3,6 +3,6 @@
\subsection dirh-synopsis Synopsis
<tt>dirh</tt>
\subsection dirh-description Description
\subsection dirh-description Description
<tt>dirh</tt> prints the current directory history. The current position in the
history is highlighted using <tt>$fish_color_history_current</tt>.

View File

@@ -3,5 +3,5 @@
\subsection dirs-synopsis Synopsis
<tt>dirs</tt>
\subsection dirs-description Description
\subsection dirs-description Description
<tt>dirs</tt> prints the current directory stack.

View File

@@ -13,5 +13,5 @@ status is 0, the commands COMMANDS_TRUE will execute. If it is not 0 and
The command <tt>if test -f foo.txt; echo foo.txt exists; else; echo foo.txt does not exist; end</tt>
will print <tt>foo.txt exists</tt> if the file foo.txt
exists and is a regular file, otherwise it will print
exists and is a regular file, otherwise it will print
<tt>foo.txt does not exist</tt>.

View File

@@ -5,7 +5,7 @@
\subsection emit-description Description
The emit builtin fires a generic fish event. Such events can be caught by special functions called event handlers.
The emit builtin fires a generic fish event. Such events can be caught by special functions called event handlers.
\subsection emit-example Example

View File

@@ -7,6 +7,7 @@
- <a href='#faq-default'>How do I make fish my default shell?</a>
- <a href='#faq-titlebar'>I'm seeing weird output before each prompt when using screen. What's wrong?</a>
- <a href='#faq-greeting'>How do I change the greeting message?</a>
- <a href='#faq-history'>Why doesn't history substitution ("!$" etc.) work?</a>
<hr>
@@ -32,7 +33,7 @@ parent is ~. This issue is not possible to fix without either making
every single command into a builtin, breaking Unix semantics or
implementing kludges in every single command.
This issue can also be seen when doing IO redirection.
This issue can also be seen when doing IO redirection.
Another related issue is that many programs that operate on recursive
directory trees, like the find command, silently ignore symlinked
@@ -55,9 +56,9 @@ feature, write <code>set CDPATH .</code> on the commandline.
If fish is unable to locate a command with a given name, fish will
test if a directory of that name exists. If it does, it is implicitly
assumed that you want to change working directory. For example, the
fastest way to switch to your home directory is to simply type
<code>~</code>.
assumed that you want to change working directory. For example, the
fastest way to switch to your home directory is to simply press
<code>~</code> and enter.
<hr>
@@ -92,8 +93,8 @@ In order to change your default shell, type:
You may need to adjust the above path to e.g. /usr/bin/fish. Use the command <code>which fish</code> if you are unsure of where fish is installed.
You will need to log out and back in again for the change to take
effect.
Unfortunatly, there is no way to make the changes take effect at once,
you will need to log out and back in again.
<hr>
@@ -104,7 +105,7 @@ Quick answer:
Run the following command in fish:
<pre>
echo function fish_title;end ~/.config/fish/config.fish
echo 'function fish_title;end' &gt; ~/.config/fish/config.fish
</pre>
Problem solved!
@@ -136,5 +137,25 @@ the greeting use:
set fish_greeting
</pre>
<hr>
\section faq-history Why doesn't history substitution ("!$" etc.) work?
Because history substitution is an awkward interface that was invented before
interactive line editing was even possible. Fish drops it in favor of
perfecting the interactive history recall interface. Switching requires a
small change of habits: if you want to modify an old line/word, first recall
it, then edit. E.g. don't type "sudo !!" - first press Up, then Home, then
type "sudo ".
Fish history recall is very simple yet effective:
- As in any modern shell, the Up arrow recalls whole lines, starting from the last line executed. A single press replaces "!!", later presses replace "!-3" and the like.
- If the line you want is far back in the history, type any part of the line and then press Up one or more times. This will constrain the recall to lines that include this text, and you will get to the line you want much faster. This replaces "!vi", "!?bar.c" and the like.
- Alt+Up recalls individual arguments, starting from the last argument in the last line executed. A single press replaces "!$", later presses replace "!!:4" and the like.
- If the argument you want is far back in history (e.g. 2 lines back - that's a lot of words!), type any part of it and then press Alt+Up. This will show only arguments containing that part and you will get what you want much faster. Try it out, this is very convenient!
- If you want to reuse several arguments from the same line ("!!:3*" and the like), consider recalling the whole line and removing what you don't need (Alt+D and Alt+Backspace are your friends).
See <a href='index.html#editor'>documentation</a> for more details about line editing in fish.
*/

View File

@@ -1,15 +1,15 @@
\section fish_indent fish_indent - indenter and prettyfier
\section fish_indent fish_indent - indenter and prettifier
\subsection fish_indent-synopsis Synopsis
<tt>fish_indent [options]</tt>
\subsection fish_indent-description Description
\c fish_indent is used to indent or otherwise prettyfy a piece of fish
\c fish_indent is used to indent or otherwise prettify a piece of fish
code. \c fish_indent reads commands from standard input and outputs
them to standard output.
\c fish_indent underatands the following options:
\c fish_indent understands the following options:
- <tt>-h</tt> or <tt>--help</tt> displays this help message and then exits
- <tt>-i</tt> or <tt>--no-indent</tt> do not indent commands

View File

@@ -1,4 +1,4 @@
\section fish_prompt fish_prompt - define the apperance of the command line promp
\section fish_prompt fish_prompt - define the apperance of the command line prompt
\subsection fish_promt-synopsis Synopsis
<pre>function fish_prompt

View File

@@ -11,7 +11,7 @@ not be executed at all.
\subsection for-example Example
The command
The command
<tt>for i in foo bar baz; echo $i; end</tt>
@@ -21,5 +21,5 @@ would output:
foo
bar
baz
</pre>
</pre>

9
doc_src/funced.txt Normal file
View File

@@ -0,0 +1,9 @@
\section funced funced - edit a function interactively
\subsection funced-synopsis Synopsis
<code>funced NAME</code>
\subsection funced-description Description
Use the funced command to interactively edit the definition of a
function. If there is no function with the name specified, a skeleton function is inserted, if a function exist, the definion will be shown on the command line.

12
doc_src/funcsave.txt Normal file
View File

@@ -0,0 +1,12 @@
\section funcsave funcsave - save the definition of a function to the users autoload directory
\subsection funcsave-synopsis Synopsis
<tt>funcsave FUNCTION_NAME</tt>
\subsection funcsave-description Description
funcsave is used to save the current definition of a function to
a file which will be autoloaded by current and future fish
sessions. This can be useful if you have interactively created a new
function and wish to save it for later use.

View File

@@ -6,6 +6,7 @@
\subsection function-description Description
- <code>-d DESCRIPTION</code> or \c --description=DESCRIPTION is a description of what the function does, suitable as a completion description
- <code>-e</code> or <code>--on-event EVENT_NAME</code> tells fish to run this function when the specified named event is emitted. Fish internally generates named events e.g. when showing the prompt.
- <code>-j PID</code> or <code> --on-job-exit PID</code> tells fish to run this function when the job with group id PID exits. Instead of PID, the string 'caller' can be specified. This is only legal when in a command substitution, and will result in the handler being triggered by the exit of the job which created this command substitution.
- <code>-p PID</code> or <code> --on-process-exit PID</code> tells fish to run this function when the fish child process with process id PID exits
- <code>-s</code> or <code>--on-signal SIGSPEC</code> tells fish to run this function when the signal SIGSPEC is delivered. SIGSPEC can be a signal number, or the signal name, such as SIGHUP (or just HUP)
@@ -26,6 +27,11 @@ will write <code>hello</code> whenever the user enters \c hi.
If the user enters any additional arguments after the function, they
are inserted into the environment <a href="index.html#variables-arrays">variable array</a> argv.
By using one of the event handler switches, a function can be made to run automatically at specific events. The user may generate new events using the <a href='#emit">emit</a> builtin. Fish generates the following named events:
- \c fish_prompt, which is emitted whenever a new fish prompt is about to be displayed
- \c fish_command_not_found, which is emitted whenever a command lookup failed
\subsection function-example Example
<pre>

View File

@@ -8,6 +8,7 @@
This builtin command is used to print or erase functions.
- <code>-a</code> or <code>--all</code> list all functions, even those whose name start with an underscore.
- <code>-c OLDNAME NEWNAME</code> or <code>--copy OLDNAME NEWNAME</code> creates a new function named NEWNAME, using the definition of the OLDNAME function.
- <code>-d DESCRIPTION</code> or <code>--description=DESCRIPTION</code> change the description of this function
- <code>-e</code> or <code>--erase</code> causes the specified functions to be erased.
- <code>-h</code> or <code>--help</code> display a help message and exit
@@ -17,11 +18,14 @@ This builtin command is used to print or erase functions.
The default behavior of \c functions when called with no arguments,
is to print the names and definitions of all defined functions. If any
non-switch parameters are given, only the definition of the specified
functions are printed.
functions are printed.
Automatically loaded functions can not be removed using functions
-e. Either remove the definition file or change the
$fish_function_path variable to remove autoloaded functions.
Function copies, created with -c, will not have any event/signal/on-exit
notifications that the original may have had.
The exit status of the functions builtin is the number functions
specified in the argument list that do not exist.

View File

@@ -8,7 +8,7 @@
<tt>if</tt> will execute the command CONDITION. If the condition's
exit status is 0, the commands COMMANDS_TRUE will execute. If the
exit status is not 0 and <tt>else</tt> is given, COMMANDS_FALSE will
be executed.
be executed.
In order to use the exit status of multiple commands as the condition
of an if block, use <a href="#begin"><tt>begin; ...; end</tt></a> and
@@ -29,5 +29,5 @@ else
end
</pre>
will print <tt>foo.txt exists</tt> if the file foo.txt
exists and is a regular file, otherwise it will print
exists and is a regular file, otherwise it will print
<tt>foo.txt does not exist</tt>.

View File

@@ -59,7 +59,7 @@ Here is a list of some useful commands:
- \c mv, move (rename) files
- \c cp, copy files
- \c open, open files with the default application associated with each filetype
- \c less, list the contents of files
- \c less, list the contents of files
Commands and parameters are separated by the space character
(&nbsp;). Every command ends with either a newline (i.e. by pressing
@@ -135,11 +135,15 @@ these characters, so called escape sequences are provided. These are:
- <code>'\\\<'</code>, escapes the less than character
- <code>'\\\>'</code>, escapes the more than character
- <code>'\\^'</code>, escapes the circumflex character
- <code>'\\&'</code>, escapes the ampersand character
- <code>'\\;'</code>, escapes the semicolon character
- <code>'\\"'</code>, escapes the quote character
- <code>'\\''</code>, escapes the apostrophe character
- <code>'\\x<i>xx</i>'</code>, where <code><i>xx</i></code> is a hexadecimal number, escapes the ascii character with the specified value. For example, \\x9 is the tab character.
- <code>'\\X<i>xx</i>'</code>, where <code><i>xx</i></code> is a hexadecimal number, escapes a byte of data with the specified value. If you are using a mutibyte encoding, this can be used to enter invalid strings. Only use this if you know what you are doing.
- <code>'\\<i>ooo</i>'</code>, where <code><i>ooo</i></code> is an octal number, escapes the ascii character with the specified value. For example, \\011 is the tab character.
- <code>'\\u<i>xxxx</i>'</code>, where <code><i>xxxx</i></code> is a hexadecimal number, escapes the 16-bit unicode character with the specified value. For example, \\u9 is the tab character.
- <code>'\\U<i>xxxxxxxx</i>'</code>, where <code><i>xxxxxxxx</i></code> is a hexadecimal number, escapes the 32-bit unicode character with the specified value. For example, \\U9 is the tab character.
- <code>'\\u<i>xxxx</i>'</code>, where <code><i>xxxx</i></code> is a hexadecimal number, escapes the 16-bit Unicode character with the specified value. For example, \\u9 is the tab character.
- <code>'\\U<i>xxxxxxxx</i>'</code>, where <code><i>xxxxxxxx</i></code> is a hexadecimal number, escapes the 32-bit Unicode character with the specified value. For example, \\U9 is the tab character.
- <code>'\\c<i>x</i>'</code>, where <code><i>x</i></code> is a letter of the alphabet, escapes the control sequence generated by pressing the control key and the specified letter. For example, \\ci is the tab character
\subsection redirects IO redirection
@@ -147,7 +151,7 @@ these characters, so called escape sequences are provided. These are:
Most program use three types of input/output (IO), each represented by
a number called a file descriptor (FD). These are:
- Standard input, FD 0, for reading, defaults to reading from the keyboard.
- Standard input, FD 0, for reading, defaults to reading from the keyboard.
- Standard output, FD 1, for writing, defaults to writing to the screen.
- Standard error, FD 2, for writing errors and warnings, defaults to writing to the screen.
@@ -160,13 +164,13 @@ default through a simple mechanism called a redirection.
An example of a file redirection is <code> echo hello \>output.txt</code>,
which directs the output of the echo command to the file error.txt.
- To redirect standard input, write <code>\<SOURCE_FILE</code>
- To redirect standard output, write <code>\>DESTINATION</code>
- To redirect standard error, write <code>^DESTINATION</code>
- To redirect standard input, write <code>\<SOURCE_FILE</code>
- To redirect standard output, write <code>\>DESTINATION</code>
- To redirect standard error, write <code>^DESTINATION</code>
- To redirect standard output to a file which will be appended, write <code>\>\>DESTINATION_FILE</code>
- To redirect standard error to a file which will be appended, write <code>^^DESTINATION_FILE</code>
- To redirect standard error to a file which will be appended, write <code>^^DESTINATION_FILE</code>
<code>DESTINATION</code> can be one of the following:
<code>DESTINATION</code> can be one of the following:
- A filename. The output will be written to the specified file.
- An ampersand (\&) followed by the number of another file descriptor. The file descriptor will be a duplicate of the specified file descriptor.
@@ -182,7 +186,7 @@ Any FD can be redirected in an arbitrary way by prefixing the
redirection with the number of the FD.
- To redirect input of FD number N, write <code>N\<DESTINATION</code>
- To redirect output of FD number N, write <code>N\>DESTINATION</code>
- To redirect output of FD number N, write <code>N\>DESTINATION</code>
- To redirect output of FD number N to a file which will be appended, write <code>N\>\>DESTINATION_FILE</code>
Example: <code>echo Hello 2\>-</code> and <code>echo Hello ^-</code> are
@@ -230,7 +234,7 @@ Example:
<code>emacs \&</code>
will start the emacs text editor in the background.
will start the emacs text editor in the background.
\subsection syntax-job-control Job control
@@ -306,7 +310,7 @@ a filename consisting of the name of the function plus the suffix
The default value for \$fish_function_path is \c ~/.config/fish/functions
\c /etc/fish/functions \c /usr/share/fish/functions. The exact path
to the last two of these may be slighly different depending on what
to the last two of these may be slightly different depending on what
install path prefix was chosen at configuration time. The rationale
behind having three different directories is that the first one is for
user specific functions, the second one is for system-wide additional
@@ -323,10 +327,10 @@ function already be loaded, i.e. a circular dependency.
\subsection syntax-conditional Conditional execution of code
There are four fish builtins that let you execute commands only if a
specific criterion is met. These builtins are
<a href="commands.html#if">if</a>,
<a href="commands.html#switch">switch</a>,
<a href="commands.html#and">and</a> and
specific criterion is met. These builtins are
<a href="commands.html#if">if</a>,
<a href="commands.html#switch">switch</a>,
<a href="commands.html#and">and</a> and
<a href="commands.html#or">or</a>.
The \c switch command is used to execute one of possibly many blocks
@@ -335,7 +339,7 @@ for <a href="commands.html#switch">switch</a> for more information.
The other conditionals use the <a href='#variables-status'>exit
status</a> of a command to decide if a command or a block of commands
should be executed. See the documentation for
should be executed. See the documentation for
<a href="commands.html#if">if</a>, <a href="commands.html#and">and</a>
and <a href="commands.html#or">or</a> for more information.
@@ -392,13 +396,13 @@ These are the general purpose tab completions that \c fish provides:
of these completions are simple options like the \c -l option for \c
ls, but some are more advanced. The latter include:
- The programs 'man' and 'whatis' show all installed
- The programs 'man' and 'whatis' show all installed
manual pages as completions.
- The 'make' program uses all targets in the Makefile in
- The 'make' program uses all targets in the Makefile in
the current directory as completions.
- The 'mount' command uses all mount points specified in fstab as completions.
- The 'ssh' command uses all hosts that are stored
in the known_hosts file as completions. (see the ssh documentation for more information)
- The 'ssh' command uses all hosts that are stored
in the known_hosts file as completions. (see the ssh documentation for more information)
- The 'su' command uses all users on the system as completions.
- The \c apt-get, \c rpm and \c yum commands use all installed packages as completions.
@@ -415,7 +419,7 @@ this can be specified as <code>complete -c myprog -a 'start
stop'</code>. The argument to the \c -a switch is always a single
string. At completion time, it will be tokenized on spaces and tabs,
and variable expansion, command substitution and other forms of
parameter expansion will take place.
parameter expansion will take place.
Fish has a special syntax to support specifying switches accepted by a
command. The switches \c -s, \c -l and \c -o are used to specify a
@@ -466,11 +470,11 @@ prints a list of all user groups with the groups members as description.
<pre>__fish_complete_pids</pre>
prints a list of all procceses IDs with the command name as description.
prints a list of all processes IDs with the command name as description.
<pre>__fish_complete_suffix SUFFIX</pre>
performs file completion allowing only files ending in SUFFIX. The mimetype database is usded to find a suitable description.
performs file completion allowing only files ending in SUFFIX. The mimetype database is used to find a suitable description.
<pre>__fish_complete_users</pre>
@@ -494,7 +498,7 @@ prints a list of all known network interfaces.
<pre>__fish_print_packages</pre>
prints a list of all installed packages. This function currently handles
debian, rpm and gentoo packages.
Debian, rpm and Gentoo packages.
@@ -509,7 +513,7 @@ of the name of the command to complete and the suffix '.fish'.
The default value for \$fish_complete_path is ~/.config/fish/completions,
/etc/fish/completions and /usr/share/fish/completions. The exact
path to the last two of these may be slighly different depending on
path to the last two of these may be slightly different depending on
what install path prefix was chosen at configuration time. If a
suitable file is found in one of these directories, it will be
automatically loaded and the search will be stopped. The rationale
@@ -519,20 +523,20 @@ completions and the last one is for default fish completions.
If you have written new completions for a common
Unix command, please consider sharing your work by sending it to <a
href='mailto: fish-users@lists.sf.net'>the fish mailinglist</a>.
href='mailto: fish-users@lists.sf.net'>the fish mailing list</a>.
\section expand Parameter expansion (Globbing)
When an argument for a program is given on the commandline, it
undergoes the process of parameter expansion before it is sent on to
the command. Parameter expansion is a powerful set of mechamisms that
the command. Parameter expansion is a powerful set of mechanisms that
allow you to expand the parameter in various ways, including
performing wildcard matching on files, inserting the value of
environment variables into the parameter or even using the output of
another command as a parameter list.
\subsection expand-wildcard Wildcards
\subsection expand-wildcard Wildcards
If a star (*) or a question mark (?) is present in the parameter, \c
fish attempts to match the given parameter to any files in such a
@@ -609,7 +613,7 @@ href="#variables"> Environment variables</a> section.
Example:
<code> echo \$HOME</code> prints the home directory of the current
user.
user.
If you wish to combine environment variables with text, you can
encase the variables within braces to embed a variable inside running
@@ -620,9 +624,8 @@ The {$USER}san syntax might need a bit of an elaboration. Posix
shells allow you to specify a variable name using '$VARNAME' or
'${VARNAME}'. Fish supports the former, and has no support whatsoever
for the latter or anything like it. So what is '{$VARNAME}' then?
Well, '{WHATEVER}' is <a href='#brace'>brace expansion</a>, identical
to that supported by e.g. bash. 'a{b,c}d' -> 'abd acd' works
both in bash and on fish. So '{$VARNAME}' is a bracket-expansion with
Well, '{WHATEVER}' is <a href='#brace'>brace expansion</a>, e.g. 'a{b,c}d' -> 'abd acd'.
So '{$VARNAME}' is a bracket-expansion with
only a single element, i.e. it becomes expanded to '$VARNAME', which
will be variable expanded to the value of the variable 'VARNAME'. So
you might think that the brackets don't actually do anything, and that
@@ -684,12 +687,12 @@ The \% (percent) character at the beginning of a parameter followed by
a string is expanded into a process id. The following expansions are
performed:
- If the string is the entire word \c self, the shells pid is the result
- If the string is the entire word \c self, the shells pid is the result.
- Otherwise, if the string is the id of a job, the result is the process
group id of the job.
- Otherwise, if any child processes match the specified string, their
pids are the result of the expansion.
- Otherwise, if any processes owned by the user match the specified
- Otherwise, if any child processes match the specified string, their
pids are the result of the expansion.
- Otherwise, if any processes owned by the user match the specified
string, their pids are the result of the expansion.
This form of expansion is useful for commands like kill and fg, which
@@ -739,7 +742,7 @@ expansion</a>.
To set a variable value, use the <a href="commands.html#set"> \c set
command</a>.
Example:
Example:
To set the variable \c smurf_color to the value \c blue, use the command
<code>set smurf_color blue</code>.
@@ -749,7 +752,7 @@ the shell through <a href="expand-variable">variable expansion</a>.
Example:
To use the value of a the variable \c smurf, write $ (dollar symbol)
To use the value of the variable \c smurf, write $ (dollar symbol)
followed by the name of the variable, like <code>echo Smurfs are
usually $smurf_color</code>, which would print the result 'Smurfs are
usually blue'.
@@ -868,8 +871,8 @@ echo $PATH[3]
</pre>
Note that array indices start at 1 in fish, not 0, as is more common
in other languages. This is because many common unix tools like seq
are more suited to such use.
in other languages. This is because many common Unix tools like seq
are more suited to such use.
If you do not use any brackets, all the elements of the array will be
written as separate items. This means you can easily iterate over an
@@ -921,14 +924,14 @@ certain environment variables.
\c fish also sends additional information to the user through the
values of certain environment variables. The user can not change the
values of most of these variables.
values of most of these variables.
- \c _, which is the name of the currently running command.
- \c argv, which is an array of arguments to the shell or function. \c argv is only defined when inside a function call, or if fish was invoked with a list of arguments, like 'fish myscript.fish foo bar'. This variable can be changed by the user.
- \c history, which is an array containing the last commands that where entered.
- \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.
- \c PWD, which is the current working directory.
- \c status, which is the exit status of the last foreground job to exit. If the job was terminated through a signal, the exit status will be 128 plus the signal number.
- \c USER, which is the username. This variable can only be changed by the root user.
The names of these variables are mostly derived from the csh family of
@@ -967,6 +970,8 @@ variable may also be set to a specific value:
- 126 means that while a file with the specified name was located, it was not executable
- 127 means that no function, builtin or command with the given name could be located
If a process exits through a signal, the exit status will be 128 plus the number of the signal.
\subsection variables-color Variables for changing highlighting colors
The colors used by fish for syntax highlighting can be configured by
@@ -975,7 +980,7 @@ variables can be one of the colors accepted by the <a
href='commands.html#set_color'>set_color</a> command. The \c --bold
or \c -b switches accepted by \c set_color are also accepted.
The following variables are available to change the highligting colors
The following variables are available to change the highlighting colors
in fish:
- \c fish_color_normal, the default color
@@ -1022,7 +1027,7 @@ variables set the specified aspect of the locale information. LANG
is a fallback value, it will be used if none of the LC_ variables are
specified.
\section builtin-overview Builtins
\section builtin-overview Builtins
Many other shells have a large library of builtin commands. Most of
these commands are also available as standalone commands, but have
@@ -1040,7 +1045,7 @@ switch of the command.
The \c fish editor features copy and paste, a searchable history and
many editor functions that can be bound to special keyboard
shortcuts. The most important keybinding is probably the tab key, which is bound to the complete function.
shortcuts. The most important keybinding is probably the tab key, which is bound to the complete function.
Here are some of the commands available in the editor:
- Tab completes the current token
@@ -1050,7 +1055,7 @@ Here are some of the commands available in the editor:
- Alt-left and Alt-right moves one word left or right, or moves forward/backward in the directory history if the commandline is empty
- Up and down search the command history for the previous/next command containing the string that was specified on the commandline before the search was started. If the commandline was empty when the search started, all commands match. See the <a href='#history'>history </a>section for more information on history searching.
- Alt-up and Alt-down search the command history for the previous/next token containing the token under the cursor before the search was started. If the commandline was not on a token when the search started, all tokens match. See the <a href='#history'>history </a>section for more information on history searching.
- Delete and backspace removes one character forwards or backwards respecitvely
- Delete and backspace removes one character forwards or backwards respectively
- Ctrl-c deletes entire line
- Ctrl-d delete one character to the right of the cursor, unless the buffer is empty, in which case the shell will exit
- Ctrl-k move contents from the cursor to the end of line to the <a href="#killring">killring</a>
@@ -1058,12 +1063,12 @@ Here are some of the commands available in the editor:
- Ctrl-l clear and repaint screen
- Ctrl-w move previous word to the <a href="#killring">killring</a>
- Alt-d move next word to the <a href="#killring">killring</a>
- Alt-w prints a short description of the command under the cursor
- Alt-l lists the contents of the current directory, unless the cursor is over a directory argument, in which case the contents of that directory will be listed
- Alt-w prints a short description of the command under the cursor
- Alt-l lists the contents of the current directory, unless the cursor is over a directory argument, in which case the contents of that directory will be listed
- Alt-p adds the string '| less;' to the end of the job under the cursor. The result is that the output of the command will be paged.
You can change these key bindings using the
<a href="commands.html#bind">bind</a> builtin command.
You can change these key bindings using the
<a href="commands.html#bind">bind</a> builtin command.
- \c backward-char, moves one character to the left
@@ -1094,7 +1099,7 @@ If such a script produces output, the script needs to finish by
calling 'commandline -f repaint' in order to tell fish that a repaint
is in order.
\subsection killring Copy and paste (Kill Ring)
\subsection killring Copy and paste (Kill Ring)
\c fish uses an Emacs style kill ring for copy and paste
functionality. Use Ctrl-K to cut from the current cursor position to
@@ -1105,7 +1110,7 @@ Meta-Y to rotate to the previous kill.
If the environment variable DISPLAY is set, \c fish will try to
connect to the X-windows server specified by this variable, and use
the clipboard on the X server for copying and pasting.
the clipboard on the X server for copying and pasting.
\subsection history Searchable history
@@ -1140,7 +1145,7 @@ than a single line:
- Pressing the enter key while a block of commands is unclosed, i.e. when one or more block commands such as 'for', 'begin' or 'if' do not have a corresponding 'end' command.
- Pressing Alt-enter instead of pressing the enter key.
- By backslash escaping a newline, i.e. by inserting a backslash (\\) character pefore pressing the enter key.
- By backslash escaping a newline, i.e. by inserting a backslash (\\) character before pressing the enter key.
The fish commandline editor works exactly the same in single line mode
and in multiline mode. To move between lines use the left and right
@@ -1156,7 +1161,7 @@ graphical user interface from the terminal, and then be able to
continue using the shell. In such cases, there are several ways in
which the user can change <code>fish</code>'s behavior.
-# By ending a command with the \& (ampersand) symbol, the user tells \c fish to put the specified command into the background. A background process will be run simultaneous with \c fish. \c fish will retain control of the terminal, so the program will not be able to read from the keyboard.
-# By ending a command with the \& (ampersand) symbol, the user tells \c fish to put the specified command into the background. A background process will be run simultaneous with \c fish. \c fish will retain control of the terminal, so the program will not be able to read from the keyboard.
-# By pressing ^Z, the user stops a currently running foreground program and returns control to \c fish. Some programs do not support this feature, or remap it to another key. Gnu emacs uses ^X z to stop running.
-# By using the <a href="commands.html#fg">fg</a> and <a href="commands.html#bg">bg</a> builtin commands, the user can send any currently running job into the foreground or background.
@@ -1241,11 +1246,11 @@ fish_title function is executed before and after a new command is
executed or put into the foreground and the output is used as a
titlebar message. The $_ environment variable will always contain the
name of the job to be put into the foreground (Or 'fish' if control is
returning to the shell) when the fish_prompt function is called.
returning to the shell) when the \c fish_prompt function is called.
Example:
<p>
The default \c fish title is
The default \c fish title is
</p>
<p>
<pre>
@@ -1256,6 +1261,12 @@ end
</pre>
</p>
\subsection greeting Configurable greeting
If a function named fish_greeting exists after initialization, it will
be run when entering interactive mode. Otherwise,if an environment
variable named fish_greeting exists, it will be printed.
\subsection event Event handlers
When defining a new function in fish, it is possible to make it into an
@@ -1266,6 +1277,7 @@ specific event takes place. Events that can trigger a handler currently are:
- When a process or job exits
- When the value of a variable is updated
- When the prompt is about to be shown
- When a command lookup fails
Example:
@@ -1280,9 +1292,9 @@ For more information on how to define new event handlers, see the
documentation for the <a href='commands.html#function'>function</a>
command.
\subsection debuging Debuging fish scripts
\subsection debugging Debugging fish scripts
Fish includes a built in debuger. The debuger allows you to stop
Fish includes a built in debugger. The debugger allows you to stop
execution of a script at an arbitrary point and launch a prompt. This
prompt can then be used to check or change the value of any variables
or perform any shellscript command. To resume normal execution of the
@@ -1290,15 +1302,15 @@ script, simply exit the prompt.
To start the debugger, simply call the builtin command
'breakpoint'. The default action of the TRAP signal is to call this
builtin, so a running script can be debuged by sending it the TRAP
signal. Once in the debuger, it is easy to insert new breakpoints by
builtin, so a running script can be debugged by sending it the TRAP
signal. Once in the debugger, it is easy to insert new breakpoints by
using the funced function to edit the definition of a function.
\section issues Common issues with fish
If you install fish in your home directory, fish will not work
correctly for any other user than yourself. This is because fish needs
its initalization files to function properly. To solve this
its initialization files to function properly. To solve this
problem, either copy the initialization files to each fish users home
directory, or install them in /etc.
@@ -1310,7 +1322,7 @@ making a translation. Currently, only the shell itself can be
translated, a future version of fish should also include translated
manuals.
To make a translation of fish, you will first need the sourcecode,
To make a translation of fish, you will first need the source code,
available from the <a href='http://www.fishshell.org'>fish
homepage</a>. Download the latest version, and then extract it using a
command like <code>tar -zxf fish-VERSION.tar.gz</code>.
@@ -1318,7 +1330,7 @@ command like <code>tar -zxf fish-VERSION.tar.gz</code>.
Next, cd into the newly created fish directory using <code>cd
fish-VERSION</code>.
You will now need to configure the sourcecode using the command
You will now need to configure the source code using the command
<code>./configure</code>. This step might take a while.
Before you continue, you will need to know the ISO 639 language code
@@ -1326,7 +1338,7 @@ of the language you are translating to. These codes can be found <a
href='http://www.w3.org/WAI/ER/IG/ert/iso639.htm'>here</a>. For
example, the language code for Uighur is ug.
Now you have the sourcecode and it is properly configured. Lets start
Now you have the source code and it is properly configured. Lets start
translating. To do this, first create an empty translation table for
the language you wish to translate to by writing <code>make
po/[LANGUAGE CODE].po</code> in the fish terminal. For example, if you
@@ -1346,7 +1358,7 @@ msgstr ""
</pre>
The first line is the English string to translate, the second line
should contain your translation. For example, in swedish the above
should contain your translation. For example, in Swedish the above
might become:
<pre>
@@ -1370,9 +1382,9 @@ href='fish-users@lists.sf.net'>fish-users@lists.sf.net</a>.
\subsection todo-features Missing features
- Complete vi-mode key bindings
- More completions (for example konsole, gnome-terminal,
- More completions (for example konsole, gnome-terminal,
rlogin, rsync, arch, finger, bibtex, aspell, xpdf,
compress, wine, dig, batch,
compress, wine, dig, batch,
g++, javac, java, gcj, lpr, doxygen, whois)
- Undo support
- wait shellscript
@@ -1382,7 +1394,7 @@ g++, javac, java, gcj, lpr, doxygen, whois)
\subsection todo-possible Possible features
- mouse support like zsh has with http://stchaz.free.fr/mouse.zsh
- mouse support like zsh has with http://stchaz.free.fr/mouse.zsh
installed would be awesome
- suggest a completion on unique matches by writing it out in an understated color
- Highlight beginning/end of block when moving over a block command
@@ -1395,12 +1407,11 @@ g++, javac, java, gcj, lpr, doxygen, whois)
- Selectable completions in the pager
- Per process output redirection
- Reduce the space of the pager by one line to allow the commandline to remain visible.
- down-arrow could be used to save the current command to the history. Or give the next command in-sequnce. Or both.
- Drop support for inputrc-files. Use shellscripts and the bind builtin. Also, redo the syntax for the bind builtin to something more sane.
- down-arrow could be used to save the current command to the history. Or give the next command in-sequence. Or both.
- History could reload itself when the file is updated. This would need to be done in a clever way to avoid chain reactions
- The error function should probably be moved into it's own library, and be made mere general purpose.
- The code validation functions should be moved from the parser to parse_util.
- Try to remove more malloc calls to reduce memory usage. The time_t arrays used by the autoloader sound like a good candidate.
- Try to remove more malloc calls to reduce memory usage. The time_t arrays used by the autoloader sound like a good candidate.
- The code validator should warn about unknown commands.
- Auto-newlines
- A fault injector could be written to increase robustness and testing of error recovery paths
@@ -1409,24 +1420,24 @@ g++, javac, java, gcj, lpr, doxygen, whois)
- exec_subshell should be either merged with eval or moved to parser.c
- Don't use expand_string to perform completions. wildcard_complete can be called directly, the brace expansion handling should be universal, and the process expansion can be moved to complete.c.
- Make the history search support incremental searching
- An automatic logout feature
- An automatic logout feature
- Make tab completions completely silent by default, i.e. kill stderr when running completion commands. This needs to be overridalbe for debugging purposes.
- Move history to an environment variable
\subsection bugs Known bugs and issues
- Suspending and then resuming pipelines containing a builtin or a shellscript function is broken. Ideally, the exec function in exec.c should be able to resume execution of a partially executed job.
- delete-word is broken on the commandline 'sudo update-alternatives --config x-'
- Sometimes autoheader needs to be run on a fresh tarball. Fix dates before creating tarballs.
- The completion autoloader does not remember which completions where actually autoloaded, and may unload manually specified completions.
- There have been stray reports of issues with strang values of the PATH variable during startup.
- The completion autoloader does not remember which completions where actually autoloaded, and may unload manually specified completions.
- There have been stray reports of issues with strange values of the PATH variable during startup.
- bindings in config.fish are overwritten by default key bindings.
- Adding 'bind -k ...' doesn't overwrite non-keybinding binds of the same sequence.
- History file does not remove duplicates.
- History file should apply some kind of maximum history length.
- Older versions of Doxygen has bugs in the man-page generation which cause the builtin help to render incorrectly. Version 1.2.14 is known to have this problem.
If you think you have found a bug not described here, please send a
report to <a href="mailto:fish-users@lists.sf.net">fish-users@lists.sf.net</a>.
\subsection issues Known issues
Older versions of Doxygen has bugs in the man-page generation which
cause the builtin help to render incorrectly. Version 1.2.14 is known
to have this problem.
*/

View File

@@ -1,28 +1,11 @@
/** \page license Licenses
Fish Copyright (C) 2005-2006 Axel Liljencrantz. Fish is released under
<h2>License for fish</h2>
Fish Copyright (C) 2005-2009 Axel Liljencrantz. Fish is released under
the GNU General Public License, version 2. The license agreement is
included below.
Fish contains code under the BSD license, namely versions of the
two functions strlcat and strlcpy, modified for use with wide
character strings. This code is copyrighted by Todd C. Miller. The
license agreement is included below.
The XSel command, written and copyrighted by Conrad Parker, is
distributed together with, and used by fish. It is released under the MIT
license. The license agreement is included below.
The xdgmime library, written and copyrighted by Red Hat, Inc, is used
by the mimedb command, which is a part of fish. It is released under
the LGPL. The license agreement is included below.
Fish contains code from the glibc library, namely the wcstok
function. This code is licensed under the LGPL. The license agreement
is included below.
<HR>
<H2><A NAME="SEC1" HREF="gpl.html#TOC1">GNU GENERAL PUBLIC LICENSE</A></H2>
<P>
@@ -31,7 +14,7 @@ Version 2, June 1991
</P>
<PRE>
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
Everyone is permitted to copy and distribute verbatim copies
@@ -464,7 +447,7 @@ PERFORMANCE OF THIS SOFTWARE.
<h2>License for XSel</h2>
The XSel command, written and copyrighted by Conrad Parker, is
distributed together with \c fish.
distributed together with \c fish.
It is Copyright (C) 2001 Conrad Parker <conrad@vergenet.net>
@@ -480,6 +463,18 @@ without express or implied warranty.
<HR>
<h2>License for xdgmime and glibc</h2>
The xdgmime library, written and copyrighted by Red Hat, Inc, is used
by the mimedb command, which is a part of fish. It is released under
the LGPL, version 2 or later, or under the Academic Free License,
version 2. Version 2 of the LGPL license agreement is included below.
Fish contains code from the glibc library, namely the wcstok
function. This code is licensed under the LGPL, version 2 or
later. Version 2 of the LPGL license agreement is included below.
<H2><A NAME="SEC1" HREF="#TOC1">GNU LESSER GENERAL PUBLIC LICENSE</A></H2>
<P>
@@ -807,7 +802,7 @@ of these things:
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
<LI><STRONG>b)</STRONG> Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,

View File

@@ -9,7 +9,7 @@
math is used to perform mathematical calculations. It is only a very
thin wrapper for the bc program, that makes it possible to specify an
expression from the command line without using non-standard extensions
or a pipeline. Simply use a command like <code>math 1+1</code>.
or a pipeline. Simply use a command like <code>math 1+1</code>.
For a description of the syntax supported by math, see the manual for
the bc program. Keep in mind that parameter expansion takes place on

View File

@@ -5,7 +5,7 @@
\subsection mimedb-description Description
- \c FILES is a list of files to analyse
- \c FILES is a list of files to analyse
- \c -t, \c --input-file-data the specified files type should be determined both by their filename and by their contents (Default)
- \c -f, \c --input-filename the specified files type should be determined by their filename
- \c -i, \c --input-mime the arguments are not files but mimetypes

View File

@@ -5,7 +5,7 @@
\subsection not-description Description
The \c not builtin is used to negate the exit status of another command.
The \c not builtin is used to negate the exit status of another command.
\subsection not-example Example

View File

@@ -1,12 +1,12 @@
\section open open - open file in it's default application
\section open open - open file in its default application
\subsection open-synopsis Synopsis
<tt>open FILES...</tt>
\subsection open-description Description
The \c open command is used to open a file in it's default application. \c open is implemented using the <a href="commands.html#mimedb">mimedb</a> command.
The \c open command is used to open a file in its default application. \c open is implemented using the \c xdg-open command if it exists, or else the <a href="commands.html#mimedb">mimedb</a> command.
\subsection open-example Example
<tt>open *.txt</tt> opens all the text files in the current directory using your systems default text editor.
<tt>open *.txt</tt> opens all the text files in the current directory using your system's default text editor.

View File

@@ -17,7 +17,7 @@ variable.
\subsection or-example Example
The following code runs the \c make command to build a program, if the
build succceeds, the program is installed. If either step fails,
build succeeds, the program is installed. If either step fails,
<tt>make clean</tt> is run, which removes the files created by the
build process

View File

@@ -3,6 +3,6 @@
\subsection popd-synopsis Synopsis
<tt>popd</tt>
\subsection popd-description Description
<tt>popd</tt> removes the top directory from the directory stack and
\subsection popd-description Description
<tt>popd</tt> removes the top directory from the directory stack and
cd's to the new top directory.

View File

@@ -3,7 +3,7 @@
\subsection prevd-synopsis Synopsis
<tt>prevd [-l | --list] [pos]</tt>
\subsection prevd-description Description
\subsection prevd-description Description
<tt>prevd</tt> moves backwards <tt>pos</tt> positions in the history
of visited directories; if the beginning of the history has been hit,

View File

@@ -3,7 +3,7 @@
\subsection pushd-synopsis Synopsis
<tt>pushd [DIRECTORY]</tt>
\subsection pushd-description Description
\subsection pushd-description Description
The <tt>pushd</tt> function adds DIRECTORY to the top of the directory stack
and makes it the current directory. Use <tt>popd</tt> to pop it off and and
return to the original directory.

View File

@@ -21,4 +21,4 @@ for i in (seq (random) -1 1)
echo $i
sleep
end
</pre>
</pre>

View File

@@ -6,12 +6,12 @@
\subsection read-description Description
The <tt>read</tt> builtin causes fish to read one line from standard
input and store the result in one or more environment variables.
input and store the result in one or more environment variables.
- <tt>-c CMD</tt> or <tt>--command=CMD</tt> specifies that the initial string in the interactive mode command buffer should be CMD.
- <tt>-e</tt> or <tt>--export</tt> specifies that the variables will be exported to subshells.
- <tt>-g</tt> or <tt>--global</tt> specifies that the variables will be made global.
- <tt>-m NAME</tt> or <tt>--mode-name=NAME</tt> specifies that the name NAME should be used to save/load the history file. If NAME is fish, the regular fish history will be available.
- <tt>-m NAME</tt> or <tt>--mode-name=NAME</tt> specifies that the name NAME should be used to save/load the history file. If NAME is fish, the regular fish history will be available.
- <tt>-p PROMPT_CMD</tt> or <tt>--prompt=PROMPT_CMD</tt> specifies that the output of the shell command PROMPT_CMD should be used as the prompt for the interactive mode prompt. The default prompt command is <tt>set_color green; echo read; set_color normal; echo "> "</tt>.
- <code>-s</code> or <code>--shell</code> Use syntax highlighting, tab completions and command termination suitable for entering shellscript code
- <code>-u</code> or <code>--unexport</code> causes the specified environment not to be exported to child processes

View File

@@ -3,7 +3,7 @@
\subsection return-synopsis Synopsis
<tt>function NAME; [COMMANDS...;] return [STATUS]; [COMMANDS...;] end</tt>
\subsection return-description Description
\subsection return-description Description
The \c return builtin is used to halt a currently running function. It
is usually added inside of a conditional block such as an <a

View File

@@ -1,12 +0,0 @@
\section save_function save_function - save the definition of a function to the users autoload directory
\subsection save_function-synopsis Synopsis
<tt>save_function FUNCTION_NAME</tt>
\subsection save_function-description Description
save_function is used to save the current definition of a function to
a file which will be autoloaded by current and future fish
sessions. This can be useful if you have interactively created a new
function and wish to save it for later use.

View File

@@ -7,7 +7,7 @@
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.
purple, cyan, white and normal.
- \c -b, \c --background Set the background color
- \c -c, \c --print-colors Prints a list of all valid color names
@@ -28,3 +28,9 @@ result in a white font color.
Not all terminal emulators support all these features. This is not a
bug in set_color but a missing feature in the terminal emulator.
set_color uses the terminfo database to look up how to change terminal
colors on whatever terminal is in use. Some systems have old and
incomplete terminfo databases, and may lack color information for
terminals that support it. Download and install the latest version of
ncurses and recompile fish against it in order to fix this issue.

View File

@@ -3,7 +3,7 @@
\subsection source-synopsis Synopsis
<tt>. FILENAME [ARGUMENTS...]</tt>
\subsection source-description Description
\subsection source-description Description
Evaluates the commands of the specified file in the current
shell. This is different from starting a new process to perform the

View File

@@ -14,5 +14,5 @@
- <tt>-f</tt> or <tt>--current-filename</tt> prints the filename of the currently running script
- <tt>-n</tt> or <tt>--current-line-number</tt> prints the line number of the currently running script
- <tt>-j CONTROLTYPE</tt> or <tt>--job-control=CONTROLTYPE</tt> set the job control type. Can be one of: none, full, interactive
- <tt>-t</tt> or <tt>--print-stack-trace</tt>
- <tt>-t</tt> or <tt>--print-stack-trace</tt> prints a stack trace of all function calls on the call stack
- <tt>-h</tt> or <tt>--help</tt> display a help message and exit

View File

@@ -27,7 +27,7 @@ Note that not all these limits are available in all operating systems.
The value of limit can be a number in the unit specified for
the resource or one of the special values hard, soft, or unlimited,
which stand for the current hard limit, the current soft limit, and no
limit, respectively.
limit, respectively.
If limit is given, it is the new value of the specified resource. If
no option is given, then -f is assumed. Values are in kilobytes,
@@ -56,7 +56,7 @@ The fish implementation of ulimit should behave identically to the
implementation in bash, except for these differences:
- Fish ulimit supports GNU-style long options for all switches
- Fish ulimit does not support the -p option for getting the pipe size. The bash implementation consists of a compile-time check that empirically guesses this number by writing to a pipe and waiting for SIGPIPE. Fish does not do this because it this method of determining pipe sixe is unreliable. Depending on bash version, there may also be further additional limits to set in bash that do not exist in fish.
- Fish ulimit does not support the -p option for getting the pipe size. The bash implementation consists of a compile-time check that empirically guesses this number by writing to a pipe and waiting for SIGPIPE. Fish does not do this because it this method of determining pipe size is unreliable. Depending on bash version, there may also be further additional limits to set in bash that do not exist in fish.
- Fish ulimit does not support getting or setting multiple limits in one command, except reporting all values using the -a switch
\subsection ulimit-example Example

View File

@@ -1,4 +1,4 @@
\section vared vared - interactively edit the value of an environment variable
\section vared vared - interactively edit the value of an environment variable
\subsection vared-synopsis Synopsis
<tt>vared VARIABLE_NAME</tt>
@@ -7,7 +7,7 @@
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.
but individual array elements can.
\subsection vared-example Example

496
env.c

File diff suppressed because it is too large Load Diff

13
env.h
View File

@@ -63,7 +63,7 @@ void env_destroy();
/**
Set the value of the environment variable whose name matches key to val.
Set the value of the environment variable whose name matches key to val.
Memory policy: All keys and values are copied, the parameters can and should be freed by the caller afterwards
@@ -79,7 +79,7 @@ void env_destroy();
* ENV_INVALID, the variable name or mode was invalid
*/
int env_set( const wchar_t *key,
int env_set( const wchar_t *key,
const wchar_t *val,
int mode );
@@ -104,7 +104,7 @@ int env_exist( const wchar_t *key, int mode );
/**
Remove environemnt variable
\param key The name of the variable to remove
\param mode should be ENV_USER if this is a remove request from the user, 0 otherwise. If this is a user request, read-only variables can not be removed. The mode may also specify the scope of the variable that should be erased.
@@ -132,4 +132,11 @@ char **env_export_arr( int recalc );
*/
void env_get_names( array_list_t *l, int flags );
/**
Update the PWD variable
directory
*/
int env_set_pwd();
#endif

View File

@@ -83,27 +83,27 @@ static int get_socket( int fork_ok )
{
int s, len;
struct sockaddr_un local;
char *name;
wchar_t *wdir;
wchar_t *wuname;
wchar_t *wuname;
char *dir =0, *uname=0;
get_socket_count++;
wdir = path;
wuname = user;
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
{
wperror(L"socket");
return -1;
}
if( wdir )
dir = wcs2str(wdir );
else
dir = strdup("/tmp");
if( wuname )
uname = wcs2str(wuname );
else
@@ -112,53 +112,53 @@ static int get_socket( int fork_ok )
pw = getpwuid( getuid() );
uname = strdup( pw->pw_name );
}
name = malloc( strlen(dir) +
strlen(uname) +
strlen(SOCK_FILENAME) +
strlen(uname) +
strlen(SOCK_FILENAME) +
2 );
strcpy( name, dir );
strcat( name, "/" );
strcat( name, SOCK_FILENAME );
strcat( name, uname );
free( dir );
free( uname );
debug( 3, L"Connect to socket %s at fd %2", name, s );
local.sun_family = AF_UNIX;
strcpy(local.sun_path, name );
free( name );
len = sizeof(local);
if( connect( s, (struct sockaddr *)&local, len) == -1 )
if( connect( s, (struct sockaddr *)&local, len) == -1 )
{
close( s );
if( fork_ok && start_fishd )
{
debug( 2, L"Could not connect to socket %d, starting fishd", s );
start_fishd();
return get_socket( 0 );
}
debug( 1, L"Could not connect to universal variable server, already tried manual restart (or no command supplied). You will not be able to share variable values between fish sessions. Is fish properly installed?" );
return -1;
}
if( (fcntl( s, F_SETFL, O_NONBLOCK ) != 0) || (fcntl( s, F_SETFD, FD_CLOEXEC ) != 0) )
if( (fcntl( s, F_SETFL, O_NONBLOCK ) != 0) || (fcntl( s, F_SETFD, FD_CLOEXEC ) != 0) )
{
wperror( L"fcntl" );
close( s );
close( s );
return -1;
}
debug( 3, L"Connected to fd %d", s );
return s;
}
@@ -166,7 +166,7 @@ static int get_socket( int fork_ok )
Callback function used whenever a new fishd message is recieved
*/
static void callback( int type, const wchar_t *name, const wchar_t *val )
{
{
if( type == BARRIER_REPLY )
{
barrier_reply = 1;
@@ -174,8 +174,8 @@ static void callback( int type, const wchar_t *name, const wchar_t *val )
else
{
if( external_callback )
external_callback( type, name, val );
}
external_callback( type, name, val );
}
}
/**
@@ -186,21 +186,21 @@ static void check_connection()
{
if( !init )
return;
if( env_universal_server.killme )
{
debug( 3, L"Lost connection to universal variable server." );
if( close( env_universal_server.fd ) )
{
wperror( L"close" );
}
env_universal_server.fd = -1;
env_universal_server.killme=0;
env_universal_server.input.used=0;
env_universal_server.input.used=0;
env_universal_read_all();
}
}
}
/**
@@ -210,10 +210,10 @@ static void env_universal_remove_all()
{
array_list_t lst;
int i;
al_init( &lst );
env_universal_common_get_names( &lst,
env_universal_common_get_names( &lst,
1,
1 );
@@ -224,7 +224,7 @@ static void env_universal_remove_all()
}
al_destroy( &lst );
}
@@ -237,9 +237,9 @@ static void reconnect()
{
if( get_socket_count >= RECONNECT_COUNT )
return;
debug( 3, L"Get new fishd connection" );
init = 0;
env_universal_server.buffer_consumed = env_universal_server.buffer_used = 0;
env_universal_server.fd = get_socket(1);
@@ -252,22 +252,22 @@ static void reconnect()
}
void env_universal_init( wchar_t * p,
wchar_t *u,
void env_universal_init( wchar_t * p,
wchar_t *u,
void (*sf)(),
void (*cb)( int type, const wchar_t *name, const wchar_t *val ))
{
path=p;
user=u;
start_fishd=sf;
start_fishd=sf;
external_callback = cb;
connection_init( &env_universal_server, -1 );
env_universal_server.fd = get_socket(1);
env_universal_common_init( &callback );
env_universal_read_all();
init = 1;
env_universal_read_all();
init = 1;
if( env_universal_server.fd >= 0 )
{
env_universal_barrier();
@@ -285,7 +285,7 @@ void env_universal_destroy()
{
wperror( L"fcntl" );
}
try_send_all( &env_universal_server );
try_send_all( &env_universal_server );
}
connection_destroy( &env_universal_server );
@@ -305,22 +305,22 @@ int env_universal_read_all()
if( env_universal_server.fd == -1 )
{
reconnect();
reconnect();
if( env_universal_server.fd == -1 )
return 0;
return 0;
}
if( env_universal_server.fd != -1 )
{
read_message( &env_universal_server );
check_connection();
check_connection();
return 1;
}
else
{
debug( 2, L"No connection to universal variable server" );
return 0;
}
}
}
wchar_t *env_universal_get( const wchar_t *name )
@@ -329,7 +329,7 @@ wchar_t *env_universal_get( const wchar_t *name )
return 0;
CHECK( name, 0 );
return env_universal_common_get( name );
}
@@ -339,7 +339,7 @@ int env_universal_get_export( const wchar_t *name )
return 0;
CHECK( name, 0 );
return env_universal_common_get_export( name );
}
@@ -366,19 +366,19 @@ void env_universal_barrier()
debug( 3, L"Create barrier" );
while( 1 )
{
try_send_all( &env_universal_server );
check_connection();
try_send_all( &env_universal_server );
check_connection();
if( q_empty( &env_universal_server.unsent ) )
break;
if( env_universal_server.fd == -1 )
{
reconnect();
debug( 2, L"barrier interrupted, exiting" );
return;
return;
}
FD_ZERO( &fds );
FD_SET( env_universal_server.fd, &fds );
select( env_universal_server.fd+1, 0, &fds, 0, 0 );
@@ -394,10 +394,10 @@ void env_universal_barrier()
{
reconnect();
debug( 2, L"barrier interrupted, exiting (2)" );
return;
}
return;
}
FD_ZERO( &fds );
FD_SET( env_universal_server.fd, &fds );
FD_SET( env_universal_server.fd, &fds );
select( env_universal_server.fd+1, &fds, 0, 0, 0 );
env_universal_read_all();
}
@@ -408,12 +408,12 @@ void env_universal_barrier()
void env_universal_set( const wchar_t *name, const wchar_t *value, int export )
{
message_t *msg;
if( !init )
return;
CHECK( name, );
debug( 3, L"env_universal_set( \"%ls\", \"%ls\" )", name, value );
if( is_dead() )
@@ -422,8 +422,8 @@ void env_universal_set( const wchar_t *name, const wchar_t *value, int export )
}
else
{
msg = create_message( export?SET_EXPORT:SET,
name,
msg = create_message( export?SET_EXPORT:SET,
name,
value);
if( !msg )
@@ -431,7 +431,7 @@ void env_universal_set( const wchar_t *name, const wchar_t *value, int export )
debug( 1, L"Could not create universal variable message" );
return;
}
msg->count=1;
q_put( &env_universal_server.unsent, msg );
env_universal_barrier();
@@ -441,18 +441,18 @@ void env_universal_set( const wchar_t *name, const wchar_t *value, int export )
int env_universal_remove( const wchar_t *name )
{
int res;
message_t *msg;
if( !init )
return 1;
CHECK( name, 1 );
res = !env_universal_common_get( name );
debug( 3,
L"env_universal_remove( \"%ls\" )",
name );
if( is_dead() )
{
env_universal_common_remove( name );
@@ -464,7 +464,7 @@ int env_universal_remove( const wchar_t *name )
q_put( &env_universal_server.unsent, msg );
env_universal_barrier();
}
return res;
}
@@ -476,8 +476,8 @@ void env_universal_get_names( array_list_t *l,
return;
CHECK( l, );
env_universal_common_get_names( l,
env_universal_common_get_names( l,
show_exported,
show_unexported );
show_unexported );
}

View File

@@ -40,7 +40,7 @@ int env_universal_get_export( const wchar_t *name );
void env_universal_set( const wchar_t *name, const wchar_t *val, int export );
/**
Erase a universal variable
\return zero if the variable existed, and non-zero if the variable did not exist
*/
int env_universal_remove( const wchar_t *name );
@@ -52,7 +52,7 @@ int env_universal_read_all();
/**
Get the names of all universal variables
\param l the list to insert the names into
\param show_exported whether exported variables should be shown
\param show_unexported whether unexported variables should be shown

View File

@@ -99,7 +99,7 @@ var_uni_entry_t;
static void parse_message( wchar_t *msg,
connection_t *src );
connection_t *src );
/**
The table of all universal variables
@@ -109,8 +109,8 @@ hash_table_t env_universal_var;
/**
Callback function, should be called on all events
*/
void (*callback)( int type,
const wchar_t *key,
void (*callback)( int type,
const wchar_t *key,
const wchar_t *val );
/**
@@ -140,8 +140,8 @@ static char *iconv_utf8_names[]=
*/
static char *iconv_wide_names_unknown[]=
{
"wchar_t", "WCHAR_T",
"wchar", "WCHAR",
"wchar_t", "WCHAR_T",
"wchar", "WCHAR",
0
}
;
@@ -151,12 +151,12 @@ static char *iconv_wide_names_unknown[]=
*/
static char *iconv_wide_names_4[]=
{
"wchar_t", "WCHAR_T",
"wchar", "WCHAR",
"ucs-4", "UCS-4",
"ucs4", "UCS4",
"utf-32", "UTF-32",
"utf32", "UTF32",
"wchar_t", "WCHAR_T",
"wchar", "WCHAR",
"ucs-4", "UCS-4",
"ucs4", "UCS4",
"utf-32", "UTF-32",
"utf32", "UTF32",
0
}
;
@@ -166,18 +166,20 @@ static char *iconv_wide_names_4[]=
*/
static char *iconv_wide_names_2[]=
{
"wchar_t", "WCHAR_T",
"wchar", "WCHAR",
"ucs-2", "UCS-2",
"ucs2", "UCS2",
"utf-16", "UTF-16",
"utf16", "UTF16",
"wchar_t", "WCHAR_T",
"wchar", "WCHAR",
"ucs-2", "UCS-2",
"ucs2", "UCS2",
"utf-16", "UTF-16",
"utf16", "UTF16",
0
}
;
wchar_t *utf2wcs( const char *in )
/**
Convert utf-8 string to wide string
*/
static wchar_t *utf2wcs( const char *in )
{
iconv_t cd=(iconv_t) -1;
int i,j;
@@ -194,7 +196,7 @@ wchar_t *utf2wcs( const char *in )
switch (sizeof (wchar_t))
{
case 2:
to_name = iconv_wide_names_2;
break;
@@ -202,15 +204,15 @@ wchar_t *utf2wcs( const char *in )
case 4:
to_name = iconv_wide_names_4;
break;
default:
to_name = iconv_wide_names_unknown;
break;
}
/*
The line protocol fish uses is always utf-8.
The line protocol fish uses is always utf-8.
*/
char **from_name = iconv_utf8_names;
@@ -218,13 +220,13 @@ wchar_t *utf2wcs( const char *in )
size_t out_len = sizeof( wchar_t )*(in_len+2);
size_t nconv;
char *nout;
out = malloc( out_len );
nout = (char *)out;
if( !out )
return 0;
for( i=0; to_name[i]; i++ )
{
for( j=0; from_name[j]; j++ )
@@ -234,7 +236,7 @@ wchar_t *utf2wcs( const char *in )
if( cd != (iconv_t) -1)
{
goto start_conversion;
}
}
}
@@ -244,23 +246,23 @@ wchar_t *utf2wcs( const char *in )
if (cd == (iconv_t) -1)
{
/* Something went wrong. */
debug( 0, L"Could not perform utf-8 conversion" );
debug( 0, L"Could not perform utf-8 conversion" );
if(errno != EINVAL)
wperror( L"iconv_open" );
/* Terminate the output string. */
free(out);
return 0;
return 0;
}
nconv = iconv( cd, (const char **)&in, &in_len, &nout, &out_len );
nconv = iconv( cd, (char **)&in, &in_len, &nout, &out_len );
if (nconv == (size_t) -1)
{
debug( 0, L"Error while converting from utf string" );
return 0;
}
*((wchar_t *) nout) = L'\0';
/*
@@ -279,19 +281,22 @@ wchar_t *utf2wcs( const char *in )
}
free( out_old );
}
if (iconv_close (cd) != 0)
wperror (L"iconv_close");
return out;
return out;
}
char *wcs2utf( const wchar_t *in )
/**
Convert wide string to utf-8
*/
static char *wcs2utf( const wchar_t *in )
{
iconv_t cd=(iconv_t) -1;
int i,j;
char *char_in = (char *)in;
char *out;
@@ -305,7 +310,7 @@ char *wcs2utf( const wchar_t *in )
switch (sizeof (wchar_t))
{
case 2:
from_name = iconv_wide_names_2;
break;
@@ -313,7 +318,7 @@ char *wcs2utf( const wchar_t *in )
case 4:
from_name = iconv_wide_names_4;
break;
default:
from_name = iconv_wide_names_unknown;
break;
@@ -325,24 +330,24 @@ char *wcs2utf( const wchar_t *in )
size_t out_len = sizeof( char )*( (MAX_UTF8_BYTES*in_len)+1);
size_t nconv;
char *nout;
out = malloc( out_len );
nout = (char *)out;
in_len *= sizeof( wchar_t );
if( !out )
return 0;
for( i=0; to_name[i]; i++ )
{
for( j=0; from_name[j]; j++ )
{
cd = iconv_open ( to_name[i], from_name[j] );
if( cd != (iconv_t) -1)
{
goto start_conversion;
}
}
}
@@ -352,17 +357,17 @@ char *wcs2utf( const wchar_t *in )
if (cd == (iconv_t) -1)
{
/* Something went wrong. */
debug( 0, L"Could not perform utf-8 conversion" );
debug( 0, L"Could not perform utf-8 conversion" );
if(errno != EINVAL)
wperror( L"iconv_open" );
/* Terminate the output string. */
free(out);
return 0;
return 0;
}
nconv = iconv( cd, &char_in, &in_len, &nout, &out_len );
if (nconv == (size_t) -1)
{
@@ -370,13 +375,13 @@ char *wcs2utf( const wchar_t *in )
debug( 0, L"Error while converting from to string" );
return 0;
}
*nout = '\0';
if (iconv_close (cd) != 0)
wperror (L"iconv_close");
return out;
return out;
}
@@ -404,6 +409,9 @@ void env_universal_common_destroy()
hash_destroy( &env_universal_var );
}
/**
Read one byte of date form the specified connection
*/
static int read_byte( connection_t *src )
{
@@ -413,9 +421,9 @@ static int read_byte( connection_t *src )
int res;
res = read( src->fd, src->buffer, ENV_UNIVERSAL_BUFFER_SIZE );
// debug(4, L"Read chunk '%.*s'", res, src->buffer );
if( res < 0 )
{
@@ -424,20 +432,20 @@ static int read_byte( connection_t *src )
{
return ENV_UNIVERSAL_AGAIN;
}
return ENV_UNIVERSAL_ERROR;
}
if( res == 0 )
{
return ENV_UNIVERSAL_EOF;
}
src->buffer_consumed = 0;
src->buffer_used = res;
}
return src->buffer[src->buffer_consumed++];
}
@@ -447,10 +455,10 @@ void read_message( connection_t *src )
{
while( 1 )
{
int ib = read_byte( src );
char b;
switch( ib )
{
case ENV_UNIVERSAL_AGAIN:
@@ -475,43 +483,43 @@ void read_message( connection_t *src )
{
char c = 0;
b_append( &src->input, &c, 1 );
debug( 1,
L"Universal variable connection closed while reading command. Partial command recieved: '%s'",
debug( 1,
L"Universal variable connection closed while reading command. Partial command recieved: '%s'",
(wchar_t *)src->input.buff );
}
return;
}
}
b = (char)ib;
if( b == '\n' )
{
wchar_t *msg;
b = 0;
b_append( &src->input, &b, 1 );
msg = utf2wcs( src->input.buff );
/*
Before calling parse_message, we must empty reset
everything, since the callback function could
potentially call read_message.
*/
src->input.used=0;
if( msg )
{
parse_message( msg, src );
parse_message( msg, src );
}
else
{
debug( 0, _(L"Could not convert message '%s' to wide character string"), src->input.buff );
}
free( msg );
}
else
{
@@ -526,7 +534,7 @@ void read_message( connection_t *src )
void env_universal_common_remove( const wchar_t *name )
{
void *k, *v;
hash_remove( &env_universal_var,
hash_remove( &env_universal_var,
name,
&k,
&v );
@@ -545,7 +553,7 @@ static int match( const wchar_t *msg, const wchar_t *cmd )
if( msg[len] && msg[len]!= L' ' && msg[len] != L'\t' )
return 0;
return 1;
}
@@ -556,20 +564,20 @@ void env_universal_common_set( const wchar_t *key, const wchar_t *val, int expor
CHECK( key, );
CHECK( val, );
entry = malloc( sizeof(var_uni_entry_t) + sizeof(wchar_t)*(wcslen(val)+1) );
entry = malloc( sizeof(var_uni_entry_t) + sizeof(wchar_t)*(wcslen(val)+1) );
name = wcsdup(key);
if( !entry || !name )
DIE_MEM();
entry->export=export;
wcscpy( entry->val, val );
env_universal_common_remove( name );
hash_put( &env_universal_var, name, entry );
if( callback )
{
callback( export?SET_EXPORT:SET, name, val );
@@ -580,67 +588,67 @@ void env_universal_common_set( const wchar_t *key, const wchar_t *val, int expor
/**
Parse message msg
*/
static void parse_message( wchar_t *msg,
static void parse_message( wchar_t *msg,
connection_t *src )
{
// debug( 3, L"parse_message( %ls );", msg );
if( msg[0] == L'#' )
return;
if( match( msg, SET_STR ) || match( msg, SET_EXPORT_STR ))
{
wchar_t *name, *tmp;
int export = match( msg, SET_EXPORT_STR );
name = msg+(export?wcslen(SET_EXPORT_STR):wcslen(SET_STR));
while( wcschr( L"\t ", *name ) )
name++;
tmp = wcschr( name, L':' );
if( tmp )
{
wchar_t *key;
wchar_t *val;
key = malloc( sizeof( wchar_t)*(tmp-name+1));
memcpy( key, name, sizeof( wchar_t)*(tmp-name));
key[tmp-name]=0;
val = tmp+1;
val = unescape( val, 0 );
env_universal_common_set( key, val, export );
free( val );
free( key );
}
else
{
debug( 1, PARSE_ERR, msg );
}
}
}
else if( match( msg, ERASE_STR ) )
{
wchar_t *name, *tmp;
name = msg+wcslen(ERASE_STR);
while( wcschr( L"\t ", *name ) )
name++;
tmp = name;
while( iswalnum( *tmp ) || *tmp == L'_')
tmp++;
*tmp = 0;
if( !wcslen( name ) )
{
debug( 1, PARSE_ERR, msg );
}
env_universal_common_remove( name );
if( callback )
{
callback( ERASE, name, 0 );
@@ -663,7 +671,7 @@ static void parse_message( wchar_t *msg,
else
{
debug( 1, PARSE_ERR, msg );
}
}
}
/**
@@ -676,7 +684,7 @@ static int try_send( message_t *msg,
{
debug( 3,
L"before write of %d chars to fd %d", strlen(msg->body), fd );
L"before write of %d chars to fd %d", strlen(msg->body), fd );
int res = write( fd, msg->body, strlen(msg->body) );
@@ -688,26 +696,26 @@ static int try_send( message_t *msg,
{
debug( 4, L"Failed to write message '%s'", msg->body );
}
if( res == -1 )
{
switch( errno )
{
case EAGAIN:
return 0;
default:
debug( 2,
L"Error while sending universal variable message to fd %d. Closing connection",
fd );
if( debug_level > 2 )
wperror( L"write" );
return -1;
}
}
}
msg->count--;
if( !msg->count )
{
free( msg );
@@ -718,7 +726,7 @@ static int try_send( message_t *msg,
void try_send_all( connection_t *c )
{
/* debug( 3,
L"Send all updates to connection on fd %d",
L"Send all updates to connection on fd %d",
c->fd );*/
while( !q_empty( &c->unsent) )
{
@@ -727,12 +735,12 @@ void try_send_all( connection_t *c )
case 1:
q_get( &c->unsent);
break;
case 0:
debug( 4,
L"Socket full, send rest later" );
L"Socket full, send rest later" );
return;
case -1:
c->killme = 1;
return;
@@ -740,6 +748,9 @@ void try_send_all( connection_t *c )
}
}
/**
Escape specified string
*/
static wchar_t *full_escape( const wchar_t *in )
{
string_buffer_t out;
@@ -768,16 +779,16 @@ static wchar_t *full_escape( const wchar_t *in )
message_t *create_message( int type,
const wchar_t *key_in,
const wchar_t *key_in,
const wchar_t *val_in )
{
message_t *msg=0;
char *key=0;
size_t sz;
// debug( 4, L"Crete message of type %d", type );
if( key_in )
{
if( wcsvarname( key_in ) )
@@ -785,7 +796,7 @@ message_t *create_message( int type,
debug( 0, L"Illegal variable name: '%ls'", key_in );
return 0;
}
key = wcs2utf(key_in);
if( !key )
{
@@ -795,8 +806,8 @@ message_t *create_message( int type,
return 0;
}
}
switch( type )
{
case SET:
@@ -806,29 +817,29 @@ message_t *create_message( int type,
{
val_in=L"";
}
wchar_t *esc = full_escape( val_in );
if( !esc )
break;
char *val = wcs2utf(esc );
free(esc);
sz = strlen(type==SET?SET_MBS:SET_EXPORT_MBS) + strlen(key) + strlen(val) + 4;
msg = malloc( sizeof( message_t ) + sz );
if( !msg )
DIE_MEM();
strcpy( msg->body, (type==SET?SET_MBS:SET_EXPORT_MBS) );
strcat( msg->body, " " );
strcat( msg->body, key );
strcat( msg->body, ":" );
strcat( msg->body, val );
strcat( msg->body, "\n" );
free( val );
break;
}
@@ -839,7 +850,7 @@ message_t *create_message( int type,
if( !msg )
DIE_MEM();
strcpy( msg->body, ERASE_MBS " " );
strcat( msg->body, key );
strcat( msg->body, "\n" );
@@ -848,14 +859,14 @@ message_t *create_message( int type,
case BARRIER:
{
msg = malloc( sizeof( message_t ) +
msg = malloc( sizeof( message_t ) +
strlen( BARRIER_MBS ) +2);
if( !msg )
DIE_MEM();
strcpy( msg->body, BARRIER_MBS "\n" );
break;
}
case BARRIER_REPLY:
{
msg = malloc( sizeof( message_t ) +
@@ -865,7 +876,7 @@ message_t *create_message( int type,
strcpy( msg->body, BARRIER_REPLY_MBS "\n" );
break;
}
default:
{
debug( 0, L"create_message: Unknown message type" );
@@ -879,19 +890,19 @@ message_t *create_message( int type,
// debug( 4, L"Message body is '%s'", msg->body );
return msg;
return msg;
}
/**
Function used with hash_foreach to insert keys of one table into
another
*/
static void add_key_to_hash( void *key,
static void add_key_to_hash( void *key,
void *data,
void *aux )
{
var_uni_entry_t *e = (var_uni_entry_t *)data;
if( ( e->export && get_names_show_exported) ||
if( ( e->export && get_names_show_exported) ||
( !e->export && get_names_show_unexported) )
al_push( (array_list_t *)aux, key );
}
@@ -902,18 +913,18 @@ void env_universal_common_get_names( array_list_t *l,
{
get_names_show_exported = show_exported;
get_names_show_unexported = show_unexported;
hash_foreach2( &env_universal_var,
hash_foreach2( &env_universal_var,
add_key_to_hash,
l );
}
wchar_t *env_universal_common_get( const wchar_t *name )
{
var_uni_entry_t *e = (var_uni_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;
return 0;
}
int env_universal_common_get_export( const wchar_t *name )
@@ -941,17 +952,17 @@ static void enqueue( void *k,
const wchar_t *key = (const wchar_t *)k;
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 );
msg->count=1;
q_put( queue, msg );
}
void enqueue_all( connection_t *c )
{
hash_foreach2( &env_universal_var,
&enqueue,
&enqueue,
(void *)&c->unsent );
try_send_all( c );
}
@@ -963,7 +974,7 @@ void connection_init( connection_t *c, int fd )
c->fd = fd;
b_init( &c->input );
q_init( &c->unsent );
c->buffer_consumed = c->buffer_used = 0;
c->buffer_consumed = c->buffer_used = 0;
}
void connection_destroy( connection_t *c)

View File

@@ -76,9 +76,9 @@ typedef struct connection
newline is encountered, the buffer is parsed and cleared.
*/
buffer_t input;
/**
The read buffer.
The read buffer.
*/
char buffer[ENV_UNIVERSAL_BUFFER_SIZE];
@@ -86,12 +86,12 @@ typedef struct connection
Number of bytes that have already been consumed.
*/
int buffer_consumed;
/**
Number of bytes that have been read into the buffer.
Number of bytes that have been read into the buffer.
*/
int buffer_used;
/**
Link to the next connection
@@ -103,7 +103,7 @@ typedef struct connection
/**
A struct representing a message to be sent between client and server
*/
typedef struct
typedef struct
{
/**
Number of queues that contain this message. Once this reaches zero, the message should be deleted
@@ -163,7 +163,7 @@ void env_universal_common_get_names( array_list_t *l,
void env_universal_common_set( const wchar_t *key, const wchar_t *val, int export );
/**
Remove the specified variable.
Remove the specified variable.
This function operate agains the local copy of all universal
variables, it does not communicate with any other process.

View File

@@ -39,7 +39,7 @@ if status --is-login
end
#
# There are variables that contain colons that are not arrays. This
# There are variables that contain colons that are not arrays. This
# reverts them back to regular strings.
#

193
event.c
View File

@@ -44,11 +44,11 @@ typedef struct
/**
Whether signals have been skipped
*/
int overflow;
int overflow;
/**
Array of signal events
*/
int signal[SIG_UNHANDLED_MAX];
int signal[SIG_UNHANDLED_MAX];
}
signal_list_t;
@@ -95,23 +95,23 @@ static int event_match( event_t *class, event_t *instance )
if( class->type == EVENT_ANY )
return 1;
if( class->type != instance->type )
return 0;
switch( class->type )
{
case EVENT_SIGNAL:
if( class->param1.signal == EVENT_ANY_SIGNAL )
return 1;
return class->param1.signal == instance->param1.signal;
case EVENT_VARIABLE:
return wcscmp( instance->param1.variable,
class->param1.variable )==0;
case EVENT_EXIT:
if( class->param1.pid == EVENT_ANY_PID )
return 1;
@@ -125,11 +125,11 @@ static int event_match( event_t *class, event_t *instance )
class->param1.param )==0;
}
/**
This should never be reached
*/
return 0;
return 0;
}
@@ -140,10 +140,10 @@ static int event_match( event_t *class, event_t *instance )
static event_t *event_copy( event_t *event, int copy_arguments )
{
event_t *e = malloc( sizeof( event_t ) );
if( !e )
DIE_MEM();
memcpy( e, event, sizeof(event_t));
if( e->function_name )
@@ -153,7 +153,7 @@ static event_t *event_copy( event_t *event, int copy_arguments )
e->param1.variable = wcsdup( e->param1.variable );
else if( e->type == EVENT_GENERIC )
e->param1.param = wcsdup( e->param1.param );
al_init( &e->arguments );
if( copy_arguments )
{
@@ -162,9 +162,9 @@ static event_t *event_copy( event_t *event, int copy_arguments )
{
al_push( &e->arguments, wcsdup( (wchar_t *)al_get( &event->arguments, i ) ) );
}
}
return e;
}
@@ -175,7 +175,7 @@ static int event_is_blocked( event_t *e )
{
block_t *block;
event_block_t *eb;
for( block = current_block; block; block = block->outer )
{
for( eb = block->first_event_block; eb; eb=eb->next )
@@ -193,9 +193,9 @@ static int event_is_blocked( event_t *e )
if( eb->type & (1<<e->type) )
return 1;
return 1;
}
return 0;
}
@@ -217,18 +217,18 @@ const wchar_t *event_get_desc( event_t *e )
{
sb_clear( get_desc_buff );
}
switch( e->type )
{
case EVENT_SIGNAL:
sb_printf( get_desc_buff, _(L"signal handler for %ls (%ls)"), sig2wcs(e->param1.signal ), signal_get_desc( e->param1.signal ) );
break;
case EVENT_VARIABLE:
sb_printf( get_desc_buff, _(L"handler for variable '%ls'"), e->param1.variable );
break;
case EVENT_EXIT:
if( e->param1.pid > 0 )
{
@@ -242,9 +242,9 @@ const wchar_t *event_get_desc( event_t *e )
else
sb_printf( get_desc_buff, _(L"exit handler for job with process group %d"), -e->param1.pid );
}
break;
case EVENT_JOB_ID:
{
job_t *j = job_get( e->param1.job_id );
@@ -255,17 +255,17 @@ const wchar_t *event_get_desc( event_t *e )
break;
}
case EVENT_GENERIC:
sb_printf( get_desc_buff, _(L"handler for generic event '%ls'"), e->param1.param );
break;
default:
sb_printf( get_desc_buff, _(L"Unknown event type") );
break;
}
return (const wchar_t *)get_desc_buff->buff;
}
@@ -275,7 +275,7 @@ void event_add_handler( event_t *event )
event_t *e;
CHECK( event, );
e = event_copy( event, 0 );
if( !events )
@@ -285,8 +285,8 @@ void event_add_handler( event_t *event )
{
signal_handle( e->param1.signal, 1 );
}
al_push( events, e );
al_push( events, e );
}
void event_remove( event_t *criterion )
@@ -294,7 +294,7 @@ void event_remove( event_t *criterion )
int i;
array_list_t *new_list=0;
event_t e;
CHECK( criterion, );
/*
@@ -305,19 +305,19 @@ void event_remove( event_t *criterion )
that shouldn't be killed to new_list, and then drops the empty
events-list.
*/
if( !events )
return;
for( i=0; i<al_get_count( events); i++ )
{
event_t *n = (event_t *)al_get( events, i );
event_t *n = (event_t *)al_get( events, i );
if( event_match( criterion, n ) )
{
if( !killme )
killme = al_new();
al_push( killme, n );
al_push( killme, n );
/*
If this event was a signal handler and no other handler handles
@@ -329,11 +329,11 @@ void event_remove( event_t *criterion )
e.type = EVENT_SIGNAL;
e.param1.signal = n->param1.signal;
e.function_name = 0;
if( event_get( &e, 0 ) == 1 )
{
signal_handle( e.param1.signal, 0 );
}
}
}
}
else
@@ -344,7 +344,7 @@ void event_remove( event_t *criterion )
}
}
al_destroy( events );
free( events );
free( events );
events = new_list;
}
@@ -352,21 +352,21 @@ int event_get( event_t *criterion, array_list_t *out )
{
int i;
int found = 0;
if( !events )
return 0;
return 0;
CHECK( criterion, 0 );
for( i=0; i<al_get_count( events); i++ )
{
event_t *n = (event_t *)al_get( events, i );
event_t *n = (event_t *)al_get( events, i );
if( event_match(criterion, n ) )
{
found++;
if( out )
al_push( out, n );
}
}
}
return found;
}
@@ -379,7 +379,7 @@ static void event_free_kills()
int i;
if( !killme )
return;
for( i=0; i<al_get_count( killme ); i++ )
{
event_t *roadkill = (event_t *)al_get( killme, i );
@@ -396,16 +396,16 @@ static int event_is_killed( event_t *e )
int i;
if( !killme )
return 0;
for( i=0; i<al_get_count( killme ); i++ )
{
event_t *roadkill = (event_t *)al_get( events, i );
if( roadkill ==e )
return 1;
}
return 0;
}
}
/**
Perform the specified event. Since almost all event firings will
@@ -418,11 +418,11 @@ static void event_fire_internal( event_t *event )
int i, j;
string_buffer_t *b=0;
array_list_t *fire=0;
/*
First we free all events that have been removed
*/
event_free_kills();
event_free_kills();
if( !events )
return;
@@ -437,7 +437,7 @@ static void event_fire_internal( event_t *event )
for( i=0; i<al_get_count( events ); i++ )
{
event_t *criterion = (event_t *)al_get( events, i );
/*
Check if this event is a match
*/
@@ -448,17 +448,17 @@ static void event_fire_internal( event_t *event )
al_push( fire, criterion );
}
}
/*
No matches. Time to return.
*/
if( !fire )
return;
/*
Iterate over our list of matching events
*/
for( i=0; i<al_get_count( fire ); i++ )
{
event_t *criterion = (event_t *)al_get( fire, i );
@@ -477,19 +477,19 @@ static void event_fire_internal( event_t *event )
b = sb_new();
else
sb_clear( b );
sb_append( b, criterion->function_name );
for( j=0; j<al_get_count(&event->arguments); j++ )
{
wchar_t *arg_esc = escape( (wchar_t *)al_get( &event->arguments, j), 1 );
wchar_t *arg_esc = escape( (wchar_t *)al_get( &event->arguments, j), 1 );
sb_append( b, L" " );
sb_append( b, arg_esc );
free( arg_esc );
free( arg_esc );
}
// debug( 1, L"Event handler fires command '%ls'", (wchar_t *)b->buff );
/*
Event handlers are not part of the main flow of code, so
they are marked as non-interactive
@@ -500,27 +500,27 @@ static void event_fire_internal( event_t *event )
current_block->param1.event = event;
eval( (wchar_t *)b->buff, 0, TOP );
parser_pop_block();
proc_pop_interactive();
proc_pop_interactive();
proc_set_last_status( prev_status );
}
if( b )
{
sb_destroy( b );
free( b );
free( b );
}
if( fire )
{
al_destroy( fire );
free( fire );
}
/*
Free killed events
*/
event_free_kills();
event_free_kills();
}
/**
@@ -532,7 +532,7 @@ static void event_fire_delayed()
int i;
/*
If is_event is one, we are running the event-handler non-recursively.
If is_event is one, we are running the event-handler non-recursively.
When the event handler has called a piece of code that triggers
another event, we do not want to fire delayed events because of
@@ -541,7 +541,7 @@ static void event_fire_delayed()
if( blocked && is_event==1)
{
array_list_t *new_blocked = 0;
for( i=0; i<al_get_count( blocked ); i++ )
{
event_t *e = (event_t *)al_get( blocked, i );
@@ -549,24 +549,24 @@ static void event_fire_delayed()
{
if( !new_blocked )
new_blocked = al_new();
al_push( new_blocked, e );
al_push( new_blocked, e );
}
else
{
event_fire_internal( e );
event_free( e );
}
}
}
al_destroy( blocked );
free( blocked );
blocked = new_blocked;
}
while( sig_list[active_list].count > 0 )
{
signal_list_t *lst;
event_t e;
al_init( &e.arguments );
al_init( &e.arguments );
/*
Switch signal lists
@@ -576,47 +576,47 @@ static void event_fire_delayed()
active_list=1-active_list;
/*
Set up
Set up
*/
e.type=EVENT_SIGNAL;
e.function_name=0;
lst = &sig_list[1-active_list];
if( lst->overflow )
{
debug( 0, _( L"Signal list overflow. Signals have been ignored." ) );
}
/*
Send all signals in our private list
*/
for( i=0; i<lst->count; i++ )
{
e.param1.signal = lst->signal[i];
al_set( &e.arguments, 0, sig2wcs( e.param1.signal ) );
al_set( &e.arguments, 0, sig2wcs( e.param1.signal ) );
if( event_is_blocked( &e ) )
{
if( !blocked )
blocked = al_new();
al_push( blocked, event_copy(&e, 1) );
al_push( blocked, event_copy(&e, 1) );
}
else
{
event_fire_internal( &e );
}
}
al_destroy( &e.arguments );
}
}
}
void event_fire( event_t *event )
{
is_event++;
if( event && (event->type == EVENT_SIGNAL) )
{
/*
@@ -636,14 +636,14 @@ void event_fire( event_t *event )
Fire events triggered by signals
*/
event_fire_delayed();
if( event )
{
if( event_is_blocked( event ) )
{
if( !blocked )
blocked = al_new();
al_push( blocked, event_copy(event, 1) );
}
else
@@ -651,8 +651,8 @@ void event_fire( event_t *event )
event_fire_internal( event );
}
}
}
}
is_event--;
}
@@ -668,7 +668,7 @@ void event_destroy()
{
al_foreach( events, (void (*)(void *))&event_free );
al_destroy( events );
free( events );
free( events );
events=0;
}
@@ -676,9 +676,9 @@ void event_destroy()
{
al_foreach( killme, (void (*)(void *))&event_free );
al_destroy( killme );
free( killme );
killme=0;
}
free( killme );
killme=0;
}
}
void event_free( event_t *e )
@@ -704,19 +704,28 @@ void event_free( event_t *e )
}
void event_fire_generic(const wchar_t *name)
void event_fire_generic_internal(const wchar_t *name, ...)
{
event_t ev;
va_list va;
wchar_t *arg;
CHECK( name, );
ev.type = EVENT_GENERIC;
ev.param1.param = name;
ev.function_name=0;
al_init( &ev.arguments );
va_start( va, name );
while( (arg=va_arg(va, wchar_t *) )!= 0 )
{
al_push( &ev.arguments, arg );
}
va_end( va );
event_fire( &ev );
}

19
event.h
View File

@@ -7,7 +7,7 @@
functions produce output or perform memory allocations, since
such functions may not be safely called by signal handlers.
*/
#ifndef FISH_EVENT_H
#define FISH_EVENT_H
@@ -44,7 +44,7 @@ enum
- When used as a parameter to event_add, it represents a class of events, and function_name is the name of the function which will be called whenever an event matching the specified class occurs. This is also how events are stored internally.
- When used as a parameter to event_get, event_remove and event_fire, it represents a class of events, and if the function_name field is non-zero, only events which call the specified function will be returned.
*/
typedef struct
typedef struct
{
/**
Type of event
@@ -78,13 +78,13 @@ typedef struct
The parameter describing this generic event
*/
const wchar_t *param;
} param1;
/**
The name of the event handler function
*/
const wchar_t *function_name;
const wchar_t *function_name;
/**
The argument list. Only used when sending a new event using
@@ -96,28 +96,28 @@ typedef struct
event_t;
/**
Add an event handler
Add an event handler
May not be called by a signal handler, since it may allocate new memory.
*/
void event_add_handler( event_t *event );
/**
Remove all events matching the specified criterion.
Remove all events matching the specified criterion.
May not be called by a signal handler, since it may free allocated memory.
*/
void event_remove( event_t *event );
/**
Return all events which match the specified event class
Return all events which match the specified event class
This function is safe to call from a signal handler _ONLY_ if the
out parameter is null.
\param criterion Is the class of events to return. If the criterion has a non-null function_name, only events which trigger the specified function will return.
\param out the list to add events to. May be 0, in which case no events will be added, but the result count will still be valid
\return the number of found matches
*/
int event_get( event_t *criterion, array_list_t *out );
@@ -164,7 +164,8 @@ const wchar_t *event_get_desc( event_t *e );
/**
Fire a generic event with the specified name
*/
void event_fire_generic(const wchar_t *name);
#define event_fire_generic( ... ) event_fire_generic_internal( __VA_ARGS__, (void *)0 )
void event_fire_generic_internal(const wchar_t *name,...);
#endif

617
exec.c

File diff suppressed because it is too large Load Diff

4
exec.h
View File

@@ -19,7 +19,7 @@
#define PIPE_ERROR _(L"An error occurred while setting up pipe")
/**
Execute the processes specified by j.
Execute the processes specified by j.
I've put a fair bit of work into making builtins behave like other
programs as far as pipes are concerned. Unlike i.e. bash, builtins
@@ -51,7 +51,7 @@ void exec( job_t *j );
\return the status of the last job to exit, or -1 if en error was encountered.
*/
__warn_unused int exec_subshell( const wchar_t *cmd,
__warn_unused int exec_subshell( const wchar_t *cmd,
array_list_t *l );

223
expand.c
View File

@@ -1,7 +1,7 @@
/**\file expand.c
String expansion functions. These functions perform several kinds of
parameter expansion.
parameter expansion.
*/
@@ -109,11 +109,11 @@ parameter expansion.
/**
Characters which make a string unclean if they are the first
character of the string. See \c is_clean().
character of the string. See \c expand_is_clean().
*/
#define UNCLEAN_FIRST L"~%"
/**
Unclean characters. See \c is_clean().
Unclean characters. See \c expand_is_clean().
*/
#define UNCLEAN L"$*?\\\"'({})"
@@ -195,7 +195,7 @@ wchar_t *expand_escape_variable( const wchar_t *in )
case 0:
sb_append( &buff, L"''");
break;
case 1:
{
wchar_t *el = (wchar_t *)al_get( &l, 0 );
@@ -276,14 +276,14 @@ static int match_pid( const wchar_t *cmd,
int *offset)
{
/* Test for direct match */
if( wcsncmp( cmd, proc, wcslen( proc ) ) == 0 )
{
if( offset )
*offset = 0;
return 1;
}
/*
Test if the commandline is a path to the command, if so we try
to match against only the command part
@@ -313,7 +313,7 @@ static int match_pid( const wchar_t *cmd,
{
if( offset )
*offset = start+1-first_token;
free( first_token );
return 1;
@@ -373,14 +373,14 @@ static int find_process( const wchar_t *proc,
if( wcsncmp( proc, jid, wcslen(proc ) )==0 )
{
string_buffer_t desc_buff;
sb_init( &desc_buff );
sb_printf( &desc_buff,
sb_printf( &desc_buff,
COMPLETE_JOB_DESC_VAL,
j->command );
completion_allocate( out,
completion_allocate( out,
jid+wcslen(proc),
(wchar_t *)desc_buff.buff,
0 );
@@ -395,7 +395,7 @@ static int find_process( const wchar_t *proc,
int jid;
wchar_t *end;
errno = 0;
jid = wcstol( proc, &end, 10 );
if( jid > 0 && !errno && !*end )
@@ -403,7 +403,7 @@ static int find_process( const wchar_t *proc,
j = job_get( jid );
if( (j != 0) && (j->command != 0 ) )
{
{
result = malloc(sizeof(wchar_t)*16 );
swprintf( result, 16, L"%d", j->pgid );
@@ -420,15 +420,15 @@ static int find_process( const wchar_t *proc,
for( j=first_job; j != 0; j=j->next )
{
int offset;
if( j->command == 0 )
continue;
if( match_pid( j->command, proc, flags, &offset ) )
{
if( flags & ACCEPT_INCOMPLETE )
{
completion_allocate( out,
completion_allocate( out,
j->command + offset + wcslen(proc),
COMPLETE_JOB_DESC,
0 );
@@ -456,7 +456,7 @@ static int find_process( const wchar_t *proc,
for( p=j->first_process; p; p=p->next )
{
int offset;
if( p->actual_cmd == 0 )
continue;
@@ -464,7 +464,7 @@ static int find_process( const wchar_t *proc,
{
if( flags & ACCEPT_INCOMPLETE )
{
completion_allocate( out,
completion_allocate( out,
p->actual_cmd + offset + wcslen(proc),
COMPLETE_CHILD_PROCESS_DESC,
0 );
@@ -496,7 +496,7 @@ static int find_process( const wchar_t *proc,
pdir_name = malloc( sizeof(wchar_t)*256 );
pfile_name = malloc( sizeof(wchar_t)*64 );
wcscpy( pdir_name, L"/proc/" );
while( (next=wreaddir(dir))!=0 )
{
wchar_t *name = next->d_name;
@@ -533,7 +533,7 @@ static int find_process( const wchar_t *proc,
signal_block();
fgetws2( &cmd, &sz, cmdfile );
signal_unblock();
fclose( cmdfile );
}
else
@@ -574,12 +574,12 @@ static int find_process( const wchar_t *proc,
if( cmd != 0 )
{
int offset;
if( match_pid( cmd, proc, flags, &offset ) )
{
if( flags & ACCEPT_INCOMPLETE )
{
completion_allocate( out,
completion_allocate( out,
cmd + offset + wcslen(proc),
COMPLETE_PROCESS_DESC,
0 );
@@ -615,7 +615,7 @@ static int expand_pid( wchar_t *in,
CHECK( in, 0 );
CHECK( out, 0 );
if( *in != PROCESS_EXPAND )
{
al_push( out, in );
@@ -626,16 +626,16 @@ static int expand_pid( wchar_t *in,
{
if( wcsncmp( in+1, SELF_STR, wcslen(in+1) )==0 )
{
completion_allocate( out,
completion_allocate( out,
SELF_STR+wcslen(in+1),
COMPLETE_SELF_DESC,
COMPLETE_SELF_DESC,
0 );
}
else if( wcsncmp( in+1, LAST_STR, wcslen(in+1) )==0 )
{
completion_allocate( out,
LAST_STR+wcslen(in+1),
COMPLETE_LAST_DESC,
completion_allocate( out,
LAST_STR+wcslen(in+1),
COMPLETE_LAST_DESC,
0 );
}
}
@@ -692,7 +692,7 @@ static int expand_pid( wchar_t *in,
void expand_variable_error( const wchar_t *token, int token_pos, int error_pos )
{
int stop_pos = token_pos+1;
switch( token[stop_pos] )
{
case BRACKET_BEGIN:
@@ -707,13 +707,13 @@ void expand_variable_error( const wchar_t *token, int token_pos, int error_pos )
{
post = end+1;
*end = 0;
if( !wcsvarname( name ) )
{
is_var = 1;
}
}
if( is_var )
{
error( SYNTAX_ERROR,
@@ -721,7 +721,7 @@ void expand_variable_error( const wchar_t *token, int token_pos, int error_pos )
COMPLETE_VAR_BRACKET_DESC,
cpy,
name,
post );
post );
}
else
{
@@ -733,18 +733,18 @@ void expand_variable_error( const wchar_t *token, int token_pos, int error_pos )
L"" );
}
free( cpy );
break;
}
case INTERNAL_SEPARATOR:
{
error( SYNTAX_ERROR,
error_pos,
COMPLETE_VAR_PARAN_DESC );
COMPLETE_VAR_PARAN_DESC );
break;
}
case 0:
{
error( SYNTAX_ERROR,
@@ -752,7 +752,7 @@ void expand_variable_error( const wchar_t *token, int token_pos, int error_pos )
COMPLETE_VAR_NULL_DESC );
break;
}
default:
{
error( SYNTAX_ERROR,
@@ -764,31 +764,33 @@ void expand_variable_error( const wchar_t *token, int token_pos, int error_pos )
}
}
/**
Parse an array slicing specification
*/
static int parse_slice( wchar_t *in, wchar_t **end_ptr, array_list_t *idx )
{
wchar_t *end;
int pos = 1;
// debug( 0, L"parse_slice on '%ls'", in );
while( 1 )
{
long tmp;
while( iswspace(in[pos]) || (in[pos]==INTERNAL_SEPARATOR))
pos++;
pos++;
if( in[pos] == L']' )
{
pos++;
break;
}
errno=0;
tmp = wcstol( &in[pos], &end, 10 );
if( ( errno ) || ( end == &in[pos] ) )
@@ -796,19 +798,19 @@ static int parse_slice( wchar_t *in, wchar_t **end_ptr, array_list_t *idx )
return 1;
}
// debug( 0, L"Push idx %d", tmp );
al_push_long( idx, tmp );
pos = end-in;
}
if( end_ptr )
{
// debug( 0, L"Remainder is '%ls', slice def was %d characters long", in+pos, pos );
*end_ptr = in+pos;
}
// debug( 0, L"ok, done" );
return 0;
}
@@ -841,7 +843,7 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
CHECK( in, 0 );
CHECK( out, 0 );
if( !var_tmp )
{
var_tmp = sb_halloc( global_context );
@@ -876,7 +878,7 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
wchar_t * new_in;
int is_single = (c==VARIABLE_EXPAND_SINGLE);
int var_name_stop_pos;
stop_pos = start_pos;
while( 1 )
@@ -890,15 +892,15 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
stop_pos++;
}
var_name_stop_pos = stop_pos;
/* printf( "Stop for '%c'\n", in[stop_pos]);*/
var_len = stop_pos - start_pos;
if( var_len == 0 )
{
expand_variable_error( in, stop_pos-1, -1 );
expand_variable_error( in, stop_pos-1, -1 );
is_ok = 0;
break;
}
@@ -917,17 +919,17 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
{
wchar_t *slice_end;
all_vars=0;
if( parse_slice( &in[stop_pos], &slice_end, var_idx_list ) )
{
error( SYNTAX_ERROR,
-1,
L"Invalid index value" );
L"Invalid index value" );
is_ok = 0;
}
}
stop_pos = (slice_end-in);
}
}
if( is_ok )
{
tokenize_variable_array( var_val, &var_item_list );
@@ -972,12 +974,12 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
if( is_ok )
{
if( is_single )
{
string_buffer_t res;
in[i]=0;
sb_init( &res );
sb_append( &res, in );
sb_append_char( &res, INTERNAL_SEPARATOR );
@@ -985,7 +987,7 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
for( j=0; j<al_get_count( &var_item_list); j++ )
{
wchar_t *next = (wchar_t *)al_get( &var_item_list, j );
if( is_ok )
{
if( j != 0 )
@@ -1008,19 +1010,19 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
}
else
{
if( is_ok )
{
new_len = wcslen(in) - (stop_pos-start_pos+1);
new_len += wcslen( next) +2;
if( !(new_in = malloc( sizeof(wchar_t)*new_len )))
{
DIE_MEM();
}
else
{
wcslcpy( new_in, in, start_pos );
if(start_pos>1 && new_in[start_pos-2]!=VARIABLE_EXPAND)
@@ -1030,20 +1032,20 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
}
else
new_in[start_pos-1]=L'\0';
wcscat( new_in, next );
wcscat( new_in, &in[stop_pos] );
is_ok &= expand_variables( new_in, out, i );
}
}
free( next );
}
}
}
}
free(in);
al_destroy( &var_item_list );
return is_ok;
@@ -1114,7 +1116,7 @@ static int expand_brackets( wchar_t *in, int flags, array_list_t *out )
CHECK( in, 0 );
CHECK( out, 0 );
for( pos=in;
(*pos) && !syntax_error;
pos++ )
@@ -1136,7 +1138,7 @@ static int expand_brackets( wchar_t *in, int flags, array_list_t *out )
{
bracket_end = pos;
}
if( bracket_count < 0 )
{
syntax_error = 1;
@@ -1244,12 +1246,12 @@ static int expand_cmdsubst( wchar_t *in, array_list_t *out )
array_list_t *sub_res, *tail_expand;
int i, j;
const wchar_t *item_begin;
wchar_t *tail_begin = 0;
wchar_t *tail_begin = 0;
void *context;
CHECK( in, 0 );
CHECK( out, 0 );
switch( parse_util_locate_cmdsubst(in,
@@ -1279,7 +1281,7 @@ static int expand_cmdsubst( wchar_t *in, array_list_t *out )
sub_res = al_halloc( context );
if( !(subcmd = halloc( context, sizeof(wchar_t)*(paran_end-paran_begin) )))
{
halloc_free( context );
halloc_free( context );
return 0;
}
@@ -1298,10 +1300,10 @@ static int expand_cmdsubst( wchar_t *in, array_list_t *out )
{
array_list_t *slice_idx = al_halloc( context );
wchar_t *slice_end;
if( parse_slice( tail_begin, &slice_end, slice_idx ) )
{
halloc_free( context );
halloc_free( context );
error( SYNTAX_ERROR, -1, L"Invalid index value" );
return 0;
}
@@ -1316,23 +1318,23 @@ static int expand_cmdsubst( wchar_t *in, array_list_t *out )
{
idx = al_get_count( sub_res ) + idx + 1;
}
if( idx < 1 || idx > al_get_count( sub_res ) )
{
halloc_free( context );
error( SYNTAX_ERROR, -1, L"Invalid index value" );
return 0;
}
idx = idx-1;
al_push( sub_res2, al_get( sub_res, idx ) );
// debug( 0, L"Pushing item '%ls' with index %d onto sliced result", al_get( sub_res, idx ), idx );
al_set( sub_res, idx, 0 );
}
al_foreach( sub_res, &free );
sub_res = sub_res2;
sub_res = sub_res2;
}
}
@@ -1369,16 +1371,16 @@ static int expand_cmdsubst( wchar_t *in, array_list_t *out )
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 );
}
free( sub_item2 );
}
free(in);
al_foreach( tail_expand, &free );
halloc_free( context );
halloc_free( context );
return 1;
}
@@ -1479,7 +1481,7 @@ static wchar_t * expand_tilde_internal( wchar_t *in )
wchar_t *expand_tilde( wchar_t *in)
{
CHECK( in, 0 );
if( in[0] == L'~' )
{
in[0] = HOME_DIRECTORY;
@@ -1496,7 +1498,7 @@ static void remove_internal_separator( const void *s, int conv )
{
wchar_t *in = (wchar_t *)s;
wchar_t *out=in;
CHECK( s, );
while( *in )
@@ -1506,7 +1508,7 @@ static void remove_internal_separator( const void *s, int conv )
case INTERNAL_SEPARATOR:
in++;
break;
case ANY_CHAR:
in++;
*out++ = conv?L'?':ANY_CHAR;
@@ -1517,6 +1519,11 @@ static void remove_internal_separator( const void *s, int conv )
*out++ = conv?L'*':ANY_STRING;
break;
case ANY_STRING_RECURSIVE:
in++;
*out++ = conv?L'*':ANY_STRING_RECURSIVE;
break;
default:
*out++ = *in++;
}
@@ -1557,7 +1564,7 @@ int expand_string( void *context,
if( EXPAND_SKIP_CMDSUBST & flags )
{
wchar_t *begin, *end;
if( parse_util_locate_cmdsubst( str,
&begin,
&end,
@@ -1604,7 +1611,7 @@ int expand_string( void *context,
if( !next )
{
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
continue;
continue;
}
if( EXPAND_SKIP_VARIABLES & flags )
@@ -1638,8 +1645,8 @@ int expand_string( void *context,
if( !next )
{
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
continue;
}
continue;
}
if( !expand_brackets( next, flags, out ))
{
@@ -1660,8 +1667,8 @@ int expand_string( void *context,
if( !next )
{
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
continue;
}
continue;
}
if( !(next=expand_tilde_internal( next ) ) )
{
@@ -1712,11 +1719,11 @@ int expand_string( void *context,
if( !next )
{
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
continue;
}
continue;
}
remove_internal_separator( next, EXPAND_SKIP_WILDCARDS & flags );
if( ((flags & ACCEPT_INCOMPLETE) && (!(flags & EXPAND_SKIP_WILDCARDS))) ||
wildcard_has( next, 1 ) )
{
@@ -1738,14 +1745,14 @@ int expand_string( void *context,
{
list = end_out;
}
wc_res = wildcard_expand( rest, start, flags, list );
free( next );
if( !(flags & ACCEPT_INCOMPLETE) )
{
switch( wc_res )
{
case 0:
@@ -1757,7 +1764,7 @@ int expand_string( void *context,
break;
}
}
case 1:
{
int j;
@@ -1770,8 +1777,8 @@ int expand_string( void *context,
if( !next )
{
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
continue;
}
continue;
}
al_push( end_out, next );
}
al_truncate( out, 0 );
@@ -1785,10 +1792,10 @@ int expand_string( void *context,
al_destroy( out );
return EXPAND_ERROR;
}
}
}
}
else
{
@@ -1815,7 +1822,7 @@ int expand_string( void *context,
}
}
return res;
}
@@ -1828,13 +1835,13 @@ wchar_t *expand_one( void *context, wchar_t *string, int flags )
wchar_t *one;
CHECK( string, 0 );
if( (!(flags & ACCEPT_INCOMPLETE)) && expand_is_clean( string ) )
{
halloc_register( context, string );
return string;
}
al_init( &l );
res = expand_string( 0, string, &l, flags );
if( !res )

View File

@@ -6,7 +6,7 @@
benefit from using a more clever memory allocation scheme, perhaps
an evil combination of talloc, string buffers and reference
counting.
*/
#ifndef FISH_EXPAND_H
@@ -58,6 +58,10 @@
Use unencoded private-use keycodes for internal characters
*/
#define EXPAND_RESERVED 0xf000
/**
End of range reserved for expand
*/
#define EXPAND_RESERVED_END 0xf000f
enum
{
@@ -66,7 +70,7 @@ enum
/** Character represeting process expansion */
PROCESS_EXPAND,
/** Character representing variable expansion */
VARIABLE_EXPAND,
@@ -82,7 +86,7 @@ enum
/** Character representing separation between two bracket elements */
BRACKET_SEP,
/**
Separate subtokens in a token with this character.
Separate subtokens in a token with this character.
*/
INTERNAL_SEPARATOR,
@@ -124,7 +128,7 @@ enum
(\$VAR_NAME becomes the value of the environment variable VAR_NAME),
cmdsubst expansion and wildcard expansion. The results are inserted
into the list out.
If the parameter does not need expansion, it is copied into the list
out. If expansion is performed, the original parameter is freed and
newly allocated strings are inserted into the list out.
@@ -132,7 +136,7 @@ enum
If \c context is non-null, all the strings contained in the
array_list_t \c out will be registered to be free'd when context is
free'd.
\param context the halloc context to use for automatic deallocation
\param in The parameter to expand
\param flag Specifies if any expansion pass should be skipped. Legal values are any combination of EXPAND_SKIP_CMDSUBST EXPAND_SKIP_VARIABLES and EXPAND_SKIP_WILDCARDS
@@ -148,8 +152,8 @@ __warn_unused int expand_string( void *context, wchar_t *in, array_list_t *out,
If \c context is non-null, the returning string ill be registered
to be free'd when context is free'd.
\param context the halloc context to use for automatic deallocation
\param context the halloc context to use for automatic deallocation
\param in The parameter to expand
\param flag Specifies if any expansion pass should be skipped. Legal values are any combination of EXPAND_SKIP_CMDSUBST EXPAND_SKIP_VARIABLES and EXPAND_SKIP_WILDCARDS
\return The expanded parameter, or 0 on failiure

View File

@@ -60,7 +60,7 @@ int tputs(const char *str, int affcnt, int (*fish_putc)(tputs_arg_t))
while( *str )
{
fish_putc( *str++ );
}
}
}
#endif
@@ -81,26 +81,26 @@ char *tparm_solaris_kludge( char *str, ... )
if( ( set_a_foreground && ! strcmp( str, set_a_foreground ) )
|| ( set_a_background && ! strcmp( str, set_a_background ) )
|| ( set_foreground && ! strcmp( str, set_foreground ) )
|| ( set_foreground && ! strcmp( str, set_foreground ) )
|| ( set_background && ! strcmp( str, set_background ) )
|| ( enter_underline_mode && ! strcmp( str, enter_underline_mode ) )
|| ( exit_underline_mode && ! strcmp( str, exit_underline_mode ) )
|| ( enter_standout_mode && ! strcmp( str, enter_standout_mode ) )
|| ( exit_standout_mode && ! strcmp( str, exit_standout_mode ) )
|| ( flash_screen && ! strcmp( str, flash_screen ) )
|| ( enter_subscript_mode && ! strcmp( str, enter_subscript_mode ) )
|| ( exit_subscript_mode && ! strcmp( str, exit_subscript_mode ) )
|| ( enter_superscript_mode && ! strcmp( str, enter_superscript_mode ) )
|| ( exit_superscript_mode && ! strcmp( str, exit_superscript_mode ) )
|| ( enter_blink_mode && ! strcmp( str, enter_blink_mode ) )
|| ( enter_italics_mode && ! strcmp( str, enter_italics_mode ) )
|| ( exit_italics_mode && ! strcmp( str, exit_italics_mode ) )
|| ( enter_reverse_mode && ! strcmp( str, enter_reverse_mode ) )
|| ( enter_shadow_mode && ! strcmp( str, enter_shadow_mode ) )
|| ( exit_shadow_mode && ! strcmp( str, exit_shadow_mode ) )
|| ( enter_standout_mode && ! strcmp( str, enter_standout_mode ) )
|| ( exit_standout_mode && ! strcmp( str, exit_standout_mode ) )
|| ( enter_secure_mode && ! strcmp( str, enter_secure_mode ) )
|| ( enter_underline_mode && ! strcmp( str, enter_underline_mode ) )
|| ( exit_underline_mode && ! strcmp( str, exit_underline_mode ) )
|| ( enter_standout_mode && ! strcmp( str, enter_standout_mode ) )
|| ( exit_standout_mode && ! strcmp( str, exit_standout_mode ) )
|| ( flash_screen && ! strcmp( str, flash_screen ) )
|| ( enter_subscript_mode && ! strcmp( str, enter_subscript_mode ) )
|| ( exit_subscript_mode && ! strcmp( str, exit_subscript_mode ) )
|| ( enter_superscript_mode && ! strcmp( str, enter_superscript_mode ) )
|| ( exit_superscript_mode && ! strcmp( str, exit_superscript_mode ) )
|| ( enter_blink_mode && ! strcmp( str, enter_blink_mode ) )
|| ( enter_italics_mode && ! strcmp( str, enter_italics_mode ) )
|| ( exit_italics_mode && ! strcmp( str, exit_italics_mode ) )
|| ( enter_reverse_mode && ! strcmp( str, enter_reverse_mode ) )
|| ( enter_shadow_mode && ! strcmp( str, enter_shadow_mode ) )
|| ( exit_shadow_mode && ! strcmp( str, exit_shadow_mode ) )
|| ( enter_standout_mode && ! strcmp( str, enter_standout_mode ) )
|| ( exit_standout_mode && ! strcmp( str, exit_standout_mode ) )
|| ( enter_secure_mode && ! strcmp( str, enter_secure_mode ) )
|| ( enter_bold_mode && ! strcmp ( str, enter_bold_mode ) ) )
{
param[0] = va_arg( ap, long int );
@@ -140,11 +140,11 @@ char *tparm_solaris_kludge( char *str, ... )
*/
static void pad( void (*writer)(wchar_t), int count)
{
int i;
if( count < 0 )
return;
for( i=0; i<count; i++ )
{
writer( L' ' );
@@ -171,13 +171,13 @@ static void pad( void (*writer)(wchar_t), int count)
For a full description on the usage of *printf, see use 'man 3 printf'.
*/
static int vgwprintf( void (*writer)(wchar_t),
const wchar_t *filter,
static int vgwprintf( void (*writer)(wchar_t),
const wchar_t *filter,
va_list va )
{
const wchar_t *filter_org=filter;
int count=0;
for( ;*filter; filter++)
{
if(*filter == L'%')
@@ -188,19 +188,19 @@ static int vgwprintf( void (*writer)(wchar_t),
int loop=1;
int precision=-1;
int pad_left = 1;
if( iswdigit( *filter ) )
{
width=0;
while( (*filter >= L'0') && (*filter <= L'9'))
{
width=10*width+(*filter++ - L'0');
}
}
}
while( loop )
{
switch(*filter)
{
case L'l':
@@ -219,9 +219,9 @@ static int vgwprintf( void (*writer)(wchar_t),
filter++;
pad_left=0;
break;
case L'.':
/*
/*
Set precision.
*/
filter++;
@@ -235,10 +235,10 @@ static int vgwprintf( void (*writer)(wchar_t),
while( (*filter >= L'0') && (*filter <= L'9'))
{
precision=10*precision+(*filter++ - L'0');
}
}
}
break;
default:
loop=0;
break;
@@ -253,8 +253,8 @@ static int vgwprintf( void (*writer)(wchar_t),
if( (width >= 0) && pad_left )
{
pad( writer, width-1 );
count += maxi( width-1, 0 );
pad( writer, width-1 );
count += maxi( width-1, 0 );
}
c = is_long?va_arg(va, wint_t):btowc(va_arg(va, int));
@@ -265,16 +265,16 @@ static int vgwprintf( void (*writer)(wchar_t),
if( (width >= 0) && !pad_left )
{
pad( writer, width-1 );
count += maxi( width-1, 0 );
count += maxi( width-1, 0 );
}
count++;
break;
}
case L's':
{
{
wchar_t *ss=0;
if( is_long )
{
@@ -287,41 +287,41 @@ static int vgwprintf( void (*writer)(wchar_t),
if( ns )
{
ss = str2wcs( ns );
}
}
}
if( !ss )
{
return -1;
}
if( (width >= 0) && pad_left )
{
pad( writer, width-wcslen(ss) );
count += maxi(width-wcslen(ss), 0);
pad( writer, width-wcslen(ss) );
count += maxi(width-wcslen(ss), 0);
}
wchar_t *s=ss;
int precount = count;
while( *s )
{
if( (precision > 0) && (precision <= (count-precount) ) )
break;
writer( *(s++) );
count++;
}
if( (width >= 0) && !pad_left )
{
pad( writer, width-wcslen(ss) );
count += maxi( width-wcslen(ss), 0 );
pad( writer, width-wcslen(ss) );
count += maxi( width-wcslen(ss), 0 );
}
if( !is_long )
free( ss );
break;
}
@@ -336,7 +336,7 @@ static int vgwprintf( void (*writer)(wchar_t),
char *pos;
char format[16];
int len;
format[0]=0;
strcat( format, "%");
if( precision >= 0 )
@@ -350,7 +350,7 @@ static int vgwprintf( void (*writer)(wchar_t),
strcat( format, "l" );
break;
}
len = strlen(format);
format[len++]=(char)*filter;
format[len]=0;
@@ -360,7 +360,7 @@ static int vgwprintf( void (*writer)(wchar_t),
case L'd':
case L'i':
{
switch( is_long )
{
case 0:
@@ -370,10 +370,10 @@ static int vgwprintf( void (*writer)(wchar_t),
snprintf( str, 32, format, precision, d );
else
snprintf( str, 32, format, d );
break;
}
case 1:
{
long d = va_arg( va, long );
@@ -383,7 +383,7 @@ static int vgwprintf( void (*writer)(wchar_t),
snprintf( str, 32, format, d );
break;
}
case 2:
{
long long d = va_arg( va, long long );
@@ -393,21 +393,21 @@ static int vgwprintf( void (*writer)(wchar_t),
snprintf( str, 32, format, d );
break;
}
default:
debug( 0, L"Invalid length modifier in string %ls\n", filter_org );
return -1;
}
break;
}
case L'u':
case L'o':
case L'x':
case L'X':
{
switch( is_long )
{
case 0:
@@ -419,7 +419,7 @@ static int vgwprintf( void (*writer)(wchar_t),
snprintf( str, 32, format, d );
break;
}
case 1:
{
unsigned long d = va_arg( va, unsigned long );
@@ -429,7 +429,7 @@ static int vgwprintf( void (*writer)(wchar_t),
snprintf( str, 32, format, d );
break;
}
case 2:
{
unsigned long long d = va_arg( va, unsigned long long );
@@ -439,43 +439,43 @@ static int vgwprintf( void (*writer)(wchar_t),
snprintf( str, 32, format, d );
break;
}
default:
debug( 0, L"Invalid length modifier in string %ls\n", filter_org );
return -1;
}
break;
}
default:
debug( 0, L"Invalid filter %ls in string %ls\n", *filter, filter_org );
return -1;
}
if( (width >= 0) && pad_left )
{
int l = maxi(width-strlen(str), 0 );
pad( writer, l );
count += l;
}
pos = str;
while( *pos )
{
writer( *(pos++) );
count++;
}
if( (width >= 0) && !pad_left )
{
int l = maxi(width-strlen(str), 0 );
pad( writer, l );
count += l;
}
break;
}
@@ -484,7 +484,7 @@ static int vgwprintf( void (*writer)(wchar_t),
char str[32];
char *pos;
double val = va_arg( va, double );
if( precision>= 0 )
{
if( width>= 0 )
@@ -509,21 +509,21 @@ static int vgwprintf( void (*writer)(wchar_t),
}
pos = str;
while( *pos )
{
writer( *(pos++) );
count++;
}
break;
}
case L'n':
{
int *n = va_arg( va, int *);
*n = count;
*n = count;
break;
}
case L'%':
@@ -564,14 +564,14 @@ sw_data;
static void sw_writer( wchar_t c )
{
if( sw_data.count < sw_data.max )
*(sw_data.pos++)=c;
*(sw_data.pos++)=c;
sw_data.count++;
}
int vswprintf( wchar_t *out, size_t n, const wchar_t *filter, va_list va )
{
int written;
sw_data.pos=out;
sw_data.max=n;
sw_data.count=0;
@@ -586,7 +586,7 @@ int vswprintf( wchar_t *out, size_t n, const wchar_t *filter, va_list va )
{
written=-1;
}
return written;
}
@@ -594,7 +594,7 @@ int swprintf( wchar_t *out, size_t n, const wchar_t *filter, ... )
{
va_list va;
int written;
va_start( va, filter );
written = vswprintf( out, n, filter, va );
va_end( va );
@@ -624,7 +624,7 @@ int fwprintf( FILE *f, const wchar_t *filter, ... )
{
va_list va;
int written;
va_start( va, filter );
written = vfwprintf( f, filter, va );
va_end( va );
@@ -640,7 +640,7 @@ int wprintf( const wchar_t *filter, ... )
{
va_list va;
int written;
va_start( va, filter );
written=vwprintf( filter, va );
va_end( va );
@@ -661,16 +661,16 @@ wint_t fgetwc(FILE *stream)
{
int b = fgetc( stream );
char bb;
int sz;
if( b == EOF )
return WEOF;
bb=b;
sz = mbrtowc( &res, &bb, 1, &state );
switch( sz )
{
case -1:
@@ -733,13 +733,13 @@ static size_t fish_wcsspn (const wchar_t *wcs,
for (a = accept; *a != L'\0'; ++a)
if (*p == *a)
break;
if (*a == L'\0')
return count;
else
++count;
}
return count;
return count;
}
/*
@@ -752,7 +752,7 @@ static wchar_t *fish_wcspbrk (const wchar_t *wcs, const wchar_t *accept)
++wcs;
else
return (wchar_t *) wcs;
return NULL;
return NULL;
}
/*
@@ -775,18 +775,18 @@ wchar_t *wcstok(wchar_t *wcs, const wchar_t *delim, wchar_t **save_ptr)
/* Scan leading delimiters. */
wcs += fish_wcsspn (wcs, delim);
if (*wcs == L'\0')
{
*save_ptr = NULL;
*save_ptr = NULL;
return NULL;
}
/* Find the end of the token. */
result = wcs;
wcs = fish_wcspbrk (result, delim);
if (wcs == NULL)
{
/* This token finishes the string. */
@@ -815,7 +815,7 @@ wchar_t *wcsdup( const wchar_t *in )
memcpy( out, in, sizeof( wchar_t)*(len+1));
return out;
}
#endif
@@ -855,7 +855,7 @@ int wcsncasecmp( const wchar_t *a, const wchar_t *b, int count )
{
if( count == 0 )
return 0;
if( *a == 0 )
{
return (*b==0)?0:-1;
@@ -892,7 +892,7 @@ wchar_t *wcsndup( const wchar_t *in, int c )
return 0;
}
wcslcpy( res, in, c+1 );
return res;
return res;
}
#endif
@@ -905,22 +905,22 @@ long convert_digit( wchar_t d, int base )
}
else if( (d <= L'z') && (d >= L'a') )
{
res = d + 10 - L'a';
res = d + 10 - L'a';
}
else if( (d <= L'Z') && (d >= L'A') )
{
res = d + 10 - L'A';
res = d + 10 - L'A';
}
if( res >= base )
{
res = -1;
}
return res;
}
#ifndef HAVE_WCSTOL
long wcstol(const wchar_t *nptr,
long wcstol(const wchar_t *nptr,
wchar_t **endptr,
int base)
{
@@ -943,7 +943,7 @@ long wcstol(const wchar_t *nptr,
{
errno = EINVAL;
}
return res;
return res;
}
res = (res*base)+nxt;
is_set = 1;
@@ -985,25 +985,25 @@ long wcstol(const wchar_t *nptr,
size_t
wcslcat(wchar_t *dst, const wchar_t *src, size_t siz)
{
register wchar_t *d = dst;
register const wchar_t *s = src;
register size_t n = siz;
register size_t n = siz;
size_t dlen;
/* Find the end of dst and adjust bytes left but don't go past end */
while (n-- != 0 && *d != '\0')
d++;
dlen = d - dst;
n = siz - dlen;
n = siz - dlen;
if (n == 0)
return(dlen + wcslen(s));
while (*s != '\0')
while (*s != '\0')
{
if (n != 1)
if (n != 1)
{
*d++ = *s;
n--;
@@ -1043,12 +1043,12 @@ wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz)
register wchar_t *d = dst;
register const wchar_t *s = src;
register size_t n = siz;
/* Copy as many bytes as will fit */
if (n != 0 && --n != 0)
{
do
{
if (n != 0 && --n != 0)
{
do
{
if ((*d++ = *s++) == 0)
break;
}
@@ -1056,8 +1056,8 @@ wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz)
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0)
{
if (n == 0)
{
if (siz != 0)
*d = '\0';
/* NUL-terminate dst */
@@ -1074,7 +1074,7 @@ wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz)
int lrand48_r(struct drand48_data *buffer, long int *result)
{
*result = rand_r( &buffer->seed );
*result = rand_r( &buffer->seed );
return 0;
}
@@ -1143,10 +1143,10 @@ int killpg( int pgr, int sig )
#ifndef HAVE_WORKING_GETOPT_LONG
int getopt_long( int argc,
int getopt_long( int argc,
char * const argv[],
const char *optstring,
const struct option *longopts,
const struct option *longopts,
int *longindex )
{
return getopt( argc, argv, optstring );
@@ -1181,7 +1181,14 @@ long sysconf(int name)
}
return -1;
}
}
#endif
#ifndef HAVE_NAN
double nan(char *tagp)
{
return 0.0/0.0;
}
#endif

View File

@@ -54,9 +54,18 @@ typedef char tputs_arg_t;
#endif
#ifndef HAVE_WINSIZE
struct winsize
/**
Structure used to get the size of a terminal window
*/
struct winsize
{
unsigned short ws_row;
/**
Number of rows
*/
unsigned short ws_row;
/**
Number of columns
*/
unsigned short ws_col;
}
;
@@ -184,7 +193,7 @@ wchar_t *wcstok(wchar_t *wcs, const wchar_t *delim, wchar_t **ptr);
/**
Return the number of columns used by a character. This is a libc
function, but the prototype for this function is missing in some libc
implementations.
implementations.
Fish has a fallback implementation in case the implementation is
missing altogether. In locales without a native wcwidth, Unicode
@@ -311,7 +320,7 @@ size_t wcslcat( wchar_t *dst, const wchar_t *src, size_t siz );
wcslen(src); if retval >= siz, truncation occurred.
This is the OpenBSD strlcpy function, modified for wide characters,
and renamed to reflect this change.
and renamed to reflect this change.
*/
size_t wcslcpy( wchar_t *dst, const wchar_t *src, size_t siz );
@@ -381,7 +390,7 @@ char * textdomain( const char * domainname );
/**
Fallback implementation of dcgettext. Just returns the original string.
*/
char * dcgettext ( const char * domainname,
char * dcgettext ( const char * domainname,
const char * msgid,
int category );
@@ -400,18 +409,36 @@ extern int _nl_msg_cat_cntr;
#ifndef HAVE_KILLPG
/**
Send specified signal to specified process group.
*/
int killpg( int pgr, int sig );
#endif
#ifndef HAVE_WORKING_GETOPT_LONG
struct option
/**
Struct describing a long getopt option
*/
struct option
{
/**
Name of option
*/
const char *name;
/**
Flag
*/
int has_arg;
/**
Flag
*/
int *flag;
int val;
/**
Return value
*/
int val;
}
;
@@ -427,10 +454,10 @@ struct option
#define optional_argument 2
#endif
int getopt_long(int argc,
int getopt_long(int argc,
char * const argv[],
const char *optstring,
const struct option *longopts,
const struct option *longopts,
int *longindex);
#endif
@@ -442,4 +469,9 @@ long sysconf(int name);
#endif
#ifndef HAVE_NAN
double nan(char *tagp);
#endif
#endif

141
fish.c
View File

@@ -66,7 +66,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/**
The string describing the single-character options accepted by the main fish binary
*/
#define GETOPT_STRING "hilnvc:p:d:"
#define GETOPT_STRING "+hilnvc:p:d:"
/**
Parse init files
@@ -80,7 +80,7 @@ static int read_init()
eval( L"builtin . " DATADIR "/fish/config.fish 2>/dev/null", 0, TOP );
eval( L"builtin . " SYSCONFDIR L"/fish/config.fish 2>/dev/null", 0, TOP );
/*
We need to get the configuration directory before we can source the user configuration file
*/
@@ -99,99 +99,98 @@ static int read_init()
eval( (wchar_t *)eval_buff->buff, 0, TOP );
free( config_dir_escaped );
}
halloc_free( context );
return 1;
}
/*
/**
Parse the argument list, return the index of the first non-switch
arguments.
*/
static int fish_parse_opt( int argc, char **argv, char **cmd_ptr )
{
int my_optind;
int force_interactive=0;
while( 1 )
{
static struct option
long_options[] =
{
{
"command", required_argument, 0, 'c'
"command", required_argument, 0, 'c'
}
,
{
"debug-level", required_argument, 0, 'd'
"debug-level", required_argument, 0, 'd'
}
,
{
"interactive", no_argument, 0, 'i'
"interactive", no_argument, 0, 'i'
}
,
{
"login", no_argument, 0, 'l'
"login", no_argument, 0, 'l'
}
,
{
"no-execute", no_argument, 0, 'n'
"no-execute", no_argument, 0, 'n'
}
,
{
"profile", required_argument, 0, 'p'
"profile", required_argument, 0, 'p'
}
,
{
"help", no_argument, 0, 'h'
"help", no_argument, 0, 'h'
}
,
{
"version", no_argument, 0, 'v'
"version", no_argument, 0, 'v'
}
,
{
0, 0, 0, 0
{
0, 0, 0, 0
}
}
;
int opt_index = 0;
int opt = getopt_long( argc,
argv,
argv,
GETOPT_STRING,
long_options,
long_options,
&opt_index );
if( opt == -1 )
break;
switch( opt )
{
case 0:
{
break;
}
case 'c':
case 'c':
{
*cmd_ptr = optarg;
*cmd_ptr = optarg;
is_interactive_session = 0;
break;
}
case 'd':
case 'd':
{
char *end;
int tmp;
errno = 0;
tmp = strtol(optarg, &end, 10);
if( tmp >= 0 && tmp <=10 && !*end && !errno )
{
debug_level=tmp;
@@ -203,65 +202,65 @@ static int fish_parse_opt( int argc, char **argv, char **cmd_ptr )
}
break;
}
case 'h':
{
*cmd_ptr = "__fish_print_help fish";
break;
}
case 'i':
{
force_interactive = 1;
break;
break;
}
case 'l':
{
is_login=1;
break;
break;
}
case 'n':
{
no_exec=1;
break;
break;
}
case 'p':
{
profile = optarg;
break;
break;
}
case 'v':
{
fwprintf( stderr,
_(L"%s, version %s\n"),
fwprintf( stderr,
_(L"%s, version %s\n"),
PACKAGE_NAME,
PACKAGE_VERSION );
exit( 0 );
exit( 0 );
}
case '?':
{
exit( 1 );
}
}
}
}
my_optind = optind;
is_login |= (strcmp( argv[0], "-fish") == 0);
/*
We are an interactive session if we have not been given an
explicit command to execute, _and_ stdin is a tty.
*/
is_interactive_session &= (*cmd_ptr == 0);
is_interactive_session &= (my_optind == argc);
is_interactive_session &= isatty(STDIN_FILENO);
is_interactive_session &= isatty(STDIN_FILENO);
/*
We are also an interactive session if we have are forced-
@@ -283,7 +282,7 @@ int main( int argc, char **argv )
char *cmd=0;
int my_optind=0;
halloc_util_init();
halloc_util_init();
wsetlocale( LC_ALL, L"" );
is_interactive_session=1;
@@ -300,9 +299,9 @@ int main( int argc, char **argv )
debug( 1, _(L"Can not use the no-execute mode when running an interactive session") );
no_exec = 0;
}
proc_init();
event_init();
proc_init();
event_init();
wutil_init();
parser_init();
builtin_init();
@@ -324,28 +323,28 @@ int main( int argc, char **argv )
{
if( my_optind == argc )
{
res = reader_read( 0, 0 );
res = reader_read( STDIN_FILENO, 0 );
}
else
{
char **ptr;
char *file = *(argv+1);
int i;
char **ptr;
char *file = *(argv+(my_optind++));
int i;
string_buffer_t sb;
int fd;
wchar_t *rel_filename, *abs_filename;
if( ( fd = open(file, O_RDONLY) ) == -1 )
{
wperror( L"open" );
return 1;
}
if( *(argv+2))
if( *(argv+my_optind))
{
sb_init( &sb );
for( i=1,ptr = argv+2; *ptr; i++, ptr++ )
for( i=1,ptr = argv+my_optind; *ptr; i++, ptr++ )
{
if( i != 1 )
sb_append( &sb, ARRAY_SEP_STR );
@@ -353,7 +352,7 @@ int main( int argc, char **argv )
sb_append( &sb, val );
free( val );
}
env_set( L"argv", (wchar_t *)sb.buff, 0 );
sb_destroy( &sb );
}
@@ -374,17 +373,17 @@ int main( int argc, char **argv )
if( res )
{
debug( 1,
_(L"Error while reading file %ls\n"),
debug( 1,
_(L"Error while reading file %ls\n"),
reader_current_filename()?reader_current_filename(): _(L"Standard input") );
}
}
reader_pop_current_filename();
}
}
}
proc_fire_event( L"PROCESS_EXIT", EVENT_EXIT, getpid(), res );
history_destroy();
proc_destroy();
builtin_destroy();
@@ -393,12 +392,12 @@ int main( int argc, char **argv )
parser_destroy();
wutil_destroy();
event_destroy();
halloc_util_destroy();
env_destroy();
intern_free_all();
return res?STATUS_UNKNOWN_COMMAND:proc_get_last_status();
return res?STATUS_UNKNOWN_COMMAND:proc_get_last_status();
}

View File

@@ -11,7 +11,7 @@ URL: http://www.fishshell.org
Source0: http://www.fishshell.org/files/%{version}/%{name}-%{version}.tar.bz2
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: ncurses-devel gettext groff
BuildRequires: ncurses-devel gettext groff
# Locate correct build time-dependencies for providing X headers
@@ -50,10 +50,10 @@ BuildRequires: %{xinclude}/X11/Intrinsic.h, %{xinclude}/X11/Xatom.h
%endif
%description
%description
fish is a shell geared towards interactive use. Its features are
focused on user friendliness and discoverability. The language syntax
fish is a shell geared towards interactive use. Its features are
focused on user friendliness and discoverability. The language syntax
is simple but incompatible with other shell languages.
@@ -75,7 +75,7 @@ make %{?_smp_mflags}
%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR="$RPM_BUILD_ROOT"
make install DESTDIR="$RPM_BUILD_ROOT"
# Find translation files
%find_lang %{name}.\*

View File

@@ -16,7 +16,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/** \file main.c
/** \file fish_indent.c
The fish_indent proegram.
*/
@@ -48,31 +48,47 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define GETOPT_STRING "hvi"
void read_file( FILE *f, string_buffer_t *b )
/**
Read the entire contents of a file into the specified string_Buffer_t
*/
static void read_file( FILE *f, string_buffer_t *b )
{
while( 1 )
{
errno=0;
wint_t c = fgetwc( f );
if( c == WEOF )
{
if( errno )
{
wperror(L"fgetwc");
exit(1);
}
break;
}
sb_append_char( b, c );
}
}
/**
Insert the specified number of tabe into the output buffer
*/
static void insert_tabs( string_buffer_t *out, int indent )
{
int i;
for( i=0; i<indent; i++ )
{
sb_append( out, L"\t" );
}
}
/**
Indent the specified input
*/
static int indent( string_buffer_t *out, wchar_t *in, int flags )
{
tokenizer tok;
@@ -84,12 +100,12 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
int prev_prev_type = 0;
tok_init( &tok, in, TOK_SHOW_COMMENTS );
for( ; tok_has_next( &tok ); tok_next( &tok ) )
{
int type = tok_last_type( &tok );
wchar_t *last = tok_last( &tok );
switch( type )
{
case TOK_STRING:
@@ -100,7 +116,7 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
is_command = 0;
wchar_t *unesc = unescape( last, UNESCAPE_SPECIAL );
if( parser_keywords_is_block( unesc ) )
{
next_indent++;
@@ -109,34 +125,41 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
{
indent--;
}
/* case should have the same indent level as switch*/
else if( wcscmp( unesc, L"case" ) == 0 )
{
indent--;
}
else if( wcscmp( unesc, L"end" ) == 0 )
{
indent--;
next_indent--;
}
if( do_indent && flags)
if( do_indent && flags && prev_type != TOK_PIPE )
{
insert_tabs( out, indent );
}
sb_printf( out, L"%ls", last );
indent = next_indent;
}
else
{
sb_printf( out, L" %ls", last );
if ( prev_type != TOK_REDIRECT_FD )
sb_append( out, L" " );
sb_append( out, last );
}
break;
}
case TOK_END:
{
if( prev_type != TOK_END || prev_prev_type != TOK_END )
if( prev_type != TOK_END || prev_prev_type != TOK_END )
sb_append( out, L"\n" );
do_indent = 1;
is_command = 1;
@@ -145,39 +168,60 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
case TOK_PIPE:
{
sb_append( out, L" | " );
sb_append( out, L" " );
if ( last[0] == '2' && !last[1] ) {
sb_append( out, L"^" );
} else if ( last[0] != '1' || last[1] ) {
sb_append( out, last, L">" );
}
sb_append( out, L"| " );
is_command = 1;
break;
}
case TOK_REDIRECT_OUT:
case TOK_REDIRECT_APPEND:
case TOK_REDIRECT_IN:
case TOK_REDIRECT_FD:
{
sb_append( out, last );
switch( type )
{
case TOK_REDIRECT_OUT:
sb_append( out, L"> " );
break;
case TOK_REDIRECT_APPEND:
sb_append( out, L">> " );
break;
case TOK_REDIRECT_IN:
sb_append( out, L"< " );
break;
case TOK_REDIRECT_FD:
sb_append( out, L">& " );
break;
sb_append( out, L" " );
if ( wcscmp( last, L"2" ) == 0 ) {
sb_append( out, L"^" );
} else {
if ( wcscmp( last, L"1" ) != 0 )
sb_append( out, last );
sb_append( out, L">" );
}
break;
}
case TOK_REDIRECT_APPEND:
{
sb_append( out, L" " );
if ( wcscmp( last, L"2" ) == 0 ) {
sb_append( out, L"^^" );
} else {
if ( wcscmp( last, L"1" ) != 0 )
sb_append( out, last );
sb_append( out, L">>" );
}
break;
}
case TOK_REDIRECT_IN:
{
sb_append( out, L" " );
if ( wcscmp( last, L"0" ) != 0 )
sb_append( out, last );
sb_append( out, L"<" );
break;
}
case TOK_REDIRECT_FD:
{
sb_append( out, L" " );
if ( wcscmp( last, L"1" ) != 0 )
sb_append( out, last );
sb_append( out, L">&" );
break;
}
case TOK_BACKGROUND:
{
@@ -186,7 +230,6 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
is_command = 1;
break;
}
case TOK_COMMENT:
{
@@ -194,65 +237,72 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
{
insert_tabs( out, indent );
}
sb_printf( out, L"%ls", last );
do_indent = 1;
break;
break;
}
default:
{
debug( 0, L"Unknown token '%ls'", last );
exit(1);
}
}
}
prev_prev_type = prev_type;
prev_type = type;
}
tok_destroy( &tok );
return res;
}
wchar_t *trim( wchar_t *in )
/**
Remove any prefix and suffix newlines from the specified
string. Does not allocete a new string, edits the string in place
and returns a pointer somewhere into the string.
*/
static wchar_t *trim( wchar_t *in )
{
wchar_t *end;
while( *in == L'\n' )
{
in++;
}
end = in + wcslen(in);
while( 1 )
{
if( end < in+2 )
break;
end--;
if( (*end == L'\n' ) && ( *(end-1) == L'\n' ) )
*end=0;
else
break;
}
return in;
}
/**
The main mathod. Run the program.
*/
int main( int argc, char **argv )
{
string_buffer_t sb_in;
string_buffer_t sb_out;
int do_indent=1;
wsetlocale( LC_ALL, L"" );
program_name=L"fish_indent";
@@ -262,55 +312,55 @@ int main( int argc, char **argv )
long_options[] =
{
{
"no-indent", no_argument, 0, 'i'
"no-indent", no_argument, 0, 'i'
}
,
{
"help", no_argument, 0, 'h'
"help", no_argument, 0, 'h'
}
,
{
"version", no_argument, 0, 'v'
"version", no_argument, 0, 'v'
}
,
{
0, 0, 0, 0
{
0, 0, 0, 0
}
}
;
int opt_index = 0;
int opt = getopt_long( argc,
argv,
argv,
GETOPT_STRING,
long_options,
long_options,
&opt_index );
if( opt == -1 )
break;
switch( opt )
{
case 0:
{
break;
}
case 'h':
{
print_help( "fish_indent", 1 );
exit( 0 );
exit( 0 );
break;
}
case 'v':
{
fwprintf( stderr,
_(L"%ls, version %s\n"),
fwprintf( stderr,
_(L"%ls, version %s\n"),
program_name,
PACKAGE_VERSION );
exit( 0 );
exit( 0 );
}
case 'i':
@@ -318,23 +368,23 @@ int main( int argc, char **argv )
do_indent = 0;
break;
}
case '?':
{
exit( 1 );
}
}
}
}
halloc_util_init();
halloc_util_init();
sb_init( &sb_in );
sb_init( &sb_out );
read_file( stdin, &sb_in );
wutil_init();
if( !indent( &sb_out, (wchar_t *)sb_in.buff, do_indent ) )
@@ -348,7 +398,7 @@ int main( int argc, char **argv )
*/
fwprintf( stdout, L"%ls", (wchar_t *)sb_in.buff );
}
wutil_destroy();

View File

@@ -61,7 +61,7 @@
#include "halloc_util.h"
#include "print_help.h"
enum
enum
{
LINE_UP = R_NULL+1,
LINE_DOWN,
@@ -146,7 +146,7 @@ static buffer_t *pager_buffer;
The environment variables used to specify the color of different
tokens.
*/
static wchar_t *hightlight_var[] =
static wchar_t *hightlight_var[] =
{
L"fish_pager_color_prefix",
L"fish_pager_color_completion",
@@ -167,7 +167,7 @@ static FILE *out_file;
/**
Data structure describing one or a group of related completions
*/
typedef struct
typedef struct
{
/**
The list of all completin strings this entry applies to
@@ -180,11 +180,11 @@ typedef struct
/**
On-screen width of the completion string
*/
int comp_width;
int comp_width;
/**
On-screen width of the description information
*/
int desc_width;
int desc_width;
/**
Preffered total width
*/
@@ -208,20 +208,20 @@ static int get_color( int highlight )
return FISH_COLOR_NORMAL;
if( highlight >= (4) )
return FISH_COLOR_NORMAL;
val = wgetenv( hightlight_var[highlight]);
if( !val )
{
val = env_universal_get( hightlight_var[highlight]);
}
if( !val )
{
return FISH_COLOR_NORMAL;
}
return output_color_code( val );
return output_color_code( val );
}
/**
@@ -236,11 +236,11 @@ static void recalc_width( array_list_t *l, const wchar_t *prefix )
for( i=0; i<al_get_count( l ); i++ )
{
comp_t *c = (comp_t *)al_get( l, i );
c->min_width = mini( c->desc_width, maxi(0,termsize.ws_col/3 - 2)) +
mini( c->desc_width, maxi(0,termsize.ws_col/5 - 4)) +4;
}
}
/**
@@ -251,14 +251,14 @@ static int try_sequence( char *seq )
{
int j, k;
wint_t c=0;
for( j=0;
seq[j] != '\0' && seq[j] == (c=input_common_readch( j>0 ));
for( j=0;
seq[j] != '\0' && seq[j] == (c=input_common_readch( j>0 ));
j++ )
;
if( seq[j] == '\0' )
{
{
return 1;
}
else
@@ -281,10 +281,10 @@ static wint_t readch()
wint_t bnd;
}
;
struct mapping m[]=
{
{
{
"\x1b[A", LINE_UP
}
,
@@ -292,7 +292,7 @@ static wint_t readch()
key_up, LINE_UP
}
,
{
{
"\x1b[B", LINE_DOWN
}
,
@@ -319,18 +319,18 @@ static wint_t readch()
{
0, 0
}
}
;
int i;
for( i=0; m[i].bnd; i++ )
{
if( !m[i].seq )
{
continue;
}
if( try_sequence(m[i].seq ) )
return m[i].bnd;
}
@@ -351,7 +351,7 @@ static int pager_buffered_writer( char c)
*/
static void pager_flush()
{
write( 1, pager_buffer->buff, pager_buffer->used );
write_loop( 1, pager_buffer->buff, pager_buffer->used );
pager_buffer->used = 0;
}
@@ -369,7 +369,7 @@ static int print_max( const wchar_t *str, int max, int has_more )
int written = 0;
for( i=0; str[i]; i++ )
{
if( written + wcwidth(str[i]) > max )
break;
if( ( written + wcwidth(str[i]) == max) && (has_more || str[i+1]) )
@@ -378,7 +378,7 @@ static int print_max( const wchar_t *str, int max, int has_more )
written += wcwidth(ellipsis_char );
break;
}
writech( str[i] );
written+= wcwidth( str[i] );
}
@@ -393,7 +393,7 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width )
int comp_width=0, desc_width=0;
int i;
int written=0;
if( c->pref_width <= width )
{
/*
@@ -411,7 +411,7 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width )
the description.
*/
int desc_all = c->desc_width?c->desc_width+4:0;
comp_width = maxi( mini( c->comp_width,
2*(width-4)/3 ),
width - desc_all );
@@ -419,9 +419,9 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width )
desc_width = width-comp_width-4;
else
c->desc_width=0;
}
for( i=0; i<al_get_count( c->comp ); i++ )
{
const wchar_t *comp = (const wchar_t *)al_get( c->comp, i );
@@ -455,7 +455,7 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width )
writech( L' ');
}
}
}
/**
@@ -490,14 +490,14 @@ static void completion_print( int cols,
comp_t *el;
int is_last = (j==(cols-1));
if( al_get_count( l ) <= j*rows + i )
continue;
el = (comp_t *)al_get( l, j*rows + i );
completion_print_item( prefix, el, width[j] - (is_last?0:2) );
if( !is_last)
writestr( L" " );
}
@@ -545,24 +545,24 @@ static int completion_try_print( int cols,
Set to one if the list should be printed at this width
*/
int print=0;
int i, j;
int rows = (al_get_count( l )-1)/cols+1;
int pref_tot_width=0;
int min_tot_width = 0;
int res=PAGER_RETRY;
/*
Skip completions on tiny terminals
*/
if( termsize.ws_col < PAGER_MIN_WIDTH )
return PAGER_DONE;
memset( pref_width, 0, sizeof(pref_width) );
memset( min_width, 0, sizeof(min_width) );
/* Calculate how wide the list would be */
for( j = 0; j < cols; j++ )
{
@@ -576,7 +576,7 @@ static int completion_try_print( int cols,
c = (comp_t *)al_get( l, j*rows + i );
pref = c->pref_width;
min = c->min_width;
if( j != cols-1 )
{
pref += 2;
@@ -632,7 +632,7 @@ static int completion_try_print( int cols,
be helped, but it is not uncommon for the completions to
_almost_ fit on one screen. In those cases, it is almost
always desirable to 'squeeze' the completions into a
single page.
single page.
If we are using N columns and can get everything to
fit using squeezing, but everything would also fit
@@ -668,7 +668,7 @@ static int completion_try_print( int cols,
is_ca_mode = 0;
writembs(exit_ca_mode);
}
completion_print( cols, width, 0, rows, prefix, is_quoted, l);
pager_flush();
}
@@ -687,7 +687,7 @@ static int completion_try_print( int cols,
is_ca_mode=1;
writembs(enter_ca_mode);
}
completion_print( cols,
width,
@@ -704,18 +704,18 @@ static int completion_try_print( int cols,
{
string_buffer_t msg;
sb_init( &msg );
set_color( FISH_COLOR_BLACK,
get_color(HIGHLIGHT_PAGER_PROGRESS) );
sb_printf( &msg,
_(L" %d to %d of %d"),
pos,
pos+termsize.ws_row-1,
pos+termsize.ws_row-1,
rows );
sb_printf( &msg,
L" \r" );
writestr((wchar_t *)msg.buff);
sb_destroy( &msg );
set_color( FISH_COLOR_NORMAL, FISH_COLOR_NORMAL );
@@ -817,15 +817,15 @@ static int completion_try_print( int cols,
do_loop=0;
res=PAGER_RESIZE;
break;
}
default:
{
sb_append_char( &out_buff, c );
do_loop = 0;
break;
}
}
}
}
writembs(clr_eol);
@@ -847,31 +847,31 @@ static void mangle_descriptions( array_list_t *l )
wchar_t *next = (wchar_t *)al_get(l, i);
wchar_t *in, *out;
skip=1;
while( *next != COMPLETE_SEP && *next )
next++;
if( !*next )
continue;
in=out=(next+1);
while( *in != 0 )
{
if( *in == L' ' || *in==L'\t' || *in<32 )
{
if( !skip )
*out++=L' ';
skip=1;
skip=1;
}
else
{
*out++ = *in;
*out++ = *in;
skip=0;
}
in++;
}
*out=0;
*out=0;
}
}
@@ -883,7 +883,7 @@ static void join_completions( array_list_t *l )
long i;
int in, out;
hash_table_t desc_table;
hash_init( &desc_table, &hash_wcs_func, &hash_wcs_cmp );
for( i=0; i<al_get_count(l); i++ )
@@ -891,7 +891,7 @@ static void join_completions( array_list_t *l )
wchar_t *item = (wchar_t *)al_get( l, i );
wchar_t *desc = wcschr( item, COMPLETE_SEP );
long prev_idx;
if( !desc )
continue;
desc++;
@@ -905,11 +905,11 @@ static void join_completions( array_list_t *l )
string_buffer_t foo;
wchar_t *old = (wchar_t *)al_get( l, prev_idx );
wchar_t *old_end = wcschr( old, COMPLETE_SEP );
if( old_end )
{
*old_end = 0;
sb_init( &foo );
sb_append( &foo, old );
sb_append_char( &foo, COMPLETE_ITEM_SEP );
@@ -921,23 +921,23 @@ static void join_completions( array_list_t *l )
free( (void *)al_get( l, i ) );
al_set( l, i, 0 );
}
}
}
}
hash_destroy( &desc_table );
out=0;
for( in=0; in < al_get_count(l); in++ )
{
const void * d = al_get( l, in );
if( d )
{
al_set( l, out++, d );
}
}
al_truncate( l, out );
al_truncate( l, out );
}
/**
@@ -946,23 +946,23 @@ static void join_completions( array_list_t *l )
static void mangle_completions( array_list_t *l, const wchar_t *prefix )
{
int i;
for( i=0; i<al_get_count( l ); i++ )
{
wchar_t *next = (wchar_t *)al_get( l, i );
wchar_t *start, *end;
comp_t *comp = halloc( global_context, sizeof( comp_t ) );
comp->comp = al_halloc( global_context );
for( start=end=next; 1; end++ )
{
wchar_t c = *end;
if( (c == COMPLETE_ITEM_SEP) || (c==COMPLETE_SEP) || !c)
{
*end = 0;
wchar_t * str = escape( start, ESCAPE_ALL | ESCAPE_NO_QUOTED );
comp->comp_width += my_wcswidth( str );
halloc_register( global_context, str );
al_push( comp->comp, str );
@@ -973,22 +973,22 @@ static void mangle_completions( array_list_t *l, const wchar_t *prefix )
{
comp->desc = halloc_wcsdup( global_context, start );
break;
}
}
if( !c )
break;
}
comp->comp_width += my_wcswidth(prefix)*al_get_count(comp->comp) + 2*(al_get_count(comp->comp)-1);
comp->desc_width = comp->desc?my_wcswidth( comp->desc ):0;
comp->pref_width = comp->comp_width + comp->desc_width + (comp->desc_width?4:0);
free( next );
al_set( l, i, comp );
}
recalc_width( l, prefix );
}
@@ -1026,10 +1026,10 @@ static void init( int mangle_descriptors, int out )
static struct termios pager_modes;
char *term;
if( mangle_descriptors )
{
/*
Make fd 1 output to screen, and use some other fd for writing
the resulting output back to the caller
@@ -1042,13 +1042,13 @@ static void init( int mangle_descriptors, int out )
if( (in = open( ttyname(2), O_RDWR )) != -1 )
{
if( dup2( 2, 1 ) == -1 )
{
{
debug( 0, _(L"Could not set up output file descriptors for pager") );
exit( 1 );
}
if( dup2( in, 0 ) == -1 )
{
{
debug( 0, _(L"Could not set up input file descriptors for pager") );
exit( 1 );
}
@@ -1059,13 +1059,13 @@ static void init( int mangle_descriptors, int out )
exit( 1 );
}
}
if( !(out_file = fdopen( out, "w" )) )
{
debug( 0, _(L"Could not initialize result pipe" ) );
exit( 1 );
}
/**
Init the stringbuffer used to keep any output in
@@ -1088,7 +1088,7 @@ static void init( int mangle_descriptors, int out )
wperror( L"sigaction" );
exit(1);
}
handle_winch( 0 ); /* Set handler for window change events */
tcgetattr(0,&pager_modes); /* get the current terminal modes */
@@ -1102,14 +1102,14 @@ static void init( int mangle_descriptors, int out )
pager_modes.c_cc[VTIME]=0;
/*
*/
if( tcsetattr(0,TCSANOW,&pager_modes)) /* set the new modes */
{
wperror(L"tcsetattr");
exit(1);
}
if( setupterm( 0, STDOUT_FILENO, 0) == ERR )
{
@@ -1124,7 +1124,7 @@ static void init( int mangle_descriptors, int out )
output_set_term( wterm );
free( wterm );
}
}
/**
@@ -1137,9 +1137,9 @@ static void destroy()
wutil_destroy();
if( del_curterm( cur_term ) == ERR )
{
debug( 0, _(L"Error while closing terminfo") );
debug( 0, _(L"Error while closing terminfo") );
}
sb_destroy( &out_buff );
fclose( out_file );
}
@@ -1164,7 +1164,7 @@ static void read_array( FILE* file, array_list_t *comp )
while( 1 )
{
c = getc( file );
if( c == EOF )
if( c == EOF )
{
break;
}
@@ -1175,7 +1175,7 @@ static void read_array( FILE* file, array_list_t *comp )
}
cc=c;
b_append( &buffer, &cc, 1 );
}
@@ -1183,15 +1183,15 @@ static void read_array( FILE* file, array_list_t *comp )
{
cc=0;
b_append( &buffer, &cc, 1 );
wcs = str2wcs( buffer.buff );
if( wcs )
if( wcs )
{
unescaped = unescape( wcs, 0 );
if( unescaped )
{
al_push( comp, unescaped );
}
}
free( wcs );
}
}
@@ -1203,9 +1203,9 @@ static void read_array( FILE* file, array_list_t *comp )
static int get_fd( const char *str )
{
char *end;
char *end;
long fd;
errno = 0;
fd = strtol( str, &end, 10 );
if( fd < 0 || *end || errno )
@@ -1220,13 +1220,13 @@ static int get_fd( const char *str )
int main( int argc, char **argv )
{
int i;
int is_quoted=0;
int is_quoted=0;
array_list_t *comp;
wchar_t *prefix = 0;
int mangle_descriptors = 0;
int result_fd = -1;
/*
This initialization is made early, so that the other init code
can use global_context for memory managment
@@ -1252,69 +1252,69 @@ int main( int argc, char **argv )
/*
Third mode
*/
int completion_fd = -1;
FILE *completion_file;
while( 1 )
{
static struct option
long_options[] =
{
{
"result-fd", required_argument, 0, 'r'
"result-fd", required_argument, 0, 'r'
}
,
{
"completion-fd", required_argument, 0, 'c'
"completion-fd", required_argument, 0, 'c'
}
,
{
"prefix", required_argument, 0, 'p'
"prefix", required_argument, 0, 'p'
}
,
{
"is-quoted", no_argument, 0, 'q'
"is-quoted", no_argument, 0, 'q'
}
,
{
"help", no_argument, 0, 'h'
"help", no_argument, 0, 'h'
}
,
{
"version", no_argument, 0, 'v'
"version", no_argument, 0, 'v'
}
,
{
0, 0, 0, 0
{
0, 0, 0, 0
}
}
;
int opt_index = 0;
int opt = getopt_long( argc,
argv,
argv,
GETOPT_STRING,
long_options,
long_options,
&opt_index );
if( opt == -1 )
break;
switch( opt )
{
case 0:
{
break;
}
case 'r':
{
result_fd = get_fd( optarg );
break;
}
case 'c':
{
completion_fd = get_fd( optarg );
@@ -1330,20 +1330,20 @@ int main( int argc, char **argv )
case 'h':
{
print_help( argv[0], 1 );
exit(0);
exit(0);
}
case 'v':
{
debug( 0, L"%ls, version %s\n", program_name, PACKAGE_VERSION );
exit( 0 );
exit( 0 );
}
case 'q':
{
is_quoted = 1;
}
}
}
@@ -1352,7 +1352,7 @@ int main( int argc, char **argv )
debug( 0, _(L"Unspecified file descriptors") );
exit( 1 );
}
if( (completion_file = fdopen( completion_fd, "r" ) ) )
{
@@ -1370,8 +1370,8 @@ int main( int argc, char **argv )
{
prefix = wcsdup( L"" );
}
}
else
{
@@ -1385,7 +1385,7 @@ int main( int argc, char **argv )
forward. A reasonable time frame for removal of the code
below has yet to be determined.
*/
if( argc < 3 )
{
print_help( argv[0], 1 );
@@ -1394,10 +1394,10 @@ int main( int argc, char **argv )
else
{
mangle_descriptors = 1;
prefix = str2wcs( argv[2] );
is_quoted = strcmp( "1", argv[1] )==0;
if( argc > 3 )
{
/*
@@ -1420,11 +1420,11 @@ int main( int argc, char **argv )
read_array( stdin, comp );
}
}
}
// debug( 3, L"prefix is '%ls'", prefix );
init( mangle_descriptors, result_fd );
mangle_descriptions( comp );
@@ -1462,9 +1462,9 @@ int main( int argc, char **argv )
i=PAGER_MAX_COLS+1;
break;
}
}
}
free(prefix );
fwprintf( out_file, L"%ls", (wchar_t *)out_buff.buff );
@@ -1476,6 +1476,6 @@ int main( int argc, char **argv )
destroy();
halloc_util_destroy();
}

View File

@@ -16,7 +16,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdarg.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
@@ -85,7 +85,7 @@ static void say( wchar_t *blah, ... )
va_list va;
va_start( va, blah );
vwprintf( blah, va );
va_end( va );
va_end( va );
wprintf( L"\n" );
}
@@ -97,10 +97,10 @@ static void err( wchar_t *blah, ... )
va_list va;
va_start( va, blah );
err_count++;
wprintf( L"Error: " );
vwprintf( blah, va );
va_end( va );
va_end( va );
wprintf( L"\n" );
}
@@ -119,13 +119,13 @@ static void pq_test( int elements )
{
int i;
int prev;
int *count = calloc( sizeof(int), 100 );
priority_queue_t q;
pq_init( &q, pq_compare );
for( i=0; i<elements; i++ )
{
long foo = rand() % 100;
@@ -133,9 +133,9 @@ static void pq_test( int elements )
pq_put( &q, (void *)foo );
count[foo]++;
}
prev = 100;
for( i=0; i<elements; i++ )
{
long pos = (long)pq_get( &q );
@@ -143,7 +143,7 @@ static void pq_test( int elements )
if( pos > prev )
err( L"Wrong order of elements in priority_queue_t" );
prev = pos;
}
for( i=0; i<100; i++ )
@@ -163,10 +163,10 @@ static int stack_test( int elements )
long i;
int res=1;
array_list_t s;
al_init( &s );
al_init( &s );
for( i=0; i<elements; i++ )
{
@@ -174,11 +174,11 @@ static int stack_test( int elements )
al_push_long( &s, i);
al_push_long( &s, i);
if( (foo=al_pop_long( &s )) != i )
{
err( L"Unexpected data" );
res = 0;
res = 0;
break;
}
}
@@ -186,18 +186,18 @@ static int stack_test( int elements )
for( i=0; i<elements; i++ )
{
long foo;
if( (foo=al_pop_long( &s )) != (elements-i-1) )
{
err( L"Unexpected data" );
res = 0;
break;
}
}
}
al_destroy( &s );
return res;
}
@@ -210,7 +210,7 @@ static int hash_func( void *data )
return rand();
*/
int foo = (int)(long)data;
return 127*((foo^0xefc7e214)) ^(foo<<11);
return 127*((foo^0xefc7e214)) ^(foo<<11);
}
/**
@@ -229,26 +229,26 @@ static int hash_test( long elements )
{
long i;
int res=1;
hash_table_t h;
hash_init( &h, hash_func, compare_func );
for( i=1; i< elements+1; i++ )
{
hash_put( &h, (void*)i, (void*)100l-i );
}
for( i=1; i< elements+1; i++ )
{
if( (long)hash_get( &h, (void*)i ) != (100l-i) )
{
err( L"Key %d gave data %d, expected data %d",
i,
i,
(long)hash_get( &h, (void*)i ),
100l-i );
res = 0;
break;
}
}
@@ -259,14 +259,14 @@ static int hash_test( long elements )
hash_get_count( &h ),
elements );
res = 0;
}
for( i=1; i<elements+1; i+=2 )
{
hash_remove( &h, (void*)i, 0, 0 );
}
if( hash_get_count( &h ) != ((elements)/2) )
@@ -276,7 +276,7 @@ static int hash_test( long elements )
elements/2 );
res = 0;
}
for( i=1; i<elements+1; i++ )
{
if( hash_contains( &h, (void*)i) != (i+1l)%2l )
@@ -295,7 +295,7 @@ static int hash_test( long elements )
hash_destroy( &h );
return res;
}
/**
@@ -303,19 +303,19 @@ static int hash_test( long elements )
*/
static void al_test( int sz)
{
long i;
long i;
array_list_t l;
al_init( &l );
al_set_long( &l, 1, 7L );
al_set_long( &l, sz, 7L );
if( al_get_count( &l ) != maxi( sz+1, 2 ) )
err( L"Wrong number of elements in array list" );
for( i=0; i<al_get_count( &l ); i++ )
{
long val = al_get_long( &l, i );
@@ -339,15 +339,15 @@ static void sb_test()
{
string_buffer_t b;
int res;
sb_init( &b );
if( (res=sb_printf( &b, L"%ls%s", L"Testing ", "string_buffer_t " )) == -1 )
{
err( L"Error %d while testing stringbuffers", res );
}
if( (res=sb_printf( &b, L"%ls", L"functionality" ))==-1)
if( (res=sb_printf( &b, L"%ls", L"functionality" ))==-1)
{
err( L"Error %d while testing stringbuffers", res );
}
@@ -362,9 +362,9 @@ static void sb_test()
err( L"numerical formating is broken, '%ls' != '%ls'", (wchar_t *)b.buff, NUM_ANS );
}
else
say( L"numerical formating works" );
say( L"numerical formating works" );
}
/**
@@ -375,7 +375,7 @@ static void test_util()
int i;
say( L"Testing utility library" );
for( i=0; i<18; i++ )
{
long t1, t2;
@@ -392,27 +392,27 @@ static void test_util()
}
sb_test();
/*
int i;
for( i=2; i<10000000; i*=2 )
{
printf( "%d", i );
t1 = get_time();
if(!hash_test(i))
exit(0);
t2 = get_time();
printf( " %d\n", (t2-t1)/i );
}
*/
*/
}
@@ -424,15 +424,15 @@ static void test_escape()
{
int i;
string_buffer_t sb;
say( L"Testing escaping and unescaping" );
sb_init( &sb );
for( i=0; i<ESCAPE_TEST_COUNT; i++ )
{
wchar_t *o, *e, *u;
sb_clear( &sb );
while( rand() % ESCAPE_TEST_LENGTH )
{
@@ -444,23 +444,23 @@ static void test_escape()
if( !o || !e || !u )
{
err( L"Escaping cycle of string %ls produced null pointer on %ls", o, e?L"unescaping":L"escaping" );
}
if( wcscmp(o, u) )
{
err( L"Escaping cycle of string %ls produced different string %ls", o, u );
}
free( e );
free( u );
}
}
}
/**
@@ -470,17 +470,17 @@ static void test_escape()
*/
static void test_convert()
{
/* char o[] =
/* char o[] =
{
-17, -128, -121, -68, 0
}
;
wchar_t *w = str2wcs(o);
char *n = wcs2str(w);
int i;
for( i=0; o[i]; i++ )
{
bitprint(o[i]);;
@@ -508,20 +508,20 @@ static void test_convert()
int i;
buffer_t sb;
say( L"Testing wide/narrow string conversion" );
b_init( &sb );
for( i=0; i<ESCAPE_TEST_COUNT; i++ )
{
wchar_t *w;
char *o, *n;
char c;
sb.used=0;
while( rand() % ESCAPE_TEST_LENGTH )
{
c = rand ();
@@ -529,23 +529,23 @@ static void test_convert()
}
c = 0;
b_append( &sb, &c, 1 );
o = (char *)sb.buff;
w = str2wcs(o);
n = wcs2str(w);
if( !o || !w || !n )
{
err( L"Conversion cycle of string %s produced null pointer on %s", o, w?L"str2wcs":L"wcs2str" );
}
if( strcmp(o, n) )
{
err( L"%d: Conversion cycle of string %s produced different string %s", i, o, n );
}
free( w );
free( n );
}
}
@@ -556,10 +556,10 @@ static void test_convert()
static void test_tok()
{
tokenizer t;
say( L"Testing tokenizer" );
say( L"Testing invalid input" );
tok_init( &t, 0, 0 );
@@ -567,13 +567,13 @@ static void test_tok()
{
err(L"Invalid input to tokenizer was undetected" );
}
say( L"Testing use of broken tokenizer" );
if( !tok_has_next( &t ) )
{
err( L"tok_has_next() should return 1 once on broken tokenizer" );
}
tok_next( &t );
if( tok_last_type( &t ) != TOK_ERROR )
{
@@ -585,17 +585,17 @@ static void test_tok()
*/
say( L"Test destruction of broken tokenizer" );
tok_destroy( &t );
{
wchar_t *str = L"string <redirection 2>&1 'nested \"quoted\" '(string containing subshells ){and,brackets}$as[$well (as variable arrays)]";
const int types[] =
const int types[] =
{
TOK_STRING, TOK_REDIRECT_IN, TOK_STRING, TOK_REDIRECT_FD, TOK_STRING, TOK_STRING, TOK_END
}
;
int i;
say( L"Test correct tokenization" );
for( i=0, tok_init( &t, str, 0 ); i<(sizeof(types)/sizeof(int)); i++,tok_next( &t ) )
@@ -603,7 +603,7 @@ static void test_tok()
if( types[i] != tok_last_type( &t ) )
{
err( L"Tokenization error:");
wprintf( L"Token number %d of string \n'%ls'\n, expected token type %ls, got token '%ls' of type %ls\n",
wprintf( L"Token number %d of string \n'%ls'\n, expected token type %ls, got token '%ls' of type %ls\n",
i+1,
str,
tok_get_desc(types[i]),
@@ -612,9 +612,9 @@ static void test_tok()
}
}
}
}
/**
@@ -623,8 +623,8 @@ static void test_tok()
static void test_parser()
{
say( L"Testing parser" );
say( L"Testing null input to parser" );
if( !parser_test( 0, 0, 0, 0 ) )
{
@@ -634,51 +634,51 @@ static void test_parser()
say( L"Testing block nesting" );
if( !parser_test( L"if; end", 0, 0, 0 ) )
{
err( L"Incomplete if statement undetected" );
err( L"Incomplete if statement undetected" );
}
if( !parser_test( L"if test; echo", 0, 0, 0 ) )
{
err( L"Missing end undetected" );
err( L"Missing end undetected" );
}
if( !parser_test( L"if test; end; end", 0, 0, 0 ) )
{
err( L"Unbalanced end undetected" );
err( L"Unbalanced end undetected" );
}
say( L"Testing detection of invalid use of builtin commands" );
if( !parser_test( L"case foo", 0, 0, 0 ) )
{
err( L"'case' command outside of block context undetected" );
err( L"'case' command outside of block context undetected" );
}
if( !parser_test( L"switch ggg; if true; case foo;end;end", 0, 0, 0 ) )
{
err( L"'case' command outside of switch block context undetected" );
err( L"'case' command outside of switch block context undetected" );
}
if( !parser_test( L"else", 0, 0, 0 ) )
{
err( L"'else' command outside of conditional block context undetected" );
err( L"'else' command outside of conditional block context undetected" );
}
if( !parser_test( L"break", 0, 0, 0 ) )
{
err( L"'break' command outside of loop block context undetected" );
err( L"'break' command outside of loop block context undetected" );
}
if( !parser_test( L"exec ls|less", 0, 0, 0 ) || !parser_test( L"echo|return", 0, 0, 0 ))
{
err( L"Invalid pipe command undetected" );
}
err( L"Invalid pipe command undetected" );
}
say( L"Testing basic evaluation" );
if( !eval( 0, 0, TOP ) )
{
err( L"Null input when evaluating undetected" );
}
}
if( !eval( L"ls", 0, WHILE ) )
{
err( L"Invalid block mode when evaluating undetected" );
}
}
/**
Perform parameter expansion and test if the output equals the zero-terminated parameter list supplied.
@@ -688,42 +688,42 @@ static void test_parser()
static int expand_test( const wchar_t *in, int flags, ... )
{
array_list_t out;
array_list_t out;
va_list va;
int i=0;
int res=1;
wchar_t *arg;
al_init( &out );
if( expand_string( 0, wcsdup(in), &out, flags) )
{
}
va_start( va, flags );
while( (arg=va_arg(va, wchar_t *) )!= 0 )
while( (arg=va_arg(va, wchar_t *) )!= 0 )
{
if( al_get_count( &out ) == i )
{
res=0;
break;
}
if( wcscmp( al_get( &out, i ),arg) != 0 )
{
res=0;
break;
}
i++;
i++;
}
va_end( va );
al_foreach( &out, &free );
return res;
}
/**
@@ -732,7 +732,7 @@ static int expand_test( const wchar_t *in, int flags, ... )
static void test_expand()
{
say( L"Testing parameter expansion" );
if( !expand_test( L"foo", 0, L"foo", 0 ))
{
err( L"Strings do not expand to themselves" );
@@ -747,25 +747,28 @@ static void test_expand()
{
err( L"Cannot skip wildcard expansion" );
}
}
/**
Test path functions
*/
static void test_path()
{
say( L"Testing path functions" );
void *context = halloc( 0, 0 );
wchar_t *can = path_make_canonical( context, L"//foo//////bar/" );
if( wcscmp( can, L"/foo/bar" ) )
{
err( L"Bug in canonical PATH code" );
}
halloc_free( context );
}
@@ -782,72 +785,72 @@ void perf_complete()
double t;
wchar_t str[3]=
{
0, 0, 0
0, 0, 0
}
;
int i;
say( L"Testing completion performance" );
al_init( &out );
reader_push(L"");
say( L"Here we go" );
t1 = get_time();
for( c=L'a'; c<=L'z'; c++ )
{
str[0]=c;
reader_set_buffer( str, 0 );
complete( str, &out );
matches += al_get_count( &out );
al_foreach( &out, &free );
al_truncate( &out, 0 );
}
t2=get_time();
t = (double)(t2-t1)/(1000000*26);
say( L"One letter command completion took %f seconds per completion, %f microseconds/match", t, (double)(t2-t1)/matches );
matches=0;
t1 = get_time();
for( i=0; i<LAPS; i++ )
{
str[0]='a'+(rand()%26);
str[1]='a'+(rand()%26);
reader_set_buffer( str, 0 );
complete( str, &out );
matches += al_get_count( &out );
al_foreach( &out, &free );
al_truncate( &out, 0 );
}
t2=get_time();
t = (double)(t2-t1)/(1000000*LAPS);
say( L"Two letter command completion took %f seconds per completion, %f microseconds/match", t, (double)(t2-t1)/matches );
al_destroy( &out );
reader_pop();
}
/**
Main test
Main test
*/
int main( int argc, char **argv )
{
@@ -855,13 +858,13 @@ int main( int argc, char **argv )
srand( time( 0 ) );
program_name=L"(ignore)";
say( L"Testing low-level functionality");
say( L"Lines beginning with '(ignore):' are not errors, they are warning messages\ngenerated by the fish parser library when given broken input, and can be\nignored. All actual errors begin with 'Error:'." );
proc_init();
proc_init();
halloc_util_init();
event_init();
event_init();
parser_init();
function_init();
builtin_init();
@@ -875,7 +878,7 @@ int main( int argc, char **argv )
test_parser();
test_expand();
test_path();
say( L"Encountered %d errors in low-level tests", err_count );
/*
@@ -883,9 +886,9 @@ int main( int argc, char **argv )
*/
// say( L"Testing performance" );
// perf_complete();
env_destroy();
reader_destroy();
reader_destroy();
parser_destroy();
function_destroy();
builtin_destroy();
@@ -893,5 +896,5 @@ int main( int argc, char **argv )
event_destroy();
proc_destroy();
halloc_util_destroy();
}

184
fishd.c
View File

@@ -78,7 +78,7 @@ time the original barrier request was sent have been received.
/**
Maximum length of socket filename
*/
#ifndef UNIX_PATH_MAX
#ifndef UNIX_PATH_MAX
#define UNIX_PATH_MAX 100
#endif
@@ -182,7 +182,7 @@ static char *get_socket_filename()
}
/**
Signal handler for the term signal.
Signal handler for the term signal.
*/
static void handle_term( int signal )
{
@@ -192,17 +192,17 @@ static void handle_term( int signal )
/**
Acquire the lock for the socket
Returns the name of the lock file if successful or
Returns the name of the lock file if successful or
NULL if unable to obtain lock.
The returned string must be free()d after unlink()ing the file to release
The returned string must be free()d after unlink()ing the file to release
the lock
*/
static char *acquire_socket_lock( const char *sock_name )
{
int len = strlen( sock_name );
char *lockfile = malloc( len + strlen( LOCKPOSTFIX ) + 1 );
if( lockfile == NULL )
if( lockfile == NULL )
{
wperror( L"acquire_socket_lock" );
exit( EXIT_FAILURE );
@@ -237,13 +237,13 @@ static int get_socket()
exit( EXIT_FAILURE );
}
debug( 4, L"Acquired lockfile: %s", lockfile );
local.sun_family = AF_UNIX;
strcpy( local.sun_path, sock_name );
len = sizeof(local);
debug(1, L"Connect to socket at %s", sock_name);
if( ( s = socket( AF_UNIX, SOCK_STREAM, 0 ) ) == -1 )
{
wperror( L"socket" );
@@ -262,7 +262,7 @@ static int get_socket()
exitcode = 0;
goto unlock;
}
unlink( local.sun_path );
if( bind( s, (struct sockaddr *)&local, len ) == -1 )
{
@@ -288,9 +288,9 @@ static int get_socket()
/*
End critical section protected by lock
*/
free( lockfile );
free( sock_name );
if( doexit )
@@ -311,24 +311,24 @@ static void broadcast( int type, const wchar_t *key, const wchar_t *val )
if( !conn )
return;
msg = create_message( type, key, val );
/*
Don't merge these loops, or try_send_all can free the message
prematurely
*/
for( c = conn; c; c=c->next )
{
msg->count++;
q_put( &c->unsent, msg );
}
}
for( c = conn; c; c=c->next )
{
try_send_all( c );
}
}
}
/**
@@ -345,7 +345,7 @@ static void daemonize()
debug( 0, L"Could not put fishd in background. Quitting" );
wperror( L"fork" );
exit(1);
case 0:
{
/*
@@ -366,19 +366,19 @@ static void daemonize()
sigaction( SIGTERM, &act, 0);
break;
}
default:
{
{
debug( 0, L"Parent process exiting (This is normal)" );
exit(0);
}
}
}
/*
Put ourself in out own processing group
*/
setsid();
/*
Close stdin and stdout. We only use stderr, anyway.
*/
@@ -394,7 +394,7 @@ static wchar_t *fishd_env_get( wchar_t *key )
{
char *nres, *nkey;
wchar_t *res;
nkey = wcs2str( key );
nres = getenv( nkey );
free( nkey );
@@ -407,7 +407,7 @@ static wchar_t *fishd_env_get( wchar_t *key )
res = env_universal_common_get( key );
if( res )
res = wcsdup( res );
return env_universal_common_get( key );
}
}
@@ -423,7 +423,7 @@ static wchar_t *fishd_get_config()
wchar_t *xdg_dir, *home;
int done = 0;
wchar_t *res = 0;
xdg_dir = fishd_env_get( L"XDG_CONFIG_HOME" );
if( xdg_dir )
{
@@ -439,7 +439,7 @@ static wchar_t *fishd_get_config()
free( xdg_dir );
}
else
{
{
home = fishd_env_get( L"HOME" );
if( home )
{
@@ -455,7 +455,7 @@ static wchar_t *fishd_get_config()
free( home );
}
}
if( done )
{
return res;
@@ -465,7 +465,7 @@ static wchar_t *fishd_get_config()
debug( 0, _(L"Unable to create a configuration directory for fish. Your personal settings will not be saved. Please set the $XDG_CONFIG_HOME variable to a directory where the current user has write access." ));
return 0;
}
}
/**
@@ -475,22 +475,22 @@ static void load_or_save( int save)
{
char *name;
wchar_t *wdir = fishd_get_config();
char *dir;
char *dir;
char hostname[HOSTNAME_LEN];
connection_t c;
int fd;
if( !wdir )
{
return;
}
dir = wcs2str( wdir );
free( wdir );
gethostname( hostname, HOSTNAME_LEN );
name = malloc( strlen(dir)+ strlen(FILE)+ strlen(hostname) + 2 );
strcpy( name, dir );
strcat( name, "/" );
@@ -499,20 +499,20 @@ static void load_or_save( int save)
free( dir );
debug( 4, L"Open file for %s: '%s'",
save?"saving":"loading",
debug( 4, L"Open file for %s: '%s'",
save?"saving":"loading",
name );
fd = open( name, save?(O_CREAT | O_TRUNC | O_WRONLY):O_RDONLY, 0600);
free( name );
if( fd == -1 )
{
debug( 1, L"Could not open load/save file. No previous saves?" );
wperror( L"open" );
return;
return;
}
debug( 4, L"File open on fd %d", c.fd );
@@ -520,14 +520,14 @@ static void load_or_save( int save)
if( save )
{
write( c.fd, SAVE_MSG, strlen(SAVE_MSG) );
write_loop( c.fd, SAVE_MSG, strlen(SAVE_MSG) );
enqueue_all( &c );
}
else
read_message( &c );
connection_destroy( &c );
connection_destroy( &c );
}
/**
@@ -553,10 +553,10 @@ static void init()
{
sock = get_socket();
daemonize();
daemonize();
env_universal_common_init( &broadcast );
load();
load();
}
/**
@@ -569,13 +569,13 @@ int main( int argc, char ** argv )
socklen_t t;
int max_fd;
int update_count=0;
fd_set read_fd, write_fd;
halloc_util_init();
program_name=L"fishd";
wsetlocale( LC_ALL, L"" );
wsetlocale( LC_ALL, L"" );
/*
Parse options
@@ -586,57 +586,57 @@ int main( int argc, char ** argv )
long_options[] =
{
{
"help", no_argument, 0, 'h'
"help", no_argument, 0, 'h'
}
,
{
"version", no_argument, 0, 'v'
"version", no_argument, 0, 'v'
}
,
{
0, 0, 0, 0
{
0, 0, 0, 0
}
}
;
int opt_index = 0;
int opt = getopt_long( argc,
argv,
argv,
GETOPT_STRING,
long_options,
long_options,
&opt_index );
if( opt == -1 )
break;
switch( opt )
{
case 0:
break;
break;
case 'h':
print_help( argv[0], 1 );
exit(0);
exit(0);
case 'v':
debug( 0, L"%ls, version %s\n", program_name, PACKAGE_VERSION );
exit( 0 );
exit( 0 );
case '?':
return 1;
}
}
}
init();
while(1)
while(1)
{
connection_t *c;
int res;
t = sizeof( remote );
t = sizeof( remote );
FD_ZERO( &read_fd );
FD_ZERO( &write_fd );
FD_SET( sock, &read_fd );
@@ -645,7 +645,7 @@ int main( int argc, char ** argv )
{
FD_SET( c->fd, &read_fd );
max_fd = maxi( max_fd, c->fd+1);
if( ! q_empty( &c->unsent ) )
{
FD_SET( c->fd, &write_fd );
@@ -661,22 +661,22 @@ int main( int argc, char ** argv )
save();
exit(0);
}
if( res != -1 )
break;
if( errno != EINTR )
{
wperror( L"select" );
exit(1);
}
}
if( FD_ISSET( sock, &read_fd ) )
{
if( (child_socket =
accept( sock,
(struct sockaddr *)&remote,
if( (child_socket =
accept( sock,
(struct sockaddr *)&remote,
&t) ) == -1) {
wperror( L"accept" );
exit(1);
@@ -688,20 +688,20 @@ int main( int argc, char ** argv )
if( fcntl( child_socket, F_SETFL, O_NONBLOCK ) != 0 )
{
wperror( L"fcntl" );
close( child_socket );
close( child_socket );
}
else
{
connection_t *new = malloc( sizeof(connection_t));
connection_init( new, child_socket );
connection_init( new, child_socket );
new->next = conn;
send( new->fd, GREETING, strlen(GREETING), MSG_DONTWAIT );
enqueue_all( new );
enqueue_all( new );
conn=new;
}
}
}
for( c=conn; c; c=c->next )
{
if( FD_ISSET( c->fd, &write_fd ) )
@@ -709,7 +709,7 @@ int main( int argc, char ** argv )
try_send_all( c );
}
}
for( c=conn; c; c=c->next )
{
if( FD_ISSET( c->fd, &read_fd ) )
@@ -728,10 +728,10 @@ int main( int argc, char ** argv )
}
}
}
connection_t *prev=0;
c=conn;
while( c )
{
if( c->killme )
@@ -745,7 +745,7 @@ int main( int argc, char ** argv )
if( !msg->count )
free( msg );
}
connection_destroy( c );
if( prev )
{
@@ -755,11 +755,11 @@ int main( int argc, char ** argv )
{
conn=c->next;
}
free(c);
c=(prev?prev->next:conn);
}
else
{
@@ -771,10 +771,10 @@ int main( int argc, char ** argv )
if( !conn )
{
debug( 0, L"No more clients. Quitting" );
save();
save();
env_universal_common_destroy();
break;
}
}
}
halloc_util_destroy();

View File

@@ -41,9 +41,9 @@
typedef struct
{
/** Function definition */
wchar_t *cmd;
wchar_t *definition;
/** Function description */
wchar_t *desc;
wchar_t *description;
/**
File where this function was defined
*/
@@ -51,16 +51,23 @@ typedef struct
/**
Line where definition started
*/
int definition_offset;
int definition_offset;
/**
List of all named arguments for this function
*/
array_list_t *named_arguments;
/**
Flag for specifying that this function was automatically loaded
*/
int is_autoload;
/**
Set to non-zero if invoking this function shadows the variables
of the underlying function.
*/
int shadows;
}
function_internal_data_t;
@@ -89,8 +96,8 @@ static int load( const wchar_t *name )
data = (function_internal_data_t *)hash_get( &function, name );
if( data && !data->is_autoload )
return 0;
is_autoload = 1;
is_autoload = 1;
res = parse_util_load( name,
L"fish_function_path",
&function_remove,
@@ -106,13 +113,13 @@ static int load( const wchar_t *name )
static void autoload_names( array_list_t *out, int get_hidden )
{
int i;
array_list_t path_list;
const wchar_t *path_var = env_get( L"fish_function_path" );
if( ! path_var )
return;
al_init( &path_list );
tokenize_variable_array( path_var, &path_list );
@@ -122,7 +129,7 @@ static void autoload_names( array_list_t *out, int get_hidden )
DIR *dir = wopendir( ndir );
if( !dir )
continue;
struct wdirent *next;
while( (next=wreaddir(dir))!=0 )
{
@@ -130,7 +137,7 @@ static void autoload_names( array_list_t *out, int get_hidden )
wchar_t *suffix;
if( !get_hidden && fn[0] == L'_' )
continue;
suffix = wcsrchr( fn, L'.' );
if( suffix && (wcscmp( suffix, L".fish" ) == 0 ) )
{
@@ -141,7 +148,7 @@ static void autoload_names( array_list_t *out, int get_hidden )
DIE_MEM();
al_push( out, dup );
}
}
}
closedir(dir);
}
al_foreach( &path_list, &free );
@@ -155,6 +162,9 @@ void function_init()
&hash_wcs_cmp );
}
/**
Clear specified value, but not key
*/
static void clear_entry( void *key, void *value )
{
halloc_free( value );
@@ -172,15 +182,15 @@ void function_add( function_data_t *data )
int i;
wchar_t *cmd_end;
function_internal_data_t *d;
CHECK( data->name, );
CHECK( data->definition, );
function_remove( data->name );
d = halloc( 0, sizeof( function_internal_data_t ) );
d->definition_offset = parse_util_lineno( parser_get_buffer(), current_block->tok_pos )-1;
d->cmd = halloc_wcsdup( d, data->definition );
d->definition = halloc_wcsdup( d, data->definition );
if( data->named_arguments )
{
@@ -191,31 +201,68 @@ void function_add( function_data_t *data )
al_push( d->named_arguments, halloc_wcsdup( d, (wchar_t *)al_get( data->named_arguments, i ) ) );
}
}
cmd_end = d->cmd + wcslen(d->cmd)-1;
d->desc = data->description?halloc_wcsdup( d, data->description ):0;
cmd_end = d->definition + wcslen(d->definition)-1;
d->description = data->description?halloc_wcsdup( d, data->description ):0;
d->definition_file = intern(reader_current_filename());
d->is_autoload = is_autoload;
d->shadows = data->shadows;
hash_put( &function, intern(data->name), d );
for( i=0; i<al_get_count( data->events ); i++ )
{
event_add_handler( (event_t *)al_get( data->events, i ) );
}
}
int function_copy( const wchar_t *name, const wchar_t *new_name )
{
int i;
function_internal_data_t *d, *orig_d;
CHECK( name, 0 );
CHECK( new_name, 0 );
orig_d = (function_internal_data_t *)hash_get(&function, name);
if( !orig_d )
return 0;
d = halloc(0, sizeof( function_internal_data_t ) );
d->definition_offset = orig_d->definition_offset;
d->definition = halloc_wcsdup( d, orig_d->definition );
if( orig_d->named_arguments )
{
d->named_arguments = al_halloc( d );
for( i=0; i<al_get_count( orig_d->named_arguments ); i++ )
{
al_push( d->named_arguments, halloc_wcsdup( d, (wchar_t *)al_get( orig_d->named_arguments, i ) ) );
}
d->description = orig_d->description?halloc_wcsdup(d, orig_d->description):0;
d->shadows = orig_d->shadows;
// This new instance of the function shouldn't be tied to the def
// file of the original.
d->definition_file = 0;
d->is_autoload = 0;
}
hash_put( &function, intern(new_name), d );
return 1;
}
int function_exists( const wchar_t *cmd )
{
CHECK( cmd, 0 );
if( parser_keywords_is_reserved(cmd) )
return 0;
load( cmd );
return (hash_get(&function, cmd) != 0 );
}
@@ -226,7 +273,7 @@ void function_remove( const wchar_t *name )
void *dv;
function_internal_data_t *d;
event_t ev;
CHECK( name, );
hash_remove( &function,
@@ -235,12 +282,12 @@ void function_remove( const wchar_t *name )
&dv );
d=(function_internal_data_t *)dv;
if( !key )
return;
ev.type=EVENT_ANY;
ev.function_name=name;
ev.function_name=name;
event_remove( &ev );
halloc_free( d );
@@ -255,26 +302,26 @@ void function_remove( const wchar_t *name )
parse_util_unload( name, L"fish_function_path", 0 );
}
}
const wchar_t *function_get_definition( const wchar_t *name )
{
function_internal_data_t *data;
CHECK( name, 0 );
load( name );
data = (function_internal_data_t *)hash_get( &function, name );
if( data == 0 )
return 0;
return data->cmd;
return data->definition;
}
array_list_t *function_get_named_arguments( const wchar_t *name )
{
function_internal_data_t *data;
CHECK( name, 0 );
load( name );
data = (function_internal_data_t *)hash_get( &function, name );
if( data == 0 )
@@ -285,9 +332,9 @@ array_list_t *function_get_named_arguments( const wchar_t *name )
int function_get_shadows( const wchar_t *name )
{
function_internal_data_t *data;
CHECK( name, 0 );
load( name );
data = (function_internal_data_t *)hash_get( &function, name );
if( data == 0 )
@@ -295,34 +342,34 @@ int function_get_shadows( const wchar_t *name )
return data->shadows;
}
const wchar_t *function_get_desc( const wchar_t *name )
{
function_internal_data_t *data;
CHECK( name, 0 );
load( name );
data = (function_internal_data_t *)hash_get( &function, name );
if( data == 0 )
return 0;
return _(data->desc);
return _(data->description);
}
void function_set_desc( const wchar_t *name, const wchar_t *desc )
{
function_internal_data_t *data;
CHECK( name, );
CHECK( desc, );
load( name );
data = (function_internal_data_t *)hash_get( &function, name );
if( data == 0 )
return;
data->desc = halloc_wcsdup( data, desc );
data->description = halloc_wcsdup( data, desc );
}
/**
@@ -331,6 +378,10 @@ void function_set_desc( const wchar_t *name, const wchar_t *desc )
static int al_contains_str( array_list_t *list, const wchar_t * str )
{
int i;
CHECK( list, 0 );
CHECK( str, 0 );
for( i=0; i<al_get_count( list ); i++ )
{
if( wcscmp( al_get( list, i ), str) == 0 )
@@ -340,9 +391,9 @@ static int al_contains_str( array_list_t *list, const wchar_t * str )
}
return 0;
}
/**
Helper function for removing hidden functions
Helper function for removing hidden functions
*/
static void get_names_internal( void *key,
void *val,
@@ -356,14 +407,14 @@ static void get_names_internal( void *key,
}
/**
Helper function for removing hidden functions
Helper function for removing hidden functions
*/
static void get_names_internal_all( void *key,
void *val,
void *aux )
{
wchar_t *name = (wchar_t *)key;
if( !al_contains_str( (array_list_t *)aux, name ) )
{
al_push( (array_list_t *)aux, name );
@@ -373,9 +424,9 @@ static void get_names_internal_all( void *key,
void function_get_names( array_list_t *list, int get_hidden )
{
CHECK( list, );
autoload_names( list, get_hidden );
if( get_hidden )
{
hash_foreach2( &function, &get_names_internal_all, list );
@@ -384,7 +435,7 @@ void function_get_names( array_list_t *list, int get_hidden )
{
hash_foreach2( &function, &get_names_internal, list );
}
}
const wchar_t *function_get_definition_file( const wchar_t *name )
@@ -392,11 +443,11 @@ const wchar_t *function_get_definition_file( const wchar_t *name )
function_internal_data_t *data;
CHECK( name, 0 );
data = (function_internal_data_t *)hash_get( &function, name );
if( data == 0 )
return 0;
return data->definition_file;
}
@@ -406,11 +457,11 @@ int function_get_definition_offset( const wchar_t *name )
function_internal_data_t *data;
CHECK( name, -1 );
data = (function_internal_data_t *)hash_get( &function, name );
if( data == 0 )
return -1;
return data->definition_offset;
}

View File

@@ -1,4 +1,4 @@
/** \file function.h
/** \file function.h
Prototypes for functions for storing and retrieving function
information. These functions also take care of autoloading
@@ -15,22 +15,45 @@
#include "util.h"
/**
Structure describing a function
*/
Structure describing a function. This is used by the parser to
store data on a function while parsing it. It is not used
internally to store functions, the function_internal_data_t
structure is used for that purpose. Parhaps these two should be
merged.
*/
typedef struct function_data
{
/**
Name of function
*/
wchar_t *name;
/**
Description of function
*/
wchar_t *description;
/**
Function definition
*/
wchar_t *definition;
/**
List of all event handlers for this function
*/
array_list_t *events;
/**
List of all named arguments for this function
*/
array_list_t *named_arguments;
/**
Set to non-zero if invoking this function shadows the variables
of the underlying function.
*/
int shadows;
}
function_data_t;
/**
Initialize function data
Initialize function data
*/
void function_init();
@@ -73,11 +96,11 @@ int function_exists( const wchar_t *name );
/**
Insert all function names into l. These are not copies of the
strings and should not be freed after use.
\param list the list to add the names to
\param get_hidden whether to include hidden functions, i.e. ones starting with an underscore
*/
void function_get_names( array_list_t *list,
void function_get_names( array_list_t *list,
int get_hidden );
/**
@@ -108,4 +131,10 @@ array_list_t *function_get_named_arguments( const wchar_t *name );
*/
int function_get_shadows( const wchar_t *name );
/**
Creates a new function using the same definition as the specified function.
Returns non-zero if copy is successful.
*/
int function_copy( const wchar_t *name, const wchar_t *new_name );
#endif

View File

@@ -78,6 +78,9 @@ typedef struct halloc
}
halloc_t;
/**
Allign the specified pointer
*/
static char *align_ptr( char *in )
{
unsigned long step = maxi(sizeof(double),sizeof(void *));
@@ -87,6 +90,9 @@ static char *align_ptr( char *in )
return (char *)long_out;
}
/**
Allign specifies size_t
*/
static size_t align_sz( size_t in )
{
size_t step = maxi(sizeof(double),sizeof(void *));
@@ -119,37 +125,37 @@ static void halloc_report()
{
if( getpid() == pid )
{
debug( 1, L"%d parents, %d children with average child size of %.2f bytes caused %d allocs, average spill of %.2f bytes",
debug( 1, L"%d parents, %d children with average child size of %.2f bytes caused %d allocs, average spill of %.2f bytes",
parent_count, child_count, (double)child_size/child_count,
parent_count+alloc_count, (double)alloc_spill/(parent_count+alloc_count) );
parent_count+alloc_count, (double)alloc_spill/(parent_count+alloc_count) );
}
}
#endif
void *halloc( void *context, size_t size )
{
{
halloc_t *me, *parent;
if( context )
{
char *res;
char *aligned;
#ifdef HALLOC_DEBUG
if( !child_count )
{
pid = getpid();
atexit( &halloc_report );
}
child_count++;
child_size += size;
#endif
#endif
parent = halloc_from_data( context );
/*
Align memory address
Align memory address
*/
aligned = align_ptr( parent->scratch );
@@ -157,7 +163,7 @@ void *halloc( void *context, size_t size )
if( parent->scratch_free < 0 )
parent->scratch_free=0;
parent->scratch = aligned;
if( size <= parent->scratch_free )
@@ -171,8 +177,8 @@ void *halloc( void *context, size_t size )
#ifdef HALLOC_DEBUG
alloc_count++;
#endif
#endif
if( parent->scratch_free < HALLOC_SCRAP_SIZE )
{
#ifdef HALLOC_DEBUG
@@ -192,23 +198,23 @@ void *halloc( void *context, size_t size )
}
al_push_func( &parent->children, &late_free );
al_push( &parent->children, res );
}
return res;
}
else
{
me = (halloc_t *)calloc( 1, align_sz(sizeof(halloc_t)) + align_sz(size) + HALLOC_BLOCK_SIZE );
if( !me )
DIE_MEM();
#ifdef HALLOC_DEBUG
parent_count++;
#endif
#endif
me->scratch = ((char *)me) + align_sz(sizeof(halloc_t)) + align_sz(size);
me->scratch_free = HALLOC_BLOCK_SIZE;
al_init( &me->children );
return ((char *)me) + align_sz(sizeof(halloc_t));
}
@@ -219,7 +225,7 @@ void halloc_register_function( void *context, void (*func)(void *), void *data )
halloc_t *me;
if( !context )
return;
me = halloc_from_data( context );
al_push_func( &me->children, func );
al_push( &me->children, data );
@@ -229,11 +235,11 @@ void halloc_free( void *context )
{
halloc_t *me;
int i;
if( !context )
return;
me = halloc_from_data( context );
#ifdef HALLOC_DEBUG

View File

@@ -1,4 +1,4 @@
/** \file halloc.h
/** \file halloc.h
A hierarchical memory allocation system. Works mostly like talloc
used in Samba, except that an arbitrary block allocated with

View File

@@ -69,7 +69,7 @@ void *halloc_register( void *context, void *data )
{
if( !data )
return 0;
halloc_register_function( context, &free, data );
return data;
}
@@ -78,7 +78,7 @@ wchar_t *halloc_wcsdup( void *context, const wchar_t *in )
{
size_t len=wcslen(in);
wchar_t *out = halloc( context, sizeof( wchar_t)*(len+1));
if( out == 0 )
{
DIE_MEM();
@@ -95,6 +95,6 @@ wchar_t *halloc_wcsndup( void * context, const wchar_t *in, int c )
DIE_MEM();
}
wcslcpy( res, in, c+1 );
res[c] = L'\0';
return res;
res[c] = L'\0';
return res;
}

View File

@@ -41,15 +41,15 @@
*/
#define VAR_COUNT ( sizeof(highlight_var)/sizeof(wchar_t *) )
static void highlight_universal_internal( wchar_t * buff,
int *color,
int pos,
static void highlight_universal_internal( wchar_t * buff,
int *color,
int pos,
array_list_t *error );
/**
The environment variables used to specify the color of different tokens.
*/
static wchar_t *highlight_var[] =
static wchar_t *highlight_var[] =
{
L"fish_color_normal",
L"fish_color_error",
@@ -68,7 +68,7 @@ static wchar_t *highlight_var[] =
;
/**
Tests if the specified string is the prefix of any valid path in the system.
Tests if the specified string is the prefix of any valid path in the system.
\return zero it this is not a valid prefix, non-zero otherwise
*/
@@ -85,15 +85,15 @@ static int is_potential_path( const wchar_t *path )
if( tilde )
{
halloc_register( context, tilde );
unescaped = unescape( tilde, 1 );
if( unescaped )
{
// debug( 1, L"%ls -> %ls ->%ls", path, tilde, unescaped );
halloc_register( context, unescaped );
for( in = out = unescaped; *in; in++ )
{
switch( *in )
@@ -109,25 +109,25 @@ static int is_potential_path( const wchar_t *path )
case ANY_STRING_RECURSIVE:
{
has_magic = 1;
break;
break;
}
case INTERNAL_SEPARATOR:
{
break;
}
default:
{
*(out++) = *in;
break;
}
}
}
*out = 0;
if( !has_magic && wcslen( unescaped ) )
{
int must_be_dir = 0;
@@ -146,10 +146,10 @@ static int is_potential_path( const wchar_t *path )
{
wchar_t *dir_name, *base;
struct wdirent *ent;
dir_name = wdirname( halloc_wcsdup(context, unescaped) );
base = wbasename( halloc_wcsdup(context, unescaped) );
base = wbasename( halloc_wcsdup(context, unescaped) );
if( (wcscmp( dir_name, L"/" ) == 0 ) &&
(wcscmp( base, L"/" ) == 0 ) )
{
@@ -157,7 +157,7 @@ static int is_potential_path( const wchar_t *path )
}
else if( (dir = wopendir( dir_name )) )
{
while( (ent = wreaddir( dir )) )
{
if( wcsncmp( ent->d_name, base, wcslen(base) ) == 0 )
@@ -166,19 +166,19 @@ static int is_potential_path( const wchar_t *path )
break;
}
}
closedir( dir );
}
}
}
}
}
halloc_free( context );
return res;
}
@@ -188,7 +188,7 @@ int highlight_get_color( int highlight )
int i;
int idx=0;
int result = 0;
if( highlight < 0 )
return FISH_COLOR_NORMAL;
if( highlight >= (1<<VAR_COUNT) )
@@ -202,34 +202,34 @@ int highlight_get_color( int highlight )
break;
}
}
wchar_t *val = env_get( highlight_var[idx]);
// debug( 1, L"%d -> %d -> %ls", highlight, idx, val );
// debug( 1, L"%d -> %d -> %ls", highlight, idx, val );
if( val == 0 )
val = env_get( highlight_var[0]);
if( val )
result = output_color_code( val );
if( highlight & HIGHLIGHT_VALID_PATH )
{
wchar_t *val2 = env_get( L"fish_color_valid_path" );
int result2 = output_color_code( val2 );
if( result == FISH_COLOR_NORMAL )
result = result2;
else
else
{
if( result2 & FISH_COLOR_BOLD )
result |= FISH_COLOR_BOLD;
if( result2 & FISH_COLOR_UNDERLINE )
result |= FISH_COLOR_UNDERLINE;
}
}
return result;
}
/**
@@ -240,16 +240,16 @@ static void highlight_param( const wchar_t * buff,
int pos,
array_list_t *error )
{
int mode = 0;
int mode = 0;
int in_pos, len = wcslen( buff );
int bracket_count=0;
wchar_t c;
int normal_status = *color;
for( in_pos=0;
in_pos<len;
in_pos<len;
in_pos++ )
{
c = buff[in_pos];
@@ -265,7 +265,7 @@ static void highlight_param( const wchar_t * buff,
{
int start_pos = in_pos;
in_pos++;
if( wcschr( L"~%", buff[in_pos] ) )
{
if( in_pos == 1 )
@@ -298,10 +298,10 @@ static void highlight_param( const wchar_t * buff,
long long res=0;
int chars=2;
int base=16;
int byte = 0;
wchar_t max_val = ASCII_MAX;
switch( buff[in_pos] )
{
case L'u':
@@ -310,62 +310,62 @@ static void highlight_param( const wchar_t * buff,
max_val = UCS2_MAX;
break;
}
case L'U':
{
chars=8;
max_val = WCHAR_MAX;
break;
}
case L'x':
{
break;
}
case L'X':
{
byte=1;
max_val = BYTE_MAX;
break;
}
default:
{
base=8;
chars=3;
in_pos--;
break;
}
}
}
for( i=0; i<chars; i++ )
{
int d = convert_digit( buff[++in_pos],base);
if( d < 0 )
{
in_pos--;
break;
}
res=(res*base)|d;
}
if( (res <= max_val) )
{
color[start_pos] = HIGHLIGHT_ESCAPE;
color[in_pos+1] = normal_status;
color[in_pos+1] = normal_status;
}
else
{
{
color[start_pos] = HIGHLIGHT_ERROR;
color[in_pos+1] = normal_status;
color[in_pos+1] = normal_status;
}
}
}
else
else
{
switch( buff[in_pos]){
case L'~':
@@ -381,9 +381,9 @@ static void highlight_param( const wchar_t * buff,
case L'$':
{
wchar_t n = buff[in_pos+1];
wchar_t n = buff[in_pos+1];
color[in_pos] = (n==L'$'||wcsvarchr(n))? HIGHLIGHT_OPERATOR:HIGHLIGHT_ERROR;
color[in_pos+1] = normal_status;
color[in_pos+1] = normal_status;
break;
}
@@ -397,21 +397,21 @@ static void highlight_param( const wchar_t * buff,
color[in_pos+1] = normal_status;
break;
}
case L'{':
{
color[in_pos] = HIGHLIGHT_OPERATOR;
color[in_pos+1] = normal_status;
bracket_count++;
break;
break;
}
case L'}':
{
color[in_pos] = HIGHLIGHT_OPERATOR;
color[in_pos+1] = normal_status;
bracket_count--;
break;
break;
}
case L',':
@@ -422,16 +422,16 @@ static void highlight_param( const wchar_t * buff,
color[in_pos+1] = normal_status;
}
break;
break;
}
case L'\'':
{
color[in_pos] = HIGHLIGHT_QUOTE;
mode = 1;
break;
break;
}
case L'\"':
{
color[in_pos] = HIGHLIGHT_QUOTE;
@@ -440,7 +440,7 @@ static void highlight_param( const wchar_t * buff,
}
}
}
}
break;
}
@@ -461,21 +461,21 @@ static void highlight_param( const wchar_t * buff,
color[in_pos+1] = HIGHLIGHT_QUOTE;
break;
}
case 0:
{
return;
}
}
}
if( c == L'\'' )
{
mode = 0;
color[in_pos+1] = normal_status;
}
break;
}
@@ -492,7 +492,7 @@ static void highlight_param( const wchar_t * buff,
color[in_pos+1] = normal_status;
break;
}
case '\\':
{
int start_pos = in_pos;
@@ -502,7 +502,7 @@ static void highlight_param( const wchar_t * buff,
{
return;
}
case '\\':
case L'$':
case '"':
@@ -514,26 +514,40 @@ static void highlight_param( const wchar_t * buff,
}
break;
}
case '$':
{
wchar_t n = buff[in_pos+1];
color[in_pos] = (n==L'$'||wcsvarchr(n))? HIGHLIGHT_OPERATOR:HIGHLIGHT_ERROR;
color[in_pos+1] = HIGHLIGHT_QUOTE;
color[in_pos+1] = HIGHLIGHT_QUOTE;
break;
}
}
}
break;
}
}
}
}
static int has_expand_reserved( wchar_t *str )
{
while( *str )
{
if( *str >= EXPAND_RESERVED &&
*str <= EXPAND_RESERVED_END )
{
return 1;
}
str++;
}
return 0;
}
void highlight_shell( wchar_t * buff,
int *color,
int pos,
void highlight_shell( wchar_t * buff,
int *color,
int pos,
array_list_t *error )
{
tokenizer tok;
@@ -545,29 +559,29 @@ void highlight_shell( wchar_t * buff,
void *context;
wchar_t *cmd=0;
int accept_switches = 1;
int accept_switches = 1;
int use_function = 1;
int use_command = 1;
int use_builtin = 1;
CHECK( buff, );
CHECK( color, );
len = wcslen(buff);
if( !len )
return;
context = halloc( 0, 0 );
for( i=0; buff[i] != 0; i++ )
color[i] = -1;
for( tok_init( &tok, buff, TOK_SHOW_COMMENTS );
tok_has_next( &tok );
tok_next( &tok ) )
{
{
int last_type = tok_last_type( &tok );
int prev_argc=0;
@@ -577,7 +591,7 @@ void highlight_shell( wchar_t * buff,
{
if( had_cmd )
{
/*Parameter */
wchar_t *param = tok_last( &tok );
if( param[0] == L'-' )
@@ -602,44 +616,44 @@ void highlight_shell( wchar_t * buff,
else
{
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_PARAM;
}
}
if( cmd && (wcscmp( cmd, L"cd" ) == 0) )
{
wchar_t *dir = expand_one( context,
wchar_t *dir = expand_one( context,
wcsdup(tok_last( &tok )),
EXPAND_SKIP_CMDSUBST );
if( dir )
{
int is_long_help = wcsncmp(dir,L"--help", wcslen(dir) );
int is_short_help = wcsncmp(dir,L"-h", wcslen(dir) );
if( !is_long_help && !is_short_help && !path_get_cdpath( context, dir ) )
{
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
}
}
}
highlight_param( param,
&color[tok_get_pos( &tok )],
pos-tok_get_pos( &tok ),
pos-tok_get_pos( &tok ),
error );
}
else
{
{
prev_argc=0;
/*
Command. First check that the command actually exists.
*/
cmd = expand_one( context,
wcsdup(tok_last( &tok )),
EXPAND_SKIP_CMDSUBST | EXPAND_SKIP_VARIABLES);
if( cmd == 0 )
cmd = expand_one( context,
wcsdup(tok_last( &tok )),
EXPAND_SKIP_CMDSUBST | EXPAND_SKIP_VARIABLES);
if( (cmd == 0) || has_expand_reserved( cmd ) )
{
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
}
@@ -652,9 +666,9 @@ void highlight_shell( wchar_t * buff,
if( parser_keywords_is_subcommand( cmd ) )
{
int sw;
if( wcscmp( cmd, L"builtin" )==0)
{
use_function = 0;
@@ -669,13 +683,13 @@ void highlight_shell( wchar_t * buff,
}
tok_next( &tok );
sw = parser_keywords_is_switch( tok_last( &tok ) );
if( !parser_keywords_is_block( cmd ) &&
sw == ARG_SWITCH )
{
/*
/*
The 'builtin' and 'command' builtins
are normally followed by another
command, but if they are invoked
@@ -693,7 +707,7 @@ void highlight_shell( wchar_t * buff,
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_PARAM;
mark = tok_get_pos( &tok );
}
is_subcommand = 1;
}
tok_set_pos( &tok, mark );
@@ -716,7 +730,7 @@ void highlight_shell( wchar_t * buff,
*/
if( use_builtin )
is_cmd |= builtin_exists( cmd );
if( use_function )
is_cmd |= function_exists( cmd );
@@ -729,16 +743,16 @@ void highlight_shell( wchar_t * buff,
*/
if( use_command )
is_cmd |= !!(tmp=path_get_path( context, cmd ));
/*
/*
Could not find the command. Maybe it is
a path for a implicit cd command.
*/
if( use_builtin || (use_function && function_exists( L"cd") ) )
is_cmd |= !!(tmp=path_get_cdpath( context, cmd ));
if( is_cmd )
{
{
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_COMMAND;
}
else
@@ -752,14 +766,14 @@ void highlight_shell( wchar_t * buff,
if( had_cmd )
{
last_cmd = halloc_wcsdup( context, tok_last( &tok ) );
last_cmd = halloc_wcsdup( context, tok_last( &tok ) );
}
}
}
break;
}
case TOK_REDIRECT_NOCLOB:
case TOK_REDIRECT_OUT:
case TOK_REDIRECT_IN:
@@ -773,9 +787,9 @@ void highlight_shell( wchar_t * buff,
al_push( error, wcsdup ( L"Redirection without a command" ) );
break;
}
wchar_t *target=0;
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_REDIRECTION;
tok_next( &tok );
@@ -789,7 +803,7 @@ void highlight_shell( wchar_t * buff,
{
target = expand_one( context, wcsdup( tok_last( &tok ) ), EXPAND_SKIP_CMDSUBST);
/*
Redirect filename may contain a cmdsubst.
Redirect filename may contain a cmdsubst.
If so, it will be ignored/not flagged.
*/
}
@@ -800,7 +814,7 @@ void highlight_shell( wchar_t * buff,
if( error )
al_push( error, wcsdup ( L"Invalid redirection" ) );
}
}
if( target != 0 )
@@ -808,7 +822,7 @@ void highlight_shell( wchar_t * buff,
wchar_t *dir = halloc_wcsdup( context, target );
wchar_t *dir_end = wcsrchr( dir, L'/' );
struct stat buff;
/*
/*
If file is in directory other than '.', check
that the directory exists.
*/
@@ -820,15 +834,15 @@ void highlight_shell( wchar_t * buff,
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
if( error )
al_push( error, wcsdupcat( L"Directory \'", dir, L"\' does not exist" ) );
}
}
/*
If the file is read from or appended to, check
if it exists.
*/
if( last_type == TOK_REDIRECT_IN ||
if( last_type == TOK_REDIRECT_IN ||
last_type == TOK_REDIRECT_APPEND )
{
if( wstat( target, &buff ) == -1 )
@@ -850,7 +864,7 @@ void highlight_shell( wchar_t * buff,
}
break;
}
case TOK_PIPE:
case TOK_BACKGROUND:
{
@@ -865,14 +879,14 @@ void highlight_shell( wchar_t * buff,
}
else
{
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
if( error )
al_push( error, wcsdup ( L"No job to put in background" ) );
}
break;
}
case TOK_END:
{
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_END;
@@ -883,13 +897,13 @@ void highlight_shell( wchar_t * buff,
accept_switches = 1;
break;
}
case TOK_COMMENT:
{
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_COMMENT;
break;
}
case TOK_ERROR:
default:
{
@@ -899,13 +913,13 @@ void highlight_shell( wchar_t * buff,
if( error )
al_push( error, wcsdup ( tok_last( &tok) ) );
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
break;
}
break;
}
}
}
tok_destroy( &tok );
tok_destroy( &tok );
/*
Locate and syntax highlight cmdsubsts recursively
*/
@@ -913,32 +927,32 @@ void highlight_shell( wchar_t * buff,
wchar_t *buffcpy = halloc_wcsdup( context, buff );
wchar_t *subpos=buffcpy;
int done=0;
while( 1 )
{
wchar_t *begin, *end;
if( parse_util_locate_cmdsubst( subpos,
&begin,
if( parse_util_locate_cmdsubst( subpos,
&begin,
&end,
1) <= 0)
{
break;
}
if( !*end )
done=1;
else
*end=0;
highlight_shell( begin+1, color +(begin-buffcpy)+1, -1, error );
color[end-buffcpy]=HIGHLIGHT_OPERATOR;
if( done )
break;
subpos = end+1;
subpos = end+1;
}
/*
@@ -961,15 +975,15 @@ void highlight_shell( wchar_t * buff,
if( pos >= 0 && pos <= len )
{
wchar_t *tok_begin, *tok_end;
wchar_t *token;
parse_util_token_extent( buff, pos, &tok_begin, &tok_end, 0, 0 );
if( tok_begin && tok_end )
{
token = halloc_wcsndup( context, tok_begin, tok_end-tok_begin );
if( is_potential_path( token ) )
{
for( i=tok_begin-buff; i < (tok_end-buff); i++ )
@@ -979,7 +993,7 @@ void highlight_shell( wchar_t * buff,
}
}
}
highlight_universal_internal( buff, color, pos, error );
@@ -995,21 +1009,21 @@ void highlight_shell( wchar_t * buff,
}
halloc_free( context );
}
/**
Perform quote and parenthesis highlighting on the specified string.
*/
static void highlight_universal_internal( wchar_t * buff,
int *color,
int pos,
static void highlight_universal_internal( wchar_t * buff,
int *color,
int pos,
array_list_t *error )
{
if( (pos >= 0) && (pos < wcslen(buff)) )
{
/*
Highlight matching quotes
*/
@@ -1018,14 +1032,14 @@ static void highlight_universal_internal( wchar_t * buff,
array_list_t l;
al_init( &l );
int level=0;
wchar_t prev_q=0;
wchar_t *str=buff;
int match_found=0;
while(*str)
{
switch( *str )
@@ -1046,7 +1060,7 @@ static void highlight_universal_internal( wchar_t * buff,
if( prev_q == *str )
{
long pos1, pos2;
level--;
pos1 = al_pop_long( &l );
pos2 = str-buff;
@@ -1055,7 +1069,7 @@ static void highlight_universal_internal( wchar_t * buff,
color[pos1]|=HIGHLIGHT_MATCH<<16;
color[pos2]|=HIGHLIGHT_MATCH<<16;
match_found = 1;
}
prev_q = *str==L'\"'?L'\'':L'\"';
}
@@ -1066,7 +1080,7 @@ static void highlight_universal_internal( wchar_t * buff,
prev_q = *str;
}
}
break;
}
if( (*str == L'\0'))
@@ -1076,7 +1090,7 @@ static void highlight_universal_internal( wchar_t * buff,
}
al_destroy( &l );
if( !match_found )
color[pos] = HIGHLIGHT_ERROR<<16;
}
@@ -1091,7 +1105,7 @@ static void highlight_universal_internal( wchar_t * buff,
wchar_t inc_char = buff[pos];
int level = 0;
wchar_t *str = &buff[pos];
int match_found=0;
int match_found=0;
while( (str >= buff) && *str)
{
@@ -1109,22 +1123,22 @@ static void highlight_universal_internal( wchar_t * buff,
}
str+= step;
}
if( !match_found )
color[pos] = HIGHLIGHT_ERROR<<16;
}
}
}
void highlight_universal( wchar_t * buff,
int *color,
int pos,
void highlight_universal( wchar_t * buff,
int *color,
int pos,
array_list_t *error )
{
int i;
for( i=0; buff[i]; i++ )
color[i] = 0;
highlight_universal_internal( buff, color, pos, error );
}

View File

@@ -56,7 +56,7 @@
/**
Internal value representing highlighting of an IO redirection
*/
#define HIGHLIGHT_REDIRECTION 0x800
#define HIGHLIGHT_REDIRECTION 0x800
/**
Internal value representing highlighting a potentially valid path
*/
@@ -68,7 +68,7 @@
for each character in buff.
\param buff The buffer on which to perform syntax highlighting
\param color The array in wchich to store the color codes. The first 8 bits are used for fg color, the next 8 bits for bg color.
\param color The array in wchich to store the color codes. The first 8 bits are used for fg color, the next 8 bits for bg color.
\param pos the cursor position. Used for quote matching, etc.
\param error a list in which a description of each error will be inserted. May be 0, in whcich case no error descriptions will be generated.
*/
@@ -80,7 +80,7 @@ void highlight_shell( wchar_t * buff, int *color, int pos, array_list_t *error )
for each character in buff.
\param buff The buffer on which to perform syntax highlighting
\param color The array in wchich to store the color codes. The first 8 bits are used for fg color, the next 8 bits for bg color.
\param color The array in wchich to store the color codes. The first 8 bits are used for fg color, the next 8 bits for bg color.
\param pos the cursor position. Used for quote matching, etc.
\param error a list in which a description of each error will be inserted. May be 0, in whcich case no error descriptions will be generated.
*/
@@ -90,7 +90,7 @@ void highlight_universal( wchar_t * buff, int *color, int pos, array_list_t *err
Translate from HIGHLIGHT_* to FISH_COLOR_* according to environment
variables. Defaults to FISH_COLOR_NORMAL.
Example:
Example:
If the environment variable FISH_FISH_COLOR_ERROR is set to 'red', a
call to highlight_get_color( HIGHLIGHT_ERROR) will return

232
history.c
View File

@@ -43,13 +43,13 @@
/**
A struct representiong a history list
*/
typedef struct
typedef struct
{
/**
The name of this list. Used for picking a suitable filename and for switching modes.
*/
const wchar_t *name;
/**
The items of the list. Each entry may be either a pointer to an
item_t struct or a pointer to an mmaped memory region where a
@@ -66,12 +66,12 @@ typedef struct
this session.
*/
hash_table_t session_item;
/**
The current history position
*/
int pos;
/**
This flag is set nonzero if the file containing earlier saves has ben mmaped in
*/
@@ -91,7 +91,7 @@ typedef struct
A list of indices of all previous search maches. This is used to eliminate duplicate search results.
*/
array_list_t used;
/**
Timestamp of last save
*/
@@ -114,13 +114,13 @@ typedef struct
/**
This struct represents a history item
*/
typedef struct
typedef struct
{
/**
The actual contents of the entry
*/
wchar_t *data;
/**
Original creation time for the entry
*/
@@ -154,7 +154,7 @@ static int hash_item_cmp( void *v1, void *v2 )
{
item_t *i1 = (item_t *)v1;
item_t *i2 = (item_t *)v2;
return (i1->timestamp == i2->timestamp) && (wcscmp( i1->data, i2->data )==0);
return (i1->timestamp == i2->timestamp) && (wcscmp( i1->data, i2->data )==0);
}
/**
@@ -198,7 +198,7 @@ static wchar_t *history_escape_newlines( wchar_t *in )
*/
sb_append_char( out, L'\n' );
}
}
else if( *in == L'\n' )
{
@@ -209,7 +209,7 @@ static wchar_t *history_escape_newlines( wchar_t *in )
{
sb_append_char( out, *in );
}
}
return (wchar_t *)out->buff;
}
@@ -252,15 +252,18 @@ static wchar_t *history_unescape_newlines( wchar_t *in )
return (wchar_t *)out->buff;
}
/**
Check if the specified item is already loaded
*/
static int item_is_new( history_mode_t *m, void *d )
{
{
char *begin = (char *)d;
if( !m->has_loaded || !m->mmap_start || (m->mmap_start == MAP_FAILED ) )
{
return 1;
return 1;
}
if( (begin < m->mmap_start) || (begin > (m->mmap_start+m->mmap_length) ) )
{
return 1;
@@ -274,7 +277,7 @@ static int item_is_new( history_mode_t *m, void *d )
Later calls to this function may erase the output of a previous call to this function.
*/
static item_t *item_get( history_mode_t *m, void *d )
{
{
char *begin = (char *)d;
if( item_is_new( m, d ) )
@@ -283,18 +286,18 @@ static item_t *item_get( history_mode_t *m, void *d )
}
else
{
char *end = m->mmap_start + m->mmap_length;
char *pos=begin;
int was_backslash = 0;
int was_backslash = 0;
static string_buffer_t *out = 0;
static item_t narrow_item;
int first_char = 1;
int first_char = 1;
int timestamp_mode = 0;
narrow_item.timestamp = 0;
if( !out )
{
out = sb_halloc( global_context );
@@ -307,17 +310,17 @@ static item_t *item_get( history_mode_t *m, void *d )
{
sb_clear( out );
}
while( 1 )
{
wchar_t c;
mbstate_t state;
size_t res;
memset( &state, 0, sizeof(state) );
res = mbrtowc( &c, pos, end-pos, &state );
if( res == (size_t)-1 )
{
pos++;
@@ -333,7 +336,7 @@ static item_t *item_get( history_mode_t *m, void *d )
continue;
}
pos += res;
if( c == L'\n' )
{
if( timestamp_mode )
@@ -342,21 +345,21 @@ static item_t *item_get( history_mode_t *m, void *d )
while( *time_string && !iswdigit(*time_string))
time_string++;
errno=0;
if( *time_string )
{
time_t tm;
wchar_t *end;
errno = 0;
tm = (time_t)wcstol( time_string, &end, 10 );
if( tm && !errno && !*end )
{
narrow_item.timestamp = tm;
}
}
}
sb_clear( out );
timestamp_mode = 0;
@@ -365,21 +368,21 @@ static item_t *item_get( history_mode_t *m, void *d )
if( !was_backslash )
break;
}
if( first_char )
{
if( c == L'#' )
if( c == L'#' )
timestamp_mode = 1;
}
first_char = 0;
sb_append_char( out, c );
was_backslash = ( (c == L'\\') && !was_backslash);
}
narrow_item.data = history_unescape_newlines((wchar_t *)out->buff);
return &narrow_item;
}
@@ -401,25 +404,28 @@ static int item_write( FILE *f, history_mode_t *m, void *v )
static void history_destroy_mode( history_mode_t *m )
{
halloc_free( m->item_context );
if( m->mmap_start && (m->mmap_start != MAP_FAILED ))
{
munmap( m->mmap_start, m->mmap_length);
}
}
}
/**
Free all memory used by specified mistory mode
*/
static void history_destroy_mode_wrapper( void *n, history_mode_t *m )
{
halloc_free( m );
}
/**
Create a new empty mode with the specified name.
Create a new empty mode with the specified name.
The mode is a halloc context, and the entire mode can be destroyed using halloc_free().
*/
static history_mode_t *history_create_mode( const wchar_t *name )
{
{
history_mode_t *new_mode = halloc( 0, sizeof( history_mode_t ));
new_mode->name = intern(name);
@@ -428,16 +434,16 @@ static history_mode_t *history_create_mode( const wchar_t *name )
al_init( &new_mode->used );
halloc_register_function( new_mode, (void (*)(void *))&al_destroy, &new_mode->item );
halloc_register_function( new_mode, (void (*)(void *))&al_destroy, &new_mode->used );
hash_init( &new_mode->session_item, &hash_item_func, &hash_item_cmp );
halloc_register_function( new_mode, (void (*)(void *))&hash_destroy, &new_mode->session_item );
new_mode->save_timestamp=time(0);
new_mode->item_context = halloc( 0,0 );
halloc_register_function( new_mode, (void (*)(void *))&history_destroy_mode, new_mode );
return new_mode;
return new_mode;
}
/**
@@ -458,16 +464,16 @@ static int history_test( const wchar_t *needle, const wchar_t *haystack )
static wchar_t *history_filename( void *context, const wchar_t *name, const wchar_t *suffix )
{
wchar_t *path;
wchar_t *res;
wchar_t *res;
if( !current_mode )
return 0;
path = path_get_config( context );
if( !path )
return 0;
res = wcsdupcat( path, L"/", name, L"_history", suffix?suffix:(void *)0);
halloc_register_function( context, &free, res );
return res;
@@ -477,24 +483,24 @@ static wchar_t *history_filename( void *context, const wchar_t *name, const wcha
Go through the mmaped region and insert pointers to suitable loacations into the item list
*/
static void history_populate_from_mmap( history_mode_t *m )
{
{
char *begin = m->mmap_start;
char *end = begin + m->mmap_length;
char *pos;
array_list_t old_item;
array_list_t session_item_list;
int ignore_newline = 0;
int do_push = 1;
al_init( &old_item );
al_init( &session_item_list );
al_push_all( &old_item, &m->item );
al_truncate( &m->item, 0 );
for( pos = begin; pos <end; pos++ )
{
if( do_push )
{
item_t *i;
@@ -503,14 +509,14 @@ static void history_populate_from_mmap( history_mode_t *m )
ignore_newline = *pos == '#';
i = item_get( m, pos );
if( (i_orig=hash_get( &current_mode->session_item, i ) ) )
{
/*
This item comes from this session. Insert the
original item at the end of the item list.
*/
al_push( &session_item_list, i_orig );
al_push( &session_item_list, i_orig );
}
else
{
@@ -519,10 +525,10 @@ static void history_populate_from_mmap( history_mode_t *m )
*/
al_push( &m->item, pos );
}
do_push = 0;
}
switch( *pos )
{
case '\\':
@@ -530,7 +536,7 @@ static void history_populate_from_mmap( history_mode_t *m )
pos++;
break;
}
case '\n':
{
if( ignore_newline )
@@ -540,12 +546,12 @@ static void history_populate_from_mmap( history_mode_t *m )
else
{
do_push = 1;
}
}
break;
}
}
}
}
al_push_all( &m->item, &session_item_list );
m->pos += al_get_count( &m->item );
al_push_all( &m->item, &old_item );
@@ -562,20 +568,20 @@ static void history_load( history_mode_t *m )
{
int fd;
int ok=0;
void *context;
wchar_t *filename;
if( !m )
return;
return;
m->has_loaded=1;
signal_block();
context = halloc( 0, 0 );
filename = history_filename( context, m->name, 0 );
if( filename )
{
if( ( fd = wopen( filename, O_RDONLY ) ) > 0 )
@@ -596,7 +602,7 @@ static void history_load( history_mode_t *m )
close( fd );
}
}
halloc_free( context );
signal_unblock();
}
@@ -627,12 +633,12 @@ static void history_save_mode( void *n, history_mode_t *m )
break;
}
}
if( !has_new )
{
return;
}
signal_block();
/*
@@ -641,19 +647,19 @@ static void history_save_mode( void *n, history_mode_t *m )
*/
on_disk = history_create_mode( m->name );
history_load( on_disk );
tmp_name = history_filename( on_disk, m->name, L".tmp" );
if( tmp_name )
{
tmp_name = wcsdup(tmp_name );
if( (out=wfopen( tmp_name, "w" ) ) )
{
hash_table_t mine;
hash_init( &mine, &hash_item_func, &hash_item_cmp );
for( i=0; i<al_get_count(&m->item); i++ )
{
void *ptr = al_get( &m->item, i );
@@ -663,7 +669,7 @@ static void history_save_mode( void *n, history_mode_t *m )
hash_put( &mine, item_get( m, ptr ), L"" );
}
}
/*
Re-save the old history
*/
@@ -679,14 +685,14 @@ static void history_save_mode( void *n, history_mode_t *m )
break;
}
}
}
hash_destroy( &mine );
/*
Add our own items last
*/
*/
for( i=0; ok && (i<al_get_count(&m->item)); i++ )
{
void *ptr = al_get( &m->item, i );
@@ -694,12 +700,12 @@ static void history_save_mode( void *n, history_mode_t *m )
if( is_new )
{
if( item_write( out, m, ptr ) == -1 )
{
{
ok = 0;
}
}
}
if( fclose( out ) || !ok )
{
/*
@@ -714,8 +720,8 @@ static void history_save_mode( void *n, history_mode_t *m )
}
}
free( tmp_name );
}
}
halloc_free( on_disk);
if( ok )
@@ -727,23 +733,23 @@ static void history_save_mode( void *n, history_mode_t *m )
hash table. On reload, they will be automatically inserted at
the end of the history list.
*/
if( m->mmap_start && (m->mmap_start != MAP_FAILED ) )
{
munmap( m->mmap_start, m->mmap_length );
}
al_truncate( &m->item, 0 );
al_truncate( &m->used, 0 );
m->pos = 0;
m->has_loaded = 0;
m->mmap_start=0;
m->mmap_length=0;
m->save_timestamp=time(0);
m->new_count = 0;
}
signal_unblock();
}
@@ -751,27 +757,27 @@ static void history_save_mode( void *n, history_mode_t *m )
void history_add( const wchar_t *str )
{
item_t *i;
if( !current_mode )
return;
i = halloc( current_mode->item_context, sizeof(item_t));
i->data = (wchar_t *)halloc_wcsdup( current_mode->item_context, str );
i->timestamp = time(0);
al_push( &current_mode->item, i );
hash_put( &current_mode->session_item, i, i );
al_truncate( &current_mode->used, 0 );
current_mode->pos = al_get_count( &current_mode->item );
current_mode->new_count++;
if( (time(0) > current_mode->save_timestamp+SAVE_INTERVAL) || (current_mode->new_count >= SAVE_COUNT) )
{
history_save_mode( 0, current_mode );
}
}
/**
@@ -790,9 +796,9 @@ static int history_is_used( const wchar_t *str )
if( wcscmp( it->data, str ) == 0 )
{
res = 1;
break;
break;
}
}
return res;
}
@@ -807,11 +813,11 @@ const wchar_t *history_prev_match( const wchar_t *needle )
{
item_t *i = item_get( current_mode, al_get( &current_mode->item, current_mode->pos ) );
wchar_t *haystack = (wchar_t *)i->data;
if( history_test( needle, haystack ) )
{
int is_used;
/*
This is ugly. Whenever we call item_get(),
there is a chance that the return value of any
@@ -823,11 +829,11 @@ const wchar_t *history_prev_match( const wchar_t *needle )
*/
haystack = wcsdup(haystack );
is_used = history_is_used( haystack );
free( haystack );
if( !is_used )
{
i = item_get( current_mode, al_get( &current_mode->item, current_mode->pos ) );
@@ -837,7 +843,7 @@ const wchar_t *history_prev_match( const wchar_t *needle )
}
}
}
if( !current_mode->has_loaded )
{
/*
@@ -858,9 +864,9 @@ const wchar_t *history_prev_match( const wchar_t *needle )
if( al_peek_long( &current_mode->used ) != -1 )
al_push_long( &current_mode->used, -1 );
}
}
return needle;
}
@@ -871,7 +877,7 @@ wchar_t *history_get( int idx )
if( !current_mode )
return 0;
len = al_get_count( &current_mode->item );
if( (idx >= len ) && !current_mode->has_loaded )
@@ -879,13 +885,13 @@ wchar_t *history_get( int idx )
history_load( current_mode );
len = al_get_count( &current_mode->item );
}
if( idx < 0 )
return 0;
if( idx >= len )
return 0;
return item_get( current_mode, al_get( &current_mode->item, len - 1 - idx ) )->data;
}
@@ -897,9 +903,9 @@ void history_first()
{
history_load( current_mode );
}
current_mode->pos = 0;
}
}
}
void history_reset()
@@ -911,7 +917,7 @@ void history_reset()
Clear list of search matches
*/
al_truncate( &current_mode->used, 0 );
}
}
}
const wchar_t *history_next_match( const wchar_t *needle)
@@ -933,7 +939,7 @@ const wchar_t *history_next_match( const wchar_t *needle)
return i->data;
}
}
/*
The used-list is empty. Set position to 'past end of list'
and return the search string.
@@ -941,7 +947,7 @@ const wchar_t *history_next_match( const wchar_t *needle)
current_mode->pos = al_get_count( &current_mode->item );
}
return needle;
return needle;
}
@@ -950,16 +956,16 @@ void history_set_mode( const wchar_t *name )
if( !mode_table )
{
mode_table = malloc( sizeof(hash_table_t ));
hash_init( mode_table, &hash_wcs_func, &hash_wcs_cmp );
hash_init( mode_table, &hash_wcs_func, &hash_wcs_cmp );
}
current_mode = (history_mode_t *)hash_get( mode_table, name );
if( !current_mode )
{
current_mode = history_create_mode( name );
hash_put( mode_table, name, current_mode );
}
hash_put( mode_table, name, current_mode );
}
}
void history_init()

View File

@@ -50,7 +50,7 @@ void history_reset();
/**
Find next history item starting with str. If this moves past
the end of the history, str is returned.
the end of the history, str is returned.
*/
const wchar_t *history_next_match( const wchar_t *str);

189
input.c
View File

@@ -88,7 +88,7 @@ typedef struct
{
const wchar_t *seq; /**< Character sequence which generates this event */
const wchar_t *command; /**< command that should be evaluated by this mapping */
}
input_mapping_t;
@@ -99,7 +99,7 @@ typedef struct
{
const wchar_t *name; /**< Name of key */
const char *seq; /**< Character sequence generated on keypress */
}
terminfo_mapping_t;
@@ -107,7 +107,7 @@ typedef struct
/**
Names of all the input functions supported
*/
static const wchar_t *name_arr[] =
static const wchar_t *name_arr[] =
{
L"beginning-of-line",
L"end-of-line",
@@ -188,7 +188,7 @@ static const wchar_t *desc_arr[] =
/**
Internal code for each supported input function
*/
static const wchar_t code_arr[] =
static const wchar_t code_arr[] =
{
R_BEGINNING_OF_LINE,
R_END_OF_LINE,
@@ -230,38 +230,31 @@ static const wchar_t code_arr[] =
/**
Mappings for the current input mode
*/
static array_list_t mappings = {0,0,0};
static array_list_t mappings = {0,0,0};
/**
List of all terminfo mappings
*/
static array_list_t *terminfo_mappings = 0;
/**
Set to one when the input subsytem has been initialized.
Set to one when the input subsytem has been initialized.
*/
static int is_init = 0;
/**
Initialize terminfo.
*/
static void input_terminfo_init();
/**
Deallocate memory used by terminfo. Or at least try to. Terminfo leaks.
*/
static void input_terminfo_destroy();
/**
Returns the function description for the given function code.
*/
/*
static const wchar_t *input_get_desc( wchar_t c )
{
int i;
for( i = 0; i<(sizeof( code_arr )/sizeof(wchar_t)) ; i++ )
{
if( c == code_arr[i] )
{
return desc_arr[i];
}
}
return 0;
}
*/
void input_mapping_add( const wchar_t *sequence,
const wchar_t *command )
@@ -270,9 +263,9 @@ void input_mapping_add( const wchar_t *sequence,
CHECK( sequence, );
CHECK( command, );
// debug( 0, L"Add mapping from %ls to %ls", escape(sequence, 1), escape(command, 1 ) );
for( i=0; i<al_get_count( &mappings); i++ )
{
@@ -283,12 +276,12 @@ void input_mapping_add( const wchar_t *sequence,
return;
}
}
input_mapping_t *m = malloc( sizeof( input_mapping_t ) );
m->seq = intern( sequence );
m->command = intern(command);
al_push( &mappings, m );
al_push( &mappings, m );
}
/**
@@ -300,14 +293,14 @@ static int interrupt_handler()
/*
Fire any pending events
*/
event_fire( 0 );
event_fire( NULL );
/*
Reap stray processes, including printing exit status messages
*/
if( job_reap( 1 ) )
reader_repaint_needed();
/*
Tell the reader an event occured
*/
@@ -319,14 +312,14 @@ static int interrupt_handler()
return 3;
}
return R_NULL;
return R_NULL;
}
int input_init()
{
if( is_init )
return 1;
is_init = 1;
input_common_init( &interrupt_handler );
@@ -337,7 +330,7 @@ int input_init()
exit(1);
}
output_set_term( env_get( L"TERM" ) );
input_terminfo_init();
/*
@@ -360,22 +353,22 @@ void input_destroy()
{
if( !is_init )
return;
is_init=0;
al_foreach( &mappings, &free );
al_foreach( &mappings, &free );
al_destroy( &mappings );
input_common_destroy();
if( del_curterm( cur_term ) == ERR )
{
debug( 0, _(L"Error while closing terminfo") );
}
input_terminfo_destroy();
}
/**
@@ -385,7 +378,7 @@ static wint_t input_exec_binding( input_mapping_t *m, const wchar_t *seq )
{
wchar_t code = input_function_get_code( m->command );
if( code != -1 )
{
{
switch( code )
{
@@ -393,37 +386,37 @@ static wint_t input_exec_binding( input_mapping_t *m, const wchar_t *seq )
{
return seq[0];
}
default:
{
return code;
}
}
}
else
{
/*
This key sequence is bound to a command, which
is sent to the parser for evaluation.
*/
int last_status = proc_get_last_status();
eval( m->command, 0, TOP );
proc_set_last_status( last_status );
/*
We still need to return something to the caller, R_NULL
tells the reader that no key press needs to be handled,
tells the reader that no key press needs to be handled,
and no repaint is needed.
Bindings that produce output should emit a R_REPAINT
function by calling 'commandline -f repaint' to tell
fish that a repaint is in order.
fish that a repaint is in order.
*/
return R_NULL;
}
@@ -448,14 +441,14 @@ static wint_t input_try_mapping( input_mapping_t *m)
return input_exec_binding( m, m->seq );
}
input_unreadch( c );
if( m->seq != 0 )
{
for( j=0; m->seq[j] != L'\0' &&
for( j=0; m->seq[j] != L'\0' &&
m->seq[j] == (c=input_common_readch( j>0 )); j++ )
;
if( m->seq[j] == L'\0' )
{
return input_exec_binding( m, m->seq );
@@ -473,7 +466,7 @@ static wint_t input_try_mapping( input_mapping_t *m)
}
}
return 0;
}
void input_unreadch( wint_t ch )
@@ -483,16 +476,16 @@ void input_unreadch( wint_t ch )
wint_t input_readch()
{
int i;
CHECK_BLOCK( R_NULL );
/*
Clear the interrupted flag
*/
reader_interrupted();
/*
Search for sequence in mapping tables
*/
@@ -503,51 +496,51 @@ wint_t input_readch()
for( i=0; i<al_get_count( &mappings); i++ )
{
input_mapping_t *m = (input_mapping_t *)al_get( &mappings, i );
wint_t res = input_try_mapping( m );
wint_t res = input_try_mapping( m );
if( res )
return res;
if( wcslen( m->seq) == 0 )
{
generic = m;
}
}
/*
No matching exact mapping, try to find generic mapping.
*/
if( generic )
{
{
wchar_t arr[2]=
{
0,
0,
0
}
;
arr[0] = input_common_readch(0);
return input_exec_binding( generic, arr );
return input_exec_binding( generic, arr );
}
/*
No action to take on specified character, ignore it
and move to next one.
*/
input_common_readch( 0 ); }
input_common_readch( 0 ); }
}
void input_mapping_get_names( array_list_t *list )
{
int i;
for( i=0; i<al_get_count( &mappings ); i++ )
{
input_mapping_t *m = (input_mapping_t *)al_get( &mappings, i );
al_push( list, m->seq );
}
}
@@ -556,7 +549,7 @@ int input_mapping_erase( const wchar_t *sequence )
int ok = 0;
int i;
size_t sz = al_get_count( &mappings );
for( i=0; i<sz; i++ )
{
input_mapping_t *m = (input_mapping_t *)al_get( &mappings, i );
@@ -568,24 +561,24 @@ int input_mapping_erase( const wchar_t *sequence )
}
al_truncate( &mappings, sz-1 );
ok = 1;
free( m );
break;
}
}
return ok;
}
const wchar_t *input_mapping_get( const wchar_t *sequence )
{
int i;
size_t sz = al_get_count( &mappings );
for( i=0; i<sz; i++ )
{
input_mapping_t *m = (input_mapping_t *)al_get( &mappings, i );
@@ -603,7 +596,7 @@ const wchar_t *input_mapping_get( const wchar_t *sequence )
static void input_terminfo_init()
{
terminfo_mappings = al_halloc( 0 );
TERMINFO_ADD(key_a1);
TERMINFO_ADD(key_a3);
@@ -765,7 +758,7 @@ static void input_terminfo_init()
static void input_terminfo_destroy()
{
if( terminfo_mappings )
{
halloc_free( terminfo_mappings );
@@ -775,17 +768,17 @@ static void input_terminfo_destroy()
const wchar_t *input_terminfo_get_sequence( const wchar_t *name )
{
const char *res = 0;
int i;
int i;
static string_buffer_t *buff = 0;
int err = ENOENT;
CHECK( name, 0 );
input_init();
for( i=0; i<al_get_count( terminfo_mappings ); i++ )
{
terminfo_mapping_t *m = (terminfo_mapping_t *)al_get( terminfo_mappings, i );
if( !wcscmp( name, m->name ) )
{
res = m->seq;
@@ -793,71 +786,71 @@ const wchar_t *input_terminfo_get_sequence( const wchar_t *name )
break;
}
}
if( !res )
{
errno = err;
return 0;
}
if( !buff )
{
buff = sb_halloc( global_context );
}
sb_clear( buff );
sb_printf( buff, L"%s", res );
return (wchar_t *)buff->buff;
}
const wchar_t *input_terminfo_get_name( const wchar_t *seq )
{
int i;
int i;
static string_buffer_t *buff = 0;
CHECK( seq, 0 );
input_init();
if( !buff )
{
buff = sb_halloc( global_context );
}
for( i=0; i<al_get_count( terminfo_mappings ); i++ )
{
terminfo_mapping_t *m = (terminfo_mapping_t *)al_get( terminfo_mappings, i );
if( !m->seq )
{
continue;
}
sb_clear( buff );
sb_printf( buff, L"%s", m->seq );
if( !wcscmp( seq, (wchar_t *)buff->buff ) )
{
return m->name;
}
}
return 0;
}
void input_terminfo_get_names( array_list_t *lst, int skip_null )
{
int i;
int i;
CHECK( lst, );
input_init();
for( i=0; i<al_get_count( terminfo_mappings ); i++ )
{
terminfo_mapping_t *m = (terminfo_mapping_t *)al_get( terminfo_mappings, i );
if( skip_null && !m->seq )
{
continue;
@@ -868,10 +861,10 @@ void input_terminfo_get_names( array_list_t *lst, int skip_null )
void input_function_get_names( array_list_t *lst )
{
int i;
int i;
CHECK( lst, );
for( i=0; i<(sizeof(name_arr)/sizeof(wchar_t *)); i++ )
{
al_push( lst, name_arr[i] );
@@ -889,6 +882,6 @@ wchar_t input_function_get_code( const wchar_t *name )
return code_arr[i];
}
}
return -1;
return -1;
}

21
input.h
View File

@@ -83,25 +83,32 @@ wint_t input_readch();
/**
Push a character or a readline function onto the stack of unread
characters that input_readch will return before actually reading from fd
0.
0.
*/
void input_unreadch( wint_t ch );
/**
Add a key mapping from the specified sequence
Add a key mapping from the specified sequence to the specified command
\param mode the name of the mapping mode to add this mapping to
\param s the sequence
\param d a description of the sequence
\param cmd an input function that will be run whenever the key sequence occurs
\param sequence the sequence to bind
\param command an input function that will be run whenever the key sequence occurs
*/
void input_mapping_add( const wchar_t *sequence, const wchar_t *cmd );
void input_mapping_add( const wchar_t *sequence, const wchar_t *command );
/**
Insert all mapping names into the specified array_list_t
*/
void input_mapping_get_names( array_list_t *list );
/**
Erase binding for specified key sequence
*/
int input_mapping_erase( const wchar_t *sequence );
/**
Return the command bound to the specified key sequence
*/
const wchar_t *input_mapping_get( const wchar_t *sequence );
/**

View File

@@ -1,5 +1,5 @@
/** \file input_common.c
Implementation file for the low level input library
*/
@@ -28,7 +28,7 @@ Implementation file for the low level input library
/**
Time in milliseconds to wait for another byte to be available for
reading after \x1b is read before assuming that escape key was
reading after \\x1b is read before assuming that escape key was
pressed, and not an escape sequence.
*/
#define WAIT_ON_ESCAPE 10
@@ -55,7 +55,7 @@ void input_common_init( int (*ih)() )
void input_common_destroy()
{
}
/**
@@ -66,13 +66,13 @@ static wint_t readb()
{
unsigned char arr[1];
int do_loop = 0;
do
{
fd_set fd;
fd_set fd;
int fd_max=1;
int res;
FD_ZERO( &fd );
FD_SET( 0, &fd );
if( env_universal_server.fd > 0 )
@@ -80,9 +80,9 @@ static wint_t readb()
FD_SET( env_universal_server.fd, &fd );
fd_max = env_universal_server.fd+1;
}
do_loop = 0;
do_loop = 0;
res = select( fd_max, &fd, 0, 0, 0 );
if( res==-1 )
{
@@ -102,10 +102,10 @@ static wint_t readb()
{
return lookahead_arr[--lookahead_count];
}
}
do_loop = 1;
break;
}
@@ -116,7 +116,7 @@ static wint_t readb()
*/
return R_EOF;
}
}
}
}
else
{
@@ -124,7 +124,7 @@ static wint_t readb()
{
if( FD_ISSET( env_universal_server.fd, &fd ) )
{
debug( 3, L"Wake up on universal variable event" );
debug( 3, L"Wake up on universal variable event" );
env_universal_read_all();
do_loop = 1;
@@ -132,7 +132,7 @@ static wint_t readb()
{
return lookahead_arr[--lookahead_count];
}
}
}
}
if( FD_ISSET( 0, &fd ) )
{
@@ -144,11 +144,11 @@ static wint_t readb()
return R_EOF;
}
do_loop = 0;
}
}
}
}
while( do_loop );
return arr[0];
}
@@ -167,16 +167,16 @@ wchar_t input_common_readch( int timed )
1000 * WAIT_ON_ESCAPE
}
;
FD_ZERO( &fds );
FD_SET( 0, &fds );
count = select(1, &fds, 0, 0, &tm);
switch( count )
{
case 0:
return WEOF;
case -1:
return WEOF;
break;
@@ -185,7 +185,7 @@ wchar_t input_common_readch( int timed )
}
}
wchar_t res;
static mbstate_t state;
@@ -193,33 +193,33 @@ wchar_t input_common_readch( int timed )
{
wint_t b = readb();
char bb;
int sz;
if( (b >= R_NULL) && (b < R_NULL + 1000) )
return b;
bb=b;
sz = mbrtowc( &res, &bb, 1, &state );
switch( sz )
{
case -1:
memset (&state, '\0', sizeof (state));
debug( 2, L"Illegal input" );
return R_NULL;
debug( 2, L"Illegal input" );
return R_NULL;
case -2:
break;
case 0:
return 0;
default:
return res;
}
}
}
else
else
{
if( !timed )
{
@@ -228,7 +228,7 @@ wchar_t input_common_readch( int timed )
if( lookahead_count == 0 )
return input_common_readch(0);
}
return lookahead_arr[--lookahead_count];
}
}

View File

@@ -1,5 +1,5 @@
/** \file input_common.h
Header file for the low level input library
*/

View File

@@ -115,7 +115,7 @@ fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
chmodcmd=""
@@ -125,7 +125,7 @@ if [ x"$dir_arg" != x ]; then
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
@@ -135,7 +135,7 @@ else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
@@ -163,7 +163,7 @@ dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
@@ -202,17 +202,17 @@ else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
@@ -243,7 +243,7 @@ else
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&

View File

@@ -33,10 +33,10 @@ const wchar_t *intern( const wchar_t *in )
const wchar_t *res=0;
// debug( 0, L"intern %ls", in );
if( !in )
return 0;
if( !intern_table )
{
intern_table = malloc( sizeof( hash_table_t ) );
@@ -46,16 +46,16 @@ const wchar_t *intern( const wchar_t *in )
}
hash_init( intern_table, &hash_wcs_func, &hash_wcs_cmp );
}
if( intern_static_table )
{
res = hash_get( intern_static_table, in );
}
if( !res )
{
res = hash_get( intern_table, in );
if( !res )
{
res = wcsdup( in );
@@ -63,39 +63,39 @@ const wchar_t *intern( const wchar_t *in )
{
DIE_MEM();
}
hash_put( intern_table, res, res );
}
}
return res;
}
const wchar_t *intern_static( const wchar_t *in )
{
const wchar_t *res=0;
if( !in )
return 0;
if( !intern_static_table )
{
intern_static_table = malloc( sizeof( hash_table_t ) );
if( !intern_static_table )
{
DIE_MEM();
DIE_MEM();
}
hash_init( intern_static_table, &hash_wcs_func, &hash_wcs_cmp );
}
res = hash_get( intern_static_table, in );
if( !res )
{
res = in;
hash_put( intern_static_table, res, res );
}
return res;
}
@@ -104,7 +104,7 @@ const wchar_t *intern_static( const wchar_t *in )
*/
static void clear_value( void *key, void *data )
{
debug( 3, L"interned string: '%ls'", data );
debug( 3, L"interned string: '%ls'", data );
free( (void *)data );
}
@@ -112,17 +112,17 @@ void intern_free_all()
{
if( intern_table )
{
hash_foreach( intern_table, &clear_value );
hash_destroy( intern_table );
hash_foreach( intern_table, &clear_value );
hash_destroy( intern_table );
free( intern_table );
intern_table=0;
intern_table=0;
}
if( intern_static_table )
{
hash_destroy( intern_static_table );
hash_destroy( intern_static_table );
free( intern_static_table );
intern_static_table=0;
intern_static_table=0;
}
}

50
io.c
View File

@@ -1,7 +1,7 @@
/** \file io.c
Utilities for io redirection.
*/
#include "config.h"
@@ -56,7 +56,7 @@ void io_buffer_read( io_data_t *d )
exec_close(d->param1.pipe_fd[1] );
if( d->io_mode == IO_BUFFER )
{
{
/* if( fcntl( d->param1.pipe_fd[0], F_SETFL, 0 ) )
{
wperror( L"fcntl" );
@@ -83,17 +83,17 @@ void io_buffer_read( io_data_t *d )
*/
if( errno != EAGAIN )
{
debug( 1,
_(L"An error occured while reading output from code block on file descriptor %d"),
debug( 1,
_(L"An error occured while reading output from code block on file descriptor %d"),
d->param1.pipe_fd[0] );
wperror( L"io_buffer_read" );
wperror( L"io_buffer_read" );
}
break;
break;
}
else
{
b_append( d->param2.out_buffer, b, l );
{
b_append( d->param2.out_buffer, b, l );
}
}
}
@@ -103,14 +103,14 @@ void io_buffer_read( io_data_t *d )
io_data_t *io_buffer_create( int is_input )
{
io_data_t *buffer_redirect = malloc( sizeof( io_data_t ));
buffer_redirect->io_mode=IO_BUFFER;
buffer_redirect->next=0;
buffer_redirect->param2.out_buffer= malloc( sizeof(buffer_t));
buffer_redirect->is_input = is_input;
b_init( buffer_redirect->param2.out_buffer );
buffer_redirect->fd=is_input?0:1;
if( exec_pipe( buffer_redirect->param1.pipe_fd ) == -1 )
{
debug( 1, PIPE_ERROR );
@@ -150,9 +150,9 @@ void io_buffer_destroy( io_data_t *io_buffer )
Dont free fd for writing. This should already be free'd before
calling exec_read_io_buffer on the buffer
*/
b_destroy( io_buffer->param2.out_buffer );
free( io_buffer->param2.out_buffer );
free( io_buffer );
}
@@ -174,7 +174,7 @@ io_data_t *io_remove( io_data_t *list, io_data_t *element )
{
io_data_t *curr, *prev=0;
for( curr=list; curr; curr = curr->next )
{
{
if( element == curr )
{
if( prev == 0 )
@@ -198,32 +198,32 @@ io_data_t *io_remove( io_data_t *list, io_data_t *element )
io_data_t *io_duplicate( void *context, io_data_t *l )
{
io_data_t *res;
if( l == 0 )
return 0;
res = halloc( context, sizeof( io_data_t) );
if( !res )
{
DIE_MEM();
}
memcpy( res, l, sizeof(io_data_t ));
res->next=io_duplicate( context, l->next );
return res;
return res;
}
io_data_t *io_get( io_data_t *io, int fd )
{
if( io == 0 )
return 0;
io_data_t *res = io_get( io->next, fd );
if( res )
return res;
if( io->fd == fd )
return io;
@@ -237,14 +237,14 @@ void io_print( io_data_t *io )
{
return;
}
debug( 1, L"IO fd %d, type ", io->fd );
switch( io->io_mode )
{
case IO_PIPE:
debug( 1, L"PIPE, data %d", io->param1.pipe_fd[io->fd?1:0] );
break;
case IO_FD:
debug( 1, L"FD, copy %d", io->param1.old_fd );
break;
@@ -252,11 +252,11 @@ void io_print( io_data_t *io )
case IO_BUFFER:
debug( 1, L"BUFFER" );
break;
default:
debug( 1, L"OTHER" );
}
io_print( io->next );
}

15
io.h
View File

@@ -17,8 +17,8 @@ typedef struct io_data
int io_mode;
/** FD to redirect */
int fd;
/**
Type-specific parameter for redirection
/**
Type-specific parameter for redirection
*/
union
{
@@ -30,7 +30,7 @@ typedef struct io_data
int old_fd;
} param1
;
/**
/**
Second type-specific paramter for redirection
*/
union
@@ -38,20 +38,23 @@ typedef struct io_data
/** file creation flags to send to open for IO_FILE */
int flags;
/** buffer to save output in for IO_BUFFER */
buffer_t *out_buffer;
buffer_t *out_buffer;
/** Whether to close old_fd for IO_FD */
int close_old;
} param2
;
/**
Set to true if this is an input io redirection
*/
int is_input;
/** Pointer to the next IO redirection */
struct io_data *next;
}
io_data_t;
/**
Join two chains of io redirections
*/

View File

@@ -29,7 +29,7 @@ int main( int argc, char **argv)
{
setlocale( LC_ALL, "" );
if( argc == 2 )
{
@@ -37,24 +37,24 @@ int main( int argc, char **argv)
char *termtype = getenv ("TERM");
char *tbuff = malloc( sizeof(char)*9999);
char *res;
tgetent( term_buffer, termtype );
res = tgetstr( argv[1], &tbuff );
res = tgetstr( argv[1], &tbuff );
if( res != 0 )
{
while( *res != 0 )
{
{
printf("%d ", *res );
res++;
}
printf( "\n" );
printf( "\n" );
}
else
{
printf("Undefined sequence\n");
}
}
}
else
{
@@ -65,11 +65,11 @@ int main( int argc, char **argv)
savemodes; /* so we can reset the modes when we're done */
input_common_init(0);
tcgetattr(0,&modes); /* get the current terminal modes */
savemodes = modes; /* save a copy so we can reset them */
modes.c_lflag &= ~ICANON; /* turn off canonical mode */
modes.c_lflag &= ~ECHO; /* turn off echo mode */
modes.c_cc[VMIN]=1;
@@ -83,13 +83,13 @@ int main( int argc, char **argv)
sprintf( scratch, "dec: %d hex: %x char: %c\n", c, c, c );
else
sprintf( scratch, "dec: %d hex: %x\n", c, c );
writestr( scratch );
writestr( scratch );
}
/* reset the terminal to the saved mode */
tcsetattr(0,TCSANOW,&savemodes);
tcsetattr(0,TCSANOW,&savemodes);
input_common_destroy();
}
}
return 0;
}

124
kill.c
View File

@@ -45,19 +45,25 @@ static ll_node_t /** Last kill string */*kill_last=0, /** Current kill string */
static wchar_t *cut_buffer=0;
/**
Test if the xsel command is installed
Test if the xsel command is installed. Since this is called often,
cache the result.
*/
static int has_xsel()
{
void *context = halloc(0, 0);
wchar_t *path = path_get_path( context, L"xsel" );
int res = !!path;
halloc_free( context );
static int called=0;
static int res = 0;
if (!called) {
void *context = halloc(0, 0);
wchar_t *path = path_get_path( context, L"xsel" );
res = !!path;
halloc_free( context );
called = 1;
}
return res;
}
/**
Add the string to the internal killring
*/
@@ -65,7 +71,7 @@ static void kill_add_internal( wchar_t *str )
{
if( wcslen( str ) == 0 )
return;
if( kill_last == 0 )
{
kill_current = kill_last=malloc( sizeof( ll_node_t ) );
@@ -86,27 +92,51 @@ static void kill_add_internal( wchar_t *str )
void kill_add( wchar_t *str )
{
wchar_t *cmd = NULL;
wchar_t *escaped_str;
kill_add_internal(str);
if( !has_xsel() )
return;
/* This is for sending the kill to the X copy-and-paste buffer */
wchar_t *disp;
if( (disp = env_get( L"DISPLAY" )) )
/*
Check to see if user has set the FISH_CLIPBOARD_CMD variable,
and, if so, use it instead of checking the display, etc.
I couldn't think of a safe way to allow overide of the echo
command too, so, the command used must accept the input via stdin.
*/
wchar_t *clipboard;
if( (clipboard = env_get(L"FISH_CLIPBOARD_CMD")) )
{
escaped_str = escape( str, 1 );
cmd = wcsdupcat(L"echo -n ", escaped_str, clipboard);
}
else
{
/* This is for sending the kill to the X copy-and-paste buffer */
if( !has_xsel() ) {
return;
}
wchar_t *disp;
if( (disp = env_get( L"DISPLAY" )) )
{
escaped_str = escape( str, 1 );
cmd = wcsdupcat(L"echo ", escaped_str, L"|xsel -b" );
}
}
if (cmd != NULL)
{
wchar_t *escaped_str = escape( str, 1 );
wchar_t *cmd = wcsdupcat(L"echo ", escaped_str, L"|xsel -b" );
if( exec_subshell( cmd, 0 ) == -1 )
{
/*
Do nothing on failiure
/*
Do nothing on failiure
*/
}
free( cut_buffer );
free( cmd );
cut_buffer = escaped_str;
}
}
@@ -134,8 +164,8 @@ static void kill_remove_node( ll_node_t *n )
}
kill_current=kill_last;
free( n->data );
free( n );
}
free( n );
}
}
/**
@@ -144,13 +174,13 @@ static void kill_remove_node( ll_node_t *n )
static void kill_remove( wchar_t *s )
{
ll_node_t *n, *next=0;
if( !kill_last )
{
return;
}
for( n=kill_last;
for( n=kill_last;
n!=kill_last || next == 0 ;
n=n->prev )
{
@@ -162,13 +192,13 @@ static void kill_remove( wchar_t *s )
next = n;
}
}
void kill_replace( wchar_t *old, wchar_t *new )
{
kill_remove( old );
kill_add( new );
kill_add( new );
}
wchar_t *kill_yank_rotate()
@@ -184,13 +214,13 @@ wchar_t *kill_yank_rotate()
clipboard contents to the fish killring.
*/
static void kill_check_x_buffer()
{
{
wchar_t *disp;
if( !has_xsel() )
return;
if( (disp = env_get( L"DISPLAY" )) )
{
int i;
@@ -200,7 +230,7 @@ static void kill_check_x_buffer()
al_init( &list );
if( exec_subshell( cmd, &list ) != -1 )
{
for( i=0; i<al_get_count( &list ); i++ )
{
wchar_t *next_line = escape( (wchar_t *)al_get( &list, i ), 0 );
@@ -213,20 +243,20 @@ static void kill_check_x_buffer()
wchar_t *old = new_cut_buffer;
new_cut_buffer= wcsdupcat( new_cut_buffer, L"\\n", next_line );
free( old );
free( next_line );
free( next_line );
}
}
if( new_cut_buffer )
{
/*
/*
The buffer is inserted with backslash escapes,
since we don't really like tabs, newlines,
etc. anyway.
*/
if( cut_buffer != 0 )
{
{
if( wcscmp( new_cut_buffer, cut_buffer ) == 0 )
{
free( new_cut_buffer );
@@ -235,7 +265,7 @@ static void kill_check_x_buffer()
else
{
free( cut_buffer );
cut_buffer = 0;
cut_buffer = 0;
}
}
if( cut_buffer == 0 )
@@ -245,7 +275,7 @@ static void kill_check_x_buffer()
}
}
}
al_foreach( &list, &free );
al_destroy( &list );
}
@@ -277,22 +307,22 @@ void kill_sanity_check()
break;
if( tmp->data == 0 )
break;
if( tmp == kill_current )
{
kill_ok = 1;
break;
}
tmp = tmp->prev;
tmp = tmp->prev;
}
if( !kill_ok )
{
debug( 0,
debug( 0,
L"Killring inconsistent" );
sanity_lose();
}
}
}
}
@@ -304,12 +334,12 @@ void kill_destroy()
{
if( cut_buffer )
free( cut_buffer );
if( kill_current != 0 )
{
kill_current = kill_last->prev;
kill_last->prev = 0;
while( kill_current )
{
ll_node_t *tmp = kill_current;
@@ -317,7 +347,7 @@ void kill_destroy()
free( tmp->data );
free( tmp );
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More