blob: 35e90fc002e6fb85bcd1a3a48fd8d109c38065d5 [file] [log] [blame]
Michal Vaskoafac7822020-10-20 14:22:26 +02001/**
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"
19#include "tree_schema_internal.h"
20
21/**
22 * @brief Parser input structure specifying where the data are read.
23 */
24struct ly_in {
25 LY_IN_TYPE type; /**< type of the output to select the output method */
26 const char *current; /**< Current position in the input data */
27 const char *func_start; /**< Input data position when the last parser function was executed */
28 const char *start; /**< Input data start */
29 size_t length; /**< mmap() length (if used) */
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 */
33 struct {
34 int fd; /**< file descriptor for LY_IN_FILEPATH */
35 char *filepath; /**< stored original filepath */
36 } fpath; /**< filepath structure for LY_IN_FILEPATH */
37 } method; /**< type-specific information about the output */
Radek Krejcid54412f2020-12-17 20:25:35 +010038 uint64_t line; /**< current line of the input */
Michal Vaskoafac7822020-10-20 14:22:26 +020039};
40
41/**
Radek Krejcid54412f2020-12-17 20:25:35 +010042 * @brief Increment line counter.
43 * @param[in] IN The input handler.
44 */
45#define LY_IN_NEW_LINE(IN) \
46 (IN)->line++
47
48/**
Michal Vaskoafac7822020-10-20 14:22:26 +020049 * @brief Read bytes from an input.
50 *
Radek Krejcidd713ce2021-01-04 23:12:12 +010051 * Does not count new lines, which is expected from the caller who has better idea about
52 * the content of the read data and can better optimize counting.
53 *
Michal Vaskoafac7822020-10-20 14:22:26 +020054 * @param[in] in Input structure.
55 * @param[in] buf Destination buffer.
56 * @param[in] count Number of bytes to read.
57 * @return LY_SUCCESS on success,
58 * @return LY_EDENIED on EOF.
59 */
60LY_ERR ly_in_read(struct ly_in *in, void *buf, size_t count);
61
62/**
63 * @brief Just skip bytes in an input.
64 *
Radek Krejcidd713ce2021-01-04 23:12:12 +010065 * Does not count new lines, which is expected from the caller who has better idea about
66 * the content of the skipped data and can better optimize counting.
67 *
Michal Vaskoafac7822020-10-20 14:22:26 +020068 * @param[in] in Input structure.
69 * @param[in] count Number of bytes to skip.
70 * @return LY_SUCCESS on success,
71 * @return LY_EDENIED on EOF.
72 */
73LY_ERR ly_in_skip(struct ly_in *in, size_t count);
74
75#endif /* LY_IN_INTERNAL_H_ */