Tools

This chapters discusses additional tools that work together with XOScript.

XOCL

XOCL (XO Client) can be used to turn a webapp into a desktop application to reduce client-side attack surface (including XSS).

Basic usage:

xsltproc gtk.xsl screen.html | ./xocl

XOCL reads XML from stdin and writes form field values to stdout. The current version supports GTK4 XML as input and JSON as output. To convert HTML to the target XML format, XSLT can be used, a default GTK4-XSLT is provided as well as an example HTML-file and an xocl_example1.sh script that ties it all together.

The xocl_wrapper.sh template illustrates how to use XOCL in a persistent way, acting as a kind of application specific browser. The general idea is:


curl URL
|
apply XSLT
|
stdin XOCL
|
jq result
|
curl post
|
repeat

The current version only supports GTK4, support for other GUI toolkits will be added (or you can add it yourself). This assumes the target GUI toolkit can already process XML, if not (like Motif), an additional XML adapter is needed.

XOTR

XOTR (XO translate) translates the XO code file in the 2nd argument with the provided dictionary file in the 1st argument and writes the result to stdout and warnings/errors to stderr.

Use gendict.xo to create a dictionary file for XOTR based on two dictionary header files (found in src/i18n or plugin/i18n).

You can also craft dictionaries by hand, the format is:

<type> <source> <translation>

Type can be t for tokens or s for strings (in case you want to translate string literals as well).

XOTEST

XOTEST is the XOScript testing system. It consists of two scripts (ksh/bash) that run the tests. Each test is t-XXXX.ctr file containing XOScript code and a .exp file with the expected output. The main runner script in the root folder (runtests) switches based on the platform.

Multi-language tests

The script misc/xotest/runtest_multi.sh (Linux) runs the unit tests in other languages. For every selected language it builds a language edition of XOScript and the server plugin, translates all tests with XOTR and runs the translated tests.

Run the script from the root folder of the repository:

misc/xotest/runtest_multi.sh [build|nobuild] [languages] [ask|record|report]
Argument Meaning
build build every language edition first (default)
nobuild use the editions of a previous run
languages all (default) or a list of ISO codes like “de fr ja”
ask upon a difference: show it and ask to save the new result (default)
record upon a difference: save the new result without asking
report upon a difference: show it, save nothing and continue

The following settings can be passed as environment variables:

Setting Meaning Default
FROM first test to run 1
TIL last test to run 822
MODES memory modes to run each test in “1 4 0”
LANGS same as the languages argument all
SANITIZE build with address/undefined sanitizers, use no for a much faster run yes
STRINGS translate names of messages and settings in strings yes

For example, to test German, Japanese and Arabic with the first two tests in memory mode 1:

FROM=1 TIL=2 MODES="1" misc/xotest/runtest_multi.sh build "de ja ar" report

To run the same tests again without building:

FROM=1 TIL=2 MODES="1" misc/xotest/runtest_multi.sh nobuild "de ja ar" report

The English edition is always built as well, because it is needed to generate the dictionaries (gendict.xo). The editions are kept in build/Linux/bin as xo-ISO and mods-ISO, after a run the English edition is the active one again. The dictionaries and the translated tests are written to /tmp/xo. The translated tests are also kept in tests/ISO (like tests/de/t-0001.ctr), with paths to the libraries of the language (src/xo/ISO), so the multilingual manual can show every example in the language.

At the end the script prints a summary per language and exits with code 1 if a test failed or could not be translated.

Tests are skipped if the first line contains #OBSD or !XOTR (a test that cannot be translated). A test that fails to translate is reported as not translated.

XOTR only translates code. Names of messages and settings in strings are translated by the script misc/xotr/strings.awk, for instance the string in: on: [‘new’] do: { … }. This applies to strings after on:, message:, learn:, means: and setting:. All other strings are data and remain untouched.

The libraries in src/xo/en and the code in tests/assets are translated as well, the tests use the translated files instead of the English ones.

A test that runs English code from a string cannot work in a translated edition. Mark such a test as a single language test by adding !XOTR to the first line. Do not add a new line for this, because the line numbers in the expected results would change, use a comment on the first line instead, for instance:

Server init. # !XOTR

Avoid names in tests that are a word in another language. For example, a message named text is the translation of string in German. The script misc/xotr/checklang.py does not check this, the test will simply fail in that language.

Libraries per language

The script misc/xotr/makelibs.sh generates the libraries of src/xo/en for other languages:

misc/xotr/makelibs.sh "de fr ja"

Without arguments the libraries for all languages are generated. The libraries are written to src/xo/ISO. Besides the words of the language itself, the names defined by the libraries are translated: objects (like Template), messages (like content:) and the variables inside. These names are in src/i18n/ISO/libraries.h, line by line equal to src/i18n/en/libraries.h, and may not be the same as a word in dictionary.h or server.h of that language. Strings remain untouched, so mail headers (like Subject:) and the markers in templates (like cut:) stay the same in every language. Tests that use the libraries are translated with these names as well.

Existing files are not overwritten, because they may have been translated by hand. To regenerate the libraries of a language after its dictionary has changed:

FORCE=yes misc/xotr/makelibs.sh "de"

Checking language files

The script misc/xotr/checklang.py checks the language files against the rules in src/i18n/rules.txt:

python3 misc/xotr/checklang.py
python3 misc/xotr/checklang.py -w de

The option -w shows warnings as well.

Right-to-left languages

In right-to-left languages (like ar, fa, he and ur) parentheses, brackets and braces would be shown mirrored. These languages therefore use symbols that have no direction of their own and are never mirrored: ﴿ and ﴾ instead of ( and ), ⎬ and ⎨ instead of { and }, and ⌝’ and ‘⌜ instead of [‘ and ‘]. The opening symbol comes first in the text, so it is shown at the right. The quotes remain symmetrical: a symbol followed by ‘ to open a string and ‘ followed by a symbol to close it. These symbols are defined in dictionary.h of the language, xotr translates them like the other words and checklang.py checks them (rules 21 and 22).

Expected results per language

The expected result of a test in a language is read from:

tests/exp/ISO/testNNNNISO.exp

For example tests/exp/de/test0004de.exp. If this file does not exist, the English result (tests/exp/en) is used as a reference. When the test passes, its result is saved in tests/exp/ISO, so every translated test gets its own result file. The multilingual manual uses these files to show the result of each example in the language. A result that differs from the reference, for instance because the output contains a translated word like Objekt instead of Object, is only saved with record (or ask).

To generate the expected results for a language:

misc/xotest/runtest_multi.sh build "de" record

To check them afterwards:

misc/xotest/runtest_multi.sh nobuild "de" report

Note that record accepts the output of the translated edition as-is. Always review the recorded files before you rely on them, otherwise a bug might be recorded as the expected result.