From 1b71f91a014996d60886885c6fee091e8013d988 Mon Sep 17 00:00:00 2001 From: axel Date: Sat, 18 Nov 2006 02:24:38 +1000 Subject: Update documentation display code to run roff on the client system instead of pregenerating documentation and compiling it into program binaries darcs-hash:20061117162438-ac50b-5c4c7f0bd8bf53a16e16ecfead9569e642b7160f.gz --- Makefile.in | 101 ++++++++++------------------ builtin.c | 116 +++++++++++++++++++++++++++------ builtin.h | 6 +- builtin_help.hdr | 45 ------------- doc_src/alias.txt | 15 +++++ doc_src/math.txt | 15 +++++ exec.c | 23 +++++-- fish.spec.in | 4 ++ fishd.c | 8 +-- gen_hdr.sh | 12 ---- gen_hdr2.c | 76 --------------------- mimedb.c | 9 +-- parse_util.c | 1 - parser.c | 16 ++--- print_help.c | 22 +++++++ print_help.h | 15 +++++ set_color.c | 7 +- share/config.fish.in | 4 +- share/functions/__fish_print_help.fish | 7 ++ share/functions/alias.fish | 9 +++ share/functions/contains.fish | 6 +- share/functions/dirh.fish | 9 +++ share/functions/help.fish | 3 +- share/functions/isatty.fish | 3 +- share/functions/math.fish | 6 ++ share/functions/nextd.fish | 9 +++ share/functions/open.fish | 8 +++ share/functions/popd.fish | 8 +++ share/functions/prevd.fish | 9 +++ share/functions/psub.fish | 3 +- share/functions/pushd.fish | 8 +++ share/functions/save_function.fish | 8 +++ share/functions/trap.fish | 2 +- share/functions/type.fish | 2 +- share/functions/umask.fish | 2 +- share/functions/vared.fish | 4 +- 36 files changed, 332 insertions(+), 269 deletions(-) delete mode 100644 builtin_help.hdr create mode 100644 doc_src/alias.txt create mode 100644 doc_src/math.txt delete mode 100755 gen_hdr.sh delete mode 100644 gen_hdr2.c create mode 100644 print_help.c create mode 100644 print_help.h create mode 100644 share/functions/__fish_print_help.fish diff --git a/Makefile.in b/Makefile.in index 7b28e965..3cb41235 100644 --- a/Makefile.in +++ b/Makefile.in @@ -96,7 +96,7 @@ FISH_OBJS := function.o builtin.o complete.o env.o exec.o expand.o \ # Additional files used by builtin.o # -BUILTIN_FILES := builtin_help.c builtin_set.c builtin_commandline.c \ +BUILTIN_FILES := builtin_set.c builtin_commandline.c \ builtin_ulimit.c builtin_complete.c builtin_jobs.c @@ -119,16 +119,17 @@ FISH_TESTS_OBJS := $(FISH_OBJS) fish_tests.o # All objects that the system needs to build fishd # -FISHD_OBJS := fishd.o env_universal_common.o wutil.o \ - doc_src/fishd.o common.o +FISHD_OBJS := fishd.o env_universal_common.o wutil.o print_help.o \ + common.o # # All objects needed to build mimedb # -MIME_OBJS := mimedb.o xdgmimealias.o xdgmime.o xdgmimeglob.o \ - xdgmimeint.o xdgmimemagic.o xdgmimeparent.o wutil.o common.o +MIME_OBJS := mimedb.o print_help.o xdgmimealias.o xdgmime.o \ + xdgmimeglob.o xdgmimeint.o xdgmimemagic.o xdgmimeparent.o wutil.o \ + common.o # @@ -205,10 +206,10 @@ DOC_SRC_DIR_FILES := doc_src/Doxyfile.in doc_src/index.hdr \ MAIN_DIR_FILES := Doxyfile Doxyfile.user Makefile.in configure \ configure.ac config.h.in install-sh set_color.c count.c \ - key_reader.c gen_hdr.sh gen_hdr2.c $(MIME_OBJS:.o=.h) \ + 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) \ - builtin_help.hdr fish.spec.in INSTALL README user_doc.head.html \ + fish.spec.in INSTALL README user_doc.head.html \ xsel-0.9.6.tar ChangeLog config.sub config.guess fish_tests.c \ main.c fish_pager.c fishd.c seq.in @@ -312,6 +313,7 @@ debug: # User documentation, describing the features of the fish shell. # + user_doc: doc_src/index.hdr doc_src/design.hdr doc_src/license.hdr doc_src/faq.hdr Doxyfile.user user_doc.head.html $(CMD_DOC_SRC) $(BUILTIN_DOC_SRC) $(MAKE) doc.h # Depend on the sources (*.hdr) and manually make the intermediate as needed doxygen Doxyfile.user @@ -322,7 +324,7 @@ user_doc: doc_src/index.hdr doc_src/design.hdr doc_src/license.hdr doc_src/faq.h # Source code documentation. Also includes user documentation. # -doc: *.h *.c doc.h Doxyfile builtin_help.c +doc: *.h *.c doc.h Doxyfile doxygen; @@ -467,8 +469,7 @@ common.o: $(COMMON_FILES) # # Generate the internal help functions by making doxygen create -# man-pages which are then converted into C code. The convertion path -# looks like this: +# man-pages. The convertion path looks like this: # # .txt file # || @@ -480,26 +481,20 @@ common.o: $(COMMON_FILES) # (doxygen) # || # \/ -# man file +# roff file # || -# (man) +# (__fish_print_help) # || # \/ # formated text # with escape # sequences -# || -# \/ -# (gen_hdr2) -# || -# \/ -# .c file # -# Which is an awful, clunky and ugly way of producing -# documentation. There ought to be something simpler. +# +# There ought to be something simpler. # -doc_src/builtin_doc: $(BUILTIN_DOC_SRC) doc_src/count.txt builtin_help.hdr $(CMD_DOC_SRC) +doc_src/builtin_doc: $(BUILTIN_DOC_SRC) doc_src/count.txt $(CMD_DOC_SRC) for i in $(BUILTIN_DOC_SRC) $(CMD_DOC_SRC); do \ FILE=doc_src/`basename $$i .txt`.doxygen; \ echo "/** \page" `basename $$i .txt` >$$FILE; \ @@ -514,37 +509,6 @@ doc_src/builtin_doc: $(BUILTIN_DOC_SRC) doc_src/count.txt builtin_help.hdr $(CMD done touch doc_src/builtin_doc -builtin_help.c: doc_src/builtin_doc gen_hdr.sh - $(MAKE) gen_hdr2 # Don't depend on gen_hdr2, because then we would need to rebuild the docs whenever we use a fresh tarball - cp builtin_help.hdr builtin_help.c; - if test -x gen_hdr.sh; then true; else chmod 755 gen_hdr.sh; fi - for i in $(BUILTIN_DOC_HDR) doc_src/count.doxygen ; do \ - echo ' hash_put( &tbl, L"'`basename $$i .doxygen`'",' >>$@; \ - ./gen_hdr.sh $$i >>$@; \ - printf " );\n\n" >>$@; \ - done; - echo "}" >>builtin_help.c - - -# -# Generate help texts for external fish commands, like set_color and -# mimedb. -# - -%.c : %.doxygen - $(MAKE) gen_hdr2 builtin_help.c # These should really be filed as dependencis for %.c above instead, but that seems to confuse make - echo "// This file was automatically generated, do not edit" >$@ - echo "#include " >>$@ - echo "#include " >>$@ - echo >>$@ - echo "void print_help()" >>$@ - echo "{" >>$@ - echo ' printf( "%s",' >>$@ - chmod 755 gen_hdr.sh - ./gen_hdr.sh $*.doxygen >>$@ - echo ");" >>$@ - echo "}" >>$@ - # # The build rules for installing/uninstalling fish # @@ -614,6 +578,7 @@ install-force: all install-translations $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/completions $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/functions + $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/man $(INSTALL) -m 644 etc/config.fish $(DESTDIR)$(sysconfdir)/fish/ $(INSTALL) -m 644 share/config.fish $(DESTDIR)$(datadir)/fish/ $(INSTALL) -m 644 share/config_interactive.fish $(DESTDIR)$(datadir)/fish/ @@ -623,6 +588,9 @@ install-force: all install-translations for i in $(FUNCTIONS_DIR_FILES); do \ $(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/functions/; \ done; + for i in share/man/*.1; do \ + $(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/man/; \ + done; $(INSTALL) -m 644 etc/fish_inputrc $(DESTDIR)$(sysconfdir)/fish/fish_inputrc; $(INSTALL) -m 755 -d $(DESTDIR)$(docdir) for i in user_doc/html/* ChangeLog; do \ @@ -755,8 +723,8 @@ fish_tests: $(FISH_TESTS_OBJS) # mimedb does not need any libraries, so we don't use LDFLAGS here. # -mimedb: $(MIME_OBJS) doc_src/mimedb.o - $(CC) $(MIME_OBJS) doc_src/mimedb.o $(LDFLAGS) -o $@ +mimedb: $(MIME_OBJS) + $(CC) $(MIME_OBJS) $(LDFLAGS) -o $@ # @@ -773,8 +741,8 @@ count: count.o # Build the set_color program # -set_color: set_color.o doc_src/set_color.o common.o - $(CC) set_color.o doc_src/set_color.o common.o wutil.o $(LDFLAGS) -o $@ +set_color: set_color.o print_help.o common.o + $(CC) set_color.o print_help.o common.o wutil.o $(LDFLAGS) -o $@ # @@ -801,7 +769,6 @@ depend: ./config.status .PHONY: depend - # # Copy all the source files into a new directory and use tar to create # an archive from it. Simplest way I could think of to make an archive @@ -820,6 +787,7 @@ fish-@PACKAGE_VERSION@.tar: $(DOC_SRC_DIR_FILES) $(MAIN_DIR_FILES) $(ETC_DIR_FIL $(INSTALL) -d fish-@PACKAGE_VERSION@/share $(INSTALL) -d fish-@PACKAGE_VERSION@/share/completions $(INSTALL) -d fish-@PACKAGE_VERSION@/share/functions + $(INSTALL) -d fish-@PACKAGE_VERSION@/share/man $(INSTALL) -d fish-@PACKAGE_VERSION@/tests $(INSTALL) -d fish-@PACKAGE_VERSION@/po cp -f $(DOC_SRC_DIR_FILES) fish-@PACKAGE_VERSION@/doc_src @@ -830,6 +798,7 @@ fish-@PACKAGE_VERSION@.tar: $(DOC_SRC_DIR_FILES) $(MAIN_DIR_FILES) $(ETC_DIR_FIL cp -f $(FUNCTIONS_DIR_FILES) fish-@PACKAGE_VERSION@/share/functions/ cp -f $(TESTS_DIR_FILES) fish-@PACKAGE_VERSION@/tests/ cp -f $(TRANSLATIONS_SRC) fish-@PACKAGE_VERSION@/po/ + cp -f doc_src/builtin_doc/man/man1/*.1 fish-@PACKAGE_VERSION@/share/man/ cp -rf user_doc fish-@PACKAGE_VERSION@/ cp -rf doc_src/builtin_doc fish-@PACKAGE_VERSION@/doc_src/ tar -c fish-@PACKAGE_VERSION@ >fish-@PACKAGE_VERSION@.tar @@ -908,7 +877,7 @@ distclean: clean clean: rm -f *.o doc.h doc.tmp doc_src/*.doxygen doc_src/*.c doc_src/*.o doc_src/commands.hdr rm -f tests/tmp.err tests/tmp.out tests/tmp.status tests/foo.txt - rm -f tokenizer_test fish key_reader set_color gen_hdr2 mimedb + rm -f tokenizer_test fish key_reader set_color mimedb rm -f fishd fish_pager count fish_tests rm -f fish-@PACKAGE_VERSION@.tar rm -f fish-@PACKAGE_VERSION@.tar.gz @@ -926,8 +895,8 @@ builtin.o: config.h fallback.h util.h wutil.h builtin.h function.h complete.h builtin.o: proc.h io.h parser.h event.h reader.h env.h common.h wgetopt.h builtin.o: sanity.h tokenizer.h wildcard.h input_common.h input.h intern.h builtin.o: signal.h halloc.h halloc_util.h parse_util.h expand.h path.h -builtin.o: builtin_help.c builtin_set.c builtin_commandline.c -builtin.o: builtin_complete.c builtin_ulimit.c builtin_jobs.c +builtin.o: builtin_set.c builtin_commandline.c builtin_complete.c +builtin.o: builtin_ulimit.c builtin_jobs.c builtin_commandline.o: config.h signal.h fallback.h util.h wutil.h builtin.h builtin_commandline.o: common.h wgetopt.h reader.h proc.h io.h parser.h builtin_commandline.o: event.h tokenizer.h input_common.h input.h @@ -935,7 +904,6 @@ builtin_commandline.o: parse_util.h builtin_complete.o: config.h signal.h fallback.h util.h wutil.h builtin.h builtin_complete.o: common.h complete.h wgetopt.h parser.h proc.h io.h builtin_complete.o: event.h reader.h -builtin_help.o: config.h util.h common.h halloc_util.h builtin_jobs.o: config.h fallback.h util.h wutil.h builtin.h proc.h io.h builtin_jobs.o: parser.h event.h common.h wgetopt.h builtin_set.o: config.h signal.h fallback.h util.h wutil.h builtin.h env.h @@ -960,8 +928,7 @@ event.o: config.h signal.h fallback.h util.h wutil.h function.h proc.h io.h event.o: parser.h event.h common.h halloc_util.h exec.o: config.h signal.h fallback.h util.h common.h wutil.h proc.h io.h exec.o: exec.h parser.h event.h builtin.h function.h env.h wildcard.h -exec.o: sanity.h expand.h env_universal.h env_universal_common.h halloc.h -exec.o: halloc_util.h parse_util.h +exec.o: sanity.h expand.h halloc.h halloc_util.h parse_util.h expand.o: config.h signal.h fallback.h util.h common.h wutil.h env.h proc.h expand.o: io.h parser.h event.h expand.h wildcard.h exec.h tokenizer.h expand.o: complete.h parse_util.h halloc.h halloc_util.h @@ -976,7 +943,7 @@ fish_tests.o: reader.h builtin.h function.h complete.h wutil.h env.h expand.h fish_tests.o: parser.h event.h tokenizer.h output.h exec.h halloc_util.h function.o: config.h signal.h wutil.h fallback.h util.h function.h proc.h function.o: io.h parser.h event.h common.h intern.h reader.h parse_util.h -function.o: env.h expand.h +function.o: env.h expand.h halloc.h halloc_util.h halloc.o: config.h fallback.h util.h common.h halloc.h halloc_util.o: config.h fallback.h util.h common.h halloc.h highlight.o: config.h signal.h fallback.h util.h wutil.h highlight.h @@ -1011,7 +978,7 @@ parser.o: env_universal_common.h intern.h parse_util.h halloc.h halloc_util.h parser.o: path.h parse_util.o: config.h fallback.h util.h wutil.h common.h tokenizer.h parse_util.o: parse_util.h expand.h intern.h exec.h proc.h io.h env.h -parse_util.o: wildcard.h halloc_util.h +parse_util.o: signal.h wildcard.h halloc_util.h path.o: config.h fallback.h util.h common.h env.h wutil.h halloc.h path.o: halloc_util.h path.h expand.h proc.o: config.h signal.h fallback.h util.h wutil.h proc.h io.h common.h @@ -1024,8 +991,8 @@ reader.o: function.h output.h screen.h parse_util.h sanity.o: config.h signal.h fallback.h util.h common.h sanity.h proc.h io.h sanity.o: history.h reader.h kill.h wutil.h screen.o: config.h fallback.h common.h util.h wutil.h output.h highlight.h -screen.o: screen.h -set_color.o: config.h fallback.h +screen.o: screen.h env.h +set_color.o: config.h fallback.h print_help.h signal.o: config.h signal.h common.h util.h fallback.h wutil.h event.h signal.o: reader.h proc.h io.h test.o: stringtab.h diff --git a/builtin.c b/builtin.c index 6d0bf6c1..435d58c3 100644 --- a/builtin.c +++ b/builtin.c @@ -60,6 +60,7 @@ #include "intern.h" #include "event.h" #include "signal.h" +#include "exec.h" #include "halloc.h" #include "halloc_util.h" @@ -193,10 +194,53 @@ static int count_char( const wchar_t *str, wchar_t c ) */ +wchar_t *builtin_help_get( const wchar_t *name ) +{ + array_list_t lst; + string_buffer_t cmd; + wchar_t *name_esc; + + static string_buffer_t *out = 0; + int i; + + al_init( &lst ); + sb_init( &cmd ); + + if( !out ) + { + out = sb_halloc( global_context ); + } + else + { + sb_clear( out ); + } + + name_esc = escape( name, 1 ); + sb_printf( &cmd, L"__fish_print_help %ls", name_esc ); + + + exec_subshell( (wchar_t *)cmd.buff, &lst ); + + for( i=0; ibuff; + +} + static void builtin_print_help( wchar_t *cmd, string_buffer_t *b ) { - const char *h; + + const wchar_t *h; if( b == sb_err ) { @@ -209,14 +253,17 @@ static void builtin_print_help( wchar_t *cmd, string_buffer_t *b ) if( !h ) return; - wchar_t *str = str2wcs( h ); + wchar_t *str = wcsdup( h ); if( str ) { if( is_interactive && !builtin_out_redirect && b==sb_err) { - /* Interactive mode help to screen - only print synopsis if the rest won't fit */ + /* + Interactive mode help to screen - only print synopsis if + the rest won't fit + */ int screen_height, lines; @@ -226,39 +273,67 @@ static void builtin_print_help( wchar_t *cmd, string_buffer_t *b ) { wchar_t *pos; int cut=0; + int i; + + /* + First move down 4 lines + */ - /* Find first empty line */ - for( pos=str; *pos; pos++ ) + pos = str; + for( i=0; i<4; i++ ) + { + pos = wcschr( pos+1, L'\n' ); + if( !pos ) + break; + } + + if( pos ) { - if( *pos == L'\n' ) - { - wchar_t *pos2; - int is_empty = 1; - for( pos2 = pos+1; *pos2; pos2++ ) + /* + Then find the next empty line + */ + for( ; *pos; pos++ ) + { + if( *pos == L'\n' ) { - if( *pos2 == L'\n' ) - break; + wchar_t *pos2; + int is_empty = 1; - if( *pos2 != L'\t' && *pos2 !=L' ' ) + for( pos2 = pos+1; *pos2; pos2++ ) + { + if( *pos2 == L'\n' ) + break; + + if( *pos2 != L'\t' && *pos2 !=L' ' ) + { + is_empty = 0; + break; + } + } + if( is_empty ) { - is_empty = 0; + /* + And cut it + */ + *(pos2+1)=L'\0'; + cut = 1; break; } } - if( is_empty ) - { - *(pos+1)=L'\0'; - cut = 1; - break; - } } } + /* + We did not find a good place to cut message to + shorten it - so we make sure we don't print + anything. + */ if( !cut ) { *str = 0; } + } } @@ -287,7 +362,6 @@ static void builtin_print_help( wchar_t *cmd, string_buffer_t *b ) */ -#include "builtin_help.c" #include "builtin_set.c" #include "builtin_commandline.c" #include "builtin_complete.c" diff --git a/builtin.h b/builtin.h index 2f98c741..9629c7ad 100644 --- a/builtin.h +++ b/builtin.h @@ -164,12 +164,10 @@ const wchar_t *builtin_complete_get_temporary_buffer(); /** - Return the help text for the specified builtin command. Use - non-wide characters since wide characters have some issues with - string formating escape sequences sometimes. + Return the help text for the specified builtin command. \param cmd The command for which to obtain help text */ -char *builtin_help_get( const wchar_t *cmd ); +wchar_t *builtin_help_get( const wchar_t *cmd ); #endif diff --git a/builtin_help.hdr b/builtin_help.hdr deleted file mode 100644 index f209680f..00000000 --- a/builtin_help.hdr +++ /dev/null @@ -1,45 +0,0 @@ -/** \file builtin_help.c - - Functions for printing usage information of builtin commands. This - file is automatically generated from the file builtin_help.hdr and - various help files in the doc_src directory. -*/ - -#include "config.h" - -#include -#include -#include -#include -#include - -#include "util.h" -#include "common.h" -#include "halloc_util.h" - -/** - Hashtable storing the help text -*/ -static hash_table_t tbl; - -static void builtin_help_init(); - -char *builtin_help_get( const wchar_t *cmd ) -{ - builtin_help_init(); - - return (char *)hash_get( &tbl, (void *)cmd ); -} - -/** - Initialize help hash table. Don't invoke it manually, - it is called by builtin_help_get automatically. -*/ -static void builtin_help_init() -{ - static int is_help_init = 0; - if( is_help_init ) - return; - is_help_init=1; - halloc_register_function( global_context, (void (*)(void *))&hash_destroy, &tbl ); - hash_init( &tbl, &hash_wcs_func, &hash_wcs_cmp ); diff --git a/doc_src/alias.txt b/doc_src/alias.txt new file mode 100644 index 00000000..ca34ab4b --- /dev/null +++ b/doc_src/alias.txt @@ -0,0 +1,15 @@ +\section alias alias - create a function + +\subsection alias-synopsis Synopsis +alias NAME DEFINITION
+alias NAME=DEFINITION + +\subsection alias-description Description + +Alias is a shellscript wrapper around the function builtin. +It exists for backwards compatibility with Posix +shells. For other uses, it is recommended to define a function. + +- 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. diff --git a/doc_src/math.txt b/doc_src/math.txt new file mode 100644 index 00000000..a29a3a83 --- /dev/null +++ b/doc_src/math.txt @@ -0,0 +1,15 @@ + +\section math math - Perform mathematics calculations + +\subsection math-synopsis Synopsis + math EXPRESSION + +\subsection math-description Description + +math is used to perform mathematical calcualtions. It is only a very +thin wrapper for the bc program, that makes it possible to specify an +expression from the commandline without using non-standard extensions +or a pipeline. Simply use a command like math 1+1. + +For a description of the syntax supported by math, see the manual for +the bc program. diff --git a/exec.c b/exec.c index c95ff81b..6a5b497d 100644 --- a/exec.c +++ b/exec.c @@ -800,11 +800,7 @@ void exec( job_t *j ) pipe_write.io_mode=IO_PIPE; pipe_read.next=0; pipe_write.next=0; - pipe_write.param1.pipe_fd[0]=pipe_write.param1.pipe_fd[1]=-1; - - - - //fwprintf( stderr, L"Run command %ls\n", j->command ); + pipe_write.param1.pipe_fd[0]=pipe_write.param1.pipe_fd[1]=-1; j->io = io_add( j->io, &pipe_write ); @@ -918,6 +914,12 @@ void exec( job_t *j ) const wchar_t * orig_def; wchar_t * def=0; + /* + Calls to function_get_definition might need to + source a file as a part of autoloading, hence there + must be no blocks. + */ + signal_unblock(); orig_def = function_get_definition( p->argv[0] ); signal_block(); @@ -1042,8 +1044,9 @@ void exec( job_t *j ) } else { - builtin_push_io( builtin_stdin ); - + int old_out = builtin_out_redirect; + int old_err = builtin_err_redirect; + /* Since this may be the foreground job, and since a builtin may execute another foreground job, @@ -1059,8 +1062,11 @@ void exec( job_t *j ) to make exec handle things. */ + builtin_push_io( builtin_stdin ); + builtin_out_redirect = has_fd( j->io, 1 ); builtin_err_redirect = has_fd( j->io, 2 ); + fg = job_get_flag( j, JOB_FOREGROUND ); job_set_flag( j, JOB_FOREGROUND, 0 ); @@ -1068,6 +1074,9 @@ void exec( job_t *j ) p->status = builtin_run( p->argv ); + builtin_out_redirect=old_out; + builtin_err_redirect=old_err; + signal_block(); /* diff --git a/fish.spec.in b/fish.spec.in index f2b26b7f..50d33d26 100644 --- a/fish.spec.in +++ b/fish.spec.in @@ -150,6 +150,10 @@ fi %dir %_datadir/fish/functions %_datadir/fish/functions/*.fish +# Documentation for builtins and shellscript functions +%dir %_datadir/fish/man +%_datadir/fish/man/*.1 + diff --git a/fishd.c b/fishd.c index 998b6550..0437c09e 100644 --- a/fishd.c +++ b/fishd.c @@ -73,6 +73,7 @@ time the original barrier request was sent have been received. #include "halloc.h" #include "halloc_util.h" #include "path.h" +#include "print_help.h" /** Maximum length of socket filename @@ -140,11 +141,6 @@ static int sock; */ static int quit=0; -/** - Dynamically generated function, made from the documentation in doc_src. -*/ -void print_help(); - /** Constructs the fish socket filename */ @@ -620,7 +616,7 @@ int main( int argc, char ** argv ) break; case 'h': - print_help(); + print_help( argv[0], 1 ); exit(0); case 'v': diff --git a/gen_hdr.sh b/gen_hdr.sh deleted file mode 100755 index 5e09f40e..00000000 --- a/gen_hdr.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -# This little script calls the man command to render a manual page and -# pipes the result into the gen_hdr2 program to convert the output -# into a C string literal. - -# NAME is the name of the function we are generating documentation for. -NAME=`basename $1 .doxygen` - -# Render the page -nroff -man doc_src/builtin_doc/man/man1/${NAME}.1 | col -b | cat -s | sed -e '$d' | ./gen_hdr2 - diff --git a/gen_hdr2.c b/gen_hdr2.c deleted file mode 100644 index 1a13fbb7..00000000 --- a/gen_hdr2.c +++ /dev/null @@ -1,76 +0,0 @@ -/** \file gen_hdr2.c - A program that reads data from stdin and outputs it as a C string. - - It is used as a part of the build process to generate help texts - for the built in commands. -*/ -#include -#include -#include -/** - The main function, does all the work -*/ -int main() -{ - int line = 0; - printf( "\t\t\"" ); - int c; - int count=0; - while( (c=getchar()) != EOF ) - { - if( c == '\n' ) - line++; - - if( line > 4 ) - break; - } - - while( (c=getchar()) != EOF ) - { - if( (c >= 'a' && c <= 'z' ) || - (c >= 'A' && c <= 'Z' ) || - (c >= '0' && c <= '9' ) || - ( strchr(" ,.!;:-_#$%&(){}[]<>=?+-*/'",c) != 0) ) - { - count++; - putchar(c); - } - else - { - switch(c) - { - case '\n': - printf( "\\n" ); - printf( "\"\n\t\t\"" ); - count =0; - break; - case '\t': - printf( "\\t" ); - count +=2; - break; - case '\r': - printf( "\\r" ); - count +=2; - break; - - case '\"': - case '\\': - printf( "\\%c",c ); - count +=2; - break; - - default: - count +=7; - printf( "\\x%02x\" \"", c ); - break; - } - } - if( count > 60 ) - { - count=0; - printf( "\"\n\t\t\"" ); - } - } - printf( "\"" ); - return 0; -} diff --git a/mimedb.c b/mimedb.c index ac1b8ec6..8e0078f9 100644 --- a/mimedb.c +++ b/mimedb.c @@ -46,6 +46,7 @@ license. Read the source code of the library for more information. #include "xdgmime.h" #include "fallback.h" #include "util.h" +#include "print_help.h" /** @@ -140,10 +141,6 @@ static int launch_pos=0; */ #define _(string) gettext(string) -/** - Dynamically generated function, made from the documentation in doc_src. -*/ -void print_help(); /** Call malloc, set error flag and print message on failure @@ -1258,7 +1255,7 @@ int main (int argc, char *argv[]) break; case 'h': - print_help(); + print_help( argv[0], 1 ); exit(0); case 'v': @@ -1274,7 +1271,7 @@ int main (int argc, char *argv[]) if( ( output_type == LAUNCH )&&(input_type==MIMETYPE)) { fprintf( stderr, _("%s: Can not launch a mimetype\n"), MIMEDB ); - print_help(); + print_help( argv[0], 2 ); exit(1); } diff --git a/parse_util.c b/parse_util.c index 934b3dc8..6ac410e7 100644 --- a/parse_util.c +++ b/parse_util.c @@ -885,7 +885,6 @@ static int parse_util_load_internal( const wchar_t *cmd, if( on_load ) on_load(cmd ); - /* Source the completion file for the specified completion */ diff --git a/parser.c b/parser.c index 4460c2d1..475e8d2d 100644 --- a/parser.c +++ b/parser.c @@ -2564,7 +2564,7 @@ int eval( const wchar_t *cmd, io_data_t *io, int block_type ) if( (!error_code) && (!exit_status()) && (!proc_get_last_status()) ) { - char *h; + wchar_t *h; //debug( 2, L"Status %d\n", proc_get_last_status() ); @@ -2576,7 +2576,7 @@ int eval( const wchar_t *cmd, io_data_t *io, int block_type ) h = builtin_help_get( L"end" ); if( h ) - fwprintf( stderr, L"%s", h ); + fwprintf( stderr, L"%ls", h ); break; } @@ -3090,7 +3090,7 @@ int parser_test( const wchar_t * buff, if( out ) { - char *h; + wchar_t *h; error( SYNTAX_ERROR, tok_get_pos( &tok ), @@ -3099,7 +3099,7 @@ int parser_test( const wchar_t * buff, print_errors( out, prefix); h = builtin_help_get( L"case" ); if( h ) - sb_printf( out, L"%s", h ); + sb_printf( out, L"%ls", h ); } } } @@ -3253,7 +3253,7 @@ int parser_test( const wchar_t * buff, err = 1; if( out ) { - char *h; + wchar_t *h; error( SYNTAX_ERROR, tok_get_pos( &tok ), @@ -3261,7 +3261,7 @@ int parser_test( const wchar_t * buff, print_errors( out, prefix ); h = builtin_help_get( L"end" ); if( h ) - sb_printf( out, L"%s", h ); + sb_printf( out, L"%ls", h ); } } @@ -3532,7 +3532,7 @@ int parser_test( const wchar_t * buff, if( out && count>0 ) { - const char *h; + const wchar_t *h; const wchar_t *cmd; error( SYNTAX_ERROR, @@ -3547,7 +3547,7 @@ int parser_test( const wchar_t * buff, h = builtin_help_get( cmd ); if( cmd ) { - sb_printf( out, L"%s", h ); + sb_printf( out, L"%ls", h ); } } diff --git a/print_help.c b/print_help.c new file mode 100644 index 00000000..72344cde --- /dev/null +++ b/print_help.c @@ -0,0 +1,22 @@ + +/** \file print_help.c + Print help message for the specified command +*/ + +#include +#include + + +#include "print_help.h" + +#define CMD_LEN 1024 + +void print_help( char *c, int fd ) +{ + char cmd[ CMD_LEN]; + int printed = snprintf( cmd, CMD_LEN, "fish -c '__fish_print_help %s >&%d'", c, fd ); + + if( printed < CMD_LEN ) + system( cmd ); + +} diff --git a/print_help.h b/print_help.h new file mode 100644 index 00000000..570b43a6 --- /dev/null +++ b/print_help.h @@ -0,0 +1,15 @@ + +/** \file print_help.h + Print help message for the specified command +*/ + +#ifndef FISH_PRINT_HELP_H +#define FISH_PRINT_HELP_H + +/** + Print help message for the specified command +*/ + +void print_help( char *cmd, int fd ); + +#endif diff --git a/set_color.c b/set_color.c index 54ca87ec..edaa0fdb 100644 --- a/set_color.c +++ b/set_color.c @@ -37,6 +37,7 @@ #endif #include "fallback.h" +#include "print_help.h" /* Small utility for setting the color. @@ -90,8 +91,6 @@ int col_idx[]= } ; -void print_help(); - int translate_color( char *str ) { char *endptr; @@ -206,7 +205,7 @@ int main( int argc, char **argv ) bgcolor = optarg; break; case 'h': - print_help(); + print_help( argv[0], 1 ); exit(0); case 'o': @@ -254,7 +253,7 @@ int main( int argc, char **argv ) { check_locale_init(); fprintf( stderr, _("%s: Expected an argument\n"), SET_COLOR ); - print_help(); + print_help( argv[0], 2 ); return 1; } diff --git a/share/config.fish.in b/share/config.fish.in index bc4d21f2..0857c42e 100644 --- a/share/config.fish.in +++ b/share/config.fish.in @@ -15,7 +15,9 @@ if set -q XDG_CONFIG_HOME set configdir $XDG_CONFIG_HOME end - +if not set -q __fish_datadir + set -U __fish_datadir @datadir@/fish +end if not set -q fish_function_path set -U fish_function_path $configdir/fish/functions @sysconfdir@/fish/functions @datadir@/fish/functions diff --git a/share/functions/__fish_print_help.fish b/share/functions/__fish_print_help.fish new file mode 100644 index 00000000..88a35b4b --- /dev/null +++ b/share/functions/__fish_print_help.fish @@ -0,0 +1,7 @@ + +function __fish_print_help + set -l help (nroff -man $__fish_datadir/man/$argv.1) + set -l lines (count $help) + echo + printf "%s\n" $help| tail -n (expr $lines - 5 ) | head -n (expr $lines - 8) +end \ No newline at end of file diff --git a/share/functions/alias.fish b/share/functions/alias.fish index f0772795..64ee83de 100644 --- a/share/functions/alias.fish +++ b/share/functions/alias.fish @@ -1,5 +1,14 @@ function alias -d (_ "Legacy function for creating shellscript functions using an alias-like syntax") + + if count $argv >/dev/null + switch $argv[1] + case -h --h --he --hel --help + __fish_print_help alias + return 0 + end + end + set -l name set -l body switch (count $argv) diff --git a/share/functions/contains.fish b/share/functions/contains.fish index f1decd80..64f8c45b 100644 --- a/share/functions/contains.fish +++ b/share/functions/contains.fish @@ -3,7 +3,7 @@ function contains -d (N_ "Test if a key is contained in a set of values") while count $argv >/dev/null switch $argv[1] case '-h' '--h' '--he' '--hel' '--help' - help contains + __fish_print_help contains return case '--' @@ -12,8 +12,8 @@ function contains -d (N_ "Test if a key is contained in a set of values") break case '-*' - printf (_ "%s: Unknown option '%s'\n") contains $argv[$i] - help contains + printf (_ "%s: Unknown option '%s'\n") contains $argv[1] + __fish_print_help contains >&2 return 1 case '*' diff --git a/share/functions/dirh.fish b/share/functions/dirh.fish index ca324b8b..b30a44e9 100644 --- a/share/functions/dirh.fish +++ b/share/functions/dirh.fish @@ -1,5 +1,14 @@ function dirh -d (N_ "Print the current directory history (the back- and fwd- lists)") + + if count $argv >/dev/null + switch $argv[1] + case -h --h --he --hel --help + __fish_print_help dirh + return 0 + end + end + # Avoid set comment set -l current (command pwd) set -l separator " " diff --git a/share/functions/help.fish b/share/functions/help.fish index c93270ec..7fc32211 100644 --- a/share/functions/help.fish +++ b/share/functions/help.fish @@ -22,7 +22,8 @@ function help -d (N_ "Show help for the fish shell") if count $argv >/dev/null switch $argv[1] case -h --h --he --hel --help - set argv help + __fish_print_help help + return 0 end end diff --git a/share/functions/isatty.fish b/share/functions/isatty.fish index 3a54c6ab..b4c59e29 100644 --- a/share/functions/isatty.fish +++ b/share/functions/isatty.fish @@ -5,7 +5,8 @@ function isatty -d "Tests if a file descriptor is a tty" switch $argv[1] case -h --h --he --hel --help - help isatty + __fish_print_help isatty + return 0 case stdin set fd 0 diff --git a/share/functions/math.fish b/share/functions/math.fish index d28087fa..cda345a6 100644 --- a/share/functions/math.fish +++ b/share/functions/math.fish @@ -1,6 +1,12 @@ function math -d (N_ "Perform math calculations in bc") if count $argv >/dev/null + switch $argv[1] + case -h --h --he --hel --help + __fish_print_help math + return 0 + end + set -l out (echo $argv|bc) echo $out switch $out diff --git a/share/functions/nextd.fish b/share/functions/nextd.fish index ae5c0720..018fef66 100644 --- a/share/functions/nextd.fish +++ b/share/functions/nextd.fish @@ -1,5 +1,14 @@ function nextd -d (N_ "Move forward in the directory history") + + if count $argv >/dev/null + switch $argv[1] + case -h --h --he --hel --help + __fish_print_help nextd + return 0 + end + end + # Parse arguments set -l show_hist 0 set -l times 1 diff --git a/share/functions/open.fish b/share/functions/open.fish index 140269ee..8c8d9b9d 100644 --- a/share/functions/open.fish +++ b/share/functions/open.fish @@ -6,6 +6,14 @@ if not test (uname) = Darwin function open -d (N_ "Open file in default application") + if count $argv >/dev/null + switch $argv[1] + case -h --h --he --hel --help + __fish_print_help dirh + return 0 + end + end + if type -f xdg-open >/dev/null xdg-open $argv else diff --git a/share/functions/popd.fish b/share/functions/popd.fish index cf2e8ff3..2878659f 100644 --- a/share/functions/popd.fish +++ b/share/functions/popd.fish @@ -1,5 +1,13 @@ function popd -d (N_ "Pop dir from stack") + if count $argv >/dev/null + switch $argv[1] + case -h --h --he --hel --help + __fish_print_help popd + return 0 + end + end + if test $dirstack[1] cd $dirstack[1] else diff --git a/share/functions/prevd.fish b/share/functions/prevd.fish index 9e7d4658..eb2536db 100644 --- a/share/functions/prevd.fish +++ b/share/functions/prevd.fish @@ -1,5 +1,14 @@ function prevd -d (N_ "Move back in the directory history") + + if count $argv >/dev/null + switch $argv[1] + case -h --h --he --hel --help + __fish_print_help prevd + return 0 + end + end + # Parse arguments set -l show_hist 0 set -l times 1 diff --git a/share/functions/psub.fish b/share/functions/psub.fish index 7c73cc2e..22538c8c 100644 --- a/share/functions/psub.fish +++ b/share/functions/psub.fish @@ -8,8 +8,7 @@ function psub -d (N_ "Read from stdin into a file and output the filename. Remov if count $argv >/dev/null switch $argv[1] case '-h*' --h --he --hel --help - - help psub + __fish_print_help psub return 0 case '*' diff --git a/share/functions/pushd.fish b/share/functions/pushd.fish index 2f12c6f3..405fde36 100644 --- a/share/functions/pushd.fish +++ b/share/functions/pushd.fish @@ -1,6 +1,14 @@ function pushd -d (N_ "Push directory to stack") + if count $argv >/dev/null + switch $argv[1] + case -h --h --he --hel --help + __fish_print_help pushd + return 0 + end + end + # Comment to avoid set completions set -g dirstack (command pwd) $dirstack cd $argv[1] diff --git a/share/functions/save_function.fish b/share/functions/save_function.fish index 62f7a9ea..7f04ef91 100644 --- a/share/functions/save_function.fish +++ b/share/functions/save_function.fish @@ -1,6 +1,14 @@ function save_function -d (N_ "Save the current definition of all specified functions to file") + if count $argv >/dev/null + switch $argv[1] + case -h --h --he --hel --help + __fish_print_help save_function + return 0 + end + end + set -l res 0 set -l configdir ~/.config diff --git a/share/functions/trap.fish b/share/functions/trap.fish index 74940dbe..27af0f4e 100644 --- a/share/functions/trap.fish +++ b/share/functions/trap.fish @@ -45,7 +45,7 @@ function trap -d 'Perform an action when the shell recives a signal' while count $opt >/dev/null switch $opt[1] case -h --help - help trap + __fish_print_help trap return 0 case -p --print diff --git a/share/functions/type.fish b/share/functions/type.fish index 4d3dcd8d..ef9e31f7 100644 --- a/share/functions/type.fish +++ b/share/functions/type.fish @@ -43,7 +43,7 @@ function type -d (N_ "Print the type of a command") set selection files case -h --help - help type + __fish_print_help type return 0 case -- diff --git a/share/functions/umask.fish b/share/functions/umask.fish index 0a09fb72..78ab0087 100644 --- a/share/functions/umask.fish +++ b/share/functions/umask.fish @@ -155,7 +155,7 @@ function umask -d (N_ "Set default file permission mask") switch $opt[1] case -h --help - help umask + __fish_print_help umask return 0 case -p --as-command diff --git a/share/functions/vared.fish b/share/functions/vared.fish index e77acd47..979cc594 100644 --- a/share/functions/vared.fish +++ b/share/functions/vared.fish @@ -9,10 +9,12 @@ function vared -d (N_ "Edit variable value") switch $argv case '-h' '--h' '--he' '--hel' '--help' - help vared + __fish_print_help vared + return 0 case '-*' printf (_ "%s: Unknown option %s\n") vared $argv + return 1 case '*' if test (count $$argv ) -lt 2 -- cgit v1.2.3