Exemplo n.º 1
0
Arquivo: main.c Projeto: lorvis/study
int main()
{
    printf("Hello world!\n");
    set_t * set_A = set_new(10);
    set_t * set_B = set_new(7);
    set_t * set_C;
    set_add_range(set_A,0,11);
    set_add_range(set_B,3,5);
    puts("\n\n Set_A after add");
    set_print_out(set_A);
    set_delete_range(set_A,3,11);
    puts("\n\n Set_A after delete");
    set_print_out(set_A);
    puts("\n\n Set_B after add");
    set_print_out(set_B);
    set_C = set_merge(set_A,set_B,"none");
    puts("\n\n Set_C - result of merge");
    set_print_out(set_C);
    set_delete_range(set_A,0,10);
    set_add_range(set_A,4,7);
    puts("\n\n another set_A");
    set_print_out(set_A);
    set_delete(set_C);
    set_A = _set_intersection(set_A,set_B,"del 1");
    puts("\n\n set_A after intersection with set_B");
    set_print_out(set_A);
    puts("\n\n set_A size after intersection \n");
    set_print_size(set_A);
    set_delete_range(set_A,4,5);
    set_add_range(set_A,1,1);
        set_add_range(set_A,3,4);
    puts("\n\n another set_A");
    set_print_out(set_A);
     puts("\n\n set_B");
    set_print_out(set_B);
    set_C = set_absolute_complement(set_A,set_B,"none");
    puts("\n\n set_C - absolute_complement of set_A and set_B");
    set_print_out(set_C);

    printf("\n Power of set_C = %i",set_measure_power(set_C));
    set_delete(set_C);
    set_add_range(set_A,0,10);
    puts("\n\n set_A");
    set_print_out(set_A);
    set_delete_range(set_B,3,5);
    set_add_range(set_B,2,4);
    puts("\n\n set_B");
    set_print_out(set_B);
    set_C = set_relative_complement(set_A,set_B,"none");
    puts("\n\n set_C - relative_complement of set_A and set_B");
    set_print_out(set_C);
    set_delete(set_A);
    set_delete(set_B);
    set_delete(set_C);
    return 0;
}
Exemplo n.º 2
0
/* Calculates the value of FIRST for the string of N grammar symbols
   at X.  Sets the result into SET. */
static void
calc_first (struct set *set, int *X, int n)
{
  int i;
  
  set_init (set);
  for (i = 0; i < n; i++)
    {
      const struct set *f = &find_symbol (X[i])->first;

      set_merge (set, f, 0);
      if (!set_contains (f, 0))
	return;
    }

  set_add (set, 0);
}
Exemplo n.º 3
0
Arquivo: tini.c Projeto: twpayne/tini
int main(int argc, char *argv[])
{
    program_name = strrchr(argv[0], '/');
    program_name = program_name ? program_name + 1 : argv[0];

    const char *manufacturer = 0;

    device = getenv("TINI_DEVICE");
    if (!device)
	device = DEVICE;

    setenv("TZ", "UTC", 1);
    tzset();

    opterr = 0;
    while (1) {
	static struct option options[] = {
	    { "device",          required_argument, 0, 'd' },
	    { "directory",       required_argument, 0, 'D' },
	    { "help",            no_argument,       0, 'h' },
	    { "overwrite",       no_argument,       0, 'o' },
	    { "quiet",           no_argument,       0, 'q' },
	    { "manufacturer",    required_argument, 0, 'm' },
	    { "short-filenames", no_argument,       0, 's' },
	    { "log",             required_argument, 0, 'l' },
	    { 0,                 0,                 0, 0 },
	};
	int c = getopt_long(argc, argv, ":D:d:hl:m:oqs", options, 0);
	if (c == -1)
	    break;
	switch (c) {
	    case 'D':
		if (chdir(optarg) == -1)
		    error("chdir: %s: %s", optarg, strerror(errno));
		break;
	    case 'd':
		device = optarg;
		break;
	    case 'h':
		usage();
		exit(EXIT_SUCCESS);
	    case 'l':
		if (strcmp(optarg, "-") == 0)
		    logfile = stdout;
		else {
		    logfile = fopen(optarg, "a");
		    if (!logfile)
			error("fopen: %s: %s", optarg, strerror(errno));
		}
		break;
	    case 'm':
		manufacturer = optarg;
		break;
	    case 'o':
		overwrite = 1;
		break;
	    case 'q':
		quiet = 1;
		break;
	    case 's':
		igc_filename_format = igc_filename_format_short;
		break;
	    case ':':
		error("option '%c' requires an argument", optopt);
	    case '?':
		error("invalid option '%c'", optopt);
	}
    }

    flytec_t *flytec = flytec_new(device, logfile);
    if (!manufacturer) {
	flytec_pbrsnp(flytec);
	manufacturer = flytec->manufacturer;
    }
    if (optind == argc || strcmp(argv[optind], "do") == 0 || strcmp(argv[optind], "download") == 0) {
	++optind;
	set_t *indexes = 0;
	for (; optind < argc; ++optind)
	    indexes = set_merge(indexes, argv[optind]);
	tini_download(flytec, indexes, manufacturer, igc_filename_format);
	set_delete(indexes);
    } else {
	if (optind + 1 != argc)
	    error("excess argument%s on command line", argc - optind == 1 ? "" : "s");
	if (strcmp(argv[optind], "id") == 0) {
	    tini_id(flytec);
	} else if (strcmp(argv[optind], "ig") == 0 || strcmp(argv[optind], "igc") == 0) {
	    tini_igc(flytec);
	} else if (strcmp(argv[optind], "li") == 0 || strcmp(argv[optind], "list") == 0) {
	    tini_list(flytec, manufacturer, igc_filename_format);
	} else {
	    error("invalid command '%s'", argv[optind]);
	}
    }

    flytec_delete(flytec);
    if (logfile && logfile != stdout)
	fclose(logfile);

    return EXIT_SUCCESS;
}
Exemplo n.º 4
0
/* Calculates the value of FOLLOW for all nonterminals (and terminals
   while we're at it, but they're not useful).  Sets
   symbols[].follow. */
static void
precalc_follow (void)
{
  int i;

  for (i = 0; i < n_symbols; i++)
    set_init (&symbols[i].follow);

  set_add (&find_symbol (G[0].left)->follow, '$');

  for (;;)
    {
      int added = 0;
      
      for (i = 0; i < n_grammar; i++)
	{
	  const struct production *prod;
	  struct symbol *A;
	  int j;

	  prod = &G[i];
	  A = find_symbol (prod->left);
	  for (j = 0; j < prod->n_right - 1; j++)
	    {
	      struct symbol *B;
	      struct set first_Beta;

	      B = find_symbol (prod->right[j]);
	      calc_first (&first_Beta,
			  &prod->right[j + 1], prod->n_right - (j + 1));
	      added |= set_merge (&B->follow, &first_Beta, 0);

	      if (set_contains (&first_Beta, 0))
		added |= set_merge (&B->follow, &A->follow, 1);

	      set_free (&first_Beta);
	    }
	  
	  if (prod->n_right > 0)
	    {
	      struct symbol *B = find_symbol (prod->right[prod->n_right - 1]);
	      added |= set_merge (&B->follow, &A->follow, 1);
	    }
	}

      if (!added)
	break;
    }

  if (debug) 
    {
      printf ("FOLLOW function:\n");
      for (i = 0; i < n_symbols; i++)
	{
	  struct symbol *sym = &symbols[i];

	  if (!sym->nonterminal)
	    continue;
	  printf ("\tFOLLOW(%c) = ", sym->sym);
	  set_print (&sym->follow);
	  putchar ('\n');
	}
    }
}