~ubuntu-branches/ubuntu/feisty/libdebian-installer/feisty

« back to all changes in this revision

Viewing changes to include/debian-installer/parser.h

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2004-06-15 12:41:12 UTC
  • Revision ID: james.westby@ubuntu.com-20040615124112-irrmriyd8d6s067u
Tags: 0.29
* Joey Hess
  - Re-enable character device mapping. Though it often gets it wrong, the
    cases where it gets it right are used by prebaseconfig.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * parser.h
 
3
 *
 
4
 * Copyright (C) 2003 Bastian Blank <waldi@debian.org>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
19
 *
 
20
 * $Id: parser.h 11699 2004-03-22 09:35:42Z waldi $
 
21
 */
 
22
 
 
23
#ifndef DEBIAN_INSTALLER__PARSER_H
 
24
#define DEBIAN_INSTALLER__PARSER_H
 
25
 
 
26
#include <debian-installer/hash.h>
 
27
#include <debian-installer/slist.h>
 
28
#include <debian-installer/string.h>
 
29
 
 
30
#include <stdbool.h>
 
31
#include <stdio.h>
 
32
#include <stdlib.h>
 
33
#include <string.h>
 
34
 
 
35
typedef struct di_parser_info di_parser_info;
 
36
typedef struct di_parser_fieldinfo di_parser_fieldinfo;
 
37
 
 
38
/**
 
39
 * @addtogroup di_parser
 
40
 * @{
 
41
 */
 
42
 
 
43
/**
 
44
 * Read a single field
 
45
 *
 
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
 
51
 */
 
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);
 
53
 
 
54
/**
 
55
 * Write a single field - callback
 
56
 *
 
57
 * @param field the field
 
58
 * @param value the value of the field
 
59
 * @param data the callback_data
 
60
 */
 
61
typedef void di_parser_fields_function_write_callback (const di_rstring *field, const di_rstring *value, void *data);
 
62
 
 
63
/**
 
64
 * Write a single field
 
65
 *
 
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
 
70
 *
 
71
 * @return written bytes
 
72
 */
 
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);
 
74
 
 
75
/**
 
76
 * @param user_data data supplied to di_parse
 
77
 * @return new data
 
78
 */
 
79
typedef void *di_parser_read_entry_new (void *user_data);
 
80
 
 
81
/**
 
82
 * @param data the actual data
 
83
 * @param user_data data supplied to di_parse
 
84
 */
 
85
typedef int di_parser_read_entry_finish (void *data, void *user_data);
 
86
 
 
87
/**
 
88
 * @param data the actual data
 
89
 * @param user_data data supplied to di_parse
 
90
 */
 
91
typedef void *di_parser_write_entry_next (void **state_data, void *user_data);
 
92
 
 
93
/**
 
94
 * @brief Parse info
 
95
 */
 
96
struct di_parser_info
 
97
{
 
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 "") */
 
102
};
 
103
 
 
104
/**
 
105
 * @brief Info about a parser field
 
106
 */
 
107
struct di_parser_fieldinfo
 
108
{
 
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. */
 
114
};
 
115
 
 
116
/**
 
117
 * generates a di_parser_fieldinfo
 
118
 */
 
119
#define DI_PARSER_FIELDINFO(name, read, write, integer) \
 
120
  { { name, sizeof (name) - 1 }, read, write, integer }
 
121
 
 
122
di_parser_fields_function_read
 
123
  /**
 
124
   * Read function for a boolean (true == "Yes")
 
125
   */
 
126
  di_parser_read_boolean,
 
127
  /**
 
128
   * Read function for an int
 
129
   */
 
130
  di_parser_read_int,
 
131
  /**
 
132
   * Read function for a di_rstring
 
133
   */
 
134
  di_parser_read_rstring,
 
135
  /**
 
136
   * Read function for a string
 
137
   */
 
138
  di_parser_read_string;
 
139
 
 
140
di_parser_fields_function_write
 
141
  /**
 
142
   * Write function for a boolean ("Yes" == true)
 
143
   */
 
144
  di_parser_write_boolean,
 
145
  /**
 
146
   * Write function for an int
 
147
   */
 
148
  di_parser_write_int,
 
149
  /**
 
150
   * Write function for a di_string
 
151
   */
 
152
  di_parser_write_rstring,
 
153
  /**
 
154
   * Write function for a string
 
155
   */
 
156
  di_parser_write_string;
 
157
 
 
158
di_parser_info *di_parser_info_alloc (void);
 
159
void di_parser_info_free (di_parser_info *info);
 
160
 
 
161
void di_parser_info_add (di_parser_info *info, const di_parser_fieldinfo *fieldinfo[]);
 
162
 
 
163
/** @} */
 
164
#endif