2026-07-18 18:48:23 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
|
|
|
|
|
std::string file_basename(const std::string& filename);
|
|
|
|
|
std::string extension(const std::string& filename);
|
|
|
|
|
std::string file_directory(const std::string& filename);
|
|
|
|
|
std::string absolute_pathname(const std::string& filename, const std::string& base="");
|
|
|
|
|
std::string relative_pathname(const std::string& filename);
|
|
|
|
|
std::string relative_pathname(const std::string& filename, const std::string& base);
|
|
|
|
|
|
|
|
|
|
fs::path relative_to_cwd(const fs::path& input);
|
|
|
|
|
|
|
|
|
|
bool file_exists(const std::string& pathname, bool error_if_not=false, bool is_directory=false);
|
2026-07-26 23:22:59 +02:00
|
|
|
|
|
|
|
|
// Filenames may contain spaces. A filename LIST in a flat string or an
|
|
|
|
|
// argument vector is separated by a standalone "/" token (whitespace on both
|
|
|
|
|
// sides; never a legal input filename -- "/" alone is the root directory).
|
|
|
|
|
// Without a separator, whitespace-split tokens that do not name existing
|
|
|
|
|
// files are greedily rejoined with their neighbors into names that do (the
|
|
|
|
|
// rescue is announced). A leading "~/" (or bare "~") expands to $HOME.
|
|
|
|
|
std::string expand_tilde(const std::string& path);
|
|
|
|
|
std::vector<std::string> group_filename_tokens(
|
|
|
|
|
const std::vector<std::string>& tokens, const std::string& base_dir="");
|
|
|
|
|
std::vector<std::string> resolve_filename_list(
|
|
|
|
|
const std::string& text, const std::string& base_dir="");
|
2026-07-18 18:48:23 +02:00
|
|
|
std::string string_from_file(const std::string& pathname, bool strip_surrounding_whitespace=false);
|
|
|
|
|
void string_to_file(const std::string& pathname, std::string contents);
|
|
|
|
|
std::vector<std::string> get_files_in_directory(const std::string& dir);
|
|
|
|
|
std::string find_file(const std::string& basename, std::vector<std::string> search_path,
|
|
|
|
|
bool error_if_not_found=true);
|
|
|
|
|
|
|
|
|
|
std::vector<fs::path>
|
|
|
|
|
find_file_recursive(const fs::path& root, const std::string& filename,
|
|
|
|
|
bool only_one=true); //, Locator loc=Locator());
|
|
|
|
|
std::vector<fs::path>
|
|
|
|
|
find_file_from_roots(const std::vector<std::string>& roots, const std::string& filename, bool only_one);
|
|
|
|
|
|
|
|
|
|
fs::path klammertext_filename(
|
|
|
|
|
const std::string& basename, bool error_if_missing=true, bool make_directory_if_missing=false);
|
|
|
|
|
std::vector<std::string> sks_dirs();
|
|
|
|
|
std::vector<std::string> get_sks_directories(const std::string& s, bool include_argument=true);
|
Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).
(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00
|
|
|
std::string cache_directory(const std::string& subdirectory, std::string parent_directory="");
|
2026-07-18 18:48:23 +02:00
|
|
|
std::time_t to_time_t(const fs::file_time_type& ftime);
|
|
|
|
|
bool in_modification_order(std::string filename1, std::string filename2);
|
Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).
(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00
|
|
|
void write_to_cache(const std::string& cache_dir, const std::string& basename, const std::string& text);
|
|
|
|
|
std::string read_from_cache(const std::string& cache_dir, const std::string& basename);
|
|
|
|
|
bool cache_requires_update(const std::string& cache_dir, const std::string& file_to_cache, const std::string& basename);
|
2026-07-18 18:48:23 +02:00
|
|
|
|
|
|
|
|
std::vector<fs::path> pathnames_with_extension(
|
|
|
|
|
const fs::path& dir, const std::string extension
|
|
|
|
|
);
|
|
|
|
|
//std::string find_file(const fs::path& root, const std::string& name);
|
|
|
|
|
std::vector<std::string> find_files_with_extension(
|
|
|
|
|
const fs::path& root, const std::string& ext, bool case_insensitive=false);
|
|
|
|
|
std::string combine_files(
|
2026-07-31 00:25:18 +02:00
|
|
|
const std::vector<std::string>& filenames,
|
|
|
|
|
const std::string& prolog="", const std::string& epilog="",
|
|
|
|
|
const std::function <std::string(std::string)>& processor = nullptr);
|
2026-07-18 18:48:23 +02:00
|
|
|
|
|
|
|
|
bool files_differ(const fs::path& p1,
|
|
|
|
|
const fs::path& p2,
|
|
|
|
|
std::size_t buffer_size = 1 << 16); // 64 KiB
|
|
|
|
|
|
|
|
|
|
// Copy a single file with an explicit binary stream (NOT std::filesystem
|
|
|
|
|
// copy_file/copy), forcing the destination world-readable. Required for output
|
|
|
|
|
// onto Apple `container` virtiofs mounts — see the definition in file.cpp.
|
|
|
|
|
void copy_file_stream(const fs::path& src, const fs::path& dst);
|
|
|
|
|
|
|
|
|
|
void copy_preserving_basename(
|
Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).
(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00
|
|
|
const std::vector<std::string>& filenames, const std::string& output_directory,
|
|
|
|
|
const std::string& link_directory);
|
2026-07-18 18:48:23 +02:00
|
|
|
|
|
|
|
|
fs::path resolve_relative_to(const fs::path& relative, const fs::path& base=std::filesystem::current_path());
|