Exemplo n.º 1
0
static void parse_long_option(
	const int argc, const char *const argv[], int *i, struct argument_flags *flags)
{
	if (!strcmp(argv[*i], "--help")) {
		help_and_exit(flags->program_name);
	} else if (!strcmp(argv[*i], "--version")) {
		version_and_exit();
	} else if (!strcmp(argv[*i], "--foreground")) {
		flags->daemonize = false;
	} else if (!strcmp(argv[*i], "--config")) {
		if (++(*i) == argc) {
			fprintf(stderr, "You must specify a configuration file.\n");
			cleanup(EXIT_ARGUMENTS, true);
		}

		flags->conf_file = argv[*i];
	} else if (!strcmp(argv[*i], "--noconfig")) {
		flags->conf_file = NULL;
	} else if (!strcmp(argv[*i], "--lax")) {
		fprintf(stderr, "Note: --lax has been enabled. Security checks will *not* be performed.\n");
		flags->strict = false;
	} else if (!strcmp(argv[*i], "--pidfile")) {
		if (++(*i) == argc) {
			fprintf(stderr, "You must specify a pid file.\n");
			cleanup(EXIT_ARGUMENTS, true);
		}

		flags->pid_file = argv[*i];
	} else if (!strcmp(argv[*i], "--quotes")) {
		if (++(*i) == argc) {
			fprintf(stderr, "You must specify a quotes file.\n");
			cleanup(EXIT_ARGUMENTS, true);
		}

		flags->quotes_file = argv[*i];
	} else if (!strcmp(argv[*i], "--journal")) {
		if (++(*i) == argc) {
			fprintf(stderr, "You must specify a journal file.\n");
			cleanup(EXIT_ARGUMENTS, true);
		}

		flags->journal_file = argv[*i];
	} else if (!strcmp(argv[*i], "--ipv4")) {
		if (flags->iproto == PROTOCOL_IPv6) {
			fprintf(stderr, "Conflicting options passed: -4 and -6.\n");
			cleanup(EXIT_ARGUMENTS, true);
		}

		flags->iproto = PROTOCOL_IPv4;
	} else if (!strcmp(argv[*i], "--ipv6")) {
		if (flags->iproto == PROTOCOL_IPv4) {
			fprintf(stderr, "Conflicting options passed: -4 and -6.\n");
			cleanup(EXIT_ARGUMENTS, true);
		}

		flags->iproto = PROTOCOL_IPv6;
	} else if (!strcmp(argv[*i], "--tcp")) {
		if (flags->tproto == PROTOCOL_UDP) {
			fprintf(stderr, "Conflicting options passed: -t and -u.\n");
			cleanup(EXIT_ARGUMENTS, true);
		}

		flags->tproto = PROTOCOL_TCP;
	} else if (!strcmp(argv[*i], "--udp")) {
		if (flags->tproto == PROTOCOL_TCP) {
			fprintf(stderr, "Conflicting options passed: -t and -u.\n");
			cleanup(EXIT_ARGUMENTS, true);
		}

		flags->tproto = PROTOCOL_UDP;
	} else if (!strcmp(argv[*i], "--quiet")) {
		close_journal();
	} else {
		printf("Unrecognized long option: %s.\n", argv[*i]);
		usage_and_exit(flags->program_name);
	}
}
Exemplo n.º 2
0
void parse_args(int argc, char **argv)
{
        const struct option options[] = {
                {"daemon", no_argument, NULL, 'd'},
                {"config-dir", no_argument, NULL, 'c'},
                {"version", no_argument, NULL, 'V'},
                {"help", no_argument, NULL, 'h'},
                {0, 0, 0, 0}
        };

        while (1) {
                int option;

                option = getopt_long(argc, argv, "Vh", options, NULL);

                if (option == -1)
                        break;

                switch (option) {
                case 'd':
                        is_daemon = 1;
                        break;
                case 'c':
                        printf("%s\n", PATH_CONFIG_DIR);
                        exit(EXIT_SUCCESS);
                case 'V':
                        printf("%s %s\n"
                               "Copyright © 2010 %s\n"
                               "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n"
                               "This is free software: you are free to change and redistribute it.\n"
                               "There is NO WARRANTY, to the extent permitted by law.\n",
                               PACKAGE_NAME, VERSION, PACKAGE_AUTHOR);
                        exit(EXIT_SUCCESS);
                case 'h':
                        printf("Usage: %s [OPTION]...\n"
                               "%s\n"
                               "\n"
                               "Options:\n"
                               "     --daemon               run as a daemon process\n"
                               "     --config-dir           output configuration directory path and exit\n"
                               " -h, --help                 display this help and exit\n"
                               " -V, --version              output version infromation and exit\n"
                               "\n"
                               "Processing information and error messages are always printed into syslog. If\n"
                               "%s is not running as a daemon, logs are also printed into stderr.\n"
                               "\n"
                               "Report %s bugs to <%s>\n"
                               "Home page: <%s>\n",
                               program_invocation_name, PACKAGE_DESCRIPTION,
                               PACKAGE_NAME, PACKAGE_NAME,
                               PACKAGE_BUGREPORT,
                               PACKAGE_URL);
                        exit(EXIT_SUCCESS);
                case '?':
                        help_and_exit();
                default:
                        errx(EXIT_FAILURE, "argument parsing failed");
                }
        }

        if (optind != argc) {
                fprintf(stderr, "%s: wrong number of arguments\n",
                        program_invocation_name);
                help_and_exit();
        }
}
Exemplo n.º 3
0
int
main (int argc, char **argv)
{ 
  FT_Library ft_library;
  FT_Face face;
  char *filename;
  int long_format = 0;
  int i;

  if (FT_Init_FreeType (&ft_library))
    FATAL_ERROR ("%s\n", "!! Freetype initialization failed.");

  if (argc > 1)
    {
      if (! strcmp (argv[1], "-h") || ! strcmp (argv[1], "--help"))
	help_and_exit (argv[0]);
      if (! strcmp (argv[1], "-l"))
	long_format = 1, argc--, argv++;
    }
  if (argc == 2)
    {
      if (chdir (argv[1]) < 0)
	FATAL_ERROR ("Can't change directory to %s\n", argv[1]);
    }

  while ((filename = next_file (".")) != NULL)
    {
      if (! FT_New_Face (ft_library, filename, 0, &face))
	{
	  OTF *otf = OTF_open (filename);
	  char *name, *family = NULL, *style = NULL;

	  if (otf && OTF_get_table (otf, "name") == 0)
	    {
	      if (! (family = otf->name->name[16]))
		family = otf->name->name[1];
	      if (! (style = otf->name->name[17]))
		style = otf->name->name[2];
	    }
	  if (! family)
	    family = face->family_name;
	  if (! style)
	    style = face->style_name;

	  name = alloca (strlen (filename)
			 + strlen (family)
			 + 4);
	  sprintf (name, "%s (%s)", filename, family);
	  printf ("%-40s %s", name, style);
	  for (i = 0; i < face->num_charmaps; i++)
	    printf (" %d-%d", face->charmaps[i]->platform_id,
		    face->charmaps[i]->encoding_id);
	  printf ("\n");
	  if (otf && long_format)
	    {
	      print_gsub_gpos_info (otf, "GSUB");
	      print_gsub_gpos_info (otf, "GPOS");
	    }
	  if (otf)
	    OTF_close (otf);
	}
      else
	{
	  printf ("%s fail to open\n", filename);
	}
    }
  exit (0);
}