Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'S4U'
[simgrid.git] / include / surf / surfxml_parse.h
1 /* Copyright (c) 2006-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef _SURF_SURFXML_PARSE_H
8 #define _SURF_SURFXML_PARSE_H
9
10 #include <stdio.h>              /* to have FILE */
11 #include "xbt/misc.h"
12 #include "xbt/function_types.h"
13 #include "xbt/dict.h"
14 #include "surf/simgrid_dtd.h"
15
16
17 #ifndef YY_TYPEDEF_YY_SIZE_T
18 #define YY_TYPEDEF_YY_SIZE_T
19 typedef size_t yy_size_t;
20 #endif
21
22 SG_BEGIN_DECL()
23
24 XBT_PUBLIC(void) surf_parse_open(const char *file);
25 XBT_PUBLIC(void) surf_parse_close(void);
26 XBT_PUBLIC(void) surf_parse_init_callbacks(void);
27 XBT_PUBLIC(void) surf_parse_reset_callbacks(void);
28 XBT_PUBLIC(void) surf_parse_free_callbacks(void);
29 XBT_PUBLIC(void) XBT_ATTRIB_NORETURN surf_parse_error(const char *msg,...) XBT_ATTRIB_PRINTF(1,2);
30 XBT_PUBLIC(void) surf_parse_warn(const char *msg,...) XBT_ATTRIB_PRINTF(1,2);
31 XBT_PUBLIC(double) surf_parse_get_double(const char *string);
32 XBT_PUBLIC(int) surf_parse_get_int(const char *string);
33 XBT_PUBLIC(double) surf_parse_get_time(const char *string);
34 XBT_PUBLIC(double) surf_parse_get_size(const char *string);
35 XBT_PUBLIC(double) surf_parse_get_bandwidth(const char *string);
36 XBT_PUBLIC(double) surf_parse_get_power(const char *string);
37
38 /* Prototypes of the functions offered by flex */
39 XBT_PUBLIC(int) surf_parse_lex(void);
40 XBT_PUBLIC(int) surf_parse_get_lineno(void);
41 XBT_PUBLIC(FILE *) surf_parse_get_in(void);
42 XBT_PUBLIC(FILE *) surf_parse_get_out(void);
43 XBT_PUBLIC(yy_size_t) surf_parse_get_leng(void);
44 XBT_PUBLIC(char *) surf_parse_get_text(void);
45 XBT_PUBLIC(void) surf_parse_set_lineno(int line_number);
46 XBT_PUBLIC(void) surf_parse_set_in(FILE * in_str);
47 XBT_PUBLIC(void) surf_parse_set_out(FILE * out_str);
48 XBT_PUBLIC(int) surf_parse_get_debug(void);
49 XBT_PUBLIC(void) surf_parse_set_debug(int bdebug);
50 XBT_PUBLIC(int) surf_parse_lex_destroy(void);
51
52 /* What is needed to bypass the parser. */
53 XBT_PUBLIC_DATA(int_f_void_t) surf_parse;       /* Entry-point to the parser. Set this to your function. */
54
55 /* Set of macros to make the bypassing work easier.
56  * See examples/msg/masterslave_bypass.c for an example of use */
57
58 extern unsigned int surfxml_buffer_stack_stack_ptr;
59 extern unsigned int surfxml_buffer_stack_stack[1024];
60
61 #define SURFXML_BUFFER_SET(key,val) do { \
62   AX_surfxml_##key=AX_ptr; \
63   strcpy(A_surfxml_##key,val); \
64   AX_ptr+=(int)strlen(val)+1; } while(0)
65
66 #define SURFXML_BUFFER_RESET() do { \
67   AX_ptr = 0; \
68   memset(surfxml_bufferstack,0,surfxml_bufferstack_size); } while(0)
69
70 #define SURFXML_START_TAG(tag) \
71   do{                                                                   \
72     surfxml_buffer_stack_stack[surfxml_buffer_stack_stack_ptr++] = AX_ptr; \
73     STag_surfxml_##tag();                                               \
74   }while(0)
75
76 #define SURFXML_END_TAG(tag)                                            \
77   do{                                                                   \
78     AX_ptr = surfxml_buffer_stack_stack[--surfxml_buffer_stack_stack_ptr]; \
79     ETag_surfxml_##tag();                                               \
80   } while(0)
81
82 SG_END_DECL()
83 #endif