datdump.c
来自「db.* (pronounced dee-be star) is an adva」· C语言 代码 · 共 637 行 · 第 1/2 页
C
637 行
d_encode_dba(fno, rno, &dba); /* read record */ if ( dio_read(dba, &rec, NOPGHOLD, task) != S_OKAY ) return(1); /* get and interpret record identification number */ memcpy(&rid, rec, sizeof(short)); rtn = rid; if (rtn < 0) { deleted = TRUE; rtn = (short) ~rtn; } else { deleted = FALSE; } if (rtn & RLBMASK) { rlb = TRUE; rtn &= ~RLBMASK; } else { rlb = FALSE; } /* print first line of record dump */ addr = phys_addr(fno, rno, task); vtprintf(DB_TEXT("SLOT: %-7ld ADDR: %lxH TYPE: %s\n"), rno, addr, task->record_names[rtn]); if (header || formatted) { /* print formatted header info */ pr_rechdr(rid, rtn, rlb, deleted, rec, task); } if (formatted) { /* print field contents */ pr_fields(rtn, rec, task); } if (hex) { /* print hex dump */ pr_hex(rtn, addr, rec, task); } vtprintf(DB_TEXT("\n")); return(0);}/* Print data file header info **********************************************/static void pr_filehdr( FILE_NO fno, DB_TCHAR *datfile, DB_TCHAR *dbname, DB_TASK *task){ DB_TCHAR buf[80]; d_dbver(DB_TEXT("%V"), buf, sizeof(buf) / sizeof(DB_TCHAR)); vtprintf(DB_TEXT("%s\n"), buf); vtprintf(DB_TEXT("Data File Dump Utility\n")); d_dbver(DB_TEXT("%C"), buf, sizeof(buf) / sizeof(DB_TCHAR)); vtprintf(DB_TEXT("%s\n"), buf); vtprintf(DB_TEXT("------------------------------------")); vtprintf(DB_TEXT("------------------------------------\n")); vtprintf(DB_TEXT("DATA FILE : %s\n"), datfile); vtprintf(DB_TEXT("DATABASE : %s\n"), dbname); vtprintf(DB_TEXT("TIMESTAMP : %lu\n"), task->pgzero[fno].pz_timestamp); vtprintf(DB_TEXT("PAGE SIZE : %d\n"), task->file_table[fno].ft_pgsize); vtprintf(DB_TEXT("SLOT SIZE : %d\n"), task->file_table[fno].ft_slsize); vtprintf(DB_TEXT("SLOTS PER PAGE: %d\n"), task->file_table[fno].ft_slots); vtprintf(DB_TEXT("NEXT SLOT : %ld (%08lX)\n"), task->pgzero[fno].pz_next, task->pgzero[fno].pz_next); vtprintf(DB_TEXT("DELETE CHAIN : %ld (%08lX)\n"), task->pgzero[fno].pz_dchain, task->pgzero[fno].pz_dchain); vtprintf(DB_TEXT("------------------------------------")); vtprintf(DB_TEXT("------------------------------------\n\n\n"));}/* Print record header ******************************************************/static void pr_rechdr( short rid, short rtn, DB_BOOLEAN rlb, DB_BOOLEAN deleted, char *rec, DB_TASK *task){ DB_BOOLEAN printed; DB_ADDR dba; long cts, uts; register int fld, set, mbr; short fileO, fileF, fileL; DB_ULONG slotO, slotF, slotL; SET_PTR sp; MEM_PTR mp; /* get database address */ memcpy(&dba, rec + sizeof(short), sizeof(DB_ADDR)); /* print general info */ vtprintf(DB_TEXT(" RID: %04hX RLB: %s "), rid, (rlb ? "set " : "clear")); if (deleted) { vtprintf(DB_TEXT("DELETED, NEXT AT %lu\n"), dba); return; } d_decode_dba(dba, &fileO, &slotO); vtprintf(DB_TEXT("DBA: [%03d:%07lu] "), fileO, slotO); /* print any timestamp info */ if (task->record_table[rtn].rt_flags & TIMESTAMPED) { /* get and print timestamps */ memcpy(&cts, rec + RECCRTIME, sizeof(long)); memcpy(&uts, rec + RECUPTIME, sizeof(long)); vtprintf(DB_TEXT("CTIME: %06lu UTIME: %06lu"), cts, uts); } vtprintf(DB_TEXT("\n")); /* print any optional key settings */ for ( printed = FALSE, fld = task->record_table[rtn].rt_fields; fld < task->record_table[rtn].rt_fields + task->record_table[rtn].rt_fdtot; ++fld) { if (task->field_table[fld].fd_flags & OPTKEYMASK) { if (!printed) { vtprintf(DB_TEXT("\n STORED OPT KEYS: ")); printed = TRUE; } if (tstopt(fld, rec, task) == S_DUPLICATE) vtprintf(DB_TEXT("%s "), task->field_names[fld]); } } if (printed) vtprintf(DB_TEXT("\n")); /* print any set pointers */ for (printed = FALSE, set = 0; set < task->size_st; ++set) { if (task->set_table[set].st_own_rt == rtn) { /* print set pointer */ if (! printed) { /* print set pointer header */ vtprintf( DB_TEXT("\n SET POINTER COUNT FIRST LAST")); if (task->set_table[set].st_flags & TIMESTAMPED) vtprintf(DB_TEXT(" UTIME")); vtprintf(DB_TEXT("\n")); printed = TRUE; } memcpy(&sp, rec + task->set_table[set].st_own_ptr, SETPSIZE); d_decode_dba(sp.first, &fileF, &slotF); d_decode_dba(sp.last, &fileL, &slotL); vtprintf(DB_TEXT(" %3d %-20.20s %06lu [%03d:%07lu] [%03d:%07lu]"), set, task->set_names[set], sp.total, fileF, slotF, fileL, slotL); if (task->set_table[set].st_flags & TIMESTAMPED) vtprintf(DB_TEXT(" %06lu"), sp.timestamp); vtprintf(DB_TEXT("\n")); } } /* print any member pointers */ for (printed = FALSE, set = 0; set < task->size_st; ++set) { for ( mbr = task->set_table[set].st_members; mbr < task->set_table[set].st_members + task->set_table[set].st_memtot; ++mbr) { if (task->member_table[mbr].mt_record == rtn) { /* print member pointer */ if (! printed) { /* print member pointer header */ vtprintf( DB_TEXT("\n MEMBER POINTER OWNER PREVIOUS NEXT\n")); printed = TRUE; } memcpy(&mp, rec + task->member_table[mbr].mt_mem_ptr, MEMPSIZE); d_decode_dba(mp.owner, &fileO, &slotO); d_decode_dba(mp.prev, &fileF, &slotF); d_decode_dba(mp.next, &fileL, &slotL); vtprintf( DB_TEXT(" %3d %-20.20s [%03d:%07lu] [%03d:%07lu] [%03d:%07lu]\n"), set, task->set_names[set], fileO, slotO, fileF, slotF, fileL, slotL); } } }}/* Print the field contents *************************************************/static void pr_fields(short rtn, char *rec, DB_TASK *task){ int fld; DB_TCHAR buf[MAXTEXT]; if (task->record_table[rtn].rt_fdtot <= 0) return; vtprintf(DB_TEXT("\n FIELD CONTENTS\n")); /* for each field type in record */ for ( fld = task->record_table[rtn].rt_fields; fld < task->record_table[rtn].rt_fields + task->record_table[rtn].rt_fdtot; ++fld) { if (task->field_table[fld].fd_flags & STRUCTFLD) continue; vtprintf(DB_TEXT(" %4d %-20.20s "), fld, task->field_names[fld]); fldtotxt(fld, rec + task->field_table[fld].fd_ptr, buf, 0, task); vtprintf(DB_TEXT("%s\n"), buf); }}/* Print hex dump of record contents ****************************************/static void pr_hex(short rtn, F_ADDR addr, char *rec, DB_TASK *task){ DB_TCHAR hln[50]; DB_TCHAR cln[30]; int p; register int i; for (hln[0] = cln[0] = 0, i = 0; i < task->record_table[rtn].rt_len; ++i) { p = i % 12; if (p == 0) { /* print previous line */ vtprintf(DB_TEXT("%-45.45s %s\n"), hln, cln); /* print new address */ vstprintf(hln, DB_TEXT(" %05lX: "), addr + i); } vstprintf(hln + (p * 3) + 10, DB_TEXT("%02X "), (0xFF & (int) rec[i])); vstprintf(cln + (p * 2), DB_TEXT(" %c"), (rec[i] < ' ' || rec[i] > '~') ? '.' : rec[i]); } vtprintf(DB_TEXT("%-45.45s %s\n"), hln, cln);}/* Calculate a physical address from a database address *********************/static F_ADDR phys_addr(FILE_NO fno, F_ADDR rno, DB_TASK *task){ F_ADDR page, offset, addr; page = (rno - 1L) / + 1L; offset = (F_ADDR) task->file_table[fno].ft_slsize * ((rno - 1L) % (F_ADDR) task->file_table[fno].ft_slots) + PGHDRSIZE; addr = page * (F_ADDR) task->file_table[fno].ft_pgsize + offset; return (addr);}/* Test the optional key field "stored" bit *********************************/static int tstopt( 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 (dberr(S_SYSERR)); /* 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 (S_DUPLICATE); else return (S_OKAY);}/* Print usage message and exit *********************************************/static void usage(){ vftprintf(stderr, DB_TEXT("usage: datdump [-x] [-f] [-h] [-rN] [-sg [<mode>,]<password>] dbname filename\n")); vftprintf(stderr, DB_TEXT(" where -x selects hex output only (no formatted output)\n")); vftprintf(stderr, DB_TEXT(" -f selects formatted output only (no hex output)\n")); vftprintf(stderr, DB_TEXT(" -h selects header info only (no field info)\n")); vftprintf(stderr, DB_TEXT(" -r prints record at slot N only\n")); vftprintf(stderr, DB_TEXT(" -sg specifies the encryption information for the database\n")); vftprintf(stderr, DB_TEXT(" <mode> can be 'low', 'med' (default), or 'high'\n")); vftprintf(stderr, DB_TEXT("Default is both formatted and hex print of entire file.\n")); vftprintf(stderr, DB_TEXT("To see list of data files, omit filename from command line.\n"));}VXSTARTUP("datdump", 0)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?