Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file in_internal.h |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief Internal structures and functions for libyang parsers |
| 5 | * |
| 6 | * Copyright (c) 2020 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
| 14 | |
| 15 | #ifndef LY_IN_INTERNAL_H_ |
| 16 | #define LY_IN_INTERNAL_H_ |
| 17 | |
| 18 | #include "in.h" |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * @brief Parser input structure specifying where the data are read. |
| 22 | */ |
| 23 | struct ly_in { |
| 24 | LY_IN_TYPE type; /**< type of the output to select the output method */ |
| 25 | const char *current; /**< Current position in the input data */ |
| 26 | const char *func_start; /**< Input data position when the last parser function was executed */ |
| 27 | const char *start; /**< Input data start */ |
| 28 | size_t length; /**< mmap() length (if used) */ |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 29 | |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 30 | union { |
| 31 | int fd; /**< file descriptor for LY_IN_FD type */ |
| 32 | FILE *f; /**< file structure for LY_IN_FILE and LY_IN_FILEPATH types */ |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 33 | |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 34 | struct { |
| 35 | int fd; /**< file descriptor for LY_IN_FILEPATH */ |
| 36 | char *filepath; /**< stored original filepath */ |
| 37 | } fpath; /**< filepath structure for LY_IN_FILEPATH */ |
| 38 | } method; /**< type-specific information about the output */ |
Radek Krejci | d54412f | 2020-12-17 20:25:35 +0100 | [diff] [blame] | 39 | uint64_t line; /**< current line of the input */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | /** |
Radek Krejci | d54412f | 2020-12-17 20:25:35 +0100 | [diff] [blame] | 43 | * @brief Increment line counter. |
| 44 | * @param[in] IN The input handler. |
| 45 | */ |
| 46 | #define LY_IN_NEW_LINE(IN) \ |
| 47 | (IN)->line++ |
| 48 | |
| 49 | /** |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 50 | * @brief Read bytes from an input. |
| 51 | * |
Radek Krejci | dd713ce | 2021-01-04 23:12:12 +0100 | [diff] [blame] | 52 | * Does not count new lines, which is expected from the caller who has better idea about |
| 53 | * the content of the read data and can better optimize counting. |
| 54 | * |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 55 | * @param[in] in Input structure. |
| 56 | * @param[in] buf Destination buffer. |
| 57 | * @param[in] count Number of bytes to read. |
| 58 | * @return LY_SUCCESS on success, |
| 59 | * @return LY_EDENIED on EOF. |
| 60 | */ |
| 61 | LY_ERR ly_in_read(struct ly_in *in, void *buf, size_t count); |
| 62 | |
| 63 | /** |
| 64 | * @brief Just skip bytes in an input. |
| 65 | * |
Radek Krejci | dd713ce | 2021-01-04 23:12:12 +0100 | [diff] [blame] | 66 | * Does not count new lines, which is expected from the caller who has better idea about |
| 67 | * the content of the skipped data and can better optimize counting. |
| 68 | * |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 69 | * @param[in] in Input structure. |
| 70 | * @param[in] count Number of bytes to skip. |
| 71 | * @return LY_SUCCESS on success, |
| 72 | * @return LY_EDENIED on EOF. |
| 73 | */ |
| 74 | LY_ERR ly_in_skip(struct ly_in *in, size_t count); |
| 75 | |
| 76 | #endif /* LY_IN_INTERNAL_H_ */ |