コード例 #1
0
ファイル: hex.c プロジェクト: dgdunix/qemacs-tmp
static int hex_display(EditState *s, DisplayState *ds, int offset)
{
    int j, len, ateof;
    int offset1, offset2;
    unsigned char b;

    display_bol(ds);

    ds->style = QE_STYLE_COMMENT;
    display_printf(ds, -1, -1, "%08x ", offset);

    ateof = 0;
    len = s->b->total_size - offset;
    if (len > s->disp_width)
        len = s->disp_width;

    if (s->mode == &hex_mode) {

        ds->style = QE_STYLE_FUNCTION;

        for (j = 0; j < s->disp_width; j++) {
            display_char(ds, -1, -1, ' ');
            offset1 = offset + j;
            offset2 = offset1 + 1;
            if (j < len) {
                eb_read(s->b, offset1, &b, 1);
                display_printhex(ds, offset1, offset2, b, 2);
            } else {
                if (!ateof) {
                    ateof = 1;
                } else {
                    offset1 = offset2 = -1;
                }
                ds->cur_hex_mode = s->hex_mode;
                display_printf(ds, offset1, offset2, "  ");
                ds->cur_hex_mode = 0;
            }
            if ((j & 7) == 7)
                display_char(ds, -1, -1, ' ');
        }
        display_char(ds, -1, -1, ' ');
    }
    ds->style = 0;

    display_char(ds, -1, -1, ' ');

    ateof = 0;
    for (j = 0; j < s->disp_width; j++) {
        offset1 = offset + j;
        offset2 = offset1 + 1;
        if (j < len) {
            eb_read(s->b, offset1, &b, 1);
        } else {
            b = ' ';
            if (!ateof) {
                ateof = 1;
            } else {
                offset1 = offset2 = -1;
            }
        }
        display_char(ds, offset1, offset2, to_disp(b));
    }
    display_eol(ds, -1, -1);

    if (len >= s->disp_width)
        return offset + len;
    else
        return -1;
}
コード例 #2
0
ファイル: mpeg.c プロジェクト: kjk/qemacs
static int mpeg_display(EditState *s, DisplayState *ds, int offset)
{
    unsigned int startcode;
    int ret, badchars, offset_start;
    unsigned char buf[4];

    /* search start code */

    badchars = 0;

    display_bol(ds);
    display_printf(ds, -1, -1,  "%08x:", offset);
    for (;;) {
        ret = eb_read(s->b, offset, buf, 4);
        if (ret == 0) {
            if (badchars)
                display_eol(ds, -1, -1);
            goto the_end;
        }
        
        if (ret == 4) {
            startcode = (buf[0] << 24) | (buf[1] << 16) | (buf[2]  << 8) | buf[3];
            if ((startcode & 0xffffff00) == 0x00000100) {
                if (badchars) {
                    display_eol(ds, -1, -1);
                    display_bol(ds);
                    display_printf(ds, -1, -1,  "%08x:", offset);
                }
                break;
            }
        }
        /* display unknown chars */
        display_printf(ds, -1, -1, " [");
        display_printhex(ds, offset, offset + 1, buf[0], 2);
        display_printf(ds, -1, -1, "]");
        offset++;
        if (++badchars == 8) {
            badchars = 0;
            display_eol(ds, -1, -1);
            goto the_end;
        }
    }
    offset_start = offset;
    offset += 4;
    display_printf(ds, offset_start, offset, " [%08x] ", startcode);
        
    switch (startcode) {
    case SEQ_END_CODE:
        display_printf(ds, -1, -1, "SEQ_END");
        break;
    case SEQ_START_CODE:
        display_printf(ds, -1, -1, "SEQUENCE");
        break;
    case PICTURE_START_CODE:
        display_printf(ds, -1, -1, "PICTURE");
        break;
    case GOP_START_CODE:
        display_printf(ds, -1, -1, "GOP");
        break;
    case EXT_START_CODE:
        display_printf(ds, -1, -1, "EXT");
        break;
    case PACK_START_CODE:
        display_printf(ds, -1, -1, "PACK");
        break;
    case SYSTEM_HEADER_START_CODE:
        display_printf(ds, -1, -1, "SYSTEM");
        break;
    default:
        if (startcode >= SLICE_MIN_START_CODE &&
            startcode <= SLICE_MAX_START_CODE) {
            display_printf(ds, -1, -1, "SLICE %d", startcode & 0xff);
        } else {
            display_printf(ds, -1, -1, "UNKNOWN", startcode);
        }
        break;
    }

    display_eol(ds, -1, -1);
 the_end:
    return offset;
}