tt is a tiny C++ utility that converts .h.tt template files into .h
files by alternating between raw byte output and inline C/C++ code.
It is designed for generating C/C++ source or headers that embed raw data safely as byte strings while still allowing logic, macros, or hand-written code inline.
%is used as a mode toggle- Text outside
%blocks is treated as raw data - Text inside
%blocks is treated as C/C++ code - Raw data is emitted as escaped hex bytes via an
OUT()macro
RAW TEXT % C/C++ CODE % MORE RAW TEXT
Hello world
%
// some C/C++ code
#define X 42
%
GoodbyeOUT("\x48\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64\x0a", 12);
// some C/C++ code;
OUT("\x47\x6f\x6f\x64\x62\x79\x65", 7);- Raw text is converted to
\xNNbyte sequences - Code blocks are copied verbatim (with
;appended)
make buildThis produces:
./bin/tt
./bin/tt index.h.tt- Input files must end with
.tt - Output file name is derived by stripping the suffix
index.h.tt → index.h
%toggles between data mode and code mode- Processing starts in data mode
- Every
%flips the mode - No nesting — intentionally simple
- C++17-compatible compiler
- Tested with
g++
- An
OUT(const char*, size_t)macro or function exists - Newlines are preserved as raw bytes
- No attempt is made to be clever or safe beyond byte-accuracy
- Small
- Predictable
- Hackable
- Build-system friendly
If it feels like something you’d write at 2am inside Emacs, it’s working.
Do whatever you want. If it breaks, you get to keep both pieces.