Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Further parser cleanups
[simgrid.git] / include / surf / surfxml_parse.h
1 /* Copyright (c) 2006, 2007, 2008, 2009, 2010. 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 "surf/simgrid_dtd.h"
12 #include "xbt/function_types.h"
13 #include "xbt/dict.h"
14
15 SG_BEGIN_DECL()
16
17 /* Hook for the different tags. All the functions which pointer to are push into here are run when the tag is encountered */
18 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_platform_cb_list;
19 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_platform_cb_list;
20 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_router_cb_list;
21 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_link_cb_list;
22 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_link_cb_list;
23 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_route_cb_list;
24 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_route_cb_list;
25 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_link_ctn_cb_list;
26 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_link_ctn_cb_list;
27 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_process_cb_list;
28 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_process_cb_list;
29 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_argument_cb_list;
30 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_argument_cb_list;
31 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_prop_cb_list;
32 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_prop_cb_list;
33 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_trace_cb_list;
34 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_trace_cb_list;
35 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_trace_connect_cb_list;
36 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_trace_connect_cb_list;
37 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_random_cb_list;
38 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_random_cb_list;
39 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_AS_cb_list;
40 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_AS_cb_list;
41 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_ASroute_cb_list;
42 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_ASroute_cb_list;
43 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_bypassRoute_cb_list;
44 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_bypassRoute_cb_list;
45 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_cluster_cb_list;
46 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_cluster_cb_list;
47 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_peer_cb_list;
48 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_peer_cb_list;
49 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_include_cb_list;
50 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_include_cb_list;
51
52 XBT_PUBLIC(void) surf_parse_open(const char *file);
53 XBT_PUBLIC(void) surf_parse_close(void);
54 XBT_PUBLIC(void) surf_parse_init_callbacks(void);
55 XBT_PUBLIC(void) surf_parse_reset_callbacks(void);
56 XBT_PUBLIC(void) surf_parse_free_callbacks(void);
57 XBT_PUBLIC(double) surf_parse_get_double(const char *string);
58 XBT_PUBLIC(int) surf_parse_get_int(const char *string);
59 XBT_PUBLIC(void) surf_parse_add_callback_config(void);
60 XBT_PUBLIC(void) surf_parse_models_setup(void);
61 /* Prototypes of the functions offered by flex */
62 XBT_PUBLIC(int) surf_parse_lex(void);
63 XBT_PUBLIC(int) surf_parse_get_lineno(void);
64 XBT_PUBLIC(FILE *) surf_parse_get_in(void);
65 XBT_PUBLIC(FILE *) surf_parse_get_out(void);
66 XBT_PUBLIC(int) surf_parse_get_leng(void);
67 XBT_PUBLIC(char *) surf_parse_get_text(void);
68 XBT_PUBLIC(void) surf_parse_set_lineno(int line_number);
69 XBT_PUBLIC(void) surf_parse_set_in(FILE * in_str);
70 XBT_PUBLIC(void) surf_parse_set_out(FILE * out_str);
71 XBT_PUBLIC(int) surf_parse_get_debug(void);
72 XBT_PUBLIC(void) surf_parse_set_debug(int bdebug);
73 XBT_PUBLIC(int) surf_parse_lex_destroy(void);
74
75 /* What is needed to bypass the parser. */
76 XBT_PUBLIC_DATA(int_f_void_t) surf_parse;       /* Entry-point to the parser. Set this to your function. */
77
78 /* Set of macros to make the bypassing work easier.
79  * See examples/msg/masterslave_bypass.c for an example of use */
80
81 extern unsigned int surfxml_buffer_stack_stack_ptr;
82 extern unsigned int surfxml_buffer_stack_stack[1024];
83
84 #define SURFXML_BUFFER_SET(key,val) do { \
85   AX_surfxml_##key=AX_ptr; \
86   strcpy(A_surfxml_##key,val); \
87   AX_ptr+=(int)strlen(val)+1; } while(0)
88
89 #define SURFXML_BUFFER_RESET() do { \
90   AX_ptr = 0; \
91   memset(surfxml_bufferstack,0,surfxml_bufferstack_size); } while(0)
92
93 #define SURFXML_START_TAG(tag) do{ \
94                 surfxml_buffer_stack_stack[surfxml_buffer_stack_stack_ptr] = AX_ptr;\
95                 surfxml_buffer_stack_stack_ptr++;\
96                 STag_surfxml_##tag(); \
97                 }while(0)
98
99 #define SURFXML_END_TAG(tag)  do{ \
100                 surfxml_buffer_stack_stack_ptr--;\
101                 AX_ptr = surfxml_buffer_stack_stack[surfxml_buffer_stack_stack_ptr-1];\
102                 ETag_surfxml_##tag();\
103                 } while(0)
104
105 XBT_PUBLIC(void) surfxml_add_callback(xbt_dynar_t cb_list,
106                                       void_f_void_t function);
107 XBT_PUBLIC(void) surfxml_del_callback(xbt_dynar_t cb_list,
108                                       void_f_void_t function);
109
110 SG_END_DECL()
111 #endif