Пример #1
0
/*
 * Print a term to an allocated string.
 */
extern char *show(term_t t)
{
    char *end = show_buf(NULL, NULL, t);
    size_t len = end - (char *)NULL;
    char *str = (char *)gc_malloc(len+1);
    show_buf(str, str+len+1, t);
    return str;
}
Пример #2
0
/*
 * Print a term to a file.
 */
extern void show_file(FILE *file, term_t t)
{
    char buf[1000];
    char *end = show_buf(buf, buf+sizeof(buf), t);
    if (end < buf+sizeof(buf))
    {
        fputs(buf, file);
        return;
    }
    else
    {
        char buf2[end-buf+1];
        show_buf(buf2, buf2+sizeof(buf2), t);
        fputs(buf2, file);
        return;
    }
}
Пример #3
0
/*
 * Write a constraint.
 */
extern char *solver_show_buf_cons(char *start, char *end, cons_t c)
{
    switch (c->sym->type)
    {
        case X_CMP_Y:
        {
            var_t x = var(c->args[X]);
            var_t y = var(c->args[Y]);
            char *cmp = (c->sym == EQ? "=": ">");
            return show_buf_var_op_var(start, end, x, cmp, y);
        }
        case X_CMP_C:
        {
            var_t x = var(c->args[X]);
            num_t k = num(c->args[Y]);
            char *cmp = (c->sym == EQ_C? "=": ">");
            return show_buf_var_op_num(start, end, x, cmp, k);
        }
        case X_EQ_Y_OP_Z:
        {
            var_t x = var(c->args[X]);
            var_t y = var(c->args[Y]);
            var_t z = var(c->args[Z]);
            char *op = (c->sym == EQ_PLUS? "+": "*");
            start = show_buf_var(start, end, x);
            start = show_buf_str(start, end, " = ");
            return show_buf_var_op_var(start, end, y, op, z);         
        }
        case X_EQ_Y_OP_C:
        {
            var_t x = var(c->args[X]);
            var_t y = var(c->args[Y]);
            num_t k = num(c->args[Z]);
            char *op = (c->sym == EQ_PLUS_C? "+": "*");
            start = show_buf_var(start, end, x);
            start = show_buf_str(start, end, " = ");
            return show_buf_var_op_num(start, end, y, op, k);
        }
        default:
        {
            sym_t sym = c->sym;
            start = show_buf_name(start, end, sym->name);
            start = show_buf_char(start, end, '(');
            for (size_t i = 0; i < sym->arity; i++)
            {
                start = show_buf(start, end, c->args[i]);
                if (i < sym->arity-1)
                    start = show_buf_char(start, end, ',');
            }
            start = show_buf_char(start, end, ')');
            return start;
        }
    }
}
Пример #4
0
static void read_eeprom(__bit verbose)
{
    writeln_uart("Read test: [");

    if (read_block_eeprom(0, buf, SIZE_BUF) == 1) {
        writeln_uart("ERR_I2C]\r\n");
        return;
    }

    if (buf[SIZE_BUF-1] != crc8(buf, SIZE_BUF-1, CRC_POLYNOM)) // check crc8
        writeln_uart("ERR_CRC]\r\n");
    else
        writeln_uart("OK]\r\n");
    
    if(verbose)        
        show_buf();
}
Пример #5
0
static void write_eeprom(__bit verbose)
{
    uint32_t i;
    for(i = 0; i <= SIZE_BUF-2; i++)
        buf[i] = randomize();        
    
    buf[SIZE_BUF-1] = crc8(buf, SIZE_BUF-1, CRC_POLYNOM); // write crc8

    writeln_uart("Write test: [");

    if (write_block_eeprom(0, buf, SIZE_BUF) == 1)
        writeln_uart("ERR_I2C]\r\n");
    else
        writeln_uart("OK]\r\n");
    
    if(verbose)        
        show_buf();    
}
Пример #6
0
int get_avi_from_index(pes_in_t *p, int fd, avi_context *ac,
                       void (*func)(pes_in_t *p), int insize)
{
    struct replex *rx= (struct replex *) p->priv;
    avi_index *idx = ac->idx;
    int cidx = ac->current_idx;
    uint8_t buf[MAX_BUF_SIZE];
    uint32_t cid;
    int c=0;
    off_t pos=0;
    int per = 0;
    static int lastper=0;

    if (cidx > ac->num_idx_frames) return -2;

    switch(idx[cidx].id) {
    case TAG_IT('0','1','w','b'):
        p->type = 1;
        p->rbuf = &rx->arbuffer[0];
        break;

    case TAG_IT('0','0','d','c'):
        p->type = 0xE0;
        p->rbuf = &rx->vrbuffer;
        break;

    default:
        fprintf(stderr,"strange chunk :\n");
        show_buf((uint8_t *) &idx[cidx].id,4);
        fprintf(stderr,"offset: 0x%04x  length: 0x%04x\n",
                (int)idx[cidx].off, (int)idx[cidx].len);
        ac->current_idx++;
        p->found=0;
        return 0;
        break;
    }

    memset(buf, 0, MAX_BUF_SIZE);
    pos=lseek (fd, idx[cidx].off+ac->movi_start-4, SEEK_SET);
    read(fd,buf,idx[cidx].len);
    cid = getle32(buf);
    c+=4;
    p->plength = getsize_buf(buf+c);
//	show_buf(buf,16);
    if (idx[cidx].len > insize) return 0;

    if (idx[cidx].len > MAX_BUF_SIZE) {
        fprintf(stderr,"Buffer too small in get_avi_from_index\n");
        exit(1);
    }
    if (!idx[cidx].len) {
        func(p);
        ac->current_idx++;
        p->found=0;
        return 0;
    }
    if (cid != idx[cidx].id) {
        char *cc;
        cc = (char *)&idx[cidx].id;
        fprintf(stderr,"wrong chunk id: %c%c%c%c != %c%c%c%c\n",
                buf[0],buf[1],buf[2],buf[3]
                ,*cc,*(cc+1),*(cc+2),*(cc+3));

        print_index(ac,cidx);
        exit(1);
    }
    if (p->plength != idx[cidx].len) {
        fprintf(stderr,"wrong chunk size: %d != %d\n",
                (int)p->plength, idx[cidx].len);
        exit(1);
    }
    c+=4;
    p->done = 1;
    p->ini_pos = ring_wpos(p->rbuf);

    per = (int)(100*(pos-ac->movi_start)/ac->movi_length);
    if (per>lastper) fprintf(stderr,"read %3d%%\r", per);
    lastper = per;

    if (ring_write(p->rbuf, buf+c, p->plength)<0) {
        fprintf(stderr,	"ring buffer overflow %d 0x%02x\n"
                ,p->rbuf->size,p->type);
        exit(1);
    }

    func(p);
    init_pes_in(p, 0, NULL, p->withbuf);

    ac->current_idx++;

    return 0;
}
Пример #7
0
/*
 * Write a functor.
 */
extern char *show_buf_func(char *start, char *end, func_t f)
{
show_buf_func_restart: {}
    const char *name = atom_name(f->atom);
    uint_t a = atom_arity(f->atom);
    assoc_t assoc;
    unsigned priority;
    bool ac, space;

    if (a == 1 && unop_lookup(opinfo_init(), name, &priority, &space))
    {
        // A unary operator.
        bool b2 = show_needs_brackets(f->atom, f->args[0], 0, XFX, priority,
            false);
        start = show_buf_str(start, end, name);
        if (space)
            start = show_buf_char(start, end, ' ');
        if (!b2 && type(f->args[0]) == FUNC)
        {
            f = func(f->args[0]);
            goto show_buf_func_restart;     // Tail call optimization.
        }
        if (b2)
            start = show_buf_char(start, end, '(');
        start = show_buf(start, end, f->args[0]);
        if (b2)
            start = show_buf_char(start, end, ')');
        return start;
    }

    if (a == 2 && binop_lookup(opinfo_init(), name, &assoc, &priority, &ac,
            &space))
    {
        // A binary operator.
        bool b1 = show_needs_brackets(f->atom, f->args[0], 0, assoc, priority,
            ac);
        bool b2 = show_needs_brackets(f->atom, f->args[1], 1, assoc, priority,
            ac);
        if (b1)
            start = show_buf_char(start, end, '(');
        start = show_buf(start, end, f->args[0]);
        if (b1)
            start = show_buf_char(start, end, ')');
        if (space)
            start = show_buf_char(start, end, ' ');
        start = show_buf_str(start, end, name);
        if (space)
            start = show_buf_char(start, end, ' ');
        if (!b2 && type(f->args[1]) == FUNC)
        {
            f = func(f->args[1]);
            goto show_buf_func_restart;     // Tail call optimization.
        }
        if (b2)
            start = show_buf_char(start, end, '(');
        start = show_buf(start, end, f->args[1]);
        if (b2)
            start = show_buf_char(start, end, ')');
        return start;
    }

    // Not an operator:
    start = show_buf_name(start, end, name);
    if (a == 0)
    {
        start = show_buf_str(start, end, "()");
        return start;
    }

    start = show_buf_char(start, end, '(');
    for (uint_t i = 0; i < a-1; i++)
    {
        start = show_buf(start, end, f->args[i]);
        start = show_buf_char(start, end, ',');
    }
    start = show_buf(start, end, f->args[a-1]);
    start = show_buf_char(start, end, ')');
    return start;
}