xref: /freebsd/lib/libbsdconf/bsdconf_internal.h (revision 3fe5961a0b708da599d42cbb6b5e4f030c28ea45)
1*3fe5961aSDevin Teske /*
2*3fe5961aSDevin Teske  * Copyright (c) 2001-2026 Devin Teske <dteske@FreeBSD.org>
3*3fe5961aSDevin Teske  * Copyright (c) 2021-2026 Faraz Vahedi <kfv@FreeBSD.org>
4*3fe5961aSDevin Teske  *
5*3fe5961aSDevin Teske  * SPDX-License-Identifier: BSD-2-Clause
6*3fe5961aSDevin Teske  */
7*3fe5961aSDevin Teske 
8*3fe5961aSDevin Teske #ifndef _BSDCONF_INTERNAL_H_
9*3fe5961aSDevin Teske #define _BSDCONF_INTERNAL_H_
10*3fe5961aSDevin Teske 
11*3fe5961aSDevin Teske #include <sys/stat.h>
12*3fe5961aSDevin Teske 
13*3fe5961aSDevin Teske #include <stdbool.h>
14*3fe5961aSDevin Teske #include <stddef.h>
15*3fe5961aSDevin Teske #include <stdint.h>
16*3fe5961aSDevin Teske 
17*3fe5961aSDevin Teske #include "bsdconf.h"
18*3fe5961aSDevin Teske 
19*3fe5961aSDevin Teske /*
20*3fe5961aSDevin Teske  * Private interfaces shared between the libbsdconf translation units.
21*3fe5961aSDevin Teske  * This header is deliberately not installed.
22*3fe5961aSDevin Teske  */
23*3fe5961aSDevin Teske 
24*3fe5961aSDevin Teske /* String manipulation routines (bsdconf_string.c) */
25*3fe5961aSDevin Teske void		bsdconf_strunexpand(char *_dst, const char *_src);
26*3fe5961aSDevin Teske void		bsdconf_strtolower(char *_buf);
27*3fe5961aSDevin Teske int		bsdconf_replaceall(char *_buf, size_t _buflen,
28*3fe5961aSDevin Teske 		    const char *_find, const char *_replace);
29*3fe5961aSDevin Teske unsigned int	bsdconf_strcount(const char *_source, const char *_find);
30*3fe5961aSDevin Teske 
31*3fe5961aSDevin Teske /*
32*3fe5961aSDevin Teske  * Parsed extent of a single statement within the in-memory copy of the file.
33*3fe5961aSDevin Teske  * All members are byte offsets into the buffer except as noted. A statement
34*3fe5961aSDevin Teske  * runs from the first byte of its directive to its terminator (newline, an
35*3fe5961aSDevin Teske  * inline `#' comment, or a semicolon when enabled).
36*3fe5961aSDevin Teske  */
37*3fe5961aSDevin Teske struct bsdconf_stmt {
38*3fe5961aSDevin Teske 	size_t line_start; /* start of the physical line (for removal) */
39*3fe5961aSDevin Teske 	size_t dir_start;  /* first byte of the directive */
40*3fe5961aSDevin Teske 	size_t dir_end;    /* one past the last byte of the directive */
41*3fe5961aSDevin Teske 	size_t op_start;   /* first byte of the assignment operator */
42*3fe5961aSDevin Teske 	size_t eq;         /* index of the `=' (valid iff have_equals) */
43*3fe5961aSDevin Teske 	size_t val_start;  /* first byte of the value (== val_end if none) */
44*3fe5961aSDevin Teske 	size_t val_end;    /* one past last byte of value (ws trimmed) */
45*3fe5961aSDevin Teske 	size_t term;       /* index of the terminator (`\n', `#', `;', EOF) */
46*3fe5961aSDevin Teske 	size_t line_end;   /* one past the terminating newline (for removal) */
47*3fe5961aSDevin Teske 	uint32_t line;     /* 1-based line number of the directive */
48*3fe5961aSDevin Teske 	enum bsdconf_op op; /* assignment operator of the statement */
49*3fe5961aSDevin Teske 	bool have_value;   /* a value was present */
50*3fe5961aSDevin Teske 	bool have_equals;  /* an `=' separated directive/value */
51*3fe5961aSDevin Teske };
52*3fe5961aSDevin Teske 
53*3fe5961aSDevin Teske /* Statement scan / put helpers (bsdconf_stmt.c) */
54*3fe5961aSDevin Teske const char	*bsdconf_op_token(enum bsdconf_op _op);
55*3fe5961aSDevin Teske int		 bsdconf_writeall(int _fd, const void *_data, size_t _len);
56*3fe5961aSDevin Teske char		*bsdconf_readfile(int _fd, size_t _size, size_t *_lenp);
57*3fe5961aSDevin Teske int		 bsdconf_emit(int _fd, const void *_data, size_t _len,
58*3fe5961aSDevin Teske 		    int *_last);
59*3fe5961aSDevin Teske int		 bsdconf_ensure_tmp(int *_tmpfdp, char *_tpath, size_t _tpathsz,
60*3fe5961aSDevin Teske 		    const char *_rpath, const struct stat *_sb);
61*3fe5961aSDevin Teske char		*bsdconf_format_value(const struct bsdconf_option *_option,
62*3fe5961aSDevin Teske 		    bool _unquoted, bool _quote_always, bool _bsemicolon);
63*3fe5961aSDevin Teske int		 bsdconf_value_empty(const struct bsdconf_option *_option);
64*3fe5961aSDevin Teske int		 bsdconf_dir_matches(const char *_buf, size_t _start,
65*3fe5961aSDevin Teske 		    size_t _end, const char *_directive, bool _case_sensitive);
66*3fe5961aSDevin Teske int		 bsdconf_scan(const char *_buf, size_t _len, size_t *_ip,
67*3fe5961aSDevin Teske 		    uint32_t *_linep, bool _bequals, bool _bsemicolon,
68*3fe5961aSDevin Teske 		    bool _strict_equals, bool _operator_equals,
69*3fe5961aSDevin Teske 		    struct bsdconf_stmt *_st);
70*3fe5961aSDevin Teske 
71*3fe5961aSDevin Teske #endif /* !_BSDCONF_INTERNAL_H_ */
72