po: Update German man pages translation
[dpkg.git] / lib / dpkg / parsedump.h
blob21076cc66fb6df9123ca1a52ff2fc06576322dcc
1 /*
2 * libdpkg - Debian packaging suite library routines
3 * parsedump.h - declarations for in-core database reading/writing
5 * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 * Copyright © 2001 Wichert Akkerman
7 * Copyright © 2008-2011 Guillem Jover <guillem@debian.org>
9 * This is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 #ifndef LIBDPKG_PARSEDUMP_H
24 #define LIBDPKG_PARSEDUMP_H
26 #include <stdbool.h>
27 #include <stdint.h>
29 #include <dpkg/error.h>
30 #include <dpkg/dpkg-db.h>
32 DPKG_BEGIN_DECLS
34 /**
35 * @defgroup parsedump In-core package database parsing and reading
36 * @ingroup dpkg-public
37 * @{
40 struct fieldinfo;
42 /**
43 * Parse action.
45 enum parsedbtype {
46 pdb_file_update,
47 pdb_file_status,
48 pdb_file_control,
49 pdb_file_available,
52 struct parsedb_state {
53 enum parsedbtype type;
54 enum parsedbflags flags;
55 struct dpkg_error err;
56 struct varbuf errmsg;
57 struct pkginfo *pkg;
58 struct pkgbin *pkgbin;
59 char *data;
60 char *dataptr;
61 char *endptr;
62 const char *filename;
63 int fd;
64 int lno;
67 #define parse_at_eof(ps) ((ps)->dataptr >= (ps)->endptr)
68 #define parse_getc(ps) *(ps)->dataptr++
69 #define parse_ungetc(c, ps) (ps)->dataptr--
71 struct field_state {
72 const char *fieldstart;
73 const char *valuestart;
74 struct varbuf value;
75 int fieldlen;
76 int valuelen;
77 int *fieldencountered;
80 struct parsedb_state *
81 parsedb_new(const char *filename, int fd, enum parsedbflags flags);
82 struct parsedb_state *
83 parsedb_open(const char *filename, enum parsedbflags flags);
84 void
85 parsedb_load(struct parsedb_state *ps);
86 int
87 parsedb_parse(struct parsedb_state *ps, struct pkginfo **pkgp);
88 void
89 parsedb_close(struct parsedb_state *ps);
91 typedef void parse_field_func(struct parsedb_state *ps, struct field_state *fs,
92 void *parse_obj);
94 bool parse_stanza(struct parsedb_state *ps, struct field_state *fs,
95 parse_field_func *parse_field, void *parse_obj);
97 #define STRUCTFIELD(klass, off, type) (*(type *)((uintptr_t)(klass) + (off)))
99 #define PKGIFPOFF(f) (offsetof(struct pkgbin, f))
100 #define ARCHIVEFOFF(f) (offsetof(struct archivedetails, f))
102 typedef void freadfunction(struct pkginfo *pkg, struct pkgbin *pkgbin,
103 struct parsedb_state *ps,
104 const char *value, const struct fieldinfo *fip);
105 freadfunction f_name;
106 freadfunction f_charfield;
107 freadfunction f_priority;
108 freadfunction f_obs_class;
109 freadfunction f_section;
110 freadfunction f_status;
111 freadfunction f_boolean;
112 freadfunction f_dependency;
113 freadfunction f_conffiles;
114 freadfunction f_version;
115 freadfunction f_obs_revision;
116 freadfunction f_obs_dependency;
117 freadfunction f_configversion;
118 freadfunction f_multiarch;
119 freadfunction f_architecture;
120 freadfunction f_trigpend, f_trigaw;
121 freadfunction f_archives;
123 enum DPKG_ATTR_ENUM_FLAGS fwriteflags {
124 /** No flags. */
125 fw_none = 0,
126 /** Print field header and trailing newline. */
127 fw_printheader = DPKG_BIT(0),
130 typedef void fwritefunction(struct varbuf*,
131 const struct pkginfo *, const struct pkgbin *,
132 enum fwriteflags flags, const struct fieldinfo*);
133 fwritefunction w_name, w_charfield, w_priority, w_section, w_status, w_configversion;
134 fwritefunction w_version, w_null, w_booleandefno, w_dependency, w_conffiles;
135 fwritefunction w_multiarch;
136 fwritefunction w_architecture;
137 fwritefunction w_trigpend, w_trigaw;
138 fwritefunction w_archives;
140 void
141 varbuf_add_arbfield(struct varbuf *vb, const struct arbitraryfield *arbfield,
142 enum fwriteflags flags);
144 #define FIELD(name) name, sizeof(name) - 1
146 struct fieldinfo {
147 const char *name;
148 size_t namelen;
149 freadfunction *rcall;
150 fwritefunction *wcall;
151 size_t integer;
155 parse_db_version(struct parsedb_state *ps,
156 struct dpkg_version *version, const char *value)
157 DPKG_ATTR_REQRET;
159 void parse_error(struct parsedb_state *ps, const char *fmt, ...)
160 DPKG_ATTR_NORET DPKG_ATTR_PRINTF(2);
161 void parse_warn(struct parsedb_state *ps, const char *fmt, ...)
162 DPKG_ATTR_PRINTF(2);
163 void
164 parse_lax_problem(struct parsedb_state *ps, enum parsedbflags flags_lax,
165 const char *fmt, ...)
166 DPKG_ATTR_PRINTF(3);
167 void
168 parse_problem(struct parsedb_state *ps, const char *fmt, ...)
169 DPKG_ATTR_PRINTF(2);
171 void parse_must_have_field(struct parsedb_state *ps,
172 const char *value, const char *what);
173 void parse_ensure_have_field(struct parsedb_state *ps,
174 const char **value, const char *what);
176 #define MSDOS_EOF_CHAR '\032' /* ^Z */
178 extern const struct fieldinfo fieldinfos[];
180 /** @} */
182 DPKG_END_DECLS
184 #endif /* LIBDPKG_PARSEDUMP_H */