mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-12 03:41:14 -03:00
Compare commits
490 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
44e8a12b66 | ||
|
|
fe21577a8e | ||
|
|
a4ac924512 | ||
|
|
e936629dc3 | ||
|
|
dfabf7f206 | ||
|
|
7118269e4b | ||
|
|
100355c3c1 | ||
|
|
4b1fced1f8 | ||
|
|
abff4e5b41 | ||
|
|
25082b6528 | ||
|
|
766482d90e | ||
|
|
15e0a44fc7 | ||
|
|
3b653cd26a | ||
|
|
ba6661e9df | ||
|
|
55af8e4966 | ||
|
|
dcad2ef17b | ||
|
|
418192b312 | ||
|
|
76d9051605 | ||
|
|
ca2b2103d3 | ||
|
|
14e6bdb139 | ||
|
|
20d42378de | ||
|
|
41c9f89fcf | ||
|
|
7953863b38 | ||
|
|
3fff030ee2 | ||
|
|
da9f7227f5 | ||
|
|
ba932b6590 | ||
|
|
c02e2b1320 | ||
|
|
37a95a3096 | ||
|
|
bbd229b206 | ||
|
|
6a60377e02 | ||
|
|
fc87b3c4b4 | ||
|
|
fcbdb6f2a7 | ||
|
|
a537b01814 | ||
|
|
bd5a16d213 | ||
|
|
be0bd50bad | ||
|
|
cab5c63402 | ||
|
|
d480d892c9 | ||
|
|
f2ccbe7374 | ||
|
|
85241817f8 | ||
|
|
8cf46bdb5c | ||
|
|
5e6d1efb56 | ||
|
|
bc1f9b6f1c | ||
|
|
85d069c106 | ||
|
|
cfecb58bb6 | ||
|
|
11c2ec91d4 | ||
|
|
cc6f133368 | ||
|
|
350b637a1a | ||
|
|
f917dccf6f | ||
|
|
62d380a1ee | ||
|
|
65ef6cf217 | ||
|
|
2bba0f7b8f | ||
|
|
565970b8ca | ||
|
|
6ea3dd7dfe | ||
|
|
8176a1253b | ||
|
|
4f67c38777 | ||
|
|
86beb7b109 | ||
|
|
98a6c491b1 | ||
|
|
66c045c439 | ||
|
|
a1ec38f53b | ||
|
|
64f1024eb5 | ||
|
|
b3500bfbdc | ||
|
|
f8c45324b6 | ||
|
|
bf5d4f6b07 | ||
|
|
1300e68fa5 | ||
|
|
1a76f2ecb9 | ||
|
|
9c5fb0392d | ||
|
|
f4c5eaf05b | ||
|
|
dd90b4ece4 | ||
|
|
4930db35e2 | ||
|
|
e6409a88d5 | ||
|
|
77a48dc252 | ||
|
|
029be823e2 | ||
|
|
421aff7d67 | ||
|
|
9e7094adfc | ||
|
|
19e8d60179 | ||
|
|
9d9869e515 | ||
|
|
54e19b1efb | ||
|
|
f603b6ef68 | ||
|
|
81e0fcbc13 | ||
|
|
b999bd9c8c | ||
|
|
9c9a8f9d0f | ||
|
|
461ef2a508 | ||
|
|
7492b6cdb3 | ||
|
|
34e27ff4c2 | ||
|
|
47588c8e75 | ||
|
|
00c6fcfe98 | ||
|
|
c90f7c3203 | ||
|
|
6467ead9ad | ||
|
|
cb7caf2afc | ||
|
|
c6ebb23f38 | ||
|
|
5753d63958 | ||
|
|
e56d9765d7 | ||
|
|
a5b7ec2624 | ||
|
|
b2fa41307c | ||
|
|
fce74c73c7 | ||
|
|
e110b29c2f | ||
|
|
a3aba0269d | ||
|
|
e1f4aa5fcd | ||
|
|
e19ee86b0d | ||
|
|
6e71b5a59c | ||
|
|
b70092e281 | ||
|
|
602eac89c4 | ||
|
|
d8b5cc6717 | ||
|
|
76fedccf13 | ||
|
|
41206e70b4 | ||
|
|
bc2c37c739 | ||
|
|
4a2a47666f | ||
|
|
94fbbb7669 | ||
|
|
63010c26ad | ||
|
|
f398b2eafa | ||
|
|
1214067d03 | ||
|
|
0469d05447 | ||
|
|
2fcec27e23 | ||
|
|
42d0283489 | ||
|
|
3fbd8036f4 | ||
|
|
3b4bacb5ba | ||
|
|
7e350dab66 | ||
|
|
9c23d50e92 | ||
|
|
2ec7428e32 | ||
|
|
594f81ec8c | ||
|
|
9767b76881 | ||
|
|
0ace93c2a4 | ||
|
|
c73d165165 | ||
|
|
c1945f8275 | ||
|
|
4d368dc06c | ||
|
|
9ff0e9cf72 | ||
|
|
a971d91a70 | ||
|
|
52b74f9f34 | ||
|
|
b932a9a084 | ||
|
|
997f2dffbf | ||
|
|
1289e03134 | ||
|
|
9a8e5e64ed | ||
|
|
774c050f92 | ||
|
|
478a319442 | ||
|
|
24fea5dd7b | ||
|
|
2b05bdfa94 | ||
|
|
6c8a559023 | ||
|
|
ca8c337c94 | ||
|
|
8ccad65504 | ||
|
|
fd11f294bc | ||
|
|
b3fa76c1be | ||
|
|
d3dd9400e3 | ||
|
|
234034d302 | ||
|
|
edc20a7505 | ||
|
|
3a29028f60 | ||
|
|
f4af7603da | ||
|
|
63a28eb46f | ||
|
|
b85d9ee737 | ||
|
|
58042b0e9f | ||
|
|
23759e6eca | ||
|
|
1d3465698f | ||
|
|
b156f083be | ||
|
|
f83b754cd4 | ||
|
|
df4a0d65bd | ||
|
|
77b5532ce9 | ||
|
|
d9ec65da4d | ||
|
|
4b9dcf1cf2 | ||
|
|
1fbac89a38 | ||
|
|
ceacfb83a8 | ||
|
|
d736c8cca6 | ||
|
|
60769903a5 | ||
|
|
8b73bac580 | ||
|
|
c8162c2900 | ||
|
|
de181c91d5 | ||
|
|
687ba1c9ef | ||
|
|
02802b509d | ||
|
|
7f18dd6a4a | ||
|
|
2f7a472230 | ||
|
|
b8f2f46945 | ||
|
|
2570eb1ab8 | ||
|
|
d3062f9a97 | ||
|
|
8619d17f43 | ||
|
|
8062eb3511 | ||
|
|
e0322bf0e0 | ||
|
|
ddc617f80a | ||
|
|
f64364cced | ||
|
|
32502bfac8 | ||
|
|
1f6a98ecb8 | ||
|
|
6ad0f141be | ||
|
|
0b6366aacb | ||
|
|
deed3a63a3 | ||
|
|
cab80b452b | ||
|
|
338d32a7c6 | ||
|
|
88f15a6804 | ||
|
|
20b3f3b9a1 | ||
|
|
1145a5d483 | ||
|
|
125ca9ff73 | ||
|
|
bc1efb1556 | ||
|
|
7b5649097f | ||
|
|
c2e1d76400 | ||
|
|
f7435559a7 | ||
|
|
47afca1fdb | ||
|
|
372c811763 | ||
|
|
dd061b1dda | ||
|
|
eb3c99c54e | ||
|
|
5d864e3f69 | ||
|
|
1b71f91a01 | ||
|
|
b30886228c | ||
|
|
f91de04269 | ||
|
|
a3531db645 | ||
|
|
1e8fe508f0 | ||
|
|
54244fd33d | ||
|
|
4c1d1bb218 | ||
|
|
903326ddf5 | ||
|
|
0105ec284d | ||
|
|
55b253152c | ||
|
|
6573d2b451 | ||
|
|
cfa9ecbfd2 | ||
|
|
b139201a33 | ||
|
|
946b5d1528 | ||
|
|
3b2670532a | ||
|
|
d00bc973fe | ||
|
|
4768b37531 | ||
|
|
ab162c6c25 | ||
|
|
5ed912bebc | ||
|
|
ec43090c16 | ||
|
|
80759ee03f | ||
|
|
816f473ac9 | ||
|
|
d59d3b4463 | ||
|
|
8784b78d84 | ||
|
|
5005c67d76 | ||
|
|
63732a99e9 | ||
|
|
04b7da336d | ||
|
|
5f69f2bb0c | ||
|
|
fb62a35921 | ||
|
|
08787c7674 | ||
|
|
79de45eed5 | ||
|
|
9bc9e1c08d | ||
|
|
3acdeb87a4 | ||
|
|
9959e53985 | ||
|
|
4edb71325f | ||
|
|
310768e8d2 | ||
|
|
dc90e460fe | ||
|
|
d20c14b4bb | ||
|
|
981f5782d8 | ||
|
|
c2021b6225 | ||
|
|
9de4dbdd03 | ||
|
|
1a84a44cc2 | ||
|
|
80a9fc2fce | ||
|
|
8aac7e82c0 | ||
|
|
49e300d0ca | ||
|
|
136e99de62 | ||
|
|
c41986a63f | ||
|
|
bedf8ea55e | ||
|
|
d8f1c0abcd | ||
|
|
13a85ee3f1 | ||
|
|
fab18bae80 | ||
|
|
6e24b26e2c | ||
|
|
7fb44d4d5f | ||
|
|
44f85d04f9 | ||
|
|
bd71f0a096 |
@@ -30,7 +30,7 @@ PROJECT_NUMBER = @PACKAGE_VERSION@
|
||||
# If a relative path is entered, it will be relative to the location
|
||||
# where doxygen was started. If left blank the current directory will be used.
|
||||
|
||||
OUTPUT_DIRECTORY = builtin_doc
|
||||
OUTPUT_DIRECTORY = help_doc
|
||||
|
||||
# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
|
||||
# 4096 sub-directories (in 2 levels) under the output directory of each output
|
||||
@@ -423,7 +423,7 @@ WARN_LOGFILE =
|
||||
# directories like "/usr/src/myproject". Separate the files or directories
|
||||
# with spaces.
|
||||
|
||||
INPUT =
|
||||
INPUT = doc_src
|
||||
|
||||
# If the value of the INPUT tag contains directories, you can use the
|
||||
# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
|
||||
23
INSTALL
23
INSTALL
@@ -32,17 +32,22 @@ separate build directories or any other fancy configure options.
|
||||
Simple install procedure
|
||||
========================
|
||||
|
||||
If you have downloaded the darcs repository of fish, you need to run
|
||||
the autoconf command first. Then use the following commands to compile
|
||||
fish:
|
||||
Always begin by uninstalling any previous fish versions. This is done
|
||||
by running the command 'make uninstall' in the source directory of
|
||||
your previous fish installation.
|
||||
|
||||
% ./configure
|
||||
% make # Compile fish
|
||||
% make install # Install fish
|
||||
% echo /usr/local/bin/fish >>/etc/shells # Add fish to list of shells
|
||||
Next, if you have downloaded a fresh copy of the darcs repository of
|
||||
fish, you need to run the 'autoconf' command.
|
||||
|
||||
If you wish to use fish as your default shell, use the following
|
||||
command:
|
||||
Then, use following commands to compile fish:
|
||||
|
||||
./configure
|
||||
make # Compile fish
|
||||
make install # Install fish
|
||||
echo /usr/local/bin/fish >>/etc/shells # Add fish to list of shells
|
||||
|
||||
Finally, if you wish to use fish as your default shell, use the
|
||||
following command:
|
||||
|
||||
% chsh -s /usr/local/bin/fish
|
||||
|
||||
|
||||
455
Makefile.in
455
Makefile.in
@@ -1,4 +1,4 @@
|
||||
#
|
||||
|
||||
# Copyright (C) 2005-2006 Axel Liljencrantz
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
@@ -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,21 +86,24 @@ 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
|
||||
#
|
||||
|
||||
BUILTIN_FILES := builtin_help.c builtin_set.c builtin_commandline.c \
|
||||
BUILTIN_FILES := builtin_set.c builtin_commandline.c \
|
||||
builtin_ulimit.c builtin_complete.c builtin_jobs.c
|
||||
|
||||
|
||||
@@ -104,8 +111,9 @@ BUILTIN_FILES := builtin_help.c 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 \
|
||||
input_common.o env_universal.o env_universal_common.o common.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
|
||||
|
||||
|
||||
#
|
||||
@@ -119,62 +127,41 @@ FISH_TESTS_OBJS := $(FISH_OBJS) fish_tests.o
|
||||
# All objects that the system needs to build fishd
|
||||
#
|
||||
|
||||
FISHD_OBJS := fishd.o env_universal_common.o wutil.o \
|
||||
doc_src/fishd.o common.o
|
||||
FISHD_OBJS := fishd.o env_universal_common.o wutil.o print_help.o \
|
||||
common.o
|
||||
|
||||
|
||||
#
|
||||
# All objects needed to build mimedb
|
||||
#
|
||||
|
||||
MIME_OBJS := mimedb.o xdgmimealias.o xdgmime.o xdgmimeglob.o \
|
||||
xdgmimeint.o xdgmimemagic.o xdgmimeparent.o wutil.o common.o
|
||||
MIME_OBJS := mimedb.o print_help.o xdgmimealias.o xdgmime.o \
|
||||
xdgmimeglob.o xdgmimeint.o xdgmimemagic.o xdgmimeparent.o wutil.o \
|
||||
common.o
|
||||
|
||||
|
||||
#
|
||||
# Files containing documentation for builtins.
|
||||
# Files containing user documentation
|
||||
#
|
||||
|
||||
BUILTIN_DOC_SRC := doc_src/source.txt doc_src/and.txt \
|
||||
doc_src/begin.txt doc_src/bg.txt doc_src/bind.txt \
|
||||
doc_src/block.txt doc_src/break.txt doc_src/builtin.txt \
|
||||
doc_src/case.txt doc_src/cd.txt doc_src/command.txt \
|
||||
doc_src/commandline.txt doc_src/complete.txt doc_src/continue.txt \
|
||||
doc_src/else.txt doc_src/end.txt doc_src/eval.txt doc_src/exec.txt \
|
||||
doc_src/exit.txt doc_src/fg.txt doc_src/for.txt \
|
||||
doc_src/function.txt doc_src/functions.txt doc_src/if.txt \
|
||||
doc_src/jobs.txt doc_src/not.txt doc_src/or.txt doc_src/random.txt \
|
||||
doc_src/return.txt doc_src/read.txt doc_src/set.txt \
|
||||
doc_src/status.txt doc_src/switch.txt doc_src/ulimit.txt \
|
||||
doc_src/while.txt
|
||||
#
|
||||
# These files are the source files, they contain a few @FOO@-style substitutions
|
||||
#
|
||||
|
||||
HDR_FILES_SRC := doc_src/index.hdr.in doc_src/commands.hdr.in doc_src/design.hdr doc_src/license.hdr doc_src/faq.hdr
|
||||
|
||||
|
||||
#
|
||||
# Files generated by running doxygen on the files in $(BUILTIN_DOC_SRC)
|
||||
# These are the generated result files
|
||||
#
|
||||
|
||||
BUILTIN_DOC_HDR := $(BUILTIN_DOC_SRC:.txt=.doxygen)
|
||||
|
||||
HDR_FILES := doc_src/index.hdr doc_src/commands.hdr doc_src/design.hdr doc_src/license.hdr doc_src/faq.hdr
|
||||
HDR_FILES := $(subst .hdr.in,.hdr,$(HDR_FILES_SRC))
|
||||
|
||||
#
|
||||
# Files containing documentation for external commands.
|
||||
#
|
||||
|
||||
CMD_DOC_SRC := doc_src/contains.txt doc_src/count.txt doc_src/dirh.txt \
|
||||
doc_src/dirs.txt doc_src/fish.txt doc_src/fish_pager.txt \
|
||||
doc_src/fishd.txt doc_src/help.txt doc_src/isatty.txt \
|
||||
doc_src/mimedb.txt doc_src/nextd.txt doc_src/open.txt \
|
||||
doc_src/popd.txt doc_src/prevd.txt doc_src/psub.txt \
|
||||
doc_src/pushd.txt doc_src/set_color.txt doc_src/trap.txt \
|
||||
doc_src/type.txt doc_src/umask.txt doc_src/vared.txt
|
||||
|
||||
|
||||
#
|
||||
# Files generated by running doxygen on the files in $(CMD_DOC_SRC)
|
||||
#
|
||||
|
||||
CMD_DOC_HDR := $(CMD_DOC_SRC:.txt=.doxygen)
|
||||
HELP_SRC := $(wildcard doc_src/*.txt)
|
||||
|
||||
|
||||
#
|
||||
@@ -192,39 +179,43 @@ TEST_IN := $(wildcard tests/test*.in)
|
||||
# Files in ./doc_src/
|
||||
#
|
||||
|
||||
DOC_SRC_DIR_FILES := doc_src/Doxyfile.in doc_src/index.hdr \
|
||||
doc_src/license.hdr doc_src/faq.hdr doc_src/design.hdr \
|
||||
$(BUILTIN_DOC_SRC) $(CMD_DOC_SRC)
|
||||
DOC_SRC_DIR_FILES := $(HDR_FILES_SRC) $(HELP_SRC)
|
||||
|
||||
|
||||
#
|
||||
# Files in ./. There is some overlap between the variables in the
|
||||
# list, so when copying these files, cp will complain that some files
|
||||
# are specified more than once.
|
||||
# Files in ./
|
||||
#
|
||||
|
||||
MAIN_DIR_FILES := Doxyfile Doxyfile.user Makefile.in configure \
|
||||
configure.ac config.h.in install-sh set_color.c count.c \
|
||||
key_reader.c gen_hdr.sh gen_hdr2.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) \
|
||||
builtin_help.hdr 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
|
||||
MAIN_DIR_FILES_UNSORTED := Doxyfile Doxyfile.user Doxyfile.help.in \
|
||||
Makefile.in configure configure.ac config.h.in install-sh \
|
||||
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 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
|
||||
# of removing duplicates, which means there will be fewer warnings
|
||||
# during building.
|
||||
#
|
||||
|
||||
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
|
||||
|
||||
|
||||
#
|
||||
@@ -253,19 +244,16 @@ FUNCTIONS_DIR_FILES := $(wildcard share/functions/*.fish)
|
||||
# Programs to install
|
||||
#
|
||||
|
||||
PROGRAMS:=fish set_color @XSEL@ @SEQ_FALLBACK@ mimedb count fish_pager fishd
|
||||
SIMPLE_PROGRAMS := fish set_color mimedb fish_pager fishd fish_indent
|
||||
PROGRAMS := $(SIMPLE_PROGRAMS) @XSEL@ @SEQ_FALLBACK@
|
||||
|
||||
|
||||
#
|
||||
# Manual pagess to install
|
||||
# Manual pages to install
|
||||
#
|
||||
|
||||
MANUALS:=doc_src/builtin_doc/man/man1/fish.1 @XSEL_MAN_PATH@ \
|
||||
doc_src/builtin_doc/man/man1/mimedb.1 \
|
||||
doc_src/builtin_doc/man/man1/set_color.1 \
|
||||
doc_src/builtin_doc/man/man1/count.1 \
|
||||
doc_src/builtin_doc/man/man1/fishd.1 \
|
||||
doc_src/builtin_doc/man/man1/fish_pager.1
|
||||
MANUALS := $(addsuffix .1, $(addprefix share/man/, \
|
||||
$(SIMPLE_PROGRAMS))) @XSEL_MAN_PATH@
|
||||
|
||||
|
||||
#
|
||||
@@ -280,9 +268,9 @@ TRANSLATIONS := $(TRANSLATIONS_SRC:.po=.gmo)
|
||||
# Make everything needed for installing fish
|
||||
#
|
||||
|
||||
all: $(PROGRAMS) user_doc 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.
|
||||
@echo Use \'$(MAKE) install\' to install fish.
|
||||
.PHONY: all
|
||||
|
||||
|
||||
@@ -304,7 +292,7 @@ Makefile: Makefile.in configure
|
||||
#
|
||||
|
||||
debug:
|
||||
make fish CFLAGS="@CFLAGS@ $(MACROS) -O0 -Wno-unused -Werror -g"
|
||||
$(MAKE) fish CFLAGS="@CFLAGS@ $(MACROS) -O0 -Wno-unused -Werror -g"
|
||||
.PHONY: debug
|
||||
|
||||
|
||||
@@ -312,8 +300,11 @@ debug:
|
||||
# User documentation, describing the features of the fish shell.
|
||||
#
|
||||
|
||||
user_doc: $(HDR_FILES) Doxyfile.user user_doc.head.html $(CMD_DOC_SRC) $(BUILTIN_DOC_SRC)
|
||||
$(MAKE) doc.h # Depend on the sources (*.hdr) and manually make the intermediate as needed
|
||||
# Depend on the sources (*.hdr.in) and manually make the
|
||||
# intermediate *.hdr and doc.h files if needed
|
||||
|
||||
user_doc: $(HDR_FILES_SRC) Doxyfile.user user_doc.head.html $(HELP_SRC)
|
||||
$(MAKE) doc.h $(HDR_FILES)
|
||||
doxygen Doxyfile.user
|
||||
touch user_doc
|
||||
|
||||
@@ -322,7 +313,7 @@ user_doc: $(HDR_FILES) Doxyfile.user user_doc.head.html $(CMD_DOC_SRC) $(BUILTIN
|
||||
# Source code documentation. Also includes user documentation.
|
||||
#
|
||||
|
||||
doc: *.h *.c doc.h Doxyfile builtin_help.c
|
||||
doc: *.h *.c doc.h Doxyfile
|
||||
doxygen;
|
||||
|
||||
|
||||
@@ -355,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."
|
||||
|
||||
|
||||
#
|
||||
@@ -363,19 +354,32 @@ xsel-0.9.6/xsel: xsel-0.9.6
|
||||
# builtins
|
||||
#
|
||||
|
||||
doc_src/commands.hdr:$(BUILTIN_DOC_SRC) $(CMD_DOC_SRC)
|
||||
rm -f commands.tmp;
|
||||
echo "/** \page commands Commands" >>commands.tmp;
|
||||
echo "Fish ships with a large number of builtin commands, shellscript functions and external commandss. These are all described below. " >>commands.tmp;
|
||||
for i in `printf "%s\n" $(BUILTIN_DOC_SRC) $(CMD_DOC_SRC)|sort`; do \
|
||||
echo "<hr>" >>commands.tmp; \
|
||||
cat $$i >>commands.tmp; \
|
||||
echo >>commands.tmp; \
|
||||
echo >>commands.tmp; \
|
||||
echo "Back to <a href='index.html#toc-commands'>index</a>". >>commands.tmp; \
|
||||
doc_src/commands.hdr:$(HELP_SRC) doc_src/commands.hdr.in
|
||||
-rm command_list.tmp $@
|
||||
for i in `printf "%s\n" $(HELP_SRC)|sort`; do \
|
||||
echo "<hr>" >>command_list.tmp; \
|
||||
cat $$i >>command_list.tmp; \
|
||||
echo >>command_list.tmp; \
|
||||
echo >>command_list.tmp; \
|
||||
echo "Back to <a href='index.html#toc-commands'>index</a>". >>command_list.tmp; \
|
||||
done
|
||||
echo "*/" >>commands.tmp
|
||||
mv commands.tmp doc_src/commands.hdr
|
||||
mv command_list.tmp command_list.txt
|
||||
cat $@.in | awk '{if ($$0 ~ /@command_list@/){ system("cat command_list.txt");} else{ print $$0;}}' >$@
|
||||
|
||||
|
||||
toc.txt: $(subst index.hdr,index.hdr.in,$(HDR_FILES))
|
||||
-rm toc.tmp $@
|
||||
for i in $(subst index.hdr,index.hdr.in,$(HDR_FILES)); do\
|
||||
NAME=`basename $$i .hdr`; \
|
||||
NAME=`basename $$NAME .hdr.in`; \
|
||||
sed <$$i >>toc.tmp -n \
|
||||
-e 's,.*\\page *\([^ ]*\) *\(.*\)$$,- <a href="'$$NAME'.html" name="toc-'$$NAME'">\2</a>,p' \
|
||||
-e 's,.*\\section *\([^ ]*\) *\(.*\)$$, - <a href="'$$NAME'.html#\1" name="toc-'$$NAME'">\2</a>,p'; \
|
||||
done
|
||||
mv toc.tmp $@
|
||||
|
||||
doc_src/index.hdr: toc.txt doc_src/index.hdr.in
|
||||
cat $@.in | awk '{if ($$0 ~ /@toc@/){ system("cat toc.txt");} else{ print $$0;}}' >$@
|
||||
|
||||
|
||||
#
|
||||
@@ -385,20 +389,8 @@ doc_src/commands.hdr:$(BUILTIN_DOC_SRC) $(CMD_DOC_SRC)
|
||||
# documentation.
|
||||
#
|
||||
|
||||
doc.h:$(HDR_FILES)
|
||||
rm -f doc.h
|
||||
echo "/** \mainpage Fish user documentation" >doc.tmp
|
||||
echo "\section toc Table of contents" >>doc.tmp
|
||||
echo '- <a href="index.html" name="toc-index">Fish user documentation</a>' >>doc.tmp
|
||||
for i in $(HDR_FILES); do\
|
||||
sed <$$i >>doc.tmp -n \
|
||||
-e 's,.*\\page *\([^ ]*\) *\(.*\)$$,- <a href="'`basename $$i .hdr`'.html" name="toc-'`basename $$i .hdr`'">\2</a>,p' \
|
||||
-e 's,.*\\section *\([^ ]*\) *\(.*\)$$, - <a href="'`basename $$i .hdr`'.html#\1" name="toc-'`basename $$i .hdr`'">\2</a>,p' \
|
||||
# -e 's,.*\\subsection *\([^ ]*\) *\(.*\)$$, - <a href="'`basename $$i .hdr`'.html#\1" name="toc-'`basename $$i .hdr`'">\2</a>,p'; \
|
||||
done
|
||||
cat $(HDR_FILES) >>doc.tmp;
|
||||
mv doc.tmp doc.h
|
||||
|
||||
doc.h: $(HDR_FILES)
|
||||
cat $(HDR_FILES) >$@
|
||||
|
||||
#
|
||||
# This rule creates complete doxygen headers from each of the various
|
||||
@@ -412,8 +404,14 @@ doc.h:$(HDR_FILES)
|
||||
cat $*.txt >>$@;
|
||||
echo "*/" >>$@
|
||||
|
||||
%: %.in Makefile
|
||||
sed <$@.in >$@ -e "s,@sysconfdir\@,$(sysconfdir),g" -e "s,@datadir\@,$(datadir),g" -e "s,@docdir\@,$(docdir),g" -e "s|@configure_input\@|$@, generated from $@.in by the Makefile. DO NOT MANUALLY EDIT THIS FILE!|g" -e "s,@prefix\@,$(prefix),g" -e "s,@optbindirs\@,$(optbindirs),g"
|
||||
%: %.in
|
||||
sed <$@.in >$@ \
|
||||
-e "s,@sysconfdir\@,$(sysconfdir),g" \
|
||||
-e "s,@datadir\@,$(datadir),g" \
|
||||
-e "s,@docdir\@,$(docdir),g" \
|
||||
-e "s|@configure_input\@|$@, generated from $@.in by the Makefile. DO NOT MANUALLY EDIT THIS FILE!|g" \
|
||||
-e "s,@prefix\@,$(prefix),g" \
|
||||
-e "s,@optbindirs\@,$(optbindirs),g"
|
||||
#-e "s,@\@,$(),"
|
||||
|
||||
|
||||
@@ -422,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
|
||||
|
||||
@@ -445,10 +443,10 @@ doc.h:$(HDR_FILES)
|
||||
# Create a template translation object
|
||||
#
|
||||
|
||||
messages.pot: *.c *.h etc/*.in share/fish share/completions/*.fish share/functions/*.fish seq
|
||||
messages.pot: *.c *.h etc/*.in share/*.in share/completions/*.fish share/functions/*.fish seq
|
||||
if test $(HAVE_GETTEXT) = 1;then \
|
||||
xgettext -k_ -kN_ *.c *.h -o messages.pot; \
|
||||
if xgettext -j -k_ -kN_ -LShell etc/*.in share/fish share/completions/*.fish share/functions/*.fish seq -o messages.pot; then true; else \
|
||||
if xgettext -j -k_ -kN_ -k--description -LShell etc/*.in share/*.in share/completions/*.fish share/functions/*.fish seq -o messages.pot; then true; else \
|
||||
echo "Your xgettext version is too old to build the messages.pot file"\
|
||||
rm messages.pot\
|
||||
false;\
|
||||
@@ -462,8 +460,7 @@ common.o: $(COMMON_FILES)
|
||||
|
||||
#
|
||||
# Generate the internal help functions by making doxygen create
|
||||
# man-pages which are then converted into C code. The convertion path
|
||||
# looks like this:
|
||||
# man-pages. The convertion path looks like this:
|
||||
#
|
||||
# .txt file
|
||||
# ||
|
||||
@@ -475,70 +472,37 @@ common.o: $(COMMON_FILES)
|
||||
# (doxygen)
|
||||
# ||
|
||||
# \/
|
||||
# man file
|
||||
# roff file
|
||||
# ||
|
||||
# (man)
|
||||
# (__fish_print_help)
|
||||
# ||
|
||||
# \/
|
||||
# formated text
|
||||
# with escape
|
||||
# sequences
|
||||
# ||
|
||||
# \/
|
||||
# (gen_hdr2)
|
||||
# ||
|
||||
# \/
|
||||
# .c file
|
||||
#
|
||||
# Which is an awful, clunky and ugly way of producing
|
||||
# documentation. There ought to be something simpler.
|
||||
#
|
||||
# There ought to be something simpler.
|
||||
#
|
||||
|
||||
doc_src/builtin_doc: $(BUILTIN_DOC_SRC) doc_src/count.txt builtin_help.hdr $(CMD_DOC_SRC)
|
||||
for i in $(BUILTIN_DOC_SRC) $(CMD_DOC_SRC); do \
|
||||
share/man: $(HELP_SRC)
|
||||
-rm doc_src/*.doxygen # Remove temp files from previous run
|
||||
-rm -r help_doc
|
||||
-mkdir share/man
|
||||
touch share/man
|
||||
for i in $(HELP_SRC); do \
|
||||
FILE=doc_src/`basename $$i .txt`.doxygen; \
|
||||
echo "/** \page" `basename $$i .txt` >$$FILE; \
|
||||
cat $$i >>$$FILE; \
|
||||
echo "*/" >>$$FILE; \
|
||||
done
|
||||
cd doc_src; doxygen; cd ..;
|
||||
for i in doc_src/builtin_doc/man/man1/*.1; do \
|
||||
CMD_NAME=`basename $$i .1`; \
|
||||
sed -e "s/\(.\)\\.SH/\1/" -e "s/$$CMD_NAME *\\\\- *\"\(.*\)\"/\1/" <$$i >$$i.tmp; \
|
||||
mv $$i.tmp $$i; \
|
||||
doxygen Doxyfile.help
|
||||
for i in $(HELP_SRC); do \
|
||||
CMD_NAME=`basename $$i .txt`; \
|
||||
sed -e "s/\(.\)\\.SH/\1/" -e "s/$$CMD_NAME *\\\\- *\"\(.*\)\"/\1/" <help_doc/man/man1/$$CMD_NAME.1 >share/man/$$CMD_NAME.1; \
|
||||
done
|
||||
touch doc_src/builtin_doc
|
||||
|
||||
builtin_help.c: doc_src/builtin_doc gen_hdr.sh
|
||||
$(MAKE) gen_hdr2 # Don't depend on gen_hdr2, because then we would need to rebuild the docs whenever we use a fresh tarball
|
||||
cp builtin_help.hdr builtin_help.c;
|
||||
if test -x gen_hdr.sh; then true; else chmod 755 gen_hdr.sh; fi
|
||||
for i in $(BUILTIN_DOC_HDR) doc_src/count.doxygen ; do \
|
||||
echo ' hash_put( &tbl, L"'`basename $$i .doxygen`'",' >>$@; \
|
||||
./gen_hdr.sh $$i >>$@; \
|
||||
printf " );\n\n" >>$@; \
|
||||
done;
|
||||
echo "}" >>builtin_help.c
|
||||
|
||||
|
||||
#
|
||||
# Generate help texts for external fish commands, like set_color and
|
||||
# mimedb.
|
||||
#
|
||||
|
||||
%.c : %.doxygen
|
||||
$(MAKE) gen_hdr2 builtin_help.c # These should really be filed as dependencis for %.c above instead, but that seems to confuse make
|
||||
echo "// This file was automatically generated, do not edit" >$@
|
||||
echo "#include <stdlib.h>" >>$@
|
||||
echo "#include <stdio.h>" >>$@
|
||||
echo >>$@
|
||||
echo "void print_help()" >>$@
|
||||
echo "{" >>$@
|
||||
echo ' printf( "%s",' >>$@
|
||||
chmod 755 gen_hdr.sh
|
||||
./gen_hdr.sh $*.doxygen >>$@
|
||||
echo ");" >>$@
|
||||
echo "}" >>$@
|
||||
rm doc_src/*.doxygen # Clean up intermediate files in doc_src/
|
||||
rm -r help_doc # Clean up intermediate help_doc tree
|
||||
|
||||
#
|
||||
# The build rules for installing/uninstalling fish
|
||||
@@ -556,8 +520,8 @@ check-uninstall:
|
||||
echo;\
|
||||
echo An older fish installation using an incompatible filesystem hierarchy was detected;\
|
||||
echo You must uninstall this fish version before proceeding;\
|
||||
echo type \'make uninstall-legacy\' to uninstall these files,;\
|
||||
echo or type \'make force-install\' to force installation.;\
|
||||
echo type \'$(MAKE) uninstall-legacy\' to uninstall these files,;\
|
||||
echo or type \'$(MAKE) force-install\' to force installation.;\
|
||||
echo The latter may result in a broken installation.;\
|
||||
echo;\
|
||||
false;\
|
||||
@@ -568,7 +532,7 @@ check-uninstall:
|
||||
echo;\
|
||||
echo An older fish installation using an incompatible filesystem hierarchy was detected;\
|
||||
echo You must remove the file $(DESTDIR)$(sysconfdir)/fish before proceeding;\
|
||||
echo type \'make uninstall-legacy\' to uninstall this file,;\
|
||||
echo type \'$(MAKE) uninstall-legacy\' to uninstall this file,;\
|
||||
echo or remove it manually using \'rm $(DESTDIR)$(sysconfdir)/fish\'.;\
|
||||
echo;\
|
||||
false;\
|
||||
@@ -583,7 +547,7 @@ check-uninstall:
|
||||
#
|
||||
|
||||
install-sh:
|
||||
if test -x install-sh; then true; else chmod 755 install-sh; fi
|
||||
if test -x $@; then true; else chmod 755 $@; fi
|
||||
.PHONY: install-sh
|
||||
|
||||
|
||||
@@ -609,16 +573,18 @@ install-force: all install-translations
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/completions
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/functions
|
||||
$(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;
|
||||
for i in $(FUNCTIONS_DIR_FILES); do \
|
||||
$(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/functions/; \
|
||||
done;
|
||||
$(INSTALL) -m 644 etc/fish_inputrc $(DESTDIR)$(sysconfdir)/fish/fish_inputrc;
|
||||
for i in share/man/*.1; do \
|
||||
$(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/man/; \
|
||||
done;
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(docdir)
|
||||
for i in user_doc/html/* ChangeLog; do \
|
||||
if test -f $$i; then \
|
||||
@@ -650,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; \
|
||||
@@ -675,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`; \
|
||||
@@ -716,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 $@
|
||||
|
||||
|
||||
#
|
||||
@@ -725,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 $@
|
||||
|
||||
|
||||
#
|
||||
@@ -733,7 +699,7 @@ fish_pager: $(FISH_PAGER_OBJS)
|
||||
#
|
||||
|
||||
fishd: $(FISHD_OBJS)
|
||||
$(CC) $(FISHD_OBJS) $(LDFLAGS) -o $@
|
||||
$(CC) $(FISHD_OBJS) $(LDFLAGS_FISHD) -o $@
|
||||
|
||||
|
||||
#
|
||||
@@ -741,7 +707,7 @@ fishd: $(FISHD_OBJS)
|
||||
#
|
||||
|
||||
fish_tests: $(FISH_TESTS_OBJS)
|
||||
$(CC) $(FISH_TESTS_OBJS) $(LDFLAGS) -o $@
|
||||
$(CC) $(FISH_TESTS_OBJS) $(LDFLAGS_FISH) -o $@
|
||||
|
||||
|
||||
#
|
||||
@@ -750,26 +716,16 @@ fish_tests: $(FISH_TESTS_OBJS)
|
||||
# mimedb does not need any libraries, so we don't use LDFLAGS here.
|
||||
#
|
||||
|
||||
mimedb: $(MIME_OBJS) doc_src/mimedb.o
|
||||
$(CC) $(MIME_OBJS) doc_src/mimedb.o $(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 $@
|
||||
mimedb: $(MIME_OBJS)
|
||||
$(CC) $(MIME_OBJS) $(LDFLAGS_MIMEDB) -o $@
|
||||
|
||||
|
||||
#
|
||||
# Build the set_color program
|
||||
#
|
||||
|
||||
set_color: set_color.o doc_src/set_color.o common.o
|
||||
$(CC) set_color.o doc_src/set_color.o common.o wutil.o $(LDFLAGS) -o $@
|
||||
set_color: set_color.o print_help.o common.o
|
||||
$(CC) set_color.o print_help.o common.o wutil.o $(LDFLAGS_SET_COLOR) -o $@
|
||||
|
||||
|
||||
#
|
||||
@@ -780,6 +736,14 @@ 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
|
||||
#
|
||||
@@ -796,7 +760,6 @@ depend:
|
||||
./config.status
|
||||
.PHONY: depend
|
||||
|
||||
|
||||
#
|
||||
# Copy all the source files into a new directory and use tar to create
|
||||
# an archive from it. Simplest way I could think of to make an archive
|
||||
@@ -806,7 +769,7 @@ depend:
|
||||
# exists
|
||||
#
|
||||
|
||||
fish-@PACKAGE_VERSION@.tar: $(DOC_SRC_DIR_FILES) $(MAIN_DIR_FILES) $(ETC_DIR_FILES) $(TEST_DIR_FILES) $(SHARE_DIR_FILES) $(FUNCTIONS_DIR_FILES) $(COMPLETIONS_DIR_FILES) ChangeLog user_doc doc_src/builtin_doc
|
||||
fish-@PACKAGE_VERSION@.tar: $(DOC_SRC_DIR_FILES) $(MAIN_DIR_FILES) $(ETC_DIR_FILES) $(TEST_DIR_FILES) $(SHARE_DIR_FILES) $(FUNCTIONS_DIR_FILES) $(COMPLETIONS_DIR_FILES) ChangeLog user_doc share/man
|
||||
rm -rf fish-@PACKAGE_VERSION@
|
||||
$(INSTALL) -d fish-@PACKAGE_VERSION@
|
||||
$(INSTALL) -d fish-@PACKAGE_VERSION@/doc_src
|
||||
@@ -815,6 +778,7 @@ fish-@PACKAGE_VERSION@.tar: $(DOC_SRC_DIR_FILES) $(MAIN_DIR_FILES) $(ETC_DIR_FIL
|
||||
$(INSTALL) -d fish-@PACKAGE_VERSION@/share
|
||||
$(INSTALL) -d fish-@PACKAGE_VERSION@/share/completions
|
||||
$(INSTALL) -d fish-@PACKAGE_VERSION@/share/functions
|
||||
$(INSTALL) -d fish-@PACKAGE_VERSION@/share/man
|
||||
$(INSTALL) -d fish-@PACKAGE_VERSION@/tests
|
||||
$(INSTALL) -d fish-@PACKAGE_VERSION@/po
|
||||
cp -f $(DOC_SRC_DIR_FILES) fish-@PACKAGE_VERSION@/doc_src
|
||||
@@ -825,8 +789,8 @@ fish-@PACKAGE_VERSION@.tar: $(DOC_SRC_DIR_FILES) $(MAIN_DIR_FILES) $(ETC_DIR_FIL
|
||||
cp -f $(FUNCTIONS_DIR_FILES) fish-@PACKAGE_VERSION@/share/functions/
|
||||
cp -f $(TESTS_DIR_FILES) fish-@PACKAGE_VERSION@/tests/
|
||||
cp -f $(TRANSLATIONS_SRC) fish-@PACKAGE_VERSION@/po/
|
||||
cp -f share/man/*.1 fish-@PACKAGE_VERSION@/share/man/
|
||||
cp -rf user_doc fish-@PACKAGE_VERSION@/
|
||||
cp -rf doc_src/builtin_doc fish-@PACKAGE_VERSION@/doc_src/
|
||||
tar -c fish-@PACKAGE_VERSION@ >fish-@PACKAGE_VERSION@.tar
|
||||
rm -rf fish-@PACKAGE_VERSION@
|
||||
|
||||
@@ -860,6 +824,7 @@ fish.spec: fish.spec.in
|
||||
./config.status
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Create .rpm file for the current systems architecture and an
|
||||
# .src.rpm file.
|
||||
@@ -889,8 +854,8 @@ rpm: fish-@PACKAGE_VERSION@.tar.bz2 fish.spec
|
||||
#
|
||||
|
||||
distclean: clean
|
||||
rm -f fish.spec doc_src/Doxyfile
|
||||
rm -f etc/config.fish share/config_interactive.fish seq share/config.fish
|
||||
rm -f fish.spec Doxyfile.help
|
||||
rm -f etc/config.fish seq share/config.fish
|
||||
rm -f config.status config.log config.h Makefile
|
||||
.PHONY: distclean
|
||||
|
||||
@@ -903,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 gen_hdr2 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
|
||||
@@ -917,36 +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_help.c builtin_set.c builtin_commandline.c
|
||||
builtin.o: builtin_complete.c 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_help.o: config.h util.h common.h halloc_util.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
|
||||
@@ -955,36 +921,41 @@ event.o: config.h signal.h fallback.h util.h wutil.h function.h proc.h io.h
|
||||
event.o: parser.h event.h common.h halloc_util.h
|
||||
exec.o: config.h signal.h fallback.h util.h common.h wutil.h proc.h io.h
|
||||
exec.o: exec.h parser.h event.h builtin.h function.h env.h wildcard.h
|
||||
exec.o: sanity.h expand.h env_universal.h env_universal_common.h halloc.h
|
||||
exec.o: halloc_util.h parse_util.h
|
||||
exec.o: sanity.h expand.h halloc.h halloc_util.h parse_util.h
|
||||
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
|
||||
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
|
||||
@@ -992,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: wildcard.h halloc_util.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
|
||||
set_color.o: config.h fallback.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
|
||||
|
||||
18
builtin.h
18
builtin.h
@@ -8,6 +8,7 @@
|
||||
#include <wchar.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "io.h"
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -35,12 +36,12 @@ enum
|
||||
/**
|
||||
Error message on multiple scope levels for variables
|
||||
*/
|
||||
#define BUILTIN_ERR_GLOCAL _( L"%ls: Variable scope can only be one of universal, global and local\n%ls\n" )
|
||||
#define BUILTIN_ERR_GLOCAL _( L"%ls: Variable scope can only be one of universal, global and local\n" )
|
||||
|
||||
/**
|
||||
Error message for specifying both export and unexport to set/read
|
||||
*/
|
||||
#define BUILTIN_ERR_EXPUNEXP _( L"%ls: Variable can't be both exported and unexported\n%ls\n" )
|
||||
#define BUILTIN_ERR_EXPUNEXP _( L"%ls: Variable can't be both exported and unexported\n" )
|
||||
|
||||
/**
|
||||
Error message for unknown switch
|
||||
@@ -131,7 +132,7 @@ int builtin_exists( wchar_t *cmd );
|
||||
|
||||
\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,12 +165,11 @@ const wchar_t *builtin_complete_get_temporary_buffer();
|
||||
|
||||
|
||||
/**
|
||||
Return the help text for the specified builtin command. Use
|
||||
non-wide characters since wide characters have some issues with
|
||||
string formating escape sequences sometimes.
|
||||
|
||||
\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.
|
||||
*/
|
||||
char *builtin_help_get( const wchar_t *cmd );
|
||||
|
||||
wchar_t *builtin_help_get( const wchar_t *cmd );
|
||||
|
||||
#endif
|
||||
|
||||
@@ -146,7 +146,6 @@ static void write_part( const wchar_t *begin,
|
||||
|
||||
if( tokenize )
|
||||
{
|
||||
|
||||
buff = wcsndup( begin, end-begin );
|
||||
// fwprintf( stderr, L"Subshell: %ls, end char %lc\n", buff, *end );
|
||||
sb_init( &out );
|
||||
@@ -159,20 +158,21 @@ static void write_part( const wchar_t *begin,
|
||||
(tok_get_pos( &tok)+wcslen(tok_last( &tok)) >= pos) )
|
||||
break;
|
||||
|
||||
// fwprintf( stderr, L"Next token %ls\n", tok_last( &tok ) );
|
||||
|
||||
switch( tok_last_type( &tok ) )
|
||||
{
|
||||
case TOK_STRING:
|
||||
sb_append2( &out, tok_last( &tok), L"\n", (void *)0 );
|
||||
{
|
||||
wchar_t *tmp = unescape( tok_last( &tok ), UNESCAPE_INCOMPLETE );
|
||||
sb_append( &out, tmp, L"\n", (void *)0 );
|
||||
free( tmp );
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if( out.buff )
|
||||
sb_append( sb_out,
|
||||
(wchar_t *)out.buff );
|
||||
|
||||
sb_append( sb_out,
|
||||
(wchar_t *)out.buff );
|
||||
|
||||
free( buff );
|
||||
tok_destroy( &tok );
|
||||
@@ -180,12 +180,24 @@ static void write_part( const wchar_t *begin,
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t *buff, *esc;
|
||||
|
||||
if( cut_at_cursor )
|
||||
{
|
||||
end = begin+pos;
|
||||
}
|
||||
sb_append_substring( sb_out, begin, end-begin );
|
||||
sb_append( sb_out, L"\n" );
|
||||
|
||||
buff = wcsndup( begin, end-begin );
|
||||
esc = unescape( buff, UNESCAPE_INCOMPLETE );
|
||||
|
||||
// debug( 0, L"woot2 %ls -> %ls", buff, esc );
|
||||
|
||||
sb_append( sb_out, esc );
|
||||
sb_append( sb_out, L"\n" );
|
||||
|
||||
free( esc );
|
||||
free( buff );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,6 +220,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();
|
||||
@@ -223,13 +237,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;
|
||||
|
||||
@@ -290,6 +314,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
|
||||
}
|
||||
@@ -300,7 +332,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 )
|
||||
@@ -322,6 +354,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;
|
||||
@@ -364,12 +401,20 @@ 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;
|
||||
|
||||
case L'?':
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
builtin_unknown_option( argv[0], argv[woptind-1] );
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -381,7 +426,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,
|
||||
@@ -403,7 +448,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 )
|
||||
{
|
||||
/*
|
||||
@@ -416,9 +461,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;
|
||||
}
|
||||
@@ -430,10 +475,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 );
|
||||
@@ -441,7 +486,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,
|
||||
@@ -500,9 +545,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 );
|
||||
}
|
||||
|
||||
@@ -519,6 +564,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 )
|
||||
{
|
||||
|
||||
@@ -48,10 +48,10 @@ static void builtin_complete_add2( const wchar_t *cmd,
|
||||
array_list_t *gnu_opt,
|
||||
array_list_t *old_opt,
|
||||
int result_mode,
|
||||
int authorative,
|
||||
const wchar_t *condition,
|
||||
const wchar_t *comp,
|
||||
const wchar_t *desc )
|
||||
const wchar_t *desc,
|
||||
int flags )
|
||||
{
|
||||
int i;
|
||||
const wchar_t *s;
|
||||
@@ -64,10 +64,10 @@ static void builtin_complete_add2( const wchar_t *cmd,
|
||||
0,
|
||||
0,
|
||||
result_mode,
|
||||
authorative,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
desc,
|
||||
flags );
|
||||
}
|
||||
|
||||
for( i=0; i<al_get_count( gnu_opt ); i++ )
|
||||
@@ -78,10 +78,10 @@ static void builtin_complete_add2( const wchar_t *cmd,
|
||||
(wchar_t *)al_get(gnu_opt, i ),
|
||||
0,
|
||||
result_mode,
|
||||
authorative,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
desc,
|
||||
flags );
|
||||
}
|
||||
|
||||
for( i=0; i<al_get_count( old_opt ); i++ )
|
||||
@@ -92,10 +92,10 @@ static void builtin_complete_add2( const wchar_t *cmd,
|
||||
(wchar_t *)al_get(old_opt, i ),
|
||||
1,
|
||||
result_mode,
|
||||
authorative,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
desc,
|
||||
flags );
|
||||
}
|
||||
|
||||
if( al_get_count( old_opt )+al_get_count( gnu_opt )+wcslen(short_opt) == 0 )
|
||||
@@ -106,10 +106,10 @@ static void builtin_complete_add2( const wchar_t *cmd,
|
||||
0,
|
||||
0,
|
||||
result_mode,
|
||||
authorative,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
desc,
|
||||
flags );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,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;
|
||||
|
||||
@@ -137,10 +138,18 @@ static void builtin_complete_add( array_list_t *cmd,
|
||||
gnu_opt,
|
||||
old_opt,
|
||||
result_mode,
|
||||
authorative,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
desc,
|
||||
flags );
|
||||
|
||||
if( authoritative != -1 )
|
||||
{
|
||||
complete_set_authoritative( al_get( cmd, i ),
|
||||
COMMAND,
|
||||
authoritative );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for( i=0; i<al_get_count( path ); i++ )
|
||||
@@ -151,12 +160,19 @@ static void builtin_complete_add( array_list_t *cmd,
|
||||
gnu_opt,
|
||||
old_opt,
|
||||
result_mode,
|
||||
authorative,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
}
|
||||
|
||||
desc,
|
||||
flags );
|
||||
|
||||
if( authoritative != -1 )
|
||||
{
|
||||
complete_set_authoritative( al_get( path, i ),
|
||||
PATH,
|
||||
authoritative );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,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;
|
||||
@@ -356,7 +373,11 @@ static int builtin_complete( wchar_t **argv )
|
||||
}
|
||||
,
|
||||
{
|
||||
L"unauthorative", no_argument, 0, 'u'
|
||||
L"unauthoritative", no_argument, 0, 'u'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"authoritative", no_argument, 0, 'A'
|
||||
}
|
||||
,
|
||||
{
|
||||
@@ -381,7 +402,7 @@ static int builtin_complete( wchar_t **argv )
|
||||
|
||||
int opt = wgetopt_long( argc,
|
||||
argv,
|
||||
L"a:c:p:s:l:o:d:frxeun:C::h",
|
||||
L"a:c:p:s:l:o:d:frxeuAn:C::h",
|
||||
long_options,
|
||||
&opt_index );
|
||||
if( opt == -1 )
|
||||
@@ -396,9 +417,6 @@ static int builtin_complete( wchar_t **argv )
|
||||
BUILTIN_ERR_UNKNOWN,
|
||||
argv[0],
|
||||
long_options[opt_index].name );
|
||||
sb_append( sb_err,
|
||||
parser_current_line() );
|
||||
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
|
||||
|
||||
@@ -438,7 +456,11 @@ static int builtin_complete( wchar_t **argv )
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
authorative=0;
|
||||
authoritative=0;
|
||||
break;
|
||||
|
||||
case 'A':
|
||||
authoritative=1;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
@@ -474,10 +496,7 @@ static int builtin_complete( wchar_t **argv )
|
||||
return 0;
|
||||
|
||||
case '?':
|
||||
sb_append( sb_err,
|
||||
parser_current_line() );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
|
||||
builtin_unknown_option( argv[0], argv[woptind-1] );
|
||||
res = 1;
|
||||
break;
|
||||
|
||||
@@ -525,31 +544,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--;
|
||||
}
|
||||
|
||||
@@ -561,8 +600,6 @@ static int builtin_complete( wchar_t **argv )
|
||||
sb_printf( sb_err,
|
||||
_( L"%ls: Too many arguments\n" ),
|
||||
argv[0] );
|
||||
sb_append( sb_err,
|
||||
parser_current_line() );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
|
||||
res = 1;
|
||||
@@ -591,10 +628,11 @@ static int builtin_complete( wchar_t **argv )
|
||||
&gnu_opt,
|
||||
&old_opt,
|
||||
result_mode,
|
||||
authorative,
|
||||
authoritative,
|
||||
condition,
|
||||
comp,
|
||||
desc );
|
||||
desc,
|
||||
flags );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/** \file builtin_help.c
|
||||
|
||||
Functions for printing usage information of builtin commands. This
|
||||
file is automatically generated from the file builtin_help.hdr and
|
||||
various help files in the doc_src directory.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "common.h"
|
||||
#include "halloc_util.h"
|
||||
|
||||
/**
|
||||
Hashtable storing the help text
|
||||
*/
|
||||
static hash_table_t tbl;
|
||||
|
||||
static void builtin_help_init();
|
||||
|
||||
char *builtin_help_get( const wchar_t *cmd )
|
||||
{
|
||||
builtin_help_init();
|
||||
|
||||
return (char *)hash_get( &tbl, (void *)cmd );
|
||||
}
|
||||
|
||||
/**
|
||||
Initialize help hash table. Don't invoke it manually,
|
||||
it is called by builtin_help_get automatically.
|
||||
*/
|
||||
static void builtin_help_init()
|
||||
{
|
||||
static int is_help_init = 0;
|
||||
if( is_help_init )
|
||||
return;
|
||||
is_help_init=1;
|
||||
halloc_register_function( global_context, (void (*)(void *))&hash_destroy, &tbl );
|
||||
hash_init( &tbl, &hash_wcs_func, &hash_wcs_cmp );
|
||||
@@ -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,
|
||||
@@ -222,8 +222,6 @@ static int builtin_jobs( wchar_t **argv )
|
||||
argv[0],
|
||||
long_options[opt_index].name );
|
||||
|
||||
sb_append( sb_err,
|
||||
parser_current_line() );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
|
||||
|
||||
@@ -253,8 +251,7 @@ static int builtin_jobs( wchar_t **argv )
|
||||
return 0;
|
||||
|
||||
case '?':
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
|
||||
builtin_unknown_option( argv[0], argv[woptind-1] );
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
@@ -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" );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,7 +140,8 @@ static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
|
||||
{
|
||||
for( i=0; i<al_get_count( val ); i++ )
|
||||
{
|
||||
sb_append( &sb, (wchar_t *)al_get( val, i ) );
|
||||
wchar_t *next =(wchar_t *)al_get( val, i );
|
||||
sb_append( &sb, next?next:L"" );
|
||||
if( i<al_get_count( val )-1 )
|
||||
{
|
||||
sb_append( &sb, ARRAY_SEP_STR );
|
||||
@@ -232,9 +232,14 @@ static int parse_index( array_list_t *indexes,
|
||||
while (*src != L']')
|
||||
{
|
||||
wchar_t *end;
|
||||
long l_ind = wcstol(src, &end, 10);
|
||||
|
||||
if (end == src)
|
||||
long l_ind;
|
||||
|
||||
errno = 0;
|
||||
|
||||
l_ind = wcstol(src, &end, 10);
|
||||
|
||||
if( end==src || errno )
|
||||
{
|
||||
sb_printf(sb_err, _(L"%ls: Invalid index starting at '%ls'\n"), L"set", src);
|
||||
return 0;
|
||||
@@ -274,11 +279,11 @@ static int update_values( array_list_t *list,
|
||||
{
|
||||
/*
|
||||
The '- 1' below is because the indices in fish are
|
||||
one-based, but the array_lsit_t uses zero-based indices
|
||||
one-based, but the array_list_t uses zero-based indices
|
||||
*/
|
||||
long ind = al_get_long(indexes, i) - 1;
|
||||
void *new = (void *) al_get(values, i);
|
||||
if( ind <= 0 )
|
||||
if( ind < 0 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@@ -382,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 )
|
||||
@@ -534,7 +539,7 @@ static int builtin_set( wchar_t **argv )
|
||||
return 0;
|
||||
|
||||
case '?':
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
builtin_unknown_option( argv[0], argv[woptind-1] );
|
||||
return 1;
|
||||
|
||||
default:
|
||||
@@ -554,9 +559,8 @@ static int builtin_set( wchar_t **argv )
|
||||
if( query && (erase || list || global || local || universal || export || unexport ) )
|
||||
{
|
||||
sb_printf(sb_err,
|
||||
BUILTIN_ERR_COMBO2,
|
||||
argv[0],
|
||||
parser_current_line() );
|
||||
BUILTIN_ERR_COMBO,
|
||||
argv[0] );
|
||||
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
@@ -567,9 +571,8 @@ static int builtin_set( wchar_t **argv )
|
||||
if( erase && list )
|
||||
{
|
||||
sb_printf(sb_err,
|
||||
BUILTIN_ERR_COMBO2,
|
||||
argv[0],
|
||||
parser_current_line() );
|
||||
BUILTIN_ERR_COMBO,
|
||||
argv[0] );
|
||||
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
@@ -582,8 +585,7 @@ static int builtin_set( wchar_t **argv )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
BUILTIN_ERR_GLOCAL,
|
||||
argv[0],
|
||||
parser_current_line() );
|
||||
argv[0] );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
@@ -595,8 +597,7 @@ static int builtin_set( wchar_t **argv )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
BUILTIN_ERR_EXPUNEXP,
|
||||
argv[0],
|
||||
parser_current_line() );
|
||||
argv[0] );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
@@ -615,10 +616,55 @@ static int builtin_set( wchar_t **argv )
|
||||
int i;
|
||||
for( i=woptind; i<argc; i++ )
|
||||
{
|
||||
if( !env_exist( argv[i], scope ) )
|
||||
wchar_t *arg = argv[i];
|
||||
int slice=0;
|
||||
|
||||
if( !(dest = wcsdup(arg)))
|
||||
{
|
||||
retcode++;
|
||||
DIE_MEM();
|
||||
}
|
||||
|
||||
if( wcschr( dest, L'[' ) )
|
||||
{
|
||||
slice = 1;
|
||||
*wcschr( dest, L'[' )=0;
|
||||
}
|
||||
|
||||
if( slice )
|
||||
{
|
||||
array_list_t indexes;
|
||||
array_list_t result;
|
||||
int j;
|
||||
|
||||
al_init( &result );
|
||||
al_init( &indexes );
|
||||
|
||||
tokenize_variable_array( env_get( dest ), &result );
|
||||
|
||||
if( !parse_index( &indexes, arg, dest, al_get_count( &result ) ) )
|
||||
{
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
retcode = 1;
|
||||
break;
|
||||
}
|
||||
for( j=0; j<al_get_count( &indexes ); j++ )
|
||||
{
|
||||
long idx = al_get_long( &indexes, j );
|
||||
if( idx < 1 || idx > al_get_count( &result ) )
|
||||
{
|
||||
retcode++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !env_exist( arg, scope ) )
|
||||
{
|
||||
retcode++;
|
||||
}
|
||||
}
|
||||
|
||||
free( dest );
|
||||
|
||||
}
|
||||
return retcode;
|
||||
@@ -641,8 +687,7 @@ static int builtin_set( wchar_t **argv )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_(L"%ls: Erase needs a variable name\n%ls\n"),
|
||||
argv[0],
|
||||
parser_current_line() );
|
||||
argv[0] );
|
||||
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
retcode = 1;
|
||||
@@ -799,9 +844,8 @@ static int builtin_set( wchar_t **argv )
|
||||
if( woptind != argc )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_(L"%ls: Values cannot be specfied with erase\n%ls\n"),
|
||||
argv[0],
|
||||
parser_current_line() );
|
||||
_(L"%ls: Values cannot be specfied with erase\n"),
|
||||
argv[0] );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
retcode=1;
|
||||
}
|
||||
|
||||
@@ -123,7 +123,9 @@ static int get_multiplier( int what )
|
||||
}
|
||||
|
||||
/**
|
||||
Return the value for the specified resource limit
|
||||
Return the value for the specified resource limit. This function
|
||||
does _not_ multiply the limit value by the multiplier constant used
|
||||
by the commandline ulimit.
|
||||
*/
|
||||
static rlim_t get( int resource, int hard )
|
||||
{
|
||||
@@ -144,7 +146,7 @@ static void print( int resource, int hard )
|
||||
if( l == RLIM_INFINITY )
|
||||
sb_append( sb_out, L"unlimited\n" );
|
||||
else
|
||||
sb_printf( sb_out, L"%d\n", l );
|
||||
sb_printf( sb_out, L"%d\n", l / get_multiplier( resource ) );
|
||||
|
||||
}
|
||||
|
||||
@@ -178,10 +180,15 @@ static void print_all( int hard )
|
||||
resource_arr[i].switch_char);
|
||||
|
||||
if( l == RLIM_INFINITY )
|
||||
{
|
||||
sb_append( sb_out, L"unlimited\n" );
|
||||
}
|
||||
else
|
||||
sb_printf( sb_out, L"%d\n", l );
|
||||
{
|
||||
sb_printf( sb_out, L"%d\n", l/get_multiplier(resource_arr[i].resource) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,14 +209,14 @@ static const wchar_t *get_desc( int what )
|
||||
}
|
||||
|
||||
/**
|
||||
Set the new value of the specified resource limit
|
||||
Set the new value of the specified resource limit. This function
|
||||
does _not_ multiply the limit value by the multiplier constant used
|
||||
by the commandline ulimit.
|
||||
*/
|
||||
static int set( int resource, int hard, int soft, rlim_t value )
|
||||
{
|
||||
struct rlimit ls;
|
||||
getrlimit( resource, &ls );
|
||||
if( value != RLIM_INFINITY )
|
||||
value *= get_multiplier( resource );
|
||||
|
||||
if( hard )
|
||||
{
|
||||
@@ -241,22 +248,6 @@ static int set( int resource, int hard, int soft, rlim_t value )
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Set all resource limits
|
||||
*/
|
||||
static int set_all( int hard, int soft, rlim_t value )
|
||||
{
|
||||
int i;
|
||||
int res=0;
|
||||
|
||||
for( i=0; resource_arr[i].desc; i++ )
|
||||
{
|
||||
if( set( resource_arr[i].resource, hard, soft, value ) )
|
||||
res = 1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
The ulimit builtin, used for setting resource limits. Defined in
|
||||
builtin_ulimit.c.
|
||||
@@ -315,7 +306,7 @@ static int builtin_ulimit( wchar_t ** argv )
|
||||
}
|
||||
,
|
||||
{
|
||||
L"pipe-size", no_argument, 0, 'p'
|
||||
L"stack-size", no_argument, 0, 's'
|
||||
}
|
||||
,
|
||||
{
|
||||
@@ -345,7 +336,7 @@ static int builtin_ulimit( wchar_t ** argv )
|
||||
|
||||
int opt = wgetopt_long( argc,
|
||||
argv,
|
||||
L"aHScdflmnptuvh",
|
||||
L"aHScdflmnstuvh",
|
||||
long_options,
|
||||
&opt_index );
|
||||
if( opt == -1 )
|
||||
@@ -428,28 +419,41 @@ static int builtin_ulimit( wchar_t ** argv )
|
||||
return 0;
|
||||
|
||||
case L'?':
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
builtin_unknown_option( argv[0], argv[woptind-1] );
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if( report_all )
|
||||
{
|
||||
if( argc - woptind == 0 )
|
||||
{
|
||||
print_all( hard );
|
||||
}
|
||||
else
|
||||
{
|
||||
sb_append( sb_err,
|
||||
argv[0],
|
||||
L": Too many arguments\n",
|
||||
(void *)0 );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch( argc - woptind )
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
/*
|
||||
Show current limit value
|
||||
*/
|
||||
if( report_all )
|
||||
{
|
||||
print_all( hard );
|
||||
}
|
||||
else
|
||||
{
|
||||
print( what, hard );
|
||||
}
|
||||
|
||||
print( what, hard );
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
case 1:
|
||||
{
|
||||
/*
|
||||
@@ -457,7 +461,7 @@ static int builtin_ulimit( wchar_t ** argv )
|
||||
*/
|
||||
rlim_t new_limit;
|
||||
wchar_t *end;
|
||||
|
||||
|
||||
/*
|
||||
Set both hard and soft limits if nothing else was specified
|
||||
*/
|
||||
@@ -466,7 +470,6 @@ static int builtin_ulimit( wchar_t ** argv )
|
||||
hard=soft=1;
|
||||
}
|
||||
|
||||
|
||||
if( wcscasecmp( argv[woptind], L"unlimited" )==0)
|
||||
{
|
||||
new_limit = RLIM_INFINITY;
|
||||
@@ -492,30 +495,22 @@ static int builtin_ulimit( wchar_t ** argv )
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
new_limit *= get_multiplier( what );
|
||||
}
|
||||
|
||||
if( report_all )
|
||||
{
|
||||
return set_all( hard, soft, new_limit );
|
||||
}
|
||||
else
|
||||
{
|
||||
return set( what, hard, soft, new_limit );
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
return set( what, hard, soft, new_limit );
|
||||
}
|
||||
|
||||
default:
|
||||
sb_append2( sb_err,
|
||||
{
|
||||
sb_append( sb_err,
|
||||
argv[0],
|
||||
L": Too many arguments\n",
|
||||
(void *)0 );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
292
common.c
292
common.c
@@ -44,6 +44,10 @@ parts of fish.
|
||||
#include <sys/time.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
|
||||
#ifndef HOST_NAME_MAX
|
||||
/**
|
||||
Maximum length of hostname return. It is ok if this is too short,
|
||||
@@ -110,6 +114,28 @@ static struct winsize termsize;
|
||||
*/
|
||||
static string_buffer_t *setlocale_buff=0;
|
||||
|
||||
|
||||
void show_stackframe()
|
||||
{
|
||||
void *trace[32];
|
||||
char **messages = (char **)NULL;
|
||||
int i, trace_size = 0;
|
||||
|
||||
trace_size = backtrace(trace, 32);
|
||||
messages = backtrace_symbols(trace, trace_size);
|
||||
|
||||
if( messages )
|
||||
{
|
||||
debug( 0, L"Backtrace:" );
|
||||
for( i=0; i<trace_size; i++ )
|
||||
{
|
||||
fwprintf( stderr, L"%s\n", messages[i]);
|
||||
}
|
||||
free( messages );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
wchar_t **list_to_char_arr( array_list_t *l )
|
||||
{
|
||||
wchar_t ** res = malloc( sizeof(wchar_t *)*(al_get_count( l )+1) );
|
||||
@@ -157,8 +183,6 @@ int fgetws2( wchar_t **b, int *len, FILE *f )
|
||||
|
||||
if( errno == EILSEQ )
|
||||
{
|
||||
|
||||
getc( f );
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -190,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);
|
||||
@@ -202,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 )
|
||||
@@ -234,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++;
|
||||
@@ -250,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;
|
||||
|
||||
@@ -300,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;
|
||||
}
|
||||
@@ -347,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;
|
||||
@@ -510,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;
|
||||
@@ -548,14 +581,17 @@ int read_blocked(int fd, void *buf, size_t count)
|
||||
void debug( int level, const wchar_t *msg, ... )
|
||||
{
|
||||
va_list va;
|
||||
|
||||
string_buffer_t sb;
|
||||
string_buffer_t sb2;
|
||||
|
||||
int errno_old = errno;
|
||||
|
||||
CHECK( msg, );
|
||||
|
||||
if( level > debug_level )
|
||||
return;
|
||||
|
||||
CHECK( msg, );
|
||||
|
||||
sb_init( &sb );
|
||||
sb_init( &sb2 );
|
||||
|
||||
@@ -570,6 +606,8 @@ void debug( int level, const wchar_t *msg, ... )
|
||||
|
||||
sb_destroy( &sb );
|
||||
sb_destroy( &sb2 );
|
||||
|
||||
errno = errno_old;
|
||||
}
|
||||
|
||||
void write_screen( const wchar_t *msg, string_buffer_t *buff )
|
||||
@@ -664,17 +702,50 @@ 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 )
|
||||
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__ );
|
||||
exit(1);
|
||||
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;
|
||||
@@ -699,6 +770,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
|
||||
@@ -709,29 +781,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' ':
|
||||
@@ -749,12 +836,11 @@ wchar_t *escape( const wchar_t *in,
|
||||
case L'*':
|
||||
case L'|':
|
||||
case L';':
|
||||
case L':':
|
||||
case L'\'':
|
||||
case L'"':
|
||||
case L'%':
|
||||
case L'~':
|
||||
{
|
||||
need_escape=1;
|
||||
if( escape_all )
|
||||
*pos++ = L'\\';
|
||||
*pos++ = *in;
|
||||
@@ -765,11 +851,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
|
||||
{
|
||||
@@ -783,11 +882,22 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
||||
wchar_t *unescape( const wchar_t * orig, int flags )
|
||||
{
|
||||
|
||||
int mode = 0;
|
||||
@@ -796,7 +906,9 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
||||
int bracket_count=0;
|
||||
wchar_t prev=0;
|
||||
wchar_t *in;
|
||||
|
||||
int unescape_special = flags & UNESCAPE_SPECIAL;
|
||||
int allow_incomplete = flags & UNESCAPE_INCOMPLETE;
|
||||
|
||||
CHECK( orig, 0 );
|
||||
|
||||
len = wcslen( orig );
|
||||
@@ -829,10 +941,13 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
||||
*/
|
||||
case L'\0':
|
||||
{
|
||||
free(in);
|
||||
return 0;
|
||||
if( !allow_incomplete )
|
||||
{
|
||||
free(in);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Numeric escape sequences. No prefix means
|
||||
octal escape, otherwise hexadecimal.
|
||||
@@ -966,7 +1081,7 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
||||
}
|
||||
|
||||
/*
|
||||
\e means escape
|
||||
\x1b means escape
|
||||
*/
|
||||
case L'e':
|
||||
{
|
||||
@@ -1011,7 +1126,7 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
||||
}
|
||||
|
||||
/*
|
||||
\v means vetrical tab
|
||||
\v means vertical tab
|
||||
*/
|
||||
case L'v':
|
||||
{
|
||||
@@ -1149,6 +1264,8 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
||||
mode = 1;
|
||||
if( unescape_special )
|
||||
in[out_pos] = INTERNAL_SEPARATOR;
|
||||
else
|
||||
out_pos--;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1157,6 +1274,8 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
||||
mode = 2;
|
||||
if( unescape_special )
|
||||
in[out_pos] = INTERNAL_SEPARATOR;
|
||||
else
|
||||
out_pos--;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1189,8 +1308,13 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
||||
|
||||
case 0:
|
||||
{
|
||||
free(in);
|
||||
return 0;
|
||||
if( !allow_incomplete )
|
||||
{
|
||||
free(in);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
out_pos--;
|
||||
}
|
||||
|
||||
default:
|
||||
@@ -1205,6 +1329,8 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
||||
{
|
||||
if( unescape_special )
|
||||
in[out_pos] = INTERNAL_SEPARATOR;
|
||||
else
|
||||
out_pos--;
|
||||
mode = 0;
|
||||
}
|
||||
else
|
||||
@@ -1227,6 +1353,8 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
||||
mode = 0;
|
||||
if( unescape_special )
|
||||
in[out_pos] = INTERNAL_SEPARATOR;
|
||||
else
|
||||
out_pos--;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1236,8 +1364,13 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
||||
{
|
||||
case L'\0':
|
||||
{
|
||||
free(in);
|
||||
return 0;
|
||||
if( !allow_incomplete )
|
||||
{
|
||||
free(in);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
out_pos--;
|
||||
}
|
||||
|
||||
case '\\':
|
||||
@@ -1283,6 +1416,13 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !allow_incomplete && mode )
|
||||
{
|
||||
free( in );
|
||||
return 0;
|
||||
}
|
||||
|
||||
in[out_pos]=L'\0';
|
||||
return in;
|
||||
}
|
||||
@@ -1425,7 +1565,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;
|
||||
@@ -1543,6 +1683,7 @@ void tokenize_variable_array( const wchar_t *val, array_list_t *out )
|
||||
{
|
||||
wchar_t *cpy = wcsdup( val );
|
||||
wchar_t *pos, *start;
|
||||
wchar_t *next;
|
||||
|
||||
if( !cpy )
|
||||
{
|
||||
@@ -1553,12 +1694,19 @@ void tokenize_variable_array( const wchar_t *val, array_list_t *out )
|
||||
{
|
||||
if( *pos == ARRAY_SEP )
|
||||
{
|
||||
|
||||
*pos=0;
|
||||
al_push( out, start==cpy?cpy:wcsdup(start) );
|
||||
next = start==cpy?cpy:wcsdup(start);
|
||||
if( !next )
|
||||
DIE_MEM();
|
||||
al_push( out, next );
|
||||
start=pos+1;
|
||||
}
|
||||
}
|
||||
al_push( out, start==cpy?cpy:wcsdup(start) );
|
||||
next = start==cpy?cpy:wcsdup(start);
|
||||
if( !next )
|
||||
DIE_MEM();
|
||||
al_push( out, next );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1602,3 +1750,53 @@ int create_directory( wchar_t *d )
|
||||
return ok?0:-1;
|
||||
}
|
||||
|
||||
void bugreport()
|
||||
{
|
||||
debug( 1,
|
||||
_( 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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
132
common.h
132
common.h
@@ -40,6 +40,25 @@
|
||||
*/
|
||||
#define BYTE_MAX 0xffu
|
||||
|
||||
/*
|
||||
Escape special fish syntax characters liek 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
|
||||
*/
|
||||
@@ -72,23 +91,34 @@ extern wchar_t *program_name;
|
||||
This macro is used to check that an input argument is not null. It
|
||||
is a bit lika a non-fatal form of assert. Instead of exit-ing on
|
||||
failiure, the current function is ended at once. The second
|
||||
parameter is the exit status of the current function on failiure.
|
||||
parameter is the return value of the current function on failiure.
|
||||
*/
|
||||
#define CHECK( arg, retval ) \
|
||||
if( !(arg) ) \
|
||||
{ \
|
||||
debug( 1, \
|
||||
_( L"function %s called with null value for argument %s. " \
|
||||
L"This is a bug. " \
|
||||
L"If you can reproduce it, please send a bug report to %s." ), \
|
||||
debug( 0, \
|
||||
_( L"function %s called with null value for argument %s. " ), \
|
||||
__func__, \
|
||||
#arg, \
|
||||
PACKAGE_BUGREPORT ); \
|
||||
#arg ); \
|
||||
bugreport(); \
|
||||
show_stackframe(); \
|
||||
return retval; \
|
||||
}
|
||||
|
||||
/**
|
||||
Exit program at once, leaving an error message about running out of memory
|
||||
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 ); \
|
||||
} \
|
||||
|
||||
|
||||
/**
|
||||
Exit program at once, leaving an error message about running out of memory.
|
||||
*/
|
||||
#define DIE_MEM() \
|
||||
{ \
|
||||
@@ -96,31 +126,22 @@ extern wchar_t *program_name;
|
||||
L"fish: Out of memory on line %d of file %s, shutting down fish\n", \
|
||||
__LINE__, \
|
||||
__FILE__ ); \
|
||||
exit(1); \
|
||||
FATAL_EXIT(); \
|
||||
}
|
||||
|
||||
/**
|
||||
Cause fish to crash. This should only be usd for debugging.
|
||||
Check if signals are blocked. If so, print an error message and
|
||||
return from the function performing this check.
|
||||
*/
|
||||
#define CRASH() \
|
||||
{ \
|
||||
int *n = 0; \
|
||||
*n = 1; \
|
||||
}
|
||||
|
||||
/**
|
||||
Check if signals are blocked
|
||||
*/
|
||||
#define CHECK_BLOCK( retval ) \
|
||||
#define CHECK_BLOCK( retval ) \
|
||||
if( signal_is_blocked() ) \
|
||||
{ \
|
||||
debug( 0, \
|
||||
L"function %s called while blocking signals. " \
|
||||
L"This is a bug. " \
|
||||
L"If you can reproduce it, please send a bug report to %s.", \
|
||||
__func__, \
|
||||
PACKAGE_BUGREPORT ); \
|
||||
return retval; \
|
||||
_( L"function %s called while blocking signals. " ), \
|
||||
__func__); \
|
||||
bugreport(); \
|
||||
show_stackframe(); \
|
||||
return retval; \
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,17 +150,23 @@ extern wchar_t *program_name;
|
||||
#define _(wstr) wgettext(wstr)
|
||||
|
||||
/**
|
||||
Noop, used to tell xgettext that a string should be translated, even though it is not directly sent to wgettext.
|
||||
Noop, used to tell xgettext that a string should be translated,
|
||||
even though it is not directly sent to wgettext.
|
||||
*/
|
||||
#define N_(wstr) wstr
|
||||
|
||||
#define contains( str,... ) contains_internal( str, __VA_ARGS__, (void *)0 )
|
||||
#define wcsdupcat( str,... ) wcsdupcat_internal( str, __VA_ARGS__, (void *)0 )
|
||||
|
||||
/*
|
||||
Print a stack trace to stderr
|
||||
*/
|
||||
void show_stackframe();
|
||||
|
||||
/**
|
||||
Take an array_list_t containing wide strings and converts them to a
|
||||
single null-terminated wchar_t **. The array is allocated using
|
||||
halloc, and uses the \c context parameter as context. If \c context
|
||||
is not noll, all elements of the \c array_list_t are also
|
||||
registered to \c context using \c halloc_register().
|
||||
malloc, and needs to be fred's by the caller.
|
||||
*/
|
||||
wchar_t **list_to_char_arr( array_list_t *l );
|
||||
|
||||
@@ -211,17 +238,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
|
||||
@@ -291,13 +313,14 @@ 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);
|
||||
|
||||
@@ -306,6 +329,10 @@ int read_blocked(int fd, void *buf, size_t count);
|
||||
Issue a debug message with printf-style string formating and
|
||||
automatic line breaking. The string will begin with the string \c
|
||||
program_name, followed by a colon and a whitespace.
|
||||
|
||||
Because debug is often called to tell the user about an error,
|
||||
before using wperror to give a specific error message, debug will
|
||||
never ever modify the value of errno.
|
||||
|
||||
\param level the priority of the message. Lower number means higher priority. Messages with a priority_number higher than \c debug_level will be ignored..
|
||||
\param msg the message format string.
|
||||
@@ -355,17 +382,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.
|
||||
*/
|
||||
@@ -394,13 +421,24 @@ 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 );
|
||||
|
||||
/**
|
||||
Print a short message about how to file a bug report to stderr
|
||||
*/
|
||||
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 );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
1448
complete.c
1448
complete.c
File diff suppressed because it is too large
Load Diff
95
complete.h
95
complete.h
@@ -67,15 +67,68 @@
|
||||
#define PROG_COMPLETE_SEP L'\t'
|
||||
|
||||
/**
|
||||
Terminator for completions sent to the fish_pager
|
||||
Do not insert space afterwards if this is the only completion. (The
|
||||
default is to try insert a space)
|
||||
*/
|
||||
#define COMPLETE_TERMINATOR L'\006'
|
||||
#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
|
||||
|
||||
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.
|
||||
|
||||
Values are copied and should be freed by the caller.
|
||||
All supplied values are copied, they should be freed by or otherwise
|
||||
disposed by the caller.
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -109,7 +162,6 @@
|
||||
file completion is not performed.
|
||||
\param comp A space separated list of completions which may contain subshells.
|
||||
\param desc A description of the completion.
|
||||
\param authorative Whether there list of completions 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.
|
||||
\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.
|
||||
|
||||
*/
|
||||
@@ -119,10 +171,18 @@ void complete_add( const wchar_t *cmd,
|
||||
const wchar_t *long_opt,
|
||||
int long_mode,
|
||||
int result_mode,
|
||||
int authorative,
|
||||
const wchar_t *condition,
|
||||
const wchar_t *comp,
|
||||
const wchar_t *desc );
|
||||
const wchar_t *desc,
|
||||
int flags );
|
||||
/**
|
||||
Sets whether the completion list for this command is complete. If
|
||||
true, any options not matching one of the provided options will be
|
||||
flagged as an error by syntax highlighting.
|
||||
*/
|
||||
void complete_set_authoritative( const wchar_t *cmd,
|
||||
int cmd_type,
|
||||
int authoritative );
|
||||
|
||||
/**
|
||||
Remove a previously defined completion
|
||||
@@ -151,15 +211,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
|
||||
*/
|
||||
@@ -187,4 +238,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
|
||||
\pram 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
|
||||
|
||||
350
configure.ac
350
configure.ac
@@ -9,9 +9,30 @@
|
||||
# configure the build process.
|
||||
#
|
||||
|
||||
AC_INIT(fish,1.22.0,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
|
||||
#
|
||||
@@ -62,7 +83,7 @@ if test ! -f ./config.h.in -o config.h.in -ot configure.ac; then
|
||||
[cannot find the autoheader program in your path.
|
||||
This program needs to be run whenever the configure.ac file is modified.
|
||||
Please install it and try again.]
|
||||
)
|
||||
)
|
||||
fi
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
@@ -86,7 +107,7 @@ for i in /usr/pkg /sw /opt /opt/local; do
|
||||
CPPFLAGS="$CPPFLAGS -I$i/include/"
|
||||
CFLAGS="$CFLAGS -I$i/include/"
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING([for $i/lib library directory])
|
||||
@@ -94,7 +115,7 @@ for i in /usr/pkg /sw /opt /opt/local; do
|
||||
AC_MSG_RESULT(yes)
|
||||
LDFLAGS="$LDFLAGS -L$i/lib/ -R$i/lib/"
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING([for $i/bin command directory])
|
||||
@@ -102,13 +123,11 @@ for i in /usr/pkg /sw /opt /opt/local; do
|
||||
AC_MSG_RESULT(yes)
|
||||
optbindirs="$optbindirs $i/bin"
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
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.
|
||||
@@ -147,6 +168,29 @@ AC_PROG_INSTALL
|
||||
AC_CHECK_PROG( SEQ_FALLBACK, seq, [ ], [seq])
|
||||
|
||||
|
||||
if test "$SEQ_FALLBACK"; then
|
||||
|
||||
#
|
||||
# We already have seq. Check if the seq version is installed by an
|
||||
# earlier fish version. If it is, we'll replace it.
|
||||
#
|
||||
|
||||
file=`which seq`
|
||||
if test -f "$file"; then
|
||||
|
||||
AC_MSG_CHECKING([if seq comes from a previous fish version])
|
||||
shebang=`grep "\(^#!/.*/fish\|^#!/usr/bin/env fish\)" $file`
|
||||
|
||||
if test "$shebang"; then
|
||||
SEQ_FALLBACK=seq
|
||||
AC_MSG_RESULT(yes, replace it)
|
||||
else
|
||||
AC_MSG_RESULT(no, keep it)
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Optionally drop xsel command
|
||||
#
|
||||
@@ -162,61 +206,87 @@ 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
|
||||
|
||||
|
||||
#
|
||||
# Optionally drop gettext support
|
||||
#
|
||||
|
||||
AC_ARG_WITH(
|
||||
gettext,
|
||||
AC_HELP_STRING(
|
||||
[--without-gettext],
|
||||
[do not translate messages, even if gettext is available]
|
||||
),
|
||||
[local_gettext=$withval],
|
||||
[local_gettext=yes]
|
||||
)
|
||||
|
||||
if test x$local_gettext != xno; then
|
||||
AC_DEFINE([USE_GETTEXT],[1],[Perform string translations with gettext])
|
||||
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
|
||||
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 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"
|
||||
|
||||
#
|
||||
# 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
|
||||
@@ -237,6 +307,12 @@ if test "$CC" = gcc; then
|
||||
|
||||
CFLAGS="$CFLAGS -Wall"
|
||||
|
||||
#
|
||||
# This is needed in order to get the really cool backtraces
|
||||
#
|
||||
|
||||
LDFLAGS_FISH="$LDFLAGS_FISH -rdynamic"
|
||||
|
||||
fi
|
||||
|
||||
|
||||
@@ -297,7 +373,7 @@ fi
|
||||
AC_CANONICAL_TARGET
|
||||
|
||||
if test $target_cpu = powerpc; then
|
||||
AC_DEFINE([TPUTS_KLUDGE],[1],[Evil kludge to get Power based machines to work])
|
||||
AC_DEFINE([TPUTS_KLUDGE],[1],[Evil kludge to get Power based machines to work])
|
||||
fi
|
||||
|
||||
|
||||
@@ -316,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
|
||||
@@ -342,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
|
||||
|
||||
|
||||
@@ -357,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
|
||||
|
||||
|
||||
@@ -368,7 +469,7 @@ fi
|
||||
# installed.
|
||||
#
|
||||
|
||||
AC_SUBST( [localedir], [$datadir/locale])
|
||||
localedir=$datadir/locale
|
||||
|
||||
|
||||
#
|
||||
@@ -392,20 +493,102 @@ 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.
|
||||
#
|
||||
|
||||
AC_SEARCH_LIBS( gettext, intl,,)
|
||||
# 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])] )
|
||||
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
|
||||
|
||||
|
||||
AC_SEARCH_LIBS( iconv_open, iconv, , [AC_MSG_ERROR([Could not find an iconv implementation, needed to build fish])] )
|
||||
LIBS_FISH=$LIBS
|
||||
LIBS=$LIBS_COMMON
|
||||
|
||||
#
|
||||
# Check for libraries needed by fish_indent.
|
||||
#
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
#
|
||||
|
||||
AC_CHECK_HEADERS([getopt.h termio.h sys/resource.h term.h ncurses/term.h libintl.h ncurses.h curses.h stropts.h siginfo.h sys/select.h sys/ioctl.h sys/termios.h])
|
||||
AC_CHECK_HEADERS([getopt.h termio.h sys/resource.h term.h ncurses/term.h ncurses.h curses.h stropts.h siginfo.h sys/select.h sys/ioctl.h sys/termios.h libintl.h execinfo.h])
|
||||
|
||||
AC_CHECK_HEADER(
|
||||
[regex.h],
|
||||
@@ -414,9 +597,9 @@ AC_CHECK_HEADER(
|
||||
[HAVE_REGEX_H],
|
||||
[1],
|
||||
[Define to 1 if you have the <regex.h> header file.]
|
||||
)],
|
||||
[AC_MSG_ERROR([Could not find the header regex.h, needed to build fish])
|
||||
]
|
||||
)
|
||||
],
|
||||
[AC_MSG_ERROR([Could not find the header regex.h, needed to build fish])]
|
||||
)
|
||||
|
||||
|
||||
@@ -424,7 +607,7 @@ AC_CHECK_HEADER(
|
||||
# On some platforms (Solaris 10) adding -std=c99 in turn requires that
|
||||
# _POSIX_C_SOURCE be defined to 200112L otherwise several
|
||||
# POSIX-specific, non-ISO-C99 types/prototypes are made unavailable
|
||||
# e.g. siginfo_t. Defining _XOPEN_SOURCE to 600 is compatible with
|
||||
# e.g. siginfo_t. Defining _XOPEN_SOURCE to 600 is compatible with
|
||||
# the _POSIX_C_SOURCE value and provides a little assurance that
|
||||
# extension functions' prototypes are available, e.g. killpg().
|
||||
#
|
||||
@@ -546,17 +729,19 @@ fi
|
||||
# Check for presense of various functions used by fish
|
||||
#
|
||||
|
||||
AC_CHECK_FUNCS( gettext wcsdup wcsndup wcslen wcscasecmp wcsncasecmp fwprintf )
|
||||
AC_CHECK_FUNCS( wcsdup wcsndup wcslen wcscasecmp wcsncasecmp fwprintf )
|
||||
AC_CHECK_FUNCS( futimes wcwidth wcswidth wcstok fputwc fgetwc )
|
||||
AC_CHECK_FUNCS( wcstol dcgettext wcslcat wcslcpy lrand48_r killpg)
|
||||
|
||||
AC_CHECK_FUNCS( wcstol wcslcat wcslcpy lrand48_r killpg gettext )
|
||||
AC_CHECK_FUNCS( dcgettext backtrace backtrace_symbols sysconf )
|
||||
|
||||
#
|
||||
# The Makefile also needs to know if we have gettext, so it knows if
|
||||
# the translations should be installed.
|
||||
#
|
||||
|
||||
AC_CHECK_FUNC( gettext, AC_SUBST( HAVE_GETTEXT, 1 ), AC_SUBST( HAVE_GETTEXT, 0 ) )
|
||||
if test x$local_gettext != xno; then
|
||||
AC_CHECK_FUNC( gettext, HAVE_GETTEXT=1, HAVE_GETTEXT=0 )
|
||||
fi
|
||||
|
||||
#
|
||||
# Here follows a list of small programs used to test for various
|
||||
@@ -658,10 +843,10 @@ if test "$ac_cv_func_fwprintf" = yes; then
|
||||
]
|
||||
)
|
||||
],
|
||||
[
|
||||
[
|
||||
AC_MSG_RESULT(no)
|
||||
],
|
||||
[
|
||||
[
|
||||
AC_MSG_RESULT([yes])
|
||||
AC_DEFINE([HAVE_BROKEN_FWPRINTF], [1], [Define to 1 one if the implemented fwprintf is broken])
|
||||
]
|
||||
@@ -694,7 +879,32 @@ if test "$have__nl_msg_cat_cntr" = yes; then
|
||||
[Define to 1 if the _nl_msg_cat_cntr symbol is exported.]
|
||||
)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
# Check for __environ symbol
|
||||
AC_MSG_CHECKING([for __environ symbol])
|
||||
AC_TRY_LINK(
|
||||
[
|
||||
#include <unistd.h>
|
||||
],
|
||||
[
|
||||
extern char **__environ;
|
||||
char **tmp = __environ;
|
||||
exit(tmp!=0);
|
||||
],
|
||||
have___environ=yes,
|
||||
have___environ=no
|
||||
)
|
||||
if test "$have___environ" = yes; then
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(
|
||||
[HAVE___ENVIRON],
|
||||
[1],
|
||||
[Define to 1 if the __environ symbol is exported.]
|
||||
)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
# Check if getopt_long exists and works
|
||||
@@ -730,7 +940,7 @@ if test "$have_working_getopt_long" = yes; then
|
||||
[Define to 1 if getopt_long exists and works.]
|
||||
)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
# Check if del_curterm is broken - in that case we redefine
|
||||
@@ -752,7 +962,7 @@ case $target_os in
|
||||
esac
|
||||
|
||||
# Tell the world what we know
|
||||
AC_CONFIG_FILES([Makefile fish.spec doc_src/Doxyfile seq])
|
||||
AC_CONFIG_FILES([Makefile fish.spec Doxyfile.help seq])
|
||||
AC_OUTPUT
|
||||
|
||||
if test ! x$local_found_posix_switch = xyes; then
|
||||
|
||||
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;
|
||||
}
|
||||
121
create_wajig_completions.py
Executable file
121
create_wajig_completions.py
Executable file
@@ -0,0 +1,121 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- python -*-
|
||||
|
||||
# Program to generate fish completion function for wajig.
|
||||
# It runs 'wajig command' and analyzes the output to build a
|
||||
# completion file which it writes to stdout.
|
||||
# To use the result, direct stdout to
|
||||
# ~/.fish.d/completions/wajig.fish.
|
||||
|
||||
# Author Reuben Thomas, from Don Rozenberg's bash_completion.py and
|
||||
# fish's apt-get.fish.
|
||||
|
||||
import os
|
||||
import re
|
||||
import pprint
|
||||
pp = pprint.PrettyPrinter()
|
||||
|
||||
def escape_quotes(s):
|
||||
return re.sub('\'', '\\\'', s)
|
||||
|
||||
# Run wajig command
|
||||
f = os.popen('wajig commands', 'r')
|
||||
|
||||
lines = f.readlines()
|
||||
|
||||
option_patt = r'^-([a-z]*)\|--([a-z]*) +([^ ].*)'
|
||||
option_patt_r = re.compile(option_patt)
|
||||
|
||||
command_patt = r'^([a-z-]*) +([^ ].*)'
|
||||
command_patt_r = re.compile(command_patt)
|
||||
|
||||
os_str = []
|
||||
os_str.append('')
|
||||
ol_str = []
|
||||
ol_str.append('')
|
||||
oh_str = []
|
||||
oh_str.append('')
|
||||
o_i = 0
|
||||
|
||||
c_str = []
|
||||
c_str.append('')
|
||||
ch_str = []
|
||||
ch_str.append('')
|
||||
c_i = 0
|
||||
|
||||
for l in lines:
|
||||
l = l.strip()
|
||||
if l == '' or l.find(':') > -1 or l.find('Run') == 0:
|
||||
continue
|
||||
if l.find('-') == 0:
|
||||
mo = option_patt_r.search(l)
|
||||
if mo == None:
|
||||
continue
|
||||
os_str[o_i] = mo.group(1)
|
||||
os_str.append('')
|
||||
ol_str[o_i] = mo.group(2)
|
||||
ol_str.append('')
|
||||
oh_str[o_i] = escape_quotes(mo.group(3))
|
||||
oh_str.append('')
|
||||
o_i += 1
|
||||
else:
|
||||
mo = command_patt_r.search(l)
|
||||
if mo == None:
|
||||
continue
|
||||
c_str[c_i] = mo.group(1)
|
||||
c_str.append('')
|
||||
ch_str[c_i] = escape_quotes(mo.group(2))
|
||||
ch_str.append('')
|
||||
c_i += 1
|
||||
|
||||
# For debugging, print the commands and options.
|
||||
#print
|
||||
#pp.pprint(c_str)
|
||||
|
||||
#print
|
||||
#pp.pprint(os_str)
|
||||
#print
|
||||
#pp.pprint(ol_str)
|
||||
|
||||
part1 = '''function __fish_wajig_no_subcommand -d (N_ 'Test if wajig has yet to be given the subcommand')
|
||||
for i in (commandline -opc)
|
||||
if contains -- $i'''
|
||||
|
||||
part2 = '''
|
||||
return 1
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
function __fish_wajig_use_package -d (N_ 'Test if wajig command should have packages as potential completion')
|
||||
for i in (commandline -opc)
|
||||
if contains -- $i contains bug build build-depend changelog dependents describe detail hold install installr installrs installs list list-files news package purge purge-depend readme recursive recommended reconfigure reinstall remove remove-depend repackage show showinstall showremove showupgrade size sizes source suggested unhold upgrade versions whatis
|
||||
return 0
|
||||
end
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
complete -c wajig -n '__fish_wajig_use_package' -a '(__fish_print_packages)' -d (N_ 'Package')'''
|
||||
|
||||
wajig = part1
|
||||
|
||||
#add the commands.
|
||||
for i in range(0, len(c_str) - 1):
|
||||
wajig = "%s %s" % (wajig, c_str[i])
|
||||
|
||||
#add part2
|
||||
wajig = "%s%s" % (wajig, part2)
|
||||
|
||||
#add the options.
|
||||
wajig = "%s%s" % (wajig, os_str[0].lstrip())
|
||||
for i in range(1, len(os_str) - 1):
|
||||
wajig = "%s\ncomplete -c apt-get -s %s -l %s -d (N_ '%s')" % (wajig, os_str[i], ol_str[i], oh_str[i])
|
||||
|
||||
#add the commands.
|
||||
for i in range(0, len(c_str) - 1):
|
||||
wajig = "%s\ncomplete -f -n '__fish_wajig_no_subcommand' -c wajig -a '%s' -d(N_ '%s')" % (wajig, c_str[i], ch_str[i])
|
||||
|
||||
#print it all
|
||||
print wajig
|
||||
18
doc_src/alias.txt
Normal file
18
doc_src/alias.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
\section alias alias - create a function
|
||||
|
||||
\subsection alias-synopsis Synopsis
|
||||
<pre>alias NAME DEFINITION
|
||||
alias NAME=DEFINITION</pre>
|
||||
|
||||
\subsection alias-description Description
|
||||
|
||||
Alias is a shellscript wrapper around the function builtin.
|
||||
It exists for backwards compatibility with Posix
|
||||
shells. For other uses, it is recommended to define a <a
|
||||
href='#function'>function</a>.
|
||||
|
||||
Alias does not keep track of which functions have been defined using
|
||||
alias, nor does it allow erasing of aliases.
|
||||
|
||||
- NAME is the name of the function to define
|
||||
- DEFINITION is the body of the function. The string " $argv" will be appended to the body.
|
||||
@@ -10,10 +10,14 @@ status (as set by the last previous command) is 0.
|
||||
|
||||
The and command does not change the current exit status.
|
||||
|
||||
The exit status of the last foreground command to exit can always be
|
||||
accessed using the <a href="index.html#variables-status">$status</a>
|
||||
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 succceeds, the program is installed. If either step fails,
|
||||
<tt>make clean</tt> is run, which removes the files created by the
|
||||
build process
|
||||
|
||||
|
||||
@@ -23,11 +23,11 @@ scope, they will be automatically deleted when the block ends.
|
||||
|
||||
<pre>
|
||||
begin
|
||||
set -x PIRATE Yarrr
|
||||
set -l PIRATE Yarrr
|
||||
...
|
||||
end
|
||||
# This will not output anything, since PIRATE went out of scope at the end of
|
||||
# the block and was killed
|
||||
# This will not output anything, since the PIRATE variable went out
|
||||
# of scope at the end of the block
|
||||
echo $PIRATE
|
||||
</pre>
|
||||
|
||||
|
||||
@@ -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,54 @@
|
||||
\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, Alt-w can be
|
||||
written as <tt>\\ew</tt>, and Control-x can be written as
|
||||
<tt>\\cx</tt>.
|
||||
|
||||
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.
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
- <tt>-n</tt> or <tt>--names</tt> List the names of all defined builtins
|
||||
|
||||
Prefixing a command with the word 'builtin' forces fish to ignore any aliases with the same name.
|
||||
Prefixing a command with the word 'builtin' forces fish to ignore any functions with the same name.
|
||||
|
||||
\subsection builtin-example Example
|
||||
|
||||
|
||||
@@ -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 statementes 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
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
<tt>command COMMANDNAME [OPTIONS...]</tt>
|
||||
|
||||
\subsection command-description Description
|
||||
prefixing a command with the word 'command' forces fish to ignore any aliases or builtins with the same name.
|
||||
prefixing a command with the word 'command' forces fish to ignore any functions or builtins with the same name.
|
||||
|
||||
\subsection command-example Example
|
||||
|
||||
|
||||
<tt>command ls</tt>
|
||||
|
||||
causes fish to execute the ls program, even if there exists a 'ls' alias.
|
||||
causes fish to execute the ls program, even if there exists a 'ls' function.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -20,7 +22,7 @@ The following switches change what the commandline builtin does
|
||||
will cause any additional arguments to be interpreted as readline
|
||||
functions, and these functions will be injected into the reader, so
|
||||
that they will be returned to the reader before any additional
|
||||
actual keypresses are read.
|
||||
actual key presses are read.
|
||||
|
||||
|
||||
The following switches change the way \c commandline updates the
|
||||
@@ -39,7 +41,7 @@ or updated
|
||||
- \c -b or \c --current-buffer select the entire buffer (default)
|
||||
- \c -j or \c --current-job select the current job
|
||||
- \c -p or \c --current-process select the current process
|
||||
- \c -t or \c --current_token select the current token.
|
||||
- \c -t or \c --current-token select the current token.
|
||||
|
||||
The following switch changes the way \c commandline prints the current
|
||||
commandline buffer
|
||||
|
||||
6
doc_src/commands.hdr.in
Normal file
6
doc_src/commands.hdr.in
Normal file
@@ -0,0 +1,6 @@
|
||||
/** \page commands Commands, functions and builtins bundled with fish
|
||||
Fish ships with a large number of builtin commands, shellscript functions and external commands. These are all described below.
|
||||
|
||||
@command_list@
|
||||
|
||||
*/
|
||||
@@ -21,7 +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>-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.
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -71,6 +71,8 @@ in a nonstandard location. Please contact the <a
|
||||
href='mailto:fish-users@lists.sf.net'>fish mailing list</a>, and
|
||||
hopefully this can be resolved.
|
||||
|
||||
<hr>
|
||||
|
||||
\section faq-default How do I make fish my default shell?
|
||||
|
||||
If you installed fish manually (e.g. by compiling it, not by using a
|
||||
@@ -78,6 +80,23 @@ package manager), you first need to add fish to the list of shells by
|
||||
executing the following command (assuming you installed fish in
|
||||
/usr/local) as root:
|
||||
|
||||
|
||||
<code>echo /usr/local/bin/fish >>/etc/shells</code>
|
||||
|
||||
If you installed a prepackaged version of fish, the package manager
|
||||
should have already done this for you.
|
||||
|
||||
In order to change your default shell, type:
|
||||
|
||||
<code>chsh -s /usr/local/bin/fish</code>
|
||||
|
||||
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.
|
||||
|
||||
<hr>
|
||||
|
||||
\section faq-titlebar I'm seeing weird output before each prompt when using screen. What's wrong?
|
||||
|
||||
Quick answer:
|
||||
@@ -106,21 +125,6 @@ Note that fish has a default titlebar message, which will be used if
|
||||
the fish_title function is undefined. So simply unsetting the
|
||||
fish_title function will not work.
|
||||
|
||||
|
||||
<code>echo /usr/local/bin/fish >>/etc/shells</code>
|
||||
|
||||
If you installed a prepackaged version of fish, the package manager
|
||||
should have already done this for you.
|
||||
|
||||
In order to change your default shell, type:
|
||||
|
||||
<code>chsh -s /usr/bin/fish</code>
|
||||
|
||||
You may need to adjust the above path to e.g. /usr/local/bin/fish.
|
||||
|
||||
You will need to log out and back in again for the change to take
|
||||
effect.
|
||||
|
||||
<hr>
|
||||
|
||||
\section faq-greeting How do I change the greeting message?
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
.TH fish 1 "February 25, 2005" "version @PACKAGE_VERSION@" "USER COMMANDS"
|
||||
.SH NAME
|
||||
fish - friendly interactive shell
|
||||
.SH SYNOPSIS
|
||||
.B fish
|
||||
[\-h] [\-v] [\-c command] [FILE [ARGUMENTS...]]
|
||||
.SH DESCRIPTION
|
||||
A shell written mainly with interactive use in mind. The complete fish manuals are written in HTML format. You can find them by using the
|
||||
.I
|
||||
help
|
||||
command from inside the fish shell.
|
||||
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
\-h
|
||||
display help and exit
|
||||
.TP
|
||||
\-c
|
||||
Evaluate the specified commands instead of reading from the commandline
|
||||
.TP
|
||||
\-i
|
||||
Specify that fish is to run in interactive mode
|
||||
.TP
|
||||
\-v
|
||||
display version and exit
|
||||
.SH AUTHOR
|
||||
Axel Liljencrantz ( @PACKAGE_BUGREPORT@ )
|
||||
@@ -5,7 +5,9 @@ fish [-h] [-v] [-c command] [FILE [ARGUMENTS...]]
|
||||
|
||||
\subsection fish-description Description
|
||||
|
||||
A commandline shell written mainly with interactive use in mind. The full manual is available <a href='index.html'>in html</a> by using the <a href='#help'>help</a> command from inside fish.
|
||||
A commandline shell written mainly with interactive use in mind. The
|
||||
full manual is available <a href='index.html'>in html</a> by using the
|
||||
<a href='#help'>help</a> command from inside fish.
|
||||
|
||||
- <code>-c</code> or <code>--command=COMMANDS</code> evaluate the specified commands instead of reading from the commandline
|
||||
- <code>-d</code> or <code>--debug-level=DEBUG_LEVEL</code> specify the verbosity level of fish. A higher number means higher verbosity. The default level is 1.
|
||||
@@ -16,3 +18,6 @@ A commandline shell written mainly with interactive use in mind. The full manual
|
||||
- <code>-p</code> or <code>--profile=PROFILE_FILE</code> when fish exits, output timing information on all executed commands to the specified file
|
||||
- <code>-v</code> or <code>--version</code> display version and exit
|
||||
|
||||
The fish exit status is generally the exit status of the last
|
||||
foreground command. If fish is exiting because of a parse error, the
|
||||
exit status is 127.
|
||||
|
||||
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 prettyfy a piece of fish
|
||||
code. \c fish_indent reads commands from standard input and outputs
|
||||
them to standard output.
|
||||
|
||||
\c fish_indent underatands the following options:
|
||||
|
||||
- <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 promp
|
||||
|
||||
\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>
|
||||
|
||||
@@ -4,10 +4,20 @@
|
||||
<tt>if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] end</tt>
|
||||
|
||||
\subsection if-description Description
|
||||
<tt>if</tt> will execute the command CONDITION. If the condition's exit
|
||||
status is 0, the commands COMMANDS_TRUE will execute. If it is not 0 and
|
||||
<tt>else</tt> is given, COMMANDS_FALSE will be executed. Hint: use
|
||||
<a href="#begin"><tt>begin; ...; end</tt></a> for complex conditions.
|
||||
|
||||
<tt>if</tt> will execute the command CONDITION. If the condition's
|
||||
exit status is 0, the commands COMMANDS_TRUE will execute. If the
|
||||
exit status is not 0 and <tt>else</tt> is given, COMMANDS_FALSE will
|
||||
be executed.
|
||||
|
||||
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 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
|
||||
accessed using the <a href="index.html#variables-status">$status</a>
|
||||
variable.
|
||||
|
||||
\subsection if-example Example
|
||||
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
/** \mainpage Fish user documentation
|
||||
|
||||
\section toc Table of contents
|
||||
|
||||
- <a href="index.html" name="toc-index">Fish user documentation</a>
|
||||
@toc@
|
||||
|
||||
\section introduction Introduction
|
||||
|
||||
This is the documentation for \c fish, the friendly interactive
|
||||
@@ -26,7 +33,7 @@ assigning variables, commands for treating a group of commands as a
|
||||
single command, etc.. And every single command follows the same simple
|
||||
syntax.
|
||||
|
||||
If you wish to find out more about the echo command used above, read
|
||||
If you want to find out more about the echo command used above, read
|
||||
the manual page for the echo command by writing:
|
||||
|
||||
<code>man echo</code>
|
||||
@@ -63,7 +70,7 @@ A switch is a very common special type of argument. Switches almost
|
||||
always start with one or more hyphens (-) and alter the way a command
|
||||
operates. For example, the \c ls command usually lists all the files
|
||||
and directories in the current working directory, but by using the \c
|
||||
-l switch, the behaviour of ls is changed to not only display the
|
||||
-l switch, the behavior of ls is changed to not only display the
|
||||
filename, but also the size, permissions, owner and modification time
|
||||
of each file. Switches differ between commands and are documented in
|
||||
the manual page for each command. Some switches are common to most
|
||||
@@ -128,11 +135,12 @@ these characters, so called escape sequences are provided. These are:
|
||||
- <code>'\\\<'</code>, escapes the less than character
|
||||
- <code>'\\\>'</code>, escapes the more than character
|
||||
- <code>'\\^'</code>, escapes the circumflex character
|
||||
- <code>'\\x<i>xx</i>'</code>, where <code><i>xx</i></code> is a hexadecimal number, escapes the ascii character with the specified value
|
||||
- <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
|
||||
- <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
|
||||
- <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
|
||||
- <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>'\\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
|
||||
|
||||
@@ -262,12 +270,31 @@ the example above, these are simply passed on to the ls command. For
|
||||
more information on functions, see the documentation for the <a
|
||||
href='commands.html#function'>function</a> builtin.
|
||||
|
||||
\subsubsection Autoloading functions
|
||||
\subsubsection syntax-function-wrappers Defining wrapper functions
|
||||
|
||||
One of the most common used for functions is to slightly alter the
|
||||
behavior of an already existing command. For example, one might want
|
||||
to redefine the \c ls command to display colors. The switch for
|
||||
turning on colors on GNU systems is \c '--color=auto'. A wrapper
|
||||
around \c ls might look like this:
|
||||
|
||||
<pre>function ls
|
||||
ls --color=auto $argv
|
||||
end
|
||||
</pre>
|
||||
|
||||
There are a few important things that need to be noted about wrapper
|
||||
functions:
|
||||
|
||||
- Wrappers should always take care to add the $argv variable to the list of parameters to the wrapped command. This makes sure that if the user specifies any additional parameters to the function, they are passed on to the underlying command.
|
||||
- If the wrapped command is not the first command to be called by the wrapper, it is necessary to prefix the call to the command with the word 'command' in order to tell fish that the function should not call itself, but rather a command with the same name. Failing to do so will cause infinite recursion bugs.
|
||||
|
||||
\subsubsection syntax-function-autoloading Autoloading functions
|
||||
|
||||
Functions can be defined on the commandline or in a configuration
|
||||
file, but they can also be automatically loaded. This method of
|
||||
defining functions has several advantages. An autoloaded function
|
||||
becomes avaialble automatically to all running shells, if the function
|
||||
becomes available automatically to all running shells, if the function
|
||||
definition is changed, all running shells will automatically reload
|
||||
the altered version, startup time and memory usage is improved, etc.
|
||||
|
||||
@@ -293,6 +320,25 @@ definition for the specified function and nothing else, otherwise it
|
||||
is possible that autoloading a function files requires that the
|
||||
function already be loaded, i.e. a circular dependency.
|
||||
|
||||
\subsection syntax-conditional Conditional execution of code
|
||||
|
||||
There are four fish builtins that let you execute commands only if a
|
||||
specific criterion is met. These builtins are
|
||||
<a href="commands.html#if">if</a>,
|
||||
<a href="commands.html#switch">switch</a>,
|
||||
<a href="commands.html#and">and</a> and
|
||||
<a href="commands.html#or">or</a>.
|
||||
|
||||
The \c switch command is used to execute one of possibly many blocks
|
||||
of commands depending on the value of a string. See the documentation
|
||||
for <a href="commands.html#switch">switch</a> for more information.
|
||||
|
||||
The other conditionals use the <a href='#variables-status'>exit
|
||||
status</a> of a command to decide if a command or a block of commands
|
||||
should be executed. See the documentation for
|
||||
<a href="commands.html#if">if</a>, <a href="commands.html#and">and</a>
|
||||
and <a href="commands.html#or">or</a> for more information.
|
||||
|
||||
\subsection syntax-words Some common words
|
||||
|
||||
This is a short explanation of some of the commonly used words in fish.
|
||||
@@ -300,11 +346,11 @@ This is a short explanation of some of the commonly used words in fish.
|
||||
- argument, a parameter given to a command
|
||||
- builtin, a command that is implemented in the shell. Builtins are commands that are so closely tied to the shell that it is impossible to implement them as external commands.
|
||||
- command, a program that the shell can run.
|
||||
- function, a block of commands and arguments that can be called as if they where a single command. By using functions, it is possible to string together multiple smaller commands into one more advanced command.
|
||||
- function, a block of commands that can be called as if they where a single command. By using functions, it is possible to string together multiple smaller commands into one more advanced command.
|
||||
- job, a running pipeline or command
|
||||
- pipeline, a set of commands stringed together so that the output of one command is the input of the next command
|
||||
- redirection, a operation that changes one of the input/output streams associated with a job
|
||||
- switch, a special flag sent as an argument to a command that will alter the behavious of the command. A switch almost always begins with one or two hyphens.
|
||||
- switch, a special flag sent as an argument to a command that will alter the behavior of the command. A switch almost always begins with one or two hyphens.
|
||||
|
||||
\section help Help
|
||||
|
||||
@@ -326,13 +372,13 @@ shell. By tapping the tab key, the user asks \c fish to guess the rest
|
||||
of the command or parameter that the user is currently typing. If \c
|
||||
fish can only find one possible completion, \c fish will write it
|
||||
out. If there is more than one completion, \c fish will write out the
|
||||
longest common prefix that all completions have in common. If all
|
||||
completions differ on the first character, a list of all possible
|
||||
completions is printed. The list features descriptions of the
|
||||
completions and if the list doesn't fit the screen, it is scrollable
|
||||
by using the arrow keys, the page up/page down keys or the space
|
||||
bar. Press any other key will exit the list and insert the pressed key
|
||||
into the command line.
|
||||
longest prefix that all completions have in common. If the completions
|
||||
differ on the first character, a list of all possible completions is
|
||||
printed. The list features descriptions of the completions and if the
|
||||
list doesn't fit the screen, it is scrollable by using the arrow keys,
|
||||
the page up/page down keys, the tab key or the space bar. Pressing any
|
||||
other key will exit the list and insert the pressed key into the
|
||||
command line.
|
||||
|
||||
These are the general purpose tab completions that \c fish provides:
|
||||
|
||||
@@ -351,14 +397,14 @@ manual pages as completions.
|
||||
- The 'make' program uses all targets in the Makefile in
|
||||
the current directory as completions.
|
||||
- The 'mount' command uses all mount points specified in fstab as completions.
|
||||
- The 'ssh' command uses all hosts in that are stored
|
||||
- The 'ssh' command uses all hosts that are stored
|
||||
in the known_hosts file as completions. (see the ssh documentation for more information)
|
||||
- The 'su' command uses all users on the system as completions.
|
||||
- The \c apt-get, \c rpm and \c yum commands use all installed packages as completions.
|
||||
|
||||
\subsection completion-own Writing your own completions
|
||||
|
||||
Specifying your own completions is not complicated. To specify a
|
||||
Specifying your own completions is not difficult. To specify a
|
||||
completion, use the \c complete command. \c complete takes
|
||||
as a parameter the name of the command to specify a completion
|
||||
for. For example, to add a completion for the program \c myprog, one
|
||||
@@ -393,6 +439,65 @@ For examples of how to write your own complex completions, study the
|
||||
completions in /usr/share/fish/completions. (The exact path depends on
|
||||
your chosen installation prefix and may be slightly different)
|
||||
|
||||
\subsection completion-func Useful functions for writing completions
|
||||
|
||||
Fish ships with several functions that are very useful when writing
|
||||
command specific completions. Most of these functions name begins with
|
||||
the string '__fish_'. Such functions are internal to fish and their
|
||||
name and interface may change in future fish versions. Still, some of
|
||||
them may be very useful when writing completions. A few of these
|
||||
functions are described here. Be aware that they may be removed or
|
||||
changed in future versions of fish.
|
||||
|
||||
Functions beginning with the string '__fish_print_' print a
|
||||
newline-separated list of strings. For example,
|
||||
__fish_print_filesystems prints a list of all known file systems. Functions
|
||||
beginning with '__fish_complete_' print out a newline separated list of
|
||||
completions with descriptions. The description is separated from the
|
||||
completion by a tab character.
|
||||
|
||||
<pre>__fish_complete_directories STRING DESCRIPTION</pre>
|
||||
|
||||
performs path completion on STRING, allowing only directories, and giving them the description DESCRIPTION.
|
||||
|
||||
<pre>__fish_complete_groups</pre>
|
||||
|
||||
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.
|
||||
|
||||
<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.
|
||||
|
||||
<pre>__fish_complete_users</pre>
|
||||
|
||||
prints a list of all users with their full name as description.
|
||||
|
||||
<pre>__fish_print_filesystems</pre>
|
||||
|
||||
prints a list of all known file systems. Currently, this is a static
|
||||
list, and not dependent on what file systems the host operating system
|
||||
actually understands.
|
||||
|
||||
<pre>__fish_print_hostnames</pre>
|
||||
|
||||
prints a list of all known hostnames. This functions searches the
|
||||
fstab for nfs servers, ssh for known hosts and checks the /etc/hosts file.
|
||||
|
||||
<pre>__fish_print_interfaces</pre>
|
||||
|
||||
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.
|
||||
|
||||
|
||||
|
||||
\subsection completion-path Where to put completions
|
||||
|
||||
Completions can be defined on the commandline or in a configuration
|
||||
@@ -421,8 +526,11 @@ href='mailto: fish-users@lists.sf.net'>the fish mailinglist</a>.
|
||||
|
||||
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. There are many ways in which the user can specify a
|
||||
parameter to be expanded. These include:
|
||||
the command. Parameter expansion is a powerful set of mechamisms that
|
||||
allow you to expand the parameter in various ways, including
|
||||
performing wildcard matching on files, inserting the value of
|
||||
environment variables into the parameter or even using the output of
|
||||
another command as a parameter list.
|
||||
|
||||
\subsection expand-wildcard Wildcards
|
||||
|
||||
@@ -430,10 +538,19 @@ If a star (*) or a question mark (?) is present in the parameter, \c
|
||||
fish attempts to match the given parameter to any files in such a
|
||||
way that:
|
||||
|
||||
- '?' can match any character except '/'.
|
||||
- '?' can match any single character except '/'.
|
||||
- '*' can match any string of characters not containing '/'. This includes matching an empty string.
|
||||
- '**' matches any string of characters. This includes matching an empty string. The string may include the '/' character but does not need to.
|
||||
|
||||
Wildcard matches are sorted case insensitively. When sorting matches
|
||||
containing numbers, consecutive digits are considered to be one
|
||||
element, so that the strings '1' '5' and '12' would be sorted in the
|
||||
order given.
|
||||
|
||||
File names beginning with a dot are not considered when wildcarding
|
||||
unless a dot is specifically given as the first character of the file
|
||||
name.
|
||||
|
||||
Examples:
|
||||
|
||||
<code>a*</code> matches any files beginning with an 'a' in the current directory.
|
||||
@@ -451,7 +568,7 @@ warning will also be printed.
|
||||
\subsection expand-command-substitution Command substitution
|
||||
|
||||
If a parameter contains a set of parenthesis, the text enclosed by the
|
||||
parenthesis will be interpreted as a list of commands. Om expansion,
|
||||
parenthesis will be interpreted as a list of commands. On expansion,
|
||||
this list is executed, and substituted by the output. If the output is
|
||||
more than one line long, each line will be expanded to a new
|
||||
parameter.
|
||||
@@ -546,11 +663,11 @@ end
|
||||
</pre>
|
||||
|
||||
The above code demonstrates how to use multiple '$' symbols to expand
|
||||
the value of a variable as a variable name. One can simply think of
|
||||
the value of a variable as a variable name. One can think of
|
||||
the $-symbol as a variable dereference operator. When using this
|
||||
feature together with array brackets, the brackets will always match
|
||||
the innermost $ dereference. Thus, $$foo[5] will always mean the fift
|
||||
element of the foo variable should be dereferenced and never that the fift
|
||||
the innermost $ dereference. Thus, $$foo[5] will always mean the fifth
|
||||
element of the foo variable should be dereferenced and never that the fifth
|
||||
element of the doubly dereferenced variable foo. The latter can
|
||||
instead be expressed as $$foo[1][5].
|
||||
|
||||
@@ -593,6 +710,17 @@ All of the above expansions can be combined. If several expansions
|
||||
result in more than one parameter, all possible combinations are
|
||||
created.
|
||||
|
||||
When combining multiple parameter expansions, expansions are performed in the following order:
|
||||
|
||||
- Command substitutions
|
||||
- Variable expansions
|
||||
- Bracket expansion
|
||||
- Pid expansion
|
||||
- Wildcard expansion
|
||||
|
||||
Expansions are performed from right to left, nested bracket expansions
|
||||
are performed from the inside and out.
|
||||
|
||||
Example:
|
||||
|
||||
If the current directory contains the files 'foo' and 'bar', the command
|
||||
@@ -613,8 +741,8 @@ 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>.
|
||||
@@ -623,7 +751,8 @@ Example:
|
||||
|
||||
To use the value of a 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
|
||||
|
||||
@@ -725,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
|
||||
@@ -783,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.
|
||||
@@ -802,21 +931,29 @@ values of most of these variables.
|
||||
- \c status, which is the exit status of the last foreground job to exit.
|
||||
- \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
|
||||
|
||||
Whenever a process exits, an exit status is returned to the program
|
||||
that started it. This exit status is an integer number, which tells
|
||||
the calling application how the execution of the command went. In
|
||||
general, a zero exit status means that the command executed without
|
||||
problem, but a non-zero exit status means there was some form of
|
||||
problem.
|
||||
that started it (usually the shell). This exit status is an integer
|
||||
number, which tells the calling application how the execution of the
|
||||
command went. In general, a zero exit status means that the command
|
||||
executed without problem, but a non-zero exit status means there was
|
||||
some form of problem.
|
||||
|
||||
Fish stores the exit status of the last process in the last job to
|
||||
exit in the \c status variable.
|
||||
@@ -825,9 +962,10 @@ 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
|
||||
- 127 means that no command with the given name could be located
|
||||
- 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
|
||||
|
||||
\subsection variables-color Variables for changing highlighting colors
|
||||
|
||||
@@ -871,7 +1009,7 @@ To make errors highlighted and red, use:
|
||||
\subsection variables-locale Locale variables
|
||||
|
||||
The most common way to set the locale to use a command like 'set -x
|
||||
LANG en_GB.utf8', which sets the current locale to be the english
|
||||
LANG en_GB.utf8', which sets the current locale to be the English
|
||||
language, as used in Great Britain, using the UTF-8 character set. For
|
||||
a list of available locales, use 'locale -a'.
|
||||
|
||||
@@ -893,61 +1031,10 @@ code duplication, and to avoid the confusion of subtly differing
|
||||
versions of the same command, \c fish only implements builtins for
|
||||
actions which cannot be performed by a regular command.
|
||||
|
||||
\section bundle Commands bundled with fish
|
||||
|
||||
The following commands are distributed with fish. Many of them are
|
||||
builtins or shellscript functions, and can only be used inside fish.
|
||||
|
||||
- <a href="commands.html#source">.</a>, read and execute the commands in a file
|
||||
- <a href="commands.html#and">and</a>, execute command if previous command suceeded
|
||||
- <a href="commands.html#bg">bg</a>, set a command to the background
|
||||
- <a href="commands.html#begin">begin</a>, execute a block of commands
|
||||
- <a href="commands.html#bind">bind</a>, change keyboard bindings
|
||||
- <a href="commands.html#break">break</a>, stop the execution of a loop
|
||||
- <a href="commands.html#block">block</a>, Temporarily block delivery of events
|
||||
- <a href="commands.html#builtin">builtin</a>, execute a builtin command
|
||||
- <a href="commands.html#case">case</a>, conditionally execute a block of commands
|
||||
- <a href="commands.html#cd">cd</a>, change the current directory
|
||||
- <a href="commands.html#command">command</a>, execute an external program
|
||||
- <a href="commands.html#commandline">commandline</a>, set or get the contents of the commandline buffer
|
||||
- <a href="commands.html#complete">complete</a>, add and remove completions
|
||||
- <a href="commands.html#continue">continue</a>, skip the rest of the current lap of a loop
|
||||
- <a href="commands.html#count">count</a>, count the number of arguments
|
||||
- <a href="commands.html#dirh">dirh</a>, view the directory history
|
||||
- <a href="commands.html#dirs">dirs</a>, view the directory stack
|
||||
- <a href="commands.html#end">end</a>, end a block of commands
|
||||
- <a href="commands.html#else">else</a>, conditionally execute a block of commands
|
||||
- <a href="commands.html#eval">eval</a>, evaluate a string as a command
|
||||
- <a href="commands.html#exec">exec</a>, replace the current process image with a new command
|
||||
- <a href="commands.html#exit">exit</a>, causes \c fish to quit
|
||||
- <a href="commands.html#fg">fg</a>, set a command to the foreground
|
||||
- <a href="commands.html#fishd">fishd</a>, the universal variable daemon
|
||||
- <a href="commands.html#for">for</a>, perform a block of commands once for every element in a list
|
||||
- <a href="commands.html#function">function</a>, define a new function
|
||||
- <a href="commands.html#functions">functions</a>, print or erase functions
|
||||
- <a href="commands.html#help">help</a>, show the fish documentation
|
||||
- <a href="commands.html#if">if</a>, conditionally execute a block of commands
|
||||
- <a href="commands.html#jobs">jobs</a>, print the currently running jobs
|
||||
- <a href="commands.html#mimedb">mimedb</a>, view mimedata about a file
|
||||
- <a href="commands.html#nextd">nextd</a>, move forward in the directory history
|
||||
- <a href="commands.html#not">not</a>, negates the exit status of any command
|
||||
- <a href="commands.html#or">or</a>, execute a command if previous command failed
|
||||
- <a href="commands.html#popd">popd</a>, move to the topmost directory on the directory stack
|
||||
- <a href="commands.html#prevd">prevd</a>, move backwards in the direcotry stack
|
||||
- <a href="commands.html#pushd">pushd</a>, push the surrent directory onto the directory stack
|
||||
- <a href="commands.html#random">random</a>, calculate a pseudo-random number
|
||||
- <a href="commands.html#return">return</a>, return from a function
|
||||
- <a href="commands.html#read">read</a>, read from a stream into an environment variable
|
||||
- <a href="commands.html#set">set</a>, set environment variables
|
||||
- <a href="commands.html#set_color">set_color</a>, change the terminal colors
|
||||
- <a href="commands.html#switch">switch</a>, conditionally execute a block of commands
|
||||
- <a href="commands.html#tokenize">tokenize</a>, split a string up into multiple tokens
|
||||
- <a href="commands.html#ulimit">ulimit</a>, set or get the shells resurce usage limits
|
||||
- <a href="commands.html#umask">umask</a>, set or get the file creation mask
|
||||
- <a href="commands.html#while">while</a>, perform a block of commands while a condition is met
|
||||
|
||||
For more information about these commands, use the <code>--help</code>
|
||||
option of the command to display a longer explanation.
|
||||
For a list of all builtins, functions and commands shipped with fish,
|
||||
see the <a href="#toc-commands">table of contents</a>. The
|
||||
documentation is also available by using the <code>--help</code>
|
||||
switch of the command.
|
||||
|
||||
\section editor Command Line editor
|
||||
|
||||
@@ -975,14 +1062,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 fileformat 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
|
||||
@@ -1009,11 +1090,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)
|
||||
|
||||
@@ -1040,7 +1119,7 @@ the string entered into the command line are shown.
|
||||
By pressing Alt-up and Alt-down, a history search is also performed,
|
||||
but instead of searching for a complete commandline, each commandline
|
||||
is tokenized into separate elements just like it would be before
|
||||
execution, and each such token is matched agains the token under the
|
||||
execution, and each such token is matched against the token under the
|
||||
cursor when the search began.
|
||||
|
||||
History searches can be aborted by pressing the escape key.
|
||||
@@ -1075,7 +1154,7 @@ fish will be stopped until the program finishes. Sometimes this is not
|
||||
desirable. For example, you may wish to start an application with a
|
||||
graphical user interface from the terminal, and then be able to
|
||||
continue using the shell. In such cases, there are several ways in
|
||||
which the user can change <code>fish</code>'s behaviour.
|
||||
which the user can change <code>fish</code>'s behavior.
|
||||
|
||||
-# By ending a command with the \& (ampersand) symbol, the user tells \c fish to put the specified command into the background. A background process will be run simultaneous with \c fish. \c fish will retain control of the terminal, so the program will not be able to read from the keyboard.
|
||||
-# By pressing ^Z, the user stops a currently running foreground program and returns control to \c fish. Some programs do not support this feature, or remap it to another key. Gnu emacs uses ^X z to stop running.
|
||||
@@ -1153,28 +1232,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 direcotry.
|
||||
|
||||
</p>
|
||||
|
||||
|
||||
\subsection title Programmable title
|
||||
|
||||
When using most virtual terminals, it is possible to set the message
|
||||
@@ -1208,6 +1265,7 @@ 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
|
||||
|
||||
Example:
|
||||
|
||||
@@ -1222,6 +1280,20 @@ For more information on how to define new event handlers, see the
|
||||
documentation for the <a href='commands.html#function'>function</a>
|
||||
command.
|
||||
|
||||
\subsection debuging Debuging fish scripts
|
||||
|
||||
Fish includes a built in debuger. The debuger 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 debuged by sending it the TRAP
|
||||
signal. Once in the debuger, 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
|
||||
@@ -1273,7 +1345,7 @@ msgid "%ls: No suitable job\n"
|
||||
msgstr ""
|
||||
</pre>
|
||||
|
||||
The first line is the english string to translate, the second line
|
||||
The first line is the English string to translate, the second line
|
||||
should contain your translation. For example, in swedish the above
|
||||
might become:
|
||||
|
||||
@@ -1298,64 +1370,57 @@ href='fish-users@lists.sf.net'>fish-users@lists.sf.net</a>.
|
||||
\subsection todo-features Missing features
|
||||
|
||||
- Complete vi-mode key bindings
|
||||
- More completions (for example xterm, vim,
|
||||
konsole, gnome-terminal, dcop, cron,
|
||||
rlogin, rsync, arch, finger, nice, locate,
|
||||
bibtex, aspell, xpdf,
|
||||
compress, wine, xmms, dig, batch, cron,
|
||||
g++, javac, java, gcj, lpr, doxygen, whois, find)
|
||||
- More completions (for example konsole, gnome-terminal,
|
||||
rlogin, rsync, arch, finger, bibtex, aspell, xpdf,
|
||||
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
|
||||
- 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
|
||||
- Completions could support options beginning with a plus (like xterm
|
||||
+fbx) and options without dashes (like top p) Do we really want to
|
||||
complicate the code additionally for such a small number of programs?
|
||||
- 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
|
||||
- With a bit of tweakage, quite a few of the readline key-binding functions could be implemented in shellscript.
|
||||
- Highlight beginning/end of block when moving over a block command
|
||||
- Inclusion guards for the init files to make them evaluate only once, even if the user has installed fish both in /etc and in $HOME
|
||||
- command specific wildcarding (use case * instead of case '*', etc.)
|
||||
- Map variables. (export only the values. When expanding with no key specified, expand to all values.)
|
||||
- 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.
|
||||
- A pretty-printer.
|
||||
- Help messages for builtin should not be compiled into fish, they should be kept in a separate directory
|
||||
- Shellscript functions should be able to show help on the commandline instead of launching a browser
|
||||
- Drop support for inputrc-files. Use shellscripts and the bind builtin. Also, redo the syntax for the bind builtin to something more sane.
|
||||
- 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.
|
||||
- The large number of interned strings means that autounloading frees less memory than it should. Completion strings should probably be either refcounted or not shared at all.
|
||||
- Auto-newlines
|
||||
- A fault injector could be written to increase robustness and testing of error recovery paths
|
||||
- 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
|
||||
|
||||
\subsection bugs Known bugs and issues
|
||||
|
||||
\subsection bugs Known bugs
|
||||
|
||||
- Completion for gcc -\#\#\# option doesn't work.
|
||||
- Suspending and then resuming pipelines containing a builtin is broken. How should this be handled?
|
||||
- screen handling code can't handle tabs in input.
|
||||
|
||||
- Suspending and then resuming pipelines containing a builtin or a shellscript function is broken. Ideally, the exec function in exec.c should be able to resume execution of a partially executed job.
|
||||
- delete-word is broken on the commandline 'sudo update-alternatives --config x-'
|
||||
- Sometimes autoheader needs to be run on a fresh tarball. Fix dates before creating tarballs.
|
||||
- The completion autoloader does not remember which completions where actually autoloaded, and may unload manually specified completions.
|
||||
- There have been stray reports of issues with strang values of the PATH variable during startup.
|
||||
|
||||
If you think you have found a bug not described here, please send a
|
||||
report to <a href="mailto:axel@liljencrantz.se"> axel@liljencrantz.se
|
||||
</a>.
|
||||
report to <a href="mailto:fish-users@lists.sf.net">fish-users@lists.sf.net</a>.
|
||||
|
||||
|
||||
\subsection issues Known issues
|
||||
@@ -1,4 +1,4 @@
|
||||
\section isatty isatty - test if the specidied file descriptor is a tty
|
||||
\section isatty isatty - test if the specified file descriptor is a tty
|
||||
|
||||
\subsection isatty-synopsis Synopsis
|
||||
<tt>isatty [FILE DESCRIPTOR]</tt>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/** \page license Licenses
|
||||
|
||||
Fish Copyright (C) 2005 Axel Liljencrantz. Fish is released under the
|
||||
GNU General Public License, version 2. The license agreement is
|
||||
Fish Copyright (C) 2005-2006 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
|
||||
|
||||
20
doc_src/math.txt
Normal file
20
doc_src/math.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
\section math math - Perform mathematics calculations
|
||||
|
||||
\subsection math-synopsis Synopsis
|
||||
<tt>math EXPRESSION</tt>
|
||||
|
||||
\subsection math-description Description
|
||||
|
||||
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>.
|
||||
|
||||
For a description of the syntax supported by math, see the manual for
|
||||
the bc program. Keep in mind that parameter expansion takes place on
|
||||
any expressions before they are evaluated. This can be very useful in
|
||||
order to perform calculations involving environment variables or the
|
||||
output of command substitutions, but it also means that parenthesis
|
||||
have to be escaped.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -10,10 +10,14 @@ status (as set by the last previous command) is not 0.
|
||||
|
||||
The or command does not change the current exit status.
|
||||
|
||||
The exit status of the last foreground command to exit can always be
|
||||
accessed using the <a href="index.html#variables-status">$status</a>
|
||||
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 succceeds, the program is installed. If either step fails,
|
||||
<tt>make clean</tt> is run, which removes the files created by the
|
||||
build process
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
\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>
|
||||
|
||||
\subsection prevd-description Description <tt>prevd</tt> moves
|
||||
backwards <tt>pos</tt> positions in the history of visited
|
||||
directories; if the beginning of the history has been hit, a warning
|
||||
is printed. If the <code>-l</code> or <code>--list</code> flag is
|
||||
specified, the current history is also displayed.
|
||||
\subsection prevd-description Description
|
||||
|
||||
<tt>prevd</tt> moves backwards <tt>pos</tt> positions in the history
|
||||
of visited directories; if the beginning of the history has been hit,
|
||||
a warning is printed. If the <code>-l</code> or <code>--list</code>
|
||||
flag is specified, the current history is also displayed.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
\section psub psub - perform process substitution
|
||||
|
||||
\subsection psub-synopsis Synopsis
|
||||
<tt>COMMAND1 (COMMAND2|psub) </tt>
|
||||
<tt>COMMAND1 (COMMAND2|psub [-f]) </tt>
|
||||
|
||||
\subsection psub-description Description
|
||||
|
||||
@@ -14,6 +14,12 @@ filename of the named pipe sent as an argument to the calling
|
||||
program. The psub shellscript function, which when combined with a
|
||||
regular command substitution provides the same functionality.
|
||||
|
||||
If the \c -f or \c --file switch is given to psub, psub will use a
|
||||
regular file instead of a named pipe to communicate with the calling
|
||||
process. This will cause psub to be significantly slower when large
|
||||
amounts of data are involved, but has the advantage that the reading
|
||||
process can seek in the stream.
|
||||
|
||||
\subsection psub-example Example
|
||||
|
||||
<tt>diff (sort a.txt|psub) (sort b.txt|psub)</tt> shows the difference
|
||||
|
||||
@@ -11,7 +11,9 @@ input and store the result in one or more environment variables.
|
||||
- <tt>-c CMD</tt> or <tt>--command=CMD</tt> specifies that the initial string in the interactive mode command buffer should be CMD.
|
||||
- <tt>-e</tt> or <tt>--export</tt> specifies that the variables will be exported to subshells.
|
||||
- <tt>-g</tt> or <tt>--global</tt> specifies that the variables will be made global.
|
||||
- <tt>-m NAME</tt> or <tt>--mode-name=NAME</tt> specifies that the name NAME should be used to save/load the history file. If NAME is fish, the regular fish history will be available.
|
||||
- <tt>-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
|
||||
- <code>-U</code> or <code>--universal</code> causes the specified environment variable to be made universal. If this option is supplied, the variable will be shared between all the current users fish instances on the current computer, and will be preserved across restarts of the shell.
|
||||
- <code>-x</code> or <code>--export</code> causes the specified environment variable to be exported to child processes
|
||||
|
||||
12
doc_src/save_function.txt
Normal file
12
doc_src/save_function.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
\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.
|
||||
|
||||
|
||||
@@ -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>
|
||||
- <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
|
||||
|
||||
@@ -5,22 +5,13 @@
|
||||
|
||||
\subsection ulimit-description Description
|
||||
|
||||
The ulimit builtin provides control over the resources available to
|
||||
the shell and to processes started by it. The -H and -S options
|
||||
specify that the hard or soft limit is set for the given resource. 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 set. The value of limit
|
||||
can be a number in the unit specified for the resource or one of the
|
||||
special values hard, soft, or unlimited, which stand for the current
|
||||
hard limit, the current soft limit, and no limit, respectively. If
|
||||
limit is omitted, the current value of the soft limit of the resource
|
||||
is printed, unless the -H option is given. When more than one
|
||||
resource is specified, the limit name and unit are printed before the
|
||||
value. Other options are interpreted as follows:
|
||||
The ulimit builtin is used to set the resource usage limits of the
|
||||
shell and any processes spawned by it. If a new limit value is
|
||||
omitted, the current value of the limit of the resource is printed.
|
||||
|
||||
- <code>-a</code> or <code>--all</code> Set or get all current limits
|
||||
- <code>-c</code> or <code>--core-size</code> The maximum size of core files created
|
||||
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. 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
|
||||
@@ -31,17 +22,42 @@ value. Other options are interpreted as follows:
|
||||
- <code>-u</code> or <code>--process-count</code> The maximum number of processes available to a single user
|
||||
- <code>-v</code> or <code>--virtual-memory-size</code> The maximum amount of virtual memory available to the shell. If supported by OS.
|
||||
|
||||
Note that not all these limits are available in all operating systems.
|
||||
|
||||
The value of limit can be a number in the unit specified for
|
||||
the resource or one of the special values hard, soft, or unlimited,
|
||||
which stand for the current hard limit, the current soft limit, and no
|
||||
limit, respectively.
|
||||
|
||||
If limit is given, it is the new value of the specified resource. If
|
||||
no option is given, then -f is assumed. Values are in kilobytes,
|
||||
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.
|
||||
|
||||
The fish implementation of ulimit should behave identically to the implementation in bash, except for these differences:
|
||||
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 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:
|
||||
|
||||
- <code>-a</code> or <code>--all</code> Print all current limits
|
||||
- <code>-h</code> or <code>--help</code> Display help and exit
|
||||
|
||||
The fish implementation of ulimit should behave identically to the
|
||||
implementation in bash, except for these differences:
|
||||
|
||||
- Fish ulimit supports GNU-style long options for all switches
|
||||
- Fish ulimit does not support the -p option for getting the pipe size. The bash implementation consists of a compile-time check that empirically guesses this number by writing to a pipe and waiting for SIGPIPE.
|
||||
- Fish ulimit does not support getting the values of multiple limits in one command, except by using the -a switch
|
||||
- Fish ulimit does not support the -p option for getting the pipe size. The bash implementation consists of a compile-time check that empirically guesses this number by writing to a pipe and waiting for SIGPIPE. Fish does not do this because it this method of determining pipe sixe is unreliable. Depending on bash version, there may also be further additional limits to set in bash that do not exist in fish.
|
||||
- Fish ulimit does not support 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.
|
||||
|
||||
|
||||
259
env.c
259
env.c
@@ -1,7 +1,6 @@
|
||||
/** \file env.c
|
||||
Functions for setting and getting environment variables.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -53,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"
|
||||
|
||||
@@ -67,9 +69,13 @@
|
||||
#define ENV_NULL L"\x1d"
|
||||
|
||||
/**
|
||||
At init, we read all the environment variables from this array
|
||||
At init, we read all the environment variables from this array.
|
||||
*/
|
||||
extern char **environ;
|
||||
/**
|
||||
This should be the same thing as \c environ, but it is possible only one of the two work...
|
||||
*/
|
||||
extern char **__environ;
|
||||
|
||||
|
||||
/**
|
||||
@@ -108,6 +114,8 @@ typedef struct env_node
|
||||
typedef struct var_entry
|
||||
{
|
||||
int export; /**< Whether the variable should be exported */
|
||||
size_t size; /**< The maximum length (excluding the NULL) that will fit into this var_entry_t */
|
||||
|
||||
#if __STDC_VERSION__ < 199901L
|
||||
wchar_t val[1]; /**< The value of the variable */
|
||||
#else
|
||||
@@ -200,7 +208,9 @@ static void clear_hash_entry( void *key, void *data )
|
||||
{
|
||||
var_entry_t *entry = (var_entry_t *)data;
|
||||
if( entry->export )
|
||||
{
|
||||
has_changed = 1;
|
||||
}
|
||||
|
||||
free( (void *)key );
|
||||
free( (void *)data );
|
||||
@@ -255,8 +265,12 @@ static int is_locale( const wchar_t *key )
|
||||
{
|
||||
int i;
|
||||
for( i=0; locale_variable[i]; i++ )
|
||||
{
|
||||
if( wcscmp(locale_variable[i], key ) == 0 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -301,8 +315,11 @@ static void handle_locale()
|
||||
for( i=2; locale_variable[i]; i++ )
|
||||
{
|
||||
const wchar_t *val = env_get( locale_variable[i] );
|
||||
|
||||
if( val )
|
||||
{
|
||||
wsetlocale( cat[i], val );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,8 +333,10 @@ static void handle_locale()
|
||||
strings should be reloaded. We do both and hope for the
|
||||
best.
|
||||
*/
|
||||
|
||||
extern int _nl_msg_cat_cntr;
|
||||
++_nl_msg_cat_cntr;
|
||||
_nl_msg_cat_cntr++;
|
||||
|
||||
dcgettext( "fish", "Changing language to English", LC_MESSAGES );
|
||||
|
||||
if( is_interactive )
|
||||
@@ -341,17 +360,24 @@ static void universal_callback( int type,
|
||||
wchar_t *str=0;
|
||||
|
||||
if( is_locale( name ) )
|
||||
{
|
||||
handle_locale();
|
||||
}
|
||||
|
||||
switch( type )
|
||||
{
|
||||
case SET:
|
||||
case SET_EXPORT:
|
||||
{
|
||||
str=L"SET";
|
||||
break;
|
||||
}
|
||||
|
||||
case ERASE:
|
||||
{
|
||||
str=L"ERASE";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( str )
|
||||
@@ -393,28 +419,31 @@ 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 );
|
||||
|
||||
if( path )
|
||||
{
|
||||
tokenize_variable_array( path, &l );
|
||||
}
|
||||
|
||||
for( j=0; path_el[j]; j++ )
|
||||
{
|
||||
|
||||
int has_el=0;
|
||||
|
||||
for( i=0; i<al_get_count( &l); i++ )
|
||||
{
|
||||
wchar_t * el = (wchar_t *)al_get( &l, i );
|
||||
size_t len = wcslen( el );
|
||||
|
||||
while( (len > 0) && (el[len-1]==L'/') )
|
||||
{
|
||||
len--;
|
||||
if( (wcslen( path_el[j] ) == len) && (wcsncmp( el, path_el[j], len)==0) )
|
||||
}
|
||||
|
||||
if( (wcslen( path_el[j] ) == len) &&
|
||||
(wcsncmp( el, path_el[j], len)==0) )
|
||||
{
|
||||
has_el = 1;
|
||||
}
|
||||
@@ -432,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 );
|
||||
|
||||
@@ -454,6 +482,7 @@ static void setup_path()
|
||||
|
||||
static void env_set_defaults()
|
||||
{
|
||||
|
||||
if( !env_get( L"USER" ) )
|
||||
{
|
||||
struct passwd *pw = getpwuid( getuid());
|
||||
@@ -461,6 +490,7 @@ static void env_set_defaults()
|
||||
env_set( L"USER", unam, ENV_GLOBAL );
|
||||
free( unam );
|
||||
}
|
||||
|
||||
if( !env_get( L"HOME" ) )
|
||||
{
|
||||
wchar_t *unam = env_get( L"USER" );
|
||||
@@ -471,6 +501,7 @@ static void env_set_defaults()
|
||||
free( dir );
|
||||
free( unam_narrow );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void env_init()
|
||||
@@ -480,7 +511,6 @@ void env_init()
|
||||
wchar_t *uname;
|
||||
wchar_t *version;
|
||||
|
||||
|
||||
sb_init( &dyn_var );
|
||||
b_init( &export_buffer );
|
||||
|
||||
@@ -522,7 +552,7 @@ void env_init()
|
||||
hash_init( &top->env, &hash_wcs_func, &hash_wcs_cmp );
|
||||
global_env = top;
|
||||
global = &top->env;
|
||||
|
||||
|
||||
/*
|
||||
Now the environemnt variable handling is set up, the next step
|
||||
is to insert valid data
|
||||
@@ -531,7 +561,7 @@ void env_init()
|
||||
/*
|
||||
Import environment variables
|
||||
*/
|
||||
for( p=environ; *p; p++ )
|
||||
for( p=environ?environ:__environ; p && *p; p++ )
|
||||
{
|
||||
wchar_t *key, *val;
|
||||
wchar_t *pos;
|
||||
@@ -539,13 +569,16 @@ void env_init()
|
||||
key = str2wcs(*p);
|
||||
|
||||
if( !key )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
val = wcschr( key, L'=' );
|
||||
|
||||
|
||||
if( val == 0 )
|
||||
{
|
||||
env_set( key, L"", ENV_EXPORT );
|
||||
}
|
||||
else
|
||||
{
|
||||
*val = L'\0';
|
||||
@@ -555,7 +588,9 @@ void env_init()
|
||||
while( *pos )
|
||||
{
|
||||
if( *pos == L':' )
|
||||
{
|
||||
*pos = ARRAY_SEP;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
|
||||
@@ -563,7 +598,7 @@ void env_init()
|
||||
}
|
||||
free(key);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Set up the PATH variable
|
||||
*/
|
||||
@@ -607,8 +642,10 @@ void env_destroy()
|
||||
b_destroy( &export_buffer );
|
||||
|
||||
while( &top->env != global )
|
||||
{
|
||||
env_pop();
|
||||
|
||||
}
|
||||
|
||||
hash_destroy( &env_read_only );
|
||||
|
||||
hash_destroy( &env_electric );
|
||||
@@ -622,8 +659,8 @@ void env_destroy()
|
||||
}
|
||||
|
||||
/**
|
||||
Find the scope hashtable containing the variable with the specified
|
||||
key
|
||||
Search all visible scopes in order for the specified key. Return
|
||||
the first scope in which it was found.
|
||||
*/
|
||||
static env_node_t *env_get_node( const wchar_t *key )
|
||||
{
|
||||
@@ -641,9 +678,13 @@ static env_node_t *env_get_node( const wchar_t *key )
|
||||
}
|
||||
|
||||
if( env->new_scope )
|
||||
{
|
||||
env = global_env;
|
||||
}
|
||||
else
|
||||
{
|
||||
env = env->next;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -663,9 +704,22 @@ int env_set( const wchar_t *key,
|
||||
|
||||
event_t ev;
|
||||
int is_universal = 0;
|
||||
|
||||
|
||||
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 ) )
|
||||
{
|
||||
@@ -691,13 +745,15 @@ int env_set( const wchar_t *key,
|
||||
}
|
||||
}
|
||||
/*
|
||||
Do not actually create a umask variable, on env_get, it will be calculated dynamically
|
||||
Do not actually create a umask variable, on env_get, it will
|
||||
be calculated dynamically
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Zero element arrays are internaly not coded as null but as this placeholder string
|
||||
Zero element arrays are internaly not coded as null but as this
|
||||
placeholder string
|
||||
*/
|
||||
if( !val )
|
||||
{
|
||||
@@ -714,7 +770,9 @@ int env_set( const wchar_t *key,
|
||||
env_universal_get_export( key );
|
||||
}
|
||||
else
|
||||
{
|
||||
export = (var_mode & ENV_EXPORT );
|
||||
}
|
||||
|
||||
env_universal_set( key, val, export );
|
||||
is_universal = 1;
|
||||
@@ -723,14 +781,6 @@ int env_set( const wchar_t *key,
|
||||
else
|
||||
{
|
||||
|
||||
if( val == 0 )
|
||||
{
|
||||
wchar_t *prev_val;
|
||||
free_val = 1;
|
||||
prev_val = env_get( key );
|
||||
val = wcsdup( prev_val?prev_val:L"" );
|
||||
}
|
||||
|
||||
node = env_get_node( key );
|
||||
if( node && &node->env != 0 )
|
||||
{
|
||||
@@ -738,15 +788,15 @@ int env_set( const wchar_t *key,
|
||||
key );
|
||||
|
||||
if( e->export )
|
||||
{
|
||||
has_changed_new = 1;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if( (var_mode & ENV_LOCAL) ||
|
||||
(var_mode & ENV_GLOBAL) )
|
||||
{
|
||||
node = ( var_mode & ENV_GLOBAL )?global_env:top;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -776,8 +826,10 @@ int env_set( const wchar_t *key,
|
||||
env_universal_get_export( key );
|
||||
}
|
||||
else
|
||||
{
|
||||
export = (var_mode & ENV_EXPORT );
|
||||
|
||||
}
|
||||
|
||||
env_universal_set( key, val, export );
|
||||
is_universal = 1;
|
||||
|
||||
@@ -788,12 +840,15 @@ int env_set( const wchar_t *key,
|
||||
{
|
||||
/*
|
||||
New variable with unspecified scope. The default
|
||||
scope is the innermost scope that is shadowing
|
||||
scope is the innermost scope that is shadowing,
|
||||
which will be either the current function or the
|
||||
global scope.
|
||||
*/
|
||||
node = top;
|
||||
while( node->next && !node->new_scope )
|
||||
{
|
||||
node = node->next;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -801,24 +856,59 @@ int env_set( const wchar_t *key,
|
||||
if( !done )
|
||||
{
|
||||
void *k, *v;
|
||||
hash_remove( &node->env, key, &k, &v );
|
||||
free( k );
|
||||
free( v );
|
||||
var_entry_t *old_entry;
|
||||
size_t val_len = wcslen(val);
|
||||
|
||||
entry = malloc( sizeof( var_entry_t ) +
|
||||
sizeof(wchar_t )*(wcslen(val)+1));
|
||||
|
||||
if( var_mode & ENV_EXPORT)
|
||||
hash_remove( &node->env, key, &k, &v );
|
||||
|
||||
/*
|
||||
Try to reuse previous key string
|
||||
*/
|
||||
if( !k )
|
||||
{
|
||||
entry->export = 1;
|
||||
has_changed_new = 1;
|
||||
k = wcsdup(key);
|
||||
}
|
||||
|
||||
old_entry = (var_entry_t *)v;
|
||||
if( old_entry && old_entry->size >= val_len )
|
||||
{
|
||||
entry = old_entry;
|
||||
|
||||
if( !!(var_mode & ENV_EXPORT) || entry->export )
|
||||
{
|
||||
entry->export = !!(var_mode & ENV_EXPORT);
|
||||
has_changed_new = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
entry->export = 0;
|
||||
{
|
||||
free( v );
|
||||
|
||||
entry = malloc( sizeof( var_entry_t ) +
|
||||
sizeof(wchar_t )*(val_len+1));
|
||||
|
||||
if( !entry )
|
||||
{
|
||||
DIE_MEM();
|
||||
}
|
||||
|
||||
entry->size = val_len;
|
||||
|
||||
if( var_mode & ENV_EXPORT)
|
||||
{
|
||||
entry->export = 1;
|
||||
has_changed_new = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
entry->export = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
wcscpy( entry->val, val );
|
||||
|
||||
hash_put( &node->env, wcsdup(key), entry );
|
||||
|
||||
hash_put( &node->env, k, entry );
|
||||
|
||||
if( entry->export )
|
||||
{
|
||||
@@ -826,8 +916,10 @@ int env_set( const wchar_t *key,
|
||||
}
|
||||
|
||||
if( free_val )
|
||||
{
|
||||
free((void *)val);
|
||||
|
||||
}
|
||||
|
||||
has_changed = has_changed_old || has_changed_new;
|
||||
}
|
||||
|
||||
@@ -873,8 +965,10 @@ static int try_remove( env_node_t *n,
|
||||
wchar_t *old_key, *old_val;
|
||||
|
||||
if( n == 0 )
|
||||
{
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
hash_remove( &n->env,
|
||||
key,
|
||||
&old_key_void,
|
||||
@@ -897,12 +991,18 @@ static int try_remove( env_node_t *n,
|
||||
}
|
||||
|
||||
if( var_mode & ENV_LOCAL )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( n->new_scope )
|
||||
{
|
||||
return try_remove( global_env, key, var_mode );
|
||||
}
|
||||
else
|
||||
{
|
||||
return try_remove( n->next, key, var_mode );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -996,7 +1096,10 @@ wchar_t *env_get( const wchar_t *key )
|
||||
}
|
||||
|
||||
if( i!=0)
|
||||
{
|
||||
sb_append( &dyn_var, ARRAY_SEP_STR );
|
||||
}
|
||||
|
||||
sb_append( &dyn_var, next );
|
||||
}
|
||||
|
||||
@@ -1038,13 +1141,19 @@ wchar_t *env_get( const wchar_t *key )
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return res->val;
|
||||
}
|
||||
}
|
||||
|
||||
if( env->new_scope )
|
||||
{
|
||||
env = global_env;
|
||||
}
|
||||
else
|
||||
{
|
||||
env = env->next;
|
||||
}
|
||||
}
|
||||
if( !proc_had_barrier)
|
||||
{
|
||||
@@ -1059,7 +1168,9 @@ wchar_t *env_get( const wchar_t *key )
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
int env_exist( const wchar_t *key, int mode )
|
||||
@@ -1096,12 +1207,18 @@ int env_exist( const wchar_t *key, int mode )
|
||||
}
|
||||
|
||||
if( mode & ENV_LOCAL )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if( env->new_scope )
|
||||
{
|
||||
env = global_env;
|
||||
}
|
||||
else
|
||||
{
|
||||
env = env->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1314,16 +1431,31 @@ void env_get_names( array_list_t *l, int flags )
|
||||
static void export_func1( void *k, void *v, void *aux )
|
||||
{
|
||||
var_entry_t *val_entry = (var_entry_t *)v;
|
||||
if( val_entry->export )
|
||||
{
|
||||
hash_table_t *h = (hash_table_t *)aux;
|
||||
|
||||
if( !hash_get( h, k ) )
|
||||
hash_put( h, k, val_entry->val );
|
||||
hash_table_t *h = (hash_table_t *)aux;
|
||||
|
||||
hash_remove( h, k, 0, 0 );
|
||||
|
||||
if( val_entry->export && wcscmp( val_entry->val, ENV_NULL ) )
|
||||
{
|
||||
hash_put( h, k, val_entry->val );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void get_exported( env_node_t *n, hash_table_t *h )
|
||||
{
|
||||
if( !n )
|
||||
return;
|
||||
|
||||
if( n->new_scope )
|
||||
get_exported( global_env, h );
|
||||
else
|
||||
get_exported( n->next, h );
|
||||
|
||||
hash_foreach2( &n->env, &export_func1, h );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Function used by env_export_arr to iterate over hashtable of variables
|
||||
*/
|
||||
@@ -1376,7 +1508,6 @@ char **env_export_arr( int recalc )
|
||||
{
|
||||
array_list_t uni;
|
||||
hash_table_t vals;
|
||||
env_node_t *n=top;
|
||||
int prev_was_null=1;
|
||||
int pos=0;
|
||||
int i;
|
||||
@@ -1385,15 +1516,7 @@ char **env_export_arr( int recalc )
|
||||
|
||||
hash_init( &vals, &hash_wcs_func, &hash_wcs_cmp );
|
||||
|
||||
while( n )
|
||||
{
|
||||
hash_foreach2( &n->env, &export_func1, &vals );
|
||||
|
||||
if( n->new_scope )
|
||||
n = global_env;
|
||||
else
|
||||
n = n->next;
|
||||
}
|
||||
get_exported( top, &vals );
|
||||
|
||||
al_init( &uni );
|
||||
env_universal_get_names( &uni, 1, 0 );
|
||||
@@ -1401,7 +1524,7 @@ char **env_export_arr( int recalc )
|
||||
{
|
||||
wchar_t *key = (wchar_t *)al_get( &uni, i );
|
||||
wchar_t *val = env_universal_get( key );
|
||||
if( !hash_get( &vals, key ) )
|
||||
if( wcscmp( val, ENV_NULL) && !hash_get( &vals, key ) )
|
||||
hash_put( &vals, key, val );
|
||||
}
|
||||
al_destroy( &uni );
|
||||
|
||||
@@ -70,6 +70,11 @@ static int barrier_reply = 0;
|
||||
|
||||
void env_universal_barrier();
|
||||
|
||||
static int is_dead()
|
||||
{
|
||||
return env_universal_server.fd < 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Get a socket for reading from the server
|
||||
@@ -140,18 +145,18 @@ static int get_socket( int fork_ok )
|
||||
return get_socket( 0 );
|
||||
}
|
||||
|
||||
debug( 2, L"Could not connect to socket %d, already tried manual restart (or no command supplied), giving up", s );
|
||||
debug( 1, L"Could not connect to universal variable server, already tried manual restart (or no command supplied). You will not be able to share variable values between fish sessions. Is fish properly installed?" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( fcntl( s, F_SETFL, O_NONBLOCK ) != 0 )
|
||||
if( (fcntl( s, F_SETFL, O_NONBLOCK ) != 0) || (fcntl( s, F_SETFD, FD_CLOEXEC ) != 0) )
|
||||
{
|
||||
wperror( L"fcntl" );
|
||||
close( s );
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
debug( 3, L"Connected to fd %d", s );
|
||||
|
||||
return s;
|
||||
@@ -198,6 +203,31 @@ static void check_connection()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Remove all universal variables.
|
||||
*/
|
||||
static void env_universal_remove_all()
|
||||
{
|
||||
array_list_t lst;
|
||||
int i;
|
||||
|
||||
al_init( &lst );
|
||||
|
||||
env_universal_common_get_names( &lst,
|
||||
1,
|
||||
1 );
|
||||
|
||||
for( i=0; i<al_get_count( &lst ); i++ )
|
||||
{
|
||||
wchar_t *key = (wchar_t *)al_get( &lst, i );
|
||||
env_universal_common_remove( key );
|
||||
}
|
||||
|
||||
al_destroy( &lst );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Try to establish a new connection to fishd. If successfull, end
|
||||
with call to env_universal_barrier(), to make sure everything is in
|
||||
@@ -216,6 +246,7 @@ static void reconnect()
|
||||
init = 1;
|
||||
if( env_universal_server.fd >= 0 )
|
||||
{
|
||||
env_universal_remove_all();
|
||||
env_universal_barrier();
|
||||
}
|
||||
}
|
||||
@@ -317,7 +348,7 @@ void env_universal_barrier()
|
||||
message_t *msg;
|
||||
fd_set fds;
|
||||
|
||||
if( !init || ( env_universal_server.fd == -1 ))
|
||||
if( !init || is_dead() )
|
||||
return;
|
||||
|
||||
barrier_reply = 0;
|
||||
@@ -384,20 +415,27 @@ void env_universal_set( const wchar_t *name, const wchar_t *value, int export )
|
||||
CHECK( name, );
|
||||
|
||||
debug( 3, L"env_universal_set( \"%ls\", \"%ls\" )", name, value );
|
||||
|
||||
msg = create_message( export?SET_EXPORT:SET,
|
||||
name,
|
||||
value);
|
||||
|
||||
if( !msg )
|
||||
if( is_dead() )
|
||||
{
|
||||
debug( 1, L"Could not create universal variable message" );
|
||||
return;
|
||||
env_universal_common_set( name, value, export );
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = create_message( export?SET_EXPORT:SET,
|
||||
name,
|
||||
value);
|
||||
|
||||
if( !msg )
|
||||
{
|
||||
debug( 1, L"Could not create universal variable message" );
|
||||
return;
|
||||
}
|
||||
|
||||
msg->count=1;
|
||||
q_put( &env_universal_server.unsent, msg );
|
||||
env_universal_barrier();
|
||||
}
|
||||
|
||||
msg->count=1;
|
||||
q_put( &env_universal_server.unsent, msg );
|
||||
env_universal_barrier();
|
||||
}
|
||||
|
||||
int env_universal_remove( const wchar_t *name )
|
||||
@@ -411,16 +449,22 @@ int env_universal_remove( const wchar_t *name )
|
||||
CHECK( name, 1 );
|
||||
|
||||
res = !env_universal_common_get( name );
|
||||
|
||||
debug( 3,
|
||||
L"env_universal_remove( \"%ls\" )",
|
||||
name );
|
||||
|
||||
msg= create_message( ERASE, name, 0);
|
||||
msg->count=1;
|
||||
q_put( &env_universal_server.unsent, msg );
|
||||
env_universal_barrier();
|
||||
|
||||
|
||||
if( is_dead() )
|
||||
{
|
||||
env_universal_common_remove( name );
|
||||
}
|
||||
else
|
||||
{
|
||||
msg= create_message( ERASE, name, 0);
|
||||
msg->count=1;
|
||||
q_put( &env_universal_server.unsent, msg );
|
||||
env_universal_barrier();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -430,6 +474,8 @@ void env_universal_get_names( array_list_t *l,
|
||||
{
|
||||
if( !init )
|
||||
return;
|
||||
|
||||
CHECK( l, );
|
||||
|
||||
env_universal_common_get_names( l,
|
||||
show_exported,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/** \file env_universal.h
|
||||
Universal variable client library
|
||||
Universal variable client library.
|
||||
*/
|
||||
|
||||
#ifndef ENV_UNIVERSAL_H
|
||||
|
||||
@@ -93,7 +93,7 @@
|
||||
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;
|
||||
|
||||
@@ -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,6 +124,58 @@ 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
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
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
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
wchar_t *utf2wcs( const char *in )
|
||||
{
|
||||
@@ -133,20 +184,38 @@ wchar_t *utf2wcs( const char *in )
|
||||
|
||||
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 +253,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 +262,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");
|
||||
@@ -209,17 +295,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);
|
||||
@@ -423,7 +523,7 @@ void read_message( connection_t *src )
|
||||
/**
|
||||
Remove variable with specified name
|
||||
*/
|
||||
static void remove_entry( wchar_t *name )
|
||||
void env_universal_common_remove( const wchar_t *name )
|
||||
{
|
||||
void *k, *v;
|
||||
hash_remove( &env_universal_var,
|
||||
@@ -449,6 +549,34 @@ static int match( const wchar_t *msg, const wchar_t *cmd )
|
||||
return 1;
|
||||
}
|
||||
|
||||
void env_universal_common_set( const wchar_t *key, const wchar_t *val, int export )
|
||||
{
|
||||
var_uni_entry_t *entry;
|
||||
wchar_t *name;
|
||||
|
||||
CHECK( key, );
|
||||
CHECK( val, );
|
||||
|
||||
entry = malloc( sizeof(var_uni_entry_t) + sizeof(wchar_t)*(wcslen(val)+1) );
|
||||
name = wcsdup(key);
|
||||
|
||||
if( !entry || !name )
|
||||
DIE_MEM();
|
||||
|
||||
entry->export=export;
|
||||
|
||||
wcscpy( entry->val, val );
|
||||
env_universal_common_remove( name );
|
||||
|
||||
hash_put( &env_universal_var, name, entry );
|
||||
|
||||
if( callback )
|
||||
{
|
||||
callback( export?SET_EXPORT:SET, name, val );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Parse message msg
|
||||
*/
|
||||
@@ -462,7 +590,7 @@ static void parse_message( wchar_t *msg,
|
||||
|
||||
if( match( msg, SET_STR ) || match( msg, SET_EXPORT_STR ))
|
||||
{
|
||||
wchar_t *name, *val, *tmp;
|
||||
wchar_t *name, *tmp;
|
||||
int export = match( msg, SET_EXPORT_STR );
|
||||
|
||||
name = msg+(export?wcslen(SET_EXPORT_STR):wcslen(SET_STR));
|
||||
@@ -472,31 +600,20 @@ static void parse_message( wchar_t *msg,
|
||||
tmp = wcschr( name, L':' );
|
||||
if( tmp )
|
||||
{
|
||||
wchar_t *key =malloc( sizeof( wchar_t)*(tmp-name+1));
|
||||
wchar_t *key;
|
||||
wchar_t *val;
|
||||
|
||||
key = malloc( sizeof( wchar_t)*(tmp-name+1));
|
||||
memcpy( key, name, sizeof( wchar_t)*(tmp-name));
|
||||
key[tmp-name]=0;
|
||||
|
||||
val = tmp+1;
|
||||
|
||||
|
||||
val = unescape( val, 0 );
|
||||
|
||||
var_uni_entry_t *entry =
|
||||
malloc( sizeof(var_uni_entry_t) + sizeof(wchar_t)*(wcslen(val)+1) );
|
||||
if( !entry )
|
||||
DIE_MEM();
|
||||
entry->export=export;
|
||||
env_universal_common_set( key, val, export );
|
||||
|
||||
wcscpy( entry->val, val );
|
||||
remove_entry( key );
|
||||
|
||||
hash_put( &env_universal_var, key, entry );
|
||||
|
||||
if( callback )
|
||||
{
|
||||
callback( export?SET_EXPORT:SET, key, val );
|
||||
}
|
||||
free(val );
|
||||
free( val );
|
||||
free( key );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -522,7 +639,7 @@ static void parse_message( wchar_t *msg,
|
||||
debug( 1, PARSE_ERR, msg );
|
||||
}
|
||||
|
||||
remove_entry( name );
|
||||
env_universal_common_remove( name );
|
||||
|
||||
if( callback )
|
||||
{
|
||||
@@ -853,8 +970,16 @@ void connection_destroy( connection_t *c)
|
||||
{
|
||||
q_destroy( &c->unsent );
|
||||
b_destroy( &c->input );
|
||||
if( close( c->fd ) )
|
||||
|
||||
/*
|
||||
A connection need not always be open - we only try to close it
|
||||
if it is open.
|
||||
*/
|
||||
if( c->fd >= 0 )
|
||||
{
|
||||
wperror( L"close" );
|
||||
if( close( c->fd ) )
|
||||
{
|
||||
wperror( L"close" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -143,19 +143,50 @@ void env_universal_common_destroy();
|
||||
|
||||
/**
|
||||
Add all variable names to the specified list
|
||||
|
||||
This function operate agains the local copy of all universal
|
||||
variables, it does not communicate with any other process.
|
||||
*/
|
||||
void env_universal_common_get_names( array_list_t *l,
|
||||
int show_exported,
|
||||
int show_unexported );
|
||||
|
||||
/**
|
||||
Perform the specified variable assignment.
|
||||
|
||||
This function operate agains the local copy of all universal
|
||||
variables, it does not communicate with any other process.
|
||||
|
||||
Do not call this function. Create a message to do it. This function
|
||||
is only to be used when fishd is dead.
|
||||
*/
|
||||
void env_universal_common_set( const wchar_t *key, const wchar_t *val, int export );
|
||||
|
||||
/**
|
||||
Remove the specified variable.
|
||||
|
||||
This function operate agains the local copy of all universal
|
||||
variables, it does not communicate with any other process.
|
||||
|
||||
Do not call this function. Create a message to do it. This function
|
||||
is only to be used when fishd is dead.
|
||||
*/
|
||||
void env_universal_common_remove( const wchar_t *key );
|
||||
|
||||
/**
|
||||
Get the value of the variable with the specified name
|
||||
|
||||
This function operate agains the local copy of all universal
|
||||
variables, it does not communicate with any other process.
|
||||
*/
|
||||
wchar_t *env_universal_common_get( const wchar_t *name );
|
||||
|
||||
/**
|
||||
Get the export flag of the variable with the specified
|
||||
name. Returns 0 if the variable doesn't exist.
|
||||
|
||||
This function operate agains the local copy of all universal
|
||||
variables, it does not communicate with any other process.
|
||||
*/
|
||||
int env_universal_common_get_export( const wchar_t *name );
|
||||
|
||||
@@ -164,8 +195,17 @@ int env_universal_common_get_export( const wchar_t *name );
|
||||
*/
|
||||
void enqueue_all( connection_t *c );
|
||||
|
||||
/**
|
||||
Fill in the specified connection_t struct. Use the specified file
|
||||
descriptor for communication.
|
||||
*/
|
||||
void connection_init( connection_t *c, int fd );
|
||||
|
||||
/**
|
||||
Close and destroy the specified connection struct. This frees
|
||||
allstructures allocated by the connection, such as ques of unsent
|
||||
messages.
|
||||
*/
|
||||
void connection_destroy( connection_t *c);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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
|
||||
66
event.c
66
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;
|
||||
@@ -444,7 +462,8 @@ static void event_fire_internal( event_t *event )
|
||||
for( i=0; i<al_get_count( fire ); i++ )
|
||||
{
|
||||
event_t *criterion = (event_t *)al_get( fire, i );
|
||||
|
||||
int prev_status;
|
||||
|
||||
/*
|
||||
Check if this event has been removed, if so, dont fire it
|
||||
*/
|
||||
@@ -476,11 +495,13 @@ static void event_fire_internal( event_t *event )
|
||||
they are marked as non-interactive
|
||||
*/
|
||||
proc_push_interactive(0);
|
||||
prev_status = proc_get_last_status();
|
||||
parser_push_block( EVENT );
|
||||
current_block->param1.event = event;
|
||||
eval( (wchar_t *)b->buff, 0, TOP );
|
||||
parser_pop_block();
|
||||
proc_pop_interactive();
|
||||
proc_set_last_status( prev_status );
|
||||
}
|
||||
|
||||
if( b )
|
||||
@@ -611,7 +632,9 @@ void event_fire( event_t *event )
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/*
|
||||
Fire events triggered by signals
|
||||
*/
|
||||
event_fire_delayed();
|
||||
|
||||
if( event )
|
||||
@@ -670,7 +693,30 @@ 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(const wchar_t *name)
|
||||
{
|
||||
event_t ev;
|
||||
|
||||
CHECK( name, );
|
||||
|
||||
ev.type = EVENT_GENERIC;
|
||||
ev.param1.param = name;
|
||||
ev.function_name=0;
|
||||
|
||||
al_init( &ev.arguments );
|
||||
event_fire( &ev );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
37
event.h
37
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,10 @@ void event_free( event_t *e );
|
||||
*/
|
||||
const wchar_t *event_get_desc( event_t *e );
|
||||
|
||||
/**
|
||||
Fire a generic event with the specified name
|
||||
*/
|
||||
void event_fire_generic(const wchar_t *name);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
213
expand.c
213
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
|
||||
@@ -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"'",
|
||||
@@ -272,16 +272,18 @@ static int iswnumeric( const wchar_t *n )
|
||||
*/
|
||||
static int match_pid( const wchar_t *cmd,
|
||||
const wchar_t *proc,
|
||||
int flags )
|
||||
int flags,
|
||||
int *offset)
|
||||
{
|
||||
/* Test for direct match */
|
||||
|
||||
|
||||
if( wcsncmp( cmd, proc, wcslen( proc ) ) == 0 )
|
||||
{
|
||||
if( offset )
|
||||
*offset = 0;
|
||||
return 1;
|
||||
|
||||
if( flags & ACCEPT_INCOMPLETE )
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
Test if the commandline is a path to the command, if so we try
|
||||
to match against only the command part
|
||||
@@ -309,7 +311,11 @@ static int match_pid( const wchar_t *cmd,
|
||||
|
||||
if( wcsncmp( start+1, proc, wcslen( proc ) ) == 0 )
|
||||
{
|
||||
if( offset )
|
||||
*offset = start+1-first_token;
|
||||
|
||||
free( first_token );
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -323,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,
|
||||
@@ -366,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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,8 +393,12 @@ static int find_process( const wchar_t *proc,
|
||||
else
|
||||
{
|
||||
|
||||
int jid = wcstol( proc, 0, 10 );
|
||||
if( jid > 0 )
|
||||
int jid;
|
||||
wchar_t *end;
|
||||
|
||||
errno = 0;
|
||||
jid = wcstol( proc, &end, 10 );
|
||||
if( jid > 0 && !errno && !*end )
|
||||
{
|
||||
j = job_get( jid );
|
||||
if( (j != 0) && (j->command != 0 ) )
|
||||
@@ -403,18 +419,19 @@ static int find_process( const wchar_t *proc,
|
||||
|
||||
for( j=first_job; j != 0; j=j->next )
|
||||
{
|
||||
int offset;
|
||||
|
||||
if( j->command == 0 )
|
||||
continue;
|
||||
|
||||
if( match_pid( j->command, proc, flags ) )
|
||||
|
||||
if( match_pid( j->command, proc, flags, &offset ) )
|
||||
{
|
||||
if( flags & ACCEPT_INCOMPLETE )
|
||||
{
|
||||
wchar_t *res = wcsdupcat2( j->command + 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
|
||||
{
|
||||
@@ -438,19 +455,19 @@ static int find_process( const wchar_t *proc,
|
||||
continue;
|
||||
for( p=j->first_process; p; p=p->next )
|
||||
{
|
||||
|
||||
int offset;
|
||||
|
||||
if( p->actual_cmd == 0 )
|
||||
continue;
|
||||
|
||||
if( match_pid( p->actual_cmd, proc, flags ) )
|
||||
if( match_pid( p->actual_cmd, proc, flags, &offset ) )
|
||||
{
|
||||
if( flags & ACCEPT_INCOMPLETE )
|
||||
{
|
||||
wchar_t *res = wcsdupcat2( p->actual_cmd + 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
|
||||
{
|
||||
@@ -556,16 +573,16 @@ static int find_process( const wchar_t *proc,
|
||||
|
||||
if( cmd != 0 )
|
||||
{
|
||||
if( match_pid( cmd, proc, flags ) )
|
||||
int offset;
|
||||
|
||||
if( match_pid( cmd, proc, flags, &offset ) )
|
||||
{
|
||||
if( flags & ACCEPT_INCOMPLETE )
|
||||
{
|
||||
wchar_t *res = wcsdupcat2( cmd + 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
|
||||
{
|
||||
@@ -609,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
|
||||
@@ -1503,6 +1524,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.
|
||||
*/
|
||||
@@ -1568,8 +1590,14 @@ int expand_string( void *context,
|
||||
{
|
||||
wchar_t *next;
|
||||
|
||||
next = expand_unescape( (wchar_t *)al_get( in, i ),
|
||||
1);
|
||||
/*
|
||||
We accept incomplete strings here, since complete uses
|
||||
expand_string to expand incomplete strings from the
|
||||
commandline.
|
||||
*/
|
||||
int unescape_flags = UNESCAPE_SPECIAL | UNESCAPE_INCOMPLETE;
|
||||
|
||||
next = expand_unescape( (wchar_t *)al_get( in, i ), unescape_flags );
|
||||
|
||||
free( (void *)al_get( in, i ) );
|
||||
|
||||
@@ -1657,7 +1685,9 @@ int expand_string( void *context,
|
||||
return EXPAND_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
al_push( out, next );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1690,48 +1720,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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1744,6 +1801,7 @@ int expand_string( void *context,
|
||||
al_push( end_out, next );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
al_destroy( in );
|
||||
al_destroy( out );
|
||||
@@ -1756,6 +1814,7 @@ int expand_string( void *context,
|
||||
halloc_register( context, (void *)al_get( end_out, i ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return res;
|
||||
|
||||
|
||||
94
fallback.c
94
fallback.c
@@ -47,6 +47,12 @@
|
||||
#include "util.h"
|
||||
|
||||
|
||||
#ifndef HAVE___ENVIRON
|
||||
|
||||
char **__environ = 0;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef TPUTS_KLUDGE
|
||||
|
||||
int tputs(const char *str, int affcnt, int (*fish_putc)(tputs_arg_t))
|
||||
@@ -59,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
|
||||
@@ -1091,3 +1155,33 @@ int getopt_long( int argc,
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_BACKTRACE
|
||||
int backtrace (void **buffer, int size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_BACKTRACE_SYMBOLS
|
||||
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
|
||||
|
||||
42
fallback.h
42
fallback.h
@@ -59,7 +59,7 @@ struct winsize
|
||||
unsigned short ws_row;
|
||||
unsigned short ws_col;
|
||||
}
|
||||
;
|
||||
;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -73,6 +73,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 +283,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 +337,7 @@ struct drand48_data
|
||||
*/
|
||||
unsigned int seed;
|
||||
}
|
||||
;
|
||||
;
|
||||
|
||||
/**
|
||||
Fallback implementation of lrand48_r. Internally uses rand_r, so it is pretty weak.
|
||||
@@ -370,8 +382,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
|
||||
|
||||
@@ -401,7 +413,7 @@ struct option
|
||||
int *flag;
|
||||
int val;
|
||||
}
|
||||
;
|
||||
;
|
||||
|
||||
#ifndef no_argument
|
||||
#define no_argument 0
|
||||
@@ -416,12 +428,18 @@ 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
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
104
main.c → fish.c
104
main.c → fish.c
@@ -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,22 +73,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
static int read_init()
|
||||
{
|
||||
char cwd[4096];
|
||||
wchar_t *wcwd;
|
||||
|
||||
wchar_t *config_dir;
|
||||
wchar_t *config_dir_escaped;
|
||||
void *context;
|
||||
string_buffer_t *eval_buff;
|
||||
|
||||
if( !getcwd( cwd, 4096 ) )
|
||||
{
|
||||
wperror( L"getcwd" );
|
||||
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
|
||||
@@ -96,39 +87,35 @@ 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( chdir( 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 );
|
||||
}
|
||||
|
||||
wcwd = str2wcs( cwd );
|
||||
if( wcwd )
|
||||
{
|
||||
env_set( L"PWD", wcwd, ENV_EXPORT );
|
||||
free( wcwd );
|
||||
}
|
||||
|
||||
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
|
||||
@@ -200,8 +187,12 @@ static int fish_parse_opt( int argc, char **argv, char **cmd_ptr )
|
||||
case 'd':
|
||||
{
|
||||
char *end;
|
||||
int tmp = strtol(optarg, &end, 10);
|
||||
if( tmp >= 0 && tmp <=10 && !*end )
|
||||
int tmp;
|
||||
|
||||
errno = 0;
|
||||
tmp = strtol(optarg, &end, 10);
|
||||
|
||||
if( tmp >= 0 && tmp <=10 && !*end && !errno )
|
||||
{
|
||||
debug_level=tmp;
|
||||
}
|
||||
@@ -215,7 +206,7 @@ static int fish_parse_opt( int argc, char **argv, char **cmd_ptr )
|
||||
|
||||
case 'h':
|
||||
{
|
||||
*cmd_ptr = "help";
|
||||
*cmd_ptr = "__fish_print_help fish";
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -264,9 +255,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;
|
||||
@@ -290,6 +289,7 @@ int main( int argc, char **argv )
|
||||
is_interactive_session=1;
|
||||
program_name=L"fish";
|
||||
|
||||
|
||||
my_optind = fish_parse_opt( argc, argv, &cmd );
|
||||
|
||||
/*
|
||||
@@ -301,7 +301,6 @@ int main( int argc, char **argv )
|
||||
no_exec = 0;
|
||||
}
|
||||
|
||||
|
||||
proc_init();
|
||||
event_init();
|
||||
wutil_init();
|
||||
@@ -312,7 +311,6 @@ int main( int argc, char **argv )
|
||||
reader_init();
|
||||
history_init();
|
||||
|
||||
|
||||
if( read_init() )
|
||||
{
|
||||
if( cmd != 0 )
|
||||
@@ -326,7 +324,7 @@ int main( int argc, char **argv )
|
||||
{
|
||||
if( my_optind == argc )
|
||||
{
|
||||
res = reader_read( 0 );
|
||||
res = reader_read( 0, 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -362,28 +360,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();
|
||||
@@ -392,13 +393,12 @@ int main( int argc, char **argv )
|
||||
parser_destroy();
|
||||
wutil_destroy();
|
||||
event_destroy();
|
||||
|
||||
|
||||
halloc_util_destroy();
|
||||
|
||||
|
||||
env_destroy();
|
||||
|
||||
|
||||
intern_free_all();
|
||||
|
||||
|
||||
return res;
|
||||
|
||||
return res?STATUS_UNKNOWN_COMMAND:proc_get_last_status();
|
||||
}
|
||||
28
fish.spec.in
28
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
|
||||
@@ -150,11 +148,19 @@ fi
|
||||
%dir %_datadir/fish/functions
|
||||
%_datadir/fish/functions/*.fish
|
||||
|
||||
|
||||
# Documentation for builtins and shellscript functions
|
||||
%dir %_datadir/fish/man
|
||||
%_datadir/fish/man/*.1
|
||||
|
||||
|
||||
|
||||
%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/
|
||||
|
||||
* Sat Oct 14 2006 Axel Liljencrantz<axel@liljencrantz.se> 1.22.0-0
|
||||
- Update names of various configuration files
|
||||
|
||||
|
||||
358
fish_indent.c
Normal file
358
fish_indent.c
Normal file
@@ -0,0 +1,358 @@
|
||||
/*
|
||||
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 main.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"
|
||||
|
||||
void read_file( FILE *f, string_buffer_t *b )
|
||||
{
|
||||
while( 1 )
|
||||
{
|
||||
wint_t c = fgetwc( f );
|
||||
if( c == WEOF )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
sb_append_char( b, c );
|
||||
}
|
||||
}
|
||||
|
||||
static void insert_tabs( string_buffer_t *out, int indent )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i=0; i<indent; i++ )
|
||||
{
|
||||
sb_append( out, L"\t" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
589
fish_pager.c
589
fish_pager.c
@@ -42,6 +42,11 @@
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef HAVE_GETOPT_H
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "fallback.h"
|
||||
#include "util.h"
|
||||
@@ -54,6 +59,7 @@
|
||||
#include "env_universal.h"
|
||||
#include "halloc.h"
|
||||
#include "halloc_util.h"
|
||||
#include "print_help.h"
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -92,7 +98,7 @@ enum
|
||||
;
|
||||
|
||||
/**
|
||||
The minimum number of columns the terminal may have for fish_pager to not refuse showing the completions
|
||||
The minimum width (in characters) the terminal may have for fish_pager to not refuse showing the completions
|
||||
*/
|
||||
#define PAGER_MIN_WIDTH 16
|
||||
|
||||
@@ -101,11 +107,20 @@ enum
|
||||
*/
|
||||
#define PAGER_MAX_COLS 6
|
||||
|
||||
/**
|
||||
The string describing the single-character options accepted by fish_pager
|
||||
*/
|
||||
#define GETOPT_STRING "c:hr:qvp:"
|
||||
|
||||
/**
|
||||
Error to use when given an invalid file descriptor for reading completions or writing output
|
||||
*/
|
||||
#define ERR_NOT_FD _( L"%ls: Argument '%s' is not a valid file descriptor\n" )
|
||||
|
||||
/**
|
||||
This struct should be continually updated by signals as the term
|
||||
resizes, and as such always contain the correct current size.
|
||||
*/
|
||||
|
||||
static struct winsize termsize;
|
||||
|
||||
/**
|
||||
@@ -151,7 +166,7 @@ static FILE *out_file;
|
||||
|
||||
/**
|
||||
Data structure describing one or a group of related completions
|
||||
*/
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/**
|
||||
@@ -238,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' )
|
||||
@@ -270,7 +285,7 @@ static wint_t readch()
|
||||
struct mapping m[]=
|
||||
{
|
||||
{
|
||||
"\e[A", LINE_UP
|
||||
"\x1b[A", LINE_UP
|
||||
}
|
||||
,
|
||||
{
|
||||
@@ -278,7 +293,7 @@ static wint_t readch()
|
||||
}
|
||||
,
|
||||
{
|
||||
"\e[B", LINE_DOWN
|
||||
"\x1b[B", LINE_DOWN
|
||||
}
|
||||
,
|
||||
{
|
||||
@@ -309,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;
|
||||
}
|
||||
@@ -393,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
|
||||
@@ -423,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 );
|
||||
}
|
||||
@@ -452,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;
|
||||
@@ -505,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
|
||||
@@ -563,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];
|
||||
@@ -599,12 +619,26 @@ 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 whole list fit on-screen
|
||||
Terminal almost wide enough, or squeezing makes the
|
||||
whole list fit on-screen.
|
||||
|
||||
This part of the code is really important. People hate
|
||||
having to scroll through the completion list. In cases
|
||||
where there are a huge number of completions, it can't
|
||||
be helped, but it is not uncommon for the completions to
|
||||
_almost_ fit on one screen. In those cases, it is almost
|
||||
always desirable to 'squeeze' the completions into a
|
||||
single page.
|
||||
|
||||
If we are using N columns and can get everything to
|
||||
fit using squeezing, but everything would also fit
|
||||
using N-1 columns, don't try.
|
||||
*/
|
||||
|
||||
int tot_width = min_tot_width;
|
||||
width = min_width;
|
||||
|
||||
@@ -643,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
|
||||
@@ -663,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 );
|
||||
@@ -686,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 );
|
||||
|
||||
}
|
||||
@@ -707,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;
|
||||
}
|
||||
@@ -721,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
|
||||
{
|
||||
@@ -745,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
|
||||
{
|
||||
@@ -915,7 +961,8 @@ 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 );
|
||||
al_push( comp->comp, str );
|
||||
@@ -973,45 +1020,52 @@ static int interrupt_handler()
|
||||
it with a copy of stderr, so the reading of completion strings must
|
||||
be done before init is called.
|
||||
*/
|
||||
static void init()
|
||||
static void init( int mangle_descriptors, int out )
|
||||
{
|
||||
struct sigaction act;
|
||||
|
||||
static struct termios pager_modes;
|
||||
|
||||
|
||||
program_name = L"fish_pager";
|
||||
wsetlocale( LC_ALL, L"" );
|
||||
|
||||
/*
|
||||
Make fd 1 output to screen, and use some other fd for writing
|
||||
the resulting output back to the caller
|
||||
*/
|
||||
int out = dup( 1 );
|
||||
int in = dup( 0 );
|
||||
close(1);
|
||||
close(0);
|
||||
|
||||
if( (in = open( ttyname(2), O_RDWR )) != -1 )
|
||||
char *term;
|
||||
|
||||
if( mangle_descriptors )
|
||||
{
|
||||
if( dup2( 2, 1 ) == -1 )
|
||||
{
|
||||
debug( 0, _(L"Could not set up output file descriptors for pager") );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
if( dup2( in, 0 ) == -1 )
|
||||
{
|
||||
debug( 0, _(L"Could not set up input file descriptors for pager %d"), in );
|
||||
/*
|
||||
Make fd 1 output to screen, and use some other fd for writing
|
||||
the resulting output back to the caller
|
||||
*/
|
||||
int in;
|
||||
out = dup( 1 );
|
||||
close(1);
|
||||
close(0);
|
||||
|
||||
if( (in = open( ttyname(2), O_RDWR )) != -1 )
|
||||
{
|
||||
if( dup2( 2, 1 ) == -1 )
|
||||
{
|
||||
debug( 0, _(L"Could not set up output file descriptors for pager") );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
if( dup2( in, 0 ) == -1 )
|
||||
{
|
||||
debug( 0, _(L"Could not set up input file descriptors for pager") );
|
||||
exit( 1 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
debug( 0, _(L"Could not open tty for pager") );
|
||||
exit( 1 );
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if( !(out_file = fdopen( out, "w" )) )
|
||||
{
|
||||
debug( 0, _(L"Could not open tty for pager") );
|
||||
debug( 0, _(L"Could not initialize result pipe" ) );
|
||||
exit( 1 );
|
||||
}
|
||||
out_file = fdopen( out, "w" );
|
||||
|
||||
|
||||
/**
|
||||
Init the stringbuffer used to keep any output in
|
||||
@@ -1039,22 +1093,23 @@ static void init()
|
||||
|
||||
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 )
|
||||
{
|
||||
@@ -1062,6 +1117,14 @@ static void init()
|
||||
exit(1);
|
||||
}
|
||||
|
||||
term = getenv("TERM");
|
||||
if( term )
|
||||
{
|
||||
wchar_t *wterm = str2wcs(term);
|
||||
output_set_term( wterm );
|
||||
free( wterm );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1071,7 +1134,6 @@ static void destroy()
|
||||
{
|
||||
env_universal_destroy();
|
||||
input_common_destroy();
|
||||
halloc_util_destroy();
|
||||
wutil_destroy();
|
||||
if( del_curterm( cur_term ) == ERR )
|
||||
{
|
||||
@@ -1101,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;
|
||||
@@ -1126,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 );
|
||||
}
|
||||
}
|
||||
@@ -1136,99 +1201,281 @@ static void read_array( FILE* file, array_list_t *comp )
|
||||
|
||||
}
|
||||
|
||||
static int get_fd( const char *str )
|
||||
{
|
||||
char *end;
|
||||
long fd;
|
||||
|
||||
errno = 0;
|
||||
fd = strtol( str, &end, 10 );
|
||||
if( fd < 0 || *end || errno )
|
||||
{
|
||||
debug( 0, ERR_NOT_FD, program_name, optarg );
|
||||
exit( 1 );
|
||||
}
|
||||
return (int)fd;
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
int i;
|
||||
int is_quoted=0;
|
||||
array_list_t *comp;
|
||||
wchar_t *prefix;
|
||||
wchar_t *prefix = 0;
|
||||
|
||||
int mangle_descriptors = 0;
|
||||
int result_fd = -1;
|
||||
|
||||
/*
|
||||
This initialization is made early, so that the other init code
|
||||
can use global_context for memory managment
|
||||
*/
|
||||
halloc_util_init();
|
||||
program_name = L"fish_pager";
|
||||
|
||||
if( argc < 3 )
|
||||
|
||||
wsetlocale( LC_ALL, L"" );
|
||||
comp = al_halloc( global_context );
|
||||
|
||||
/*
|
||||
The call signature for fish_pager is a mess. Because we want
|
||||
to be able to upgrade fish without breaking running
|
||||
instances, we need to support all previous
|
||||
modes. Unfortunatly, the two previous ones are a mess. The
|
||||
third one is designed to be extensible, so hopefully it will
|
||||
be the last.
|
||||
*/
|
||||
|
||||
if( argc > 1 && argv[1][0] == '-' )
|
||||
{
|
||||
debug( 0, _(L"Insufficient arguments") );
|
||||
/*
|
||||
Third mode
|
||||
*/
|
||||
|
||||
int completion_fd = -1;
|
||||
FILE *completion_file;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
static struct option
|
||||
long_options[] =
|
||||
{
|
||||
{
|
||||
"result-fd", required_argument, 0, 'r'
|
||||
}
|
||||
,
|
||||
{
|
||||
"completion-fd", required_argument, 0, 'c'
|
||||
}
|
||||
,
|
||||
{
|
||||
"prefix", required_argument, 0, 'p'
|
||||
}
|
||||
,
|
||||
{
|
||||
"is-quoted", no_argument, 0, 'q'
|
||||
}
|
||||
,
|
||||
{
|
||||
"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 'r':
|
||||
{
|
||||
result_fd = get_fd( optarg );
|
||||
break;
|
||||
}
|
||||
|
||||
case 'c':
|
||||
{
|
||||
completion_fd = get_fd( optarg );
|
||||
break;
|
||||
}
|
||||
|
||||
case 'p':
|
||||
{
|
||||
prefix = str2wcs(optarg);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'h':
|
||||
{
|
||||
print_help( argv[0], 1 );
|
||||
exit(0);
|
||||
}
|
||||
|
||||
case 'v':
|
||||
{
|
||||
debug( 0, L"%ls, version %s\n", program_name, PACKAGE_VERSION );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
case 'q':
|
||||
{
|
||||
is_quoted = 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if( completion_fd == -1 || result_fd == -1 )
|
||||
{
|
||||
debug( 0, _(L"Unspecified file descriptors") );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
|
||||
if( (completion_file = fdopen( completion_fd, "r" ) ) )
|
||||
{
|
||||
read_array( completion_file, comp );
|
||||
fclose( completion_file );
|
||||
}
|
||||
else
|
||||
{
|
||||
debug( 0, _(L"Could not read completions") );
|
||||
wperror( L"fdopen" );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
if( !prefix )
|
||||
{
|
||||
prefix = wcsdup( L"" );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
Second or first mode. These suck, but we need to support
|
||||
them for backwards compatibility. At least for some
|
||||
time.
|
||||
|
||||
comp = al_halloc( global_context );
|
||||
prefix = str2wcs( argv[2] );
|
||||
is_quoted = strcmp( "1", argv[1] )==0;
|
||||
is_quoted = 0;
|
||||
Third mode was implemented in January 2007, and previous
|
||||
modes should be considered deprecated from that point
|
||||
forward. A reasonable time frame for removal of the code
|
||||
below has yet to be determined.
|
||||
*/
|
||||
|
||||
if( argc < 3 )
|
||||
{
|
||||
print_help( argv[0], 1 );
|
||||
exit( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
mangle_descriptors = 1;
|
||||
|
||||
prefix = str2wcs( argv[2] );
|
||||
is_quoted = strcmp( "1", argv[1] )==0;
|
||||
|
||||
if( argc > 3 )
|
||||
{
|
||||
/*
|
||||
First mode
|
||||
*/
|
||||
for( i=3; i<argc; i++ )
|
||||
{
|
||||
wchar_t *wcs = str2wcs( argv[i] );
|
||||
if( wcs )
|
||||
{
|
||||
al_push( comp, wcs );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
Second mode
|
||||
*/
|
||||
read_array( stdin, comp );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// debug( 3, L"prefix is '%ls'", prefix );
|
||||
|
||||
if( argc > 3 )
|
||||
init( mangle_descriptors, result_fd );
|
||||
|
||||
mangle_descriptions( comp );
|
||||
|
||||
if( wcscmp( prefix, L"-" ) == 0 )
|
||||
join_completions( comp );
|
||||
|
||||
mangle_completions( comp, prefix );
|
||||
|
||||
/**
|
||||
Try to print the completions. Start by trying to print the
|
||||
list in PAGER_MAX_COLS columns, if the completions won't
|
||||
fit, reduce the number of columns by one. Printing a single
|
||||
column never fails.
|
||||
*/
|
||||
for( i = PAGER_MAX_COLS; i>0; i-- )
|
||||
{
|
||||
switch( completion_try_print( i, prefix, is_quoted, comp ) )
|
||||
{
|
||||
for( i=3; i<argc; i++ )
|
||||
{
|
||||
wchar_t *wcs = str2wcs( argv[i] );
|
||||
if( wcs )
|
||||
{
|
||||
al_push( comp, wcs );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
read_array( stdin, comp );
|
||||
}
|
||||
|
||||
init();
|
||||
case PAGER_RETRY:
|
||||
break;
|
||||
|
||||
mangle_descriptions( comp );
|
||||
case PAGER_DONE:
|
||||
i=0;
|
||||
break;
|
||||
|
||||
if( wcscmp( prefix, L"-" ) == 0 )
|
||||
join_completions( comp );
|
||||
case PAGER_RESIZE:
|
||||
/*
|
||||
This means we got a resize event, so we start
|
||||
over from the beginning. Since it the screen got
|
||||
bigger, we might be able to fit all completions
|
||||
on-screen.
|
||||
*/
|
||||
i=PAGER_MAX_COLS+1;
|
||||
break;
|
||||
|
||||
mangle_completions( comp, prefix );
|
||||
|
||||
/**
|
||||
Try to print the completions. Start by trying to print the
|
||||
list in PAGER_MAX_COLS columns, if the completions won't
|
||||
fit, reduce the number of columns by one. Printing a single
|
||||
column never fails.
|
||||
*/
|
||||
for( i = PAGER_MAX_COLS; i>0; i-- )
|
||||
{
|
||||
switch( completion_try_print( i, prefix, is_quoted, comp ) )
|
||||
{
|
||||
|
||||
case PAGER_RETRY:
|
||||
break;
|
||||
|
||||
case PAGER_DONE:
|
||||
i=0;
|
||||
break;
|
||||
|
||||
case PAGER_RESIZE:
|
||||
/*
|
||||
This means we got a resize event, so we start
|
||||
over from the beginning. Since it the screen got
|
||||
bigger, we might be able to fit all completions
|
||||
on-screen.
|
||||
*/
|
||||
i=PAGER_MAX_COLS+1;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
free(prefix );
|
||||
|
||||
fwprintf( out_file, L"%ls", (wchar_t *)out_buff.buff );
|
||||
if( is_ca_mode )
|
||||
{
|
||||
writembs(exit_ca_mode);
|
||||
pager_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(prefix );
|
||||
|
||||
fwprintf( out_file, L"%ls", (wchar_t *)out_buff.buff );
|
||||
if( is_ca_mode )
|
||||
{
|
||||
writembs(exit_ca_mode);
|
||||
pager_flush();
|
||||
}
|
||||
destroy();
|
||||
|
||||
halloc_util_destroy();
|
||||
|
||||
}
|
||||
|
||||
|
||||
180
fish_tests.c
180
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,26 @@ static void test_expand()
|
||||
|
||||
}
|
||||
|
||||
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 +843,16 @@ void perf_complete()
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Main test
|
||||
*/
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
setlocale( LC_ALL, "" );
|
||||
srand( time( 0 ) );
|
||||
|
||||
program_name=L"(ignore)";
|
||||
|
||||
@@ -694,10 +869,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 );
|
||||
|
||||
/*
|
||||
|
||||
8
fishd.c
8
fishd.c
@@ -73,6 +73,7 @@ time the original barrier request was sent have been received.
|
||||
#include "halloc.h"
|
||||
#include "halloc_util.h"
|
||||
#include "path.h"
|
||||
#include "print_help.h"
|
||||
|
||||
/**
|
||||
Maximum length of socket filename
|
||||
@@ -140,11 +141,6 @@ static int sock;
|
||||
*/
|
||||
static int quit=0;
|
||||
|
||||
/**
|
||||
Dynamically generated function, made from the documentation in doc_src.
|
||||
*/
|
||||
void print_help();
|
||||
|
||||
/**
|
||||
Constructs the fish socket filename
|
||||
*/
|
||||
@@ -620,7 +616,7 @@ int main( int argc, char ** argv )
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
print_help();
|
||||
print_help( argv[0], 1 );
|
||||
exit(0);
|
||||
|
||||
case 'v':
|
||||
|
||||
164
function.c
164
function.c
@@ -1,5 +1,10 @@
|
||||
/** \file function.c
|
||||
Functions for storing and retrieving function information.
|
||||
|
||||
Prototypes for functions for storing and retrieving function
|
||||
information. These functions also take care of autoloading
|
||||
functions in the $fish_function_path. Actual function evaluation
|
||||
is taken care of by the parser and to some degree the builtin
|
||||
handling library.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
@@ -23,8 +28,11 @@
|
||||
#include "event.h"
|
||||
#include "reader.h"
|
||||
#include "parse_util.h"
|
||||
#include "parser_keywords.h"
|
||||
#include "env.h"
|
||||
#include "expand.h"
|
||||
#include "halloc.h"
|
||||
#include "halloc_util.h"
|
||||
|
||||
|
||||
/**
|
||||
@@ -44,13 +52,18 @@ typedef struct
|
||||
Line where definition started
|
||||
*/
|
||||
int definition_offset;
|
||||
|
||||
array_list_t *named_arguments;
|
||||
|
||||
|
||||
/**
|
||||
Flag for specifying that this function was automatically loaded
|
||||
*/
|
||||
int is_autoload;
|
||||
|
||||
int shadows;
|
||||
}
|
||||
function_data_t;
|
||||
function_internal_data_t;
|
||||
|
||||
/**
|
||||
Table containing all functions
|
||||
@@ -72,8 +85,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;
|
||||
|
||||
@@ -135,19 +148,6 @@ static void autoload_names( array_list_t *out, int get_hidden )
|
||||
al_destroy( &path_list );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Free all contents of an entry to the function hash table
|
||||
*/
|
||||
static void clear_function_entry( void *key,
|
||||
void *data )
|
||||
{
|
||||
function_data_t *d = (function_data_t *)data;
|
||||
free( (void *)d->cmd );
|
||||
free( (void *)d->desc );
|
||||
free( (void *)d );
|
||||
}
|
||||
|
||||
void function_init()
|
||||
{
|
||||
hash_init( &function,
|
||||
@@ -155,42 +155,55 @@ void function_init()
|
||||
&hash_wcs_cmp );
|
||||
}
|
||||
|
||||
static void clear_entry( void *key, void *value )
|
||||
{
|
||||
halloc_free( value );
|
||||
}
|
||||
|
||||
void function_destroy()
|
||||
{
|
||||
hash_foreach( &function, &clear_function_entry );
|
||||
hash_foreach( &function, &clear_entry );
|
||||
hash_destroy( &function );
|
||||
}
|
||||
|
||||
|
||||
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 = malloc( 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 = wcsdup( val );
|
||||
d->cmd = 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;
|
||||
|
||||
d->desc = desc?wcsdup( desc ):0;
|
||||
d->desc = 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 ) );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -200,7 +213,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 );
|
||||
@@ -211,7 +224,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, );
|
||||
@@ -221,7 +234,7 @@ void function_remove( const wchar_t *name )
|
||||
&key,
|
||||
&dv );
|
||||
|
||||
d=(function_data_t *)dv;
|
||||
d=(function_internal_data_t *)dv;
|
||||
|
||||
if( !key )
|
||||
return;
|
||||
@@ -230,7 +243,7 @@ void function_remove( const wchar_t *name )
|
||||
ev.function_name=name;
|
||||
event_remove( &ev );
|
||||
|
||||
clear_function_entry( key, d );
|
||||
halloc_free( d );
|
||||
|
||||
/*
|
||||
Notify the autoloader that the specified function is erased, but
|
||||
@@ -243,27 +256,54 @@ 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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -272,17 +312,17 @@ const wchar_t *function_get_desc( const wchar_t *argv )
|
||||
|
||||
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 =wcsdup(desc);
|
||||
data->desc = halloc_wcsdup( data, desc );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -294,9 +334,9 @@ static int al_contains_str( array_list_t *list, const wchar_t * str )
|
||||
for( i=0; i<al_get_count( list ); i++ )
|
||||
{
|
||||
if( wcscmp( al_get( list, i ), str) == 0 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -347,13 +387,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;
|
||||
|
||||
@@ -361,13 +401,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;
|
||||
|
||||
|
||||
59
function.h
59
function.h
@@ -1,8 +1,10 @@
|
||||
/** \file function.h
|
||||
|
||||
Prototypes for functions for storing and retrieving function
|
||||
information. Actual function evaluation is taken care of by the
|
||||
parser and to some degree the builtin handling library.
|
||||
information. These functions also take care of autoloading
|
||||
functions in the $fish_function_path. Actual function evaluation
|
||||
is taken care of by the parser and to some degree the builtin
|
||||
handling library.
|
||||
*/
|
||||
|
||||
#ifndef FISH_FUNCTION_H
|
||||
@@ -12,33 +14,42 @@
|
||||
|
||||
#include "util.h"
|
||||
|
||||
/**
|
||||
Structure describing a function
|
||||
*/
|
||||
typedef struct function_data
|
||||
{
|
||||
wchar_t *name;
|
||||
wchar_t *description;
|
||||
wchar_t *definition;
|
||||
array_list_t *events;
|
||||
array_list_t *named_arguments;
|
||||
int shadows;
|
||||
}
|
||||
function_data_t;
|
||||
|
||||
|
||||
/**
|
||||
Initialize function data
|
||||
*/
|
||||
void function_init();
|
||||
|
||||
/**
|
||||
Destroy function data
|
||||
*/
|
||||
void function_destroy();
|
||||
|
||||
/**
|
||||
Add an function. The parameters values are copied and should be freed by the caller.
|
||||
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.
|
||||
*/
|
||||
void function_remove( const wchar_t *name );
|
||||
|
||||
/**
|
||||
Returns true if the function with the name name uses internal variables, false otherwise.
|
||||
*/
|
||||
int function_use_vars( const wchar_t *name );
|
||||
|
||||
/**
|
||||
Returns the definition of the function with the name \c name.
|
||||
*/
|
||||
@@ -55,12 +66,13 @@ const wchar_t *function_get_desc( const wchar_t *name );
|
||||
void function_set_desc( const wchar_t *name, const wchar_t *desc );
|
||||
|
||||
/**
|
||||
Returns true if the function witrh the name name exists.
|
||||
Returns true if the function with the name name exists.
|
||||
*/
|
||||
int function_exists( const wchar_t *name );
|
||||
|
||||
/**
|
||||
Insert all function names into l. These are not copies of the strings and should not be freed after use.
|
||||
Insert all function names into l. These are not copies of the
|
||||
strings and should not be freed after use.
|
||||
|
||||
\param list the list to add the names to
|
||||
\param get_hidden whether to include hidden functions, i.e. ones starting with an underscore
|
||||
@@ -71,12 +83,29 @@ void function_get_names( array_list_t *list,
|
||||
/**
|
||||
Returns tha absolute path of the file where the specified function
|
||||
was defined. Returns 0 if the file was defined on the commandline.
|
||||
|
||||
This function does not autoload functions, it will only work on
|
||||
functions that have already been defined.
|
||||
*/
|
||||
const wchar_t *function_get_definition_file( const wchar_t *name );
|
||||
|
||||
/**
|
||||
Returns the linenumber where the definition of the specified function started
|
||||
Returns the linenumber where the definition of the specified
|
||||
function started.
|
||||
|
||||
This function does not autoload functions, it will only work on
|
||||
functions that have already been defined.
|
||||
*/
|
||||
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
|
||||
|
||||
12
gen_hdr.sh
12
gen_hdr.sh
@@ -1,12 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This little script calls the man command to render a manual page and
|
||||
# pipes the result into the gen_hdr2 program to convert the output
|
||||
# into a C string literal.
|
||||
|
||||
# NAME is the name of the function we are generating documentation for.
|
||||
NAME=`basename $1 .doxygen`
|
||||
|
||||
# Render the page
|
||||
nroff -man doc_src/builtin_doc/man/man1/${NAME}.1 | col -b | cat -s | sed -e '$d' | ./gen_hdr2
|
||||
|
||||
76
gen_hdr2.c
76
gen_hdr2.c
@@ -1,76 +0,0 @@
|
||||
/** \file gen_hdr2.c
|
||||
A program that reads data from stdin and outputs it as a C string.
|
||||
|
||||
It is used as a part of the build process to generate help texts
|
||||
for the built in commands.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
/**
|
||||
The main function, does all the work
|
||||
*/
|
||||
int main()
|
||||
{
|
||||
int line = 0;
|
||||
printf( "\t\t\"" );
|
||||
int c;
|
||||
int count=0;
|
||||
while( (c=getchar()) != EOF )
|
||||
{
|
||||
if( c == '\n' )
|
||||
line++;
|
||||
|
||||
if( line > 4 )
|
||||
break;
|
||||
}
|
||||
|
||||
while( (c=getchar()) != EOF )
|
||||
{
|
||||
if( (c >= 'a' && c <= 'z' ) ||
|
||||
(c >= 'A' && c <= 'Z' ) ||
|
||||
(c >= '0' && c <= '9' ) ||
|
||||
( strchr(" ,.!;:-_#$%&(){}[]<>=?+-*/'",c) != 0) )
|
||||
{
|
||||
count++;
|
||||
putchar(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(c)
|
||||
{
|
||||
case '\n':
|
||||
printf( "\\n" );
|
||||
printf( "\"\n\t\t\"" );
|
||||
count =0;
|
||||
break;
|
||||
case '\t':
|
||||
printf( "\\t" );
|
||||
count +=2;
|
||||
break;
|
||||
case '\r':
|
||||
printf( "\\r" );
|
||||
count +=2;
|
||||
break;
|
||||
|
||||
case '\"':
|
||||
case '\\':
|
||||
printf( "\\%c",c );
|
||||
count +=2;
|
||||
break;
|
||||
|
||||
default:
|
||||
count +=7;
|
||||
printf( "\\x%02x\" \"", c );
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( count > 60 )
|
||||
{
|
||||
count=0;
|
||||
printf( "\"\n\t\t\"" );
|
||||
}
|
||||
}
|
||||
printf( "\"" );
|
||||
return 0;
|
||||
}
|
||||
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,13 +78,13 @@ typedef struct halloc
|
||||
}
|
||||
halloc_t;
|
||||
|
||||
static void *align_ptr( void *in )
|
||||
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;
|
||||
}
|
||||
|
||||
static size_t align_sz( size_t in )
|
||||
@@ -132,8 +132,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 +142,7 @@ void *halloc( void *context, size_t size )
|
||||
pid = getpid();
|
||||
atexit( &halloc_report );
|
||||
}
|
||||
|
||||
|
||||
child_count++;
|
||||
child_size += size;
|
||||
#endif
|
||||
@@ -179,14 +179,18 @@ void *halloc( void *context, size_t size )
|
||||
alloc_spill += parent->scratch_free;
|
||||
#endif
|
||||
res = calloc( 1, size + HALLOC_BLOCK_SIZE );
|
||||
if( !res )
|
||||
DIE_MEM();
|
||||
parent->scratch = (char *)res + size;
|
||||
parent->scratch_free = HALLOC_BLOCK_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = calloc( 1, size );
|
||||
if( !res )
|
||||
DIE_MEM();
|
||||
}
|
||||
al_push( &parent->children, &late_free );
|
||||
al_push_func( &parent->children, &late_free );
|
||||
al_push( &parent->children, res );
|
||||
|
||||
}
|
||||
@@ -198,7 +202,7 @@ void *halloc( void *context, size_t size )
|
||||
me = (halloc_t *)calloc( 1, align_sz(sizeof(halloc_t)) + align_sz(size) + HALLOC_BLOCK_SIZE );
|
||||
|
||||
if( !me )
|
||||
return 0;
|
||||
DIE_MEM();
|
||||
#ifdef HALLOC_DEBUG
|
||||
parent_count++;
|
||||
#endif
|
||||
@@ -217,7 +221,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 );
|
||||
}
|
||||
|
||||
@@ -244,7 +248,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;
|
||||
}
|
||||
|
||||
|
||||
125
highlight.c
125
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;
|
||||
@@ -540,6 +545,11 @@ void highlight_shell( wchar_t * buff,
|
||||
|
||||
void *context;
|
||||
wchar_t *cmd=0;
|
||||
int accept_switches = 1;
|
||||
|
||||
int use_function = 1;
|
||||
int use_command = 1;
|
||||
int use_builtin = 1;
|
||||
|
||||
CHECK( buff, );
|
||||
CHECK( color, );
|
||||
@@ -572,10 +582,22 @@ void highlight_shell( wchar_t * buff,
|
||||
wchar_t *param = tok_last( &tok );
|
||||
if( param[0] == L'-' )
|
||||
{
|
||||
if( complete_is_valid_option( last_cmd, param, error ))
|
||||
if (wcscmp( param, L"--" ) == 0 )
|
||||
{
|
||||
accept_switches = 0;
|
||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_PARAM;
|
||||
}
|
||||
else if( accept_switches )
|
||||
{
|
||||
if( complete_is_valid_option( last_cmd, param, error ) )
|
||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_PARAM;
|
||||
else
|
||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
||||
}
|
||||
else
|
||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
||||
{
|
||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_PARAM;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -585,11 +607,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;
|
||||
}
|
||||
@@ -625,23 +650,50 @@ 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;
|
||||
|
||||
if( wcscmp( cmd, L"builtin" )==0)
|
||||
{
|
||||
use_function = 0;
|
||||
use_command = 0;
|
||||
use_builtin = 1;
|
||||
}
|
||||
else if( wcscmp( cmd, L"command" )==0)
|
||||
{
|
||||
use_command = 1;
|
||||
use_function = 0;
|
||||
use_builtin = 0;
|
||||
}
|
||||
|
||||
tok_next( &tok );
|
||||
if( ( ! parser_is_block( cmd ) ) &&
|
||||
( ( wcscmp( L"-h", tok_last( &tok ) ) == 0 ) ||
|
||||
( wcsncmp( L"--help", tok_last( &tok ), wcslen( tok_last( &tok ) ) ) == 0 && wcslen( tok_last( &tok ) ) >= 3 ) ) )
|
||||
|
||||
sw = parser_keywords_is_switch( tok_last( &tok ) );
|
||||
|
||||
if( !parser_keywords_is_block( cmd ) &&
|
||||
sw == ARG_SWITCH )
|
||||
{
|
||||
/*
|
||||
The builtin and command builtins
|
||||
The 'builtin' and 'command' builtins
|
||||
are normally followed by another
|
||||
command, but if they are invoked
|
||||
with the -h option, their help text
|
||||
is displayed instead
|
||||
with a switch, they aren't.
|
||||
|
||||
*/
|
||||
use_command = 1;
|
||||
use_function = 1;
|
||||
use_builtin = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( sw == ARG_SKIP )
|
||||
{
|
||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_PARAM;
|
||||
mark = tok_get_pos( &tok );
|
||||
}
|
||||
|
||||
is_subcommand = 1;
|
||||
}
|
||||
tok_set_pos( &tok, mark );
|
||||
@@ -662,8 +714,11 @@ void highlight_shell( wchar_t * buff,
|
||||
function, since we don't have to stat
|
||||
any files for that
|
||||
*/
|
||||
is_cmd |= builtin_exists( cmd );
|
||||
is_cmd |= function_exists( cmd );
|
||||
if( use_builtin )
|
||||
is_cmd |= builtin_exists( cmd );
|
||||
|
||||
if( use_function )
|
||||
is_cmd |= function_exists( cmd );
|
||||
|
||||
/*
|
||||
Moving on to expensive tests
|
||||
@@ -672,13 +727,15 @@ void highlight_shell( wchar_t * buff,
|
||||
/*
|
||||
Check if this is a regular command
|
||||
*/
|
||||
is_cmd |= !!(tmp=path_get_path( context, cmd ));
|
||||
if( use_command )
|
||||
is_cmd |= !!(tmp=path_get_path( context, cmd ));
|
||||
|
||||
/*
|
||||
Could not find the command. Maybe it is
|
||||
a path for a implicit cd command.
|
||||
*/
|
||||
is_cmd |= !!(tmp=path_get_cdpath( context, cmd ));
|
||||
if( use_builtin || (use_function && function_exists( L"cd") ) )
|
||||
is_cmd |= !!(tmp=path_get_cdpath( context, cmd ));
|
||||
|
||||
if( is_cmd )
|
||||
{
|
||||
@@ -687,7 +744,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;
|
||||
@@ -703,6 +760,7 @@ void highlight_shell( wchar_t * buff,
|
||||
break;
|
||||
}
|
||||
|
||||
case TOK_REDIRECT_NOCLOB:
|
||||
case TOK_REDIRECT_OUT:
|
||||
case TOK_REDIRECT_IN:
|
||||
case TOK_REDIRECT_APPEND:
|
||||
@@ -761,7 +819,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" ) );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -771,13 +829,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" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -791,6 +858,10 @@ void highlight_shell( wchar_t * buff,
|
||||
{
|
||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_END;
|
||||
had_cmd = 0;
|
||||
use_command = 1;
|
||||
use_function = 1;
|
||||
use_builtin = 1;
|
||||
accept_switches = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -806,6 +877,10 @@ void highlight_shell( wchar_t * buff,
|
||||
{
|
||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_END;
|
||||
had_cmd = 0;
|
||||
use_command = 1;
|
||||
use_function = 1;
|
||||
use_builtin = 1;
|
||||
accept_switches = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
97
history.c
97
history.c
@@ -1,5 +1,5 @@
|
||||
/** \file history.c
|
||||
History functions, part of the user interface.
|
||||
History functions, part of the user interface.
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
@@ -345,9 +345,13 @@ static item_t *item_get( history_mode_t *m, void *d )
|
||||
|
||||
if( *time_string )
|
||||
{
|
||||
time_t tm = (time_t)wcstol( time_string, 0, 10 );
|
||||
|
||||
if( tm && !errno )
|
||||
time_t tm;
|
||||
wchar_t *end;
|
||||
|
||||
errno = 0;
|
||||
tm = (time_t)wcstol( time_string, &end, 10 );
|
||||
|
||||
if( tm && !errno && !*end )
|
||||
{
|
||||
narrow_item.timestamp = tm;
|
||||
}
|
||||
@@ -385,10 +389,10 @@ static item_t *item_get( history_mode_t *m, void *d )
|
||||
/**
|
||||
Write the specified item to the specified file.
|
||||
*/
|
||||
static void item_write( FILE *f, history_mode_t *m, void *v )
|
||||
static int item_write( FILE *f, history_mode_t *m, void *v )
|
||||
{
|
||||
item_t *i = item_get( m, v );
|
||||
fwprintf( f, L"# %d\n%ls\n", i->timestamp, history_escape_newlines( i->data ) );
|
||||
return fwprintf( f, L"# %d\n%ls\n", i->timestamp, history_escape_newlines( i->data ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -464,7 +468,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;
|
||||
}
|
||||
@@ -503,7 +507,8 @@ static void history_populate_from_mmap( history_mode_t *m )
|
||||
if( (i_orig=hash_get( ¤t_mode->session_item, i ) ) )
|
||||
{
|
||||
/*
|
||||
This item comes from this session. Insert the original item at the end of the item list.
|
||||
This item comes from this session. Insert the
|
||||
original item at the end of the item list.
|
||||
*/
|
||||
al_push( &session_item_list, i_orig );
|
||||
}
|
||||
@@ -604,11 +609,14 @@ static void history_save_mode( void *n, history_mode_t *m )
|
||||
FILE *out;
|
||||
history_mode_t *on_disk;
|
||||
int i;
|
||||
int has_new;
|
||||
int has_new=0;
|
||||
wchar_t *tmp_name;
|
||||
|
||||
int ok = 1;
|
||||
|
||||
/*
|
||||
First check if there are any new entries to save. If not, thenm we can just return
|
||||
First check if there are any new entries to save. If not, then
|
||||
we can just return
|
||||
*/
|
||||
for( i=0; i<al_get_count(&m->item); i++ )
|
||||
{
|
||||
@@ -628,7 +636,8 @@ static void history_save_mode( void *n, history_mode_t *m )
|
||||
signal_block();
|
||||
|
||||
/*
|
||||
Set up on_disk variable to describe the current contents of the history file
|
||||
Set up on_disk variable to describe the current contents of the
|
||||
history file
|
||||
*/
|
||||
on_disk = history_create_mode( m->name );
|
||||
history_load( on_disk );
|
||||
@@ -658,12 +667,19 @@ static void history_save_mode( void *n, history_mode_t *m )
|
||||
/*
|
||||
Re-save the old history
|
||||
*/
|
||||
for( i=0; i<al_get_count(&on_disk->item); i++ )
|
||||
for( i=0; ok && (i<al_get_count(&on_disk->item)); i++ )
|
||||
{
|
||||
void *ptr = al_get( &on_disk->item, i );
|
||||
item_t *i = item_get( on_disk, ptr );
|
||||
if( !hash_get( &mine, i ) )
|
||||
item_write( out, on_disk, ptr );
|
||||
{
|
||||
if( item_write( out, on_disk, ptr ) == -1 )
|
||||
{
|
||||
ok = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
hash_destroy( &mine );
|
||||
@@ -671,15 +687,20 @@ static void history_save_mode( void *n, history_mode_t *m )
|
||||
/*
|
||||
Add our own items last
|
||||
*/
|
||||
for( i=0; i<al_get_count(&m->item); i++ )
|
||||
for( i=0; ok && (i<al_get_count(&m->item)); i++ )
|
||||
{
|
||||
void *ptr = al_get( &m->item, i );
|
||||
int is_new = item_is_new( m, ptr );
|
||||
if( is_new )
|
||||
item_write( out, m, ptr );
|
||||
{
|
||||
if( item_write( out, m, ptr ) == -1 )
|
||||
{
|
||||
ok = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( fclose( out ) )
|
||||
if( fclose( out ) || !ok )
|
||||
{
|
||||
/*
|
||||
This message does not have high enough priority to
|
||||
@@ -697,26 +718,32 @@ static void history_save_mode( void *n, history_mode_t *m )
|
||||
|
||||
halloc_free( on_disk);
|
||||
|
||||
/*
|
||||
Reset the history. The item_t entries created in this session
|
||||
are not lost or dropped, they are stored in the session_item
|
||||
hash table. On reload, they will be automatically inserted at
|
||||
the end of the history list.
|
||||
*/
|
||||
|
||||
if( m->mmap_start && (m->mmap_start != MAP_FAILED ) )
|
||||
munmap( m->mmap_start, m->mmap_length );
|
||||
|
||||
al_truncate( &m->item, 0 );
|
||||
al_truncate( &m->used, 0 );
|
||||
m->pos = 0;
|
||||
m->has_loaded = 0;
|
||||
m->mmap_start=0;
|
||||
m->mmap_length=0;
|
||||
|
||||
m->save_timestamp=time(0);
|
||||
m->new_count = 0;
|
||||
if( ok )
|
||||
{
|
||||
|
||||
/*
|
||||
Reset the history. The item_t entries created in this session
|
||||
are not lost or dropped, they are stored in the session_item
|
||||
hash table. On reload, they will be automatically inserted at
|
||||
the end of the history list.
|
||||
*/
|
||||
|
||||
if( m->mmap_start && (m->mmap_start != MAP_FAILED ) )
|
||||
{
|
||||
munmap( m->mmap_start, m->mmap_length );
|
||||
}
|
||||
|
||||
al_truncate( &m->item, 0 );
|
||||
al_truncate( &m->used, 0 );
|
||||
m->pos = 0;
|
||||
m->has_loaded = 0;
|
||||
m->mmap_start=0;
|
||||
m->mmap_length=0;
|
||||
|
||||
m->save_timestamp=time(0);
|
||||
m->new_count = 0;
|
||||
}
|
||||
|
||||
signal_unblock();
|
||||
}
|
||||
|
||||
|
||||
48
input.h
48
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,
|
||||
@@ -48,7 +45,10 @@ enum
|
||||
R_VI_DELETE_TO,
|
||||
R_EXECUTE,
|
||||
R_BEGINNING_OF_BUFFER,
|
||||
R_END_OF_BUFFER
|
||||
R_END_OF_BUFFER,
|
||||
R_REPAINT,
|
||||
R_UP_LINE,
|
||||
R_DOWN_LINE,
|
||||
}
|
||||
;
|
||||
|
||||
@@ -96,26 +96,42 @@ void input_unreadch( wint_t ch );
|
||||
\param d a description of the sequence
|
||||
\param cmd 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 *cmd );
|
||||
|
||||
void input_mapping_get_names( array_list_t *list );
|
||||
|
||||
int input_mapping_erase( const wchar_t *sequence );
|
||||
|
||||
const wchar_t *input_mapping_get( const wchar_t *sequence );
|
||||
|
||||
/**
|
||||
Sets the mode keybindings.
|
||||
*/
|
||||
void input_set_mode( wchar_t *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 );
|
||||
|
||||
/**
|
||||
Sets the application keybindings
|
||||
*/
|
||||
void input_set_application( 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 );
|
||||
|
||||
/**
|
||||
Parse a single line of inputrc information.
|
||||
*/
|
||||
void input_parse_inputrc_line( wchar_t *cmd );
|
||||
Return a list of all known terminfo names
|
||||
*/
|
||||
void input_terminfo_get_names( array_list_t *lst, int skip_null );
|
||||
|
||||
|
||||
/**
|
||||
Returns the function for the given function name.
|
||||
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
|
||||
@@ -98,6 +98,11 @@ static wint_t readb()
|
||||
{
|
||||
return res;
|
||||
}
|
||||
if( lookahead_count )
|
||||
{
|
||||
return lookahead_arr[--lookahead_count];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +112,7 @@ static wint_t readb()
|
||||
default:
|
||||
{
|
||||
/*
|
||||
The teminal has been closed. Save and exit.
|
||||
The terminal has been closed. Save and exit.
|
||||
*/
|
||||
return R_EOF;
|
||||
}
|
||||
@@ -122,6 +127,11 @@ static wint_t readb()
|
||||
debug( 3, L"Wake up on universal variable event" );
|
||||
env_universal_read_all();
|
||||
do_loop = 1;
|
||||
|
||||
if( lookahead_count )
|
||||
{
|
||||
return lookahead_arr[--lookahead_count];
|
||||
}
|
||||
}
|
||||
}
|
||||
if( FD_ISSET( 0, &fd ) )
|
||||
|
||||
2
intern.c
2
intern.c
@@ -31,6 +31,8 @@ static hash_table_t *intern_static_table=0;
|
||||
const wchar_t *intern( const wchar_t *in )
|
||||
{
|
||||
const wchar_t *res=0;
|
||||
|
||||
// debug( 0, L"intern %ls", in );
|
||||
|
||||
if( !in )
|
||||
return 0;
|
||||
|
||||
16
io.c
16
io.c
@@ -53,9 +53,8 @@ Utilities for io redirection.
|
||||
|
||||
void io_buffer_read( io_data_t *d )
|
||||
{
|
||||
|
||||
exec_close(d->param1.pipe_fd[1] );
|
||||
|
||||
|
||||
if( d->io_mode == IO_BUFFER )
|
||||
{
|
||||
/* if( fcntl( d->param1.pipe_fd[0], F_SETFL, 0 ) )
|
||||
@@ -108,7 +107,7 @@ io_data_t *io_buffer_create( int is_input )
|
||||
buffer_redirect->io_mode=IO_BUFFER;
|
||||
buffer_redirect->next=0;
|
||||
buffer_redirect->param2.out_buffer= malloc( sizeof(buffer_t));
|
||||
buffer_redirect->param3.is_input = is_input;
|
||||
buffer_redirect->is_input = is_input;
|
||||
b_init( buffer_redirect->param2.out_buffer );
|
||||
buffer_redirect->fd=is_input?0:1;
|
||||
|
||||
@@ -135,7 +134,16 @@ io_data_t *io_buffer_create( int is_input )
|
||||
|
||||
void io_buffer_destroy( io_data_t *io_buffer )
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
If this is an input buffer, then io_read_buffer will not have
|
||||
been called, and we need to close the output fd as well.
|
||||
*/
|
||||
if( io_buffer->is_input )
|
||||
{
|
||||
exec_close(io_buffer->param1.pipe_fd[1] );
|
||||
}
|
||||
|
||||
exec_close( io_buffer->param1.pipe_fd[0] );
|
||||
|
||||
/*
|
||||
|
||||
14
io.h
14
io.h
@@ -41,20 +41,10 @@ typedef struct io_data
|
||||
buffer_t *out_buffer;
|
||||
/** Whether to close old_fd for IO_FD */
|
||||
int close_old;
|
||||
|
||||
} param2
|
||||
;
|
||||
|
||||
union
|
||||
{
|
||||
/**
|
||||
This will be non-zero if this is a buffer of input, not
|
||||
output
|
||||
*/
|
||||
int is_input;
|
||||
}
|
||||
param3;
|
||||
|
||||
int is_input;
|
||||
|
||||
/** Pointer to the next IO redirection */
|
||||
struct io_data *next;
|
||||
@@ -78,7 +68,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 );
|
||||
}
|
||||
|
||||
158
make_completions.py
Executable file
158
make_completions.py
Executable file
@@ -0,0 +1,158 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
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 clean(s):
|
||||
res=s
|
||||
for r, str in cl.items():
|
||||
res = r.sub(str, res)
|
||||
return res
|
||||
|
||||
def print_completion( cmd, switch_arr, arg, desc ):
|
||||
|
||||
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 sw[1] == "-":
|
||||
switch_type = "l"
|
||||
offset=2
|
||||
|
||||
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
|
||||
|
||||
MODE_NONE = 0
|
||||
MODE_SWITCH = 1
|
||||
MODE_BETWEEN = 2
|
||||
MODE_BETWEEN_IGNORE = 3
|
||||
MODE_DESC = 4
|
||||
|
||||
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=''
|
||||
|
||||
can_be_switch =True
|
||||
|
||||
for c in man:
|
||||
|
||||
if mode == MODE_NONE:
|
||||
if c == '-' and can_be_switch:
|
||||
mode = MODE_SWITCH
|
||||
sw = '-'
|
||||
|
||||
elif c == '\n':
|
||||
can_be_switch = True
|
||||
elif before_switch.find(c)<0:
|
||||
can_be_switch = False
|
||||
|
||||
|
||||
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=''
|
||||
|
||||
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
|
||||
|
||||
elif mode == MODE_DESC:
|
||||
|
||||
stop = False
|
||||
|
||||
if c == '.':
|
||||
stop = True
|
||||
|
||||
if c == '\n' and pc == '\n':
|
||||
stop=True
|
||||
|
||||
if stop:
|
||||
mode=MODE_NONE
|
||||
|
||||
print_completion( cmd, sw_arr, None, desc )
|
||||
|
||||
sw_arr = []
|
||||
|
||||
desc = ''
|
||||
|
||||
else:
|
||||
desc += c
|
||||
|
||||
else:
|
||||
print "Unknown mode", mode
|
||||
|
||||
pc = c
|
||||
|
||||
237
make_vcs_completions.fish
Executable file
237
make_vcs_completions.fish
Executable file
@@ -0,0 +1,237 @@
|
||||
#!/usr/bin/env fish
|
||||
#
|
||||
# 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
|
||||
set res (echo $argv |cut -c 1|tr a-z A-Z)(echo $argv |cut -c 2-)
|
||||
echo $res
|
||||
end
|
||||
|
||||
#
|
||||
# Escapes the single quote (') character and removes trailing whitespace from $argv
|
||||
#
|
||||
|
||||
function esc
|
||||
echo $argv | sed -e "s/\(['\\\]\)/\\\\\1/g" | sed -e 's/ *$//' | sed -e 's/ .*//'
|
||||
end
|
||||
|
||||
|
||||
#
|
||||
# This function formats a list of completion information into a set of fish completions
|
||||
#
|
||||
# The first argument is the condition string, which will be copied to
|
||||
# the resulting commandline verbatim
|
||||
#
|
||||
# Remaining arguments are tab separated lists of completion
|
||||
# information. Each list contains four elements, the short switch, the
|
||||
# long switch, the argument and the description.
|
||||
#
|
||||
|
||||
function complete_from_list
|
||||
|
||||
set condition $argv[1]
|
||||
set -e argv[1]
|
||||
|
||||
for j in $argv
|
||||
set exploded (echo $j|tr \t \n)
|
||||
set short $exploded[1]
|
||||
set long $exploded[2]
|
||||
set arg $exploded[3]
|
||||
set desc (cap (esc $exploded[4]))
|
||||
|
||||
set str
|
||||
|
||||
switch $short
|
||||
case '-?'
|
||||
set str $str -s (printf "%s\n" $short|cut -c 2)
|
||||
end
|
||||
|
||||
switch $long
|
||||
case '--?*'
|
||||
set str $str -l (printf "%s\n" $long|cut -c 3-)
|
||||
end
|
||||
|
||||
switch $arg
|
||||
case '=DIRECTORY' ' dir'
|
||||
set str $str -x -a "'(__fish_complete_directories (commandline -ct))'"
|
||||
|
||||
case '=COMMAND'
|
||||
set str $str -x -a "'(__fish_complete_command)'"
|
||||
|
||||
case '=USERNAME' ' <user>'
|
||||
set str $str -x -a "'(__fish_complete_users)'"
|
||||
|
||||
case '=FILENAME' '=FILE' ' <file>'
|
||||
set str $str -r
|
||||
|
||||
case ' arg'
|
||||
set str $str -x
|
||||
|
||||
case ' (*):'
|
||||
set str $str -x -a \'(echo $arg| sed -e "s/ (\(.*\)):/\1/" |tr '/' ' ')\'
|
||||
|
||||
case '?*'
|
||||
set str $str -x
|
||||
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
|
||||
case '?*'
|
||||
set str $str --description \'$desc\'
|
||||
end
|
||||
|
||||
echo complete -c $cmd $condition $str
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
function write_completions
|
||||
|
||||
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_vcs_completions.fish
|
||||
# which is shipped with the fish source code.
|
||||
#
|
||||
|
||||
#
|
||||
# Completions from commandline
|
||||
#
|
||||
'
|
||||
set -e argv[1]
|
||||
|
||||
while count $argv >/dev/null
|
||||
echo $argv[1]
|
||||
set -e argv[1]
|
||||
end
|
||||
|
||||
|
||||
eval "function cmd; $cmd \$argv; end"
|
||||
|
||||
set -l cmd_str
|
||||
|
||||
switch $cmd
|
||||
case svn
|
||||
|
||||
function list_subcommand
|
||||
set cmd1 '\([^ ]*\)'
|
||||
set cmd2 '\([^,)]*\)'
|
||||
set 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
|
||||
|
||||
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\(\|\\.\)\$"
|
||||
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 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
|
||||
|
||||
function list_subcommand
|
||||
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 -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'
|
||||
|
||||
cmd -H $argv 2>| sed -n -e 's/'$re'/\1\t\t\2\t\4/p'
|
||||
end
|
||||
|
||||
echo '
|
||||
#
|
||||
# Global switches
|
||||
#
|
||||
'
|
||||
|
||||
complete_from_list "-n '__fish_use_subcommand'" (cmd --help-options 2>| sed -n -e 's/'$re'/\1\t\t\2\t\4/p')
|
||||
|
||||
set cmd_str_internal (cmd --help-commands 2>| sed -n -e 's/^ *\([^ ][^ ]*\)[\t ]*\([^ ].*\)$/\1\t\2/p')
|
||||
for i in $cmd_str_internal
|
||||
set exploded (echo $i|tr \t \n)
|
||||
set cmd_str $cmd_str "-a $exploded[1] --description '"(esc $exploded[2])"'"
|
||||
end
|
||||
|
||||
case '*'
|
||||
|
||||
function list_subcommand
|
||||
cmd help | sed -n -e 's/^ *\([^ ][^ ]*\) .*$/\1/p'
|
||||
end
|
||||
|
||||
function list_subcommand_help
|
||||
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 '
|
||||
#
|
||||
# subcommands
|
||||
#
|
||||
'
|
||||
|
||||
printf "complete -c $cmd -n '__fish_use_subcommand' -x %s\n" $cmd_str
|
||||
|
||||
for i in (list_subcommand)
|
||||
|
||||
echo '
|
||||
|
||||
#
|
||||
# Completions for the \''$i'\' subcommand
|
||||
#
|
||||
'
|
||||
|
||||
complete_from_list "-n 'contains \\'$i\\' (commandline -poc)'" (list_subcommand_help $i)
|
||||
end
|
||||
|
||||
echo \n\n
|
||||
|
||||
end
|
||||
|
||||
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
|
||||
60
mimedb.c
60
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
|
||||
@@ -46,6 +46,7 @@ license. Read the source code of the library for more information.
|
||||
#include "xdgmime.h"
|
||||
#include "fallback.h"
|
||||
#include "util.h"
|
||||
#include "print_help.h"
|
||||
|
||||
|
||||
/**
|
||||
@@ -65,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
|
||||
@@ -138,12 +139,11 @@ static int launch_pos=0;
|
||||
/**
|
||||
gettext alias
|
||||
*/
|
||||
#ifdef USE_GETTEXT
|
||||
#define _(string) gettext(string)
|
||||
|
||||
/**
|
||||
Dynamically generated function, made from the documentation in doc_src.
|
||||
*/
|
||||
void print_help();
|
||||
#else
|
||||
#define _(string) (string)
|
||||
#endif
|
||||
|
||||
/**
|
||||
Call malloc, set error flag and print message on failure
|
||||
@@ -418,7 +418,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 +434,13 @@ static char *get_lang_re()
|
||||
case '.':
|
||||
case '_':
|
||||
if( close )
|
||||
{
|
||||
*out++ = ')';
|
||||
*out++ = '?';
|
||||
}
|
||||
|
||||
close=1;
|
||||
*out++ = '(';
|
||||
*out++ = '|';
|
||||
*out++ = *lang;
|
||||
break;
|
||||
|
||||
@@ -448,8 +450,12 @@ static char *get_lang_re()
|
||||
}
|
||||
|
||||
if( close )
|
||||
{
|
||||
*out++ = ')';
|
||||
*out++ = '?';
|
||||
}
|
||||
*out++=0;
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
||||
@@ -480,18 +486,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 );
|
||||
@@ -742,6 +762,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 +851,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 +863,7 @@ static void write_url( char *file )
|
||||
else
|
||||
{
|
||||
writer( '%' );
|
||||
writer_hex( *str );
|
||||
writer_hex( (unsigned char)*str );
|
||||
}
|
||||
str++;
|
||||
}
|
||||
@@ -1258,7 +1279,7 @@ int main (int argc, char *argv[])
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
print_help();
|
||||
print_help( argv[0], 1 );
|
||||
exit(0);
|
||||
|
||||
case 'v':
|
||||
@@ -1274,7 +1295,7 @@ int main (int argc, char *argv[])
|
||||
if( ( output_type == LAUNCH )&&(input_type==MIMETYPE))
|
||||
{
|
||||
fprintf( stderr, _("%s: Can not launch a mimetype\n"), MIMEDB );
|
||||
print_help();
|
||||
print_help( argv[0], 2 );
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1324,6 +1345,9 @@ int main (int argc, char *argv[])
|
||||
case DESCRIPTION:
|
||||
{
|
||||
output = get_description( mimetype );
|
||||
if( !output )
|
||||
output = strdup( _("Unknown") );
|
||||
|
||||
break;
|
||||
}
|
||||
case ACTION:
|
||||
|
||||
29
output.c
29
output.c
@@ -121,6 +121,9 @@ static char *writestr_buff = 0;
|
||||
|
||||
static int (*out)(char c) = &writeb_internal;
|
||||
|
||||
static wchar_t *current_term = 0;
|
||||
|
||||
|
||||
/**
|
||||
Cleanup function. Run automatically through halloc
|
||||
*/
|
||||
@@ -153,6 +156,16 @@ void set_color( int c, int c2 )
|
||||
int is_bold = 0;
|
||||
int is_underline = 0;
|
||||
|
||||
/*
|
||||
Test if we have at least basic support for setting fonts, colors
|
||||
and related bits - otherwise just give up...
|
||||
*/
|
||||
if( !exit_attribute_mode )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
is_bold |= (c&FISH_COLOR_BOLD)!=0;
|
||||
is_bold |= (c2&FISH_COLOR_BOLD)!=0;
|
||||
|
||||
@@ -356,7 +369,7 @@ int writeb( tputs_arg_t b )
|
||||
return 0;
|
||||
}
|
||||
|
||||
int writembs( char *str )
|
||||
int writembs_internal( char *str )
|
||||
{
|
||||
CHECK( str, 1 );
|
||||
|
||||
@@ -367,7 +380,7 @@ int writech( wint_t ch )
|
||||
{
|
||||
mbstate_t state;
|
||||
int i;
|
||||
char buff[MB_CUR_MAX+1];
|
||||
char buff[MB_LEN_MAX+1];
|
||||
size_t bytes;
|
||||
|
||||
if( ( ch >= ENCODE_DIRECT_BASE) &&
|
||||
@@ -570,3 +583,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>";
|
||||
}
|
||||
|
||||
|
||||
|
||||
25
output.h
25
output.h
@@ -73,13 +73,34 @@ enum
|
||||
|
||||
void set_color( int c, int c2 );
|
||||
|
||||
|
||||
#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().
|
||||
@@ -126,5 +147,7 @@ void output_set_writer( int (*writer)(char) );
|
||||
|
||||
int (*output_get_writer())(char) ;
|
||||
|
||||
void output_set_term( wchar_t *term );
|
||||
wchar_t *output_get_term();
|
||||
|
||||
#endif
|
||||
|
||||
243
parse_util.c
243
parse_util.c
@@ -97,7 +97,6 @@ int parse_util_lineno( const wchar_t *str, int len )
|
||||
static int res2 = 1;
|
||||
|
||||
CHECK( str, 0 );
|
||||
|
||||
|
||||
if( str != prev_str || i>len )
|
||||
{
|
||||
@@ -129,11 +128,104 @@ int parse_util_lineno( const wchar_t *str, int len )
|
||||
for( ; str[i] && i<len; i++ )
|
||||
{
|
||||
if( str[i] == L'\n' )
|
||||
{
|
||||
res++;
|
||||
}
|
||||
}
|
||||
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,
|
||||
@@ -169,13 +261,17 @@ int parse_util_locate_cmdsubst( const wchar_t *in,
|
||||
if( *pos == '(' )
|
||||
{
|
||||
if(( paran_count == 0)&&(paran_begin==0))
|
||||
{
|
||||
paran_begin = pos;
|
||||
}
|
||||
|
||||
paran_count++;
|
||||
}
|
||||
else if( *pos == ')' )
|
||||
{
|
||||
|
||||
paran_count--;
|
||||
|
||||
if( (paran_count == 0) && (paran_end == 0) )
|
||||
{
|
||||
paran_end = pos;
|
||||
@@ -208,9 +304,14 @@ int parse_util_locate_cmdsubst( const wchar_t *in,
|
||||
}
|
||||
|
||||
if( begin )
|
||||
{
|
||||
*begin = paran_begin;
|
||||
}
|
||||
|
||||
if( end )
|
||||
{
|
||||
*end = paran_count?(wchar_t *)in+wcslen(in):paran_end;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -228,9 +329,14 @@ void parse_util_cmdsubst_extent( const wchar_t *buff,
|
||||
CHECK( buff, );
|
||||
|
||||
if( a )
|
||||
{
|
||||
*a = (wchar_t *)buff;
|
||||
}
|
||||
|
||||
if( b )
|
||||
{
|
||||
*b = (wchar_t *)buff+wcslen(buff);
|
||||
}
|
||||
|
||||
pos = (wchar_t *)buff;
|
||||
|
||||
@@ -255,10 +361,17 @@ void parse_util_cmdsubst_extent( const wchar_t *buff,
|
||||
if(( begin < cursor ) && (end >= cursor) )
|
||||
{
|
||||
begin++;
|
||||
|
||||
if( a )
|
||||
{
|
||||
*a = begin;
|
||||
}
|
||||
|
||||
if( b )
|
||||
{
|
||||
*b = end;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -291,14 +404,21 @@ static void job_or_process_extent( const wchar_t *buff,
|
||||
CHECK( buff, );
|
||||
|
||||
if( a )
|
||||
{
|
||||
*a=0;
|
||||
}
|
||||
|
||||
if( b )
|
||||
{
|
||||
*b = 0;
|
||||
}
|
||||
|
||||
parse_util_cmdsubst_extent( buff, cursor_pos, &begin, &end );
|
||||
if( !end || !begin )
|
||||
{
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
pos = cursor_pos - (begin - buff);
|
||||
|
||||
if( a )
|
||||
@@ -327,9 +447,13 @@ static void job_or_process_extent( const wchar_t *buff,
|
||||
switch( tok_last_type( &tok ) )
|
||||
{
|
||||
case TOK_PIPE:
|
||||
{
|
||||
if( !process )
|
||||
{
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
case TOK_END:
|
||||
case TOK_BACKGROUND:
|
||||
{
|
||||
@@ -338,15 +462,19 @@ static void job_or_process_extent( const wchar_t *buff,
|
||||
{
|
||||
finished=1;
|
||||
if( b )
|
||||
{
|
||||
*b = (wchar_t *)buff + tok_begin;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( a )
|
||||
{
|
||||
*a = (wchar_t *)buff + tok_begin+1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -398,7 +526,9 @@ void parse_util_token_extent( const wchar_t *buff,
|
||||
parse_util_cmdsubst_extent( buff, cursor_pos, &begin, &end );
|
||||
|
||||
if( !end || !begin )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pos = cursor_pos - (begin - buff);
|
||||
|
||||
@@ -430,7 +560,9 @@ void parse_util_token_extent( const wchar_t *buff,
|
||||
Calculate end of token
|
||||
*/
|
||||
if( tok_last_type( &tok ) == TOK_STRING )
|
||||
{
|
||||
tok_end +=wcslen(tok_last(&tok));
|
||||
}
|
||||
|
||||
/*
|
||||
Cursor was before beginning of this token, means that the
|
||||
@@ -451,9 +583,6 @@ void parse_util_token_extent( const wchar_t *buff,
|
||||
{
|
||||
a = begin + tok_get_pos( &tok );
|
||||
b = a + wcslen(tok_last(&tok));
|
||||
|
||||
// fwprintf( stderr, L"Whee %ls\n", *a );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -472,14 +601,25 @@ void parse_util_token_extent( const wchar_t *buff,
|
||||
tok_destroy( &tok );
|
||||
|
||||
if( tok_begin )
|
||||
{
|
||||
*tok_begin = a;
|
||||
if( tok_end )
|
||||
*tok_end = b;
|
||||
if( prev_begin )
|
||||
*prev_begin = pa;
|
||||
if( prev_end )
|
||||
*prev_end = pb;
|
||||
}
|
||||
|
||||
if( tok_end )
|
||||
{
|
||||
*tok_end = b;
|
||||
}
|
||||
|
||||
if( prev_begin )
|
||||
{
|
||||
*prev_begin = pa;
|
||||
}
|
||||
|
||||
if( prev_end )
|
||||
{
|
||||
*prev_end = pb;
|
||||
}
|
||||
|
||||
assert( pa >= buff );
|
||||
assert( pa <= (buff+wcslen(buff) ) );
|
||||
assert( pb >= pa );
|
||||
@@ -560,7 +700,9 @@ void parse_util_load_reset( const wchar_t *path_var_name,
|
||||
void *key, *data;
|
||||
hash_remove( all_loaded, path_var_name, &key, &data );
|
||||
if( key )
|
||||
{
|
||||
clear_loaded_entry( key, data, (void *)on_load );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -592,7 +734,7 @@ int parse_util_unload( const wchar_t *cmd,
|
||||
{
|
||||
if( on_load )
|
||||
{
|
||||
on_load( (wchar_t *)val );
|
||||
on_load( cmd );
|
||||
}
|
||||
free( val );
|
||||
}
|
||||
@@ -600,6 +742,16 @@ int parse_util_unload( const wchar_t *cmd,
|
||||
return !!val;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Unload all autoloaded items that have expired, that where loaded in
|
||||
the specified path.
|
||||
|
||||
\param path_var_name The variable containing the path to autoload in
|
||||
\param skip unloading the the specified file
|
||||
\param on_load the callback function to call for every unloaded file
|
||||
|
||||
*/
|
||||
static void parse_util_autounload( const wchar_t *path_var_name,
|
||||
const wchar_t *skip,
|
||||
void (*on_load)(const wchar_t *cmd) )
|
||||
@@ -637,8 +789,10 @@ static void parse_util_autounload( const wchar_t *path_var_name,
|
||||
}
|
||||
|
||||
if( !tm[0] )
|
||||
{
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
if( hash_get( &loaded->is_loading, item ) )
|
||||
{
|
||||
continue;
|
||||
@@ -690,7 +844,6 @@ int parse_util_load( const wchar_t *cmd,
|
||||
// debug( 0, L"Autoload %ls in %ls", cmd, path_var_name );
|
||||
|
||||
parse_util_autounload( path_var_name, cmd, on_load );
|
||||
|
||||
path_var = env_get( path_var_name );
|
||||
|
||||
/*
|
||||
@@ -698,7 +851,6 @@ int parse_util_load( const wchar_t *cmd,
|
||||
*/
|
||||
if( !path_var )
|
||||
{
|
||||
// debug( 0, L"Path null" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -846,9 +998,13 @@ static int parse_util_load_internal( const wchar_t *cmd,
|
||||
}
|
||||
|
||||
if( !path )
|
||||
{
|
||||
path = sb_halloc( global_context );
|
||||
}
|
||||
else
|
||||
{
|
||||
sb_clear( path );
|
||||
}
|
||||
|
||||
/*
|
||||
Iterate over path searching for suitable completion files
|
||||
@@ -858,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) )
|
||||
@@ -873,7 +1029,9 @@ static int parse_util_load_internal( const wchar_t *cmd,
|
||||
{
|
||||
tm = malloc(sizeof(time_t)*2);
|
||||
if( !tm )
|
||||
{
|
||||
DIE_MEM();
|
||||
}
|
||||
}
|
||||
|
||||
tm[0] = buf.st_mtime;
|
||||
@@ -883,9 +1041,10 @@ static int parse_util_load_internal( const wchar_t *cmd,
|
||||
tm );
|
||||
|
||||
if( on_load )
|
||||
{
|
||||
on_load(cmd );
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
Source the completion file for the specified completion
|
||||
*/
|
||||
@@ -921,7 +1080,9 @@ static int parse_util_load_internal( const wchar_t *cmd,
|
||||
{
|
||||
tm = malloc(sizeof(time_t)*2);
|
||||
if( !tm )
|
||||
{
|
||||
DIE_MEM();
|
||||
}
|
||||
|
||||
tm[0] = 0;
|
||||
tm[1] = time(0);
|
||||
@@ -931,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 )
|
||||
{
|
||||
@@ -942,7 +1103,9 @@ void parse_util_set_argv( wchar_t **argv )
|
||||
for( arg=argv; *arg; arg++ )
|
||||
{
|
||||
if( arg != argv )
|
||||
{
|
||||
sb_append( &sb, ARRAY_SEP_STR );
|
||||
}
|
||||
sb_append( &sb, *arg );
|
||||
}
|
||||
|
||||
@@ -953,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 )
|
||||
@@ -965,13 +1145,16 @@ wchar_t *parse_util_unescape_wildcards( const wchar_t *str )
|
||||
unescaped = wcsdup(str);
|
||||
|
||||
if( !unescaped )
|
||||
{
|
||||
DIE_MEM();
|
||||
}
|
||||
|
||||
for( in=out=unescaped; *in; in++ )
|
||||
{
|
||||
switch( *in )
|
||||
{
|
||||
case L'\\':
|
||||
{
|
||||
if( *(in+1) )
|
||||
{
|
||||
in++;
|
||||
@@ -979,20 +1162,26 @@ wchar_t *parse_util_unescape_wildcards( const wchar_t *str )
|
||||
}
|
||||
*(out++)=*in;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
case L'*':
|
||||
{
|
||||
*(out++)=ANY_STRING;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
case L'?':
|
||||
{
|
||||
*(out++)=ANY_CHAR;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
*(out++)=*in;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return unescaped;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
33
parser.h
33
parser.h
@@ -47,7 +47,8 @@ typedef struct block
|
||||
int type; /**< Type of block. Can be one of WHILE, FOR, IF and FUNCTION */
|
||||
int skip; /**< Whether execution of the commands in this block should be skipped */
|
||||
int tok_pos; /**< The start index of the block */
|
||||
|
||||
int had_command; /**< Set to non-zero once a command has been executed in this block */
|
||||
|
||||
/**
|
||||
Status for the current loop block. Can be any of the values from the loop_status enum.
|
||||
*/
|
||||
@@ -119,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 */
|
||||
@@ -126,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 */
|
||||
}
|
||||
;
|
||||
|
||||
@@ -210,7 +213,7 @@ int eval_args( const wchar_t *line,
|
||||
array_list_t *output );
|
||||
|
||||
/**
|
||||
Sets the current error
|
||||
Sets the current evaluation error. This function should only be used by libraries that are called by
|
||||
|
||||
\param ec The new error code
|
||||
\param p The character offset at which the error occured
|
||||
@@ -219,32 +222,6 @@ int eval_args( const wchar_t *line,
|
||||
void error( int ec, int p, const wchar_t *str, ... );
|
||||
|
||||
|
||||
/**
|
||||
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" );
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user