⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cbexp.cpp

📁 CBASE v1.01 采用Borland公司TC++编写的数据库管理源程序库
💻 CPP
字号:
/*	Copyright (c) 1989 Citadel	*/
/*	   All Rights Reserved    	*/

/* #ident	"@(#)cbexp.c	1.4 - 90/06/20" */

/* ansi headers */
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
/*#include <stddef.h>*/
/*#include <string.h>*/

/* local headers */
#include "cbase_.h"

/*man---------------------------------------------------------------------------
NAME
     cbexp - cbase export functions

SYNOPSIS

DESCRIPTION

SEE ALSO
     cbcmp, cbimp.

DIAGNOSTICS

WARNINGS
     Pointer format is implementation defined; it could possibly
     contain the field delimiter ('|') or escape ('\\\\') chars.  If
     so, the field delimiter or escape character will have to be
     changed.

------------------------------------------------------------------------------*/
/* array data type export macro */
#define vexp(EXPFCT) {							\
	int i = 0;							\
	int nelems = n / sizeof(*cp);					\
									\
	for (i = 0; i < nelems; ++i) {					\
		if (EXPFCT(fp, cp, sizeof(*cp)) == -1) return -1;	\
		if (fputc(EXPFLDDLM, fp) == EOF) return -1;		\
		++cp;							\
	}								\
	return 0;							\
}

/* t_char -> use t_uchar export function */
#define charexp		ucharexp

/* t_charv -> use t_ucharv export function */
#define charvexp	ucharvexp

/* ucharexp:  t_uchar export function */
static int ucharexp(FILE *fp, const void *p, size_t n)
{
	unsigned char c = *(unsigned char *)p;

	switch (c) {
	case EXPFLDDLM:	/* export file field delimiter */
		if (fputc(EXPESC, fp) == EOF) return -1;
		if (fputc('F', fp) == EOF) return -1;
		break;	/* case EXPFLDDLM: */
	case EXPESC:	/* export file field escape character */
		if (fputc(EXPESC, fp) == EOF) return -1;
		if (fputc(EXPESC, fp) == EOF) return -1;
		break;	/* case EXPESC: */
#if __STDC__ == 1
	case '\a':	/* audible alert */
		if (fputc(EXPESC, fp) == EOF) return -1;
		if (fputc('a', fp) == EOF) return -1;
		break;	/* case '\a': */
#endif
	case '\b':	/* backspace */
		if (fputc(EXPESC, fp) == EOF) return -1;
		if (fputc('b', fp) == EOF) return -1;
		break;	/* case '\b': */
	case '\f':	/* form feed */
		if (fputc(EXPESC, fp) == EOF) return -1;
		if (fputc('f', fp) == EOF) return -1;
		break;	/* case '\f': */
	case '\n':	/* newline */
		if (fputc(EXPESC, fp) == EOF) return -1;
		if (fputc('n', fp) == EOF) return -1;
		break;	/* case '\n': */
	case '\r':	/* carriage return */
		if (fputc(EXPESC, fp) == EOF) return -1;
		if (fputc('r', fp) == EOF) return -1;
		break;	/* case '\r': */
	case '\t':	/* horizontal tab */
		if (fputc(EXPESC, fp) == EOF) return -1;
		if (fputc('t', fp) == EOF) return -1;
		break;	/* case '\t': */
	case '\v':	/* vertical tab */
		if (fputc(EXPESC, fp) == EOF) return -1;
		if (fputc('v', fp) == EOF) return -1;
		break;	/* case '\v': */
	default:
		if (isprint(c)) {
			if (fputc(c, fp) == EOF) return -1;
		} else {
			if (fprintf(fp, "%c%.3o", (int)EXPESC, (int)c) < 0) {
				return -1;
			}
		}
	}

	return 0;
}

/* ucharvexp:  t_ucharv export function */
static int ucharvexp(FILE *fp, const void *p, size_t n)
{
	unsigned char *cp = (unsigned char *)p;

	vexp(ucharexp);
}

/* shortexp:  t_short export function */
static int shortexp(FILE *fp, const void *p, size_t n)
{
	signed short x = 0;

	memcpy(&x, p, sizeof(x));
	if (fprintf(fp, "%hd", (int)x) < 0) return -1;

	return 0;
}

/* shortvexp:  t_shortv export function */
static int shortvexp(FILE *fp, const void *p, size_t n)
{
	signed short *cp = (signed short *)p;

    vexp(shortexp);
}

/* ushortexp:  t_ushort export function */
static int ushortexp(FILE *fp, const void *p, size_t n)
{
	unsigned short x = 0;

	memcpy(&x, p, sizeof(x));
	if (fprintf(fp, "%hu", (unsigned int)x) < 0) return -1;

	return 0;
}

/* ushortvexp:  t_ushortv export function */
static int ushortvexp(FILE *fp, const void *p, size_t n)
{
	unsigned short *cp = (unsigned short *)p;

	vexp(ushortexp);
}

/* intexp:  t_int export function */
static int intexp(FILE *fp, const void *p, size_t n)
{
	signed int x = 0;

	memcpy(&x, p, sizeof(x));
	if (fprintf(fp, "%d", x) < 0) return -1;

	return 0;
}

/* intvexp:  t_intv export function */
static int intvexp(FILE *fp, const void *p, size_t n)
{
	signed int *cp = (signed int *)p;

	vexp(intexp);
}

/* uintexp:  t_uint export function */
static int uintexp(FILE *fp, const void *p, size_t n)
{
	unsigned int x = 0;

	memcpy(&x, p, sizeof(x));
	if (fprintf(fp, "%u", x) < 0) return -1;

	return 0;
}

/* uintvexp:  t_uintv export function */
static int uintvexp(FILE *fp, const void *p, size_t n)
{
	unsigned int *cp = (unsigned int *)p;

	vexp(uintexp);
}

/* longexp:  t_long export function */
static int longexp(FILE *fp, const void *p, size_t n)
{
	signed long x = 0;

	memcpy(&x, p, sizeof(x));
	if (fprintf(fp, "%ld", x) < 0) return -1;

	return 0;
}

/* longvexp:  t_longv export function */
static int longvexp(FILE *fp, const void *p, size_t n)
{
	signed long *cp = (signed long *)p;

	vexp(longexp);
}

/* ulongexp:  t_ulong export function */
static int ulongexp(FILE *fp, const void *p, size_t n)
{
	unsigned long x = 0;

	memcpy(&x, p, sizeof(x));
	if (fprintf(fp, "%lu", x) < 0) return -1;

	return 0;
}

/* ulongvexp:  t_ulongv export function */
static int ulongvexp(FILE *fp, const void *p, size_t n)
{
	unsigned long *cp = (unsigned long *)p;

	vexp(ulongexp);
}

/* floatexp:  t_float export function */
static int floatexp(FILE *fp, const void *p, size_t n)
{
	float x = 0;

	memcpy(&x, p, sizeof(x));
	if (fprintf(fp, "%G", (double)x) < 0) return -1;

	return 0;
}

/* floatvexp:  t_floatv export function */
static int floatvexp(FILE *fp, const void *p, size_t n)
{
	float *cp = (float *)p;

	vexp(floatexp);
}

/* dblexp:  t_double export function */
static int dblexp(FILE *fp, const void *p, size_t n)
{
	double x = 0;

	memcpy(&x, p, sizeof(x));
	if (fprintf(fp, "%G", x) < 0) return -1;

	return 0;
}

/* dblexp:  t_double export function */
static int dblvexp(FILE *fp, const void *p, size_t n)
{
	double *cp = (double *)p;

	vexp(dblexp);
}

/* ldblexp:  t_ldouble export function */
static int ldblexp(FILE *fp, const void *p, size_t n)
{
#ifdef AC_LDOUBLE
	long double x = 0;

	memcpy(&x, p, sizeof(x));
	if (fprintf(fp, "%lG", x) < 0) return -1;

	return 0;
#else
	return 0;
#endif
}

/* ldblvexp:  t_ldoublev export function */
static int ldblvexp(FILE *fp, const void *p, size_t n)
{
#ifdef AC_LDOUBLE
	long double *cp = (long double *)p;

	vexp(ldblexp);
#else
	return 0;
#endif
}

/* ptrexp:  t_pointer export function */
static int ptrexp(FILE *fp, const void *p, size_t n)
{
	void *x = NULL;

	memcpy(&x, p, sizeof(x));
	if (fprintf(fp, "%p", x) < 0) return -1;

	return 0;
}

/* ptrvexp:  t_pointerv export function */
static int ptrvexp(FILE *fp, const void *p, size_t n)
{
	void **cp = (void **)p;

	vexp(ptrexp);
}

/* strexp:  t_string export function */
static int strexp(FILE *fp, const void *p, size_t n)
{
	char *s = (char *)p;
	int i = 0;

	for (i = 0; i < n; ++i) {
		if (s[i] == NUL) {
			break;
		}
		if (ucharexp(fp, &s[i], sizeof(*s)) == -1) {
			return -1;
		}
	}

	return 0;
}

/* t_cistring -> use t_string export function */
#define cistrexp	strexp

/* binexp:  t_binary export function */
static int binexp(FILE *fp, const void *p, size_t n)
{
	/* calculate number of hex digits for each char
	     # bits in char == CHAR_BIT, # bits in hex digit == 4 */
	const int hexdigits = (CHAR_BIT + (4 - 1)) / 4;
	unsigned char *pi = (unsigned char *)p;
	char fmt[24];			/* printf format string */

	sprintf(fmt, "%%.%dX", hexdigits);
	while (pi < ((unsigned char *)p + n)) {
		if (fprintf(fp, fmt, (unsigned int)*pi++) < 0) return -1;
	}

	return 0;
}

/* export function table definition */
const cbexp_t cbexpv[] = {
	charexp,		/* t_char	=  0 */
	charvexp,		/* t_charv	=  1 */
	ucharexp,		/* t_uchar	=  2 */
	ucharvexp,		/* t_ucharv	=  3 */
	shortexp,		/* t_short	=  4 */
	shortvexp,		/* t_shortv	=  5 */
	ushortexp,		/* t_ushort	=  6 */
	ushortvexp,		/* t_ushortv	=  7 */
	intexp,			/* t_int	=  8 */
	intvexp,		/* t_intv	=  9 */
	uintexp,		/* t_uint	= 10 */
	uintvexp,		/* t_uintv	= 11 */
	longexp,		/* t_long	= 12 */
	longvexp,		/* t_longv	= 13 */
	ulongexp,		/* t_ulong	= 14 */
	ulongvexp,		/* t_ulongv	= 15 */
	floatexp,		/* t_float	= 16 */
	floatvexp,		/* t_floatv	= 17 */
	dblexp,			/* t_double	= 18 */
	dblvexp,		/* t_doublev	= 19 */
	ldblexp,		/* t_ldouble	= 20 */
	ldblvexp,		/* t_ldoublev	= 21 */
	ptrexp,			/* t_pointer	= 22 */
	ptrvexp,		/* t_pointerv	= 23 */
	strexp,			/* t_string	= 24 */
	cistrexp,		/* t_cistring	= 25 */
	binexp			/* t_binary	= 26 */
};

⌨️ 快捷键说明

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