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

📄 type.c

📁 postgresql8.3.4源码,开源数据库
💻 C
📖 第 1 页 / 共 2 页
字号:
				ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), ind_struct_sizeof, ind_prefix, 0);			break;	}}/* If siz is NULL, then the offset is 0, if not use siz as a   string, it represents the offset needed if we are in an array of structs. */static voidECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,				  char *varcharsize,				  char *arrsize,				  const char *siz,				  const char *prefix,				  int lineno){	if (type == ECPGt_NO_INDICATOR)		fprintf(o, "\n\tECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ");	else if (type == ECPGt_descriptor)		/* remember that name here already contains quotes (if needed) */		fprintf(o, "\n\tECPGt_descriptor, %s, 0L, 0L, 0L, ", name);	else	{		char	   *variable = (char *) mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 4);		char	   *offset = (char *) mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1 + strlen(varcharsize) + sizeof(int) * CHAR_BIT * 10 / 3);		switch (type)		{				/*				 * we have to use the & operator except for arrays and				 * pointers				 */			case ECPGt_varchar:				/*				 * we have to use the pointer except for arrays with given				 * bounds				 */				if (((atoi(arrsize) > 0) ||					 (atoi(arrsize) == 0 && strcmp(arrsize, "0") != 0)) &&					siz == NULL)					sprintf(variable, "(%s%s)", prefix ? prefix : "", name);				else					sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);				if (lineno)					sprintf(offset, "sizeof(struct varchar_%s_%d)", name, lineno);				else					sprintf(offset, "sizeof(struct varchar_%s)", name);				break;			case ECPGt_char:			case ECPGt_unsigned_char:			case ECPGt_char_variable:				/*				 * we have to use the pointer except for arrays with given				 * bounds, ecpglib will distinguish between * and []				 */				if ((atoi(varcharsize) > 1 ||					 (atoi(arrsize) > 0) ||				 (atoi(varcharsize) == 0 && strcmp(varcharsize, "0") != 0) ||					 (atoi(arrsize) == 0 && strcmp(arrsize, "0") != 0))					&& siz == NULL)					sprintf(variable, "(%s%s)", prefix ? prefix : "", name);				else					sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);				sprintf(offset, "(%s)*sizeof(char)", strcmp(varcharsize, "0") == 0 ? "1" : varcharsize);				break;			case ECPGt_numeric:				/*				 * we have to use a pointer here				 */				sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);				sprintf(offset, "sizeof(numeric)");				break;			case ECPGt_interval:				/*				 * we have to use a pointer here				 */				sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);				sprintf(offset, "sizeof(interval)");				break;			case ECPGt_date:				/*				 * we have to use a pointer and translate the variable type				 */				sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);				sprintf(offset, "sizeof(date)");				break;			case ECPGt_timestamp:				/*				 * we have to use a pointer and translate the variable type				 */				sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);				sprintf(offset, "sizeof(timestamp)");				break;			case ECPGt_const:				/*				 * just dump the const as string				 */				sprintf(variable, "\"%s\"", name);				sprintf(offset, "strlen(\"%s\")", name);				break;			default:				/*				 * we have to use the pointer except for arrays with given				 * bounds				 */				if (((atoi(arrsize) > 0) ||					 (atoi(arrsize) == 0 && strcmp(arrsize, "0") != 0)) &&					siz == NULL)					sprintf(variable, "(%s%s)", prefix ? prefix : "", name);				else					sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);				sprintf(offset, "sizeof(%s)", ecpg_type_name(type));				break;		}		if (atoi(arrsize) < 0)			strcpy(arrsize, "1");		if (siz == NULL || strlen(siz) == 0 || strcmp(arrsize, "0") == 0 || strcmp(arrsize, "1") == 0)			fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, offset);		else			fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, siz);		free(variable);		free(offset);	}}/* Penetrate a struct and dump the contents. */static voidECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, char *arrsiz, struct ECPGtype * type, struct ECPGtype * ind_type, const char *offsetarg, const char *prefix, const char *ind_prefix){	/*	 * If offset is NULL, then this is the first recursive level. If not then	 * we are in a struct in a struct and the offset is used as offset.	 */	struct ECPGstruct_member *p,			   *ind_p = NULL;	char		obuf[BUFSIZ];	char		pbuf[BUFSIZ],				ind_pbuf[BUFSIZ];	const char *offset;	if (offsetarg == NULL)	{		sprintf(obuf, "sizeof(%s)", name);		offset = obuf;	}	else		offset = offsetarg;	if (atoi(arrsiz) == 1)		sprintf(pbuf, "%s%s.", prefix ? prefix : "", name);	else		sprintf(pbuf, "%s%s->", prefix ? prefix : "", name);	prefix = pbuf;	if (ind_type == &ecpg_no_indicator)		ind_p = &struct_no_indicator;	else if (ind_type != NULL)	{		if (atoi(arrsiz) == 1)			sprintf(ind_pbuf, "%s%s.", ind_prefix ? ind_prefix : "", ind_name);		else			sprintf(ind_pbuf, "%s%s->", ind_prefix ? ind_prefix : "", ind_name);		ind_prefix = ind_pbuf;		ind_p = ind_type->u.members;	}	for (p = type->u.members; p; p = p->next)	{		ECPGdump_a_type(o, p->name, p->type,						(ind_p != NULL) ? ind_p->name : NULL,						(ind_p != NULL) ? ind_p->type : NULL,						prefix, ind_prefix, arrsiz, type->struct_sizeof,						(ind_p != NULL) ? ind_type->struct_sizeof : NULL);		if (ind_p != NULL && ind_p != &struct_no_indicator)			ind_p = ind_p->next;	}}voidECPGfree_struct_member(struct ECPGstruct_member * rm){	while (rm)	{		struct ECPGstruct_member *p = rm;		rm = rm->next;		free(p->name);		free(p->type);		free(p);	}}voidECPGfree_type(struct ECPGtype * type){	if (!IS_SIMPLE_TYPE(type->type))	{		switch (type->type)		{			case ECPGt_array:				switch (type->u.element->type)				{					case ECPGt_array:						base_yyerror("internal error, found multidimensional array\n");						break;					case ECPGt_struct:					case ECPGt_union:						/* Array of structs. */						ECPGfree_struct_member(type->u.element->u.members);						free(type->u.element);						break;					default:						if (!IS_SIMPLE_TYPE(type->u.element->type))							base_yyerror("Internal error: unknown datatype, please inform pgsql-bugs@postgresql.org");						free(type->u.element);				}				break;			case ECPGt_struct:			case ECPGt_union:				ECPGfree_struct_member(type->u.members);				break;			default:				mmerror(PARSE_ERROR, ET_ERROR, "illegal variable type %d\n", type->type);				break;		}	}	free(type);}const char *get_dtype(enum ECPGdtype type){	switch (type)	{		case ECPGd_count:			return ("ECPGd_countr");			break;		case ECPGd_data:			return ("ECPGd_data");			break;		case ECPGd_di_code:			return ("ECPGd_di_code");			break;		case ECPGd_di_precision:			return ("ECPGd_di_precision");			break;		case ECPGd_indicator:			return ("ECPGd_indicator");			break;		case ECPGd_key_member:			return ("ECPGd_key_member");			break;		case ECPGd_length:			return ("ECPGd_length");			break;		case ECPGd_name:			return ("ECPGd_name");			break;		case ECPGd_nullable:			return ("ECPGd_nullable");			break;		case ECPGd_octet:			return ("ECPGd_octet");			break;		case ECPGd_precision:			return ("ECPGd_precision");			break;		case ECPGd_ret_length:			return ("ECPGd_ret_length");		case ECPGd_ret_octet:			return ("ECPGd_ret_octet");			break;		case ECPGd_scale:			return ("ECPGd_scale");			break;		case ECPGd_type:			return ("ECPGd_type");			break;		case ECPGd_cardinality:			return ("ECPGd_cardinality");		default:			mmerror(PARSE_ERROR, ET_ERROR, "illegal descriptor item %d\n", type);	}	return NULL;}

⌨️ 快捷键说明

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