39 lines
1.4 KiB
C
39 lines
1.4 KiB
C
// Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License.
|
|
// See LICENSE.md for license information.
|
|
// SPDX-License-Identifier: MIT
|
|
//
|
|
// gateText.h - text for the gate tools: printf into a growing buffer,
|
|
// bytes found in a buffer, and a whole-file read that says why it could not
|
|
// read the file.
|
|
|
|
#ifndef GATE_TEXT_H
|
|
#define GATE_TEXT_H
|
|
|
|
#include <stdarg.h>
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#include "toolBuf.h"
|
|
|
|
// gateTextFind: the bytes are not there.
|
|
#define GATE_TEXT_NOT_FOUND SIZE_MAX
|
|
|
|
// Append printf-style text to buf (no terminating zero: see gateTextString).
|
|
void gateTextAdd(ToolBufT *buf, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
|
|
|
|
// gateTextAdd with the arguments in a va_list.
|
|
void gateTextAddV(ToolBufT *buf, const char *fmt, va_list args) __attribute__((format(printf, 2, 0)));
|
|
|
|
// Where needle first is in hay at or after from; GATE_TEXT_NOT_FOUND when
|
|
// it is not (an empty needle is at from).
|
|
size_t gateTextFind(const uint8_t *hay, size_t hayLen, size_t from, const void *needle, size_t needleLen);
|
|
|
|
// A whole file, as toolReadFile reads it; false, with "cannot read PATH:
|
|
// <why>" appended to problem, when it cannot be read.
|
|
bool gateTextReadFile(const char *path, uint8_t **data, size_t *len, ToolBufT *problem);
|
|
|
|
// buf's text as a C string: a zero byte kept after it, not counted in len.
|
|
const char *gateTextString(ToolBufT *buf);
|
|
|
|
#endif
|