Go to the source code of this file.
|
enum | dbf_version_t {
DBF_VERSION_UNKNOWN = 0x00
, DBF_VERSION_DBASE2 = 0x02
, DBF_VERSION_DBASE3 = 0x03
, DBF_VERSION_DBASE4 = 0x04
,
DBF_VERSION_DBASE5 = 0x05
, DBF_VERSION_VISUAL_OBJECTS = 0x07
, DBF_VERSION_VISUAL_FOXPRO = 0x30
, DBF_VERSION_VISUAL_FOXPRO_AUTO = 0x31
,
DBF_VERSION_VISUAL_FOXPRO_VARIFIELD = 0x32
, DBF_VERSION_DBASE3_MEMO = 0x83
, DBF_VERSION_VISUAL_OBJECTS_MEMO = 0x87
, DBF_VERSION_DBASE4_MEMO = 0x8b
,
DBF_VERSION_DBASE7 = 0x8c
, DBF_VERSION_FOXPRO_MEMO = 0xf5
} |
| Versions. More...
|
|
enum | dbf_type_t {
DBF_TYPE_AUTOINCREMENT = '+'
, DBF_TYPE_BINARY_OR_DOUBLE = 'B'
, DBF_TYPE_BLOB = 'W'
, DBF_TYPE_CHARACTER = 'C'
,
DBF_TYPE_CURRENCY = 'Y'
, DBF_TYPE_DATE = 'D'
, DBF_TYPE_DATETIME = 'T'
, DBF_TYPE_DOUBLE = 'O'
,
DBF_TYPE_FLOAT = 'F'
, DBF_TYPE_GENERAL = 'G'
, DBF_TYPE_INTEGER = 'I'
, DBF_TYPE_LOGICAL = 'L'
,
DBF_TYPE_MEMO = 'M'
, DBF_TYPE_NULLFLAGS = '0'
, DBF_TYPE_NUMBER = 'N'
, DBF_TYPE_PICTURE = 'P'
,
DBF_TYPE_TIMESTAMP = '@'
, DBF_TYPE_VARBINARY = 'Q'
, DBF_TYPE_VARCHAR = 'V'
} |
| Field types. More...
|
|
|
void | dbf_jd_to_tm (int32_t jd, int32_t jt, struct tm *tm) |
| Convert a Julian date into a tm structure. More...
|
|
int | dbf_yyyymmdd_to_tm (const char *ymd, size_t n, struct tm *tm) |
| Converts a date string in the format "YYYYMMDD" into a tm structure. More...
|
|
dbf_file_t * | dbf_init_file (dbf_file_t *fh, FILE *stream, void *user_data) |
| Initialize a file handle. More...
|
|
void | dbf_set_error (dbf_file_t *fh, const char *format,...) |
| Set an error message. More...
|
|
int | dbf_read (dbf_file_t *fh, dbf_header_callback_t handle_header, dbf_record_callback_t handle_record) |
| Read a data file. More...
|
|
int | dbf_read_header (dbf_file_t *fh, dbf_header_t **pheader) |
| Read the file header. More...
|
|
int | dbf_read_record (dbf_file_t *fh, dbf_record_t **precord) |
| Read a record. More...
|
|
int | dbf_seek_record (dbf_file_t *fh, size_t file_offset, dbf_record_t **precord) |
| Read a record by record number. More...
|
|
◆ dbf_header_callback_t
A callback function that is called for the file header.
- Parameters
-
fh | a file handle. |
header | a pointer to a dbf_header_t structure. |
- Return values
-
1 | on sucess. |
0 | to stop the processing. |
-1 | on error. |
◆ dbf_record_callback_t
A callback function that is called for each record.
- Parameters
-
fh | a file handle. |
header | a pointer to a dbf_header_t structure. |
record | a pointer to a dbf_record_t structure. |
file_offset | the record's position in the file. |
- Return values
-
1 | on sucess. |
0 | to stop the processing. |
-1 | on error. |
◆ dbf_version_t
Enumerator |
---|
DBF_VERSION_UNKNOWN | Unknown.
|
DBF_VERSION_DBASE2 | dBase II
|
DBF_VERSION_DBASE3 | dBase III
|
DBF_VERSION_DBASE4 | dBase IV
|
DBF_VERSION_DBASE5 | dBase V
|
DBF_VERSION_VISUAL_OBJECTS | Visual Objects.
|
DBF_VERSION_VISUAL_FOXPRO | Visual FoxPro.
|
DBF_VERSION_VISUAL_FOXPRO_AUTO | Visual FoxPro with Autoincrement field.
Visual FoxPro with Varchar or Varbinary field
|
DBF_VERSION_DBASE3_MEMO | dBase III with memo file
|
DBF_VERSION_VISUAL_OBJECTS_MEMO | Visual Objects with memo file.
|
DBF_VERSION_DBASE4_MEMO | dBase IV with memo file
|
DBF_VERSION_DBASE7 | dBase 7
|
DBF_VERSION_FOXPRO_MEMO | FoxPro with memo file.
|
◆ dbf_type_t
Enumerator |
---|
DBF_TYPE_AUTOINCREMENT | Autoincrement (4 bytes)
|
DBF_TYPE_BINARY_OR_DOUBLE | Binary (integer stored as a string).
Double (8 bytes) in FoxPro
|
DBF_TYPE_BLOB | Blob (integer stored as a string)
|
DBF_TYPE_CHARACTER | String.
|
DBF_TYPE_CURRENCY | Decimal number (8 bytes)
|
DBF_TYPE_DATE | Date (stored as "YYYYMMDD")
|
DBF_TYPE_DATETIME | Date and time (8 bytes)
|
DBF_TYPE_DOUBLE | Double (8 bytes)
|
DBF_TYPE_FLOAT | Number (stored as a string)
|
DBF_TYPE_GENERAL | OLE (integer stored as a string)
|
DBF_TYPE_INTEGER | Integer (4 bytes)
|
DBF_TYPE_LOGICAL | Logical (1 byte)
|
DBF_TYPE_MEMO | Memo (integer stored as a string)
|
DBF_TYPE_NULLFLAGS | _NullFlags (bytes)
|
DBF_TYPE_NUMBER | Number (stored as a string)
|
DBF_TYPE_PICTURE | Picture (integer stored as a string)
|
DBF_TYPE_TIMESTAMP | Timestamp (8 bytes)
|
DBF_TYPE_VARBINARY | Varbinary.
|
DBF_TYPE_VARCHAR | Varchar.
|
◆ dbf_jd_to_tm()
void dbf_jd_to_tm |
( |
int32_t |
jd, |
|
|
int32_t |
jt, |
|
|
struct tm * |
tm |
|
) |
| |
Calculates the calendar date from a Julian date and the time since midnight.
The tm_isdst member of the tm structure is always set to -1.
- Parameters
-
| jd | days since 1 January -4712. |
| jt | milliseconds since midnight. |
[out] | tm | the converted date. |
- See also
- "Astronomical Algorithms" [4], p. 63 for a description of the algorithm.
◆ dbf_yyyymmdd_to_tm()
int dbf_yyyymmdd_to_tm |
( |
const char * |
ymd, |
|
|
size_t |
n, |
|
|
struct tm * |
tm |
|
) |
| |
Fills a tm structure with the day, month and year from a date string.
The tm_wday member is only valid after 15 October 1582 in the Gregorian calendar.
The tm_isdst member is always set to -1.
- Parameters
-
| ymd | a date string in the format "YYYYMMDD". |
| n | the string length |
[out] | tm | the converted date. |
- Returns
- true on success, otherwise false.
◆ dbf_init_file()
Initializes a dbf_file_t structure.
- Parameters
-
fh | an uninitialized file handle. |
stream | a FILE pointer. |
user_data | callback data or NULL. |
- Returns
- the initialized file handle.
◆ dbf_set_error()
void dbf_set_error |
( |
dbf_file_t * |
fh, |
|
|
const char * |
format, |
|
|
|
... |
|
) |
| |
Formats and sets an error message.
- Parameters
-
fh | a file handle. |
format | a printf format string followed by a variable number of arguments. |
◆ dbf_read()
Reads a file that has the file extension ".dbf" and calls functions for the file header and each record.
The data that is passed to the callback functions is only valid during the function call. Do not keep pointers to the data.
Example
mydata_t *mydata = (mydata_t *) fh->
user_data;
return 1;
}
mydata_t *mydata = (mydata_t *) fh->
user_data;
return 1;
}
rc =
dbf_read(fh, handle_header, handle_record);
int dbf_read(dbf_file_t *fh, dbf_header_callback_t handle_header, dbf_record_callback_t handle_record)
Read a data file.
Definition: dbf.c:1200
dbf_file_t * dbf_init_file(dbf_file_t *fh, FILE *stream, void *user_data)
Initialize a file handle.
Definition: dbf.c:55
File handle.
Definition: dbf.h:475
void * user_data
Callback data.
Definition: dbf.h:487
Record.
Definition: dbf.h:135
- Parameters
-
fh | a file handle. |
handle_header | a function that is called for the file header. |
handle_record | a function that is called for each record. |
- Return values
-
1 | on success. |
0 | on end of file. |
-1 | on error. |
- See also
- the "Xbase File Format Description" [1] for information on the file format.
◆ dbf_read_header()
Reads the header from a file that has the file extension ".dbf".
- Parameters
-
| fh | a file handle. |
[out] | pheader | on sucess, a pointer to a dbf_header_t structure. Free the header with free() when you are done. |
- Return values
-
1 | on success. |
0 | on end of file. |
-1 | on error. |
- See also
- dbf_read_record
◆ dbf_read_record()
Reads a record from a file that has the file extension ".dbf".
Example
free(record);
}
free(header);
}
int dbf_read_record(dbf_file_t *fh, dbf_record_t **precord)
Read a record.
Definition: dbf.c:1107
int dbf_read_header(dbf_file_t *fh, dbf_header_t **pheader)
Read the file header.
Definition: dbf.c:1060
- Parameters
-
| fh | a file handle. |
[out] | precord | on sucess, a pointer to a dbf_record_t structure. Free the record with free() when you are done. |
- Return values
-
1 | on success. |
0 | on end of file. |
-1 | on error. |
- See also
- dbf_read_header
◆ dbf_seek_record()
Sets the file position to the specified record number and reads the requested record.
Example
size_t i;
while (i-- > 0) {
free(record);
}
}
free(header);
}
int dbf_seek_record(dbf_file_t *fh, size_t file_offset, dbf_record_t **precord)
Read a record by record number.
Definition: dbf.c:1172
- Parameters
-
| fh | a file handle. |
| record_number | a zero-based record number. |
[out] | precord | on success, a pointer to a dbf_record_t structure. Free the record with free() when you are done. |
- Return values
-
1 | on success. |
0 | on end of file. |
-1 | on error. |