4
* Copyright (C) 2003 Bastian Blank <waldi@debian.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
* $Id: parser.h 11699 2004-03-22 09:35:42Z waldi $
23
#ifndef DEBIAN_INSTALLER__PARSER_H
24
#define DEBIAN_INSTALLER__PARSER_H
26
#include <debian-installer/hash.h>
27
#include <debian-installer/slist.h>
28
#include <debian-installer/string.h>
35
typedef struct di_parser_info di_parser_info;
36
typedef struct di_parser_fieldinfo di_parser_fieldinfo;
39
* @addtogroup di_parser
46
* @param data the actual data
47
* @param fip info of the actual field
48
* @param value the actual value
49
* @param value_size size of the actual value
50
* @param user_data data supplied to the parser
52
typedef void di_parser_fields_function_read (void **data, const di_parser_fieldinfo *fip, di_rstring *field_modifier, di_rstring *value, void *user_data);
55
* Write a single field - callback
57
* @param field the field
58
* @param value the value of the field
59
* @param data the callback_data
61
typedef void di_parser_fields_function_write_callback (const di_rstring *field, const di_rstring *value, void *data);
64
* Write a single field
66
* @param data the actual data
67
* @param fip info of the actual field
68
* @param output static buffer for output
69
* @param user_data data supplied to the parser
71
* @return written bytes
73
typedef void di_parser_fields_function_write (void **data, const di_parser_fieldinfo *fip, di_parser_fields_function_write_callback callback, void *callback_data, void *user_data);
76
* @param user_data data supplied to di_parse
79
typedef void *di_parser_read_entry_new (void *user_data);
82
* @param data the actual data
83
* @param user_data data supplied to di_parse
85
typedef int di_parser_read_entry_finish (void *data, void *user_data);
88
* @param data the actual data
89
* @param user_data data supplied to di_parse
91
typedef void *di_parser_write_entry_next (void **state_data, void *user_data);
98
di_hash_table *table; /**< table of di_parser_fieldinfo */
99
di_slist list; /**< list of di_parser_fieldinfo */
100
bool modifier; /**< use modifier */
101
bool wildcard; /**< use wildcard (entry with key "") */
105
* @brief Info about a parser field
107
struct di_parser_fieldinfo
109
di_rstring key; /**< field name */
110
di_parser_fields_function_read *read; /**< function for reading a field */
111
di_parser_fields_function_write *write; /**< function for writing a field */
112
unsigned int integer; /**< Simple value, usage is defined by the read and write functions.
113
* Most used with an offset of the field in the structure. */
117
* generates a di_parser_fieldinfo
119
#define DI_PARSER_FIELDINFO(name, read, write, integer) \
120
{ { name, sizeof (name) - 1 }, read, write, integer }
122
di_parser_fields_function_read
124
* Read function for a boolean (true == "Yes")
126
di_parser_read_boolean,
128
* Read function for an int
132
* Read function for a di_rstring
134
di_parser_read_rstring,
136
* Read function for a string
138
di_parser_read_string;
140
di_parser_fields_function_write
142
* Write function for a boolean ("Yes" == true)
144
di_parser_write_boolean,
146
* Write function for an int
150
* Write function for a di_string
152
di_parser_write_rstring,
154
* Write function for a string
156
di_parser_write_string;
158
di_parser_info *di_parser_info_alloc (void);
159
void di_parser_info_free (di_parser_info *info);
161
void di_parser_info_add (di_parser_info *info, const di_parser_fieldinfo *fieldinfo[]);