1 /*****************************************************************************
2  * statistic.c
3  * inherits the statistic functions for dBASE files
4  * Author: Bjoern Berg, September 2002
5  * Email: clergyman@gmx.de
6  * dbf Reader and Converter for dBase III, IV, 5.0
7  *
8  *
9  *****************************************************************************
10  * $Id: statistic.c,v 1.12 2004/09/07 15:50:54 steinm Exp $
11  ****************************************************************************/
12 
13 #include "dbf.h"
14 #include "statistic.h"
15 
16 
get_db_version(int version)17 static const char *get_db_version (int version) {
18 	static char name[31];
19 
20 	switch (version) {
21 		case 0x02:
22 			// without memo fields
23 			return "FoxBase";
24 		case 0x03:
25 			// without memo fields
26 			return "FoxBase+/dBASE III+";
27 		case 0x04:
28 			// without memo fields
29 			return "dBASE IV";
30 		case 0x05:
31 			// without memo fields
32 			return "dBASE 5.0";
33 		case 0x83:
34 			return "FoxBase+/dBASE III+";
35 		case 0x8B:
36 			return "dBASE IV";
37 		case 0x30:
38 			// without memo fields
39 			return "Visual FoxPro";
40 		case 0xF5:
41 			// with memo fields
42 			return "FoxPro 2.0";
43 		default:
44 			sprintf(name, _("Unknown (code 0x%.2X)"), version);
45 			return name;
46 	}
47 }
48 
49 
50 /* output for header statistic */
51 void
dbf_file_info(P_DBF * p_dbf)52 dbf_file_info (P_DBF *p_dbf)
53 {
54 	int version, memo;
55 
56 	version	= dbf_GetVersion(p_dbf);
57 	memo = (version  & 128)==128 ? 1 : 0;
58 	printf("\n");
59 	printf(_("File statistics:"));
60 	printf("\n");
61 	printf(_("dBase version.........:"));
62 	printf(" \t %s (%s)\n",
63 			dbf_GetStringVersion(p_dbf), memo?"with memo":"without memo");
64 	printf(_("Date of last update...:"));
65 	printf(" \t %s\n", dbf_GetDate(p_dbf));
66 	printf(_("Number of records.....:"));
67 	printf(" \t %d (0x%08x)\n", dbf_NumRows(p_dbf), dbf_NumRows(p_dbf));
68 	printf(_("Length of header......:"));
69 	printf(" \t %d (0x%04x)\n", dbf_HeaderSize(p_dbf), dbf_HeaderSize(p_dbf));
70 	printf(_("Record length.........:"));
71 	printf(" \t %d (0x%04x)\n", dbf_RecordLength(p_dbf), dbf_RecordLength(p_dbf));
72 	printf(_("Columns in file.......:"));
73 	printf(" \t %d \n", dbf_NumCols(p_dbf));
74 }
75 
76 /* output for field statistic */
77 #define linelength	73
78 
79 void
dbf_field_stat(P_DBF * p_dbf)80 dbf_field_stat (P_DBF *p_dbf)
81 {
82 	const struct DB_FIELD *dbf;
83 	int cross[] = {1,17,25,41,57,73};
84 	int i, columns;
85 	columns = dbf_NumCols(p_dbf);
86 
87 	drawline(linelength, cross, (sizeof(cross)/sizeof(int)));
88 	printf("| ");
89 	printf(_("field name"));
90 	printf("\t| ");
91 	printf(_("type"));
92 	printf("\t| ");
93 	printf(_("field address"));
94 	printf("\t| ");
95 	printf(_("length"));
96 	printf("\t| ");
97 	printf(_("field dec."));
98 	printf("\t|\n");
99 	drawline(linelength, cross, sizeof(cross)/sizeof(int));
100 	for (i = 0; i < columns; i++) {
101 		char field_type;
102 		const char *field_name;
103 		int field_length, field_decimals, field_address;
104 		field_type = dbf_ColumnType(p_dbf, i);
105 		field_name = dbf_ColumnName(p_dbf, i);
106 		field_length = dbf_ColumnSize(p_dbf, i);
107 		field_decimals = dbf_ColumnDecimals(p_dbf, i);
108 		field_address = dbf_ColumnAddress(p_dbf, i);
109 
110 		printf("|%13.11s\t| %3c\t| %8x\t| %3d\t\t| %3d\t\t|\n",
111 			   field_name, field_type, field_address, field_length, field_decimals);
112 	}
113 	drawline(linelength, cross, sizeof(cross)/sizeof(int));
114 }
115