예제 #1
0
파일: main.c 프로젝트: roccof/tinycalc
int main(int argc, char **argv)
{
        int decres = 0;
        char binres[MAX_BIT_BIN + 1];
        Lex *lex = NULL;

        if (argc != 2) {
                usage(argv[0]);
        }

        lex = lex_init(argv[1]);
        if (lex == NULL) {
                show_error("syntax analizator not initialized");
        }

        decres = parse(lex);

        lex_free(lex);

        /* Convert result in binary format */
        dec2bin((unsigned int)abs(decres), binres);

        /* Print the result */
        if (decres < 0) {
                printf("\n\t%d\t\t\t-0x%x\t\t\t-0b%s\n\n", decres, decres, binres);
        } else {
                printf("\n\t%d\t\t\t0x%x\t\t\t0b%s\n\n", decres, decres, binres);
        }

        return 0;
}
예제 #2
0
파일: binport.c 프로젝트: EQ4/Pd-for-LibPd
static void binport_free(t_binport *bp)
{
    fclose(bp->b_fp);
    if (bp->b_symtable)
	freebytes(bp->b_symtable, bp->b_symsize * sizeof(*bp->b_symtable));
    if (bp->b_old)
    {
	bp->b_old->o_fp = 0;
	binpold_free(bp->b_old);
    }
    if (bp->b_lex)
    {
	bp->b_lex->l_fp = 0;
	lex_free(bp->b_lex);
    }
    freebytes(bp, sizeof(*bp));
}
예제 #3
0
static STANDARDIZER *
CreateStd(char *lextab, char *gaztab, char *rultab)
{
    STANDARDIZER        *std;
    LEXICON             *lex;
    LEXICON             *gaz;
    RULES               *rules;
    int                  err;
    int                  SPIcode;

    DBG("Enter: CreateStd");
    SPIcode = SPI_connect();
    if (SPIcode != SPI_OK_CONNECT) {
        elog(ERROR, "CreateStd: couldn't open a connection to SPI");
    }

    std = std_init();
    if (!std)
        elog(ERROR, "CreateStd: could not allocate memory (std)");

    lex = lex_init(std->err_p);
    if (!lex) {
        std_free(std);
        SPI_finish();
        elog(ERROR, "CreateStd: could not allocate memory (lex)");
    }

    err = load_lex(lex, lextab);
    if (err == -1) {
        lex_free(lex);
        std_free(std);
        SPI_finish();
        elog(ERROR, "CreateStd: failed to load '%s' for lexicon", lextab);
    }

    gaz = lex_init(std->err_p);
    if (!gaz) {
        lex_free(lex);
        std_free(std);
        SPI_finish();
        elog(ERROR, "CreateStd: could not allocate memory (gaz)");
    }

    err = load_lex(gaz, gaztab);
    if (err == -1) {
        lex_free(gaz);
        lex_free(lex);
        std_free(std);
        SPI_finish();
        elog(ERROR, "CreateStd: failed to load '%s' for gazeteer", gaztab);
    }

    rules = rules_init(std->err_p);
    if (!rules) {
        lex_free(gaz);
        lex_free(lex);
        std_free(std);
        SPI_finish();
        elog(ERROR, "CreateStd: could not allocate memory (rules)");
    }

    err = load_rules(rules, rultab);
    if (err == -1) {
        rules_free(rules);
        lex_free(gaz);
        lex_free(lex);
        std_free(std);
        SPI_finish();
        elog(ERROR, "CreateStd: failed to load '%s' for rules", rultab);
    }

    std_use_lex(std, lex);
    std_use_gaz(std, gaz);
    std_use_rules(std, rules);
    std_ready_standardizer(std);

    SPI_finish();

    return std;
}