pr_fcns.c

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

C
627
字号
    FILE       *df,    char       *fld_area,    int         ndx,    EXPOPTS    *xo,    DB_TASK    *task){    DB_TCHAR    str[30];    char        charint;    short       shortint;    int         regint;    long        longint;    float       floatval;    double      doubval;    DB_ADDR     dbaval;    int         unsignedFld;    int         status = S_OKAY;    /* select action based on type */    unsignedFld = task->field_table[ndx].fd_flags & UNSIGNEDFLD;    switch (task->field_table[ndx].fd_type)    {        case CHARACTER:            /* single character type */            memcpy(&charint, fld_area, CHAR_SIZE);            if (unsignedFld)                vstprintf(str, DB_TEXT("%u"), (unsigned int) charint);            else                vstprintf(str, DB_TEXT("%d"), (int) charint);            status = pr_string(df, str, NO_QUOTES, xo, task);            break;        case SHORTINT:            /* short integer type */            memcpy(&shortint, fld_area, SHORT_SIZE);            if (unsignedFld)                vstprintf(str, DB_TEXT("%u"), (unsigned int) ((unsigned short) shortint));            else                vstprintf(str, DB_TEXT("%d"), (int) shortint);            status = pr_string(df, str, NO_QUOTES, xo, task);            break;        case REGINT:            /* regular integer type */            memcpy(&regint, fld_area, INT_SIZE);            if (unsignedFld)                vstprintf(str, DB_TEXT("%u"), (unsigned int) regint);            else                vstprintf(str, DB_TEXT("%d"), regint);            status = pr_string(df, str, NO_QUOTES, xo, task);            break;        case LONGINT:            /* long integer type */            memcpy(&longint, fld_area, LONG_SIZE);            if (unsignedFld)                vstprintf(str, DB_TEXT("%lu"), (unsigned long) longint);            else                vstprintf(str, DB_TEXT("%ld"), longint);            status = pr_string(df, str, NO_QUOTES, xo, task);            break;        case FLOAT:            /* float type */            memcpy(&floatval, fld_area, FLOAT_SIZE);            vstprintf(str, DB_TEXT("%.20g"), floatval);            status = pr_string(df, str, NO_QUOTES, xo, task);            break;        case DOUBLE:            /* double float type */            memcpy(&doubval, fld_area, DOUBLE_SIZE);            vstprintf(str, DB_TEXT("%.20g"), doubval);            status = pr_string(df, str, NO_QUOTES, xo, task);            break;        case DBADDR:            /* database address type */            memcpy(&dbaval, fld_area, DB_ADDR_SIZE);            cvt_dba(str, dbaval, xo);            status = pr_string(df, str, NO_QUOTES, xo, task);            break;        case GROUPED:            /* grouped type - WRONG! */            vftprintf(stderr, DB_TEXT("Grouped type found in pr_field\n"));            break;    }                                   /* end select action based on type */    return status;}/* * print to the data file, adding quotes and/or backslash characters * to escape quotes and backslashes. */static int pr_ascii(    FILE          *df,    void          *data,    DB_BOOLEAN     quotes,    EXPOPTS       *xo,    DB_TASK       *task){    unsigned char  k;    char           buf[10];    char          *str = (char *) data;#if defined(UNICODE)    DB_TCHAR       tbuf[10];    DB_TCHAR       tstr[2];#else    DB_TCHAR      *tbuf = buf;    DB_TCHAR      *tstr;#endif    if (xo->comma)    {        if (vfputtc(xo->sep_char, df) != xo->sep_char)            return S_NOSPACE;    }    else    {        xo->comma = TRUE;    }    if (quotes)    {        if (vfputtc(DB_TEXT('"'), df) != DB_TEXT('"'))            return S_NOSPACE;    }    /* for each character to be printed */    while (*str)    {#if defined(UNICODE)        atow(str, tstr, 2);        tstr[1] = 0;#else        tstr = str;#endif        /* if the character needs to be escaped */        if ((*str == '"') || (tstr[0] == xo->esc_char))        {            /* put an escape character in front of it */            if (vfputtc(xo->esc_char, df) != xo->esc_char)                return S_NOSPACE;        }        /* print the character */        if ((*str < ' ') || (*str > '~'))        {            buf[1] = '\0';            k = (unsigned char) *str;            if (task->ctbl_activ && task->country_tbl[k].out_chr)            {                buf[0] = k;            }            else            {                switch (*str)                {                    case '\n':  buf[0] = 'n';  break;                    case '\r':  buf[0] = 'r';  break;                    case '\t':  buf[0] = 't';  break;                    case '\f':  buf[0] = 'f';  break;                    case '\b':  buf[0] = 'b';  break;                    default:                        if (xo->extended)                            buf[0] = *str;                        else /* convert to \ooo form */                            sprintf(buf, "%03o", (0xff & (int) *str));                        break;                }                /* if the character needs to be escaped */                if (*buf != *str)                {                    if (vfputtc(xo->esc_char, df) != xo->esc_char)                        return S_NOSPACE;                }            }#if defined(UNICODE)            atow(buf, tbuf, sizeof(tbuf) / sizeof(DB_TCHAR));#endif            if (vfputts(tbuf, df) == EOF)                return S_NOSPACE;        }        else        {            if (vfputtc(tstr[0], df) != tstr[0])                return S_NOSPACE;        }        str++;    }    if (quotes)    {        if (vfputtc(DB_TEXT('"'), df) != DB_TEXT('"'))            return S_NOSPACE;    }    return S_OKAY;}void cvt_dba(    DB_TCHAR   *sdba,    DB_ADDR     dba,    EXPOPTS    *xo){    short       file;    DB_ULONG    slot;    if (dba == NULL_DBA)    {        vtstrcpy(sdba, DB_TEXT("NULL"));    }    else    {        if (xo->decimal)        {            vstprintf(sdba, DB_TEXT("%lu"), dba);        }        else        {            d_decode_dba(dba, &file, &slot);            vstprintf(sdba, DB_TEXT("%d:%lu"), file, slot);        }    }    return;}static int pr_unicode(    FILE          *df,    void          *data,    DB_BOOLEAN     quotes,    EXPOPTS       *xo,    DB_TASK       *task){    wchar_t       *str = (wchar_t *) data;#if defined(UNICODE)    DB_TCHAR      *tstr;#else    DB_TCHAR       tstr[2];#endif    if (xo->comma)    {        if (vfputtc(xo->sep_char, df) != xo->sep_char)            return S_NOSPACE;    }    else    {        xo->comma = TRUE;    }    if (quotes)    {        if (vfputtc(DB_TEXT('"'), df) != DB_TEXT('"'))            return S_NOSPACE;    }    /* for each character to be printed */    while (*str)    {#if defined(UNICODE)        tstr = str;#else        wtoa(str, tstr, 2);        tstr[1] = 0;#endif        if (vfputtc(tstr[0], df) != tstr[0])            return S_NOSPACE;        str++;    }    if (quotes)    {        if (vfputtc(DB_TEXT('"'), df) != DB_TEXT('"'))            return S_NOSPACE;    }    return S_OKAY;}static int pr_wbinary(    FILE       *df,    char       *rec_area,    int         width,    EXPOPTS    *xo){    int      i;    wchar_t *p = (wchar_t *) rec_area;    if (xo->comma)    {        if (vfputtc(xo->sep_char, df) != xo->sep_char)            return S_NOSPACE;    }    else    {        xo->comma = TRUE;    }    for (i = 0; i < width; i++)    {        if (vftprintf(df, DB_TEXT("%04x"), (unsigned int) *p++) == 0)            return S_NOSPACE;    }    return S_OKAY;}

⌨️ 快捷键说明

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