dbe_disp.c

来自「db.* (pronounced dee-be star) is an adva」· C语言 代码 · 共 686 行 · 第 1/2 页

C
686
字号
                }                switch (lineno)                {                    case 0:                        d_decode_dba(sp.first, &fileF, &slotF);                        d_decode_dba(sp.last, &fileL, &slotL);                        vstprintf(ascii_line, decimal ?                            DB_TEXT("%ld [%d:%ld] [%d:%ld]") :                            DB_TEXT("%lx [%x:%lx] [%x:%lx]"),                            (long) (sp.total), fileF, slotF, fileL, slotL);                        break;                    case 1:                        if (task->set_table[set].st_flags & TIMESTAMPED)                        {                            vstprintf(ascii_line, DB_TEXT("%06ld"), (long) (sp.timestamp));                            break;                        }                        lineno++;                        /* fall thru ? */                    case 2:                        vtstrcpy(ascii_line, task->set_names[set]);                        break;                    default:                        ascii_line[0] = 0;                        break;                }                lineno++;                if (titles && !title)                {                    disp_str(DB_TEXT(""), dbe_getstr(M_DISPSO));                    title = 1;                }                disp_str(hex_line, ascii_line);            }        }    }    if (title)        dbe_out(DB_TEXT("\n"), STDOUT);    return ((setno < 0 || found) ? 0 : ERR_OSET);}/* **************** Display mem - set member pointers **************** */int disp_mem(int setno, DB_TASK *task){    register int   set, mem;    short          rec;    MEM_PTR        mp;    DB_TCHAR       hex_line[50], ascii_line[50];    char          *p;    int            n, found, first, last, bytes, lineno, title;    long           addr;    short          fileO, fileP, fileN;    DB_ULONG       slotO, slotP, slotN;    /* Get record type */    if ((rec = getrtype(slot.buffer, task)) == -1)        return (BAD_TYPE);    for (set = title = found = 0; (set < task->size_st) && (! found); set++)    {        if (setno >= 0 && set != setno)            continue;        first = task->set_table[set].st_members;        last = first + task->set_table[set].st_memtot;        for (mem = first; mem < last && !found; mem++)        {            if (task->member_table[mem].mt_record == rec)            {                if (setno >= 0)                    found = 1;                bytes = MEMPSIZE;                addr = slot.address + task->member_table[mem].mt_mem_ptr;                p = slot.buffer + task->member_table[mem].mt_mem_ptr;                memcpy(&mp, p, MEMPSIZE);                lineno = 0;                while (bytes || (lineno < 2))                {                    if (bytes)                    {                        n = do_hex(addr, p, hex_line, bytes);                        bytes -= n;                        p += n;                        addr = -1L;                    }                    else                    {                        hex_line[0] = 0;                    }                    switch (lineno)                    {                        case 0:                            d_decode_dba(mp.owner, &fileO, &slotO);                            d_decode_dba(mp.prev, &fileP, &slotP);                            d_decode_dba(mp.next, &fileN, &slotN);                            vstprintf(ascii_line, decimal ?                                DB_TEXT("[%d:%ld] [%d:%ld] [%d:%ld]") :                                DB_TEXT("[%x:%lx] [%x:%lx] [%x:%lx]"),                                fileO, slotO, fileP, slotP, fileN, slotN);                            break;                        case 1:                            vtstrcpy(ascii_line, task->set_names[set]);                            break;                        default:                            ascii_line[0] = 0;                            break;                    }                    lineno++;                    if (titles && !title)                    {                        disp_str(DB_TEXT(""), dbe_getstr(M_DISPSM));                        title = 1;                    }                    disp_str(hex_line, ascii_line);                }            }        }    }    if (title)        dbe_out(DB_TEXT("\n"), STDOUT);    return ((setno < 0 || found) ? 0 : ERR_MSET);}/* ******************** Display fld - data fields ******************** */int disp_fld(int fldno, DB_TASK *task){    register int   fld;    short          rec;    DB_TCHAR       hex_line[50], ascii_line[30 + NAMELEN], *ascii_ptr;    char          *hex_ptr;    int            n, found, first, last, hex_len;    size_t         ascii_len;    long           addr;    static DB_TCHAR ascii_buff[1600];    if (!fields)        return (0);    /* Get record type */    if ((rec = getrtype(slot.buffer, task)) == -1)        return (BAD_TYPE);    /* Do fields */    first = task->record_table[rec].rt_fields;    last = first + task->record_table[rec].rt_fdtot;    for (fld = first, found = 0; (fld < last) && (! found); fld++)    {        if (fldno >= 0)        {            if (fld != fldno)                continue;            found = 1;        }        if (task->field_table[fld].fd_flags & STRUCTFLD)            continue;        /* Work out offsets */        addr = slot.address + task->field_table[fld].fd_ptr;        hex_ptr = slot.buffer + task->field_table[fld].fd_ptr;        ascii_len = hex_len = task->field_table[fld].fd_len;        /* Store ascii representation of field, if it'll fit */        if (ascii_len > sizeof(ascii_buff) / sizeof(DB_TCHAR))        {            ascii_buff[0] = 0;            ascii_len = 0;        }        else        {            fldtotxt(fld, hex_ptr, ascii_buff, !decimal, task);            ascii_len = vtstrlen(ascii_buff);        }        ascii_ptr = ascii_buff;        /* Print field title */        if (titles)        {            vtstrcpy(ascii_line, dbe_getstr(M_DISPFD));            vtstrcat(ascii_line, task->field_names[fld]);            disp_str(DB_TEXT(""), ascii_line);        }        /* Print field contents */        while ((ascii_len > 0) || (hex_len > 0))        {            if (ascii_len > 0)            {                n = do_ascii(ascii_ptr, ascii_line, ascii_len);                ascii_len -= n;                ascii_ptr += n;            }            else            {                ascii_line[0] = 0;            }            if (hex_len > 0)            {                n = do_hex(addr, hex_ptr, hex_line, hex_len);                hex_len -= n;                hex_ptr += n;                addr = -1L;            }            else            {                hex_line[0] = 0;            }            disp_str(hex_line, ascii_line);        }/*        if ( titles )            dbe_out( DB_TEXT("\n"), STDOUT );*/    }    return ((fldno < 0 || found) ? 0 : ERR_RFLD);}/* ********************* Miscellaneous functions ********************* *//* Display a line of hex & ascii output*/int disp_str(DB_TCHAR *hex_str, DB_TCHAR *ascii_str){    DB_TCHAR line[LINELEN];    vstprintf(line, DB_TEXT("%-45.45s  %s\n"), hex_str, ascii_str);    dbe_out(line, STDOUT);    return 0;}/* Convert byte string into hex representation, with file address*/int do_hex(long addr, char *in_str, DB_TCHAR *out_str, int len){    int addrlen;    if (len > HEX_BYTES)        len = HEX_BYTES;    if (addr >= 0L)        vstprintf(out_str,            decimal ? DB_TEXT("%06ld:   ") : DB_TEXT(" %05lx:   "), addr);    else        vtstrcpy(out_str, DB_TEXT("          "));    if ((addrlen = vtstrlen(out_str)) > 13)        out_str[addrlen - 3] = 0;    else if (addrlen > 10)        out_str[10] = 0;    do_hexstr(in_str, out_str, len);    return (len);}/* Convert byte string into hex representation, without file address*/DB_TCHAR *do_hexstr(char *in_str, DB_TCHAR *out_str, int len){    int i;    while (*out_str)        out_str++;    for (i = 0; i < len; i++)    {        vstprintf(out_str, DB_TEXT("%02x "), (0xFF & (int) in_str[i]));        out_str += 3;    }    *out_str = 0;    return (out_str);}/* Copy ascii string, checking length*/int do_ascii(DB_TCHAR *in_str, DB_TCHAR *out_str, int len){    if (len > ASCII_BYTES)        len = ASCII_BYTES;    vtstrncpy(out_str, in_str, len);    out_str[len] = 0;    return (len);}/* Get record type from slot*/short getrtype(char *buffer, DB_TASK *task){    short rec_type;    memcpy(&rec_type, buffer, sizeof(short));    if (rec_type < 0)        rec_type = (short) (~rec_type);    if (rec_type & RLBMASK)        rec_type &= ~RLBMASK;    if ((rec_type < 0) || (rec_type >= task->size_rt))        rec_type = -1;      /* error condition */    return (rec_type);}/* Test whether optional key has been stored*/int testopt(int field,   /* Field table index of optional key */            char *rec,   /* Pointer to record */            DB_TASK *task){    int offset;                         /* offset to the bit map */    int keyndx;                         /* index into bit map of this key */    int byteno, bitno;                  /* position within bit map of this                                         * key */    /* calculate the position to the bit map */    offset = task->record_table[task->field_table[field].fd_rec].rt_flags & TIMESTAMPED ?        RECHDRSIZE + 2 * sizeof(long) : RECHDRSIZE;    /* extract the index into the bit map of this key */    keyndx = (((task->field_table[field].fd_flags & OPTKEYMASK) >> OPTKEYSHIFT)             & OPTKEYNDX) - 1;    if (keyndx < 0)        return (0);    /* determine which byte, and which bit within the byte */    byteno = keyndx / BITS_PER_BYTE;    bitno = keyndx % BITS_PER_BYTE;    /* extract the bit */    if (*(rec + offset + byteno) & (1 << (BITS_PER_BYTE - bitno - 1)))        return (1);    else        return (0);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?