2026-07-18 18:48:23 +02:00
|
|
|
#include "argv.h"
|
|
|
|
|
#include "command.h"
|
2026-08-12 17:20:23 +02:00
|
|
|
#include "coverage.h"
|
2026-07-18 18:48:23 +02:00
|
|
|
#include "error.h"
|
|
|
|
|
#include "file.h"
|
2026-07-22 18:17:43 +02:00
|
|
|
#include "font_store.h"
|
2026-07-18 18:48:23 +02:00
|
|
|
#include "ktype.h"
|
2026-09-07 22:37:05 +02:00
|
|
|
#include "katom_rewrite_rules.h"
|
2026-07-18 18:48:23 +02:00
|
|
|
#include "log.h"
|
2026-07-30 23:50:07 +02:00
|
|
|
#include "argtype_registry.h"
|
|
|
|
|
#include "klammerset_registry.h"
|
2026-07-18 18:48:23 +02:00
|
|
|
#include "character.h"
|
|
|
|
|
#include "show.h"
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
2026-07-22 18:17:43 +02:00
|
|
|
static void font_usage()
|
|
|
|
|
{
|
|
|
|
|
std::cout <<
|
|
|
|
|
"Font maintenance commands:\n"
|
2026-09-18 20:02:44 +02:00
|
|
|
" --typeface List the available fonts\n"
|
|
|
|
|
" --typeface list The same\n"
|
|
|
|
|
" --typeface samples <output-dir> Write a sample page of the available fonts\n"
|
2026-08-16 01:37:59 +02:00
|
|
|
" to <output-dir>/index.html\n"
|
2026-09-18 20:02:44 +02:00
|
|
|
" --typeface samples <input-dir> <output-dir>\n"
|
2026-08-16 01:37:59 +02:00
|
|
|
" Write a sample page for the (not yet\n"
|
|
|
|
|
" installed) font files under <input-dir>\n"
|
2026-09-18 20:02:44 +02:00
|
|
|
" --typeface install <input-dir> Install the font files found under\n"
|
2026-08-16 01:37:59 +02:00
|
|
|
" <input-dir> into the user font directory\n"
|
2026-09-18 20:02:44 +02:00
|
|
|
" --typeface install <input-dir> <output-dir>\n"
|
2026-08-16 01:37:59 +02:00
|
|
|
" Install into <output-dir> instead\n"
|
2026-09-18 20:02:44 +02:00
|
|
|
" --typeface help This description\n"
|
2026-07-22 18:17:43 +02:00
|
|
|
"\n"
|
|
|
|
|
"Fonts are searched in the directories of the KLAMMERTEXT_FONTS\n"
|
|
|
|
|
"environment variable (colon-separated; default $HOME/.klammertext/fonts)\n"
|
|
|
|
|
"and then in the default font set.\n";
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-12 17:20:23 +02:00
|
|
|
static void coverage_usage()
|
|
|
|
|
{
|
|
|
|
|
std::cout <<
|
|
|
|
|
"Coverage commands:\n"
|
2026-08-16 01:37:59 +02:00
|
|
|
" --coverage Report the targets each klammer covers\n"
|
|
|
|
|
" --coverage all Also name the file each klammer is written\n"
|
|
|
|
|
" in, and show every \"needs attention\"\n"
|
|
|
|
|
" category, including the empty ones\n"
|
2026-09-26 23:00:57 +02:00
|
|
|
" --coverage <target>\n"
|
|
|
|
|
" One target's view: the klammers that cover it,\n"
|
|
|
|
|
" those that do so with an EMPTY definition (a\n"
|
|
|
|
|
" decision: no meaning there), and the undecided\n"
|
|
|
|
|
" ones (no definition: nothing decided). \"all\"\n"
|
|
|
|
|
" may be added for the explanations.\n"
|
2026-08-16 01:37:59 +02:00
|
|
|
" --coverage help This description\n"
|
2026-08-12 17:20:23 +02:00
|
|
|
"\n"
|
|
|
|
|
"Coverage is a fact about a klammer: the targets it can render to. It is\n"
|
|
|
|
|
"DERIVED where the definitions determine it (a general body of klammer\n"
|
|
|
|
|
"calls covers the intersection of what those klammers cover), must be\n"
|
|
|
|
|
"DECLARED where they cannot (an @eval body, whose targets are named in a\n"
|
|
|
|
|
"comma-separated list: @@name.html,tex :: ... @@), and is UNKNOWN where\n"
|
|
|
|
|
"nothing is written -- which never means \"deliberately unavailable\".\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"Without \"all\", an AUTHOR sees what is available and only the problems\n"
|
|
|
|
|
"that exist. With it, a DESIGNER building a klammer set is reminded of\n"
|
|
|
|
|
"the whole set of categories.\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void katom_usage()
|
|
|
|
|
{
|
|
|
|
|
std::cout <<
|
|
|
|
|
"Katom commands:\n"
|
2026-08-16 01:37:59 +02:00
|
|
|
" --katoms List the katom types\n"
|
|
|
|
|
" --katoms full The list, with the regex syntax used for a march\n"
|
|
|
|
|
" --katoms help This description\n";
|
2026-08-12 17:20:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The words of a variadic option, with the empty ones dropped.
|
|
|
|
|
static strings_t option_words(Argv& args, const std::string& name)
|
|
|
|
|
{
|
|
|
|
|
strings_t words {};
|
|
|
|
|
for (const std::string& w : args.as_vector(name)) {
|
|
|
|
|
if (!w.empty()) {
|
|
|
|
|
words.push_back(w);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return words;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-30 23:50:07 +02:00
|
|
|
static void klammerset_usage()
|
|
|
|
|
{
|
|
|
|
|
std::cout <<
|
|
|
|
|
"Klammerset commands:\n"
|
2026-08-16 01:37:59 +02:00
|
|
|
" --klammersets List the klammersets on the search path\n"
|
|
|
|
|
" --klammersets <symbols> Load the klammersets specified by <symbols>\n"
|
|
|
|
|
" --klammersets help This description\n"
|
2026-07-30 23:50:07 +02:00
|
|
|
"\n"
|
2026-08-16 01:37:59 +02:00
|
|
|
"Without an argument, all available klammersets are listed. With one or more\n"
|
|
|
|
|
"klammerset symbols, those klammersets are loaded for analysis by the -k, -t,\n"
|
|
|
|
|
"--argtypes, --optionsets, and --coverage arguments.\n\n"
|
|
|
|
|
"SEVERAL SETS COMBINE. The symbols are a list, loaded in the order given, and\n"
|
|
|
|
|
"the klammers of all of them share ONE flat namespace -- membership in a set is\n"
|
|
|
|
|
"provenance, not containment. Where two sets define the same klammer, the\n"
|
|
|
|
|
"definition modes decide: \":\" is an error if the name is already defined,\n"
|
|
|
|
|
"\":::\" replaces the earlier definition (with a warning), and \"::::\" yields to\n"
|
|
|
|
|
"any later one. So a set of house overrides is loaded after the set it\n"
|
|
|
|
|
"adjusts, and a set of defaults before it.\n\n"
|
|
|
|
|
"The Standard Klammer Set is loaded by default. If the <symbols> argument is\n"
|
|
|
|
|
"\"none\", no klammerset is loaded.\n\n"
|
2026-07-30 23:50:07 +02:00
|
|
|
"A klammerset symbol x names the declaration file x/x.k, searched for in:\n"
|
2026-08-16 01:37:59 +02:00
|
|
|
"1) the current directory (for ktext, the input document's directory); 2) the\n"
|
|
|
|
|
"KLAMMERTEXT_KLAMMERSETS directories (colon-separated; the default is\n"
|
|
|
|
|
"$HOME/.klammertext/klammersets); and 3) $KLAMMERTEXT_HOME. The first hit\n"
|
2026-07-30 23:50:07 +02:00
|
|
|
"wins, so a document-local klammerset shadows an installed one, which\n"
|
|
|
|
|
"shadows a distributed one.\n";
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-16 01:37:59 +02:00
|
|
|
static void klammerset_command(Machine& machine, const strings_t& words)
|
2026-07-30 23:50:07 +02:00
|
|
|
{
|
2026-08-16 01:37:59 +02:00
|
|
|
if (words.empty()) {
|
2026-07-30 23:50:07 +02:00
|
|
|
std::cout << boldblack << "Klammersets\n" << black
|
|
|
|
|
<< describe_klammerset_search(fs::current_path().string());
|
2026-08-16 01:37:59 +02:00
|
|
|
} else if (words[0] == "help") {
|
2026-07-30 23:50:07 +02:00
|
|
|
klammerset_usage();
|
|
|
|
|
} else {
|
2026-08-16 01:37:59 +02:00
|
|
|
// "none" is not filtered out here: load_klammersets() is the single
|
|
|
|
|
// place that decides what the word means, including that it may not be
|
|
|
|
|
// combined with other symbols. Deciding it twice is how kdesc came to
|
|
|
|
|
// accept "--klammersets none sks" and silently load neither.
|
|
|
|
|
load_klammersets(machine, words);
|
2026-07-30 23:50:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-23 17:36:35 +02:00
|
|
|
// The target for the Klammertext kdesc renders for its own output: the
|
|
|
|
|
// ansi target (plain text with type styles as escape sequences) when
|
|
|
|
|
// stdout is a terminal, the txt target otherwise. The COMMAND decides,
|
|
|
|
|
// because only it knows the stream -- the same per-stream rule Color
|
|
|
|
|
// follows for the listings, NO_COLOR included -- and the targets stay
|
|
|
|
|
// formats a writer names with -t.
|
|
|
|
|
static std::string text_target()
|
|
|
|
|
{
|
|
|
|
|
return color_enabled(std::cout) ? "ansi" : "txt";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The Machine for a description kdesc renders from the ref/ klammerset.
|
|
|
|
|
static Machine ref_machine()
|
|
|
|
|
{
|
|
|
|
|
Machine M;
|
|
|
|
|
M.read(M.m_state.value("KLAMMERTEXT_HOME") + "/ref/ref.k");
|
|
|
|
|
return M;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void show_fonts()
|
|
|
|
|
{
|
|
|
|
|
Machine M = ref_machine();
|
|
|
|
|
M.read_string("@klammertext_fonts@");
|
|
|
|
|
std::cout << "\n" << M.apply(text_target()) << "\n\n";
|
|
|
|
|
}
|
2026-08-16 01:37:59 +02:00
|
|
|
|
2026-07-22 18:17:43 +02:00
|
|
|
static void font_command(const strings_t& words)
|
|
|
|
|
{
|
|
|
|
|
std::string verb = words.empty() ? "list" : words[0];
|
|
|
|
|
size_t n = words.size() - (words.empty() ? 0 : 1);
|
|
|
|
|
if (verb == "list" && n == 0) {
|
2026-09-23 17:36:35 +02:00
|
|
|
show_fonts();
|
2026-07-22 18:17:43 +02:00
|
|
|
} else if (verb == "samples" && n == 1) {
|
|
|
|
|
std::cout << "Font samples written to "
|
|
|
|
|
<< write_font_samples(words[1]) << "\n";
|
|
|
|
|
} else if (verb == "samples" && n == 2) {
|
|
|
|
|
std::cout << "Font samples written to "
|
|
|
|
|
<< write_font_samples(words[2], words[1]) << "\n";
|
|
|
|
|
} else if (verb == "install" && (n == 1 || n == 2)) {
|
|
|
|
|
std::cout << "Installing fonts from " << words[1] << ":\n"
|
|
|
|
|
<< install_fonts(words[1], n == 2 ? words[2] : "");
|
|
|
|
|
} else if (verb == "help") {
|
|
|
|
|
font_usage();
|
|
|
|
|
} else {
|
2026-09-18 20:02:44 +02:00
|
|
|
std::cout << "Unrecognized typeface command: --typeface " << join(words, " ")
|
2026-07-22 18:17:43 +02:00
|
|
|
<< "\n\n";
|
|
|
|
|
font_usage();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-21 22:37:13 +02:00
|
|
|
void show_special_characters()
|
|
|
|
|
{
|
|
|
|
|
Machine M = ref_machine();
|
2026-09-12 18:11:48 +02:00
|
|
|
M.read_string("@b Writing characters with diacritics and non-English characters @\n\n");
|
|
|
|
|
M.read_string("@diacritics_examples@");
|
|
|
|
|
M.read_string("@extended_latin_examples@");
|
|
|
|
|
M.read_string("@pinyin_examples@");
|
|
|
|
|
std::cout << "\n" << M.apply(text_target()) << "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void show_unicode_examples()
|
|
|
|
|
{
|
2026-09-21 22:37:13 +02:00
|
|
|
Machine M = ref_machine();
|
2026-09-12 18:11:48 +02:00
|
|
|
M.read_string("@unicode_examples@");
|
|
|
|
|
std::cout << "\n" << M.apply(text_target()) << "\n\n";
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-16 16:59:49 +02:00
|
|
|
void show_argtype_definitions()
|
|
|
|
|
{
|
2026-09-21 22:37:13 +02:00
|
|
|
Machine M = ref_machine();
|
2026-09-16 16:59:49 +02:00
|
|
|
M.read_string("@argtype_definitions@");
|
|
|
|
|
std::cout << "\n" << M.apply(text_target()) << "\n\n";
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-21 22:37:13 +02:00
|
|
|
// The katom table is wider than the text: four columns, the last of them a
|
|
|
|
|
// sentence. The width is the klammer's argument rather than a state
|
|
|
|
|
// variable set here, so the paragraphs above the table keep the text width.
|
|
|
|
|
void describe_katoms(bool show_regex)
|
|
|
|
|
{
|
|
|
|
|
Machine M = ref_machine();
|
|
|
|
|
M.read_string(std::string("@katom_descriptions :txt_width ") +
|
|
|
|
|
(show_regex ? "160 :regex" : "120") + " @");
|
|
|
|
|
std::cout << "\n" << M.apply(text_target()) << "\n\n";
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-22 22:53:13 +02:00
|
|
|
void show_katom_rewrite_patterns()
|
|
|
|
|
{
|
|
|
|
|
Machine M = ref_machine();
|
|
|
|
|
M.read_string("@katom_rewrite_patterns@");
|
|
|
|
|
std::cout << "\n" << M.apply(text_target()) << "\n\n";
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 18:48:23 +02:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
set_verbose_level(argc, argv);
|
|
|
|
|
|
|
|
|
|
Argv args {};
|
2026-08-12 17:20:23 +02:00
|
|
|
// Declaration order is display order in the usage text, so these are
|
|
|
|
|
// ordered by how likely a user is to want them. A single letter is a
|
|
|
|
|
// flag one reaches for often; a multi-letter name is a more specialised
|
|
|
|
|
// topic. -v stays last: it says how much to show about the command's
|
|
|
|
|
// PROCESSING, never what its RESULT contains -- which is why the katom
|
|
|
|
|
// regexes and the coverage file column are words of their own options
|
|
|
|
|
// rather than verbosity levels.
|
|
|
|
|
args.var("k", "Show klammers. With <text>, only those whose name or description contains <text>.", "text");
|
|
|
|
|
args.flag("c", "Show the codes for accented vowels and other special characters");
|
2026-08-25 23:30:55 +02:00
|
|
|
args.flag("u", "Describe including Unicode characters in KLammertext");
|
2026-08-16 01:37:59 +02:00
|
|
|
args.flag("t", "Show the targets for Klammertext output");
|
|
|
|
|
args.opt("i", "Input filename to analyze containing klammer and other definitions", "filename", "", "'text'");
|
|
|
|
|
args.var("klammersets", "List the available klammersets, or load one or more for analysis. Enter \"--klammersets help\" for details.", "symbols");
|
2026-08-25 23:30:55 +02:00
|
|
|
args.var("typeface", "List installed typefaces. Enter \"--typeface help\" for typeface maintenance commands.");
|
2026-08-12 17:20:23 +02:00
|
|
|
args.flag("argtypes", "Show the klammer argument types");
|
|
|
|
|
args.var("katoms", "Show the katom types. Enter \"--katoms help\" for details.");
|
|
|
|
|
args.flag("rewrite", "Show the katom rewrite patterns");
|
|
|
|
|
args.flag("optionsets", "Show the option sets declared by the input");
|
|
|
|
|
args.var("coverage", "Show the targets each klammer covers. Enter \"--coverage help\" for details.");
|
2026-07-18 18:48:23 +02:00
|
|
|
args.opt("v", "'verbosity'", "n", "0", "'verbosity'");
|
|
|
|
|
|
|
|
|
|
if (show_usage(argc, argv)) {
|
2026-08-16 01:37:59 +02:00
|
|
|
// A bare command is a REQUEST for information, not a failure:
|
|
|
|
|
// usage goes to stdout (it is the result being asked for) and the
|
|
|
|
|
// exit status is 0, so "kdesc && echo ok" reports what happened.
|
2026-07-18 18:48:23 +02:00
|
|
|
args.usage(file_basename(argv[0]));
|
2026-08-16 01:37:59 +02:00
|
|
|
exit(0);
|
2026-07-18 18:48:23 +02:00
|
|
|
}
|
2026-07-30 23:50:07 +02:00
|
|
|
auto p = [&](const std::string& name) { return args.get(name) == "true"; };
|
2026-07-18 18:48:23 +02:00
|
|
|
|
|
|
|
|
args.parse(argc, argv);
|
|
|
|
|
verbose_level = stoi(args.get("v"));
|
|
|
|
|
if (verbose_level > 0) {
|
|
|
|
|
args.describe();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-08-25 23:30:55 +02:00
|
|
|
if (p("u")) {
|
2026-09-12 18:11:48 +02:00
|
|
|
show_unicode_examples();
|
2026-08-25 23:30:55 +02:00
|
|
|
}
|
|
|
|
|
|
2026-09-16 16:59:49 +02:00
|
|
|
|
2026-08-12 17:20:23 +02:00
|
|
|
if (p("argtypes")) {
|
2026-09-16 16:59:49 +02:00
|
|
|
show_argtype_definitions();
|
2026-07-18 18:48:23 +02:00
|
|
|
}
|
|
|
|
|
|
2026-08-12 17:20:23 +02:00
|
|
|
if (args.given("katoms")) {
|
|
|
|
|
strings_t words = option_words(args, "katoms");
|
|
|
|
|
std::string verb = words.empty() ? "" : words[0];
|
|
|
|
|
if (verb == "help") {
|
|
|
|
|
katom_usage();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (!verb.empty() && verb != "full") {
|
|
|
|
|
std::cout << "Unrecognized katom command: --katoms " << join(words, " ") << "\n\n";
|
|
|
|
|
katom_usage();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
describe_katoms(verb == "full");
|
2026-07-18 18:48:23 +02:00
|
|
|
}
|
|
|
|
|
|
2026-08-12 17:20:23 +02:00
|
|
|
if (p("rewrite")) {
|
2026-09-22 22:53:13 +02:00
|
|
|
show_katom_rewrite_patterns();
|
2026-07-18 18:48:23 +02:00
|
|
|
}
|
|
|
|
|
|
2026-09-18 20:02:44 +02:00
|
|
|
// The --typeface subcommands operate on the Klammertext font store
|
2026-07-22 18:17:43 +02:00
|
|
|
// (infrastructure) and load no klammer set.
|
2026-08-25 23:30:55 +02:00
|
|
|
if (args.given("typeface")) {
|
|
|
|
|
font_command(option_words(args, "typeface"));
|
2026-07-22 18:17:43 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-16 01:37:59 +02:00
|
|
|
Machine M;
|
|
|
|
|
// Same rule as kdiag: a command that specifies no target evaluates
|
|
|
|
|
// under the GENERAL target (Andy, 2026-08-15). kdesc has no target
|
|
|
|
|
// argument either -- it describes what a klammer set provides for ALL
|
|
|
|
|
// targets -- and a designer's ".k" holding a top-level @eval hit the
|
|
|
|
|
// identical "Variable "K_target" not defined".
|
|
|
|
|
M.m_state.set("K_target", Target_registry::general_name);
|
|
|
|
|
|
|
|
|
|
strings_t input_filenames = resolve_filename_list(args.get("i"));
|
|
|
|
|
if (verbose_level > 0 && !input_filenames.empty()) {
|
|
|
|
|
std::cout << "input_filenames: " << input_filenames << "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!input_filenames.empty()) {
|
|
|
|
|
M.m_state.set(
|
|
|
|
|
"K_input_dir", absolute_pathname(file_directory(input_filenames[0])));
|
|
|
|
|
} else {
|
2026-09-25 00:32:55 +02:00
|
|
|
M.m_state.set("K_input_dir", fs::current_path().generic_string());
|
2026-08-16 01:37:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --klammersets both lists and loads: with no words it enumerates the
|
|
|
|
|
// search path, with symbols it loads them for the analyses below.
|
|
|
|
|
if (args.given("klammersets")) {
|
|
|
|
|
klammerset_command(M, option_words(args, "klammersets"));
|
|
|
|
|
} else { // By default, SKS is loaded for analysis
|
|
|
|
|
M.read(fs::path(M.m_state.value("KLAMMERTEXT_HOME") + "/sks/sks.k"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Snapshot BEFORE the input is read. The distinction is not "declared
|
|
|
|
|
// by a klammerset" but "loaded as context": an input file may itself
|
|
|
|
|
// declare @@@klammerset -- that is how a designer writes one -- and
|
|
|
|
|
// its klammers are still the ones being asked about.
|
|
|
|
|
strings_t context_files = M.m_klammersets.loaded_files();
|
|
|
|
|
|
|
|
|
|
for (auto fname : input_filenames) {
|
|
|
|
|
if (verbose_level > 0) {
|
|
|
|
|
std::cout << "Read " << fname << "\n";
|
|
|
|
|
}
|
|
|
|
|
M.read(fs::path(absolute_pathname(fname)));
|
2026-07-30 23:50:07 +02:00
|
|
|
}
|
|
|
|
|
|
2026-08-12 17:20:23 +02:00
|
|
|
// --coverage is validated here, before a klammer set is read, so a
|
|
|
|
|
// mistyped word or "help" is answered at once. The report itself
|
|
|
|
|
// needs the loaded registry, so it runs at the end.
|
2026-09-26 23:00:57 +02:00
|
|
|
// The words are "help", "all", and at most one target name, which
|
|
|
|
|
// can only be checked once the klammersets are loaded (below).
|
2026-08-12 17:20:23 +02:00
|
|
|
bool coverage_all = false;
|
2026-09-26 23:00:57 +02:00
|
|
|
std::string coverage_target {};
|
2026-08-12 17:20:23 +02:00
|
|
|
if (args.given("coverage")) {
|
|
|
|
|
strings_t words = option_words(args, "coverage");
|
2026-09-26 23:00:57 +02:00
|
|
|
for (const std::string& word : words) {
|
|
|
|
|
if (word == "help") {
|
|
|
|
|
coverage_usage();
|
|
|
|
|
return 0;
|
|
|
|
|
} else if (word == "all") {
|
|
|
|
|
coverage_all = true;
|
|
|
|
|
} else if (coverage_target.empty()) {
|
|
|
|
|
coverage_target = word;
|
|
|
|
|
} else {
|
|
|
|
|
std::cout << "Unrecognized coverage command: --coverage "
|
|
|
|
|
<< join(words, " ") << "\n\n";
|
|
|
|
|
coverage_usage();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2026-08-12 17:20:23 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-16 01:37:59 +02:00
|
|
|
strings_t own_klammers_only {};
|
|
|
|
|
if (!input_filenames.empty()) {
|
|
|
|
|
own_klammers_only = context_files;
|
2026-07-18 18:48:23 +02:00
|
|
|
}
|
|
|
|
|
|
2026-09-12 18:11:48 +02:00
|
|
|
|
|
|
|
|
if (p("c")) {
|
|
|
|
|
show_special_characters();
|
|
|
|
|
std::cout << "\n";
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-12 17:20:23 +02:00
|
|
|
if (p("t")) {
|
2026-08-16 01:37:59 +02:00
|
|
|
std::cout << boldblack << "Targets\n" << black
|
|
|
|
|
<< M.m_targets.describe(2, true, own_klammers_only);
|
2026-07-18 18:48:23 +02:00
|
|
|
}
|
|
|
|
|
|
2026-08-12 17:20:23 +02:00
|
|
|
// "-k <text>" searches names AND descriptions, case-insensitively,
|
|
|
|
|
// with whitespace collapsed on both sides. An empty listing for a
|
|
|
|
|
// search that was actually made is reported: silence would read as a
|
|
|
|
|
// broken command. It is not an error -- finding nothing is a result.
|
2026-08-16 01:37:59 +02:00
|
|
|
// With an input file, the klammersets are loaded so the input can be
|
|
|
|
|
// ANALYSED against them, but they are not what the user is asking
|
|
|
|
|
// about: a designer wants the klammers this file defines, and a reader
|
|
|
|
|
// of an unfamiliar document wants the custom klammers it carries. So
|
|
|
|
|
// the listing is restricted to klammers with a definition outside the
|
|
|
|
|
// klammerset files. Without -i there is nothing else to show, so the
|
|
|
|
|
// klammerset itself is the answer and no filter applies.
|
2026-08-12 17:20:23 +02:00
|
|
|
if (args.given("k")) {
|
|
|
|
|
std::string search = join(option_words(args, "k"), " ");
|
2026-08-16 01:37:59 +02:00
|
|
|
std::string listing = M.m_klammers.describe(2, search, own_klammers_only);
|
2026-08-12 17:20:23 +02:00
|
|
|
if (listing.empty() && !search.empty()) {
|
|
|
|
|
std::cout << "No klammer names or descriptions contained "
|
|
|
|
|
<< q_(collapse_whitespace(search)) << ".\n";
|
|
|
|
|
} else {
|
|
|
|
|
std::cout << boldblack << "Klammers\n" << black << listing;
|
|
|
|
|
}
|
2026-07-18 18:48:23 +02:00
|
|
|
}
|
|
|
|
|
|
2026-08-06 13:11:37 +02:00
|
|
|
if (p("optionsets")) {
|
2026-08-16 01:37:59 +02:00
|
|
|
std::cout << boldblack << "Option sets\n" << black
|
|
|
|
|
<< M.m_option_sets.describe(2, own_klammers_only);
|
2026-08-06 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
2026-08-12 17:20:23 +02:00
|
|
|
// Analysis only: klammer_coverage() reads the registry and modifies
|
|
|
|
|
// nothing, so what a document renders to is unaffected by asking.
|
|
|
|
|
if (args.given("coverage")) {
|
2026-09-26 23:00:57 +02:00
|
|
|
if (!coverage_target.empty()) {
|
|
|
|
|
if (!is_in(coverage_target, M.m_targets.user_defined())) {
|
|
|
|
|
std::cout << "No target \"" << coverage_target << "\" is defined. Enter \"kdesc -t\" to see the\n"
|
|
|
|
|
<< "targets the loaded klammersets define, or \"--coverage help\".\n";
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
report_target_coverage(klammer_coverage(M, own_klammers_only), coverage_target, coverage_all, std::cout);
|
|
|
|
|
} else {
|
|
|
|
|
report_coverage(M, klammer_coverage(M, own_klammers_only), coverage_all, std::cout);
|
|
|
|
|
}
|
2026-08-12 17:20:23 +02:00
|
|
|
}
|
2026-07-18 18:48:23 +02:00
|
|
|
}
|
|
|
|
|
catch (Error& e) {
|
2026-08-12 17:20:23 +02:00
|
|
|
// Nonzero, as ktext does: a command that prints an error and exits 0
|
|
|
|
|
// reports success, and a script cannot tell the difference.
|
2026-07-18 18:48:23 +02:00
|
|
|
e.print_message();
|
2026-08-12 17:20:23 +02:00
|
|
|
return 1;
|
2026-07-18 18:48:23 +02:00
|
|
|
}
|
2026-08-12 17:20:23 +02:00
|
|
|
return 0;
|
2026-07-18 18:48:23 +02:00
|
|
|
}
|