浏览代码

* check for getopt_long; work with simple getopt.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/pwntcha/trunk@391 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 21 年前
父节点
当前提交
4ffb87231e
共有 2 个文件被更改,包括 24 次插入5 次删除
  1. +2
    -0
      configure.ac
  2. +22
    -5
      src/main.c

+ 2
- 0
configure.ac 查看文件

@@ -18,6 +18,8 @@ AC_C_CONST
AC_C_INLINE AC_C_INLINE
AC_TYPE_SIZE_T AC_TYPE_SIZE_T


AC_CHECK_FUNCS(getopt_long)

# Use OpenCV? # Use OpenCV?
ac_cv_my_have_opencv="no" ac_cv_my_have_opencv="no"
save_CPPFLAGS="${CPPFLAGS}" save_CPPFLAGS="${CPPFLAGS}"


+ 22
- 5
src/main.c 查看文件

@@ -17,6 +17,12 @@
#include "config.h" #include "config.h"
#include "common.h" #include "common.h"


#ifdef HAVE_GETOPT_LONG
# define MOREINFO "Try `%s --help' for more information.\n"
#else
# define MOREINFO "Try `%s -h' for more information.\n"
#endif

int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *mode = "auto"; char *mode = "auto";
@@ -27,6 +33,7 @@ int main(int argc, char *argv[])
for(;;) for(;;)
{ {
int this_option_optind = optind ? optind : 1; int this_option_optind = optind ? optind : 1;
#ifdef HAVE_GETOPT_LONG
int option_index = 0; int option_index = 0;
static struct option long_options[] = static struct option long_options[] =
{ {
@@ -37,6 +44,9 @@ int main(int argc, char *argv[])
}; };


c = getopt_long(argc, argv, "hm:v", long_options, &option_index); c = getopt_long(argc, argv, "hm:v", long_options, &option_index);
#else
c = getopt(argc, argv, "hm:v");
#endif
if(c == -1) if(c == -1)
break; break;


@@ -44,15 +54,21 @@ int main(int argc, char *argv[])
{ {
case 'h': /* --help */ case 'h': /* --help */
printf("Usage: %s [OPTION]... FILE...\n", argv[0]); printf("Usage: %s [OPTION]... FILE...\n", argv[0]);
#ifdef HAVE_GETOPT_LONG
printf(" -m, --mode force operating mode\n"); printf(" -m, --mode force operating mode\n");
printf(" -h, --help display this help and exit\n"); printf(" -h, --help display this help and exit\n");
printf(" -v, --version output version information and exit\n"); printf(" -v, --version output version information and exit\n");
#else
printf(" -m force operating mode\n");
printf(" -h display this help and exit\n");
printf(" -v output version information and exit\n");
#endif
return 0; return 0;
case 'm': /* --mode */ case 'm': /* --mode */
mode = optarg; mode = optarg;
break; break;
case 'v': /* --version */ case 'v': /* --version */
printf("pwntcha (CAPTCHA decoder) %s\n", VERSION);
printf("pwntcha (captcha decoder) %s\n", VERSION);
printf("Written by Sam Hocevar.\n"); printf("Written by Sam Hocevar.\n");
printf("\n"); printf("\n");
printf("Copyright (C) 2004-2005 Sam Hocevar <sam@zoy.org>\n"); printf("Copyright (C) 2004-2005 Sam Hocevar <sam@zoy.org>\n");
@@ -60,10 +76,11 @@ int main(int argc, char *argv[])
printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
return 0; return 0;
case '?': case '?':
break;
printf(MOREINFO, argv[0]);
return 1;
default: default:
printf("%s: invalid option -- %i\n", argv[0], c); printf("%s: invalid option -- %i\n", argv[0], c);
printf("Try `%s --help' for more information.\n", argv[0]);
printf(MOREINFO, argv[0]);
return 1; return 1;
} }
} }
@@ -71,7 +88,7 @@ int main(int argc, char *argv[])
if(optind >= argc) if(optind >= argc)
{ {
printf("%s: too few arguments\n", argv[0]); printf("%s: too few arguments\n", argv[0]);
printf("Try `%s --help' for more information.\n", argv[0]);
printf(MOREINFO, argv[0]);
return 1; return 1;
} }


@@ -102,7 +119,7 @@ int main(int argc, char *argv[])
result = decode_slashdot(img); result = decode_slashdot(img);
else else
{ {
fprintf(stderr, "%s: could not guess CAPTCHA type\n", argv[0]);
fprintf(stderr, "%s: could not guess captcha type\n", argv[0]);
printf("\n"); printf("\n");
image_free(img); image_free(img);
continue; continue;


正在加载...
取消
保存