mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Merged changes from codemonkey and grissiom branches
Conflicts: kill.c seq.in
This commit is contained in:
commit
1b0ce33669
221 changed files with 6749 additions and 6514 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -28,4 +28,6 @@ share/config.fish
|
||||||
share/man/
|
share/man/
|
||||||
toc.txt
|
toc.txt
|
||||||
user_doc/
|
user_doc/
|
||||||
xsel-0.9.6/
|
xsel-1.2.0/
|
||||||
|
tests/*tmp.*
|
||||||
|
tests/foo.txt
|
||||||
|
|
936
Doxyfile.help.in
936
Doxyfile.help.in
File diff suppressed because it is too large
Load diff
|
@ -10,8 +10,8 @@ ABBREVIATE_BRIEF = YES
|
||||||
ALWAYS_DETAILED_SEC = NO
|
ALWAYS_DETAILED_SEC = NO
|
||||||
INLINE_INHERITED_MEMB = NO
|
INLINE_INHERITED_MEMB = NO
|
||||||
FULL_PATH_NAMES = YES
|
FULL_PATH_NAMES = YES
|
||||||
STRIP_FROM_PATH =
|
STRIP_FROM_PATH =
|
||||||
STRIP_FROM_INC_PATH =
|
STRIP_FROM_INC_PATH =
|
||||||
SHORT_NAMES = NO
|
SHORT_NAMES = NO
|
||||||
JAVADOC_AUTOBRIEF = YES
|
JAVADOC_AUTOBRIEF = YES
|
||||||
MULTILINE_CPP_IS_BRIEF = NO
|
MULTILINE_CPP_IS_BRIEF = NO
|
||||||
|
@ -19,7 +19,7 @@ DETAILS_AT_TOP = NO
|
||||||
INHERIT_DOCS = YES
|
INHERIT_DOCS = YES
|
||||||
DISTRIBUTE_GROUP_DOC = NO
|
DISTRIBUTE_GROUP_DOC = NO
|
||||||
TAB_SIZE = 8
|
TAB_SIZE = 8
|
||||||
ALIASES =
|
ALIASES =
|
||||||
OPTIMIZE_OUTPUT_FOR_C = YES
|
OPTIMIZE_OUTPUT_FOR_C = YES
|
||||||
OPTIMIZE_OUTPUT_JAVA = NO
|
OPTIMIZE_OUTPUT_JAVA = NO
|
||||||
SUBGROUPING = YES
|
SUBGROUPING = YES
|
||||||
|
@ -44,7 +44,7 @@ GENERATE_TODOLIST = YES
|
||||||
GENERATE_TESTLIST = YES
|
GENERATE_TESTLIST = YES
|
||||||
GENERATE_BUGLIST = YES
|
GENERATE_BUGLIST = YES
|
||||||
GENERATE_DEPRECATEDLIST= YES
|
GENERATE_DEPRECATEDLIST= YES
|
||||||
ENABLED_SECTIONS =
|
ENABLED_SECTIONS =
|
||||||
MAX_INITIALIZER_LINES = 30
|
MAX_INITIALIZER_LINES = 30
|
||||||
SHOW_USED_FILES = YES
|
SHOW_USED_FILES = YES
|
||||||
SHOW_DIRECTORIES = YES
|
SHOW_DIRECTORIES = YES
|
||||||
|
@ -53,19 +53,19 @@ WARNINGS = YES
|
||||||
WARN_IF_UNDOCUMENTED = YES
|
WARN_IF_UNDOCUMENTED = YES
|
||||||
WARN_IF_DOC_ERROR = YES
|
WARN_IF_DOC_ERROR = YES
|
||||||
WARN_FORMAT = "$file:$line: $text"
|
WARN_FORMAT = "$file:$line: $text"
|
||||||
WARN_LOGFILE =
|
WARN_LOGFILE =
|
||||||
INPUT =
|
INPUT =
|
||||||
FILE_PATTERNS = doc.h
|
FILE_PATTERNS = doc.h
|
||||||
RECURSIVE = NO
|
RECURSIVE = NO
|
||||||
EXCLUDE =
|
EXCLUDE =
|
||||||
EXCLUDE_SYMLINKS = NO
|
EXCLUDE_SYMLINKS = NO
|
||||||
EXCLUDE_PATTERNS =
|
EXCLUDE_PATTERNS =
|
||||||
EXAMPLE_PATH =
|
EXAMPLE_PATH =
|
||||||
EXAMPLE_PATTERNS =
|
EXAMPLE_PATTERNS =
|
||||||
EXAMPLE_RECURSIVE = NO
|
EXAMPLE_RECURSIVE = NO
|
||||||
IMAGE_PATH =
|
IMAGE_PATH =
|
||||||
INPUT_FILTER =
|
INPUT_FILTER =
|
||||||
FILTER_PATTERNS =
|
FILTER_PATTERNS =
|
||||||
FILTER_SOURCE_FILES = NO
|
FILTER_SOURCE_FILES = NO
|
||||||
SOURCE_BROWSER = NO
|
SOURCE_BROWSER = NO
|
||||||
INLINE_SOURCES = NO
|
INLINE_SOURCES = NO
|
||||||
|
@ -75,17 +75,17 @@ REFERENCES_RELATION = YES
|
||||||
VERBATIM_HEADERS = YES
|
VERBATIM_HEADERS = YES
|
||||||
ALPHABETICAL_INDEX = NO
|
ALPHABETICAL_INDEX = NO
|
||||||
COLS_IN_ALPHA_INDEX = 5
|
COLS_IN_ALPHA_INDEX = 5
|
||||||
IGNORE_PREFIX =
|
IGNORE_PREFIX =
|
||||||
GENERATE_HTML = YES
|
GENERATE_HTML = YES
|
||||||
HTML_OUTPUT = html
|
HTML_OUTPUT = html
|
||||||
HTML_FILE_EXTENSION = .html
|
HTML_FILE_EXTENSION = .html
|
||||||
HTML_HEADER = user_doc.head.html
|
HTML_HEADER = user_doc.head.html
|
||||||
HTML_FOOTER =
|
HTML_FOOTER =
|
||||||
HTML_STYLESHEET =
|
HTML_STYLESHEET =
|
||||||
HTML_ALIGN_MEMBERS = YES
|
HTML_ALIGN_MEMBERS = YES
|
||||||
GENERATE_HTMLHELP = NO
|
GENERATE_HTMLHELP = NO
|
||||||
CHM_FILE =
|
CHM_FILE =
|
||||||
HHC_LOCATION =
|
HHC_LOCATION =
|
||||||
GENERATE_CHI = NO
|
GENERATE_CHI = NO
|
||||||
BINARY_TOC = NO
|
BINARY_TOC = NO
|
||||||
TOC_EXPAND = NO
|
TOC_EXPAND = NO
|
||||||
|
@ -99,8 +99,8 @@ LATEX_CMD_NAME = latex
|
||||||
MAKEINDEX_CMD_NAME = makeindex
|
MAKEINDEX_CMD_NAME = makeindex
|
||||||
COMPACT_LATEX = NO
|
COMPACT_LATEX = NO
|
||||||
PAPER_TYPE = a4wide
|
PAPER_TYPE = a4wide
|
||||||
EXTRA_PACKAGES =
|
EXTRA_PACKAGES =
|
||||||
LATEX_HEADER =
|
LATEX_HEADER =
|
||||||
PDF_HYPERLINKS = YES
|
PDF_HYPERLINKS = YES
|
||||||
USE_PDFLATEX = YES
|
USE_PDFLATEX = YES
|
||||||
LATEX_BATCHMODE = NO
|
LATEX_BATCHMODE = NO
|
||||||
|
@ -109,33 +109,33 @@ GENERATE_RTF = NO
|
||||||
RTF_OUTPUT = rtf
|
RTF_OUTPUT = rtf
|
||||||
COMPACT_RTF = NO
|
COMPACT_RTF = NO
|
||||||
RTF_HYPERLINKS = NO
|
RTF_HYPERLINKS = NO
|
||||||
RTF_STYLESHEET_FILE =
|
RTF_STYLESHEET_FILE =
|
||||||
RTF_EXTENSIONS_FILE =
|
RTF_EXTENSIONS_FILE =
|
||||||
GENERATE_MAN = NO
|
GENERATE_MAN = NO
|
||||||
MAN_OUTPUT = man
|
MAN_OUTPUT = man
|
||||||
MAN_EXTENSION = .3
|
MAN_EXTENSION = .3
|
||||||
MAN_LINKS = NO
|
MAN_LINKS = NO
|
||||||
GENERATE_XML = NO
|
GENERATE_XML = NO
|
||||||
XML_OUTPUT = xml
|
XML_OUTPUT = xml
|
||||||
XML_SCHEMA =
|
XML_SCHEMA =
|
||||||
XML_DTD =
|
XML_DTD =
|
||||||
XML_PROGRAMLISTING = YES
|
XML_PROGRAMLISTING = YES
|
||||||
GENERATE_AUTOGEN_DEF = NO
|
GENERATE_AUTOGEN_DEF = NO
|
||||||
GENERATE_PERLMOD = NO
|
GENERATE_PERLMOD = NO
|
||||||
PERLMOD_LATEX = NO
|
PERLMOD_LATEX = NO
|
||||||
PERLMOD_PRETTY = YES
|
PERLMOD_PRETTY = YES
|
||||||
PERLMOD_MAKEVAR_PREFIX =
|
PERLMOD_MAKEVAR_PREFIX =
|
||||||
ENABLE_PREPROCESSING = YES
|
ENABLE_PREPROCESSING = YES
|
||||||
MACRO_EXPANSION = NO
|
MACRO_EXPANSION = NO
|
||||||
EXPAND_ONLY_PREDEF = NO
|
EXPAND_ONLY_PREDEF = NO
|
||||||
SEARCH_INCLUDES = YES
|
SEARCH_INCLUDES = YES
|
||||||
INCLUDE_PATH =
|
INCLUDE_PATH =
|
||||||
INCLUDE_FILE_PATTERNS =
|
INCLUDE_FILE_PATTERNS =
|
||||||
PREDEFINED =
|
PREDEFINED =
|
||||||
EXPAND_AS_DEFINED =
|
EXPAND_AS_DEFINED =
|
||||||
SKIP_FUNCTION_MACROS = YES
|
SKIP_FUNCTION_MACROS = YES
|
||||||
TAGFILES =
|
TAGFILES =
|
||||||
GENERATE_TAGFILE =
|
GENERATE_TAGFILE =
|
||||||
ALLEXTERNALS = NO
|
ALLEXTERNALS = NO
|
||||||
EXTERNAL_GROUPS = YES
|
EXTERNAL_GROUPS = YES
|
||||||
PERL_PATH = /usr/bin/perl
|
PERL_PATH = /usr/bin/perl
|
||||||
|
@ -151,8 +151,8 @@ INCLUDED_BY_GRAPH = YES
|
||||||
CALL_GRAPH = YES
|
CALL_GRAPH = YES
|
||||||
GRAPHICAL_HIERARCHY = YES
|
GRAPHICAL_HIERARCHY = YES
|
||||||
DOT_IMAGE_FORMAT = png
|
DOT_IMAGE_FORMAT = png
|
||||||
DOT_PATH =
|
DOT_PATH =
|
||||||
DOTFILE_DIRS =
|
DOTFILE_DIRS =
|
||||||
MAX_DOT_GRAPH_WIDTH = 750
|
MAX_DOT_GRAPH_WIDTH = 750
|
||||||
MAX_DOT_GRAPH_HEIGHT = 1024
|
MAX_DOT_GRAPH_HEIGHT = 1024
|
||||||
MAX_DOT_GRAPH_DEPTH = 0
|
MAX_DOT_GRAPH_DEPTH = 0
|
||||||
|
|
2
INSTALL
2
INSTALL
|
@ -49,7 +49,7 @@ Then, use following commands to compile fish:
|
||||||
Finally, if you wish to use fish as your default shell, use the
|
Finally, if you wish to use fish as your default shell, use the
|
||||||
following command:
|
following command:
|
||||||
|
|
||||||
% chsh -s /usr/local/bin/fish
|
% chsh -s /usr/local/bin/fish
|
||||||
|
|
||||||
chsh will prompt you for your password, and change your default shell.
|
chsh will prompt you for your password, and change your default shell.
|
||||||
|
|
||||||
|
|
102
Makefile.in
102
Makefile.in
|
@ -53,16 +53,16 @@ sysconfdir = @sysconfdir@
|
||||||
docdir = @docdir@
|
docdir = @docdir@
|
||||||
localedir = @localedir@
|
localedir = @localedir@
|
||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
optbindirs = @optbindirs@
|
optbindirs = @optbindirs@
|
||||||
|
|
||||||
#
|
#
|
||||||
# Various flags
|
# Various flags
|
||||||
#
|
#
|
||||||
|
|
||||||
MACROS = -DLOCALEDIR=\"$(localedir)\" -DPREFIX=L\"$(prefix)\" -DDATADIR=L\"$(datadir)\" -DSYSCONFDIR=L\"$(sysconfdir)\"
|
MACROS = -DLOCALEDIR=\"$(localedir)\" -DPREFIX=L\"$(prefix)\" -DDATADIR=L\"$(datadir)\" -DSYSCONFDIR=L\"$(sysconfdir)\"
|
||||||
CFLAGS = @CFLAGS@ $(MACROS)
|
CFLAGS = @CFLAGS@ $(MACROS) $(EXTRA_CFLAGS)
|
||||||
CPPFLAGS = @CPPFLAGS@
|
CPPFLAGS = @CPPFLAGS@
|
||||||
LDFLAGS = @LIBS@ @LDFLAGS@
|
LDFLAGS = @LIBS@ @LDFLAGS@
|
||||||
LDFLAGS_FISH = ${LDFLAGS} @LIBS_FISH@ @LDFLAGS_FISH@
|
LDFLAGS_FISH = ${LDFLAGS} @LIBS_FISH@ @LDFLAGS_FISH@
|
||||||
LDFLAGS_FISH_INDENT = ${LDFLAGS} @LIBS_FISH_INDENT@
|
LDFLAGS_FISH_INDENT = ${LDFLAGS} @LIBS_FISH_INDENT@
|
||||||
LDFLAGS_FISH_PAGER = ${LDFLAGS} @LIBS_FISH_PAGER@
|
LDFLAGS_FISH_PAGER = ${LDFLAGS} @LIBS_FISH_PAGER@
|
||||||
|
@ -158,7 +158,7 @@ HDR_FILES_SRC := doc_src/index.hdr.in doc_src/commands.hdr.in doc_src/design.hdr
|
||||||
HDR_FILES := $(subst .hdr.in,.hdr,$(HDR_FILES_SRC))
|
HDR_FILES := $(subst .hdr.in,.hdr,$(HDR_FILES_SRC))
|
||||||
|
|
||||||
#
|
#
|
||||||
# Files containing documentation for external commands.
|
# Files containing documentation for external commands.
|
||||||
#
|
#
|
||||||
|
|
||||||
HELP_SRC := $(wildcard doc_src/*.txt)
|
HELP_SRC := $(wildcard doc_src/*.txt)
|
||||||
|
@ -208,7 +208,7 @@ MAIN_DIR_FILES := $(sort $(MAIN_DIR_FILES_UNSORTED))
|
||||||
# Files in ./etc/
|
# Files in ./etc/
|
||||||
#
|
#
|
||||||
|
|
||||||
ETC_DIR_FILES :=etc/config.fish.in
|
ETC_DIR_FILES :=etc/config.fish.in
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -245,7 +245,7 @@ FUNCTIONS_DIR_FILES := $(wildcard share/functions/*.fish)
|
||||||
#
|
#
|
||||||
|
|
||||||
SIMPLE_PROGRAMS := fish set_color mimedb fish_pager fishd fish_indent
|
SIMPLE_PROGRAMS := fish set_color mimedb fish_pager fishd fish_indent
|
||||||
PROGRAMS := $(SIMPLE_PROGRAMS) @XSEL@ @SEQ_FALLBACK@
|
PROGRAMS := $(SIMPLE_PROGRAMS) @XSEL_BIN@ @SEQ_FALLBACK@
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -264,12 +264,19 @@ TRANSLATIONS_SRC := $(wildcard po/*.po)
|
||||||
TRANSLATIONS := $(TRANSLATIONS_SRC:.po=.gmo)
|
TRANSLATIONS := $(TRANSLATIONS_SRC:.po=.gmo)
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Extra util
|
||||||
|
#
|
||||||
|
|
||||||
|
XSEL := @XSEL@
|
||||||
|
XSEL_BIN := @XSEL_BIN@
|
||||||
|
|
||||||
#
|
#
|
||||||
# Make everything needed for installing fish
|
# Make everything needed for installing fish
|
||||||
#
|
#
|
||||||
|
|
||||||
all: $(PROGRAMS) user_doc share/man etc/config.fish share/config.fish $(TRANSLATIONS)
|
all: $(PROGRAMS) user_doc share/man etc/config.fish share/config.fish $(TRANSLATIONS)
|
||||||
@echo fish has now been built.
|
@echo fish has now been built.
|
||||||
@echo Use \'$(MAKE) install\' to install fish.
|
@echo Use \'$(MAKE) install\' to install fish.
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
|
|
||||||
|
@ -292,15 +299,18 @@ Makefile: Makefile.in configure
|
||||||
#
|
#
|
||||||
|
|
||||||
debug:
|
debug:
|
||||||
$(MAKE) fish CFLAGS="@CFLAGS@ $(MACROS) -O0 -Wno-unused -Werror -g"
|
$(MAKE) all EXTRA_CFLAGS="-O0 -Wno-unused -Werror -g"
|
||||||
.PHONY: debug
|
.PHONY: debug
|
||||||
|
|
||||||
|
prof:
|
||||||
|
$(MAKE) all EXTRA_CFLAGS="-pg" LDFLAGS="-pg"
|
||||||
|
.PHONY: prof
|
||||||
|
|
||||||
#
|
#
|
||||||
# User documentation, describing the features of the fish shell.
|
# User documentation, describing the features of the fish shell.
|
||||||
#
|
#
|
||||||
|
|
||||||
# Depend on the sources (*.hdr.in) and manually make the
|
# Depend on the sources (*.hdr.in) and manually make the
|
||||||
# intermediate *.hdr and doc.h files if needed
|
# intermediate *.hdr and doc.h files if needed
|
||||||
|
|
||||||
user_doc: $(HDR_FILES_SRC) Doxyfile.user user_doc.head.html $(HELP_SRC)
|
user_doc: $(HDR_FILES_SRC) Doxyfile.user user_doc.head.html $(HELP_SRC)
|
||||||
|
@ -313,19 +323,19 @@ user_doc: $(HDR_FILES_SRC) Doxyfile.user user_doc.head.html $(HELP_SRC)
|
||||||
# Source code documentation. Also includes user documentation.
|
# Source code documentation. Also includes user documentation.
|
||||||
#
|
#
|
||||||
|
|
||||||
doc: *.h *.c doc.h Doxyfile
|
doc: *.h *.c doc.h Doxyfile
|
||||||
doxygen;
|
doxygen;
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# PDF version of the source code documentation.
|
# PDF version of the source code documentation.
|
||||||
#
|
#
|
||||||
|
|
||||||
doc/refman.pdf: doc
|
doc/refman.pdf: doc
|
||||||
cd doc/latex;
|
cd doc/latex;
|
||||||
make;
|
make;
|
||||||
mv refman.pdf ..;
|
mv refman.pdf ..;
|
||||||
cd ../..;
|
cd ../..;
|
||||||
rm -r doc/latex;
|
rm -r doc/latex;
|
||||||
|
|
||||||
|
|
||||||
|
@ -342,11 +352,8 @@ test: $(PROGRAMS) fish_tests
|
||||||
# Build the xsel program, which is maintained in its own tarball
|
# Build the xsel program, which is maintained in its own tarball
|
||||||
#
|
#
|
||||||
|
|
||||||
xsel-0.9.6:
|
$(XSEL_BIN):
|
||||||
tar -xf xsel-0.9.6.tar
|
$(MAKE) -C $(XSEL) || echo "Failed to build xsel - either add the required dependencies or use './configure --without-xsel' to disable it."
|
||||||
|
|
||||||
xsel-0.9.6/xsel: xsel-0.9.6
|
|
||||||
cd xsel-0.9.6; ./configure && make || echo "Failed to build xsel - either add the required dependencies or use './configure --without-xsel' to disable it."
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -362,7 +369,7 @@ doc_src/commands.hdr:$(HELP_SRC) doc_src/commands.hdr.in
|
||||||
echo >>command_list.tmp; \
|
echo >>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; \
|
echo "Back to <a href='index.html#toc-commands'>index</a>". >>command_list.tmp; \
|
||||||
done
|
done
|
||||||
mv command_list.tmp command_list.txt
|
mv command_list.tmp command_list.txt
|
||||||
cat $@.in | awk '{if ($$0 ~ /@command_list@/){ system("cat command_list.txt");} else{ print $$0;}}' >$@
|
cat $@.in | awk '{if ($$0 ~ /@command_list@/){ system("cat command_list.txt");} else{ print $$0;}}' >$@
|
||||||
|
|
||||||
|
@ -400,19 +407,19 @@ doc.h: $(HDR_FILES)
|
||||||
#
|
#
|
||||||
|
|
||||||
%.doxygen:%.txt
|
%.doxygen:%.txt
|
||||||
echo "/** \page " `basename $*` >$@;
|
echo "/** \page " `basename $*` >$@;
|
||||||
cat $*.txt >>$@;
|
cat $*.txt >>$@;
|
||||||
echo "*/" >>$@
|
echo "*/" >>$@
|
||||||
|
|
||||||
%: %.in
|
%: %.in
|
||||||
sed <$@.in >$@ \
|
sed <$@.in >$@ \
|
||||||
-e "s,@sysconfdir\@,$(sysconfdir),g" \
|
-e "s,@sysconfdir\@,$(sysconfdir),g" \
|
||||||
-e "s,@datadir\@,$(datadir),g" \
|
-e "s,@datadir\@,$(datadir),g" \
|
||||||
-e "s,@docdir\@,$(docdir),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|@configure_input\@|$@, generated from $@.in by the Makefile. DO NOT MANUALLY EDIT THIS FILE!|g" \
|
||||||
-e "s,@prefix\@,$(prefix),g" \
|
-e "s,@prefix\@,$(prefix),g" \
|
||||||
-e "s,@optbindirs\@,$(optbindirs),g"
|
-e "s,@optbindirs\@,$(optbindirs),g"
|
||||||
#-e "s,@\@,$(),"
|
#-e "s,@\@,$(),"
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -477,8 +484,8 @@ common.o: $(COMMON_FILES)
|
||||||
# (__fish_print_help)
|
# (__fish_print_help)
|
||||||
# ||
|
# ||
|
||||||
# \/
|
# \/
|
||||||
# formated text
|
# formated text
|
||||||
# with escape
|
# with escape
|
||||||
# sequences
|
# sequences
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
@ -500,7 +507,7 @@ share/man: $(HELP_SRC)
|
||||||
for i in $(HELP_SRC); do \
|
for i in $(HELP_SRC); do \
|
||||||
CMD_NAME=`basename $$i .txt`; \
|
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; \
|
sed -e "s/\(.\)\\.SH/\1/" -e "s/$$CMD_NAME *\\\\- *\"\(.*\)\"/\1/" <help_doc/man/man1/$$CMD_NAME.1 >share/man/$$CMD_NAME.1; \
|
||||||
done
|
done
|
||||||
rm doc_src/*.doxygen # Clean up intermediate files in doc_src/
|
rm doc_src/*.doxygen # Clean up intermediate files in doc_src/
|
||||||
rm -r help_doc # Clean up intermediate help_doc tree
|
rm -r help_doc # Clean up intermediate help_doc tree
|
||||||
|
|
||||||
|
@ -565,7 +572,7 @@ install: all install-sh check-uninstall install-force
|
||||||
#
|
#
|
||||||
|
|
||||||
install-force: all install-translations
|
install-force: all install-translations
|
||||||
$(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
|
$(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
|
||||||
for i in $(PROGRAMS); do\
|
for i in $(PROGRAMS); do\
|
||||||
$(INSTALL) -m 755 $$i $(DESTDIR)$(bindir) ; \
|
$(INSTALL) -m 755 $$i $(DESTDIR)$(bindir) ; \
|
||||||
done;
|
done;
|
||||||
|
@ -595,7 +602,7 @@ install-force: all install-translations
|
||||||
for i in $(MANUALS); do \
|
for i in $(MANUALS); do \
|
||||||
$(INSTALL) -m 644 $$i $(DESTDIR)$(mandir)/man1/; \
|
$(INSTALL) -m 644 $$i $(DESTDIR)$(mandir)/man1/; \
|
||||||
done;
|
done;
|
||||||
@echo fish is now installed on your system.
|
@echo fish is now installed on your system.
|
||||||
@echo To run fish, type \'fish\' in your terminal.
|
@echo To run fish, type \'fish\' in your terminal.
|
||||||
@echo
|
@echo
|
||||||
@echo To use fish as your login shell:
|
@echo To use fish as your login shell:
|
||||||
|
@ -652,7 +659,7 @@ uninstall-legacy: uninstall
|
||||||
-rmdir $(DESTDIR)$(sysconfdir)/fish.d/completions
|
-rmdir $(DESTDIR)$(sysconfdir)/fish.d/completions
|
||||||
-rmdir $(DESTDIR)$(sysconfdir)/fish.d
|
-rmdir $(DESTDIR)$(sysconfdir)/fish.d
|
||||||
-rm $(DESTDIR)$(sysconfdir)/fish
|
-rm $(DESTDIR)$(sysconfdir)/fish
|
||||||
@echo The previous fish installation has been removed.
|
@echo The previous fish installation has been removed.
|
||||||
.PHONY: uninstall-legacy
|
.PHONY: uninstall-legacy
|
||||||
|
|
||||||
install-translations: $(TRANSLATIONS)
|
install-translations: $(TRANSLATIONS)
|
||||||
|
@ -665,7 +672,7 @@ install-translations: $(TRANSLATIONS)
|
||||||
fi;
|
fi;
|
||||||
.PHONY: install-translations
|
.PHONY: install-translations
|
||||||
|
|
||||||
uninstall-translations:
|
uninstall-translations:
|
||||||
if test $(HAVE_GETTEXT) = 1; then \
|
if test $(HAVE_GETTEXT) = 1; then \
|
||||||
for i in $(TRANSLATIONS_SRC); do \
|
for i in $(TRANSLATIONS_SRC); do \
|
||||||
rm -f $(DESTDIR)$(datadir)/locale/*/LC_MESSAGES/fish.mo; \
|
rm -f $(DESTDIR)$(datadir)/locale/*/LC_MESSAGES/fish.mo; \
|
||||||
|
@ -682,7 +689,7 @@ uninstall-translations:
|
||||||
# Build the fish program.
|
# Build the fish program.
|
||||||
#
|
#
|
||||||
|
|
||||||
fish: $(FISH_OBJS) fish.o
|
fish: $(FISH_OBJS) fish.o
|
||||||
$(CC) $(FISH_OBJS) fish.o $(LDFLAGS_FISH) -o $@
|
$(CC) $(FISH_OBJS) fish.o $(LDFLAGS_FISH) -o $@
|
||||||
|
|
||||||
|
|
||||||
|
@ -698,7 +705,7 @@ fish_pager: $(FISH_PAGER_OBJS)
|
||||||
# Build the fishd program.
|
# Build the fishd program.
|
||||||
#
|
#
|
||||||
|
|
||||||
fishd: $(FISHD_OBJS)
|
fishd: $(FISHD_OBJS)
|
||||||
$(CC) $(FISHD_OBJS) $(LDFLAGS_FISHD) -o $@
|
$(CC) $(FISHD_OBJS) $(LDFLAGS_FISHD) -o $@
|
||||||
|
|
||||||
|
|
||||||
|
@ -756,7 +763,7 @@ key_reader: key_reader.o input_common.o common.o env_universal.o env_universal_c
|
||||||
# Update dependencies
|
# Update dependencies
|
||||||
#
|
#
|
||||||
depend:
|
depend:
|
||||||
makedepend -fMakefile.in -Y *.c
|
makedepend -fMakefile.in -Y *.c
|
||||||
./config.status
|
./config.status
|
||||||
.PHONY: depend
|
.PHONY: depend
|
||||||
|
|
||||||
|
@ -765,7 +772,7 @@ depend:
|
||||||
# an archive from it. Simplest way I could think of to make an archive
|
# an archive from it. Simplest way I could think of to make an archive
|
||||||
# witout backups, autogenerated files, etc.
|
# witout backups, autogenerated files, etc.
|
||||||
#
|
#
|
||||||
# Uses install instead of mkdir so build won't fail if the directory
|
# Uses install instead of mkdir so build won't fail if the directory
|
||||||
# exists
|
# exists
|
||||||
#
|
#
|
||||||
|
|
||||||
|
@ -817,7 +824,7 @@ dist: fish-@PACKAGE_VERSION@.tar.bz2
|
||||||
.PHONY: dist
|
.PHONY: dist
|
||||||
|
|
||||||
#
|
#
|
||||||
# Build the RPM spec file.
|
# Build the RPM spec file.
|
||||||
#
|
#
|
||||||
|
|
||||||
fish.spec: fish.spec.in
|
fish.spec: fish.spec.in
|
||||||
|
@ -854,9 +861,10 @@ rpm: fish-@PACKAGE_VERSION@.tar.bz2 fish.spec
|
||||||
#
|
#
|
||||||
|
|
||||||
distclean: clean
|
distclean: clean
|
||||||
rm -f fish.spec Doxyfile.help
|
rm -f fish.spec Doxyfile.help
|
||||||
rm -f etc/config.fish seq share/config.fish
|
rm -f etc/config.fish seq share/config.fish
|
||||||
rm -f config.status config.log config.h Makefile
|
rm -f config.status config.log config.h Makefile
|
||||||
|
rm -rf $(XSEL)
|
||||||
.PHONY: distclean
|
.PHONY: distclean
|
||||||
|
|
||||||
|
|
||||||
|
@ -868,15 +876,15 @@ distclean: clean
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o doc.h doc.tmp doc_src/*.doxygen doc_src/*.c doc_src/*.o doc_src/commands.hdr
|
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 tests/tmp.err tests/tmp.out tests/tmp.status tests/foo.txt
|
||||||
rm -f $(PROGRAMS) fish_tests tokenizer_test key_reader
|
rm -f $(PROGRAMS) fish_tests tokenizer_test key_reader
|
||||||
rm -f share/config.fish etc/config.fish doc_src/index.hdr doc_src/commands.hdr
|
rm -f 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
|
||||||
rm -f fish-@PACKAGE_VERSION@.tar.gz
|
rm -f fish-@PACKAGE_VERSION@.tar.gz
|
||||||
rm -f fish-@PACKAGE_VERSION@.tar.bz2
|
rm -f fish-@PACKAGE_VERSION@.tar.bz2
|
||||||
rm -rf doc;
|
rm -rf doc;
|
||||||
rm -rf fish-@PACKAGE_VERSION@
|
rm -rf fish-@PACKAGE_VERSION@
|
||||||
rm -rf xsel-0.9.6/
|
|
||||||
rm -f $(TRANSLATIONS)
|
rm -f $(TRANSLATIONS)
|
||||||
|
-make -C $(XSEL) clean
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
|
||||||
|
|
||||||
|
|
10
builtin.h
10
builtin.h
|
@ -64,7 +64,7 @@ enum
|
||||||
#define BUILTIN_FOR_ERR_IN _( L"%ls: Second argument must be 'in'\n" )
|
#define BUILTIN_FOR_ERR_IN _( L"%ls: Second argument must be 'in'\n" )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Error message for insufficient number of arguments
|
Error message for insufficient number of arguments
|
||||||
*/
|
*/
|
||||||
#define BUILTIN_FOR_ERR_COUNT _( L"%ls: Expected at least two arguments, got %d\n")
|
#define BUILTIN_FOR_ERR_COUNT _( L"%ls: Expected at least two arguments, got %d\n")
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ extern int builtin_err_redirect;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initialize builtin data.
|
Initialize builtin data.
|
||||||
*/
|
*/
|
||||||
void builtin_init();
|
void builtin_init();
|
||||||
|
|
||||||
|
@ -123,11 +123,11 @@ void builtin_destroy();
|
||||||
int builtin_exists( wchar_t *cmd );
|
int builtin_exists( wchar_t *cmd );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Execute a builtin command
|
Execute a builtin command
|
||||||
|
|
||||||
\param argv Array containing the command and parameters
|
\param argv Array containing the command and parameters
|
||||||
of the builtin. The list is terminated by a
|
of the builtin. The list is terminated by a
|
||||||
null pointer. This syntax resembles the syntax
|
null pointer. This syntax resembles the syntax
|
||||||
for exec.
|
for exec.
|
||||||
\param io the io redirections to perform on this builtin.
|
\param io the io redirections to perform on this builtin.
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/** \file builtin_commandline.c Functions defining the commandline builtin
|
/** \file builtin_commandline.c Functions defining the commandline builtin
|
||||||
|
|
||||||
Functions used for implementing the commandline builtin.
|
Functions used for implementing the commandline builtin.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -96,20 +96,20 @@ static void replace_part( const wchar_t *begin,
|
||||||
const wchar_t *buff = get_buffer();
|
const wchar_t *buff = get_buffer();
|
||||||
string_buffer_t out;
|
string_buffer_t out;
|
||||||
int out_pos=get_cursor_pos();
|
int out_pos=get_cursor_pos();
|
||||||
|
|
||||||
sb_init( &out );
|
sb_init( &out );
|
||||||
|
|
||||||
sb_append_substring( &out, buff, begin-buff );
|
sb_append_substring( &out, buff, begin-buff );
|
||||||
|
|
||||||
switch( append_mode)
|
switch( append_mode)
|
||||||
{
|
{
|
||||||
case REPLACE_MODE:
|
case REPLACE_MODE:
|
||||||
{
|
{
|
||||||
|
|
||||||
sb_append( &out, insert );
|
sb_append( &out, insert );
|
||||||
out_pos = wcslen( insert ) + (begin-buff);
|
out_pos = wcslen( insert ) + (begin-buff);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
case APPEND_MODE:
|
case APPEND_MODE:
|
||||||
{
|
{
|
||||||
|
@ -123,7 +123,7 @@ static void replace_part( const wchar_t *begin,
|
||||||
sb_append_substring( &out, begin, cursor );
|
sb_append_substring( &out, begin, cursor );
|
||||||
sb_append( &out, insert );
|
sb_append( &out, insert );
|
||||||
sb_append_substring( &out, begin+cursor, end-begin-cursor );
|
sb_append_substring( &out, begin+cursor, end-begin-cursor );
|
||||||
out_pos += wcslen( insert );
|
out_pos += wcslen( insert );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ static void replace_part( const wchar_t *begin,
|
||||||
reader_set_buffer( (wchar_t *)out.buff, out_pos );
|
reader_set_buffer( (wchar_t *)out.buff, out_pos );
|
||||||
sb_destroy( &out );
|
sb_destroy( &out );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Output the specified selection.
|
Output the specified selection.
|
||||||
|
|
||||||
|
@ -140,11 +140,11 @@ static void replace_part( const wchar_t *begin,
|
||||||
\param cut_at_cursor whether printing should stop at the surrent cursor position
|
\param cut_at_cursor whether printing should stop at the surrent cursor position
|
||||||
\param tokenize whether the string should be tokenized, printing one string token on every line and skipping non-string tokens
|
\param tokenize whether the string should be tokenized, printing one string token on every line and skipping non-string tokens
|
||||||
*/
|
*/
|
||||||
static void write_part( const wchar_t *begin,
|
static void write_part( const wchar_t *begin,
|
||||||
const wchar_t *end,
|
const wchar_t *end,
|
||||||
int cut_at_cursor,
|
int cut_at_cursor,
|
||||||
int tokenize )
|
int tokenize )
|
||||||
{
|
{
|
||||||
tokenizer tok;
|
tokenizer tok;
|
||||||
string_buffer_t out;
|
string_buffer_t out;
|
||||||
wchar_t *buff;
|
wchar_t *buff;
|
||||||
|
@ -157,7 +157,7 @@ static void write_part( const wchar_t *begin,
|
||||||
buff = wcsndup( begin, end-begin );
|
buff = wcsndup( begin, end-begin );
|
||||||
// fwprintf( stderr, L"Subshell: %ls, end char %lc\n", buff, *end );
|
// fwprintf( stderr, L"Subshell: %ls, end char %lc\n", buff, *end );
|
||||||
sb_init( &out );
|
sb_init( &out );
|
||||||
|
|
||||||
for( tok_init( &tok, buff, TOK_ACCEPT_UNFINISHED );
|
for( tok_init( &tok, buff, TOK_ACCEPT_UNFINISHED );
|
||||||
tok_has_next( &tok );
|
tok_has_next( &tok );
|
||||||
tok_next( &tok ) )
|
tok_next( &tok ) )
|
||||||
|
@ -165,7 +165,7 @@ static void write_part( const wchar_t *begin,
|
||||||
if( (cut_at_cursor) &&
|
if( (cut_at_cursor) &&
|
||||||
(tok_get_pos( &tok)+wcslen(tok_last( &tok)) >= pos) )
|
(tok_get_pos( &tok)+wcslen(tok_last( &tok)) >= pos) )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch( tok_last_type( &tok ) )
|
switch( tok_last_type( &tok ) )
|
||||||
{
|
{
|
||||||
case TOK_STRING:
|
case TOK_STRING:
|
||||||
|
@ -175,13 +175,13 @@ static void write_part( const wchar_t *begin,
|
||||||
free( tmp );
|
free( tmp );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sb_append( sb_out,
|
sb_append( sb_out,
|
||||||
(wchar_t *)out.buff );
|
(wchar_t *)out.buff );
|
||||||
|
|
||||||
free( buff );
|
free( buff );
|
||||||
tok_destroy( &tok );
|
tok_destroy( &tok );
|
||||||
sb_destroy( &out );
|
sb_destroy( &out );
|
||||||
|
@ -189,10 +189,10 @@ static void write_part( const wchar_t *begin,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wchar_t *buff, *esc;
|
wchar_t *buff, *esc;
|
||||||
|
|
||||||
if( cut_at_cursor )
|
if( cut_at_cursor )
|
||||||
{
|
{
|
||||||
end = begin+pos;
|
end = begin+pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
buff = wcsndup( begin, end-begin );
|
buff = wcsndup( begin, end-begin );
|
||||||
|
@ -202,10 +202,10 @@ static void write_part( const wchar_t *begin,
|
||||||
|
|
||||||
sb_append( sb_out, esc );
|
sb_append( sb_out, esc );
|
||||||
sb_append( sb_out, L"\n" );
|
sb_append( sb_out, L"\n" );
|
||||||
|
|
||||||
free( esc );
|
free( esc );
|
||||||
free( buff );
|
free( buff );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,14 +219,14 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
|
|
||||||
int buffer_part=0;
|
int buffer_part=0;
|
||||||
int cut_at_cursor=0;
|
int cut_at_cursor=0;
|
||||||
|
|
||||||
int argc = builtin_count_args( argv );
|
int argc = builtin_count_args( argv );
|
||||||
int append_mode=0;
|
int append_mode=0;
|
||||||
|
|
||||||
int function_mode = 0;
|
int function_mode = 0;
|
||||||
|
|
||||||
int tokenize = 0;
|
int tokenize = 0;
|
||||||
|
|
||||||
int cursor_mode = 0;
|
int cursor_mode = 0;
|
||||||
int line_mode = 0;
|
int line_mode = 0;
|
||||||
int search_mode = 0;
|
int search_mode = 0;
|
||||||
|
@ -254,7 +254,7 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
*/
|
*/
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sb_append( sb_err,
|
sb_append( sb_err,
|
||||||
argv[0],
|
argv[0],
|
||||||
L": Can not set commandline in non-interactive mode\n",
|
L": Can not set commandline in non-interactive mode\n",
|
||||||
|
@ -267,7 +267,7 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
const static struct woption
|
static const struct woption
|
||||||
long_options[] =
|
long_options[] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
@ -293,11 +293,11 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
{
|
{
|
||||||
L"current-token", no_argument, 0, 't'
|
L"current-token", no_argument, 0, 't'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
L"current-buffer", no_argument, 0, 'b'
|
L"current-buffer", no_argument, 0, 'b'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
L"cut-at-cursor", no_argument, 0, 'c'
|
L"cut-at-cursor", no_argument, 0, 'c'
|
||||||
}
|
}
|
||||||
|
@ -314,7 +314,7 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
L"help", no_argument, 0, 'h'
|
L"help", no_argument, 0, 'h'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
L"input", required_argument, 0, 'I'
|
L"input", required_argument, 0, 'I'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
|
@ -331,21 +331,21 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
0, 0, 0, 0
|
0, 0, 0, 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
int opt_index = 0;
|
int opt_index = 0;
|
||||||
|
|
||||||
int opt = wgetopt_long( argc,
|
int opt = wgetopt_long( argc,
|
||||||
argv,
|
argv,
|
||||||
L"abijpctwforhI:CLS",
|
L"abijpctwforhI:CLS",
|
||||||
long_options,
|
long_options,
|
||||||
&opt_index );
|
&opt_index );
|
||||||
if( opt == -1 )
|
if( opt == -1 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch( opt )
|
switch( opt )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -358,7 +358,7 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case L'a':
|
case L'a':
|
||||||
append_mode = APPEND_MODE;
|
append_mode = APPEND_MODE;
|
||||||
break;
|
break;
|
||||||
|
@ -366,8 +366,8 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
case L'b':
|
case L'b':
|
||||||
buffer_part = STRING_MODE;
|
buffer_part = STRING_MODE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case L'i':
|
case L'i':
|
||||||
append_mode = INSERT_MODE;
|
append_mode = INSERT_MODE;
|
||||||
break;
|
break;
|
||||||
|
@ -375,11 +375,11 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
case L'r':
|
case L'r':
|
||||||
append_mode = REPLACE_MODE;
|
append_mode = REPLACE_MODE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
cut_at_cursor=1;
|
cut_at_cursor=1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
buffer_part = TOKEN_MODE;
|
buffer_part = TOKEN_MODE;
|
||||||
break;
|
break;
|
||||||
|
@ -404,33 +404,33 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
current_buffer = woptarg;
|
current_buffer = woptarg;
|
||||||
current_cursor_pos = wcslen( woptarg );
|
current_cursor_pos = wcslen( woptarg );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'C':
|
case 'C':
|
||||||
cursor_mode = 1;
|
cursor_mode = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'L':
|
case 'L':
|
||||||
line_mode = 1;
|
line_mode = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'S':
|
case 'S':
|
||||||
search_mode = 1;
|
search_mode = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
builtin_print_help( argv[0], sb_out );
|
builtin_print_help( argv[0], sb_out );
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case L'?':
|
case L'?':
|
||||||
builtin_unknown_option( argv[0], argv[woptind-1] );
|
builtin_unknown_option( argv[0], argv[woptind-1] );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( function_mode )
|
if( function_mode )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Check for invalid switch combinations
|
Check for invalid switch combinations
|
||||||
*/
|
*/
|
||||||
|
@ -439,18 +439,18 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
sb_printf(sb_err,
|
sb_printf(sb_err,
|
||||||
BUILTIN_ERR_COMBO,
|
BUILTIN_ERR_COMBO,
|
||||||
argv[0] );
|
argv[0] );
|
||||||
|
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( argc == woptind )
|
if( argc == woptind )
|
||||||
{
|
{
|
||||||
sb_printf( sb_err,
|
sb_printf( sb_err,
|
||||||
BUILTIN_ERR_MISSING,
|
BUILTIN_ERR_MISSING,
|
||||||
argv[0] );
|
argv[0] );
|
||||||
|
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -476,16 +476,16 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Check for invalid switch combinations
|
Check for invalid switch combinations
|
||||||
*/
|
*/
|
||||||
if( (search_mode || line_mode || cursor_mode) && (argc-woptind > 1) )
|
if( (search_mode || line_mode || cursor_mode) && (argc-woptind > 1) )
|
||||||
{
|
{
|
||||||
|
|
||||||
sb_append( sb_err,
|
sb_append( sb_err,
|
||||||
argv[0],
|
argv[0],
|
||||||
L": Too many arguments\n",
|
L": Too many arguments\n",
|
||||||
|
@ -495,15 +495,15 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (buffer_part || tokenize || cut_at_cursor) && (cursor_mode || line_mode || search_mode) )
|
if( (buffer_part || tokenize || cut_at_cursor) && (cursor_mode || line_mode || search_mode) )
|
||||||
{
|
{
|
||||||
sb_printf( sb_err,
|
sb_printf( sb_err,
|
||||||
BUILTIN_ERR_COMBO,
|
BUILTIN_ERR_COMBO,
|
||||||
argv[0] );
|
argv[0] );
|
||||||
|
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( (tokenize || cut_at_cursor) && (argc-woptind) )
|
if( (tokenize || cut_at_cursor) && (argc-woptind) )
|
||||||
{
|
{
|
||||||
|
@ -511,7 +511,7 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
BUILTIN_ERR_COMBO2,
|
BUILTIN_ERR_COMBO2,
|
||||||
argv[0],
|
argv[0],
|
||||||
L"--cut-at-cursor and --tokenize can not be used when setting the commandline" );
|
L"--cut-at-cursor and --tokenize can not be used when setting the commandline" );
|
||||||
|
|
||||||
|
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -524,7 +524,7 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
argv[0],
|
argv[0],
|
||||||
L"insertion mode switches can not be used when not in insertion mode" );
|
L"insertion mode switches can not be used when not in insertion mode" );
|
||||||
|
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -535,7 +535,7 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
{
|
{
|
||||||
append_mode = REPLACE_MODE;
|
append_mode = REPLACE_MODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !buffer_part )
|
if( !buffer_part )
|
||||||
{
|
{
|
||||||
buffer_part = STRING_MODE;
|
buffer_part = STRING_MODE;
|
||||||
|
@ -548,7 +548,7 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
wchar_t *endptr;
|
wchar_t *endptr;
|
||||||
int new_pos;
|
int new_pos;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
new_pos = wcstol( argv[woptind], &endptr, 10 );
|
new_pos = wcstol( argv[woptind], &endptr, 10 );
|
||||||
if( *endptr || errno )
|
if( *endptr || errno )
|
||||||
{
|
{
|
||||||
|
@ -558,7 +558,7 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
argv[woptind] );
|
argv[woptind] );
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
}
|
}
|
||||||
|
|
||||||
current_buffer = reader_get_buffer();
|
current_buffer = reader_get_buffer();
|
||||||
new_pos = maxi( 0, mini( new_pos, wcslen( current_buffer ) ) );
|
new_pos = maxi( 0, mini( new_pos, wcslen( current_buffer ) ) );
|
||||||
reader_set_buffer( current_buffer, new_pos );
|
reader_set_buffer( current_buffer, new_pos );
|
||||||
|
@ -569,98 +569,98 @@ static int builtin_commandline( wchar_t **argv )
|
||||||
sb_printf( sb_out, L"%d\n", reader_get_cursor_pos() );
|
sb_printf( sb_out, L"%d\n", reader_get_cursor_pos() );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( line_mode )
|
if( line_mode )
|
||||||
{
|
{
|
||||||
int pos = reader_get_cursor_pos();
|
int pos = reader_get_cursor_pos();
|
||||||
wchar_t *buff = reader_get_buffer();
|
wchar_t *buff = reader_get_buffer();
|
||||||
sb_printf( sb_out, L"%d\n", parse_util_lineno( buff, pos ) );
|
sb_printf( sb_out, L"%d\n", parse_util_lineno( buff, pos ) );
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( search_mode )
|
if( search_mode )
|
||||||
{
|
{
|
||||||
return !reader_search_mode();
|
return !reader_search_mode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch( buffer_part )
|
switch( buffer_part )
|
||||||
{
|
{
|
||||||
case STRING_MODE:
|
case STRING_MODE:
|
||||||
{
|
{
|
||||||
begin = get_buffer();
|
begin = get_buffer();
|
||||||
end = begin+wcslen(begin);
|
end = begin+wcslen(begin);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case PROCESS_MODE:
|
case PROCESS_MODE:
|
||||||
{
|
{
|
||||||
parse_util_process_extent( get_buffer(),
|
parse_util_process_extent( get_buffer(),
|
||||||
get_cursor_pos(),
|
get_cursor_pos(),
|
||||||
&begin,
|
&begin,
|
||||||
&end );
|
&end );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case JOB_MODE:
|
case JOB_MODE:
|
||||||
{
|
{
|
||||||
parse_util_job_extent( get_buffer(),
|
parse_util_job_extent( get_buffer(),
|
||||||
get_cursor_pos(),
|
get_cursor_pos(),
|
||||||
&begin,
|
&begin,
|
||||||
&end );
|
&end );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TOKEN_MODE:
|
case TOKEN_MODE:
|
||||||
{
|
{
|
||||||
parse_util_token_extent( get_buffer(),
|
parse_util_token_extent( get_buffer(),
|
||||||
get_cursor_pos(),
|
get_cursor_pos(),
|
||||||
&begin,
|
&begin,
|
||||||
&end,
|
&end,
|
||||||
0, 0 );
|
0, 0 );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(argc-woptind)
|
switch(argc-woptind)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
write_part( begin, end, cut_at_cursor, tokenize );
|
write_part( begin, end, cut_at_cursor, tokenize );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
replace_part( begin, end, argv[woptind], append_mode );
|
replace_part( begin, end, argv[woptind], append_mode );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
string_buffer_t sb;
|
string_buffer_t sb;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
sb_init( &sb );
|
sb_init( &sb );
|
||||||
|
|
||||||
sb_append( &sb, argv[woptind] );
|
sb_append( &sb, argv[woptind] );
|
||||||
|
|
||||||
for( i=woptind+1; i<argc; i++ )
|
for( i=woptind+1; i<argc; i++ )
|
||||||
{
|
{
|
||||||
sb_append( &sb, L"\n" );
|
sb_append( &sb, L"\n" );
|
||||||
sb_append( &sb, argv[i] );
|
sb_append( &sb, argv[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
replace_part( begin, end, (wchar_t *)sb.buff, append_mode );
|
replace_part( begin, end, (wchar_t *)sb.buff, append_mode );
|
||||||
sb_destroy( &sb );
|
sb_destroy( &sb );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/** \file builtin_complete.c Functions defining the complete builtin
|
/** \file builtin_complete.c Functions defining the complete builtin
|
||||||
|
|
||||||
Functions used for implementing the complete builtin.
|
Functions used for implementing the complete builtin.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -28,7 +28,7 @@ Functions used for implementing the complete builtin.
|
||||||
/**
|
/**
|
||||||
Internal storage for the builtin_get_temporary_buffer() function.
|
Internal storage for the builtin_get_temporary_buffer() function.
|
||||||
*/
|
*/
|
||||||
const static wchar_t *temporary_buffer;
|
static const wchar_t *temporary_buffer;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
builtin_complete_* are a set of rather silly looping functions that
|
builtin_complete_* are a set of rather silly looping functions that
|
||||||
|
@ -46,8 +46,8 @@ static void builtin_complete_add2( const wchar_t *cmd,
|
||||||
int cmd_type,
|
int cmd_type,
|
||||||
const wchar_t *short_opt,
|
const wchar_t *short_opt,
|
||||||
array_list_t *gnu_opt,
|
array_list_t *gnu_opt,
|
||||||
array_list_t *old_opt,
|
array_list_t *old_opt,
|
||||||
int result_mode,
|
int result_mode,
|
||||||
const wchar_t *condition,
|
const wchar_t *condition,
|
||||||
const wchar_t *comp,
|
const wchar_t *comp,
|
||||||
const wchar_t *desc,
|
const wchar_t *desc,
|
||||||
|
@ -55,10 +55,10 @@ static void builtin_complete_add2( const wchar_t *cmd,
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
const wchar_t *s;
|
const wchar_t *s;
|
||||||
|
|
||||||
for( s=short_opt; *s; s++ )
|
for( s=short_opt; *s; s++ )
|
||||||
{
|
{
|
||||||
complete_add( cmd,
|
complete_add( cmd,
|
||||||
cmd_type,
|
cmd_type,
|
||||||
*s,
|
*s,
|
||||||
0,
|
0,
|
||||||
|
@ -69,10 +69,10 @@ static void builtin_complete_add2( const wchar_t *cmd,
|
||||||
desc,
|
desc,
|
||||||
flags );
|
flags );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i=0; i<al_get_count( gnu_opt ); i++ )
|
for( i=0; i<al_get_count( gnu_opt ); i++ )
|
||||||
{
|
{
|
||||||
complete_add( cmd,
|
complete_add( cmd,
|
||||||
cmd_type,
|
cmd_type,
|
||||||
0,
|
0,
|
||||||
(wchar_t *)al_get(gnu_opt, i ),
|
(wchar_t *)al_get(gnu_opt, i ),
|
||||||
|
@ -83,10 +83,10 @@ static void builtin_complete_add2( const wchar_t *cmd,
|
||||||
desc,
|
desc,
|
||||||
flags );
|
flags );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i=0; i<al_get_count( old_opt ); i++ )
|
for( i=0; i<al_get_count( old_opt ); i++ )
|
||||||
{
|
{
|
||||||
complete_add( cmd,
|
complete_add( cmd,
|
||||||
cmd_type,
|
cmd_type,
|
||||||
0,
|
0,
|
||||||
(wchar_t *)al_get(old_opt, i ),
|
(wchar_t *)al_get(old_opt, i ),
|
||||||
|
@ -96,11 +96,11 @@ static void builtin_complete_add2( const wchar_t *cmd,
|
||||||
comp,
|
comp,
|
||||||
desc,
|
desc,
|
||||||
flags );
|
flags );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( al_get_count( old_opt )+al_get_count( gnu_opt )+wcslen(short_opt) == 0 )
|
if( al_get_count( old_opt )+al_get_count( gnu_opt )+wcslen(short_opt) == 0 )
|
||||||
{
|
{
|
||||||
complete_add( cmd,
|
complete_add( cmd,
|
||||||
cmd_type,
|
cmd_type,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
@ -110,18 +110,18 @@ static void builtin_complete_add2( const wchar_t *cmd,
|
||||||
comp,
|
comp,
|
||||||
desc,
|
desc,
|
||||||
flags );
|
flags );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Silly function
|
Silly function
|
||||||
*/
|
*/
|
||||||
static void builtin_complete_add( array_list_t *cmd,
|
static void builtin_complete_add( array_list_t *cmd,
|
||||||
array_list_t *path,
|
array_list_t *path,
|
||||||
const wchar_t *short_opt,
|
const wchar_t *short_opt,
|
||||||
array_list_t *gnu_opt,
|
array_list_t *gnu_opt,
|
||||||
array_list_t *old_opt,
|
array_list_t *old_opt,
|
||||||
int result_mode,
|
int result_mode,
|
||||||
int authoritative,
|
int authoritative,
|
||||||
const wchar_t *condition,
|
const wchar_t *condition,
|
||||||
const wchar_t *comp,
|
const wchar_t *comp,
|
||||||
|
@ -129,17 +129,17 @@ static void builtin_complete_add( array_list_t *cmd,
|
||||||
int flags )
|
int flags )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for( i=0; i<al_get_count( cmd ); i++ )
|
for( i=0; i<al_get_count( cmd ); i++ )
|
||||||
{
|
{
|
||||||
builtin_complete_add2( al_get( cmd, i ),
|
builtin_complete_add2( al_get( cmd, i ),
|
||||||
COMMAND,
|
COMMAND,
|
||||||
short_opt,
|
short_opt,
|
||||||
gnu_opt,
|
gnu_opt,
|
||||||
old_opt,
|
old_opt,
|
||||||
result_mode,
|
result_mode,
|
||||||
condition,
|
condition,
|
||||||
comp,
|
comp,
|
||||||
desc,
|
desc,
|
||||||
flags );
|
flags );
|
||||||
|
|
||||||
|
@ -149,19 +149,19 @@ static void builtin_complete_add( array_list_t *cmd,
|
||||||
COMMAND,
|
COMMAND,
|
||||||
authoritative );
|
authoritative );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i=0; i<al_get_count( path ); i++ )
|
for( i=0; i<al_get_count( path ); i++ )
|
||||||
{
|
{
|
||||||
builtin_complete_add2( al_get( path, i ),
|
builtin_complete_add2( al_get( path, i ),
|
||||||
PATH,
|
PATH,
|
||||||
short_opt,
|
short_opt,
|
||||||
gnu_opt,
|
gnu_opt,
|
||||||
old_opt,
|
old_opt,
|
||||||
result_mode,
|
result_mode,
|
||||||
condition,
|
condition,
|
||||||
comp,
|
comp,
|
||||||
desc,
|
desc,
|
||||||
flags );
|
flags );
|
||||||
|
|
||||||
|
@ -171,8 +171,8 @@ static void builtin_complete_add( array_list_t *cmd,
|
||||||
PATH,
|
PATH,
|
||||||
authoritative );
|
authoritative );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -181,17 +181,17 @@ static void builtin_complete_add( array_list_t *cmd,
|
||||||
static void builtin_complete_remove3( wchar_t *cmd,
|
static void builtin_complete_remove3( wchar_t *cmd,
|
||||||
int cmd_type,
|
int cmd_type,
|
||||||
wchar_t short_opt,
|
wchar_t short_opt,
|
||||||
array_list_t *long_opt )
|
array_list_t *long_opt )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for( i=0; i<al_get_count( long_opt ); i++ )
|
for( i=0; i<al_get_count( long_opt ); i++ )
|
||||||
{
|
{
|
||||||
complete_remove( cmd,
|
complete_remove( cmd,
|
||||||
cmd_type,
|
cmd_type,
|
||||||
short_opt,
|
short_opt,
|
||||||
(wchar_t *)al_get( long_opt, i ) );
|
(wchar_t *)al_get( long_opt, i ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -214,7 +214,7 @@ static void builtin_complete_remove2( wchar_t *cmd,
|
||||||
cmd_type,
|
cmd_type,
|
||||||
*s,
|
*s,
|
||||||
0 );
|
0 );
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -239,42 +239,42 @@ static void builtin_complete_remove2( wchar_t *cmd,
|
||||||
cmd_type,
|
cmd_type,
|
||||||
0,
|
0,
|
||||||
old_opt );
|
old_opt );
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Silly function
|
Silly function
|
||||||
*/
|
*/
|
||||||
static void builtin_complete_remove( array_list_t *cmd,
|
static void builtin_complete_remove( array_list_t *cmd,
|
||||||
array_list_t *path,
|
array_list_t *path,
|
||||||
const wchar_t *short_opt,
|
const wchar_t *short_opt,
|
||||||
array_list_t *gnu_opt,
|
array_list_t *gnu_opt,
|
||||||
array_list_t *old_opt )
|
array_list_t *old_opt )
|
||||||
{
|
{
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for( i=0; i<al_get_count( cmd ); i++ )
|
for( i=0; i<al_get_count( cmd ); i++ )
|
||||||
{
|
{
|
||||||
builtin_complete_remove2( (wchar_t *)al_get( cmd, i ),
|
builtin_complete_remove2( (wchar_t *)al_get( cmd, i ),
|
||||||
COMMAND,
|
COMMAND,
|
||||||
short_opt,
|
short_opt,
|
||||||
gnu_opt,
|
gnu_opt,
|
||||||
old_opt );
|
old_opt );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i=0; i<al_get_count( path ); i++ )
|
for( i=0; i<al_get_count( path ); i++ )
|
||||||
{
|
{
|
||||||
builtin_complete_remove2( (wchar_t *)al_get( path, i ),
|
builtin_complete_remove2( (wchar_t *)al_get( path, i ),
|
||||||
PATH,
|
PATH,
|
||||||
short_opt,
|
short_opt,
|
||||||
gnu_opt,
|
gnu_opt,
|
||||||
old_opt );
|
old_opt );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -296,55 +296,55 @@ static int builtin_complete( wchar_t **argv )
|
||||||
int remove = 0;
|
int remove = 0;
|
||||||
int authoritative = -1;
|
int authoritative = -1;
|
||||||
int flags = COMPLETE_AUTO_SPACE;
|
int flags = COMPLETE_AUTO_SPACE;
|
||||||
|
|
||||||
string_buffer_t short_opt;
|
string_buffer_t short_opt;
|
||||||
array_list_t gnu_opt, old_opt;
|
array_list_t gnu_opt, old_opt;
|
||||||
wchar_t *comp=L"", *desc=L"", *condition=L"";
|
wchar_t *comp=L"", *desc=L"", *condition=L"";
|
||||||
|
|
||||||
wchar_t *do_complete = 0;
|
wchar_t *do_complete = 0;
|
||||||
|
|
||||||
array_list_t cmd;
|
array_list_t cmd;
|
||||||
array_list_t path;
|
array_list_t path;
|
||||||
|
|
||||||
static int recursion_level=0;
|
static int recursion_level=0;
|
||||||
|
|
||||||
al_init( &cmd );
|
al_init( &cmd );
|
||||||
al_init( &path );
|
al_init( &path );
|
||||||
sb_init( &short_opt );
|
sb_init( &short_opt );
|
||||||
al_init( &gnu_opt );
|
al_init( &gnu_opt );
|
||||||
al_init( &old_opt );
|
al_init( &old_opt );
|
||||||
|
|
||||||
argc = builtin_count_args( argv );
|
argc = builtin_count_args( argv );
|
||||||
|
|
||||||
woptind=0;
|
woptind=0;
|
||||||
|
|
||||||
while( res == 0 )
|
while( res == 0 )
|
||||||
{
|
{
|
||||||
const static struct woption
|
static const struct woption
|
||||||
long_options[] =
|
long_options[] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
L"exclusive", no_argument, 0, 'x'
|
L"exclusive", no_argument, 0, 'x'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
L"no-files", no_argument, 0, 'f'
|
L"no-files", no_argument, 0, 'f'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
L"require-parameter", no_argument, 0, 'r'
|
L"require-parameter", no_argument, 0, 'r'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
L"path", required_argument, 0, 'p'
|
L"path", required_argument, 0, 'p'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
L"command", required_argument, 0, 'c'
|
L"command", required_argument, 0, 'c'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
L"short-option", required_argument, 0, 's'
|
L"short-option", required_argument, 0, 's'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
|
@ -352,7 +352,7 @@ static int builtin_complete( wchar_t **argv )
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
L"old-option", required_argument, 0, 'o'
|
L"old-option", required_argument, 0, 'o'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
|
@ -387,22 +387,22 @@ static int builtin_complete( wchar_t **argv )
|
||||||
L"help", no_argument, 0, 'h'
|
L"help", no_argument, 0, 'h'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
0, 0, 0, 0
|
0, 0, 0, 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
int opt_index = 0;
|
int opt_index = 0;
|
||||||
|
|
||||||
int opt = wgetopt_long( argc,
|
int opt = wgetopt_long( argc,
|
||||||
argv,
|
argv,
|
||||||
L"a:c:p:s:l:o:d:frxeuAn:C::h",
|
L"a:c:p:s:l:o:d:frxeuAn:C::h",
|
||||||
long_options,
|
long_options,
|
||||||
&opt_index );
|
&opt_index );
|
||||||
if( opt == -1 )
|
if( opt == -1 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch( opt )
|
switch( opt )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -414,23 +414,23 @@ static int builtin_complete( wchar_t **argv )
|
||||||
long_options[opt_index].name );
|
long_options[opt_index].name );
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
|
|
||||||
|
|
||||||
res = 1;
|
res = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'x':
|
case 'x':
|
||||||
result_mode |= EXCLUSIVE;
|
result_mode |= EXCLUSIVE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
result_mode |= NO_FILES;
|
result_mode |= NO_FILES;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
result_mode |= NO_COMMON;
|
result_mode |= NO_COMMON;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
case 'c':
|
case 'c':
|
||||||
{
|
{
|
||||||
wchar_t *a = unescape( woptarg, 1);
|
wchar_t *a = unescape( woptarg, 1);
|
||||||
|
@ -441,31 +441,31 @@ static int builtin_complete( wchar_t **argv )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sb_printf( sb_err, L"%ls: Invalid token '%ls'\n", argv[0], woptarg );
|
sb_printf( sb_err, L"%ls: Invalid token '%ls'\n", argv[0], woptarg );
|
||||||
res = 1;
|
res = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
desc = woptarg;
|
desc = woptarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'u':
|
case 'u':
|
||||||
authoritative=0;
|
authoritative=0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'A':
|
case 'A':
|
||||||
authoritative=1;
|
authoritative=1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
sb_append( &short_opt, woptarg );
|
sb_append( &short_opt, woptarg );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'l':
|
case 'l':
|
||||||
al_push( &gnu_opt, woptarg );
|
al_push( &gnu_opt, woptarg );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
al_push( &old_opt, woptarg );
|
al_push( &old_opt, woptarg );
|
||||||
break;
|
break;
|
||||||
|
@ -473,7 +473,7 @@ static int builtin_complete( wchar_t **argv )
|
||||||
case 'a':
|
case 'a':
|
||||||
comp = woptarg;
|
comp = woptarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'e':
|
case 'e':
|
||||||
remove = 1;
|
remove = 1;
|
||||||
break;
|
break;
|
||||||
|
@ -481,22 +481,22 @@ static int builtin_complete( wchar_t **argv )
|
||||||
case 'n':
|
case 'n':
|
||||||
condition = woptarg;
|
condition = woptarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'C':
|
case 'C':
|
||||||
do_complete = woptarg?woptarg:reader_get_buffer();
|
do_complete = woptarg?woptarg:reader_get_buffer();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
builtin_print_help( argv[0], sb_out );
|
builtin_print_help( argv[0], sb_out );
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
builtin_unknown_option( argv[0], argv[woptind-1] );
|
builtin_unknown_option( argv[0], argv[woptind-1] );
|
||||||
res = 1;
|
res = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !res )
|
if( !res )
|
||||||
|
@ -506,17 +506,17 @@ static int builtin_complete( wchar_t **argv )
|
||||||
if( parser_test( condition, 0, 0, 0 ) )
|
if( parser_test( condition, 0, 0, 0 ) )
|
||||||
{
|
{
|
||||||
sb_printf( sb_err,
|
sb_printf( sb_err,
|
||||||
L"%ls: Condition '%ls' contained a syntax error\n",
|
L"%ls: Condition '%ls' contained a syntax error\n",
|
||||||
argv[0],
|
argv[0],
|
||||||
condition );
|
condition );
|
||||||
|
|
||||||
parser_test( condition, 0, sb_err, argv[0] );
|
parser_test( condition, 0, sb_err, argv[0] );
|
||||||
|
|
||||||
res = 1;
|
res = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !res )
|
if( !res )
|
||||||
{
|
{
|
||||||
if( comp && wcslen( comp ) )
|
if( comp && wcslen( comp ) )
|
||||||
|
@ -524,12 +524,12 @@ static int builtin_complete( wchar_t **argv )
|
||||||
if( parser_test_args( comp, 0, 0 ) )
|
if( parser_test_args( comp, 0, 0 ) )
|
||||||
{
|
{
|
||||||
sb_printf( sb_err,
|
sb_printf( sb_err,
|
||||||
L"%ls: Completion '%ls' contained a syntax error\n",
|
L"%ls: Completion '%ls' contained a syntax error\n",
|
||||||
argv[0],
|
argv[0],
|
||||||
comp );
|
comp );
|
||||||
|
|
||||||
parser_test_args( comp, sb_err, argv[0] );
|
parser_test_args( comp, sb_err, argv[0] );
|
||||||
|
|
||||||
res = 1;
|
res = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -547,22 +547,22 @@ static int builtin_complete( wchar_t **argv )
|
||||||
wchar_t *token;
|
wchar_t *token;
|
||||||
|
|
||||||
parse_util_token_extent( do_complete, wcslen( do_complete ), &token, 0, 0, 0 );
|
parse_util_token_extent( do_complete, wcslen( do_complete ), &token, 0, 0, 0 );
|
||||||
|
|
||||||
temporary_buffer = do_complete;
|
temporary_buffer = do_complete;
|
||||||
|
|
||||||
if( recursion_level < 1 )
|
if( recursion_level < 1 )
|
||||||
{
|
{
|
||||||
recursion_level++;
|
recursion_level++;
|
||||||
|
|
||||||
comp = al_halloc( 0 );
|
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++ )
|
||||||
{
|
{
|
||||||
completion_t *next = (completion_t *)al_get( comp, i );
|
completion_t *next = (completion_t *)al_get( comp, i );
|
||||||
wchar_t *prepend;
|
wchar_t *prepend;
|
||||||
|
|
||||||
if( next->flags & COMPLETE_NO_CASE )
|
if( next->flags & COMPLETE_NO_CASE )
|
||||||
{
|
{
|
||||||
prepend = L"";
|
prepend = L"";
|
||||||
|
@ -571,7 +571,7 @@ static int builtin_complete( wchar_t **argv )
|
||||||
{
|
{
|
||||||
prepend = token;
|
prepend = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( next->description )
|
if( next->description )
|
||||||
{
|
{
|
||||||
|
@ -582,17 +582,17 @@ static int builtin_complete( wchar_t **argv )
|
||||||
sb_printf( sb_out, L"%ls%ls\n", prepend, next->completion );
|
sb_printf( sb_out, L"%ls%ls\n", prepend, next->completion );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
halloc_free( comp );
|
halloc_free( comp );
|
||||||
recursion_level--;
|
recursion_level--;
|
||||||
}
|
}
|
||||||
|
|
||||||
temporary_buffer = prev_temporary_buffer;
|
temporary_buffer = prev_temporary_buffer;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if( woptind != argc )
|
else if( woptind != argc )
|
||||||
{
|
{
|
||||||
sb_printf( sb_err,
|
sb_printf( sb_err,
|
||||||
_( L"%ls: Too many arguments\n" ),
|
_( L"%ls: Too many arguments\n" ),
|
||||||
argv[0] );
|
argv[0] );
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
|
@ -603,7 +603,7 @@ static int builtin_complete( wchar_t **argv )
|
||||||
{
|
{
|
||||||
/* No arguments specified, meaning we print the definitions of
|
/* No arguments specified, meaning we print the definitions of
|
||||||
* all specified completions to stdout.*/
|
* all specified completions to stdout.*/
|
||||||
complete_print( sb_out );
|
complete_print( sb_out );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -613,26 +613,26 @@ static int builtin_complete( wchar_t **argv )
|
||||||
&path,
|
&path,
|
||||||
(wchar_t *)short_opt.buff,
|
(wchar_t *)short_opt.buff,
|
||||||
&gnu_opt,
|
&gnu_opt,
|
||||||
&old_opt );
|
&old_opt );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
builtin_complete_add( &cmd,
|
builtin_complete_add( &cmd,
|
||||||
&path,
|
&path,
|
||||||
(wchar_t *)short_opt.buff,
|
(wchar_t *)short_opt.buff,
|
||||||
&gnu_opt,
|
&gnu_opt,
|
||||||
&old_opt,
|
&old_opt,
|
||||||
result_mode,
|
result_mode,
|
||||||
authoritative,
|
authoritative,
|
||||||
condition,
|
condition,
|
||||||
comp,
|
comp,
|
||||||
desc,
|
desc,
|
||||||
flags );
|
flags );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
al_foreach( &cmd, &free );
|
al_foreach( &cmd, &free );
|
||||||
al_foreach( &path, &free );
|
al_foreach( &path, &free );
|
||||||
|
|
||||||
|
|
|
@ -173,7 +173,7 @@ static int builtin_jobs( wchar_t **argv )
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
const static struct woption
|
static const struct woption
|
||||||
long_options[] =
|
long_options[] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
@ -248,7 +248,7 @@ static int builtin_jobs( wchar_t **argv )
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
builtin_print_help( argv[0], sb_out );
|
builtin_print_help( argv[0], sb_out );
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
builtin_unknown_option( argv[0], argv[woptind-1] );
|
builtin_unknown_option( argv[0], argv[woptind-1] );
|
||||||
|
|
314
builtin_set.c
314
builtin_set.c
|
@ -1,6 +1,6 @@
|
||||||
/** \file builtin_set.c Functions defining the set builtin
|
/** \file builtin_set.c Functions defining the set builtin
|
||||||
|
|
||||||
Functions used for implementing the set builtin.
|
Functions used for implementing the set builtin.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -61,19 +61,19 @@ static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
|
||||||
int i;
|
int i;
|
||||||
int retcode = 0;
|
int retcode = 0;
|
||||||
wchar_t *val_str=0;
|
wchar_t *val_str=0;
|
||||||
|
|
||||||
if( is_path_variable( key ) )
|
if( is_path_variable( key ) )
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
for( i=0; i<al_get_count( val ); i++ )
|
for( i=0; i<al_get_count( val ); i++ )
|
||||||
{
|
{
|
||||||
int show_perror = 0;
|
int show_perror = 0;
|
||||||
int show_hint = 0;
|
int show_hint = 0;
|
||||||
|
|
||||||
struct stat buff;
|
struct stat buff;
|
||||||
wchar_t *dir = (wchar_t *)al_get( val, i );
|
wchar_t *dir = (wchar_t *)al_get( val, i );
|
||||||
|
|
||||||
if( wstat( dir, &buff ) )
|
if( wstat( dir, &buff ) )
|
||||||
{
|
{
|
||||||
error = 1;
|
error = 1;
|
||||||
|
@ -83,55 +83,55 @@ static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
|
||||||
if( !( S_ISDIR(buff.st_mode) ) )
|
if( !( S_ISDIR(buff.st_mode) ) )
|
||||||
{
|
{
|
||||||
error = 1;
|
error = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( error )
|
if( error )
|
||||||
{
|
{
|
||||||
wchar_t *colon;
|
wchar_t *colon;
|
||||||
|
|
||||||
sb_printf( sb_err,
|
sb_printf( sb_err,
|
||||||
_(BUILTIN_SET_PATH_ERROR),
|
_(BUILTIN_SET_PATH_ERROR),
|
||||||
L"set",
|
L"set",
|
||||||
dir,
|
dir,
|
||||||
key );
|
key );
|
||||||
|
|
||||||
colon = wcschr( dir, L':' );
|
colon = wcschr( dir, L':' );
|
||||||
|
|
||||||
if( colon && *(colon+1) )
|
if( colon && *(colon+1) )
|
||||||
{
|
{
|
||||||
show_hint = 1;
|
show_hint = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( show_perror )
|
if( show_perror )
|
||||||
{
|
{
|
||||||
builtin_wperror( L"set" );
|
builtin_wperror( L"set" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( show_hint )
|
if( show_hint )
|
||||||
{
|
{
|
||||||
sb_printf( sb_err,
|
sb_printf( sb_err,
|
||||||
_(BUILTIN_SET_PATH_HINT),
|
_(BUILTIN_SET_PATH_HINT),
|
||||||
L"set",
|
L"set",
|
||||||
key,
|
key,
|
||||||
key,
|
key,
|
||||||
wcschr( dir, L':' )+1);
|
wcschr( dir, L':' )+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( error )
|
if( error )
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( error )
|
if( error )
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sb_init( &sb );
|
sb_init( &sb );
|
||||||
|
@ -148,9 +148,9 @@ static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val_str = (wchar_t *)sb.buff;
|
val_str = (wchar_t *)sb.buff;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch( env_set( key, val_str, scope | ENV_USER ) )
|
switch( env_set( key, val_str, scope | ENV_USER ) )
|
||||||
{
|
{
|
||||||
case ENV_PERM:
|
case ENV_PERM:
|
||||||
|
@ -159,7 +159,7 @@ static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
|
||||||
retcode=1;
|
retcode=1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ENV_INVALID:
|
case ENV_INVALID:
|
||||||
{
|
{
|
||||||
sb_printf( sb_err, _(L"%ls: Unknown error"), L"set" );
|
sb_printf( sb_err, _(L"%ls: Unknown error"), L"set" );
|
||||||
|
@ -173,13 +173,13 @@ static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
|
||||||
return retcode;
|
return retcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Extract indexes from a destination argument of the form name[index1 index2...]
|
Extract indexes from a destination argument of the form name[index1 index2...]
|
||||||
|
|
||||||
\param indexes the list to insert the new indexes into
|
\param indexes the list to insert the new indexes into
|
||||||
\param src the source string to parse
|
\param src the source string to parse
|
||||||
\param name the name of the element. Return null if the name in \c src does not match this name
|
\param name the name of the element. Return null if the name in \c src does not match this name
|
||||||
\param var_count the number of elements in the array to parse.
|
\param var_count the number of elements in the array to parse.
|
||||||
|
|
||||||
\return the total number of indexes parsed, or -1 on error
|
\return the total number of indexes parsed, or -1 on error
|
||||||
*/
|
*/
|
||||||
|
@ -189,57 +189,57 @@ static int parse_index( array_list_t *indexes,
|
||||||
int var_count )
|
int var_count )
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
const wchar_t *src_orig = src;
|
const wchar_t *src_orig = src;
|
||||||
|
|
||||||
if (src == 0)
|
if (src == 0)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*src != L'\0' && (iswalnum(*src) || *src == L'_'))
|
while (*src != L'\0' && (iswalnum(*src) || *src == L'_'))
|
||||||
{
|
{
|
||||||
src++;
|
src++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*src != L'[')
|
if (*src != L'[')
|
||||||
{
|
{
|
||||||
sb_printf( sb_err, _(BUILTIN_SET_ARG_COUNT), L"set" );
|
sb_printf( sb_err, _(BUILTIN_SET_ARG_COUNT), L"set" );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = src-src_orig;
|
len = src-src_orig;
|
||||||
|
|
||||||
if( (wcsncmp( src_orig, name, len )!=0) || (wcslen(name) != (len)) )
|
if( (wcsncmp( src_orig, name, len )!=0) || (wcslen(name) != (len)) )
|
||||||
{
|
{
|
||||||
sb_printf( sb_err,
|
sb_printf( sb_err,
|
||||||
_(L"%ls: Multiple variable names specified in single call (%ls and %.*ls)\n"),
|
_(L"%ls: Multiple variable names specified in single call (%ls and %.*ls)\n"),
|
||||||
L"set",
|
L"set",
|
||||||
name,
|
name,
|
||||||
len,
|
len,
|
||||||
src_orig);
|
src_orig);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
src++;
|
src++;
|
||||||
|
|
||||||
while (iswspace(*src))
|
while (iswspace(*src))
|
||||||
{
|
{
|
||||||
src++;
|
src++;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*src != L']')
|
while (*src != L']')
|
||||||
{
|
{
|
||||||
wchar_t *end;
|
wchar_t *end;
|
||||||
|
|
||||||
long l_ind;
|
long l_ind;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
l_ind = wcstol(src, &end, 10);
|
l_ind = wcstol(src, &end, 10);
|
||||||
|
|
||||||
if( end==src || errno )
|
if( end==src || errno )
|
||||||
{
|
{
|
||||||
sb_printf(sb_err, _(L"%ls: Invalid index starting at '%ls'\n"), L"set", src);
|
sb_printf(sb_err, _(L"%ls: Invalid index starting at '%ls'\n"), L"set", src);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -249,7 +249,7 @@ static int parse_index( array_list_t *indexes,
|
||||||
{
|
{
|
||||||
l_ind = var_count+l_ind+1;
|
l_ind = var_count+l_ind+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
al_push_long(indexes, l_ind);
|
al_push_long(indexes, l_ind);
|
||||||
src = end;
|
src = end;
|
||||||
count++;
|
count++;
|
||||||
|
@ -268,14 +268,14 @@ static int parse_index( array_list_t *indexes,
|
||||||
|
|
||||||
\return 0 if the operation was successfull, non-zero otherwise
|
\return 0 if the operation was successfull, non-zero otherwise
|
||||||
*/
|
*/
|
||||||
static int update_values( array_list_t *list,
|
static int update_values( array_list_t *list,
|
||||||
array_list_t *indexes,
|
array_list_t *indexes,
|
||||||
array_list_t *values )
|
array_list_t *values )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Replace values where needed */
|
/* Replace values where needed */
|
||||||
for( i = 0; i < al_get_count(indexes); i++ )
|
for( i = 0; i < al_get_count(indexes); i++ )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
The '- 1' below is because the indices in fish are
|
The '- 1' below is because the indices in fish are
|
||||||
|
@ -287,11 +287,11 @@ static int update_values( array_list_t *list,
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
free((void *) al_get(list, ind));
|
free((void *) al_get(list, ind));
|
||||||
al_set(list, ind, new != 0 ? wcsdup(new) : wcsdup(L""));
|
al_set(list, ind, new != 0 ? wcsdup(new) : wcsdup(L""));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,42 +305,42 @@ static int al_contains_long( array_list_t *list,
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < al_get_count(list); i++)
|
for (i = 0; i < al_get_count(list); i++)
|
||||||
{
|
{
|
||||||
long current = al_get_long(list, i);
|
long current = al_get_long(list, i);
|
||||||
if( current != 0 && current == val )
|
if( current != 0 && current == val )
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Erase from a list values at specified indexes
|
Erase from a list values at specified indexes
|
||||||
*/
|
*/
|
||||||
static void erase_values(array_list_t *list, array_list_t *indexes)
|
static void erase_values(array_list_t *list, array_list_t *indexes)
|
||||||
{
|
{
|
||||||
long i;
|
long i;
|
||||||
array_list_t result;
|
array_list_t result;
|
||||||
|
|
||||||
al_init(&result);
|
al_init(&result);
|
||||||
|
|
||||||
for (i = 0; i < al_get_count(list); i++)
|
for (i = 0; i < al_get_count(list); i++)
|
||||||
{
|
{
|
||||||
if (!al_contains_long(indexes, i + 1))
|
if (!al_contains_long(indexes, i + 1))
|
||||||
{
|
{
|
||||||
al_push(&result, al_get(list, i));
|
al_push(&result, al_get(list, i));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
free( (void *)al_get(list, i));
|
free( (void *)al_get(list, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
al_truncate(list,0);
|
al_truncate(list,0);
|
||||||
al_push_all( list, &result );
|
al_push_all( list, &result );
|
||||||
al_destroy(&result);
|
al_destroy(&result);
|
||||||
}
|
}
|
||||||
|
@ -350,31 +350,31 @@ static void erase_values(array_list_t *list, array_list_t *indexes)
|
||||||
Print the names of all environment variables in the scope, with or without values,
|
Print the names of all environment variables in the scope, with or without values,
|
||||||
with or without escaping
|
with or without escaping
|
||||||
*/
|
*/
|
||||||
static void print_variables(int include_values, int esc, int scope)
|
static void print_variables(int include_values, int esc, int scope)
|
||||||
{
|
{
|
||||||
array_list_t names;
|
array_list_t names;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
al_init( &names );
|
al_init( &names );
|
||||||
env_get_names( &names, scope );
|
env_get_names( &names, scope );
|
||||||
|
|
||||||
sort_list( &names );
|
sort_list( &names );
|
||||||
|
|
||||||
for( i = 0; i < al_get_count(&names); i++ )
|
for( i = 0; i < al_get_count(&names); i++ )
|
||||||
{
|
{
|
||||||
wchar_t *key = (wchar_t *)al_get( &names, i );
|
wchar_t *key = (wchar_t *)al_get( &names, i );
|
||||||
wchar_t *e_key = esc ? escape(key, 0) : wcsdup(key);
|
wchar_t *e_key = esc ? escape(key, 0) : wcsdup(key);
|
||||||
|
|
||||||
sb_append(sb_out, e_key);
|
sb_append(sb_out, e_key);
|
||||||
|
|
||||||
if( include_values )
|
if( include_values )
|
||||||
{
|
{
|
||||||
wchar_t *value = env_get(key);
|
wchar_t *value = env_get(key);
|
||||||
wchar_t *e_value;
|
wchar_t *e_value;
|
||||||
if( value )
|
if( value )
|
||||||
{
|
{
|
||||||
int shorten = 0;
|
int shorten = 0;
|
||||||
|
|
||||||
if( wcslen( value ) > 64 )
|
if( wcslen( value ) > 64 )
|
||||||
{
|
{
|
||||||
shorten = 1;
|
shorten = 1;
|
||||||
|
@ -384,12 +384,12 @@ static void print_variables(int include_values, int esc, int scope)
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
e_value = esc ? expand_escape_variable(value) : wcsdup(value);
|
e_value = esc ? expand_escape_variable(value) : wcsdup(value);
|
||||||
|
|
||||||
sb_append(sb_out, L" ", e_value, (void *)0);
|
sb_append(sb_out, L" ", e_value, (void *)0);
|
||||||
free(e_value);
|
free(e_value);
|
||||||
|
|
||||||
if( shorten )
|
if( shorten )
|
||||||
{
|
{
|
||||||
sb_append(sb_out, L"\u2026");
|
sb_append(sb_out, L"\u2026");
|
||||||
|
@ -398,7 +398,7 @@ static void print_variables(int include_values, int esc, int scope)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sb_append(sb_out, L"\n");
|
sb_append(sb_out, L"\n");
|
||||||
free(e_key);
|
free(e_key);
|
||||||
}
|
}
|
||||||
|
@ -411,57 +411,57 @@ static void print_variables(int include_values, int esc, int scope)
|
||||||
The set builtin. Creates, updates and erases environment variables
|
The set builtin. Creates, updates and erases environment variables
|
||||||
and environemnt variable arrays.
|
and environemnt variable arrays.
|
||||||
*/
|
*/
|
||||||
static int builtin_set( wchar_t **argv )
|
static int builtin_set( wchar_t **argv )
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Variables used for parsing the argument list
|
Variables used for parsing the argument list
|
||||||
*/
|
*/
|
||||||
const static struct woption
|
static const struct woption
|
||||||
long_options[] =
|
long_options[] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
L"export", no_argument, 0, 'x'
|
L"export", no_argument, 0, 'x'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
L"global", no_argument, 0, 'g'
|
L"global", no_argument, 0, 'g'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
L"local", no_argument, 0, 'l'
|
L"local", no_argument, 0, 'l'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
L"erase", no_argument, 0, 'e'
|
L"erase", no_argument, 0, 'e'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
L"names", no_argument, 0, 'n'
|
L"names", no_argument, 0, 'n'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
L"unexport", no_argument, 0, 'u'
|
L"unexport", no_argument, 0, 'u'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
L"universal", no_argument, 0, 'U'
|
L"universal", no_argument, 0, 'U'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
L"query", no_argument, 0, 'q'
|
L"query", no_argument, 0, 'q'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
L"help", no_argument, 0, 'h'
|
L"help", no_argument, 0, 'h'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
0, 0, 0, 0
|
0, 0, 0, 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
const wchar_t *short_options = L"+xglenuUqh";
|
const wchar_t *short_options = L"+xglenuUqh";
|
||||||
|
|
||||||
int argc = builtin_count_args(argv);
|
int argc = builtin_count_args(argv);
|
||||||
|
@ -472,7 +472,7 @@ static int builtin_set( wchar_t **argv )
|
||||||
int local = 0, global = 0, export = 0;
|
int local = 0, global = 0, export = 0;
|
||||||
int erase = 0, list = 0, unexport=0;
|
int erase = 0, list = 0, unexport=0;
|
||||||
int universal = 0, query=0;
|
int universal = 0, query=0;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Variables used for performing the actual work
|
Variables used for performing the actual work
|
||||||
|
@ -482,22 +482,22 @@ static int builtin_set( wchar_t **argv )
|
||||||
int scope;
|
int scope;
|
||||||
int slice=0;
|
int slice=0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
wchar_t *bad_char;
|
wchar_t *bad_char;
|
||||||
|
|
||||||
|
|
||||||
/* Parse options to obtain the requested operation and the modifiers */
|
/* Parse options to obtain the requested operation and the modifiers */
|
||||||
woptind = 0;
|
woptind = 0;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
int c = wgetopt_long(argc, argv, short_options, long_options, 0);
|
int c = wgetopt_long(argc, argv, short_options, long_options, 0);
|
||||||
|
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(c)
|
switch(c)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
|
@ -561,18 +561,18 @@ static int builtin_set( wchar_t **argv )
|
||||||
sb_printf(sb_err,
|
sb_printf(sb_err,
|
||||||
BUILTIN_ERR_COMBO,
|
BUILTIN_ERR_COMBO,
|
||||||
argv[0] );
|
argv[0] );
|
||||||
|
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* We can't both list and erase varaibles */
|
/* We can't both list and erase varaibles */
|
||||||
if( erase && list )
|
if( erase && list )
|
||||||
{
|
{
|
||||||
sb_printf(sb_err,
|
sb_printf(sb_err,
|
||||||
BUILTIN_ERR_COMBO,
|
BUILTIN_ERR_COMBO,
|
||||||
argv[0] );
|
argv[0] );
|
||||||
|
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -581,7 +581,7 @@ static int builtin_set( wchar_t **argv )
|
||||||
/*
|
/*
|
||||||
Variables can only have one scope
|
Variables can only have one scope
|
||||||
*/
|
*/
|
||||||
if( local + global + universal > 1 )
|
if( local + global + universal > 1 )
|
||||||
{
|
{
|
||||||
sb_printf( sb_err,
|
sb_printf( sb_err,
|
||||||
BUILTIN_ERR_GLOCAL,
|
BUILTIN_ERR_GLOCAL,
|
||||||
|
@ -593,7 +593,7 @@ static int builtin_set( wchar_t **argv )
|
||||||
/*
|
/*
|
||||||
Variables can only have one export status
|
Variables can only have one export status
|
||||||
*/
|
*/
|
||||||
if( export && unexport )
|
if( export && unexport )
|
||||||
{
|
{
|
||||||
sb_printf( sb_err,
|
sb_printf( sb_err,
|
||||||
BUILTIN_ERR_EXPUNEXP,
|
BUILTIN_ERR_EXPUNEXP,
|
||||||
|
@ -605,7 +605,7 @@ static int builtin_set( wchar_t **argv )
|
||||||
/*
|
/*
|
||||||
Calculate the scope value for variable assignement
|
Calculate the scope value for variable assignement
|
||||||
*/
|
*/
|
||||||
scope = (local ? ENV_LOCAL : 0) | (global ? ENV_GLOBAL : 0) | (export ? ENV_EXPORT : 0) | (unexport ? ENV_UNEXPORT : 0) | (universal ? ENV_UNIVERSAL:0) | ENV_USER;
|
scope = (local ? ENV_LOCAL : 0) | (global ? ENV_GLOBAL : 0) | (export ? ENV_EXPORT : 0) | (unexport ? ENV_UNEXPORT : 0) | (universal ? ENV_UNIVERSAL:0) | ENV_USER;
|
||||||
|
|
||||||
if( query )
|
if( query )
|
||||||
{
|
{
|
||||||
|
@ -621,7 +621,7 @@ static int builtin_set( wchar_t **argv )
|
||||||
|
|
||||||
if( !(dest = wcsdup(arg)))
|
if( !(dest = wcsdup(arg)))
|
||||||
{
|
{
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( wcschr( dest, L'[' ) )
|
if( wcschr( dest, L'[' ) )
|
||||||
|
@ -629,18 +629,18 @@ static int builtin_set( wchar_t **argv )
|
||||||
slice = 1;
|
slice = 1;
|
||||||
*wcschr( dest, L'[' )=0;
|
*wcschr( dest, L'[' )=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( slice )
|
if( slice )
|
||||||
{
|
{
|
||||||
array_list_t indexes;
|
array_list_t indexes;
|
||||||
array_list_t result;
|
array_list_t result;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
al_init( &result );
|
al_init( &result );
|
||||||
al_init( &indexes );
|
al_init( &indexes );
|
||||||
|
|
||||||
tokenize_variable_array( env_get( dest ), &result );
|
tokenize_variable_array( env_get( dest ), &result );
|
||||||
|
|
||||||
if( !parse_index( &indexes, arg, dest, al_get_count( &result ) ) )
|
if( !parse_index( &indexes, arg, dest, al_get_count( &result ) ) )
|
||||||
{
|
{
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
|
@ -663,32 +663,32 @@ static int builtin_set( wchar_t **argv )
|
||||||
retcode++;
|
retcode++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free( dest );
|
free( dest );
|
||||||
|
|
||||||
}
|
}
|
||||||
return retcode;
|
return retcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( list )
|
if( list )
|
||||||
{
|
{
|
||||||
/* Maybe we should issue an error if there are any other arguments? */
|
/* Maybe we should issue an error if there are any other arguments? */
|
||||||
print_variables(0, 0, scope);
|
print_variables(0, 0, scope);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( woptind == argc )
|
if( woptind == argc )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Print values of variables
|
Print values of variables
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( erase )
|
if( erase )
|
||||||
{
|
{
|
||||||
sb_printf( sb_err,
|
sb_printf( sb_err,
|
||||||
_(L"%ls: Erase needs a variable name\n%ls\n"),
|
_(L"%ls: Erase needs a variable name\n%ls\n"),
|
||||||
argv[0] );
|
argv[0] );
|
||||||
|
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
retcode = 1;
|
retcode = 1;
|
||||||
}
|
}
|
||||||
|
@ -696,13 +696,13 @@ static int builtin_set( wchar_t **argv )
|
||||||
{
|
{
|
||||||
print_variables( 1, 1, scope );
|
print_variables( 1, 1, scope );
|
||||||
}
|
}
|
||||||
|
|
||||||
return retcode;
|
return retcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !(dest = wcsdup(argv[woptind])))
|
if( !(dest = wcsdup(argv[woptind])))
|
||||||
{
|
{
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( wcschr( dest, L'[' ) )
|
if( wcschr( dest, L'[' ) )
|
||||||
|
@ -710,7 +710,7 @@ static int builtin_set( wchar_t **argv )
|
||||||
slice = 1;
|
slice = 1;
|
||||||
*wcschr( dest, L'[' )=0;
|
*wcschr( dest, L'[' )=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !wcslen( dest ) )
|
if( !wcslen( dest ) )
|
||||||
{
|
{
|
||||||
free( dest );
|
free( dest );
|
||||||
|
@ -718,7 +718,7 @@ static int builtin_set( wchar_t **argv )
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (bad_char = wcsvarname( dest ) ) )
|
if( (bad_char = wcsvarname( dest ) ) )
|
||||||
{
|
{
|
||||||
sb_printf( sb_err, BUILTIN_ERR_VARCHAR, argv[0], *bad_char );
|
sb_printf( sb_err, BUILTIN_ERR_VARCHAR, argv[0], *bad_char );
|
||||||
|
@ -726,7 +726,7 @@ static int builtin_set( wchar_t **argv )
|
||||||
free( dest );
|
free( dest );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( slice && erase && (scope != ENV_USER) )
|
if( slice && erase && (scope != ENV_USER) )
|
||||||
{
|
{
|
||||||
free( dest );
|
free( dest );
|
||||||
|
@ -734,12 +734,12 @@ static int builtin_set( wchar_t **argv )
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
set assignment can work in two modes, either using slices or
|
set assignment can work in two modes, either using slices or
|
||||||
using the whole array. We detect which mode is used here.
|
using the whole array. We detect which mode is used here.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( slice )
|
if( slice )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -750,22 +750,22 @@ static int builtin_set( wchar_t **argv )
|
||||||
array_list_t values;
|
array_list_t values;
|
||||||
array_list_t indexes;
|
array_list_t indexes;
|
||||||
array_list_t result;
|
array_list_t result;
|
||||||
|
|
||||||
al_init(&values);
|
al_init(&values);
|
||||||
al_init(&indexes);
|
al_init(&indexes);
|
||||||
al_init(&result);
|
al_init(&result);
|
||||||
|
|
||||||
tokenize_variable_array( env_get(dest), &result );
|
tokenize_variable_array( env_get(dest), &result );
|
||||||
|
|
||||||
for( ; woptind<argc; woptind++ )
|
for( ; woptind<argc; woptind++ )
|
||||||
{
|
{
|
||||||
if( !parse_index( &indexes, argv[woptind], dest, al_get_count( &result ) ) )
|
if( !parse_index( &indexes, argv[woptind], dest, al_get_count( &result ) ) )
|
||||||
{
|
{
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
retcode = 1;
|
retcode = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
val_count = argc-woptind-1;
|
val_count = argc-woptind-1;
|
||||||
idx_count = al_get_count( &indexes );
|
idx_count = al_get_count( &indexes );
|
||||||
|
|
||||||
|
@ -784,7 +784,7 @@ static int builtin_set( wchar_t **argv )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !retcode )
|
if( !retcode )
|
||||||
{
|
{
|
||||||
|
@ -802,12 +802,12 @@ static int builtin_set( wchar_t **argv )
|
||||||
array_list_t value;
|
array_list_t value;
|
||||||
al_init(&value);
|
al_init(&value);
|
||||||
|
|
||||||
while( woptind < argc )
|
while( woptind < argc )
|
||||||
{
|
{
|
||||||
al_push(&value, argv[woptind++]);
|
al_push(&value, argv[woptind++]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( update_values( &result,
|
if( update_values( &result,
|
||||||
&indexes,
|
&indexes,
|
||||||
&value ) )
|
&value ) )
|
||||||
{
|
{
|
||||||
|
@ -815,14 +815,14 @@ static int builtin_set( wchar_t **argv )
|
||||||
sb_printf( sb_err, ARRAY_BOUNDS_ERR );
|
sb_printf( sb_err, ARRAY_BOUNDS_ERR );
|
||||||
sb_append( sb_err, L"\n" );
|
sb_append( sb_err, L"\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
my_env_set(dest,
|
my_env_set(dest,
|
||||||
&result,
|
&result,
|
||||||
scope);
|
scope);
|
||||||
|
|
||||||
al_destroy( &value );
|
al_destroy( &value );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
al_foreach( &result, &free );
|
al_foreach( &result, &free );
|
||||||
|
@ -830,12 +830,12 @@ static int builtin_set( wchar_t **argv )
|
||||||
|
|
||||||
al_destroy(&indexes);
|
al_destroy(&indexes);
|
||||||
al_destroy(&values);
|
al_destroy(&values);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
woptind++;
|
woptind++;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
No slicing
|
No slicing
|
||||||
*/
|
*/
|
||||||
|
@ -843,7 +843,7 @@ static int builtin_set( wchar_t **argv )
|
||||||
{
|
{
|
||||||
if( woptind != argc )
|
if( woptind != argc )
|
||||||
{
|
{
|
||||||
sb_printf( sb_err,
|
sb_printf( sb_err,
|
||||||
_(L"%ls: Values cannot be specfied with erase\n"),
|
_(L"%ls: Values cannot be specfied with erase\n"),
|
||||||
argv[0] );
|
argv[0] );
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
|
@ -858,21 +858,21 @@ static int builtin_set( wchar_t **argv )
|
||||||
{
|
{
|
||||||
array_list_t val;
|
array_list_t val;
|
||||||
al_init( &val );
|
al_init( &val );
|
||||||
|
|
||||||
for( i=woptind; i<argc; i++ )
|
for( i=woptind; i<argc; i++ )
|
||||||
{
|
{
|
||||||
al_push( &val, argv[i] );
|
al_push( &val, argv[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
retcode = my_env_set( dest, &val, scope );
|
retcode = my_env_set( dest, &val, scope );
|
||||||
|
|
||||||
al_destroy( &val );
|
al_destroy( &val );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free( dest );
|
free( dest );
|
||||||
|
|
||||||
return retcode;
|
return retcode;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
136
builtin_ulimit.c
136
builtin_ulimit.c
|
@ -1,6 +1,6 @@
|
||||||
/** \file builtin_ulimit.c Functions defining the ulimit builtin
|
/** \file builtin_ulimit.c Functions defining the ulimit builtin
|
||||||
|
|
||||||
Functions used for implementing the ulimit builtin.
|
Functions used for implementing the ulimit builtin.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -38,18 +38,18 @@ struct resource_t
|
||||||
/**
|
/**
|
||||||
Switch used on commandline to specify resource
|
Switch used on commandline to specify resource
|
||||||
*/
|
*/
|
||||||
wchar_t switch_char;
|
wchar_t switch_char;
|
||||||
/**
|
/**
|
||||||
The implicit multiplier used when setting getting values
|
The implicit multiplier used when setting getting values
|
||||||
*/
|
*/
|
||||||
int multiplier;
|
int multiplier;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Array of resource_t structs, describing all known resource types.
|
Array of resource_t structs, describing all known resource types.
|
||||||
*/
|
*/
|
||||||
const static struct resource_t resource_arr[] =
|
static const struct resource_t resource_arr[] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
RLIMIT_CORE, L"Maximum size of core files created", L'c', 1024
|
RLIMIT_CORE, L"Maximum size of core files created", L'c', 1024
|
||||||
|
@ -96,7 +96,7 @@ const static struct resource_t resource_arr[] =
|
||||||
#ifdef RLIMIT_AS
|
#ifdef RLIMIT_AS
|
||||||
{
|
{
|
||||||
RLIMIT_AS, L"Maximum amount of virtual memory available to the shell", L'v', 1024
|
RLIMIT_AS, L"Maximum amount of virtual memory available to the shell", L'v', 1024
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
@ -111,7 +111,7 @@ const static struct resource_t resource_arr[] =
|
||||||
static int get_multiplier( int what )
|
static int get_multiplier( int what )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for( i=0; resource_arr[i].desc; i++ )
|
for( i=0; resource_arr[i].desc; i++ )
|
||||||
{
|
{
|
||||||
if( resource_arr[i].resource == what )
|
if( resource_arr[i].resource == what )
|
||||||
|
@ -130,9 +130,9 @@ static int get_multiplier( int what )
|
||||||
static rlim_t get( int resource, int hard )
|
static rlim_t get( int resource, int hard )
|
||||||
{
|
{
|
||||||
struct rlimit ls;
|
struct rlimit ls;
|
||||||
|
|
||||||
getrlimit( resource, &ls );
|
getrlimit( resource, &ls );
|
||||||
|
|
||||||
return hard ? ls.rlim_max:ls.rlim_cur;
|
return hard ? ls.rlim_max:ls.rlim_cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ static void print( int resource, int hard )
|
||||||
sb_append( sb_out, L"unlimited\n" );
|
sb_append( sb_out, L"unlimited\n" );
|
||||||
else
|
else
|
||||||
sb_printf( sb_out, L"%d\n", l / get_multiplier( resource ) );
|
sb_printf( sb_out, L"%d\n", l / get_multiplier( resource ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -157,12 +157,12 @@ static void print_all( int hard )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int w=0;
|
int w=0;
|
||||||
|
|
||||||
for( i=0; resource_arr[i].desc; i++ )
|
for( i=0; resource_arr[i].desc; i++ )
|
||||||
{
|
{
|
||||||
w=maxi( w, my_wcswidth(resource_arr[i].desc));
|
w=maxi( w, my_wcswidth(resource_arr[i].desc));
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i=0; resource_arr[i].desc; i++ )
|
for( i=0; resource_arr[i].desc; i++ )
|
||||||
{
|
{
|
||||||
struct rlimit ls;
|
struct rlimit ls;
|
||||||
|
@ -171,14 +171,14 @@ static void print_all( int hard )
|
||||||
l = hard ? ls.rlim_max:ls.rlim_cur;
|
l = hard ? ls.rlim_max:ls.rlim_cur;
|
||||||
|
|
||||||
wchar_t *unit = ((resource_arr[i].resource==RLIMIT_CPU)?L"(seconds, ":(get_multiplier(resource_arr[i].resource)==1?L"(":L"(kB, "));
|
wchar_t *unit = ((resource_arr[i].resource==RLIMIT_CPU)?L"(seconds, ":(get_multiplier(resource_arr[i].resource)==1?L"(":L"(kB, "));
|
||||||
|
|
||||||
sb_printf( sb_out,
|
sb_printf( sb_out,
|
||||||
L"%-*ls %10ls-%lc) ",
|
L"%-*ls %10ls-%lc) ",
|
||||||
w,
|
w,
|
||||||
resource_arr[i].desc,
|
resource_arr[i].desc,
|
||||||
unit,
|
unit,
|
||||||
resource_arr[i].switch_char);
|
resource_arr[i].switch_char);
|
||||||
|
|
||||||
if( l == RLIM_INFINITY )
|
if( l == RLIM_INFINITY )
|
||||||
{
|
{
|
||||||
sb_append( sb_out, L"unlimited\n" );
|
sb_append( sb_out, L"unlimited\n" );
|
||||||
|
@ -188,7 +188,7 @@ static void print_all( int hard )
|
||||||
sb_printf( sb_out, L"%d\n", l/get_multiplier(resource_arr[i].resource) );
|
sb_printf( sb_out, L"%d\n", l/get_multiplier(resource_arr[i].resource) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -197,7 +197,7 @@ static void print_all( int hard )
|
||||||
static const wchar_t *get_desc( int what )
|
static const wchar_t *get_desc( int what )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for( i=0; resource_arr[i].desc; i++ )
|
for( i=0; resource_arr[i].desc; i++ )
|
||||||
{
|
{
|
||||||
if( resource_arr[i].resource == what )
|
if( resource_arr[i].resource == what )
|
||||||
|
@ -217,26 +217,26 @@ static int set( int resource, int hard, int soft, rlim_t value )
|
||||||
{
|
{
|
||||||
struct rlimit ls;
|
struct rlimit ls;
|
||||||
getrlimit( resource, &ls );
|
getrlimit( resource, &ls );
|
||||||
|
|
||||||
if( hard )
|
if( hard )
|
||||||
{
|
{
|
||||||
ls.rlim_max = value;
|
ls.rlim_max = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( soft )
|
if( soft )
|
||||||
{
|
{
|
||||||
ls.rlim_cur = value;
|
ls.rlim_cur = value;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Do not attempt to set the soft limit higher than the hard limit
|
Do not attempt to set the soft limit higher than the hard limit
|
||||||
*/
|
*/
|
||||||
if( ( value == RLIM_INFINITY && ls.rlim_max != RLIM_INFINITY ) ||
|
if( ( value == RLIM_INFINITY && ls.rlim_max != RLIM_INFINITY ) ||
|
||||||
( value != RLIM_INFINITY && ls.rlim_max != RLIM_INFINITY && value > ls.rlim_max))
|
( value != RLIM_INFINITY && ls.rlim_max != RLIM_INFINITY && value > ls.rlim_max))
|
||||||
{
|
{
|
||||||
ls.rlim_cur = ls.rlim_max;
|
ls.rlim_cur = ls.rlim_max;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( setrlimit( resource, &ls ) )
|
if( setrlimit( resource, &ls ) )
|
||||||
{
|
{
|
||||||
if( errno == EPERM )
|
if( errno == EPERM )
|
||||||
|
@ -244,8 +244,8 @@ static int set( int resource, int hard, int soft, rlim_t value )
|
||||||
else
|
else
|
||||||
builtin_wperror( L"ulimit" );
|
builtin_wperror( L"ulimit" );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -256,17 +256,17 @@ static int builtin_ulimit( wchar_t ** argv )
|
||||||
{
|
{
|
||||||
int hard=0;
|
int hard=0;
|
||||||
int soft=0;
|
int soft=0;
|
||||||
|
|
||||||
int what = RLIMIT_FSIZE;
|
int what = RLIMIT_FSIZE;
|
||||||
int report_all = 0;
|
int report_all = 0;
|
||||||
|
|
||||||
int argc = builtin_count_args( argv );
|
int argc = builtin_count_args( argv );
|
||||||
|
|
||||||
woptind=0;
|
woptind=0;
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
const static struct woption
|
static const struct woption
|
||||||
long_options[] =
|
long_options[] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
@ -321,27 +321,27 @@ static int builtin_ulimit( wchar_t ** argv )
|
||||||
L"virtual-memory-size", no_argument, 0, 'v'
|
L"virtual-memory-size", no_argument, 0, 'v'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
L"help", no_argument, 0, 'h'
|
L"help", no_argument, 0, 'h'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
0, 0, 0, 0
|
0, 0, 0, 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
int opt_index = 0;
|
int opt_index = 0;
|
||||||
|
|
||||||
int opt = wgetopt_long( argc,
|
int opt = wgetopt_long( argc,
|
||||||
argv,
|
argv,
|
||||||
L"aHScdflmnstuvh",
|
L"aHScdflmnstuvh",
|
||||||
long_options,
|
long_options,
|
||||||
&opt_index );
|
&opt_index );
|
||||||
if( opt == -1 )
|
if( opt == -1 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch( opt )
|
switch( opt )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -354,7 +354,7 @@ static int builtin_ulimit( wchar_t ** argv )
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case L'a':
|
case L'a':
|
||||||
report_all=1;
|
report_all=1;
|
||||||
break;
|
break;
|
||||||
|
@ -364,17 +364,17 @@ static int builtin_ulimit( wchar_t ** argv )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case L'S':
|
case L'S':
|
||||||
soft=1;
|
soft=1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case L'c':
|
case L'c':
|
||||||
what=RLIMIT_CORE;
|
what=RLIMIT_CORE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case L'd':
|
case L'd':
|
||||||
what=RLIMIT_DATA;
|
what=RLIMIT_DATA;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case L'f':
|
case L'f':
|
||||||
what=RLIMIT_FSIZE;
|
what=RLIMIT_FSIZE;
|
||||||
break;
|
break;
|
||||||
|
@ -384,45 +384,45 @@ static int builtin_ulimit( wchar_t ** argv )
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RLIMIT_RSS
|
#ifdef RLIMIT_RSS
|
||||||
case L'm':
|
case L'm':
|
||||||
what=RLIMIT_RSS;
|
what=RLIMIT_RSS;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case L'n':
|
case L'n':
|
||||||
what=RLIMIT_NOFILE;
|
what=RLIMIT_NOFILE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case L's':
|
case L's':
|
||||||
what=RLIMIT_STACK;
|
what=RLIMIT_STACK;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case L't':
|
case L't':
|
||||||
what=RLIMIT_CPU;
|
what=RLIMIT_CPU;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef RLIMIT_NPROC
|
#ifdef RLIMIT_NPROC
|
||||||
case L'u':
|
case L'u':
|
||||||
what=RLIMIT_NPROC;
|
what=RLIMIT_NPROC;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RLIMIT_AS
|
#ifdef RLIMIT_AS
|
||||||
case L'v':
|
case L'v':
|
||||||
what=RLIMIT_AS;
|
what=RLIMIT_AS;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case L'h':
|
case L'h':
|
||||||
builtin_print_help( argv[0], sb_out );
|
builtin_print_help( argv[0], sb_out );
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case L'?':
|
case L'?':
|
||||||
builtin_unknown_option( argv[0], argv[woptind-1] );
|
builtin_unknown_option( argv[0], argv[woptind-1] );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( report_all )
|
if( report_all )
|
||||||
{
|
{
|
||||||
|
@ -442,7 +442,7 @@ static int builtin_ulimit( wchar_t ** argv )
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch( argc - woptind )
|
switch( argc - woptind )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -453,7 +453,7 @@ static int builtin_ulimit( wchar_t ** argv )
|
||||||
print( what, hard );
|
print( what, hard );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -469,7 +469,7 @@ static int builtin_ulimit( wchar_t ** argv )
|
||||||
{
|
{
|
||||||
hard=soft=1;
|
hard=soft=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( wcscasecmp( argv[woptind], L"unlimited" )==0)
|
if( wcscasecmp( argv[woptind], L"unlimited" )==0)
|
||||||
{
|
{
|
||||||
new_limit = RLIM_INFINITY;
|
new_limit = RLIM_INFINITY;
|
||||||
|
@ -484,23 +484,23 @@ static int builtin_ulimit( wchar_t ** argv )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
errno=0;
|
errno=0;
|
||||||
new_limit = wcstol( argv[woptind], &end, 10 );
|
new_limit = wcstol( argv[woptind], &end, 10 );
|
||||||
if( errno || *end )
|
if( errno || *end )
|
||||||
{
|
{
|
||||||
sb_printf( sb_err,
|
sb_printf( sb_err,
|
||||||
L"%ls: Invalid limit '%ls'\n",
|
L"%ls: Invalid limit '%ls'\n",
|
||||||
argv[0],
|
argv[0],
|
||||||
argv[woptind] );
|
argv[woptind] );
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
new_limit *= get_multiplier( what );
|
new_limit *= get_multiplier( what );
|
||||||
}
|
}
|
||||||
|
|
||||||
return set( what, hard, soft, new_limit );
|
return set( what, hard, soft, new_limit );
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
sb_append( sb_err,
|
sb_append( sb_err,
|
||||||
|
@ -510,7 +510,7 @@ static int builtin_ulimit( wchar_t ** argv )
|
||||||
builtin_print_help( argv[0], sb_err );
|
builtin_print_help( argv[0], sb_err );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
42
common.h
42
common.h
|
@ -60,10 +60,10 @@
|
||||||
#define ESCAPE_NO_QUOTED 2
|
#define ESCAPE_NO_QUOTED 2
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Save the shell mode on startup so we can restore them on exit
|
Save the shell mode on startup so we can restore them on exit
|
||||||
*/
|
*/
|
||||||
extern struct termios shell_modes;
|
extern struct termios shell_modes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The character to use where the text has been truncated. Is an
|
The character to use where the text has been truncated. Is an
|
||||||
|
@ -116,7 +116,7 @@ extern wchar_t *program_name;
|
||||||
exit_read_count=read( 0, &exit_read_buff, 1 ); \
|
exit_read_count=read( 0, &exit_read_buff, 1 ); \
|
||||||
exit( 1 ); \
|
exit( 1 ); \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Exit program at once, leaving an error message about running out of memory.
|
Exit program at once, leaving an error message about running out of memory.
|
||||||
|
@ -144,7 +144,7 @@ extern wchar_t *program_name;
|
||||||
show_stackframe(); \
|
show_stackframe(); \
|
||||||
return retval; \
|
return retval; \
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Shorthand for wgettext call
|
Shorthand for wgettext call
|
||||||
*/
|
*/
|
||||||
|
@ -152,7 +152,7 @@ extern wchar_t *program_name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Noop, used to tell xgettext that a string should be translated,
|
Noop, used to tell xgettext that a string should be translated,
|
||||||
even though it is not directly sent to wgettext.
|
even though it is not directly sent to wgettext.
|
||||||
*/
|
*/
|
||||||
#define N_(wstr) wstr
|
#define N_(wstr) wstr
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ wchar_t **list_to_char_arr( array_list_t *l );
|
||||||
Read a line from the stream f into the buffer buff of length len. If
|
Read a line from the stream f into the buffer buff of length len. If
|
||||||
buff is to small, it will be reallocated, and both buff and len will
|
buff is to small, it will be reallocated, and both buff and len will
|
||||||
be updated to reflect this. Returns the number of bytes read or -1
|
be updated to reflect this. Returns the number of bytes read or -1
|
||||||
on failiure.
|
on failiure.
|
||||||
|
|
||||||
If the carriage return character is encountered, it is
|
If the carriage return character is encountered, it is
|
||||||
ignored. fgetws() considers the line to end if reading the file
|
ignored. fgetws() considers the line to end if reading the file
|
||||||
|
@ -258,7 +258,7 @@ __sentinel wchar_t *wcsdupcat_internal( const wchar_t *a, ... );
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Test if the given string is a valid variable name.
|
Test if the given string is a valid variable name.
|
||||||
|
|
||||||
\return null if this is a valid name, and a pointer to the first invalid character otherwise
|
\return null if this is a valid name, and a pointer to the first invalid character otherwise
|
||||||
*/
|
*/
|
||||||
|
@ -267,7 +267,7 @@ wchar_t *wcsvarname( const wchar_t *str );
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Test if the given string is a valid function name.
|
Test if the given string is a valid function name.
|
||||||
|
|
||||||
\return null if this is a valid name, and a pointer to the first invalid character otherwise
|
\return null if this is a valid name, and a pointer to the first invalid character otherwise
|
||||||
*/
|
*/
|
||||||
|
@ -275,7 +275,7 @@ wchar_t *wcsvarname( const wchar_t *str );
|
||||||
wchar_t *wcsfuncname( const wchar_t *str );
|
wchar_t *wcsfuncname( const wchar_t *str );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Test if the given string is valid in a variable name
|
Test if the given string is valid in a variable name
|
||||||
|
|
||||||
\return 1 if this is a valid name, 0 otherwise
|
\return 1 if this is a valid name, 0 otherwise
|
||||||
*/
|
*/
|
||||||
|
@ -311,14 +311,14 @@ void error_reset();
|
||||||
This function behaves exactly like a wide character equivalent of
|
This function behaves exactly like a wide character equivalent of
|
||||||
the C function setlocale, except that it will also try to detect if
|
the C function setlocale, except that it will also try to detect if
|
||||||
the user is using a Unicode character set, and if so, use the
|
the user is using a Unicode character set, and if so, use the
|
||||||
unicode ellipsis character as ellipsis, instead of '$'.
|
unicode ellipsis character as ellipsis, instead of '$'.
|
||||||
*/
|
*/
|
||||||
const wchar_t *wsetlocale( int category, const wchar_t *locale );
|
const wchar_t *wsetlocale( int category, const wchar_t *locale );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Checks if \c needle is included in the list of strings specified. A warning is printed if needle is zero.
|
Checks if \c needle is included in the list of strings specified. A warning is printed if needle is zero.
|
||||||
|
|
||||||
\param needle the string to search for in the list
|
\param needle the string to search for in the list
|
||||||
|
|
||||||
\return zero if needle is not found, of if needle is null, non-zero otherwise
|
\return zero if needle is not found, of if needle is null, non-zero otherwise
|
||||||
*/
|
*/
|
||||||
|
@ -346,9 +346,9 @@ ssize_t write_loop(int fd, char *buff, size_t count);
|
||||||
Because debug is often called to tell the user about an error,
|
Because debug is often called to tell the user about an error,
|
||||||
before using wperror to give a specific error message, debug will
|
before using wperror to give a specific error message, debug will
|
||||||
never ever modify the value of errno.
|
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 level the priority of the message. Lower number means higher priority. Messages with a priority_number higher than \c debug_level will be ignored..
|
||||||
\param msg the message format string.
|
\param msg the message format string.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
@ -360,7 +360,7 @@ void debug( int level, const wchar_t *msg, ... );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Replace special characters with backslash escape sequences. Newline is
|
Replace special characters with backslash escape sequences. Newline is
|
||||||
replaced with \n, etc.
|
replaced with \n, etc.
|
||||||
|
|
||||||
\param in The string to be escaped
|
\param in The string to be escaped
|
||||||
\param escape_all Whether all characters wich hold special meaning in fish (Pipe, semicolon, etc,) should be escaped, or only unprintable characters
|
\param escape_all Whether all characters wich hold special meaning in fish (Pipe, semicolon, etc,) should be escaped, or only unprintable characters
|
||||||
|
@ -380,21 +380,21 @@ wchar_t *escape( const wchar_t *in, int escape_all );
|
||||||
an invalid sequence is specified, 0 is returned.
|
an invalid sequence is specified, 0 is returned.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
wchar_t *unescape( const wchar_t * in,
|
wchar_t *unescape( const wchar_t * in,
|
||||||
int escape_special );
|
int escape_special );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Attempt to acquire a lock based on a lockfile, waiting LOCKPOLLINTERVAL
|
Attempt to acquire a lock based on a lockfile, waiting LOCKPOLLINTERVAL
|
||||||
milliseconds between polls and timing out after timeout seconds,
|
milliseconds between polls and timing out after timeout seconds,
|
||||||
thereafter forcibly attempting to obtain the lock if force is non-zero.
|
thereafter forcibly attempting to obtain the lock if force is non-zero.
|
||||||
Returns 1 on success, 0 on failure.
|
Returns 1 on success, 0 on failure.
|
||||||
To release the lock the lockfile must be unlinked.
|
To release the lock the lockfile must be unlinked.
|
||||||
A unique temporary file named by appending characters to the lockfile name
|
A unique temporary file named by appending characters to the lockfile name
|
||||||
is used; any pre-existing file of the same name is subject to deletion.
|
is used; any pre-existing file of the same name is subject to deletion.
|
||||||
*/
|
*/
|
||||||
int acquire_lock_file( const char *lockfile, const int timeout, int force );
|
int acquire_lock_file( const char *lockfile, const int timeout, int force );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the width of the terminal window, so that not all
|
Returns the width of the terminal window, so that not all
|
||||||
functions that use these values continually have to keep track of
|
functions that use these values continually have to keep track of
|
||||||
it separately.
|
it separately.
|
||||||
|
@ -428,9 +428,9 @@ void write_screen( const wchar_t *msg, string_buffer_t *buff );
|
||||||
Tokenize the specified string into the specified array_list_t.
|
Tokenize the specified string into the specified array_list_t.
|
||||||
Each new element is allocated using malloc and must be freed by the
|
Each new element is allocated using malloc and must be freed by the
|
||||||
caller.
|
caller.
|
||||||
|
|
||||||
\param val the input string. The contents of this string is not changed.
|
\param val the input string. The contents of this string is not changed.
|
||||||
\param out the list in which to place the elements.
|
\param out the list in which to place the elements.
|
||||||
*/
|
*/
|
||||||
void tokenize_variable_array( const wchar_t *val, array_list_t *out );
|
void tokenize_variable_array( const wchar_t *val, array_list_t *out );
|
||||||
|
|
||||||
|
|
300
complete.c
300
complete.c
|
@ -124,7 +124,7 @@
|
||||||
If either short_opt or long_opt are non-zero, they specify a switch
|
If either short_opt or long_opt are non-zero, they specify a switch
|
||||||
for the command. If \c comp is also not empty, it contains a list
|
for the command. If \c comp is also not empty, it contains a list
|
||||||
of non-switch arguments that may only follow directly after the
|
of non-switch arguments that may only follow directly after the
|
||||||
specified switch.
|
specified switch.
|
||||||
*/
|
*/
|
||||||
typedef struct complete_entry_opt
|
typedef struct complete_entry_opt
|
||||||
{
|
{
|
||||||
|
@ -202,12 +202,12 @@ void completion_allocate( array_list_t *context,
|
||||||
int len = wcslen(comp);
|
int len = wcslen(comp);
|
||||||
|
|
||||||
flags = flags & (~COMPLETE_AUTO_SPACE);
|
flags = flags & (~COMPLETE_AUTO_SPACE);
|
||||||
|
|
||||||
if( ( len > 0 ) && ( wcschr( L"/=@:", comp[ len - 1 ] ) != 0 ) )
|
if( ( len > 0 ) && ( wcschr( L"/=@:", comp[ len - 1 ] ) != 0 ) )
|
||||||
flags |= COMPLETE_NO_SPACE;
|
flags |= COMPLETE_NO_SPACE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res->flags = flags;
|
res->flags = flags;
|
||||||
al_push( context, res );
|
al_push( context, res );
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ void completion_allocate( array_list_t *context,
|
||||||
static void complete_destroy()
|
static void complete_destroy()
|
||||||
{
|
{
|
||||||
complete_entry_t *i=first_entry, *prev;
|
complete_entry_t *i=first_entry, *prev;
|
||||||
|
|
||||||
while( i )
|
while( i )
|
||||||
{
|
{
|
||||||
prev = i;
|
prev = i;
|
||||||
|
@ -226,9 +226,9 @@ static void complete_destroy()
|
||||||
complete_free_entry( prev );
|
complete_free_entry( prev );
|
||||||
}
|
}
|
||||||
first_entry = 0;
|
first_entry = 0;
|
||||||
|
|
||||||
parse_util_load_reset( L"fish_complete_path", 0 );
|
parse_util_load_reset( L"fish_complete_path", 0 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -318,7 +318,7 @@ static void complete_free_opt_recursive( complete_entry_opt_t *o )
|
||||||
{
|
{
|
||||||
if( !o )
|
if( !o )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
complete_free_opt_recursive( o->next );
|
complete_free_opt_recursive( o->next );
|
||||||
halloc_free( o );
|
halloc_free( o );
|
||||||
}
|
}
|
||||||
|
@ -369,7 +369,7 @@ static complete_entry_t *complete_get_exact_entry( const wchar_t *cmd,
|
||||||
{
|
{
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
}
|
}
|
||||||
|
|
||||||
c->next = first_entry;
|
c->next = first_entry;
|
||||||
first_entry = c;
|
first_entry = c;
|
||||||
|
|
||||||
|
@ -416,7 +416,7 @@ void complete_add( const wchar_t *cmd,
|
||||||
c = complete_get_exact_entry( cmd, cmd_type );
|
c = complete_get_exact_entry( cmd, cmd_type );
|
||||||
|
|
||||||
opt = halloc( 0, sizeof( complete_entry_opt_t ) );
|
opt = halloc( 0, sizeof( complete_entry_opt_t ) );
|
||||||
|
|
||||||
opt->next = c->first_option;
|
opt->next = c->first_option;
|
||||||
c->first_option = opt;
|
c->first_option = opt;
|
||||||
if( short_opt != L'\0' )
|
if( short_opt != L'\0' )
|
||||||
|
@ -432,7 +432,7 @@ void complete_add( const wchar_t *cmd,
|
||||||
wcscat( c->short_opt_str, L":" );
|
wcscat( c->short_opt_str, L":" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
opt->short_opt = short_opt;
|
opt->short_opt = short_opt;
|
||||||
opt->result_mode = result_mode;
|
opt->result_mode = result_mode;
|
||||||
opt->old_mode=old_mode;
|
opt->old_mode=old_mode;
|
||||||
|
@ -441,7 +441,7 @@ void complete_add( const wchar_t *cmd,
|
||||||
opt->condition = condition?halloc_wcsdup(opt, condition):L"";
|
opt->condition = condition?halloc_wcsdup(opt, condition):L"";
|
||||||
opt->long_opt = long_opt?halloc_wcsdup(opt, long_opt):L"" ;
|
opt->long_opt = long_opt?halloc_wcsdup(opt, long_opt):L"" ;
|
||||||
opt->flags = flags;
|
opt->flags = flags;
|
||||||
|
|
||||||
if( desc && wcslen( desc ) )
|
if( desc && wcslen( desc ) )
|
||||||
{
|
{
|
||||||
opt->desc = halloc_wcsdup( opt, desc );
|
opt->desc = halloc_wcsdup( opt, desc );
|
||||||
|
@ -450,7 +450,7 @@ void complete_add( const wchar_t *cmd,
|
||||||
{
|
{
|
||||||
opt->desc = L"";
|
opt->desc = L"";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -463,7 +463,7 @@ static complete_entry_t *complete_remove_entry( complete_entry_t *e,
|
||||||
{
|
{
|
||||||
|
|
||||||
complete_entry_opt_t *o, *oprev=0, *onext=0;
|
complete_entry_opt_t *o, *oprev=0, *onext=0;
|
||||||
|
|
||||||
if(( short_opt == 0 ) && (long_opt == 0 ) )
|
if(( short_opt == 0 ) && (long_opt == 0 ) )
|
||||||
{
|
{
|
||||||
complete_free_opt_recursive( e->first_option );
|
complete_free_opt_recursive( e->first_option );
|
||||||
|
@ -471,11 +471,11 @@ static complete_entry_t *complete_remove_entry( complete_entry_t *e,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
for( o= e->first_option; o; o=onext )
|
for( o= e->first_option; o; o=onext )
|
||||||
{
|
{
|
||||||
onext=o->next;
|
onext=o->next;
|
||||||
|
|
||||||
if( ( short_opt==o->short_opt ) ||
|
if( ( short_opt==o->short_opt ) ||
|
||||||
( wcscmp( long_opt, o->long_opt ) == 0 ) )
|
( wcscmp( long_opt, o->long_opt ) == 0 ) )
|
||||||
{
|
{
|
||||||
|
@ -496,13 +496,13 @@ static complete_entry_t *complete_remove_entry( complete_entry_t *e,
|
||||||
{
|
{
|
||||||
pos2++;
|
pos2++;
|
||||||
}
|
}
|
||||||
|
|
||||||
memmove( pos,
|
memmove( pos,
|
||||||
pos2,
|
pos2,
|
||||||
sizeof(wchar_t)*wcslen(pos2) );
|
sizeof(wchar_t)*wcslen(pos2) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( oprev == 0 )
|
if( oprev == 0 )
|
||||||
{
|
{
|
||||||
e->first_option = o->next;
|
e->first_option = o->next;
|
||||||
|
@ -519,14 +519,14 @@ static complete_entry_t *complete_remove_entry( complete_entry_t *e,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( e && (e->first_option == 0) )
|
if( e && (e->first_option == 0) )
|
||||||
{
|
{
|
||||||
free( e->short_opt_str );
|
free( e->short_opt_str );
|
||||||
free( e );
|
free( e );
|
||||||
e=0;
|
e=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -540,7 +540,7 @@ void complete_remove( const wchar_t *cmd,
|
||||||
complete_entry_t *e, *eprev=0, *enext=0;
|
complete_entry_t *e, *eprev=0, *enext=0;
|
||||||
|
|
||||||
CHECK( cmd, );
|
CHECK( cmd, );
|
||||||
|
|
||||||
for( e = first_entry; e; e=enext )
|
for( e = first_entry; e; e=enext )
|
||||||
{
|
{
|
||||||
enext=e->next;
|
enext=e->next;
|
||||||
|
@ -566,7 +566,7 @@ void complete_remove( const wchar_t *cmd,
|
||||||
first_entry = enext;
|
first_entry = enext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -575,7 +575,7 @@ void complete_remove( const wchar_t *cmd,
|
||||||
pointers are allocated using halloc and will be free'd when\c
|
pointers are allocated using halloc and will be free'd when\c
|
||||||
context is halloc_free'd.
|
context is halloc_free'd.
|
||||||
*/
|
*/
|
||||||
static void parse_cmd_string( void *context,
|
static void parse_cmd_string( void *context,
|
||||||
const wchar_t *str,
|
const wchar_t *str,
|
||||||
wchar_t **pathp,
|
wchar_t **pathp,
|
||||||
wchar_t **cmdp )
|
wchar_t **cmdp )
|
||||||
|
@ -592,7 +592,7 @@ static void parse_cmd_string( void *context,
|
||||||
*/
|
*/
|
||||||
path = halloc_wcsdup( context, L"");
|
path = halloc_wcsdup( context, L"");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure the path is not included in the command */
|
/* Make sure the path is not included in the command */
|
||||||
cmd = wcsrchr( str, L'/' );
|
cmd = wcsrchr( str, L'/' );
|
||||||
if( cmd != 0 )
|
if( cmd != 0 )
|
||||||
|
@ -603,7 +603,7 @@ static void parse_cmd_string( void *context,
|
||||||
{
|
{
|
||||||
cmd = (wchar_t *)str;
|
cmd = (wchar_t *)str;
|
||||||
}
|
}
|
||||||
|
|
||||||
*pathp=path;
|
*pathp=path;
|
||||||
*cmdp=cmd;
|
*cmdp=cmd;
|
||||||
}
|
}
|
||||||
|
@ -627,10 +627,10 @@ int complete_is_valid_option( const wchar_t *str,
|
||||||
char *short_validated;
|
char *short_validated;
|
||||||
|
|
||||||
void *context;
|
void *context;
|
||||||
|
|
||||||
CHECK( str, 0 );
|
CHECK( str, 0 );
|
||||||
CHECK( opt, 0 );
|
CHECK( opt, 0 );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Check some generic things like -- and - options.
|
Check some generic things like -- and - options.
|
||||||
*/
|
*/
|
||||||
|
@ -642,7 +642,7 @@ int complete_is_valid_option( const wchar_t *str,
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
if( wcscmp( L"--", opt ) == 0 )
|
if( wcscmp( L"--", opt ) == 0 )
|
||||||
|
@ -652,7 +652,7 @@ int complete_is_valid_option( const wchar_t *str,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( opt[0] != L'-' )
|
if( opt[0] != L'-' )
|
||||||
{
|
{
|
||||||
if( errors )
|
if( errors )
|
||||||
|
@ -668,7 +668,7 @@ int complete_is_valid_option( const wchar_t *str,
|
||||||
{
|
{
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
memset( short_validated, 0, wcslen( opt ) );
|
memset( short_validated, 0, wcslen( opt ) );
|
||||||
|
@ -690,14 +690,14 @@ int complete_is_valid_option( const wchar_t *str,
|
||||||
gnu_opt_len = wcslen(opt)-2;
|
gnu_opt_len = wcslen(opt)-2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_cmd_string( context, str, &path, &cmd );
|
parse_cmd_string( context, str, &path, &cmd );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Make sure completions are loaded for the specified command
|
Make sure completions are loaded for the specified command
|
||||||
*/
|
*/
|
||||||
complete_load( cmd, 0 );
|
complete_load( cmd, 0 );
|
||||||
|
|
||||||
for( i=first_entry; i; i=i->next )
|
for( i=first_entry; i; i=i->next )
|
||||||
{
|
{
|
||||||
wchar_t *match = i->cmd_type?path:cmd;
|
wchar_t *match = i->cmd_type?path:cmd;
|
||||||
|
@ -707,7 +707,7 @@ int complete_is_valid_option( const wchar_t *str,
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
found_match = 1;
|
found_match = 1;
|
||||||
|
|
||||||
if( !i->authoritative )
|
if( !i->authoritative )
|
||||||
|
@ -726,7 +726,7 @@ int complete_is_valid_option( const wchar_t *str,
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( wcsncmp( &opt[2], o->long_opt, gnu_opt_len )==0)
|
if( wcsncmp( &opt[2], o->long_opt, gnu_opt_len )==0)
|
||||||
{
|
{
|
||||||
hash_put( &gnu_match_hash, o->long_opt, L"" );
|
hash_put( &gnu_match_hash, o->long_opt, L"" );
|
||||||
|
@ -845,7 +845,7 @@ int complete_is_valid_option( const wchar_t *str,
|
||||||
hash_destroy( &gnu_match_hash );
|
hash_destroy( &gnu_match_hash );
|
||||||
|
|
||||||
halloc_free( context );
|
halloc_free( context );
|
||||||
|
|
||||||
return (authoritative && found_match)?opt_found:1;
|
return (authoritative && found_match)?opt_found:1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -893,7 +893,7 @@ static void complete_strings( array_list_t *comp_out,
|
||||||
|
|
||||||
wc = parse_util_unescape_wildcards( tmp );
|
wc = parse_util_unescape_wildcards( tmp );
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
|
||||||
for( i=0; i<al_get_count( possible_comp ); i++ )
|
for( i=0; i<al_get_count( possible_comp ); i++ )
|
||||||
{
|
{
|
||||||
wchar_t *next_str = (wchar_t *)al_get( possible_comp, i );
|
wchar_t *next_str = (wchar_t *)al_get( possible_comp, i );
|
||||||
|
@ -921,7 +921,7 @@ static void complete_cmd_desc( const wchar_t *cmd, array_list_t *comp )
|
||||||
hash_table_t lookup;
|
hash_table_t lookup;
|
||||||
wchar_t *esc;
|
wchar_t *esc;
|
||||||
int skip;
|
int skip;
|
||||||
|
|
||||||
if( !cmd )
|
if( !cmd )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -948,24 +948,24 @@ static void complete_cmd_desc( const wchar_t *cmd, array_list_t *comp )
|
||||||
}
|
}
|
||||||
|
|
||||||
skip = 1;
|
skip = 1;
|
||||||
|
|
||||||
for( i=0; i<al_get_count( comp ); i++ )
|
for( i=0; i<al_get_count( comp ); i++ )
|
||||||
{
|
{
|
||||||
completion_t *c = (completion_t *)al_get( comp, i );
|
completion_t *c = (completion_t *)al_get( comp, i );
|
||||||
|
|
||||||
if( !wcslen( c->completion) || (c->completion[wcslen(c->completion)-1] != L'/' ))
|
if( !wcslen( c->completion) || (c->completion[wcslen(c->completion)-1] != L'/' ))
|
||||||
{
|
{
|
||||||
skip = 0;
|
skip = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( skip )
|
if( skip )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
esc = escape( cmd_start, 1 );
|
esc = escape( cmd_start, 1 );
|
||||||
|
|
||||||
|
@ -985,7 +985,7 @@ static void complete_cmd_desc( const wchar_t *cmd, array_list_t *comp )
|
||||||
*/
|
*/
|
||||||
if( exec_subshell( lookup_cmd, &list ) != -1 )
|
if( exec_subshell( lookup_cmd, &list ) != -1 )
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Then discard anything that is not a possible completion and put
|
Then discard anything that is not a possible completion and put
|
||||||
the result into a hashtable with the completion as key and the
|
the result into a hashtable with the completion as key and the
|
||||||
|
@ -997,7 +997,7 @@ static void complete_cmd_desc( const wchar_t *cmd, array_list_t *comp )
|
||||||
{
|
{
|
||||||
wchar_t *el = (wchar_t *)al_get( &list, i );
|
wchar_t *el = (wchar_t *)al_get( &list, i );
|
||||||
wchar_t *key, *key_end, *val_begin;
|
wchar_t *key, *key_end, *val_begin;
|
||||||
|
|
||||||
if( !el )
|
if( !el )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -1006,7 +1006,7 @@ static void complete_cmd_desc( const wchar_t *cmd, array_list_t *comp )
|
||||||
|
|
||||||
if( !key_end )
|
if( !key_end )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
*key_end = 0;
|
*key_end = 0;
|
||||||
val_begin = key_end+1;
|
val_begin = key_end+1;
|
||||||
|
|
||||||
|
@ -1016,7 +1016,7 @@ static void complete_cmd_desc( const wchar_t *cmd, array_list_t *comp )
|
||||||
things.
|
things.
|
||||||
*/
|
*/
|
||||||
val_begin[0]=towupper(val_begin[0]);
|
val_begin[0]=towupper(val_begin[0]);
|
||||||
|
|
||||||
hash_put( &lookup, key, val_begin );
|
hash_put( &lookup, key, val_begin );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1031,19 +1031,19 @@ static void complete_cmd_desc( const wchar_t *cmd, array_list_t *comp )
|
||||||
{
|
{
|
||||||
completion_t *c = (completion_t *)al_get( comp, i );
|
completion_t *c = (completion_t *)al_get( comp, i );
|
||||||
const wchar_t *el = c->completion;
|
const wchar_t *el = c->completion;
|
||||||
|
|
||||||
wchar_t *new_desc;
|
wchar_t *new_desc;
|
||||||
|
|
||||||
new_desc = (wchar_t *)hash_get( &lookup,
|
new_desc = (wchar_t *)hash_get( &lookup,
|
||||||
el );
|
el );
|
||||||
|
|
||||||
if( new_desc )
|
if( new_desc )
|
||||||
{
|
{
|
||||||
c->description = halloc_wcsdup( comp, new_desc );
|
c->description = halloc_wcsdup( comp, new_desc );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hash_destroy( &lookup );
|
hash_destroy( &lookup );
|
||||||
al_foreach( &list,
|
al_foreach( &list,
|
||||||
&free );
|
&free );
|
||||||
|
@ -1095,7 +1095,7 @@ static void complete_cmd( const wchar_t *cmd,
|
||||||
|
|
||||||
if( use_command )
|
if( use_command )
|
||||||
{
|
{
|
||||||
|
|
||||||
if( expand_string( 0,
|
if( expand_string( 0,
|
||||||
wcsdup(cmd),
|
wcsdup(cmd),
|
||||||
comp,
|
comp,
|
||||||
|
@ -1109,13 +1109,13 @@ static void complete_cmd( const wchar_t *cmd,
|
||||||
{
|
{
|
||||||
if( use_command )
|
if( use_command )
|
||||||
{
|
{
|
||||||
|
|
||||||
path = env_get(L"PATH");
|
path = env_get(L"PATH");
|
||||||
if( path )
|
if( path )
|
||||||
{
|
{
|
||||||
|
|
||||||
path_cpy = wcsdup( path );
|
path_cpy = wcsdup( path );
|
||||||
|
|
||||||
for( nxt_path = wcstok( path_cpy, ARRAY_SEP_STR, &state );
|
for( nxt_path = wcstok( path_cpy, ARRAY_SEP_STR, &state );
|
||||||
nxt_path != 0;
|
nxt_path != 0;
|
||||||
nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) )
|
nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) )
|
||||||
|
@ -1124,21 +1124,21 @@ static void complete_cmd( const wchar_t *cmd,
|
||||||
int i;
|
int i;
|
||||||
int path_len = wcslen(nxt_path);
|
int path_len = wcslen(nxt_path);
|
||||||
int add_slash;
|
int add_slash;
|
||||||
|
|
||||||
if( !path_len )
|
if( !path_len )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
add_slash = nxt_path[path_len-1]!=L'/';
|
add_slash = nxt_path[path_len-1]!=L'/';
|
||||||
nxt_completion = wcsdupcat( nxt_path,
|
nxt_completion = wcsdupcat( nxt_path,
|
||||||
add_slash?L"/":L"",
|
add_slash?L"/":L"",
|
||||||
cmd );
|
cmd );
|
||||||
if( ! nxt_completion )
|
if( ! nxt_completion )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
prev_count = al_get_count( comp );
|
prev_count = al_get_count( comp );
|
||||||
|
|
||||||
if( expand_string( 0,
|
if( expand_string( 0,
|
||||||
nxt_completion,
|
nxt_completion,
|
||||||
comp,
|
comp,
|
||||||
|
@ -1159,7 +1159,7 @@ static void complete_cmd( const wchar_t *cmd,
|
||||||
complete_cmd_desc( cmd, comp );
|
complete_cmd_desc( cmd, comp );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
These return the original strings - don't free them
|
These return the original strings - don't free them
|
||||||
*/
|
*/
|
||||||
|
@ -1173,7 +1173,7 @@ static void complete_cmd( const wchar_t *cmd,
|
||||||
}
|
}
|
||||||
|
|
||||||
al_truncate( &possible_comp, 0 );
|
al_truncate( &possible_comp, 0 );
|
||||||
|
|
||||||
if( use_builtin )
|
if( use_builtin )
|
||||||
{
|
{
|
||||||
builtin_get_names( &possible_comp );
|
builtin_get_names( &possible_comp );
|
||||||
|
@ -1202,7 +1202,7 @@ static void complete_cmd( const wchar_t *cmd,
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( expand_string( 0,
|
if( expand_string( 0,
|
||||||
nxt_completion,
|
nxt_completion,
|
||||||
comp,
|
comp,
|
||||||
|
@ -1242,7 +1242,7 @@ static void complete_from_args( const wchar_t *str,
|
||||||
proc_push_interactive(0);
|
proc_push_interactive(0);
|
||||||
eval_args( args, &possible_comp );
|
eval_args( args, &possible_comp );
|
||||||
proc_pop_interactive();
|
proc_pop_interactive();
|
||||||
|
|
||||||
complete_strings( comp_out, str, desc, 0, &possible_comp, flags );
|
complete_strings( comp_out, str, desc, 0, &possible_comp, flags );
|
||||||
|
|
||||||
al_foreach( &possible_comp, &free );
|
al_foreach( &possible_comp, &free );
|
||||||
|
@ -1355,10 +1355,10 @@ static void complete_load_handler( const wchar_t *cmd )
|
||||||
void complete_load( const wchar_t *name, int reload )
|
void complete_load( const wchar_t *name, int reload )
|
||||||
{
|
{
|
||||||
CHECK( name, );
|
CHECK( name, );
|
||||||
parse_util_load( name,
|
parse_util_load( name,
|
||||||
L"fish_complete_path",
|
L"fish_complete_path",
|
||||||
&complete_load_handler,
|
&complete_load_handler,
|
||||||
reload );
|
reload );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1380,7 +1380,7 @@ static int complete_param( const wchar_t *cmd_orig,
|
||||||
int use_common=1, use_files=1;
|
int use_common=1, use_files=1;
|
||||||
|
|
||||||
void *context = halloc( 0, 0 );
|
void *context = halloc( 0, 0 );
|
||||||
|
|
||||||
parse_cmd_string( context, cmd_orig, &path, &cmd );
|
parse_cmd_string( context, cmd_orig, &path, &cmd );
|
||||||
|
|
||||||
complete_load( cmd, 1 );
|
complete_load( cmd, 1 );
|
||||||
|
@ -1395,11 +1395,11 @@ static int complete_param( const wchar_t *cmd_orig,
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
use_common=1;
|
use_common=1;
|
||||||
if( use_switches )
|
if( use_switches )
|
||||||
{
|
{
|
||||||
|
|
||||||
if( str[0] == L'-' )
|
if( str[0] == L'-' )
|
||||||
{
|
{
|
||||||
/* Check if we are entering a combined option and argument
|
/* Check if we are entering a combined option and argument
|
||||||
|
@ -1420,7 +1420,7 @@ static int complete_param( const wchar_t *cmd_orig,
|
||||||
{
|
{
|
||||||
/* Set to true if we found a matching old-style switch */
|
/* Set to true if we found a matching old-style switch */
|
||||||
int old_style_match = 0;
|
int old_style_match = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
If we are using old style long options, check for them
|
If we are using old style long options, check for them
|
||||||
first
|
first
|
||||||
|
@ -1438,7 +1438,7 @@ static int complete_param( const wchar_t *cmd_orig,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
No old style option matched, or we are not using old
|
No old style option matched, or we are not using old
|
||||||
style options. We check if any short (or gnu style
|
style options. We check if any short (or gnu style
|
||||||
|
@ -1467,7 +1467,7 @@ static int complete_param( const wchar_t *cmd_orig,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( use_common )
|
if( use_common )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -1487,7 +1487,7 @@ static int complete_param( const wchar_t *cmd_orig,
|
||||||
use_files &= ((o->result_mode & NO_FILES )==0);
|
use_files &= ((o->result_mode & NO_FILES )==0);
|
||||||
complete_from_args( str, o->comp, C_(o->desc), comp_out, o->flags );
|
complete_from_args( str, o->comp, C_(o->desc), comp_out, o->flags );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( wcslen(str) > 0 && use_switches )
|
if( wcslen(str) > 0 && use_switches )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -1500,7 +1500,7 @@ static int complete_param( const wchar_t *cmd_orig,
|
||||||
wchar_t completion[2];
|
wchar_t completion[2];
|
||||||
completion[0] = o->short_opt;
|
completion[0] = o->short_opt;
|
||||||
completion[1] = 0;
|
completion[1] = 0;
|
||||||
|
|
||||||
completion_allocate( comp_out, completion, desc, 0 );
|
completion_allocate( comp_out, completion, desc, 0 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1511,7 +1511,7 @@ static int complete_param( const wchar_t *cmd_orig,
|
||||||
if( o->long_opt[0] != L'\0' )
|
if( o->long_opt[0] != L'\0' )
|
||||||
{
|
{
|
||||||
int match=0, match_no_case=0;
|
int match=0, match_no_case=0;
|
||||||
|
|
||||||
string_buffer_t *whole_opt = sb_halloc( context );
|
string_buffer_t *whole_opt = sb_halloc( context );
|
||||||
sb_append( whole_opt, o->old_mode?L"-":L"--", o->long_opt, (void *)0 );
|
sb_append( whole_opt, o->old_mode?L"-":L"--", o->long_opt, (void *)0 );
|
||||||
|
|
||||||
|
@ -1521,7 +1521,7 @@ static int complete_param( const wchar_t *cmd_orig,
|
||||||
{
|
{
|
||||||
match_no_case = wcsncasecmp( str, (wchar_t *)whole_opt->buff, wcslen(str) )==0;
|
match_no_case = wcsncasecmp( str, (wchar_t *)whole_opt->buff, wcslen(str) )==0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( match || match_no_case )
|
if( match || match_no_case )
|
||||||
{
|
{
|
||||||
int has_arg=0; /* Does this switch have any known arguments */
|
int has_arg=0; /* Does this switch have any known arguments */
|
||||||
|
@ -1530,7 +1530,7 @@ static int complete_param( const wchar_t *cmd_orig,
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
|
|
||||||
|
|
||||||
if( match )
|
if( match )
|
||||||
offset = wcslen( str );
|
offset = wcslen( str );
|
||||||
else
|
else
|
||||||
|
@ -1541,7 +1541,7 @@ static int complete_param( const wchar_t *cmd_orig,
|
||||||
|
|
||||||
if( !o->old_mode && ( has_arg && !req_arg ) )
|
if( !o->old_mode && ( has_arg && !req_arg ) )
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Optional arguments to a switch can
|
Optional arguments to a switch can
|
||||||
only be handled using the '=', so we
|
only be handled using the '=', so we
|
||||||
|
@ -1555,31 +1555,31 @@ static int complete_param( const wchar_t *cmd_orig,
|
||||||
sb_init( &completion );
|
sb_init( &completion );
|
||||||
|
|
||||||
sb_printf( &completion,
|
sb_printf( &completion,
|
||||||
L"%ls=",
|
L"%ls=",
|
||||||
((wchar_t *)whole_opt->buff)+offset );
|
((wchar_t *)whole_opt->buff)+offset );
|
||||||
|
|
||||||
completion_allocate( comp_out,
|
completion_allocate( comp_out,
|
||||||
(wchar_t *)completion.buff,
|
(wchar_t *)completion.buff,
|
||||||
C_(o->desc),
|
C_(o->desc),
|
||||||
flags );
|
flags );
|
||||||
|
|
||||||
sb_destroy( &completion );
|
sb_destroy( &completion );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
completion_allocate( comp_out,
|
completion_allocate( comp_out,
|
||||||
((wchar_t *)whole_opt->buff) + offset,
|
((wchar_t *)whole_opt->buff) + offset,
|
||||||
C_(o->desc),
|
C_(o->desc),
|
||||||
flags );
|
flags );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
halloc_free( context );
|
halloc_free( context );
|
||||||
|
|
||||||
return use_files;
|
return use_files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1592,7 +1592,7 @@ static void complete_param_expand( wchar_t *str,
|
||||||
{
|
{
|
||||||
wchar_t *comp_str;
|
wchar_t *comp_str;
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
if( (wcsncmp( str, L"--", 2 )) == 0 && (comp_str = wcschr(str, L'=' ) ) )
|
if( (wcsncmp( str, L"--", 2 )) == 0 && (comp_str = wcschr(str, L'=' ) ) )
|
||||||
{
|
{
|
||||||
comp_str++;
|
comp_str++;
|
||||||
|
@ -1602,18 +1602,18 @@ static void complete_param_expand( wchar_t *str,
|
||||||
comp_str = str;
|
comp_str = str;
|
||||||
}
|
}
|
||||||
|
|
||||||
flags = EXPAND_SKIP_CMDSUBST |
|
flags = EXPAND_SKIP_CMDSUBST |
|
||||||
ACCEPT_INCOMPLETE |
|
ACCEPT_INCOMPLETE |
|
||||||
(do_file?0:EXPAND_SKIP_WILDCARDS);
|
(do_file?0:EXPAND_SKIP_WILDCARDS);
|
||||||
|
|
||||||
if( expand_string( 0,
|
if( expand_string( 0,
|
||||||
wcsdup(comp_str),
|
wcsdup(comp_str),
|
||||||
comp_out,
|
comp_out,
|
||||||
flags ) == EXPAND_ERROR )
|
flags ) == EXPAND_ERROR )
|
||||||
{
|
{
|
||||||
debug( 3, L"Error while expanding string '%ls'", comp_str );
|
debug( 3, L"Error while expanding string '%ls'", comp_str );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1636,13 +1636,13 @@ static int complete_variable( const wchar_t *whole_var,
|
||||||
{
|
{
|
||||||
wchar_t *name = (wchar_t *)al_get( &names, i );
|
wchar_t *name = (wchar_t *)al_get( &names, i );
|
||||||
int namelen = wcslen( name );
|
int namelen = wcslen( name );
|
||||||
int match=0, match_no_case=0;
|
int match=0, match_no_case=0;
|
||||||
|
|
||||||
if( varlen > namelen )
|
if( varlen > namelen )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
match = ( wcsncmp( var, name, varlen) == 0 );
|
match = ( wcsncmp( var, name, varlen) == 0 );
|
||||||
|
|
||||||
if( !match )
|
if( !match )
|
||||||
{
|
{
|
||||||
match_no_case = ( wcsncasecmp( var, name, varlen) == 0 );
|
match_no_case = ( wcsncasecmp( var, name, varlen) == 0 );
|
||||||
|
@ -1659,11 +1659,11 @@ static int complete_variable( const wchar_t *whole_var,
|
||||||
string_buffer_t comp;
|
string_buffer_t comp;
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
sb_init( &comp );
|
sb_init( &comp );
|
||||||
if( match )
|
if( match )
|
||||||
{
|
{
|
||||||
sb_append( &comp, &name[varlen] );
|
sb_append( &comp, &name[varlen] );
|
||||||
offset = varlen;
|
offset = varlen;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1672,23 +1672,23 @@ static int complete_variable( const wchar_t *whole_var,
|
||||||
sb_append( &comp, name );
|
sb_append( &comp, name );
|
||||||
flags = COMPLETE_NO_CASE | COMPLETE_DONT_ESCAPE;
|
flags = COMPLETE_NO_CASE | COMPLETE_DONT_ESCAPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = expand_escape_variable( value_unescaped );
|
value = expand_escape_variable( value_unescaped );
|
||||||
|
|
||||||
sb_init( &desc );
|
sb_init( &desc );
|
||||||
sb_printf( &desc, COMPLETE_VAR_DESC_VAL, value );
|
sb_printf( &desc, COMPLETE_VAR_DESC_VAL, value );
|
||||||
|
|
||||||
completion_allocate( comp_list,
|
completion_allocate( comp_list,
|
||||||
(wchar_t *)comp.buff,
|
(wchar_t *)comp.buff,
|
||||||
(wchar_t *)desc.buff,
|
(wchar_t *)desc.buff,
|
||||||
flags );
|
flags );
|
||||||
res =1;
|
res =1;
|
||||||
|
|
||||||
free( value );
|
free( value );
|
||||||
sb_destroy( &desc );
|
sb_destroy( &desc );
|
||||||
sb_destroy( &comp );
|
sb_destroy( &comp );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1698,7 +1698,7 @@ static int complete_variable( const wchar_t *whole_var,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Search the specified string for the \$ sign. If found, try to
|
Search the specified string for the \$ sign. If found, try to
|
||||||
complete as an environment variable.
|
complete as an environment variable.
|
||||||
|
|
||||||
\return 0 if unable to complete, 1 otherwise
|
\return 0 if unable to complete, 1 otherwise
|
||||||
*/
|
*/
|
||||||
|
@ -1735,7 +1735,7 @@ static int try_complete_user( const wchar_t *cmd,
|
||||||
const wchar_t *first_char=cmd;
|
const wchar_t *first_char=cmd;
|
||||||
int res=0;
|
int res=0;
|
||||||
double start_time = timef();
|
double start_time = timef();
|
||||||
|
|
||||||
if( *first_char ==L'~' && !wcschr(first_char, L'/'))
|
if( *first_char ==L'~' && !wcschr(first_char, L'/'))
|
||||||
{
|
{
|
||||||
const wchar_t *user_name = first_char+1;
|
const wchar_t *user_name = first_char+1;
|
||||||
|
@ -1744,19 +1744,19 @@ static int try_complete_user( const wchar_t *cmd,
|
||||||
{
|
{
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
int name_len = wcslen( user_name );
|
int name_len = wcslen( user_name );
|
||||||
|
|
||||||
setpwent();
|
setpwent();
|
||||||
|
|
||||||
while((pw=getpwent()) != 0)
|
while((pw=getpwent()) != 0)
|
||||||
{
|
{
|
||||||
double current_time = timef();
|
double current_time = timef();
|
||||||
wchar_t *pw_name;
|
wchar_t *pw_name;
|
||||||
|
|
||||||
if( current_time - start_time > 0.2 )
|
if( current_time - start_time > 0.2 )
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pw_name = str2wcs( pw->pw_name );
|
pw_name = str2wcs( pw->pw_name );
|
||||||
|
|
||||||
if( pw_name )
|
if( pw_name )
|
||||||
|
@ -1764,26 +1764,26 @@ static int try_complete_user( const wchar_t *cmd,
|
||||||
if( wcsncmp( user_name, pw_name, name_len )==0 )
|
if( wcsncmp( user_name, pw_name, name_len )==0 )
|
||||||
{
|
{
|
||||||
string_buffer_t desc;
|
string_buffer_t desc;
|
||||||
|
|
||||||
sb_init( &desc );
|
sb_init( &desc );
|
||||||
sb_printf( &desc,
|
sb_printf( &desc,
|
||||||
COMPLETE_USER_DESC,
|
COMPLETE_USER_DESC,
|
||||||
pw_name );
|
pw_name );
|
||||||
|
|
||||||
completion_allocate( comp,
|
completion_allocate( comp,
|
||||||
&pw_name[name_len],
|
&pw_name[name_len],
|
||||||
(wchar_t *)desc.buff,
|
(wchar_t *)desc.buff,
|
||||||
COMPLETE_NO_SPACE );
|
COMPLETE_NO_SPACE );
|
||||||
|
|
||||||
res=1;
|
res=1;
|
||||||
|
|
||||||
sb_destroy( &desc );
|
sb_destroy( &desc );
|
||||||
}
|
}
|
||||||
else if( wcsncasecmp( user_name, pw_name, name_len )==0 )
|
else if( wcsncasecmp( user_name, pw_name, name_len )==0 )
|
||||||
{
|
{
|
||||||
string_buffer_t name;
|
string_buffer_t name;
|
||||||
string_buffer_t desc;
|
string_buffer_t desc;
|
||||||
|
|
||||||
sb_init( &name );
|
sb_init( &name );
|
||||||
sb_init( &desc );
|
sb_init( &desc );
|
||||||
sb_printf( &name,
|
sb_printf( &name,
|
||||||
|
@ -1792,16 +1792,16 @@ static int try_complete_user( const wchar_t *cmd,
|
||||||
sb_printf( &desc,
|
sb_printf( &desc,
|
||||||
COMPLETE_USER_DESC,
|
COMPLETE_USER_DESC,
|
||||||
pw_name );
|
pw_name );
|
||||||
|
|
||||||
completion_allocate( comp,
|
completion_allocate( comp,
|
||||||
(wchar_t *)name.buff,
|
(wchar_t *)name.buff,
|
||||||
(wchar_t *)desc.buff,
|
(wchar_t *)desc.buff,
|
||||||
COMPLETE_NO_CASE | COMPLETE_DONT_ESCAPE | COMPLETE_NO_SPACE );
|
COMPLETE_NO_CASE | COMPLETE_DONT_ESCAPE | COMPLETE_NO_SPACE );
|
||||||
res=1;
|
res=1;
|
||||||
|
|
||||||
sb_destroy( &desc );
|
sb_destroy( &desc );
|
||||||
sb_destroy( &name );
|
sb_destroy( &name );
|
||||||
|
|
||||||
}
|
}
|
||||||
free( pw_name );
|
free( pw_name );
|
||||||
}
|
}
|
||||||
|
@ -1862,9 +1862,9 @@ void complete( const wchar_t *cmd,
|
||||||
if( !done )
|
if( !done )
|
||||||
{
|
{
|
||||||
pos = cursor_pos-(cmdsubst_begin-cmd);
|
pos = cursor_pos-(cmdsubst_begin-cmd);
|
||||||
|
|
||||||
buff = wcsndup( cmdsubst_begin, cmdsubst_end-cmdsubst_begin );
|
buff = wcsndup( cmdsubst_begin, cmdsubst_end-cmdsubst_begin );
|
||||||
|
|
||||||
if( !buff )
|
if( !buff )
|
||||||
done=1;
|
done=1;
|
||||||
}
|
}
|
||||||
|
@ -1887,7 +1887,7 @@ void complete( const wchar_t *cmd,
|
||||||
|
|
||||||
wchar_t *ncmd = tok_last( &tok );
|
wchar_t *ncmd = tok_last( &tok );
|
||||||
int is_ddash = (wcscmp( ncmd, L"--" ) == 0) && ( (tok_get_pos( &tok )+2) < pos );
|
int is_ddash = (wcscmp( ncmd, L"--" ) == 0) && ( (tok_get_pos( &tok )+2) < pos );
|
||||||
|
|
||||||
if( !had_cmd )
|
if( !had_cmd )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -1908,17 +1908,17 @@ void complete( const wchar_t *cmd,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( !is_ddash ||
|
if( !is_ddash ||
|
||||||
( (use_command && use_function && use_builtin ) ) )
|
( (use_command && use_function && use_builtin ) ) )
|
||||||
{
|
{
|
||||||
int token_end;
|
int token_end;
|
||||||
|
|
||||||
free( current_command );
|
free( current_command );
|
||||||
current_command = wcsdup( ncmd );
|
current_command = wcsdup( ncmd );
|
||||||
|
|
||||||
token_end = tok_get_pos( &tok ) + wcslen( ncmd );
|
token_end = tok_get_pos( &tok ) + wcslen( ncmd );
|
||||||
|
|
||||||
on_command = (pos <= token_end );
|
on_command = (pos <= token_end );
|
||||||
had_cmd=1;
|
had_cmd=1;
|
||||||
}
|
}
|
||||||
|
@ -1931,10 +1931,10 @@ void complete( const wchar_t *cmd,
|
||||||
had_ddash = 1;
|
had_ddash = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TOK_END:
|
case TOK_END:
|
||||||
case TOK_PIPE:
|
case TOK_PIPE:
|
||||||
case TOK_BACKGROUND:
|
case TOK_BACKGROUND:
|
||||||
|
@ -1946,20 +1946,20 @@ void complete( const wchar_t *cmd,
|
||||||
use_builtin = 1;
|
use_builtin = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TOK_ERROR:
|
case TOK_ERROR:
|
||||||
{
|
{
|
||||||
end_loop=1;
|
end_loop=1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( tok_get_pos( &tok ) >= pos )
|
if( tok_get_pos( &tok ) >= pos )
|
||||||
{
|
{
|
||||||
end_loop=1;
|
end_loop=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
tok_next( &tok );
|
tok_next( &tok );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1974,7 +1974,7 @@ void complete( const wchar_t *cmd,
|
||||||
current_token = wcsndup( tok_begin, cursor_pos-(tok_begin-cmd) );
|
current_token = wcsndup( tok_begin, cursor_pos-(tok_begin-cmd) );
|
||||||
|
|
||||||
prev_token = prev_begin ? wcsndup( prev_begin, prev_end - prev_begin ): wcsdup(L"");
|
prev_token = prev_begin ? wcsndup( prev_begin, prev_end - prev_begin ): wcsdup(L"");
|
||||||
|
|
||||||
// debug( 0, L"on_command: %d, %ls %ls\n", on_command, current_command, current_token );
|
// debug( 0, L"on_command: %d, %ls %ls\n", on_command, current_command, current_token );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1983,9 +1983,9 @@ void complete( const wchar_t *cmd,
|
||||||
case, complete using the builtins completions, not using a
|
case, complete using the builtins completions, not using a
|
||||||
subcommand.
|
subcommand.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( (on_command || (wcscmp( current_token, L"--" ) == 0 ) ) &&
|
if( (on_command || (wcscmp( current_token, L"--" ) == 0 ) ) &&
|
||||||
(current_token[0] == L'-') &&
|
(current_token[0] == L'-') &&
|
||||||
!(use_command && use_function && use_builtin ) )
|
!(use_command && use_function && use_builtin ) )
|
||||||
{
|
{
|
||||||
free( current_command );
|
free( current_command );
|
||||||
|
@ -1993,11 +1993,11 @@ void complete( const wchar_t *cmd,
|
||||||
current_command = wcsdup( L"builtin" );
|
current_command = wcsdup( L"builtin" );
|
||||||
else
|
else
|
||||||
current_command = wcsdup( L"command" );
|
current_command = wcsdup( L"command" );
|
||||||
|
|
||||||
had_cmd = 1;
|
had_cmd = 1;
|
||||||
on_command = 0;
|
on_command = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Use command completions if in between commands
|
Use command completions if in between commands
|
||||||
*/
|
*/
|
||||||
|
@ -2005,7 +2005,7 @@ void complete( const wchar_t *cmd,
|
||||||
{
|
{
|
||||||
on_command=1;
|
on_command=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
We don't want these to be null
|
We don't want these to be null
|
||||||
*/
|
*/
|
||||||
|
@ -2014,12 +2014,12 @@ void complete( const wchar_t *cmd,
|
||||||
{
|
{
|
||||||
current_token = wcsdup(L"");
|
current_token = wcsdup(L"");
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !current_command )
|
if( !current_command )
|
||||||
{
|
{
|
||||||
current_command = wcsdup(L"");
|
current_command = wcsdup(L"");
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !prev_token )
|
if( !prev_token )
|
||||||
{
|
{
|
||||||
prev_token = wcsdup(L"");
|
prev_token = wcsdup(L"");
|
||||||
|
@ -2036,31 +2036,31 @@ void complete( const wchar_t *cmd,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int do_file=0;
|
int do_file=0;
|
||||||
|
|
||||||
wchar_t *current_command_unescape = unescape( current_command, 0 );
|
wchar_t *current_command_unescape = unescape( current_command, 0 );
|
||||||
wchar_t *prev_token_unescape = unescape( prev_token, 0 );
|
wchar_t *prev_token_unescape = unescape( prev_token, 0 );
|
||||||
wchar_t *current_token_unescape = unescape( current_token, UNESCAPE_INCOMPLETE );
|
wchar_t *current_token_unescape = unescape( current_token, UNESCAPE_INCOMPLETE );
|
||||||
|
|
||||||
if( current_token_unescape && prev_token_unescape && current_token_unescape )
|
if( current_token_unescape && prev_token_unescape && current_token_unescape )
|
||||||
{
|
{
|
||||||
do_file = complete_param( current_command_unescape,
|
do_file = complete_param( current_command_unescape,
|
||||||
prev_token_unescape,
|
prev_token_unescape,
|
||||||
current_token_unescape,
|
current_token_unescape,
|
||||||
!had_ddash,
|
!had_ddash,
|
||||||
comp );
|
comp );
|
||||||
}
|
}
|
||||||
|
|
||||||
free( current_command_unescape );
|
free( current_command_unescape );
|
||||||
free( prev_token_unescape );
|
free( prev_token_unescape );
|
||||||
free( current_token_unescape );
|
free( current_token_unescape );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
If we have found no command specific completions at
|
If we have found no command specific completions at
|
||||||
all, fall back to using file completions.
|
all, fall back to using file completions.
|
||||||
*/
|
*/
|
||||||
if( !al_get_count( comp ) )
|
if( !al_get_count( comp ) )
|
||||||
do_file = 1;
|
do_file = 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This function wants the unescaped string
|
This function wants the unescaped string
|
||||||
*/
|
*/
|
||||||
|
@ -2068,7 +2068,7 @@ void complete( const wchar_t *cmd,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free( current_token );
|
free( current_token );
|
||||||
free( current_command );
|
free( current_command );
|
||||||
free( prev_token );
|
free( prev_token );
|
||||||
|
|
64
complete.h
64
complete.h
|
@ -16,39 +16,39 @@
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Use all completions
|
Use all completions
|
||||||
*/
|
*/
|
||||||
#define SHARED 0
|
#define SHARED 0
|
||||||
/**
|
/**
|
||||||
Do not use file completion
|
Do not use file completion
|
||||||
*/
|
*/
|
||||||
#define NO_FILES 1
|
#define NO_FILES 1
|
||||||
/**
|
/**
|
||||||
Require a parameter after completion
|
Require a parameter after completion
|
||||||
*/
|
*/
|
||||||
#define NO_COMMON 2
|
#define NO_COMMON 2
|
||||||
/**
|
/**
|
||||||
Only use the argument list specifies with completion after
|
Only use the argument list specifies with completion after
|
||||||
option. This is the same as (NO_FILES & NO_COMMON)
|
option. This is the same as (NO_FILES & NO_COMMON)
|
||||||
*/
|
*/
|
||||||
#define EXCLUSIVE 3
|
#define EXCLUSIVE 3
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Command is a path
|
Command is a path
|
||||||
*/
|
*/
|
||||||
#define PATH 1
|
#define PATH 1
|
||||||
/**
|
/**
|
||||||
Command is not a path
|
Command is not a path
|
||||||
*/
|
*/
|
||||||
#define COMMAND 0
|
#define COMMAND 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Separator between completion and description
|
Separator between completion and description
|
||||||
*/
|
*/
|
||||||
#define COMPLETE_SEP L'\004'
|
#define COMPLETE_SEP L'\004'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Separator between completion and description
|
Separator between completion and description
|
||||||
*/
|
*/
|
||||||
#define COMPLETE_SEP_STR L"\004"
|
#define COMPLETE_SEP_STR L"\004"
|
||||||
|
@ -73,7 +73,7 @@
|
||||||
#define COMPLETE_NO_SPACE 1
|
#define COMPLETE_NO_SPACE 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This compeltion is case insensitive.
|
This compeltion is case insensitive.
|
||||||
|
|
||||||
Warning: The contents of the completion_t structure is actually
|
Warning: The contents of the completion_t structure is actually
|
||||||
different if this flag is set! Specifically, the completion string
|
different if this flag is set! Specifically, the completion string
|
||||||
|
@ -115,7 +115,7 @@ typedef struct
|
||||||
const wchar_t *description;
|
const wchar_t *description;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Flags determining the completion behaviour.
|
Flags determining the completion behaviour.
|
||||||
|
|
||||||
Determines whether a space should be inserted after this
|
Determines whether a space should be inserted after this
|
||||||
compeltion if it is the only possible completion using the
|
compeltion if it is the only possible completion using the
|
||||||
|
@ -132,17 +132,17 @@ typedef struct
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
Add a completion.
|
Add a completion.
|
||||||
|
|
||||||
All supplied values are copied, they should be freed by or otherwise
|
All supplied values are copied, they should be freed by or otherwise
|
||||||
disposed by the caller.
|
disposed by the caller.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
The command 'gcc -o' requires that a file follows it, so the
|
The command 'gcc -o' requires that a file follows it, so the
|
||||||
NO_COMMON option is suitable. This can be done using the following
|
NO_COMMON option is suitable. This can be done using the following
|
||||||
line:
|
line:
|
||||||
|
|
||||||
complete -c gcc -s o -r
|
complete -c gcc -s o -r
|
||||||
|
|
||||||
The command 'grep -d' required that one of the strings 'read',
|
The command 'grep -d' required that one of the strings 'read',
|
||||||
|
@ -159,7 +159,7 @@ typedef struct
|
||||||
will be interpreted as the command name.
|
will be interpreted as the command name.
|
||||||
\param short_opt The single character name of an option. (-a is a short option, --all and -funroll are long options)
|
\param short_opt The single character name of an option. (-a is a short option, --all and -funroll are long options)
|
||||||
\param long_opt The multi character name of an option. (-a is a short option, --all and -funroll are long options)
|
\param long_opt The multi character name of an option. (-a is a short option, --all and -funroll are long options)
|
||||||
\param long_mode Whether to use old style, single dash long options.
|
\param long_mode Whether to use old style, single dash long options.
|
||||||
\param result_mode Whether to search further completions when this
|
\param result_mode Whether to search further completions when this
|
||||||
completion has been succesfully matched. If result_mode is SHARED,
|
completion has been succesfully matched. If result_mode is SHARED,
|
||||||
any other completions may also be used. If result_mode is NO_FILES,
|
any other completions may also be used. If result_mode is NO_FILES,
|
||||||
|
@ -172,16 +172,16 @@ typedef struct
|
||||||
\param condition a command to be run to check it this completion should be used. If \c condition is empty, the completion is always used.
|
\param condition a command to be run to check it this completion should be used. If \c condition is empty, the completion is always used.
|
||||||
\param flags A set of completion flags
|
\param flags A set of completion flags
|
||||||
*/
|
*/
|
||||||
void complete_add( const wchar_t *cmd,
|
void complete_add( const wchar_t *cmd,
|
||||||
int cmd_type,
|
int cmd_type,
|
||||||
wchar_t short_opt,
|
wchar_t short_opt,
|
||||||
const wchar_t *long_opt,
|
const wchar_t *long_opt,
|
||||||
int long_mode,
|
int long_mode,
|
||||||
int result_mode,
|
int result_mode,
|
||||||
const wchar_t *condition,
|
const wchar_t *condition,
|
||||||
const wchar_t *comp,
|
const wchar_t *comp,
|
||||||
const wchar_t *desc,
|
const wchar_t *desc,
|
||||||
int flags );
|
int flags );
|
||||||
/**
|
/**
|
||||||
Sets whether the completion list for this command is complete. If
|
Sets whether the completion list for this command is complete. If
|
||||||
true, any options not matching one of the provided options will be
|
true, any options not matching one of the provided options will be
|
||||||
|
@ -194,8 +194,8 @@ void complete_set_authoritative( const wchar_t *cmd,
|
||||||
/**
|
/**
|
||||||
Remove a previously defined completion
|
Remove a previously defined completion
|
||||||
*/
|
*/
|
||||||
void complete_remove( const wchar_t *cmd,
|
void complete_remove( const wchar_t *cmd,
|
||||||
int cmd_type,
|
int cmd_type,
|
||||||
wchar_t short_opt,
|
wchar_t short_opt,
|
||||||
const wchar_t *long_opt );
|
const wchar_t *long_opt );
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ void complete_remove( const wchar_t *cmd,
|
||||||
void complete( const wchar_t *cmd, array_list_t *out );
|
void complete( const wchar_t *cmd, array_list_t *out );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Print a list of all current completions into the string_buffer_t.
|
Print a list of all current completions into the string_buffer_t.
|
||||||
|
|
||||||
\param out The string_buffer_t to write completions to
|
\param out The string_buffer_t to write completions to
|
||||||
*/
|
*/
|
||||||
|
@ -221,16 +221,16 @@ void complete_print( string_buffer_t *out );
|
||||||
/**
|
/**
|
||||||
Tests if the specified option is defined for the specified command
|
Tests if the specified option is defined for the specified command
|
||||||
*/
|
*/
|
||||||
int complete_is_valid_option( const wchar_t *str,
|
int complete_is_valid_option( const wchar_t *str,
|
||||||
const wchar_t *opt,
|
const wchar_t *opt,
|
||||||
array_list_t *errors );
|
array_list_t *errors );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Tests if the specified argument is valid for the specified option
|
Tests if the specified argument is valid for the specified option
|
||||||
and command
|
and command
|
||||||
*/
|
*/
|
||||||
int complete_is_valid_argument( const wchar_t *str,
|
int complete_is_valid_argument( const wchar_t *str,
|
||||||
const wchar_t *opt,
|
const wchar_t *opt,
|
||||||
const wchar_t *arg );
|
const wchar_t *arg );
|
||||||
|
|
||||||
|
|
||||||
|
|
146
configure.ac
146
configure.ac
|
@ -11,6 +11,11 @@
|
||||||
|
|
||||||
AC_INIT(fish,1.23.1,fish-users@lists.sf.net)
|
AC_INIT(fish,1.23.1,fish-users@lists.sf.net)
|
||||||
|
|
||||||
|
#
|
||||||
|
# preserve configure arguments for xsel
|
||||||
|
#
|
||||||
|
|
||||||
|
conf_arg=$@
|
||||||
|
|
||||||
#
|
#
|
||||||
# List of output variables produced by this configure script
|
# List of output variables produced by this configure script
|
||||||
|
@ -31,6 +36,7 @@ AC_SUBST(prefix)
|
||||||
AC_SUBST(SEQ_FALLBACK)
|
AC_SUBST(SEQ_FALLBACK)
|
||||||
AC_SUBST(XSEL)
|
AC_SUBST(XSEL)
|
||||||
AC_SUBST(XSEL_MAN)
|
AC_SUBST(XSEL_MAN)
|
||||||
|
AC_SUBST(XSEL_BIN)
|
||||||
AC_SUBST(XSEL_MAN_PATH)
|
AC_SUBST(XSEL_MAN_PATH)
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -54,7 +60,7 @@ if test configure -ot configure.ac; then
|
||||||
fi
|
fi
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
AC_MSG_ERROR(
|
AC_MSG_ERROR(
|
||||||
[cannot find the autoconf program in your path.
|
[cannot find the autoconf program in your path.
|
||||||
This program needs to be run whenever the configure.ac file is modified.
|
This program needs to be run whenever the configure.ac file is modified.
|
||||||
Please install it and try again.]
|
Please install it and try again.]
|
||||||
|
@ -79,7 +85,7 @@ if test ! -f ./config.h.in -o config.h.in -ot configure.ac; then
|
||||||
AC_MSG_NOTICE([running autoheader])
|
AC_MSG_NOTICE([running autoheader])
|
||||||
autoheader || exit 1
|
autoheader || exit 1
|
||||||
else
|
else
|
||||||
AC_MSG_ERROR(
|
AC_MSG_ERROR(
|
||||||
[cannot find the autoheader program in your path.
|
[cannot find the autoheader program in your path.
|
||||||
This program needs to be run whenever the configure.ac file is modified.
|
This program needs to be run whenever the configure.ac file is modified.
|
||||||
Please install it and try again.]
|
Please install it and try again.]
|
||||||
|
@ -130,7 +136,7 @@ done
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Tell autoconf to create config.h header
|
# Tell autoconf to create config.h header
|
||||||
#
|
#
|
||||||
AC_CONFIG_HEADERS(config.h)
|
AC_CONFIG_HEADERS(config.h)
|
||||||
|
|
||||||
|
@ -144,8 +150,8 @@ AH_BOTTOM([#if __GNUC__ >= 3
|
||||||
#define __warn_unused __attribute__ ((warn_unused_result))
|
#define __warn_unused __attribute__ ((warn_unused_result))
|
||||||
#define __sentinel __attribute__ ((sentinel))
|
#define __sentinel __attribute__ ((sentinel))
|
||||||
#else
|
#else
|
||||||
#define __warn_unused
|
#define __warn_unused
|
||||||
#define __sentinel
|
#define __sentinel
|
||||||
#endif])
|
#endif])
|
||||||
|
|
||||||
|
|
||||||
|
@ -195,20 +201,22 @@ fi
|
||||||
# Optionally drop xsel command
|
# Optionally drop xsel command
|
||||||
#
|
#
|
||||||
|
|
||||||
AC_ARG_WITH(
|
AC_ARG_WITH(
|
||||||
xsel,
|
xsel,
|
||||||
AC_HELP_STRING(
|
AC_HELP_STRING(
|
||||||
[--without-xsel],
|
[--without-xsel],
|
||||||
[do not build the xsel program needed for X clipboard integration]
|
[do not build the xsel program needed for X clipboard integration.
|
||||||
|
If build xsel, it will be configured with the same options as fish.]
|
||||||
),
|
),
|
||||||
[xsel=$withval],
|
[xsel=$withval],
|
||||||
[xsel=with_xsel]
|
[xsel=with_xsel]
|
||||||
)
|
)
|
||||||
|
|
||||||
if [[ "$xsel" = "with_xsel" ]]; then
|
if [[ "$xsel" = "with_xsel" ]]; then
|
||||||
XSEL=xsel-0.9.6/xsel
|
XSEL=xsel-1.2.0
|
||||||
|
XSEL_BIN=$XSEL/xsel
|
||||||
XSEL_MAN=xsel.1x
|
XSEL_MAN=xsel.1x
|
||||||
XSEL_MAN_PATH=xsel-0.9.6/xsel.1x
|
XSEL_MAN_PATH=$XSEL/xsel.1x
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
@ -226,7 +234,7 @@ AC_ARG_WITH(
|
||||||
[local_gettext=yes]
|
[local_gettext=yes]
|
||||||
)
|
)
|
||||||
|
|
||||||
if test x$local_gettext != xno; then
|
if test x$local_gettext != xno; then
|
||||||
AC_DEFINE([USE_GETTEXT],[1],[Perform string translations with gettext])
|
AC_DEFINE([USE_GETTEXT],[1],[Perform string translations with gettext])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -338,9 +346,9 @@ AC_RUN_IFELSE(
|
||||||
return STATUS;
|
return STATUS;
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
[glibc=yes],
|
[glibc=yes],
|
||||||
[glibc=no]
|
[glibc=no]
|
||||||
)
|
)
|
||||||
|
|
||||||
if test "$glibc" = yes; then
|
if test "$glibc" = yes; then
|
||||||
|
@ -383,7 +391,7 @@ fi
|
||||||
|
|
||||||
AC_MSG_CHECKING([if we are under Solaris])
|
AC_MSG_CHECKING([if we are under Solaris])
|
||||||
case $target_os in
|
case $target_os in
|
||||||
solaris*)
|
solaris*)
|
||||||
AC_DEFINE( __EXTENSIONS__, 1, [Macro to enable additional prototypes under Solaris])
|
AC_DEFINE( __EXTENSIONS__, 1, [Macro to enable additional prototypes under Solaris])
|
||||||
AC_MSG_RESULT(yes)
|
AC_MSG_RESULT(yes)
|
||||||
;;
|
;;
|
||||||
|
@ -397,7 +405,7 @@ AC_MSG_CHECKING([if we are using non varargs tparm.])
|
||||||
AC_COMPILE_IFELSE(
|
AC_COMPILE_IFELSE(
|
||||||
[
|
[
|
||||||
AC_LANG_PROGRAM(
|
AC_LANG_PROGRAM(
|
||||||
[
|
[
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <term.h>
|
#include <term.h>
|
||||||
],
|
],
|
||||||
|
@ -406,8 +414,8 @@ AC_COMPILE_IFELSE(
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
[tparm_solaris_kludge=no],
|
[tparm_solaris_kludge=no],
|
||||||
[tparm_solaris_kludge=yes]
|
[tparm_solaris_kludge=yes]
|
||||||
)
|
)
|
||||||
if test "x$tparm_solaris_kludge" = "xyes"; then
|
if test "x$tparm_solaris_kludge" = "xyes"; then
|
||||||
AC_MSG_RESULT(yes)
|
AC_MSG_RESULT(yes)
|
||||||
|
@ -427,7 +435,7 @@ fi
|
||||||
|
|
||||||
AC_MSG_CHECKING([if we are under BSD])
|
AC_MSG_CHECKING([if we are under BSD])
|
||||||
case $target_os in
|
case $target_os in
|
||||||
*bsd*)
|
*bsd*)
|
||||||
AC_DEFINE( __BSD_VISIBLE, 1, [Macro to enable additional prototypes under BSD])
|
AC_DEFINE( __BSD_VISIBLE, 1, [Macro to enable additional prototypes under BSD])
|
||||||
AC_DEFINE( _NETBSD_SOURCE, 1, [Macro to enable additional prototypes under BSD])
|
AC_DEFINE( _NETBSD_SOURCE, 1, [Macro to enable additional prototypes under BSD])
|
||||||
AC_MSG_RESULT(yes)
|
AC_MSG_RESULT(yes)
|
||||||
|
@ -486,7 +494,7 @@ AC_CHECK_FILES([/proc/self/stat])
|
||||||
#
|
#
|
||||||
|
|
||||||
AC_DEFINE(
|
AC_DEFINE(
|
||||||
[HAVE_TRANSLATE_H],
|
[HAVE_TRANSLATE_H],
|
||||||
[1],
|
[1],
|
||||||
[Define to 1 if the wgettext function should be used for translating strings.]
|
[Define to 1 if the wgettext function should be used for translating strings.]
|
||||||
)
|
)
|
||||||
|
@ -510,12 +518,12 @@ LIBS_SHARED=$LIBS
|
||||||
LIBS=$LIBS_COMMON
|
LIBS=$LIBS_COMMON
|
||||||
|
|
||||||
#
|
#
|
||||||
# Check for libraries needed by fish.
|
# Check for libraries needed by fish.
|
||||||
#
|
#
|
||||||
|
|
||||||
LIBS_COMMON=$LIBS
|
LIBS_COMMON=$LIBS
|
||||||
LIBS="$LIBS_SHARED"
|
LIBS="$LIBS_SHARED"
|
||||||
if test x$local_gettext != xno; then
|
if test x$local_gettext != xno; then
|
||||||
AC_SEARCH_LIBS( gettext, intl,,)
|
AC_SEARCH_LIBS( gettext, intl,,)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -527,24 +535,24 @@ LIBS_FISH=$LIBS
|
||||||
LIBS=$LIBS_COMMON
|
LIBS=$LIBS_COMMON
|
||||||
|
|
||||||
#
|
#
|
||||||
# Check for libraries needed by fish_indent.
|
# Check for libraries needed by fish_indent.
|
||||||
#
|
#
|
||||||
|
|
||||||
LIBS_COMMON=$LIBS
|
LIBS_COMMON=$LIBS
|
||||||
LIBS="$LIBS_SHARED"
|
LIBS="$LIBS_SHARED"
|
||||||
if test x$local_gettext != xno; then
|
if test x$local_gettext != xno; then
|
||||||
AC_SEARCH_LIBS( gettext, intl,,)
|
AC_SEARCH_LIBS( gettext, intl,,)
|
||||||
fi
|
fi
|
||||||
LIBS_FISH_INDENT=$LIBS
|
LIBS_FISH_INDENT=$LIBS
|
||||||
LIBS=$LIBS_COMMON
|
LIBS=$LIBS_COMMON
|
||||||
|
|
||||||
#
|
#
|
||||||
# Check for libraries needed by fish_pager.
|
# Check for libraries needed by fish_pager.
|
||||||
#
|
#
|
||||||
|
|
||||||
LIBS_COMMON=$LIBS
|
LIBS_COMMON=$LIBS
|
||||||
LIBS="$LIBS_SHARED"
|
LIBS="$LIBS_SHARED"
|
||||||
if test x$local_gettext != xno; then
|
if test x$local_gettext != xno; then
|
||||||
AC_SEARCH_LIBS( gettext, intl,,)
|
AC_SEARCH_LIBS( gettext, intl,,)
|
||||||
fi
|
fi
|
||||||
AC_SEARCH_LIBS( iconv_open, iconv, , [AC_MSG_ERROR([Could not find an iconv implementation, needed to build fish])] )
|
AC_SEARCH_LIBS( iconv_open, iconv, , [AC_MSG_ERROR([Could not find an iconv implementation, needed to build fish])] )
|
||||||
|
@ -552,12 +560,12 @@ LIBS_FISH_PAGER=$LIBS
|
||||||
LIBS=$LIBS_COMMON
|
LIBS=$LIBS_COMMON
|
||||||
|
|
||||||
#
|
#
|
||||||
# Check for libraries needed by fishd.
|
# Check for libraries needed by fishd.
|
||||||
#
|
#
|
||||||
|
|
||||||
LIBS_COMMON=$LIBS
|
LIBS_COMMON=$LIBS
|
||||||
LIBS="$LIBS_SHARED"
|
LIBS="$LIBS_SHARED"
|
||||||
if test x$local_gettext != xno; then
|
if test x$local_gettext != xno; then
|
||||||
AC_SEARCH_LIBS( gettext, intl,,)
|
AC_SEARCH_LIBS( gettext, intl,,)
|
||||||
fi
|
fi
|
||||||
AC_SEARCH_LIBS( iconv_open, iconv, , [AC_MSG_ERROR([Could not find an iconv implementation, needed to build fish])] )
|
AC_SEARCH_LIBS( iconv_open, iconv, , [AC_MSG_ERROR([Could not find an iconv implementation, needed to build fish])] )
|
||||||
|
@ -565,12 +573,12 @@ LIBS_FISHD=$LIBS
|
||||||
LIBS=$LIBS_COMMON
|
LIBS=$LIBS_COMMON
|
||||||
|
|
||||||
#
|
#
|
||||||
# Check for libraries needed by mimedb.
|
# Check for libraries needed by mimedb.
|
||||||
#
|
#
|
||||||
|
|
||||||
LIBS_COMMON=$LIBS
|
LIBS_COMMON=$LIBS
|
||||||
LIBS="$LIBS_SHARED"
|
LIBS="$LIBS_SHARED"
|
||||||
if test x$local_gettext != xno; then
|
if test x$local_gettext != xno; then
|
||||||
AC_SEARCH_LIBS( gettext, intl,,)
|
AC_SEARCH_LIBS( gettext, intl,,)
|
||||||
fi
|
fi
|
||||||
LIBS_MIMEDB=$LIBS
|
LIBS_MIMEDB=$LIBS
|
||||||
|
@ -578,12 +586,12 @@ LIBS=$LIBS_COMMON
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Check for libraries needed by set_color
|
# Check for libraries needed by set_color
|
||||||
#
|
#
|
||||||
|
|
||||||
LIBS_COMMON=$LIBS
|
LIBS_COMMON=$LIBS
|
||||||
LIBS="$LIBS_SHARED"
|
LIBS="$LIBS_SHARED"
|
||||||
if test x$local_gettext != xno; then
|
if test x$local_gettext != xno; then
|
||||||
AC_SEARCH_LIBS( gettext, intl,,)
|
AC_SEARCH_LIBS( gettext, intl,,)
|
||||||
fi
|
fi
|
||||||
LIBS_SET_COLOR=$LIBS
|
LIBS_SET_COLOR=$LIBS
|
||||||
|
@ -599,8 +607,8 @@ AC_CHECK_HEADER(
|
||||||
[regex.h],
|
[regex.h],
|
||||||
[
|
[
|
||||||
AC_DEFINE(
|
AC_DEFINE(
|
||||||
[HAVE_REGEX_H],
|
[HAVE_REGEX_H],
|
||||||
[1],
|
[1],
|
||||||
[Define to 1 if you have the <regex.h> header file.]
|
[Define to 1 if you have the <regex.h> header file.]
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
@ -697,10 +705,10 @@ for i in "" "-D_POSIX_C_SOURCE=200112L" "-D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=2
|
||||||
/* Extended-POSIX: might be unhidden by _XOPEN_SOURCE. */
|
/* Extended-POSIX: might be unhidden by _XOPEN_SOURCE. */
|
||||||
ret += killpg( 0, 0 );
|
ret += killpg( 0, 0 );
|
||||||
/* Non-standard: might be hidden by the macros. */
|
/* Non-standard: might be hidden by the macros. */
|
||||||
{
|
{
|
||||||
struct winsize termsize;
|
struct winsize termsize;
|
||||||
ret += (int)(void *)&termsize;
|
ret += (int)(void *)&termsize;
|
||||||
ret += SIGWINCH + TIOCGWINSZ + SIGIO;
|
ret += SIGWINCH + TIOCGWINSZ + SIGIO;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
@ -744,7 +752,7 @@ AC_CHECK_FUNCS( dcgettext backtrace backtrace_symbols sysconf )
|
||||||
# the translations should be installed.
|
# the translations should be installed.
|
||||||
#
|
#
|
||||||
|
|
||||||
if test x$local_gettext != xno; then
|
if test x$local_gettext != xno; then
|
||||||
AC_CHECK_FUNC( gettext, HAVE_GETTEXT=1, HAVE_GETTEXT=0 )
|
AC_CHECK_FUNC( gettext, HAVE_GETTEXT=1, HAVE_GETTEXT=0 )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -768,22 +776,22 @@ AC_RUN_IFELSE(
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
int status;
|
int status;
|
||||||
char *res;
|
char *res;
|
||||||
res = realpath( "somefile", 0 );
|
res = realpath( "somefile", 0 );
|
||||||
status = !(res != 0 || errno == ENOENT);
|
status = !(res != 0 || errno == ENOENT);
|
||||||
exit( status );
|
exit( status );
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
[have_realpath_null=yes],
|
[have_realpath_null=yes],
|
||||||
[have_realpath_null=no]
|
[have_realpath_null=no]
|
||||||
)
|
)
|
||||||
|
|
||||||
if test "$have_realpath_null" = yes; then
|
if test "$have_realpath_null" = yes; then
|
||||||
AC_MSG_RESULT(yes)
|
AC_MSG_RESULT(yes)
|
||||||
AC_DEFINE(
|
AC_DEFINE(
|
||||||
[HAVE_REALPATH_NULL],
|
[HAVE_REALPATH_NULL],
|
||||||
[1],
|
[1],
|
||||||
[Define to 1 if realpath accepts null for its second argument.]
|
[Define to 1 if realpath accepts null for its second argument.]
|
||||||
)
|
)
|
||||||
|
@ -810,15 +818,15 @@ AC_LINK_IFELSE(
|
||||||
#endif
|
#endif
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
struct winsize termsize = {0};
|
struct winsize termsize = {0};
|
||||||
TIOCGWINSZ;
|
TIOCGWINSZ;
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
AC_MSG_RESULT(yes);
|
AC_MSG_RESULT(yes);
|
||||||
AC_DEFINE([HAVE_WINSIZE], [1], [Define to 1 if the winsize struct and TIOCGWINSZ macro exist])
|
AC_DEFINE([HAVE_WINSIZE], [1], [Define to 1 if the winsize struct and TIOCGWINSZ macro exist])
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
AC_MSG_RESULT(no)
|
AC_MSG_RESULT(no)
|
||||||
]
|
]
|
||||||
|
@ -854,7 +862,7 @@ if test "$ac_cv_func_fwprintf" = yes; then
|
||||||
[
|
[
|
||||||
AC_MSG_RESULT([yes])
|
AC_MSG_RESULT([yes])
|
||||||
AC_DEFINE([HAVE_BROKEN_FWPRINTF], [1], [Define to 1 one if the implemented fwprintf is broken])
|
AC_DEFINE([HAVE_BROKEN_FWPRINTF], [1], [Define to 1 one if the implemented fwprintf is broken])
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
@ -870,19 +878,19 @@ AC_TRY_LINK(
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
extern int _nl_msg_cat_cntr;
|
extern int _nl_msg_cat_cntr;
|
||||||
int tmp = _nl_msg_cat_cntr;
|
int tmp = _nl_msg_cat_cntr;
|
||||||
exit(tmp);
|
exit(tmp);
|
||||||
],
|
],
|
||||||
have__nl_msg_cat_cntr=yes,
|
have__nl_msg_cat_cntr=yes,
|
||||||
have__nl_msg_cat_cntr=no
|
have__nl_msg_cat_cntr=no
|
||||||
)
|
)
|
||||||
if test "$have__nl_msg_cat_cntr" = yes; then
|
if test "$have__nl_msg_cat_cntr" = yes; then
|
||||||
AC_MSG_RESULT(yes)
|
AC_MSG_RESULT(yes)
|
||||||
AC_DEFINE(
|
AC_DEFINE(
|
||||||
[HAVE__NL_MSG_CAT_CNTR],
|
[HAVE__NL_MSG_CAT_CNTR],
|
||||||
[1],
|
[1],
|
||||||
[Define to 1 if the _nl_msg_cat_cntr symbol is exported.]
|
[Define to 1 if the _nl_msg_cat_cntr symbol is exported.]
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
AC_MSG_RESULT(no)
|
AC_MSG_RESULT(no)
|
||||||
fi
|
fi
|
||||||
|
@ -895,19 +903,19 @@ AC_TRY_LINK(
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
extern char **__environ;
|
extern char **__environ;
|
||||||
char **tmp = __environ;
|
char **tmp = __environ;
|
||||||
exit(tmp!=0);
|
exit(tmp!=0);
|
||||||
],
|
],
|
||||||
have___environ=yes,
|
have___environ=yes,
|
||||||
have___environ=no
|
have___environ=no
|
||||||
)
|
)
|
||||||
if test "$have___environ" = yes; then
|
if test "$have___environ" = yes; then
|
||||||
AC_MSG_RESULT(yes)
|
AC_MSG_RESULT(yes)
|
||||||
AC_DEFINE(
|
AC_DEFINE(
|
||||||
[HAVE___ENVIRON],
|
[HAVE___ENVIRON],
|
||||||
[1],
|
[1],
|
||||||
[Define to 1 if the __environ symbol is exported.]
|
[Define to 1 if the __environ symbol is exported.]
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
AC_MSG_RESULT(no)
|
AC_MSG_RESULT(no)
|
||||||
fi
|
fi
|
||||||
|
@ -924,26 +932,26 @@ AC_TRY_LINK(
|
||||||
static struct option
|
static struct option
|
||||||
long_options[] =
|
long_options[] =
|
||||||
{
|
{
|
||||||
0, 0, 0, 0
|
0, 0, 0, 0
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
int opt = getopt_long( 0,
|
int opt = getopt_long( 0,
|
||||||
0,
|
|
||||||
0,
|
0,
|
||||||
long_options,
|
0,
|
||||||
|
long_options,
|
||||||
0 );
|
0 );
|
||||||
|
|
||||||
],
|
],
|
||||||
have_working_getopt_long=yes,
|
have_working_getopt_long=yes,
|
||||||
have_working_getopt_long=no
|
have_working_getopt_long=no
|
||||||
)
|
)
|
||||||
if test "$have_working_getopt_long" = yes; then
|
if test "$have_working_getopt_long" = yes; then
|
||||||
AC_MSG_RESULT(yes)
|
AC_MSG_RESULT(yes)
|
||||||
AC_DEFINE(
|
AC_DEFINE(
|
||||||
[HAVE_WORKING_GETOPT_LONG],
|
[HAVE_WORKING_GETOPT_LONG],
|
||||||
[1],
|
[1],
|
||||||
[Define to 1 if getopt_long exists and works.]
|
[Define to 1 if getopt_long exists and works.]
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
AC_MSG_RESULT(no)
|
AC_MSG_RESULT(no)
|
||||||
fi
|
fi
|
||||||
|
@ -975,6 +983,12 @@ if test ! x$local_found_posix_switch = xyes; then
|
||||||
echo "Some fish features may be disabled."
|
echo "Some fish features may be disabled."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "$xsel" = "with_xsel" ]]; then
|
||||||
|
echo "Now configure xsel with $conf_arg"
|
||||||
|
rm -rf $XSEL
|
||||||
|
tar xf $XSEL.tar.gz
|
||||||
|
cd $XSEL && ./configure $conf_arg
|
||||||
|
fi
|
||||||
echo "fish is now configured."
|
echo "fish is now configured."
|
||||||
echo "Use 'make' and 'make install' to build and install fish."
|
echo "Use 'make' and 'make install' to build and install fish."
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ shells. For other uses, it is recommended to define a <a
|
||||||
href='#function'>function</a>.
|
href='#function'>function</a>.
|
||||||
|
|
||||||
Alias does not keep track of which functions have been defined using
|
Alias does not keep track of which functions have been defined using
|
||||||
alias, nor does it allow erasing of aliases.
|
alias, nor does it allow erasing of aliases.
|
||||||
|
|
||||||
- NAME is the name of the function to define
|
- 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.
|
- DEFINITION is the body of the function. The string " $argv" will be appended to the body.
|
||||||
|
|
|
@ -37,7 +37,7 @@ In the following code, all output is redirected to the file out.html.
|
||||||
begin
|
begin
|
||||||
echo $xml_header
|
echo $xml_header
|
||||||
echo $html_header
|
echo $html_header
|
||||||
if test -e $file
|
if test -e $file
|
||||||
...
|
...
|
||||||
end
|
end
|
||||||
...
|
...
|
||||||
|
|
|
@ -13,9 +13,9 @@
|
||||||
|
|
||||||
The following switches change what the commandline builtin does
|
The following switches change what the commandline builtin does
|
||||||
|
|
||||||
- \c -C or \c --cursor set or get the current cursor position, not
|
- \c -C or \c --cursor set or get the current cursor position, not
|
||||||
the contents of the buffer. If no argument is given, the current
|
the contents of the buffer. If no argument is given, the current
|
||||||
cursor position is printed, otherwise the argument is interpreted
|
cursor position is printed, otherwise the argument is interpreted
|
||||||
as the new cursor position.
|
as the new cursor position.
|
||||||
- \c -f or \c --function inject readline functions into the
|
- \c -f or \c --function inject readline functions into the
|
||||||
reader. This option can not be combined with any other option. It
|
reader. This option can not be combined with any other option. It
|
||||||
|
@ -44,7 +44,7 @@ or updated
|
||||||
- \c -t or \c --current-token select the current token.
|
- \c -t or \c --current-token select the current token.
|
||||||
|
|
||||||
The following switch changes the way \c commandline prints the current
|
The following switch changes the way \c commandline prints the current
|
||||||
commandline buffer
|
commandline buffer
|
||||||
|
|
||||||
- \c -c or \c --cut-at-cursor only print selection up until the
|
- \c -c or \c --cut-at-cursor only print selection up until the
|
||||||
current cursor position
|
current cursor position
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/** \page commands Commands, functions and builtins bundled with fish
|
/** \page commands Commands, functions and builtins bundled with fish
|
||||||
Fish ships with a large number of builtin commands, shellscript functions and external commands. These are all described below.
|
Fish ships with a large number of builtin commands, shellscript functions and external commands. These are all described below.
|
||||||
|
|
||||||
@command_list@
|
@command_list@
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,8 @@ design fish. The fish design has three high level goals. These are:
|
||||||
|
|
||||||
-# Everything that can be done in other shell languages should be
|
-# Everything that can be done in other shell languages should be
|
||||||
possible to do in fish, though fish may rely on external commands in
|
possible to do in fish, though fish may rely on external commands in
|
||||||
doing so.
|
doing so.
|
||||||
-# Fish should be user friendly, but not at the expense of expressiveness.
|
-# Fish should be user friendly, but not at the expense of expressiveness.
|
||||||
Most tradeoffs between power and ease of use can be avoided with careful design.
|
Most tradeoffs between power and ease of use can be avoided with careful design.
|
||||||
-# Whenever possible without breaking the above goals, fish should
|
-# Whenever possible without breaking the above goals, fish should
|
||||||
follow the Posix syntax.
|
follow the Posix syntax.
|
||||||
|
@ -33,7 +33,7 @@ program harder to maintain and update.
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
- Here documents are too similar to using echo inside of a pipeline.
|
- Here documents are too similar to using echo inside of a pipeline.
|
||||||
- Subshells, command substitution and process substitution are strongly related. \c fish only supports command substitution, the others can be achived either using a block or the psub shellscript function.
|
- Subshells, command substitution and process substitution are strongly related. \c fish only supports command substitution, the others can be achived either using a block or the psub shellscript function.
|
||||||
- Having both aliases and functions is confusing, especially since both of them have limitations and problems. \c fish functions have none of the drawbacks of either syntax.
|
- Having both aliases and functions is confusing, especially since both of them have limitations and problems. \c fish functions have none of the drawbacks of either syntax.
|
||||||
- The many Posix quoting styles are silly, especially \$''.
|
- The many Posix quoting styles are silly, especially \$''.
|
||||||
|
|
||||||
|
@ -57,14 +57,14 @@ take the whole system down.
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
- Builtin commands should only be created when it cannot be
|
- Builtin commands should only be created when it cannot be
|
||||||
avoided. \c echo, \c kill, \c printf and \c time are among the commands
|
avoided. \c echo, \c kill, \c printf and \c time are among the commands
|
||||||
that fish does not implement internally since they can be provided as
|
that fish does not implement internally since they can be provided as
|
||||||
external commands. Several other commands that are commonly implemented
|
external commands. Several other commands that are commonly implemented
|
||||||
as builtins and can not be implemented as external commands,
|
as builtins and can not be implemented as external commands,
|
||||||
including \c type, \c vared, \c pushd and \c popd are implemented as shellscript
|
including \c type, \c vared, \c pushd and \c popd are implemented as shellscript
|
||||||
functions in fish.
|
functions in fish.
|
||||||
- Mathematical calculations, regex matching, generating lists of numbers
|
- Mathematical calculations, regex matching, generating lists of numbers
|
||||||
and many other funtions can easily be done in external programs. They
|
and many other funtions can easily be done in external programs. They
|
||||||
should not be supported internally by the shell.
|
should not be supported internally by the shell.
|
||||||
|
|
||||||
The law of minimalism does not imply that a large feature set is
|
The law of minimalism does not imply that a large feature set is
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
\subsection dirh-synopsis Synopsis
|
\subsection dirh-synopsis Synopsis
|
||||||
<tt>dirh</tt>
|
<tt>dirh</tt>
|
||||||
|
|
||||||
\subsection dirh-description Description
|
\subsection dirh-description Description
|
||||||
<tt>dirh</tt> prints the current directory history. The current position in the
|
<tt>dirh</tt> prints the current directory history. The current position in the
|
||||||
history is highlighted using <tt>$fish_color_history_current</tt>.
|
history is highlighted using <tt>$fish_color_history_current</tt>.
|
||||||
|
|
|
@ -3,5 +3,5 @@
|
||||||
\subsection dirs-synopsis Synopsis
|
\subsection dirs-synopsis Synopsis
|
||||||
<tt>dirs</tt>
|
<tt>dirs</tt>
|
||||||
|
|
||||||
\subsection dirs-description Description
|
\subsection dirs-description Description
|
||||||
<tt>dirs</tt> prints the current directory stack.
|
<tt>dirs</tt> prints the current directory stack.
|
||||||
|
|
|
@ -13,5 +13,5 @@ status is 0, the commands COMMANDS_TRUE will execute. If it is not 0 and
|
||||||
|
|
||||||
The command <tt>if test -f foo.txt; echo foo.txt exists; else; echo foo.txt does not exist; end</tt>
|
The command <tt>if test -f foo.txt; echo foo.txt exists; else; echo foo.txt does not exist; end</tt>
|
||||||
will print <tt>foo.txt exists</tt> if the file foo.txt
|
will print <tt>foo.txt exists</tt> if the file foo.txt
|
||||||
exists and is a regular file, otherwise it will print
|
exists and is a regular file, otherwise it will print
|
||||||
<tt>foo.txt does not exist</tt>.
|
<tt>foo.txt does not exist</tt>.
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
\subsection emit-description Description
|
\subsection emit-description Description
|
||||||
|
|
||||||
The emit builtin fires a generic fish event. Such events can be caught by special functions called event handlers.
|
The emit builtin fires a generic fish event. Such events can be caught by special functions called event handlers.
|
||||||
|
|
||||||
\subsection emit-example Example
|
\subsection emit-example Example
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ parent is ~. This issue is not possible to fix without either making
|
||||||
every single command into a builtin, breaking Unix semantics or
|
every single command into a builtin, breaking Unix semantics or
|
||||||
implementing kludges in every single command.
|
implementing kludges in every single command.
|
||||||
|
|
||||||
This issue can also be seen when doing IO redirection.
|
This issue can also be seen when doing IO redirection.
|
||||||
|
|
||||||
Another related issue is that many programs that operate on recursive
|
Another related issue is that many programs that operate on recursive
|
||||||
directory trees, like the find command, silently ignore symlinked
|
directory trees, like the find command, silently ignore symlinked
|
||||||
|
@ -56,7 +56,7 @@ feature, write <code>set CDPATH .</code> on the commandline.
|
||||||
|
|
||||||
If fish is unable to locate a command with a given name, fish will
|
If fish is unable to locate a command with a given name, fish will
|
||||||
test if a directory of that name exists. If it does, it is implicitly
|
test if a directory of that name exists. If it does, it is implicitly
|
||||||
assumed that you want to change working directory. For example, the
|
assumed that you want to change working directory. For example, the
|
||||||
fastest way to switch to your home directory is to simply press
|
fastest way to switch to your home directory is to simply press
|
||||||
<code>~</code> and enter.
|
<code>~</code> and enter.
|
||||||
|
|
||||||
|
@ -141,21 +141,21 @@ set fish_greeting
|
||||||
|
|
||||||
\section faq-history Why doesn't history substitution ("!$" etc.) work?
|
\section faq-history Why doesn't history substitution ("!$" etc.) work?
|
||||||
|
|
||||||
Because history substitution is an awkward interface that was invented before
|
Because history substitution is an awkward interface that was invented before
|
||||||
interactive line editing was even possible. Fish drops it in favor of
|
interactive line editing was even possible. Fish drops it in favor of
|
||||||
perfecting the interactive history recall interface. Switching requires a
|
perfecting the interactive history recall interface. Switching requires a
|
||||||
small change of habits: if you want to modify an old line/word, first recall
|
small change of habits: if you want to modify an old line/word, first recall
|
||||||
it, then edit. E.g. don't type "sudo !!" - first press Up, then Home, then
|
it, then edit. E.g. don't type "sudo !!" - first press Up, then Home, then
|
||||||
type "sudo ".
|
type "sudo ".
|
||||||
|
|
||||||
Fish history recall is very simple yet effective:
|
Fish history recall is very simple yet effective:
|
||||||
|
|
||||||
- As in any modern shell, the Up arrow recalls whole lines, starting from the last line executed. A single press replaces "!!", later presses replace "!-3" and the like.
|
- As in any modern shell, the Up arrow recalls whole lines, starting from the last line executed. A single press replaces "!!", later presses replace "!-3" and the like.
|
||||||
- If the line you want is far back in the history, type any part of the line and then press Up one or more times. This will constrain the recall to lines that include this text, and you will get to the line you want much faster. This replaces "!vi", "!?bar.c" and the like.
|
- If the line you want is far back in the history, type any part of the line and then press Up one or more times. This will constrain the recall to lines that include this text, and you will get to the line you want much faster. This replaces "!vi", "!?bar.c" and the like.
|
||||||
- Alt+Up recalls individual arguments, starting from the last argument in the last line executed. A single press replaces "!$", later presses replace "!!:4" and the like.
|
- Alt+Up recalls individual arguments, starting from the last argument in the last line executed. A single press replaces "!$", later presses replace "!!:4" and the like.
|
||||||
- If the argument you want is far back in history (e.g. 2 lines back - that's a lot of words!), type any part of it and then press Alt+Up. This will show only arguments containing that part and you will get what you want much faster. Try it out, this is very convenient!
|
- If the argument you want is far back in history (e.g. 2 lines back - that's a lot of words!), type any part of it and then press Alt+Up. This will show only arguments containing that part and you will get what you want much faster. Try it out, this is very convenient!
|
||||||
- If you want to reuse several arguments from the same line ("!!:3*" and the like), consider recalling the whole line and removing what you don't need (Alt+D and Alt+Backspace are your friends).
|
- If you want to reuse several arguments from the same line ("!!:3*" and the like), consider recalling the whole line and removing what you don't need (Alt+D and Alt+Backspace are your friends).
|
||||||
|
|
||||||
See <a href='index.html#editor'>documentation</a> for more details about line editing in fish.
|
See <a href='index.html#editor'>documentation</a> for more details about line editing in fish.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -11,7 +11,7 @@ not be executed at all.
|
||||||
|
|
||||||
\subsection for-example Example
|
\subsection for-example Example
|
||||||
|
|
||||||
The command
|
The command
|
||||||
|
|
||||||
<tt>for i in foo bar baz; echo $i; end</tt>
|
<tt>for i in foo bar baz; echo $i; end</tt>
|
||||||
|
|
||||||
|
@ -21,5 +21,5 @@ would output:
|
||||||
foo
|
foo
|
||||||
bar
|
bar
|
||||||
baz
|
baz
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
This builtin command is used to print or erase functions.
|
This builtin command is used to print or erase functions.
|
||||||
|
|
||||||
- <code>-a</code> or <code>--all</code> list all functions, even those whose name start with an underscore.
|
- <code>-a</code> or <code>--all</code> list all functions, even those whose name start with an underscore.
|
||||||
|
- <code>-c OLDNAME NEWNAME</code> or <code>--copy OLDNAME NEWNAME</code> creates a new function named NEWNAME, using the definition of the OLDNAME function.
|
||||||
- <code>-d DESCRIPTION</code> or <code>--description=DESCRIPTION</code> change the description of this function
|
- <code>-d DESCRIPTION</code> or <code>--description=DESCRIPTION</code> change the description of this function
|
||||||
- <code>-e</code> or <code>--erase</code> causes the specified functions to be erased.
|
- <code>-e</code> or <code>--erase</code> causes the specified functions to be erased.
|
||||||
- <code>-h</code> or <code>--help</code> display a help message and exit
|
- <code>-h</code> or <code>--help</code> display a help message and exit
|
||||||
|
@ -17,11 +18,14 @@ This builtin command is used to print or erase functions.
|
||||||
The default behavior of \c functions when called with no arguments,
|
The default behavior of \c functions when called with no arguments,
|
||||||
is to print the names and definitions of all defined functions. If any
|
is to print the names and definitions of all defined functions. If any
|
||||||
non-switch parameters are given, only the definition of the specified
|
non-switch parameters are given, only the definition of the specified
|
||||||
functions are printed.
|
functions are printed.
|
||||||
|
|
||||||
Automatically loaded functions can not be removed using functions
|
Automatically loaded functions can not be removed using functions
|
||||||
-e. Either remove the definition file or change the
|
-e. Either remove the definition file or change the
|
||||||
$fish_function_path variable to remove autoloaded functions.
|
$fish_function_path variable to remove autoloaded functions.
|
||||||
|
|
||||||
|
Function copies, created with -c, will not have any event/signal/on-exit
|
||||||
|
notifications that the original may have had.
|
||||||
|
|
||||||
The exit status of the functions builtin is the number functions
|
The exit status of the functions builtin is the number functions
|
||||||
specified in the argument list that do not exist.
|
specified in the argument list that do not exist.
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<tt>if</tt> will execute the command CONDITION. If the condition's
|
<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 0, the commands COMMANDS_TRUE will execute. If the
|
||||||
exit status is not 0 and <tt>else</tt> is given, COMMANDS_FALSE will
|
exit status is not 0 and <tt>else</tt> is given, COMMANDS_FALSE will
|
||||||
be executed.
|
be executed.
|
||||||
|
|
||||||
In order to use the exit status of multiple commands as the condition
|
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
|
of an if block, use <a href="#begin"><tt>begin; ...; end</tt></a> and
|
||||||
|
@ -29,5 +29,5 @@ else
|
||||||
end
|
end
|
||||||
</pre>
|
</pre>
|
||||||
will print <tt>foo.txt exists</tt> if the file foo.txt
|
will print <tt>foo.txt exists</tt> if the file foo.txt
|
||||||
exists and is a regular file, otherwise it will print
|
exists and is a regular file, otherwise it will print
|
||||||
<tt>foo.txt does not exist</tt>.
|
<tt>foo.txt does not exist</tt>.
|
||||||
|
|
|
@ -59,7 +59,7 @@ Here is a list of some useful commands:
|
||||||
- \c mv, move (rename) files
|
- \c mv, move (rename) files
|
||||||
- \c cp, copy files
|
- \c cp, copy files
|
||||||
- \c open, open files with the default application associated with each filetype
|
- \c open, open files with the default application associated with each filetype
|
||||||
- \c less, list the contents of files
|
- \c less, list the contents of files
|
||||||
|
|
||||||
Commands and parameters are separated by the space character
|
Commands and parameters are separated by the space character
|
||||||
( ). Every command ends with either a newline (i.e. by pressing
|
( ). Every command ends with either a newline (i.e. by pressing
|
||||||
|
@ -147,7 +147,7 @@ these characters, so called escape sequences are provided. These are:
|
||||||
Most program use three types of input/output (IO), each represented by
|
Most program use three types of input/output (IO), each represented by
|
||||||
a number called a file descriptor (FD). These are:
|
a number called a file descriptor (FD). These are:
|
||||||
|
|
||||||
- Standard input, FD 0, for reading, defaults to reading from the keyboard.
|
- Standard input, FD 0, for reading, defaults to reading from the keyboard.
|
||||||
- Standard output, FD 1, for writing, defaults to writing to the screen.
|
- Standard output, FD 1, for writing, defaults to writing to the screen.
|
||||||
- Standard error, FD 2, for writing errors and warnings, defaults to writing to the screen.
|
- Standard error, FD 2, for writing errors and warnings, defaults to writing to the screen.
|
||||||
|
|
||||||
|
@ -160,13 +160,13 @@ default through a simple mechanism called a redirection.
|
||||||
An example of a file redirection is <code> echo hello \>output.txt</code>,
|
An example of a file redirection is <code> echo hello \>output.txt</code>,
|
||||||
which directs the output of the echo command to the file error.txt.
|
which directs the output of the echo command to the file error.txt.
|
||||||
|
|
||||||
- To redirect standard input, write <code>\<SOURCE_FILE</code>
|
- To redirect standard input, write <code>\<SOURCE_FILE</code>
|
||||||
- To redirect standard output, write <code>\>DESTINATION</code>
|
- To redirect standard output, write <code>\>DESTINATION</code>
|
||||||
- To redirect standard error, write <code>^DESTINATION</code>
|
- To redirect standard error, write <code>^DESTINATION</code>
|
||||||
- To redirect standard output to a file which will be appended, write <code>\>\>DESTINATION_FILE</code>
|
- To redirect standard output to a file which will be appended, write <code>\>\>DESTINATION_FILE</code>
|
||||||
- To redirect standard error to a file which will be appended, write <code>^^DESTINATION_FILE</code>
|
- To redirect standard error to a file which will be appended, write <code>^^DESTINATION_FILE</code>
|
||||||
|
|
||||||
<code>DESTINATION</code> can be one of the following:
|
<code>DESTINATION</code> can be one of the following:
|
||||||
|
|
||||||
- A filename. The output will be written to the specified file.
|
- A filename. The output will be written to the specified file.
|
||||||
- An ampersand (\&) followed by the number of another file descriptor. The file descriptor will be a duplicate of the specified file descriptor.
|
- An ampersand (\&) followed by the number of another file descriptor. The file descriptor will be a duplicate of the specified file descriptor.
|
||||||
|
@ -182,7 +182,7 @@ Any FD can be redirected in an arbitrary way by prefixing the
|
||||||
redirection with the number of the FD.
|
redirection with the number of the FD.
|
||||||
|
|
||||||
- To redirect input of FD number N, write <code>N\<DESTINATION</code>
|
- To redirect input of FD number N, write <code>N\<DESTINATION</code>
|
||||||
- To redirect output of FD number N, write <code>N\>DESTINATION</code>
|
- To redirect output of FD number N, write <code>N\>DESTINATION</code>
|
||||||
- To redirect output of FD number N to a file which will be appended, write <code>N\>\>DESTINATION_FILE</code>
|
- To redirect output of FD number N to a file which will be appended, write <code>N\>\>DESTINATION_FILE</code>
|
||||||
|
|
||||||
Example: <code>echo Hello 2\>-</code> and <code>echo Hello ^-</code> are
|
Example: <code>echo Hello 2\>-</code> and <code>echo Hello ^-</code> are
|
||||||
|
@ -230,7 +230,7 @@ Example:
|
||||||
|
|
||||||
<code>emacs \&</code>
|
<code>emacs \&</code>
|
||||||
|
|
||||||
will start the emacs text editor in the background.
|
will start the emacs text editor in the background.
|
||||||
|
|
||||||
\subsection syntax-job-control Job control
|
\subsection syntax-job-control Job control
|
||||||
|
|
||||||
|
@ -323,10 +323,10 @@ function already be loaded, i.e. a circular dependency.
|
||||||
\subsection syntax-conditional Conditional execution of code
|
\subsection syntax-conditional Conditional execution of code
|
||||||
|
|
||||||
There are four fish builtins that let you execute commands only if a
|
There are four fish builtins that let you execute commands only if a
|
||||||
specific criterion is met. These builtins are
|
specific criterion is met. These builtins are
|
||||||
<a href="commands.html#if">if</a>,
|
<a href="commands.html#if">if</a>,
|
||||||
<a href="commands.html#switch">switch</a>,
|
<a href="commands.html#switch">switch</a>,
|
||||||
<a href="commands.html#and">and</a> and
|
<a href="commands.html#and">and</a> and
|
||||||
<a href="commands.html#or">or</a>.
|
<a href="commands.html#or">or</a>.
|
||||||
|
|
||||||
The \c switch command is used to execute one of possibly many blocks
|
The \c switch command is used to execute one of possibly many blocks
|
||||||
|
@ -335,7 +335,7 @@ for <a href="commands.html#switch">switch</a> for more information.
|
||||||
|
|
||||||
The other conditionals use the <a href='#variables-status'>exit
|
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
|
status</a> of a command to decide if a command or a block of commands
|
||||||
should be executed. See the documentation for
|
should be executed. See the documentation for
|
||||||
<a href="commands.html#if">if</a>, <a href="commands.html#and">and</a>
|
<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.
|
and <a href="commands.html#or">or</a> for more information.
|
||||||
|
|
||||||
|
@ -392,13 +392,13 @@ These are the general purpose tab completions that \c fish provides:
|
||||||
of these completions are simple options like the \c -l option for \c
|
of these completions are simple options like the \c -l option for \c
|
||||||
ls, but some are more advanced. The latter include:
|
ls, but some are more advanced. The latter include:
|
||||||
|
|
||||||
- The programs 'man' and 'whatis' show all installed
|
- The programs 'man' and 'whatis' show all installed
|
||||||
manual pages as completions.
|
manual pages as completions.
|
||||||
- The 'make' program uses all targets in the Makefile in
|
- The 'make' program uses all targets in the Makefile in
|
||||||
the current directory as completions.
|
the current directory as completions.
|
||||||
- The 'mount' command uses all mount points specified in fstab as completions.
|
- The 'mount' command uses all mount points specified in fstab as completions.
|
||||||
- The 'ssh' command uses all hosts 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)
|
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 '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.
|
- The \c apt-get, \c rpm and \c yum commands use all installed packages as completions.
|
||||||
|
|
||||||
|
@ -415,7 +415,7 @@ this can be specified as <code>complete -c myprog -a 'start
|
||||||
stop'</code>. The argument to the \c -a switch is always a single
|
stop'</code>. The argument to the \c -a switch is always a single
|
||||||
string. At completion time, it will be tokenized on spaces and tabs,
|
string. At completion time, it will be tokenized on spaces and tabs,
|
||||||
and variable expansion, command substitution and other forms of
|
and variable expansion, command substitution and other forms of
|
||||||
parameter expansion will take place.
|
parameter expansion will take place.
|
||||||
|
|
||||||
Fish has a special syntax to support specifying switches accepted by a
|
Fish has a special syntax to support specifying switches accepted by a
|
||||||
command. The switches \c -s, \c -l and \c -o are used to specify a
|
command. The switches \c -s, \c -l and \c -o are used to specify a
|
||||||
|
@ -532,7 +532,7 @@ performing wildcard matching on files, inserting the value of
|
||||||
environment variables into the parameter or even using the output of
|
environment variables into the parameter or even using the output of
|
||||||
another command as a parameter list.
|
another command as a parameter list.
|
||||||
|
|
||||||
\subsection expand-wildcard Wildcards
|
\subsection expand-wildcard Wildcards
|
||||||
|
|
||||||
If a star (*) or a question mark (?) is present in the parameter, \c
|
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
|
fish attempts to match the given parameter to any files in such a
|
||||||
|
@ -609,7 +609,7 @@ href="#variables"> Environment variables</a> section.
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
<code> echo \$HOME</code> prints the home directory of the current
|
<code> echo \$HOME</code> prints the home directory of the current
|
||||||
user.
|
user.
|
||||||
|
|
||||||
If you wish to combine environment variables with text, you can
|
If you wish to combine environment variables with text, you can
|
||||||
encase the variables within braces to embed a variable inside running
|
encase the variables within braces to embed a variable inside running
|
||||||
|
@ -687,9 +687,9 @@ performed:
|
||||||
- If the string is the entire word \c self, the shells pid is the result
|
- If the string is the entire word \c self, the shells pid is the result
|
||||||
- Otherwise, if the string is the id of a job, the result is the process
|
- Otherwise, if the string is the id of a job, the result is the process
|
||||||
group id of the job.
|
group id of the job.
|
||||||
- Otherwise, if any child processes match the specified string, their
|
- Otherwise, if any child processes match the specified string, their
|
||||||
pids are the result of the expansion.
|
pids are the result of the expansion.
|
||||||
- Otherwise, if any processes owned by the user match the specified
|
- Otherwise, if any processes owned by the user match the specified
|
||||||
string, their pids are the result of the expansion.
|
string, their pids are the result of the expansion.
|
||||||
|
|
||||||
This form of expansion is useful for commands like kill and fg, which
|
This form of expansion is useful for commands like kill and fg, which
|
||||||
|
@ -739,7 +739,7 @@ expansion</a>.
|
||||||
To set a variable value, use the <a href="commands.html#set"> \c set
|
To set a variable value, use the <a href="commands.html#set"> \c set
|
||||||
command</a>.
|
command</a>.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
To set the variable \c smurf_color to the value \c blue, use the command
|
To set the variable \c smurf_color to the value \c blue, use the command
|
||||||
<code>set smurf_color blue</code>.
|
<code>set smurf_color blue</code>.
|
||||||
|
@ -869,7 +869,7 @@ echo $PATH[3]
|
||||||
|
|
||||||
Note that array indices start at 1 in fish, not 0, as is more common
|
Note that array indices start at 1 in fish, not 0, as is more common
|
||||||
in other languages. This is because many common Unix tools like seq
|
in other languages. This is because many common Unix tools like seq
|
||||||
are more suited to such use.
|
are more suited to such use.
|
||||||
|
|
||||||
If you do not use any brackets, all the elements of the array will be
|
If you do not use any brackets, all the elements of the array will be
|
||||||
written as separate items. This means you can easily iterate over an
|
written as separate items. This means you can easily iterate over an
|
||||||
|
@ -921,13 +921,13 @@ certain environment variables.
|
||||||
|
|
||||||
\c fish also sends additional information to the user through the
|
\c fish also sends additional information to the user through the
|
||||||
values of certain environment variables. The user can not change the
|
values of certain environment variables. The user can not change the
|
||||||
values of most of these variables.
|
values of most of these variables.
|
||||||
|
|
||||||
- \c _, which is the name of the currently running command.
|
- \c _, which is the name of the currently running command.
|
||||||
- \c argv, which is an array of arguments to the shell or function. \c argv is only defined when inside a function call, or if fish was invoked with a list of arguments, like 'fish myscript.fish foo bar'. This variable can be changed by the user.
|
- \c argv, which is an array of arguments to the shell or function. \c argv is only defined when inside a function call, or if fish was invoked with a list of arguments, like 'fish myscript.fish foo bar'. This variable can be changed by the user.
|
||||||
- \c history, which is an array containing the last commands that where entered.
|
- \c history, which is an array containing the last commands that where entered.
|
||||||
- \c HOME, which is the users home directory. This variable can only be changed by the root user.
|
- \c HOME, which is the users home directory. This variable can only be changed by the root user.
|
||||||
- \c PWD, which is the current working directory.
|
- \c PWD, which is the current working directory.
|
||||||
- \c status, which is the exit status of the last foreground job to exit. If the job was terminated through a signal, the exit status will be 128 plus the signal number.
|
- \c status, which is the exit status of the last foreground job to exit. If the job was terminated through a signal, the exit status will be 128 plus the signal number.
|
||||||
- \c USER, which is the username. This variable can only be changed by the root user.
|
- \c USER, which is the username. This variable can only be changed by the root user.
|
||||||
|
|
||||||
|
@ -1024,7 +1024,7 @@ variables set the specified aspect of the locale information. LANG
|
||||||
is a fallback value, it will be used if none of the LC_ variables are
|
is a fallback value, it will be used if none of the LC_ variables are
|
||||||
specified.
|
specified.
|
||||||
|
|
||||||
\section builtin-overview Builtins
|
\section builtin-overview Builtins
|
||||||
|
|
||||||
Many other shells have a large library of builtin commands. Most of
|
Many other shells have a large library of builtin commands. Most of
|
||||||
these commands are also available as standalone commands, but have
|
these commands are also available as standalone commands, but have
|
||||||
|
@ -1042,7 +1042,7 @@ switch of the command.
|
||||||
|
|
||||||
The \c fish editor features copy and paste, a searchable history and
|
The \c fish editor features copy and paste, a searchable history and
|
||||||
many editor functions that can be bound to special keyboard
|
many editor functions that can be bound to special keyboard
|
||||||
shortcuts. The most important keybinding is probably the tab key, which is bound to the complete function.
|
shortcuts. The most important keybinding is probably the tab key, which is bound to the complete function.
|
||||||
Here are some of the commands available in the editor:
|
Here are some of the commands available in the editor:
|
||||||
|
|
||||||
- Tab completes the current token
|
- Tab completes the current token
|
||||||
|
@ -1060,12 +1060,12 @@ Here are some of the commands available in the editor:
|
||||||
- Ctrl-l clear and repaint screen
|
- Ctrl-l clear and repaint screen
|
||||||
- Ctrl-w move previous word to the <a href="#killring">killring</a>
|
- Ctrl-w move previous word to the <a href="#killring">killring</a>
|
||||||
- Alt-d move next word to the <a href="#killring">killring</a>
|
- Alt-d move next word to the <a href="#killring">killring</a>
|
||||||
- Alt-w prints a short description of the command under the cursor
|
- Alt-w prints a short description of the command under the cursor
|
||||||
- Alt-l lists the contents of the current directory, unless the cursor is over a directory argument, in which case the contents of that directory will be listed
|
- Alt-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.
|
- Alt-p adds the string '| less;' to the end of the job under the cursor. The result is that the output of the command will be paged.
|
||||||
|
|
||||||
You can change these key bindings using the
|
You can change these key bindings using the
|
||||||
<a href="commands.html#bind">bind</a> builtin command.
|
<a href="commands.html#bind">bind</a> builtin command.
|
||||||
|
|
||||||
|
|
||||||
- \c backward-char, moves one character to the left
|
- \c backward-char, moves one character to the left
|
||||||
|
@ -1096,7 +1096,7 @@ If such a script produces output, the script needs to finish by
|
||||||
calling 'commandline -f repaint' in order to tell fish that a repaint
|
calling 'commandline -f repaint' in order to tell fish that a repaint
|
||||||
is in order.
|
is in order.
|
||||||
|
|
||||||
\subsection killring Copy and paste (Kill Ring)
|
\subsection killring Copy and paste (Kill Ring)
|
||||||
|
|
||||||
\c fish uses an Emacs style kill ring for copy and paste
|
\c fish uses an Emacs style kill ring for copy and paste
|
||||||
functionality. Use Ctrl-K to cut from the current cursor position to
|
functionality. Use Ctrl-K to cut from the current cursor position to
|
||||||
|
@ -1107,7 +1107,7 @@ Meta-Y to rotate to the previous kill.
|
||||||
|
|
||||||
If the environment variable DISPLAY is set, \c fish will try to
|
If the environment variable DISPLAY is set, \c fish will try to
|
||||||
connect to the X-windows server specified by this variable, and use
|
connect to the X-windows server specified by this variable, and use
|
||||||
the clipboard on the X server for copying and pasting.
|
the clipboard on the X server for copying and pasting.
|
||||||
|
|
||||||
\subsection history Searchable history
|
\subsection history Searchable history
|
||||||
|
|
||||||
|
@ -1158,7 +1158,7 @@ graphical user interface from the terminal, and then be able to
|
||||||
continue using the shell. In such cases, there are several ways in
|
continue using the shell. In such cases, there are several ways in
|
||||||
which the user can change <code>fish</code>'s behavior.
|
which the user can change <code>fish</code>'s behavior.
|
||||||
|
|
||||||
-# By ending a command with the \& (ampersand) symbol, the user tells \c fish to put the specified command into the background. A background process will be run simultaneous with \c fish. \c fish will retain control of the terminal, so the program will not be able to read from the keyboard.
|
-# By ending a command with the \& (ampersand) symbol, the user tells \c fish to put the specified command into the background. A background process will be run simultaneous with \c fish. \c fish will retain control of the terminal, so the program will not be able to read from the keyboard.
|
||||||
-# By pressing ^Z, the user stops a currently running foreground program and returns control to \c fish. Some programs do not support this feature, or remap it to another key. Gnu emacs uses ^X z to stop running.
|
-# By pressing ^Z, the user stops a currently running foreground program and returns control to \c fish. Some programs do not support this feature, or remap it to another key. Gnu emacs uses ^X z to stop running.
|
||||||
-# By using the <a href="commands.html#fg">fg</a> and <a href="commands.html#bg">bg</a> builtin commands, the user can send any currently running job into the foreground or background.
|
-# By using the <a href="commands.html#fg">fg</a> and <a href="commands.html#bg">bg</a> builtin commands, the user can send any currently running job into the foreground or background.
|
||||||
|
|
||||||
|
@ -1247,7 +1247,7 @@ returning to the shell) when the \c fish_prompt function is called.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
<p>
|
<p>
|
||||||
The default \c fish title is
|
The default \c fish title is
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<pre>
|
<pre>
|
||||||
|
@ -1379,9 +1379,9 @@ href='fish-users@lists.sf.net'>fish-users@lists.sf.net</a>.
|
||||||
\subsection todo-features Missing features
|
\subsection todo-features Missing features
|
||||||
|
|
||||||
- Complete vi-mode key bindings
|
- Complete vi-mode key bindings
|
||||||
- More completions (for example konsole, gnome-terminal,
|
- More completions (for example konsole, gnome-terminal,
|
||||||
rlogin, rsync, arch, finger, bibtex, aspell, xpdf,
|
rlogin, rsync, arch, finger, bibtex, aspell, xpdf,
|
||||||
compress, wine, dig, batch,
|
compress, wine, dig, batch,
|
||||||
g++, javac, java, gcj, lpr, doxygen, whois)
|
g++, javac, java, gcj, lpr, doxygen, whois)
|
||||||
- Undo support
|
- Undo support
|
||||||
- wait shellscript
|
- wait shellscript
|
||||||
|
@ -1391,7 +1391,7 @@ g++, javac, java, gcj, lpr, doxygen, whois)
|
||||||
|
|
||||||
\subsection todo-possible Possible features
|
\subsection todo-possible Possible features
|
||||||
|
|
||||||
- mouse support like zsh has with http://stchaz.free.fr/mouse.zsh
|
- mouse support like zsh has with http://stchaz.free.fr/mouse.zsh
|
||||||
installed would be awesome
|
installed would be awesome
|
||||||
- suggest a completion on unique matches by writing it out in an understated color
|
- suggest a completion on unique matches by writing it out in an understated color
|
||||||
- Highlight beginning/end of block when moving over a block command
|
- Highlight beginning/end of block when moving over a block command
|
||||||
|
@ -1408,7 +1408,7 @@ g++, javac, java, gcj, lpr, doxygen, whois)
|
||||||
- History could reload itself when the file is updated. This would need to be done in a clever way to avoid chain reactions
|
- 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 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 code validation functions should be moved from the parser to parse_util.
|
||||||
- Try to remove more malloc calls to reduce memory usage. The time_t arrays used by the autoloader sound like a good candidate.
|
- Try to remove more malloc calls to reduce memory usage. The time_t arrays used by the autoloader sound like a good candidate.
|
||||||
- The code validator should warn about unknown commands.
|
- The code validator should warn about unknown commands.
|
||||||
- Auto-newlines
|
- Auto-newlines
|
||||||
- A fault injector could be written to increase robustness and testing of error recovery paths
|
- A fault injector could be written to increase robustness and testing of error recovery paths
|
||||||
|
@ -1417,7 +1417,7 @@ g++, javac, java, gcj, lpr, doxygen, whois)
|
||||||
- exec_subshell should be either merged with eval or moved to parser.c
|
- 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.
|
- 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
|
- Make the history search support incremental searching
|
||||||
- An automatic logout feature
|
- An automatic logout feature
|
||||||
- Make tab completions completely silent by default, i.e. kill stderr when running completion commands. This needs to be overridalbe for debugging purposes.
|
- Make tab completions completely silent by default, i.e. kill stderr when running completion commands. This needs to be overridalbe for debugging purposes.
|
||||||
- Move history to an environment variable
|
- Move history to an environment variable
|
||||||
|
|
||||||
|
@ -1426,8 +1426,8 @@ g++, javac, java, gcj, lpr, doxygen, whois)
|
||||||
- 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.
|
- 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-'
|
- 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.
|
- 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.
|
- The completion autoloader does not remember which completions where actually autoloaded, and may unload manually specified completions.
|
||||||
- There have been stray reports of issues with strange values of the PATH variable during startup.
|
- There have been stray reports of issues with strange values of the PATH variable during startup.
|
||||||
- bindings in config.fish are overwritten by default key bindings.
|
- bindings in config.fish are overwritten by default key bindings.
|
||||||
- Adding 'bind -k ...' doesn't overwrite non-keybinding binds of the same sequence.
|
- Adding 'bind -k ...' doesn't overwrite non-keybinding binds of the same sequence.
|
||||||
- History file does not remove duplicates.
|
- History file does not remove duplicates.
|
||||||
|
|
|
@ -14,7 +14,7 @@ Version 2, June 1991
|
||||||
</P>
|
</P>
|
||||||
|
|
||||||
<PRE>
|
<PRE>
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
@ -447,7 +447,7 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
<h2>License for XSel</h2>
|
<h2>License for XSel</h2>
|
||||||
|
|
||||||
The XSel command, written and copyrighted by Conrad Parker, is
|
The XSel command, written and copyrighted by Conrad Parker, is
|
||||||
distributed together with \c fish.
|
distributed together with \c fish.
|
||||||
|
|
||||||
|
|
||||||
It is Copyright (C) 2001 Conrad Parker <conrad@vergenet.net>
|
It is Copyright (C) 2001 Conrad Parker <conrad@vergenet.net>
|
||||||
|
@ -802,7 +802,7 @@ of these things:
|
||||||
that the user who changes the contents of definitions files in the
|
that the user who changes the contents of definitions files in the
|
||||||
Library will not necessarily be able to recompile the application
|
Library will not necessarily be able to recompile the application
|
||||||
to use the modified definitions.)
|
to use the modified definitions.)
|
||||||
|
|
||||||
<LI><STRONG>b)</STRONG> Use a suitable shared library mechanism for linking with the
|
<LI><STRONG>b)</STRONG> Use a suitable shared library mechanism for linking with the
|
||||||
Library. A suitable mechanism is one that (1) uses at run time a
|
Library. A suitable mechanism is one that (1) uses at run time a
|
||||||
copy of the library already present on the user's computer system,
|
copy of the library already present on the user's computer system,
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
math is used to perform mathematical calculations. It is only a very
|
math is used to perform mathematical calculations. It is only a very
|
||||||
thin wrapper for the bc program, that makes it possible to specify an
|
thin wrapper for the bc program, that makes it possible to specify an
|
||||||
expression from the command line without using non-standard extensions
|
expression from the command line without using non-standard extensions
|
||||||
or a pipeline. Simply use a command like <code>math 1+1</code>.
|
or a pipeline. Simply use a command like <code>math 1+1</code>.
|
||||||
|
|
||||||
For a description of the syntax supported by math, see the manual for
|
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
|
the bc program. Keep in mind that parameter expansion takes place on
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
\subsection mimedb-description Description
|
\subsection mimedb-description Description
|
||||||
|
|
||||||
- \c FILES is a list of files to analyse
|
- \c FILES is a list of files to analyse
|
||||||
- \c -t, \c --input-file-data the specified files type should be determined both by their filename and by their contents (Default)
|
- \c -t, \c --input-file-data the specified files type should be determined both by their filename and by their contents (Default)
|
||||||
- \c -f, \c --input-filename the specified files type should be determined by their filename
|
- \c -f, \c --input-filename the specified files type should be determined by their filename
|
||||||
- \c -i, \c --input-mime the arguments are not files but mimetypes
|
- \c -i, \c --input-mime the arguments are not files but mimetypes
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
\subsection not-description Description
|
\subsection not-description Description
|
||||||
|
|
||||||
The \c not builtin is used to negate the exit status of another command.
|
The \c not builtin is used to negate the exit status of another command.
|
||||||
|
|
||||||
\subsection not-example Example
|
\subsection not-example Example
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
\subsection popd-synopsis Synopsis
|
\subsection popd-synopsis Synopsis
|
||||||
<tt>popd</tt>
|
<tt>popd</tt>
|
||||||
|
|
||||||
\subsection popd-description Description
|
\subsection popd-description Description
|
||||||
<tt>popd</tt> removes the top directory from the directory stack and
|
<tt>popd</tt> removes the top directory from the directory stack and
|
||||||
cd's to the new top directory.
|
cd's to the new top directory.
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
\subsection prevd-synopsis Synopsis
|
\subsection prevd-synopsis Synopsis
|
||||||
<tt>prevd [-l | --list] [pos]</tt>
|
<tt>prevd [-l | --list] [pos]</tt>
|
||||||
|
|
||||||
\subsection prevd-description Description
|
\subsection prevd-description Description
|
||||||
|
|
||||||
<tt>prevd</tt> moves backwards <tt>pos</tt> positions in the history
|
<tt>prevd</tt> moves backwards <tt>pos</tt> positions in the history
|
||||||
of visited directories; if the beginning of the history has been hit,
|
of visited directories; if the beginning of the history has been hit,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
\subsection pushd-synopsis Synopsis
|
\subsection pushd-synopsis Synopsis
|
||||||
<tt>pushd [DIRECTORY]</tt>
|
<tt>pushd [DIRECTORY]</tt>
|
||||||
|
|
||||||
\subsection pushd-description Description
|
\subsection pushd-description Description
|
||||||
The <tt>pushd</tt> function adds DIRECTORY to the top of the directory stack
|
The <tt>pushd</tt> function adds DIRECTORY to the top of the directory stack
|
||||||
and makes it the current directory. Use <tt>popd</tt> to pop it off and and
|
and makes it the current directory. Use <tt>popd</tt> to pop it off and and
|
||||||
return to the original directory.
|
return to the original directory.
|
||||||
|
|
|
@ -21,4 +21,4 @@ for i in (seq (random) -1 1)
|
||||||
echo $i
|
echo $i
|
||||||
sleep
|
sleep
|
||||||
end
|
end
|
||||||
</pre>
|
</pre>
|
||||||
|
|
|
@ -6,12 +6,12 @@
|
||||||
\subsection read-description Description
|
\subsection read-description Description
|
||||||
|
|
||||||
The <tt>read</tt> builtin causes fish to read one line from standard
|
The <tt>read</tt> builtin causes fish to read one line from standard
|
||||||
input and store the result in one or more environment variables.
|
input and store the result in one or more environment variables.
|
||||||
|
|
||||||
- <tt>-c CMD</tt> or <tt>--command=CMD</tt> specifies that the initial string in the interactive mode command buffer should be CMD.
|
- <tt>-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>-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>-g</tt> or <tt>--global</tt> specifies that the variables will be made global.
|
||||||
- <tt>-m NAME</tt> or <tt>--mode-name=NAME</tt> specifies that the name NAME should be used to save/load the history file. If NAME is fish, the regular fish history will be available.
|
- <tt>-m NAME</tt> or <tt>--mode-name=NAME</tt> specifies that the name NAME should be used to save/load the history file. If NAME is fish, the regular fish history will be available.
|
||||||
- <tt>-p PROMPT_CMD</tt> or <tt>--prompt=PROMPT_CMD</tt> specifies that the output of the shell command PROMPT_CMD should be used as the prompt for the interactive mode prompt. The default prompt command is <tt>set_color green; echo read; set_color normal; echo "> "</tt>.
|
- <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>-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>--unexport</code> causes the specified environment not to be exported to child processes
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
\subsection return-synopsis Synopsis
|
\subsection return-synopsis Synopsis
|
||||||
<tt>function NAME; [COMMANDS...;] return [STATUS]; [COMMANDS...;] end</tt>
|
<tt>function NAME; [COMMANDS...;] return [STATUS]; [COMMANDS...;] end</tt>
|
||||||
|
|
||||||
\subsection return-description Description
|
\subsection return-description Description
|
||||||
|
|
||||||
The \c return builtin is used to halt a currently running function. It
|
The \c return builtin is used to halt a currently running function. It
|
||||||
is usually added inside of a conditional block such as an <a
|
is usually added inside of a conditional block such as an <a
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
Change the foreground and/or background color of the terminal.
|
Change the foreground and/or background color of the terminal.
|
||||||
COLOR is one of black, red, green, brown, yellow, blue, magenta,
|
COLOR is one of black, red, green, brown, yellow, blue, magenta,
|
||||||
purple, cyan, white and normal.
|
purple, cyan, white and normal.
|
||||||
|
|
||||||
- \c -b, \c --background Set the background color
|
- \c -b, \c --background Set the background color
|
||||||
- \c -c, \c --print-colors Prints a list of all valid color names
|
- \c -c, \c --print-colors Prints a list of all valid color names
|
||||||
|
@ -26,7 +26,7 @@ in a grey font color, while <code>set_color --bold white</code> will
|
||||||
result in a white font color.
|
result in a white font color.
|
||||||
|
|
||||||
Not all terminal emulators support all these features. This is not a
|
Not all terminal emulators support all these features. This is not a
|
||||||
bug in set_color but a missing feature in the terminal emulator.
|
bug in set_color but a missing feature in the terminal emulator.
|
||||||
|
|
||||||
set_color uses the terminfo database to look up how to change terminal
|
set_color uses the terminfo database to look up how to change terminal
|
||||||
colors on whatever terminal is in use. Some systems have old and
|
colors on whatever terminal is in use. Some systems have old and
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
\subsection source-synopsis Synopsis
|
\subsection source-synopsis Synopsis
|
||||||
<tt>. FILENAME [ARGUMENTS...]</tt>
|
<tt>. FILENAME [ARGUMENTS...]</tt>
|
||||||
|
|
||||||
\subsection source-description Description
|
\subsection source-description Description
|
||||||
|
|
||||||
Evaluates the commands of the specified file in the current
|
Evaluates the commands of the specified file in the current
|
||||||
shell. This is different from starting a new process to perform the
|
shell. This is different from starting a new process to perform the
|
||||||
|
|
|
@ -27,7 +27,7 @@ Note that not all these limits are available in all operating systems.
|
||||||
The value of limit can be a number in the unit specified for
|
The value of limit can be a number in the unit specified for
|
||||||
the resource or one of the special values hard, soft, or unlimited,
|
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
|
which stand for the current hard limit, the current soft limit, and no
|
||||||
limit, respectively.
|
limit, respectively.
|
||||||
|
|
||||||
If limit is given, it is the new value of the specified resource. If
|
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,
|
no option is given, then -f is assumed. Values are in kilobytes,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
\section vared vared - interactively edit the value of an environment variable
|
\section vared vared - interactively edit the value of an environment variable
|
||||||
|
|
||||||
\subsection vared-synopsis Synopsis
|
\subsection vared-synopsis Synopsis
|
||||||
<tt>vared VARIABLE_NAME</tt>
|
<tt>vared VARIABLE_NAME</tt>
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
vared is used to interactively edit the value of an environment
|
vared is used to interactively edit the value of an environment
|
||||||
variable. Array variables as a whole can not be edited using vared,
|
variable. Array variables as a whole can not be edited using vared,
|
||||||
but individual array elements can.
|
but individual array elements can.
|
||||||
|
|
||||||
\subsection vared-example Example
|
\subsection vared-example Example
|
||||||
|
|
||||||
|
|
6
env.h
6
env.h
|
@ -63,7 +63,7 @@ void env_destroy();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set the value of the environment variable whose name matches key to val.
|
Set the value of the environment variable whose name matches key to val.
|
||||||
|
|
||||||
Memory policy: All keys and values are copied, the parameters can and should be freed by the caller afterwards
|
Memory policy: All keys and values are copied, the parameters can and should be freed by the caller afterwards
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ void env_destroy();
|
||||||
* ENV_INVALID, the variable name or mode was invalid
|
* ENV_INVALID, the variable name or mode was invalid
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int env_set( const wchar_t *key,
|
int env_set( const wchar_t *key,
|
||||||
const wchar_t *val,
|
const wchar_t *val,
|
||||||
int mode );
|
int mode );
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ int env_exist( const wchar_t *key, int mode );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Remove environemnt variable
|
Remove environemnt variable
|
||||||
|
|
||||||
\param key The name of the variable to remove
|
\param key The name of the variable to remove
|
||||||
\param mode should be ENV_USER if this is a remove request from the user, 0 otherwise. If this is a user request, read-only variables can not be removed. The mode may also specify the scope of the variable that should be erased.
|
\param mode should be ENV_USER if this is a remove request from the user, 0 otherwise. If this is a user request, read-only variables can not be removed. The mode may also specify the scope of the variable that should be erased.
|
||||||
|
|
||||||
|
|
144
env_universal.c
144
env_universal.c
|
@ -83,27 +83,27 @@ static int get_socket( int fork_ok )
|
||||||
{
|
{
|
||||||
int s, len;
|
int s, len;
|
||||||
struct sockaddr_un local;
|
struct sockaddr_un local;
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
wchar_t *wdir;
|
wchar_t *wdir;
|
||||||
wchar_t *wuname;
|
wchar_t *wuname;
|
||||||
char *dir =0, *uname=0;
|
char *dir =0, *uname=0;
|
||||||
|
|
||||||
get_socket_count++;
|
get_socket_count++;
|
||||||
wdir = path;
|
wdir = path;
|
||||||
wuname = user;
|
wuname = user;
|
||||||
|
|
||||||
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
||||||
{
|
{
|
||||||
wperror(L"socket");
|
wperror(L"socket");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( wdir )
|
if( wdir )
|
||||||
dir = wcs2str(wdir );
|
dir = wcs2str(wdir );
|
||||||
else
|
else
|
||||||
dir = strdup("/tmp");
|
dir = strdup("/tmp");
|
||||||
|
|
||||||
if( wuname )
|
if( wuname )
|
||||||
uname = wcs2str(wuname );
|
uname = wcs2str(wuname );
|
||||||
else
|
else
|
||||||
|
@ -112,53 +112,53 @@ static int get_socket( int fork_ok )
|
||||||
pw = getpwuid( getuid() );
|
pw = getpwuid( getuid() );
|
||||||
uname = strdup( pw->pw_name );
|
uname = strdup( pw->pw_name );
|
||||||
}
|
}
|
||||||
|
|
||||||
name = malloc( strlen(dir) +
|
name = malloc( strlen(dir) +
|
||||||
strlen(uname) +
|
strlen(uname) +
|
||||||
strlen(SOCK_FILENAME) +
|
strlen(SOCK_FILENAME) +
|
||||||
2 );
|
2 );
|
||||||
|
|
||||||
strcpy( name, dir );
|
strcpy( name, dir );
|
||||||
strcat( name, "/" );
|
strcat( name, "/" );
|
||||||
strcat( name, SOCK_FILENAME );
|
strcat( name, SOCK_FILENAME );
|
||||||
strcat( name, uname );
|
strcat( name, uname );
|
||||||
|
|
||||||
free( dir );
|
free( dir );
|
||||||
free( uname );
|
free( uname );
|
||||||
|
|
||||||
debug( 3, L"Connect to socket %s at fd %2", name, s );
|
debug( 3, L"Connect to socket %s at fd %2", name, s );
|
||||||
|
|
||||||
local.sun_family = AF_UNIX;
|
local.sun_family = AF_UNIX;
|
||||||
strcpy(local.sun_path, name );
|
strcpy(local.sun_path, name );
|
||||||
free( name );
|
free( name );
|
||||||
len = sizeof(local);
|
len = sizeof(local);
|
||||||
|
|
||||||
if( connect( s, (struct sockaddr *)&local, len) == -1 )
|
if( connect( s, (struct sockaddr *)&local, len) == -1 )
|
||||||
{
|
{
|
||||||
close( s );
|
close( s );
|
||||||
if( fork_ok && start_fishd )
|
if( fork_ok && start_fishd )
|
||||||
{
|
{
|
||||||
debug( 2, L"Could not connect to socket %d, starting fishd", s );
|
debug( 2, L"Could not connect to socket %d, starting fishd", s );
|
||||||
|
|
||||||
start_fishd();
|
start_fishd();
|
||||||
|
|
||||||
return get_socket( 0 );
|
return get_socket( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
debug( 1, L"Could not connect to universal variable server, already tried manual restart (or no command supplied). You will not be able to share variable values between fish sessions. Is fish properly installed?" );
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (fcntl( s, F_SETFL, O_NONBLOCK ) != 0) || (fcntl( s, F_SETFD, FD_CLOEXEC ) != 0) )
|
if( (fcntl( s, F_SETFL, O_NONBLOCK ) != 0) || (fcntl( s, F_SETFD, FD_CLOEXEC ) != 0) )
|
||||||
{
|
{
|
||||||
wperror( L"fcntl" );
|
wperror( L"fcntl" );
|
||||||
close( s );
|
close( s );
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug( 3, L"Connected to fd %d", s );
|
debug( 3, L"Connected to fd %d", s );
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ static int get_socket( int fork_ok )
|
||||||
Callback function used whenever a new fishd message is recieved
|
Callback function used whenever a new fishd message is recieved
|
||||||
*/
|
*/
|
||||||
static void callback( int type, const wchar_t *name, const wchar_t *val )
|
static void callback( int type, const wchar_t *name, const wchar_t *val )
|
||||||
{
|
{
|
||||||
if( type == BARRIER_REPLY )
|
if( type == BARRIER_REPLY )
|
||||||
{
|
{
|
||||||
barrier_reply = 1;
|
barrier_reply = 1;
|
||||||
|
@ -174,8 +174,8 @@ static void callback( int type, const wchar_t *name, const wchar_t *val )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( external_callback )
|
if( external_callback )
|
||||||
external_callback( type, name, val );
|
external_callback( type, name, val );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -186,21 +186,21 @@ static void check_connection()
|
||||||
{
|
{
|
||||||
if( !init )
|
if( !init )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( env_universal_server.killme )
|
if( env_universal_server.killme )
|
||||||
{
|
{
|
||||||
debug( 3, L"Lost connection to universal variable server." );
|
debug( 3, L"Lost connection to universal variable server." );
|
||||||
|
|
||||||
if( close( env_universal_server.fd ) )
|
if( close( env_universal_server.fd ) )
|
||||||
{
|
{
|
||||||
wperror( L"close" );
|
wperror( L"close" );
|
||||||
}
|
}
|
||||||
|
|
||||||
env_universal_server.fd = -1;
|
env_universal_server.fd = -1;
|
||||||
env_universal_server.killme=0;
|
env_universal_server.killme=0;
|
||||||
env_universal_server.input.used=0;
|
env_universal_server.input.used=0;
|
||||||
env_universal_read_all();
|
env_universal_read_all();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -210,10 +210,10 @@ static void env_universal_remove_all()
|
||||||
{
|
{
|
||||||
array_list_t lst;
|
array_list_t lst;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
al_init( &lst );
|
al_init( &lst );
|
||||||
|
|
||||||
env_universal_common_get_names( &lst,
|
env_universal_common_get_names( &lst,
|
||||||
1,
|
1,
|
||||||
1 );
|
1 );
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ static void env_universal_remove_all()
|
||||||
}
|
}
|
||||||
|
|
||||||
al_destroy( &lst );
|
al_destroy( &lst );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -237,9 +237,9 @@ static void reconnect()
|
||||||
{
|
{
|
||||||
if( get_socket_count >= RECONNECT_COUNT )
|
if( get_socket_count >= RECONNECT_COUNT )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
debug( 3, L"Get new fishd connection" );
|
debug( 3, L"Get new fishd connection" );
|
||||||
|
|
||||||
init = 0;
|
init = 0;
|
||||||
env_universal_server.buffer_consumed = env_universal_server.buffer_used = 0;
|
env_universal_server.buffer_consumed = env_universal_server.buffer_used = 0;
|
||||||
env_universal_server.fd = get_socket(1);
|
env_universal_server.fd = get_socket(1);
|
||||||
|
@ -252,22 +252,22 @@ static void reconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void env_universal_init( wchar_t * p,
|
void env_universal_init( wchar_t * p,
|
||||||
wchar_t *u,
|
wchar_t *u,
|
||||||
void (*sf)(),
|
void (*sf)(),
|
||||||
void (*cb)( int type, const wchar_t *name, const wchar_t *val ))
|
void (*cb)( int type, const wchar_t *name, const wchar_t *val ))
|
||||||
{
|
{
|
||||||
path=p;
|
path=p;
|
||||||
user=u;
|
user=u;
|
||||||
start_fishd=sf;
|
start_fishd=sf;
|
||||||
external_callback = cb;
|
external_callback = cb;
|
||||||
|
|
||||||
connection_init( &env_universal_server, -1 );
|
connection_init( &env_universal_server, -1 );
|
||||||
|
|
||||||
env_universal_server.fd = get_socket(1);
|
env_universal_server.fd = get_socket(1);
|
||||||
env_universal_common_init( &callback );
|
env_universal_common_init( &callback );
|
||||||
env_universal_read_all();
|
env_universal_read_all();
|
||||||
init = 1;
|
init = 1;
|
||||||
if( env_universal_server.fd >= 0 )
|
if( env_universal_server.fd >= 0 )
|
||||||
{
|
{
|
||||||
env_universal_barrier();
|
env_universal_barrier();
|
||||||
|
@ -285,7 +285,7 @@ void env_universal_destroy()
|
||||||
{
|
{
|
||||||
wperror( L"fcntl" );
|
wperror( L"fcntl" );
|
||||||
}
|
}
|
||||||
try_send_all( &env_universal_server );
|
try_send_all( &env_universal_server );
|
||||||
}
|
}
|
||||||
|
|
||||||
connection_destroy( &env_universal_server );
|
connection_destroy( &env_universal_server );
|
||||||
|
@ -305,22 +305,22 @@ int env_universal_read_all()
|
||||||
|
|
||||||
if( env_universal_server.fd == -1 )
|
if( env_universal_server.fd == -1 )
|
||||||
{
|
{
|
||||||
reconnect();
|
reconnect();
|
||||||
if( env_universal_server.fd == -1 )
|
if( env_universal_server.fd == -1 )
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( env_universal_server.fd != -1 )
|
if( env_universal_server.fd != -1 )
|
||||||
{
|
{
|
||||||
read_message( &env_universal_server );
|
read_message( &env_universal_server );
|
||||||
check_connection();
|
check_connection();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debug( 2, L"No connection to universal variable server" );
|
debug( 2, L"No connection to universal variable server" );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t *env_universal_get( const wchar_t *name )
|
wchar_t *env_universal_get( const wchar_t *name )
|
||||||
|
@ -329,7 +329,7 @@ wchar_t *env_universal_get( const wchar_t *name )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
CHECK( name, 0 );
|
CHECK( name, 0 );
|
||||||
|
|
||||||
return env_universal_common_get( name );
|
return env_universal_common_get( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,7 +339,7 @@ int env_universal_get_export( const wchar_t *name )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
CHECK( name, 0 );
|
CHECK( name, 0 );
|
||||||
|
|
||||||
return env_universal_common_get_export( name );
|
return env_universal_common_get_export( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,19 +366,19 @@ void env_universal_barrier()
|
||||||
debug( 3, L"Create barrier" );
|
debug( 3, L"Create barrier" );
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
try_send_all( &env_universal_server );
|
try_send_all( &env_universal_server );
|
||||||
check_connection();
|
check_connection();
|
||||||
|
|
||||||
if( q_empty( &env_universal_server.unsent ) )
|
if( q_empty( &env_universal_server.unsent ) )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if( env_universal_server.fd == -1 )
|
if( env_universal_server.fd == -1 )
|
||||||
{
|
{
|
||||||
reconnect();
|
reconnect();
|
||||||
debug( 2, L"barrier interrupted, exiting" );
|
debug( 2, L"barrier interrupted, exiting" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FD_ZERO( &fds );
|
FD_ZERO( &fds );
|
||||||
FD_SET( env_universal_server.fd, &fds );
|
FD_SET( env_universal_server.fd, &fds );
|
||||||
select( env_universal_server.fd+1, 0, &fds, 0, 0 );
|
select( env_universal_server.fd+1, 0, &fds, 0, 0 );
|
||||||
|
@ -394,10 +394,10 @@ void env_universal_barrier()
|
||||||
{
|
{
|
||||||
reconnect();
|
reconnect();
|
||||||
debug( 2, L"barrier interrupted, exiting (2)" );
|
debug( 2, L"barrier interrupted, exiting (2)" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FD_ZERO( &fds );
|
FD_ZERO( &fds );
|
||||||
FD_SET( env_universal_server.fd, &fds );
|
FD_SET( env_universal_server.fd, &fds );
|
||||||
select( env_universal_server.fd+1, &fds, 0, 0, 0 );
|
select( env_universal_server.fd+1, &fds, 0, 0, 0 );
|
||||||
env_universal_read_all();
|
env_universal_read_all();
|
||||||
}
|
}
|
||||||
|
@ -408,12 +408,12 @@ void env_universal_barrier()
|
||||||
void env_universal_set( const wchar_t *name, const wchar_t *value, int export )
|
void env_universal_set( const wchar_t *name, const wchar_t *value, int export )
|
||||||
{
|
{
|
||||||
message_t *msg;
|
message_t *msg;
|
||||||
|
|
||||||
if( !init )
|
if( !init )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CHECK( name, );
|
CHECK( name, );
|
||||||
|
|
||||||
debug( 3, L"env_universal_set( \"%ls\", \"%ls\" )", name, value );
|
debug( 3, L"env_universal_set( \"%ls\", \"%ls\" )", name, value );
|
||||||
|
|
||||||
if( is_dead() )
|
if( is_dead() )
|
||||||
|
@ -422,8 +422,8 @@ void env_universal_set( const wchar_t *name, const wchar_t *value, int export )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
msg = create_message( export?SET_EXPORT:SET,
|
msg = create_message( export?SET_EXPORT:SET,
|
||||||
name,
|
name,
|
||||||
value);
|
value);
|
||||||
|
|
||||||
if( !msg )
|
if( !msg )
|
||||||
|
@ -431,7 +431,7 @@ void env_universal_set( const wchar_t *name, const wchar_t *value, int export )
|
||||||
debug( 1, L"Could not create universal variable message" );
|
debug( 1, L"Could not create universal variable message" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg->count=1;
|
msg->count=1;
|
||||||
q_put( &env_universal_server.unsent, msg );
|
q_put( &env_universal_server.unsent, msg );
|
||||||
env_universal_barrier();
|
env_universal_barrier();
|
||||||
|
@ -441,18 +441,18 @@ void env_universal_set( const wchar_t *name, const wchar_t *value, int export )
|
||||||
int env_universal_remove( const wchar_t *name )
|
int env_universal_remove( const wchar_t *name )
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
message_t *msg;
|
message_t *msg;
|
||||||
if( !init )
|
if( !init )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
CHECK( name, 1 );
|
CHECK( name, 1 );
|
||||||
|
|
||||||
res = !env_universal_common_get( name );
|
res = !env_universal_common_get( name );
|
||||||
debug( 3,
|
debug( 3,
|
||||||
L"env_universal_remove( \"%ls\" )",
|
L"env_universal_remove( \"%ls\" )",
|
||||||
name );
|
name );
|
||||||
|
|
||||||
if( is_dead() )
|
if( is_dead() )
|
||||||
{
|
{
|
||||||
env_universal_common_remove( name );
|
env_universal_common_remove( name );
|
||||||
|
@ -464,7 +464,7 @@ int env_universal_remove( const wchar_t *name )
|
||||||
q_put( &env_universal_server.unsent, msg );
|
q_put( &env_universal_server.unsent, msg );
|
||||||
env_universal_barrier();
|
env_universal_barrier();
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -476,8 +476,8 @@ void env_universal_get_names( array_list_t *l,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CHECK( l, );
|
CHECK( l, );
|
||||||
|
|
||||||
env_universal_common_get_names( l,
|
env_universal_common_get_names( l,
|
||||||
show_exported,
|
show_exported,
|
||||||
show_unexported );
|
show_unexported );
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ int env_universal_get_export( const wchar_t *name );
|
||||||
void env_universal_set( const wchar_t *name, const wchar_t *val, int export );
|
void env_universal_set( const wchar_t *name, const wchar_t *val, int export );
|
||||||
/**
|
/**
|
||||||
Erase a universal variable
|
Erase a universal variable
|
||||||
|
|
||||||
\return zero if the variable existed, and non-zero if the variable did not exist
|
\return zero if the variable existed, and non-zero if the variable did not exist
|
||||||
*/
|
*/
|
||||||
int env_universal_remove( const wchar_t *name );
|
int env_universal_remove( const wchar_t *name );
|
||||||
|
@ -52,7 +52,7 @@ int env_universal_read_all();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Get the names of all universal variables
|
Get the names of all universal variables
|
||||||
|
|
||||||
\param l the list to insert the names into
|
\param l the list to insert the names into
|
||||||
\param show_exported whether exported variables should be shown
|
\param show_exported whether exported variables should be shown
|
||||||
\param show_unexported whether unexported variables should be shown
|
\param show_unexported whether unexported variables should be shown
|
||||||
|
|
|
@ -109,8 +109,8 @@ hash_table_t env_universal_var;
|
||||||
/**
|
/**
|
||||||
Callback function, should be called on all events
|
Callback function, should be called on all events
|
||||||
*/
|
*/
|
||||||
void (*callback)( int type,
|
void (*callback)( int type,
|
||||||
const wchar_t *key,
|
const wchar_t *key,
|
||||||
const wchar_t *val );
|
const wchar_t *val );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -140,8 +140,8 @@ static char *iconv_utf8_names[]=
|
||||||
*/
|
*/
|
||||||
static char *iconv_wide_names_unknown[]=
|
static char *iconv_wide_names_unknown[]=
|
||||||
{
|
{
|
||||||
"wchar_t", "WCHAR_T",
|
"wchar_t", "WCHAR_T",
|
||||||
"wchar", "WCHAR",
|
"wchar", "WCHAR",
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
@ -151,12 +151,12 @@ static char *iconv_wide_names_unknown[]=
|
||||||
*/
|
*/
|
||||||
static char *iconv_wide_names_4[]=
|
static char *iconv_wide_names_4[]=
|
||||||
{
|
{
|
||||||
"wchar_t", "WCHAR_T",
|
"wchar_t", "WCHAR_T",
|
||||||
"wchar", "WCHAR",
|
"wchar", "WCHAR",
|
||||||
"ucs-4", "UCS-4",
|
"ucs-4", "UCS-4",
|
||||||
"ucs4", "UCS4",
|
"ucs4", "UCS4",
|
||||||
"utf-32", "UTF-32",
|
"utf-32", "UTF-32",
|
||||||
"utf32", "UTF32",
|
"utf32", "UTF32",
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
@ -166,12 +166,12 @@ static char *iconv_wide_names_4[]=
|
||||||
*/
|
*/
|
||||||
static char *iconv_wide_names_2[]=
|
static char *iconv_wide_names_2[]=
|
||||||
{
|
{
|
||||||
"wchar_t", "WCHAR_T",
|
"wchar_t", "WCHAR_T",
|
||||||
"wchar", "WCHAR",
|
"wchar", "WCHAR",
|
||||||
"ucs-2", "UCS-2",
|
"ucs-2", "UCS-2",
|
||||||
"ucs2", "UCS2",
|
"ucs2", "UCS2",
|
||||||
"utf-16", "UTF-16",
|
"utf-16", "UTF-16",
|
||||||
"utf16", "UTF16",
|
"utf16", "UTF16",
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
@ -196,7 +196,7 @@ static wchar_t *utf2wcs( const char *in )
|
||||||
|
|
||||||
switch (sizeof (wchar_t))
|
switch (sizeof (wchar_t))
|
||||||
{
|
{
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
to_name = iconv_wide_names_2;
|
to_name = iconv_wide_names_2;
|
||||||
break;
|
break;
|
||||||
|
@ -204,15 +204,15 @@ static wchar_t *utf2wcs( const char *in )
|
||||||
case 4:
|
case 4:
|
||||||
to_name = iconv_wide_names_4;
|
to_name = iconv_wide_names_4;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
to_name = iconv_wide_names_unknown;
|
to_name = iconv_wide_names_unknown;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The line protocol fish uses is always utf-8.
|
The line protocol fish uses is always utf-8.
|
||||||
*/
|
*/
|
||||||
char **from_name = iconv_utf8_names;
|
char **from_name = iconv_utf8_names;
|
||||||
|
|
||||||
|
@ -220,13 +220,13 @@ static wchar_t *utf2wcs( const char *in )
|
||||||
size_t out_len = sizeof( wchar_t )*(in_len+2);
|
size_t out_len = sizeof( wchar_t )*(in_len+2);
|
||||||
size_t nconv;
|
size_t nconv;
|
||||||
char *nout;
|
char *nout;
|
||||||
|
|
||||||
out = malloc( out_len );
|
out = malloc( out_len );
|
||||||
nout = (char *)out;
|
nout = (char *)out;
|
||||||
|
|
||||||
if( !out )
|
if( !out )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for( i=0; to_name[i]; i++ )
|
for( i=0; to_name[i]; i++ )
|
||||||
{
|
{
|
||||||
for( j=0; from_name[j]; j++ )
|
for( j=0; from_name[j]; j++ )
|
||||||
|
@ -236,7 +236,7 @@ static wchar_t *utf2wcs( const char *in )
|
||||||
if( cd != (iconv_t) -1)
|
if( cd != (iconv_t) -1)
|
||||||
{
|
{
|
||||||
goto start_conversion;
|
goto start_conversion;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -246,23 +246,23 @@ static wchar_t *utf2wcs( const char *in )
|
||||||
if (cd == (iconv_t) -1)
|
if (cd == (iconv_t) -1)
|
||||||
{
|
{
|
||||||
/* Something went wrong. */
|
/* Something went wrong. */
|
||||||
debug( 0, L"Could not perform utf-8 conversion" );
|
debug( 0, L"Could not perform utf-8 conversion" );
|
||||||
if(errno != EINVAL)
|
if(errno != EINVAL)
|
||||||
wperror( L"iconv_open" );
|
wperror( L"iconv_open" );
|
||||||
|
|
||||||
/* Terminate the output string. */
|
/* Terminate the output string. */
|
||||||
free(out);
|
free(out);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
nconv = iconv( cd, (char **)&in, &in_len, &nout, &out_len );
|
nconv = iconv( cd, (char **)&in, &in_len, &nout, &out_len );
|
||||||
|
|
||||||
if (nconv == (size_t) -1)
|
if (nconv == (size_t) -1)
|
||||||
{
|
{
|
||||||
debug( 0, L"Error while converting from utf string" );
|
debug( 0, L"Error while converting from utf string" );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
*((wchar_t *) nout) = L'\0';
|
*((wchar_t *) nout) = L'\0';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -281,12 +281,12 @@ static wchar_t *utf2wcs( const char *in )
|
||||||
}
|
}
|
||||||
free( out_old );
|
free( out_old );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (iconv_close (cd) != 0)
|
if (iconv_close (cd) != 0)
|
||||||
wperror (L"iconv_close");
|
wperror (L"iconv_close");
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -296,7 +296,7 @@ static char *wcs2utf( const wchar_t *in )
|
||||||
{
|
{
|
||||||
iconv_t cd=(iconv_t) -1;
|
iconv_t cd=(iconv_t) -1;
|
||||||
int i,j;
|
int i,j;
|
||||||
|
|
||||||
char *char_in = (char *)in;
|
char *char_in = (char *)in;
|
||||||
char *out;
|
char *out;
|
||||||
|
|
||||||
|
@ -310,7 +310,7 @@ static char *wcs2utf( const wchar_t *in )
|
||||||
|
|
||||||
switch (sizeof (wchar_t))
|
switch (sizeof (wchar_t))
|
||||||
{
|
{
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
from_name = iconv_wide_names_2;
|
from_name = iconv_wide_names_2;
|
||||||
break;
|
break;
|
||||||
|
@ -318,7 +318,7 @@ static char *wcs2utf( const wchar_t *in )
|
||||||
case 4:
|
case 4:
|
||||||
from_name = iconv_wide_names_4;
|
from_name = iconv_wide_names_4;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
from_name = iconv_wide_names_unknown;
|
from_name = iconv_wide_names_unknown;
|
||||||
break;
|
break;
|
||||||
|
@ -330,24 +330,24 @@ static char *wcs2utf( const wchar_t *in )
|
||||||
size_t out_len = sizeof( char )*( (MAX_UTF8_BYTES*in_len)+1);
|
size_t out_len = sizeof( char )*( (MAX_UTF8_BYTES*in_len)+1);
|
||||||
size_t nconv;
|
size_t nconv;
|
||||||
char *nout;
|
char *nout;
|
||||||
|
|
||||||
out = malloc( out_len );
|
out = malloc( out_len );
|
||||||
nout = (char *)out;
|
nout = (char *)out;
|
||||||
in_len *= sizeof( wchar_t );
|
in_len *= sizeof( wchar_t );
|
||||||
|
|
||||||
if( !out )
|
if( !out )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for( i=0; to_name[i]; i++ )
|
for( i=0; to_name[i]; i++ )
|
||||||
{
|
{
|
||||||
for( j=0; from_name[j]; j++ )
|
for( j=0; from_name[j]; j++ )
|
||||||
{
|
{
|
||||||
cd = iconv_open ( to_name[i], from_name[j] );
|
cd = iconv_open ( to_name[i], from_name[j] );
|
||||||
|
|
||||||
if( cd != (iconv_t) -1)
|
if( cd != (iconv_t) -1)
|
||||||
{
|
{
|
||||||
goto start_conversion;
|
goto start_conversion;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -357,17 +357,17 @@ static char *wcs2utf( const wchar_t *in )
|
||||||
if (cd == (iconv_t) -1)
|
if (cd == (iconv_t) -1)
|
||||||
{
|
{
|
||||||
/* Something went wrong. */
|
/* Something went wrong. */
|
||||||
debug( 0, L"Could not perform utf-8 conversion" );
|
debug( 0, L"Could not perform utf-8 conversion" );
|
||||||
if(errno != EINVAL)
|
if(errno != EINVAL)
|
||||||
wperror( L"iconv_open" );
|
wperror( L"iconv_open" );
|
||||||
|
|
||||||
/* Terminate the output string. */
|
/* Terminate the output string. */
|
||||||
free(out);
|
free(out);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
nconv = iconv( cd, &char_in, &in_len, &nout, &out_len );
|
nconv = iconv( cd, &char_in, &in_len, &nout, &out_len );
|
||||||
|
|
||||||
|
|
||||||
if (nconv == (size_t) -1)
|
if (nconv == (size_t) -1)
|
||||||
{
|
{
|
||||||
|
@ -375,13 +375,13 @@ static char *wcs2utf( const wchar_t *in )
|
||||||
debug( 0, L"Error while converting from to string" );
|
debug( 0, L"Error while converting from to string" );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
*nout = '\0';
|
*nout = '\0';
|
||||||
|
|
||||||
if (iconv_close (cd) != 0)
|
if (iconv_close (cd) != 0)
|
||||||
wperror (L"iconv_close");
|
wperror (L"iconv_close");
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -421,9 +421,9 @@ static int read_byte( connection_t *src )
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
res = read( src->fd, src->buffer, ENV_UNIVERSAL_BUFFER_SIZE );
|
res = read( src->fd, src->buffer, ENV_UNIVERSAL_BUFFER_SIZE );
|
||||||
|
|
||||||
// debug(4, L"Read chunk '%.*s'", res, src->buffer );
|
// debug(4, L"Read chunk '%.*s'", res, src->buffer );
|
||||||
|
|
||||||
if( res < 0 )
|
if( res < 0 )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -432,20 +432,20 @@ static int read_byte( connection_t *src )
|
||||||
{
|
{
|
||||||
return ENV_UNIVERSAL_AGAIN;
|
return ENV_UNIVERSAL_AGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ENV_UNIVERSAL_ERROR;
|
return ENV_UNIVERSAL_ERROR;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( res == 0 )
|
if( res == 0 )
|
||||||
{
|
{
|
||||||
return ENV_UNIVERSAL_EOF;
|
return ENV_UNIVERSAL_EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
src->buffer_consumed = 0;
|
src->buffer_consumed = 0;
|
||||||
src->buffer_used = res;
|
src->buffer_used = res;
|
||||||
}
|
}
|
||||||
|
|
||||||
return src->buffer[src->buffer_consumed++];
|
return src->buffer[src->buffer_consumed++];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -455,10 +455,10 @@ void read_message( connection_t *src )
|
||||||
{
|
{
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
|
|
||||||
int ib = read_byte( src );
|
int ib = read_byte( src );
|
||||||
char b;
|
char b;
|
||||||
|
|
||||||
switch( ib )
|
switch( ib )
|
||||||
{
|
{
|
||||||
case ENV_UNIVERSAL_AGAIN:
|
case ENV_UNIVERSAL_AGAIN:
|
||||||
|
@ -483,43 +483,43 @@ void read_message( connection_t *src )
|
||||||
{
|
{
|
||||||
char c = 0;
|
char c = 0;
|
||||||
b_append( &src->input, &c, 1 );
|
b_append( &src->input, &c, 1 );
|
||||||
debug( 1,
|
debug( 1,
|
||||||
L"Universal variable connection closed while reading command. Partial command recieved: '%s'",
|
L"Universal variable connection closed while reading command. Partial command recieved: '%s'",
|
||||||
(wchar_t *)src->input.buff );
|
(wchar_t *)src->input.buff );
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b = (char)ib;
|
b = (char)ib;
|
||||||
|
|
||||||
if( b == '\n' )
|
if( b == '\n' )
|
||||||
{
|
{
|
||||||
wchar_t *msg;
|
wchar_t *msg;
|
||||||
|
|
||||||
b = 0;
|
b = 0;
|
||||||
b_append( &src->input, &b, 1 );
|
b_append( &src->input, &b, 1 );
|
||||||
|
|
||||||
msg = utf2wcs( src->input.buff );
|
msg = utf2wcs( src->input.buff );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Before calling parse_message, we must empty reset
|
Before calling parse_message, we must empty reset
|
||||||
everything, since the callback function could
|
everything, since the callback function could
|
||||||
potentially call read_message.
|
potentially call read_message.
|
||||||
*/
|
*/
|
||||||
src->input.used=0;
|
src->input.used=0;
|
||||||
|
|
||||||
if( msg )
|
if( msg )
|
||||||
{
|
{
|
||||||
parse_message( msg, src );
|
parse_message( msg, src );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debug( 0, _(L"Could not convert message '%s' to wide character string"), src->input.buff );
|
debug( 0, _(L"Could not convert message '%s' to wide character string"), src->input.buff );
|
||||||
}
|
}
|
||||||
|
|
||||||
free( msg );
|
free( msg );
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -534,7 +534,7 @@ void read_message( connection_t *src )
|
||||||
void env_universal_common_remove( const wchar_t *name )
|
void env_universal_common_remove( const wchar_t *name )
|
||||||
{
|
{
|
||||||
void *k, *v;
|
void *k, *v;
|
||||||
hash_remove( &env_universal_var,
|
hash_remove( &env_universal_var,
|
||||||
name,
|
name,
|
||||||
&k,
|
&k,
|
||||||
&v );
|
&v );
|
||||||
|
@ -553,7 +553,7 @@ static int match( const wchar_t *msg, const wchar_t *cmd )
|
||||||
|
|
||||||
if( msg[len] && msg[len]!= L' ' && msg[len] != L'\t' )
|
if( msg[len] && msg[len]!= L' ' && msg[len] != L'\t' )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -564,20 +564,20 @@ void env_universal_common_set( const wchar_t *key, const wchar_t *val, int expor
|
||||||
|
|
||||||
CHECK( key, );
|
CHECK( key, );
|
||||||
CHECK( val, );
|
CHECK( val, );
|
||||||
|
|
||||||
entry = malloc( sizeof(var_uni_entry_t) + sizeof(wchar_t)*(wcslen(val)+1) );
|
entry = malloc( sizeof(var_uni_entry_t) + sizeof(wchar_t)*(wcslen(val)+1) );
|
||||||
name = wcsdup(key);
|
name = wcsdup(key);
|
||||||
|
|
||||||
if( !entry || !name )
|
if( !entry || !name )
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
|
|
||||||
entry->export=export;
|
entry->export=export;
|
||||||
|
|
||||||
wcscpy( entry->val, val );
|
wcscpy( entry->val, val );
|
||||||
env_universal_common_remove( name );
|
env_universal_common_remove( name );
|
||||||
|
|
||||||
hash_put( &env_universal_var, name, entry );
|
hash_put( &env_universal_var, name, entry );
|
||||||
|
|
||||||
if( callback )
|
if( callback )
|
||||||
{
|
{
|
||||||
callback( export?SET_EXPORT:SET, name, val );
|
callback( export?SET_EXPORT:SET, name, val );
|
||||||
|
@ -588,67 +588,67 @@ void env_universal_common_set( const wchar_t *key, const wchar_t *val, int expor
|
||||||
/**
|
/**
|
||||||
Parse message msg
|
Parse message msg
|
||||||
*/
|
*/
|
||||||
static void parse_message( wchar_t *msg,
|
static void parse_message( wchar_t *msg,
|
||||||
connection_t *src )
|
connection_t *src )
|
||||||
{
|
{
|
||||||
// debug( 3, L"parse_message( %ls );", msg );
|
// debug( 3, L"parse_message( %ls );", msg );
|
||||||
|
|
||||||
if( msg[0] == L'#' )
|
if( msg[0] == L'#' )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( match( msg, SET_STR ) || match( msg, SET_EXPORT_STR ))
|
if( match( msg, SET_STR ) || match( msg, SET_EXPORT_STR ))
|
||||||
{
|
{
|
||||||
wchar_t *name, *tmp;
|
wchar_t *name, *tmp;
|
||||||
int export = match( msg, SET_EXPORT_STR );
|
int export = match( msg, SET_EXPORT_STR );
|
||||||
|
|
||||||
name = msg+(export?wcslen(SET_EXPORT_STR):wcslen(SET_STR));
|
name = msg+(export?wcslen(SET_EXPORT_STR):wcslen(SET_STR));
|
||||||
while( wcschr( L"\t ", *name ) )
|
while( wcschr( L"\t ", *name ) )
|
||||||
name++;
|
name++;
|
||||||
|
|
||||||
tmp = wcschr( name, L':' );
|
tmp = wcschr( name, L':' );
|
||||||
if( tmp )
|
if( tmp )
|
||||||
{
|
{
|
||||||
wchar_t *key;
|
wchar_t *key;
|
||||||
wchar_t *val;
|
wchar_t *val;
|
||||||
|
|
||||||
key = malloc( sizeof( wchar_t)*(tmp-name+1));
|
key = malloc( sizeof( wchar_t)*(tmp-name+1));
|
||||||
memcpy( key, name, sizeof( wchar_t)*(tmp-name));
|
memcpy( key, name, sizeof( wchar_t)*(tmp-name));
|
||||||
key[tmp-name]=0;
|
key[tmp-name]=0;
|
||||||
|
|
||||||
val = tmp+1;
|
val = tmp+1;
|
||||||
val = unescape( val, 0 );
|
val = unescape( val, 0 );
|
||||||
|
|
||||||
env_universal_common_set( key, val, export );
|
env_universal_common_set( key, val, export );
|
||||||
|
|
||||||
free( val );
|
free( val );
|
||||||
free( key );
|
free( key );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debug( 1, PARSE_ERR, msg );
|
debug( 1, PARSE_ERR, msg );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if( match( msg, ERASE_STR ) )
|
else if( match( msg, ERASE_STR ) )
|
||||||
{
|
{
|
||||||
wchar_t *name, *tmp;
|
wchar_t *name, *tmp;
|
||||||
|
|
||||||
name = msg+wcslen(ERASE_STR);
|
name = msg+wcslen(ERASE_STR);
|
||||||
while( wcschr( L"\t ", *name ) )
|
while( wcschr( L"\t ", *name ) )
|
||||||
name++;
|
name++;
|
||||||
|
|
||||||
tmp = name;
|
tmp = name;
|
||||||
while( iswalnum( *tmp ) || *tmp == L'_')
|
while( iswalnum( *tmp ) || *tmp == L'_')
|
||||||
tmp++;
|
tmp++;
|
||||||
|
|
||||||
*tmp = 0;
|
*tmp = 0;
|
||||||
|
|
||||||
if( !wcslen( name ) )
|
if( !wcslen( name ) )
|
||||||
{
|
{
|
||||||
debug( 1, PARSE_ERR, msg );
|
debug( 1, PARSE_ERR, msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
env_universal_common_remove( name );
|
env_universal_common_remove( name );
|
||||||
|
|
||||||
if( callback )
|
if( callback )
|
||||||
{
|
{
|
||||||
callback( ERASE, name, 0 );
|
callback( ERASE, name, 0 );
|
||||||
|
@ -671,7 +671,7 @@ static void parse_message( wchar_t *msg,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debug( 1, PARSE_ERR, msg );
|
debug( 1, PARSE_ERR, msg );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -684,7 +684,7 @@ static int try_send( message_t *msg,
|
||||||
{
|
{
|
||||||
|
|
||||||
debug( 3,
|
debug( 3,
|
||||||
L"before write of %d chars to fd %d", strlen(msg->body), fd );
|
L"before write of %d chars to fd %d", strlen(msg->body), fd );
|
||||||
|
|
||||||
int res = write( fd, msg->body, strlen(msg->body) );
|
int res = write( fd, msg->body, strlen(msg->body) );
|
||||||
|
|
||||||
|
@ -696,26 +696,26 @@ static int try_send( message_t *msg,
|
||||||
{
|
{
|
||||||
debug( 4, L"Failed to write message '%s'", msg->body );
|
debug( 4, L"Failed to write message '%s'", msg->body );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( res == -1 )
|
if( res == -1 )
|
||||||
{
|
{
|
||||||
switch( errno )
|
switch( errno )
|
||||||
{
|
{
|
||||||
case EAGAIN:
|
case EAGAIN:
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
debug( 2,
|
debug( 2,
|
||||||
L"Error while sending universal variable message to fd %d. Closing connection",
|
L"Error while sending universal variable message to fd %d. Closing connection",
|
||||||
fd );
|
fd );
|
||||||
if( debug_level > 2 )
|
if( debug_level > 2 )
|
||||||
wperror( L"write" );
|
wperror( L"write" );
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
msg->count--;
|
msg->count--;
|
||||||
|
|
||||||
if( !msg->count )
|
if( !msg->count )
|
||||||
{
|
{
|
||||||
free( msg );
|
free( msg );
|
||||||
|
@ -726,7 +726,7 @@ static int try_send( message_t *msg,
|
||||||
void try_send_all( connection_t *c )
|
void try_send_all( connection_t *c )
|
||||||
{
|
{
|
||||||
/* debug( 3,
|
/* debug( 3,
|
||||||
L"Send all updates to connection on fd %d",
|
L"Send all updates to connection on fd %d",
|
||||||
c->fd );*/
|
c->fd );*/
|
||||||
while( !q_empty( &c->unsent) )
|
while( !q_empty( &c->unsent) )
|
||||||
{
|
{
|
||||||
|
@ -735,12 +735,12 @@ void try_send_all( connection_t *c )
|
||||||
case 1:
|
case 1:
|
||||||
q_get( &c->unsent);
|
q_get( &c->unsent);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
debug( 4,
|
debug( 4,
|
||||||
L"Socket full, send rest later" );
|
L"Socket full, send rest later" );
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case -1:
|
case -1:
|
||||||
c->killme = 1;
|
c->killme = 1;
|
||||||
return;
|
return;
|
||||||
|
@ -779,16 +779,16 @@ static wchar_t *full_escape( const wchar_t *in )
|
||||||
|
|
||||||
|
|
||||||
message_t *create_message( int type,
|
message_t *create_message( int type,
|
||||||
const wchar_t *key_in,
|
const wchar_t *key_in,
|
||||||
const wchar_t *val_in )
|
const wchar_t *val_in )
|
||||||
{
|
{
|
||||||
message_t *msg=0;
|
message_t *msg=0;
|
||||||
|
|
||||||
char *key=0;
|
char *key=0;
|
||||||
size_t sz;
|
size_t sz;
|
||||||
|
|
||||||
// debug( 4, L"Crete message of type %d", type );
|
// debug( 4, L"Crete message of type %d", type );
|
||||||
|
|
||||||
if( key_in )
|
if( key_in )
|
||||||
{
|
{
|
||||||
if( wcsvarname( key_in ) )
|
if( wcsvarname( key_in ) )
|
||||||
|
@ -796,7 +796,7 @@ message_t *create_message( int type,
|
||||||
debug( 0, L"Illegal variable name: '%ls'", key_in );
|
debug( 0, L"Illegal variable name: '%ls'", key_in );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
key = wcs2utf(key_in);
|
key = wcs2utf(key_in);
|
||||||
if( !key )
|
if( !key )
|
||||||
{
|
{
|
||||||
|
@ -806,8 +806,8 @@ message_t *create_message( int type,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch( type )
|
switch( type )
|
||||||
{
|
{
|
||||||
case SET:
|
case SET:
|
||||||
|
@ -817,29 +817,29 @@ message_t *create_message( int type,
|
||||||
{
|
{
|
||||||
val_in=L"";
|
val_in=L"";
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t *esc = full_escape( val_in );
|
wchar_t *esc = full_escape( val_in );
|
||||||
if( !esc )
|
if( !esc )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
char *val = wcs2utf(esc );
|
char *val = wcs2utf(esc );
|
||||||
free(esc);
|
free(esc);
|
||||||
|
|
||||||
sz = strlen(type==SET?SET_MBS:SET_EXPORT_MBS) + strlen(key) + strlen(val) + 4;
|
sz = strlen(type==SET?SET_MBS:SET_EXPORT_MBS) + strlen(key) + strlen(val) + 4;
|
||||||
msg = malloc( sizeof( message_t ) + sz );
|
msg = malloc( sizeof( message_t ) + sz );
|
||||||
|
|
||||||
if( !msg )
|
if( !msg )
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
|
|
||||||
strcpy( msg->body, (type==SET?SET_MBS:SET_EXPORT_MBS) );
|
strcpy( msg->body, (type==SET?SET_MBS:SET_EXPORT_MBS) );
|
||||||
strcat( msg->body, " " );
|
strcat( msg->body, " " );
|
||||||
strcat( msg->body, key );
|
strcat( msg->body, key );
|
||||||
strcat( msg->body, ":" );
|
strcat( msg->body, ":" );
|
||||||
strcat( msg->body, val );
|
strcat( msg->body, val );
|
||||||
strcat( msg->body, "\n" );
|
strcat( msg->body, "\n" );
|
||||||
|
|
||||||
free( val );
|
free( val );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -850,7 +850,7 @@ message_t *create_message( int type,
|
||||||
|
|
||||||
if( !msg )
|
if( !msg )
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
|
|
||||||
strcpy( msg->body, ERASE_MBS " " );
|
strcpy( msg->body, ERASE_MBS " " );
|
||||||
strcat( msg->body, key );
|
strcat( msg->body, key );
|
||||||
strcat( msg->body, "\n" );
|
strcat( msg->body, "\n" );
|
||||||
|
@ -859,14 +859,14 @@ message_t *create_message( int type,
|
||||||
|
|
||||||
case BARRIER:
|
case BARRIER:
|
||||||
{
|
{
|
||||||
msg = malloc( sizeof( message_t ) +
|
msg = malloc( sizeof( message_t ) +
|
||||||
strlen( BARRIER_MBS ) +2);
|
strlen( BARRIER_MBS ) +2);
|
||||||
if( !msg )
|
if( !msg )
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
strcpy( msg->body, BARRIER_MBS "\n" );
|
strcpy( msg->body, BARRIER_MBS "\n" );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case BARRIER_REPLY:
|
case BARRIER_REPLY:
|
||||||
{
|
{
|
||||||
msg = malloc( sizeof( message_t ) +
|
msg = malloc( sizeof( message_t ) +
|
||||||
|
@ -876,7 +876,7 @@ message_t *create_message( int type,
|
||||||
strcpy( msg->body, BARRIER_REPLY_MBS "\n" );
|
strcpy( msg->body, BARRIER_REPLY_MBS "\n" );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
debug( 0, L"create_message: Unknown message type" );
|
debug( 0, L"create_message: Unknown message type" );
|
||||||
|
@ -890,19 +890,19 @@ message_t *create_message( int type,
|
||||||
|
|
||||||
// debug( 4, L"Message body is '%s'", msg->body );
|
// debug( 4, L"Message body is '%s'", msg->body );
|
||||||
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Function used with hash_foreach to insert keys of one table into
|
Function used with hash_foreach to insert keys of one table into
|
||||||
another
|
another
|
||||||
*/
|
*/
|
||||||
static void add_key_to_hash( void *key,
|
static void add_key_to_hash( void *key,
|
||||||
void *data,
|
void *data,
|
||||||
void *aux )
|
void *aux )
|
||||||
{
|
{
|
||||||
var_uni_entry_t *e = (var_uni_entry_t *)data;
|
var_uni_entry_t *e = (var_uni_entry_t *)data;
|
||||||
if( ( e->export && get_names_show_exported) ||
|
if( ( e->export && get_names_show_exported) ||
|
||||||
( !e->export && get_names_show_unexported) )
|
( !e->export && get_names_show_unexported) )
|
||||||
al_push( (array_list_t *)aux, key );
|
al_push( (array_list_t *)aux, key );
|
||||||
}
|
}
|
||||||
|
@ -913,18 +913,18 @@ void env_universal_common_get_names( array_list_t *l,
|
||||||
{
|
{
|
||||||
get_names_show_exported = show_exported;
|
get_names_show_exported = show_exported;
|
||||||
get_names_show_unexported = show_unexported;
|
get_names_show_unexported = show_unexported;
|
||||||
|
|
||||||
hash_foreach2( &env_universal_var,
|
hash_foreach2( &env_universal_var,
|
||||||
add_key_to_hash,
|
add_key_to_hash,
|
||||||
l );
|
l );
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t *env_universal_common_get( const wchar_t *name )
|
wchar_t *env_universal_common_get( const wchar_t *name )
|
||||||
{
|
{
|
||||||
var_uni_entry_t *e = (var_uni_entry_t *)hash_get( &env_universal_var, name );
|
var_uni_entry_t *e = (var_uni_entry_t *)hash_get( &env_universal_var, name );
|
||||||
if( e )
|
if( e )
|
||||||
return e->val;
|
return e->val;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int env_universal_common_get_export( const wchar_t *name )
|
int env_universal_common_get_export( const wchar_t *name )
|
||||||
|
@ -952,17 +952,17 @@ static void enqueue( void *k,
|
||||||
const wchar_t *key = (const wchar_t *)k;
|
const wchar_t *key = (const wchar_t *)k;
|
||||||
const var_uni_entry_t *val = (const var_uni_entry_t *)v;
|
const var_uni_entry_t *val = (const var_uni_entry_t *)v;
|
||||||
dyn_queue_t *queue = (dyn_queue_t *)q;
|
dyn_queue_t *queue = (dyn_queue_t *)q;
|
||||||
|
|
||||||
message_t *msg = create_message( val->export?SET_EXPORT:SET, key, val->val );
|
message_t *msg = create_message( val->export?SET_EXPORT:SET, key, val->val );
|
||||||
msg->count=1;
|
msg->count=1;
|
||||||
|
|
||||||
q_put( queue, msg );
|
q_put( queue, msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
void enqueue_all( connection_t *c )
|
void enqueue_all( connection_t *c )
|
||||||
{
|
{
|
||||||
hash_foreach2( &env_universal_var,
|
hash_foreach2( &env_universal_var,
|
||||||
&enqueue,
|
&enqueue,
|
||||||
(void *)&c->unsent );
|
(void *)&c->unsent );
|
||||||
try_send_all( c );
|
try_send_all( c );
|
||||||
}
|
}
|
||||||
|
@ -974,7 +974,7 @@ void connection_init( connection_t *c, int fd )
|
||||||
c->fd = fd;
|
c->fd = fd;
|
||||||
b_init( &c->input );
|
b_init( &c->input );
|
||||||
q_init( &c->unsent );
|
q_init( &c->unsent );
|
||||||
c->buffer_consumed = c->buffer_used = 0;
|
c->buffer_consumed = c->buffer_used = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void connection_destroy( connection_t *c)
|
void connection_destroy( connection_t *c)
|
||||||
|
|
|
@ -76,9 +76,9 @@ typedef struct connection
|
||||||
newline is encountered, the buffer is parsed and cleared.
|
newline is encountered, the buffer is parsed and cleared.
|
||||||
*/
|
*/
|
||||||
buffer_t input;
|
buffer_t input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The read buffer.
|
The read buffer.
|
||||||
*/
|
*/
|
||||||
char buffer[ENV_UNIVERSAL_BUFFER_SIZE];
|
char buffer[ENV_UNIVERSAL_BUFFER_SIZE];
|
||||||
|
|
||||||
|
@ -86,12 +86,12 @@ typedef struct connection
|
||||||
Number of bytes that have already been consumed.
|
Number of bytes that have already been consumed.
|
||||||
*/
|
*/
|
||||||
int buffer_consumed;
|
int buffer_consumed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Number of bytes that have been read into the buffer.
|
Number of bytes that have been read into the buffer.
|
||||||
*/
|
*/
|
||||||
int buffer_used;
|
int buffer_used;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Link to the next connection
|
Link to the next connection
|
||||||
|
@ -103,7 +103,7 @@ typedef struct connection
|
||||||
/**
|
/**
|
||||||
A struct representing a message to be sent between client and server
|
A struct representing a message to be sent between client and server
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
Number of queues that contain this message. Once this reaches zero, the message should be deleted
|
Number of queues that contain this message. Once this reaches zero, the message should be deleted
|
||||||
|
@ -163,7 +163,7 @@ void env_universal_common_get_names( array_list_t *l,
|
||||||
void env_universal_common_set( const wchar_t *key, const wchar_t *val, int export );
|
void env_universal_common_set( const wchar_t *key, const wchar_t *val, int export );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Remove the specified variable.
|
Remove the specified variable.
|
||||||
|
|
||||||
This function operate agains the local copy of all universal
|
This function operate agains the local copy of all universal
|
||||||
variables, it does not communicate with any other process.
|
variables, it does not communicate with any other process.
|
||||||
|
|
|
@ -39,7 +39,7 @@ if status --is-login
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# There are variables that contain colons that are not arrays. This
|
# There are variables that contain colons that are not arrays. This
|
||||||
# reverts them back to regular strings.
|
# reverts them back to regular strings.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
184
event.c
184
event.c
|
@ -44,11 +44,11 @@ typedef struct
|
||||||
/**
|
/**
|
||||||
Whether signals have been skipped
|
Whether signals have been skipped
|
||||||
*/
|
*/
|
||||||
int overflow;
|
int overflow;
|
||||||
/**
|
/**
|
||||||
Array of signal events
|
Array of signal events
|
||||||
*/
|
*/
|
||||||
int signal[SIG_UNHANDLED_MAX];
|
int signal[SIG_UNHANDLED_MAX];
|
||||||
}
|
}
|
||||||
signal_list_t;
|
signal_list_t;
|
||||||
|
|
||||||
|
@ -95,23 +95,23 @@ static int event_match( event_t *class, event_t *instance )
|
||||||
|
|
||||||
if( class->type == EVENT_ANY )
|
if( class->type == EVENT_ANY )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if( class->type != instance->type )
|
if( class->type != instance->type )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
switch( class->type )
|
switch( class->type )
|
||||||
{
|
{
|
||||||
|
|
||||||
case EVENT_SIGNAL:
|
case EVENT_SIGNAL:
|
||||||
if( class->param1.signal == EVENT_ANY_SIGNAL )
|
if( class->param1.signal == EVENT_ANY_SIGNAL )
|
||||||
return 1;
|
return 1;
|
||||||
return class->param1.signal == instance->param1.signal;
|
return class->param1.signal == instance->param1.signal;
|
||||||
|
|
||||||
case EVENT_VARIABLE:
|
case EVENT_VARIABLE:
|
||||||
return wcscmp( instance->param1.variable,
|
return wcscmp( instance->param1.variable,
|
||||||
class->param1.variable )==0;
|
class->param1.variable )==0;
|
||||||
|
|
||||||
case EVENT_EXIT:
|
case EVENT_EXIT:
|
||||||
if( class->param1.pid == EVENT_ANY_PID )
|
if( class->param1.pid == EVENT_ANY_PID )
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -125,11 +125,11 @@ static int event_match( event_t *class, event_t *instance )
|
||||||
class->param1.param )==0;
|
class->param1.param )==0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This should never be reached
|
This should never be reached
|
||||||
*/
|
*/
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,10 +140,10 @@ static int event_match( event_t *class, event_t *instance )
|
||||||
static event_t *event_copy( event_t *event, int copy_arguments )
|
static event_t *event_copy( event_t *event, int copy_arguments )
|
||||||
{
|
{
|
||||||
event_t *e = malloc( sizeof( event_t ) );
|
event_t *e = malloc( sizeof( event_t ) );
|
||||||
|
|
||||||
if( !e )
|
if( !e )
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
|
|
||||||
memcpy( e, event, sizeof(event_t));
|
memcpy( e, event, sizeof(event_t));
|
||||||
|
|
||||||
if( e->function_name )
|
if( e->function_name )
|
||||||
|
@ -153,7 +153,7 @@ static event_t *event_copy( event_t *event, int copy_arguments )
|
||||||
e->param1.variable = wcsdup( e->param1.variable );
|
e->param1.variable = wcsdup( e->param1.variable );
|
||||||
else if( e->type == EVENT_GENERIC )
|
else if( e->type == EVENT_GENERIC )
|
||||||
e->param1.param = wcsdup( e->param1.param );
|
e->param1.param = wcsdup( e->param1.param );
|
||||||
|
|
||||||
al_init( &e->arguments );
|
al_init( &e->arguments );
|
||||||
if( copy_arguments )
|
if( copy_arguments )
|
||||||
{
|
{
|
||||||
|
@ -162,9 +162,9 @@ static event_t *event_copy( event_t *event, int copy_arguments )
|
||||||
{
|
{
|
||||||
al_push( &e->arguments, wcsdup( (wchar_t *)al_get( &event->arguments, i ) ) );
|
al_push( &e->arguments, wcsdup( (wchar_t *)al_get( &event->arguments, i ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ static int event_is_blocked( event_t *e )
|
||||||
{
|
{
|
||||||
block_t *block;
|
block_t *block;
|
||||||
event_block_t *eb;
|
event_block_t *eb;
|
||||||
|
|
||||||
for( block = current_block; block; block = block->outer )
|
for( block = current_block; block; block = block->outer )
|
||||||
{
|
{
|
||||||
for( eb = block->first_event_block; eb; eb=eb->next )
|
for( eb = block->first_event_block; eb; eb=eb->next )
|
||||||
|
@ -193,9 +193,9 @@ static int event_is_blocked( event_t *e )
|
||||||
if( eb->type & (1<<e->type) )
|
if( eb->type & (1<<e->type) )
|
||||||
return 1;
|
return 1;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,18 +217,18 @@ const wchar_t *event_get_desc( event_t *e )
|
||||||
{
|
{
|
||||||
sb_clear( get_desc_buff );
|
sb_clear( get_desc_buff );
|
||||||
}
|
}
|
||||||
|
|
||||||
switch( e->type )
|
switch( e->type )
|
||||||
{
|
{
|
||||||
|
|
||||||
case EVENT_SIGNAL:
|
case EVENT_SIGNAL:
|
||||||
sb_printf( get_desc_buff, _(L"signal handler for %ls (%ls)"), sig2wcs(e->param1.signal ), signal_get_desc( e->param1.signal ) );
|
sb_printf( get_desc_buff, _(L"signal handler for %ls (%ls)"), sig2wcs(e->param1.signal ), signal_get_desc( e->param1.signal ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVENT_VARIABLE:
|
case EVENT_VARIABLE:
|
||||||
sb_printf( get_desc_buff, _(L"handler for variable '%ls'"), e->param1.variable );
|
sb_printf( get_desc_buff, _(L"handler for variable '%ls'"), e->param1.variable );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVENT_EXIT:
|
case EVENT_EXIT:
|
||||||
if( e->param1.pid > 0 )
|
if( e->param1.pid > 0 )
|
||||||
{
|
{
|
||||||
|
@ -242,9 +242,9 @@ const wchar_t *event_get_desc( event_t *e )
|
||||||
else
|
else
|
||||||
sb_printf( get_desc_buff, _(L"exit handler for job with process group %d"), -e->param1.pid );
|
sb_printf( get_desc_buff, _(L"exit handler for job with process group %d"), -e->param1.pid );
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVENT_JOB_ID:
|
case EVENT_JOB_ID:
|
||||||
{
|
{
|
||||||
job_t *j = job_get( e->param1.job_id );
|
job_t *j = job_get( e->param1.job_id );
|
||||||
|
@ -255,17 +255,17 @@ const wchar_t *event_get_desc( event_t *e )
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EVENT_GENERIC:
|
case EVENT_GENERIC:
|
||||||
sb_printf( get_desc_buff, _(L"handler for generic event '%ls'"), e->param1.param );
|
sb_printf( get_desc_buff, _(L"handler for generic event '%ls'"), e->param1.param );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
sb_printf( get_desc_buff, _(L"Unknown event type") );
|
sb_printf( get_desc_buff, _(L"Unknown event type") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (const wchar_t *)get_desc_buff->buff;
|
return (const wchar_t *)get_desc_buff->buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@ void event_add_handler( event_t *event )
|
||||||
event_t *e;
|
event_t *e;
|
||||||
|
|
||||||
CHECK( event, );
|
CHECK( event, );
|
||||||
|
|
||||||
e = event_copy( event, 0 );
|
e = event_copy( event, 0 );
|
||||||
|
|
||||||
if( !events )
|
if( !events )
|
||||||
|
@ -285,8 +285,8 @@ void event_add_handler( event_t *event )
|
||||||
{
|
{
|
||||||
signal_handle( e->param1.signal, 1 );
|
signal_handle( e->param1.signal, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
al_push( events, e );
|
al_push( events, e );
|
||||||
}
|
}
|
||||||
|
|
||||||
void event_remove( event_t *criterion )
|
void event_remove( event_t *criterion )
|
||||||
|
@ -294,7 +294,7 @@ void event_remove( event_t *criterion )
|
||||||
int i;
|
int i;
|
||||||
array_list_t *new_list=0;
|
array_list_t *new_list=0;
|
||||||
event_t e;
|
event_t e;
|
||||||
|
|
||||||
CHECK( criterion, );
|
CHECK( criterion, );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -305,19 +305,19 @@ void event_remove( event_t *criterion )
|
||||||
that shouldn't be killed to new_list, and then drops the empty
|
that shouldn't be killed to new_list, and then drops the empty
|
||||||
events-list.
|
events-list.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( !events )
|
if( !events )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for( i=0; i<al_get_count( events); i++ )
|
for( i=0; i<al_get_count( events); i++ )
|
||||||
{
|
{
|
||||||
event_t *n = (event_t *)al_get( events, i );
|
event_t *n = (event_t *)al_get( events, i );
|
||||||
if( event_match( criterion, n ) )
|
if( event_match( criterion, n ) )
|
||||||
{
|
{
|
||||||
if( !killme )
|
if( !killme )
|
||||||
killme = al_new();
|
killme = al_new();
|
||||||
|
|
||||||
al_push( killme, n );
|
al_push( killme, n );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
If this event was a signal handler and no other handler handles
|
If this event was a signal handler and no other handler handles
|
||||||
|
@ -329,11 +329,11 @@ void event_remove( event_t *criterion )
|
||||||
e.type = EVENT_SIGNAL;
|
e.type = EVENT_SIGNAL;
|
||||||
e.param1.signal = n->param1.signal;
|
e.param1.signal = n->param1.signal;
|
||||||
e.function_name = 0;
|
e.function_name = 0;
|
||||||
|
|
||||||
if( event_get( &e, 0 ) == 1 )
|
if( event_get( &e, 0 ) == 1 )
|
||||||
{
|
{
|
||||||
signal_handle( e.param1.signal, 0 );
|
signal_handle( e.param1.signal, 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -344,7 +344,7 @@ void event_remove( event_t *criterion )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
al_destroy( events );
|
al_destroy( events );
|
||||||
free( events );
|
free( events );
|
||||||
events = new_list;
|
events = new_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,21 +352,21 @@ int event_get( event_t *criterion, array_list_t *out )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
|
||||||
if( !events )
|
if( !events )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
CHECK( criterion, 0 );
|
CHECK( criterion, 0 );
|
||||||
|
|
||||||
for( i=0; i<al_get_count( events); i++ )
|
for( i=0; i<al_get_count( events); i++ )
|
||||||
{
|
{
|
||||||
event_t *n = (event_t *)al_get( events, i );
|
event_t *n = (event_t *)al_get( events, i );
|
||||||
if( event_match(criterion, n ) )
|
if( event_match(criterion, n ) )
|
||||||
{
|
{
|
||||||
found++;
|
found++;
|
||||||
if( out )
|
if( out )
|
||||||
al_push( out, n );
|
al_push( out, n );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
@ -379,7 +379,7 @@ static void event_free_kills()
|
||||||
int i;
|
int i;
|
||||||
if( !killme )
|
if( !killme )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for( i=0; i<al_get_count( killme ); i++ )
|
for( i=0; i<al_get_count( killme ); i++ )
|
||||||
{
|
{
|
||||||
event_t *roadkill = (event_t *)al_get( killme, i );
|
event_t *roadkill = (event_t *)al_get( killme, i );
|
||||||
|
@ -396,16 +396,16 @@ static int event_is_killed( event_t *e )
|
||||||
int i;
|
int i;
|
||||||
if( !killme )
|
if( !killme )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for( i=0; i<al_get_count( killme ); i++ )
|
for( i=0; i<al_get_count( killme ); i++ )
|
||||||
{
|
{
|
||||||
event_t *roadkill = (event_t *)al_get( events, i );
|
event_t *roadkill = (event_t *)al_get( events, i );
|
||||||
if( roadkill ==e )
|
if( roadkill ==e )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Perform the specified event. Since almost all event firings will
|
Perform the specified event. Since almost all event firings will
|
||||||
|
@ -418,11 +418,11 @@ static void event_fire_internal( event_t *event )
|
||||||
int i, j;
|
int i, j;
|
||||||
string_buffer_t *b=0;
|
string_buffer_t *b=0;
|
||||||
array_list_t *fire=0;
|
array_list_t *fire=0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
First we free all events that have been removed
|
First we free all events that have been removed
|
||||||
*/
|
*/
|
||||||
event_free_kills();
|
event_free_kills();
|
||||||
|
|
||||||
if( !events )
|
if( !events )
|
||||||
return;
|
return;
|
||||||
|
@ -437,7 +437,7 @@ static void event_fire_internal( event_t *event )
|
||||||
for( i=0; i<al_get_count( events ); i++ )
|
for( i=0; i<al_get_count( events ); i++ )
|
||||||
{
|
{
|
||||||
event_t *criterion = (event_t *)al_get( events, i );
|
event_t *criterion = (event_t *)al_get( events, i );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Check if this event is a match
|
Check if this event is a match
|
||||||
*/
|
*/
|
||||||
|
@ -448,17 +448,17 @@ static void event_fire_internal( event_t *event )
|
||||||
al_push( fire, criterion );
|
al_push( fire, criterion );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
No matches. Time to return.
|
No matches. Time to return.
|
||||||
*/
|
*/
|
||||||
if( !fire )
|
if( !fire )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Iterate over our list of matching events
|
Iterate over our list of matching events
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for( i=0; i<al_get_count( fire ); i++ )
|
for( i=0; i<al_get_count( fire ); i++ )
|
||||||
{
|
{
|
||||||
event_t *criterion = (event_t *)al_get( fire, i );
|
event_t *criterion = (event_t *)al_get( fire, i );
|
||||||
|
@ -477,19 +477,19 @@ static void event_fire_internal( event_t *event )
|
||||||
b = sb_new();
|
b = sb_new();
|
||||||
else
|
else
|
||||||
sb_clear( b );
|
sb_clear( b );
|
||||||
|
|
||||||
sb_append( b, criterion->function_name );
|
sb_append( b, criterion->function_name );
|
||||||
|
|
||||||
for( j=0; j<al_get_count(&event->arguments); j++ )
|
for( j=0; j<al_get_count(&event->arguments); j++ )
|
||||||
{
|
{
|
||||||
wchar_t *arg_esc = escape( (wchar_t *)al_get( &event->arguments, j), 1 );
|
wchar_t *arg_esc = escape( (wchar_t *)al_get( &event->arguments, j), 1 );
|
||||||
sb_append( b, L" " );
|
sb_append( b, L" " );
|
||||||
sb_append( b, arg_esc );
|
sb_append( b, arg_esc );
|
||||||
free( arg_esc );
|
free( arg_esc );
|
||||||
}
|
}
|
||||||
|
|
||||||
// debug( 1, L"Event handler fires command '%ls'", (wchar_t *)b->buff );
|
// debug( 1, L"Event handler fires command '%ls'", (wchar_t *)b->buff );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Event handlers are not part of the main flow of code, so
|
Event handlers are not part of the main flow of code, so
|
||||||
they are marked as non-interactive
|
they are marked as non-interactive
|
||||||
|
@ -500,27 +500,27 @@ static void event_fire_internal( event_t *event )
|
||||||
current_block->param1.event = event;
|
current_block->param1.event = event;
|
||||||
eval( (wchar_t *)b->buff, 0, TOP );
|
eval( (wchar_t *)b->buff, 0, TOP );
|
||||||
parser_pop_block();
|
parser_pop_block();
|
||||||
proc_pop_interactive();
|
proc_pop_interactive();
|
||||||
proc_set_last_status( prev_status );
|
proc_set_last_status( prev_status );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( b )
|
if( b )
|
||||||
{
|
{
|
||||||
sb_destroy( b );
|
sb_destroy( b );
|
||||||
free( b );
|
free( b );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( fire )
|
if( fire )
|
||||||
{
|
{
|
||||||
al_destroy( fire );
|
al_destroy( fire );
|
||||||
free( fire );
|
free( fire );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Free killed events
|
Free killed events
|
||||||
*/
|
*/
|
||||||
event_free_kills();
|
event_free_kills();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -532,7 +532,7 @@ static void event_fire_delayed()
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
If is_event is one, we are running the event-handler non-recursively.
|
If is_event is one, we are running the event-handler non-recursively.
|
||||||
|
|
||||||
When the event handler has called a piece of code that triggers
|
When the event handler has called a piece of code that triggers
|
||||||
another event, we do not want to fire delayed events because of
|
another event, we do not want to fire delayed events because of
|
||||||
|
@ -541,7 +541,7 @@ static void event_fire_delayed()
|
||||||
if( blocked && is_event==1)
|
if( blocked && is_event==1)
|
||||||
{
|
{
|
||||||
array_list_t *new_blocked = 0;
|
array_list_t *new_blocked = 0;
|
||||||
|
|
||||||
for( i=0; i<al_get_count( blocked ); i++ )
|
for( i=0; i<al_get_count( blocked ); i++ )
|
||||||
{
|
{
|
||||||
event_t *e = (event_t *)al_get( blocked, i );
|
event_t *e = (event_t *)al_get( blocked, i );
|
||||||
|
@ -549,24 +549,24 @@ static void event_fire_delayed()
|
||||||
{
|
{
|
||||||
if( !new_blocked )
|
if( !new_blocked )
|
||||||
new_blocked = al_new();
|
new_blocked = al_new();
|
||||||
al_push( new_blocked, e );
|
al_push( new_blocked, e );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
event_fire_internal( e );
|
event_fire_internal( e );
|
||||||
event_free( e );
|
event_free( e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
al_destroy( blocked );
|
al_destroy( blocked );
|
||||||
free( blocked );
|
free( blocked );
|
||||||
blocked = new_blocked;
|
blocked = new_blocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
while( sig_list[active_list].count > 0 )
|
while( sig_list[active_list].count > 0 )
|
||||||
{
|
{
|
||||||
signal_list_t *lst;
|
signal_list_t *lst;
|
||||||
event_t e;
|
event_t e;
|
||||||
al_init( &e.arguments );
|
al_init( &e.arguments );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Switch signal lists
|
Switch signal lists
|
||||||
|
@ -576,47 +576,47 @@ static void event_fire_delayed()
|
||||||
active_list=1-active_list;
|
active_list=1-active_list;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Set up
|
Set up
|
||||||
*/
|
*/
|
||||||
e.type=EVENT_SIGNAL;
|
e.type=EVENT_SIGNAL;
|
||||||
e.function_name=0;
|
e.function_name=0;
|
||||||
|
|
||||||
lst = &sig_list[1-active_list];
|
lst = &sig_list[1-active_list];
|
||||||
|
|
||||||
if( lst->overflow )
|
if( lst->overflow )
|
||||||
{
|
{
|
||||||
debug( 0, _( L"Signal list overflow. Signals have been ignored." ) );
|
debug( 0, _( L"Signal list overflow. Signals have been ignored." ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Send all signals in our private list
|
Send all signals in our private list
|
||||||
*/
|
*/
|
||||||
for( i=0; i<lst->count; i++ )
|
for( i=0; i<lst->count; i++ )
|
||||||
{
|
{
|
||||||
e.param1.signal = lst->signal[i];
|
e.param1.signal = lst->signal[i];
|
||||||
al_set( &e.arguments, 0, sig2wcs( e.param1.signal ) );
|
al_set( &e.arguments, 0, sig2wcs( e.param1.signal ) );
|
||||||
if( event_is_blocked( &e ) )
|
if( event_is_blocked( &e ) )
|
||||||
{
|
{
|
||||||
if( !blocked )
|
if( !blocked )
|
||||||
blocked = al_new();
|
blocked = al_new();
|
||||||
al_push( blocked, event_copy(&e, 1) );
|
al_push( blocked, event_copy(&e, 1) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
event_fire_internal( &e );
|
event_fire_internal( &e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
al_destroy( &e.arguments );
|
al_destroy( &e.arguments );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void event_fire( event_t *event )
|
void event_fire( event_t *event )
|
||||||
{
|
{
|
||||||
is_event++;
|
is_event++;
|
||||||
|
|
||||||
if( event && (event->type == EVENT_SIGNAL) )
|
if( event && (event->type == EVENT_SIGNAL) )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -636,14 +636,14 @@ void event_fire( event_t *event )
|
||||||
Fire events triggered by signals
|
Fire events triggered by signals
|
||||||
*/
|
*/
|
||||||
event_fire_delayed();
|
event_fire_delayed();
|
||||||
|
|
||||||
if( event )
|
if( event )
|
||||||
{
|
{
|
||||||
if( event_is_blocked( event ) )
|
if( event_is_blocked( event ) )
|
||||||
{
|
{
|
||||||
if( !blocked )
|
if( !blocked )
|
||||||
blocked = al_new();
|
blocked = al_new();
|
||||||
|
|
||||||
al_push( blocked, event_copy(event, 1) );
|
al_push( blocked, event_copy(event, 1) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -651,8 +651,8 @@ void event_fire( event_t *event )
|
||||||
event_fire_internal( event );
|
event_fire_internal( event );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
is_event--;
|
is_event--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -668,7 +668,7 @@ void event_destroy()
|
||||||
{
|
{
|
||||||
al_foreach( events, (void (*)(void *))&event_free );
|
al_foreach( events, (void (*)(void *))&event_free );
|
||||||
al_destroy( events );
|
al_destroy( events );
|
||||||
free( events );
|
free( events );
|
||||||
events=0;
|
events=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -676,9 +676,9 @@ void event_destroy()
|
||||||
{
|
{
|
||||||
al_foreach( killme, (void (*)(void *))&event_free );
|
al_foreach( killme, (void (*)(void *))&event_free );
|
||||||
al_destroy( killme );
|
al_destroy( killme );
|
||||||
free( killme );
|
free( killme );
|
||||||
killme=0;
|
killme=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void event_free( event_t *e )
|
void event_free( event_t *e )
|
||||||
|
@ -711,11 +711,11 @@ void event_fire_generic_internal(const wchar_t *name, ...)
|
||||||
wchar_t *arg;
|
wchar_t *arg;
|
||||||
|
|
||||||
CHECK( name, );
|
CHECK( name, );
|
||||||
|
|
||||||
ev.type = EVENT_GENERIC;
|
ev.type = EVENT_GENERIC;
|
||||||
ev.param1.param = name;
|
ev.param1.param = name;
|
||||||
ev.function_name=0;
|
ev.function_name=0;
|
||||||
|
|
||||||
al_init( &ev.arguments );
|
al_init( &ev.arguments );
|
||||||
va_start( va, name );
|
va_start( va, name );
|
||||||
while( (arg=va_arg(va, wchar_t *) )!= 0 )
|
while( (arg=va_arg(va, wchar_t *) )!= 0 )
|
||||||
|
@ -723,9 +723,9 @@ void event_fire_generic_internal(const wchar_t *name, ...)
|
||||||
al_push( &ev.arguments, arg );
|
al_push( &ev.arguments, arg );
|
||||||
}
|
}
|
||||||
va_end( va );
|
va_end( va );
|
||||||
|
|
||||||
event_fire( &ev );
|
event_fire( &ev );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
16
event.h
16
event.h
|
@ -7,7 +7,7 @@
|
||||||
functions produce output or perform memory allocations, since
|
functions produce output or perform memory allocations, since
|
||||||
such functions may not be safely called by signal handlers.
|
such functions may not be safely called by signal handlers.
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
#ifndef FISH_EVENT_H
|
#ifndef FISH_EVENT_H
|
||||||
#define FISH_EVENT_H
|
#define FISH_EVENT_H
|
||||||
|
@ -44,7 +44,7 @@ enum
|
||||||
- When used as a parameter to event_add, it represents a class of events, and function_name is the name of the function which will be called whenever an event matching the specified class occurs. This is also how events are stored internally.
|
- When used as a parameter to event_add, it represents a class of events, and function_name is the name of the function which will be called whenever an event matching the specified class occurs. This is also how events are stored internally.
|
||||||
- When used as a parameter to event_get, event_remove and event_fire, it represents a class of events, and if the function_name field is non-zero, only events which call the specified function will be returned.
|
- When used as a parameter to event_get, event_remove and event_fire, it represents a class of events, and if the function_name field is non-zero, only events which call the specified function will be returned.
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
Type of event
|
Type of event
|
||||||
|
@ -78,13 +78,13 @@ typedef struct
|
||||||
The parameter describing this generic event
|
The parameter describing this generic event
|
||||||
*/
|
*/
|
||||||
const wchar_t *param;
|
const wchar_t *param;
|
||||||
|
|
||||||
} param1;
|
} param1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The name of the event handler function
|
The name of the event handler function
|
||||||
*/
|
*/
|
||||||
const wchar_t *function_name;
|
const wchar_t *function_name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The argument list. Only used when sending a new event using
|
The argument list. Only used when sending a new event using
|
||||||
|
@ -96,28 +96,28 @@ typedef struct
|
||||||
event_t;
|
event_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Add an event handler
|
Add an event handler
|
||||||
|
|
||||||
May not be called by a signal handler, since it may allocate new memory.
|
May not be called by a signal handler, since it may allocate new memory.
|
||||||
*/
|
*/
|
||||||
void event_add_handler( event_t *event );
|
void event_add_handler( event_t *event );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Remove all events matching the specified criterion.
|
Remove all events matching the specified criterion.
|
||||||
|
|
||||||
May not be called by a signal handler, since it may free allocated memory.
|
May not be called by a signal handler, since it may free allocated memory.
|
||||||
*/
|
*/
|
||||||
void event_remove( event_t *event );
|
void event_remove( event_t *event );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return all events which match the specified event class
|
Return all events which match the specified event class
|
||||||
|
|
||||||
This function is safe to call from a signal handler _ONLY_ if the
|
This function is safe to call from a signal handler _ONLY_ if the
|
||||||
out parameter is null.
|
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 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
|
\param out the list to add events to. May be 0, in which case no events will be added, but the result count will still be valid
|
||||||
|
|
||||||
\return the number of found matches
|
\return the number of found matches
|
||||||
*/
|
*/
|
||||||
int event_get( event_t *criterion, array_list_t *out );
|
int event_get( event_t *criterion, array_list_t *out );
|
||||||
|
|
4
exec.h
4
exec.h
|
@ -19,7 +19,7 @@
|
||||||
#define PIPE_ERROR _(L"An error occurred while setting up pipe")
|
#define PIPE_ERROR _(L"An error occurred while setting up pipe")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Execute the processes specified by j.
|
Execute the processes specified by j.
|
||||||
|
|
||||||
I've put a fair bit of work into making builtins behave like other
|
I've put a fair bit of work into making builtins behave like other
|
||||||
programs as far as pipes are concerned. Unlike i.e. bash, builtins
|
programs as far as pipes are concerned. Unlike i.e. bash, builtins
|
||||||
|
@ -51,7 +51,7 @@ void exec( job_t *j );
|
||||||
|
|
||||||
\return the status of the last job to exit, or -1 if en error was encountered.
|
\return the status of the last job to exit, or -1 if en error was encountered.
|
||||||
*/
|
*/
|
||||||
__warn_unused int exec_subshell( const wchar_t *cmd,
|
__warn_unused int exec_subshell( const wchar_t *cmd,
|
||||||
array_list_t *l );
|
array_list_t *l );
|
||||||
|
|
||||||
|
|
||||||
|
|
210
expand.c
210
expand.c
|
@ -1,7 +1,7 @@
|
||||||
/**\file expand.c
|
/**\file expand.c
|
||||||
|
|
||||||
String expansion functions. These functions perform several kinds of
|
String expansion functions. These functions perform several kinds of
|
||||||
parameter expansion.
|
parameter expansion.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ wchar_t *expand_escape_variable( const wchar_t *in )
|
||||||
case 0:
|
case 0:
|
||||||
sb_append( &buff, L"''");
|
sb_append( &buff, L"''");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
wchar_t *el = (wchar_t *)al_get( &l, 0 );
|
wchar_t *el = (wchar_t *)al_get( &l, 0 );
|
||||||
|
@ -276,14 +276,14 @@ static int match_pid( const wchar_t *cmd,
|
||||||
int *offset)
|
int *offset)
|
||||||
{
|
{
|
||||||
/* Test for direct match */
|
/* Test for direct match */
|
||||||
|
|
||||||
if( wcsncmp( cmd, proc, wcslen( proc ) ) == 0 )
|
if( wcsncmp( cmd, proc, wcslen( proc ) ) == 0 )
|
||||||
{
|
{
|
||||||
if( offset )
|
if( offset )
|
||||||
*offset = 0;
|
*offset = 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Test if the commandline is a path to the command, if so we try
|
Test if the commandline is a path to the command, if so we try
|
||||||
to match against only the command part
|
to match against only the command part
|
||||||
|
@ -313,7 +313,7 @@ static int match_pid( const wchar_t *cmd,
|
||||||
{
|
{
|
||||||
if( offset )
|
if( offset )
|
||||||
*offset = start+1-first_token;
|
*offset = start+1-first_token;
|
||||||
|
|
||||||
free( first_token );
|
free( first_token );
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -373,14 +373,14 @@ static int find_process( const wchar_t *proc,
|
||||||
if( wcsncmp( proc, jid, wcslen(proc ) )==0 )
|
if( wcsncmp( proc, jid, wcslen(proc ) )==0 )
|
||||||
{
|
{
|
||||||
string_buffer_t desc_buff;
|
string_buffer_t desc_buff;
|
||||||
|
|
||||||
sb_init( &desc_buff );
|
sb_init( &desc_buff );
|
||||||
|
|
||||||
sb_printf( &desc_buff,
|
sb_printf( &desc_buff,
|
||||||
COMPLETE_JOB_DESC_VAL,
|
COMPLETE_JOB_DESC_VAL,
|
||||||
j->command );
|
j->command );
|
||||||
|
|
||||||
completion_allocate( out,
|
completion_allocate( out,
|
||||||
jid+wcslen(proc),
|
jid+wcslen(proc),
|
||||||
(wchar_t *)desc_buff.buff,
|
(wchar_t *)desc_buff.buff,
|
||||||
0 );
|
0 );
|
||||||
|
@ -395,7 +395,7 @@ static int find_process( const wchar_t *proc,
|
||||||
|
|
||||||
int jid;
|
int jid;
|
||||||
wchar_t *end;
|
wchar_t *end;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
jid = wcstol( proc, &end, 10 );
|
jid = wcstol( proc, &end, 10 );
|
||||||
if( jid > 0 && !errno && !*end )
|
if( jid > 0 && !errno && !*end )
|
||||||
|
@ -403,7 +403,7 @@ static int find_process( const wchar_t *proc,
|
||||||
j = job_get( jid );
|
j = job_get( jid );
|
||||||
if( (j != 0) && (j->command != 0 ) )
|
if( (j != 0) && (j->command != 0 ) )
|
||||||
{
|
{
|
||||||
|
|
||||||
{
|
{
|
||||||
result = malloc(sizeof(wchar_t)*16 );
|
result = malloc(sizeof(wchar_t)*16 );
|
||||||
swprintf( result, 16, L"%d", j->pgid );
|
swprintf( result, 16, L"%d", j->pgid );
|
||||||
|
@ -420,15 +420,15 @@ static int find_process( const wchar_t *proc,
|
||||||
for( j=first_job; j != 0; j=j->next )
|
for( j=first_job; j != 0; j=j->next )
|
||||||
{
|
{
|
||||||
int offset;
|
int offset;
|
||||||
|
|
||||||
if( j->command == 0 )
|
if( j->command == 0 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if( match_pid( j->command, proc, flags, &offset ) )
|
if( match_pid( j->command, proc, flags, &offset ) )
|
||||||
{
|
{
|
||||||
if( flags & ACCEPT_INCOMPLETE )
|
if( flags & ACCEPT_INCOMPLETE )
|
||||||
{
|
{
|
||||||
completion_allocate( out,
|
completion_allocate( out,
|
||||||
j->command + offset + wcslen(proc),
|
j->command + offset + wcslen(proc),
|
||||||
COMPLETE_JOB_DESC,
|
COMPLETE_JOB_DESC,
|
||||||
0 );
|
0 );
|
||||||
|
@ -456,7 +456,7 @@ static int find_process( const wchar_t *proc,
|
||||||
for( p=j->first_process; p; p=p->next )
|
for( p=j->first_process; p; p=p->next )
|
||||||
{
|
{
|
||||||
int offset;
|
int offset;
|
||||||
|
|
||||||
if( p->actual_cmd == 0 )
|
if( p->actual_cmd == 0 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -464,7 +464,7 @@ static int find_process( const wchar_t *proc,
|
||||||
{
|
{
|
||||||
if( flags & ACCEPT_INCOMPLETE )
|
if( flags & ACCEPT_INCOMPLETE )
|
||||||
{
|
{
|
||||||
completion_allocate( out,
|
completion_allocate( out,
|
||||||
p->actual_cmd + offset + wcslen(proc),
|
p->actual_cmd + offset + wcslen(proc),
|
||||||
COMPLETE_CHILD_PROCESS_DESC,
|
COMPLETE_CHILD_PROCESS_DESC,
|
||||||
0 );
|
0 );
|
||||||
|
@ -496,7 +496,7 @@ static int find_process( const wchar_t *proc,
|
||||||
pdir_name = malloc( sizeof(wchar_t)*256 );
|
pdir_name = malloc( sizeof(wchar_t)*256 );
|
||||||
pfile_name = malloc( sizeof(wchar_t)*64 );
|
pfile_name = malloc( sizeof(wchar_t)*64 );
|
||||||
wcscpy( pdir_name, L"/proc/" );
|
wcscpy( pdir_name, L"/proc/" );
|
||||||
|
|
||||||
while( (next=wreaddir(dir))!=0 )
|
while( (next=wreaddir(dir))!=0 )
|
||||||
{
|
{
|
||||||
wchar_t *name = next->d_name;
|
wchar_t *name = next->d_name;
|
||||||
|
@ -533,7 +533,7 @@ static int find_process( const wchar_t *proc,
|
||||||
signal_block();
|
signal_block();
|
||||||
fgetws2( &cmd, &sz, cmdfile );
|
fgetws2( &cmd, &sz, cmdfile );
|
||||||
signal_unblock();
|
signal_unblock();
|
||||||
|
|
||||||
fclose( cmdfile );
|
fclose( cmdfile );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -574,12 +574,12 @@ static int find_process( const wchar_t *proc,
|
||||||
if( cmd != 0 )
|
if( cmd != 0 )
|
||||||
{
|
{
|
||||||
int offset;
|
int offset;
|
||||||
|
|
||||||
if( match_pid( cmd, proc, flags, &offset ) )
|
if( match_pid( cmd, proc, flags, &offset ) )
|
||||||
{
|
{
|
||||||
if( flags & ACCEPT_INCOMPLETE )
|
if( flags & ACCEPT_INCOMPLETE )
|
||||||
{
|
{
|
||||||
completion_allocate( out,
|
completion_allocate( out,
|
||||||
cmd + offset + wcslen(proc),
|
cmd + offset + wcslen(proc),
|
||||||
COMPLETE_PROCESS_DESC,
|
COMPLETE_PROCESS_DESC,
|
||||||
0 );
|
0 );
|
||||||
|
@ -615,7 +615,7 @@ static int expand_pid( wchar_t *in,
|
||||||
|
|
||||||
CHECK( in, 0 );
|
CHECK( in, 0 );
|
||||||
CHECK( out, 0 );
|
CHECK( out, 0 );
|
||||||
|
|
||||||
if( *in != PROCESS_EXPAND )
|
if( *in != PROCESS_EXPAND )
|
||||||
{
|
{
|
||||||
al_push( out, in );
|
al_push( out, in );
|
||||||
|
@ -626,16 +626,16 @@ static int expand_pid( wchar_t *in,
|
||||||
{
|
{
|
||||||
if( wcsncmp( in+1, SELF_STR, wcslen(in+1) )==0 )
|
if( wcsncmp( in+1, SELF_STR, wcslen(in+1) )==0 )
|
||||||
{
|
{
|
||||||
completion_allocate( out,
|
completion_allocate( out,
|
||||||
SELF_STR+wcslen(in+1),
|
SELF_STR+wcslen(in+1),
|
||||||
COMPLETE_SELF_DESC,
|
COMPLETE_SELF_DESC,
|
||||||
0 );
|
0 );
|
||||||
}
|
}
|
||||||
else if( wcsncmp( in+1, LAST_STR, wcslen(in+1) )==0 )
|
else if( wcsncmp( in+1, LAST_STR, wcslen(in+1) )==0 )
|
||||||
{
|
{
|
||||||
completion_allocate( out,
|
completion_allocate( out,
|
||||||
LAST_STR+wcslen(in+1),
|
LAST_STR+wcslen(in+1),
|
||||||
COMPLETE_LAST_DESC,
|
COMPLETE_LAST_DESC,
|
||||||
0 );
|
0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -692,7 +692,7 @@ static int expand_pid( wchar_t *in,
|
||||||
void expand_variable_error( const wchar_t *token, int token_pos, int error_pos )
|
void expand_variable_error( const wchar_t *token, int token_pos, int error_pos )
|
||||||
{
|
{
|
||||||
int stop_pos = token_pos+1;
|
int stop_pos = token_pos+1;
|
||||||
|
|
||||||
switch( token[stop_pos] )
|
switch( token[stop_pos] )
|
||||||
{
|
{
|
||||||
case BRACKET_BEGIN:
|
case BRACKET_BEGIN:
|
||||||
|
@ -707,13 +707,13 @@ void expand_variable_error( const wchar_t *token, int token_pos, int error_pos )
|
||||||
{
|
{
|
||||||
post = end+1;
|
post = end+1;
|
||||||
*end = 0;
|
*end = 0;
|
||||||
|
|
||||||
if( !wcsvarname( name ) )
|
if( !wcsvarname( name ) )
|
||||||
{
|
{
|
||||||
is_var = 1;
|
is_var = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( is_var )
|
if( is_var )
|
||||||
{
|
{
|
||||||
error( SYNTAX_ERROR,
|
error( SYNTAX_ERROR,
|
||||||
|
@ -721,7 +721,7 @@ void expand_variable_error( const wchar_t *token, int token_pos, int error_pos )
|
||||||
COMPLETE_VAR_BRACKET_DESC,
|
COMPLETE_VAR_BRACKET_DESC,
|
||||||
cpy,
|
cpy,
|
||||||
name,
|
name,
|
||||||
post );
|
post );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -733,18 +733,18 @@ void expand_variable_error( const wchar_t *token, int token_pos, int error_pos )
|
||||||
L"" );
|
L"" );
|
||||||
}
|
}
|
||||||
free( cpy );
|
free( cpy );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case INTERNAL_SEPARATOR:
|
case INTERNAL_SEPARATOR:
|
||||||
{
|
{
|
||||||
error( SYNTAX_ERROR,
|
error( SYNTAX_ERROR,
|
||||||
error_pos,
|
error_pos,
|
||||||
COMPLETE_VAR_PARAN_DESC );
|
COMPLETE_VAR_PARAN_DESC );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
error( SYNTAX_ERROR,
|
error( SYNTAX_ERROR,
|
||||||
|
@ -752,7 +752,7 @@ void expand_variable_error( const wchar_t *token, int token_pos, int error_pos )
|
||||||
COMPLETE_VAR_NULL_DESC );
|
COMPLETE_VAR_NULL_DESC );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
error( SYNTAX_ERROR,
|
error( SYNTAX_ERROR,
|
||||||
|
@ -769,28 +769,28 @@ void expand_variable_error( const wchar_t *token, int token_pos, int error_pos )
|
||||||
*/
|
*/
|
||||||
static int parse_slice( wchar_t *in, wchar_t **end_ptr, array_list_t *idx )
|
static int parse_slice( wchar_t *in, wchar_t **end_ptr, array_list_t *idx )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
wchar_t *end;
|
wchar_t *end;
|
||||||
|
|
||||||
int pos = 1;
|
int pos = 1;
|
||||||
|
|
||||||
// debug( 0, L"parse_slice on '%ls'", in );
|
// debug( 0, L"parse_slice on '%ls'", in );
|
||||||
|
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
long tmp;
|
long tmp;
|
||||||
|
|
||||||
while( iswspace(in[pos]) || (in[pos]==INTERNAL_SEPARATOR))
|
while( iswspace(in[pos]) || (in[pos]==INTERNAL_SEPARATOR))
|
||||||
pos++;
|
pos++;
|
||||||
|
|
||||||
if( in[pos] == L']' )
|
if( in[pos] == L']' )
|
||||||
{
|
{
|
||||||
pos++;
|
pos++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
errno=0;
|
errno=0;
|
||||||
tmp = wcstol( &in[pos], &end, 10 );
|
tmp = wcstol( &in[pos], &end, 10 );
|
||||||
if( ( errno ) || ( end == &in[pos] ) )
|
if( ( errno ) || ( end == &in[pos] ) )
|
||||||
|
@ -798,19 +798,19 @@ static int parse_slice( wchar_t *in, wchar_t **end_ptr, array_list_t *idx )
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// debug( 0, L"Push idx %d", tmp );
|
// debug( 0, L"Push idx %d", tmp );
|
||||||
|
|
||||||
al_push_long( idx, tmp );
|
al_push_long( idx, tmp );
|
||||||
pos = end-in;
|
pos = end-in;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( end_ptr )
|
if( end_ptr )
|
||||||
{
|
{
|
||||||
// debug( 0, L"Remainder is '%ls', slice def was %d characters long", in+pos, pos );
|
// debug( 0, L"Remainder is '%ls', slice def was %d characters long", in+pos, pos );
|
||||||
|
|
||||||
*end_ptr = in+pos;
|
*end_ptr = in+pos;
|
||||||
}
|
}
|
||||||
// debug( 0, L"ok, done" );
|
// debug( 0, L"ok, done" );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -843,7 +843,7 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
|
||||||
|
|
||||||
CHECK( in, 0 );
|
CHECK( in, 0 );
|
||||||
CHECK( out, 0 );
|
CHECK( out, 0 );
|
||||||
|
|
||||||
if( !var_tmp )
|
if( !var_tmp )
|
||||||
{
|
{
|
||||||
var_tmp = sb_halloc( global_context );
|
var_tmp = sb_halloc( global_context );
|
||||||
|
@ -878,7 +878,7 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
|
||||||
wchar_t * new_in;
|
wchar_t * new_in;
|
||||||
int is_single = (c==VARIABLE_EXPAND_SINGLE);
|
int is_single = (c==VARIABLE_EXPAND_SINGLE);
|
||||||
int var_name_stop_pos;
|
int var_name_stop_pos;
|
||||||
|
|
||||||
stop_pos = start_pos;
|
stop_pos = start_pos;
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
|
@ -892,15 +892,15 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
|
||||||
stop_pos++;
|
stop_pos++;
|
||||||
}
|
}
|
||||||
var_name_stop_pos = stop_pos;
|
var_name_stop_pos = stop_pos;
|
||||||
|
|
||||||
/* printf( "Stop for '%c'\n", in[stop_pos]);*/
|
/* printf( "Stop for '%c'\n", in[stop_pos]);*/
|
||||||
|
|
||||||
var_len = stop_pos - start_pos;
|
var_len = stop_pos - start_pos;
|
||||||
|
|
||||||
if( var_len == 0 )
|
if( var_len == 0 )
|
||||||
{
|
{
|
||||||
expand_variable_error( in, stop_pos-1, -1 );
|
expand_variable_error( in, stop_pos-1, -1 );
|
||||||
|
|
||||||
is_ok = 0;
|
is_ok = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -919,17 +919,17 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
|
||||||
{
|
{
|
||||||
wchar_t *slice_end;
|
wchar_t *slice_end;
|
||||||
all_vars=0;
|
all_vars=0;
|
||||||
|
|
||||||
if( parse_slice( &in[stop_pos], &slice_end, var_idx_list ) )
|
if( parse_slice( &in[stop_pos], &slice_end, var_idx_list ) )
|
||||||
{
|
{
|
||||||
error( SYNTAX_ERROR,
|
error( SYNTAX_ERROR,
|
||||||
-1,
|
-1,
|
||||||
L"Invalid index value" );
|
L"Invalid index value" );
|
||||||
is_ok = 0;
|
is_ok = 0;
|
||||||
}
|
}
|
||||||
stop_pos = (slice_end-in);
|
stop_pos = (slice_end-in);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( is_ok )
|
if( is_ok )
|
||||||
{
|
{
|
||||||
tokenize_variable_array( var_val, &var_item_list );
|
tokenize_variable_array( var_val, &var_item_list );
|
||||||
|
@ -974,12 +974,12 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
|
||||||
|
|
||||||
if( is_ok )
|
if( is_ok )
|
||||||
{
|
{
|
||||||
|
|
||||||
if( is_single )
|
if( is_single )
|
||||||
{
|
{
|
||||||
string_buffer_t res;
|
string_buffer_t res;
|
||||||
in[i]=0;
|
in[i]=0;
|
||||||
|
|
||||||
sb_init( &res );
|
sb_init( &res );
|
||||||
sb_append( &res, in );
|
sb_append( &res, in );
|
||||||
sb_append_char( &res, INTERNAL_SEPARATOR );
|
sb_append_char( &res, INTERNAL_SEPARATOR );
|
||||||
|
@ -987,7 +987,7 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
|
||||||
for( j=0; j<al_get_count( &var_item_list); j++ )
|
for( j=0; j<al_get_count( &var_item_list); j++ )
|
||||||
{
|
{
|
||||||
wchar_t *next = (wchar_t *)al_get( &var_item_list, j );
|
wchar_t *next = (wchar_t *)al_get( &var_item_list, j );
|
||||||
|
|
||||||
if( is_ok )
|
if( is_ok )
|
||||||
{
|
{
|
||||||
if( j != 0 )
|
if( j != 0 )
|
||||||
|
@ -1010,19 +1010,19 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
if( is_ok )
|
if( is_ok )
|
||||||
{
|
{
|
||||||
new_len = wcslen(in) - (stop_pos-start_pos+1);
|
new_len = wcslen(in) - (stop_pos-start_pos+1);
|
||||||
new_len += wcslen( next) +2;
|
new_len += wcslen( next) +2;
|
||||||
|
|
||||||
if( !(new_in = malloc( sizeof(wchar_t)*new_len )))
|
if( !(new_in = malloc( sizeof(wchar_t)*new_len )))
|
||||||
{
|
{
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
wcslcpy( new_in, in, start_pos );
|
wcslcpy( new_in, in, start_pos );
|
||||||
|
|
||||||
if(start_pos>1 && new_in[start_pos-2]!=VARIABLE_EXPAND)
|
if(start_pos>1 && new_in[start_pos-2]!=VARIABLE_EXPAND)
|
||||||
|
@ -1032,20 +1032,20 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
new_in[start_pos-1]=L'\0';
|
new_in[start_pos-1]=L'\0';
|
||||||
|
|
||||||
wcscat( new_in, next );
|
wcscat( new_in, next );
|
||||||
wcscat( new_in, &in[stop_pos] );
|
wcscat( new_in, &in[stop_pos] );
|
||||||
|
|
||||||
is_ok &= expand_variables( new_in, out, i );
|
is_ok &= expand_variables( new_in, out, i );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free( next );
|
free( next );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(in);
|
free(in);
|
||||||
al_destroy( &var_item_list );
|
al_destroy( &var_item_list );
|
||||||
return is_ok;
|
return is_ok;
|
||||||
|
@ -1116,7 +1116,7 @@ static int expand_brackets( wchar_t *in, int flags, array_list_t *out )
|
||||||
|
|
||||||
CHECK( in, 0 );
|
CHECK( in, 0 );
|
||||||
CHECK( out, 0 );
|
CHECK( out, 0 );
|
||||||
|
|
||||||
for( pos=in;
|
for( pos=in;
|
||||||
(*pos) && !syntax_error;
|
(*pos) && !syntax_error;
|
||||||
pos++ )
|
pos++ )
|
||||||
|
@ -1138,7 +1138,7 @@ static int expand_brackets( wchar_t *in, int flags, array_list_t *out )
|
||||||
{
|
{
|
||||||
bracket_end = pos;
|
bracket_end = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( bracket_count < 0 )
|
if( bracket_count < 0 )
|
||||||
{
|
{
|
||||||
syntax_error = 1;
|
syntax_error = 1;
|
||||||
|
@ -1246,12 +1246,12 @@ static int expand_cmdsubst( wchar_t *in, array_list_t *out )
|
||||||
array_list_t *sub_res, *tail_expand;
|
array_list_t *sub_res, *tail_expand;
|
||||||
int i, j;
|
int i, j;
|
||||||
const wchar_t *item_begin;
|
const wchar_t *item_begin;
|
||||||
wchar_t *tail_begin = 0;
|
wchar_t *tail_begin = 0;
|
||||||
void *context;
|
void *context;
|
||||||
|
|
||||||
CHECK( in, 0 );
|
CHECK( in, 0 );
|
||||||
CHECK( out, 0 );
|
CHECK( out, 0 );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch( parse_util_locate_cmdsubst(in,
|
switch( parse_util_locate_cmdsubst(in,
|
||||||
|
@ -1281,7 +1281,7 @@ static int expand_cmdsubst( wchar_t *in, array_list_t *out )
|
||||||
sub_res = al_halloc( context );
|
sub_res = al_halloc( context );
|
||||||
if( !(subcmd = halloc( context, sizeof(wchar_t)*(paran_end-paran_begin) )))
|
if( !(subcmd = halloc( context, sizeof(wchar_t)*(paran_end-paran_begin) )))
|
||||||
{
|
{
|
||||||
halloc_free( context );
|
halloc_free( context );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1300,10 +1300,10 @@ static int expand_cmdsubst( wchar_t *in, array_list_t *out )
|
||||||
{
|
{
|
||||||
array_list_t *slice_idx = al_halloc( context );
|
array_list_t *slice_idx = al_halloc( context );
|
||||||
wchar_t *slice_end;
|
wchar_t *slice_end;
|
||||||
|
|
||||||
if( parse_slice( tail_begin, &slice_end, slice_idx ) )
|
if( parse_slice( tail_begin, &slice_end, slice_idx ) )
|
||||||
{
|
{
|
||||||
halloc_free( context );
|
halloc_free( context );
|
||||||
error( SYNTAX_ERROR, -1, L"Invalid index value" );
|
error( SYNTAX_ERROR, -1, L"Invalid index value" );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1318,23 +1318,23 @@ static int expand_cmdsubst( wchar_t *in, array_list_t *out )
|
||||||
{
|
{
|
||||||
idx = al_get_count( sub_res ) + idx + 1;
|
idx = al_get_count( sub_res ) + idx + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( idx < 1 || idx > al_get_count( sub_res ) )
|
if( idx < 1 || idx > al_get_count( sub_res ) )
|
||||||
{
|
{
|
||||||
halloc_free( context );
|
halloc_free( context );
|
||||||
error( SYNTAX_ERROR, -1, L"Invalid index value" );
|
error( SYNTAX_ERROR, -1, L"Invalid index value" );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
idx = idx-1;
|
idx = idx-1;
|
||||||
|
|
||||||
al_push( sub_res2, al_get( sub_res, idx ) );
|
al_push( sub_res2, al_get( sub_res, idx ) );
|
||||||
// debug( 0, L"Pushing item '%ls' with index %d onto sliced result", al_get( sub_res, idx ), idx );
|
// debug( 0, L"Pushing item '%ls' with index %d onto sliced result", al_get( sub_res, idx ), idx );
|
||||||
|
|
||||||
al_set( sub_res, idx, 0 );
|
al_set( sub_res, idx, 0 );
|
||||||
}
|
}
|
||||||
al_foreach( sub_res, &free );
|
al_foreach( sub_res, &free );
|
||||||
sub_res = sub_res2;
|
sub_res = sub_res2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1371,16 +1371,16 @@ static int expand_cmdsubst( wchar_t *in, array_list_t *out )
|
||||||
sb_append_substring( &whole_item, sub_item2, item_len );
|
sb_append_substring( &whole_item, sub_item2, item_len );
|
||||||
sb_append_char( &whole_item, INTERNAL_SEPARATOR );
|
sb_append_char( &whole_item, INTERNAL_SEPARATOR );
|
||||||
sb_append( &whole_item, tail_item );
|
sb_append( &whole_item, tail_item );
|
||||||
|
|
||||||
al_push( out, whole_item.buff );
|
al_push( out, whole_item.buff );
|
||||||
}
|
}
|
||||||
|
|
||||||
free( sub_item2 );
|
free( sub_item2 );
|
||||||
}
|
}
|
||||||
free(in);
|
free(in);
|
||||||
|
|
||||||
al_foreach( tail_expand, &free );
|
al_foreach( tail_expand, &free );
|
||||||
halloc_free( context );
|
halloc_free( context );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1481,7 +1481,7 @@ static wchar_t * expand_tilde_internal( wchar_t *in )
|
||||||
wchar_t *expand_tilde( wchar_t *in)
|
wchar_t *expand_tilde( wchar_t *in)
|
||||||
{
|
{
|
||||||
CHECK( in, 0 );
|
CHECK( in, 0 );
|
||||||
|
|
||||||
if( in[0] == L'~' )
|
if( in[0] == L'~' )
|
||||||
{
|
{
|
||||||
in[0] = HOME_DIRECTORY;
|
in[0] = HOME_DIRECTORY;
|
||||||
|
@ -1498,7 +1498,7 @@ static void remove_internal_separator( const void *s, int conv )
|
||||||
{
|
{
|
||||||
wchar_t *in = (wchar_t *)s;
|
wchar_t *in = (wchar_t *)s;
|
||||||
wchar_t *out=in;
|
wchar_t *out=in;
|
||||||
|
|
||||||
CHECK( s, );
|
CHECK( s, );
|
||||||
|
|
||||||
while( *in )
|
while( *in )
|
||||||
|
@ -1508,7 +1508,7 @@ static void remove_internal_separator( const void *s, int conv )
|
||||||
case INTERNAL_SEPARATOR:
|
case INTERNAL_SEPARATOR:
|
||||||
in++;
|
in++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ANY_CHAR:
|
case ANY_CHAR:
|
||||||
in++;
|
in++;
|
||||||
*out++ = conv?L'?':ANY_CHAR;
|
*out++ = conv?L'?':ANY_CHAR;
|
||||||
|
@ -1564,7 +1564,7 @@ int expand_string( void *context,
|
||||||
if( EXPAND_SKIP_CMDSUBST & flags )
|
if( EXPAND_SKIP_CMDSUBST & flags )
|
||||||
{
|
{
|
||||||
wchar_t *begin, *end;
|
wchar_t *begin, *end;
|
||||||
|
|
||||||
if( parse_util_locate_cmdsubst( str,
|
if( parse_util_locate_cmdsubst( str,
|
||||||
&begin,
|
&begin,
|
||||||
&end,
|
&end,
|
||||||
|
@ -1611,7 +1611,7 @@ int expand_string( void *context,
|
||||||
if( !next )
|
if( !next )
|
||||||
{
|
{
|
||||||
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
|
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( EXPAND_SKIP_VARIABLES & flags )
|
if( EXPAND_SKIP_VARIABLES & flags )
|
||||||
|
@ -1645,8 +1645,8 @@ int expand_string( void *context,
|
||||||
if( !next )
|
if( !next )
|
||||||
{
|
{
|
||||||
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
|
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !expand_brackets( next, flags, out ))
|
if( !expand_brackets( next, flags, out ))
|
||||||
{
|
{
|
||||||
|
@ -1667,8 +1667,8 @@ int expand_string( void *context,
|
||||||
if( !next )
|
if( !next )
|
||||||
{
|
{
|
||||||
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
|
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !(next=expand_tilde_internal( next ) ) )
|
if( !(next=expand_tilde_internal( next ) ) )
|
||||||
{
|
{
|
||||||
|
@ -1719,11 +1719,11 @@ int expand_string( void *context,
|
||||||
if( !next )
|
if( !next )
|
||||||
{
|
{
|
||||||
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
|
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_internal_separator( next, EXPAND_SKIP_WILDCARDS & flags );
|
remove_internal_separator( next, EXPAND_SKIP_WILDCARDS & flags );
|
||||||
|
|
||||||
if( ((flags & ACCEPT_INCOMPLETE) && (!(flags & EXPAND_SKIP_WILDCARDS))) ||
|
if( ((flags & ACCEPT_INCOMPLETE) && (!(flags & EXPAND_SKIP_WILDCARDS))) ||
|
||||||
wildcard_has( next, 1 ) )
|
wildcard_has( next, 1 ) )
|
||||||
{
|
{
|
||||||
|
@ -1745,14 +1745,14 @@ int expand_string( void *context,
|
||||||
{
|
{
|
||||||
list = end_out;
|
list = end_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
wc_res = wildcard_expand( rest, start, flags, list );
|
wc_res = wildcard_expand( rest, start, flags, list );
|
||||||
|
|
||||||
free( next );
|
free( next );
|
||||||
|
|
||||||
if( !(flags & ACCEPT_INCOMPLETE) )
|
if( !(flags & ACCEPT_INCOMPLETE) )
|
||||||
{
|
{
|
||||||
|
|
||||||
switch( wc_res )
|
switch( wc_res )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -1764,7 +1764,7 @@ int expand_string( void *context,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
|
@ -1777,8 +1777,8 @@ int expand_string( void *context,
|
||||||
if( !next )
|
if( !next )
|
||||||
{
|
{
|
||||||
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
|
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
al_push( end_out, next );
|
al_push( end_out, next );
|
||||||
}
|
}
|
||||||
al_truncate( out, 0 );
|
al_truncate( out, 0 );
|
||||||
|
@ -1792,10 +1792,10 @@ int expand_string( void *context,
|
||||||
al_destroy( out );
|
al_destroy( out );
|
||||||
return EXPAND_ERROR;
|
return EXPAND_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1822,7 +1822,7 @@ int expand_string( void *context,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1835,13 +1835,13 @@ wchar_t *expand_one( void *context, wchar_t *string, int flags )
|
||||||
wchar_t *one;
|
wchar_t *one;
|
||||||
|
|
||||||
CHECK( string, 0 );
|
CHECK( string, 0 );
|
||||||
|
|
||||||
if( (!(flags & ACCEPT_INCOMPLETE)) && expand_is_clean( string ) )
|
if( (!(flags & ACCEPT_INCOMPLETE)) && expand_is_clean( string ) )
|
||||||
{
|
{
|
||||||
halloc_register( context, string );
|
halloc_register( context, string );
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
al_init( &l );
|
al_init( &l );
|
||||||
res = expand_string( 0, string, &l, flags );
|
res = expand_string( 0, string, &l, flags );
|
||||||
if( !res )
|
if( !res )
|
||||||
|
|
14
expand.h
14
expand.h
|
@ -6,7 +6,7 @@
|
||||||
benefit from using a more clever memory allocation scheme, perhaps
|
benefit from using a more clever memory allocation scheme, perhaps
|
||||||
an evil combination of talloc, string buffers and reference
|
an evil combination of talloc, string buffers and reference
|
||||||
counting.
|
counting.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef FISH_EXPAND_H
|
#ifndef FISH_EXPAND_H
|
||||||
|
@ -70,7 +70,7 @@ enum
|
||||||
|
|
||||||
/** Character represeting process expansion */
|
/** Character represeting process expansion */
|
||||||
PROCESS_EXPAND,
|
PROCESS_EXPAND,
|
||||||
|
|
||||||
/** Character representing variable expansion */
|
/** Character representing variable expansion */
|
||||||
VARIABLE_EXPAND,
|
VARIABLE_EXPAND,
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ enum
|
||||||
/** Character representing separation between two bracket elements */
|
/** Character representing separation between two bracket elements */
|
||||||
BRACKET_SEP,
|
BRACKET_SEP,
|
||||||
/**
|
/**
|
||||||
Separate subtokens in a token with this character.
|
Separate subtokens in a token with this character.
|
||||||
*/
|
*/
|
||||||
INTERNAL_SEPARATOR,
|
INTERNAL_SEPARATOR,
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ enum
|
||||||
(\$VAR_NAME becomes the value of the environment variable VAR_NAME),
|
(\$VAR_NAME becomes the value of the environment variable VAR_NAME),
|
||||||
cmdsubst expansion and wildcard expansion. The results are inserted
|
cmdsubst expansion and wildcard expansion. The results are inserted
|
||||||
into the list out.
|
into the list out.
|
||||||
|
|
||||||
If the parameter does not need expansion, it is copied into the list
|
If the parameter does not need expansion, it is copied into the list
|
||||||
out. If expansion is performed, the original parameter is freed and
|
out. If expansion is performed, the original parameter is freed and
|
||||||
newly allocated strings are inserted into the list out.
|
newly allocated strings are inserted into the list out.
|
||||||
|
@ -136,7 +136,7 @@ enum
|
||||||
If \c context is non-null, all the strings contained in the
|
If \c context is non-null, all the strings contained in the
|
||||||
array_list_t \c out will be registered to be free'd when context is
|
array_list_t \c out will be registered to be free'd when context is
|
||||||
free'd.
|
free'd.
|
||||||
|
|
||||||
\param context the halloc context to use for automatic deallocation
|
\param context the halloc context to use for automatic deallocation
|
||||||
\param in The parameter to expand
|
\param in The parameter to expand
|
||||||
\param flag Specifies if any expansion pass should be skipped. Legal values are any combination of EXPAND_SKIP_CMDSUBST EXPAND_SKIP_VARIABLES and EXPAND_SKIP_WILDCARDS
|
\param flag Specifies if any expansion pass should be skipped. Legal values are any combination of EXPAND_SKIP_CMDSUBST EXPAND_SKIP_VARIABLES and EXPAND_SKIP_WILDCARDS
|
||||||
|
@ -152,8 +152,8 @@ __warn_unused int expand_string( void *context, wchar_t *in, array_list_t *out,
|
||||||
|
|
||||||
If \c context is non-null, the returning string ill be registered
|
If \c context is non-null, the returning string ill be registered
|
||||||
to be free'd when context is free'd.
|
to be free'd when context is free'd.
|
||||||
|
|
||||||
\param context the halloc context to use for automatic deallocation
|
\param context the halloc context to use for automatic deallocation
|
||||||
\param in The parameter to expand
|
\param in The parameter to expand
|
||||||
\param flag Specifies if any expansion pass should be skipped. Legal values are any combination of EXPAND_SKIP_CMDSUBST EXPAND_SKIP_VARIABLES and EXPAND_SKIP_WILDCARDS
|
\param flag Specifies if any expansion pass should be skipped. Legal values are any combination of EXPAND_SKIP_CMDSUBST EXPAND_SKIP_VARIABLES and EXPAND_SKIP_WILDCARDS
|
||||||
\return The expanded parameter, or 0 on failiure
|
\return The expanded parameter, or 0 on failiure
|
||||||
|
|
240
fallback.c
240
fallback.c
|
@ -60,7 +60,7 @@ int tputs(const char *str, int affcnt, int (*fish_putc)(tputs_arg_t))
|
||||||
while( *str )
|
while( *str )
|
||||||
{
|
{
|
||||||
fish_putc( *str++ );
|
fish_putc( *str++ );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -81,26 +81,26 @@ char *tparm_solaris_kludge( char *str, ... )
|
||||||
|
|
||||||
if( ( set_a_foreground && ! strcmp( str, set_a_foreground ) )
|
if( ( set_a_foreground && ! strcmp( str, set_a_foreground ) )
|
||||||
|| ( set_a_background && ! strcmp( str, set_a_background ) )
|
|| ( set_a_background && ! strcmp( str, set_a_background ) )
|
||||||
|| ( set_foreground && ! strcmp( str, set_foreground ) )
|
|| ( set_foreground && ! strcmp( str, set_foreground ) )
|
||||||
|| ( set_background && ! strcmp( str, set_background ) )
|
|| ( set_background && ! strcmp( str, set_background ) )
|
||||||
|| ( enter_underline_mode && ! strcmp( str, enter_underline_mode ) )
|
|| ( enter_underline_mode && ! strcmp( str, enter_underline_mode ) )
|
||||||
|| ( exit_underline_mode && ! strcmp( str, exit_underline_mode ) )
|
|| ( exit_underline_mode && ! strcmp( str, exit_underline_mode ) )
|
||||||
|| ( enter_standout_mode && ! strcmp( str, enter_standout_mode ) )
|
|| ( enter_standout_mode && ! strcmp( str, enter_standout_mode ) )
|
||||||
|| ( exit_standout_mode && ! strcmp( str, exit_standout_mode ) )
|
|| ( exit_standout_mode && ! strcmp( str, exit_standout_mode ) )
|
||||||
|| ( flash_screen && ! strcmp( str, flash_screen ) )
|
|| ( flash_screen && ! strcmp( str, flash_screen ) )
|
||||||
|| ( enter_subscript_mode && ! strcmp( str, enter_subscript_mode ) )
|
|| ( enter_subscript_mode && ! strcmp( str, enter_subscript_mode ) )
|
||||||
|| ( exit_subscript_mode && ! strcmp( str, exit_subscript_mode ) )
|
|| ( exit_subscript_mode && ! strcmp( str, exit_subscript_mode ) )
|
||||||
|| ( enter_superscript_mode && ! strcmp( str, enter_superscript_mode ) )
|
|| ( enter_superscript_mode && ! strcmp( str, enter_superscript_mode ) )
|
||||||
|| ( exit_superscript_mode && ! strcmp( str, exit_superscript_mode ) )
|
|| ( exit_superscript_mode && ! strcmp( str, exit_superscript_mode ) )
|
||||||
|| ( enter_blink_mode && ! strcmp( str, enter_blink_mode ) )
|
|| ( enter_blink_mode && ! strcmp( str, enter_blink_mode ) )
|
||||||
|| ( enter_italics_mode && ! strcmp( str, enter_italics_mode ) )
|
|| ( enter_italics_mode && ! strcmp( str, enter_italics_mode ) )
|
||||||
|| ( exit_italics_mode && ! strcmp( str, exit_italics_mode ) )
|
|| ( exit_italics_mode && ! strcmp( str, exit_italics_mode ) )
|
||||||
|| ( enter_reverse_mode && ! strcmp( str, enter_reverse_mode ) )
|
|| ( enter_reverse_mode && ! strcmp( str, enter_reverse_mode ) )
|
||||||
|| ( enter_shadow_mode && ! strcmp( str, enter_shadow_mode ) )
|
|| ( enter_shadow_mode && ! strcmp( str, enter_shadow_mode ) )
|
||||||
|| ( exit_shadow_mode && ! strcmp( str, exit_shadow_mode ) )
|
|| ( exit_shadow_mode && ! strcmp( str, exit_shadow_mode ) )
|
||||||
|| ( enter_standout_mode && ! strcmp( str, enter_standout_mode ) )
|
|| ( enter_standout_mode && ! strcmp( str, enter_standout_mode ) )
|
||||||
|| ( exit_standout_mode && ! strcmp( str, exit_standout_mode ) )
|
|| ( exit_standout_mode && ! strcmp( str, exit_standout_mode ) )
|
||||||
|| ( enter_secure_mode && ! strcmp( str, enter_secure_mode ) )
|
|| ( enter_secure_mode && ! strcmp( str, enter_secure_mode ) )
|
||||||
|| ( enter_bold_mode && ! strcmp ( str, enter_bold_mode ) ) )
|
|| ( enter_bold_mode && ! strcmp ( str, enter_bold_mode ) ) )
|
||||||
{
|
{
|
||||||
param[0] = va_arg( ap, long int );
|
param[0] = va_arg( ap, long int );
|
||||||
|
@ -140,11 +140,11 @@ char *tparm_solaris_kludge( char *str, ... )
|
||||||
*/
|
*/
|
||||||
static void pad( void (*writer)(wchar_t), int count)
|
static void pad( void (*writer)(wchar_t), int count)
|
||||||
{
|
{
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
if( count < 0 )
|
if( count < 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for( i=0; i<count; i++ )
|
for( i=0; i<count; i++ )
|
||||||
{
|
{
|
||||||
writer( L' ' );
|
writer( L' ' );
|
||||||
|
@ -171,13 +171,13 @@ static void pad( void (*writer)(wchar_t), int count)
|
||||||
|
|
||||||
For a full description on the usage of *printf, see use 'man 3 printf'.
|
For a full description on the usage of *printf, see use 'man 3 printf'.
|
||||||
*/
|
*/
|
||||||
static int vgwprintf( void (*writer)(wchar_t),
|
static int vgwprintf( void (*writer)(wchar_t),
|
||||||
const wchar_t *filter,
|
const wchar_t *filter,
|
||||||
va_list va )
|
va_list va )
|
||||||
{
|
{
|
||||||
const wchar_t *filter_org=filter;
|
const wchar_t *filter_org=filter;
|
||||||
int count=0;
|
int count=0;
|
||||||
|
|
||||||
for( ;*filter; filter++)
|
for( ;*filter; filter++)
|
||||||
{
|
{
|
||||||
if(*filter == L'%')
|
if(*filter == L'%')
|
||||||
|
@ -188,19 +188,19 @@ static int vgwprintf( void (*writer)(wchar_t),
|
||||||
int loop=1;
|
int loop=1;
|
||||||
int precision=-1;
|
int precision=-1;
|
||||||
int pad_left = 1;
|
int pad_left = 1;
|
||||||
|
|
||||||
if( iswdigit( *filter ) )
|
if( iswdigit( *filter ) )
|
||||||
{
|
{
|
||||||
width=0;
|
width=0;
|
||||||
while( (*filter >= L'0') && (*filter <= L'9'))
|
while( (*filter >= L'0') && (*filter <= L'9'))
|
||||||
{
|
{
|
||||||
width=10*width+(*filter++ - L'0');
|
width=10*width+(*filter++ - L'0');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while( loop )
|
while( loop )
|
||||||
{
|
{
|
||||||
|
|
||||||
switch(*filter)
|
switch(*filter)
|
||||||
{
|
{
|
||||||
case L'l':
|
case L'l':
|
||||||
|
@ -219,9 +219,9 @@ static int vgwprintf( void (*writer)(wchar_t),
|
||||||
filter++;
|
filter++;
|
||||||
pad_left=0;
|
pad_left=0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case L'.':
|
case L'.':
|
||||||
/*
|
/*
|
||||||
Set precision.
|
Set precision.
|
||||||
*/
|
*/
|
||||||
filter++;
|
filter++;
|
||||||
|
@ -235,10 +235,10 @@ static int vgwprintf( void (*writer)(wchar_t),
|
||||||
while( (*filter >= L'0') && (*filter <= L'9'))
|
while( (*filter >= L'0') && (*filter <= L'9'))
|
||||||
{
|
{
|
||||||
precision=10*precision+(*filter++ - L'0');
|
precision=10*precision+(*filter++ - L'0');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
loop=0;
|
loop=0;
|
||||||
break;
|
break;
|
||||||
|
@ -253,8 +253,8 @@ static int vgwprintf( void (*writer)(wchar_t),
|
||||||
|
|
||||||
if( (width >= 0) && pad_left )
|
if( (width >= 0) && pad_left )
|
||||||
{
|
{
|
||||||
pad( writer, width-1 );
|
pad( writer, width-1 );
|
||||||
count += maxi( width-1, 0 );
|
count += maxi( width-1, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
c = is_long?va_arg(va, wint_t):btowc(va_arg(va, int));
|
c = is_long?va_arg(va, wint_t):btowc(va_arg(va, int));
|
||||||
|
@ -265,16 +265,16 @@ static int vgwprintf( void (*writer)(wchar_t),
|
||||||
if( (width >= 0) && !pad_left )
|
if( (width >= 0) && !pad_left )
|
||||||
{
|
{
|
||||||
pad( writer, width-1 );
|
pad( writer, width-1 );
|
||||||
count += maxi( width-1, 0 );
|
count += maxi( width-1, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case L's':
|
case L's':
|
||||||
{
|
{
|
||||||
|
|
||||||
wchar_t *ss=0;
|
wchar_t *ss=0;
|
||||||
if( is_long )
|
if( is_long )
|
||||||
{
|
{
|
||||||
|
@ -287,41 +287,41 @@ static int vgwprintf( void (*writer)(wchar_t),
|
||||||
if( ns )
|
if( ns )
|
||||||
{
|
{
|
||||||
ss = str2wcs( ns );
|
ss = str2wcs( ns );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !ss )
|
if( !ss )
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (width >= 0) && pad_left )
|
if( (width >= 0) && pad_left )
|
||||||
{
|
{
|
||||||
pad( writer, width-wcslen(ss) );
|
pad( writer, width-wcslen(ss) );
|
||||||
count += maxi(width-wcslen(ss), 0);
|
count += maxi(width-wcslen(ss), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t *s=ss;
|
wchar_t *s=ss;
|
||||||
int precount = count;
|
int precount = count;
|
||||||
|
|
||||||
while( *s )
|
while( *s )
|
||||||
{
|
{
|
||||||
if( (precision > 0) && (precision <= (count-precount) ) )
|
if( (precision > 0) && (precision <= (count-precount) ) )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
writer( *(s++) );
|
writer( *(s++) );
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (width >= 0) && !pad_left )
|
if( (width >= 0) && !pad_left )
|
||||||
{
|
{
|
||||||
pad( writer, width-wcslen(ss) );
|
pad( writer, width-wcslen(ss) );
|
||||||
count += maxi( width-wcslen(ss), 0 );
|
count += maxi( width-wcslen(ss), 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !is_long )
|
if( !is_long )
|
||||||
free( ss );
|
free( ss );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,7 +336,7 @@ static int vgwprintf( void (*writer)(wchar_t),
|
||||||
char *pos;
|
char *pos;
|
||||||
char format[16];
|
char format[16];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
format[0]=0;
|
format[0]=0;
|
||||||
strcat( format, "%");
|
strcat( format, "%");
|
||||||
if( precision >= 0 )
|
if( precision >= 0 )
|
||||||
|
@ -350,7 +350,7 @@ static int vgwprintf( void (*writer)(wchar_t),
|
||||||
strcat( format, "l" );
|
strcat( format, "l" );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = strlen(format);
|
len = strlen(format);
|
||||||
format[len++]=(char)*filter;
|
format[len++]=(char)*filter;
|
||||||
format[len]=0;
|
format[len]=0;
|
||||||
|
@ -360,7 +360,7 @@ static int vgwprintf( void (*writer)(wchar_t),
|
||||||
case L'd':
|
case L'd':
|
||||||
case L'i':
|
case L'i':
|
||||||
{
|
{
|
||||||
|
|
||||||
switch( is_long )
|
switch( is_long )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -370,10 +370,10 @@ static int vgwprintf( void (*writer)(wchar_t),
|
||||||
snprintf( str, 32, format, precision, d );
|
snprintf( str, 32, format, precision, d );
|
||||||
else
|
else
|
||||||
snprintf( str, 32, format, d );
|
snprintf( str, 32, format, d );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
long d = va_arg( va, long );
|
long d = va_arg( va, long );
|
||||||
|
@ -383,7 +383,7 @@ static int vgwprintf( void (*writer)(wchar_t),
|
||||||
snprintf( str, 32, format, d );
|
snprintf( str, 32, format, d );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
long long d = va_arg( va, long long );
|
long long d = va_arg( va, long long );
|
||||||
|
@ -393,21 +393,21 @@ static int vgwprintf( void (*writer)(wchar_t),
|
||||||
snprintf( str, 32, format, d );
|
snprintf( str, 32, format, d );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
debug( 0, L"Invalid length modifier in string %ls\n", filter_org );
|
debug( 0, L"Invalid length modifier in string %ls\n", filter_org );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case L'u':
|
case L'u':
|
||||||
case L'o':
|
case L'o':
|
||||||
case L'x':
|
case L'x':
|
||||||
case L'X':
|
case L'X':
|
||||||
{
|
{
|
||||||
|
|
||||||
switch( is_long )
|
switch( is_long )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -419,7 +419,7 @@ static int vgwprintf( void (*writer)(wchar_t),
|
||||||
snprintf( str, 32, format, d );
|
snprintf( str, 32, format, d );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
unsigned long d = va_arg( va, unsigned long );
|
unsigned long d = va_arg( va, unsigned long );
|
||||||
|
@ -429,7 +429,7 @@ static int vgwprintf( void (*writer)(wchar_t),
|
||||||
snprintf( str, 32, format, d );
|
snprintf( str, 32, format, d );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
unsigned long long d = va_arg( va, unsigned long long );
|
unsigned long long d = va_arg( va, unsigned long long );
|
||||||
|
@ -439,43 +439,43 @@ static int vgwprintf( void (*writer)(wchar_t),
|
||||||
snprintf( str, 32, format, d );
|
snprintf( str, 32, format, d );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
debug( 0, L"Invalid length modifier in string %ls\n", filter_org );
|
debug( 0, L"Invalid length modifier in string %ls\n", filter_org );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
debug( 0, L"Invalid filter %ls in string %ls\n", *filter, filter_org );
|
debug( 0, L"Invalid filter %ls in string %ls\n", *filter, filter_org );
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (width >= 0) && pad_left )
|
if( (width >= 0) && pad_left )
|
||||||
{
|
{
|
||||||
int l = maxi(width-strlen(str), 0 );
|
int l = maxi(width-strlen(str), 0 );
|
||||||
pad( writer, l );
|
pad( writer, l );
|
||||||
count += l;
|
count += l;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = str;
|
pos = str;
|
||||||
|
|
||||||
while( *pos )
|
while( *pos )
|
||||||
{
|
{
|
||||||
writer( *(pos++) );
|
writer( *(pos++) );
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (width >= 0) && !pad_left )
|
if( (width >= 0) && !pad_left )
|
||||||
{
|
{
|
||||||
int l = maxi(width-strlen(str), 0 );
|
int l = maxi(width-strlen(str), 0 );
|
||||||
pad( writer, l );
|
pad( writer, l );
|
||||||
count += l;
|
count += l;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,7 +484,7 @@ static int vgwprintf( void (*writer)(wchar_t),
|
||||||
char str[32];
|
char str[32];
|
||||||
char *pos;
|
char *pos;
|
||||||
double val = va_arg( va, double );
|
double val = va_arg( va, double );
|
||||||
|
|
||||||
if( precision>= 0 )
|
if( precision>= 0 )
|
||||||
{
|
{
|
||||||
if( width>= 0 )
|
if( width>= 0 )
|
||||||
|
@ -509,21 +509,21 @@ static int vgwprintf( void (*writer)(wchar_t),
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = str;
|
pos = str;
|
||||||
|
|
||||||
while( *pos )
|
while( *pos )
|
||||||
{
|
{
|
||||||
writer( *(pos++) );
|
writer( *(pos++) );
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case L'n':
|
case L'n':
|
||||||
{
|
{
|
||||||
int *n = va_arg( va, int *);
|
int *n = va_arg( va, int *);
|
||||||
|
|
||||||
*n = count;
|
*n = count;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case L'%':
|
case L'%':
|
||||||
|
@ -564,14 +564,14 @@ sw_data;
|
||||||
static void sw_writer( wchar_t c )
|
static void sw_writer( wchar_t c )
|
||||||
{
|
{
|
||||||
if( sw_data.count < sw_data.max )
|
if( sw_data.count < sw_data.max )
|
||||||
*(sw_data.pos++)=c;
|
*(sw_data.pos++)=c;
|
||||||
sw_data.count++;
|
sw_data.count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vswprintf( wchar_t *out, size_t n, const wchar_t *filter, va_list va )
|
int vswprintf( wchar_t *out, size_t n, const wchar_t *filter, va_list va )
|
||||||
{
|
{
|
||||||
int written;
|
int written;
|
||||||
|
|
||||||
sw_data.pos=out;
|
sw_data.pos=out;
|
||||||
sw_data.max=n;
|
sw_data.max=n;
|
||||||
sw_data.count=0;
|
sw_data.count=0;
|
||||||
|
@ -586,7 +586,7 @@ int vswprintf( wchar_t *out, size_t n, const wchar_t *filter, va_list va )
|
||||||
{
|
{
|
||||||
written=-1;
|
written=-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return written;
|
return written;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -594,7 +594,7 @@ int swprintf( wchar_t *out, size_t n, const wchar_t *filter, ... )
|
||||||
{
|
{
|
||||||
va_list va;
|
va_list va;
|
||||||
int written;
|
int written;
|
||||||
|
|
||||||
va_start( va, filter );
|
va_start( va, filter );
|
||||||
written = vswprintf( out, n, filter, va );
|
written = vswprintf( out, n, filter, va );
|
||||||
va_end( va );
|
va_end( va );
|
||||||
|
@ -624,7 +624,7 @@ int fwprintf( FILE *f, const wchar_t *filter, ... )
|
||||||
{
|
{
|
||||||
va_list va;
|
va_list va;
|
||||||
int written;
|
int written;
|
||||||
|
|
||||||
va_start( va, filter );
|
va_start( va, filter );
|
||||||
written = vfwprintf( f, filter, va );
|
written = vfwprintf( f, filter, va );
|
||||||
va_end( va );
|
va_end( va );
|
||||||
|
@ -640,7 +640,7 @@ int wprintf( const wchar_t *filter, ... )
|
||||||
{
|
{
|
||||||
va_list va;
|
va_list va;
|
||||||
int written;
|
int written;
|
||||||
|
|
||||||
va_start( va, filter );
|
va_start( va, filter );
|
||||||
written=vwprintf( filter, va );
|
written=vwprintf( filter, va );
|
||||||
va_end( va );
|
va_end( va );
|
||||||
|
@ -661,16 +661,16 @@ wint_t fgetwc(FILE *stream)
|
||||||
{
|
{
|
||||||
int b = fgetc( stream );
|
int b = fgetc( stream );
|
||||||
char bb;
|
char bb;
|
||||||
|
|
||||||
int sz;
|
int sz;
|
||||||
|
|
||||||
if( b == EOF )
|
if( b == EOF )
|
||||||
return WEOF;
|
return WEOF;
|
||||||
|
|
||||||
bb=b;
|
bb=b;
|
||||||
|
|
||||||
sz = mbrtowc( &res, &bb, 1, &state );
|
sz = mbrtowc( &res, &bb, 1, &state );
|
||||||
|
|
||||||
switch( sz )
|
switch( sz )
|
||||||
{
|
{
|
||||||
case -1:
|
case -1:
|
||||||
|
@ -733,13 +733,13 @@ static size_t fish_wcsspn (const wchar_t *wcs,
|
||||||
for (a = accept; *a != L'\0'; ++a)
|
for (a = accept; *a != L'\0'; ++a)
|
||||||
if (*p == *a)
|
if (*p == *a)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (*a == L'\0')
|
if (*a == L'\0')
|
||||||
return count;
|
return count;
|
||||||
else
|
else
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -752,7 +752,7 @@ static wchar_t *fish_wcspbrk (const wchar_t *wcs, const wchar_t *accept)
|
||||||
++wcs;
|
++wcs;
|
||||||
else
|
else
|
||||||
return (wchar_t *) wcs;
|
return (wchar_t *) wcs;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -775,18 +775,18 @@ wchar_t *wcstok(wchar_t *wcs, const wchar_t *delim, wchar_t **save_ptr)
|
||||||
|
|
||||||
/* Scan leading delimiters. */
|
/* Scan leading delimiters. */
|
||||||
wcs += fish_wcsspn (wcs, delim);
|
wcs += fish_wcsspn (wcs, delim);
|
||||||
|
|
||||||
if (*wcs == L'\0')
|
if (*wcs == L'\0')
|
||||||
{
|
{
|
||||||
*save_ptr = NULL;
|
*save_ptr = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find the end of the token. */
|
/* Find the end of the token. */
|
||||||
result = wcs;
|
result = wcs;
|
||||||
|
|
||||||
wcs = fish_wcspbrk (result, delim);
|
wcs = fish_wcspbrk (result, delim);
|
||||||
|
|
||||||
if (wcs == NULL)
|
if (wcs == NULL)
|
||||||
{
|
{
|
||||||
/* This token finishes the string. */
|
/* This token finishes the string. */
|
||||||
|
@ -815,7 +815,7 @@ wchar_t *wcsdup( const wchar_t *in )
|
||||||
|
|
||||||
memcpy( out, in, sizeof( wchar_t)*(len+1));
|
memcpy( out, in, sizeof( wchar_t)*(len+1));
|
||||||
return out;
|
return out;
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -855,7 +855,7 @@ int wcsncasecmp( const wchar_t *a, const wchar_t *b, int count )
|
||||||
{
|
{
|
||||||
if( count == 0 )
|
if( count == 0 )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if( *a == 0 )
|
if( *a == 0 )
|
||||||
{
|
{
|
||||||
return (*b==0)?0:-1;
|
return (*b==0)?0:-1;
|
||||||
|
@ -892,7 +892,7 @@ wchar_t *wcsndup( const wchar_t *in, int c )
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
wcslcpy( res, in, c+1 );
|
wcslcpy( res, in, c+1 );
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -905,22 +905,22 @@ long convert_digit( wchar_t d, int base )
|
||||||
}
|
}
|
||||||
else if( (d <= L'z') && (d >= L'a') )
|
else if( (d <= L'z') && (d >= L'a') )
|
||||||
{
|
{
|
||||||
res = d + 10 - L'a';
|
res = d + 10 - L'a';
|
||||||
}
|
}
|
||||||
else if( (d <= L'Z') && (d >= L'A') )
|
else if( (d <= L'Z') && (d >= L'A') )
|
||||||
{
|
{
|
||||||
res = d + 10 - L'A';
|
res = d + 10 - L'A';
|
||||||
}
|
}
|
||||||
if( res >= base )
|
if( res >= base )
|
||||||
{
|
{
|
||||||
res = -1;
|
res = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef HAVE_WCSTOL
|
#ifndef HAVE_WCSTOL
|
||||||
long wcstol(const wchar_t *nptr,
|
long wcstol(const wchar_t *nptr,
|
||||||
wchar_t **endptr,
|
wchar_t **endptr,
|
||||||
int base)
|
int base)
|
||||||
{
|
{
|
||||||
|
@ -943,7 +943,7 @@ long wcstol(const wchar_t *nptr,
|
||||||
{
|
{
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
res = (res*base)+nxt;
|
res = (res*base)+nxt;
|
||||||
is_set = 1;
|
is_set = 1;
|
||||||
|
@ -985,25 +985,25 @@ long wcstol(const wchar_t *nptr,
|
||||||
size_t
|
size_t
|
||||||
wcslcat(wchar_t *dst, const wchar_t *src, size_t siz)
|
wcslcat(wchar_t *dst, const wchar_t *src, size_t siz)
|
||||||
{
|
{
|
||||||
|
|
||||||
register wchar_t *d = dst;
|
register wchar_t *d = dst;
|
||||||
register const wchar_t *s = src;
|
register const wchar_t *s = src;
|
||||||
register size_t n = siz;
|
register size_t n = siz;
|
||||||
size_t dlen;
|
size_t dlen;
|
||||||
|
|
||||||
/* Find the end of dst and adjust bytes left but don't go past end */
|
/* Find the end of dst and adjust bytes left but don't go past end */
|
||||||
while (n-- != 0 && *d != '\0')
|
while (n-- != 0 && *d != '\0')
|
||||||
d++;
|
d++;
|
||||||
|
|
||||||
dlen = d - dst;
|
dlen = d - dst;
|
||||||
n = siz - dlen;
|
n = siz - dlen;
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return(dlen + wcslen(s));
|
return(dlen + wcslen(s));
|
||||||
|
|
||||||
while (*s != '\0')
|
while (*s != '\0')
|
||||||
{
|
{
|
||||||
if (n != 1)
|
if (n != 1)
|
||||||
{
|
{
|
||||||
*d++ = *s;
|
*d++ = *s;
|
||||||
n--;
|
n--;
|
||||||
|
@ -1043,12 +1043,12 @@ wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz)
|
||||||
register wchar_t *d = dst;
|
register wchar_t *d = dst;
|
||||||
register const wchar_t *s = src;
|
register const wchar_t *s = src;
|
||||||
register size_t n = siz;
|
register size_t n = siz;
|
||||||
|
|
||||||
/* Copy as many bytes as will fit */
|
/* Copy as many bytes as will fit */
|
||||||
if (n != 0 && --n != 0)
|
if (n != 0 && --n != 0)
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if ((*d++ = *s++) == 0)
|
if ((*d++ = *s++) == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1056,8 +1056,8 @@ wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Not enough room in dst, add NUL and traverse rest of src */
|
/* Not enough room in dst, add NUL and traverse rest of src */
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
{
|
{
|
||||||
if (siz != 0)
|
if (siz != 0)
|
||||||
*d = '\0';
|
*d = '\0';
|
||||||
/* NUL-terminate dst */
|
/* NUL-terminate dst */
|
||||||
|
@ -1074,7 +1074,7 @@ wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz)
|
||||||
|
|
||||||
int lrand48_r(struct drand48_data *buffer, long int *result)
|
int lrand48_r(struct drand48_data *buffer, long int *result)
|
||||||
{
|
{
|
||||||
*result = rand_r( &buffer->seed );
|
*result = rand_r( &buffer->seed );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1143,10 +1143,10 @@ int killpg( int pgr, int sig )
|
||||||
|
|
||||||
#ifndef HAVE_WORKING_GETOPT_LONG
|
#ifndef HAVE_WORKING_GETOPT_LONG
|
||||||
|
|
||||||
int getopt_long( int argc,
|
int getopt_long( int argc,
|
||||||
char * const argv[],
|
char * const argv[],
|
||||||
const char *optstring,
|
const char *optstring,
|
||||||
const struct option *longopts,
|
const struct option *longopts,
|
||||||
int *longindex )
|
int *longindex )
|
||||||
{
|
{
|
||||||
return getopt( argc, argv, optstring );
|
return getopt( argc, argv, optstring );
|
||||||
|
@ -1181,7 +1181,7 @@ long sysconf(int name)
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
18
fallback.h
18
fallback.h
|
@ -57,12 +57,12 @@ typedef char tputs_arg_t;
|
||||||
/**
|
/**
|
||||||
Structure used to get the size of a terminal window
|
Structure used to get the size of a terminal window
|
||||||
*/
|
*/
|
||||||
struct winsize
|
struct winsize
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
Number of rows
|
Number of rows
|
||||||
*/
|
*/
|
||||||
unsigned short ws_row;
|
unsigned short ws_row;
|
||||||
/**
|
/**
|
||||||
Number of columns
|
Number of columns
|
||||||
*/
|
*/
|
||||||
|
@ -193,7 +193,7 @@ wchar_t *wcstok(wchar_t *wcs, const wchar_t *delim, wchar_t **ptr);
|
||||||
/**
|
/**
|
||||||
Return the number of columns used by a character. This is a libc
|
Return the number of columns used by a character. This is a libc
|
||||||
function, but the prototype for this function is missing in some libc
|
function, but the prototype for this function is missing in some libc
|
||||||
implementations.
|
implementations.
|
||||||
|
|
||||||
Fish has a fallback implementation in case the implementation is
|
Fish has a fallback implementation in case the implementation is
|
||||||
missing altogether. In locales without a native wcwidth, Unicode
|
missing altogether. In locales without a native wcwidth, Unicode
|
||||||
|
@ -320,7 +320,7 @@ size_t wcslcat( wchar_t *dst, const wchar_t *src, size_t siz );
|
||||||
wcslen(src); if retval >= siz, truncation occurred.
|
wcslen(src); if retval >= siz, truncation occurred.
|
||||||
|
|
||||||
This is the OpenBSD strlcpy function, modified for wide characters,
|
This is the OpenBSD strlcpy function, modified for wide characters,
|
||||||
and renamed to reflect this change.
|
and renamed to reflect this change.
|
||||||
*/
|
*/
|
||||||
size_t wcslcpy( wchar_t *dst, const wchar_t *src, size_t siz );
|
size_t wcslcpy( wchar_t *dst, const wchar_t *src, size_t siz );
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ char * textdomain( const char * domainname );
|
||||||
/**
|
/**
|
||||||
Fallback implementation of dcgettext. Just returns the original string.
|
Fallback implementation of dcgettext. Just returns the original string.
|
||||||
*/
|
*/
|
||||||
char * dcgettext ( const char * domainname,
|
char * dcgettext ( const char * domainname,
|
||||||
const char * msgid,
|
const char * msgid,
|
||||||
int category );
|
int category );
|
||||||
|
|
||||||
|
@ -421,7 +421,7 @@ int killpg( int pgr, int sig );
|
||||||
/**
|
/**
|
||||||
Struct describing a long getopt option
|
Struct describing a long getopt option
|
||||||
*/
|
*/
|
||||||
struct option
|
struct option
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
Name of option
|
Name of option
|
||||||
|
@ -438,7 +438,7 @@ struct option
|
||||||
/**
|
/**
|
||||||
Return value
|
Return value
|
||||||
*/
|
*/
|
||||||
int val;
|
int val;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -454,10 +454,10 @@ struct option
|
||||||
#define optional_argument 2
|
#define optional_argument 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int getopt_long(int argc,
|
int getopt_long(int argc,
|
||||||
char * const argv[],
|
char * const argv[],
|
||||||
const char *optstring,
|
const char *optstring,
|
||||||
const struct option *longopts,
|
const struct option *longopts,
|
||||||
int *longindex);
|
int *longindex);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
136
fish.c
136
fish.c
|
@ -80,7 +80,7 @@ static int read_init()
|
||||||
|
|
||||||
eval( L"builtin . " DATADIR "/fish/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 );
|
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
|
We need to get the configuration directory before we can source the user configuration file
|
||||||
*/
|
*/
|
||||||
|
@ -99,9 +99,9 @@ static int read_init()
|
||||||
eval( (wchar_t *)eval_buff->buff, 0, TOP );
|
eval( (wchar_t *)eval_buff->buff, 0, TOP );
|
||||||
free( config_dir_escaped );
|
free( config_dir_escaped );
|
||||||
}
|
}
|
||||||
|
|
||||||
halloc_free( context );
|
halloc_free( context );
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,83 +114,83 @@ static int fish_parse_opt( int argc, char **argv, char **cmd_ptr )
|
||||||
{
|
{
|
||||||
int my_optind;
|
int my_optind;
|
||||||
int force_interactive=0;
|
int force_interactive=0;
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
static struct option
|
static struct option
|
||||||
long_options[] =
|
long_options[] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
"command", required_argument, 0, 'c'
|
"command", required_argument, 0, 'c'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"debug-level", required_argument, 0, 'd'
|
"debug-level", required_argument, 0, 'd'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"interactive", no_argument, 0, 'i'
|
"interactive", no_argument, 0, 'i'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"login", no_argument, 0, 'l'
|
"login", no_argument, 0, 'l'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"no-execute", no_argument, 0, 'n'
|
"no-execute", no_argument, 0, 'n'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"profile", required_argument, 0, 'p'
|
"profile", required_argument, 0, 'p'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"help", no_argument, 0, 'h'
|
"help", no_argument, 0, 'h'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"version", no_argument, 0, 'v'
|
"version", no_argument, 0, 'v'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
0, 0, 0, 0
|
0, 0, 0, 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
int opt_index = 0;
|
int opt_index = 0;
|
||||||
|
|
||||||
int opt = getopt_long( argc,
|
int opt = getopt_long( argc,
|
||||||
argv,
|
argv,
|
||||||
GETOPT_STRING,
|
GETOPT_STRING,
|
||||||
long_options,
|
long_options,
|
||||||
&opt_index );
|
&opt_index );
|
||||||
|
|
||||||
if( opt == -1 )
|
if( opt == -1 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch( opt )
|
switch( opt )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
{
|
{
|
||||||
*cmd_ptr = optarg;
|
*cmd_ptr = optarg;
|
||||||
is_interactive_session = 0;
|
is_interactive_session = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
{
|
{
|
||||||
char *end;
|
char *end;
|
||||||
int tmp;
|
int tmp;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
tmp = strtol(optarg, &end, 10);
|
tmp = strtol(optarg, &end, 10);
|
||||||
|
|
||||||
if( tmp >= 0 && tmp <=10 && !*end && !errno )
|
if( tmp >= 0 && tmp <=10 && !*end && !errno )
|
||||||
{
|
{
|
||||||
debug_level=tmp;
|
debug_level=tmp;
|
||||||
|
@ -202,65 +202,65 @@ static int fish_parse_opt( int argc, char **argv, char **cmd_ptr )
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
{
|
{
|
||||||
*cmd_ptr = "__fish_print_help fish";
|
*cmd_ptr = "__fish_print_help fish";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
{
|
{
|
||||||
force_interactive = 1;
|
force_interactive = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'l':
|
case 'l':
|
||||||
{
|
{
|
||||||
is_login=1;
|
is_login=1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'n':
|
case 'n':
|
||||||
{
|
{
|
||||||
no_exec=1;
|
no_exec=1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
{
|
{
|
||||||
profile = optarg;
|
profile = optarg;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
{
|
{
|
||||||
fwprintf( stderr,
|
fwprintf( stderr,
|
||||||
_(L"%s, version %s\n"),
|
_(L"%s, version %s\n"),
|
||||||
PACKAGE_NAME,
|
PACKAGE_NAME,
|
||||||
PACKAGE_VERSION );
|
PACKAGE_VERSION );
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
{
|
{
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my_optind = optind;
|
my_optind = optind;
|
||||||
|
|
||||||
is_login |= (strcmp( argv[0], "-fish") == 0);
|
is_login |= (strcmp( argv[0], "-fish") == 0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
We are an interactive session if we have not been given an
|
We are an interactive session if we have not been given an
|
||||||
explicit command to execute, _and_ stdin is a tty.
|
explicit command to execute, _and_ stdin is a tty.
|
||||||
*/
|
*/
|
||||||
is_interactive_session &= (*cmd_ptr == 0);
|
is_interactive_session &= (*cmd_ptr == 0);
|
||||||
is_interactive_session &= (my_optind == argc);
|
is_interactive_session &= (my_optind == argc);
|
||||||
is_interactive_session &= isatty(STDIN_FILENO);
|
is_interactive_session &= isatty(STDIN_FILENO);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
We are also an interactive session if we have are forced-
|
We are also an interactive session if we have are forced-
|
||||||
|
@ -282,7 +282,7 @@ int main( int argc, char **argv )
|
||||||
char *cmd=0;
|
char *cmd=0;
|
||||||
int my_optind=0;
|
int my_optind=0;
|
||||||
|
|
||||||
halloc_util_init();
|
halloc_util_init();
|
||||||
|
|
||||||
wsetlocale( LC_ALL, L"" );
|
wsetlocale( LC_ALL, L"" );
|
||||||
is_interactive_session=1;
|
is_interactive_session=1;
|
||||||
|
@ -299,9 +299,9 @@ int main( int argc, char **argv )
|
||||||
debug( 1, _(L"Can not use the no-execute mode when running an interactive session") );
|
debug( 1, _(L"Can not use the no-execute mode when running an interactive session") );
|
||||||
no_exec = 0;
|
no_exec = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
proc_init();
|
proc_init();
|
||||||
event_init();
|
event_init();
|
||||||
wutil_init();
|
wutil_init();
|
||||||
parser_init();
|
parser_init();
|
||||||
builtin_init();
|
builtin_init();
|
||||||
|
@ -323,28 +323,28 @@ int main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
if( my_optind == argc )
|
if( my_optind == argc )
|
||||||
{
|
{
|
||||||
res = reader_read( 0, 0 );
|
res = reader_read( STDIN_FILENO, 0 );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char **ptr;
|
char **ptr;
|
||||||
char *file = *(argv+1);
|
char *file = *(argv+(my_optind++));
|
||||||
int i;
|
int i;
|
||||||
string_buffer_t sb;
|
string_buffer_t sb;
|
||||||
int fd;
|
int fd;
|
||||||
wchar_t *rel_filename, *abs_filename;
|
wchar_t *rel_filename, *abs_filename;
|
||||||
|
|
||||||
if( ( fd = open(file, O_RDONLY) ) == -1 )
|
if( ( fd = open(file, O_RDONLY) ) == -1 )
|
||||||
{
|
{
|
||||||
wperror( L"open" );
|
wperror( L"open" );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( *(argv+2))
|
if( *(argv+my_optind))
|
||||||
{
|
{
|
||||||
sb_init( &sb );
|
sb_init( &sb );
|
||||||
|
|
||||||
for( i=1,ptr = argv+2; *ptr; i++, ptr++ )
|
for( i=1,ptr = argv+my_optind; *ptr; i++, ptr++ )
|
||||||
{
|
{
|
||||||
if( i != 1 )
|
if( i != 1 )
|
||||||
sb_append( &sb, ARRAY_SEP_STR );
|
sb_append( &sb, ARRAY_SEP_STR );
|
||||||
|
@ -352,7 +352,7 @@ int main( int argc, char **argv )
|
||||||
sb_append( &sb, val );
|
sb_append( &sb, val );
|
||||||
free( val );
|
free( val );
|
||||||
}
|
}
|
||||||
|
|
||||||
env_set( L"argv", (wchar_t *)sb.buff, 0 );
|
env_set( L"argv", (wchar_t *)sb.buff, 0 );
|
||||||
sb_destroy( &sb );
|
sb_destroy( &sb );
|
||||||
}
|
}
|
||||||
|
@ -373,17 +373,17 @@ int main( int argc, char **argv )
|
||||||
|
|
||||||
if( res )
|
if( res )
|
||||||
{
|
{
|
||||||
debug( 1,
|
debug( 1,
|
||||||
_(L"Error while reading file %ls\n"),
|
_(L"Error while reading file %ls\n"),
|
||||||
reader_current_filename()?reader_current_filename(): _(L"Standard input") );
|
reader_current_filename()?reader_current_filename(): _(L"Standard input") );
|
||||||
}
|
}
|
||||||
reader_pop_current_filename();
|
reader_pop_current_filename();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
proc_fire_event( L"PROCESS_EXIT", EVENT_EXIT, getpid(), res );
|
proc_fire_event( L"PROCESS_EXIT", EVENT_EXIT, getpid(), res );
|
||||||
|
|
||||||
history_destroy();
|
history_destroy();
|
||||||
proc_destroy();
|
proc_destroy();
|
||||||
builtin_destroy();
|
builtin_destroy();
|
||||||
|
@ -392,12 +392,12 @@ int main( int argc, char **argv )
|
||||||
parser_destroy();
|
parser_destroy();
|
||||||
wutil_destroy();
|
wutil_destroy();
|
||||||
event_destroy();
|
event_destroy();
|
||||||
|
|
||||||
halloc_util_destroy();
|
halloc_util_destroy();
|
||||||
|
|
||||||
env_destroy();
|
env_destroy();
|
||||||
|
|
||||||
intern_free_all();
|
intern_free_all();
|
||||||
|
|
||||||
return res?STATUS_UNKNOWN_COMMAND:proc_get_last_status();
|
return res?STATUS_UNKNOWN_COMMAND:proc_get_last_status();
|
||||||
}
|
}
|
||||||
|
|
10
fish.spec.in
10
fish.spec.in
|
@ -11,7 +11,7 @@ URL: http://www.fishshell.org
|
||||||
Source0: http://www.fishshell.org/files/%{version}/%{name}-%{version}.tar.bz2
|
Source0: http://www.fishshell.org/files/%{version}/%{name}-%{version}.tar.bz2
|
||||||
|
|
||||||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
||||||
BuildRequires: ncurses-devel gettext groff
|
BuildRequires: ncurses-devel gettext groff
|
||||||
|
|
||||||
|
|
||||||
# Locate correct build time-dependencies for providing X headers
|
# Locate correct build time-dependencies for providing X headers
|
||||||
|
@ -50,10 +50,10 @@ BuildRequires: %{xinclude}/X11/Intrinsic.h, %{xinclude}/X11/Xatom.h
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
|
|
||||||
%description
|
%description
|
||||||
|
|
||||||
fish is a shell geared towards interactive use. Its features are
|
fish is a shell geared towards interactive use. Its features are
|
||||||
focused on user friendliness and discoverability. The language syntax
|
focused on user friendliness and discoverability. The language syntax
|
||||||
is simple but incompatible with other shell languages.
|
is simple but incompatible with other shell languages.
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ make %{?_smp_mflags}
|
||||||
|
|
||||||
%install
|
%install
|
||||||
rm -rf $RPM_BUILD_ROOT
|
rm -rf $RPM_BUILD_ROOT
|
||||||
make install DESTDIR="$RPM_BUILD_ROOT"
|
make install DESTDIR="$RPM_BUILD_ROOT"
|
||||||
|
|
||||||
# Find translation files
|
# Find translation files
|
||||||
%find_lang %{name}.\*
|
%find_lang %{name}.\*
|
||||||
|
|
120
fish_indent.c
120
fish_indent.c
|
@ -64,10 +64,10 @@ static void read_file( FILE *f, string_buffer_t *b )
|
||||||
wperror(L"fgetwc");
|
wperror(L"fgetwc");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
sb_append_char( b, c );
|
sb_append_char( b, c );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,12 +78,12 @@ static void read_file( FILE *f, string_buffer_t *b )
|
||||||
static void insert_tabs( string_buffer_t *out, int indent )
|
static void insert_tabs( string_buffer_t *out, int indent )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for( i=0; i<indent; i++ )
|
for( i=0; i<indent; i++ )
|
||||||
{
|
{
|
||||||
sb_append( out, L"\t" );
|
sb_append( out, L"\t" );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,12 +100,12 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
|
||||||
int prev_prev_type = 0;
|
int prev_prev_type = 0;
|
||||||
|
|
||||||
tok_init( &tok, in, TOK_SHOW_COMMENTS );
|
tok_init( &tok, in, TOK_SHOW_COMMENTS );
|
||||||
|
|
||||||
for( ; tok_has_next( &tok ); tok_next( &tok ) )
|
for( ; tok_has_next( &tok ); tok_next( &tok ) )
|
||||||
{
|
{
|
||||||
int type = tok_last_type( &tok );
|
int type = tok_last_type( &tok );
|
||||||
wchar_t *last = tok_last( &tok );
|
wchar_t *last = tok_last( &tok );
|
||||||
|
|
||||||
switch( type )
|
switch( type )
|
||||||
{
|
{
|
||||||
case TOK_STRING:
|
case TOK_STRING:
|
||||||
|
@ -116,7 +116,7 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
|
||||||
is_command = 0;
|
is_command = 0;
|
||||||
|
|
||||||
wchar_t *unesc = unescape( last, UNESCAPE_SPECIAL );
|
wchar_t *unesc = unescape( last, UNESCAPE_SPECIAL );
|
||||||
|
|
||||||
if( parser_keywords_is_block( unesc ) )
|
if( parser_keywords_is_block( unesc ) )
|
||||||
{
|
{
|
||||||
next_indent++;
|
next_indent++;
|
||||||
|
@ -130,29 +130,29 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
|
||||||
indent--;
|
indent--;
|
||||||
next_indent--;
|
next_indent--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( do_indent && flags)
|
if( do_indent && flags)
|
||||||
{
|
{
|
||||||
insert_tabs( out, indent );
|
insert_tabs( out, indent );
|
||||||
}
|
}
|
||||||
|
|
||||||
sb_printf( out, L"%ls", last );
|
sb_printf( out, L"%ls", last );
|
||||||
|
|
||||||
indent = next_indent;
|
indent = next_indent;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sb_printf( out, L" %ls", last );
|
sb_printf( out, L" %ls", last );
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TOK_END:
|
case TOK_END:
|
||||||
{
|
{
|
||||||
if( prev_type != TOK_END || prev_prev_type != TOK_END )
|
if( prev_type != TOK_END || prev_prev_type != TOK_END )
|
||||||
sb_append( out, L"\n" );
|
sb_append( out, L"\n" );
|
||||||
do_indent = 1;
|
do_indent = 1;
|
||||||
is_command = 1;
|
is_command = 1;
|
||||||
|
@ -165,7 +165,7 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
|
||||||
is_command = 1;
|
is_command = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TOK_REDIRECT_OUT:
|
case TOK_REDIRECT_OUT:
|
||||||
case TOK_REDIRECT_APPEND:
|
case TOK_REDIRECT_APPEND:
|
||||||
case TOK_REDIRECT_IN:
|
case TOK_REDIRECT_IN:
|
||||||
|
@ -177,23 +177,23 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
|
||||||
case TOK_REDIRECT_OUT:
|
case TOK_REDIRECT_OUT:
|
||||||
sb_append( out, L"> " );
|
sb_append( out, L"> " );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_REDIRECT_APPEND:
|
case TOK_REDIRECT_APPEND:
|
||||||
sb_append( out, L">> " );
|
sb_append( out, L">> " );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_REDIRECT_IN:
|
case TOK_REDIRECT_IN:
|
||||||
sb_append( out, L"< " );
|
sb_append( out, L"< " );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_REDIRECT_FD:
|
case TOK_REDIRECT_FD:
|
||||||
sb_append( out, L">& " );
|
sb_append( out, L">& " );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case TOK_BACKGROUND:
|
case TOK_BACKGROUND:
|
||||||
{
|
{
|
||||||
|
@ -202,7 +202,7 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
|
||||||
is_command = 1;
|
is_command = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case TOK_COMMENT:
|
case TOK_COMMENT:
|
||||||
{
|
{
|
||||||
|
@ -210,24 +210,24 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
|
||||||
{
|
{
|
||||||
insert_tabs( out, indent );
|
insert_tabs( out, indent );
|
||||||
}
|
}
|
||||||
|
|
||||||
sb_printf( out, L"%ls", last );
|
sb_printf( out, L"%ls", last );
|
||||||
do_indent = 1;
|
do_indent = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
debug( 0, L"Unknown token '%ls'", last );
|
debug( 0, L"Unknown token '%ls'", last );
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prev_prev_type = prev_type;
|
prev_prev_type = prev_type;
|
||||||
prev_type = type;
|
prev_type = type;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tok_destroy( &tok );
|
tok_destroy( &tok );
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
@ -241,27 +241,27 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
|
||||||
static wchar_t *trim( wchar_t *in )
|
static wchar_t *trim( wchar_t *in )
|
||||||
{
|
{
|
||||||
wchar_t *end;
|
wchar_t *end;
|
||||||
|
|
||||||
while( *in == L'\n' )
|
while( *in == L'\n' )
|
||||||
{
|
{
|
||||||
in++;
|
in++;
|
||||||
}
|
}
|
||||||
|
|
||||||
end = in + wcslen(in);
|
end = in + wcslen(in);
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
if( end < in+2 )
|
if( end < in+2 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
end--;
|
end--;
|
||||||
|
|
||||||
if( (*end == L'\n' ) && ( *(end-1) == L'\n' ) )
|
if( (*end == L'\n' ) && ( *(end-1) == L'\n' ) )
|
||||||
*end=0;
|
*end=0;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,9 +273,9 @@ int main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
string_buffer_t sb_in;
|
string_buffer_t sb_in;
|
||||||
string_buffer_t sb_out;
|
string_buffer_t sb_out;
|
||||||
|
|
||||||
int do_indent=1;
|
int do_indent=1;
|
||||||
|
|
||||||
wsetlocale( LC_ALL, L"" );
|
wsetlocale( LC_ALL, L"" );
|
||||||
program_name=L"fish_indent";
|
program_name=L"fish_indent";
|
||||||
|
|
||||||
|
@ -285,55 +285,55 @@ int main( int argc, char **argv )
|
||||||
long_options[] =
|
long_options[] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
"no-indent", no_argument, 0, 'i'
|
"no-indent", no_argument, 0, 'i'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"help", no_argument, 0, 'h'
|
"help", no_argument, 0, 'h'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"version", no_argument, 0, 'v'
|
"version", no_argument, 0, 'v'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
0, 0, 0, 0
|
0, 0, 0, 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
int opt_index = 0;
|
int opt_index = 0;
|
||||||
|
|
||||||
int opt = getopt_long( argc,
|
int opt = getopt_long( argc,
|
||||||
argv,
|
argv,
|
||||||
GETOPT_STRING,
|
GETOPT_STRING,
|
||||||
long_options,
|
long_options,
|
||||||
&opt_index );
|
&opt_index );
|
||||||
|
|
||||||
if( opt == -1 )
|
if( opt == -1 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch( opt )
|
switch( opt )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
{
|
{
|
||||||
print_help( "fish_indent", 1 );
|
print_help( "fish_indent", 1 );
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
{
|
{
|
||||||
fwprintf( stderr,
|
fwprintf( stderr,
|
||||||
_(L"%ls, version %s\n"),
|
_(L"%ls, version %s\n"),
|
||||||
program_name,
|
program_name,
|
||||||
PACKAGE_VERSION );
|
PACKAGE_VERSION );
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
|
@ -341,23 +341,23 @@ int main( int argc, char **argv )
|
||||||
do_indent = 0;
|
do_indent = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
{
|
{
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
halloc_util_init();
|
halloc_util_init();
|
||||||
|
|
||||||
sb_init( &sb_in );
|
sb_init( &sb_in );
|
||||||
sb_init( &sb_out );
|
sb_init( &sb_out );
|
||||||
|
|
||||||
read_file( stdin, &sb_in );
|
read_file( stdin, &sb_in );
|
||||||
|
|
||||||
wutil_init();
|
wutil_init();
|
||||||
|
|
||||||
if( !indent( &sb_out, (wchar_t *)sb_in.buff, do_indent ) )
|
if( !indent( &sb_out, (wchar_t *)sb_in.buff, do_indent ) )
|
||||||
|
@ -371,7 +371,7 @@ int main( int argc, char **argv )
|
||||||
*/
|
*/
|
||||||
fwprintf( stdout, L"%ls", (wchar_t *)sb_in.buff );
|
fwprintf( stdout, L"%ls", (wchar_t *)sb_in.buff );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wutil_destroy();
|
wutil_destroy();
|
||||||
|
|
||||||
|
|
260
fish_pager.c
260
fish_pager.c
|
@ -61,7 +61,7 @@
|
||||||
#include "halloc_util.h"
|
#include "halloc_util.h"
|
||||||
#include "print_help.h"
|
#include "print_help.h"
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
LINE_UP = R_NULL+1,
|
LINE_UP = R_NULL+1,
|
||||||
LINE_DOWN,
|
LINE_DOWN,
|
||||||
|
@ -146,7 +146,7 @@ static buffer_t *pager_buffer;
|
||||||
The environment variables used to specify the color of different
|
The environment variables used to specify the color of different
|
||||||
tokens.
|
tokens.
|
||||||
*/
|
*/
|
||||||
static wchar_t *hightlight_var[] =
|
static wchar_t *hightlight_var[] =
|
||||||
{
|
{
|
||||||
L"fish_pager_color_prefix",
|
L"fish_pager_color_prefix",
|
||||||
L"fish_pager_color_completion",
|
L"fish_pager_color_completion",
|
||||||
|
@ -167,7 +167,7 @@ static FILE *out_file;
|
||||||
/**
|
/**
|
||||||
Data structure describing one or a group of related completions
|
Data structure describing one or a group of related completions
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
The list of all completin strings this entry applies to
|
The list of all completin strings this entry applies to
|
||||||
|
@ -180,11 +180,11 @@ typedef struct
|
||||||
/**
|
/**
|
||||||
On-screen width of the completion string
|
On-screen width of the completion string
|
||||||
*/
|
*/
|
||||||
int comp_width;
|
int comp_width;
|
||||||
/**
|
/**
|
||||||
On-screen width of the description information
|
On-screen width of the description information
|
||||||
*/
|
*/
|
||||||
int desc_width;
|
int desc_width;
|
||||||
/**
|
/**
|
||||||
Preffered total width
|
Preffered total width
|
||||||
*/
|
*/
|
||||||
|
@ -208,20 +208,20 @@ static int get_color( int highlight )
|
||||||
return FISH_COLOR_NORMAL;
|
return FISH_COLOR_NORMAL;
|
||||||
if( highlight >= (4) )
|
if( highlight >= (4) )
|
||||||
return FISH_COLOR_NORMAL;
|
return FISH_COLOR_NORMAL;
|
||||||
|
|
||||||
val = wgetenv( hightlight_var[highlight]);
|
val = wgetenv( hightlight_var[highlight]);
|
||||||
|
|
||||||
if( !val )
|
if( !val )
|
||||||
{
|
{
|
||||||
val = env_universal_get( hightlight_var[highlight]);
|
val = env_universal_get( hightlight_var[highlight]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !val )
|
if( !val )
|
||||||
{
|
{
|
||||||
return FISH_COLOR_NORMAL;
|
return FISH_COLOR_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return output_color_code( val );
|
return output_color_code( val );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -236,11 +236,11 @@ static void recalc_width( array_list_t *l, const wchar_t *prefix )
|
||||||
for( i=0; i<al_get_count( l ); i++ )
|
for( i=0; i<al_get_count( l ); i++ )
|
||||||
{
|
{
|
||||||
comp_t *c = (comp_t *)al_get( l, i );
|
comp_t *c = (comp_t *)al_get( l, i );
|
||||||
|
|
||||||
c->min_width = mini( c->desc_width, maxi(0,termsize.ws_col/3 - 2)) +
|
c->min_width = mini( c->desc_width, maxi(0,termsize.ws_col/3 - 2)) +
|
||||||
mini( c->desc_width, maxi(0,termsize.ws_col/5 - 4)) +4;
|
mini( c->desc_width, maxi(0,termsize.ws_col/5 - 4)) +4;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -251,14 +251,14 @@ static int try_sequence( char *seq )
|
||||||
{
|
{
|
||||||
int j, k;
|
int j, k;
|
||||||
wint_t c=0;
|
wint_t c=0;
|
||||||
|
|
||||||
for( j=0;
|
for( j=0;
|
||||||
seq[j] != '\0' && seq[j] == (c=input_common_readch( j>0 ));
|
seq[j] != '\0' && seq[j] == (c=input_common_readch( j>0 ));
|
||||||
j++ )
|
j++ )
|
||||||
;
|
;
|
||||||
|
|
||||||
if( seq[j] == '\0' )
|
if( seq[j] == '\0' )
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -281,10 +281,10 @@ static wint_t readch()
|
||||||
wint_t bnd;
|
wint_t bnd;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
struct mapping m[]=
|
struct mapping m[]=
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
"\x1b[A", LINE_UP
|
"\x1b[A", LINE_UP
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
|
@ -292,7 +292,7 @@ static wint_t readch()
|
||||||
key_up, LINE_UP
|
key_up, LINE_UP
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"\x1b[B", LINE_DOWN
|
"\x1b[B", LINE_DOWN
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
|
@ -319,18 +319,18 @@ static wint_t readch()
|
||||||
{
|
{
|
||||||
0, 0
|
0, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for( i=0; m[i].bnd; i++ )
|
for( i=0; m[i].bnd; i++ )
|
||||||
{
|
{
|
||||||
if( !m[i].seq )
|
if( !m[i].seq )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( try_sequence(m[i].seq ) )
|
if( try_sequence(m[i].seq ) )
|
||||||
return m[i].bnd;
|
return m[i].bnd;
|
||||||
}
|
}
|
||||||
|
@ -369,7 +369,7 @@ static int print_max( const wchar_t *str, int max, int has_more )
|
||||||
int written = 0;
|
int written = 0;
|
||||||
for( i=0; str[i]; i++ )
|
for( i=0; str[i]; i++ )
|
||||||
{
|
{
|
||||||
|
|
||||||
if( written + wcwidth(str[i]) > max )
|
if( written + wcwidth(str[i]) > max )
|
||||||
break;
|
break;
|
||||||
if( ( written + wcwidth(str[i]) == max) && (has_more || str[i+1]) )
|
if( ( written + wcwidth(str[i]) == max) && (has_more || str[i+1]) )
|
||||||
|
@ -378,7 +378,7 @@ static int print_max( const wchar_t *str, int max, int has_more )
|
||||||
written += wcwidth(ellipsis_char );
|
written += wcwidth(ellipsis_char );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
writech( str[i] );
|
writech( str[i] );
|
||||||
written+= wcwidth( str[i] );
|
written+= wcwidth( str[i] );
|
||||||
}
|
}
|
||||||
|
@ -393,7 +393,7 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width )
|
||||||
int comp_width=0, desc_width=0;
|
int comp_width=0, desc_width=0;
|
||||||
int i;
|
int i;
|
||||||
int written=0;
|
int written=0;
|
||||||
|
|
||||||
if( c->pref_width <= width )
|
if( c->pref_width <= width )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -411,7 +411,7 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width )
|
||||||
the description.
|
the description.
|
||||||
*/
|
*/
|
||||||
int desc_all = c->desc_width?c->desc_width+4:0;
|
int desc_all = c->desc_width?c->desc_width+4:0;
|
||||||
|
|
||||||
comp_width = maxi( mini( c->comp_width,
|
comp_width = maxi( mini( c->comp_width,
|
||||||
2*(width-4)/3 ),
|
2*(width-4)/3 ),
|
||||||
width - desc_all );
|
width - desc_all );
|
||||||
|
@ -419,9 +419,9 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width )
|
||||||
desc_width = width-comp_width-4;
|
desc_width = width-comp_width-4;
|
||||||
else
|
else
|
||||||
c->desc_width=0;
|
c->desc_width=0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i=0; i<al_get_count( c->comp ); i++ )
|
for( i=0; i<al_get_count( c->comp ); i++ )
|
||||||
{
|
{
|
||||||
const wchar_t *comp = (const wchar_t *)al_get( c->comp, i );
|
const wchar_t *comp = (const wchar_t *)al_get( c->comp, i );
|
||||||
|
@ -455,7 +455,7 @@ static void completion_print_item( const wchar_t *prefix, comp_t *c, int width )
|
||||||
writech( L' ');
|
writech( L' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -490,14 +490,14 @@ static void completion_print( int cols,
|
||||||
comp_t *el;
|
comp_t *el;
|
||||||
|
|
||||||
int is_last = (j==(cols-1));
|
int is_last = (j==(cols-1));
|
||||||
|
|
||||||
if( al_get_count( l ) <= j*rows + i )
|
if( al_get_count( l ) <= j*rows + i )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
el = (comp_t *)al_get( l, j*rows + i );
|
el = (comp_t *)al_get( l, j*rows + i );
|
||||||
|
|
||||||
completion_print_item( prefix, el, width[j] - (is_last?0:2) );
|
completion_print_item( prefix, el, width[j] - (is_last?0:2) );
|
||||||
|
|
||||||
if( !is_last)
|
if( !is_last)
|
||||||
writestr( L" " );
|
writestr( L" " );
|
||||||
}
|
}
|
||||||
|
@ -545,24 +545,24 @@ static int completion_try_print( int cols,
|
||||||
Set to one if the list should be printed at this width
|
Set to one if the list should be printed at this width
|
||||||
*/
|
*/
|
||||||
int print=0;
|
int print=0;
|
||||||
|
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
int rows = (al_get_count( l )-1)/cols+1;
|
int rows = (al_get_count( l )-1)/cols+1;
|
||||||
|
|
||||||
int pref_tot_width=0;
|
int pref_tot_width=0;
|
||||||
int min_tot_width = 0;
|
int min_tot_width = 0;
|
||||||
int res=PAGER_RETRY;
|
int res=PAGER_RETRY;
|
||||||
/*
|
/*
|
||||||
Skip completions on tiny terminals
|
Skip completions on tiny terminals
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( termsize.ws_col < PAGER_MIN_WIDTH )
|
if( termsize.ws_col < PAGER_MIN_WIDTH )
|
||||||
return PAGER_DONE;
|
return PAGER_DONE;
|
||||||
|
|
||||||
memset( pref_width, 0, sizeof(pref_width) );
|
memset( pref_width, 0, sizeof(pref_width) );
|
||||||
memset( min_width, 0, sizeof(min_width) );
|
memset( min_width, 0, sizeof(min_width) );
|
||||||
|
|
||||||
/* Calculate how wide the list would be */
|
/* Calculate how wide the list would be */
|
||||||
for( j = 0; j < cols; j++ )
|
for( j = 0; j < cols; j++ )
|
||||||
{
|
{
|
||||||
|
@ -576,7 +576,7 @@ static int completion_try_print( int cols,
|
||||||
c = (comp_t *)al_get( l, j*rows + i );
|
c = (comp_t *)al_get( l, j*rows + i );
|
||||||
pref = c->pref_width;
|
pref = c->pref_width;
|
||||||
min = c->min_width;
|
min = c->min_width;
|
||||||
|
|
||||||
if( j != cols-1 )
|
if( j != cols-1 )
|
||||||
{
|
{
|
||||||
pref += 2;
|
pref += 2;
|
||||||
|
@ -632,7 +632,7 @@ static int completion_try_print( int cols,
|
||||||
be helped, but it is not uncommon for the completions to
|
be helped, but it is not uncommon for the completions to
|
||||||
_almost_ fit on one screen. In those cases, it is almost
|
_almost_ fit on one screen. In those cases, it is almost
|
||||||
always desirable to 'squeeze' the completions into a
|
always desirable to 'squeeze' the completions into a
|
||||||
single page.
|
single page.
|
||||||
|
|
||||||
If we are using N columns and can get everything to
|
If we are using N columns and can get everything to
|
||||||
fit using squeezing, but everything would also fit
|
fit using squeezing, but everything would also fit
|
||||||
|
@ -668,7 +668,7 @@ static int completion_try_print( int cols,
|
||||||
is_ca_mode = 0;
|
is_ca_mode = 0;
|
||||||
writembs(exit_ca_mode);
|
writembs(exit_ca_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
completion_print( cols, width, 0, rows, prefix, is_quoted, l);
|
completion_print( cols, width, 0, rows, prefix, is_quoted, l);
|
||||||
pager_flush();
|
pager_flush();
|
||||||
}
|
}
|
||||||
|
@ -687,7 +687,7 @@ static int completion_try_print( int cols,
|
||||||
is_ca_mode=1;
|
is_ca_mode=1;
|
||||||
writembs(enter_ca_mode);
|
writembs(enter_ca_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
completion_print( cols,
|
completion_print( cols,
|
||||||
width,
|
width,
|
||||||
|
@ -704,18 +704,18 @@ static int completion_try_print( int cols,
|
||||||
{
|
{
|
||||||
string_buffer_t msg;
|
string_buffer_t msg;
|
||||||
sb_init( &msg );
|
sb_init( &msg );
|
||||||
|
|
||||||
set_color( FISH_COLOR_BLACK,
|
set_color( FISH_COLOR_BLACK,
|
||||||
get_color(HIGHLIGHT_PAGER_PROGRESS) );
|
get_color(HIGHLIGHT_PAGER_PROGRESS) );
|
||||||
sb_printf( &msg,
|
sb_printf( &msg,
|
||||||
_(L" %d to %d of %d"),
|
_(L" %d to %d of %d"),
|
||||||
pos,
|
pos,
|
||||||
pos+termsize.ws_row-1,
|
pos+termsize.ws_row-1,
|
||||||
rows );
|
rows );
|
||||||
|
|
||||||
sb_printf( &msg,
|
sb_printf( &msg,
|
||||||
L" \r" );
|
L" \r" );
|
||||||
|
|
||||||
writestr((wchar_t *)msg.buff);
|
writestr((wchar_t *)msg.buff);
|
||||||
sb_destroy( &msg );
|
sb_destroy( &msg );
|
||||||
set_color( FISH_COLOR_NORMAL, FISH_COLOR_NORMAL );
|
set_color( FISH_COLOR_NORMAL, FISH_COLOR_NORMAL );
|
||||||
|
@ -817,15 +817,15 @@ static int completion_try_print( int cols,
|
||||||
do_loop=0;
|
do_loop=0;
|
||||||
res=PAGER_RESIZE;
|
res=PAGER_RESIZE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
sb_append_char( &out_buff, c );
|
sb_append_char( &out_buff, c );
|
||||||
do_loop = 0;
|
do_loop = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writembs(clr_eol);
|
writembs(clr_eol);
|
||||||
|
@ -847,31 +847,31 @@ static void mangle_descriptions( array_list_t *l )
|
||||||
wchar_t *next = (wchar_t *)al_get(l, i);
|
wchar_t *next = (wchar_t *)al_get(l, i);
|
||||||
wchar_t *in, *out;
|
wchar_t *in, *out;
|
||||||
skip=1;
|
skip=1;
|
||||||
|
|
||||||
while( *next != COMPLETE_SEP && *next )
|
while( *next != COMPLETE_SEP && *next )
|
||||||
next++;
|
next++;
|
||||||
|
|
||||||
if( !*next )
|
if( !*next )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
in=out=(next+1);
|
in=out=(next+1);
|
||||||
|
|
||||||
while( *in != 0 )
|
while( *in != 0 )
|
||||||
{
|
{
|
||||||
if( *in == L' ' || *in==L'\t' || *in<32 )
|
if( *in == L' ' || *in==L'\t' || *in<32 )
|
||||||
{
|
{
|
||||||
if( !skip )
|
if( !skip )
|
||||||
*out++=L' ';
|
*out++=L' ';
|
||||||
skip=1;
|
skip=1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*out++ = *in;
|
*out++ = *in;
|
||||||
skip=0;
|
skip=0;
|
||||||
}
|
}
|
||||||
in++;
|
in++;
|
||||||
}
|
}
|
||||||
*out=0;
|
*out=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -883,7 +883,7 @@ static void join_completions( array_list_t *l )
|
||||||
long i;
|
long i;
|
||||||
int in, out;
|
int in, out;
|
||||||
hash_table_t desc_table;
|
hash_table_t desc_table;
|
||||||
|
|
||||||
hash_init( &desc_table, &hash_wcs_func, &hash_wcs_cmp );
|
hash_init( &desc_table, &hash_wcs_func, &hash_wcs_cmp );
|
||||||
|
|
||||||
for( i=0; i<al_get_count(l); i++ )
|
for( i=0; i<al_get_count(l); i++ )
|
||||||
|
@ -891,7 +891,7 @@ static void join_completions( array_list_t *l )
|
||||||
wchar_t *item = (wchar_t *)al_get( l, i );
|
wchar_t *item = (wchar_t *)al_get( l, i );
|
||||||
wchar_t *desc = wcschr( item, COMPLETE_SEP );
|
wchar_t *desc = wcschr( item, COMPLETE_SEP );
|
||||||
long prev_idx;
|
long prev_idx;
|
||||||
|
|
||||||
if( !desc )
|
if( !desc )
|
||||||
continue;
|
continue;
|
||||||
desc++;
|
desc++;
|
||||||
|
@ -905,11 +905,11 @@ static void join_completions( array_list_t *l )
|
||||||
string_buffer_t foo;
|
string_buffer_t foo;
|
||||||
wchar_t *old = (wchar_t *)al_get( l, prev_idx );
|
wchar_t *old = (wchar_t *)al_get( l, prev_idx );
|
||||||
wchar_t *old_end = wcschr( old, COMPLETE_SEP );
|
wchar_t *old_end = wcschr( old, COMPLETE_SEP );
|
||||||
|
|
||||||
if( old_end )
|
if( old_end )
|
||||||
{
|
{
|
||||||
*old_end = 0;
|
*old_end = 0;
|
||||||
|
|
||||||
sb_init( &foo );
|
sb_init( &foo );
|
||||||
sb_append( &foo, old );
|
sb_append( &foo, old );
|
||||||
sb_append_char( &foo, COMPLETE_ITEM_SEP );
|
sb_append_char( &foo, COMPLETE_ITEM_SEP );
|
||||||
|
@ -921,23 +921,23 @@ static void join_completions( array_list_t *l )
|
||||||
free( (void *)al_get( l, i ) );
|
free( (void *)al_get( l, i ) );
|
||||||
al_set( l, i, 0 );
|
al_set( l, i, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
hash_destroy( &desc_table );
|
hash_destroy( &desc_table );
|
||||||
|
|
||||||
out=0;
|
out=0;
|
||||||
for( in=0; in < al_get_count(l); in++ )
|
for( in=0; in < al_get_count(l); in++ )
|
||||||
{
|
{
|
||||||
const void * d = al_get( l, in );
|
const void * d = al_get( l, in );
|
||||||
|
|
||||||
if( d )
|
if( d )
|
||||||
{
|
{
|
||||||
al_set( l, out++, d );
|
al_set( l, out++, d );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
al_truncate( l, out );
|
al_truncate( l, out );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -946,23 +946,23 @@ static void join_completions( array_list_t *l )
|
||||||
static void mangle_completions( array_list_t *l, const wchar_t *prefix )
|
static void mangle_completions( array_list_t *l, const wchar_t *prefix )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for( i=0; i<al_get_count( l ); i++ )
|
for( i=0; i<al_get_count( l ); i++ )
|
||||||
{
|
{
|
||||||
wchar_t *next = (wchar_t *)al_get( l, i );
|
wchar_t *next = (wchar_t *)al_get( l, i );
|
||||||
wchar_t *start, *end;
|
wchar_t *start, *end;
|
||||||
comp_t *comp = halloc( global_context, sizeof( comp_t ) );
|
comp_t *comp = halloc( global_context, sizeof( comp_t ) );
|
||||||
comp->comp = al_halloc( global_context );
|
comp->comp = al_halloc( global_context );
|
||||||
|
|
||||||
for( start=end=next; 1; end++ )
|
for( start=end=next; 1; end++ )
|
||||||
{
|
{
|
||||||
wchar_t c = *end;
|
wchar_t c = *end;
|
||||||
|
|
||||||
if( (c == COMPLETE_ITEM_SEP) || (c==COMPLETE_SEP) || !c)
|
if( (c == COMPLETE_ITEM_SEP) || (c==COMPLETE_SEP) || !c)
|
||||||
{
|
{
|
||||||
*end = 0;
|
*end = 0;
|
||||||
wchar_t * str = escape( start, ESCAPE_ALL | ESCAPE_NO_QUOTED );
|
wchar_t * str = escape( start, ESCAPE_ALL | ESCAPE_NO_QUOTED );
|
||||||
|
|
||||||
comp->comp_width += my_wcswidth( str );
|
comp->comp_width += my_wcswidth( str );
|
||||||
halloc_register( global_context, str );
|
halloc_register( global_context, str );
|
||||||
al_push( comp->comp, str );
|
al_push( comp->comp, str );
|
||||||
|
@ -973,22 +973,22 @@ static void mangle_completions( array_list_t *l, const wchar_t *prefix )
|
||||||
{
|
{
|
||||||
comp->desc = halloc_wcsdup( global_context, start );
|
comp->desc = halloc_wcsdup( global_context, start );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !c )
|
if( !c )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
comp->comp_width += my_wcswidth(prefix)*al_get_count(comp->comp) + 2*(al_get_count(comp->comp)-1);
|
comp->comp_width += my_wcswidth(prefix)*al_get_count(comp->comp) + 2*(al_get_count(comp->comp)-1);
|
||||||
comp->desc_width = comp->desc?my_wcswidth( comp->desc ):0;
|
comp->desc_width = comp->desc?my_wcswidth( comp->desc ):0;
|
||||||
|
|
||||||
comp->pref_width = comp->comp_width + comp->desc_width + (comp->desc_width?4:0);
|
comp->pref_width = comp->comp_width + comp->desc_width + (comp->desc_width?4:0);
|
||||||
|
|
||||||
free( next );
|
free( next );
|
||||||
al_set( l, i, comp );
|
al_set( l, i, comp );
|
||||||
}
|
}
|
||||||
|
|
||||||
recalc_width( l, prefix );
|
recalc_width( l, prefix );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1026,10 +1026,10 @@ static void init( int mangle_descriptors, int out )
|
||||||
|
|
||||||
static struct termios pager_modes;
|
static struct termios pager_modes;
|
||||||
char *term;
|
char *term;
|
||||||
|
|
||||||
if( mangle_descriptors )
|
if( mangle_descriptors )
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Make fd 1 output to screen, and use some other fd for writing
|
Make fd 1 output to screen, and use some other fd for writing
|
||||||
the resulting output back to the caller
|
the resulting output back to the caller
|
||||||
|
@ -1042,13 +1042,13 @@ static void init( int mangle_descriptors, int out )
|
||||||
if( (in = open( ttyname(2), O_RDWR )) != -1 )
|
if( (in = open( ttyname(2), O_RDWR )) != -1 )
|
||||||
{
|
{
|
||||||
if( dup2( 2, 1 ) == -1 )
|
if( dup2( 2, 1 ) == -1 )
|
||||||
{
|
{
|
||||||
debug( 0, _(L"Could not set up output file descriptors for pager") );
|
debug( 0, _(L"Could not set up output file descriptors for pager") );
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( dup2( in, 0 ) == -1 )
|
if( dup2( in, 0 ) == -1 )
|
||||||
{
|
{
|
||||||
debug( 0, _(L"Could not set up input file descriptors for pager") );
|
debug( 0, _(L"Could not set up input file descriptors for pager") );
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
|
@ -1059,13 +1059,13 @@ static void init( int mangle_descriptors, int out )
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !(out_file = fdopen( out, "w" )) )
|
if( !(out_file = fdopen( out, "w" )) )
|
||||||
{
|
{
|
||||||
debug( 0, _(L"Could not initialize result pipe" ) );
|
debug( 0, _(L"Could not initialize result pipe" ) );
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Init the stringbuffer used to keep any output in
|
Init the stringbuffer used to keep any output in
|
||||||
|
@ -1088,7 +1088,7 @@ static void init( int mangle_descriptors, int out )
|
||||||
wperror( L"sigaction" );
|
wperror( L"sigaction" );
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_winch( 0 ); /* Set handler for window change events */
|
handle_winch( 0 ); /* Set handler for window change events */
|
||||||
|
|
||||||
tcgetattr(0,&pager_modes); /* get the current terminal modes */
|
tcgetattr(0,&pager_modes); /* get the current terminal modes */
|
||||||
|
@ -1102,14 +1102,14 @@ static void init( int mangle_descriptors, int out )
|
||||||
pager_modes.c_cc[VTIME]=0;
|
pager_modes.c_cc[VTIME]=0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
if( tcsetattr(0,TCSANOW,&pager_modes)) /* set the new modes */
|
if( tcsetattr(0,TCSANOW,&pager_modes)) /* set the new modes */
|
||||||
{
|
{
|
||||||
wperror(L"tcsetattr");
|
wperror(L"tcsetattr");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( setupterm( 0, STDOUT_FILENO, 0) == ERR )
|
if( setupterm( 0, STDOUT_FILENO, 0) == ERR )
|
||||||
{
|
{
|
||||||
|
@ -1124,7 +1124,7 @@ static void init( int mangle_descriptors, int out )
|
||||||
output_set_term( wterm );
|
output_set_term( wterm );
|
||||||
free( wterm );
|
free( wterm );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1137,9 +1137,9 @@ static void destroy()
|
||||||
wutil_destroy();
|
wutil_destroy();
|
||||||
if( del_curterm( cur_term ) == ERR )
|
if( del_curterm( cur_term ) == ERR )
|
||||||
{
|
{
|
||||||
debug( 0, _(L"Error while closing terminfo") );
|
debug( 0, _(L"Error while closing terminfo") );
|
||||||
}
|
}
|
||||||
|
|
||||||
sb_destroy( &out_buff );
|
sb_destroy( &out_buff );
|
||||||
fclose( out_file );
|
fclose( out_file );
|
||||||
}
|
}
|
||||||
|
@ -1164,7 +1164,7 @@ static void read_array( FILE* file, array_list_t *comp )
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
c = getc( file );
|
c = getc( file );
|
||||||
if( c == EOF )
|
if( c == EOF )
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1175,7 +1175,7 @@ static void read_array( FILE* file, array_list_t *comp )
|
||||||
}
|
}
|
||||||
|
|
||||||
cc=c;
|
cc=c;
|
||||||
|
|
||||||
b_append( &buffer, &cc, 1 );
|
b_append( &buffer, &cc, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1183,15 +1183,15 @@ static void read_array( FILE* file, array_list_t *comp )
|
||||||
{
|
{
|
||||||
cc=0;
|
cc=0;
|
||||||
b_append( &buffer, &cc, 1 );
|
b_append( &buffer, &cc, 1 );
|
||||||
|
|
||||||
wcs = str2wcs( buffer.buff );
|
wcs = str2wcs( buffer.buff );
|
||||||
if( wcs )
|
if( wcs )
|
||||||
{
|
{
|
||||||
unescaped = unescape( wcs, 0 );
|
unescaped = unescape( wcs, 0 );
|
||||||
if( unescaped )
|
if( unescaped )
|
||||||
{
|
{
|
||||||
al_push( comp, unescaped );
|
al_push( comp, unescaped );
|
||||||
}
|
}
|
||||||
free( wcs );
|
free( wcs );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1203,9 +1203,9 @@ static void read_array( FILE* file, array_list_t *comp )
|
||||||
|
|
||||||
static int get_fd( const char *str )
|
static int get_fd( const char *str )
|
||||||
{
|
{
|
||||||
char *end;
|
char *end;
|
||||||
long fd;
|
long fd;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
fd = strtol( str, &end, 10 );
|
fd = strtol( str, &end, 10 );
|
||||||
if( fd < 0 || *end || errno )
|
if( fd < 0 || *end || errno )
|
||||||
|
@ -1220,13 +1220,13 @@ static int get_fd( const char *str )
|
||||||
int main( int argc, char **argv )
|
int main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int is_quoted=0;
|
int is_quoted=0;
|
||||||
array_list_t *comp;
|
array_list_t *comp;
|
||||||
wchar_t *prefix = 0;
|
wchar_t *prefix = 0;
|
||||||
|
|
||||||
int mangle_descriptors = 0;
|
int mangle_descriptors = 0;
|
||||||
int result_fd = -1;
|
int result_fd = -1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This initialization is made early, so that the other init code
|
This initialization is made early, so that the other init code
|
||||||
can use global_context for memory managment
|
can use global_context for memory managment
|
||||||
|
@ -1252,69 +1252,69 @@ int main( int argc, char **argv )
|
||||||
/*
|
/*
|
||||||
Third mode
|
Third mode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int completion_fd = -1;
|
int completion_fd = -1;
|
||||||
FILE *completion_file;
|
FILE *completion_file;
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
static struct option
|
static struct option
|
||||||
long_options[] =
|
long_options[] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
"result-fd", required_argument, 0, 'r'
|
"result-fd", required_argument, 0, 'r'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"completion-fd", required_argument, 0, 'c'
|
"completion-fd", required_argument, 0, 'c'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"prefix", required_argument, 0, 'p'
|
"prefix", required_argument, 0, 'p'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"is-quoted", no_argument, 0, 'q'
|
"is-quoted", no_argument, 0, 'q'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"help", no_argument, 0, 'h'
|
"help", no_argument, 0, 'h'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"version", no_argument, 0, 'v'
|
"version", no_argument, 0, 'v'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
0, 0, 0, 0
|
0, 0, 0, 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
int opt_index = 0;
|
int opt_index = 0;
|
||||||
|
|
||||||
int opt = getopt_long( argc,
|
int opt = getopt_long( argc,
|
||||||
argv,
|
argv,
|
||||||
GETOPT_STRING,
|
GETOPT_STRING,
|
||||||
long_options,
|
long_options,
|
||||||
&opt_index );
|
&opt_index );
|
||||||
|
|
||||||
if( opt == -1 )
|
if( opt == -1 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch( opt )
|
switch( opt )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
{
|
{
|
||||||
result_fd = get_fd( optarg );
|
result_fd = get_fd( optarg );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
{
|
{
|
||||||
completion_fd = get_fd( optarg );
|
completion_fd = get_fd( optarg );
|
||||||
|
@ -1330,20 +1330,20 @@ int main( int argc, char **argv )
|
||||||
case 'h':
|
case 'h':
|
||||||
{
|
{
|
||||||
print_help( argv[0], 1 );
|
print_help( argv[0], 1 );
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
{
|
{
|
||||||
debug( 0, L"%ls, version %s\n", program_name, PACKAGE_VERSION );
|
debug( 0, L"%ls, version %s\n", program_name, PACKAGE_VERSION );
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'q':
|
case 'q':
|
||||||
{
|
{
|
||||||
is_quoted = 1;
|
is_quoted = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1352,7 +1352,7 @@ int main( int argc, char **argv )
|
||||||
debug( 0, _(L"Unspecified file descriptors") );
|
debug( 0, _(L"Unspecified file descriptors") );
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( (completion_file = fdopen( completion_fd, "r" ) ) )
|
if( (completion_file = fdopen( completion_fd, "r" ) ) )
|
||||||
{
|
{
|
||||||
|
@ -1370,8 +1370,8 @@ int main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
prefix = wcsdup( L"" );
|
prefix = wcsdup( L"" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1385,7 +1385,7 @@ int main( int argc, char **argv )
|
||||||
forward. A reasonable time frame for removal of the code
|
forward. A reasonable time frame for removal of the code
|
||||||
below has yet to be determined.
|
below has yet to be determined.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( argc < 3 )
|
if( argc < 3 )
|
||||||
{
|
{
|
||||||
print_help( argv[0], 1 );
|
print_help( argv[0], 1 );
|
||||||
|
@ -1394,10 +1394,10 @@ int main( int argc, char **argv )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mangle_descriptors = 1;
|
mangle_descriptors = 1;
|
||||||
|
|
||||||
prefix = str2wcs( argv[2] );
|
prefix = str2wcs( argv[2] );
|
||||||
is_quoted = strcmp( "1", argv[1] )==0;
|
is_quoted = strcmp( "1", argv[1] )==0;
|
||||||
|
|
||||||
if( argc > 3 )
|
if( argc > 3 )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -1420,11 +1420,11 @@ int main( int argc, char **argv )
|
||||||
read_array( stdin, comp );
|
read_array( stdin, comp );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// debug( 3, L"prefix is '%ls'", prefix );
|
// debug( 3, L"prefix is '%ls'", prefix );
|
||||||
|
|
||||||
init( mangle_descriptors, result_fd );
|
init( mangle_descriptors, result_fd );
|
||||||
|
|
||||||
mangle_descriptions( comp );
|
mangle_descriptions( comp );
|
||||||
|
@ -1462,9 +1462,9 @@ int main( int argc, char **argv )
|
||||||
i=PAGER_MAX_COLS+1;
|
i=PAGER_MAX_COLS+1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(prefix );
|
free(prefix );
|
||||||
|
|
||||||
fwprintf( out_file, L"%ls", (wchar_t *)out_buff.buff );
|
fwprintf( out_file, L"%ls", (wchar_t *)out_buff.buff );
|
||||||
|
@ -1476,6 +1476,6 @@ int main( int argc, char **argv )
|
||||||
destroy();
|
destroy();
|
||||||
|
|
||||||
halloc_util_destroy();
|
halloc_util_destroy();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
290
fish_tests.c
290
fish_tests.c
|
@ -16,7 +16,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#ifdef HAVE_GETOPT_H
|
#ifdef HAVE_GETOPT_H
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
@ -85,7 +85,7 @@ static void say( wchar_t *blah, ... )
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start( va, blah );
|
va_start( va, blah );
|
||||||
vwprintf( blah, va );
|
vwprintf( blah, va );
|
||||||
va_end( va );
|
va_end( va );
|
||||||
wprintf( L"\n" );
|
wprintf( L"\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,10 +97,10 @@ static void err( wchar_t *blah, ... )
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start( va, blah );
|
va_start( va, blah );
|
||||||
err_count++;
|
err_count++;
|
||||||
|
|
||||||
wprintf( L"Error: " );
|
wprintf( L"Error: " );
|
||||||
vwprintf( blah, va );
|
vwprintf( blah, va );
|
||||||
va_end( va );
|
va_end( va );
|
||||||
wprintf( L"\n" );
|
wprintf( L"\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,13 +119,13 @@ static void pq_test( int elements )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int prev;
|
int prev;
|
||||||
|
|
||||||
int *count = calloc( sizeof(int), 100 );
|
int *count = calloc( sizeof(int), 100 );
|
||||||
|
|
||||||
priority_queue_t q;
|
priority_queue_t q;
|
||||||
pq_init( &q, pq_compare );
|
pq_init( &q, pq_compare );
|
||||||
|
|
||||||
|
|
||||||
for( i=0; i<elements; i++ )
|
for( i=0; i<elements; i++ )
|
||||||
{
|
{
|
||||||
long foo = rand() % 100;
|
long foo = rand() % 100;
|
||||||
|
@ -133,9 +133,9 @@ static void pq_test( int elements )
|
||||||
pq_put( &q, (void *)foo );
|
pq_put( &q, (void *)foo );
|
||||||
count[foo]++;
|
count[foo]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
prev = 100;
|
prev = 100;
|
||||||
|
|
||||||
for( i=0; i<elements; i++ )
|
for( i=0; i<elements; i++ )
|
||||||
{
|
{
|
||||||
long pos = (long)pq_get( &q );
|
long pos = (long)pq_get( &q );
|
||||||
|
@ -143,7 +143,7 @@ static void pq_test( int elements )
|
||||||
if( pos > prev )
|
if( pos > prev )
|
||||||
err( L"Wrong order of elements in priority_queue_t" );
|
err( L"Wrong order of elements in priority_queue_t" );
|
||||||
prev = pos;
|
prev = pos;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i=0; i<100; i++ )
|
for( i=0; i<100; i++ )
|
||||||
|
@ -163,10 +163,10 @@ static int stack_test( int elements )
|
||||||
long i;
|
long i;
|
||||||
|
|
||||||
int res=1;
|
int res=1;
|
||||||
|
|
||||||
array_list_t s;
|
array_list_t s;
|
||||||
|
|
||||||
al_init( &s );
|
al_init( &s );
|
||||||
|
|
||||||
for( i=0; i<elements; i++ )
|
for( i=0; i<elements; i++ )
|
||||||
{
|
{
|
||||||
|
@ -174,11 +174,11 @@ static int stack_test( int elements )
|
||||||
|
|
||||||
al_push_long( &s, i);
|
al_push_long( &s, i);
|
||||||
al_push_long( &s, i);
|
al_push_long( &s, i);
|
||||||
|
|
||||||
if( (foo=al_pop_long( &s )) != i )
|
if( (foo=al_pop_long( &s )) != i )
|
||||||
{
|
{
|
||||||
err( L"Unexpected data" );
|
err( L"Unexpected data" );
|
||||||
res = 0;
|
res = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,18 +186,18 @@ static int stack_test( int elements )
|
||||||
for( i=0; i<elements; i++ )
|
for( i=0; i<elements; i++ )
|
||||||
{
|
{
|
||||||
long foo;
|
long foo;
|
||||||
|
|
||||||
if( (foo=al_pop_long( &s )) != (elements-i-1) )
|
if( (foo=al_pop_long( &s )) != (elements-i-1) )
|
||||||
{
|
{
|
||||||
err( L"Unexpected data" );
|
err( L"Unexpected data" );
|
||||||
res = 0;
|
res = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
al_destroy( &s );
|
al_destroy( &s );
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ static int hash_func( void *data )
|
||||||
return rand();
|
return rand();
|
||||||
*/
|
*/
|
||||||
int foo = (int)(long)data;
|
int foo = (int)(long)data;
|
||||||
return 127*((foo^0xefc7e214)) ^(foo<<11);
|
return 127*((foo^0xefc7e214)) ^(foo<<11);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -229,26 +229,26 @@ static int hash_test( long elements )
|
||||||
{
|
{
|
||||||
long i;
|
long i;
|
||||||
int res=1;
|
int res=1;
|
||||||
|
|
||||||
hash_table_t h;
|
hash_table_t h;
|
||||||
|
|
||||||
hash_init( &h, hash_func, compare_func );
|
hash_init( &h, hash_func, compare_func );
|
||||||
|
|
||||||
for( i=1; i< elements+1; i++ )
|
for( i=1; i< elements+1; i++ )
|
||||||
{
|
{
|
||||||
hash_put( &h, (void*)i, (void*)100l-i );
|
hash_put( &h, (void*)i, (void*)100l-i );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i=1; i< elements+1; i++ )
|
for( i=1; i< elements+1; i++ )
|
||||||
{
|
{
|
||||||
if( (long)hash_get( &h, (void*)i ) != (100l-i) )
|
if( (long)hash_get( &h, (void*)i ) != (100l-i) )
|
||||||
{
|
{
|
||||||
err( L"Key %d gave data %d, expected data %d",
|
err( L"Key %d gave data %d, expected data %d",
|
||||||
i,
|
i,
|
||||||
(long)hash_get( &h, (void*)i ),
|
(long)hash_get( &h, (void*)i ),
|
||||||
100l-i );
|
100l-i );
|
||||||
res = 0;
|
res = 0;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,14 +259,14 @@ static int hash_test( long elements )
|
||||||
hash_get_count( &h ),
|
hash_get_count( &h ),
|
||||||
elements );
|
elements );
|
||||||
res = 0;
|
res = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for( i=1; i<elements+1; i+=2 )
|
for( i=1; i<elements+1; i+=2 )
|
||||||
{
|
{
|
||||||
hash_remove( &h, (void*)i, 0, 0 );
|
hash_remove( &h, (void*)i, 0, 0 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( hash_get_count( &h ) != ((elements)/2) )
|
if( hash_get_count( &h ) != ((elements)/2) )
|
||||||
|
@ -276,7 +276,7 @@ static int hash_test( long elements )
|
||||||
elements/2 );
|
elements/2 );
|
||||||
res = 0;
|
res = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i=1; i<elements+1; i++ )
|
for( i=1; i<elements+1; i++ )
|
||||||
{
|
{
|
||||||
if( hash_contains( &h, (void*)i) != (i+1l)%2l )
|
if( hash_contains( &h, (void*)i) != (i+1l)%2l )
|
||||||
|
@ -295,7 +295,7 @@ static int hash_test( long elements )
|
||||||
hash_destroy( &h );
|
hash_destroy( &h );
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -303,19 +303,19 @@ static int hash_test( long elements )
|
||||||
*/
|
*/
|
||||||
static void al_test( int sz)
|
static void al_test( int sz)
|
||||||
{
|
{
|
||||||
long i;
|
long i;
|
||||||
array_list_t l;
|
array_list_t l;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
al_init( &l );
|
al_init( &l );
|
||||||
|
|
||||||
al_set_long( &l, 1, 7L );
|
al_set_long( &l, 1, 7L );
|
||||||
al_set_long( &l, sz, 7L );
|
al_set_long( &l, sz, 7L );
|
||||||
|
|
||||||
if( al_get_count( &l ) != maxi( sz+1, 2 ) )
|
if( al_get_count( &l ) != maxi( sz+1, 2 ) )
|
||||||
err( L"Wrong number of elements in array list" );
|
err( L"Wrong number of elements in array list" );
|
||||||
|
|
||||||
for( i=0; i<al_get_count( &l ); i++ )
|
for( i=0; i<al_get_count( &l ); i++ )
|
||||||
{
|
{
|
||||||
long val = al_get_long( &l, i );
|
long val = al_get_long( &l, i );
|
||||||
|
@ -339,15 +339,15 @@ static void sb_test()
|
||||||
{
|
{
|
||||||
string_buffer_t b;
|
string_buffer_t b;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
sb_init( &b );
|
sb_init( &b );
|
||||||
|
|
||||||
if( (res=sb_printf( &b, L"%ls%s", L"Testing ", "string_buffer_t " )) == -1 )
|
if( (res=sb_printf( &b, L"%ls%s", L"Testing ", "string_buffer_t " )) == -1 )
|
||||||
{
|
{
|
||||||
err( L"Error %d while testing stringbuffers", res );
|
err( L"Error %d while testing stringbuffers", res );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (res=sb_printf( &b, L"%ls", L"functionality" ))==-1)
|
if( (res=sb_printf( &b, L"%ls", L"functionality" ))==-1)
|
||||||
{
|
{
|
||||||
err( L"Error %d while testing stringbuffers", res );
|
err( L"Error %d while testing stringbuffers", res );
|
||||||
}
|
}
|
||||||
|
@ -362,9 +362,9 @@ static void sb_test()
|
||||||
err( L"numerical formating is broken, '%ls' != '%ls'", (wchar_t *)b.buff, NUM_ANS );
|
err( L"numerical formating is broken, '%ls' != '%ls'", (wchar_t *)b.buff, NUM_ANS );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
say( L"numerical formating works" );
|
say( L"numerical formating works" );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -375,7 +375,7 @@ static void test_util()
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
say( L"Testing utility library" );
|
say( L"Testing utility library" );
|
||||||
|
|
||||||
for( i=0; i<18; i++ )
|
for( i=0; i<18; i++ )
|
||||||
{
|
{
|
||||||
long t1, t2;
|
long t1, t2;
|
||||||
|
@ -392,27 +392,27 @@ static void test_util()
|
||||||
}
|
}
|
||||||
|
|
||||||
sb_test();
|
sb_test();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
int i;
|
int i;
|
||||||
for( i=2; i<10000000; i*=2 )
|
for( i=2; i<10000000; i*=2 )
|
||||||
{
|
{
|
||||||
|
|
||||||
printf( "%d", i );
|
printf( "%d", i );
|
||||||
|
|
||||||
t1 = get_time();
|
t1 = get_time();
|
||||||
|
|
||||||
if(!hash_test(i))
|
if(!hash_test(i))
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
t2 = get_time();
|
t2 = get_time();
|
||||||
|
|
||||||
printf( " %d\n", (t2-t1)/i );
|
printf( " %d\n", (t2-t1)/i );
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -424,15 +424,15 @@ static void test_escape()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
string_buffer_t sb;
|
string_buffer_t sb;
|
||||||
|
|
||||||
say( L"Testing escaping and unescaping" );
|
say( L"Testing escaping and unescaping" );
|
||||||
|
|
||||||
sb_init( &sb );
|
sb_init( &sb );
|
||||||
|
|
||||||
for( i=0; i<ESCAPE_TEST_COUNT; i++ )
|
for( i=0; i<ESCAPE_TEST_COUNT; i++ )
|
||||||
{
|
{
|
||||||
wchar_t *o, *e, *u;
|
wchar_t *o, *e, *u;
|
||||||
|
|
||||||
sb_clear( &sb );
|
sb_clear( &sb );
|
||||||
while( rand() % ESCAPE_TEST_LENGTH )
|
while( rand() % ESCAPE_TEST_LENGTH )
|
||||||
{
|
{
|
||||||
|
@ -444,23 +444,23 @@ static void test_escape()
|
||||||
if( !o || !e || !u )
|
if( !o || !e || !u )
|
||||||
{
|
{
|
||||||
err( L"Escaping cycle of string %ls produced null pointer on %ls", o, e?L"unescaping":L"escaping" );
|
err( L"Escaping cycle of string %ls produced null pointer on %ls", o, e?L"unescaping":L"escaping" );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( wcscmp(o, u) )
|
if( wcscmp(o, u) )
|
||||||
{
|
{
|
||||||
err( L"Escaping cycle of string %ls produced different string %ls", o, u );
|
err( L"Escaping cycle of string %ls produced different string %ls", o, u );
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
free( e );
|
free( e );
|
||||||
free( u );
|
free( u );
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -470,17 +470,17 @@ static void test_escape()
|
||||||
*/
|
*/
|
||||||
static void test_convert()
|
static void test_convert()
|
||||||
{
|
{
|
||||||
/* char o[] =
|
/* char o[] =
|
||||||
{
|
{
|
||||||
-17, -128, -121, -68, 0
|
-17, -128, -121, -68, 0
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
wchar_t *w = str2wcs(o);
|
wchar_t *w = str2wcs(o);
|
||||||
char *n = wcs2str(w);
|
char *n = wcs2str(w);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for( i=0; o[i]; i++ )
|
for( i=0; o[i]; i++ )
|
||||||
{
|
{
|
||||||
bitprint(o[i]);;
|
bitprint(o[i]);;
|
||||||
|
@ -508,20 +508,20 @@ static void test_convert()
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
buffer_t sb;
|
buffer_t sb;
|
||||||
|
|
||||||
say( L"Testing wide/narrow string conversion" );
|
say( L"Testing wide/narrow string conversion" );
|
||||||
|
|
||||||
b_init( &sb );
|
b_init( &sb );
|
||||||
|
|
||||||
for( i=0; i<ESCAPE_TEST_COUNT; i++ )
|
for( i=0; i<ESCAPE_TEST_COUNT; i++ )
|
||||||
{
|
{
|
||||||
wchar_t *w;
|
wchar_t *w;
|
||||||
char *o, *n;
|
char *o, *n;
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
sb.used=0;
|
sb.used=0;
|
||||||
|
|
||||||
while( rand() % ESCAPE_TEST_LENGTH )
|
while( rand() % ESCAPE_TEST_LENGTH )
|
||||||
{
|
{
|
||||||
c = rand ();
|
c = rand ();
|
||||||
|
@ -529,23 +529,23 @@ static void test_convert()
|
||||||
}
|
}
|
||||||
c = 0;
|
c = 0;
|
||||||
b_append( &sb, &c, 1 );
|
b_append( &sb, &c, 1 );
|
||||||
|
|
||||||
o = (char *)sb.buff;
|
o = (char *)sb.buff;
|
||||||
w = str2wcs(o);
|
w = str2wcs(o);
|
||||||
n = wcs2str(w);
|
n = wcs2str(w);
|
||||||
|
|
||||||
if( !o || !w || !n )
|
if( !o || !w || !n )
|
||||||
{
|
{
|
||||||
err( L"Conversion cycle of string %s produced null pointer on %s", o, w?L"str2wcs":L"wcs2str" );
|
err( L"Conversion cycle of string %s produced null pointer on %s", o, w?L"str2wcs":L"wcs2str" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( strcmp(o, n) )
|
if( strcmp(o, n) )
|
||||||
{
|
{
|
||||||
err( L"%d: Conversion cycle of string %s produced different string %s", i, o, n );
|
err( L"%d: Conversion cycle of string %s produced different string %s", i, o, n );
|
||||||
}
|
}
|
||||||
free( w );
|
free( w );
|
||||||
free( n );
|
free( n );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -556,10 +556,10 @@ static void test_convert()
|
||||||
static void test_tok()
|
static void test_tok()
|
||||||
{
|
{
|
||||||
tokenizer t;
|
tokenizer t;
|
||||||
|
|
||||||
say( L"Testing tokenizer" );
|
say( L"Testing tokenizer" );
|
||||||
|
|
||||||
|
|
||||||
say( L"Testing invalid input" );
|
say( L"Testing invalid input" );
|
||||||
tok_init( &t, 0, 0 );
|
tok_init( &t, 0, 0 );
|
||||||
|
|
||||||
|
@ -567,13 +567,13 @@ static void test_tok()
|
||||||
{
|
{
|
||||||
err(L"Invalid input to tokenizer was undetected" );
|
err(L"Invalid input to tokenizer was undetected" );
|
||||||
}
|
}
|
||||||
|
|
||||||
say( L"Testing use of broken tokenizer" );
|
say( L"Testing use of broken tokenizer" );
|
||||||
if( !tok_has_next( &t ) )
|
if( !tok_has_next( &t ) )
|
||||||
{
|
{
|
||||||
err( L"tok_has_next() should return 1 once on broken tokenizer" );
|
err( L"tok_has_next() should return 1 once on broken tokenizer" );
|
||||||
}
|
}
|
||||||
|
|
||||||
tok_next( &t );
|
tok_next( &t );
|
||||||
if( tok_last_type( &t ) != TOK_ERROR )
|
if( tok_last_type( &t ) != TOK_ERROR )
|
||||||
{
|
{
|
||||||
|
@ -585,17 +585,17 @@ static void test_tok()
|
||||||
*/
|
*/
|
||||||
say( L"Test destruction of broken tokenizer" );
|
say( L"Test destruction of broken tokenizer" );
|
||||||
tok_destroy( &t );
|
tok_destroy( &t );
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
wchar_t *str = L"string <redirection 2>&1 'nested \"quoted\" '(string containing subshells ){and,brackets}$as[$well (as variable arrays)]";
|
wchar_t *str = L"string <redirection 2>&1 'nested \"quoted\" '(string containing subshells ){and,brackets}$as[$well (as variable arrays)]";
|
||||||
const int types[] =
|
const int types[] =
|
||||||
{
|
{
|
||||||
TOK_STRING, TOK_REDIRECT_IN, TOK_STRING, TOK_REDIRECT_FD, TOK_STRING, TOK_STRING, TOK_END
|
TOK_STRING, TOK_REDIRECT_IN, TOK_STRING, TOK_REDIRECT_FD, TOK_STRING, TOK_STRING, TOK_END
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
say( L"Test correct tokenization" );
|
say( L"Test correct tokenization" );
|
||||||
|
|
||||||
for( i=0, tok_init( &t, str, 0 ); i<(sizeof(types)/sizeof(int)); i++,tok_next( &t ) )
|
for( i=0, tok_init( &t, str, 0 ); i<(sizeof(types)/sizeof(int)); i++,tok_next( &t ) )
|
||||||
|
@ -603,7 +603,7 @@ static void test_tok()
|
||||||
if( types[i] != tok_last_type( &t ) )
|
if( types[i] != tok_last_type( &t ) )
|
||||||
{
|
{
|
||||||
err( L"Tokenization error:");
|
err( L"Tokenization error:");
|
||||||
wprintf( L"Token number %d of string \n'%ls'\n, expected token type %ls, got token '%ls' of type %ls\n",
|
wprintf( L"Token number %d of string \n'%ls'\n, expected token type %ls, got token '%ls' of type %ls\n",
|
||||||
i+1,
|
i+1,
|
||||||
str,
|
str,
|
||||||
tok_get_desc(types[i]),
|
tok_get_desc(types[i]),
|
||||||
|
@ -612,9 +612,9 @@ static void test_tok()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -623,8 +623,8 @@ static void test_tok()
|
||||||
static void test_parser()
|
static void test_parser()
|
||||||
{
|
{
|
||||||
say( L"Testing parser" );
|
say( L"Testing parser" );
|
||||||
|
|
||||||
|
|
||||||
say( L"Testing null input to parser" );
|
say( L"Testing null input to parser" );
|
||||||
if( !parser_test( 0, 0, 0, 0 ) )
|
if( !parser_test( 0, 0, 0, 0 ) )
|
||||||
{
|
{
|
||||||
|
@ -634,51 +634,51 @@ static void test_parser()
|
||||||
say( L"Testing block nesting" );
|
say( L"Testing block nesting" );
|
||||||
if( !parser_test( L"if; end", 0, 0, 0 ) )
|
if( !parser_test( L"if; end", 0, 0, 0 ) )
|
||||||
{
|
{
|
||||||
err( L"Incomplete if statement undetected" );
|
err( L"Incomplete if statement undetected" );
|
||||||
}
|
}
|
||||||
if( !parser_test( L"if test; echo", 0, 0, 0 ) )
|
if( !parser_test( L"if test; echo", 0, 0, 0 ) )
|
||||||
{
|
{
|
||||||
err( L"Missing end undetected" );
|
err( L"Missing end undetected" );
|
||||||
}
|
}
|
||||||
if( !parser_test( L"if test; end; end", 0, 0, 0 ) )
|
if( !parser_test( L"if test; end; end", 0, 0, 0 ) )
|
||||||
{
|
{
|
||||||
err( L"Unbalanced end undetected" );
|
err( L"Unbalanced end undetected" );
|
||||||
}
|
}
|
||||||
|
|
||||||
say( L"Testing detection of invalid use of builtin commands" );
|
say( L"Testing detection of invalid use of builtin commands" );
|
||||||
if( !parser_test( L"case foo", 0, 0, 0 ) )
|
if( !parser_test( L"case foo", 0, 0, 0 ) )
|
||||||
{
|
{
|
||||||
err( L"'case' command outside of block context undetected" );
|
err( L"'case' command outside of block context undetected" );
|
||||||
}
|
}
|
||||||
if( !parser_test( L"switch ggg; if true; case foo;end;end", 0, 0, 0 ) )
|
if( !parser_test( L"switch ggg; if true; case foo;end;end", 0, 0, 0 ) )
|
||||||
{
|
{
|
||||||
err( L"'case' command outside of switch block context undetected" );
|
err( L"'case' command outside of switch block context undetected" );
|
||||||
}
|
}
|
||||||
if( !parser_test( L"else", 0, 0, 0 ) )
|
if( !parser_test( L"else", 0, 0, 0 ) )
|
||||||
{
|
{
|
||||||
err( L"'else' command outside of conditional block context undetected" );
|
err( L"'else' command outside of conditional block context undetected" );
|
||||||
}
|
}
|
||||||
if( !parser_test( L"break", 0, 0, 0 ) )
|
if( !parser_test( L"break", 0, 0, 0 ) )
|
||||||
{
|
{
|
||||||
err( L"'break' command outside of loop block context undetected" );
|
err( L"'break' command outside of loop block context undetected" );
|
||||||
}
|
}
|
||||||
if( !parser_test( L"exec ls|less", 0, 0, 0 ) || !parser_test( L"echo|return", 0, 0, 0 ))
|
if( !parser_test( L"exec ls|less", 0, 0, 0 ) || !parser_test( L"echo|return", 0, 0, 0 ))
|
||||||
{
|
{
|
||||||
err( L"Invalid pipe command undetected" );
|
err( L"Invalid pipe command undetected" );
|
||||||
}
|
}
|
||||||
|
|
||||||
say( L"Testing basic evaluation" );
|
say( L"Testing basic evaluation" );
|
||||||
if( !eval( 0, 0, TOP ) )
|
if( !eval( 0, 0, TOP ) )
|
||||||
{
|
{
|
||||||
err( L"Null input when evaluating undetected" );
|
err( L"Null input when evaluating undetected" );
|
||||||
}
|
}
|
||||||
if( !eval( L"ls", 0, WHILE ) )
|
if( !eval( L"ls", 0, WHILE ) )
|
||||||
{
|
{
|
||||||
err( L"Invalid block mode when evaluating undetected" );
|
err( L"Invalid block mode when evaluating undetected" );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Perform parameter expansion and test if the output equals the zero-terminated parameter list supplied.
|
Perform parameter expansion and test if the output equals the zero-terminated parameter list supplied.
|
||||||
|
|
||||||
|
@ -688,42 +688,42 @@ static void test_parser()
|
||||||
|
|
||||||
static int expand_test( const wchar_t *in, int flags, ... )
|
static int expand_test( const wchar_t *in, int flags, ... )
|
||||||
{
|
{
|
||||||
array_list_t out;
|
array_list_t out;
|
||||||
va_list va;
|
va_list va;
|
||||||
int i=0;
|
int i=0;
|
||||||
int res=1;
|
int res=1;
|
||||||
wchar_t *arg;
|
wchar_t *arg;
|
||||||
|
|
||||||
al_init( &out );
|
al_init( &out );
|
||||||
if( expand_string( 0, wcsdup(in), &out, flags) )
|
if( expand_string( 0, wcsdup(in), &out, flags) )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
va_start( va, flags );
|
va_start( va, flags );
|
||||||
|
|
||||||
while( (arg=va_arg(va, wchar_t *) )!= 0 )
|
while( (arg=va_arg(va, wchar_t *) )!= 0 )
|
||||||
{
|
{
|
||||||
if( al_get_count( &out ) == i )
|
if( al_get_count( &out ) == i )
|
||||||
{
|
{
|
||||||
res=0;
|
res=0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( wcscmp( al_get( &out, i ),arg) != 0 )
|
if( wcscmp( al_get( &out, i ),arg) != 0 )
|
||||||
{
|
{
|
||||||
res=0;
|
res=0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
va_end( va );
|
va_end( va );
|
||||||
|
|
||||||
al_foreach( &out, &free );
|
al_foreach( &out, &free );
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -732,7 +732,7 @@ static int expand_test( const wchar_t *in, int flags, ... )
|
||||||
static void test_expand()
|
static void test_expand()
|
||||||
{
|
{
|
||||||
say( L"Testing parameter expansion" );
|
say( L"Testing parameter expansion" );
|
||||||
|
|
||||||
if( !expand_test( L"foo", 0, L"foo", 0 ))
|
if( !expand_test( L"foo", 0, L"foo", 0 ))
|
||||||
{
|
{
|
||||||
err( L"Strings do not expand to themselves" );
|
err( L"Strings do not expand to themselves" );
|
||||||
|
@ -747,7 +747,7 @@ static void test_expand()
|
||||||
{
|
{
|
||||||
err( L"Cannot skip wildcard expansion" );
|
err( L"Cannot skip wildcard expansion" );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -758,17 +758,17 @@ static void test_path()
|
||||||
say( L"Testing path functions" );
|
say( L"Testing path functions" );
|
||||||
|
|
||||||
void *context = halloc( 0, 0 );
|
void *context = halloc( 0, 0 );
|
||||||
|
|
||||||
|
|
||||||
wchar_t *can = path_make_canonical( context, L"//foo//////bar/" );
|
wchar_t *can = path_make_canonical( context, L"//foo//////bar/" );
|
||||||
|
|
||||||
if( wcscmp( can, L"/foo/bar" ) )
|
if( wcscmp( can, L"/foo/bar" ) )
|
||||||
{
|
{
|
||||||
err( L"Bug in canonical PATH code" );
|
err( L"Bug in canonical PATH code" );
|
||||||
}
|
}
|
||||||
|
|
||||||
halloc_free( context );
|
halloc_free( context );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -785,72 +785,72 @@ void perf_complete()
|
||||||
double t;
|
double t;
|
||||||
wchar_t str[3]=
|
wchar_t str[3]=
|
||||||
{
|
{
|
||||||
0, 0, 0
|
0, 0, 0
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
||||||
say( L"Testing completion performance" );
|
say( L"Testing completion performance" );
|
||||||
al_init( &out );
|
al_init( &out );
|
||||||
|
|
||||||
reader_push(L"");
|
reader_push(L"");
|
||||||
say( L"Here we go" );
|
say( L"Here we go" );
|
||||||
|
|
||||||
t1 = get_time();
|
t1 = get_time();
|
||||||
|
|
||||||
|
|
||||||
for( c=L'a'; c<=L'z'; c++ )
|
for( c=L'a'; c<=L'z'; c++ )
|
||||||
{
|
{
|
||||||
str[0]=c;
|
str[0]=c;
|
||||||
reader_set_buffer( str, 0 );
|
reader_set_buffer( str, 0 );
|
||||||
|
|
||||||
complete( str, &out );
|
complete( str, &out );
|
||||||
|
|
||||||
matches += al_get_count( &out );
|
matches += al_get_count( &out );
|
||||||
|
|
||||||
al_foreach( &out, &free );
|
al_foreach( &out, &free );
|
||||||
al_truncate( &out, 0 );
|
al_truncate( &out, 0 );
|
||||||
}
|
}
|
||||||
t2=get_time();
|
t2=get_time();
|
||||||
|
|
||||||
t = (double)(t2-t1)/(1000000*26);
|
t = (double)(t2-t1)/(1000000*26);
|
||||||
|
|
||||||
say( L"One letter command completion took %f seconds per completion, %f microseconds/match", t, (double)(t2-t1)/matches );
|
say( L"One letter command completion took %f seconds per completion, %f microseconds/match", t, (double)(t2-t1)/matches );
|
||||||
|
|
||||||
matches=0;
|
matches=0;
|
||||||
t1 = get_time();
|
t1 = get_time();
|
||||||
for( i=0; i<LAPS; i++ )
|
for( i=0; i<LAPS; i++ )
|
||||||
{
|
{
|
||||||
str[0]='a'+(rand()%26);
|
str[0]='a'+(rand()%26);
|
||||||
str[1]='a'+(rand()%26);
|
str[1]='a'+(rand()%26);
|
||||||
|
|
||||||
reader_set_buffer( str, 0 );
|
reader_set_buffer( str, 0 );
|
||||||
|
|
||||||
complete( str, &out );
|
complete( str, &out );
|
||||||
|
|
||||||
matches += al_get_count( &out );
|
matches += al_get_count( &out );
|
||||||
|
|
||||||
al_foreach( &out, &free );
|
al_foreach( &out, &free );
|
||||||
al_truncate( &out, 0 );
|
al_truncate( &out, 0 );
|
||||||
}
|
}
|
||||||
t2=get_time();
|
t2=get_time();
|
||||||
|
|
||||||
t = (double)(t2-t1)/(1000000*LAPS);
|
t = (double)(t2-t1)/(1000000*LAPS);
|
||||||
|
|
||||||
say( L"Two letter command completion took %f seconds per completion, %f microseconds/match", t, (double)(t2-t1)/matches );
|
say( L"Two letter command completion took %f seconds per completion, %f microseconds/match", t, (double)(t2-t1)/matches );
|
||||||
|
|
||||||
al_destroy( &out );
|
al_destroy( &out );
|
||||||
|
|
||||||
reader_pop();
|
reader_pop();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Main test
|
Main test
|
||||||
*/
|
*/
|
||||||
int main( int argc, char **argv )
|
int main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
|
@ -858,13 +858,13 @@ int main( int argc, char **argv )
|
||||||
srand( time( 0 ) );
|
srand( time( 0 ) );
|
||||||
|
|
||||||
program_name=L"(ignore)";
|
program_name=L"(ignore)";
|
||||||
|
|
||||||
say( L"Testing low-level functionality");
|
say( L"Testing low-level functionality");
|
||||||
say( L"Lines beginning with '(ignore):' are not errors, they are warning messages\ngenerated by the fish parser library when given broken input, and can be\nignored. All actual errors begin with 'Error:'." );
|
say( L"Lines beginning with '(ignore):' are not errors, they are warning messages\ngenerated by the fish parser library when given broken input, and can be\nignored. All actual errors begin with 'Error:'." );
|
||||||
|
|
||||||
proc_init();
|
proc_init();
|
||||||
halloc_util_init();
|
halloc_util_init();
|
||||||
event_init();
|
event_init();
|
||||||
parser_init();
|
parser_init();
|
||||||
function_init();
|
function_init();
|
||||||
builtin_init();
|
builtin_init();
|
||||||
|
@ -878,7 +878,7 @@ int main( int argc, char **argv )
|
||||||
test_parser();
|
test_parser();
|
||||||
test_expand();
|
test_expand();
|
||||||
test_path();
|
test_path();
|
||||||
|
|
||||||
say( L"Encountered %d errors in low-level tests", err_count );
|
say( L"Encountered %d errors in low-level tests", err_count );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -886,9 +886,9 @@ int main( int argc, char **argv )
|
||||||
*/
|
*/
|
||||||
// say( L"Testing performance" );
|
// say( L"Testing performance" );
|
||||||
// perf_complete();
|
// perf_complete();
|
||||||
|
|
||||||
env_destroy();
|
env_destroy();
|
||||||
reader_destroy();
|
reader_destroy();
|
||||||
parser_destroy();
|
parser_destroy();
|
||||||
function_destroy();
|
function_destroy();
|
||||||
builtin_destroy();
|
builtin_destroy();
|
||||||
|
@ -896,5 +896,5 @@ int main( int argc, char **argv )
|
||||||
event_destroy();
|
event_destroy();
|
||||||
proc_destroy();
|
proc_destroy();
|
||||||
halloc_util_destroy();
|
halloc_util_destroy();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
182
fishd.c
182
fishd.c
|
@ -78,7 +78,7 @@ time the original barrier request was sent have been received.
|
||||||
/**
|
/**
|
||||||
Maximum length of socket filename
|
Maximum length of socket filename
|
||||||
*/
|
*/
|
||||||
#ifndef UNIX_PATH_MAX
|
#ifndef UNIX_PATH_MAX
|
||||||
#define UNIX_PATH_MAX 100
|
#define UNIX_PATH_MAX 100
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ static char *get_socket_filename()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Signal handler for the term signal.
|
Signal handler for the term signal.
|
||||||
*/
|
*/
|
||||||
static void handle_term( int signal )
|
static void handle_term( int signal )
|
||||||
{
|
{
|
||||||
|
@ -192,17 +192,17 @@ static void handle_term( int signal )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Acquire the lock for the socket
|
Acquire the lock for the socket
|
||||||
Returns the name of the lock file if successful or
|
Returns the name of the lock file if successful or
|
||||||
NULL if unable to obtain lock.
|
NULL if unable to obtain lock.
|
||||||
The returned string must be free()d after unlink()ing the file to release
|
The returned string must be free()d after unlink()ing the file to release
|
||||||
the lock
|
the lock
|
||||||
*/
|
*/
|
||||||
static char *acquire_socket_lock( const char *sock_name )
|
static char *acquire_socket_lock( const char *sock_name )
|
||||||
{
|
{
|
||||||
int len = strlen( sock_name );
|
int len = strlen( sock_name );
|
||||||
char *lockfile = malloc( len + strlen( LOCKPOSTFIX ) + 1 );
|
char *lockfile = malloc( len + strlen( LOCKPOSTFIX ) + 1 );
|
||||||
|
|
||||||
if( lockfile == NULL )
|
if( lockfile == NULL )
|
||||||
{
|
{
|
||||||
wperror( L"acquire_socket_lock" );
|
wperror( L"acquire_socket_lock" );
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
|
@ -237,13 +237,13 @@ static int get_socket()
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
debug( 4, L"Acquired lockfile: %s", lockfile );
|
debug( 4, L"Acquired lockfile: %s", lockfile );
|
||||||
|
|
||||||
local.sun_family = AF_UNIX;
|
local.sun_family = AF_UNIX;
|
||||||
strcpy( local.sun_path, sock_name );
|
strcpy( local.sun_path, sock_name );
|
||||||
len = sizeof(local);
|
len = sizeof(local);
|
||||||
|
|
||||||
debug(1, L"Connect to socket at %s", sock_name);
|
debug(1, L"Connect to socket at %s", sock_name);
|
||||||
|
|
||||||
if( ( s = socket( AF_UNIX, SOCK_STREAM, 0 ) ) == -1 )
|
if( ( s = socket( AF_UNIX, SOCK_STREAM, 0 ) ) == -1 )
|
||||||
{
|
{
|
||||||
wperror( L"socket" );
|
wperror( L"socket" );
|
||||||
|
@ -262,7 +262,7 @@ static int get_socket()
|
||||||
exitcode = 0;
|
exitcode = 0;
|
||||||
goto unlock;
|
goto unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink( local.sun_path );
|
unlink( local.sun_path );
|
||||||
if( bind( s, (struct sockaddr *)&local, len ) == -1 )
|
if( bind( s, (struct sockaddr *)&local, len ) == -1 )
|
||||||
{
|
{
|
||||||
|
@ -288,9 +288,9 @@ unlock:
|
||||||
/*
|
/*
|
||||||
End critical section protected by lock
|
End critical section protected by lock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
free( lockfile );
|
free( lockfile );
|
||||||
|
|
||||||
free( sock_name );
|
free( sock_name );
|
||||||
|
|
||||||
if( doexit )
|
if( doexit )
|
||||||
|
@ -311,24 +311,24 @@ static void broadcast( int type, const wchar_t *key, const wchar_t *val )
|
||||||
|
|
||||||
if( !conn )
|
if( !conn )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
msg = create_message( type, key, val );
|
msg = create_message( type, key, val );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Don't merge these loops, or try_send_all can free the message
|
Don't merge these loops, or try_send_all can free the message
|
||||||
prematurely
|
prematurely
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for( c = conn; c; c=c->next )
|
for( c = conn; c; c=c->next )
|
||||||
{
|
{
|
||||||
msg->count++;
|
msg->count++;
|
||||||
q_put( &c->unsent, msg );
|
q_put( &c->unsent, msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( c = conn; c; c=c->next )
|
for( c = conn; c; c=c->next )
|
||||||
{
|
{
|
||||||
try_send_all( c );
|
try_send_all( c );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -345,7 +345,7 @@ static void daemonize()
|
||||||
debug( 0, L"Could not put fishd in background. Quitting" );
|
debug( 0, L"Could not put fishd in background. Quitting" );
|
||||||
wperror( L"fork" );
|
wperror( L"fork" );
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -366,19 +366,19 @@ static void daemonize()
|
||||||
sigaction( SIGTERM, &act, 0);
|
sigaction( SIGTERM, &act, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
debug( 0, L"Parent process exiting (This is normal)" );
|
debug( 0, L"Parent process exiting (This is normal)" );
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Put ourself in out own processing group
|
Put ourself in out own processing group
|
||||||
*/
|
*/
|
||||||
setsid();
|
setsid();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Close stdin and stdout. We only use stderr, anyway.
|
Close stdin and stdout. We only use stderr, anyway.
|
||||||
*/
|
*/
|
||||||
|
@ -394,7 +394,7 @@ static wchar_t *fishd_env_get( wchar_t *key )
|
||||||
{
|
{
|
||||||
char *nres, *nkey;
|
char *nres, *nkey;
|
||||||
wchar_t *res;
|
wchar_t *res;
|
||||||
|
|
||||||
nkey = wcs2str( key );
|
nkey = wcs2str( key );
|
||||||
nres = getenv( nkey );
|
nres = getenv( nkey );
|
||||||
free( nkey );
|
free( nkey );
|
||||||
|
@ -407,7 +407,7 @@ static wchar_t *fishd_env_get( wchar_t *key )
|
||||||
res = env_universal_common_get( key );
|
res = env_universal_common_get( key );
|
||||||
if( res )
|
if( res )
|
||||||
res = wcsdup( res );
|
res = wcsdup( res );
|
||||||
|
|
||||||
return env_universal_common_get( key );
|
return env_universal_common_get( key );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -423,7 +423,7 @@ static wchar_t *fishd_get_config()
|
||||||
wchar_t *xdg_dir, *home;
|
wchar_t *xdg_dir, *home;
|
||||||
int done = 0;
|
int done = 0;
|
||||||
wchar_t *res = 0;
|
wchar_t *res = 0;
|
||||||
|
|
||||||
xdg_dir = fishd_env_get( L"XDG_CONFIG_HOME" );
|
xdg_dir = fishd_env_get( L"XDG_CONFIG_HOME" );
|
||||||
if( xdg_dir )
|
if( xdg_dir )
|
||||||
{
|
{
|
||||||
|
@ -439,7 +439,7 @@ static wchar_t *fishd_get_config()
|
||||||
free( xdg_dir );
|
free( xdg_dir );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
home = fishd_env_get( L"HOME" );
|
home = fishd_env_get( L"HOME" );
|
||||||
if( home )
|
if( home )
|
||||||
{
|
{
|
||||||
|
@ -455,7 +455,7 @@ static wchar_t *fishd_get_config()
|
||||||
free( home );
|
free( home );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( done )
|
if( done )
|
||||||
{
|
{
|
||||||
return res;
|
return res;
|
||||||
|
@ -465,7 +465,7 @@ static wchar_t *fishd_get_config()
|
||||||
debug( 0, _(L"Unable to create a configuration directory for fish. Your personal settings will not be saved. Please set the $XDG_CONFIG_HOME variable to a directory where the current user has write access." ));
|
debug( 0, _(L"Unable to create a configuration directory for fish. Your personal settings will not be saved. Please set the $XDG_CONFIG_HOME variable to a directory where the current user has write access." ));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -475,22 +475,22 @@ static void load_or_save( int save)
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
wchar_t *wdir = fishd_get_config();
|
wchar_t *wdir = fishd_get_config();
|
||||||
char *dir;
|
char *dir;
|
||||||
char hostname[HOSTNAME_LEN];
|
char hostname[HOSTNAME_LEN];
|
||||||
connection_t c;
|
connection_t c;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if( !wdir )
|
if( !wdir )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dir = wcs2str( wdir );
|
dir = wcs2str( wdir );
|
||||||
|
|
||||||
free( wdir );
|
free( wdir );
|
||||||
|
|
||||||
gethostname( hostname, HOSTNAME_LEN );
|
gethostname( hostname, HOSTNAME_LEN );
|
||||||
|
|
||||||
name = malloc( strlen(dir)+ strlen(FILE)+ strlen(hostname) + 2 );
|
name = malloc( strlen(dir)+ strlen(FILE)+ strlen(hostname) + 2 );
|
||||||
strcpy( name, dir );
|
strcpy( name, dir );
|
||||||
strcat( name, "/" );
|
strcat( name, "/" );
|
||||||
|
@ -499,20 +499,20 @@ static void load_or_save( int save)
|
||||||
|
|
||||||
free( dir );
|
free( dir );
|
||||||
|
|
||||||
|
|
||||||
debug( 4, L"Open file for %s: '%s'",
|
debug( 4, L"Open file for %s: '%s'",
|
||||||
save?"saving":"loading",
|
save?"saving":"loading",
|
||||||
name );
|
name );
|
||||||
|
|
||||||
fd = open( name, save?(O_CREAT | O_TRUNC | O_WRONLY):O_RDONLY, 0600);
|
fd = open( name, save?(O_CREAT | O_TRUNC | O_WRONLY):O_RDONLY, 0600);
|
||||||
|
|
||||||
free( name );
|
free( name );
|
||||||
|
|
||||||
if( fd == -1 )
|
if( fd == -1 )
|
||||||
{
|
{
|
||||||
debug( 1, L"Could not open load/save file. No previous saves?" );
|
debug( 1, L"Could not open load/save file. No previous saves?" );
|
||||||
wperror( L"open" );
|
wperror( L"open" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
debug( 4, L"File open on fd %d", c.fd );
|
debug( 4, L"File open on fd %d", c.fd );
|
||||||
|
|
||||||
|
@ -520,14 +520,14 @@ static void load_or_save( int save)
|
||||||
|
|
||||||
if( save )
|
if( save )
|
||||||
{
|
{
|
||||||
|
|
||||||
write_loop( c.fd, SAVE_MSG, strlen(SAVE_MSG) );
|
write_loop( c.fd, SAVE_MSG, strlen(SAVE_MSG) );
|
||||||
enqueue_all( &c );
|
enqueue_all( &c );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
read_message( &c );
|
read_message( &c );
|
||||||
|
|
||||||
connection_destroy( &c );
|
connection_destroy( &c );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -553,10 +553,10 @@ static void init()
|
||||||
{
|
{
|
||||||
|
|
||||||
sock = get_socket();
|
sock = get_socket();
|
||||||
daemonize();
|
daemonize();
|
||||||
env_universal_common_init( &broadcast );
|
env_universal_common_init( &broadcast );
|
||||||
|
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -569,13 +569,13 @@ int main( int argc, char ** argv )
|
||||||
socklen_t t;
|
socklen_t t;
|
||||||
int max_fd;
|
int max_fd;
|
||||||
int update_count=0;
|
int update_count=0;
|
||||||
|
|
||||||
fd_set read_fd, write_fd;
|
fd_set read_fd, write_fd;
|
||||||
|
|
||||||
halloc_util_init();
|
halloc_util_init();
|
||||||
|
|
||||||
program_name=L"fishd";
|
program_name=L"fishd";
|
||||||
wsetlocale( LC_ALL, L"" );
|
wsetlocale( LC_ALL, L"" );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Parse options
|
Parse options
|
||||||
|
@ -586,57 +586,57 @@ int main( int argc, char ** argv )
|
||||||
long_options[] =
|
long_options[] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
"help", no_argument, 0, 'h'
|
"help", no_argument, 0, 'h'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"version", no_argument, 0, 'v'
|
"version", no_argument, 0, 'v'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
0, 0, 0, 0
|
0, 0, 0, 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
int opt_index = 0;
|
int opt_index = 0;
|
||||||
|
|
||||||
int opt = getopt_long( argc,
|
int opt = getopt_long( argc,
|
||||||
argv,
|
argv,
|
||||||
GETOPT_STRING,
|
GETOPT_STRING,
|
||||||
long_options,
|
long_options,
|
||||||
&opt_index );
|
&opt_index );
|
||||||
|
|
||||||
if( opt == -1 )
|
if( opt == -1 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch( opt )
|
switch( opt )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
print_help( argv[0], 1 );
|
print_help( argv[0], 1 );
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
debug( 0, L"%ls, version %s\n", program_name, PACKAGE_VERSION );
|
debug( 0, L"%ls, version %s\n", program_name, PACKAGE_VERSION );
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init();
|
init();
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
connection_t *c;
|
connection_t *c;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
t = sizeof( remote );
|
t = sizeof( remote );
|
||||||
|
|
||||||
FD_ZERO( &read_fd );
|
FD_ZERO( &read_fd );
|
||||||
FD_ZERO( &write_fd );
|
FD_ZERO( &write_fd );
|
||||||
FD_SET( sock, &read_fd );
|
FD_SET( sock, &read_fd );
|
||||||
|
@ -645,7 +645,7 @@ int main( int argc, char ** argv )
|
||||||
{
|
{
|
||||||
FD_SET( c->fd, &read_fd );
|
FD_SET( c->fd, &read_fd );
|
||||||
max_fd = maxi( max_fd, c->fd+1);
|
max_fd = maxi( max_fd, c->fd+1);
|
||||||
|
|
||||||
if( ! q_empty( &c->unsent ) )
|
if( ! q_empty( &c->unsent ) )
|
||||||
{
|
{
|
||||||
FD_SET( c->fd, &write_fd );
|
FD_SET( c->fd, &write_fd );
|
||||||
|
@ -661,22 +661,22 @@ int main( int argc, char ** argv )
|
||||||
save();
|
save();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( res != -1 )
|
if( res != -1 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if( errno != EINTR )
|
if( errno != EINTR )
|
||||||
{
|
{
|
||||||
wperror( L"select" );
|
wperror( L"select" );
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( FD_ISSET( sock, &read_fd ) )
|
if( FD_ISSET( sock, &read_fd ) )
|
||||||
{
|
{
|
||||||
if( (child_socket =
|
if( (child_socket =
|
||||||
accept( sock,
|
accept( sock,
|
||||||
(struct sockaddr *)&remote,
|
(struct sockaddr *)&remote,
|
||||||
&t) ) == -1) {
|
&t) ) == -1) {
|
||||||
wperror( L"accept" );
|
wperror( L"accept" );
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -688,20 +688,20 @@ int main( int argc, char ** argv )
|
||||||
if( fcntl( child_socket, F_SETFL, O_NONBLOCK ) != 0 )
|
if( fcntl( child_socket, F_SETFL, O_NONBLOCK ) != 0 )
|
||||||
{
|
{
|
||||||
wperror( L"fcntl" );
|
wperror( L"fcntl" );
|
||||||
close( child_socket );
|
close( child_socket );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
connection_t *new = malloc( sizeof(connection_t));
|
connection_t *new = malloc( sizeof(connection_t));
|
||||||
connection_init( new, child_socket );
|
connection_init( new, child_socket );
|
||||||
new->next = conn;
|
new->next = conn;
|
||||||
send( new->fd, GREETING, strlen(GREETING), MSG_DONTWAIT );
|
send( new->fd, GREETING, strlen(GREETING), MSG_DONTWAIT );
|
||||||
enqueue_all( new );
|
enqueue_all( new );
|
||||||
conn=new;
|
conn=new;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for( c=conn; c; c=c->next )
|
for( c=conn; c; c=c->next )
|
||||||
{
|
{
|
||||||
if( FD_ISSET( c->fd, &write_fd ) )
|
if( FD_ISSET( c->fd, &write_fd ) )
|
||||||
|
@ -709,7 +709,7 @@ int main( int argc, char ** argv )
|
||||||
try_send_all( c );
|
try_send_all( c );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for( c=conn; c; c=c->next )
|
for( c=conn; c; c=c->next )
|
||||||
{
|
{
|
||||||
if( FD_ISSET( c->fd, &read_fd ) )
|
if( FD_ISSET( c->fd, &read_fd ) )
|
||||||
|
@ -728,10 +728,10 @@ int main( int argc, char ** argv )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connection_t *prev=0;
|
connection_t *prev=0;
|
||||||
c=conn;
|
c=conn;
|
||||||
|
|
||||||
while( c )
|
while( c )
|
||||||
{
|
{
|
||||||
if( c->killme )
|
if( c->killme )
|
||||||
|
@ -745,7 +745,7 @@ int main( int argc, char ** argv )
|
||||||
if( !msg->count )
|
if( !msg->count )
|
||||||
free( msg );
|
free( msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
connection_destroy( c );
|
connection_destroy( c );
|
||||||
if( prev )
|
if( prev )
|
||||||
{
|
{
|
||||||
|
@ -755,11 +755,11 @@ int main( int argc, char ** argv )
|
||||||
{
|
{
|
||||||
conn=c->next;
|
conn=c->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(c);
|
free(c);
|
||||||
|
|
||||||
c=(prev?prev->next:conn);
|
c=(prev?prev->next:conn);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -771,10 +771,10 @@ int main( int argc, char ** argv )
|
||||||
if( !conn )
|
if( !conn )
|
||||||
{
|
{
|
||||||
debug( 0, L"No more clients. Quitting" );
|
debug( 0, L"No more clients. Quitting" );
|
||||||
save();
|
save();
|
||||||
env_universal_common_destroy();
|
env_universal_common_destroy();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
halloc_util_destroy();
|
halloc_util_destroy();
|
||||||
|
|
141
function.c
141
function.c
|
@ -43,7 +43,7 @@ typedef struct
|
||||||
/** Function definition */
|
/** Function definition */
|
||||||
wchar_t *definition;
|
wchar_t *definition;
|
||||||
/** Function description */
|
/** Function description */
|
||||||
wchar_t *description;
|
wchar_t *description;
|
||||||
/**
|
/**
|
||||||
File where this function was defined
|
File where this function was defined
|
||||||
*/
|
*/
|
||||||
|
@ -51,14 +51,14 @@ typedef struct
|
||||||
/**
|
/**
|
||||||
Line where definition started
|
Line where definition started
|
||||||
*/
|
*/
|
||||||
int definition_offset;
|
int definition_offset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
List of all named arguments for this function
|
List of all named arguments for this function
|
||||||
*/
|
*/
|
||||||
array_list_t *named_arguments;
|
array_list_t *named_arguments;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Flag for specifying that this function was automatically loaded
|
Flag for specifying that this function was automatically loaded
|
||||||
*/
|
*/
|
||||||
|
@ -96,8 +96,8 @@ static int load( const wchar_t *name )
|
||||||
data = (function_internal_data_t *)hash_get( &function, name );
|
data = (function_internal_data_t *)hash_get( &function, name );
|
||||||
if( data && !data->is_autoload )
|
if( data && !data->is_autoload )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
is_autoload = 1;
|
is_autoload = 1;
|
||||||
res = parse_util_load( name,
|
res = parse_util_load( name,
|
||||||
L"fish_function_path",
|
L"fish_function_path",
|
||||||
&function_remove,
|
&function_remove,
|
||||||
|
@ -113,13 +113,13 @@ static int load( const wchar_t *name )
|
||||||
static void autoload_names( array_list_t *out, int get_hidden )
|
static void autoload_names( array_list_t *out, int get_hidden )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
array_list_t path_list;
|
array_list_t path_list;
|
||||||
const wchar_t *path_var = env_get( L"fish_function_path" );
|
const wchar_t *path_var = env_get( L"fish_function_path" );
|
||||||
|
|
||||||
if( ! path_var )
|
if( ! path_var )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
al_init( &path_list );
|
al_init( &path_list );
|
||||||
|
|
||||||
tokenize_variable_array( path_var, &path_list );
|
tokenize_variable_array( path_var, &path_list );
|
||||||
|
@ -129,7 +129,7 @@ static void autoload_names( array_list_t *out, int get_hidden )
|
||||||
DIR *dir = wopendir( ndir );
|
DIR *dir = wopendir( ndir );
|
||||||
if( !dir )
|
if( !dir )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
struct wdirent *next;
|
struct wdirent *next;
|
||||||
while( (next=wreaddir(dir))!=0 )
|
while( (next=wreaddir(dir))!=0 )
|
||||||
{
|
{
|
||||||
|
@ -137,7 +137,7 @@ static void autoload_names( array_list_t *out, int get_hidden )
|
||||||
wchar_t *suffix;
|
wchar_t *suffix;
|
||||||
if( !get_hidden && fn[0] == L'_' )
|
if( !get_hidden && fn[0] == L'_' )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
suffix = wcsrchr( fn, L'.' );
|
suffix = wcsrchr( fn, L'.' );
|
||||||
if( suffix && (wcscmp( suffix, L".fish" ) == 0 ) )
|
if( suffix && (wcscmp( suffix, L".fish" ) == 0 ) )
|
||||||
{
|
{
|
||||||
|
@ -148,7 +148,7 @@ static void autoload_names( array_list_t *out, int get_hidden )
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
al_push( out, dup );
|
al_push( out, dup );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
}
|
}
|
||||||
al_foreach( &path_list, &free );
|
al_foreach( &path_list, &free );
|
||||||
|
@ -182,12 +182,12 @@ void function_add( function_data_t *data )
|
||||||
int i;
|
int i;
|
||||||
wchar_t *cmd_end;
|
wchar_t *cmd_end;
|
||||||
function_internal_data_t *d;
|
function_internal_data_t *d;
|
||||||
|
|
||||||
CHECK( data->name, );
|
CHECK( data->name, );
|
||||||
CHECK( data->definition, );
|
CHECK( data->definition, );
|
||||||
|
|
||||||
function_remove( data->name );
|
function_remove( data->name );
|
||||||
|
|
||||||
d = halloc( 0, sizeof( function_internal_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->definition_offset = parse_util_lineno( parser_get_buffer(), current_block->tok_pos )-1;
|
||||||
d->definition = halloc_wcsdup( d, data->definition );
|
d->definition = halloc_wcsdup( d, data->definition );
|
||||||
|
@ -201,31 +201,68 @@ void function_add( function_data_t *data )
|
||||||
al_push( d->named_arguments, halloc_wcsdup( d, (wchar_t *)al_get( data->named_arguments, i ) ) );
|
al_push( d->named_arguments, halloc_wcsdup( d, (wchar_t *)al_get( data->named_arguments, i ) ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_end = d->definition + wcslen(d->definition)-1;
|
cmd_end = d->definition + wcslen(d->definition)-1;
|
||||||
|
|
||||||
d->description = data->description?halloc_wcsdup( d, data->description ):0;
|
d->description = data->description?halloc_wcsdup( d, data->description ):0;
|
||||||
d->definition_file = intern(reader_current_filename());
|
d->definition_file = intern(reader_current_filename());
|
||||||
d->is_autoload = is_autoload;
|
d->is_autoload = is_autoload;
|
||||||
d->shadows = data->shadows;
|
d->shadows = data->shadows;
|
||||||
|
|
||||||
hash_put( &function, intern(data->name), d );
|
hash_put( &function, intern(data->name), d );
|
||||||
|
|
||||||
for( i=0; i<al_get_count( data->events ); i++ )
|
for( i=0; i<al_get_count( data->events ); i++ )
|
||||||
{
|
{
|
||||||
event_add_handler( (event_t *)al_get( data->events, i ) );
|
event_add_handler( (event_t *)al_get( data->events, i ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int function_copy( const wchar_t *name, const wchar_t *new_name )
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
function_internal_data_t *d, *orig_d;
|
||||||
|
|
||||||
|
CHECK( name, 0 );
|
||||||
|
CHECK( new_name, 0 );
|
||||||
|
|
||||||
|
orig_d = (function_internal_data_t *)hash_get(&function, name);
|
||||||
|
if( !orig_d )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
d = halloc(0, sizeof( function_internal_data_t ) );
|
||||||
|
d->definition_offset = orig_d->definition_offset;
|
||||||
|
d->definition = halloc_wcsdup( d, orig_d->definition );
|
||||||
|
if( orig_d->named_arguments )
|
||||||
|
{
|
||||||
|
d->named_arguments = al_halloc( d );
|
||||||
|
for( i=0; i<al_get_count( orig_d->named_arguments ); i++ )
|
||||||
|
{
|
||||||
|
al_push( d->named_arguments, halloc_wcsdup( d, (wchar_t *)al_get( orig_d->named_arguments, i ) ) );
|
||||||
|
}
|
||||||
|
d->description = orig_d->description?halloc_wcsdup(d, orig_d->description):0;
|
||||||
|
d->shadows = orig_d->shadows;
|
||||||
|
|
||||||
|
// This new instance of the function shouldn't be tied to the def
|
||||||
|
// file of the original.
|
||||||
|
d->definition_file = 0;
|
||||||
|
d->is_autoload = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
hash_put( &function, intern(new_name), d );
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int function_exists( const wchar_t *cmd )
|
int function_exists( const wchar_t *cmd )
|
||||||
{
|
{
|
||||||
|
|
||||||
CHECK( cmd, 0 );
|
CHECK( cmd, 0 );
|
||||||
|
|
||||||
if( parser_keywords_is_reserved(cmd) )
|
if( parser_keywords_is_reserved(cmd) )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
load( cmd );
|
load( cmd );
|
||||||
return (hash_get(&function, cmd) != 0 );
|
return (hash_get(&function, cmd) != 0 );
|
||||||
}
|
}
|
||||||
|
@ -236,7 +273,7 @@ void function_remove( const wchar_t *name )
|
||||||
void *dv;
|
void *dv;
|
||||||
function_internal_data_t *d;
|
function_internal_data_t *d;
|
||||||
event_t ev;
|
event_t ev;
|
||||||
|
|
||||||
CHECK( name, );
|
CHECK( name, );
|
||||||
|
|
||||||
hash_remove( &function,
|
hash_remove( &function,
|
||||||
|
@ -245,12 +282,12 @@ void function_remove( const wchar_t *name )
|
||||||
&dv );
|
&dv );
|
||||||
|
|
||||||
d=(function_internal_data_t *)dv;
|
d=(function_internal_data_t *)dv;
|
||||||
|
|
||||||
if( !key )
|
if( !key )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ev.type=EVENT_ANY;
|
ev.type=EVENT_ANY;
|
||||||
ev.function_name=name;
|
ev.function_name=name;
|
||||||
event_remove( &ev );
|
event_remove( &ev );
|
||||||
|
|
||||||
halloc_free( d );
|
halloc_free( d );
|
||||||
|
@ -265,13 +302,13 @@ void function_remove( const wchar_t *name )
|
||||||
parse_util_unload( name, L"fish_function_path", 0 );
|
parse_util_unload( name, L"fish_function_path", 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const wchar_t *function_get_definition( const wchar_t *name )
|
const wchar_t *function_get_definition( const wchar_t *name )
|
||||||
{
|
{
|
||||||
function_internal_data_t *data;
|
function_internal_data_t *data;
|
||||||
|
|
||||||
CHECK( name, 0 );
|
CHECK( name, 0 );
|
||||||
|
|
||||||
load( name );
|
load( name );
|
||||||
data = (function_internal_data_t *)hash_get( &function, name );
|
data = (function_internal_data_t *)hash_get( &function, name );
|
||||||
if( data == 0 )
|
if( data == 0 )
|
||||||
|
@ -282,9 +319,9 @@ const wchar_t *function_get_definition( const wchar_t *name )
|
||||||
array_list_t *function_get_named_arguments( const wchar_t *name )
|
array_list_t *function_get_named_arguments( const wchar_t *name )
|
||||||
{
|
{
|
||||||
function_internal_data_t *data;
|
function_internal_data_t *data;
|
||||||
|
|
||||||
CHECK( name, 0 );
|
CHECK( name, 0 );
|
||||||
|
|
||||||
load( name );
|
load( name );
|
||||||
data = (function_internal_data_t *)hash_get( &function, name );
|
data = (function_internal_data_t *)hash_get( &function, name );
|
||||||
if( data == 0 )
|
if( data == 0 )
|
||||||
|
@ -295,9 +332,9 @@ array_list_t *function_get_named_arguments( const wchar_t *name )
|
||||||
int function_get_shadows( const wchar_t *name )
|
int function_get_shadows( const wchar_t *name )
|
||||||
{
|
{
|
||||||
function_internal_data_t *data;
|
function_internal_data_t *data;
|
||||||
|
|
||||||
CHECK( name, 0 );
|
CHECK( name, 0 );
|
||||||
|
|
||||||
load( name );
|
load( name );
|
||||||
data = (function_internal_data_t *)hash_get( &function, name );
|
data = (function_internal_data_t *)hash_get( &function, name );
|
||||||
if( data == 0 )
|
if( data == 0 )
|
||||||
|
@ -305,28 +342,28 @@ int function_get_shadows( const wchar_t *name )
|
||||||
return data->shadows;
|
return data->shadows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const wchar_t *function_get_desc( const wchar_t *name )
|
const wchar_t *function_get_desc( const wchar_t *name )
|
||||||
{
|
{
|
||||||
function_internal_data_t *data;
|
function_internal_data_t *data;
|
||||||
|
|
||||||
CHECK( name, 0 );
|
CHECK( name, 0 );
|
||||||
|
|
||||||
load( name );
|
load( name );
|
||||||
data = (function_internal_data_t *)hash_get( &function, name );
|
data = (function_internal_data_t *)hash_get( &function, name );
|
||||||
if( data == 0 )
|
if( data == 0 )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return _(data->description);
|
return _(data->description);
|
||||||
}
|
}
|
||||||
|
|
||||||
void function_set_desc( const wchar_t *name, const wchar_t *desc )
|
void function_set_desc( const wchar_t *name, const wchar_t *desc )
|
||||||
{
|
{
|
||||||
function_internal_data_t *data;
|
function_internal_data_t *data;
|
||||||
|
|
||||||
CHECK( name, );
|
CHECK( name, );
|
||||||
CHECK( desc, );
|
CHECK( desc, );
|
||||||
|
|
||||||
load( name );
|
load( name );
|
||||||
data = (function_internal_data_t *)hash_get( &function, name );
|
data = (function_internal_data_t *)hash_get( &function, name );
|
||||||
if( data == 0 )
|
if( data == 0 )
|
||||||
|
@ -344,7 +381,7 @@ static int al_contains_str( array_list_t *list, const wchar_t * str )
|
||||||
|
|
||||||
CHECK( list, 0 );
|
CHECK( list, 0 );
|
||||||
CHECK( str, 0 );
|
CHECK( str, 0 );
|
||||||
|
|
||||||
for( i=0; i<al_get_count( list ); i++ )
|
for( i=0; i<al_get_count( list ); i++ )
|
||||||
{
|
{
|
||||||
if( wcscmp( al_get( list, i ), str) == 0 )
|
if( wcscmp( al_get( list, i ), str) == 0 )
|
||||||
|
@ -354,9 +391,9 @@ static int al_contains_str( array_list_t *list, const wchar_t * str )
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Helper function for removing hidden functions
|
Helper function for removing hidden functions
|
||||||
*/
|
*/
|
||||||
static void get_names_internal( void *key,
|
static void get_names_internal( void *key,
|
||||||
void *val,
|
void *val,
|
||||||
|
@ -370,14 +407,14 @@ static void get_names_internal( void *key,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Helper function for removing hidden functions
|
Helper function for removing hidden functions
|
||||||
*/
|
*/
|
||||||
static void get_names_internal_all( void *key,
|
static void get_names_internal_all( void *key,
|
||||||
void *val,
|
void *val,
|
||||||
void *aux )
|
void *aux )
|
||||||
{
|
{
|
||||||
wchar_t *name = (wchar_t *)key;
|
wchar_t *name = (wchar_t *)key;
|
||||||
|
|
||||||
if( !al_contains_str( (array_list_t *)aux, name ) )
|
if( !al_contains_str( (array_list_t *)aux, name ) )
|
||||||
{
|
{
|
||||||
al_push( (array_list_t *)aux, name );
|
al_push( (array_list_t *)aux, name );
|
||||||
|
@ -387,9 +424,9 @@ static void get_names_internal_all( void *key,
|
||||||
void function_get_names( array_list_t *list, int get_hidden )
|
void function_get_names( array_list_t *list, int get_hidden )
|
||||||
{
|
{
|
||||||
CHECK( list, );
|
CHECK( list, );
|
||||||
|
|
||||||
autoload_names( list, get_hidden );
|
autoload_names( list, get_hidden );
|
||||||
|
|
||||||
if( get_hidden )
|
if( get_hidden )
|
||||||
{
|
{
|
||||||
hash_foreach2( &function, &get_names_internal_all, list );
|
hash_foreach2( &function, &get_names_internal_all, list );
|
||||||
|
@ -398,7 +435,7 @@ void function_get_names( array_list_t *list, int get_hidden )
|
||||||
{
|
{
|
||||||
hash_foreach2( &function, &get_names_internal, list );
|
hash_foreach2( &function, &get_names_internal, list );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const wchar_t *function_get_definition_file( const wchar_t *name )
|
const wchar_t *function_get_definition_file( const wchar_t *name )
|
||||||
|
@ -406,11 +443,11 @@ const wchar_t *function_get_definition_file( const wchar_t *name )
|
||||||
function_internal_data_t *data;
|
function_internal_data_t *data;
|
||||||
|
|
||||||
CHECK( name, 0 );
|
CHECK( name, 0 );
|
||||||
|
|
||||||
data = (function_internal_data_t *)hash_get( &function, name );
|
data = (function_internal_data_t *)hash_get( &function, name );
|
||||||
if( data == 0 )
|
if( data == 0 )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return data->definition_file;
|
return data->definition_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,11 +457,11 @@ int function_get_definition_offset( const wchar_t *name )
|
||||||
function_internal_data_t *data;
|
function_internal_data_t *data;
|
||||||
|
|
||||||
CHECK( name, -1 );
|
CHECK( name, -1 );
|
||||||
|
|
||||||
data = (function_internal_data_t *)hash_get( &function, name );
|
data = (function_internal_data_t *)hash_get( &function, name );
|
||||||
if( data == 0 )
|
if( data == 0 )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return data->definition_offset;
|
return data->definition_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
function.h
14
function.h
|
@ -1,4 +1,4 @@
|
||||||
/** \file function.h
|
/** \file function.h
|
||||||
|
|
||||||
Prototypes for functions for storing and retrieving function
|
Prototypes for functions for storing and retrieving function
|
||||||
information. These functions also take care of autoloading
|
information. These functions also take care of autoloading
|
||||||
|
@ -53,7 +53,7 @@ typedef struct function_data
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initialize function data
|
Initialize function data
|
||||||
*/
|
*/
|
||||||
void function_init();
|
void function_init();
|
||||||
|
|
||||||
|
@ -96,11 +96,11 @@ int function_exists( const wchar_t *name );
|
||||||
/**
|
/**
|
||||||
Insert all function names into l. These are not copies of the
|
Insert all function names into l. These are not copies of the
|
||||||
strings and should not be freed after use.
|
strings and should not be freed after use.
|
||||||
|
|
||||||
\param list the list to add the names to
|
\param list the list to add the names to
|
||||||
\param get_hidden whether to include hidden functions, i.e. ones starting with an underscore
|
\param get_hidden whether to include hidden functions, i.e. ones starting with an underscore
|
||||||
*/
|
*/
|
||||||
void function_get_names( array_list_t *list,
|
void function_get_names( array_list_t *list,
|
||||||
int get_hidden );
|
int get_hidden );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,4 +131,10 @@ array_list_t *function_get_named_arguments( const wchar_t *name );
|
||||||
*/
|
*/
|
||||||
int function_get_shadows( const wchar_t *name );
|
int function_get_shadows( const wchar_t *name );
|
||||||
|
|
||||||
|
/**
|
||||||
|
Creates a new function using the same definition as the specified function.
|
||||||
|
Returns non-zero if copy is successful.
|
||||||
|
*/
|
||||||
|
int function_copy( const wchar_t *name, const wchar_t *new_name );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
38
halloc.c
38
halloc.c
|
@ -125,37 +125,37 @@ static void halloc_report()
|
||||||
{
|
{
|
||||||
if( getpid() == pid )
|
if( getpid() == pid )
|
||||||
{
|
{
|
||||||
debug( 1, L"%d parents, %d children with average child size of %.2f bytes caused %d allocs, average spill of %.2f bytes",
|
debug( 1, L"%d parents, %d children with average child size of %.2f bytes caused %d allocs, average spill of %.2f bytes",
|
||||||
parent_count, child_count, (double)child_size/child_count,
|
parent_count, child_count, (double)child_size/child_count,
|
||||||
parent_count+alloc_count, (double)alloc_spill/(parent_count+alloc_count) );
|
parent_count+alloc_count, (double)alloc_spill/(parent_count+alloc_count) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void *halloc( void *context, size_t size )
|
void *halloc( void *context, size_t size )
|
||||||
{
|
{
|
||||||
halloc_t *me, *parent;
|
halloc_t *me, *parent;
|
||||||
if( context )
|
if( context )
|
||||||
{
|
{
|
||||||
char *res;
|
char *res;
|
||||||
char *aligned;
|
char *aligned;
|
||||||
|
|
||||||
#ifdef HALLOC_DEBUG
|
#ifdef HALLOC_DEBUG
|
||||||
|
|
||||||
if( !child_count )
|
if( !child_count )
|
||||||
{
|
{
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
atexit( &halloc_report );
|
atexit( &halloc_report );
|
||||||
}
|
}
|
||||||
|
|
||||||
child_count++;
|
child_count++;
|
||||||
child_size += size;
|
child_size += size;
|
||||||
#endif
|
#endif
|
||||||
parent = halloc_from_data( context );
|
parent = halloc_from_data( context );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Align memory address
|
Align memory address
|
||||||
*/
|
*/
|
||||||
aligned = align_ptr( parent->scratch );
|
aligned = align_ptr( parent->scratch );
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ void *halloc( void *context, size_t size )
|
||||||
|
|
||||||
if( parent->scratch_free < 0 )
|
if( parent->scratch_free < 0 )
|
||||||
parent->scratch_free=0;
|
parent->scratch_free=0;
|
||||||
|
|
||||||
parent->scratch = aligned;
|
parent->scratch = aligned;
|
||||||
|
|
||||||
if( size <= parent->scratch_free )
|
if( size <= parent->scratch_free )
|
||||||
|
@ -177,8 +177,8 @@ void *halloc( void *context, size_t size )
|
||||||
|
|
||||||
#ifdef HALLOC_DEBUG
|
#ifdef HALLOC_DEBUG
|
||||||
alloc_count++;
|
alloc_count++;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( parent->scratch_free < HALLOC_SCRAP_SIZE )
|
if( parent->scratch_free < HALLOC_SCRAP_SIZE )
|
||||||
{
|
{
|
||||||
#ifdef HALLOC_DEBUG
|
#ifdef HALLOC_DEBUG
|
||||||
|
@ -198,23 +198,23 @@ void *halloc( void *context, size_t size )
|
||||||
}
|
}
|
||||||
al_push_func( &parent->children, &late_free );
|
al_push_func( &parent->children, &late_free );
|
||||||
al_push( &parent->children, res );
|
al_push( &parent->children, res );
|
||||||
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
me = (halloc_t *)calloc( 1, align_sz(sizeof(halloc_t)) + align_sz(size) + HALLOC_BLOCK_SIZE );
|
me = (halloc_t *)calloc( 1, align_sz(sizeof(halloc_t)) + align_sz(size) + HALLOC_BLOCK_SIZE );
|
||||||
|
|
||||||
if( !me )
|
if( !me )
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
#ifdef HALLOC_DEBUG
|
#ifdef HALLOC_DEBUG
|
||||||
parent_count++;
|
parent_count++;
|
||||||
#endif
|
#endif
|
||||||
me->scratch = ((char *)me) + align_sz(sizeof(halloc_t)) + align_sz(size);
|
me->scratch = ((char *)me) + align_sz(sizeof(halloc_t)) + align_sz(size);
|
||||||
me->scratch_free = HALLOC_BLOCK_SIZE;
|
me->scratch_free = HALLOC_BLOCK_SIZE;
|
||||||
|
|
||||||
al_init( &me->children );
|
al_init( &me->children );
|
||||||
return ((char *)me) + align_sz(sizeof(halloc_t));
|
return ((char *)me) + align_sz(sizeof(halloc_t));
|
||||||
}
|
}
|
||||||
|
@ -225,7 +225,7 @@ void halloc_register_function( void *context, void (*func)(void *), void *data )
|
||||||
halloc_t *me;
|
halloc_t *me;
|
||||||
if( !context )
|
if( !context )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
me = halloc_from_data( context );
|
me = halloc_from_data( context );
|
||||||
al_push_func( &me->children, func );
|
al_push_func( &me->children, func );
|
||||||
al_push( &me->children, data );
|
al_push( &me->children, data );
|
||||||
|
@ -235,11 +235,11 @@ void halloc_free( void *context )
|
||||||
{
|
{
|
||||||
halloc_t *me;
|
halloc_t *me;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if( !context )
|
if( !context )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
me = halloc_from_data( context );
|
me = halloc_from_data( context );
|
||||||
|
|
||||||
#ifdef HALLOC_DEBUG
|
#ifdef HALLOC_DEBUG
|
||||||
|
|
2
halloc.h
2
halloc.h
|
@ -1,4 +1,4 @@
|
||||||
/** \file halloc.h
|
/** \file halloc.h
|
||||||
|
|
||||||
A hierarchical memory allocation system. Works mostly like talloc
|
A hierarchical memory allocation system. Works mostly like talloc
|
||||||
used in Samba, except that an arbitrary block allocated with
|
used in Samba, except that an arbitrary block allocated with
|
||||||
|
|
|
@ -69,7 +69,7 @@ void *halloc_register( void *context, void *data )
|
||||||
{
|
{
|
||||||
if( !data )
|
if( !data )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
halloc_register_function( context, &free, data );
|
halloc_register_function( context, &free, data );
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ wchar_t *halloc_wcsdup( void *context, const wchar_t *in )
|
||||||
{
|
{
|
||||||
size_t len=wcslen(in);
|
size_t len=wcslen(in);
|
||||||
wchar_t *out = halloc( context, sizeof( wchar_t)*(len+1));
|
wchar_t *out = halloc( context, sizeof( wchar_t)*(len+1));
|
||||||
|
|
||||||
if( out == 0 )
|
if( out == 0 )
|
||||||
{
|
{
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
|
@ -95,6 +95,6 @@ wchar_t *halloc_wcsndup( void * context, const wchar_t *in, int c )
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
}
|
}
|
||||||
wcslcpy( res, in, c+1 );
|
wcslcpy( res, in, c+1 );
|
||||||
res[c] = L'\0';
|
res[c] = L'\0';
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
328
highlight.c
328
highlight.c
|
@ -41,15 +41,15 @@
|
||||||
*/
|
*/
|
||||||
#define VAR_COUNT ( sizeof(highlight_var)/sizeof(wchar_t *) )
|
#define VAR_COUNT ( sizeof(highlight_var)/sizeof(wchar_t *) )
|
||||||
|
|
||||||
static void highlight_universal_internal( wchar_t * buff,
|
static void highlight_universal_internal( wchar_t * buff,
|
||||||
int *color,
|
int *color,
|
||||||
int pos,
|
int pos,
|
||||||
array_list_t *error );
|
array_list_t *error );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The environment variables used to specify the color of different tokens.
|
The environment variables used to specify the color of different tokens.
|
||||||
*/
|
*/
|
||||||
static wchar_t *highlight_var[] =
|
static wchar_t *highlight_var[] =
|
||||||
{
|
{
|
||||||
L"fish_color_normal",
|
L"fish_color_normal",
|
||||||
L"fish_color_error",
|
L"fish_color_error",
|
||||||
|
@ -68,7 +68,7 @@ static wchar_t *highlight_var[] =
|
||||||
;
|
;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Tests if the specified string is the prefix of any valid path in the system.
|
Tests if the specified string is the prefix of any valid path in the system.
|
||||||
|
|
||||||
\return zero it this is not a valid prefix, non-zero otherwise
|
\return zero it this is not a valid prefix, non-zero otherwise
|
||||||
*/
|
*/
|
||||||
|
@ -85,15 +85,15 @@ static int is_potential_path( const wchar_t *path )
|
||||||
if( tilde )
|
if( tilde )
|
||||||
{
|
{
|
||||||
halloc_register( context, tilde );
|
halloc_register( context, tilde );
|
||||||
|
|
||||||
unescaped = unescape( tilde, 1 );
|
unescaped = unescape( tilde, 1 );
|
||||||
if( unescaped )
|
if( unescaped )
|
||||||
{
|
{
|
||||||
|
|
||||||
// debug( 1, L"%ls -> %ls ->%ls", path, tilde, unescaped );
|
// debug( 1, L"%ls -> %ls ->%ls", path, tilde, unescaped );
|
||||||
|
|
||||||
halloc_register( context, unescaped );
|
halloc_register( context, unescaped );
|
||||||
|
|
||||||
for( in = out = unescaped; *in; in++ )
|
for( in = out = unescaped; *in; in++ )
|
||||||
{
|
{
|
||||||
switch( *in )
|
switch( *in )
|
||||||
|
@ -109,25 +109,25 @@ static int is_potential_path( const wchar_t *path )
|
||||||
case ANY_STRING_RECURSIVE:
|
case ANY_STRING_RECURSIVE:
|
||||||
{
|
{
|
||||||
has_magic = 1;
|
has_magic = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case INTERNAL_SEPARATOR:
|
case INTERNAL_SEPARATOR:
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
*(out++) = *in;
|
*(out++) = *in;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
*out = 0;
|
*out = 0;
|
||||||
|
|
||||||
if( !has_magic && wcslen( unescaped ) )
|
if( !has_magic && wcslen( unescaped ) )
|
||||||
{
|
{
|
||||||
int must_be_dir = 0;
|
int must_be_dir = 0;
|
||||||
|
@ -146,10 +146,10 @@ static int is_potential_path( const wchar_t *path )
|
||||||
{
|
{
|
||||||
wchar_t *dir_name, *base;
|
wchar_t *dir_name, *base;
|
||||||
struct wdirent *ent;
|
struct wdirent *ent;
|
||||||
|
|
||||||
dir_name = wdirname( halloc_wcsdup(context, unescaped) );
|
dir_name = wdirname( halloc_wcsdup(context, unescaped) );
|
||||||
base = wbasename( halloc_wcsdup(context, unescaped) );
|
base = wbasename( halloc_wcsdup(context, unescaped) );
|
||||||
|
|
||||||
if( (wcscmp( dir_name, L"/" ) == 0 ) &&
|
if( (wcscmp( dir_name, L"/" ) == 0 ) &&
|
||||||
(wcscmp( base, L"/" ) == 0 ) )
|
(wcscmp( base, L"/" ) == 0 ) )
|
||||||
{
|
{
|
||||||
|
@ -157,7 +157,7 @@ static int is_potential_path( const wchar_t *path )
|
||||||
}
|
}
|
||||||
else if( (dir = wopendir( dir_name )) )
|
else if( (dir = wopendir( dir_name )) )
|
||||||
{
|
{
|
||||||
|
|
||||||
while( (ent = wreaddir( dir )) )
|
while( (ent = wreaddir( dir )) )
|
||||||
{
|
{
|
||||||
if( wcsncmp( ent->d_name, base, wcslen(base) ) == 0 )
|
if( wcsncmp( ent->d_name, base, wcslen(base) ) == 0 )
|
||||||
|
@ -166,19 +166,19 @@ static int is_potential_path( const wchar_t *path )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir( dir );
|
closedir( dir );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
halloc_free( context );
|
halloc_free( context );
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ int highlight_get_color( int highlight )
|
||||||
int i;
|
int i;
|
||||||
int idx=0;
|
int idx=0;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
if( highlight < 0 )
|
if( highlight < 0 )
|
||||||
return FISH_COLOR_NORMAL;
|
return FISH_COLOR_NORMAL;
|
||||||
if( highlight >= (1<<VAR_COUNT) )
|
if( highlight >= (1<<VAR_COUNT) )
|
||||||
|
@ -202,34 +202,34 @@ int highlight_get_color( int highlight )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t *val = env_get( highlight_var[idx]);
|
wchar_t *val = env_get( highlight_var[idx]);
|
||||||
|
|
||||||
// debug( 1, L"%d -> %d -> %ls", highlight, idx, val );
|
// debug( 1, L"%d -> %d -> %ls", highlight, idx, val );
|
||||||
|
|
||||||
if( val == 0 )
|
if( val == 0 )
|
||||||
val = env_get( highlight_var[0]);
|
val = env_get( highlight_var[0]);
|
||||||
|
|
||||||
if( val )
|
if( val )
|
||||||
result = output_color_code( val );
|
result = output_color_code( val );
|
||||||
|
|
||||||
if( highlight & HIGHLIGHT_VALID_PATH )
|
if( highlight & HIGHLIGHT_VALID_PATH )
|
||||||
{
|
{
|
||||||
wchar_t *val2 = env_get( L"fish_color_valid_path" );
|
wchar_t *val2 = env_get( L"fish_color_valid_path" );
|
||||||
int result2 = output_color_code( val2 );
|
int result2 = output_color_code( val2 );
|
||||||
if( result == FISH_COLOR_NORMAL )
|
if( result == FISH_COLOR_NORMAL )
|
||||||
result = result2;
|
result = result2;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( result2 & FISH_COLOR_BOLD )
|
if( result2 & FISH_COLOR_BOLD )
|
||||||
result |= FISH_COLOR_BOLD;
|
result |= FISH_COLOR_BOLD;
|
||||||
if( result2 & FISH_COLOR_UNDERLINE )
|
if( result2 & FISH_COLOR_UNDERLINE )
|
||||||
result |= FISH_COLOR_UNDERLINE;
|
result |= FISH_COLOR_UNDERLINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -240,16 +240,16 @@ static void highlight_param( const wchar_t * buff,
|
||||||
int pos,
|
int pos,
|
||||||
array_list_t *error )
|
array_list_t *error )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
int mode = 0;
|
int mode = 0;
|
||||||
int in_pos, len = wcslen( buff );
|
int in_pos, len = wcslen( buff );
|
||||||
int bracket_count=0;
|
int bracket_count=0;
|
||||||
wchar_t c;
|
wchar_t c;
|
||||||
int normal_status = *color;
|
int normal_status = *color;
|
||||||
|
|
||||||
for( in_pos=0;
|
for( in_pos=0;
|
||||||
in_pos<len;
|
in_pos<len;
|
||||||
in_pos++ )
|
in_pos++ )
|
||||||
{
|
{
|
||||||
c = buff[in_pos];
|
c = buff[in_pos];
|
||||||
|
@ -265,7 +265,7 @@ static void highlight_param( const wchar_t * buff,
|
||||||
{
|
{
|
||||||
int start_pos = in_pos;
|
int start_pos = in_pos;
|
||||||
in_pos++;
|
in_pos++;
|
||||||
|
|
||||||
if( wcschr( L"~%", buff[in_pos] ) )
|
if( wcschr( L"~%", buff[in_pos] ) )
|
||||||
{
|
{
|
||||||
if( in_pos == 1 )
|
if( in_pos == 1 )
|
||||||
|
@ -298,10 +298,10 @@ static void highlight_param( const wchar_t * buff,
|
||||||
long long res=0;
|
long long res=0;
|
||||||
int chars=2;
|
int chars=2;
|
||||||
int base=16;
|
int base=16;
|
||||||
|
|
||||||
int byte = 0;
|
int byte = 0;
|
||||||
wchar_t max_val = ASCII_MAX;
|
wchar_t max_val = ASCII_MAX;
|
||||||
|
|
||||||
switch( buff[in_pos] )
|
switch( buff[in_pos] )
|
||||||
{
|
{
|
||||||
case L'u':
|
case L'u':
|
||||||
|
@ -310,62 +310,62 @@ static void highlight_param( const wchar_t * buff,
|
||||||
max_val = UCS2_MAX;
|
max_val = UCS2_MAX;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case L'U':
|
case L'U':
|
||||||
{
|
{
|
||||||
chars=8;
|
chars=8;
|
||||||
max_val = WCHAR_MAX;
|
max_val = WCHAR_MAX;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case L'x':
|
case L'x':
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case L'X':
|
case L'X':
|
||||||
{
|
{
|
||||||
byte=1;
|
byte=1;
|
||||||
max_val = BYTE_MAX;
|
max_val = BYTE_MAX;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
base=8;
|
base=8;
|
||||||
chars=3;
|
chars=3;
|
||||||
in_pos--;
|
in_pos--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i=0; i<chars; i++ )
|
for( i=0; i<chars; i++ )
|
||||||
{
|
{
|
||||||
int d = convert_digit( buff[++in_pos],base);
|
int d = convert_digit( buff[++in_pos],base);
|
||||||
|
|
||||||
if( d < 0 )
|
if( d < 0 )
|
||||||
{
|
{
|
||||||
in_pos--;
|
in_pos--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
res=(res*base)|d;
|
res=(res*base)|d;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (res <= max_val) )
|
if( (res <= max_val) )
|
||||||
{
|
{
|
||||||
color[start_pos] = HIGHLIGHT_ESCAPE;
|
color[start_pos] = HIGHLIGHT_ESCAPE;
|
||||||
color[in_pos+1] = normal_status;
|
color[in_pos+1] = normal_status;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
color[start_pos] = HIGHLIGHT_ERROR;
|
color[start_pos] = HIGHLIGHT_ERROR;
|
||||||
color[in_pos+1] = normal_status;
|
color[in_pos+1] = normal_status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
switch( buff[in_pos]){
|
switch( buff[in_pos]){
|
||||||
case L'~':
|
case L'~':
|
||||||
|
@ -381,9 +381,9 @@ static void highlight_param( const wchar_t * buff,
|
||||||
|
|
||||||
case L'$':
|
case L'$':
|
||||||
{
|
{
|
||||||
wchar_t n = buff[in_pos+1];
|
wchar_t n = buff[in_pos+1];
|
||||||
color[in_pos] = (n==L'$'||wcsvarchr(n))? HIGHLIGHT_OPERATOR:HIGHLIGHT_ERROR;
|
color[in_pos] = (n==L'$'||wcsvarchr(n))? HIGHLIGHT_OPERATOR:HIGHLIGHT_ERROR;
|
||||||
color[in_pos+1] = normal_status;
|
color[in_pos+1] = normal_status;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,21 +397,21 @@ static void highlight_param( const wchar_t * buff,
|
||||||
color[in_pos+1] = normal_status;
|
color[in_pos+1] = normal_status;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case L'{':
|
case L'{':
|
||||||
{
|
{
|
||||||
color[in_pos] = HIGHLIGHT_OPERATOR;
|
color[in_pos] = HIGHLIGHT_OPERATOR;
|
||||||
color[in_pos+1] = normal_status;
|
color[in_pos+1] = normal_status;
|
||||||
bracket_count++;
|
bracket_count++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case L'}':
|
case L'}':
|
||||||
{
|
{
|
||||||
color[in_pos] = HIGHLIGHT_OPERATOR;
|
color[in_pos] = HIGHLIGHT_OPERATOR;
|
||||||
color[in_pos+1] = normal_status;
|
color[in_pos+1] = normal_status;
|
||||||
bracket_count--;
|
bracket_count--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case L',':
|
case L',':
|
||||||
|
@ -422,16 +422,16 @@ static void highlight_param( const wchar_t * buff,
|
||||||
color[in_pos+1] = normal_status;
|
color[in_pos+1] = normal_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case L'\'':
|
case L'\'':
|
||||||
{
|
{
|
||||||
color[in_pos] = HIGHLIGHT_QUOTE;
|
color[in_pos] = HIGHLIGHT_QUOTE;
|
||||||
mode = 1;
|
mode = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case L'\"':
|
case L'\"':
|
||||||
{
|
{
|
||||||
color[in_pos] = HIGHLIGHT_QUOTE;
|
color[in_pos] = HIGHLIGHT_QUOTE;
|
||||||
|
@ -440,7 +440,7 @@ static void highlight_param( const wchar_t * buff,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,21 +461,21 @@ static void highlight_param( const wchar_t * buff,
|
||||||
color[in_pos+1] = HIGHLIGHT_QUOTE;
|
color[in_pos+1] = HIGHLIGHT_QUOTE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if( c == L'\'' )
|
if( c == L'\'' )
|
||||||
{
|
{
|
||||||
mode = 0;
|
mode = 0;
|
||||||
color[in_pos+1] = normal_status;
|
color[in_pos+1] = normal_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,7 +492,7 @@ static void highlight_param( const wchar_t * buff,
|
||||||
color[in_pos+1] = normal_status;
|
color[in_pos+1] = normal_status;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case '\\':
|
case '\\':
|
||||||
{
|
{
|
||||||
int start_pos = in_pos;
|
int start_pos = in_pos;
|
||||||
|
@ -502,7 +502,7 @@ static void highlight_param( const wchar_t * buff,
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case '\\':
|
case '\\':
|
||||||
case L'$':
|
case L'$':
|
||||||
case '"':
|
case '"':
|
||||||
|
@ -514,16 +514,16 @@ static void highlight_param( const wchar_t * buff,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case '$':
|
case '$':
|
||||||
{
|
{
|
||||||
wchar_t n = buff[in_pos+1];
|
wchar_t n = buff[in_pos+1];
|
||||||
color[in_pos] = (n==L'$'||wcsvarchr(n))? HIGHLIGHT_OPERATOR:HIGHLIGHT_ERROR;
|
color[in_pos] = (n==L'$'||wcsvarchr(n))? HIGHLIGHT_OPERATOR:HIGHLIGHT_ERROR;
|
||||||
color[in_pos+1] = HIGHLIGHT_QUOTE;
|
color[in_pos+1] = HIGHLIGHT_QUOTE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -545,9 +545,9 @@ static int has_expand_reserved( wchar_t *str )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void highlight_shell( wchar_t * buff,
|
void highlight_shell( wchar_t * buff,
|
||||||
int *color,
|
int *color,
|
||||||
int pos,
|
int pos,
|
||||||
array_list_t *error )
|
array_list_t *error )
|
||||||
{
|
{
|
||||||
tokenizer tok;
|
tokenizer tok;
|
||||||
|
@ -559,29 +559,29 @@ void highlight_shell( wchar_t * buff,
|
||||||
|
|
||||||
void *context;
|
void *context;
|
||||||
wchar_t *cmd=0;
|
wchar_t *cmd=0;
|
||||||
int accept_switches = 1;
|
int accept_switches = 1;
|
||||||
|
|
||||||
int use_function = 1;
|
int use_function = 1;
|
||||||
int use_command = 1;
|
int use_command = 1;
|
||||||
int use_builtin = 1;
|
int use_builtin = 1;
|
||||||
|
|
||||||
CHECK( buff, );
|
CHECK( buff, );
|
||||||
CHECK( color, );
|
CHECK( color, );
|
||||||
|
|
||||||
len = wcslen(buff);
|
len = wcslen(buff);
|
||||||
|
|
||||||
if( !len )
|
if( !len )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
context = halloc( 0, 0 );
|
context = halloc( 0, 0 );
|
||||||
|
|
||||||
for( i=0; buff[i] != 0; i++ )
|
for( i=0; buff[i] != 0; i++ )
|
||||||
color[i] = -1;
|
color[i] = -1;
|
||||||
|
|
||||||
for( tok_init( &tok, buff, TOK_SHOW_COMMENTS );
|
for( tok_init( &tok, buff, TOK_SHOW_COMMENTS );
|
||||||
tok_has_next( &tok );
|
tok_has_next( &tok );
|
||||||
tok_next( &tok ) )
|
tok_next( &tok ) )
|
||||||
{
|
{
|
||||||
int last_type = tok_last_type( &tok );
|
int last_type = tok_last_type( &tok );
|
||||||
int prev_argc=0;
|
int prev_argc=0;
|
||||||
|
|
||||||
|
@ -591,7 +591,7 @@ void highlight_shell( wchar_t * buff,
|
||||||
{
|
{
|
||||||
if( had_cmd )
|
if( had_cmd )
|
||||||
{
|
{
|
||||||
|
|
||||||
/*Parameter */
|
/*Parameter */
|
||||||
wchar_t *param = tok_last( &tok );
|
wchar_t *param = tok_last( &tok );
|
||||||
if( param[0] == L'-' )
|
if( param[0] == L'-' )
|
||||||
|
@ -616,43 +616,43 @@ void highlight_shell( wchar_t * buff,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_PARAM;
|
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( cmd && (wcscmp( cmd, L"cd" ) == 0) )
|
if( cmd && (wcscmp( cmd, L"cd" ) == 0) )
|
||||||
{
|
{
|
||||||
wchar_t *dir = expand_one( context,
|
wchar_t *dir = expand_one( context,
|
||||||
wcsdup(tok_last( &tok )),
|
wcsdup(tok_last( &tok )),
|
||||||
EXPAND_SKIP_CMDSUBST );
|
EXPAND_SKIP_CMDSUBST );
|
||||||
if( dir )
|
if( dir )
|
||||||
{
|
{
|
||||||
int is_long_help = wcsncmp(dir,L"--help", wcslen(dir) );
|
int is_long_help = wcsncmp(dir,L"--help", wcslen(dir) );
|
||||||
int is_short_help = wcsncmp(dir,L"-h", wcslen(dir) );
|
int is_short_help = wcsncmp(dir,L"-h", wcslen(dir) );
|
||||||
|
|
||||||
if( !is_long_help && !is_short_help && !path_get_cdpath( context, dir ) )
|
if( !is_long_help && !is_short_help && !path_get_cdpath( context, dir ) )
|
||||||
{
|
{
|
||||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
highlight_param( param,
|
highlight_param( param,
|
||||||
&color[tok_get_pos( &tok )],
|
&color[tok_get_pos( &tok )],
|
||||||
pos-tok_get_pos( &tok ),
|
pos-tok_get_pos( &tok ),
|
||||||
error );
|
error );
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
prev_argc=0;
|
prev_argc=0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Command. First check that the command actually exists.
|
Command. First check that the command actually exists.
|
||||||
*/
|
*/
|
||||||
cmd = expand_one( context,
|
cmd = expand_one( context,
|
||||||
wcsdup(tok_last( &tok )),
|
wcsdup(tok_last( &tok )),
|
||||||
EXPAND_SKIP_CMDSUBST | EXPAND_SKIP_VARIABLES);
|
EXPAND_SKIP_CMDSUBST | EXPAND_SKIP_VARIABLES);
|
||||||
|
|
||||||
if( (cmd == 0) || has_expand_reserved( cmd ) )
|
if( (cmd == 0) || has_expand_reserved( cmd ) )
|
||||||
{
|
{
|
||||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
||||||
|
@ -666,9 +666,9 @@ void highlight_shell( wchar_t * buff,
|
||||||
|
|
||||||
if( parser_keywords_is_subcommand( cmd ) )
|
if( parser_keywords_is_subcommand( cmd ) )
|
||||||
{
|
{
|
||||||
|
|
||||||
int sw;
|
int sw;
|
||||||
|
|
||||||
if( wcscmp( cmd, L"builtin" )==0)
|
if( wcscmp( cmd, L"builtin" )==0)
|
||||||
{
|
{
|
||||||
use_function = 0;
|
use_function = 0;
|
||||||
|
@ -683,13 +683,13 @@ void highlight_shell( wchar_t * buff,
|
||||||
}
|
}
|
||||||
|
|
||||||
tok_next( &tok );
|
tok_next( &tok );
|
||||||
|
|
||||||
sw = parser_keywords_is_switch( tok_last( &tok ) );
|
sw = parser_keywords_is_switch( tok_last( &tok ) );
|
||||||
|
|
||||||
if( !parser_keywords_is_block( cmd ) &&
|
if( !parser_keywords_is_block( cmd ) &&
|
||||||
sw == ARG_SWITCH )
|
sw == ARG_SWITCH )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
The 'builtin' and 'command' builtins
|
The 'builtin' and 'command' builtins
|
||||||
are normally followed by another
|
are normally followed by another
|
||||||
command, but if they are invoked
|
command, but if they are invoked
|
||||||
|
@ -707,12 +707,12 @@ void highlight_shell( wchar_t * buff,
|
||||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_PARAM;
|
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_PARAM;
|
||||||
mark = tok_get_pos( &tok );
|
mark = tok_get_pos( &tok );
|
||||||
}
|
}
|
||||||
|
|
||||||
is_subcommand = 1;
|
is_subcommand = 1;
|
||||||
}
|
}
|
||||||
tok_set_pos( &tok, mark );
|
tok_set_pos( &tok, mark );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !is_subcommand )
|
if( !is_subcommand )
|
||||||
{
|
{
|
||||||
wchar_t *tmp;
|
wchar_t *tmp;
|
||||||
|
@ -730,7 +730,7 @@ void highlight_shell( wchar_t * buff,
|
||||||
*/
|
*/
|
||||||
if( use_builtin )
|
if( use_builtin )
|
||||||
is_cmd |= builtin_exists( cmd );
|
is_cmd |= builtin_exists( cmd );
|
||||||
|
|
||||||
if( use_function )
|
if( use_function )
|
||||||
is_cmd |= function_exists( cmd );
|
is_cmd |= function_exists( cmd );
|
||||||
|
|
||||||
|
@ -743,16 +743,16 @@ void highlight_shell( wchar_t * buff,
|
||||||
*/
|
*/
|
||||||
if( use_command )
|
if( use_command )
|
||||||
is_cmd |= !!(tmp=path_get_path( context, cmd ));
|
is_cmd |= !!(tmp=path_get_path( context, cmd ));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Could not find the command. Maybe it is
|
Could not find the command. Maybe it is
|
||||||
a path for a implicit cd command.
|
a path for a implicit cd command.
|
||||||
*/
|
*/
|
||||||
if( use_builtin || (use_function && function_exists( L"cd") ) )
|
if( use_builtin || (use_function && function_exists( L"cd") ) )
|
||||||
is_cmd |= !!(tmp=path_get_cdpath( context, cmd ));
|
is_cmd |= !!(tmp=path_get_cdpath( context, cmd ));
|
||||||
|
|
||||||
if( is_cmd )
|
if( is_cmd )
|
||||||
{
|
{
|
||||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_COMMAND;
|
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_COMMAND;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -766,14 +766,14 @@ void highlight_shell( wchar_t * buff,
|
||||||
|
|
||||||
if( had_cmd )
|
if( had_cmd )
|
||||||
{
|
{
|
||||||
last_cmd = halloc_wcsdup( context, tok_last( &tok ) );
|
last_cmd = halloc_wcsdup( context, tok_last( &tok ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TOK_REDIRECT_NOCLOB:
|
case TOK_REDIRECT_NOCLOB:
|
||||||
case TOK_REDIRECT_OUT:
|
case TOK_REDIRECT_OUT:
|
||||||
case TOK_REDIRECT_IN:
|
case TOK_REDIRECT_IN:
|
||||||
|
@ -787,9 +787,9 @@ void highlight_shell( wchar_t * buff,
|
||||||
al_push( error, wcsdup ( L"Redirection without a command" ) );
|
al_push( error, wcsdup ( L"Redirection without a command" ) );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t *target=0;
|
wchar_t *target=0;
|
||||||
|
|
||||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_REDIRECTION;
|
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_REDIRECTION;
|
||||||
tok_next( &tok );
|
tok_next( &tok );
|
||||||
|
|
||||||
|
@ -803,7 +803,7 @@ void highlight_shell( wchar_t * buff,
|
||||||
{
|
{
|
||||||
target = expand_one( context, wcsdup( tok_last( &tok ) ), EXPAND_SKIP_CMDSUBST);
|
target = expand_one( context, wcsdup( tok_last( &tok ) ), EXPAND_SKIP_CMDSUBST);
|
||||||
/*
|
/*
|
||||||
Redirect filename may contain a cmdsubst.
|
Redirect filename may contain a cmdsubst.
|
||||||
If so, it will be ignored/not flagged.
|
If so, it will be ignored/not flagged.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
@ -814,7 +814,7 @@ void highlight_shell( wchar_t * buff,
|
||||||
if( error )
|
if( error )
|
||||||
al_push( error, wcsdup ( L"Invalid redirection" ) );
|
al_push( error, wcsdup ( L"Invalid redirection" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( target != 0 )
|
if( target != 0 )
|
||||||
|
@ -822,7 +822,7 @@ void highlight_shell( wchar_t * buff,
|
||||||
wchar_t *dir = halloc_wcsdup( context, target );
|
wchar_t *dir = halloc_wcsdup( context, target );
|
||||||
wchar_t *dir_end = wcsrchr( dir, L'/' );
|
wchar_t *dir_end = wcsrchr( dir, L'/' );
|
||||||
struct stat buff;
|
struct stat buff;
|
||||||
/*
|
/*
|
||||||
If file is in directory other than '.', check
|
If file is in directory other than '.', check
|
||||||
that the directory exists.
|
that the directory exists.
|
||||||
*/
|
*/
|
||||||
|
@ -834,15 +834,15 @@ void highlight_shell( wchar_t * buff,
|
||||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
||||||
if( error )
|
if( error )
|
||||||
al_push( error, wcsdupcat( L"Directory \'", dir, L"\' does not exist" ) );
|
al_push( error, wcsdupcat( L"Directory \'", dir, L"\' does not exist" ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
If the file is read from or appended to, check
|
If the file is read from or appended to, check
|
||||||
if it exists.
|
if it exists.
|
||||||
*/
|
*/
|
||||||
if( last_type == TOK_REDIRECT_IN ||
|
if( last_type == TOK_REDIRECT_IN ||
|
||||||
last_type == TOK_REDIRECT_APPEND )
|
last_type == TOK_REDIRECT_APPEND )
|
||||||
{
|
{
|
||||||
if( wstat( target, &buff ) == -1 )
|
if( wstat( target, &buff ) == -1 )
|
||||||
|
@ -864,7 +864,7 @@ void highlight_shell( wchar_t * buff,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TOK_PIPE:
|
case TOK_PIPE:
|
||||||
case TOK_BACKGROUND:
|
case TOK_BACKGROUND:
|
||||||
{
|
{
|
||||||
|
@ -879,14 +879,14 @@ void highlight_shell( wchar_t * buff,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
||||||
if( error )
|
if( error )
|
||||||
al_push( error, wcsdup ( L"No job to put in background" ) );
|
al_push( error, wcsdup ( L"No job to put in background" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TOK_END:
|
case TOK_END:
|
||||||
{
|
{
|
||||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_END;
|
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_END;
|
||||||
|
@ -897,13 +897,13 @@ void highlight_shell( wchar_t * buff,
|
||||||
accept_switches = 1;
|
accept_switches = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TOK_COMMENT:
|
case TOK_COMMENT:
|
||||||
{
|
{
|
||||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_COMMENT;
|
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_COMMENT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TOK_ERROR:
|
case TOK_ERROR:
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
@ -913,13 +913,13 @@ void highlight_shell( wchar_t * buff,
|
||||||
if( error )
|
if( error )
|
||||||
al_push( error, wcsdup ( tok_last( &tok) ) );
|
al_push( error, wcsdup ( tok_last( &tok) ) );
|
||||||
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
color[ tok_get_pos( &tok ) ] = HIGHLIGHT_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tok_destroy( &tok );
|
tok_destroy( &tok );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Locate and syntax highlight cmdsubsts recursively
|
Locate and syntax highlight cmdsubsts recursively
|
||||||
*/
|
*/
|
||||||
|
@ -927,32 +927,32 @@ void highlight_shell( wchar_t * buff,
|
||||||
wchar_t *buffcpy = halloc_wcsdup( context, buff );
|
wchar_t *buffcpy = halloc_wcsdup( context, buff );
|
||||||
wchar_t *subpos=buffcpy;
|
wchar_t *subpos=buffcpy;
|
||||||
int done=0;
|
int done=0;
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
wchar_t *begin, *end;
|
wchar_t *begin, *end;
|
||||||
|
|
||||||
if( parse_util_locate_cmdsubst( subpos,
|
if( parse_util_locate_cmdsubst( subpos,
|
||||||
&begin,
|
&begin,
|
||||||
&end,
|
&end,
|
||||||
1) <= 0)
|
1) <= 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !*end )
|
if( !*end )
|
||||||
done=1;
|
done=1;
|
||||||
else
|
else
|
||||||
*end=0;
|
*end=0;
|
||||||
|
|
||||||
highlight_shell( begin+1, color +(begin-buffcpy)+1, -1, error );
|
highlight_shell( begin+1, color +(begin-buffcpy)+1, -1, error );
|
||||||
color[end-buffcpy]=HIGHLIGHT_OPERATOR;
|
color[end-buffcpy]=HIGHLIGHT_OPERATOR;
|
||||||
|
|
||||||
if( done )
|
if( done )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
subpos = end+1;
|
subpos = end+1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -975,15 +975,15 @@ void highlight_shell( wchar_t * buff,
|
||||||
|
|
||||||
if( pos >= 0 && pos <= len )
|
if( pos >= 0 && pos <= len )
|
||||||
{
|
{
|
||||||
|
|
||||||
wchar_t *tok_begin, *tok_end;
|
wchar_t *tok_begin, *tok_end;
|
||||||
wchar_t *token;
|
wchar_t *token;
|
||||||
|
|
||||||
parse_util_token_extent( buff, pos, &tok_begin, &tok_end, 0, 0 );
|
parse_util_token_extent( buff, pos, &tok_begin, &tok_end, 0, 0 );
|
||||||
if( tok_begin && tok_end )
|
if( tok_begin && tok_end )
|
||||||
{
|
{
|
||||||
token = halloc_wcsndup( context, tok_begin, tok_end-tok_begin );
|
token = halloc_wcsndup( context, tok_begin, tok_end-tok_begin );
|
||||||
|
|
||||||
if( is_potential_path( token ) )
|
if( is_potential_path( token ) )
|
||||||
{
|
{
|
||||||
for( i=tok_begin-buff; i < (tok_end-buff); i++ )
|
for( i=tok_begin-buff; i < (tok_end-buff); i++ )
|
||||||
|
@ -993,7 +993,7 @@ void highlight_shell( wchar_t * buff,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
highlight_universal_internal( buff, color, pos, error );
|
highlight_universal_internal( buff, color, pos, error );
|
||||||
|
|
||||||
|
@ -1009,21 +1009,21 @@ void highlight_shell( wchar_t * buff,
|
||||||
}
|
}
|
||||||
|
|
||||||
halloc_free( context );
|
halloc_free( context );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Perform quote and parenthesis highlighting on the specified string.
|
Perform quote and parenthesis highlighting on the specified string.
|
||||||
*/
|
*/
|
||||||
static void highlight_universal_internal( wchar_t * buff,
|
static void highlight_universal_internal( wchar_t * buff,
|
||||||
int *color,
|
int *color,
|
||||||
int pos,
|
int pos,
|
||||||
array_list_t *error )
|
array_list_t *error )
|
||||||
{
|
{
|
||||||
|
|
||||||
if( (pos >= 0) && (pos < wcslen(buff)) )
|
if( (pos >= 0) && (pos < wcslen(buff)) )
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Highlight matching quotes
|
Highlight matching quotes
|
||||||
*/
|
*/
|
||||||
|
@ -1032,14 +1032,14 @@ static void highlight_universal_internal( wchar_t * buff,
|
||||||
|
|
||||||
array_list_t l;
|
array_list_t l;
|
||||||
al_init( &l );
|
al_init( &l );
|
||||||
|
|
||||||
int level=0;
|
int level=0;
|
||||||
wchar_t prev_q=0;
|
wchar_t prev_q=0;
|
||||||
|
|
||||||
wchar_t *str=buff;
|
wchar_t *str=buff;
|
||||||
|
|
||||||
int match_found=0;
|
int match_found=0;
|
||||||
|
|
||||||
while(*str)
|
while(*str)
|
||||||
{
|
{
|
||||||
switch( *str )
|
switch( *str )
|
||||||
|
@ -1060,7 +1060,7 @@ static void highlight_universal_internal( wchar_t * buff,
|
||||||
if( prev_q == *str )
|
if( prev_q == *str )
|
||||||
{
|
{
|
||||||
long pos1, pos2;
|
long pos1, pos2;
|
||||||
|
|
||||||
level--;
|
level--;
|
||||||
pos1 = al_pop_long( &l );
|
pos1 = al_pop_long( &l );
|
||||||
pos2 = str-buff;
|
pos2 = str-buff;
|
||||||
|
@ -1069,7 +1069,7 @@ static void highlight_universal_internal( wchar_t * buff,
|
||||||
color[pos1]|=HIGHLIGHT_MATCH<<16;
|
color[pos1]|=HIGHLIGHT_MATCH<<16;
|
||||||
color[pos2]|=HIGHLIGHT_MATCH<<16;
|
color[pos2]|=HIGHLIGHT_MATCH<<16;
|
||||||
match_found = 1;
|
match_found = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
prev_q = *str==L'\"'?L'\'':L'\"';
|
prev_q = *str==L'\"'?L'\'':L'\"';
|
||||||
}
|
}
|
||||||
|
@ -1080,7 +1080,7 @@ static void highlight_universal_internal( wchar_t * buff,
|
||||||
prev_q = *str;
|
prev_q = *str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if( (*str == L'\0'))
|
if( (*str == L'\0'))
|
||||||
|
@ -1090,7 +1090,7 @@ static void highlight_universal_internal( wchar_t * buff,
|
||||||
}
|
}
|
||||||
|
|
||||||
al_destroy( &l );
|
al_destroy( &l );
|
||||||
|
|
||||||
if( !match_found )
|
if( !match_found )
|
||||||
color[pos] = HIGHLIGHT_ERROR<<16;
|
color[pos] = HIGHLIGHT_ERROR<<16;
|
||||||
}
|
}
|
||||||
|
@ -1105,7 +1105,7 @@ static void highlight_universal_internal( wchar_t * buff,
|
||||||
wchar_t inc_char = buff[pos];
|
wchar_t inc_char = buff[pos];
|
||||||
int level = 0;
|
int level = 0;
|
||||||
wchar_t *str = &buff[pos];
|
wchar_t *str = &buff[pos];
|
||||||
int match_found=0;
|
int match_found=0;
|
||||||
|
|
||||||
while( (str >= buff) && *str)
|
while( (str >= buff) && *str)
|
||||||
{
|
{
|
||||||
|
@ -1123,22 +1123,22 @@ static void highlight_universal_internal( wchar_t * buff,
|
||||||
}
|
}
|
||||||
str+= step;
|
str+= step;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !match_found )
|
if( !match_found )
|
||||||
color[pos] = HIGHLIGHT_ERROR<<16;
|
color[pos] = HIGHLIGHT_ERROR<<16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void highlight_universal( wchar_t * buff,
|
void highlight_universal( wchar_t * buff,
|
||||||
int *color,
|
int *color,
|
||||||
int pos,
|
int pos,
|
||||||
array_list_t *error )
|
array_list_t *error )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for( i=0; buff[i]; i++ )
|
for( i=0; buff[i]; i++ )
|
||||||
color[i] = 0;
|
color[i] = 0;
|
||||||
|
|
||||||
highlight_universal_internal( buff, color, pos, error );
|
highlight_universal_internal( buff, color, pos, error );
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
/**
|
/**
|
||||||
Internal value representing highlighting of an IO redirection
|
Internal value representing highlighting of an IO redirection
|
||||||
*/
|
*/
|
||||||
#define HIGHLIGHT_REDIRECTION 0x800
|
#define HIGHLIGHT_REDIRECTION 0x800
|
||||||
/**
|
/**
|
||||||
Internal value representing highlighting a potentially valid path
|
Internal value representing highlighting a potentially valid path
|
||||||
*/
|
*/
|
||||||
|
@ -68,7 +68,7 @@
|
||||||
for each character in buff.
|
for each character in buff.
|
||||||
|
|
||||||
\param buff The buffer on which to perform syntax highlighting
|
\param buff The buffer on which to perform syntax highlighting
|
||||||
\param color The array in wchich to store the color codes. The first 8 bits are used for fg color, the next 8 bits for bg color.
|
\param color The array in wchich to store the color codes. The first 8 bits are used for fg color, the next 8 bits for bg color.
|
||||||
\param pos the cursor position. Used for quote matching, etc.
|
\param pos the cursor position. Used for quote matching, etc.
|
||||||
\param error a list in which a description of each error will be inserted. May be 0, in whcich case no error descriptions will be generated.
|
\param error a list in which a description of each error will be inserted. May be 0, in whcich case no error descriptions will be generated.
|
||||||
*/
|
*/
|
||||||
|
@ -80,7 +80,7 @@ void highlight_shell( wchar_t * buff, int *color, int pos, array_list_t *error )
|
||||||
for each character in buff.
|
for each character in buff.
|
||||||
|
|
||||||
\param buff The buffer on which to perform syntax highlighting
|
\param buff The buffer on which to perform syntax highlighting
|
||||||
\param color The array in wchich to store the color codes. The first 8 bits are used for fg color, the next 8 bits for bg color.
|
\param color The array in wchich to store the color codes. The first 8 bits are used for fg color, the next 8 bits for bg color.
|
||||||
\param pos the cursor position. Used for quote matching, etc.
|
\param pos the cursor position. Used for quote matching, etc.
|
||||||
\param error a list in which a description of each error will be inserted. May be 0, in whcich case no error descriptions will be generated.
|
\param error a list in which a description of each error will be inserted. May be 0, in whcich case no error descriptions will be generated.
|
||||||
*/
|
*/
|
||||||
|
@ -90,7 +90,7 @@ void highlight_universal( wchar_t * buff, int *color, int pos, array_list_t *err
|
||||||
Translate from HIGHLIGHT_* to FISH_COLOR_* according to environment
|
Translate from HIGHLIGHT_* to FISH_COLOR_* according to environment
|
||||||
variables. Defaults to FISH_COLOR_NORMAL.
|
variables. Defaults to FISH_COLOR_NORMAL.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
If the environment variable FISH_FISH_COLOR_ERROR is set to 'red', a
|
If the environment variable FISH_FISH_COLOR_ERROR is set to 'red', a
|
||||||
call to highlight_get_color( HIGHLIGHT_ERROR) will return
|
call to highlight_get_color( HIGHLIGHT_ERROR) will return
|
||||||
|
|
226
history.c
226
history.c
|
@ -43,13 +43,13 @@
|
||||||
/**
|
/**
|
||||||
A struct representiong a history list
|
A struct representiong a history list
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
The name of this list. Used for picking a suitable filename and for switching modes.
|
The name of this list. Used for picking a suitable filename and for switching modes.
|
||||||
*/
|
*/
|
||||||
const wchar_t *name;
|
const wchar_t *name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The items of the list. Each entry may be either a pointer to an
|
The items of the list. Each entry may be either a pointer to an
|
||||||
item_t struct or a pointer to an mmaped memory region where a
|
item_t struct or a pointer to an mmaped memory region where a
|
||||||
|
@ -66,12 +66,12 @@ typedef struct
|
||||||
this session.
|
this session.
|
||||||
*/
|
*/
|
||||||
hash_table_t session_item;
|
hash_table_t session_item;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The current history position
|
The current history position
|
||||||
*/
|
*/
|
||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This flag is set nonzero if the file containing earlier saves has ben mmaped in
|
This flag is set nonzero if the file containing earlier saves has ben mmaped in
|
||||||
*/
|
*/
|
||||||
|
@ -91,7 +91,7 @@ typedef struct
|
||||||
A list of indices of all previous search maches. This is used to eliminate duplicate search results.
|
A list of indices of all previous search maches. This is used to eliminate duplicate search results.
|
||||||
*/
|
*/
|
||||||
array_list_t used;
|
array_list_t used;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Timestamp of last save
|
Timestamp of last save
|
||||||
*/
|
*/
|
||||||
|
@ -114,13 +114,13 @@ typedef struct
|
||||||
/**
|
/**
|
||||||
This struct represents a history item
|
This struct represents a history item
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
The actual contents of the entry
|
The actual contents of the entry
|
||||||
*/
|
*/
|
||||||
wchar_t *data;
|
wchar_t *data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Original creation time for the entry
|
Original creation time for the entry
|
||||||
*/
|
*/
|
||||||
|
@ -154,7 +154,7 @@ static int hash_item_cmp( void *v1, void *v2 )
|
||||||
{
|
{
|
||||||
item_t *i1 = (item_t *)v1;
|
item_t *i1 = (item_t *)v1;
|
||||||
item_t *i2 = (item_t *)v2;
|
item_t *i2 = (item_t *)v2;
|
||||||
return (i1->timestamp == i2->timestamp) && (wcscmp( i1->data, i2->data )==0);
|
return (i1->timestamp == i2->timestamp) && (wcscmp( i1->data, i2->data )==0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -198,7 +198,7 @@ static wchar_t *history_escape_newlines( wchar_t *in )
|
||||||
*/
|
*/
|
||||||
sb_append_char( out, L'\n' );
|
sb_append_char( out, L'\n' );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if( *in == L'\n' )
|
else if( *in == L'\n' )
|
||||||
{
|
{
|
||||||
|
@ -209,7 +209,7 @@ static wchar_t *history_escape_newlines( wchar_t *in )
|
||||||
{
|
{
|
||||||
sb_append_char( out, *in );
|
sb_append_char( out, *in );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return (wchar_t *)out->buff;
|
return (wchar_t *)out->buff;
|
||||||
}
|
}
|
||||||
|
@ -256,14 +256,14 @@ static wchar_t *history_unescape_newlines( wchar_t *in )
|
||||||
Check if the specified item is already loaded
|
Check if the specified item is already loaded
|
||||||
*/
|
*/
|
||||||
static int item_is_new( history_mode_t *m, void *d )
|
static int item_is_new( history_mode_t *m, void *d )
|
||||||
{
|
{
|
||||||
char *begin = (char *)d;
|
char *begin = (char *)d;
|
||||||
|
|
||||||
if( !m->has_loaded || !m->mmap_start || (m->mmap_start == MAP_FAILED ) )
|
if( !m->has_loaded || !m->mmap_start || (m->mmap_start == MAP_FAILED ) )
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (begin < m->mmap_start) || (begin > (m->mmap_start+m->mmap_length) ) )
|
if( (begin < m->mmap_start) || (begin > (m->mmap_start+m->mmap_length) ) )
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -277,7 +277,7 @@ static int item_is_new( history_mode_t *m, void *d )
|
||||||
Later calls to this function may erase the output of a previous call to this function.
|
Later calls to this function may erase the output of a previous call to this function.
|
||||||
*/
|
*/
|
||||||
static item_t *item_get( history_mode_t *m, void *d )
|
static item_t *item_get( history_mode_t *m, void *d )
|
||||||
{
|
{
|
||||||
char *begin = (char *)d;
|
char *begin = (char *)d;
|
||||||
|
|
||||||
if( item_is_new( m, d ) )
|
if( item_is_new( m, d ) )
|
||||||
|
@ -286,18 +286,18 @@ static item_t *item_get( history_mode_t *m, void *d )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
char *end = m->mmap_start + m->mmap_length;
|
char *end = m->mmap_start + m->mmap_length;
|
||||||
char *pos=begin;
|
char *pos=begin;
|
||||||
|
|
||||||
int was_backslash = 0;
|
int was_backslash = 0;
|
||||||
static string_buffer_t *out = 0;
|
static string_buffer_t *out = 0;
|
||||||
static item_t narrow_item;
|
static item_t narrow_item;
|
||||||
int first_char = 1;
|
int first_char = 1;
|
||||||
int timestamp_mode = 0;
|
int timestamp_mode = 0;
|
||||||
|
|
||||||
narrow_item.timestamp = 0;
|
narrow_item.timestamp = 0;
|
||||||
|
|
||||||
if( !out )
|
if( !out )
|
||||||
{
|
{
|
||||||
out = sb_halloc( global_context );
|
out = sb_halloc( global_context );
|
||||||
|
@ -310,17 +310,17 @@ static item_t *item_get( history_mode_t *m, void *d )
|
||||||
{
|
{
|
||||||
sb_clear( out );
|
sb_clear( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
wchar_t c;
|
wchar_t c;
|
||||||
mbstate_t state;
|
mbstate_t state;
|
||||||
size_t res;
|
size_t res;
|
||||||
|
|
||||||
memset( &state, 0, sizeof(state) );
|
memset( &state, 0, sizeof(state) );
|
||||||
|
|
||||||
res = mbrtowc( &c, pos, end-pos, &state );
|
res = mbrtowc( &c, pos, end-pos, &state );
|
||||||
|
|
||||||
if( res == (size_t)-1 )
|
if( res == (size_t)-1 )
|
||||||
{
|
{
|
||||||
pos++;
|
pos++;
|
||||||
|
@ -336,7 +336,7 @@ static item_t *item_get( history_mode_t *m, void *d )
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
pos += res;
|
pos += res;
|
||||||
|
|
||||||
if( c == L'\n' )
|
if( c == L'\n' )
|
||||||
{
|
{
|
||||||
if( timestamp_mode )
|
if( timestamp_mode )
|
||||||
|
@ -345,21 +345,21 @@ static item_t *item_get( history_mode_t *m, void *d )
|
||||||
while( *time_string && !iswdigit(*time_string))
|
while( *time_string && !iswdigit(*time_string))
|
||||||
time_string++;
|
time_string++;
|
||||||
errno=0;
|
errno=0;
|
||||||
|
|
||||||
if( *time_string )
|
if( *time_string )
|
||||||
{
|
{
|
||||||
time_t tm;
|
time_t tm;
|
||||||
wchar_t *end;
|
wchar_t *end;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
tm = (time_t)wcstol( time_string, &end, 10 );
|
tm = (time_t)wcstol( time_string, &end, 10 );
|
||||||
|
|
||||||
if( tm && !errno && !*end )
|
if( tm && !errno && !*end )
|
||||||
{
|
{
|
||||||
narrow_item.timestamp = tm;
|
narrow_item.timestamp = tm;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sb_clear( out );
|
sb_clear( out );
|
||||||
timestamp_mode = 0;
|
timestamp_mode = 0;
|
||||||
|
@ -368,21 +368,21 @@ static item_t *item_get( history_mode_t *m, void *d )
|
||||||
if( !was_backslash )
|
if( !was_backslash )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( first_char )
|
if( first_char )
|
||||||
{
|
{
|
||||||
if( c == L'#' )
|
if( c == L'#' )
|
||||||
timestamp_mode = 1;
|
timestamp_mode = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
first_char = 0;
|
first_char = 0;
|
||||||
|
|
||||||
sb_append_char( out, c );
|
sb_append_char( out, c );
|
||||||
|
|
||||||
was_backslash = ( (c == L'\\') && !was_backslash);
|
was_backslash = ( (c == L'\\') && !was_backslash);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
narrow_item.data = history_unescape_newlines((wchar_t *)out->buff);
|
narrow_item.data = history_unescape_newlines((wchar_t *)out->buff);
|
||||||
return &narrow_item;
|
return &narrow_item;
|
||||||
}
|
}
|
||||||
|
@ -404,12 +404,12 @@ static int item_write( FILE *f, history_mode_t *m, void *v )
|
||||||
static void history_destroy_mode( history_mode_t *m )
|
static void history_destroy_mode( history_mode_t *m )
|
||||||
{
|
{
|
||||||
halloc_free( m->item_context );
|
halloc_free( m->item_context );
|
||||||
|
|
||||||
if( m->mmap_start && (m->mmap_start != MAP_FAILED ))
|
if( m->mmap_start && (m->mmap_start != MAP_FAILED ))
|
||||||
{
|
{
|
||||||
munmap( m->mmap_start, m->mmap_length);
|
munmap( m->mmap_start, m->mmap_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -421,11 +421,11 @@ static void history_destroy_mode_wrapper( void *n, history_mode_t *m )
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Create a new empty mode with the specified name.
|
Create a new empty mode with the specified name.
|
||||||
The mode is a halloc context, and the entire mode can be destroyed using halloc_free().
|
The mode is a halloc context, and the entire mode can be destroyed using halloc_free().
|
||||||
*/
|
*/
|
||||||
static history_mode_t *history_create_mode( const wchar_t *name )
|
static history_mode_t *history_create_mode( const wchar_t *name )
|
||||||
{
|
{
|
||||||
history_mode_t *new_mode = halloc( 0, sizeof( history_mode_t ));
|
history_mode_t *new_mode = halloc( 0, sizeof( history_mode_t ));
|
||||||
|
|
||||||
new_mode->name = intern(name);
|
new_mode->name = intern(name);
|
||||||
|
@ -434,16 +434,16 @@ static history_mode_t *history_create_mode( const wchar_t *name )
|
||||||
al_init( &new_mode->used );
|
al_init( &new_mode->used );
|
||||||
halloc_register_function( new_mode, (void (*)(void *))&al_destroy, &new_mode->item );
|
halloc_register_function( new_mode, (void (*)(void *))&al_destroy, &new_mode->item );
|
||||||
halloc_register_function( new_mode, (void (*)(void *))&al_destroy, &new_mode->used );
|
halloc_register_function( new_mode, (void (*)(void *))&al_destroy, &new_mode->used );
|
||||||
|
|
||||||
hash_init( &new_mode->session_item, &hash_item_func, &hash_item_cmp );
|
hash_init( &new_mode->session_item, &hash_item_func, &hash_item_cmp );
|
||||||
halloc_register_function( new_mode, (void (*)(void *))&hash_destroy, &new_mode->session_item );
|
halloc_register_function( new_mode, (void (*)(void *))&hash_destroy, &new_mode->session_item );
|
||||||
|
|
||||||
new_mode->save_timestamp=time(0);
|
new_mode->save_timestamp=time(0);
|
||||||
new_mode->item_context = halloc( 0,0 );
|
new_mode->item_context = halloc( 0,0 );
|
||||||
|
|
||||||
halloc_register_function( new_mode, (void (*)(void *))&history_destroy_mode, new_mode );
|
halloc_register_function( new_mode, (void (*)(void *))&history_destroy_mode, new_mode );
|
||||||
|
|
||||||
return new_mode;
|
return new_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -464,16 +464,16 @@ static int history_test( const wchar_t *needle, const wchar_t *haystack )
|
||||||
static wchar_t *history_filename( void *context, const wchar_t *name, const wchar_t *suffix )
|
static wchar_t *history_filename( void *context, const wchar_t *name, const wchar_t *suffix )
|
||||||
{
|
{
|
||||||
wchar_t *path;
|
wchar_t *path;
|
||||||
wchar_t *res;
|
wchar_t *res;
|
||||||
|
|
||||||
if( !current_mode )
|
if( !current_mode )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
path = path_get_config( context );
|
path = path_get_config( context );
|
||||||
|
|
||||||
if( !path )
|
if( !path )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
res = wcsdupcat( path, L"/", name, L"_history", suffix?suffix:(void *)0);
|
res = wcsdupcat( path, L"/", name, L"_history", suffix?suffix:(void *)0);
|
||||||
halloc_register_function( context, &free, res );
|
halloc_register_function( context, &free, res );
|
||||||
return res;
|
return res;
|
||||||
|
@ -483,24 +483,24 @@ static wchar_t *history_filename( void *context, const wchar_t *name, const wcha
|
||||||
Go through the mmaped region and insert pointers to suitable loacations into the item list
|
Go through the mmaped region and insert pointers to suitable loacations into the item list
|
||||||
*/
|
*/
|
||||||
static void history_populate_from_mmap( history_mode_t *m )
|
static void history_populate_from_mmap( history_mode_t *m )
|
||||||
{
|
{
|
||||||
char *begin = m->mmap_start;
|
char *begin = m->mmap_start;
|
||||||
char *end = begin + m->mmap_length;
|
char *end = begin + m->mmap_length;
|
||||||
char *pos;
|
char *pos;
|
||||||
|
|
||||||
array_list_t old_item;
|
array_list_t old_item;
|
||||||
array_list_t session_item_list;
|
array_list_t session_item_list;
|
||||||
int ignore_newline = 0;
|
int ignore_newline = 0;
|
||||||
int do_push = 1;
|
int do_push = 1;
|
||||||
|
|
||||||
al_init( &old_item );
|
al_init( &old_item );
|
||||||
al_init( &session_item_list );
|
al_init( &session_item_list );
|
||||||
al_push_all( &old_item, &m->item );
|
al_push_all( &old_item, &m->item );
|
||||||
al_truncate( &m->item, 0 );
|
al_truncate( &m->item, 0 );
|
||||||
|
|
||||||
for( pos = begin; pos <end; pos++ )
|
for( pos = begin; pos <end; pos++ )
|
||||||
{
|
{
|
||||||
|
|
||||||
if( do_push )
|
if( do_push )
|
||||||
{
|
{
|
||||||
item_t *i;
|
item_t *i;
|
||||||
|
@ -509,14 +509,14 @@ static void history_populate_from_mmap( history_mode_t *m )
|
||||||
ignore_newline = *pos == '#';
|
ignore_newline = *pos == '#';
|
||||||
|
|
||||||
i = item_get( m, pos );
|
i = item_get( m, pos );
|
||||||
|
|
||||||
if( (i_orig=hash_get( ¤t_mode->session_item, i ) ) )
|
if( (i_orig=hash_get( ¤t_mode->session_item, i ) ) )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
This item comes from this session. Insert the
|
This item comes from this session. Insert the
|
||||||
original item at the end of the item list.
|
original item at the end of the item list.
|
||||||
*/
|
*/
|
||||||
al_push( &session_item_list, i_orig );
|
al_push( &session_item_list, i_orig );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -525,10 +525,10 @@ static void history_populate_from_mmap( history_mode_t *m )
|
||||||
*/
|
*/
|
||||||
al_push( &m->item, pos );
|
al_push( &m->item, pos );
|
||||||
}
|
}
|
||||||
|
|
||||||
do_push = 0;
|
do_push = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch( *pos )
|
switch( *pos )
|
||||||
{
|
{
|
||||||
case '\\':
|
case '\\':
|
||||||
|
@ -536,7 +536,7 @@ static void history_populate_from_mmap( history_mode_t *m )
|
||||||
pos++;
|
pos++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case '\n':
|
case '\n':
|
||||||
{
|
{
|
||||||
if( ignore_newline )
|
if( ignore_newline )
|
||||||
|
@ -546,12 +546,12 @@ static void history_populate_from_mmap( history_mode_t *m )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
do_push = 1;
|
do_push = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
al_push_all( &m->item, &session_item_list );
|
al_push_all( &m->item, &session_item_list );
|
||||||
m->pos += al_get_count( &m->item );
|
m->pos += al_get_count( &m->item );
|
||||||
al_push_all( &m->item, &old_item );
|
al_push_all( &m->item, &old_item );
|
||||||
|
@ -568,20 +568,20 @@ static void history_load( history_mode_t *m )
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int ok=0;
|
int ok=0;
|
||||||
|
|
||||||
void *context;
|
void *context;
|
||||||
wchar_t *filename;
|
wchar_t *filename;
|
||||||
|
|
||||||
if( !m )
|
if( !m )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m->has_loaded=1;
|
m->has_loaded=1;
|
||||||
|
|
||||||
signal_block();
|
signal_block();
|
||||||
|
|
||||||
context = halloc( 0, 0 );
|
context = halloc( 0, 0 );
|
||||||
filename = history_filename( context, m->name, 0 );
|
filename = history_filename( context, m->name, 0 );
|
||||||
|
|
||||||
if( filename )
|
if( filename )
|
||||||
{
|
{
|
||||||
if( ( fd = wopen( filename, O_RDONLY ) ) > 0 )
|
if( ( fd = wopen( filename, O_RDONLY ) ) > 0 )
|
||||||
|
@ -602,7 +602,7 @@ static void history_load( history_mode_t *m )
|
||||||
close( fd );
|
close( fd );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
halloc_free( context );
|
halloc_free( context );
|
||||||
signal_unblock();
|
signal_unblock();
|
||||||
}
|
}
|
||||||
|
@ -633,12 +633,12 @@ static void history_save_mode( void *n, history_mode_t *m )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !has_new )
|
if( !has_new )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
signal_block();
|
signal_block();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -647,19 +647,19 @@ static void history_save_mode( void *n, history_mode_t *m )
|
||||||
*/
|
*/
|
||||||
on_disk = history_create_mode( m->name );
|
on_disk = history_create_mode( m->name );
|
||||||
history_load( on_disk );
|
history_load( on_disk );
|
||||||
|
|
||||||
tmp_name = history_filename( on_disk, m->name, L".tmp" );
|
tmp_name = history_filename( on_disk, m->name, L".tmp" );
|
||||||
|
|
||||||
if( tmp_name )
|
if( tmp_name )
|
||||||
{
|
{
|
||||||
tmp_name = wcsdup(tmp_name );
|
tmp_name = wcsdup(tmp_name );
|
||||||
|
|
||||||
if( (out=wfopen( tmp_name, "w" ) ) )
|
if( (out=wfopen( tmp_name, "w" ) ) )
|
||||||
{
|
{
|
||||||
hash_table_t mine;
|
hash_table_t mine;
|
||||||
|
|
||||||
hash_init( &mine, &hash_item_func, &hash_item_cmp );
|
hash_init( &mine, &hash_item_func, &hash_item_cmp );
|
||||||
|
|
||||||
for( i=0; i<al_get_count(&m->item); i++ )
|
for( i=0; i<al_get_count(&m->item); i++ )
|
||||||
{
|
{
|
||||||
void *ptr = al_get( &m->item, i );
|
void *ptr = al_get( &m->item, i );
|
||||||
|
@ -669,7 +669,7 @@ static void history_save_mode( void *n, history_mode_t *m )
|
||||||
hash_put( &mine, item_get( m, ptr ), L"" );
|
hash_put( &mine, item_get( m, ptr ), L"" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Re-save the old history
|
Re-save the old history
|
||||||
*/
|
*/
|
||||||
|
@ -685,14 +685,14 @@ static void history_save_mode( void *n, history_mode_t *m )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hash_destroy( &mine );
|
hash_destroy( &mine );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Add our own items last
|
Add our own items last
|
||||||
*/
|
*/
|
||||||
for( i=0; ok && (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 );
|
void *ptr = al_get( &m->item, i );
|
||||||
|
@ -700,12 +700,12 @@ static void history_save_mode( void *n, history_mode_t *m )
|
||||||
if( is_new )
|
if( is_new )
|
||||||
{
|
{
|
||||||
if( item_write( out, m, ptr ) == -1 )
|
if( item_write( out, m, ptr ) == -1 )
|
||||||
{
|
{
|
||||||
ok = 0;
|
ok = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( fclose( out ) || !ok )
|
if( fclose( out ) || !ok )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -720,8 +720,8 @@ static void history_save_mode( void *n, history_mode_t *m )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free( tmp_name );
|
free( tmp_name );
|
||||||
}
|
}
|
||||||
|
|
||||||
halloc_free( on_disk);
|
halloc_free( on_disk);
|
||||||
|
|
||||||
if( ok )
|
if( ok )
|
||||||
|
@ -733,23 +733,23 @@ static void history_save_mode( void *n, history_mode_t *m )
|
||||||
hash table. On reload, they will be automatically inserted at
|
hash table. On reload, they will be automatically inserted at
|
||||||
the end of the history list.
|
the end of the history list.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( m->mmap_start && (m->mmap_start != MAP_FAILED ) )
|
if( m->mmap_start && (m->mmap_start != MAP_FAILED ) )
|
||||||
{
|
{
|
||||||
munmap( m->mmap_start, m->mmap_length );
|
munmap( m->mmap_start, m->mmap_length );
|
||||||
}
|
}
|
||||||
|
|
||||||
al_truncate( &m->item, 0 );
|
al_truncate( &m->item, 0 );
|
||||||
al_truncate( &m->used, 0 );
|
al_truncate( &m->used, 0 );
|
||||||
m->pos = 0;
|
m->pos = 0;
|
||||||
m->has_loaded = 0;
|
m->has_loaded = 0;
|
||||||
m->mmap_start=0;
|
m->mmap_start=0;
|
||||||
m->mmap_length=0;
|
m->mmap_length=0;
|
||||||
|
|
||||||
m->save_timestamp=time(0);
|
m->save_timestamp=time(0);
|
||||||
m->new_count = 0;
|
m->new_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
signal_unblock();
|
signal_unblock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -757,27 +757,27 @@ static void history_save_mode( void *n, history_mode_t *m )
|
||||||
void history_add( const wchar_t *str )
|
void history_add( const wchar_t *str )
|
||||||
{
|
{
|
||||||
item_t *i;
|
item_t *i;
|
||||||
|
|
||||||
if( !current_mode )
|
if( !current_mode )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
i = halloc( current_mode->item_context, sizeof(item_t));
|
i = halloc( current_mode->item_context, sizeof(item_t));
|
||||||
i->data = (wchar_t *)halloc_wcsdup( current_mode->item_context, str );
|
i->data = (wchar_t *)halloc_wcsdup( current_mode->item_context, str );
|
||||||
i->timestamp = time(0);
|
i->timestamp = time(0);
|
||||||
|
|
||||||
al_push( ¤t_mode->item, i );
|
al_push( ¤t_mode->item, i );
|
||||||
hash_put( ¤t_mode->session_item, i, i );
|
hash_put( ¤t_mode->session_item, i, i );
|
||||||
|
|
||||||
al_truncate( ¤t_mode->used, 0 );
|
al_truncate( ¤t_mode->used, 0 );
|
||||||
current_mode->pos = al_get_count( ¤t_mode->item );
|
current_mode->pos = al_get_count( ¤t_mode->item );
|
||||||
|
|
||||||
current_mode->new_count++;
|
current_mode->new_count++;
|
||||||
|
|
||||||
if( (time(0) > current_mode->save_timestamp+SAVE_INTERVAL) || (current_mode->new_count >= SAVE_COUNT) )
|
if( (time(0) > current_mode->save_timestamp+SAVE_INTERVAL) || (current_mode->new_count >= SAVE_COUNT) )
|
||||||
{
|
{
|
||||||
history_save_mode( 0, current_mode );
|
history_save_mode( 0, current_mode );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -796,9 +796,9 @@ static int history_is_used( const wchar_t *str )
|
||||||
if( wcscmp( it->data, str ) == 0 )
|
if( wcscmp( it->data, str ) == 0 )
|
||||||
{
|
{
|
||||||
res = 1;
|
res = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -813,11 +813,11 @@ const wchar_t *history_prev_match( const wchar_t *needle )
|
||||||
{
|
{
|
||||||
item_t *i = item_get( current_mode, al_get( ¤t_mode->item, current_mode->pos ) );
|
item_t *i = item_get( current_mode, al_get( ¤t_mode->item, current_mode->pos ) );
|
||||||
wchar_t *haystack = (wchar_t *)i->data;
|
wchar_t *haystack = (wchar_t *)i->data;
|
||||||
|
|
||||||
if( history_test( needle, haystack ) )
|
if( history_test( needle, haystack ) )
|
||||||
{
|
{
|
||||||
int is_used;
|
int is_used;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This is ugly. Whenever we call item_get(),
|
This is ugly. Whenever we call item_get(),
|
||||||
there is a chance that the return value of any
|
there is a chance that the return value of any
|
||||||
|
@ -829,11 +829,11 @@ const wchar_t *history_prev_match( const wchar_t *needle )
|
||||||
*/
|
*/
|
||||||
|
|
||||||
haystack = wcsdup(haystack );
|
haystack = wcsdup(haystack );
|
||||||
|
|
||||||
is_used = history_is_used( haystack );
|
is_used = history_is_used( haystack );
|
||||||
|
|
||||||
free( haystack );
|
free( haystack );
|
||||||
|
|
||||||
if( !is_used )
|
if( !is_used )
|
||||||
{
|
{
|
||||||
i = item_get( current_mode, al_get( ¤t_mode->item, current_mode->pos ) );
|
i = item_get( current_mode, al_get( ¤t_mode->item, current_mode->pos ) );
|
||||||
|
@ -843,7 +843,7 @@ const wchar_t *history_prev_match( const wchar_t *needle )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !current_mode->has_loaded )
|
if( !current_mode->has_loaded )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -864,9 +864,9 @@ const wchar_t *history_prev_match( const wchar_t *needle )
|
||||||
if( al_peek_long( ¤t_mode->used ) != -1 )
|
if( al_peek_long( ¤t_mode->used ) != -1 )
|
||||||
al_push_long( ¤t_mode->used, -1 );
|
al_push_long( ¤t_mode->used, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return needle;
|
return needle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -877,7 +877,7 @@ wchar_t *history_get( int idx )
|
||||||
|
|
||||||
if( !current_mode )
|
if( !current_mode )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
len = al_get_count( ¤t_mode->item );
|
len = al_get_count( ¤t_mode->item );
|
||||||
|
|
||||||
if( (idx >= len ) && !current_mode->has_loaded )
|
if( (idx >= len ) && !current_mode->has_loaded )
|
||||||
|
@ -885,13 +885,13 @@ wchar_t *history_get( int idx )
|
||||||
history_load( current_mode );
|
history_load( current_mode );
|
||||||
len = al_get_count( ¤t_mode->item );
|
len = al_get_count( ¤t_mode->item );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( idx < 0 )
|
if( idx < 0 )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if( idx >= len )
|
if( idx >= len )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return item_get( current_mode, al_get( ¤t_mode->item, len - 1 - idx ) )->data;
|
return item_get( current_mode, al_get( ¤t_mode->item, len - 1 - idx ) )->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -903,9 +903,9 @@ void history_first()
|
||||||
{
|
{
|
||||||
history_load( current_mode );
|
history_load( current_mode );
|
||||||
}
|
}
|
||||||
|
|
||||||
current_mode->pos = 0;
|
current_mode->pos = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void history_reset()
|
void history_reset()
|
||||||
|
@ -917,7 +917,7 @@ void history_reset()
|
||||||
Clear list of search matches
|
Clear list of search matches
|
||||||
*/
|
*/
|
||||||
al_truncate( ¤t_mode->used, 0 );
|
al_truncate( ¤t_mode->used, 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const wchar_t *history_next_match( const wchar_t *needle)
|
const wchar_t *history_next_match( const wchar_t *needle)
|
||||||
|
@ -939,7 +939,7 @@ const wchar_t *history_next_match( const wchar_t *needle)
|
||||||
return i->data;
|
return i->data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The used-list is empty. Set position to 'past end of list'
|
The used-list is empty. Set position to 'past end of list'
|
||||||
and return the search string.
|
and return the search string.
|
||||||
|
@ -947,7 +947,7 @@ const wchar_t *history_next_match( const wchar_t *needle)
|
||||||
current_mode->pos = al_get_count( ¤t_mode->item );
|
current_mode->pos = al_get_count( ¤t_mode->item );
|
||||||
|
|
||||||
}
|
}
|
||||||
return needle;
|
return needle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -956,16 +956,16 @@ void history_set_mode( const wchar_t *name )
|
||||||
if( !mode_table )
|
if( !mode_table )
|
||||||
{
|
{
|
||||||
mode_table = malloc( sizeof(hash_table_t ));
|
mode_table = malloc( sizeof(hash_table_t ));
|
||||||
hash_init( mode_table, &hash_wcs_func, &hash_wcs_cmp );
|
hash_init( mode_table, &hash_wcs_func, &hash_wcs_cmp );
|
||||||
}
|
}
|
||||||
|
|
||||||
current_mode = (history_mode_t *)hash_get( mode_table, name );
|
current_mode = (history_mode_t *)hash_get( mode_table, name );
|
||||||
|
|
||||||
if( !current_mode )
|
if( !current_mode )
|
||||||
{
|
{
|
||||||
current_mode = history_create_mode( name );
|
current_mode = history_create_mode( name );
|
||||||
hash_put( mode_table, name, current_mode );
|
hash_put( mode_table, name, current_mode );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void history_init()
|
void history_init()
|
||||||
|
|
|
@ -50,7 +50,7 @@ void history_reset();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Find next history item starting with str. If this moves past
|
Find next history item starting with str. If this moves past
|
||||||
the end of the history, str is returned.
|
the end of the history, str is returned.
|
||||||
*/
|
*/
|
||||||
const wchar_t *history_next_match( const wchar_t *str);
|
const wchar_t *history_next_match( const wchar_t *str);
|
||||||
|
|
||||||
|
|
164
input.c
164
input.c
|
@ -88,7 +88,7 @@ typedef struct
|
||||||
{
|
{
|
||||||
const wchar_t *seq; /**< Character sequence which generates this event */
|
const wchar_t *seq; /**< Character sequence which generates this event */
|
||||||
const wchar_t *command; /**< command that should be evaluated by this mapping */
|
const wchar_t *command; /**< command that should be evaluated by this mapping */
|
||||||
|
|
||||||
}
|
}
|
||||||
input_mapping_t;
|
input_mapping_t;
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ typedef struct
|
||||||
{
|
{
|
||||||
const wchar_t *name; /**< Name of key */
|
const wchar_t *name; /**< Name of key */
|
||||||
const char *seq; /**< Character sequence generated on keypress */
|
const char *seq; /**< Character sequence generated on keypress */
|
||||||
|
|
||||||
}
|
}
|
||||||
terminfo_mapping_t;
|
terminfo_mapping_t;
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ typedef struct
|
||||||
/**
|
/**
|
||||||
Names of all the input functions supported
|
Names of all the input functions supported
|
||||||
*/
|
*/
|
||||||
static const wchar_t *name_arr[] =
|
static const wchar_t *name_arr[] =
|
||||||
{
|
{
|
||||||
L"beginning-of-line",
|
L"beginning-of-line",
|
||||||
L"end-of-line",
|
L"end-of-line",
|
||||||
|
@ -188,7 +188,7 @@ static const wchar_t *desc_arr[] =
|
||||||
/**
|
/**
|
||||||
Internal code for each supported input function
|
Internal code for each supported input function
|
||||||
*/
|
*/
|
||||||
static const wchar_t code_arr[] =
|
static const wchar_t code_arr[] =
|
||||||
{
|
{
|
||||||
R_BEGINNING_OF_LINE,
|
R_BEGINNING_OF_LINE,
|
||||||
R_END_OF_LINE,
|
R_END_OF_LINE,
|
||||||
|
@ -230,7 +230,7 @@ static const wchar_t code_arr[] =
|
||||||
/**
|
/**
|
||||||
Mappings for the current input mode
|
Mappings for the current input mode
|
||||||
*/
|
*/
|
||||||
static array_list_t mappings = {0,0,0};
|
static array_list_t mappings = {0,0,0};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
List of all terminfo mappings
|
List of all terminfo mappings
|
||||||
|
@ -239,7 +239,7 @@ static array_list_t *terminfo_mappings = 0;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set to one when the input subsytem has been initialized.
|
Set to one when the input subsytem has been initialized.
|
||||||
*/
|
*/
|
||||||
static int is_init = 0;
|
static int is_init = 0;
|
||||||
|
|
||||||
|
@ -263,9 +263,9 @@ void input_mapping_add( const wchar_t *sequence,
|
||||||
|
|
||||||
CHECK( sequence, );
|
CHECK( sequence, );
|
||||||
CHECK( command, );
|
CHECK( command, );
|
||||||
|
|
||||||
// debug( 0, L"Add mapping from %ls to %ls", escape(sequence, 1), escape(command, 1 ) );
|
// debug( 0, L"Add mapping from %ls to %ls", escape(sequence, 1), escape(command, 1 ) );
|
||||||
|
|
||||||
|
|
||||||
for( i=0; i<al_get_count( &mappings); i++ )
|
for( i=0; i<al_get_count( &mappings); i++ )
|
||||||
{
|
{
|
||||||
|
@ -276,12 +276,12 @@ void input_mapping_add( const wchar_t *sequence,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
input_mapping_t *m = malloc( sizeof( input_mapping_t ) );
|
input_mapping_t *m = malloc( sizeof( input_mapping_t ) );
|
||||||
m->seq = intern( sequence );
|
m->seq = intern( sequence );
|
||||||
m->command = intern(command);
|
m->command = intern(command);
|
||||||
al_push( &mappings, m );
|
al_push( &mappings, m );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -293,14 +293,14 @@ static int interrupt_handler()
|
||||||
/*
|
/*
|
||||||
Fire any pending events
|
Fire any pending events
|
||||||
*/
|
*/
|
||||||
event_fire( 0 );
|
event_fire( NULL );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Reap stray processes, including printing exit status messages
|
Reap stray processes, including printing exit status messages
|
||||||
*/
|
*/
|
||||||
if( job_reap( 1 ) )
|
if( job_reap( 1 ) )
|
||||||
reader_repaint_needed();
|
reader_repaint_needed();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Tell the reader an event occured
|
Tell the reader an event occured
|
||||||
*/
|
*/
|
||||||
|
@ -312,14 +312,14 @@ static int interrupt_handler()
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
return R_NULL;
|
return R_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int input_init()
|
int input_init()
|
||||||
{
|
{
|
||||||
if( is_init )
|
if( is_init )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
is_init = 1;
|
is_init = 1;
|
||||||
|
|
||||||
input_common_init( &interrupt_handler );
|
input_common_init( &interrupt_handler );
|
||||||
|
@ -330,7 +330,7 @@ int input_init()
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
output_set_term( env_get( L"TERM" ) );
|
output_set_term( env_get( L"TERM" ) );
|
||||||
|
|
||||||
input_terminfo_init();
|
input_terminfo_init();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -353,22 +353,22 @@ void input_destroy()
|
||||||
{
|
{
|
||||||
if( !is_init )
|
if( !is_init )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
is_init=0;
|
is_init=0;
|
||||||
|
|
||||||
al_foreach( &mappings, &free );
|
al_foreach( &mappings, &free );
|
||||||
al_destroy( &mappings );
|
al_destroy( &mappings );
|
||||||
|
|
||||||
input_common_destroy();
|
input_common_destroy();
|
||||||
|
|
||||||
if( del_curterm( cur_term ) == ERR )
|
if( del_curterm( cur_term ) == ERR )
|
||||||
{
|
{
|
||||||
debug( 0, _(L"Error while closing terminfo") );
|
debug( 0, _(L"Error while closing terminfo") );
|
||||||
}
|
}
|
||||||
|
|
||||||
input_terminfo_destroy();
|
input_terminfo_destroy();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -378,7 +378,7 @@ static wint_t input_exec_binding( input_mapping_t *m, const wchar_t *seq )
|
||||||
{
|
{
|
||||||
wchar_t code = input_function_get_code( m->command );
|
wchar_t code = input_function_get_code( m->command );
|
||||||
if( code != -1 )
|
if( code != -1 )
|
||||||
{
|
{
|
||||||
switch( code )
|
switch( code )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -386,37 +386,37 @@ static wint_t input_exec_binding( input_mapping_t *m, const wchar_t *seq )
|
||||||
{
|
{
|
||||||
return seq[0];
|
return seq[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This key sequence is bound to a command, which
|
This key sequence is bound to a command, which
|
||||||
is sent to the parser for evaluation.
|
is sent to the parser for evaluation.
|
||||||
*/
|
*/
|
||||||
int last_status = proc_get_last_status();
|
int last_status = proc_get_last_status();
|
||||||
|
|
||||||
eval( m->command, 0, TOP );
|
eval( m->command, 0, TOP );
|
||||||
|
|
||||||
proc_set_last_status( last_status );
|
proc_set_last_status( last_status );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
We still need to return something to the caller, R_NULL
|
We still need to return something to the caller, R_NULL
|
||||||
tells the reader that no key press needs to be handled,
|
tells the reader that no key press needs to be handled,
|
||||||
and no repaint is needed.
|
and no repaint is needed.
|
||||||
|
|
||||||
Bindings that produce output should emit a R_REPAINT
|
Bindings that produce output should emit a R_REPAINT
|
||||||
function by calling 'commandline -f repaint' to tell
|
function by calling 'commandline -f repaint' to tell
|
||||||
fish that a repaint is in order.
|
fish that a repaint is in order.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return R_NULL;
|
return R_NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -441,14 +441,14 @@ static wint_t input_try_mapping( input_mapping_t *m)
|
||||||
return input_exec_binding( m, m->seq );
|
return input_exec_binding( m, m->seq );
|
||||||
}
|
}
|
||||||
input_unreadch( c );
|
input_unreadch( c );
|
||||||
|
|
||||||
if( m->seq != 0 )
|
if( m->seq != 0 )
|
||||||
{
|
{
|
||||||
|
|
||||||
for( j=0; m->seq[j] != L'\0' &&
|
for( j=0; m->seq[j] != L'\0' &&
|
||||||
m->seq[j] == (c=input_common_readch( j>0 )); j++ )
|
m->seq[j] == (c=input_common_readch( j>0 )); j++ )
|
||||||
;
|
;
|
||||||
|
|
||||||
if( m->seq[j] == L'\0' )
|
if( m->seq[j] == L'\0' )
|
||||||
{
|
{
|
||||||
return input_exec_binding( m, m->seq );
|
return input_exec_binding( m, m->seq );
|
||||||
|
@ -466,7 +466,7 @@ static wint_t input_try_mapping( input_mapping_t *m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void input_unreadch( wint_t ch )
|
void input_unreadch( wint_t ch )
|
||||||
|
@ -476,16 +476,16 @@ void input_unreadch( wint_t ch )
|
||||||
|
|
||||||
wint_t input_readch()
|
wint_t input_readch()
|
||||||
{
|
{
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
CHECK_BLOCK( R_NULL );
|
CHECK_BLOCK( R_NULL );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Clear the interrupted flag
|
Clear the interrupted flag
|
||||||
*/
|
*/
|
||||||
reader_interrupted();
|
reader_interrupted();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Search for sequence in mapping tables
|
Search for sequence in mapping tables
|
||||||
*/
|
*/
|
||||||
|
@ -496,51 +496,51 @@ wint_t input_readch()
|
||||||
for( i=0; i<al_get_count( &mappings); i++ )
|
for( i=0; i<al_get_count( &mappings); i++ )
|
||||||
{
|
{
|
||||||
input_mapping_t *m = (input_mapping_t *)al_get( &mappings, i );
|
input_mapping_t *m = (input_mapping_t *)al_get( &mappings, i );
|
||||||
wint_t res = input_try_mapping( m );
|
wint_t res = input_try_mapping( m );
|
||||||
if( res )
|
if( res )
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
if( wcslen( m->seq) == 0 )
|
if( wcslen( m->seq) == 0 )
|
||||||
{
|
{
|
||||||
generic = m;
|
generic = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
No matching exact mapping, try to find generic mapping.
|
No matching exact mapping, try to find generic mapping.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( generic )
|
if( generic )
|
||||||
{
|
{
|
||||||
wchar_t arr[2]=
|
wchar_t arr[2]=
|
||||||
{
|
{
|
||||||
0,
|
0,
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
arr[0] = input_common_readch(0);
|
arr[0] = input_common_readch(0);
|
||||||
|
|
||||||
return input_exec_binding( generic, arr );
|
return input_exec_binding( generic, arr );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
No action to take on specified character, ignore it
|
No action to take on specified character, ignore it
|
||||||
and move to next one.
|
and move to next one.
|
||||||
*/
|
*/
|
||||||
input_common_readch( 0 ); }
|
input_common_readch( 0 ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
void input_mapping_get_names( array_list_t *list )
|
void input_mapping_get_names( array_list_t *list )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for( i=0; i<al_get_count( &mappings ); i++ )
|
for( i=0; i<al_get_count( &mappings ); i++ )
|
||||||
{
|
{
|
||||||
input_mapping_t *m = (input_mapping_t *)al_get( &mappings, i );
|
input_mapping_t *m = (input_mapping_t *)al_get( &mappings, i );
|
||||||
al_push( list, m->seq );
|
al_push( list, m->seq );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -549,7 +549,7 @@ int input_mapping_erase( const wchar_t *sequence )
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
int i;
|
int i;
|
||||||
size_t sz = al_get_count( &mappings );
|
size_t sz = al_get_count( &mappings );
|
||||||
|
|
||||||
for( i=0; i<sz; i++ )
|
for( i=0; i<sz; i++ )
|
||||||
{
|
{
|
||||||
input_mapping_t *m = (input_mapping_t *)al_get( &mappings, i );
|
input_mapping_t *m = (input_mapping_t *)al_get( &mappings, i );
|
||||||
|
@ -561,24 +561,24 @@ int input_mapping_erase( const wchar_t *sequence )
|
||||||
}
|
}
|
||||||
al_truncate( &mappings, sz-1 );
|
al_truncate( &mappings, sz-1 );
|
||||||
ok = 1;
|
ok = 1;
|
||||||
|
|
||||||
free( m );
|
free( m );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const wchar_t *input_mapping_get( const wchar_t *sequence )
|
const wchar_t *input_mapping_get( const wchar_t *sequence )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
size_t sz = al_get_count( &mappings );
|
size_t sz = al_get_count( &mappings );
|
||||||
|
|
||||||
for( i=0; i<sz; i++ )
|
for( i=0; i<sz; i++ )
|
||||||
{
|
{
|
||||||
input_mapping_t *m = (input_mapping_t *)al_get( &mappings, i );
|
input_mapping_t *m = (input_mapping_t *)al_get( &mappings, i );
|
||||||
|
@ -596,7 +596,7 @@ const wchar_t *input_mapping_get( const wchar_t *sequence )
|
||||||
static void input_terminfo_init()
|
static void input_terminfo_init()
|
||||||
{
|
{
|
||||||
terminfo_mappings = al_halloc( 0 );
|
terminfo_mappings = al_halloc( 0 );
|
||||||
|
|
||||||
|
|
||||||
TERMINFO_ADD(key_a1);
|
TERMINFO_ADD(key_a1);
|
||||||
TERMINFO_ADD(key_a3);
|
TERMINFO_ADD(key_a3);
|
||||||
|
@ -758,7 +758,7 @@ static void input_terminfo_init()
|
||||||
|
|
||||||
static void input_terminfo_destroy()
|
static void input_terminfo_destroy()
|
||||||
{
|
{
|
||||||
|
|
||||||
if( terminfo_mappings )
|
if( terminfo_mappings )
|
||||||
{
|
{
|
||||||
halloc_free( terminfo_mappings );
|
halloc_free( terminfo_mappings );
|
||||||
|
@ -768,17 +768,17 @@ static void input_terminfo_destroy()
|
||||||
const wchar_t *input_terminfo_get_sequence( const wchar_t *name )
|
const wchar_t *input_terminfo_get_sequence( const wchar_t *name )
|
||||||
{
|
{
|
||||||
const char *res = 0;
|
const char *res = 0;
|
||||||
int i;
|
int i;
|
||||||
static string_buffer_t *buff = 0;
|
static string_buffer_t *buff = 0;
|
||||||
int err = ENOENT;
|
int err = ENOENT;
|
||||||
|
|
||||||
CHECK( name, 0 );
|
CHECK( name, 0 );
|
||||||
input_init();
|
input_init();
|
||||||
|
|
||||||
for( i=0; i<al_get_count( terminfo_mappings ); i++ )
|
for( i=0; i<al_get_count( terminfo_mappings ); i++ )
|
||||||
{
|
{
|
||||||
terminfo_mapping_t *m = (terminfo_mapping_t *)al_get( terminfo_mappings, i );
|
terminfo_mapping_t *m = (terminfo_mapping_t *)al_get( terminfo_mappings, i );
|
||||||
|
|
||||||
if( !wcscmp( name, m->name ) )
|
if( !wcscmp( name, m->name ) )
|
||||||
{
|
{
|
||||||
res = m->seq;
|
res = m->seq;
|
||||||
|
@ -786,71 +786,71 @@ const wchar_t *input_terminfo_get_sequence( const wchar_t *name )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !res )
|
if( !res )
|
||||||
{
|
{
|
||||||
errno = err;
|
errno = err;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !buff )
|
if( !buff )
|
||||||
{
|
{
|
||||||
buff = sb_halloc( global_context );
|
buff = sb_halloc( global_context );
|
||||||
}
|
}
|
||||||
|
|
||||||
sb_clear( buff );
|
sb_clear( buff );
|
||||||
sb_printf( buff, L"%s", res );
|
sb_printf( buff, L"%s", res );
|
||||||
|
|
||||||
return (wchar_t *)buff->buff;
|
return (wchar_t *)buff->buff;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const wchar_t *input_terminfo_get_name( const wchar_t *seq )
|
const wchar_t *input_terminfo_get_name( const wchar_t *seq )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
static string_buffer_t *buff = 0;
|
static string_buffer_t *buff = 0;
|
||||||
|
|
||||||
CHECK( seq, 0 );
|
CHECK( seq, 0 );
|
||||||
input_init();
|
input_init();
|
||||||
|
|
||||||
if( !buff )
|
if( !buff )
|
||||||
{
|
{
|
||||||
buff = sb_halloc( global_context );
|
buff = sb_halloc( global_context );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i=0; i<al_get_count( terminfo_mappings ); i++ )
|
for( i=0; i<al_get_count( terminfo_mappings ); i++ )
|
||||||
{
|
{
|
||||||
terminfo_mapping_t *m = (terminfo_mapping_t *)al_get( terminfo_mappings, i );
|
terminfo_mapping_t *m = (terminfo_mapping_t *)al_get( terminfo_mappings, i );
|
||||||
|
|
||||||
if( !m->seq )
|
if( !m->seq )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sb_clear( buff );
|
sb_clear( buff );
|
||||||
sb_printf( buff, L"%s", m->seq );
|
sb_printf( buff, L"%s", m->seq );
|
||||||
|
|
||||||
if( !wcscmp( seq, (wchar_t *)buff->buff ) )
|
if( !wcscmp( seq, (wchar_t *)buff->buff ) )
|
||||||
{
|
{
|
||||||
return m->name;
|
return m->name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void input_terminfo_get_names( array_list_t *lst, int skip_null )
|
void input_terminfo_get_names( array_list_t *lst, int skip_null )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
CHECK( lst, );
|
CHECK( lst, );
|
||||||
input_init();
|
input_init();
|
||||||
|
|
||||||
for( i=0; i<al_get_count( terminfo_mappings ); i++ )
|
for( i=0; i<al_get_count( terminfo_mappings ); i++ )
|
||||||
{
|
{
|
||||||
terminfo_mapping_t *m = (terminfo_mapping_t *)al_get( terminfo_mappings, i );
|
terminfo_mapping_t *m = (terminfo_mapping_t *)al_get( terminfo_mappings, i );
|
||||||
|
|
||||||
if( skip_null && !m->seq )
|
if( skip_null && !m->seq )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -861,10 +861,10 @@ void input_terminfo_get_names( array_list_t *lst, int skip_null )
|
||||||
|
|
||||||
void input_function_get_names( array_list_t *lst )
|
void input_function_get_names( array_list_t *lst )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
CHECK( lst, );
|
CHECK( lst, );
|
||||||
|
|
||||||
for( i=0; i<(sizeof(name_arr)/sizeof(wchar_t *)); i++ )
|
for( i=0; i<(sizeof(name_arr)/sizeof(wchar_t *)); i++ )
|
||||||
{
|
{
|
||||||
al_push( lst, name_arr[i] );
|
al_push( lst, name_arr[i] );
|
||||||
|
@ -882,6 +882,6 @@ wchar_t input_function_get_code( const wchar_t *name )
|
||||||
return code_arr[i];
|
return code_arr[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
input.h
2
input.h
|
@ -83,7 +83,7 @@ wint_t input_readch();
|
||||||
/**
|
/**
|
||||||
Push a character or a readline function onto the stack of unread
|
Push a character or a readline function onto the stack of unread
|
||||||
characters that input_readch will return before actually reading from fd
|
characters that input_readch will return before actually reading from fd
|
||||||
0.
|
0.
|
||||||
*/
|
*/
|
||||||
void input_unreadch( wint_t ch );
|
void input_unreadch( wint_t ch );
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/** \file input_common.c
|
/** \file input_common.c
|
||||||
|
|
||||||
Implementation file for the low level input library
|
Implementation file for the low level input library
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
@ -55,7 +55,7 @@ void input_common_init( int (*ih)() )
|
||||||
|
|
||||||
void input_common_destroy()
|
void input_common_destroy()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,13 +66,13 @@ static wint_t readb()
|
||||||
{
|
{
|
||||||
unsigned char arr[1];
|
unsigned char arr[1];
|
||||||
int do_loop = 0;
|
int do_loop = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
fd_set fd;
|
fd_set fd;
|
||||||
int fd_max=1;
|
int fd_max=1;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
FD_ZERO( &fd );
|
FD_ZERO( &fd );
|
||||||
FD_SET( 0, &fd );
|
FD_SET( 0, &fd );
|
||||||
if( env_universal_server.fd > 0 )
|
if( env_universal_server.fd > 0 )
|
||||||
|
@ -80,9 +80,9 @@ static wint_t readb()
|
||||||
FD_SET( env_universal_server.fd, &fd );
|
FD_SET( env_universal_server.fd, &fd );
|
||||||
fd_max = env_universal_server.fd+1;
|
fd_max = env_universal_server.fd+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
do_loop = 0;
|
do_loop = 0;
|
||||||
|
|
||||||
res = select( fd_max, &fd, 0, 0, 0 );
|
res = select( fd_max, &fd, 0, 0, 0 );
|
||||||
if( res==-1 )
|
if( res==-1 )
|
||||||
{
|
{
|
||||||
|
@ -102,10 +102,10 @@ static wint_t readb()
|
||||||
{
|
{
|
||||||
return lookahead_arr[--lookahead_count];
|
return lookahead_arr[--lookahead_count];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
do_loop = 1;
|
do_loop = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ static wint_t readb()
|
||||||
*/
|
*/
|
||||||
return R_EOF;
|
return R_EOF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -124,7 +124,7 @@ static wint_t readb()
|
||||||
{
|
{
|
||||||
if( FD_ISSET( env_universal_server.fd, &fd ) )
|
if( FD_ISSET( env_universal_server.fd, &fd ) )
|
||||||
{
|
{
|
||||||
debug( 3, L"Wake up on universal variable event" );
|
debug( 3, L"Wake up on universal variable event" );
|
||||||
env_universal_read_all();
|
env_universal_read_all();
|
||||||
do_loop = 1;
|
do_loop = 1;
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ static wint_t readb()
|
||||||
{
|
{
|
||||||
return lookahead_arr[--lookahead_count];
|
return lookahead_arr[--lookahead_count];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( FD_ISSET( 0, &fd ) )
|
if( FD_ISSET( 0, &fd ) )
|
||||||
{
|
{
|
||||||
|
@ -144,11 +144,11 @@ static wint_t readb()
|
||||||
return R_EOF;
|
return R_EOF;
|
||||||
}
|
}
|
||||||
do_loop = 0;
|
do_loop = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while( do_loop );
|
while( do_loop );
|
||||||
|
|
||||||
return arr[0];
|
return arr[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,16 +167,16 @@ wchar_t input_common_readch( int timed )
|
||||||
1000 * WAIT_ON_ESCAPE
|
1000 * WAIT_ON_ESCAPE
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
FD_ZERO( &fds );
|
FD_ZERO( &fds );
|
||||||
FD_SET( 0, &fds );
|
FD_SET( 0, &fds );
|
||||||
count = select(1, &fds, 0, 0, &tm);
|
count = select(1, &fds, 0, 0, &tm);
|
||||||
|
|
||||||
switch( count )
|
switch( count )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
return WEOF;
|
return WEOF;
|
||||||
|
|
||||||
case -1:
|
case -1:
|
||||||
return WEOF;
|
return WEOF;
|
||||||
break;
|
break;
|
||||||
|
@ -185,7 +185,7 @@ wchar_t input_common_readch( int timed )
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t res;
|
wchar_t res;
|
||||||
static mbstate_t state;
|
static mbstate_t state;
|
||||||
|
|
||||||
|
@ -193,33 +193,33 @@ wchar_t input_common_readch( int timed )
|
||||||
{
|
{
|
||||||
wint_t b = readb();
|
wint_t b = readb();
|
||||||
char bb;
|
char bb;
|
||||||
|
|
||||||
int sz;
|
int sz;
|
||||||
|
|
||||||
if( (b >= R_NULL) && (b < R_NULL + 1000) )
|
if( (b >= R_NULL) && (b < R_NULL + 1000) )
|
||||||
return b;
|
return b;
|
||||||
|
|
||||||
bb=b;
|
bb=b;
|
||||||
|
|
||||||
sz = mbrtowc( &res, &bb, 1, &state );
|
sz = mbrtowc( &res, &bb, 1, &state );
|
||||||
|
|
||||||
switch( sz )
|
switch( sz )
|
||||||
{
|
{
|
||||||
case -1:
|
case -1:
|
||||||
memset (&state, '\0', sizeof (state));
|
memset (&state, '\0', sizeof (state));
|
||||||
debug( 2, L"Illegal input" );
|
debug( 2, L"Illegal input" );
|
||||||
return R_NULL;
|
return R_NULL;
|
||||||
case -2:
|
case -2:
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( !timed )
|
if( !timed )
|
||||||
{
|
{
|
||||||
|
@ -228,7 +228,7 @@ wchar_t input_common_readch( int timed )
|
||||||
if( lookahead_count == 0 )
|
if( lookahead_count == 0 )
|
||||||
return input_common_readch(0);
|
return input_common_readch(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return lookahead_arr[--lookahead_count];
|
return lookahead_arr[--lookahead_count];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/** \file input_common.h
|
/** \file input_common.h
|
||||||
|
|
||||||
Header file for the low level input library
|
Header file for the low level input library
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
16
install-sh
16
install-sh
|
@ -115,7 +115,7 @@ fi
|
||||||
if [ x"$dir_arg" != x ]; then
|
if [ x"$dir_arg" != x ]; then
|
||||||
dst=$src
|
dst=$src
|
||||||
src=""
|
src=""
|
||||||
|
|
||||||
if [ -d $dst ]; then
|
if [ -d $dst ]; then
|
||||||
instcmd=:
|
instcmd=:
|
||||||
chmodcmd=""
|
chmodcmd=""
|
||||||
|
@ -125,7 +125,7 @@ if [ x"$dir_arg" != x ]; then
|
||||||
else
|
else
|
||||||
|
|
||||||
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
|
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
|
||||||
# might cause directories to be created, which would be especially bad
|
# might cause directories to be created, which would be especially bad
|
||||||
# if $src (and thus $dsttmp) contains '*'.
|
# if $src (and thus $dsttmp) contains '*'.
|
||||||
|
|
||||||
if [ -f $src -o -d $src ]
|
if [ -f $src -o -d $src ]
|
||||||
|
@ -135,7 +135,7 @@ else
|
||||||
echo "install: $src does not exist"
|
echo "install: $src does not exist"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ x"$dst" = x ]
|
if [ x"$dst" = x ]
|
||||||
then
|
then
|
||||||
echo "install: no destination specified"
|
echo "install: no destination specified"
|
||||||
|
@ -163,7 +163,7 @@ dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
|
||||||
|
|
||||||
# Skip lots of stat calls in the usual case.
|
# Skip lots of stat calls in the usual case.
|
||||||
if [ ! -d "$dstdir" ]; then
|
if [ ! -d "$dstdir" ]; then
|
||||||
defaultIFS='
|
defaultIFS='
|
||||||
'
|
'
|
||||||
IFS="${IFS-${defaultIFS}}"
|
IFS="${IFS-${defaultIFS}}"
|
||||||
|
|
||||||
|
@ -202,17 +202,17 @@ else
|
||||||
|
|
||||||
# If we're going to rename the final executable, determine the name now.
|
# If we're going to rename the final executable, determine the name now.
|
||||||
|
|
||||||
if [ x"$transformarg" = x ]
|
if [ x"$transformarg" = x ]
|
||||||
then
|
then
|
||||||
dstfile=`basename $dst`
|
dstfile=`basename $dst`
|
||||||
else
|
else
|
||||||
dstfile=`basename $dst $transformbasename |
|
dstfile=`basename $dst $transformbasename |
|
||||||
sed $transformarg`$transformbasename
|
sed $transformarg`$transformbasename
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# don't allow the sed command to completely eliminate the filename
|
# don't allow the sed command to completely eliminate the filename
|
||||||
|
|
||||||
if [ x"$dstfile" = x ]
|
if [ x"$dstfile" = x ]
|
||||||
then
|
then
|
||||||
dstfile=`basename $dst`
|
dstfile=`basename $dst`
|
||||||
else
|
else
|
||||||
|
@ -243,7 +243,7 @@ else
|
||||||
# Now rename the file to the real destination.
|
# Now rename the file to the real destination.
|
||||||
|
|
||||||
$doit $rmcmd -f $dstdir/$dstfile &&
|
$doit $rmcmd -f $dstdir/$dstfile &&
|
||||||
$doit $mvcmd $dsttmp $dstdir/$dstfile
|
$doit $mvcmd $dsttmp $dstdir/$dstfile
|
||||||
|
|
||||||
fi &&
|
fi &&
|
||||||
|
|
||||||
|
|
40
intern.c
40
intern.c
|
@ -33,10 +33,10 @@ const wchar_t *intern( const wchar_t *in )
|
||||||
const wchar_t *res=0;
|
const wchar_t *res=0;
|
||||||
|
|
||||||
// debug( 0, L"intern %ls", in );
|
// debug( 0, L"intern %ls", in );
|
||||||
|
|
||||||
if( !in )
|
if( !in )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if( !intern_table )
|
if( !intern_table )
|
||||||
{
|
{
|
||||||
intern_table = malloc( sizeof( hash_table_t ) );
|
intern_table = malloc( sizeof( hash_table_t ) );
|
||||||
|
@ -46,16 +46,16 @@ const wchar_t *intern( const wchar_t *in )
|
||||||
}
|
}
|
||||||
hash_init( intern_table, &hash_wcs_func, &hash_wcs_cmp );
|
hash_init( intern_table, &hash_wcs_func, &hash_wcs_cmp );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( intern_static_table )
|
if( intern_static_table )
|
||||||
{
|
{
|
||||||
res = hash_get( intern_static_table, in );
|
res = hash_get( intern_static_table, in );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !res )
|
if( !res )
|
||||||
{
|
{
|
||||||
res = hash_get( intern_table, in );
|
res = hash_get( intern_table, in );
|
||||||
|
|
||||||
if( !res )
|
if( !res )
|
||||||
{
|
{
|
||||||
res = wcsdup( in );
|
res = wcsdup( in );
|
||||||
|
@ -63,39 +63,39 @@ const wchar_t *intern( const wchar_t *in )
|
||||||
{
|
{
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
}
|
}
|
||||||
|
|
||||||
hash_put( intern_table, res, res );
|
hash_put( intern_table, res, res );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
const wchar_t *intern_static( const wchar_t *in )
|
const wchar_t *intern_static( const wchar_t *in )
|
||||||
{
|
{
|
||||||
const wchar_t *res=0;
|
const wchar_t *res=0;
|
||||||
|
|
||||||
if( !in )
|
if( !in )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if( !intern_static_table )
|
if( !intern_static_table )
|
||||||
{
|
{
|
||||||
intern_static_table = malloc( sizeof( hash_table_t ) );
|
intern_static_table = malloc( sizeof( hash_table_t ) );
|
||||||
if( !intern_static_table )
|
if( !intern_static_table )
|
||||||
{
|
{
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
}
|
}
|
||||||
hash_init( intern_static_table, &hash_wcs_func, &hash_wcs_cmp );
|
hash_init( intern_static_table, &hash_wcs_func, &hash_wcs_cmp );
|
||||||
}
|
}
|
||||||
|
|
||||||
res = hash_get( intern_static_table, in );
|
res = hash_get( intern_static_table, in );
|
||||||
|
|
||||||
if( !res )
|
if( !res )
|
||||||
{
|
{
|
||||||
res = in;
|
res = in;
|
||||||
hash_put( intern_static_table, res, res );
|
hash_put( intern_static_table, res, res );
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ const wchar_t *intern_static( const wchar_t *in )
|
||||||
*/
|
*/
|
||||||
static void clear_value( void *key, void *data )
|
static void clear_value( void *key, void *data )
|
||||||
{
|
{
|
||||||
debug( 3, L"interned string: '%ls'", data );
|
debug( 3, L"interned string: '%ls'", data );
|
||||||
free( (void *)data );
|
free( (void *)data );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,17 +112,17 @@ void intern_free_all()
|
||||||
{
|
{
|
||||||
if( intern_table )
|
if( intern_table )
|
||||||
{
|
{
|
||||||
hash_foreach( intern_table, &clear_value );
|
hash_foreach( intern_table, &clear_value );
|
||||||
hash_destroy( intern_table );
|
hash_destroy( intern_table );
|
||||||
free( intern_table );
|
free( intern_table );
|
||||||
intern_table=0;
|
intern_table=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( intern_static_table )
|
if( intern_static_table )
|
||||||
{
|
{
|
||||||
hash_destroy( intern_static_table );
|
hash_destroy( intern_static_table );
|
||||||
free( intern_static_table );
|
free( intern_static_table );
|
||||||
intern_static_table=0;
|
intern_static_table=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
50
io.c
50
io.c
|
@ -1,7 +1,7 @@
|
||||||
/** \file io.c
|
/** \file io.c
|
||||||
|
|
||||||
Utilities for io redirection.
|
Utilities for io redirection.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ void io_buffer_read( io_data_t *d )
|
||||||
exec_close(d->param1.pipe_fd[1] );
|
exec_close(d->param1.pipe_fd[1] );
|
||||||
|
|
||||||
if( d->io_mode == IO_BUFFER )
|
if( d->io_mode == IO_BUFFER )
|
||||||
{
|
{
|
||||||
/* if( fcntl( d->param1.pipe_fd[0], F_SETFL, 0 ) )
|
/* if( fcntl( d->param1.pipe_fd[0], F_SETFL, 0 ) )
|
||||||
{
|
{
|
||||||
wperror( L"fcntl" );
|
wperror( L"fcntl" );
|
||||||
|
@ -83,17 +83,17 @@ void io_buffer_read( io_data_t *d )
|
||||||
*/
|
*/
|
||||||
if( errno != EAGAIN )
|
if( errno != EAGAIN )
|
||||||
{
|
{
|
||||||
debug( 1,
|
debug( 1,
|
||||||
_(L"An error occured while reading output from code block on file descriptor %d"),
|
_(L"An error occured while reading output from code block on file descriptor %d"),
|
||||||
d->param1.pipe_fd[0] );
|
d->param1.pipe_fd[0] );
|
||||||
wperror( L"io_buffer_read" );
|
wperror( L"io_buffer_read" );
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
b_append( d->param2.out_buffer, b, l );
|
b_append( d->param2.out_buffer, b, l );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,14 +103,14 @@ void io_buffer_read( io_data_t *d )
|
||||||
io_data_t *io_buffer_create( int is_input )
|
io_data_t *io_buffer_create( int is_input )
|
||||||
{
|
{
|
||||||
io_data_t *buffer_redirect = malloc( sizeof( io_data_t ));
|
io_data_t *buffer_redirect = malloc( sizeof( io_data_t ));
|
||||||
|
|
||||||
buffer_redirect->io_mode=IO_BUFFER;
|
buffer_redirect->io_mode=IO_BUFFER;
|
||||||
buffer_redirect->next=0;
|
buffer_redirect->next=0;
|
||||||
buffer_redirect->param2.out_buffer= malloc( sizeof(buffer_t));
|
buffer_redirect->param2.out_buffer= malloc( sizeof(buffer_t));
|
||||||
buffer_redirect->is_input = is_input;
|
buffer_redirect->is_input = is_input;
|
||||||
b_init( buffer_redirect->param2.out_buffer );
|
b_init( buffer_redirect->param2.out_buffer );
|
||||||
buffer_redirect->fd=is_input?0:1;
|
buffer_redirect->fd=is_input?0:1;
|
||||||
|
|
||||||
if( exec_pipe( buffer_redirect->param1.pipe_fd ) == -1 )
|
if( exec_pipe( buffer_redirect->param1.pipe_fd ) == -1 )
|
||||||
{
|
{
|
||||||
debug( 1, PIPE_ERROR );
|
debug( 1, PIPE_ERROR );
|
||||||
|
@ -150,9 +150,9 @@ void io_buffer_destroy( io_data_t *io_buffer )
|
||||||
Dont free fd for writing. This should already be free'd before
|
Dont free fd for writing. This should already be free'd before
|
||||||
calling exec_read_io_buffer on the buffer
|
calling exec_read_io_buffer on the buffer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
b_destroy( io_buffer->param2.out_buffer );
|
b_destroy( io_buffer->param2.out_buffer );
|
||||||
|
|
||||||
free( io_buffer->param2.out_buffer );
|
free( io_buffer->param2.out_buffer );
|
||||||
free( io_buffer );
|
free( io_buffer );
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ io_data_t *io_remove( io_data_t *list, io_data_t *element )
|
||||||
{
|
{
|
||||||
io_data_t *curr, *prev=0;
|
io_data_t *curr, *prev=0;
|
||||||
for( curr=list; curr; curr = curr->next )
|
for( curr=list; curr; curr = curr->next )
|
||||||
{
|
{
|
||||||
if( element == curr )
|
if( element == curr )
|
||||||
{
|
{
|
||||||
if( prev == 0 )
|
if( prev == 0 )
|
||||||
|
@ -198,32 +198,32 @@ io_data_t *io_remove( io_data_t *list, io_data_t *element )
|
||||||
io_data_t *io_duplicate( void *context, io_data_t *l )
|
io_data_t *io_duplicate( void *context, io_data_t *l )
|
||||||
{
|
{
|
||||||
io_data_t *res;
|
io_data_t *res;
|
||||||
|
|
||||||
if( l == 0 )
|
if( l == 0 )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
res = halloc( context, sizeof( io_data_t) );
|
res = halloc( context, sizeof( io_data_t) );
|
||||||
|
|
||||||
if( !res )
|
if( !res )
|
||||||
{
|
{
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy( res, l, sizeof(io_data_t ));
|
memcpy( res, l, sizeof(io_data_t ));
|
||||||
res->next=io_duplicate( context, l->next );
|
res->next=io_duplicate( context, l->next );
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
io_data_t *io_get( io_data_t *io, int fd )
|
io_data_t *io_get( io_data_t *io, int fd )
|
||||||
{
|
{
|
||||||
if( io == 0 )
|
if( io == 0 )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
io_data_t *res = io_get( io->next, fd );
|
io_data_t *res = io_get( io->next, fd );
|
||||||
if( res )
|
if( res )
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
if( io->fd == fd )
|
if( io->fd == fd )
|
||||||
return io;
|
return io;
|
||||||
|
|
||||||
|
@ -237,14 +237,14 @@ void io_print( io_data_t *io )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug( 1, L"IO fd %d, type ", io->fd );
|
debug( 1, L"IO fd %d, type ", io->fd );
|
||||||
switch( io->io_mode )
|
switch( io->io_mode )
|
||||||
{
|
{
|
||||||
case IO_PIPE:
|
case IO_PIPE:
|
||||||
debug( 1, L"PIPE, data %d", io->param1.pipe_fd[io->fd?1:0] );
|
debug( 1, L"PIPE, data %d", io->param1.pipe_fd[io->fd?1:0] );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IO_FD:
|
case IO_FD:
|
||||||
debug( 1, L"FD, copy %d", io->param1.old_fd );
|
debug( 1, L"FD, copy %d", io->param1.old_fd );
|
||||||
break;
|
break;
|
||||||
|
@ -252,11 +252,11 @@ void io_print( io_data_t *io )
|
||||||
case IO_BUFFER:
|
case IO_BUFFER:
|
||||||
debug( 1, L"BUFFER" );
|
debug( 1, L"BUFFER" );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
debug( 1, L"OTHER" );
|
debug( 1, L"OTHER" );
|
||||||
}
|
}
|
||||||
|
|
||||||
io_print( io->next );
|
io_print( io->next );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
12
io.h
12
io.h
|
@ -17,8 +17,8 @@ typedef struct io_data
|
||||||
int io_mode;
|
int io_mode;
|
||||||
/** FD to redirect */
|
/** FD to redirect */
|
||||||
int fd;
|
int fd;
|
||||||
/**
|
/**
|
||||||
Type-specific parameter for redirection
|
Type-specific parameter for redirection
|
||||||
*/
|
*/
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
|
@ -30,7 +30,7 @@ typedef struct io_data
|
||||||
int old_fd;
|
int old_fd;
|
||||||
} param1
|
} param1
|
||||||
;
|
;
|
||||||
/**
|
/**
|
||||||
Second type-specific paramter for redirection
|
Second type-specific paramter for redirection
|
||||||
*/
|
*/
|
||||||
union
|
union
|
||||||
|
@ -38,7 +38,7 @@ typedef struct io_data
|
||||||
/** file creation flags to send to open for IO_FILE */
|
/** file creation flags to send to open for IO_FILE */
|
||||||
int flags;
|
int flags;
|
||||||
/** buffer to save output in for IO_BUFFER */
|
/** buffer to save output in for IO_BUFFER */
|
||||||
buffer_t *out_buffer;
|
buffer_t *out_buffer;
|
||||||
/** Whether to close old_fd for IO_FD */
|
/** Whether to close old_fd for IO_FD */
|
||||||
int close_old;
|
int close_old;
|
||||||
} param2
|
} param2
|
||||||
|
@ -48,13 +48,13 @@ typedef struct io_data
|
||||||
Set to true if this is an input io redirection
|
Set to true if this is an input io redirection
|
||||||
*/
|
*/
|
||||||
int is_input;
|
int is_input;
|
||||||
|
|
||||||
/** Pointer to the next IO redirection */
|
/** Pointer to the next IO redirection */
|
||||||
struct io_data *next;
|
struct io_data *next;
|
||||||
}
|
}
|
||||||
io_data_t;
|
io_data_t;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Join two chains of io redirections
|
Join two chains of io redirections
|
||||||
*/
|
*/
|
||||||
|
|
22
key_reader.c
22
key_reader.c
|
@ -29,7 +29,7 @@ int main( int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
setlocale( LC_ALL, "" );
|
setlocale( LC_ALL, "" );
|
||||||
|
|
||||||
|
|
||||||
if( argc == 2 )
|
if( argc == 2 )
|
||||||
{
|
{
|
||||||
|
@ -37,24 +37,24 @@ int main( int argc, char **argv)
|
||||||
char *termtype = getenv ("TERM");
|
char *termtype = getenv ("TERM");
|
||||||
char *tbuff = malloc( sizeof(char)*9999);
|
char *tbuff = malloc( sizeof(char)*9999);
|
||||||
char *res;
|
char *res;
|
||||||
|
|
||||||
tgetent( term_buffer, termtype );
|
tgetent( term_buffer, termtype );
|
||||||
res = tgetstr( argv[1], &tbuff );
|
res = tgetstr( argv[1], &tbuff );
|
||||||
if( res != 0 )
|
if( res != 0 )
|
||||||
{
|
{
|
||||||
while( *res != 0 )
|
while( *res != 0 )
|
||||||
{
|
{
|
||||||
printf("%d ", *res );
|
printf("%d ", *res );
|
||||||
|
|
||||||
|
|
||||||
res++;
|
res++;
|
||||||
}
|
}
|
||||||
printf( "\n" );
|
printf( "\n" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Undefined sequence\n");
|
printf("Undefined sequence\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -65,11 +65,11 @@ int main( int argc, char **argv)
|
||||||
savemodes; /* so we can reset the modes when we're done */
|
savemodes; /* so we can reset the modes when we're done */
|
||||||
|
|
||||||
input_common_init(0);
|
input_common_init(0);
|
||||||
|
|
||||||
|
|
||||||
tcgetattr(0,&modes); /* get the current terminal modes */
|
tcgetattr(0,&modes); /* get the current terminal modes */
|
||||||
savemodes = modes; /* save a copy so we can reset them */
|
savemodes = modes; /* save a copy so we can reset them */
|
||||||
|
|
||||||
modes.c_lflag &= ~ICANON; /* turn off canonical mode */
|
modes.c_lflag &= ~ICANON; /* turn off canonical mode */
|
||||||
modes.c_lflag &= ~ECHO; /* turn off echo mode */
|
modes.c_lflag &= ~ECHO; /* turn off echo mode */
|
||||||
modes.c_cc[VMIN]=1;
|
modes.c_cc[VMIN]=1;
|
||||||
|
@ -83,13 +83,13 @@ int main( int argc, char **argv)
|
||||||
sprintf( scratch, "dec: %d hex: %x char: %c\n", c, c, c );
|
sprintf( scratch, "dec: %d hex: %x char: %c\n", c, c, c );
|
||||||
else
|
else
|
||||||
sprintf( scratch, "dec: %d hex: %x\n", c, c );
|
sprintf( scratch, "dec: %d hex: %x\n", c, c );
|
||||||
writestr( scratch );
|
writestr( scratch );
|
||||||
}
|
}
|
||||||
/* reset the terminal to the saved mode */
|
/* reset the terminal to the saved mode */
|
||||||
tcsetattr(0,TCSANOW,&savemodes);
|
tcsetattr(0,TCSANOW,&savemodes);
|
||||||
|
|
||||||
input_common_destroy();
|
input_common_destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
154
kill.c
154
kill.c
|
@ -45,21 +45,21 @@ static ll_node_t /** Last kill string */*kill_last=0, /** Current kill string */
|
||||||
static wchar_t *cut_buffer=0;
|
static wchar_t *cut_buffer=0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Test if the xsel command is installed. Since this is called often,
|
Test if the xsel command is installed. Since this is called often,
|
||||||
cache the result.
|
cache the result.
|
||||||
*/
|
*/
|
||||||
static int has_xsel()
|
static int has_xsel()
|
||||||
{
|
{
|
||||||
static int called=0;
|
static int called=0;
|
||||||
static int res = 0;
|
static int res = 0;
|
||||||
|
|
||||||
if (!called) {
|
if (!called) {
|
||||||
void *context = halloc(0, 0);
|
void *context = halloc(0, 0);
|
||||||
wchar_t *path = path_get_path( context, L"xsel" );
|
wchar_t *path = path_get_path( context, L"xsel" );
|
||||||
res = !!path;
|
res = !!path;
|
||||||
halloc_free( context );
|
halloc_free( context );
|
||||||
called = 1;
|
called = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ static void kill_add_internal( wchar_t *str )
|
||||||
{
|
{
|
||||||
if( wcslen( str ) == 0 )
|
if( wcslen( str ) == 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( kill_last == 0 )
|
if( kill_last == 0 )
|
||||||
{
|
{
|
||||||
kill_current = kill_last=malloc( sizeof( ll_node_t ) );
|
kill_current = kill_last=malloc( sizeof( ll_node_t ) );
|
||||||
|
@ -93,51 +93,51 @@ static void kill_add_internal( wchar_t *str )
|
||||||
void kill_add( wchar_t *str )
|
void kill_add( wchar_t *str )
|
||||||
{
|
{
|
||||||
wchar_t *cmd = NULL;
|
wchar_t *cmd = NULL;
|
||||||
wchar_t *escaped_str;
|
wchar_t *escaped_str;
|
||||||
kill_add_internal(str);
|
kill_add_internal(str);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Check to see if user has set the FISH_CLIPBOARD_CMD variable,
|
Check to see if user has set the FISH_CLIPBOARD_CMD variable,
|
||||||
and, if so, use it instead of checking the display, etc.
|
and, if so, use it instead of checking the display, etc.
|
||||||
|
|
||||||
I couldn't think of a safe way to allow overide of the echo
|
I couldn't think of a safe way to allow overide of the echo
|
||||||
command too, so, the command used must accept the input via stdin.
|
command too, so, the command used must accept the input via stdin.
|
||||||
*/
|
*/
|
||||||
wchar_t *clipboard;
|
wchar_t *clipboard;
|
||||||
if( (clipboard = env_get(L"FISH_CLIPBOARD_CMD")) )
|
if( (clipboard = env_get(L"FISH_CLIPBOARD_CMD")) )
|
||||||
{
|
{
|
||||||
escaped_str = escape( str, 1 );
|
escaped_str = escape( str, 1 );
|
||||||
cmd = wcsdupcat(L"echo -n ", escaped_str, clipboard);
|
cmd = wcsdupcat(L"echo -n ", escaped_str, clipboard);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* This is for sending the kill to the X copy-and-paste buffer */
|
/* This is for sending the kill to the X copy-and-paste buffer */
|
||||||
if( !has_xsel() ) {
|
if( !has_xsel() ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t *disp;
|
wchar_t *disp;
|
||||||
if( (disp = env_get( L"DISPLAY" )) )
|
if( (disp = env_get( L"DISPLAY" )) )
|
||||||
{
|
{
|
||||||
escaped_str = escape( str, 1 );
|
escaped_str = escape( str, 1 );
|
||||||
cmd = wcsdupcat(L"echo ", escaped_str, L"|xsel -b" );
|
cmd = wcsdupcat(L"echo ", escaped_str, L"|xsel -b" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd != NULL)
|
if (cmd != NULL)
|
||||||
{
|
{
|
||||||
if( exec_subshell( cmd, 0 ) == -1 )
|
if( exec_subshell( cmd, 0 ) == -1 )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Do nothing on failiure
|
Do nothing on failiure
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
free( cut_buffer );
|
free( cut_buffer );
|
||||||
free( cmd );
|
free( cmd );
|
||||||
|
|
||||||
cut_buffer = escaped_str;
|
cut_buffer = escaped_str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,8 +164,8 @@ static void kill_remove_node( ll_node_t *n )
|
||||||
}
|
}
|
||||||
kill_current=kill_last;
|
kill_current=kill_last;
|
||||||
free( n->data );
|
free( n->data );
|
||||||
free( n );
|
free( n );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -174,13 +174,13 @@ static void kill_remove_node( ll_node_t *n )
|
||||||
static void kill_remove( wchar_t *s )
|
static void kill_remove( wchar_t *s )
|
||||||
{
|
{
|
||||||
ll_node_t *n, *next=0;
|
ll_node_t *n, *next=0;
|
||||||
|
|
||||||
if( !kill_last )
|
if( !kill_last )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( n=kill_last;
|
for( n=kill_last;
|
||||||
n!=kill_last || next == 0 ;
|
n!=kill_last || next == 0 ;
|
||||||
n=n->prev )
|
n=n->prev )
|
||||||
{
|
{
|
||||||
|
@ -192,13 +192,13 @@ static void kill_remove( wchar_t *s )
|
||||||
next = n;
|
next = n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void kill_replace( wchar_t *old, wchar_t *new )
|
void kill_replace( wchar_t *old, wchar_t *new )
|
||||||
{
|
{
|
||||||
kill_remove( old );
|
kill_remove( old );
|
||||||
kill_add( new );
|
kill_add( new );
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t *kill_yank_rotate()
|
wchar_t *kill_yank_rotate()
|
||||||
|
@ -214,13 +214,13 @@ wchar_t *kill_yank_rotate()
|
||||||
clipboard contents to the fish killring.
|
clipboard contents to the fish killring.
|
||||||
*/
|
*/
|
||||||
static void kill_check_x_buffer()
|
static void kill_check_x_buffer()
|
||||||
{
|
{
|
||||||
wchar_t *disp;
|
wchar_t *disp;
|
||||||
|
|
||||||
if( !has_xsel() )
|
if( !has_xsel() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
if( (disp = env_get( L"DISPLAY" )) )
|
if( (disp = env_get( L"DISPLAY" )) )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -230,7 +230,7 @@ static void kill_check_x_buffer()
|
||||||
al_init( &list );
|
al_init( &list );
|
||||||
if( exec_subshell( cmd, &list ) != -1 )
|
if( exec_subshell( cmd, &list ) != -1 )
|
||||||
{
|
{
|
||||||
|
|
||||||
for( i=0; i<al_get_count( &list ); i++ )
|
for( i=0; i<al_get_count( &list ); i++ )
|
||||||
{
|
{
|
||||||
wchar_t *next_line = escape( (wchar_t *)al_get( &list, i ), 0 );
|
wchar_t *next_line = escape( (wchar_t *)al_get( &list, i ), 0 );
|
||||||
|
@ -243,20 +243,20 @@ static void kill_check_x_buffer()
|
||||||
wchar_t *old = new_cut_buffer;
|
wchar_t *old = new_cut_buffer;
|
||||||
new_cut_buffer= wcsdupcat( new_cut_buffer, L"\\n", next_line );
|
new_cut_buffer= wcsdupcat( new_cut_buffer, L"\\n", next_line );
|
||||||
free( old );
|
free( old );
|
||||||
free( next_line );
|
free( next_line );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( new_cut_buffer )
|
if( new_cut_buffer )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
The buffer is inserted with backslash escapes,
|
The buffer is inserted with backslash escapes,
|
||||||
since we don't really like tabs, newlines,
|
since we don't really like tabs, newlines,
|
||||||
etc. anyway.
|
etc. anyway.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( cut_buffer != 0 )
|
if( cut_buffer != 0 )
|
||||||
{
|
{
|
||||||
if( wcscmp( new_cut_buffer, cut_buffer ) == 0 )
|
if( wcscmp( new_cut_buffer, cut_buffer ) == 0 )
|
||||||
{
|
{
|
||||||
free( new_cut_buffer );
|
free( new_cut_buffer );
|
||||||
|
@ -265,7 +265,7 @@ static void kill_check_x_buffer()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
free( cut_buffer );
|
free( cut_buffer );
|
||||||
cut_buffer = 0;
|
cut_buffer = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( cut_buffer == 0 )
|
if( cut_buffer == 0 )
|
||||||
|
@ -275,7 +275,7 @@ static void kill_check_x_buffer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
al_foreach( &list, &free );
|
al_foreach( &list, &free );
|
||||||
al_destroy( &list );
|
al_destroy( &list );
|
||||||
}
|
}
|
||||||
|
@ -307,22 +307,22 @@ void kill_sanity_check()
|
||||||
break;
|
break;
|
||||||
if( tmp->data == 0 )
|
if( tmp->data == 0 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if( tmp == kill_current )
|
if( tmp == kill_current )
|
||||||
{
|
{
|
||||||
kill_ok = 1;
|
kill_ok = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tmp = tmp->prev;
|
tmp = tmp->prev;
|
||||||
}
|
}
|
||||||
if( !kill_ok )
|
if( !kill_ok )
|
||||||
{
|
{
|
||||||
debug( 0,
|
debug( 0,
|
||||||
L"Killring inconsistent" );
|
L"Killring inconsistent" );
|
||||||
sanity_lose();
|
sanity_lose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,12 +334,12 @@ void kill_destroy()
|
||||||
{
|
{
|
||||||
if( cut_buffer )
|
if( cut_buffer )
|
||||||
free( cut_buffer );
|
free( cut_buffer );
|
||||||
|
|
||||||
if( kill_current != 0 )
|
if( kill_current != 0 )
|
||||||
{
|
{
|
||||||
kill_current = kill_last->prev;
|
kill_current = kill_last->prev;
|
||||||
kill_last->prev = 0;
|
kill_last->prev = 0;
|
||||||
|
|
||||||
while( kill_current )
|
while( kill_current )
|
||||||
{
|
{
|
||||||
ll_node_t *tmp = kill_current;
|
ll_node_t *tmp = kill_current;
|
||||||
|
@ -347,7 +347,7 @@ void kill_destroy()
|
||||||
free( tmp->data );
|
free( tmp->data );
|
||||||
free( tmp );
|
free( tmp );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,13 +39,13 @@ def print_completion( cmd, switch_arr, arg, desc ):
|
||||||
|
|
||||||
if len(switch_arr)==0:
|
if len(switch_arr)==0:
|
||||||
return
|
return
|
||||||
|
|
||||||
res = "complete -c %s" % (cmd)
|
res = "complete -c %s" % (cmd)
|
||||||
for sw in switch_arr:
|
for sw in switch_arr:
|
||||||
|
|
||||||
offset=1
|
offset=1
|
||||||
switch_type = "o"
|
switch_type = "o"
|
||||||
|
|
||||||
if len(sw) == 2:
|
if len(sw) == 2:
|
||||||
switch_type = "s"
|
switch_type = "s"
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ for c in man:
|
||||||
can_be_switch = True
|
can_be_switch = True
|
||||||
elif before_switch.find(c)<0:
|
elif before_switch.find(c)<0:
|
||||||
can_be_switch = False
|
can_be_switch = False
|
||||||
|
|
||||||
|
|
||||||
elif mode == MODE_SWITCH:
|
elif mode == MODE_SWITCH:
|
||||||
if not switch_end.find(c)>=0:
|
if not switch_end.find(c)>=0:
|
||||||
|
@ -106,7 +106,7 @@ for c in man:
|
||||||
else:
|
else:
|
||||||
if len(sw) > 1:
|
if len(sw) > 1:
|
||||||
sw_arr.append(sw)
|
sw_arr.append(sw)
|
||||||
|
|
||||||
if switch_between_ignore.find(c) >= 0:
|
if switch_between_ignore.find(c) >= 0:
|
||||||
mode=MODE_BETWEEN_IGNORE
|
mode=MODE_BETWEEN_IGNORE
|
||||||
else:
|
else:
|
||||||
|
@ -124,7 +124,7 @@ for c in man:
|
||||||
elif not switch_between_continue.find(c) >= 0:
|
elif not switch_between_continue.find(c) >= 0:
|
||||||
mode = MODE_DESC
|
mode = MODE_DESC
|
||||||
desc = c
|
desc = c
|
||||||
|
|
||||||
elif mode == MODE_BETWEEN_IGNORE:
|
elif mode == MODE_BETWEEN_IGNORE:
|
||||||
if between_ignore.find(c)>=0:
|
if between_ignore.find(c)>=0:
|
||||||
mode = MODE_BETWEEN
|
mode = MODE_BETWEEN
|
||||||
|
@ -139,20 +139,20 @@ for c in man:
|
||||||
if c == '\n' and pc == '\n':
|
if c == '\n' and pc == '\n':
|
||||||
stop=True
|
stop=True
|
||||||
|
|
||||||
if stop:
|
if stop:
|
||||||
mode=MODE_NONE
|
mode=MODE_NONE
|
||||||
|
|
||||||
print_completion( cmd, sw_arr, None, desc )
|
print_completion( cmd, sw_arr, None, desc )
|
||||||
|
|
||||||
sw_arr = []
|
sw_arr = []
|
||||||
|
|
||||||
desc = ''
|
desc = ''
|
||||||
|
|
||||||
else:
|
else:
|
||||||
desc += c
|
desc += c
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "Unknown mode", mode
|
print "Unknown mode", mode
|
||||||
|
|
||||||
pc = c
|
pc = c
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ end
|
||||||
|
|
||||||
#
|
#
|
||||||
# This function formats a list of completion information into a set of fish completions
|
# 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 first argument is the condition string, which will be copied to
|
||||||
# the resulting commandline verbatim
|
# the resulting commandline verbatim
|
||||||
#
|
#
|
||||||
|
@ -42,7 +42,7 @@ function complete_from_list
|
||||||
set arg $exploded[3]
|
set arg $exploded[3]
|
||||||
set desc (cap (esc $exploded[4]))
|
set desc (cap (esc $exploded[4]))
|
||||||
|
|
||||||
set str
|
set str
|
||||||
|
|
||||||
switch $short
|
switch $short
|
||||||
case '-?'
|
case '-?'
|
||||||
|
@ -65,7 +65,7 @@ function complete_from_list
|
||||||
set str $str -x -a "'(__fish_complete_users)'"
|
set str $str -x -a "'(__fish_complete_users)'"
|
||||||
|
|
||||||
case '=FILENAME' '=FILE' ' <file>'
|
case '=FILENAME' '=FILE' ' <file>'
|
||||||
set str $str -r
|
set str $str -r
|
||||||
|
|
||||||
case ' arg'
|
case ' arg'
|
||||||
set str $str -x
|
set str $str -x
|
||||||
|
@ -89,7 +89,7 @@ function complete_from_list
|
||||||
set str $str --description \'$desc\'
|
set str $str --description \'$desc\'
|
||||||
end
|
end
|
||||||
|
|
||||||
echo complete -c $cmd $condition $str
|
echo complete -c $cmd $condition $str
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ function write_completions
|
||||||
set -g cmd $argv[1]; or return 1
|
set -g cmd $argv[1]; or return 1
|
||||||
|
|
||||||
echo "Making completions for $cmd" >&2
|
echo "Making completions for $cmd" >&2
|
||||||
|
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
#
|
#
|
||||||
|
@ -129,7 +129,7 @@ function write_completions
|
||||||
switch $cmd
|
switch $cmd
|
||||||
case svn
|
case svn
|
||||||
|
|
||||||
function list_subcommand
|
function list_subcommand
|
||||||
set cmd1 '\([^ ]*\)'
|
set cmd1 '\([^ ]*\)'
|
||||||
set cmd2 '\([^,)]*\)'
|
set cmd2 '\([^,)]*\)'
|
||||||
set cmdn '\(, \([^,)]*\)\|\)'
|
set cmdn '\(, \([^,)]*\)\|\)'
|
||||||
|
@ -155,7 +155,7 @@ function write_completions
|
||||||
|
|
||||||
case cvs
|
case cvs
|
||||||
|
|
||||||
function list_subcommand
|
function list_subcommand
|
||||||
cmd --help-commands 2>| sed -n -e 's/^ *\([^ ][^ ]*\) .*$/\1/p'
|
cmd --help-commands 2>| sed -n -e 's/^ *\([^ ][^ ]*\) .*$/\1/p'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ function write_completions
|
||||||
function list_subcommand_help
|
function list_subcommand_help
|
||||||
#'s/^[ \t]*\(-.\)[ \t]\([^- \t][^ \t]*\)*[ \t]*\([^-].*\)$/\1\t\2\t\3/p'
|
#'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'
|
cmd -H $argv 2>| sed -n -e 's/'$re'/\1\t\t\2\t\4/p'
|
||||||
end
|
end
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
|
@ -181,12 +181,12 @@ function write_completions
|
||||||
set cmd_str_internal (cmd --help-commands 2>| sed -n -e 's/^ *\([^ ][^ ]*\)[\t ]*\([^ ].*\)$/\1\t\2/p')
|
set cmd_str_internal (cmd --help-commands 2>| sed -n -e 's/^ *\([^ ][^ ]*\)[\t ]*\([^ ].*\)$/\1\t\2/p')
|
||||||
for i in $cmd_str_internal
|
for i in $cmd_str_internal
|
||||||
set exploded (echo $i|tr \t \n)
|
set exploded (echo $i|tr \t \n)
|
||||||
set cmd_str $cmd_str "-a $exploded[1] --description '"(esc $exploded[2])"'"
|
set cmd_str $cmd_str "-a $exploded[1] --description '"(esc $exploded[2])"'"
|
||||||
end
|
end
|
||||||
|
|
||||||
case '*'
|
case '*'
|
||||||
|
|
||||||
function list_subcommand
|
function list_subcommand
|
||||||
cmd help | sed -n -e 's/^ *\([^ ][^ ]*\) .*$/\1/p'
|
cmd help | sed -n -e 's/^ *\([^ ][^ ]*\) .*$/\1/p'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ function write_completions
|
||||||
set cmd_str (cmd help | sed -n -e 's/^ *\([^ ][^ ]*\)[\t ]*\([^ ].*[^.]\)\(\|\\.\)$/-a \1 --description \'\2\'/p')
|
set cmd_str (cmd help | sed -n -e 's/^ *\([^ ][^ ]*\)[\t ]*\([^ ].*[^.]\)\(\|\\.\)$/-a \1 --description \'\2\'/p')
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
#
|
#
|
||||||
# subcommands
|
# subcommands
|
||||||
|
@ -228,8 +228,8 @@ function write_completions
|
||||||
|
|
||||||
end
|
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 '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'
|
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 darcs $darcs_comp >share/completions/darcs.fish
|
||||||
write_completions hg >share/completions/hg.fish
|
write_completions hg >share/completions/hg.fish
|
||||||
|
|
324
mimedb.c
324
mimedb.c
|
@ -1,8 +1,8 @@
|
||||||
/** \file mimedb.c
|
/** \file mimedb.c
|
||||||
|
|
||||||
mimedb is a program for checking the mimetype, description and
|
mimedb is a program for checking the mimetype, description and
|
||||||
default action associated with a file or mimetype. It uses the
|
default action associated with a file or mimetype. It uses the
|
||||||
xdgmime library written by the fine folks at freedesktop.org. There does
|
xdgmime library written by the fine folks at freedesktop.org. There does
|
||||||
not seem to be any standard way for the user to change the preferred
|
not seem to be any standard way for the user to change the preferred
|
||||||
application yet.
|
application yet.
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ license. Read the source code of the library for more information.
|
||||||
/**
|
/**
|
||||||
Error message if system call goes wrong.
|
Error message if system call goes wrong.
|
||||||
*/
|
*/
|
||||||
#define ERROR_SYSTEM "%s: Could not execute command \"%s\"\n"
|
#define ERROR_SYSTEM "%s: Could not execute command \"%s\"\n"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Exit code if system call goes wrong.
|
Exit code if system call goes wrong.
|
||||||
|
@ -194,8 +194,8 @@ static char * search_ini( const char *filename, const char *match )
|
||||||
FILE *f = fopen( filename, "r" );
|
FILE *f = fopen( filename, "r" );
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
int len=strlen(match);
|
int len=strlen(match);
|
||||||
int done = 0;
|
int done = 0;
|
||||||
|
|
||||||
if(!f )
|
if(!f )
|
||||||
{
|
{
|
||||||
perror( "fopen" );
|
perror( "fopen" );
|
||||||
|
@ -210,14 +210,14 @@ static char * search_ini( const char *filename, const char *match )
|
||||||
{
|
{
|
||||||
perror( "fgets" );
|
perror( "fgets" );
|
||||||
error=1;
|
error=1;
|
||||||
}
|
}
|
||||||
buf[0]=0;
|
buf[0]=0;
|
||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
else if( strncmp( buf, match,len )==0)
|
else if( strncmp( buf, match,len )==0)
|
||||||
{
|
{
|
||||||
done=1;
|
done=1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose( f );
|
fclose( f );
|
||||||
if( buf[0] )
|
if( buf[0] )
|
||||||
|
@ -245,29 +245,29 @@ static char *file_exists( const char *dir, const char *in )
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
|
|
||||||
// fprintf( stderr, "Check %s%s\n", dir, in );
|
// fprintf( stderr, "Check %s%s\n", dir, in );
|
||||||
|
|
||||||
if( !filename )
|
if( !filename )
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
strcpy( filename, dir );
|
strcpy( filename, dir );
|
||||||
strcat( filename, in );
|
strcat( filename, in );
|
||||||
|
|
||||||
if( !stat( filename, &buf ) )
|
if( !stat( filename, &buf ) )
|
||||||
return filename;
|
return filename;
|
||||||
|
|
||||||
free( filename );
|
free( filename );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
DOH! File does not exist. But all is not lost. KDE sometimes uses
|
DOH! File does not exist. But all is not lost. KDE sometimes uses
|
||||||
a slash in the name as a directory separator. We try to replace
|
a slash in the name as a directory separator. We try to replace
|
||||||
a dash with a slash and try again.
|
a dash with a slash and try again.
|
||||||
*/
|
*/
|
||||||
replaceme = strchr( in, '-' );
|
replaceme = strchr( in, '-' );
|
||||||
if( replaceme )
|
if( replaceme )
|
||||||
{
|
{
|
||||||
char *res;
|
char *res;
|
||||||
|
|
||||||
*replaceme = '/';
|
*replaceme = '/';
|
||||||
res = file_exists( dir, in );
|
res = file_exists( dir, in );
|
||||||
*replaceme = '-';
|
*replaceme = '-';
|
||||||
|
@ -296,7 +296,7 @@ static char *get_filename( char *f )
|
||||||
xdg_data_home = getenv ("XDG_DATA_HOME");
|
xdg_data_home = getenv ("XDG_DATA_HOME");
|
||||||
if (xdg_data_home)
|
if (xdg_data_home)
|
||||||
{
|
{
|
||||||
result = file_exists( xdg_data_home, f );
|
result = file_exists( xdg_data_home, f );
|
||||||
if (result)
|
if (result)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -312,10 +312,10 @@ static char *get_filename( char *f )
|
||||||
guessed_xdg_home = my_malloc (strlen (home) + strlen ("/.local/share/") + 1);
|
guessed_xdg_home = my_malloc (strlen (home) + strlen ("/.local/share/") + 1);
|
||||||
if( !guessed_xdg_home )
|
if( !guessed_xdg_home )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
strcpy (guessed_xdg_home, home);
|
strcpy (guessed_xdg_home, home);
|
||||||
strcat (guessed_xdg_home, "/.local/share/");
|
strcat (guessed_xdg_home, "/.local/share/");
|
||||||
result = file_exists( guessed_xdg_home, f );
|
result = file_exists( guessed_xdg_home, f );
|
||||||
free (guessed_xdg_home);
|
free (guessed_xdg_home);
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
|
@ -352,11 +352,11 @@ static char *get_filename( char *f )
|
||||||
dir = my_malloc (len + 1);
|
dir = my_malloc (len + 1);
|
||||||
if( !dir )
|
if( !dir )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
strncpy (dir, ptr, len);
|
strncpy (dir, ptr, len);
|
||||||
dir[len] = '\0';
|
dir[len] = '\0';
|
||||||
result = file_exists( dir, f );
|
result = file_exists( dir, f );
|
||||||
|
|
||||||
free (dir);
|
free (dir);
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
|
@ -364,7 +364,7 @@ static char *get_filename( char *f )
|
||||||
|
|
||||||
ptr = end_ptr;
|
ptr = end_ptr;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -382,11 +382,11 @@ static char *munge( char *in )
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
// fprintf( stderr, "%c\n", *in );
|
// fprintf( stderr, "%c\n", *in );
|
||||||
|
|
||||||
switch( *in )
|
switch( *in )
|
||||||
{
|
{
|
||||||
case ' ':
|
case ' ':
|
||||||
|
@ -407,7 +407,7 @@ static char *munge( char *in )
|
||||||
*(p++)=' ';
|
*(p++)=' ';
|
||||||
}
|
}
|
||||||
printed=1;
|
printed=1;
|
||||||
had_whitespace=0;
|
had_whitespace=0;
|
||||||
*(p++)=*in;
|
*(p++)=*in;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -424,19 +424,19 @@ static char *munge( char *in )
|
||||||
*/
|
*/
|
||||||
static char *get_lang_re()
|
static char *get_lang_re()
|
||||||
{
|
{
|
||||||
|
|
||||||
static char buff[BUFF_SIZE];
|
static char buff[BUFF_SIZE];
|
||||||
const char *lang = setlocale( LC_MESSAGES, 0 );
|
const char *lang = setlocale( LC_MESSAGES, 0 );
|
||||||
int close=0;
|
int close=0;
|
||||||
char *out=buff;
|
char *out=buff;
|
||||||
|
|
||||||
if( (1+strlen(lang)*4) >= BUFF_SIZE )
|
if( (1+strlen(lang)*4) >= BUFF_SIZE )
|
||||||
{
|
{
|
||||||
fprintf( stderr, _( "%s: Locale string too long\n"), MIMEDB );
|
fprintf( stderr, _( "%s: Locale string too long\n"), MIMEDB );
|
||||||
error = 1;
|
error = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( ; *lang; lang++ )
|
for( ; *lang; lang++ )
|
||||||
{
|
{
|
||||||
switch( *lang )
|
switch( *lang )
|
||||||
|
@ -449,17 +449,17 @@ static char *get_lang_re()
|
||||||
*out++ = ')';
|
*out++ = ')';
|
||||||
*out++ = '?';
|
*out++ = '?';
|
||||||
}
|
}
|
||||||
|
|
||||||
close=1;
|
close=1;
|
||||||
*out++ = '(';
|
*out++ = '(';
|
||||||
*out++ = *lang;
|
*out++ = *lang;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
*out++ = *lang;
|
*out++ = *lang;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( close )
|
if( close )
|
||||||
{
|
{
|
||||||
*out++ = ')';
|
*out++ = ')';
|
||||||
|
@ -471,12 +471,12 @@ static char *get_lang_re()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Get description for a specified mimetype.
|
Get description for a specified mimetype.
|
||||||
*/
|
*/
|
||||||
static char *get_description( const char *mimetype )
|
static char *get_description( const char *mimetype )
|
||||||
{
|
{
|
||||||
char *fn_part;
|
char *fn_part;
|
||||||
|
|
||||||
char *fn;
|
char *fn;
|
||||||
int fd;
|
int fd;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
@ -491,12 +491,12 @@ static char *get_description( const char *mimetype )
|
||||||
lang = get_lang_re();
|
lang = get_lang_re();
|
||||||
if( !lang )
|
if( !lang )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
snprintf( buff, BUFF_SIZE, START_TAG, lang, lang );
|
snprintf( buff, BUFF_SIZE, START_TAG, lang, lang );
|
||||||
|
|
||||||
start_re = my_malloc( sizeof(regex_t));
|
start_re = my_malloc( sizeof(regex_t));
|
||||||
stop_re = my_malloc( sizeof(regex_t));
|
stop_re = my_malloc( sizeof(regex_t));
|
||||||
|
|
||||||
int reg_status;
|
int reg_status;
|
||||||
if( ( reg_status = regcomp( start_re, buff, REG_EXTENDED ) ) )
|
if( ( reg_status = regcomp( start_re, buff, REG_EXTENDED ) ) )
|
||||||
{
|
{
|
||||||
|
@ -504,7 +504,7 @@ static char *get_description( const char *mimetype )
|
||||||
regerror(reg_status, start_re, 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);
|
fprintf( stderr, _( "%s: Could not compile regular expressions %s with error %s\n"), MIMEDB, buff, regerrbuf);
|
||||||
error=1;
|
error=1;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ( ( reg_status = regcomp( stop_re, STOP_TAG, REG_EXTENDED ) ) )
|
else if ( ( reg_status = regcomp( stop_re, STOP_TAG, REG_EXTENDED ) ) )
|
||||||
{
|
{
|
||||||
|
@ -512,7 +512,7 @@ static char *get_description( const char *mimetype )
|
||||||
regerror(reg_status, stop_re, 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);
|
fprintf( stderr, _( "%s: Could not compile regular expressions %s with error %s\n"), MIMEDB, buff, regerrbuf);
|
||||||
error=1;
|
error=1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( error )
|
if( error )
|
||||||
|
@ -524,7 +524,7 @@ static char *get_description( const char *mimetype )
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn_part = my_malloc( strlen(MIME_DIR) + strlen( mimetype) + strlen(MIME_SUFFIX) + 1 );
|
fn_part = my_malloc( strlen(MIME_DIR) + strlen( mimetype) + strlen(MIME_SUFFIX) + 1 );
|
||||||
|
|
||||||
if( !fn_part )
|
if( !fn_part )
|
||||||
|
@ -538,7 +538,7 @@ static char *get_description( const char *mimetype )
|
||||||
|
|
||||||
fn = get_filename(fn_part); //malloc( strlen(MIME_DIR) +strlen( MIME_SUFFIX)+ strlen( mimetype ) + 1 );
|
fn = get_filename(fn_part); //malloc( strlen(MIME_DIR) +strlen( MIME_SUFFIX)+ strlen( mimetype ) + 1 );
|
||||||
free(fn_part );
|
free(fn_part );
|
||||||
|
|
||||||
if( !fn )
|
if( !fn )
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -547,14 +547,14 @@ static char *get_description( const char *mimetype )
|
||||||
fd = open( fn, O_RDONLY );
|
fd = open( fn, O_RDONLY );
|
||||||
|
|
||||||
// fprintf( stderr, "%s\n", fn );
|
// fprintf( stderr, "%s\n", fn );
|
||||||
|
|
||||||
if( fd == -1 )
|
if( fd == -1 )
|
||||||
{
|
{
|
||||||
perror( "open" );
|
perror( "open" );
|
||||||
error=1;
|
error=1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( stat( fn, &st) )
|
if( stat( fn, &st) )
|
||||||
{
|
{
|
||||||
perror( "stat" );
|
perror( "stat" );
|
||||||
|
@ -567,7 +567,7 @@ static char *get_description( const char *mimetype )
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( read( fd, contents, st.st_size ) != st.st_size )
|
if( read( fd, contents, st.st_size ) != st.st_size )
|
||||||
{
|
{
|
||||||
perror( "read" );
|
perror( "read" );
|
||||||
|
@ -584,9 +584,9 @@ static char *get_description( const char *mimetype )
|
||||||
contents[st.st_size]=0;
|
contents[st.st_size]=0;
|
||||||
regmatch_t match[1];
|
regmatch_t match[1];
|
||||||
int w = -1;
|
int w = -1;
|
||||||
|
|
||||||
start=contents;
|
start=contents;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
On multiple matches, use the longest match, should be a pretty
|
On multiple matches, use the longest match, should be a pretty
|
||||||
good heuristic for best match...
|
good heuristic for best match...
|
||||||
|
@ -595,10 +595,10 @@ static char *get_description( const char *mimetype )
|
||||||
{
|
{
|
||||||
int new_w = match[0].rm_eo - match[0].rm_so;
|
int new_w = match[0].rm_eo - match[0].rm_so;
|
||||||
start += match[0].rm_eo;
|
start += match[0].rm_eo;
|
||||||
|
|
||||||
if( new_w > w )
|
if( new_w > w )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
New match is for a longer match then the previous
|
New match is for a longer match then the previous
|
||||||
match, so we use the new match
|
match, so we use the new match
|
||||||
*/
|
*/
|
||||||
|
@ -606,7 +606,7 @@ static char *get_description( const char *mimetype )
|
||||||
best_start = start;
|
best_start = start;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( w != -1 )
|
if( w != -1 )
|
||||||
{
|
{
|
||||||
start = best_start;
|
start = best_start;
|
||||||
|
@ -633,36 +633,36 @@ static char *get_description( const char *mimetype )
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Get default action for a specified mimetype.
|
Get default action for a specified mimetype.
|
||||||
*/
|
*/
|
||||||
static char *get_action( const char *mimetype )
|
static char *get_action( const char *mimetype )
|
||||||
{
|
{
|
||||||
char *res=0;
|
char *res=0;
|
||||||
|
|
||||||
char *launcher;
|
char *launcher;
|
||||||
char *end;
|
char *end;
|
||||||
char *mime_filename;
|
char *mime_filename;
|
||||||
|
|
||||||
char *launcher_str;
|
char *launcher_str;
|
||||||
char *launcher_filename, *launcher_command_str, *launcher_command;
|
char *launcher_filename, *launcher_command_str, *launcher_command;
|
||||||
char *launcher_full;
|
char *launcher_full;
|
||||||
|
|
||||||
mime_filename = get_filename( DESKTOP_DEFAULT );
|
mime_filename = get_filename( DESKTOP_DEFAULT );
|
||||||
if( !mime_filename )
|
if( !mime_filename )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
launcher_str = search_ini( mime_filename, mimetype );
|
launcher_str = search_ini( mime_filename, mimetype );
|
||||||
|
|
||||||
free( mime_filename );
|
free( mime_filename );
|
||||||
|
|
||||||
if( !launcher_str )
|
if( !launcher_str )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
This type does not have a launcher. Try the supertype!
|
This type does not have a launcher. Try the supertype!
|
||||||
*/
|
*/
|
||||||
// fprintf( stderr, "mimedb: %s does not have launcher, try supertype\n", mimetype );
|
// fprintf( stderr, "mimedb: %s does not have launcher, try supertype\n", mimetype );
|
||||||
const char ** parents = xdg_mime_get_mime_parents(mimetype);
|
const char ** parents = xdg_mime_get_mime_parents(mimetype);
|
||||||
|
|
||||||
const char **p;
|
const char **p;
|
||||||
if( parents )
|
if( parents )
|
||||||
{
|
{
|
||||||
|
@ -677,26 +677,26 @@ static char *get_action( const char *mimetype )
|
||||||
Just in case subclassing doesn't work, (It doesn't on Fedora
|
Just in case subclassing doesn't work, (It doesn't on Fedora
|
||||||
Core 3) we also test some common subclassings.
|
Core 3) we also test some common subclassings.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( strncmp( mimetype, "text/plain", 10) != 0 && strncmp( mimetype, "text/", 5 ) == 0 )
|
if( strncmp( mimetype, "text/plain", 10) != 0 && strncmp( mimetype, "text/", 5 ) == 0 )
|
||||||
return get_action( "text/plain" );
|
return get_action( "text/plain" );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fprintf( stderr, "WOOT %s\n", launcher_str );
|
// fprintf( stderr, "WOOT %s\n", launcher_str );
|
||||||
launcher = strchr( launcher_str, '=' );
|
launcher = strchr( launcher_str, '=' );
|
||||||
|
|
||||||
if( !launcher )
|
if( !launcher )
|
||||||
{
|
{
|
||||||
fprintf( stderr, _("%s: Could not parse launcher string '%s'\n"), MIMEDB, launcher_str );
|
fprintf( stderr, _("%s: Could not parse launcher string '%s'\n"), MIMEDB, launcher_str );
|
||||||
error=1;
|
error=1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip the = */
|
/* Skip the = */
|
||||||
launcher++;
|
launcher++;
|
||||||
|
|
||||||
/* Only use first launcher */
|
/* Only use first launcher */
|
||||||
end = strchr( launcher, ';' );
|
end = strchr( launcher, ';' );
|
||||||
if( end )
|
if( end )
|
||||||
|
@ -708,34 +708,34 @@ static char *get_action( const char *mimetype )
|
||||||
free( launcher_str );
|
free( launcher_str );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy( launcher_full, APPLICATIONS_DIR );
|
strcpy( launcher_full, APPLICATIONS_DIR );
|
||||||
strcat( launcher_full, launcher );
|
strcat( launcher_full, launcher );
|
||||||
free( launcher_str );
|
free( launcher_str );
|
||||||
|
|
||||||
launcher_filename = get_filename( launcher_full );
|
launcher_filename = get_filename( launcher_full );
|
||||||
|
|
||||||
free( launcher_full );
|
free( launcher_full );
|
||||||
|
|
||||||
launcher_command_str = search_ini( launcher_filename, "Exec=" );
|
launcher_command_str = search_ini( launcher_filename, "Exec=" );
|
||||||
|
|
||||||
if( !launcher_command_str )
|
if( !launcher_command_str )
|
||||||
{
|
{
|
||||||
fprintf( stderr,
|
fprintf( stderr,
|
||||||
_( "%s: Default launcher '%s' does not specify how to start\n"), MIMEDB,
|
_( "%s: Default launcher '%s' does not specify how to start\n"), MIMEDB,
|
||||||
launcher_filename );
|
launcher_filename );
|
||||||
free( launcher_filename );
|
free( launcher_filename );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
free( launcher_filename );
|
free( launcher_filename );
|
||||||
|
|
||||||
launcher_command = strchr( launcher_command_str, '=' );
|
launcher_command = strchr( launcher_command_str, '=' );
|
||||||
launcher_command++;
|
launcher_command++;
|
||||||
|
|
||||||
res = my_strdup( launcher_command );
|
res = my_strdup( launcher_command );
|
||||||
|
|
||||||
free( launcher_command_str );
|
free( launcher_command_str );
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -748,7 +748,7 @@ static void writer( char c )
|
||||||
{
|
{
|
||||||
if( launch_len == -1 )
|
if( launch_len == -1 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( launch_len <= launch_pos )
|
if( launch_len <= launch_pos )
|
||||||
{
|
{
|
||||||
int new_len = launch_len?2*launch_len:256;
|
int new_len = launch_len?2*launch_len:256;
|
||||||
|
@ -762,7 +762,7 @@ static void writer( char c )
|
||||||
}
|
}
|
||||||
launch_buff = new_buff;
|
launch_buff = new_buff;
|
||||||
launch_len = new_len;
|
launch_len = new_len;
|
||||||
|
|
||||||
}
|
}
|
||||||
launch_buff[launch_pos++]=c;
|
launch_buff[launch_pos++]=c;
|
||||||
}
|
}
|
||||||
|
@ -785,7 +785,7 @@ static void writer_hex( int num )
|
||||||
*/
|
*/
|
||||||
static char *my_getcwd ()
|
static char *my_getcwd ()
|
||||||
{
|
{
|
||||||
size_t size = 100;
|
size_t size = 100;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
char *buffer = (char *) malloc (size);
|
char *buffer = (char *) malloc (size);
|
||||||
|
@ -804,7 +804,7 @@ static char *my_getcwd ()
|
||||||
static char *get_fullfile( char *file )
|
static char *get_fullfile( char *file )
|
||||||
{
|
{
|
||||||
char *fullfile;
|
char *fullfile;
|
||||||
|
|
||||||
if( file[0] == '/' )
|
if( file[0] == '/' )
|
||||||
{
|
{
|
||||||
fullfile = file;
|
fullfile = file;
|
||||||
|
@ -818,9 +818,9 @@ static char *get_fullfile( char *file )
|
||||||
perror( "getcwd" );
|
perror( "getcwd" );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int l = strlen(cwd);
|
int l = strlen(cwd);
|
||||||
|
|
||||||
fullfile = my_malloc( l + strlen(file)+2 );
|
fullfile = my_malloc( l + strlen(file)+2 );
|
||||||
if( !fullfile )
|
if( !fullfile )
|
||||||
{
|
{
|
||||||
|
@ -831,7 +831,7 @@ static char *get_fullfile( char *file )
|
||||||
if( cwd[l-1] != '/' )
|
if( cwd[l-1] != '/' )
|
||||||
strcat(fullfile, "/" );
|
strcat(fullfile, "/" );
|
||||||
strcat( fullfile, file );
|
strcat( fullfile, file );
|
||||||
|
|
||||||
free(cwd);
|
free(cwd);
|
||||||
}
|
}
|
||||||
return fullfile;
|
return fullfile;
|
||||||
|
@ -845,13 +845,13 @@ static void write_url( char *file )
|
||||||
{
|
{
|
||||||
char *fullfile = get_fullfile( file );
|
char *fullfile = get_fullfile( file );
|
||||||
char *str = fullfile;
|
char *str = fullfile;
|
||||||
|
|
||||||
if( str == 0 )
|
if( str == 0 )
|
||||||
{
|
{
|
||||||
launch_len = -1;
|
launch_len = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
writer( 'f');
|
writer( 'f');
|
||||||
writer( 'i');
|
writer( 'i');
|
||||||
writer( 'l');
|
writer( 'l');
|
||||||
|
@ -866,9 +866,9 @@ static void write_url( char *file )
|
||||||
((*str >= '0') && (*str <='9')) ||
|
((*str >= '0') && (*str <='9')) ||
|
||||||
(strchr( "-_.~/",*str) != 0) )
|
(strchr( "-_.~/",*str) != 0) )
|
||||||
{
|
{
|
||||||
writer(*str);
|
writer(*str);
|
||||||
}
|
}
|
||||||
else if(strchr( "()?&=",*str) != 0)
|
else if(strchr( "()?&=",*str) != 0)
|
||||||
{
|
{
|
||||||
writer('\\');
|
writer('\\');
|
||||||
writer(*str);
|
writer(*str);
|
||||||
|
@ -882,7 +882,7 @@ static void write_url( char *file )
|
||||||
}
|
}
|
||||||
if( fullfile != file )
|
if( fullfile != file )
|
||||||
free( fullfile );
|
free( fullfile );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -906,7 +906,7 @@ static void write_file( char *file, int print_path )
|
||||||
}
|
}
|
||||||
str = basename( fullfile );
|
str = basename( fullfile );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !str )
|
if( !str )
|
||||||
{
|
{
|
||||||
error = 1;
|
error = 1;
|
||||||
|
@ -979,7 +979,7 @@ static void write_file( char *file, int print_path )
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Use the specified launch filter to launch all the files in the specified list.
|
Use the specified launch filter to launch all the files in the specified list.
|
||||||
|
|
||||||
\param filter the action to take
|
\param filter the action to take
|
||||||
\param files the list of files for which to perform the action
|
\param files the list of files for which to perform the action
|
||||||
|
@ -990,11 +990,11 @@ static void launch( char *filter, array_list_t *files, int fileno )
|
||||||
char *filter_org=filter;
|
char *filter_org=filter;
|
||||||
int count=0;
|
int count=0;
|
||||||
int launch_again=0;
|
int launch_again=0;
|
||||||
|
|
||||||
if( al_get_count( files ) <= fileno )
|
if( al_get_count( files ) <= fileno )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
launch_pos=0;
|
launch_pos=0;
|
||||||
|
|
||||||
for( ;*filter && !error; filter++)
|
for( ;*filter && !error; filter++)
|
||||||
|
@ -1009,7 +1009,7 @@ static void launch( char *filter, array_list_t *files, int fileno )
|
||||||
launch_again = 1;
|
launch_again = 1;
|
||||||
write_url( (char *)al_get( files, fileno ) );
|
write_url( (char *)al_get( files, fileno ) );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'U':
|
case 'U':
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -1021,10 +1021,10 @@ static void launch( char *filter, array_list_t *files, int fileno )
|
||||||
if( error )
|
if( error )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
case 'n':
|
case 'n':
|
||||||
{
|
{
|
||||||
|
@ -1032,7 +1032,7 @@ static void launch( char *filter, array_list_t *files, int fileno )
|
||||||
write_file( (char *)al_get( files, fileno ), *filter == 'f' );
|
write_file( (char *)al_get( files, fileno ), *filter == 'f' );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'F':
|
case 'F':
|
||||||
case 'N':
|
case 'N':
|
||||||
{
|
{
|
||||||
|
@ -1047,14 +1047,14 @@ static void launch( char *filter, array_list_t *files, int fileno )
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
{
|
{
|
||||||
char *cpy = get_fullfile( (char *)al_get( files, fileno ) );
|
char *cpy = get_fullfile( (char *)al_get( files, fileno ) );
|
||||||
char *dir;
|
char *dir;
|
||||||
|
|
||||||
launch_again=1;
|
launch_again=1;
|
||||||
/*
|
/*
|
||||||
We wish to modify this string, make sure it is only a copy
|
We wish to modify this string, make sure it is only a copy
|
||||||
*/
|
*/
|
||||||
|
@ -1068,16 +1068,16 @@ static void launch( char *filter, array_list_t *files, int fileno )
|
||||||
dir=dirname( cpy );
|
dir=dirname( cpy );
|
||||||
write_file( dir, 1 );
|
write_file( dir, 1 );
|
||||||
free( cpy );
|
free( cpy );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'D':
|
case 'D':
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for( i=0; i<al_get_count( files ); i++ )
|
for( i=0; i<al_get_count( files ); i++ )
|
||||||
{
|
{
|
||||||
char *cpy = get_fullfile( (char *)al_get( files, i ) );
|
char *cpy = get_fullfile( (char *)al_get( files, i ) );
|
||||||
char *dir;
|
char *dir;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1091,7 +1091,7 @@ static void launch( char *filter, array_list_t *files, int fileno )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
dir=dirname( cpy );
|
dir=dirname( cpy );
|
||||||
|
|
||||||
if( i != 0 )
|
if( i != 0 )
|
||||||
writer( ' ' );
|
writer( ' ' );
|
||||||
|
|
||||||
|
@ -1099,14 +1099,14 @@ static void launch( char *filter, array_list_t *files, int fileno )
|
||||||
free( cpy );
|
free( cpy );
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf( stderr, _("%s: Unsupported switch '%c' in launch string '%s'\n"), MIMEDB, *filter, filter_org );
|
fprintf( stderr, _("%s: Unsupported switch '%c' in launch string '%s'\n"), MIMEDB, *filter, filter_org );
|
||||||
launch_len=0;
|
launch_len=0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1118,7 +1118,7 @@ static void launch( char *filter, array_list_t *files, int fileno )
|
||||||
|
|
||||||
if( error )
|
if( error )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch( launch_len )
|
switch( launch_len )
|
||||||
{
|
{
|
||||||
case -1:
|
case -1:
|
||||||
|
@ -1133,17 +1133,17 @@ static void launch( char *filter, array_list_t *files, int fileno )
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
|
||||||
writer( ' ' );
|
writer( ' ' );
|
||||||
writer( '&' );
|
writer( '&' );
|
||||||
writer( '\0' );
|
writer( '\0' );
|
||||||
|
|
||||||
if( system( launch_buff ) == -1 )
|
if( system( launch_buff ) == -1 )
|
||||||
{
|
{
|
||||||
fprintf( stderr, _( ERROR_SYSTEM ), MIMEDB, launch_buff );
|
fprintf( stderr, _( ERROR_SYSTEM ), MIMEDB, launch_buff );
|
||||||
exit(STATUS_ERROR_SYSTEM);
|
exit(STATUS_ERROR_SYSTEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1151,7 +1151,7 @@ static void launch( char *filter, array_list_t *files, int fileno )
|
||||||
{
|
{
|
||||||
launch( filter_org, files, fileno+1 );
|
launch( filter_org, files, fileno+1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1188,19 +1188,19 @@ static void locale_init()
|
||||||
Main function. Parses options and calls helper function for any heavy lifting.
|
Main function. Parses options and calls helper function for any heavy lifting.
|
||||||
*/
|
*/
|
||||||
int main (int argc, char *argv[])
|
int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int input_type=FILEDATA;
|
int input_type=FILEDATA;
|
||||||
int output_type=MIMETYPE;
|
int output_type=MIMETYPE;
|
||||||
|
|
||||||
const char *mimetype;
|
const char *mimetype;
|
||||||
char *output=0;
|
char *output=0;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
hash_table_t launch_hash;
|
hash_table_t launch_hash;
|
||||||
|
|
||||||
locale_init();
|
locale_init();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Parse options
|
Parse options
|
||||||
*/
|
*/
|
||||||
|
@ -1210,103 +1210,103 @@ int main (int argc, char *argv[])
|
||||||
long_options[] =
|
long_options[] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
"input-file-data", no_argument, 0, 't'
|
"input-file-data", no_argument, 0, 't'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"input-filename", no_argument, 0, 'f'
|
"input-filename", no_argument, 0, 'f'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"input-mime", no_argument, 0, 'i'
|
"input-mime", no_argument, 0, 'i'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"output-mime", no_argument, 0, 'm'
|
"output-mime", no_argument, 0, 'm'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"output-description", no_argument, 0, 'd'
|
"output-description", no_argument, 0, 'd'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"output-action", no_argument, 0, 'a'
|
"output-action", no_argument, 0, 'a'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"help", no_argument, 0, 'h'
|
"help", no_argument, 0, 'h'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"version", no_argument, 0, 'v'
|
"version", no_argument, 0, 'v'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"launch", no_argument, 0, 'l'
|
"launch", no_argument, 0, 'l'
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
0, 0, 0, 0
|
0, 0, 0, 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
int opt_index = 0;
|
int opt_index = 0;
|
||||||
|
|
||||||
int opt = getopt_long( argc,
|
int opt = getopt_long( argc,
|
||||||
argv,
|
argv,
|
||||||
GETOPT_STRING,
|
GETOPT_STRING,
|
||||||
long_options,
|
long_options,
|
||||||
&opt_index );
|
&opt_index );
|
||||||
|
|
||||||
if( opt == -1 )
|
if( opt == -1 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch( opt )
|
switch( opt )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
input_type=FILEDATA;
|
input_type=FILEDATA;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
input_type=FILENAME;
|
input_type=FILENAME;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
input_type=MIMETYPE;
|
input_type=MIMETYPE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
output_type=MIMETYPE;
|
output_type=MIMETYPE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
output_type=DESCRIPTION;
|
output_type=DESCRIPTION;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'a':
|
case 'a':
|
||||||
output_type=ACTION;
|
output_type=ACTION;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'l':
|
case 'l':
|
||||||
output_type=LAUNCH;
|
output_type=LAUNCH;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
print_help( argv[0], 1 );
|
print_help( argv[0], 1 );
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
printf( _("%s, version %s\n"), MIMEDB, PACKAGE_VERSION );
|
printf( _("%s, version %s\n"), MIMEDB, PACKAGE_VERSION );
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ( output_type == LAUNCH )&&(input_type==MIMETYPE))
|
if( ( output_type == LAUNCH )&&(input_type==MIMETYPE))
|
||||||
|
@ -1318,13 +1318,13 @@ int main (int argc, char *argv[])
|
||||||
|
|
||||||
if( output_type == LAUNCH )
|
if( output_type == LAUNCH )
|
||||||
hash_init( &launch_hash, &hash_str_func, &hash_str_cmp );
|
hash_init( &launch_hash, &hash_str_func, &hash_str_cmp );
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Loop over all non option arguments and do the specified lookup
|
Loop over all non option arguments and do the specified lookup
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//fprintf( stderr, "Input %d, output %d\n", input_type, output_type );
|
//fprintf( stderr, "Input %d, output %d\n", input_type, output_type );
|
||||||
|
|
||||||
for (i = optind; (i < argc)&&(!error); i++)
|
for (i = optind; (i < argc)&&(!error); i++)
|
||||||
{
|
{
|
||||||
|
@ -1347,7 +1347,7 @@ int main (int argc, char *argv[])
|
||||||
error=1;
|
error=1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Convert from mimetype to whatever, if needed
|
Convert from mimetype to whatever, if needed
|
||||||
*/
|
*/
|
||||||
|
@ -1357,21 +1357,21 @@ int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
output = (char *)mimetype;
|
output = (char *)mimetype;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
case DESCRIPTION:
|
case DESCRIPTION:
|
||||||
{
|
{
|
||||||
output = get_description( mimetype );
|
output = get_description( mimetype );
|
||||||
if( !output )
|
if( !output )
|
||||||
output = strdup( _("Unknown") );
|
output = strdup( _("Unknown") );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ACTION:
|
case ACTION:
|
||||||
{
|
{
|
||||||
output = get_action( mimetype );
|
output = get_action( mimetype );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LAUNCH:
|
case LAUNCH:
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -1382,7 +1382,7 @@ int main (int argc, char *argv[])
|
||||||
*/
|
*/
|
||||||
array_list_t *l= (array_list_t *)hash_get( &launch_hash, mimetype );
|
array_list_t *l= (array_list_t *)hash_get( &launch_hash, mimetype );
|
||||||
output = 0;
|
output = 0;
|
||||||
|
|
||||||
if( !l )
|
if( !l )
|
||||||
{
|
{
|
||||||
l = my_malloc( sizeof( array_list_t ) );
|
l = my_malloc( sizeof( array_list_t ) );
|
||||||
|
@ -1393,10 +1393,10 @@ int main (int argc, char *argv[])
|
||||||
al_init( l );
|
al_init( l );
|
||||||
hash_put( &launch_hash, mimetype, l );
|
hash_put( &launch_hash, mimetype, l );
|
||||||
}
|
}
|
||||||
al_push( l, argv[i] );
|
al_push( l, argv[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Print the glorious result
|
Print the glorious result
|
||||||
*/
|
*/
|
||||||
|
@ -1426,9 +1426,9 @@ int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
fprintf( stderr, _( "%s: Unknown error\n"), MIMEDB );
|
fprintf( stderr, _( "%s: Unknown error\n"), MIMEDB );
|
||||||
error=1;
|
error=1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *launcher = get_action( mimetype );
|
char *launcher = get_action( mimetype );
|
||||||
|
|
||||||
if( launcher )
|
if( launcher )
|
||||||
|
@ -1441,7 +1441,7 @@ int main (int argc, char *argv[])
|
||||||
hash_destroy( &launch_hash );
|
hash_destroy( &launch_hash );
|
||||||
al_destroy( &mimes );
|
al_destroy( &mimes );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( launch_buff )
|
if( launch_buff )
|
||||||
free( launch_buff );
|
free( launch_buff );
|
||||||
|
|
||||||
|
@ -1451,9 +1451,9 @@ int main (int argc, char *argv[])
|
||||||
regfree( stop_re );
|
regfree( stop_re );
|
||||||
free( start_re );
|
free( start_re );
|
||||||
free( stop_re );
|
free( stop_re );
|
||||||
}
|
}
|
||||||
|
|
||||||
xdg_mime_shutdown();
|
xdg_mime_shutdown();
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
64
output.c
64
output.c
|
@ -65,7 +65,7 @@
|
||||||
static int writeb_internal( char c );
|
static int writeb_internal( char c );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Names of different colors.
|
Names of different colors.
|
||||||
*/
|
*/
|
||||||
static wchar_t *col[]=
|
static wchar_t *col[]=
|
||||||
{
|
{
|
||||||
|
@ -91,7 +91,7 @@ static wchar_t *col[]=
|
||||||
*/
|
*/
|
||||||
static int col_idx[]=
|
static int col_idx[]=
|
||||||
{
|
{
|
||||||
0,
|
0,
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
3,
|
3,
|
||||||
|
@ -108,7 +108,7 @@ static int col_idx[]=
|
||||||
/**
|
/**
|
||||||
Size of writestr_buff
|
Size of writestr_buff
|
||||||
*/
|
*/
|
||||||
static size_t writestr_buff_sz=0;
|
static size_t writestr_buff_sz=0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Temp buffer used for converting from wide to narrow strings
|
Temp buffer used for converting from wide to narrow strings
|
||||||
|
@ -167,7 +167,7 @@ void set_color( int c, int c2 )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
is_bold |= (c&FISH_COLOR_BOLD)!=0;
|
is_bold |= (c&FISH_COLOR_BOLD)!=0;
|
||||||
is_bold |= (c2&FISH_COLOR_BOLD)!=0;
|
is_bold |= (c2&FISH_COLOR_BOLD)!=0;
|
||||||
|
@ -210,7 +210,7 @@ void set_color( int c, int c2 )
|
||||||
if( was_bold && !is_bold )
|
if( was_bold && !is_bold )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Only way to exit bold mode is a reset of all attributes.
|
Only way to exit bold mode is a reset of all attributes.
|
||||||
*/
|
*/
|
||||||
writembs( exit_attribute_mode );
|
writembs( exit_attribute_mode );
|
||||||
last_color = FISH_COLOR_NORMAL;
|
last_color = FISH_COLOR_NORMAL;
|
||||||
|
@ -218,7 +218,7 @@ void set_color( int c, int c2 )
|
||||||
was_bold=0;
|
was_bold=0;
|
||||||
was_underline=0;
|
was_underline=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( last_color2 != FISH_COLOR_NORMAL &&
|
if( last_color2 != FISH_COLOR_NORMAL &&
|
||||||
last_color2 != FISH_COLOR_RESET &&
|
last_color2 != FISH_COLOR_RESET &&
|
||||||
last_color2 != FISH_COLOR_IGNORE )
|
last_color2 != FISH_COLOR_IGNORE )
|
||||||
|
@ -313,7 +313,7 @@ void set_color( int c, int c2 )
|
||||||
writembs( tparm( fg, last_color ) );
|
writembs( tparm( fg, last_color ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
was_bold=0;
|
was_bold=0;
|
||||||
was_underline=0;
|
was_underline=0;
|
||||||
|
@ -341,20 +341,20 @@ void set_color( int c, int c2 )
|
||||||
writembs( tparm( enter_bold_mode ) );
|
writembs( tparm( enter_bold_mode ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
was_bold = is_bold;
|
was_bold = is_bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( was_underline && !is_underline )
|
if( was_underline && !is_underline )
|
||||||
{
|
{
|
||||||
writembs( exit_underline_mode );
|
writembs( exit_underline_mode );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !was_underline && is_underline )
|
if( !was_underline && is_underline )
|
||||||
{
|
{
|
||||||
writembs( enter_underline_mode );
|
writembs( enter_underline_mode );
|
||||||
}
|
}
|
||||||
was_underline = is_underline;
|
was_underline = is_underline;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -375,7 +375,7 @@ int writeb( tputs_arg_t b )
|
||||||
int writembs_internal( char *str )
|
int writembs_internal( char *str )
|
||||||
{
|
{
|
||||||
CHECK( str, 1 );
|
CHECK( str, 1 );
|
||||||
|
|
||||||
return tputs(str,1,&writeb)==ERR?1:0;
|
return tputs(str,1,&writeb)==ERR?1:0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,7 +396,7 @@ int writech( wint_t ch )
|
||||||
{
|
{
|
||||||
memset( &state, 0, sizeof(state) );
|
memset( &state, 0, sizeof(state) );
|
||||||
bytes= wcrtomb( buff, ch, &state );
|
bytes= wcrtomb( buff, ch, &state );
|
||||||
|
|
||||||
switch( bytes )
|
switch( bytes )
|
||||||
{
|
{
|
||||||
case (size_t)(-1):
|
case (size_t)(-1):
|
||||||
|
@ -405,7 +405,7 @@ int writech( wint_t ch )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i=0; i<bytes; i++ )
|
for( i=0; i<bytes; i++ )
|
||||||
{
|
{
|
||||||
out( buff[i] );
|
out( buff[i] );
|
||||||
|
@ -418,7 +418,7 @@ void writestr( const wchar_t *str )
|
||||||
char *pos;
|
char *pos;
|
||||||
|
|
||||||
CHECK( str, );
|
CHECK( str, );
|
||||||
|
|
||||||
// while( *str )
|
// while( *str )
|
||||||
// writech( *str++ );
|
// writech( *str++ );
|
||||||
|
|
||||||
|
@ -426,15 +426,15 @@ void writestr( const wchar_t *str )
|
||||||
Check amount of needed space
|
Check amount of needed space
|
||||||
*/
|
*/
|
||||||
size_t len = wcstombs( 0, str, 0 );
|
size_t len = wcstombs( 0, str, 0 );
|
||||||
|
|
||||||
if( len == (size_t)-1 )
|
if( len == (size_t)-1 )
|
||||||
{
|
{
|
||||||
debug( 1, L"Tried to print invalid wide character string" );
|
debug( 1, L"Tried to print invalid wide character string" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
len++;
|
len++;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Reallocate if needed
|
Reallocate if needed
|
||||||
*/
|
*/
|
||||||
|
@ -444,7 +444,7 @@ void writestr( const wchar_t *str )
|
||||||
{
|
{
|
||||||
halloc_register_function_void( global_context, &output_destroy );
|
halloc_register_function_void( global_context, &output_destroy );
|
||||||
}
|
}
|
||||||
|
|
||||||
writestr_buff = realloc( writestr_buff, len );
|
writestr_buff = realloc( writestr_buff, len );
|
||||||
if( !writestr_buff )
|
if( !writestr_buff )
|
||||||
{
|
{
|
||||||
|
@ -452,11 +452,11 @@ void writestr( const wchar_t *str )
|
||||||
}
|
}
|
||||||
writestr_buff_sz = len;
|
writestr_buff_sz = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Convert
|
Convert
|
||||||
*/
|
*/
|
||||||
wcstombs( writestr_buff,
|
wcstombs( writestr_buff,
|
||||||
str,
|
str,
|
||||||
writestr_buff_sz );
|
writestr_buff_sz );
|
||||||
|
|
||||||
|
@ -476,7 +476,7 @@ void writestr_ellipsis( const wchar_t *str, int max_width )
|
||||||
int tot;
|
int tot;
|
||||||
|
|
||||||
CHECK( str, );
|
CHECK( str, );
|
||||||
|
|
||||||
tot = my_wcswidth(str);
|
tot = my_wcswidth(str);
|
||||||
|
|
||||||
if( tot <= max_width )
|
if( tot <= max_width )
|
||||||
|
@ -515,7 +515,7 @@ int write_escaped_str( const wchar_t *str, int max_len )
|
||||||
int written=0;
|
int written=0;
|
||||||
|
|
||||||
CHECK( str, 0 );
|
CHECK( str, 0 );
|
||||||
|
|
||||||
out = escape( str, 1 );
|
out = escape( str, 1 );
|
||||||
len = my_wcswidth( out );
|
len = my_wcswidth( out );
|
||||||
|
|
||||||
|
@ -528,7 +528,7 @@ int write_escaped_str( const wchar_t *str, int max_len )
|
||||||
}
|
}
|
||||||
writech( ellipsis_char );
|
writech( ellipsis_char );
|
||||||
written += wcwidth( ellipsis_char );
|
written += wcwidth( ellipsis_char );
|
||||||
|
|
||||||
for( i=written; i<max_len; i++ )
|
for( i=written; i<max_len; i++ )
|
||||||
{
|
{
|
||||||
writech( L' ' );
|
writech( L' ' );
|
||||||
|
@ -552,17 +552,17 @@ int output_color_code( const wchar_t *val )
|
||||||
array_list_t el;
|
array_list_t el;
|
||||||
int is_bold=0;
|
int is_bold=0;
|
||||||
int is_underline=0;
|
int is_underline=0;
|
||||||
|
|
||||||
if( !val )
|
if( !val )
|
||||||
return FISH_COLOR_NORMAL;
|
return FISH_COLOR_NORMAL;
|
||||||
|
|
||||||
al_init( &el );
|
al_init( &el );
|
||||||
tokenize_variable_array( val, &el );
|
tokenize_variable_array( val, &el );
|
||||||
|
|
||||||
for( j=0; j<al_get_count( &el ); j++ )
|
for( j=0; j<al_get_count( &el ); j++ )
|
||||||
{
|
{
|
||||||
wchar_t *next = (wchar_t *)al_get( &el, j );
|
wchar_t *next = (wchar_t *)al_get( &el, j );
|
||||||
|
|
||||||
is_bold |= (wcsncmp( next, L"--bold", wcslen(next) ) == 0 ) && wcslen(next)>=3;
|
is_bold |= (wcsncmp( next, L"--bold", wcslen(next) ) == 0 ) && wcslen(next)>=3;
|
||||||
is_bold |= wcscmp( next, L"-o" ) == 0;
|
is_bold |= wcscmp( next, L"-o" ) == 0;
|
||||||
|
|
||||||
|
@ -577,14 +577,14 @@ int output_color_code( const wchar_t *val )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
al_foreach( &el, &free );
|
al_foreach( &el, &free );
|
||||||
al_destroy( &el );
|
al_destroy( &el );
|
||||||
|
|
||||||
return color | (is_bold?FISH_COLOR_BOLD:0) | (is_underline?FISH_COLOR_UNDERLINE:0);
|
return color | (is_bold?FISH_COLOR_BOLD:0) | (is_underline?FISH_COLOR_UNDERLINE:0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void output_set_term( wchar_t *term )
|
void output_set_term( wchar_t *term )
|
||||||
|
|
2
output.h
2
output.h
|
@ -11,7 +11,7 @@
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constants for various colors as used by the set_color function.
|
Constants for various colors as used by the set_color function.
|
||||||
*/
|
*/
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
|
248
parse_util.c
248
parse_util.c
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
This library can be seen as a 'toolbox' for functions that are
|
This library can be seen as a 'toolbox' for functions that are
|
||||||
used in many places in fish and that are somehow related to
|
used in many places in fish and that are somehow related to
|
||||||
parsing the code.
|
parsing the code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -108,7 +108,7 @@ int parse_util_lineno( const wchar_t *str, int len )
|
||||||
prev_str = prev_str2;
|
prev_str = prev_str2;
|
||||||
i=i2;
|
i=i2;
|
||||||
res=res2;
|
res=res2;
|
||||||
|
|
||||||
prev_str2 = tmp_str;
|
prev_str2 = tmp_str;
|
||||||
i2 = tmp_i;
|
i2 = tmp_i;
|
||||||
res2 = tmp_res;
|
res2 = tmp_res;
|
||||||
|
@ -118,13 +118,13 @@ int parse_util_lineno( const wchar_t *str, int len )
|
||||||
prev_str2 = prev_str;
|
prev_str2 = prev_str;
|
||||||
i2 = i;
|
i2 = i;
|
||||||
res2=res;
|
res2=res;
|
||||||
|
|
||||||
prev_str = (wchar_t *)str;
|
prev_str = (wchar_t *)str;
|
||||||
i=0;
|
i=0;
|
||||||
res=1;
|
res=1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for( ; str[i] && i<len; i++ )
|
for( ; str[i] && i<len; i++ )
|
||||||
{
|
{
|
||||||
if( str[i] == L'\n' )
|
if( str[i] == L'\n' )
|
||||||
|
@ -146,14 +146,14 @@ int parse_util_get_line_from_offset( wchar_t *buff, int pos )
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i=0; i<pos; i++ )
|
for( i=0; i<pos; i++ )
|
||||||
{
|
{
|
||||||
if( !buff[i] )
|
if( !buff[i] )
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( buff[i] == L'\n' )
|
if( buff[i] == L'\n' )
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
|
@ -167,7 +167,7 @@ int parse_util_get_offset_from_line( wchar_t *buff, int line )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
if( line < 0 )
|
if( line < 0 )
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -175,14 +175,14 @@ int parse_util_get_offset_from_line( wchar_t *buff, int line )
|
||||||
|
|
||||||
if( line == 0 )
|
if( line == 0 )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for( i=0;; i++ )
|
for( i=0;; i++ )
|
||||||
{
|
{
|
||||||
if( !buff[i] )
|
if( !buff[i] )
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( buff[i] == L'\n' )
|
if( buff[i] == L'\n' )
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
|
@ -190,7 +190,7 @@ int parse_util_get_offset_from_line( wchar_t *buff, int line )
|
||||||
{
|
{
|
||||||
return i+1;
|
return i+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,46 +200,46 @@ int parse_util_get_offset( wchar_t *buff, int line, int line_offset )
|
||||||
int off = parse_util_get_offset_from_line( buff, line );
|
int off = parse_util_get_offset_from_line( buff, line );
|
||||||
int off2 = parse_util_get_offset_from_line( buff, line+1 );
|
int off2 = parse_util_get_offset_from_line( buff, line+1 );
|
||||||
int line_offset2 = line_offset;
|
int line_offset2 = line_offset;
|
||||||
|
|
||||||
if( off < 0 )
|
if( off < 0 )
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( off2 < 0 )
|
if( off2 < 0 )
|
||||||
{
|
{
|
||||||
off2 = wcslen( buff )+1;
|
off2 = wcslen( buff )+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( line_offset2 < 0 )
|
if( line_offset2 < 0 )
|
||||||
{
|
{
|
||||||
line_offset2 = 0;
|
line_offset2 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( line_offset2 >= off2-off-1 )
|
if( line_offset2 >= off2-off-1 )
|
||||||
{
|
{
|
||||||
line_offset2 = off2-off-1;
|
line_offset2 = off2-off-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return off + line_offset2;
|
return off + line_offset2;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int parse_util_locate_cmdsubst( const wchar_t *in,
|
int parse_util_locate_cmdsubst( const wchar_t *in,
|
||||||
wchar_t **begin,
|
wchar_t **begin,
|
||||||
wchar_t **end,
|
wchar_t **end,
|
||||||
int allow_incomplete )
|
int allow_incomplete )
|
||||||
{
|
{
|
||||||
wchar_t *pos;
|
wchar_t *pos;
|
||||||
wchar_t prev=0;
|
wchar_t prev=0;
|
||||||
int syntax_error=0;
|
int syntax_error=0;
|
||||||
int paran_count=0;
|
int paran_count=0;
|
||||||
|
|
||||||
wchar_t *paran_begin=0, *paran_end=0;
|
wchar_t *paran_begin=0, *paran_end=0;
|
||||||
|
|
||||||
CHECK( in, 0 );
|
CHECK( in, 0 );
|
||||||
|
|
||||||
for( pos = (wchar_t *)in; *pos; pos++ )
|
for( pos = (wchar_t *)in; *pos; pos++ )
|
||||||
{
|
{
|
||||||
if( prev != '\\' )
|
if( prev != '\\' )
|
||||||
|
@ -264,7 +264,7 @@ int parse_util_locate_cmdsubst( const wchar_t *in,
|
||||||
{
|
{
|
||||||
paran_begin = pos;
|
paran_begin = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
paran_count++;
|
paran_count++;
|
||||||
}
|
}
|
||||||
else if( *pos == ')' )
|
else if( *pos == ')' )
|
||||||
|
@ -277,7 +277,7 @@ int parse_util_locate_cmdsubst( const wchar_t *in,
|
||||||
paran_end = pos;
|
paran_end = pos;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( paran_count < 0 )
|
if( paran_count < 0 )
|
||||||
{
|
{
|
||||||
syntax_error = 1;
|
syntax_error = 1;
|
||||||
|
@ -285,19 +285,19 @@ int parse_util_locate_cmdsubst( const wchar_t *in,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
prev = *pos;
|
prev = *pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
syntax_error |= (paran_count < 0 );
|
syntax_error |= (paran_count < 0 );
|
||||||
syntax_error |= ((paran_count>0)&&(!allow_incomplete));
|
syntax_error |= ((paran_count>0)&&(!allow_incomplete));
|
||||||
|
|
||||||
if( syntax_error )
|
if( syntax_error )
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( paran_begin == 0 )
|
if( paran_begin == 0 )
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -312,20 +312,20 @@ int parse_util_locate_cmdsubst( const wchar_t *in,
|
||||||
{
|
{
|
||||||
*end = paran_count?(wchar_t *)in+wcslen(in):paran_end;
|
*end = paran_count?(wchar_t *)in+wcslen(in):paran_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void parse_util_cmdsubst_extent( const wchar_t *buff,
|
void parse_util_cmdsubst_extent( const wchar_t *buff,
|
||||||
int cursor_pos,
|
int cursor_pos,
|
||||||
wchar_t **a,
|
wchar_t **a,
|
||||||
wchar_t **b )
|
wchar_t **b )
|
||||||
{
|
{
|
||||||
wchar_t *begin, *end;
|
wchar_t *begin, *end;
|
||||||
wchar_t *pos;
|
wchar_t *pos;
|
||||||
const wchar_t *cursor = buff + cursor_pos;
|
const wchar_t *cursor = buff + cursor_pos;
|
||||||
|
|
||||||
CHECK( buff, );
|
CHECK( buff, );
|
||||||
|
|
||||||
if( a )
|
if( a )
|
||||||
|
@ -337,9 +337,9 @@ void parse_util_cmdsubst_extent( const wchar_t *buff,
|
||||||
{
|
{
|
||||||
*b = (wchar_t *)buff+wcslen(buff);
|
*b = (wchar_t *)buff+wcslen(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = (wchar_t *)buff;
|
pos = (wchar_t *)buff;
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
if( parse_util_locate_cmdsubst( pos,
|
if( parse_util_locate_cmdsubst( pos,
|
||||||
|
@ -379,10 +379,10 @@ void parse_util_cmdsubst_extent( const wchar_t *buff,
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = end+1;
|
pos = end+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -390,19 +390,19 @@ void parse_util_cmdsubst_extent( const wchar_t *buff,
|
||||||
*/
|
*/
|
||||||
static void job_or_process_extent( const wchar_t *buff,
|
static void job_or_process_extent( const wchar_t *buff,
|
||||||
int cursor_pos,
|
int cursor_pos,
|
||||||
wchar_t **a,
|
wchar_t **a,
|
||||||
wchar_t **b,
|
wchar_t **b,
|
||||||
int process )
|
int process )
|
||||||
{
|
{
|
||||||
wchar_t *begin, *end;
|
wchar_t *begin, *end;
|
||||||
int pos;
|
int pos;
|
||||||
wchar_t *buffcpy;
|
wchar_t *buffcpy;
|
||||||
int finished=0;
|
int finished=0;
|
||||||
|
|
||||||
tokenizer tok;
|
tokenizer tok;
|
||||||
|
|
||||||
CHECK( buff, );
|
CHECK( buff, );
|
||||||
|
|
||||||
if( a )
|
if( a )
|
||||||
{
|
{
|
||||||
*a=0;
|
*a=0;
|
||||||
|
@ -412,20 +412,20 @@ static void job_or_process_extent( const wchar_t *buff,
|
||||||
{
|
{
|
||||||
*b = 0;
|
*b = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_util_cmdsubst_extent( buff, cursor_pos, &begin, &end );
|
parse_util_cmdsubst_extent( buff, cursor_pos, &begin, &end );
|
||||||
if( !end || !begin )
|
if( !end || !begin )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = cursor_pos - (begin - buff);
|
pos = cursor_pos - (begin - buff);
|
||||||
|
|
||||||
if( a )
|
if( a )
|
||||||
{
|
{
|
||||||
*a = begin;
|
*a = begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( b )
|
if( b )
|
||||||
{
|
{
|
||||||
*b = end;
|
*b = end;
|
||||||
|
@ -453,14 +453,14 @@ static void job_or_process_extent( const wchar_t *buff,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case TOK_END:
|
case TOK_END:
|
||||||
case TOK_BACKGROUND:
|
case TOK_BACKGROUND:
|
||||||
{
|
{
|
||||||
|
|
||||||
if( tok_begin >= pos )
|
if( tok_begin >= pos )
|
||||||
{
|
{
|
||||||
finished=1;
|
finished=1;
|
||||||
if( b )
|
if( b )
|
||||||
{
|
{
|
||||||
*b = (wchar_t *)buff + tok_begin;
|
*b = (wchar_t *)buff + tok_begin;
|
||||||
|
@ -474,31 +474,31 @@ static void job_or_process_extent( const wchar_t *buff,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free( buffcpy);
|
free( buffcpy);
|
||||||
|
|
||||||
tok_destroy( &tok );
|
tok_destroy( &tok );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_util_process_extent( const wchar_t *buff,
|
void parse_util_process_extent( const wchar_t *buff,
|
||||||
int pos,
|
int pos,
|
||||||
wchar_t **a,
|
wchar_t **a,
|
||||||
wchar_t **b )
|
wchar_t **b )
|
||||||
{
|
{
|
||||||
job_or_process_extent( buff, pos, a, b, 1 );
|
job_or_process_extent( buff, pos, a, b, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_util_job_extent( const wchar_t *buff,
|
void parse_util_job_extent( const wchar_t *buff,
|
||||||
int pos,
|
int pos,
|
||||||
wchar_t **a,
|
wchar_t **a,
|
||||||
wchar_t **b )
|
wchar_t **b )
|
||||||
{
|
{
|
||||||
job_or_process_extent( buff,pos,a, b, 0 );
|
job_or_process_extent( buff,pos,a, b, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -506,7 +506,7 @@ void parse_util_token_extent( const wchar_t *buff,
|
||||||
int cursor_pos,
|
int cursor_pos,
|
||||||
wchar_t **tok_begin,
|
wchar_t **tok_begin,
|
||||||
wchar_t **tok_end,
|
wchar_t **tok_end,
|
||||||
wchar_t **prev_begin,
|
wchar_t **prev_begin,
|
||||||
wchar_t **prev_end )
|
wchar_t **prev_end )
|
||||||
{
|
{
|
||||||
wchar_t *begin, *end;
|
wchar_t *begin, *end;
|
||||||
|
@ -516,34 +516,34 @@ void parse_util_token_extent( const wchar_t *buff,
|
||||||
tokenizer tok;
|
tokenizer tok;
|
||||||
|
|
||||||
wchar_t *a, *b, *pa, *pb;
|
wchar_t *a, *b, *pa, *pb;
|
||||||
|
|
||||||
CHECK( buff, );
|
CHECK( buff, );
|
||||||
|
|
||||||
assert( cursor_pos >= 0 );
|
assert( cursor_pos >= 0 );
|
||||||
|
|
||||||
a = b = pa = pb = 0;
|
a = b = pa = pb = 0;
|
||||||
|
|
||||||
parse_util_cmdsubst_extent( buff, cursor_pos, &begin, &end );
|
parse_util_cmdsubst_extent( buff, cursor_pos, &begin, &end );
|
||||||
|
|
||||||
if( !end || !begin )
|
if( !end || !begin )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = cursor_pos - (begin - buff);
|
pos = cursor_pos - (begin - buff);
|
||||||
|
|
||||||
a = (wchar_t *)buff + pos;
|
a = (wchar_t *)buff + pos;
|
||||||
b = a;
|
b = a;
|
||||||
pa = (wchar_t *)buff + pos;
|
pa = (wchar_t *)buff + pos;
|
||||||
pb = pa;
|
pb = pa;
|
||||||
|
|
||||||
assert( begin >= buff );
|
assert( begin >= buff );
|
||||||
assert( begin <= (buff+wcslen(buff) ) );
|
assert( begin <= (buff+wcslen(buff) ) );
|
||||||
assert( end >= begin );
|
assert( end >= begin );
|
||||||
assert( end <= (buff+wcslen(buff) ) );
|
assert( end <= (buff+wcslen(buff) ) );
|
||||||
|
|
||||||
buffcpy = wcsndup( begin, end-begin );
|
buffcpy = wcsndup( begin, end-begin );
|
||||||
|
|
||||||
if( !buffcpy )
|
if( !buffcpy )
|
||||||
{
|
{
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
|
@ -563,7 +563,7 @@ void parse_util_token_extent( const wchar_t *buff,
|
||||||
{
|
{
|
||||||
tok_end +=wcslen(tok_last(&tok));
|
tok_end +=wcslen(tok_last(&tok));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Cursor was before beginning of this token, means that the
|
Cursor was before beginning of this token, means that the
|
||||||
cursor is between two tokens, so we set it to a zero element
|
cursor is between two tokens, so we set it to a zero element
|
||||||
|
@ -580,12 +580,12 @@ void parse_util_token_extent( const wchar_t *buff,
|
||||||
looking for. If so, set a and b and break
|
looking for. If so, set a and b and break
|
||||||
*/
|
*/
|
||||||
if( (tok_last_type( &tok ) == TOK_STRING) && (tok_end >= pos ) )
|
if( (tok_last_type( &tok ) == TOK_STRING) && (tok_end >= pos ) )
|
||||||
{
|
{
|
||||||
a = begin + tok_get_pos( &tok );
|
a = begin + tok_get_pos( &tok );
|
||||||
b = a + wcslen(tok_last(&tok));
|
b = a + wcslen(tok_last(&tok));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Remember previous string token
|
Remember previous string token
|
||||||
*/
|
*/
|
||||||
|
@ -597,7 +597,7 @@ void parse_util_token_extent( const wchar_t *buff,
|
||||||
}
|
}
|
||||||
|
|
||||||
free( buffcpy);
|
free( buffcpy);
|
||||||
|
|
||||||
tok_destroy( &tok );
|
tok_destroy( &tok );
|
||||||
|
|
||||||
if( tok_begin )
|
if( tok_begin )
|
||||||
|
@ -619,7 +619,7 @@ void parse_util_token_extent( const wchar_t *buff,
|
||||||
{
|
{
|
||||||
*prev_end = pb;
|
*prev_end = pb;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert( pa >= buff );
|
assert( pa >= buff );
|
||||||
assert( pa <= (buff+wcslen(buff) ) );
|
assert( pa <= (buff+wcslen(buff) ) );
|
||||||
assert( pb >= pa );
|
assert( pb >= pa );
|
||||||
|
@ -648,14 +648,14 @@ static void clear_hash_value( void *key, void *data, void *aux )
|
||||||
handler( name );
|
handler( name );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free( (void *)data );
|
free( (void *)data );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Part of the autoloader cleanup
|
Part of the autoloader cleanup
|
||||||
*/
|
*/
|
||||||
static void clear_loaded_entry( void *key,
|
static void clear_loaded_entry( void *key,
|
||||||
void *data,
|
void *data,
|
||||||
void *handler )
|
void *handler )
|
||||||
{
|
{
|
||||||
|
@ -667,7 +667,7 @@ static void clear_loaded_entry( void *key,
|
||||||
hash_destroy( &loaded->is_loading );
|
hash_destroy( &loaded->is_loading );
|
||||||
|
|
||||||
free( loaded->old_path );
|
free( loaded->old_path );
|
||||||
free( loaded );
|
free( loaded );
|
||||||
free( (void *)key );
|
free( (void *)key );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -683,9 +683,9 @@ static void parse_util_destroy()
|
||||||
hash_foreach2( all_loaded,
|
hash_foreach2( all_loaded,
|
||||||
&clear_loaded_entry,
|
&clear_loaded_entry,
|
||||||
0 );
|
0 );
|
||||||
|
|
||||||
hash_destroy( all_loaded );
|
hash_destroy( all_loaded );
|
||||||
free( all_loaded );
|
free( all_loaded );
|
||||||
all_loaded = 0;
|
all_loaded = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -704,7 +704,7 @@ void parse_util_load_reset( const wchar_t *path_var_name,
|
||||||
clear_loaded_entry( key, data, (void *)on_load );
|
clear_loaded_entry( key, data, (void *)on_load );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_util_unload( const wchar_t *cmd,
|
int parse_util_unload( const wchar_t *cmd,
|
||||||
|
@ -721,14 +721,14 @@ int parse_util_unload( const wchar_t *cmd,
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
loaded = (autoload_t *)hash_get( all_loaded, path_var_name );
|
loaded = (autoload_t *)hash_get( all_loaded, path_var_name );
|
||||||
|
|
||||||
if( !loaded )
|
if( !loaded )
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
hash_remove( &loaded->load_time, cmd, 0, &val );
|
hash_remove( &loaded->load_time, cmd, 0, &val );
|
||||||
if( val )
|
if( val )
|
||||||
{
|
{
|
||||||
|
@ -738,7 +738,7 @@ int parse_util_unload( const wchar_t *cmd,
|
||||||
}
|
}
|
||||||
free( val );
|
free( val );
|
||||||
}
|
}
|
||||||
|
|
||||||
return !!val;
|
return !!val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -763,13 +763,13 @@ static void parse_util_autounload( const wchar_t *path_var_name,
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
loaded = (autoload_t *)hash_get( all_loaded, path_var_name );
|
loaded = (autoload_t *)hash_get( all_loaded, path_var_name );
|
||||||
if( !loaded )
|
if( !loaded )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( hash_get_count( &loaded->load_time ) >= AUTOLOAD_MAX )
|
if( hash_get_count( &loaded->load_time ) >= AUTOLOAD_MAX )
|
||||||
{
|
{
|
||||||
time_t oldest_access = time(0) - AUTOLOAD_MIN_AGE;
|
time_t oldest_access = time(0) - AUTOLOAD_MIN_AGE;
|
||||||
|
@ -787,19 +787,19 @@ static void parse_util_autounload( const wchar_t *path_var_name,
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !tm[0] )
|
if( !tm[0] )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( hash_get( &loaded->is_loading, item ) )
|
if( hash_get( &loaded->is_loading, item ) )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
loaded_count++;
|
loaded_count++;
|
||||||
|
|
||||||
if( tm[1] < oldest_access )
|
if( tm[1] < oldest_access )
|
||||||
{
|
{
|
||||||
oldest_access = tm[1];
|
oldest_access = tm[1];
|
||||||
|
@ -807,7 +807,7 @@ static void parse_util_autounload( const wchar_t *path_var_name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
al_destroy( &key );
|
al_destroy( &key );
|
||||||
|
|
||||||
if( oldest_item && loaded_count > AUTOLOAD_MAX)
|
if( oldest_item && loaded_count > AUTOLOAD_MAX)
|
||||||
{
|
{
|
||||||
parse_util_unload( oldest_item, path_var_name, on_load );
|
parse_util_unload( oldest_item, path_var_name, on_load );
|
||||||
|
@ -835,17 +835,17 @@ int parse_util_load( const wchar_t *cmd,
|
||||||
|
|
||||||
int res;
|
int res;
|
||||||
int c, c2;
|
int c, c2;
|
||||||
|
|
||||||
CHECK( path_var_name, 0 );
|
CHECK( path_var_name, 0 );
|
||||||
CHECK( cmd, 0 );
|
CHECK( cmd, 0 );
|
||||||
|
|
||||||
CHECK_BLOCK( 0 );
|
CHECK_BLOCK( 0 );
|
||||||
|
|
||||||
// debug( 0, L"Autoload %ls in %ls", cmd, path_var_name );
|
// debug( 0, L"Autoload %ls in %ls", cmd, path_var_name );
|
||||||
|
|
||||||
parse_util_autounload( path_var_name, cmd, on_load );
|
parse_util_autounload( path_var_name, cmd, on_load );
|
||||||
path_var = env_get( path_var_name );
|
path_var = env_get( path_var_name );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Do we know where to look?
|
Do we know where to look?
|
||||||
*/
|
*/
|
||||||
|
@ -859,7 +859,7 @@ int parse_util_load( const wchar_t *cmd,
|
||||||
*/
|
*/
|
||||||
if( !all_loaded )
|
if( !all_loaded )
|
||||||
{
|
{
|
||||||
all_loaded = malloc( sizeof( hash_table_t ) );
|
all_loaded = malloc( sizeof( hash_table_t ) );
|
||||||
halloc_register_function_void( global_context, &parse_util_destroy );
|
halloc_register_function_void( global_context, &parse_util_destroy );
|
||||||
if( !all_loaded )
|
if( !all_loaded )
|
||||||
{
|
{
|
||||||
|
@ -867,7 +867,7 @@ int parse_util_load( const wchar_t *cmd,
|
||||||
}
|
}
|
||||||
hash_init( all_loaded, &hash_wcs_func, &hash_wcs_cmp );
|
hash_init( all_loaded, &hash_wcs_func, &hash_wcs_cmp );
|
||||||
}
|
}
|
||||||
|
|
||||||
loaded = (autoload_t *)hash_get( all_loaded, path_var_name );
|
loaded = (autoload_t *)hash_get( all_loaded, path_var_name );
|
||||||
|
|
||||||
if( loaded )
|
if( loaded )
|
||||||
|
@ -888,13 +888,13 @@ int parse_util_load( const wchar_t *cmd,
|
||||||
*/
|
*/
|
||||||
if( hash_get( &loaded->is_loading, cmd ) )
|
if( hash_get( &loaded->is_loading, cmd ) )
|
||||||
{
|
{
|
||||||
debug( 0,
|
debug( 0,
|
||||||
_( L"Could not autoload item '%ls', it is already being autoloaded. "
|
_( L"Could not autoload item '%ls', it is already being autoloaded. "
|
||||||
L"This is a circular dependency in the autoloading scripts, please remove it."),
|
L"This is a circular dependency in the autoloading scripts, please remove it."),
|
||||||
cmd );
|
cmd );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -911,7 +911,7 @@ int parse_util_load( const wchar_t *cmd,
|
||||||
}
|
}
|
||||||
hash_init( &loaded->load_time, &hash_wcs_func, &hash_wcs_cmp );
|
hash_init( &loaded->load_time, &hash_wcs_func, &hash_wcs_cmp );
|
||||||
hash_put( all_loaded, wcsdup(path_var_name), loaded );
|
hash_put( all_loaded, wcsdup(path_var_name), loaded );
|
||||||
|
|
||||||
hash_init( &loaded->is_loading, &hash_wcs_func, &hash_wcs_cmp );
|
hash_init( &loaded->is_loading, &hash_wcs_func, &hash_wcs_cmp );
|
||||||
|
|
||||||
loaded->old_path = wcsdup( path_var );
|
loaded->old_path = wcsdup( path_var );
|
||||||
|
@ -919,11 +919,11 @@ int parse_util_load( const wchar_t *cmd,
|
||||||
|
|
||||||
|
|
||||||
path_list = al_new( global_context);
|
path_list = al_new( global_context);
|
||||||
|
|
||||||
tokenize_variable_array( path_var, path_list );
|
tokenize_variable_array( path_var, path_list );
|
||||||
|
|
||||||
c = al_get_count( path_list );
|
c = al_get_count( path_list );
|
||||||
|
|
||||||
hash_put( &loaded->is_loading, cmd, cmd );
|
hash_put( &loaded->is_loading, cmd, cmd );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -940,7 +940,7 @@ int parse_util_load( const wchar_t *cmd,
|
||||||
*/
|
*/
|
||||||
hash_remove( &loaded->is_loading, cmd, 0, 0 );
|
hash_remove( &loaded->is_loading, cmd, 0, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
c2 = al_get_count( path_list );
|
c2 = al_get_count( path_list );
|
||||||
|
|
||||||
al_foreach( path_list, &free );
|
al_foreach( path_list, &free );
|
||||||
|
@ -950,9 +950,9 @@ int parse_util_load( const wchar_t *cmd,
|
||||||
/**
|
/**
|
||||||
Make sure we didn't 'drop' something
|
Make sure we didn't 'drop' something
|
||||||
*/
|
*/
|
||||||
|
|
||||||
assert( c == c2 );
|
assert( c == c2 );
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -977,7 +977,7 @@ static int parse_util_load_internal( const wchar_t *cmd,
|
||||||
Get modification time of file
|
Get modification time of file
|
||||||
*/
|
*/
|
||||||
tm = (time_t *)hash_get( &loaded->load_time, cmd );
|
tm = (time_t *)hash_get( &loaded->load_time, cmd );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Did we just check this?
|
Did we just check this?
|
||||||
*/
|
*/
|
||||||
|
@ -988,7 +988,7 @@ static int parse_util_load_internal( const wchar_t *cmd,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Return if already loaded and we are skipping reloading
|
Return if already loaded and we are skipping reloading
|
||||||
*/
|
*/
|
||||||
|
@ -996,7 +996,7 @@ static int parse_util_load_internal( const wchar_t *cmd,
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !path )
|
if( !path )
|
||||||
{
|
{
|
||||||
path = sb_halloc( global_context );
|
path = sb_halloc( global_context );
|
||||||
|
@ -1005,7 +1005,7 @@ static int parse_util_load_internal( const wchar_t *cmd,
|
||||||
{
|
{
|
||||||
sb_clear( path );
|
sb_clear( path );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Iterate over path searching for suitable completion files
|
Iterate over path searching for suitable completion files
|
||||||
*/
|
*/
|
||||||
|
@ -1024,7 +1024,7 @@ static int parse_util_load_internal( const wchar_t *cmd,
|
||||||
wchar_t *esc = escape( (wchar_t *)path->buff, 1 );
|
wchar_t *esc = escape( (wchar_t *)path->buff, 1 );
|
||||||
wchar_t *src_cmd = wcsdupcat( L". ", esc );
|
wchar_t *src_cmd = wcsdupcat( L". ", esc );
|
||||||
free( esc );
|
free( esc );
|
||||||
|
|
||||||
if( !tm )
|
if( !tm )
|
||||||
{
|
{
|
||||||
tm = malloc(sizeof(time_t)*2);
|
tm = malloc(sizeof(time_t)*2);
|
||||||
|
@ -1044,7 +1044,7 @@ static int parse_util_load_internal( const wchar_t *cmd,
|
||||||
{
|
{
|
||||||
on_load(cmd );
|
on_load(cmd );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Source the completion file for the specified completion
|
Source the completion file for the specified completion
|
||||||
*/
|
*/
|
||||||
|
@ -1054,7 +1054,7 @@ static int parse_util_load_internal( const wchar_t *cmd,
|
||||||
Do nothing on failiure
|
Do nothing on failiure
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
free(src_cmd);
|
free(src_cmd);
|
||||||
reloaded = 1;
|
reloaded = 1;
|
||||||
}
|
}
|
||||||
|
@ -1064,9 +1064,9 @@ static int parse_util_load_internal( const wchar_t *cmd,
|
||||||
If we are rechecking an autoload file, and it hasn't
|
If we are rechecking an autoload file, and it hasn't
|
||||||
changed, update the 'last check' timestamp.
|
changed, update the 'last check' timestamp.
|
||||||
*/
|
*/
|
||||||
tm[1] = time(0);
|
tm[1] = time(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1083,13 +1083,13 @@ static int parse_util_load_internal( const wchar_t *cmd,
|
||||||
{
|
{
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
}
|
}
|
||||||
|
|
||||||
tm[0] = 0;
|
tm[0] = 0;
|
||||||
tm[1] = time(0);
|
tm[1] = time(0);
|
||||||
hash_put( &loaded->load_time, intern( cmd ), tm );
|
hash_put( &loaded->load_time, intern( cmd ), tm );
|
||||||
}
|
}
|
||||||
|
|
||||||
return reloaded;
|
return reloaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_util_set_argv( wchar_t **argv, array_list_t *named_arguments )
|
void parse_util_set_argv( wchar_t **argv, array_list_t *named_arguments )
|
||||||
|
@ -1099,7 +1099,7 @@ void parse_util_set_argv( wchar_t **argv, array_list_t *named_arguments )
|
||||||
wchar_t **arg;
|
wchar_t **arg;
|
||||||
string_buffer_t sb;
|
string_buffer_t sb;
|
||||||
sb_init( &sb );
|
sb_init( &sb );
|
||||||
|
|
||||||
for( arg=argv; *arg; arg++ )
|
for( arg=argv; *arg; arg++ )
|
||||||
{
|
{
|
||||||
if( arg != argv )
|
if( arg != argv )
|
||||||
|
@ -1108,20 +1108,20 @@ void parse_util_set_argv( wchar_t **argv, array_list_t *named_arguments )
|
||||||
}
|
}
|
||||||
sb_append( &sb, *arg );
|
sb_append( &sb, *arg );
|
||||||
}
|
}
|
||||||
|
|
||||||
env_set( L"argv", (wchar_t *)sb.buff, ENV_LOCAL );
|
env_set( L"argv", (wchar_t *)sb.buff, ENV_LOCAL );
|
||||||
sb_destroy( &sb );
|
sb_destroy( &sb );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
env_set( L"argv", 0, ENV_LOCAL );
|
env_set( L"argv", 0, ENV_LOCAL );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( named_arguments )
|
if( named_arguments )
|
||||||
{
|
{
|
||||||
wchar_t **arg;
|
wchar_t **arg;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for( i=0, arg=argv; i < al_get_count( named_arguments ); i++ )
|
for( i=0, arg=argv; i < al_get_count( named_arguments ); i++ )
|
||||||
{
|
{
|
||||||
env_set( al_get( named_arguments, i ), *arg, ENV_LOCAL );
|
env_set( al_get( named_arguments, i ), *arg, ENV_LOCAL );
|
||||||
|
@ -1129,10 +1129,10 @@ void parse_util_set_argv( wchar_t **argv, array_list_t *named_arguments )
|
||||||
if( *arg )
|
if( *arg )
|
||||||
arg++;
|
arg++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t *parse_util_unescape_wildcards( const wchar_t *str )
|
wchar_t *parse_util_unescape_wildcards( const wchar_t *str )
|
||||||
|
@ -1141,14 +1141,14 @@ wchar_t *parse_util_unescape_wildcards( const wchar_t *str )
|
||||||
wchar_t *unescaped;
|
wchar_t *unescaped;
|
||||||
|
|
||||||
CHECK( str, 0 );
|
CHECK( str, 0 );
|
||||||
|
|
||||||
unescaped = wcsdup(str);
|
unescaped = wcsdup(str);
|
||||||
|
|
||||||
if( !unescaped )
|
if( !unescaped )
|
||||||
{
|
{
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
}
|
}
|
||||||
|
|
||||||
for( in=out=unescaped; *in; in++ )
|
for( in=out=unescaped; *in; in++ )
|
||||||
{
|
{
|
||||||
switch( *in )
|
switch( *in )
|
||||||
|
@ -1163,25 +1163,25 @@ wchar_t *parse_util_unescape_wildcards( const wchar_t *str )
|
||||||
*(out++)=*in;
|
*(out++)=*in;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case L'*':
|
case L'*':
|
||||||
{
|
{
|
||||||
*(out++)=ANY_STRING;
|
*(out++)=ANY_STRING;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case L'?':
|
case L'?':
|
||||||
{
|
{
|
||||||
*(out++)=ANY_CHAR;
|
*(out++)=ANY_CHAR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
*(out++)=*in;
|
*(out++)=*in;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return unescaped;
|
return unescaped;
|
||||||
}
|
}
|
||||||
|
|
18
parse_util.h
18
parse_util.h
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Find the beginning and end of the first subshell in the specified string.
|
Find the beginning and end of the first subshell in the specified string.
|
||||||
|
|
||||||
\param in the string to search for subshells
|
\param in the string to search for subshells
|
||||||
\param begin the starting paranthesis of the subshell
|
\param begin the starting paranthesis of the subshell
|
||||||
\param end the ending paranthesis of the subshell
|
\param end the ending paranthesis of the subshell
|
||||||
|
@ -19,8 +19,8 @@
|
||||||
\return -1 on syntax error, 0 if no subshells exist and 1 on sucess
|
\return -1 on syntax error, 0 if no subshells exist and 1 on sucess
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int parse_util_locate_cmdsubst( const wchar_t *in,
|
int parse_util_locate_cmdsubst( const wchar_t *in,
|
||||||
wchar_t **begin,
|
wchar_t **begin,
|
||||||
wchar_t **end,
|
wchar_t **end,
|
||||||
int flags );
|
int flags );
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ int parse_util_locate_cmdsubst( const wchar_t *in,
|
||||||
*/
|
*/
|
||||||
void parse_util_cmdsubst_extent( const wchar_t *buff,
|
void parse_util_cmdsubst_extent( const wchar_t *buff,
|
||||||
int cursor_pos,
|
int cursor_pos,
|
||||||
wchar_t **a,
|
wchar_t **a,
|
||||||
wchar_t **b );
|
wchar_t **b );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,7 +51,7 @@ void parse_util_cmdsubst_extent( const wchar_t *buff,
|
||||||
*/
|
*/
|
||||||
void parse_util_process_extent( const wchar_t *buff,
|
void parse_util_process_extent( const wchar_t *buff,
|
||||||
int cursor_pos,
|
int cursor_pos,
|
||||||
wchar_t **a,
|
wchar_t **a,
|
||||||
wchar_t **b );
|
wchar_t **b );
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ void parse_util_process_extent( const wchar_t *buff,
|
||||||
*/
|
*/
|
||||||
void parse_util_job_extent( const wchar_t *buff,
|
void parse_util_job_extent( const wchar_t *buff,
|
||||||
int cursor_pos,
|
int cursor_pos,
|
||||||
wchar_t **a,
|
wchar_t **a,
|
||||||
wchar_t **b );
|
wchar_t **b );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,7 +84,7 @@ void parse_util_token_extent( const wchar_t *buff,
|
||||||
int cursor_pos,
|
int cursor_pos,
|
||||||
wchar_t **tok_begin,
|
wchar_t **tok_begin,
|
||||||
wchar_t **tok_end,
|
wchar_t **tok_end,
|
||||||
wchar_t **prev_begin,
|
wchar_t **prev_begin,
|
||||||
wchar_t **prev_end );
|
wchar_t **prev_end );
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ int parse_util_get_offset( wchar_t *buff, int line, int line_offset );
|
||||||
not load it multiple times unless it's timestamp changes or
|
not load it multiple times unless it's timestamp changes or
|
||||||
parse_util_unload is called.
|
parse_util_unload is called.
|
||||||
|
|
||||||
Autoloading one file may unload another.
|
Autoloading one file may unload another.
|
||||||
|
|
||||||
\param cmd the filename to search for. The suffix '.fish' is always added to this name
|
\param cmd the filename to search for. The suffix '.fish' is always added to this name
|
||||||
\param path_var_name the environment variable giving the search path
|
\param path_var_name the environment variable giving the search path
|
||||||
|
@ -153,7 +153,7 @@ int parse_util_unload( const wchar_t *cmd,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set the argv environment variable to the specified null-terminated
|
Set the argv environment variable to the specified null-terminated
|
||||||
array of strings.
|
array of strings.
|
||||||
*/
|
*/
|
||||||
void parse_util_set_argv( wchar_t **argv, array_list_t *named_arguments );
|
void parse_util_set_argv( wchar_t **argv, array_list_t *named_arguments );
|
||||||
|
|
||||||
|
|
44
parser.h
44
parser.h
|
@ -1,5 +1,5 @@
|
||||||
/** \file parser.h
|
/** \file parser.h
|
||||||
The fish parser.
|
The fish parser.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef FISH_PARSER_H
|
#ifndef FISH_PARSER_H
|
||||||
|
@ -24,12 +24,12 @@ typedef struct event_block
|
||||||
The types of events to block. This is interpreted as a bitset
|
The types of events to block. This is interpreted as a bitset
|
||||||
whete the value is 1 for every bit corresponding to a blocked
|
whete the value is 1 for every bit corresponding to a blocked
|
||||||
event type. For example, if EVENT_VARIABLE type events should
|
event type. For example, if EVENT_VARIABLE type events should
|
||||||
be blocked, (type & 1<<EVENT_BLOCKED) should be set.
|
be blocked, (type & 1<<EVENT_BLOCKED) should be set.
|
||||||
|
|
||||||
Note that EVENT_ANY can be used to specify any event.
|
Note that EVENT_ANY can be used to specify any event.
|
||||||
*/
|
*/
|
||||||
int type;
|
int type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The next event_block struct
|
The next event_block struct
|
||||||
*/
|
*/
|
||||||
|
@ -40,7 +40,7 @@ typedef struct event_block
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
block_t represents a block of commands.
|
block_t represents a block of commands.
|
||||||
*/
|
*/
|
||||||
typedef struct block
|
typedef struct block
|
||||||
{
|
{
|
||||||
|
@ -48,7 +48,7 @@ typedef struct block
|
||||||
int skip; /**< Whether execution of the commands in this block should be skipped */
|
int skip; /**< Whether execution of the commands in this block should be skipped */
|
||||||
int tok_pos; /**< The start index of the block */
|
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 */
|
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.
|
Status for the current loop block. Can be any of the values from the loop_status enum.
|
||||||
*/
|
*/
|
||||||
|
@ -63,18 +63,18 @@ typedef struct block
|
||||||
Block type-specific data
|
Block type-specific data
|
||||||
*/
|
*/
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
First block type specific variable
|
First block type specific variable
|
||||||
*/
|
*/
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
int while_state; /**< True if the loop condition has not yet been evaluated*/
|
int while_state; /**< True if the loop condition has not yet been evaluated*/
|
||||||
wchar_t *for_variable; /**< Name of the variable to loop over */
|
wchar_t *for_variable; /**< Name of the variable to loop over */
|
||||||
int if_state; /**< The state of the if block, can be one of IF_STATE_UNTESTED, IF_STATE_FALSE, IF_STATE_TRUE */
|
int if_state; /**< The state of the if block, can be one of IF_STATE_UNTESTED, IF_STATE_FALSE, IF_STATE_TRUE */
|
||||||
wchar_t *switch_value; /**< The value to test in a switch block */
|
wchar_t *switch_value; /**< The value to test in a switch block */
|
||||||
const wchar_t *source_dest; /**< The name of the file to source*/
|
const wchar_t *source_dest; /**< The name of the file to source*/
|
||||||
event_t *event; /**<The event that triggered this block */
|
event_t *event; /**<The event that triggered this block */
|
||||||
wchar_t *function_call_name;
|
wchar_t *function_call_name;
|
||||||
} param1;
|
} param1;
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ typedef struct block
|
||||||
*/
|
*/
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
array_list_t for_vars; /**< List of values for a for block */
|
array_list_t for_vars; /**< List of values for a for block */
|
||||||
int switch_taken; /**< Whether a switch match has already been found */
|
int switch_taken; /**< Whether a switch match has already been found */
|
||||||
process_t *function_call_process; /**< The process representing this function call */
|
process_t *function_call_process; /**< The process representing this function call */
|
||||||
} param2;
|
} param2;
|
||||||
|
@ -93,24 +93,24 @@ typedef struct block
|
||||||
Name of file that created this block
|
Name of file that created this block
|
||||||
*/
|
*/
|
||||||
const wchar_t *src_filename;
|
const wchar_t *src_filename;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Line number where this block was created
|
Line number where this block was created
|
||||||
*/
|
*/
|
||||||
int src_lineno;
|
int src_lineno;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Some naming confusion. This is a pointer to the first element in the list of all event blocks.
|
Some naming confusion. This is a pointer to the first element in the list of all event blocks.
|
||||||
*/
|
*/
|
||||||
event_block_t *first_event_block;
|
event_block_t *first_event_block;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Next outer block
|
Next outer block
|
||||||
*/
|
*/
|
||||||
struct block *outer;
|
struct block *outer;
|
||||||
} block_t;
|
} block_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Types of blocks
|
Types of blocks
|
||||||
*/
|
*/
|
||||||
enum block_type
|
enum block_type
|
||||||
|
@ -135,7 +135,7 @@ enum block_type
|
||||||
/**
|
/**
|
||||||
Possible states for a loop
|
Possible states for a loop
|
||||||
*/
|
*/
|
||||||
enum loop_status
|
enum loop_status
|
||||||
{
|
{
|
||||||
LOOP_NORMAL, /**< Current loop block executed as normal */
|
LOOP_NORMAL, /**< Current loop block executed as normal */
|
||||||
LOOP_BREAK, /**< Current loop block should be removed */
|
LOOP_BREAK, /**< Current loop block should be removed */
|
||||||
|
@ -159,14 +159,14 @@ enum while_status
|
||||||
/**
|
/**
|
||||||
Errors that can be generated by the parser
|
Errors that can be generated by the parser
|
||||||
*/
|
*/
|
||||||
enum parser_error
|
enum parser_error
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
No error
|
No error
|
||||||
*/
|
*/
|
||||||
NO_ERR=0,
|
NO_ERR=0,
|
||||||
/**
|
/**
|
||||||
An error in the syntax
|
An error in the syntax
|
||||||
*/
|
*/
|
||||||
SYNTAX_ERROR,
|
SYNTAX_ERROR,
|
||||||
/**
|
/**
|
||||||
|
@ -187,7 +187,7 @@ extern block_t *current_block;
|
||||||
extern event_block_t *global_event_block;
|
extern event_block_t *global_event_block;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Current block level io redirections
|
Current block level io redirections
|
||||||
*/
|
*/
|
||||||
extern io_data_t *block_io;
|
extern io_data_t *block_io;
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ int eval_args( const wchar_t *line,
|
||||||
array_list_t *output );
|
array_list_t *output );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Sets the current evaluation error. This function should only be used by libraries that are called by
|
Sets the current evaluation error. This function should only be used by libraries that are called by
|
||||||
|
|
||||||
\param ec The new error code
|
\param ec The new error code
|
||||||
\param p The character offset at which the error occured
|
\param p The character offset at which the error occured
|
||||||
|
@ -224,7 +224,7 @@ void error( int ec, int p, const wchar_t *str, ... );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns a string describing the current parser pisition in the format 'FILENAME (line LINE_NUMBER): LINE'.
|
Returns a string describing the current parser pisition in the format 'FILENAME (line LINE_NUMBER): LINE'.
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
init.fish (line 127): ls|grep pancake
|
init.fish (line 127): ls|grep pancake
|
||||||
*/
|
*/
|
||||||
|
@ -315,7 +315,7 @@ void parser_init();
|
||||||
void parser_destroy();
|
void parser_destroy();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This function checks if the specified string is a help option.
|
This function checks if the specified string is a help option.
|
||||||
|
|
||||||
\param s the string to test
|
\param s the string to test
|
||||||
\param min_match is the minimum number of characters that must match in a long style option, i.e. the longest common prefix between --help and any other option. If less than 3, 3 will be assumed.
|
\param min_match is the minimum number of characters that must match in a long style option, i.e. the longest common prefix between --help and any other option. If less than 3, 3 will be assumed.
|
||||||
|
|
|
@ -18,7 +18,7 @@ int parser_keywords_is_switch( const wchar_t *cmd )
|
||||||
{
|
{
|
||||||
if( wcscmp( cmd, L"--" ) == 0 )
|
if( wcscmp( cmd, L"--" ) == 0 )
|
||||||
return ARG_SKIP;
|
return ARG_SKIP;
|
||||||
else
|
else
|
||||||
return cmd[0] == L'-';
|
return cmd[0] == L'-';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ int parser_keywords_is_subcommand( const wchar_t *cmd )
|
||||||
L"and",
|
L"and",
|
||||||
L"or",
|
L"or",
|
||||||
L"not" );
|
L"not" );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int parser_keywords_is_block( const wchar_t *word)
|
int parser_keywords_is_block( const wchar_t *word)
|
||||||
|
|
|
@ -9,7 +9,7 @@ Functions having to do with parser keywords, like testing if a function is a blo
|
||||||
/**
|
/**
|
||||||
Return valuse for parser_keywords_is_switch()
|
Return valuse for parser_keywords_is_switch()
|
||||||
*/
|
*/
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
ARG_NON_SWITCH,
|
ARG_NON_SWITCH,
|
||||||
ARG_SWITCH,
|
ARG_SWITCH,
|
||||||
|
@ -27,7 +27,7 @@ int parser_keywords_is_switch( const wchar_t *cmd );
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Tests if the specified commands parameters should be interpreted as another command, which will be true if the command is either 'command', 'exec', 'if', 'while' or 'builtin'.
|
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
|
\param cmd The command name to test
|
||||||
\return 1 of the command parameter is a command, 0 otherwise
|
\return 1 of the command parameter is a command, 0 otherwise
|
||||||
|
|
36
path.c
36
path.c
|
@ -32,7 +32,7 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
|
||||||
wchar_t *path;
|
wchar_t *path;
|
||||||
|
|
||||||
int err = ENOENT;
|
int err = ENOENT;
|
||||||
|
|
||||||
CHECK( cmd, 0 );
|
CHECK( cmd, 0 );
|
||||||
|
|
||||||
debug( 3, L"path_get_path( '%ls' )", cmd );
|
debug( 3, L"path_get_path( '%ls' )", cmd );
|
||||||
|
@ -46,7 +46,7 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( S_ISREG(buff.st_mode) )
|
if( S_ISREG(buff.st_mode) )
|
||||||
return halloc_wcsdup( context, cmd );
|
return halloc_wcsdup( context, cmd );
|
||||||
else
|
else
|
||||||
|
@ -61,7 +61,7 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
|
||||||
wstat( cmd, &buff );
|
wstat( cmd, &buff );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -77,12 +77,12 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
|
||||||
path = L"/bin" ARRAY_SEP_STR L"/usr/bin" ARRAY_SEP_STR PREFIX L"/bin";
|
path = L"/bin" ARRAY_SEP_STR L"/usr/bin" ARRAY_SEP_STR PREFIX L"/bin";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Allocate string long enough to hold the whole command
|
Allocate string long enough to hold the whole command
|
||||||
*/
|
*/
|
||||||
wchar_t *new_cmd = halloc( context, sizeof(wchar_t)*(wcslen(cmd)+wcslen(path)+2) );
|
wchar_t *new_cmd = halloc( context, sizeof(wchar_t)*(wcslen(cmd)+wcslen(path)+2) );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
We tokenize a copy of the path, since strtok modifies
|
We tokenize a copy of the path, since strtok modifies
|
||||||
its arguments
|
its arguments
|
||||||
|
@ -90,7 +90,7 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
|
||||||
wchar_t *path_cpy = wcsdup( path );
|
wchar_t *path_cpy = wcsdup( path );
|
||||||
wchar_t *nxt_path = path;
|
wchar_t *nxt_path = path;
|
||||||
wchar_t *state;
|
wchar_t *state;
|
||||||
|
|
||||||
if( (new_cmd==0) || (path_cpy==0) )
|
if( (new_cmd==0) || (path_cpy==0) )
|
||||||
{
|
{
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
|
@ -124,7 +124,7 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
|
||||||
return new_cmd;
|
return new_cmd;
|
||||||
}
|
}
|
||||||
err = EACCES;
|
err = EACCES;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -229,7 +229,7 @@ wchar_t *path_get_cdpath( void *context, wchar_t *dir )
|
||||||
if( S_ISDIR(buf.st_mode) )
|
if( S_ISDIR(buf.st_mode) )
|
||||||
{
|
{
|
||||||
res = whole_path;
|
res = whole_path;
|
||||||
halloc_register( context, whole_path );
|
halloc_register( context, whole_path );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -244,7 +244,7 @@ wchar_t *path_get_cdpath( void *context, wchar_t *dir )
|
||||||
err = EROTTEN;
|
err = EROTTEN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free( whole_path );
|
free( whole_path );
|
||||||
}
|
}
|
||||||
free( path_cpy );
|
free( path_cpy );
|
||||||
|
@ -264,7 +264,7 @@ wchar_t *path_get_config( void *context)
|
||||||
wchar_t *xdg_dir, *home;
|
wchar_t *xdg_dir, *home;
|
||||||
int done = 0;
|
int done = 0;
|
||||||
wchar_t *res = 0;
|
wchar_t *res = 0;
|
||||||
|
|
||||||
xdg_dir = env_get( L"XDG_CONFIG_HOME" );
|
xdg_dir = env_get( L"XDG_CONFIG_HOME" );
|
||||||
if( xdg_dir )
|
if( xdg_dir )
|
||||||
{
|
{
|
||||||
|
@ -277,10 +277,10 @@ wchar_t *path_get_config( void *context)
|
||||||
{
|
{
|
||||||
free( res );
|
free( res );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
home = env_get( L"HOME" );
|
home = env_get( L"HOME" );
|
||||||
if( home )
|
if( home )
|
||||||
{
|
{
|
||||||
|
@ -295,7 +295,7 @@ wchar_t *path_get_config( void *context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( done )
|
if( done )
|
||||||
{
|
{
|
||||||
halloc_register_function( context, &free, res );
|
halloc_register_function( context, &free, res );
|
||||||
|
@ -306,16 +306,16 @@ wchar_t *path_get_config( void *context)
|
||||||
debug( 0, _(L"Unable to create a configuration directory for fish. Your personal settings will not be saved. Please set the $XDG_CONFIG_HOME variable to a directory where the current user has write access." ));
|
debug( 0, _(L"Unable to create a configuration directory for fish. Your personal settings will not be saved. Please set the $XDG_CONFIG_HOME variable to a directory where the current user has write access." ));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t *path_make_canonical( void *context, const wchar_t *path )
|
wchar_t *path_make_canonical( void *context, const wchar_t *path )
|
||||||
{
|
{
|
||||||
wchar_t *res = halloc_wcsdup( context, path );
|
wchar_t *res = halloc_wcsdup( context, path );
|
||||||
wchar_t *in, *out;
|
wchar_t *in, *out;
|
||||||
|
|
||||||
in = out = res;
|
in = out = res;
|
||||||
|
|
||||||
while( *in )
|
while( *in )
|
||||||
{
|
{
|
||||||
if( *in == L'/' )
|
if( *in == L'/' )
|
||||||
|
@ -326,7 +326,7 @@ wchar_t *path_make_canonical( void *context, const wchar_t *path )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*out = *in;
|
*out = *in;
|
||||||
|
|
||||||
out++;
|
out++;
|
||||||
in++;
|
in++;
|
||||||
}
|
}
|
||||||
|
@ -340,7 +340,7 @@ wchar_t *path_make_canonical( void *context, const wchar_t *path )
|
||||||
out--;
|
out--;
|
||||||
}
|
}
|
||||||
*out = 0;
|
*out = 0;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
path.h
8
path.h
|
@ -25,7 +25,7 @@ wchar_t *path_get_config( void *context);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Finds the full path of an executable in a newly allocated string.
|
Finds the full path of an executable in a newly allocated string.
|
||||||
|
|
||||||
\param cmd The name of the executable.
|
\param cmd The name of the executable.
|
||||||
\param context the halloc context to use for memory allocations
|
\param context the halloc context to use for memory allocations
|
||||||
\return 0 if the command can not be found, the path of the command otherwise.
|
\return 0 if the command can not be found, the path of the command otherwise.
|
||||||
|
@ -37,14 +37,14 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd );
|
||||||
variable as a list of base directories for relative paths. The
|
variable as a list of base directories for relative paths. The
|
||||||
returned string is allocated using halloc and the specified
|
returned string is allocated using halloc and the specified
|
||||||
context.
|
context.
|
||||||
|
|
||||||
If no valid path is found, null is returned and errno is set to
|
If no valid path is found, null is returned and errno is set to
|
||||||
ENOTDIR if at least one such path was found, but it did not point
|
ENOTDIR if at least one such path was found, but it did not point
|
||||||
to a directory, EROTTEN if a arotten symbolic link was found, or
|
to a directory, EROTTEN if a arotten symbolic link was found, or
|
||||||
ENOENT if no file of the specified name was found. If both a rotten
|
ENOENT if no file of the specified name was found. If both a rotten
|
||||||
symlink and a file are found, it is undefined which error status
|
symlink and a file are found, it is undefined which error status
|
||||||
will be returned.
|
will be returned.
|
||||||
|
|
||||||
\param in The name of the directory.
|
\param in The name of the directory.
|
||||||
\param context the halloc context to use for memory allocations
|
\param context the halloc context to use for memory allocations
|
||||||
\return 0 if the command can not be found, the path of the command otherwise.
|
\return 0 if the command can not be found, the path of the command otherwise.
|
||||||
|
@ -54,7 +54,7 @@ wchar_t *path_get_cdpath( void *context, wchar_t *in );
|
||||||
/**
|
/**
|
||||||
Remove doulbe slashes and trailing slashes from a path,
|
Remove doulbe slashes and trailing slashes from a path,
|
||||||
e.g. transform foo//bar/ into foo/bar.
|
e.g. transform foo//bar/ into foo/bar.
|
||||||
|
|
||||||
The returned string is allocated using the specified halloc
|
The returned string is allocated using the specified halloc
|
||||||
context.
|
context.
|
||||||
*/
|
*/
|
||||||
|
|
10
po/en.po
10
po/en.po
|
@ -562,7 +562,7 @@ msgid "%ls: Values cannot be specfied with erase\n"
|
||||||
msgstr "%ls: Values cannot be specfied with erase\n"
|
msgstr "%ls: Values cannot be specfied with erase\n"
|
||||||
|
|
||||||
#: common.c:1756
|
#: common.c:1756
|
||||||
#,
|
#,
|
||||||
msgid "This is a bug. "
|
msgid "This is a bug. "
|
||||||
msgstr "This is a bug. "
|
msgstr "This is a bug. "
|
||||||
|
|
||||||
|
@ -637,7 +637,7 @@ msgid "handler for generic event '%ls'"
|
||||||
msgstr "handler for generic event “%ls”"
|
msgstr "handler for generic event “%ls”"
|
||||||
|
|
||||||
#: event.c:264
|
#: event.c:264
|
||||||
#,
|
#,
|
||||||
msgid "Unknown event type"
|
msgid "Unknown event type"
|
||||||
msgstr "Unknown event type"
|
msgstr "Unknown event type"
|
||||||
|
|
||||||
|
@ -791,7 +791,7 @@ msgid "Could not set up output file descriptors for pager"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: fish_pager.c:1047
|
#: fish_pager.c:1047
|
||||||
#,
|
#,
|
||||||
msgid "Could not set up input file descriptors for pager"
|
msgid "Could not set up input file descriptors for pager"
|
||||||
msgstr "Could not set up input file descriptors for pager"
|
msgstr "Could not set up input file descriptors for pager"
|
||||||
|
|
||||||
|
@ -817,7 +817,7 @@ msgid "Unspecified file descriptors"
|
||||||
msgstr "Unspecified file descriptors"
|
msgstr "Unspecified file descriptors"
|
||||||
|
|
||||||
#: fish_pager.c:1359
|
#: fish_pager.c:1359
|
||||||
#,
|
#,
|
||||||
msgid "Could not read completions"
|
msgid "Could not read completions"
|
||||||
msgstr "Could not read completions"
|
msgstr "Could not read completions"
|
||||||
|
|
||||||
|
@ -2609,7 +2609,7 @@ msgid "Specify a dir"
|
||||||
msgstr "Specify a dir"
|
msgstr "Specify a dir"
|
||||||
|
|
||||||
#: share/completions/apt-src.fish:19
|
#: share/completions/apt-src.fish:19
|
||||||
#,
|
#,
|
||||||
msgid "Omit debian version"
|
msgid "Omit debian version"
|
||||||
msgstr "Omit debian version"
|
msgstr "Omit debian version"
|
||||||
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue