Пример #1
0
void
cmdline_parser_print_help (void)
{
  cmdline_parser_print_version ();
  printf("\n"
  "Purpose:\n"
  "  perform Statistical Substring Reduction operation on input N-grams\n"
  "  \n"
  "  example: strreduction -f5 -a2 file\n"
  "  will do SSR operation on input word N-gram strings with merging threshold set\n"
  "  to 5 (-f5) using algorithm 2 (-a2).\n"
  "\n"
  "Usage: %s [OPTIONS]... [FILES]...\n", CMDLINE_PARSER_PACKAGE);
  printf("   -h         --help           Print help and exit\n");
  printf("   -V         --version        Print version and exit\n");
  printf("   -FSTRING   --from=STRING    input stream encoding (for character ngram only) (default='UTF-8')\n");
  printf("   -TSTRING   --to=STRING      output stream encoding (for character ngram only) (default='UTF-8')\n");
  printf("   -oSTRING   --output=STRING  write output to file,use stdout if omitted\n");
  printf("   -aINT      --algorithm=INT  using Nth reduction algorithm (default='2')\n");
  printf("   -c         --char           enter char gram mode, default is word ngram model (default=off)\n");
  printf("   -s         --sort           sort result (default=off)\n");
  printf("   -t         --time           show time cost by reduction algorithm on stderr (not including I/O) (default=off)\n");
  printf("   -fINT      --freq=INT       frequence threshold needed in algorithm 1,2,4 (default='1')\n");
  printf("   -mINT      --m1=INT         minimum n-gram need in algorithm 4 (default='1')\n");
}
Пример #2
0
void
cmdline_parser_print_help (void)
{
  cmdline_parser_print_version ();
  printf("\n"
  "Purpose:\n"
  "  CERTI test application\n"
  "\n"
  "Usage: %s [OPTIONS]...\n", CMDLINE_PARSER_PACKAGE);
  printf("   -h         --help               Print help and exit\n");
  printf("   -V         --version            Print version and exit\n");
  printf("   -aINT      --auto=INT           auto start\n");
  printf("   -c         --coordinated        coordinated time (default=on)\n");
  printf("   -dINT      --delay=INT          delay before 1st step\n");
  printf("   -e         --notimestamp        no timestamp (default=off)\n");
  printf("   -fSTRING   --federation=STRING  federation name\n");
  printf("   -lSTRING   --logfile=STRING     file to log events\n");
  printf("   -nSTRING   --name=STRING        federate name\n");
  printf("   -oSTRING   --demo=STRING        select demo (static-ddm, dynamic-ddm)\n");
  printf("   -tINT      --timer=INT          timer\n");
  printf("   -v         --verbose            verbose mode (default=off)\n");
  printf("   -xINT      --xoffset=INT        X offset (X11)\n");
  printf("   -yINT      --yoffset=INT        Y offset (X11)\n");
  printf("   -XINT      --initx=INT          ball initial X value\n");
  printf("   -YINT      --inity=INT          ball initial Y value\n");
  printf("   -FSTRING   --filename=STRING    FED file name\n");
}
Пример #3
0
void
cmdline_parser_print_help (void)
{
  int i = 0;
  cmdline_parser_print_version ();

  if (strlen(gengetopt_args_info_purpose) > 0)
    printf("\n%s\n", gengetopt_args_info_purpose);

  printf("\n%s\n\n", gengetopt_args_info_usage);
  while (gengetopt_args_info_help[i])
    printf("%s\n", gengetopt_args_info_help[i++]);
}
Пример #4
0
int
main(int argc, char *argv[])
{
  setlocale(LC_ALL, "");

  // Process command-line options
  if (cmdline_parser(argc, argv, &args_info) != 0)
    exit(EXIT_FAILURE);
  if (args_info.help_given)
    cmdline_parser_print_help();
  if (args_info.version_given)
    cmdline_parser_print_version();

  // Compile regex
  regex_t re;
  int err = regcomp(&re, args_info.symbol_arg, REG_EXTENDED);
  if (err != 0) {
    size_t errlen = regerror(err, &re, NULL, 0);
    char *errbuf = xmalloc(errlen);
    regerror(err, &re, errbuf, errlen);
    error(EXIT_FAILURE, errno, "%s", errbuf);
  }

  // Process input
  for (unsigned i = 0; i <= args_info.inputs_num; i++) {
    if (i < args_info.inputs_num && strcmp(args_info.inputs[i], "-") != 0) {
      if (!freopen(args_info.inputs[i], "r", stdin))
        error(EXIT_FAILURE, errno, "cannot open %s", quote(args_info.inputs[i]));
    }
    size_t len;
    for (char *line = NULL; getline(&line, &len, stdin) != -1; line = NULL) {
      char *symbol = NULL, *p = line;
      for (char *end; (symbol = get_symbol(&re, p, &end)); p = end) {
        // Temporarily insert a NUL to make the symbol a string
        char c = *end;
        *end = '\0';
        printf("%s\n", symbol);
        *end = c; // Restore the overwritten character
      }
      free(line);
    }
    fclose(stdin);
    if (i < (unsigned)args_info.inputs_num - 1)
      putchar('\n');
  }

  return EXIT_SUCCESS;
}
Пример #5
0
void cmdline_parser_print_help (void) {
	cmdline_parser_print_version ();
	printf(
"Usage: %s [OPTIONS]...\n"
"Build generic tunnels trough HTTPS proxies using HTTP authentication\n"
"\n"
"Standard options:\n"
// FIXME: "   -c, --config=FILE       Read config options from file\n"
" -i, --inetd               Run from inetd (default: off)\n"
" -a, --standalone=INT      Run as standalone daemon on specified port\n"
// FIXME: " -f, --nobackground        Don't for tok background in standalone mode\n"
" -p, --proxy=STRING        Local proxy host:port combination\n"
" -r, --remproxy=STRING     Remote proxy host:port combination (using 2 proxies)\n"
" -d, --dest=STRING         Destination host:port combination\n"
#ifdef USE_SSL
" -e, --encrypt             SSL encrypt data between local proxy and destination\n"
" -E, --encrypt-proxy       SSL encrypt data between client and local proxy\n"
" -X, --encrypt-remproxy    SSL encrypt data between local and remote proxy\n"
#endif
"\n"
"Additional options for specific features:\n"
" -F, --passfile=STRING     File with credentials for proxy authentication\n"
" -P, --proxyauth=STRING    Proxy auth credentials user:pass combination\n"
" -R, --remproxyauth=STRING Remote proxy auth credentials user:pass combination\n"
// " -u, --user=STRING      Username for proxy authentication\n"
// " -s, --pass=STRING      Password for proxy authentication\n"
// " -U, --uservar=STRING   Environment variable that holds username\n"
// " -S, --passvar=STRING   Environment variable that holds password\n"
" -N, --ntlm                Use NTLM based authentication\n"
" -t, --domain=STRING       NTLM domain (default: autodetect)\n"
" -H, --header=STRING       Add additional HTTP headers to send to proxy\n"
#ifdef SETPROCTITLE
" -x, --proctitle=STRING    Use a different process title\n"
#endif
"\n"
"Miscellaneous options:\n"
" -v, --verbose             Turn on verbosity\n"
" -q, --quiet               Suppress messages\n"
" -h, --help                Print help and exit\n"
" -V, --version             Print version and exit\n", PACKAGE);

#ifndef HAVE_GETOPT_LONG
	printf( "\n"
"Notice: This version is compiled without support for long options.\n"
"This means you can only use the short (1 letter) options on the commandline.\n" );
#endif
}
Пример #6
0
Файл: RNAz.c Проект: wash/rnaz
PRIVATE void help(void){

  cmdline_parser_print_version ();

  printf("\nUsage: %s [OPTIONS]... [FILES]\n\n", CMDLINE_PARSER_PACKAGE);
  printf("%s\n","  -f, --forward           Score forward strand");
  printf("%s\n","  -r, --reverse           Score reverse strand");
  printf("%s\n","  -b, --both-strands      Score both strands");
  printf("%s\n","  -o, --outfile=FILENAME  Output filename");
  printf("%s\n","  -p, --cutoff=FLOAT      Probability cutoff");
  printf("%s\n","  -d, --dinucleotide      Use dinucleotide shuffled z-scores (default)");
  printf("%s\n","  -m, --mononucleotide    Use mononucleotide shuffled z-scores (default)");
  printf("%s\n","  -l, --locarnate         Use decision model for structural alignments (default=off)");
  printf("%s\n","  -n, --no-shuffle        Never fall back to shuffling (default=off)");
  printf("%s\n","  -h, --help              Print this help screen");
  printf("%s\n\n","  -V, --version           Show version information");


}
Пример #7
0
int
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
{
  int c;	/* Character of the parsed option.  */
  int missing_required_options = 0;

  args_info->help_given = 0 ;
  args_info->version_given = 0 ;
  args_info->auto_given = 0 ;
  args_info->coordinated_given = 0 ;
  args_info->delay_given = 0 ;
  args_info->federation_given = 0 ;
  args_info->logfile_given = 0 ;
  args_info->name_given = 0 ;
  args_info->demo_given = 0 ;
  args_info->timer_given = 0 ;
  args_info->verbose_given = 0 ;
  args_info->xoffset_given = 0 ;
  args_info->yoffset_given = 0 ;
  args_info->initx_given = 0 ;
  args_info->inity_given = 0 ;
  args_info->filename_given = 0 ;
  args_info->notimestamp_given = 0 ;
#define clear_args() { \
  args_info->coordinated_flag = 1;\
  args_info->federation_arg = NULL; \
  args_info->logfile_arg = NULL; \
  args_info->name_arg = NULL; \
  args_info->demo_arg = NULL; \
  args_info->verbose_flag = 0;\
  args_info->filename_arg = NULL;\
  args_info->notimestamp_flag = 1;\
}

  clear_args();

  optarg = 0;
  optind = 1;
  opterr = 1;
  optopt = '?';

  while (1)
    {
      int option_index = 0;
      char *stop_char;

      static struct option long_options[] = {
        { "help",	0, NULL, 'h' },
        { "version",	0, NULL, 'V' },
        { "auto",	1, NULL, 'a' },
        { "coordinated",	0, NULL, 'c' },
        { "delay",	1, NULL, 'd' },
        { "notimestamp",	0, NULL, 'e' },
        { "federation",	1, NULL, 'f' },
        { "logfile",	1, NULL, 'l' },
        { "name",	1, NULL, 'n' },
        { "demo",	1, NULL, 'o' },
        { "timer",	1, NULL, 't' },
        { "verbose",	0, NULL, 'v' },
        { "xoffset",	1, NULL, 'x' },
        { "yoffset",	1, NULL, 'y' },
        { "initx",	1, NULL, 'X' },
        { "inity",	1, NULL, 'Y' },
        { "filename",   1, NULL, 'F' },
        { NULL,	0, NULL, 0 }
      };

      stop_char = 0;
      c = getopt_long (argc, argv, "hVa:cd:f:l:n:o:t:vx:y:X:Y:F:e", long_options, &option_index);

      if (c == -1) break;	/* Exit from `while (1)' loop.  */

      switch (c)
        {
        case 'h':	/* Print help and exit.  */
          clear_args ();
          cmdline_parser_print_help ();
          exit (EXIT_SUCCESS);

        case 'V':	/* Print version and exit.  */
          clear_args ();
          cmdline_parser_print_version ();
          exit (EXIT_SUCCESS);

        case 'a':	/* auto start.  */
          if (args_info->auto_given)
            {
              fprintf (stderr, "%s: `--auto' (`-a') option given more than once\n", CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->auto_given = 1;
          args_info->auto_arg = strtol (optarg,&stop_char,0);
          break;

        case 'c':	/* coordinated time.  */
          if (args_info->coordinated_given)
            {
              fprintf (stderr, "%s: `--coordinated' (`-c') option given more than once\n",
                       CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->coordinated_given = 1;
          args_info->coordinated_flag = !(args_info->coordinated_flag);
          break;

        case 'd':	/* delay before 1st step.  */
          if (args_info->delay_given)
            {
              fprintf (stderr, "%s: `--delay' (`-d') option given more than once\n", CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->delay_given = 1;
          args_info->delay_arg = strtol (optarg,&stop_char,0);
          break;

        case 'e':	/* no time stamp.  */
          if (args_info->notimestamp_given)
            {
              fprintf (stderr, "%s: `--notimestamp' (`-e') option given more than once\n",
                       CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->notimestamp_given = 1;
          args_info->notimestamp_flag = !(args_info->notimestamp_flag);
          break;

        case 'f':	/* federation name.  */
          if (args_info->federation_given)
            {
              fprintf (stderr, "%s: `--federation' (`-f') option given more than once\n",
                       CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->federation_given = 1;
          args_info->federation_arg = gengetopt_strdup (optarg);
          break;

        case 'l':	/* file to log events.  */
          if (args_info->logfile_given)
            {
              fprintf (stderr, "%s: `--logfile' (`-l') option given more than once\n",
                       CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->logfile_given = 1;
          args_info->logfile_arg = gengetopt_strdup (optarg);
          break;

        case 'n':	/* federate name.  */
          if (args_info->name_given)
            {
              fprintf (stderr, "%s: `--name' (`-n') option given more than once\n", CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->name_given = 1;
          args_info->name_arg = gengetopt_strdup (optarg);
          break;

        case 'o':	/* select demo (static-ddm, dynamic-ddm).  */
          if (args_info->demo_given)
            {
              fprintf (stderr, "%s: `--demo' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->demo_given = 1;
          args_info->demo_arg = gengetopt_strdup (optarg);
          break;

        case 't':	/* timer.  */
          if (args_info->timer_given)
            {
              fprintf (stderr, "%s: `--timer' (`-t') option given more than once\n", CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->timer_given = 1;
          args_info->timer_arg = strtol (optarg,&stop_char,0);
          break;

        case 'v':	/* verbose mode.  */
          if (args_info->verbose_given)
            {
              fprintf (stderr, "%s: `--verbose' (`-v') option given more than once\n",
                       CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->verbose_given = 1;
          args_info->verbose_flag = !(args_info->verbose_flag);
          break;

        case 'x':	/* X offset (X11).  */
          if (args_info->xoffset_given)
            {
              fprintf (stderr, "%s: `--xoffset' (`-x') option given more than once\n",
                       CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->xoffset_given = 1;
          args_info->xoffset_arg = strtol (optarg,&stop_char,0);
          break;

        case 'y':	/* Y offset (X11).  */
          if (args_info->yoffset_given)
            {
              fprintf (stderr, "%s: `--yoffset' (`-y') option given more than once\n",
                       CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->yoffset_given = 1;
          args_info->yoffset_arg = strtol (optarg,&stop_char,0);
          break;

        case 'X':	/* ball initial X value.  */
          if (args_info->initx_given)
            {
              fprintf (stderr, "%s: `--initx' (`-X') option given more than once\n", CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->initx_given = 1;
          args_info->initx_arg = strtol (optarg,&stop_char,0);
          break;

        case 'Y':	/* ball initial Y value.  */
          if (args_info->inity_given)
            {
              fprintf (stderr, "%s: `--inity' (`-Y') option given more than once\n", CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->inity_given = 1;
          args_info->inity_arg = strtol (optarg,&stop_char,0);
          break;

       case 'F':	/* FED file name  */
          if (args_info->filename_given)
            {
              fprintf (stderr, "%s: `--filename' (`-F') option given more than once\n",
                       CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->filename_given = 1;
          args_info->filename_arg = gengetopt_strdup (optarg);
          break;

        case 0:	/* Long option with no short option */

        case '?':	/* Invalid option.  */
          /* `getopt_long' already printed an error message.  */
          exit (EXIT_FAILURE);

        default:	/* bug: option not considered.  */
          fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c);
          abort ();
        } /* switch */
    } /* while */


  if (! args_info->federation_given)
    {
      fprintf (stderr, "%s: '--federation' ('-f') option required\n", CMDLINE_PARSER_PACKAGE);
      missing_required_options = 1;
    }
  if (! args_info->name_given)
    {
      fprintf (stderr, "%s: '--name' ('-n') option required\n", CMDLINE_PARSER_PACKAGE);
      missing_required_options = 1;
    }
  if (! args_info->filename_given)
    {
      fprintf (stderr, "%s: '--filename' ('-F') option required\n", CMDLINE_PARSER_PACKAGE);
      missing_required_options = 1;
    }
  if ( missing_required_options )
    exit (EXIT_FAILURE);

  return 0;
}
Пример #8
0
int cmdline_parser( int argc, char * const *argv, struct gengetopt_args_info *args_info ) {
	/* Character of the parsed option.  */
	int c;
	/* Tmd retval */
	int r;
	int missing_required_options = 0;

	args_info->help_given = 0;
	args_info->version_given = 0;
	args_info->user_given = 0;
	args_info->pass_given = 0;
	args_info->remuser_given = 0;
	args_info->rempass_given = 0;
	args_info->proxy_given = 0;
	args_info->proxyauth_given = 0;
	args_info->proxyhost_given = 0;
	args_info->proxyport_given = 0;
	args_info->dest_given = 0;
	args_info->remproxy_given = 0;
	args_info->remproxyauth_given = 0;
	args_info->verbose_given = 0;
	args_info->ntlm_given = 0;
	args_info->inetd_given = 0;
	args_info->quiet_given = 0;
	args_info->header_given = 0;
	args_info->domain_given = 0;
	args_info->encrypt_given = 0;
	args_info->encryptproxy_given = 0;
	args_info->encryptremproxy_given = 0;
	args_info->proctitle_given = 0;
	args_info->host_given = 0;

/* No... we can't make this a function... -- Maniac */
#define clear_args() \
{ \
	args_info->user_arg = NULL; \
	args_info->pass_arg = NULL; \
	args_info->remuser_arg = NULL; \
	args_info->rempass_arg = NULL; \
	args_info->domain_arg = NULL; \
	args_info->proxy_arg = NULL; \
	args_info->proxyauth_arg = NULL; \
	args_info->proxyhost_arg = NULL; \
	args_info->dest_arg = NULL; \
	args_info->remproxy_arg = NULL; \
	args_info->remproxyauth_arg = NULL; \
	args_info->header_arg[0] = '\0'; \
	args_info->verbose_flag = 0; \
	args_info->ntlm_flag = 0; \
	args_info->inetd_flag = 0; \
	args_info->quiet_flag = 0; \
	args_info->standalone_arg = 0; \
	args_info->encrypt_flag = 0; \
	args_info->encryptproxy_flag = 0; \
	args_info->encryptremproxy_flag = 0; \
	args_info->proctitle_arg = NULL; \
	args_info->host_arg = NULL; \
} 

	clear_args();

	optarg = 0;

#ifdef HAVE_GETOPT_LONG
	optind = 1;
	opterr = 1;
	optopt = '?';
#endif

	while (1) {
#ifdef HAVE_GETOPT_LONG
		int option_index = 0;

		/* Struct option: Name, Has_arg, Flag, Value */
		static struct option long_options[] = {
			{ "help",			0, NULL, 'h' },
			{ "version",		0, NULL, 'V' },
			{ "user",			1, NULL, 'u' },
			{ "pass",			1, NULL, 's' },
			{ "domain",			1, NULL, 't' },
//			{ "uservar",		1, NULL, 'U' },
//			{ "passvar",		1, NULL, 'S' },
			{ "passfile",		1, NULL, 'F' },
			{ "proxy",			1, NULL, 'p' },
			{ "proxyauth",		1, NULL, 'P' },
			{ "dest",			1, NULL, 'd' },
			{ "remproxy",		1, NULL, 'r' },
			{ "remproxyauth",	1, NULL, 'R' },
			{ "proctitle",		1, NULL, 'x' },
			{ "host",		1, NULL, 'o' },
			{ "header",			1, NULL, 'H' },
			{ "verbose",		0, NULL, 'v' },
			{ "ntlm",			0, NULL, 'N' },
			{ "inetd",			0, NULL, 'i' },
			{ "standalone", 	1, NULL, 'a' },
			{ "quiet",			0, NULL, 'q' },
			{ "encrypt",		0, NULL, 'e' },
			{ "encrypt-proxy",	0, NULL, 'E' },
			{ "encrypt-remproxy",0,NULL, 'X' },
			{ NULL,				0, NULL, 0 }
		};

		c = getopt_long (argc, argv, "hVia:u:s:t:F:p:P:r:R:d:H:x:nvNeEXqo:", long_options, &option_index);
#else
		c = getopt( argc, argv, "hVia:u:s:t:F:p:P:r:R:d:H:x:nvNeEXqo:" );
#endif

		if (c == -1)
			break;	/* Exit from `while (1)' loop.  */

		switch (c) {
			case 'h':	/* Print help and exit.  */
				clear_args ();
				cmdline_parser_print_help ();
				exit(0);

#ifdef USE_SSL
			case 'e':       /* Turn on SSL encryption */
				args_info->encrypt_flag = !(args_info->encrypt_flag);
				if( args_info->verbose_flag )
					message("SSL enabled\n");
				break;

			case 'E':	/* Turn on client to proxy SSL encryption */
				args_info->encryptproxy_flag = !(args_info->encryptproxy_flag);
				if( args_info->verbose_flag )
					message("SSL client to proxy enabled\n");
				break;
#endif

			case 'i':	/* Run from inetd. */
				if ( args_info->standalone_arg > 0 ) {
					fprintf( stderr, "%s: '--inetd' ('-i') conflicts with '--standalone' ('-a')\n", PACKAGE );
					clear_args();
					exit( 1 );
				}
				args_info->inetd_flag = !(args_info->inetd_flag);
				break;

			case 'a':       /* Run as standalone daemon */
				if ( args_info->inetd_flag ) {
					fprintf( stderr, "%s: `--standalone' (`-a') conflicts with `--inetd' (`-i')\n", PACKAGE );
					clear_args();
					exit(1);
				}
				if ( ( args_info->standalone_arg = atoi( optarg ) ) < 1 ) {
					fprintf( stderr, "%s: Illegal port value for `--standalone' (`-a')\n", PACKAGE);
					clear_args();
					exit(1);
				}
				break;

			case 'V':	/* Print version and exit.  */
				clear_args ();
				cmdline_parser_print_version ();
				exit(0);

			case 'x':
				args_info->proctitle_given = 1;
				message( "Proctitle override enabled\n" );
				args_info->proctitle_arg = gengetopt_strdup (optarg);
				break;

			case 'o':
				args_info->host_given = 1;
				/* message( "Host-header override enabled\n" ); */
				args_info->host_arg = gengetopt_strdup (optarg);
				break;

			case 'u':	/* Username to send to HTTPS proxy for authentication.  */
				if (args_info->user_given) {
					fprintf (stderr, "%s: `--user' (`-u'), `--proxyauth' (`-P') or `--passfile' (`-F') option given more than once\n", PACKAGE);
					clear_args ();
					exit(1);
				}
				args_info->user_given = 1;
				args_info->user_arg = gengetopt_strdup (optarg);
				message ("Option -u/--user is deprecated, please use -P/--proxyauth user:pass\n");
				break;


			case 's':	/* Password to send to HTTPS proxy for authentication.  */
				if (args_info->pass_given) {
					fprintf (stderr, "%s: `--pass' (`-s') or `--passfile' (`-F') option given more than once\n", PACKAGE);
					clear_args ();
					exit(1);
				}
				args_info->pass_given = 1;
				args_info->pass_arg = gengetopt_strdup (optarg);
				message ("Option -s/--pass is deprecated, please use -P/--proxyauth user:pass\n");
				break;

			case 't':	/* Env Var with NTLM DOMAIN (when overriding).  */
				if (args_info->domain_given) {
					fprintf (stderr, "%s: `--domain' (`-t') option given more than once\n", PACKAGE);
					clear_args ();
					exit(1);
				}
				args_info->domain_given = 1;
				args_info->domain_arg = gengetopt_strdup (optarg);
				break;

			case 'F':  /* File containing Username & Password to send to
							HTTPS proxy for authentication.  */
				if (args_info->user_given) {
					fprintf (stderr, "%s: `--user' (`-u') or `--passfile' (`-F') option given more than once\n", PACKAGE);
					clear_args ();
					exit(1);
				}
				if (args_info->pass_given) {
					fprintf (stderr, "%s: `--pass' (`-s') or `--passfile' (`-F') option given more than once\n", PACKAGE);
					clear_args ();
					exit(1);
				}
				char *result = getCredentialsFromFile(optarg, &(args_info->user_arg), &(args_info->pass_arg), &(args_info->remuser_arg), &(args_info->rempass_arg) );
				if ( args_info->user_arg != NULL )
					args_info->user_given = 1;
				if ( args_info->pass_arg != NULL )
					args_info->pass_given = 1;
				if ( args_info->remuser_arg != NULL )
					args_info->remuser_given = 1;
				if ( args_info->rempass_arg != NULL )
					args_info->rempass_given = 1;

				if( result != NULL ) {
					fprintf( stderr, "%s: Bad password file for `--passfile' (`-F')\n%s\n", PACKAGE, result);
					clear_args();
					exit(1);
				}
				break;

			case 'p':       /* HTTPS Proxy host:port to connect to.  */
				if (args_info->proxy_given) {
					fprintf (stderr, "%s: `--proxy' (`-p') option given more than once\n", PACKAGE);
					clear_args ();
					exit(1);
				}
				args_info->proxy_given = 1;
				args_info->proxy_arg = gengetopt_strdup (optarg);
				break;

			case 'P':       /* HTTPS Proxy auth user:pass for local proxy */
				if (args_info->proxyauth_given) {
					fprintf (stderr, "%s: `--proxyauth' (`-P') option given more than once\n", PACKAGE);
					clear_args ();
					exit(1);
				}
				args_info->proxyauth_given = 1;
				args_info->proxyauth_arg = gengetopt_strdup (optarg);
				break;

			case 'r':       /* Use a remote proxy */
				if (args_info->remproxy_given) {
					fprintf (stderr, "%s: `--remproxy' (`-r') option given more than once\n", PACKAGE);
					clear_args ();
					exit(1);
				}
				args_info->remproxy_given = 1;
				args_info->remproxy_arg = gengetopt_strdup (optarg);
				break;

			case 'R':       /* HTTPS Proxy auth user:pass for remote proxy */
				if (args_info->remproxyauth_given) {
					fprintf (stderr, "%s: `--remproxyauth' (`-P') option given more than once\n", PACKAGE);
					clear_args ();
					exit(1);
				}
				args_info->remproxyauth_given = 1;
				args_info->remproxyauth_arg = gengetopt_strdup (optarg);
				break;

			case 'X':   /* Turn on local to remote proxy SSL encryption */
				args_info->encryptremproxy_flag = !(args_info->encryptremproxy_flag);
				if( args_info->verbose_flag )
					message("SSL local to remote proxy enabled\n");
				break;


			case 'd':	/* Destination host to built the tunnel to.  */
				if (args_info->dest_given) {
					fprintf (stderr, "%s: `--dest' (`-d') option given more than once\n", PACKAGE);
					clear_args ();
					exit(1);
				}
				args_info->dest_given = 1;
				args_info->dest_arg = gengetopt_strdup (optarg);
				break;

			case 'H':	/* Extra headers to send to HTTPS proxy. */
				args_info->header_given++;
				strzcat( args_info->header_arg, "%s\r\n", optarg);
				break;

			case 'v':	/* Turn on verbosity.  */
				if (args_info->quiet_flag) {       /* -q also on cmd line */
					fprintf (stderr, "-v and -q are mutually exclusive\n");
					clear_args();
					exit(1);
				}
				args_info->verbose_flag = !(args_info->verbose_flag);
				break;

			case 'N':	/* Turn on NTLM.  */
				args_info->ntlm_flag = !(args_info->ntlm_flag);
				break;

			case 'q':	/* Suppress messages -- Quiet mode */
				args_info->quiet_flag = !(args_info->quiet_flag);
				break;

			case 0:	/* Long option with no short option */

			case '?':	/* Invalid option.  */
				/* `getopt_long' already printed an error message.  */
				clear_args();
				exit(1);

			default:	/* bug: option not considered.  */
				fprintf (stderr, "%s: option unknown: %c\n", PACKAGE, c);
				clear_args();
				abort();
		} /* switch */
	} /* while */

/* For Windows quiet is the default output. -- Dag */
#ifdef CYGWIN
	if (! args_info->verbose_flag ) {
		args_info->quiet_flag = 1;
	}
#endif

/* Get credentials from environment. -- Dag */
	char *tmp = NULL;
	if ( args_info->user_arg == NULL ) {
		if ( (tmp = getenv("PROXYUSER")) != NULL) {
			args_info->user_given = 1;
			args_info->user_arg = gengetopt_strdup (tmp);
			if( args_info->verbose_flag )
				message( "Found user '%s' in env variable PROXYUSER.\n", args_info->user_arg);
		}
	}
	if ( args_info->pass_arg == NULL ) {
		if ( (tmp = getenv("PROXYPASS")) != NULL ) {
			args_info->pass_given = 1;
			args_info->pass_arg = gengetopt_strdup (tmp);
			if( args_info->verbose_flag )
				message( "Found password in env variable PROXYPASS.\n", args_info->pass_arg);
		}
	}
	if ( args_info->remuser_arg == NULL ) {
		if ( (tmp = getenv("REMPROXYUSER")) != NULL ) {
			args_info->remuser_given = 1;
			args_info->user_arg = gengetopt_strdup (tmp);
			if( args_info->verbose_flag )
				message( "Found remote user '%s' in env variable REMPROXYPASS.\n", args_info->remuser_arg);
		}
	}
	if ( args_info->rempass_arg == NULL ) {
		if ( (tmp = getenv("REMPROXYPASS")) != NULL ) {
			args_info->rempass_given = 1;
			args_info->user_arg = gengetopt_strdup (tmp);
			if( args_info->verbose_flag )
				message( "Found remote password in env variable REMPROXYPASS.\n" );
		}
	}

	if ( args_info->proxy_arg == NULL ) {
		if ( ((tmp = getenv("http_proxy")) != NULL) || ((tmp = getenv("HTTP_PROXY")) != NULL) ) {
			int r;
			char * temp;
			temp = malloc( 56+1 );
			r = sscanf( tmp, "http://%56[^/]/", temp );
//			message( "r = '%d'\ntemp = '%s'\n", r, temp);

			args_info->proxy_given = 1;
			args_info->proxy_arg = gengetopt_strdup (temp);
			if( args_info->verbose_flag )
				message( "Proxy info found using env variable HTTP_PROXY (%s).\n", args_info->proxy_arg);
		}
	}

	if (! args_info->proxy_given && ! args_info->dest_given ) {
		clear_args ();
//		cmdline_parser_print_help ();
		message( "No proxy or destination given, exiting\nUse '--help' flag for usage info\n" );
		exit(1);
	}

	if (args_info->proxy_given ) {
		char * phost;
		int pport;

		phost = malloc( 50+1 );

		r = sscanf( args_info->proxy_arg, "%50[^:]:%5u", phost, &pport );
		if ( r == 2 ) {
			args_info->proxyhost_arg = phost;
			args_info->proxyport_arg = pport;
			args_info->proxyhost_given = 1;
			args_info->proxyport_given = 1;
		} else {
			message( "parse_cmdline: could not find your proxy hostname/ip (%s)\n", args_info->proxy_arg );
			missing_required_options++;
		}
	}

	/* Parse -P/--proxyauth information */
	if (args_info->proxyauth_given ) {
		char *puser = NULL;
		char *ppass = NULL;

		puser = malloc( 24+1 );
		ppass = malloc( 24+1 );

		r = sscanf( args_info->proxyauth_arg, "%24[^:]:%24s", puser, ppass );
		if ( r == 2 ) {
			args_info->user_arg = puser;
			args_info->pass_arg = ppass;
			args_info->user_given = 1;
			args_info->pass_given = 1;
		} else if ( r == 1 ) {
			args_info->user_arg = args_info->proxyauth_arg;
			args_info->user_given = 1;
		} else {
			message( "parse_cmdline: could not find your proxy auth user/pass\n" );
			missing_required_options++;
		}
	}

	/* Parse -R/--remproxyauth information */
	if (args_info->remproxyauth_given ) {
		char *ruser = NULL;
		char *rpass = NULL;

		ruser = malloc( 24+1 );
		rpass = malloc( 24+1 );

		r = sscanf( args_info->remproxyauth_arg, "%24[^:]:%24s", ruser, rpass );
		if ( r == 2 ) {
			args_info->remuser_arg = ruser;
			args_info->rempass_arg = rpass;
			args_info->remuser_given = 1;
			args_info->rempass_given = 1;
		} else if ( r == 1 ) {
			args_info->remuser_arg = args_info->remproxyauth_arg;
			args_info->remuser_given = 1;
		} else {
			message( "parse_cmdline: could not find your proxy auth user/pass\n" );
			missing_required_options++;
		}
	}
	if ( missing_required_options )
		exit(1);

	return 0;
}
Пример #9
0
/**
 * Initialize preload library.
 * Checks if tracing is activated using the environment variable OGRT_ACTIVE.
 * If it is: connect to the unix socket of the daemon. If establishing a connection to
 * the daemon fails the init function will return with a non-zero exit code, but program
 * execution will continue as normal.
 */
__attribute__((constructor)) int ogrt_preload_init_hook()
{
  ogrt_log_file = stderr;
  ogrt_log_level = OGRT_LOG_INFO;

  if(ogrt_env_enabled("OGRT_SCHLEICHFAHRT")) {
    ogrt_log_level = OGRT_LOG_NOTHING;
  }

  if(ogrt_env_enabled("OGRT_DEBUG_INFO")) {
    cmdline_parser_print_version();
    printf("  OGRT_NET_HOST=%s\n  OGRT_NET_PORT=%s\n  OGRT_ENV_JOBID=%s\n  OGRT_ELF_SECTION_NAME=%s\n  OGRT_ELF_NOTE_TYPE=0x%x\n",
              OGRT_NET_HOST,      OGRT_NET_PORT,      OGRT_ENV_JOBID,      OGRT_ELF_SECTION_NAME,      OGRT_ELF_NOTE_TYPE);
    printf("  OGRT_MSG_SEND_USERNAME=%d\n  OGRT_MSG_SEND_HOSTNAME=%d\n  OGRT_MSG_SEND_ENVIRONMENT=%d\n",
              OGRT_MSG_SEND_USERNAME,      OGRT_MSG_SEND_HOSTNAME,      OGRT_MSG_SEND_ENVIRONMENT);
#if OGRT_MSG_SEND_ENVIRONMENT == 1 && defined(OGRT_MSG_SEND_ENVIRONMENT_WHITELIST)
    printf("  OGRT_ENVIRONMENT_WHITELIST:\n");
    char *whitelist[] = { OGRT_MSG_SEND_ENVIRONMENT_WHITELIST };
    for(int i=0; i < OGRT_MSG_SEND_ENVIRONMENT_WHITELIST_LENGTH; i++) {
      printf("    %s\n", whitelist[i]);
    }
#endif
  }

  if(ogrt_env_enabled("OGRT_ACTIVE")) {
    __ogrt_active = true;
  }

  if(__ogrt_active && __daemon_socket < 0) {
    /* establish a connection the the ogrt server */
    struct addrinfo hints, *servinfo, *p;
    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;

    int ret;
    if ((ret = getaddrinfo(OGRT_NET_HOST, OGRT_NET_PORT, &hints, &servinfo)) != 0) {
      Log(OGRT_LOG_ERR, "getaddrinfo: %s\n", gai_strerror(ret));
      __ogrt_active = false;
      return 1;
    }

    for(p = servinfo; p != NULL; p = p->ai_next) {
        if ((__daemon_socket = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
            Log(OGRT_LOG_ERR, "%s\n", strerror(errno));
            __ogrt_active = false;
            continue;
        }

        if (connect(__daemon_socket, p->ai_addr, p->ai_addrlen) == -1) {
            close(__daemon_socket);
            __ogrt_active = false;
            Log(OGRT_LOG_ERR, "%s\n", strerror(errno));
            continue;
        }

        break;
    }

    if (p == NULL) {
        Log(OGRT_LOG_ERR, "%s\n", strerror(errno));
        __ogrt_active = false;
        return 1;
    }

    freeaddrinfo(servinfo);

    Log(OGRT_LOG_INFO, "Connected to socket.\n");

    /* cache PID of current process - we are reusing that quite often */
    __pid = getpid();
    __parent_pid = getppid();
    if(gethostname(__hostname, HOST_NAME_MAX) != 0) {
      Log(OGRT_LOG_ERR, "%s\n", strerror(errno));
      __ogrt_active = false;
      return 1;
    }

    Log(OGRT_LOG_INFO, "I be watchin' yo! (process %d [%s] with parent %d)\n", __pid, ogrt_get_binpath(__pid), getppid());

    if(!ogrt_send_processinfo()) {
      Log(OGRT_LOG_ERR, "failed to send process info\n");
      __ogrt_active = 0;
      return 1;
    }
  }

  close(__daemon_socket);
  return 0;
}
Пример #10
0
int
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
{
  int c;	/* Character of the parsed option.  */
  int missing_required_options = 0;

  args_info->help_given = 0 ;
  args_info->version_given = 0 ;
  args_info->from_given = 0 ;
  args_info->to_given = 0 ;
  args_info->output_given = 0 ;
  args_info->algorithm_given = 0 ;
  args_info->char_given = 0 ;
  args_info->sort_given = 0 ;
  args_info->time_given = 0 ;
  args_info->freq_given = 0 ;
  args_info->m1_given = 0 ;
#define clear_args() { \
  args_info->from_arg = gengetopt_strdup("UTF-8") ;\
  args_info->to_arg = gengetopt_strdup("UTF-8") ;\
  args_info->output_arg = NULL; \
  args_info->algorithm_arg = 2 ;\
  args_info->char_flag = 0;\
  args_info->sort_flag = 0;\
  args_info->time_flag = 0;\
  args_info->freq_arg = 1 ;\
  args_info->m1_arg = 1 ;\
}

  clear_args();

  args_info->inputs = NULL;
  args_info->inputs_num = 0;

  optarg = 0;
  optind = 1;
  opterr = 1;
  optopt = '?';

  while (1)
    {
      int option_index = 0;
      char *stop_char;

      static struct option long_options[] = {
        { "help",	0, NULL, 'h' },
        { "version",	0, NULL, 'V' },
        { "from",	1, NULL, 'F' },
        { "to",	1, NULL, 'T' },
        { "output",	1, NULL, 'o' },
        { "algorithm",	1, NULL, 'a' },
        { "char",	0, NULL, 'c' },
        { "sort",	0, NULL, 's' },
        { "time",	0, NULL, 't' },
        { "freq",	1, NULL, 'f' },
        { "m1",	1, NULL, 'm' },
        { NULL,	0, NULL, 0 }
      };

      stop_char = 0;
      c = getopt_long (argc, argv, "hVF:T:o:a:cstf:m:", long_options, &option_index);

      if (c == -1) break;	/* Exit from `while (1)' loop.  */

      switch (c)
        {
        case 'h':	/* Print help and exit.  */
          clear_args ();
          cmdline_parser_print_help ();
          exit (EXIT_SUCCESS);

        case 'V':	/* Print version and exit.  */
          clear_args ();
          cmdline_parser_print_version ();
          exit (EXIT_SUCCESS);

        case 'F':	/* input stream encoding (for character ngram only).  */
          if (args_info->from_given)
            {
              fprintf (stderr, "%s: `--from' (`-F') option given more than once\n", CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->from_given = 1;
          args_info->from_arg = gengetopt_strdup (optarg);
          break;

        case 'T':	/* output stream encoding (for character ngram only).  */
          if (args_info->to_given)
            {
              fprintf (stderr, "%s: `--to' (`-T') option given more than once\n", CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->to_given = 1;
          args_info->to_arg = gengetopt_strdup (optarg);
          break;

        case 'o':	/* write output to file,use stdout if omitted.  */
          if (args_info->output_given)
            {
              fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->output_given = 1;
          args_info->output_arg = gengetopt_strdup (optarg);
          break;

        case 'a':	/* using Nth reduction algorithm.  */
          if (args_info->algorithm_given)
            {
              fprintf (stderr, "%s: `--algorithm' (`-a') option given more than once\n", CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->algorithm_given = 1;
          args_info->algorithm_arg = strtol (optarg,&stop_char,0);
          break;

        case 'c':	/* enter char gram mode, default is word ngram model.  */
          if (args_info->char_given)
            {
              fprintf (stderr, "%s: `--char' (`-c') option given more than once\n", CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->char_given = 1;
          args_info->char_flag = !(args_info->char_flag);
          break;

        case 's':	/* sort result.  */
          if (args_info->sort_given)
            {
              fprintf (stderr, "%s: `--sort' (`-s') option given more than once\n", CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->sort_given = 1;
          args_info->sort_flag = !(args_info->sort_flag);
          break;

        case 't':	/* show time cost by reduction algorithm on stderr (not including I/O).  */
          if (args_info->time_given)
            {
              fprintf (stderr, "%s: `--time' (`-t') option given more than once\n", CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->time_given = 1;
          args_info->time_flag = !(args_info->time_flag);
          break;

        case 'f':	/* frequence threshold needed in algorithm 1,2,4.  */
          if (args_info->freq_given)
            {
              fprintf (stderr, "%s: `--freq' (`-f') option given more than once\n", CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->freq_given = 1;
          args_info->freq_arg = strtol (optarg,&stop_char,0);
          break;

        case 'm':	/* minimum n-gram need in algorithm 4.  */
          if (args_info->m1_given)
            {
              fprintf (stderr, "%s: `--m1' (`-m') option given more than once\n", CMDLINE_PARSER_PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->m1_given = 1;
          args_info->m1_arg = strtol (optarg,&stop_char,0);
          break;


        case 0:	/* Long option with no short option */

        case '?':	/* Invalid option.  */
          /* `getopt_long' already printed an error message.  */
          exit (EXIT_FAILURE);

        default:	/* bug: option not considered.  */
          fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c);
          abort ();
        } /* switch */
    } /* while */


  if ( missing_required_options )
    exit (EXIT_FAILURE);

  if (optind < argc)
    {
      int i = 0 ;
  
      args_info->inputs_num = argc - optind ;
      args_info->inputs = 
        (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
      while (optind < argc)
        args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; 
    }
  
  return 0;
}