Exemplo n.º 1
0
/*
=======================================
    主程序
=======================================
*/
int main (int argc, char *argv[])
{
    fbuf_t file;
    const ansi_t *root;

    /* 建立 CrHack 系统 */
    if (!set_app_type(CR_APP_CUI))
        return (QST_ERROR);

    /* 参数解析 [搜索根目录] */
    if (argc < 1) {
        printf("filehash [directory]\n");
        return (QST_ERROR);
    }

    /* 生成性能测试对象 */
    s_profile = timer_new();

    /* 生成输出文件 */
    file_deleteA("__hash__.old");
    file_renameA("__hash__.old", "__hash__.txt");
    file = file_buf_openA("__hash__.txt", CR_FO_WO);
    if (file == NULL) {
        printf("can't create output file\n");
        return (QST_ERROR);
    }

    /* 枚举所有文件 */
    if (argc == 1)
        root = "";
    else
        root = argv[1];
    s_rdata = NULL;
    mem_info(&s_total, &s_avail);
    s_total = (s_total * 618) / 1000;
    file_searchA(root, TRUE, FALSE, FALSE, "*.*", hasher, file);

    /* 释放内存 */
    file_buf_close(file);
    timer_del(s_profile);
    TRY_FREE(s_rdata);
    return (QST_OKAY);
}
Exemplo n.º 2
0
/*
=======================================
    命令行主函数
=======================================
*/
int main (int argc, char *argv[])
{
    sCP_PARAM ft;

    /* 建立 CrHack 系统 */
    if (!set_app_type(CR_APP_CUI))
        return (QST_ERROR);

    /* 参数解析 <源编码> <目标编码> <搜索根目录> <通配符> */
    if (argc < 5) {
        usage();
        return (QST_ERROR);
    }

    /* 填充结构 */
    ft.tot = ft.cvt = 0;
    ft.from = str2intA(argv[1]);
    if (ft.from == CR_LOCAL)
        ft.from = get_sys_codepage();
    ft.to = str2intA(argv[2]);
    if (ft.to == CR_LOCAL)
        ft.to = get_sys_codepage();

    /* 已经是 UTF-8 的文件不用转换 */
    if (ft.to == CR_UTF8)
        ft.skip_utf8 = TRUE;
    else
        ft.skip_utf8 = FALSE;

    /* 两个编码值相等表示删除 UTF-8 BOM 标志 */
    if (ft.from == ft.to)
        ft.del_u8_bom = TRUE;
    else
        ft.del_u8_bom = FALSE;

    /* 子目录递归 + 跳过隐藏目录和文件 */
    file_searchA(argv[3], TRUE, TRUE, FALSE, argv[4], do_each_file, &ft);
    printf("%u file(s) found. %u file(s) converted.\n", ft.tot, ft.cvt);
    return (QST_OKAY);
}