Beispiel #1
0
int main(int argc, char *argv[])
{
   int first,i;
   char* f;
   group_t* group;
   int sh_override = -1;
   int list_packages = 0;

   for (i=1; i<argc && *argv[i] == '-'; i++)
   {
      for (f=argv[i]+1; *f; f++)
         switch (*f)
         {
            case 'v':
               debugging = 1;
               silent = 0;
               break;
            case 's':
               debugging = 0;
               silent = 1;
               break;
            case 'c':
               sh_override = 1;
               break;
            case 'b':
               sh_override = 0;
               break;
            case 'f':
               main_package_filename = argv[++i];
               break;
            case 'l':
               list_packages = 1;
               break;
            default:
               fprintf(stderr, "usepackage: unrecognised flag '%c'\n", *f);
               exit(1);
         }
   }

   if (!list_packages && (i >= argc))
   {
      fprintf(stderr, "\n%s %s, %s\n", PACKAGE_NAME, PACKAGE_VERSION, COPYRIGHT);
      fprintf(stderr, "Bug reports and comments to: %s\n", PACKAGE_BUGREPORT);
      fprintf(stderr, "Discussion/announcement list: %s\n\n", MAILING_LIST);
      fprintf(stderr, "usage: use [-vs] [-f <file>] <package> [<package>...]\n");
      fprintf(stderr, "       use -l\n\n");
      fprintf(stderr, "       -v : verbose\n");
      fprintf(stderr, "       -s : silence match warnings\n");
      fprintf(stderr, "       -f : use <file> as main packages file\n");
      fprintf(stderr, "       -l : list available packages\n\n");
      exit(1);
   }

   DEBUG(stderr, "%s\n", PACKAGE_NAME);
   DEBUG(stderr, "Version: %s\n", PACKAGE_VERSION);
   DEBUG(stderr, "%s\n", COPYRIGHT);

   uname(&the_host_info);
   DEBUG(stderr, "host: %s\n", the_host_info.nodename);
   DEBUG(stderr, "operating system: %s %s\n", the_host_info.sysname,
         the_host_info.release);
   DEBUG(stderr, "architecture: %s\n", the_host_info.machine);

   the_shell = get_user_shell();
   DEBUG(stderr, "shell: %s\n", the_shell);

   if (sh_override != -1)
      csh_user = sh_override;
   else
      csh_user = ((!strcmp(the_shell, "csh")) || (!strcmp(the_shell, "tcsh")));

   the_environment = new_list();
   the_scripts = new_list();
   
   if (get_packages(&the_packages, &the_groups, &the_annotations))
   {
      fprintf(stderr, "usepackage: couldn't load package information.\n");
      exit(2);
   }

   if (list_packages)
   {
      fprintf(stderr, "\nusepackage %s, %s\n\n", VERSION, COPYRIGHT);
      fprintf(stderr, "Available packages are:\n\n");
      list_annotations();
      fprintf(stderr, "\nAvailable groups are:\n\n");
      list_groups();
      fprintf(stderr, "\n");
      exit(0);
   }

   for (first = i, i = argc - 1 ; i >= first ; i--)
   {
      if (group = get_group(argv[i]))
         use_group(group);
      else
         use_package(argv[i]);
   }

   print_env();

   print_scripts();

   return(0);
}
Beispiel #2
0
dstring_t *haplo_split(GapIO *io, snp_t *snp, int nsnps, int verbose,
		       double min_score, int two_pass, int fast_mode,
		       double c_offset, int max_sets) {
    graph *g;
    edge *e;
    dstring_t *ds;

    verbosity = verbose;
    g = graph_from_snps(io, snp, nsnps, c_offset);
    if (verbosity >= 3)
	print_matrix(g);

    graph_add_edges(g);
    graph_calc_chimeric_scores(g);
    graph_calc_link_scores(g, 1);
    if (verbosity >= 3)
	graph_print(g, 0);

    if (verbosity)
	puts("Merging graph nodes");

    while ((e = best_edge(g)) && (e->linkage_score > min_score)) {
	if (verbosity >= 1) {
	    putchar('.');
	    fflush(stdout);
	}
	merge_node(g, e);
	graph_calc_link_scores(g, fast_mode ? 0 : 1);
	if (verbosity >= 4) {
	    print_matrix(g);
	    graph_print(g, 1);
	}
    }
    if (verbosity >= 1)
	puts("");

    /* graph_print(g, 1); */

    if (two_pass) {
	/* Add fake zero-score edges if we want just 2-haplotypes */
	add_zero_edges(g);
	graph_calc_link_scores(g, 1);
	if (verbosity >= 4)
	    graph_print(g, 1);

	puts("===pass 2===");
	while ((e = best_edge(g)) && (e->linkage_score > min_score)) {
	    merge_node(g, e);
	    graph_calc_link_scores(g, fast_mode ? 0 : 1);
	    /* graph_print(g, 1); */
	}
	/* graph_print(g, 1); */
    }

    /* Force number of groups to be X? */
    if (max_sets) {
	int ngroups = count_groups(g);
	add_zero_edges(g);
	for (; ngroups > max_sets; ngroups--) {
	    e = best_edge(g);
	    if (!e) {
		printf("Bailed out as no edge connecting groups\n");
		break;
	    }
	    merge_node(g, e);
	    graph_calc_link_scores(g, fast_mode ? 0 : 1);
	}
    }

    /* print_groups(g); */

    ds = list_groups(g);
    graph_destroy(g);

    return ds;
}
int main_0019_list_groups (int argc, char **argv) {
	const char *topic = test_mk_topic_name(__FUNCTION__, 1);
#define _CONS_CNT 2
        char *groups[_CONS_CNT];
	rd_kafka_t *rk, *rk_c[_CONS_CNT];
	rd_kafka_topic_partition_list_t *topics;
	rd_kafka_resp_err_t err;
        test_timing_t t_grps;
	int i;
        int groups_seen;
	rd_kafka_topic_t *rkt;

        /* Handle for group listings */
        rk = test_create_producer();

	/* Produce messages so that topic is auto created */
	rkt = test_create_topic_object(rk, topic, NULL);
	test_produce_msgs(rk, rkt, 0, 0, 0, 10, NULL, 64);
	rd_kafka_topic_destroy(rkt);

        /* Query groups before creation, should not list our groups. */
        groups_seen = list_groups(rk, NULL, 0, "should be none");
        if (groups_seen != 0)
                TEST_FAIL("Saw %d groups when there wasn't "
                          "supposed to be any\n", groups_seen);

	/* Fill in topic subscription set */
	topics = rd_kafka_topic_partition_list_new(1);
	rd_kafka_topic_partition_list_add(topics, topic, -1);

	/* Create consumers and start subscription */
	for (i = 0 ; i < _CONS_CNT ; i++) {
                groups[i] = malloc(32);
                test_str_id_generate(groups[i], 32);
		rk_c[i] = test_create_consumer(groups[i],
					       NULL, NULL, NULL);

		err = rd_kafka_poll_set_consumer(rk_c[i]);
		if (err)
			TEST_FAIL("poll_set_consumer: %s\n",
				  rd_kafka_err2str(err));

		err = rd_kafka_subscribe(rk_c[i], topics);
		if (err)
			TEST_FAIL("subscribe: %s\n", rd_kafka_err2str(err));
	}

        rd_kafka_topic_partition_list_destroy(topics);


        TIMING_START(&t_grps, "WAIT.GROUPS");
        /* Query groups again until both groups are seen. */
        while (1) {
                int groups_seen = list_groups(rk, (char **)groups, _CONS_CNT,
                                              "should see my groups");
                if (groups_seen == _CONS_CNT)
                        break;
                rd_sleep(1);
        }
        TIMING_STOP(&t_grps);


	TEST_SAY("Closing remaining consumers\n");
	for (i = 0 ; i < _CONS_CNT ; i++) {
		test_timing_t t_close;
		if (!rk_c[i])
			continue;

		TEST_SAY("Closing %s\n", rd_kafka_name(rk_c[i]));
		TIMING_START(&t_close, "CONSUMER.CLOSE");
		err = rd_kafka_consumer_close(rk_c[i]);
		TIMING_STOP(&t_close);
		if (err)
			TEST_FAIL("consumer_close failed: %s\n",
				  rd_kafka_err2str(err));

		rd_kafka_destroy(rk_c[i]);
		rk_c[i] = NULL;

                free(groups[i]);
	}

        rd_kafka_destroy(rk);

        return 0;
}
Beispiel #4
0
Load_Balancer::Group_List *
Object_Group_Factory_i::random_groups (void)
{
  return list_groups (1);
}
Beispiel #5
0
Load_Balancer::Group_List *
Object_Group_Factory_i::round_robin_groups (void)
{
  return list_groups (0);
}
Beispiel #6
0
/* 
 * Read and process buxfer commands
 * Return -1 to indicate user has quit
 * Return 1 to indicate broadcast message must be sent to all other users
 * Return 0 otherwise
 */
int process_args(int cmd_argc, char **cmd_argv, Client *c, Pool *p) 
{
    Group *g;
    char *buf;
    char *username = c->username;

    if (cmd_argc <= 0) {
        return 0;

    } else if (strcmp(cmd_argv[0], "quit") == 0 && cmd_argc == 1) {
        return -1;  // -1 indicates used has quit
        
    } else if (strcmp(cmd_argv[0], "add_group") == 0 && cmd_argc == 2) {
        
        // add group
        buf = add_group(&p->group, cmd_argv[1]);  
        Write(c->soc, buf);

        // add user
        if ((g = find_group(p->group, cmd_argv[1])) == NULL) {    
            buf = "Cannot add user. Group does not exist";    
        } else{
            buf = add_user(g, username);                               
            strncpy(c->groupname, cmd_argv[1], MAXLINE);    // set groupname for this client            
            Write(c->soc, buf);   
            return 1;       // Return 1 indicates notification should be sent to all other users
        }   

    } else if (strcmp(cmd_argv[0], "list_groups") == 0 && cmd_argc == 1) {
        buf = list_groups(p->group);
    
    } else if (strcmp(cmd_argv[0], "list_users") == 0 && cmd_argc == 2) {
        if ((g = find_group(p->group, cmd_argv[1])) == NULL) {
            buf = "Group does not exist";
        } else {
            buf = list_users(g);
        }
      
    } else if (strcmp(cmd_argv[0], "user_balance") == 0 && cmd_argc == 2) {
        if ((g = find_group(p->group, cmd_argv[1])) == NULL) {
            buf = "Group does not exist";
        } else {
            buf = user_balance(g, username);            
        }
        
    } else if (strcmp(cmd_argv[0], "add_xct") == 0 && cmd_argc == 3) {
        if ((g = find_group(p->group, cmd_argv[1])) == NULL) {
            buf = "Group does not exist";            
        } else {
            char *end;
            double amount = strtod(cmd_argv[2], &end);
            if (end == cmd_argv[2]) {
                buf = "Incorrect number format";
            } else {
                buf = add_xct(g, username, amount);
            }
        }

    } else {
        buf = "Incorrect syntax";
    }

    // Write output to client
    Write(c->soc, buf);     // Write output to client
    return 0;
}