| 1004 | }; |
| 1005 | |
| 1006 | static int do_event(struct config_source *cs, enum config_event_t type, |
| 1007 | struct parse_event_data *data) |
| 1008 | { |
| 1009 | size_t offset; |
| 1010 | |
| 1011 | if (!data->opts || !data->opts->event_fn) |
| 1012 | return 0; |
| 1013 | |
| 1014 | if (type == CONFIG_EVENT_WHITESPACE && |
| 1015 | data->previous_type == type) |
| 1016 | return 0; |
| 1017 | |
| 1018 | offset = cs->do_ftell(cs); |
| 1019 | /* |
| 1020 | * At EOF, the parser always "inserts" an extra '\n', therefore |
| 1021 | * the end offset of the event is the current file position, otherwise |
| 1022 | * we will already have advanced to the next event. |
| 1023 | */ |
| 1024 | if (type != CONFIG_EVENT_EOF) |
| 1025 | offset--; |
| 1026 | |
| 1027 | if (data->previous_type != CONFIG_EVENT_EOF && |
| 1028 | data->opts->event_fn(data->previous_type, data->previous_offset, |
| 1029 | offset, cs, data->opts->event_fn_data) < 0) |
| 1030 | return -1; |
| 1031 | |
| 1032 | data->previous_type = type; |
| 1033 | data->previous_offset = offset; |
| 1034 | |
| 1035 | return 0; |
| 1036 | } |
| 1037 | |
| 1038 | static void kvi_from_source(struct config_source *cs, |
| 1039 | enum config_scope scope, |