1: #include <petscsys.h>
2: #include <yaml.h>
4: /* The option structure */
5: typedef struct option_s {
6: /* The option name */
7: char *name;
8: /* The group the option is in. Defaults to default */
9: char *group;
10: struct {
11: /* The array of strings containing the arguments */
12: char **args;
13: /* The number of arguments in the list */
14: int count;
15: } arguments;
16: } option_t;
18: /* The options_list structure */
19: typedef struct options_list_s {
20: /* The array containing the options */
21: option_t *options;
22: /* The length of the options list */
23: int count;
24: } options_list_t;
26: /**
27: * This is a generic function to call on the proper function to populate an options list.
28: *
29: * The application is responsible for freeing any buffers associated with the produced
30: * options_list object using the options_list_delete function.
31: *
32: * @param[in] filename A string containing the filename
33: * @param[out] options_list An empty options_list_t object.
34: *
35: * returns 1 if the function succeeded, 0 on error.
36: */
37: int 38: options_list_populate(char *filename, options_list_t *options_list);
40: /**
41: * Reads a YAML file from a string and produces an options_list.
42: *
43: * The application is responsible for freeing any buffers assiciated with the produced
44: * options_list object using the options_list_delete function.
45: *
46: * @param[in] str A string containing the YAML file.
47: * @param[out] options_list An empty options_list object.
48: *
49: * returns 1 if the function succeeded, 0 on error.
50: */
51: int 52: options_list_populate_yaml(char *str, options_list_t *options_list);
54: /**
55: * Destroy an options_list
56: *
57: * @param[in,out] options_list An options_list object.
58: */
59: void 60: options_list_delete(options_list_t *options_list);
62: /**
63: * Reads data from a file and copies it to a string.
64: *
65: * The application is responsible for freeing the str buffer.
66: *
67: * @param[in] filename The name of the file to be read to string.
68: * @param[out] str The address of a NULL char* object.
69: *
70: * returns 1 on success, 0 on error.
71: */
72: PetscErrorCode 73: file_to_string(char *filename, char **str);
75: /* The grouping_stack_group structure */
76: typedef struct grouping_stack_group_s {
77: /* The name of the group */
78: char *name;
79: /* The event index the group starts at */
80: int start;
81: /* The event index the group ends at */
82: int end;
83: } grouping_stack_group_t;
85: /* The grouping_stack structure */
86: typedef struct grouping_stack_s {
87: /* The array of groups in the stack */
88: grouping_stack_group_t *groups;
89: /* The number of elements in the string array */
90: int count;
91: } grouping_stack_t;
93: /* The alias_key_value structure */
94: typedef struct alias_key_value_s {
95: /* The string containing the alias name */
96: char *alias;
97: /* The YAML event corresponding with the name */
98: yaml_event_t event;
99: } alias_key_value_t;
101: /* The alias_list structure */
102: typedef struct alias_list_s {
103: /* The length of the list */
104: int count;
105: /* The list itself */
106: alias_key_value_t *list;
107: } alias_list_t;
109: /**
110: * Generic copy constructor for a YAML event.
111: *
112: * @param[out] out An uninitialized yaml_event_t object.
113: * @param[in] in The yaml_event_t object to copy.
114: *
115: * returns 1 if the function succeeded, 0 on error.
116: */
117: int118: yaml_event_initialize(yaml_event_t *out, yaml_event_t *in);
120: /**
121: * Populates a list of alias information from parsing a yaml file.
122: * This is only called on by the options_list_populate_yaml function.
123: *
124: * The application is responsible for freeing any buffers associated
125: * with the alias_list_t object by use of the alias_list_delete() function.
126: *
127: * @param[in] str A string containing the YAML document to be read.
128: * @param[out] list An empty alias_list_t object.
129: *
130: * returns 1 on success.
131: */
132: int133: alias_list_populate_yaml(char *str, alias_list_t *list);
135: /**
136: * Destroy an alias_list_t object.
137: *
138: * @param[in,out] list An alias_list_t object.
139: */
140: void141: alias_list_delete(alias_list_t *list);