mirror of
https://github.com/Dushistov/sdcv.git
synced 2025-12-16 18:01:54 +00:00
get rid of getopt, because of it cause problem on mac os x.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
dnl Process this file with autoconf to produce a configure script.
|
dnl Process this file with autoconf to produce a configure script.
|
||||||
AC_PREREQ(2.52)
|
AC_PREREQ(2.52)
|
||||||
|
|
||||||
AC_INIT(sdcv, 0.4.2, dushistov@mail.ru)
|
AC_INIT(sdcv, 0.4.3, dushistov@mail.ru)
|
||||||
AC_CONFIG_SRCDIR(src/sdcv.cpp)
|
AC_CONFIG_SRCDIR(src/sdcv.cpp)
|
||||||
|
|
||||||
dnl Don't include maintainer make-rules by default
|
dnl Don't include maintainer make-rules by default
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
SUBDIRS=lib
|
SUBDIRS=lib
|
||||||
bin_PROGRAMS = sdcv
|
bin_PROGRAMS = sdcv
|
||||||
sdcv_SOURCES = \
|
sdcv_SOURCES = \
|
||||||
sdcv.cpp getopt.c getopt1.c getopt.h \
|
sdcv.cpp \
|
||||||
libwrapper.cpp libwrapper.hpp \
|
libwrapper.cpp libwrapper.hpp \
|
||||||
readline.cpp readline.hpp \
|
readline.cpp readline.hpp \
|
||||||
utils.cpp utils.hpp
|
utils.cpp utils.hpp
|
||||||
|
|||||||
1067
src/getopt.c
1067
src/getopt.c
File diff suppressed because it is too large
Load Diff
179
src/getopt.h
179
src/getopt.h
@@ -1,179 +0,0 @@
|
|||||||
/* 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
187
src/getopt1.c
@@ -1,187 +0,0 @@
|
|||||||
/* 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 */
|
|
||||||
@@ -220,7 +220,7 @@ void Library::LookupData(const string &str, TSearchResultList& res_list)
|
|||||||
|
|
||||||
void Library::print_search_result(FILE *out, const TSearchResult & res)
|
void Library::print_search_result(FILE *out, const TSearchResult & res)
|
||||||
{
|
{
|
||||||
string loc_bookname, loc_def, loc_exp;
|
std::string loc_bookname, loc_def, loc_exp;
|
||||||
if(!utf8_output){
|
if(!utf8_output){
|
||||||
loc_bookname=utf8_to_locale_ign_err(res.bookname);
|
loc_bookname=utf8_to_locale_ign_err(res.bookname);
|
||||||
loc_def=utf8_to_locale_ign_err(res.def);
|
loc_def=utf8_to_locale_ign_err(res.def);
|
||||||
@@ -375,7 +375,7 @@ bool Library::process_phrase(const char *loc_str, read_line &io, bool force)
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
string loc_str;
|
std::string loc_str;
|
||||||
if (!utf8_output)
|
if (!utf8_output)
|
||||||
loc_str=utf8_to_locale_ign_err(str);
|
loc_str=utf8_to_locale_ign_err(str);
|
||||||
|
|
||||||
|
|||||||
156
src/sdcv.cpp
156
src/sdcv.cpp
@@ -30,7 +30,6 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
#include <glib/gstdio.h>
|
#include <glib/gstdio.h>
|
||||||
#include <getopt.h>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -39,20 +38,7 @@
|
|||||||
#include "readline.hpp"
|
#include "readline.hpp"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
|
||||||
const char gVersion[] = VERSION;
|
static 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 {
|
struct PrintDictInfo {
|
||||||
void operator()(const std::string& filename, bool) {
|
void operator()(const std::string& filename, bool) {
|
||||||
@@ -65,9 +51,15 @@ struct PrintDictInfo {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct CreateDisableList {
|
struct CreateDisableList {
|
||||||
CreateDisableList(const strlist_t& enable_list_, strlist_t& disable_list_) :
|
CreateDisableList(gchar **use_dist_list, strlist_t& disable_list_) :
|
||||||
enable_list(enable_list_), disable_list(disable_list_)
|
disable_list(disable_list_)
|
||||||
{}
|
{
|
||||||
|
gchar **p = use_dist_list;
|
||||||
|
while (*p) {
|
||||||
|
enable_list.push_back(*p);
|
||||||
|
++p;
|
||||||
|
}
|
||||||
|
}
|
||||||
void operator()(const std::string& filename, bool) {
|
void operator()(const std::string& filename, bool) {
|
||||||
DictInfo dict_info;
|
DictInfo dict_info;
|
||||||
if (dict_info.load_from_ifo_file(filename, false) &&
|
if (dict_info.load_from_ifo_file(filename, false) &&
|
||||||
@@ -76,10 +68,24 @@ struct CreateDisableList {
|
|||||||
disable_list.push_back(dict_info.ifo_file_name);
|
disable_list.push_back(dict_info.ifo_file_name);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
const strlist_t& enable_list;
|
strlist_t enable_list;
|
||||||
strlist_t& disable_list;
|
strlist_t& disable_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
void free_str_array(gchar **arr)
|
||||||
|
{
|
||||||
|
gchar **p;
|
||||||
|
|
||||||
|
for (p = arr; *p; ++p)
|
||||||
|
g_free(*p);
|
||||||
|
g_free(arr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
namespace glib {
|
||||||
|
typedef ResourceWrapper<gchar *, gchar *, free_str_array> StrArr;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
@@ -87,74 +93,64 @@ int main(int argc, char *argv[])
|
|||||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||||
textdomain (PACKAGE);
|
textdomain (PACKAGE);
|
||||||
#endif
|
#endif
|
||||||
int optc;
|
|
||||||
bool h = false, v = false, show_list_dicts=false,
|
gboolean show_version = FALSE;
|
||||||
use_book_name=false, non_interactive=false,
|
gboolean show_list_dicts = FALSE;
|
||||||
utf8_output=false, utf8_input=false;
|
glib::StrArr use_dict_list;
|
||||||
strlist_t enable_list;
|
gboolean non_interactive = FALSE;
|
||||||
string data_dir;
|
gboolean utf8_output = FALSE;
|
||||||
int option_index = 0;
|
gboolean utf8_input = FALSE;
|
||||||
while ((optc = getopt_long (argc, argv, "hvu:ln", longopts,
|
glib::CharStr opt_data_dir;
|
||||||
&option_index))!=-1)
|
|
||||||
switch (optc){
|
GOptionEntry entries[] = {
|
||||||
case 0:
|
{"version", 'v', 0, G_OPTION_ARG_NONE, &show_version,
|
||||||
utf8_output=true;
|
_("display version information and exit"), NULL },
|
||||||
break;
|
{"list-dicts", 'l', 0, G_OPTION_ARG_NONE, &show_list_dicts,
|
||||||
case 1:
|
_("display list of available dictionaries and exit"), NULL},
|
||||||
utf8_input=true;
|
{"use-dict", 'u', 0, G_OPTION_ARG_STRING_ARRAY, get_addr(use_dict_list),
|
||||||
break;
|
_("for search use only dictionary with this bookname"),
|
||||||
case 2:
|
_("bookname")},
|
||||||
data_dir=optarg;
|
{"non-interactive", 'n', 0, G_OPTION_ARG_NONE, &non_interactive,
|
||||||
break;
|
_("for use in scripts"), NULL},
|
||||||
case 'v':
|
{"utf8-output", '0', 0, G_OPTION_ARG_NONE, &utf8_output,
|
||||||
v = true;
|
_("output must be in utf8"), NULL},
|
||||||
break;
|
{"utf8-input", '1', 0, G_OPTION_ARG_NONE, &utf8_input,
|
||||||
case 'h':
|
_("input of sdcv in utf8"), NULL},
|
||||||
h = true;
|
{"data-dir", '2', 0, G_OPTION_ARG_STRING, get_addr(opt_data_dir),
|
||||||
break;
|
_("use this directory as path to stardict data directory"),
|
||||||
case 'l':
|
_("path/to/dir")},
|
||||||
show_list_dicts=true;
|
{ NULL },
|
||||||
break;
|
};
|
||||||
case 'u':
|
|
||||||
use_book_name=true;
|
glib::Error error;
|
||||||
enable_list.push_back(locale_to_utf8(optarg));
|
GOptionContext *context;
|
||||||
break;
|
|
||||||
case 'n':
|
context = g_option_context_new(_(" words"));
|
||||||
non_interactive=true;
|
g_option_context_set_help_enabled(context, TRUE);
|
||||||
break;
|
g_option_context_add_main_entries(context, entries, NULL);
|
||||||
case '?':
|
gboolean parse_res = g_option_context_parse(context, &argc, &argv, get_addr(error));
|
||||||
fprintf(stderr,
|
g_option_context_free(context);
|
||||||
_("Unknown option.\nTry '%s --help' for more information.\n"),
|
if (!parse_res) {
|
||||||
argv[0]);
|
fprintf(stderr, _("Invalid command line arguments: %s\n"),
|
||||||
|
error->message);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (h) {
|
if (show_version) {
|
||||||
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);
|
printf(_("Console version of Stardict, version %s\n"), gVersion);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
const gchar *stardict_data_dir=g_getenv("STARDICT_DATA_DIR");
|
|
||||||
if (data_dir.empty()) {
|
const gchar *stardict_data_dir = g_getenv("STARDICT_DATA_DIR");
|
||||||
|
std::string data_dir;
|
||||||
|
if (!opt_data_dir) {
|
||||||
if (stardict_data_dir)
|
if (stardict_data_dir)
|
||||||
data_dir=stardict_data_dir;
|
data_dir = stardict_data_dir;
|
||||||
else
|
else
|
||||||
data_dir="/usr/share/stardict/dic";
|
data_dir = "/usr/share/stardict/dic";
|
||||||
|
} else {
|
||||||
|
data_dir = get_impl(opt_data_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -178,9 +174,9 @@ int main(int argc, char *argv[])
|
|||||||
strlist_t disable_list;
|
strlist_t disable_list;
|
||||||
//DictInfoList dict_info_list;
|
//DictInfoList dict_info_list;
|
||||||
|
|
||||||
if (use_book_name) {
|
if (use_dict_list) {
|
||||||
strlist_t empty_list;
|
strlist_t empty_list;
|
||||||
CreateDisableList create_disable_list(enable_list, disable_list);
|
CreateDisableList create_disable_list(get_impl(use_dict_list), disable_list);
|
||||||
for_each_file(dicts_dir_list, ".ifo", empty_list,
|
for_each_file(dicts_dir_list, ".ifo", empty_list,
|
||||||
empty_list, create_disable_list);
|
empty_list, create_disable_list);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
|
||||||
bool stdio_getline(FILE *in, string & str)
|
bool stdio_getline(FILE *in, std::string & str)
|
||||||
{
|
{
|
||||||
str.clear();
|
str.clear();
|
||||||
int ch;
|
int ch;
|
||||||
@@ -38,11 +38,11 @@ bool stdio_getline(FILE *in, string & str)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
string utf8_to_locale_ign_err(const string& utf8_str)
|
std::string utf8_to_locale_ign_err(const std::string& utf8_str)
|
||||||
{
|
{
|
||||||
gsize bytes_read, bytes_written;
|
gsize bytes_read, bytes_written;
|
||||||
GError *err=NULL;
|
GError *err=NULL;
|
||||||
string res;
|
std::string res;
|
||||||
|
|
||||||
const char * charset;
|
const char * charset;
|
||||||
if (g_get_charset(&charset))
|
if (g_get_charset(&charset))
|
||||||
|
|||||||
@@ -1,11 +1,60 @@
|
|||||||
#ifndef _UTILS_HPP_
|
#ifndef _UTILS_HPP_
|
||||||
#define _UTILS_HPP_
|
#define _UTILS_HPP_
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
using std::string;
|
|
||||||
|
|
||||||
extern bool stdio_getline(FILE *in, string &str);
|
template <typename T, typename unref_res_t, void (*unref_res)(unref_res_t *)>
|
||||||
|
class ResourceWrapper {
|
||||||
|
public:
|
||||||
|
ResourceWrapper(T *p = NULL) : p_(p) {}
|
||||||
|
~ResourceWrapper() { free_resource(); }
|
||||||
|
T *operator->() const { return p_; }
|
||||||
|
bool operator!() const { return p_ == NULL; }
|
||||||
|
|
||||||
|
void reset(T *newp) {
|
||||||
|
if (p_ != newp) {
|
||||||
|
free_resource();
|
||||||
|
p_ = newp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
friend inline T *get_impl(const ResourceWrapper& rw) {
|
||||||
|
return rw.p_;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend inline T **get_addr(ResourceWrapper& rw) {
|
||||||
|
return &rw.p_;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
T *p_;
|
||||||
|
|
||||||
|
void free_resource() { if (p_) unref_res(p_); }
|
||||||
|
|
||||||
|
// Helper for enabling 'if (sp)'
|
||||||
|
struct Tester {
|
||||||
|
Tester() {}
|
||||||
|
private:
|
||||||
|
void operator delete(void*);
|
||||||
|
};
|
||||||
|
public:
|
||||||
|
// enable 'if (sp)'
|
||||||
|
operator Tester*() const
|
||||||
|
{
|
||||||
|
if (!*this) return 0;
|
||||||
|
static Tester t;
|
||||||
|
return &t;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace glib {
|
||||||
|
typedef ResourceWrapper<gchar, void, g_free> CharStr;
|
||||||
|
typedef ResourceWrapper<GError, GError, g_error_free> Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern bool stdio_getline(FILE *in, std::string &str);
|
||||||
extern char *locale_to_utf8(const char *locstr);
|
extern char *locale_to_utf8(const char *locstr);
|
||||||
extern string utf8_to_locale_ign_err(const string& utf8_str);
|
extern std::string utf8_to_locale_ign_err(const std::string& utf8_str);
|
||||||
|
|
||||||
#endif//!_UTILS_HPP_
|
#endif//!_UTILS_HPP_
|
||||||
|
|||||||
Reference in New Issue
Block a user