]> granicus.if.org Git - postgresql/blob - contrib/dbase/dbf.h
Avoid PQisBusy/PQconsumeInput busy loop in case of PQisBusy returning
[postgresql] / contrib / dbase / dbf.h
1 /* header-file for dbf.c
2    declares routines for reading and writing xBase-files (.dbf), and
3    associated structures
4
5    Maarten Boekhold (maarten.boekhold@reuters.com) 29 oktober 1995
6 */
7
8 #ifndef _DBF_H
9 #define _DBF_H
10
11 #include <sys/types.h>
12
13 /**********************************************************************
14
15                 The DBF-part
16
17 ***********************************************************************/
18
19 #define DBF_FILE_MODE   0644
20
21 /* byte offsets for date in dbh_date */
22
23 #define DBH_DATE_YEAR   0
24 #define DBH_DATE_MONTH  1
25 #define DBH_DATE_DAY    2
26
27 /* maximum fieldname-length */
28
29 #define DBF_NAMELEN 11
30
31 /* magic-cookies for the file */
32
33 #define DBH_NORMAL      0x03
34 #define DBH_MEMO        0x83
35
36 /* magic-cookies for the fields */
37
38 #define DBF_ERROR       -1
39 #define DBF_VALID       0x20
40 #define DBF_DELETED 0x2A
41
42 /* diskheader */
43
44 typedef struct
45 {
46         u_char          dbh_dbt;                /* indentification field */
47         u_char          dbh_year;               /* last modification-date */
48         u_char          dbh_month;
49         u_char          dbh_day;
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 */
54 }       dbf_header;
55
56 /* disk field-description */
57
58 typedef struct
59 {
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
65                                                                  * 'N' */
66         u_char          dbf_stub[14];   /* stuff we don't need */
67 }       dbf_field;
68
69 /* memory field-description */
70
71 typedef struct
72 {
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 */
77 }       f_descr;
78
79 /* memory dfb-header */
80
81 typedef struct
82 {
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 */
87         u_char          db_month;
88         u_char          db_day;
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-
97                                                                  * descriptions */
98 }       dbhead;
99
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
103    filled */
104
105 typedef struct
106 {
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 */
112 }       field;
113
114 /* prototypes for functions */
115
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);
127
128 /*********************************************************************
129
130                 The endian-part
131
132 ***********************************************************************/
133
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);
138
139 #endif   /* _DBF_H */