mirror of
https://github.com/Dushistov/sdcv.git
synced 2025-12-16 01:41:55 +00:00
0.4.2 release
This commit is contained in:
14
src/Makefile.am
Normal file
14
src/Makefile.am
Normal file
@@ -0,0 +1,14 @@
|
||||
SUBDIRS=lib
|
||||
bin_PROGRAMS = sdcv
|
||||
sdcv_SOURCES = \
|
||||
sdcv.cpp getopt.c getopt1.c getopt.h \
|
||||
libwrapper.cpp libwrapper.hpp \
|
||||
readline.cpp readline.hpp \
|
||||
utils.cpp utils.hpp
|
||||
|
||||
sdcv_DEPENDENCIES = lib/libstardict.a
|
||||
sdcv_LDADD = @SDCV_LIBS@ @LIBINTL@ @LIBREADLINE@ lib/libstardict.a
|
||||
localedir = $(datadir)/locale
|
||||
|
||||
INCLUDES = @SDCV_CFLAGS@ -I$(top_builddir) -Ilib
|
||||
DEFS=-DLOCALEDIR=\"$(localedir)\" @DEFS@
|
||||
581
src/Makefile.in
Normal file
581
src/Makefile.in
Normal file
@@ -0,0 +1,581 @@
|
||||
# Makefile.in generated by automake 1.9.6 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
# 2003, 2004, 2005 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
top_builddir = ..
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
INSTALL = @INSTALL@
|
||||
install_sh_DATA = $(install_sh) -c -m 644
|
||||
install_sh_PROGRAM = $(install_sh) -c
|
||||
install_sh_SCRIPT = $(install_sh) -c
|
||||
INSTALL_HEADER = $(INSTALL_DATA)
|
||||
transform = $(program_transform_name)
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
bin_PROGRAMS = sdcv$(EXEEXT)
|
||||
subdir = src
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/m4/gettext.m4 \
|
||||
$(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/lib-ld.m4 \
|
||||
$(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \
|
||||
$(top_srcdir)/m4/nls.m4 $(top_srcdir)/m4/po.m4 \
|
||||
$(top_srcdir)/m4/progtest.m4 $(top_srcdir)/m4/readline.m4 \
|
||||
$(top_srcdir)/configure.ac
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = $(top_builddir)/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
am__installdirs = "$(DESTDIR)$(bindir)"
|
||||
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
|
||||
PROGRAMS = $(bin_PROGRAMS)
|
||||
am_sdcv_OBJECTS = sdcv.$(OBJEXT) getopt.$(OBJEXT) getopt1.$(OBJEXT) \
|
||||
libwrapper.$(OBJEXT) readline.$(OBJEXT) utils.$(OBJEXT)
|
||||
sdcv_OBJECTS = $(am_sdcv_OBJECTS)
|
||||
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
|
||||
depcomp = $(SHELL) $(top_srcdir)/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
|
||||
CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
|
||||
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
|
||||
CXXLD = $(CXX)
|
||||
CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
|
||||
-o $@
|
||||
SOURCES = $(sdcv_SOURCES)
|
||||
DIST_SOURCES = $(sdcv_SOURCES)
|
||||
RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
|
||||
html-recursive info-recursive install-data-recursive \
|
||||
install-exec-recursive install-info-recursive \
|
||||
install-recursive installcheck-recursive installdirs-recursive \
|
||||
pdf-recursive ps-recursive uninstall-info-recursive \
|
||||
uninstall-recursive
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DIST_SUBDIRS = $(SUBDIRS)
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AMDEP_FALSE = @AMDEP_FALSE@
|
||||
AMDEP_TRUE = @AMDEP_TRUE@
|
||||
AMTAR = @AMTAR@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
CC = @CC@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CXX = @CXX@
|
||||
CXXCPP = @CXXCPP@
|
||||
CXXDEPMODE = @CXXDEPMODE@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
GETTEXT_PACKAGE = @GETTEXT_PACKAGE@
|
||||
GMSGFMT = @GMSGFMT@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
INTLLIBS = @INTLLIBS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBICONV = @LIBICONV@
|
||||
LIBINTL = @LIBINTL@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBREADLINE = @LIBREADLINE@
|
||||
LIBS = @LIBS@
|
||||
LIB_STARDICT_CFLAGS = @LIB_STARDICT_CFLAGS@
|
||||
LIB_STARDICT_LIBS = @LIB_STARDICT_LIBS@
|
||||
LTLIBICONV = @LTLIBICONV@
|
||||
LTLIBINTL = @LTLIBINTL@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
MAINT = @MAINT@
|
||||
MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@
|
||||
MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
MKINSTALLDIRS = @MKINSTALLDIRS@
|
||||
MSGFMT = @MSGFMT@
|
||||
MSGMERGE = @MSGMERGE@
|
||||
OBJEXT = @OBJEXT@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_STRING = @PACKAGE_STRING@
|
||||
PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
PKG_CONFIG = @PKG_CONFIG@
|
||||
POSUB = @POSUB@
|
||||
RANLIB = @RANLIB@
|
||||
SDCV_CFLAGS = @SDCV_CFLAGS@
|
||||
SDCV_LIBS = @SDCV_LIBS@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
USE_NLS = @USE_NLS@
|
||||
VERSION = @VERSION@
|
||||
XGETTEXT = @XGETTEXT@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_CXX = @ac_ct_CXX@
|
||||
ac_ct_RANLIB = @ac_ct_RANLIB@
|
||||
ac_ct_STRIP = @ac_ct_STRIP@
|
||||
ac_pt_PKG_CONFIG = @ac_pt_PKG_CONFIG@
|
||||
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
|
||||
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
|
||||
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
|
||||
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build = @build@
|
||||
build_alias = @build_alias@
|
||||
build_cpu = @build_cpu@
|
||||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
datadir = @datadir@
|
||||
exec_prefix = @exec_prefix@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
oldincludedir = @oldincludedir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
SUBDIRS = lib
|
||||
sdcv_SOURCES = \
|
||||
sdcv.cpp getopt.c getopt1.c getopt.h \
|
||||
libwrapper.cpp libwrapper.hpp \
|
||||
readline.cpp readline.hpp \
|
||||
utils.cpp utils.hpp
|
||||
|
||||
sdcv_DEPENDENCIES = lib/libstardict.a
|
||||
sdcv_LDADD = @SDCV_LIBS@ @LIBINTL@ @LIBREADLINE@ lib/libstardict.a
|
||||
localedir = $(datadir)/locale
|
||||
INCLUDES = @SDCV_CFLAGS@ -I$(top_builddir) -Ilib
|
||||
all: all-recursive
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .cpp .o .obj
|
||||
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
|
||||
@for dep in $?; do \
|
||||
case '$(am__configure_deps)' in \
|
||||
*$$dep*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
|
||||
&& exit 0; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
|
||||
cd $(top_srcdir) && \
|
||||
$(AUTOMAKE) --gnu src/Makefile
|
||||
.PRECIOUS: Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
*config.status*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
|
||||
*) \
|
||||
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
|
||||
esac;
|
||||
|
||||
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
install-binPROGRAMS: $(bin_PROGRAMS)
|
||||
@$(NORMAL_INSTALL)
|
||||
test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)"
|
||||
@list='$(bin_PROGRAMS)'; for p in $$list; do \
|
||||
p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
|
||||
if test -f $$p \
|
||||
; then \
|
||||
f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
|
||||
echo " $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
|
||||
$(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
|
||||
else :; fi; \
|
||||
done
|
||||
|
||||
uninstall-binPROGRAMS:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@list='$(bin_PROGRAMS)'; for p in $$list; do \
|
||||
f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
|
||||
echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
|
||||
rm -f "$(DESTDIR)$(bindir)/$$f"; \
|
||||
done
|
||||
|
||||
clean-binPROGRAMS:
|
||||
-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
|
||||
sdcv$(EXEEXT): $(sdcv_OBJECTS) $(sdcv_DEPENDENCIES)
|
||||
@rm -f sdcv$(EXEEXT)
|
||||
$(CXXLINK) $(sdcv_LDFLAGS) $(sdcv_OBJECTS) $(sdcv_LDADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt1.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libwrapper.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readline.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sdcv.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utils.Po@am__quote@
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
|
||||
|
||||
.c.obj:
|
||||
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
|
||||
|
||||
.cpp.o:
|
||||
@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
|
||||
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $<
|
||||
|
||||
.cpp.obj:
|
||||
@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
|
||||
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
uninstall-info-am:
|
||||
|
||||
# This directory's subdirectories are mostly independent; you can cd
|
||||
# into them and run `make' without going through this Makefile.
|
||||
# To change the values of `make' variables: instead of editing Makefiles,
|
||||
# (1) if the variable is set in `config.status', edit `config.status'
|
||||
# (which will cause the Makefiles to be regenerated when you run `make');
|
||||
# (2) otherwise, pass the desired values on the `make' command line.
|
||||
$(RECURSIVE_TARGETS):
|
||||
@failcom='exit 1'; \
|
||||
for f in x $$MAKEFLAGS; do \
|
||||
case $$f in \
|
||||
*=* | --[!k]*);; \
|
||||
*k*) failcom='fail=yes';; \
|
||||
esac; \
|
||||
done; \
|
||||
dot_seen=no; \
|
||||
target=`echo $@ | sed s/-recursive//`; \
|
||||
list='$(SUBDIRS)'; for subdir in $$list; do \
|
||||
echo "Making $$target in $$subdir"; \
|
||||
if test "$$subdir" = "."; then \
|
||||
dot_seen=yes; \
|
||||
local_target="$$target-am"; \
|
||||
else \
|
||||
local_target="$$target"; \
|
||||
fi; \
|
||||
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|
||||
|| eval $$failcom; \
|
||||
done; \
|
||||
if test "$$dot_seen" = "no"; then \
|
||||
$(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
|
||||
fi; test -z "$$fail"
|
||||
|
||||
mostlyclean-recursive clean-recursive distclean-recursive \
|
||||
maintainer-clean-recursive:
|
||||
@failcom='exit 1'; \
|
||||
for f in x $$MAKEFLAGS; do \
|
||||
case $$f in \
|
||||
*=* | --[!k]*);; \
|
||||
*k*) failcom='fail=yes';; \
|
||||
esac; \
|
||||
done; \
|
||||
dot_seen=no; \
|
||||
case "$@" in \
|
||||
distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
|
||||
*) list='$(SUBDIRS)' ;; \
|
||||
esac; \
|
||||
rev=''; for subdir in $$list; do \
|
||||
if test "$$subdir" = "."; then :; else \
|
||||
rev="$$subdir $$rev"; \
|
||||
fi; \
|
||||
done; \
|
||||
rev="$$rev ."; \
|
||||
target=`echo $@ | sed s/-recursive//`; \
|
||||
for subdir in $$rev; do \
|
||||
echo "Making $$target in $$subdir"; \
|
||||
if test "$$subdir" = "."; then \
|
||||
local_target="$$target-am"; \
|
||||
else \
|
||||
local_target="$$target"; \
|
||||
fi; \
|
||||
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|
||||
|| eval $$failcom; \
|
||||
done && test -z "$$fail"
|
||||
tags-recursive:
|
||||
list='$(SUBDIRS)'; for subdir in $$list; do \
|
||||
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
|
||||
done
|
||||
ctags-recursive:
|
||||
list='$(SUBDIRS)'; for subdir in $$list; do \
|
||||
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
|
||||
done
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
mkid -fID $$unique
|
||||
tags: TAGS
|
||||
|
||||
TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
|
||||
include_option=--etags-include; \
|
||||
empty_fix=.; \
|
||||
else \
|
||||
include_option=--include; \
|
||||
empty_fix=; \
|
||||
fi; \
|
||||
list='$(SUBDIRS)'; for subdir in $$list; do \
|
||||
if test "$$subdir" = .; then :; else \
|
||||
test ! -f $$subdir/TAGS || \
|
||||
tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \
|
||||
fi; \
|
||||
done; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
|
||||
test -n "$$unique" || unique=$$empty_fix; \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
$$tags $$unique; \
|
||||
fi
|
||||
ctags: CTAGS
|
||||
CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|
||||
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
|
||||
$$tags $$unique
|
||||
|
||||
GTAGS:
|
||||
here=`$(am__cd) $(top_builddir) && pwd` \
|
||||
&& cd $(top_srcdir) \
|
||||
&& gtags -i $(GTAGS_ARGS) $$here
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
|
||||
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
|
||||
list='$(DISTFILES)'; for file in $$list; do \
|
||||
case $$file in \
|
||||
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
|
||||
esac; \
|
||||
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
|
||||
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
|
||||
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
|
||||
dir="/$$dir"; \
|
||||
$(mkdir_p) "$(distdir)$$dir"; \
|
||||
else \
|
||||
dir=''; \
|
||||
fi; \
|
||||
if test -d $$d/$$file; then \
|
||||
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
|
||||
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
|
||||
fi; \
|
||||
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file \
|
||||
|| exit 1; \
|
||||
fi; \
|
||||
done
|
||||
list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
|
||||
if test "$$subdir" = .; then :; else \
|
||||
test -d "$(distdir)/$$subdir" \
|
||||
|| $(mkdir_p) "$(distdir)/$$subdir" \
|
||||
|| exit 1; \
|
||||
distdir=`$(am__cd) $(distdir) && pwd`; \
|
||||
top_distdir=`$(am__cd) $(top_distdir) && pwd`; \
|
||||
(cd $$subdir && \
|
||||
$(MAKE) $(AM_MAKEFLAGS) \
|
||||
top_distdir="$$top_distdir" \
|
||||
distdir="$$distdir/$$subdir" \
|
||||
distdir) \
|
||||
|| exit 1; \
|
||||
fi; \
|
||||
done
|
||||
check-am: all-am
|
||||
check: check-recursive
|
||||
all-am: Makefile $(PROGRAMS)
|
||||
installdirs: installdirs-recursive
|
||||
installdirs-am:
|
||||
for dir in "$(DESTDIR)$(bindir)"; do \
|
||||
test -z "$$dir" || $(mkdir_p) "$$dir"; \
|
||||
done
|
||||
install: install-recursive
|
||||
install-exec: install-exec-recursive
|
||||
install-data: install-data-recursive
|
||||
uninstall: uninstall-recursive
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
|
||||
installcheck: installcheck-recursive
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
`test -z '$(STRIP)' || \
|
||||
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
|
||||
|
||||
maintainer-clean-generic:
|
||||
@echo "This command is intended for maintainers to use"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
clean: clean-recursive
|
||||
|
||||
clean-am: clean-binPROGRAMS clean-generic mostlyclean-am
|
||||
|
||||
distclean: distclean-recursive
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
distclean-am: clean-am distclean-compile distclean-generic \
|
||||
distclean-tags
|
||||
|
||||
dvi: dvi-recursive
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-recursive
|
||||
|
||||
info: info-recursive
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am:
|
||||
|
||||
install-exec-am: install-binPROGRAMS
|
||||
|
||||
install-info: install-info-recursive
|
||||
|
||||
install-man:
|
||||
|
||||
installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-recursive
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||
|
||||
mostlyclean: mostlyclean-recursive
|
||||
|
||||
mostlyclean-am: mostlyclean-compile mostlyclean-generic
|
||||
|
||||
pdf: pdf-recursive
|
||||
|
||||
pdf-am:
|
||||
|
||||
ps: ps-recursive
|
||||
|
||||
ps-am:
|
||||
|
||||
uninstall-am: uninstall-binPROGRAMS uninstall-info-am
|
||||
|
||||
uninstall-info: uninstall-info-recursive
|
||||
|
||||
.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am check check-am \
|
||||
clean clean-binPROGRAMS clean-generic clean-recursive ctags \
|
||||
ctags-recursive distclean distclean-compile distclean-generic \
|
||||
distclean-recursive distclean-tags distdir dvi dvi-am html \
|
||||
html-am info info-am install install-am install-binPROGRAMS \
|
||||
install-data install-data-am install-exec install-exec-am \
|
||||
install-info install-info-am install-man install-strip \
|
||||
installcheck installcheck-am installdirs installdirs-am \
|
||||
maintainer-clean maintainer-clean-generic \
|
||||
maintainer-clean-recursive mostlyclean mostlyclean-compile \
|
||||
mostlyclean-generic mostlyclean-recursive pdf pdf-am ps ps-am \
|
||||
tags tags-recursive uninstall uninstall-am \
|
||||
uninstall-binPROGRAMS uninstall-info-am
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
1067
src/getopt.c
Normal file
1067
src/getopt.c
Normal file
File diff suppressed because it is too large
Load Diff
179
src/getopt.h
Normal file
179
src/getopt.h
Normal file
@@ -0,0 +1,179 @@
|
||||
/* Declarations for getopt.
|
||||
Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef _GETOPT_H
|
||||
|
||||
#ifndef __need_getopt
|
||||
# define _GETOPT_H 1
|
||||
#endif
|
||||
|
||||
/* If __GNU_LIBRARY__ is not already defined, either we are being used
|
||||
standalone, or this is the first header included in the source file.
|
||||
If we are being used with glibc, we need to include <features.h>, but
|
||||
that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
|
||||
not defined, include <ctype.h>, which will pull in <features.h> for us
|
||||
if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
|
||||
doesn't flood the namespace with stuff the way some other headers do.) */
|
||||
#if !defined __GNU_LIBRARY__
|
||||
# include <ctype.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* For communication from `getopt' to the caller.
|
||||
When `getopt' finds an option that takes an argument,
|
||||
the argument value is returned here.
|
||||
Also, when `ordering' is RETURN_IN_ORDER,
|
||||
each non-option ARGV-element is returned here. */
|
||||
|
||||
extern char *optarg;
|
||||
|
||||
/* Index in ARGV of the next element to be scanned.
|
||||
This is used for communication to and from the caller
|
||||
and for communication between successive calls to `getopt'.
|
||||
|
||||
On entry to `getopt', zero means this is the first call; initialize.
|
||||
|
||||
When `getopt' returns -1, this is the index of the first of the
|
||||
non-option elements that the caller should itself scan.
|
||||
|
||||
Otherwise, `optind' communicates from one call to the next
|
||||
how much of ARGV has been scanned so far. */
|
||||
|
||||
extern int optind;
|
||||
|
||||
/* Callers store zero here to inhibit the error message `getopt' prints
|
||||
for unrecognized options. */
|
||||
|
||||
extern int opterr;
|
||||
|
||||
/* Set to an option character which was unrecognized. */
|
||||
|
||||
extern int optopt;
|
||||
|
||||
#ifndef __need_getopt
|
||||
/* Describe the long-named options requested by the application.
|
||||
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
|
||||
of `struct option' terminated by an element containing a name which is
|
||||
zero.
|
||||
|
||||
The field `has_arg' is:
|
||||
no_argument (or 0) if the option does not take an argument,
|
||||
required_argument (or 1) if the option requires an argument,
|
||||
optional_argument (or 2) if the option takes an optional argument.
|
||||
|
||||
If the field `flag' is not NULL, it points to a variable that is set
|
||||
to the value given in the field `val' when the option is found, but
|
||||
left unchanged if the option is not found.
|
||||
|
||||
To have a long-named option do something other than set an `int' to
|
||||
a compiled-in constant, such as set a value from `optarg', set the
|
||||
option's `flag' field to zero and its `val' field to a nonzero
|
||||
value (the equivalent single-letter option character, if there is
|
||||
one). For long options that have a zero `flag' field, `getopt'
|
||||
returns the contents of the `val' field. */
|
||||
|
||||
struct option
|
||||
{
|
||||
# if (defined __STDC__ && __STDC__) || defined __cplusplus
|
||||
const char *name;
|
||||
# else
|
||||
char *name;
|
||||
# endif
|
||||
/* has_arg can't be an enum because some compilers complain about
|
||||
type mismatches in all the code that assumes it is an int. */
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int val;
|
||||
};
|
||||
|
||||
/* Names for the values of the `has_arg' field of `struct option'. */
|
||||
|
||||
# define no_argument 0
|
||||
# define required_argument 1
|
||||
# define optional_argument 2
|
||||
#endif /* need getopt */
|
||||
|
||||
|
||||
/* Get definitions and prototypes for functions to process the
|
||||
arguments in ARGV (ARGC of them, minus the program name) for
|
||||
options given in OPTS.
|
||||
|
||||
Return the option character from OPTS just read. Return -1 when
|
||||
there are no more options. For unrecognized options, or options
|
||||
missing arguments, `optopt' is set to the option letter, and '?' is
|
||||
returned.
|
||||
|
||||
The OPTS string is a list of characters which are recognized option
|
||||
letters, optionally followed by colons, specifying that that letter
|
||||
takes an argument, to be placed in `optarg'.
|
||||
|
||||
If a letter in OPTS is followed by two colons, its argument is
|
||||
optional. This behavior is specific to the GNU `getopt'.
|
||||
|
||||
The argument `--' causes premature termination of argument
|
||||
scanning, explicitly telling `getopt' that there are no more
|
||||
options.
|
||||
|
||||
If OPTS begins with `--', then non-option arguments are treated as
|
||||
arguments to the option '\0'. This behavior is specific to the GNU
|
||||
`getopt'. */
|
||||
|
||||
#if (defined __STDC__ && __STDC__) || defined __cplusplus
|
||||
# ifdef __GNU_LIBRARY__
|
||||
/* Many other libraries have conflicting prototypes for getopt, with
|
||||
differences in the consts, in stdlib.h. To avoid compilation
|
||||
errors, only prototype getopt for the GNU C library. */
|
||||
extern int getopt (int __argc, char *const *__argv, const char *__shortopts);
|
||||
# else /* not __GNU_LIBRARY__ */
|
||||
extern int getopt ();
|
||||
# endif /* __GNU_LIBRARY__ */
|
||||
|
||||
# ifndef __need_getopt
|
||||
extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind);
|
||||
extern int getopt_long_only (int __argc, char *const *__argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind);
|
||||
|
||||
/* Internal only. Users should not call this directly. */
|
||||
extern int _getopt_internal (int __argc, char *const *__argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind,
|
||||
int __long_only);
|
||||
# endif
|
||||
#else /* not __STDC__ */
|
||||
extern int getopt ();
|
||||
# ifndef __need_getopt
|
||||
extern int getopt_long ();
|
||||
extern int getopt_long_only ();
|
||||
|
||||
extern int _getopt_internal ();
|
||||
# endif
|
||||
#endif /* __STDC__ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make sure we later can get all the definitions and declarations. */
|
||||
#undef __need_getopt
|
||||
|
||||
#endif /* getopt.h */
|
||||
187
src/getopt1.c
Normal file
187
src/getopt1.c
Normal file
@@ -0,0 +1,187 @@
|
||||
/* getopt_long and getopt_long_only entry points for GNU getopt.
|
||||
Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98
|
||||
Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "getopt.h"
|
||||
|
||||
#if !defined __STDC__ || !__STDC__
|
||||
/* This is a separate conditional since some stdc systems
|
||||
reject `defined (const)'. */
|
||||
#ifndef const
|
||||
#define const
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* Comment out all this code if we are using the GNU C Library, and are not
|
||||
actually compiling the library itself. This code is part of the GNU C
|
||||
Library, but also included in many other GNU distributions. Compiling
|
||||
and linking in this code is a waste when using the GNU C library
|
||||
(especially if it is a shared library). Rather than having every GNU
|
||||
program understand `configure --with-gnu-libc' and omit the object files,
|
||||
it is simpler to just do this in the source for each such file. */
|
||||
|
||||
#define GETOPT_INTERFACE_VERSION 2
|
||||
#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
|
||||
#include <gnu-versions.h>
|
||||
#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
|
||||
#define ELIDE_CODE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ELIDE_CODE
|
||||
|
||||
|
||||
/* This needs to come after some library #include
|
||||
to get __GNU_LIBRARY__ defined. */
|
||||
#ifdef __GNU_LIBRARY__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
int
|
||||
getopt_long (argc, argv, options, long_options, opt_index)
|
||||
int argc;
|
||||
char *const *argv;
|
||||
const char *options;
|
||||
const struct option *long_options;
|
||||
int *opt_index;
|
||||
{
|
||||
return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
|
||||
}
|
||||
|
||||
/* Like getopt_long, but '-' as well as '--' can indicate a long option.
|
||||
If an option that starts with '-' (not '--') doesn't match a long option,
|
||||
but does match a short option, it is parsed as a short option
|
||||
instead. */
|
||||
|
||||
int
|
||||
getopt_long_only (argc, argv, options, long_options, opt_index)
|
||||
int argc;
|
||||
char *const *argv;
|
||||
const char *options;
|
||||
const struct option *long_options;
|
||||
int *opt_index;
|
||||
{
|
||||
return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
|
||||
}
|
||||
|
||||
|
||||
#endif /* Not ELIDE_CODE. */
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main (argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int c;
|
||||
int digit_optind = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
int this_option_optind = optind ? optind : 1;
|
||||
int option_index = 0;
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"add", 1, 0, 0},
|
||||
{"append", 0, 0, 0},
|
||||
{"delete", 1, 0, 0},
|
||||
{"verbose", 0, 0, 0},
|
||||
{"create", 0, 0, 0},
|
||||
{"file", 1, 0, 0},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
c = getopt_long (argc, argv, "abc:d:0123456789",
|
||||
long_options, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case 0:
|
||||
printf ("option %s", long_options[option_index].name);
|
||||
if (optarg)
|
||||
printf (" with arg %s", optarg);
|
||||
printf ("\n");
|
||||
break;
|
||||
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if (digit_optind != 0 && digit_optind != this_option_optind)
|
||||
printf ("digits occur in two different argv-elements.\n");
|
||||
digit_optind = this_option_optind;
|
||||
printf ("option %c\n", c);
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
printf ("option a\n");
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
printf ("option b\n");
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
printf ("option c with value `%s'\n", optarg);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
printf ("option d with value `%s'\n", optarg);
|
||||
break;
|
||||
|
||||
case '?':
|
||||
break;
|
||||
|
||||
default:
|
||||
printf ("?? getopt returned character code 0%o ??\n", c);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc)
|
||||
{
|
||||
printf ("non-option ARGV-elements: ");
|
||||
while (optind < argc)
|
||||
printf ("%s ", argv[optind++]);
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
exit (0);
|
||||
}
|
||||
|
||||
#endif /* TEST */
|
||||
10
src/lib/Makefile.am
Normal file
10
src/lib/Makefile.am
Normal file
@@ -0,0 +1,10 @@
|
||||
noinst_LIBRARIES = libstardict.a
|
||||
|
||||
libstardict_a_SOURCES = \
|
||||
lib.cpp lib.h \
|
||||
dictziplib.cpp dictziplib.hpp \
|
||||
distance.cpp distance.h \
|
||||
mapfile.hpp file.hpp
|
||||
|
||||
|
||||
INCLUDES = @LIB_STARDICT_CFLAGS@
|
||||
428
src/lib/Makefile.in
Normal file
428
src/lib/Makefile.in
Normal file
@@ -0,0 +1,428 @@
|
||||
# Makefile.in generated by automake 1.9.6 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
# 2003, 2004, 2005 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
top_builddir = ../..
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
INSTALL = @INSTALL@
|
||||
install_sh_DATA = $(install_sh) -c -m 644
|
||||
install_sh_PROGRAM = $(install_sh) -c
|
||||
install_sh_SCRIPT = $(install_sh) -c
|
||||
INSTALL_HEADER = $(INSTALL_DATA)
|
||||
transform = $(program_transform_name)
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
subdir = src/lib
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/m4/gettext.m4 \
|
||||
$(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/lib-ld.m4 \
|
||||
$(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \
|
||||
$(top_srcdir)/m4/nls.m4 $(top_srcdir)/m4/po.m4 \
|
||||
$(top_srcdir)/m4/progtest.m4 $(top_srcdir)/m4/readline.m4 \
|
||||
$(top_srcdir)/configure.ac
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = $(top_builddir)/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
LIBRARIES = $(noinst_LIBRARIES)
|
||||
AR = ar
|
||||
ARFLAGS = cru
|
||||
libstardict_a_AR = $(AR) $(ARFLAGS)
|
||||
libstardict_a_LIBADD =
|
||||
am_libstardict_a_OBJECTS = lib.$(OBJEXT) dictziplib.$(OBJEXT) \
|
||||
distance.$(OBJEXT)
|
||||
libstardict_a_OBJECTS = $(am_libstardict_a_OBJECTS)
|
||||
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
|
||||
depcomp = $(SHELL) $(top_srcdir)/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
|
||||
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
|
||||
CXXLD = $(CXX)
|
||||
CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
|
||||
-o $@
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
|
||||
SOURCES = $(libstardict_a_SOURCES)
|
||||
DIST_SOURCES = $(libstardict_a_SOURCES)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AMDEP_FALSE = @AMDEP_FALSE@
|
||||
AMDEP_TRUE = @AMDEP_TRUE@
|
||||
AMTAR = @AMTAR@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
CC = @CC@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CXX = @CXX@
|
||||
CXXCPP = @CXXCPP@
|
||||
CXXDEPMODE = @CXXDEPMODE@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
GETTEXT_PACKAGE = @GETTEXT_PACKAGE@
|
||||
GMSGFMT = @GMSGFMT@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
INTLLIBS = @INTLLIBS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBICONV = @LIBICONV@
|
||||
LIBINTL = @LIBINTL@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBREADLINE = @LIBREADLINE@
|
||||
LIBS = @LIBS@
|
||||
LIB_STARDICT_CFLAGS = @LIB_STARDICT_CFLAGS@
|
||||
LIB_STARDICT_LIBS = @LIB_STARDICT_LIBS@
|
||||
LTLIBICONV = @LTLIBICONV@
|
||||
LTLIBINTL = @LTLIBINTL@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
MAINT = @MAINT@
|
||||
MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@
|
||||
MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
MKINSTALLDIRS = @MKINSTALLDIRS@
|
||||
MSGFMT = @MSGFMT@
|
||||
MSGMERGE = @MSGMERGE@
|
||||
OBJEXT = @OBJEXT@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_STRING = @PACKAGE_STRING@
|
||||
PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
PKG_CONFIG = @PKG_CONFIG@
|
||||
POSUB = @POSUB@
|
||||
RANLIB = @RANLIB@
|
||||
SDCV_CFLAGS = @SDCV_CFLAGS@
|
||||
SDCV_LIBS = @SDCV_LIBS@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
USE_NLS = @USE_NLS@
|
||||
VERSION = @VERSION@
|
||||
XGETTEXT = @XGETTEXT@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_CXX = @ac_ct_CXX@
|
||||
ac_ct_RANLIB = @ac_ct_RANLIB@
|
||||
ac_ct_STRIP = @ac_ct_STRIP@
|
||||
ac_pt_PKG_CONFIG = @ac_pt_PKG_CONFIG@
|
||||
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
|
||||
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
|
||||
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
|
||||
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build = @build@
|
||||
build_alias = @build_alias@
|
||||
build_cpu = @build_cpu@
|
||||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
datadir = @datadir@
|
||||
exec_prefix = @exec_prefix@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
oldincludedir = @oldincludedir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
noinst_LIBRARIES = libstardict.a
|
||||
libstardict_a_SOURCES = \
|
||||
lib.cpp lib.h \
|
||||
dictziplib.cpp dictziplib.hpp \
|
||||
distance.cpp distance.h \
|
||||
mapfile.hpp file.hpp
|
||||
|
||||
INCLUDES = @LIB_STARDICT_CFLAGS@
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .cpp .o .obj
|
||||
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
|
||||
@for dep in $?; do \
|
||||
case '$(am__configure_deps)' in \
|
||||
*$$dep*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
|
||||
&& exit 0; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/lib/Makefile'; \
|
||||
cd $(top_srcdir) && \
|
||||
$(AUTOMAKE) --gnu src/lib/Makefile
|
||||
.PRECIOUS: Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
*config.status*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
|
||||
*) \
|
||||
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
|
||||
esac;
|
||||
|
||||
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
clean-noinstLIBRARIES:
|
||||
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
|
||||
libstardict.a: $(libstardict_a_OBJECTS) $(libstardict_a_DEPENDENCIES)
|
||||
-rm -f libstardict.a
|
||||
$(libstardict_a_AR) libstardict.a $(libstardict_a_OBJECTS) $(libstardict_a_LIBADD)
|
||||
$(RANLIB) libstardict.a
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dictziplib.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/distance.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lib.Po@am__quote@
|
||||
|
||||
.cpp.o:
|
||||
@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
|
||||
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $<
|
||||
|
||||
.cpp.obj:
|
||||
@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
|
||||
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
uninstall-info-am:
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
mkid -fID $$unique
|
||||
tags: TAGS
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
|
||||
test -n "$$unique" || unique=$$empty_fix; \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
$$tags $$unique; \
|
||||
fi
|
||||
ctags: CTAGS
|
||||
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|
||||
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
|
||||
$$tags $$unique
|
||||
|
||||
GTAGS:
|
||||
here=`$(am__cd) $(top_builddir) && pwd` \
|
||||
&& cd $(top_srcdir) \
|
||||
&& gtags -i $(GTAGS_ARGS) $$here
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
|
||||
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
|
||||
list='$(DISTFILES)'; for file in $$list; do \
|
||||
case $$file in \
|
||||
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
|
||||
esac; \
|
||||
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
|
||||
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
|
||||
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
|
||||
dir="/$$dir"; \
|
||||
$(mkdir_p) "$(distdir)$$dir"; \
|
||||
else \
|
||||
dir=''; \
|
||||
fi; \
|
||||
if test -d $$d/$$file; then \
|
||||
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
|
||||
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
|
||||
fi; \
|
||||
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file \
|
||||
|| exit 1; \
|
||||
fi; \
|
||||
done
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
all-am: Makefile $(LIBRARIES)
|
||||
installdirs:
|
||||
install: install-am
|
||||
install-exec: install-exec-am
|
||||
install-data: install-data-am
|
||||
uninstall: uninstall-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
|
||||
installcheck: installcheck-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
`test -z '$(STRIP)' || \
|
||||
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
|
||||
|
||||
maintainer-clean-generic:
|
||||
@echo "This command is intended for maintainers to use"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
clean: clean-am
|
||||
|
||||
clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
distclean-am: clean-am distclean-compile distclean-generic \
|
||||
distclean-tags
|
||||
|
||||
dvi: dvi-am
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-am
|
||||
|
||||
info: info-am
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am:
|
||||
|
||||
install-exec-am:
|
||||
|
||||
install-info: install-info-am
|
||||
|
||||
install-man:
|
||||
|
||||
installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
mostlyclean-am: mostlyclean-compile mostlyclean-generic
|
||||
|
||||
pdf: pdf-am
|
||||
|
||||
pdf-am:
|
||||
|
||||
ps: ps-am
|
||||
|
||||
ps-am:
|
||||
|
||||
uninstall-am: uninstall-info-am
|
||||
|
||||
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
|
||||
clean-noinstLIBRARIES ctags distclean distclean-compile \
|
||||
distclean-generic distclean-tags distdir dvi dvi-am html \
|
||||
html-am info info-am install install-am install-data \
|
||||
install-data-am install-exec install-exec-am install-info \
|
||||
install-info-am install-man install-strip installcheck \
|
||||
installcheck-am installdirs maintainer-clean \
|
||||
maintainer-clean-generic mostlyclean mostlyclean-compile \
|
||||
mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \
|
||||
uninstall-am uninstall-info-am
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
484
src/lib/dictziplib.cpp
Normal file
484
src/lib/dictziplib.cpp
Normal file
@@ -0,0 +1,484 @@
|
||||
/* dictziplib.c --
|
||||
* http://stardict.sourceforge.net
|
||||
* Copyright (C) 2003-2003 Hu Zheng <huzheng_001@163.com>
|
||||
* This file is a modify version of dictd-1.9.7's data.c
|
||||
*
|
||||
* data.c --
|
||||
* Created: Tue Jul 16 12:45:41 1996 by faith@dict.org
|
||||
* Revised: Sat Mar 30 10:46:06 2002 by faith@dict.org
|
||||
* Copyright 1996, 1997, 1998, 2000, 2002 Rickard E. Faith (faith@dict.org)
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
//#define HAVE_MMAP //it will defined in config.h. this can be done by configure.in with a AC_FUNC_MMAP.
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
#include "dictziplib.hpp"
|
||||
|
||||
#define USE_CACHE 1
|
||||
|
||||
#define BUFFERSIZE 10240
|
||||
|
||||
/*
|
||||
* Output buffer must be greater than or
|
||||
* equal to 110% of input buffer size, plus
|
||||
* 12 bytes.
|
||||
*/
|
||||
#define OUT_BUFFER_SIZE 0xffffL
|
||||
|
||||
#define IN_BUFFER_SIZE ((unsigned long)((double)(OUT_BUFFER_SIZE - 12) * 0.89))
|
||||
|
||||
/* For gzip-compatible header, as defined in RFC 1952 */
|
||||
|
||||
/* Magic for GZIP (rfc1952) */
|
||||
#define GZ_MAGIC1 0x1f /* First magic byte */
|
||||
#define GZ_MAGIC2 0x8b /* Second magic byte */
|
||||
|
||||
/* FLaGs (bitmapped), from rfc1952 */
|
||||
#define GZ_FTEXT 0x01 /* Set for ASCII text */
|
||||
#define GZ_FHCRC 0x02 /* Header CRC16 */
|
||||
#define GZ_FEXTRA 0x04 /* Optional field (random access index) */
|
||||
#define GZ_FNAME 0x08 /* Original name */
|
||||
#define GZ_COMMENT 0x10 /* Zero-terminated, human-readable comment */
|
||||
#define GZ_MAX 2 /* Maximum compression */
|
||||
#define GZ_FAST 4 /* Fasted compression */
|
||||
|
||||
/* These are from rfc1952 */
|
||||
#define GZ_OS_FAT 0 /* FAT filesystem (MS-DOS, OS/2, NT/Win32) */
|
||||
#define GZ_OS_AMIGA 1 /* Amiga */
|
||||
#define GZ_OS_VMS 2 /* VMS (or OpenVMS) */
|
||||
#define GZ_OS_UNIX 3 /* Unix */
|
||||
#define GZ_OS_VMCMS 4 /* VM/CMS */
|
||||
#define GZ_OS_ATARI 5 /* Atari TOS */
|
||||
#define GZ_OS_HPFS 6 /* HPFS filesystem (OS/2, NT) */
|
||||
#define GZ_OS_MAC 7 /* Macintosh */
|
||||
#define GZ_OS_Z 8 /* Z-System */
|
||||
#define GZ_OS_CPM 9 /* CP/M */
|
||||
#define GZ_OS_TOPS20 10 /* TOPS-20 */
|
||||
#define GZ_OS_NTFS 11 /* NTFS filesystem (NT) */
|
||||
#define GZ_OS_QDOS 12 /* QDOS */
|
||||
#define GZ_OS_ACORN 13 /* Acorn RISCOS */
|
||||
#define GZ_OS_UNKNOWN 255 /* unknown */
|
||||
|
||||
#define GZ_RND_S1 'R' /* First magic for random access format */
|
||||
#define GZ_RND_S2 'A' /* Second magic for random access format */
|
||||
|
||||
#define GZ_ID1 0 /* GZ_MAGIC1 */
|
||||
#define GZ_ID2 1 /* GZ_MAGIC2 */
|
||||
#define GZ_CM 2 /* Compression Method (Z_DEFALTED) */
|
||||
#define GZ_FLG 3 /* FLaGs (see above) */
|
||||
#define GZ_MTIME 4 /* Modification TIME */
|
||||
#define GZ_XFL 8 /* eXtra FLags (GZ_MAX or GZ_FAST) */
|
||||
#define GZ_OS 9 /* Operating System */
|
||||
#define GZ_XLEN 10 /* eXtra LENgth (16bit) */
|
||||
#define GZ_FEXTRA_START 12 /* Start of extra fields */
|
||||
#define GZ_SI1 12 /* Subfield ID1 */
|
||||
#define GZ_SI2 13 /* Subfield ID2 */
|
||||
#define GZ_SUBLEN 14 /* Subfield length (16bit) */
|
||||
#define GZ_VERSION 16 /* Version for subfield format */
|
||||
#define GZ_CHUNKLEN 18 /* Chunk length (16bit) */
|
||||
#define GZ_CHUNKCNT 20 /* Number of chunks (16bit) */
|
||||
#define GZ_RNDDATA 22 /* Random access data (16bit) */
|
||||
|
||||
#define DICT_UNKNOWN 0
|
||||
#define DICT_TEXT 1
|
||||
#define DICT_GZIP 2
|
||||
#define DICT_DZIP 3
|
||||
|
||||
|
||||
int dictData::read_header(const std::string &fname, int computeCRC)
|
||||
{
|
||||
FILE *str;
|
||||
int id1, id2, si1, si2;
|
||||
char buffer[BUFFERSIZE];
|
||||
int extraLength, subLength;
|
||||
int i;
|
||||
char *pt;
|
||||
int c;
|
||||
struct stat sb;
|
||||
unsigned long crc = crc32( 0L, Z_NULL, 0 );
|
||||
int count;
|
||||
unsigned long offset;
|
||||
|
||||
if (!(str = fopen(fname.c_str(), "rb"))) {
|
||||
//err_fatal_errno( __FUNCTION__,
|
||||
// "Cannot open data file \"%s\" for read\n", filename );
|
||||
}
|
||||
|
||||
this->headerLength = GZ_XLEN - 1;
|
||||
this->type = DICT_UNKNOWN;
|
||||
|
||||
id1 = getc( str );
|
||||
id2 = getc( str );
|
||||
|
||||
if (id1 != GZ_MAGIC1 || id2 != GZ_MAGIC2) {
|
||||
this->type = DICT_TEXT;
|
||||
fstat( fileno( str ), &sb );
|
||||
this->compressedLength = this->length = sb.st_size;
|
||||
this->origFilename = fname;
|
||||
this->mtime = sb.st_mtime;
|
||||
if (computeCRC) {
|
||||
rewind( str );
|
||||
while (!feof( str )) {
|
||||
if ((count = fread( buffer, 1, BUFFERSIZE, str ))) {
|
||||
crc = crc32(crc, (Bytef *)buffer, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
this->crc = crc;
|
||||
fclose( str );
|
||||
return 0;
|
||||
}
|
||||
this->type = DICT_GZIP;
|
||||
|
||||
this->method = getc( str );
|
||||
this->flags = getc( str );
|
||||
this->mtime = getc( str ) << 0;
|
||||
this->mtime |= getc( str ) << 8;
|
||||
this->mtime |= getc( str ) << 16;
|
||||
this->mtime |= getc( str ) << 24;
|
||||
this->extraFlags = getc( str );
|
||||
this->os = getc( str );
|
||||
|
||||
if (this->flags & GZ_FEXTRA) {
|
||||
extraLength = getc( str ) << 0;
|
||||
extraLength |= getc( str ) << 8;
|
||||
this->headerLength += extraLength + 2;
|
||||
si1 = getc( str );
|
||||
si2 = getc( str );
|
||||
|
||||
if (si1 == GZ_RND_S1 || si2 == GZ_RND_S2) {
|
||||
subLength = getc( str ) << 0;
|
||||
subLength |= getc( str ) << 8;
|
||||
this->version = getc( str ) << 0;
|
||||
this->version |= getc( str ) << 8;
|
||||
|
||||
if (this->version != 1) {
|
||||
//err_internal( __FUNCTION__,
|
||||
// "dzip header version %d not supported\n",
|
||||
// this->version );
|
||||
}
|
||||
|
||||
this->chunkLength = getc( str ) << 0;
|
||||
this->chunkLength |= getc( str ) << 8;
|
||||
this->chunkCount = getc( str ) << 0;
|
||||
this->chunkCount |= getc( str ) << 8;
|
||||
|
||||
if (this->chunkCount <= 0) {
|
||||
fclose( str );
|
||||
return 5;
|
||||
}
|
||||
this->chunks = (int *)malloc(sizeof( this->chunks[0] )
|
||||
* this->chunkCount );
|
||||
for (i = 0; i < this->chunkCount; i++) {
|
||||
this->chunks[i] = getc( str ) << 0;
|
||||
this->chunks[i] |= getc( str ) << 8;
|
||||
}
|
||||
this->type = DICT_DZIP;
|
||||
} else {
|
||||
fseek( str, this->headerLength, SEEK_SET );
|
||||
}
|
||||
}
|
||||
|
||||
if (this->flags & GZ_FNAME) { /* FIXME! Add checking against header len */
|
||||
pt = buffer;
|
||||
while ((c = getc( str )) && c != EOF)
|
||||
*pt++ = c;
|
||||
*pt = '\0';
|
||||
|
||||
this->origFilename = buffer;
|
||||
this->headerLength += this->origFilename.length() + 1;
|
||||
} else {
|
||||
this->origFilename = "";
|
||||
}
|
||||
|
||||
if (this->flags & GZ_COMMENT) { /* FIXME! Add checking for header len */
|
||||
pt = buffer;
|
||||
while ((c = getc( str )) && c != EOF)
|
||||
*pt++ = c;
|
||||
*pt = '\0';
|
||||
comment = buffer;
|
||||
headerLength += comment.length()+1;
|
||||
} else {
|
||||
comment = "";
|
||||
}
|
||||
|
||||
if (this->flags & GZ_FHCRC) {
|
||||
getc( str );
|
||||
getc( str );
|
||||
this->headerLength += 2;
|
||||
}
|
||||
|
||||
if (ftell( str ) != this->headerLength + 1) {
|
||||
//err_internal( __FUNCTION__,
|
||||
// "File position (%lu) != header length + 1 (%d)\n",
|
||||
// ftell( str ), this->headerLength + 1 );
|
||||
}
|
||||
|
||||
fseek( str, -8, SEEK_END );
|
||||
this->crc = getc( str ) << 0;
|
||||
this->crc |= getc( str ) << 8;
|
||||
this->crc |= getc( str ) << 16;
|
||||
this->crc |= getc( str ) << 24;
|
||||
this->length = getc( str ) << 0;
|
||||
this->length |= getc( str ) << 8;
|
||||
this->length |= getc( str ) << 16;
|
||||
this->length |= getc( str ) << 24;
|
||||
this->compressedLength = ftell( str );
|
||||
|
||||
/* Compute offsets */
|
||||
this->offsets = (unsigned long *)malloc( sizeof( this->offsets[0] )
|
||||
* this->chunkCount );
|
||||
for (offset = this->headerLength + 1, i = 0;
|
||||
i < this->chunkCount;
|
||||
i++) {
|
||||
this->offsets[i] = offset;
|
||||
offset += this->chunks[i];
|
||||
}
|
||||
|
||||
fclose( str );
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool dictData::open(const std::string& fname, int computeCRC)
|
||||
{
|
||||
struct stat sb;
|
||||
int j;
|
||||
int fd;
|
||||
|
||||
this->initialized = 0;
|
||||
|
||||
if (stat(fname.c_str(), &sb) || !S_ISREG(sb.st_mode)) {
|
||||
//err_warning( __FUNCTION__,
|
||||
// "%s is not a regular file -- ignoring\n", fname );
|
||||
return false;
|
||||
}
|
||||
|
||||
if (read_header(fname, computeCRC)) {
|
||||
//err_fatal( __FUNCTION__,
|
||||
// "\"%s\" not in text or dzip format\n", fname );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((fd = ::open(fname.c_str(), O_RDONLY )) < 0) {
|
||||
//err_fatal_errno( __FUNCTION__,
|
||||
// "Cannot open data file \"%s\"\n", fname );
|
||||
return false;
|
||||
}
|
||||
if (fstat(fd, &sb)) {
|
||||
//err_fatal_errno( __FUNCTION__,
|
||||
// "Cannot stat data file \"%s\"\n", fname );
|
||||
return false;
|
||||
}
|
||||
|
||||
this->size = sb.st_size;
|
||||
::close(fd);
|
||||
if (!mapfile.open(fname.c_str(), size))
|
||||
return false;
|
||||
|
||||
this->start=mapfile.begin();
|
||||
this->end = this->start + this->size;
|
||||
|
||||
for (j = 0; j < DICT_CACHE_SIZE; j++) {
|
||||
cache[j].chunk = -1;
|
||||
cache[j].stamp = -1;
|
||||
cache[j].inBuffer = NULL;
|
||||
cache[j].count = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void dictData::close()
|
||||
{
|
||||
int i;
|
||||
|
||||
if (this->chunks)
|
||||
free(this->chunks);
|
||||
if (this->offsets)
|
||||
free(this->offsets);
|
||||
|
||||
if (this->initialized) {
|
||||
if (inflateEnd( &this->zStream )) {
|
||||
//err_internal( __FUNCTION__,
|
||||
// "Cannot shut down inflation engine: %s\n",
|
||||
// this->zStream.msg );
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < DICT_CACHE_SIZE; ++i){
|
||||
if (this -> cache [i].inBuffer)
|
||||
free (this -> cache [i].inBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
void dictData::read(char *buffer, unsigned long start, unsigned long size)
|
||||
{
|
||||
char *pt;
|
||||
unsigned long end;
|
||||
int count;
|
||||
char *inBuffer;
|
||||
char outBuffer[OUT_BUFFER_SIZE];
|
||||
int firstChunk, lastChunk;
|
||||
int firstOffset, lastOffset;
|
||||
int i, j;
|
||||
int found, target, lastStamp;
|
||||
static int stamp = 0;
|
||||
|
||||
end = start + size;
|
||||
|
||||
//buffer = malloc( size + 1 );
|
||||
|
||||
//PRINTF(DBG_UNZIP,
|
||||
// ("dict_data_read( %p, %lu, %lu )\n",
|
||||
//h, start, size ));
|
||||
|
||||
|
||||
switch (this->type) {
|
||||
case DICT_GZIP:
|
||||
//err_fatal( __FUNCTION__,
|
||||
// "Cannot seek on pure gzip format files.\n"
|
||||
// "Use plain text (for performance)"
|
||||
// " or dzip format (for space savings).\n" );
|
||||
break;
|
||||
case DICT_TEXT:
|
||||
memcpy( buffer, this->start + start, size );
|
||||
//buffer[size] = '\0';
|
||||
break;
|
||||
case DICT_DZIP:
|
||||
if (!this->initialized) {
|
||||
++this->initialized;
|
||||
this->zStream.zalloc = NULL;
|
||||
this->zStream.zfree = NULL;
|
||||
this->zStream.opaque = NULL;
|
||||
this->zStream.next_in = 0;
|
||||
this->zStream.avail_in = 0;
|
||||
this->zStream.next_out = NULL;
|
||||
this->zStream.avail_out = 0;
|
||||
if (inflateInit2( &this->zStream, -15 ) != Z_OK) {
|
||||
//err_internal( __FUNCTION__,
|
||||
// "Cannot initialize inflation engine: %s\n",
|
||||
//this->zStream.msg );
|
||||
}
|
||||
}
|
||||
firstChunk = start / this->chunkLength;
|
||||
firstOffset = start - firstChunk * this->chunkLength;
|
||||
lastChunk = end / this->chunkLength;
|
||||
lastOffset = end - lastChunk * this->chunkLength;
|
||||
//PRINTF(DBG_UNZIP,
|
||||
// (" start = %lu, end = %lu\n"
|
||||
//"firstChunk = %d, firstOffset = %d,"
|
||||
//" lastChunk = %d, lastOffset = %d\n",
|
||||
//start, end, firstChunk, firstOffset, lastChunk, lastOffset ));
|
||||
for (pt = buffer, i = firstChunk; i <= lastChunk; i++) {
|
||||
|
||||
/* Access cache */
|
||||
found = 0;
|
||||
target = 0;
|
||||
lastStamp = INT_MAX;
|
||||
for (j = 0; j < DICT_CACHE_SIZE; j++) {
|
||||
#if USE_CACHE
|
||||
if (this->cache[j].chunk == i) {
|
||||
found = 1;
|
||||
target = j;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (this->cache[j].stamp < lastStamp) {
|
||||
lastStamp = this->cache[j].stamp;
|
||||
target = j;
|
||||
}
|
||||
}
|
||||
|
||||
this->cache[target].stamp = ++stamp;
|
||||
if (found) {
|
||||
count = this->cache[target].count;
|
||||
inBuffer = this->cache[target].inBuffer;
|
||||
} else {
|
||||
this->cache[target].chunk = i;
|
||||
if (!this->cache[target].inBuffer)
|
||||
this->cache[target].inBuffer = (char *)malloc( IN_BUFFER_SIZE );
|
||||
inBuffer = this->cache[target].inBuffer;
|
||||
|
||||
if (this->chunks[i] >= OUT_BUFFER_SIZE ) {
|
||||
//err_internal( __FUNCTION__,
|
||||
// "this->chunks[%d] = %d >= %ld (OUT_BUFFER_SIZE)\n",
|
||||
// i, this->chunks[i], OUT_BUFFER_SIZE );
|
||||
}
|
||||
memcpy( outBuffer, this->start + this->offsets[i], this->chunks[i] );
|
||||
|
||||
this->zStream.next_in = (Bytef *)outBuffer;
|
||||
this->zStream.avail_in = this->chunks[i];
|
||||
this->zStream.next_out = (Bytef *)inBuffer;
|
||||
this->zStream.avail_out = IN_BUFFER_SIZE;
|
||||
if (inflate( &this->zStream, Z_PARTIAL_FLUSH ) != Z_OK) {
|
||||
//err_fatal( __FUNCTION__, "inflate: %s\n", this->zStream.msg );
|
||||
}
|
||||
if (this->zStream.avail_in) {
|
||||
//err_internal( __FUNCTION__,
|
||||
// "inflate did not flush (%d pending, %d avail)\n",
|
||||
// this->zStream.avail_in, this->zStream.avail_out );
|
||||
}
|
||||
|
||||
count = IN_BUFFER_SIZE - this->zStream.avail_out;
|
||||
|
||||
this->cache[target].count = count;
|
||||
}
|
||||
|
||||
if (i == firstChunk) {
|
||||
if (i == lastChunk) {
|
||||
memcpy( pt, inBuffer + firstOffset, lastOffset-firstOffset);
|
||||
pt += lastOffset - firstOffset;
|
||||
} else {
|
||||
if (count != this->chunkLength ) {
|
||||
//err_internal( __FUNCTION__,
|
||||
// "Length = %d instead of %d\n",
|
||||
//count, this->chunkLength );
|
||||
}
|
||||
memcpy( pt, inBuffer + firstOffset,
|
||||
this->chunkLength - firstOffset );
|
||||
pt += this->chunkLength - firstOffset;
|
||||
}
|
||||
} else if (i == lastChunk) {
|
||||
memcpy( pt, inBuffer, lastOffset );
|
||||
pt += lastOffset;
|
||||
} else {
|
||||
assert( count == this->chunkLength );
|
||||
memcpy( pt, inBuffer, this->chunkLength );
|
||||
pt += this->chunkLength;
|
||||
}
|
||||
}
|
||||
//*pt = '\0';
|
||||
break;
|
||||
case DICT_UNKNOWN:
|
||||
//err_fatal( __FUNCTION__, "Cannot read unknown file type\n" );
|
||||
break;
|
||||
}
|
||||
}
|
||||
57
src/lib/dictziplib.hpp
Normal file
57
src/lib/dictziplib.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef __DICT_ZIP_LIB_H__
|
||||
#define __DICT_ZIP_LIB_H__
|
||||
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <zlib.h>
|
||||
|
||||
#include "mapfile.hpp"
|
||||
|
||||
|
||||
#define DICT_CACHE_SIZE 5
|
||||
|
||||
struct dictCache {
|
||||
int chunk;
|
||||
char *inBuffer;
|
||||
int stamp;
|
||||
int count;
|
||||
};
|
||||
|
||||
struct dictData {
|
||||
dictData() {}
|
||||
bool open(const std::string& filename, int computeCRC);
|
||||
void close();
|
||||
void read(char *buffer, unsigned long start, unsigned long size);
|
||||
~dictData() { close(); }
|
||||
private:
|
||||
const char *start; /* start of mmap'd area */
|
||||
const char *end; /* end of mmap'd area */
|
||||
unsigned long size; /* size of mmap */
|
||||
|
||||
int type;
|
||||
z_stream zStream;
|
||||
int initialized;
|
||||
|
||||
int headerLength;
|
||||
int method;
|
||||
int flags;
|
||||
time_t mtime;
|
||||
int extraFlags;
|
||||
int os;
|
||||
int version;
|
||||
int chunkLength;
|
||||
int chunkCount;
|
||||
int *chunks;
|
||||
unsigned long *offsets; /* Sum-scan of chunks. */
|
||||
std::string origFilename;
|
||||
std::string comment;
|
||||
unsigned long crc;
|
||||
unsigned long length;
|
||||
unsigned long compressedLength;
|
||||
dictCache cache[DICT_CACHE_SIZE];
|
||||
MapFile mapfile;
|
||||
|
||||
int read_header(const std::string &filename, int computeCRC);
|
||||
};
|
||||
|
||||
#endif//!__DICT_ZIP_LIB_H__
|
||||
203
src/lib/distance.cpp
Normal file
203
src/lib/distance.cpp
Normal file
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
writer : Opera Wang
|
||||
E-Mail : wangvisual AT sohu DOT com
|
||||
License: GPL
|
||||
*/
|
||||
|
||||
/* filename: distance.cc */
|
||||
/*
|
||||
http://www.merriampark.com/ld.htm
|
||||
What is Levenshtein Distance?
|
||||
|
||||
Levenshtein distance (LD) is a measure of the similarity between two strings,
|
||||
which we will refer to as the source string (s) and the target string (t).
|
||||
The distance is the number of deletions, insertions, or substitutions required
|
||||
to transform s into t. For example,
|
||||
|
||||
* If s is "test" and t is "test", then LD(s,t) = 0, because no transformations are needed.
|
||||
The strings are already identical.
|
||||
* If s is "test" and t is "tent", then LD(s,t) = 1, because one substitution
|
||||
(change "s" to "n") is sufficient to transform s into t.
|
||||
|
||||
The greater the Levenshtein distance, the more different the strings are.
|
||||
|
||||
Levenshtein distance is named after the Russian scientist Vladimir Levenshtein,
|
||||
who devised the algorithm in 1965. If you can't spell or pronounce Levenshtein,
|
||||
the metric is also sometimes called edit distance.
|
||||
|
||||
The Levenshtein distance algorithm has been used in:
|
||||
|
||||
* Spell checking
|
||||
* Speech recognition
|
||||
* DNA analysis
|
||||
* Plagiarism detection
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
//#include <stdio.h>
|
||||
|
||||
#include "distance.h"
|
||||
|
||||
#define OPTIMIZE_ED
|
||||
/*
|
||||
Cover transposition, in addition to deletion,
|
||||
insertion and substitution. This step is taken from:
|
||||
Berghel, Hal ; Roach, David : "An Extension of Ukkonen's
|
||||
Enhanced Dynamic Programming ASM Algorithm"
|
||||
(http://www.acm.org/~hlb/publications/asm/asm.html)
|
||||
*/
|
||||
#define COVER_TRANSPOSITION
|
||||
|
||||
/****************************************/
|
||||
/*Implementation of Levenshtein distance*/
|
||||
/****************************************/
|
||||
|
||||
EditDistance::EditDistance()
|
||||
{
|
||||
currentelements = 2500; // It's enough for most conditions :-)
|
||||
d = (int*)malloc(sizeof(int)*currentelements);
|
||||
}
|
||||
|
||||
EditDistance::~EditDistance()
|
||||
{
|
||||
// printf("size:%d\n",currentelements);
|
||||
if (d) free(d);
|
||||
}
|
||||
|
||||
#ifdef OPTIMIZE_ED
|
||||
int EditDistance::CalEditDistance(const gunichar *s,const gunichar *t,const int limit)
|
||||
/*Compute levenshtein distance between s and t, this is using QUICK algorithm*/
|
||||
{
|
||||
int n=0,m=0,iLenDif,k,i,j,cost;
|
||||
// Remove leftmost matching portion of strings
|
||||
while ( *s && (*s==*t) )
|
||||
{
|
||||
s++;
|
||||
t++;
|
||||
}
|
||||
|
||||
while (s[n])
|
||||
{
|
||||
n++;
|
||||
}
|
||||
while (t[m])
|
||||
{
|
||||
m++;
|
||||
}
|
||||
|
||||
// Remove rightmost matching portion of strings by decrement n and m.
|
||||
while ( n && m && (*(s+n-1)==*(t+m-1)) )
|
||||
{
|
||||
n--;m--;
|
||||
}
|
||||
if ( m==0 || n==0 || d==(int*)0 )
|
||||
return (m+n);
|
||||
if ( m < n )
|
||||
{
|
||||
const gunichar * temp = s;
|
||||
int itemp = n;
|
||||
s = t;
|
||||
t = temp;
|
||||
n = m;
|
||||
m = itemp;
|
||||
}
|
||||
iLenDif = m - n;
|
||||
if ( iLenDif >= limit )
|
||||
return iLenDif;
|
||||
// step 1
|
||||
n++;m++;
|
||||
// d=(int*)malloc(sizeof(int)*m*n);
|
||||
if ( m*n > currentelements )
|
||||
{
|
||||
currentelements = m*n*2; // double the request
|
||||
d = (int*)realloc(d,sizeof(int)*currentelements);
|
||||
if ( (int*)0 == d )
|
||||
return (m+n);
|
||||
}
|
||||
// step 2, init matrix
|
||||
for (k=0;k<n;k++)
|
||||
d[k] = k;
|
||||
for (k=1;k<m;k++)
|
||||
d[k*n] = k;
|
||||
// step 3
|
||||
for (i=1;i<n;i++)
|
||||
{
|
||||
// first calculate column, d(i,j)
|
||||
for ( j=1;j<iLenDif+i;j++ )
|
||||
{
|
||||
cost = s[i-1]==t[j-1]?0:1;
|
||||
d[j*n+i] = minimum(d[(j-1)*n+i]+1,d[j*n+i-1]+1,d[(j-1)*n+i-1]+cost);
|
||||
#ifdef COVER_TRANSPOSITION
|
||||
if ( i>=2 && j>=2 && (d[j*n+i]-d[(j-2)*n+i-2]==2)
|
||||
&& (s[i-2]==t[j-1]) && (s[i-1]==t[j-2]) )
|
||||
d[j*n+i]--;
|
||||
#endif
|
||||
}
|
||||
// second calculate row, d(k,j)
|
||||
// now j==iLenDif+i;
|
||||
for ( k=1;k<=i;k++ )
|
||||
{
|
||||
cost = s[k-1]==t[j-1]?0:1;
|
||||
d[j*n+k] = minimum(d[(j-1)*n+k]+1,d[j*n+k-1]+1,d[(j-1)*n+k-1]+cost);
|
||||
#ifdef COVER_TRANSPOSITION
|
||||
if ( k>=2 && j>=2 && (d[j*n+k]-d[(j-2)*n+k-2]==2)
|
||||
&& (s[k-2]==t[j-1]) && (s[k-1]==t[j-2]) )
|
||||
d[j*n+k]--;
|
||||
#endif
|
||||
}
|
||||
// test if d(i,j) limit gets equal or exceed
|
||||
if ( d[j*n+i] >= limit )
|
||||
{
|
||||
return d[j*n+i];
|
||||
}
|
||||
}
|
||||
// d(n-1,m-1)
|
||||
return d[n*m-1];
|
||||
}
|
||||
#else
|
||||
int EditDistance::CalEditDistance(const char *s,const char *t,const int limit)
|
||||
{
|
||||
//Step 1
|
||||
int k,i,j,n,m,cost;
|
||||
n=strlen(s);
|
||||
m=strlen(t);
|
||||
if( n!=0 && m!=0 && d!=(int*)0 )
|
||||
{
|
||||
m++;n++;
|
||||
if ( m*n > currentelements )
|
||||
{
|
||||
currentelements = m*n*2;
|
||||
d = (int*)realloc(d,sizeof(int)*currentelements);
|
||||
if ( (int*)0 == d )
|
||||
return (m+n);
|
||||
}
|
||||
//Step 2
|
||||
for(k=0;k<n;k++)
|
||||
d[k]=k;
|
||||
for(k=0;k<m;k++)
|
||||
d[k*n]=k;
|
||||
//Step 3 and 4
|
||||
for(i=1;i<n;i++)
|
||||
for(j=1;j<m;j++)
|
||||
{
|
||||
//Step 5
|
||||
if(s[i-1]==t[j-1])
|
||||
cost=0;
|
||||
else
|
||||
cost=1;
|
||||
//Step 6
|
||||
d[j*n+i]=minimum(d[(j-1)*n+i]+1,d[j*n+i-1]+1,d[(j-1)*n+i-1]+cost);
|
||||
#ifdef COVER_TRANSPOSITION
|
||||
if ( i>=2 && j>=2 && (d[j*n+i]-d[(j-2)*n+i-2]==2)
|
||||
&& (s[i-2]==t[j-1]) && (s[i-1]==t[j-2]) )
|
||||
d[j*n+i]--;
|
||||
#endif
|
||||
}
|
||||
return d[n*m-1];
|
||||
}
|
||||
else
|
||||
return (n+m);
|
||||
}
|
||||
#endif
|
||||
26
src/lib/distance.h
Normal file
26
src/lib/distance.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef DISTANCE_H
|
||||
#define DISTANCE_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
class EditDistance {
|
||||
private:
|
||||
int *d;
|
||||
int currentelements;
|
||||
/*Gets the minimum of three values */
|
||||
inline int minimum( const int a, const int b, const int c )
|
||||
{
|
||||
int min = a;
|
||||
if ( b < min )
|
||||
min = b;
|
||||
if ( c < min )
|
||||
min = c;
|
||||
return min;
|
||||
};
|
||||
public:
|
||||
EditDistance( );
|
||||
~EditDistance( );
|
||||
int CalEditDistance( const gunichar *s, const gunichar *t, const int limit );
|
||||
};
|
||||
|
||||
#endif
|
||||
53
src/lib/file.hpp
Normal file
53
src/lib/file.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef _FILE_HPP_
|
||||
#define _FILE_HPP_
|
||||
|
||||
#include <algorithm>
|
||||
#include <glib.h>
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
|
||||
typedef std::list<std::string> List;
|
||||
|
||||
template<typename Function>
|
||||
void __for_each_file(const std::string& dirname, const std::string& suff,
|
||||
const List& order_list, const List& disable_list,
|
||||
Function f)
|
||||
{
|
||||
GDir *dir = g_dir_open(dirname.c_str(), 0, NULL);
|
||||
if (dir) {
|
||||
const gchar *filename;
|
||||
|
||||
while ((filename = g_dir_read_name(dir))!=NULL) {
|
||||
std::string fullfilename(dirname+G_DIR_SEPARATOR_S+filename);
|
||||
if (g_file_test(fullfilename.c_str(), G_FILE_TEST_IS_DIR))
|
||||
__for_each_file(fullfilename, suff, order_list, disable_list, f);
|
||||
else if (g_str_has_suffix(filename, suff.c_str()) &&
|
||||
std::find(order_list.begin(), order_list.end(),
|
||||
fullfilename)==order_list.end()) {
|
||||
bool disable=std::find(disable_list.begin(),
|
||||
disable_list.end(),
|
||||
fullfilename)!=disable_list.end();
|
||||
f(fullfilename, disable);
|
||||
}
|
||||
}
|
||||
g_dir_close(dir);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Function>
|
||||
void for_each_file(const List& dirs_list, const std::string& suff,
|
||||
const List& order_list, const List& disable_list,
|
||||
Function f)
|
||||
{
|
||||
List::const_iterator it;
|
||||
for (it=order_list.begin(); it!=order_list.end(); ++it) {
|
||||
bool disable=std::find(disable_list.begin(), disable_list.end(),
|
||||
*it)!=disable_list.end();
|
||||
f(*it, disable);
|
||||
}
|
||||
for (it=dirs_list.begin(); it!=dirs_list.end(); ++it)
|
||||
__for_each_file(*it, suff, order_list, disable_list, f);
|
||||
}
|
||||
|
||||
#endif//!_FILE_HPP_
|
||||
1693
src/lib/lib.cpp
Normal file
1693
src/lib/lib.cpp
Normal file
File diff suppressed because it is too large
Load Diff
158
src/lib/lib.h
Normal file
158
src/lib/lib.h
Normal file
@@ -0,0 +1,158 @@
|
||||
#ifndef __SD_LIB_H__
|
||||
#define __SD_LIB_H__
|
||||
|
||||
#include <cstdio>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "dictziplib.hpp"
|
||||
|
||||
const int MAX_MATCH_ITEM_PER_LIB=100;
|
||||
const int MAX_FUZZY_DISTANCE= 3; // at most MAX_FUZZY_DISTANCE-1 differences allowed when find similar words
|
||||
|
||||
struct cacheItem {
|
||||
guint32 offset;
|
||||
gchar *data;
|
||||
//write code here to make it inline
|
||||
cacheItem() {data= NULL;}
|
||||
~cacheItem() {g_free(data);}
|
||||
};
|
||||
|
||||
const int WORDDATA_CACHE_NUM = 10;
|
||||
const int INVALID_INDEX=-100;
|
||||
|
||||
class DictBase {
|
||||
public:
|
||||
DictBase();
|
||||
~DictBase();
|
||||
gchar * GetWordData(guint32 idxitem_offset, guint32 idxitem_size);
|
||||
bool containSearchData();
|
||||
bool SearchData(std::vector<std::string> &SearchWords, guint32 idxitem_offset, guint32 idxitem_size, gchar *origin_data);
|
||||
protected:
|
||||
std::string sametypesequence;
|
||||
FILE *dictfile;
|
||||
std::auto_ptr<dictData> dictdzfile;
|
||||
private:
|
||||
cacheItem cache[WORDDATA_CACHE_NUM];
|
||||
gint cache_cur;
|
||||
};
|
||||
|
||||
//this structure contain all information about dictionary
|
||||
struct DictInfo {
|
||||
std::string ifo_file_name;
|
||||
guint32 wordcount;
|
||||
std::string bookname;
|
||||
std::string author;
|
||||
std::string email;
|
||||
std::string website;
|
||||
std::string date;
|
||||
std::string description;
|
||||
guint32 index_file_size;
|
||||
std::string sametypesequence;
|
||||
bool load_from_ifo_file(const std::string& ifofilename, bool istreedict);
|
||||
};
|
||||
|
||||
class index_file {
|
||||
public:
|
||||
guint32 wordentry_offset;
|
||||
guint32 wordentry_size;
|
||||
|
||||
virtual ~index_file() {}
|
||||
virtual bool load(const std::string& url, gulong wc, gulong fsize) = 0;
|
||||
virtual const gchar *get_key(glong idx) = 0;
|
||||
virtual void get_data(glong idx) = 0;
|
||||
virtual const gchar *get_key_and_data(glong idx) = 0;
|
||||
virtual bool lookup(const char *str, glong &idx) = 0;
|
||||
};
|
||||
|
||||
class Dict : public DictBase {
|
||||
private:
|
||||
std::string ifo_file_name;
|
||||
gulong wordcount;
|
||||
std::string bookname;
|
||||
|
||||
std::auto_ptr<index_file> idx_file;
|
||||
|
||||
bool load_ifofile(const std::string& ifofilename, gulong &idxfilesize);
|
||||
public:
|
||||
Dict() {}
|
||||
bool load(const std::string& ifofilename);
|
||||
|
||||
gulong narticles() { return wordcount; }
|
||||
const std::string& dict_name() { return bookname; }
|
||||
const std::string& ifofilename() { return ifo_file_name; }
|
||||
|
||||
const gchar *get_key(glong index) { return idx_file->get_key(index); }
|
||||
gchar *get_data(glong index)
|
||||
{
|
||||
idx_file->get_data(index);
|
||||
return DictBase::GetWordData(idx_file->wordentry_offset, idx_file->wordentry_size);
|
||||
}
|
||||
void get_key_and_data(glong index, const gchar **key, guint32 *offset, guint32 *size)
|
||||
{
|
||||
*key = idx_file->get_key_and_data(index);
|
||||
*offset = idx_file->wordentry_offset;
|
||||
*size = idx_file->wordentry_size;
|
||||
}
|
||||
bool Lookup(const char *str, glong &idx) { return idx_file->lookup(str, idx); }
|
||||
|
||||
bool LookupWithRule(GPatternSpec *pspec, glong *aIndex, int iBuffLen);
|
||||
};
|
||||
|
||||
typedef std::list<std::string> strlist_t;
|
||||
|
||||
class Libs {
|
||||
public:
|
||||
typedef void (*progress_func_t)(void);
|
||||
|
||||
Libs(progress_func_t f=NULL);
|
||||
~Libs();
|
||||
void load_dict(const std::string& url);
|
||||
void load(const strlist_t& dicts_dirs,
|
||||
const strlist_t& order_list,
|
||||
const strlist_t& disable_list);
|
||||
void reload(const strlist_t& dicts_dirs,
|
||||
const strlist_t& order_list,
|
||||
const strlist_t& disable_list);
|
||||
|
||||
glong narticles(int idict) { return oLib[idict]->narticles(); }
|
||||
const std::string& dict_name(int idict) { return oLib[idict]->dict_name(); }
|
||||
gint ndicts() { return oLib.size(); }
|
||||
|
||||
const gchar * poGetWord(glong iIndex,int iLib) {
|
||||
return oLib[iLib]->get_key(iIndex);
|
||||
}
|
||||
gchar * poGetWordData(glong iIndex,int iLib) {
|
||||
if (iIndex==INVALID_INDEX)
|
||||
return NULL;
|
||||
return oLib[iLib]->get_data(iIndex);
|
||||
}
|
||||
const gchar *poGetCurrentWord(glong *iCurrent);
|
||||
const gchar *poGetNextWord(const gchar *word, glong *iCurrent);
|
||||
const gchar *poGetPreWord(glong *iCurrent);
|
||||
bool LookupWord(const gchar* sWord, glong& iWordIndex, int iLib) {
|
||||
return oLib[iLib]->Lookup(sWord, iWordIndex);
|
||||
}
|
||||
bool LookupSimilarWord(const gchar* sWord, glong & iWordIndex, int iLib);
|
||||
bool SimpleLookupWord(const gchar* sWord, glong & iWordIndex, int iLib);
|
||||
|
||||
|
||||
bool LookupWithFuzzy(const gchar *sWord, gchar *reslist[], gint reslist_size);
|
||||
gint LookupWithRule(const gchar *sWord, gchar *reslist[]);
|
||||
bool LookupData(const gchar *sWord, std::vector<gchar *> *reslist);
|
||||
private:
|
||||
std::vector<Dict *> oLib; // word Libs.
|
||||
int iMaxFuzzyDistance;
|
||||
progress_func_t progress_func;
|
||||
};
|
||||
|
||||
|
||||
typedef enum {
|
||||
qtSIMPLE, qtREGEXP, qtFUZZY, qtDATA
|
||||
} query_t;
|
||||
|
||||
extern query_t analyze_query(const char *s, std::string& res);
|
||||
|
||||
#endif//!__SD_LIB_H__
|
||||
94
src/lib/mapfile.hpp
Normal file
94
src/lib/mapfile.hpp
Normal file
@@ -0,0 +1,94 @@
|
||||
#ifndef _MAPFILE_HPP_
|
||||
#define _MAPFILE_HPP_
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MMAP
|
||||
# include <sys/types.h>
|
||||
# include <fcntl.h>
|
||||
# include <sys/mman.h>
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
# include <windows.h>
|
||||
#endif
|
||||
#include <glib.h>
|
||||
|
||||
class MapFile {
|
||||
public:
|
||||
MapFile(void) :
|
||||
data(NULL),
|
||||
#ifdef HAVE_MMAP
|
||||
mmap_fd(-1)
|
||||
#elif defined(_WIN32)
|
||||
hFile(0),
|
||||
hFileMap(0)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
~MapFile();
|
||||
bool open(const char *file_name, unsigned long file_size);
|
||||
inline gchar *begin(void) { return data; }
|
||||
private:
|
||||
char *data;
|
||||
unsigned long size;
|
||||
#ifdef HAVE_MMAP
|
||||
int mmap_fd;
|
||||
#elif defined(_WIN32)
|
||||
HANDLE hFile;
|
||||
HANDLE hFileMap;
|
||||
#endif
|
||||
};
|
||||
|
||||
inline bool MapFile::open(const char *file_name, unsigned long file_size)
|
||||
{
|
||||
size=file_size;
|
||||
#ifdef HAVE_MMAP
|
||||
if ((mmap_fd = ::open(file_name, O_RDONLY)) < 0) {
|
||||
//g_print("Open file %s failed!\n",fullfilename);
|
||||
return false;
|
||||
}
|
||||
data = (gchar *)mmap( NULL, file_size, PROT_READ, MAP_SHARED, mmap_fd, 0);
|
||||
if ((void *)data == (void *)(-1)) {
|
||||
//g_print("mmap file %s failed!\n",idxfilename);
|
||||
data=NULL;
|
||||
return false;
|
||||
}
|
||||
#elif defined( _WIN32)
|
||||
hFile = CreateFile(file_name, GENERIC_READ, 0, NULL, OPEN_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL, 0);
|
||||
hFileMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0,
|
||||
file_size, NULL);
|
||||
data = (gchar *)MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, file_size);
|
||||
#else
|
||||
gsize read_len;
|
||||
if (!g_file_get_contents(file_name, &data, &read_len, NULL))
|
||||
return false;
|
||||
|
||||
if (read_len!=file_size)
|
||||
return false;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline MapFile::~MapFile()
|
||||
{
|
||||
if (!data)
|
||||
return;
|
||||
#ifdef HAVE_MMAP
|
||||
munmap(data, size);
|
||||
close(mmap_fd);
|
||||
#else
|
||||
# ifdef _WIN32
|
||||
UnmapViewOfFile(data);
|
||||
CloseHandle(hFileMap);
|
||||
CloseHandle(hFile);
|
||||
# else
|
||||
g_free(data);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif//!_MAPFILE_HPP_
|
||||
387
src/libwrapper.cpp
Normal file
387
src/libwrapper.cpp
Normal file
@@ -0,0 +1,387 @@
|
||||
/*
|
||||
* This file part of sdcv - console version of Stardict program
|
||||
* http://sdcv.sourceforge.net
|
||||
* Copyright (C) 2005-2006 Evgeniy <dushistov@mail.ru>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
#include <map>
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
#include "libwrapper.hpp"
|
||||
|
||||
|
||||
static std::string xdxf2text(const char *p)
|
||||
{
|
||||
std::string res;
|
||||
for (; *p; ++p) {
|
||||
if (*p!='<') {
|
||||
if (g_str_has_prefix(p, ">")) {
|
||||
res+=">";
|
||||
p+=3;
|
||||
} else if (g_str_has_prefix(p, "<")) {
|
||||
res+="<";
|
||||
p+=3;
|
||||
} else if (g_str_has_prefix(p, "&")) {
|
||||
res+="&";
|
||||
p+=4;
|
||||
} else if (g_str_has_prefix(p, """)) {
|
||||
res+="\"";
|
||||
p+=5;
|
||||
} else
|
||||
res+=*p;
|
||||
continue;
|
||||
}
|
||||
|
||||
const char *next=strchr(p, '>');
|
||||
if (!next)
|
||||
continue;
|
||||
|
||||
std::string name(p+1, next-p-1);
|
||||
|
||||
if (name=="abr")
|
||||
res+="";
|
||||
else if (name=="/abr")
|
||||
res+="";
|
||||
else if (name=="k") {
|
||||
const char *begin=next;
|
||||
if ((next=strstr(begin, "</k>"))!=NULL)
|
||||
next+=sizeof("</k>")-1-1;
|
||||
else
|
||||
next=begin;
|
||||
} else if (name=="b")
|
||||
res+="";
|
||||
else if (name=="/b")
|
||||
res+="";
|
||||
else if (name=="i")
|
||||
res+="";
|
||||
else if (name=="/i")
|
||||
res+="";
|
||||
else if (name=="tr")
|
||||
res+="[";
|
||||
else if (name=="/tr")
|
||||
res+="]";
|
||||
else if (name=="ex")
|
||||
res+="";
|
||||
else if (name=="/ex")
|
||||
res+="";
|
||||
else if (!name.empty() && name[0]=='c' && name!="co") {
|
||||
std::string::size_type pos=name.find("code");
|
||||
if (pos!=std::string::size_type(-1)) {
|
||||
pos+=sizeof("code=\"")-1;
|
||||
std::string::size_type end_pos=name.find("\"");
|
||||
std::string color(name, pos, end_pos-pos);
|
||||
res+="";
|
||||
} else {
|
||||
res+="";
|
||||
}
|
||||
} else if (name=="/c")
|
||||
res+="";
|
||||
|
||||
p=next;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static string parse_data(const gchar *data)
|
||||
{
|
||||
if (!data)
|
||||
return "";
|
||||
|
||||
string res;
|
||||
guint32 data_size, sec_size=0;
|
||||
gchar *m_str;
|
||||
const gchar *p=data;
|
||||
data_size=*((guint32 *)p);
|
||||
p+=sizeof(guint32);
|
||||
while (guint32(p - data)<data_size) {
|
||||
switch (*p++) {
|
||||
case 'm':
|
||||
case 'l': //need more work...
|
||||
case 'g':
|
||||
sec_size = strlen(p);
|
||||
if (sec_size) {
|
||||
res+="\n";
|
||||
m_str = g_strndup(p, sec_size);
|
||||
res += m_str;
|
||||
g_free(m_str);
|
||||
}
|
||||
sec_size++;
|
||||
break;
|
||||
case 'x':
|
||||
sec_size = strlen(p);
|
||||
if (sec_size) {
|
||||
res+="\n";
|
||||
m_str = g_strndup(p, sec_size);
|
||||
res += xdxf2text(m_str);
|
||||
g_free(m_str);
|
||||
}
|
||||
sec_size++;
|
||||
break;
|
||||
case 't':
|
||||
sec_size = strlen(p);
|
||||
if(sec_size){
|
||||
res+="\n";
|
||||
m_str = g_strndup(p, sec_size);
|
||||
res += "["+string(m_str)+"]";
|
||||
g_free(m_str);
|
||||
}
|
||||
sec_size++;
|
||||
break;
|
||||
case 'y':
|
||||
sec_size = strlen(p);
|
||||
sec_size++;
|
||||
break;
|
||||
case 'W':
|
||||
case 'P':
|
||||
sec_size=*((guint32 *)p);
|
||||
sec_size+=sizeof(guint32);
|
||||
break;
|
||||
}
|
||||
p += sec_size;
|
||||
}
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void Library::SimpleLookup(const string &str, TSearchResultList& res_list)
|
||||
{
|
||||
glong ind;
|
||||
res_list.reserve(ndicts());
|
||||
for (gint idict=0; idict<ndicts(); ++idict)
|
||||
if (SimpleLookupWord(str.c_str(), ind, idict))
|
||||
res_list.push_back(
|
||||
TSearchResult(dict_name(idict),
|
||||
poGetWord(ind, idict),
|
||||
parse_data(poGetWordData(ind, idict))));
|
||||
|
||||
}
|
||||
|
||||
void Library::LookupWithFuzzy(const string &str, TSearchResultList& res_list)
|
||||
{
|
||||
static const int MAXFUZZY=10;
|
||||
|
||||
gchar *fuzzy_res[MAXFUZZY];
|
||||
if (!Libs::LookupWithFuzzy(str.c_str(), fuzzy_res, MAXFUZZY))
|
||||
return;
|
||||
|
||||
for (gchar **p=fuzzy_res, **end=fuzzy_res+MAXFUZZY;
|
||||
p!=end && *p; ++p) {
|
||||
SimpleLookup(*p, res_list);
|
||||
g_free(*p);
|
||||
}
|
||||
}
|
||||
|
||||
void Library::LookupWithRule(const string &str, TSearchResultList& res_list)
|
||||
{
|
||||
std::vector<gchar *> match_res((MAX_MATCH_ITEM_PER_LIB) * ndicts());
|
||||
|
||||
gint nfound=Libs::LookupWithRule(str.c_str(), &match_res[0]);
|
||||
if (!nfound)
|
||||
return;
|
||||
|
||||
for (gint i=0; i<nfound; ++i) {
|
||||
SimpleLookup(match_res[i], res_list);
|
||||
g_free(match_res[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void Library::LookupData(const string &str, TSearchResultList& res_list)
|
||||
{
|
||||
std::vector<gchar *> drl[ndicts()];
|
||||
if (!Libs::LookupData(str.c_str(), drl))
|
||||
return;
|
||||
for (int idict=0; idict<ndicts(); ++idict)
|
||||
for (std::vector<gchar *>::size_type j=0; j<drl[idict].size(); ++j) {
|
||||
SimpleLookup(drl[idict][j], res_list);
|
||||
g_free(drl[idict][j]);
|
||||
}
|
||||
}
|
||||
|
||||
void Library::print_search_result(FILE *out, const TSearchResult & res)
|
||||
{
|
||||
string loc_bookname, loc_def, loc_exp;
|
||||
if(!utf8_output){
|
||||
loc_bookname=utf8_to_locale_ign_err(res.bookname);
|
||||
loc_def=utf8_to_locale_ign_err(res.def);
|
||||
loc_exp=utf8_to_locale_ign_err(res.exp);
|
||||
}
|
||||
|
||||
|
||||
fprintf(out, "-->%s\n-->%s\n%s\n\n",
|
||||
utf8_output ? res.bookname.c_str() : loc_bookname.c_str(),
|
||||
utf8_output ? res.def.c_str() : loc_def.c_str(),
|
||||
utf8_output ? res.exp.c_str() : loc_exp.c_str());
|
||||
}
|
||||
|
||||
class sdcv_pager {
|
||||
public:
|
||||
sdcv_pager(bool ignore_env=false) {
|
||||
output=stdout;
|
||||
if (ignore_env)
|
||||
return;
|
||||
const gchar *pager=g_getenv("SDCV_PAGER");
|
||||
if (pager && (output=popen(pager, "w"))==NULL) {
|
||||
perror(_("popen failed"));
|
||||
output=stdout;
|
||||
}
|
||||
}
|
||||
~sdcv_pager() {
|
||||
if (output!=stdout)
|
||||
fclose(output);
|
||||
}
|
||||
FILE *get_stream() { return output; }
|
||||
private:
|
||||
FILE *output;
|
||||
};
|
||||
|
||||
bool Library::process_phrase(const char *loc_str, read_line &io, bool force)
|
||||
{
|
||||
if (NULL==loc_str)
|
||||
return true;
|
||||
|
||||
std::string query;
|
||||
|
||||
|
||||
analyze_query(loc_str, query);
|
||||
if (!query.empty())
|
||||
io.add_to_history(query.c_str());
|
||||
|
||||
|
||||
|
||||
gsize bytes_read;
|
||||
gsize bytes_written;
|
||||
GError *err=NULL;
|
||||
char *str=NULL;
|
||||
if (!utf8_input)
|
||||
str=g_locale_to_utf8(loc_str, -1, &bytes_read, &bytes_written, &err);
|
||||
else
|
||||
str=g_strdup(loc_str);
|
||||
|
||||
if (NULL==str) {
|
||||
fprintf(stderr, _("Can not convert %s to utf8.\n"), loc_str);
|
||||
fprintf(stderr, "%s\n", err->message);
|
||||
g_error_free(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (str[0]=='\0')
|
||||
return true;
|
||||
|
||||
|
||||
TSearchResultList res_list;
|
||||
|
||||
|
||||
switch (analyze_query(str, query)) {
|
||||
case qtFUZZY:
|
||||
LookupWithFuzzy(query, res_list);
|
||||
break;
|
||||
case qtREGEXP:
|
||||
LookupWithRule(query, res_list);
|
||||
break;
|
||||
case qtSIMPLE:
|
||||
SimpleLookup(str, res_list);
|
||||
if (res_list.empty())
|
||||
LookupWithFuzzy(str, res_list);
|
||||
break;
|
||||
case qtDATA:
|
||||
LookupData(query, res_list);
|
||||
break;
|
||||
default:
|
||||
/*nothing*/;
|
||||
}
|
||||
|
||||
if (!res_list.empty()) {
|
||||
/* try to be more clever, if there are
|
||||
one or zero results per dictionary show all
|
||||
*/
|
||||
bool show_all_results=true;
|
||||
typedef std::map< string, int, std::less<string> > DictResMap;
|
||||
if (!force) {
|
||||
DictResMap res_per_dict;
|
||||
for(TSearchResultList::iterator ptr=res_list.begin(); ptr!=res_list.end(); ++ptr){
|
||||
std::pair<DictResMap::iterator, DictResMap::iterator> r =
|
||||
res_per_dict.equal_range(ptr->bookname);
|
||||
DictResMap tmp(r.first, r.second);
|
||||
if (tmp.empty()) //there are no yet such bookname in map
|
||||
res_per_dict.insert(DictResMap::value_type(ptr->bookname, 1));
|
||||
else {
|
||||
++((tmp.begin())->second);
|
||||
if (tmp.begin()->second>1) {
|
||||
show_all_results=false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}//if (!force)
|
||||
|
||||
if (!show_all_results && !force) {
|
||||
printf(_("Found %d items, similar to %s.\n"), res_list.size(),
|
||||
utf8_output ? str : utf8_to_locale_ign_err(str).c_str());
|
||||
for (size_t i=0; i<res_list.size(); ++i) {
|
||||
string loc_bookname, loc_def;
|
||||
loc_bookname=utf8_to_locale_ign_err(res_list[i].bookname);
|
||||
loc_def=utf8_to_locale_ign_err(res_list[i].def);
|
||||
printf("%d)%s-->%s\n", i,
|
||||
utf8_output ? res_list[i].bookname.c_str() : loc_bookname.c_str(),
|
||||
utf8_output ? res_list[i].def.c_str() : loc_def.c_str());
|
||||
}
|
||||
int choise;
|
||||
for (;;) {
|
||||
string str_choise;
|
||||
printf(_("Your choice[-1 to abort]: "));
|
||||
|
||||
if(!stdio_getline(stdin, str_choise)){
|
||||
putchar('\n');
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
sscanf(str_choise.c_str(), "%d", &choise);
|
||||
if (choise>=0 && choise<int(res_list.size())) {
|
||||
sdcv_pager pager;
|
||||
print_search_result(pager.get_stream(), res_list[choise]);
|
||||
break;
|
||||
} else if (choise==-1)
|
||||
break;
|
||||
else
|
||||
printf(_("Invalid choise.\nIt must be from 0 to %d or -1.\n"),
|
||||
res_list.size()-1);
|
||||
}
|
||||
} else {
|
||||
sdcv_pager pager(force);
|
||||
fprintf(pager.get_stream(), _("Found %d items, similar to %s.\n"),
|
||||
res_list.size(), utf8_output ? str : utf8_to_locale_ign_err(str).c_str());
|
||||
for (PSearchResult ptr=res_list.begin(); ptr!=res_list.end(); ++ptr)
|
||||
print_search_result(pager.get_stream(), *ptr);
|
||||
}
|
||||
|
||||
} else {
|
||||
string loc_str;
|
||||
if (!utf8_output)
|
||||
loc_str=utf8_to_locale_ign_err(str);
|
||||
|
||||
printf(_("Nothing similar to %s, sorry :(\n"), utf8_output ? str : loc_str.c_str());
|
||||
}
|
||||
g_free(str);
|
||||
|
||||
return true;
|
||||
}
|
||||
48
src/libwrapper.hpp
Normal file
48
src/libwrapper.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef _LIBWRAPPER_HPP_
|
||||
#define _LIBWRAPPER_HPP_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "file.hpp"
|
||||
#include "lib.h"
|
||||
#include "readline.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
//this structure is wrapper and it need for unification
|
||||
//results of search whith return Dicts class
|
||||
struct TSearchResult {
|
||||
string bookname;
|
||||
string def;
|
||||
string exp;
|
||||
|
||||
TSearchResult(const string& bookname_, const string& def_, const string& exp_)
|
||||
: bookname(bookname_), def(def_), exp(exp_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
typedef vector<TSearchResult> TSearchResultList;
|
||||
typedef TSearchResultList::iterator PSearchResult;
|
||||
|
||||
//this class is wrapper around Dicts class for easy use
|
||||
//of it
|
||||
class Library : public Libs {
|
||||
public:
|
||||
Library(bool uinput, bool uoutput) :
|
||||
utf8_input(uinput), utf8_output(uoutput) {}
|
||||
|
||||
bool process_phrase(const char *loc_str, read_line &io, bool force=false);
|
||||
private:
|
||||
bool utf8_input, utf8_output;
|
||||
|
||||
void SimpleLookup(const string &str, TSearchResultList& res_list);
|
||||
void LookupWithFuzzy(const string &str, TSearchResultList& res_list);
|
||||
void LookupWithRule(const string &str, TSearchResultList& res_lsit);
|
||||
void LookupData(const string &str, TSearchResultList& res_list);
|
||||
void print_search_result(FILE *out, const TSearchResult & res);
|
||||
};
|
||||
|
||||
#endif//!_LIBWRAPPER_HPP_
|
||||
89
src/readline.cpp
Normal file
89
src/readline.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* This file part of sdcv - console version of Stardict program
|
||||
* http://sdcv.sourceforge.net
|
||||
* Copyright (C) 2005 Evgeniy <dushistov@mail.ru>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <cstdio>
|
||||
#ifdef WITH_READLINE
|
||||
# include <readline/readline.h>
|
||||
# include <readline/history.h>
|
||||
#endif
|
||||
#include <glib.h>
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
#include "readline.hpp"
|
||||
|
||||
#ifndef WITH_READLINE
|
||||
|
||||
class dummy_readline : public read_line {
|
||||
public:
|
||||
bool read(const string& banner, string& line) {
|
||||
printf(banner.c_str());
|
||||
return stdio_getline(stdin, line);
|
||||
}
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
class real_readline : public read_line {
|
||||
public:
|
||||
real_readline()
|
||||
{
|
||||
using_history();
|
||||
string histname=(string(g_get_home_dir())+G_DIR_SEPARATOR+".sdcv_history");
|
||||
read_history(histname.c_str());;
|
||||
}
|
||||
~real_readline()
|
||||
{
|
||||
string histname=(string(g_get_home_dir())+G_DIR_SEPARATOR+".sdcv_history");
|
||||
write_history(histname.c_str());
|
||||
const gchar *hist_size_str=g_getenv("SDCV_HISTSIZE");
|
||||
int hist_size;
|
||||
if (!hist_size_str || sscanf(hist_size_str, "%d", &hist_size)<1)
|
||||
hist_size=2000;
|
||||
history_truncate_file(histname.c_str(), hist_size);
|
||||
}
|
||||
bool read(const string &banner, string& line)
|
||||
{
|
||||
char *phrase=NULL;
|
||||
phrase=readline(banner.c_str());
|
||||
if (phrase) {
|
||||
line=phrase;
|
||||
free(phrase);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void add_to_history(const std::string& phrase) { add_history(phrase.c_str()); }
|
||||
};
|
||||
|
||||
#endif//WITH_READLINE
|
||||
|
||||
read_line *create_readline_object()
|
||||
{
|
||||
#ifdef WITH_READLINE
|
||||
return new real_readline;
|
||||
#else
|
||||
return new dummy_readline;
|
||||
#endif
|
||||
}
|
||||
16
src/readline.hpp
Normal file
16
src/readline.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef _READLINE_HPP_
|
||||
#define _READLINE_HPP_
|
||||
|
||||
#include <string>
|
||||
using std::string;
|
||||
|
||||
class read_line {
|
||||
public:
|
||||
virtual ~read_line() {}
|
||||
virtual bool read(const string &banner, string& line)=0;
|
||||
virtual void add_to_history(const std::string& phrase) {}
|
||||
};
|
||||
|
||||
extern read_line *create_readline_object();
|
||||
|
||||
#endif//!_READLINE_HPP_
|
||||
220
src/sdcv.cpp
Normal file
220
src/sdcv.cpp
Normal file
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* This file part of sdcv - console version of Stardict program
|
||||
* http://sdcv.sourceforge.net
|
||||
* Copyright (C) 2003-2006 Evgeniy <dushistov@mail.ru>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <clocale>
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <getopt.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "libwrapper.hpp"
|
||||
#include "readline.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
const char gVersion[] = VERSION;
|
||||
|
||||
|
||||
struct option longopts[] ={
|
||||
{"version", no_argument, NULL, 'v' },
|
||||
{"help", no_argument, NULL, 'h' },
|
||||
{"list-dicts", no_argument, NULL, 'l'},
|
||||
{"use-dict", required_argument, NULL, 'u'},
|
||||
{"non-interactive", no_argument, NULL, 'n'},
|
||||
{"utf8-output", no_argument, NULL, 0},
|
||||
{"utf8-input", no_argument, NULL, 1},
|
||||
{"data-dir", required_argument, NULL, 2},
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
struct PrintDictInfo {
|
||||
void operator()(const std::string& filename, bool) {
|
||||
DictInfo dict_info;
|
||||
if (dict_info.load_from_ifo_file(filename, false)) {
|
||||
string bookname=utf8_to_locale_ign_err(dict_info.bookname);
|
||||
printf("%s %d\n", bookname.c_str(), dict_info.wordcount);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct CreateDisableList {
|
||||
CreateDisableList(const strlist_t& enable_list_, strlist_t& disable_list_) :
|
||||
enable_list(enable_list_), disable_list(disable_list_)
|
||||
{}
|
||||
void operator()(const std::string& filename, bool) {
|
||||
DictInfo dict_info;
|
||||
if (dict_info.load_from_ifo_file(filename, false) &&
|
||||
std::find(enable_list.begin(), enable_list.end(),
|
||||
dict_info.bookname)==enable_list.end())
|
||||
disable_list.push_back(dict_info.ifo_file_name);
|
||||
}
|
||||
private:
|
||||
const strlist_t& enable_list;
|
||||
strlist_t& disable_list;
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
setlocale(LC_ALL, "");
|
||||
#if ENABLE_NLS
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
#endif
|
||||
int optc;
|
||||
bool h = false, v = false, show_list_dicts=false,
|
||||
use_book_name=false, non_interactive=false,
|
||||
utf8_output=false, utf8_input=false;
|
||||
strlist_t enable_list;
|
||||
string data_dir;
|
||||
int option_index = 0;
|
||||
while ((optc = getopt_long (argc, argv, "hvu:ln", longopts,
|
||||
&option_index))!=-1)
|
||||
switch (optc){
|
||||
case 0:
|
||||
utf8_output=true;
|
||||
break;
|
||||
case 1:
|
||||
utf8_input=true;
|
||||
break;
|
||||
case 2:
|
||||
data_dir=optarg;
|
||||
break;
|
||||
case 'v':
|
||||
v = true;
|
||||
break;
|
||||
case 'h':
|
||||
h = true;
|
||||
break;
|
||||
case 'l':
|
||||
show_list_dicts=true;
|
||||
break;
|
||||
case 'u':
|
||||
use_book_name=true;
|
||||
enable_list.push_back(locale_to_utf8(optarg));
|
||||
break;
|
||||
case 'n':
|
||||
non_interactive=true;
|
||||
break;
|
||||
case '?':
|
||||
fprintf(stderr,
|
||||
_("Unknown option.\nTry '%s --help' for more information.\n"),
|
||||
argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (h) {
|
||||
printf("sdcv - console version of StarDict.\n");
|
||||
printf(_("Usage: %s [OPTIONS] words\n"), argv[0]);
|
||||
printf(_("-h, --help display this help and exit\n"));
|
||||
printf(_("-v, --version display version information and exit\n"));
|
||||
printf(_("-l, --list-dicts display list of available dictionaries and exit\n"));
|
||||
printf(_("-u, --use-dict bookname for search use only dictionary with this bookname\n"));
|
||||
printf(_("-n, --non-interactive for use in scripts\n"));
|
||||
printf(_("--utf8-output output must be in utf8\n"));
|
||||
printf(_("--utf8-input input of sdcv in utf8\n"));
|
||||
printf(_("--data-dir path/to/dir use this directory as path to stardict data directory\n"));
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if (v) {
|
||||
printf(_("Console version of Stardict, version %s\n"), gVersion);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
const gchar *stardict_data_dir=g_getenv("STARDICT_DATA_DIR");
|
||||
if (data_dir.empty()) {
|
||||
if (stardict_data_dir)
|
||||
data_dir=stardict_data_dir;
|
||||
else
|
||||
data_dir="/usr/share/stardict/dic";
|
||||
}
|
||||
|
||||
|
||||
|
||||
strlist_t dicts_dir_list;
|
||||
|
||||
dicts_dir_list.push_back(std::string(g_get_home_dir())+G_DIR_SEPARATOR+
|
||||
".stardict"+G_DIR_SEPARATOR+"dic");
|
||||
dicts_dir_list.push_back(data_dir);
|
||||
|
||||
if (show_list_dicts) {
|
||||
printf(_("Dictionary's name Word count\n"));
|
||||
PrintDictInfo print_dict_info;
|
||||
strlist_t order_list, disable_list;
|
||||
for_each_file(dicts_dir_list, ".ifo", order_list,
|
||||
disable_list, print_dict_info);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
strlist_t disable_list;
|
||||
//DictInfoList dict_info_list;
|
||||
|
||||
if (use_book_name) {
|
||||
strlist_t empty_list;
|
||||
CreateDisableList create_disable_list(enable_list, disable_list);
|
||||
for_each_file(dicts_dir_list, ".ifo", empty_list,
|
||||
empty_list, create_disable_list);
|
||||
}
|
||||
|
||||
|
||||
string conf_dir = string(g_get_home_dir())+G_DIR_SEPARATOR+".stardict";
|
||||
if (g_mkdir(conf_dir.c_str(), S_IRWXU)==-1 && errno!=EEXIST)
|
||||
fprintf(stderr, _("g_mkdir failed: %s\n"), strerror(errno));
|
||||
|
||||
|
||||
Library lib(utf8_input, utf8_output);
|
||||
strlist_t empty_list;
|
||||
lib.load(dicts_dir_list, empty_list, disable_list);
|
||||
|
||||
|
||||
std::auto_ptr<read_line> io(create_readline_object());
|
||||
if (optind < argc) {
|
||||
for(int i=optind; i<argc; ++i)
|
||||
if (!lib.process_phrase(argv[i], *io, non_interactive))
|
||||
return EXIT_FAILURE;
|
||||
} else if (!non_interactive) {
|
||||
|
||||
string phrase;
|
||||
while (io->read(_("Enter word or phrase: "), phrase)) {
|
||||
if (!lib.process_phrase(phrase.c_str(), *io))
|
||||
return EXIT_FAILURE;
|
||||
phrase.clear();
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
} else
|
||||
fprintf(stderr, _("There are no words/phrases to translate.\n"));
|
||||
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
84
src/utils.cpp
Normal file
84
src/utils.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* This file part of sdcv - console version of Stardict program
|
||||
* http://sdcv.sourceforge.net
|
||||
* Copyright (C) 2005-2006 Evgeniy <dushistov@mail.ru>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
bool stdio_getline(FILE *in, string & str)
|
||||
{
|
||||
str.clear();
|
||||
int ch;
|
||||
while((ch=fgetc(in))!=EOF && ch!='\n')
|
||||
str+=ch;
|
||||
if(EOF==ch)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
string utf8_to_locale_ign_err(const string& utf8_str)
|
||||
{
|
||||
gsize bytes_read, bytes_written;
|
||||
GError *err=NULL;
|
||||
string res;
|
||||
|
||||
const char * charset;
|
||||
if (g_get_charset(&charset))
|
||||
res=utf8_str;
|
||||
else {
|
||||
gchar *tmp=g_convert_with_fallback(utf8_str.c_str(), -1, charset, "UTF-8", NULL,
|
||||
&bytes_read, &bytes_written, &err);
|
||||
if (NULL==tmp){
|
||||
fprintf(stderr, _("Can not convert %s to current locale.\n"), utf8_str.c_str());
|
||||
fprintf(stderr, "%s\n", err->message);
|
||||
g_error_free(err);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
res=tmp;
|
||||
g_free(tmp);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
char *locale_to_utf8(const char *loc_str)
|
||||
{
|
||||
if(NULL==loc_str)
|
||||
return NULL;
|
||||
gsize bytes_read;
|
||||
gsize bytes_written;
|
||||
GError *err=NULL;
|
||||
gchar *str=NULL;
|
||||
str=g_locale_to_utf8(loc_str, -1, &bytes_read, &bytes_written, &err);
|
||||
if(NULL==str){
|
||||
fprintf(stderr, _("Can not convert %s to utf8.\n"), loc_str);
|
||||
fprintf(stderr, "%s\n", err->message);
|
||||
g_error_free(err);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
11
src/utils.hpp
Normal file
11
src/utils.hpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef _UTILS_HPP_
|
||||
#define _UTILS_HPP_
|
||||
|
||||
#include <string>
|
||||
using std::string;
|
||||
|
||||
extern bool stdio_getline(FILE *in, string &str);
|
||||
extern char *locale_to_utf8(const char *locstr);
|
||||
extern string utf8_to_locale_ign_err(const string& utf8_str);
|
||||
|
||||
#endif//!_UTILS_HPP_
|
||||
Reference in New Issue
Block a user