Beispiel #1
0
/* writeDBFHeader() {{{
 * creates the DBF Header with the information provided by DB_FIELD
 */
int
writeDBFHeader (FILE *fp, P_DBF *p_dbf,
    const char *in /* __unused */, const char *out /* __unused */)
{
	int i, columns;
	char *fields, *fieldptr;

	columns = dbf_NumCols(p_dbf);
	if(NULL == (fields = malloc(columns * SIZE_OF_DB_FIELD))) {
		return -1;
	}

	fieldptr = fields;
	for (i = 0; i < columns; i++) {
		char field_type;
		const char *field_name;
		int field_length, field_decimals;
		field_type = dbf_ColumnType(p_dbf, i);
		field_name = dbf_ColumnName(p_dbf, i);
		field_length = dbf_ColumnSize(p_dbf, i);
		field_decimals = dbf_ColumnDecimals(p_dbf, i);
		dbf_SetField((DB_FIELD *)fieldptr, field_type, field_name, field_length, field_decimals);
		fieldptr += SIZE_OF_DB_FIELD;
	}
	op_dbf = dbf_CreateFH(fileno(fp), (DB_FIELD *)fields, columns);

	return 0;
}
Beispiel #2
0
/* printDBF() {{{
 * printDBF is the real function that is hidden behind writeLine
 */
static int
printDBF(FILE *output, P_DBF *p_dbf,
    const unsigned char *record, int header_length,
    const char *filename, const char *export_filename)
{
	int i, columns;
	const char *value;
	columns = dbf_NumCols(p_dbf);
	value = record;

	for (i = 0; i < columns; i++) {
		char field_type;
		const char *field_name;
		int field_length, field_decimals;
		field_type = dbf_ColumnType(p_dbf, i);
		field_name = dbf_ColumnName(p_dbf, i);
		field_length = dbf_ColumnSize(p_dbf, i);
		field_decimals = dbf_ColumnDecimals(p_dbf, i);
		printf("%11.11s: %.*s\n", field_name, field_length, value);
		value += field_length;
	}
	return 0;
}
Beispiel #3
0
void
dbf_field_stat (P_DBF *p_dbf)
{
	const struct DB_FIELD *dbf;
	int cross[] = {1,17,25,41,57,73};
	int i, columns;
	columns = dbf_NumCols(p_dbf);

	drawline(linelength, cross, (sizeof(cross)/sizeof(int)));
	printf("| ");
	printf(_("field name"));
	printf("\t| ");
	printf(_("type"));
	printf("\t| ");
	printf(_("field address"));
	printf("\t| ");
	printf(_("length"));
	printf("\t| ");
	printf(_("field dec."));
	printf("\t|\n");
	drawline(linelength, cross, sizeof(cross)/sizeof(int));
	for (i = 0; i < columns; i++) {
		char field_type;
		const char *field_name;
		int field_length, field_decimals, field_address;
		field_type = dbf_ColumnType(p_dbf, i);
		field_name = dbf_ColumnName(p_dbf, i);
		field_length = dbf_ColumnSize(p_dbf, i);
		field_decimals = dbf_ColumnDecimals(p_dbf, i);
		field_address = dbf_ColumnAddress(p_dbf, i);

		printf("|%13.11s\t| %3c\t| %8x\t| %3d\t\t| %3d\t\t|\n",
			   field_name, field_type, field_address, field_length, field_decimals);
	}
	drawline(linelength, cross, sizeof(cross)/sizeof(int));
}