Files
klammertext/ref/reflect.cpp
T

55 lines
1.9 KiB
C++
Raw Normal View History

#include "machine.h"
#include "character.h"
#include "error.h"
#include "show.h"
// extern "C" is needed for dlsym name lookup. Returning std::string from
// C-linkage functions is technically non-standard but works correctly on
// Linux (Itanium ABI) where C and C++ calling conventions are identical.
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
#endif
extern "C"
std::string diacritics_examples([[maybe_unused]] Machine& machine)
{
if (diacritics.size() != diacritic_symbols_order.size()) {
throw Internal_error("Mismatch between diacritics order list and their definitions");
}
//std::cout << machine;
std::stringstream kt {};
kt << "@table :caption Diacritics (with typical base characters) :cell_hpos c c l |\n"
<< "@i-Displayed | @i-Written | @i-Name ||\n";
for (char symbol : diacritic_symbols_order) {
std::string sym { symbol };
auto [code, name] = diacritics[sym];
std::string letter = diacritic_example_letter[sym];
std::string written = "^" + letter + sym;
if (sym == "~") {
written = "^" + letter + "^~";
}
std::string display = "^" + letter + sym;
kt << display << " | @t ^" << written << " @ | " << name << " ||\n";
}
kt << "table@";
return kt.str();
}
extern "C"
std::string extended_latin_examples([[maybe_unused]] Machine& machine)
{
std::stringstream kt {};
kt << "@table :caption Extended Latin characters and ligatures :cell_hpos c c l |\n"
<< "@i-Displayed | @i-Written | @i-Name ||\n";
for (const std::string& symbol : extended_latin_symbols) {
auto [code, name] = extended_latin[symbol];
std::string coded = "^" + symbol + "^";
std::string file_literal = "^^ #- " + symbol + " #- ^^";
kt << coded << " | @t " << file_literal << " @ | " << name << " ||\n";
}
kt << "table@";
return kt.str();
}