mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-27 16:51:15 -03:00
Compare commits
310 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e50d0c18b0 | ||
|
|
810d5f9548 | ||
|
|
e0c317dfd4 | ||
|
|
d5320fb9f9 | ||
|
|
14c84ffbcb | ||
|
|
f71c6f3f0e | ||
|
|
6dbb9e070d | ||
|
|
47ae2a05ce | ||
|
|
810262118a | ||
|
|
f5be301a2f | ||
|
|
b1357d11b2 | ||
|
|
5fc42fcaff | ||
|
|
c1cf6a4071 | ||
|
|
972f3e121e | ||
|
|
0dd8ae4843 | ||
|
|
8a93b6f26d | ||
|
|
07717a3570 | ||
|
|
79784d3e18 | ||
|
|
c08c313c0a | ||
|
|
dfd70057b3 | ||
|
|
07dec5c3ed | ||
|
|
1ed5decf2c | ||
|
|
9b95dda6bf | ||
|
|
41015691db | ||
|
|
7e1ac2d806 | ||
|
|
35258bf1fb | ||
|
|
72025a6a38 | ||
|
|
05341b055b | ||
|
|
9d7224d756 | ||
|
|
33ec8b45a0 | ||
|
|
1dc49a4062 | ||
|
|
1123467991 | ||
|
|
4f54da3795 | ||
|
|
c8de3d24c8 | ||
|
|
31439ffb52 | ||
|
|
9111b85437 | ||
|
|
c6427c5a47 | ||
|
|
36c3bd4e8d | ||
|
|
dad549afd1 | ||
|
|
e73c2be216 | ||
|
|
b0d324f1a7 | ||
|
|
d7396ac59f | ||
|
|
3f439e9cd3 | ||
|
|
0b722864c0 | ||
|
|
75e26f0f94 | ||
|
|
8cacb33347 | ||
|
|
bf7d62fd91 | ||
|
|
4ac31e637d | ||
|
|
0ad64ad2e4 | ||
|
|
523096e5d8 | ||
|
|
0de629e009 | ||
|
|
1f6fa1208e | ||
|
|
b86856b454 | ||
|
|
6598320534 | ||
|
|
0a66dc4a31 | ||
|
|
88a2b622df | ||
|
|
e10f75483f | ||
|
|
1a66fc4c5d | ||
|
|
905b792de7 | ||
|
|
804f5ab334 | ||
|
|
f974c7c416 | ||
|
|
f3b6b74568 | ||
|
|
ab94a397c3 | ||
|
|
537ab32dd9 | ||
|
|
a2660cfb76 | ||
|
|
3743a5758b | ||
|
|
e510d10c77 | ||
|
|
f5540ff958 | ||
|
|
c2b28063e1 | ||
|
|
8d2564291d | ||
|
|
87db9517e9 | ||
|
|
ab3502fc8b | ||
|
|
22472ea980 | ||
|
|
ef705be6a5 | ||
|
|
d50fac7fe5 | ||
|
|
39c16a7770 | ||
|
|
2aad9d5a95 | ||
|
|
52aaf60510 | ||
|
|
3a2f7d0edf | ||
|
|
605fffa9d2 | ||
|
|
2229fad410 | ||
|
|
8e9384e2e8 | ||
|
|
394776c56b | ||
|
|
e3d3a1062d | ||
|
|
b4042b18c6 | ||
|
|
5379200b9e | ||
|
|
9c38ed8238 | ||
|
|
cb59da7a6f | ||
|
|
bdec900aca | ||
|
|
564d19e3bd | ||
|
|
063c4d7e67 | ||
|
|
30cfa2a445 | ||
|
|
71c2cde390 | ||
|
|
da4a4bcc18 | ||
|
|
286ce1d6a4 | ||
|
|
5064cec16d | ||
|
|
f5f5e63ddf | ||
|
|
ae878ed6ea | ||
|
|
2c5151bb78 | ||
|
|
f506f1f495 | ||
|
|
374fc09af0 | ||
|
|
54b1986986 | ||
|
|
6e9489f4f5 | ||
|
|
a52bd219b9 | ||
|
|
bdd1b6b4b2 | ||
|
|
6dfdb3ba6e | ||
|
|
48d5637178 | ||
|
|
d724b160ea | ||
|
|
7a4dc6f700 | ||
|
|
c9f43fb02d | ||
|
|
da02905250 | ||
|
|
80060229f8 | ||
|
|
10b9b06ef7 | ||
|
|
e9aba6a878 | ||
|
|
5fee5a2890 | ||
|
|
3f3fe634c8 | ||
|
|
a5156c54cb | ||
|
|
74cd64ba21 | ||
|
|
348e991d7c | ||
|
|
a1af86cb6b | ||
|
|
baa6a40d6f | ||
|
|
5082054bcb | ||
|
|
2160777d2f | ||
|
|
a97faaf664 | ||
|
|
0c1b40e3b3 | ||
|
|
e54ce9a147 | ||
|
|
36e08dc49e | ||
|
|
dd02e96712 | ||
|
|
4163040e56 | ||
|
|
0bea4c46e3 | ||
|
|
0f6fe652a4 | ||
|
|
afa0ed124f | ||
|
|
8904ab47aa | ||
|
|
25305c6b24 | ||
|
|
89c27c6d9d | ||
|
|
175dd75a3d | ||
|
|
9b74687384 | ||
|
|
fcd474afe8 | ||
|
|
3ca3b6209d | ||
|
|
9299515f3e | ||
|
|
188f0454b7 | ||
|
|
e55739296d | ||
|
|
68857220ac | ||
|
|
713c84d821 | ||
|
|
d34d05ca8b | ||
|
|
dac2129048 | ||
|
|
8cd8c3002e | ||
|
|
4b85eb32d7 | ||
|
|
5870ee7723 | ||
|
|
feec9579c2 | ||
|
|
dde3838f2d | ||
|
|
97b77d1b3a | ||
|
|
addb5a698d | ||
|
|
db0a982570 | ||
|
|
3a73b60956 | ||
|
|
f4f10a8226 | ||
|
|
d6c7e25bea | ||
|
|
f28e83d3e9 | ||
|
|
0e716763d8 | ||
|
|
50f5941a82 | ||
|
|
093cb71f91 | ||
|
|
df4fdf33c4 | ||
|
|
5694d3f027 | ||
|
|
cf8e746d0c | ||
|
|
af9c2067e1 | ||
|
|
d44dd73682 | ||
|
|
5938a93018 | ||
|
|
79ac330afb | ||
|
|
e6764f3130 | ||
|
|
710a01c945 | ||
|
|
0b7b20f013 | ||
|
|
819c20e1d8 | ||
|
|
61ebc12dd4 | ||
|
|
449a75756d | ||
|
|
5e2e9e2b9b | ||
|
|
737935ebe4 | ||
|
|
0679a6351f | ||
|
|
657e3f8147 | ||
|
|
e6b9955fc1 | ||
|
|
e1afe17671 | ||
|
|
16e2c4805a | ||
|
|
5ecd0e22bf | ||
|
|
1420744669 | ||
|
|
048f903a9d | ||
|
|
dab7e6c7b9 | ||
|
|
06de2602cb | ||
|
|
65d223e672 | ||
|
|
c0aac8996d | ||
|
|
3692074e7e | ||
|
|
954c99a5ad | ||
|
|
8c4770a26c | ||
|
|
624878d35f | ||
|
|
2375578310 | ||
|
|
084c0c5f80 | ||
|
|
d2d397d9eb | ||
|
|
607e970659 | ||
|
|
3b39b1fa03 | ||
|
|
64933d31a6 | ||
|
|
c780f1a8c9 | ||
|
|
76bb8e79b2 | ||
|
|
370aeec44d | ||
|
|
b0ae3dc9cc | ||
|
|
a900d16540 | ||
|
|
3fc1ba0f0e | ||
|
|
38ed4c0f9b | ||
|
|
5a61ae3e0d | ||
|
|
c9fe154c01 | ||
|
|
2a3b01a7a0 | ||
|
|
c2c4b24174 | ||
|
|
74a270ea32 | ||
|
|
2994378e1a | ||
|
|
baeca81305 | ||
|
|
151943f89e | ||
|
|
ad02bb9b48 | ||
|
|
e464b4270c | ||
|
|
e076f2c239 | ||
|
|
3cb24e0681 | ||
|
|
27baa6e62b | ||
|
|
fa9d00a81a | ||
|
|
04948702e0 | ||
|
|
20526687b2 | ||
|
|
0a0870180d | ||
|
|
972edef341 | ||
|
|
8ed521c817 | ||
|
|
88199d6b51 | ||
|
|
782a739736 | ||
|
|
cd19320ab2 | ||
|
|
58fd6b895a | ||
|
|
df55e89bbb | ||
|
|
91de143003 | ||
|
|
748d726ddf | ||
|
|
2caaa7526d | ||
|
|
778aa1c304 | ||
|
|
c40eb8a716 | ||
|
|
1c6236831c | ||
|
|
c1b4fa847f | ||
|
|
a6644631d9 | ||
|
|
e4f5bc69e2 | ||
|
|
03f322c715 | ||
|
|
a72d877752 | ||
|
|
d0585befb3 | ||
|
|
784c5d9fa3 | ||
|
|
52e7a7ec1c | ||
|
|
c00e1fcf26 | ||
|
|
5425970706 | ||
|
|
419b3166c8 | ||
|
|
e2714b05eb | ||
|
|
2c02b59703 | ||
|
|
ee94424b0f | ||
|
|
2b7535bb51 | ||
|
|
c5805cfd47 | ||
|
|
7ca76ef743 | ||
|
|
2c743173d3 | ||
|
|
003dfb99da | ||
|
|
dd48de068d | ||
|
|
cb179c448b | ||
|
|
c323fc226f | ||
|
|
176c1a487b | ||
|
|
2872df66d7 | ||
|
|
45412f2b1f | ||
|
|
e9790db64a | ||
|
|
8ab1d0254c | ||
|
|
4c858a10c9 | ||
|
|
b4ccce2dc3 | ||
|
|
06688fb9ea | ||
|
|
4d5c50cbb3 | ||
|
|
91d1dee06b | ||
|
|
3e030bc6c6 | ||
|
|
b9009eba96 | ||
|
|
90c5cea43d | ||
|
|
52f9560b4f | ||
|
|
91ca8610ee | ||
|
|
2efb88a30a | ||
|
|
87223c68f4 | ||
|
|
5c9570eb56 | ||
|
|
778b6a31ad | ||
|
|
4d6751c274 | ||
|
|
a03a4d1ba3 | ||
|
|
5a670e2a96 | ||
|
|
edf896f7cd | ||
|
|
e128fa1a8e | ||
|
|
e8ba091161 | ||
|
|
65d99117aa | ||
|
|
94a483d46b | ||
|
|
e750f1a3c2 | ||
|
|
3f4b47b4af | ||
|
|
f6b3fcb4f5 | ||
|
|
8fe90e4327 | ||
|
|
a17019e439 | ||
|
|
b5baac8291 | ||
|
|
f36508837b | ||
|
|
3969c1b453 | ||
|
|
1e524fbc7a | ||
|
|
3e1b0e587e | ||
|
|
2aea1d5a84 | ||
|
|
6616543991 | ||
|
|
83a3706099 | ||
|
|
7c96cb2ff8 | ||
|
|
a3c5718eb9 | ||
|
|
9b10fa4762 | ||
|
|
0f51d5ec18 | ||
|
|
73a67c2a43 | ||
|
|
6859e012d9 | ||
|
|
680cf17570 | ||
|
|
854c4aee9a | ||
|
|
104ec963c2 | ||
|
|
08eb92707a | ||
|
|
e50f43416b | ||
|
|
58755fc579 | ||
|
|
31ca1218d4 |
29
Doxyfile
29
Doxyfile
@@ -53,16 +53,6 @@ CREATE_SUBDIRS = NO
|
||||
|
||||
OUTPUT_LANGUAGE = English
|
||||
|
||||
# This tag can be used to specify the encoding used in the generated output.
|
||||
# The encoding is not always determined by the language that is chosen,
|
||||
# but also whether or not the output is meant for Windows or non-Windows users.
|
||||
# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES
|
||||
# forces the Windows encoding (this is the default for the Windows binary),
|
||||
# whereas setting the tag to NO uses a Unix-style encoding (the default for
|
||||
# all platforms other than Windows).
|
||||
|
||||
USE_WINDOWS_ENCODING = NO
|
||||
|
||||
# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
|
||||
# include brief member descriptions after the members that are listed in
|
||||
# the file and class documentation (similar to JavaDoc).
|
||||
@@ -444,7 +434,8 @@ RECURSIVE = NO
|
||||
# excluded from the INPUT source files. This way you can easily exclude a
|
||||
# subdirectory from a directory tree whose root is specified with the INPUT tag.
|
||||
|
||||
EXCLUDE =
|
||||
EXCLUDE = print_help.c xdgmimealias.c xdgmimealias.h xdgmime.c xdgmimeglob.c xdgmimeglob.h xdgmime.h xdgmimeint.c xdgmimeint.h xdgmimemagic.c xdgmimemagic.h xdgmimeparent.c xdgmimeparent.h
|
||||
|
||||
|
||||
# The EXCLUDE_SYMLINKS tag can be used select whether or not files or directories
|
||||
# that are symbolic links (a Unix filesystem feature) are excluded from the input.
|
||||
@@ -1112,22 +1103,6 @@ DOT_PATH =
|
||||
|
||||
DOTFILE_DIRS =
|
||||
|
||||
# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width
|
||||
# (in pixels) of the graphs generated by dot. If a graph becomes larger than
|
||||
# this value, doxygen will try to truncate the graph, so that it fits within
|
||||
# the specified constraint. Beware that most browsers cannot cope with very
|
||||
# large images.
|
||||
|
||||
MAX_DOT_GRAPH_WIDTH = 750
|
||||
|
||||
# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height
|
||||
# (in pixels) of the graphs generated by dot. If a graph becomes larger than
|
||||
# this value, doxygen will try to truncate the graph, so that it fits within
|
||||
# the specified constraint. Beware that most browsers cannot cope with very
|
||||
# large images.
|
||||
|
||||
MAX_DOT_GRAPH_HEIGHT = 1024
|
||||
|
||||
# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the
|
||||
# graphs generated by dot. A depth value of 3 means that only nodes reachable
|
||||
# from the root by following a path via at most 3 edges will be shown. Nodes that
|
||||
|
||||
208
Makefile.in
208
Makefile.in
@@ -53,18 +53,22 @@ 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)
|
||||
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@
|
||||
LDFLAGS_FISHD = ${LDFLAGS} @LIBS_FISHD@
|
||||
LDFLAGS_MIMEDB = ${LDFLAGS} @LIBS_MIMEDB@
|
||||
LDFLAGS_SET_COLOR = ${LDFLAGS} @LIBS_SET_COLOR@
|
||||
|
||||
#
|
||||
# Set to 1 if we have gettext
|
||||
@@ -82,15 +86,18 @@ COMMON_FILES := util.c halloc.c halloc_util.c fallback.c
|
||||
|
||||
|
||||
#
|
||||
# All objects that the system needs to build fish, except main.o
|
||||
# All objects that the system needs to build fish, except fish.o
|
||||
#
|
||||
|
||||
FISH_OBJS := function.o builtin.o complete.o env.o exec.o expand.o \
|
||||
highlight.o history.o kill.o parser.o proc.o reader.o sanity.o \
|
||||
tokenizer.o wildcard.o wgetopt.o wutil.o input.o output.o intern.o \
|
||||
env_universal.o env_universal_common.o input_common.o event.o \
|
||||
signal.o io.o parse_util.o common.o screen.o path.o
|
||||
signal.o io.o parse_util.o common.o screen.o path.o \
|
||||
parser_keywords.o
|
||||
|
||||
FISH_INDENT_OBJS := fish_indent.o print_help.o common.o \
|
||||
parser_keywords.o wutil.o tokenizer.o
|
||||
|
||||
#
|
||||
# Additional files used by builtin.o
|
||||
@@ -104,7 +111,7 @@ BUILTIN_FILES := builtin_set.c builtin_commandline.c \
|
||||
# All objects that the system needs to build fish_pager
|
||||
#
|
||||
|
||||
FISH_PAGER_OBJS := fish_pager.o output.o wutil.o tokenizer.o \
|
||||
FISH_PAGER_OBJS := fish_pager.o output.o wutil.o \
|
||||
input_common.o env_universal.o env_universal_common.o common.o \
|
||||
print_help.o
|
||||
|
||||
@@ -181,12 +188,12 @@ DOC_SRC_DIR_FILES := $(HDR_FILES_SRC) $(HELP_SRC)
|
||||
|
||||
MAIN_DIR_FILES_UNSORTED := Doxyfile Doxyfile.user Doxyfile.help.in \
|
||||
Makefile.in configure configure.ac config.h.in install-sh \
|
||||
set_color.c count.c key_reader.c $(MIME_OBJS:.o=.h) \
|
||||
set_color.c key_reader.c $(MIME_OBJS:.o=.h) \
|
||||
$(MIME_OBJS:.o=.c) $(FISH_OBJS:.o=.h) $(BUILTIN_FILES) \
|
||||
$(COMMON_FILES) $(COMMON_FILES:.c=.h) $(FISH_OBJS:.o=.c) \
|
||||
fish.spec.in INSTALL README user_doc.head.html xsel-0.9.6.tar \
|
||||
ChangeLog config.sub config.guess fish_tests.c main.c fish_pager.c \
|
||||
fishd.c seq.in
|
||||
ChangeLog config.sub config.guess fish_tests.c fish.c fish_pager.c \
|
||||
fishd.c seq.in make_vcs_completions.fish $(FISH_INDENT_OBJS:.o=.c)
|
||||
|
||||
#
|
||||
# The sorting is not meaningful in itself, but it has the side effect
|
||||
@@ -201,14 +208,14 @@ MAIN_DIR_FILES := $(sort $(MAIN_DIR_FILES_UNSORTED))
|
||||
# Files in ./etc/
|
||||
#
|
||||
|
||||
ETC_DIR_FILES :=etc/config.fish.in etc/fish_inputrc
|
||||
ETC_DIR_FILES :=etc/config.fish.in
|
||||
|
||||
|
||||
#
|
||||
# Files in ./share/
|
||||
#
|
||||
|
||||
SHARE_DIR_FILES :=share/config.fish.in share/config_interactive.fish.in
|
||||
SHARE_DIR_FILES :=share/config.fish.in
|
||||
|
||||
|
||||
#
|
||||
@@ -237,7 +244,7 @@ FUNCTIONS_DIR_FILES := $(wildcard share/functions/*.fish)
|
||||
# Programs to install
|
||||
#
|
||||
|
||||
SIMPLE_PROGRAMS := fish set_color mimedb count fish_pager fishd
|
||||
SIMPLE_PROGRAMS := fish set_color mimedb fish_pager fishd fish_indent
|
||||
PROGRAMS := $(SIMPLE_PROGRAMS) @XSEL@ @SEQ_FALLBACK@
|
||||
|
||||
|
||||
@@ -261,7 +268,7 @@ TRANSLATIONS := $(TRANSLATIONS_SRC:.po=.gmo)
|
||||
# Make everything needed for installing fish
|
||||
#
|
||||
|
||||
all: $(PROGRAMS) user_doc share/man etc/config.fish share/config.fish share/config_interactive.fish $(TRANSLATIONS)
|
||||
all: $(PROGRAMS) user_doc share/man etc/config.fish share/config.fish $(TRANSLATIONS)
|
||||
@echo fish has now been built.
|
||||
@echo Use \'$(MAKE) install\' to install fish.
|
||||
.PHONY: all
|
||||
@@ -293,9 +300,11 @@ debug:
|
||||
# User documentation, describing the features of the fish shell.
|
||||
#
|
||||
|
||||
# Depend on the sources (*.hdr.in) and manually make the
|
||||
# intermediate *.hdr and doc.h files if needed
|
||||
|
||||
user_doc: $(HDR_FILES) Doxyfile.user user_doc.head.html
|
||||
$(MAKE) doc.h # Depend on the sources (*.hdr) and manually make the intermediate doc.h file if needed
|
||||
user_doc: $(HDR_FILES_SRC) Doxyfile.user user_doc.head.html $(HELP_SRC)
|
||||
$(MAKE) doc.h $(HDR_FILES)
|
||||
doxygen Doxyfile.user
|
||||
touch user_doc
|
||||
|
||||
@@ -337,7 +346,7 @@ 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
|
||||
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."
|
||||
|
||||
|
||||
#
|
||||
@@ -395,7 +404,7 @@ doc.h: $(HDR_FILES)
|
||||
cat $*.txt >>$@;
|
||||
echo "*/" >>$@
|
||||
|
||||
%: %.in Makefile
|
||||
%: %.in
|
||||
sed <$@.in >$@ \
|
||||
-e "s,@sysconfdir\@,$(sysconfdir),g" \
|
||||
-e "s,@datadir\@,$(datadir),g" \
|
||||
@@ -411,7 +420,7 @@ doc.h: $(HDR_FILES)
|
||||
#
|
||||
|
||||
%.gmo:
|
||||
if test $(HAVE_GETTEXT) = 1; then \
|
||||
if test "$(HAVE_GETTEXT)" = 1; then \
|
||||
msgfmt -o $*.gmo $*.po; \
|
||||
fi
|
||||
|
||||
@@ -541,10 +550,6 @@ install-sh:
|
||||
if test -x $@; then true; else chmod 755 $@; fi
|
||||
.PHONY: install-sh
|
||||
|
||||
make_mercurial_completions.fish:
|
||||
if test -x $@; then true; else chmod 755 $@; fi
|
||||
.PHONY: make_mercurial_completions.fish
|
||||
|
||||
|
||||
#
|
||||
# Try to install after checking for incompatible installed versions.
|
||||
@@ -571,7 +576,6 @@ install-force: all install-translations
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/man
|
||||
$(INSTALL) -m 644 etc/config.fish $(DESTDIR)$(sysconfdir)/fish/
|
||||
$(INSTALL) -m 644 share/config.fish $(DESTDIR)$(datadir)/fish/
|
||||
$(INSTALL) -m 644 share/config_interactive.fish $(DESTDIR)$(datadir)/fish/
|
||||
for i in $(COMPLETIONS_DIR_FILES); do \
|
||||
$(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/completions/; \
|
||||
done;
|
||||
@@ -581,7 +585,6 @@ install-force: all install-translations
|
||||
for i in share/man/*.1; do \
|
||||
$(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/man/; \
|
||||
done;
|
||||
$(INSTALL) -m 644 etc/fish_inputrc $(DESTDIR)$(sysconfdir)/fish/fish_inputrc;
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(docdir)
|
||||
for i in user_doc/html/* ChangeLog; do \
|
||||
if test -f $$i; then \
|
||||
@@ -613,7 +616,6 @@ uninstall: uninstall-translations
|
||||
done;
|
||||
-rm -f $(DESTDIR)$(bindir)/xsel
|
||||
-rm -f $(DESTDIR)$(sysconfdir)/fish/config.fish
|
||||
-rm -f $(DESTDIR)$(sysconfdir)/fish/fish_inputrc
|
||||
-rmdir $(DESTDIR)$(sysconfdir)/fish
|
||||
-if test -d $(DESTDIR)$(datadir)/fish; then \
|
||||
rm -r $(DESTDIR)$(datadir)/fish; \
|
||||
@@ -638,6 +640,7 @@ uninstall-legacy: uninstall
|
||||
-rm -f $(DESTDIR)$(sysconfdir)/fish.d/fish_interactive.fish
|
||||
-rm -f $(DESTDIR)$(sysconfdir)/fish.d/fish_complete.fish
|
||||
-rm -f $(DESTDIR)$(sysconfdir)/fish.d/fish_function.fish
|
||||
-rm -f $(DESTDIR)$(sysconfdir)/fish/fish_inputrc
|
||||
-if test -d $(DESTDIR)$(sysconfdir)/fish.d/completions; then \
|
||||
for i in $(COMPLETIONS_DIR_FILES); do \
|
||||
basename=`basename $$i`; \
|
||||
@@ -679,8 +682,8 @@ uninstall-translations:
|
||||
# Build the fish program.
|
||||
#
|
||||
|
||||
fish: $(FISH_OBJS) main.o
|
||||
$(CC) $(FISH_OBJS) main.o $(LDFLAGS) -o $@
|
||||
fish: $(FISH_OBJS) fish.o
|
||||
$(CC) $(FISH_OBJS) fish.o $(LDFLAGS_FISH) -o $@
|
||||
|
||||
|
||||
#
|
||||
@@ -688,7 +691,7 @@ fish: $(FISH_OBJS) main.o
|
||||
#
|
||||
|
||||
fish_pager: $(FISH_PAGER_OBJS)
|
||||
$(CC) $(FISH_PAGER_OBJS) $(LDFLAGS) -o $@
|
||||
$(CC) $(FISH_PAGER_OBJS) $(LDFLAGS_FISH_PAGER) -o $@
|
||||
|
||||
|
||||
#
|
||||
@@ -696,7 +699,7 @@ fish_pager: $(FISH_PAGER_OBJS)
|
||||
#
|
||||
|
||||
fishd: $(FISHD_OBJS)
|
||||
$(CC) $(FISHD_OBJS) $(LDFLAGS) -o $@
|
||||
$(CC) $(FISHD_OBJS) $(LDFLAGS_FISHD) -o $@
|
||||
|
||||
|
||||
#
|
||||
@@ -704,7 +707,7 @@ fishd: $(FISHD_OBJS)
|
||||
#
|
||||
|
||||
fish_tests: $(FISH_TESTS_OBJS)
|
||||
$(CC) $(FISH_TESTS_OBJS) $(LDFLAGS) -o $@
|
||||
$(CC) $(FISH_TESTS_OBJS) $(LDFLAGS_FISH) -o $@
|
||||
|
||||
|
||||
#
|
||||
@@ -714,17 +717,7 @@ fish_tests: $(FISH_TESTS_OBJS)
|
||||
#
|
||||
|
||||
mimedb: $(MIME_OBJS)
|
||||
$(CC) $(MIME_OBJS) $(LDFLAGS) -o $@
|
||||
|
||||
|
||||
#
|
||||
# Build the count program.
|
||||
#
|
||||
# count does not need any libraries, so we don't use LDFLAGS here.
|
||||
#
|
||||
|
||||
count: count.o
|
||||
$(CC) count.o -o $@
|
||||
$(CC) $(MIME_OBJS) $(LDFLAGS_MIMEDB) -o $@
|
||||
|
||||
|
||||
#
|
||||
@@ -732,7 +725,7 @@ count: count.o
|
||||
#
|
||||
|
||||
set_color: set_color.o print_help.o common.o
|
||||
$(CC) set_color.o print_help.o common.o wutil.o $(LDFLAGS) -o $@
|
||||
$(CC) set_color.o print_help.o common.o wutil.o $(LDFLAGS_SET_COLOR) -o $@
|
||||
|
||||
|
||||
#
|
||||
@@ -743,12 +736,20 @@ tokenizer_test: tokenizer.c tokenizer.h wutil.o common.o
|
||||
$(CC) $(CFLAGS) tokenizer.c wutil.o common.o -D TOKENIZER_TEST $(LDFLAGS) -o $@
|
||||
|
||||
|
||||
#
|
||||
# Build the fish_indent program.
|
||||
#
|
||||
|
||||
fish_indent: $(FISH_INDENT_OBJS)
|
||||
$(CC) $(FISH_INDENT_OBJS) $(LDFLAGS_FISH_INDENT) -o $@
|
||||
|
||||
|
||||
#
|
||||
# Neat little program to show output from terminal
|
||||
#
|
||||
|
||||
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 $@
|
||||
|
||||
|
||||
#
|
||||
@@ -823,21 +824,6 @@ fish.spec: fish.spec.in
|
||||
./config.status
|
||||
|
||||
|
||||
#
|
||||
# Completion files which are autogenerated using various scripts
|
||||
#
|
||||
|
||||
share/completions/darcs.fish: make_mercurial_completions.fish
|
||||
./make_mercurial_completions.fish darcs 'complete -c darcs -n "not __fish_use_subcommand" -a "(test -f _darcs/prefs/repos; and cat _darcs/prefs/repos)" --description "Darcs repo"' 'complete -c darcs -a "test predist boringfile binariesfile" -n "contains setpref (commandline -poc)" -d "woot" -x' >$@
|
||||
|
||||
share/completions/hg.fish: make_mercurial_completions.fish
|
||||
./make_mercurial_completions.fish hg >$@
|
||||
|
||||
share/completions/svn.fish: make_mercurial_completions.fish
|
||||
./make_mercurial_completions.fish svn >$@
|
||||
|
||||
share/completions/cvs.fish: make_mercurial_completions.fish
|
||||
./make_mercurial_completions.fish cvs >$@
|
||||
|
||||
#
|
||||
# Create .rpm file for the current systems architecture and an
|
||||
@@ -869,7 +855,7 @@ rpm: fish-@PACKAGE_VERSION@.tar.bz2 fish.spec
|
||||
|
||||
distclean: clean
|
||||
rm -f fish.spec Doxyfile.help
|
||||
rm -f etc/config.fish share/config_interactive.fish seq share/config.fish
|
||||
rm -f etc/config.fish seq share/config.fish
|
||||
rm -f config.status config.log config.h Makefile
|
||||
.PHONY: distclean
|
||||
|
||||
@@ -882,8 +868,8 @@ 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 tokenizer_test fish key_reader set_color mimedb
|
||||
rm -f fishd fish_pager count fish_tests
|
||||
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.bz2
|
||||
@@ -896,35 +882,37 @@ clean:
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
builtin.o: config.h fallback.h util.h wutil.h builtin.h function.h complete.h
|
||||
builtin.o: proc.h io.h parser.h event.h reader.h env.h common.h wgetopt.h
|
||||
builtin.o: sanity.h tokenizer.h wildcard.h input_common.h input.h intern.h
|
||||
builtin.o: signal.h halloc.h halloc_util.h parse_util.h expand.h path.h
|
||||
builtin.o: builtin_set.c builtin_commandline.c builtin_complete.c
|
||||
builtin.o: builtin_ulimit.c builtin_jobs.c
|
||||
builtin.o: config.h fallback.h util.h wutil.h builtin.h io.h function.h
|
||||
builtin.o: complete.h proc.h parser.h event.h reader.h env.h common.h
|
||||
builtin.o: wgetopt.h sanity.h tokenizer.h wildcard.h input_common.h input.h
|
||||
builtin.o: intern.h signal.h exec.h highlight.h halloc.h halloc_util.h
|
||||
builtin.o: parse_util.h parser_keywords.h expand.h path.h builtin_set.c
|
||||
builtin.o: builtin_commandline.c builtin_complete.c builtin_ulimit.c
|
||||
builtin.o: builtin_jobs.c
|
||||
builtin_commandline.o: config.h signal.h fallback.h util.h wutil.h builtin.h
|
||||
builtin_commandline.o: common.h wgetopt.h reader.h proc.h io.h parser.h
|
||||
builtin_commandline.o: io.h common.h wgetopt.h reader.h proc.h parser.h
|
||||
builtin_commandline.o: event.h tokenizer.h input_common.h input.h
|
||||
builtin_commandline.o: parse_util.h
|
||||
builtin_complete.o: config.h signal.h fallback.h util.h wutil.h builtin.h
|
||||
builtin_complete.o: common.h complete.h wgetopt.h parser.h proc.h io.h
|
||||
builtin_complete.o: io.h common.h complete.h wgetopt.h parser.h proc.h
|
||||
builtin_complete.o: event.h reader.h
|
||||
builtin_jobs.o: config.h fallback.h util.h wutil.h builtin.h proc.h io.h
|
||||
builtin_jobs.o: config.h fallback.h util.h wutil.h builtin.h io.h proc.h
|
||||
builtin_jobs.o: parser.h event.h common.h wgetopt.h
|
||||
builtin_set.o: config.h signal.h fallback.h util.h wutil.h builtin.h env.h
|
||||
builtin_set.o: expand.h common.h wgetopt.h proc.h io.h parser.h event.h
|
||||
builtin_ulimit.o: config.h fallback.h util.h builtin.h common.h wgetopt.h
|
||||
builtin_set.o: config.h signal.h fallback.h util.h wutil.h builtin.h io.h
|
||||
builtin_set.o: env.h expand.h common.h wgetopt.h proc.h parser.h event.h
|
||||
builtin_ulimit.o: config.h fallback.h util.h builtin.h io.h common.h
|
||||
builtin_ulimit.o: wgetopt.h
|
||||
common.o: config.h fallback.h util.h wutil.h common.h expand.h proc.h io.h
|
||||
common.o: wildcard.h parser.h event.h util.c halloc.c halloc.h halloc_util.c
|
||||
common.o: fallback.c
|
||||
complete.o: config.h signal.h fallback.h util.h tokenizer.h wildcard.h proc.h
|
||||
complete.o: io.h parser.h event.h function.h complete.h builtin.h env.h
|
||||
complete.o: exec.h expand.h common.h reader.h history.h intern.h parse_util.h
|
||||
complete.o: halloc.h halloc_util.h wutil.h path.h
|
||||
count.o: config.h
|
||||
complete.o: parser_keywords.h halloc.h halloc_util.h wutil.h path.h
|
||||
env.o: config.h signal.h fallback.h util.h wutil.h proc.h io.h common.h env.h
|
||||
env.o: sanity.h expand.h history.h reader.h parser.h event.h env_universal.h
|
||||
env.o: env_universal_common.h input_common.h complete.h
|
||||
env.o: env_universal_common.h input_common.h path.h halloc.h halloc_util.h
|
||||
env.o: complete.h
|
||||
env_universal.o: config.h signal.h fallback.h util.h common.h wutil.h
|
||||
env_universal.o: env_universal_common.h env_universal.h
|
||||
env_universal_common.o: config.h signal.h fallback.h util.h common.h wutil.h
|
||||
@@ -938,30 +926,36 @@ expand.o: config.h signal.h fallback.h util.h common.h wutil.h env.h proc.h
|
||||
expand.o: io.h parser.h event.h expand.h wildcard.h exec.h tokenizer.h
|
||||
expand.o: complete.h parse_util.h halloc.h halloc_util.h
|
||||
fallback.o: config.h fallback.h util.h
|
||||
fishd.o: config.h signal.h fallback.h util.h common.h wutil.h
|
||||
fishd.o: env_universal_common.h halloc.h halloc_util.h path.h
|
||||
fish.o: config.h signal.h fallback.h util.h common.h reader.h io.h builtin.h
|
||||
fish.o: function.h complete.h wutil.h env.h sanity.h proc.h parser.h event.h
|
||||
fish.o: expand.h intern.h exec.h output.h halloc.h halloc_util.h history.h
|
||||
fish.o: path.h
|
||||
fish_indent.o: config.h fallback.h util.h common.h wutil.h halloc.h
|
||||
fish_indent.o: halloc_util.h tokenizer.h print_help.h parser_keywords.h
|
||||
fish_pager.o: config.h signal.h fallback.h util.h wutil.h common.h complete.h
|
||||
fish_pager.o: output.h input_common.h env_universal.h env_universal_common.h
|
||||
fish_pager.o: halloc.h halloc_util.h
|
||||
fish_pager.o: halloc.h halloc_util.h print_help.h
|
||||
fish_tests.o: config.h signal.h fallback.h util.h common.h proc.h io.h
|
||||
fish_tests.o: reader.h builtin.h function.h complete.h wutil.h env.h expand.h
|
||||
fish_tests.o: parser.h event.h tokenizer.h output.h exec.h halloc_util.h
|
||||
fish_tests.o: parser.h event.h tokenizer.h output.h exec.h path.h halloc.h
|
||||
fish_tests.o: halloc_util.h
|
||||
fishd.o: config.h signal.h fallback.h util.h common.h wutil.h
|
||||
fishd.o: env_universal_common.h halloc.h halloc_util.h path.h print_help.h
|
||||
function.o: config.h signal.h wutil.h fallback.h util.h function.h proc.h
|
||||
function.o: io.h parser.h event.h common.h intern.h reader.h parse_util.h
|
||||
function.o: env.h expand.h halloc.h halloc_util.h
|
||||
function.o: parser_keywords.h env.h expand.h halloc.h halloc_util.h
|
||||
halloc.o: config.h fallback.h util.h common.h halloc.h
|
||||
halloc_util.o: config.h fallback.h util.h common.h halloc.h
|
||||
highlight.o: config.h signal.h fallback.h util.h wutil.h highlight.h
|
||||
highlight.o: tokenizer.h proc.h io.h parser.h event.h parse_util.h builtin.h
|
||||
highlight.o: function.h env.h expand.h sanity.h common.h complete.h output.h
|
||||
highlight.o: halloc.h halloc_util.h wildcard.h path.h
|
||||
history2.o: config.h fallback.h util.h wutil.h history.h common.h halloc.h
|
||||
history2.o: halloc_util.h intern.h path.h
|
||||
highlight.o: tokenizer.h proc.h io.h parser.h event.h parse_util.h
|
||||
highlight.o: parser_keywords.h builtin.h function.h env.h expand.h sanity.h
|
||||
highlight.o: common.h complete.h output.h halloc.h halloc_util.h wildcard.h
|
||||
highlight.o: path.h
|
||||
history.o: config.h fallback.h util.h wutil.h history.h common.h halloc.h
|
||||
history.o: halloc_util.h intern.h path.h signal.h
|
||||
input.o: config.h signal.h fallback.h util.h wutil.h reader.h proc.h io.h
|
||||
input.o: config.h signal.h fallback.h util.h wutil.h reader.h io.h proc.h
|
||||
input.o: common.h sanity.h input_common.h input.h parser.h event.h env.h
|
||||
input.o: expand.h output.h intern.h
|
||||
input.o: expand.h output.h intern.h halloc.h halloc_util.h
|
||||
input_common.o: config.h fallback.h util.h common.h wutil.h input_common.h
|
||||
input_common.o: env_universal.h env_universal_common.h
|
||||
intern.o: config.h fallback.h util.h wutil.h common.h intern.h
|
||||
@@ -969,48 +963,44 @@ io.o: config.h fallback.h util.h wutil.h exec.h proc.h io.h common.h halloc.h
|
||||
key_reader.o: config.h fallback.h input_common.h
|
||||
kill.o: config.h signal.h fallback.h util.h wutil.h kill.h proc.h io.h
|
||||
kill.o: sanity.h common.h env.h exec.h halloc.h path.h
|
||||
main.o: config.h signal.h fallback.h util.h common.h reader.h builtin.h
|
||||
main.o: function.h complete.h wutil.h env.h sanity.h proc.h io.h parser.h
|
||||
main.o: event.h expand.h intern.h exec.h output.h halloc.h halloc_util.h
|
||||
main.o: history.h path.h
|
||||
mimedb.o: config.h xdgmime.h fallback.h util.h
|
||||
mimedb.o: config.h xdgmime.h fallback.h util.h print_help.h
|
||||
output.o: config.h signal.h fallback.h util.h wutil.h expand.h common.h
|
||||
output.o: output.h halloc_util.h highlight.h
|
||||
parser.o: config.h signal.h fallback.h util.h common.h wutil.h proc.h io.h
|
||||
parser.o: parser.h event.h tokenizer.h exec.h wildcard.h function.h builtin.h
|
||||
parser.o: env.h expand.h reader.h sanity.h env_universal.h
|
||||
parser.o: env_universal_common.h intern.h parse_util.h halloc.h halloc_util.h
|
||||
parser.o: path.h
|
||||
parse_util.o: config.h fallback.h util.h wutil.h common.h tokenizer.h
|
||||
parse_util.o: parse_util.h expand.h intern.h exec.h proc.h io.h env.h
|
||||
parse_util.o: signal.h wildcard.h halloc_util.h
|
||||
parser.o: config.h signal.h fallback.h util.h common.h wutil.h proc.h io.h
|
||||
parser.o: parser.h event.h parser_keywords.h tokenizer.h exec.h wildcard.h
|
||||
parser.o: function.h builtin.h env.h expand.h reader.h sanity.h
|
||||
parser.o: env_universal.h env_universal_common.h intern.h parse_util.h
|
||||
parser.o: halloc.h halloc_util.h path.h
|
||||
parser_keywords.o: config.h fallback.h common.h util.h parser_keywords.h
|
||||
path.o: config.h fallback.h util.h common.h env.h wutil.h halloc.h
|
||||
path.o: halloc_util.h path.h expand.h
|
||||
print_help.o: print_help.h
|
||||
proc.o: config.h signal.h fallback.h util.h wutil.h proc.h io.h common.h
|
||||
proc.o: reader.h sanity.h env.h parser.h event.h halloc.h halloc_util.h
|
||||
proc.o: output.h
|
||||
reader.o: config.h signal.h fallback.h util.h wutil.h highlight.h reader.h
|
||||
reader.o: proc.h io.h parser.h event.h complete.h history.h common.h sanity.h
|
||||
reader.o: io.h proc.h parser.h event.h complete.h history.h common.h sanity.h
|
||||
reader.o: env.h exec.h expand.h tokenizer.h kill.h input_common.h input.h
|
||||
reader.o: function.h output.h screen.h parse_util.h
|
||||
reader.o: function.h output.h screen.h halloc.h halloc_util.h parse_util.h
|
||||
sanity.o: config.h signal.h fallback.h util.h common.h sanity.h proc.h io.h
|
||||
sanity.o: history.h reader.h kill.h wutil.h
|
||||
screen.o: config.h fallback.h common.h util.h wutil.h output.h highlight.h
|
||||
screen.o: screen.h env.h
|
||||
set_color.o: config.h fallback.h print_help.h
|
||||
signal.o: config.h signal.h common.h util.h fallback.h wutil.h event.h
|
||||
signal.o: reader.h proc.h io.h
|
||||
test.o: stringtab.h
|
||||
signal.o: reader.h io.h proc.h
|
||||
tokenizer.o: config.h fallback.h util.h wutil.h tokenizer.h common.h
|
||||
tokenizer.o: wildcard.h
|
||||
util.o: config.h fallback.h util.h common.h wutil.h
|
||||
wgetopt.o: config.h wgetopt.h wutil.h fallback.h
|
||||
wildcard.o: config.h fallback.h util.h wutil.h complete.h common.h wildcard.h
|
||||
wildcard.o: reader.h expand.h
|
||||
wildcard.o: reader.h io.h expand.h exec.h proc.h halloc_util.h
|
||||
wutil.o: config.h fallback.h util.h common.h wutil.h halloc.h halloc_util.h
|
||||
xdgmimealias.o: xdgmimealias.h xdgmime.h xdgmimeint.h
|
||||
xdgmime.o: xdgmime.h xdgmimeint.h xdgmimeglob.h xdgmimemagic.h xdgmimealias.h
|
||||
xdgmime.o: xdgmimeparent.h
|
||||
xdgmimealias.o: xdgmimealias.h xdgmime.h xdgmimeint.h
|
||||
xdgmimeglob.o: xdgmimeglob.h xdgmime.h xdgmimeint.h
|
||||
xdgmimeint.o: xdgmimeint.h xdgmime.h
|
||||
xdgmimemagic.o: xdgmimemagic.h xdgmime.h xdgmimeint.h
|
||||
|
||||
11
builtin.h
11
builtin.h
@@ -8,6 +8,7 @@
|
||||
#include <wchar.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "io.h"
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -128,10 +129,11 @@ int builtin_exists( wchar_t *cmd );
|
||||
of the builtin. The list is terminated by a
|
||||
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
|
||||
*/
|
||||
int builtin_run( wchar_t **argv );
|
||||
int builtin_run( wchar_t **argv, io_data_t *io );
|
||||
|
||||
/**
|
||||
Insert all builtin names into l. These are not copies of the strings and should not be freed after use.
|
||||
@@ -164,10 +166,11 @@ const wchar_t *builtin_complete_get_temporary_buffer();
|
||||
|
||||
|
||||
/**
|
||||
Return the help text for the specified builtin command.
|
||||
|
||||
\param cmd The command for which to obtain help text
|
||||
Run the __fish_print_help function to obtain the help information
|
||||
for the specified command. The resulting string will be valid until
|
||||
the next time this function is called, and must never be free'd manually.
|
||||
*/
|
||||
|
||||
wchar_t *builtin_help_get( const wchar_t *cmd );
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
@@ -163,7 +171,7 @@ static void write_part( const wchar_t *begin,
|
||||
case TOK_STRING:
|
||||
{
|
||||
wchar_t *tmp = unescape( tok_last( &tok ), UNESCAPE_INCOMPLETE );
|
||||
sb_append2( &out, tmp, L"\n", (void *)0 );
|
||||
sb_append( &out, tmp, L"\n", (void *)0 );
|
||||
free( tmp );
|
||||
break;
|
||||
}
|
||||
@@ -220,6 +228,8 @@ static int builtin_commandline( wchar_t **argv )
|
||||
int tokenize = 0;
|
||||
|
||||
int cursor_mode = 0;
|
||||
int line_mode = 0;
|
||||
int search_mode = 0;
|
||||
wchar_t *begin, *end;
|
||||
|
||||
current_buffer = (wchar_t *)builtin_complete_get_temporary_buffer();
|
||||
@@ -235,13 +245,23 @@ static int builtin_commandline( wchar_t **argv )
|
||||
|
||||
if( !get_buffer() )
|
||||
{
|
||||
sb_append2( sb_err,
|
||||
argv[0],
|
||||
L": Can not set commandline in non-interactive mode\n",
|
||||
(void *)0 );
|
||||
if (is_interactive_session)
|
||||
{
|
||||
/*
|
||||
Prompt change requested while we don't have
|
||||
a prompt, most probably while reading the
|
||||
init files. Just ignore it.
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
sb_append( sb_err,
|
||||
argv[0],
|
||||
L": Can not set commandline in non-interactive mode\n",
|
||||
(void *)0 );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
woptind=0;
|
||||
|
||||
@@ -302,6 +322,14 @@ static int builtin_commandline( wchar_t **argv )
|
||||
L"cursor", no_argument, 0, 'C'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"line", no_argument, 0, 'L'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"search-mode", no_argument, 0, 'S'
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
@@ -312,7 +340,7 @@ static int builtin_commandline( wchar_t **argv )
|
||||
|
||||
int opt = wgetopt_long( argc,
|
||||
argv,
|
||||
L"aijpctwforhI:C",
|
||||
L"abijpctwforhI:CLS",
|
||||
long_options,
|
||||
&opt_index );
|
||||
if( opt == -1 )
|
||||
@@ -334,6 +362,11 @@ static int builtin_commandline( wchar_t **argv )
|
||||
case L'a':
|
||||
append_mode = APPEND_MODE;
|
||||
break;
|
||||
|
||||
case L'b':
|
||||
buffer_part = STRING_MODE;
|
||||
break;
|
||||
|
||||
|
||||
case L'i':
|
||||
append_mode = INSERT_MODE;
|
||||
@@ -376,6 +409,14 @@ static int builtin_commandline( wchar_t **argv )
|
||||
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;
|
||||
@@ -393,7 +434,7 @@ static int builtin_commandline( wchar_t **argv )
|
||||
/*
|
||||
Check for invalid switch combinations
|
||||
*/
|
||||
if( buffer_part || cut_at_cursor || append_mode || tokenize || cursor_mode )
|
||||
if( buffer_part || cut_at_cursor || append_mode || tokenize || cursor_mode || line_mode || search_mode )
|
||||
{
|
||||
sb_printf(sb_err,
|
||||
BUILTIN_ERR_COMBO,
|
||||
@@ -415,7 +456,7 @@ static int builtin_commandline( wchar_t **argv )
|
||||
}
|
||||
for( i=woptind; i<argc; i++ )
|
||||
{
|
||||
wint_t c = input_get_code( argv[i] );
|
||||
wint_t c = input_function_get_code( argv[i] );
|
||||
if( c != -1 )
|
||||
{
|
||||
/*
|
||||
@@ -428,9 +469,9 @@ static int builtin_commandline( wchar_t **argv )
|
||||
else
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_(L"%ls: Unknown readline function '%ls'\n"),
|
||||
argv[0],
|
||||
argv[i] );
|
||||
_(L"%ls: Unknown input function '%ls'\n"),
|
||||
argv[0],
|
||||
argv[i] );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
@@ -442,10 +483,10 @@ static int builtin_commandline( wchar_t **argv )
|
||||
/*
|
||||
Check for invalid switch combinations
|
||||
*/
|
||||
if( cursor_mode && (argc-woptind > 1) )
|
||||
if( (search_mode || line_mode || cursor_mode) && (argc-woptind > 1) )
|
||||
{
|
||||
|
||||
sb_append2( sb_err,
|
||||
sb_append( sb_err,
|
||||
argv[0],
|
||||
L": Too many arguments\n",
|
||||
(void *)0 );
|
||||
@@ -453,7 +494,7 @@ static int builtin_commandline( wchar_t **argv )
|
||||
return 1;
|
||||
}
|
||||
|
||||
if( (buffer_part || tokenize || cut_at_cursor) && cursor_mode )
|
||||
if( (buffer_part || tokenize || cut_at_cursor) && (cursor_mode || line_mode || search_mode) )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
BUILTIN_ERR_COMBO,
|
||||
@@ -512,9 +553,9 @@ static int builtin_commandline( wchar_t **argv )
|
||||
if( *endptr || errno )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
BUILTIN_ERR_NOT_NUMBER,
|
||||
argv[0],
|
||||
argv[woptind] );
|
||||
BUILTIN_ERR_NOT_NUMBER,
|
||||
argv[0],
|
||||
argv[woptind] );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
}
|
||||
|
||||
@@ -531,6 +572,20 @@ static int builtin_commandline( wchar_t **argv )
|
||||
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
|
||||
@@ -50,7 +50,8 @@ static void builtin_complete_add2( const wchar_t *cmd,
|
||||
int result_mode,
|
||||
const wchar_t *condition,
|
||||
const wchar_t *comp,
|
||||
const wchar_t *desc )
|
||||
const wchar_t *desc,
|
||||
int flags )
|
||||
{
|
||||
int i;
|
||||
const wchar_t *s;
|
||||
@@ -65,7 +66,8 @@ static void builtin_complete_add2( const wchar_t *cmd,
|
||||
result_mode,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
desc,
|
||||
flags );
|
||||
}
|
||||
|
||||
for( i=0; i<al_get_count( gnu_opt ); i++ )
|
||||
@@ -78,7 +80,8 @@ static void builtin_complete_add2( const wchar_t *cmd,
|
||||
result_mode,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
desc,
|
||||
flags );
|
||||
}
|
||||
|
||||
for( i=0; i<al_get_count( old_opt ); i++ )
|
||||
@@ -91,7 +94,8 @@ static void builtin_complete_add2( const wchar_t *cmd,
|
||||
result_mode,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
desc,
|
||||
flags );
|
||||
}
|
||||
|
||||
if( al_get_count( old_opt )+al_get_count( gnu_opt )+wcslen(short_opt) == 0 )
|
||||
@@ -104,7 +108,8 @@ static void builtin_complete_add2( const wchar_t *cmd,
|
||||
result_mode,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
desc,
|
||||
flags );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,10 +122,11 @@ static void builtin_complete_add( array_list_t *cmd,
|
||||
array_list_t *gnu_opt,
|
||||
array_list_t *old_opt,
|
||||
int result_mode,
|
||||
int authorative,
|
||||
int authoritative,
|
||||
const wchar_t *condition,
|
||||
const wchar_t *comp,
|
||||
const wchar_t *desc )
|
||||
const wchar_t *desc,
|
||||
int flags )
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -134,13 +140,14 @@ static void builtin_complete_add( array_list_t *cmd,
|
||||
result_mode,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
desc,
|
||||
flags );
|
||||
|
||||
if( authorative != -1 )
|
||||
if( authoritative != -1 )
|
||||
{
|
||||
complete_set_authorative( al_get( cmd, i ),
|
||||
complete_set_authoritative( al_get( cmd, i ),
|
||||
COMMAND,
|
||||
authorative );
|
||||
authoritative );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -155,13 +162,14 @@ static void builtin_complete_add( array_list_t *cmd,
|
||||
result_mode,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
desc,
|
||||
flags );
|
||||
|
||||
if( authorative != -1 )
|
||||
if( authoritative != -1 )
|
||||
{
|
||||
complete_set_authorative( al_get( path, i ),
|
||||
complete_set_authoritative( al_get( path, i ),
|
||||
PATH,
|
||||
authorative );
|
||||
authoritative );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -286,7 +294,8 @@ static int builtin_complete( wchar_t **argv )
|
||||
int argc=0;
|
||||
int result_mode=SHARED;
|
||||
int remove = 0;
|
||||
int authorative = -1;
|
||||
int authoritative = -1;
|
||||
int flags = COMPLETE_AUTO_SPACE;
|
||||
|
||||
string_buffer_t short_opt;
|
||||
array_list_t gnu_opt, old_opt;
|
||||
@@ -299,11 +308,6 @@ static int builtin_complete( wchar_t **argv )
|
||||
|
||||
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 );
|
||||
@@ -364,11 +368,11 @@ static int builtin_complete( wchar_t **argv )
|
||||
}
|
||||
,
|
||||
{
|
||||
L"unauthorative", no_argument, 0, 'u'
|
||||
L"unauthoritative", no_argument, 0, 'u'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"authorative", no_argument, 0, 'A'
|
||||
L"authoritative", no_argument, 0, 'A'
|
||||
}
|
||||
,
|
||||
{
|
||||
@@ -447,11 +451,11 @@ static int builtin_complete( wchar_t **argv )
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
authorative=0;
|
||||
authoritative=0;
|
||||
break;
|
||||
|
||||
case 'A':
|
||||
authorative=1;
|
||||
authoritative=1;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
@@ -535,31 +539,51 @@ static int builtin_complete( wchar_t **argv )
|
||||
{
|
||||
if( do_complete )
|
||||
{
|
||||
array_list_t comp;
|
||||
array_list_t *comp;
|
||||
int i;
|
||||
|
||||
const wchar_t *prev_temporary_buffer = temporary_buffer;
|
||||
|
||||
wchar_t *token;
|
||||
|
||||
parse_util_token_extent( do_complete, wcslen( do_complete ), &token, 0, 0, 0 );
|
||||
|
||||
temporary_buffer = do_complete;
|
||||
|
||||
if( recursion_level < 1 )
|
||||
{
|
||||
recursion_level++;
|
||||
|
||||
al_init( &comp );
|
||||
comp = al_halloc( 0 );
|
||||
|
||||
complete( do_complete, &comp );
|
||||
complete( do_complete, comp );
|
||||
|
||||
for( i=0; i<al_get_count( &comp ); i++ )
|
||||
for( i=0; i<al_get_count( comp ); i++ )
|
||||
{
|
||||
wchar_t *next = (wchar_t *)al_get( &comp, i );
|
||||
wchar_t *sep = wcschr( next, COMPLETE_SEP );
|
||||
if( sep )
|
||||
*sep = L'\t';
|
||||
sb_printf( sb_out, L"%ls\n", next );
|
||||
completion_t *next = (completion_t *)al_get( comp, i );
|
||||
wchar_t *prepend;
|
||||
|
||||
if( next->flags & COMPLETE_NO_CASE )
|
||||
{
|
||||
prepend = L"";
|
||||
}
|
||||
else
|
||||
{
|
||||
prepend = token;
|
||||
}
|
||||
|
||||
|
||||
if( next->description )
|
||||
{
|
||||
sb_printf( sb_out, L"%ls%ls\t%ls\n", prepend, next->completion, next->description );
|
||||
}
|
||||
else
|
||||
{
|
||||
sb_printf( sb_out, L"%ls%ls\n", prepend, next->completion );
|
||||
}
|
||||
}
|
||||
|
||||
al_foreach( &comp, &free );
|
||||
al_destroy( &comp );
|
||||
halloc_free( comp );
|
||||
recursion_level--;
|
||||
}
|
||||
|
||||
@@ -599,10 +623,11 @@ static int builtin_complete( wchar_t **argv )
|
||||
&gnu_opt,
|
||||
&old_opt,
|
||||
result_mode,
|
||||
authorative,
|
||||
authoritative,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
desc,
|
||||
flags );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ static void builtin_jobs_print( job_t *j, int mode, int header )
|
||||
#ifdef HAVE__PROC_SELF_STAT
|
||||
sb_printf( sb_out, L"%d%%\t", cpu_use(j) );
|
||||
#endif
|
||||
sb_append2( sb_out,
|
||||
sb_append( sb_out,
|
||||
job_is_stopped(j)?_(L"stopped"):_(L"running"),
|
||||
L"\t",
|
||||
j->command,
|
||||
|
||||
@@ -46,10 +46,9 @@ Functions used for implementing the set builtin.
|
||||
*/
|
||||
static int is_path_variable( const wchar_t *env )
|
||||
{
|
||||
return contains_str( env,
|
||||
return contains( env,
|
||||
L"PATH",
|
||||
L"CDPATH",
|
||||
(void *)0 );
|
||||
L"CDPATH" );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -388,7 +387,7 @@ static void print_variables(int include_values, int esc, int scope)
|
||||
|
||||
e_value = esc ? expand_escape_variable(value) : wcsdup(value);
|
||||
|
||||
sb_append2(sb_out, L" ", e_value, (void *)0);
|
||||
sb_append(sb_out, L" ", e_value, (void *)0);
|
||||
free(e_value);
|
||||
|
||||
if( shorten )
|
||||
|
||||
@@ -432,7 +432,7 @@ static int builtin_ulimit( wchar_t ** argv )
|
||||
}
|
||||
else
|
||||
{
|
||||
sb_append2( sb_err,
|
||||
sb_append( sb_err,
|
||||
argv[0],
|
||||
L": Too many arguments\n",
|
||||
(void *)0 );
|
||||
@@ -503,7 +503,7 @@ static int builtin_ulimit( wchar_t ** argv )
|
||||
|
||||
default:
|
||||
{
|
||||
sb_append2( sb_err,
|
||||
sb_append( sb_err,
|
||||
argv[0],
|
||||
L": Too many arguments\n",
|
||||
(void *)0 );
|
||||
|
||||
245
common.c
245
common.c
@@ -214,7 +214,7 @@ int fgetws2( wchar_t **b, int *len, FILE *f )
|
||||
/**
|
||||
Wrapper for wcsfilecmp
|
||||
*/
|
||||
static int completion_cmp( const void *a, const void *b )
|
||||
static int str_cmp( const void *a, const void *b )
|
||||
{
|
||||
wchar_t *c= *((wchar_t **)a);
|
||||
wchar_t *d= *((wchar_t **)b);
|
||||
@@ -226,7 +226,7 @@ void sort_list( array_list_t *comp )
|
||||
qsort( comp->arr,
|
||||
al_get_count( comp ),
|
||||
sizeof( void*),
|
||||
&completion_cmp );
|
||||
&str_cmp );
|
||||
}
|
||||
|
||||
wchar_t *str2wcs( const char *in )
|
||||
@@ -258,15 +258,27 @@ wchar_t *str2wcs_internal( const char *in, wchar_t *out )
|
||||
len = strlen(in);
|
||||
|
||||
memset( &state, 0, sizeof(state) );
|
||||
|
||||
|
||||
while( in[in_pos] )
|
||||
{
|
||||
res = mbrtowc( &out[out_pos], &in[in_pos], len-in_pos, &state );
|
||||
|
||||
switch( res )
|
||||
if( ( ( out[out_pos] >= ENCODE_DIRECT_BASE) &&
|
||||
( out[out_pos] < ENCODE_DIRECT_BASE+256)) ||
|
||||
( out[out_pos] == INTERNAL_SEPARATOR ) )
|
||||
{
|
||||
case (size_t)(-2):
|
||||
case (size_t)(-1):
|
||||
out[out_pos] = ENCODE_DIRECT_BASE + (unsigned char)in[in_pos];
|
||||
in_pos++;
|
||||
memset( &state, 0, sizeof(state) );
|
||||
out_pos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
switch( res )
|
||||
{
|
||||
case (size_t)(-2):
|
||||
case (size_t)(-1):
|
||||
{
|
||||
out[out_pos] = ENCODE_DIRECT_BASE + (unsigned char)in[in_pos];
|
||||
in_pos++;
|
||||
@@ -274,18 +286,20 @@ wchar_t *str2wcs_internal( const char *in, wchar_t *out )
|
||||
break;
|
||||
}
|
||||
|
||||
case 0:
|
||||
{
|
||||
return out;
|
||||
}
|
||||
case 0:
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
in_pos += res;
|
||||
break;
|
||||
default:
|
||||
{
|
||||
in_pos += res;
|
||||
break;
|
||||
}
|
||||
}
|
||||
out_pos++;
|
||||
}
|
||||
out_pos++;
|
||||
|
||||
}
|
||||
out[out_pos] = 0;
|
||||
|
||||
@@ -324,7 +338,7 @@ char *wcs2str_internal( const wchar_t *in, char *out )
|
||||
{
|
||||
}
|
||||
else if( ( in[in_pos] >= ENCODE_DIRECT_BASE) &&
|
||||
( in[in_pos] < ENCODE_DIRECT_BASE+256) )
|
||||
( in[in_pos] < ENCODE_DIRECT_BASE+256) )
|
||||
{
|
||||
out[out_pos++] = in[in_pos]- ENCODE_DIRECT_BASE;
|
||||
}
|
||||
@@ -371,12 +385,7 @@ char **wcsv2strv( const wchar_t **in )
|
||||
|
||||
}
|
||||
|
||||
wchar_t *wcsdupcat( const wchar_t *a, const wchar_t *b )
|
||||
{
|
||||
return wcsdupcat2( a, b, (void *)0 );
|
||||
}
|
||||
|
||||
wchar_t *wcsdupcat2( const wchar_t *a, ... )
|
||||
wchar_t *wcsdupcat_internal( const wchar_t *a, ... )
|
||||
{
|
||||
int len=wcslen(a);
|
||||
int pos;
|
||||
@@ -534,7 +543,7 @@ const wchar_t *wsetlocale(int category, const wchar_t *locale)
|
||||
return (wchar_t *)setlocale_buff->buff;
|
||||
}
|
||||
|
||||
int contains_str( const wchar_t *a, ... )
|
||||
int contains_internal( const wchar_t *a, ... )
|
||||
{
|
||||
wchar_t *arg;
|
||||
va_list va;
|
||||
@@ -569,6 +578,36 @@ int read_blocked(int fd, void *buf, size_t count)
|
||||
return res;
|
||||
}
|
||||
|
||||
ssize_t write_loop(int fd, char *buff, size_t count)
|
||||
{
|
||||
ssize_t out=0;
|
||||
ssize_t out_cum=0;
|
||||
while( 1 )
|
||||
{
|
||||
out = write( fd,
|
||||
&buff[out_cum],
|
||||
count - out_cum );
|
||||
if (out == -1)
|
||||
{
|
||||
if( errno != EAGAIN &&
|
||||
errno != EINTR )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
} else
|
||||
{
|
||||
out_cum += out;
|
||||
}
|
||||
if( out_cum >= count )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return out_cum;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void debug( int level, const wchar_t *msg, ... )
|
||||
{
|
||||
va_list va;
|
||||
@@ -693,17 +732,55 @@ void write_screen( const wchar_t *msg, string_buffer_t *buff )
|
||||
sb_append_char( buff, L'\n' );
|
||||
}
|
||||
|
||||
wchar_t *escape( const wchar_t *in,
|
||||
int escape_all )
|
||||
/**
|
||||
Perform string escaping of a strinng by only quoting it. Assumes
|
||||
the string has already been checked for characters that can not be
|
||||
escaped this way.
|
||||
*/
|
||||
static wchar_t *escape_simple( const wchar_t *in )
|
||||
{
|
||||
wchar_t *out;
|
||||
size_t len = wcslen(in);
|
||||
out = malloc( sizeof(wchar_t)*(len+3));
|
||||
if( !out )
|
||||
DIE_MEM();
|
||||
|
||||
out[0] = L'\'';
|
||||
wcscpy(&out[1], in );
|
||||
out[len+1]=L'\'';
|
||||
out[len+2]=0;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
wchar_t *escape( const wchar_t *in_orig,
|
||||
int flags )
|
||||
{
|
||||
const wchar_t *in = in_orig;
|
||||
|
||||
int escape_all = flags & ESCAPE_ALL;
|
||||
int no_quoted = flags & ESCAPE_NO_QUOTED;
|
||||
|
||||
wchar_t *out;
|
||||
wchar_t *pos;
|
||||
|
||||
int need_escape=0;
|
||||
int need_complex_escape=0;
|
||||
|
||||
if( !in )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
FATAL_EXIT();
|
||||
}
|
||||
|
||||
if( !no_quoted && (wcslen( in ) == 0) )
|
||||
{
|
||||
out = wcsdup(L"''");
|
||||
if( !out )
|
||||
DIE_MEM();
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
out = malloc( sizeof(wchar_t)*(wcslen(in)*4 + 1));
|
||||
pos = out;
|
||||
@@ -728,6 +805,7 @@ wchar_t *escape( const wchar_t *in,
|
||||
|
||||
tmp = val%16;
|
||||
*pos++ = tmp > 9? L'a'+(tmp-10):L'0'+tmp;
|
||||
need_escape=need_complex_escape=1;
|
||||
|
||||
}
|
||||
else
|
||||
@@ -738,29 +816,44 @@ wchar_t *escape( const wchar_t *in,
|
||||
case L'\t':
|
||||
*(pos++) = L'\\';
|
||||
*(pos++) = L't';
|
||||
need_escape=need_complex_escape=1;
|
||||
break;
|
||||
|
||||
case L'\n':
|
||||
*(pos++) = L'\\';
|
||||
*(pos++) = L'n';
|
||||
need_escape=need_complex_escape=1;
|
||||
break;
|
||||
|
||||
case L'\b':
|
||||
*(pos++) = L'\\';
|
||||
*(pos++) = L'b';
|
||||
need_escape=need_complex_escape=1;
|
||||
break;
|
||||
|
||||
case L'\r':
|
||||
*(pos++) = L'\\';
|
||||
*(pos++) = L'r';
|
||||
need_escape=need_complex_escape=1;
|
||||
break;
|
||||
|
||||
case L'\e':
|
||||
case L'\x1b':
|
||||
*(pos++) = L'\\';
|
||||
*(pos++) = L'e';
|
||||
need_escape=need_complex_escape=1;
|
||||
break;
|
||||
|
||||
|
||||
case L'\\':
|
||||
case L'\'':
|
||||
{
|
||||
need_escape=need_complex_escape=1;
|
||||
if( escape_all )
|
||||
*pos++ = L'\\';
|
||||
*pos++ = *in;
|
||||
break;
|
||||
}
|
||||
|
||||
case L'&':
|
||||
case L'$':
|
||||
case L' ':
|
||||
@@ -778,11 +871,11 @@ wchar_t *escape( const wchar_t *in,
|
||||
case L'*':
|
||||
case L'|':
|
||||
case L';':
|
||||
case L'\'':
|
||||
case L'"':
|
||||
case L'%':
|
||||
case L'~':
|
||||
{
|
||||
need_escape=1;
|
||||
if( escape_all )
|
||||
*pos++ = L'\\';
|
||||
*pos++ = *in;
|
||||
@@ -793,11 +886,24 @@ wchar_t *escape( const wchar_t *in,
|
||||
{
|
||||
if( *in < 32 )
|
||||
{
|
||||
if( *in <27 && *in > 0 )
|
||||
{
|
||||
*(pos++) = L'\\';
|
||||
*(pos++) = L'c';
|
||||
*(pos++) = L'a' + *in -1;
|
||||
|
||||
need_escape=need_complex_escape=1;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int tmp = (*in)%16;
|
||||
*pos++ = L'\\';
|
||||
*pos++ = L'x';
|
||||
*pos++ = ((*in>15)? L'1' : L'0');
|
||||
*pos++ = tmp > 9? L'a'+(tmp-10):L'0'+tmp;
|
||||
need_escape=need_complex_escape=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -811,6 +917,17 @@ wchar_t *escape( const wchar_t *in,
|
||||
in++;
|
||||
}
|
||||
*pos = 0;
|
||||
|
||||
/*
|
||||
Use quoted escaping if possible, since most people find it
|
||||
easier to read.
|
||||
*/
|
||||
if( !no_quoted && need_escape && !need_complex_escape && escape_all )
|
||||
{
|
||||
free( out );
|
||||
out = escape_simple( in_orig );
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -999,7 +1116,7 @@ wchar_t *unescape( const wchar_t * orig, int flags )
|
||||
}
|
||||
|
||||
/*
|
||||
\e means escape
|
||||
\x1b means escape
|
||||
*/
|
||||
case L'e':
|
||||
{
|
||||
@@ -1044,7 +1161,7 @@ wchar_t *unescape( const wchar_t * orig, int flags )
|
||||
}
|
||||
|
||||
/*
|
||||
\v means vetrical tab
|
||||
\v means vertical tab
|
||||
*/
|
||||
case L'v':
|
||||
{
|
||||
@@ -1483,7 +1600,7 @@ int acquire_lock_file( const char *lockfile, const int timeout, int force )
|
||||
goto done;
|
||||
}
|
||||
(void)unlink( linkfile );
|
||||
if( ( fd = open( linkfile, O_CREAT|O_RDONLY ) ) == -1 )
|
||||
if( ( fd = open( linkfile, O_CREAT|O_RDONLY, 0600 ) ) == -1 )
|
||||
{
|
||||
debug( 1, L"acquire_lock_file: open: %s", strerror( errno ) );
|
||||
goto done;
|
||||
@@ -1671,8 +1788,72 @@ int create_directory( wchar_t *d )
|
||||
void bugreport()
|
||||
{
|
||||
debug( 1,
|
||||
_( L"This is a bug. "
|
||||
L"If you can reproduce it, please send a bug report to %s." ),
|
||||
_( L"This is a bug. "
|
||||
L"If you can reproduce it, please send a bug report to %s." ),
|
||||
PACKAGE_BUGREPORT );
|
||||
}
|
||||
|
||||
|
||||
void sb_format_size( string_buffer_t *sb,
|
||||
long long sz )
|
||||
{
|
||||
wchar_t *sz_name[]=
|
||||
{
|
||||
L"kB", L"MB", L"GB", L"TB", L"PB", L"EB", L"ZB", L"YB", 0
|
||||
}
|
||||
;
|
||||
|
||||
if( sz < 0 )
|
||||
{
|
||||
sb_append( sb, L"unknown" );
|
||||
}
|
||||
else if( sz < 1 )
|
||||
{
|
||||
sb_append( sb, _( L"empty" ) );
|
||||
}
|
||||
else if( sz < 1024 )
|
||||
{
|
||||
sb_printf( sb, L"%lldB", sz );
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i=0; sz_name[i]; i++ )
|
||||
{
|
||||
if( sz < (1024*1024) || !sz_name[i+1] )
|
||||
{
|
||||
int isz = sz/1024;
|
||||
if( isz > 9 )
|
||||
sb_printf( sb, L"%d%ls", isz, sz_name[i] );
|
||||
else
|
||||
sb_printf( sb, L"%.1f%ls", (double)sz/1024, sz_name[i] );
|
||||
break;
|
||||
}
|
||||
sz /= 1024;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double timef()
|
||||
{
|
||||
int time_res;
|
||||
struct timeval tv;
|
||||
|
||||
time_res = gettimeofday(&tv, 0);
|
||||
|
||||
if( time_res )
|
||||
{
|
||||
/*
|
||||
Fixme: What on earth is the correct parameter value for NaN?
|
||||
The man pages and the standard helpfully state that this
|
||||
parameter is implementation defined. Gcc gives a warning if
|
||||
a null pointer is used. But not even all mighty Google gives
|
||||
a hint to what value should actually be returned.
|
||||
*/
|
||||
return nan("");
|
||||
}
|
||||
|
||||
return (double)tv.tv_sec + 0.000001*tv.tv_usec;
|
||||
}
|
||||
|
||||
93
common.h
93
common.h
@@ -40,9 +40,25 @@
|
||||
*/
|
||||
#define BYTE_MAX 0xffu
|
||||
|
||||
/**
|
||||
Escape special fish syntax characters like the semicolon
|
||||
*/
|
||||
#define UNESCAPE_SPECIAL 1
|
||||
|
||||
/**
|
||||
Allow incomplete escape sequences
|
||||
*/
|
||||
#define UNESCAPE_INCOMPLETE 2
|
||||
|
||||
/**
|
||||
Escape all characters, including magic characters like the semicolon
|
||||
*/
|
||||
#define ESCAPE_ALL 1
|
||||
/**
|
||||
Do not try to use 'simplified' quoted escapes, and do not use empty quotes as the empty string
|
||||
*/
|
||||
#define ESCAPE_NO_QUOTED 2
|
||||
|
||||
|
||||
/**
|
||||
Save the shell mode on startup so we can restore them on exit
|
||||
@@ -93,13 +109,13 @@ 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 ); \
|
||||
} \
|
||||
|
||||
|
||||
/**
|
||||
@@ -140,7 +156,16 @@ extern wchar_t *program_name;
|
||||
*/
|
||||
#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();
|
||||
@@ -220,17 +245,12 @@ char **wcsv2strv( const wchar_t **in );
|
||||
*/
|
||||
wchar_t **strv2wcsv( const char **in );
|
||||
|
||||
/**
|
||||
Returns a newly allocated concatenation of the specified wide
|
||||
character strings
|
||||
*/
|
||||
wchar_t *wcsdupcat( const wchar_t *a, const wchar_t *b );
|
||||
|
||||
/**
|
||||
Returns a newly allocated concatenation of the specified wide
|
||||
character strings. The last argument must be a null pointer.
|
||||
*/
|
||||
__sentinel wchar_t *wcsdupcat2( const wchar_t *a, ... );
|
||||
__sentinel wchar_t *wcsdupcat_internal( const wchar_t *a, ... );
|
||||
|
||||
/**
|
||||
Test if the given string is a valid variable name
|
||||
@@ -300,16 +320,23 @@ const wchar_t *wsetlocale( int category, const wchar_t *locale );
|
||||
|
||||
\param needle the string to search for in the list
|
||||
|
||||
\return zero is needle is not found, of if needle is null, non-zero otherwise
|
||||
\return zero if needle is not found, of if needle is null, non-zero otherwise
|
||||
*/
|
||||
__sentinel int contains_str( const wchar_t *needle, ... );
|
||||
__sentinel int contains_internal( const wchar_t *needle, ... );
|
||||
|
||||
/**
|
||||
Call read while blocking the SIGCHLD signal. Should only be called
|
||||
if you _know_ there is data available for reading.
|
||||
if you _know_ there is data available for reading, or the program
|
||||
will hang until there is data.
|
||||
*/
|
||||
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
|
||||
@@ -368,17 +395,17 @@ wchar_t *unescape( const wchar_t * in,
|
||||
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.
|
||||
Returns the width of the terminal window, so that not all
|
||||
functions that use these values continually have to keep track of
|
||||
it separately.
|
||||
|
||||
Only works if common_handle_winch is registered to handle winch signals.
|
||||
Only works if common_handle_winch is registered to handle winch signals.
|
||||
*/
|
||||
int common_get_width();
|
||||
/**
|
||||
Returns the height of the terminal window, so that not all
|
||||
functions that use these values continually have to keep track of
|
||||
it.
|
||||
it separatly.
|
||||
|
||||
Only works if common_handle_winch is registered to handle winch signals.
|
||||
*/
|
||||
@@ -407,11 +434,11 @@ void write_screen( const wchar_t *msg, string_buffer_t *buff );
|
||||
*/
|
||||
void tokenize_variable_array( const wchar_t *val, array_list_t *out );
|
||||
|
||||
|
||||
/**
|
||||
Make sure the specified direcotry exists. If no, try to create it.
|
||||
Make sure the specified direcotry exists. If needed, try to create
|
||||
it and any currently not existing parent directories..
|
||||
|
||||
\return 0 if the directory exists, -1 otherwise.
|
||||
\return 0 if, at the time of function return the directory exists, -1 otherwise.
|
||||
*/
|
||||
int create_directory( wchar_t *d );
|
||||
|
||||
@@ -420,5 +447,21 @@ int create_directory( wchar_t *d );
|
||||
*/
|
||||
void bugreport();
|
||||
|
||||
/**
|
||||
Format the specified size (in bytes, kilobytes, etc.) into the specified stringbuffer.
|
||||
*/
|
||||
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
|
||||
|
||||
|
||||
897
complete.c
897
complete.c
File diff suppressed because it is too large
Load Diff
118
complete.h
118
complete.h
@@ -66,6 +66,70 @@
|
||||
*/
|
||||
#define PROG_COMPLETE_SEP L'\t'
|
||||
|
||||
/**
|
||||
Do not insert space afterwards if this is the only completion. (The
|
||||
default is to try insert a space)
|
||||
*/
|
||||
#define COMPLETE_NO_SPACE 1
|
||||
|
||||
/**
|
||||
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
|
||||
contains the _entire_ completion token, not only the current
|
||||
*/
|
||||
#define COMPLETE_NO_CASE 2
|
||||
|
||||
/**
|
||||
This compeltion is the whole argument, not just the remainder. This
|
||||
flag must never be set on completions returned from the complete()
|
||||
function. It is strictly for internal use in the completion code.
|
||||
*/
|
||||
#define COMPLETE_WHOLE_ARGUMENT 4
|
||||
|
||||
/**
|
||||
This completion may or may not want a space at the end - guess by
|
||||
checking the last character of the completion.
|
||||
*/
|
||||
#define COMPLETE_AUTO_SPACE 8
|
||||
|
||||
/**
|
||||
This completion should be inserted as-is, without escaping.
|
||||
*/
|
||||
#define COMPLETE_DONT_ESCAPE 16
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
||||
/**
|
||||
The completion string
|
||||
*/
|
||||
const wchar_t *completion;
|
||||
|
||||
/**
|
||||
The description for this completion
|
||||
*/
|
||||
const wchar_t *description;
|
||||
|
||||
/**
|
||||
Flags determining the completion behaviour.
|
||||
|
||||
Determines whether a space should be inserted after this
|
||||
compeltion if it is the only possible completion using the
|
||||
COMPLETE_NO_SPACE flag.
|
||||
|
||||
The COMPLETE_NO_CASE can be used to signal that this completion
|
||||
is case insensitive.
|
||||
*/
|
||||
int flags;
|
||||
|
||||
}
|
||||
completion_t;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Add a completion.
|
||||
@@ -106,33 +170,34 @@
|
||||
\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 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_authorative( const wchar_t *cmd,
|
||||
int cmd_type,
|
||||
int authorative );
|
||||
void complete_set_authoritative( const wchar_t *cmd,
|
||||
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 );
|
||||
int cmd_type,
|
||||
wchar_t short_opt,
|
||||
const wchar_t *long_opt );
|
||||
|
||||
/**
|
||||
Find all completions of the command cmd, insert them into out. The
|
||||
@@ -153,15 +218,6 @@ void complete( const wchar_t *cmd, array_list_t *out );
|
||||
*/
|
||||
void complete_print( string_buffer_t *out );
|
||||
|
||||
/**
|
||||
Obtain a description string for the file specified by the filename.
|
||||
|
||||
The returned value is a string constant and should not be freed.
|
||||
|
||||
\param filename The file for which to find a description string
|
||||
*/
|
||||
const wchar_t *complete_get_desc( const wchar_t *filename );
|
||||
|
||||
/**
|
||||
Tests if the specified option is defined for the specified command
|
||||
*/
|
||||
@@ -189,4 +245,18 @@ int complete_is_valid_argument( const wchar_t *str,
|
||||
*/
|
||||
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
|
||||
\param comp The completion string
|
||||
\param desc The description of the completion
|
||||
\param flags completion flags
|
||||
*/
|
||||
void completion_allocate( array_list_t *context,
|
||||
const wchar_t *comp,
|
||||
const wchar_t *desc,
|
||||
int flags );
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
252
configure.ac
252
configure.ac
@@ -9,9 +9,30 @@
|
||||
# configure the build process.
|
||||
#
|
||||
|
||||
AC_INIT(fish,1.22.3,fish-users@lists.sf.net)
|
||||
AC_INIT(fish,1.23.0,fish-users@lists.sf.net)
|
||||
|
||||
|
||||
#
|
||||
# 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)
|
||||
|
||||
#
|
||||
# If needed, run autoconf to regenerate the configure file
|
||||
#
|
||||
@@ -107,8 +128,6 @@ for i in /usr/pkg /sw /opt /opt/local; do
|
||||
|
||||
done
|
||||
|
||||
AC_SUBST( optbindirs, $optbindirs )
|
||||
|
||||
|
||||
#
|
||||
# Tell autoconf to create config.h header
|
||||
@@ -134,11 +153,13 @@ AH_BOTTOM([#if __GNUC__ >= 3
|
||||
# Set up various programs needed for install
|
||||
#
|
||||
|
||||
AC_PROG_CC
|
||||
# Here we look for c99 before cc as Sun Studio compiler supports c99
|
||||
# through the c99 binary.
|
||||
|
||||
AC_PROG_CC([gcc c99 cc])
|
||||
AC_PROG_CPP
|
||||
AC_PROG_INSTALL
|
||||
|
||||
|
||||
#
|
||||
# Check for seq command. If missing, make sure fallback shellscript
|
||||
# implementation is installed.
|
||||
@@ -161,7 +182,7 @@ if test "$SEQ_FALLBACK"; then
|
||||
shebang=`grep "\(^#!/.*/fish\|^#!/usr/bin/env fish\)" $file`
|
||||
|
||||
if test "$shebang"; then
|
||||
AC_SUBST( SEQ_FALLBACK, seq )
|
||||
SEQ_FALLBACK=seq
|
||||
AC_MSG_RESULT(yes, replace it)
|
||||
else
|
||||
AC_MSG_RESULT(no, keep it)
|
||||
@@ -185,13 +206,9 @@ AC_ARG_WITH(
|
||||
)
|
||||
|
||||
if [[ "$xsel" = "with_xsel" ]]; then
|
||||
AC_SUBST( XSEL,[xsel-0.9.6/xsel])
|
||||
AC_SUBST( XSEL_MAN,[xsel.1x])
|
||||
AC_SUBST( XSEL_MAN_PATH,[xsel-0.9.6/xsel.1x])
|
||||
else
|
||||
AC_SUBST( XSEL,[ ])
|
||||
AC_SUBST( XSEL_MAN,[ ])
|
||||
AC_SUBST( XSEL_MAN_PATH,[ ])
|
||||
XSEL=xsel-0.9.6/xsel
|
||||
XSEL_MAN=xsel.1x
|
||||
XSEL_MAN_PATH=xsel-0.9.6/xsel.1x
|
||||
fi
|
||||
|
||||
|
||||
@@ -217,56 +234,59 @@ fi
|
||||
#
|
||||
# Test if the compiler accepts the -std=c99 flag. If so, using it
|
||||
# increases the odds of correct compilation, since we want to use the
|
||||
# *wprintf functions, which where defined in C99.
|
||||
# *wprintf functions, which where defined in C99.
|
||||
#
|
||||
# NOTE: Never versions of autoconf has AC_CHECK_PROG_CC_C99
|
||||
#
|
||||
|
||||
XCFLAGS="$CFLAGS"
|
||||
CFLAGS="$CFLAGS -std=c99"
|
||||
XCPPFLAGS="$CPPFLAGS"
|
||||
CPPFLAGS="$CPPFLAGS -std=c99"
|
||||
AC_MSG_CHECKING(if -std=c99 works)
|
||||
if test "$CC" != "c99"; then
|
||||
XCFLAGS="$CFLAGS"
|
||||
CFLAGS="$CFLAGS -std=c99"
|
||||
XCPPFLAGS="$CPPFLAGS"
|
||||
CPPFLAGS="$CPPFLAGS -std=c99"
|
||||
AC_MSG_CHECKING(if -std=c99 works)
|
||||
|
||||
AC_CACHE_VAL(
|
||||
local_cv_has__std_c99,
|
||||
[
|
||||
AC_TRY_RUN(
|
||||
[
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
AC_CACHE_VAL(
|
||||
local_cv_has__std_c99,
|
||||
[
|
||||
AC_TRY_RUN(
|
||||
[
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
],
|
||||
local_cv_has__std_c99=yes,
|
||||
local_cv_has__std_c99=no,
|
||||
)
|
||||
]
|
||||
)
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
],
|
||||
local_cv_has__std_c99=yes,
|
||||
local_cv_has__std_c99=no,
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
AC_MSG_RESULT($local_cv_has__std_c99)
|
||||
case x$local_cv_has__std_c99 in
|
||||
xno)
|
||||
CFLAGS="$XCFLAGS"
|
||||
CPPFLAGS="$XCPPFLAGS" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
#
|
||||
# Try to enale large file support. This will make sure that on systems
|
||||
# Try to enable large file support. This will make sure that on systems
|
||||
# where off_t can be either 32 or 64 bit, the latter size is used. On
|
||||
# other systems, this should do nothing. (Hopefully)
|
||||
#
|
||||
|
||||
CFLAGS="$CFLAGS -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64"
|
||||
|
||||
AC_MSG_RESULT($local_cv_has__std_c99)
|
||||
case x$local_cv_has__std_c99 in
|
||||
xno)
|
||||
CFLAGS="$XCFLAGS"
|
||||
CPPFLAGS="$XCPPFLAGS" ;;
|
||||
esac
|
||||
|
||||
|
||||
#
|
||||
# If we are using gcc, set some flags that increase the odds of the
|
||||
# compiler producing a working binary...
|
||||
#
|
||||
|
||||
if test "$CC" = gcc; then
|
||||
if test "$GCC" = yes; then
|
||||
|
||||
#
|
||||
# -fno-optimize-sibling-calls seems to work around a bug where
|
||||
@@ -291,7 +311,7 @@ if test "$CC" = gcc; then
|
||||
# This is needed in order to get the really cool backtraces
|
||||
#
|
||||
|
||||
LDFLAGS="$LDFLAGS -rdynamic"
|
||||
LDFLAGS_FISH="$LDFLAGS_FISH -rdynamic"
|
||||
|
||||
fi
|
||||
|
||||
@@ -372,6 +392,34 @@ case $target_os in
|
||||
;;
|
||||
esac
|
||||
|
||||
# Check for Solaris curses tputs having fixed length parameter list.
|
||||
AC_MSG_CHECKING([if we are using non varargs tparm.])
|
||||
AC_COMPILE_IFELSE(
|
||||
[
|
||||
AC_LANG_PROGRAM(
|
||||
[
|
||||
#include <curses.h>
|
||||
#include <term.h>
|
||||
],
|
||||
[
|
||||
tparm( "" );
|
||||
]
|
||||
)
|
||||
],
|
||||
[tparm_solaris_kludge=no],
|
||||
[tparm_solaris_kludge=yes]
|
||||
)
|
||||
if test "x$tparm_solaris_kludge" = "xyes"; then
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(
|
||||
[TPARM_SOLARIS_KLUDGE],
|
||||
[1],
|
||||
[Define to 1 if tparm accepts a fixed amount of paramters.]
|
||||
)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# BSD-specific flags go here
|
||||
@@ -398,10 +446,7 @@ esac
|
||||
#
|
||||
|
||||
if [[ "$prefix" = NONE ]]; then
|
||||
export prefix=/usr/local
|
||||
AC_SUBST( prefix, /usr/local)
|
||||
else
|
||||
AC_SUBST( prefix, [$prefix])
|
||||
prefix=/usr/local
|
||||
fi
|
||||
|
||||
|
||||
@@ -413,9 +458,9 @@ fi
|
||||
AC_ARG_VAR( [docdir], [Documentation direcotry] )
|
||||
|
||||
if test -z $docdir; then
|
||||
AC_SUBST(docdir, [$datadir/doc/fish] )
|
||||
docdir=$datadir/doc/fish
|
||||
else
|
||||
AC_SUBST(docdir, [$docdir])
|
||||
docdir=$docdir
|
||||
fi
|
||||
|
||||
|
||||
@@ -424,7 +469,7 @@ fi
|
||||
# installed.
|
||||
#
|
||||
|
||||
AC_SUBST( [localedir], [$datadir/locale])
|
||||
localedir=$datadir/locale
|
||||
|
||||
|
||||
#
|
||||
@@ -448,18 +493,101 @@ AC_DEFINE(
|
||||
|
||||
|
||||
#
|
||||
# Check presense of various libraries
|
||||
# Check presense of various libraries. This is done on a per-binary
|
||||
# level, since including various extra libraries in all binaries only
|
||||
# because thay are used by some of them can cause extra bloat and
|
||||
# slower compiles when developing fish.
|
||||
#
|
||||
|
||||
# Only link with gettext if we are using it
|
||||
if test x$local_gettext != xno; then
|
||||
AC_SEARCH_LIBS( gettext, intl,,)
|
||||
fi
|
||||
# Check for os dependant libraries for all binaries.
|
||||
LIBS_COMMON=$LIBS
|
||||
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( iconv_open, iconv, , [AC_MSG_ERROR([Could not find an iconv 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.
|
||||
#
|
||||
|
||||
LIBS_COMMON=$LIBS
|
||||
LIBS="$LIBS_SHARED"
|
||||
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])] )] )
|
||||
|
||||
LIBS_FISH=$LIBS
|
||||
LIBS=$LIBS_COMMON
|
||||
|
||||
#
|
||||
# Check for libraries needed by fish_indent.
|
||||
#
|
||||
|
||||
LIBS_COMMON=$LIBS
|
||||
LIBS="$LIBS_SHARED"
|
||||
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.
|
||||
#
|
||||
|
||||
LIBS_COMMON=$LIBS
|
||||
LIBS="$LIBS_SHARED"
|
||||
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.
|
||||
#
|
||||
|
||||
LIBS_COMMON=$LIBS
|
||||
LIBS="$LIBS_SHARED"
|
||||
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.
|
||||
#
|
||||
|
||||
LIBS_COMMON=$LIBS
|
||||
LIBS="$LIBS_SHARED"
|
||||
if test x$local_gettext != xno; then
|
||||
AC_SEARCH_LIBS( gettext, intl,,)
|
||||
fi
|
||||
LIBS_MIMEDB=$LIBS
|
||||
LIBS=$LIBS_COMMON
|
||||
|
||||
|
||||
#
|
||||
# Check for libraries needed by set_color
|
||||
#
|
||||
|
||||
LIBS_COMMON=$LIBS
|
||||
LIBS="$LIBS_SHARED"
|
||||
if test x$local_gettext != xno; then
|
||||
AC_SEARCH_LIBS( gettext, intl,,)
|
||||
fi
|
||||
LIBS_SET_COLOR=$LIBS
|
||||
LIBS=$LIBS_COMMON
|
||||
|
||||
#
|
||||
# Check presense of various header files
|
||||
@@ -609,7 +737,7 @@ fi
|
||||
AC_CHECK_FUNCS( wcsdup wcsndup wcslen wcscasecmp wcsncasecmp fwprintf )
|
||||
AC_CHECK_FUNCS( futimes wcwidth wcswidth wcstok fputwc fgetwc )
|
||||
AC_CHECK_FUNCS( wcstol wcslcat wcslcpy lrand48_r killpg gettext )
|
||||
AC_CHECK_FUNCS( dcgettext backtrace backtrace_symbols)
|
||||
AC_CHECK_FUNCS( dcgettext backtrace backtrace_symbols sysconf )
|
||||
|
||||
#
|
||||
# The Makefile also needs to know if we have gettext, so it knows if
|
||||
@@ -617,7 +745,7 @@ AC_CHECK_FUNCS( dcgettext backtrace backtrace_symbols)
|
||||
#
|
||||
|
||||
if test x$local_gettext != xno; then
|
||||
AC_CHECK_FUNC( gettext, AC_SUBST( HAVE_GETTEXT, 1 ), AC_SUBST( HAVE_GETTEXT, 0 ) )
|
||||
AC_CHECK_FUNC( gettext, HAVE_GETTEXT=1, HAVE_GETTEXT=0 )
|
||||
fi
|
||||
|
||||
#
|
||||
|
||||
24
count.c
24
count.c
@@ -1,24 +0,0 @@
|
||||
/** \file count.c
|
||||
The length command, used for determining the number of items in an
|
||||
environment variable array.
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/**
|
||||
The main function. Does nothing but return the number of arguments.
|
||||
|
||||
This command, unlike all other fish commands, does not feature a -h
|
||||
or --help option. This is because we want to avoid errors on arrays
|
||||
that have -h or --help as entries, which is very common when
|
||||
parsing options, etc. For this reason, the main fish binary does a
|
||||
check and prints help usage if -h or --help is explicitly given to
|
||||
the command, but not if it is the contents of a variable.
|
||||
*/
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
printf( "%d\n", argc-1 );
|
||||
return argc==1;
|
||||
}
|
||||
@@ -17,7 +17,7 @@ variable.
|
||||
\subsection and-example Example
|
||||
|
||||
The following code runs the \c make command to build a program, if the
|
||||
build succceds, 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
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ Sends the specified jobs to the background. A background job is
|
||||
executed simultaneously with fish, and does not have access to the
|
||||
keyboard. If no job is specified, the last job to be used is put in the background. If PID is specified, the jobs with the specified group ids are put in the background.
|
||||
|
||||
The PID of the desired process is usually found by using process globbing.
|
||||
The PID of the desired process is usually found by using <a href="index.html#expand-process">process expansion</a>.
|
||||
|
||||
\subsection bg-example Example
|
||||
|
||||
|
||||
@@ -1,23 +1,60 @@
|
||||
\section bind bind - handle key bindings
|
||||
\section bind bind - handle fish key bindings
|
||||
|
||||
\subsection bind-synopsis Synopsis
|
||||
<tt>bind [OPTIONS] [BINDINGS...]</tt>
|
||||
|
||||
The <tt>bind</tt> builtin causes fish to add the readline style bindings specified by BINDINGS to the list of key bindings, as if they appeared in your <tt>~/.fish_inputrc</tt> file.
|
||||
|
||||
For more information on the syntax keyboard bindings, use <tt>man
|
||||
readline</tt> to access the readline documentation. The availiable commands
|
||||
are listed in the <a href="index.html#editor">Command Line Editor</a> section
|
||||
of the fish manual - but you may also use any fish command! To write such
|
||||
commands, see the <a href="#commandline">commandline</a> builtin. It's good
|
||||
practice to put the code into a <tt><a href="#function">function</a> -b</tt>
|
||||
and bind to the function name.
|
||||
<tt>bind [OPTIONS] SEQUENCE COMMAND</tt>
|
||||
|
||||
\subsection bind-description Description
|
||||
- <tt>-M MODE</tt> or <tt>--set-mode=MODE</tt> sets the current input mode to MODE.
|
||||
|
||||
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, 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
|
||||
other binding matches. For most key bindings, it makes sense to use
|
||||
the \c self-insert function (i.e. <tt>bind '' self-insert</tt> as the
|
||||
default keybining. This will insert any keystrokes not specifically
|
||||
bound to into the editor. Non-printable characters are ignored by the
|
||||
editor, so this will not result in e.g. control sequences being
|
||||
printable.
|
||||
|
||||
If the -k switch is used, the name of the key (such as down, up or
|
||||
backspace) is used instead of a sequence. The names used are the same
|
||||
as the corresponding curses variables, but without the 'key_'
|
||||
prefix. (See man 5 terminfo for more information, or use <tt>bind
|
||||
--key-names</tt> for a list of all available named keys)
|
||||
|
||||
COMMAND can be any fish command, but it can also be one of a set of
|
||||
special input functions. These include functions for moving the
|
||||
cursor, operating on the kill-ring, performing tab completion,
|
||||
etc. Use 'bind --function-names' for a complete list of these input
|
||||
functions.
|
||||
|
||||
When COMMAND is a shellscript command, it is a good practice to put
|
||||
the actual code into a <a href="#function">function</a> and simply
|
||||
bind to the function name. This way it becomes significantly easier to
|
||||
test the function while editing, and the result is usually more
|
||||
readable as well.
|
||||
|
||||
- <tt>-a</tt> or <tt>--all</tt> If --key-names is specified, show all key names, not only the ones that actually are defined for the current terminal. If erase mode is specified, this switch will cause all current bindings to be erased.
|
||||
- <tt>-e</tt> or <tt>--erase</tt> Erase mode. All non-switch arguments are interpreted as character sequences and any commands associated with those sequences are erased.
|
||||
- <tt>-h</tt> or <tt>--help</tt> Display help and exit
|
||||
- <tt>-k</tt> or <tt>--key</tt> Specify a key name, such as 'left' or 'backspace' instead of a character sequence
|
||||
- <tt>-K</tt> or <tt>--key-names</tt> Display a list of available key names
|
||||
- <tt>-f</tt> or <tt>--function-names</tt> Display a list of available input functions
|
||||
|
||||
\subsection bind-example Example
|
||||
|
||||
<tt>bind -M vi</tt> changes to the vi input mode
|
||||
<tt>bind \\cd 'exit'</tt> causes fish to exit on Control-d
|
||||
|
||||
<tt>bind -k ppage history-search-backward</tt> Causes fish to perform a history search when the page up key is pressed
|
||||
|
||||
<tt>bind '"\\M-j": jobs'</tt> Binds the jobs command to the Alt-j keyboard shortcut
|
||||
|
||||
10
doc_src/breakpoint.txt
Normal file
10
doc_src/breakpoint.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
\section breakpoint breakpoint - Launch debug mode
|
||||
|
||||
\subsection breakpoint-synopsis Synopsis
|
||||
<tt>breakpoint</tt>
|
||||
|
||||
\subsection breakpoint-description Description
|
||||
|
||||
The \c breakpoint builtin is used to halt a running script and launch
|
||||
an interactive debug prompt.
|
||||
|
||||
@@ -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 stamantes 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
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
|
||||
|
||||
- \c CMD is the new value of the commandline. If unspecified, the
|
||||
current value of the commandline is written to standard output.
|
||||
current value of the commandline is written to standard output. All
|
||||
output from the commandline builtin is escaped, i.e. quotes are
|
||||
removed, backslash escapes are expanded, etc..
|
||||
|
||||
The following switches change what the commandline builtin does
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ the fish manual.
|
||||
- <tt>-o</tt> or <tt>--old-option</tt> implies that the command uses old long style options with only one dash
|
||||
- <tt>-p</tt> or <tt>--path</tt> implies that the string COMMAND is the full path of the command
|
||||
- <tt>-r</tt> or <tt>--require-parameter</tt> specifies that the option specified by this completion always must have an option argument, i.e. may not be followed by another option
|
||||
- <tt>-u</tt> or <tt>--unauthorative</tt> implies that there may be more options than the ones specified, and that fish should not assume that options not listed are spelling errors
|
||||
- <tt>-A</tt> or <tt>--authorative</tt> implies that there may be no more options than the ones specified, and that fish should assume that options not listed are spelling errors
|
||||
- <tt>-u</tt> or <tt>--unauthoritative</tt> implies that there may be more options than the ones specified, and that fish should not assume that options not listed are spelling errors
|
||||
- <tt>-A</tt> or <tt>--authoritative</tt> implies that there may be no more options than the ones specified, and that fish should assume that options not listed are spelling errors
|
||||
- <tt>-x</tt> or <tt>--exclusive</tt> implies both <tt>-r</tt> and <tt>-f</tt>
|
||||
|
||||
Command specific tab-completions in \c fish are based on the notion
|
||||
|
||||
@@ -5,17 +5,18 @@
|
||||
|
||||
\subsection count-description Description
|
||||
|
||||
<tt>count</tt> prints the number of arguments that were passed to
|
||||
it. This is usually used to find out how many elements an environment
|
||||
variable array contains, but this is not the only potential usage for
|
||||
the count command.
|
||||
The <tt>count</tt> builtin prints the number of arguments that were
|
||||
passed to it. This is usually used to find out how many elements an
|
||||
environment variable array contains, but this is not the only
|
||||
potential usage for the count command.
|
||||
|
||||
The count command does not accept any options, not even '-h'. This way
|
||||
the user does not have to worry about an array containing elements
|
||||
such as dashes. \c fish performs a special check when invoking the
|
||||
count program, and if the user uses a help option, this help page is
|
||||
count command, and if the user uses a help option, this help page is
|
||||
displayed, but if a help option is contained inside of a variable or
|
||||
is the result of expansion, it will be passed on to the count program.
|
||||
is the result of expansion, it will simply be counted like any other
|
||||
argument.
|
||||
|
||||
Count exits with a non-zero exit status if no arguments where passed
|
||||
to it, with zero otherwise.
|
||||
|
||||
@@ -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.
|
||||
|
||||
19
doc_src/emit.txt
Normal file
19
doc_src/emit.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
\section emit emit - Emit a generic event
|
||||
|
||||
\subsection block-synopsis Synopsis
|
||||
<tt>emit EVENT_NAME</tt>
|
||||
|
||||
\subsection emit-description Description
|
||||
|
||||
The emit builtin fires a generic fish event. Such events can be caught by special functions called event handlers.
|
||||
|
||||
\subsection emit-example Example
|
||||
|
||||
The following code first defines an event handler for the generic
|
||||
event named 'test_event', and then emits an event of that type.
|
||||
|
||||
<pre>function event_test --on-event test_event
|
||||
echo event test!!!
|
||||
end
|
||||
|
||||
emit test_event</pre>
|
||||
@@ -1,10 +1,10 @@
|
||||
\section eval eval - eval the specified commands
|
||||
\section eval eval - evaluate the specified commands
|
||||
|
||||
\subsection eval-synopsis Synopsis
|
||||
<tt>eval [COMMANDS...]</tt>
|
||||
|
||||
\subsection eval-description Description
|
||||
The <tt>eval</tt> builtin causes fish to evaluate the specified parameters as a command. If more than one parameter is specified, all parameters will be joined using a space character as a separator.
|
||||
The <tt>eval</tt> function causes fish to evaluate the specified parameters as a command. If more than one parameter is specified, all parameters will be joined using a space character as a separator.
|
||||
|
||||
\subsection eval-example Example
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -56,8 +57,8 @@ 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>.
|
||||
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' > ~/.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.
|
||||
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
Sends the specified job to the foreground. While a foreground job is
|
||||
executed, fish is suspended. If no job is specified, the last job to be used is put in the foreground. If PID is specified, the job with the specified group id is put in the foreground.
|
||||
|
||||
The PID of the desired process is usually found by using process globbing.
|
||||
The PID of the desired process is usually found by using <a href="index.html#expand-process">process expansion</a>.
|
||||
|
||||
\subsection fg-example Example
|
||||
|
||||
|
||||
17
doc_src/fish_indent.txt
Normal file
17
doc_src/fish_indent.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
\section fish_indent fish_indent - indenter and prettyfier
|
||||
|
||||
\subsection fish_indent-synopsis Synopsis
|
||||
<tt>fish_indent [options]</tt>
|
||||
|
||||
\subsection fish_indent-description Description
|
||||
|
||||
\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 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
|
||||
- <tt>-v</tt> or <tt>--version</tt> displays the current fish version and then exits
|
||||
|
||||
23
doc_src/fish_prompt.txt
Normal file
23
doc_src/fish_prompt.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
\section fish_prompt fish_prompt - define the apperance of the command line prompt
|
||||
|
||||
\subsection fish_promt-synopsis Synopsis
|
||||
<pre>function fish_prompt
|
||||
...
|
||||
end</pre>
|
||||
|
||||
\subsection fish_prompt-description Description
|
||||
|
||||
By defining the \c fish_prompt function, the user can choose a custom
|
||||
prompt. The \c fish_prompt function is executed when the prompt is to
|
||||
be shown, and the output is used as a prompt.
|
||||
|
||||
\subsection fish_prompt-example Example
|
||||
|
||||
A simple prompt:
|
||||
|
||||
<pre>
|
||||
function fish_prompt -d "Write out the prompt"
|
||||
printf '\%s\@\%s\%s\%s\%s> ' (whoami) (hostname|cut -d . -f 1) (set_color \$fish_color_cwd) (prompt_pwd) (set_color normal)
|
||||
end
|
||||
</pre>
|
||||
|
||||
9
doc_src/funced.txt
Normal file
9
doc_src/funced.txt
Normal 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
12
doc_src/funcsave.txt
Normal 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.
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -10,9 +10,9 @@ 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.
|
||||
|
||||
In order to use the exit status of mutiple commands as the condition
|
||||
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
|
||||
the short circut commands <a href="commands.html#and">and</a> and <a
|
||||
the short circuit commands <a href="commands.html#and">and</a> and <a
|
||||
href="commands.html#or">or</a>.
|
||||
|
||||
The exit status of the last foreground command to exit can always be
|
||||
|
||||
@@ -138,8 +138,8 @@ these characters, so called escape sequences are provided. These are:
|
||||
- <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
|
||||
@@ -306,7 +306,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
|
||||
@@ -466,11 +466,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 +494,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 +509,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,14 +519,14 @@ 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
|
||||
@@ -741,17 +741,18 @@ command</a>.
|
||||
|
||||
Example:
|
||||
|
||||
To set the variable \c smurf to the value \c blue, use the command
|
||||
<code>set smurf blue</code>.
|
||||
To set the variable \c smurf_color to the value \c blue, use the command
|
||||
<code>set smurf_color blue</code>.
|
||||
|
||||
After a variable has been set, you can use the value of a variable in
|
||||
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
|
||||
$smurf</code>, which would print the result 'Smurfs are blue'.
|
||||
usually $smurf_color</code>, which would print the result 'Smurfs are
|
||||
usually blue'.
|
||||
|
||||
\subsection variables-scope Variable scope
|
||||
|
||||
@@ -853,7 +854,7 @@ identical to the scoping rules for variables:
|
||||
|
||||
-# If a variable is explicitly set to either be exported or not exported, that setting will be honored.
|
||||
-# If a variable is not explicitly set to be exported or not exported, but has been previously defined, the previous exporting rule for the variable is kept.
|
||||
-# If a variable is not explicitly set to be either global or local and has never before been defined, the variable will not be exported.
|
||||
-# If a variable is not explicitly set to be either exported or not exported and has never before been defined, the variable will not be exported.
|
||||
|
||||
|
||||
\subsection variables-arrays Arrays
|
||||
@@ -867,7 +868,7 @@ 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
|
||||
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
|
||||
@@ -911,7 +912,7 @@ The user can change the settings of \c fish by changing the values of
|
||||
certain environment variables.
|
||||
|
||||
- \c BROWSER, which is the users preferred web browser. If this variable is set, fish will use the specified browser instead of the system default browser to display the fish documentation.
|
||||
- \c CDPATH, which is an array of directories in which to search for the new directory for the \c cd builtin.
|
||||
- \c CDPATH, which is an array of directories in which to search for the new directory for the \c cd builtin. The fish init files defined CDPATH to be a universal variable with the values . and ~.
|
||||
- A large number of variable starting with the prefixes \c fish_color and \c fish_pager_color. See <a href='#variables-color'>Variables for changing highlighting colors</a> for more information.
|
||||
- \c fish_greeting, which is the greeting message printed on startup.
|
||||
- \c LANG, \c LC_ALL, \c LC_COLLATE, \c LC_CTYPE, \c LC_MESSAGES, \c LC_MONETARY, \c LC_NUMERIC and \c LC_TIME set the language option for the shell and subprograms. See the section <a href='#variables-locale'>Locale variables</a> for more information.
|
||||
@@ -927,15 +928,23 @@ values of most of these variables.
|
||||
- \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 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
|
||||
shells and differ from the ones used by Bourne style shells such as
|
||||
bash. The csh names where chosen because Bourne style names, such as
|
||||
?, * and @ lead to significantly less readable code, and much larger
|
||||
discoverability problems, and given the existence of tab completion,
|
||||
the keystroke savings are minimal.
|
||||
|
||||
Variables whose name are in uppercase are exported to the commands
|
||||
started by fish, those in lowercase are not exported. This rule is not
|
||||
enforced by fish, but it is good coding practice to use casing to
|
||||
distinguish between exported and unexported variables. \c fish also
|
||||
uses several variables internally. Such variables are prefixed with
|
||||
the string __FISH or __fish. These should be ignored by the user.
|
||||
the string __FISH or __fish. These should never be used by the
|
||||
user. Changing their value may break fish.
|
||||
|
||||
\subsection variables-status The status variable
|
||||
|
||||
@@ -953,10 +962,13 @@ If fish encounters a problem while executing a command, the status
|
||||
variable may also be set to a specific value:
|
||||
|
||||
- 1 is the generally the exit status from fish builtins if they where supplied with invalid arguments
|
||||
- 125 means an unknown error occured while trying to execute the command
|
||||
- 126 means that the command was not executed because none of the wildcards in the command produced any matches
|
||||
- 124 means that the command was not executed because none of the wildcards in the command produced any matches
|
||||
- 125 means that while an executable with the specified name was located, the operating system could not actually execute the command
|
||||
- 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
|
||||
@@ -965,7 +977,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
|
||||
@@ -1040,7 +1052,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>
|
||||
@@ -1052,14 +1064,8 @@ Here are some of the commands available in the editor:
|
||||
- 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 by making an inputrc file. To do
|
||||
this, copy the file /etc/fish/fish_inputrc to your home directory and
|
||||
rename it to '.config/fish/fish_inputrc'. Now you can edit the file
|
||||
to change your key bindings. The file format of this file is described
|
||||
in the manual page for readline. Use the command <code>man readline</code>
|
||||
to read up on this syntax. Please note that the list of key binding
|
||||
functions in fish is different to that offered by readline. Currently,
|
||||
the following functions are available:
|
||||
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
|
||||
@@ -1086,11 +1092,9 @@ the following functions are available:
|
||||
- \c yank, insert the latest entry of the killring into the buffer
|
||||
- \c yank-pop, rotate to the previous entry of the killring
|
||||
|
||||
You can also bind a pice of shellscript to a key using the same
|
||||
syntax. For example, the Alt-p functionality described above is
|
||||
implemented using the following keybinding.
|
||||
|
||||
<pre>"\M-p": if commandline -j|grep -v 'less *$' >/dev/null; commandline -aj "|less;"; end</pre>
|
||||
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)
|
||||
|
||||
@@ -1138,7 +1142,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
|
||||
@@ -1230,28 +1234,6 @@ Issuing <code>set fish_color_error black --background=red
|
||||
--bold</code> will make all commandline errors be written in a black,
|
||||
bold font, with a red background.
|
||||
|
||||
\subsection prompt Programmable prompt
|
||||
|
||||
By defining the \c fish_prompt function, the user can choose a custom
|
||||
prompt. The \c fish_prompt function is executed and the output is used
|
||||
as a prompt.
|
||||
|
||||
Example:
|
||||
<p>
|
||||
The default \c fish prompt is
|
||||
</p>
|
||||
<p>
|
||||
<pre>
|
||||
function fish_prompt -d "Write out the prompt"
|
||||
printf '\%s\@\%s\%s\%s\%s> ' (whoami) (hostname|cut -d . -f 1) (set_color \$fish_color_cwd) (prompt_pwd) (set_color normal)
|
||||
end
|
||||
</pre>
|
||||
|
||||
where \c prompt_pwd is a shellscript function that displays a condensed version of the current working directory.
|
||||
|
||||
</p>
|
||||
|
||||
|
||||
\subsection title Programmable title
|
||||
|
||||
When using most virtual terminals, it is possible to set the message
|
||||
@@ -1261,7 +1243,7 @@ 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>
|
||||
@@ -1276,6 +1258,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
|
||||
@@ -1285,6 +1273,8 @@ specific event takes place. Events that can trigger a handler currently are:
|
||||
- When a signal is delivered
|
||||
- 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:
|
||||
|
||||
@@ -1299,11 +1289,25 @@ For more information on how to define new event handlers, see the
|
||||
documentation for the <a href='commands.html#function'>function</a>
|
||||
command.
|
||||
|
||||
\subsection debugging Debugging fish scripts
|
||||
|
||||
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
|
||||
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 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.
|
||||
|
||||
@@ -1315,7 +1319,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>.
|
||||
@@ -1323,7 +1327,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
|
||||
@@ -1331,7 +1335,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
|
||||
@@ -1351,7 +1355,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>
|
||||
@@ -1374,28 +1378,19 @@ href='fish-users@lists.sf.net'>fish-users@lists.sf.net</a>.
|
||||
|
||||
\subsection todo-features Missing features
|
||||
|
||||
- A limited interactive mode for really dumb terminals
|
||||
- The completion autoloader does not remember which completions where actually autoloaded, and may unload manually specified completions.
|
||||
- Use a struct to describe a possible completion instead of a weirdly formated string
|
||||
- Complete vi-mode key bindings
|
||||
- More completions (for example xterm, vim,
|
||||
konsole, gnome-terminal, cron,
|
||||
- More completions (for example konsole, gnome-terminal,
|
||||
rlogin, rsync, arch, finger, bibtex, aspell, xpdf,
|
||||
compress, wine, xmms, dig, batch, cron,
|
||||
compress, wine, dig, batch,
|
||||
g++, javac, java, gcj, lpr, doxygen, whois)
|
||||
- Undo support
|
||||
- Check keybinding commands for output - if nothing has happened, don't repaint to reduce flicker
|
||||
- wait shellscript
|
||||
- Support for the screen clipboard
|
||||
- It should be possible to test in a script if a function is autoloaded or manually defined
|
||||
- A pretty-printer. It should among other things be able to indent a piece of code.
|
||||
- Up/down to move between lines in multiline mode
|
||||
- a 'funced' function, which works like the vared function. Needs the above three features in order to work well.
|
||||
- The validator should be better about error reporting unclosed quotes. They are usually reported as something else.
|
||||
|
||||
\subsection todo-possible Possible features
|
||||
|
||||
- tab completion could use smart casing
|
||||
- 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
|
||||
@@ -1405,17 +1400,14 @@ g++, javac, java, gcj, lpr, doxygen, whois)
|
||||
- Descriptions for variables using 'set -d'.
|
||||
- Parse errors should when possible honor IO redirections
|
||||
- Support for writing strings like /u/l/b/foo and have them expand to /usr/local/bin/foo - perhaps through tab expansion
|
||||
- Autoreload inputrc-file on updates
|
||||
- Right-side prompt
|
||||
- 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.
|
||||
- The parser_is_* functions should be moved to parse_util. Possibly, they should be made into a single function, i.e. parse_util_classify( "begin", BLOCK_COMMAND);
|
||||
- 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
|
||||
@@ -1423,24 +1415,26 @@ g++, javac, java, gcj, lpr, doxygen, whois)
|
||||
- The parser/validator could be more clever in order to make things like writing 'function --help' work as expected
|
||||
- Some event handler functions make much more sense as oneshots - maybe they should be automatically deleted after firing?
|
||||
- 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
|
||||
- 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-'
|
||||
- When a builtin has its output redirected to a file, and the builtin does not produce any IO, then the file is never opened. Thus tha file may not be cleared.
|
||||
- No '--' completion
|
||||
- else is not indented properly
|
||||
- if an if fails inside an if, the out if's else may trigger
|
||||
- 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 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.
|
||||
|
||||
*/
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
\subsection math-description Description
|
||||
|
||||
math is used to perform mathematical calcualtions. It is only a very
|
||||
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>.
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
The mimedb command is used to query the mimetype database and the
|
||||
.desktop files installed on the system in order to find information on
|
||||
a file. The information that mimedb can retrive includes the mimetype
|
||||
a file. The information that mimedb can retrieve includes the mimetype
|
||||
for a file, a description of the type and what its default action
|
||||
is. mimedb can also be used to launch the default action for this
|
||||
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.
|
||||
|
||||
@@ -17,7 +17,7 @@ variable.
|
||||
\subsection or-example Example
|
||||
|
||||
The following code runs the \c make command to build a program, if the
|
||||
build succceds, 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
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
\section prevd prevd - move backward through direcotry history
|
||||
\section prevd prevd - move backward through directory history
|
||||
|
||||
\subsection prevd-synopsis Synopsis
|
||||
<tt>prevd [-l | --list] [pos]</tt>
|
||||
|
||||
@@ -11,7 +11,7 @@ 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 hiustory 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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -43,7 +43,7 @@ the last index of an array.
|
||||
The scoping rules when creating or updating a variable are:
|
||||
|
||||
-# If a variable is explicitly set to either universal, global or local, that setting will be honored. If a variable of the same name exists in a different scope, that variable will not be changed.
|
||||
-# If a variable is not explicitly set to be either universal, global or local, but has been previously defined, the previos variable scope is used.
|
||||
-# If a variable is not explicitly set to be either universal, global or local, but has been previously defined, the previous variable scope is used.
|
||||
-# If a variable is not explicitly set to be either universal, global or local and has never before been defined, the variable will be local to the currently executing functions. If no function is executing, the variable will be global.
|
||||
|
||||
The exporting rules when creating or updating a variable are identical
|
||||
@@ -51,7 +51,7 @@ to the scoping rules for variables:
|
||||
|
||||
-# If a variable is explicitly set to either be exported or not exported, that setting will be honored.
|
||||
-# If a variable is not explicitly set to be exported or not exported, but has been previously defined, the previous exporting rule for the variable is kept.
|
||||
-# If a variable is not explicitly set to be either global or local and has never before been defined, the variable will not be exported.
|
||||
-# If a variable is not explicitly set to be either exported or unexported and has never before been defined, the variable will not be exported.
|
||||
|
||||
In query mode, the scope to be examined can be specified.
|
||||
|
||||
|
||||
@@ -26,5 +26,11 @@ in a grey font color, while <code>set_color --bold white</code> will
|
||||
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.
|
||||
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.
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
\section source . - evaluate contents of file.
|
||||
|
||||
\subsection source-synopsis Synopsis
|
||||
<tt>. FILENAME</tt>
|
||||
<tt>. FILENAME [ARGUMENTS...]</tt>
|
||||
|
||||
\subsection source-description Description
|
||||
|
||||
@@ -9,7 +9,16 @@ Evaluates the commands of the specified file in the current
|
||||
shell. This is different from starting a new process to perform the
|
||||
commands (i.e. <tt>fish < FILENAME</tt>) since the commands will be
|
||||
evaluated by the current shell, which means that changes in
|
||||
environment variables, etc., will remain.
|
||||
environment variables, etc., will remain. If additional arguments are
|
||||
specified after the file name, they will be inserted into the $argv
|
||||
variable.
|
||||
|
||||
If no file is specified, or if the file name '-' is used, stdin will
|
||||
be read.
|
||||
|
||||
The return status of . is the return status of the last job to
|
||||
execute. If something goes wrong while opening or reading the file,
|
||||
. exits with a non-zero status.
|
||||
|
||||
\subsection source-example Example
|
||||
|
||||
|
||||
@@ -8,3 +8,11 @@
|
||||
- <tt>-b</tt> or <tt>--is-block</tt> returns 0 if fish is currently executing a block of code
|
||||
- <tt>-i</tt> or <tt>--is-interactive</tt> returns 0 if fish is interactive, i.e.connected to a keyboard
|
||||
- <tt>-l</tt> or <tt>--is-login</tt> returns 0 if fish is a login shell, i.e. if fish should perform login tasks such as setting up the PATH.
|
||||
- <tt>--is-full-job-control</tt> returns 0 if full job control is enabled
|
||||
- <tt>--is-interactive-job-control</tt> returns 0 if interactive job control is enabled
|
||||
- <tt>--is-no-job-control</tt> returns 0 if no job control is enabled
|
||||
- <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> 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
|
||||
|
||||
@@ -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 stamantes 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
|
||||
|
||||
@@ -11,7 +11,7 @@ omitted, the current value of the limit of the resource is printed.
|
||||
|
||||
Use one of the following switches to specify which resource limit to set or report:
|
||||
|
||||
- <code>-c</code> or <code>--core-size</code> The maximum size of core files created
|
||||
- <code>-c</code> or <code>--core-size</code> The maximum size of core files created. By setting this limit to zero, core dumps can be disabled.
|
||||
- <code>-d</code> or <code>--data-size</code> The maximum size of a process's data segment
|
||||
- <code>-f</code> or <code>--file-size</code> The maximum size of files created by the shell
|
||||
- <code>-l</code> or <code>--lock-size</code> The maximum size that may be locked into memory
|
||||
@@ -35,16 +35,17 @@ except for -t, which is in seconds and -n and -u, which are unscaled
|
||||
values. The return status is 0 unless an invalid option or argument is
|
||||
supplied, or an error occurs while setting a new limit.
|
||||
|
||||
ulimit also accepts the following switches that determine what type of limit to set:
|
||||
ulimit also accepts the following switches that determine what type of
|
||||
limit to set:
|
||||
|
||||
- <code>-H</code> or <code>--hard</code> Set hard resource limit
|
||||
- <code>-S</code> or <code>--soft</code> Set soft resource limit
|
||||
|
||||
A hard limit cannot be increased once it is set; a soft limit may be
|
||||
increased up to the value of the hard limit. If neither -H nor -S is
|
||||
specified, both the soft and hard limits are updated when assigning a
|
||||
new limit value, and the soft limit is used when reporting the current
|
||||
value.
|
||||
A hard limit can only be decreased, once it is set it can not be
|
||||
increased; a soft limit may be increased up to the value of the hard
|
||||
limit. If neither -H nor -S is specified, both the soft and hard
|
||||
limits are updated when assigning a new limit value, and the soft
|
||||
limit is used when reporting the current value.
|
||||
|
||||
The following additional options are also understood by ulimit:
|
||||
|
||||
@@ -55,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. 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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
\section umask umask - set or get the shells resource usage limits
|
||||
\section umask umask - set or get the file-creation mask
|
||||
|
||||
\subsection umask-synopsis Synopsis
|
||||
<code>umask [OPTIONS] [MASK]</code>
|
||||
@@ -43,7 +43,7 @@ in bash.
|
||||
|
||||
\subsection umask-example Example
|
||||
|
||||
<code>umask 177</code> or <code>umask u=rw</code>sets the file
|
||||
<code>umask 177</code> or <code>umask u=rw</code> sets the file
|
||||
creation mask to read and write for the owner and no permissions at
|
||||
all for any other users.
|
||||
|
||||
|
||||
48
env.c
48
env.c
@@ -52,6 +52,9 @@
|
||||
#include "env_universal.h"
|
||||
#include "input_common.h"
|
||||
#include "event.h"
|
||||
#include "path.h"
|
||||
#include "halloc.h"
|
||||
#include "halloc_util.h"
|
||||
|
||||
#include "complete.h"
|
||||
|
||||
@@ -416,11 +419,6 @@ static void setup_path()
|
||||
;
|
||||
|
||||
path = env_get( L"PATH" );
|
||||
if( !path )
|
||||
{
|
||||
env_set( L"PATH", 0, ENV_EXPORT | ENV_GLOBAL );
|
||||
path=0;
|
||||
}
|
||||
|
||||
al_init( &l );
|
||||
|
||||
@@ -463,10 +461,9 @@ static void setup_path()
|
||||
sb_append( &b, path );
|
||||
}
|
||||
|
||||
sb_append2( &b,
|
||||
ARRAY_SEP_STR,
|
||||
path_el[j],
|
||||
(void *)0 );
|
||||
sb_append( &b,
|
||||
ARRAY_SEP_STR,
|
||||
path_el[j] );
|
||||
|
||||
env_set( L"PATH", (wchar_t *)b.buff, ENV_GLOBAL | ENV_EXPORT );
|
||||
|
||||
@@ -483,6 +480,21 @@ static void setup_path()
|
||||
al_destroy( &l );
|
||||
}
|
||||
|
||||
int env_set_pwd()
|
||||
{
|
||||
wchar_t dir_path[4096];
|
||||
wchar_t *res = wgetcwd( dir_path, 4096 );
|
||||
if( !res )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
env_set( L"PWD", dir_path, ENV_EXPORT | ENV_GLOBAL );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
Set up default values for various variables if not defined.
|
||||
*/
|
||||
static void env_set_defaults()
|
||||
{
|
||||
|
||||
@@ -505,6 +517,8 @@ static void env_set_defaults()
|
||||
free( unam_narrow );
|
||||
}
|
||||
|
||||
env_set_pwd();
|
||||
|
||||
}
|
||||
|
||||
void env_init()
|
||||
@@ -710,6 +724,19 @@ int env_set( const wchar_t *key,
|
||||
|
||||
CHECK( key, ENV_INVALID );
|
||||
|
||||
if( val && contains( key, L"PWD", L"HOME" ) )
|
||||
{
|
||||
void *context = halloc( 0, 0 );
|
||||
const wchar_t *val_canonical = path_make_canonical( context, val );
|
||||
if( wcscmp( val_canonical, val ) )
|
||||
{
|
||||
int res = env_set( key, val_canonical, var_mode );
|
||||
halloc_free( context );
|
||||
return res;
|
||||
}
|
||||
halloc_free( context );
|
||||
}
|
||||
|
||||
if( (var_mode & ENV_USER ) &&
|
||||
hash_get( &env_read_only, key ) )
|
||||
{
|
||||
@@ -1432,6 +1459,9 @@ static void export_func1( void *k, void *v, void *aux )
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Get list of all exported variables
|
||||
*/
|
||||
static void get_exported( env_node_t *n, hash_table_t *h )
|
||||
{
|
||||
if( !n )
|
||||
|
||||
7
env.h
7
env.h
@@ -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
|
||||
|
||||
@@ -93,13 +93,13 @@
|
||||
typedef struct var_uni_entry
|
||||
{
|
||||
int export; /**< Whether the variable should be exported */
|
||||
wchar_t val[0]; /**< The value of the variable */
|
||||
wchar_t val[1]; /**< The value of the variable */
|
||||
}
|
||||
var_uni_entry_t;
|
||||
|
||||
|
||||
static void parse_message( wchar_t *msg,
|
||||
connection_t *src );
|
||||
connection_t *src );
|
||||
|
||||
/**
|
||||
The table of all universal variables
|
||||
@@ -113,7 +113,6 @@ void (*callback)( int type,
|
||||
const wchar_t *key,
|
||||
const wchar_t *val );
|
||||
|
||||
|
||||
/**
|
||||
Variable used by env_get_names to communicate auxiliary information
|
||||
to add_key_to_hash
|
||||
@@ -125,28 +124,100 @@ static int get_names_show_exported;
|
||||
*/
|
||||
static int get_names_show_unexported;
|
||||
|
||||
/**
|
||||
List of names for the UTF-8 character set.
|
||||
*/
|
||||
static char *iconv_utf8_names[]=
|
||||
{
|
||||
"utf-8", "UTF-8",
|
||||
"utf8", "UTF8",
|
||||
0
|
||||
}
|
||||
;
|
||||
|
||||
wchar_t *utf2wcs( const char *in )
|
||||
/**
|
||||
List of wide character names, undefined byte length.
|
||||
*/
|
||||
static char *iconv_wide_names_unknown[]=
|
||||
{
|
||||
"wchar_t", "WCHAR_T",
|
||||
"wchar", "WCHAR",
|
||||
0
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
List of wide character names, 4 bytes long.
|
||||
*/
|
||||
static char *iconv_wide_names_4[]=
|
||||
{
|
||||
"wchar_t", "WCHAR_T",
|
||||
"wchar", "WCHAR",
|
||||
"ucs-4", "UCS-4",
|
||||
"ucs4", "UCS4",
|
||||
"utf-32", "UTF-32",
|
||||
"utf32", "UTF32",
|
||||
0
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
List of wide character names, 2 bytes long.
|
||||
*/
|
||||
static char *iconv_wide_names_2[]=
|
||||
{
|
||||
"wchar_t", "WCHAR_T",
|
||||
"wchar", "WCHAR",
|
||||
"ucs-2", "UCS-2",
|
||||
"ucs2", "UCS2",
|
||||
"utf-16", "UTF-16",
|
||||
"utf16", "UTF16",
|
||||
0
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
Convert utf-8 string to wide string
|
||||
*/
|
||||
static wchar_t *utf2wcs( const char *in )
|
||||
{
|
||||
iconv_t cd=(iconv_t) -1;
|
||||
int i,j;
|
||||
|
||||
wchar_t *out;
|
||||
|
||||
char *to_name[]=
|
||||
{
|
||||
"wchar_t", "WCHAR_T", "wchar", "WCHAR", 0
|
||||
}
|
||||
;
|
||||
/*
|
||||
Try to convert to wchar_t. If that is not a valid character set,
|
||||
try various names for ucs-4. We can't be sure that ucs-4 is
|
||||
really the character set used by wchar_t, but it is the best
|
||||
assumption we can make.
|
||||
*/
|
||||
char **to_name=0;
|
||||
|
||||
char *from_name[]=
|
||||
switch (sizeof (wchar_t))
|
||||
{
|
||||
"utf-8", "UTF-8", "utf8", "UTF8", 0
|
||||
|
||||
case 2:
|
||||
to_name = iconv_wide_names_2;
|
||||
break;
|
||||
|
||||
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.
|
||||
*/
|
||||
char **from_name = iconv_utf8_names;
|
||||
|
||||
size_t in_len = strlen( in );
|
||||
size_t out_len = sizeof( wchar_t )*(in_len+1);
|
||||
size_t out_len = sizeof( wchar_t )*(in_len+2);
|
||||
size_t nconv;
|
||||
char *nout;
|
||||
|
||||
@@ -184,8 +255,7 @@ wchar_t *utf2wcs( const char *in )
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
nconv = iconv( cd, (char **)&in, &in_len, &nout, &out_len );
|
||||
nconv = iconv( cd, (const char **)&in, &in_len, &nout, &out_len );
|
||||
|
||||
if (nconv == (size_t) -1)
|
||||
{
|
||||
@@ -194,6 +264,24 @@ wchar_t *utf2wcs( const char *in )
|
||||
}
|
||||
|
||||
*((wchar_t *) nout) = L'\0';
|
||||
|
||||
/*
|
||||
Check for silly iconv behaviour inserting an bytemark in the output
|
||||
string.
|
||||
*/
|
||||
if (*out == L'\xfeff' || *out == L'\xffef' || *out == L'\xefbbbf')
|
||||
{
|
||||
wchar_t *out_old = out;
|
||||
out = wcsdup(out+1);
|
||||
if (! out )
|
||||
{
|
||||
debug(0, L"FNORD!!!!");
|
||||
free( out_old );
|
||||
return 0;
|
||||
}
|
||||
free( out_old );
|
||||
}
|
||||
|
||||
|
||||
if (iconv_close (cd) != 0)
|
||||
wperror (L"iconv_close");
|
||||
@@ -201,7 +289,10 @@ wchar_t *utf2wcs( const char *in )
|
||||
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;
|
||||
@@ -209,17 +300,31 @@ char *wcs2utf( const wchar_t *in )
|
||||
char *char_in = (char *)in;
|
||||
char *out;
|
||||
|
||||
char *from_name[]=
|
||||
{
|
||||
"wchar_t", "WCHAR_T", "wchar", "WCHAR", 0
|
||||
}
|
||||
;
|
||||
/*
|
||||
Try to convert to wchar_t. If that is not a valid character set,
|
||||
try various names for ucs-4. We can't be sure that ucs-4 is
|
||||
really the character set used by wchar_t, but it is the best
|
||||
assumption we can make.
|
||||
*/
|
||||
char **from_name=0;
|
||||
|
||||
char *to_name[]=
|
||||
switch (sizeof (wchar_t))
|
||||
{
|
||||
"utf-8", "UTF-8", "utf8", "UTF8", 0
|
||||
|
||||
case 2:
|
||||
from_name = iconv_wide_names_2;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
from_name = iconv_wide_names_4;
|
||||
break;
|
||||
|
||||
default:
|
||||
from_name = iconv_wide_names_unknown;
|
||||
break;
|
||||
}
|
||||
;
|
||||
|
||||
char **to_name = iconv_utf8_names;
|
||||
|
||||
size_t in_len = wcslen( in );
|
||||
size_t out_len = sizeof( char )*( (MAX_UTF8_BYTES*in_len)+1);
|
||||
@@ -304,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 )
|
||||
{
|
||||
|
||||
@@ -640,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;
|
||||
|
||||
@@ -112,7 +112,7 @@ typedef struct
|
||||
/**
|
||||
Message body. The message must be allocated using enough memory to actually contain the message.
|
||||
*/
|
||||
char body[0];
|
||||
char body[1];
|
||||
}
|
||||
message_t;
|
||||
|
||||
|
||||
@@ -3,12 +3,6 @@
|
||||
#
|
||||
# @configure_input@
|
||||
|
||||
#
|
||||
# Set default field separators
|
||||
#
|
||||
|
||||
set -g IFS \ \t\n
|
||||
|
||||
#
|
||||
# Some things should only be done for login terminals
|
||||
#
|
||||
@@ -63,4 +57,5 @@ if test -d include
|
||||
for i in include/*.fish
|
||||
. $i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
#
|
||||
# This file contains key bindings for fish
|
||||
#
|
||||
|
||||
# Include system-wide inputrc file before including fish-specific key
|
||||
# bindings if it exists
|
||||
|
||||
$include /etc/inputrc
|
||||
|
||||
$if fish
|
||||
"\M-l": __fish_list_current_token
|
||||
"\M-w": set tok (commandline -pt); if test $tok[1]; whatis $tok[1]; end
|
||||
"\C-l": clear
|
||||
"\C-c": delete-line
|
||||
"\C-u": backward-kill-line
|
||||
"\M-d": kill-word
|
||||
"\C-w": backward-kill-word
|
||||
"\M-k": dump-functions
|
||||
"\M-d": if test -z (commandline); dirh; else; commandline -f kill-word; end
|
||||
"\C-d": delete-or-exit
|
||||
# This will make sure the output of the current command is paged using the less pager when you press Meta-p
|
||||
"\M-p": if commandline -j|grep -v 'less *$' >/dev/null; commandline -aj "|less;"; end
|
||||
$endif
|
||||
|
||||
# Include user-specific inputrc file after including fish-specific
|
||||
# bindings so that they will override fish defaults
|
||||
|
||||
$include ~/.inputrc
|
||||
70
event.c
70
event.c
@@ -78,11 +78,6 @@ static array_list_t *killme;
|
||||
*/
|
||||
static array_list_t *blocked;
|
||||
|
||||
/**
|
||||
String buffer used for formating event descriptions in event_get_desc()
|
||||
*/
|
||||
static string_buffer_t *get_desc_buff=0;
|
||||
|
||||
/**
|
||||
Tests if one event instance matches the definition of a event
|
||||
class. If both the class and the instance name a function,
|
||||
@@ -91,6 +86,7 @@ static string_buffer_t *get_desc_buff=0;
|
||||
*/
|
||||
static int event_match( event_t *class, event_t *instance )
|
||||
{
|
||||
|
||||
if( class->function_name && instance->function_name )
|
||||
{
|
||||
if( wcscmp( class->function_name, instance->function_name ) != 0 )
|
||||
@@ -103,15 +99,15 @@ static int event_match( event_t *class, event_t *instance )
|
||||
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;
|
||||
@@ -123,6 +119,11 @@ static int event_match( event_t *class, event_t *instance )
|
||||
|
||||
case EVENT_JOB_ID:
|
||||
return class->param1.job_id == instance->param1.job_id;
|
||||
|
||||
case EVENT_GENERIC:
|
||||
return wcscmp( instance->param1.param,
|
||||
class->param1.param )==0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,8 +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 )
|
||||
@@ -148,6 +151,8 @@ static event_t *event_copy( event_t *event, int copy_arguments )
|
||||
|
||||
if( e->type == EVENT_VARIABLE )
|
||||
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 )
|
||||
@@ -197,6 +202,11 @@ static int event_is_blocked( event_t *e )
|
||||
const wchar_t *event_get_desc( event_t *e )
|
||||
{
|
||||
|
||||
/*
|
||||
String buffer used for formating event descriptions in event_get_desc()
|
||||
*/
|
||||
static string_buffer_t *get_desc_buff=0;
|
||||
|
||||
CHECK( e, 0 );
|
||||
|
||||
if( !get_desc_buff )
|
||||
@@ -246,6 +256,14 @@ 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;
|
||||
@@ -614,7 +632,9 @@ void event_fire( event_t *event )
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/*
|
||||
Fire events triggered by signals
|
||||
*/
|
||||
event_fire_delayed();
|
||||
|
||||
if( event )
|
||||
@@ -673,7 +693,39 @@ void event_free( event_t *e )
|
||||
|
||||
free( (void *)e->function_name );
|
||||
if( e->type == EVENT_VARIABLE )
|
||||
{
|
||||
free( (void *)e->param1.variable );
|
||||
}
|
||||
else if( e->type == EVENT_GENERIC )
|
||||
{
|
||||
free( (void *)e->param1.param );
|
||||
}
|
||||
free( e );
|
||||
}
|
||||
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
38
event.h
38
event.h
@@ -2,6 +2,12 @@
|
||||
|
||||
Functions for handling event triggers
|
||||
|
||||
Because most of these functions can be called by signal
|
||||
handler, it is important to make it well defined when these
|
||||
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
|
||||
@@ -27,6 +33,7 @@ enum
|
||||
EVENT_VARIABLE, /**< An event triggered by a variable update */
|
||||
EVENT_EXIT, /**< An event triggered by a job or process exit */
|
||||
EVENT_JOB_ID, /**< An event triggered by a job exit */
|
||||
EVENT_GENERIC, /**< A generic event */
|
||||
}
|
||||
;
|
||||
|
||||
@@ -67,7 +74,11 @@ typedef struct
|
||||
Job id for EVENT_JOB_ID type events
|
||||
*/
|
||||
int job_id;
|
||||
|
||||
/**
|
||||
The parameter describing this generic event
|
||||
*/
|
||||
const wchar_t *param;
|
||||
|
||||
} param1;
|
||||
|
||||
/**
|
||||
@@ -86,17 +97,24 @@ typedef struct
|
||||
|
||||
/**
|
||||
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.
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
@@ -111,7 +129,14 @@ int event_get( event_t *criterion, array_list_t *out );
|
||||
called. If event is a null-pointer, all pending events are
|
||||
dispatched.
|
||||
|
||||
\param event the specific event whose handlers should fire
|
||||
This function is safe to call from a signal handler _ONLY_ if the
|
||||
event parameter is for a signal. Signal events not be fired, by the
|
||||
call to event_fire, instead they will be fired the next time
|
||||
event_fire is called with anull argument. This is needed to make
|
||||
sure that no code evaluation is ever performed by a signal handler.
|
||||
|
||||
\param event the specific event whose handlers should fire. If
|
||||
null, then all delayed events will be fired.
|
||||
*/
|
||||
void event_fire( event_t *event );
|
||||
|
||||
@@ -126,7 +151,7 @@ void event_init();
|
||||
void event_destroy();
|
||||
|
||||
/**
|
||||
Free all memory used by event
|
||||
Free all memory used by the specified event
|
||||
*/
|
||||
void event_free( event_t *e );
|
||||
|
||||
@@ -136,4 +161,11 @@ void event_free( event_t *e );
|
||||
*/
|
||||
const wchar_t *event_get_desc( event_t *e );
|
||||
|
||||
/**
|
||||
Fire a generic event with the specified name
|
||||
*/
|
||||
#define event_fire_generic( ... ) event_fire_generic_internal( __VA_ARGS__, (void *)0 )
|
||||
|
||||
void event_fire_generic_internal(const wchar_t *name,...);
|
||||
|
||||
#endif
|
||||
|
||||
454
exec.c
454
exec.c
@@ -52,10 +52,22 @@
|
||||
file descriptor redirection error message
|
||||
*/
|
||||
#define FD_ERROR _( L"An error occurred while redirecting file descriptor %d" )
|
||||
|
||||
/**
|
||||
file descriptor redirection error message
|
||||
*/
|
||||
#define WRITE_ERROR _( L"An error occurred while writing output" )
|
||||
|
||||
/**
|
||||
file redirection error message
|
||||
*/
|
||||
#define FILE_ERROR _( L"An error occurred while redirecting file '%ls'" )
|
||||
|
||||
/**
|
||||
file redirection clobbering error message
|
||||
*/
|
||||
#define NOCLOB_ERROR _( L"The file '%ls' already exists" )
|
||||
|
||||
/**
|
||||
fork error message
|
||||
*/
|
||||
@@ -85,6 +97,18 @@ static array_list_t *open_fds=0;
|
||||
|
||||
static int set_child_group( job_t *j, process_t *p, int print_errors );
|
||||
|
||||
static void exec_write_and_exit( int fd, char *buff, size_t count, int status )
|
||||
{
|
||||
if( write_loop(fd, buff, count) == -1 )
|
||||
{
|
||||
debug( 0, WRITE_ERROR);
|
||||
wperror( L"write" );
|
||||
exit(status);
|
||||
}
|
||||
exit( status );
|
||||
}
|
||||
|
||||
|
||||
void exec_close( int fd )
|
||||
{
|
||||
int i;
|
||||
@@ -113,10 +137,10 @@ void exec_close( int fd )
|
||||
if( n == fd )
|
||||
{
|
||||
al_set_long( open_fds,
|
||||
i,
|
||||
al_get_long( open_fds, al_get_count( open_fds ) -1 ) );
|
||||
i,
|
||||
al_get_long( open_fds, al_get_count( open_fds ) -1 ) );
|
||||
al_truncate( open_fds,
|
||||
al_get_count( open_fds ) -1 );
|
||||
al_get_count( open_fds ) -1 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -288,13 +312,24 @@ static int handle_child_io( io_data_t *io )
|
||||
case IO_FILE:
|
||||
{
|
||||
if( (tmp=wopen( io->param1.filename,
|
||||
io->param2.flags, OPEN_MASK ) )==-1 )
|
||||
io->param2.flags, OPEN_MASK ) )==-1 )
|
||||
{
|
||||
debug( 1,
|
||||
FILE_ERROR,
|
||||
io->param1.filename );
|
||||
if( ( io->param2.flags & O_EXCL ) &&
|
||||
( errno ==EEXIST ) )
|
||||
{
|
||||
debug( 1,
|
||||
NOCLOB_ERROR,
|
||||
io->param1.filename );
|
||||
}
|
||||
else
|
||||
{
|
||||
debug( 1,
|
||||
FILE_ERROR,
|
||||
io->param1.filename );
|
||||
|
||||
wperror( L"open" );
|
||||
}
|
||||
|
||||
wperror( L"open" );
|
||||
return -1;
|
||||
}
|
||||
else if( tmp != io->fd)
|
||||
@@ -424,7 +459,41 @@ static int setup_child_process( job_t *j, process_t *p )
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Returns the interpreter for the specified script. Returns 0 if file
|
||||
is not a script with a shebang. This function leaks memory on every
|
||||
call. Only use it in the execve error handler which calls exit
|
||||
right afterwards, anyway.
|
||||
*/
|
||||
static wchar_t *get_interpreter( wchar_t *file )
|
||||
{
|
||||
string_buffer_t sb;
|
||||
FILE *fp = wfopen( file, "r" );
|
||||
sb_init( &sb );
|
||||
wchar_t *res = 0;
|
||||
if( fp )
|
||||
{
|
||||
while( 1 )
|
||||
{
|
||||
wint_t ch = getwc( fp );
|
||||
if( ch == WEOF )
|
||||
break;
|
||||
if( ch == L'\n' )
|
||||
break;
|
||||
sb_append_char( &sb, (wchar_t)ch );
|
||||
}
|
||||
}
|
||||
|
||||
res = (wchar_t *)sb.buff;
|
||||
|
||||
if( !wcsncmp( L"#! /", res, 4 ) )
|
||||
return res+3;
|
||||
if( !wcsncmp( L"#!/", res, 3 ) )
|
||||
return res+2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
This function is executed by the child process created by a call to
|
||||
@@ -439,62 +508,161 @@ static void launch_process( process_t *p )
|
||||
|
||||
// debug( 1, L"exec '%ls'", p->argv[0] );
|
||||
|
||||
char **argv = wcsv2strv( (const wchar_t **) p->argv);
|
||||
char **envv = env_export_arr( 0 );
|
||||
|
||||
execve ( wcs2str(p->actual_cmd),
|
||||
wcsv2strv( (const wchar_t **) p->argv),
|
||||
env_export_arr( 0 ) );
|
||||
|
||||
err = errno;
|
||||
argv,
|
||||
envv );
|
||||
|
||||
err = errno;
|
||||
|
||||
/*
|
||||
Something went wrong with execve, check for a ":", and run
|
||||
/bin/sh if encountered. This is a weird predecessor to the shebang
|
||||
that is still sometimes used since it is supported on Windows.
|
||||
Something went wrong with execve, check for a ":", and run
|
||||
/bin/sh if encountered. This is a weird predecessor to the shebang
|
||||
that is still sometimes used since it is supported on Windows.
|
||||
*/
|
||||
f = wfopen(p->actual_cmd, "r");
|
||||
if( f )
|
||||
{
|
||||
char begin[1] = {0};
|
||||
if( f )
|
||||
{
|
||||
char begin[1] = {0};
|
||||
size_t read;
|
||||
|
||||
|
||||
read = fread(begin, 1, 1, f);
|
||||
fclose( f );
|
||||
|
||||
if( (read==1) && (begin[0] == ':') )
|
||||
{
|
||||
int count = 0;
|
||||
int i = 1;
|
||||
if( (read==1) && (begin[0] == ':') )
|
||||
{
|
||||
int count = 0;
|
||||
int i = 1;
|
||||
wchar_t **res;
|
||||
|
||||
while( p->argv[count] != 0 )
|
||||
char **res_real;
|
||||
|
||||
while( p->argv[count] != 0 )
|
||||
count++;
|
||||
|
||||
|
||||
res = malloc( sizeof(wchar_t*)*(count+2));
|
||||
|
||||
|
||||
res[0] = L"/bin/sh";
|
||||
res[1] = p->actual_cmd;
|
||||
|
||||
res[1] = p->actual_cmd;
|
||||
|
||||
for( i=1; p->argv[i]; i++ ){
|
||||
res[i+1] = p->argv[i];
|
||||
}
|
||||
res[i+1] = p->argv[i];
|
||||
}
|
||||
|
||||
res[i+1] = 0;
|
||||
p->argv = res;
|
||||
p->actual_cmd = L"/bin/sh";
|
||||
|
||||
res[i+1] = 0;
|
||||
p->argv = res;
|
||||
p->actual_cmd = L"/bin/sh";
|
||||
res_real = wcsv2strv( (const wchar_t **) res);
|
||||
|
||||
execve ( wcs2str(p->actual_cmd),
|
||||
wcsv2strv( (const wchar_t **) p->argv),
|
||||
env_export_arr( 0 ) );
|
||||
}
|
||||
}
|
||||
|
||||
debug( 0,
|
||||
_( L"Failed to execute process '%ls'" ),
|
||||
p->actual_cmd );
|
||||
|
||||
errno = err;
|
||||
res_real,
|
||||
envv );
|
||||
}
|
||||
}
|
||||
|
||||
errno = err;
|
||||
debug( 0,
|
||||
_( L"Failed to execute process '%ls'. Reason:" ),
|
||||
p->actual_cmd );
|
||||
|
||||
switch( errno )
|
||||
{
|
||||
|
||||
case E2BIG:
|
||||
{
|
||||
size_t sz = 0;
|
||||
char **p;
|
||||
|
||||
string_buffer_t sz1;
|
||||
string_buffer_t sz2;
|
||||
|
||||
long arg_max = -1;
|
||||
|
||||
sb_init( &sz1 );
|
||||
sb_init( &sz2 );
|
||||
|
||||
for(p=argv; *p; p++)
|
||||
{
|
||||
sz += strlen(*p)+1;
|
||||
}
|
||||
|
||||
for(p=envv; *p; p++)
|
||||
{
|
||||
sz += strlen(*p)+1;
|
||||
}
|
||||
|
||||
sb_format_size( &sz1, sz );
|
||||
|
||||
arg_max = sysconf( _SC_ARG_MAX );
|
||||
|
||||
if( arg_max > 0 )
|
||||
{
|
||||
|
||||
sb_format_size( &sz2, arg_max );
|
||||
|
||||
debug( 0,
|
||||
L"The total size of the argument and environment lists (%ls) exceeds the operating system limit of %ls.",
|
||||
(wchar_t *)sz1.buff,
|
||||
(wchar_t *)sz2.buff);
|
||||
}
|
||||
else
|
||||
{
|
||||
debug( 0,
|
||||
L"The total size of the argument and environment lists (%ls) exceeds the operating system limit.",
|
||||
(wchar_t *)sz1.buff);
|
||||
}
|
||||
|
||||
debug( 0,
|
||||
L"Try running the command again with fewer arguments.");
|
||||
sb_destroy( &sz1 );
|
||||
sb_destroy( &sz2 );
|
||||
|
||||
exit(STATUS_EXEC_FAIL);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ENOEXEC:
|
||||
{
|
||||
wperror(L"exec");
|
||||
|
||||
debug(0, L"The file '%ls' is marked as an executable but could not be run by the operating system.", p->actual_cmd);
|
||||
exit(STATUS_EXEC_FAIL);
|
||||
}
|
||||
|
||||
case ENOENT:
|
||||
{
|
||||
wchar_t *interpreter = get_interpreter( p->actual_cmd );
|
||||
|
||||
if( interpreter && waccess( interpreter, X_OK ) )
|
||||
{
|
||||
debug(0, L"The file '%ls' specified the interpreter '%ls', which is not an executable command.", p->actual_cmd, interpreter );
|
||||
}
|
||||
else
|
||||
{
|
||||
debug(0, L"The file '%ls' or a script or ELF interpreter does not exist, or a shared library needed for file or interpreter cannot be found.", p->actual_cmd);
|
||||
}
|
||||
|
||||
exit(STATUS_EXEC_FAIL);
|
||||
}
|
||||
|
||||
case ENOMEM:
|
||||
{
|
||||
debug(0, L"Out of memory");
|
||||
exit(STATUS_EXEC_FAIL);
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
wperror(L"exec");
|
||||
|
||||
// debug(0, L"The file '%ls' is marked as an executable but could not be run by the operating system.", p->actual_cmd);
|
||||
exit(STATUS_EXEC_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
wperror( L"execve" );
|
||||
FATAL_EXIT();
|
||||
}
|
||||
|
||||
|
||||
@@ -668,13 +836,14 @@ static int set_child_group( job_t *j, process_t *p, int print_errors )
|
||||
if( getpgid( p->pid) != j->pgid && print_errors )
|
||||
{
|
||||
debug( 1,
|
||||
_( L"Could not send process %d, '%ls' in job %d, '%ls' from group %d to group %d" ),
|
||||
p->pid,
|
||||
p->argv[0],
|
||||
j->job_id,
|
||||
j->command,
|
||||
getpgid( p->pid),
|
||||
j->pgid );
|
||||
_( L"Could not send process %d, '%ls' in job %d, '%ls' from group %d to group %d" ),
|
||||
p->pid,
|
||||
p->argv[0],
|
||||
j->job_id,
|
||||
j->command,
|
||||
getpgid( p->pid),
|
||||
j->pgid );
|
||||
|
||||
wperror( L"setpgid" );
|
||||
res = -1;
|
||||
}
|
||||
@@ -744,6 +913,9 @@ static pid_t exec_fork()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Perform output from builtins
|
||||
*/
|
||||
static void do_builtin_io( wchar_t *out, wchar_t *err )
|
||||
{
|
||||
|
||||
@@ -884,25 +1056,34 @@ void exec( job_t *j )
|
||||
signal_block();
|
||||
|
||||
/*
|
||||
See if we need to create a group keepalive process. This is a
|
||||
process that we create to make sure that the process group
|
||||
doesn't die accidentally, and is needed when a block/function is
|
||||
inside a pipeline.
|
||||
See if we need to create a group keepalive process. This is
|
||||
a process that we create to make sure that the process group
|
||||
doesn't die accidentally, and is often needed when a
|
||||
builtin/block/function is inside a pipeline, since that
|
||||
usually means we have to wait for one program to exit before
|
||||
continuing in the pipeline, causing the group leader to
|
||||
exit.
|
||||
*/
|
||||
|
||||
if( job_get_flag( j, JOB_CONTROL ) )
|
||||
{
|
||||
for( p=j->first_process; p; p = p->next )
|
||||
{
|
||||
if( (p->type == INTERNAL_BLOCK ) ||
|
||||
(p->type == INTERNAL_FUNCTION ) )
|
||||
if( p->type != EXTERNAL )
|
||||
{
|
||||
if( p->next )
|
||||
{
|
||||
needs_keepalive = 1;
|
||||
break;
|
||||
}
|
||||
if( p != j->first_process )
|
||||
{
|
||||
needs_keepalive = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -993,6 +1174,9 @@ void exec( job_t *j )
|
||||
{
|
||||
const wchar_t * orig_def;
|
||||
wchar_t * def=0;
|
||||
array_list_t *named_arguments;
|
||||
int shadows;
|
||||
|
||||
|
||||
/*
|
||||
Calls to function_get_definition might need to
|
||||
@@ -1002,6 +1186,9 @@ void exec( job_t *j )
|
||||
|
||||
signal_unblock();
|
||||
orig_def = function_get_definition( p->argv[0] );
|
||||
named_arguments = function_get_named_arguments( p->argv[0] );
|
||||
shadows = function_get_shadows( p->argv[0] );
|
||||
|
||||
signal_block();
|
||||
|
||||
if( orig_def )
|
||||
@@ -1014,12 +1201,20 @@ void exec( job_t *j )
|
||||
break;
|
||||
}
|
||||
|
||||
parser_push_block( FUNCTION_CALL );
|
||||
parser_push_block( shadows?FUNCTION_CALL:FUNCTION_CALL_NO_SHADOW );
|
||||
|
||||
current_block->param2.function_call_process = p;
|
||||
current_block->param1.function_call_name = halloc_register( current_block, wcsdup( p->argv[0] ) );
|
||||
|
||||
parse_util_set_argv( p->argv+1 );
|
||||
|
||||
/*
|
||||
set_argv might trigger an event
|
||||
handler, hence we need to unblock
|
||||
signals.
|
||||
*/
|
||||
signal_unblock();
|
||||
parse_util_set_argv( p->argv+1, named_arguments );
|
||||
signal_block();
|
||||
|
||||
parser_forbid_function( p->argv[0] );
|
||||
|
||||
@@ -1099,7 +1294,33 @@ void exec( job_t *j )
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case IO_CLOSE:
|
||||
{
|
||||
/*
|
||||
FIXME:
|
||||
|
||||
When
|
||||
requesting
|
||||
that
|
||||
stdin
|
||||
be
|
||||
closed,
|
||||
we
|
||||
really
|
||||
don't
|
||||
do
|
||||
anything. How
|
||||
should
|
||||
this
|
||||
be
|
||||
handled?
|
||||
*/
|
||||
builtin_stdin = -1;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
builtin_stdin=-1;
|
||||
@@ -1152,7 +1373,7 @@ void exec( job_t *j )
|
||||
|
||||
signal_unblock();
|
||||
|
||||
p->status = builtin_run( p->argv );
|
||||
p->status = builtin_run( p->argv, j->io );
|
||||
|
||||
builtin_out_redirect=old_out;
|
||||
builtin_err_redirect=old_err;
|
||||
@@ -1222,15 +1443,17 @@ void exec( job_t *j )
|
||||
|
||||
if( pid == 0 )
|
||||
{
|
||||
|
||||
/*
|
||||
This is the child process. Write out the contents of the pipeline.
|
||||
*/
|
||||
p->pid = getpid();
|
||||
setup_child_process( j, p );
|
||||
write( io_buffer->fd,
|
||||
io_buffer->param2.out_buffer->buff,
|
||||
io_buffer->param2.out_buffer->used );
|
||||
exit( status );
|
||||
|
||||
exec_write_and_exit(io_buffer->fd,
|
||||
io_buffer->param2.out_buffer->buff,
|
||||
io_buffer->param2.out_buffer->used,
|
||||
status);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1276,10 +1499,10 @@ void exec( job_t *j )
|
||||
p->pid = getpid();
|
||||
setup_child_process( j, p );
|
||||
|
||||
write( 1,
|
||||
input_redirect->param2.out_buffer->buff,
|
||||
input_redirect->param2.out_buffer->used );
|
||||
exit( 0 );
|
||||
exec_write_and_exit( 1,
|
||||
input_redirect->param2.out_buffer->buff,
|
||||
input_redirect->param2.out_buffer->used,
|
||||
0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1297,7 +1520,7 @@ void exec( job_t *j )
|
||||
|
||||
case INTERNAL_BUILTIN:
|
||||
{
|
||||
int skip_fork=0;
|
||||
int skip_fork;
|
||||
|
||||
/*
|
||||
Handle output from builtin commands. In the general
|
||||
@@ -1316,14 +1539,14 @@ void exec( job_t *j )
|
||||
( !sb_out->used ) &&
|
||||
( !sb_err->used ) &&
|
||||
( !p->next );
|
||||
|
||||
|
||||
/*
|
||||
If the output of a builtin is to be sent to an internal
|
||||
buffer, there is no need to fork. This helps out the
|
||||
performance quite a bit in complex completion code.
|
||||
*/
|
||||
|
||||
io_data_t *io = io_get( j->io, 1 );
|
||||
io_data_t *io = io_get( j->io, 1 );
|
||||
int buffer_stdout = io && io->io_mode == IO_BUFFER;
|
||||
|
||||
if( ( !sb_err->used ) &&
|
||||
@@ -1331,12 +1554,20 @@ void exec( job_t *j )
|
||||
( sb_out->used ) &&
|
||||
( buffer_stdout ) )
|
||||
{
|
||||
char *res = wcs2str( (wchar_t *)sb_out->buff );
|
||||
char *res = wcs2str( (wchar_t *)sb_out->buff );
|
||||
b_append( io->param2.out_buffer, res, strlen( res ) );
|
||||
skip_fork = 1;
|
||||
free( res );
|
||||
free( res );
|
||||
}
|
||||
|
||||
for( io = j->io; io; io=io->next )
|
||||
{
|
||||
if( io->io_mode == IO_FILE && wcscmp(io->param1.filename, L"/dev/null" ))
|
||||
{
|
||||
skip_fork = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if( skip_fork )
|
||||
{
|
||||
p->completed=1;
|
||||
@@ -1344,7 +1575,8 @@ void exec( job_t *j )
|
||||
{
|
||||
debug( 3, L"Set status of %ls to %d using short circut", j->command, p->status );
|
||||
|
||||
proc_set_last_status( job_get_flag( j, JOB_NEGATE )?(!p->status):p->status );
|
||||
int status = proc_format_status(p->status);
|
||||
proc_set_last_status( job_get_flag( j, JOB_NEGATE )?(!status):status );
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1487,9 +1719,27 @@ int exec_subshell( const wchar_t *cmd,
|
||||
int prev_subshell = is_subshell;
|
||||
int status, prev_status;
|
||||
io_data_t *io_buffer;
|
||||
|
||||
const wchar_t *ifs;
|
||||
char sep=0;
|
||||
|
||||
CHECK( cmd, -1 );
|
||||
|
||||
ifs = env_get(L"IFS");
|
||||
|
||||
if( ifs && ifs[0] )
|
||||
{
|
||||
if( ifs[0] < 128 )
|
||||
{
|
||||
sep = '\n';//ifs[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
sep = 0;
|
||||
debug( 0, L"Warning - invalid command substitution separator '%lc'. Please change the firsta character of IFS", ifs[0] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
is_subshell=1;
|
||||
io_buffer= io_buffer_create( 0 );
|
||||
|
||||
@@ -1505,7 +1755,7 @@ int exec_subshell( const wchar_t *cmd,
|
||||
}
|
||||
|
||||
io_buffer_read( io_buffer );
|
||||
|
||||
|
||||
proc_set_last_status( prev_status );
|
||||
|
||||
is_subshell = prev_subshell;
|
||||
@@ -1518,31 +1768,11 @@ int exec_subshell( const wchar_t *cmd,
|
||||
{
|
||||
while( 1 )
|
||||
{
|
||||
switch( *end )
|
||||
if( *end == 0 )
|
||||
{
|
||||
case 0:
|
||||
|
||||
if( begin != end )
|
||||
{
|
||||
wchar_t *el = str2wcs( begin );
|
||||
if( el )
|
||||
{
|
||||
al_push( lst, el );
|
||||
}
|
||||
else
|
||||
{
|
||||
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
|
||||
}
|
||||
}
|
||||
io_buffer_destroy( io_buffer );
|
||||
|
||||
return status;
|
||||
|
||||
case '\n':
|
||||
if( begin != end )
|
||||
{
|
||||
wchar_t *el;
|
||||
*end=0;
|
||||
el = str2wcs( begin );
|
||||
wchar_t *el = str2wcs( begin );
|
||||
if( el )
|
||||
{
|
||||
al_push( lst, el );
|
||||
@@ -1551,9 +1781,25 @@ int exec_subshell( const wchar_t *cmd,
|
||||
{
|
||||
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
|
||||
}
|
||||
begin = end+1;
|
||||
break;
|
||||
}
|
||||
io_buffer_destroy( io_buffer );
|
||||
|
||||
return status;
|
||||
}
|
||||
else if( *end == sep )
|
||||
{
|
||||
wchar_t *el;
|
||||
*end=0;
|
||||
el = str2wcs( begin );
|
||||
if( el )
|
||||
{
|
||||
al_push( lst, el );
|
||||
}
|
||||
else
|
||||
{
|
||||
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
|
||||
}
|
||||
begin = end+1;
|
||||
}
|
||||
end++;
|
||||
}
|
||||
|
||||
185
expand.c
185
expand.c
@@ -85,7 +85,7 @@ parameter expansion.
|
||||
/**
|
||||
Description for short job. The job command is concatenated
|
||||
*/
|
||||
#define COMPLETE_JOB_DESC_VAL _( L"Job: ")
|
||||
#define COMPLETE_JOB_DESC_VAL _( L"Job: %ls")
|
||||
|
||||
/**
|
||||
Description for the shells own pid
|
||||
@@ -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"$*?\\\"'({})"
|
||||
|
||||
@@ -168,7 +168,7 @@ static int is_quotable( wchar_t *str )
|
||||
case L'\t':
|
||||
case L'\r':
|
||||
case L'\b':
|
||||
case L'\e':
|
||||
case L'\x1b':
|
||||
return 0;
|
||||
|
||||
default:
|
||||
@@ -202,7 +202,7 @@ wchar_t *expand_escape_variable( const wchar_t *in )
|
||||
|
||||
if( wcschr( el, L' ' ) && is_quotable( el ) )
|
||||
{
|
||||
sb_append2( &buff,
|
||||
sb_append( &buff,
|
||||
L"'",
|
||||
el,
|
||||
L"'",
|
||||
@@ -228,7 +228,7 @@ wchar_t *expand_escape_variable( const wchar_t *in )
|
||||
|
||||
if( is_quotable( el ) )
|
||||
{
|
||||
sb_append2( &buff,
|
||||
sb_append( &buff,
|
||||
L"'",
|
||||
el,
|
||||
L"'",
|
||||
@@ -329,14 +329,14 @@ static int match_pid( const wchar_t *cmd,
|
||||
Searches for a job with the specified job id, or a job or process
|
||||
which has the string \c proc as a prefix of its commandline.
|
||||
|
||||
If accept_incomplete is true, the remaining string for any matches
|
||||
If the ACCEPT_INCOMPLETE flag is set, the remaining string for any matches
|
||||
are inserted.
|
||||
|
||||
If accept_incomplete is false, any job matching the specified
|
||||
string is matched, and the job pgid is returned. If no job
|
||||
matches, all child processes are searched. If no child processes
|
||||
match, and <tt>fish</tt> can understand the contents of the /proc
|
||||
filesystem, all the users processes are searched for matches.
|
||||
Otherwise, any job matching the specified string is matched, and
|
||||
the job pgid is returned. If no job matches, all child processes
|
||||
are searched. If no child processes match, and <tt>fish</tt> can
|
||||
understand the contents of the /proc filesystem, all the users
|
||||
processes are searched for matches.
|
||||
*/
|
||||
|
||||
static int find_process( const wchar_t *proc,
|
||||
@@ -372,14 +372,20 @@ static int find_process( const wchar_t *proc,
|
||||
|
||||
if( wcsncmp( proc, jid, wcslen(proc ) )==0 )
|
||||
{
|
||||
al_push( out,
|
||||
wcsdupcat2( jid+wcslen(proc),
|
||||
COMPLETE_SEP_STR,
|
||||
COMPLETE_JOB_DESC_VAL,
|
||||
j->command,
|
||||
(void *)0 ) );
|
||||
|
||||
string_buffer_t desc_buff;
|
||||
|
||||
sb_init( &desc_buff );
|
||||
|
||||
sb_printf( &desc_buff,
|
||||
COMPLETE_JOB_DESC_VAL,
|
||||
j->command );
|
||||
|
||||
completion_allocate( out,
|
||||
jid+wcslen(proc),
|
||||
(wchar_t *)desc_buff.buff,
|
||||
0 );
|
||||
|
||||
sb_destroy( &desc_buff );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,11 +428,10 @@ static int find_process( const wchar_t *proc,
|
||||
{
|
||||
if( flags & ACCEPT_INCOMPLETE )
|
||||
{
|
||||
wchar_t *res = wcsdupcat2( j->command + offset + wcslen(proc),
|
||||
COMPLETE_SEP_STR,
|
||||
COMPLETE_JOB_DESC,
|
||||
(void *)0 );
|
||||
al_push( out, res );
|
||||
completion_allocate( out,
|
||||
j->command + offset + wcslen(proc),
|
||||
COMPLETE_JOB_DESC,
|
||||
0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -459,11 +464,10 @@ static int find_process( const wchar_t *proc,
|
||||
{
|
||||
if( flags & ACCEPT_INCOMPLETE )
|
||||
{
|
||||
wchar_t *res = wcsdupcat2( p->actual_cmd + offset + wcslen(proc),
|
||||
COMPLETE_SEP_STR,
|
||||
COMPLETE_CHILD_PROCESS_DESC,
|
||||
(void *)0);
|
||||
al_push( out, res );
|
||||
completion_allocate( out,
|
||||
p->actual_cmd + offset + wcslen(proc),
|
||||
COMPLETE_CHILD_PROCESS_DESC,
|
||||
0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -575,13 +579,10 @@ static int find_process( const wchar_t *proc,
|
||||
{
|
||||
if( flags & ACCEPT_INCOMPLETE )
|
||||
{
|
||||
wchar_t *res = wcsdupcat2( cmd + offset + wcslen(proc),
|
||||
COMPLETE_SEP_STR,
|
||||
COMPLETE_PROCESS_DESC,
|
||||
(void *)0);
|
||||
if( res )
|
||||
al_push( out, res );
|
||||
|
||||
completion_allocate( out,
|
||||
cmd + offset + wcslen(proc),
|
||||
COMPLETE_PROCESS_DESC,
|
||||
0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -625,13 +626,17 @@ static int expand_pid( wchar_t *in,
|
||||
{
|
||||
if( wcsncmp( in+1, SELF_STR, wcslen(in+1) )==0 )
|
||||
{
|
||||
wchar_t *res = wcsdupcat2( SELF_STR+wcslen(in+1), COMPLETE_SEP_STR, COMPLETE_SELF_DESC, (void *)0 );
|
||||
al_push( out, res );
|
||||
completion_allocate( out,
|
||||
SELF_STR+wcslen(in+1),
|
||||
COMPLETE_SELF_DESC,
|
||||
0 );
|
||||
}
|
||||
else if( wcsncmp( in+1, LAST_STR, wcslen(in+1) )==0 )
|
||||
{
|
||||
wchar_t *res = wcsdupcat2( LAST_STR+wcslen(in+1), COMPLETE_SEP_STR, COMPLETE_LAST_DESC, (void *)0 );
|
||||
al_push( out, res );
|
||||
completion_allocate( out,
|
||||
LAST_STR+wcslen(in+1),
|
||||
COMPLETE_LAST_DESC,
|
||||
0 );
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -759,7 +764,9 @@ 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 )
|
||||
{
|
||||
|
||||
@@ -1512,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++;
|
||||
}
|
||||
@@ -1519,6 +1531,7 @@ static void remove_internal_separator( const void *s, int conv )
|
||||
*out=0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
The real expansion function. expand_one is just a wrapper around this one.
|
||||
*/
|
||||
@@ -1679,7 +1692,9 @@ int expand_string( void *context,
|
||||
return EXPAND_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
al_push( out, next );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1712,57 +1727,75 @@ int expand_string( void *context,
|
||||
if( ((flags & ACCEPT_INCOMPLETE) && (!(flags & EXPAND_SKIP_WILDCARDS))) ||
|
||||
wildcard_has( next, 1 ) )
|
||||
{
|
||||
wchar_t *start, *rest;
|
||||
array_list_t *list = out;
|
||||
|
||||
if( next[0] == '/' )
|
||||
{
|
||||
wc_res = wildcard_expand( &next[1], L"/",flags, out );
|
||||
start = L"/";
|
||||
rest = &next[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
wc_res = wildcard_expand( next, L"", flags, out );
|
||||
start = L"";
|
||||
rest = next;
|
||||
}
|
||||
free( next );
|
||||
switch( wc_res )
|
||||
|
||||
if( flags & ACCEPT_INCOMPLETE )
|
||||
{
|
||||
case 0:
|
||||
list = end_out;
|
||||
}
|
||||
|
||||
wc_res = wildcard_expand( rest, start, flags, list );
|
||||
|
||||
free( next );
|
||||
|
||||
if( !(flags & ACCEPT_INCOMPLETE) )
|
||||
{
|
||||
|
||||
switch( wc_res )
|
||||
{
|
||||
if( !(flags & ACCEPT_INCOMPLETE) )
|
||||
case 0:
|
||||
{
|
||||
if( res == EXPAND_OK )
|
||||
res = EXPAND_WILDCARD_NO_MATCH;
|
||||
if( !(flags & ACCEPT_INCOMPLETE) )
|
||||
{
|
||||
if( res == EXPAND_OK )
|
||||
res = EXPAND_WILDCARD_NO_MATCH;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
case 1:
|
||||
{
|
||||
int j;
|
||||
res = EXPAND_WILDCARD_MATCH;
|
||||
sort_list( out );
|
||||
|
||||
for( j=0; j<al_get_count( out ); j++ )
|
||||
{
|
||||
wchar_t *next = (wchar_t *)al_get( out, j );
|
||||
if( !next )
|
||||
{
|
||||
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
|
||||
continue;
|
||||
}
|
||||
al_push( end_out, next );
|
||||
}
|
||||
al_truncate( out, 0 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
case 1:
|
||||
{
|
||||
int j;
|
||||
res = EXPAND_WILDCARD_MATCH;
|
||||
sort_list( out );
|
||||
|
||||
for( j=0; j<al_get_count( out ); j++ )
|
||||
case -1:
|
||||
{
|
||||
wchar_t *next = (wchar_t *)al_get( out, j );
|
||||
if( !next )
|
||||
{
|
||||
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
|
||||
continue;
|
||||
}
|
||||
al_push( end_out, next );
|
||||
al_foreach( out, &free );
|
||||
al_destroy( in );
|
||||
al_destroy( out );
|
||||
return EXPAND_ERROR;
|
||||
}
|
||||
al_truncate( out, 0 );
|
||||
break;
|
||||
}
|
||||
|
||||
case -1:
|
||||
{
|
||||
al_foreach( out, &free );
|
||||
al_destroy( in );
|
||||
al_destroy( out );
|
||||
return EXPAND_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1775,6 +1808,7 @@ int expand_string( void *context,
|
||||
al_push( end_out, next );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
al_destroy( in );
|
||||
al_destroy( out );
|
||||
@@ -1787,6 +1821,7 @@ int expand_string( void *context,
|
||||
halloc_register( context, (void *)al_get( end_out, i ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return res;
|
||||
|
||||
|
||||
4
expand.h
4
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
|
||||
{
|
||||
|
||||
82
fallback.c
82
fallback.c
@@ -65,6 +65,64 @@ int tputs(const char *str, int affcnt, int (*fish_putc)(tputs_arg_t))
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef TPARM_SOLARIS_KLUDGE
|
||||
|
||||
#undef tparm
|
||||
|
||||
/**
|
||||
Checks for known string values and maps to correct number of parameters.
|
||||
*/
|
||||
char *tparm_solaris_kludge( char *str, ... )
|
||||
{
|
||||
long int param[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
va_list ap;
|
||||
va_start( ap, 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_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_bold_mode && ! strcmp ( str, enter_bold_mode ) ) )
|
||||
{
|
||||
param[0] = va_arg( ap, long int );
|
||||
}
|
||||
else if( cursor_address && ! strcmp( str, cursor_address ) )
|
||||
{
|
||||
param[0] = va_arg( ap, long int );
|
||||
param[1] = va_arg( ap, long int );
|
||||
}
|
||||
|
||||
va_end( ap );
|
||||
|
||||
|
||||
return tparm( str, param[0], param[1], param[2], param[3],
|
||||
param[4], param[5], param[6], param[7], param[8] );
|
||||
}
|
||||
|
||||
// Re-defining just to make sure nothing breaks further down in this file.
|
||||
#define tparm tparm_solaris_kludge
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef HAVE_FWPRINTF
|
||||
#define INTERNAL_FWPRINTF 1
|
||||
@@ -1110,3 +1168,27 @@ char ** backtrace_symbols (void *const *buffer, int size)
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SYSCONF
|
||||
|
||||
long sysconf(int name)
|
||||
{
|
||||
if( name == _SC_ARG_MAX )
|
||||
{
|
||||
#ifdef ARG_MAX
|
||||
return ARG_MAX;
|
||||
#endif
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_NAN
|
||||
double nan(char *tagp)
|
||||
{
|
||||
return 0.0/0.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
72
fallback.h
72
fallback.h
@@ -54,12 +54,21 @@ typedef char tputs_arg_t;
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_WINSIZE
|
||||
/**
|
||||
Structure used to get the size of a terminal window
|
||||
*/
|
||||
struct winsize
|
||||
{
|
||||
/**
|
||||
Number of rows
|
||||
*/
|
||||
unsigned short ws_row;
|
||||
/**
|
||||
Number of columns
|
||||
*/
|
||||
unsigned short ws_col;
|
||||
}
|
||||
;
|
||||
;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -73,6 +82,18 @@ int tputs(const char *str, int affcnt, int (*fish_putc)(tputs_arg_t));
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef TPARM_SOLARIS_KLUDGE
|
||||
|
||||
/**
|
||||
Solaris tparm has a set fixed of paramters in it's curses implementation,
|
||||
work around this here.
|
||||
*/
|
||||
|
||||
#define tparm tparm_solaris_kludge
|
||||
char *tparm_solaris_kludge( char *str, ... );
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FWPRINTF
|
||||
|
||||
/**
|
||||
@@ -271,8 +292,8 @@ long convert_digit( wchar_t d, int base );
|
||||
supported.
|
||||
*/
|
||||
long wcstol(const wchar_t *nptr,
|
||||
wchar_t **endptr,
|
||||
int base);
|
||||
wchar_t **endptr,
|
||||
int base);
|
||||
|
||||
#endif
|
||||
#ifndef HAVE_WCSLCAT
|
||||
@@ -325,7 +346,7 @@ struct drand48_data
|
||||
*/
|
||||
unsigned int seed;
|
||||
}
|
||||
;
|
||||
;
|
||||
|
||||
/**
|
||||
Fallback implementation of lrand48_r. Internally uses rand_r, so it is pretty weak.
|
||||
@@ -370,8 +391,8 @@ char * textdomain( const char * domainname );
|
||||
Fallback implementation of dcgettext. Just returns the original string.
|
||||
*/
|
||||
char * dcgettext ( const char * domainname,
|
||||
const char * msgid,
|
||||
int category );
|
||||
const char * msgid,
|
||||
int category );
|
||||
|
||||
#endif
|
||||
|
||||
@@ -388,20 +409,38 @@ 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 describing a long getopt option
|
||||
*/
|
||||
struct option
|
||||
{
|
||||
/**
|
||||
Name of option
|
||||
*/
|
||||
const char *name;
|
||||
/**
|
||||
Flag
|
||||
*/
|
||||
int has_arg;
|
||||
/**
|
||||
Flag
|
||||
*/
|
||||
int *flag;
|
||||
/**
|
||||
Return value
|
||||
*/
|
||||
int val;
|
||||
}
|
||||
;
|
||||
;
|
||||
|
||||
#ifndef no_argument
|
||||
#define no_argument 0
|
||||
@@ -416,12 +455,23 @@ struct option
|
||||
#endif
|
||||
|
||||
int getopt_long(int argc,
|
||||
char * const argv[],
|
||||
const char *optstring,
|
||||
const struct option *longopts,
|
||||
int *longindex);
|
||||
char * const argv[],
|
||||
const char *optstring,
|
||||
const struct option *longopts,
|
||||
int *longindex);
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SYSCONF
|
||||
|
||||
#define _SC_ARG_MAX 1
|
||||
long sysconf(int name);
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_NAN
|
||||
double nan(char *tagp);
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 2005-2006 Axel Liljencrantz
|
||||
Copyright (C) 2005-2008 Axel Liljencrantz
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2 as
|
||||
@@ -16,7 +16,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
|
||||
/** \file main.c
|
||||
/** \file fish.c
|
||||
The main loop of <tt>fish</tt>.
|
||||
*/
|
||||
|
||||
@@ -73,20 +73,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
static int read_init()
|
||||
{
|
||||
wchar_t cwd[4096];
|
||||
wchar_t *config_dir;
|
||||
wchar_t *config_dir_escaped;
|
||||
void *context;
|
||||
string_buffer_t *eval_buff;
|
||||
|
||||
if( !wgetcwd( cwd, 4096 ) )
|
||||
{
|
||||
wperror( L"wgetcwd" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
eval( L"builtin cd " DATADIR L"/fish 2>/dev/null; and builtin . config.fish 2>/dev/null", 0, TOP );
|
||||
eval( L"builtin cd " SYSCONFDIR L"/fish 2>/dev/null; and builtin . config.fish 2>/dev/null", 0, TOP );
|
||||
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
|
||||
@@ -94,36 +87,34 @@ static int read_init()
|
||||
context = halloc( 0, 0 );
|
||||
eval_buff = sb_halloc( context );
|
||||
config_dir = path_get_config( context );
|
||||
config_dir_escaped = escape( config_dir, 1 );
|
||||
sb_printf( eval_buff, L"builtin cd %ls 2>/dev/null; and builtin . config.fish 2>/dev/null", config_dir_escaped );
|
||||
eval( (wchar_t *)eval_buff->buff, 0, TOP );
|
||||
|
||||
/*
|
||||
If config_dir is null then we have no configuration directory
|
||||
and no custom config to load.
|
||||
*/
|
||||
if( config_dir )
|
||||
{
|
||||
config_dir_escaped = escape( config_dir, 1 );
|
||||
sb_printf( eval_buff, L"builtin . %ls/config.fish 2>/dev/null", config_dir_escaped );
|
||||
eval( (wchar_t *)eval_buff->buff, 0, TOP );
|
||||
free( config_dir_escaped );
|
||||
}
|
||||
|
||||
halloc_free( context );
|
||||
free( config_dir_escaped );
|
||||
|
||||
if( wchdir( cwd ) == -1 )
|
||||
{
|
||||
/*
|
||||
If we can't change back to previos directory, we go to
|
||||
~. Should be a sane default behavior.
|
||||
*/
|
||||
eval( L"builtin cd", 0, TOP );
|
||||
}
|
||||
else
|
||||
{
|
||||
env_set( L"PWD", cwd, ENV_EXPORT );
|
||||
}
|
||||
|
||||
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
|
||||
@@ -263,9 +254,17 @@ static int fish_parse_opt( int argc, char **argv, char **cmd_ptr )
|
||||
|
||||
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);
|
||||
|
||||
/*
|
||||
We are also an interactive session if we have are forced-
|
||||
*/
|
||||
is_interactive_session |= force_interactive;
|
||||
|
||||
return my_optind;
|
||||
@@ -301,7 +300,6 @@ int main( int argc, char **argv )
|
||||
no_exec = 0;
|
||||
}
|
||||
|
||||
|
||||
proc_init();
|
||||
event_init();
|
||||
wutil_init();
|
||||
@@ -325,7 +323,7 @@ int main( int argc, char **argv )
|
||||
{
|
||||
if( my_optind == argc )
|
||||
{
|
||||
res = reader_read( 0 );
|
||||
res = reader_read( 0, 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -361,27 +359,31 @@ int main( int argc, char **argv )
|
||||
|
||||
rel_filename = str2wcs( file );
|
||||
abs_filename = wrealpath( rel_filename, 0 );
|
||||
|
||||
if( !abs_filename )
|
||||
{
|
||||
abs_filename = wcsdup(rel_filename);
|
||||
}
|
||||
|
||||
reader_push_current_filename( intern( abs_filename ) );
|
||||
free( rel_filename );
|
||||
free( abs_filename );
|
||||
|
||||
res = reader_read( fd );
|
||||
res = reader_read( fd, 0 );
|
||||
|
||||
if( res )
|
||||
{
|
||||
debug( 1,
|
||||
_(L"Error while reading file %ls\n"),
|
||||
reader_current_filename()?reader_current_filename(): _(L"Standard input") );
|
||||
_(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();
|
||||
@@ -390,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();
|
||||
}
|
||||
23
fish.spec.in
23
fish.spec.in
@@ -116,31 +116,29 @@ fi
|
||||
|
||||
# man files
|
||||
%_mandir/man1/fish.1*
|
||||
%_mandir/man1/xsel.1x*
|
||||
%_mandir/man1/fish_pager.1*
|
||||
%_mandir/man1/fish_indent.1*
|
||||
%_mandir/man1/fishd.1*
|
||||
%_mandir/man1/mimedb.1*
|
||||
%_mandir/man1/set_color.1*
|
||||
%_mandir/man1/count.1*
|
||||
%_mandir/man1/fishd.1*
|
||||
%_mandir/man1/fish_pager.1*
|
||||
%_mandir/man1/xsel.1x*
|
||||
|
||||
# The program binaries
|
||||
%attr(0755,root,root) %_bindir/fish
|
||||
%attr(0755,root,root) %_bindir/fishd
|
||||
%attr(0755,root,root) %_bindir/fish_indent
|
||||
%attr(0755,root,root) %_bindir/fish_pager
|
||||
%attr(0755,root,root) %_bindir/xsel
|
||||
%attr(0755,root,root) %_bindir/set_color
|
||||
%attr(0755,root,root) %_bindir/fishd
|
||||
%attr(0755,root,root) %_bindir/mimedb
|
||||
%attr(0755,root,root) %_bindir/count
|
||||
%attr(0755,root,root) %_bindir/set_color
|
||||
%attr(0755,root,root) %_bindir/xsel
|
||||
|
||||
# Configuration files
|
||||
%config %_sysconfdir/fish/config.fish
|
||||
%config %_sysconfdir/fish/fish_inputrc
|
||||
%dir %_sysconfdir/fish
|
||||
|
||||
# Non-configuration initialization files
|
||||
%dir %_datadir/fish
|
||||
%_datadir/fish/config.fish
|
||||
%_datadir/fish/config_interactive.fish
|
||||
|
||||
# Program specific tab-completions
|
||||
%dir %_datadir/fish/completions
|
||||
@@ -156,9 +154,10 @@ fi
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
%changelog
|
||||
* Sat Apr 21 2007 Axel Liljencrantz<axel@liljencrantz.se> 1.23.0-0
|
||||
- Add fish_indent command
|
||||
|
||||
* Thu Feb 8 2007 Axel Liljencrantz<axel@liljencrantz.se> 1.22.3-0
|
||||
- Tell rpm about the help pages in %_datadir/fish/man/
|
||||
|
||||
|
||||
381
fish_indent.c
Normal file
381
fish_indent.c
Normal file
@@ -0,0 +1,381 @@
|
||||
/*
|
||||
Copyright (C) 2005-2008 Axel Liljencrantz
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2 as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
|
||||
/** \file fish_indent.c
|
||||
The fish_indent proegram.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_GETOPT_H
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
#include <locale.h>
|
||||
|
||||
#include "fallback.h"
|
||||
#include "util.h"
|
||||
#include "common.h"
|
||||
#include "wutil.h"
|
||||
#include "halloc.h"
|
||||
#include "halloc_util.h"
|
||||
#include "tokenizer.h"
|
||||
#include "print_help.h"
|
||||
#include "parser_keywords.h"
|
||||
|
||||
/**
|
||||
The string describing the single-character options accepted by the main fish binary
|
||||
*/
|
||||
#define GETOPT_STRING "hvi"
|
||||
|
||||
/**
|
||||
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;
|
||||
int res=0;
|
||||
int is_command = 1;
|
||||
int indent = 0;
|
||||
int do_indent = 1;
|
||||
int prev_type = 0;
|
||||
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:
|
||||
{
|
||||
if( is_command )
|
||||
{
|
||||
int next_indent = indent;
|
||||
is_command = 0;
|
||||
|
||||
wchar_t *unesc = unescape( last, UNESCAPE_SPECIAL );
|
||||
|
||||
if( parser_keywords_is_block( unesc ) )
|
||||
{
|
||||
next_indent++;
|
||||
}
|
||||
else if( wcscmp( unesc, L"else" ) == 0 )
|
||||
{
|
||||
indent--;
|
||||
}
|
||||
else if( wcscmp( unesc, L"end" ) == 0 )
|
||||
{
|
||||
indent--;
|
||||
next_indent--;
|
||||
}
|
||||
|
||||
|
||||
if( do_indent && flags)
|
||||
{
|
||||
insert_tabs( out, indent );
|
||||
}
|
||||
|
||||
sb_printf( out, L"%ls", last );
|
||||
|
||||
indent = next_indent;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
sb_printf( out, L" %ls", last );
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case TOK_END:
|
||||
{
|
||||
if( prev_type != TOK_END || prev_prev_type != TOK_END )
|
||||
sb_append( out, L"\n" );
|
||||
do_indent = 1;
|
||||
is_command = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
case TOK_PIPE:
|
||||
{
|
||||
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;
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case TOK_BACKGROUND:
|
||||
{
|
||||
sb_append( out, L"&\n" );
|
||||
do_indent = 1;
|
||||
is_command = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case TOK_COMMENT:
|
||||
{
|
||||
if( do_indent && flags)
|
||||
{
|
||||
insert_tabs( out, indent );
|
||||
}
|
||||
|
||||
sb_printf( out, L"%ls", last );
|
||||
do_indent = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
debug( 0, L"Unknown token '%ls'", last );
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
prev_prev_type = prev_type;
|
||||
prev_type = type;
|
||||
|
||||
}
|
||||
|
||||
tok_destroy( &tok );
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
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";
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
static struct option
|
||||
long_options[] =
|
||||
{
|
||||
{
|
||||
"no-indent", no_argument, 0, 'i'
|
||||
}
|
||||
,
|
||||
{
|
||||
"help", no_argument, 0, 'h'
|
||||
}
|
||||
,
|
||||
{
|
||||
"version", no_argument, 0, 'v'
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
int opt_index = 0;
|
||||
|
||||
int opt = getopt_long( argc,
|
||||
argv,
|
||||
GETOPT_STRING,
|
||||
long_options,
|
||||
&opt_index );
|
||||
|
||||
if( opt == -1 )
|
||||
break;
|
||||
|
||||
switch( opt )
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case 'h':
|
||||
{
|
||||
print_help( "fish_indent", 1 );
|
||||
exit( 0 );
|
||||
break;
|
||||
}
|
||||
|
||||
case 'v':
|
||||
{
|
||||
fwprintf( stderr,
|
||||
_(L"%ls, version %s\n"),
|
||||
program_name,
|
||||
PACKAGE_VERSION );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
case 'i':
|
||||
{
|
||||
do_indent = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case '?':
|
||||
{
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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 ) )
|
||||
{
|
||||
fwprintf( stdout, L"%ls", trim( (wchar_t *)sb_out.buff) );
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
Indenting failed - print original input
|
||||
*/
|
||||
fwprintf( stdout, L"%ls", (wchar_t *)sb_in.buff );
|
||||
}
|
||||
|
||||
|
||||
wutil_destroy();
|
||||
|
||||
halloc_util_destroy();
|
||||
|
||||
return 0;
|
||||
}
|
||||
189
fish_pager.c
189
fish_pager.c
@@ -253,8 +253,8 @@ static int try_sequence( char *seq )
|
||||
wint_t c=0;
|
||||
|
||||
for( j=0;
|
||||
seq[j] != '\0' && seq[j] == (c=input_common_readch( j>0 ));
|
||||
j++ )
|
||||
seq[j] != '\0' && seq[j] == (c=input_common_readch( j>0 ));
|
||||
j++ )
|
||||
;
|
||||
|
||||
if( seq[j] == '\0' )
|
||||
@@ -285,7 +285,7 @@ static wint_t readch()
|
||||
struct mapping m[]=
|
||||
{
|
||||
{
|
||||
"\e[A", LINE_UP
|
||||
"\x1b[A", LINE_UP
|
||||
}
|
||||
,
|
||||
{
|
||||
@@ -293,7 +293,7 @@ static wint_t readch()
|
||||
}
|
||||
,
|
||||
{
|
||||
"\e[B", LINE_DOWN
|
||||
"\x1b[B", LINE_DOWN
|
||||
}
|
||||
,
|
||||
{
|
||||
@@ -324,8 +324,13 @@ static wint_t readch()
|
||||
;
|
||||
int i;
|
||||
|
||||
for( i=0; m[i].seq; i++ )
|
||||
for( i=0; m[i].bnd; i++ )
|
||||
{
|
||||
if( !m[i].seq )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if( try_sequence(m[i].seq ) )
|
||||
return m[i].bnd;
|
||||
}
|
||||
@@ -346,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;
|
||||
}
|
||||
|
||||
@@ -408,8 +413,8 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width )
|
||||
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 );
|
||||
2*(width-4)/3 ),
|
||||
width - desc_all );
|
||||
if( c->desc_width )
|
||||
desc_width = width-comp_width-4;
|
||||
else
|
||||
@@ -438,7 +443,7 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width )
|
||||
}
|
||||
written += print_max( L"(", 1, 0 );
|
||||
set_color( get_color( HIGHLIGHT_PAGER_DESCRIPTION ),
|
||||
FISH_COLOR_IGNORE );
|
||||
FISH_COLOR_IGNORE );
|
||||
written += print_max( c->desc, desc_width, 0 );
|
||||
written += print_max( L")", 1, 0 );
|
||||
}
|
||||
@@ -467,12 +472,12 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width )
|
||||
*/
|
||||
|
||||
static void completion_print( int cols,
|
||||
int *width,
|
||||
int row_start,
|
||||
int row_stop,
|
||||
wchar_t *prefix,
|
||||
int is_quoted,
|
||||
array_list_t *l)
|
||||
int *width,
|
||||
int row_start,
|
||||
int row_stop,
|
||||
wchar_t *prefix,
|
||||
int is_quoted,
|
||||
array_list_t *l)
|
||||
{
|
||||
|
||||
int rows = (al_get_count( l )-1)/cols+1;
|
||||
@@ -520,9 +525,9 @@ static void completion_print( int cols,
|
||||
*/
|
||||
|
||||
static int completion_try_print( int cols,
|
||||
wchar_t *prefix,
|
||||
int is_quoted,
|
||||
array_list_t *l )
|
||||
wchar_t *prefix,
|
||||
int is_quoted,
|
||||
array_list_t *l )
|
||||
{
|
||||
/*
|
||||
The calculated preferred width of each column
|
||||
@@ -578,9 +583,9 @@ static int completion_try_print( int cols,
|
||||
min += 2;
|
||||
}
|
||||
min_width[j] = maxi( min_width[j],
|
||||
min );
|
||||
min );
|
||||
pref_width[j] = maxi( pref_width[j],
|
||||
pref );
|
||||
pref );
|
||||
}
|
||||
min_tot_width += min_width[j];
|
||||
pref_tot_width += pref_width[j];
|
||||
@@ -614,8 +619,8 @@ static int completion_try_print( int cols,
|
||||
pref_tot_width-termsize.ws_col );
|
||||
*/
|
||||
if( min_tot_width < termsize.ws_col &&
|
||||
( ( (rows < termsize.ws_row) && (next_rows >= termsize.ws_row ) ) ||
|
||||
( pref_tot_width-termsize.ws_col< 4 && cols < 3 ) ) )
|
||||
( ( (rows < termsize.ws_row) && (next_rows >= termsize.ws_row ) ) ||
|
||||
( pref_tot_width-termsize.ws_col< 4 && cols < 3 ) ) )
|
||||
{
|
||||
/*
|
||||
Terminal almost wide enough, or squeezing makes the
|
||||
@@ -672,16 +677,25 @@ static int completion_try_print( int cols,
|
||||
int npos, pos = 0;
|
||||
int do_loop = 1;
|
||||
|
||||
is_ca_mode=1;
|
||||
writembs(enter_ca_mode);
|
||||
/*
|
||||
Enter ca_mode, which means that the terminal
|
||||
content will be restored to the current
|
||||
state on exit.
|
||||
*/
|
||||
if( enter_ca_mode && exit_ca_mode )
|
||||
{
|
||||
is_ca_mode=1;
|
||||
writembs(enter_ca_mode);
|
||||
}
|
||||
|
||||
|
||||
completion_print( cols,
|
||||
width,
|
||||
0,
|
||||
termsize.ws_row-1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l);
|
||||
width,
|
||||
0,
|
||||
termsize.ws_row-1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l);
|
||||
/*
|
||||
List does not fit on screen. Print one screenfull and
|
||||
leave a scrollable interface
|
||||
@@ -692,13 +706,16 @@ static int completion_try_print( int cols,
|
||||
sb_init( &msg );
|
||||
|
||||
set_color( FISH_COLOR_BLACK,
|
||||
get_color(HIGHLIGHT_PAGER_PROGRESS) );
|
||||
get_color(HIGHLIGHT_PAGER_PROGRESS) );
|
||||
sb_printf( &msg,
|
||||
_(L" %d to %d of %d \r"),
|
||||
pos,
|
||||
pos+termsize.ws_row-1,
|
||||
rows );
|
||||
_(L" %d to %d of %d"),
|
||||
pos,
|
||||
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 );
|
||||
@@ -715,14 +732,14 @@ static int completion_try_print( int cols,
|
||||
writembs(tparm( cursor_address, 0, 0));
|
||||
writembs(scroll_reverse);
|
||||
completion_print( cols,
|
||||
width,
|
||||
pos,
|
||||
pos+1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l );
|
||||
width,
|
||||
pos,
|
||||
pos+1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l );
|
||||
writembs( tparm( cursor_address,
|
||||
termsize.ws_row-1, 0) );
|
||||
termsize.ws_row-1, 0) );
|
||||
writembs(clr_eol );
|
||||
|
||||
}
|
||||
@@ -736,12 +753,12 @@ static int completion_try_print( int cols,
|
||||
{
|
||||
pos++;
|
||||
completion_print( cols,
|
||||
width,
|
||||
pos+termsize.ws_row-2,
|
||||
pos+termsize.ws_row-1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l );
|
||||
width,
|
||||
pos+termsize.ws_row-2,
|
||||
pos+termsize.ws_row-1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l );
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -750,17 +767,17 @@ static int completion_try_print( int cols,
|
||||
{
|
||||
|
||||
npos = mini( rows - termsize.ws_row+1,
|
||||
pos + termsize.ws_row-1 );
|
||||
pos + termsize.ws_row-1 );
|
||||
if( npos != pos )
|
||||
{
|
||||
pos = npos;
|
||||
completion_print( cols,
|
||||
width,
|
||||
pos,
|
||||
pos+termsize.ws_row-1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l );
|
||||
width,
|
||||
pos,
|
||||
pos+termsize.ws_row-1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -774,18 +791,18 @@ static int completion_try_print( int cols,
|
||||
case PAGE_UP:
|
||||
{
|
||||
npos = maxi( 0,
|
||||
pos - termsize.ws_row+1 );
|
||||
pos - termsize.ws_row+1 );
|
||||
|
||||
if( npos != pos )
|
||||
{
|
||||
pos = npos;
|
||||
completion_print( cols,
|
||||
width,
|
||||
pos,
|
||||
pos+termsize.ws_row-1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l );
|
||||
width,
|
||||
pos,
|
||||
pos+termsize.ws_row-1,
|
||||
prefix,
|
||||
is_quoted,
|
||||
l );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -944,7 +961,7 @@ static void mangle_completions( array_list_t *l, const wchar_t *prefix )
|
||||
if( (c == COMPLETE_ITEM_SEP) || (c==COMPLETE_SEP) || !c)
|
||||
{
|
||||
*end = 0;
|
||||
wchar_t * str = escape( start, 1 );
|
||||
wchar_t * str = escape( start, ESCAPE_ALL | ESCAPE_NO_QUOTED );
|
||||
|
||||
comp->comp_width += my_wcswidth( str );
|
||||
halloc_register( global_context, str );
|
||||
@@ -1008,8 +1025,8 @@ static void init( int mangle_descriptors, int out )
|
||||
struct sigaction act;
|
||||
|
||||
static struct termios pager_modes;
|
||||
|
||||
|
||||
char *term;
|
||||
|
||||
if( mangle_descriptors )
|
||||
{
|
||||
|
||||
@@ -1076,22 +1093,23 @@ static void init( int mangle_descriptors, int out )
|
||||
|
||||
tcgetattr(0,&pager_modes); /* get the current terminal modes */
|
||||
memcpy( &saved_modes,
|
||||
&pager_modes,
|
||||
sizeof(saved_modes)); /* save a copy so we can reset the terminal later */
|
||||
&pager_modes,
|
||||
sizeof(saved_modes)); /* save a copy so we can reset the terminal later */
|
||||
|
||||
pager_modes.c_lflag &= ~ICANON; /* turn off canonical mode */
|
||||
pager_modes.c_lflag &= ~ECHO; /* turn off echo mode */
|
||||
pager_modes.c_cc[VMIN]=1;
|
||||
pager_modes.c_cc[VTIME]=0;
|
||||
pager_modes.c_cc[VMIN]=1;
|
||||
pager_modes.c_cc[VTIME]=0;
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
if( tcsetattr(0,TCSANOW,&pager_modes)) /* set the new modes */
|
||||
{
|
||||
wperror(L"tcsetattr");
|
||||
exit(1);
|
||||
}
|
||||
if( tcsetattr(0,TCSANOW,&pager_modes)) /* set the new modes */
|
||||
{
|
||||
wperror(L"tcsetattr");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
if( setupterm( 0, STDOUT_FILENO, 0) == ERR )
|
||||
{
|
||||
@@ -1099,6 +1117,14 @@ static void init( int mangle_descriptors, int out )
|
||||
exit(1);
|
||||
}
|
||||
|
||||
term = getenv("TERM");
|
||||
if( term )
|
||||
{
|
||||
wchar_t *wterm = str2wcs(term);
|
||||
output_set_term( wterm );
|
||||
free( wterm );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1137,7 +1163,7 @@ static void read_array( FILE* file, array_list_t *comp )
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
c = getc( file );
|
||||
c = getc( file );
|
||||
if( c == EOF )
|
||||
{
|
||||
break;
|
||||
@@ -1162,7 +1188,10 @@ static void read_array( FILE* file, array_list_t *comp )
|
||||
if( wcs )
|
||||
{
|
||||
unescaped = unescape( wcs, 0 );
|
||||
al_push( comp, unescaped );
|
||||
if( unescaped )
|
||||
{
|
||||
al_push( comp, unescaped );
|
||||
}
|
||||
free( wcs );
|
||||
}
|
||||
}
|
||||
@@ -1265,10 +1294,10 @@ int main( int argc, char **argv )
|
||||
int opt_index = 0;
|
||||
|
||||
int opt = getopt_long( argc,
|
||||
argv,
|
||||
GETOPT_STRING,
|
||||
long_options,
|
||||
&opt_index );
|
||||
argv,
|
||||
GETOPT_STRING,
|
||||
long_options,
|
||||
&opt_index );
|
||||
|
||||
if( opt == -1 )
|
||||
break;
|
||||
|
||||
183
fish_tests.c
183
fish_tests.c
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <locale.h>
|
||||
#include <dirent.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "fallback.h"
|
||||
#include "util.h"
|
||||
@@ -44,8 +45,23 @@
|
||||
#include "output.h"
|
||||
#include "exec.h"
|
||||
#include "event.h"
|
||||
#include "path.h"
|
||||
#include "halloc.h"
|
||||
#include "halloc_util.h"
|
||||
|
||||
/**
|
||||
The number of tests to run
|
||||
*/
|
||||
#define ESCAPE_TEST_COUNT 1000000
|
||||
/**
|
||||
The average length of strings to unescape
|
||||
*/
|
||||
#define ESCAPE_TEST_LENGTH 100
|
||||
/**
|
||||
The higest character number of character to try and escape
|
||||
*/
|
||||
#define ESCAPE_TEST_CHAR 4000
|
||||
|
||||
/**
|
||||
Number of laps to run performance testing loop
|
||||
*/
|
||||
@@ -400,6 +416,140 @@ static void test_util()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Test the escaping/unescaping code by escaping/unescaping random
|
||||
strings and verifying that the original string comes back.
|
||||
*/
|
||||
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 )
|
||||
{
|
||||
sb_append_char( &sb, (rand() %ESCAPE_TEST_CHAR) +1 );
|
||||
}
|
||||
o = (wchar_t *)sb.buff;
|
||||
e = escape(o, 1);
|
||||
u = unescape( e, 0 );
|
||||
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 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Test wide/narrow conversion by creating random strings and
|
||||
verifying that the original string comes back thorugh double
|
||||
conversion.
|
||||
*/
|
||||
static void test_convert()
|
||||
{
|
||||
/* 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]);;
|
||||
//wprintf(L"%d ", o[i]);
|
||||
}
|
||||
wprintf(L"\n");
|
||||
|
||||
for( i=0; w[i]; i++ )
|
||||
{
|
||||
wbitprint(w[i]);;
|
||||
//wprintf(L"%d ", w[i]);
|
||||
}
|
||||
wprintf(L"\n");
|
||||
|
||||
for( i=0; n[i]; i++ )
|
||||
{
|
||||
bitprint(n[i]);;
|
||||
//wprintf(L"%d ", n[i]);
|
||||
}
|
||||
wprintf(L"\n");
|
||||
|
||||
return;
|
||||
*/
|
||||
|
||||
|
||||
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 ();
|
||||
b_append( &sb, &c, 1 );
|
||||
}
|
||||
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 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Test the tokenizer
|
||||
*/
|
||||
@@ -600,6 +750,29 @@ static void test_expand()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
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 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Test speed of completion calculations
|
||||
*/
|
||||
@@ -673,11 +846,16 @@ void perf_complete()
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Main test
|
||||
*/
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
setlocale( LC_ALL, "" );
|
||||
srand( time( 0 ) );
|
||||
|
||||
program_name=L"(ignore)";
|
||||
|
||||
@@ -694,10 +872,13 @@ int main( int argc, char **argv )
|
||||
env_init();
|
||||
|
||||
test_util();
|
||||
test_escape();
|
||||
test_convert();
|
||||
test_tok();
|
||||
test_parser();
|
||||
test_expand();
|
||||
|
||||
test_path();
|
||||
|
||||
say( L"Encountered %d errors in low-level tests", err_count );
|
||||
|
||||
/*
|
||||
|
||||
2
fishd.c
2
fishd.c
@@ -521,7 +521,7 @@ 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
|
||||
|
||||
151
function.c
151
function.c
@@ -28,6 +28,7 @@
|
||||
#include "event.h"
|
||||
#include "reader.h"
|
||||
#include "parse_util.h"
|
||||
#include "parser_keywords.h"
|
||||
#include "env.h"
|
||||
#include "expand.h"
|
||||
#include "halloc.h"
|
||||
@@ -40,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
|
||||
*/
|
||||
@@ -52,12 +53,24 @@ typedef struct
|
||||
*/
|
||||
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_data_t;
|
||||
function_internal_data_t;
|
||||
|
||||
/**
|
||||
Table containing all functions
|
||||
@@ -79,8 +92,8 @@ static int load( const wchar_t *name )
|
||||
{
|
||||
int was_autoload = is_autoload;
|
||||
int res;
|
||||
function_data_t *data;
|
||||
data = (function_data_t *)hash_get( &function, name );
|
||||
function_internal_data_t *data;
|
||||
data = (function_internal_data_t *)hash_get( &function, name );
|
||||
if( data && !data->is_autoload )
|
||||
return 0;
|
||||
|
||||
@@ -149,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 );
|
||||
@@ -161,35 +177,43 @@ void function_destroy()
|
||||
}
|
||||
|
||||
|
||||
void function_add( const wchar_t *name,
|
||||
const wchar_t *val,
|
||||
const wchar_t *desc,
|
||||
array_list_t *events )
|
||||
void function_add( function_data_t *data )
|
||||
{
|
||||
int i;
|
||||
wchar_t *cmd_end;
|
||||
function_data_t *d;
|
||||
function_internal_data_t *d;
|
||||
|
||||
CHECK( name, );
|
||||
CHECK( val, );
|
||||
CHECK( data->name, );
|
||||
CHECK( data->definition, );
|
||||
|
||||
function_remove( name );
|
||||
function_remove( data->name );
|
||||
|
||||
d = halloc( 0, sizeof( function_data_t ) );
|
||||
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, val );
|
||||
d->definition = halloc_wcsdup( d, data->definition );
|
||||
|
||||
if( data->named_arguments )
|
||||
{
|
||||
d->named_arguments = al_halloc( d );
|
||||
|
||||
for( i=0; i<al_get_count( data->named_arguments ); i++ )
|
||||
{
|
||||
al_push( d->named_arguments, halloc_wcsdup( d, (wchar_t *)al_get( data->named_arguments, i ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
cmd_end = d->cmd + wcslen(d->cmd)-1;
|
||||
cmd_end = d->definition + wcslen(d->definition)-1;
|
||||
|
||||
d->desc = desc?halloc_wcsdup( d, desc ):0;
|
||||
d->description = data->description?halloc_wcsdup( d, data->description ):0;
|
||||
d->definition_file = intern(reader_current_filename());
|
||||
d->is_autoload = is_autoload;
|
||||
|
||||
hash_put( &function, intern(name), d );
|
||||
d->shadows = data->shadows;
|
||||
|
||||
for( i=0; i<al_get_count( events ); i++ )
|
||||
hash_put( &function, intern(data->name), d );
|
||||
|
||||
for( i=0; i<al_get_count( data->events ); i++ )
|
||||
{
|
||||
event_add_handler( (event_t *)al_get( events, i ) );
|
||||
event_add_handler( (event_t *)al_get( data->events, i ) );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -199,7 +223,7 @@ int function_exists( const wchar_t *cmd )
|
||||
|
||||
CHECK( cmd, 0 );
|
||||
|
||||
if( parser_is_reserved(cmd) )
|
||||
if( parser_keywords_is_reserved(cmd) )
|
||||
return 0;
|
||||
|
||||
load( cmd );
|
||||
@@ -210,7 +234,7 @@ void function_remove( const wchar_t *name )
|
||||
{
|
||||
void *key;
|
||||
void *dv;
|
||||
function_data_t *d;
|
||||
function_internal_data_t *d;
|
||||
event_t ev;
|
||||
|
||||
CHECK( name, );
|
||||
@@ -220,7 +244,7 @@ void function_remove( const wchar_t *name )
|
||||
&key,
|
||||
&dv );
|
||||
|
||||
d=(function_data_t *)dv;
|
||||
d=(function_internal_data_t *)dv;
|
||||
|
||||
if( !key )
|
||||
return;
|
||||
@@ -242,46 +266,73 @@ void function_remove( const wchar_t *name )
|
||||
}
|
||||
}
|
||||
|
||||
const wchar_t *function_get_definition( const wchar_t *argv )
|
||||
const wchar_t *function_get_definition( const wchar_t *name )
|
||||
{
|
||||
function_data_t *data;
|
||||
function_internal_data_t *data;
|
||||
|
||||
CHECK( argv, 0 );
|
||||
CHECK( name, 0 );
|
||||
|
||||
load( argv );
|
||||
data = (function_data_t *)hash_get( &function, argv );
|
||||
load( name );
|
||||
data = (function_internal_data_t *)hash_get( &function, name );
|
||||
if( data == 0 )
|
||||
return 0;
|
||||
return data->cmd;
|
||||
return data->definition;
|
||||
}
|
||||
|
||||
const wchar_t *function_get_desc( const wchar_t *argv )
|
||||
|
||||
array_list_t *function_get_named_arguments( const wchar_t *name )
|
||||
{
|
||||
function_data_t *data;
|
||||
function_internal_data_t *data;
|
||||
|
||||
CHECK( argv, 0 );
|
||||
CHECK( name, 0 );
|
||||
|
||||
load( name );
|
||||
data = (function_internal_data_t *)hash_get( &function, name );
|
||||
if( data == 0 )
|
||||
return 0;
|
||||
return data->named_arguments;
|
||||
}
|
||||
|
||||
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 )
|
||||
return 0;
|
||||
return data->shadows;
|
||||
}
|
||||
|
||||
|
||||
const wchar_t *function_get_desc( const wchar_t *name )
|
||||
{
|
||||
function_internal_data_t *data;
|
||||
|
||||
CHECK( name, 0 );
|
||||
|
||||
load( argv );
|
||||
data = (function_data_t *)hash_get( &function, argv );
|
||||
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_data_t *data;
|
||||
function_internal_data_t *data;
|
||||
|
||||
CHECK( name, );
|
||||
CHECK( desc, );
|
||||
|
||||
load( name );
|
||||
data = (function_data_t *)hash_get( &function, 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 );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,6 +341,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 )
|
||||
@@ -346,13 +401,13 @@ void function_get_names( array_list_t *list, int get_hidden )
|
||||
|
||||
}
|
||||
|
||||
const wchar_t *function_get_definition_file( const wchar_t *argv )
|
||||
const wchar_t *function_get_definition_file( const wchar_t *name )
|
||||
{
|
||||
function_data_t *data;
|
||||
function_internal_data_t *data;
|
||||
|
||||
CHECK( argv, 0 );
|
||||
CHECK( name, 0 );
|
||||
|
||||
data = (function_data_t *)hash_get( &function, argv );
|
||||
data = (function_internal_data_t *)hash_get( &function, name );
|
||||
if( data == 0 )
|
||||
return 0;
|
||||
|
||||
@@ -360,13 +415,13 @@ const wchar_t *function_get_definition_file( const wchar_t *argv )
|
||||
}
|
||||
|
||||
|
||||
int function_get_definition_offset( const wchar_t *argv )
|
||||
int function_get_definition_offset( const wchar_t *name )
|
||||
{
|
||||
function_data_t *data;
|
||||
function_internal_data_t *data;
|
||||
|
||||
CHECK( argv, -1 );
|
||||
CHECK( name, -1 );
|
||||
|
||||
data = (function_data_t *)hash_get( &function, argv );
|
||||
data = (function_internal_data_t *)hash_get( &function, name );
|
||||
if( data == 0 )
|
||||
return -1;
|
||||
|
||||
|
||||
53
function.h
53
function.h
@@ -14,6 +14,44 @@
|
||||
|
||||
#include "util.h"
|
||||
|
||||
/**
|
||||
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
|
||||
*/
|
||||
@@ -28,10 +66,7 @@ void function_destroy();
|
||||
Add an function. The parameters values are copied and should be
|
||||
freed by the caller.
|
||||
*/
|
||||
void function_add( const wchar_t *name,
|
||||
const wchar_t *val,
|
||||
const wchar_t *desc,
|
||||
array_list_t *events );
|
||||
void function_add( function_data_t *data );
|
||||
|
||||
/**
|
||||
Remove the function with the specified name.
|
||||
@@ -86,4 +121,14 @@ const wchar_t *function_get_definition_file( const wchar_t *name );
|
||||
*/
|
||||
int function_get_definition_offset( const wchar_t *name );
|
||||
|
||||
/**
|
||||
Returns a list of all named arguments of the specified function.
|
||||
*/
|
||||
array_list_t *function_get_named_arguments( const wchar_t *name );
|
||||
|
||||
/**
|
||||
Returns whether this function shadows variables of the underlying function
|
||||
*/
|
||||
int function_get_shadows( const wchar_t *name );
|
||||
|
||||
#endif
|
||||
|
||||
24
halloc.c
24
halloc.c
@@ -70,7 +70,7 @@ typedef struct halloc
|
||||
/**
|
||||
Memory scratch area used to fullfil smaller memory allocations
|
||||
*/
|
||||
void *scratch;
|
||||
char *scratch;
|
||||
/**
|
||||
Amount of free space in the scratch area
|
||||
*/
|
||||
@@ -78,15 +78,21 @@ typedef struct halloc
|
||||
}
|
||||
halloc_t;
|
||||
|
||||
static void *align_ptr( void *in )
|
||||
/**
|
||||
Allign the specified pointer
|
||||
*/
|
||||
static char *align_ptr( char *in )
|
||||
{
|
||||
unsigned long step = maxi(sizeof(double),sizeof(void *));
|
||||
unsigned long inc = step-1;
|
||||
unsigned long long_in = (long)in;
|
||||
unsigned long long_out = ((long_in+inc)/step)*step;
|
||||
return (void *)long_out;
|
||||
return (char *)long_out;
|
||||
}
|
||||
|
||||
/**
|
||||
Allign specifies size_t
|
||||
*/
|
||||
static size_t align_sz( size_t in )
|
||||
{
|
||||
size_t step = maxi(sizeof(double),sizeof(void *));
|
||||
@@ -132,8 +138,8 @@ void *halloc( void *context, size_t size )
|
||||
halloc_t *me, *parent;
|
||||
if( context )
|
||||
{
|
||||
void *res;
|
||||
void *aligned;
|
||||
char *res;
|
||||
char *aligned;
|
||||
|
||||
#ifdef HALLOC_DEBUG
|
||||
|
||||
@@ -142,7 +148,7 @@ void *halloc( void *context, size_t size )
|
||||
pid = getpid();
|
||||
atexit( &halloc_report );
|
||||
}
|
||||
|
||||
|
||||
child_count++;
|
||||
child_size += size;
|
||||
#endif
|
||||
@@ -190,7 +196,7 @@ void *halloc( void *context, size_t size )
|
||||
if( !res )
|
||||
DIE_MEM();
|
||||
}
|
||||
al_push( &parent->children, &late_free );
|
||||
al_push_func( &parent->children, &late_free );
|
||||
al_push( &parent->children, res );
|
||||
|
||||
}
|
||||
@@ -221,7 +227,7 @@ void halloc_register_function( void *context, void (*func)(void *), void *data )
|
||||
return;
|
||||
|
||||
me = halloc_from_data( context );
|
||||
al_push( &me->children, func );
|
||||
al_push_func( &me->children, func );
|
||||
al_push( &me->children, data );
|
||||
}
|
||||
|
||||
@@ -248,7 +254,7 @@ void halloc_free( void *context )
|
||||
}
|
||||
for( i=0; i<al_get_count(&me->children); i+=2 )
|
||||
{
|
||||
void (*func)(void *) = (void (*)(void *))al_get( &me->children, i );
|
||||
void (*func)(void *) = (void (*)(void *))al_get_func( &me->children, i );
|
||||
void * data = (void *)al_get( &me->children, i+1 );
|
||||
if( func == &late_free )
|
||||
free( data );
|
||||
|
||||
@@ -37,7 +37,7 @@ array_list_t *al_halloc( void *context )
|
||||
if( !res )
|
||||
DIE_MEM();
|
||||
al_init( res );
|
||||
halloc_register_function( context, (void (*)(void *)) &al_destroy, res );
|
||||
halloc_register_function( context?context:res, (void (*)(void *)) &al_destroy, res );
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ string_buffer_t *sb_halloc( void *context )
|
||||
if( !res )
|
||||
DIE_MEM();
|
||||
sb_init( res );
|
||||
halloc_register_function( context, (void (*)(void *)) &sb_destroy, res );
|
||||
halloc_register_function( context?context:res, (void (*)(void *)) &sb_destroy, res );
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
70
highlight.c
70
highlight.c
@@ -22,6 +22,7 @@
|
||||
#include "proc.h"
|
||||
#include "parser.h"
|
||||
#include "parse_util.h"
|
||||
#include "parser_keywords.h"
|
||||
#include "builtin.h"
|
||||
#include "function.h"
|
||||
#include "env.h"
|
||||
@@ -41,10 +42,9 @@
|
||||
#define VAR_COUNT ( sizeof(highlight_var)/sizeof(wchar_t *) )
|
||||
|
||||
static void highlight_universal_internal( wchar_t * buff,
|
||||
int *color,
|
||||
int pos,
|
||||
array_list_t *error );
|
||||
|
||||
int *color,
|
||||
int pos,
|
||||
array_list_t *error );
|
||||
|
||||
/**
|
||||
The environment variables used to specify the color of different tokens.
|
||||
@@ -282,11 +282,16 @@ static void highlight_param( const wchar_t * buff,
|
||||
color[in_pos+1] = normal_status;
|
||||
}
|
||||
}
|
||||
else if( wcschr( L"nrtbe*?$(){}'\"<>^ \\#;|&", buff[in_pos] ) )
|
||||
else if( wcschr( L"abefnrtv*?$(){}[]'\"<>^ \\#;|&", buff[in_pos] ) )
|
||||
{
|
||||
color[start_pos]=HIGHLIGHT_ESCAPE;
|
||||
color[in_pos+1]=normal_status;
|
||||
}
|
||||
else if( wcschr( L"c", buff[in_pos] ) )
|
||||
{
|
||||
color[start_pos]=HIGHLIGHT_ESCAPE;
|
||||
color[in_pos+2]=normal_status;
|
||||
}
|
||||
else if( wcschr( L"uUxX01234567", buff[in_pos] ) )
|
||||
{
|
||||
int i;
|
||||
@@ -525,6 +530,20 @@ static void highlight_param( const wchar_t * buff,
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -602,11 +621,14 @@ void highlight_shell( wchar_t * buff,
|
||||
if( cmd && (wcscmp( cmd, L"cd" ) == 0) )
|
||||
{
|
||||
wchar_t *dir = expand_one( context,
|
||||
wcsdup(tok_last( &tok )),
|
||||
EXPAND_SKIP_CMDSUBST );
|
||||
wcsdup(tok_last( &tok )),
|
||||
EXPAND_SKIP_CMDSUBST );
|
||||
if( dir )
|
||||
{
|
||||
if( !path_get_cdpath( context, 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;
|
||||
}
|
||||
@@ -628,10 +650,10 @@ void highlight_shell( wchar_t * buff,
|
||||
Command. First check that the command actually exists.
|
||||
*/
|
||||
cmd = expand_one( context,
|
||||
wcsdup(tok_last( &tok )),
|
||||
EXPAND_SKIP_CMDSUBST | EXPAND_SKIP_VARIABLES);
|
||||
wcsdup(tok_last( &tok )),
|
||||
EXPAND_SKIP_CMDSUBST | EXPAND_SKIP_VARIABLES);
|
||||
|
||||
if( cmd == 0 )
|
||||
if( (cmd == 0) || has_expand_reserved( cmd ) )
|
||||
{
|
||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
||||
}
|
||||
@@ -642,7 +664,7 @@ void highlight_shell( wchar_t * buff,
|
||||
int mark = tok_get_pos( &tok );
|
||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_COMMAND;
|
||||
|
||||
if( parser_is_subcommand( cmd ) )
|
||||
if( parser_keywords_is_subcommand( cmd ) )
|
||||
{
|
||||
|
||||
int sw;
|
||||
@@ -662,9 +684,9 @@ void highlight_shell( wchar_t * buff,
|
||||
|
||||
tok_next( &tok );
|
||||
|
||||
sw = parser_is_switch( tok_last( &tok ) );
|
||||
sw = parser_keywords_is_switch( tok_last( &tok ) );
|
||||
|
||||
if( !parser_is_block( cmd ) &&
|
||||
if( !parser_keywords_is_block( cmd ) &&
|
||||
sw == ARG_SWITCH )
|
||||
{
|
||||
/*
|
||||
@@ -690,7 +712,7 @@ void highlight_shell( wchar_t * buff,
|
||||
}
|
||||
tok_set_pos( &tok, mark );
|
||||
}
|
||||
|
||||
|
||||
if( !is_subcommand )
|
||||
{
|
||||
wchar_t *tmp;
|
||||
@@ -736,7 +758,7 @@ void highlight_shell( wchar_t * buff,
|
||||
else
|
||||
{
|
||||
if( error )
|
||||
al_push( error, wcsdupcat2 ( L"Unknown command \'", cmd, L"\'", (void *)0 ));
|
||||
al_push( error, wcsdupcat ( L"Unknown command \'", cmd, L"\'" ));
|
||||
color[ tok_get_pos( &tok ) ] = (HIGHLIGHT_ERROR);
|
||||
}
|
||||
had_cmd = 1;
|
||||
@@ -752,6 +774,7 @@ void highlight_shell( wchar_t * buff,
|
||||
break;
|
||||
}
|
||||
|
||||
case TOK_REDIRECT_NOCLOB:
|
||||
case TOK_REDIRECT_OUT:
|
||||
case TOK_REDIRECT_IN:
|
||||
case TOK_REDIRECT_APPEND:
|
||||
@@ -810,7 +833,7 @@ void highlight_shell( wchar_t * buff,
|
||||
{
|
||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
||||
if( error )
|
||||
al_push( error, wcsdupcat2( L"Directory \'", dir, L"\' does not exist", (void *)0 ) );
|
||||
al_push( error, wcsdupcat( L"Directory \'", dir, L"\' does not exist" ) );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -820,13 +843,22 @@ void highlight_shell( wchar_t * buff,
|
||||
if it exists.
|
||||
*/
|
||||
if( last_type == TOK_REDIRECT_IN ||
|
||||
last_type == TOK_REDIRECT_APPEND )
|
||||
last_type == TOK_REDIRECT_APPEND )
|
||||
{
|
||||
if( wstat( target, &buff ) == -1 )
|
||||
{
|
||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
||||
if( error )
|
||||
al_push( error, wcsdupcat2( L"File \'", target, L"\' does not exist", (void *)0 ) );
|
||||
al_push( error, wcsdupcat( L"File \'", target, L"\' does not exist" ) );
|
||||
}
|
||||
}
|
||||
if( last_type == TOK_REDIRECT_NOCLOB )
|
||||
{
|
||||
if( wstat( target, &buff ) != -1 )
|
||||
{
|
||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
||||
if( error )
|
||||
al_push( error, wcsdupcat( L"File \'", target, L"\' exists" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,6 +252,9 @@ 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;
|
||||
@@ -409,6 +412,9 @@ static void history_destroy_mode( history_mode_t *m )
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Free all memory used by specified mistory mode
|
||||
*/
|
||||
static void history_destroy_mode_wrapper( void *n, history_mode_t *m )
|
||||
{
|
||||
halloc_free( m );
|
||||
@@ -468,7 +474,7 @@ static wchar_t *history_filename( void *context, const wchar_t *name, const wcha
|
||||
if( !path )
|
||||
return 0;
|
||||
|
||||
res = wcsdupcat2( path, L"/", name, L"_history", suffix?suffix:(void *)0, (void *)0 );
|
||||
res = wcsdupcat( path, L"/", name, L"_history", suffix?suffix:(void *)0);
|
||||
halloc_register_function( context, &free, res );
|
||||
return res;
|
||||
}
|
||||
|
||||
64
input.h
64
input.h
@@ -33,14 +33,11 @@ enum
|
||||
R_COMPLETE,
|
||||
R_BEGINNING_OF_HISTORY,
|
||||
R_END_OF_HISTORY,
|
||||
R_DELETE_LINE,
|
||||
R_BACKWARD_KILL_LINE,
|
||||
R_KILL_WHOLE_LINE,
|
||||
R_KILL_WORD,
|
||||
R_BACKWARD_KILL_WORD,
|
||||
R_DUMP_FUNCTIONS,
|
||||
R_WINCH,
|
||||
R_EXIT,
|
||||
R_HISTORY_TOKEN_SEARCH_BACKWARD,
|
||||
R_HISTORY_TOKEN_SEARCH_FORWARD,
|
||||
R_SELF_INSERT,
|
||||
@@ -49,7 +46,9 @@ enum
|
||||
R_EXECUTE,
|
||||
R_BEGINNING_OF_BUFFER,
|
||||
R_END_OF_BUFFER,
|
||||
R_REPAINT
|
||||
R_REPAINT,
|
||||
R_UP_LINE,
|
||||
R_DOWN_LINE,
|
||||
}
|
||||
;
|
||||
|
||||
@@ -90,33 +89,56 @@ 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 add_mapping( const wchar_t *mode, const wchar_t *s, const wchar_t * d, const wchar_t *cmd );
|
||||
void input_mapping_add( const wchar_t *sequence, const wchar_t *command );
|
||||
|
||||
/**
|
||||
Sets the mode keybindings.
|
||||
*/
|
||||
void input_set_mode( wchar_t *name );
|
||||
Insert all mapping names into the specified array_list_t
|
||||
*/
|
||||
void input_mapping_get_names( array_list_t *list );
|
||||
|
||||
/**
|
||||
Sets the application keybindings
|
||||
*/
|
||||
void input_set_application( wchar_t *name );
|
||||
Erase binding for specified key sequence
|
||||
*/
|
||||
int input_mapping_erase( const wchar_t *sequence );
|
||||
|
||||
/**
|
||||
Parse a single line of inputrc information.
|
||||
*/
|
||||
void input_parse_inputrc_line( wchar_t *cmd );
|
||||
Return the command bound to the specified key sequence
|
||||
*/
|
||||
const wchar_t *input_mapping_get( const wchar_t *sequence );
|
||||
|
||||
/**
|
||||
Returns the function for the given function name.
|
||||
Return the sequence for the terminfo variable of the specified name.
|
||||
|
||||
If no terminfo variable of the specified name could be found, return 0 and set errno to ENOENT.
|
||||
If the terminfo variable does not have a value, return 0 and set errno to EILSEQ.
|
||||
*/
|
||||
const wchar_t *input_terminfo_get_sequence( const wchar_t *name );
|
||||
|
||||
/**
|
||||
Return the name of the terminfo variable with the specified sequence
|
||||
*/
|
||||
const wchar_t *input_terminfo_get_name( const wchar_t *seq );
|
||||
|
||||
/**
|
||||
Return a list of all known terminfo names
|
||||
*/
|
||||
void input_terminfo_get_names( array_list_t *lst, int skip_null );
|
||||
|
||||
|
||||
/**
|
||||
Returns the input function code for the given input function name.
|
||||
*/
|
||||
wchar_t input_get_code( const wchar_t *name );
|
||||
wchar_t input_function_get_code( const wchar_t *name );
|
||||
|
||||
/**
|
||||
Returns a list of all existing input function names
|
||||
*/
|
||||
void input_function_get_names( array_list_t *lst );
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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 \e 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
|
||||
|
||||
5
io.h
5
io.h
@@ -44,6 +44,9 @@ typedef struct io_data
|
||||
} param2
|
||||
;
|
||||
|
||||
/**
|
||||
Set to true if this is an input io redirection
|
||||
*/
|
||||
int is_input;
|
||||
|
||||
/** Pointer to the next IO redirection */
|
||||
@@ -68,7 +71,7 @@ io_data_t *io_remove( io_data_t *list, io_data_t *element );
|
||||
io_data_t *io_duplicate( void *context, io_data_t *l );
|
||||
|
||||
/**
|
||||
Return the last io redirection in ht e chain for the specified file descriptor.
|
||||
Return the last io redirection in the chain for the specified file descriptor.
|
||||
*/
|
||||
io_data_t *io_get( io_data_t *io, int fd );
|
||||
|
||||
|
||||
4
kill.c
4
kill.c
@@ -96,7 +96,7 @@ void kill_add( wchar_t *str )
|
||||
if( (disp = env_get( L"DISPLAY" )) )
|
||||
{
|
||||
wchar_t *escaped_str = escape( str, 1 );
|
||||
wchar_t *cmd = wcsdupcat2(L"echo ", escaped_str, L"|xsel -b",(void *)0);
|
||||
wchar_t *cmd = wcsdupcat(L"echo ", escaped_str, L"|xsel -b" );
|
||||
if( exec_subshell( cmd, 0 ) == -1 )
|
||||
{
|
||||
/*
|
||||
@@ -211,7 +211,7 @@ static void kill_check_x_buffer()
|
||||
else
|
||||
{
|
||||
wchar_t *old = new_cut_buffer;
|
||||
new_cut_buffer= wcsdupcat2( new_cut_buffer, L"\\n", next_line, (void *)0 );
|
||||
new_cut_buffer= wcsdupcat( new_cut_buffer, L"\\n", next_line );
|
||||
free( old );
|
||||
free( next_line );
|
||||
}
|
||||
|
||||
@@ -4,85 +4,155 @@ import sys
|
||||
import commands
|
||||
import re
|
||||
|
||||
# Regexes for performing cleanup
|
||||
|
||||
cl = { re.compile(r"-[ \t]*\n[ \t\r]+" ):"",
|
||||
re.compile(r"[ \n\t\r]+", re.MULTILINE):" ",
|
||||
re.compile(r"^[ \n\t\r]"):"",
|
||||
re.compile(r"[ \n\t\r]$"):"" }
|
||||
|
||||
def header(cmd):
|
||||
print '''#
|
||||
# Command specific completions for the %s command.
|
||||
# These completions where generated from the commands
|
||||
# man page by the make_completions.py script, but may
|
||||
# have been hand edited since.
|
||||
#
|
||||
''' % (cmd)
|
||||
|
||||
def up_first(s):
|
||||
return s[0].upper() + s[1:]
|
||||
|
||||
def escape_quotes(s):
|
||||
return re.sub('\'', '\\\'', s)
|
||||
|
||||
def escape(s):
|
||||
return re.sub('([\'"#%*?])', r"\\\1", s)
|
||||
|
||||
def print_completion( cmd, switch_name, desc ):
|
||||
def clean(s):
|
||||
res=s
|
||||
for r, str in cl.items():
|
||||
res = r.sub(str, res)
|
||||
return res
|
||||
|
||||
offset=1
|
||||
switch_type = "o"
|
||||
def print_completion( cmd, switch_arr, arg, desc ):
|
||||
|
||||
if len(switch_name) == 2:
|
||||
switch_type = "s"
|
||||
if len(switch_arr)==0:
|
||||
return
|
||||
|
||||
res = "complete -c %s" % (cmd)
|
||||
for sw in switch_arr:
|
||||
|
||||
offset=1
|
||||
switch_type = "o"
|
||||
|
||||
if len(sw) == 2:
|
||||
switch_type = "s"
|
||||
|
||||
if switch_name[1] == "-":
|
||||
switch_type = "l"
|
||||
offset=2
|
||||
if sw[1] == "-":
|
||||
switch_type = "l"
|
||||
offset=2
|
||||
|
||||
print "complete -c %s -%s %s --description '%s'" % (cmd, switch_type, escape( switch_name[offset:] ), escape_quotes(desc))
|
||||
|
||||
def clean_whitespace( str ):
|
||||
clean_whitespace_prog0 = re.compile( r"-[ \t]*\n[ \t\r]+" )
|
||||
clean_whitespace_prog1 = re.compile( r"[ \n\t]+" )
|
||||
clean_whitespace_prog2 = re.compile( r"^[ \t\r]*", re.MULTILINE )
|
||||
str = clean_whitespace_prog0.sub( "", str )
|
||||
str = clean_whitespace_prog1.sub( " ", str )
|
||||
str = clean_whitespace_prog2.sub( "", str )
|
||||
return str
|
||||
res += " -%s %s" % (switch_type, escape(sw[offset:]))
|
||||
|
||||
res += " --description '%s'" % (up_first(escape_quotes(clean(desc))))
|
||||
|
||||
print res
|
||||
|
||||
cmd = sys.argv[1]
|
||||
|
||||
header(cmd)
|
||||
|
||||
man = commands.getoutput( "man %s | col -b" % cmd )
|
||||
|
||||
remainder = man
|
||||
|
||||
re1 = r"\n( *-[^ ,]* *(|\n))+[^.]+"
|
||||
prog1 = re.compile(re1, re.MULTILINE)
|
||||
MODE_NONE = 0
|
||||
MODE_SWITCH = 1
|
||||
MODE_BETWEEN = 2
|
||||
MODE_BETWEEN_IGNORE = 3
|
||||
MODE_DESC = 4
|
||||
|
||||
re2 = r"^(|=[^ ]*)( |\n)*(?P<switch>-[^ =./\n]+)( *[^-\n ]*\n|)"
|
||||
prog2 = re.compile(re2, re.MULTILINE)
|
||||
mode = MODE_NONE
|
||||
pos = 0
|
||||
sw=''
|
||||
sw_arr=[]
|
||||
switch_end="= \t\n[,"
|
||||
switch_between_ignore="[="
|
||||
switch_between_continue=" \t\n|"
|
||||
before_switch=" \t\r"
|
||||
between_ignore=" \t\n]"
|
||||
pc=False
|
||||
desc=''
|
||||
|
||||
while True:
|
||||
can_be_switch =True
|
||||
|
||||
match = prog1.search( remainder )
|
||||
for c in man:
|
||||
|
||||
if match == None:
|
||||
break
|
||||
if mode == MODE_NONE:
|
||||
if c == '-' and can_be_switch:
|
||||
mode = MODE_SWITCH
|
||||
sw = '-'
|
||||
|
||||
# print "yay match!!!\n"
|
||||
str = match.string[match.start():match.end()]
|
||||
elif c == '\n':
|
||||
can_be_switch = True
|
||||
elif before_switch.find(c)<0:
|
||||
can_be_switch = False
|
||||
|
||||
|
||||
# print str
|
||||
elif mode == MODE_SWITCH:
|
||||
if not switch_end.find(c)>=0:
|
||||
sw+=c
|
||||
else:
|
||||
if len(sw) > 1:
|
||||
sw_arr.append(sw)
|
||||
|
||||
if switch_between_ignore.find(c) >= 0:
|
||||
mode=MODE_BETWEEN_IGNORE
|
||||
else:
|
||||
mode=MODE_BETWEEN
|
||||
# print "End of switch argumnt", sw, "switch to between mode"
|
||||
sw=''
|
||||
|
||||
rem2 = str
|
||||
elif mode == MODE_BETWEEN:
|
||||
if c == '-':
|
||||
mode = MODE_SWITCH
|
||||
sw = '-'
|
||||
elif switch_between_ignore.find(c) >= 0:
|
||||
mode = MODE_BETWEEN_IGNORE
|
||||
# print "Found character", c, "switching to ignore mode"
|
||||
elif not switch_between_continue.find(c) >= 0:
|
||||
mode = MODE_DESC
|
||||
desc = c
|
||||
|
||||
elif mode == MODE_BETWEEN_IGNORE:
|
||||
if between_ignore.find(c)>=0:
|
||||
mode = MODE_BETWEEN
|
||||
|
||||
switch = []
|
||||
elif mode == MODE_DESC:
|
||||
|
||||
while True:
|
||||
match2 = prog2.search( rem2 )
|
||||
stop = False
|
||||
|
||||
if match2 == None:
|
||||
break
|
||||
if c == '.':
|
||||
stop = True
|
||||
|
||||
sw = match2.expand( r"\g<switch>" )
|
||||
# print "yay switch %s!!!\n" %sw
|
||||
if c == '\n' and pc == '\n':
|
||||
stop=True
|
||||
|
||||
switch.append( sw )
|
||||
if stop:
|
||||
mode=MODE_NONE
|
||||
|
||||
print_completion( cmd, sw_arr, None, desc )
|
||||
|
||||
rem2 = rem2[match2.end():]
|
||||
sw_arr = []
|
||||
|
||||
desc = clean_whitespace(rem2)
|
||||
desc = ''
|
||||
|
||||
else:
|
||||
desc += c
|
||||
|
||||
if len( desc) > 8:
|
||||
|
||||
# print "Yay desc '%s'!!\n" % desc
|
||||
|
||||
for i in switch:
|
||||
print_completion( cmd, i, desc )
|
||||
|
||||
|
||||
remainder = remainder[match.end():]
|
||||
else:
|
||||
print "Unknown mode", mode
|
||||
|
||||
pc = c
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env fish
|
||||
|
||||
#
|
||||
# This file produces command specific completions for either hg or darcs
|
||||
# This file produces command specific completions for hg, darcs and a
|
||||
# few other vcs systems. It uses the fact that all these systems have a
|
||||
# somewhat uniform command line help mechanism.
|
||||
#
|
||||
|
||||
function cap
|
||||
@@ -9,8 +10,12 @@ function cap
|
||||
echo $res
|
||||
end
|
||||
|
||||
#
|
||||
# Escapes the single quote (') character and removes trailing whitespace from $argv
|
||||
#
|
||||
|
||||
function esc
|
||||
echo $argv | sed -e "s/'/\\\'/g"
|
||||
echo $argv | sed -e "s/\(['\\\]\)/\\\\\1/g" | sed -e 's/ *$//' | sed -e 's/ .*//'
|
||||
end
|
||||
|
||||
|
||||
@@ -70,7 +75,13 @@ function complete_from_list
|
||||
|
||||
case '?*'
|
||||
set str $str -x
|
||||
echo "Don't know how to handle arguments of type '$arg'" >&2
|
||||
if not set -q unknown
|
||||
set -g unknown
|
||||
end
|
||||
if not contains $arg $unknown
|
||||
echo "Don't know how to handle arguments of type '$arg'" >&2
|
||||
set unknown $unknown $arg
|
||||
end
|
||||
end
|
||||
|
||||
switch $desc
|
||||
@@ -85,39 +96,44 @@ function complete_from_list
|
||||
end
|
||||
|
||||
|
||||
set cmd $argv[1]; or exit 1
|
||||
function write_completions
|
||||
|
||||
echo '
|
||||
set -g cmd $argv[1]; or return 1
|
||||
|
||||
echo "Making completions for $cmd" >&2
|
||||
|
||||
|
||||
echo '
|
||||
#
|
||||
# Completions for the '$cmd' command
|
||||
# This file was autogenerated by the file make_mercurial_completions.fish
|
||||
# which is shipped with the fish source code
|
||||
# This file was autogenerated by the file make_vcs_completions.fish
|
||||
# which is shipped with the fish source code.
|
||||
#
|
||||
|
||||
#
|
||||
# Completions from commandline
|
||||
#
|
||||
'
|
||||
set -e argv[1]
|
||||
set -e argv[1]
|
||||
|
||||
while count $argv >/dev/null
|
||||
echo $argv[1]
|
||||
set -e argv[1]
|
||||
end
|
||||
while count $argv >/dev/null
|
||||
echo $argv[1]
|
||||
set -e argv[1]
|
||||
end
|
||||
|
||||
|
||||
eval "function cmd; $cmd \$argv; end"
|
||||
eval "function cmd; $cmd \$argv; end"
|
||||
|
||||
set -l cmd_str
|
||||
set -l cmd_str
|
||||
|
||||
switch $cmd
|
||||
case svn
|
||||
switch $cmd
|
||||
case svn
|
||||
|
||||
function list_subcommand
|
||||
set cmd1 '\([^ ]*\)'
|
||||
set cmd2 '\([^,)]*\)'
|
||||
set cmdn '\(, \([^,)]*\)\|\)'
|
||||
set svn_re '^ *'$cmd1'\( ('$cmd2$cmdn$cmdn')\|\).*$'
|
||||
set svn_re '^ *'$cmd1'\( ('$cmd2$cmdn$cmdn')\|\).*$'
|
||||
cmd help|sed -ne 's/'$svn_re'/\1\n\3\n\5\n\7/p'| grep .
|
||||
end
|
||||
|
||||
@@ -130,23 +146,23 @@ switch $cmd
|
||||
cmd help $argv | sed -n -e 's/'$re'/\1\t\2\t\3\t\5/p'
|
||||
end
|
||||
|
||||
|
||||
for i in (list_subcommand)
|
||||
set desc (cmd help $i|head -n 1|sed -e 's/[^:]*: *\(.*[^.]\)\(\|\\.\)$/\1/')
|
||||
|
||||
set desc (cmd help $i|head -n 3| sed -e 's/usage:.*//'| tr \n \ | sed -e 's/[^:]*: *\(.*[^.]\)\(\|\\.\)$/\1/')
|
||||
set desc (esc $desc)
|
||||
set cmd_str $cmd_str "-a $i --description '$desc'"
|
||||
end
|
||||
|
||||
case cvs
|
||||
case cvs
|
||||
|
||||
function list_subcommand
|
||||
cmd --help-commands 2>| sed -n -e 's/^ *\([^ ][^ ]*\) .*$/\1/p'
|
||||
cmd --help-commands 2>| sed -n -e 's/^ *\([^ ][^ ]*\) .*$/\1/p'
|
||||
end
|
||||
|
||||
set short_exp '\(-.\)'
|
||||
set arg_exp '\(\| [^ \t][^ \t]*\)'
|
||||
set desc_exp '\([\t ]*:[\t ]*\|\)\([^ ].*\)'
|
||||
set re '^[ \t]*'$short_exp$arg_exp'[ \t]*'$desc_exp'$'
|
||||
set -g re '^[ \t]*'$short_exp$arg_exp'[ \t]*'$desc_exp'$'
|
||||
|
||||
function list_subcommand_help
|
||||
#'s/^[ \t]*\(-.\)[ \t]\([^- \t][^ \t]*\)*[ \t]*\([^-].*\)$/\1\t\2\t\3/p'
|
||||
@@ -168,44 +184,54 @@ switch $cmd
|
||||
set cmd_str $cmd_str "-a $exploded[1] --description '"(esc $exploded[2])"'"
|
||||
end
|
||||
|
||||
case '*'
|
||||
case '*'
|
||||
|
||||
function list_subcommand
|
||||
cmd help | sed -n -e 's/^ *\([^ ][^ ]*\) .*$/\1/p'
|
||||
cmd help | sed -n -e 's/^ *\([^ ][^ ]*\) .*$/\1/p'
|
||||
end
|
||||
|
||||
function list_subcommand_help
|
||||
set short_exp '\(-.\|\)\( [^ -][^ ]*\|\)'
|
||||
set long_exp '\(--[^ =,]*\)'
|
||||
set arg_exp '\(\|[= ][^ ][^ ]*\)'
|
||||
set desc_exp '\([\t ]*:[\t ]*\|\)\([^ ].*[^.]\)'
|
||||
set re "^ *$short_exp *$long_exp$arg_exp *$desc_exp\(\|\\.\)\$"
|
||||
set -l short_exp '\(-.\|\)\( [^ -][^ ]*\|\)'
|
||||
set -l long_exp '\(--[^ =,]*\)'
|
||||
set -l arg_exp '\(\|[= ][^ ][^ ]*\)'
|
||||
set -l desc_exp '\([\t ]*:[\t ]*\|\)\([^ ].*[^.]\)'
|
||||
set -l re "^ *$short_exp *$long_exp$arg_exp *$desc_exp\(\|\\.\)\$"
|
||||
|
||||
cmd help $argv | sed -n -e 's/'$re'/\1\t\3\t\4\t\6/p'
|
||||
end
|
||||
|
||||
set cmd_str (cmd help | sed -n -e 's/^ *\([^ ][^ ]*\)[\t ]*\([^ ].*[^.]\)\(\|\\.\)$/-a \1 --description \'\2\'/p')
|
||||
|
||||
end
|
||||
|
||||
echo '
|
||||
end
|
||||
|
||||
echo '
|
||||
#
|
||||
# subcommands
|
||||
#
|
||||
'
|
||||
|
||||
printf "complete -c $cmd -n '__fish_use_subcommand' -x %s\n" $cmd_str
|
||||
printf "complete -c $cmd -n '__fish_use_subcommand' -x %s\n" $cmd_str
|
||||
|
||||
for i in (list_subcommand)
|
||||
for i in (list_subcommand)
|
||||
|
||||
echo '
|
||||
echo '
|
||||
|
||||
#
|
||||
# Completions for the \''$i'\' subcommand
|
||||
#
|
||||
'
|
||||
|
||||
complete_from_list "-n 'contains \\'$i\\' (commandline -poc)'" (list_subcommand_help $i)
|
||||
complete_from_list "-n 'contains \\'$i\\' (commandline -poc)'" (list_subcommand_help $i)
|
||||
end
|
||||
|
||||
echo \n\n
|
||||
|
||||
end
|
||||
|
||||
echo \n\n
|
||||
set darcs_comp 'complete -c darcs -n "not __fish_use_subcommand" -a "(test -f _darcs/prefs/repos; and cat _darcs/prefs/repos)" --description "Darcs repo"'
|
||||
set darcs_comp $darcs_comp 'complete -c darcs -a "test predist boringfile binariesfile" -n "contains setpref (commandline -poc)" --description "Set the specified option" -x'
|
||||
|
||||
write_completions darcs $darcs_comp >share/completions/darcs.fish
|
||||
write_completions hg >share/completions/hg.fish
|
||||
write_completions svn >share/completions/svn.fish
|
||||
write_completions cvs >share/completions/cvs.fish
|
||||
73
mimedb.c
73
mimedb.c
@@ -12,7 +12,7 @@ because of the performance implications of parsing xml. The current
|
||||
version only does a simple string search, which is much, much
|
||||
faster but it might fall on it's head.
|
||||
|
||||
This code is Copyright 2005 Axel Liljencrantz.
|
||||
This code is Copyright 2005-2008 Axel Liljencrantz.
|
||||
It is released under the GPL.
|
||||
|
||||
The xdgmime library is dual licensed under LGPL/artistic
|
||||
@@ -66,7 +66,7 @@ license. Read the source code of the library for more information.
|
||||
/**
|
||||
Start tag for langauge-specific comment
|
||||
*/
|
||||
#define START_TAG "<comment *(| +xml:lang *= *(\"%s\"|'%s') *)>"
|
||||
#define START_TAG "<comment( +xml:lang *= *(\"%s\"|'%s'))? *>"
|
||||
|
||||
/**
|
||||
End tab for comment
|
||||
@@ -94,6 +94,17 @@ license. Read the source code of the library for more information.
|
||||
*/
|
||||
#define GETOPT_STRING "tfimdalhv"
|
||||
|
||||
/**
|
||||
Error message if system call goes wrong.
|
||||
*/
|
||||
#define ERROR_SYSTEM "%s: Could not execute command \"%s\"\n"
|
||||
|
||||
/**
|
||||
Exit code if system call goes wrong.
|
||||
*/
|
||||
#define STATUS_ERROR_SYSTEM 1
|
||||
|
||||
|
||||
/**
|
||||
All types of input and output possible
|
||||
*/
|
||||
@@ -418,7 +429,7 @@ static char *get_lang_re()
|
||||
const char *lang = setlocale( LC_MESSAGES, 0 );
|
||||
int close=0;
|
||||
char *out=buff;
|
||||
|
||||
|
||||
if( (1+strlen(lang)*4) >= BUFF_SIZE )
|
||||
{
|
||||
fprintf( stderr, _( "%s: Locale string too long\n"), MIMEDB );
|
||||
@@ -434,11 +445,13 @@ static char *get_lang_re()
|
||||
case '.':
|
||||
case '_':
|
||||
if( close )
|
||||
{
|
||||
*out++ = ')';
|
||||
*out++ = '?';
|
||||
}
|
||||
|
||||
close=1;
|
||||
*out++ = '(';
|
||||
*out++ = '|';
|
||||
*out++ = *lang;
|
||||
break;
|
||||
|
||||
@@ -448,8 +461,12 @@ static char *get_lang_re()
|
||||
}
|
||||
|
||||
if( close )
|
||||
{
|
||||
*out++ = ')';
|
||||
*out++ = '?';
|
||||
}
|
||||
*out++=0;
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
||||
@@ -464,7 +481,7 @@ static char *get_description( const char *mimetype )
|
||||
int fd;
|
||||
struct stat st;
|
||||
char *contents;
|
||||
char *start=0, *stop=0;
|
||||
char *start=0, *stop=0, *best_start=0;
|
||||
|
||||
if( !start_re )
|
||||
{
|
||||
@@ -480,18 +497,32 @@ static char *get_description( const char *mimetype )
|
||||
start_re = my_malloc( sizeof(regex_t));
|
||||
stop_re = my_malloc( sizeof(regex_t));
|
||||
|
||||
if( regcomp( start_re, buff, REG_EXTENDED ) ||
|
||||
regcomp( stop_re, STOP_TAG, REG_EXTENDED ) )
|
||||
{
|
||||
fprintf( stderr, _( "%s: Could not compile regular expressions\n"), MIMEDB );
|
||||
int reg_status;
|
||||
if( ( reg_status = regcomp( start_re, buff, REG_EXTENDED ) ) )
|
||||
{
|
||||
char regerrbuf[BUFF_SIZE];
|
||||
regerror(reg_status, start_re, regerrbuf, BUFF_SIZE);
|
||||
fprintf( stderr, _( "%s: Could not compile regular expressions %s with error %s\n"), MIMEDB, buff, regerrbuf);
|
||||
error=1;
|
||||
|
||||
}
|
||||
else if ( ( reg_status = regcomp( stop_re, STOP_TAG, REG_EXTENDED ) ) )
|
||||
{
|
||||
char regerrbuf[BUFF_SIZE];
|
||||
regerror(reg_status, stop_re, regerrbuf, BUFF_SIZE);
|
||||
fprintf( stderr, _( "%s: Could not compile regular expressions %s with error %s\n"), MIMEDB, buff, regerrbuf);
|
||||
error=1;
|
||||
|
||||
}
|
||||
|
||||
if( error )
|
||||
{
|
||||
free( start_re );
|
||||
free( stop_re );
|
||||
start_re = stop_re = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn_part = my_malloc( strlen(MIME_DIR) + strlen( mimetype) + strlen(MIME_SUFFIX) + 1 );
|
||||
@@ -563,6 +594,7 @@ static char *get_description( const char *mimetype )
|
||||
while( !regexec(start_re, start, 1, match, 0) )
|
||||
{
|
||||
int new_w = match[0].rm_eo - match[0].rm_so;
|
||||
start += match[0].rm_eo;
|
||||
|
||||
if( new_w > w )
|
||||
{
|
||||
@@ -571,12 +603,13 @@ static char *get_description( const char *mimetype )
|
||||
match, so we use the new match
|
||||
*/
|
||||
w=new_w;
|
||||
start += match[0].rm_eo;
|
||||
best_start = start;
|
||||
}
|
||||
}
|
||||
|
||||
if( w != -1 )
|
||||
{
|
||||
start = best_start;
|
||||
if( !regexec(stop_re, start, 1, match, 0) )
|
||||
{
|
||||
/*
|
||||
@@ -645,7 +678,7 @@ static char *get_action( const char *mimetype )
|
||||
Core 3) we also test some common subclassings.
|
||||
*/
|
||||
|
||||
if( strncmp( mimetype, "text/", 5 ) == 0 )
|
||||
if( strncmp( mimetype, "text/plain", 10) != 0 && strncmp( mimetype, "text/", 5 ) == 0 )
|
||||
return get_action( "text/plain" );
|
||||
|
||||
return 0;
|
||||
@@ -742,6 +775,7 @@ static void writer_hex( int num )
|
||||
int a, b;
|
||||
a = num /16;
|
||||
b = num %16;
|
||||
|
||||
writer( a>9?('A'+a-10):('0'+a));
|
||||
writer( b>9?('A'+b-10):('0'+b));
|
||||
}
|
||||
@@ -830,7 +864,7 @@ static void write_url( char *file )
|
||||
if( ((*str >= 'a') && (*str <='z')) ||
|
||||
((*str >= 'A') && (*str <='Z')) ||
|
||||
((*str >= '0') && (*str <='9')) ||
|
||||
(strchr( "./_",*str) != 0) )
|
||||
(strchr( "-_.~/",*str) != 0) )
|
||||
{
|
||||
writer(*str);
|
||||
}
|
||||
@@ -842,7 +876,7 @@ static void write_url( char *file )
|
||||
else
|
||||
{
|
||||
writer( '%' );
|
||||
writer_hex( *str );
|
||||
writer_hex( (unsigned char)*str );
|
||||
}
|
||||
str++;
|
||||
}
|
||||
@@ -1104,8 +1138,12 @@ static void launch( char *filter, array_list_t *files, int fileno )
|
||||
writer( '&' );
|
||||
writer( '\0' );
|
||||
|
||||
// fprintf( stderr, "mimedb: %s\n", launch_buff );
|
||||
system( launch_buff );
|
||||
if( system( launch_buff ) == -1 )
|
||||
{
|
||||
fprintf( stderr, _( ERROR_SYSTEM ), MIMEDB, launch_buff );
|
||||
exit(STATUS_ERROR_SYSTEM);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1324,6 +1362,9 @@ int main (int argc, char *argv[])
|
||||
case DESCRIPTION:
|
||||
{
|
||||
output = get_description( mimetype );
|
||||
if( !output )
|
||||
output = strdup( _("Unknown") );
|
||||
|
||||
break;
|
||||
}
|
||||
case ACTION:
|
||||
|
||||
22
output.c
22
output.c
@@ -121,6 +121,12 @@ static char *writestr_buff = 0;
|
||||
|
||||
static int (*out)(char c) = &writeb_internal;
|
||||
|
||||
/**
|
||||
Name of terminal
|
||||
*/
|
||||
static wchar_t *current_term = 0;
|
||||
|
||||
|
||||
/**
|
||||
Cleanup function. Run automatically through halloc
|
||||
*/
|
||||
@@ -356,7 +362,7 @@ void set_color( int c, int c2 )
|
||||
*/
|
||||
static int writeb_internal( char c )
|
||||
{
|
||||
write( 1, &c, 1 );
|
||||
write_loop( 1, &c, 1 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -366,7 +372,7 @@ int writeb( tputs_arg_t b )
|
||||
return 0;
|
||||
}
|
||||
|
||||
int writembs( char *str )
|
||||
int writembs_internal( char *str )
|
||||
{
|
||||
CHECK( str, 1 );
|
||||
|
||||
@@ -580,3 +586,15 @@ int output_color_code( const wchar_t *val )
|
||||
return color | (is_bold?FISH_COLOR_BOLD:0) | (is_underline?FISH_COLOR_UNDERLINE:0);
|
||||
|
||||
}
|
||||
|
||||
void output_set_term( wchar_t *term )
|
||||
{
|
||||
current_term = halloc_wcsdup(global_context, term);
|
||||
}
|
||||
|
||||
wchar_t *output_get_term()
|
||||
{
|
||||
return current_term ? current_term : L"<unknown>";
|
||||
}
|
||||
|
||||
|
||||
|
||||
38
output.h
38
output.h
@@ -73,13 +73,36 @@ enum
|
||||
|
||||
void set_color( int c, int c2 );
|
||||
|
||||
/**
|
||||
Write specified multibyte string
|
||||
*/
|
||||
#define writembs( mbs ) \
|
||||
{ \
|
||||
char *tmp = mbs; \
|
||||
if( tmp ) \
|
||||
{ \
|
||||
writembs_internal( tmp ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
debug( 0, \
|
||||
_(L"Tried to use terminfo string %s on line %d of %s, which is undefined in terminal of type \"%ls\". Please report this error to %s"), \
|
||||
#mbs, \
|
||||
__LINE__, \
|
||||
__FILE__, \
|
||||
output_get_term(), \
|
||||
PACKAGE_BUGREPORT); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Write a char * narrow string to FD 1, needed for the terminfo
|
||||
strings. This is usually just a wrapper aound tputs, using writeb
|
||||
as the sending function. But a weird bug on PPC Linux means that on
|
||||
this platform, write is instead used directly.
|
||||
*/
|
||||
int writembs( char *str );
|
||||
int writembs_internal( char *str );
|
||||
|
||||
/**
|
||||
Write a wide character using the output method specified using output_set_writer().
|
||||
@@ -123,7 +146,18 @@ int writeb( tputs_arg_t b );
|
||||
void output_set_writer( int (*writer)(char) );
|
||||
|
||||
//typedef int (*func_ptr_t)(char);
|
||||
|
||||
/**
|
||||
Return the current output writer
|
||||
*/
|
||||
int (*output_get_writer())(char) ;
|
||||
|
||||
/**
|
||||
Set the terminal name
|
||||
*/
|
||||
void output_set_term( wchar_t *term );
|
||||
/**
|
||||
Return the terminal name
|
||||
*/
|
||||
wchar_t *output_get_term();
|
||||
|
||||
#endif
|
||||
|
||||
112
parse_util.c
112
parse_util.c
@@ -135,6 +135,97 @@ int parse_util_lineno( const wchar_t *str, int len )
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
int parse_util_get_line_from_offset( wchar_t *buff, int pos )
|
||||
{
|
||||
// return parse_util_lineno( buff, pos );
|
||||
|
||||
int i;
|
||||
int count = 0;
|
||||
if( pos < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
for( i=0; i<pos; i++ )
|
||||
{
|
||||
if( !buff[i] )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( buff[i] == L'\n' )
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
int parse_util_get_offset_from_line( wchar_t *buff, int line )
|
||||
{
|
||||
int i;
|
||||
int count = 0;
|
||||
|
||||
if( line < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( line == 0 )
|
||||
return 0;
|
||||
|
||||
for( i=0;; i++ )
|
||||
{
|
||||
if( !buff[i] )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( buff[i] == L'\n' )
|
||||
{
|
||||
count++;
|
||||
if( count == line )
|
||||
{
|
||||
return i+1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int parse_util_get_offset( wchar_t *buff, int line, int line_offset )
|
||||
{
|
||||
int off = parse_util_get_offset_from_line( buff, line );
|
||||
int off2 = parse_util_get_offset_from_line( buff, line+1 );
|
||||
int line_offset2 = line_offset;
|
||||
|
||||
if( off < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( off2 < 0 )
|
||||
{
|
||||
off2 = wcslen( buff )+1;
|
||||
}
|
||||
|
||||
if( line_offset2 < 0 )
|
||||
{
|
||||
line_offset2 = 0;
|
||||
}
|
||||
|
||||
if( line_offset2 >= off2-off-1 )
|
||||
{
|
||||
line_offset2 = off2-off-1;
|
||||
}
|
||||
|
||||
return off + line_offset2;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int parse_util_locate_cmdsubst( const wchar_t *in,
|
||||
wchar_t **begin,
|
||||
wchar_t **end,
|
||||
@@ -923,7 +1014,7 @@ static int parse_util_load_internal( const wchar_t *cmd,
|
||||
struct stat buf;
|
||||
wchar_t *next = (wchar_t *)al_get( path_list, i );
|
||||
sb_clear( path );
|
||||
sb_append2( path, next, L"/", cmd, L".fish", (void *)0 );
|
||||
sb_append( path, next, L"/", cmd, L".fish", (void *)0 );
|
||||
|
||||
if( (wstat( (wchar_t *)path->buff, &buf )== 0) &&
|
||||
(waccess( (wchar_t *)path->buff, R_OK ) == 0) )
|
||||
@@ -1001,7 +1092,7 @@ static int parse_util_load_internal( const wchar_t *cmd,
|
||||
return reloaded;
|
||||
}
|
||||
|
||||
void parse_util_set_argv( wchar_t **argv )
|
||||
void parse_util_set_argv( wchar_t **argv, array_list_t *named_arguments )
|
||||
{
|
||||
if( *argv )
|
||||
{
|
||||
@@ -1025,6 +1116,23 @@ void parse_util_set_argv( wchar_t **argv )
|
||||
{
|
||||
env_set( L"argv", 0, ENV_LOCAL );
|
||||
}
|
||||
|
||||
if( named_arguments )
|
||||
{
|
||||
wchar_t **arg;
|
||||
int i;
|
||||
|
||||
for( i=0, arg=argv; i < al_get_count( named_arguments ); i++ )
|
||||
{
|
||||
env_set( al_get( named_arguments, i ), *arg, ENV_LOCAL );
|
||||
|
||||
if( *arg )
|
||||
arg++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
wchar_t *parse_util_unescape_wildcards( const wchar_t *str )
|
||||
|
||||
21
parse_util.h
21
parse_util.h
@@ -93,6 +93,23 @@ void parse_util_token_extent( const wchar_t *buff,
|
||||
*/
|
||||
int parse_util_lineno( const wchar_t *str, int len );
|
||||
|
||||
/**
|
||||
Calculate the line number of the specified cursor position
|
||||
*/
|
||||
int parse_util_get_line_from_offset( wchar_t *buff, int pos );
|
||||
|
||||
/**
|
||||
Get the offset of the first character on the specified line
|
||||
*/
|
||||
int parse_util_get_offset_from_line( wchar_t *buff, int line );
|
||||
|
||||
|
||||
/**
|
||||
Return the total offset of the buffer for the cursor position nearest to the specified poition
|
||||
*/
|
||||
int parse_util_get_offset( wchar_t *buff, int line, int line_offset );
|
||||
|
||||
|
||||
/**
|
||||
Autoload the specified file, if it exists in the specified path. Do
|
||||
not load it multiple times unless it's timestamp changes or
|
||||
@@ -138,7 +155,7 @@ int parse_util_unload( const wchar_t *cmd,
|
||||
Set the argv environment variable to the specified null-terminated
|
||||
array of strings.
|
||||
*/
|
||||
void parse_util_set_argv( wchar_t **argv );
|
||||
void parse_util_set_argv( wchar_t **argv, array_list_t *named_arguments );
|
||||
|
||||
/**
|
||||
Make a duplicate of the specified string, unescape wildcard
|
||||
@@ -146,4 +163,6 @@ void parse_util_set_argv( wchar_t **argv );
|
||||
*/
|
||||
wchar_t *parse_util_unescape_wildcards( const wchar_t *in );
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
312
parser.c
312
parser.c
@@ -26,6 +26,7 @@ The fish parser. Contains functions for parsing and evaluating code.
|
||||
#include "wutil.h"
|
||||
#include "proc.h"
|
||||
#include "parser.h"
|
||||
#include "parser_keywords.h"
|
||||
#include "tokenizer.h"
|
||||
#include "exec.h"
|
||||
#include "wildcard.h"
|
||||
@@ -188,6 +189,12 @@ The fish parser. Contains functions for parsing and evaluating code.
|
||||
*/
|
||||
#define FOR_BLOCK N_( L"'for' block" )
|
||||
|
||||
/**
|
||||
Breakpoint block
|
||||
*/
|
||||
#define BREAKPOINT_BLOCK N_( L"Block created by breakpoint" )
|
||||
|
||||
|
||||
|
||||
/**
|
||||
If block description
|
||||
@@ -206,6 +213,11 @@ The fish parser. Contains functions for parsing and evaluating code.
|
||||
*/
|
||||
#define FUNCTION_CALL_BLOCK N_( L"function invocation block" )
|
||||
|
||||
/**
|
||||
Function invocation block description
|
||||
*/
|
||||
#define FUNCTION_CALL_NO_SHADOW_BLOCK N_( L"function invocation block with no variable shadowing" )
|
||||
|
||||
|
||||
/**
|
||||
Switch block description
|
||||
@@ -302,6 +314,10 @@ const static struct block_lookup_entry block_lookup[]=
|
||||
FUNCTION_CALL, 0, FUNCTION_CALL_BLOCK
|
||||
}
|
||||
,
|
||||
{
|
||||
FUNCTION_CALL_NO_SHADOW, 0, FUNCTION_CALL_NO_SHADOW_BLOCK
|
||||
}
|
||||
,
|
||||
{
|
||||
SWITCH, L"switch", SWITCH_BLOCK
|
||||
}
|
||||
@@ -331,7 +347,11 @@ const static struct block_lookup_entry block_lookup[]=
|
||||
}
|
||||
,
|
||||
{
|
||||
0,0,0
|
||||
BREAKPOINT, L"breakpoint", BREAKPOINT_BLOCK
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 0, 0
|
||||
}
|
||||
}
|
||||
;
|
||||
@@ -416,6 +436,7 @@ typedef struct
|
||||
/**
|
||||
Return the current number of block nestings
|
||||
*/
|
||||
/*
|
||||
static int block_count( block_t *b )
|
||||
{
|
||||
|
||||
@@ -423,7 +444,7 @@ static int block_count( block_t *b )
|
||||
return 0;
|
||||
return( block_count(b->outer)+1);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
void parser_push_block( int type )
|
||||
{
|
||||
@@ -502,82 +523,17 @@ const wchar_t *parser_get_block_desc( int block )
|
||||
return _(UNKNOWN_BLOCK);
|
||||
}
|
||||
|
||||
/**
|
||||
Check if the specified bcommand is one of the builtins that cannot
|
||||
have arguments, any followin argument is interpreted as a new
|
||||
command
|
||||
*/
|
||||
static int parser_skip_arguments( const wchar_t *cmd )
|
||||
{
|
||||
return contains_str( cmd,
|
||||
L"else",
|
||||
L"begin",
|
||||
(void *)0 );
|
||||
}
|
||||
|
||||
int parser_is_switch( const wchar_t *cmd )
|
||||
{
|
||||
if( wcscmp( cmd, L"--" ) == 0 )
|
||||
return ARG_SKIP;
|
||||
else
|
||||
return cmd[0] == L'-';
|
||||
}
|
||||
|
||||
|
||||
int parser_is_subcommand( const wchar_t *cmd )
|
||||
{
|
||||
|
||||
return parser_skip_arguments( cmd ) ||
|
||||
contains_str( cmd,
|
||||
L"command",
|
||||
L"builtin",
|
||||
L"while",
|
||||
L"exec",
|
||||
L"if",
|
||||
L"and",
|
||||
L"or",
|
||||
L"not",
|
||||
(void *)0 );
|
||||
}
|
||||
|
||||
int parser_is_block( const wchar_t *word)
|
||||
{
|
||||
return contains_str( word,
|
||||
L"for",
|
||||
L"while",
|
||||
L"if",
|
||||
L"function",
|
||||
L"switch",
|
||||
L"begin",
|
||||
(void *)0 );
|
||||
}
|
||||
|
||||
int parser_is_reserved( const wchar_t *word)
|
||||
{
|
||||
return parser_is_block(word) ||
|
||||
parser_is_subcommand( word ) ||
|
||||
contains_str( word,
|
||||
L"end",
|
||||
L"case",
|
||||
L"else",
|
||||
L"return",
|
||||
L"continue",
|
||||
L"break",
|
||||
(void *)0 );
|
||||
}
|
||||
|
||||
/**
|
||||
Returns 1 if the specified command is a builtin that may not be used in a pipeline
|
||||
*/
|
||||
static int parser_is_pipe_forbidden( wchar_t *word )
|
||||
{
|
||||
return contains_str( word,
|
||||
L"exec",
|
||||
L"case",
|
||||
L"break",
|
||||
L"return",
|
||||
L"continue",
|
||||
(void *)0 );
|
||||
return contains( word,
|
||||
L"exec",
|
||||
L"case",
|
||||
L"break",
|
||||
L"return",
|
||||
L"continue" );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -608,7 +564,7 @@ static const wchar_t *parser_find_end( const wchar_t * buff )
|
||||
{
|
||||
count--;
|
||||
}
|
||||
else if( parser_is_block( tok_last(&tok) ) )
|
||||
else if( parser_keywords_is_block( tok_last(&tok) ) )
|
||||
{
|
||||
count++;
|
||||
}
|
||||
@@ -1053,7 +1009,7 @@ void parser_stack_trace( block_t *b, string_buffer_t *buff)
|
||||
|
||||
for( i=1; b->param2.function_call_process->argv[i]; i++ )
|
||||
{
|
||||
sb_append2( &tmp, i>1?L" ":L"", b->param2.function_call_process->argv[i], (void *)0 );
|
||||
sb_append( &tmp, i>1?L" ":L"", b->param2.function_call_process->argv[i], (void *)0 );
|
||||
}
|
||||
sb_printf( buff, _(L"\twith parameter list '%ls'\n"), (wchar_t *)tmp.buff );
|
||||
|
||||
@@ -1354,16 +1310,8 @@ static void parse_job_argument_list( process_t *p,
|
||||
workaround and a huge hack, but as near as I can tell, the
|
||||
alternatives are worse.
|
||||
*/
|
||||
if( p->actual_cmd )
|
||||
{
|
||||
wchar_t *woot = wcsrchr( p->actual_cmd, L'/' );
|
||||
if( !woot )
|
||||
woot = p->actual_cmd;
|
||||
else
|
||||
woot++;
|
||||
proc_is_count = wcscmp( woot, L"count" )==0;
|
||||
}
|
||||
|
||||
proc_is_count = (wcscmp( (wchar_t *)al_get( args, 0 ), L"count" )==0);
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
|
||||
@@ -1454,18 +1402,17 @@ static void parse_job_argument_list( process_t *p,
|
||||
|
||||
if( !skip )
|
||||
{
|
||||
if( proc_is_count &&
|
||||
(al_get_count( args) == 1) &&
|
||||
( parser_is_help( tok_last(tok), 0) ) )
|
||||
if( ( proc_is_count ) &&
|
||||
( al_get_count( args) == 1) &&
|
||||
( parser_is_help( tok_last(tok), 0) ) &&
|
||||
( p->type == INTERNAL_BUILTIN ) )
|
||||
{
|
||||
/*
|
||||
Display help for count
|
||||
*/
|
||||
p->type = INTERNAL_BUILTIN;
|
||||
p->actual_cmd = L"count";
|
||||
p->count_help_magic = 1;
|
||||
}
|
||||
|
||||
|
||||
switch( expand_string( j, wcsdup(tok_last( tok )), args, 0 ) )
|
||||
{
|
||||
case EXPAND_ERROR:
|
||||
@@ -1474,9 +1421,9 @@ static void parse_job_argument_list( process_t *p,
|
||||
if( error_code == 0 )
|
||||
{
|
||||
error( SYNTAX_ERROR,
|
||||
tok_get_pos( tok ),
|
||||
_(L"Could not expand string '%ls'"),
|
||||
tok_last(tok) );
|
||||
tok_get_pos( tok ),
|
||||
_(L"Could not expand string '%ls'"),
|
||||
tok_last(tok) );
|
||||
|
||||
}
|
||||
break;
|
||||
@@ -1516,6 +1463,7 @@ static void parse_job_argument_list( process_t *p,
|
||||
case TOK_REDIRECT_IN:
|
||||
case TOK_REDIRECT_APPEND:
|
||||
case TOK_REDIRECT_FD:
|
||||
case TOK_REDIRECT_NOCLOB:
|
||||
{
|
||||
int type = tok_last_type( tok );
|
||||
io_data_t *new_io;
|
||||
@@ -1611,6 +1559,12 @@ static void parse_job_argument_list( process_t *p,
|
||||
new_io->param1.filename = target;
|
||||
break;
|
||||
|
||||
case TOK_REDIRECT_NOCLOB:
|
||||
new_io->io_mode = IO_FILE;
|
||||
new_io->param2.flags = O_CREAT | O_EXCL | O_WRONLY;
|
||||
new_io->param1.filename = target;
|
||||
break;
|
||||
|
||||
case TOK_REDIRECT_IN:
|
||||
new_io->io_mode = IO_FILE;
|
||||
new_io->param2.flags = O_RDONLY;
|
||||
@@ -1817,14 +1771,13 @@ static int parse_job( process_t *p,
|
||||
|
||||
mark = tok_get_pos( tok );
|
||||
|
||||
if( contains_str( nxt,
|
||||
L"command",
|
||||
L"builtin",
|
||||
L"not",
|
||||
L"and",
|
||||
L"or",
|
||||
L"exec",
|
||||
(void *)0 ) )
|
||||
if( contains( nxt,
|
||||
L"command",
|
||||
L"builtin",
|
||||
L"not",
|
||||
L"and",
|
||||
L"or",
|
||||
L"exec" ) )
|
||||
{
|
||||
int sw;
|
||||
int is_exec = (wcscmp( L"exec", nxt )==0);
|
||||
@@ -1839,7 +1792,7 @@ static int parse_job( process_t *p,
|
||||
}
|
||||
|
||||
tok_next( tok );
|
||||
sw = parser_is_switch( tok_last( tok ) );
|
||||
sw = parser_keywords_is_switch( tok_last( tok ) );
|
||||
|
||||
if( sw == ARG_SWITCH )
|
||||
{
|
||||
@@ -2002,7 +1955,7 @@ static int parse_job( process_t *p,
|
||||
builtin_exists( (wchar_t *)al_get( args, 0 ) ) )
|
||||
{
|
||||
p->type = INTERNAL_BUILTIN;
|
||||
is_new_block |= parser_is_block( (wchar_t *)al_get( args, 0 ) );
|
||||
is_new_block |= parser_keywords_is_block( (wchar_t *)al_get( args, 0 ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2018,7 +1971,10 @@ static int parse_job( process_t *p,
|
||||
}
|
||||
else
|
||||
{
|
||||
int err;
|
||||
|
||||
p->actual_cmd = path_get_path( j, (wchar_t *)al_get( args, 0 ) );
|
||||
err = errno;
|
||||
|
||||
/*
|
||||
Check if the specified command exists
|
||||
@@ -2110,11 +2066,17 @@ static int parse_job( process_t *p,
|
||||
cmd,
|
||||
cmd );
|
||||
}
|
||||
else if( err!=ENOENT )
|
||||
{
|
||||
debug( 0,
|
||||
_(L"The file '%ls' is not executable by this user"),
|
||||
cmd?cmd:L"UNKNOWN" );
|
||||
}
|
||||
else
|
||||
{
|
||||
debug( 0,
|
||||
_(L"Unknown command '%ls'"),
|
||||
cmd );
|
||||
cmd?cmd:L"UNKNOWN" );
|
||||
}
|
||||
|
||||
tmp = current_tokenizer_pos;
|
||||
@@ -2125,7 +2087,8 @@ static int parse_job( process_t *p,
|
||||
current_tokenizer_pos=tmp;
|
||||
|
||||
job_set_flag( j, JOB_SKIP, 1 );
|
||||
proc_set_last_status( STATUS_UNKNOWN_COMMAND );
|
||||
event_fire_generic(L"fish_command_not_found", (wchar_t *)al_get( args, 0 ) );
|
||||
proc_set_last_status( err==ENOENT?STATUS_UNKNOWN_COMMAND:STATUS_NOT_EXECUTABLE );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2156,79 +2119,83 @@ static int parse_job( process_t *p,
|
||||
BLOCK_END_ERR_MSG );
|
||||
|
||||
}
|
||||
|
||||
if( !make_sub_block )
|
||||
else
|
||||
{
|
||||
int done=0;
|
||||
|
||||
for( tok_init( &subtok, end, 0 );
|
||||
!done && tok_has_next( &subtok );
|
||||
tok_next( &subtok ) )
|
||||
if( !make_sub_block )
|
||||
{
|
||||
|
||||
switch( tok_last_type( &subtok ) )
|
||||
int done=0;
|
||||
|
||||
for( tok_init( &subtok, end, 0 );
|
||||
!done && tok_has_next( &subtok );
|
||||
tok_next( &subtok ) )
|
||||
{
|
||||
case TOK_END:
|
||||
done = 1;
|
||||
break;
|
||||
|
||||
switch( tok_last_type( &subtok ) )
|
||||
{
|
||||
case TOK_END:
|
||||
done = 1;
|
||||
break;
|
||||
|
||||
case TOK_REDIRECT_OUT:
|
||||
case TOK_REDIRECT_APPEND:
|
||||
case TOK_REDIRECT_IN:
|
||||
case TOK_REDIRECT_FD:
|
||||
case TOK_PIPE:
|
||||
{
|
||||
done = 1;
|
||||
make_sub_block = 1;
|
||||
break;
|
||||
}
|
||||
case TOK_REDIRECT_OUT:
|
||||
case TOK_REDIRECT_NOCLOB:
|
||||
case TOK_REDIRECT_APPEND:
|
||||
case TOK_REDIRECT_IN:
|
||||
case TOK_REDIRECT_FD:
|
||||
case TOK_PIPE:
|
||||
{
|
||||
done = 1;
|
||||
make_sub_block = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
case TOK_STRING:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case TOK_STRING:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
done = 1;
|
||||
error( SYNTAX_ERROR,
|
||||
current_tokenizer_pos,
|
||||
BLOCK_END_ERR_MSG );
|
||||
default:
|
||||
{
|
||||
done = 1;
|
||||
error( SYNTAX_ERROR,
|
||||
current_tokenizer_pos,
|
||||
BLOCK_END_ERR_MSG );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tok_destroy( &subtok );
|
||||
tok_destroy( &subtok );
|
||||
}
|
||||
|
||||
if( make_sub_block )
|
||||
{
|
||||
|
||||
int end_pos = end-tok_string( tok );
|
||||
wchar_t *sub_block= halloc_wcsndup( j,
|
||||
tok_string( tok ) + current_tokenizer_pos,
|
||||
end_pos - current_tokenizer_pos);
|
||||
|
||||
p->type = INTERNAL_BLOCK;
|
||||
al_set( args, 0, sub_block );
|
||||
|
||||
tok_set_pos( tok,
|
||||
end_pos );
|
||||
|
||||
while( prev_block != current_block )
|
||||
{
|
||||
parser_pop_block();
|
||||
}
|
||||
|
||||
}
|
||||
else tok_next( tok );
|
||||
}
|
||||
|
||||
if( make_sub_block )
|
||||
{
|
||||
|
||||
int end_pos = end-tok_string( tok );
|
||||
wchar_t *sub_block= halloc_wcsndup( j,
|
||||
tok_string( tok ) + current_tokenizer_pos,
|
||||
end_pos - current_tokenizer_pos);
|
||||
|
||||
p->type = INTERNAL_BLOCK;
|
||||
al_set( args, 0, sub_block );
|
||||
|
||||
tok_set_pos( tok,
|
||||
end_pos );
|
||||
|
||||
while( prev_block != current_block )
|
||||
{
|
||||
parser_pop_block();
|
||||
}
|
||||
|
||||
}
|
||||
else tok_next( tok );
|
||||
|
||||
}
|
||||
else tok_next( tok );
|
||||
|
||||
if( !error_code )
|
||||
{
|
||||
if( p->type == INTERNAL_BUILTIN && parser_skip_arguments( (wchar_t *)al_get(args, 0) ) )
|
||||
if( p->type == INTERNAL_BUILTIN && parser_keywords_skip_arguments( (wchar_t *)al_get(args, 0) ) )
|
||||
{
|
||||
if( !p->argv )
|
||||
halloc_register( j, p->argv = list_to_char_arr( args ) );
|
||||
@@ -2995,9 +2962,8 @@ int parser_test( const wchar_t * buff,
|
||||
command is needed, such as after 'and' or
|
||||
'while'
|
||||
*/
|
||||
if( contains_str( cmd,
|
||||
L"end",
|
||||
(void *)0 ) )
|
||||
if( contains( cmd,
|
||||
L"end" ) )
|
||||
{
|
||||
err=1;
|
||||
if( out )
|
||||
@@ -3038,7 +3004,7 @@ int parser_test( const wchar_t * buff,
|
||||
/*
|
||||
Handle block commands
|
||||
*/
|
||||
if( parser_is_block( cmd ) )
|
||||
if( parser_keywords_is_block( cmd ) )
|
||||
{
|
||||
if( count >= BLOCK_MAX_COUNT )
|
||||
{
|
||||
@@ -3059,21 +3025,20 @@ int parser_test( const wchar_t * buff,
|
||||
}
|
||||
|
||||
/*
|
||||
If parser_is_subcommand is true, the command
|
||||
If parser_keywords_is_subcommand is true, the command
|
||||
accepts a second command as it's first
|
||||
argument. If parser_skip_arguments is true, the
|
||||
second argument is optional.
|
||||
*/
|
||||
if( parser_is_subcommand( cmd ) && !parser_skip_arguments(cmd ) )
|
||||
if( parser_keywords_is_subcommand( cmd ) && !parser_keywords_skip_arguments(cmd ) )
|
||||
{
|
||||
needs_cmd = 1;
|
||||
had_cmd = 0;
|
||||
}
|
||||
|
||||
if( contains_str( cmd,
|
||||
L"or",
|
||||
L"and",
|
||||
(void *)0 ) )
|
||||
if( contains( cmd,
|
||||
L"or",
|
||||
L"and" ) )
|
||||
{
|
||||
/*
|
||||
'or' and 'and' can not be used inside pipelines
|
||||
@@ -3205,7 +3170,7 @@ int parser_test( const wchar_t * buff,
|
||||
/*
|
||||
Test that break and continue are only used within loop blocks
|
||||
*/
|
||||
if( contains_str( cmd, L"break", L"continue", (void *)0 ) )
|
||||
if( contains( cmd, L"break", L"continue" ) )
|
||||
{
|
||||
int found_loop=0;
|
||||
int i;
|
||||
@@ -3377,6 +3342,7 @@ int parser_test( const wchar_t * buff,
|
||||
case TOK_REDIRECT_IN:
|
||||
case TOK_REDIRECT_APPEND:
|
||||
case TOK_REDIRECT_FD:
|
||||
case TOK_REDIRECT_NOCLOB:
|
||||
{
|
||||
if( !had_cmd )
|
||||
{
|
||||
|
||||
46
parser.h
46
parser.h
@@ -15,17 +15,6 @@
|
||||
#define PARSER_TEST_ERROR 1
|
||||
#define PARSER_TEST_INCOMPLETE 2
|
||||
|
||||
/**
|
||||
REturn valuse for parser_is_switch()
|
||||
*/
|
||||
enum
|
||||
{
|
||||
ARG_NON_SWITCH,
|
||||
ARG_SWITCH,
|
||||
ARG_SKIP
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
event_block_t represents a block on events of the specified type
|
||||
*/
|
||||
@@ -131,6 +120,7 @@ enum block_type
|
||||
IF, /**< If block */
|
||||
FUNCTION_DEF, /**< Function definition block */
|
||||
FUNCTION_CALL, /**< Function invocation block */
|
||||
FUNCTION_CALL_NO_SHADOW, /**< Function invocation block with no variable shadowing */
|
||||
SWITCH, /**< Switch block */
|
||||
FAKE, /**< Fake block */
|
||||
SUBST, /**< Command substitution scope */
|
||||
@@ -138,6 +128,7 @@ enum block_type
|
||||
BEGIN, /**< Unconditional block */
|
||||
SOURCE, /**< Block created by the . (source) builtin */
|
||||
EVENT, /**< Block created on event notifier invocation */
|
||||
BREAKPOINT, /**< Breakpoint block */
|
||||
}
|
||||
;
|
||||
|
||||
@@ -231,39 +222,6 @@ int eval_args( const wchar_t *line,
|
||||
void error( int ec, int p, const wchar_t *str, ... );
|
||||
|
||||
|
||||
/**
|
||||
Check if the specified argument is a switch. Return ARG_SWITCH if yes,
|
||||
ARG_NON_SWITCH if no and ARG_SKIP if the argument is '--'
|
||||
*/
|
||||
int parser_is_switch( const wchar_t *cmd );
|
||||
|
||||
|
||||
/**
|
||||
Tests if the specified commands parameters should be interpreted as another command, which will be true if the command is either 'command', 'exec', 'if', 'while' or 'builtin'.
|
||||
|
||||
\param cmd The command name to test
|
||||
\return 1 of the command parameter is a command, 0 otherwise
|
||||
*/
|
||||
|
||||
int parser_is_subcommand( const wchar_t *cmd );
|
||||
|
||||
/**
|
||||
Tests if the specified command is a reserved word, i.e. if it is
|
||||
the name of one of the builtin functions that change the block or
|
||||
command scope, like 'for', 'end' or 'command' or 'exec'. These
|
||||
functions may not be overloaded, so their names are reserved.
|
||||
|
||||
\param word The command name to test
|
||||
\return 1 of the command parameter is a command, 0 otherwise
|
||||
*/
|
||||
int parser_is_reserved( const wchar_t *word );
|
||||
|
||||
/**
|
||||
Test if the specified string is command that opens a new block
|
||||
*/
|
||||
|
||||
int parser_is_block( const wchar_t *word);
|
||||
|
||||
/**
|
||||
Returns a string describing the current parser pisition in the format 'FILENAME (line LINE_NUMBER): LINE'.
|
||||
Example:
|
||||
|
||||
72
parser_keywords.c
Normal file
72
parser_keywords.c
Normal file
@@ -0,0 +1,72 @@
|
||||
/** \file parser_keywords.c
|
||||
|
||||
Functions having to do with parser keywords, like testing if a function is a block command.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "fallback.h"
|
||||
#include "common.h"
|
||||
#include "parser_keywords.h"
|
||||
|
||||
|
||||
int parser_keywords_is_switch( const wchar_t *cmd )
|
||||
{
|
||||
if( wcscmp( cmd, L"--" ) == 0 )
|
||||
return ARG_SKIP;
|
||||
else
|
||||
return cmd[0] == L'-';
|
||||
}
|
||||
|
||||
int parser_keywords_skip_arguments( const wchar_t *cmd )
|
||||
{
|
||||
return contains( cmd,
|
||||
L"else",
|
||||
L"begin" );
|
||||
}
|
||||
|
||||
|
||||
int parser_keywords_is_subcommand( const wchar_t *cmd )
|
||||
{
|
||||
|
||||
return parser_keywords_skip_arguments( cmd ) ||
|
||||
contains( cmd,
|
||||
L"command",
|
||||
L"builtin",
|
||||
L"while",
|
||||
L"exec",
|
||||
L"if",
|
||||
L"and",
|
||||
L"or",
|
||||
L"not" );
|
||||
|
||||
}
|
||||
|
||||
int parser_keywords_is_block( const wchar_t *word)
|
||||
{
|
||||
return contains( word,
|
||||
L"for",
|
||||
L"while",
|
||||
L"if",
|
||||
L"function",
|
||||
L"switch",
|
||||
L"begin" );
|
||||
}
|
||||
|
||||
int parser_keywords_is_reserved( const wchar_t *word)
|
||||
{
|
||||
return parser_keywords_is_block(word) ||
|
||||
parser_keywords_is_subcommand( word ) ||
|
||||
contains( word,
|
||||
L"end",
|
||||
L"case",
|
||||
L"else",
|
||||
L"return",
|
||||
L"continue",
|
||||
L"break" );
|
||||
}
|
||||
|
||||
63
parser_keywords.h
Normal file
63
parser_keywords.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/** \file parser_keywords.h
|
||||
|
||||
Functions having to do with parser keywords, like testing if a function is a block command.
|
||||
*/
|
||||
|
||||
#ifndef FISH_PARSER_KEYWORD_H
|
||||
#define FISH_PARSER_KEYWORD_H
|
||||
|
||||
/**
|
||||
Return valuse for parser_keywords_is_switch()
|
||||
*/
|
||||
enum
|
||||
{
|
||||
ARG_NON_SWITCH,
|
||||
ARG_SWITCH,
|
||||
ARG_SKIP
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Check if the specified argument is a switch. Return ARG_SWITCH if yes,
|
||||
ARG_NON_SWITCH if no and ARG_SKIP if the argument is '--'
|
||||
*/
|
||||
int parser_keywords_is_switch( const wchar_t *cmd );
|
||||
|
||||
|
||||
/**
|
||||
Tests if the specified commands parameters should be interpreted as another command, which will be true if the command is either 'command', 'exec', 'if', 'while' or 'builtin'.
|
||||
|
||||
\param cmd The command name to test
|
||||
\return 1 of the command parameter is a command, 0 otherwise
|
||||
*/
|
||||
|
||||
int parser_keywords_is_subcommand( const wchar_t *cmd );
|
||||
|
||||
/**
|
||||
Tests if the specified command is a reserved word, i.e. if it is
|
||||
the name of one of the builtin functions that change the block or
|
||||
command scope, like 'for', 'end' or 'command' or 'exec'. These
|
||||
functions may not be overloaded, so their names are reserved.
|
||||
|
||||
\param word The command name to test
|
||||
\return 1 of the command parameter is a command, 0 otherwise
|
||||
*/
|
||||
int parser_keywords_is_reserved( const wchar_t *word );
|
||||
|
||||
/**
|
||||
Test if the specified string is command that opens a new block
|
||||
*/
|
||||
|
||||
int parser_keywords_is_block( const wchar_t *word);
|
||||
|
||||
/**
|
||||
Check if the specified command is one of the builtins that cannot
|
||||
have arguments, any followin argument is interpreted as a new
|
||||
command
|
||||
*/
|
||||
int parser_keywords_skip_arguments( const wchar_t *cmd );
|
||||
|
||||
|
||||
#endif
|
||||
91
path.c
91
path.c
@@ -31,8 +31,10 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
|
||||
{
|
||||
wchar_t *path;
|
||||
|
||||
int err = ENOENT;
|
||||
|
||||
CHECK( cmd, 0 );
|
||||
|
||||
|
||||
debug( 3, L"path_get_path( '%ls' )", cmd );
|
||||
|
||||
if(wcschr( cmd, L'/' ) != 0 )
|
||||
@@ -40,19 +42,33 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
|
||||
if( waccess( cmd, X_OK )==0 )
|
||||
{
|
||||
struct stat buff;
|
||||
wstat( cmd, &buff );
|
||||
if(wstat( cmd, &buff ))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( S_ISREG(buff.st_mode) )
|
||||
return halloc_wcsdup( context, cmd );
|
||||
else
|
||||
{
|
||||
errno = EACCES;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
struct stat buff;
|
||||
wstat( cmd, &buff );
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
path = env_get(L"PATH");
|
||||
if( path == 0 )
|
||||
{
|
||||
if( contains_str( PREFIX L"/bin", L"/bin", L"/usr/bin", (void *)0 ) )
|
||||
if( contains( PREFIX L"/bin", L"/bin", L"/usr/bin" ) )
|
||||
{
|
||||
path = L"/bin" ARRAY_SEP_STR L"/usr/bin";
|
||||
}
|
||||
@@ -66,6 +82,7 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
|
||||
Allocate string long enough to hold the whole command
|
||||
*/
|
||||
wchar_t *new_cmd = halloc( context, sizeof(wchar_t)*(wcslen(cmd)+wcslen(path)+2) );
|
||||
|
||||
/*
|
||||
We tokenize a copy of the path, since strtok modifies
|
||||
its arguments
|
||||
@@ -106,6 +123,8 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
|
||||
free( path_cpy );
|
||||
return new_cmd;
|
||||
}
|
||||
err = EACCES;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -129,6 +148,8 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
|
||||
free( path_cpy );
|
||||
|
||||
}
|
||||
|
||||
errno = err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -136,7 +157,7 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
|
||||
wchar_t *path_get_cdpath( void *context, wchar_t *dir )
|
||||
{
|
||||
wchar_t *res = 0;
|
||||
|
||||
int err = ENOENT;
|
||||
if( !dir )
|
||||
return 0;
|
||||
|
||||
@@ -150,6 +171,11 @@ wchar_t *path_get_cdpath( void *context, wchar_t *dir )
|
||||
{
|
||||
res = halloc_wcsdup( context, dir );
|
||||
}
|
||||
else
|
||||
{
|
||||
err = ENOTDIR;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -191,9 +217,9 @@ wchar_t *path_get_cdpath( void *context, wchar_t *dir )
|
||||
}
|
||||
|
||||
whole_path =
|
||||
wcsdupcat2( expanded_path,
|
||||
wcsdupcat( expanded_path,
|
||||
( expanded_path[path_len-1] != L'/' )?L"/":L"",
|
||||
dir, (void *)0 );
|
||||
dir );
|
||||
|
||||
free(expanded_path );
|
||||
|
||||
@@ -206,11 +232,29 @@ wchar_t *path_get_cdpath( void *context, wchar_t *dir )
|
||||
halloc_register( context, whole_path );
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = ENOTDIR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( lwstat( whole_path, &buf ) == 0 )
|
||||
{
|
||||
err = EROTTEN;
|
||||
}
|
||||
}
|
||||
|
||||
free( whole_path );
|
||||
}
|
||||
free( path_cpy );
|
||||
}
|
||||
|
||||
if( !res )
|
||||
{
|
||||
errno = err;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -265,3 +309,38 @@ wchar_t *path_get_config( void *context)
|
||||
|
||||
}
|
||||
|
||||
wchar_t *path_make_canonical( void *context, const wchar_t *path )
|
||||
{
|
||||
wchar_t *res = halloc_wcsdup( context, path );
|
||||
wchar_t *in, *out;
|
||||
|
||||
in = out = res;
|
||||
|
||||
while( *in )
|
||||
{
|
||||
if( *in == L'/' )
|
||||
{
|
||||
while( *(in+1) == L'/' )
|
||||
{
|
||||
in++;
|
||||
}
|
||||
}
|
||||
*out = *in;
|
||||
|
||||
out++;
|
||||
in++;
|
||||
}
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
if( out == res )
|
||||
break;
|
||||
if( *(out-1) != L'/' )
|
||||
break;
|
||||
out--;
|
||||
}
|
||||
*out = 0;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
33
path.h
33
path.h
@@ -9,6 +9,11 @@
|
||||
#ifndef FISH_PATH_H
|
||||
#define FISH_PATH_H
|
||||
|
||||
/**
|
||||
Return value for path_cdpath_get when locatied a rotten symlink
|
||||
*/
|
||||
#define EROTTEN 1
|
||||
|
||||
/**
|
||||
Returns the user configuration directory for fish. If the directory
|
||||
or one of it's parents doesn't exist, they are first created.
|
||||
@@ -28,16 +33,32 @@ wchar_t *path_get_config( void *context);
|
||||
wchar_t *path_get_path( void *context, const wchar_t *cmd );
|
||||
|
||||
/**
|
||||
Returns the full path of the specified directory. If the \c in is a
|
||||
full path to an existing directory, a copy of the string is
|
||||
returned. If \c in is a directory relative to one of the
|
||||
directories i the CDPATH, the full path is returned. If no
|
||||
directory can be found, 0 is returned.
|
||||
|
||||
Returns the full path of the specified directory, using the CDPATH
|
||||
variable as a list of base directories for relative paths. The
|
||||
returned string is allocated using halloc and the specified
|
||||
context.
|
||||
|
||||
If no valid path is found, null is returned and errno is set to
|
||||
ENOTDIR if at least one such path was found, but it did not point
|
||||
to a directory, EROTTEN if a arotten symbolic link was found, or
|
||||
ENOENT if no file of the specified name was found. If both a rotten
|
||||
symlink and a file are found, it is undefined which error status
|
||||
will be returned.
|
||||
|
||||
\param in The name of the directory.
|
||||
\param context the halloc context to use for memory allocations
|
||||
\return 0 if the command can not be found, the path of the command otherwise.
|
||||
*/
|
||||
wchar_t *path_get_cdpath( void *context, wchar_t *in );
|
||||
|
||||
/**
|
||||
Remove doulbe slashes and trailing slashes from a path,
|
||||
e.g. transform foo//bar/ into foo/bar.
|
||||
|
||||
The returned string is allocated using the specified halloc
|
||||
context.
|
||||
*/
|
||||
wchar_t *path_make_canonical( void *context, const wchar_t *path );
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
12
print_help.c
12
print_help.c
@@ -5,18 +5,26 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "print_help.h"
|
||||
|
||||
#define CMD_LEN 1024
|
||||
|
||||
#define HELP_ERR "Could not show help message\n"
|
||||
|
||||
void print_help( char *c, int fd )
|
||||
{
|
||||
char cmd[ CMD_LEN];
|
||||
int printed = snprintf( cmd, CMD_LEN, "fish -c '__fish_print_help %s >&%d'", c, fd );
|
||||
|
||||
if( printed < CMD_LEN )
|
||||
system( cmd );
|
||||
{
|
||||
if( (system( cmd ) == -1) )
|
||||
{
|
||||
write_loop(2, HELP_ERR, strlen(HELP_ERR));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
79
proc.c
79
proc.c
@@ -190,7 +190,6 @@ void proc_destroy()
|
||||
void proc_set_last_status( int s )
|
||||
{
|
||||
last_status = s;
|
||||
// debug( 0, L"Set last status to %d\n", s );
|
||||
}
|
||||
|
||||
int proc_get_last_status()
|
||||
@@ -344,30 +343,35 @@ static void mark_process_status( job_t *j,
|
||||
process_t *p,
|
||||
int status )
|
||||
{
|
||||
p->status = status;
|
||||
// debug( 0, L"Process %ls %ls", p->argv[0], WIFSTOPPED (status)?L"stopped":(WIFEXITED( status )?L"exited":(WIFSIGNALED( status )?L"signaled to exit":L"BLARGH")) );
|
||||
p->status = status;
|
||||
|
||||
if (WIFSTOPPED (status))
|
||||
{
|
||||
p->stopped = 1;
|
||||
}
|
||||
else
|
||||
else if (WIFSIGNALED(status) || WIFEXITED(status))
|
||||
{
|
||||
p->completed = 1;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ssize_t ignore;
|
||||
|
||||
if (( !WIFEXITED( status ) ) &&
|
||||
(! WIFSIGNALED( status )) )
|
||||
{
|
||||
/* This should never be reached */
|
||||
char mess[MESS_SIZE];
|
||||
snprintf( mess,
|
||||
MESS_SIZE,
|
||||
"Process %d exited abnormally\n",
|
||||
(int) p->pid );
|
||||
|
||||
write( 2, mess, strlen(mess) );
|
||||
}
|
||||
/* This should never be reached */
|
||||
p->completed = 1;
|
||||
|
||||
char mess[MESS_SIZE];
|
||||
snprintf( mess,
|
||||
MESS_SIZE,
|
||||
"Process %d exited abnormally\n",
|
||||
(int) p->pid );
|
||||
/*
|
||||
If write fails, do nothing. We're in a signal handlers error
|
||||
handler. If things aren't working properly, it's safer to
|
||||
give up.
|
||||
*/
|
||||
ignore = write( 2, mess, strlen(mess) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,7 +493,6 @@ void job_handle_signal ( int signal, siginfo_t *info, void *con )
|
||||
got_signal = 1;
|
||||
|
||||
// write( 2, "got signal\n", 11 );
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
@@ -847,7 +850,6 @@ static void read_try( job_t *j )
|
||||
if( d->io_mode == IO_BUFFER )
|
||||
{
|
||||
buff=d;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -884,6 +886,15 @@ static void read_try( job_t *j )
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Give ownership of the terminal to the specified job.
|
||||
|
||||
\param j The job to give the terminal to.
|
||||
|
||||
\param cont If this variable is set, we are giving back control to
|
||||
a job that has previously been stopped. In that case, we need to
|
||||
set the terminal attributes to those saved in the job.
|
||||
*/
|
||||
static int terminal_give_to_job( job_t *j, int cont )
|
||||
{
|
||||
|
||||
@@ -913,7 +924,9 @@ static int terminal_give_to_job( job_t *j, int cont )
|
||||
}
|
||||
|
||||
/**
|
||||
Returns contol of the terminal to the shell
|
||||
Returns contol of the terminal to the shell, and saves the terminal
|
||||
attribute state to the job, so that we can restore the terminal
|
||||
ownership to the job at a later time .
|
||||
*/
|
||||
static int terminal_return_from_job( job_t *j)
|
||||
{
|
||||
@@ -1033,7 +1046,10 @@ void job_continue (job_t *j, int cont)
|
||||
got_signal = 0;
|
||||
quit = job_is_stopped( j ) || job_is_completed( j );
|
||||
}
|
||||
while( got_signal && !quit );
|
||||
|
||||
while( got_signal && !quit )
|
||||
;
|
||||
|
||||
if( !quit )
|
||||
{
|
||||
|
||||
@@ -1077,7 +1093,6 @@ void job_continue (job_t *j, int cont)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1096,7 +1111,7 @@ void job_continue (job_t *j, int cont)
|
||||
while( p->next )
|
||||
p = p->next;
|
||||
|
||||
if( WIFEXITED( p->status ) )
|
||||
if( WIFEXITED( p->status ) || WIFSIGNALED(p->status))
|
||||
{
|
||||
/*
|
||||
Mark process status only if we are in the foreground
|
||||
@@ -1104,8 +1119,9 @@ void job_continue (job_t *j, int cont)
|
||||
*/
|
||||
if( p->pid )
|
||||
{
|
||||
debug( 3, L"Set status of %ls to %d", j->command, WEXITSTATUS(p->status) );
|
||||
proc_set_last_status( job_get_flag( j, JOB_NEGATE )?(WEXITSTATUS(p->status)?0:1):WEXITSTATUS(p->status) );
|
||||
int status = proc_format_status(p->status);
|
||||
|
||||
proc_set_last_status( job_get_flag( j, JOB_NEGATE )?!status:status);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1130,6 +1146,21 @@ void job_continue (job_t *j, int cont)
|
||||
|
||||
}
|
||||
|
||||
int proc_format_status(int status)
|
||||
{
|
||||
if( WIFSIGNALED( status ) )
|
||||
{
|
||||
return 128+WTERMSIG(status);
|
||||
}
|
||||
else if( WIFEXITED( status ) )
|
||||
{
|
||||
return WEXITSTATUS(status);
|
||||
}
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void proc_sanity_check()
|
||||
{
|
||||
job_t *j;
|
||||
|
||||
102
proc.h
102
proc.h
@@ -25,15 +25,20 @@
|
||||
#define STATUS_UNKNOWN_COMMAND 127
|
||||
|
||||
/**
|
||||
The status code use when a wildcard had no matches
|
||||
The status code use when an unknown error occured during execution of a command
|
||||
*/
|
||||
#define STATUS_UNMATCHED_WILDCARD 126
|
||||
#define STATUS_NOT_EXECUTABLE 126
|
||||
|
||||
/**
|
||||
The status code use when an unknown error occured during execution of a command
|
||||
*/
|
||||
#define STATUS_EXEC_FAIL 125
|
||||
|
||||
/**
|
||||
The status code use when a wildcard had no matches
|
||||
*/
|
||||
#define STATUS_UNMATCHED_WILDCARD 124
|
||||
|
||||
/**
|
||||
The status code used for normal exit in a builtin
|
||||
*/
|
||||
@@ -126,22 +131,34 @@ typedef struct process
|
||||
INTERNAL_EXEC, or INTERNAL_BUFFER
|
||||
*/
|
||||
int type;
|
||||
|
||||
/** argv parameter for for execv, builtin_run, etc. */
|
||||
wchar_t **argv;
|
||||
|
||||
/** actual command to pass to exec in case of EXTERNAL or INTERNAL_EXEC */
|
||||
wchar_t *actual_cmd;
|
||||
|
||||
/** process ID */
|
||||
pid_t pid;
|
||||
|
||||
/** File descriptor that pipe output should bind to */
|
||||
int pipe_write_fd;
|
||||
|
||||
/** File descriptor that the _next_ process pipe input should bind to */
|
||||
int pipe_read_fd;
|
||||
|
||||
/** true if process has completed */
|
||||
volatile int completed;
|
||||
|
||||
/** true if process has stopped */
|
||||
volatile int stopped;
|
||||
|
||||
/** reported status value */
|
||||
volatile int status;
|
||||
|
||||
/** Special flag to tell the evaluation function for count to print the help information */
|
||||
int count_help_magic;
|
||||
|
||||
/** next process in pipeline */
|
||||
struct process *next;
|
||||
#ifdef HAVE__PROC_SELF_STAT
|
||||
@@ -212,24 +229,53 @@ typedef struct process
|
||||
*/
|
||||
#define JOB_TERMINAL 256
|
||||
|
||||
/** A pipeline of one or more processes. */
|
||||
/**
|
||||
A struct represeting a job. A job is basically a pipeline of one
|
||||
or more processes and a couple of flags.
|
||||
*/
|
||||
typedef struct job
|
||||
{
|
||||
/** command line, used for messages */
|
||||
/**
|
||||
The original command which led to the creation of this
|
||||
job. It is used for displaying messages about job status
|
||||
on the terminal.
|
||||
*/
|
||||
wchar_t *command;
|
||||
/** list of processes in this job */
|
||||
|
||||
/**
|
||||
A linked list of all the processes in this job.
|
||||
*/
|
||||
process_t *first_process;
|
||||
/** process group ID */
|
||||
|
||||
/**
|
||||
process group ID for the process group that this job is
|
||||
running in.
|
||||
*/
|
||||
pid_t pgid;
|
||||
/** saved terminal modes */
|
||||
struct termios tmodes;
|
||||
/** The job id of the job*/
|
||||
|
||||
/**
|
||||
The saved terminal modes of this job. This needs to be
|
||||
saved so that we can restore the terminal to the same
|
||||
state after temporarily taking control over the terminal
|
||||
when a job stops.
|
||||
*/
|
||||
struct termios tmodes;
|
||||
|
||||
/**
|
||||
The job id of the job. This is a small integer that is a
|
||||
unique identifier of the job within this shell, and is
|
||||
used e.g. in process expansion.
|
||||
*/
|
||||
int job_id;
|
||||
|
||||
/** List of IO redrections for the job */
|
||||
/**
|
||||
List of all IO redirections for this job
|
||||
*/
|
||||
io_data_t *io;
|
||||
|
||||
/** Pointer to the next job */
|
||||
/**
|
||||
A pointer to the next job in the job queue
|
||||
*/
|
||||
struct job *next;
|
||||
|
||||
/**
|
||||
@@ -266,21 +312,21 @@ extern int is_interactive_session;
|
||||
extern int is_login;
|
||||
|
||||
/**
|
||||
Whether we are a event handler
|
||||
Whether we are running an event handler
|
||||
*/
|
||||
extern int is_event;
|
||||
|
||||
/**
|
||||
Linked list of all jobs
|
||||
Linked list of all living jobs
|
||||
*/
|
||||
extern job_t *first_job;
|
||||
|
||||
/**
|
||||
Whether a universal variable barrier roundtrip has already been
|
||||
made for this command. Such a roundtrip only needs to be done once
|
||||
on a given command, unless a unversal variable value is
|
||||
changed. Once this has been done, this variable is set to 1, so
|
||||
that no more roundtrips need to be done.
|
||||
made for the currently executing command. Such a roundtrip only
|
||||
needs to be done once on a given command, unless a universal
|
||||
variable value is changed. Once this has been done, this variable
|
||||
is set to 1, so that no more roundtrips need to be done.
|
||||
|
||||
Both setting it to one when it should be zero and the opposite may
|
||||
cause concurrency bugs.
|
||||
@@ -293,17 +339,27 @@ extern int proc_had_barrier;
|
||||
extern pid_t proc_last_bg_pid;
|
||||
|
||||
/**
|
||||
Can be one of JOB_CONTROL_ALL, JOB_CONTROL_INTERACTIVE and JOB_CONTROL_NONE
|
||||
The current job control mode.
|
||||
|
||||
Must be one of JOB_CONTROL_ALL, JOB_CONTROL_INTERACTIVE and JOB_CONTROL_NONE
|
||||
*/
|
||||
extern int job_control_mode;
|
||||
|
||||
/**
|
||||
If this flag is set, fish will never fork or run execve.
|
||||
*/
|
||||
If this flag is set, fish will never fork or run execve. It is used
|
||||
to put fish into a syntax verifier mode where fish tries to validate
|
||||
the syntax of a file but doesn't actually do anything.
|
||||
*/
|
||||
extern int no_exec;
|
||||
|
||||
/**
|
||||
Add the specified flag to the bitset of flags for the specified job
|
||||
*/
|
||||
void job_set_flag( job_t *j, int flag, int set );
|
||||
|
||||
/**
|
||||
Returns one if the specified flag is set in the specified job, 0 otherwise.
|
||||
*/
|
||||
int job_get_flag( job_t *j, int flag );
|
||||
|
||||
/**
|
||||
@@ -429,4 +485,10 @@ void proc_push_interactive( int value );
|
||||
*/
|
||||
void proc_pop_interactive();
|
||||
|
||||
/**
|
||||
Format an exit status code as returned by e.g. wait into a fish exit code number as accepted by proc_set_last_status.
|
||||
*/
|
||||
int proc_format_status(int status) ;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
20
reader.h
20
reader.h
@@ -12,11 +12,12 @@
|
||||
#include <wchar.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "io.h"
|
||||
|
||||
/**
|
||||
Read commands from \c fd until encountering EOF
|
||||
*/
|
||||
int reader_read( int fd);
|
||||
int reader_read( int fd, io_data_t *io);
|
||||
|
||||
/**
|
||||
Tell the shell that it should exit after the currently running command finishes.
|
||||
@@ -62,11 +63,10 @@ wchar_t *reader_pop_current_filename();
|
||||
void reader_write_title();
|
||||
|
||||
/**
|
||||
Repaint the entire commandline. This means reset and clear the
|
||||
commandline, write the prompt, perform syntax highlighting, write
|
||||
the commandline and move the cursor.
|
||||
*/
|
||||
void repaint();
|
||||
Call this function to tell the reader that a repaint is needed, and
|
||||
should be performed when possible.
|
||||
*/
|
||||
void reader_repaint_needed();
|
||||
|
||||
/**
|
||||
Run the specified command with the correct terminal modes, and
|
||||
@@ -173,4 +173,12 @@ int reader_exit_forced();
|
||||
*/
|
||||
int reader_shell_test( wchar_t *b );
|
||||
|
||||
/**
|
||||
Test whether the interactive reader is in search mode.
|
||||
|
||||
\return o if not in search mode, 1 if in search mode and -1 if not in interactive mode
|
||||
*/
|
||||
int reader_search_mode();
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user