/*1* *****************************************************************************2*3* SPDX-License-Identifier: BSD-2-Clause4*5* Copyright (c) 2018-2025 Gavin D. Howard and contributors.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions are met:9*10* * Redistributions of source code must retain the above copyright notice, this11* list of conditions and the following disclaimer.12*13* * Redistributions in binary form must reproduce the above copyright notice,14* this list of conditions and the following disclaimer in the documentation15* and/or other materials provided with the distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"18* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE19* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE20* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE21* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR22* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF23* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS24* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN25* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)26* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE27* POSSIBILITY OF SUCH DAMAGE.28*29* *****************************************************************************30*31* Code to handle special I/O for bc.32*33*/3435#ifndef BC_READ_H36#define BC_READ_H3738#include <stdlib.h>3940#include <status.h>41#include <vector.h>4243/**44* Returns true if @a c is a non-ASCII (invalid) char.45* @param c The character to test.46* @return True if @a c is an invalid char.47*/48#define BC_READ_BIN_CHAR(c) (!(c))4950/**51* Reads a line from stdin after printing prompt, if desired.52* @param vec The vector to put the stdin data into.53* @param prompt The prompt to print, if desired.54*/55BcStatus56bc_read_line(BcVec* vec, const char* prompt);5758/**59* Read a file and return a buffer with the data. The buffer must be freed by60* the caller.61* @param path The path to the file to read.62*/63char*64bc_read_file(const char* path);6566/**67* Helper function for reading characters from stdin. This takes care of a bunch68* of complex error handling. Thus, it returns a status instead of throwing an69* error, except for fatal errors.70* @param vec The vec to put the stdin into.71* @param prompt The prompt to print, if desired.72*/73BcStatus74bc_read_chars(BcVec* vec, const char* prompt);7576/**77* Read a line from buf into vec.78* @param vec The vector to read data into.79* @param buf The buffer to read from.80* @param buf_len The length of the buffer.81*/82bool83bc_read_buf(BcVec* vec, char* buf, size_t* buf_len);8485#endif // BC_READ_H868788