mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-31 08:04:58 +08:00
Add option parsing and support for -h and -v switches to fishd
darcs-hash:20060123162534-ac50b-e993c28ee80cf83dc1f83a64f2cf7bac5dc1c55d.gz
This commit is contained in:
parent
9853286bf9
commit
89eb80f3a4
|
@ -85,6 +85,7 @@ FISH_TESTS_OBJS := $(COMMON_OBJS) $(COMMON_OBJS_WITH_CODE) \
|
||||||
|
|
||||||
# All objects that the system needs to build fishd
|
# All objects that the system needs to build fishd
|
||||||
FISHD_OBJS := fishd.o env_universal_common.o common.o util.o wutil.o \
|
FISHD_OBJS := fishd.o env_universal_common.o common.o util.o wutil.o \
|
||||||
|
doc_src/fishd.o
|
||||||
|
|
||||||
# All objects needed to build mimedb
|
# All objects needed to build mimedb
|
||||||
MIME_OBJS := mimedb.o xdgmimealias.o xdgmime.o xdgmimeglob.o \
|
MIME_OBJS := mimedb.o xdgmimealias.o xdgmime.o xdgmimeglob.o \
|
||||||
|
@ -171,7 +172,8 @@ PROGRAMS:=fish set_color @XSEL@ @SEQ_FALLBACK@ mimedb count fish_pager fishd
|
||||||
MANUALS:=doc_src/fish.1 @XSEL_MAN_PATH@ \
|
MANUALS:=doc_src/fish.1 @XSEL_MAN_PATH@ \
|
||||||
doc_src/builtin_doc/man/man1/mimedb.1 \
|
doc_src/builtin_doc/man/man1/mimedb.1 \
|
||||||
doc_src/builtin_doc/man/man1/set_color.1 \
|
doc_src/builtin_doc/man/man1/set_color.1 \
|
||||||
doc_src/builtin_doc/man/man1/count.1
|
doc_src/builtin_doc/man/man1/count.1 \
|
||||||
|
doc_src/builtin_doc/man/man1/fishd.1
|
||||||
|
|
||||||
#All translation message catalogs
|
#All translation message catalogs
|
||||||
TRANSLATIONS_SRC := $(wildcard po/*.po)
|
TRANSLATIONS_SRC := $(wildcard po/*.po)
|
||||||
|
@ -366,7 +368,7 @@ uninstall: uninstall-translations
|
||||||
rm -f $(DESTDIR)$(sysconfdir)$(fishinputfile)
|
rm -f $(DESTDIR)$(sysconfdir)$(fishinputfile)
|
||||||
rm -r $(DESTDIR)$(sysconfdir)$(fishdir)
|
rm -r $(DESTDIR)$(sysconfdir)$(fishdir)
|
||||||
rm -r $(DESTDIR)$(docdir)
|
rm -r $(DESTDIR)$(docdir)
|
||||||
for i in fish.1* @XSEL_MAN@ mimedb.1* set_color.1* count.1*; do \
|
for i in fish.1* @XSEL_MAN@ mimedb.1* fishd.1* set_color.1* count.1*; do \
|
||||||
rm $(DESTDIR)$(mandir)/man1/$$i; \
|
rm $(DESTDIR)$(mandir)/man1/$$i; \
|
||||||
done;
|
done;
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ fi
|
||||||
%_mandir/man1/mimedb.1*
|
%_mandir/man1/mimedb.1*
|
||||||
%_mandir/man1/set_color.1*
|
%_mandir/man1/set_color.1*
|
||||||
%_mandir/man1/count.1*
|
%_mandir/man1/count.1*
|
||||||
|
%_mandir/man1/fishd.1*
|
||||||
%attr(0755,root,root) %_bindir/fish
|
%attr(0755,root,root) %_bindir/fish
|
||||||
%attr(0755,root,root) %_bindir/fishd
|
%attr(0755,root,root) %_bindir/fishd
|
||||||
%attr(0755,root,root) %_bindir/fish_pager
|
%attr(0755,root,root) %_bindir/fish_pager
|
||||||
|
|
76
fishd.c
76
fishd.c
|
@ -7,6 +7,9 @@ instances. When no clients are running, fishd will automatically shut
|
||||||
down and save.
|
down and save.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
@ -19,6 +22,10 @@ down and save.
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_GETOPT_H
|
||||||
|
#include <getopt.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
@ -75,6 +82,11 @@ static int sock;
|
||||||
*/
|
*/
|
||||||
static int quit=0;
|
static int quit=0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Dynamically generated function, made from the documentation in doc_src.
|
||||||
|
*/
|
||||||
|
void print_help();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructs the fish socket filename
|
Constructs the fish socket filename
|
||||||
*/
|
*/
|
||||||
|
@ -396,11 +408,9 @@ static void save()
|
||||||
*/
|
*/
|
||||||
static void init()
|
static void init()
|
||||||
{
|
{
|
||||||
program_name=L"fishd";
|
|
||||||
|
|
||||||
sock = get_socket();
|
sock = get_socket();
|
||||||
daemonize();
|
daemonize();
|
||||||
wsetlocale( LC_ALL, L"" );
|
|
||||||
env_universal_common_init( &broadcast );
|
env_universal_common_init( &broadcast );
|
||||||
|
|
||||||
load();
|
load();
|
||||||
|
@ -419,8 +429,68 @@ int main( int argc, char ** argv )
|
||||||
|
|
||||||
fd_set read_fd, write_fd;
|
fd_set read_fd, write_fd;
|
||||||
|
|
||||||
init();
|
program_name=L"fishd";
|
||||||
|
wsetlocale( LC_ALL, L"" );
|
||||||
|
|
||||||
|
/*
|
||||||
|
Parse options
|
||||||
|
*/
|
||||||
|
while( 1 )
|
||||||
|
{
|
||||||
|
#ifdef HAVE_GETOPT_LONG
|
||||||
|
static struct option
|
||||||
|
long_options[] =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
"help", no_argument, 0, 'h'
|
||||||
|
}
|
||||||
|
,
|
||||||
|
{
|
||||||
|
"version", no_argument, 0, 'v'
|
||||||
|
}
|
||||||
|
,
|
||||||
|
{
|
||||||
|
0, 0, 0, 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
int opt_index = 0;
|
||||||
|
|
||||||
|
int opt = getopt_long( argc,
|
||||||
|
argv,
|
||||||
|
"hv",
|
||||||
|
long_options,
|
||||||
|
&opt_index );
|
||||||
|
|
||||||
|
#else
|
||||||
|
int opt = getopt( argc,
|
||||||
|
argv,
|
||||||
|
"hv" );
|
||||||
|
#endif
|
||||||
|
if( opt == -1 )
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch( opt )
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'h':
|
||||||
|
print_help();
|
||||||
|
exit(0);
|
||||||
|
|
||||||
|
case 'v':
|
||||||
|
debug( 0, L"%ls, version %s\n", program_name, PACKAGE_VERSION );
|
||||||
|
exit( 0 );
|
||||||
|
|
||||||
|
case '?':
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
connection_t *c;
|
connection_t *c;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user