added clang section in installation guide
[deliverable/titan.core.git] / common / config_preproc.h
1 /******************************************************************************
2 * Copyright (c) 2000-2016 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 * Contributors:
9 * Balasko, Jeno
10 * Beres, Szabolcs
11 * Forstner, Matyas
12 * Raduly, Csaba
13 * Szabo, Janos Zoltan – initial implementation
14 *
15 ******************************************************************************/
16 #ifndef _Common_config_preproc_H
17 #define _Common_config_preproc_H
18
19 #include <string>
20
21 #include "memory.h"
22
23 extern void config_preproc_error(const char *error_str, ...)
24 __attribute__ ((__format__ (__printf__, 1, 2)));
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 extern void path_error(const char *fmt, ...)
31 __attribute__ ((__format__ (__printf__, 1, 2)));
32
33 #ifdef __cplusplus
34 } /* extern "C" */
35 #endif
36
37 extern std::string get_cfg_preproc_current_file();
38 extern int config_preproc_yylineno;
39
40 /** this struct is used to maintain a list of config files */
41 typedef struct string_chain_t {
42 char *str;
43 struct string_chain_t *next;
44 } string_chain_t;
45
46 /** adds a new string to the end of chain (reference), if it is not
47 * contained by the chain */
48 void string_chain_add(string_chain_t **ec, char *s);
49 /** cuts the head of the chain (reference!) and returns that
50 * string */
51 char* string_chain_cut(string_chain_t **ec);
52
53 /** struct to store string key-value pairs. the value can contain
54 * null-characters so we store also the length. */
55 typedef struct string_keyvalue_t {
56 char *key;
57 char *value;
58 size_t value_len;
59 } string_keyvalue_t;
60
61 /** an array. keep it sorted */
62 typedef struct string_map_t {
63 size_t n;
64 string_keyvalue_t **data;
65 } string_map_t;
66
67 /** adds a new key-value pair. if the key exists, it will be
68 * overwritten, and the return value is the (old) key. */
69 const char* string_map_add(string_map_t *map, char *key,
70 char *value, size_t value_len);
71
72 /** returns NULL if no such key. the length of value is returned in
73 * \a value_len */
74 const char* string_map_get_bykey(const string_map_t *map, const char *key,
75 size_t *value_len);
76
77 /** constructor */
78 string_map_t* string_map_new(void);
79 /** destructor */
80 void string_map_free(string_map_t *map);
81
82 /** Parses out and returns the macro identifier from macro reference \a str.
83 * The input shall be in format "${<macro_id>,something}", NULL pointer is
84 * returned otherwise. Whitespaces are allowed anywhere within the braces.
85 * The returned string shall be deallocated by the caller using Free(). */
86 char *get_macro_id_from_ref(const char *str);
87
88 /** Entry point for preprocessing config files.
89 *
90 * @param [in] filename the main config file
91 * @param [out] filenames main config plus all the included files
92 * @param [out] defines the macro definitions
93 * @return 1 if there were errors, 0 otherwise.
94 */
95 int preproc_parse_file(const char *filename, string_chain_t **filenames,
96 string_map_t **defines);
97
98 int string_is_int(const char *str, size_t len);
99 int string_is_float(const char *str, size_t len);
100 int string_is_id(const char *str, size_t len);
101 int string_is_bstr(const char *str, size_t len);
102 int string_is_hstr(const char *str, size_t len);
103 int string_is_ostr(const char *str, size_t len);
104 int string_is_hostname(const char *str, size_t len);
105
106 #endif /* _Common_config_preproc_H */
This page took 0.032589 seconds and 5 git commands to generate.