Esempio n. 1
0
int
main(int argc, char *argv[])
{
    char *dic_base;
    int c;
    FILE *output[3];
    char path[PATH_MAX];
    da_build_t *builder;
    cha_mmap_t *tmpfile;

    cha_set_progpath(argv[0]);

    cha_set_encode("");
    while ((c = cha_getopt(argv, "i:", stderr)) != EOF) {
	switch (c) {
	case 'i':
	    cha_set_encode(Cha_optarg);
	    break;
	default:
	    usage();
	}
    }
    argv += Cha_optind;
    argc -= Cha_optind;

    if (argc < 2)
	usage();

    dic_base = argv[0];
    argv++;

    cha_read_grammar(stderr, 1, 2);
    cha_read_katuyou(stderr, 2);
    cha_read_table(stderr, 2);

    snprintf(path, PATH_MAX, "%s.da", dic_base);
    builder = da_build_new(path);
    snprintf(path, PATH_MAX, "%s.dat", dic_base);
    output[0] = cha_fopen(path, "wb", 1);
    snprintf(path, PATH_MAX, "%s.lex", dic_base);
    output[1] = cha_fopen(path, "wb", 1);
    snprintf(path, PATH_MAX, "%s.tmp", dic_base);
    output[2] = cha_fopen(path, "wb", 1);

    if (translate_files(argv, output, builder) < 0)
	exit(1);
    fclose(output[2]);

    tmpfile = cha_mmap_file(path);
    da_build_dump(builder, cha_mmap_map(tmpfile), output[1]);
    cha_munmap_file(tmpfile);

    remove(path);

    return EXIT_SUCCESS;
}
Esempio n. 2
0
int
main(int argc, const char **argv)
{
    int res = 0;
    int optCount = 0;

    dbgIn = stdin;
    conOut = stdout;
    (void)conIn;
    (void)dbgOut;

    memset(&cache, 0, sizeof(LIST));
    memset(&sources, 0, sizeof(LIST));
    stat_clear(&summ);
    memset(&revinfo, 0, sizeof(REVINFO));
    clearLastLine();

    optionInit(argc, argv);
    optCount = optionParse(argc, argv);
    if (optCount < 0)
    {
        return optCount;
    }

    argc -= optCount;

    if (opt_Revision && (strcmp(opt_Revision, "update") == 0))
    {
        res = updateSvnlog();
        return res;
    }

    if (check_directory(opt_force))
        return 3;

    create_cache(opt_force, 0);
    if (opt_exit)
        return 0;

    read_cache();
    l2l_dbg(4, "Cache read complete\n");

    if (set_LogFile(&logFile))
        return 2;
    l2l_dbg(4, "opt_logFile processed\n");

    if (opt_Pipe)
    {
        l2l_dbg(3, "Command line: \"%s\"\n",opt_Pipe);

        if (!(dbgIn = POPEN(opt_Pipe, "r")))
        {
            dbgIn = stdin; //restore
            l2l_dbg(0, "Could not popen '%s' (%s)\n", opt_Pipe, strerror(errno));
            free(opt_Pipe); opt_Pipe = NULL;
        }
    }
    l2l_dbg(4, "opt_Pipe processed\n");

    if (argc > 1)
    {   // translate {<exefile> <offset>}
        int i = 1;
        const char *exefile = NULL;
        const char *offset = NULL;
        char Line[LINESIZE + 1];

        while (i < argc)
        {
            Line[0] = '\0';
            offset = argv[optCount + i++];
            if (isOffset(offset))
            {
                if (exefile)
                {
                    l2l_dbg(2, "translating %s %s\n", exefile, offset);
                    translate_file(exefile, my_atoi(offset), Line);
                    printf("%s\n", Line);
                    report(conOut);
                }
                else
                {
                    l2l_dbg(0, "<exefile> expected\n");
                    res = 3;
                    break;
                }
            }
            else
            {
                // Not an offset so must be an exefile:
                exefile = offset;
            }
        }
    }
    else
    {   // translate logging from stdin
        translate_files(dbgIn, conOut);
    }

    if (logFile)
        fclose(logFile);

    if (opt_Pipe)
        PCLOSE(dbgIn);

    return res;
}