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
This commit is contained in:
axel 2007-04-24 08:00:26 +10:00
parent e2714b05eb
commit 419b3166c8
5 changed files with 8 additions and 53 deletions

View file

@ -188,7 +188,7 @@ DOC_SRC_DIR_FILES := $(HDR_FILES_SRC) $(HELP_SRC)
MAIN_DIR_FILES_UNSORTED := Doxyfile Doxyfile.user Doxyfile.help.in \ MAIN_DIR_FILES_UNSORTED := Doxyfile Doxyfile.user Doxyfile.help.in \
Makefile.in configure configure.ac config.h.in install-sh \ 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) \ $(MIME_OBJS:.o=.c) $(FISH_OBJS:.o=.h) $(BUILTIN_FILES) \
$(COMMON_FILES) $(COMMON_FILES:.c=.h) $(FISH_OBJS:.o=.c) \ $(COMMON_FILES) $(COMMON_FILES:.c=.h) $(FISH_OBJS:.o=.c) \
fish.spec.in INSTALL README user_doc.head.html xsel-0.9.6.tar \ 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 # 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@ PROGRAMS := $(SIMPLE_PROGRAMS) @XSEL@ @SEQ_FALLBACK@
@ -722,16 +722,6 @@ mimedb: $(MIME_OBJS)
$(CC) $(MIME_OBJS) $(LDFLAGS_MIMEDB) -o $@ $(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 # 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: 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: 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 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: 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: sanity.h expand.h history.h reader.h parser.h event.h env_universal.h
env.o: env_universal_common.h input_common.h complete.h env.o: env_universal_common.h input_common.h complete.h

24
count.c
View file

@ -1,24 +0,0 @@
/** \file count.c
The length command, used for determining the number of items in an
environment variable array.
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
/**
The main function. Does nothing but return the number of arguments.
This command, unlike all other fish commands, does not feature a -h
or --help option. This is because we want to avoid errors on arrays
that have -h or --help as entries, which is very common when
parsing options, etc. For this reason, the main fish binary does a
check and prints help usage if -h or --help is explicitly given to
the command, but not if it is the contents of a variable.
*/
int main( int argc, char **argv )
{
printf( "%d\n", argc-1 );
return argc==1;
}

View file

@ -5,10 +5,10 @@
\subsection count-description Description \subsection count-description Description
<tt>count</tt> prints the number of arguments that were passed to The <tt>count</tt> function prints the number of arguments that were
it. This is usually used to find out how many elements an environment passed to it. This is usually used to find out how many elements an
variable array contains, but this is not the only potential usage for environment variable array contains, but this is not the only
the count command. potential usage for the count command.
The count command does not accept any options, not even '-h'. This way 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 the user does not have to worry about an array containing elements

View file

@ -115,7 +115,6 @@ fi
%doc %_datadir/doc/%{name}-%{version} %doc %_datadir/doc/%{name}-%{version}
# man files # man files
%_mandir/man1/count.1*
%_mandir/man1/fish.1* %_mandir/man1/fish.1*
%_mandir/man1/fish_pager.1* %_mandir/man1/fish_pager.1*
%_mandir/man1/fish_indent.1* %_mandir/man1/fish_indent.1*
@ -125,7 +124,6 @@ fi
%_mandir/man1/xsel.1x* %_mandir/man1/xsel.1x*
# The program binaries # The program binaries
%attr(0755,root,root) %_bindir/count
%attr(0755,root,root) %_bindir/fish %attr(0755,root,root) %_bindir/fish
%attr(0755,root,root) %_bindir/fish_indent %attr(0755,root,root) %_bindir/fish_indent
%attr(0755,root,root) %_bindir/fish_pager %attr(0755,root,root) %_bindir/fish_pager

View file

@ -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 workaround and a huge hack, but as near as I can tell, the
alternatives are worse. alternatives are worse.
*/ */
if( p->actual_cmd ) proc_is_count = (wcscmp( (wchar_t *)al_get( args, 0 ), L"count" )==0);
{
wchar_t *woot = wcsrchr( p->actual_cmd, L'/' );
if( !woot )
woot = p->actual_cmd;
else
woot++;
proc_is_count = wcscmp( woot, L"count" )==0;
}
while( 1 ) while( 1 )
{ {