Пример #1
0
static void parse_option_chkimg(int argc, char** argv, cmd_opt* option){
    static const char *sopt = "-hd::L:s:f:CXFNiB";
    static const struct option lopt[] = {
        { "help",		no_argument,	    NULL,   'h' },
        { "source",		required_argument,  NULL,   's' },
        { "debug",		optional_argument,  NULL,   'd' },
        { "UI-fresh",	required_argument,  NULL,   'u' },
        { "check",		no_argument,	    NULL,   'C' },
        { "logfile",	required_argument,  NULL,   'L' },
        { "force",		no_argument,	    NULL,   'F' },
	{ "ignore_crc",     no_argument,    NULL,   'i' },
	{ "no_block_detail",     no_argument,    NULL,   'B' },
#ifdef HAVE_LIBNCURSESW
        { "ncurses",		no_argument,	    NULL,   'N' },
#endif
        { NULL,			0,		    NULL,    0  }
    };

    char c;
    memset(option, 0, sizeof(cmd_opt));
    option->debug = 0;
    option->check = 1;
    option->restore = 1;
    option->chkimg = 1;
    option->ignore_crc = 0;
    option->no_block_detail = 0;
    option->logfile = "/var/log/partclone.log";
    while ((c = getopt_long(argc, argv, sopt, lopt, NULL)) != (char)-1) {
        switch (c) {
            case 's': 
                option->source = optarg;
                break;
            case 'h':
                usage_chkimg();
                break;
            case '?':
                usage_chkimg();
                break;
            case 'd':
                if (optarg)
                    option->debug = atol(optarg);
                else
                    option->debug = 1;
                break;
            case 'L': 
                option->logfile = optarg;
                break;
            case 'f':
                option->fresh = atol(optarg);
                break;
            case 'F':
                option->force++;
		break;
	    case 'i':
		option->ignore_crc = 1;
		break;
	    case 'B':
		option->no_block_detail = 1;
		break;
#ifdef HAVE_LIBNCURSESW
            case 'N':
                option->ncurses = 1;
                break;
#endif
            case 'C':
                option->check = 0;
                break;
            default:
                fprintf(stderr, "Unknown option '%s'.\n", argv[optind-1]);
                usage_chkimg();
        }
    }

    if (!option->debug){
        option->debug = 0;
    }

    if (option->source == NULL){
        fprintf(stderr, "There is no image name. or --help get more info.\n");
        exit(0);
    }

}
Пример #2
0
static void parse_option_chkimg(int argc, char** argv, cmd_opt* option){
    static const char *sopt = "-hd::L:s:f:CXFN";
    static const struct option lopt[] = {
        { "help",		no_argument,	    NULL,   'h' },
        { "source",		required_argument,  NULL,   's' },
        { "debug",		optional_argument,  NULL,   'd' },
        { "UI-fresh",	required_argument,  NULL,   'u' },
        { "check",		no_argument,	    NULL,   'C' },
        { "dialog",		no_argument,	    NULL,   'X' },
        { "logfile",	required_argument,  NULL,   'L' },
        { "force",		no_argument,	    NULL,   'F' },
#ifdef HAVE_LIBNCURSESW
        { "ncurses",		no_argument,	    NULL,   'N' },
#endif
        { NULL,			0,		    NULL,    0  }
    };

    char c;
    memset(option, 0, sizeof(cmd_opt));
    option->debug = 0;
    option->check = 1;
    option->restore = 1;
    option->chkimg = 1;
    option->logfile = "/var/log/partclone.log";
    while ((c = getopt_long(argc, argv, sopt, lopt, NULL)) != (char)-1) {
        switch (c) {
            case 's': 
                option->source = optarg;
                break;
            case 'h':
                usage_chkimg();
                break;
            case '?':
                usage_chkimg();
                break;
            case 'd':
                if (optarg)
                    option->debug = atol(optarg);
                else
                    option->debug = 1;
                break;
            case 'L': 
                option->logfile = optarg;
                break;
            case 'f':
                option->fresh = atol(optarg);
                break;
            case 'F':
                option->force++;
                break;
            case 'X':
                /// output message as dialog format, reference
                /// dialog --guage is text height width percent
                ///    A guage box displays a meter along the bottom of the box. The meter indicates the percentage. New percentages are read from standard input, one integer per line. The meter is updated to reflect each new percentage. If stdin is XXX, then the first line following is taken as an integer percentage, then subsequent lines up to another XXX are used for a new prompt. The guage exits when EOF is reached on stdin. 
                option->dialog = 1;
                break;
#ifdef HAVE_LIBNCURSESW
            case 'N':
                option->ncurses = 1;
                break;
#endif
            case 'C':
                option->check = 0;
                break;
            default:
                fprintf(stderr, "Unknown option '%s'.\n", argv[optind-1]);
                usage_chkimg();
        }
    }

    if (!option->debug){
        option->debug = 0;
    }

    if (option->source == NULL){
        fprintf(stderr, "There is no image name. or --help get more info.\n");
        exit(0);
    }

}