From 419b3166c8853707980bc8b9912ab664e8daecd6 Mon Sep 17 00:00:00 2001 From: axel Date: Tue, 24 Apr 2007 08:00:26 +1000 Subject: Implement count as ashellscript function instead of a command in order to support very long argument lists. Note that this implementation is painfully slow for more than 1000 arguments. darcs-hash:20070423220026-ac50b-69c4b06c88e6120429b6358f1b61f6076d392ce5.gz --- Makefile.in | 15 ++------------- count.c | 24 ------------------------ doc_src/count.txt | 8 ++++---- fish.spec.in | 2 -- parser.c | 12 ++---------- 5 files changed, 8 insertions(+), 53 deletions(-) delete mode 100644 count.c diff --git a/Makefile.in b/Makefile.in index 5f5a6d4b..6b6c8cfa 100644 --- a/Makefile.in +++ b/Makefile.in @@ -188,7 +188,7 @@ DOC_SRC_DIR_FILES := $(HDR_FILES_SRC) $(HELP_SRC) MAIN_DIR_FILES_UNSORTED := Doxyfile Doxyfile.user Doxyfile.help.in \ Makefile.in configure configure.ac config.h.in install-sh \ - set_color.c count.c key_reader.c $(MIME_OBJS:.o=.h) \ + set_color.c key_reader.c $(MIME_OBJS:.o=.h) \ $(MIME_OBJS:.o=.c) $(FISH_OBJS:.o=.h) $(BUILTIN_FILES) \ $(COMMON_FILES) $(COMMON_FILES:.c=.h) $(FISH_OBJS:.o=.c) \ fish.spec.in INSTALL README user_doc.head.html xsel-0.9.6.tar \ @@ -244,7 +244,7 @@ FUNCTIONS_DIR_FILES := $(wildcard share/functions/*.fish) # Programs to install # -SIMPLE_PROGRAMS := fish set_color mimedb count fish_pager fishd fish_indent +SIMPLE_PROGRAMS := fish set_color mimedb fish_pager fishd fish_indent PROGRAMS := $(SIMPLE_PROGRAMS) @XSEL@ @SEQ_FALLBACK@ @@ -722,16 +722,6 @@ mimedb: $(MIME_OBJS) $(CC) $(MIME_OBJS) $(LDFLAGS_MIMEDB) -o $@ -# -# Build the count program. -# -# count does not need any libraries, so we don't use LDFLAGS here. -# - -count: count.o - $(CC) count.o -o $@ - - # # Build the set_color program # @@ -918,7 +908,6 @@ complete.o: config.h signal.h fallback.h util.h tokenizer.h wildcard.h proc.h complete.o: io.h parser.h event.h function.h complete.h builtin.h env.h complete.o: exec.h expand.h common.h reader.h history.h intern.h parse_util.h complete.o: halloc.h halloc_util.h wutil.h path.h -count.o: config.h env.o: config.h signal.h fallback.h util.h wutil.h proc.h io.h common.h env.h env.o: sanity.h expand.h history.h reader.h parser.h event.h env_universal.h env.o: env_universal_common.h input_common.h complete.h diff --git a/count.c b/count.c deleted file mode 100644 index 66525ef8..00000000 --- a/count.c +++ /dev/null @@ -1,24 +0,0 @@ -/** \file count.c - The length command, used for determining the number of items in an - environment variable array. -*/ -#include "config.h" - -#include -#include - -/** - The main function. Does nothing but return the number of arguments. - - This command, unlike all other fish commands, does not feature a -h - or --help option. This is because we want to avoid errors on arrays - that have -h or --help as entries, which is very common when - parsing options, etc. For this reason, the main fish binary does a - check and prints help usage if -h or --help is explicitly given to - the command, but not if it is the contents of a variable. -*/ -int main( int argc, char **argv ) -{ - printf( "%d\n", argc-1 ); - return argc==1; -} diff --git a/doc_src/count.txt b/doc_src/count.txt index 5b6e4606..ca4b5d04 100644 --- a/doc_src/count.txt +++ b/doc_src/count.txt @@ -5,10 +5,10 @@ \subsection count-description Description -count prints the number of arguments that were passed to -it. This is usually used to find out how many elements an environment -variable array contains, but this is not the only potential usage for -the count command. +The count function prints the number of arguments that were +passed to it. This is usually used to find out how many elements an +environment variable array contains, but this is not the only +potential usage for the count command. The count command does not accept any options, not even '-h'. This way the user does not have to worry about an array containing elements diff --git a/fish.spec.in b/fish.spec.in index ee47dfcd..958db62d 100644 --- a/fish.spec.in +++ b/fish.spec.in @@ -115,7 +115,6 @@ fi %doc %_datadir/doc/%{name}-%{version} # man files -%_mandir/man1/count.1* %_mandir/man1/fish.1* %_mandir/man1/fish_pager.1* %_mandir/man1/fish_indent.1* @@ -125,7 +124,6 @@ fi %_mandir/man1/xsel.1x* # The program binaries -%attr(0755,root,root) %_bindir/count %attr(0755,root,root) %_bindir/fish %attr(0755,root,root) %_bindir/fish_indent %attr(0755,root,root) %_bindir/fish_pager diff --git a/parser.c b/parser.c index c115aafb..83e88533 100644 --- a/parser.c +++ b/parser.c @@ -1309,16 +1309,8 @@ static void parse_job_argument_list( process_t *p, workaround and a huge hack, but as near as I can tell, the alternatives are worse. */ - if( p->actual_cmd ) - { - wchar_t *woot = wcsrchr( p->actual_cmd, L'/' ); - if( !woot ) - woot = p->actual_cmd; - else - woot++; - proc_is_count = wcscmp( woot, L"count" )==0; - } - + proc_is_count = (wcscmp( (wchar_t *)al_get( args, 0 ), L"count" )==0); + while( 1 ) { -- cgit v1.2.3