Exemple #1
0
void *list_actions(void *args) {
	t_args_plug *a;

	a = (t_args_plug*) args;
	if (strcmp(a->name, "volumes") == 0)
		list_volumes(a->general_info, a->commands[0]);
	else if (strcmp(a->name, "plugins") == 0)
		list_plugins(a->general_info, a->commands[0]);
	else if (strcmp(a->name, "help") == 0)
		printf("Usage; list [plugins | volumes] --verbose\n");
	return (NULL);
}
int main_plugin(int argc, char *argv[])
{
    int c;
    args_t *args  = (args_t*) calloc(1,sizeof(args_t));
    args->argc    = argc; args->argv = argv;
    args->files   = bcf_sr_init();
    args->output_fname = "-";
    args->output_type = FT_VCF;
    args->nplugin_paths = -1;
    int regions_is_file = 0, targets_is_file = 0, plist_only = 0;

    if ( argc==1 ) usage(args);
    char *plugin_name = NULL;
    if ( argv[1][0]!='-' ) { plugin_name = argv[1]; argc--; argv++; }

    static struct option loptions[] =
    {
        {"verbose",0,0,'v'},
        {"help",0,0,'h'},
        {"list-plugins",0,0,'l'},
        {"output",1,0,'o'},
        {"output-type",1,0,'O'},
        {"include",1,0,'i'},
        {"exclude",1,0,'e'},
        {"regions",1,0,'r'},
        {"regions-file",1,0,'R'},
        {"targets",1,0,'t'},
        {"targets-file",1,0,'T'},
        {0,0,0,0}
    };
    while ((c = getopt_long(argc, argv, "h?o:O:r:R:li:e:v",loptions,NULL)) >= 0)
    {
        switch (c) {
            case 'v': args->verbose = 1; break;
            case 'o': args->output_fname = optarg; break;
            case 'O':
                switch (optarg[0]) {
                    case 'b': args->output_type = FT_BCF_GZ; break;
                    case 'u': args->output_type = FT_BCF; break;
                    case 'z': args->output_type = FT_VCF_GZ; break;
                    case 'v': args->output_type = FT_VCF; break;
                    default: error("The output type \"%s\" not recognised\n", optarg);
                };
                break;
            case 'e': args->filter_str = optarg; args->filter_logic |= FLT_EXCLUDE; break;
            case 'i': args->filter_str = optarg; args->filter_logic |= FLT_INCLUDE; break;
            case 'r': args->regions_list = optarg; break;
            case 'R': args->regions_list = optarg; regions_is_file = 1; break;
            case 't': args->targets_list = optarg; break;
            case 'T': args->targets_list = optarg; targets_is_file = 1; break;
            case 'l': plist_only = 1; break;
            case '?':
            case 'h': load_plugin(args, plugin_name, 1, &args->plugin); fprintf(stderr,"%s",args->plugin.usage()); return 0; break;
            default: error("Unknown argument: %s\n", optarg);
        }
    }
    if ( plist_only )  return list_plugins(args);

    char *fname = NULL;
    if ( optind>=argc || argv[optind][0]=='-' )
    {
        if ( !isatty(fileno((FILE *)stdin)) ) fname = "-";  // reading from stdin
        else usage(args);
        args->plugin.argc = argc - optind + 1;
        args->plugin.argv = argv + optind - 1;
    }
    else
    {
        fname = argv[optind];
        args->plugin.argc = argc - optind;
        args->plugin.argv = argv + optind;
    }
    optind = 0;
    args->plugin.argv[0] = plugin_name;
    load_plugin(args, plugin_name, 1, &args->plugin);

    if ( args->regions_list )
    {
        if ( bcf_sr_set_regions(args->files, args->regions_list, regions_is_file)<0 )
            error("Failed to read the regions: %s\n", args->regions_list);
    }
    if ( args->targets_list )
    {
        if ( bcf_sr_set_targets(args->files, args->targets_list, targets_is_file, 0)<0 )
            error("Failed to read the targets: %s\n", args->targets_list);
        args->files->collapse |= COLLAPSE_SOME;
    }
    if ( !bcf_sr_add_reader(args->files, fname) ) error("Failed to open or the file not indexed: %s\n", fname);

    init_data(args);
    while ( bcf_sr_next_line(args->files) )
    {
        bcf1_t *line = bcf_sr_get_line(args->files,0);
        if ( args->filter )
        {
            int pass = filter_test(args->filter, line, NULL);
            if ( args->filter_logic & FLT_EXCLUDE ) pass = pass ? 0 : 1;
            if ( !pass ) continue;
        }
        line = args->plugin.process(line);
        if ( line ) bcf_write1(args->out_fh, args->hdr_out, line);
    }
    destroy_data(args);
    bcf_sr_destroy(args->files);
    free(args);
    return 0;
}
Exemple #3
0
int main(int carg, char *varg[])
{
	size_t i;
	char *filename;
	char *dir;
	char *metafile;
	pup_mode_t mode;
	plugin_t *p;
	
	filename = NULL;
	dir = NULL;
	metafile = NULL;
	mode = NONE;
	p = NULL;

	for(i = 1; i < carg; i++)
	{
		if (strcmp(varg[i], "--plugin") == 0)
		{
			i++;
			if ((i < carg) && (strncmp(varg[i], "--", 2) != 0))
				p = select_plugin(varg[i]);
		}
		else if (strcmp(varg[i], "--pack") == 0)
		{
			mode = PACK;
			i++;
			if ((i < carg) && (strncmp(varg[i], "--", 2) != 0))
				filename = varg[i];
			i++;
			if ((i < carg) && (strncmp(varg[i], "--", 2) != 0))
				dir = varg[i];
			i++;
			if ((i < carg) && (strncmp(varg[i], "--", 2) != 0))
				metafile = varg[i];
		}
		else if (strcmp(varg[i], "--unpack") == 0)
		{
			mode = UNPACK;
			i++;
			if ((i < carg) && (strncmp(varg[i], "--", 2) != 0))
				filename = varg[i];
			i++;
			if ((i < carg) && (strncmp(varg[i], "--", 2) != 0))
				dir = varg[i];
			i++;
			if ((i < carg) && (strncmp(varg[i], "--", 2) != 0))
				metafile = varg[i];
		}
		else if (strcmp(varg[i], "--print") == 0)
		{
			mode = PRINT;
			i++;
			if ((i < carg) && (strncmp(varg[i], "--", 2) != 0))
				filename = varg[i];
		}
		else if (strcmp(varg[i], "--savemeta") == 0)
		{
			mode = SAVEMETA;
			i++;
			if ((i < carg) && (strncmp(varg[i], "--", 2) != 0))
				filename = varg[i];
			i++;
			if ((i < carg) && (strncmp(varg[i], "--", 2) != 0))
				metafile = varg[i];
		}
		else if (strcmp(varg[i], "--list") == 0)
			mode = LIST;
		else
		{
			fprintf(stderr, "Unknown option: %s\n", varg[i]);
			return 1;
		}
	}
	
	if ((filename == NULL) && ((mode == PACK) || (mode == UNPACK) || (mode == PRINT) || (mode == SAVEMETA)))
	{
		fprintf(stderr, "You must specify filename for this mode.\n");
		return 2;
	}
	if ((metafile == NULL) && (mode == SAVEMETA))
	{
		fprintf(stderr, "You must specify metafile for this mode.\n");
		return 2;
	}
	
	if (mode == LIST)
		list_plugins();
	else if (mode == PACK)
	{
		if (pack(p, filename, dir, metafile) == FALSE)
			return 3;
	}
	else if (mode == UNPACK)
	{
		if (unpack(p, filename, dir, metafile) == FALSE)
			return 4;
	}
	else if (mode == SAVEMETA)
	{
		if (savemeta(p, filename, metafile) == FALSE)
			return 5;
	}
	else if (mode == PRINT)
	{
		if (print(p, filename) == FALSE)
			return 7;
	}
	else
	{
		fprintf(stdout, "Usage: pup --list\n"
						"       pup --plugin <plugin> --pack <file> [<dir> [<meta>]]\n"
						"       pup [--plugin <plugin>] --unpack <file> [<dir> [<meta>]]\n"
						"       pup [--plugin <plugin>] --savemeta <file> [<meta>]\n"
						"       pup [--plugin <plugin>] --print <file>\n"
						"Options:\n"
						"       --plugin <plugin>\t\t - specify certain plugin\n");
		fprintf(stdout,		 	"Modes:\n"
						"       --list\t\t\t\t - list of all supported plugins\n"
						"       --pack <file> [<dir> [<meta>]]\t - packing dir to specified file\n"
						"       --unpack <file> [<dir> [<meta>]]\t - unpacking specified file to dir\n"
						"       --savemeta <file> [<meta>]\t - only save metadata to specified metafile\n"
						"       --print <file>\t\t\t - print technical information to stdout\n");
		return 8;
	}
	return 0;
}
Exemple #4
0
int main(int argc, char *argv[])
{
	int c, cmd, ret;
	conf_info_t info = {0};
	char *config = DEFAULT_INTERNAL;
	xmlKeepBlanksDefault(0);
	xmlTreeIndentString = "\t";
	
	if (argc < 2) {
		usage(argv[0]);
		return 1;
	}
	
	cmd = command_decode(argv[1]);

	/* parse params */
	while ((c = getopt_long(argc, argv, OPTSTRING, long_opts, NULL)) != -1) {
		switch (c) {
		case 'h':
			usage(argv[0]);
			return 0;
		case 'c':
			config = optarg;
			break;
		case 'p':
			switch (optarg[0]) {
			case 'i': case 'I':
				info.type = PL_INPUT;
				break;
			case 'm': case 'M':
				info.type = PL_INTERMEDIATE;
				break;
			case 'o': case 'O':
				info.type = PL_OUTPUT;
				break;
			default:
				fprintf(stderr, "Unknown plugin type '%c'\n", optarg[0]);
				return 1;
			}
			break;
		case 'n':
			info.name = optarg;
			break;
		case 's':
			info.sofile = optarg;
			break;
		case 't':
			info.thread = optarg;
			break;
		case 'f':
			info.force = 1;
			break;
		default:
			return 1;
		}
	}
	
	ret = open_xml(&info, config);
	if (ret != 0) {
		return 1;
	}
	
	switch (cmd) {
		case CMD_ADD:
			ret = add_plugin(&info);
			break;
		case CMD_REMOVE:
			ret = remove_plugin(&info);
			break;
		case CMD_LIST:
			ret = list_plugins(&info);
			break;
		default:
			fprintf(stderr, "Unknown command '%s'\n", argv[1]);
			ret = 1;
			break;
	}
	
	if (ret == 0 && cmd != CMD_LIST) {
		save_xml(&info, config);
	}
	
	close_xml(&info);
	
	return ret;
}