dbe_show.c

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

C
635
字号
/*************************************************************************** *                                                                         * * 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_show.c - DBEDIT, show command    This file contains all the functions for the show command (i.e. to    output information about the database structure).-----------------------------------------------------------------------*/#include "db.star.h"#include "dbe_type.h"#include "dbe_str.h"#include "dbe_err.h"#include "dbe_io.h"#include "dbe_ext.h"int show(DBE_TOK *tokens, int *tokenptr, DB_TASK *task){    int i, token, error;    error = 0;    token = *tokenptr + 1;    /* If no argument was specified, show everything */    if (tokens[token].parent != token - 1 || tokens[token].type == 0)    {        show_nft(task);        show_nrt(-1, task);        show_nst(task);        show_nkt(task);        show_nfd(task);    }    else    {        switch (tokens[token++].ival)        {            case K_FLD:                if (tokens[token].parent == token - 1)                {                          /* One field */                    i = tokens[token++].ival;                    show_fd(&i, 0, 0, task);                }                else                {                    show_nfd(task);         /* All fields */                }                break;            case K_FILE:                if (tokens[token].parent == token - 1)                {                          /* One file */                    i = (tokens[token].type == TYPE_FIL) ?                        tokens[token].ival :                        (int) tokens[token].lval;                    if (i >= task->size_ft)                        error = BAD_FILE;                    else                        show_ft(i, task);    /* All files */                    token++;                }                else                {                    show_nft(task);                }                break;            case K_KEY:                if (tokens[token].parent == token - 1)                {                          /* One key */                    i = tokens[token++].ival;                    show_fd(&i, 0, 1, task);                }                else                {                    show_nkt(task);         /* All keys */                }                break;            case K_RECORD:                if (tokens[token].parent == token - 1)      /* One record */                    show_rt(tokens[token++].ival, task);                else                    show_nrt(-1, task);     /* All records */                break;            case K_SET:                if (tokens[token].parent == token - 1)      /* One set */                    show_st(tokens[token++].ival, task);                else                    show_nst(task);         /* All sets */                break;        }    }    *tokenptr = token;    return (error);}/* ********************** Show files ********************************* *//* Show comma separated list of all files in database*/int show_nft(DB_TASK *task){    int i, j, len, comma;    DB_TCHAR *p;    dbe_out(dbe_getstr(M_SHOWFL), STDOUT);    comma = 0;    j = SCRWIDTH;    for (i = 0; i < task->size_ft; i++)    {        len = vtstrlen(task->file_table[i].ft_name);        if (len + 2 + j >= SCRWIDTH)        {                                /* Add 2 for comma & space */            if (comma)                dbe_out(DB_TEXT(",\n"), STDOUT);            dbe_out(p = dbe_getstr(M_TAB), STDOUT);            j = vtstrlen(p);        }        else if (comma)        {            dbe_out(DB_TEXT(", "), STDOUT);            j += 2;        }        dbe_out(task->file_table[i].ft_name, STDOUT);        comma = 1;        j += len;    }    dbe_out(DB_TEXT("\n"), STDOUT);    return 0;}/* Show details for one file*/int show_ft(int index, DB_TASK *task){    int i;    if (task->file_table[index].ft_type == 'd')        show_nrt(index, task);    else    {        if (task->file_table[index].ft_type == 'k')        {            dbe_out(dbe_getstr(M_SHOWKL), STDOUT);            for (i = 0; i < task->size_fd;)            {                if (task->field_table[i].fd_keyfile == index)                    show_fd(&i, 0, 1, task);                else                    i++;            }        }    }    return 0;}/* ********************** Show records ******************************* *//* Show comma separated list of all records in database*/int show_nrt(    int file_no,                        /* File containing records to  */    DB_TASK *task)                      /* be shown (-1 for all files) */{    int i, j, len, comma;    DB_TCHAR *p;    dbe_out(dbe_getstr(M_SHOWRD), STDOUT);    comma = 0;    j = SCRWIDTH;    for (i = 0; i < task->size_rt; i++)    {        if (file_no >= 0 && task->record_table[i].rt_file != file_no)            continue;        len = vtstrlen(task->record_names[i]);        if (len + 2 + j >= SCRWIDTH)        {                                /* Add 2 for comma & space */            if (comma)                dbe_out(DB_TEXT(",\n"), STDOUT);            dbe_out(p = dbe_getstr(M_TAB), STDOUT);            j = vtstrlen(p);        }        else        {            if (comma)            {                dbe_out(DB_TEXT(", "), STDOUT);                j += 2;            }        }        dbe_out(task->record_names[i], STDOUT);        comma = 1;        j += len;    }    dbe_out(DB_TEXT("\n"), STDOUT);    return 0;}/* Show details for one record*/int show_rt(int index, DB_TASK *task){    DB_TCHAR buffer[LINELEN];    int i, first, last, n, comma;    /* Record Type */    vstprintf(buffer, DB_TEXT("%s%s (%d)"),        dbe_getstr(M_SHOWRT), task->record_names[index], index);    dbe_out(buffer, STDOUT);    /* Contained in file... */    vtstrcpy(buffer, dbe_getstr(M_SHOWRC));    vtstrcat(buffer, task->file_table[task->record_table[index].rt_file].ft_name);    dbe_out(buffer, STDOUT);    /* Record Length */    n = task->record_table[index].rt_len;    vstprintf(buffer, decimal ? DB_TEXT("%s%d") : DB_TEXT("%s%x"),        dbe_getstr(M_SHOWRL), n);    dbe_out(buffer, STDOUT);    /* Offset to Data */    n = task->record_table[index].rt_data;    vstprintf(buffer, decimal ? DB_TEXT("%s%d") : DB_TEXT("%s%x"),        dbe_getstr(M_SHOWRO), n);    dbe_out(buffer, STDOUT);    /* Flags */    vtstrcpy(buffer, dbe_getstr(M_SHOWRG));    comma = 0;    if (task->record_table[index].rt_flags & TIMESTAMPED)    {        vtstrcat(buffer, dbe_getstr(M_FLAGRT));        comma = 1;    }    if (task->record_table[index].rt_flags & STATIC)    {        if (comma)            vtstrcat(buffer, DB_TEXT(", "));        vtstrcat(buffer, dbe_getstr(M_FLAGRS));        comma = 1;    }    if (task->record_table[index].rt_flags & COMKEYED)    {        if (comma)            vtstrcat(buffer, DB_TEXT(", "));        vtstrcat(buffer, dbe_getstr(M_FLAGRC));    }    vtstrcat(buffer, DB_TEXT("\n"));    dbe_out(buffer, STDOUT);    /* Fields */    vtstrcpy(buffer, dbe_getstr(M_SHOWRF));    dbe_out(buffer, STDOUT);    first = task->record_table[index].rt_fields;    last = first + task->record_table[index].rt_fdtot;    for (i = first; i < last;)        show_fd(&i, 0, 0, task);    return 0;}/* ********************** Show sets ********************************** *//* Show comma separated list of all sets in database*/int show_nst(DB_TASK *task){    int i, j, len, comma;    DB_TCHAR *p;    dbe_out(dbe_getstr(M_SHOWSL), STDOUT);    comma = 0;    j = SCRWIDTH;    for (i = 0; i < task->size_st; i++)    {        len = vtstrlen(task->set_names[i]);        if (len + 2 + j >= SCRWIDTH)        {                                /* Add 2 for comma & space */            if (comma)                dbe_out(DB_TEXT(",\n"), STDOUT);            dbe_out(p = dbe_getstr(M_TAB), STDOUT);            j = vtstrlen(p);        }        else        {            if (comma)            {                dbe_out(DB_TEXT(", "), STDOUT);                j += 2;            }

⌨️ 快捷键说明

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