1 /* header-file for dbf.c
2 declares routines for reading and writing xBase-files (.dbf), and
5 Maarten Boekhold (maarten.boekhold@reuters.com) 29 oktober 1995
11 #include <sys/types.h>
13 /**********************************************************************
17 ***********************************************************************/
19 #define DBF_FILE_MODE 0644
21 /* byte offsets for date in dbh_date */
23 #define DBH_DATE_YEAR 0
24 #define DBH_DATE_MONTH 1
25 #define DBH_DATE_DAY 2
27 /* maximum fieldname-length */
29 #define DBF_NAMELEN 11
31 /* magic-cookies for the file */
33 #define DBH_NORMAL 0x03
36 /* magic-cookies for the fields */
39 #define DBF_VALID 0x20
40 #define DBF_DELETED 0x2A
46 u_char dbh_dbt; /* indentification field */
47 u_char dbh_year; /* last modification-date */
50 u_char dbh_records[4]; /* number of records */
51 u_char dbh_hlen[2]; /* length of this header */
52 u_char dbh_rlen[2]; /* length of a record */
53 u_char dbh_stub[20]; /* misc stuff we don't need */
56 /* disk field-description */
60 u_char dbf_name[DBF_NAMELEN]; /* field-name terminated with \0 */
61 u_char dbf_type; /* field-type */
62 u_char dbf_reserved[4]; /* some reserved stuff */
63 u_char dbf_flen; /* field-length */
64 u_char dbf_dec; /* number of decimal positions if type is
66 u_char dbf_stub[14]; /* stuff we don't need */
69 /* memory field-description */
73 u_char db_name[DBF_NAMELEN]; /* field-name terminated with \0 */
74 u_char db_type; /* field-type */
75 u_char db_flen; /* field-length */
76 u_char db_dec; /* number of decimal positions */
79 /* memory dfb-header */
83 int db_fd; /* file-descriptor */
84 u_long db_offset; /* current offset in file */
85 u_char db_memo; /* memo-file present */
86 u_char db_year; /* last update as YYMMDD */
89 u_long db_hlen; /* length of the diskheader, for
90 * calculating the offsets */
91 u_long db_records; /* number of records */
92 u_long db_currec; /* current record-number starting at 0 */
93 u_short db_rlen; /* length of the record */
94 u_char db_nfields; /* number of fields */
95 u_char *db_buff; /* record-buffer to save malloc()'s */
96 f_descr *db_fields; /* pointer to an array of field-
100 /* structure that contains everything a user wants from a field, including
101 the contents (in ASCII). Warning! db_flen may be bigger than the actual
102 length of db_name! This is because a field doesn't have to be completely
107 u_char db_name[DBF_NAMELEN]; /* field-name terminated with \0 */
108 u_char db_type; /* field-type */
109 u_char db_flen; /* field-length */
110 u_char db_dec; /* number of decimal positions */
111 u_char *db_contents; /* contents of the field in ASCII */
114 /* prototypes for functions */
116 extern dbhead *dbf_open(u_char *file, int flags);
117 extern int dbf_write_head(dbhead * dbh);
118 extern int dbf_put_fields(dbhead * dbh);
119 extern int dbf_add_field(dbhead * dbh, u_char *name, u_char type,
120 u_char length, u_char dec);
121 extern dbhead *dbf_open_new(u_char *name, int flags);
122 extern void dbf_close(dbhead * dbh);
123 extern int dbf_get_record(dbhead * dbh, field * fields, u_long rec);
124 extern field *dbf_build_record(dbhead * dbh);
125 extern void dbf_free_record(dbhead * dbh, field * fields);
126 extern int dbf_put_record(dbhead * dbh, field * rec, u_long where);
128 /*********************************************************************
132 ***********************************************************************/
134 extern long get_long(u_char *cp);
135 extern void put_long(u_char *cp, long lval);
136 extern short get_short(u_char *cp);
137 extern void put_short(u_char *cp, short lval);