int main(int argc, char** argv) {
    int index;

    umask(0);

    if (argc < 5) {
        print_usage();
        exit(-1);
    }

    strcpy(tmp_dir, EER_DEFAULT_TMP);

    for (index = 1; index < argc; index++) {
        if (strlen(argv[index]) != 2) {
            arg_error = 1;
            index = argc;
        } else if (strncmp(argv[index], "-i", 2) == 0) {
            // Input filename
            if (index == argc - 1) {
                arg_error = 1;
                printf("Missing input filename.\n\n");
                index = argc;
            } else if (strlen(argv[index + 1]) > PATH_MAX - 1) {
                arg_error = 2;
                index = argc;
            } else {
                index++;
                strcpy(input_filename, argv[index]);
                if (!path_exists(input_filename)) {
                    arg_error = 4;
                    printf("Input filename '%s' does not exist.\n\n",
                           input_filename);
                    index = argc;
                }
            }
        } else if (strncmp(argv[index], "-o", 2) == 0) {
            // Output filename
            if (index == argc - 1) {
                arg_error = 1;
                printf("Missing output filename.\n\n");
                index = argc;
            } else if (strlen(argv[index + 1]) > PATH_MAX - 1) {
                arg_error = 2;
                index = argc;
            } else {
                index++;
                strcpy(output_filename, argv[index]);
            }
        } else if (strncmp(argv[index], "-t", 2) == 0) {
            // Temp folder specified
            if (index == argc - 1) {
                arg_error = 1;
                printf("Missing temp directory parameter.\n\n");
                index = argc;
            } else if (strlen(argv[index + 1]) > PATH_MAX - 1) {
                arg_error = 2;
                index = argc;
            } else {
                index++;
                strcpy(tmp_dir, argv[index]);
                if (!path_exists(tmp_dir)) {
                    arg_error = 5;
                    printf("Temp directory '%s' does not exist.\n\n",
                           tmp_dir);
                    index = argc;
                }
            }
        } else if (strncmp(argv[index], "-d", 2) == 0) {
            dont_unzip = 1;
        } else if (strncmp(argv[index], "-c", 2) == 0) {
            check_ramdisk = 1;
        } else if (strncmp(argv[index], "-u", 2) == 0) {
            use_dump_image = 1;
        } else if (strncmp(argv[index], "-0", 2) == 0) {
            ramdisk_loc = 1;
        } else if (strncmp(argv[index], "-2", 2) == 0) {
            ramdisk_loc = 3;
        } else {
            arg_error = 3;
            printf("Invalid argument '%s'.\n\n", argv[index]);
            index = argc;
        }
    }

    if (arg_error != 0) {
        print_usage();
        exit(-1);
    } else {
        extract_ramdisk();
        exit(0);
    }
}
Exemplo n.º 2
0
int main(int argc, const char** argv) {
	return extract_ramdisk(argc, argv);
}