026d09560262f0ab8471e18e50b61541f787defd
[deliverable/titan.core.git] / common / config_preproc.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 Ericsson Telecom AB
3 // All rights reserved. This program and the accompanying materials
4 // are made available under the terms of the Eclipse Public License v1.0
5 // which accompanies this distribution, and is available at
6 // http://www.eclipse.org/legal/epl-v10.html
7 ///////////////////////////////////////////////////////////////////////////////
8 #ifndef _Common_config_preproc_H
9 #define _Common_config_preproc_H
10
11 #include <string>
12
13 #include "memory.h"
14
15 extern void config_preproc_error(const char *error_str, ...)
16 __attribute__ ((__format__ (__printf__, 1, 2)));
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 extern void path_error(const char *fmt, ...)
23 __attribute__ ((__format__ (__printf__, 1, 2)));
24
25 #ifdef __cplusplus
26 } /* extern "C" */
27 #endif
28
29 extern std::string get_cfg_preproc_current_file();
30 extern int config_preproc_yylineno;
31
32 /** this struct is used to maintain a list of config files */
33 typedef struct string_chain_t {
34 char *str;
35 struct string_chain_t *next;
36 } string_chain_t;
37
38 /** adds a new string to the end of chain (reference), if it is not
39 * contained by the chain */
40 void string_chain_add(string_chain_t **ec, char *s);
41 /** cuts the head of the chain (reference!) and returns that
42 * string */
43 char* string_chain_cut(string_chain_t **ec);
44
45 /** struct to store string key-value pairs. the value can contain
46 * null-characters so we store also the length. */
47 typedef struct string_keyvalue_t {
48 char *key;
49 char *value;
50 size_t value_len;
51 } string_keyvalue_t;
52
53 /** an array. keep it sorted */
54 typedef struct string_map_t {
55 size_t n;
56 string_keyvalue_t **data;
57 } string_map_t;
58
59 /** adds a new key-value pair. if the key exists, it will be
60 * overwritten, and the return value is the (old) key. */
61 const char* string_map_add(string_map_t *map, char *key,
62 char *value, size_t value_len);
63
64 /** returns NULL if no such key. the length of value is returned in
65 * \a value_len */
66 const char* string_map_get_bykey(const string_map_t *map, const char *key,
67 size_t *value_len);
68
69 /** constructor */
70 string_map_t* string_map_new(void);
71 /** destructor */
72 void string_map_free(string_map_t *map);
73
74 /** Parses out and returns the macro identifier from macro reference \a str.
75 * The input shall be in format "${<macro_id>,something}", NULL pointer is
76 * returned otherwise. Whitespaces are allowed anywhere within the braces.
77 * The returned string shall be deallocated by the caller using Free(). */
78 char *get_macro_id_from_ref(const char *str);
79
80 /** Entry point for preprocessing config files.
81 *
82 * @param [in] filename the main config file
83 * @param [out] filenames main config plus all the included files
84 * @param [out] defines the macro definitions
85 * @return 1 if there were errors, 0 otherwise.
86 */
87 int preproc_parse_file(const char *filename, string_chain_t **filenames,
88 string_map_t **defines);
89
90 int string_is_int(const char *str, size_t len);
91 int string_is_float(const char *str, size_t len);
92 int string_is_id(const char *str, size_t len);
93 int string_is_bstr(const char *str, size_t len);
94 int string_is_hstr(const char *str, size_t len);
95 int string_is_ostr(const char *str, size_t len);
96 int string_is_hostname(const char *str, size_t len);
97
98 #endif /* _Common_config_preproc_H */
This page took 0.033909 seconds and 5 git commands to generate.