aboutsummaryrefslogtreecommitdiff
path: root/src/grecs.h
blob: 9823c9dcfd7381a0aac5f47d876fbacc6efa0752 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* grecs - Gray's Extensible Configuration System
   Copyright (C) 2007, 2008, 2009 Sergey Poznyakoff

   Grecs is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 3 of the License, or (at your
   option) any later version.

   Grecs is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with Grecs. If not, see <http://www.gnu.org/licenses/>. */

#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <gl_xlist.h>
#include <gl_linked_list.h>

typedef struct {
    char *file;
    int line;
} grecs_locus_t;

extern grecs_locus_t grecs_locus;

enum grecs_data_type {
    grecs_type_void,
    grecs_type_string,
    grecs_type_short,
    grecs_type_ushort,
    grecs_type_int,
    grecs_type_uint,
    grecs_type_long,
    grecs_type_ulong,
    grecs_type_size,
/*    grecs_type_off,*/
    grecs_type_uintmax,
    grecs_type_intmax,
    grecs_type_time,
    grecs_type_bool,
    grecs_type_ipv4,
    grecs_type_cidr,
    grecs_type_host,
    grecs_type_sockaddr,
    grecs_type_section
};

#define GRECS_LIST 0x8000
#define GRECS_TYPE_MASK 0x00ff
#define GRECS_TYPE(c) ((c) & GRECS_TYPE_MASK)
#define GRECS_IS_LIST(c) ((c) & GRECS_LIST)

enum grecs_callback_command {
    grecs_callback_section_begin,
    grecs_callback_section_end,
    grecs_callback_set_value
};

#define GRECS_TYPE_STRING 0
#define GRECS_TYPE_LIST   1
#define GRECS_TYPE_ARRAY  2

typedef struct grecs_value {
    int type;
    union {
	gl_list_t list;
	const char *string;
	struct {
	    size_t c;
	    struct grecs_value *v;
	} arg;
    } v;
} grecs_value_t;

typedef int (*grecs_callback_fn) (
    enum grecs_callback_command cmd,
    grecs_locus_t *    /* locus */,
    void *             /* varptr */,
    grecs_value_t *    /* value */,
    void *             /* cb_data */
    );

struct grecs_keyword {
    const char *ident;
    const char *argname;
    const char *docstring;
    enum grecs_data_type type;
    void *varptr;
    size_t offset;
    grecs_callback_fn callback;
    void *callback_data;
    struct grecs_keyword *kwd;
};

struct grecs_sockaddr {
  int len;
  struct sockaddr *sa;
};

grecs_value_t *grecs_value_dup(grecs_value_t *input);

extern void grecs_print_diag(grecs_locus_t *, int, int, const char*);

void grecs_warning(grecs_locus_t *locus, int errcode, const char *fmt, ...)
  __attribute__ ((__format__ (__printf__, 3, 4)));
void grecs_error(grecs_locus_t *locus, int errcode, const char *fmt, ...)
  __attribute__ ((__format__ (__printf__, 3, 4)));
void grecs_set_keywords(struct grecs_keyword *kwd);
void grecs_gram_trace(int n);
void grecs_lex_trace (int n);

int grecs_lex_begin(const char*);  
void grecs_lex_end(void);
int grecs_parse (const char *name);

void grecs_line_begin (void);
void grecs_line_add (const char *text, size_t len);
char *grecs_line_finish (void);

extern int grecs_string_convert (void *target, enum grecs_data_type type,
				 const char *string, grecs_locus_t *locus);
extern void grecs_process_ident (struct grecs_keyword *kwp,
				 grecs_value_t *value,
				 void *base,
				 grecs_locus_t *locus);

extern grecs_locus_t grecs_current_locus;
extern int grecs_error_count;    
extern int grecs_default_port;

extern const char *grecs_preprocessor;
extern bool grecs_log_to_stderr;
extern void (*grecs_log_setup_hook) ();

size_t grecs_preproc_fill_buffer (char *buf, size_t size);
void grecs_preproc_add_include_dir (char *dir);
int grecs_preproc_init (const char *name);
void grecs_preproc_done (void);
int grecs_preproc_run (const char *config_file, const char *extpp);

FILE *grecs_preproc_extrn_start (const char *file, pid_t *ppid);
void grecs_preproc_extrn_shutdown (pid_t pid);

char *grecs_install_text (const char *str);
void grecs_destroy_text (void);

void grecs_include_path_setup (const char *dir, ...);
void grecs_include_path_setup_v (char **dirs);

const char *grecs_data_type_string (enum grecs_data_type type);
void grecs_format_docstring (FILE *stream, const char *docstring,
			     unsigned level);
void grecs_format_simple_statement (FILE *stream, struct grecs_keyword *kwp,
				    unsigned level);
void grecs_format_block_statement (FILE *stream, struct grecs_keyword *kwp,
				   unsigned level);
void grecs_format_statement_array (FILE *stream, struct grecs_keyword *kwp,
				   unsigned n,
				   unsigned level);



Return to:

Send suggestions and report system problems to the System administrator.