dbe_disp.c
来自「db.* (pronounced dee-be star) is an adva」· C语言 代码 · 共 686 行 · 第 1/2 页
C
686 行
/*************************************************************************** * * * db.* * * open source database, dbedit utility * * * * Copyright (c) 2000 Centura Software Corporation. All rights reserved. * * * * Use of this software, whether in source code format, or in executable, * * binary object code form, is governed by the CENTURA OPEN SOURCE LICENSE * * which is fully described in the LICENSE.TXT file, included within this * * distribution of source code files. * * * **************************************************************************//*----------------------------------------------------------------------- dbe_disp.c - DBEDIT, display command This file contains all the functions for the display command (i.e. to output the contents of the current record).-----------------------------------------------------------------------*//* ********************** INCLUDE FILES ****************************** */#include "db.star.h"#include "dbe_type.h"#include "dbe_str.h"#include "dbe_io.h"#include "dbe_err.h"#include "dbe_ext.h"#define DBEDIT#include "cnvfld.h"int disp(DBE_TOK *tokens, int *tokenptr, DB_TASK *task){ int n, token, error, option; error = 0; token = *tokenptr + 1; if ((error = dbe_chkdba(task->curr_rec, task)) == BAD_DBA) error = ERR_CREC; if (error >= 0) { error = 0; if (tokens[token].parent != token - 1 || tokens[token].type == 0) { /* Next token isn't an argument of disp command, or else there isn't another token, i.e. display everything */ if ((error = disp_type(task)) != 0) return error; if ((error = disp_dba()) != 0) return error; if ((error = disp_ts(task)) != 0) return error; if ((error = disp_opt(task)) != 0) return error; if ((error = disp_set(-1, task)) != 0) return error; if ((error = disp_mem(-1, task)) != 0) return error; if ((error = disp_fld(-1, task)) != 0) return error; } else { switch (option = tokens[token++].ival) { case K_TYPE: error = disp_type(task); break; case K_DBA: error = disp_dba(); break; case K_TS: error = disp_ts(task); break; case K_OPT: error = disp_opt(task); break; case K_SET: case K_MEM: case K_FLD: n = -1; if ((tokens[token].parent == token - 1) && (tokens[token].type != 0)) { n = tokens[token++].ival; } if (option == K_SET) error = disp_set(n, task); else if (option == K_MEM) error = disp_mem(n, task); else error = disp_fld(n, task); break; default: break; } } } *tokenptr = token; return (error);}/* ********************** Display type ******************************* */int disp_type(DB_TASK *task){ short rec_type; DB_TCHAR hex_line[50], ascii_line[30 + NAMELEN]; /* Get record type */ if ((rec_type = getrtype(slot.buffer, task)) == -1) return (BAD_TYPE); /* Print title */ if (titles) disp_str(DB_TEXT(""), dbe_getstr(M_DISPRT)); /* Print type */ do_hex(slot.address, slot.buffer, hex_line, sizeof(short)); vstprintf(ascii_line, DB_TEXT("%s (%d)"), task->record_names[rec_type], rec_type); disp_str(hex_line, ascii_line); if (titles) dbe_out(DB_TEXT("\n"), STDOUT); return (0);}/* ***************** Display dba - database address ****************** */int disp_dba(){ DB_ADDR dba; DB_TCHAR hex_line[50], ascii_line[50]; short file; DB_ULONG rec_num; /* Get dba */ memcpy(&dba, slot.buffer + sizeof(short), DB_ADDR_SIZE); /* Print title */ if (titles) disp_str(DB_TEXT(""), dbe_getstr(M_DISPDA)); /* Print dba */ do_hex(slot.address + sizeof(short), slot.buffer + sizeof(short), hex_line, DB_ADDR_SIZE); d_decode_dba(dba, &file, &rec_num); vstprintf(ascii_line, decimal ? DB_TEXT("[%d:%lu]") : DB_TEXT("[%x:%lx]"), file, rec_num); disp_str(hex_line, ascii_line); if (titles) dbe_out(DB_TEXT("\n"), STDOUT); return (0);}/* ************* Display ts - creation & update timestamp ************ */int disp_ts(DB_TASK *task){ DB_TCHAR hex_line[50], ascii_line[50]; short rec_type; DB_ULONG cts, uts; int n; /* Get record type and check whether record is timestamped */ if ((rec_type = getrtype(slot.buffer, task)) == -1) return (BAD_TYPE); if (!(task->record_table[rec_type].rt_flags & TIMESTAMPED)) return(0); /* Print title */ if (titles) disp_str(DB_TEXT(""), dbe_getstr(M_DISPCU)); /* Get timestamps */ memcpy(&cts, slot.buffer + RECCRTIME, sizeof(DB_ULONG)); memcpy(&uts, slot.buffer + RECUPTIME, sizeof(DB_ULONG)); /* Print timestamps */ n = do_hex(slot.address + RECCRTIME, slot.buffer + RECCRTIME, hex_line, 2 * sizeof(DB_ULONG)); vstprintf(ascii_line, DB_TEXT("%06ld/%06ld"), (long) cts, (long) uts); disp_str(hex_line, ascii_line); if (n < (int) (2 * sizeof(DB_ULONG))) { do_hex(-1L, slot.buffer + RECCRTIME + n, hex_line, 2 * sizeof(DB_ULONG) - n); ascii_line[0] = 0; disp_str(hex_line, ascii_line); } if (titles) dbe_out(DB_TEXT("\n"), STDOUT); return (0);}/* *************** Display opt - optional key bit map **************** */int disp_opt(DB_TASK *task){ short rec; register int fld; int n, first, last, count, bytes, offset; DB_TCHAR hex_line[50], ascii_line[50]; char *p; long addr; /* Get record type */ if ((rec = getrtype(slot.buffer, task)) == -1) return (BAD_TYPE); /* Count optional keys */ first = task->record_table[rec].rt_fields; last = first + task->record_table[rec].rt_fdtot; for (count = 0, fld = first; fld < last; fld++) if (task->field_table[fld].fd_flags & OPTKEYMASK) count++; if (count == 0) return(0); /* Print title */ if (titles) disp_str(DB_TEXT(""), dbe_getstr(M_DISPOK)); /* Work out where optional key bit map starts */ offset = task->record_table[rec].rt_flags & TIMESTAMPED ? RECHDRSIZE + 2 * sizeof(DB_ULONG) : RECHDRSIZE; /* Test for, and print stored keys */ addr = slot.address + offset; p = slot.buffer + offset; fld = first; bytes = (count + BITS_PER_BYTE - 1) / BITS_PER_BYTE; ascii_line[0] = hex_line[0] = 0; while ((fld < last) || (bytes > 0)) { if (fld < last) { if (task->field_table[fld].fd_flags & OPTKEYMASK) { /* Found on optional key */ if (testopt(fld, slot.buffer, task)) { /* Found a stored optional key - will it fit on line */ if (vtstrlen(ascii_line) + vtstrlen(task->field_names[fld]) + 3 > ASCII_BYTES) { /* 3 for commas & spaces */ vtstrcat(ascii_line, DB_TEXT(",")); if (bytes > 0) { n = do_hex(addr, p, hex_line, bytes); p += n; bytes -= n; addr = -1L; } else { hex_line[0] = 0; } disp_str(hex_line, ascii_line); ascii_line[0] = hex_line[0] = 0; } /* Append key name to line */ if (ascii_line[0]) vtstrcat(ascii_line, DB_TEXT(", ")); vtstrcat(ascii_line, task->field_names[fld]); } } fld++; } else { n = do_hex(addr, p, hex_line, bytes); p += n; bytes -= n; addr = -1L; disp_str(hex_line, ascii_line); ascii_line[0] = hex_line[0] = 0; } } if (ascii_line[0]) disp_str(hex_line, ascii_line); if (titles) dbe_out(DB_TEXT("\n"), STDOUT); return(0);}/* **************** Display set - set owner pointers ***************** */int disp_set(int setno, DB_TASK *task){ register int set; short rec; SET_PTR sp; DB_TCHAR hex_line[50], ascii_line[50]; char *p; int n, found, bytes, lineno, title; long addr; short fileF, fileL; DB_ULONG slotF, slotL; /* Get record type */ if ((rec = getrtype(slot.buffer, task)) == -1) return (BAD_TYPE); /* Print the sets */ for (set = title = found = 0; (set < task->size_st) && (! found); set++) { if (task->set_table[set].st_own_rt == rec) { if (setno >= 0) { if (set != setno) continue; found = 1; } bytes = (task->set_table[set].st_flags & TIMESTAMPED) ? SETPSIZE : SETPSIZE - sizeof(DB_ULONG); addr = slot.address + task->set_table[set].st_own_ptr; p = slot.buffer + task->set_table[set].st_own_ptr; memcpy(&sp, p, SETPSIZE); lineno = 0; while (bytes || (lineno < 3)) { if (bytes) { n = do_hex(addr, p, hex_line, bytes); bytes -= n; p += n; addr = -1L; } else { hex_line[0] = 0;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?