Ejemplo n.º 1
0
int main(int argc, char** argv)
{
    command_t cmd;
    command_init(&cmd, "dhcore-test", "1.0");    
    command_option_pos(&cmd, "test", "Choose unit test", TRUE, cmd_gettest);
    command_parse(&cmd, argc, argv, NULL);

    if (IS_FAIL(core_init(CORE_INIT_ALL)))     {
        printf("core init error.\n");
        return -1;
    }

    log_outputconsole(TRUE);

    if (g_testidx == -1)
        g_testidx = show_help();

    if (g_testidx != -1) 
        g_tests[g_testidx].test_fn();

#if defined(_DEBUG_)
    core_release(TRUE);
#else
    core_release(FALSE);
#endif
    return 1;
}
Ejemplo n.º 2
0
int main(int argc, char** argv)
{
    struct paki_args args;

    // read arguments
    memset(&args, 0x00, sizeof(args));

    args.compress_mode = COMPRESS_NORMAL;
    command_t cmd;
    command_init(&cmd, argv[0], VERSION);
    command_option_pos(&cmd, "pakfile", "pakfile (.pak)", 0, cmdline_pakfile);
    command_option_pos(&cmd, "path", "path to input directory (for compress mode) or"
                       " path to a file in pakfile (for extract mode)", 1, cmdline_path);
    command_option(&cmd, "-v", "--verbose", "enable verbose mode", cmdline_verbose);
    command_option(&cmd, "-l", "--list", "list files in pak", cmdline_list);
    command_option(&cmd, "-x", "--extract", "extract a file from pak", cmdline_extract);
    command_option(&cmd, "-c", "--compress", "compress a directory into pak", cmdline_compress);
    command_option(&cmd, "-z", "--zmode <mode>", "define compression mode, "
                   "compression modes are (none, normal, best, fast)", cmdline_compressmode);
    cmd.data = &args;
    command_parse(&cmd, argc, argv, NULL);
    command_free(&cmd);

    core_init(CORE_INIT_ALL);
    log_outputconsole(TRUE);

    /* check for arguments validity */
    if (args.pakfile[0] == 0 ||
            ((BIT_CHECK(args.usage, PAKI_USAGE_EXTRACT) +
              BIT_CHECK(args.usage, PAKI_USAGE_COMPRESS) +
              BIT_CHECK(args.usage, PAKI_USAGE_LIST)) != 1))
    {
        printf(TERM_BOLDRED "Invalid arguments\n" TERM_RESET);
        core_release(FALSE);
        return -1;
    }

    if (BIT_CHECK(args.usage, PAKI_USAGE_EXTRACT) || BIT_CHECK(args.usage, PAKI_USAGE_COMPRESS)) {
        if (str_isempty(args.path)) {
            printf(TERM_BOLDRED "'path' argument is not provided\n" TERM_RESET);
            core_release(FALSE);
            return -1;
        }
    }

    /* creating archive (-c flag) */
    if (BIT_CHECK(args.usage, PAKI_USAGE_COMPRESS))     {
        save_pak(&args);
    }   else if(BIT_CHECK(args.usage, PAKI_USAGE_EXTRACT))  {
        load_pak(&args);
    } else if(BIT_CHECK(args.usage, PAKI_USAGE_LIST))	{
        list_pak(&args);
    }

#if defined(_DEBUG_)
    core_release(TRUE);
#else
    core_release(FALSE);
#endif
    return 0;
}