gnu_readline_sys/
lib.rs

1/*
2 * Copyright (C) 2023 taylor.fish <contact@taylor.fish>
3 *
4 * This file is part of gnu-readline-sys.
5 *
6 * gnu-readline-sys is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * gnu-readline-sys is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with gnu-readline-sys. If not, see <https://www.gnu.org/licenses/>.
18 *
19 * gnu-readline-sys links to or is otherwise a derived work of GNU Readline.
20 * See ./COPYRIGHT for more information.
21 */
22
23#![deny(unsafe_op_in_unsafe_fn)]
24#![allow(non_camel_case_types)]
25#![allow(non_snake_case)]
26#![allow(non_upper_case_globals)]
27
28//! This crate contains low-level bindings to GNU Readline.
29//!
30//! This crate does not build Readline; it must already be installed on your
31//! system.
32//!
33//! For API details, see [the documentation for GNU Readline][docs].
34//!
35//! [docs]: https://tiswww.cwru.edu/php/chet/readline/readline.html
36
37use libc::{c_ulong, time_t, FILE};
38use std::marker::{PhantomData, PhantomPinned};
39
40mod bindgen;
41pub use bindgen::*;
42
43#[repr(C)]
44pub struct KEYMAP_ENTRY {
45    _data: [u8; 0],
46    _marker: PhantomData<(*mut u8, PhantomPinned)>,
47}
48
49#[repr(C)]
50pub struct readline_state {
51    _data: [u8; 0],
52    _marker: PhantomData<(*mut u8, PhantomPinned)>,
53}
54
55#[allow(clippy::missing_safety_doc)]
56pub unsafe fn rl_clear_timeout() {
57    unsafe {
58        rl_set_timeout(0, 0);
59    }
60}
61
62#[allow(clippy::missing_safety_doc)]
63pub unsafe fn RL_SETSTATE(x: c_ulong) {
64    unsafe {
65        rl_readline_state |= x;
66    }
67}
68
69#[allow(clippy::missing_safety_doc)]
70pub unsafe fn RL_UNSETSTATE(x: c_ulong) {
71    unsafe {
72        rl_readline_state &= !x;
73    }
74}
75
76#[allow(clippy::missing_safety_doc)]
77pub unsafe fn RL_ISSTATE(x: c_ulong) -> c_ulong {
78    (unsafe { rl_readline_state }) & x
79}
80
81#[repr(C)]
82pub struct HIST_ENTRY {
83    _data: [u8; 0],
84    _marker: PhantomData<(*mut u8, PhantomPinned)>,
85}
86
87#[repr(C)]
88pub struct HISTORY_STATE {
89    _data: [u8; 0],
90    _marker: PhantomData<(*mut u8, PhantomPinned)>,
91}