Convert Terminfo Source to Termcap Safely with infotocap
By the end, you will have a termcap text file produced from a terminfo source file, without accidentally compiling anything into the system database. The workflow uses the ncurses-bin tools installed on this machine. Allow about ten minutes for a small conversion, including a check of the output.
The route
Jump straight to the step you need, or tick off Done means at the end.
Before you start
infotocap reads one or more text files containing terminfo entries and writes converted termcap descriptions to standard output. It does not need root for this job. You need:
- a readable terminfo source file, such as
terminal.info; - a shell with enough space for the output file; and
- a reason to target termcap, such as feeding an older tool that cannot read terminfo directly.
This guide describes ncurses 6.4 as identified by the local infotocap(1) manpage. The executable found first on this machine reports ncurses 6.6, so check your own version when reproducing an example:
infotocap -V
Expected output is a single version line, for example:
ncurses 6.6.20251230
The exact version is not cosmetic. Translation details, warnings and the available database may differ between ncurses builds.
1. Check the source without producing output
Start with validation. Replace terminal.info with the path to your file:
infotocap -c terminal.info
The -c option checks syntax and use references but produces no translated file. A successful run is normally silent and returns exit status zero:
if infotocap -c terminal.info; then
echo "terminfo source is valid"
else
echo "terminfo source needs repair" >&2
exit 1
fi
Do not skip this checkpoint when the source came from elsewhere. A malformed entry can make the conversion fail, and an unresolved use reference means the result may not represent the terminal description you intended.
2. Convert to a new file
Redirect standard output to a new path. The command below leaves the source untouched:
infotocap terminal.info > terminal.termcap
Inspect the first few lines and confirm that the file is non-empty:
sed -n '1,12p' terminal.termcap
test -s terminal.termcap && echo "termcap output exists"
The output uses termcap syntax, with capabilities separated by colons. A normal result may also contain comments saying that capabilities were removed or suppressed. Termcap is less expressive than terminfo, so a conversion cannot preserve every capability. Treat those comments as review items, not harmless decoration.
The converter writes to standard output by design. It does not install the result, update /etc/terminfo, or alter TERM. That makes shell redirection a useful safety boundary. If you used a wrong output name, undo it by removing only that generated file after checking the path:
rm -- terminal.termcap
This removes the converted copy, not the source. Do not replace the final destination in place until you have checked its contents and made a backup if another program depends on it.
3. Convert only selected entries
A source file can contain several terminal types and aliases. Use -e with a comma-separated list when you need only particular names:
infotocap -e xterm,screen terminal.info > selected.termcap
If a name or alias matches, that entry is translated. Other entries produce no output. Verify that the requested names really appear in the result:
grep -E '^(xterm|screen)(\||:)' selected.termcap
A slash in the -e value changes its meaning: ncurses interprets the value as a file containing the list. That is easy to trigger accidentally with an absolute path, so keep the comma-separated form for ordinary entry names.
4. Choose readable output when reviewing it
Termcap lines can be dense. Add -1 to put one capability on each line, which is easier to diff and inspect:
infotocap -1 -e xterm terminal.info > xterm.review.termcap
sed -n '1,24p' xterm.review.termcap
Use -f when complex terminfo strings contain conditional expressions and need a more readable layout. Use -w with an optional width when you want to control wrapping. These affect presentation, not the underlying limitation that termcap cannot express all terminfo behaviour.
5. Decide how much compatibility you need
By default, infotocap behaves like tic with termcap translation enabled. The manpage documents other tic options, including -K, -R, -r, -t, -T, -U, -v and -x.
Use -K when the consumer requires stricter BSD-style termcap syntax. Use -r when preparing a file for an old termcap library that cannot follow the remaining tc references. Both choices can change compatibility and completeness, so compare the result with the target library's documentation before deploying it.
Do not assume that a successful exit means semantic equivalence. For example, parameterised terminfo capabilities can use operations that termcap cannot represent. A useful review command is:
infotocap -C -c terminal.info
Here -C makes the translation target explicit while -c keeps the operation to checking. Warnings about values with no exact termcap equivalent are a signal to test the resulting terminal behaviour, especially cursor movement, attributes and function keys.
Common traps
- Using a compiled database entry as input. The input is a terminfo source file, not a binary file under
/etc/terminfo. Use a source file that you can read and review. - Overwriting the source with redirection.
infotocap terminal.info > terminal.infotruncates the file before the command reads it. Always choose a different output name. - Expecting installation. Conversion prints text. It does not install a termcap database or grant the output to another service.
- Ignoring size warnings. Traditional termcap consumers can have small entry limits. The local tool may report that an entry is too large, and an older library may behave badly with oversized data. Test with the actual consumer.
- Adding
-xcasually. This permits user-defined capabilities. It is useful for source that intentionally contains extensions, but it does not make an unknown capability portable.
Done means
infotocap -caccepted the source with the expected exit status.- The output file is separate from the source and contains the requested entry names.
- You reviewed warnings about removed, suppressed or untranslatable capabilities.
- The target termcap consumer has been tested with this exact output.