2 * Copyright (C) 2013-2014 Intel Corporation.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 * José Bollo <jose.bollo@open.eurogiciel.org>
20 * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
21 * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
24 #ifndef TIZEN_PLATFORM_WRAPPER_PARSER_H
25 #define TIZEN_PLATFORM_WRAPPER_PARSER_H
27 /* structure used for parsing config files */
30 /* The buffer to parse. */
33 /* The length of the buffer to parse. */
36 /* The maximum data size allowed */
37 size_t maximum_data_size;
39 /* Some user data, please use it as you wish. */
42 /* Should escape the key values (inserting \ where needed) */
46 Callback function to resolve the variables.
47 Should return the value of the variable of 'key' that
48 length is 'length' without terminating zero.
50 const char *(*get)( struct parsing *parsing,
51 const char *key, size_t length,
52 size_t begin_pos, size_t end_pos);
55 Callback function to receive new values.
56 Should add/insert/replace the key/value pair
57 given. This values aren't zero terminated.
58 The given length is the one without terminating nul.
60 int (*put)( struct parsing *parsing,
61 const char *key, size_t key_length,
62 const char *value, size_t value_length,
63 size_t begin_pos, size_t end_pos);
66 Callback function to report errors.
67 'buffer' is the scanned buffer.
68 'position' is the position of the character raising the error.
69 'message' is a short explanation of the error.
70 Should return 0 to stop parsing;
72 int (*error)( struct parsing *parsing,
73 size_t position, const char *message);
77 Parse the config file using data of 'parsing'.
78 Return 0 if not error found or a negative number
79 corresponding to the opposite of the count of found errors
80 (ex: -5 means 5 errors).
81 Note: works on utf8 data.
83 int parse_utf8_config(
84 struct parsing *parsing
87 /* Structure for getting information about a position. */
89 const char *begin; /* pointer to the first char of the line */
90 const char *end; /* pointer to the char just after the end of the line */
91 size_t length; /* length of the line (== end-begin) */
92 int lino; /* number of the line within the buffer */
93 int colno; /* number of the column within the line */
97 Fill the data of 'info' for the current position 'pos' that is an offset
98 into the buffer of 'parsing'.
99 This function computes into info the pointers of the line containig the
100 char of offset 'pos', the number of this line and the column number of
101 the position within the line.
102 Note: works on utf8 data.
104 void parse_utf8_info(
105 struct parsing *parsing,
106 struct parsinfo *info,